Formatting

This commit is contained in:
Miles Lott 2001-05-21 07:31:00 +00:00
parent 551661182f
commit 061c819fed
6 changed files with 378 additions and 319 deletions

View File

@ -12,36 +12,41 @@
/* $Id$ */ /* $Id$ */
if ($download =='on') { if ($download == 'on')
$phpgw_info["flags"] = array( {
"noheader" => True, $phpgw_info['flags'] = array(
"nonavbar" => True 'noheader' => True,
'nonavbar' => True
); );
} else { }
$phpgw_info["flags"] = array( else
"noheader" => False, {
"nonavbar" => False $phpgw_info['flags'] = array(
'noheader' => False,
'nonavbar' => False
); );
} }
$phpgw_info["flags"]["currentapp"] = "addressbook"; $phpgw_info['flags'] = array(
$phpgw_info["flags"]["enable_contacts_class"] = True; 'currentapp' => 'addressbook',
$phpgw_info["flags"]["enable_browser_class"] = True; 'enable_contacts_class' => True,
include("../header.inc.php"); 'enable_browser_class' => True
);
include('../header.inc.php');
$sep = SEP; $sep = SEP;
if (!$convert) if (!$convert)
{ {
$t = new Template(PHPGW_APP_TPL); $t = new Template(PHPGW_APP_TPL);
$t->set_file(array("export" => "export.tpl")); $t->set_file(array('export' => 'export.tpl'));
$dir_handle=opendir($phpgw_info["server"]["app_root"].$sep."export"); $dir_handle=opendir($phpgw_info['server']['app_root'].$sep.'export');
$i=0; $myfilearray=""; $i=0; $myfilearray='';
while ($file = readdir($dir_handle)) while ($file = readdir($dir_handle))
{ {
#echo "<!-- ".is_file($phpgw_info["server"]["app_root"].$sep."conv".$sep.$file)." -->"; #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) ) if ((substr($file, 0, 1) != '.') && is_file($phpgw_info['server']['app_root'].$sep.'export'.$sep.$file) )
{ {
$myfilearray[$i] = $file; $myfilearray[$i] = $file;
$i++; $i++;
@ -52,40 +57,40 @@
for ($i=0;$i<count($myfilearray);$i++) for ($i=0;$i<count($myfilearray);$i++)
{ {
$fname = ereg_replace('_',' ',$myfilearray[$i]); $fname = ereg_replace('_',' ',$myfilearray[$i]);
$conv .= ' <OPTION VALUE="'.$myfilearray[$i].'">'.$fname.'</OPTION>'."\n"; $conv .= ' <option value="'.$myfilearray[$i].'">'.$fname.'</option>'."\n";
} }
$t->set_var("lang_cancel",lang("Cancel")); $t->set_var('lang_cancel',lang('Cancel'));
$t->set_var("lang_cat",lang("Select Category")); $t->set_var('lang_cat',lang('Select Category'));
$t->set_var("cat_link",cat_option($cat_id,False,False)); $t->set_var('cat_link',cat_option($cat_id,False,False));
$t->set_var("cancel_url",$phpgw->link("/addressbook/index.php")); $t->set_var('cancel_url',$phpgw->link('/addressbook/index.php'));
$t->set_var("navbar_bg",$phpgw_info["theme"]["navbar_bg"]); $t->set_var('navbar_bg',$phpgw_info['theme']['navbar_bg']);
$t->set_var("navbar_text",$phpgw_info["theme"]["navbar_text"]); $t->set_var('navbar_text',$phpgw_info['theme']['navbar_text']);
$t->set_var("export_text",lang("Export from Addressbook")); $t->set_var('export_text',lang('Export from Addressbook'));
$t->set_var("action_url",$phpgw->link("/addressbook/export.php")); $t->set_var('action_url',$phpgw->link('/addressbook/export.php'));
$t->set_var("filename",lang("Export file name")); $t->set_var('filename',lang('Export file name'));
$t->set_var("conv",$conv); $t->set_var('conv',$conv);
$t->set_var("debug",lang("")); $t->set_var('debug',lang(''));
$t->set_var("download",lang("Submit")); $t->set_var('download',lang('Submit'));
$t->set_var("start",$start); $t->set_var('start',$start);
$t->set_var("sort",$sort); $t->set_var('sort',$sort);
$t->set_var("order",$order); $t->set_var('order',$order);
$t->set_var("filter",$filter); $t->set_var('filter',$filter);
$t->set_var("query",$query); $t->set_var('query',$query);
$t->set_var("cat_id",$cat_id); $t->set_var('cat_id',$cat_id);
$t->pparse("out","export"); $t->pparse('out','export');
$phpgw->common->phpgw_footer(); $phpgw->common->phpgw_footer();
} }
else else
{ {
include ($phpgw_info["server"]["app_root"].$sep."export".$sep.$conv_type); include ($phpgw_info['server']['app_root'].$sep.'export'.$sep.$conv_type);
$buffer=array(); $buffer=array();
$this = new export_conv; $this = new export_conv;
// Read in user custom fields, if any // Read in user custom fields, if any
$customfields = array(); $customfields = array();
while (list($col,$descr) = @each($phpgw_info["user"]["preferences"]["addressbook"])) while (list($col,$descr) = @each($phpgw_info['user']['preferences']['addressbook']))
{ {
if ( substr($col,0,6) == 'extra_' ) if ( substr($col,0,6) == 'extra_' )
{ {
@ -95,9 +100,9 @@
} }
} }
$extrafields = array( $extrafields = array(
"ophone" => "ophone", 'ophone' => 'ophone',
"address2" => "address2", 'address2' => 'address2',
"address3" => "address3" 'address3' => 'address3'
); );
if ($this->type != 'vcard') if ($this->type != 'vcard')
{ {
@ -128,7 +133,7 @@
$tsvfilename = $phpgw_info['server']['temp_dir'].$sep.$tsvfilename; $tsvfilename = $phpgw_info['server']['temp_dir'].$sep.$tsvfilename;
if ( ($download == "on") || ($o->type == 'pdb') ) if ( ($download == 'on') || ($o->type == 'pdb') )
{ {
// filename, default application/octet-stream, length of file, default nocache True // filename, default application/octet-stream, length of file, default nocache True
$phpgw->browser->content_header($tsvfilename,'',strlen($buffer)); $phpgw->browser->content_header($tsvfilename,'',strlen($buffer));
@ -139,9 +144,9 @@
echo "<pre>\n"; echo "<pre>\n";
echo $buffer; echo $buffer;
echo "\n</pre>\n"; echo "\n</pre>\n";
echo '<a href="'.$phpgw->link("/addressbook/index.php", echo '<a href="'.$phpgw->link('/addressbook/index.php',
"sort=$sort&order=$order&filter=$filter&start=$start&query=$query&cat_id=$cat_id") "sort=$sort&order=$order&filter=$filter&start=$start&query=$query&cat_id=$cat_id")
. '">'.lang("OK").'</a>'; . '">'.lang('OK').'</a>';
$phpgw->common->phpgw_footer(); $phpgw->common->phpgw_footer();
} }
} }

View File

@ -28,56 +28,56 @@
// make sure to order how we ask for these // make sure to order how we ask for these
var $qfields = array( var $qfields = array(
"fn" => "fn", 'fn' => 'fn',
"n_given" => "n_given", 'n_given' => 'n_given',
"n_family" => "n_family", 'n_family' => 'n_family',
"n_middle" => "n_middle", 'n_middle' => 'n_middle',
"n_prefix" => "n_prefix", 'n_prefix' => 'n_prefix',
"n_suffix" => "n_suffix", 'n_suffix' => 'n_suffix',
"sound" => "sound", 'sound' => 'sound',
"bday" => "bday", 'bday' => 'bday',
"note" => "note", 'note' => 'note',
"tz" => "tz", 'tz' => 'tz',
"geo" => "geo", 'geo' => 'geo',
"url" => "url", 'url' => 'url',
"pubkey" => "pubkey", 'pubkey' => 'pubkey',
"org_name" => "org_name", 'org_name' => 'org_name',
"org_unit" => "org_unit", 'org_unit' => 'org_unit',
"title" => "title", 'title' => 'title',
"adr_one_type" => "adr_one_type", 'adr_one_type' => 'adr_one_type',
"adr_two_type" => "adr_two_type", 'adr_two_type' => 'adr_two_type',
"tel_prefer" => "tel_prefer", 'tel_prefer' => 'tel_prefer',
"email_type" => "email_type", 'email_type' => 'email_type',
"email_home_type" => "email_home_type", 'email_home_type' => 'email_home_type',
"adr_one_street" => "adr_one_street", 'adr_one_street' => 'adr_one_street',
"adr_one_locality" => "adr_one_locality", 'adr_one_locality' => 'adr_one_locality',
"adr_one_region" => "adr_one_region", 'adr_one_region' => 'adr_one_region',
"adr_one_postalcode" => "adr_one_postalcode", 'adr_one_postalcode' => 'adr_one_postalcode',
"adr_one_countryname" => "adr_one_countryname", 'adr_one_countryname' => 'adr_one_countryname',
"label" => "label", 'label' => 'label',
"adr_two_street" => "adr_two_street", 'adr_two_street' => 'adr_two_street',
"adr_two_locality" => "adr_two_locality", 'adr_two_locality' => 'adr_two_locality',
"adr_two_region" => "adr_two_region", 'adr_two_region' => 'adr_two_region',
"adr_two_postalcode" => "adr_two_postalcode", 'adr_two_postalcode' => 'adr_two_postalcode',
"adr_two_countryname" => "adr_two_countryname", 'adr_two_countryname' => 'adr_two_countryname',
"tel_work" => "tel_work", 'tel_work' => 'tel_work',
"tel_home" => "tel_home", 'tel_home' => 'tel_home',
"tel_voice" => "tel_voice", 'tel_voice' => 'tel_voice',
"tel_fax" => "tel_fax", 'tel_fax' => 'tel_fax',
"tel_msg" => "tel_msg", 'tel_msg' => 'tel_msg',
"tel_cell" => "tel_cell", 'tel_cell' => 'tel_cell',
"tel_pager" => "tel_pager", 'tel_pager' => 'tel_pager',
"tel_bbs" => "tel_bbs", 'tel_bbs' => 'tel_bbs',
"tel_modem" => "tel_modem", 'tel_modem' => 'tel_modem',
"tel_car" => "tel_car", 'tel_car' => 'tel_car',
"tel_isdn" => "tel_isdn", 'tel_isdn' => 'tel_isdn',
"tel_video" => "tel_video", 'tel_video' => 'tel_video',
"email" => "email", 'email' => 'email',
"email_home" => "email_home" 'email_home' => 'email_home'
); );
// This will store the contacts and vcard objects // This will store the contacts and vcard objects
@ -85,17 +85,19 @@
var $vcard = ''; var $vcard = '';
// Read full list of user's contacts only to get id's for each // Read full list of user's contacts only to get id's for each
function export_start_file($buffer,$ncat_id='') { function export_start_file($buffer,$ncat_id='')
{
$this->id=-1; $this->id=-1;
if ($ncat_id) { $filter = "tid=n,cat_id=".$ncat_id; } if ($ncat_id) { $filter = 'tid=n,cat_id='.$ncat_id; }
else { $filter = "tid=n"; } else { $filter = 'tid=n'; }
// Setup the contact and vcard objects, and the export fields var // Setup the contact and vcard objects, and the export fields var
$this->contacts = CreateObject('phpgwapi.contacts'); $this->contacts = CreateObject('phpgwapi.contacts');
$this->vcard = CreateObject("phpgwapi.vcard"); $this->vcard = CreateObject('phpgwapi.vcard');
$this->export = $this->vcard->export; $this->export = $this->vcard->export;
$tmp = $this->contacts->read('','',array('id'=>'id'),'',$filter); $tmp = $this->contacts->read('','',array('id'=>'id'),'',$filter);
for ($i=0;$i<count($tmp);$i++) { for ($i=0;$i<count($tmp);$i++)
{
$this->ids[$i] = $tmp[$i]['id']; $this->ids[$i] = $tmp[$i]['id'];
} }
// $ids is now an array of all id's for this user, e.g. $ids[0] = 21, etc... // $ids is now an array of all id's for this user, e.g. $ids[0] = 21, etc...
@ -104,7 +106,8 @@
} }
// Read each entry // Read each entry
function export_start_record($buffer) { function export_start_record($buffer)
{
$this->id++; $this->id++;
$top = $this->contacts->read_single_entry($this->ids[$this->id],$this->qfields); $top = $this->contacts->read_single_entry($this->ids[$this->id],$this->qfields);
$this->currentrecord = $top[0]; $this->currentrecord = $top[0];
@ -113,21 +116,26 @@
// Read each attribute, populate buffer // Read each attribute, populate buffer
// name/value are the fields from the export array in the vcard class // name/value are the fields from the export array in the vcard class
function export_new_attrib($buffer,$name,$value) { function export_new_attrib($buffer,$name,$value)
if ($this->export[$name] && ($value != "") ) { {
if ($this->export[$name] && ($value != '') )
{
$buffer[$this->id][$this->export[$name]] = $value; $buffer[$this->id][$this->export[$name]] = $value;
//echo '<br>'.$this->id.' - '.$this->export[$name].': '.$buffer[$this->id][$this->export[$name]]; //echo '<br>'.$this->id.' - '.$this->export[$name].': '.$buffer[$this->id][$this->export[$name]];
} }
return $buffer; return $buffer;
} }
function export_end_record($buffer) { function export_end_record($buffer)
{
return $buffer; return $buffer;
} }
function export_end_file($buffer) { function export_end_file($buffer)
{
reset($this->ids); reset($this->ids);
for ($i=0;$i<count($this->ids);$i++) { for ($i=0;$i<count($this->ids);$i++)
{
$vcards .= $this->vcard->out($buffer[$i]); $vcards .= $this->vcard->out($buffer[$i]);
} }
$buffer = $vcards; $buffer = $vcards;

View File

@ -24,41 +24,43 @@
var $type = 'ldif'; var $type = 'ldif';
var $export= array( var $export= array(
"title" => "title", 'title' => 'title',
"n_given" => "givenname", 'n_given' => 'givenname',
"n_family" => "sn", 'n_family' => 'sn',
"fn" => "cn", 'fn' => 'cn',
"org_name" => "o", 'org_name' => 'o',
"org_unit" => "ou", 'org_unit' => 'ou',
"adr_one_street" => "streetaddress", 'adr_one_street' => 'streetaddress',
"adr_one_locality" => "locality", 'adr_one_locality' => 'locality',
"adr_one_region" => "st", 'adr_one_region' => 'st',
"adr_one_postalcode" => "postalcode", 'adr_one_postalcode' => 'postalcode',
"adr_one_countryname" => "countryname", 'adr_one_countryname' => 'countryname',
"tel_work" => "telephonenumber", 'tel_work' => 'telephonenumber',
"tel_home" => "homephone", 'tel_home' => 'homephone',
"tel_fax" => "facsimiletelephonenumber", 'tel_fax' => 'facsimiletelephonenumber',
"ophone" => "xmozillaanyphone", 'ophone' => 'xmozillaanyphone',
"tel_cell" => "cellphone", 'tel_cell' => 'cellphone',
"note" => "description", 'note' => 'description',
"ophone" => "ophone", 'ophone' => 'ophone',
"tel_pager" => "pagerphone", 'tel_pager' => 'pagerphone',
"email" => "mail", 'email' => 'mail',
"url" => "homeurl", 'url' => 'homeurl',
); );
// This will store the contacts object // This will store the contacts object
var $contacts = ''; var $contacts = '';
// Read full list of user's contacts only to get id's for each // Read full list of user's contacts only to get id's for each
function export_start_file($buffer,$ncat_id='') { function export_start_file($buffer,$ncat_id='')
{
$this->id=-1; $this->id=-1;
if ($ncat_id) { $filter = "tid=n,cat_id=".$ncat_id; } if ($ncat_id) { $filter = "tid=n,cat_id=".$ncat_id; }
else { $filter = "tid=n"; } else { $filter = "tid=n"; }
$this->contacts = CreateObject('phpgwapi.contacts'); $this->contacts = CreateObject('phpgwapi.contacts');
$tmp = $this->contacts->read('','',array('id'=>'id'),'',$filter); $tmp = $this->contacts->read('','',array('id'=>'id'),'',$filter);
for ($i=0;$i<count($tmp);$i++) { for ($i=0;$i<count($tmp);$i++)
{
$this->ids[$i] = $tmp[$i]['id']; $this->ids[$i] = $tmp[$i]['id'];
} }
// $ids is now an array of all id's for this user, e.g. $ids[0] = 21, etc... // $ids is now an array of all id's for this user, e.g. $ids[0] = 21, etc...
@ -67,7 +69,8 @@
} }
// Read each entry // Read each entry
function export_start_record($buffer) { function export_start_record($buffer)
{
$this->id++; $this->id++;
$top = $this->contacts->read_single_entry($this->ids[$this->id],$this->qfields); $top = $this->contacts->read_single_entry($this->ids[$this->id],$this->qfields);
$this->currentrecord = $top[0]; $this->currentrecord = $top[0];
@ -76,12 +79,17 @@
// Read each attribute, populate buffer // Read each attribute, populate buffer
// name/value are the fields from the export array above // name/value are the fields from the export array above
function export_new_attrib($buffer,$name,$value) { function export_new_attrib($buffer,$name,$value)
if ($this->export[$name]) { {
if (strstr($value,"\n")) { if ($this->export[$name])
$value = ": ".base64_encode($value); {
} else { if (strstr($value,"\n"))
$value = " ".$value; {
$value = ': '.base64_encode($value);
}
else
{
$value = ' '.$value;
} }
$buffer[$this->id][$this->export[$name]] = $value; $buffer[$this->id][$this->export[$name]] = $value;
//echo '<br>'.$this->id.' - '.$this->export[$name].': '.$buffer[$this->id][$this->export[$name]]; //echo '<br>'.$this->id.' - '.$this->export[$name].': '.$buffer[$this->id][$this->export[$name]];
@ -90,40 +98,48 @@
} }
// Tack on some extra values // Tack on some extra values
function export_end_record($buffer) { function export_end_record($buffer)
$buffer[$this->id]["dn"] = 'cn='.$buffer[$this->id]["cn"].',mail='.$buffer[$this->id]["mail"]; {
$buffer[$this->id]["xmozillauseconferenceserver"] = "0"; $buffer[$this->id]['dn'] = 'cn='.$buffer[$this->id]['cn'].',mail='.$buffer[$this->id]['mail'];
$buffer[$this->id]["xmozillanickname"] = ""; $buffer[$this->id]['xmozillauseconferenceserver'] = '0';
$buffer[$this->id]["xmozillausehtmlmail"] = "False"; $buffer[$this->id]['xmozillanickname'] = '';
if ($buffer[$this->id]["ophone"]) { $buffer[$this->id]['xmozillausehtmlmail'] = 'False';
$buffer[$this->id]["xmozillaanyphone"] = $buffer[$this->id]["ophone"]; if ($buffer[$this->id]['ophone'])
} else { {
$buffer[$this->id]["xmozillaanyphone"] = $buffer[$this->id]["telephonenumber"]; $buffer[$this->id]['xmozillaanyphone'] = $buffer[$this->id]['ophone'];
}
else
{
$buffer[$this->id]['xmozillaanyphone'] = $buffer[$this->id]['telephonenumber'];
} }
//echo '<br>'.$this->id.' - '.$buffer[$this->id]['dn']; //echo '<br>'.$this->id.' - '.$buffer[$this->id]['dn'];
return $buffer; return $buffer;
} }
function export_end_file($buffer) { function export_end_file($buffer)
{
reset($this->ids); reset($this->ids);
for ($i=0;$i<count($this->ids);$i++) { for ($i=0;$i<count($this->ids);$i++)
{
$entries .= 'dn: ' . $buffer[$i]['dn'] . "\n"; $entries .= 'dn: ' . $buffer[$i]['dn'] . "\n";
reset($this->export); reset($this->export);
while (list($name,$value)=each($this->export)) { while (list($name,$value)=each($this->export))
if ($value != 'dn') { {
if ($value != 'dn')
{
$entries .= $value . ":" . $buffer[$i][$value] . "\n"; $entries .= $value . ":" . $buffer[$i][$value] . "\n";
} }
} }
$entries .= "xmozillauseconferenceserver: " . $buffer[$i]["xmozillauseconferenceserver"] . "\n"; $entries .= 'xmozillauseconferenceserver: ' . $buffer[$i]['xmozillauseconferenceserver'] . "\n";
$entries .= "xmozillanickname: " . $buffer[$i]["xmozillanickname"] . "\n"; $entries .= 'xmozillanickname: ' . $buffer[$i]['xmozillanickname'] . "\n";
$entries .= "xmozillausehtmlmail: " . $buffer[$i]["xmozillausehtmlmail"] . "\n"; $entries .= 'xmozillausehtmlmail: ' . $buffer[$i]['xmozillausehtmlmail'] . "\n";
$entries .= "xmozillaanyphone: " . $buffer[$i]["xmozillaanyphone"] . "\n"; $entries .= 'xmozillaanyphone: ' . $buffer[$i]['xmozillaanyphone'] . "\n";
$entries .= "objectClass: person\n"; $entries .= 'objectClass: person' . "\n";
$entries .= "objectClass: account\n"; $entries .= 'objectClass: account' . "\n";
$entries .= "objectClass: organizationalPerson\n"; $entries .= 'objectClass: organizationalPerson' . "\n";
$entries .= "objectClass: posixAccount\n"; $entries .= 'objectClass: posixAccount' . "\n";
$entries .= "objectClass: inetOrgPerson\n"; $entries .= 'objectClass: inetOrgPerson' . "\n";
$entries .= "objectClass: shadowAccount\n"; $entries .= 'objectClass: shadowAccount' . "\n";
$entries .= "\n"; $entries .= "\n";
} }
$buffer = $entries; $buffer = $entries;

View File

@ -30,52 +30,54 @@
var $type = 'csv'; var $type = 'csv';
var $export = array( var $export = array(
"title" => "Title", 'title' => 'Title',
"n_given" => "First Name", 'n_given' => 'First Name',
"n_middle" => "Middle Name", 'n_middle' => 'Middle Name',
"n_family" => "Last Name", 'n_family' => 'Last Name',
"n_suffix" => "Suffix", 'n_suffix' => 'Suffix',
"org_name" => "Company", 'org_name' => 'Company',
"org_unit" => "Department", 'org_unit' => 'Department',
"adr_one_street" => "Business Street", 'adr_one_street' => 'Business Street',
"address2" => "Business Street 2", 'address2' => 'Business Street 2',
"address3" => "Business Street 3", 'address3' => 'Business Street 3',
"adr_one_locality" => "Business City", 'adr_one_locality' => 'Business City',
"adr_one_region" => "Business State", 'adr_one_region' => 'Business State',
"adr_one_postalcode" => "Business Postal Code", 'adr_one_postalcode' => 'Business Postal Code',
"adr_one_countryname" => "Business Country", 'adr_one_countryname' => 'Business Country',
"adr_two_street" => "Home Street", 'adr_two_street' => 'Home Street',
"adr_two_locality" => "Home City", 'adr_two_locality' => 'Home City',
"adr_two_region" => "Home State", 'adr_two_region' => 'Home State',
"adr_two_postalcode" => "Home Postal Code", 'adr_two_postalcode' => 'Home Postal Code',
"adr_two_countryname" => "Home Country", 'adr_two_countryname' => 'Home Country',
"tel_fax" => "Business Fax", 'tel_fax' => 'Business Fax',
"tel_work" => "Business Phone", 'tel_work' => 'Business Phone',
"tel_msg" => "Assistant's Phone", 'tel_msg' => "Assistant's Phone",
"tel_car" => "Car Phone", 'tel_car' => 'Car Phone',
"tel_isdn" => "ISDN", 'tel_isdn' => 'ISDN',
"tel_home" => "Home Phone", 'tel_home' => 'Home Phone',
"tel_cell" => "Mobile Phone", 'tel_cell' => 'Mobile Phone',
"tel_pager" => "Pager", 'tel_pager' => 'Pager',
"ophone" => "Business Phone 2", 'ophone' => 'Business Phone 2',
"bday" => "Birthday", 'bday' => 'Birthday',
"email" => "E-mail Address", 'email' => 'E-mail Address',
"email_home" => "E-mail Address 2", 'email_home' => 'E-mail Address 2',
"url" => "Web Page", 'url' => 'Web Page',
"note" => "Notes" 'note' => 'Notes'
); );
// This will store the contacts object // This will store the contacts object
var $contacts = ''; var $contacts = '';
function export_start_file($buffer,$ncat_id='') { function export_start_file($buffer,$ncat_id='')
{
$this->id=-1; $this->id=-1;
if ($ncat_id) { $filter = "tid=n,cat_id=".$ncat_id; } if ($ncat_id) { $filter = 'tid=n,cat_id='.$ncat_id; }
else { $filter = "tid=n"; } else { $filter = 'tid=n'; }
$this->contacts = CreateObject('phpgwapi.contacts'); $this->contacts = CreateObject('phpgwapi.contacts');
$tmp = $this->contacts->read('','',array('id'=>'id'),'',$filter); $tmp = $this->contacts->read('','',array('id'=>'id'),'',$filter);
for ($i=0;$i<count($tmp);$i++) { for ($i=0;$i<count($tmp);$i++)
{
$this->ids[$i] = $tmp[$i]['id']; $this->ids[$i] = $tmp[$i]['id'];
} }
// $ids is now an array of all id's for this user, e.g. $ids[0] = 21, etc... // $ids is now an array of all id's for this user, e.g. $ids[0] = 21, etc...
@ -84,7 +86,8 @@
} }
// Read each entry // Read each entry
function export_start_record($buffer) { function export_start_record($buffer)
{
$this->id++; $this->id++;
$top = $this->contacts->read_single_entry($this->ids[$this->id],$this->qfields); $top = $this->contacts->read_single_entry($this->ids[$this->id],$this->qfields);
$this->currentrecord = $top[0]; $this->currentrecord = $top[0];
@ -93,8 +96,10 @@
// Read each attribute, populate buffer // Read each attribute, populate buffer
// name/value are the fields from the export array above // name/value are the fields from the export array above
function export_new_attrib($buffer,$name,$value) { function export_new_attrib($buffer,$name,$value)
if ($this->export[$name]) { {
if ($this->export[$name])
{
$buffer[$this->id][$this->export[$name]] = $value; $buffer[$this->id][$this->export[$name]] = $value;
//echo '<br>'.$this->id.' - '.$this->export[$name].': '.$buffer[$this->id][$this->export[$name]]; //echo '<br>'.$this->id.' - '.$this->export[$name].': '.$buffer[$this->id][$this->export[$name]];
} }
@ -102,14 +107,17 @@
} }
// Tack on some extra values // Tack on some extra values
function export_end_record($buffer) { function export_end_record($buffer)
{
return $buffer; return $buffer;
} }
function export_end_file($buffer) { function export_end_file($buffer)
{
// Build the header for the file (field list) // Build the header for the file (field list)
reset($this->export); reset($this->export);
while (list($name,$value)=each($this->export)) { while (list($name,$value)=each($this->export))
{
$entries .= $value . ','; $entries .= $value . ',';
} }
$entries = substr($entries,0,-1); $entries = substr($entries,0,-1);
@ -117,9 +125,11 @@
// Now add all the data // Now add all the data
reset($this->ids); reset($this->ids);
for ($i=0;$i<count($this->ids);$i++) { for ($i=0;$i<count($this->ids);$i++)
{
reset($this->export); reset($this->export);
while (list($name,$value)=each($this->export)) { while (list($name,$value)=each($this->export))
{
$entries .= $buffer[$i][$value] . ','; $entries .= $buffer[$i][$value] . ',';
} }
$entries = substr($entries,0,-1); $entries = substr($entries,0,-1);

View File

@ -21,56 +21,58 @@
var $id; var $id;
//list of all id's //list of all id's
var $ids = array(); var $ids = array();
var $type = "pdb"; var $type = 'pdb';
var $export = array( var $export = array(
"title" => "Title", 'title' => 'Title',
"n_given" => "First", 'n_given' => 'First',
"n_middle" => "Middle", 'n_middle' => 'Middle',
"n_family" => "Last", 'n_family' => 'Last',
"n_suffix" => "Suffix", 'n_suffix' => 'Suffix',
"org_name" => "Company", 'org_name' => 'Company',
"org_unit" => "Dept", 'org_unit' => 'Dept',
"adr_one_street" => "Bus. Street", 'adr_one_street' => 'Bus. Street',
"address2" => "Bus. St. 2", 'address2' => 'Bus. St. 2',
"address3" => "Bus. St. 3", 'address3' => 'Bus. St. 3',
"adr_one_locality" => "Bus. City", 'adr_one_locality' => 'Bus. City',
"adr_one_region" => "Bus. State", 'adr_one_region' => 'Bus. State',
"adr_one_postalcode" => "Bus. Postal Code", 'adr_one_postalcode' => 'Bus. Postal Code',
"adr_one_countryname" => "Bus. Country", 'adr_one_countryname' => 'Bus. Country',
"adr_two_street" => "Home Street", 'adr_two_street' => 'Home Street',
"adr_two_locality" => "Home City", 'adr_two_locality' => 'Home City',
"adr_two_region" => "Home State", 'adr_two_region' => 'Home State',
"adr_two_postalcode" => "Home Postal Code", 'adr_two_postalcode' => 'Home Postal Code',
"adr_two_countryname" => "Home Country", 'adr_two_countryname' => 'Home Country',
"tel_fax" => "Bus. Fax", 'tel_fax' => 'Bus. Fax',
"tel_work" => "Bus. Phone", 'tel_work' => 'Bus. Phone',
"tel_msg" => "Assistant's Phone", 'tel_msg' => "Assistant's Phone",
"tel_car" => "Car Phone", 'tel_car' => 'Car Phone',
"tel_isdn" => "ISDN", 'tel_isdn' => 'ISDN',
"tel_home" => "Home Phone", 'tel_home' => 'Home Phone',
"tel_cell" => "Mobile Phone", 'tel_cell' => 'Mobile Phone',
"tel_pager" => "Pager", 'tel_pager' => 'Pager',
"ophone" => "Bus. Phone2", 'ophone' => 'Bus. Phone2',
"bday" => "Birthday", 'bday' => 'Birthday',
"email" => "Email Addr", 'email' => 'Email Addr',
"email_home" => "Email Addr2", 'email_home' => 'Email Addr2',
"url" => "URL", 'url' => 'URL',
"note" => "Notes" 'note' => 'Notes'
); );
// This will store the contacts object // This will store the contacts object
var $contacts = ''; var $contacts = '';
// Read full list of user's contacts only to get id's for each // Read full list of user's contacts only to get id's for each
function export_start_file($buffer,$ncat_id='') { function export_start_file($buffer,$ncat_id='')
{
$this->id=-1; $this->id=-1;
if ($ncat_id) { $filter = "tid=n,cat_id=".$ncat_id; } if ($ncat_id) { $filter = 'tid=n,cat_id='.$ncat_id; }
else { $filter = "tid=n"; } else { $filter = 'tid=n'; }
$this->contacts = CreateObject('phpgwapi.contacts'); $this->contacts = CreateObject('phpgwapi.contacts');
$tmp = $this->contacts->read('','',array('id'=>'id'),'',$filter); $tmp = $this->contacts->read('','',array('id'=>'id'),'',$filter);
for ($i=0;$i<count($tmp);$i++) { for ($i=0;$i<count($tmp);$i++)
{
$this->ids[$i] = $tmp[$i]['id']; $this->ids[$i] = $tmp[$i]['id'];
} }
// $ids is now an array of all id's for this user, e.g. $ids[0] = 21, etc... // $ids is now an array of all id's for this user, e.g. $ids[0] = 21, etc...
@ -79,7 +81,8 @@
} }
// Read each entry // Read each entry
function export_start_record($buffer) { function export_start_record($buffer)
{
$this->id++; $this->id++;
$top = $this->contacts->read_single_entry($this->ids[$this->id],$this->qfields); $top = $this->contacts->read_single_entry($this->ids[$this->id],$this->qfields);
$this->currentrecord = $top[0]; $this->currentrecord = $top[0];
@ -88,8 +91,10 @@
// Read each attribute, populate buffer array // Read each attribute, populate buffer array
// name/value are the fields from the export array above // name/value are the fields from the export array above
function export_new_attrib($buffer,$name,$value) { function export_new_attrib($buffer,$name,$value)
if ($this->export[$name]) { {
if ($this->export[$name])
{
$buffer[$this->id][$this->export[$name]] = $value; $buffer[$this->id][$this->export[$name]] = $value;
//echo '<br>'.$this->id.' - '.$this->export[$name].': '.$buffer[$this->id][$this->export[$name]]; //echo '<br>'.$this->id.' - '.$this->export[$name].': '.$buffer[$this->id][$this->export[$name]];
} }
@ -97,26 +102,30 @@
} }
// Tack on some extra values - none for this file // Tack on some extra values - none for this file
function export_end_record($buffer) { function export_end_record($buffer)
{
return $buffer; return $buffer;
} }
// Parse it all into a string // Parse it all into a string
function export_end_file($buffer) { function export_end_file($buffer)
{
reset($this->ids); reset($this->ids);
for ($i=0;$i<count($this->ids);$i++) { for ($i=0;$i<count($this->ids);$i++)
{
$j = $i + 1; $j = $i + 1;
reset($this->export); reset($this->export);
$entries .= "#" . $j . ":" . $buffer[$i]['n_given'] . $buffer[$i]['n_family'] . "\r\n"; $entries .= "#" . $j . ":" . $buffer[$i]['n_given'] . $buffer[$i]['n_family'] . "\r\n";
while (list($name,$value)=each($this->export)) { while (list($name,$value)=each($this->export))
{
$entries .= $value . ":\t" . $buffer[$i][$value] . "\n"; $entries .= $value . ":\t" . $buffer[$i][$value] . "\n";
} }
$entries .= "\r\n"; $entries .= "\r\n";
} }
$buffer = $entries; $buffer = $entries;
$pdb = CreateObject("addressbook.pdb"); $pdb = CreateObject('addressbook.pdb');
$pdb->fetch($buffer, 'phpgw Contacts', 'phpgw.pdb'); $pdb->fetch($buffer, 'phpgw Contacts', 'phpgw.pdb');
return $buffer; return $buffer;
} }

View File

@ -24,75 +24,77 @@
var $type = 'ldif'; var $type = 'ldif';
var $export = array( var $export = array(
"id" => "uidnumber", 'id' => 'uidnumber',
"lid" => "uid", 'lid' => 'uid',
"tid" => "phpgwcontacttype", 'tid' => 'phpgwcontacttype',
"owner" => "phpgwowner", 'owner' => 'phpgwcontactowner',
"access" => "phpgwaccess", 'access' => 'phpgwcontactaccess',
"fn" => "cn", // 'prefix given middle family suffix' 'fn' => 'cn', // 'prefix given middle family suffix'
"n_given" => "givenname", // firstname 'n_given' => 'givenname', // firstname
"n_family" => "sn", // lastname 'n_family' => 'sn', // lastname
"n_middle" => "middlename", 'n_middle' => 'phpgwmiddlename',
"n_prefix" => "prefix", 'n_prefix' => 'phpgwprefix',
"n_suffix" => "suffix", 'n_suffix' => 'phpgwsuffix',
"sound" => "audio", 'sound' => 'phpgwaudio',
"bday" => "birthday", 'bday' => 'phpgwbirthday',
"note" => "description", 'note' => 'description',
"tz" => "tz", 'tz' => 'phpgwtz',
"geo" => "geo", 'geo' => 'phpgwgeo',
"url" => "url", 'url' => 'phpgwurl',
"pubkey" => "publickey", 'pubkey' => 'phpgwpublickey',
"org_name" => "o", // company 'org_name' => 'o', // company
"org_unit" => "ou", // division 'org_unit' => 'ou', // division
"title" => "title", 'title' => 'title',
"adr_one_street" => "streetaddress", 'adr_one_street' => 'streetaddress',
"adr_one_locality" => "locality", 'adr_one_locality' => 'locality',
"adr_one_region" => "st", 'adr_one_region' => 'st',
"adr_one_postalcode" => "postalcode", 'adr_one_postalcode' => 'postalcode',
"adr_one_countryname" => "countryname", 'adr_one_countryname' => 'co',
"adr_one_type" => "phpgwadronetype", // address is domestic/intl/postal/parcel/work/home 'adr_one_type' => 'phpgwadronetype', // address is domestic/intl/postal/parcel/work/home
"label" => "phpgwaddresslabel", // address label 'label' => 'phpgwaddresslabel', // address label
"adr_two_street" => "phpgwadrtwostreet", 'adr_two_street' => 'phpgwadrtwostreet',
"adr_two_locality" => "phpgwadrtwolocality", 'adr_two_locality' => 'phpgwadrtwolocality',
"adr_two_region" => "phpgwadrtworegion", 'adr_two_region' => 'phpgwadrtworegion',
"adr_two_postalcode" => "phpgwadrtwopostalcode", 'adr_two_postalcode' => 'phpgwadrtwopostalcode',
"adr_two_countryname" => "phpgwadrtwocountryname", 'adr_two_countryname' => 'phpgwadrtwocountryname',
"adr_two_type" => "phpgwadrtwotype", // address is domestic/intl/postal/parcel/work/home 'adr_two_type' => 'phpgwadrtwotype', // address is domestic/intl/postal/parcel/work/home
"tel_work" => "telephonenumber", 'tel_work' => 'telephonenumber',
"tel_home" => "homephone", 'tel_home' => 'homephone',
"tel_voice" => "voicetelephonenumber", 'tel_voice' => 'phpgwvoicetelephonenumber',
"tel_fax" => "facsimiletelephonenumber", 'tel_fax' => 'facsimiletelephonenumber',
"tel_msg" => "msgtelephonenumber", 'tel_msg' => 'phpgwmsgtelephonenumber',
"tel_cell" => "cellphone", 'tel_cell' => 'phpgwcelltelephonenumber',
"tel_pager" => "pagertelephonenumber", 'tel_pager' => 'phpgwpagertelephonenumber',
"tel_bbs" => "bbstelephonenumber", 'tel_bbs' => 'phpgwbbstelephonenumber',
"tel_modem" => "modemtelephonenumber", 'tel_modem' => 'phpgwmodemtelephonenumber',
"tel_car" => "mobiletelephonenumber", 'tel_car' => 'phpgwmobiletelephonenumber',
"tel_isdn" => "isdnphonenumber", 'tel_isdn' => 'phpgwisdnphonenumber',
"tel_video" => "videophonenumber", 'tel_video' => 'phpgwvideophonenumber',
"tel_prefer" => "preferphone", // home, work, voice, etc 'tel_prefer' => 'phpgwpreferphone', // home, work, voice, etc
"email" => "mail", 'email' => 'mail',
"email_type" => "mailtype", //'INTERNET','CompuServe',etc... 'email_type' => 'phpgwmailtype', //'INTERNET','CompuServe',etc...
"email_home" => "mailhome", 'email_home' => 'phpgwmailhome',
"email_home_type" => "mailhometype" //'INTERNET','CompuServe',etc... 'email_home_type' => 'phpgwmailhometype' //'INTERNET','CompuServe',etc...
); );
// This will store the contacts object // This will store the contacts object
var $contacts = ''; var $contacts = '';
// Read full list of user's contacts only to get id's for each // Read full list of user's contacts only to get id's for each
function export_start_file($buffer,$ncat_id='') { function export_start_file($buffer,$ncat_id='')
{
$this->id=-1; $this->id=-1;
if ($ncat_id) { $filter = "tid=n,cat_id=".$ncat_id; } if ($ncat_id) { $filter = 'tid=n,cat_id='.$ncat_id; }
else { $filter = "tid=n"; } else { $filter = 'tid=n'; }
$this->contacts = CreateObject('phpgwapi.contacts'); $this->contacts = CreateObject('phpgwapi.contacts');
$tmp = $this->contacts->read('','',array('id'=>'id'),'',$filter); $tmp = $this->contacts->read('','',array('id'=>'id'),'',$filter);
for ($i=0;$i<count($tmp);$i++) { for ($i=0;$i<count($tmp);$i++)
{
$this->ids[$i] = $tmp[$i]['id']; $this->ids[$i] = $tmp[$i]['id'];
} }
// $ids is now an array of all id's for this user, e.g. $ids[0] = 21, etc... // $ids is now an array of all id's for this user, e.g. $ids[0] = 21, etc...
@ -101,7 +103,8 @@
} }
// Read each entry // Read each entry
function export_start_record($buffer) { function export_start_record($buffer)
{
$this->id++; $this->id++;
$top = $this->contacts->read_single_entry($this->ids[$this->id],$this->qfields); $top = $this->contacts->read_single_entry($this->ids[$this->id],$this->qfields);
$this->currentrecord = $top[0]; $this->currentrecord = $top[0];
@ -110,8 +113,10 @@
// Read each attribute, populate buffer // Read each attribute, populate buffer
// name/value are the fields from the export array above // name/value are the fields from the export array above
function export_new_attrib($buffer,$name,$value) { function export_new_attrib($buffer,$name,$value)
if ($this->export[$name] && ($value != "") ) { {
if ($this->export[$name] && ($value != '') )
{
$buffer[$this->id][$this->export[$name]] = $value; $buffer[$this->id][$this->export[$name]] = $value;
//echo '<br>'.$this->id.' - '.$this->export[$name].': '.$buffer[$this->id][$this->export[$name]]; //echo '<br>'.$this->id.' - '.$this->export[$name].': '.$buffer[$this->id][$this->export[$name]];
} }
@ -119,38 +124,44 @@
} }
// Tack on some extra values // Tack on some extra values
function export_end_record($buffer) { function export_end_record($buffer)
{
global $phpgw_info; global $phpgw_info;
if ($phpgw_info['server']['ldap_contact_context']) { if ($phpgw_info['server']['ldap_contact_context'])
{
$context = $phpgw_info['server']['ldap_contact_context']; $context = $phpgw_info['server']['ldap_contact_context'];
} }
$time = gettimeofday(); $time = gettimeofday();
$cn = ereg_replace(',','',$buffer[$this->id]["cn"]); $cn = ereg_replace(',','',$buffer[$this->id]['cn']);
$buffer[$this->id]["dn"] = 'uid='.time().$time["usec"].":".$cn.','.$context; $buffer[$this->id]['dn'] = 'uid='.time().$time['usec'].':'.$cn.','.$context;
$buffer[$this->id]["uid"] = time().$time["usec"]; $buffer[$this->id]['uid'] = time().$time['usec'];
if ($buffer[$this->id]['cn']) { if ($buffer[$this->id]['cn'])
$buffer[$this->id]["uid"] .= ":".$buffer[$this->id]['cn']; {
$buffer[$this->id]['uid'] .= ':'.$buffer[$this->id]['cn'];
} }
$buffer[$this->id]["description"] = ereg_replace("\r\n",';',$buffer[$this->id]["description"]); $buffer[$this->id]['description'] = ereg_replace("\r\n",';',$buffer[$this->id]['description']);
//echo '<br>'.$this->id.' - '.$buffer[$this->id]['dn']; //echo '<br>'.$this->id.' - '.$buffer[$this->id]['dn'];
return $buffer; return $buffer;
} }
function export_end_file($buffer) { function export_end_file($buffer) {
reset($this->ids); reset($this->ids);
for ($i=0;$i<count($this->ids);$i++) { for ($i=0;$i<count($this->ids);$i++)
{
$entries .= 'dn: '.$buffer[$i]['dn'] . "\n"; $entries .= 'dn: '.$buffer[$i]['dn'] . "\n";
reset($this->export); reset($this->export);
while (list($name,$value)=each($this->export)) { while (list($name,$value)=each($this->export))
if (($value != 'dn') && !empty($buffer[$i][$value])) { {
if (($value != 'dn') && !empty($buffer[$i][$value]))
{
$tmp = ereg_replace(',','',$buffer[$i][$value]); $tmp = ereg_replace(',','',$buffer[$i][$value]);
$entries .= $value . ": " . $tmp . "\n"; $entries .= $value . ': ' . $tmp . "\n";
} }
} }
$entries .= "objectClass: person\n"; $entries .= 'objectClass: person' . "\n";
$entries .= "objectClass: organizationalPerson\n"; $entries .= 'objectClass: organizationalPerson' . "\n";
$entries .= "objectClass: inetOrgPerson\n"; $entries .= 'objectClass: inetOrgPerson' . "\n";
$entries .= "objectClass: phpgwContact\n"; $entries .= 'objectClass: phpgwContact' . "\n";
$entries .= "\n"; $entries .= "\n";
} }
$buffer = $entries; $buffer = $entries;