<?php
/*
* @package LabCMS
* @copyright (c) 2006 Alexander Levin aka Loki (loki_angel@mail.ru)
* @support http://labcms.ru
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/

switch(true)
{
	case($_GET['action']=='add' && access('admin')): 
		$mode='add';
		addBreadcrumb("добавление группы");
		include dirname(__FILE__)."/edit.php";
	break;
	
	case($_GET['action']=='edit' && access('admin')):
		$mode='edit';
		addBreadcrumb("редактирование группы");
		include dirname(__FILE__)."/edit.php";
	break;
	
	case($_GET['action']=='delete' && access('admin')):
		$mode='delete';
		include dirname(__FILE__)."/edit.php";
	break;
	
	case($_GET['action']=='access' && access('admin')):
		addBreadcrumb("настройка группы");
		include dirname(__FILE__)."/access.php";
	break;
	
	case(access('admin')):
		include dirname(__FILE__)."/groups_list.php";
	break;
	
	default:
		LabCMS::i()->error403();
}

function get_child_groups($id, $finish=false, $noSAGroup=true, $groups=array(), $indent=0)
{
	$result=Db::i()->select("SELECT group_id, group_name FROM ?_groups WHERE parent_id=? {AND group_id!=?} ORDER BY group_name", $id, ($noSAGroup?1:DBSIMPLE_SKIP));
	if (count($result))
	{
		foreach($result as $val)
		{
			if ($val['group_id']==$finish) continue;
			$groups[]=array('group_id'=>$val['group_id'], 'group_name'=>$val['group_name'], 'indent'=>$indent);
			$groups=get_child_groups($val['group_id'], $finish, $noSAGroup, $groups, $indent+1);
		}
	}
	return $groups;

}
