home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / groupoffice-com-2.01 / modules / addressbook / company_contacts.inc < prev    next >
Encoding:
Text File  |  2004-03-08  |  7.3 KB  |  203 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. if (isset($_REQUEST['delete_contact_id']) && $_REQUEST['delete_contact_id'] > 0)
  14. {
  15.     $contact = $ab->get_contact($_REQUEST['delete_contact_id']);
  16.     if ($GO_SECURITY->has_permission($GO_SECURITY->user_id, $contact['acl_write']))
  17.     {
  18.         $ab->add_contact_to_company($_REQUEST['delete_contact_id'], 0);
  19.     }else
  20.     {
  21.         $feedback = '<p class="Error">'.$strAccessDenied.'</p>';
  22.     }
  23. }
  24.  
  25. //define the items to show
  26. $max_rows = isset($_REQUEST['max_rows']) ? $_REQUEST['max_rows'] : $_SESSION['GO_SESSION']['max_rows_list'];
  27. $first = isset($_REQUEST['first']) ? $_REQUEST['first'] : 0;
  28.  
  29. //determine sorting
  30. $contact_sort = isset($_COOKIE['contact_sort']) ? $_COOKIE['contact_sort'] : 'name';
  31. $contact_direction = isset($_COOKIE['contact_direction']) ? $_COOKIE['contact_direction'] : 'ASC';
  32.  
  33. if ($contact_direction == "DESC")
  34. {
  35.     $sort_arrow = ' <img src="'.$GO_THEME->images['arrow_down'].'" border="0" />';
  36.     $new_sort_direction = "ASC";
  37. }else
  38. {
  39.     $sort_arrow = ' <img src="'.$GO_THEME->images['arrow_up'].'" border="0" />';
  40.     $new_sort_direction = "DESC";
  41. }
  42.  
  43. echo '<input type="hidden" name="first" value="'.$first.'" />';
  44. echo '<input type="hidden" name="max_rows" value="'.$max_rows.'" />';
  45. echo '<input type="hidden" name="delete_contact_id" />';
  46. echo '<input type="hidden" name="new_sort_field" value="'.$contact_sort.'" />';
  47. echo '<input type="hidden" name="new_sort_direction" value="'.$contact_direction.'" />';
  48.  
  49. echo '<a class="normal" href="'.$GO_MODULES->url.'contact.php?company_id='.$company_id.'&addressbook_id='.$addressbook_id.'&return_to='.rawurlencode($link_back.'&active_tab='.$tabtable->active_tab).'">'.$ab_add_new.'</a>';
  50. echo ' | ';
  51. echo '<a class="normal" href="'.$ab->select_contacts('', $GO_MODULES->url.'add_employees.php?company_id='.$company_id, 'true', 'false', 'false', 'true', 'false', 'id').'">'.$ab_add_existing.'</a>';
  52.  
  53.  
  54. echo '<table border="0" cellspacing="0" cellpadding="2">';
  55. echo '<tr><td>';
  56. $count = $ab->get_company_contacts($company_id, $contact_sort, $contact_direction, $first, $max_rows);
  57. $str_count = $count == 1 ? $ab_employee_count_single : $ab_employee_count_multiple;
  58. echo '</td><td colspan="99" class="small" align="right">'.$count.' '.$str_count.'</td></tr>';
  59. echo '<tr height="20">';
  60. echo '<td class="TableHead2" width="100" nowrap><a class="TableHead2" href="javascript:_sort(\'name\',\''.$new_sort_direction.'\');">'.$strName.'</a>';
  61. if ($contact_sort == 'name')
  62. {
  63.     echo $sort_arrow;
  64. }
  65. echo '</td>';
  66. echo '<td class="TableHead2" width="100" nowrap><a class="TableHead2" href="javascript:_sort(\'email\',\''.$new_sort_direction.'\');">'.$strEmail.'</a>';
  67. if ($contact_sort == 'email')
  68. {
  69.     echo $sort_arrow;
  70. }
  71. echo '</td>';
  72. echo '<td class="TableHead2" width="100" nowrap><a class="TableHead2" href="javascript:_sort(\'home_phone\',\''.$new_sort_direction.'\');">'.$strPhone.'</a>';
  73. if ($contact_sort == 'home_phone')
  74. {
  75.     echo $sort_arrow;
  76. }
  77. echo '</td>';
  78. echo '<td class="TableHead2" width="100" nowrap><a class="TableHead2" href="javascript:_sort(\'work_phone\',\''.$new_sort_direction.'\');">'.$strWorkphone.'</a>';
  79. if ($contact_sort == 'work_phone')
  80. {
  81.     echo $sort_arrow;
  82. }
  83. echo '</td>';
  84. echo '<td class="TableHead2"> </td></tr>';
  85.  
  86. if ($count > 0)
  87. {
  88.     while($ab->next_record())
  89.     {
  90.         $middle_name = $ab->f('middle_name') == '' ? '' : $ab->f('middle_name').' ';
  91.         $name = $ab->f('first_name').' '.$middle_name.$ab->f('last_name');
  92.  
  93.         echo '<tr><td><a class="normal" href="'.$GO_MODULES->url.'contact.php?contact_id='.$ab->f('id').'&return_to='.rawurlencode($link_back.'&active_tab='.$tabtable->active_tab).'">'.$name.'</a></td>';
  94.         echo '<td>'.mail_to($ab->f('email'), $ab->f('email')).'</td>';
  95.         echo '<td>'.$ab->f('home_phone').'</a></td>';
  96.         echo '<td>'.$ab->f('work_phone').'</td>';
  97.         echo "<td><a href='javascript:confirm_action(\"javascript:delete_contact(".$ab->f('id').")\",\"".rawurlencode($strDeletePrefix."'".$name."'".$strDeleteSuffix)."\")' title=\"".$strDeleteItem." '".$name."'\"><img src=\"".$GO_THEME->images['delete']."\" border=\"0\"></a></td>\n";
  98.         echo '<tr><td colspan="99" height="1"><img src="'.$GO_THEME->images['cccccc'].'" border="0" height="1" width="100%" /></td></tr>';
  99.     }
  100.  
  101.     $links = '';
  102.     $max_links=10;
  103.     if ($max_rows != 0)
  104.     {
  105.         if ($count > $max_rows)
  106.         {
  107.             $links = '<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td>';
  108.             $next_start = $first+$max_rows;
  109.             $previous_start = $first-$max_rows;
  110.             if ($first != 0)
  111.             {
  112.                 $links .= '<a href="javascript:change_list(0, '.$max_rows.');"><<</a> ';
  113.                 $links .= '<a href="javascript:change_list('.$previous_start.', '.$max_rows.');">'.$cmdPrevious.'</a> ';
  114.             }else
  115.             {
  116.                 $links .= '<font color="#cccccc"><< '.$cmdPrevious.'</font> ';
  117.             }
  118.  
  119.             $start = ($first-(($max_links/2)*$max_rows));
  120.  
  121.             $end = ($first+(($max_links/2)*$max_rows));
  122.  
  123.             if ($start < 0)
  124.             {
  125.                 $end = $end - $start;
  126.                 $start=0;
  127.             }
  128.             if ($end > $count)
  129.             {
  130.                 $end = $count;
  131.             }
  132.             if ($start > 0)
  133.             {
  134.                 $links .= '... ';
  135.             }
  136.  
  137.             for ($i=$start;$i<$end;$i+=$max_rows)
  138.             {
  139.                 $page = ($i/$max_rows)+1;
  140.                 if ($i==$first)
  141.                 {
  142.                     $links .= '<b><i>'.$page.'</i></b> ';
  143.                 }else
  144.                 {
  145.                     $links .= '<a href="'.$_SERVER['PHP_SELF'].'?post_action=projects&first='.$i.'">'.$page.'</a> ';
  146.                 }
  147.             }
  148.  
  149.             if ($end < $count)
  150.             {
  151.                 $links .= '... ';
  152.             }
  153.  
  154.             $last_page = floor($count/$max_rows)*$max_rows;
  155.  
  156.             if ($count > $next_start)
  157.             {
  158.                 $links .= '<a href="javascript:change_list('.$next_start.', '.$max_rows.');">'.$cmdNext.'</a> ';
  159.                 $links .= '<a href="javascript:change_list('.$last_page.', '.$max_rows.');">>></a>';
  160.             }else
  161.             {
  162.                 $links .= '<font color="#cccccc">'.$cmdNext.' >></font>';
  163.             }
  164.             $links .= '</td><td align="right"><a class="normal" href="javascript:change_list(0, 0);">'.$cmdShowAll.'</a></td></tr></table>';
  165.  
  166.             echo '<tr height="20"><td colspan="99">'.$links.'</td></tr>';
  167.             echo '<tr><td colspan="99" height="1"><img src="'.$GO_THEME->images['cccccc'].'" border="0" height="1" width="100%" /></td></tr>';
  168.         }
  169.     }
  170.  
  171. }else
  172. {
  173.     echo '<tr><td colspan="99">'.$ab_no_employees.'</td></tr>';
  174.     echo '<tr><td colspan="99" height="1"><img src="'.$GO_THEME->images['cccccc'].'" border="0" height="1" width="100%" /></td></tr>';
  175. }
  176. echo '</table>';
  177. echo '<br />';
  178. $button = new button($cmdClose, "javascript:document.location='".$return_to."'");
  179. ?>
  180.  
  181. <script type="text/javascript">
  182.  
  183. function _sort(field, direction)
  184. {
  185.     document.company_form.new_sort_field.value=field;
  186.     document.company_form.new_sort_direction.value=direction;
  187.     document.company_form.submit();
  188. }
  189.  
  190. function delete_contact(id)
  191. {
  192.     document.company_form.delete_contact_id.value=id;
  193.     document.company_form.submit();
  194. }
  195.  
  196. function change_list(first, max_rows)
  197. {
  198.     document.company_form.first.value=first;
  199.     document.company_form.max_rows.value=max_rows;
  200.     document.company_form.submit();
  201. }
  202. </script>
  203.