3
/********************************************************
5
AUTHOR: Ben Weinberg <ben@bensbrain.com>
6
FILE: source/addcontacts3.php
8
Add contacts from csv file...
10
********************************************************/
13
include("../include/super2global.inc");
14
include("../include/contacts_commons.inc");
15
include_once("../include/data_manager.inc");
17
include("../include/header_main.inc");
18
include("../lang/".$my_prefs["lang"]."/contacts.inc");
19
include("../lang/".$my_prefs["lang"]."/compose.inc");
22
include_once("../include/icl.inc");
23
$conn=iil_Connect($host, $loginID, $password, $AUTH_MODE);
27
echo "Authentication failed.";
33
$temp_contacts = unserialize(rawurldecode($temp_contacts));
37
<table width="100%" cellpadding=2 cellspacing=0>
38
<tr bgcolor="#222244"><td>
39
<span class="bigTitle">Contact Importer: Page 3/3</span>
41
<tr bgcolor="#f0f0f0"><td>
45
//initialize source name
46
$source_name = $DB_CONTACTS_TABLE;
47
if (empty($source_name)) $source_name = "contacts";
49
//open data manager connection
50
$dm = new DataManager_obj;
51
if ($dm->initialize($loginID, $host, $source_name, $backend)){
53
echo "Data Manager initialization failed:<br>\n";
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;
66
$numrows = count($temp_contacts);
68
// $temp_contacts is an array of contacts in sub-arrays like: ("name"=>"bill",email=>"bill@bill.com")
70
// make new array like temp_contacts, using the matching array above to substitute new iloha field names as keys
72
for ($i = 0; $i < $numrows; $i++) { // loop through rows of imported contacts
74
if ( isset($new_contact_array) ) unset($new_contact_array);
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
81
reset($matching_array);
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;
91
$recordname = (isset($new_contact_array["name"])) ? "(" . $new_contact_array["name"] . ")" : "" ;
94
while ( list($key,$value) = each ($new_contact_array)){
95
echo "$key = $value<br>";
100
if ($dm->insert($new_contact_array)) echo "Record " . ($i + 1) . " $recordname Inserted <br>\n";
102
echo "Insert failed for record " . ($i + 1) . "<br>";
106
}// end loop through rows of imported contacts
108
echo("<br><br><a href='contacts.php?user=$user'>Click here to view all your contacts.</a><br><br>");