Adding category support to addressbook

This commit is contained in:
Miles Lott 2001-03-25 05:41:06 +00:00
parent e1e01851d7
commit 37cdf6faf1
8 changed files with 133 additions and 41 deletions

View File

@ -63,7 +63,8 @@
addressbook_add_entry($addnew['owner'],$addnew);
$fields = addressbook_read_last_entry($qfields);
$newid = $fields[0]['id'];
Header("Location: " . $phpgw->link('/addressbook/edit.php',"&ab_id=$newid&order=$order&sort=$sort&filter=$filter&start=$start&query=$query"));
Header("Location: "
. $phpgw->link('/addressbook/edit.php',"&ab_id=$newid&order=$order&sort=$sort&filter=$filter&start=$start&query=$query&cat_id=$cat_id"));
} else {
if (! $bday_month && ! $bday_day && ! $bday_year) {
$bday = "";
@ -147,17 +148,20 @@
$fields["access"] = 'public';
}
addressbook_add_entry($phpgw_info["user"]["account_id"],$fields,$fields["access"]);
$fields["cat_id"] = $cat_id;
addressbook_add_entry($phpgw_info["user"]["account_id"],$fields,$fields["access"],$fields["cat_id"]);
$ab_id = addressbook_get_lastid();
Header("Location: " . $phpgw->link("/addressbook/view.php","ab_id=$ab_id&order=$order&sort=$sort&filter=$filter&start=$start"));
Header("Location: "
. $phpgw->link("/addressbook/view.php","ab_id=$ab_id&order=$order&sort=$sort&filter=$filter&start=$start&cat_id=$cat_id"));
$phpgw->common->phpgw_exit();
}
$t->set_var("lang_ok",lang("ok"));
$t->set_var("lang_clear",lang("clear"));
$t->set_var("lang_cancel",lang("cancel"));
$t->set_var("cancel_url",$phpgw->link("/addressbook/index.php","sort=$sort&order=$order&filter=$filter&start=$start"));
$t->set_var("cancel_url",$phpgw->link("/addressbook/index.php","sort=$sort&order=$order&filter=$filter&start=$start&cat_id=$cat_id"));
$t->parse("out","add");
$t->pparse("out","add");

View File

@ -29,7 +29,8 @@
if (! $this->check_perms($this->grants[$check[0]['owner']],PHPGW_ACL_EDIT) && $check[0]['owner'] != $phpgw_info['user']['account_id'])
{
Header("Location: " . $phpgw->link('/addressbook/index.php',"cd=16&order=$order&sort=$sort&filter=$filter&start=$start&query=$query"));
Header("Location: "
. $phpgw->link('/addressbook/index.php',"cd=16&order=$order&sort=$sort&filter=$filter&start=$start&query=$query&cat_id=$cat_id"));
$phpgw->common->phpgw_exit();
}
@ -37,7 +38,8 @@
$t->set_file(array("edit" => "edit.tpl"));
if (! $ab_id) {
Header("Location: " . $phpgw->link('/addressbook/index.php',"cd=16&order=$order&sort=$sort&filter=$filter&start=$start&query=$query"));
Header("Location: "
. $phpgw->link('/addressbook/index.php',"cd=16&order=$order&sort=$sort&filter=$filter&start=$start&query=$query&cat_id=$cat_id"));
$phpgw->common->phpgw_exit();
}
@ -156,11 +158,14 @@
$fields["access"] = 'public';
}
$fields["cat_id"] = $cat_id;
$userid = $phpgw_info["user"]["account_id"];
addressbook_update_entry($ab_id,$userid,$fields,$fields['access']);
addressbook_update_entry($ab_id,$userid,$fields,$fields['access'],$fields["cat_id"]);
Header("Location: " . $phpgw->link("/addressbook/view.php","ab_id=$ab_id&order=$order&sort=$sort&filter=$filter&start=$start&query=$query"));
Header("Location: "
. $phpgw->link("/addressbook/view.php","ab_id=$ab_id&order=$order&sort=$sort&filter=$filter&start=$start&query=$query&cat_id=$cat_id"));
$phpgw->common->phpgw_exit();
}
@ -174,7 +179,8 @@
$t->set_var("lang_cancel",lang("cancel"));
$t->set_var("lang_delete",lang("delete"));
$t->set_var("lang_submit",lang("submit"));
$t->set_var("cancel_link",'<form method="POST" action="'.$phpgw->link("/addressbook/index.php","sort=$sort&order=$order&filter=$filter&start=$start&query=$query") . '">');
$t->set_var("cancel_link",'<form method="POST" action="'
. $phpgw->link("/addressbook/index.php","sort=$sort&order=$order&filter=$filter&start=$start&query=$query&cat_id=$cat_id") . '">');
$t->set_var("delete_link",'<form method="POST" action="'.$phpgw->link("/addressbook/delete.php","ab_id=$ab_id") . '">');
$t->parse("out","edit");

