From be05bc6e25e599464a83c649d69d130291f959e1 Mon Sep 17 00:00:00 2001 From: ceb Date: Sat, 12 Oct 2002 21:18:23 +0000 Subject: [PATCH] update edit_cats to move the subtree with the cat if the parent changes --- admin/inc/class.bocategories.inc.php | 5 ++ admin/inc/class.uicategories.inc.php | 15 ++-- phpgwapi/inc/class.categories.inc.php | 81 +++++++++++----------- preferences/inc/class.bocategories.inc.php | 6 +- preferences/inc/class.uicategories.inc.php | 12 +++- 5 files changed, 62 insertions(+), 57 deletions(-) diff --git a/admin/inc/class.bocategories.inc.php b/admin/inc/class.bocategories.inc.php index fba62f5811..dfb9c7eb17 100644 --- a/admin/inc/class.bocategories.inc.php +++ b/admin/inc/class.bocategories.inc.php @@ -52,6 +52,11 @@ if($this->debug) { echo '
overriding start: "' . $this->start . '" now "' . $start . '"'; } $this->start = $start; } + else + { + $this->start = 0; + } + if((empty($query) && !empty($this->query)) || !empty($query)) { if($this->debug) { echo '
setting query to: "' . $query . '"'; } diff --git a/admin/inc/class.uicategories.inc.php b/admin/inc/class.uicategories.inc.php index 88c6223447..752fb268ce 100644 --- a/admin/inc/class.uicategories.inc.php +++ b/admin/inc/class.uicategories.inc.php @@ -125,11 +125,6 @@ $GLOBALS['phpgw']->template->set_var('actionurl',$GLOBALS['phpgw']->link('/index.php',$link_data)); $GLOBALS['phpgw']->template->set_var('doneurl',$GLOBALS['phpgw']->link('/admin/index.php')); - if(!$start) - { - $start = 0; - } - if (!$global_cats) { $global_cats = False; @@ -295,9 +290,9 @@ } $GLOBALS['phpgw']->template->set_var('category_list',$this->bo->cats->formated_list(array('format' => 'select', - 'type' => 'all', - 'selected' => $parent, - 'globals' => $global_cats))); + 'type' => 'all', + 'selected' => $parent, + 'globals' => $global_cats))); $GLOBALS['phpgw']->template->set_var('cat_name',$values['name']); $GLOBALS['phpgw']->template->set_var('cat_description',$values['descr']); @@ -343,8 +338,6 @@ $values['access'] = 'public'; } - //_debug_array($values); - $error = $this->bo->check_values($values); if (is_array($error)) { @@ -369,7 +362,7 @@ } $link_data['menuaction'] = 'admin.uicategories.edit'; - $link_data['cat_id'] = $this->cat_id; + $link_data['cat_id'] = $this->cat_id; $GLOBALS['phpgw']->template->set_var('actionurl',$GLOBALS['phpgw']->link('/index.php',$link_data)); $link_data['menuaction'] = 'admin.uicategories.delete'; diff --git a/phpgwapi/inc/class.categories.inc.php b/phpgwapi/inc/class.categories.inc.php index 38648a38d5..176c8474fc 100644 --- a/phpgwapi/inc/class.categories.inc.php +++ b/phpgwapi/inc/class.categories.inc.php @@ -145,7 +145,7 @@ } $filter = $this->filter($type); - + if (!$sort) { $sort = 'ASC'; @@ -194,7 +194,7 @@ $sql = "SELECT * from phpgw_categories WHERE (cat_appname='" . $this->app_name . "' AND" . $grant_cats . $global_cats . ")" . $parent_filter . $querymethod . $filter; - + if ($limit) { $this->db->limit_query($sql . $ordermethod,$start,__LINE__,__FILE__); @@ -330,23 +330,9 @@ { $this->db->query('SELECT * FROM phpgw_categories WHERE cat_id=' . intval($id),__LINE__,__FILE__); - if ($this->db->next_record()) - { - $cats = array - ( - 'cat_id' => $this->db->f('cat_id'), - 'owner' => $this->db->f('cat_owner'), - 'access' => $this->db->f('cat_access'), - 'app_name' => $this->db->f('cat_appname'), - 'main' => $this->db->f('cat_main'), - 'level' => $this->db->f('cat_level'), - 'parent' => $this->db->f('cat_parent'), - 'name' => $this->db->f('cat_name'), - 'descr' => $this->db->f('cat_description'), - 'data' => $this->db->f('cat_data') - ); - } - return $cats; + list($cat) = $this->db2cats(); + + return $cat; } /*! @@ -539,8 +525,8 @@ { if ($values['parent'] && $values['parent'] != 0) { - $values['main'] = intval($this->id2item(array('cat_id' => $values['parent'],'item' => 'main'))); - $values['level'] = intval($this->id2item(array('cat_id' => $values['parent'],'item' => 'level'))+1); + $values['main'] = intval($this->id2item(array('cat_id' => $values['parent'],'item' => 'main'))); + $values['level'] = intval($this->id2item(array('cat_id' => $values['parent'],'item' => 'level'))+1); } $values['descr'] = $this->db->db_addslashes($values['descr']); @@ -551,17 +537,11 @@ $id_col = 'cat_id,'; $id_val = $values['cat_id'].','; } - $this->db->query("INSERT INTO phpgw_categories (${id_col}cat_parent,cat_owner,cat_access,cat_appname,cat_name,cat_description,cat_data," . "cat_main,cat_level) VALUES ($id_val'" . intval($values['parent']) . "','" . $this->account_id . "','" . $values['access'] . "','" . $this->app_name . "','" . $values['name'] . "','" . $values['descr'] . "','" . $values['data'] . "','" . $values['main'] . "','" . $values['level'] . "')",__LINE__,__FILE__); - if (isset($values['cat_id'])) - { - $max = intval($values['cat_id']); - } - $max = $this->db->get_last_insert_id('phpgw_categories','cat_id'); if (!$values['parent'] || $values['parent'] == 0) @@ -603,9 +583,9 @@ { if ($cats[$i]['level'] == 1) { - $this->db->query("UPDATE phpgw_categories set cat_level=0, cat_parent=0, cat_main='" . intval($cats[$i]['id']) - . "' WHERE cat_id='" . intval($cats[$i]['id']) . "' AND cat_appname='" . $this->app_name . "'",__LINE__,__FILE__); - $new_main = $cats[$i]['id']; + $this->db->query("UPDATE phpgw_categories set cat_level=0, cat_parent=0, cat_main='" . intval($cats[$i]['cat_id']) + . "' WHERE cat_id='" . intval($cats[$i]['cat_id']) . "' AND cat_appname='" . $this->app_name . "'",__LINE__,__FILE__); + $new_main = $cats[$i]['cat_id']; } else { @@ -620,7 +600,7 @@ } $this->db->query("UPDATE phpgw_categories set cat_level='" . ($cats[$i]['level']-1) . "'" . $update_main . $update_parent - . " WHERE cat_id='" . intval($cats[$i]['id']) . "' AND cat_appname='" . $this->app_name . "'",__LINE__,__FILE__); + . " WHERE cat_id='" . intval($cats[$i]['cat_id']) . "' AND cat_appname='" . $this->app_name . "'",__LINE__,__FILE__); } } } @@ -634,7 +614,7 @@ { if (!is_array($main)) { - $this->db->query("SELECT * from phpgw_categories WHERE cat_main = $main"); + $this->db->query("SELECT * from phpgw_categories WHERE cat_main = $main",__LINE__,__FILE__); $main = $this->db2cats(); //echo "main: "; _debug_array($main); } @@ -644,8 +624,8 @@ $cat = $main[$n]; if ($cat['parent'] == $parent) { - //echo "Adding($cat['cat_id'])
"; - $subs[] = $cat; + //echo "Adding($cat[cat_id])
"; + $subs[$cat['cat_id']] = $cat; $this->subs($cat['cat_id'],$subs,$main); } } @@ -656,11 +636,28 @@ $id = $values['cat_id']; $parent = $values['parent']; $old_parent = $values['old_parent']; - $main = $old_parent ? intval($this->id2item(array('cat_id' => $old_parent,'item' => 'main'))) : $id; - //echo "

reparent($id,$parent,$old_parent,$main)

\n"; + $main = $old_parent ? intval($this->id2name($old_parent,'main')) : $id; + //echo "

reparent: $id/$main: $old_parent --> $parent

\n"; $subs = array(); $this->subs($id,$subs,$main); + //echo "

subs($id) = "; _debug_array($subs); + + if (isset($subs[$parent])) + { + //echo "

new parent $parent is sub of $id

\n"; + $parent = $subs[$parent]; + $parent['old_parent'] = $parent['parent']; + $parent['parent'] = intval($values['old_parent']); + $this->reparent($parent); + + unset($parent['old_parent']); + unset($parent['main']); + + $this->edit($parent); + $this->reparent($values); + return; + } $new_main = $parent ? $this->id2name($parent,'main') : $id; $new_parent_level = $parent ? $this->id2name($parent,'level') : -1; @@ -672,6 +669,7 @@ { $subs[$n]['main'] = $new_main; $subs[$n]['level'] -= $level_adj; + //echo "

$n: id=".$subs[$n]['cat_id']." set main to $new_main, subs[$n] = \n"; _debug_array($subs[$n]); $this->edit($subs[$n]); } } @@ -693,17 +691,17 @@ $this->reparent($values); } - else + if (!isset($values['main']) || !isset($values['level'])) { if ($values['parent'] && ($values['parent'] != 0)) { - $values['main'] = intval($this->id2item(array('cat_id' => $values['parent'],'item' => 'main'))); - $values['level'] = intval($this->id2item(array('cat_id' => $values['parent'],'item' => 'level'))+1); + $values['main'] = intval($this->id2item(array('cat_id' => $values['parent'],'item' => 'main'))); + $values['level'] = intval($this->id2item(array('cat_id' => $values['parent'],'item' => 'level'))+1); } else { - $values['main'] = intval($values['id']); - $values['level'] = 0; + $values['main'] = intval($values['cat_id']); + $values['parent'] = $values['level'] = 0; // parent need to be set to 0, as it can be '' } } @@ -714,7 +712,6 @@ . "', cat_data='" . $values['data'] . "', cat_parent=" . intval($values['parent']) . ", cat_access='" . $values['access'] . "', cat_main=" . $values['main'] . ", cat_level=" . $values['level'] . " WHERE cat_appname='" . $this->app_name . "' AND cat_id=" . intval($values['cat_id']); - $this->db->query($sql,__LINE__,__FILE__); return intval($values['cat_id']); } diff --git a/preferences/inc/class.bocategories.inc.php b/preferences/inc/class.bocategories.inc.php index 5e8ff75e70..48fece5dbb 100644 --- a/preferences/inc/class.bocategories.inc.php +++ b/preferences/inc/class.bocategories.inc.php @@ -19,6 +19,7 @@ var $query; var $sort; var $order; + var $cat_id; function bocategories($cats_app) { @@ -81,7 +82,10 @@ $this->query = $data['query']; $this->sort = $data['sort']; $this->order = $data['order']; - $this->cat_id = $data['cat_id']; + if(isset($data['cat_id'])) + { + $this->cat_id = $data['cat_id']; + } } function get_list($global_cats) diff --git a/preferences/inc/class.uicategories.inc.php b/preferences/inc/class.uicategories.inc.php index 3b43869591..2b813ca11c 100644 --- a/preferences/inc/class.uicategories.inc.php +++ b/preferences/inc/class.uicategories.inc.php @@ -52,9 +52,13 @@ 'start' => $this->start, 'query' => $this->query, 'sort' => $this->sort, - 'order' => $this->order, - 'cat_id' => $this->cat_id + 'order' => $this->order ); + + if(isset($this->cat_id)) + { + $data['cat_id'] = $this->cat_id; + } $this->bo->save_sessiondata($data,$cats_app); } @@ -350,7 +354,7 @@ $edata = explode(',',$extra); for($i=0;$itemplate->set_var('td_data$categories[$i]['cat_id']$categories[$i]['cat_id']',''); + $GLOBALS['phpgw']->template->set_var('td_data',''); $GLOBALS['phpgw']->template->set_var('lang_data',lang($edata[$i])); $GLOBALS['phpgw']->template->fp('rows','data_row',True); } @@ -430,6 +434,7 @@ $GLOBALS['phpgw']->template->set_var('doneurl',$GLOBALS['phpgw']->link('/index.php',$link_data)); $link_data['menuaction'] = 'preferences.uicategories.edit'; + $link_data['cat_id'] = $this->cat_id; $GLOBALS['phpgw']->template->set_var('actionurl',$GLOBALS['phpgw']->link('/index.php',$link_data)); $GLOBALS['phpgw']->template->set_var('old_parent',$cats['parent']); @@ -555,6 +560,7 @@ $GLOBALS['phpgw']->template->set_var('lang_no',lang('No')); $link_data['menuaction'] = 'preferences.uicategories.delete'; + $link_data['cat_id'] = $this->cat_id; $GLOBALS['phpgw']->template->set_var('action_url',$GLOBALS['phpgw']->link('/index.php',$link_data)); $GLOBALS['phpgw']->template->set_var('lang_yes',lang('Yes')); $GLOBALS['phpgw']->template->fp('phpgw_body','category_delete');