<?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/>.
*/
# ***************************************
# Users tabs
#
# !! be careful, this file must be saved under uft8 format, and display an e accentuated here : é
# ***************************************

$folder="";
$not_access=1;
$granted="I,N";
$pagename="portal/xmltabs.php";
//includes
require_once('includes.php');
require_once('../includes/xml.inc.php');

$file=new xmlFile();

$file->header("tabs");
	
//dummy tab
if (isset($_GET["dumtab"]))
{
	echo "<tab>
	<number>0</number>
	<name><![CDATA[".$_GET["dumtab"]."]]></name>
	<type>1</type>
	<action></action>
	<locked>0</locked>
	<seq>0</seq>
	<style>1</style>
	<edit>0</edit>
	<move>0</move>
	<icon>".(isset($_GET["dumicon"])?$_GET["dumicon"]:"")."</icon>
    <removable>1</removable>
	</tab>";
}

include('selections/tabs_connected.inc.xml');

//get the user profile
$DB->getResults($xmltabs_getTabs2,$DB->escape($_SESSION["user_id"]));
$lines = array();
while($row = $DB->fetch(0))
{
    array_push($lines,$row);
}
$DB->freeResults();

foreach ($lines as $row) {
	echo "<tab>
	<number>".$row["id"]."</number>
	<name><![CDATA[".$row["name"]."]]></name>
	<type>".$row["type"]."</type>
	<action><![CDATA[";
	if ($row["type"]==1)
	{
		echo "$"."p.app.pages.change(".$row["id"].")";
	}
	else if ($row["type"]==2)
	{
		echo "$"."p.app.pages.frame('".$row["param"]."',".$row["id"].")";
	}
    else if ($row["type"]==4)
	{
		echo "$"."p.app.pages.redirect('".$row["param"]."',".$row["id"].")";
	}
	else
	{
		echo $row["param"];
	}
	echo "]]></action>";
	if ($row["md5pass"]=="")
	{
		echo "<locked>0</locked>";
	}
	else
	{
		echo "<locked>1</locked>";
	}
	
	echo "<seq>".$row["seq"]."</seq>
	<edit>1</edit>
	<move>1</move>
	<icon>" . $row["icon"] . "</icon>
	<style>" . $row["style"] . "</style>
	<loadstart>" . $row["loadonstart"] . "</loadstart>
	<status>" . $row["status"] . "</status>
	<shared>" . $row["shared"] . "</shared>
    <removable>" . $row["removable"] . "</removable>
    <showwidgetbar>" . $row["showwidgetbar"] . "</showwidgetbar>
	<template>" . $row["template"] . "</template>
    <controls>" . $row["controls"] . "</controls>
	<param><![CDATA[" . $row["param"] . "]]></param>
	<colnb>" . $row["width"] . "</colnb>
    ";
    $cells = array();
    $nbCols = $row['width'];
    for ($i = 1; $i <= $nbCols; $i++) {
        $cells[$i] = 0;
    }
    $DB->getResults($getnbModules_by_col,$DB->escape($_SESSION["user_id"]),$DB->escape($row["id"]));
    while( $row2 = $DB->fetch(0) ) {
        $nb = $row2['nb'];
        $cellid  = $row2['posx'];
        $cells[$cellid] = $nb;
    }
    $DB->freeResults();
    
    foreach ($cells as $cellid => $nb) {
        echo "  <cells><cellid>" . $cellid . "</cellid><nb>" . $nb . "</nb></cells>\n";
    }
	echo "<page_id>".$row["page_id"]."</page_id>";
	echo "</tab>\n";
}

$file->footer("tabs");

$DB->close();
?>