gettype, intval, ereg_replace changes

This commit is contained in:
Miles Lott 2003-12-10 11:36:54 +00:00
parent 86a9b91004
commit ad9658f725
3 changed files with 55 additions and 56 deletions

View File

@ -50,7 +50,7 @@
//echo "<p>contacts::check_perms($rights,$needed,".print_r($addr,True).")"; //echo "<p>contacts::check_perms($rights,$needed,".print_r($addr,True).")";
if ($addr !== False) // addr-record or id given if ($addr !== False) // addr-record or id given
{ {
if (is_array($addr)) if(@is_array($addr))
{ {
if (isset($addr['rights'])) if (isset($addr['rights']))
{ {
@ -62,12 +62,12 @@
} }
else else
{ {
$id = intval(isset($addr['id']) ? $addr['id'] : $addr['ab_id']); $id = (int)(isset($addr['id']) ? $addr['id'] : $addr['ab_id']);
} }
} }
else else
{ {
$id = intval($addr); $id = (int)$addr;
} }
if (isset($id)) if (isset($id))
{ {
@ -76,7 +76,7 @@
//echo "addr($id)=<pre>".print_r($addr[0],True)."</pre>\n"; //echo "addr($id)=<pre>".print_r($addr[0],True)."</pre>\n";
} }
} }
$ret = !!(intval($rights) & $needed); $ret = !!((int)$rights & $needed);
//echo " rights=$rights, id=$id => ".($ret?'True':'False')."</p>\n"; //echo " rights=$rights, id=$id => ".($ret?'True':'False')."</p>\n";
//echo "grants=<pre>".print_r($this->grants,True)."</pre>\n"; //echo "grants=<pre>".print_r($this->grants,True)."</pre>\n";
@ -92,13 +92,13 @@
*/ */
function read_single_entry($id,$fields='') function read_single_entry($id,$fields='')
{ {
if (is_array($fields)) if(@is_array($fields))
{ {
$fields['owner'] = 'owner'; // we need the owner to set the rights $fields['owner'] = 'owner'; // we need the owner to set the rights
} }
if ($entry = contacts_::read_single_entry($id,$fields)) if ($entry = contacts_::read_single_entry($id,$fields))
{ {
$entry[0]['rights'] = intval($this->grants[$entry[0]['owner']]); $entry[0]['rights'] = (int)$this->grants[$entry[0]['owner']];
} }
return $entry; return $entry;
} }
@ -118,7 +118,7 @@
*/ */
function read($start=0,$limit=0,$fields='',$query='',$filter='',$sort='',$order='', $lastmod=-1) function read($start=0,$limit=0,$fields='',$query='',$filter='',$sort='',$order='', $lastmod=-1)
{ {
if (is_array($fields)) if(@is_array($fields))
{ {
$fields['owner'] = 'owner'; // we need the owner to set the rights $fields['owner'] = 'owner'; // we need the owner to set the rights
} }
@ -126,7 +126,7 @@
{ {
foreach($entrys as $nr => $entry) foreach($entrys as $nr => $entry)
{ {
$entrys[$nr]['rights'] = intval($this->grants[$entry['owner']]); $entrys[$nr]['rights'] = (int)$this->grants[$entry['owner']];
} }
} }
return $entrys; return $entrys;
@ -137,7 +137,7 @@
while (list($field,$value) = @each($fields)) while (list($field,$value) = @each($fields))
{ {
/* Depending on how the array was built, this is needed. */ /* Depending on how the array was built, this is needed. */
if (gettype($value) == 'integer') if(@is_int($value))
{ {
$value = $field; $value = $field;
} }
@ -168,7 +168,7 @@
/* This will take an array or integer */ /* This will take an array or integer */
function delete($id) function delete($id)
{ {
if (gettype($id) == 'array') if(@is_array($id))
{ {
while (list($null,$t_id) = each($id)) while (list($null,$t_id) = each($id))
{ {
@ -207,17 +207,17 @@
*/ */
$order = 1; $order = 1;
if ( (strlen($s1) == 0) ) if((strlen($s1) == 0))
{ {
return 0; return 0;
} }
if ( (strlen($s2) == 0) ) if((strlen($s2) == 0))
{ {
return 1; return 1;
} }
if (strlen ($s1) > strlen ($s2)) if(strlen ($s1) > strlen ($s2))
{ {
$temp = $s1; $temp = $s1;
$s1 = $s2; $s1 = $s2;
@ -331,7 +331,7 @@
if($DEBUG) { echo ', but number '.$ldap_fields[$i]['uidnumber'][0].' did not match.'.'&nbsp;&nbsp;'; } if($DEBUG) { echo ', but number '.$ldap_fields[$i]['uidnumber'][0].' did not match.'.'&nbsp;&nbsp;'; }
$yes &= False; $yes &= False;
$match--; $match--;
} }
} }
} }
else else
@ -384,23 +384,22 @@
$t = CreateObject('phpgwapi.Template',$GLOBALS['phpgw']->common->get_tpl_dir('addressbook')); $t = CreateObject('phpgwapi.Template',$GLOBALS['phpgw']->common->get_tpl_dir('addressbook'));
$s = CreateObject('phpgwapi.sbox'); $s = CreateObject('phpgwapi.sbox');
$fields = array $fields = array(
( 'n_given' => 'n_given',
'n_given' => 'n_given', 'n_family' => 'n_family',
'n_family' => 'n_family', 'title' => 'title',
'title' => 'title', 'org_name' => 'org_name',
'org_name' => 'org_name', 'org_unit' => 'org_unit',
'org_unit' => 'org_unit', 'adr_one_street' => 'adr_one_street',
'adr_one_street' => 'adr_one_street', 'adr_one_locality' => 'adr_one_locality',
'adr_one_locality' => 'adr_one_locality', 'adr_one_postalcode' => 'adr_one_postalcode',
'adr_one_postalcode' => 'adr_one_postalcode', 'adr_one_region' => 'adr_one_region',
'adr_one_region' => 'adr_one_region', 'adr_one_countryname' => 'adr_one_countryname',
'adr_one_countryname' => 'adr_one_countryname', 'adr_two_street' => 'adr_two_street',
'adr_two_street' => 'adr_two_street', 'adr_two_locality' => 'adr_two_locality',
'adr_two_locality' => 'adr_two_locality', 'adr_two_postalcode' => 'adr_two_postalcode',
'adr_two_postalcode' => 'adr_two_postalcode', 'adr_two_region' => 'adr_two_region',
'adr_two_region' => 'adr_two_region', 'adr_two_countryname' => 'adr_two_countryname'
'adr_two_countryname' => 'adr_two_countryname'
); );
list($address) = $this->read_single_entry($id,$fields); list($address) = $this->read_single_entry($id,$fields);

View File

@ -192,7 +192,7 @@
$return_fields[0]['owner'] = $ldap_fields[0]['phpgwcontactowner'][0]; $return_fields[0]['owner'] = $ldap_fields[0]['phpgwcontactowner'][0];
$return_fields[0]['access'] = $ldap_fields[0]['phpgwcontactaccess'][0]; $return_fields[0]['access'] = $ldap_fields[0]['phpgwcontactaccess'][0];
$return_fields[0]['cat_id'] = $ldap_fields[0]['phpgwcontactcatid'][0]; $return_fields[0]['cat_id'] = $ldap_fields[0]['phpgwcontactcatid'][0];
if (gettype($stock_fieldnames) == 'array') if(@is_array($stock_fieldnames))
{ {
while(list($name,$value)=each($stock_fieldnames)) while(list($name,$value)=each($stock_fieldnames))
{ {
@ -259,7 +259,7 @@
$return_fields[0]['access'] = $ldap_fields[0]['phpgwcontactaccess'][0]; $return_fields[0]['access'] = $ldap_fields[0]['phpgwcontactaccess'][0];
$return_fields[0]['cat_id'] = $ldap_fields[0]['phpgwcontactcatid'][0]; $return_fields[0]['cat_id'] = $ldap_fields[0]['phpgwcontactcatid'][0];
if (gettype($stock_fieldnames) == 'array') if(@is_array($stock_fieldnames))
{ {
while(list($name,$value)=each($stock_fieldnames)) while(list($name,$value)=each($stock_fieldnames))
{ {
@ -350,13 +350,13 @@
need some way of using the lastmod arg in the filter like this: need some way of using the lastmod arg in the filter like this:
if($lastmod >= 0) if($lastmod >= 0)
{ {
$filterfields += array('last_mod' => (int) $lastmod); $filterfields += array('last_mod' => (int)$lastmod;
} }
or maybe not like this - i am not sure what i am doing :) or maybe not like this - i am not sure what i am doing :)
*/ */
if (is_array($this->grants)) if(@is_array($this->grants))
{ {
/* this was not listing private entries when show all was selected */ /* this was not listing private entries when show all was selected */
/* $filterfields += array('phpgwcontactaccess' => 'public'); */ /* $filterfields += array('phpgwcontactaccess' => 'public'); */
@ -474,7 +474,7 @@
$return_fields[$j]['access'] = $ldap_fields[$i]['phpgwcontactaccess'][0]; $return_fields[$j]['access'] = $ldap_fields[$i]['phpgwcontactaccess'][0];
$return_fields[$j]['cat_id'] = $ldap_fields[$i]['phpgwcontactcatid'][0]; $return_fields[$j]['cat_id'] = $ldap_fields[$i]['phpgwcontactcatid'][0];
if (gettype($stock_fieldnames) == 'array') if(@is_array($stock_fieldnames))
{ {
reset($stock_fieldnames); reset($stock_fieldnames);
while (list($f_name,$f_value) = each($stock_fieldnames)) while (list($f_name,$f_value) = each($stock_fieldnames))
@ -484,7 +484,7 @@
reset($stock_fieldnames); reset($stock_fieldnames);
} }
$this->db->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='"
. intval($ldap_fields[$i]['uidnumber']) . "'",__LINE__,__FILE__); . (int)$ldap_fields[$i]['uidnumber'] . "'",__LINE__,__FILE__);
while ($this->db->next_record()) while ($this->db->next_record())
{ {
if ($extra_fields[$this->db->f('contact_name')]) if ($extra_fields[$this->db->f('contact_name')])
@ -501,12 +501,12 @@
/* Used by read() above to build the ldap filter string */ /* Used by read() above to build the ldap filter string */
function makefilter($qarray,$extra='',$query='', $DEBUG=False) function makefilter($qarray,$extra='',$query='', $DEBUG=False)
{ {
if(!is_array($qarray)) if(!@is_array($qarray))
{ {
return $qarray; return $qarray;
} }
if(is_array($extra)) if(@is_array($extra))
{ {
if($DEBUG) { echo '<br>Searching...'; } if($DEBUG) { echo '<br>Searching...'; }
reset($extra); reset($extra);
@ -529,7 +529,7 @@
while(list($name,$value) = @each($qarray)) while(list($name,$value) = @each($qarray))
{ {
if(is_array($value)) if(@is_array($value))
{ {
while(list($x,$y) = each($value)) while(list($x,$y) = each($value))
{ {
@ -538,7 +538,7 @@
$oquery .= '(' . $x . '=*)'; $oquery .= '(' . $x . '=*)';
$hasor = True; $hasor = True;
} }
elseif(is_array($y)) elseif(@is_array($y))
{ {
/* This was most likely created from acl grants in read() above */ /* This was most likely created from acl grants in read() above */
while(list($a,$b) = each($y)) while(list($a,$b) = each($y))
@ -644,7 +644,7 @@
} }
$ldap_fields = ''; $ldap_fields = '';
if (gettype($stock_fieldnames) == 'array') if(@is_array($stock_fieldnames))
{ {
while(list($name,$value)=each($stock_fieldnames)) while(list($name,$value)=each($stock_fieldnames))
{ {
@ -722,7 +722,7 @@
{ {
$dn = $ldap_fields[0]['dn']; $dn = $ldap_fields[0]['dn'];
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 (gettype($stock_fieldnames) == 'array') if(@is_array($stock_fieldnames))
{ {
/* /*
Check each value, add our extra attributes if they are missing, and Check each value, add our extra attributes if they are missing, and

View File

@ -177,7 +177,7 @@
} }
} }
$this->db->query("SELECT id,lid,tid,owner,access,cat_id $t_fields FROM $this->std_table WHERE id='". intval($id) . "'"); $this->db->query("SELECT id,lid,tid,owner,access,cat_id $t_fields FROM $this->std_table WHERE id='". (int)$id . "'");
$this->db->next_record(); $this->db->next_record();
$return_fields[0]['id'] = $this->db->f('id'); $return_fields[0]['id'] = $this->db->f('id');
@ -187,7 +187,7 @@
$return_fields[0]['access'] = $this->db->f('access'); $return_fields[0]['access'] = $this->db->f('access');
$return_fields[0]['cat_id'] = $this->db->f('cat_id'); $return_fields[0]['cat_id'] = $this->db->f('cat_id');
if (gettype($stock_fieldnames) == 'array') if(@is_array($stock_fieldnames))
{ {
while (list($f_name) = each($stock_fieldnames)) while (list($f_name) = each($stock_fieldnames))
{ {
@ -215,7 +215,7 @@
} }
} }
$this->db->query("SELECT contact_name,contact_value FROM $this->ext_table where contact_id='" . intval($this->db->f('id')) . "'",__LINE__,__FILE__); $this->db->query("SELECT contact_name,contact_value FROM $this->ext_table where contact_id='" . (int)$this->db->f('id') . "'",__LINE__,__FILE__);
while ($this->db->next_record()) while ($this->db->next_record())
{ {
if ($extra_fields[$this->db->f('contact_name')]) if ($extra_fields[$this->db->f('contact_name')])
@ -246,7 +246,7 @@
$id = $this->db->f(0); $id = $this->db->f(0);
$this->db->query("SELECT id,lid,tid,owner,access,cat_id $t_fields FROM $this->std_table WHERE id='" . intval($id) . "'",__LINE__,__FILE__); $this->db->query("SELECT id,lid,tid,owner,access,cat_id $t_fields FROM $this->std_table WHERE id='" . (int)$id . "'",__LINE__,__FILE__);
$this->db->next_record(); $this->db->next_record();
$return_fields[0]['id'] = $this->db->f('id'); $return_fields[0]['id'] = $this->db->f('id');
@ -256,7 +256,7 @@
$return_fields[0]['access'] = $this->db->f('access'); $return_fields[0]['access'] = $this->db->f('access');
$return_fields[0]['cat_id'] = $this->db->f('cat_id'); $return_fields[0]['cat_id'] = $this->db->f('cat_id');
if (gettype($stock_fieldnames) == 'array') if (@is_array($stock_fieldnames))
{ {
while (list($f_name) = each($stock_fieldnames)) while (list($f_name) = each($stock_fieldnames))
{ {
@ -376,7 +376,7 @@
{ {
$filterlist .= "(" . $name . " LIKE '%," . $value . ",%' OR " . $name."='".$value."');"; $filterlist .= "(" . $name . " LIKE '%," . $value . ",%' OR " . $name."='".$value."');";
} }
elseif (gettype($value) == "integer") elseif(@is_int($value))
{ {
$filterlist .= $name."=".$value.";"; $filterlist .= $name."=".$value.";";
} }
@ -395,7 +395,7 @@
$i++; $i++;
} }
$filterlist = substr($filterlist,0,-1); $filterlist = substr($filterlist,0,-1);
$filterlist = ereg_replace(';',' AND ',$filterlist); $filterlist = str_replace(';',' AND ',$filterlist);
if ($DEBUG) if ($DEBUG)
{ {
@ -436,7 +436,7 @@
} }
} }
if (is_array($this->grants)) if(@is_array($this->grants))
{ {
$grants = $this->grants; $grants = $this->grants;
while (list($user) = each($grants)) while (list($user) = each($grants))
@ -491,8 +491,8 @@
if($query) if($query)
{ {
$query = ereg_replace("'",'',$query); $query = str_replace("'",'',$query);
$query = ereg_replace('"','',$query); $query = str_replace('"','',$query);
$sql = "SELECT * FROM $this->std_table WHERE ("; $sql = "SELECT * FROM $this->std_table WHERE (";
$sqlcount = "SELECT COUNT(id) FROM $this->std_table WHERE ("; $sqlcount = "SELECT COUNT(id) FROM $this->std_table WHERE (";
@ -583,7 +583,7 @@
function add($owner,$fields,$access=NULL,$cat_id=NULL,$tid=NULL) function add($owner,$fields,$access=NULL,$cat_id=NULL,$tid=NULL)
{ {
$owner = intval($owner); $owner = (int)$owner;
// access, cat_id and tid can be in $fields now or as extra params // access, cat_id and tid can be in $fields now or as extra params
foreach(array('access','cat_id','tid') as $extra) foreach(array('access','cat_id','tid') as $extra)
{ {
@ -646,8 +646,8 @@
function update($id,$owner,$fields,$access=NULL,$cat_id=NULL,$tid=NULL) function update($id,$owner,$fields,$access=NULL,$cat_id=NULL,$tid=NULL)
{ {
$owner = intval($owner); $owner = (int)$owner;
$id = intval($id); $id = (int)$id;
/* First make sure that id number exists */ /* 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(); $this->db->next_record();