mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-22 16:03:47 +01:00
update edit_cats to move the subtree with the cat if the parent changes
This commit is contained in:
parent
6b1588ada5
commit
be05bc6e25
@ -52,6 +52,11 @@
|
||||
if($this->debug) { echo '<br>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 '<br>setting query to: "' . $query . '"'; }
|
||||
|
@ -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;
|
||||
@ -343,8 +338,6 @@
|
||||
$values['access'] = 'public';
|
||||
}
|
||||
|
||||
//_debug_array($values);
|
||||
|
||||
$error = $this->bo->check_values($values);
|
||||
if (is_array($error))
|
||||
{
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -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'])<br>";
|
||||
$subs[] = $cat;
|
||||
//echo "Adding($cat[cat_id])<br>";
|
||||
$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 "<p>reparent($id,$parent,$old_parent,$main)</p>\n";
|
||||
$main = $old_parent ? intval($this->id2name($old_parent,'main')) : $id;
|
||||
//echo "<p>reparent: $id/$main: $old_parent --> $parent</p>\n";
|
||||
|
||||
$subs = array();
|
||||
$this->subs($id,$subs,$main);
|
||||
//echo "<p>subs($id) = "; _debug_array($subs);
|
||||
|
||||
if (isset($subs[$parent]))
|
||||
{
|
||||
//echo "<p>new parent $parent is sub of $id</p>\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 "<p>$n: id=".$subs[$n]['cat_id']." set main to $new_main, subs[$n] = \n"; _debug_array($subs[$n]);
|
||||
$this->edit($subs[$n]);
|
||||
}
|
||||
}
|
||||
@ -693,7 +691,7 @@
|
||||
|
||||
$this->reparent($values);
|
||||
}
|
||||
else
|
||||
if (!isset($values['main']) || !isset($values['level']))
|
||||
{
|
||||
if ($values['parent'] && ($values['parent'] != 0))
|
||||
{
|
||||
@ -702,8 +700,8 @@
|
||||
}
|
||||
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']);
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
var $query;
|
||||
var $sort;
|
||||
var $order;
|
||||
var $cat_id;
|
||||
|
||||
function bocategories($cats_app)
|
||||
{
|
||||
@ -81,8 +82,11 @@
|
||||
$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($global_cats)
|
||||
{
|
||||
|
@ -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;$i<count($edata);$i++)
|
||||
{
|
||||
$GLOBALS['phpgw']->template->set_var('td_data$categories[$i]['cat_id']$categories[$i]['cat_id']','<input name="cat_data[' . $edata[$i] . ']" size="50" value="' . $cat_data[$edata[$i]] . '">');
|
||||
$GLOBALS['phpgw']->template->set_var('td_data','<input name="cat_data[' . $edata[$i] . ']" size="50" value="' . $cat_data[$edata[$i]] . '">');
|
||||
$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');
|
||||
|
Loading…
Reference in New Issue
Block a user