Location: PHPKode > scripts > phpMyAccess > phpmyaccess-1.5.3/phpmyaccess/user_menu_pages.php
<?php
// XML spec conformance tested OK

function MyHeader ($menutitle) {
echo("<?xml version=\"1.0\"?>
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
    \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\">
<head>
  <title>$menutitle</title>
</head>
<body bgcolor=\"#ffeb10\">
  <div class=\"main\">
  <h3>$menutitle</h3>
<hr width=\"30%\" align=\"left\"></hr><br/>\n");
}

function displaypage() {
  reset($GLOBALS['qryusers']);
  reset($GLOBALS['qrypages']);
  reset($GLOBALS['qryumenu']);
  echo "<form action=\"user_menu_pages.php\" method=\"post\">\n";
  echo "  <table border=\"2\">\n";
  echo "   <tr>\n";
  echo "   <th>Page</th>\n";
  while (list ($key, $name) = each ($GLOBALS['qryusers'])) {
    echo "   <th>" . $name . "</th>\n";
  }
  echo "   </tr>\n";
  reset($GLOBALS['qryusers']);
  while (list ($key, $val) = each ($GLOBALS['qrypages'])) {
     echo "   <tr>\n     <td>$val</td>\n";
     while (list ($num, $name) = each ($GLOBALS['qryusers'])) {
         $tmpvar = $name . "_" . $val;
         echo "     <td><input type=\"checkbox\" name=\"$tmpvar\"";
         if ($GLOBALS['qryumenu'][$name][$val]) {
            echo " checked=\"checked\" ";
         }
         echo "/></td>\n";
     }
     echo "   </tr>\n";
     reset($GLOBALS['qryusers']);
  }
  echo "  </table>\n";
  echo "  <hr  width=\"30%\" align=\"left\"/>\n";
  echo "  <table>\n";
  echo "  <tr>\n";
  echo "    <td align=\"left\">\n";
  echo "      <input type=\"submit\" name=\"update\" value=\"update\"/>";
  echo "    </td>\n";
  echo "   </tr>\n";
  echo "  </table>\n";
  echo "</form>\n";
}

function DoFooter() {
echo " </div>
  <p/>
  <hr  width=\"30%\" align=\"left\"/>
  <table>
   <tr>
     <td><a href=\"index.php\" name=\"link\">Main Page</a></td>
     <td> &nbsp;&nbsp;&nbsp; </td>
     <td><a href=\"index.php?page=menus\" name=\"link\">Menus Maintenance Page</a></td>
   </tr>
  </table>\n";
  echo "<br/>\n<b> User : ".$GLOBALS['auth_user']."</b>\n<br/>\n";
  echo "</body>\n</html>\n";
}

function Dbconnect() {
  $GLOBALS['dbl'] = mysql_connect($GLOBALS['opt']['hn'],$GLOBALS['opt']['un'],$GLOBALS['opt']['pw'])
    or die ('<h1>Could not connect to MySQL</h1>'."\n");
  if (!isset($GLOBALS['opt']['db'])) { 
     pma_errpage ("No Database defined");
  }
}

function DoAuth () {
  if ($GLOBALS['auth'] >= 1) {
     $GLOBALS['auth_level'] = 0;
     include 'auth.inc.php';
     if ((!$GLOBALS['auth_level']) || ($GLOBALS['auth_level'] < $GLOBALS['auth'])) {
       // this can be a function to display something nicer, of course
       pma_errpage("Access Denied !!");
     }
  }
}

function GetUserlist () {
  $query = "Select " . $GLOBALS['opt']['userfldname']. " from " . $GLOBALS['opt']['userdb'] . " ORDER BY " . $GLOBALS['opt']['userfldname'] . " ASC";
  $res = mysql_db_query($GLOBALS['opt']['db'],$query);
  if (!$res) {
     pma_errpage ("User Select " . mysql_errno().": ".mysql_error()." Bad Query or DB error");
  }
  while(list($row) = mysql_fetch_row($res)) {
    $GLOBALS['qryusers'][] = $row;
    pma_debug ("User : " . $row[0] );
  }
}

function GetMenuPages () {
  $query = "Select " . $GLOBALS['opt']['pagesfldname'] . ", " . $GLOBALS['opt']['pagesfldId'] . " from " . $GLOBALS['opt']['pagesdb'] . " ORDER BY " . $GLOBALS['opt']['pagesfldname'] . " ASC";
  $res = mysql_db_query($GLOBALS['opt']['db'],$query);
  if (!$res) {
     pma_errpage ("Page Select " . mysql_errno().": ".mysql_error()." Bad Query or DB error");
  }
  while(list($name, $id) = mysql_fetch_row($res)) {
    $GLOBALS['qrypages'][$id] = $name;
    pma_debug ($name . " : " . $id . "=" . $GLOBALS['qrypages'][$id] );
  }
}

function GetUserMenuData () {
  $query = "Select " .$GLOBALS['opt']['upagesfldId'] . ", " . $GLOBALS['opt']['upagesfldname'] . ", " .$GLOBALS['opt']['upagesfldpage'] .
               " from " . $GLOBALS['opt']['upagesdb'] . " ORDER BY " . $GLOBALS['opt']['upagesfldname'] . " ASC";
  $res = mysql_db_query($GLOBALS['opt']['db'],$query);
  if (!$res) {
     pma_errpage ("User Page Select " . mysql_errno().": ".mysql_error()." Bad Query or DB error");
  }
  while(list($idno, $logname, $pagename) = mysql_fetch_row($res)) {
    $GLOBALS['qryumenu'][$logname][$pagename] = $idno;
    pma_debug ( $logname . " has : $pagename Value : " . $GLOBALS['qryumenu'][$logname][$pagename] );
  }
}

function DoCreateUmenu ($logname, $menu) {
  $query = "INSERT INTO " . $GLOBALS['opt']['upagesdb'] . " (" . $GLOBALS['opt']['upagesfldname'] . ", " .$GLOBALS['opt']['upagesfldpage']
                 . ") VALUES  ('" . $logname . "', '" . $menu . "')";
  $res = mysql_db_query($GLOBALS['opt']['db'],$query);
  if (!$res) {
     pma_errpage ($query . " User Page INSERT " . mysql_errno().": ".mysql_error()." Bad Query or DB error");
  }
  $GLOBALS['qryumenu']='';//empty array so it can be cleanly reloaded
  GetUserMenuData();
}

function DoDeleteUmenu ($umenu_ID) {
  $query = "DELETE FROM " . $GLOBALS['opt']['upagesdb'] . " WHERE " . $GLOBALS['opt']['upagesfldId'] . "=" . $umenu_ID;
  $res = mysql_db_query($GLOBALS['opt']['db'],$query);
  if (!$res) {
     pma_errpage ($query . " User Page DELETE " . mysql_errno().": ".mysql_error(). " Bad Query or DB error");
  }
  $GLOBALS['qryumenu']='';//empty array so it can be cleanly reloaded
  GetUserMenuData();  
}

function displayvars() {
  reset($GLOBALS['qrypages']);
  reset($GLOBALS['qryusers']);
  while (list ($key, $val) = each ($GLOBALS['qrypages'])) {
     while (list ($num, $name) = each ($GLOBALS['qryusers'])) {
         $tmpvar = $name . "_" . $val;
         echo $tmpvar . " set to : " . $_POST[$tmpvar] . "<br> \n";
     }
     reset($GLOBALS['qryusers']);
  }
}

function getpostvars() {
  reset($GLOBALS['qrypages']);
  reset($GLOBALS['qryusers']);
  while (list ($key, $val) = each ($GLOBALS['qrypages'])) {
     while (list ($num, $name) = each ($GLOBALS['qryusers'])) {
         $tmpvar = $name . "_" . $val;
         // echo $tmpvar . " " . $_POST[$tmpvar]. " : ";
         if($_POST[$tmpvar]=='on') {
            if ($GLOBALS['qryumenu'][$name][$val]) {
               // record exists nothing to do
               pma_debug ("Exists $name and $val");
            } else {
               // create it, add to create list
               pma_debug ("Create $name and $val" );
               DoCreateUmenu($name, $val);
            }
         } else {
            if ($GLOBALS['qryumenu'][$name][$val]) {
               // record exists delete it, add to delete list
               pma_debug ("Delete $name and $val");
               DoDeleteUmenu($GLOBALS['qryumenu'][$name][$val]);
            } else {
               // No record
               pma_debug ("Not present $name and $val");
            }
         }
     }
     reset($GLOBALS['qryusers']);
  }
}

function DisplayPostvars() {
  while (list ($num, $name) = each ($_POST)) {
     echo $num . " set to : " . $name . "<br> \n";
  }
}

//-------------MAIN
$opt['pagesdb']='menu_pages';
$opt['pagesfldname']='menu_page_name';
$opt['pagesfldId']='menu_page_ID';

$opt['userdb']='useraccounts';
$opt['userfldname']='user_logname';
$opt['userfldId']='user_ID';

$opt['upagesdb']='umenu_pages';
$opt['upagesfldId']='umenu_ID';
$opt['upagesfldname']='user_logname';
$opt['upagesfldpage']='menu_page_name';


include 'dbaccess.php';
include 'pma-debuginc.php';
$debug=0;
$auth = '999';

Dbconnect();
DoAuth();

MyHeader("User Menu Pages Setup");

GetMenuPages();
GetUserlist();
GetUserMenuData();

if ($_POST['update']=="update") {
   getpostvars();
   //GetUserMenuData();
} 

DisplayPage();
DoFooter();
?>
Return current item: phpMyAccess