From 05653960d49a3fd46fc07801f5db0708c3d0113d Mon Sep 17 00:00:00 2001 From: ceb Date: Sat, 12 Oct 2002 18:27:22 +0000 Subject: [PATCH] update edit_cats to move the subtree with the cat if the parent changes --- preferences/inc/class.bocategories.inc.php | 30 +++- preferences/inc/class.uicategories.inc.php | 150 +++++++----------- .../templates/default/category_form.tpl | 10 +- 3 files changed, 86 insertions(+), 104 deletions(-) diff --git a/preferences/inc/class.bocategories.inc.php b/preferences/inc/class.bocategories.inc.php index 044d5da8c1..5e8ff75e70 100644 --- a/preferences/inc/class.bocategories.inc.php +++ b/preferences/inc/class.bocategories.inc.php @@ -31,11 +31,17 @@ $query = get_var('query',Array('GET','POST')); $sort = get_var('sort',Array('GET','POST')); $order = get_var('order',Array('GET','POST')); + $cat_id = intval(get_var('cat_id', array('POST','GET'))); if(!empty($start) || $start == '0' || $start == 0) { $this->start = $start; } + else + { + $this->start = 0; + } + if((empty($query) && !empty($this->query)) || !empty($query)) { $this->query = $query; @@ -49,6 +55,15 @@ { $this->order = $order; } + if(isset($cat_id)) + { + $this->cat_id = $cat_id; + } + + if($cat_id == 0) + { + unset($this->cat_id); + } } function save_sessiondata($data, $cats_app) @@ -62,10 +77,11 @@ $colum = $cats_app . '_cats'; $data = $GLOBALS['phpgw']->session->appsession('session_data',$column); - $this->start = $data['start']; - $this->query = $data['query']; - $this->sort = $data['sort']; - $this->order = $data['order']; + $this->start = $data['start']; + $this->query = $data['query']; + $this->sort = $data['sort']; + $this->order = $data['order']; + $this->cat_id = $data['cat_id']; } function get_list($global_cats) @@ -84,7 +100,7 @@ $values['access'] = 'public'; } - if ($values['id'] && $values['id'] != 0) + if ($values['cat_id'] && $values['cat_id'] != 0) { return $this->cats->edit($values); } @@ -131,7 +147,7 @@ ( 'type' => 'appandmains', 'cat_name' => $values['name'], - 'cat_id' => $values['id'] + 'cat_id' => $values['cat_id'] )); } else @@ -140,7 +156,7 @@ ( 'type' => 'appandsubs', 'cat_name' => $values['name'], - 'cat_id' => $values['id'] + 'cat_id' => $values['cat_id'] )); } diff --git a/preferences/inc/class.uicategories.inc.php b/preferences/inc/class.uicategories.inc.php index b8ca4d9e24..bccca867b5 100644 --- a/preferences/inc/class.uicategories.inc.php +++ b/preferences/inc/class.uicategories.inc.php @@ -42,16 +42,18 @@ $this->query = $this->bo->query; $this->sort = $this->bo->sort; $this->order = $this->bo->order; + $this->cat_id = $this->bo->cat_id; } function save_sessiondata($cats_app) { $data = array ( - 'start' => $this->start, - 'query' => $this->query, - 'sort' => $this->sort, - 'order' => $this->order + 'start' => $this->start, + 'query' => $this->query, + 'sort' => $this->sort, + 'order' => $this->order, + 'cat_id' => $this->cat_id ); $this->bo->save_sessiondata($data,$cats_app); } @@ -90,7 +92,6 @@ $extra = get_var('extra',array('POST','GET')); $global_cats = get_var('global_cats',array('POST','GET')); $cats_level = get_var('cats_level',array('POST','GET')); - $cat_id = get_var('cat_id',array('POST','GET')); $link_data = array ( @@ -119,11 +120,6 @@ $GLOBALS['phpgw']->template->set_var('actionurl',$GLOBALS['phpgw']->link('/index.php',$link_data)); $GLOBALS['phpgw']->template->set_var('doneurl',$GLOBALS['phpgw']->link('/preferences/index.php')); - if(!$this->start) - { - $this->start = 0; - } - if (!$global_cats) { $global_cats = False; @@ -186,7 +182,7 @@ $name = $spaceset . $GLOBALS['phpgw']->strip_html($cats[$i]['name']) . $appendix; } - $descr = $GLOBALS['phpgw']->strip_html($cats[$i]['description']); + $descr = $GLOBALS['phpgw']->strip_html($cats[$i]['descr']); if (!$descr) { $descr = ' '; } if (is_array($edata)) @@ -215,14 +211,13 @@ 'descr' => $descr )); - $GLOBALS['phpgw']->template->set_var('app_url',$GLOBALS['phpgw']->link('/' . $cats_app . '/index.php','cat_id=' . $cats[$i]['id'])); + $GLOBALS['phpgw']->template->set_var('app_url',$GLOBALS['phpgw']->link('/' . $cats_app . '/index.php','cat_id=' . $cats[$i]['cat_id'])); if ($cats_level || ($level == 0)) { if ($cats[$i]['owner'] == $this->account || $cats[$i]['app_name'] == 'phpgw') { $link_data['menuaction'] = 'preferences.uicategories.add'; - $link_data['cat_parent'] = $cats[$i]['id']; $GLOBALS['phpgw']->template->set_var('add_sub',$GLOBALS['phpgw']->link('/index.php',$link_data)); $GLOBALS['phpgw']->template->set_var('lang_sub_entry',lang('Add sub')); } @@ -233,7 +228,7 @@ $GLOBALS['phpgw']->template->set_var('lang_sub_entry',' '); } - $link_data['cat_id'] = $cats[$i]['id']; + $link_data['cat_id'] = $cats[$i]['cat_id']; if ($cats[$i]['owner'] == $this->account && $cats[$i]['app_name'] != 'phpgw') { $link_data['menuaction'] = 'preferences.uicategories.edit'; @@ -267,7 +262,6 @@ $extra = get_var('extra',array('POST','GET')); $global_cats = get_var('global_cats',array('POST','GET')); $cats_level = get_var('cats_level',array('POST','GET')); - $cat_id = get_var('cat_id',array('POST','GET')); $link_data = array ( @@ -278,40 +272,30 @@ 'cats_level' => $cats_level ); - $new_parent = get_var('new_parent',Array('POST')); - $cat_parent = get_var('cat_parent',Array('GET','POST')); - $cat_name = get_var('cat_name',Array('POST')); - $cat_description = get_var('cat_description',Array('POST')); - $cat_data = get_var('cat_data',Array('POST')); - $cat_access = get_var('cat_access',Array('POST')); - - if ($new_parent) - { - $cat_parent = $new_parent; - } + $values = get_var('values',array('POST')); + $cat_data = get_var('cat_data',array('POST')); if (get_var('submit',Array('POST'))) { - $data = serialize($cat_data); - - $values = array - ( - 'parent' => $cat_parent, - 'descr' => $cat_description, - 'name' => $cat_name, - 'access' => $cat_access, - 'data' => $data - ); - - $error = $this->bo->check_values($values); - if (is_array($error)) + if (is_array($cat_data)) { - $message = $GLOBALS['phpgw']->common->error_list($error); + $data = serialize($cat_data); } - else + + if (is_array($values)) { - $this->bo->save_cat($values); - $message = lang('Category x has been added !', $cat_name); + $values['data'] = $data; + + $error = $this->bo->check_values($values); + if (is_array($error)) + { + $message = $GLOBALS['phpgw']->common->error_list($error); + } + else + { + $this->cat_id = $this->bo->save_cat($values); + $message = lang('Category x has been added !', $values['name']); + } } } @@ -375,7 +359,6 @@ $extra = get_var('extra',array('POST','GET')); $global_cats = get_var('global_cats',array('POST','GET')); $cats_level = get_var('cats_level',array('POST','GET')); - $cat_id = get_var('cat_id',array('POST','GET')); $link_data = array ( @@ -383,52 +366,39 @@ 'cats_app' => $cats_app, 'extra' => $extra, 'global_cats' => $global_cats, - 'cats_level' => $cats_level, - 'cat_id' => $cat_id + 'cats_level' => $cats_level ); - if (!$cat_id) + if (!$this->cat_id) { Header('Location: ' . $GLOBALS['phpgw']->link('/index.php',$link_data)); } - $new_parent = get_var('new_parent',Array('POST')); - $cat_parent = get_var('cat_parent',Array('POST')); - $cat_name = get_var('cat_name',Array('POST')); - $cat_description = get_var('cat_description',Array('POST')); - $cat_data = get_var('cat_data',Array('POST')); - $cat_access = get_var('cat_access',Array('POST')); - $old_parent = get_var('old_parent',array('POST')); - - if ($new_parent) - { - $cat_parent = $new_parent; - } + $values = get_var('values',Array('POST')); + $cat_data = get_var('cat_data',Array('POST')); if (get_var('submit',Array('POST'))) { - $data = serialize($cat_data); - - $values = array - ( - 'id' => $cat_id, - 'parent' => $cat_parent, - 'old_parent' => $old_parent, - 'descr' => $cat_description, - 'name' => $cat_name, - 'access' => $cat_access, - 'data' => $data - ); - - $error = $this->bo->check_values($values); - if (is_array($error)) + if (is_array($cat_data)) { - $message = $GLOBALS['phpgw']->common->error_list($error); + $data = serialize($cat_data); } - else + + if (is_array($values)) { - $cat_id = $this->bo->save_cat($values); - $message = lang('Category x has been updated !',$cat_name); + $values['cat_id'] = $this->cat_id; + $values['data'] = $data; + + $error = $this->bo->check_values($values); + if (is_array($error)) + { + $message = $GLOBALS['phpgw']->common->error_list($error); + } + else + { + $this->cat_id = $this->bo->save_cat($values); + $message = lang('Category x has been updated !',$values['name']); + } } } @@ -442,9 +412,7 @@ $this->set_langs(); - $cats = $this->bo->cats->return_single($cat_id); - - $GLOBALS['phpgw']->template->set_var('hidden_vars',''); + $cats = $this->bo->cats->return_single($this->cat_id); $GLOBALS['phpgw']->template->set_var('title_categories',lang('Edit x category for',lang($cats_app))); $GLOBALS['phpgw']->template->set_var('message',$message); @@ -454,8 +422,9 @@ $link_data['menuaction'] = 'preferences.uicategories.edit'; $GLOBALS['phpgw']->template->set_var('actionurl',$GLOBALS['phpgw']->link('/index.php',$link_data)); - $GLOBALS['phpgw']->template->set_var('cat_name',$GLOBALS['phpgw']->strip_html($cats[0]['name'])); - $GLOBALS['phpgw']->template->set_var('cat_description',$GLOBALS['phpgw']->strip_html($cats[0]['description'])); + $GLOBALS['phpgw']->template->set_var('old_parent',$cats['parent']); + $GLOBALS['phpgw']->template->set_var('cat_name',$GLOBALS['phpgw']->strip_html($cats['name'])); + $GLOBALS['phpgw']->template->set_var('cat_description',$GLOBALS['phpgw']->strip_html($cats['descr'])); if (!$global_cats) { @@ -471,16 +440,15 @@ $type = 'mains'; } - $GLOBALS['phpgw']->template->set_var('category_list',$this->bo->cats->formated_list('select',$type,$cats[0]['parent'],$global_cats)); + $GLOBALS['phpgw']->template->set_var('category_list',$this->bo->cats->formated_list('select',$type,$cats['parent'],$global_cats)); - $GLOBALS['phpgw']->template->set_var('access',''); + $GLOBALS['phpgw']->template->set_var('access',$cats['access'] == 'private' ?' checked':''); if ($extra) { $edata = explode(',',$extra); - $data = unserialize($cats[0]['data']); + $data = unserialize($cats['data']); for($i=0;$itemplate->set_var('td_data',''); @@ -510,7 +478,6 @@ $extra = get_var('extra',array('POST','GET')); $global_cats = get_var('global_cats',array('POST','GET')); $cats_level = get_var('cats_level',array('POST','GET')); - $cat_id = get_var('cat_id',array('POST','GET')); $link_data = array ( @@ -518,11 +485,10 @@ 'cats_app' => $cats_app, 'extra' => $extra, 'global_cats' => $global_cats, - 'cats_level' => $cats_level, - 'cat_id' => $cat_id + 'cats_level' => $cats_level ); - if (!$cat_id) + if (!$this->cat_id) { Header('Location: ' . $GLOBALS['phpgw']->link('/index.php',$link_data)); } @@ -565,7 +531,7 @@ ( 'type' => 'subs', 'cat_name' => '', - 'cat_id' => $cat_id + 'cat_id' => $this->cat_id )); if ($exists) diff --git a/preferences/templates/default/category_form.tpl b/preferences/templates/default/category_form.tpl index ab3d453172..48505dad0b 100644 --- a/preferences/templates/default/category_form.tpl +++ b/preferences/templates/default/category_form.tpl @@ -13,22 +13,22 @@
{lang_parent} - + {lang_name} - + {lang_descr} - + {rows} {lang_access} - {access} + @@ -59,7 +59,7 @@
- {hidden_vars} + {delete}