Don't like ads? PRO users don't see any ads ;-)
Guest

Core Class

By: gromanazzi on Apr 29th, 2012  |  syntax: PHP  |  size: 2.16 KB  |  hits: 51  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.  
  3. require('app/login.class.php');
  4.  
  5. class Application {
  6.    
  7.     private $userId;
  8.     private $userEmail;
  9.     private $userName;
  10.     private $logged;
  11.    
  12.     public function __construct(){
  13.     }
  14.    
  15.     private function openHtml(){
  16.         echo '<!DOCTYPE html>
  17.              <html>
  18.                  <head>
  19.                      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  20.                      <title></title>
  21.                      <link type="text/css" rel="stylesheet" href="style.css" />
  22.                  </head>
  23.                  <body>';
  24.     }
  25.    
  26.     private function closeHtml(){
  27.         echo '    </body>
  28.              </html>';
  29.     }
  30.    
  31.     public function run(){
  32.        
  33.         $login = new Login();
  34.        
  35.         $this->openHtml();        
  36.                
  37.         if($this->logged){
  38.             if(isset($_GET['a'])){
  39.                 if($_GET['a'] == 'logout')
  40.                     $login->logout();
  41.             }
  42.             else{
  43.                 //Go to application
  44.             }
  45.                
  46.         }            
  47.         else{
  48.             if(!isset($_GET['a']))
  49.                 $login::showForm();
  50.             else if($_GET['a'] == 'login'){
  51.                 if($login->autenticate($_POST['email'], $_POST['password'])){
  52.                     $this->logged = true;
  53.                     $this->userId = $login->getUserId();
  54.                     $this->userEmail = $login->getUserEmail();
  55.                     $this->userName = $login->getUserName();
  56.                 }
  57.                 else
  58.                     $this->logged = false;
  59.                 header('location: ./');
  60.             }
  61.         }
  62.        
  63.         $this->closeHtml();
  64.     }
  65.    
  66.     public function viewUserName(){
  67.         echo $this->user;
  68.     }
  69.    
  70.     public static function saveHistance($object){
  71.         $_SESSION['mainHistance'] = base64_encode(serialize($object)); //Crypted in next version
  72.     }
  73.    
  74.     public static function loadHistance(){
  75.         return unserialize(base64_decode($_SESSION['mainHistance']));
  76.     }
  77.    
  78.     public function showStatus(){
  79.         echo $this->logged;
  80.     }
  81.    
  82. }
  83.  
  84. ?>