<mySearch ⁄>
<mySnippets order="rand" ⁄>
<myContacts ⁄><email ⁄>
<windows live messenger ⁄>
<myCurriculum type="pdf" ⁄>
<myBlog show="last" ⁄>
<myNews show="rand" ⁄>
<myNews type="cat" ⁄>
<myQuote order="random" ⁄>O homem não vive uma centena de anos, mas preocupa-se o suficiente para mil
<myPhoto order="random" ⁄>
<myAdSense ⁄>
<myVisitorsMap ⁄>
*{margin: 0;padding: 0;} body{ font-family: Tahoma, Verdana, Arial, sans-serif;font-size: 11px; color: #000;background: #fff;text-align: left;} table.message_box{ border: solid #235B74; border-width: 0 1px 1px 1px; width: 400px; text-align: justify; height: 120px; margin: 2px auto; } table.message_box th{ height: 24px; background: url( "../images/bg.gif" ) repeat-x top left; text-align: center; color: #fff; font-size: 13px; } table.message_box td{vertical-align: middle;} table.message_box td.msg{padding: 4px 8px;} table.message_box td.msg span.timestamp{ color: #666; text-decoration: underline; font-weight: 700; } table.message_box td.msg span.title{font-weight: 700; color: #666;} table.message_box td.error{ width: 80px; background: url( "../images/msg/error.png" ) no-repeat center center; } table.message_box td.ok{ width: 80px; background: url( "../images/msg/ok.png" ) no-repeat center center; } table.message_box td.info{ width: 80px; background: url( "../images/msg/info.png" ) no-repeat center center; } table.message_box td.protected{ width: 80px; background: url( "../images/msg/protected.png" ) no-repeat center center; }
<?php //class para automaticamente fazer o load das classes if(function_exists("__autoload")) return;{ function __autoload($class){ include_once("class.$class.php"); } } ?>
<?php class MyServerTime{ private $_format; //formatação DateTime /** * Método construtor * * @param String $format */ public function __construct($format){$this->Format($format);} /** * Getter/ Setter TimeFormat * * @param String $value * @return String */ public function Format($value=""){ if($value){$this->_format=$value;} else{return $this->_format;} } /** * Obter Data formatada * * @return DateTime */ function GetDate(){return gmdate($this->Format());} } ?>
<?php /** * Mapear tipos de erro para correspondente CSS * */ class MessageBoxType { private static $arrCss = array ("info" => "info", "error" => "error", "ok" => "ok", "protected" => "protected" ); public static function Error() {return self::$arrCss["error"];} public static function Ok() {return self::$arrCss["ok"];} public static function Info() {return self::$arrCss["info"];} public static function Protect() {return self::$arrCss["protected"];} } ?>
<?php /** * Class que vai armazenar as mensagens * */ class MessageBoxText { private $_arr; /** * Método construtor * * @param String Texto da mensagem * @param String Titulo da mensagem */ public function __construct($text="",$title="") { $this->_arr = array (); $this->AddMessage ($text, $title); } /** * Adicionar mensagem * * @param String Texto da mensagem * @param String Titulo da mensagem */ public function AddMessage($text,$title=""){ if($text){array_push ($this->_arr, array ($title => $text));} } /** * Obter mensagem * * @param Int Posição da mensagem * @return Array */ public function GetMessage($pos){return $this->_arr[$pos];} /** * Obter todas as Mensagens * * @param Int $pos * @return Array */ public function GetAllMessages(){return $this->_arr;} /** * Obter número de mensagens * * @return Int */ public function Count() {return sizeof ( $this->_arr );} /** * Remover todas as mensagens * */ public function Clear() {$this->_arr = array ();} } ?>
<?php /** * Class que permite exibir uma * mensagem customizável ao utilizador * */ class MessageBox { private $_msg; private $_msg_type; private $_title; private $_timestamp_format; /** * Método construtor * * @param MessageBoxText Mensagens * @param MessageBoxType Tipo * @param String Titulo * @param String Formato Timestamp */ public function __construct($msgs, $msg_type, $title, $timestamp_format = "Y-m-d H:m:s") { $this->SetMessages($msgs); $this->SetMessageType($msg_type); $this->SetTitle($title); $this->SetTimestampFormat($timestamp_format); } /** * Construir Mensagem * * @return String */ public function Show(){ //construir header, se activo if ($this->_title) {$row_header="<tr><th colspan='2'>{$this->_title}</th></tr>";} //construir timestamp, se activo if($this->_timestamp_format){ $timestamp=new MyServerTime($this->_timestamp_format); $timestamp="<span class='timestamp'>{$timestamp->GetDate()}</span><br/><br/>"; } //construir mensagens $count=$this->_msg->Count(); for ($i=0;$i<$count;$i++){ $auxArr=$this->_msg->GetMessage($i); foreach ($auxArr as $key => $value) { if($key) $messages.="<span class='title'>$key:</span> "; $messages.="$value<br/><br/>"; } } return " <table class='message_box' cellspacing='0' cellpadding='0'> $row_header <tr> <td class='$this->_msg_type'></td> <td class='msg'>$timestamp$messages</td> </tr> </table> "; } /** * Atribuir tipo de Mensagem * * @param MessageBoxType */ public function SetMessageType($msg_type){$this->_msg_type=$msg_type;} /** * Atribuir formato ao timestamp * * @param String */ public function SetTimestampFormat($timestamp_format){$this->_timestamp_format=$timestamp_format;} /** * Atribuir titulo * * @param String */ public function SetTitle($title){$this->_title=$title;} /** * Atribuir mensagens * * @param MessageBoxText */ public function SetMessages($msgs){ if (!($msgs instanceof MessageBoxText)) { throw new Exception ( "MessageBoxTextExpected" ); } $this->_msg=$msgs; } } ?>
<?php class MessageBoxVerbose extends MessageBox { public function __construct($intro,$title,$msg_type,$line,$file,$caller_function,$error_description=""){ $msgs=new MessageBoxText(); $msgs->AddMessage($intro); $msgs->AddMessage($line,"Linha"); $msgs->AddMessage($file,"Ficheiro"); $msgs->AddMessage($caller_function,"Função"); $msgs->AddMessage($error_description,"Erro"); parent::__construct($msgs,$msg_type,$title); return $this->Show(); } } ?>
<?php include_once ("Classes/AutoLoad.inc"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>MessageBox</title> <link rel="stylesheet" type="text/css" href="css/style.css" media="all" /> </head> <body> <?php /** * 1º exemplo */ $msgs = new MessageBoxText(); $msgs->AddMessage ("Isto é um teste simples à MessageBox" ); $box = new MessageBox ($msgs, MessageBoxType::Info(), "A testar a MessageBox",""); echo $box->Show (); /** * 2º exemplo */ $box->SetMessageType(MessageBoxType::Ok()); $box->SetTimestampFormat("H:m:s"); $box->SetTitle("MessageBox com Timestamp"); echo $box->Show(); /** * 3º exemplo */ //limpar mensagens de texto $msgs->Clear(); $msgs->AddMessage("As credenciais fornecidas não correspondem a uma conta válida","Erro Credenciais"); $box->SetMessageType(MessageBoxType::Protect()); echo $box->Show(); /** * 4º/ 5º exemplo */ GerarErrosMySQL(); function GerarErrosMySQL(){ $link=@mysql_connect("localhost","username","password"); if(!$link){ die(MySQLVerbose("Erro na ligação ao MySQL","Conexão MySQL",mysql_error(),__LINE__,__FILE__,__FUNCTION__)); } $db=@mysql_select_db("my_database",$link); if(!$db){ die(MySQLVerbose("Erro na selecção da BD","BD inválida",mysql_error(),__LINE__,__FILE__,__FUNCTION__)); } } /** * Função auxiliar para apresentar erros MySQL * * @param String Mensagem de introdução * @param String Titulo * @param String Descrição do erro * @return String */ function MySQLVerbose($intro,$title,$error_description,$line,$file,$function){ $verbose_box=new MessageBoxVerbose($intro,$title,MessageBoxType::Error(),$line,$file,$function,$error_description); return $verbose_box->Show(); } ?> </body> </html>


