From ba0a1b2e8ccdb660fcf80519fd68ff15ef5a93d2 Mon Sep 17 00:00:00 2001 From: Miles Lott Date: Sun, 14 Jan 2001 21:35:04 +0000 Subject: [PATCH] Add import features from cdb, including templifying those files. --- addressbook/add.php | 2 +- addressbook/conv/Debug LDAP | 252 +++++++++++++++++ addressbook/conv/Debug MySQL | 190 +++++++++++++ .../conv/Import to Addressbook (MySQL) | 200 ++++++++++++++ addressbook/conv/Import to LDAP | 253 ++++++++++++++++++ addressbook/import.php | 116 ++++++++ addressbook/index.php | 2 + addressbook/templates/default/add.tpl | 14 +- addressbook/templates/default/footer.tpl | 17 +- addressbook/templates/default/import.tpl | 49 ++++ addressbook/templates/default/list.tpl | 1 + addressbook/templates/justweb/add.tpl | 14 +- addressbook/templates/justweb/footer.tpl | 17 +- addressbook/templates/justweb/import.tpl | 49 ++++ addressbook/templates/justweb/list.tpl | 1 + addressbook/templates/verdilak/add.tpl | 14 +- addressbook/templates/verdilak/footer.tpl | 17 +- addressbook/templates/verdilak/list.tpl | 1 + 18 files changed, 1187 insertions(+), 22 deletions(-) create mode 100644 addressbook/conv/Debug LDAP create mode 100644 addressbook/conv/Debug MySQL create mode 100644 addressbook/conv/Import to Addressbook (MySQL) create mode 100644 addressbook/conv/Import to LDAP create mode 100644 addressbook/import.php create mode 100644 addressbook/templates/default/import.tpl create mode 100644 addressbook/templates/justweb/import.tpl diff --git a/addressbook/add.php b/addressbook/add.php index 06bd761dca..4c564e7761 100755 --- a/addressbook/add.php +++ b/addressbook/add.php @@ -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",''); + $t->set_var("cancel_url",$phpgw->link("index.php")); $t->parse("out","add"); $t->pparse("out","add"); diff --git a/addressbook/conv/Debug LDAP b/addressbook/conv/Debug LDAP new file mode 100644 index 0000000000..87e2be0296 --- /dev/null +++ b/addressbook/conv/Debug LDAP @@ -0,0 +1,252 @@ +First NameMiddle NameLast Name... +// PatrickWalsh... +// +// 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;$ibasedn= $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; + } +} +} +?> diff --git a/addressbook/conv/Debug MySQL b/addressbook/conv/Debug MySQL new file mode 100644 index 0000000000..d45a4e0c8e --- /dev/null +++ b/addressbook/conv/Debug MySQL @@ -0,0 +1,190 @@ +First NameMiddle NameLast Name... +// PatrickWalsh... +// +// 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;$i2) { + $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","
",$value); + $value = str_replace("\r","",$value); + if ($value=="") { $value="NULL"; } + $this->currentrecord .= $name."%%".$value."##"; + + return $buffer; +} +} +?> diff --git a/addressbook/conv/Import to Addressbook (MySQL) b/addressbook/conv/Import to Addressbook (MySQL) new file mode 100644 index 0000000000..70a45971c9 --- /dev/null +++ b/addressbook/conv/Import to Addressbook (MySQL) @@ -0,0 +1,200 @@ +First NameMiddle NameLast Name... +// PatrickWalsh... +// +// 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;$idb->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;$i2) { + $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","
",$value); + $value = str_replace("\r","",$value); + if ($value=="") { $value="NULL"; } + $this->currentrecord .= $name."%%".addslashes($value)."##"; + + return $buffer; +} +} +?> diff --git a/addressbook/conv/Import to LDAP b/addressbook/conv/Import to LDAP new file mode 100644 index 0000000000..b4dcfbf798 --- /dev/null +++ b/addressbook/conv/Import to LDAP @@ -0,0 +1,253 @@ +First NameMiddle NameLast Name... +// PatrickWalsh... +// +// 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;$ibasedn= $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; + } +} +} +?> diff --git a/addressbook/import.php b/addressbook/import.php new file mode 100644 index 0000000000..d98ce58e8a --- /dev/null +++ b/addressbook/import.php @@ -0,0 +1,116 @@ + * + * -------------------------------------------- * + * 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;$iset_file(array("import" => "import.tpl")); + + $dir_handle=opendir($phpgw_info["server"]["app_root"].$sep."conv"); + $i=0; $myfilearray=""; + while ($file = readdir($dir_handle)) { + #echo ""; + 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'.$myfilearray[$i].''; + } + + $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 "
$buffer
"; + echo '
'.lang("OK").''; + $phpgw->common->phpgw_footer(); + } + } else { + echo "
$buffer
"; + echo ''.lang("OK").''; + $phpgw->common->phpgw_footer(); + } + } +?> diff --git a/addressbook/index.php b/addressbook/index.php index 844f2b1d0c..1ba3a2da78 100755 --- a/addressbook/index.php +++ b/addressbook/index.php @@ -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")); diff --git a/addressbook/templates/default/add.tpl b/addressbook/templates/default/add.tpl index df7e0ebc15..ba0448e531 100644 --- a/addressbook/templates/default/add.tpl +++ b/addressbook/templates/default/add.tpl @@ -13,15 +13,21 @@ - - {cancel_link} - + + + +
+ +
+ +   +   + - diff --git a/addressbook/templates/default/footer.tpl b/addressbook/templates/default/footer.tpl index 0a4f8014ce..f70240d967 100644 --- a/addressbook/templates/default/footer.tpl +++ b/addressbook/templates/default/footer.tpl @@ -5,19 +5,30 @@ + + + + + +
-
+
-
+
   
+
+
+ +
+
+
  
- diff --git a/addressbook/templates/default/import.tpl b/addressbook/templates/default/import.tpl new file mode 100644 index 0000000000..fc42b5b35e --- /dev/null +++ b/addressbook/templates/default/import.tpl @@ -0,0 +1,49 @@ + + +
+ + + + + + + + + + + + +
{import_text}
+
+ + + + +
+
    +
  1. In Outlook, select your Contacts folder, select Import + and Export... from the File + menu and export your contacts into a comma separated text file.

  2. +
  3. Enter the path to the exported file here: +

  4. +
  5. Select the type of conversion (Import types will perform an actual import. Debug will display output in browser or via a download.):
    +

  6. +
  7. Debug output in browser (Uncheck to download output.)
  8. +
  9. Mark records as private (Addressbook)
  10. +
  11. Use this basedn (LDAP)
  12. +
  13. Use this context for storing Contacts (LDAP)
  14. +
  15. +
+
+
+
+
+ +
+
+
  
+
+ diff --git a/addressbook/templates/default/list.tpl b/addressbook/templates/default/list.tpl index b524fb2729..08a2e97152 100644 --- a/addressbook/templates/default/list.tpl +++ b/addressbook/templates/default/list.tpl @@ -1,3 +1,4 @@ + {rows} diff --git a/addressbook/templates/justweb/add.tpl b/addressbook/templates/justweb/add.tpl index df7e0ebc15..ba0448e531 100644 --- a/addressbook/templates/justweb/add.tpl +++ b/addressbook/templates/justweb/add.tpl @@ -13,15 +13,21 @@ - - {cancel_link} - + + + +
+ +
+ +   +   + - diff --git a/addressbook/templates/justweb/footer.tpl b/addressbook/templates/justweb/footer.tpl index 0a4f8014ce..f70240d967 100644 --- a/addressbook/templates/justweb/footer.tpl +++ b/addressbook/templates/justweb/footer.tpl @@ -5,19 +5,30 @@ + + + + + +
-
+
-
+
   
+
+
+ +
+
+
  
- diff --git a/addressbook/templates/justweb/import.tpl b/addressbook/templates/justweb/import.tpl new file mode 100644 index 0000000000..fc42b5b35e --- /dev/null +++ b/addressbook/templates/justweb/import.tpl @@ -0,0 +1,49 @@ + + +
+ + + + + + + + + + + + +
{import_text}
+
+ + + + +
+
    +
  1. In Outlook, select your Contacts folder, select Import + and Export... from the File + menu and export your contacts into a comma separated text file.

  2. +
  3. Enter the path to the exported file here: +

  4. +
  5. Select the type of conversion (Import types will perform an actual import. Debug will display output in browser or via a download.):
    +

  6. +
  7. Debug output in browser (Uncheck to download output.)
  8. +
  9. Mark records as private (Addressbook)
  10. +
  11. Use this basedn (LDAP)
  12. +
  13. Use this context for storing Contacts (LDAP)
  14. +
  15. +
+
+
+
+
+ +
+
+
  
+
+ diff --git a/addressbook/templates/justweb/list.tpl b/addressbook/templates/justweb/list.tpl index b524fb2729..08a2e97152 100644 --- a/addressbook/templates/justweb/list.tpl +++ b/addressbook/templates/justweb/list.tpl @@ -1,3 +1,4 @@ + {rows} diff --git a/addressbook/templates/verdilak/add.tpl b/addressbook/templates/verdilak/add.tpl index df7e0ebc15..ba0448e531 100644 --- a/addressbook/templates/verdilak/add.tpl +++ b/addressbook/templates/verdilak/add.tpl @@ -13,15 +13,21 @@ - - {cancel_link} - + + + +
+ +
+ +   +   + - diff --git a/addressbook/templates/verdilak/footer.tpl b/addressbook/templates/verdilak/footer.tpl index 0a4f8014ce..f70240d967 100644 --- a/addressbook/templates/verdilak/footer.tpl +++ b/addressbook/templates/verdilak/footer.tpl @@ -5,19 +5,30 @@ + + + + + +
-
+
-
+
   
+
+
+ +
+
+
  
- diff --git a/addressbook/templates/verdilak/list.tpl b/addressbook/templates/verdilak/list.tpl index b524fb2729..08a2e97152 100644 --- a/addressbook/templates/verdilak/list.tpl +++ b/addressbook/templates/verdilak/list.tpl @@ -1,3 +1,4 @@ + {rows}