Advertisement
rekamil97

function.php

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