From 0d60a943c9420c7eef66c8241bdfae54960244c7 Mon Sep 17 00:00:00 2001 From: Miles Lott Date: Fri, 16 Mar 2001 17:56:18 +0000 Subject: [PATCH] Add ability to manage custom fields, field edit forms still need work --- addressbook/add.php | 20 ++- addressbook/edit.php | 23 ++- addressbook/field_edit.php | 138 ++++++++++++++++++ addressbook/fields.php | 80 ++++++++++ addressbook/inc/functions.inc.php | 114 +++++++++------ addressbook/inc/hook_preferences.inc.php | 8 +- addressbook/index.php | 23 ++- addressbook/preferences.php | 16 +- .../templates/default/custom_field_list.tpl | 17 +++ .../default/custom_field_list_row.tpl | 5 + addressbook/templates/default/form.tpl | 6 + 11 files changed, 394 insertions(+), 56 deletions(-) create mode 100755 addressbook/field_edit.php create mode 100644 addressbook/fields.php create mode 100644 addressbook/templates/default/custom_field_list.tpl create mode 100644 addressbook/templates/default/custom_field_list_row.tpl diff --git a/addressbook/add.php b/addressbook/add.php index 12c0b286b7..0c45ecfaca 100755 --- a/addressbook/add.php +++ b/addressbook/add.php @@ -27,7 +27,18 @@ $t->set_file(array("add" => "add.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); + } + } + 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; diff --git a/addressbook/edit.php b/addressbook/edit.php index 9aa6c718f3..91a898bb77 100755 --- a/addressbook/edit.php +++ b/addressbook/edit.php @@ -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; diff --git a/addressbook/field_edit.php b/addressbook/field_edit.php new file mode 100755 index 0000000000..3586b4dac9 --- /dev/null +++ b/addressbook/field_edit.php @@ -0,0 +1,138 @@ +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', + ' + ' + ); + $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', + ' + + ' + ); + $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', + ' + ' + ); + $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', + '' + ); + $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(); +?> diff --git a/addressbook/fields.php b/addressbook/fields.php new file mode 100644 index 0000000000..36c1c706b8 --- /dev/null +++ b/addressbook/fields.php @@ -0,0 +1,80 @@ + "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 "
".$i.": '".$fields[$i]."'"; + } else { + $fields[$i] = ''; + } + $i++; + } + + reset($fields); + for($i=0;$inextmatchs->template_alternate_row_color(&$phpgw->template); + + $phpgw->template->set_var("field_name",$fields[$i]); + + $phpgw->template->set_var("field_edit",'' . lang("Edit") . ''); + + $phpgw->template->set_var("field_delete",'' . lang("Delete") . ''); + + $phpgw->template->parse("rows","row",True); + } + } + + $phpgw->template->set_var("add_field",'' . lang("Add") . ''); + + $phpgw->template->pparse("out","row"); + $phpgw->template->pparse("out","body"); + $phpgw->common->phpgw_footer(); +?> diff --git a/addressbook/inc/functions.inc.php b/addressbook/inc/functions.inc.php index 7683f34c50..c6bd28c8f2 100755 --- a/addressbook/inc/functions.inc.php +++ b/addressbook/inc/functions.inc.php @@ -33,53 +33,55 @@ // this cleans up the fieldnames for display function display_name($column) { $abc = array( - "fn" => "full name", //'firstname lastname' - "sound" => "", - "org_name" => "company name", //company - "org_unit" => "department", //division - "title" => "title", - "n_prefix" => "prefix", - "n_given" => "first name", //firstname - "n_middle" => "middle name", - "n_family" => "last name", //lastname - "n_suffix" => "suffix", + "fn" => "full name", + "sound" => "", + "org_name" => "company name", + "org_unit" => "department", + "title" => "title", + "n_prefix" => "prefix", + "n_given" => "first name", + "n_middle" => "middle name", + "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", - "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_pager" => "pager", - "tel_cell" => "mobile phone", - "tel_bbs" => "bbs phone", - "tel_modem" => "modem phone", - "tel_isdn" => "isdn phone", - "tel_car" => "car phone", - "tel_video" => "video phone", + "adr_two_type" => "", + "tz" => "time zone", + "geo" => "geo", + "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", + "tel_modem" => "modem phone", + "tel_isdn" => "isdn phone", + "tel_car" => "car phone", + "tel_video" => "video phone", - "tel_prefer" => "prefer", //yn - "email" => "business email", - "email_type" => "business email type", //'INTERNET','CompuServe',etc... - "email_home" => "home email", //yn - "email_home_type" => "home email type", - "address2" => "address line 2", - "address3" => "address line 3", - "bday" => "birthday", - "url" => "url", - "pubkey" => "public key", - "note" => "notes" + "tel_prefer" => "prefer", + "email" => "business email", + "email_type" => "business email type", + "email_home" => "home email", + "email_home_type" => "home email type", + "address2" => "address line 2", + "address3" => "address line 3", + "bday" => "birthday", + "url" => "url", + "pubkey" => "public key", + "note" => "notes" ); while($name = each($abc) ) { @@ -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 .= ' + + + '.$value.': + + + + + + +'; + } + } + $this = CreateObject("phpgwapi.contacts"); if ($format != "view") { @@ -419,7 +438,7 @@ $t->set_var("bcountry",$bcountry); $t->set_var("lang_badrtype",lang("Address Type")); $t->set_var("badrtype",$badrtype); - + $t->set_var("lang_hphone",lang("Home Phone")); $t->set_var("hphone",$hphone); $t->set_var("lang_hemail",lang("Home Email")); @@ -444,7 +463,14 @@ $t->set_var("notes",$notes); $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 diff --git a/addressbook/inc/hook_preferences.inc.php b/addressbook/inc/hook_preferences.inc.php index 37d1a81ccd..28bdd04246 100644 --- a/addressbook/inc/hook_preferences.inc.php +++ b/addressbook/inc/hook_preferences.inc.php @@ -30,11 +30,11 @@ echo '' . lang('Addressbook preferences') . '
'; - echo '' - . lang('Edit custom fields (NOT WORKING)') . '
'; - echo '' - . lang('Grant Addressbook Access') . ''; + . lang('Grant Addressbook Access') . '
'; + + echo '' + . lang('Edit custom fields') . ''; section_end(); } diff --git a/addressbook/index.php b/addressbook/index.php index 9719d5e499..47a2da39de 100755 --- a/addressbook/index.php +++ b/addressbook/index.php @@ -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 .= " \n"; $cols .= ' '; $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 $cols=""; while ($column = each($columns_to_display)) { $showcol = display_name($column[0]); + if (!$showcol) { $showcol = $column[1]; } $cols .= " \n"; $cols .= ' '; $cols .= $phpgw->nextmatchs->show_sort_order($sort, $column[0],$order,"/addressbook/index.php",$showcol); diff --git a/addressbook/preferences.php b/addressbook/preferences.php index 2ae5564e3b..324215dcea 100644 --- a/addressbook/preferences.php +++ b/addressbook/preferences.php @@ -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 "
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) { diff --git a/addressbook/templates/default/custom_field_list.tpl b/addressbook/templates/default/custom_field_list.tpl new file mode 100644 index 0000000000..9be103d91f --- /dev/null +++ b/addressbook/templates/default/custom_field_list.tpl @@ -0,0 +1,17 @@ + +
{message}

+ + + + + + + + {rows} + + + + +
{sort_name}{lang_edit}{lang_delete}
+  {add_field} +
diff --git a/addressbook/templates/default/custom_field_list_row.tpl b/addressbook/templates/default/custom_field_list_row.tpl new file mode 100644 index 0000000000..e09e798910 --- /dev/null +++ b/addressbook/templates/default/custom_field_list_row.tpl @@ -0,0 +1,5 @@ + + {field_name}  + {field_edit} + {field_delete} + diff --git a/addressbook/templates/default/form.tpl b/addressbook/templates/default/form.tpl index 85f73cfa6b..d678882de4 100755 --- a/addressbook/templates/default/form.tpl +++ b/addressbook/templates/default/form.tpl @@ -336,5 +336,11 @@ {notes}
+ + {lang_custom} + + + +{custom}