Move class vars out of constructor, remove unneeded extra db objects

This commit is contained in:
Miles Lott 2001-09-05 12:03:51 +00:00
parent 8fe80611d3
commit e372d5bcdc

View File

@ -36,28 +36,19 @@
*/ */
class contacts_ class contacts_
{ {
var $db; var $db = '';
var $std_table='phpgw_addressbook'; var $std_table='phpgw_addressbook';
var $ext_table='phpgw_addressbook_extra'; var $ext_table='phpgw_addressbook_extra';
var $account_id; var $account_id = 0;
var $stock_contact_fields; /* This is an array of almost the fields in the phpgw_addressbook table, except id,owner,lid,tid,access,cat_id */ var $stock_contact_fields = array();
var $non_contact_fields; /* Here are the rest */ var $non_contact_fields = array();
var $email_types; /* VCard email type array */ var $email_types = array();
var $total_records; /* This will contain numrows for data retrieved */ var $total_records = 0;
var $grants; /* This holds all of the users that have granted access to there entrys */ var $grants = '';
function contacts_($useacl=True)
{
$this->db = $GLOBALS['phpgw']->db;
if($useacl)
{
$this->grants = $GLOBALS['phpgw']->acl->get_grants('addressbook');
}
$this->account_id = $GLOBALS['phpgw_info']['user']['account_id'];
/* The left side are the array elements used throughout phpgw, right side are the db field names. */ /* The left side are the array elements used throughout phpgw, right side are the db field names. */
$this->stock_contact_fields = array( var $stock_contact_fields = array(
'fn' => 'fn', 'fn' => 'fn',
'n_given' => 'n_given', 'n_given' => 'n_given',
'n_family' => 'n_family', 'n_family' => 'n_family',
@ -71,11 +62,9 @@
'geo' => 'geo', 'geo' => 'geo',
'url' => 'url', 'url' => 'url',
'pubkey' => 'pubkey', 'pubkey' => 'pubkey',
'org_name' => 'org_name', 'org_name' => 'org_name',
'org_unit' => 'org_unit', 'org_unit' => 'org_unit',
'title' => 'title', 'title' => 'title',
'adr_one_street' => 'adr_one_street', 'adr_one_street' => 'adr_one_street',
'adr_one_locality' => 'adr_one_locality', 'adr_one_locality' => 'adr_one_locality',
'adr_one_region' => 'adr_one_region', 'adr_one_region' => 'adr_one_region',
@ -83,14 +72,12 @@
'adr_one_countryname' => 'adr_one_countryname', 'adr_one_countryname' => 'adr_one_countryname',
'adr_one_type' => 'adr_one_type', 'adr_one_type' => 'adr_one_type',
'label' => 'label', 'label' => 'label',
'adr_two_street' => 'adr_two_street', 'adr_two_street' => 'adr_two_street',
'adr_two_locality' => 'adr_two_locality', 'adr_two_locality' => 'adr_two_locality',
'adr_two_region' => 'adr_two_region', 'adr_two_region' => 'adr_two_region',
'adr_two_postalcode' => 'adr_two_postalcode', 'adr_two_postalcode' => 'adr_two_postalcode',
'adr_two_countryname' => 'adr_two_countryname', 'adr_two_countryname' => 'adr_two_countryname',
'adr_two_type' => 'adr_two_type', 'adr_two_type' => 'adr_two_type',
'tel_work' => 'tel_work', 'tel_work' => 'tel_work',
'tel_home' => 'tel_home', 'tel_home' => 'tel_home',
'tel_voice' => 'tel_voice', 'tel_voice' => 'tel_voice',
@ -110,7 +97,7 @@
'email_home_type' => 'email_home_type' 'email_home_type' => 'email_home_type'
); );
$this->non_contact_fields = array( var $non_contact_fields = array(
'id' => 'id', 'id' => 'id',
'lid' => 'lid', 'lid' => 'lid',
'tid' => 'tid', 'tid' => 'tid',
@ -124,7 +111,7 @@
parcel(default) parcel(default)
postal(default) postal(default)
*/ */
$this->adr_types = array( var $adr_types = array(
'dom' => lang('Domestic'), 'dom' => lang('Domestic'),
'intl' => lang('International'), 'intl' => lang('International'),
'parcel' => lang('Parcel'), 'parcel' => lang('Parcel'),
@ -132,7 +119,7 @@
); );
/* Used to set preferred number field */ /* Used to set preferred number field */
$this->tel_types = array( var $tel_types = array(
'work' => 'work', 'work' => 'work',
'home' => 'home', 'home' => 'home',
'voice' => 'voice', 'voice' => 'voice',
@ -148,7 +135,7 @@
); );
/* Used to set email_type fields */ /* Used to set email_type fields */
$this->email_types = array( var $email_types = array(
'INTERNET' => 'INTERNET', 'INTERNET' => 'INTERNET',
'CompuServe' => 'CompuServe', 'CompuServe' => 'CompuServe',
'AOL' => 'AOL', 'AOL' => 'AOL',
@ -163,10 +150,19 @@
'X.400' => 'X.400', 'X.400' => 'X.400',
'TLX' => 'TLX' 'TLX' => 'TLX'
); );
function contacts_($useacl=True)
{
$this->db = $GLOBALS['phpgw']->db;
if($useacl)
{
$this->grants = $GLOBALS['phpgw']->acl->get_grants('addressbook');
}
$this->account_id = $GLOBALS['phpgw_info']['user']['account_id'];
} }
/* send this the id and whatever fields you want to see */ /* send this the id and whatever fields you want to see */
function read_single_entry($id,$fields="") function read_single_entry($id,$fields='')
{ {
if (!$fields || empty($fields)) { $fields = $this->stock_contact_fields; } if (!$fields || empty($fields)) { $fields = $this->stock_contact_fields; }
list($stock_fields,$stock_fieldnames,$extra_fields) = list($stock_fields,$stock_fieldnames,$extra_fields) =
@ -174,15 +170,13 @@
if (count($stock_fieldnames)) if (count($stock_fieldnames))
{ {
$t_fields = "," . implode(",",$stock_fieldnames); $t_fields = ',' . implode(',',$stock_fieldnames);
if ($t_fields == ",") if ($t_fields == ',')
{ {
unset($t_fields); unset($t_fields);
} }
} }
$this->db2 = $this->db;
$this->db->query("SELECT id,lid,tid,owner,access,cat_id $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(); $this->db->next_record();
@ -201,7 +195,7 @@
} }
} }
/* Setup address type fields */ /* Setup address type fields for ui forms display */
if ($this->db->f('adr_one_type')) if ($this->db->f('adr_one_type'))
{ {
$one_type = $this->db->f('adr_one_type'); $one_type = $this->db->f('adr_one_type');
@ -221,12 +215,12 @@
} }
} }
$this->db2->query("SELECT contact_name,contact_value FROM $this->ext_table where contact_id='" . $this->db->f('id') . "'",__LINE__,__FILE__); $this->db->query("SELECT contact_name,contact_value FROM $this->ext_table where contact_id='" . $this->db->f('id') . "'",__LINE__,__FILE__);
while ($this->db2->next_record()) while ($this->db->next_record())
{ {
if ($extra_fields[$this->db2->f('contact_name')]) if ($extra_fields[$this->db->f('contact_name')])
{ {
$return_fields[0][$this->db2->f('contact_name')] = $this->db2->f('contact_value'); $return_fields[0][$this->db->f('contact_name')] = $this->db->f('contact_value');
} }
} }
return $return_fields; return $return_fields;
@ -240,15 +234,13 @@
if (count($stock_fieldnames)) if (count($stock_fieldnames))
{ {
$t_fields = "," . implode(",",$stock_fieldnames); $t_fields = ',' . implode(',',$stock_fieldnames);
if ($t_fields == ",") if ($t_fields == ',')
{ {
unset($t_fields); unset($t_fields);
} }
} }
$this->db2 = $this->db;
$this->db->query('SELECT max(id) FROM '.$this->std_table,__LINE__,__FILE__); $this->db->query('SELECT max(id) FROM '.$this->std_table,__LINE__,__FILE__);
$this->db->next_record(); $this->db->next_record();
@ -272,7 +264,7 @@
} }
} }
/* Setup address type fields */ /* Setup address type fields for ui forms display */
if ($this->db->f('adr_one_type')) if ($this->db->f('adr_one_type'))
{ {
$one_type = $this->db->f('adr_one_type'); $one_type = $this->db->f('adr_one_type');
@ -292,12 +284,12 @@
} }
} }
$this->db2->query("SELECT contact_name,contact_value FROM $this->ext_table WHERE contact_id='" . $this->db->f('id') . "'",__LINE__,__FILE__); $this->db->query("SELECT contact_name,contact_value FROM $this->ext_table WHERE contact_id='" . $this->db->f('id') . "'",__LINE__,__FILE__);
while ($this->db2->next_record()) while ($this->db->next_record())
{ {
if ($extra_fields[$this->db2->f('contact_name')]) if ($extra_fields[$this->db->f('contact_name')])
{ {
$return_fields[0][$this->db2->f('contact_name')] = $this->db2->f('contact_value'); $return_fields[0][$this->db->f('contact_name')] = $this->db->f('contact_value');
} }
} }
return $return_fields; return $return_fields;
@ -328,7 +320,7 @@
{ {
$check_stock = $this->stock_contact_fields + $this->non_contact_fields; $check_stock = $this->stock_contact_fields + $this->non_contact_fields;
if ($DEBUG) { echo "DEBUG - Inbound filter is: #".$filter."#"; } if ($DEBUG) { echo 'DEBUG - Inbound filter is: #'.$filter.'#'; }
$filterarray = split(',',$filter); $filterarray = split(',',$filter);
if ($filterarray[1]) if ($filterarray[1])
{ {
@ -338,7 +330,7 @@
list($name,$value) = split('=',$filterarray[$i]); list($name,$value) = split('=',$filterarray[$i]);
if ($name) if ($name)
{ {
if ($DEBUG) { echo "<br>DEBUG - Filter intermediate strings 1: #".$name."# => #".$value."#"; } if ($DEBUG) { echo '<br>DEBUG - Filter intermediate strings 1: #'.$name.'# => #'.$value.'#'; }
$filterfields[$name] = $value; $filterfields[$name] = $value;
} }
} }
@ -399,11 +391,11 @@
$i++; $i++;
} }
$filterlist = substr($filterlist,0,-1); $filterlist = substr($filterlist,0,-1);
$filterlist = ereg_replace(";"," AND ",$filterlist); $filterlist = ereg_replace(';',' AND ',$filterlist);
if ($DEBUG) if ($DEBUG)
{ {
echo "<br>DEBUG - Filter output string: #".$filterlist."#"; echo '<br>DEBUG - Filter output string: #'.$filterlist.'#';
} }
if ($filterlist) if ($filterlist)
@ -419,18 +411,18 @@
if (!$filtermethod) if (!$filtermethod)
{ {
if($GLOBALS['phpgw_info']['user']['account_id']) if($this->account_id)
{ {
$fwhere .= " (owner=" . $GLOBALS['phpgw_info']['user']['account_id']; $fwhere .= ' (owner=' . $this->account_id;
$fand .= " (owner=" . $GLOBALS['phpgw_info']['user']['account_id']; $fand .= ' (owner=' . $this->account_id;
} }
} }
else else
{ {
if($GLOBALS['phpgw_info']['user']['account_id']) if($this->account_id)
{ {
$fwhere .= $filtermethod . " AND (owner=" . $GLOBALS['phpgw_info']['user']['account_id']; $fwhere .= $filtermethod . ' AND (owner=' . $this->account_id;
$fand .= $filtermethod . " AND (owner=" . $GLOBALS['phpgw_info']['user']['account_id']; $fand .= $filtermethod . ' AND (owner=' . $this->account_id;
} }
else else
{ {
@ -458,7 +450,7 @@
if ($DEBUG && $filtermethod) if ($DEBUG && $filtermethod)
{ {
echo "<br>DEBUG - Filtering with: #" . $filtermethod . "#"; echo '<br>DEBUG - Filtering with: #' . $filtermethod . '#';
} }
if (!$sort) { $sort = 'ASC'; } if (!$sort) { $sort = 'ASC'; }
@ -477,7 +469,7 @@
echo "<br>DEBUG - $ordermethod"; echo "<br>DEBUG - $ordermethod";
} }
$filtermethod = ""; $filtermethod = '';
if ($query) if ($query)
{ {
@ -492,15 +484,12 @@
else else
{ {
$sql = "SELECT id,lid,tid,owner,access,cat_id $t_fields FROM $this->std_table " . $fwhere $sql = "SELECT id,lid,tid,owner,access,cat_id $t_fields FROM $this->std_table " . $fwhere
. $filtermethod . " " . $ordermethod; . $filtermethod . ' ' . $ordermethod;
} }
if ($DEBUG) { echo "<br>$sql"; } if ($DEBUG) { echo "<br>$sql"; }
$this->db2 = $this->db; $this->db->query($sql,__LINE__,__FILE__);
$this->db2->query($sql,__LINE__,__FILE__); $this->total_records = $this->db->num_rows();
$this->total_records = $this->db2->num_rows();
if ($start && $limit) if ($start && $limit)
{ {
@ -514,6 +503,7 @@
{ {
$this->db->limit_query($sql,$start,__LINE__,__FILE__); $this->db->limit_query($sql,$start,__LINE__,__FILE__);
} }
$this->db2 = $this->db;
$i = 0; $i = 0;
while ($this->db->next_record()) while ($this->db->next_record())
@ -619,8 +609,8 @@
{ {
$ta[] = $stock_fieldname . "='" . addslashes($stock_fields[$stock_fieldname]) . "'"; $ta[] = $stock_fieldname . "='" . addslashes($stock_fields[$stock_fieldname]) . "'";
} }
$fields_s = "," . implode(",",$ta); $fields_s = ',' . implode(',',$ta);
if ($field_s == ",") if ($field_s == ',')
{ {
unset($field_s); unset($field_s);
} }