From 4da6635a51d1473cc3bc937d33abbb4a13b0cd06 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Wed, 19 Nov 2014 21:15:48 +0000 Subject: [PATCH] Fix missing infolog custom types --- admin/inc/class.customfields.inc.php | 15 ++++-- .../inc/class.infolog_customfields.inc.php | 47 ++++++++++++------- 2 files changed, 41 insertions(+), 21 deletions(-) diff --git a/admin/inc/class.customfields.inc.php b/admin/inc/class.customfields.inc.php index 8d51cc4ca6..2168118bdf 100644 --- a/admin/inc/class.customfields.inc.php +++ b/admin/inc/class.customfields.inc.php @@ -113,7 +113,7 @@ class customfields $this->content_types = (array)egw_link::get_registry($this->appname,'default_types'); } // Set this now, we need to know it for updates - $this->content_type = $content['content_types']['types']; + $this->content_type = $content['content_types']['types'] ? $content['content_types']['types'] : (array_key_exists(0,$this->content_types) ? $this->content_types[0] : key($this->content_types)); // Common type changes - add, delete if($content['content_types']['delete']) @@ -122,7 +122,11 @@ class customfields } elseif($content['content_types']['create']) { - $content['content_types']['types'] = $this->create_content_type($content); + if($new_type = $this->create_content_type($content)) + { + $content['content_types']['types'] = $this->content_type = $new_type; + } + unset($content['content_types']['create']); unset($content['content_types']['name']); } // No common type change and type didn't change, try an update @@ -181,7 +185,6 @@ class customfields $content['type_template'] = $this->appname . '.admin.types'; $content['content_types']['appname'] = $this->appname; $content_types = array_keys($this->content_types); - $this->content_type = $content['content_types']['types'] ? $content['content_types']['types'] : $content_types[0]; $content['content_type_options'] = $this->content_types[$this->content_type]['options']; $content['content_type_options']['type'] = $this->types2[$this->content_type]; @@ -535,6 +538,12 @@ class customfields } } + /** + * Validate and create a new content type + * + * @param array $content + * @return string|boolean New type ID, or false for error + */ function create_content_type(&$content) { $new_name = trim($content['content_types']['name']); diff --git a/infolog/inc/class.infolog_customfields.inc.php b/infolog/inc/class.infolog_customfields.inc.php index e5e1a2be62..23c07e692d 100644 --- a/infolog/inc/class.infolog_customfields.inc.php +++ b/infolog/inc/class.infolog_customfields.inc.php @@ -71,6 +71,11 @@ class infolog_customfields extends customfields } $readonlys['content_type_options']['status']["create$name"] = True; } + $content['content_type_options']['status'][++$n] = array( + 'name' => '', + 'label' => '', + 'disabled' => False + ); $content['content_type_options']['status']['default'] = $this->status['defaults'][$this->content_type]; $content['content_type_options']['group_owner'] = $this->group_owners[$this->content_type]; $readonlys['content_types']['delete'] = isset($this->bo->stock_enums['type'][$this->content_type]); @@ -250,31 +255,37 @@ class infolog_customfields extends customfields $this->save_repository(); } - function create(&$content) + function create_content_type(&$content) { - $new_name = trim($content['new_name']); - unset($content['new_name']); - if (empty($new_name) || isset($this->content_types[$new_name])) + $new_name = trim($content['content_types']['name']); + if (empty($new_name)) { - $content['error_msg'] .= empty($new_name) ? - lang('You have to enter a name, to create a new typ!!!') : - lang("Typ '%1' already exists !!!",$new_name); + $this->tmpl->set_validation_error('content_types[name]','You have to enter a name, to create a new type!!!'); + return false; } else { - $this->content_types[$new_name] = $new_name; - $this->status[$new_name] = array( - 'ongoing' => 'ongoing', - 'done' => 'done' - ); - $this->status['defaults'][$new_name] = 'ongoing'; - - // save changes to repository - $this->save_repository(); - - $content['type2'] = $new_name; // show the new entry + foreach($this->content_types as $letter => $name) + { + if($name == $new_name) + { + $this->tmpl->set_validation_error('content_types[name]',lang("type '%1' already exists !!!",$new_name)); + return false; + } + } } + $this->content_types[$new_name] = $new_name; + $this->status[$new_name] = array( + 'ongoing' => 'ongoing', + 'done' => 'done' + ); + $this->status['defaults'][$new_name] = 'ongoing'; + + // save changes to repository + $this->save_repository(); + return $new_name; } + function save_repository() { // save changes to repository