<?php
abstract class Event_Handler{
function dbconn(){
$link_id =mysql_connect( "localhost" , "root" , "root" );
mysql_select_db( "mytest" , $link_id );
mysql_query( "set names utf8" , $link_id );
return $link_id ;
}
abstract function handled_event();
abstract function secure_handler();
}
class Handler_View extends Event_Handler{
private $handle ;
function __construct( $event_handle ){
$this ->handle= $event_handle ;
}
function handled_event(){
echo "The event, $this ->handle, is now handled.<br>
It is ,I promise!<br><br>
Your records are as follows:<br><br>";
$id =parent::dbconn();
$result =mysql_query( "select * from table01" , $id );
while ( $row =mysql_fetch_array( $result )){
echo "Numbers:" . $row [ 'number' ]. "\tName:" . $row [ 'name' ]. "<br>" ;
}
}
function secure_handler(){
if ( $_SESSION [ 'name' ]== "Wangzy" ){
$this ->handled_event();
} else {
echo "Sorry {$_SESSION['name']} you are not authorized!" ;
}
}
}
class Handler_Edit extends Event_Handler{
private $handle ;
function __construct( $event_handle ){
$this ->handle= $event_handle ;
}
function handled_event(){
echo "This is event $this->handle, which is now handled -no kidding!<br>" ;
}
function secure_handler(){
$this ->handled_event();
}
}
|