Advertisement
Guest User

ACP Handler | FarFromPerfect

a guest
Jan 24th, 2015
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.14 KB | None | 0 0
  1. <?php
  2. /**
  3. * Description:
  4. * This is the ACP class
  5. *
  6. * @author     Asus
  7. * @date       1/15/2015
  8. * @file       Class.ACP.php
  9. * @package    Class/
  10. */
  11.  
  12. /*****************************/
  13. /*/ Created By DarkSkiesDO /*/
  14. /*/ Script By DarkSkiesDO /*/
  15. /**************************/
  16.  
  17. class ACP {
  18.  
  19.     /* ACP - Variables */
  20.     static $Access;
  21.  
  22.     /* Add - Variables */
  23.     static $AddResponse;
  24.  
  25.     /* Edit - Variables */
  26.     static $EditResponse;
  27.     static $Title;
  28.     static $Author;
  29.     static $Story;
  30.     static $Status;
  31.  
  32.     public function __construct($user) {
  33.  
  34.         // Globalize Our Database Variable //
  35.         global $PDO;
  36.  
  37.         // Access: Prepare Query //
  38.         $getAccess = $PDO->prepare("SELECT * FROM users WHERE username = ?");
  39.  
  40.         // Access: Execute Query //
  41.         $getAccess->execute(array($user));
  42.  
  43.         // Access: Fetch Statement //
  44.         while ($Users = $getAccess->fetch(PDO::FETCH_ASSOC)) {
  45.  
  46.             // Access: Row - Rank //
  47.             $Rank = $Users["rank"];
  48.  
  49.             // Access: Check //
  50.             if ($Rank >= 10) {
  51.  
  52.                 // Access: Set //
  53.                 ACP::$Access = true;
  54.                 return true;
  55.  
  56.             } else {
  57.  
  58.                 // Access: Set //
  59.                 ACP::$Access = false;
  60.                 return false;
  61.  
  62.             }
  63.  
  64.         }
  65.  
  66.     }
  67.  
  68.     /* Add - Functions */
  69.     static function createStory($Title, $Author, $Story, $Status) {
  70.  
  71.         // Globalize Our Database Variable //
  72.         global $PDO;
  73.  
  74.         // Add: Sanitize Variables //
  75.         $Title = strip_tags(stripslashes($Title));
  76.         $Author = strip_tags(stripslashes($Author));
  77.         $Story = strip_tags(stripslashes($Story));
  78.         $Status = strip_tags(stripslashes($Status));
  79.  
  80.         // Add: Prepare Query //
  81.         $addStory = $PDO->prepare("INSERT INTO stories VALUES ('', ?, ?, ?, '', utc_timestamp(), ?)");
  82.  
  83.         // Add: Execute Query //
  84.         $addStory->execute(array($Title, $Author, $Story, $Status));
  85.  
  86.         // Add: Check Query //
  87.         if ($addStory) {
  88.             ACP::$AddResponse = "<font color='green'>Story Created/Added Successfully!</font>";
  89.         } else {
  90.             ACP::$AddResponse = "<font color='red'>Story Couldn't Be Created/Added!</font>";
  91.         }
  92.  
  93.     }
  94.  
  95.     /* Edit - Functions */
  96.     static function checkStory($Id) {
  97.  
  98.         // Globalize Our Database Variable //
  99.         global $PDO;
  100.  
  101.         // Story: Prepare Query //
  102.         $getStory = $PDO->prepare("SELECT * FROM stories WHERE id = ?");
  103.  
  104.         // Story: Execute Query //
  105.         $getStory->execute(array($Id));
  106.  
  107.         // Story: Row Count //
  108.         $storyCount = $getStory->rowCount();
  109.  
  110.         // Story: Row Check //
  111.         if ($storyCount == 1) {
  112.             ACP::buildStory($Id);
  113.         } else {
  114.             if ($Id == 1) {
  115.                 header('Location: ./index?page=admin&action=home');
  116.             } else {
  117.                 header('Location: ./index?page=admin&action=edit&storyId=1');
  118.             }
  119.         }
  120.  
  121.     }
  122.  
  123.     static function buildStory($Id) {
  124.  
  125.         // Globalize Our Database Variable //
  126.         global $PDO;
  127.  
  128.         // Story: Prepare Query //
  129.         $getStory = $PDO->prepare("SELECT * FROM stories WHERE id = ?");
  130.  
  131.         // Story: Execute Query //
  132.         $getStory->execute(array($Id));
  133.  
  134.         // Story: Fetch Statement //
  135.         while ($Data = $getStory->fetch(PDO::FETCH_ASSOC)) {
  136.  
  137.             // Story: Row - Title //
  138.             $Title = $Data["title"];
  139.  
  140.             // Story: Row - Author //
  141.             $Author = $Data["author"];
  142.  
  143.             // Story: Row - Story //
  144.             $Story = $Data["story"];
  145.  
  146.             // Story: Row - Status //
  147.             $Status = $Data["status"];
  148.  
  149.         }
  150.  
  151.         // Story - Set Variables //
  152.         ACP::$Title = $Title;
  153.         ACP::$Author = $Author;
  154.         ACP::$Story = $Story;
  155.         ACP::$Status = $Status;
  156.  
  157.     }
  158.  
  159.     static function updateStory($Id, $Title, $Author, $Story, $Status) {
  160.  
  161.         // Globalize Our Database Variable //
  162.         global $PDO;
  163.  
  164.         // Update: Sanitize Variables //
  165.         $Title = strip_tags(stripslashes($Title));
  166.         $Author = strip_tags(stripslashes($Author));
  167.         $Story = strip_tags(stripslashes($Story));
  168.         $Status = strip_tags(stripslashes($Status));
  169.  
  170.         // Update: Prepare Query //
  171.         $updateStory = $PDO->prepare("UPDATE stories SET title = ?, author = ?, story = ?, status = ? WHERE id = ?");
  172.  
  173.         // Update: Execute Query //
  174.         $updateStory->execute(array($Title, $Author, $Story, $Status, $Id));
  175.  
  176.         // Update: Check Query //
  177.         if ($updateStory) {
  178.             ACP::$EditResponse = "<font color='green'>Story Updated Successfully!</font>";
  179.         } else {
  180.             ACP::$EditResponse = "<font color='red'>Story Couldn't Be Updated!</font>";
  181.         }
  182.  
  183.     }
  184.  
  185. }
  186.  
  187. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement