here are my errors:
string(5) "1MASO" Warning: Invalid argument supplied for foreach() in /var/www/acl/ACL-1/file.php on line 63 Warning: Invalid argument supplied for foreach() in /var/www/acl/ACL-1/file.php on line 92
acl.php
<?php
// Place in class.acl.php
class ACL{
var $list_ACL;
function fetch_ACL($level = 0){
$query = "SELECT p.privilege_id FROM tbl_user_privilege p WHERE p.privilege_group_id = ". $level ." ORDER BY p.privilege_id ASC";
$result = mysql_query($query);
$count = 1;
while($row = mysql_fetch_array($result)):
while($count < $row["privilege_id"]):
$this->list_ACL[$count] = 0;
$count++;
endwhile;
if($count == $row["privilege_id"]):
$this->list_ACL[$count] = 1;
$count++;
endif;
endwhile;
$query_acl = "SELECT count(acl_id) AS totals FROM tbl_acl";
$result_acl = mysql_query($query_acl);
$row_acl = mysql_fetch_array($result_acl);
for(; $count <= $row_acl["totals"]; $count++):
$this->list_ACL[$count] = 0;
endfor;
}
function check_ACL($acl = 0){
if($this->list_ACL[$acl] == 1):
return true;
else:
return false;
endif;
}
}
?>
File.php
<?php
$server = 'localhost';
$user = '*******';
$pass = '********';
$db = 'test_acl2';
$link = mysql_connect($server,$user,$pass);
if (!is_resource($link)) {
//$hasDB = false;
die("Could not connect to the MySQL server at localhost.");
} else {
//$hasDB = true;
mysql_select_db($db);
}
require_once "class.acl.php";
?>
<?php
// Get user data
$result = mysql_query("SELECT u.user_username, g.user_group_id FROM tbl_users u LEFT JOIN tbl_user_group g ON u.user_group = g.user_group_id WHERE u.user_id = 1");
$row = mysql_fetch_array($result);
$username = $row["user_username"];
$levels = $row["user_group_id"];
$appACL = new ACL();
$appACL->fetch_ACL($levels);
if($appACL->check_ACL(1)):
// Give access to module A
elseif($appACL->check_ACL(2)):
// Give access to module B
elseif($appACL->check_ACL(3)):
// Give access to module C
endif;
?>
<form id="acl_manager" method="POST" action="acl.php">
<?php
$query_group = "SELECT * FROM tbl_user_group";
$result_group = mysql_query($query_group);
while($row_group = mysql_fetch_array($result_group)):
$levels[$row_group["user_group_id"]] = $row_group["user_group_name"];
endwhile;
?>
<table>
<thead>
<tr>
<th>Module</th>
<?php
var_dump($levels);
foreach($levels as $value):
print "<th>".$value."</th>";
endforeach;
?>
</tr>
</thead>
<tbody>
<?php
$query_acl = "SELECT * FROM tbl_acl ORDER BY acl_id ASC";
$result_acl = mysql_query($query_acl);
$count = 0;
while($row_acl = mysql_fetch_array($result_acl)):
$menu_id[$count] = $row_acl["acl_id"];
$menu_runid[$row_acl["acl_id"]] = $count;
$menu_name[$count] = $row_acl["acl_modules"];
$count++;
endwhile;
$query_acp = "SELECT * FROM tbl_user_privilege";
$result_acp = mysql_query($query_acp);
while($row_acp = mysql_fetch_array($result_acp)):
$this_id = $menu_runid[$row_acp["privilege_acl_id"]];
$menu_access[$this_id["privilege_id"][$row_acp["privilege_group_id"]]] = 1;
endwhile;
$counts = 0;
for($list = 0; $list < count($menu_id); $list++):
print "<tr>";
print "<td><strong>".$menu_name[$list]."</strong></td>";
foreach($levels as $level => $name):
$checked = ((isset($menu_access[$list][$level]) && $menu_access[$list][$level] == 1) ? "checked='checked'" : "");
print "<td><input type='checkbox'".$checked." id='menu_access-".$counts." name='menu_access[".$counts."]' value='1' />
<input type='hidden' name='menu_id[".$counts."]' value='".$menu_id[$list]."' />
<input type='hidden' name='menu_level[".$list."]' value='".$level."' /></td>";
$counts++;
endforeach;
print "</tr>";
endfor;
?>
</tbody>
</table>
<div></div>
</form>
<?php
/*
// Validate post form command
mysql_query("TRUNCATE TABLE tbl_user_privilege");
$acl_id = $_POST["menu_id"];
$acl_access = $_POST["menu_access"];
$acl_group = $_POST["menu_level"];
for($i=0; $i < count($acl_id); $i++):
$bool = ((isset($acl_access[$i]) and $acl_access[$i] == 1) ? 1 : 0);
if($bool == 1):
mysql_query("INSERT INTO tbl_user_privilege (privilege_acl_id, privilege_group_id) VALUES (".$acl_id[$i].", ".$acl_group[$i].")");
endif;
endfor;
*/
?>