Fix start/offset/limit

This commit is contained in:
Miles Lott 2001-03-22 02:39:38 +00:00
parent c5e34d10b5
commit 1bafd75341

View File

@ -362,17 +362,17 @@
// 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);
if ($start && $offset) {
//$limit = $this->db->limit($start,$offset);
} elseif ($start && !$offset) {
$limit = "";
} elseif(!$start && !$offset) {
$limit = "";
$limit = $this->total_records;
} else { #(!$start && $offset) {
$start = 0;
$limit = $this->db->limit($start,$offset);
//$limit = $this->db->limit($start,$offset);
}
*/
$this->db3 = $this->db2 = $this->db; // Create new result objects before our queries
/*
if ($query) {
@ -403,39 +403,54 @@
}
*/
$sri = ldap_search($this->ldap, $phpgw_info["server"]["ldap_contact_context"], "phpgwowner=*".$owner);
$sri = ldap_search($this->ldap, $phpgw_info["server"]["ldap_contact_context"], "phpgwowner=*");
$ldap_fields = ldap_get_entries($this->ldap, $sri);
$this->total_records = ldap_count_entries($this->ldap, $sri);
// $end = $offset - $start;
// 92 records minus 0 = 92.
// 92 records minus 15 = 77.
$end = $start + $offset;
echo $end;
reset($ldap_fields);
for ($i=$start;$i<$end;$i++) {
// 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"] = $ldap_fields[$i]["uidnumber"][0];
$return_fields[$i]["lid"] = $ldap_fields[$i]["uid"][0];
$return_fields[$i]["tid"] = $ldap_fields[$i]["phpgwcontacttype"][0];
$return_fields[$i]["owner"] = $ldap_fields[$i]["phpgwowner"][0];
// 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) {
$limit = $start;
} elseif(!$start && !$offset) {
$limit = $this->total_records;
} else { #(!$start && $offset) {
$start = 0;
$limit = $offset;
}
//echo '('.$start.','.$limit.')';
if (gettype($stock_fieldnames) == "array") {
while (list($f_name,$f_value) = each($stock_fieldnames)) {
$return_fields[$i][$f_name] = $ldap_fields[$i][$f_value][0];
reset($ldap_fields);
$j=0;
for ($i=$start;$i<$limit;$i++) {
if ($i<$this->total_records && $ldap_fields[$i]["uid"][0]) {
//echo '<br>j:'.$j;
// unique id, lid for group/account records,
// type id (g/u) for groups/accounts, and
// id of owner/parent for the record
$return_fields[$j]["id"] = $ldap_fields[$i]["uidnumber"][0];
$return_fields[$j]["lid"] = $ldap_fields[$i]["uid"][0];
$return_fields[$j]["tid"] = $ldap_fields[$i]["phpgwcontacttype"][0];
$return_fields[$j]["owner"] = $ldap_fields[$i]["phpgwowner"][0];
if (gettype($stock_fieldnames) == "array") {
while (list($f_name,$f_value) = each($stock_fieldnames)) {
$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='"
. $ldap_fields[$i]["id"] . "'",__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");
$this->db2->query("SELECT contact_name,contact_value FROM $this->ext_table WHERE contact_id='"
. $ldap_fields[$i]["id"] . "'",__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[$j][$this->db2->f("contact_name")] = $this->db2->f("contact_value");
}
}
$j++;
}
}
return $return_fields;