~ubuntu-branches/ubuntu/maverick/ilohamail/maverick

« back to all changes in this revision

Viewing changes to CONTRIB/contacts_importer_CVS/contacts.php

  • Committer: Bazaar Package Importer
  • Author(s): Joerg Jaspert
  • Date: 2004-02-04 13:44:37 UTC
  • Revision ID: james.westby@ubuntu.com-20040204134437-kz8j3ui2qa7oq8z2
Tags: upstream-0.8.12
ImportĀ upstreamĀ versionĀ 0.8.12

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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)) echo "Inserted";
 
109
                        else{
 
110
                                echo "Insert failed<br>";
 
111
                                $dm->showError();
 
112
                        }
 
113
                }else{                  //is edit, do an update
 
114
                        if ($dm->update($edit, $new_contact_array)) echo "updated";
 
115
                        else{
 
116
                                echo "update failed<br>";
 
117
                                $dm->showError();
 
118
                        }
 
119
                }
 
120
        }else if (isset($delete)){      //delete entry
 
121
                $dm->delete($delete_item);
 
122
        }else if (isset($remove)){      //confirm removal of entry
 
123
                include("../lang/".$my_prefs["lang"]."/edit_contact.inc");
 
124
                echo "<font color=red>".$errors[6].$name.$errors[7]."</font>\n";
 
125
                echo "[<a href=\"contacts.php?user=$sid&delete=1&delete_item=$delete_item\">".$ecStrings[13]."</a>]\n";
 
126
                echo "[<a href=\"contacts.php?user=$sid\">Cancel</a>]\n";
 
127
        }
 
128
        
 
129
        //initialize sort fields and order
 
130
        if (empty($sort_field)) $sort_field = "grp,name";
 
131
        if (empty($sort_order)) $sort_order = "ASC";
 
132
        
 
133
        //fetch and sort
 
134
        $contacts = $dm->sort($sort_field, $sort_order);
 
135
        $numContacts = count($contacts);
 
136
 
 
137
        //show error, if any
 
138
        if (!empty($error)) echo "<p>".$error."<br>\n";
 
139
        
 
140
        
 
141
        $groups = GetGroups($contacts);
 
142
        echo '<p><a href="edit_contact.php?user='.$sid.'&edit=-1" class="mainLight">'.$cStrings[1].'</a><br>';
 
143
        // line added by Ben Weinberg to link to contact importer
 
144
        echo '<p><a href="addcontacts.php?user='.$sid.'" class="mainLight">Import Contacts from another program</a><br>';
 
145
        echo "\n";
 
146
 
 
147
        //show contacts
 
148
        if ( is_array($contacts) && count($contacts) > 0){
 
149
                reset($contacts);
 
150
                $target = ($my_prefs["compose_inside"]?"list2":"_blank"); 
 
151
        echo "<form method=\"POST\" action=\"compose2.php\" target=\"$target\">\n";
 
152
        echo "<input type=\"hidden\" name=\"user\" value=\"$user\">\n";
 
153
                echo "<table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"1\" bgcolor=\"".$my_colors["main_hilite"]."\">\n";
 
154
                //echo "<table border=1>\n";
 
155
                echo "<tr bgcolor=\"".$my_colors["tool_bg"]."\">";
 
156
        echo "<td class=\"mainHeading\"><b>".$composeHStrings[2]."</b></td>";
 
157
        echo "<td class=\"mainHeading\"><b>".$composeHStrings[3]."</b></td>";
 
158
        echo "<td class=\"mainHeading\"><b>".$composeHStrings[4]."</b></td>";        
 
159
                echo "<td>".FormatHeaderLink($user, $cStrings[3], $textc, "name", $sort_field, $sort_order)."</td>";
 
160
                echo "<td>".FormatHeaderLink($user, $cStrings[4], $textc, "email", $sort_field, $sort_order)."</td>";
 
161
                echo "<td>".FormatHeaderLink($user, $cStrings[6], $textc, "grp,name", $sort_field, $sort_order)."</td>";
 
162
                echo "</tr>";
 
163
                while( list($k1, $foobar) = each($contacts) ){
 
164
                        echo "<tr bgcolor=\"".$my_colors["main_bg"]."\">\n";
 
165
                        $a=$contacts[$k1];
 
166
                        $id=$a["id"];
 
167
                        $toString=(!empty($a["name"])?"\"".$a["name"]."\" ":"")."<".$a["email"].">";
 
168
                        $toString=urlencode($toString);
 
169
                        if (empty($a["name"])) $a["name"]="--";
 
170
            echo "<td><input type=\"checkbox\" name=\"contact_to[]\" value=\"$toString\"></td>";
 
171
            echo "<td><input type=\"checkbox\" name=\"contact_cc[]\" value=\"$toString\"></td>";
 
172
            echo "<td><input type=\"checkbox\" name=\"contact_bcc[]\" value=\"$toString\"></td>";
 
173
                        echo "<td><a href=\"edit_contact.php?user=$sid&k=$k1&edit=$id\">".$a["name"]."</a></td>";
 
174
                        echo "<td><a href=\"compose2.php?user=$sid&to=$toString\" target=$target>".$a["email"]."</a></td>";
 
175
                        echo "<td>".$a["grp"]."</td>";
 
176
                        echo "</tr>\n";
 
177
                }
 
178
                echo "</table>\n";
 
179
        echo "<input type=\"submit\" name=\"contacts_submit\" value=\"".$cStrings[10]."\">\n";
 
180
        }else{
 
181
                echo "<p>".$cErrors[0];
 
182
        }
 
183
}
 
184
?>
 
185
</BODY></HTML>
 
 
b'\\ No newline at end of file'