Add import features from cdb, including templifying those files.

This commit is contained in:
Miles Lott 2001-01-14 21:35:04 +00:00
parent 4fa4faabc3
commit ba0a1b2e8c
18 changed files with 1187 additions and 22 deletions

View File

@ -106,7 +106,7 @@
$t->set_var("lang_ok",lang("ok"));
$t->set_var("lang_clear",lang("clear"));
$t->set_var("lang_cancel",lang("cancel"));
$t->set_var("cancel_link",'<a href="'.$phpgw->link($phpgw_info["server"]["webserver_url"] . "/addressbook/") . '">');
$t->set_var("cancel_url",$phpgw->link("index.php"));
$t->parse("out","add");
$t->pparse("out","add");

252
addressbook/conv/Debug LDAP Normal file
View File

@ -0,0 +1,252 @@
<?php
// This file defines a set of functions and an associative array.
// 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
// 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 outlook_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 $outlook = array(
"Title" => "",
"First Name" => "givenName",
"Middle Name" => "",
"Last Name" => "sn",
"Suffix" => "",
"Company" => "o", //objectclass: organization
"Department" => "ou", //objectclass: organizationalPerson
"Job Title" => "title", //objectclass: organizationalPerson
"Business Street" => "postalAddress",
"Business Street 2" => "",
"Business Street 3" => "",
"Business City" => "l",
"Business State" => "st",
"Business Postal Code" => "postalCode",
"Business Country" => "co",
"Home Street" => "homePostalAddress",
"Home City" => "+\n",
"Home State" => "+, ",
"Home Postal Code" => "+ ",
"Home Country" => "+\n",
"Home Street 2" => "",
"Home Street 3" => "",
"Other Street" => "",
"Other City" => "+\n",
"Other State" => "+, ",
"Other Postal Code" => "+ ",
"Other Country" => "+\n",
"Assistant's Phone" => "",
"Business Fax" => "facsimileTelephoneNumber",
"Business Phone" => "telephoneNumber",
"Business Phone 2" => "",
"Callback" => "",
"Car Phone" => "",
"Company Main Phone" => "",
"Home Fax" => "",
"Home Phone" => "homePhone",
"Home Phone 2" => "homePhone", //This will make another homePhone entry
"ISDN" => "",
"Mobile Phone" => "mobile", //newPilotPerson
"Other Fax" => "",
"Other Phone" => "",
"Pager" => "pager",
"Primary Phone" => "",
"Radio Phone" => "",
"TTY/TDD Phone" => "",
"Telex" => "telexNumber", //organization
"Account" => "",
"Anniversary" => "",
"Assistant's Name" => "secretary", //newPilotPerson
"Billing Information" => "",
"Birthday" => "",
"Categories" => "#businessCategory",
"Children" => "",
"Directory Server" => "",
"E-mail Address" => "mail",
"E-mail Display Name" => "",
"E-mail 2 Address" => "otherMailbox",
"E-mail 2 Display Name" => "",
"E-mail 3 Address" => "otherMailbox", //add another...
"E-mail 3 Display Name" => "",
"Gender" => "",
"Government ID Number" => "",
"Hobby" => "",
"Initials" => "",
"Internet Free Busy" => "",
"Keywords" => "",
"Language" => "",
"Location" => "",
"Manager's Name" => "",
"Mileage" => "",
"Notes" => "comment",
"Office Location" => "physicalDeliveryOfficeName",
"Organizational ID Number" => "",
"PO Box" => "postOfficeBox",
"Priority" => "",
"Private Profession" => "",
"Referred By" => "",
"Sensitivity" => "",
"Spouse" => "",
"User 1" => "",
"User 2" => "",
"User 3" => "",
"User 4" => "",
"Web Page" => "");
function outlook_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;
return $buffer;
}
function outlook_end_file($buffer) {
return $buffer;
}
function outlook_start_record($buffer) {
global $phpgw_info;
$top="\nobjectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
objectClass: outlookPerson";
$this->o="";
$this->sn="";
$this->givenName="";
$this->currentrecord = $top;
return $buffer;
}
function outlook_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 outlook_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","|br x=y/|",$value);
$name = str_replace("\n","|br x=y/|",$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;
}
}
}
?>

View File

