<?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/>.
*/
# ***************************************
# POSH Users management - XML List of the groups
#
# !! be careful, this file must be saved under uft8 format, and display an e accentuated here : é
# ***************************************
/**
* \brief Get groups, subgroups and the number of all into the DB
*
*   return xml file
*
* @param [in]  group (POST)
*
*   Need to improve error xml to get different messages on failure
*
* \relates
*   php xml_group.php
*
*  \relatesalso
*   admin.js
*   $p.admin.users.loadGroup
*   $p.admin.users.loadAvailGroups
*
* !! be careful, this file must be saved under uft8 format, and display an e accentuated here : é
*
**/

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

$file=new xmlFile();

$file->header("groups");

$id=$DB->escape(isset($_GET["group"])?$_GET["group"]:0);

    // selected group information
    $DB->getResults($xmlgroup_getName,$id);
    $numbergroup = $DB->nbResults();
    if ($numbergroup>0) {
    $row=$DB->fetch(0);
    echo "<parent><![CDATA[".$row['name']."]]></parent>";
    $DB->freeResults();
    }

    //childs groups information
    $DB->getResults($xmlgroup_getChildrenName,$id);
    $number = $DB->nbResults();
    if( $number > 0 ) {
        echo "<nb>".$number."</nb>";
    } elseif($numbergroup<=0 &&  $number<=0 ){
            $file->error("nogroupid");
    }
    
    if ($number>0)
    {
    	while ($row = $DB->fetch(0))
    	{
    		echo "<dir>";
    		echo "<dirid>".$row['id']."</dirid>";
    		echo "<dirname><![CDATA[".$row['name']."]]></dirname>";
    		echo "</dir>";
    	}
    }
    $DB->freeResults();

$file->footer("groups");

$DB->close();
?>