Formatting and some adjustment to start making actual imports work again

This commit is contained in:
Miles Lott 2001-03-11 06:58:57 +00:00
parent ed3da58048
commit 3d06057c20
3 changed files with 501 additions and 500 deletions

View File

@ -1,7 +1,7 @@
<?php <?php
// This file defines a set of functions and an associative array. // This file defines a set of functions and an associative array.
// The key of the array corresponds to a header in the source // The key of the array corresponds to a header in the source
// outlook file and the value of the array item will be used in // import file and the value of the array item will be used in
// the creation of the output file. // the creation of the output file.
// //
// An exported Outlook file looks like this: // An exported Outlook file looks like this:
@ -23,7 +23,8 @@
// Also start with a '#' symbol and a comma separated list will be // Also start with a '#' symbol and a comma separated list will be
// turned into a number of the same entries. // turned into a number of the same entries.
class outlook_conv { class import_conv
{
var $basedn; var $basedn;
var $contactsdn; var $contactsdn;
@ -32,7 +33,7 @@ class outlook_conv {
var $givenName; //this is used in building a cn field var $givenName; //this is used in building a cn field
var $currentrecord; //used for buffering to allow uid lines to go first var $currentrecord; //used for buffering to allow uid lines to go first
var $outlook = array( var $import = array(
"Title" => "", "Title" => "",
"First Name" => "givenName", "First Name" => "givenName",
"Middle Name" => "", "Middle Name" => "",
@ -116,9 +117,10 @@ class outlook_conv {
"User 2" => "", "User 2" => "",
"User 3" => "", "User 3" => "",
"User 4" => "", "User 4" => "",
"Web Page" => ""); "Web Page" => ""
);
function outlook_start_file($buffer,$basedn="",$context="") { function import_start_file($buffer,$basedn="",$context="") {
# Here are some tests for correct basedn and Contacts context. # Here are some tests for correct basedn and Contacts context.
# If none of these are correct, ldap_add will fail, but at least # If none of these are correct, ldap_add will fail, but at least
# we can give them a fighting chance. # we can give them a fighting chance.
@ -152,21 +154,21 @@ function outlook_start_file($buffer,$basedn="",$context="") {
$this->basedn= $basedn; $this->basedn= $basedn;
$this->contactsdn= $context; $this->contactsdn= $context;
$buffer="";
return $buffer; return $buffer;
} }
function outlook_end_file($buffer) { function import_end_file($buffer) {
return $buffer; return $buffer;
} }
function outlook_start_record($buffer) { function import_start_record($buffer) {
global $phpgw_info; global $phpgw_info;
$top="\nobjectClass: person $top="\nobjectClass: person
objectClass: organizationalPerson objectClass: organizationalPerson
objectClass: inetOrgPerson objectClass: inetOrgPerson
objectClass: outlookPerson"; objectClass: importPerson";
$this->o=""; $this->o="";
$this->sn=""; $this->sn="";
@ -176,7 +178,7 @@ objectClass: outlookPerson";
return $buffer; return $buffer;
} }
function outlook_end_record($buffer,$private="") { function import_end_record($buffer,$private="") {
if (trim($this->sn) != "") { if (trim($this->sn) != "") {
$this->currentrecord = "cn: ".$this->givenName." ".$this->sn.$this->currentrecord; $this->currentrecord = "cn: ".$this->givenName." ".$this->sn.$this->currentrecord;
} else if (trim($this->o) != "") { } else if (trim($this->o) != "") {
@ -208,7 +210,7 @@ function outlook_end_record($buffer,$private="") {
return $buffer.$this->currentrecord."\n\n"; return $buffer.$this->currentrecord."\n\n";
} }
function outlook_new_attrib($buffer,$name,$value) { function import_new_attrib($buffer,$name,$value) {
if ($name == "sn") { if ($name == "sn") {
$this->sn = $value; $this->sn = $value;
} }
@ -246,7 +248,7 @@ function outlook_new_attrib($buffer,$name,$value) {
$this->currentrecord .= "\n$name: $value"; $this->currentrecord .= "\n$name: $value";
} }
return $buffer; return $buffer;
} } // end switch
} }
} }
?> ?>

View File

@ -1,7 +1,7 @@
<?php <?php
// This file defines a set of functions and an associative array. // This file defines a set of functions and an associative array.
// The key of the array corresponds to a header in the source // The key of the array corresponds to a header in the source
// outlook file and the value of the array item will be used in // import file and the value of the array item will be used in
// the creation of the output file. // the creation of the output file.
// //
// An exported Outlook file looks like this: // An exported Outlook file looks like this:
@ -23,10 +23,11 @@
// Also start with a '#' symbol and a comma separated list will be // Also start with a '#' symbol and a comma separated list will be
// turned into a number of the same entries. // turned into a number of the same entries.
class outlook_conv { class import_conv
{
var $currentrecord; //used for buffering to allow uid lines to go first var $currentrecord; //used for buffering to allow uid lines to go first
var $outlook = array( var $import = array(
"Title" => "title", "Title" => "title",
"First Name" => "n_given", "First Name" => "n_given",
"Middle Name" => "n_middle", "Middle Name" => "n_middle",
@ -97,7 +98,7 @@ class outlook_conv {
"Location" => "", "Location" => "",
"Manager's Name" => "", "Manager's Name" => "",
"Mileage" => "", "Mileage" => "",
"Notes" => "ab_notes", "Notes" => "note",
"Office Location" => "", "Office Location" => "",
"Organizational ID Number" => "", "Organizational ID Number" => "",
"PO Box" => "postOfficeBox", "PO Box" => "postOfficeBox",
@ -110,24 +111,26 @@ class outlook_conv {
"User 2" => "", "User 2" => "",
"User 3" => "", "User 3" => "",
"User 4" => "", "User 4" => "",
"Web Page" => ""); "Web Page" => ""
);
function outlook_start_file($buffer,$j="",$k="") { function import_start_file($buffer,$j="",$k="") {
$buffer="";
return $buffer; return $buffer;
} }
function outlook_end_file($buffer) { function import_end_file($buffer) {
return $buffer; return $buffer;
} }
function outlook_start_record($buffer) { function import_start_record($buffer) {
$top=""; $top="";
$this->currentrecord = $top; $this->currentrecord = $top;
return $buffer; return $buffer;
} }
function outlook_end_record($buffer,$private="private") { function import_end_record($buffer,$private="private") {
global $phpgw_info; global $phpgw_info;
$row=0; $row=0;
$i=0; $i=0;
@ -178,7 +181,7 @@ function outlook_end_record($buffer,$private="private") {
return $buffer.$namelist.$valulist; return $buffer.$namelist.$valulist;
} }
function outlook_new_attrib($buffer,$name,$value) { function import_new_attrib($buffer,$name,$value) {
$value = str_replace("\n","<BR>",$value); $value = str_replace("\n","<BR>",$value);
$value = str_replace("\r","",$value); $value = str_replace("\r","",$value);
if ($value=="") { $value="NULL"; } if ($value=="") { $value="NULL"; }

View File

@ -1,7 +1,7 @@
<?php <?php
// This file defines a set of functions and an associative array. // This file defines a set of functions and an associative array.
// The key of the array corresponds to a header in the source // The key of the array corresponds to a header in the source
// outlook file and the value of the array item will be used in // import file and the value of the array item will be used in
// the creation of the output file. // the creation of the output file.
// //
// An exported Outlook file looks like this: // An exported Outlook file looks like this:
@ -23,10 +23,11 @@
// Also start with a '#' symbol and a comma separated list will be // Also start with a '#' symbol and a comma separated list will be
// turned into a number of the same entries. // turned into a number of the same entries.
class outlook_conv { class import_conv
var $currentrecord; //used for buffering to allow uid lines to go first {
var $currentrecord = array(); //used for buffering to allow uid lines to go first
var $outlook = array( var $import = array(
"Title" => "title", "Title" => "title",
"First Name" => "n_given", "First Name" => "n_given",
"Middle Name" => "n_middle", "Middle Name" => "n_middle",
@ -110,54 +111,49 @@ class outlook_conv {
"User 2" => "", "User 2" => "",
"User 3" => "", "User 3" => "",
"User 4" => "", "User 4" => "",
"Web Page" => ""); "Web Page" => ""
);
function outlook_start_file($buffer,$j="",$k="") { function import_start_file($buffer,$j="",$k="") {
return $buffer; return $buffer;
} }
function outlook_end_file($buffer) { function import_end_file($buffer) {
global $phpgw,$phpgw_info; global $phpgw,$phpgw_info;
$lines = split("\n",$buffer); //$contacts = CreateObject("phpgwapi.contacts");
$contacts = CreateObject("phpgwapi.contacts"); echo '<br>';
while ( list($name,$value) = each($buffer) ) {
for ($i=0;$i<count($lines);$i++) { echo '<br>'.$name.' => '.$value;
$entry=$lines[$i]; $i++;
$contacts->add($phpgw_info["user"]["account_id"],$entry); //$contacts->add($phpgw_info["user"]["account_id"],$entry);
} }
return "Successfully imported $i records into your addressbook."; return "Successfully imported $i records into your addressbook.";
} }
function outlook_start_record($buffer) { function import_start_record($buffer) {
$top=""; $top=array();
$this->currentrecord = $top; $this->currentrecord = $top;
return $buffer; return $buffer;
} }
function outlook_end_record($buffer,$private="private") { function import_end_record($buffer,$private="private") {
global $phpgw_info; global $phpgw_info;
$row=0; $namelist=array();
$i=0; while ( list($name, $value) = each($this->currentrecord)) {
$lines = split("##",$this->currentrecord); $namelist = $namelist + array($name => $value);
echo '<br>'.$name.' => '.$value;
for ($i=0;$i<count($lines)-1;$i++) { }
list($name, $value) = split("%%",$lines[$i]); echo '<br>';
$row++; $buffer = $buffer + $namelist;
$namelist .= array($name => $value); return $buffer;
echo $name.' '.$value;
} }
return $buffer.$namelist; function import_new_attrib($buffer,$name,$value) {
}
function outlook_new_attrib($buffer,$name,$value) {
$value = str_replace("\n","<BR>",$value); $value = str_replace("\n","<BR>",$value);
$value = str_replace("\r","",$value); $value = str_replace("\r","",$value);
if ($value=="") { $value="NULL"; } $this->currentrecord += array($name => $value);
$this->currentrecord .= $name."%%".addslashes($value)."##";
return $buffer; return $buffer;
} }