@ -0,0 +1,190 @@
<?php
// This file defines a set of functions and an associative array.
// 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
// 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 outlook_conv {
var $currentrecord; //used for buffering to allow uid lines to go first
var $outlook = array(
"Title" => "",
"First Name" => "ab_firstname",
"Middle Name" => "",
"Last Name" => "ab_lastname",
"Suffix" => "",
"Company" => "ab_company", //objectclass: organization
"Department" => "", //objectclass: organizationalPerson
"Job Title" => "ab_title", //objectclass: organizationalPerson
"Business Street" => "ab_address2",
"Business Street 2" => "",
"Business Street 3" => "",
"Business City" => "",
"Business State" => "",
"Business Postal Code" => "",
"Business Country" => "",
"Home Street" => "ab_street",
"Home City" => "ab_city",
"Home State" => "ab_state",
"Home Postal Code" => "ab_zip",
"Home Country" => "",
"Home Street 2" => "",
"Home Street 3" => "",
"Other Street" => "",
"Other City" => "",
"Other State" => "",
"Other Postal Code" => "",
"Other Country" => "",
"Assistant's Phone" => "",
"Business Fax" => "ab_fax",
"Business Phone" => "ab_wphone",
"Business Phone 2" => "ab_ophone",
"Callback" => "",
"Car Phone" => "",
"Company Main Phone" => "",
"Home Fax" => "",
"Home Phone" => "ab_hphone",
"Home Phone 2" => "", //This will make another homePhone entry
"ISDN" => "",
"Mobile Phone" => "ab_mphone", //newPilotPerson
"Other Fax" => "",
"Other Phone" => "",
"Pager" => "ab_pager",
"Primary Phone" => "",
"Radio Phone" => "",
"TTY/TDD Phone" => "",
"Telex" => "", //organization
"Account" => "",
"Anniversary" => "",
"Assistant's Name" => "", //newPilotPerson
"Billing Information" => "",
"Birthday" => "ab_bday",
"Categories" => "",
"Children" => "",
"Directory Server" => "",
"E-mail Address" => "ab_email",
"E-mail Display Name" => "",
"E-mail 2 Address" => "",
"E-mail 2 Display Name" => "",
"E-mail 3 Address" => "", //add another...
"E-mail 3 Display Name" => "",
"Gender" => "",
"Government ID Number" => "",
"Hobby" => "",
"Initials" => "",
"Internet Free Busy" => "",
"Keywords" => "",
"Language" => "",
"Location" => "",
"Manager's Name" => "",
"Mileage" => "",
"Notes" => "ab_notes",
"Office Location" => "",
"Organizational ID Number" => "",
"PO Box" => "postOfficeBox",
"Priority" => "",
"Private Profession" => "",
"Referred By" => "",
"Sensitivity" => "",
"Spouse" => "",
"User 1" => "",
"User 2" => "",
"User 3" => "",
"User 4" => "",
"Web Page" => "");
function outlook_start_file($buffer,$j="",$k="") {
return $buffer;
}
function outlook_end_file($buffer) {
return $buffer;
}
function outlook_start_record($buffer) {
$top="";
$this->currentrecord = $top;
return $buffer;
}
function outlook_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 addressbook (ab_owner,ab_access,".$thisname;
$valulist = $valulist."VALUES ('".$phpgw_info["user"]["account_id"]."','".$private."',".$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 outlook_new_attrib($buffer,$name,$value) {
$value = str_replace("\n","<BR>",$value);
$value = str_replace("\r","",$value);
if ($value=="") { $value="NULL"; }
$this->currentrecord .= $name."%%".$value."##";
return $buffer;
}
}
?>

View File

