home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / dotproject / modules / companies / vw_depts.php < prev    next >
Encoding:
PHP Script  |  2003-12-17  |  2.3 KB  |  82 lines

  1. <?php /* COMPANIES $Id: vw_depts.php,v 1.11 2003/12/17 02:41:38 robertoibarra Exp $ */
  2. ##
  3. ##    Companies: View Projects sub-table
  4. ##
  5. GLOBAL $AppUI, $company_id, $canEdit;
  6.  
  7. $sql = "
  8. SELECT departments.*, COUNT(user_department) dept_users
  9. FROM departments
  10. LEFT JOIN users ON user_department = dept_id
  11. WHERE dept_company = $company_id
  12. GROUP BY dept_id
  13. ORDER BY dept_parent,dept_name
  14. ";
  15. ##echo $sql;
  16.  
  17. function showchild( &$a, $level=0 ) {
  18.     global $AppUI;
  19.     $s = '';
  20.  
  21.     $s .= '<td>';
  22.     $s .= '<a href="./index.php?m=departments&a=addedit&dept_id='.$a["dept_id"].'" title="'.$AppUI->_('edit').'">';
  23.     $s .= dPshowImage( './images/icons/stock_edit-16.png', 16, 16, '' );
  24.     $s .= '</td>';
  25.     $s .= '<td>';
  26.  
  27.     for ($y=0; $y < $level; $y++) {
  28.         if ($y+1 == $level) {
  29.             $s .= '<img src="./images/corner-dots.gif" width="16" height="12" border="0">';
  30.         } else {
  31.             $s .= '<img src="./images/shim.gif" width="16" height="12" border="0">';
  32.         }
  33.     }
  34.  
  35.     $s .= '<a href="./index.php?m=departments&a=view&dept_id='.$a["dept_id"].'">'.$a["dept_name"].'</a>';
  36.     $s .= '</td>';
  37.     $s .= '<td align="center">'.($a["dept_users"] ? $a["dept_users"] : '').'</td>';
  38.  
  39.     echo "<tr>$s</tr>";
  40. }
  41.  
  42. function findchild( &$tarr, $parent, $level=0 ){
  43.     $level = $level+1;
  44.     $n = count( $tarr );
  45.     for ($x=0; $x < $n; $x++) {
  46.         if($tarr[$x]["dept_parent"] == $parent && $tarr[$x]["dept_parent"] != $tarr[$x]["dept_id"]){
  47.             showchild( $tarr[$x], $level );
  48.             findchild( $tarr, $tarr[$x]["dept_id"], $level);
  49.         }
  50.     }
  51. }
  52.  
  53.  
  54. $s = '<table width="100%" border="0" cellpadding="2" cellspacing="1" class="tbl">';
  55. $s .= '<tr>';
  56. $rows = db_loadList( $sql, NULL );
  57. if (count( $rows)) {
  58.     $s .= '<th> </th>';
  59.     $s .= '<th width="100%">'.$AppUI->_( 'Name' ).'</th>';
  60.     $s .= '<th>'.$AppUI->_( 'Users' ).'</th>';
  61. } else {
  62.     $s .= $AppUI->_('No data available');
  63. }
  64.  
  65. $s .= '</tr>';
  66. echo $s;
  67.  
  68. foreach ($rows as $row) {
  69.     if ($row["dept_parent"] == 0) {
  70.         showchild( $row );
  71.         findchild( $rows, $row["dept_id"] );
  72.     }
  73. }
  74.  
  75. echo '<td colspan="3" nowrap="nowrap" rowspan="99" align="right" valign="top" style="background-color:#ffffff">';
  76. if ($canEdit) {
  77.     echo '<input type="button" class=button value="'.$AppUI->_( 'new department' ).'" onClick="javascript:window.location=\'./index.php?m=departments&a=addedit&company_id='.$company_id.'\';">';
  78. }
  79. echo '</td>';
  80.  
  81. echo '</table>';
  82. ?>