View File

@ -169,7 +169,7 @@
$this->db2 = $this->db;
$this->db->query("select id,lid,tid,owner,access $t_fields from $this->std_table WHERE id='$id'");
$this->db->query("select id,lid,tid,owner,access,cat_id $t_fields from $this->std_table WHERE id='$id'");
$this->db->next_record();
$return_fields[0]["id"] = $this->db->f("id"); // unique id
@ -177,6 +177,7 @@
$return_fields[0]["tid"] = $this->db->f("tid"); // type id (g/u) for groups/accounts
$return_fields[0]["owner"] = $this->db->f("owner"); // id of owner/parent for the record
$return_fields[0]["access"] = $this->db->f("access"); // public/private
$return_fields[0]["cat_id"] = $this->db->f("cat_id");
if (gettype($stock_fieldnames) == "array") {
while (list($f_name) = each($stock_fieldnames)) {
@ -232,7 +233,7 @@
$id = $this->db->f(0);
$this->db->query("SELECT id,lid,tid,owner,access $t_fields from $this->std_table WHERE id='$id'",__LINE__,__FILE__);
$this->db->query("SELECT id,lid,tid,owner,access,cat_id $t_fields from $this->std_table WHERE id='$id'",__LINE__,__FILE__);
$this->db->next_record();
$return_fields[0]["id"] = $this->db->f("id");
@ -240,6 +241,7 @@
$return_fields[0]["tid"] = $this->db->f("tid");
$return_fields[0]["owner"] = $this->db->f("owner");
$return_fields[0]["access"] = $this->db->f("access"); // public/private
$return_fields[0]["cat_id"] = $this->db->f("cat_id");
if (gettype($stock_fieldnames) == "array") {
while (list($f_name) = each($stock_fieldnames)) {
@ -335,7 +337,11 @@
reset($stock_fields);
while (list($fname,$fvalue)=each($stock_fields)) {
if ($fvalue==$name) {
$filterlist .= $name.'="'.$value.'",';
if (gettype($value) == "integer") {
$filterlist .= $name."=".$value.",";
} else {
$filterlist .= $name."='".$value."',";
}
break;
}
}
@ -355,7 +361,7 @@
}
}
$fwhere .= " owner=" . $phpgw_info['user']['account_id'];
$fwhere .= $filtermethod . " AND (owner=" . $phpgw_info['user']['account_id'];
if (is_array($this->grants))
{
$grants = $this->grants;
@ -364,7 +370,7 @@
$public_user_list[] = $user;
}
reset($public_user_list);
$fwhere .= " OR (access='public' AND owner in(" . implode(',',$public_user_list) . ")) AND ";
$fwhere .= " OR (access='public' AND owner in(" . implode(',',$public_user_list) . "))) ";
}
else
{
@ -388,6 +394,8 @@
echo "<br>DEBUG - $ordermethod";
}
$filtermethod = "";
// This logic allows you to limit rows, or not.
// The export feature, for example, does not limit rows.
// This way, it can retrieve all rows at once.
@ -441,6 +449,7 @@
$return_fields[$i]["tid"] = $this->db->f("tid");
$return_fields[$i]["owner"] = $this->db->f("owner");
$return_fields[$i]["access"] = $this->db->f("access"); // public/private
$return_fields[$i]["cat_id"] = $this->db->f("cat_id");
if (gettype($stock_fieldnames) == "array") {
while (list($f_name) = each($stock_fieldnames)) {
@ -462,14 +471,14 @@
return $return_fields;
}
function add($owner,$fields,$access='')
function add($owner,$fields,$access='',$cat_id='')
{
list($stock_fields,$stock_fieldnames,$extra_fields) = $this->split_stock_and_extras($fields);
//$this->db->lock(array("contacts"));
$this->db->query("insert into $this->std_table (owner,access,"
$this->db->query("insert into $this->std_table (owner,access,cat_id"
. implode(",",$this->stock_contact_fields)
. ") values ('$owner','$access','"
. ") values ('$owner','$access','$cat_id','"
. implode("','",$this->loop_addslashes($stock_fields)) . "')",__LINE__,__FILE__);
$this->db->query("select max(id) from $this->std_table ",__LINE__,__FILE__);
@ -504,7 +513,7 @@
. addslashes($field_name) . "'",__LINE__,__FILE__);
}
function update($id,$owner,$fields,$access='')
function update($id,$owner,$fields,$access='',$cat_id='')
{
// First make sure that id number exists
$this->db->query("select count(*) from $this->std_table where id='$id'",__LINE__,__FILE__);
@ -522,7 +531,7 @@
if ($field_s == ",") {
unset($field_s);
}
$this->db->query("update $this->std_table set access='$access' $fields_s where "
$this->db->query("update $this->std_table set access='$access',cat_id='$cat_id' $fields_s where "
. "id='$id'",__LINE__,__FILE__);
}

View File

@ -33,6 +33,48 @@
}
}
function cat_option($cat_id) {
global $phpgw_info;
// Get global and app-specific category listings
$cats_link = "<select name=\"cat_id\">";
$cats_link .= "<option value =\"0\"";
if (!$cat_id) {
$cats_link .= " selected";
}
$cats_link .= ">".lang("none");
$cats = CreateObject('phpgwapi.categories');
$cats->categories($phpgw_info['user']['account_id'],'phpgw');
$cats_link .= $cats->formated_list('select','',$cat_id);
$cats->categories($phpgw_info['user']['account_id'],'addressbook');
$cats_link .= $cats->formated_list('select','',$cat_id);
$cats_link .= '</select>';
return $cats_link;
}
### SET THE FONT TO DEFAULT IF IT DOESNT EXISTS ###
function set_font() {
if($phpgw_info["user"]["preferences"]["notes"]["notes_font"] == "") {
$font = "Arial";
return $font;
} else {
$font = $phpgw_info["user"]["preferences"]["notes"]["notes_font"];
return $font;
}
}
### SET FONT SIZE ####
function set_font_size() {
if($phpgw_info["user"]["preferences"]["notes"]["notes_font_size"] == "") {
$font_size = "3";
return $font_size;
} else {
$font_size = $phpgw_info["user"]["preferences"]["notes"]["notes_font_size"];
return $font_size;
}
}
// this cleans up the fieldnames for display
function display_name($column) {
$abc = array(
@ -122,10 +164,10 @@
}
}
function addressbook_add_entry($userid,$fields,$access) {
function addressbook_add_entry($userid,$fields,$access,$cat_id) {
global $this,$rights;
if ($rights & PHPGW_ACL_ADD) {
$this->add($userid,$fields);
$this->add($userid,$fields,$access,$cat_id);
}
return;
}
@ -137,10 +179,10 @@
return $ab_id;
}
function addressbook_update_entry($id,$userid,$fields,$access) {
function addressbook_update_entry($id,$userid,$fields,$access,$cat_id) {
global $this,$rights;
if ($rights & PHPGW_ACL_EDIT) {
$this->update($id,$userid,$fields,$access);
$this->update($id,$userid,$fields,$access,$cat_id);
}
return;
}
@ -206,6 +248,9 @@
$url = $fields["url"];
$pubkey = $fields["pubkey"];
$access = $fields["access"];
$cat_id = $fields["cat_id"];
$cats_link = cat_option($cat_id);
if ($access == 'private') {
$access_check = ' checked';
@ -462,6 +507,9 @@
$t->set_var("access_check",$access_check);
$t->set_var('lang_private',lang('Private'));
$t->set_var('lang_cats',lang('Category'));
$t->set_var('cats_link',$cats_link);
if ($customfields) {
$t->set_var('lang_custom',lang('Custom Fields').':');
} else {

View File

@ -56,7 +56,7 @@
$showcol = display_name($column[0]);
$cols .= " <td height=\"21\">\n";
$cols .= ' <font size="-1" face="Arial, Helvetica, sans-serif">';
$cols .= $phpgw->nextmatchs->show_sort_order($sort, $column[0],$order,"/addressbook/index.php",$showcol);
$cols .= $phpgw->nextmatchs->show_sort_order($sort, $column[0],$order,"/addressbook/index.php",$showcol,"&cat_id=".$cat_id);
$cols .= "</font>\n </td>";
$cols .= "\n";
@ -97,11 +97,11 @@
// else they may be accounts, etc.
$savefilter = $filter;
if ($filter == "none") {
$filter = 'tid=';
$filter = 'tid=,cat_id='.$cat_id;
} elseif($filter == "private") {
$filter = 'owner='.$phpgw_info["user"]["account_id"].',tid=';
$filter = 'owner='.$phpgw_info["user"]["account_id"].',tid=,cat_id='.$cat_id;
} else {
$filter .= ',tid=';
$filter .= ',tid=,cat_id='.$cat_id;
}
// Check if prefs were set, if not, create some defaults
@ -119,7 +119,7 @@
if (!$showcol) { $showcol = $column[1]; }
$cols .= " <td height=\"21\">\n";
$cols .= ' <font size="-1" face="Arial, Helvetica, sans-serif">';
$cols .= $phpgw->nextmatchs->show_sort_order($sort, $column[0],$order,"/addressbook/index.php",$showcol);
$cols .= $phpgw->nextmatchs->show_sort_order($sort, $column[0],$order,"/addressbook/index.php",$showcol,"&cat_id=$cat_id");
$cols .= "</font>\n </td>";
$cols .= "\n";
}
@ -133,7 +133,7 @@
// now that the query is done, reset filter, since nextmatchs grabs it globally
$filter=$savefilter;
$search_filter = $phpgw->nextmatchs->show_tpl("/addressbook/index.php",$start, $this->total_records,"&order=$order&filter=$filter&sort=$sort&query=$query","75%", $phpgw_info["theme"]["th_bg"]);
$search_filter = $phpgw->nextmatchs->show_tpl("/addressbook/index.php",$start, $this->total_records,"&order=$order&filter=$filter&sort=$sort&query=$query&cat_id=$cat_id","75%", $phpgw_info["theme"]["th_bg"]);
if ($this->total_records > $phpgw_info["user"]["preferences"]["common"]["maxmatchs"]) {
if ($start + $phpgw_info["user"]["preferences"]["common"]["maxmatchs"] > $this->total_records) {
@ -156,6 +156,10 @@
$t->set_var(searchreturn,$noprefs . " " . $searchreturn);
$t->set_var(lang_showing,$lang_showing);
$t->set_var(search_filter,$search_filter);
$t->set_var(cats,lang('Categories'));
$t->set_var(cats_url,$phpgw->link("/addressbook/index.php","sort=$sort&order=$order&filter=$filter&start=$start&query=$query&cat_id=$cat_id"));
$t->set_var(cats_link,cat_option($cat_id));
$t->set_var(lang_cats,lang('Select'));
$t->set_var("lang_addressbook",lang("Address book"));
$t->set_var("th_bg",$phpgw_info["theme"]["th_bg"]);
$t->set_var("th_font",$phpgw_info["theme"]["font"]);
@ -172,7 +176,7 @@
$t->set_var("filter",$filter);
$t->set_var("qfield",$qfield);
$t->set_var("query",$query);
$t->set_var("actionurl",$phpgw->link("/addressbook/add.php","sort=$sort&order=$order&filter=$filter&start=$start"));
$t->set_var("actionurl",$phpgw->link("/addressbook/add.php","sort=$sort&order=$order&filter=$filter&start=$start&cat_id=$cat_id"));
$t->set_var("start",$start);
$t->set_var("filter",$filter);
$t->set_var("cols",$cols);
@ -211,18 +215,18 @@
if (1) {
$t->set_var(row_view_link,$phpgw->link("/addressbook/view.php","ab_id=$myid&start=$start&order=$order&filter="
. "$filter&query=$query&sort=$sort"));
. "$filter&query=$query&sort=$sort&cat_id=$cat_id"));
} else {
$t->set_var(row_view_link,"");
$t->set_var("lang_view",lang("Private"));
}
$t->set_var(row_vcard_link,$phpgw->link("/addressbook/vcardout.php","ab_id=$myid&start=$start&order=$order&filter="
. "$filter&query=$query&sort=$sort"));
. "$filter&query=$query&sort=$sort&cat_id=$cat_id"));
// echo '<br>: ' . $this->grants[$myowner] . ' - ' . $myowner;
if ($this->check_perms($this->grants[$myowner],PHPGW_ACL_EDIT) || $myowner == $phpgw_info['user']['account_id']) {
$t->set_var(row_edit,'<a href="' . $phpgw->link("/addressbook/edit.php","ab_id=$myid&start=$start&sort=$sort&order=$order"
. "&query=$query&sort=$sort") . '">' . lang('Edit') . '</a>');
. "&query=$query&sort=$sort&cat_id=$cat_id") . '">' . lang('Edit') . '</a>');
} else {
$t->set_var(row_edit,'&nbsp;');
}

View File

@ -313,14 +313,18 @@
{notes}
</font></td>
</tr>
<tr>
<td><font size="-1">{lang_private}:</font></td>
<td colspan="3">
<input type="checkbox" name="access" value="True"{access_check}>
</td>
</tr>
<tr>
<td><font size="-1">{lang_cats}:</font></td>
<td>{cats_link}</td>
<td colspan="3">
</td>
</tr>
<tr>
<td><font color="#000000" face="" size="-1">{lang_custom}</font></td>
<td></td>

View File

@ -3,6 +3,10 @@
<center>{lang_addressbook}
<br>{lang_showing}
<br>{searchreturn}
<form action="{cats_url}" method="POST">
{cats}{cats_link}
<input type="submit" name="cats" value="{lang_cats}">
</form>
{search_filter}
<table width=75% border=0 cellspacing=1 cellpadding=3>

View File

@ -29,7 +29,8 @@
if (! $this->check_perms($this->grants[$check[0]['owner']],PHPGW_ACL_PRIVATE) && $check[0]['owner'] != $phpgw_info['user']['account_id'])
{
Header("Location: " . $phpgw->link('/addressbook/index.php',"cd=16&order=$order&sort=$sort&filter=$filter&start=$start&query=$query"));
Header("Location: "
. $phpgw->link('/addressbook/index.php',"cd=16&order=$order&sort=$sort&filter=$filter&start=$start&query=$query&cat_id=$cat_id"));
$phpgw->common->phpgw_exit();
}
@ -111,25 +112,37 @@
$columns_html .= "<td>" . $ref . $data . "</td>";
}
$cat = CreateObject('phpgwapi.categories');
$catinfo = $cat->return_single($cat_id);
$catname = $catinfo[0]["name"];
$cat->app_name = "phpgw";
$catinfo = $cat->return_single($cat_id);
$catname .= $catinfo[0]["name"];
$columns_html .= '<tr><td colspan="4">&nbsp;</td></tr>'
. '<tr><td><b>' . lang("Record owner") . '</b></td><td>'
. $phpgw->common->grab_owner_name($record_owner) . '</td></tr>'
. '<tr><td><b>' . lang("Record access") . '</b></td><td>'
. $access_check . '</b></td></tr>'
. '<tr><td><b>' . lang("Category") . '</b></td><td>'
. $catname . '</b></td></tr>'
. '</td></td></table>';
$sfields = rawurlencode(serialize($fields[0]));
if ($rights & PHPGW_ACL_EDIT) {
$editlink = '<form method="POST" action="'.$phpgw->link("/addressbook/edit.php","ab_id=$ab_id&start=$start&sort=$sort&order=$order"
$editlink = '<form method="POST" action="'.$phpgw->link("/addressbook/edit.php","ab_id=$ab_id&start=$start&sort=$sort&order=$order&cat_id=$cat_id"
. "&query=$query&sort=$sort").'">';
} else {
$editlink = '';
}
$copylink = '<form method="POST" action="'.$phpgw->link("/addressbook/add.php","order=$order&start=$start&filter=$filter&query=$query&sort=$sort").'">';
$vcardlink = '<form method="POST" action="'.$phpgw->link("/addressbook/vcardout.php","ab_id=$ab_id&order=$order&start=$start&filter=$filter&query=$query&sort=$sort").'">';
$donelink = '<form method="POST" action="'.$phpgw->link("/addressbook/index.php","order=$order&start=$start&filter=$filter&query=$query&sort=$sort").'">';
$copylink = '<form method="POST" action="'
. $phpgw->link("/addressbook/add.php","order=$order&start=$start&filter=$filter&query=$query&sort=$sort&cat_id=$cat_id").'">';
$vcardlink = '<form method="POST" action="'
. $phpgw->link("/addressbook/vcardout.php","ab_id=$ab_id&order=$order&start=$start&filter=$filter&query=$query&sort=$sort&cat_id=$cat_id").'">';
$donelink = '<form method="POST" action="'
. $phpgw->link("/addressbook/index.php","order=$order&start=$start&filter=$filter&query=$query&sort=$sort&cat_id=$cat_id").'">';
$t->set_var("access_link",$access_link);
$t->set_var("ab_id",$ab_id);