101 $this->tblFields=array();
102 $this->tblFieldsOrder=array();
103 $this->LayoutObject=null;
104 $this->SubmitObject=null;
106 $this->LayoutClass=
'CYAP_clsSearchLayout';
107 $this->SubmitClass=
'CYAP_ViewSubmitButton';
108 $this->Lang=$language;
122 $index=count($this->tblFieldsOrder);
123 foreach($info as $FieldOrder => $FieldCfg)
125 if(is_array($FieldCfg))
128 $FieldClass=(array_key_exists(
"fieldclass",$FieldCfg))?$FieldCfg[
'fieldclass']:
'CYap_clsSearchTxt';
129 if(array_key_exists($FieldOrder,$this->tblFields))
132 die(
"Duplicated fieldname: " . $FieldOrder.
".Check the search parameters");
136 eval(
'$this->tblFields[$FieldOrder]=new '.$FieldClass.
'($FieldCfg,$FieldOrder);');
137 $this->tblFieldsOrder[$index]=&$this->tblFields[$FieldOrder];
138 $this->tblFields[$FieldOrder]->SetProperty(
'FieldOrder',$index);
145 $this->LayoutClass=$this->
GetParameter(
'layoutclass',$info,
'CYAP_clsSearchLayout');
146 $this->SubmitClass=$this->
GetParameter(
'submitclass',$info,
'CYAP_ViewSubmitButton');
162 return((array_key_exists($paramName,$cfg))?
175 if(array_key_exists($FieldName,$this->tblFields))
176 return($this->tblFields[$FieldName]);
191 $index=count($this->tblFieldsOrder);
192 if(array_key_exists($FieldName,$this->tblFields))
195 die(
"Duplicated fieldname: " . $FieldName.
".Check the search parameters");
199 $this->tblFields[$FieldName]=&$Field;
200 $this->tblFieldsOrder[$index]=&$Field;
201 $this->tblFields[$FieldName]->SetProperty(
'FieldOrder',$index);
213 if(array_key_exists($FieldName,$this->tblFields))
216 $index=$this->tblFields[$FieldName]->GetProperty(
'FieldOrder');
217 unset($this->tblFieldsOrder[$index]);
218 unset($this->tblFields[$FieldName]);
231 $this->LayoutObject=&$layout;
240 $this->LayoutClass=$ClassName;
251 $this->SubmitObject=&$Submit;
259 $this->SubmitClass=$ClassName;
273 return(count($this->tblFieldsOrder)<2);
285 foreach($this->tblFields as $FieldName => $Field)
287 $this->tblFields[$FieldName]->ReadFormData();
299 foreach($this->tblFields as $FieldName => $Field)
301 $this->tblFields[$FieldName]->StoreInformation($prefix);
314 foreach($this->tblFields as $FieldName => $Field)
316 $this->tblFields[$FieldName]->LoadInformation($prefix);
328 foreach($this->tblFields as $FieldName => $Field)
330 $this->tblFields[$FieldName]->CleanSessionInfo($prefix);
344 foreach($this->tblFields as $FieldName => $Field)
346 $risp=$this->tblFields[$FieldName]->GetWhereCondition($db_class);
348 $where.=
' and '.$risp;
363 $nRows=($this->
NoSearchBox())?1000:$this->tblFields[
'PagSize']->GetValue();
378 $this->tblFields[
'PagSize']->SetLabel($this->Lang[
'PageLen']);
379 $this->tblFields[
'PagSize']->SetDefaultValue(15);
380 $this->tblFieldsOrder[199]=&$this->tblFields[
'PagSize'];
393 <script type="text/javascript">
394 function CheckSearchBox(TheForm)
397 foreach($this->tblFields as $FieldName => $Field)
399 $JsCode.=$this->tblFields[$FieldName]->JsSearchFieldValidate();
421 $txt=
"<h3>".$this->Lang[
'NewSearch'].
"</h3>
422 <form action=".$_SERVER[
"PHP_SELF"] .
" method=post onsubmit='return CheckSearchBox(this)' name='yapfilter'>\n
423 <input type=hidden name=daquery value=1>\n
424 <input type=hidden name=ev value=YAP_SEARCH>\n";
429 if (is_null($this->LayoutObject))
430 eval(
'$LayoutObj=new ' . $this->LayoutClass .
'();');
433 $txt.=$LayoutObj->Start();
434 ksort($this->tblFieldsOrder);
435 $txt.=$LayoutObj->Draw($this->tblFieldsOrder);
436 if (is_null($this->SubmitObject))
437 eval(
'$subObj=new ' . $this->SubmitClass .
'();');
440 $subObj->SetControlLabel($this->Lang[
'Search']);
441 $txt.=$LayoutObj->DrawElement($subObj);
442 $txt.=$LayoutObj->End();
444 $txt.=$LayoutObj->GetJsCode();
471 return(
'<table border=0 align=center>');
494 foreach($tblFields as $FieldName => $Field)
496 if(is_subclass_of($tblFields[$FieldName],
'CYap_clsSearchField'))
497 $drawObject=$tblFields[$FieldName]->GetDrawObject();
499 $drawObject=$tblFields[$FieldName];
500 if(!is_subclass_of($drawObject,
'CYAP_Control'))
501 die(
'Error: the control object given does not extend the class CYAP_Control');
502 $Html.=$this->
_DoDraw($drawObject);
503 $this->JsCode.=$drawObject->GetJsCode();
517 if(is_subclass_of($element,
'CYap_clsSearchField'))
518 $drawObject=$element->GetDrawObject();
520 $drawObject=$element;
521 if(!is_subclass_of($drawObject,
'CYAP_Control'))
522 die(
'Error: the control object given does not extend the class CYAP_Control');
523 $Html=$this->
_DoDraw($drawObject);
537 $Html.=$DrawObject->DrawLabel(
false).
"\n";
538 $Html.=
"</td><td>\n";
539 $Html.=$DrawObject->Draw(
false).
"\n";
540 $Html.=
"</td></tr>\n";
546 return($this->JsCode);
566 parent::CYAP_clsSearchLayout();
574 if(is_subclass_of($DrawObject,
'CYAP_ViewSubmitButton'))
577 if($this->ElementNo>1)
578 $Html.=
"</td></tr>\n";
579 $Html.=
"<tr><td colspan=4>\n";
580 $Html.=$DrawObject->Draw(
false).
"\n";
581 $Html.=
"</td></tr>\n";
586 if($this->ElementNo%2)
589 $Html.=
"</td><td>\n";
590 $Html.=$DrawObject->DrawLabel(
false).
"\n";
591 $Html.=
"</td><td>\n";
592 $Html.=$DrawObject->Draw(
false).
"\n";
593 if(!$this->ElementNo%2)
594 $Html.=
"</td></tr>\n";
668 $this->MyName=$FieldName;
669 $this->DefaultValue=
'';
686 return((array_key_exists($paramName,$cfg))?
699 $this->PaddingChar=
' ';
700 $this->Padding=
'none';
703 $this->ViewClass=
'CYAP_ViewTextBox';
715 if(array_key_exists(
"type",$cfg))
716 $this->Type=$cfg[
"type"];
717 if(array_key_exists(
"fieldname",$cfg))
718 $this->DbField=$cfg[
"fieldname"];
719 if(array_key_exists(
"paddingchar",$cfg))
720 $this->PaddingChar=$cfg[
"paddingchar"];
721 if(array_key_exists(
"padding",$cfg))
722 $this->Padding=$cfg[
"padding"];
723 if(array_key_exists(
"useregex",$cfg))
724 $this->UseRegex=$cfg[
"useregex"];
725 if(array_key_exists(
"size",$cfg))
726 $this->Size=$cfg[
"size"];
727 if(array_key_exists(
"viewclass",$cfg))
728 $this->ViewClass=$cfg[
"viewclass"];
729 if(array_key_exists(
"description",$cfg))
730 $this->Label=$cfg[
"description"];
742 $this->DefaultValue=$value;
758 eval(
'$this->'.$Property.
'=$value;');
770 eval(
'return($this->'.$Property.
');');
792 if($this->RequestValue!=
'' && !is_null($this->RequestValue))
793 return($this->RequestValue);
795 return($this->DefaultValue);
819 if(array_key_exists($prefix.
"F".$this->MyName,$_SESSION))
822 if(is_null($this->RequestValue))
831 if(isset($_SESSION[$prefix.
"F".$this->MyName]))
832 unset($_SESSION[$prefix.
"F".$this->MyName]);
840 if(isset($_REQUEST[
"F".$this->MyName])&&$_REQUEST[
"F".$this->MyName]!=
'')
842 $this->RequestValue=$_REQUEST[
"F".$this->MyName];
843 if(is_null($this->RequestValue))
877 if(is_null($this->ViewObj))
879 $this->ViewObj=
new $this->ViewClass();
880 $this->ViewObj->SetControlLabel($this->Label);
881 $this->ViewObj->SetControlName(
'F'.$this->MyName);
882 $this->ViewObj->SetValue($this->
GetValue());
884 return($this->ViewObj);
898 parent::CYap_clsSearchField($cfg,$FieldName);
911 if($this->RequestValue==
'')
917 if ($this->Type==
"A")
920 if($this->UseRegex==
"1")
922 $RetValue=$db_class->DbRegexCond($this->DbField,$db_class->DBEscape($this->RequestValue)).
' ';
926 $LookFor=$this->
var_padding($this->Size,$this->Padding,$this->PaddingChar,$this->RequestValue);
927 $RetValue=$this->DbField.
'=\''.$db_class->DBEscape($LookFor).
'\' ';
933 $LookFor=$this->RequestValue;
934 $RetValue=$this->DbField.'=
'.$db_class->DBEscape($LookFor).' ';
949 function var_padding($size,$padding,$paddingchar,$text)
951 if($padding=='none
') { return($text); }
954 case 'left
': $cmd=STR_PAD_LEFT;
956 case 'right
': $cmd=STR_PAD_RIGHT;
958 case 'center
': $cmd=STR_PAD_BOTH;
961 trigger_error('ERROR: invalid padding value
'.$padding,E_USER_ERROR);
964 $dimTesto=strlen($text);
965 // se la dimensione è sufficiente restituisco la stringa
966 if ($dimTesto<$size) { return(str_pad($text, $size, $paddingchar, $cmd)); }
967 else {return($text); }
974 function &GetDrawObject()
976 $ViewObj=$this->_MakeViewObj();
977 $ViewObj->SetProperty('Size
',$this->Size);
984 class CYap_clsSearchPageSize extends CYap_clsSearchField
986 function CYap_clsSearchPageSize($cfg,$FieldName)
988 parent::CYap_clsSearchField($cfg,$FieldName);
1000 function GetWhereCondition($db_class)
1010 function &GetDrawObject()
1012 $ViewObj=$this->_MakeViewObj();
1013 $ViewObj->SetProperty('Size
',$this->Size);
1030 class CYap_clsSearchRegexOpt extends CYap_clsSearchTxt
1034 function CYap_clsSearchRegexOpt($cfg,$FieldName)
1036 parent::CYap_clsSearchTxt($cfg,$FieldName);
1043 function _Initialize()
1045 parent::_Initialize();
1055 function LoadCfg($cfg)
1057 parent::LoadCFg($cfg);
1059 die('Error: the provided view
class '.$this->ViewClass.' is not subclass of
CYap_ViewOptRegex');
1068 if($this->RequestValue==
'')
1074 if ($this->Type==
"A")
1077 if($this->RegexValue==
"1")
1078 return($Db_Class->DbRegexCond($this->DbField,$Db_Class->DBEscape($this->RequestValue)).
' ');
1081 $LookFor=$this->
var_padding($this->Size,$this->Padding,$this->PaddingChar,$this->RequestValue);
1082 return($this->DbField.
'=\''.$Db_Class->DBEscape($LookFor).
'\' ');
1088 $LookFor=$this->RequestValue;
1089 return($this->DbField.'=
'.$Db_Class->DBEscape($LookFor).' ');
1096 function ReadFormData()
1098 // The text is retrieved by the standard function
1099 parent::ReadFormData();
1100 // Now I retrieve the 'complete word flag
1101 if(isset($_REQUEST[
"F".$this->MyName.
"_compWord"])&&$_REQUEST[
"F".$this->MyName.
"_compWord"]!=
'')
1108 $this->RegexValue=($_REQUEST[
"F".$this->MyName.
"_compWord"]==
'on')?
'0':
'1';
1121 $ViewObj->SetProperty(
'Size',$this->Size);
1122 $ViewObj->SetProperty(
'UseRegex',$this->RegexValue);
1136 parent::StoreInformation($prefix);
1137 $_SESSION[$prefix.
"F".$this->MyName.
'_regex']=$this->RegexValue;
1148 parent::LoadInformation($prefix);
1149 if(array_key_exists($prefix.
"F".$this->MyName.
'_regex',$_SESSION))
1151 $this->RegexValue=$_SESSION[$prefix.
"F".$this->MyName.
'_regex'];
1152 if(is_null($this->RegexValue))
1161 parent::CleanSessionInfo($prefix);
1162 if(isset($_SESSION[$prefix.
"F".$this->MyName.
'_regex']))
1163 unset($_SESSION[$prefix.
"F".$this->MyName.
'_regex']);
1183 parent::CYap_clsSearchField($cfg,$FieldName);
1192 parent::_Initialize();
1193 $this->OptionList=array();
1194 $this->ViewClass=
'CYap_SelectBox';
1195 $this->DefaultValue=
'NOFILTER';
1204 function LoadCfg($cfg)
1206 parent::LoadCFg($cfg);
1207 if(array_key_exists(
"optionlist",$cfg))
1208 $this->OptionList=$cfg[
"optionlist"];
1209 if(!
is_subclass($this->ViewClass,
'CYap_SelectBox'))
1210 die(
'Error: the provided view class '.$this->ViewClass.
' is not subclass of CYap_SelectBox');
1221 function AddOption($Text,$Value)
1223 $this->OptionList[$Value]=$Text;
1237 if($this->RequestValue==
''||$this->RequestValue==
'ALL'||$this->RequestValue==
'NOFILTER')
1242 if ($this->Type==
"A")
1244 return($this->DbField.
'=\''.$Db_Class->DBEscape($LookFor).
'\' ');
1247 return($this->DbField.'=
'.$Db_Class->DBEscape($LookFor).' ');
1254 function &GetDrawObject()
1256 $ViewObj=$this->_MakeViewObj();
1257 $ViewObj->SetProperty('Choices
',$this->OptionList);
1265 class CYap_clsSearchRangeTxt extends CYap_clsSearchField
1270 * $RequestValue is assumed as from,
1271 * $RequestValueTo is the to field
1272 * $DefaultValue is assumed as from
1273 * $DefaultValueTo is the 'to
' default
1274 * if only the from, or only the to RequestValue (or DefaultValue) is filled
1275 * the 'to
' and the 'from
' values are set equal
1278 var $RequestValueTo;
1279 var $DefaultValueTo;
1281 function CYap_clsSearchRangeTxt($cfg,$FieldName)
1283 parent::CYap_clsSearchField($cfg,$FieldName);
1284 $this->UseRegex='0
';
1285 if(is_null($this->DefaultValueTo))
1286 $this->DefaultValueTo=$this->DefaultValue;
1293 function _Initialize()
1295 parent::_Initialize();
1296 $this->DefaultValueTo='';
1306 function LoadCfg($cfg)
1308 parent::LoadCFg($cfg);
1309 if(array_key_exists("defaultto",$cfg))
1310 $this->DefaultValueTo=$cfg["defaultto"];
1312 die('Error: the provided view
class '.$this->ViewClass.' is not subclass of
CYAP_ViewTextRange');
1323 if($this->RequestValue==
'')
1329 if ($this->Type==
"A")
1331 $LookForFrom=$this->
var_padding($this->Size,$this->Padding,$this->PaddingChar,$this->RequestValue);
1332 $LookForTo=$this->
var_padding($this->Size,$this->Padding,$this->PaddingChar,$this->RequestValueTo);
1333 return($Db_Class->DbBetweenCond($this->DbField,$Db_Class->DBEscape($this->RequestValue),$Db_Class->DBEscape($this->RequestValueTo),
'DB_TEXT').
' ');
1339 $LookForTo=$this->RequestValueTo;
1340 return($Db_Class->DbBetweenCond($this->DbField,$Db_Class->DBEscape($this->RequestValue),$Db_Class->DBEscape($this->RequestValueTo),
'DB_NUMBER').
' ');
1356 if($padding==
'none') {
return($text); }
1359 case 'left': $cmd=STR_PAD_LEFT;
1361 case 'right': $cmd=STR_PAD_RIGHT;
1363 case 'center': $cmd=STR_PAD_BOTH;
1366 trigger_error(
'ERROR: invalid padding value '.$padding,E_USER_ERROR);
1369 $dimTesto=strlen($text);
1371 if ($dimTesto<$size) {
return(str_pad($text, $size, $paddingchar, $cmd)); }
1372 else {
return($text); }
1381 if(isset($_REQUEST[
"F".$this->MyName])&&$_REQUEST[
"F".$this->MyName]!=
'')
1383 $this->RequestValue=$_REQUEST[
"F".$this->MyName];
1384 if(is_null($this->RequestValue))
1389 if(isset($_REQUEST[
"F".$this->MyName.
"_To"])&&$_REQUEST[
"F".$this->MyName.
"_To"]!=
'')
1391 $this->RequestValueTo=$_REQUEST[
"F".$this->MyName.
"_To"];
1392 if(is_null($this->RequestValueTo))
1393 $this->RequestValueTo=$this->DefaultValueTo;
1396 $this->RequestValueTo=$this->DefaultValueTo;
1397 if((is_null($this->RequestValue)||$this->RequestValue==
'')&&!is_null($this->RequestValueTo))
1398 $this->RequestValue=$this->RequestValueTo;
1399 elseif(!is_null($this->RequestValue)&&(is_null($this->RequestValueTo)||$this->RequestValueTo==
''))
1409 function GetValueTo()
1411 if($this->RequestValueTo!=
'' && !is_null($this->RequestValueTo))
1412 return($this->RequestValueTo);
1414 return($this->DefaultValueTo);
1424 function SetDefaultValueTo($value)
1426 $this->DefaultValueTo=$value;
1438 parent::StoreInformation($prefix);
1439 $_SESSION[$prefix.
"F".$this->MyName.
"_To"]=$this->RequestValueTo;
1450 parent::LoadInformation($prefix);
1451 if(array_key_exists($prefix.
"F".$this->MyName.
"_To",$_SESSION))
1453 $this->RequestValueTo=$_SESSION[$prefix.
"F".$this->MyName.
"_To"];
1454 if(is_null($this->RequestValueTo))
1455 $this->RequestValueTo=$this->DefaultValueTo;
1458 $this->RequestValueTo=$this->DefaultValueTo;
1463 parent::CleanSessionInfo($prefix);
1464 if(isset($_SESSION[$prefix.
"F".$this->MyName.
"_To"]))
1465 unset($_SESSION[$prefix.
"F".$this->MyName.
"_To"]);
1475 $ViewObj->SetValueTo($this->GetValueTo());
1476 $ViewObj->SetProperty(
'Size',$this->Size);
1477 $ViewObj->SetControlNameTo(
'F'.$this->MyName.
'_To');
1498 parent::CYap_clsSearchField($cfg,$FieldName);
1507 parent::_Initialize();
1508 $this->ShowFormat=
'd-m-Y';
1509 $this->WhereFormat=
'Ymd';
1510 $this->ViewClass=
'CYAP_ViewDate';
1519 function LoadCfg($cfg)
1521 parent::LoadCFg($cfg);
1522 if(array_key_exists(
"showformat",$cfg))
1523 $this->ShowFormat=$cfg[
"showformat"];
1524 if(array_key_exists(
"showformat",$cfg))
1525 $this->WhereFormat=$cfg[
"filterformat"];
1526 if(!
is_subclass($this->ViewClass,
'CYap_ViewDate'))
1527 die(
'Error: the provided view class '.$this->ViewClass.
' is not subclass of CYAP_ViewDate');
1538 if($this->RequestValue==
'')
1543 if ($this->Type==
"A")
1545 if($this->WhereFormat==strtoupper(
'TIMESTAMP'))
1546 $cond= $this->DbField.
'= \''.$this->RequestValue.
'\'';
1548 $cond= $this->DbField.
'= \''.date($this->WhereFormat,$this->RequestValue).
'\'';
1552 if($this->WhereFormat==strtoupper(
'TIMESTAMP'))
1553 $cond= $this->DbField.
'='.$this->RequestValue.
' ';
1555 $cond= $this->DbField.
'= '.date($this->WhereFormat,$this->RequestValue).
' ';
1566 if(isset($_REQUEST[
"F".$this->MyName])&&$_REQUEST[
"F".$this->MyName]!=
'')
1568 $InsertValue=$_REQUEST[
"F".$this->MyName];
1569 if(is_null($InsertValue))
1574 $cond=
'/([dmYHM])/';
1576 $Format=preg_replace($cond,$replace,$this->ShowFormat);
1577 $this->RequestValue=@strtotime($this->parseDate($InsertValue,$Format));
1578 if($this->RequestValue===
false)
1608 if( !preg_match_all(
"/%([YmdHMsu])([^%])*/", $format, $formatTokens, PREG_SET_ORDER ) ) {
1612 foreach( $formatTokens as $formatToken ) {
1613 if(array_key_exists(2,$formatToken))
1614 $delimiter = preg_quote( $formatToken[2],
"/" );
1617 if($formatToken[1] ==
'Y') {
1618 $datePattern .=
'(.{1,4})'.$delimiter;
1619 } elseif($formatToken[1] ==
'u') {
1620 $datePattern .=
'(.{1,5})'.$delimiter;
1622 $datePattern .=
'(.{1,2})'.$delimiter;
1627 if( !preg_match(
"/".$datePattern.
"/", $date, $dateTokens) ) {
1630 $dateSegments = array();
1631 for($i = 0; $i < count($formatTokens); $i++) {
1632 $dateSegments[$formatTokens[$i][1]] = $dateTokens[$i+1];
1637 if( $dateSegments[
"Y"] && $dateSegments[
"m"] && $dateSegments[
"d"] ) {
1638 if( ! checkdate ( $dateSegments[
"m"], $dateSegments[
"d"], $dateSegments[
"Y"] )) {
return false; }
1640 str_pad($dateSegments[
"Y"], 4,
'0', STR_PAD_LEFT)
1641 .
"-".str_pad($dateSegments[
"m"], 2,
'0', STR_PAD_LEFT)
1642 .
"-".str_pad($dateSegments[
"d"], 2,
'0', STR_PAD_LEFT);
1662 return $dateReformated;
1674 $ViewObj->SetProperty(
'ShowFormat',$this->ShowFormat);