Revamp custom field editing

This commit is contained in:
Miles Lott 2001-04-21 14:51:05 +00:00
parent 1523f097a1
commit eb8f0e5f76
10 changed files with 454 additions and 68 deletions

74
addressbook/addfield.php Normal file
View File

@ -0,0 +1,74 @@
<?php
/**************************************************************************\
* phpGroupWare - addressbook *
* http://www.phpgroupware.org *
* Written by Bettina Gille [ceb@phpgroupware.org] *
* ----------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU General Public License as published by the *
* Free Software Foundation; either version 2 of the License, or (at your *
* option) any later version. *
\**************************************************************************/
/* $Id$ */
$phpgw_info["flags"]["currentapp"] = 'addressbook';
include('../header.inc.php');
if(!$phpgw->acl->check('run',1,'admin'))
{
echo lang('access not permitted');
$phpgw->common->phpgw_footer();
$phpgw->common->phpgw_exit();
}
$t = CreateObject('phpgwapi.Template',$phpgw->common->get_tpl_dir('addressbook'));
$t->set_file(array('form' => 'field_form.tpl'));
$t->set_block('form','add','addhandle');
$t->set_block('form','edit','edithandle');
if ($submit) {
$errorcount = 0;
if (!$field_name)
{
$error[$errorcount++] = lang('Please enter a name for that field !');
}
$fields = read_custom_fields($start,$limit,$field_name);
if ($fields[0]['name'])
{
$error[$errorcount++] = lang('That field name has been used already !');
}
if (! $error)
{
$field_name = addslashes($field_name);
save_custom_field($field,$field_name);
}
}
if ($errorcount) { $t->set_var('message',$phpgw->common->error_list($error)); }
if (($submit) && (! $error) && (! $errorcount)) { $t->set_var('message',lang('Field x has been added !', $field_name)); }
if ((! $submit) && (! $error) && (! $errorcount)) { $t->set_var('message',''); }
$t->set_var('title_fields',lang('Add'). ' ' . lang('Custom Field'));
$t->set_var('actionurl',$phpgw->link('/addressbook/addfield.php'));
$t->set_var('doneurl',$phpgw->link('/addressbook/fields.php'));
$t->set_var('hidden_vars','<input type="hidden" name="field" value="' . $field . '">');
$t->set_var('lang_name',lang('Server name'));
$t->set_var('lang_add',lang('Add'));
$t->set_var('lang_reset',lang('Clear Form'));
$t->set_var('lang_done',lang('Done'));
$t->set_var('field_name',$field_name);
$t->set_var('edithandle','');
$t->set_var('addhandle','');
$t->pparse('out','form');
$t->pparse('addhandle','add');
$phpgw->common->phpgw_footer();
?>

View File

@ -0,0 +1,64 @@
<?php
/**************************************************************************\
* phpGroupWare - Admin *
* (http://www.phpgroupware.org) *
* Written by Bettina Gille [ceb@phpgroupware.org] *
* ----------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU General Public License as published by the *
* Free Software Foundation; either version 2 of the License, or (at your *
* option) any later version. *
\**************************************************************************/
/* $Id$ */
if ($confirm) {
$phpgw_info["flags"] = array(
'noheader' => True,
'nonavbar' => True
);
}
$phpgw_info["flags"]["currentapp"] = 'addressbook';
include('../header.inc.php');
if (!$field) {
Header('Location: ' . $phpgw->link('/addressbook/fields.php'));
}
if ($confirm) {
save_custom_field($field);
Header('Location: ' . $phpgw->link('/addressbook/fields.php',"start=$start&query=$query&sort=$sort"));
}
else
{
$hidden_vars = "<input type=\"hidden\" name=\"sort\" value=\"$sort\">\n"
. "<input type=\"hidden\" name=\"order\" value=\"$order\">\n"
. "<input type=\"hidden\" name=\"query\" value=\"$query\">\n"
. "<input type=\"hidden\" name=\"start\" value=\"$start\">\n"
. "<input type=\"hidden\" name=\"field\" value=\"$field\">\n";
$t = CreateObject('phpgwapi.Template',$phpgw->common->get_tpl_dir('addressbook'));
$t->set_file(array('field_delete' => 'delete_common.tpl'));
$t->set_var('messages',lang('Are you sure you want to delete this field?'));
$nolinkf = $phpgw->link('/addressbook/fields.php',"field_id=$field_id&start=$start&query=$query&sort=$sort");
$nolink = "<a href=\"$nolinkf\">" . lang('No') ."</a>";
$t->set_var('no',$nolink);
$yeslinkf = $phpgw->link('/addressbook/deletefield.php',"field_id=$field_id&confirm=True");
$yeslinkf = "<FORM method=\"POST\" name=yesbutton action=\"".$phpgw->link('/addressbook/deletefield.php') . "\">"
. $hidden_vars
. "<input type=hidden name=field_id value=$field_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->pparse('out','field_delete');
}
$phpgw->common->phpgw_footer();
?>

