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

« back to all changes in this revision

Viewing changes to CONTRIB/contacts_importer_CVS/addcontacts3.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
 
 
5
        AUTHOR: Ben Weinberg <ben@bensbrain.com>
 
6
        FILE:  source/addcontacts3.php
 
7
        PURPOSE:
 
8
                Add contacts from csv file...
 
9
        
 
10
********************************************************/
 
11
 
 
12
 
 
13
include("../include/super2global.inc");
 
14
include("../include/contacts_commons.inc");
 
15
include_once("../include/data_manager.inc");
 
16
if (isset($user)){
 
17
        include("../include/header_main.inc");
 
18
        include("../lang/".$my_prefs["lang"]."/contacts.inc");
 
19
        include("../lang/".$my_prefs["lang"]."/compose.inc");
 
20
 
 
21
        //authenticate
 
22
        include_once("../include/icl.inc");
 
23
        $conn=iil_Connect($host, $loginID, $password, $AUTH_MODE);
 
24
        if ($conn){
 
25
                iil_Close($conn);
 
26
        }else{
 
27
                echo "Authentication failed.";
 
28
                echo "</html>\n";
 
29
                exit;
 
30
        }
 
31
}
 
32
 
 
33
$temp_contacts = unserialize(rawurldecode($temp_contacts));
 
34
?>
 
35
 
 
36
<br>
 
37
<table width="100%" cellpadding=2 cellspacing=0>
 
38
<tr bgcolor="#222244"><td>
 
39
<span class="bigTitle">Contact Importer: Page 3/3</span>
 
40
</td></tr>
 
41
<tr bgcolor="#f0f0f0"><td>
 
42
 
 
43
<?php
 
44
 
 
45
//initialize source name
 
46
        $source_name = $DB_CONTACTS_TABLE;
 
47
        if (empty($source_name)) $source_name = "contacts";
 
48
        
 
49
        //open data manager connection
 
50
        $dm = new DataManager_obj;
 
51
        if ($dm->initialize($loginID, $host, $source_name, $backend)){
 
52
        }else{
 
53
                echo "Data Manager initialization failed:<br>\n";
 
54
                $dm->showError();
 
55
        }
 
56
 
 
57
// make array containing names of imported fields and matching iloha fields
 
58
$matching_array = array();
 
59
while (list($key, $value) = each($HTTP_POST_VARS)){
 
60
if ($key != "temp_contacts" && $key != "finish") {
 
61
        // $key is imported field, $value is iloha field
 
62
        if ($value != "") $matching_array["$key"] = $value; 
 
63
        }
 
64
}
 
65
 
 
66
$numrows = count($temp_contacts);
 
67
 
 
68
// $temp_contacts is an array of contacts in sub-arrays like:  ("name"=>"bill",email=>"bill@bill.com")
 
69
 
 
70
// make new array like temp_contacts, using the matching array above to substitute new iloha field names as keys
 
71
 
 
72
for ($i = 0; $i < $numrows; $i++) {  // loop through rows of imported contacts
 
73
 
 
74
if ( isset($new_contact_array) ) unset($new_contact_array);
 
75
 
 
76
                $new_contact_array = array(
 
77
                "owner" => $session_dataID
 
78
//              "grp" => $group,  // this leaves the option of defining a group on the previous page into which to insert these contacts
 
79
        );
 
80
        
 
81
        reset($matching_array);
 
82
        
 
83
        while (list($imp_name, $iloha_name) = each($matching_array)){
 
84
        $newvalue = $temp_contacts[$i][$imp_name];
 
85
//      echo "temp_contacts [$imp_name] = " .  $newvalue . "<br>";
 
86
        if ($newvalue != "") {
 
87
                if (!isset($new_contact_array["$iloha_name"])) $new_contact_array["$iloha_name"] = $newvalue;
 
88
                else $new_contact_array["$iloha_name"] .= "  " . $newvalue;
 
89
                }
 
90
        }
 
91
$recordname = (isset($new_contact_array["name"])) ? "(" . $new_contact_array["name"] . ")" : "" ;
 
92
        
 
93
/*
 
94
        while ( list($key,$value) = each ($new_contact_array)){
 
95
        echo "$key = $value<br>";
 
96
        }
 
97
*/      
 
98
 
 
99
        // insert contact
 
100
        if ($dm->insert($new_contact_array)) echo "Record " . ($i + 1) . " $recordname Inserted <br>\n";
 
101
        else{
 
102
                echo "Insert failed for record " . ($i + 1) . "<br>";
 
103
                $dm->showError();
 
104
        }
 
105
 
 
106
}// end loop through rows of imported contacts
 
107
 
 
108
echo("<br><br><a href='contacts.php?user=$user'>Click here to view all your contacts.</a><br><br>");
 
109
 
 
110
?>
 
111
</td></tr>
 
112
</table>
 
113
</body>
 
114
</html>