Sorting works, filtering very strict

This commit is contained in:
Miles Lott 2001-03-22 20:19:40 +00:00
parent 7b91787b6f
commit 4573f18ad7

View File

@ -277,12 +277,6 @@
$DEBUG = 0; $DEBUG = 0;
list($stock_fields,$stock_fieldnames,$extra_fields) = $this->split_stock_and_extras($fields); 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 == ",") {
unset($t_fields);
}
}
// turn filter's a=b,c=d OR a=b into an array // turn filter's a=b,c=d OR a=b into an array
if ($filter) { if ($filter) {
@ -351,63 +345,37 @@
if (!$sort) { $sort = "ASC"; } if (!$sort) { $sort = "ASC"; }
if ($order) { if (!$order) {
$ordermethod = "order by $order $sort "; $order = "n_family";
} else {
$ordermethod = "order by n_family,n_given,email $sort";
} }
if ($DEBUG && $ordermethod) { if ($DEBUG && $order) {
echo "<br>DEBUG - $ordermethod"; echo "<br>DEBUG - ORDER by $order";
} }
// 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 = $this->total_records;
} 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) { if ($query) {
$this->db3->query("SELECT * FROM $this->std_table WHERE (n_family LIKE '" $ldap_fields = array();
. "%$query%' OR n_given LIKE '%$query%' OR email LIKE '%$query%' OR " $total = 0;
. "adr_one_street LIKE '%$query%' OR adr_one_locality LIKE '%$query%' OR adr_one_region LIKE '%$query%' OR " while (list($name,$value) = each($stock_fieldnames) ) {
. "adr_one_postalcode LIKE '%$query%' OR adr_one_countryname LIKE '%$query%' OR " $lquery = $value.'='.$query;
. "adr_two_street LIKE '%$query%' OR adr_two_locality LIKE '%$query%' OR adr_two_region LIKE '%$query%' OR " //echo $lquery; exit;
. "adr_two_postalcode LIKE '%$query%' OR adr_two_countryname LIKE '%$query%' OR " $sri = ldap_search($this->ldap, $phpgw_info["server"]["ldap_contact_context"], $lquery);
. "org_name LIKE '%$query%' OR org_unit LIKE '%$query%') " . $fand . $filtermethod . $ordermethod,__LINE__,__FILE__); $ldap_fields += ldap_get_entries($this->ldap, $sri);
$this->total_records = $this->db3->num_rows(); $total = $total + ldap_count_entries($this->ldap, $sri);
}
$this->db->query("SELECT * FROM $this->std_table WHERE (n_family LIKE '" $this->total_records = $total;
. "%$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__);
} else { } else {
$this->db3->query("SELECT id,lid,tid,owner $t_fields FROM $this->std_table " . $fwhere $sri = ldap_search($this->ldap, $phpgw_info["server"]["ldap_contact_context"], "phpgwowner=*");
. $filtermethod,__LINE__,__FILE__); $ldap_fields = ldap_get_entries($this->ldap, $sri);
$this->total_records = $this->db3->num_rows(); $this->total_records = ldap_count_entries($this->ldap, $sri);
$this->db->query("SELECT id,lid,tid,owner $t_fields FROM $this->std_table " . $fwhere
. $filtermethod . " " . $ordermethod . " " . $limit,__LINE__,__FILE__);
} }
*/
$sri = ldap_search($this->ldap, $phpgw_info["server"]["ldap_contact_context"], "phpgwowner=*"); // Use shared sorting routines, based on sort and order
$ldap_fields = ldap_get_entries($this->ldap, $sri); if ($sort == "ASC") {
$this->total_records = ldap_count_entries($this->ldap, $sri); $ldap_fields = $this->asortbyindex($ldap_fields, $this->stock_contact_fields[$order]);
} else {
$ldap_fields = $this->arsortbyindex($ldap_fields, $this->stock_contact_fields[$order]);
}
// This logic allows you to limit rows, or not. // This logic allows you to limit rows, or not.
// The export feature, for example, does not limit rows. // The export feature, for example, does not limit rows.
@ -438,18 +406,19 @@
$return_fields[$j]["owner"] = $ldap_fields[$i]["phpgwowner"][0]; $return_fields[$j]["owner"] = $ldap_fields[$i]["phpgwowner"][0];
if (gettype($stock_fieldnames) == "array") { if (gettype($stock_fieldnames) == "array") {
reset($stock_fieldnames);
while (list($f_name,$f_value) = each($stock_fieldnames)) { while (list($f_name,$f_value) = each($stock_fieldnames)) {
$return_fields[$j][$f_name] = $ldap_fields[$i][$f_value][0]; $return_fields[$j][$f_name] = $ldap_fields[$i][$f_value][0];
} }
reset($stock_fieldnames); reset($stock_fieldnames);
} }
$this->db2->query("SELECT contact_name,contact_value FROM $this->ext_table WHERE contact_id='" $this->db->query("SELECT contact_name,contact_value FROM $this->ext_table WHERE contact_id='"
. $ldap_fields[$i]["id"] . "'",__LINE__,__FILE__); . $ldap_fields[$i]["id"] . "'",__LINE__,__FILE__);
while ($this->db2->next_record()) { while ($this->db->next_record()) {
// If its not in the list to be returned, don't return it. // If its not in the list to be returned, don't return it.
// This is still quicker then 5(+) separate queries // This is still quicker then 5(+) separate queries
if ($extra_fields[$this->db2->f("contact_name")]) { if ($extra_fields[$this->db->f("contact_name")]) {
$return_fields[$j][$this->db2->f("contact_name")] = $this->db2->f("contact_value"); $return_fields[$j][$this->db->f("contact_name")] = $this->db->f("contact_value");
} }
} }
$j++; $j++;
@ -545,7 +514,8 @@
if (gettype($stock_fieldnames) == "array") { if (gettype($stock_fieldnames) == "array") {
$stock_fields['phpgwowner'] = $owner; $stock_fields['phpgwowner'] = $owner;
// Check each value, add our extra attributes if they are missing, and // Check each value, add our extra attributes if they are missing, and
// otherwise fix the entry while we can // otherwise fix the entry while we can.
//
// Verify uidnumber // Verify uidnumber
if (empty($ldap_fields[0]['uidnumber'])) { if (empty($ldap_fields[0]['uidnumber'])) {
$stock_fields['uidnumber'] = $id; $stock_fields['uidnumber'] = $id;