From da44fa8c19a3b5772c712559bae133bc6f1b2ab1 Mon Sep 17 00:00:00 2001 From: bettina Date: Fri, 11 May 2001 20:43:51 +0000 Subject: [PATCH] update categories --- admin/addcategory.php | 145 +++++++++++++++---------- admin/categories.php | 237 +++++++++++++++++++++-------------------- admin/editcategory.php | 156 ++++++++++++++++----------- 3 files changed, 296 insertions(+), 242 deletions(-) diff --git a/admin/addcategory.php b/admin/addcategory.php index 20515423f2..4af9fad678 100644 --- a/admin/addcategory.php +++ b/admin/addcategory.php @@ -9,74 +9,101 @@ * Free Software Foundation; either version 2 of the License, or (at your * * option) any later version. * \**************************************************************************/ -/* $Id$ */ + /* $Id$ */ - $phpgw_info['flags']['currentapp'] = 'admin'; - include('../header.inc.php'); + $phpgw_info['flags']['currentapp'] = 'admin'; + include('../header.inc.php'); - $t = CreateObject('phpgwapi.Template',PHPGW_APP_TPL); - $t->set_file(array('form' => 'category_form.tpl')); - $t->set_block('form','add','addhandle'); - $t->set_block('form','edit','edithandle'); + $t = CreateObject('phpgwapi.Template',PHPGW_APP_TPL); + $t->set_file(array('form' => 'category_form.tpl')); + $t->set_block('form','add','addhandle'); + $t->set_block('form','edit','edithandle'); - $c = CreateObject('phpgwapi.categories'); - $c->categories($phpgw_info['user']['account_id'],'phpgw'); + $c = CreateObject('phpgwapi.categories'); + $c->app_name = 'phpgw'; - 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); - $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=''); + } - $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',''); + if ($exists == True) + { + $error[$errorcount++] = lang('That category name has been used already !'); + } + } - $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); - $t->set_var('cat_description',$cat_description); - $t->set_var('lang_add',lang('Add')); - $t->set_var('lang_reset',lang('Clear Form')); - $t->set_var('lang_done',lang('Done')); + if ($cat_main && $cat_parent) + { + $main = $c->return_main($cat_parent); + if ($main != $cat_main) + { + $error[$errorcount++] = lang('You selected an invalid main category !'); + } + } - $t->set_var('edithandle',''); - $t->set_var('addhandle',''); - $t->pparse('out','form'); - $t->pparse('addhandle','add'); + if (!$error) + { + $cat_name = addslashes($cat_name); + $cat_description = addslashes($cat_description); + $cat_access = 'public'; - $phpgw->common->phpgw_footer(); + $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('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_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); + $t->set_var('cat_description',$cat_description); + $t->set_var('lang_add',lang('Add')); + $t->set_var('lang_reset',lang('Clear Form')); + $t->set_var('lang_done',lang('Done')); + + $t->set_var('edithandle',''); + $t->set_var('addhandle',''); + $t->pparse('out','form'); + $t->pparse('addhandle','add'); + + $phpgw->common->phpgw_footer(); ?> diff --git a/admin/categories.php b/admin/categories.php index ae1182ddcd..59514e8cfd 100644 --- a/admin/categories.php +++ b/admin/categories.php @@ -11,137 +11,138 @@ \**************************************************************************/ /* $Id$ */ - $phpgw_info['flags'] = array( - 'currentapp' => 'admin', - 'enable_nextmatchs_class' => True - ); + $phpgw_info['flags'] = array('currentapp' => 'admin', + 'enable_nextmatchs_class' => True); - include('../header.inc.php'); + include('../header.inc.php'); - $t = CreateObject('phpgwapi.Template',PHPGW_APP_TPL); + $t = CreateObject('phpgwapi.Template',PHPGW_APP_TPL); - $t->set_file(array( - 'cat_list_t' => 'listcats.tpl', - 'cat_list' => 'listcats.tpl' - )); - $t->set_block('cat_list_t','cat_list','list'); + $t->set_file(array('cat_list_t' => 'listcats.tpl', + 'cat_list' => 'listcats.tpl')); + $t->set_block('cat_list_t','cat_list','list'); - $common_hidden_vars = "\n" + $common_hidden_vars = "\n" . "\n" . "\n" . "\n" . "\n"; - $t->set_var('lang_action',lang('Category list')); - $t->set_var('add_action',$phpgw->link('/admin/addcategory.php')); - $t->set_var('lang_add',lang('Add')); - $t->set_var('title_categories',lang('Global categories')); - $t->set_var('lang_search',lang('Search')); - $t->set_var('actionurl',$phpgw->link('/admin/categories.php')); - $t->set_var('lang_done',lang('Done')); - $t->set_var('doneurl',$phpgw->link('/admin/index.php')); + $t->set_var('lang_action',lang('Category list')); + $t->set_var('add_action',$phpgw->link('/admin/addcategory.php')); + $t->set_var('lang_add',lang('Add')); + $t->set_var('title_categories',lang('Global categories')); + $t->set_var('lang_search',lang('Search')); + $t->set_var('actionurl',$phpgw->link('/admin/categories.php')); + $t->set_var('lang_done',lang('Done')); + $t->set_var('doneurl',$phpgw->link('/admin/index.php')); - if (! $start) { $start = 0; } + if (! $start) { $start = 0; } - if($phpgw_info['user']['preferences']['common']['maxmatchs'] && $phpgw_info['user']['preferences']['common']['maxmatchs'] > 0) + if($phpgw_info['user']['preferences']['common']['maxmatchs'] && $phpgw_info['user']['preferences']['common']['maxmatchs'] > 0) + { + $limit = $phpgw_info['user']['preferences']['common']['maxmatchs']; + } + else + { + $limit = 15; + } + + $c = CreateObject('phpgwapi.categories'); + $c->categories($phpgw_info['user']['account_id'],'phpgw'); + $categories = $c->return_array('all',$start,$limit,$query,$sort,$order); + +//--------------------------------- nextmatch -------------------------------------------- + + $left = $phpgw->nextmatchs->left('/admin/categories.php',$start,$c->total_records); + $right = $phpgw->nextmatchs->right('/admin/categories.php',$start,$c->total_records); + $t->set_var('left',$left); + $t->set_var('right',$right); + + if ($c->total_records > $limit) + { + $lang_showing=lang('showing x - x of x',($start + 1),($start + $limit),$c->total_records); + } + else + { + $lang_showing=lang('showing x',$c->total_records); + } + $t->set_var('lang_showing',$lang_showing); + +// ------------------------------ end nextmatch ------------------------------------------ + +//------------------- list header variable template-declarations ------------------------- + + $t->set_var('th_bg',$phpgw_info['theme']['th_bg']); + $t->set_var('sort_name',$phpgw->nextmatchs->show_sort_order($sort,'cat_name',$order,'/admin/categories.php',lang('Name'))); + $t->set_var('sort_description',$phpgw->nextmatchs->show_sort_order($sort,'cat_description',$order,'/admin/categories.php',lang('Description'))); + $t->set_var('lang_edit',lang('Edit')); + $t->set_var('lang_delete',lang('Delete')); + +// -------------------------- end header declaration -------------------------------------- + + for ($i=0;$inextmatchs->alternate_row_color($tr_color); + $t->set_var(tr_color,$tr_color); + + $cat_id = $categories[$i]['id']; + $owner = $categories[$i]['owner']; + $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 ($level == 0) + { + $name = '' . $phpgw->strip_html($categories[$i]['name']) . ''; + $descr = '' . $descr . ''; + } + +//-------------------------- template declaration for list records --------------------------- + + $t->set_var(array('name' => $name, + 'descr' => $descr)); + + if ($categories[$i]['owner'] == $phpgw_info['user']['account_id']) + { + $t->set_var('edit',$phpgw->link('/admin/editcategory.php',"cat_id=$cat_id&start=$start&query=$query&sort=$sort&order=$order&filter=$filter")); + $t->set_var('lang_edit_entry',lang('Edit')); + } + else + { + $t->set_var('edit',''); + $t->set_var('lang_edit_entry',' '); + } + + if ($categories[$i]['owner'] == $phpgw_info['user']['account_id']) + { + $t->set_var('delete',$phpgw->link('/admin/deletecategory.php',"cat_id=$cat_id&start=$start&query=$query&sort=$sort&order=$order&filter=$filter")); + $t->set_var('lang_delete_entry',lang('Delete')); + } + else + { + $t->set_var('delete',''); + $t->set_var('lang_delete_entry',' '); + } + + $t->parse('list','cat_list',True); } + } + +// ---------------------------- end record declaration ----------------------------------------- - $c = CreateObject('phpgwapi.categories'); - $c->categories($phpgw_info['user']['account_id'],'phpgw'); - $categories = $c->return_array('all',$start,$limit,$query,$sort,$order); + $t->parse('out','cat_list_t',True); + $t->p('out'); - //--------------------------------- nextmatch -------------------------------------------- - $left = $phpgw->nextmatchs->left('/admin/categories.php',$start,$c->total_records); - $right = $phpgw->nextmatchs->right('/admin/categories.php',$start,$c->total_records); - $t->set_var('left',$left); - $t->set_var('right',$right); - - if ($c->total_records > $limit) - { - $lang_showing=lang('showing x - x of x',($start + 1),($start + $limit),$c->total_records); - } - else - { - $lang_showing=lang('showing x',$c->total_records); - } - $t->set_var('lang_showing',$lang_showing); - - // ------------------------------ end nextmatch ------------------------------------------ - - //------------------- list header variable template-declarations ------------------------- - $t->set_var('th_bg',$phpgw_info['theme']['th_bg']); - $t->set_var('sort_name',$phpgw->nextmatchs->show_sort_order($sort,'cat_name',$order,'/admin/categories.php',lang('Name'))); - $t->set_var('sort_description',$phpgw->nextmatchs->show_sort_order($sort,'cat_description',$order,'/admin/categories.php',lang('Description'))); - $t->set_var('lang_edit',lang('Edit')); - $t->set_var('lang_delete',lang('Delete')); - // -------------------------- end header declaration -------------------------------------- - - for ($i=0;$inextmatchs->alternate_row_color($tr_color); - $t->set_var(tr_color,$tr_color); - - $cat_id = $categories[$i]['id']; - $owner = $categories[$i]['owner']; - $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 ($level == 0) - { - $name = '' . $phpgw->strip_html($categories[$i]['name']) . ''; - $descr = '' . $descr . ''; - } - - //-------------------------- template declaration for list records --------------------------- - $t->set_var(array( - 'name' => $name, - 'descr' => $descr - )); - - if ($categories[$i]["owner"] == $phpgw_info['user']['account_id']) - { - $t->set_var('edit',$phpgw->link('/admin/editcategory.php',"cat_id=$cat_id&start=$start&query=$query&sort=$sort&order=$order&filter=$filter")); - $t->set_var('lang_edit_entry',lang('Edit')); - } - else - { - $t->set_var('edit',''); - $t->set_var('lang_edit_entry',' '); - } - if ($categories[$i]["owner"] == $phpgw_info['user']['account_id']) - { - $t->set_var('delete',$phpgw->link('/admin/deletecategory.php',"cat_id=$cat_id&start=$start&query=$query&sort=$sort&order=$order&filter=$filter")); - $t->set_var('lang_delete_entry',lang('Delete')); - } - else - { - $t->set_var('delete',''); - $t->set_var('lang_delete_entry',' '); - } - $t->parse('list','cat_list',True); - } - } - // ---------------------------- end record declaration ----------------------------------------- - - $t->parse('out','cat_list_t',True); - $t->p('out'); - - $phpgw->common->phpgw_footer(); + $phpgw->common->phpgw_footer(); ?> diff --git a/admin/editcategory.php b/admin/editcategory.php index 857724e725..63ee672c34 100644 --- a/admin/editcategory.php +++ b/admin/editcategory.php @@ -11,91 +11,117 @@ \**************************************************************************/ /* $Id$ */ - $phpgw_info['flags']['currentapp'] = 'admin'; - include('../header.inc.php'); + if (! $cat_id) + { + Header('Location: ' . $phpgw->link('/admin/categories.php',"sort=$sort&order=$order&query=$query&start=$start" + . "&filter=$filter")); + } - if (! $cat_id) - { - Header('Location: ' . $phpgw->link('/admin/categories.php',"sort=$sort&order=$order&query=$query&start=$start" - . "&filter=$filter")); - } + $phpgw_info['flags']['currentapp'] = 'admin'; + include('../header.inc.php'); - $t = CreateObject('phpgwapi.Template',PHPGW_APP_TPL); - $t->set_file(array('form' => 'category_form.tpl')); - $t->set_block('form','add','addhandle'); - $t->set_block('form','edit','edithandle'); + $t = CreateObject('phpgwapi.Template',PHPGW_APP_TPL); + $t->set_file(array('form' => 'category_form.tpl')); + $t->set_block('form','add','addhandle'); + $t->set_block('form','edit','edithandle'); - $c = CreateObject('phpgwapi.categories'); - $c->categories($phpgw_info['user']['account_id'],'phpgw'); + $c = CreateObject('phpgwapi.categories'); + $c->app_name = 'phpgw'; - $hidden_vars = "\n" + $hidden_vars = "\n" . "\n" . "\n" . "\n" . "\n" . "\n"; - 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 !'); } - } - - $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,$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 updated !',$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); + } - $cats = $c->return_single($cat_id); + if ($exists == True) + { + $error[$errorcount++] = lang('That category name has been used already !'); + } + } - $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")); - $t->set_var('doneurl',$phpgw->link('/admin/categories.php',"start=$start&query=$query&sort=$sort&order=$order&filter=$filter")); + if ($cat_main && $cat_parent) + { + $main = $c->return_main($cat_parent); + if ($main != $cat_main) + { + $error[$errorcount++] = lang('You selected an invalid main category !'); + } + } - $t->set_var('hidden_vars',$hidden_vars); - $t->set_var('lang_name',lang('Category name')); - $t->set_var('lang_descr',lang('Category description')); - $t->set_var('lang_done',lang('Done')); - $t->set_var('lang_edit',lang('Edit')); - $t->set_var('lang_delete',lang('Delete')); + $cat_name = addslashes($cat_name); + $cat_description = addslashes($cat_description); + $cat_access = 'public'; - $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',$cats[0]['main'])); + if (! $error) + { + $c->edit($cat_id,$cat_parent,$cat_name,$cat_description,$cat_data,$cat_access,$cat_main); + } + } - $cat_id = $cats[0]['id']; + if ($errorcount) + { + $t->set_var('message',$phpgw->common->error_list($error)); + } - $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',$cats[0]['parent'])); + if (($submit) && (! $error) && (! $errorcount)) + { + $t->set_var('message',lang('Category x has been updated !',$cat_name)); + } - $t->set_var('edithandle',''); - $t->set_var('addhandle',''); + if ((! $submit) && (! $error) && (! $errorcount)) + { + $t->set_var('message',''); + } - $t->pparse('out','form'); - $t->pparse('edithandle','edit'); + $cats = $c->return_single($cat_id); - $phpgw->common->phpgw_footer(); + $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")); + $t->set_var('doneurl',$phpgw->link('/admin/categories.php',"start=$start&query=$query&sort=$sort&order=$order&filter=$filter")); + $t->set_var('hidden_vars',$hidden_vars); + $t->set_var('lang_name',lang('Category name')); + $t->set_var('lang_descr',lang('Category description')); + $t->set_var('lang_done',lang('Done')); + $t->set_var('lang_edit',lang('Edit')); + $t->set_var('lang_delete',lang('Delete')); + $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',$cats[0]['main'])); + + $cat_id = $cats[0]['id']; + $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',$cats[0]['parent'])); + + $t->set_var('edithandle',''); + $t->set_var('addhandle',''); + $t->pparse('out','form'); + $t->pparse('edithandle','edit'); + + $phpgw->common->phpgw_footer(); ?>