From 01be8c3c6f032ab52debd8034f972028e8b966ff Mon Sep 17 00:00:00 2001 From: bettina Date: Mon, 9 Apr 2001 14:45:27 +0000 Subject: [PATCH] added possibility to delete also all subcats if deleting the maincat --- admin/addcategory.php | 20 ++++----- admin/deletecategory.php | 40 +++++++++--------- admin/editcategory.php | 19 +++++---- admin/templates/default/delete_cat.tpl | 21 ++++++++++ admin/templates/idsociety/delete_cat.tpl | 21 ++++++++++ admin/templates/verdilak/delete_cat.tpl | 21 ++++++++++ phpgwapi/inc/class.categories.inc.php | 52 ++++++++++++++++-------- preferences/addcategory.php | 6 +-- preferences/deletecategory.php | 36 ++++++++-------- preferences/editcategory.php | 26 +++++------- preferences/templates/default/delete.tpl | 25 +++++++----- 11 files changed, 186 insertions(+), 101 deletions(-) create mode 100644 admin/templates/default/delete_cat.tpl create mode 100644 admin/templates/idsociety/delete_cat.tpl create mode 100644 admin/templates/verdilak/delete_cat.tpl diff --git a/admin/addcategory.php b/admin/addcategory.php index 3161e393da..7a60abbb1c 100644 --- a/admin/addcategory.php +++ b/admin/addcategory.php @@ -23,24 +23,24 @@ $c->categories($phpgw_info['user']['account_id'],'phpgw'); if ($submit) { - $errorcount = 0; + $errorcount = 0; - $exists = $c->exists('main',$cat_name); + if (!$cat_name) { $error[$errorcount++] = lang('Please enter a name for that category !'); } + 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_name) { $error[$errorcount++] = lang('Please enter a name for that category !'); } + if (! $error) { + $cat_name = addslashes($cat_name); + $cat_description = addslashes($cat_description); + $cat_access = 'public'; - if (! $error) { - $cat_name = addslashes($cat_name); - $cat_description = addslashes($cat_description); - $cat_access = 'public'; - - $c->add($cat_name,$cat_parent,$cat_description,$cat_data,$cat_access); + $c->add($cat_name,$cat_parent,$cat_description,$cat_data,$cat_access); } } 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',lang("Category x has been added !", $cat_name)); } if ((! $submit) && (! $error) && (! $errorcount)) { $t->set_var('message',''); } $t->set_var('title_categories',lang('Add global category')); diff --git a/admin/deletecategory.php b/admin/deletecategory.php index 0415d3bd5d..686e761f60 100644 --- a/admin/deletecategory.php +++ b/admin/deletecategory.php @@ -27,8 +27,9 @@ } if ($confirm) { - $c->delete($cat_id); - Header('Location: ' . $phpgw->link('/admin/categories.php',"start=$start&query=$query&sort=$sort&order=$order&filter=$filter")); + if ($subs) { $c->delete($cat_id,'True'); } + else { $c->delete($cat_id); } + Header('Location: ' . $phpgw->link('/admin/categories.php',"start=$start&query=$query&sort=$sort&order=$order&filter=$filter")); } else { $hidden_vars = "\n" @@ -39,28 +40,29 @@ . "\n"; $t = CreateObject('phpgwapi.Template',$phpgw->common->get_tpl_dir('admin')); - $t->set_file(array('category_delete' => 'delete_common.tpl')); + $t->set_file(array('category_delete' => 'delete_cat.tpl')); $t->set_var('messages',lang('Are you sure you want to delete this category ?')); + $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 want to delete also all subcategories ?')); + $t->set_var('subs',''); + } + else { + $t->set_var('lang_subs',''); + $t->set_var('subs', ''); + } - $nolinkf = $phpgw->link('/admin/categories.php',"cat_id=$cat_id&start=$start&query=$query&sort=$sort&order=$order&filter=$filter"); - $nolink = "" . lang('No') .""; - $t->set_var('no',$nolink); + $t->set_var('nolink',$phpgw->link('/admin/categories.php',"cat_id=$cat_id&start=$start&query=$query&sort=$sort&order=$order&filter=$filter")); + $t->set_var('lang_no',lang('No')); - $yeslinkf = $phpgw->link('/admin/deletecategory.php',"cat_id=$cat_id&confirm=True"); - $yeslinkf = "
link('/admin/deletecategory.php') . "\">" - . $hidden_vars - . "" - . "" - . "" - . "
"; - - $yeslink = "" . lang('Yes') .""; - $yeslink = $yeslinkf; - - $t->set_var('yes',$yeslink); + $t->set_var('action_url',$phpgw->link('/admin/deletecategory.php',"cat_id=$cat_id")); + $t->set_var('lang_yes',lang('Yes')); $t->pparse('out','category_delete'); } $phpgw->common->phpgw_footer(); -?> +?> \ No newline at end of file diff --git a/admin/editcategory.php b/admin/editcategory.php index 0827b7cdba..1876c8308a 100644 --- a/admin/editcategory.php +++ b/admin/editcategory.php @@ -35,17 +35,18 @@ . "\n"; if ($submit) { - $errorcount = 0; - if (!$cat_name) { $error[$errorcount++] = lang('Please enter a name for that category !'); } - $phpgw->db->query("SELECT count(*) from phpgw_categories WHERE cat_name='$cat_name' AND cat_id !='$cat_id' AND cat_appname='phpgw'"); - $phpgw->db->next_record(); - if ($phpgw->db->f(0) != 0) { $error[$errorcount++] = lang('That category name has been used already !'); } + $errorcount = 0; + if (!$cat_name) { $error[$errorcount++] = lang('Please enter a name for that category !'); } - $cat_name = addslashes($cat_name); - $cat_description = addslashes($cat_description); - $cat_access = 'public'; + 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 (! $error) { $c->edit($cat_id,$cat_parent,$cat_name,$cat_description,$cat_data,$cat_access); } + $cat_name = addslashes($cat_name); + $cat_description = addslashes($cat_description); + $cat_access = 'public'; + + if (! $error) { $c->edit($cat_id,$cat_parent,$cat_name,$cat_description,$cat_data,$cat_access); } } if ($errorcount) { $t->set_var('message',$phpgw->common->error_list($error)); } diff --git a/admin/templates/default/delete_cat.tpl b/admin/templates/default/delete_cat.tpl new file mode 100644 index 0000000000..568d9334a5 --- /dev/null +++ b/admin/templates/default/delete_cat.tpl @@ -0,0 +1,21 @@ + +
+ + + + + + + + + + + + + + +
{messages}
{lang_subs}{subs}
+ {hidden_vars} + {lang_no}
+
+ \ No newline at end of file diff --git a/admin/templates/idsociety/delete_cat.tpl b/admin/templates/idsociety/delete_cat.tpl new file mode 100644 index 0000000000..568d9334a5 --- /dev/null +++ b/admin/templates/idsociety/delete_cat.tpl @@ -0,0 +1,21 @@ + +
+ + + + + + + + + + + + + + +
{messages}
{lang_subs}{subs}
+ {hidden_vars} + {lang_no}
+
+ \ No newline at end of file diff --git a/admin/templates/verdilak/delete_cat.tpl b/admin/templates/verdilak/delete_cat.tpl new file mode 100644 index 0000000000..568d9334a5 --- /dev/null +++ b/admin/templates/verdilak/delete_cat.tpl @@ -0,0 +1,21 @@ + +
+ + + + + + + + + + + + + + +
{messages}
{lang_subs}{subs}
+ {hidden_vars} + {lang_no}
+
+ \ No newline at end of file diff --git a/phpgwapi/inc/class.categories.inc.php b/phpgwapi/inc/class.categories.inc.php index fa7279e039..6029798c7a 100644 --- a/phpgwapi/inc/class.categories.inc.php +++ b/phpgwapi/inc/class.categories.inc.php @@ -263,10 +263,16 @@ @abstract delete category @param $cat_id int - category id */ - function delete($cat_id) + function delete($cat_id,$subs = 'False') { - $this->db->query("delete from phpgw_categories where cat_id='$cat_id' and cat_appname='" - . $this->app_name . "'",__LINE__,__FILE__); + + if ($subs == 'True') + { + $subdelete = " OR cat_parent='$cat_id'"; + } + + $this->db->query("delete from phpgw_categories where cat_id='$cat_id' $subdelete and cat_appname='" + . $this->app_name . "'",__LINE__,__FILE__); } /*! @function edit @@ -311,23 +317,37 @@ @param $cat_name category name @result boolean true or false */ - function exists($type,$cat_name) + function exists($type,$cat_name,$cat_id) { - $filter = $this->filter($type); + $filter = $this->filter($type); - $this->db->query("select count(*) from phpgw_categories where cat_name='" - . addslashes($cat_name) . "' and cat_appname='" + if ($cat_name) + { + $cat_exists = " cat_name='" . addslashes($cat_name) . "' "; + } + if ($cat_id) + { + $cat_exists = " cat_parent='$cat_id' "; + } + if ($cat_name && $cat_id) + { + $cat_exists = " cat_name='" . addslashes($cat_name) . "' and cat_id != '$cat_id' "; + } + + $this->db->query("select count(*) from phpgw_categories where $cat_exists and cat_appname='" . $this->app_name . "' $filter",__LINE__,__FILE__); - $this->db->next_record(); - if ($this->db->f(0)) - { - return True; - } - else - { - return False; - } + $this->db->next_record(); + + if ($this->db->f(0)) + { + return True; + } + else + { + return False; + } } + } ?> diff --git a/preferences/addcategory.php b/preferences/addcategory.php index cd7f4ad780..08b7fa3f63 100644 --- a/preferences/addcategory.php +++ b/preferences/addcategory.php @@ -39,8 +39,8 @@ $errorcount = 0; if (!$cat_name) { $error[$errorcount++] = lang('Please enter a name for that category !'); } - if (!$cat_parent) { $exists = $c->exists('mains',$cat_name); } - else { $exists = $c->exists('subs',$cat_name); } + 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 (! $error) { @@ -70,7 +70,7 @@ $t->set_var('lang_access',lang('Private')); if ($access) { $t->set_var('access', ''); } - else { $t->set_var('access', 'set_var('access', ''); } $t->set_var('lang_name',lang('Name')); $t->set_var('lang_descr',lang('Description')); $t->set_var('cat_name',$cat_name); diff --git a/preferences/deletecategory.php b/preferences/deletecategory.php index 431bbf90cc..2ebb7625b7 100644 --- a/preferences/deletecategory.php +++ b/preferences/deletecategory.php @@ -30,34 +30,36 @@ } if ($confirm) { - $c->delete($cat_id); - Header('Location: ' . $phpgw->link('/preferences/categories.php',"cats_app=$cats_app&extra=$extra")); + 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")); } else { $hidden_vars = "\n" - . $hidden_vars = "\n" - . $hidden_vars = "\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"]); - $nolinkf = $phpgw->link('/preferences/categories.php',"cat_id=$cat_id&cats_app=$cats_app&extra=$extra"); - $nolink = "" . lang('No') .""; - $t->set_var("nolink",$nolink); + $t->set_var('hidden_vars',$hidden_vars); - $yeslinkf = $phpgw->link('/preferences/deletecategory.php',"cat_id=$cat_id&confirm=True"); - $yeslinkf = "
link('/preferences/deletecategory.php') . "\">" - . $hidden_vars - . "" - . "" - . "" - . "
"; + $exists = $c->exists('subs',$cat_name='',$cat_id); + if ($exists==True) { + $t->set_var('lang_subs',lang('Do you want to delete also all subcategories ?')); + $t->set_var('subs',''); + } + else { + $t->set_var('lang_subs',''); + $t->set_var('subs', ''); + } - $yeslink = "" . lang('Yes') .""; - $yeslink = $yeslinkf; + $t->set_var('nolink',$phpgw->link('/preferences/categories.php',"cat_id=$cat_id&cats_app=$cats_app&extra=$extra")); + $t->set_var('lang_no',lang('No')); - $t->set_var('yeslink',$yeslink); + $t->set_var('action_url',$phpgw->link('/preferences/deletecategory.php',"cat_id=$cat_id$cats_app=$cats_app&extra=$extra")); + $t->set_var('lang_yes',lang('Yes')); $t->pparse('out','category_delete'); } diff --git a/preferences/editcategory.php b/preferences/editcategory.php index 7175e5d788..134b995f39 100644 --- a/preferences/editcategory.php +++ b/preferences/editcategory.php @@ -40,24 +40,18 @@ $c->app_name = $cats_app; if ($submit) { - $errorcount = 0; - if (!$cat_name) { $error[$errorcount++] = lang('Please enter a name for that category !'); } - $phpgw->db->query("SELECT count(*) from phpgw_categories WHERE cat_name='$cat_name' AND cat_id !='$cat_id' AND cat_appname='" - . $phpgw_info["flags"]["currentapp"] ."' AND cat_parent='0'"); - $phpgw->db->next_record(); - if ($phpgw->db->f(0) != 0) { $error[$errorcount++] = lang('That main category name has been used already !'); } + $errorcount = 0; + if (!$cat_name) { $error[$errorcount++] = lang('Please enter a name for that category !'); } + 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 !'); } - $phpgw->db->query("SELECT count(*) from phpgw_categories WHERE cat_name='$cat_name' AND cat_id !='$cat_id' AND cat_appname='" - . $phpgw_info["flags"]["currentapp"] ."' AND cat_parent != '0'"); - $phpgw->db->next_record(); - if ($phpgw->db->f(0) != 0) { $error[$errorcount++] = lang('That sub category name has been used already !'); } + $cat_name = addslashes($cat_name); + $cat_description = addslashes($cat_description); + if ($access) { $cat_access = 'private'; } + else { $cat_access = 'public'; } - $cat_name = addslashes($cat_name); - $cat_description = addslashes($cat_description); - if ($access) { $cat_access = 'private'; } - else { $cat_access = 'public'; } - - if (! $error) { $c->edit($cat_id,$cat_parent,$cat_name,$cat_description,$cat_data,$cat_access); } + if (! $error) { $c->edit($cat_id,$cat_parent,$cat_name,$cat_description,$cat_data,$cat_access); } } if ($errorcount) { $t->set_var('message',$phpgw->common->error_list($error)); } diff --git a/preferences/templates/default/delete.tpl b/preferences/templates/default/delete.tpl index 107108be38..e721548d22 100644 --- a/preferences/templates/default/delete.tpl +++ b/preferences/templates/default/delete.tpl @@ -1,19 +1,22 @@ -


+
- +
+ - -
{deleteheader}
- - - - + + + + + + + -
{nolink}{yeslink}{lang_subs}{subs}
+ {hidden_vars} + {lang_no}
-
-
\ No newline at end of file + + \ No newline at end of file