86
addressbook/editfield.php Normal file
View File

@ -0,0 +1,86 @@
<?php
/**************************************************************************\
* phpGroupWare - Admin *
* http://www.phpgroupware.org *
* Written by Bettina Gille [ceb@phpgroupware.org] *
* ----------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU General Public License as published by the *
* Free Software Foundation; either version 2 of the License, or (at your *
* option) any later version. *
\**************************************************************************/
/* $Id$ */
$phpgw_info["flags"]["currentapp"] = 'addressbook';
include('../header.inc.php');
if(!$phpgw->acl->check('run',1,'admin'))
{
echo lang('access not permitted');
$phpgw->common->phpgw_footer();
$phpgw->common->phpgw_exit();
}
if (!$field) {
Header('Location: ' . $phpgw->link('/addressbook/fields.php',"sort=$sort&query=$query&start=$start"));
}
$t = CreateObject('phpgwapi.Template',$phpgw->common->get_tpl_dir('addressbook'));
$t->set_file(array('form' => 'field_form.tpl'));
$t->set_block('form','add','addhandle');
$t->set_block('form','edit','edithandle');
$hidden_vars = "<input type=\"hidden\" name=\"sort\" value=\"$sort\">\n"
. "<input type=\"hidden\" name=\"query\" value=\"$query\">\n"
. "<input type=\"hidden\" name=\"start\" value=\"$start\">\n"
. "<input type=\"hidden\" name=\"field\" value=\"$field\">\n";
if ($submit) {
$errorcount = 0;
if (!$field_name) { $error[$errorcount++] = lang('Please enter a name for that field!'); }
$field_name = addslashes($field_name);
if (! $error)
{
save_custom_field($field,$field_name);
}
}
if ($errorcount) { $t->set_var('message',$phpgw->common->error_list($error)); }
if (($submit) && (! $error) && (! $errorcount)) { $t->set_var('message',lang("Field '$field_name' has been updated !")); }
if ((! $submit) && (! $error) && (! $errorcount)) { $t->set_var('message',''); }
if ($submit)
{
$field = $field_name;
}
else
{
$fields = read_custom_fields($start,$limit,$field);
$field = $phpgw->strip_html($fields[0]['name']);
}
$t->set_var('title_fields',lang('Edit Field'));
$t->set_var('actionurl',$phpgw->link('/addressbook/editfield.php'));
$t->set_var('deleteurl',$phpgw->link('/addressbook/deletefield.php',"field=$field&start=$start&query=$query&sort=$sort"));
$t->set_var('doneurl',$phpgw->link('/addressbook/fields.php',"start=$start&query=$query&sort=$sort"));
$t->set_var('hidden_vars',$hidden_vars);
$t->set_var('lang_name',lang('Field name'));
$t->set_var('lang_done',lang('Done'));
$t->set_var('lang_edit',lang('Edit'));
$t->set_var('lang_delete',lang('Delete'));
$t->set_var('field_name',$field);
$t->set_var('edithandle','');
$t->set_var('addhandle','');
$t->pparse('out','form');
$t->pparse('edithandle','edit');
$phpgw->common->phpgw_footer();
?>