@ -0,0 +1,200 @@
<?php
// This file defines a set of functions and an associative array.
// 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
// 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 outlook_conv {
var $currentrecord; //used for buffering to allow uid lines to go first
var $outlook = array(
"Title" => "",
"First Name" => "ab_firstname",
"Middle Name" => "",
"Last Name" => "ab_lastname",
"Suffix" => "",
"Company" => "ab_company", //objectclass: organization
"Department" => "", //objectclass: organizationalPerson
"Job Title" => "ab_title", //objectclass: organizationalPerson
"Business Street" => "ab_address2",
"Business Street 2" => "",
"Business Street 3" => "",
"Business City" => "",
"Business State" => "",
"Business Postal Code" => "",
"Business Country" => "",
"Home Street" => "ab_street",
"Home City" => "ab_city",
"Home State" => "ab_state",
"Home Postal Code" => "ab_zip",
"Home Country" => "",
"Home Street 2" => "",
"Home Street 3" => "",
"Other Street" => "",
"Other City" => "",
"Other State" => "",
"Other Postal Code" => "",
"Other Country" => "",
"Assistant's Phone" => "",
"Business Fax" => "ab_fax",
"Business Phone" => "ab_wphone",
"Business Phone 2" => "ab_ophone",
"Callback" => "",
"Car Phone" => "",
"Company Main Phone" => "",
"Home Fax" => "",
"Home Phone" => "ab_hphone",
"Home Phone 2" => "", //This will make another homePhone entry
"ISDN" => "",
"Mobile Phone" => "ab_mphone", //newPilotPerson
"Other Fax" => "",
"Other Phone" => "",
"Pager" => "ab_pager",
"Primary Phone" => "",
"Radio Phone" => "",
"TTY/TDD Phone" => "",
"Telex" => "", //organization
"Account" => "",
"Anniversary" => "",
"Assistant's Name" => "", //newPilotPerson
"Billing Information" => "",
"Birthday" => "ab_bday",
"Categories" => "",
"Children" => "",
"Directory Server" => "",
"E-mail Address" => "ab_email",
"E-mail Display Name" => "",
"E-mail 2 Address" => "",
"E-mail 2 Display Name" => "",
"E-mail 3 Address" => "", //add another...
"E-mail 3 Display Name" => "",
"Gender" => "",
"Government ID Number" => "",
"Hobby" => "",
"Initials" => "",
"Internet Free Busy" => "",
"Keywords" => "",
"Language" => "",
"Location" => "",
"Manager's Name" => "",
"Mileage" => "",
"Notes" => "ab_notes",
"Office Location" => "",
"Organizational ID Number" => "",
"PO Box" => "postOfficeBox",
"Priority" => "",
"Private Profession" => "",
"Referred By" => "",
"Sensitivity" => "",
"Spouse" => "",
"User 1" => "",
"User 2" => "",
"User 3" => "",
"User 4" => "",
"Web Page" => "");
function outlook_start_file($buffer,$j="",$k="") {
return $buffer;
}
function outlook_end_file($buffer) {
global $phpgw;
global $phpgw_info;
$lines = split("\n",$buffer);
for ($i=0;$i<count($lines);$i++) {
$sql=$lines[$i];
$phpgw->db->query($sql);
}
return "Successfully imported $i records into your addressbook.";
}
function outlook_start_record($buffer) {
$top="";
$this->currentrecord = $top;
return $buffer;
}
function outlook_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 addressbook (ab_owner,ab_access,".$thisname;
$valulist = $valulist."VALUES ('".$phpgw_info["user"]["account_id"]."','".$private."',".$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 outlook_new_attrib($buffer,$name,$value) {
$value = str_replace("\n","<BR>",$value);
$value = str_replace("\r","",$value);
if ($value=="") { $value="NULL"; }
$this->currentrecord .= $name."%%".addslashes($value)."##";
return $buffer;
}
}
?>

View File

