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

  1. <?php /* COMPANIES $Id: view.php,v 1.36 2004/01/10 21:19:14 gregorerhardt Exp $ */
  2. $company_id = intval( dPgetParam( $_GET, "company_id", 0 ) );
  3.  
  4. // check permissions for this record
  5. $canRead = !getDenyRead( $m, $company_id );
  6. $canEdit = !getDenyEdit( $m, $company_id );
  7.  
  8. if (!$canRead) {
  9.     $AppUI->redirect( "m=public&a=access_denied" );
  10. }
  11.  
  12. // retrieve any state parameters
  13. if (isset( $_GET['tab'] )) {
  14.     $AppUI->setState( 'CompVwTab', $_GET['tab'] );
  15. }
  16. $tab = $AppUI->getState( 'CompVwTab' ) !== NULL ? $AppUI->getState( 'CompVwTab' ) : 0;
  17.  
  18. // check if this record has dependancies to prevent deletion
  19. $msg = '';
  20. $obj = new CCompany();
  21. $canDelete = $obj->canDelete( $msg, $company_id );
  22.  
  23. // load the record data
  24. $sql = "
  25. SELECT companies.*,users.user_first_name,users.user_last_name
  26. FROM companies
  27. LEFT JOIN users ON users.user_id = companies.company_owner
  28. WHERE companies.company_id = $company_id
  29. ";
  30.  
  31. $obj = null;
  32. if (!db_loadObject( $sql, $obj )) {
  33.     $AppUI->setMsg( 'Company' );
  34.     $AppUI->setMsg( "invalidID", UI_MSG_ERROR, true );
  35.     $AppUI->redirect();
  36. } else {
  37.     $AppUI->savePlace();
  38. }
  39.  
  40. // load the list of project statii and company types
  41. $pstatus = dPgetSysVal( 'ProjectStatus' );
  42. $types = dPgetSysVal( 'CompanyType' );
  43.  
  44. // setup the title block
  45. $titleBlock = new CTitleBlock( 'View Company', 'handshake.png', $m, "$m.$a" );
  46. if ($canEdit) {
  47.     $titleBlock->addCell();
  48.     $titleBlock->addCell(
  49.         '<input type="submit" class="button" value="'.$AppUI->_('new company').'" />', '',
  50.         '<form action="?m=companies&a=addedit" method="post">', '</form>'
  51.     );
  52. }
  53. $titleBlock->addCrumb( "?m=companies", "company list" );
  54. if ($canEdit) {
  55.     $titleBlock->addCrumb( "?m=companies&a=addedit&company_id=$company_id", "edit this company" );
  56.     
  57.     if ($canEdit) {
  58.         $titleBlock->addCrumbDelete( 'delete company', $canDelete, $msg );
  59.     }
  60. }
  61. $titleBlock->show();
  62. ?>
  63. <script language="javascript">
  64. function delIt() {
  65.     if (confirm( "<?php echo $AppUI->_('doDelete').' '.$AppUI->_('Company').'?';?>" )) {
  66.         document.frmDelete.submit();
  67.     }
  68. }
  69. </script>
  70.  
  71. <table border="0" cellpadding="4" cellspacing="0" width="100%" class="std">
  72.  
  73. <form name="frmDelete" action="./index.php?m=companies" method="post">
  74.     <input type="hidden" name="dosql" value="do_company_aed" />
  75.     <input type="hidden" name="del" value="1" />
  76.     <input type="hidden" name="company_id" value="<?php echo $company_id;?>" />
  77. </form>
  78.  
  79. <tr>
  80.     <td valign="top" width="50%">
  81.         <strong><?php echo $AppUI->_('Details');?></strong>
  82.         <table cellspacing="1" cellpadding="2" width="100%">
  83.         <tr>
  84.             <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Company');?>:</td>
  85.             <td class="hilite" width="100%"><?php echo $obj->company_name;?></td>
  86.         </tr>
  87.         <tr>
  88.             <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Email');?>:</td>
  89.             <td class="hilite" width="100%"><?php echo $obj->company_email;?></td>
  90.         </tr>
  91.         <tr>
  92.             <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Phone');?>:</td>
  93.             <td class="hilite"><?php echo @$obj->company_phone1;?></td>
  94.         </tr>
  95.         <tr>
  96.             <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Phone');?>2:</td>
  97.             <td class="hilite"><?php echo @$obj->company_phone2;?></td>
  98.         </tr>
  99.         <tr>
  100.             <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Fax');?>:</td>
  101.             <td class="hilite"><?php echo @$obj->company_fax;?></td>
  102.         </tr>
  103.         <tr valign=top>
  104.             <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Address');?>:</td>
  105.             <td class="hilite"><?php
  106.                 echo @$obj->company_address1
  107.                     .( ($obj->company_address2) ? '<br />'.$obj->company_address2 : '' )
  108.                     .'<br />'.$obj->company_city
  109.                     .'  '.$obj->company_state
  110.                     .'  '.$obj->company_zip
  111.                     ;
  112.             ?></td>
  113.         </tr>
  114.         <tr>
  115.             <td align="right" nowrap="nowrap"><?php echo $AppUI->_('URL');?>:</td>
  116.             <td class="hilite">
  117.                 <a href="http://<?php echo @$obj->company_primary_url;?>" target="Company"><?php echo @$obj->company_primary_url;?></a>
  118.             </td>
  119.         </tr>
  120.         <tr>
  121.             <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Type');?>:</td>
  122.             <td class="hilite"><?php echo $AppUI->_($types[@$obj->company_type]);?></td>
  123.         </tr>
  124.         <?php
  125.         $custom_fields = dPgetSysVal("CompanyCustomFields");
  126.         if ( count($custom_fields) > 0 ) {
  127.             //We have custom fields, parse them!
  128.             //Custom fields are stored in the sysval table under TaskCustomFields, the format is
  129.             //key|serialized array of ("name", "type", "options", "selects")
  130.             
  131.             if ( $obj->company_custom != "" || !is_null($obj->company_custom))  {
  132.                 //Custom info previously saved, retrieve it
  133.                 $custom_field_previous_data = unserialize($obj->company_custom);
  134.             }
  135.             
  136.             $output = '';
  137.             foreach ( $custom_fields as $key => $array) {
  138.                 $output .= "<tr id='custom_tr_$key' >";
  139.                 $field_options = unserialize($array);
  140.                 $output .= "<td align='right' nowrap='nowrap' >". ($field_options["type"] == "label" ? "<b>". $field_options['name']. "</b>" : $field_options['name'] . ":") ."</td>";
  141.                 switch ( $field_options["type"]){
  142.                     case "text":
  143.                         $output .= "<td class='hilite' width='300'>" . ( isset($custom_field_previous_data[$key]) ? $custom_field_previous_data[$key] : "") . "</td>";
  144.                         break;
  145.                     case "select":
  146.                         $optionarray = explode(",",$field_options["selects"]);
  147.                         $output .= "<td class='hilite' width='300'>". ( isset($custom_field_previous_data[$key]) ? $optionarray[$custom_field_previous_data[$key]] : "") . "</td>";
  148.                         break;
  149.                     case "textarea":
  150.                         $output .=  "<td valign='top' class='hilite'>" . ( isset($custom_field_previous_data[$key]) ? $custom_field_previous_data[$key] : "") . "</td>";
  151.                         break;
  152.                 }
  153.                 $output .= "</tr>";
  154.             }
  155.             echo $output;
  156.         } ?>
  157.         </table>
  158.  
  159.     </td>
  160.     <td width="50%" valign="top">
  161.         <strong><?php echo $AppUI->_('Description');?></strong>
  162.         <table cellspacing="0" cellpadding="2" border="0" width="100%">
  163.         <tr>
  164.             <td class="hilite">
  165.                 <?php echo str_replace( chr(10), "<br />", $obj->company_description);?> 
  166.             </td>
  167.         </tr>
  168.         
  169.         </table>
  170.     </td>
  171. </tr>
  172. </table>
  173.  
  174. <?php
  175. // tabbed information boxes
  176. $tabBox = new CTabBox( "?m=companies&a=view&company_id=$company_id", "{$AppUI->cfg['root_dir']}/modules/companies/", $tab );
  177. $tabBox->add( 'vw_active', 'Active Projects' );
  178. $tabBox->add( 'vw_archived', 'Archived Projects' );
  179. $tabBox->add( 'vw_depts', 'Departments' );
  180. $tabBox->add( 'vw_users', 'Users' );
  181. $tabBox->add( 'vw_contacts', 'Contacts' );
  182. $tabBox->show();
  183. ?>
  184.