View File

@ -2,94 +2,108 @@
/**************************************************************************\
* phpGroupWare - Addressbook *
* http://www.phpgroupware.org *
* -------------------------------------------- *
* Written by Bettina Gille [ceb@phpgroupware.org] *
* ----------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU General Public License as published by the *
* Free Software Foundation; either version 2 of the License, or (at your *
* option) any later version. *
\**************************************************************************/
/* $Id$ */
$phpgw_info["flags"]["currentapp"] = "addressbook";
$phpgw_info["flags"]["enable_nextmatchs_class"] = True;
$phpgw_info["flags"]["enable_contacts_class"] = True;
include("../header.inc.php");
$phpgw_info["flags"] = array(
'currentapp' => 'addressbook',
'enable_nextmatchs_class' => True);
$this = CreateObject("phpgwapi.contacts");
$extrafields = array(
"pager" => "pager",
"mphone" => "mphone",
"ophone" => "ophone",
"address2" => "address2",
);
$qfields = $this->stock_contact_fields + $extrafields;
include('../header.inc.php');
$phpgw->template->set_file(array(
"body" => "custom_field_list.tpl",
"row" => "custom_field_list_row.tpl"
));
$t = CreateObject('phpgwapi.Template',$phpgw->common->get_tpl_dir('addressbook'));
$phpgw->template->set_var("title",lang('addressbook').' '.lang('custom fields'));
$phpgw->template->set_var("message",'');
$phpgw->template->set_var("sort_name",lang("Name"));
$phpgw->template->set_var("lang_edit",lang("Edit"));
$phpgw->template->set_var("lang_delete",lang("Delete"));
$phpgw->template->set_var("th_bg",$phpgw_info["theme"]["th_bg"]);
$t->set_file(array(
'field_list_t' => 'listfields.tpl',
'field_list' => 'listfields.tpl'));
$t->set_block('field_list_t','field_list','list');
$phpgw->preferences->read_repository();
$common_hidden_vars = "<input type=\"hidden\" name=\"sort\" value=\"$sort\">\n"
. "<input type=\"hidden\" name=\"order\" value=\"$order\">\n"
. "<input type=\"hidden\" name=\"query\" value=\"$query\">\n"
. "<input type=\"hidden\" name=\"start\" value=\"$start\">\n"
. "<input type=\"hidden\" name=\"filter\" value=\"$filter\">\n";
while (list($col,$descr) = each($phpgw_info["user"]["preferences"]["addressbook"]))
$t->set_var('lang_action',lang('Custom Fields'));
$t->set_var('add_action',$phpgw->link('/addressbook/addfield.php'));
$t->set_var('lang_add',lang('Add'));
$t->set_var('title_fields',lang('Custom Fields'));
$t->set_var('lang_search',lang('Search'));
$t->set_var('actionurl',$phpgw->link('/addressbook/fields.php'));
$t->set_var('lang_done',lang('Done'));
$t->set_var('doneurl',$phpgw->link('/admin/index.php'));
if (!$start) { $start = 0; }
if($phpgw_info["user"]["preferences"]["common"]["maxmatchs"] && $phpgw_info["user"]["preferences"]["common"]["maxmatchs"] > 0)
{
if ( substr($col,0,6) == 'extra_' )
{
$fields[$i] = ereg_replace('extra_','',$col);
$fields[$i] = ereg_replace(' ','_',$fields[$i]);
//echo "<br>".$i.": '".$fields[$i]."'";
}
else
{
$fields[$i] = '';
}
$i++;
$limit = $phpgw_info["user"]["preferences"]["common"]["maxmatchs"];
}
else
{
$limit = 15;
}
reset($fields);
for($i=0;$i<count($fields);$i++)
if (!$sort) { $sort = "ASC"; }
$fields = read_custom_fields($start,$limit,$query,$sort,$order);
$total_records = count($fields);
//--------------------------------- nextmatch --------------------------------------------
$left = $phpgw->nextmatchs->left('/addressbook/fields.php',$start,$total_records);
$right = $phpgw->nextmatchs->right('/addressbook/fields.php',$start,$total_records);
$t->set_var('left',$left);
$t->set_var('right',$right);
if ($total_records > $limit)
{
if ($fields[$i])
{
$found = True;
$phpgw->nextmatchs->template_alternate_row_color(&$phpgw->template);
$phpgw->template->set_var("field_name",$fields[$i]);
$phpgw->template->set_var("field_edit",'<a href="'
. $phpgw->link("/addressbook/field_edit.php","ofield="
. $fields[$i] . "&method=edit")
. '">' . lang("Edit") . '</a>');
$phpgw->template->set_var("field_delete",'<a href="'
. $phpgw->link("/addressbook/field_edit.php","field="
. $fields[$i] . "&method=delete&deletefield=delete")
. '">' . lang("Delete") . '</a>');
$phpgw->template->parse("rows","row",True);
}
$t->set_var('lang_showing',lang("showing x - x of x",($start + 1),($start + $limit),$total_records));
}
if (!$found)
else
{
$phpgw->nextmatchs->template_alternate_row_color(&$phpgw->template);
$phpgw->template->set_var("field_name",'&nbsp;');
$phpgw->template->set_var("field_edit",'&nbsp;');
$phpgw->template->set_var("field_delete",'&nbsp;');
$phpgw->template->parse("rows","row",False);
$t->set_var('lang_showing',lang("showing x",$total_records));
}
$phpgw->template->set_var("add_field",'<a href="'
. $phpgw->link("/addressbook/field_edit.php","method=add")
. '">' . lang("Add") . '</a>');
// ------------------------------ end nextmatch ------------------------------------------
//------------------- list header variable template-declarations -------------------------
$t->set_var('th_bg',$phpgw_info["theme"][th_bg]);
$t->set_var('sort_field',$phpgw->nextmatchs->show_sort_order($sort,'name',$order,'/addressbook/fields.php',lang('Name')));
$t->set_var('lang_edit',lang('Edit'));
$t->set_var('lang_delete',lang('Delete'));
// -------------------------- end header declaration --------------------------------------
for ($i=0;$i<count($fields);$i++)
{
$tr_color = $phpgw->nextmatchs->alternate_row_color($tr_color);
$t->set_var(tr_color,$tr_color);
$field = $fields[$i]['name'];
//-------------------------- template declaration for list records ---------------------------
$t->set_var('cfield',$field);
$t->set_var('edit',$phpgw->link('/addressbook/editfield.php',"field=$field&start=$start&query=$query&sort=$sort&order=$order&filter=$filter"));
$t->set_var('lang_edit_entry',lang('Edit'));
$t->set_var('delete',$phpgw->link('/addressbook/deletefield.php',"field=$field&start=$start&query=$query&sort=$sort&order=$order&filter=$filter"));
$t->set_var('lang_delete_entry',lang('Delete'));
$t->parse('list','field_list',True);
}
// ---------------------------- end record declaration -----------------------------------------
$t->parse('out','field_list_t',True);
$t->p('out');
$phpgw->template->pparse("out","body");
$phpgw->common->phpgw_footer();
?>