@ -0,0 +1,253 @@
<?php
// This file defines a set of functions and an associative array.
// 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
// 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 outlook_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 $outlook = array(
"Title" => "",
"First Name" => "givenName",
"Middle Name" => "",
"Last Name" => "sn",
"Suffix" => "",
"Company" => "o", //objectclass: organization
"Department" => "ou", //objectclass: organizationalPerson
"Job Title" => "title", //objectclass: organizationalPerson
"Business Street" => "postalAddress",
"Business Street 2" => "",
"Business Street 3" => "",
"Business City" => "l",
"Business State" => "st",
"Business Postal Code" => "postalCode",
"Business Country" => "co",
"Home Street" => "homePostalAddress",
"Home City" => "+\n",
"Home State" => "+, ",
"Home Postal Code" => "+ ",
"Home Country" => "+\n",
"Home Street 2" => "",
"Home Street 3" => "",
"Other Street" => "",
"Other City" => "+\n",
"Other State" => "+, ",
"Other Postal Code" => "+ ",
"Other Country" => "+\n",
"Assistant's Phone" => "",
"Business Fax" => "facsimileTelephoneNumber",
"Business Phone" => "telephoneNumber",
"Business Phone 2" => "",
"Callback" => "",
"Car Phone" => "",
"Company Main Phone" => "",
"Home Fax" => "",
"Home Phone" => "homePhone",
"Home Phone 2" => "homePhone", //This will make another homePhone entry
"ISDN" => "",
"Mobile Phone" => "mobile", //newPilotPerson
"Other Fax" => "",
"Other Phone" => "",
"Pager" => "pager",
"Primary Phone" => "",
"Radio Phone" => "",
"TTY/TDD Phone" => "",
"Telex" => "telexNumber", //organization
"Account" => "",
"Anniversary" => "",
"Assistant's Name" => "secretary", //newPilotPerson
"Billing Information" => "",
"Birthday" => "",
"Categories" => "#businessCategory",
"Children" => "",
"Directory Server" => "",
"E-mail Address" => "mail",
"E-mail Display Name" => "",
"E-mail 2 Address" => "otherMailbox",
"E-mail 2 Display Name" => "",
"E-mail 3 Address" => "otherMailbox", //add another...
"E-mail 3 Display Name" => "",
"Gender" => "",
"Government ID Number" => "",
"Hobby" => "",
"Initials" => "",
"Internet Free Busy" => "",
"Keywords" => "",
"Language" => "",
"Location" => "",
"Manager's Name" => "",
"Mileage" => "",
"Notes" => "comment",
"Office Location" => "physicalDeliveryOfficeName",
"Organizational ID Number" => "",
"PO Box" => "postOfficeBox",
"Priority" => "",
"Private Profession" => "",
"Referred By" => "",
"Sensitivity" => "",
"Spouse" => "",
"User 1" => "",
"User 2" => "",
"User 3" => "",
"User 4" => "",
"Web Page" => "");
function outlook_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;
return $buffer;
}
function outlook_end_file($buffer) {
$i="zarro";
return "Successfully imported $i records into LDAP.";
}
function outlook_start_record($buffer) {
global $phpgw_info;
$top="\nobjectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
objectClass: outlookPerson";
$this->o="";
$this->sn="";
$this->givenName="";
$this->currentrecord = $top;
return $buffer;
}
function outlook_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 outlook_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","|br x=y/|",$value);
$name = str_replace("\n","|br x=y/|",$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;
}
}
}
?>

116
addressbook/import.php Normal file
View File

