Documentation TYPO3 par Ameos |
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 2001-2004 Christian Jul Jensen (christian@typo3.com) 00006 * All rights reserved 00007 * 00008 * This script is part of the TYPO3 project. The TYPO3 project is 00009 * free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * The GNU General Public License can be found at 00015 * http://www.gnu.org/copyleft/gpl.html. 00016 * A copy is found in the textfile GPL.txt and important notices to the license 00017 * from the author is found in LICENSE.txt distributed with these scripts. 00018 * 00019 * 00020 * This script is distributed in the hope that it will be useful, 00021 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 * GNU General Public License for more details. 00024 * 00025 * This copyright notice MUST APPEAR in all copies of the script! 00026 ***************************************************************/ 00095 class t3lib_queryGenerator { 00096 var $lang = array( 00097 "OR" => "or", 00098 "AND" => "and", 00099 "comparison" => array( 00100 // Type = text offset = 0 00101 "0_" => "contains", 00102 "1_" => "does not contain", 00103 "2_" => "starts with", 00104 "3_" => "does not start with", 00105 "4_" => "ends with", 00106 "5_" => "does not end with", 00107 "6_" => "equals", 00108 "7_" => "does not equal", 00109 // Type = date,number , offset = 32 00110 "32_" => "equals", 00111 "33_" => "does not equal", 00112 "34_" => "is greater than", 00113 "35_" => "is less than", 00114 "36_" => "is between", 00115 "37_" => "is not between", 00116 "38_" => "is in list", 00117 "39_" => "is not in list", 00118 "40_" => "binary AND equals", 00119 "41_" => "binary AND does not equal", 00120 "42_" => "binary OR equals", 00121 "43_" => "binary OR does not equal" 00122 ) 00123 ); 00124 00125 var $compSQL = array( 00126 // Type = text offset = 0 00127 "0" => "#FIELD# LIKE '%#VALUE#%'", 00128 "1" => "#FIELD# NOT LIKE '%#VALUE#%'", 00129 "2" => "#FIELD# LIKE '#VALUE#%'", 00130 "3" => "#FIELD# NOT LIKE '#VALUE#%'", 00131 "4" => "#FIELD# LIKE '%#VALUE#'", 00132 "5" => "#FIELD# NOT LIKE '%#VALUE#'", 00133 "6" => "#FIELD# = '#VALUE#'", 00134 "7" => "#FIELD# != '#VALUE#'", 00135 // Type = date,number , offset = 32 00136 "32" => "#FIELD# = '#VALUE#'", 00137 "33" => "#FIELD# != '#VALUE#'", 00138 "34" => "#FIELD# > #VALUE#", 00139 "35" => "#FIELD# < #VALUE#", 00140 "36" => "#FIELD# >= #VALUE# AND #FIELD# <= #VALUE1#", 00141 "37" => "NOT (#FIELD# >= #VALUE# AND #FIELD# <= #VALUE1#)", 00142 "38" => "#FIELD# IN (#VALUE#)", 00143 "39" => "#FIELD# NOT IN (#VALUE#)", 00144 "40" => "(#FIELD# & #VALUE#)=#VALUE#", 00145 "41" => "(#FIELD# & #VALUE#)!=#VALUE#", 00146 "42" => "(#FIELD# | #VALUE#)=#VALUE#", 00147 "43" => "(#FIELD# | #VALUE#)!=#VALUE#" 00148 ); 00149 00150 var $comp_offsets = array( 00151 "text" => 0, 00152 "number" => 1, 00153 "date" => 1 00154 ); 00155 var $noWrap=" nowrap"; 00156 00157 var $name; // Form data name prefix 00158 var $table; // table for the query 00159 var $fieldList; // field list 00160 var $fields = array(); // Array of the fields possible 00161 var $extFieldLists = array(); 00162 var $queryConfig=array(); // The query config 00163 var $enablePrefix=0; 00164 var $enableQueryParts = 0; 00165 var $extJSCODE=""; 00166 00167 00168 00169 00170 00171 00172 00176 function makeFieldList() { 00177 global $TCA; 00178 $fieldListArr = array(); 00179 if (is_array($TCA[$this->table])) { 00180 t3lib_div::loadTCA($this->table); 00181 reset($TCA[$this->table]["columns"]); 00182 while(list($fN)=each($TCA[$this->table]["columns"])) { 00183 $fieldListArr[]=$fN; 00184 } 00185 $fieldListArr[]="uid"; 00186 $fieldListArr[]="pid"; 00187 if ($TCA[$this->table]["ctrl"]["tstamp"]) $fieldListArr[]=$TCA[$this->table]["ctrl"]["tstamp"]; 00188 if ($TCA[$this->table]["ctrl"]["crdate"]) $fieldListArr[]=$TCA[$this->table]["ctrl"]["crdate"]; 00189 if ($TCA[$this->table]["ctrl"]["cruser_id"]) $fieldListArr[]=$TCA[$this->table]["ctrl"]["cruser_id"]; 00190 if ($TCA[$this->table]["ctrl"]["sortby"]) $fieldListArr[]=$TCA[$this->table]["ctrl"]["sortby"]; 00191 } 00192 return implode(",",$fieldListArr); 00193 } 00194 00203 function init($name,$table,$fieldList="") { 00204 global $TCA; 00205 00206 // Analysing the fields in the table. 00207 if (is_array($TCA[$table])) { 00208 t3lib_div::loadTCA($table); 00209 $this->name = $name; 00210 $this->table = $table; 00211 $this->fieldList = $fieldList ? $fieldList : $this->makeFieldList(); 00212 00213 $fieldArr = t3lib_div::trimExplode(",",$this->fieldList,1); 00214 reset($fieldArr); 00215 while(list(,$fN)=each($fieldArr)) { 00216 $fC = $TCA[$this->table]["columns"][$fN]; 00217 if (is_array($fC) && $fC["label"]) { 00218 $this->fields[$fN]["label"] = ereg_replace(":$","",trim($GLOBALS["LANG"]->sL($fC["label"]))); 00219 switch($fC["config"]["type"]) { 00220 case "input": 00221 if (eregi("int|year",$fC["config"]["eval"])) { 00222 $this->fields[$fN]["type"]="number"; 00223 } elseif (eregi("date|time",$fC["config"]["eval"])) { 00224 $this->fields[$fN]["type"]="date"; 00225 } else { 00226 $this->fields[$fN]["type"]="text"; 00227 } 00228 break; 00229 case "check": 00230 case "select": 00231 $this->fields[$fN]["type"]="number"; 00232 break; 00233 case "text": 00234 default: 00235 $this->fields[$fN]["type"]="text"; 00236 break; 00237 } 00238 00239 } else { 00240 $this->fields[$fN]["label"]="[FIELD: ".$fN."]"; 00241 $this->fields[$fN]["type"]="number"; 00242 } 00243 } 00244 } 00245 00246 /* // EXAMPLE: 00247 $this->queryConfig = array( 00248 array( 00249 "operator" => "AND", 00250 "type" => "FIELD_spaceBefore", 00251 ), 00252 array( 00253 "operator" => "AND", 00254 "type" => "FIELD_records", 00255 "negate" => 1, 00256 "inputValue" => "foo foo" 00257 ), 00258 array( 00259 "type" => "newlevel", 00260 "nl" => array( 00261 array( 00262 "operator" => "AND", 00263 "type" => "FIELD_spaceBefore", 00264 "negate" => 1, 00265 "inputValue" => "foo foo" 00266 ), 00267 array( 00268 "operator" => "AND", 00269 "type" => "FIELD_records", 00270 "negate" => 1, 00271 "inputValue" => "foo foo" 00272 ) 00273 ) 00274 ), 00275 array( 00276 "operator" => "OR", 00277 "type" => "FIELD_maillist", 00278 ) 00279 ); 00280 */ 00281 $this->initUserDef(); 00282 } 00283 00292 function setAndCleanUpExternalLists($name,$list,$force="") { 00293 $fields = array_unique(t3lib_div::trimExplode(",",$list.",".$force,1)); 00294 reset($fields); 00295 $reList=array(); 00296 while(list(,$fN)=each($fields)) { 00297 if ($this->fields[$fN]) $reList[]=$fN; 00298 } 00299 $this->extFieldLists[$name]=implode(",",$reList); 00300 } 00301 00308 function procesData($qC="") { 00309 $this->queryConfig = $qC; 00310 00311 $POST = t3lib_div::_POST(); 00312 00313 // if delete... 00314 if($POST["qG_del"]) { 00315 //initialize array to work on, save special parameters 00316 $ssArr = $this->getSubscript($POST["qG_del"]); 00317 $workArr =& $this->queryConfig; 00318 for($i=0;$i<sizeof($ssArr)-1;$i++) { 00319 $workArr =& $workArr[$ssArr[$i]]; 00320 } 00321 // delete the entry and move the other entries 00322 unset($workArr[$ssArr[$i]]); 00323 for($j=$ssArr[$i];$j<sizeof($workArr);$j++) { 00324 $workArr[$j] = $workArr[$j+1]; 00325 unset($workArr[$j+1]); 00326 } 00327 } 00328 00329 // if insert... 00330 if($POST["qG_ins"]) { 00331 //initialize array to work on, save special parameters 00332 $ssArr = $this->getSubscript($POST["qG_ins"]); 00333 $workArr =& $this->queryConfig; 00334 for($i=0;$i<sizeof($ssArr)-1;$i++) { 00335 $workArr =& $workArr[$ssArr[$i]]; 00336 } 00337 // move all entries above position where new entry is to be inserted 00338 for($j=sizeof($workArr);$j>$ssArr[$i];$j--) { 00339 $workArr[$j] = $workArr[$j-1]; 00340 } 00341 //clear new entry position 00342 unset($workArr[$ssArr[$i]+1]); 00343 $workArr[$ssArr[$i]+1]['type'] = "FIELD_"; 00344 } 00345 00346 // if move up... 00347 if($POST["qG_up"]) { 00348 //initialize array to work on 00349 $ssArr = $this->getSubscript($POST["qG_up"]); 00350 $workArr =& $this->queryConfig; 00351 for($i=0;$i<sizeof($ssArr)-1;$i++) { 00352 $workArr =& $workArr[$ssArr[$i]]; 00353 } 00354 //swap entries 00355 $qG_tmp = $workArr[$ssArr[$i]]; 00356 $workArr[$ssArr[$i]] = $workArr[$ssArr[$i]-1]; 00357 $workArr[$ssArr[$i]-1] = $qG_tmp; 00358 } 00359 00360 // if new level... 00361 if($POST["qG_nl"]) { 00362 //initialize array to work on 00363 $ssArr = $this->getSubscript($POST["qG_nl"]); 00364 $workArr =& $this->queryConfig; 00365 for($i=0;$i<sizeof($ssArr)-1;$i++) { 00366 $workArr =& $workArr[$ssArr[$i]]; 00367 } 00368 // Do stuff: 00369 $tempEl = $workArr[$ssArr[$i]]; 00370 if (is_array($tempEl)) { 00371 if ($tempEl["type"]!="newlevel") { 00372 $workArr[$ssArr[$i]]=array( 00373 "type" => "newlevel", 00374 "operator" => $tempEl["operator"], 00375 "nl" => array($tempEl) 00376 ); 00377 } 00378 } 00379 } 00380 00381 // if collapse level... 00382 if($POST["qG_remnl"]) { 00383 //initialize array to work on 00384 $ssArr = $this->getSubscript($POST["qG_remnl"]); 00385 $workArr =& $this->queryConfig; 00386 for($i=0;$i<sizeof($ssArr)-1;$i++) { 00387 $workArr =& $workArr[$ssArr[$i]]; 00388 } 00389 00390 // Do stuff: 00391 $tempEl = $workArr[$ssArr[$i]]; 00392 if (is_array($tempEl)) { 00393 if ($tempEl["type"]=="newlevel") { 00394 $a1 = array_slice($workArr,0,$ssArr[$i]); 00395 $a2 = array_slice($workArr,$ssArr[$i]); 00396 array_shift($a2); 00397 $a3 = $tempEl["nl"]; 00398 $a3[0]["operator"] = $tempEl["operator"]; 00399 $workArr=array_merge($a1,$a3,$a2); 00400 } 00401 } 00402 } 00403 } 00404 00411 function cleanUpQueryConfig($queryConfig) { 00412 //since we dont traverse the array using numeric keys in the upcoming whileloop make sure it's fresh and clean before displaying 00413 if (is_array($queryConfig)) { 00414 ksort($queryConfig); 00415 } else { 00416 //queryConfig should never be empty! 00417 if(!$queryConfig[0] || !$queryConfig[0]["type"]) $queryConfig[0] = array("type"=>"FIELD_"); 00418 } 00419 // Traverse: 00420 reset($queryConfig); 00421 $c=0; 00422 $arrCount=0; 00423 while(list($key,$conf)=each($queryConfig)) { 00424 if(substr($conf["type"],0,6)=="FIELD_") { 00425 $fName = substr($conf["type"],6); 00426 $fType = $this->fields[$fName]["type"]; 00427 } elseif($conf["type"]=="newlevel") { 00428 $fType = $conf["type"]; 00429 } else { 00430 $fType = "ignore"; 00431 } 00432 // debug($fType); 00433 switch($fType) { 00434 case "newlevel": 00435 if(!$queryConfig[$key]["nl"]) $queryConfig[$key]["nl"][0]["type"] = "FIELD_"; 00436 $queryConfig[$key]["nl"]=$this->cleanUpQueryConfig($queryConfig[$key]["nl"]); 00437 break; 00438 case "userdef": 00439 $queryConfig[$key]=$this->userDefCleanUp($queryConfig[$key]); 00440 break; 00441 case "ignore": 00442 default: 00443 // debug($queryConfig[$key]); 00444 $verifiedName=$this->verifyType($fName); 00445 $queryConfig[$key]["type"]="FIELD_".$this->verifyType($verifiedName); 00446 00447 if($conf["comparison"] >> 5 != $this->comp_offsets[$fType]) $conf["comparison"] = $this->comp_offsets[$fType] << 5; 00448 $queryConfig[$key]["comparison"]=$this->verifyComparison($conf["comparison"],$conf["negate"]?1:0); 00449 00450 $queryConfig[$key]["inputValue"]=$this->cleanInputVal($queryConfig[$key]); 00451 $queryConfig[$key]["inputValue1"]=$this->cleanInputVal($queryConfig[$key],1); 00452 00453 // debug($queryConfig[$key]); 00454 break; 00455 } 00456 } 00457 return $queryConfig; 00458 } 00459 00468 function getFormElements($subLevel=0,$queryConfig="",$parent="") { 00469 $codeArr=array(); 00470 if (!is_array($queryConfig)) $queryConfig=$this->queryConfig; 00471 00472 reset($queryConfig); 00473 $c=0; 00474 $arrCount=0; 00475 while(list($key,$conf)=each($queryConfig)) { 00476 $subscript = $parent."[$key]"; 00477 $lineHTML = ""; 00478 $lineHTML.=$this->mkOperatorSelect($this->name.$subscript,$conf["operator"],$c,($conf["type"]!="FIELD_")); 00479 if(substr($conf["type"],0,6)=="FIELD_") { 00480 $fName = substr($conf["type"],6); 00481 $fType = $this->fields[$fName]["type"]; 00482 if($conf["comparison"] >> 5 != $this->comp_offsets[$fType]) $conf["comparison"] = $this->comp_offsets[$fType] << 5; 00483 00484 //nasty nasty... 00485 //make sure queryConfig contains _actual_ comparevalue. 00486 //mkCompSelect don't care, but getQuery does. 00487 $queryConfig[$key]["comparison"] += (isset($conf["negate"])-($conf["comparison"]%2)); 00488 00489 } elseif($conf["type"]=="newlevel") { 00490 $fType = $conf["type"]; 00491 } else { 00492 $fType = "ignore"; 00493 } 00494 // debug($fType); 00495 switch($fType) { 00496 case "ignore": 00497 break; 00498 case "newlevel": 00499 if(!$queryConfig[$key]["nl"]) $queryConfig[$key]["nl"][0]["type"] = "FIELD_"; 00500 $lineHTML.='<input type="hidden" name="'.$this->name.$subscript.'[type]" value="newlevel">'; 00501 $codeArr[$arrCount]["sub"] = $this->getFormElements($subLevel+1,$queryConfig[$key]["nl"],$subscript."[nl]"); 00502 break; 00503 case "userdef": 00504 $lineHTML.=$this->userDef($this->name.$subscript,$conf,$fName,$fType); 00505 break; 00506 default: 00507 $lineHTML.=$this->mkTypeSelect($this->name.$subscript.'[type]',$fName); 00508 $lineHTML.=$this->mkCompSelect($this->name.$subscript.'[comparison]',$conf["comparison"],$conf["negate"]?1:0); 00509 $lineHTML.='<input type="checkbox" '.($conf["negate"]?"checked":"").' name="'.$this->name.$subscript.'[negate]'.'" onClick="submit();">'; 00510 00511 if ($conf["comparison"]==37 || $conf["comparison"]==36) { // between: 00512 $lineHTML.='<input type="text" value="'.htmlspecialchars($conf["inputValue"]).'" name="'.$this->name.$subscript.'[inputValue]'.'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(5).'> 00513 <input type="text" value="'.htmlspecialchars($conf["inputValue1"]).'" name="'.$this->name.$subscript.'[inputValue1]'.'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(5).'> 00514 '; // onChange="submit();" 00515 } elseif ($fType=="date") { 00516 $lineHTML.='<input type="text" name="'.$this->name.$subscript.'[inputValue]_hr'.'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(10).' onChange="typo3FormFieldGet(\''.$this->name.$subscript.'[inputValue]\', \'datetime\', \'\', 0,0);"><input type="hidden" value="'.htmlspecialchars($conf["inputValue"]).'" name="'.$this->name.$subscript.'[inputValue]'.'">'; 00517 $this->extJSCODE.='typo3FormFieldSet("'.$this->name.$subscript.'[inputValue]", "datetime", "", 0,0);'; 00518 } else { 00519 $lineHTML.='<input type="text" value="'.htmlspecialchars($conf["inputValue"]).'" name="'.$this->name.$subscript.'[inputValue]'.'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(10).'>'; // onChange="submit();" 00520 } 00521 break; 00522 } 00523 if($fType != "ignore") { 00524 $lineHTML .= $this->updateIcon(); 00525 $lineHTML .= '<input type="image" border=0 src="'.$GLOBALS["BACK_PATH"].'gfx/garbage.gif" class="absmiddle" width="11" height="12" hspace=3 vspace=3 title="Remove condition" name="qG_del'.$subscript.'">'; 00526 $lineHTML .= '<input type="image" border=0 src="'.$GLOBALS["BACK_PATH"].'gfx/add.gif" class="absmiddle" width="12" height="12" hspace=3 vspace=3 title="Add condition" name="qG_ins'.$subscript.'">'; 00527 if($c!=0) $lineHTML.= '<input type="image" border=0 src="'.$GLOBALS["BACK_PATH"].'gfx/pil2up.gif" class="absmiddle" width="12" height="7" hspace=3 vspace=3 title="Move up" name="qG_up'.$subscript.'">'; 00528 00529 if($c!=0 && $fType!="newlevel") { 00530 $lineHTML.= '<input type="image" border=0 src="'.$GLOBALS["BACK_PATH"].'gfx/pil2right.gif" class="absmiddle" height="12" width="7" hspace=3 vspace=3 title="New level" name="qG_nl'.$subscript.'">'; 00531 } 00532 if($fType=="newlevel") { 00533 $lineHTML.= '<input type="image" border=0 src="'.$GLOBALS["BACK_PATH"].'gfx/pil2left.gif" class="absmiddle" height="12" width="7" hspace=3 vspace=3 title="Collapse new level" name="qG_remnl'.$subscript.'">'; 00534 } 00535 00536 $codeArr[$arrCount]["html"] = $lineHTML; 00537 $codeArr[$arrCount]["query"] = $this->getQuerySingle($conf,$c>0?0:1); 00538 $arrCount++; 00539 $c++; 00540 } 00541 } 00542 // $codeArr[$arrCount] .='<input type="hidden" name="CMD" value="displayQuery">'; 00543 $this->queryConfig = $queryConfig; 00544 //modifyHTMLColor($color,$R,$G,$B) 00545 return $codeArr; 00546 } 00547 00555 function printCodeArray($codeArr,$l=0) { 00556 reset($codeArr); 00557 $line=""; 00558 if ($l) $indent='<td><img height="1" width="50"></td>'; 00559 $lf=$l*30; 00560 $bgColor = t3lib_div::modifyHTMLColor($GLOBALS["TBE_TEMPLATE"]->bgColor2,$lf,$lf,$lf); 00561 while(list($k,$v)=each($codeArr)) { 00562 $line.= '<tr>'.$indent.'<td bgcolor="'.$bgColor.'"'.$this->noWrap.'>'.$v["html"].'</td></tr>'; 00563 if ($this->enableQueryParts) {$line.= '<tr>'.$indent.'<td>'.$this->formatQ($v["query"]).'</td></tr>';} 00564 if (is_array($v["sub"])) { 00565 $line.= '<tr>'.$indent.'<td'.$this->noWrap.'>'.$this->printCodeArray($v["sub"],$l+1).'</td></tr>'; 00566 } 00567 } 00568 $out='<table border=0 cellpadding=0 cellspacing=1>'.$line.'</table>'; 00569 return $out; 00570 } 00571 00578 function formatQ($str) { 00579 return '<font size=1 face=verdana color=maroon><i>'.$str.'</i></font>'; 00580 } 00581 00591 function mkOperatorSelect($name,$op,$draw,$submit) { 00592 if ($draw) { 00593 $out='<select name="'.$name.'[operator]"'.($submit?' onChange="submit();"':'').'>'; // 00594 $out.='<option value="AND"'.(!$op||$op=="AND" ? ' selected':'').'>'.$this->lang["AND"].'</option>'; 00595 $out.='<option value="OR"'.($op=="OR" ? ' selected':'').'>'.$this->lang["OR"].'</option>'; 00596 $out.='</select>'; 00597 } else { 00598 $out.='<input type="hidden" value="'.$op.'" name="'.$name.'[operator]">'; 00599 $out.='<img src="clear.gif" height="1" width="47">'; 00600 00601 } 00602 return $out; 00603 } 00604 00613 function mkTypeSelect($name,$fieldName,$prepend="FIELD_") { 00614 $out='<select name="'.$name.'" onChange="submit();">'; 00615 $out.='<option value=""></option>'; 00616 reset($this->fields); 00617 while(list($key,)=each($this->fields)) { 00618 if ($GLOBALS["BE_USER"]->check("non_exclude_fields",$this->table.":".$key)) { 00619 $out.='<option value="'.$prepend.$key.'"'.($key==$fieldName ? ' selected':'').'>'.$this->fields[$key]["label"].'</option>'; 00620 } 00621 } 00622 $out.='</select>'; 00623 return $out; 00624 } 00625 00632 function verifyType($fieldName) { 00633 reset($this->fields); 00634 $first = ""; 00635 while(list($key,)=each($this->fields)) { 00636 if (!$first) $first = $key; 00637 if ($key==$fieldName) return $key; 00638 } 00639 return $first; 00640 } 00641 00649 function verifyComparison($comparison,$neg) { 00650 $compOffSet = $comparison >> 5; 00651 $first=-1; 00652 for($i=32*$compOffSet+$neg;$i<32*($compOffSet+1);$i+=2) { 00653 if ($first==-1) $first = $i; 00654 if (($i >> 1)==($comparison >> 1)) { 00655 return $i; 00656 } 00657 } 00658 return $first; 00659 } 00660 00668 function mkFieldToInputSelect($name,$fieldName) { 00669 $out='<input type="Text" value="'.htmlspecialchars($fieldName).'" name="'.$name.'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth().'>'.$this->updateIcon(); 00670 $out.='<a href="#" onClick="document.forms[0][\''.$name.'\'].value=\'\';return false;"><img src="'.$GLOBALS["BACK_PATH"].'gfx/garbage.gif" class="absmiddle" width="11" height="12" hspace=3 vspace=3 title="Clear list" border=0></a>'; 00671 $out.='<BR><select name="_fieldListDummy" size=5 onChange="document.forms[0][\''.$name.'\'].value+=\',\'+this.value">'; 00672 reset($this->fields); 00673 while(list($key,)=each($this->fields)) { 00674 if ($GLOBALS["BE_USER"]->check("non_exclude_fields",$this->table.":".$key)) { 00675 $out.='<option value="'.$prepend.$key.'"'.($key==$fieldName ? ' selected':'').'>'.$this->fields[$key]["label"].'</option>'; 00676 } 00677 } 00678 $out.='</select>'; 00679 return $out; 00680 } 00681 00689 function mkTableSelect($name,$cur) { 00690 global $TCA; 00691 $out='<select name="'.$name.'" onChange="submit();">'; 00692 $out.='<option value=""></option>'; 00693 reset($TCA); 00694 while(list($tN)=each($TCA)) { 00695 if ($GLOBALS["BE_USER"]->check("tables_select",$tN)) { 00696 $out.='<option value="'.$tN.'"'.($tN==$cur ? ' selected':'').'>'.$GLOBALS["LANG"]->sl($TCA[$tN]["ctrl"]["title"]).'</option>'; 00697 } 00698 } 00699 $out.='</select>'; 00700 return $out; 00701 } 00702 00711 function mkCompSelect($name,$comparison,$neg) { 00712 $compOffSet = $comparison >> 5; 00713 $out='<select name="'.$name.'" onChange="submit();">'; 00714 for($i=32*$compOffSet+$neg;$i<32*($compOffSet+1);$i+=2) { 00715 if($this->lang["comparison"][$i."_"]) { 00716 $out.='<option value="'.$i.'"'.(($i >> 1)==($comparison >> 1) ? ' selected':'').'>'.$this->lang["comparison"][$i."_"].'</option>'; 00717 } 00718 } 00719 $out.='</select>'; 00720 return $out; 00721 } 00722 00729 function getSubscript($arr) { 00730 while(is_array($arr)) { 00731 reset($arr); 00732 list($key,)=each($arr); 00733 $retArr[] = $key; 00734 $arr = $arr[$key]; 00735 } 00736 return $retArr; 00737 } 00738 00744 function initUserDef() { 00745 00746 } 00747 00753 function userDef() { 00754 } 00755 00762 function userDefCleanUp($queryConfig) { 00763 return $queryConfig; 00764 } 00765 00773 function getQuery ($queryConfig,$pad="") { 00774 $qs = ""; 00775 // Since we don't traverse the array using numeric keys in the upcoming whileloop make sure it's fresh and clean 00776 ksort($queryConfig); 00777 reset($queryConfig); 00778 $first=1; 00779 while(list($key,$conf) = each($queryConfig)) { 00780 switch($conf['type']) { 00781 case 'newlevel': 00782 $qs.=chr(10).$pad.trim($conf['operator']).' ('.$this->getQuery($queryConfig[$key]['nl'],$pad.' ').chr(10).$pad.')'; 00783 break; 00784 case 'userdef': 00785 $qs.=chr(10).$pad.getUserDefQuery($conf,$first); 00786 break; 00787 default: 00788 $qs.=chr(10).$pad.$this->getQuerySingle($conf,$first); 00789 break; 00790 } 00791 $first=0; 00792 } 00793 return $qs; 00794 } 00795 00803 function getQuerySingle($conf,$first) { 00804 $prefix = $this->enablePrefix ? $this->table.'.' : ''; 00805 if (!$first) { 00806 // Is it OK to insert the AND operator if none is set? 00807 $qs .= trim(($conf['operator'] ? $conf['operator'] : 'AND')).' '; 00808 } 00809 $qsTmp = str_replace('#FIELD#', $prefix.trim(substr($conf['type'],6)), $this->compSQL[$conf['comparison']]); 00810 $inputVal = $this->cleanInputVal($conf); 00811 $qsTmp = str_replace('#VALUE#', $GLOBALS['TYPO3_DB']->quoteStr($inputVal,$this->table), $qsTmp); 00812 if ($conf['comparison']==37 || $conf['comparison']==36) { // between: 00813 $inputVal = $this->cleanInputVal($conf,'1'); 00814 $qsTmp = str_replace('#VALUE1#', $GLOBALS['TYPO3_DB']->quoteStr($inputVal,$this->table), $qsTmp); 00815 } 00816 $qs .= trim($qsTmp); 00817 return $qs; 00818 } 00819 00827 function cleanInputVal($conf,$suffix="") { 00828 if(($conf["comparison"] >> 5==0) || ($conf["comparison"]==32 || $conf["comparison"]==33)) { 00829 $inputVal = $conf["inputValue".$suffix]; 00830 } else { 00831 if ($conf["comparison"]==39 || $conf["comparison"]==38) { // in list: 00832 $inputVal = implode(",",t3lib_div::intExplode(",",$conf["inputValue".$suffix])); 00833 } else { 00834 $inputVal = doubleval($conf["inputValue".$suffix]); 00835 } 00836 } 00837 return $inputVal; 00838 } 00839 00846 function getUserDefQuery ($qcArr) { 00847 } 00848 00854 function updateIcon() { 00855 return '<input type="image" border=0 src="'.$GLOBALS["BACK_PATH"].'gfx/refresh_n.gif" class="absmiddle" width="14" height="14" hspace=3 vspace=3 title="Update" name="just_update">'; 00856 } 00857 00863 function getLabelCol() { 00864 global $TCA; 00865 return $TCA[$this->table]["ctrl"]["label"]; 00866 } 00867 00875 function makeSelectorTable($modSettings,$enableList="table,fields,query,group,order,limit") { 00876 $enableArr=explode(",",$enableList); 00877 // Make output 00878 $TDparams = ' class="bgColor5" nowrap'; 00879 00880 if (in_array("table",$enableArr)) { 00881 $out=' 00882 <tr> 00883 <td'.$TDparams.'><strong>Select a table:</strong></td> 00884 <td'.$TDparams.'>'.$this->mkTableSelect("SET[queryTable]",$this->table).'</td> 00885 </tr>'; 00886 } 00887 if ($this->table) { 00888 00889 // Init fields: 00890 $this->setAndCleanUpExternalLists("queryFields",$modSettings["queryFields"],"uid,".$this->getLabelCol()); 00891 $this->setAndCleanUpExternalLists("queryGroup",$modSettings["queryGroup"]); 00892 $this->setAndCleanUpExternalLists("queryOrder",$modSettings["queryOrder"].",".$modSettings["queryOrder2"]); 00893 00894 // Limit: 00895 $this->extFieldLists["queryLimit"]=$modSettings["queryLimit"]; 00896 if (!$this->extFieldLists["queryLimit"]) $this->extFieldLists["queryLimit"]=100; 00897 $parts = t3lib_div::intExplode(",",$this->extFieldLists["queryLimit"]); 00898 $this->extFieldLists["queryLimit"] = implode(",",array_slice($parts,0,2)); 00899 00900 // Insert Descending parts 00901 if ($this->extFieldLists["queryOrder"]) { 00902 $descParts = explode(",",$modSettings["queryOrderDesc"].",".$modSettings["queryOrder2Desc"]); 00903 $orderParts = explode(",",$this->extFieldLists["queryOrder"]); 00904 reset($orderParts); 00905 $reList=array(); 00906 while(list($kk,$vv)=each($orderParts)) { 00907 $reList[]=$vv.($descParts[$kk]?" DESC":""); 00908 } 00909 $this->extFieldLists["queryOrder_SQL"] = implode(",",$reList); 00910 } 00911 00912 // Query Generator: 00913 $this->procesData($modSettings["queryConfig"] ? unserialize($modSettings["queryConfig"]) : ""); 00914 // debug($this->queryConfig); 00915 $this->queryConfig = $this->cleanUpQueryConfig($this->queryConfig); 00916 // debug($this->queryConfig); 00917 $this->enableQueryParts = $modSettings["search_query_smallparts"]; 00918 00919 $codeArr=$this->getFormElements(); 00920 $queryCode=$this->printCodeArray($codeArr); 00921 00922 if (in_array("fields",$enableArr)) { 00923 $out.=' 00924 <tr> 00925 <td'.$TDparams.'><strong>Select fields:</strong></td> 00926 <td'.$TDparams.'>'.$this->mkFieldToInputSelect("SET[queryFields]",$this->extFieldLists["queryFields"]).'</td> 00927 </tr>'; 00928 } 00929 if (in_array("query",$enableArr)) { 00930 $out.='<tr> 00931 <td colspan=2'.$TDparams.'><strong>Make Query:</strong></td> 00932 </tr> 00933 <tr> 00934 <td colspan=2>'.$queryCode.'</td> 00935 </tr> 00936 '; 00937 } 00938 if (in_array("group",$enableArr)) { 00939 $out.='<tr> 00940 <td'.$TDparams.'><strong>Group By:</strong></td> 00941 <td'.$TDparams.'>'.$this->mkTypeSelect("SET[queryGroup]",$this->extFieldLists["queryGroup"],"").'</td> 00942 </tr>'; 00943 } 00944 if (in_array("order",$enableArr)) { 00945 $orderByArr = explode(",",$this->extFieldLists["queryOrder"]); 00946 // debug($orderByArr); 00947 $orderBy=""; 00948 $orderBy.=$this->mkTypeSelect("SET[queryOrder]",$orderByArr[0],""). 00949 " ".t3lib_BEfunc::getFuncCheck($GLOBALS["SOBE"]->id,"SET[queryOrderDesc]",$modSettings["queryOrderDesc"])." Descending"; 00950 if ($orderByArr[0]) { 00951 $orderBy.= "<BR>".$this->mkTypeSelect("SET[queryOrder2]",$orderByArr[1],""). 00952 " ".t3lib_BEfunc::getFuncCheck($GLOBALS["SOBE"]->id,"SET[queryOrder2Desc]",$modSettings["queryOrder2Desc"])." Descending"; 00953 } 00954 $out.='<tr> 00955 <td'.$TDparams.'><strong>Order By:</strong></td> 00956 <td'.$TDparams.'>'.$orderBy.'</td> 00957 </tr>'; 00958 } 00959 if (in_array("limit",$enableArr)) { 00960 $limit = '<input type="Text" value="'.htmlspecialchars($this->extFieldLists["queryLimit"]).'" name="SET[queryLimit]"'.$GLOBALS["TBE_TEMPLATE"]->formWidth(10).'>'.$this->updateIcon(); 00961 $out.='<tr> 00962 <td'.$TDparams.'><strong>Limit:</strong></td> 00963 <td'.$TDparams.'>'.$limit.'</td> 00964 </tr> 00965 '; 00966 } 00967 } 00968 $out='<table border=0 cellpadding=3 cellspacing=1>'.$out.'</table>'; 00969 $out.=$this->JSbottom(); 00970 return $out; 00971 } 00972 00979 function getSelectQuery($qString="") { 00980 if (!$qString) $qString=$this->getQuery($this->queryConfig); 00981 00982 $query = $GLOBALS['TYPO3_DB']->SELECTquery( 00983 $this->extFieldLists["queryFields"], 00984 $this->table, 00985 $qString.t3lib_BEfunc::deleteClause($this->table), 00986 trim($this->extFieldLists["queryGroup"]), 00987 $this->extFieldLists["queryOrder"] ? trim($this->extFieldLists["queryOrder_SQL"]) : '', 00988 $this->extFieldLists["queryLimit"] 00989 ); 00990 return $query; 00991 } 00992 00999 function JSbottom($formname="forms[0]") { 01000 if ($this->extJSCODE) { 01001 $out.=' 01002 <script language="javascript" type="text/javascript" src="'.$GLOBALS["BACK_PATH"].'t3lib/jsfunc.evalfield.js"></script> 01003 <script language="javascript" type="text/javascript"> 01004 var evalFunc = new evalFunc; 01005 function typo3FormFieldSet(theField, evallist, is_in, checkbox, checkboxValue) { 01006 var theFObj = new evalFunc_dummy (evallist,is_in, checkbox, checkboxValue); 01007 var theValue = document.'.$formname.'[theField].value; 01008 if (checkbox && theValue==checkboxValue) { 01009 document.'.$formname.'[theField+"_hr"].value=""; 01010 if (document.'.$formname.'[theField+"_cb"]) document.'.$formname.'[theField+"_cb"].checked = ""; 01011 } else { 01012 document.'.$formname.'[theField+"_hr"].value = evalFunc.outputObjValue(theFObj, theValue); 01013 if (document.'.$formname.'[theField+"_cb"]) document.'.$formname.'[theField+"_cb"].checked = "on"; 01014 } 01015 } 01016 01023 function typo3FormFieldGet(theField, evallist, is_in, checkbox, checkboxValue, checkbox_off) { 01024 var theFObj = new evalFunc_dummy (evallist,is_in, checkbox, checkboxValue); 01025 if (checkbox_off) { 01026 document.'.$formname.'[theField].value=checkboxValue; 01027 }else{ 01028 document.'.$formname.'[theField].value = evalFunc.evalObjValue(theFObj, document.'.$formname.'[theField+"_hr"].value); 01029 } 01030 typo3FormFieldSet(theField, evallist, is_in, checkbox, checkboxValue); 01031 } 01032 </script> 01033 <script language="javascript" type="text/javascript">'.$this->extJSCODE.'</script>'; 01034 return $out; 01035 } 01036 } 01037 } 01038 01039 01040 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_querygenerator.php']) { 01041 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_querygenerator.php']); 01042 } 01043 ?>