Page MenuHomeIn-Portal Phabricator

in-portal
No OneTemporary

File Metadata

Created
Thu, Jul 17, 7:14 PM

in-portal

Index: trunk/kernel/include/searchconfig.php
===================================================================
--- trunk/kernel/include/searchconfig.php (revision 3617)
+++ trunk/kernel/include/searchconfig.php (revision 3618)
@@ -1,553 +1,553 @@
<?php
RegisterPrefix("clsSearchConfig","searchfield","kernel/include/searchconfig.php");
class clsSearchConfig extends clsParsedItem
{
function clsSearchConfig($id=NULL)
{
$this->clsParsedItem();
$this->tablename = GetTablePrefix()."SearchConfig";
$this->id_field = "SearchConfigId";
$this->NoResourceId=1;
$this->TagPrefix="searchfield";
if($id)
$this->LoadFromDatabase($id);
}
function LoadFromDatabase($Id)
{
global $Errors;
if(!isset($Id))
{
$Errors->AddError("error.AppError",NULL,'Internal error: LoadFromDatabase id',"",get_class($this),"LoadFromDatabase");
return false;
}
$sql = sprintf("SELECT * FROM ".$this->tablename." WHERE ".$this->IdField()." = '%s'",$Id);
$result = $this->adodbConnection->Execute($sql);
if ($result === false)
{
$Errors->AddError("error.DatabaseError",NULL,$this->adodbConnection->ErrorMsg(),"",get_class($this),"LoadFromDatabase");
return false;
}
$data = $result->fields;
$this->SetFromArray($data);
$this->Clean();
return true;
}
function GetWhereClause($verb,$value)
{
//$value = $this->adodbConnection->qstr(stripslashes($value));
$where = "";
if(strlen($this->Get("ForeignField"))>0)
{
$field = $this->Get("ForeignField");
}
else
{
$field = $this->Get("FieldName");
}
if (is_array($value))
{
foreach ($value as $value_item) {
$where .= '('.$field.' = '.$this->adodbConnection->qstr($value_item).') OR ';
}
return preg_replace('/(.*) OR $/', '\\1', $where);
}
switch($verb)
{
case "is":
if(strlen($this->Get("IsWhere")))
{
$where = str_replace("{Value}",$value,$this->Get("IsWhere"));
}
else
$where = $field." = '".$value."'";
break;
case "isnot":
if(strlen($this->Get("IsNotWhere")))
{
$where = str_replace("{Value}",$value,$this->Get("IsNotWhere"));
}
else
$where = $field." != '".$value."'";
break;
case "contains":
if(strlen($this->Get("ContainsWhere")))
{
$where = str_replace("{Value}",$value,$this->Get("ContainsWhere"));
}
else
$where = $field." LIKE '%".$value."%'";
break;
case "notcontains":
if(strlen($this->Get("NotContainsWhere")))
{
$where = str_replace("{Value}",$value,$this->Get("NotContainsWhere"));
}
else
$where = $field." NOT LIKE '%".$value."%'";
break;
}
return $where;
}
function ParseObject($element)
{
global $objConfig, $objSession, $objUsers, $objCatList, $var_list_update, $var_list,
$bb_var_list_update, $m_var_list_update,$FormValues;
$extra_attribs = ExtraAttributes($element->attributes);
if (strtolower($element->name)==$this->TagPrefix)
{
$field = strtolower($element->attributes["_field"]);
switch($field)
{
case "name":
$ret = $this->Get("FieldName");
break;
case "lang_name":
$ret = language($this->Get("DisplayName"));
break;
case "id":
$ret = $this->Get("SearchConfigId");
break;
case "header":
$hdr = $this->Get("ConfigHeader");
if ($hdr) $ret = language($hdr);
break;
case "table":
$ret = $this->Get("TableName");
break;
case "simple":
$ret = (int)$this->Get("SimpleSearch");
if($ret)
{
if(strlen($element->attributes["_text"]))
$ret = language($element->attributes["_text"]);
if(strlen($element->attributes["_plaintext"]))
$ret = $element->attributes["_plaintext"];
}
break;
case "advanced":
$ret = (int)$this->Get("AdvancedSearch");
if($ret)
{
if(strlen($element->attributes["_text"]))
$ret = language($element->attributes["_text"]);
if(strlen($element->attributes["_plaintext"]))
$ret = $element->attributes["_plaintext"];
}
break;
case "verb_select":
$datatype = $this->Get("FieldType");
switch($datatype)
{
case "text":
case 'textarea':
$fieldname = "verb[".$this->Get("FieldName")."]";
$ret = "<SELECT name=\"$fieldname\">";
$selected="";
if($FormValues[$fieldname]=="any")
$selected = " selected";
$ret .= "<OPTION value=\"any\" $selected>".language("lu_advsearch_any")."</OPTION>";
$selected="";
if($FormValues[$fieldname]=="is")
$selected = " selected";
$ret .= "<OPTION value=\"is\" $selected>".language("lu_advsearch_is")."</OPTION>";
$selected="";
if($FormValues[$fieldname]=="isnot")
$selected = " selected";
$ret .= "<OPTION value=\"isnot\" $selected>".language("lu_advsearch_isnot")."</OPTION>";
$selected="";
if($FormValues[$fieldname]=="contains")
$selected = " selected";
$ret .= "<OPTION value=\"contains\" $selected>".language("lu_advsearch_contains")."</OPTION>";
$selected="";
if($FormValues[$fieldname]=="notcontains")
$selected = " selected";
$ret .= "<OPTION value=\"notcontains\" $selected>".language("lu_advsearch_notcontains")."</OPTION>";
$ret .= "</SELECT>";
break;
case "boolean":
$ret = "";
break;
case 'select':
case 'radio':
case 'checkbox':
// $ret = '<input type="hidden" name="verb['.$this->Get('FieldName').']" value="is" />';
$fieldname = 'verb['.$this->Get('FieldName').']';
$ret = '<select name="'.$fieldname.'">';
$options = Array('any', 'is');
$option_tpl = '<option value="%s"%s>%s</option>';
foreach ($options as $option_value) {
$selected = ($option_value == $FormValues[$fieldname]) ? ' selected' : '';
$ret .= sprintf($option_tpl, $option_value, $selected, language('lu_advsearch_'.$option_value) );
}
$ret .= "</select>";
break;
}
break;
case 'form_input':
$datatype = $this->Get("FieldType");
$name = $this->Get("FieldName");
switch($datatype)
{
case "text":
case 'textarea':
$ret = "<INPUT TYPE=TEXT maxlength=50 name=\"value[$name]\" VALUE=\"".$FormValues[$name]."\">";
break;
case 'select':
$current_value = $FormValues[$name];
$values = $this->parseValuesList();
$ret = '<select name="value['.$name.']">';
$option_tpl = '<option value="%s"%s>%s</option>';
foreach ($values as $value_key => $value_name) {
$selected = ($current_value == $value_key) ? ' selected' : '';
$ret .= sprintf($option_tpl, $value_key, $selected, $value_name);
}
$ret .= '</select>';
break;
case 'radio':
$current_value = $FormValues[$name];
$values = $this->parseValuesList();
$ret = '';
$option_tpl = '<input type="radio" name="value['.$name.']" value="%s"%s>&nbsp;%s ';
foreach ($values as $value_key => $value_name) {
$selected = ($current_value == $value_key) ? ' checked' : '';
$ret .= sprintf($option_tpl, $value_key, $selected, $value_name);
}
break;
case 'checkbox':
$current_value = $FormValues[$name];
$values = $this->parseValuesList();
$ret = '';
$option_tpl = '<input type="checkbox" name="value['.$name.'][]" value="%s"%s>&nbsp;%s ';
foreach ($values as $value_key => $value_name) {
$selected = ($current_value == $value_key) ? ' checked' : '';
$ret .= sprintf($option_tpl, $value_key, $selected, $value_name);
}
break;
/*case 'password':
break;*/
case "boolean":
$ret = '<table cellspacing="0" cellpadding="0"><tr>';
$ret .= '<td><input type="radio" name="value['.$name.']" value="-1" ';
if (!is_numeric($FormValues[$name]) || ($FormValues[$name] != 1 && $FormValues[$name]!= 0)) {
$ret .= ' checked';
}
$ret .= '></td><td>'.language('lu_advsearch_any').'</td>';
$ret .= '<td><input type="radio" name="value['.$name.']" VALUE="1" ';
if ($FormValues[$name] == 1) {
$ret .= ' checked';
}
$ret .= '></td><td>'.language('lu_true').'</td>';
$ret .= '<td><input type="radio" name="value['.$name.']" value="0" ';
if (is_numeric($FormValues[$name]) && $FormValues[$name] == 0) {
$ret .= ' checked';
}
$ret .= '></td><td>'.language('lu_false').'</td></tr>';
$ret .= '</table>';
break;
case 'range':
$ret = '<table border="0"><tr><td>'.
language('lu_from').': </td><td><input type="text" size="10" maxlength="6" name="value['.$name.'_from]" value="'.$FormValues[$name].'"><br>
</td></tr><tr><td>'.
language('lu_to').': </td><td><input type="text" size="10" maxlength="6" name="value['.$name.'_to]" value="'.$FormValues[$name].'">
</td></tr></table>';
break;
}
break;
case "andor_radio":
$name = $this->Get("FieldName");
- $Field = "andor[$name]";
+ $field = "andor[$name]";
$checked = Array(1 => '', 2 => '');
- $checked[ $FormValues[$Field] ] = ' checked';
- if(!$FormValues[$Field]) $checked[1] = ' checked';
+ $checked[ $FormValues[$field] ] = ' checked';
+ if(!$FormValues[$field]) $checked[1] = ' checked';
$ret = '<table cellspacing="0" cellpadding="0"><tr>';
$ret .= '<td><input type="radio" name="'.$field.'" value="1" '.$checked[1].'></td><td>'.language('lu_and').'</td>';
- $ret .= '<td><input type="radio" name="'.$Field.'" value="2" '.$checked[2].'></td><td>'.language('lu_or').'</td></tr>';
+ $ret .= '<td><input type="radio" name="'.$field.'" value="2" '.$checked[2].'></td><td>'.language('lu_or').'</td></tr>';
$ret .= '</table>';
return $ret;
break;
}
}
return $ret;
}
/**
* If custom field contains values list, then parse it into array
*
* @return Array
*/
function parseValuesList()
{
$sql = 'SELECT ValueList
FROM '.GetTablePrefix().'CustomField
WHERE CustomFieldId = '.$this->Get('CustomFieldId');
$list = $this->adodbConnection->GetOne($sql);
if (!$list) return Array();
$ret = Array();
$values = explode(',', $list);
foreach ($values as $mixed_value) {
list($value_key, $value_name) = explode('=', $mixed_value);
$value_key = trim($value_key);
$value_name = trim($value_name);
if (substr($value_name, 0, 1) == '+')
{
$ret[$value_key] = substr($value_name, 1, strlen($value_name));
}
else {
$ret[$value_key] = language($value_name);
}
}
return $ret;
}
}
class clsSearchConfigList
{
var $Module;
var $Items;
var $SourceTable;
var $classname;
var $adodbConnection;
function clsSearchConfigList($module=NULL)
{
$this->SourceTable = GetTablePrefix()."SearchConfig";
$this->classname = "clsSearchConfig";
$this->adodbConnection = &GetADODBConnection();
$this->Items = array();
if($module)
$this->LoadModule($module);
}
function Clear()
{
unset($this->Items);
$this->Items = array();
}
function ResetModule()
{
$this->Clear();
$sql = "UPDATE ".$this->SourceTable." SET SimpleSearch=0, AdvancedSearch=0 WHERE ModuleName='".$this->Module."'";
$this->adodbConnection->Execute($sql);
}
function LoadModule($mod)
{
$this->Clear();
$this->Module = $mod;
$sql = "SELECT * FROM ".$this->SourceTable." WHERE ModuleName ='$mod' ORDER BY DisplayOrder";
return $this->Query_Item($sql);
}
function GetNextDisplayOrder($mod)
{
$ret = 0;
$sql = "SELECT MAX(DisplayOrder) AS do FROM ".$this->SourceTable." WHERE ModuleName = '$mod'";
$rs = $this->adodbConnection->Execute($sql);
if($rs && !$rs->EOF)
$ret = $rs->fields["do"]+1;
return $ret;
}
function AddItemFromArray($data)
{
$class = new $this->classname;
$class->SetFromArray($data);
//foreach($data as $prop => $value)
// $class->Set($prop,$value);
array_push($this->Items,$class);
return $class;
}
function Query_Item($sql, $limit=NULL)
{
global $Errors;
if(isset($limit))
$result = $this->adodbConnection->SelectLimit($sql, $limit);
else
$result = $this->adodbConnection->Execute($sql);
if ($result === false)
{
$Errors->AddError("error.DatabaseError",NULL,$this->adodbConnection->ErrorMsg(),"",get_class($this),"Query_Item");
return false;
}
$this->Clear();
while ($result && !$result->EOF)
{
$data = $result->fields;
$this->AddItemFromArray($data);
$result->MoveNext();
}
return $this->Items;
}
function GetItem($ID)
{
$found=FALSE;
if(is_array($this->Items))
{
foreach($this->Items as $i)
{
if($i->UniqueID()==$ID)
{
$found=TRUE;
break;
}
}
}
if(!$found)
{
$i = NULL;
$i = new $this->classname();
//$i->idfield = $i->IdField(); //set the id field before we change tables
$i->tablename = $this->SourceTable;
$i->LoadFromDatabase($ID);
array_push($this->Items, $i);
}
return $i;
}
function GetItemByName($Table,$Name)
{
$found=FALSE;
if(is_array($this->Items))
{
foreach($this->Items as $i)
{
if($i->Get("TableName")==$Table && $i->Get("FieldName")==$Name)
{
$found=TRUE;
break;
}
}
}
if(!$found)
{
$i = NULL;
$rs = $this->adodbConnection->Execute("SELECT * FROM ".$this->SourceTable." WHERE Tablename='$Table' AND FieldName='$Name'");
if($rs && !$rs->EOF)
{
$i = new $this->classname();
//$i->idfield = $i->IdField(); //set the id field before we change tables
$i->tablename = $this->SourceTable;
$i->SetFromArray($rs->fields);
}
array_push($this->Items, $i);
}
return $i;
}
function EditFieldSettings($FieldId,$SimpleSearch,$AdvancedSearch,$Priority)
{
$f = $this->GetItem($FieldId);
//echo "<PRE>"; print_r($f); echo "</PRE>";
$f->Set("SimpleSearch",(int)$SimpleSearch);
$f->Set("AdvancedSearch",(int)$AdvancedSearch);
$f->Set("Priority",(int)$Priority);
$f->Update();
return $f;
}
function &AddSearchField($Table,$FieldName,$Module,$Simple,$Adv,$Description,$DisplayName,$ConfigHeader,$DisplayOrder=0,$Priority=0,$FieldType="text",$JoinClause=NULL,$IsWhere=NULL,$IsNotWhere=NULL,$ContainsWhere=NULL,$NotContainsWhere=NULL,$CustomId=0, $ForeignField = NULL)
{
$f = new clsSearchConfig();
if($DisplayOrder==0)
$DisplayOrder = $this->GetNextDisplayOrder($Module);
$f->Set(Array("TableName","ModuleName","SimpleSearch","AdvancedSearch","Description","DisplayName","ConfigHeader",
"DisplayOrder","Priority","FieldType","FieldName", "ForeignField"),
Array($Table,$Module,$Simple,$Adv,$Description,$DisplayName,$ConfigHeader,$DisplayOrder,$Priority,$FieldType,$FieldName, $ForeignField));
$f->Set("CustomFieldId",$CustomId);
if(strlen($JoinClause))
$f->Set("JoinClause",$JoinClause);
if(strlen($IsWhere))
$f->Set("IsWhere",$IsWhere);
if(strlen($IsNotWhere))
$f->Set("IsNotWhere",$IsNotWhere);
if(strlen($ContainsWhere))
$f->Set("ContainsWhere",$ContainsWhere);
if(strlen($NotContainsWhere))
$f->Set("NotContainsWhere",$NotContainsWhere);
$f->Create();
return $f;
}
function GetHeadingList()
{
$res = array();
foreach($this->Items as $i)
{
$header = $i->Get("ConfigHeader");
$res[$header]=1;
}
reset($res);
return array_keys($res);
}
function GetHeadingItems($heading)
{
$res = array();
foreach($this->Items as $i)
{
if($i->Get("ConfigHeader")==$heading)
array_push($res,$i);
}
return $res;
}
}
?>
Property changes on: trunk/kernel/include/searchconfig.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.10
\ No newline at end of property
+1.11
\ No newline at end of property

Event Timeline