@ -0,0 +1,116 @@
<?php
/**************************************************************************\
* phpGroupWare - addressbook *
* http://www.phpgroupware.org *
* Written by Joseph Engo <jengo@phpgroupware.org> *
* -------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU General Public License as published by the *
* Free Software Foundation; either version 2 of the License, or (at your *
* option) any later version. *
\**************************************************************************/
/* $Id$ */
$phpgw_info["flags"]["currentapp"] = "addressbook";
$phpgw_info["flags"]["enable_addressbook_class"] = True;
include("../header.inc.php");
$sep = $phpgw_info["server"]["dir_separator"];
# Construct a default basedn and context for Contacts if using LDAP
$tmpbasedn = split(",",$phpgw_info["server"]["ldap_context"]);
array_shift($tmpbasedn);
for ($i=0;$i<count($tmpbasedn);$i++) {
if($i==0) {
$fakebasedn = $tmpbasedn[$i];
} else {
$fakebasedn = $fakebasedn.",".$tmpbasedn[$i];
}
}
$fakecontext = "ou=Contacts,".$fakebasedn;
if (!$convert) {
$t = new Template($phpgw_info["server"]["app_tpl"]);
$t->set_file(array("import" => "import.tpl"));
$dir_handle=opendir($phpgw_info["server"]["app_root"].$sep."conv");
$i=0; $myfilearray="";
while ($file = readdir($dir_handle)) {
#echo "<!-- ".is_file($phpgw_info["server"]["app_root"].$sep."conv".$sep.$file)." -->";
if ((substr($file, 0, 1) != ".") && is_file($phpgw_info["server"]["app_root"].$sep."conv".$sep.$file) ) {
$myfilearray[$i] = $file;
$i++;
}
}
closedir($dir_handle);
sort($myfilearray);
for ($i=0;$i<count($myfilearray);$i++) {
$conv .= '<OPTION VALUE="'.$myfilearray[$i].'">'.$myfilearray[$i].'</OPTION>';
}
$t->set_var("lang_cancel",lang("Cancel"));
$t->set_var("cancel_url",$phpgw->link("index.php"));
$t->set_var("navbar_bg",$phpgw_info["theme"]["navbar_bg"]);
$t->set_var("navbar_text",$phpgw_info["theme"]["navbar_text"]);
$t->set_var("import_text",lang("Import from Outlook"));
$t->set_var("action_url",$phpgw->link("import.php"));
$t->set_var("tsvfilename","");
$t->set_var("conv",$conv);
$t->set_var("debug",lang("Debug output in browser"));
$t->set_var("fakebasedn",$fakebasedn);
$t->set_var("fakecontext",$fakecontext);
$t->set_var("download",lang("Submit"));
#$t->parse("out","import");
$t->pparse("out","import");
$phpgw->common->phpgw_footer();
} else {
include ($phpgw_info["server"]["app_root"].$sep."conv".$sep.$conv_type);
if ($private=="") { $private="public"; }
$row=0;
$buffer="";
$o = new outlook_conv;
$buffer = $o->outlook_start_file($buffer,$basedn,$context);
$fp=fopen($tsvfile,"r");
while ($data = fgetcsv($fp,8000,",")) {
$num = count($data);
$row++;
if ($row == 1) {
$header = $data;
} else {
$buffer = $o->outlook_start_record($buffer);
for ($c=0; $c<$num; $c++ ) {
//Send name/value pairs along with the buffer
if ($o->outlook[$header[$c]]!="" && $data[$c]!="") {
$buffer = $o->outlook_new_attrib($buffer, $o->outlook[$header[$c]],$data[$c]);
}
}
$buffer = $o->outlook_end_record($buffer,$private);
}
}
fclose($fp);
$buffer = $o->outlook_end_file($buffer);
if ($download == "") {
if($conv_type=="Debug LDAP" || $conv_type=="Debug SQL" ) {
header("Content-disposition: attachment; filename=\"conversion.txt\"");
header("Content-type: application/octetstream");
header("Pragma: no-cache");
header("Expires: 0");
echo $buffer;
} else {
echo "<pre>$buffer</pre>";
echo '<a href="'.$phpgw->link("index.php").'">'.lang("OK").'</a>';
$phpgw->common->phpgw_footer();
}
} else {
echo "<pre>$buffer</pre>";
echo '<a href="'.$phpgw->link("index.php").'">'.lang("OK").'</a>';
$phpgw->common->phpgw_footer();
}
}
?>

View File

@ -215,6 +215,8 @@
$t->set_var("th_text",$phpgw_info["theme"]["th_text"]);
$t->set_var("lang_add",lang("Add"));
$t->set_var("lang_addvcard",lang("AddVCard"));
$t->set_var("lang_import",lang("Import File"));
$t->set_var("import_url",$phpgw->link("import.php"));
$t->set_var("lang_view",lang("View"));
$t->set_var("lang_vcard",lang("VCard"));
$t->set_var("lang_edit",lang("Edit"));

View File

@ -13,15 +13,21 @@
<TD align="left">
<INPUT type="reset" name="reset" value="{lang_clear}">
</TD>
<TD align="left">
{cancel_link}<INPUT type="submit" name="cancel" value="{lang_cancel}"></a>
</TD>
</TR>
</FORM>
<tr>
<td width="8%">
<form action="{cancel_url}" method="post">
<input type="submit" name="Cancel" value="{lang_cancel}">
</form>
</td>
<td width="64%">&nbsp;</td>
<td width="32">&nbsp;</td>
</tr>
</TBODY>
</TABLE>
</TD>
</TR>
</TBODY>
</TABLE>
</FORM>
<!-- END add -->

View File