View File

@ -0,0 +1 @@
<th height="21"><font size="-1" face="Arial, Helvetica, sans-serif">{show_col}</font></th>

View File

@ -0,0 +1,16 @@
<!-- BEGIN form -->
<center>
<table border="0" with="65%">
<tr>
<td colspan="2" align="center">
{messages}
</td>
</tr>
<tr>
<td align="center">{no}</td>
<td align="center">{yes}</td>
</tr>
</table>
</center>
<!-- END form -->

View File

@ -0,0 +1,57 @@
<!-- $Id$ -->
<center>
<table border="0" cellspacing="2" cellpadding="2">
<tr>
<td colspan="6" align="center" bgcolor="#c9c9c9"><b>{title_fields}<b/></td>
</tr>
<tr>
<td colspan="6" align=left>
<table border="0" width="100%">
<tr>
{left}
<td align="center">{lang_showing}</td>
{right}
</tr>
</table>
</td>
</tr>
<tr>
<td align=right>
<form method="post" action="{actionurl}">
<input type="text" name="query">&nbsp;<input type="submit" name="search" value="{lang_search}"></form></td>
</tr>
<tr bgcolor="{th_bg}">
<td width=16% bgcolor="{th_bg}">{sort_field}</td>
<td width=8% bgcolor="{th_bg}" align="center">{lang_edit}</td>
<td width=8% bgcolor="{th_bg}" align="center">{lang_delete}</td>
</tr>
<!-- BEGIN field_list -->
<tr bgcolor="{tr_color}">
<td>{cfield}</td>
<td align="center"><a href="{edit}">{lang_edit_entry}</a></td>
<td align="center"><a href="{delete}">{lang_delete_entry}</td>
</tr>
<!-- END field_list -->
<!-- BEGINN add -->
<tr valign="bottom">
<td>
<form method="POST" action="{add_action}">
<input type="submit" name="add" value="{lang_add}"></form>
</td>
</tr>
<tr valign="bottom">
<td>
<form method="POST" action="{doneurl}">
<input type="submit" name="done" value="{lang_done}"></form>
</td>
</tr>
<!-- END add -->
</table>
</center>

