home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / groupoffice-com-2.01 / modules / addressbook / companies.inc < prev    next >
Text File  |  2004-03-08  |  9KB  |  276 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($_POST['task']) && $_POST['task'] == 'delete_companies')
  14. {
  15.     for ($i=0;$i<sizeof($_POST['companies']);$i++)
  16.     {
  17.         $company = $ab->get_company($_POST['companies'][$i]);
  18.  
  19.         if ($GO_SECURITY->has_permission($GO_SECURITY->user_id, $company['acl_write']))
  20.         {
  21.             $ab->delete_company($_POST['companies'][$i]);
  22.             $GO_SECURITY->delete_acl($company['acl_write']);
  23.             $GO_SECURITY->delete_acl($company['acl_read']);
  24.         }
  25.     }
  26. }
  27.  
  28. //define the items to show
  29. $max_rows = isset($_REQUEST['max_rows']) ? $_REQUEST['max_rows'] : $_SESSION['GO_SESSION']['max_rows_list'];
  30. $first = isset($_REQUEST['first']) ? $_REQUEST['first'] : 0;
  31.  
  32. //determine sorting
  33. $abco_sort_field = isset($_COOKIE['abco_sort_field']) ? $_COOKIE['abco_sort_field'] : 'name';
  34. $abco_sort_direction = isset($_COOKIE['abco_sort_direction']) ? $_COOKIE['abco_sort_direction'] : 'ASC';
  35.  
  36. if ($abco_sort_direction == "DESC")
  37. {
  38.     $sort_arrow = ' <img src="'.$GO_THEME->images['arrow_down'].'" border="0" />';
  39.     $new_sort_direction = "ASC";
  40. }else
  41. {
  42.     $sort_arrow = ' <img src="'.$GO_THEME->images['arrow_up'].'" border="0" />';
  43.     $new_sort_direction = "DESC";
  44. }
  45.  
  46. echo '<input type="hidden" name="first" value="'.$first.'" />';
  47. echo '<input type="hidden" name="max_rows" value="'.$max_rows.'" />';
  48. echo '<input type="hidden" name="task" />';
  49. echo '<input type="hidden" name="new_sort_field" value="'.$abco_sort_field.'" />';
  50. echo '<input type="hidden" name="new_sort_direction" value="'.$abco_sort_direction.'" />';
  51.  
  52. echo '<table border="0" cellspacing="0" cellpadding="0">';
  53.  
  54.  
  55. echo '<tr><td colspan="4">';
  56.  
  57. if ($ab->get_subscribed_addressbooks($GO_SECURITY->user_id) > 1)
  58. {
  59.     echo '<table border="0"><tr><td>'.$ab_addressbook.':</td><td>';
  60.     $subscribed_addressbooks = new dropbox();
  61.     while ($ab->next_record())
  62.     {
  63.         $subscribed_addressbooks->add_value($ab->f('id'), $ab->f('name'));
  64.     }
  65.     $subscribed_addressbooks->print_dropbox('addressbook_id', $addressbook_id, 'onchange="javascript:document.forms[0].submit()"');
  66.     echo '</td></tr></table>';
  67. }else
  68. {
  69.     echo '<input type="hidden" name="addressbook_id" value="'.$addressbook_id.'" />';
  70. }
  71.  
  72. $count = $ab->get_companies($addressbook_id, $abco_sort_field, $abco_sort_direction, $first, $max_rows);
  73. $str_count = $count == 1 ? $ab_companies_count_single : $ab_companies_count;
  74. echo '</td><td colspan="99" class="small" align="right">'.$count.' '.$str_count.'</td></tr>';
  75. echo '<tr height="20">';
  76. echo '<td class="TableHead2" width="16"> </td>';
  77. echo '<td class="TableHead2" width="100" nowrap><a class="TableHead2" href="javascript:_sort(\'name\',\''.$new_sort_direction.'\');">'.$strName.'</a>';
  78. if ($abco_sort_field == 'name')
  79. {
  80.     echo $sort_arrow;
  81. }
  82. echo '</td>';
  83.  
  84. echo '<td class="TableHead2" width="100" nowrap><a class="TableHead2" href="javascript:_sort(\'city\',\''.$new_sort_direction.'\');">'.$strCity.'</a>';
  85. if ($abco_sort_field == 'city')
  86. {
  87.     echo $sort_arrow;
  88. }
  89. echo '</td>';
  90. echo '<td class="TableHead2" width="100" nowrap><a class="TableHead2" href="javascript:_sort(\'email\',\''.$new_sort_direction.'\');">'.$strEmail.'</a>';
  91. if ($abco_sort_field == 'email')
  92. {
  93.     echo $sort_arrow;
  94. }
  95. echo '</td>';
  96. echo '<td class="TableHead2" width="100" nowrap><a class="TableHead2" href="javascript:_sort(\'homepage\',\''.$new_sort_direction.'\');">'.$strHomepage.'</a>';
  97. if ($abco_sort_field == 'homepage')
  98. {
  99.     echo $sort_arrow;
  100. }
  101. echo '</td>';
  102. echo '<td class="TableHead2" width="100" nowrap><a class="TableHead2" href="javascript:_sort(\'phone\',\''.$new_sort_direction.'\');">'.$strPhone.'</a>';
  103. if ($abco_sort_field == 'phone')
  104. {
  105.     echo $sort_arrow;
  106. }
  107. echo '</td>';
  108. echo '</tr>';
  109.  
  110. if ($count > 0)
  111. {
  112.     while($ab->next_record())
  113.     {
  114.         echo '<tr id="'.$ab->f("id").'">';
  115.         echo '<td width="16"><input id="'.$ab->f('name').'" type="checkbox" onclick="javacript:item_click(this)" name="companies[]" value="'.$ab->f("id").'" /></td>';
  116.         echo '<td><a class="normal" href="'.$GO_MODULES->url.'company.php?company_id='.$ab->f('id').'&return_to='.rawurlencode($link_back).'">'.$ab->f('name').'</a></td>';
  117.         echo '<td>'.$ab->f('city').'</td>';
  118.         echo '<td>'.mail_to($ab->f('email'), $ab->f('email')).'</td>';
  119.         echo '<td><a class="normal" target="_blank" href="'.$ab->f('homepage').'">'.$ab->f('homepage').'</a></td>';
  120.         echo '<td>'.$ab->f('phone').'</td>';
  121.         echo '<tr><td colspan="99" height="1"><img src="'.$GO_THEME->images['cccccc'].'" border="0" height="1" width="100%" /></td></tr>';
  122.     }
  123.  
  124.     $links = '';
  125.     $max_links=10;
  126.     if ($max_rows != 0)
  127.     {
  128.         if ($count > $max_rows)
  129.         {
  130.             $links = '<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td>';
  131.             $next_start = $first+$max_rows;
  132.             $previous_start = $first-$max_rows;
  133.             if ($first != 0)
  134.             {
  135.                 $links .= '<a href="javascript:change_list(0, '.$max_rows.');"><<</a> ';
  136.                 $links .= '<a href="javascript:change_list('.$previous_start.', '.$max_rows.');">'.$cmdPrevious.'</a> ';
  137.             }else
  138.             {
  139.                 $links .= '<font color="#cccccc"><< '.$cmdPrevious.'</font> ';
  140.             }
  141.  
  142.             $start = ($first-(($max_links/2)*$max_rows));
  143.  
  144.             $end = ($first+(($max_links/2)*$max_rows));
  145.  
  146.             if ($start < 0)
  147.             {
  148.                 $end = $end - $start;
  149.                 $start=0;
  150.             }
  151.             if ($end > $count)
  152.             {
  153.                 $end = $count;
  154.             }
  155.             if ($start > 0)
  156.             {
  157.                 $links .= '... ';
  158.             }
  159.  
  160.             for ($i=$start;$i<$end;$i+=$max_rows)
  161.             {
  162.                 $page = ($i/$max_rows)+1;
  163.                 if ($i==$first)
  164.                 {
  165.                     $links .= '<b><i>'.$page.'</i></b> ';
  166.                 }else
  167.                 {
  168.                     $links .= '<a href="'.$_SERVER['PHP_SELF'].'?post_action=projects&first='.$i.'">'.$page.'</a> ';
  169.                 }
  170.             }
  171.  
  172.             if ($end < $count)
  173.             {
  174.                 $links .= '... ';
  175.             }
  176.  
  177.             $last_page = floor($count/$max_rows)*$max_rows;
  178.  
  179.             if ($count > $next_start)
  180.             {
  181.                 $links .= '<a href="javascript:change_list('.$next_start.', '.$max_rows.');">'.$cmdNext.'</a> ';
  182.                 $links .= '<a href="javascript:change_list('.$last_page.', '.$max_rows.');">>></a>';
  183.             }else
  184.             {
  185.                 $links .= '<font color="#cccccc">'.$cmdNext.' >></font>';
  186.             }
  187.             $links .= '</td><td align="right"><a class="normal" href="javascript:change_list(0, 0);">'.$cmdShowAll.'</a></td></tr></table>';
  188.  
  189.             echo '<tr height="20"><td colspan="99">'.$links.'</td></tr>';
  190.             echo '<tr><td colspan="99" height="1"><img src="'.$GO_THEME->images['cccccc'].'" border="0" height="1" width="100%" /></td></tr>';
  191.         }
  192.     }
  193.  
  194. }else
  195. {
  196.     echo '<tr><td colspan="99">'.$ab_no_companies.'</td></tr>';
  197.     echo '<tr><td colspan="99" height="1"><img src="'.$GO_THEME->images['cccccc'].'" border="0" height="1" width="100%" /></td></tr>';
  198. }
  199. echo '</table>';
  200. ?>
  201.  
  202. <script type="text/javascript">
  203.  
  204. function _sort(field, direction)
  205. {
  206.     document.forms[0].new_sort_field.value=field;
  207.     document.forms[0].new_sort_direction.value=direction;
  208.     document.forms[0].submit();
  209. }
  210.  
  211. function delete_company(id)
  212. {
  213.     document.forms[0].delete_company_id.value=id;
  214.     document.forms[0].submit();
  215. }
  216.  
  217. function change_list(first, max_rows)
  218. {
  219.     document.forms[0].first.value=first;
  220.     document.forms[0].max_rows.value=max_rows;
  221.     document.forms[0].submit();
  222. }
  223.  
  224. function item_click(check_box)
  225. {
  226.     var item = get_object(check_box.value);
  227.     if (check_box.checked)
  228.     {
  229.         item.className = 'Table2';
  230.     }else
  231.     {
  232.         item.className = 'Table1';
  233.     }
  234. }
  235.  
  236. function confirm_delete()
  237. {
  238.     var count = 0;
  239.     var name = new String;
  240.     for (var i=0;i<document.forms[0].elements.length;i++)
  241.     {
  242.         if(document.forms[0].elements[i].type == 'checkbox' && document.forms[0].elements[i].name != 'dummy')
  243.         {
  244.             if (document.forms[0].elements[i].checked == true)
  245.             {
  246.                 count++;
  247.                 name = document.forms[0].elements[i].id;
  248.             }
  249.         }
  250.     }
  251.     switch (count)
  252.     {
  253.         case 0:
  254.             alert("<?php echo $contacts_no_select; ?>");
  255.         break;
  256.  
  257.         case 1:
  258.             if (confirm("<?php echo $strDeletePrefix; ?> '"+name+"' <?php echo $strDeleteSuffix; ?>"))
  259.             {
  260.                 document.forms[0].task.value='delete_companies';
  261.                 document.forms[0].submit();
  262.             }
  263.         break;
  264.  
  265.         default:
  266.             if (confirm("<?php echo $strDeletePrefix.$strThis; ?> "+count+" <?php echo $contacts_contacts.$strDeleteSuffix; ?>"))
  267.             {
  268.                 document.forms[0].task.value='delete_companies';
  269.                 document.forms[0].submit();
  270.             }
  271.         break;
  272.     }
  273. }
  274.  
  275. </script>
  276.