home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / groupoffice-com-2.01 / modules / addressbook / company.php < prev    next >
PHP Script  |  2004-03-08  |  8KB  |  233 lines

  1. <?php
  2. /*
  3. Copyright Intermesh 2003
  4. Author: Merijn Schering <mschering@intermesh.nl>
  5. Version: 1.0 Release date: 08 July 2003
  6.  
  7. This program is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2 of the License, or (at your
  10. option) any later version.
  11. */
  12.  
  13. require("../../Group-Office.php");
  14.  
  15. $GO_SECURITY->authenticate();
  16. $GO_MODULES->authenticate('addressbook');
  17. require($GO_LANGUAGE->get_language_file('contacts'));
  18.  
  19. $page_title=$contact_profile;
  20. require($GO_CONFIG->class_path."addressbook.class.inc");
  21. $ab = new addressbook();
  22.  
  23. $task = isset($_REQUEST['task']) ? $_REQUEST['task'] : '';
  24. $return_to = (isset($_REQUEST['return_to']) && $_REQUEST['return_to'] != '') ? $_REQUEST['return_to'] : null;
  25. $link_back = (isset($_REQUEST['link_back']) && $_REQUEST['link_back'] != '') ? $_REQUEST['link_back'] : $_SERVER['REQUEST_URI'];
  26. $company_id = isset($_REQUEST['company_id']) ? $_REQUEST['company_id'] : '0';
  27.  
  28. $addressbook_id = isset($_REQUEST['addressbook_id']) ? $_REQUEST['addressbook_id'] : '0';
  29.  
  30. //remember sorting of the projects list in a cookie
  31. if (isset($_REQUEST['new_sort_field']))
  32. {
  33.     SetCookie("contact_sort",$_REQUEST['new_sort_field'],time()+3600*24*365,"/","",0);
  34.     $_COOKIE['contact_sort'] = $_REQUEST['new_sort_field'];
  35. }
  36.  
  37. if (isset($_REQUEST['new_sort_direction']))
  38. {
  39.     SetCookie("contact_direction",$_REQUEST['new_sort_direction'],time()+3600*24*365,"/","",0);
  40.     $_COOKIE['contact_direction'] = $_REQUEST['new_sort_direction'];
  41. }
  42.  
  43. //save
  44. switch($task)
  45. {
  46.     case 'save_company':
  47.  
  48.         $name = trim($_POST['name']);
  49.         if ($name == '')
  50.         {
  51.             $feedback = "<p class=\"Error\">".$error_missing_field."</p>";
  52.         }else
  53.         {
  54.             if ($_POST['company_id'] > 0)
  55.             {
  56.                 if ($ab->update_company($_POST['company_id'], $addressbook_id, $_POST['name'], $_POST['address'], $_POST['zip'], $_POST['city'], $_POST['state'], $_POST['country'], $_POST['email'], $_POST['phone'], $_POST['fax'], $_POST['homepage'], $_POST['bank_no'], $_POST['vat_no']))
  57.                 {
  58.                     if ($_POST['close'] == 'true')
  59.                     {
  60.                         header('Location: '.$return_to);
  61.                         exit();
  62.                     }
  63.                 }else
  64.                 {
  65.                     $feedback = "<p class=\"Error\">".$strSaveError."</p>";
  66.                 }
  67.             }else
  68.             {
  69.                 $acl_read = $GO_SECURITY->get_new_acl('company read');
  70.                 $acl_write = $GO_SECURITY->get_new_acl('company write');
  71.  
  72.                 if ($company_id = $ab->add_company($addressbook_id, $_POST['name'], $_POST['address'], $_POST['zip'], $_POST['city'], $_POST['state'], $_POST['country'], $_POST['email'], $_POST['phone'], $_POST['fax'], $_POST['homepage'], $_POST['bank_no'], $_POST['vat_no'], $acl_read, $acl_write))
  73.                 {
  74.                     if($addressbook = $ab->get_addressbook($addressbook_id))
  75.                     {
  76.                         $GO_SECURITY->copy_acl($addressbook['acl_read'], $acl_read);
  77.                         $GO_SECURITY->copy_acl($addressbook['acl_write'], $acl_write);
  78.                     }
  79.  
  80.                     if ($_POST['close'] == 'true')
  81.                     {
  82.                         header('Location: '.$return_to);
  83.                         exit();
  84.                     }
  85.                 }else
  86.                 {
  87.                     $GO_SECURITY->delete_acl($acl_read);
  88.                     $GO_SECURITY->delete_acl($acl_write);
  89.                     $feedback = "<p class=\"Error\">".$strSaveError."</p>";
  90.                 }
  91.             }
  92.         }
  93.     break;
  94.  
  95.     case 'save_custom_fields':
  96.     if (isset($_POST['fields']))
  97.     {
  98.         require_once($GO_CONFIG->class_path.'custom_fields.class.inc');
  99.         $cf = new custom_fields('ab_custom_company_fields');
  100.  
  101.         $cf->update_record($company_id, $_POST['fields']);
  102.         if ($_POST['close'] == 'true')
  103.         {
  104.             header('Location: '.$return_to);
  105.             exit();
  106.         }
  107.     }
  108.     break;
  109. }
  110.  
  111. //check permissions
  112. if ($company_id > 0 && $company = $ab->get_company($company_id))
  113. {
  114.     $tabtable= new tabtable('company_table', $company['name'], '600', '400', '120', '', true, 'left', 'top', 'company_form');
  115.     $tabtable->add_tab('profile', $ab_company_properties);
  116.     if ($GO_MODULES->get_plugin('custom_fields') && $cf_access_acl = $GO_SECURITY->get_acl_id('cf_access'))
  117.     {
  118.         if ($GO_SECURITY->has_permission($GO_SECURITY->user_id, $cf_access_acl))
  119.         {
  120.             require_once($GO_CONFIG->class_path.'custom_fields.class.inc');
  121.             $cf = new custom_fields('ab_custom_company_fields');
  122.             if ($cf->get_fields() > 0)
  123.             {
  124.                 $tabtable->add_tab('custom_fields', $ab_custom_fields);
  125.             }
  126.         }
  127.     }
  128.     $tabtable->add_tab('contacts', $ab_employees);
  129.     $tabtable->add_tab('read_permissions', $strReadRights);
  130.     $tabtable->add_tab('write_permissions', $strWriteRights);
  131.  
  132.     $addressbook_id = $company['addressbook_id'];
  133.     if (!$write_permission = $GO_SECURITY->has_permission($GO_SECURITY->user_id, $company['acl_write']))
  134.     {
  135.         $read_permission = $GO_SECURITY->has_permission($GO_SECURITY->user_id, $company['acl_read']);
  136.     }
  137. }else
  138. {
  139.     $tabtable= new tabtable('company_table', $ab_new_company, '600', '400', '120', '', true, 'left', 'top', 'company_form');
  140.     $write_permission = true;
  141.     $read_permission = true;
  142. }
  143.  
  144. if (!$write_permission && !$read_permission)
  145. {
  146.     header('Location: '.$GO_CONFIG->host.'error_docs/403.php');
  147.     exit();
  148. }
  149.  
  150. require($GO_THEME->theme_path."header.inc");
  151.  
  152. $active_tab = isset($_REQUEST['active_tab']) ? $_REQUEST['active_tab'] : null;
  153. if (isset($active_tab))
  154. {
  155.     $tabtable->set_active_tab($active_tab);
  156. }
  157.  
  158. if ($tabtable->get_active_tab_id() == 'contacts')
  159. {
  160.     $ab->enable_contact_selector();
  161. }
  162.  
  163. echo '<form method="post" name="company_form" action="'.$_SERVER['PHP_SELF'].'">';
  164. echo '<input type="hidden" name="task" value="" />';
  165. echo '<input type="hidden" name="close" value="false" />';
  166. echo '<input type="hidden" name="return_to" value="'.$return_to.'" />';
  167. echo '<input type="hidden" name="link_back" value="'.$link_back.'" />';
  168. echo '<input type="hidden" name="company_id" value="'.$company_id.'" />';
  169.  
  170. if ($company_id == 0 || $task == 'save_company')
  171. {
  172.     $company['name'] = isset($_REQUEST['name']) ? smartstrip($_REQUEST['name']) : '';
  173.     $company['address'] = isset($_REQUEST['address']) ? smartstrip($_REQUEST['address']) : '';
  174.     $company['zip'] = isset($_REQUEST['zip']) ? smartstrip($_REQUEST['zip']) : '';
  175.     $company['city'] = isset($_REQUEST['city']) ? smartstrip($_REQUEST['city']) : '';
  176.     $company['state'] = isset($_REQUEST['state']) ? smartstrip($_REQUEST['state']) : '';
  177.     $company['email'] = isset($_REQUEST['email']) ? smartstrip($_REQUEST['email']) : '';
  178.     $company['country'] = isset($_REQUEST['country']) ? smartstrip($_REQUEST['country']) : '';
  179.     $company['phone'] = isset($_REQUEST['phone']) ? smartstrip($_REQUEST['phone']) : '';
  180.     $company['fax'] = isset($_REQUEST['fax']) ? smartstrip($_REQUEST['fax']) : '';
  181.     $company['homepage'] = isset($_REQUEST['homepage']) ? smartstrip($_REQUEST['homepage']) : 'http://';
  182.     $company['bank_no'] = isset($_REQUEST['bank_no']) ? smartstrip($_REQUEST['bank_no']) : '';
  183.     $company['vat_no'] = isset($_REQUEST['vat_no']) ? smartstrip($_REQUEST['vat_no']) : '';
  184. }
  185.  
  186. $tabtable->print_head();
  187.  
  188. switch ($tabtable->get_active_tab_id())
  189. {
  190.     case 'read_permissions':
  191.         print_acl($company['acl_read']);
  192.         echo '<br />';
  193.         if (isset($return_to))
  194.         {
  195.             $button = new button($cmdClose, "javascript:document.location='".$return_to."';");
  196.         }
  197.     break;
  198.  
  199.     case 'write_permissions':
  200.         print_acl($company['acl_write']);
  201.         echo '<br />';
  202.         if (isset($return_to))
  203.         {
  204.             $button = new button($cmdClose, "javascript:document.location='".$return_to."';");
  205.         }
  206.     break;
  207.  
  208.     case 'custom_fields':
  209.         require('custom_fields/custom_fields.inc');
  210.     break;
  211.  
  212.     case 'contacts':
  213.         require('company_contacts.inc');
  214.     break;
  215.  
  216.     default:
  217.         if ($write_permission)
  218.         {
  219.             require('edit_company.inc');
  220.         }else
  221.         {
  222.             require('show_company.inc');
  223.         }
  224.     break;
  225. }
  226.  
  227. $tabtable->print_foot();
  228.  
  229. echo '</form>';
  230.  
  231.  
  232. require($GO_THEME->theme_path."footer.inc");
  233. ?>