Ciao a tutti
Ho creato una classe che usa Calendar preso da PEAR....e ottempera ottimamente al suo scopo.....ma provando poi ad implementare un avanzamento di mese rimango bloccato....
Il problema e' sicuramente nella classe scritta da me....ma nn so dove sbattere la testa.
vi posto il codice della CLASSE :
Codice PHP:
<?php require_once '../class_db_gest.php'; require_once 'Calendar/Month/Weekdays.php'; class scadenzario { private $_link_id; private $_anno; private $_mese; private $_mese_p = array("1"=>"Gennaio","Febbraio","Marzo","Aprile","Maggio","Giugno","Luglio","Agosto","Settembre","Ottobre","Novembre","Dicembre"); private $_PHP_SELF; //costruttore che crea la connessione al db attraverso la classe richiesta //e setta la data pasata come argomento public function __construct($anno, $mese) { $obj_db = new db_gest(); $this->_link_id = $obj_db->connect('mysql','scadenzario'); $this->_PHP_SELF = $_SERVER['PHP_SELF']; $this->_anno = $anno; $this->_mese = $mese; } //ID_SCADENZE: questa funzione crea un array che contiene array associativi della tabella 'scadenze' // in modo tale da poter estrarre solo la colonna-risultato desiderata in maniera abbastanza // intuitiva. //Accetta come argomento l'oggetto $object->ThisDay restituito dalle classi Calendar/PEAR private function id_scadenze($thisDay) { #echo $thisDay; $query = "SELECT * from dbo_scadenze where data = '".$this->_anno; if($this->_mese <= 9) { $query .= "-0".$this->_mese; }else{ $query .= "-".$this->_mese; } if($thisDay <= 9){ $query .= "-0".$thisDay." 00:00:00'"; }else{ $query .= "-".$thisDay." 00:00:00'"; } #echo $query; $res = mysql_query($query,$this->_link_id); if(!$res) echo ""; $dati = array(); for($x=0; $x<mysql_num_rows($res); $x++) { mysql_data_seek($res,$x); $dato = mysql_fetch_assoc($res); $dati[] = $dato; } return $dati; } //CREA_CAL_SCAD: questa funzione crea 1 calendario con al suo interno i dati delle scadenze fiscali // contenute nel database. //Usa un file CSS esterno. Vedi file CSS per info. //Accetta come argomenti l'anno ed il mese. public function crea_cal_scad()#($anno,$mesi) { #$this->_anno = $anno; #$this->_mese = $mesi; $mesi = $this->_mese; #echo "<style> @import url(stile.css) </style>"; $mese = new Calendar_Month_Weekdays($this->_anno, $this->_mese); $mese->build(); echo #"<div class='main_content1'> "<div align='center'><table border='1' celpadding='2'> <tr> <td><input type='submit' name='indietro' value='<<'></td> <td class='calCell calCellEmpty' colspan='3'>[b]".$this->_mese_p[$mesi]."[/b]</td> <td><input type='submit' name='avanti' value='>>'></td> </tr></div> <table border='1'> <th>Lunedi</th> <th>Martedi</th> <th>Mercoledi</th> <th>Giovedi</th> <th>Venerdi</th> <th>Sabato</th> <th>Domenica</th>"; while($giorni = $mese->fetch()) { if($giorni->isFirst()){ echo "<tr>"; } if($giorni->isEmpty()){ echo "<td></td>"; } else{ echo "<td><div class='dayNumber'>".$giorni->thisDay()."</div>"; $id_scad = $this->id_scadenze($giorni->thisDay()); for($y=0; $y<count($id_scad); $y++) { $titolo = $this->title_scad($id_scad[$y]['ID']); echo "[*][url='$this->_PHP_SELF?action=visualizza&scad=".$id_scad[$y][']".$id_scad[$y]['ID']."[/url]"; } echo "\n</td>"; } if($giorni->isLast()) { echo "</tr>"; } } echo "</table></div></table>"; } //VISUALIZZA_SCAD: questa funzione riceve l'id della scadenza e ne estare tutte le info a riguardo // stampandole in una gradevole formattazione a tabella.Si noti che l risultato e' // un array multidimensionale normale. //Accetta come argomento l'id della scadenza. public function visualizza_scad($id_scad) { $query = "SELECT * from dbo_scadenze where ID = '".$id_scad."'"; $res = mysql_query($query, $this->_link_id); if(!$res) die("Problemi nella ricerca database"); $dati = array(); for($x=0; $x<mysql_num_rows($res); $x++) { mysql_data_seek($res,$x); $dato = mysql_fetch_array($res); $dati[] = $dato; } echo "<table border='1'> <th>Data</th> <th>Operatiune</th> <th>Tipul</th> <th>Model</th> <th>Articole</th> <th>Legi</th> <th>CF</th> <th>CPF</th> "; for($z=0; $z<count($dati); $z++) { echo "<tr>;"; for($y=1; $y<count($dati[$z]); $y++) { echo "<td>[url='$PHP_SELF?action=visualizza&id=".$dati[$z][$y]."']".$dati[$z][$y]."[/url]</td>"; } } } //TITLE_SCAD: questa funzione restituisce dinamicamente tutti i titoli delle scadanze in formato array[0] private function title_scad($scad) { $query = "SELECT tipul from dbo_scadenze where ID ='$scad'"; $res = mysql_query($query, $this->_link_id); if(!$res) die("Errore title_scad"); $titolo = mysql_fetch_row($res); return $titolo; } public function mese_avanti() { echo $this->_mese."-".$this->_anno."
"; $this->_mese = $this->_mese +1; if($this->_mese > 12) { $this->_anno = $this->_anno +1; $this->_mese = 1; echo $this->_mese."-".$this->_anno."
"; $this->__construct($this->_anno,$this->_mese); $this->crea_cal_scad($this->_anno, $this->_mese); }else{ echo $this->_mese."-".$this->_anno."
"; $this->crea_cal_scad($this->_anno, $this->_mese); } } public function mese_indietro() { echo $this->_mese."-".$this->_anno."
"; $this->_mese = $this->_mese -1; if($this->_mese < 1){ $this->_anno = $this->_anno -1; $this->_mese = 12; echo $this->_mese."-".$this->_anno."
"; $this->crea_cal_scad($this->_anno, $this->_mese); }else{ echo $this->_mese."-".$this->_anno."
"; $this->crea_cal_scad($this->_anno, $this->_mese); } } } ?>
E il codice della pagina che la sfrutta :
Codice PHP:
<?php require_once 'class_scadenzario.php'; $obj_scad = new scadenzario('2008',date('n')); ?> <html> <head> <style>@import url(stile.css)</style> </head> <body> <div class='header'> [img]logo.png[/img] </div> <div class='left'> <form method="post" target="pipps.php"> <button type="submit" name='home'>HOME</button>
<button type="submit" name='cal_fisc'>Calendario Fiscale</button> </form> </div> <?php echo "<form method='POST' action='pipps.php'>"; echo "<div class='mainContent'>"; if($_POST['avanti'] && $_POST['val']){ $obj_scad->mese_avanti(); } if(isset($_POST['indietro']) && $_POST['val']){ $obj_scad->mese_indietro(); } else{ $obj_scad->crea_cal_scad(); echo "<input type='hidden' name='val' value='true'>"; } echo "</div><form>"; ?> <div class='right'> <button type="submit">Agenda</button>
<button type="submit">Email</button>
<button type="submit">Rubrica</button> </div> <div class='footer'> Copyright Mottek corp. 2009 </body> </html>
Non riesco a far rimanere settata la variabile interna alla classe in modo che i metodi di avanzamento/recessione lavorino su di un dato appena cambiato.....Spero di essere stato chiaro.....
:master: