home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / dotproject / modules / departments / addedit.php next >
Encoding:
PHP Script  |  2003-12-17  |  6.0 KB  |  175 lines

  1. <?php /* DEPARTMENTS $Id: addedit.php,v 1.18 2003/12/17 02:03:37 robertoibarra Exp $ */
  2. // Add / Edit Company
  3. $dept_id = isset($_GET['dept_id']) ? $_GET['dept_id'] : 0;
  4. $company_id = isset($_GET['company_id']) ? $_GET['company_id'] : 0;
  5.  
  6. // check permissions for this department
  7. $canEdit = !getDenyEdit( $m, $dept_id );
  8. if (!$canEdit) {
  9.     $AppUI->redirect( "m=public&a=access_denied" );
  10. }
  11.  
  12. // pull data for this department
  13. $sql = "
  14. SELECT departments.*, company_name
  15. FROM departments
  16. LEFT JOIN companies ON company_id = dept_company
  17. WHERE dept_id = $dept_id
  18. ";
  19. if (!db_loadHash( $sql, $drow ) && $dept_id > 0) {
  20.     $titleBlock = new CTitleBlock( 'Invalid Department ID', 'users.gif', $m, "$m.$a" );
  21.     $titleBlock->addCrumb( "?m=companies", "companies list" );
  22.     if ($company_id) {
  23.         $titleBlock->addCrumb( "?m=companies&a=view&company_id=$company_id", "view this company" );
  24.     }
  25.     $titleBlock->show();
  26. } else {
  27.     ##echo $sql.db_error();##
  28.     $company_id = $dept_id ? $drow['dept_company'] : $company_id;
  29.  
  30.     // check if valid company
  31.     $sql = "SELECT company_name FROM companies WHERE company_id = $company_id";
  32.     $company_name = db_loadResult( $sql );
  33.     if (!$dept_id && $company_name === null) {
  34.         $AppUI->setMsg( 'badCompany', UI_MSG_ERROR );
  35.         $AppUI->redirect();
  36.     }
  37.  
  38.     // collect all the departments in the company
  39.     $depts = array( 0 => '' );
  40.     if ($company_id) {
  41.         $sql = "SELECT dept_id,dept_name,dept_parent FROM departments WHERE dept_company=$company_id AND dept_id != $dept_id";
  42.         $depts = arrayMerge( array( '0'=>array( 0, '- '.$AppUI->_('Select Unit').' -', -1 ) ), db_loadHashList( $sql, 'dept_id' ));
  43.     ##echo $sql.db_error();##
  44.     }
  45.  
  46.     // collect all the users for the department owner list
  47.     $sql = "SELECT user_id,CONCAT_WS(' ',user_first_name,user_last_name) FROM users ORDER BY user_first_name,user_last_name";
  48.     $owners = arrayMerge( array( '0'=>'' ), db_loadHashList( $sql ) );
  49.  
  50. // setup the title block
  51.     $ttl = $company_id > 0 ? "Edit Department" : "Add Department";
  52.     $titleBlock = new CTitleBlock( $ttl, 'users.gif', $m, "$m.$a" );
  53.     $titleBlock->addCrumb( "?m=companies", "companies list" );
  54.     $titleBlock->addCrumb( "?m=companies&a=view&company_id=$company_id", "view this company" );
  55.     $titleBlock->show();
  56. ?>
  57. <script language="javascript">
  58. function testURL( x ) {
  59.     var test = "document.editFrm.dept_url.value";
  60.     test = eval(test);
  61.     if (test.length > 6) {
  62.         newwin = window.open( "http://" + test, 'newwin', '' );
  63.     }
  64. }
  65.  
  66. function submitIt() {
  67.     var form = document.editFrm;
  68.     if (form.dept_name.value.length < 2) {
  69.         alert( '<?php echo $AppUI->_( 'deptValidName' );?>' );
  70.         form.dept_name.focus();
  71.     } else {
  72.         form.submit();
  73.     }
  74. }
  75. </script>
  76.  
  77. <table cellspacing="0" cellpadding="4" border="0" width="98%" class="std">
  78. <form name="editFrm" action="?m=departments" method="post">
  79.     <input type="hidden" name="dosql" value="do_dept_aed" />
  80.     <input type="hidden" name="dept_id" value="<?php echo $dept_id;?>" />
  81.     <input type="hidden" name="dept_company" value="<?php echo $company_id;?>" />
  82.  
  83. <tr>
  84.     <td align="right" nowrap><?php echo $AppUI->_( 'Department Company' );?>:</td>
  85.     <td><strong><?php echo $company_name;?></strong></td>
  86. </tr>
  87. <tr>
  88.     <td align="right" nowrap><?php echo $AppUI->_( 'Department Name' );?>:</td>
  89.     <td>
  90.         <input type="text" class="text" name="dept_name" value="<?php echo @$drow["dept_name"];?>" size="50" maxlength="255" />
  91.         <span class="smallNorm">(<?php echo $AppUI->_( 'required' );?>)</span>
  92.     </td>
  93. </tr>
  94. <tr>
  95.     <td align="right" nowrap><?php echo $AppUI->_( 'Phone' );?>:</td>
  96.     <td>
  97.         <input type="text" class="text" name="dept_phone" value="<?php echo @$drow["dept_phone"];?>" maxlength="30" />
  98.     </td>
  99. </tr>
  100. <tr>
  101.     <td align="right" nowrap><?php echo $AppUI->_( 'Fax' );?>:</td>
  102.     <td>
  103.         <input type="text" class="text" name="dept_fax" value="<?php echo @$drow["dept_fax"];?>" maxlength="30" />
  104.     </td>
  105. </tr>
  106. <tr>
  107.     <td align="right"><?php echo $AppUI->_( 'Address' );?>1:</td>
  108.     <td><input type="text" class="text" name="dept_address1" value="<?php echo @$drow["dept_address1"];?>" size="50" maxlength="255" /></td>
  109. </tr>
  110. <tr>
  111.     <td align="right"><?php echo $AppUI->_( 'Address' );?>2:</td>
  112.     <td><input type="text" class="text" name="dept_address2" value="<?php echo @$drow["dept_address2"];?>" size="50" maxlength="255"></td>
  113. </tr>
  114. <tr>
  115.     <td align="right"><?php echo $AppUI->_( 'City' );?>:</td>
  116.     <td><input type="text" class="text" name="dept_city" value="<?php echo @$drow["dept_city"];?>" size="50" maxlength="50"></td>
  117. </tr>
  118. <tr>
  119.     <td align="right"><?php echo $AppUI->_( 'State' );?>:</td>
  120.     <td><input type="text" class="text" name="dept_state" value="<?php echo @$drow["dept_state"];?>" maxlength="50"></td>
  121. </tr>
  122. <tr>
  123.     <td align="right"><?php echo $AppUI->_( 'Zip' );?>:</td>
  124.     <td><input type="text" class="text" name="dept_zip" value="<?php echo @$drow["dept_zip"];?>" maxlength="15"></td>
  125. </tr>
  126. <tr>
  127.     <td align="right"><?php echo $AppUI->_( 'URL' );?><A name="x"></a></td>
  128.     <td>
  129.         <input type="text" class="text" value="<?php echo @$drow["dept_url"];?>" name="dept_url" size="50" maxlength="255">
  130.         <a href="#x" onClick="testURL('dept_url')">[<?php echo $AppUI->_( 'test' );?>]</a>
  131.     </td>
  132. </tr>
  133.  
  134. <?php
  135. if (count( $depts )) {
  136. ?>
  137. <tr>
  138.     <td align="right" nowrap><?php echo $AppUI->_( 'Department Parent' );?>:</td>
  139.     <td>
  140. <?php
  141.     echo arraySelectTree( $depts, 'dept_parent', 'class=text size=1', @$drow["dept_parent"] );
  142. ?>
  143.     </td>
  144. </tr>
  145. <?php } else {
  146.     echo '<input type="hidden" name="dept_parent" value="0">';
  147. }
  148. ?>
  149. <tr>
  150.     <td align="right"><?php echo $AppUI->_( 'Owner' );?>:</td>
  151.     <td>
  152. <?php
  153.     echo arraySelect( $owners, 'dept_owner', 'size="1" class="text"', $drow["dept_owner"] );
  154. ?>
  155.     </td>
  156. </tr>
  157. <tr>
  158.     <td align="right" valign="top" nowrap><?php echo $AppUI->_( 'Description' );?>:</td>
  159.     <td align="left">
  160.         <textarea cols="70" rows="10" class="textarea" name="dept_desc"><?php echo @$drow["dept_desc"];?></textarea>
  161.     </td>
  162. </tr>
  163.  
  164. <tr>
  165.     <td>
  166.         <input type="button" value="<?php echo $AppUI->_( 'back' );?>" class="button" onClick="javascript:history.back(-1);" />
  167.     </td>
  168.     <td align="right">
  169.         <input type="button" value="<?php echo $AppUI->_( 'submit' );?>" class="button" onClick="submitIt()" />
  170.     </td>
  171. </tr>
  172. </form>
  173. </table>
  174. <?php } ?>
  175.