| 1 | <?php |
|---|
| 2 | /*======================================================================================================== |
|---|
| 3 | This class generates HTML tables for selecting dates (English version) |
|---|
| 4 | |
|---|
| 5 | Class attributes: |
|---|
| 6 | |
|---|
| 7 | class: Class [CSS] of HTML table that will be generated. |
|---|
| 8 | onmouseover: The Javascript function that will be run when generating the event. |
|---|
| 9 | onmouseout: Javascript function that will be run when generating the event. |
|---|
| 10 | onclick: Javascript function that will be run when clicking over the object. |
|---|
| 11 | |
|---|
| 12 | =========================================================================================================*/ |
|---|
| 13 | class Calendario{ |
|---|
| 14 | var $aula; |
|---|
| 15 | var $horaresevini; |
|---|
| 16 | var $horaresevfin; |
|---|
| 17 | var $clase ; |
|---|
| 18 | var $onmouseover; |
|---|
| 19 | var $onmouseout; |
|---|
| 20 | var $onclick; |
|---|
| 21 | |
|---|
| 22 | var $desplazamiento_dias=6; // Fine tunning depending on the algorithm start year |
|---|
| 23 | var $nombre_mes=array(); |
|---|
| 24 | var $nombre_dia=array(); |
|---|
| 25 | var $numero_annos=array(); |
|---|
| 26 | var $dias_meses=array(); |
|---|
| 27 | |
|---|
| 28 | function __construct($pclase="", $ponmouseover="sobre(this)", $ponmouseout="fuera(this)", $ponclick="clic(this)"){ //Constructor |
|---|
| 29 | $this->clase=$pclase; |
|---|
| 30 | $this->onmouseover=$ponmouseover; |
|---|
| 31 | $this->onmouseout=$ponmouseout; |
|---|
| 32 | $this->onclick=$ponclick; |
|---|
| 33 | |
|---|
| 34 | $this->nombre_mes[1]=array ("January",0x0001); |
|---|
| 35 | $this->nombre_mes[2]=array ("February",0x0002); |
|---|
| 36 | $this->nombre_mes[3]=array ("March",0x0004); |
|---|
| 37 | $this->nombre_mes[4]=array ("April",0x0008); |
|---|
| 38 | $this->nombre_mes[5]=array ("May",0x0010); |
|---|
| 39 | $this->nombre_mes[6]=array ("June",0x0020); |
|---|
| 40 | $this->nombre_mes[7]=array ("July",0x0040); |
|---|
| 41 | $this->nombre_mes[8]=array ("August",0x0080); |
|---|
| 42 | $this->nombre_mes[9]=array ("September",0x0100); |
|---|
| 43 | $this->nombre_mes[10]=array ("October",0x0200); |
|---|
| 44 | $this->nombre_mes[11]=array ("November",0x0400); |
|---|
| 45 | $this->nombre_mes[12]=array ("December",0x0800); |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | $this->numero_annos[1]=array ("2004",0x01); // size 1 bytes |
|---|
| 49 | $this->numero_annos[2]=array ("2005",0x02); |
|---|
| 50 | $this->numero_annos[3]=array ("2006",0x04); |
|---|
| 51 | $this->numero_annos[4]=array ("2007",0x08); |
|---|
| 52 | $this->numero_annos[5]=array ("2008",0x10); |
|---|
| 53 | $this->numero_annos[6]=array ("2009",0x20); |
|---|
| 54 | $this->numero_annos[7]=array ("2010",0x40); |
|---|
| 55 | $this->numero_annos[8]=array ("2011",0x80); |
|---|
| 56 | |
|---|
| 57 | $this->dias_meses[1]=31; |
|---|
| 58 | $this->dias_meses[2]=28; |
|---|
| 59 | $this->dias_meses[3]=31; |
|---|
| 60 | $this->dias_meses[4]=30; |
|---|
| 61 | $this->dias_meses[5]=31; |
|---|
| 62 | $this->dias_meses[6]=30; |
|---|
| 63 | $this->dias_meses[7]=31; |
|---|
| 64 | $this->dias_meses[8]=31; |
|---|
| 65 | $this->dias_meses[9]=30; |
|---|
| 66 | $this->dias_meses[10]=31; |
|---|
| 67 | $this->dias_meses[11]=30; |
|---|
| 68 | $this->dias_meses[12]=31; |
|---|
| 69 | |
|---|
| 70 | $this->nombre_dia[1]=array ("Mo",0x01); // size 1 bytes |
|---|
| 71 | $this->nombre_dia[2]=array ("Tu",0x02); |
|---|
| 72 | $this->nombre_dia[3]=array ("We",0x04); |
|---|
| 73 | $this->nombre_dia[4]=array ("Th",0x08); |
|---|
| 74 | $this->nombre_dia[5]=array ("Fr",0x10); |
|---|
| 75 | $this->nombre_dia[6]=array ("Sa",0x20); |
|---|
| 76 | $this->nombre_dia[7]=array ("Su",0x40); |
|---|
| 77 | } |
|---|
| 78 | /*________________________________________________________________________________________________________ |
|---|
| 79 | This function returns a string with the HTML code of year and month schedule chosen |
|---|
| 80 | and they are class properties. |
|---|
| 81 | ________________________________________________________________________________________________________*/ |
|---|
| 82 | function MesAnno($mes,$anno,$CntMes){ |
|---|
| 83 | $fecha="1/".$mes."/".$anno; |
|---|
| 84 | $ds=$this->_DiaSemana($fecha); |
|---|
| 85 | if ($ds==0) $ds=7; |
|---|
| 86 | |
|---|
| 87 | $swbi=0; // add for leap year |
|---|
| 88 | if ($this->bisiesto($anno) && $mes==2) $swbi=1; |
|---|
| 89 | |
|---|
| 90 | $HTML_calendario='<TABLE border=1 cellspacing=0 cellpadding=1 id="tabla_mesanno" class="'.$this->clase.'">'.chr(13); |
|---|
| 91 | $HTML_calendario.='<TR>'.chr(13); |
|---|
| 92 | $HTML_calendario.='<TH colspan=7 id="'.$mes.'/'.$anno.'" value="'.$this->aula.'" style="cursor:hand" onclick="TH_'.$this->onclick.'">'.$this->nombre_mes[$mes][0].'</TH></TR>'.chr(13); // Month name |
|---|
| 93 | $HTML_calendario.='<TR>'.chr(13); |
|---|
| 94 | for ($i=1;$i<8;$i++) |
|---|
| 95 | $HTML_calendario.='<TH>'.$this->nombre_dia[$i][0].'</TH>'.chr(13); // Days of the week |
|---|
| 96 | $HTML_calendario.='</TR><TR>'.chr(13); |
|---|
| 97 | for ($i=1;$i<$ds;$i++) |
|---|
| 98 | $HTML_calendario.='<TD> </TD>'.chr(13); // Filling firsts days of the week |
|---|
| 99 | $sm=$ds; // Control leap of week |
|---|
| 100 | for ($i=1;$i<=$this->dias_meses[$mes]+$swbi;$i++){ |
|---|
| 101 | $HTML_calendario.='<TD align=center '; |
|---|
| 102 | if(isset($CntMes[$i])){ |
|---|
| 103 | if($CntMes[$i]==1){ |
|---|
| 104 | $HTML_calendario.=' style="COLOR:#eeeeee;BACKGROUND-COLOR: #cc3366;"'; |
|---|
| 105 | $HTML_calendario.=' id="'.$i.'/'.$mes.'/'.$anno.'" value="'.$this->aula.'" style="cursor:hand" onmouseover="'.$this->onmouseover.'" onmouseout="'.$this->onmouseout.'" onclick="'.$this->onclick.'"'; |
|---|
| 106 | } |
|---|
| 107 | } |
|---|
| 108 | $HTML_calendario.='>'.$i.'</TD>'.chr(13); |
|---|
| 109 | if ($sm%7==0){ |
|---|
| 110 | $HTML_calendario.='</TR><TR>'.chr(13); |
|---|
| 111 | $sm=0; |
|---|
| 112 | } |
|---|
| 113 | $sm++; |
|---|
| 114 | } |
|---|
| 115 | $HTML_calendario.='</TR></TABLE>'.chr(13); |
|---|
| 116 | return($HTML_calendario); |
|---|
| 117 | } |
|---|
| 118 | /*________________________________________________________________________________________________________ |
|---|
| 119 | This function returns a string with the HTML code of year and month schedule chosen |
|---|
| 120 | and they are class properties. |
|---|
| 121 | ________________________________________________________________________________________________________*/ |
|---|
| 122 | function JMesAnno($mes,$anno,$JDif,$TBfechas,$sumahoras){ |
|---|
| 123 | $fecha="1/".$mes."/".$anno; |
|---|
| 124 | $Jdpl=$this->juliana($fecha)-$JDif; // Calculates start point for julian index |
|---|
| 125 | $ds=$this->_DiaSemana($fecha); |
|---|
| 126 | if ($ds==0) $ds=7; |
|---|
| 127 | $paso=2; // Ratio of color intensity |
|---|
| 128 | $swbi=0; // Add for leap year |
|---|
| 129 | if ($this->bisiesto($anno) && $mes==2) $swbi=1; |
|---|
| 130 | $HTML_calendario='<TABLE border=1 cellspacing=0 cellpadding=1 id="tabla_mesanno" class="'.$this->clase.'">'.chr(13); |
|---|
| 131 | $HTML_calendario.='<TR>'.chr(13); |
|---|
| 132 | $HTML_calendario.='<TH colspan=7 id="'.$mes.'/'.$anno.'" style="cursor:hand" onclick="TH_'.$this->onclick.'">'.$this->nombre_mes[(int)$mes][0].'</TH></TR>'.chr(13); // Month name |
|---|
| 133 | $HTML_calendario.='<TR>'.chr(13); |
|---|
| 134 | for ($i=1;$i<8;$i++) |
|---|
| 135 | $HTML_calendario.='<TH>'.$this->nombre_dia[$i][0].'</TH>'.chr(13); // Days of week |
|---|
| 136 | $HTML_calendario.='</TR><TR>'.chr(13); |
|---|
| 137 | for ($i=1;$i<$ds;$i++) |
|---|
| 138 | $HTML_calendario.='<TD> </TD>'.chr(13); // Filling firsts days of the week |
|---|
| 139 | $sm=$ds; // Control leap of week |
|---|
| 140 | for ($i=1;$i<=$this->dias_meses[(int)$mes]+$swbi;$i++){ |
|---|
| 141 | $HTML_calendario.='<TD align=center '; |
|---|
| 142 | if(isset($TBfechas[$Jdpl])){ |
|---|
| 143 | if($TBfechas[$Jdpl]>0){ |
|---|
| 144 | $xpor=$TBfechas[$Jdpl]*100/$sumahoras; |
|---|
| 145 | $itcr=255; |
|---|
| 146 | $itc=240-($xpor*$paso); |
|---|
| 147 | if($xpor>=50) |
|---|
| 148 | $colordia="#FFFFFF"; |
|---|
| 149 | else |
|---|
| 150 | $colordia="#000000"; |
|---|
| 151 | |
|---|
| 152 | $bgcolordia=sprintf('#%02x%02x%02x',$itcr,$itc,$itc); |
|---|
| 153 | $HTML_calendario.=' style="COLOR:'.$colordia.';BACKGROUND-COLOR: '.$bgcolordia.';"'; |
|---|
| 154 | $HTML_calendario.=' id="'.$i.'/'.$mes.'/'.$anno.'" value="'.$this->aula.'" style="cursor:hand" onmouseover="'.$this->onmouseover.'" onmouseout="'.$this->onmouseout.'" onclick="'.$this->onclick.'"'; |
|---|
| 155 | } |
|---|
| 156 | } |
|---|
| 157 | $HTML_calendario.='>'.$i.'</TD>'.chr(13); |
|---|
| 158 | if ($sm%7==0){ |
|---|
| 159 | $HTML_calendario.='</TR><TR>'.chr(13); |
|---|
| 160 | $sm=0; |
|---|
| 161 | } |
|---|
| 162 | $sm++; |
|---|
| 163 | $Jdpl++; |
|---|
| 164 | } |
|---|
| 165 | $HTML_calendario.='</TR></TABLE>'.chr(13); |
|---|
| 166 | return($HTML_calendario); |
|---|
| 167 | } |
|---|
| 168 | |
|---|
| 169 | /*________________________________________________________________________________________________________ |
|---|
| 170 | This function returns day of the week number: |
|---|
| 171 | 0=sunday 1=monday, 2=tuesday ... 6=saturday |
|---|
| 172 | |
|---|
| 173 | Input parameter: |
|---|
| 174 | A string with date format dd/mm/yyyy. |
|---|
| 175 | ________________________________________________________________________________________________________*/ |
|---|
| 176 | function _DiaSemana($fecha){ |
|---|
| 177 | list($dia,$mes,$anno)=explode('[/.-]',$fecha); |
|---|
| 178 | $cont=0; |
|---|
| 179 | for ($i=1900;$i<$anno;$i++){ |
|---|
| 180 | if ($this->bisiesto($i)) $dias_anuales=366; else $dias_anuales=365; |
|---|
| 181 | $cont+=$dias_anuales; |
|---|
| 182 | } |
|---|
| 183 | for ($i=1;$i<$mes;$i++){ |
|---|
| 184 | if ($i!=2) |
|---|
| 185 | $cont+=$this->dias_meses[$i]; |
|---|
| 186 | else{ |
|---|
| 187 | if ($this->bisiesto($anno)) |
|---|
| 188 | $cont+=29; |
|---|
| 189 | else |
|---|
| 190 | $cont+=28; |
|---|
| 191 | } |
|---|
| 192 | } |
|---|
| 193 | $cont+=$dia+$this->desplazamiento_dias; |
|---|
| 194 | return($cont%7); |
|---|
| 195 | } |
|---|
| 196 | //________________________________________________________________________________________________________ |
|---|
| 197 | // These function returns true if last year was a leap-year or false if it was not |
|---|
| 198 | // |
|---|
| 199 | // Input parameter: |
|---|
| 200 | // A number representing 1 year |
|---|
| 201 | //________________________________________________________________________________________________________ |
|---|
| 202 | function bisiesto($anob){ |
|---|
| 203 | if ($anob%4==0) return(true); else return(false); |
|---|
| 204 | } |
|---|
| 205 | //________________________________________________________________________________________________________ |
|---|
| 206 | // This function returns a string with the HTML code of the lab reservations times. |
|---|
| 207 | //________________________________________________________________________________________________________ |
|---|
| 208 | function HorasDias($CntDia,&$porcenhoras){ |
|---|
| 209 | $HTML_calendario=""; |
|---|
| 210 | $sw=0; |
|---|
| 211 | $conthoras=0; // Reservations minutes and hours counter |
|---|
| 212 | $maxcolumnas=8; |
|---|
| 213 | $tbampm[0]="a.m."; |
|---|
| 214 | $tbampm[1]="p.m."; |
|---|
| 215 | |
|---|
| 216 | $HTML_calendario.='<TABLE border=0 cellspacing=0 cellpadding=0 id="tabla_horas" class="'.$this->clase.'">'.chr(13); |
|---|
| 217 | $HTML_calendario.='<TR>'.chr(13); |
|---|
| 218 | $HTML_calendario.='<TH colspan=3>Horas</TH></TR>'.chr(13); // Literal Horas |
|---|
| 219 | $HTML_calendario.='<TR>'.chr(13); |
|---|
| 220 | $HTML_ampm[0]=""; |
|---|
| 221 | $HTML_ampm[1]=""; |
|---|
| 222 | $swampm[0]=false; |
|---|
| 223 | $swampm[1]=false; |
|---|
| 224 | |
|---|
| 225 | if($this->horaresevini<12) $ix=0; else $ix=1; |
|---|
| 226 | for($j=$ix;$j<=1;$j++){ |
|---|
| 227 | $HTML_ampm[$j].='<TD style="BACKGROUND-COLOR: #FFFFFF;" valig=top >'.chr(13); |
|---|
| 228 | $HTML_ampm[$j].='<TABLE valig=top cellspacing=0 cellpadding=0 border=1 class="'.$this->clase.'">'.chr(13); |
|---|
| 229 | $HTML_ampm[$j].='<TR>'.chr(13); |
|---|
| 230 | $HTML_ampm[$j].='<TH colspan='.$maxcolumnas.'>'.$tbampm[$j].'</TH></TR>'.chr(13); // Literal Horas |
|---|
| 231 | $HTML_ampm[$j].='<TR>'.chr(13); |
|---|
| 232 | |
|---|
| 233 | if($j==0){ // A.M.height |
|---|
| 234 | $imin=$this->horaresevini; |
|---|
| 235 | $currenthora=$imin; |
|---|
| 236 | if($this->horaresevfin<=12) |
|---|
| 237 | $imax=$this->horaresevfin; |
|---|
| 238 | else |
|---|
| 239 | $imax=12; |
|---|
| 240 | } |
|---|
| 241 | else{ |
|---|
| 242 | if($this->horaresevini<=12) |
|---|
| 243 | $imin=0; |
|---|
| 244 | else |
|---|
| 245 | $imin=$this->horaresevini-12; |
|---|
| 246 | $imax=(int)$this->horaresevfin-12; |
|---|
| 247 | $currenthora=$imin; |
|---|
| 248 | } |
|---|
| 249 | $cols=0; |
|---|
| 250 | $currentminutos=0; |
|---|
| 251 | $currenthorario=$currenthora.":".$currentminutos; |
|---|
| 252 | $intervalo=($imax-$imin+1)*4; |
|---|
| 253 | for ($i=$imin;$i<$intervalo;$i++){ |
|---|
| 254 | $cols++; |
|---|
| 255 | if($sw>0) // Brings reservations from A.M. |
|---|
| 256 | $swampm[$j]=true; |
|---|
| 257 | |
|---|
| 258 | if($currentminutos==0) $currenthorario.="0"; |
|---|
| 259 | if(isset($CntDia[$j][$currenthora][$currentminutos])){ |
|---|
| 260 | if($CntDia[$j][$currenthora][$currentminutos]==1) |
|---|
| 261 | $sw++; |
|---|
| 262 | $swampm[$j]=true; |
|---|
| 263 | } |
|---|
| 264 | if(isset($CntDia[$j][$currenthora][$currentminutos])){ |
|---|
| 265 | if($CntDia[$j][$currenthora][$currentminutos]==0) |
|---|
| 266 | $sw--; |
|---|
| 267 | } |
|---|
| 268 | $HTML_ampm[$j].='<TD '; |
|---|
| 269 | if($sw>0) |
|---|
| 270 | $HTML_ampm[$j].=' style="COLOR:#eeeeee;BACKGROUND-COLOR: #cc3366;"'; |
|---|
| 271 | |
|---|
| 272 | if($sw>0) // Counts 15 minutes fraction as reserved |
|---|
| 273 | $conthoras++; |
|---|
| 274 | $HTML_ampm[$j].=' align=center> '.$currenthorario.' </TD>'.chr(13); |
|---|
| 275 | $currentminutos+=15; |
|---|
| 276 | if($currentminutos==60) { |
|---|
| 277 | $currenthora++; |
|---|
| 278 | $currentminutos=0; |
|---|
| 279 | } |
|---|
| 280 | $currenthorario=$currenthora.":".$currentminutos; |
|---|
| 281 | if (($cols)%$maxcolumnas==0 ) $HTML_ampm[$j].='</TR><TR>'.chr(13); |
|---|
| 282 | } |
|---|
| 283 | $HTML_ampm[$j].='</TR></TABLE>'.chr(13); |
|---|
| 284 | $HTML_ampm[$j].='</TD>'.chr(13); |
|---|
| 285 | } |
|---|
| 286 | |
|---|
| 287 | if ($swampm[0]) |
|---|
| 288 | $HTML_calendario.=$HTML_ampm[0]; |
|---|
| 289 | |
|---|
| 290 | if ($swampm[0] && $swampm[1]){ |
|---|
| 291 | $HTML_calendario.='<TD style="BACKGROUND-COLOR: #FFFFFF;" width=25> '.chr(13); |
|---|
| 292 | $HTML_calendario.='</TD>'.chr(13); |
|---|
| 293 | } |
|---|
| 294 | |
|---|
| 295 | if ($swampm[1]) |
|---|
| 296 | $HTML_calendario.=$HTML_ampm[1]; |
|---|
| 297 | |
|---|
| 298 | $HTML_calendario.='</TR>'.chr(13); |
|---|
| 299 | $HTML_calendario.='</TABLE>'.chr(13); |
|---|
| 300 | |
|---|
| 301 | $numblo=($this->horaresevfin-$this->horaresevini)*4; |
|---|
| 302 | $porcenhoras=floor($conthoras*100/$numblo); |
|---|
| 303 | return($HTML_calendario); |
|---|
| 304 | } |
|---|
| 305 | /* -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|---|
| 306 | Returns a string with days (monday(1), tuesday(2)....sunday(7)), separated by commas |
|---|
| 307 | ________________________________________________________________________________________________________________*/ |
|---|
| 308 | function DiasPorMes($mes,$anno,$numerodia){ |
|---|
| 309 | $cadenadias=""; |
|---|
| 310 | $dia_c=1; |
|---|
| 311 | $fecha=$dia_c."/".$mes."/".$anno; |
|---|
| 312 | $ds=$this->_DiaSemana($fecha); |
|---|
| 313 | if ($ds==0) $ds=7; |
|---|
| 314 | while($ds!=$numerodia){ |
|---|
| 315 | $dia_c++; |
|---|
| 316 | $ds++; |
|---|
| 317 | if($ds>7) $ds=1; |
|---|
| 318 | } |
|---|
| 319 | // Calculates number of days of a month |
|---|
| 320 | $diasmaxmes=$this->dias_meses[$mes]; |
|---|
| 321 | if ($mes==2){ |
|---|
| 322 | if ($this->bisiesto($anno)){ |
|---|
| 323 | $diasmaxmes=29; |
|---|
| 324 | } |
|---|
| 325 | } |
|---|
| 326 | while($dia_c<=$diasmaxmes){ |
|---|
| 327 | $cadenadias.=$dia_c.";"; |
|---|
| 328 | $dia_c+=7; |
|---|
| 329 | } |
|---|
| 330 | return($cadenadias); |
|---|
| 331 | } |
|---|
| 332 | /*________________________________________________________________________________________________________ |
|---|
| 333 | Returns a string with the days of a month of a given week, separated by commas. |
|---|
| 334 | ________________________________________________________________________________________________________*/ |
|---|
| 335 | function DiasPorSemanas($mes,$anno,$numerosemana){ |
|---|
| 336 | $cadenadias=""; |
|---|
| 337 | $dia_c=1; |
|---|
| 338 | $nsem=1; |
|---|
| 339 | $fecha=$dia_c."/".$mes."/".$anno; |
|---|
| 340 | $ds=$this->_DiaSemana($fecha); |
|---|
| 341 | if ($ds==0) $ds=7; |
|---|
| 342 | while($nsem!=$numerosemana){ |
|---|
| 343 | $dia_c++; |
|---|
| 344 | $ds++; |
|---|
| 345 | if($ds>7){ |
|---|
| 346 | $ds=1; |
|---|
| 347 | $nsem++; |
|---|
| 348 | } |
|---|
| 349 | } |
|---|
| 350 | // Calculates number of days of a month |
|---|
| 351 | $diasmaxmes=$this->dias_meses[$mes]; |
|---|
| 352 | if ($mes==2){ |
|---|
| 353 | if ($this->bisiesto($anno)){ |
|---|
| 354 | $diasmaxmes=29; |
|---|
| 355 | } |
|---|
| 356 | } |
|---|
| 357 | for($i=$ds;$i<=7;$i++){ |
|---|
| 358 | if($dia_c>$diasmaxmes) break; |
|---|
| 359 | $cadenadias.=$dia_c.";"; |
|---|
| 360 | $dia_c++; |
|---|
| 361 | } |
|---|
| 362 | return($cadenadias); |
|---|
| 363 | } |
|---|
| 364 | // ____________________________________________________________________________ |
|---|
| 365 | // This function returns the number of last week of a month |
|---|
| 366 | // ____________________________________________________________________________ |
|---|
| 367 | function UltimaSemana($mes,$anno){ |
|---|
| 368 | $diasmaxmes=$this->dias_meses[$mes]; |
|---|
| 369 | if ($mes==2){ |
|---|
| 370 | if ($this->bisiesto($anno)){ |
|---|
| 371 | $diasmaxmes=29; |
|---|
| 372 | } |
|---|
| 373 | } |
|---|
| 374 | $fecha="1/".$mes."/".$anno; |
|---|
| 375 | $ds=$this->_DiaSemana($fecha); |
|---|
| 376 | if ($ds==0) $ds=7; |
|---|
| 377 | $nwdia=$diasmaxmes+$ds-1; |
|---|
| 378 | $cociente=floor($nwdia/7); |
|---|
| 379 | $resto=$nwdia%7; |
|---|
| 380 | if($resto>0) $cociente++; |
|---|
| 381 | return($cociente); |
|---|
| 382 | } |
|---|
| 383 | //________________________________________________________________________________________________________ |
|---|
| 384 | // Function : Dates |
|---|
| 385 | // Description : |
|---|
| 386 | // Returns a string of dates saparated by commas. These dates are part of a specific reservation |
|---|
| 387 | // Parameters: |
|---|
| 388 | // - anno_c: Aaspecefic year |
|---|
| 389 | // - mes_desde: Month from the reservation is considered |
|---|
| 390 | // - mes_hasta: Month to the reservation is consedired |
|---|
| 391 | // - meses: Field with hexadecimal information about reservation months (The information contained in the field of a table with this name) |
|---|
| 392 | // - diario: The same for days of a month |
|---|
| 393 | // - dias: The same for names of days |
|---|
| 394 | // - semanas: The same for weeks |
|---|
| 395 | //________________________________________________________________________________________________________ |
|---|
| 396 | function Fechas($anno_c,$mes_desde,$mes_hasta,$meses,$diario,$dias,$semanas){ |
|---|
| 397 | $cadenafechas=""; |
|---|
| 398 | $mascara=0x0001; |
|---|
| 399 | $cadenameses=""; |
|---|
| 400 | $meses=$meses>>($mes_desde-1); |
|---|
| 401 | for($i=$mes_desde;$i<=$mes_hasta;$i++){ |
|---|
| 402 | if($meses&$mascara>0){ |
|---|
| 403 | $cadenameses.=$i.";"; |
|---|
| 404 | // Days of the week |
|---|
| 405 | if($dias>0){ |
|---|
| 406 | $auxdias=$dias; |
|---|
| 407 | for($j=1;$j<=7;$j++){ |
|---|
| 408 | if($auxdias&$mascara>0){ |
|---|
| 409 | $cadenadias=$this->DiasPorMes($i,$anno_c,$j); |
|---|
| 410 | $tbdias=explode(";",$cadenadias); |
|---|
| 411 | for ($k=0;$k<sizeof($tbdias)-1;$k++) |
|---|
| 412 | $cadenafechas.=$tbdias[$k]."/".$i."/".$anno_c.";"; |
|---|
| 413 | } |
|---|
| 414 | $auxdias=$auxdias>>1; |
|---|
| 415 | } |
|---|
| 416 | } |
|---|
| 417 | // Weeks |
|---|
| 418 | if($semanas>0){ |
|---|
| 419 | $auxsemanas=$semanas; |
|---|
| 420 | for($j=1;$j<=6;$j++){ |
|---|
| 421 | if($auxsemanas&$mascara>0){ |
|---|
| 422 | if($j==6){ |
|---|
| 423 | $ulse=$this->UltimaSemana($i,$anno_c); |
|---|
| 424 | $cadenadias=$this->DiasPorSemanas($i,$anno_c,$ulse); |
|---|
| 425 | } |
|---|
| 426 | else |
|---|
| 427 | $cadenadias=$this->DiasPorSemanas($i,$anno_c,$j); |
|---|
| 428 | $tbdias=explode(";",$cadenadias); |
|---|
| 429 | for ($k=0;$k<sizeof($tbdias)-1;$k++) |
|---|
| 430 | $cadenafechas.=$tbdias[$k]."/".$i."/".$anno_c.";"; |
|---|
| 431 | } |
|---|
| 432 | $auxsemanas=$auxsemanas>>1; |
|---|
| 433 | } |
|---|
| 434 | } |
|---|
| 435 | } |
|---|
| 436 | $meses=$meses>>1; |
|---|
| 437 | } |
|---|
| 438 | $cadenadiario=""; |
|---|
| 439 | for($i=1;$i<32;$i++){ |
|---|
| 440 | if($diario&$mascara>0) $cadenadiario.=$i.";"; |
|---|
| 441 | $diario=$diario>>1; |
|---|
| 442 | } |
|---|
| 443 | $tbmeses=explode(";",$cadenameses); |
|---|
| 444 | $tbdiario=explode(";",$cadenadiario); |
|---|
| 445 | for ($i=0;$i<sizeof($tbmeses)-1;$i++){ |
|---|
| 446 | for ($j=0;$j<sizeof($tbdiario)-1;$j++){ |
|---|
| 447 | $cadenafechas.=$tbdiario[$j]."/".$tbmeses[$i]."/".$anno_c.";"; |
|---|
| 448 | } |
|---|
| 449 | } |
|---|
| 450 | return($cadenafechas); |
|---|
| 451 | } |
|---|
| 452 | /*______________________________________________________________________ |
|---|
| 453 | Returns the Juliano day for a specific date |
|---|
| 454 | Parameters: |
|---|
| 455 | - string with date in this format "dd/mm/yyyy" |
|---|
| 456 | Returns: |
|---|
| 457 | - Juliano day |
|---|
| 458 | _______________________________________________________________________*/ |
|---|
| 459 | function juliana($fecha) { |
|---|
| 460 | list($dia,$mes,$anno)=explode("[/-]",$fecha); |
|---|
| 461 | $GGG = 1; |
|---|
| 462 | if ($anno <= 1585) $GGG = 0; |
|---|
| 463 | $juliano= -1 * floor(7 * (floor(($mes + 9) / 12) + $anno) / 4); |
|---|
| 464 | $S = 1; |
|---|
| 465 | if (($mes - 9)<0) $S=-1; |
|---|
| 466 | $A = abs($mes - 9); |
|---|
| 467 | $auxjuliano = floor($anno + $S * floor($A / 7)); |
|---|
| 468 | $auxjuliano = -1 * floor((floor($auxjuliano / 100) + 1) * 3 / 4); |
|---|
| 469 | $juliano = $juliano + floor(275 * $mes / 9) + $dia + ($GGG * $auxjuliano); |
|---|
| 470 | $juliano =$juliano + 1721027 + 2 * $GGG + 367 * $anno - 0.5; |
|---|
| 471 | return(floor($juliano)); |
|---|
| 472 | } |
|---|
| 473 | } // End of Calendar class |
|---|