Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if(defined('cms')) {
- // Zabezpieczenie przed nieuprawnionym dostępem
- /* class database {
- function __construct(){
- $db = new PDO('mysql:host=localhost;dbname=ncms','root','');
- $db->query ('SET NAMES utf8');
- }
- } */
- class system {
- var $html = 0;
- function html_set($text) {
- if($this->html == 0) {
- return htmlspecialchars($text);
- } elseif($this->html == 1) {
- return $text;
- }
- }
- function content($kolumna) { // Wyświetlanie danych o stronie
- global $db;
- if(isset($_GET['id']) && !is_array($_GET['id'])) {
- $id = $_GET['id'];
- } else {
- $id = 0;
- }
- $name = $db->prepare('SELECT name,opis,tresc FROM menu WHERE id=:id');
- $name->execute(array('id'=>$id));
- $count = $name->RowCount();
- if($count>0) {
- foreach($name as $name) {
- return htmlspecialchars($name[$kolumna]);
- }
- } else {
- $id1 = $db->query('SELECT name,opis,tresc FROM home WHERE id=1'); // "Tresc" zawsze pusta
- foreach($id1 as $id1) {
- return htmlspecialchars($id1[$kolumna]);
- }
- }
- }
- function sidebar() { // Wyświetlanie newsów na pasku bocznym
- global $db;
- $sidebar = $db->query('SELECT tytul,id FROM newsy ORDER BY id DESC LIMIT 5 ');
- $count = $sidebar->RowCount();
- if($count>0) {
- foreach($sidebar as $sidebar) {
- return '<span class="sidebar"><a href="index.php?post='.$sidebar['id'].'" class="sidebar">'.$sidebar['tytul'].'</a></span><br>';
- }
- } else {
- return '(Brak postów do wyświetlenia)';
- }
- }
- function newsy() { // Wyświetlanie newsów (sprawdzanie czy jesteśmy na stronie głównej)
- global $db;
- if(isset($_GET['id']) && !is_array($_GET['id'])) {
- $id = $_GET['id'];
- } else {
- $id = 0;
- }
- $name = $db->prepare('SELECT id FROM menu WHERE id=:id'); // Jeśli id jest prawidłowe funkcja zwróci jakąś wartość
- $name->execute(array('id'=>$id));
- $count = $name->RowCount(); // Funkcja zapisuje czy istnieje jakaś strona pod tym id
- if($count == 0) { // Sprawdzanie czy jesteśmy na stronie głównej (jeśli nie istnieje id w "GET" wartość = 0)
- $newsy = $db->query('SELECT * FROM newsy ORDER BY id DESC');
- $count_news = $newsy->RowCount();
- if($count_news>0) {
- echo 'Aktualności: ';
- foreach($newsy as $newsy) {
- 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>' ;
- }
- }
- }
- }
- }
- class admin {
- var $html = 0;
- function admin_check_password() { // Sprawdzanie hasła
- global $db;
- if(!isset($_SESSION['logowanie'])) $_SESSION['logowanie'] = 0;
- if($_SESSION['logowanie'] !== 1) {
- $name = $db->query('SELECT password FROM admin WHERE id=1');
- $password = $name->fetch();
- if(isset($_POST['password']) && $_POST['password'] == $password['password']) {
- $_SESSION['logowanie'] = 1;
- } else {
- $_SESSION['logowanie'] = 0;
- }
- }
- }
- function admin_menu_show() {
- global $db;
- if(isset($_GET['edit'])) {
- $name = $db->prepare('SELECT * FROM menu WHERE id=:id');
- $name->execute(array('id'=>$_GET['edit']));
- $count = $name->RowCount();
- if($count == 0) { // Sprawdzanie czy strona istnieje
- echo '<h2>Podana strona nie istnieje</h2>';
- } else {
- echo '<h2>Edytowanie strony:</h2>';
- foreach($name as $name) {
- }
- 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>';
- 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>';
- }
- } elseif(isset($_GET['add'])) {
- echo '<h2>Dodawanie strony</h2>' ;;
- // 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>';
- } else {
- echo '<h2>Pozycje w menu:</h2>';
- $menu = $db->query('SELECT id,name,opis FROM menu');
- foreach($menu as $menu) {
- 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> </div>';
- }
- echo '<a href="index.php?site=menu&add" class="edytuj">[Dodaj stronę]</a>';
- }
- }
- function admin_menu_add() {
- global $db;
- if(isset($_POST['name_edit']) && isset($_POST['opis_edit']) && !empty($_POST['name_edit']) && !empty($_POST['opis_edit'])) {
- $name = $db->prepare('UPDATE menu SET name=:name, opis=:opis WHERE id=:id');
- $name->execute(array('name'=>$_POST['name_edit'],'opis'=>$_POST['opis_edit'],'id'=>$_POST['id']));
- } elseif(isset($_POST['kasuj']) && $_POST['kasuj'] == "tak") {
- $name = $db->prepare('DELETE FROM menu WHERE id=:id');
- $name->execute(array('name'=>$_POST['name'],'opis'=>$_POST['opis'],'id'=>$_POST['id']));
- }
- }
- }
- } else {
- echo 'Error!';
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement