<?php

	/*
	*	Gekko - Open Source Web Development Framework
	*	------------------------------------------------------------------------
	*	Copyright (C) 2004-2005, J. Carlos Nieto <xiam@users.sourceforge.net>
	*	This program is Free Software.
	*
	*	@package	Gekko
	*	@license	http://www.gnu.org/copyleft/gpl.html GNU/GPL License 2.0
	*	@author		J. Carlos Nieto <xiam@users.sf.net>
	*	@version	CVS: $Id:$
	*	@link		http://www.gekkoware.org
	*/

	if (!defined("IN-GEKKO")) die("Get a life!");

	require_once GEKKO_ROOT."lib/auth.inc.php";

	if (!gauth("#")) abort(accessDenied());

	gpGlobalize("groups");
	gpGlobalize("object");
	gpGlobalize("popup");
	gpGlobalize("authwizard");
	gpGlobalize("relpath");

	define ("FORM_ID", "frmGroupInput_$object");

	$groups = explode(",", $groups);

	$db->query (
		"SELECT ID, Groupname, Description FROM ".db_table("group")." ORDER BY ID ASC",
		__FILE__, __LINE__
	);

	$rows = Array();
	while ($row = $db->fetch_row()) {
		if ($authwizard && (intval($row["ID"]) >= 500)) continue;
		$tmp = Array();
		foreach ($row as $key => $val)
			$tmp[$key] = $val;
		$rows[] = $tmp;
	}

	if ($authwizard) {
		$default = Array (
			Array ("ID" => "*", "Groupname" => _l("L_GROUP_ALL"), "Description" => _l("L_GROUP_ALL")),
			Array ("ID" => "#", "Groupname" => _l("L_GROUP_MANAGEMENT"), "Description" => _l("L_GROUP_MANAGEMENT")),
			Array ("ID" => "$", "Groupname" => _l("L_GROUP_ACCOUNT"), "Description" => _l("L_GROUP_ACCOUNT")),
			Array ("ID" => "?", "Groupname" => _l("L_GROUP_VISITOR"), "Description" => _l("L_GROUP_VISITOR")),
		);
		$rows = array_merge($default, $rows);
	}

	$maxrows = 4;

	$html = null;
	$html .= '<form id="'.FORM_ID.'" action="">';
	$html .= '<table class="data" style="padding:0px;margin:0px;">';
	$html .= '<tr class="head">'.str_repeat('<td></td><td>'._l("L_ID").'</td><td>'._l("L_GROUPNAME").'', $maxrows).'</tr>';

	/* table row data*/
	$i = 1;
	foreach ($rows as $row) {
		if ($authwizard && ($row["ID"] >= 500)) continue;
		if ($i%$maxrows === 1) $html .= '<tr>';
		$html .= '<td style="text-align:center"><input type="checkbox" name="group[]" value="'.$row["ID"].'"'.(in_array($row["ID"], $groups) ? ' checked="checked"' : '').'></td>';
		$html .= '<td class="id">'.$row["ID"].'</td>';
		$html .= '<td><b>'.$row["Groupname"].'</b><br />'.$row["Description"].'</td>';
		if (!$i%$maxrows) $html .= "</tr>";
		$i++;
	}
	if (!$i%$maxrows) $html .= '</tr>';

	$html .= '</table>';
	$html .= '<div class="buttons">';
	$html .= '<button type="button" onclick="addGroups(\''.FORM_ID.'\', \''.$object.'\', \''.$popup.'\'); return false;">'._l("L_OK").'</button>';
	$html .= '<button type="reset">'._l("L_RESET").'</button>';
	$html .= '<button type="button" onclick="popupClose(\''.$popup.'\'); return false;">'._l("L_CANCEL").'</button>';
	$html .= '</div>';
	$html .= '</form>';

	echo '<div class="info" style="font-size:7pt;margin:0px;padding:0px;">'.$html.'</div>';
?>