Location: PHPKode > projects > ChiCoMaS - Chilek CMS > chicomas/modules/user/groupperms.php
<?
defined( '_VALID_DA_' ) or die( 'Bu sayfaya dogrudan eriþim yapýlamaz.' );

/*****************************************************************************/
function List_GroupPerms($request){

	global $module;
	global $module_path;

	$content = null;

	$obj_tempdbarray = new CTempDBArray();
	$obj_tempdbengine = new CTempDBEngine();
	
	$obj_tempdb2array = new CTempDBArray();
	$obj_tempdb2engine = new CTempDBEngine();

	$groupid = $request['group'];

	$SQL = "SELECT * FROM group_permissions ";
	$SQL .= "WHERE group_id='".intval($groupid)."' ";
	$obj_tempdbarray = $obj_tempdbengine->GetRows($SQL);

	$content .= "
	<center>

	<form action='".basename($PHP_SELF)."?f=user&sf=groupperms&operation=save' method='post'>
	<table border=\"0\">
	<tr>
		<th>"._CP_UA_GROUP_PERMS_."</th>
		<th>-</th>
		<th>"._CP_UA_NON_GROUP_PERMS_."</th>
	</tr>
	<tr>
		<td align=\"center\" valign=\"middle\">
			<select name=\"group_permissions[]\" size=\"20\" multiple=\"multiple\">";
			while( $row = $obj_tempdbarray->get() ){
				//print_r($row);
				$grouppermissionid = $row['group_permission_id'];
				$active = $row['active'];
				$permissionid = $row['permission_id'];

				$SQL2 = "SELECT * FROM permissions ";
				$SQL2 .= "WHERE permission_id='".intval($permissionid)."' ";
				$row2 = $obj_tempdb2engine->GetRow($SQL2);
				$permissionname = $row2['permission_name'];
				$content .= "<option value=\"$grouppermissionid\">$permissionname</option>";
			}
			$content .= "
			</select>
		</td>
		<td align=\"center\" valign=\"middle\">
			<input type=\"submit\" value=\"&lt;&lt;\" name='frm_add_permission' style=\"float:center;\"/>
			<input type=\"submit\" value=\"&gt;&gt;\" name='frm_remove_permission' style=\"float:center;\"/>
		</td>
		<td align=\"center\" valign=\"middle\">
			<select name=\"permissions[]\" size=\"20\" multiple=\"multiple\">";

			$SQL = "SELECT * FROM permissions ";
			$SQL .= "WHERE active='1' ";
			$obj_tempdbarray = $obj_tempdbengine->GetRows($SQL);
			while( $row = $obj_tempdbarray->get() ){
				$permissionid = $row['permission_id'];
				$active = $row['active'];
				$permissionname = $row['permission_name'];

				$SQL2 = "SELECT * FROM group_permissions ";
				$SQL2 .= "WHERE group_id='".intval($groupid)."' ";
				$SQL2 .= "AND permission_id='".intval($permissionid)."' ";
				$row2 = $obj_tempdb2engine->GetRow($SQL2);
				if ($row2==null)
					$content .= "<option value=\"$permissionid\">$permissionname</option>";
			}
			$content .= "
			</select>
		</td>
	</tr>
	</table>
	<input type=\"hidden\" name=\"group\" value=\"$groupid\" />
	</form>

	</center>
	";

	return $content;
}

/*****************************************************************************/
function Save_GroupPerms($request){

	global $module;
	global $module_path;

	$content = null;

	$obj_tempdbarray = new CTempDBArray();
	$obj_tempdbengine = new CTempDBEngine();

	$groupid = $request['group'];
	$frm_add_permission = $request['frm_add_permission'];
	if (!isset($frm_add_permission))
		$frm_add_permission = 0;
	else
		$frm_add_permission = 1;

	$frm_remove_permission = $request['frm_remove_permission'];
	if (!isset($frm_remove_permission))
		$frm_remove_permission = 0;
	else
		$frm_remove_permission = 1;

	$group_permissions = $request['group_permissions'];
	$permissions = $request['permissions'];

   if ($frm_add_permission){
		foreach ($permissions as $permissionid){
			//echo "permissionid:$permissionid<br>";

			$SQL = "INSERT INTO group_permissions ";
			$SQL .= "( ";
			$SQL .= "group_id, ";
			$SQL .= "permission_id ";
			$SQL .= ") ";
			$SQL .= "VALUES";
			$SQL .= "( ";
			$SQL .= "'".intval($groupid)."', ";
			$SQL .= "'".intval($permissionid)."' ";
			$SQL .= ") ";

			$grouppermissionid = $obj_tempdbengine->AddRecord($SQL);

		}
	}


   if ($frm_remove_permission){
		foreach ($group_permissions as $grouppermissionid){
			//echo "grouppermissionid:$grouppermissionid<br>";

			$SQL = "DELETE FROM group_permissions ";
			$SQL .= "WHERE group_id='".intval($groupid)."'";
			$SQL .= "AND group_permission_id='".intval($grouppermissionid)."'";
		
			if (!$obj_tempdbengine->ExecQuery($SQL))
				$content .= "<br>Delete Error on ExecQuery<br>";

		}
	}

	ReDirection(basename($PHP_SELF)."?f=user&sf=groupperms&group=$groupid");

	return $content;
}

//*****************************************************************************
function Group_Permissions($request){

	global $module;
	global $module_path;

	$obj_tempdbarray = new CTempDBArray();
	$obj_tempdbengine = new CTempDBEngine();

	$operation = $request['operation'];

	switch ($operation){
	default:
	case 'list':
		$content = List_GroupPerms($request);
	break;
	case 'add':
		//$content .= Add_Groups($request);
	break;
	case 'edit':
		//$content .= Edit_Groups($request);
	break;
	case 'save':
		$content .= Save_GroupPerms($request);
	break;
	case 'upload':
//		$content .= Upload_Projects($request);
//		$content = "upload";
	break;
	case 'delete':
		//$content .= Delete_Groups($request);
	break;
	}

	return $content;
}

?>
Return current item: ChiCoMaS - Chilek CMS