home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / groupoffice-com-2.01 / modules / addressbook / addressbook.inc < prev    next >
Text File  |  2004-03-08  |  16KB  |  449 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($_SESSION['contacts_expanded']))
  14.     $_SESSION['contacts_expanded'][]=-1;
  15.  
  16. if (!isset($_COOKIE['contact_sort']))
  17. {
  18.     $_COOKIE['contact_sort'] = 'name';
  19. }
  20.  
  21. if (!isset($_COOKIE['contact_direction']))
  22. {
  23.     $_COOKIE['contact_direction'] = 'ASC';
  24. }
  25. if ($_COOKIE['contact_direction'] == "DESC")
  26. {
  27.     $image_string = ' <img src="'.$GO_THEME->images['arrow_down'].'" border="0" />';
  28.     $newdirection = "ASC";
  29. }else
  30. {
  31.     $image_string = ' <img src="'.$GO_THEME->images['arrow_up'].'" border="0" />';
  32.     $newdirection = "DESC";
  33. }
  34.  
  35. switch($task)
  36. {
  37.     case "delete":
  38.             for ($i=0;$i<sizeof($_POST['contact']);$i++)
  39.             {
  40.                 $contact = $ab->get_contact($_POST['contact'][$i]);
  41.  
  42.                 if ($GO_SECURITY->has_permission($GO_SECURITY->user_id, $contact['acl_write']))
  43.                 {
  44.                     $ab->delete_contact($_POST['contact'][$i]);
  45.                     $GO_SECURITY->delete_acl($contact['acl_write']);
  46.                     $GO_SECURITY->delete_acl($contact['acl_read']);
  47.                 }
  48.             }
  49.     break;
  50.  
  51.     case "move":
  52.         if ($GO_SECURITY->has_permission($GO_SECURITY->user_id, $addressbook['acl_write']))
  53.         {
  54.             if (!isset($_POST['group_id']))
  55.             {
  56.                 $_POST['group_id']="0";
  57.             }
  58.  
  59.             if (isset($_POST['contact']))
  60.             {
  61.                 for ($i=0;$i<sizeof($_POST['contact']);$i++)
  62.                 {
  63.                     $ab->move_contact_to_group($_POST['contact'][$i], $_POST['group_id']);
  64.                 }
  65.             }
  66.         }
  67.  
  68.     break;
  69.  
  70.     case "expand":
  71.  
  72.         if (isset($_POST['expand_id']))
  73.         {
  74.             $key = array_search($_POST['expand_id'], $_SESSION['contacts_expanded']);
  75.             if (!$key)
  76.             {
  77.                 $_SESSION['contacts_expanded'][]=$_POST['expand_id'];
  78.             }else
  79.             {
  80.                 unset($_SESSION['contacts_expanded'][$key]);
  81.             }
  82.         }
  83.     break;
  84. }
  85.  
  86.  
  87. echo '<input type="hidden" name="post_action" value="browse" />';
  88. echo '<input type="hidden" name="task" value="" />';
  89. echo '<input type="hidden" value="'.$newdirection.'" name="newdirection" />';
  90. echo '<input type="hidden" name="newsort" />';
  91. echo '<input type="hidden" name="expand_id" />';
  92.  
  93. if (isset($feedback)) echo $feedback;
  94.  
  95. echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"600\">\n";
  96. echo '<tr><td colspan="99">';
  97. echo '<table border="0"><tr>';
  98. if ($ab->get_subscribed_addressbooks($GO_SECURITY->user_id) > 1)
  99. {
  100.     echo '<td>'.$ab_addressbook.':</td><td>';
  101.     $subscribed_addressbooks = new dropbox();
  102.     while ($ab->next_record())
  103.     {
  104.         $subscribed_addressbooks->add_value($ab->f('id'), $ab->f('name'));
  105.     }
  106.     $subscribed_addressbooks->print_dropbox('addressbook_id', $addressbook_id, 'onchange="javascript:document.forms[0].submit()"');
  107.     echo '</td>';
  108. }else
  109. {
  110.     echo '<input type="hidden" name="addressbook_id" value="'.$addressbook_id.'" />';
  111. }
  112.  
  113. echo '<td align="right" width="100%">';
  114. $group_count = $ab->get_groups($addressbook_id);
  115. if ($group_count > 0)
  116. {
  117.     $groups = array();
  118.  
  119.     $dropbox = new dropbox();
  120.     $dropbox->add_value('',$contacts_move_to_group);
  121.     $dropbox->add_value('0',$contacts_other);
  122.  
  123.     while ($ab->next_record())
  124.     {
  125.         $dropbox->add_value($ab->f('id'), $ab->f('name'));
  126.         $group['name'] = $ab->f('name');
  127.         $group['id'] = $ab->f('id');
  128.         $groups[] = $group;
  129.     }
  130.     if ($GO_SECURITY->has_permission($GO_SECURITY->user_id, $addressbook['acl_write']))
  131.     {
  132.         $dropbox->print_dropbox('group_id','','onchange="javascript:move_to_group()"');
  133.     }
  134. }
  135. echo '</td></tr></table>';
  136. echo '</td></tr>';
  137.  
  138. echo "<tr>";
  139. echo '<td class="TableHead2" width="16"> </td>';
  140. echo '<td class="TableHead2" width="16"><input type="checkbox" name="dummy" value="dummy" onclick="javascript:invert_selection()" /></td>';
  141. echo "<td class=\"TableHead2\" nowrap><a class=\"TableHead2\" href=\"javascript:sort('name')\">".$strName;
  142. if ($_COOKIE['contact_sort'] == "name")
  143.         echo $image_string;
  144. echo "</a></td>\n";
  145. echo "<td class=\"TableHead2\" nowrap><a class=\"TableHead2\" href=\"javascript:sort('email')\">".$strEmail;
  146. if ($_COOKIE['contact_sort'] == "email")
  147.         echo $image_string;
  148. echo "</a></td>\n";
  149. echo "<td class=\"TableHead2\" nowrap><a class=\"TableHead2\" href=\"javascript:sort('home_phone')\">".$strPhone;
  150. if ($_COOKIE['contact_sort'] == "home_phone")
  151.         echo $image_string;
  152. echo "</a></td>\n";
  153. echo "<td class=\"TableHead2\" nowrap><a class=\"TableHead2\" href=\"javascript:sort('work_phone')\">".$strWorkphone;
  154. if ($_COOKIE['contact_sort'] == "work_phone")
  155.         echo $image_string;
  156. echo "</a></td>\n";
  157. echo "</tr>\n";
  158.  
  159. if(isset($groups))
  160. {
  161.     for($i=0;$i<sizeof($groups);$i++)
  162.     {
  163.         if (in_array($groups[$i]['id'], $_SESSION['contacts_expanded']))
  164.         {
  165.             echo "<tr class=\"Table4\"><td><a href=\"javascript:expand_group(".$groups[$i]['id'].")\"><img src=\"".$GO_THEME->images['min_node']."\" border=\"0\" /></a></td><td><input type=\"checkbox\" name=\"dummy\" value=\"dummy\" onclick=\"javascript:select_group('".$groups[$i]['id']."')\" /></td><td colspan=\"4\">".$groups[$i]['name']."</td></tr>";
  166.             echo '<tr><td colspan="99" height="1"><img src="'.$GO_THEME->images['cccccc'].'" border="0" height="1" width="100%" /></td></tr>';
  167.  
  168.             if ($ab->get_contacts_group($addressbook_id, $groups[$i]['id'], $_COOKIE['contact_sort'], $_COOKIE['contact_direction']) > 0)
  169.             {
  170.                 echo '<input type="hidden" name="group_start_'.$groups[$i]['id'].'" />';
  171.                 while ($ab->next_record())
  172.                 {
  173.                     $checked = "";
  174.                     $class = 'Table1';
  175.                     if (isset($contact))
  176.                     {
  177.                         $key = array_search($ab->f("id"), $contact);
  178.                         if (is_int($key))
  179.                         {
  180.                             unset($contact[$key]);
  181.                             $checked = "checked";
  182.                             $class = 'Table2';
  183.                         }
  184.                     }
  185.  
  186.                     if ($ab->f('color') != '')
  187.                     {
  188.                         $style = ' style="color: '.$ab->f('color').';"';
  189.                     }else
  190.                     {
  191.                         $style = '';
  192.                     }
  193.  
  194.                     $middle_name = $ab->f('middle_name') == '' ? '' : $ab->f('middle_name').' ';
  195.                     $name = $ab->f('first_name').' '.$middle_name.$ab->f('last_name');
  196.  
  197.                     echo "<tr id=\"".$ab->f("id")."\" class=\"".$class."\"><td> </td>\n";
  198.                     echo "<td><input id=\"".$name."\" type=\"checkbox\" onclick=\"javacript:item_click(this)\" name=\"contact[]\" value=\"".$ab->f("id")."\" ".$checked." /></td><td><a".$style." class=\"normal\" href=\"contact.php?contact_id=".$ab->f("id")."&return_to=".rawurlencode($_SERVER['REQUEST_URI'])."\" title=\"".$strShowProfile."\">".empty_to_stripe($name)."</a> </td>\n";
  199.                     echo "<td>".mail_to(empty_to_stripe($ab->f("email")), empty_to_stripe($ab->f("email")),'normal',true, $ab->f("id"))." </td>\n";
  200.                     echo "<td>".empty_to_stripe($ab->f("home_phone"))." </td>\n";
  201.                     echo "<td>".empty_to_stripe($ab->f("work_phone"))." </td>\n";
  202.                     echo "</tr>\n";
  203.                     echo '<tr><td colspan="99" height="1"><img src="'.$GO_THEME->images['cccccc'].'" border="0" height="1" width="100%" /></td></tr>';
  204.                 }
  205.                 echo '<input type="hidden" name="group_end_'.$groups[$i]['id'].'" />';
  206.             }else
  207.             {
  208.                 echo "<tr><td colspan=\"99\" height=\"18\">".$contacts_empty_group."</td></tr>";
  209.                 echo '<tr><td colspan="99" height="1"><img src="'.$GO_THEME->images['cccccc'].'" border="0" height="1" width="100%" /></td></tr>';
  210.             }
  211.         }else
  212.         {
  213.             echo "<tr class=\"Table4\"><td><a href=\"javascript:expand_group(".$groups[$i]['id'].")\"><img src=\"".$GO_THEME->images['plus_node']."\" border=\"0\" /></a></td><td> </td><td colspan=\"4\" width=\"100%\">".$groups[$i]['name']."</td></tr>";
  214.             echo '<tr><td colspan="99" height="1"><img src="'.$GO_THEME->images['cccccc'].'" border="0" height="1" width="100%" /></td></tr>';
  215.         }
  216.     }
  217. }
  218.  
  219. if ($group_count > 0)
  220. {
  221.     if (in_array(0, $_SESSION['contacts_expanded']))
  222.     {
  223.         echo "<tr class=\"Table4\"><td><a href=\"javascript:expand_group(0)\"><img src=\"".$GO_THEME->images['min_node']."\" border=\"0\" /></a><td><input type=\"checkbox\" name=\"dummy\" value=\"dummy\" onclick=\"javascript:select_group('0')\" /></td><td colspan=\"4\">".$contacts_other."</td></tr>";
  224.         echo '<tr><td colspan="99" height="1"><img src="'.$GO_THEME->images['cccccc'].'" border="0" height="1" width="100%" /></td></tr>';
  225.  
  226.         $ab->get_contacts_group($addressbook_id,0, $_COOKIE['contact_sort'], $_COOKIE['contact_direction']);
  227.         if ($ab->num_rows() > 0)
  228.         {
  229.             echo '<input type="hidden" name="group_start_0" />';
  230.             while ($ab->next_record())
  231.             {
  232.                 $checked = "";
  233.                 $class = 'Table1';
  234.                 if (isset($contact))
  235.                 {
  236.                     $key = array_search($ab->f("id"), $contact);
  237.                     if (is_int($key))
  238.                     {
  239.                         unset($contact[$key]);
  240.                         $checked = "checked";
  241.                         $class = 'Table2';
  242.                     }
  243.                 }
  244.                 if ($ab->f('color') != '')
  245.                 {
  246.                     $style = ' style="color: '.$ab->f('color').';"';
  247.                 }else
  248.                 {
  249.                     $style = '';
  250.                 }
  251.  
  252.                 $middle_name = $ab->f('middle_name') == '' ? '' : $ab->f('middle_name').' ';
  253.                 $name = $ab->f('first_name').' '.$middle_name.$ab->f('last_name');
  254.                 echo "<tr id=\"".$ab->f("id")."\" class=\"".$class."\"><td> </td>\n";
  255.                 echo "<td><input id=\"".$name."\" onclick=\"javacript:item_click(this)\" type=\"checkbox\" name=\"contact[]\" value=\"".$ab->f("id")."\" ".$checked." /></td><td><a".$style." class=\"normal\" href=\"contact.php?contact_id=".$ab->f("id")."&return_to=".rawurlencode($_SERVER['REQUEST_URI'])."\" title=\"".$strShowProfile."\">".empty_to_stripe($name)."</a> </td>\n";
  256.                 echo "<td>".mail_to(empty_to_stripe($ab->f("email")), empty_to_stripe($ab->f("email")),'normal',true, $ab->f("id"))." </td>\n";
  257.                 echo "<td>".empty_to_stripe($ab->f("home_phone"))." </td>\n";
  258.                 echo "<td>".empty_to_stripe($ab->f("work_phone"))." </td>\n";
  259.                 echo "</tr>\n";
  260.                 echo '<tr><td colspan="99" height="1"><img src="'.$GO_THEME->images['cccccc'].'" border="0" height="1" width="100%" /></td></tr>';
  261.             }
  262.             echo '<input type="hidden" name="group_end_0" />';
  263.         }else
  264.         {
  265.             if ($group_count > 0)
  266.                 $text = $contacts_empty_group;
  267.             else
  268.                 $text = $contacts_no_contacts;
  269.  
  270.             echo "<tr><td colspan=\"99\" height=\"18\" class=\"normal\">".$text."</td></tr>";
  271.             echo '<tr><td colspan="99" height="1"><img src="'.$GO_THEME->images['cccccc'].'" border="0" height="1" width="100%" /></td></tr>';
  272.         }
  273.     }else
  274.     {
  275.         echo "<tr class=\"Table4\"><td><a href=\"javascript:expand_group(0)\"><img src=\"".$GO_THEME->images['plus_node']."\" border=\"0\" /></a><td> </td><td colspan=\"4\" width=\"100%\">".$contacts_other."</td></tr>";
  276.         echo '<tr><td colspan="99" height="1"><img src="'.$GO_THEME->images['cccccc'].'" border="0" height="1" width="100%" /></td></tr>';
  277.     }
  278. }else
  279. {
  280.     $ab->get_contacts_group($addressbook_id, 0, $_COOKIE['contact_sort'], $_COOKIE['contact_direction']);
  281.     if ($ab->num_rows() > 0)
  282.     {
  283.         echo '<input type="hidden" name="group_start_0" />';
  284.         while ($ab->next_record())
  285.         {
  286.             $class = 'Table1';
  287.             $checked = "";
  288.             if (isset($contact))
  289.             {
  290.                 $key = array_search($ab->f("id"), $contact);
  291.                 if (is_int($key))
  292.                 {
  293.                     unset($contact[$key]);
  294.                     $checked = "checked";
  295.                     $class = 'Table2';
  296.                 }
  297.             }
  298.             if ($ab->f('color') != '')
  299.             {
  300.                 $style = ' style="color: '.$ab->f('color').';"';
  301.             }else
  302.             {
  303.                 $style = '';
  304.             }
  305.             $middle_name = $ab->f('middle_name') == '' ? '' : $ab->f('middle_name').' ';
  306.             $name = $ab->f('first_name').' '.$middle_name.$ab->f('last_name');
  307.  
  308.             echo "<tr id=\"".$ab->f("id")."\" class=\"".$class."\"><td width=\"16\"> </td>\n";
  309.             echo "<td width=\"16\"><input id=\"".$name."\" onclick=\"javacript:item_click(this)\"  type=\"checkbox\" name=\"contact[]\" value=\"".$ab->f("id")."\" ".$checked." /></td><td><a".$style." class=\"normal\" href=\"contact.php?contact_id=".$ab->f("id")."&return_to=".rawurlencode($_SERVER['REQUEST_URI'])."\" title=\"".$strShowProfile."\">".empty_to_stripe($name)."</a> </td>\n";
  310.             echo "<td>".mail_to(empty_to_stripe($ab->f("email")), empty_to_stripe($ab->f("email")),'normal',true, $ab->f("id"))." </td>\n";
  311.             echo "<td>".empty_to_stripe($ab->f("home_phone"))." </td>\n";
  312.             echo "<td>".empty_to_stripe($ab->f("work_phone"))." </td>\n";
  313.             echo "</tr>\n";
  314.             echo '<tr><td colspan="99" height="1"><img src="'.$GO_THEME->images['cccccc'].'" border="0" height="1" width="100%" /></td></tr>';
  315.         }
  316.         echo '<input type="hidden" name="group_end_0" />';
  317.     }else
  318.     {
  319.         if ($group_count > 0)
  320.             $text = $contacts_empty_group;
  321.         else
  322.             $text = $contacts_no_contacts;
  323.  
  324.         echo "<tr><td colspan=\"99\" height=\"18\" class=\"normal\" width=\"100%\">".$text."</td></tr>";
  325.         echo '<tr><td colspan="99" height="1"><img src="'.$GO_THEME->images['cccccc'].'" border="0" height="1" width="100%" /></td></tr>';
  326.     }
  327.  
  328. }
  329.  
  330. if (isset($contact))
  331. {
  332.     while($adress = array_pop($contact))
  333.     {
  334.         echo '<input type="hidden" name="contact[]" value="'.$adress.'" />';
  335.     }
  336. }
  337. echo '</table>';
  338. ?>
  339. <script type="text/javascript" language="javascript">
  340. <!--
  341. function item_click(check_box)
  342. {
  343.     var item = get_object(check_box.value);
  344.     if (check_box.checked)
  345.     {
  346.         item.className = 'Table2';
  347.     }else
  348.     {
  349.         item.className = 'Table1';
  350.     }
  351. }
  352.  
  353. function invert_selection()
  354. {
  355.     for (var i=0;i<document.forms[0].elements.length;i++)
  356.     {
  357.         if(document.forms[0].elements[i].type == 'checkbox' && document.forms[0].elements[i].name != 'dummy')
  358.         {
  359.             document.forms[0].elements[i].checked = !(document.forms[0].elements[i].checked);
  360.             item_click(document.forms[0].elements[i]);
  361.         }
  362.     }
  363. }
  364.  
  365. function select_group(group_id)
  366. {
  367.     var add = false;
  368.  
  369.     for (var i = 0; i < document.forms[0].elements.length; i++)
  370.     {
  371.         if (document.forms[0].elements[i].name == 'group_start_'+group_id)
  372.         {
  373.             add = true;
  374.         }
  375.  
  376.         if (document.forms[0].elements[i].name == 'group_end_'+group_id)
  377.         {
  378.             add = false;
  379.         }
  380.  
  381.         if(document.forms[0].elements[i].type == 'checkbox' && document.forms[0].elements[i].name != 'dummy' && add==true)
  382.         {
  383.             document.forms[0].elements[i].checked = !(document.forms[0].elements[i].checked);
  384.             item_click(document.forms[0].elements[i]);
  385.         }
  386.     }
  387. }
  388.  
  389. function confirm_delete()
  390. {
  391.     var count = 0;
  392.     var name = new String;
  393.     for (var i=0;i<document.forms[0].elements.length;i++)
  394.     {
  395.         if(document.forms[0].elements[i].type == 'checkbox' && document.forms[0].elements[i].name != 'dummy')
  396.         {
  397.             if (document.forms[0].elements[i].checked == true)
  398.             {
  399.                 count++;
  400.                 name = document.forms[0].elements[i].id;
  401.             }
  402.         }
  403.     }
  404.     switch (count)
  405.     {
  406.         case 0:
  407.             alert("<?php echo $contacts_no_select; ?>");
  408.         break;
  409.  
  410.         case 1:
  411.             if (confirm("<?php echo $strDeletePrefix; ?> '"+name+"' <?php echo $strDeleteSuffix; ?>"))
  412.             {
  413.                 document.forms[0].task.value="delete";
  414.                 document.forms[0].submit();
  415.             }
  416.         break;
  417.  
  418.         default:
  419.             if (confirm("<?php echo $strDeletePrefix.$strThis; ?> "+count+" <?php echo $contacts_contacts.$strDeleteSuffix; ?>"))
  420.             {
  421.                 document.forms[0].task.value="delete";
  422.                 document.forms[0].submit();
  423.             }
  424.         break;
  425.     }
  426. }
  427.  
  428. function move_to_group()
  429. {
  430.     document.forms[0].task.value="move";
  431.     document.forms[0].submit();
  432. }
  433. function sort(column)
  434. {
  435.     document.forms[0].task.value = 'sort';
  436.     document.forms[0].newsort.value = column;
  437.     document.forms[0].submit();
  438. }
  439.  
  440. function expand_group(group_id)
  441. {
  442.     document.forms[0].newdirection.value = '';
  443.     document.forms[0].expand_id.value = group_id;
  444.     document.forms[0].task.value = "expand";
  445.     document.forms[0].submit();
  446. }
  447.  
  448. //-->
  449. </script>