View File

@ -0,0 +1 @@
<th height="21"><font size="-1" face="Arial, Helvetica, sans-serif">{show_col}</font></th>

View File

@ -0,0 +1,16 @@
<!-- BEGIN form -->
<center>
<table border="0" with="65%">
<tr>
<td colspan="2" align="center">
{messages}
</td>
</tr>
<tr>
<td align="center">{no}</td>
<td align="center">{yes}</td>
</tr>
</table>
</center>
<!-- END form -->

View File

@ -0,0 +1,57 @@
<!-- $Id$ -->
<center>
<table border="0" cellspacing="2" cellpadding="2">
<tr>
<td colspan="6" align="center" bgcolor="#c9c9c9"><b>{title_fields}<b/></td>
</tr>
<tr>
<td colspan="6" align=left>
<table border="0" width="100%">
<tr>
{left}
<td align="center">{lang_showing}</td>
{right}
</tr>
</table>
</td>
</tr>
<tr>
<td align=right>
<form method="post" action="{actionurl}">
<input type="text" name="query">&nbsp;<input type="submit" name="search" value="{lang_search}"></form></td>
</tr>
<tr bgcolor="{th_bg}">
<td width=16% bgcolor="{th_bg}">{sort_field}</td>
<td width=8% bgcolor="{th_bg}" align="center">{lang_edit}</td>
<td width=8% bgcolor="{th_bg}" align="center">{lang_delete}</td>
</tr>
<!-- BEGIN field_list -->
<tr bgcolor="{tr_color}">
<td>{cfield}</td>
<td align="center"><a href="{edit}">{lang_edit_entry}</a></td>
<td align="center"><a href="{delete}">{lang_delete_entry}</td>
</tr>
<!-- END field_list -->
<!-- BEGINN add -->
<tr valign="bottom">
<td>
<form method="POST" action="{add_action}">
<input type="submit" name="add" value="{lang_add}"></form>
</td>
</tr>
<tr valign="bottom">
<td>
<form method="POST" action="{doneurl}">
<input type="submit" name="done" value="{lang_done}"></form>
</td>
</tr>
<!-- END add -->
</table>
</center>