home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / groupoffice-com-2.01 / modules / addressbook / addressbook.php < prev    next >
PHP Script  |  2004-03-08  |  8KB  |  247 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. $post_action = isset($post_action) ? $post_action : '';
  15.  
  16. $GO_SECURITY->authenticate();
  17. $GO_MODULES->authenticate('addressbook');
  18. require($GO_LANGUAGE->get_language_file('contacts'));
  19.  
  20. //load contact management class
  21. require($GO_CONFIG->class_path."addressbook.class.inc");
  22. $ab = new addressbook();
  23.  
  24. $return_to = (isset($_REQUEST['return_to']) && $_REQUEST['return_to'] != '') ? $_REQUEST['return_to'] : $_SERVER['HTTP_REFERER'];
  25. $addressbook_id = isset($_REQUEST['addressbook_id']) ? $_REQUEST['addressbook_id'] : 0;
  26.  
  27. $task = isset($_REQUEST['task']) ? $_REQUEST['task'] : '';
  28.  
  29. switch($task)
  30. {
  31.     case 'save':
  32.         $name = trim($_POST['name']);
  33.         if ($name == '')
  34.         {
  35.             $feedback = '<p class="Error">'.$error_missing_field.'</p>';
  36.         }else
  37.         {
  38.             if ($addressbook_id > 0)
  39.             {
  40.                 $existing_addressbook = $ab->get_addressbook_by_name($name);
  41.                 if($existing_addressbook && $existing_addressbook['id'] != $addressbook_id)
  42.                 {
  43.                     $feedback = '<p class="Error">'.$ab_addressbook_exists.'</p>';
  44.                 }elseif(!$ab->update_addressbook($_POST['addressbook_id'], $name))
  45.                 {
  46.                     $feedback = '<p class="Error">'.$strSaveError.'</p>';
  47.                 }elseif($_POST['close'] == 'true')
  48.                 {
  49.                     header('Location: '.$return_to);
  50.                     exit();
  51.                 }
  52.             }else
  53.             {
  54.                 if($ab->get_addressbook_by_name($name))
  55.                 {
  56.                     $feedback = '<p class="Error">'.$ab_addressbook_exists.'</p>';
  57.                 }elseif(!$addressbook_id = $ab->add_addressbook($GO_SECURITY->user_id, $name))
  58.                 {
  59.                     $feedback = '<p class="Error">'.$strSaveError.'</p>';
  60.                 }elseif($_POST['close'] == 'true')
  61.                 {
  62.                     header('Location: '.$return_to);
  63.                     exit();
  64.                 }
  65.             }
  66.         }
  67.     break;
  68.  
  69.     case 'export':
  70.         $addressbook = $ab->get_addressbook($addressbook_id);
  71.  
  72.         $browser = detect_browser();
  73.         header("Content-type: text/x-csv");
  74.         header('Expires: '.gmdate('D, d M Y H:i:s') . ' GMT');
  75.         if ($browser['name'] == 'MSIE')
  76.         {
  77.             header("Content-Disposition: inline; filename=".$addressbook['name']."-".$_POST['export_type'].".csv");
  78.             header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  79.             header('Pragma: public');
  80.         }else
  81.         {
  82.             header('Pragma: no-cache');
  83.             header("Content-Disposition: attachment; filename=".$addressbook['name'].".csv");
  84.         }
  85.  
  86.         $quote = smartstrip($_POST['quote']);
  87.         $crlf = smartstrip($_POST['crlf']);
  88.         $crlf = str_replace('\\r', "\015", $crlf);
  89.         $crlf = str_replace('\\n', "\012", $crlf);
  90.         $crlf = str_replace('\\t', "\011", $crlf);
  91.         $seperator = smartstrip($_POST['seperator']);
  92.  
  93.         if ($_POST['export_type'] == 'contacts')
  94.         {
  95.             $headings = array($strTitle, $strFirstName, $strMiddleName, $strLastName, $strInitials, $strSex, $strBirthday, $strEmail, $strCountry, $strState, $strCity, $strZip, $strAddress, $strPhone, $strWorkphone, $strFax, $strWorkFax, $strCellular, $strCompany, $strDepartment, $strFunction, $ab_comment, $contacts_group);
  96.             $headings = $quote.implode($quote.$seperator.$quote, $headings).$quote;
  97.             echo $headings;
  98.             echo $crlf;
  99.  
  100.             $ab->get_contacts_for_export($_POST['addressbook_id']);
  101.             while ($ab->next_record())
  102.             {
  103.                 $record = array($ab->f("title"), $ab->f("first_name"),$ab->f("middle_name"), $ab->f("last_name"), $ab->f("initials"), $ab->f("sex"), $ab->f('birthday'), $ab->f("email"), $ab->f("country"), $ab->f("state"), $ab->f("city"), $ab->f("zip"), $ab->f("address"), $ab->f("home_phone"), $ab->f("work_phone"), $ab->f("fax"), $ab->f("work_fax"), $ab->f("cellular"), $ab->f("company"), $ab->f("department"), $ab->f("function"), $ab->f("comment"), $ab->f("group_name"));
  104.                 $record = $quote.implode($quote.$seperator.$quote, $record).$quote;
  105.                 echo $record;
  106.                 echo $crlf;
  107.             }
  108.         }else
  109.         {
  110.             $headings = array($strName, $strCountry, $strState, $strCity, $strZip, $strAddress, $strEmail, $strPhone, $strFax, $strHomepage, $ab_bank_no, $ab_vat_no);
  111.             $headings = $quote.implode($quote.$seperator.$quote, $headings).$quote;
  112.             echo $headings;
  113.             echo $crlf;
  114.  
  115.             $ab->get_companies($_POST['addressbook_id']);
  116.  
  117.             while($ab->next_record())
  118.             {
  119.                 $record = array($ab->f("name"), $ab->f("country"), $ab->f("state"), $ab->f("city"), $ab->f("zip"), $ab->f("address"), $ab->f("email"), $ab->f("phone"), $ab->f("fax"), $ab->f("homepage"), $ab->f("bank_no"), $ab->f('vat_no'));
  120.                 $record = $quote.implode($quote.$seperator.$quote, $record).$quote;
  121.                 echo $record;
  122.                 echo $crlf;
  123.             }
  124.         }
  125.         exit();
  126.     break;
  127. }
  128.  
  129. if ($addressbook_id > 0 && $addressbook = $ab->get_addressbook($addressbook_id))
  130. {
  131.  
  132.     if (!$write_permission = $GO_SECURITY->has_permission($GO_SECURITY->user_id, $addressbook['acl_write']))
  133.     {
  134.         $read_permission = $GO_SECURITY->has_permission($GO_SECURITY->user_id, $addressbook['acl_read']);
  135.     }
  136.     $name = isset($name) ? $name : $addressbook['name'];
  137.  
  138.     $tabtable = new tabtable('addressbook', $name, '460', '400', '120', '', true);
  139.     $tabtable->add_tab('name', $strProperties);
  140.     if ($write_permission)
  141.     {
  142.         $tabtable->add_tab('groups', $contacts_groups);
  143.         $tabtable->add_tab('import', $contacts_import);
  144.     }
  145.     $tabtable->add_tab('export', $contacts_export);
  146.     $tabtable->add_tab('read_permissions', $strReadRights);
  147.     $tabtable->add_tab('write_permissions', $strWriteRights);
  148. }else
  149. {
  150.     $tabtable = new tabtable('addressbook', $ab_new_ab, '460', '400', '120', '', true);
  151.     $write_permission = true;
  152. }
  153.  
  154. if (!$write_permission && !$read_permission)
  155. {
  156.     header('Location: '.$GO_CONFIG->host.'error_docs/403.php');
  157.     exit();
  158. }
  159.  
  160. if (isset($_REQUEST['active_tab']))
  161. {
  162.     $tabtable->set_active_tab($_REQUEST['active_tab']);
  163. }
  164.  
  165. require($GO_THEME->theme_path."header.inc");
  166.  
  167. echo '<form name="addressbook" method="post" action="'.$_SERVER['PHP_SELF'].'" enctype="multipart/form-data">';
  168. echo '<input type="hidden" name="task" />';
  169. echo '<input type="hidden" name="close" value="false" />';
  170. echo '<input type="hidden" name="addressbook_id" value="'.$addressbook_id.'" />';
  171. echo '<input type="hidden" name="return_to" value="'.$return_to.'" />';
  172.  
  173. $tabtable->print_head();
  174.  
  175. echo '<br />';
  176. switch($tabtable->get_active_tab_id())
  177. {
  178.     case 'read_permissions':
  179.         print_acl($addressbook["acl_read"]);
  180.         echo '<br />';
  181.         $button = new button($cmdClose, "javascript:document.location='".$return_to."';");
  182.     break;
  183.  
  184.     case 'write_permissions':
  185.         print_acl($addressbook["acl_write"]);
  186.         echo '<br />';
  187.         $button = new button($cmdClose, "javascript:document.location='".$return_to."';");
  188.     break;
  189.  
  190.     case 'groups':
  191.         require('groups.inc');
  192.         echo '<br />';
  193.         $button = new button($cmdClose, "javascript:document.location='".$return_to."';");
  194.     break;
  195.  
  196.     case 'import':
  197.         require('import.inc');
  198.     break;
  199.  
  200.     case 'export':
  201.         require('export.inc');
  202.     break;
  203.  
  204.     default:
  205.         $name = isset($name) ? $name : '';
  206.         echo '<table border="0">';
  207.         if (isset($feedback))
  208.         {
  209.             echo '<tr><td colspan="2" class="Error">'.$feedback.'</td></tr>';
  210.         }
  211.         echo '<tr><td>'.$strName.':</td><td><input type="text" class="textbox" name="name" value="'.$name.'" size="40" /></td></tr></table>';
  212.         echo '<br />';
  213.         if ($write_permission)
  214.         {
  215.             $button = new button($cmdOk, "javascript:ok_addressbook()");
  216.             echo '  ';
  217.             $button = new button($cmdApply, "javascript:apply_addressbook()");
  218.             echo '  ';
  219.         }
  220.         $button = new button($cmdClose, "javascript:document.location='".$return_to."';");
  221.  
  222.         echo'<script type="text/javascript">document.forms[0].name.focus();</script>';
  223.     break;
  224. }
  225.  
  226. $tabtable->print_foot();
  227.  
  228. echo '</form>';
  229. ?>
  230. <script type="text/javascript" language="javascript">
  231.  
  232. function ok_addressbook()
  233. {
  234.     document.forms[0].close.value = 'true';
  235.     document.forms[0].task.value = 'save';
  236.     document.forms[0].submit();
  237. }
  238. function apply_addressbook()
  239. {
  240.     document.forms[0].task.value = 'save';
  241.     document.forms[0].submit();
  242. }
  243. </script>
  244. <?php
  245. require($GO_THEME->theme_path."footer.inc");
  246. ?>
  247.