home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / admin / contacts.php < prev    next >
Encoding:
PHP Script  |  2003-12-27  |  6.3 KB  |  181 lines

  1. <?php
  2. /////////////////////////////////////////////////////////
  3. //    
  4. //    source/contacts.php
  5. //
  6. //    (C)Copyright 2001-2002 Ryo Chijiiwa <Ryo@IlohaMail.org>
  7. //
  8. //        This file is part of IlohaMail.
  9. //        IlohaMail is free software released under the GPL 
  10. //        license.  See enclosed file COPYING for details,
  11. //        or see http://www.fsf.org/copyleft/gpl.html
  12. //
  13. /////////////////////////////////////////////////////////
  14.  
  15. /********************************************************
  16.  
  17.     AUTHOR: Ryo Chijiiwa <ryo@ilohamail.org>
  18.     FILE:  source/contacts.php
  19.     PURPOSE:
  20.         List basic information of all contacts. 
  21.         Offer links to
  22.             -view/edit contact
  23.             -send email to contact
  24.             -add new contact
  25.         Process posted data to edit/add/remove contacts information
  26.     PRE-CONDITIONS:
  27.         Required:
  28.             $user-Session ID for session validation and user prefernce retreaval
  29.         Optional:
  30.             POST'd data for add/remove/edit entries.  See source/edit_contact.php
  31.     POST-CONDITIONS:
  32.     COMMENTS:
  33.  
  34. ********************************************************/
  35.  
  36. function FormatHeaderLink($user, $label, $color, $new_sort_field, $sort_field, $sort_order){
  37.     if (strcasecmp($new_sort_field, $sort_field)==0){
  38.         if (strcasecmp($sort_order, "ASC")==0) $sort_order="DESC";
  39.         else $sort_order = "ASC";
  40.     }
  41.     $link = "<a href=\"contacts.php?user=$user&sort_field=$new_sort_field&sort_order=$sort_order\" class=\"mainHeading\">";
  42.     $link .= "<b>".$label."</b></a>";
  43.     return $link;
  44. }
  45.  
  46. include("../include/super2global.inc");
  47. include("../include/contacts_commons.inc");
  48. include_once("../include/data_manager.inc");
  49. if (isset($user)){
  50.     include("../include/header_main.inc");
  51.     include("../lang/".$my_prefs["lang"]."/contacts.inc");
  52.     include("../lang/".$my_prefs["lang"]."/compose.inc");
  53.  
  54.     //authenticate
  55.     include_once("../include/icl.inc");
  56.     $conn=iil_Connect($host, $loginID, $password, $AUTH_MODE);
  57.     if ($conn){
  58.         iil_Close($conn);
  59.     }else{
  60.         echo "Authentication failed.";
  61.         echo "</html>\n";
  62.         exit;
  63.     }
  64.  
  65.     echo "\n<table width=\"100%\" cellpadding=2 cellspacing=0><tr bgcolor=\"".$my_colors["main_head_bg"]."\">\n";
  66.     echo "<td align=left valign=bottom>\n";
  67.     echo "<span class=\"bigTitle\">".$cStrings[0]."</span>\n";
  68.     echo "</td></tr></table>\n";
  69.  
  70.     //initialize source name
  71.     $source_name = $DB_CONTACTS_TABLE;
  72.     if (empty($source_name)) $source_name = "contacts";
  73.     
  74.     //open data manager connection
  75.     $dm = new DataManager_obj;
  76.     if ($dm->initialize($loginID, $host, $source_name, $backend)){
  77.     }else{
  78.         echo "Data Manager initialization failed:<br>\n";
  79.         $dm->showError();
  80.     }
  81.     
  82.     //do add
  83.     if (isset($add)){
  84.         //set group if "other"
  85.         if (strcmp($group,"_otr_")==0) $group=$other_group;
  86.         
  87.         //create data array
  88.         $new_contact_array = array(
  89.             "owner" => $session_dataID,
  90.             "name" => $name,
  91.             "email" => $email,
  92.             "email2" => $email2,
  93.             "grp" => $group,
  94.             "aim" => $aim,
  95.             "icq" => $icq,
  96.             "yahoo" => $yahoo,
  97.             "msn" => $msn,
  98.             "jabber" => $jabber,
  99.             "phone" => $phone,
  100.             "work" => $work,
  101.             "cell" => $cell,
  102.             "address" => $address,
  103.             "url" => $url,
  104.             "comments" => $comments
  105.         );
  106.         
  107.         if ($edit<=0){    //if not edit (i.e. new), do an insert
  108.             if (!$dm->insert($new_contact_array)){
  109.                 echo "Insert failed<br>";
  110.                 $dm->showError();
  111.             }
  112.         }else{            //is edit, do an update
  113.             if (!$dm->update($edit, $new_contact_array)){
  114.                 echo "update failed<br>";
  115.                 $dm->showError();
  116.             }
  117.         }
  118.     }else if (isset($delete)){    //delete entry
  119.         $dm->delete($delete_item);
  120.     }else if (isset($remove)){    //confirm removal of entry
  121.         include("../lang/".$my_prefs["lang"]."/edit_contact.inc");
  122.         echo "<font color=red>".$errors[6].$name.$errors[7]."</font>\n";
  123.         echo "[<a href=\"contacts.php?user=$sid&delete=1&delete_item=$delete_item\" class=\"mainLight\">".$ecStrings[13]."</a>]\n";
  124.         echo "[<a href=\"contacts.php?user=$sid\" class=\"mainLight\">Cancel</a>]\n";
  125.     }
  126.     
  127.     //initialize sort fields and order
  128.     if (empty($sort_field)) $sort_field = "grp,name";
  129.     if (empty($sort_order)) $sort_order = "ASC";
  130.     
  131.     //fetch and sort
  132.     $contacts = $dm->sort($sort_field, $sort_order);
  133.     $numContacts = count($contacts);
  134.  
  135.     //show error, if any
  136.     if (!empty($error)) echo "<p>".$error."<br>\n";
  137.     
  138.     
  139.     $groups = GetGroups($contacts);
  140.     echo '<p><a href="edit_contact.php?user='.$sid.'&edit=-1" class="mainLight">'.$cStrings[1].'</a><br>';
  141.     echo "\n";
  142.  
  143.     //show contacts
  144.     if ( is_array($contacts) && count($contacts) > 0){
  145.         reset($contacts);
  146.         $target = ($my_prefs["compose_inside"]?"list2":"_blank"); 
  147.         echo "<form method=\"POST\" action=\"compose2.php\" target=\"$target\">\n";
  148.         echo "<input type=\"hidden\" name=\"user\" value=\"$user\">\n";
  149.         echo "<table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"1\" bgcolor=\"".$my_colors["main_hilite"]."\">\n";
  150.         //echo "<table border=1>\n";
  151.         echo "<tr bgcolor=\"".$my_colors["main_head_bg"]."\">";
  152.         echo "<td class=\"mainHeading\"><b>".$composeHStrings[2]."</b></td>";
  153.         echo "<td class=\"mainHeading\"><b>".$composeHStrings[3]."</b></td>";
  154.         echo "<td class=\"mainHeading\"><b>".$composeHStrings[4]."</b></td>";        
  155.         echo "<td>".FormatHeaderLink($user, $cStrings[3], $textc, "name", $sort_field, $sort_order)."</td>";
  156.         echo "<td>".FormatHeaderLink($user, $cStrings[4], $textc, "email", $sort_field, $sort_order)."</td>";
  157.         echo "<td>".FormatHeaderLink($user, $cStrings[6], $textc, "grp,name", $sort_field, $sort_order)."</td>";
  158.         echo "</tr>";
  159.         while( list($k1, $foobar) = each($contacts) ){
  160.             echo "<tr bgcolor=\"".$my_colors["main_bg"]."\">\n";
  161.             $a=$contacts[$k1];
  162.             $id=$a["id"];
  163.             $toString=(!empty($a["name"])?"\"".$a["name"]."\" ":"")."<".$a["email"].">";
  164.             $toString=urlencode($toString);
  165.             if (empty($a["name"])) $a["name"]="--";
  166.             echo "<td><input type=\"checkbox\" name=\"contact_to[]\" value=\"$toString\"></td>";
  167.             echo "<td><input type=\"checkbox\" name=\"contact_cc[]\" value=\"$toString\"></td>";
  168.             echo "<td><input type=\"checkbox\" name=\"contact_bcc[]\" value=\"$toString\"></td>";
  169.             echo "<td><a href=\"edit_contact.php?user=$sid&k=$k1&edit=$id\">".$a["name"]."</a></td>";
  170.             echo "<td><a href=\"compose2.php?user=$sid&to=$toString\" target=$target>".$a["email"]."</a></td>";
  171.             echo "<td>".$a["grp"]."</td>";
  172.             echo "</tr>\n";
  173.         }
  174.         echo "</table>\n";
  175.         echo "<input type=\"submit\" name=\"contacts_submit\" value=\"".$cStrings[10]."\">\n";
  176.     }else{
  177.         echo "<p>".$cErrors[0];
  178.     }
  179. }
  180. ?>
  181. </BODY></HTML>