home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / dotproject / modules / admin / vw_usr_roles.php < prev    next >
Encoding:
PHP Script  |  2003-10-02  |  6.8 KB  |  235 lines

  1. <?php /* ADMIN $Id: vw_usr_roles.php,v 1.4 2003/10/02 08:59:42 gregorerhardt Exp $ */
  2. GLOBAL $AppUI, $user_id, $canEdit, $tab;
  3.  
  4. //$roles
  5.  
  6.  
  7.  
  8.  
  9. $pvs = array(
  10. '-1' => 'read-write',
  11. '0' => 'deny',
  12. '1' => 'read only'
  13. );
  14.  
  15.  
  16. //Pull User perms
  17. $sql = "
  18. SELECT u.user_id, u.user_username,
  19.     p.permission_item, p.permission_id, p.permission_grant_on, p.permission_value,
  20.     c.company_id, c.company_name,
  21.     pj.project_id, pj.project_name,
  22.     t.task_id, t.task_name,
  23.     f.file_id, f.file_name,
  24.     u2.user_id, u2.user_username
  25. FROM users u, permissions p
  26. LEFT JOIN companies c ON c.company_id = p.permission_item and p.permission_grant_on = 'companies'
  27. LEFT JOIN projects pj ON pj.project_id = p.permission_item and p.permission_grant_on = 'projects'
  28. LEFT JOIN tasks t ON t.task_id = p.permission_item and p.permission_grant_on = 'tasks'
  29. LEFT JOIN files f ON f.file_id = p.permission_item and p.permission_grant_on = 'files'
  30. LEFT JOIN users u2 ON u2.user_id = p.permission_item and p.permission_grant_on = 'users'
  31. LEFT JOIN forums fm ON fm.forum_id = p.permission_item and p.permission_grant_on = 'forums'
  32. WHERE u.user_id = p.permission_user
  33.     AND u.user_id = $user_id
  34. ";
  35.  
  36. $res = db_exec( $sql );
  37.  
  38. //pull the projects into an temp array
  39. $tarr = array();
  40. while ($row = db_fetch_assoc( $res )) {
  41.     $item = @$row[@$pgos[$row['permission_grant_on']]];
  42.     if (!$item) {
  43.         $item = $row['permission_item'];
  44.     }
  45.     if ($item == -1) {
  46.         $item = 'all';
  47.     }
  48.     $tarr[] = array_merge( $row, array( 'grant_item'=>$item ) );
  49. }
  50.  
  51. // read the installed modules
  52. $modules = arrayMerge( array( 'all'=>'all' ), $AppUI->getActiveModules( 'modules' ));
  53. ?>
  54.  
  55. <script language="javascript">
  56. function editPerm( id, gon, it, vl, nm ) {
  57. /*
  58.     id = Permission_id
  59.     gon =permission_grant_on
  60.     it =permission_item
  61.     vl =permission_value
  62.     nm = text representation of permission_value
  63. */
  64. //alert( 'id='+id+'\ngon='+gon+'\nit='+it+'\nvalue='+vl+'\nnm='+nm);
  65.     var f = document.frmPerms;
  66.  
  67.     f.sqlaction2.value="edit";
  68.     
  69.     f.permission_id.value = id;
  70.     f.permission_item.value = it;
  71.     f.permission_item_name.value = nm;
  72.     for(var i=0, n=f.permission_grant_on.options.length; i < n; i++) {
  73.         if (f.permission_grant_on.options[i].value == gon) {
  74.             f.permission_grant_on.selectedIndex = i;
  75.             break;
  76.         }
  77.     }
  78.     f.permission_value.selectedIndex = vl+1;
  79.     f.permission_item_name.value = nm;
  80. }
  81.  
  82. function clearIt(){
  83.     var f = document.frmPerms;
  84.     f.sqlaction2.value = "add";
  85.     f.permission_id.value = 0;
  86.     f.permission_grant_on.selectedIndex = 0;
  87. }
  88.  
  89. function delIt(id) {
  90.     if (confirm( 'Are you sure you want to delete this permission?' )) {
  91.         var f = document.frmPerms;
  92.         f.del.value = 1;
  93.         f.permission_id.value = id;
  94.         f.submit();
  95.     }
  96. }
  97.  
  98. var tables = new Array;
  99. tables['companies'] = 'companies';
  100. tables['departments'] = 'departments';
  101. tables['projects'] = 'projects';
  102. tables['tasks'] = 'tasks';
  103. tables['forums'] = 'forums';
  104.  
  105. function popPermItem() {
  106.     var f = document.frmPerms;
  107.     var pgo = f.permission_grant_on.options[f.permission_grant_on.selectedIndex].value;
  108.     if (!(pgo in tables)) {
  109.         alert( 'No list associated with this Module.' );
  110.         return;
  111.     }
  112.     window.open('./index.php?m=public&a=selector&dialog=1&callback=setPermItem&table=' + tables[pgo], 'selector', 'left=50,top=50,height=250,width=400,resizable')
  113. }
  114.  
  115. // Callback function for the generic selector
  116. function setPermItem( key, val ) {
  117.     var f = document.frmPerms;
  118.     if (val != '') {
  119.         f.permission_item.value = key;
  120.         f.permission_item_name.value = val;
  121.     } else {
  122.         f.permission_item.value = '-1';
  123.         f.permission_item_name.value = 'all';
  124.     }
  125. }
  126. </script>
  127.  
  128. <table width="100%" border="0" cellpadding="2" cellspacing="0">
  129. <tr><td width="50%" valign="top">
  130.  
  131. <table width="100%" border="0" cellpadding="2" cellspacing="1" class="tbl">
  132. <tr>
  133.     <th> </th>
  134.     <th nowrap="nowrap"><?php echo $AppUI->_('Module');?></th>
  135.     <th width="100%"><?php echo $AppUI->_('Item');?></th>
  136.     <th nowrap><?php echo $AppUI->_('Type');?></th>
  137.     <th> </th>
  138. </tr>
  139.  
  140. <?php
  141. foreach ($tarr as $row){
  142.     $buf = '';
  143.  
  144.     $buf .= '<td nowrap>';
  145.     if (!$canEdit) {
  146.         $buf .= "<a href=# onClick=\"editPerm({$row['permission_id']},'{$row['permission_grant_on']}',{$row['permission_item']},{$row['permission_value']},'{$row['grant_item']}');\" title=\"".$AppUI->_('edit')."\">"
  147.             . dPshowImage( './images/icons/stock_edit-16.png', 16, 16, '' )
  148.             . "</a>";
  149.     }
  150.     $buf .= '</td>';
  151.  
  152.     $style = '';
  153.     if($row['permission_grant_on'] == "all" && $row['permission_item'] == -1 && $row['permission_value'] == -1) {
  154.         $style =  'style="background-color:#ffc235"';
  155.     } else if($row['permission_item'] == -1 && $row['permission_value'] == -1) {
  156.         $style = 'style="background-color:#ffff99"';
  157.     }
  158.  
  159.     $buf .= "<td $style>" . $row['permission_grant_on'] . "</td>";
  160.  
  161.     $buf .= "<td>" . $row['grant_item'] . "</td><td nowrap>" . $pvs[$row['permission_value']] . "</td>";
  162.  
  163.     $buf .= '<td nowrap>';
  164.     if (!$canEdit) {
  165.         $buf .= "<a href=\"javascript:delIt({$row['permission_id']});\" title=\"".$AppUI->_('delete')."\">"
  166.             . dPshowImage( './images/icons/stock_delete-16.png', 16, 16, '' )
  167.             . "</a>";
  168.     }
  169.     $buf .= '</td>';
  170.     
  171.     echo "<tr>$buf</tr>";
  172. }
  173. ?>
  174. </table>
  175.  
  176. <table>
  177. <tr>
  178.     <td><?php echo $AppUI->_('Key');?>:</td>
  179.     <td>   </td>
  180.     <td bgcolor="#ffc235">   </td>
  181.     <td>=<?php echo $AppUI->_('Super User');?></td>
  182.     <td>   </td>
  183.     <td bgcolor="#ffff99">   </td>
  184.     <td>=<?php echo $AppUI->_('full access to module');?></td>
  185. </tr>
  186. </table>
  187.  
  188.  
  189. </td><td width="50%" valign="top">
  190.  
  191. <?php if (!$canEdit) {?>
  192.  
  193. <table cellspacing="1" cellpadding="2" border="0" class="std" width="100%">
  194. <form name="frmPerms" method="post" action="?m=admin">
  195.     <input type="hidden" name="del" value="0">
  196.     <input type="hidden" name="dosql" value="do_userrole_aed">
  197.     <input type="hidden" name="user_id" value="<?php echo $user_id;?>">
  198.     <input type="hidden" name="permission_user" value="<?php echo $user_id;?>">
  199.     <input type="hidden" name="permission_id" value="0">
  200.     <input type="hidden" name="permission_item" value="-1">
  201. <tr>
  202.     <th colspan="2"><?php echo $AppUI->_('Add or Edit Permissions');?></th>
  203. </tr>
  204. <tr>
  205.     <td nowrap align="right"><?php echo $AppUI->_('Module');?>:</td>
  206.     <td width="100%"><?php echo arraySelect($modules, 'permission_grant_on', 'size="1" class="text"', 'all');?></td>
  207. </tr>
  208. <tr>
  209.     <td nowrap align="right"><?php echo $AppUI->_('Item');?>:</td>
  210.     <td>
  211.         <input type="text" name="permission_item_name" class="text" size="30" value="all" disabled>
  212.         <input type="button" name="" class="text" value="..." onclick="popPermItem();">
  213.     </td>
  214. </tr>
  215. <tr>
  216.     <td nowrap align="right"><?php echo $AppUI->_('Level');?>:</td>
  217.     <td><?php echo arraySelect($pvs, 'permission_value', 'size="1" class="text"', 0);?></td>
  218. </tr>
  219. <tr>
  220.     <td>
  221.         <input type="reset" value="<?php echo $AppUI->_('clear');?>" class="button" name="sqlaction" onClick="clearIt();">
  222.     </td>
  223.     <td align="right">
  224.         <input type="submit" value="<?php echo $AppUI->_('add');?>" class="button" name="sqlaction2">
  225.     </td>
  226. </tr>
  227. </table>
  228.  
  229. <?php } ?>
  230.  
  231. </td>
  232. </tr>
  233. </form>
  234. </table>
  235.