Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DATABASE.CLASS.PHP
- ------------------------------------------------------------------------------------------------------------------------------------------------------------
- <?php
- class Database{
- public $db_server = "localhost";
- public $db_user = "jan";
- public $db_passwd = "366271";
- public $db_name = "mcmsv2";
- protected $connection;
- protected $query_string;
- public $qexe;
- public $controlled = array();
- public $url;
- public $control_sql_string;
- public $dbselection;
- public $page_privacy;
- public function __construct(){
- session_start();
- $this->connection = MySQL_Connect($this->db_server, $this->db_user, $this->db_passwd) or die(MySQL_Error());
- MySQL_Select_Db($this->db_name) or die(MySQL_Error());
- }
- public function __destruct(){
- $close = MySQL_Close($this->connection) or die(MySQL_Error());
- }
- public function SimpleQuery($query_string){
- $this->query_string = $query_string;
- return $this->qexe = Mysql_Query($this->query_string) or die(MySQL_Error());
- }
- public function sysMenu(){
- $this->SimpleQuery("SELECT * FROM pages");
- while($menu = MySQL_Fetch_Array($this->qexe)){
- echo "<a href='index.php?page=".HtmlSpecialChars($menu['page_keywords'])."'>".HtmlSpecialChars($menu['page_title'])."</a>";
- }
- }
- public function writePage($url, $control_sql_string, $dbselection){
- $this->url = $url;
- $this->control_sql_string = $control_sql_string;
- $this->dbselection = $dbselection;
- if(isset($_GET['page'])){
- $control = $this->controlPage();
- if($control != 1){
- ob_start();
- header("Location: na.php");
- }
- else{
- $page = $_GET['page'];
- $this->SimpleQuery("SELECT * FROM pages WHERE page_keywords='$page'");
- $content = MySQL_Fetch_Row($this->qexe);
- echo $type = $_SESSION['type'] = $content[5];
- switch($type){
- case 0:
- $this->page_privacy = $content[4];
- echo "<br><br>".$content[3];
- //echo $this->page_privacy = $content[4];
- echo "<b>".$content[4]."</b>";
- break;
- case 1:
- if(!isset($_GET[article])){$this->writeArticleList();}
- else{
- $this->writeArticlePage("article", "SELECT * FROM articles", "article_keywords");
- }
- }
- }
- }
- }
- public function writeArticleList(){
- $page = $_GET['page'];
- $this->SimpleQuery("SELECT * FROM articles WHERE page_ident='$page'");
- while($ArticlesList = MySQL_Fetch_Array($this->qexe)){
- echo "<br><br><a href='index.php?page=".$page."&article=".$ArticlesList['article_keywords']."'>".$ArticlesList['article_title']."</a>";
- }
- }
- public function writeArticlePage($url, $control_sql_string, $dbselection){
- $this->url = $url;
- $this->control_sql_string = $control_sql_string;
- $this->dbselection = $dbselection;
- if(isset($_GET['article'])){
- $control = $this->controlPage();
- if($control != 1){
- ob_start();
- header("Location: na.php");
- }
- else{
- $page = $_GET['article'];
- $this->SimpleQuery("SELECT * FROM articles WHERE article_keywords='$page'");
- $content = MySQL_Fetch_Row($this->qexe);
- echo "<br><br>".$content[3];
- }
- }
- }
- public function controlPageOutput(){
- // echo "xxx>". $this->control_sql_string;
- $this->SimpleQuery($this->control_sql_string);
- while($item = MySQL_Fetch_Array($this->qexe)){
- array_push($this->controlled, $item[$this->dbselection]);
- }
- }
- public function controlPage(){
- if(!empty($_GET[$this->url])){
- $this->controlPageOutput();
- //var_dump($this->controlled);
- $page = $_GET[$this->url];
- if(in_array($page, $this->controlled)){
- return 1;
- }
- else{
- return 0;
- }
- }
- }
- }
- ?>
- UserI.CLASS.PHP
- ------------------------------------------------------------------------------------------------------------------------------------------------------------
- <?php
- class UserIclass {
- public $createDB;
- public $username;
- public $passwd;
- public function __construct(){
- require_once 'Database.class.php';
- $createDB = new Database();
- }
- private function writeForm(){
- echo "<form method='POST' action='#'>
- Username:<input type='text' name='username'>
- Password:<input type='text' name='passwd'>
- <input type='submit' value='Login'>
- </form>";
- $this->username = $_POST['username'];
- $this->passwd = md5($_POST['passwd']);
- }
- private function Logout(){
- if($_SESSION[log] == TRUE){
- echo "<a href='index.php?logout=true'>Logout</a>";
- if(isset($_GET[logout])){
- if($_GET[logout] == TRUE){
- session_destroy();
- }
- }
- }
- }
- public function writeProfile(){
- //vypise profil uzivatela
- }
- // domysliet...
- public function Login(){
- require_once 'Database.class.php';
- $createDB = new Database();
- echo ">>><b>".$createDB->page_privacy."</b>";
- if($createDB->page_privacy == 1){
- if($_SESSION[log] != TRUE){
- $this->writeForm();
- $createDB->SimpleQuery("SELECT * FROM users WHERE username='$this->username' AND passwd='$this->passwd'");
- $num_rows = MySQL_Num_Rows($createDB->qexe) or die(MySQL_Error());
- if($num_rows == 1){
- $_SESSION['log'] = TRUE;
- if($_SESSION['log'] == TRUE){
- $createDB->writePage("page", "SELECT * FROM pages", "page_keywords");
- }
- }
- else{
- echo "Invalid username or password";
- }
- }
- $this->Logout();
- $createDB->writePage("page", "SELECT * FROM pages", "page_keywords");
- }
- elseif($createDB->page_privacy == 0){
- $createDB->writePage("page", "SELECT * FROM pages", "page_keywords");
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement