From aba0107f88729b4618e247e60001804d26666939 Mon Sep 17 00:00:00 2001 From: Miles Lott Date: Sun, 21 Jan 2001 02:31:24 +0000 Subject: [PATCH] Begin move to classes for addressbook. Note ldap is a copy of sql for now. --- addressbook/delete.php | 7 +- addressbook/edit.php | 130 ++--- addressbook/inc/class.addressbook.inc.php | 4 + .../inc/class.addressbook_ldap.inc.php | 310 +++++++++++ .../inc/class.addressbook_shared.inc.php | 36 ++ addressbook/inc/class.addressbook_sql.inc.php | 310 +++++++++++ addressbook/inc/functions.inc.php | 499 ++++++++++++------ addressbook/index.php | 199 ++----- 8 files changed, 1086 insertions(+), 409 deletions(-) create mode 100644 addressbook/inc/class.addressbook.inc.php create mode 100644 addressbook/inc/class.addressbook_ldap.inc.php create mode 100644 addressbook/inc/class.addressbook_shared.inc.php create mode 100644 addressbook/inc/class.addressbook_sql.inc.php diff --git a/addressbook/delete.php b/addressbook/delete.php index b9efccdcdb..c902779e5a 100755 --- a/addressbook/delete.php +++ b/addressbook/delete.php @@ -24,6 +24,8 @@ @Header("Location: " . $phpgw->link($phpgw_info["server"]["webserver_url"] . "/addressbook/")); } + $this = CreateObject("addressbook.addressbook"); + if ($confirm != "true") { $phpgw->db->query("select ab_owner from addressbook where ab_id='$ab_id'"); $phpgw->db->next_record(); @@ -43,11 +45,10 @@ $phpgw->common->phpgw_footer(); } else { + $this->id = $ab_id; + $this->delete_entry(); - $phpgw->db->query("delete from addressbook where ab_owner='" . $phpgw_info["user"]["account_id"] - . "' and ab_id='$ab_id'"); @Header("Location: " . $phpgw->link($phpgw_info["server"]["webserver_url"]. "/addressbook/", "cd=16&order=$order&sort=$sort&filter=$filter&start=$start&query=$query")); } ?> - diff --git a/addressbook/edit.php b/addressbook/edit.php index ad92cbb405..6d720e83fe 100755 --- a/addressbook/edit.php +++ b/addressbook/edit.php @@ -29,104 +29,51 @@ $phpgw->common->phpgw_exit(); } + $this = CreateObject("addressbook.addressbook"); + if (! $submit) { - $phpgw->db->query("SELECT * FROM addressbook WHERE ab_owner='" - . $phpgw_info["user"]["account_id"] . "' AND ab_id=$ab_id"); - $phpgw->db->next_record(); - - $fields = array('ab_id' => $phpgw->db->f("ab_id"), - 'owner' => $phpgw->db->f("ab_owner"), - 'access' => $phpgw->db->f("ab_access"), - 'firstname' => $phpgw->db->f("ab_firstname"), - 'lastname' => $phpgw->db->f("ab_lastname"), - 'title' => $phpgw->db->f("ab_title"), - 'email' => $phpgw->db->f("ab_email"), - 'hphone' => $phpgw->db->f("ab_hphone"), - 'wphone' => $phpgw->db->f("ab_wphone"), - 'fax' => $phpgw->db->f("ab_fax"), - 'pager' => $phpgw->db->f("ab_pager"), - 'mphone' => $phpgw->db->f("ab_mphone"), - 'ophone' => $phpgw->db->f("ab_ophone"), - 'street' => $phpgw->db->f("ab_street"), - 'address2' => $phpgw->db->f("ab_address2"), - 'city' => $phpgw->db->f("ab_city"), - 'state' => $phpgw->db->f("ab_state"), - 'zip' => $phpgw->db->f("ab_zip"), - 'bday' => $phpgw->db->f("ab_bday"), - 'company' => $phpgw->db->f("ab_company"), - 'company_id' => $phpgw->db->f("ab_company_id"), - 'notes' => $phpgw->db->f("ab_notes"), - 'url' => $phpgw->db->f("ab_url") - ); - + $fields = $this->get_entry($ab_id); form("","edit.php","Edit",$fields); - } else { - if ($url == "http://") { - $url = ""; - } - - if (! $bday_month && ! $bday_day && ! $bday_year) { - $bday = ""; - } else { - $bday = "$bday_month/$bday_day/$bday_year"; - } - + if ($url == "http://") { + $url = ""; + } + if (! $bday_month && ! $bday_day && ! $bday_year) { + $bday = ""; + } else { + $bday = "$bday_month/$bday_day/$bday_year"; + } if ($access != "private" && $access != "public") { - $access = $phpgw->accounts->array_to_string($access,$n_groups); + $access = $phpgw->accounts->array_to_string($access,$n_groups); } - if($phpgw_info["apps"]["timetrack"]["enabled"]) { - $sql = "UPDATE addressbook set ab_email='" . addslashes($email) - . "', ab_firstname='" . addslashes($firstname) - . "', ab_lastname='" . addslashes($lastname) - . "', ab_title='" . addslashes($title) - . "', ab_hphone='" . addslashes($hphone) - . "', ab_wphone='" . addslashes($wphone) - . "', ab_fax='" . addslashes($fax) - . "', ab_pager='" . addslashes($pager) - . "', ab_mphone='" . addslashes($mphone) - . "', ab_ophone='" . addslashes($ophone) - . "', ab_street='" . addslashes($street) - . "', ab_address2='" . addslashes($address2) - . "', ab_city='" . addslashes($city) - . "', ab_state='" . addslashes($state) - . "', ab_zip='" . addslashes($zip) - . "', ab_bday='" . addslashes($bday) - . "', ab_notes='" . addslashes($notes) - . "', ab_company_id='" . addslashes($company) - . "', ab_access='" . addslashes($access) - . "', ab_url='" . addslashes($url) - . "' WHERE ab_owner='" . $phpgw_info["user"]["account_id"] . "' AND ab_id=$ab_id"; - } else { - $sql = "UPDATE addressbook set ab_email='" . addslashes($email) - . "', ab_firstname='". addslashes($firstname) - . "', ab_lastname='" . addslashes($lastname) - . "', ab_title='" . addslashes($title) - . "', ab_hphone='" . addslashes($hphone) - . "', ab_wphone='" . addslashes($wphone) - . "', ab_fax='" . addslashes($fax) - . "', ab_pager='" . addslashes($pager) - . "', ab_mphone='" . addslashes($mphone) - . "', ab_ophone='" . addslashes($ophone) - . "', ab_street='" . addslashes($street) - . "', ab_address2='" . addslashes($address2) - . "', ab_city='" . addslashes($city) - . "', ab_state='" . addslashes($state) - . "', ab_zip='" . addslashes($zip) - . "', ab_bday='" . addslashes($bday) - . "', ab_notes='" . addslashes($notes) - . "', ab_company='" . addslashes($company) - . "', ab_access='" . addslashes($access) - . "', ab_url='" . addslashes($url) - . "' WHERE ab_owner='" . $phpgw_info["user"]["account_id"] . "' AND ab_id=$ab_id"; - } + $this->id = $ab_id; + $this->company = $company; + $this->firstname = $firstname; + $this->lastname = $lastname; + $this->email = $email; + $this->title = $title; + $this->wphone = $wphone; + $this->hphone = $hphone; + $this->fax = $fax; + $this->pager = $pager; + $this->mphone = $mphone; + $this->ophone = $ophone; + $this->street = $street; + $this->address2 = $address2; + $this->city = $city; + $this->state = $state; + $this->zip = $zip; + $this->bday = $bday; + $this->url = $url; + $this->notes = $notes; + $this->access = $access; - $phpgw->db->query($sql); - - Header("Location: " . $phpgw->link("view.php","&ab_id=$ab_id&order=$order&sort=$sort&filter=" - . "$filter&start=$start")); - $phpgw->common->phpgw_exit(); + $this->update_entry($this); + + Header("Location: " . $phpgw->link("view.php","&ab_id=$ab_id&order=$order&sort=$sort&filter=" + . "$filter&start=$start")); + $phpgw->common->phpgw_exit(); } $t->set_var("ab_id",$ab_id); @@ -145,6 +92,5 @@ $t->parse("out","edit"); $t->pparse("out","edit"); - $phpgw->common->phpgw_footer(); ?> diff --git a/addressbook/inc/class.addressbook.inc.php b/addressbook/inc/class.addressbook.inc.php new file mode 100644 index 0000000000..e2582d88ff --- /dev/null +++ b/addressbook/inc/class.addressbook.inc.php @@ -0,0 +1,4 @@ + diff --git a/addressbook/inc/class.addressbook_ldap.inc.php b/addressbook/inc/class.addressbook_ldap.inc.php new file mode 100644 index 0000000000..5f81395f83 --- /dev/null +++ b/addressbook/inc/class.addressbook_ldap.inc.php @@ -0,0 +1,310 @@ + * + * -------------------------------------------- * + * 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$ */ + + class addressbook_ + { + var $id; + var $company; + var $firstname; + var $lastname; + var $email; + var $wphone; + var $hphone; + var $company; + var $fax; + var $pager; + var $mphone; + var $ophone; + var $street; + var $city; + var $state; + var $zip; + var $bday; + var $url; + var $notes; + var $access; + var $searchreturn; + var $search_filter; + var $lang_showing; + var $columns_to_display; + var $cols; + + function get_entry($id) { + global $phpgw,$phpgw_info; + $phpgw->db->query("SELECT * FROM addressbook WHERE ab_owner='" + . $phpgw_info["user"]["account_id"] . "' AND ab_id='".$id."'"); + $phpgw->db->next_record(); + + $this->ab_id = stripslashes($phpgw->db->f("ab_id")); + $this->owner = stripslashes($phpgw->db->f("ab_owner")); + $this->access = stripslashes($phpgw->db->f("ab_access")); + $this->firstname = stripslashes($phpgw->db->f("ab_firstname")); + $this->lastname = stripslashes($phpgw->db->f("ab_lastname")); + $this->title = stripslashes($phpgw->db->f("ab_title")); + $this->email = stripslashes($phpgw->db->f("ab_email")); + $this->hphone = stripslashes($phpgw->db->f("ab_hphone")); + $this->wphone = stripslashes($phpgw->db->f("ab_wphone")); + $this->fax = stripslashes($phpgw->db->f("ab_fax")); + $this->pager = stripslashes($phpgw->db->f("ab_pager")); + $this->mphone = stripslashes($phpgw->db->f("ab_mphone")); + $this->ophone = stripslashes($phpgw->db->f("ab_ophone")); + $this->street = stripslashes($phpgw->db->f("ab_street")); + $this->address2 = stripslashes($phpgw->db->f("ab_address2")); + $this->city = stripslashes($phpgw->db->f("ab_city")); + $this->state = stripslashes($phpgw->db->f("ab_state")); + $this->zip = stripslashes($phpgw->db->f("ab_zip")); + $this->bday = stripslashes($phpgw->db->f("ab_bday")); + $this->company = stripslashes($phpgw->db->f("ab_company")); + $this->company_id = stripslashes($phpgw->db->f("ab_company_id")); + $this->notes = stripslashes($phpgw->db->f("ab_notes")); + $this->url = stripslashes($phpgw->db->f("ab_url")); + $this->access = stripslashes($phpgw->db->f("ab_access")); + + return $this; + } + + function update_entry() { + global $phpgw,$phpgw_info; + + if($phpgw_info["apps"]["timetrack"]["enabled"]) { + $sql = "UPDATE addressbook set " + . " ab_email='" . addslashes($this->email) + . "', ab_firstname='" . addslashes($this->firstname) + . "', ab_lastname='" . addslashes($this->lastname) + . "', ab_title='" . addslashes($this->title) + . "', ab_hphone='" . addslashes($this->hphone) + . "', ab_wphone='" . addslashes($this->wphone) + . "', ab_company='" . addslashes($this->company) + . "', ab_fax='" . addslashes($this->fax) + . "', ab_pager='" . addslashes($this->pager) + . "', ab_mphone='" . addslashes($this->mphone) + . "', ab_ophone='" . addslashes($this->ophone) + . "', ab_street='" . addslashes($this->street) + . "', ab_address2='" . addslashes($this->address2) + . "', ab_city='" . addslashes($this->city) + . "', ab_state='" . addslashes($this->state) + . "', ab_zip='" . addslashes($this->zip) + . "', ab_bday='" . addslashes($this->bday) + . "', ab_notes='" . addslashes($this->notes) + . "', ab_company_id='" . addslashes($this->company_id) + . "', ab_access='" . addslashes($this->access) + . "', ab_url='" . addslashes($this->url) + . "' WHERE ab_owner='" . $phpgw_info["user"]["account_id"] + . "' AND ab_id='" . $this->id."'"; + } else { + $sql = "UPDATE addressbook set " + . " ab_email='" . addslashes($this->email) + . "', ab_firstname='" . addslashes($this->firstname) + . "', ab_lastname='" . addslashes($this->lastname) + . "', ab_title='" . addslashes($this->title) + . "', ab_hphone='" . addslashes($this->hphone) + . "', ab_wphone='" . addslashes($this->wphone) + . "', ab_fax='" . addslashes($this->fax) + . "', ab_pager='" . addslashes($this->pager) + . "', ab_mphone='" . addslashes($this->mphone) + . "', ab_ophone='" . addslashes($this->ophone) + . "', ab_street='" . addslashes($this->street) + . "', ab_address2='" . addslashes($this->address2) + . "', ab_city='" . addslashes($this->city) + . "', ab_state='" . addslashes($this->state) + . "', ab_zip='" . addslashes($this->zip) + . "', ab_bday='" . addslashes($this->bday) + . "', ab_notes='" . addslashes($this->notes) + . "', ab_company='" . addslashes($this->company) + . "', ab_access='" . addslashes($this->access) + . "', ab_url='" . addslashes($this->url) + . "' WHERE ab_owner='" . $phpgw_info["user"]["account_id"] + . "' AND ab_id='" . $this->id."'"; + } + $phpgw->db->query($sql); + return; + } + + function delete_entry() { + global $phpgw,$phpgw_info; + + $phpgw->db->query("delete from addressbook where ab_owner='" + . $phpgw_info["user"]["account_id"] + . "' and ab_id='".$this->id."'"); + + return; + } + + function count_entries() { + global $phpgw,$phpgw_info; + if ($phpgw_info["apps"]["timetrack"]["enabled"]) { + $phpgw->db->query("SELECT count(*) " + . "from addressbook as a, customers as c where a.ab_company_id = c.company_id " + . "AND $filtermethod AND (a.ab_lastname like '" + . "%$query%' OR a.ab_firstname like '%$query%' OR a.ab_email like '%$query%' OR " + . "a.ab_street like '%$query%' OR a.ab_city like '%$query%' OR a.ab_state " + . "like '%$query%' OR a.ab_zip like '%$query%' OR a.ab_notes like " + . "'%$query%' OR c.company_name like '%$query%' OR a.ab_url like '%$query%')",__LINE__,__FILE__); +// . "'%$query%' OR c.company_name like '%$query%')" + } else { + $phpgw->db->query("SELECT count(*) " + . "from addressbook " + . "WHERE $filtermethod AND (ab_lastname like '" + . "%$query%' OR ab_firstname like '%$query%' OR ab_email like '%$query%' OR " + . "ab_street like '%$query%' OR ab_city like '%$query%' OR ab_state " + . "like '%$query%' OR ab_zip like '%$query%' OR ab_notes like " + . "'%$query%' OR ab_company like '%$query%' OR ab_url like '%$query$%')",__LINE__,__FILE__); +// . "'%$query%' OR ab_company like '%$query%')" + } + $phpgw->db->next_record(); + + if ($phpgw->db->f(0) == 1) { + return lang("your search returned 1 match"); + } else { + $this->limit = $phpgw->db->f(0); + return lang("your search returned x matchs",$phpgw->db->f(0)); + } + } + + function get_entries($query="",$filter="",$sort="",$order="",$start=0) { + global $phpgw,$phpgw_info,$abc; + + $limit = $phpgw->nextmatchs->sql_limit($start); + + if ($order) { + $ordermethod = "order by $order $sort"; + } else { + $ordermethod = "order by ab_lastname,ab_firstname,ab_email asc"; + } + + if (! $filter) { + $filter = "none"; + } + + if ($filter != "private") { + if ($filter != "none") { + $filtermethod = " ab_access like '%,$filter,%' "; + } else { + $filtermethod = " (ab_owner='" . $phpgw_info["user"]["account_id"] ."' OR ab_access='public' " + . $phpgw->accounts->sql_search("ab_access") . " ) "; + } + } else { + $filtermethod = " ab_owner='" . $phpgw_info["user"]["account_id"] . "' "; + } + + if ($query) { + $this->searchreturn=$this->count_entries(); + } else { + $this->searchreturn=""; + $phpgw->db->query("select count(*) from addressbook where $filtermethod",__LINE__,__FILE__); + $phpgw->db->next_record(); + } + + if ($phpgw_info["apps"]["timetrack"]["enabled"]) { + $company_sortorder = "c.company_name"; + } else { + $company_sortorder = "ab_company"; + } + + //$phpgw->db->next_record(); + + if ($phpgw->db->f(0) > $phpgw_info["user"]["preferences"]["common"]["maxmatchs"]) { + $this->lang_showing=lang("showing x - x of x",($start + 1),($start + $phpgw_info["user"]["preferences"]["common"]["maxmatchs"]),$phpgw->db->f(0)); + } else { + $this->lang_showing=lang("showing x",$phpgw->db->f(0)); + } + + $this->search_filter = $phpgw->nextmatchs->show_tpl("index.php",$start,$phpgw->db->f(0),"&order=$order&filter=$filter&sort=$sort&query=$query", "75%", $phpgw_info["theme"]["th_bg"]); + + while ($column = each($abc)) { + if (isset($phpgw_info["user"]["preferences"]["addressbook"][$column[0]]) && + $phpgw_info["user"]["preferences"]["addressbook"][$column[0]]) { + $this->cols .= ''; + $this->cols .= ''; + $this->cols .= $phpgw->nextmatchs->show_sort_order($sort,"ab_" . $column[0],$order,"index.php",lang($column[1])); + $this->cols .= ''; + $this->cols .= "\n"; + + // To be used when displaying the rows + $this->columns_to_display[$column[0]] = True; + } + } + + if (isset($query) && $query) { + if (isset($phpgw_info["apps"]["timetrack"]["enabled"]) && + $phpgw_info["apps"]["timetrack"]["enabled"]) { + $phpgw->db->query("SELECT a.ab_id,a.ab_owner,a.ab_firstname,a.ab_lastname,a.ab_company_id," + . "a.ab_email,a.ab_wphone,c.company_name,a.ab_hphone,a.ab_fax,a.ab_mphone " + . "from addressbook as a, customers as c where a.ab_company_id = c.company_id " + . "AND $filtermethod AND (a.ab_lastname like '" + . "%$query%' OR a.ab_firstname like '%$query%' OR a.ab_email like '%$query%' OR " + . "a.ab_street like '%$query%' OR a.ab_city like '%$query%' OR a.ab_state " + . "like '%$query%' OR a.ab_zip like '%$query%' OR a.ab_notes like " + . "'%$query%' OR c.company_name like '%$query%') $ordermethod limit $limit",__LINE__,__FILE__); + } else { + $phpgw->db->query("SELECT * from addressbook WHERE $filtermethod AND (ab_lastname like '" + . "%$query%' OR ab_firstname like '%$query%' OR ab_email like '%$query%' OR " + . "ab_street like '%$query%' OR ab_city like '%$query%' OR ab_state " + . "like '%$query%' OR ab_zip like '%$query%' OR ab_notes like " + . "'%$query%' OR ab_company like '%$query%') $ordermethod limit $limit",__LINE__,__FILE__); + } + } else { + if ($phpgw_info["apps"]["timetrack"]["enabled"]) { + $phpgw->db->query("SELECT a.ab_id,a.ab_owner,a.ab_firstname,a.ab_lastname," + . "a.ab_email,a.ab_wphone,c.company_name " + . "from addressbook as a, customers as c where a.ab_company_id = c.company_id " + . "AND $filtermethod $ordermethod limit $limit",__LINE__,__FILE__); + } else { + $phpgw->db->query("SELECT * from addressbook WHERE $filtermethod $ordermethod limit $limit",__LINE__,__FILE__); + } + } + + $i=0; + while ($phpgw->db->next_record()) { + $this->ab_id[$i] = htmlentities(stripslashes($phpgw->db->f("ab_id"))); + $this->owner[$i] = htmlentities(stripslashes($phpgw->db->f("ab_owner"))); + $this->access[$i] = htmlentities(stripslashes($phpgw->db->f("ab_access"))); + $this->firstname[$i] = htmlentities(stripslashes($phpgw->db->f("ab_firstname"))); + $this->lastname[$i] = htmlentities(stripslashes($phpgw->db->f("ab_lastname"))); + $this->title[$i] = htmlentities(stripslashes($phpgw->db->f("ab_title"))); + $this->email[$i] = htmlentities(stripslashes($phpgw->db->f("ab_email"))); + $this->hphone[$i] = htmlentities(stripslashes($phpgw->db->f("ab_hphone"))); + $this->wphone[$i] = htmlentities(stripslashes($phpgw->db->f("ab_wphone"))); + $this->fax[$i] = htmlentities(stripslashes($phpgw->db->f("ab_fax"))); + $this->pager[$i] = htmlentities(stripslashes($phpgw->db->f("ab_pager"))); + $this->mphone[$i] = htmlentities(stripslashes($phpgw->db->f("ab_mphone"))); + $this->ophone[$i] = htmlentities(stripslashes($phpgw->db->f("ab_ophone"))); + $this->street[$i] = htmlentities(stripslashes($phpgw->db->f("ab_street"))); + $this->address2[$i] = htmlentities(stripslashes($phpgw->db->f("ab_address2"))); + $this->city[$i] = htmlentities(stripslashes($phpgw->db->f("ab_city"))); + $this->state[$i] = htmlentities(stripslashes($phpgw->db->f("ab_state"))); + $this->zip[$i] = htmlentities(stripslashes($phpgw->db->f("ab_zip"))); + $this->bday[$i] = htmlentities(stripslashes($phpgw->db->f("ab_bday"))); + if ($phpgw_info["apps"]["timetrack"]["enabled"]) { + $this->company[$i] = htmlentities(stripslashes($phpgw->db->f("ab_company"))); + } else { + $this->company[$i] = htmlentities(stripslashes($phpgw->db->f("company_name"))); + } + $this->company_id[$i] = htmlentities(stripslashes($phpgw->db->f("ab_company_id"))); + $this->notes[$i] = htmlentities(stripslashes($phpgw->db->f("ab_notes"))); + if ($phpgw->db->f("ab_url")) { + if (! ereg("^http://",$phpgw->db->f("ab_url")) ) { + $this->url[$i] = htmlentities("http://".stripslashes($phpgw->db->f("ab_url"))); + } else { + $this->url[$i] = htmlentities(stripslashes($phpgw->db->f("ab_url"))); + } + } else { + $this->url[$i] = htmlentities(""); + } + $i++; + } + return $this; + } + } +?> diff --git a/addressbook/inc/class.addressbook_shared.inc.php b/addressbook/inc/class.addressbook_shared.inc.php new file mode 100644 index 0000000000..6b1b77e07f --- /dev/null +++ b/addressbook/inc/class.addressbook_shared.inc.php @@ -0,0 +1,36 @@ + * + * -------------------------------------------- * + * 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$ */ + class addressbook extends addressbook_ + { + function colname($column,$listid) { + if ($column == "company") return $this->company[$listid]; + elseif ($column == "firstname") return $this->firstname[$listid]; + elseif ($column == "lastname") return $this->lastname[$listid]; + elseif ($column == "email") return $this->email[$listid]; + elseif ($column == "wphone") return $this->wphone[$listid]; + elseif ($column == "hphone") return $this->hphone[$listid]; + elseif ($column == "fax") return $this->fax[$listid]; + elseif ($column == "pager") return $this->pager[$listid]; + elseif ($column == "mphone") return $this->mphone[$listid]; + elseif ($column == "ophone") return $this->ophone[$listid]; + elseif ($column == "street") return $this->street[$listid]; + elseif ($column == "city") return $this->city[$listid]; + elseif ($column == "state") return $this->state[$listid]; + elseif ($column == "zip") return $this->zip[$listid]; + elseif ($column == "bday") return $this->bday[$listid]; + elseif ($column == "url") return $this->url[$listid]; + else return ""; + } + } +?> diff --git a/addressbook/inc/class.addressbook_sql.inc.php b/addressbook/inc/class.addressbook_sql.inc.php new file mode 100644 index 0000000000..5f81395f83 --- /dev/null +++ b/addressbook/inc/class.addressbook_sql.inc.php @@ -0,0 +1,310 @@ + * + * -------------------------------------------- * + * 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$ */ + + class addressbook_ + { + var $id; + var $company; + var $firstname; + var $lastname; + var $email; + var $wphone; + var $hphone; + var $company; + var $fax; + var $pager; + var $mphone; + var $ophone; + var $street; + var $city; + var $state; + var $zip; + var $bday; + var $url; + var $notes; + var $access; + var $searchreturn; + var $search_filter; + var $lang_showing; + var $columns_to_display; + var $cols; + + function get_entry($id) { + global $phpgw,$phpgw_info; + $phpgw->db->query("SELECT * FROM addressbook WHERE ab_owner='" + . $phpgw_info["user"]["account_id"] . "' AND ab_id='".$id."'"); + $phpgw->db->next_record(); + + $this->ab_id = stripslashes($phpgw->db->f("ab_id")); + $this->owner = stripslashes($phpgw->db->f("ab_owner")); + $this->access = stripslashes($phpgw->db->f("ab_access")); + $this->firstname = stripslashes($phpgw->db->f("ab_firstname")); + $this->lastname = stripslashes($phpgw->db->f("ab_lastname")); + $this->title = stripslashes($phpgw->db->f("ab_title")); + $this->email = stripslashes($phpgw->db->f("ab_email")); + $this->hphone = stripslashes($phpgw->db->f("ab_hphone")); + $this->wphone = stripslashes($phpgw->db->f("ab_wphone")); + $this->fax = stripslashes($phpgw->db->f("ab_fax")); + $this->pager = stripslashes($phpgw->db->f("ab_pager")); + $this->mphone = stripslashes($phpgw->db->f("ab_mphone")); + $this->ophone = stripslashes($phpgw->db->f("ab_ophone")); + $this->street = stripslashes($phpgw->db->f("ab_street")); + $this->address2 = stripslashes($phpgw->db->f("ab_address2")); + $this->city = stripslashes($phpgw->db->f("ab_city")); + $this->state = stripslashes($phpgw->db->f("ab_state")); + $this->zip = stripslashes($phpgw->db->f("ab_zip")); + $this->bday = stripslashes($phpgw->db->f("ab_bday")); + $this->company = stripslashes($phpgw->db->f("ab_company")); + $this->company_id = stripslashes($phpgw->db->f("ab_company_id")); + $this->notes = stripslashes($phpgw->db->f("ab_notes")); + $this->url = stripslashes($phpgw->db->f("ab_url")); + $this->access = stripslashes($phpgw->db->f("ab_access")); + + return $this; + } + + function update_entry() { + global $phpgw,$phpgw_info; + + if($phpgw_info["apps"]["timetrack"]["enabled"]) { + $sql = "UPDATE addressbook set " + . " ab_email='" . addslashes($this->email) + . "', ab_firstname='" . addslashes($this->firstname) + . "', ab_lastname='" . addslashes($this->lastname) + . "', ab_title='" . addslashes($this->title) + . "', ab_hphone='" . addslashes($this->hphone) + . "', ab_wphone='" . addslashes($this->wphone) + . "', ab_company='" . addslashes($this->company) + . "', ab_fax='" . addslashes($this->fax) + . "', ab_pager='" . addslashes($this->pager) + . "', ab_mphone='" . addslashes($this->mphone) + . "', ab_ophone='" . addslashes($this->ophone) + . "', ab_street='" . addslashes($this->street) + . "', ab_address2='" . addslashes($this->address2) + . "', ab_city='" . addslashes($this->city) + . "', ab_state='" . addslashes($this->state) + . "', ab_zip='" . addslashes($this->zip) + . "', ab_bday='" . addslashes($this->bday) + . "', ab_notes='" . addslashes($this->notes) + . "', ab_company_id='" . addslashes($this->company_id) + . "', ab_access='" . addslashes($this->access) + . "', ab_url='" . addslashes($this->url) + . "' WHERE ab_owner='" . $phpgw_info["user"]["account_id"] + . "' AND ab_id='" . $this->id."'"; + } else { + $sql = "UPDATE addressbook set " + . " ab_email='" . addslashes($this->email) + . "', ab_firstname='" . addslashes($this->firstname) + . "', ab_lastname='" . addslashes($this->lastname) + . "', ab_title='" . addslashes($this->title) + . "', ab_hphone='" . addslashes($this->hphone) + . "', ab_wphone='" . addslashes($this->wphone) + . "', ab_fax='" . addslashes($this->fax) + . "', ab_pager='" . addslashes($this->pager) + . "', ab_mphone='" . addslashes($this->mphone) + . "', ab_ophone='" . addslashes($this->ophone) + . "', ab_street='" . addslashes($this->street) + . "', ab_address2='" . addslashes($this->address2) + . "', ab_city='" . addslashes($this->city) + . "', ab_state='" . addslashes($this->state) + . "', ab_zip='" . addslashes($this->zip) + . "', ab_bday='" . addslashes($this->bday) + . "', ab_notes='" . addslashes($this->notes) + . "', ab_company='" . addslashes($this->company) + . "', ab_access='" . addslashes($this->access) + . "', ab_url='" . addslashes($this->url) + . "' WHERE ab_owner='" . $phpgw_info["user"]["account_id"] + . "' AND ab_id='" . $this->id."'"; + } + $phpgw->db->query($sql); + return; + } + + function delete_entry() { + global $phpgw,$phpgw_info; + + $phpgw->db->query("delete from addressbook where ab_owner='" + . $phpgw_info["user"]["account_id"] + . "' and ab_id='".$this->id."'"); + + return; + } + + function count_entries() { + global $phpgw,$phpgw_info; + if ($phpgw_info["apps"]["timetrack"]["enabled"]) { + $phpgw->db->query("SELECT count(*) " + . "from addressbook as a, customers as c where a.ab_company_id = c.company_id " + . "AND $filtermethod AND (a.ab_lastname like '" + . "%$query%' OR a.ab_firstname like '%$query%' OR a.ab_email like '%$query%' OR " + . "a.ab_street like '%$query%' OR a.ab_city like '%$query%' OR a.ab_state " + . "like '%$query%' OR a.ab_zip like '%$query%' OR a.ab_notes like " + . "'%$query%' OR c.company_name like '%$query%' OR a.ab_url like '%$query%')",__LINE__,__FILE__); +// . "'%$query%' OR c.company_name like '%$query%')" + } else { + $phpgw->db->query("SELECT count(*) " + . "from addressbook " + . "WHERE $filtermethod AND (ab_lastname like '" + . "%$query%' OR ab_firstname like '%$query%' OR ab_email like '%$query%' OR " + . "ab_street like '%$query%' OR ab_city like '%$query%' OR ab_state " + . "like '%$query%' OR ab_zip like '%$query%' OR ab_notes like " + . "'%$query%' OR ab_company like '%$query%' OR ab_url like '%$query$%')",__LINE__,__FILE__); +// . "'%$query%' OR ab_company like '%$query%')" + } + $phpgw->db->next_record(); + + if ($phpgw->db->f(0) == 1) { + return lang("your search returned 1 match"); + } else { + $this->limit = $phpgw->db->f(0); + return lang("your search returned x matchs",$phpgw->db->f(0)); + } + } + + function get_entries($query="",$filter="",$sort="",$order="",$start=0) { + global $phpgw,$phpgw_info,$abc; + + $limit = $phpgw->nextmatchs->sql_limit($start); + + if ($order) { + $ordermethod = "order by $order $sort"; + } else { + $ordermethod = "order by ab_lastname,ab_firstname,ab_email asc"; + } + + if (! $filter) { + $filter = "none"; + } + + if ($filter != "private") { + if ($filter != "none") { + $filtermethod = " ab_access like '%,$filter,%' "; + } else { + $filtermethod = " (ab_owner='" . $phpgw_info["user"]["account_id"] ."' OR ab_access='public' " + . $phpgw->accounts->sql_search("ab_access") . " ) "; + } + } else { + $filtermethod = " ab_owner='" . $phpgw_info["user"]["account_id"] . "' "; + } + + if ($query) { + $this->searchreturn=$this->count_entries(); + } else { + $this->searchreturn=""; + $phpgw->db->query("select count(*) from addressbook where $filtermethod",__LINE__,__FILE__); + $phpgw->db->next_record(); + } + + if ($phpgw_info["apps"]["timetrack"]["enabled"]) { + $company_sortorder = "c.company_name"; + } else { + $company_sortorder = "ab_company"; + } + + //$phpgw->db->next_record(); + + if ($phpgw->db->f(0) > $phpgw_info["user"]["preferences"]["common"]["maxmatchs"]) { + $this->lang_showing=lang("showing x - x of x",($start + 1),($start + $phpgw_info["user"]["preferences"]["common"]["maxmatchs"]),$phpgw->db->f(0)); + } else { + $this->lang_showing=lang("showing x",$phpgw->db->f(0)); + } + + $this->search_filter = $phpgw->nextmatchs->show_tpl("index.php",$start,$phpgw->db->f(0),"&order=$order&filter=$filter&sort=$sort&query=$query", "75%", $phpgw_info["theme"]["th_bg"]); + + while ($column = each($abc)) { + if (isset($phpgw_info["user"]["preferences"]["addressbook"][$column[0]]) && + $phpgw_info["user"]["preferences"]["addressbook"][$column[0]]) { + $this->cols .= ''; + $this->cols .= ''; + $this->cols .= $phpgw->nextmatchs->show_sort_order($sort,"ab_" . $column[0],$order,"index.php",lang($column[1])); + $this->cols .= ''; + $this->cols .= "\n"; + + // To be used when displaying the rows + $this->columns_to_display[$column[0]] = True; + } + } + + if (isset($query) && $query) { + if (isset($phpgw_info["apps"]["timetrack"]["enabled"]) && + $phpgw_info["apps"]["timetrack"]["enabled"]) { + $phpgw->db->query("SELECT a.ab_id,a.ab_owner,a.ab_firstname,a.ab_lastname,a.ab_company_id," + . "a.ab_email,a.ab_wphone,c.company_name,a.ab_hphone,a.ab_fax,a.ab_mphone " + . "from addressbook as a, customers as c where a.ab_company_id = c.company_id " + . "AND $filtermethod AND (a.ab_lastname like '" + . "%$query%' OR a.ab_firstname like '%$query%' OR a.ab_email like '%$query%' OR " + . "a.ab_street like '%$query%' OR a.ab_city like '%$query%' OR a.ab_state " + . "like '%$query%' OR a.ab_zip like '%$query%' OR a.ab_notes like " + . "'%$query%' OR c.company_name like '%$query%') $ordermethod limit $limit",__LINE__,__FILE__); + } else { + $phpgw->db->query("SELECT * from addressbook WHERE $filtermethod AND (ab_lastname like '" + . "%$query%' OR ab_firstname like '%$query%' OR ab_email like '%$query%' OR " + . "ab_street like '%$query%' OR ab_city like '%$query%' OR ab_state " + . "like '%$query%' OR ab_zip like '%$query%' OR ab_notes like " + . "'%$query%' OR ab_company like '%$query%') $ordermethod limit $limit",__LINE__,__FILE__); + } + } else { + if ($phpgw_info["apps"]["timetrack"]["enabled"]) { + $phpgw->db->query("SELECT a.ab_id,a.ab_owner,a.ab_firstname,a.ab_lastname," + . "a.ab_email,a.ab_wphone,c.company_name " + . "from addressbook as a, customers as c where a.ab_company_id = c.company_id " + . "AND $filtermethod $ordermethod limit $limit",__LINE__,__FILE__); + } else { + $phpgw->db->query("SELECT * from addressbook WHERE $filtermethod $ordermethod limit $limit",__LINE__,__FILE__); + } + } + + $i=0; + while ($phpgw->db->next_record()) { + $this->ab_id[$i] = htmlentities(stripslashes($phpgw->db->f("ab_id"))); + $this->owner[$i] = htmlentities(stripslashes($phpgw->db->f("ab_owner"))); + $this->access[$i] = htmlentities(stripslashes($phpgw->db->f("ab_access"))); + $this->firstname[$i] = htmlentities(stripslashes($phpgw->db->f("ab_firstname"))); + $this->lastname[$i] = htmlentities(stripslashes($phpgw->db->f("ab_lastname"))); + $this->title[$i] = htmlentities(stripslashes($phpgw->db->f("ab_title"))); + $this->email[$i] = htmlentities(stripslashes($phpgw->db->f("ab_email"))); + $this->hphone[$i] = htmlentities(stripslashes($phpgw->db->f("ab_hphone"))); + $this->wphone[$i] = htmlentities(stripslashes($phpgw->db->f("ab_wphone"))); + $this->fax[$i] = htmlentities(stripslashes($phpgw->db->f("ab_fax"))); + $this->pager[$i] = htmlentities(stripslashes($phpgw->db->f("ab_pager"))); + $this->mphone[$i] = htmlentities(stripslashes($phpgw->db->f("ab_mphone"))); + $this->ophone[$i] = htmlentities(stripslashes($phpgw->db->f("ab_ophone"))); + $this->street[$i] = htmlentities(stripslashes($phpgw->db->f("ab_street"))); + $this->address2[$i] = htmlentities(stripslashes($phpgw->db->f("ab_address2"))); + $this->city[$i] = htmlentities(stripslashes($phpgw->db->f("ab_city"))); + $this->state[$i] = htmlentities(stripslashes($phpgw->db->f("ab_state"))); + $this->zip[$i] = htmlentities(stripslashes($phpgw->db->f("ab_zip"))); + $this->bday[$i] = htmlentities(stripslashes($phpgw->db->f("ab_bday"))); + if ($phpgw_info["apps"]["timetrack"]["enabled"]) { + $this->company[$i] = htmlentities(stripslashes($phpgw->db->f("ab_company"))); + } else { + $this->company[$i] = htmlentities(stripslashes($phpgw->db->f("company_name"))); + } + $this->company_id[$i] = htmlentities(stripslashes($phpgw->db->f("ab_company_id"))); + $this->notes[$i] = htmlentities(stripslashes($phpgw->db->f("ab_notes"))); + if ($phpgw->db->f("ab_url")) { + if (! ereg("^http://",$phpgw->db->f("ab_url")) ) { + $this->url[$i] = htmlentities("http://".stripslashes($phpgw->db->f("ab_url"))); + } else { + $this->url[$i] = htmlentities(stripslashes($phpgw->db->f("ab_url"))); + } + } else { + $this->url[$i] = htmlentities(""); + } + $i++; + } + return $this; + } + } +?> diff --git a/addressbook/inc/functions.inc.php b/addressbook/inc/functions.inc.php index e7c25e9cea..0ebec0aca1 100755 --- a/addressbook/inc/functions.inc.php +++ b/addressbook/inc/functions.inc.php @@ -15,7 +15,7 @@ // NOTE: This entire file needs to be rewritten. There is a great deal of code not being used // anymore. This should also be converted to templates while where at it (jengo) - $abc = array('company' => 'company', // AddressBook Columns and their descriptions + $abc = array('company' => 'company', // AddressBook Columns and their descriptions 'firstname' => 'first name', 'lastname' => 'last name', 'email' => 'email', @@ -23,6 +23,7 @@ 'hphone' => 'home phone', 'fax' => 'fax', 'pager' => 'pager', + 'title' => 'title', 'mphone' => 'mobile phone', 'ophone' => 'other phone', 'street' => 'street', @@ -33,124 +34,124 @@ 'url' => 'URL' ); - function form($format,$action,$title,$fields) - { - global $phpgw, $phpgw_info; - - $t = new Template($phpgw_info["server"]["app_tpl"]); - $t->set_file(array( "form" => "form.tpl")); - $email = $fields["email"]; - $firstname = $fields["firstname"]; - $lastname = $fields["lastname"]; - $title = $fields["title"]; - $hphone = $fields["hphone"]; - $wphone = $fields["wphone"]; - $faxi = $fields["fax"]; - $pager = $fields["pager"]; - $mphone = $fields["mphone"]; - $ophone = $fields["ophone"]; - $street = $fields["street"]; - $address2 = $fields["address2"]; - $city = $fields["city"]; - $state = $fields["state"]; - $zip = $fields["zip"]; - $bday = $fields["bday"]; - $notes = $fields["notes"]; - $access = $fields["access"]; - $ab_company = $fields["company"]; - $company_id = $fields["company_id"]; - $company_name = $fields["company_name"]; - $url = $fields["url"]; + function form($format,$action,$title,$fields) { + global $phpgw, $phpgw_info; + + $t = new Template($phpgw_info["server"]["app_tpl"]); + $t->set_file(array( "form" => "form.tpl")); + + $email = $fields->email; + $firstname = $fields->firstname; + $lastname = $fields->lastname; + $title = $fields->title; + $hphone = $fields->hphone; + $wphone = $fields->wphone; + $fax = $fields->fax; + $pager = $fields->pager; + $mphone = $fields->mphone; + $ophone = $fields->ophone; + $street = $fields->street; + $address2 = $fields->address2; + $city = $fields->city; + $state = $fields->state; + $zip = $fields->zip; + $bday = $fields->bday; + $notes = $fields->notes; + $access = $fields->access; + $ab_company = $fields->company; + $company_id = $fields->company_id; + $company_name = $fields->company_name; + $url = $fields->url; if ($format != "view") { - $email = ""; - $firstname = ""; - $lastname = ""; - $title = ""; - $hphone = ""; - $wphone = ""; - $fax = ""; - $pager = ""; - $mphone = ""; - $ophone = ""; - $street = ""; - $address2 = ""; - $city = ""; - $state = ""; - $zip = ""; - //$url = ""; + $encurl = ($url); + $email = ""; + $firstname = ""; + $lastname = ""; + $title = ""; + $hphone = ""; + $wphone = ""; + $fax = ""; + $pager = ""; + $mphone = ""; + $ophone = ""; + $street = ""; + $address2 = ""; + $city = ""; + $state = ""; + $zip = ""; +// $url = ""; - if($phpgw_info["apps"]["timetrack"]["enabled"]) { - $company = '"; - } else { - $company = ""; - } + if($phpgw_info["apps"]["timetrack"]["enabled"]) { + $company = '"; + } else { + $company = ""; + } - if (strlen($bday) > 2) { - list( $month, $day, $year ) = split( '/', $bday ); - $temp_month[$month] = "SELECTED"; + if (strlen($bday) > 2) { + list( $month, $day, $year ) = split( '/', $bday ); + $temp_month[$month] = "SELECTED"; - $bday_month = ""; - $bday_day = '' -; - $bday_year = ''; - } else { - $bday_month = ""; - $bday_day = ''; - $bday_year = ''; - } + $bday_month = ""; + $bday_day = ''; + $bday_year = ''; + } else { + $bday_month = ""; + $bday_day = ''; + $bday_year = ''; + } $notes = ''; - } else { - $notes = "
"; - if ($bday == "//") + if ($bday == "//") $bday = ""; - if($phpgw_info["apps"]["timetrack"]["enabled"]) { - $company = $company_name; - } else { - $company = $ab_company; - } - } + if($phpgw_info["apps"]["timetrack"]["enabled"]) { + $company = $company_name; + } else { + $company = $ab_company; + } + } if ($action) { echo "
link($action)."\" method=\"post\">\n"; @@ -158,13 +159,11 @@ // test: //echo "Time track app status = " . $phpgw_info["apps"]["timetrack"]["enabled"]; - #$url .= 'common->dateformatorder($bday_year,$bday_month,$bday_day) . '(e.g. 1969)'; @@ -235,48 +234,236 @@ else $create = ''; - $t->set_var("lang_lastname",lang("Last Name")); - $t->set_var("lastname",$lastname); - $t->set_var("lang_firstname",lang("First Name")); - $t->set_var("firstname",$firstname); - $t->set_var("lang_company",lang("Company")); - $t->set_var("company",$company); - $t->set_var("lang_title",lang("Title")); - $t->set_var("title",$title); - $t->set_var("lang_email",lang("Email")); - $t->set_var("email",$email); - $t->set_var("lang_url",lang("url")); - $t->set_var("url",$url); - $t->set_var("lang_hphone",lang("Home Phone")); - $t->set_var("hphone",$hphone); - $t->set_var("lang_fax",lang("fax")); - $t->set_var("fax",$fax); - $t->set_var("lang_wphone",lang("Work Phone")); - $t->set_var("wphone",$wphone); - $t->set_var("lang_pager",lang("Pager")); - $t->set_var("pager",$pager); - $t->set_var("lang_mphone",lang("Mobile")); - $t->set_var("mphone",$mphone); - $t->set_var("lang_ophone",lang("Other Number")); - $t->set_var("ophone",$ophone); - $t->set_var("lang_street",lang("Street")); - $t->set_var("street",$street); - $t->set_var("lang_birthday",lang("Birthday")); - $t->set_var("birthday",$birthday); - $t->set_var("lang_address2",lang("Line 2")); - $t->set_var("address2",$address2); - $t->set_var("lang_city",lang("city")); - $t->set_var("city",$state); - $t->set_var("lang_state",lang("state")); - $t->set_var("state",$state); - $t->set_var("lang_zip",lang("Zip Code")); - $t->set_var("zip",$zip); - $t->set_var("access_link",$access_link); - $t->set_var("create",$create); - $t->set_var("lang_notes",lang("notes")); - $t->set_var("notes",$notes); + $t->set_var("lang_lastname",lang("Last Name")); + $t->set_var("lastname",$lastname); + $t->set_var("lang_firstname",lang("First Name")); + $t->set_var("firstname",$firstname); + $t->set_var("lang_company",lang("Company Name")); + $t->set_var("company",$company); + $t->set_var("lang_title",lang("Title")); + $t->set_var("title",$title); + $t->set_var("lang_email",lang("Email")); + $t->set_var("email",$email); + $t->set_var("lang_url",lang("URL")); + $t->set_var("url",$url); + $t->set_var("lang_hphone",lang("Home Phone")); + $t->set_var("hphone",$hphone); + $t->set_var("lang_fax",lang("fax")); + $t->set_var("fax",$fax); + $t->set_var("lang_wphone",lang("Work Phone")); + $t->set_var("wphone",$wphone); + $t->set_var("lang_pager",lang("Pager")); + $t->set_var("pager",$pager); + $t->set_var("lang_mphone",lang("Mobile")); + $t->set_var("mphone",$mphone); + $t->set_var("lang_ophone",lang("Other Number")); + $t->set_var("ophone",$ophone); + $t->set_var("lang_street",lang("Street")); + $t->set_var("street",$street); + $t->set_var("lang_birthday",lang("Birthday")); + $t->set_var("birthday",$birthday); + $t->set_var("lang_address2",lang("Line 2")); + $t->set_var("address2",$address2); + $t->set_var("lang_city",lang("city")); + $t->set_var("city",$city); + $t->set_var("lang_state",lang("state")); + $t->set_var("state",$state); + $t->set_var("lang_zip",lang("Zip Code")); + $t->set_var("zip",$zip); + $t->set_var("access_link",$access_link); + $t->set_var("create",$create); + $t->set_var("lang_notes",lang("notes")); + $t->set_var("notes",$notes); + + $t->parse("out","form"); + $t->pparse("out","form"); + } //end form function + + function NOlist_entries($start="",$sort="",$order="",$query="",$filter="") { + global $phpgw,$phpgw_info; + $limit = $phpgw->nextmatchs->sql_limit($start); + + if ($order) { + $ordermethod = "order by $order $sort"; + } else { + $ordermethod = "order by ab_lastname,ab_firstname,ab_email asc"; + } + + if (! $filter) { + $filter = "none"; + } + + if ($filter != "private") { + if ($filter != "none") { + $filtermethod = " ab_access like '%,$filter,%' "; + } else { + $filtermethod = " (ab_owner='" . $phpgw_info["user"]["account_id"] ."' OR ab_access='public' " + . $phpgw->accounts->sql_search("ab_access") . " ) "; + } + } else { + $filtermethod = " ab_owner='" . $phpgw_info["user"]["account_id"] . "' "; + } + + if ($query) { + if ($phpgw_info["apps"]["timetrack"]["enabled"]) { + $phpgw->db->query("SELECT count(*) " + . "from addressbook as a, customers as c where a.ab_company_id = c.company_id " + . "AND $filtermethod AND (a.ab_lastname like '" + . "%$query%' OR a.ab_firstname like '%$query%' OR a.ab_email like '%$query%' OR " + . "a.ab_street like '%$query%' OR a.ab_city like '%$query%' OR a.ab_state " + . "like '%$query%' OR a.ab_zip like '%$query%' OR a.ab_notes like " + . "'%$query%' OR c.company_name like '%$query%' OR a.ab_url like '%$query%')",__LINE__,__FILE__); +// . "'%$query%' OR c.company_name like '%$query%')" +// . " $ordermethod limit $limit"); + } else { + $phpgw->db->query("SELECT count(*) " + . "from addressbook " + . "WHERE $filtermethod AND (ab_lastname like '" + . "%$query%' OR ab_firstname like '%$query%' OR ab_email like '%$query%' OR " + . "ab_street like '%$query%' OR ab_city like '%$query%' OR ab_state " + . "like '%$query%' OR ab_zip like '%$query%' OR ab_notes like " + . "'%$query%' OR ab_company like '%$query%' OR ab_url like '%$query$%')",__LINE__,__FILE__); +// . "'%$query%' OR ab_company like '%$query%')" +// . " $ordermethod limit $limit"); + } + + $phpgw->db->next_record(); + + if ($phpgw->db->f(0) == 1) { + $searchreturn=lang("your search returned 1 match"); + } else { + $searchreturn=lang("your search returned x matchs",$phpgw->db->f(0)); + } + } else { + $searchreturn=""; + $phpgw->db->query("select count(*) from addressbook where $filtermethod",__LINE__,__FILE__); + $phpgw->db->next_record(); + } + + if ($phpgw_info["apps"]["timetrack"]["enabled"]) { + $company_sortorder = "c.company_name"; + } else { + $company_sortorder = "ab_company"; + } + + //$phpgw->db->next_record(); + + if ($phpgw->db->f(0) > $phpgw_info["user"]["preferences"]["common"]["maxmatchs"]) { + $lang_showing=lang("showing x - x of x",($start + 1),($start + $phpgw_info["user"]["preferences"]["common"]["maxmatchs"]),$phpgw->db->f(0)); + } else { + $lang_showing=lang("showing x",$phpgw->db->f(0)); + } + + $search_filter=$phpgw->nextmatchs->show_tpl("index.php",$start,$phpgw->db->f(0),"&order=$order&filter=$filter&sort=$sort&query=$query", "75%", $phpgw_info["theme"]["th_bg"]); + + while ($column = each($this)) { + if (isset($phpgw_info["user"]["preferences"]["addressbook"][$column[0]]) && + $phpgw_info["user"]["preferences"]["addressbook"][$column[0]]) { + $cols .= ''; + $cols .= ''; + $cols .= $phpgw->nextmatchs->show_sort_order($sort,"ab_" . $column[0],$order,"index.php",lang($column[1])); + $cols .= ''; + $cols .= "\n"; + + // To be used when displaying the rows + $columns_to_display[$column[0]] = True; + } + } + + if (isset($query) && $query) { + if (isset($phpgw_info["apps"]["timetrack"]["enabled"]) && + $phpgw_info["apps"]["timetrack"]["enabled"]) { + $phpgw->db->query("SELECT a.ab_id,a.ab_owner,a.ab_firstname,a.ab_lastname,a.ab_company_id," + . "a.ab_email,a.ab_wphone,c.company_name,a.ab_hphone,a.ab_fax,a.ab_mphone " + . "from addressbook as a, customers as c where a.ab_company_id = c.company_id " + . "AND $filtermethod AND (a.ab_lastname like '" + . "%$query%' OR a.ab_firstname like '%$query%' OR a.ab_email like '%$query%' OR " + . "a.ab_street like '%$query%' OR a.ab_city like '%$query%' OR a.ab_state " + . "like '%$query%' OR a.ab_zip like '%$query%' OR a.ab_notes like " + . "'%$query%' OR c.company_name like '%$query%') $ordermethod limit $limit",__LINE__,__FILE__); + } else { + $phpgw->db->query("SELECT * from addressbook WHERE $filtermethod AND (ab_lastname like '" + . "%$query%' OR ab_firstname like '%$query%' OR ab_email like '%$query%' OR " + . "ab_street like '%$query%' OR ab_city like '%$query%' OR ab_state " + . "like '%$query%' OR ab_zip like '%$query%' OR ab_notes like " + . "'%$query%' OR ab_company like '%$query%') $ordermethod limit $limit",__LINE__,__FILE__); + } + } else { + if ($phpgw_info["apps"]["timetrack"]["enabled"]) { + $phpgw->db->query("SELECT a.ab_id,a.ab_owner,a.ab_firstname,a.ab_lastname," + . "a.ab_email,a.ab_wphone,c.company_name " + . "from addressbook as a, customers as c where a.ab_company_id = c.company_id " + . "AND $filtermethod $ordermethod limit $limit",__LINE__,__FILE__); + } else { + $phpgw->db->query("SELECT * from addressbook WHERE $filtermethod $ordermethod limit $limit",__LINE__,__FILE__); + } + } // else $query + $rows=""; + while ($phpgw->db->next_record()) { + $tr_color = $phpgw->nextmatchs->alternate_row_color($tr_color); + $rows .= ''; + + $ab_id = $phpgw->db->f("ab_id"); + + while ($column = each($columns_to_display)) { + if ($column[0] == "company") { + if ($phpgw_info["apps"]["timetrack"]["enabled"]) { + $field = $phpgw->db->f("company_name"); + } else { + $field = $phpgw->db->f("ab_company"); + } + } else { + $field = $phpgw->db->f("ab_" . $column[0]); + } + + $field = htmlentities($field); + + // Some fields require special formating. + if ($column[0] == "url") { + if (! ereg("^http://",$field)) { + $data = "http://" . $field; + } + $rows .= '' + . '' . $field. ' '; + } else if ($column[0] == "email") { + if ($phpgw_info["user"]["apps"]["email"]) { + $rows .= '' + . '' . $field . ' '; + } else { + $rows .= '' + . '' . $field. ' '; + } + } else { + $rows .= '' + . $field . ' '; + } + #echo ''; + } + reset($columns_to_display); // If we don't reset it, our inside while won't loop + $rows .= ' + + '.lang("View").' + + + + + '.lang("vcard").' + + + + + '.$phpgw->common->check_owner($phpgw->db->f("ab_owner"),"edit.php",lang("edit"),"ab_id=" . $phpgw->db->f("ab_id")."&start=".$start."&sort=".$sort."&order=".$order).' + + + +'; + } + return array($cols,$rows,$searchreturn,$lang_showing,$search_filter); + } //end list function - $t->parse("out","form"); - $t->pparse("out","form"); -} ?> diff --git a/addressbook/index.php b/addressbook/index.php index c43f7147c6..b3ad130650 100755 --- a/addressbook/index.php +++ b/addressbook/index.php @@ -27,188 +27,71 @@ "body" => "list.tpl", "addressbook_footer" => "footer.tpl" )); -# $t->set_block("addressbook_header","searchfilter","body", -# "addressbook_footer","output"); + $this = CreateObject("addressbook.addressbook"); + $entries = $this->get_entries($query,$filter,$sort,$order,$start); - $limit =$phpgw->nextmatchs->sql_limit($start); - - if ($order) - $ordermethod = "order by $order $sort"; - else - $ordermethod = "order by ab_lastname,ab_firstname,ab_email asc"; - - if (! $filter) { - $filter = "none"; - } - - if ($filter != "private") { - if ($filter != "none") { - $filtermethod = " ab_access like '%,$filter,%' "; - } else { - $filtermethod = " (ab_owner='" . $phpgw_info["user"]["account_id"] ."' OR ab_access='public' " - . $phpgw->accounts->sql_search("ab_access") . " ) "; - } - } else { - $filtermethod = " ab_owner='" . $phpgw_info["user"]["account_id"] . "' "; - } - - if ($query) { - if ($phpgw_info["apps"]["timetrack"]["enabled"]){ - $phpgw->db->query("SELECT count(*) " - . "from addressbook as a, customers as c where a.ab_company_id = c.company_id " - . "AND $filtermethod AND (a.ab_lastname like '" - . "%$query%' OR a.ab_firstname like '%$query%' OR a.ab_email like '%$query%' OR " - . "a.ab_street like '%$query%' OR a.ab_city like '%$query%' OR a.ab_state " - . "like '%$query%' OR a.ab_zip like '%$query%' OR a.ab_notes like " - . "'%$query%' OR c.company_name like '%$query%' OR a.ab_url like '%$query%')",__LINE__,__FILE__); -// . "'%$query%' OR c.company_name like '%$query%')" -// . " $ordermethod limit $limit"); - } else { - $phpgw->db->query("SELECT count(*) " - . "from addressbook " - . "WHERE $filtermethod AND (ab_lastname like '" - . "%$query%' OR ab_firstname like '%$query%' OR ab_email like '%$query%' OR " - . "ab_street like '%$query%' OR ab_city like '%$query%' OR ab_state " - . "like '%$query%' OR ab_zip like '%$query%' OR ab_notes like " - . "'%$query%' OR ab_company like '%$query%' OR ab_url like '%$query$%')",__LINE__,__FILE__); -// . "'%$query%' OR ab_company like '%$query%')" -// . " $ordermethod limit $limit"); - } - - $phpgw->db->next_record(); - - if ($phpgw->db->f(0) == 1) - $t->set_var(searchreturn,lang("your search returned 1 match")); - else - $t->set_var(searchreturn,lang("your search returned x matchs",$phpgw->db->f(0))); - } else { - $t->set_var(searchreturn,""); - $phpgw->db->query("select count(*) from addressbook where $filtermethod",__LINE__,__FILE__); - $phpgw->db->next_record(); - } - if ($phpgw_info["apps"]["timetrack"]["enabled"]) { - $company_sortorder = "c.company_name"; - } else { - $company_sortorder = "ab_company"; - } - - //$phpgw->db->next_record(); - - if ($phpgw->db->f(0) > $phpgw_info["user"]["preferences"]["common"]["maxmatchs"]) - $t->set_var(lang_showing,lang("showing x - x of x",($start + 1),($start + $phpgw_info["user"]["preferences"]["common"]["maxmatchs"]),$phpgw->db->f(0))); - else - $t->set_var(lang_showing,lang("showing x",$phpgw->db->f(0))); - - $t->set_var("search_filter",$phpgw->nextmatchs->show_tpl("index.php",$start,$phpgw->db->f(0),"&order=$order&filter=$filter&sort=$sort&query=$query", "75%", $phpgw_info["theme"]["th_bg"])); - - while ($column = each($abc)) { - if (isset($phpgw_info["user"]["preferences"]["addressbook"][$column[0]]) && - $phpgw_info["user"]["preferences"]["addressbook"][$column[0]]) { - $cols .= ''; - $cols .= ''; - $cols .= $phpgw->nextmatchs->show_sort_order($sort,"ab_" . $column[0],$order,"index.php",lang($column[1])); - $cols .= ''; - $cols .= "\n"; - - // To be used when displaying the rows - $columns_to_display[$column[0]] = True; - } - } - - if (isset($query) && $query) { - if (isset($phpgw_info["apps"]["timetrack"]["enabled"]) && - $phpgw_info["apps"]["timetrack"]["enabled"]) { - $phpgw->db->query("SELECT a.ab_id,a.ab_owner,a.ab_firstname,a.ab_lastname,a.ab_company_id," - . "a.ab_email,a.ab_wphone,c.company_name,a.ab_hphone,a.ab_fax,a.ab_mphone " - . "from addressbook as a, customers as c where a.ab_company_id = c.company_id " - . "AND $filtermethod AND (a.ab_lastname like '" - . "%$query%' OR a.ab_firstname like '%$query%' OR a.ab_email like '%$query%' OR " - . "a.ab_street like '%$query%' OR a.ab_city like '%$query%' OR a.ab_state " - . "like '%$query%' OR a.ab_zip like '%$query%' OR a.ab_notes like " - . "'%$query%' OR c.company_name like '%$query%') $ordermethod limit $limit",__LINE__,__FILE__); - } else { - $phpgw->db->query("SELECT * from addressbook WHERE $filtermethod AND (ab_lastname like '" - . "%$query%' OR ab_firstname like '%$query%' OR ab_email like '%$query%' OR " - . "ab_street like '%$query%' OR ab_city like '%$query%' OR ab_state " - . "like '%$query%' OR ab_zip like '%$query%' OR ab_notes like " - . "'%$query%' OR ab_company like '%$query%') $ordermethod limit $limit",__LINE__,__FILE__); - } - } else { - if ($phpgw_info["apps"]["timetrack"]["enabled"]){ - $phpgw->db->query("SELECT a.ab_id,a.ab_owner,a.ab_firstname,a.ab_lastname," - . "a.ab_email,a.ab_wphone,c.company_name " - . "from addressbook as a, customers as c where a.ab_company_id = c.company_id " - . "AND $filtermethod $ordermethod limit $limit",__LINE__,__FILE__); - } else { - $phpgw->db->query("SELECT * from addressbook WHERE $filtermethod $ordermethod limit $limit",__LINE__,__FILE__); - } - } // else $query $rows=""; - while ($phpgw->db->next_record()) { + $columns_to_display=$this->columns_to_display; + if($phpgw_info["user"]["preferences"]["common"]["maxmatchs"] ) { + $limit = $phpgw_info["user"]["preferences"]["common"]["maxmatchs"]; + } else { // this must be broken, but it works + $limit = 15; + } + + for ($i=0;$i<$limit;$i++) { // each entry $tr_color = $phpgw->nextmatchs->alternate_row_color($tr_color); $rows .= ''; - - $ab_id = $phpgw->db->f("ab_id"); - - while ($column = each($columns_to_display)) { - if ($column[0] == "company") { - if ($phpgw_info["apps"]["timetrack"]["enabled"]) { - $field = $phpgw->db->f("company_name"); - } else { - $field = $phpgw->db->f("ab_company"); - } - } else { - $field = $phpgw->db->f("ab_" . $column[0]); - } - - $field = htmlentities($field); - - // Some fields require special formating. + while ($column = each($columns_to_display)) { // each entry column + $colname = $this->colname($column[0],$i); + $myid = $entries->ab_id[$i]; + $myowner = $entries->owner[$i]; + // Some fields require special formatting. if ($column[0] == "url") { - if (! ereg("^http://",$field)) { - $data = "http://" . $field; + $rows .= '' + . '' . $colname . ' '; + } else if ($column[0] == "email") { + if ($phpgw_info["user"]["apps"]["email"]) { + $rows .= '' + . '' . $colname . ' '; + } else { + $rows .= '' + . '' . $colname . ' '; } + } else { // But these do not $rows .= '' - . '' . $field. ' '; - } else if ($column[0] == "email") { - if ($phpgw_info["user"]["apps"]["email"]) { - $rows .= '' - . '' . $field . ' '; - } else { - $rows .= '' - . '' . $field. ' '; - } - } else { - $rows .= '' - . $field . ' '; + . $colname . ' '; } - #echo ''; } - reset($columns_to_display); // If we don't reset it, our inside while won't loop + + reset($columns_to_display); // If we don't reset it, our inside while won't loop + $rows .= ' - - '.lang("View").' + + '.lang("View").' - '.lang("vcard").' - '.$phpgw->common->check_owner($phpgw->db->f("ab_owner"),"edit.php",lang("edit"),"ab_id=" . $phpgw->db->f("ab_id")."&start=".$start."&sort=".$sort."&order=".$order).' + '.$phpgw->common->check_owner($myowner,"edit.php",lang("edit"),"ab_id=".$myid."&start=".$start."&sort=".$sort."&order=".$order).' '; } + $t->set_var(searchreturn,$this->searchreturn); + $t->set_var(lang_showing,$this->lang_showing); + $t->set_var(search_filter,$this->search_filter); $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"]); @@ -229,7 +112,7 @@ $t->set_var("actionurl",$phpgw->link("add.php?sort=$sort&order=$order&filter=$filter&start=$start")); $t->set_var("start",$start); $t->set_var("filter",$filter); - $t->set_var("cols",$cols); + $t->set_var("cols",$this->cols); $t->set_var("rows",$rows); $t->parse("out","addressbook_header");