inc.class.virt.filters.php 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 <? /* =========================================== FILTERS =========================================== */ class { var var var var $pname=$this->tag_prefijo."[".$this->tag_codigo."]"; if($valor=="<<vacio>>") $valor=''; switch ($this->tag_tipo) { case "text" : $retval=$this->sayText( $pname, $valor, " style='width:100%;' "); break; case "int" : $retval=$this->sayInt( $pname, $valor, " style='width:100%;' "); break; case "real" : $retval=$this->sayReal( $pname, $valor, " style='width:100%;' "); break; case "sn" : $retval=$this->saySN( $pname, $valor, ""); break; case "mf" : $retval=$this->sayMF( $pname, $valor, ""); break; case "10" : $retval=$this->say10( $pname, $valor, ""); break; case "internacional" : $retval=$this->sayInternacional( $pname, $valor, ""); break; case "nuevo" : $retval=$this->sayNuevo( $pname, $valor, ""); break; case "prorroga" : $retval=$this->sayProrroga( $pname, $valor, ""); break; case "date" : $retval=$this->sayFecha($this->tag_form,$pname, $valor, " style='width:150;' "); break; case "object" : $retval=$this->tag_object->getSelect($pname,$valor, " style='width:100%;' "); break; } 44 45 46 47 57 58 59 //nombre del dato //tipo de dato //objeto, en el caso de ser necesario //prefijo para los datos function buildControl($valor='<<vacio>>') { 40 41 42 43 56 $tag_codigo; $tag_tipo; $tag_object; $tag_prefijo; //===================================================================== // FUNCIONES PARA ARMADO DE CAMPOS. //===================================================================== 39 55 filter /* Constructor */ function filter($form,$prefijo,$nombre,$tipo,$object=null) { $this->tag_form=$form; $this->tag_codigo=$nombre; $this->tag_prefijo=$prefijo; $this->tag_tipo=$tipo; $this->tag_object=$object; } 38 48 49 50 51 52 53 54 14/03/2005 13:01 return($retval); } //INPUT ------------------------------------function sayInt($pname,$pvalue,$pextra) { return($this->sayInput("text", $pname, $pvalue, $pextra." style='text-align: right;' ")); } function sayReal($pname,$pvalue,$pextra) { return($this->sayInput("text", $pname, $pvalue, $pextra." style='text-align: right;' ")); } function sayText($pname,$pvalue,$pextra) { return($this->sayInput("text",$pname,$pvalue,$pextra)); } function sayInput($ptipo,$pname,$pvalue,$pextra) { return("<input type='$ptipo' id='$pname' name='$pname' value='$pvalue' Page 1 of 8 inc.class.virt.filters.php 14/03/2005 13:01 $pextra>"); 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 } //TEXTAREA ------------------------------------function sayTextarea($pname,$pvalue,$pextra) { return("<textarea id='$pname' name='$pname' $pextra>$pvalue</textarea>"); } //FECHA ------------------------------------function sayFecha($form,$pname,$pvalue,$pextra) { $f=new fecha(); if(!is_array($pvalue)) { $pvalue[0]=$pvalue; $pvalue[1]=$pvalue[0]; } $ret= " ".$f->showImput($form,$pname."[desde]",$pvalue[0],"",true)." ".$f->showImput($form,$pname."[hasta]",$pvalue[1]," style='display: none;' ",true)." 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 <script language='JavaScript' type='text/javascript'> function sel_fecha_cambio(ob) { //averiguo el nro de campo nombre=ob.name; nombre=nombre.substr(5); nombre=nombre.substr(0,nombre.length-1); hasta_ver= (document.all) ? document.all['pick_cr_['+nombre+'][hasta]'] : document.forms[$form].elements['pick_cr_['+nombre+'][hasta]']; if(ob.value=='entre') { hasta_ver.style.display='inline';} else { hasta_ver.style.display='none';} } </script> "; return($ret); } //YESNO ------------------------------------function saySN($pname,$pvalue,$pextra) { return( " <select id='$pname' name='$pname' $pextra> <option value='' ".((strtoupper($pvalue)=='')?"SELECTED":"")."></option> <option value='S' ".((strtoupper($pvalue)=='S')?"SELECTED":"").">Si</option> <option value='N' ".((strtoupper($pvalue)=='N')?"SELECTED":"").">No</option> </select> "); } function sayMF($pname,$pvalue,$pextra) { return( " <select id='$pname' name='$pname' $pextra> <option value='' ".((strtoupper($pvalue)=='')?"SELECTED":"")."></option> <option value='M' ".((strtoupper($pvalue)=='M')?"SELECTED":"").">Masculino</option> <option value='F' ".((strtoupper($pvalue)=='F')?"SELECTED":"").">Femenino</option> </select> "); Page 2 of 8 inc.class.virt.filters.php 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 14/03/2005 13:01 } function say10($pname,$pvalue,$pextra) { return( " <select id='$pname' name='$pname' $pextra> <option value='' ".(($pvalue=='')?"SELECTED":"")."></option> <option value='1' ".(($pvalue=='1')?"SELECTED":"").">Si</option> <option value='0' ".(($pvalue=='0')?"SELECTED":"").">No</option> </select> "); } function sayInternacional($pname,$pvalue,$pextra) { return( " <select id='$pname' name='$pname' $pextra> <option value='' ".(($pvalue=='')?"SELECTED":"")."></option> <option value='INTERNACIONAL' ".(($pvalue=='INTERNACIONAL')?"SELECTED":"").">Internacional</option> <option value='!INTERNACIONAL' ".(($pvalue=='!INTERNACIONAL')?"SELECTED":"").">NO Internacional</option> </select> "); } function sayNuevo($pname,$pvalue,$pextra) { return( " <select id='$pname' name='$pname' $pextra> <option value='' ".(($pvalue=='')?"SELECTED":"")."></option> <option value='NUEVO' ".(($pvalue=='NUEVO')?"SELECTED":"").">Nuevo</option> <option value='!NUEVO' ".(($pvalue=='!NUEVO')?"SELECTED":"").">NO Nuevo</option> </select> "); } function sayProrroga($pname,$pvalue,$pextra) { return( " <select id='$pname' name='$pname' $pextra> <option value='' ".(($pvalue=='')?"SELECTED":"")."></option> <option value='PRORROGA' ".(($pvalue=='PRORROGA')?"SELECTED":"").">Prórroga</option> <option value='!PRORROGA' ".(($pvalue=='!PRORROGA')?"SELECTED":"").">NO Prórroga</option> </select> "); } //--------------------------------------------------------------// FUNCIONES DE SELECTORS //--------------------------------------------------------------function showSelector($valor=null) { $nombre="sel_[".$this->tag_codigo."]"; switch($this->tag_tipo) { case 'text' : return($this->textSelecter($nombre,$valor)); break; case 'int' : return($this->numSelecter($nombre,$valor)); break; case 'real' : return($this->numSelecter($nombre,$valor)); break; case 'date' : return($this->dateSelecter($nombre,$valor)); break; case 'object' : return($this->objectSelecter($nombre,$valor)); break; } } function textSelecter($nombre,$valor) //------------------------------------{ return( " <select id='$nombre' name='$nombre' style='width:100%;'> Page 3 of 8 inc.class.virt.filters.php 183 <option value='igual' ".(($valor=="igual")?"SELECTED":"").">Igual a</option> <option value='distinto'".(($valor=="distinto")?"SELECTED":"").">Distinto de</option> <option value='begin'".(($valor=="begin")?"SELECTED":"").">Que Comience con</option> <option value='contain'".(($valor=="contain")?"SELECTED":"").">Que Contenga</option> <option value='notcontain'".(($valor=="notcontain")?"SELECTED":"").">Que NO Contenga</option> <option value='end'".(($valor=="end")?"SELECTED":"").">Que Termine en</option> </select> "); 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 14/03/2005 13:01 } function numSelecter($nombre,$valor) //------------------------------------{ return( " <select id='$nombre' name='$nombre' style='width:100%;'> <option value='=' ".(($valor=="=")?"SELECTED":"").">= Igual</option> <option value='!=' ".(($valor=="!=")?"SELECTED":"").">!= Distinto</option> <option value='<' ".(($valor=="<")?"SELECTED":"").">< Menor que</option> <option value='>' ".(($valor==">")?"SELECTED":"").">> Mayor que</option> <option value='<=' ".(($valor=="<=")?"SELECTED":"")."><= Menor o igual que</option> <option value='>=' ".(($valor==">=")?"SELECTED":"").">>= Mayor o igual que</option> <option value='<= >=' ".(($valor=="<= >=")?"SELECTED":"")."><= >= Entre Inclusivo</option> <option value='< >' ".(($valor=="< >")?"SELECTED":"").">< > Entre Exclusivo</option> <option value='>0' ".(($valor==">0")?"SELECTED":"").">>=0 Positivos</option> <option value='<0' ".(($valor=="<0")?"SELECTED":"")."><0 Negativos</option> </select> "); } function dateSelecter($nombre,$valor) //------------------------------------{ return( " <select id='$nombre' name='$nombre' onchange='sel_fecha_cambio(this);' style='width:100%;'> <option value='none' ".(($valor=="none")?"SELECTED":"")."></option> <option value='=' ".(($valor=="=")?"SELECTED":"").">El</option> <option value='<' ".(($valor=="<")?"SELECTED":"").">Anteriores al</option> <option value='>=' ".(($valor==">=")?"SELECTED":"").">Desde el</option> <option value='entre' ".(($valor=="entre")?"SELECTED":"").">Entre</option> </select> "); } function objectSelecter($nombre,$valor) //------------------------------------{ return( " <select id='$nombre' name='$nombre' style='width:100%;'> <option value='none' ".(($valor=="none")?"SELECTED":"")."></option> <option value='igual' ".(($valor=="igual")?"SELECTED":"").">Igual a</option> <option value='distinto' Page 4 of 8 inc.class.virt.filters.php 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 14/03/2005 13:01 ".(($valor=="distinto")?"SELECTED":"").">Distinto de</option> </select> "); } //--------------------------------------------------------------//--------------------------------------------------------------// FUNCIONES DE FILTRO POR SELECTORES //--------------------------------------------------------------function armarFiltro($sel,$cr,$prefijo="") //arma un filtro de acuerdo a los datos que se le pasan { $res=""; switch($this->tag_tipo) { case "text" : //-------------------------------------------------if(strlen(trim($cr[$this->tag_codigo]))!=0) { $res.=" AND $prefijo$this->tag_codigo "; switch($sel[$this->tag_codigo]) { case 'igual' : $res.=" = '".$cr[$this->tag_codigo]."' "; break; case 'distinto' : $res.=" != '".$cr[$this->tag_codigo]."' "; break; case 'begin' : $res.=" like '".$cr[$this->tag_codigo]."%' "; break; case 'contain' : $res.=" like '%".$cr[$this->tag_codigo]."%' "; break; case 'notcontain' : $res.=" not like '%".$cr[$this->tag_codigo]."%' "; break; case 'end' : $res.=" like '%".$cr[$this->tag_codigo]."' "; break; } } break; case "object" : //-------------------------------------------------if(strlen(trim($cr[$this->tag_codigo]))!=0) { $res.=" AND $prefijo$this->tag_codigo "; switch($sel[$this->tag_codigo]) { case 'igual' : $res.=" = '".$cr[$this->tag_codigo]."' "; break; case 'distinto' : $res.=" != '".$cr[$this->tag_codigo]."' "; break; default : $res=""; } } break; case "int" : //--------------------------------------------------case "real" : if(strlen(trim($cr[$this->tag_codigo]))!=0) { $val=$cr[$this->tag_codigo]; $campo=$prefijo.$this->tag_codigo; switch($sel[$this->tag_codigo]) { //un parametro case '=' : $res.=" AND ($campo = $val) "; break; case '!=' : $res.=" AND ($campo != $val) "; break; case '<' : $res.=" AND ($campo < $val) "; break; case '>' : $res.=" AND ($campo > $val) "; break; case '<=' : $res.=" AND ($campo <= $val) "; break; case '>=' : $res.=" AND ($campo >= $val) "; break; case '>0' : $res.=" AND ($campo >= 0 ) "; break; case '<0' : $res.=" AND ($campo < 0 ) "; break; //dos parametros case '< >' : $par=explode("..",$val); Page 5 of 8 inc.class.virt.filters.php 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 $res.=" AND ($campo > $par[0] and $campo < $par[1]) "; break; case '<= >=' : $par=explode("..",$val); $res.=" AND ($campo >= $par[0] and $campo <= $par[1]) "; break; } } break; case "10" : //--------------------------------------------------case "sn" : case "mf" : $val=$cr[$this->tag_codigo]; $campo=$prefijo.$this->tag_codigo; if($val!="") $res.=" AND ($campo = '$val' ) "; break; case "internacional" : case "nuevo" : case "prorroga" : $val=$cr[$this->tag_codigo]; if($val[0]=="!") { $val=substr($val,1); $ope="!="; } else { $ope="="; } $campo=$prefijo.$this->tag_codigo; if($val!="") $res.=" AND ($campo $ope '$val' ) "; break; case "date" : //--------------------------------------------------- //var_dump($cr[$this->tag_codigo]); $val1=$cr[$this->tag_codigo]["desde"]; $val2=$cr[$this->tag_codigo]["hasta"]; $campo=$prefijo.$this->tag_codigo; switch($sel[$this->tag_codigo]) { //un parametro case 'none' : break; case '=' : $res.=" AND ( $campo = ".$this->setDate($val1,true).") "; break; case '<' : $res.=" AND ( $campo < ".$this->setDate($val1,true).") "; break; case '>=' : $res.=" AND ( $campo >=".$this->setDate($val1,true).") "; break; case 'entre' : $res.=" AND ( $campo >=".$this->setDate($val1,true).") AND ( $campo <=".$this->setDate($val2,true).") "; break; } break; 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 14/03/2005 13:01 } return($res); } function getDate($timestamp=null,$time=null) //------------------------------{ if(is_null($timestamp) or $timestamp==0) { $formato=(is_null($time))?"Y-m-d":"Y-m-d H:i"; return(date($formato)); } if($this->connection->type=='pgsql') //------------------- pgsql { if(is_null($time)) return(substr($timestamp,0,10)); else return(substr($timestamp,0,16)); } else //--------------------------------------------------- mysql { if(strpos($timestamp,"-")===false) Page 6 of 8 inc.class.virt.filters.php 363 364 365 14/03/2005 13:01 { if(is_null($time)) return(substr($timestamp,0,4)."-".substr($timestamp,4,2)."-".substr($tim estamp,6,2)); else 366 367 return(substr($timestamp,0,4)."-".substr($timestamp,4,2)."-".substr($tim estamp,6,2)." ".substr($timestamp,8,2).":".substr($timestamp,10,2)); 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 } else { if(is_null($time)) else } return(substr($timestamp,0,16)); return($timestamp); } } function setDate($cadena=null) //---------------------------------------{ if($this->connection->type=='pgsql') //------------- pgsql { if($cadena!=null) $res=$cadena; else { $f=new Fecha(); $res=$f->toTimeStamp(); } } else //--------------------------------------------- mysql { $f=new Fecha(); if(!is_null($cadena)) { $f->fromTimeStamp($cadena); } $res= str_pad($f->anio,4,"0",STR_PAD_LEFT). str_pad($f->mes,2,"0",STR_PAD_LEFT). str_pad($f->dia,2,"0",STR_PAD_LEFT). str_pad($f->hora,2,"0",STR_PAD_LEFT). str_pad($f->minuto,2,"0",STR_PAD_LEFT). str_pad($f->segundo,2,"0",STR_PAD_LEFT); } return($res); } function showDate($timestamp=null,$time=null) //------------------------------{ if(is_null($timestamp) or $timestamp==0) { $formato=(is_null($time))?"d-m-Y":"d-m-Y H:i"; return(date($formato)); } if($this->connection->type=='pgsql') //------------------- pgsql { if(is_null($time)) return(substr($timestamp,0,10)); else return(substr($timestamp,0,16)); } else //--------------------------------------------------- mysql { if(is_null($time)) return(substr($timestamp,8,2)."-".substr($timestamp,5,2)."-".substr($times tamp,0,4)); else return(substr($timestamp,8,2)."-".substr($timestamp,5,2)."-".substr($times Page 7 of 8 inc.class.virt.filters.php 14/03/2005 13:01 tamp,0,4)." ".substr($timestamp,11,2).":".substr($timestamp,14,2)); 426 427 428 429 430 431 432 433 } } } ?> Page 8 of 8