Add some additional Debug files for Netscape import

This commit is contained in:
Miles Lott 2001-03-11 17:51:37 +00:00
parent 6a1525653b
commit 654b4488f2
2 changed files with 331 additions and 0 deletions

View File

@ -0,0 +1,196 @@
<?php
// This file defines a set of functions and an associative array.
// The key of the array corresponds to a header in the source
// import file and the value of the array item will be used in
// the creation of the output file.
//
// An exported Outlook file looks like this:
//
// Title<tab>First Name<tab>Middle Name<tab>Last Name<tab>...
// <tab>Patrick<tab><tab>Walsh<tab>...
//
// Where the first line explains each optional field. This is what
// will be looked up in the key.
//
// The array need not be in any order and any fields not defined will
// not be transferred. If the val='+', the value will be appended to
// the previous field and any text after the '+' will be appended
// before the value. For example, the following would add a comma and
// a space between LastName and FirstName and store it in FullName:
//
// array("LastName" => "FullName","FirstName" => "+, ");
//
// Also start with a '#' symbol and a comma separated list will be
// turned into a number of the same entries.
class import_conv
{
var $basedn;
var $contactsdn;
var $sn; //these two vars will be used in
var $o; //building a dn field.
var $givenName; //this is used in building a cn field
var $currentrecord; //used for buffering to allow uid lines to go first
var $type = 'ldif';
var $import = array(
"title" => "title",
"givenname" => "givenname",
"sn" => "sn",
"cn" => "cn",
"o" => "o",
"ou" => "ou",
"streetaddress" => "streetaddress",
"locality" => "locality",
"st" => "st",
"postalcode" => "postalcode",
"countryname" => "countryname",
"telephonenumber" => "telephonenumber",
"homephone" => "homephone",
"facsimiletelephonenumber" => "facsimiletelephonenumber",
"xmozillaanyphone" => "xmozillaanyphone",
"cellphone" => "cellphone",
"description" => "description",
"pagerphone" => "pagerphone",
"mail" => "mail",
"homeurl" => "homeurl",
"xmozillauseconferenceserver" => "xmozillauseconferenceserver",
"xmozillanickname" => "xmozillanickname",
"xmozillausehtmlmail" => "xmozillausehtmlmail",
"modifytimestamp" => "modifytimestamp",
"objectclass" => "objectclass"
);
function import_start_file($buffer,$basedn="",$context="") {
# Here are some tests for correct basedn and Contacts context.
# If none of these are correct, ldap_add will fail, but at least
# we can give them a fighting chance.
if (!empty($basedn) && empty($context)) {
# Oops, no context, try a default
$context = "ou=Contacts,".$basedn;
} elseif (empty($basedn) && !empty($context)) {
# Oops, no basedn, try this one
$work = split(",",$context);
array_shift($work);
for ($i=0;$i<count($work);$i++) {
if($i==0) {
$basedn = $work[$i];
} else {
$basedn = $basedn.$work[$i];
}
}
} elseif(empty($basedn) && empty($context)) {
# Wow, create both from known info
$work = split(",",$phpgw_info["server"]["ldap_context"]);
array_shift($work);
for ($i=0;$i<count($work);$i++) {
if($i==0) {
$basedn = $work[$i];
} else {
$basedn = $basedn.",".$work[$i];
}
}
$context = "ou=Contacts,".$basedn;
}
$this->basedn= $basedn;
$this->contactsdn= $context;
$buffer="";
return $buffer;
}
function import_end_file($buffer) {
return $buffer;
}
function import_start_record($buffer) {
global $phpgw_info;
$top="\nobjectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
objectClass: importPerson";
$this->o="";
$this->sn="";
$this->givenName="";
$this->currentrecord = $top;
return $buffer;
}
function import_end_record($buffer,$private="") {
if (trim($this->sn) != "") {
$this->currentrecord = "cn: ".$this->givenName." ".$this->sn.$this->currentrecord;
} else if (trim($this->o) != "") {
$this->currentrecord = "cn: ".$this->o.$this->currentrecord;
} else if (trim($this->givenName)) {
$this->currentrecord = "cn: ".$this->givenName.$this->currentrecord;
} else {
$this->currentrecord = "cn: (unnamed)".$this->currentrecord;
}
$time = gettimeofday();
$uid = ($this->sn?$this->sn:$this->o);
if (strpos($uid, ",")) {
$uid = str_replace(",", "\,", $uid);
$uid = "\"".$uid."\"";
}
$uid = time().$time["usec"].":".$uid;
$this->currentrecord = "dn: uid=$uid,".$this->contactsdn."\nuid: $uid"."\n".$this->currentrecord;
while ($pos = strpos($this->currentrecord, "|br x=y/|")) {
$startline = strrpos(substr($this->currentrecord,0,$pos), "\n");
if ($startline == "") {$startline = 0;}
$startattrib = strpos($this->currentrecord, ":", $startline) + 1;
$endline = strpos($this->currentrecord, "\n", $startattrib);
if ($endline == "") { $endline = strlen($this->currentrecord); }
$attrib = str_replace("|br x=y/|", "\r\n", substr($this->currentrecord, $startattrib + 1, $endline - $startattrib - 1));
$this->currentrecord = substr($this->currentrecord, 0, $startattrib).": ".base64_encode($attrib).substr($this->currentrecord, $endline);
}
return $buffer.$this->currentrecord."\n\n";
}
function import_new_attrib($buffer,$name,$value) {
if ($name == "sn") {
$this->sn = $value;
}
if ($name == "o") {
$this->o = $value;
}
if ($name == "givenName") {
$this->givenName = $value;
}
$value = str_replace("\n","",$value);
$name = str_replace("\n","",$name);
$value = str_replace("\r","",$value);
$name = str_replace("\r","",$name);
switch (substr($name,0,1)) {
case '+':
$this->currentrecord .= substr($name,1).$value;
return $buffer;
break;
case '#':
$data = explode(";",$value);
$num = count($data);
$return = "";
for ( $i=0; $i<$num; $i++ ) {
$return .= "\n".substr($name,1).": $data[$i]";
}
$this->currentrecord .= $return;
return $buffer;
break;
default:
if ($name == "otherMailbox") {
$this->currentrecord .= "\n$name: smtp\$$value";
} else {
$this->currentrecord .= "\n$name: $value";
}
return $buffer;
} // end switch
}
}
?>

View File

@ -0,0 +1,135 @@
<?php
// This file defines a set of functions and an associative array.
// The key of the array corresponds to a header in the source
// import file and the value of the array item will be used in
// the creation of the output file.
//
// An exported Outlook file looks like this:
//
// Title<tab>First Name<tab>Middle Name<tab>Last Name<tab>...
// <tab>Patrick<tab><tab>Walsh<tab>...
//
// Where the first line explains each optional field. This is what
// will be looked up in the key.
//
// The array need not be in any order and any fields not defined will
// not be transferred. If the val='+', the value will be appended to
// the previous field and any text after the '+' will be appended
// before the value. For example, the following would add a comma and
// a space between LastName and FirstName and store it in FullName:
//
// array("LastName" => "FullName","FirstName" => "+, ");
//
// Also start with a '#' symbol and a comma separated list will be
// turned into a number of the same entries.
class import_conv
{
var $currentrecord; //used for buffering to allow uid lines to go first
var $type = 'ldif';
var $import = array(
"title" => "title",
"givenname" => "n_givenname",
"sn" => "n_family",
"cn" => "fn",
"o" => "org_name",
"ou" => "org_unit",
"streetaddress" => "adr_street",
"locality" => "adr_locality",
"st" => "adr_region",
"postalcode" => "adr_postalcode",
"countryname" => "adr_countryname",
"telephonenumber" => "a_tel",
"homephone" => "b_tel",
"facsimiletelephonenumber" => "c_tel",
"xmozillaanyphone" => "",
"cellphone" => "mphone",
"description" => "note",
"pagerphone" => "pager",
"mail" => "d_email",
"homeurl" => "url",
"xmozillauseconferenceserver" => "",
"xmozillanickname" => "",
"xmozillausehtmlmail" => "",
"modifytimestamp" => "",
"objectclass" => ""
);
function import_start_file($buffer,$j="",$k="") {
$buffer="";
return $buffer;
}
function import_end_file($buffer) {
return $buffer;
}
function import_start_record($buffer) {
$top="";
$this->currentrecord = $top;
return $buffer;
}
function import_end_record($buffer,$private="private") {
global $phpgw_info;
$row=0;
$i=0;
$lines = split("##",$this->currentrecord);
# Commence the ugly parsing of csv into sql
for ($i=0;$i<count($lines)-1;$i++) {
list($name, $value) = split("%%",$lines[$i]);
$row++;
if ($row==1) {
if (!empty($name) && !empty($value)) {
if (count($lines)>2) {
$thisname=$name.",";
$thisvalu="'".$value."',";
} else {
$thisname=$name.") ";
$thisvalu="'".$value."');";
}
} else {
$thisname="";
$thisvalu="";
}
$namelist = $namelist."\nINSERT INTO phpgw_addressbook (owner,".$thisname;
$valulist = $valulist."VALUES ('".$phpgw_info["user"]["account_id"]."',".$thisvalu;
} elseif ($row==count($lines)-1) {
if (!empty($name) && !empty($value)) {
$thisname=$name.") ";
$thisvalu="'".$value."');";
} else {
$thisname="";
$thisvalu="";
}
$namelist = $namelist.$thisname;
$valulist = $valulist.$thisvalu;
} else {
if (!empty($name) && !empty($value)) {
$thisname=$name.",";
$thisvalu="'".$value."',";
} else {
$thisname=",";
$thisvalu=",";
}
$namelist = $namelist.$thisname;
$valulist = $valulist.$thisvalu;
}
}
return $buffer.$namelist.$valulist;
}
function import_new_attrib($buffer,$name,$value) {
$value = str_replace("\n","",$value);
$value = str_replace("\r","",$value);
if ($value=="") { $value="NULL"; }
$this->currentrecord .= $name."%%".$value."##";
return $buffer;
}
}
?>