DocMGR PHP Cross Reference Groupware Applications

Source: /lib/accperms.php - 174 lines - 5431 bytes - Summary - Text - Print

   1  <?php
   2  /*********************************************************
   3  //        FILE: accperms.inc.php
   4  // DESCRIPTION: Contains functions that queries for
   5  //              user/employee account information
   6  //              and permssions.
   7  //
   8  //    CREATION
   9  //        DATE: 04-19-2006
  10  //
  11  //     HISTORY: 05-29-2006
  12  //            removed app-specific functions
  13  //
  14  *********************************************************/
  15  function permInsert($accountId,$level) {
  16  
  17      global $DB;
  18  
  19      if (!$level) $level = "0";
  20  
  21      $sql = "SELECT account_id FROM auth_accountperm WHERE account_id='$accountId'";
  22      $info = $DB->single($sql);
  23      
  24      //create our query
  25      $opt = null;
  26      $opt["bitset"] = $level;    //the permissions level we are storing
  27      $opt["bitval"] = $level;
  28      
  29      //if there are no entries, add the new ones, otherwise update
  30      if ($info) 
  31      {
  32        $opt["where"] = "account_id='$accountId'";
  33        $DB->update("auth_accountperm",$opt);
  34      } else {
  35        $opt["account_id"] = $accountId;
  36        $DB->insert("auth_accountperm",$opt);
  37      }
  38  
  39  }
  40  
  41  function groupPermInsert($groupId,$level) {
  42  
  43      global $DB;
  44  
  45      if (!$level) $level = "0";
  46  
  47      $sql = "SELECT group_id FROM auth_groupperm WHERE group_id='$groupId'";
  48      $info = $DB->single($sql);
  49      
  50      //create our query
  51      $opt = null;
  52      $opt["bitset"] = $level;    //the permissions level we are storing
  53  
  54      //if there are no entries, add the new ones, otherwise update
  55      if ($info) {
  56        $opt["where"] = "group_id='$groupId'";
  57        $DB->update("auth_groupperm",$opt);
  58      } else {
  59        $opt["group_id"] = $groupId;
  60        $DB->insert("auth_groupperm",$opt);
  61      }
  62  
  63  }
  64  /************************************************************************************
  65      This function displays a permissions list for an object, and checks
  66      any boxes the user belongs to
  67  ************************************************************************************/
  68  function groupPerm($conn,$optionArray) {
  69  
  70      $table = $optionArray["table"];
  71      $filter = $optionArray["filter"];
  72      $filterValue = $optionArray["filterValue"];
  73      $permArray = $optionArray["permArray"];
  74      $prefix = $optionArray["prefix"];
  75      $bitValue = $optionArray["bitValue"];
  76  
  77      //display all permissions that belong to this app
  78      $sql = "SELECT * FROM $table";
  79  
  80      if ($filter) $sql .= " WHERE $filter='$filterValue'";
  81  
  82      $sql .= " ORDER BY bitpos";
  83  
  84      $list = total_result($conn,$sql);
  85  
  86      $perm_id_array  =   &$list["id"];
  87      $perm_name_array    =   &$list["name"];
  88      $perm_bitpos_array  =   &$list["bitpos"];
  89      $perm_owner_array   =   &$list["owner"];
  90  
  91      $string = "<table border=0 cellpadding=0 cellspacing=0>";
  92  
  93      //display an error message if no perms exist for this app
  94      if (count($perm_id_array)==0) $string .= "<tr><td>No permissions are defined.</td></tr>";
  95      else {
  96  
  97          for ($num=0;$num<count($perm_id_array);$num++) {
  98  
  99              $bitSet = bitCal($perm_bitpos_array[$num]);
 100  
 101              $hideCheckbox = null;
 102  
 103              //if ($bitSet == $bitAdmin) if (!(bitset_section(BITSET,ADMIN,null))) $hideCheckbox = 1;
 104  
 105              if (!$hideCheckbox) {
 106  
 107                  if ($bitValue & $bitSet) $checked = " CHECKED ";
 108                  else $checked = null;
 109  
 110                  $string .= "<tr><td valign=top >";
 111                  $string .= "<table cellpadding=0 cellspacing=0><tr><td>";
 112  
 113                  //add extra cells if this is a subPerm
 114                  if ($perm_owner_array[$num]!="0") $string .= getOwner(  $bitpos,
 115                                              $perm_owner_array,
 116                                              $perm_bitpos_array,
 117                                              null);
 118  
 119                  //create id of checkbox
 120                  $idValue = $prefix."Perm".$perm_bitpos_array[$num];
 121  
 122                  //get id of checkbox owner if there is one
 123                  if ($perm_owner_array[$num]!=0) $passId = $prefix."Perm".$perm_owner_array[$num];
 124                  else $passId="0";
 125  
 126                  //print out the checkbox
 127                  $string .= "<input type=checkbox
 128                      id=\"".$idValue."\"
 129                      name=\"".$prefix."Permission[]\"
 130                      ".$checked."
 131                      value=\"".$bitSet."\">&nbsp;";
 132  
 133                  $string .= "</td><td colspan=5>";
 134  
 135                  $string .= $perm_name_array[$num];
 136  
 137                  $string .= "</td></tr></table>";
 138                  $string .= "</td></tr>";
 139              }
 140          }
 141      }
 142      $string .= "</table>";
 143  
 144      return $string;
 145  
 146  }
 147  //this function returns a combined list of accounts and groups, sorted by name, to display
 148  //in the list when selecting permissions for an account
 149  function returnPermAccounts($conn) {
 150  
 151      $option = null;
 152      $option["conn"] = $conn;
 153      $option["sort"] = "login";
 154  
 155      //get our accounts sorted by login
 156      $accountList = returnAccountList($option);
 157  
 158      //get our groups sorted by name
 159      $sql = "SELECT * FROM auth_groups ORDER BY name";
 160      $groupList = total_result($conn,$sql);
 161  
 162      //create a new array with the keys named like we want
 163      $aType = array_fill(0,$accountList["count"], "account");
 164      $gType = array_fill(0,$groupList["count"], "group");
 165  
 166      //merge our arrays into an array with a common key name
 167      $ret["id"] = array_merge($groupList["id"],$accountList["id"]);
 168      $ret["name"] = array_merge($groupList["name"],$accountList["login"]);
 169      $ret["type"] = array_merge($gType,$aType);
 170  
 171      return $ret;
 172  
 173  }
 174  

title

Description

title

Description

title

Description

title

title

Body