<?
defined( '_VALID_DA_' ) or die( 'Bu sayfaya dogrudan eriþim yapýlamaz.' );
/*****************************************************************************/
function List_Groups($request){
global $module;
global $module_path;
$content = null;
$obj_tempdbarray = new CTempDBArray();
$obj_tempdbengine = new CTempDBEngine();
//Toplam gosterilecek kayit sayisi
$record = 10;
$desc = $request['desc'];
$orderby = $request['orderby'];
//Sayfa Numarasi
$page = $request['page'];
if ($page<=0)
$page = 1;
$SQL = "SELECT * FROM groups ";
$obj_tempdbarray = $obj_tempdbengine->GetRows($SQL);
$total_record = $obj_tempdbarray->count();
$max_page = ceil($total_record / $record);
$content = "<center>";
if ($total_record>0){
switch ($orderby){
default:
$SQL .= "ORDER BY group_id ";
break;
case 'active':
$SQL .= "ORDER BY active ";
break;
case 'name':
$SQL .= "ORDER BY group_name ";
break;
}
$start = ($page-1)*$record;
$SQL .= "LIMIT $start ,$record";
//echo "SQL:$SQL<br>";
$obj_tempdbarray = $obj_tempdbengine->GetRows($SQL);
$content .= "
<table width=\"100%\" cellpadding=\"3\" cellspacing=\"3\" border=\"1\">
<tbody>
<th><a href=".basename($PHP_SELF)."?f=user&sf=groups&operation=list&orderby=active&desc=".intval($desc).">"._CP_UA_ACTIVE_."</a></th>
<th><a href=".basename($PHP_SELF)."?f=user&sf=groups&operation=list&orderby=name&desc=".intval($desc).">"._CP_UA_GROUP_NAME_."</a></th>
<th>"._CP_UA_DESCRIPTION_."</th>
<th>"._CMN_EDIT_."</th>
<th>"._CMN_DELETE_."</th>
</tbody>";
while( $row = $obj_tempdbarray->get() ){
//print_r($row);
$groupid = $row['group_id'];
$active = $row['active'];
$groupname = $row['group_name'];
$description = $row['description'];
$content .= "
<tr>
<td align=\"center\">";
if ($active)
$content .= "<img border=0 src=\"images/icon/check.png\">";
else
$content .= "<img border=0 src=\"images/icon/disable.png\">";
$content .= "
</td>
<td align=\"center\"><a href=\"".basename($PHP_SELF)."?f=user&sf=groups&group=$groupid\">$groupname</a></td>
<td align=\"center\">$description</td>
<td align=\"center\"><a href=".basename($PHP_SELF)."?f=user&sf=groups&operation=edit&group=$groupid><img border=0 src=\"images/icon/edit.gif\"></a></td>
<td align=\"center\"><a href=".basename($PHP_SELF)."?f=user&sf=groups&operation=delete&group=$groupid><img border=0 src=\"images/icon/remove.gif\"></a></td>
</tr>";
}
$content .= "</table><br>";
if ($max_page>1){
$fpage = 1;
$lpage = $max_page;
if ($page>1)
$ppage = $page-1;
else
$ppage = 1;
if ($page>=$max_page)
$npage = $max_page;
else
$npage = $page+1;
//Sayfa gosterimi
$content .= "
<a href=".basename($PHP_SELF)."?f=user&sf=groups&operation=list&orderby=".$orderby."&desc=".intval($desc)."&page=".$fpage.">
<img src=\"./images/icon16/left2.png\" width=\"16\" height=\"16\" border=\"0\">
</a>
<a href=".basename($PHP_SELF)."?f=user&sf=groups&operation=list&orderby=".$orderby."&desc=".intval($desc)."&page=".$ppage.">
<img src=\"./images/icon16/left.png\" width=\"16\" height=\"16\" border=\"0\">
</a>
<a href=".basename($PHP_SELF)."?f=user&sf=groups&operation=list&orderby=".$orderby."&desc=".intval($desc)."&page=".$npage.">
<img src=\"./images/icon16/right.png\" width=\"16\" height=\"16\" border=\"0\">
</a>
<a href=".basename($PHP_SELF)."?f=user&sf=groups&operation=list&orderby=".$orderby."&desc=".intval($desc)."&page=".$lpage.">
<img src=\"./images/icon16/right2.png\" width=\"16\" height=\"16\" border=\"0\">
</a>
<br><br>";
}
$content .= _CMN_TOTAL_RECORD_.$total_record."<br>";
$content .= _CMN_PAGE_.$page." / ".$max_page."<br>";
$content .= "<br>";
}
else{
$content .= "
<div class=note>
<h3>".CMN_NOTES_."</h3>
<p>";
$content .= _CMN_NO_RECORD_FOUND_;
$content .= "<br><br>";
$content .= go_back();
$content .= "
</p>
</div>";
}
$content .= "
<a class=\"inline-button orange\" href=".basename($PHP_SELF)."?f=user&sf=groups&operation=list&orderby=".$orderby."&desc=".intval($desc)."&page=".$page."><em>@</em><span>"._CMN_LIST_."</span></a>
<a class=\"inline-button orange\" href=".basename($PHP_SELF)."?f=user&sf=groups&operation=add><em>@</em><span>"._CMN_ADD_."</span></a>
</center>
";
return $content;
}
/*****************************************************************************/
function Add_Groups($request){
global $module;
global $module_path;
$content = null;
$content .= "
<center>
<form action='".basename($PHP_SELF)."?f=user&sf=groups&operation=save' method='post'>
<input type=\"hidden\" name=\"lastoperation\" value=\"add\" />
<fieldset>
<img style=\"float:right;\" src=\"./images/icon48/users.png\" width=\"48\" height=\"48\" border=\"0\">
<legend>"._CP_UA_FORM_GROUPS_INFORMATION_."</legend>
<table cellpadding=\"2\" cellspacing=\"2\" border=\"0\">
<tr>
<td><label for=\"active\">"._CP_UA_FORM_ACTIVE_."</label></td>
<td><input type=\"checkbox\" name=\"active\" $active style=\"float:left;\"/></td>
</tr>
<tr>
<td><label for=\"groupname\">"._CP_UA_FORM_GROUP_NAME_."</label></td>
<td><input type=\"text\" name=\"groupname\" value=\"$groupname\" style=\"float:left;\" maxlength=\"32\"/></td>
</tr>
<tr>
<td><label for=\"description\">"._CP_UA_FORM_DESCRIPTION_."</label></td>
<td><textarea name=\"description\" cols=50 rows=10 wrap=soft style=\"float:left;\" onkeyup=\"this.value = this.value.slice(0, 255)\">".$description."</textarea></td>
</tr>
<tr>
<td colspan=\"2\" align=\"center\">
<br>";
$content .= "<input type=\"submit\" value=\""._CMN_ADD_."\" style=\"float:center;\"/>";
$content .= go_back();
$content .= "
</td>
</tr>
</table>
<br>
</fieldset>
</form>
<a class=\"inline-button orange\" href=".basename($PHP_SELF)."?f=user&sf=groups&operation=list><em>@</em><span>"._CMN_LIST_."</span></a>
</center>";
return $content;
}
/*****************************************************************************/
function Edit_Groups($request){
global $module;
global $module_path;
$content = null;
$obj_tempdbarray = new CTempDBArray();
$obj_tempdbengine = new CTempDBEngine();
$groupid = $request['group'];
$SQL = "SELECT * FROM groups WHERE group_id=".intval($groupid);
//$content .= $SQL;
$row = $obj_tempdbengine->GetRow($SQL);
$active = $row['active'];
if ($active)
$active = " checked ";
$groupname = $row['group_name'];
$description = $row['description'];
$content .= "
<center>
<form action='".basename($PHP_SELF)."?f=user&sf=groups&operation=save' method='post'>
<input type=\"hidden\" name=\"lastoperation\" value=\"update\" />
<input type=\"hidden\" name=\"group\" value=\"$groupid\" />
<fieldset>
<img style=\"float:right;\" src=\"./images/icon48/users.png\" width=\"48\" height=\"48\" border=\"0\">
<legend>"._CP_UA_FORM_GROUPS_INFORMATION_."</legend>
<table cellpadding=\"2\" cellspacing=\"2\" border=\"0\">
<tr>
<td><label for=\"active\">"._CP_UA_FORM_ACTIVE_."</label></td>
<td><input type=\"checkbox\" name=\"active\" $active style=\"float:left;\"/></td>
</tr>
<tr>
<td><label for=\"groupname\">"._CP_UA_FORM_GROUP_NAME_."</label></td>
<td><input type=\"text\" name=\"groupname\" value=\"$groupname\" style=\"float:left;\" maxlength=\"32\"/></td>
</tr>
<tr>
<td><label for=\"description\">"._CP_UA_FORM_DESCRIPTION_."</label></td>
<td><textarea name=\"description\" cols=50 rows=10 wrap=soft style=\"float:left;\" onkeyup=\"this.value = this.value.slice(0, 255)\">".$description."</textarea></td>
</tr>
<tr>
<td colspan=\"2\" align=\"center\">
<br>";
$content .= "<input type=\"submit\" value=\""._CMN_UPDATE_."\" style=\"float:center;\"/>";
$content .= go_back();
$content .= "
</td>
</tr>
</table>
<br>
</fieldset>
</form>
<a class=\"inline-button orange\" href=".basename($PHP_SELF)."?f=user&sf=groups&operation=list><em>@</em><span>"._CMN_LIST_."</span></a>
</center>";
return $content;
}
/*****************************************************************************/
function Save_Groups($request){
global $module;
global $module_path;
$content = null;
$obj_tempdbarray = new CTempDBArray();
$obj_tempdbengine = new CTempDBEngine();
$groupid = $request['group'];
$active = $request['active'];
$groupname = $request['groupname'];
$description = $request['description'];
$lastoperation = $request['lastoperation'];
$my_validator = new validator();
if (!($my_validator->validate_fields("groupname"))) {
$failed = true;
}
else {
$failed = false;
if ($active=="on")
$active=1;
else
$active=0;
if ($lastoperation=="update"){
$SQL = "UPDATE groups ";
$SQL .= "SET ";
$SQL .= "active = '".$active."', ";
$SQL .= "group_name = '".ucwords($groupname)."', ";
$SQL .= "description = '".$description."' ";
$SQL .= "WHERE group_id=".intval($groupid);
if (!$obj_tempdbengine->ExecQuery($SQL))
$content .= "<br>Update Error on ExecQuery<br>";
}
else{
$SQL = "INSERT INTO groups ";
$SQL .= "( ";
$SQL .= "active, ";
$SQL .= "group_name, ";
$SQL .= "description ";
$SQL .= ") ";
$SQL .= "VALUES";
$SQL .= "( ";
$SQL .= "'".$active."', ";
$SQL .= "'".$groupname."', ";
$SQL .= "'".$description."' ";
$SQL .= ") ";
$groupid = $obj_tempdbengine->AddRecord($SQL);
}
//$content .= $SQL;
}
$content .= "
<div class=note>
<h3>"._CMN_NOTE_."</h3>
<p>";
if (!$failed){
$content .= _CMN_SAVE_OK_;
ReDirection(basename($PHP_SELF)."?f=user&sf=groups&operation=list");
}
else{
$content .= _CMN_SAVE_FAILED_."<br><br>";
$content .= go_back();
}
$content .= "
</p>
</div>
";
return $content;
}
/*****************************************************************************/
function Delete_Groups($request){
global $module;
global $module_path;
$content = null;
$obj_tempdbarray = new CTempDBArray();
$obj_tempdbengine = new CTempDBEngine();
$groupid = $request['group'];
$accept = $request['accept'];
$SQL = "SELECT * FROM groups WHERE group_id=".intval($groupid);
//$content .= $SQL;
$row = $obj_tempdbengine->GetRow($SQL);
$active = $row['active'];
if ($active)
$active = " checked ";
$groupname = $row['group_name'];
$description = $row['description'];
if ($accept){
$SQL = "DELETE FROM groups ";
$SQL .= "WHERE group_id='".intval($groupid)."'";
if (!$obj_tempdbengine->ExecQuery($SQL))
$content .= "<br>Delete Error on ExecQuery<br>";
$content .= "
<div class=note>
<h3>"._CMN_NOTE_."</h3>
<p>";
$content .= _CMN_DELETE_OK_;
$content .= "<br><br>";
//ReDirection(basename($PHP_SELF)."?f=extra&sf=$module&proje=$proje&process=$process&operation=list");
$content .= "
</p>
</div>
";
}
else{
$content .= "
<center>
<form action='".basename($PHP_SELF)."?f=user&sf=groups&operation=delete' method='post'>
<input type=\"hidden\" name=\"lastoperation\" value=\"update\" />
<input type=\"hidden\" name=\"group\" value=\"$groupid\" />
<fieldset>
<img style=\"float:right;\" src=\"./images/icon48/users.png\" width=\"48\" height=\"48\" border=\"0\">
<legend>"._CP_UA_FORM_GROUPS_INFORMATION_."</legend>
<table cellpadding=\"2\" cellspacing=\"2\" border=\"0\">
<tr>
<td><label for=\"active\">"._CP_UA_FORM_ACTIVE_."</label></td>
<td><input type=\"checkbox\" name=\"active\" $active style=\"float:left;\"/></td>
</tr>
<tr>
<td><label for=\"groupname\">"._CP_UA_FORM_GROUP_NAME_."</label></td>
<td><input type=\"text\" name=\"groupname\" value=\"$groupname\" style=\"float:left;\" maxlength=\"32\"/></td>
</tr>
<tr>
<td><label for=\"description\">"._CP_UA_FORM_DESCRIPTION_."</label></td>
<td><textarea name=\"description\" cols=50 rows=10 wrap=soft style=\"float:left;\" onkeyup=\"this.value = this.value.slice(0, 255)\">".$description."</textarea></td>
</tr>
<tr>
<td colspan=\"2\" align=\"center\">
<br>";
$SQL = "SELECT * FROM user_groups WHERE group_id=".intval($groupid);
$obj_tempdbarray = $obj_tempdbengine->GetRows($SQL);
$total_record = $obj_tempdbarray->count();
if ($total_record==0){
$content .= "
<input type=\"hidden\" name=\"group\" value=\"$groupid\" />
<input type=\"hidden\" name=\"accept\" value=\"1\" />
<input type=\"submit\" value=\""._CMN_DELETE_."\" style=\"float:center;\"/>";
}
$content .= go_back();
$content .= "
</td>
</tr>
</table>
<br>
</fieldset>
</form>
<a class=\"inline-button orange\" href=".basename($PHP_SELF)."?f=user&sf=groups&operation=list><em>@</em><span>"._CMN_LIST_."</span></a>
<a class=\"inline-button orange\" href=".basename($PHP_SELF)."?f=user&sf=groups&operation=add><em>@</em><span>"._CMN_ADD_."</span></a>
<a class=\"inline-button orange\" href=".basename($PHP_SELF)."?f=user&sf=groups&operation=edit&group=$groupid><em>@</em><span>"._CMN_EDIT_."</span></a>
</center>";
}
return $content;
}
//*****************************************************************************
function Group_Operations($request){
global $module;
global $module_path;
$obj_tempdbarray = new CTempDBArray();
$obj_tempdbengine = new CTempDBEngine();
$operation = $request['operation'];
switch ($operation){
default:
case 'list':
$content = List_Groups($request);
break;
case 'add':
$content .= Add_Groups($request);
break;
case 'edit':
$content .= Edit_Groups($request);
break;
case 'save':
$content .= Save_Groups($request);
break;
case 'delete':
$content .= Delete_Groups($request);
break;
}
return $content;
}
?>