home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / dotproject / modules / companies / addedit.php next >
Encoding:
PHP Script  |  2004-01-11  |  7.3 KB  |  197 lines

  1. <?php /* COMPANIES $Id: addedit.php,v 1.39 2004/01/10 21:18:47 gregorerhardt Exp $ */
  2. $company_id = intval( dPgetParam( $_GET, "company_id", 0 ) );
  3.  
  4. // check permissions for this company
  5. $canEdit = !getDenyEdit( $m, $company_id );
  6. if (!$canEdit) {
  7.     $AppUI->redirect( "m=public&a=access_denied" );
  8. }
  9.  
  10. // load the company types
  11. $types = dPgetSysVal( 'CompanyType' );
  12.  
  13. // load the record data
  14. $sql = "
  15. SELECT companies.*,users.user_first_name,users.user_last_name
  16. FROM companies
  17. LEFT JOIN users ON users.user_id = companies.company_owner
  18. WHERE companies.company_id = $company_id
  19. ";
  20.  
  21. $obj = null;
  22. if (!db_loadObject( $sql, $obj ) && $company_id > 0) {
  23.     $AppUI->setMsg( 'Company' );
  24.     $AppUI->setMsg( "invalidID", UI_MSG_ERROR, true );
  25.     $AppUI->redirect();
  26. }
  27.  
  28. // collect all the users for the company owner list
  29. $owners = array( '0'=>'' );
  30. $sql = "SELECT user_id,CONCAT_WS(' ',user_first_name,user_last_name) FROM users ORDER BY user_first_name";
  31. $owners = db_loadHashList( $sql );
  32.  
  33. // setup the title block
  34. $ttl = $company_id > 0 ? "Edit Company" : "Add Company";
  35. $titleBlock = new CTitleBlock( $ttl, 'handshake.png', $m, "$m.$a" );
  36. $titleBlock->addCrumb( "?m=companies", "companies list" );
  37. if ($company_id != 0)
  38.   $titleBlock->addCrumb( "?m=companies&a=view&company_id=$company_id", "view this company" );
  39. $titleBlock->show();
  40. ?>
  41.  
  42. <script language="javascript">
  43. function submitIt() {
  44.     var form = document.changeclient;
  45.     if (form.company_name.value.length < 3) {
  46.         alert( "<?php echo $AppUI->_('companyValidName');?>" );
  47.         form.company_name.focus();
  48.     } else {
  49.         form.submit();
  50.     }
  51. }
  52.  
  53. function testURL( x ) {
  54.     var test = "document.changeclient.company_primary_url.value";
  55.     test = eval(test);
  56.     if (test.length > 6) {
  57.         newwin = window.open( "http://" + test, 'newwin', '' );
  58.     }
  59. }
  60. </script>
  61.  
  62. <table cellspacing="1" cellpadding="1" border="0" width="100%" class="std">
  63. <form name="changeclient" action="?m=companies" method="post">
  64.     <input type="hidden" name="dosql" value="do_company_aed" />
  65.     <input type="hidden" name="company_id" value="<?php echo $company_id;?>" />
  66.  
  67. <tr>
  68.     <td align="right"><?php echo $AppUI->_('Company Name');?>:</td>
  69.     <td>
  70.         <input type="text" class="text" name="company_name" value="<?php echo dPformSafe(@$obj->company_name);?>" size="50" maxlength="255" /> (<?php echo $AppUI->_('required');?>)
  71.     </td>
  72. </tr>
  73. <tr>
  74.     <td align="right"><?php echo $AppUI->_('Email');?>:</td>
  75.     <td>
  76.         <input type="text" class="text" name="company_email" value="<?php echo dPformSafe(@$obj->company_email);?>" size="30" maxlength="255" />
  77.     </td>
  78. </tr>
  79. <tr>
  80.     <td align="right"><?php echo $AppUI->_('Phone');?>:</td>
  81.     <td>
  82.         <input type="text" class="text" name="company_phone1" value="<?php echo dPformSafe(@$obj->company_phone1);?>" maxlength="30" />
  83.     </td>
  84. </tr>
  85. <tr>
  86.     <td align="right"><?php echo $AppUI->_('Phone');?>2:</td>
  87.     <td>
  88.         <input type="text" class="text" name="company_phone2" value="<?php echo dPformSafe(@$obj->company_phone2);?>" maxlength="50" />
  89.     </td>
  90. </tr>
  91. <tr>
  92.     <td align="right"><?php echo $AppUI->_('Fax');?>:</td>
  93.     <td>
  94.         <input type="text" class="text" name="company_fax" value="<?php echo dPformSafe(@$obj->company_fax);?>" maxlength="30" />
  95.     </td>
  96. </tr>
  97. <tr>
  98.     <td colspan=2 align="center">
  99.         <img src="images/shim.gif" width="50" height="1" /><?php echo $AppUI->_('Address');?><br />
  100.         <hr width="500" align="center" size=1 />
  101.     </td>
  102. </tr>
  103. <tr>
  104.     <td align="right"><?php echo $AppUI->_('Address');?>1:</td>
  105.     <td><input type="text" class="text" name="company_address1" value="<?php echo dPformSafe(@$obj->company_address1);?>" size=50 maxlength="255" /></td>
  106. </tr>
  107. <tr>
  108.     <td align="right"><?php echo $AppUI->_('Address');?>2:</td>
  109.     <td><input type="text" class="text" name="company_address2" value="<?php echo dPformSafe(@$obj->company_address2);?>" size=50 maxlength="255" /></td>
  110. </tr>
  111. <tr>
  112.     <td align="right"><?php echo $AppUI->_('City');?>:</td>
  113.     <td><input type="text" class="text" name="company_city" value="<?php echo dPformSafe(@$obj->company_city);?>" size=50 maxlength="50" /></td>
  114. </tr>
  115. <tr>
  116.     <td align="right"><?php echo $AppUI->_('State');?>:</td>
  117.     <td><input type="text" class="text" name="company_state" value="<?php echo dPformSafe(@$obj->company_state);?>" maxlength="50" /></td>
  118. </tr>
  119. <tr>
  120.     <td align="right"><?php echo $AppUI->_('Zip');?>:</td>
  121.     <td><input type="text" class="text" name="company_zip" value="<?php echo dPformSafe(@$obj->company_zip);?>" maxlength="15" /></td>
  122. </tr>
  123. <tr>
  124.     <td align="right">
  125.         URL http://<A name="x"></a></td><td><input type="text" class="text" value="<?php echo dPformSafe(@$obj->company_primary_url);?>" name="company_primary_url" size="50" maxlength="255" />
  126.         <a href="#x" onClick="testURL('CompanyURLOne')">[<?php echo $AppUI->_('test');?>]</a>
  127.     </td>
  128. </tr>
  129.  
  130. <tr>
  131.     <td align="right"><?php echo $AppUI->_('Company Owner');?>:</td>
  132.     <td>
  133. <?php
  134.     echo arraySelect( $owners, 'company_owner', 'size="1" class="text"', @$obj->company_owner );
  135. ?>
  136.     </td>
  137. </tr>
  138.  
  139. <tr>
  140.     <td align="right"><?php echo $AppUI->_('Type');?>:</td>
  141.     <td>
  142. <?php
  143.     echo arraySelect( $types, 'company_type', 'size="1" class="text"', @$obj->company_type, true );
  144. ?>
  145.     </td>
  146. </tr>
  147.  
  148. <tr>
  149.     <td align="right" valign=top><?php echo $AppUI->_('Description');?>:</td>
  150.     <td align="left">
  151.         <textarea cols="70" rows="10" class="textarea" name="company_description"><?php echo @$obj->company_description;?></textarea>
  152.     </td>
  153. </tr>
  154. <tr>
  155.     <td align="center">
  156. <?php
  157.     $custom_fields = dPgetSysVal("CompanyCustomFields");
  158.     if ( count($custom_fields) > 0 ){
  159.         //We have custom fields, parse them!
  160.         //Custom fields are stored in the sysval table under CompanyCustomFields, the format is
  161.         //key|serialized array of ("name", "type", "options", "selects")
  162.         //Ej: 0|a:3:{s:4:"name";s:22:"Quote number";s:4:"type";s:4:"text";s:7:"options";s:24:"maxlength="12" size="10"";} 
  163.         if ( $obj->company_custom != "" || !is_null($obj->company_custom))  {
  164.             //Custom info previously saved, retrieve it
  165.             $custom_field_previous_data = unserialize($obj->company_custom);
  166.         }
  167.         
  168.         $output = '';
  169.         foreach ( $custom_fields as $key => $array) {
  170.             $output .= "<tr colspan='3' valign='top' id='custom_tr_$key' >";
  171.             $field_options = unserialize($array);
  172.             $output .= "<td align='right' nowrap='nowrap' >". ($field_options["type"] == "label" ? "<strong>". $field_options['name']. "</strong>" : $field_options['name']) . ":" ."</td>";
  173.             switch ( $field_options["type"]){
  174.                 case "text":
  175.                     $output .= "<td><input type='text' name='custom_$key' class='text'" . $field_options["options"] . "value='" . ( isset($custom_field_previous_data[$key]) ? $custom_field_previous_data[$key] : "") . "' /></td>";
  176.                     break;
  177.                 case "select":
  178.                     $output .= "<td>". arraySelect(explode(",",$field_options["selects"]), "custom_$key", 'size="1" class="text" ' . $field_options["options"] ,( isset($custom_field_previous_data[$key]) ? $custom_field_previous_data[$key] : "")) . "</td>";
  179.                     break;
  180.                 case "textarea":
  181.                     $output .=  "<td><textarea name='custom_$key' class='textarea'" . $field_options["options"] . ">" . ( isset($custom_field_previous_data[$key]) ? $custom_field_previous_data[$key] : "") . "</textarea></td>";
  182.                     break;
  183.             }
  184.             $output .= "</tr>";
  185.         }
  186.         echo $output;
  187.     }
  188. ?>
  189.     </td>
  190. </tr>
  191. <tr>
  192.     <td><input type="button" value="<?php echo $AppUI->_('back');?>" class="button" onClick="javascript:history.back(-1);" /></td>
  193.     <td align="right"><input type="button" value="<?php echo $AppUI->_('submit');?>" class="button" onClick="submitIt()" /></td>
  194. </tr>
  195. </form>
  196. </table>
  197.