From 8ab7b9f7717d0a7b3272ffd617a9137631407528 Mon Sep 17 00:00:00 2001 From: Miles Lott Date: Tue, 2 Oct 2001 13:35:04 +0000 Subject: [PATCH] Add new 3-layer cats editor --- admin/inc/class.bocategories.inc.php | 125 +++++++ admin/inc/class.uicategories.inc.php | 476 +++++++++++++++++++++++++++ admin/inc/hook_admin.inc.php | 2 +- 3 files changed, 602 insertions(+), 1 deletion(-) create mode 100644 admin/inc/class.bocategories.inc.php create mode 100644 admin/inc/class.uicategories.inc.php diff --git a/admin/inc/class.bocategories.inc.php b/admin/inc/class.bocategories.inc.php new file mode 100644 index 0000000000..03f8cfcaac --- /dev/null +++ b/admin/inc/class.bocategories.inc.php @@ -0,0 +1,125 @@ +cats = CreateObject('phpgwapi.categories'); + + $this->read_sessiondata(); + + /* _debug_array($GLOBALS['HTTP_POST_VARS']); */ + /* Might change this to '' at the end---> */ + $start = $GLOBALS['HTTP_POST_VARS']['start'] ? $GLOBALS['HTTP_POST_VARS']['start'] : $GLOBALS['HTTP_GET_VARS']['start']; + $query = $GLOBALS['HTTP_POST_VARS']['query'] ? $GLOBALS['HTTP_POST_VARS']['query'] : $GLOBALS['HTTP_GET_VARS']['query']; + $sort = $GLOBALS['HTTP_POST_VARS']['sort'] ? $GLOBALS['HTTP_POST_VARS']['sort'] : $GLOBALS['HTTP_GET_VARS']['sort']; + $order = $GLOBALS['HTTP_POST_VARS']['order'] ? $GLOBALS['HTTP_POST_VARS']['order'] : $GLOBALS['HTTP_GET_VARS']['order']; + $cat_id = $GLOBALS['HTTP_POST_VARS']['cat_id'] ? $GLOBALS['HTTP_POST_VARS']['cat_id'] : $GLOBALS['HTTP_GET_VARS']['cat_id']; + + if(!empty($start) || $start == '0' || $start == 0) + { + if($this->debug) { echo '
overriding start: "' . $this->start . '" now "' . $start . '"'; } + $this->start = $start; + } + if((empty($query) && !empty($this->query)) || !empty($query)) + { + if($this->debug) { echo '
setting query to: "' . $query . '"'; } + $this->query = $query; + } + + if(isset($cat_id)) + { + $this->cat_id = $cat_id; + } + if($cat_id == '0' || $cat_id == 0 || $cat_id == '') + { + unset($this->cat_id); + } + if(isset($sort)) + { + $this->sort = $sort; + } + if(isset($order)) + { + $this->order = $order; + } + } + + function save_sessiondata($data) + { + if($this->debug) { echo '
Save:'; _debug_array($data); } + $GLOBALS['phpgw']->session->appsession('session_data','admin_cats',$data); + } + + function read_sessiondata() + { + $data = $GLOBALS['phpgw']->session->appsession('session_data','admin_cats'); + if($this->debug) { echo '
Read:'; _debug_array($data); } + + $this->start = $data['start']; + $this->query = $data['query']; + $this->sort = $data['sort']; + $this->order = $data['order']; + if(isset($data['cat_id'])) + { + $this->cat_id = $data['cat_id']; + } + } + + function get_list() + { + if($this->debug) { echo '
querying: "' . $this->query . '"'; } + return $this->cats->return_array('all',$this->start,True,$this->query,$this->sort,$this->order,True); + } + + function edit($data) + { + return $this->cats->edit($data); + } + + function add($data) + { + return $this->cats->add($data); + } + + function exists($data) + { + $data['type'] = $data['type'] ? $data['type'] : ''; + $data['cat_id'] = $data['cat_id'] ? $data['cat_id'] : ''; + return $this->cats->exists($data['type'],$data['cat_name'],$data['cat_id']); + } + + function formatted_list($data) + { + return $this->cats->formated_list($data['select'],$data['all'],$data['cat_parent']); + } + + function delete($cat_id,$subs=False) + { + return $this->cats->delete($cat_id,$subs); + } + } diff --git a/admin/inc/class.uicategories.inc.php b/admin/inc/class.uicategories.inc.php new file mode 100644 index 0000000000..e1582e1f07 --- /dev/null +++ b/admin/inc/class.uicategories.inc.php @@ -0,0 +1,476 @@ + True, + 'add' => True, + 'edit' => True, + 'delete' => True + ); + + function uicategories() + { + $this->bo = CreateObject('admin.bocategories'); + $this->template = $GLOBALS['phpgw']->template; + $this->nextmatchs = CreateObject('phpgwapi.nextmatchs'); + + $this->start = $this->bo->start; + $this->query = $this->bo->query; + $this->sort = $this->bo->sort; + $this->order = $this->bo->order; + $this->cat_id = $this->bo->cat_id; + if($this->debug) { $this->_debug_sqsof(); } + } + + function _debug_sqsof() + { + $data = array( + 'start' => $this->start, + 'query' => $this->query, + 'sort' => $this->sort, + 'order' => $this->order, + 'cat_id' => $this->cat_id + ); + echo '
UI:
'; + _debug_array($data); + } + + /* Called only by index() */ + function save_sessiondata() + { + $data = array( + 'start' => $this->start, + 'query' => $this->query, + 'sort' => $this->sort, + 'order' => $this->order, + ); + if(isset($this->cat_id)) + { + $data['cat_id'] = $this->cat_id; + } + $this->bo->save_sessiondata($data); + } + + function index() + { + $GLOBALS['phpgw']->common->phpgw_header(); + echo parse_navbar(); + + $this->template->set_file(array( + 'cat_list_t' => 'listcats.tpl', + 'cat_list' => 'listcats.tpl' + )); + $this->template->set_block('cat_list_t','cat_list','list'); + + /* + $common_hidden_vars = '' . "\n" + . '' . "\n" + . '' . "\n" + . '' . "\n" + . '' . "\n"; + */ + + $this->template->set_var('lang_action',lang('Category list')); + $this->template->set_var('add_action',$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uicategories.add')); + $this->template->set_var('lang_add',lang('Add')); + $this->template->set_var('title_categories',lang('Global categories')); + $this->template->set_var('lang_search',lang('Search')); + $this->template->set_var('query',$this->query); + $this->template->set_var('actionurl',$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uicategories.index')); + $this->template->set_var('lang_done',lang('Done')); + $this->template->set_var('doneurl',$GLOBALS['phpgw']->link('/admin/index.php')); + + if(!$start) + { + $start = 0; + } + + $this->bo->cats->app_name = 'phpgw'; + $categories = $this->bo->get_list(); + + $left = $this->nextmatchs->left('/index.php',$this->start,$this->bo->cats->total_records,'menuaction=admin.uicategories.index'); + $right = $this->nextmatchs->right('/index.php',$this->start,$this->bo->cats->total_records,'menuaction=admin.uicategories.index'); + $this->template->set_var('left',$left); + $this->template->set_var('right',$right); + + $this->template->set_var('lang_showing',$this->nextmatchs->show_hits($this->bo->cats->total_records,$this->start)); + + $this->template->set_var('th_bg',$GLOBALS['phpgw_info']['theme']['th_bg']); + $this->template->set_var('sort_name',$this->nextmatchs->show_sort_order($this->sort,'cat_name',$this->order,'/index.php',lang('Name'),'&menuaction=admin.uicategories.index')); + $this->template->set_var('sort_description',$this->nextmatchs->show_sort_order($this->sort,'cat_description',$this->order,'/index.php',lang('Description'),'&menuaction=admin.uicategories.index')); + $this->template->set_var('lang_sub',lang('Add sub')); + $this->template->set_var('lang_edit',lang('Edit')); + $this->template->set_var('lang_delete',lang('Delete')); + + for ($i=0;$inextmatchs->alternate_row_color($tr_color); + $this->template->set_var(tr_color,$tr_color); + + $id = $categories[$i]['id']; + $level = $categories[$i]['level']; + + if ($level > 0) + { + $space = '  '; + $spaceset = str_repeat($space,$level); + $name = $spaceset . $GLOBALS['phpgw']->strip_html($categories[$i]['name']); + } + + $descr = $GLOBALS['phpgw']->strip_html($categories[$i]['description']); + if (!$descr) { $descr = ' '; } + + if ($level == 0) + { + $name = '' . $GLOBALS['phpgw']->strip_html($categories[$i]['name']) . ''; + $descr = '' . $descr . ''; + } + + $this->template->set_var(array('name' => $name, + 'descr' => $descr)); + + $this->template->set_var('add_sub',$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uicategories.add&cat_parent=' . $id)); + $this->template->set_var('lang_sub_entry',lang('Add sub')); + $this->template->set_var('edit',$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uicategories.edit&cat_id=' . $id)); + $this->template->set_var('lang_edit_entry',lang('Edit')); + $this->template->set_var('delete',$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uicategories.delete&cat_id=' . $id)); + $this->template->set_var('lang_delete_entry',lang('Delete')); + + $this->template->parse('list','cat_list',True); + } + + $this->save_sessiondata(); + + $this->template->parse('out','cat_list_t',True); + $this->template->p('out'); + } + + function add() + { + $GLOBALS['phpgw']->common->phpgw_header(); + echo parse_navbar(); + + $new_parent = $GLOBALS['HTTP_POST_VARS']['new_parent']; + $submit = $GLOBALS['HTTP_POST_VARS']['submit']; + $cat_parent = $GLOBALS['HTTP_POST_VARS']['cat_parent']; + $cat_name = $GLOBALS['HTTP_POST_VARS']['cat_name']; + $cat_description = $GLOBALS['HTTP_POST_VARS']['cat_description']; + + $this->template->set_file(array('form' => 'category_form.tpl')); + $this->template->set_block('form','add','addhandle'); + $this->template->set_block('form','edit','edithandle'); + + $this->bo->cats->app_name = 'phpgw'; + + if ($new_parent) + { + $cat_parent = $new_parent; + } + + if ($submit) + { + $errorcount = 0; + + if (!$cat_name) + { + $error[$errorcount++] = lang('Please enter a name'); + } + + if (!$error) + { + if (!$cat_parent) + { + $exists = $this->bo->exists(array( + 'type' => 'appandmains', + 'cat_name' => $cat_name, + 'cat_id' => '' + )); + } + else + { + $exists = $this->bo->exists(array( + 'type' => 'appandsubs', + 'cat_name' => $cat_name, + 'cat_id' => '' + )); + } + + if ($exists == True) + { + $error[$errorcount++] = lang('That name has been used already'); + } + } + + if (!$error) + { + $this->bo->add(array( + 'parent' => $cat_parent, + 'descr' => $cat_description, + 'name' => $cat_name, + 'access' => 'public' + )); + } + } + + if ($errorcount) + { + $this->template->set_var('message',$GLOBALS['phpgw']->common->error_list($error)); + } + + if (($submit) && (! $error) && (! $errorcount)) + { + $this->template->set_var('message',lang('Category x has been added !', $cat_name)); + } + + if ((! $submit) && (! $error) && (! $errorcount)) + { + $this->template->set_var('message',''); + } + + $this->template->set_var('title_categories',lang('Add global category')); + $this->template->set_var('actionurl',$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uicategories.add')); + $this->template->set_var('doneurl',$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uicategories.index')); + $this->template->set_var('hidden_vars',''); + $this->template->set_var('lang_parent',lang('Parent category')); + $this->template->set_var('lang_none',lang('None')); + $this->template->set_var('category_list',$this->bo->formatted_list(array('select' => 'select','all' => 'all','cat_parent' => $cat_parent))); + $this->template->set_var('lang_name',lang('Name')); + $this->template->set_var('lang_descr',lang('Description')); + $this->template->set_var('cat_name',$cat_name); + $this->template->set_var('cat_description',$cat_description); + $this->template->set_var('lang_add',lang('Add')); + $this->template->set_var('lang_reset',lang('Clear Form')); + $this->template->set_var('lang_done',lang('Done')); + + $this->template->set_var('edithandle',''); + $this->template->set_var('addhandle',''); + $this->template->pparse('out','form'); + $this->template->pparse('addhandle','add'); + } + + function edit() + { + if (!$this->cat_id) + { + Header('Location: ' . $GLOBALS['phpgw']->link('/index.php','menuaction=admin.uicategories.index')); + } + + $GLOBALS['phpgw']->common->phpgw_header(); + echo parse_navbar(); + + $new_parent = $GLOBALS['HTTP_POST_VARS']['new_parent']; + $submit = $GLOBALS['HTTP_POST_VARS']['submit']; + $cat_parent = $GLOBALS['HTTP_POST_VARS']['cat_parent']; + $cat_name = $GLOBALS['HTTP_POST_VARS']['cat_name']; + $cat_description = $GLOBALS['HTTP_POST_VARS']['cat_description']; + + $this->template->set_file(array('form' => 'category_form.tpl')); + $this->template->set_block('form','add','addhandle'); + $this->template->set_block('form','edit','edithandle'); + + $this->bo->cats->app_name = 'phpgw'; + + $hidden_vars = '' . "\n"; + + if ($new_parent) + { + $cat_parent = $new_parent; + } + + if ($submit) + { + $errorcount = 0; + + if (!$cat_name) + { + $error[$errorcount++] = lang('Please enter a name'); + } + + if (!$error) + { + if (!$cat_parent) + { + $exists = $this->bo->exists(array( + 'type' => 'appandmains', + 'cat_name' => $cat_name, + 'cat_id' => $this->cat_id + )); + } + else + { + $exists = $this->bo->exists(array( + 'type' => 'appandsubs', + 'cat_name' => $cat_name, + 'cat_id' => $this->cat_id + )); + } + + if ($exists == True) + { + $error[$errorcount++] = lang('That name has been used already'); + } + } + + if (!$error) + { + $this->bo->cats->edit(array( + 'access' => 'public', + 'parent' => $cat_parent, + 'descr' => $cat_description, + 'name' => $cat_name, + 'id' => $this->cat_id + )); + } + } + + if ($errorcount) + { + $this->template->set_var('message',$GLOBALS['phpgw']->common->error_list($error)); + } + + if (($submit) && (!$error) && (!$errorcount)) + { + $this->template->set_var('message',lang('Category x has been updated !',$cat_name)); + } + + if ((!$submit) && (!$error) && (!$errorcount)) + { + $this->template->set_var('message',''); + } + + $cats = $this->bo->cats->return_single($this->cat_id); + + $this->template->set_var('title_categories',lang('Edit global category')); + $this->template->set_var('lang_parent',lang('Parent category')); + $this->template->set_var('lang_none',lang('None')); + $this->template->set_var('actionurl',$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uicategories.edit')); + $this->template->set_var('deleteurl',$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uicategories.delete&cat_id=' . $this->cat_id)); + $this->template->set_var('doneurl',$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uicategories.index')); + $this->template->set_var('hidden_vars',$hidden_vars); + $this->template->set_var('lang_name',lang('Name')); + $this->template->set_var('lang_descr',lang('Description')); + $this->template->set_var('lang_done',lang('Done')); + $this->template->set_var('lang_edit',lang('Edit')); + $this->template->set_var('lang_delete',lang('Delete')); + + $this->template->set_var('cat_name',$GLOBALS['phpgw']->strip_html($cats[0]['name'])); + $this->template->set_var('cat_description',$GLOBALS['phpgw']->strip_html($cats[0]['description'])); + $this->template->set_var('category_list',$this->bo->formatted_list(array('select' => 'select','all' => 'all', 'cat_parent' => $cats[0]['parent']))); + + $this->template->set_var('edithandle',''); + $this->template->set_var('addhandle',''); + $this->template->pparse('out','form'); + $this->template->pparse('edithandle','edit'); + } + + function delete() + { + if (!$this->cat_id) + { + Header('Location: ' . $GLOBALS['phpgw']->link('/index.php','menuaction=admin.uicategories.index')); + } + + $this->bo->cats->app_name = 'phpgw'; + + if ($GLOBALS['HTTP_POST_VARS']['confirm']) + { + if ($GLOBALS['HTTP_POST_VARS']['subs']) + { + $this->bo->delete($this->cat_id,True); + } + else + { + $this->bo->delete($this->cat_id); + } + Header('Location: ' . $GLOBALS['phpgw']->link('/index.php','menuaction=admin.uicategories.index')); + } + else + { + $hidden_vars = '' . "\n"; + + $this->template->set_file(array('category_delete' => 'delete_cat.tpl')); + $this->template->set_block('category_delete','delete','deletehandle'); + $this->template->set_block('category_delete','done','donehandle'); + + $nolink = $GLOBALS['phpgw']->link('/index.php','menuaction=admin.uicategories.index&cat_id=' . $this->cat_id); + + $apps_cats = $this->bo->exists(array( + 'type' => 'subs', + 'cat_name' => '', + 'cat_id' => $this->cat_id + )); + + $GLOBALS['phpgw']->common->phpgw_header(); + echo parse_navbar(); + + if ($apps_cats) + { + $this->template->set_var('messages',lang('This category is currently being used by applications as a parent category') . '
' + . lang('You will need to remove the subcategories before you can delete the parent category')); + $this->template->set_var('hidden_vars',$hidden_vars); + $this->template->set_var('lang_subs',''); + $this->template->set_var('subs',''); + $this->template->set_var('nolink',$nolink); + $this->template->set_var('lang_done',lang('Done')); + $this->template->set_var('deletehandle',''); + $this->template->set_var('donehandle',''); + $this->template->pparse('out','category_delete'); + $this->template->pparse('donehandle','done'); + } + else + { + $this->template->set_var('messages',lang('Are you sure you want to delete this category ?')); + $this->template->set_var('hidden_vars',$hidden_vars); + + $exists = $this->bo->exists(array( + 'type' => 'subs', + 'cat_name' => '', + 'cat_id' => $this->cat_id + )); + if ($exists) + { + $this->template->set_var('lang_subs',lang('Do you also want to delete all global subcategories ?')); + $this->template->set_var('subs',''); + } + else + { + $this->template->set_var('lang_subs',''); + $this->template->set_var('subs', ''); + } + + $this->template->set_var('nolink',$nolink); + $this->template->set_var('lang_no',lang('No')); + $this->template->set_var('action_url',$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uicategories.delete&cat_id=' . $this->cat_id)); + $this->template->set_var('lang_yes',lang('Yes')); + $this->template->set_var('deletehandle',''); + $this->template->set_var('donehandle',''); + $this->template->pparse('out','category_delete'); + $this->template->pparse('deletehandle','delete'); + } + } + } + } +?> diff --git a/admin/inc/hook_admin.inc.php b/admin/inc/hook_admin.inc.php index e5c5a037ab..4f5fdc20a9 100644 --- a/admin/inc/hook_admin.inc.php +++ b/admin/inc/hook_admin.inc.php @@ -38,7 +38,7 @@ if (! $GLOBALS['phpgw']->acl->check('global_categories_access',1,'admin')) { - $file['Global Categories'] = $GLOBALS['phpgw']->link('/admin/categories.php'); + $file['Global Categories'] = $GLOBALS['phpgw']->link('/index.php','menuaction=admin.uicategories.index'); } if (! $GLOBALS['phpgw']->acl->check('mainscreen_message_access',1,'admin'))