<?php
# ************** LICENCE ****************
/*
	Copyright (c) PORTANEO.

	This file is part of POSH (Portaneo Open Source Homepage) http://sourceforge.net/projects/posh/.

	POSH is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version

	POSH is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with Posh.  If not, see <http://www.gnu.org/licenses/>.
*/
# ***************************************
# Create a new user portal
#
# !! be careful, this file must be saved under uft8 format, and display an e accentuated here : é
# ***************************************
/**
*
* \brief
* Create an empty page :  $p.app.pages.getSharedTab 
* Get all shared tabs
*
* @param  
*
*  return xml file
*
*  \relatesalso
*   ajax.js
*
* !! be careful, this file must be saved under uft8 format, and display an e accentuated here : é
*
**/

$folder="";
$pagename="portal/xml_getsharedtab.php";
$not_access=0;
$isScript=true;
$isPortal=false;
//includes
require_once('includes.php');
require_once('../includes/xml.inc.php');


$file=new xmlFile();

$file->header("data");

$chk = 0;
$idUser = 0;
$prof = 0;

$url="notused";
$pageid=isset($_POST["pageid"])?$_POST["pageid"]:0;
$user_id = isset($_SESSION['user_id'])?$_SESSION['user_id']:0;
$pages = array();
$pagesWidgets = array();
$data = array();
$datastr = "";
if ($user_id > 0)
{
	$profileIds = "";
	$DB->getResults($xml_getsharedtabs,
						$DB->escape($user_id),
						$DB->escape($user_id));
	if ($DB->nbResults() > 0)  {
		$i = 0;
		while($row = $DB->fetch(0)){
			$pages[$row['id']] = "<id>".$row['id']."</id>";
			$pages[$row['id']] .= "<name><![CDATA[".$row['name']."]]></name>";
			$pages[$row['id']] .= "<user_id>".$row['user_id']."</user_id>";
			$pages[$row['id']] .= "<long_name><![CDATA[".$row['long_name']."]]></long_name>";
			$pages[$row['id']] .= "<type><![CDATA[".$row['type']."]]></type>";
			$pages[$row['id']] .= "<param><![CDATA[".$row['param']."]]></param>";
			
			$profileIds .= $row['id'].",";
			$i++;
		}
		$profileIds .= "0";
		$DB->freeResults();
		$DB->getResults($xml_getAllWidgetsSharedtabs,
						$profileIds);
						
		while($row = $DB->fetch(0)){
			$pages[$row['profile_id']] .= "<widgets>";
			$pages[$row['profile_id']] .= "<item_id>".$row['item_id']."</item_id>";
			$pages[$row['profile_id']] .= "<wname><![CDATA[".$row['name']."]]></wname>";
			$pages[$row['profile_id']] .= "<shared><![CDATA[".$row['shared']."]]></shared>";
			$pages[$row['profile_id']] .= "<variables><![CDATA[".$row['variables']."]]></variables>";
			$pages[$row['profile_id']] .= "</widgets>";
		}
		foreach($pages as $k => $v) {
			echo "<tab>".$pages[$k]."</tab>";
		}
	}
	$DB->freeResults();
}

$file->status($chk);

$file->footer();

$DB->close();
?>