Advertisement
rekamil97

function.php

May 1st, 2015
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.61 KB | None | 0 0
  1. <?php
  2. if(defined('cms')) {
  3.  
  4.     // Zabezpieczenie przed nieuprawnionym dostępem
  5.  
  6.     class system {
  7.  
  8.     var $html = 0;
  9.  
  10.     function html_set($text) {
  11.    
  12.                 if($this->html == 0) {
  13.                         return htmlspecialchars($text);
  14.                 } elseif($this->html == 1) {
  15.                         return $text;
  16.                 }
  17.     }      
  18.  
  19.     function content($kolumna) { // Wyświetlanie danych o stronie
  20.                 global $db;
  21.  
  22.                 if(isset($_GET['id']) && !is_array($_GET['id'])) {
  23.                     $id = $_GET['id'];
  24.                 } else {
  25.                     $id = 0;
  26.                 }
  27.  
  28.                 $name = $db->prepare('SELECT name,opis,tresc FROM menu WHERE id=:id');
  29.                 $name->execute(array('id'=>$id));
  30.                 $count = $name->RowCount();
  31.  
  32.                 if($count>0) {
  33.                  foreach($name as $name) {
  34.                    echo(htmlspecialchars($name[$kolumna]));
  35.                  }
  36.                 } else {
  37.                     $id1 = $db->query('SELECT name,opis,tresc FROM home WHERE id=1'); // "Tresc" zawsze pusta
  38.                     foreach($id1 as $id1) {
  39.                     echo(htmlspecialchars($id1[$kolumna]));
  40.                  }
  41.                 }
  42.     }
  43.  
  44.     function sidebar() { // Wyświetlanie newsów na pasku bocznym
  45.                 global $db;
  46.  
  47.                 $sidebar = $db->query('SELECT tytul,id FROM newsy ORDER BY id DESC LIMIT 5 ');
  48.                 $count = $sidebar->RowCount();
  49.  
  50.                  if($count>0) {
  51.                  foreach($sidebar as $sidebar) {
  52.                    echo('<span class="sidebar"><a href="index.php?post='.$sidebar['id'].'" class="sidebar">'.$sidebar['tytul'].'</a></span><br>');
  53.                  }
  54.                 } else {
  55.                     echo('(Brak postów do wyświetlenia)');
  56.                  }
  57.     }
  58.  
  59.     function newsy() { // Wyświetlanie newsów (sprawdzanie czy jesteśmy na stronie głównej)
  60.                 global $db;
  61.  
  62.                 if(isset($_GET['id']) && !is_array($_GET['id'])) {
  63.                     $id = $_GET['id'];
  64.                 } else {
  65.                     $id = 0;
  66.                 }
  67.  
  68.                 $name = $db->prepare('SELECT id FROM menu WHERE id=:id'); // Jeśli id jest prawidłowe funkcja zwróci jakąś wartość
  69.                 $name->execute(array('id'=>$id));
  70.                 $count = $name->RowCount(); // Funkcja zapisuje czy istnieje jakaś strona pod tym id
  71.  
  72.                 if($count == 0) { // Sprawdzanie czy jesteśmy na stronie głównej (jeśli nie istnieje id w "GET" wartość = 0)
  73.  
  74.                     $newsy = $db->query('SELECT * FROM newsy ORDER BY id DESC');
  75.                     $count_news = $newsy->RowCount();
  76.  
  77.                     if($count_news>0) {
  78.                     echo('Aktualności: ');
  79.                     foreach($newsy as $newsy) {
  80.                        echo('<div id="news"><a href="index.php?post='.$newsy['id'].'" class="news"><h4>'.$newsy['tytul'].'</h4></a>'.$newsy['wprowadzenie'].'<p class="data">Dodano: '.$newsy['data'].'</p></div>');
  81.                      }
  82.                     }
  83.                 }    
  84.     }
  85.  
  86.     }
  87.  
  88.  
  89. class admin {
  90.  
  91.     var $html = 0;
  92.  
  93.     function admin_check_password() { // Sprawdzanie hasła
  94.                 global $db;
  95.  
  96.                 if(!isset($_SESSION['logowanie'])) $_SESSION['logowanie'] = 0;
  97.  
  98.                 if($_SESSION['logowanie'] !== 1) {
  99.                 $name = $db->query('SELECT password FROM admin WHERE id=1');
  100.                 $password = $name->fetch();
  101.                
  102.                 if(isset($_POST['password']) && $_POST['password'] == $password['password']) {
  103.                     $_SESSION['logowanie'] = 1;
  104.                 } else {
  105.                     $_SESSION['logowanie'] = 0;
  106.                 }
  107.             }
  108.     }
  109.  
  110.    
  111.     function admin_menu_show() {
  112.         global $db;
  113.  
  114.             if(isset($_GET['edit'])) {
  115.  
  116.                 $name = $db->prepare('SELECT * FROM menu WHERE id=:id');
  117.                 $name->execute(array('id'=>$_GET['edit']));
  118.                 $count = $name->RowCount();
  119.  
  120.                 if($count == 0) { // Sprawdzanie czy strona istnieje
  121.                     echo('<h2>Podana strona nie istnieje</h2>');
  122.                 } else {
  123.                     echo('<h2>Edytowanie strony:</h2>');
  124.  
  125.                     foreach($name as $name) {
  126.                     }
  127.  
  128.                     echo('<div id="news"><form method="post">Tytuł: <input type="text" name="name_edit" value="'.system::html_set($name['name']).'"></input><br><br>Opis: <input type="text" name="opis_edit" value="'.system::html_set($name['opis']).'"></input><br><br><input type="hidden" name="id" value='.system::html_set($name['id']).'></input><input type="submit" value="Edytuj"></form></div>');
  129.                     echo('<div id="news"><b>Kasowanie strony</b><br><br>Aby skasować stronę zaznacz "tak" i kliknij przycisk "SKASUJ"<form method="post">Tak: <input type="checkbox" name="kasuj" value="tak"></input><br><input type="submit" value="SKASUJ"></input><input type="hidden" name="id" value='.system::html_set($name['id']).'></input></form></div>');
  130.  
  131.                 }
  132.  
  133.             } elseif(isset($_GET['add'])) {
  134.                     echo('<h2>Dodawanie strony</h2>');;
  135.                     // echo('<div id="news"><form method="post">Tytuł: <input type="text" name="name_add"></input><br><br>Opis: <input type="text" name="opis_add>"</input><br><br><input type="submit" value="Dodaj"></input></form></div>');
  136.  
  137.  
  138.  
  139.             } else {
  140.  
  141.             echo('<h2>Pozycje w menu:</h2>');
  142.             $menu = $db->query('SELECT id,name,opis FROM menu');
  143.             foreach($menu as $menu) {
  144.                      echo('<div id="news"><span class="news"><h4>'.system::html_set($menu['name']).'</h4></span><h5 class="edytuj"><a href="index.php?site=menu&edit='.system::html_set($menu['id']).'" class="edytuj">[EDYTUJ]</a></h5><span class="opis">'.system::html_set($menu['opis']).'</span>&nbsp;</div>');
  145.              }
  146.  
  147.            
  148.  
  149.              echo('<a href="index.php?site=menu&add" class="edytuj">[Dodaj stronę]</a>');
  150.  
  151.             }
  152.  
  153.     }
  154.  
  155.     function admin_menu_add() {
  156.         global $db;
  157.  
  158.         if(isset($_POST['name_edit']) && isset($_POST['opis_edit']) && !empty($_POST['name_edit']) && !empty($_POST['opis_edit'])) {
  159.                 $name = $db->prepare('UPDATE menu SET name=:name, opis=:opis WHERE id=:id');
  160.                 $name->execute(array('name'=>$_POST['name_edit'],'opis'=>$_POST['opis_edit'],'id'=>$_POST['id']));
  161.         }  elseif(isset($_POST['kasuj']) && $_POST['kasuj'] == "tak") {
  162.                 $name = $db->prepare('DELETE FROM menu WHERE id=:id');
  163.                 $name->execute(array('name'=>$_POST['name'],'opis'=>$_POST['opis'],'id'=>$_POST['id']));
  164.         }
  165.     }
  166. }
  167.  
  168. } else {
  169.     echo('Error!');
  170. }
  171. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement