mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-28 09:38:53 +01:00
Add function to filter ldap_fields array
This commit is contained in:
parent
73259969c4
commit
ca2f4389cb
@ -113,6 +113,15 @@
|
|||||||
"email_home_type" => "mailhometype" //'INTERNET','CompuServe',etc...
|
"email_home_type" => "mailhometype" //'INTERNET','CompuServe',etc...
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->non_contact_fields = array(
|
||||||
|
"id" => "uidnumber",
|
||||||
|
"lid" => "uid",
|
||||||
|
"tid" => "phpgwtypeid",
|
||||||
|
"cat_id" => "phpgwcatid",
|
||||||
|
"access" => "phpgwaccess",
|
||||||
|
"owner" => "phpgwowner"
|
||||||
|
);
|
||||||
|
|
||||||
/* Used to flag an address as being:
|
/* Used to flag an address as being:
|
||||||
domestic OR international(default)
|
domestic OR international(default)
|
||||||
parcel(default)
|
parcel(default)
|
||||||
@ -180,7 +189,7 @@
|
|||||||
|
|
||||||
$return_fields[0]["id"] = $ldap_fields[0]["uidnumber"][0];
|
$return_fields[0]["id"] = $ldap_fields[0]["uidnumber"][0];
|
||||||
$return_fields[0]["lid"] = $ldap_fields[0]["uid"][0];
|
$return_fields[0]["lid"] = $ldap_fields[0]["uid"][0];
|
||||||
$return_fields[0]["tid"] = $ldap_fields[0]["phpgwcontacttype"][0];
|
$return_fields[0]["tid"] = $ldap_fields[0]["phpgwtypeid"][0];
|
||||||
$return_fields[0]["owner"] = $ldap_fields[0]["phpgwowner"][0];
|
$return_fields[0]["owner"] = $ldap_fields[0]["phpgwowner"][0];
|
||||||
$return_fields[0]["access"] = $ldap_fields[0]["phpgwaccess"][0];
|
$return_fields[0]["access"] = $ldap_fields[0]["phpgwaccess"][0];
|
||||||
$return_fields[0]["cat_id"] = $ldap_fields[0]["phpgwcatid"][0];
|
$return_fields[0]["cat_id"] = $ldap_fields[0]["phpgwcatid"][0];
|
||||||
@ -241,7 +250,7 @@
|
|||||||
|
|
||||||
$return_fields[0]["id"] = $ldap_fields[0]["uidnumber"][0];
|
$return_fields[0]["id"] = $ldap_fields[0]["uidnumber"][0];
|
||||||
$return_fields[0]["lid"] = $ldap_fields[0]["uid"][0];
|
$return_fields[0]["lid"] = $ldap_fields[0]["uid"][0];
|
||||||
$return_fields[0]["tid"] = $ldap_fields[0]["phpgwcontacttype"][0];
|
$return_fields[0]["tid"] = $ldap_fields[0]["phpgwtypeid"][0];
|
||||||
$return_fields[0]["owner"] = $ldap_fields[0]["phpgwowner"][0];
|
$return_fields[0]["owner"] = $ldap_fields[0]["phpgwowner"][0];
|
||||||
$return_fields[0]["access"] = $ldap_fields[0]["phpgwaccess"][0];
|
$return_fields[0]["access"] = $ldap_fields[0]["phpgwaccess"][0];
|
||||||
$return_fields[0]["cat_id"] = $ldap_fields[0]["phpgwcatid"][0];
|
$return_fields[0]["cat_id"] = $ldap_fields[0]["phpgwcatid"][0];
|
||||||
@ -299,60 +308,22 @@
|
|||||||
for ($i=0;$i<count($filterarray);$i++) {
|
for ($i=0;$i<count($filterarray);$i++) {
|
||||||
list($name,$value) = split("=",$filterarray[$i]);
|
list($name,$value) = split("=",$filterarray[$i]);
|
||||||
if ($name) {
|
if ($name) {
|
||||||
if ($DEBUG) { echo "<br>DEBUG - Filter intermediate strings 1: #".$name."# => #".$value."#"; }
|
if ($DEBUG) { echo "<br>DEBUG - Filter strings: #".$this->non_contact_fields[$name]."# => #".$value."#"; }
|
||||||
$filterfields[$name] = $value;
|
$filterfields[$this->non_contact_fields[$name]] = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
list($name,$value) = split('=',$filter);
|
list($name,$value) = split('=',$filter);
|
||||||
if ($DEBUG) {
|
if ($DEBUG) {
|
||||||
echo "<br>DEBUG - Filter intermediate strings 1: #".$name."# => #".$value."#";
|
echo "<br>DEBUG - Filter strings: #".$this->non_contact_fields[$name]."# => #".$value."#";
|
||||||
}
|
}
|
||||||
$filterfields = array($name => $value);
|
$filterfields = array($this->non_contact_fields[$name] => $value);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
// now check each element of the array and convert into SQL for queries
|
$filterfields = array(
|
||||||
// below
|
'phpgwtypeid' => 'n'
|
||||||
$i=0;
|
);
|
||||||
reset($filterfields);
|
if ($DEBUG) { echo "<br>DEBUG - Filter strings: #phpgwtypeid=n#"; }
|
||||||
while (list($name,$value) = each($filterfields)) {
|
|
||||||
if ($DEBUG) { echo "<br>DEBUG - Filter intermediate strings 2: #".$name."# => #".$value."#"; }
|
|
||||||
$isstd=0;
|
|
||||||
if ($name && empty($value)) {
|
|
||||||
if ($DEBUG) { echo "<br>DEBUG - filter field '".$name."' is empty (NULL)"; }
|
|
||||||
$check_stock = $this->stock_contact_fields + array('id' => 'id', 'tid' => 'tid', 'lid' => 'lid', 'owner' => 'owner');
|
|
||||||
while (list($fname,$fvalue)=each($check_stock)) {
|
|
||||||
if ($fvalue==$name) {
|
|
||||||
$filterlist .= $name.' is NULL,';
|
|
||||||
if ($DEBUG) { echo "<br>DEBUG - filter field '".$name."' is a stock field"; }
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} elseif($name && $value) {
|
|
||||||
reset($stock_fields);
|
|
||||||
while (list($fname,$fvalue)=each($stock_fields)) {
|
|
||||||
if ($fvalue==$name) {
|
|
||||||
$filterlist .= $name.'="'.$value.'",';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$i++;
|
|
||||||
}
|
|
||||||
$filterlist = substr($filterlist,0,-1);
|
|
||||||
$filterlist = ereg_replace(","," AND ",$filterlist);
|
|
||||||
|
|
||||||
if ($DEBUG) {
|
|
||||||
echo "<br>DEBUG - Filter output string: #".$filterlist."#";
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($filterlist) {
|
|
||||||
$filtermethod = '('.$filterlist.') ';
|
|
||||||
$fwhere = ' WHERE '; $fand = ' AND ';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($DEBUG && $filtermethod) {
|
|
||||||
echo "<br>DEBUG - Filtering with: #" . $filtermethod . "#";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$sort) { $sort = "ASC"; }
|
if (!$sort) { $sort = "ASC"; }
|
||||||
@ -381,29 +352,35 @@
|
|||||||
$total = $total + ldap_count_entries($this->ldap, $sri);
|
$total = $total + ldap_count_entries($this->ldap, $sri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($filterfields) {
|
||||||
|
$ldap_fields = $this->filter_ldap($ldap_fields,$filterfields,$DEBUG);
|
||||||
|
}
|
||||||
|
|
||||||
//echo '<br>first total="'.$total.'"';
|
//echo '<br>first total="'.$total.'"';
|
||||||
|
|
||||||
// Now, remove duplicate rows
|
// Now, remove duplicate rows
|
||||||
//$tmp = array_unique($ldap_fields); PHP 4.X only
|
if (!$PHP_VERSION) global $PHP_VERSION;
|
||||||
//$ldap_fields = $tmp;
|
if (floor($PHP_VERSION ) == 4) {
|
||||||
|
$tmp = array_unique($ldap_fields);
|
||||||
$ldap_fields = $this->asortbyindex($ldap_fields,'uidnumber');
|
$ldap_fields = $tmp;
|
||||||
reset($ldap_fields);
|
} else {
|
||||||
if (count($ldap_fields) > 0) {
|
$ldap_fields = $this->asortbyindex($ldap_fields,'uidnumber');
|
||||||
for ($a = 0; $a < count($ldap_fields); $a++) {
|
reset($ldap_fields);
|
||||||
if ($ldap_fields[$a]) {
|
if (count($ldap_fields) > 0) {
|
||||||
//echo '<br>comparing "'.$ldap_fields[$a]['uidnumber'][0]
|
for ($a = 0; $a < count($ldap_fields); $a++) {
|
||||||
// .'" to "'.$ldap_fields[$a - 1]['uidnumber'][0].'"';
|
if ($ldap_fields[$a]) {
|
||||||
if (($ldap_fields[$a]['uidnumber'][0] <> $ldap_fields[$a - 1]['uidnumber'][0])
|
//echo '<br>comparing "'.$ldap_fields[$a]['uidnumber'][0]
|
||||||
) {
|
// .'" to "'.$ldap_fields[$a - 1]['uidnumber'][0].'"';
|
||||||
$uniquearray[$a] = $ldap_fields[$a];
|
if (($ldap_fields[$a]['uidnumber'][0] <> $ldap_fields[$a - 1]['uidnumber'][0])
|
||||||
} else {
|
) {
|
||||||
//echo '<br>deleting "'.$ldap_fields[$a -1 ]['uidnumber'][0];
|
$uniquearray[$a] = $ldap_fields[$a];
|
||||||
|
} else {
|
||||||
|
//echo '<br>deleting "'.$ldap_fields[$a -1 ]['uidnumber'][0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$ldap_fields = $uniquearray;
|
||||||
}
|
}
|
||||||
$ldap_fields = $uniquearray;
|
} // end version check
|
||||||
}
|
|
||||||
|
|
||||||
$this->total_records = count($ldap_fields);
|
$this->total_records = count($ldap_fields);
|
||||||
//echo '<br>total="'.$this->total_records.'"';
|
//echo '<br>total="'.$this->total_records.'"';
|
||||||
@ -411,6 +388,10 @@
|
|||||||
$sri = ldap_search($this->ldap, $phpgw_info["server"]["ldap_contact_context"], "phpgwowner=*");
|
$sri = ldap_search($this->ldap, $phpgw_info["server"]["ldap_contact_context"], "phpgwowner=*");
|
||||||
$ldap_fields = ldap_get_entries($this->ldap, $sri);
|
$ldap_fields = ldap_get_entries($this->ldap, $sri);
|
||||||
$this->total_records = ldap_count_entries($this->ldap, $sri);
|
$this->total_records = ldap_count_entries($this->ldap, $sri);
|
||||||
|
|
||||||
|
if ($filterfields) {
|
||||||
|
$ldap_fields = $this->filter_ldap($ldap_fields,$filterfields,$DEBUG);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use shared sorting routines, based on sort and order
|
// Use shared sorting routines, based on sort and order
|
||||||
@ -445,7 +426,7 @@
|
|||||||
// id of owner/parent for the record
|
// id of owner/parent for the record
|
||||||
$return_fields[$j]["id"] = $ldap_fields[$i]["uidnumber"][0];
|
$return_fields[$j]["id"] = $ldap_fields[$i]["uidnumber"][0];
|
||||||
$return_fields[$j]["lid"] = $ldap_fields[$i]["uid"][0];
|
$return_fields[$j]["lid"] = $ldap_fields[$i]["uid"][0];
|
||||||
$return_fields[$j]["tid"] = $ldap_fields[$i]["phpgwcontacttype"][0];
|
$return_fields[$j]["tid"] = $ldap_fields[$i]["phpgwtypeid"][0];
|
||||||
$return_fields[$j]["owner"] = $ldap_fields[$i]["phpgwowner"][0];
|
$return_fields[$j]["owner"] = $ldap_fields[$i]["phpgwowner"][0];
|
||||||
$return_fields[$j]["access"] = $ldap_fields[$i]["phpgwaccess"][0];
|
$return_fields[$j]["access"] = $ldap_fields[$i]["phpgwaccess"][0];
|
||||||
$return_fields[$j]["cat_id"] = $ldap_fields[$i]["phpgwcatid"][0];
|
$return_fields[$j]["cat_id"] = $ldap_fields[$i]["phpgwcatid"][0];
|
||||||
@ -472,7 +453,7 @@
|
|||||||
return $return_fields;
|
return $return_fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
function add($owner,$fields,$access='',$cat_id='')
|
function add($owner,$fields,$access='',$cat_id='',$tid='n')
|
||||||
{
|
{
|
||||||
global $phpgw,$phpgw_info;
|
global $phpgw,$phpgw_info;
|
||||||
|
|
||||||
@ -507,6 +488,7 @@
|
|||||||
$ldap_fields['uid'] = time().$time["usec"].":".$ldap_fields['givenname'];
|
$ldap_fields['uid'] = time().$time["usec"].":".$ldap_fields['givenname'];
|
||||||
|
|
||||||
$dn = 'uid=' . $ldap_fields['uid'].',' . $phpgw_info["server"]["ldap_contact_context"];
|
$dn = 'uid=' . $ldap_fields['uid'].',' . $phpgw_info["server"]["ldap_contact_context"];
|
||||||
|
$ldap_fields['phpgwtypeid'] = $tid;
|
||||||
$ldap_fields['phpgwowner'] = $owner;
|
$ldap_fields['phpgwowner'] = $owner;
|
||||||
$ldap_fields['phpgwaccess'] = $access;
|
$ldap_fields['phpgwaccess'] = $access;
|
||||||
$ldap_fields["cat_id"] = $cat_id;
|
$ldap_fields["cat_id"] = $cat_id;
|
||||||
@ -553,7 +535,7 @@
|
|||||||
. addslashes($field_name) . "'",__LINE__,__FILE__);
|
. addslashes($field_name) . "'",__LINE__,__FILE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
function update($id,$owner,$fields,$access='',$cat_id='')
|
function update($id,$owner,$fields,$access='',$cat_id='',$tid='n')
|
||||||
{
|
{
|
||||||
global $phpgw_info;
|
global $phpgw_info;
|
||||||
|
|
||||||
@ -583,6 +565,15 @@
|
|||||||
$err = ldap_mod_add($this->ldap,$dn,array('uidnumber' => $stock_fields['uidnumber']));
|
$err = ldap_mod_add($this->ldap,$dn,array('uidnumber' => $stock_fields['uidnumber']));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Verify tid
|
||||||
|
if (empty($ldap_fields[0]['phpgwtypeid'])) {
|
||||||
|
$stock_fields['phpgwtypeid'] = $tid;
|
||||||
|
$err = ldap_modify($this->ldap,$dn,array('phpgwtypeid' => $stock_fields['phpgwtypeid']));
|
||||||
|
} elseif (!$ldap_fields[0]['uid']) {
|
||||||
|
$stock_fields[''] = $tids;
|
||||||
|
$err = ldap_mod_add($this->ldap,$dn,array('phpgwtypeid' => $stock_fields['phpgwtypeid']));
|
||||||
|
}
|
||||||
|
|
||||||
// Verify uid
|
// Verify uid
|
||||||
if (empty($ldap_fields[0]['uid'])) {
|
if (empty($ldap_fields[0]['uid'])) {
|
||||||
$uids = split(',',$dn);
|
$uids = split(',',$dn);
|
||||||
|
@ -166,5 +166,35 @@
|
|||||||
}
|
}
|
||||||
return ($sortarray);
|
return ($sortarray);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function filter_ldap ($ldap_fields,$filterfields,$DEBUG=0) {
|
||||||
|
$match = 0;
|
||||||
|
reset($filterfields);
|
||||||
|
for($i=0;$i<count($ldap_fields);$i++) {
|
||||||
|
while (list($col,$filt) = each($filterfields)) {
|
||||||
|
if($DEBUG) { echo '<br>Testing "'.$col.'" for "'.$filt.'"'."\n"; }
|
||||||
|
if ($ldap_fields[$i][$col][0] == $filt) {
|
||||||
|
if($DEBUG) { echo ', and number '.$ldap_fields[$i]["uidnumber"][0].' matched!'."\n"; }
|
||||||
|
$matched[$col][$i] = True;
|
||||||
|
$match++;
|
||||||
|
} else {
|
||||||
|
$matched[$col][$i] = False;
|
||||||
|
if($DEBUG) { echo ', and number '.$ldap_fields[$i]["uidnumber"][0].' did not match!'."\n"; }
|
||||||
|
$match--;
|
||||||
|
}
|
||||||
|
if ($matched[$col][$i]) { $allmatched[$i] = True; }
|
||||||
|
}
|
||||||
|
reset($filterfields);
|
||||||
|
if ($allmatched[$i]) {
|
||||||
|
if($DEBUG) { echo ', and number '.$ldap_fields[$i]["uidnumber"][0].' matched!'."\n"; }
|
||||||
|
$new_ldap[$i] = $ldap_fields[$i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($match) { if($DEBUG) { echo '<br'.$match.' total matches.'."\n"; } }
|
||||||
|
else { if($DEBUG) { echo '<br>No matches :('."\n"; } }
|
||||||
|
$this->total_records = count($new_ldap);
|
||||||
|
|
||||||
|
return $new_ldap;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
Loading…
Reference in New Issue
Block a user