Advertisement
NinjonikSVK

Vytváranie InfoPanelu v PHP #3_1

May 30th, 2020
827
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.22 KB | None | 0 0
  1. // addticket
  2. if(isset($_POST["submit"])){
  3.     $title = $_POST["title"];
  4.     $msg = $_POST["msg"];
  5.     $admin = $_POST["admin"];
  6.     $author = $_SESSION['username'];
  7.     $date = time();
  8.  
  9.     $idget = insertDB("tickets", "title,status,admin,time,creator", "'".$title."', 1, '".$admin."', '".$date."', '".$author."'");
  10.     $msgi = insertDB("ticketr", "msg,user,time,tID,type", "'".$msg."', '".$author."', '".$date."', '".$idget."', 0");
  11.  
  12.  
  13.     header("Location: tickets?action=ticketcreated");
  14.   }
  15.  
  16. // funkcie
  17.  
  18. function getfromDBw($data, $table, $where, $what) {
  19.     global $db;
  20.  
  21.     $stmt = $db->prepare('SELECT '.$data.' FROM '.$table.' WHERE '.$where.'='.$what.'');
  22.     $stmt->execute(array());
  23.     $row = $stmt->fetch(PDO::FETCH_ASSOC);
  24.  
  25.     if (!$stmt->execute()) {
  26.         print_r($stmt->errorInfo());
  27.     }
  28.  
  29.     while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
  30.         return $row;
  31.     }
  32.  
  33.     // $row = getfromDBw("pageID, pageTitle", "pages", "pageID", $id);
  34.  
  35. }
  36.  
  37. function getperm($perm) {
  38.     global $db;
  39.     global $usergroupID;
  40.  
  41.     $stmtg = $db->prepare('SELECT '.$perm.' FROM groups WHERE id="'.$usergroupID.'"');
  42.     $stmtg->execute(array());
  43.     $rowg = $stmtg->fetch(PDO::FETCH_ASSOC);
  44.  
  45.     if (!$stmtg->execute()) {
  46.         print_r($stmtg->errorInfo());
  47.     }
  48.  
  49.     while ($rowg = $stmtg->fetch(PDO::FETCH_ASSOC)) {
  50.         return $rowg;
  51.     }
  52.  
  53.     // $row = getfromDBw("pageID, pageTitle", "pages", "pageID", $id);
  54.  
  55. }
  56.  
  57. function insertDB($table, $data, $values2) {
  58.     global $db;
  59.  
  60.     $stmt = $db->prepare('INSERT INTO '.$table.' ('.$data.') VALUES ('.$values2.')');
  61.     $stmt->execute(array());
  62.     $idget = $db->lastInsertId();
  63.     return $idget;
  64.  
  65. }
  66.  
  67. function updateDB($table, $values, $where) {
  68.     global $db;
  69.  
  70.     $stmt = $db->prepare('UPDATE '.$table.' SET '.$values.' WHERE '.$where.'');
  71.     $stmt->execute(array());
  72.  
  73.     // $row = getfromDBw("pageID, pageTitle", "pages", "pageID", $id);
  74.  
  75. }
  76.  
  77. // atickets.php
  78.  
  79.     $stmt = $db->prepare('SELECT * FROM tickets ORDER BY time DESC');
  80.     $stmt->execute(array());
  81.     $row = $stmt->fetch(PDO::FETCH_ASSOC);
  82.  
  83.     if (!$stmt->execute()) {
  84.         print_r($stmt->errorInfo());
  85.     }
  86.  
  87. while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
  88.  
  89.                         $date = date("d.m.Y H:i", $row["time"]);
  90.  
  91.                         if ($row["status"] == '1'){
  92.                           $status = '<a href="editticket?id='.$row["id"].'"><button type="button" class="btn btn-block btn-success btn-xs">Otvorený</button></a>';
  93.                         }
  94.                         else if ($row["status"]== '2'){
  95.                           $status = '<a href="editticket?id='.$row["id"].'"><button type="button" class="btn btn-block btn-default btn-xs">Rieši sa...</button></a>';
  96.                         }
  97.                         else if ($row["status"] == '3'){
  98.                           $status = '<a href="editticket?id='.$row["id"].'"><button type="button" class="btn btn-block btn-danger btn-xs">Uzavretý</button></a>';
  99.                         }
  100.                         else if ($row["status"] == '4'){
  101.                           $status = '<a href="editticket?id='.$row["id"].'"><button type="button" class="btn btn-block btn-warning btn-xs">Odložený</button></a>';
  102.                         }
  103.                         else {
  104.                           $status = '<span class="label label-danger">Chyba!</span>';
  105.                         }
  106.  
  107.                         echo '
  108.                          <tr>
  109.                            <td>'.$row["id"].'</td>
  110.                            <td>'.$row["title"].'</td>
  111.                            <td>'.$status.'</td>
  112.                            <td>'.$row["admin"].'</td>
  113.                            <td>'.$row["creator"].'</td>
  114.                            <td>'.$date.'</td>
  115.                          </tr>
  116.                          ';
  117.                       }
  118.                       ?>
  119.  
  120. // SQL
  121.  
  122. CREATE TABLE `ticketr` (
  123.   `id` int(11) NOT NULL,
  124.   `msg` text,
  125.   `user` text,
  126.   `time` int(11) DEFAULT NULL,
  127.   `tID` int(11) DEFAULT NULL,
  128.   `type` int(11) DEFAULT NULL
  129. ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
  130.  
  131. CREATE TABLE `tickets` (
  132.   `id` int(11) NOT NULL,
  133.   `title` varchar(255) DEFAULT NULL,
  134.   `status` int(11) DEFAULT NULL,
  135.   `admin` text,
  136.   `time` int(11) DEFAULT NULL,
  137.   `creator` text
  138. ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement