From 300b9b10702d2ddf008eb49e7281896f280f62a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cornelius=20Wei=C3=9F?= Date: Tue, 14 Mar 2006 13:54:17 +0000 Subject: [PATCH] addressbook extension: Admin can now define multiple addressbooks each with an own edit / view template and an own icon. Atm. all Addressbooks are stored in one backend, but this will change soon^tm --- admin/inc/class.customfields.inc.php | 146 ++++++++++++++---- admin/setup/etemplates.inc.php | 13 +- .../inc/class.customfields_widget.inc.php | 9 +- etemplate/inc/class.editor.inc.php | 2 +- etemplate/inc/class.select_widget.inc.php | 12 +- etemplate/inc/class.uietemplate.inc.php | 10 +- phpgwapi/inc/class.bolink.inc.php | 2 +- phpgwapi/inc/class.contacts_sql.inc.php | 20 ++- 8 files changed, 163 insertions(+), 51 deletions(-) diff --git a/admin/inc/class.customfields.inc.php b/admin/inc/class.customfields.inc.php index e2267c5758..aeb8497ee5 100644 --- a/admin/inc/class.customfields.inc.php +++ b/admin/inc/class.customfields.inc.php @@ -30,9 +30,9 @@ var $appname; /** - * @var array $types array with allowd types of customfields + * @var array $cf_types array with allowd types of customfields */ - var $types = array( + var $cf_types = array( 'text' => 'Text', 'label' => 'Label', 'select' => 'Selectbox', @@ -52,10 +52,9 @@ function customfields($appname='') { - $this->appname = $appname ? $appname : $_GET['appname']; - $this->tmpl =& CreateObject('etemplate.etemplate'); +// $this->tmpl =& CreateObject('etemplate.etemplate'); $this->config =& CreateObject('phpgwapi.config',$this->appname); - +// if($this->tmpl->read($this->appname.'.admin.types')) {$this->manage_content_types = true; echo 'tt';} $GLOBALS['egw']->translation->add_app('infolog'); // til we move the translations } @@ -67,24 +66,38 @@ */ function edit($content = null) { + // determine appname + $this->appname = $_GET['appname'] ? $_GET['appname'] : ($content['appname'] ? $content['appname'] : false); + if(!$this->appname) die(lang('Error! No appname found')); + + $GLOBALS['egw']->translation->add_app('infolog'); // til we move the translations + $this->tmpl =& CreateObject('etemplate.etemplate'); + $this->config =& CreateObject('phpgwapi.config',$this->appname); + // do we manage content-types? + if($this->tmpl->read($this->appname.'.admin.types')) $this->manage_content_types = true; + + $this->fields = $this->get_customfields(); + $this->tmpl->read('admin.customfields'); + + if($this->manage_content_types) $this->content_types = $this->get_content_types(); + else + { + $this->tmpl->children[0]['data'][2]['A']['disabled'] = true; + $this->tmpl->children[0]['data'][3]['A']['disabled'] = true; + } + if (is_array($content)) { - // setting our app again - $this->config->config($this->appname = $content['appname']); - $this->fields = $this->get_customfields(); - //echo '
'; print_r($content); echo "
\n"; - if($content['fields']['delete'] || $content['fields']['create']) + if($this->manage_content_types) { - if($content['fields']['delete']) - { - $this->delete($content); - } - elseif($content['fields']['create']) - { - $this->create($content); - } + $this->content_type = $content['content_types']['types']; } + + if($content['content_types']['delete']) $this->delete_content_type($content); + elseif($content['content_types']['create']) $this->create_content_type($content); + elseif($content['fields']['delete']) $this->delete_field($content); + elseif($content['fields']['create']) $this->create_field($content); else { list($action) = @each($content['button']); @@ -111,18 +124,35 @@ } else { - $this->fields = $this->get_customfields(); + if($this->manage_content_types) + { + $content_types = array_keys($this->content_types); + $this->content_type = $content_types[0]; + } - list($type) = each($this->types); - $content = array( - 'type' => $type, - ); $referer = $GLOBALS['egw']->common->get_referer(); } $GLOBALS['egw_info']['flags']['app_header'] = $GLOBALS['egw_info']['apps'][$this->appname]['title'].' - '.lang('Custom fields'); - $readonlys = array(); - + + if($this->manage_content_types) + { + $content['content_types']['app-name'] = $this->appname; + foreach($this->content_types as $type => $entry) + { + $this->types2[$type] = $entry['name']; + } + $content['content_types']['options-types'] = $this->types2; + $this->tmpl->children[0]['data'][3]['A']['name'] = $this->appname.'.admin.types'; + $this->tmpl->children[0]['data'][3]['A']['size'] = 'content_type_options'; + $content['content_type_options'] = $this->content_types[$this->content_type]['options']; + $content['content_type_options']['type'] = $this->content_types[$this->content_type]['name']; + if ($this->content_types[$this->content_type]['non_deletable']) + { + $content['content_types']['non_deletable'] = true; + } + } + //echo 'customfields=
'; print_r($this->fields); echo "
\n"; $content['fields'] = array(); $n = 0; @@ -150,13 +180,13 @@ $readonlys['fields']["create$name"] = True; } $content['fields'][++$n] = array('name'=>'','order' => 10 * $n); // new line for create + if($this->manage_content_types) $content['fields']['type2'] = 'enable'; $readonlys['fields']["delete[]"] = True; //echo '

uicustomfields.edit(content =

'; print_r($content); echo "
\n"; //echo 'readonlys =
'; print_r($readonlys); echo "
\n"; - $this->tmpl->read('admin.customfields'); $this->tmpl->exec('admin.customfields.edit',$content,array( - 'type' => $this->types, - 'type2' => $this->types2, + 'type' => $this->cf_types, + 'type2' => $this->types2 + array('tmpl' => 'template'), ),$readonlys,array( 'fields' => $preserv_fields, 'appname' => $this->appname, @@ -212,6 +242,10 @@ 'rows' => intval($field['rows']), 'order' => intval($field['order']) ); + if(!$this->fields[$name]['type2'] && $this->manage_content_types) + { + $this->fields[$name]['type2'] = (string)0; + } } if (!function_exists('sort_by_order')) { @@ -233,6 +267,7 @@ function update(&$content) { $this->update_fields($content); + $this->content_types[$this->content_type]['options'] = $content['content_type_options']; // save changes to repository $this->save_repository(); } @@ -240,18 +275,24 @@ /** * deletes custom field from customfield definitions */ - function delete(&$content) + function delete_field(&$content) { unset($this->fields[key($content['fields']['delete'])]); - // save changes to repository $this->save_repository(); } - + + function delete_content_type(&$content) + { + unset($this->content_types[$content['content_types']['types']]); + // save changes to repository + $this->save_repository(); + } + /** * create a new custom field */ - function create(&$content) + function create_field(&$content) { $new_name = trim($content['fields'][count($content['fields'])-1]['name']); if (empty($new_name) || isset($this->fields[$new_name])) @@ -267,6 +308,31 @@ $this->save_repository(); } } + + function create_content_type(&$content) + { + $new_name = trim($content['content_types']['name']); + if (empty($new_name) || isset($this->fields[$new_name])) + { + $content['error_msg'] .= empty($new_name) ? + lang('You have to enter a name, to create a new type!!!') : + lang("type '%1' already exists !!!",$new_name); + } + else + { + // search free type character + for($i=97;$i<=122;$i++) + { + if(!$this->content_types[chr($i)]) + { + $new_type = chr($i); + break; + } + } + $this->content_types[$new_type] = array('name' => $new_name); + $this->save_repository(); + } + } /** * save changes to repository @@ -275,7 +341,7 @@ { //echo '

uicustomfields::save_repository() \$this->fields=

'; print_r($this->fields); echo "
\n"; $this->config->value('customfields',$this->fields); - + $this->config->value('types',$this->content_types); $this->config->save_repository(); } @@ -293,4 +359,18 @@ return is_array($config[$config_name]) ? $config[$config_name] : array(); } + + /** + * get_content_types of using application + * + * @author Cornelius Weiss + * @return array with content-types + */ + function get_content_types() + { + $config = $this->config->read_repository(); + + return is_array($config['types']) ? $config['types'] : array(); + } + } diff --git a/admin/setup/etemplates.inc.php b/admin/setup/etemplates.inc.php index 2520faae46..8ed3b87321 100644 --- a/admin/setup/etemplates.inc.php +++ b/admin/setup/etemplates.inc.php @@ -1,11 +1,18 @@ 'admin.customfields','template' => '','lang' => '','group' => '0','version' => '1.2','data' => 'a:1:{i:0;a:4:{s:4:"type";s:4:"grid";s:4:"data";a:4:{i:0;a:1:{s:1:"F";s:3:"80%";}i:1;a:6:{s:1:"A";a:5:{s:4:"type";s:5:"label";s:4:"span";s:13:"all,redItalic";s:4:"name";s:9:"error_msg";s:5:"align";s:6:"center";s:7:"no_lang";s:1:"1";}s:1:"B";a:1:{s:4:"type";s:5:"label";}s:1:"C";a:1:{s:4:"type";s:5:"label";}s:1:"D";a:1:{s:4:"type";s:5:"label";}s:1:"E";a:1:{s:4:"type";s:5:"label";}s:1:"F";a:2:{s:4:"type";s:5:"label";s:7:"no_lang";s:1:"1";}}i:2;a:6:{s:1:"A";a:4:{s:4:"type";s:8:"template";s:4:"size";s:6:"fields";s:4:"span";s:3:"all";s:4:"name";s:25:"admin.customfields.fields";}s:1:"B";a:1:{s:4:"type";s:5:"label";}s:1:"C";a:1:{s:4:"type";s:5:"label";}s:1:"D";a:1:{s:4:"type";s:5:"label";}s:1:"E";a:1:{s:4:"type";s:5:"label";}s:1:"F";a:1:{s:4:"type";s:5:"label";}}i:3;a:6:{s:1:"A";a:6:{s:4:"type";s:4:"hbox";s:4:"size";s:1:"3";s:4:"span";s:3:"all";i:1;a:4:{s:4:"type";s:6:"button";s:5:"label";s:4:"Save";s:4:"name";s:12:"button[save]";s:4:"help";s:33:"saves the changes made and leaves";}i:2;a:4:{s:4:"type";s:6:"button";s:5:"label";s:5:"Apply";s:4:"name";s:13:"button[apply]";s:4:"help";s:19:"applies the changes";}i:3;a:4:{s:4:"type";s:6:"button";s:5:"label";s:6:"Cancel";s:4:"name";s:14:"button[cancel]";s:4:"help";s:22:"leaves without saveing";}}s:1:"B";a:1:{s:4:"type";s:5:"label";}s:1:"C";a:1:{s:4:"type";s:5:"label";}s:1:"D";a:1:{s:4:"type";s:5:"label";}s:1:"E";a:1:{s:4:"type";s:5:"label";}s:1:"F";a:1:{s:4:"type";s:5:"label";}}}s:4:"rows";i:3;s:4:"cols";i:6;}}','size' => '','style' => '.redItalic { color: red; font-style: italics; }','modified' => '1131453292',); +$templ_data[] = array('name' => 'admin.customfields','template' => '','lang' => '','group' => '0','version' => '','data' => 'a:1:{i:0;a:4:{s:4:"type";s:4:"grid";s:4:"data";a:5:{i:0;a:2:{s:1:"F";s:3:"80%";s:2:"c2";s:6:"header";}i:1;a:6:{s:1:"A";a:3:{s:4:"type";s:5:"label";s:4:"span";s:13:"all,redItalic";s:4:"name";s:9:"error_msg";}s:1:"B";a:1:{s:4:"type";s:5:"label";}s:1:"C";a:1:{s:4:"type";s:5:"label";}s:1:"D";a:1:{s:4:"type";s:5:"label";}s:1:"E";a:1:{s:4:"type";s:5:"label";}s:1:"F";a:2:{s:4:"type";s:5:"label";s:7:"no_lang";s:1:"1";}}i:2;a:6:{s:1:"A";a:3:{s:4:"type";s:5:"label";s:4:"span";s:3:"all";s:5:"label";s:13:"Custom fields";}s:1:"B";a:1:{s:4:"type";s:5:"label";}s:1:"C";a:1:{s:4:"type";s:5:"label";}s:1:"D";a:1:{s:4:"type";s:5:"label";}s:1:"E";a:1:{s:4:"type";s:5:"label";}s:1:"F";a:1:{s:4:"type";s:5:"label";}}i:3;a:6:{s:1:"A";a:4:{s:4:"type";s:8:"template";s:4:"size";s:6:"fields";s:4:"span";s:3:"all";s:4:"name";s:25:"admin.customfields.fields";}s:1:"B";a:1:{s:4:"type";s:5:"label";}s:1:"C";a:1:{s:4:"type";s:5:"label";}s:1:"D";a:1:{s:4:"type";s:5:"label";}s:1:"E";a:1:{s:4:"type";s:5:"label";}s:1:"F";a:1:{s:4:"type";s:5:"label";}}i:4;a:6:{s:1:"A";a:6:{s:4:"type";s:4:"hbox";s:4:"size";s:1:"3";s:4:"span";s:3:"all";i:1;a:4:{s:4:"type";s:6:"button";s:5:"label";s:4:"Save";s:4:"name";s:12:"button[save]";s:4:"help";s:33:"saves the changes made and leaves";}i:2;a:4:{s:4:"type";s:6:"button";s:5:"label";s:5:"Apply";s:4:"name";s:13:"button[apply]";s:4:"help";s:19:"applies the changes";}i:3;a:4:{s:4:"type";s:6:"button";s:5:"label";s:6:"Cancel";s:4:"name";s:14:"button[cancel]";s:4:"help";s:22:"leaves without saveing";}}s:1:"B";a:1:{s:4:"type";s:5:"label";}s:1:"C";a:1:{s:4:"type";s:5:"label";}s:1:"D";a:1:{s:4:"type";s:5:"label";}s:1:"E";a:1:{s:4:"type";s:5:"label";}s:1:"F";a:1:{s:4:"type";s:5:"label";}}}s:4:"rows";i:4;s:4:"cols";i:6;}}','size' => '','style' => '.header { font-weight: bold; font-size: 120%; } +.error_msg { color: red; font-style: italics; }','modified' => '1130271259',); -$templ_data[] = array('name' => 'admin.customfields.fields','template' => '','lang' => '','group' => '0','version' => '1.2','data' => 'a:1:{i:0;a:5:{s:4:"type";s:4:"grid";s:4:"data";a:3:{i:0;a:3:{s:2:"c1";s:2:"th";s:2:"c2";s:7:"row,top";s:1:"C";s:8:",!@type2";}i:1;a:8:{s:1:"A";a:3:{s:4:"type";s:5:"label";s:5:"label";s:4:"Name";s:4:"help";s:83:"the name used internaly (<= 20 chars), changeing it makes existing data unavailible";}s:1:"B";a:2:{s:4:"type";s:5:"label";s:5:"label";s:5:"Label";}s:1:"C";a:2:{s:4:"type";s:5:"label";s:5:"label";s:7:"Subtype";}s:1:"D";a:2:{s:4:"type";s:5:"label";s:5:"label";s:4:"Type";}s:1:"E";a:3:{s:4:"type";s:5:"label";s:5:"label";s:7:"Options";s:4:"help";s:40:"each value is a line like [=