. */ include("./include/include.php"); include("./include/g_workshop.php"); admin_header(); if( !in_array("roles_view", $_SESSION['sess_functions']) ) { echoln("You are not authorized to see this page."); }else { $editable = in_array("roles_edit", $_SESSION['sess_functions']); $allRoles = array(); $query = "SELECT `id`, `name` FROM `roles` WHERE `id`>0 ORDER BY `name`"; if( @mysql_num_rows( $res=doquery($query) )>0 ) { while( $row = mysql_fetch_assoc($res) ) { $allRoles[ $row['id'] ] = $row['name']; } } $allFunctions = array(); $query = "SELECT `id`, `name` FROM `functions` ORDER BY `name`"; if( @mysql_num_rows( $res=doquery($query) )>0 ) { while( $row = mysql_fetch_assoc($res) ) { $allFunctions[ $row['id'] ] = $row['name']; } } echoln("

Administrate roles

"); if( $_SERVER['REQUEST_METHOD']=="POST" && isset($_POST['functionRole']) ) { $queryDelete = "DELETE FROM `function_roles`"; $queryAdd = "INSERT INTO `function_roles` (`role_id`, `function_id`) VALUES "; $queryOk = false; foreach( $_POST['functionRole'] as $function => $roles ) { if( array_key_exists($function, $allFunctions) ) { foreach( $roles as $role => $value ) { if( array_key_exists($role, $allRoles) ) { $queryOk = true; $queryAdd .= "(".addslashes($role).", ".addslashes($function)."), "; } } } } if( doquery($queryDelete) && (($queryOk && doquery(substr($queryAdd, 0, -2))) || !$queryOk) ) { echoln("Successfully saved role.

"); }else { echoln("Failed saving role.

"); $_REQUEST['edit'] = true; } } ################# ### Show form ### ################# $functionRole = array(); $query = "SELECT `role_id`, `function_id` FROM `function_roles`"; if( @mysql_num_rows( $res=doquery($query) )>0 ) { while( $row = mysql_fetch_assoc($res) ) { $functionRole[ $row['function_id'] ][ $row['role_id'] ] = true; } } if( $editable ) { if( isset($_REQUEST['edit']) ) { echoln("

"); }else { echoln("Edit

"); } } echoln(" "); $r = 0; foreach( $allFunctions as $function_id => $function_name ) { if( $r%25==0 ) { echoln(" "); echoln(" "); foreach( $allRoles as $name ) { echoln(" "); } echoln(" "); } echoln(" "); echoln(" "); foreach( $allRoles as $role_id => $role_name ) { if( $editable && isset($_REQUEST['edit']) ) { echoln(" "); }else { if( isset($functionRole[$function_id][$role_id]) ) { echoln(" "); }else { echoln(" "); } } } echoln(" "); } echoln("
Function".$name."
".$function_name."\"Yes\"\"No\"
"); if( $editable && isset($_REQUEST['edit']) ) { echoln("

"); echoln("
"); } } admin_footer(); ?>