Advertisement
Guest User

Untitled

a guest
Mar 13th, 2017
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.48 KB | None | 0 0
  1. <?php
  2.     /* Process data submitted by login form */
  3.     if (isset($_POST['login'])) {
  4.         $loggedIn = FALSE;
  5.         $loginError = FALSE;
  6.  
  7.         $username = $_POST['username'];
  8.         $password = $_POST['password'];
  9.  
  10.         if ($username != null || $password != null) {
  11.             $users_file_name = "db/users.txt";
  12.             $usernames_list = file($users_file_name);
  13.  
  14.             for ($i = 0; $i < sizeof($usernames_list); $i++) {
  15.  
  16.                 $users_list = array_map('trim', explode(',', $usernames_list[$i]));
  17.  
  18.                 if (($username === $users_list[0]) && ($password === $users_list[2])) {
  19.                     $loggedIn = TRUE;
  20.                     $loginError = FALSE;
  21.                     break;
  22.                 } else {
  23.                     $loggedIn = FALSE;
  24.                     $loginError = TRUE;
  25.                 }
  26.             }
  27.         }
  28.     }
  29.  
  30.     /* Process data submitted by report issues form */
  31.     if (isset($_POST['reportIssues'])) {
  32.         $preferred_name = test_form_input($_POST['preferredname']);
  33.         $email = test_form_input($_POST['email']);
  34.         $issueID = test_form_input($_POST['issues']);
  35.         $issue_reported = "";
  36.         $message = test_form_input($_POST['message']);
  37.  
  38.         $dateTimeObject = new DateTime("now", new DateTimeZone("America/Halifax"));
  39.         $dateTimeObject->setTimestamp(time()); //adjust the object to correct timestamp
  40.         $message_date = $dateTimeObject->format('d.m.Y,');
  41.         $message_time = $dateTimeObject->format('H:i:sa');
  42.  
  43.         switch ($issueID) {
  44.             case '1':
  45.                 $issue_reported = "Link Not Working";
  46.                 break;
  47.  
  48.             case '2':
  49.                 $issue_reported = "Page Not Found";
  50.                 break;
  51.  
  52.             case '3':
  53.                 $issue_reported = "Incorrect Script";
  54.                 break;
  55.  
  56.             default:
  57.                 $issue_reported = "Issue Not Selected";
  58.                 break;
  59.         }
  60.  
  61.         $issue_report = "";
  62.         $issue_report .= "Issue Alert!";
  63.         $issue_report .= "\r\n";
  64.         $issue_report .= "Type of Issue: " . $issue_reported;
  65.         $issue_report .= "\r\n";
  66.         $issue_report .= "\r\n";
  67.         $issue_report .= "Submitted by: " . $preferred_name;
  68.         $issue_report .= "\r\n";
  69.         $issue_report .= "Email ID: " . $email;
  70.         $issue_report .= "\r\n";
  71.         $issue_report .= "Submitted At: " . $message_time . " - on - " . $message_date;
  72.         $issue_report .= "\r\n";
  73.         $issue_report .= "\r\n";
  74.         $issue_report .= "Details: " . $message;
  75.  
  76.         $issue_file_name = "misc/message_" . time() . ".txt";
  77.         $issue_file_handle = fopen($issue_file_name, "w") or die("Sorry! Unable to open file!");
  78.  
  79.         fwrite($issue_file_handle, $issue_report);
  80.  
  81.         fclose($issue_file_handle);
  82.  
  83.         $current_page = basename($_SERVER['PHP_SELF']);
  84.  
  85.         header("Location: " . $current_page . "?issue_reported=1");
  86.     }
  87. ?>
  88. <!DOCTYPE html>
  89. <html lang="en">
  90. <head>
  91.   <title></title>
  92.   <meta charset="utf-8">
  93.   <meta name="viewport" content="width=device-width, initial-scale=1">
  94.   <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  95.   <link href="css/styles.css" rel="stylesheet" type="text/css">
  96. </head>
  97. <body>
  98. <header>
  99.   <nav class="col-sm-3 sidenav">
  100.     <h2>Nic Mingo's Blog</h2>
  101.     <ul class="nav nav-pills nav-stacked">
  102.       <?php
  103.         if(basename($_SERVER['PHP_SELF']) == "index.php"){
  104.           echo "<li class=\"active\"><a href=\"index.php\">Homepage</a></li>"; //active
  105.           echo "<li><a href=\"post.php\">Posts</a></li>";
  106.           echo "<li><a href=\"report.php\">Report Issues</a></li>";
  107.                     echo "<li><a href=\"categories.php\">Category</a></li>";
  108.                     echo "<li><a href=\"add_post.php\">New Post</a></li>";
  109.         } elseif(basename($_SERVER['PHP_SELF']) == "post.php"){
  110.           echo "<li><a href=\"index.php\">Homepage</a></li>";
  111.           echo "<li class=\"active\"><a href=\"post.php\">Posts</a></li>"; //active
  112.           echo "<li><a href=\"report.php\">Report Issues</a></li>";
  113.                     echo "<li><a href=\"categories.php\">Category</a></li>";
  114.                     echo "<li><a href=\"add_post.php\">New Post</a></li>";
  115.         } elseif(basename($_SERVER['PHP_SELF']) == "report.php") {
  116.           echo "<li><a href=\"index.php\">Homepage</a></li>";
  117.           echo "<li><a href=\"post.php\">Posts</a></li>";
  118.           echo "<li class=\"active\"><a href=\"report.php\">Report Issues</a></li>"; //active
  119.                     echo "<li><a href=\"categories.php\">Category</a></li>";
  120.                     echo "<li><a href=\"add_post.php\">New Post</a></li>";
  121.         } elseif(basename($_SERVER['PHP_SELF']) == "categories.php") {
  122.           echo "<li><a href=\"index.php\">Homepage</a></li>";
  123.           echo "<li><a href=\"post.php\">Posts</a></li>";
  124.           echo "<li><a href=\"report.php\">Report Issues</a></li>";
  125.                     echo "<li class=\"active\"><a href=\"categories.php\">Category</a></li>"; //active
  126.                     echo "<li><a href=\"add_post.php\">New Post</a></li>";
  127.         } elseif(basename($_SERVER['PHP_SELF']) == "add_post.php") {
  128.           echo "<li><a href=\"index.php\">Homepage</a></li>";
  129.           echo "<li><a href=\"post.php\">Posts</a></li>";
  130.           echo "<li><a href=\"report.php\">Report Issues</a></li>";
  131.                     echo "<li><a href=\"categories.php\">Category</a></li>";
  132.                     echo "<li class=\"active\"><a href=\"add_post.php\">New Post</a></li>"; //active
  133.         } else {
  134.           echo "<li><a href=\"index.php\">Homepage</a></li>";
  135.           echo "<li><a href=\"post.php\">Posts</a></li>";
  136.             echo "<li><a href=\"report.php\">Report Issues</a></li>";
  137.                     echo "<li><a href=\"categories.php\">Category</a></li>";
  138.                     echo "<li><a href=\"add_post.php\">New Post</a></li>";
  139.         }
  140.       ?>
  141.     </ul>
  142.  
  143.         <?php
  144.         $server = "localhost";
  145.         $username = "root";
  146.         $password = "root";
  147.         $dbname = "cms";
  148.         $conn = new mysqli($server, $username, $password, $dbname);
  149.         if ($conn->connect_error){
  150.             die("Connection failed: " . $conn->connect_error . " please refresh the page.");
  151.         }else {
  152.  
  153.             $sql = "SELECT * FROM category";
  154.             $result = $conn->query($sql);
  155.  
  156.             if($result->num_rows > 0){
  157.                 echo "<div class=\"dropdown\">";
  158.             echo "<button class=\"btn btn-primary dropdown-toggle\" type=\"button\" data-toggle=\"dropdown\">Category Posts";
  159.             echo "<span class=\"caret\"></span></button>";
  160.             echo "<ul class=\"dropdown-menu\">";
  161.                 while($row = $result->fetch_assoc()) {
  162.                 echo "<li><a href=\"category_posts.php?category=" . $row["cat_id"] . "\">" . $row["cat_title"] . "</a></li>";
  163.                 }
  164.                 echo "</ul>";
  165.                 echo "</div>";
  166.                 echo "<br>";
  167.             }
  168.         }
  169.  
  170.         $conn->close();
  171.         ?>
  172.  
  173.     <div class="input-group">
  174.       <input type="text" class="form-control" placeholder="Search Blog..">
  175.       <span class="input-group-btn">
  176.         <button class="btn btn-default" type="button">
  177.           <span class="glyphicon glyphicon-search"></span>
  178.         </button>
  179.       </span>
  180.     </div>
  181.   </nav>
  182. </header>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement