Index: trunk/kernel/include/parseditem.php =================================================================== diff -u -r1566 -r2082 --- trunk/kernel/include/parseditem.php (.../parseditem.php) (revision 1566) +++ trunk/kernel/include/parseditem.php (.../parseditem.php) (revision 2082) @@ -943,36 +943,52 @@ return $this->Items[$index]; } - function &GetItemByField($Field,$Value,$LoadFromDB=TRUE) + function &GetItemByField($Field, $Value, $LoadFromDB = true) { - $found=FALSE; - if(is_array($this->Items)) - { - foreach($this->Items as $i) - { - if($i->Get($Field)==$Value) - { - $found = TRUE; - break; - } - } - } - if(!$found && $LoadFromDB==TRUE) - { - $sql = 'SELECT * FROM '.$this->SourceTable.' WHERE '.$Field.' = "'.addslashes($Value).'"'; -// $sql = 'SELECT * FROM '.$this->SourceTable.' WHERE '.$Field.' = "'.($Value).'"'; - $res = $this->adodbConnection->Execute($sql); + if( !is_array($Field) ) $Field = Array($Field); + if( !is_array($Value) ) $Value = Array($Value); - if($res && !$res->EOF) - { - $i = $this->AddItemFromArray($res->fields); - $i->tablename = $this->SourceTable; - $i->Clean(); - } - else - $i = FALSE; - } - return $i; + $found = false; + if( is_array($this->Items) ) + { + foreach($this->Items as $i) + { + $sub_found = true; + foreach($Field as $key_index => $field_name) + { + $sub_found = $sub_found && ( $i->Get($field_name) == $Value[$key_index] ); + } + + if($sub_found) + { + $found = true; + break; + } + } + } + + if( !$found && $LoadFromDB == true ) + { + $sql = 'SELECT * FROM '.$this->SourceTable.' WHERE '; + foreach($Field as $key_index => $field_name) + { + $sql .= '(`'.$field_name.'` = '.$this->adodbConnection->qstr($Value[$key_index]).') AND '; + } + $sql = preg_replace('/(.*) AND $/', '\\1', $sql); + $res = $this->adodbConnection->Execute($sql); + + if($res && !$res->EOF) + { + $i = $this->AddItemFromArray($res->fields); + $i->tablename = $this->SourceTable; + $i->Clean(); + } + else + { + $i = false; + } + } + return $i; } function GetPage($Page, $ItemsPerPage)