diff --git a/addressbook/add.php b/addressbook/add.php index 9469e8c23a..8d18b54f31 100755 --- a/addressbook/add.php +++ b/addressbook/add.php @@ -29,7 +29,7 @@ $t = CreateObject('phpgwapi.Template',PHPGW_APP_TPL); $t->set_file(array('add' => 'add.tpl')); - $this = CreateObject('phpgwapi.contacts'); + $contacts = CreateObject('phpgwapi.contacts'); // Read in user custom fields, if any $phpgw->preferences->read_repository(); @@ -79,7 +79,7 @@ 'address2' => 'address2', 'address3' => 'address3' ); - $qfields = $this->stock_contact_fields + $extrafields + $customfields; + $qfields = $contacts->stock_contact_fields + $extrafields + $customfields; $addnew = unserialize(rawurldecode($fields)); $addnew['note'] .= "\nCopied from ".$phpgw->accounts->id2name($addnew['owner']).", record #".$addnew['id']."."; $addnew['owner'] = $phpgw_info['user']['account_id']; @@ -144,9 +144,9 @@ $fields['adr_one_postalcode'] = $bzip; $fields['adr_one_countryname'] = $bcountry; - reset($this->adr_types); + reset($contacts->adr_types); $typed = ''; - while (list($type,$val) = each($this->adr_types)) + while (list($type,$val) = each($contacts->adr_types)) { $ftype = 'one_'.$type; eval("if (\$\$ftype=='on') { \$typed .= \$type . ';'; }"); @@ -162,9 +162,9 @@ $fields['adr_two_postalcode'] = $hzip; $fields['adr_two_countryname'] = $hcountry; - reset($this->adr_types); + reset($contacts->adr_types); $typed = ''; - while (list($type,$val) = each($this->adr_types)) + while (list($type,$val) = each($contacts->adr_types)) { $ftype = 'two_'.$type; eval("if (\$\$ftype=='on') { \$typed \.= \$type . ';'; }"); diff --git a/addressbook/delete.php b/addressbook/delete.php index bc66c3ac41..7569163b5d 100755 --- a/addressbook/delete.php +++ b/addressbook/delete.php @@ -25,11 +25,11 @@ Header('Location: ' . $phpgw->link('/addressbook/index.php')); } - $this = CreateObject('phpgwapi.contacts'); - $fields = $this->read_single_entry($ab_id,array('owner' => 'owner')); + $contacts = CreateObject('phpgwapi.contacts'); + $fields = $contacts->read_single_entry($ab_id,array('owner' => 'owner')); //$record_owner = $fields[0]['owner']; - if (! $this->check_perms($this->grants[$fields[0]['owner']],PHPGW_ACL_DELETE) && $fields[0]['owner'] != $phpgw_info['user']['account_id']) + if (! $contacts->check_perms($contacts->grants[$fields[0]['owner']],PHPGW_ACL_DELETE) && $fields[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&cat_id=$cat_id")); @@ -57,8 +57,8 @@ } else { - $this->account_id = $phpgw_info['user']['account_id']; - $this->delete($ab_id); + $contacts->account_id = $phpgw_info['user']['account_id']; + $contacts->delete($ab_id); @Header('Location: ' . $phpgw->link('/addressbook/index.php', "cd=16&order=$order&sort=$sort&filter=$filter&start=$start&query=$query&cat_id=$cat_id")); diff --git a/addressbook/edit.php b/addressbook/edit.php index 1a348c9355..ff80aa88e1 100755 --- a/addressbook/edit.php +++ b/addressbook/edit.php @@ -23,12 +23,12 @@ include('../header.inc.php'); - $this = CreateObject('phpgwapi.contacts'); + $contacts = CreateObject('phpgwapi.contacts'); // First, make sure they have permission to this entry $check = addressbook_read_entry($ab_id,array('owner' => 'owner')); - if ( !$this->check_perms($this->grants[$check[0]['owner']],PHPGW_ACL_EDIT) && ($check[0]['owner'] != $phpgw_info['user']['account_id']) ) + if ( !$contacts->check_perms($contacts->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&cat_id=$cat_id")); @@ -69,7 +69,7 @@ 'address3' => 'address3' ); - $qfields = $this->stock_contact_fields + $extrafields + $customfields; + $qfields = $contacts->stock_contact_fields + $extrafields + $customfields; $fields = addressbook_read_entry($ab_id,$qfields); addressbook_form('edit','edit.php',lang('Edit'),$fields[0],$customfields); @@ -91,7 +91,7 @@ $t->set_var('lang_submit',lang('submit')); $t->set_var('cancel_link','
'); - if (($this->grants[$check[0]['owner']] & PHPGW_ACL_DELETE) || $check[0]['owner'] == $phpgw_info['user']['account_id']) + if (($contacts->grants[$check[0]['owner']] & PHPGW_ACL_DELETE) || $check[0]['owner'] == $phpgw_info['user']['account_id']) { $t->set_var('delete_link',''); $t->set_var('delete_button',''); @@ -153,9 +153,9 @@ $fields['adr_one_postalcode'] = $bzip; $fields['adr_one_countryname'] = $bcountry; - reset($this->adr_types); + reset($contacts->adr_types); $typed = ''; - while (list($type,$val) = each($this->adr_types)) + while (list($type,$val) = each($contacts->adr_types)) { $ftype = 'one_'.$type; eval("if (\$\$ftype=='on') { \$typed .= \$type . ';'; }"); @@ -171,9 +171,9 @@ $fields['adr_two_postalcode'] = $hzip; $fields['adr_two_countryname'] = $hcountry; - reset($this->adr_types); + reset($contacts->adr_types); $typed = ''; - while (list($type,$val) = each($this->adr_types)) + while (list($type,$val) = each($contacts->adr_types)) { $ftype = 'two_'.$type; eval("if (\$\$ftype=='on') { \$typed .= \$type . ';'; }"); @@ -214,7 +214,7 @@ $fields['cat_id'] = $cat_id; } - if (($this->grants[$check[0]['owner']] & PHPGW_ACL_EDIT) && $check[0]['owner'] != $phpgw_info['user']['account_id']) + if (($contacts->grants[$check[0]['owner']] & PHPGW_ACL_EDIT) && $check[0]['owner'] != $phpgw_info['user']['account_id']) { $userid = $check[0]['owner']; } diff --git a/addressbook/export.php b/addressbook/export.php index 14be383bd7..799b36c928 100644 --- a/addressbook/export.php +++ b/addressbook/export.php @@ -97,7 +97,7 @@ { include (PHPGW_APP_ROOT . SEP . 'export' . SEP . $conv_type); $buffer=array(); - $this = new export_conv; + $contacts = new export_conv; // Read in user custom fields, if any $customfields = array(); @@ -115,32 +115,32 @@ 'address2' => 'address2', 'address3' => 'address3' ); - if ($this->type != 'vcard') + if ($contacts->type != 'vcard') { - $this->qfields = $this->stock_contact_fields;# + $extrafields;# + $customfields; + $contacts->qfields = $contacts->stock_contact_fields;# + $extrafields;# + $customfields; } if (!empty($cat_id)) { - $buffer = $this->export_start_file($buffer,$cat_id); + $buffer = $contacts->export_start_file($buffer,$cat_id); } else { - $buffer = $this->export_start_file($buffer); + $buffer = $contacts->export_start_file($buffer); } - for ($i=0;$iids);$i++) + for ($i=0;$iids);$i++) { - $buffer = $this->export_start_record($buffer); - while( list($name,$value) = each($this->currentrecord) ) + $buffer = $contacts->export_start_record($buffer); + while( list($name,$value) = each($contacts->currentrecord) ) { - $buffer = $this->export_new_attrib($buffer,$name,$value); + $buffer = $contacts->export_new_attrib($buffer,$name,$value); } - $buffer = $this->export_end_record($buffer); + $buffer = $contacts->export_end_record($buffer); } // Here, buffer becomes a string suitable for printing - $buffer = $this->export_end_file($buffer); + $buffer = $contacts->export_end_file($buffer); $tsvfilename = $phpgw_info['server']['temp_dir'].$sep.$tsvfilename; } diff --git a/addressbook/import.php b/addressbook/import.php index 8ff9f617e9..46536b06f6 100644 --- a/addressbook/import.php +++ b/addressbook/import.php @@ -72,10 +72,10 @@ if ($private == '') { $private = 'public'; } $row=0; $buffer=array(); - $this = new import_conv; - $buffer = $this->import_start_file($buffer); + $contacts = new import_conv; + $buffer = $contacts->import_start_file($buffer); $fp=fopen($tsvfile,'r'); - if ($this->type == 'csv') + if ($contacts->type == 'csv') { while ($data = fgetcsv($fp,8000,',')) { @@ -84,27 +84,27 @@ if ($row == 1) { // Changed here to ignore the header, set to our array - while(list($lhs,$rhs) = each($this->import)) + while(list($lhs,$rhs) = each($contacts->import)) { $header[] = $lhs; } } else { - $buffer = $this->import_start_record($buffer); + $buffer = $contacts->import_start_record($buffer); for ($c=0; $c<$num; $c++ ) { //Send name/value pairs along with the buffer - if ($this->import[$header[$c]] != '' && $data[$c] != '') + if ($contacts->import[$header[$c]] != '' && $data[$c] != '') { - $buffer = $this->import_new_attrib($buffer, $this->import[$header[$c]],$data[$c]); + $buffer = $contacts->import_new_attrib($buffer, $contacts->import[$header[$c]],$data[$c]); } } - $buffer = $this->import_end_record($buffer,$private); + $buffer = $contacts->import_end_record($buffer,$private); } } } - elseif ($this->type == 'ldif') + elseif ($contacts->type == 'ldif') { while ($data = fgets($fp,8000)) { @@ -112,7 +112,7 @@ list($name,$value,$extra) = split(':', $data); if (substr($name,0,2) == 'dn') { - $buffer = $this->import_start_record($buffer); + $buffer = $contacts->import_start_record($buffer); } $test = trim($value); @@ -144,14 +144,14 @@ $value = $url. ':' . $value; } //echo '
'.$j.': '.$name.' => '.$value; - if ($this->import[$name] != '' && $value != '') + if ($contacts->import[$name] != '' && $value != '') { - $buffer = $this->import_new_attrib($buffer, $this->import[$name],$value); + $buffer = $contacts->import_new_attrib($buffer, $contacts->import[$name],$value); } } else { - $buffer = $this->import_end_record($buffer,$private); + $buffer = $contacts->import_end_record($buffer,$private); } } } @@ -170,28 +170,28 @@ if (strtolower(substr($name,0,5)) == 'begin') { - $buffer = $this->import_start_record($buffer); + $buffer = $contacts->import_start_record($buffer); } if ($name && $value) { - reset($this->import); - while ( list($fname,$fvalue) = each($this->import) ) + reset($contacts->import); + while ( list($fname,$fvalue) = each($contacts->import) ) { - if ( strstr(strtolower($name), $this->import[$fname]) ) + if ( strstr(strtolower($name), $contacts->import[$fname]) ) { - $buffer = $this->import_new_attrib($buffer,$name,$value); + $buffer = $contacts->import_new_attrib($buffer,$name,$value); } } } else { - $buffer = $this->import_end_record($buffer); + $buffer = $contacts->import_end_record($buffer); } } } fclose($fp); - $buffer = $this->import_end_file($buffer,$private,$cat_id); + $buffer = $contacts->import_end_file($buffer,$private,$cat_id); if ($download == '') { diff --git a/addressbook/inc/class.contacts_ldap.inc.php b/addressbook/inc/class.contacts_ldap.inc.php index a184e5e9d2..959e24fc4e 100644 --- a/addressbook/inc/class.contacts_ldap.inc.php +++ b/addressbook/inc/class.contacts_ldap.inc.php @@ -311,7 +311,7 @@ // send this the range, query, sort, order and whatever fields you want to see // 'rights' and 'access' are unused at this time - function read($start=0,$offset=0,$fields="",$query="",$filter="",$sort="",$order="") + function read($start=0,$limit=0,$fields="",$query="",$filter="",$sort="",$order="") { global $phpgw,$phpgw_info; @@ -464,15 +464,22 @@ // 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. - if ($start && $offset) { - $limit = $start + $offset;; - } elseif ($start && !$offset) { + if ($start && $limit) + { + $limit = $start + $limit; + } + elseif ($start && !$limit) + { $limit = $start; - } elseif(!$start && !$offset) { + } + elseif(!$start && !$limit) + { $limit = $this->total_records; - } else { #(!$start && $offset) { + } + else + { #(!$start && $limit) { $start = 0; - $limit = $offset; + $limit = $limit; } //echo '('.$start.','.$limit.')'; diff --git a/addressbook/inc/class.contacts_sql.inc.php b/addressbook/inc/class.contacts_sql.inc.php index 1803b218cc..cb9d8041d9 100644 --- a/addressbook/inc/class.contacts_sql.inc.php +++ b/addressbook/inc/class.contacts_sql.inc.php @@ -49,7 +49,7 @@ { global $phpgw, $phpgw_info; - $this->db = $phpgw->db; + $this->db = $phpgw->db; if($useacl) { $this->grants = $phpgw->acl->get_grants('addressbook'); @@ -183,7 +183,7 @@ $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(); $return_fields[0]['id'] = $this->db->f('id'); // unique id @@ -221,7 +221,7 @@ } } - $this->db2->query("SELECT contact_name,contact_value FROM $this->ext_table where contact_id='" . $this->db->f("id") . "'",__LINE__,__FILE__); + $this->db2->query("SELECT contact_name,contact_value FROM $this->ext_table where contact_id='" . $this->db->f('id') . "'",__LINE__,__FILE__); while ($this->db2->next_record()) { // If its not in the list to be returned, don't return it. @@ -256,7 +256,7 @@ $id = $this->db->f(0); - $this->db->query("SELECT id,lid,tid,owner,access,cat_id $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'); @@ -294,7 +294,7 @@ } } - $this->db2->query("select contact_name,contact_value from $this->ext_table where contact_id='" . $this->db->f("id") . "'",__LINE__,__FILE__); + $this->db2->query("SELECT contact_name,contact_value FROM $this->ext_table WHERE contact_id='" . $this->db->f('id') . "'",__LINE__,__FILE__); while ($this->db2->next_record()) { // If its not in the list to be returned, don't return it. @@ -307,8 +307,8 @@ return $return_fields; } - // send this the range, query, sort, order and whatever fields you want to see - function read($start=0,$offset=0,$fields="",$query="",$filter="",$sort="",$order="") + /* send this the range, query, sort, order and whatever fields you want to see */ + function read($start=0,$limit=0,$fields="",$query="",$filter="",$sort="",$order="") { global $phpgw,$phpgw_info; @@ -318,24 +318,17 @@ list($stock_fields,$stock_fieldnames,$extra_fields) = $this->split_stock_and_extras($fields); if (count($stock_fieldnames)) { - $t_fields = "," . implode(",",$stock_fieldnames); - if ($t_fields == ",") + $t_fields = ',' . implode(',',$stock_fieldnames); + if ($t_fields == ',') { unset($t_fields); } } - // turn filter's a=b,c=d OR a=b into an array - if ($filter) { - $extra_stock = array( - 'id' => 'id', - 'tid' => 'tid', - 'lid' => 'lid', - 'owner' => 'owner', - 'access' => 'access', - 'cat_id' => 'cat_id' - ); - $check_stock = $this->stock_contact_fields + $extra_stock; + /* turn filter's a=b,c=d OR a=b into an array */ + if ($filter) + { + $check_stock = $this->stock_contact_fields + $this->non_contact_fields; if ($DEBUG) { echo "DEBUG - Inbound filter is: #".$filter."#"; } $filterarray = split(',',$filter); @@ -344,7 +337,7 @@ $i=0; for ($i=0;$iDEBUG - Filter intermediate strings 1: #".$name."# => #".$value."#"; } @@ -357,28 +350,27 @@ list($name,$value) = split('=',$filter); if ($DEBUG) { - echo "
DEBUG - Filter intermediate strings 1: #".$name."# => #".$value."#"; + echo '
DEBUG - Filter intermediate strings 1: #'.$name.'# => #'.$value.'#'; } $filterfields = array($name => $value); } - // now check each element of the array and convert into SQL for queries - // below + /* now check each element of the array and convert into SQL for queries below */ $i=0; reset($filterfields); while (list($name,$value) = each($filterfields)) { - if ($DEBUG) { echo "
DEBUG - Filter intermediate strings 2: #".$name."# => #".$value."#"; } + if ($DEBUG) { echo '
DEBUG - Filter intermediate strings 2: #'.$name.'# => #'.$value.'#'; } $isstd=0; if ($name && empty($value)) { - if ($DEBUG) { echo "
DEBUG - filter field '".$name."' is empty (NULL)"; } + if ($DEBUG) { echo '
DEBUG - filter field "'.$name.'" is empty (NULL)'; } while (list($fname,$fvalue)=each($check_stock)) { if ($fvalue==$name) { $filterlist .= $name.' is NULL,'; - if ($DEBUG) { echo "
DEBUG - filter field '".$name."' is a stock field"; } + if ($DEBUG) { echo '
DEBUG - filter field "'.$name.'" is a stock field'; } break; } } @@ -392,7 +384,6 @@ { if ($name == 'cat_id') { - // This is the alternative to CONCAT, since it is mysql-only $filterlist .= "(" . $name . " LIKE '%," . $value . ",%' OR " . $name."='".$value."');"; } elseif (gettype($value) == "integer") @@ -412,11 +403,6 @@ $filterlist = substr($filterlist,0,-1); $filterlist = ereg_replace(";"," AND ",$filterlist); - // echo "

contacts->read(): filterlist=\"$filterlist\" -->"; // allow multiple (','-separated) cat's per address - //$filterlist = ereg_replace('cat_id=[\']*([0-9]+)[\']*',"CONCAT(',',cat_id,',') LIKE '%,\\1,%'",$filterlist); - // echo "\"$filterlist\"

\n"; - // Oops, CONCAT is mysql-only, this is now handled explicitly above for cat_id - if ($DEBUG) { echo "
DEBUG - Filter output string: #".$filterlist."#"; @@ -495,65 +481,50 @@ $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. - if ($start && $offset) { - $limit = $this->db->limit($start,$offset); - } elseif ($start && !$offset) { - $limit = ""; - } elseif(!$start && !$offset) { - $limit = ""; - } else { #(!$start && $offset) { - $start = 0; - $limit = $this->db->limit($start,$offset); - } - - $this->db3 = $this->db2 = $this->db; // Create new result objects before our queries - if ($query) { - $this->db3->query("SELECT * FROM $this->std_table WHERE (bday LIKE '%$query%' OR n_family LIKE '" + $sql = "SELECT * FROM $this->std_table WHERE (bday LIKE '%$query%' OR n_family LIKE '" . "%$query%' OR n_given LIKE '%$query%' OR email LIKE '%$query%' OR " . "adr_one_street LIKE '%$query%' OR adr_one_locality LIKE '%$query%' OR adr_one_region LIKE '%$query%' OR " . "adr_one_postalcode LIKE '%$query%' OR adr_one_countryname LIKE '%$query%' OR " . "adr_two_street LIKE '%$query%' OR adr_two_locality LIKE '%$query%' OR adr_two_region LIKE '%$query%' OR " . "adr_two_postalcode LIKE '%$query%' OR adr_two_countryname LIKE '%$query%' OR " - . "org_name LIKE '%$query%' OR org_unit LIKE '%$query%') " . $fand . $filtermethod . $ordermethod,__LINE__,__FILE__); - $this->total_records = $this->db3->num_rows(); - - $this->db->query("SELECT * FROM $this->std_table WHERE (bday LIKE '%$query%' OR n_family LIKE '" - . "%$query%' OR n_given LIKE '%$query%' OR email LIKE '%$query%' OR " - . "adr_one_street LIKE '%$query%' OR adr_one_locality LIKE '%$query%' OR adr_one_region LIKE '%$query%' OR " - . "adr_one_postalcode LIKE '%$query%' OR adr_one_countryname LIKE '%$query%' OR " - . "adr_two_street LIKE '%$query%' OR adr_two_locality LIKE '%$query%' OR adr_two_region LIKE '%$query%' OR " - . "adr_two_postalcode LIKE '%$query%' OR adr_two_countryname LIKE '%$query%' OR " - . "org_name LIKE '%$query%' OR org_unit LIKE '%$query%') " . $fand . $filtermethod . $ordermethod . " " - . $limit,__LINE__,__FILE__); + . "org_name LIKE '%$query%' OR org_unit LIKE '%$query%') " . $fand . $filtermethod . $ordermethod; } else { - $this->db3->query("SELECT id,lid,tid,owner,access,cat_id $t_fields FROM $this->std_table " . $fwhere - . $filtermethod,__LINE__,__FILE__); - $this->total_records = $this->db3->num_rows(); - - $this->db->query("SELECT id,lid,tid,owner,access,cat_id $t_fields FROM $this->std_table " . $fwhere - . $filtermethod . " " . $ordermethod . " " . $limit,__LINE__,__FILE__); + $sql = "SELECT id,lid,tid,owner,access,cat_id $t_fields FROM $this->std_table " . $fwhere + . $filtermethod . " " . $ordermethod; } - if ($DEBUG) { echo "
SELECT id,lid,tid,owner,access,cat_id $t_fields FROM $this->std_table " . $fwhere . $filtermethod; } + if ($DEBUG) { echo "
$sql"; } + + $this->db2 = $this->db; + $this->db2->query($sql,__LINE__,__FILE__); + + $this->total_records = $this->db2->num_rows(); + + if ($start && $limit) + { + $this->db->limit_query($sql,array($start,$limit),__LINE__,__FILE__); + } + elseif (!$limit) + { + $this->db->query($sql,__LINE__,__FILE__); + } + else + { + $this->db->limit_query($sql,$start,__LINE__,__FILE__); + } $i=0; while ($this->db->next_record()) { - // unique id, lid for group/account records, - // type id (g/u) for groups/accounts, and - // id of owner/parent for the record $return_fields[$i]['id'] = $this->db->f('id'); $return_fields[$i]['lid'] = $this->db->f('lid'); $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]['access'] = $this->db->f('access'); $return_fields[$i]['cat_id'] = $this->db->f('cat_id'); if (gettype($stock_fieldnames) == 'array') @@ -565,11 +536,9 @@ reset($stock_fieldnames); } $this->db2->query("SELECT contact_name,contact_value FROM $this->ext_table WHERE contact_id='" - . $this->db->f("id") . "'" .$filterextra,__LINE__,__FILE__); + . $this->db->f('id') . "'" .$filterextra,__LINE__,__FILE__); while ($this->db2->next_record()) { - // If its not in the list to be returned, don't return it. - // This is still quicker then 5(+) separate queries if ($extra_fields[$this->db2->f('contact_name')]) { $return_fields[$i][$this->db2->f('contact_name')] = $this->db2->f('contact_value'); @@ -584,26 +553,25 @@ { list($stock_fields,$stock_fieldnames,$extra_fields) = $this->split_stock_and_extras($fields); - //$this->db->lock(array("contacts")); if ($fields['lid']) { $lid[0] = 'lid,'; $lid[1] = $fields['lid']."','"; } - $this->db->query("insert into $this->std_table (owner,access,cat_id,tid,".$lid[0] + $this->db->query("INSERT INTO $this->std_table (owner,access,cat_id,tid,".$lid[0] . implode(",",$this->stock_contact_fields) - . ") values ('$owner','$access','$cat_id','$tid','".$lid[1] + . ") VALUES ('$owner','$access','$cat_id','$tid','".$lid[1] . implode("','",$this->loop_addslashes($stock_fields)) . "')",__LINE__,__FILE__); - $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(); $id = $this->db->f(0); - //$this->db->unlock(); + if (count($extra_fields)) { while (list($name,$value) = each($extra_fields)) { - $this->db->query("insert into $this->ext_table values ('$id','" . $this->account_id . "','" + $this->db->query("INSERT INTO $this->ext_table VALUES ('$id','" . $this->account_id . "','" . addslashes($name) . "','" . addslashes($value) . "')",__LINE__,__FILE__); } } @@ -611,7 +579,7 @@ function field_exists($id,$field_name) { - $this->db->query("select count(*) from $this->ext_table where contact_id='$id' and contact_name='" + $this->db->query("SELECT COUNT(*) FROM $this->ext_table WHERE contact_id='$id' AND contact_name='" . addslashes($field_name) . "'",__LINE__,__FILE__); $this->db->next_record(); return $this->db->f(0); @@ -619,20 +587,20 @@ function add_single_extra_field($id,$owner,$field_name,$field_value) { - $this->db->query("insert into $this->ext_table values ($id,'$owner','" . addslashes($field_name) + $this->db->query("INSERT INTO $this->ext_table VALUES ($id,'$owner','" . addslashes($field_name) . "','" . addslashes($field_value) . "')",__LINE__,__FILE__); } function delete_single_extra_field($id,$field_name) { - $this->db->query("delete from $this->ext_table where contact_id='$id' and contact_name='" + $this->db->query("DELETE FROM $this->ext_table WHERE contact_id='$id' AND contact_name='" . addslashes($field_name) . "'",__LINE__,__FILE__); } function update($id,$owner,$fields,$access='',$cat_id='',$tid='n') { // First make sure that id number exists - $this->db->query("select count(*) from $this->std_table where id='$id'",__LINE__,__FILE__); + $this->db->query("SELECT COUNT(*) FROM $this->std_table WHERE id='$id'",__LINE__,__FILE__); $this->db->next_record(); if (!$this->db->f(0)) { @@ -651,7 +619,7 @@ { unset($field_s); } - $this->db->query("update $this->std_table set access='$access',cat_id='$cat_id', tid='$tid' $fields_s where " + $this->db->query("UPDATE $this->std_table SET access='$access',cat_id='$cat_id', tid='$tid' $fields_s WHERE " . "id='$id'",__LINE__,__FILE__); } @@ -665,9 +633,9 @@ } else { - $this->db->query("update $this->ext_table set contact_value='" . addslashes($x_value) - . "',contact_owner='$owner' where contact_name='" . addslashes($x_name) - . "' and contact_id='$id'",__LINE__,__FILE__); + $this->db->query("UPDATE $this->ext_table SET contact_value='" . addslashes($x_value) + . "',contact_owner='$owner' WHERE contact_name='" . addslashes($x_name) + . "' AND contact_id='$id'",__LINE__,__FILE__); } } else @@ -685,8 +653,8 @@ return False; } - $this->db->query("update $this->std_table set owner='$new_owner' WHERE owner=$old_owner",__LINE__,__FILE__); - $this->db->query("update $this->ext_table set contact_owner='$new_owner' WHERE contact_owner=$old_owner",__LINE__,__FILE__); + $this->db->query("UPDATE $this->std_table SET owner='$new_owner' WHERE owner=$old_owner",__LINE__,__FILE__); + $this->db->query("UPDATE $this->ext_table SET contact_owner='$new_owner' WHERE contact_owner=$old_owner",__LINE__,__FILE__); return; } @@ -694,8 +662,8 @@ // This is where the real work of delete() is done, shared class file contains calling function function delete_($id) { - $this->db->query("delete from $this->std_table where id='$id'",__LINE__,__FILE__); - $this->db->query("delete from $this->ext_table where contact_id='$id'",__LINE__,__FILE__); + $this->db->query("DELETE FROM $this->std_table WHERE id='$id'",__LINE__,__FILE__); + $this->db->query("DELETE FROM $this->ext_table WHERE contact_id='$id'",__LINE__,__FILE__); } // This is for the admin script deleteaccount.php diff --git a/addressbook/inc/functions.inc.php b/addressbook/inc/functions.inc.php index 7965b4585f..bfef191b8f 100755 --- a/addressbook/inc/functions.inc.php +++ b/addressbook/inc/functions.inc.php @@ -113,8 +113,9 @@ $phpgw->preferences->save_repository(1); } - // Return a select form element with the categories option dialog in it - function cat_option($cat_id='',$notall=False,$java=True,$multiple=False) { + /* Return a select form element with the categories option dialog in it */ + function cat_option($cat_id='',$notall=False,$java=True,$multiple=False) + { global $phpgw_info; if ($java) { @@ -132,38 +133,39 @@ $cats_link .= '>'.lang("all").''."\n"; } - // Get global and app-specific category listings + /* Get global and app-specific category listings */ $cats = CreateObject('phpgwapi.categories'); $cats_link .= $cats->formated_list('select','all',$cat_id,True); $cats_link .= ''."\n"; return $cats_link; } - ### SET THE FONT TO DEFAULT IF IT DOESNT EXISTS ### + /* SET THE FONT TO DEFAULT IF IT DOESNT EXISTS */ function set_font() { - if($phpgw_info["user"]["preferences"]["notes"]["notes_font"] == "") + if($phpgw_info['user']['preferences']['notes']['notes_font'] == '') { $font = "Arial"; return $font; } else { - $font = $phpgw_info["user"]["preferences"]["notes"]["notes_font"]; + $font = $phpgw_info['user']['preferences']['notes']['notes_font']; return $font; } } - ### SET FONT SIZE #### + /* SET FONT SIZE */ function set_font_size() { - if($phpgw_info["user"]["preferences"]["notes"]["notes_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"]; + $font_size = $phpgw_info['user']['preferences']['notes']['notes_font_size']; return $font_size; } } @@ -234,7 +236,7 @@ } } - function addressbook_strip_html($dirty = "") + function addressbook_strip_html($dirty = '') { global $phpgw; if ($dirty == ""){$dirty = array();} @@ -247,81 +249,81 @@ return $cleaned; } - function addressbook_read_entries($start,$offset,$qcols,$query,$qfilter,$sort,$order,$userid="") + function addressbook_read_entries($start,$offset,$qcols,$query,$qfilter,$sort,$order,$userid='') { - global $this,$rights; + global $contacts,$rights; $readrights = $rights & PHPGW_ACL_READ; - $entries = $this->read($start,$offset,$qcols,$query,$qfilter,$sort,$order,$readrights); + $entries = $contacts->read($start,$offset,$qcols,$query,$qfilter,$sort,$order,$readrights); $cleaned = addressbook_strip_html($entries); return $cleaned; } - function addressbook_read_entry($id,$fields,$userid="") + function addressbook_read_entry($id,$fields,$userid='') { - global $this,$rights; + global $contacts,$rights; if ($rights & PHPGW_ACL_READ) { - $entry = $this->read_single_entry($id,$fields); + $entry = $contacts->read_single_entry($id,$fields); $cleaned = addressbook_strip_html($entry); return $cleaned; } else { - $rtrn = array("No access" => "No access"); + $rtrn = array('No access' => 'No access'); return $rtrn; } } function addressbook_read_last_entry($fields) { - global $this,$rights; + global $contacts,$rights; if ($rights & PHPGW_ACL_READ) { - $entry = $this->read_last_entry($fields); + $entry = $contacts->read_last_entry($fields); $cleaned = addressbook_strip_html($entry); return $cleaned; } else { - $rtrn = array("No access" => "No access"); + $rtrn = array('No access' => 'No access'); return $rtrn; } } function addressbook_add_entry($userid,$fields,$access='',$cat_id='',$tid='n') { - global $this,$rights; + global $contacts,$rights; if ($rights & PHPGW_ACL_ADD) { - $this->add($userid,$fields,$access,$cat_id,$tid); + $contacts->add($userid,$fields,$access,$cat_id,$tid); } return; } function addressbook_get_lastid() { - global $this; - $entry = $this->read_last_entry(); - $ab_id = $entry[0]["id"]; + global $contacts; + $entry = $contacts->read_last_entry(); + $ab_id = $entry[0]['id']; return $ab_id; } function addressbook_update_entry($id,$userid,$fields,$access,$cat_id) { - global $this,$rights; + global $contacts,$rights; if ($rights & PHPGW_ACL_EDIT) { - $this->update($id,$userid,$fields,$access,$cat_id); + $contacts->update($id,$userid,$fields,$access,$cat_id); } return; } // Folowing used for add/edit - function addressbook_form($format,$action,$title="",$fields="",$customfields="",$cat_id="") + function addressbook_form($format,$action,$title='',$fields='',$customfields='',$cat_id='') { global $phpgw,$phpgw_info,$referer; - $t = new Template(PHPGW_APP_TPL); + $t = CreateObject('phpgwapi.Template',PHPGW_APP_TPL); $t->set_file(array('form' => 'form.tpl')); //$t->set_block('form','add','add'); //$t->set_block('form','edit','edit'); @@ -422,14 +424,14 @@ } } - $this = CreateObject("phpgwapi.contacts"); + $c = CreateObject("phpgwapi.contacts"); if ($format != "view") { // Preferred phone number radio buttons $pref[0] = ""; $pref[1] = "(".lang('pref').")"; - while (list($name,$val) = each($this->tel_types)) + while (list($name,$val) = each($c->tel_types)) { $str[$name] = "\n".' email_types)) + while ($type = each($c->email_types)) { $email_type .= '