[ Поиск ] - [ Пользователи ] - [ Календарь ]
Полная Версия: Посмотрите на код, так можно делать или нет
Markus111
interface Observer { 
function handleEvent($obj,$n,$name);
}

class Cache implements Observer {

public function handleEvent($obj,$n,$name) {
if($obj instanceof Content) {
$this->clear($n,$name);
}
}


public function clear($n,$name) {
if($n==1){
$date=date('Y-m-d G:i:s');
$source = $name."|".$date."| 1\r\n";
$file = "file.txt";
$Saved_File = fopen($file, 'a+');
fwrite($Saved_File, $source);
fclose($Saved_File);
}
if($n==0){
$date=date('Y-m-d G:i:s');
$source = $name."|".$date."| 0\r\n";
$file = "file.txt";
$Saved_File = fopen($file, 'a+');
fwrite($Saved_File, $source);
fclose($Saved_File);
}
}
}

class CacheBD extends DB implements Observer {

public function handleEvent($obj,$n,$name) {
if($obj instanceof Content) {
$this->clear($n,$name);
}
}


public function clear($n,$name) {
$conn=self::getInstance()->bd();

if($n==1){
$date=date('Y-m-d G:i:s');
$result="INSERT INTO activation (name,date,act) VALUES ('$name','$date','1')";
$snm=$conn->query($result);
}

if($n==0){
$date=date('Y-m-d G:i:s');
$result="INSERT INTO activation (name,date,act) VALUES ('$name','$date','0')";
$snm=$conn->query($result);
}
}
}

class Content extends DB{
protected $n;
protected $name;
private $observers = array();

public function addObserver(Observer $obj) {
$this->observers[] = $obj;
}

public function removeObserver(Observer $obj) {
$newObservers = array();
foreach ($this->observers as $obs) {
if ($obj !== $obs) {
$newObservers[] = $obs;
}
}

$this->observers = $newObservers;
}

public function notifyObservers() {
foreach($this->observers as $obj) {
$obj->handleEvent($this,$this->n,$this->name);
}
}


public function change() {
if(isset($_POST['name']) && $_POST['name']!='' && isset($_POST['pass']) && $_POST['pass']!=''){

$strEmailAddress=mysql_escape_string(stripslashes(trim(strip_tags($_POST['name']))));;
$pass=mysql_escape_string(stripslashes(trim(strip_tags($_POST['pass']))));;

$this->strNam = $strEmailAddress;
$conn=self::getInstance()->bd();
$result="SELECT name FROM user where name='$strEmailAddress' and pass='$pass'";
$snm=$conn->query($result);
$myrow=$snm->fetch(PDO::FETCH_ASSOC);
if($myrow==true){
echo '1';
$this->name=$strEmailAddress;
$this->n=1;}
else{
echo '0';
$this->name=$strEmailAddress;
$this->n=0;}
$this->notifyObservers();
}

}
}


$content = new Content;
$content->addObserver(new Cache());
$content->addObserver(new CacheBD());
$content->change();


_____________
Womans in your town
Быстрый ответ:

 Графические смайлики |  Показывать подпись
Здесь расположена полная версия этой страницы.
Invision Power Board © 2001-2025 Invision Power Services, Inc.