Advertisement
Guest User

Untitled

a guest
Jun 20th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.30 KB | None | 0 0
  1. DATABASE.CLASS.PHP
  2. ------------------------------------------------------------------------------------------------------------------------------------------------------------
  3. <?php
  4.  
  5. class Database{
  6.  
  7. public $db_server = "localhost";
  8. public $db_user = "jan";
  9. public $db_passwd = "366271";
  10. public $db_name = "mcmsv2";
  11. protected $connection;
  12. protected $query_string;
  13. public $qexe;
  14. public $controlled = array();
  15. public $url;
  16. public $control_sql_string;
  17. public $dbselection;
  18. public $page_privacy;
  19.  
  20. public function __construct(){
  21.     session_start();
  22.     $this->connection = MySQL_Connect($this->db_server, $this->db_user, $this->db_passwd) or die(MySQL_Error());
  23.     MySQL_Select_Db($this->db_name) or die(MySQL_Error());
  24.     }
  25.  
  26. public function __destruct(){
  27.     $close = MySQL_Close($this->connection) or die(MySQL_Error());
  28.     }
  29.  
  30. public function SimpleQuery($query_string){
  31.     $this->query_string = $query_string;
  32.         return $this->qexe = Mysql_Query($this->query_string) or die(MySQL_Error());
  33.     }
  34.  
  35. public function sysMenu(){
  36.     $this->SimpleQuery("SELECT * FROM pages");
  37.     while($menu = MySQL_Fetch_Array($this->qexe)){
  38.         echo "<a href='index.php?page=".HtmlSpecialChars($menu['page_keywords'])."'>".HtmlSpecialChars($menu['page_title'])."</a>";
  39.         }
  40.     }
  41.  
  42. public function writePage($url, $control_sql_string, $dbselection){
  43.    $this->url = $url;
  44.    $this->control_sql_string = $control_sql_string;
  45.    $this->dbselection = $dbselection;
  46.  
  47.    if(isset($_GET['page'])){
  48.     $control = $this->controlPage();
  49.     if($control != 1){
  50.        ob_start();
  51.         header("Location: na.php");
  52.     }
  53.     else{
  54.         $page = $_GET['page'];
  55.         $this->SimpleQuery("SELECT * FROM pages WHERE page_keywords='$page'");
  56.         $content = MySQL_Fetch_Row($this->qexe);
  57.         echo $type = $_SESSION['type'] = $content[5];
  58.  
  59.         switch($type){
  60.             case 0:
  61.                 $this->page_privacy = $content[4];
  62.                 echo "<br><br>".$content[3];
  63.                //echo $this->page_privacy = $content[4];
  64.                  echo "<b>".$content[4]."</b>";
  65.             break;
  66.  
  67.             case 1:
  68.                 if(!isset($_GET[article])){$this->writeArticleList();}
  69.                 else{
  70.                 $this->writeArticlePage("article", "SELECT * FROM articles", "article_keywords");
  71.                 }
  72.  
  73.         }
  74.  
  75.        
  76.     }
  77.   }
  78. }
  79.  
  80. public function writeArticleList(){
  81.     $page = $_GET['page'];
  82.     $this->SimpleQuery("SELECT * FROM articles WHERE page_ident='$page'");
  83.     while($ArticlesList = MySQL_Fetch_Array($this->qexe)){
  84.         echo "<br><br><a href='index.php?page=".$page."&article=".$ArticlesList['article_keywords']."'>".$ArticlesList['article_title']."</a>";
  85.     }
  86.    
  87. }
  88.  
  89. public function writeArticlePage($url, $control_sql_string, $dbselection){
  90.    $this->url = $url;
  91.    $this->control_sql_string = $control_sql_string;
  92.    $this->dbselection = $dbselection;
  93.  
  94.    if(isset($_GET['article'])){
  95.     $control = $this->controlPage();
  96.     if($control != 1){
  97.        ob_start();
  98.         header("Location: na.php");
  99.     }
  100.     else{
  101.         $page = $_GET['article'];
  102.         $this->SimpleQuery("SELECT * FROM articles WHERE article_keywords='$page'");
  103.         $content = MySQL_Fetch_Row($this->qexe);
  104.         echo "<br><br>".$content[3];
  105.     }
  106.   }
  107. }
  108.  
  109. public function controlPageOutput(){
  110.    // echo "xxx>". $this->control_sql_string;
  111.     $this->SimpleQuery($this->control_sql_string);
  112.     while($item = MySQL_Fetch_Array($this->qexe)){
  113.         array_push($this->controlled, $item[$this->dbselection]);
  114.         }
  115. }
  116.  
  117. public function controlPage(){
  118.  
  119.     if(!empty($_GET[$this->url])){
  120.         $this->controlPageOutput();
  121.         //var_dump($this->controlled);
  122.         $page = $_GET[$this->url];
  123.         if(in_array($page, $this->controlled)){
  124.             return 1;
  125.         }
  126.         else{
  127.             return 0;
  128.          }
  129.         }
  130.        }
  131.  
  132.  
  133.  
  134.     }
  135.  
  136.  
  137. ?>
  138.  
  139. UserI.CLASS.PHP
  140. ------------------------------------------------------------------------------------------------------------------------------------------------------------
  141.  
  142. <?php
  143.  
  144. class UserIclass {
  145.  
  146. public $createDB;
  147. public $username;
  148. public $passwd;
  149.  
  150.     public function __construct(){
  151.         require_once 'Database.class.php';
  152.         $createDB = new Database();
  153.     }
  154.  
  155.  
  156.     private function writeForm(){
  157.             echo "<form method='POST' action='#'>
  158.                  Username:<input type='text' name='username'>
  159.                  Password:<input type='text' name='passwd'>
  160.                           <input type='submit' value='Login'>
  161.                  </form>";
  162.             $this->username = $_POST['username'];
  163.             $this->passwd = md5($_POST['passwd']);
  164.     }
  165.  
  166.     private function Logout(){
  167.         if($_SESSION[log] == TRUE){
  168.             echo "<a href='index.php?logout=true'>Logout</a>";
  169.             if(isset($_GET[logout])){
  170.                 if($_GET[logout] == TRUE){
  171.                     session_destroy();
  172.  
  173.                 }
  174.             }
  175.         }
  176.     }
  177.  
  178.     public function writeProfile(){
  179.         //vypise profil uzivatela
  180.     }
  181.  
  182.     // domysliet...
  183.  
  184.     public function Login(){
  185.         require_once 'Database.class.php';
  186.             $createDB = new Database();
  187.             echo ">>><b>".$createDB->page_privacy."</b>";
  188.           if($createDB->page_privacy == 1){
  189.         if($_SESSION[log] != TRUE){
  190.            
  191.             $this->writeForm();
  192.             $createDB->SimpleQuery("SELECT * FROM users WHERE username='$this->username' AND passwd='$this->passwd'");
  193.             $num_rows = MySQL_Num_Rows($createDB->qexe) or die(MySQL_Error());
  194.             if($num_rows == 1){
  195.                 $_SESSION['log'] = TRUE;
  196.                 if($_SESSION['log'] == TRUE){
  197.                     $createDB->writePage("page", "SELECT * FROM pages", "page_keywords");
  198.                    
  199.                     }
  200.  
  201.                 }
  202.             else{
  203.                 echo "Invalid username or password";
  204.                 }
  205.             }
  206.             $this->Logout();
  207.             $createDB->writePage("page", "SELECT * FROM pages", "page_keywords");
  208.            
  209.  
  210.           }
  211.           elseif($createDB->page_privacy == 0){
  212.               $createDB->writePage("page", "SELECT * FROM pages", "page_keywords");
  213.           }
  214.          
  215.     }
  216. }
  217. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement