added possibility to delete also all subcats if deleting the maincat

This commit is contained in:
bettina 2001-04-09 14:45:27 +00:00
parent ace6936802
commit 01be8c3c6f
11 changed files with 186 additions and 101 deletions

View File

@ -23,24 +23,24 @@
$c->categories($phpgw_info['user']['account_id'],'phpgw');
if ($submit) {
$errorcount = 0;
$errorcount = 0;
$exists = $c->exists('main',$cat_name);
if (!$cat_name) { $error[$errorcount++] = lang('Please enter a name for that category !'); }
if (!$cat_parent) { $exists = $c->exists('mains',$cat_name,$cat_id=''); }
else { $exists = $c->exists('subs',$cat_name,$cat_id=''); }
if ($exists == True) { $error[$errorcount++] = lang('That category name has been used already !'); }
if (!$cat_name) { $error[$errorcount++] = lang('Please enter a name for that category !'); }
if (! $error) {
$cat_name = addslashes($cat_name);
$cat_description = addslashes($cat_description);
$cat_access = 'public';
if (! $error) {
$cat_name = addslashes($cat_name);
$cat_description = addslashes($cat_description);
$cat_access = 'public';
$c->add($cat_name,$cat_parent,$cat_description,$cat_data,$cat_access);
$c->add($cat_name,$cat_parent,$cat_description,$cat_data,$cat_access);
}
}
if ($errorcount) { $t->set_var('message',$phpgw->common->error_list($error)); }
if (($submit) && (! $error) && (! $errorcount)) { $t->set_var('message',lang('Category x has been added !', $cat_name)); }
if (($submit) && (! $error) && (! $errorcount)) { $t->set_var('message',lang("Category x has been added !", $cat_name)); }
if ((! $submit) && (! $error) && (! $errorcount)) { $t->set_var('message',''); }
$t->set_var('title_categories',lang('Add global category'));

View File

@ -27,8 +27,9 @@
}
if ($confirm) {
$c->delete($cat_id);
Header('Location: ' . $phpgw->link('/admin/categories.php',"start=$start&query=$query&sort=$sort&order=$order&filter=$filter"));
if ($subs) { $c->delete($cat_id,'True'); }
else { $c->delete($cat_id); }
Header('Location: ' . $phpgw->link('/admin/categories.php',"start=$start&query=$query&sort=$sort&order=$order&filter=$filter"));
}
else {
$hidden_vars = "<input type=\"hidden\" name=\"sort\" value=\"$sort\">\n"
@ -39,28 +40,29 @@
. "<input type=\"hidden\" name=\"cat_id\" value=\"$cat_id\">\n";
$t = CreateObject('phpgwapi.Template',$phpgw->common->get_tpl_dir('admin'));
$t->set_file(array('category_delete' => 'delete_common.tpl'));
$t->set_file(array('category_delete' => 'delete_cat.tpl'));
$t->set_var('messages',lang('Are you sure you want to delete this category ?'));
$t->set_var('hidden_vars',$hidden_vars);
$exists = $c->exists('subs',$cat_name='',$cat_id);
if ($exists==True) {
$t->set_var('lang_subs',lang('Do you want to delete also all subcategories ?'));
$t->set_var('subs','<input type="checkbox" name="subs" value="True">');
}
else {
$t->set_var('lang_subs','');
$t->set_var('subs', '');
}
$nolinkf = $phpgw->link('/admin/categories.php',"cat_id=$cat_id&start=$start&query=$query&sort=$sort&order=$order&filter=$filter");
$nolink = "<a href=\"$nolinkf\">" . lang('No') ."</a>";
$t->set_var('no',$nolink);
$t->set_var('nolink',$phpgw->link('/admin/categories.php',"cat_id=$cat_id&start=$start&query=$query&sort=$sort&order=$order&filter=$filter"));
$t->set_var('lang_no',lang('No'));
$yeslinkf = $phpgw->link('/admin/deletecategory.php',"cat_id=$cat_id&confirm=True");
$yeslinkf = "<FORM method=\"POST\" name=yesbutton action=\"".$phpgw->link('/admin/deletecategory.php') . "\">"
. $hidden_vars
. "<input type=hidden name=cat_id value=$cat_id>"
. "<input type=hidden name=confirm value=True>"
. "<input type=submit name=yesbutton value=Yes>"
. "</FORM><SCRIPT>document.yesbutton.yesbutton.focus()</SCRIPT>";
$yeslink = "<a href=\"$yeslinkf\">" . lang('Yes') ."</a>";
$yeslink = $yeslinkf;
$t->set_var('yes',$yeslink);
$t->set_var('action_url',$phpgw->link('/admin/deletecategory.php',"cat_id=$cat_id"));
$t->set_var('lang_yes',lang('Yes'));
$t->pparse('out','category_delete');
}
$phpgw->common->phpgw_footer();
?>
?>

View File

@ -35,17 +35,18 @@
. "<input type=\"hidden\" name=\"cat_id\" value=\"$cat_id\">\n";
if ($submit) {
$errorcount = 0;
if (!$cat_name) { $error[$errorcount++] = lang('Please enter a name for that category !'); }
$phpgw->db->query("SELECT count(*) from phpgw_categories WHERE cat_name='$cat_name' AND cat_id !='$cat_id' AND cat_appname='phpgw'");
$phpgw->db->next_record();
if ($phpgw->db->f(0) != 0) { $error[$errorcount++] = lang('That category name has been used already !'); }
$errorcount = 0;
if (!$cat_name) { $error[$errorcount++] = lang('Please enter a name for that category !'); }
$cat_name = addslashes($cat_name);
$cat_description = addslashes($cat_description);
$cat_access = 'public';
if (!$cat_parent) { $exists = $c->exists('mains',$cat_name,$cat_id); }
else { $exists = $c->exists('subs',$cat_name,$cat_id); }
if ($exists == True) { $error[$errorcount++] = lang('That category name has been used already !'); }
if (! $error) { $c->edit($cat_id,$cat_parent,$cat_name,$cat_description,$cat_data,$cat_access); }
$cat_name = addslashes($cat_name);
$cat_description = addslashes($cat_description);
$cat_access = 'public';
if (! $error) { $c->edit($cat_id,$cat_parent,$cat_name,$cat_description,$cat_data,$cat_access); }
}
if ($errorcount) { $t->set_var('message',$phpgw->common->error_list($error)); }

View File

@ -0,0 +1,21 @@
<!-- BEGIN form -->
<center>
<table border="0" with="65%" cellpadding="2" cellspacing="2">
<form method="POST" action="{action_url}">
<tr>
<td align="center">{messages}</td>
</tr>
<tr>
<td align="center">{lang_subs}</td>
<td align="center">{subs}</td>
</tr>
<tr>
<td align="center">
{hidden_vars}
<input type="submit" name="confirm" value="{lang_yes}"></td>
</form>
<td align="center"><a href="{nolink}">{lang_no}</a></td>
</tr>
</table>
</center>
<!-- END form -->

View File

@ -0,0 +1,21 @@
<!-- BEGIN form -->
<center>
<table border="0" with="65%" cellpadding="2" cellspacing="2">
<form method="POST" action="{action_url}">
<tr>
<td align="center">{messages}</td>
</tr>
<tr>
<td align="center">{lang_subs}</td>
<td align="center">{subs}</td>
</tr>
<tr>
<td align="center">
{hidden_vars}
<input type="submit" name="confirm" value="{lang_yes}"></td>
</form>
<td align="center"><a href="{nolink}">{lang_no}</a></td>
</tr>
</table>
</center>
<!-- END form -->

View File

@ -0,0 +1,21 @@
<!-- BEGIN form -->
<center>
<table border="0" with="65%" cellpadding="2" cellspacing="2">
<form method="POST" action="{action_url}">
<tr>
<td align="center">{messages}</td>
</tr>
<tr>
<td align="center">{lang_subs}</td>
<td align="center">{subs}</td>
</tr>
<tr>
<td align="center">
{hidden_vars}
<input type="submit" name="confirm" value="{lang_yes}"></td>
</form>
<td align="center"><a href="{nolink}">{lang_no}</a></td>
</tr>
</table>
</center>
<!-- END form -->

View File

@ -263,10 +263,16 @@
@abstract delete category
@param $cat_id int - category id
*/
function delete($cat_id)
function delete($cat_id,$subs = 'False')
{
$this->db->query("delete from phpgw_categories where cat_id='$cat_id' and cat_appname='"
. $this->app_name . "'",__LINE__,__FILE__);
if ($subs == 'True')
{
$subdelete = " OR cat_parent='$cat_id'";
}
$this->db->query("delete from phpgw_categories where cat_id='$cat_id' $subdelete and cat_appname='"
. $this->app_name . "'",__LINE__,__FILE__);
}
/*!
@function edit
@ -311,23 +317,37 @@
@param $cat_name category name
@result boolean true or false
*/
function exists($type,$cat_name)
function exists($type,$cat_name,$cat_id)
{
$filter = $this->filter($type);
$filter = $this->filter($type);
$this->db->query("select count(*) from phpgw_categories where cat_name='"
. addslashes($cat_name) . "' and cat_appname='"
if ($cat_name)
{
$cat_exists = " cat_name='" . addslashes($cat_name) . "' ";
}
if ($cat_id)
{
$cat_exists = " cat_parent='$cat_id' ";
}
if ($cat_name && $cat_id)
{
$cat_exists = " cat_name='" . addslashes($cat_name) . "' and cat_id != '$cat_id' ";
}
$this->db->query("select count(*) from phpgw_categories where $cat_exists and cat_appname='"
. $this->app_name . "' $filter",__LINE__,__FILE__);
$this->db->next_record();
if ($this->db->f(0))
{
return True;
}
else
{
return False;
}
$this->db->next_record();
if ($this->db->f(0))
{
return True;
}
else
{
return False;
}
}
}
?>

View File

@ -39,8 +39,8 @@
$errorcount = 0;
if (!$cat_name) { $error[$errorcount++] = lang('Please enter a name for that category !'); }
if (!$cat_parent) { $exists = $c->exists('mains',$cat_name); }
else { $exists = $c->exists('subs',$cat_name); }
if (!$cat_parent) { $exists = $c->exists('mains',$cat_name,$cat_id=''); }
else { $exists = $c->exists('subs',$cat_name,$cat_id=''); }
if ($exists == True) { $error[$errorcount++] = lang('That category name has been used already !'); }
if (! $error) {
@ -70,7 +70,7 @@
$t->set_var('lang_access',lang('Private'));
if ($access) { $t->set_var('access', '<input type="checkbox" name="access" value="True" checked>'); }
else { $t->set_var('access', '<input type="checkbox" name="access" value="True"'); }
else { $t->set_var('access', '<input type="checkbox" name="access" value="True">'); }
$t->set_var('lang_name',lang('Name'));
$t->set_var('lang_descr',lang('Description'));
$t->set_var('cat_name',$cat_name);

View File

@ -30,34 +30,36 @@
}
if ($confirm) {
$c->delete($cat_id);
Header('Location: ' . $phpgw->link('/preferences/categories.php',"cats_app=$cats_app&extra=$extra"));
if ($subs) { $c->delete($cat_id,'True'); }
else { $c->delete($cat_id); }
Header('Location: ' . $phpgw->link('/preferences/categories.php',"cats_app=$cats_app&extra=$extra"));
}
else {
$hidden_vars = "<input type=\"hidden\" name=\"cat_id\" value=\"$cat_id\">\n"
. $hidden_vars = "<input type=\"hidden\" name=\"cats_app\" value=\"$cats_app\">\n"
. $hidden_vars = "<input type=\"hidden\" name=\"extra\" value=\"$extra\">\n";
. "<input type=\"hidden\" name=\"cats_app\" value=\"$cats_app\">\n"
. "<input type=\"hidden\" name=\"extra\" value=\"$extra\">\n";
$t = CreateObject('phpgwapi.Template',$phpgw->common->get_tpl_dir('preferences'));
$t->set_file(array('category_delete' => 'delete.tpl'));
$t->set_var('deleteheader',lang('Are you sure you want to delete this category ?'));
$t->set_var('font',$phpgw_info["theme"]["font"]);
$nolinkf = $phpgw->link('/preferences/categories.php',"cat_id=$cat_id&cats_app=$cats_app&extra=$extra");
$nolink = "<a href=\"$nolinkf\">" . lang('No') ."</a>";
$t->set_var("nolink",$nolink);
$t->set_var('hidden_vars',$hidden_vars);
$yeslinkf = $phpgw->link('/preferences/deletecategory.php',"cat_id=$cat_id&confirm=True");
$yeslinkf = "<FORM method=\"POST\" name=yesbutton action=\"".$phpgw->link('/preferences/deletecategory.php') . "\">"
. $hidden_vars
. "<input type=hidden name=cat_id value=$cat_id>"
. "<input type=hidden name=confirm value=True>"
. "<input type=submit name=yesbutton value=Yes>"
. "</FORM><SCRIPT>document.yesbutton.yesbutton.focus()</SCRIPT>";
$exists = $c->exists('subs',$cat_name='',$cat_id);
if ($exists==True) {
$t->set_var('lang_subs',lang('Do you want to delete also all subcategories ?'));
$t->set_var('subs','<input type="checkbox" name="subs" value="True">');
}
else {
$t->set_var('lang_subs','');
$t->set_var('subs', '');
}
$yeslink = "<a href=\"$yeslinkf\">" . lang('Yes') ."</a>";
$yeslink = $yeslinkf;
$t->set_var('nolink',$phpgw->link('/preferences/categories.php',"cat_id=$cat_id&cats_app=$cats_app&extra=$extra"));
$t->set_var('lang_no',lang('No'));
$t->set_var('yeslink',$yeslink);
$t->set_var('action_url',$phpgw->link('/preferences/deletecategory.php',"cat_id=$cat_id$cats_app=$cats_app&extra=$extra"));
$t->set_var('lang_yes',lang('Yes'));
$t->pparse('out','category_delete');
}

View File

@ -40,24 +40,18 @@
$c->app_name = $cats_app;
if ($submit) {
$errorcount = 0;
if (!$cat_name) { $error[$errorcount++] = lang('Please enter a name for that category !'); }
$phpgw->db->query("SELECT count(*) from phpgw_categories WHERE cat_name='$cat_name' AND cat_id !='$cat_id' AND cat_appname='"
. $phpgw_info["flags"]["currentapp"] ."' AND cat_parent='0'");
$phpgw->db->next_record();
if ($phpgw->db->f(0) != 0) { $error[$errorcount++] = lang('That main category name has been used already !'); }
$errorcount = 0;
if (!$cat_name) { $error[$errorcount++] = lang('Please enter a name for that category !'); }
if (!$cat_parent) { $exists = $c->exists('mains',$cat_name,$cat_id); }
else { $exists = $c->exists('subs',$cat_name,$cat_id); }
if ($exists == True) { $error[$errorcount++] = lang('That category name has been used already !'); }
$phpgw->db->query("SELECT count(*) from phpgw_categories WHERE cat_name='$cat_name' AND cat_id !='$cat_id' AND cat_appname='"
. $phpgw_info["flags"]["currentapp"] ."' AND cat_parent != '0'");
$phpgw->db->next_record();
if ($phpgw->db->f(0) != 0) { $error[$errorcount++] = lang('That sub category name has been used already !'); }
$cat_name = addslashes($cat_name);
$cat_description = addslashes($cat_description);
if ($access) { $cat_access = 'private'; }
else { $cat_access = 'public'; }
$cat_name = addslashes($cat_name);
$cat_description = addslashes($cat_description);
if ($access) { $cat_access = 'private'; }
else { $cat_access = 'public'; }
if (! $error) { $c->edit($cat_id,$cat_parent,$cat_name,$cat_description,$cat_data,$cat_access); }
if (! $error) { $c->edit($cat_id,$cat_parent,$cat_name,$cat_description,$cat_data,$cat_access); }
}
if ($errorcount) { $t->set_var('message',$phpgw->common->error_list($error)); }

View File

@ -1,19 +1,22 @@
<!-- $Id$ -->
<br><br><br>
<!-- BEGIN form -->
<center>
<table border=0 width=50% cellpadding=2 cellspacing=2>
<table border=0 width="65%" cellpadding="2" cellspacing="2">
<form method="POST" action="{action_url}">
<tr>
<td align=center><font face="{font}">{deleteheader}</font></td>
</tr>
<tr>
<td>
<table border="0" width="30%" align="center">
<tr>
<td align="center"><font face="{font}">{nolink}</font></td>
<td align="center"><font face="{font}">{yeslink}</font></td>
<td align="center">{lang_subs}</td>
<td align="center">{subs}</td>
</tr>
<tr>
<td align="center"><font face="{font}">
{hidden_vars}
<input type="submit" name="confirm" value="{lang_yes}"></font></td>
</form>
<td align="center"><font face="{font}"><a href="{nolink}">{lang_no}</a></font></td>
</tr>
</table>
</td>
</tr>
</table>
</center>
</center>
<!-- END form -->