Index: trunk/kernel/include/advsearch.php =================================================================== diff -u -r979 -r1108 --- trunk/kernel/include/advsearch.php (.../advsearch.php) (revision 979) +++ trunk/kernel/include/advsearch.php (.../advsearch.php) (revision 1108) @@ -43,7 +43,10 @@ $objSearchConfig->Query_Item("SELECT * FROM ".$objSearchConfig->SourceTable." WHERE TableName='$SearchSource' AND AdvancedSearch=1 ORDER BY DisplayOrder"); } else { - $sql = "SELECT sc.* FROM ".$objSearchConfig->SourceTable." AS sc LEFT JOIN ".GetTablePrefix()."CustomField AS cf ON sc.CustomFieldId = cf.CustomFieldId WHERE TableName='$table' OR (TableName='CustomField' AND cf.Type = $ItemType) AND AdvancedSearch=1 ORDER BY sc.DisplayOrder"; + $tables = Array(1 => 'Category', 2 => 'News', + 3 => 'Topic', 4 => 'Link'); + $table = $tables[$ItemType]; + $sql = "SELECT sc.* FROM ".$objSearchConfig->SourceTable." AS sc LEFT JOIN ".GetTablePrefix()."CustomField AS cf ON sc.CustomFieldId = cf.CustomFieldId WHERE TableName='$table' OR (TableName='".GetTablePrefix()."CustomField' AND cf.Type = $ItemType) AND AdvancedSearch=1 ORDER BY sc.DisplayOrder"; $objSearchConfig->Query_Item($sql); } } @@ -92,10 +95,18 @@ if(!is_object($objSearchConfig)) $objSearchConfig = new clsSeachConfigList(); - $f = GetTablePrefix().$TableName.".".$FieldName; - $FieldConfig = $objSearchConfig->GetItemByName($TableName,$FieldName); - if(is_object($FieldConfig)) - { + if ($TableName==GetTablePrefix().'CustomField') + { + $prefix = ''; + } + else + { + $prefix = GetTablePrefix(); + } + $f = $prefix.$TableName.".".$FieldName; + $FieldConfig = $objSearchConfig->GetItemByName($TableName,$FieldName); + if(is_object($FieldConfig)) + { if(strlen($FieldConfig->Get("ForeignField"))>0) { $parts = explode(".",$FieldConfig->Get("ForeignField")); @@ -105,10 +116,10 @@ $join = $FieldConfig->Get("JoinClause"); $join = str_replace("{ForeignTable}",$Table,$join); $join = str_replace("{LocalTable}",AddTablePrefix($TableName),$join); - $join = str_replace("{Table}", $this->SourceTable, $join); + $join = str_replace("{Table}", AddTablePrefix($this->SourceTable), $join); $this->AddRelationship($Table,$join); - $FieldItem["where"] = $FieldConfig->GetWhereClause($Verb,$Value); + $FieldItem["where"] = GetTablePrefix().$FieldConfig->GetWhereClause($Verb,$Value); $FieldItem["Field"] = $FieldConfig->Get("ForeignField"); $FieldItem["Table"] = ""; $FieldItem["conjuction"] = $conj; @@ -129,6 +140,53 @@ } } + +/* function AddAdvancedCustomFields() + { + $sql = "SELECT * FROM ".GetTablePrefix()."SearchConfig WHERE TableName='".$this->SourceTable."' AND AdvancedSearch=1 AND CustomFieldId>0"; + //echo $sql; + foreach($this->Relationships as $Table=>$clause) + { + if(strlen($Table)>0 && $Table != "Category") + $sql .= " OR TableName='".$Table."'"; + } + $ctable = GetTablePrefix()."CustomMetaData"; + $rs = $this->adodbConnection->Execute($sql); + $CustomJoined = FALSE; + while($rs && !$rs->EOF) + { + $x = $rs->fields["CustomFieldId"]; + $t = $ctable." as c".$x; + $join = "(c$x.ResourceId=".GetTablePrefix().$this->SourceTable.".ResourceId AND c$x.CustomFieldId=".$rs->fields["CustomFieldId"].")"; + $this->AddRelationship($t,$join); + $f = "c".$x.".Value "; + $this->FieldList[] = $f; + $this->FieldWeight[$f] = $rs->fields["Priority"]; + $rs->MoveNext(); + } + } + + function AddAdvancedFields() + { + $sql = "SELECT * FROM ".GetTablePrefix()."SearchConfig WHERE TableName='".$this->SourceTable."' AND AdvancedSearch=1 AND CustomFieldId=0"; + //echo $sql; + foreach($this->Relationships as $Table=>$clause) + { + if(strlen($Table)>0 && $Table != "Category") + $sql .= " OR TableName='".$Table."'"; + } + $rs = $this->adodbConnection->Execute($sql); + + while($rs && !$rs->EOF) + { + $f = GetTablePrefix().$rs->fields["TableName"].".".$rs->fields["FieldName"]; + $this->FieldList[] = $f; + $this->FieldWeight[$f] = $rs->fields["Priority"]; + $rs->MoveNext(); + } + $this->AddAdvancedCustomFields(); + }*/ + /* ready to write the code to build the query and go */ function BuildWhereClause() @@ -141,7 +199,7 @@ $where = substr($where, 0, strlen($where) - $cut_length); return $where; } - + function PerformSearch($ItemType,$OrderBy=NULL,$InitTable=FALSE, $idlist=NULL) { static $SelectSQL, $OldItemType;