mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-22 23:00:56 +01:00
Initial check-in of export utility - not functional yet
This commit is contained in:
parent
e87d1171cc
commit
7a4db59d28
112
addressbook/export.php
Normal file
112
addressbook/export.php
Normal file
@ -0,0 +1,112 @@
|
||||
<?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_contacts_class"] = True;
|
||||
include("../header.inc.php");
|
||||
|
||||
$sep = SEP;
|
||||
|
||||
if (!$convert) {
|
||||
$t = new Template($phpgw_info["server"]["app_tpl"]);
|
||||
$t->set_file(array("export" => "export.tpl"));
|
||||
|
||||
$dir_handle=opendir($phpgw_info["server"]["app_root"].$sep."export");
|
||||
$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."export".$sep.$file) ) {
|
||||
$myfilearray[$i] = $file;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
closedir($dir_handle);
|
||||
sort($myfilearray);
|
||||
for ($i=0;$i<count($myfilearray);$i++) {
|
||||
$fname = ereg_replace('_',' ',$myfilearray[$i]);
|
||||
$conv .= '<OPTION VALUE="'.$myfilearray[$i].'">'.$fname.'</OPTION>';
|
||||
}
|
||||
|
||||
$t->set_var("lang_cancel",lang("Cancel"));
|
||||
$t->set_var("cancel_url",$phpgw->link("/addressbook/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("export_text",lang("Export from Addressbook to CSV or LDIF"));
|
||||
$t->set_var("action_url",$phpgw->link("/addressbook/export.php"));
|
||||
$t->set_var("filename",lang("Export file name"));
|
||||
$t->set_var("conv",$conv);
|
||||
$t->set_var("debug",lang(""));
|
||||
$t->set_var("download",lang("Submit"));
|
||||
|
||||
$t->pparse("out","export");
|
||||
|
||||
$phpgw->common->phpgw_footer();
|
||||
} else {
|
||||
include ($phpgw_info["server"]["app_root"].$sep."export".$sep.$conv_type);
|
||||
$buffer=array();
|
||||
$this = new export_conv;
|
||||
|
||||
// Read in user custom fields, if any
|
||||
$phpgw->preferences->read_repository();
|
||||
$customfields = array();
|
||||
while (list($col,$descr) = each($phpgw_info["user"]["preferences"]["addressbook"])) {
|
||||
if ( substr($col,0,6) == 'extra_' ) {
|
||||
$field = ereg_replace('extra_','',$col);
|
||||
$field = ereg_replace(' ','_',$field);
|
||||
$customfields[$field] = ucfirst($field);
|
||||
}
|
||||
}
|
||||
$extrafields = array(
|
||||
"ophone" => "ophone",
|
||||
"address2" => "address2",
|
||||
"address3" => "address3"
|
||||
);
|
||||
$this->qfields = $this->stock_contact_fields;# + $extrafields;# + $customfields;
|
||||
|
||||
$buffer = $this->export_start_file($buffer);
|
||||
|
||||
for ($i=0;$i<count($this->ids);$i++) {
|
||||
$this->id = $this->ids[$i];
|
||||
$buffer = $this->export_start_record($buffer);
|
||||
while( list($name,$value) = each($this->currentrecord) ) {
|
||||
$buffer = $this->export_new_attrib($buffer,$name,$value);
|
||||
}
|
||||
$buffer = $this->export_end_record($buffer);
|
||||
}
|
||||
|
||||
$buffer = $this->export_end_file($buffer);
|
||||
|
||||
$tsvfilename = $phpgw_info['server']['temp_dir'].$sep.$tsvfilename;
|
||||
|
||||
if ($download == "Submit") {
|
||||
header("Content-disposition: attachment; filename=\"".$tsvfilename."\"");
|
||||
header("Content-type: application/octetstream");
|
||||
header("Pragma: no-cache");
|
||||
header("Expires: 0");
|
||||
// while(list($name,$value) = each($buffer)) {
|
||||
//echo $name.': '.$value."\n";
|
||||
// }
|
||||
} else {
|
||||
echo "<pre>\n";
|
||||
$i=0;
|
||||
while(list($name,$value) = each($buffer[$i])) {
|
||||
echo $i.' - '.$name.': '.$value."\n";
|
||||
$i++;
|
||||
}
|
||||
echo "\n</pre>\n";
|
||||
echo '<a href="'.$phpgw->link("/addressbook/index.php").'">'.lang("OK").'</a>';
|
||||
$phpgw->common->phpgw_footer();
|
||||
}
|
||||
}
|
||||
?>
|
114
addressbook/export/Export_to_CSV
Normal file
114
addressbook/export/Export_to_CSV
Normal file
@ -0,0 +1,114 @@
|
||||
<?php
|
||||
// This file defines a set of functions and an associative array.
|
||||
// The key of the array corresponds to a header in the source
|
||||
// export 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 export_conv
|
||||
{
|
||||
var $currentrecord = array(); //used for buffering to allow uid lines to go first
|
||||
var $id;
|
||||
var $type = 'csv';
|
||||
|
||||
var $export = array(
|
||||
"title" => "Title",
|
||||
"n_given" => "First Name",
|
||||
"n_middle" => "Middle Name",
|
||||
"n_family" => "Last Name",
|
||||
"n_suffix" => "Suffix",
|
||||
"org_name" => "Company",
|
||||
"org_unit" => "Department",
|
||||
"adr_one_street" => "Business Street",
|
||||
"address2" => "Business Street 2",
|
||||
"address3" => "Business Street 3",
|
||||
"adr_one_locality" => "Business City",
|
||||
"adr_one_region" => "Business State",
|
||||
"adr_one_postalcode" => "Business Postal Code",
|
||||
"adr_one_countryname" => "Business Country",
|
||||
"adr_two_street" => "Home Street",
|
||||
"adr_two_locality" => "Home City",
|
||||
"adr_two_region" => "Home State",
|
||||
"adr_two_postalcode" => "Home Postal Code",
|
||||
"adr_two_countryname" => "Home Country",
|
||||
"tel_fax" => "Business Fax",
|
||||
"tel_work" => "Business Phone",
|
||||
"tel_msg" => "Assistant's Phone",
|
||||
"tel_car" => "Car Phone",
|
||||
"tel_isdn" => "ISDN",
|
||||
"tel_home" => "Home Phone",
|
||||
"tel_cell" => "Mobile Phone",
|
||||
"tel_pager" => "Pager",
|
||||
"ophone" => "Business Phone 2",
|
||||
"bday" => "Birthday",
|
||||
"email" => "E-mail Address",
|
||||
"email_home" => "E-mail Address 2",
|
||||
"url" => "Web Page",
|
||||
"note" => "Notes"
|
||||
);
|
||||
|
||||
function export_start_file($buffer,$j="",$k="") {
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
function export_end_file($buffer) {
|
||||
global $phpgw,$phpgw_info;
|
||||
|
||||
$contacts = CreateObject("phpgwapi.contacts");
|
||||
echo '<br>';
|
||||
for ($i=1;$i<=count($buffer);$i++) {
|
||||
while ( list($name,$value) = @each($buffer[$i]) ) {
|
||||
//echo '<br>'.$i.': '.$name.' => '.$value;
|
||||
$entry[$i][$name] = $value;
|
||||
}
|
||||
//echo '<br>';
|
||||
$contacts->add($phpgw_info["user"]["account_id"],$entry[$i]);
|
||||
}
|
||||
$num = $i - 1;
|
||||
return "Successfully exported $num records from your addressbook.";
|
||||
}
|
||||
|
||||
function export_start_record($buffer) {
|
||||
$top=array();
|
||||
++$this->id;
|
||||
$this->currentrecord = $top;
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
function export_end_record($buffer,$private="private") {
|
||||
global $phpgw_info;
|
||||
$buffer[$this->id]="";
|
||||
while ( list($name, $value) = each($this->currentrecord)) {
|
||||
$buffer[$this->id][$name] = $value;
|
||||
//echo '<br>'.$name.' => '.$value;
|
||||
}
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
function export_new_attrib($buffer,$name,$value) {
|
||||
$value = str_replace("\n","<BR>",$value);
|
||||
$value = str_replace("\r","",$value);
|
||||
$this->currentrecord += array($name => $value);
|
||||
|
||||
return $buffer;
|
||||
}
|
||||
}
|
||||
?>
|
95
addressbook/export/Export_to_LDIF
Normal file
95
addressbook/export/Export_to_LDIF
Normal file
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
// This file defines a set of functions and an associative array.
|
||||
// The key of the array corresponds to a header in the source
|
||||
// export file and the value of the array item will be used in
|
||||
// the creation of the output file.
|
||||
//
|
||||
// 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 export_conv
|
||||
{
|
||||
var $currentrecord = array(); //used for buffering to allow uid lines to go first
|
||||
var $id;
|
||||
//list of all id's
|
||||
var $ids = array();
|
||||
|
||||
var $export= array(
|
||||
"title" => "title",
|
||||
"n_given" => "givenname",
|
||||
"n_family" => "sn",
|
||||
"fn" => "cn",
|
||||
"org_name" => "o",
|
||||
"org_unit" => "ou",
|
||||
"adr_one_street" => "streetaddress",
|
||||
"adr_one_locality" => "locality",
|
||||
"adr_one_state" => "st",
|
||||
"adr_one_postalcode" => "postalcode",
|
||||
"adr_one_countryname" => "countryname",
|
||||
"tel_work" => "telephonenumber",
|
||||
"tel_home" => "homephone",
|
||||
"tel_fax" => "facsimiletelephonenumber",
|
||||
"ophone" => "xmozillaanyphone",
|
||||
"tel_cell" => "cellphone",
|
||||
"note" => "description",
|
||||
"tel_pager" => "pagerphone",
|
||||
"email" => "mail",
|
||||
"url" => "homeurl",
|
||||
);
|
||||
|
||||
// This will store the contacts object
|
||||
var $contacts = '';
|
||||
|
||||
// Read full list of user's contacts only to get id's for each
|
||||
function export_start_file($buffer) {
|
||||
$this->contacts = CreateObject('phpgwapi.contacts');
|
||||
$tmp = $this->contacts->read(0,'');
|
||||
for ($i=0;$i<count($tmp);$i++) {
|
||||
$this->ids[$i] = $tmp[$i]['id'];
|
||||
}
|
||||
// $ids is now an array of all id's for this user, e.g. $ids[0] = 21, etc...
|
||||
// $buffer is still empty
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
// Read each entry
|
||||
function export_start_record($buffer) {
|
||||
$top = $this->contacts->read_single_entry($this->id,$this->qfields);
|
||||
$this->currentrecord = $top[0];
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
// Read each attribute, populate buffer
|
||||
// name/value are the fields from the export array above
|
||||
function export_new_attrib($buffer,$name,$value) {
|
||||
if ($this->export[$name]) {
|
||||
$buffer[$this->id][$this->export[$name]] = $value;
|
||||
//echo '<br>'.$this->id.' - '.$this->export[$name].': '.$buffer[$this->id][$this->export[$name]];
|
||||
}
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
// Tack on some extra values
|
||||
function export_end_record($buffer) {
|
||||
$buffer[$this->id]["dn"] = 'dn: cn='.$buffer[$this->id]["cn"].',mail='.$buffer[$this->id]["mail"];
|
||||
$buffer[$this->id]["xmozillauseconferenceserver"] = "";
|
||||
$buffer[$this->id]["xmozillanickname"] = "";
|
||||
$buffer[$this->id]["xmozillausehtmlmail"] = "";
|
||||
$buffer[$this->id]["objectClass"] = "person";
|
||||
//echo '<br>'.$this->id.' - '.$buffer[$this->id]['dn'];
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
function export_end_file($buffer) {
|
||||
return $buffer;
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Reference in New Issue
Block a user