Location: PHPKode > scripts > PHP calendar with AJAX driven agenda > MyWeb20Agenda/MyWeb20Agenda/class/agenda.data.class.php
<?php
class SelectData
{
	private $dblogin;
	private $fields;
	private $tabname;
	private $data;	
	private $selective;
	private $standard;
	private $selectid;
	private $selectorder;
	private $goodnews;
	private $badnews;
	private $noquery;
	private $message;
	private $query;
	private $zeile;
	private $importance;
	private $status;
	private $deleteid;
	private $insertid;
	private $tbvalues;
	private $days;
	private $updateid;
 	private $updfieldid; 	
 	private $m;
 	private $y;
	
	function __construct($dblogin,$fields,$tabname,$data,$selective,$standard,
					$selectid,$selectorder,$goodnews,$badnews,$noquery,
					$message,$deleteid,$insertid,$tbvalues,$days,$updateid,
					$updfieldid,$m,$y)
	 {
	 	$this->dblogin		= $dblogin;
	 	$this->fields		= $fields;
	 	$this->tbname		= $tabname;
	 	$this->data		= $data;
	 	$this->selective	= $selective;
	 	$this->standard	= $standard;
	 	$this->selectid	= $selectid;
	 	$this->selectorder	= $selectorder;						
	 	$this->goodnews	= $goodnews;
	 	$this->badnews	= $badnews;
	 	$this->noquery	= $noquery;
	 	$this->message	= $message;
	 	$this->query		= $query;
	 	$this->zeile		= $zeile; 		
	 	$this->importance	= $importance;
	 	$this->status		= $status;
	 	$this->deleteid	= $deleteid;
	 	$this->insertid		= $insertid;
	 	$this->tbvalues	= $tbvalues;
	 	$this->days		= $days;
	 	$this->updateid	= $updateid;	 		
	 	$this->updfieldid	= $updfieldid;
	 	$this->m			= $m;	
	 	$this->y			= $y;	 	
	 }
	
	function showTable()
	{		
		require $this->dblogin;
		
		if($this->standard == 'simple')
		{
			if($this->selective != '')
			{
				$this->query = "SELECT ".$this->fields." 
							FROM ".$this->tbname." 
							WHERE $this->selective 
							ORDER by ".$this->selectorder." ";
				$this->data = mysql_query($this->query);
				if(!$this->data) die ($this->noquery);	
				while ($this->zeile = mysql_fetch_array($this->data, MYSQL_BOTH))
    				{
    					if($this->selectid != '')
    					{
    						if($this->zeile[importance] == '1')	{ $this->importance = "low"; };
    						if($this->zeile[importance] == '2')	{ $this->importance = "medium"; };
    						if($this->zeile[importance] == '3')	{ $this->importance = "high"; };
    						if($this->zeile[status] == '1')	{ $this->status = "free"; };
    						if($this->zeile[status] == '2')	{ $this->status = "booked"; };
						if($this->zeile[status] == '3')	{ $this->status = "maybe"; };
						if($this->zeile[status] == '4')	{ $this->status = "out"; };
						if($this->zeile[status] == '5')	{ $this->status = "done"; };
						$starttime = substr(utf8_encode($this->zeile[starttime]), 0,5);
						$endtime = substr(utf8_encode($this->zeile[endtime]), 0,5);
    							
    						echo "<tr>";
    						echo "<td class=\"tdad\" nowrap>".utf8_encode($this->zeile[dates])."<br/>
    													Start: $starttime<br/>
    													End: $endtime</td>";
    						echo "<td class=\"tda\">".utf8_encode($this->zeile[task])."</td>";
    						echo "<td class=\"tda\">".utf8_encode($this->zeile[lokation])."</td>";
    						echo "<td class=\"tda\">".utf8_encode($this->importance)."</td>";
    						echo "<td class=\"tda\">".utf8_encode($this->status)."</td>";
    						echo "<td class=\"tda\">".utf8_encode($this->zeile[date_id])."</td>";
    						echo "</tr>";
    						echo "<tr>
							<td class=\"matchtd\" colspan=\"6\">To do&nbsp;<span class=\"chdel\"><a href=\"#\" onClick=\"updateAgendaForm(".utf8_encode($this->days).",".utf8_encode($this->zeile[date_id]).",".$this->m.",".$this->y.");\">change</a>&nbsp;/&nbsp;<a href=\"#\" onClick=\"deleteAgendaEntry(".utf8_encode($this->zeile[date_id]).",".$this->y.",".$this->m.");\">delete</a></span></td>
						</tr>";
						echo"<tr>
							<td class=\"tdtd\" colspan=\"6\">".utf8_encode($this->zeile[todo])."</td>
						</tr>";
						echo"<tr>
							<td colspan=\"6\" height=\"2\">&nbsp;</td>
						</tr>";
    					}								
				}	
			}
			else
			{
				$this->message = $this->badnews;
				echo $this->message;		
			}
    		}
    	}
    	
    	function DeleteRow()
 	{
 		require $this->dblogin; 	
		if($this->deleteid != '')		
		{
			$this->query = "DELETE FROM ".$this->tbname." 
					WHERE ".$this->fields." = $this->deleteid ";
			mysql_query($this->query);		
			if(mysql_affected_rows() > 0)
			{
				$this->message = $this->goodnews;
				return $this->message;
			}
			else
			{
				$this->message = $this->badnews;
				return $this->message;
			}
		}
	}
	
	function FillTable()
 	{
 		require $this->dblogin;
 		
		 if($this->insertid == '1')		
		{		
			$this->query = "INSERT INTO ".$this->tbname." (".$this->fields.") 
							VALUES (".$this->tbvalues.")";
			mysql_query($this->query);
			if(mysql_affected_rows() > 0)
			{
				$this->message = $this->goodnews;
				return $this->message;
			}
			else
			{
				$this->message = $this->badnews;
				return $this->message;
			}			
		}
	}
		
	function ChangeTable()
 	{ 		
 		require $this->dblogin; 
 				
		if($this->standard == 'simple')		
		{
			$this->query = "UPDATE ".$this->tbname." 
						SET ".$this->fields." 
						WHERE $this->updfieldid = ".$this->updateid." ";
			mysql_query($this->query);	
			if(mysql_affected_rows() > 0)
			{
				$this->message = $this->goodnews; 	// Data has been changed
				return $this->message; 				
			}
			else
			{
				$this->message = $this->badnews; 	// Data has not been changed
				return $this->message;
			}
		}
	}		
	
}
 ?>
Return current item: PHP calendar with AJAX driven agenda