update edit_cats to move the subtree with the cat if the parent changes

This commit is contained in:
ceb 2002-10-12 17:23:56 +00:00
parent 7a07eef5b5
commit aac6b5e5f4
4 changed files with 172 additions and 172 deletions

View File

@ -116,7 +116,7 @@
function save_cat($values) function save_cat($values)
{ {
if ($values['id'] && $values['id'] != 0) if ($values['cat_id'] && $values['cat_id'] != 0)
{ {
return $this->cats->edit($values); return $this->cats->edit($values);
} }
@ -170,7 +170,7 @@
( (
'type' => 'appandmains', 'type' => 'appandmains',
'cat_name' => $values['name'], 'cat_name' => $values['name'],
'cat_id' => $values['id'] 'cat_id' => $values['cat_id']
)); ));
} }
else else
@ -179,7 +179,7 @@
( (
'type' => 'appandsubs', 'type' => 'appandsubs',
'cat_name' => $values['name'], 'cat_name' => $values['name'],
'cat_id' => $values['id'] 'cat_id' => $values['cat_id']
)); ));
} }

View File

@ -150,9 +150,9 @@
for ($i=0;$i<count($categories);$i++) for ($i=0;$i<count($categories);$i++)
{ {
$tr_color = $this->nextmatchs->alternate_row_color($tr_color); $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
$GLOBALS['phpgw']->template->set_var(tr_color,$tr_color); $GLOBALS['phpgw']->template->set_var('tr_color',$tr_color);
$id = $categories[$i]['id']; $id = $categories[$i]['cat_id'];
$level = $categories[$i]['level']; $level = $categories[$i]['level'];
$cat_name = $GLOBALS['phpgw']->strip_html($categories[$i]['name']); $cat_name = $GLOBALS['phpgw']->strip_html($categories[$i]['name']);
@ -163,7 +163,7 @@
$cat_name = $spaceset . $cat_name; $cat_name = $spaceset . $cat_name;
} }
$descr = $GLOBALS['phpgw']->strip_html($categories[$i]['description']); $descr = $GLOBALS['phpgw']->strip_html($categories[$i]['descr']);
if (!$descr) { $descr = '&nbsp;'; } if (!$descr) { $descr = '&nbsp;'; }
if ($level == 0) if ($level == 0)
@ -236,7 +236,7 @@
function add() function add()
{ {
$global_cats = get_var('global_cats',array('POST','GET')); $global_cats = get_var('global_cats',array('POST','GET'));
$link_data = array $link_data = array
( (
@ -249,11 +249,7 @@
$this->set_langs(); $this->set_langs();
$new_parent = $GLOBALS['HTTP_POST_VARS']['new_parent']; $values = get_var('values',array('POST'));
$submit = $GLOBALS['HTTP_POST_VARS']['submit'];
$cat_parent = $GLOBALS['HTTP_POST_VARS']['cat_parent'] ? $GLOBALS['HTTP_POST_VARS']['cat_parent'] : $GLOBALS['HTTP_GET_VARS']['cat_parent'];
$cat_name = $GLOBALS['HTTP_POST_VARS']['cat_name'];
$cat_description = $GLOBALS['HTTP_POST_VARS']['cat_description'];
$GLOBALS['phpgw']->template->set_file(array('cat_form' => 'category_form.tpl')); $GLOBALS['phpgw']->template->set_file(array('cat_form' => 'category_form.tpl'));
$GLOBALS['phpgw']->template->set_block('cat_form','add'); $GLOBALS['phpgw']->template->set_block('cat_form','add');
@ -271,20 +267,12 @@
$GLOBALS['phpgw']->template->set_var('title_categories',lang('Add global category')); $GLOBALS['phpgw']->template->set_var('title_categories',lang('Add global category'));
} }
if ($new_parent) if (get_var('submit',array('POST')))
{ {
$cat_parent = $new_parent; if(is_array($values))
} {
$values['access'] = 'public';
if ($submit) }
{
$values = array
(
'parent' => $cat_parent,
'descr' => $cat_description,
'name' => $cat_name,
'access' => 'public'
);
$error = $this->bo->check_values($values); $error = $this->bo->check_values($values);
if (is_array($error)) if (is_array($error))
@ -301,7 +289,8 @@
$link_data['menuaction'] = 'admin.uicategories.add'; $link_data['menuaction'] = 'admin.uicategories.add';
$GLOBALS['phpgw']->template->set_var('actionurl',$GLOBALS['phpgw']->link('/index.php',$link_data)); $GLOBALS['phpgw']->template->set_var('actionurl',$GLOBALS['phpgw']->link('/index.php',$link_data));
$GLOBALS['phpgw']->template->set_var('category_list',$this->bo->formatted_list(array( $GLOBALS['phpgw']->template->set_var('category_list',$this->bo->formatted_list(array
(
'select' => 'select', 'select' => 'select',
'all' => 'all', 'all' => 'all',
'cat_parent' => $cat_parent, 'cat_parent' => $cat_parent,
@ -335,12 +324,7 @@
$this->set_langs(); $this->set_langs();
$new_parent = $GLOBALS['HTTP_POST_VARS']['new_parent']; $values = get_var('values',array('POST'));
$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'];
$old_parent = $GLOBALS['HTTP_POST_VARS']['old_parent'];
$GLOBALS['phpgw']->template->set_file(array('cat_form' => 'category_form.tpl')); $GLOBALS['phpgw']->template->set_file(array('cat_form' => 'category_form.tpl'));
$GLOBALS['phpgw']->template->set_block('cat_form','add'); $GLOBALS['phpgw']->template->set_block('cat_form','add');
@ -349,22 +333,13 @@
$GLOBALS['phpgw']->template->set_var('doneurl',$GLOBALS['phpgw']->link('/index.php',$link_data)); $GLOBALS['phpgw']->template->set_var('doneurl',$GLOBALS['phpgw']->link('/index.php',$link_data));
if ($new_parent) if (get_var('submit',array('POST')))
{ {
$cat_parent = $new_parent; if (is_array($values))
} {
$values['cat_id'] = $this->cat_id;
if ($submit) $values['access'] = 'public';
{ }
$values = array
(
'id' => $this->cat_id,
'old_parent' => $old_parent,
'parent' => $cat_parent,
'descr' => $cat_description,
'name' => $cat_name,
'access' => 'public'
);
$error = $this->bo->check_values($values); $error = $this->bo->check_values($values);
if (is_array($error)) if (is_array($error))
@ -389,21 +364,20 @@
$GLOBALS['phpgw']->template->set_var('title_categories',lang('Edit global category')); $GLOBALS['phpgw']->template->set_var('title_categories',lang('Edit global category'));
} }
$hidden_vars = '<input type="hidden" name="cat_id" value="' . $this->cat_id . '">' . "\n"
. '<input type="hidden" name="old_parent" value="' . $cats[0]['parent'] . '">' . "\n";
$GLOBALS['phpgw']->template->set_var('hidden_vars',$hidden_vars);
$link_data['menuaction'] = 'admin.uicategories.edit'; $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)); $GLOBALS['phpgw']->template->set_var('actionurl',$GLOBALS['phpgw']->link('/index.php',$link_data));
$link_data['menuaction'] = 'admin.uicategories.delete'; $link_data['menuaction'] = 'admin.uicategories.delete';
$GLOBALS['phpgw']->template->set_var('deleteurl',$GLOBALS['phpgw']->link('/index.php',$link_data)); $GLOBALS['phpgw']->template->set_var('deleteurl',$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('old_parent',$cats['parent']);
$GLOBALS['phpgw']->template->set_var('cat_description',$GLOBALS['phpgw']->strip_html($cats[0]['description']));
$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']));
$GLOBALS['phpgw']->template->set_var('category_list',$this->bo->formatted_list(array('select' => 'select', $GLOBALS['phpgw']->template->set_var('category_list',$this->bo->formatted_list(array('select' => 'select',
'all' => 'all', 'all' => 'all',
'cat_parent' => $cats[0]['parent'], 'cat_parent' => $cats['parent'],
'global_cats' => $global_cats))); 'global_cats' => $global_cats)));
$GLOBALS['phpgw']->template->parse('buttons','edit'); $GLOBALS['phpgw']->template->parse('buttons','edit');
$GLOBALS['phpgw']->template->fp('phpgw_body','form'); $GLOBALS['phpgw']->template->fp('phpgw_body','form');
@ -473,7 +447,6 @@
)); ));
$GLOBALS['phpgw']->common->phpgw_header(); $GLOBALS['phpgw']->common->phpgw_header();
$GLOBALS['phpgw']->template->set_var('hidden_vars','<input type="hidden" name="cat_id" value="' . $this->cat_id . '">');
if ($apps_cats) if ($apps_cats)
{ {

View File

@ -13,15 +13,15 @@
<form name="form" action="{actionurl}" method="POST"> <form name="form" action="{actionurl}" method="POST">
<tr> <tr>
<td>{lang_parent}</td> <td>{lang_parent}</td>
<td><select name="new_parent"><option value="">{lang_none}</option>{category_list}</select></td> <td><select name="values[parent]"><option value="">{lang_none}</option>{category_list}</select></td>
</tr> </tr>
<tr> <tr>
<td>{lang_name}:</td> <td>{lang_name}:</td>
<td><input name="cat_name" size="50" value="{cat_name}"></td> <td><input name="values[name]" size="50" value="{cat_name}"></td>
</tr> </tr>
<tr> <tr>
<td>{lang_descr}:</td> <td>{lang_descr}:</td>
<td colspan="2"><textarea name="cat_description" rows="4" cols="50" wrap="virtual">{cat_description}</textarea></td> <td colspan="2"><textarea name="values[descr]" rows="4" cols="50" wrap="virtual">{cat_description}</textarea></td>
</tr> </tr>
</table> </table>
@ -52,11 +52,10 @@
<table width="50%" border="0" cellspacing="2" cellpadding="2"> <table width="50%" border="0" cellspacing="2" cellpadding="2">
<tr valign="bottom"> <tr valign="bottom">
<td height="50" align="center"> <td height="50" align="center">
{hidden_vars} <input type="hidden" name="values[old_parent]" value="{cat_parent}">
<input type="submit" name="submit" value="{lang_save}"></form></td> <input type="submit" name="submit" value="{lang_save}"></form></td>
<td height="50" align="center"> <td height="50" align="center">
<form method="POST" action="{deleteurl}"> <form method="POST" action="{deleteurl}">
{hidden_vars}
<input type="submit" name="delete" value="{lang_delete}"></form></td> <input type="submit" name="delete" value="{lang_delete}"></form></td>
<td height="50" align="center"> <td height="50" align="center">
<form method="POST" action="{doneurl}"> <form method="POST" action="{doneurl}">

View File

@ -104,6 +104,27 @@
return $this->db->f(0); return $this->db->f(0);
} }
function db2cats()
{
while ($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;
}
/*! /*!
@function return_array @function return_array
@abstract return an array populated with categories @abstract return an array populated with categories
@ -185,22 +206,7 @@
$this->total_records = $this->db->num_rows(); $this->total_records = $this->db->num_rows();
$i = 0; return $this->db2cats();
while ($this->db->next_record())
{
$cats[$i]['id'] = $this->db->f('cat_id');
$cats[$i]['owner'] = $this->db->f('cat_owner');
$cats[$i]['access'] = $this->db->f('cat_access');
$cats[$i]['app_name'] = $this->db->f('cat_appname');
$cats[$i]['main'] = $this->db->f('cat_main');
$cats[$i]['level'] = $this->db->f('cat_level');
$cats[$i]['parent'] = $this->db->f('cat_parent');
$cats[$i]['name'] = $this->db->f('cat_name');
$cats[$i]['description'] = $this->db->f('cat_description');
$cats[$i]['data'] = $this->db->f('cat_data');
$i++;
}
return $cats;
} }
function return_sorted_array($start,$limit = True,$query = '',$sort = '',$order = '',$globals = False, $parent_id = '') function return_sorted_array($start,$limit = True,$query = '',$sort = '',$order = '',$globals = False, $parent_id = '')
@ -272,26 +278,12 @@
$this->db->query($sql . $parent_select . $ordermethod,__LINE__,__FILE__); $this->db->query($sql . $parent_select . $ordermethod,__LINE__,__FILE__);
} }
$i = 0; $cats = $this->db2cats();
while ($this->db->next_record())
{
$cats[$i]['id'] = $this->db->f('cat_id');
$cats[$i]['owner'] = $this->db->f('cat_owner');
$cats[$i]['access'] = $this->db->f('cat_access');
$cats[$i]['app_name'] = $this->db->f('cat_appname');
$cats[$i]['main'] = $this->db->f('cat_main');
$cats[$i]['level'] = $this->db->f('cat_level');
$cats[$i]['parent'] = $this->db->f('cat_parent');
$cats[$i]['name'] = $this->db->f('cat_name');
$cats[$i]['description'] = $this->db->f('cat_description');
$cats[$i]['data'] = $this->db->f('cat_data');
$i++;
}
$num_cats = count($cats); $num_cats = count($cats);
for ($i=0;$i < $num_cats;$i++) for ($i=0;$i < $num_cats;$i++)
{ {
$sub_select = " AND cat_parent='" . $cats[$i]['id'] . "' AND cat_level='" . ($cats[$i]['level']+1) . "'"; $sub_select = " AND cat_parent='" . $cats[$i]['cat_id'] . "' AND cat_level='" . ($cats[$i]['level']+1) . "'";
if ($limit) if ($limit)
{ {
@ -302,22 +294,7 @@
$this->db->query($sql . $sub_select . $ordermethod,__LINE__,__FILE__); $this->db->query($sql . $sub_select . $ordermethod,__LINE__,__FILE__);
} }
$subcats = array(); $subcats = $this->db2cats();
$j = 0;
while ($this->db->next_record())
{
$subcats[$j]['id'] = $this->db->f('cat_id');
$subcats[$j]['owner'] = $this->db->f('cat_owner');
$subcats[$j]['access'] = $this->db->f('cat_access');
$subcats[$j]['app_name'] = $this->db->f('cat_appname');
$subcats[$j]['main'] = $this->db->f('cat_main');
$subcats[$j]['level'] = $this->db->f('cat_level');
$subcats[$j]['parent'] = $this->db->f('cat_parent');
$subcats[$j]['name'] = $this->db->f('cat_name');
$subcats[$j]['description'] = $this->db->f('cat_description');
$subcats[$j]['data'] = $this->db->f('cat_data');
$j++;
}
$num_subcats = count($subcats); $num_subcats = count($subcats);
if ($num_subcats != 0) if ($num_subcats != 0)
@ -355,16 +332,19 @@
if ($this->db->next_record()) if ($this->db->next_record())
{ {
$cats[0]['id'] = $this->db->f('cat_id'); $cats = array
$cats[0]['owner'] = $this->db->f('cat_owner'); (
$cats[0]['access'] = $this->db->f('cat_access'); 'cat_id' => $this->db->f('cat_id'),
$cats[0]['app_name'] = $this->db->f('cat_appname'); 'owner' => $this->db->f('cat_owner'),
$cats[0]['main'] = $this->db->f('cat_main'); 'access' => $this->db->f('cat_access'),
$cats[0]['level'] = $this->db->f('cat_level'); 'app_name' => $this->db->f('cat_appname'),
$cats[0]['parent'] = $this->db->f('cat_parent'); 'main' => $this->db->f('cat_main'),
$cats[0]['name'] = $this->db->f('cat_name'); 'level' => $this->db->f('cat_level'),
$cats[0]['description'] = $this->db->f('cat_description'); 'parent' => $this->db->f('cat_parent'),
$cats[0]['data'] = $this->db->f('cat_data'); 'name' => $this->db->f('cat_name'),
'descr' => $this->db->f('cat_description'),
'data' => $this->db->f('cat_data')
);
} }
return $cats; return $cats;
} }
@ -387,13 +367,13 @@
{ {
if(is_array($format)) if(is_array($format))
{ {
$temp_format = $format['format']; $temp_format = $format['format'];
$type = (isset($format['type'])?$format['type']:'all'); $type = (isset($format['type'])?$format['type']:'all');
$selected = (isset($format['selected'])?$format['selected']:''); $selected = (isset($format['selected'])?$format['selected']:'');
$globals = (isset($format['globals'])?$format['globals']:False); $globals = (isset($format['globals'])?$format['globals']:False);
$site_link = (isset($format['site_link'])?$format['site_link']:'site'); $site_link = (isset($format['site_link'])?$format['site_link']:'site');
settype($format,'string'); settype($format,'string');
$format = $temp_format; $format = $temp_format;
unset($temp_format); unset($temp_format);
} }
@ -481,11 +461,11 @@
{ {
if(is_array($data)) if(is_array($data))
{ {
$format = (isset($data['format'])?$data['format']:'select'); $format = (isset($data['format'])?$data['format']:'select');
$type = (isset($data['type'])?$data['type']:'all'); $type = (isset($data['type'])?$data['type']:'all');
$selected = (isset($data['selected'])?$data['selected']:''); $selected = (isset($data['selected'])?$data['selected']:'');
$globals = (isset($data['globals'])?$data['globals']:False); $globals = (isset($data['globals'])?$data['globals']:False);
$site_link = (isset($data['site_link'])?$data['site_link']:'site'); $site_link = (isset($data['site_link'])?$data['site_link']:'site');
} }
if (!is_array($selected)) if (!is_array($selected))
@ -555,36 +535,36 @@
@param $cat_description category description defaults to '' @param $cat_description category description defaults to ''
@param $cat_data category data defaults to '' @param $cat_data category data defaults to ''
*/ */
function add($cat_values) function add($values)
{ {
if ($cat_values['parent'] && $cat_values['parent'] != 0) if ($values['parent'] && $values['parent'] != 0)
{ {
$cat_values['main'] = $this->id2name($cat_values['parent'],'main'); $values['main'] = intval($this->id2item(array('cat_id' => $values['parent'],'item' => 'main')));
$cat_values['level'] = $this->id2name($cat_values['parent'],'level')+1; $values['level'] = intval($this->id2item(array('cat_id' => $values['parent'],'item' => 'level'))+1);
} }
$cat_values['descr'] = $this->db->db_addslashes($cat_values['descr']); $values['descr'] = $this->db->db_addslashes($values['descr']);
$cat_values['name'] = $this->db->db_addslashes($cat_values['name']); $values['name'] = $this->db->db_addslashes($values['name']);
if (isset($cat_values['id'])) if (isset($values['id']))
{ {
$id_col = 'cat_id,'; $id_col = 'cat_id,';
$id_val = $cat_values['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," $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'" . $cat_values['parent'] . "','" . $this->account_id . "','" . $cat_values['access'] . "cat_main,cat_level) VALUES ($id_val'" . intval($values['parent']) . "','" . $this->account_id . "','" . $values['access']
. "','" . $this->app_name . "','" . $cat_values['name'] . "','" . $cat_values['descr'] . "','" . $cat_values['data'] . "','" . $this->app_name . "','" . $values['name'] . "','" . $values['descr'] . "','" . $values['data']
. "','" . $cat_values['main'] . "','" . $cat_values['level'] . "')",__LINE__,__FILE__); . "','" . $values['main'] . "','" . $values['level'] . "')",__LINE__,__FILE__);
if (isset($cat_values['id'])) if (isset($values['cat_id']))
{ {
$max = $cat_values['id']; $max = intval($values['cat_id']);
} }
$max = $this->db->get_last_insert_id('phpgw_categories','cat_id'); $max = $this->db->get_last_insert_id('phpgw_categories','cat_id');
if (!$cat_values['parent'] || $cat_values['parent'] == 0) if (!$values['parent'] || $values['parent'] == 0)
{ {
$this->db->query("UPDATE phpgw_categories SET cat_main='" . $max . "' WHERE cat_id='" $this->db->query("UPDATE phpgw_categories SET cat_main='" . $max . "' WHERE cat_id='"
. $max . "'",__LINE__,__FILE__); . $max . "'",__LINE__,__FILE__);
@ -617,7 +597,7 @@
{ {
$cats = $this->return_sorted_array('',False,'','','',False, $cat_id); $cats = $this->return_sorted_array('',False,'','','',False, $cat_id);
$new_parent = $this->id2name($cat_id,'parent'); $new_parent = $this->id2item(array('cat_id' => $cat_id,'item' => 'parent'));
for ($i=0;$i<count($cats);$i++) for ($i=0;$i<count($cats);$i++)
{ {
@ -650,6 +630,52 @@
} }
} }
function subs($parent,&$subs,&$main)
{
if (!is_array($main))
{
$this->db->query("SELECT * from phpgw_categories WHERE cat_main = $main");
$main = $this->db2cats();
//echo "main: "; _debug_array($main);
}
reset($main);
for ($n = 0; $n < count($main); $n++)
{
$cat = $main[$n];
if ($cat['parent'] == $parent)
{
//echo "Adding($cat['cat_id'])<br>";
$subs[] = $cat;
$this->subs($cat['cat_id'],$subs,$main);
}
}
}
function reparent($values)
{
$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";
$subs = array();
$this->subs($id,$subs,$main);
$new_main = $parent ? $this->id2name($parent,'main') : $id;
$new_parent_level = $parent ? $this->id2name($parent,'level') : -1;
$old_parent_level = $old_parent ? $this->id2name($old_parent,'level') : -1;
$level_adj = $old_parent_level - $new_parent_level;
reset($subs);
//echo "new_main=$new_main,level_adj = $level_adj<br>";
while (list($n) = each($subs))
{
$subs[$n]['main'] = $new_main;
$subs[$n]['level'] -= $level_adj;
$this->edit($subs[$n]);
}
}
/*! /*!
@function edit @function edit
@abstract edit a category @abstract edit a category
@ -658,37 +684,39 @@
@param $cat_description category description defaults to '' @param $cat_description category description defaults to ''
@param $cat_data category data defaults to '' @param $cat_data category data defaults to ''
*/ */
function edit($cat_values) function edit($values)
{ {
if (isset($cat_values['old_parent']) && intval($cat_values['old_parent']) != $cat_values['parent']) if (isset($values['old_parent']) && $values['old_parent'] != $values['parent'])
{ {
$this->delete(array('cat_id' => $cat_values['id'],'drop_subs' => False,'modify_subs' => True)); //$this->delete(array('cat_id' => $values['cat_id'],'drop_subs' => False,'modify_subs' => True));
return $this->add($cat_values); //return $this->add($values);
$this->reparent($values);
} }
else else
{ {
if ($cat_values['parent'] && ($cat_values['parent'] != 0)) if ($values['parent'] && ($values['parent'] != 0))
{ {
$cat_values['main'] = intval($this->id2name($cat_values['parent'],'main')); $values['main'] = intval($this->id2item(array('cat_id' => $values['parent'],'item' => 'main')));
$cat_values['level'] = intval($this->id2name($cat_values['parent'],'level')+1); $values['level'] = intval($this->id2item(array('cat_id' => $values['parent'],'item' => 'level'))+1);
} }
else else
{ {
$cat_values['main'] = intval($cat_values['id']); $values['main'] = intval($values['id']);
$cat_values['level'] = 0; $values['level'] = 0;
} }
} }
$cat_values['descr'] = $this->db->db_addslashes($cat_values['descr']); $values['descr'] = $this->db->db_addslashes($values['descr']);
$cat_values['name'] = $this->db->db_addslashes($cat_values['name']); $values['name'] = $this->db->db_addslashes($values['name']);
$sql = "UPDATE phpgw_categories SET cat_name='" . $cat_values['name'] . "', cat_description='" . $cat_values['descr'] $sql = "UPDATE phpgw_categories SET cat_name='" . $values['name'] . "', cat_description='" . $values['descr']
. "', cat_data='" . $cat_values['data'] . "', cat_parent=" . $cat_values['parent'] . ", cat_access='" . "', cat_data='" . $values['data'] . "', cat_parent=" . intval($values['parent']) . ", cat_access='"
. $cat_values['access'] . "', cat_main=" . $cat_values['main'] . ", cat_level=" . $cat_values['level'] . $values['access'] . "', cat_main=" . $values['main'] . ", cat_level=" . $values['level']
. " WHERE cat_appname='" . $this->app_name . "' AND cat_id=" . intval($cat_values['id']); . " WHERE cat_appname='" . $this->app_name . "' AND cat_id=" . intval($values['cat_id']);
$this->db->query($sql,__LINE__,__FILE__); $this->db->query($sql,__LINE__,__FILE__);
return intval($cat_values['id']); return intval($values['cat_id']);
} }
function name2id($cat_name) function name2id($cat_name)
@ -708,10 +736,22 @@
function id2name($cat_id = '', $item = 'name') function id2name($cat_id = '', $item = 'name')
{ {
return $this->id2item(array('cat_id' => $cat_id,'item' => $item));
}
function id2item($data)
{
if(is_array($data))
{
$cat_id = $data['cat_id'];
$item = (isset($data['item'])?$data['item']:'name');
}
if ($cat_id == '') if ($cat_id == '')
{ {
return '--'; return '--';
} }
switch($item) switch($item)
{ {
case 'name': $value = 'cat_name'; break; case 'name': $value = 'cat_name'; break;
@ -738,18 +778,6 @@
} }
} }
/*!
@function return_name
@abstract return category name given $cat_id
@param $cat_id
@result cat_name category name
*/
// NOTE: This is only a temp wrapper, use id2name() to keep things matching across the board. (jengo)
function return_name($cat_id)
{
return $this->id2name($cat_id);
}
/*! /*!
@function exists @function exists
@abstract used for checking if a category name exists @abstract used for checking if a category name exists