@ -5,19 +5,30 @@
<table width="75%" border="0" cellspacing="0" cellpadding="4">
<tr>
<td width="4%">
<div align="right">
<div align="left">
<input type="submit" name="Add" value="{lang_add}">
</div>
</td>
<td width="8%">
<div align="right">
<div align="left">
<input type="submit" name="AddVcard" value="{lang_addvcard}">
</div>
</td>
<td width="64%">&nbsp;</td>
<td width="24%">&nbsp;</td>
</tr>
</form>
<tr>
<td width="8%">
<div align="right">
<form action="{import_url}" method="post">
<input type="submit" name="Import" value="{lang_import}">
</form>
</div>
</td>
<td width="64%">&nbsp;</td>
<td width="32">&nbsp;</td>
</tr>
</table>
</form>
</center>
<!-- END addressbook_footer -->

View File

@ -0,0 +1,49 @@
<!-- BEGIN import -->
<CENTER>
<TABLE WIDTH=90%>
<TR BGCOLOR="{navbar_bg}">
<TD><B><FONT SIZE=+2 COLOR="{navbar_text}"><CENTER>{import_text}</CENTER></FONT></B>
</TD>
</TR>
<TR>
<TD>
<TABLE WIDTH=85%>
<TR>
<TD><FORM ENCTYPE="multipart/form-data" action="{action_url}" method="post">
<OL>
<LI>In Outlook, select your Contacts folder, select <b>Import
and Export...</b> from the <b>File</b>
menu and export your contacts into a comma separated text file.<P></LI>
<LI>Enter the path to the exported file here:
<INPUT NAME="tsvfile" SIZE=48 TYPE="file" VALUE="{tsvfilename}"><P></LI>
<LI>Select the type of conversion (Import types will perform an actual import. Debug will display output in browser or via a download.):<BR>
<SELECT NAME="conv_type">
<OPTION VALUE="none">&lt;none&gt;</OPTION>
{conv}
</SELECT><P></LI>
<LI><INPUT NAME="download" TYPE="checkbox" VALUE="{debug}" CHECKED>Debug output in browser (Uncheck to download output.)</LI>
<LI><INPUT NAME="private" TYPE="checkbox" VALUE="private" CHECKED>Mark records as private (Addressbook)</LI>
<LI>Use this basedn (LDAP)<BR><INPUT NAME="basedn" TYPE="text" VALUE="{fakebasedn}" SIZE="48"></LI>
<LI>Use this context for storing Contacts (LDAP)<BR><INPUT NAME="context" TYPE="text" VALUE="{fakecontext}" SIZE="48"></LI>
<LI><INPUT NAME="convert" TYPE="submit" VALUE="{download}"></LI>
</OL>
</FORM></TD>
</TR>
</TABLE>
</TD>
</TR>
<tr>
<td width="8%">
<div align="left">
<form action="{cancel_url}" method="post">
<input type="submit" name="Cancel" value="{lang_cancel}">
</form>
</div>
</td>
<td width="64%">&nbsp;</td>
<td width="32">&nbsp;</td>
</tr>
</TABLE>
</CENTER>
<!-- END import -->

View File

@ -1,3 +1,4 @@
<!-- BEGIN list -->
{rows}

View File

@ -13,15 +13,21 @@
<TD align="left">
<INPUT type="reset" name="reset" value="{lang_clear}">
</TD>
<TD align="left">
{cancel_link}<INPUT type="submit" name="cancel" value="{lang_cancel}"></a>
</TD>
</TR>
</FORM>
<tr>
<td width="8%">
<form action="{cancel_url}" method="post">
<input type="submit" name="Cancel" value="{lang_cancel}">
</form>
</td>
<td width="64%">&nbsp;</td>
<td width="32">&nbsp;</td>
</tr>
</TBODY>
</TABLE>
</TD>
</TR>
</TBODY>
</TABLE>
</FORM>
<!-- END add -->

View File

@ -5,19 +5,30 @@
<table width="75%" border="0" cellspacing="0" cellpadding="4">
<tr>
<td width="4%">
<div align="right">
<div align="left">
<input type="submit" name="Add" value="{lang_add}">
</div>
</td>
<td width="8%">
<div align="right">
<div align="left">
<input type="submit" name="AddVcard" value="{lang_addvcard}">
</div>
</td>
<td width="64%">&nbsp;</td>
<td width="24%">&nbsp;</td>
</tr>
</form>
<tr>
<td width="8%">
<div align="right">
<form action="{import_url}" method="post">
<input type="submit" name="Import" value="{lang_import}">
</form>
</div>
</td>
<td width="64%">&nbsp;</td>
<td width="32">&nbsp;</td>
</tr>
</table>
</form>
</center>
<!-- END addressbook_footer -->

