From dea0ac49a908d3c382dcf66c5dd5dfa8988935ec Mon Sep 17 00:00:00 2001 From: bettina Date: Fri, 11 May 2001 20:14:28 +0000 Subject: [PATCH] update categories --- preferences/addcategory.php | 93 +++++++++++++++++++++++----------- preferences/deletecategory.php | 77 ++++++++++++++++------------ preferences/editcategory.php | 16 +++--- 3 files changed, 116 insertions(+), 70 deletions(-) diff --git a/preferences/addcategory.php b/preferences/addcategory.php index 325b40a6af..1b69b5f55f 100644 --- a/preferences/addcategory.php +++ b/preferences/addcategory.php @@ -37,39 +37,72 @@ $c = CreateObject('phpgwapi.categories'); $c->app_name = $cats_app; - if ($submit) + if ($submit) + { + $errorcount = 0; + + if (!$cat_name) { - $errorcount = 0; - - if (!$cat_name) { $error[$errorcount++] = lang('Please enter a name for that category !'); } - - if (!$error) - { - if (!$cat_parent) { $exists = $c->exists('mains',$cat_name,$cat_id=''); } - else { $exists = $c->exists('subs',$cat_name,$cat_id=''); } - if ($exists == True) { $error[$errorcount++] = lang('That category name has been used already !'); } - } - - if ($cat_main && $cat_parent) - { - $main = $c->return_main($cat_parent); - if ($main != $cat_main) { $error[$errorcount++] = lang('You selected an invalid main category !'); } - } - - if (!$error) - { - $cat_name = addslashes($cat_name); - $cat_description = addslashes($cat_description); - if ($access) { $cat_access = 'private'; } - else { $cat_access = 'public'; } - - $c->add($cat_name,$cat_parent,$cat_description,$cat_data,$cat_access,$cat_main); - } + $error[$errorcount++] = lang('Please enter a name for that category !'); } - if ($errorcount) { $t->set_var('message',$phpgw->common->error_list($error)); } - if (($submit) && (! $error) && (! $errorcount)) { $t->set_var('message',lang('Category x has been added !',$cat_name)); } - if ((! $submit) && (! $error) && (! $errorcount)) { $t->set_var('message',''); } + if (!$error) + { + if (!$cat_parent) + { + $exists = $c->exists('appandmains',$cat_name,$cat_id=''); + } + else + { + $exists = $c->exists('appandsubs',$cat_name,$cat_id=''); + } + + if ($exists == True) + { + $error[$errorcount++] = lang('That category name has been used already !'); + } + } + + if ($cat_main && $cat_parent) + { + $main = $c->return_main($cat_parent); + if ($main != $cat_main) + { + $error[$errorcount++] = lang('You selected an invalid main category !'); + } + } + + if (!$error) + { + $cat_name = addslashes($cat_name); + $cat_description = addslashes($cat_description); + if ($access) + { + $cat_access = 'private'; + } + else + { + $cat_access = 'public'; + } + + $c->add($cat_name,$cat_parent,$cat_description,$cat_data,$cat_access,$cat_main); + } + } + + if ($errorcount) + { + $t->set_var('message',$phpgw->common->error_list($error)); + } + + if (($submit) && (! $error) && (! $errorcount)) + { + $t->set_var('message',lang('Category x has been added !',$cat_name)); + } + + if ((! $submit) && (! $error) && (! $errorcount)) + { + $t->set_var('message',''); + } $t->set_var('actionurl',$phpgw->link('/preferences/addcategory.php')); $t->set_var('title_categories',lang('Add x category for',$cats_app)); diff --git a/preferences/deletecategory.php b/preferences/deletecategory.php index 11b4544d0d..843516c599 100644 --- a/preferences/deletecategory.php +++ b/preferences/deletecategory.php @@ -11,9 +11,15 @@ \**************************************************************************/ /* $Id$ */ - if ($confirm) { - $phpgw_info["flags"] = array('noheader' => True, - 'nonavbar' => True); + if (! $cat_id) + { + Header('Location: ' . $phpgw->link('/preferences/categories.php',"cats_app=$cats_app&extra=$extra&cats_level=$cats_level&global_cats=$global_cats")); + } + + if ($confirm) + { + $phpgw_info['flags'] = array('noheader' => True, + 'nonavbar' => True); } $phpgw_info['flags']['currentapp'] = $cats_app; @@ -25,45 +31,52 @@ $c = CreateObject('phpgwapi.categories'); $c->app_name = $cats_app; - if (! $cat_id) { - Header('Location: ' . $phpgw->link('/preferences/categories.php',"cats_app=$cats_app&extra=$extra&cats_level=$cats_level")); + if ($confirm) + { + if ($subs) + { + $c->delete($cat_id,'True'); + } + else + { + $c->delete($cat_id); + } + Header('Location: ' . $phpgw->link('/preferences/categories.php',"cats_app=$cats_app&extra=$extra&cats_level=$cats_level&global_cats=$global_cats")); } - - if ($confirm) { - if ($subs) { $c->delete($cat_id,'True'); } - else { $c->delete($cat_id); } - Header('Location: ' . $phpgw->link('/preferences/categories.php',"cats_app=$cats_app&extra=$extra&cats_level=$cats_level")); - } - else { + else + { $hidden_vars = "\n" . "\n" . "\n" + . "\n" . "\n"; - $t = CreateObject('phpgwapi.Template',$phpgw->common->get_tpl_dir('preferences')); - $t->set_file(array('category_delete' => 'delete.tpl')); - $t->set_var('deleteheader',lang('Are you sure you want to delete this category ?')); - $t->set_var('font',$phpgw_info['theme']['font']); - $t->set_var('hidden_vars',$hidden_vars); + $t = CreateObject('phpgwapi.Template',$phpgw->common->get_tpl_dir('preferences')); + $t->set_file(array('category_delete' => 'delete.tpl')); + $t->set_var('deleteheader',lang('Are you sure you want to delete this category ?')); + $t->set_var('font',$phpgw_info['theme']['font']); + $t->set_var('hidden_vars',$hidden_vars); - $exists = $c->exists('subs',$cat_name='',$cat_id); - if ($exists==True) { - $t->set_var('lang_subs',lang('Do you also want to delete all subcategories ?')); - $t->set_var('subs',''); - } - else { - $t->set_var('lang_subs',''); - $t->set_var('subs', ''); - } + $exists = $c->exists('subs',$cat_name='',$cat_id); + if ($exists==True) + { + $t->set_var('lang_subs',lang('Do you also want to delete all subcategories ?')); + $t->set_var('subs',''); + } + else + { + $t->set_var('lang_subs',''); + $t->set_var('subs', ''); + } - $t->set_var('nolink',$phpgw->link('/preferences/categories.php',"cat_id=$cat_id&cats_app=$cats_app&extra=$extra&cats_level=$cats_level")); - $t->set_var('lang_no',lang('No')); + $t->set_var('nolink',$phpgw->link('/preferences/categories.php',"cat_id=$cat_id&cats_app=$cats_app&extra=$extra&cats_level=$cats_level&global_cats=$global_cats")); + $t->set_var('lang_no',lang('No')); - $t->set_var('action_url',$phpgw->link('/preferences/deletecategory.php',"cat_id=$cat_id$cats_app=$cats_app&extra=$extra&cats_level=$cats_level")); - $t->set_var('lang_yes',lang('Yes')); + $t->set_var('action_url',$phpgw->link('/preferences/deletecategory.php',"cat_id=$cat_id$cats_app=$cats_app&extra=$extra&cats_level=$cats_level&global_cats=$global_cats")); + $t->set_var('lang_yes',lang('Yes')); - $t->pparse('out','category_delete'); + $t->pparse('out','category_delete'); } $phpgw->common->phpgw_footer(); -?> \ No newline at end of file +?> diff --git a/preferences/editcategory.php b/preferences/editcategory.php index 43f80b2f6e..1baf26fad3 100644 --- a/preferences/editcategory.php +++ b/preferences/editcategory.php @@ -11,6 +11,12 @@ \**************************************************************************/ /* $Id$ */ + if (! $cat_id) + { + Header('Location: ' . $phpgw->link('/preferences/categories.php',"sort=$sort&order=$order&query=$query&start=$start" + . "&filter=$filter&cats_app=$cats_app&extra=$extra&cats_level=$cats_level&global_cats=$global_cats")); + } + $phpgw_info['flags']['currentapp'] = $cats_app; $phpgw_info['flags']['noappheader'] = True; $phpgw_info['flags']['noappfooter'] = True; @@ -28,12 +34,6 @@ . "\n" . "\n"; - if (! $cat_id) - { - Header('Location: ' . $phpgw->link('/preferences/categories.php',"sort=$sort&order=$order&query=$query&start=$start" - . "&filter=$filter&cats_app=$cats_app&extra=$extra&cats_level=$cats_level&global_cats=$global_cats")); - } - $t = CreateObject('phpgwapi.Template',$phpgw->common->get_tpl_dir('preferences')); $t->set_file(array('form' => 'category_form.tpl')); $t->set_block('form','add','addhandle'); @@ -50,8 +50,8 @@ if (!$error) { - if (!$cat_parent) { $exists = $c->exists('mains',$cat_name,$cat_id); } - else { $exists = $c->exists('subs',$cat_name,$cat_id); } + if (!$cat_parent) { $exists = $c->exists('appandmains',$cat_name,$cat_id); } + else { $exists = $c->exists('appandsubs',$cat_name,$cat_id); } if ($exists == True) { $error[$errorcount++] = lang('That category name has been used already !'); } }