Add ability to manage custom fields, field edit forms still need work

This commit is contained in:
Miles Lott 2001-03-16 17:56:18 +00:00
parent a8009fde62
commit 0d60a943c9
11 changed files with 394 additions and 56 deletions

View File

@ -28,6 +28,17 @@
$this = CreateObject("phpgwapi.contacts");
// 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);
}
}
if ($AddVcard){
Header("Location: " . $phpgw->link("/addressbook/vcardin.php"));
} else if ($add_email) {
@ -98,6 +109,13 @@
}
$fields["adr_two_type"] = substr($typed,0,-1);
reset($customfields);
while (list($name,$val) = each($customfields)) {
$cust = '';
eval("if (\$name\) { \$cust \.= \$\$name; }");
if ($cust) { $fields[$name] = $cust; }
}
$fields["tz"] = $timezone;
$fields["bday"] = $bday;
$fields["url"] = $url;

View File

@ -33,6 +33,17 @@
$this = CreateObject("phpgwapi.contacts");
// 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);
}
}
if (!$submit) {
// not checking acl here, only on submit - that ok?
// merge in extra fields
@ -41,9 +52,10 @@
"address2" => "address2",
"address3" => "address3"
);
$qfields = $this->stock_contact_fields + $extrafields;
$qfields = $this->stock_contact_fields + $extrafields + $customfields;
$fields = addressbook_read_entry($ab_id,$qfields);
addressbook_form("","edit.php","Edit",$fields[0]);
addressbook_form("","edit.php","Edit",$fields[0],$customfields);
} else {
if ($url == "http://") {
$url = "";
@ -110,6 +122,13 @@
}
$fields["adr_two_type"] = substr($typed,0,-1);
reset($customfields);
while (list($name,$val) = each($customfields)) {
$cust = '';
eval("if (\$name\) { \$cust \.= \$\$name; }");
if ($cust) { $fields[$name] = $cust; }
}
$fields["tz"] = $timezone;
$fields["bday"] = $bday;
$fields["url"] = $url;

138
addressbook/field_edit.php Executable file
View File

@ -0,0 +1,138 @@
<?php
/**************************************************************************\
* phpGroupWare - Addressbook *
* http://www.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";
include("../header.inc.php");
/* if (!$id) {
header("Location: " . $phpgw->link('/addressbook/fields.php'));
$phpgw->common->phpgw_exit();
}
*/
$t = CreateObject('phpgwapi.Template',$phpgw->common->get_tpl_dir('addressbook'));
$t->set_file(array('form' => 'edit_field.tpl'));
$t->set_block('form','add','addhandle');
$t->set_block('form','edit','edithandle');
$t->set_block('form','delete','deletehandle');
$font = $phpgw_info["theme"]["font"];
$field = $phpgw->strip_html($field);
$field = ereg_replace(' ','_',$field);
$ofield = ereg_replace(' ','_',$ofield);
$t->set_var('font',$font);
$t->set_var('note',$note);
$t->set_var('lang_add',lang('Add'));
$t->set_var('lang_edit',lang('Edit'));
$t->set_var('lang_delete',lang("Delete"));
$t->set_var('deleteurl',$phpgw->link("/addressbook/field_edit.php"));
$t->set_var('actionurl',$phpgw->link("/addressbook/field_edit.php"));
$t->set_var('lang_list',lang('Field list'));
$t->set_var('listurl',$phpgw->link("/addressbook/fields.php"));
$t->set_var('lang_reset',lang('Clear Form'));
$t->set_var('edithandle','');
$t->set_var('deletehandle','');
$t->set_var('addhandle','');
switch($method) {
case "add":
if ($addfield) {
$phpgw->preferences->read_repository();
$phpgw->preferences->add("addressbook","extra_".$field);
$phpgw->preferences->save_repository(1);
$t->set_var('lang_action',lang(''));
$t->set_var('message',lang("Field has been added."));
$t->set_var('hidden_vars','');
$t->set_var('field',$field);
$t->set_var('name',"");
} else {
$t->set_var('lang_action',lang('Add a field'));
$t->set_var('message',"");
$t->set_var(
'hidden_vars',
'<input type="hidden" name="method" value="add">
<input type="hidden" name="addfield" value="Add">'
);
$t->set_var('field',$field);
$t->set_var('name',"");
}
$t->set_var('actionurl',$phpgw->link("/addressbook/field_edit.php"));
$t->set_var('lang_btn',lang('Add'));
$t->pparse('out','form');
$t->pparse('addhandle','add');
break;
case "edit":
if ($editfield && $field) {
$phpgw->preferences->read_repository();
$phpgw->preferences->delete("addressbook","extra_".$ofield);
$phpgw->preferences->add("addressbook","extra_".$field);
$phpgw->preferences->save_repository(1);
$t->set_var('lang_action',lang(''));
$t->set_var('message',lang("Field has been changed."));
$t->set_var('hidden_vars','');
$t->set_var('field',$field);
$t->set_var('name',"");
} else {
$t->set_var('lang_action',lang('Edit field'));
$t->set_var('message',"");
$t->set_var(
'hidden_vars',
'<input type="hidden" name="ofield" value="'.$ofield.'">
<input type="hidden" name="method" value="edit">
<input type="hidden" name="editfield" value="Edit">'
);
$t->set_var('field',$ofield);
$t->set_var('name','');
}
$t->set_var('lang_btn',lang('Edit'));
$t->pparse('out','form');
$t->pparse('edithandle','edit');
break;
case "delete":
if ($deletefield) {
$phpgw->preferences->read_repository();
$phpgw->preferences->delete("addressbook","extra_".$field);
$phpgw->preferences->save_repository(1);
$t->set_var('lang_action',lang(''));
$t->set_var('message',lang("Field has been deleted."));
$t->set_var('hidden_vars','');
$t->set_var('field',$field);
$t->set_var('name',"");
} else {
$t->set_var('lang_action','');
$t->set_var('message',"");
$t->set_var(
'hidden_vars',
'<input type="hidden" name="method" value="delete">
<input type="hidden" name="deletefield" value="Delete">'
);
$t->set_var('field',$field);
$t->set_var('name','');
}
$t->set_var('lang_btn',lang('Delete'));
$t->pparse('out','form');
$t->pparse('deletehandle','delete');
break;
default:
$t->set_var(
'hidden_vars',
'<input type="hidden" name="field" value="' . $field . '">'
);
$t->set_var('lang_action',lang('Add a field'));
$t->set_var('name',"");
$t->set_var('field',$field);
$t->set_var('message',"");
break;
}
$phpgw->common->phpgw_footer();
?>

80
addressbook/fields.php Normal file
View File

@ -0,0 +1,80 @@
<?php
/**************************************************************************\
* phpGroupWare - Addressbook *
* http://www.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_nextmatchs_class"] = True;
$phpgw_info["flags"]["enable_contacts_class"] = True;
include("../header.inc.php");
$this = CreateObject("phpgwapi.contacts");
$extrafields = array(
"pager" => "pager",
"mphone" => "mphone",
"ophone" => "ophone",
"address2" => "address2",
);
$qfields = $this->stock_contact_fields + $extrafields;
$phpgw->template->set_file(array(
"body" => "custom_field_list.tpl",
"row" => "custom_field_list_row.tpl"
));
$phpgw->template->set_var("message",$message);
$phpgw->template->set_var("sort_name",lang("Name"));
$phpgw->template->set_var("lang_edit",lang("Edit"));
$phpgw->template->set_var("lang_delete",lang("Delete"));
$phpgw->template->set_var("th_bg",$phpgw_info["theme"]["th_bg"]);
$phpgw->preferences->read_repository();
while (list($col,$descr) = each($phpgw_info["user"]["preferences"]["addressbook"])) {
if ( substr($col,0,6) == 'extra_' ) {
$fields[$i] = ereg_replace('extra_','',$col);
$fields[$i] = ereg_replace(' ','_',$fields[$i]);
echo "<br>".$i.": '".$fields[$i]."'";
} else {
$fields[$i] = '';
}
$i++;
}
reset($fields);
for($i=0;$i<count($fields);$i++) {
if ($fields[$i]) {
$phpgw->nextmatchs->template_alternate_row_color(&$phpgw->template);
$phpgw->template->set_var("field_name",$fields[$i]);
$phpgw->template->set_var("field_edit",'<a href="'
. $phpgw->link("/addressbook/field_edit.php","ofield="
. $fields[$i] . "&method=edit")
. '">' . lang("Edit") . '</a>');
$phpgw->template->set_var("field_delete",'<a href="'
. $phpgw->link("/addressbook/field_edit.php","field="
. $fields[$i] . "&method=delete&deletefield=delete")
. '">' . lang("Delete") . '</a>');
$phpgw->template->parse("rows","row",True);
}
}
$phpgw->template->set_var("add_field",'<a href="'
. $phpgw->link("/addressbook/field_edit.php","method=add")
. '">' . lang("Add") . '</a>');
$phpgw->template->pparse("out","row");
$phpgw->template->pparse("out","body");
$phpgw->common->phpgw_footer();
?>

View File

@ -33,34 +33,36 @@
// this cleans up the fieldnames for display
function display_name($column) {
$abc = array(
"fn" => "full name", //'firstname lastname'
"fn" => "full name",
"sound" => "",
"org_name" => "company name", //company
"org_unit" => "department", //division
"org_name" => "company name",
"org_unit" => "department",
"title" => "title",
"n_prefix" => "prefix",
"n_given" => "first name", //firstname
"n_given" => "first name",
"n_middle" => "middle name",
"n_family" => "last name", //lastname
"n_family" => "last name",
"n_suffix" => "suffix",
"label" => "label",
"adr_one_street" => "business street",
"adr_one_locality" => "business city", //city
"adr_one_region" => "business state", //state
"adr_one_postalcode" => "business zip code", //zip
"adr_one_locality" => "business city",
"adr_one_region" => "business state",
"adr_one_postalcode" => "business zip code",
"adr_one_countryname" => "business country",
"adr_one_type" => "",
"adr_two_street" => "home street",
"adr_two_locality" => "home city", //city
"adr_two_region" => "home state", //state
"adr_two_postalcode" => "home zip code", //zip
"adr_two_locality" => "home city",
"adr_two_region" => "home state",
"adr_two_postalcode" => "home zip code",
"adr_two_countryname" => "home country",
"adr_two_type" => "",
"tz" => "time zone",
"geo" => "geo",
"tel_work" => "business phone", //yn
"tel_home" => "home phone", //yn
"tel_voice" => "voice phone", //yn
"tel_msg" => "message phone", //yn
"tel_fax" => "fax", //yn
"tel_work" => "business phone",
"tel_home" => "home phone",
"tel_voice" => "voice phone",
"tel_msg" => "message phone",
"tel_fax" => "fax",
"tel_pager" => "pager",
"tel_cell" => "mobile phone",
"tel_bbs" => "bbs phone",
@ -69,10 +71,10 @@
"tel_car" => "car phone",
"tel_video" => "video phone",
"tel_prefer" => "prefer", //yn
"tel_prefer" => "prefer",
"email" => "business email",
"email_type" => "business email type", //'INTERNET','CompuServe',etc...
"email_home" => "home email", //yn
"email_type" => "business email type",
"email_home" => "home email",
"email_home_type" => "home email type",
"address2" => "address line 2",
"address3" => "address line 3",
@ -128,7 +130,8 @@
return;
}
function addressbook_form($format,$action,$title="",$fields="") { // used for add/edit
// Folowing used for add/edit
function addressbook_form($format,$action,$title="",$fields="",$customfields="") {
global $phpgw, $phpgw_info;
$t = new Template($phpgw->common->get_tpl_dir("addressbook"));
@ -187,6 +190,22 @@
$url = $fields["url"];
$pubkey = $fields["pubkey"];
if ($customfields) {
while(list($name,$value) = each($customfields)) {
$custom .= '
<tr>
<td></td>
<td><font color="#000000" face="" size="-1">'.$value.':</font></td>
<td>
<font size="-1">
<INPUT name="' . $name . '" value="' . $fields[$name] . '">
</font></td>
</td>
</tr>
';
}
}
$this = CreateObject("phpgwapi.contacts");
if ($format != "view") {
@ -445,6 +464,13 @@
$t->set_var("lang_pubkey",lang("Public Key"));
$t->set_var("pubkey",$pubkey);
if ($customfields) {
$t->set_var("lang_custom",lang("Custom Fields").':');
} else {
$t->set_var("lang_custom",'');
}
$t->set_var("custom",$custom);
$t->parse("out","form");
$t->pparse("out","form");
} //end form function

View File

@ -30,11 +30,11 @@
echo '<a href="' . $phpgw->link('/addressbook/preferences.php') . '">'
. lang('Addressbook preferences') . '</a><br>';
echo '<a href="' . $phpgw->link('/addressbook/fields.php') . '">'
. lang('Edit custom fields (NOT WORKING)') . '</a><br>';
echo '<a href="' . $phpgw->link('/addressbook/acl_preferences.php') . '">'
. lang('Grant Addressbook Access') . '</a>';
. lang('Grant Addressbook Access') . '</a><br>';
echo '<a href="' . $phpgw->link('/addressbook/fields.php') . '">'
. lang('Edit custom fields') . '</a>';
section_end();
}

View File

@ -28,18 +28,33 @@
"addressbook_footer" => "footer.tpl" ));
$this = CreateObject("phpgwapi.contacts");
// 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"
);
$qfields = $this->stock_contact_fields + $extrafields;
$qfields = $this->stock_contact_fields + $extrafields + $customfields;
// create column list and the top row of the table based on user prefs
while ($column = each($qfields)) {
if (isset($phpgw_info["user"]["preferences"]["addressbook"][$column[1]]) &&
$phpgw_info["user"]["preferences"]["addressbook"][$column[1]]) {
$test = strtolower($column[1]);
if (isset($phpgw_info["user"]["preferences"]["addressbook"][$test]) &&
$phpgw_info["user"]["preferences"]["addressbook"][$test]) {
$showcol = display_name($column[0]);
// This must be a custom field
if (!$showcol) { $showcol = $column[1]; }
$cols .= " <td height=\"21\">\n";
$cols .= ' <font size="-1" face="Arial, Helvetica, sans-serif">';
$cols .= $phpgw->nextmatchs->show_sort_order($sort, $column[0],$order,"/addressbook/index.php",$showcol);
@ -78,10 +93,12 @@
"n_family" => "n_family",
"org_name" => "org_name"
);
$columns_to_display = $columns_to_display + $customfields;
// No prefs,. so cols above may have been set to "" or a bunch of <td></td>
$cols="";
while ($column = each($columns_to_display)) {
$showcol = display_name($column[0]);
if (!$showcol) { $showcol = $column[1]; }
$cols .= " <td height=\"21\">\n";
$cols .= ' <font size="-1" face="Arial, Helvetica, sans-serif">';
$cols .= $phpgw->nextmatchs->show_sort_order($sort, $column[0],$order,"/addressbook/index.php",$showcol);

View File

@ -15,7 +15,7 @@
"noheader" => True,
"nonavbar" => True,
"currentapp" => "addressbook",
"enable_addressbook_class" => True,
"enable_contacts_class" => True,
"enable_nextmatchs_class" => True
);
@ -29,7 +29,18 @@
"address3" => "address3"
);
$qfields = $this->stock_contact_fields + $extrafields;
$phpgw->preferences->read_repository();
$customfields = array();
if ($phpgw_info["user"]["preferences"]["addressbook"]) {
while (list($col,$descr) = each($phpgw_info["user"]["preferences"]["addressbook"])) {
if ( substr($col,0,6) == 'extra_' ) {
$field = ereg_replace('extra_','',$col);
$customfields[$field] = ucfirst($field);
}
}
}
$qfields = $this->stock_contact_fields + $extrafields + $customfields;
if ($submit) {
$totalerrors = 0;
@ -80,6 +91,7 @@
// echo "<br>test: $col - $i $j - " . count($abc);
$i++; $j++;
$showcol = display_name($descr);
if (!$showcol) { $showcol = $descr; }
// yank the *'s prior to testing for a valid column description
$coltest = ereg_replace("\*","",$showcol);
if ($coltest) {

View File

@ -0,0 +1,17 @@
<center>{message}</center><p>
<table border="0" align="center" width="60%">
<tr bgcolor="{th_bg}">
<td>{sort_name}</td>
<td width="5%">{lang_edit}</td>
<td width="5%">{lang_delete}</td>
</tr>
{rows}
<tr>
<td colspan="3" align="left">
&nbsp;{add_field}
</td>
</tr>
</table>

View File

@ -0,0 +1,5 @@
<tr bgcolor="{tr_color}">
<td>{field_name}&nbsp;</td>
<td>{field_edit}</td>
<td>{field_delete}</td>
</tr>

View File

@ -336,5 +336,11 @@
{notes}
</font></td>
</tr>
<tr>
<td><font color="#000000" face="" size="-1">{lang_custom}</font></td>
<td></td>
<td></td>
</tr>
{custom}
</table>
<!-- END addressbook entry form -->