View File

@ -0,0 +1,49 @@
<!-- BEGIN import -->
<CENTER>
<TABLE WIDTH=90%>
<TR BGCOLOR="{navbar_bg}">
<TD><B><FONT SIZE=+2 COLOR="{navbar_text}"><CENTER>{import_text}</CENTER></FONT></B>
</TD>
</TR>
<TR>
<TD>
<TABLE WIDTH=85%>
<TR>
<TD><FORM ENCTYPE="multipart/form-data" action="{action_url}" method="post">
<OL>
<LI>In Outlook, select your Contacts folder, select <b>Import
and Export...</b> from the <b>File</b>
menu and export your contacts into a comma separated text file.<P></LI>
<LI>Enter the path to the exported file here:
<INPUT NAME="tsvfile" SIZE=48 TYPE="file" VALUE="{tsvfilename}"><P></LI>
<LI>Select the type of conversion (Import types will perform an actual import. Debug will display output in browser or via a download.):<BR>
<SELECT NAME="conv_type">
<OPTION VALUE="none">&lt;none&gt;</OPTION>
{conv}
</SELECT><P></LI>
<LI><INPUT NAME="download" TYPE="checkbox" VALUE="{debug}" CHECKED>Debug output in browser (Uncheck to download output.)</LI>
<LI><INPUT NAME="private" TYPE="checkbox" VALUE="private" CHECKED>Mark records as private (Addressbook)</LI>
<LI>Use this basedn (LDAP)<BR><INPUT NAME="basedn" TYPE="text" VALUE="{fakebasedn}" SIZE="48"></LI>
<LI>Use this context for storing Contacts (LDAP)<BR><INPUT NAME="context" TYPE="text" VALUE="{fakecontext}" SIZE="48"></LI>
<LI><INPUT NAME="convert" TYPE="submit" VALUE="{download}"></LI>
</OL>
</FORM></TD>
</TR>
</TABLE>
</TD>
</TR>
<tr>
<td width="8%">
<div align="left">
<form action="{cancel_url}" method="post">
<input type="submit" name="Cancel" value="{lang_cancel}">
</form>
</div>
</td>
<td width="64%">&nbsp;</td>
<td width="32">&nbsp;</td>
</tr>
</TABLE>
</CENTER>
<!-- END import -->

View File

@ -1,3 +1,4 @@
<!-- BEGIN list -->
{rows}

View File

@ -13,15 +13,21 @@
<TD align="left">
<INPUT type="reset" name="reset" value="{lang_clear}">
</TD>
<TD align="left">
{cancel_link}<INPUT type="submit" name="cancel" value="{lang_cancel}"></a>
</TD>
</TR>
</FORM>
<tr>
<td width="8%">
<form action="{cancel_url}" method="post">
<input type="submit" name="Cancel" value="{lang_cancel}">
</form>
</td>
<td width="64%">&nbsp;</td>
<td width="32">&nbsp;</td>
</tr>
</TBODY>
</TABLE>
</TD>
</TR>
</TBODY>
</TABLE>
</FORM>
<!-- END add -->

View File

@ -5,19 +5,30 @@
<table width="75%" border="0" cellspacing="0" cellpadding="4">
<tr>
<td width="4%">
<div align="right">
<div align="left">
<input type="submit" name="Add" value="{lang_add}">
</div>
</td>
<td width="8%">
<div align="right">
<div align="left">
<input type="submit" name="AddVcard" value="{lang_addvcard}">
</div>
</td>
<td width="64%">&nbsp;</td>
<td width="24%">&nbsp;</td>
</tr>
</form>
<tr>
<td width="8%">
<div align="right">
<form action="{import_url}" method="post">
<input type="submit" name="Import" value="{lang_import}">
</form>
</div>
</td>
<td width="64%">&nbsp;</td>
<td width="32">&nbsp;</td>
</tr>
</table>
</form>
</center>
<!-- END addressbook_footer -->

View File

@ -1,3 +1,4 @@
<!-- BEGIN list -->
{rows}