From 7144eef9171a1715f3d59388caf982dac52229c8 Mon Sep 17 00:00:00 2001 From: bettina Date: Fri, 27 Apr 2001 16:06:17 +0000 Subject: [PATCH] update sort categories --- admin/addcategory.php | 12 +- admin/categories.php | 17 ++- admin/editcategory.php | 12 +- admin/templates/default/category_form.tpl | 8 +- admin/templates/idsociety/category_form.tpl | 8 +- admin/templates/verdilak/category_form.tpl | 8 +- phpgwapi/inc/class.categories.inc.php | 109 ++++++++++++------ preferences/addcategory.php | 12 +- preferences/categories.php | 28 ++--- preferences/editcategory.php | 16 ++- .../templates/default/category_form.tpl | 4 + version.inc.php | 2 +- 12 files changed, 157 insertions(+), 79 deletions(-) diff --git a/admin/addcategory.php b/admin/addcategory.php index 41e1f9e96c..f8f4ccbd04 100644 --- a/admin/addcategory.php +++ b/admin/addcategory.php @@ -36,21 +36,25 @@ $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,$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',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')); $t->set_var('actionurl',$phpgw->link('/admin/addcategory.php')); $t->set_var('doneurl',$phpgw->link('/admin/categories.php')); $t->set_var('hidden_vars',''); - $t->set_var('lang_select_parent',lang('Select parent category')); - $t->set_var('category_list',$c->formated_list('select','all',$cat_parent,'False')); + $t->set_var('lang_main',lang('Main category')); + $t->set_var('lang_new_main',lang('New main category')); + $t->set_var('main_category_list',$c->formated_list('select','mains',$cat_main)); + $t->set_var('lang_parent',lang('Parent category')); + $t->set_var('lang_select_parent',lang('Select parent category')); + $t->set_var('category_list',$c->formated_list('select','all',$cat_parent)); $t->set_var('lang_name',lang('Category name')); $t->set_var('lang_descr',lang('Category description')); $t->set_var('cat_name',$cat_name); diff --git a/admin/categories.php b/admin/categories.php index 727e8d82c2..2de1df23c8 100644 --- a/admin/categories.php +++ b/admin/categories.php @@ -82,15 +82,20 @@ $cat_id = $categories[$i]['id']; $owner = $categories[$i]['owner']; - $space = "  "; - if ($categories[$i]['parent'] > 0) { $name = $space . $phpgw->strip_html($categories[$i]['name']); } + $space = '  '; + $level = $categories[$i]['level']; + + if ($level > 0) { + $spaceset = str_repeat($space,$level); + $name = $spaceset . $phpgw->strip_html($categories[$i]['name']); + } $descr = $phpgw->strip_html($categories[$i]['description']); - if (! $descr) { $descr = " "; } + if (! $descr) { $descr = ' '; } - if ($categories[$i]['parent'] == 0) { - $name = "" . $phpgw->strip_html($categories[$i]['name']) . ""; - $descr = "" . $descr . ""; + if ($level == 0) { + $name = '' . $phpgw->strip_html($categories[$i]['name']) . ''; + $descr = '' . $descr . ''; } //-------------------------- template declaration for list records --------------------------- diff --git a/admin/editcategory.php b/admin/editcategory.php index 49499caefb..8334d642f0 100644 --- a/admin/editcategory.php +++ b/admin/editcategory.php @@ -51,12 +51,13 @@ } if ($errorcount) { $t->set_var('message',$phpgw->common->error_list($error)); } - if (($submit) && (! $error) && (! $errorcount)) { $t->set_var('message',lang("Category x has been updated !",$cat_name)); } + if (($submit) && (! $error) && (! $errorcount)) { $t->set_var('message',lang('Category x has been updated !',$cat_name)); } if ((! $submit) && (! $error) && (! $errorcount)) { $t->set_var('message',''); } $cats = $c->return_single($cat_id); $t->set_var('title_categories',lang('Edit global category')); + $t->set_var('lang_parent',lang('Parent category')); $t->set_var('lang_select_parent',lang('Select parent category')); $t->set_var('actionurl',$phpgw->link('/admin/editcategory.php')); $t->set_var('deleteurl',$phpgw->link('/admin/deletecategory.php',"cat_id=$cat_id&start=$start&query=$query&sort=$sort&order=$order&filter=$filter")); @@ -69,12 +70,15 @@ $t->set_var('lang_edit',lang('Edit')); $t->set_var('lang_delete',lang('Delete')); + $cat_main = $cats[0]['main']; + $t->set_var('lang_main',lang('Main category')); + $t->set_var('lang_new_main',lang('New main category')); + $t->set_var('main_category_list',$c->formated_list('select','mains',$cat_main)); $cat_id = $cats[0]['id']; $cat_parent = $cats[0]['parent']; - $t->set_var('cat_name',$phpgw->strip_html($cats[0]['name'])); $t->set_var('cat_description',$phpgw->strip_html($cats[0]['description'])); - $t->set_var('category_list',$c->formated_list('select','all',$cat_parent,'False')); + $t->set_var('category_list',$c->formated_list('select','all',$cat_parent)); $t->set_var('edithandle',''); $t->set_var('addhandle',''); @@ -83,4 +87,4 @@ $t->pparse('edithandle','edit'); $phpgw->common->phpgw_footer(); -?> +?> \ No newline at end of file diff --git a/admin/templates/default/category_form.tpl b/admin/templates/default/category_form.tpl index 691f5dae2c..dca5aa06c6 100644 --- a/admin/templates/default/category_form.tpl +++ b/admin/templates/default/category_form.tpl @@ -10,7 +10,11 @@ - + + + + + @@ -59,4 +63,4 @@
 {lang_main}
{lang_parent}
- + \ No newline at end of file diff --git a/admin/templates/idsociety/category_form.tpl b/admin/templates/idsociety/category_form.tpl index 691f5dae2c..dca5aa06c6 100644 --- a/admin/templates/idsociety/category_form.tpl +++ b/admin/templates/idsociety/category_form.tpl @@ -10,7 +10,11 @@ - + + + + + @@ -59,4 +63,4 @@
 {lang_main}
{lang_parent}
- + \ No newline at end of file diff --git a/admin/templates/verdilak/category_form.tpl b/admin/templates/verdilak/category_form.tpl index 691f5dae2c..dca5aa06c6 100644 --- a/admin/templates/verdilak/category_form.tpl +++ b/admin/templates/verdilak/category_form.tpl @@ -10,7 +10,11 @@ - + + + + + @@ -59,4 +63,4 @@
 {lang_main}
{lang_parent}
- + \ No newline at end of file diff --git a/phpgwapi/inc/class.categories.inc.php b/phpgwapi/inc/class.categories.inc.php index 21a4cd906d..650e890076 100644 --- a/phpgwapi/inc/class.categories.inc.php +++ b/phpgwapi/inc/class.categories.inc.php @@ -93,9 +93,7 @@ { global $phpgw, $phpgw_info; - $this->db2 = $this->db; - - if ($public) + if ($public) { $public_cats = " OR cat_appname='phpgw' "; } @@ -113,7 +111,7 @@ } else { - $ordermethod = " order by cat_parent asc"; + $ordermethod = " order by cat_main asc"; } if (is_array($this->grants)) @@ -138,14 +136,11 @@ if ($query) { - $sql = "SELECT * from phpgw_categories WHERE (cat_appname='" . $this->app_name . "' $public_cats $parent_filter) AND " - . " $grant_cats AND (cat_name like '%$query%' OR cat_description like '%$query%') $filter $ordermethod"; - } - else - { - $sql = "SELECT * from phpgw_categories WHERE (cat_appname='" . $this->app_name . "' $public_cats $parent_filter) AND " - . " $grant_cats $filter $ordermethod"; + $querymethod = " AND (cat_name like '%$query%' OR cat_description like '%$query%') "; } + + $sql = "SELECT * from phpgw_categories WHERE (cat_appname='" . $this->app_name . "' $public_cats $parent_filter) AND " + . " $grant_cats $querymethod $filter $ordermethod"; $this->db2->query($sql,__LINE__,__FILE__); $this->total_records = $this->db2->num_rows(); @@ -155,14 +150,16 @@ $i = 0; while ($this->db->next_record()) { - $cats[$i]['id'] = $this->db->f('cat_id'); - $cats[$i]['owner'] = $this->db->f('cat_owner'); - $cats[$i]['access'] = $this->db->f('cat_access'); - $cats[$i]['app_name'] = $this->db->f('cat_appname'); - $cats[$i]['parent'] = $this->db->f('cat_parent'); - $cats[$i]['name'] = $this->db->f('cat_name'); - $cats[$i]['description'] = $this->db->f('cat_description'); - $cats[$i]['data'] = $this->db->f('cat_data'); + $cats[$i]['id'] = $this->db->f('cat_id'); + $cats[$i]['owner'] = $this->db->f('cat_owner'); + $cats[$i]['access'] = $this->db->f('cat_access'); + $cats[$i]['app_name'] = $this->db->f('cat_appname'); + $cats[$i]['main'] = $this->db->f('cat_main'); + $cats[$i]['level'] = $this->db->f('cat_level'); + $cats[$i]['parent'] = $this->db->f('cat_parent'); + $cats[$i]['name'] = $this->db->f('cat_name'); + $cats[$i]['description'] = $this->db->f('cat_description'); + $cats[$i]['data'] = $this->db->f('cat_data'); $i++; } return $cats; @@ -182,14 +179,16 @@ $this->db->next_record(); - $cats[0]['id'] = $this->db->f('cat_id'); - $cats[0]['owner'] = $this->db->f('cat_owner'); - $cats[0]['access'] = $this->db->f('cat_access'); - $cats[0]['parent'] = $this->db->f('cat_parent'); - $cats[0]['name'] = $this->db->f('cat_name'); - $cats[0]['description'] = $this->db->f('cat_description'); - $cats[0]['data'] = $this->db->f('cat_data'); - + $cats[0]['id'] = $this->db->f('cat_id'); + $cats[0]['owner'] = $this->db->f('cat_owner'); + $cats[0]['access'] = $this->db->f('cat_access'); + $cats[0]['main'] = $this->db->f('cat_main'); + $cats[0]['level'] = $this->db->f('cat_level'); + $cats[0]['parent'] = $this->db->f('cat_parent'); + $cats[0]['name'] = $this->db->f('cat_name'); + $cats[0]['description'] = $this->db->f('cat_description'); + $cats[0]['data'] = $this->db->f('cat_data'); + return $cats; } /*! @@ -212,6 +211,7 @@ $this->account_id = $account_id; $this->app_name = $app_name; $this->db = $phpgw->db; + $this->db2 = $this->db; $this->total_records = $this->db->num_rows(); $this->grants = $phpgw->acl->get_grants($app_name); $this->cats = $this->return_array($type,$start,$limit,$query,$sort,$order,$public); @@ -265,12 +265,33 @@ @param $cat_description category description defaults to '' @param $cat_data category data defaults to '' */ - function add($cat_name,$cat_parent,$cat_description = '', $cat_data = '',$cat_access = '') + function add($cat_name,$cat_parent,$cat_description = '', $cat_data = '',$cat_access = '',$cat_main) { - $this->db->query('insert into phpgw_categories (cat_parent,cat_owner,cat_access,cat_appname,cat_name,' + + if ($cat_main) + { + $this->db2->query("Select cat_level from phpgw_categories where cat_id='$cat_parent'",__LINE__,__FILE__); + $this->db2->next_record(); + $cat_level = $this->db2->f('cat_level')+1; + + $this->db->query("insert into phpgw_categories (cat_parent,cat_owner,cat_access,cat_appname,cat_name," . "cat_description,cat_data) values ('$cat_parent','" . $this->account_id . "','$cat_access','" . $this->app_name . "','" . addslashes($cat_name) . "','" . addslashes($cat_description) - . "','$cat_data')",__LINE__,__FILE__); + . "','$cat_data','$cat_main','$cat_level')",__LINE__,__FILE__); + } + else + { + $this->db->query("insert into phpgw_categories (cat_parent,cat_owner,cat_access,cat_appname,cat_name," + . "cat_description,cat_data,cat_main,cat_level) values ('$cat_parent','" . $this->account_id . "','$cat_access','" + . $this->app_name . "','" . addslashes($cat_name) . "','" . addslashes($cat_description) + . "','$cat_data','$cat_main','$cat_level')",__LINE__,__FILE__); + + $this->db2->query("select max(cat_id) as max from phpgw_categories",__LINE__,__FILE__); + $this->db2->next_record(); + $this->db->query("update phpgw_categories set cat_main='" . $this->db2->f('max') . "' where cat_id='" + . $this->db2->f('max') . "'",__LINE__,__FILE__); + } + } /*! @function delete @@ -296,12 +317,32 @@ @param $cat_description category description defaults to '' @param $cat_data category data defaults to '' */ - function edit($cat_id,$cat_parent,$cat_name,$cat_description = '',$cat_data = '',$cat_access = '') + function edit($cat_id,$cat_parent,$cat_name,$cat_description = '',$cat_data = '',$cat_access = '',$cat_main) { + + if ($cat_main) + { + $this->db2->query("Select cat_level from phpgw_categories where cat_id='$cat_parent'",__LINE__,__FILE__); + $this->db2->next_record(); + $cat_level = $this->db2->f('cat_level')+1; + $this->db->query("update phpgw_categories set cat_name='" . addslashes($cat_name) . "', " - . "cat_description='" . addslashes($cat_description) . "', cat_data='" - . "$cat_data', cat_parent='$cat_parent', cat_access='$cat_access' where cat_appname='" - . $this->app_name . "' and cat_id='$cat_id'",__LINE__,__FILE__); + . "cat_description='" . addslashes($cat_description) . "', cat_data='" + . "$cat_data', cat_parent='$cat_parent', cat_access='$cat_access', cat_main='$cat_main', cat_level='$cat_level' " + . "where cat_appname='" . $this->app_name . "' and cat_id='$cat_id'",__LINE__,__FILE__); + } + else + { + $this->db->query("update phpgw_categories set cat_name='" . addslashes($cat_name) . "', " + . "cat_description='" . addslashes($cat_description) . "', cat_data='" + . "$cat_data', cat_parent='$cat_parent', cat_access='$cat_access', cat_main='$cat_main', cat_level='$cat_level' " + . "where cat_appname='" . $this->app_name . "' and cat_id='$cat_id'",__LINE__,__FILE__); + + $this->db2->query("select max(cat_id) as max from phpgw_categories",__LINE__,__FILE__); + $this->db2->next_record(); + $this->db->query("update phpgw_categories set cat_main='" . $this->db2->f('max') . "' where cat_id='" + . $this->db2->f('max') . "'",__LINE__,__FILE__); + } } function name2id($cat_name) diff --git a/preferences/addcategory.php b/preferences/addcategory.php index c360de1aef..fbff2b9543 100644 --- a/preferences/addcategory.php +++ b/preferences/addcategory.php @@ -54,7 +54,7 @@ if ($access) { $cat_access = 'private'; } else { $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,$cat_main); } } @@ -63,10 +63,14 @@ if ((! $submit) && (! $error) && (! $errorcount)) { $t->set_var('message',''); } - $t->set_var('font',$phpgw_info["theme"]["font"]); - $t->set_var('category_list',$c->formated_list('select','all',$cat_parent,'False')); + + $t->set_var('lang_main',lang('Main category')); + $t->set_var('lang_new_main',lang('New main category')); + $t->set_var('font',$phpgw_info['theme']['font']); + $t->set_var('main_category_list',$c->formated_list('select','mains',$cat_main)); + $t->set_var('category_list',$c->formated_list('select','all',$cat_parent)); $t->set_var('hidden_vars',$hidden_vars); - $t->set_var('user_name',$phpgw_info["user"]["fullname"]); + $t->set_var('user_name',$phpgw_info['user']['fullname']); $t->set_var('doneurl',$phpgw->link('/preferences/categories.php')); $t->set_var('title_categories',lang("Add x category for",$cats_app)); $t->set_var('actionurl',$phpgw->link('/preferences/addcategory.php')); diff --git a/preferences/categories.php b/preferences/categories.php index 23d126ea9c..da684573d2 100644 --- a/preferences/categories.php +++ b/preferences/categories.php @@ -52,7 +52,7 @@ $c = CreateObject('phpgwapi.categories'); $c->app_name = $cats_app; - $categories = $c->return_array('all',$start,$limit,$query,$sort,$order,'False'); + $categories = $c->return_array('all',$start,$limit,$query,$sort,$order); //--------------------------------- nextmatch -------------------------------------------- @@ -92,28 +92,28 @@ $cat_id = $categories[$i]['id']; $owner = $categories[$i]['owner']; + $level = $categories[$i]['level']; $space = '  '; - if ($categories[$i]['parent'] > 0) - { - $parent_data = $c->return_single($categories[$i]['parent']); - $name = $space . $phpgw->strip_html($parent_data[0]['name'] . ' :: ' . $categories[$i]['name']); - } + + if ($level > 0) { + $spaceset = str_repeat($space,$level); + $name = $spaceset .$phpgw->strip_html($categories[$i]['name']); + } $descr = $phpgw->strip_html($categories[$i]['description']); if (! $descr) { $descr = ' '; } - if ($extra) { - $data = $categories[$i]['data']; - if (! $data) { $data = ' '; } - $t->set_var('td_data','' . $data . ''); + $data = $categories[$i]['data']; + if (! $data) { $data = ' '; } + $t->set_var('td_data','' . $data . ''); } else { $t->set_var('td_data',''); } - if ($categories[$i]['parent'] == 0) { - $name = '' . $phpgw->strip_html($categories[$i]['name']) . ''; - $descr = '' . $descr . ''; - $data = '' . $data . ''; + if ($level == 0) { + $name = '' . $phpgw->strip_html($categories[$i]['name']) . ''; + $descr = '' . $descr . ''; + $data = '' . $data . ''; } //-------------------------- template declaration for list records --------------------------- diff --git a/preferences/editcategory.php b/preferences/editcategory.php index 3621677565..4a764e50df 100644 --- a/preferences/editcategory.php +++ b/preferences/editcategory.php @@ -52,20 +52,24 @@ 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,$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 updated !",$cat_name)); } + if (($submit) && (! $error) && (! $errorcount)) { $t->set_var('message',lang('Category x has been updated !',$cat_name)); } if ((! $submit) && (! $error) && (! $errorcount)) { $t->set_var('message',''); } $cats = $c->return_single($cat_id); + $cat_main = $cats[0]['main']; + $t->set_var('lang_main',lang('Main category')); + $t->set_var('lang_new_main',lang('New main category')); + $t->set_var('main_category_list',$c->formated_list('select','mains',$cat_main)); $cat_parent = $cats[0]['parent']; - $t->set_var('category_list',$c->formated_list('select','all',$cat_parent,'False')); - $t->set_var('font',$phpgw_info["theme"]["font"]); - $t->set_var('user_name',$phpgw_info["user"]["fullname"]); - $t->set_var('title_categories',lang("Edit x category for",$cats_app)); + $t->set_var('category_list',$c->formated_list('select','all',$cat_parent)); + $t->set_var('font',$phpgw_info['theme']['font']); + $t->set_var('user_name',$phpgw_info['user']['fullname']); + $t->set_var('title_categories',lang('Edit x category for',$cats_app)); $t->set_var('doneurl',$phpgw->link('/preferences/categories.php')); $t->set_var('actionurl',$phpgw->link('/preferences/editcategory.php')); $t->set_var('deleteurl',$phpgw->link('/preferences/deletecategory.php')); diff --git a/preferences/templates/default/category_form.tpl b/preferences/templates/default/category_form.tpl index 58cc50d18f..dbe5b78906 100644 --- a/preferences/templates/default/category_form.tpl +++ b/preferences/templates/default/category_form.tpl @@ -9,6 +9,10 @@ {message} + + + + diff --git a/version.inc.php b/version.inc.php index d3a95b04b3..e1a35a5f85 100644 --- a/version.inc.php +++ b/version.inc.php @@ -11,5 +11,5 @@ /* $Id$ */ - $phpgw_info['server']['versions']['phpgwapi'] = '0.9.11.002'; + $phpgw_info['server']['versions']['phpgwapi'] = '0.9.11.003'; $phpgw_info['server']['versions']['current_header'] = '1.11';
{lang_main}
{lang_parent}