mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-25 16:19:00 +01:00
Working export to CSV or LDIF, I hope
This commit is contained in:
parent
5d7cb50e74
commit
a51a7339be
@ -12,6 +12,18 @@
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
if ($download =='on') {
|
||||
$phpgw_info["flags"] = array(
|
||||
"noheader" => True,
|
||||
"nonavbar" => True
|
||||
);
|
||||
} else {
|
||||
$phpgw_info["flags"] = array(
|
||||
"noheader" => False,
|
||||
"nonavbar" => False
|
||||
);
|
||||
}
|
||||
|
||||
$phpgw_info["flags"]["currentapp"] = "addressbook";
|
||||
$phpgw_info["flags"]["enable_contacts_class"] = True;
|
||||
include("../header.inc.php");
|
||||
@ -42,7 +54,7 @@
|
||||
$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 - NOT WORKING YET"));
|
||||
$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);
|
||||
@ -77,7 +89,6 @@
|
||||
$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);
|
||||
@ -85,25 +96,20 @@
|
||||
$buffer = $this->export_end_record($buffer);
|
||||
}
|
||||
|
||||
// Here, buffer becomes a string suitable for printing
|
||||
$buffer = $this->export_end_file($buffer);
|
||||
|
||||
$tsvfilename = $phpgw_info['server']['temp_dir'].$sep.$tsvfilename;
|
||||
|
||||
if ($download == "Submit") {
|
||||
if ($download == "on") {
|
||||
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";
|
||||
// }
|
||||
echo $buffer;
|
||||
} else {
|
||||
echo "<pre>\n";
|
||||
$i=0;
|
||||
while(list($name,$value) = each($buffer[$i])) {
|
||||
echo $i.' - '.$name.': '.$value."\n";
|
||||
$i++;
|
||||
}
|
||||
echo $buffer;
|
||||
echo "\n</pre>\n";
|
||||
echo '<a href="'.$phpgw->link("/addressbook/index.php").'">'.lang("OK").'</a>';
|
||||
$phpgw->common->phpgw_footer();
|
||||
|
@ -65,49 +65,64 @@
|
||||
"note" => "Notes"
|
||||
);
|
||||
|
||||
function export_start_file($buffer,$j="",$k="") {
|
||||
// This will store the contacts object
|
||||
var $contacts = '';
|
||||
|
||||
function export_start_file($buffer) {
|
||||
$this->id=-1;
|
||||
$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) {
|
||||
$this->id++;
|
||||
$top = $this->contacts->read_single_entry($this->ids[$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) {
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
function export_end_file($buffer) {
|
||||
global $phpgw,$phpgw_info;
|
||||
// Build the header for the file (field list)
|
||||
reset($this->export);
|
||||
while (list($name,$value)=each($this->export)) {
|
||||
$entries .= $value . ',';
|
||||
}
|
||||
$entries = substr($entries,0,-1);
|
||||
$entries .= "\r\n";
|
||||
|
||||
$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;
|
||||
// Now add all the data
|
||||
reset($this->ids);
|
||||
for ($i=0;$i<count($this->ids);$i++) {
|
||||
reset($this->export);
|
||||
while (list($name,$value)=each($this->export)) {
|
||||
$entries .= $buffer[$i][$value] . ',';
|
||||
}
|
||||
//echo '<br>';
|
||||
$contacts->add($phpgw_info["user"]["account_id"],$entry[$i]);
|
||||
$entries = substr($entries,0,-1);
|
||||
$entries .= "\r\n";
|
||||
}
|
||||
$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);
|
||||
|
||||
$buffer = $entries;
|
||||
return $buffer;
|
||||
}
|
||||
}
|
||||
|
@ -50,6 +50,7 @@
|
||||
|
||||
// Read full list of user's contacts only to get id's for each
|
||||
function export_start_file($buffer) {
|
||||
$this->id=-1;
|
||||
$this->contacts = CreateObject('phpgwapi.contacts');
|
||||
$tmp = $this->contacts->read(0,'');
|
||||
for ($i=0;$i<count($tmp);$i++) {
|
||||
@ -62,7 +63,8 @@
|
||||
|
||||
// Read each entry
|
||||
function export_start_record($buffer) {
|
||||
$top = $this->contacts->read_single_entry($this->id,$this->qfields);
|
||||
$this->id++;
|
||||
$top = $this->contacts->read_single_entry($this->ids[$this->id],$this->qfields);
|
||||
$this->currentrecord = $top[0];
|
||||
return $buffer;
|
||||
}
|
||||
@ -83,12 +85,32 @@
|
||||
$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) {
|
||||
reset($this->ids);
|
||||
for ($i=0;$i<count($this->ids);$i++) {
|
||||
$entries .= $buffer[$i]['dn'] . "\n";
|
||||
reset($this->export);
|
||||
while (list($name,$value)=each($this->export)) {
|
||||
if ($value != 'dn') {
|
||||
$entries .= $value . ": " . $buffer[$i][$value] . "\n";
|
||||
}
|
||||
}
|
||||
$entries .= "xmozillauseconferenceserver: " . $buffer[$i]["xmozillauseconferenceserver"] . "\n";
|
||||
$entries .= "xmozillanickname: " . $buffer[$i]["xmozillanickname"] . "\n";
|
||||
$entries .= "xmozillausehtmlmail: " . $buffer[$i]["xmozillausehtmlmail"] . "\n";
|
||||
$entries .= "objectClass: person\n";
|
||||
$entries .= "account\n";
|
||||
$entries .= "organizationalPerson\n";
|
||||
$entries .= "posixAccount\n";
|
||||
$entries .= "objectClass: inetOrgPerson\n";
|
||||
$entries .= "objectClass: shadowAccount\n";
|
||||
$entries .= "\n";
|
||||
}
|
||||
$buffer = $entries;
|
||||
return $buffer;
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
||||
</SELECT><P></LI>
|
||||
<LI>{filename}:
|
||||
<INPUT NAME="tsvfilename" VALUE="conversion.txt"></LI>
|
||||
<LI><INPUT NAME="download" TYPE="checkbox" VALUE="{debug}" checked>Download export file (Uncheck to debug output in browser)</LI>
|
||||
<LI><INPUT NAME="download" TYPE="checkbox" checked>Download export file (Uncheck to debug output in browser)</LI>
|
||||
<LI><INPUT NAME="convert" TYPE="submit" VALUE="{download}"></LI>
|
||||
</OL>
|
||||
</FORM></TD>
|
||||
|
Loading…
Reference in New Issue
Block a user