/**
  * forum_categories
  *
  * Function that handles all the Admin Functions for Forum Categories
  *
  * @param string $action - action to take within function
  * @param int/string
  * @param int/string
  *
  */
 public function forum_categories($action = null, $id = null, $id2 = null)
 {
     // Get data for users
     $data['current_page'] = $_SERVER['REQUEST_URI'];
     $data['title'] = "Forum Categories";
     // Check to see if there is an action
     if ($action != null && $id != null) {
         // Check to see if action is edit
         if ($action == 'CatMainEdit') {
             // Check to make sure admin is trying to update
             if (isset($_POST['submit'])) {
                 // Check to make sure the csrf token is good
                 if (Csrf::isTokenValid()) {
                     if ($_POST['action'] == "update_cat_main_title") {
                         // Catch password inputs using the Request helper
                         $new_forum_title = Request::post('forum_title');
                         $prev_forum_title = Request::post('prev_forum_title');
                         if ($this->forum->updateCatMainTitle($prev_forum_title, $new_forum_title)) {
                             // Success
                             \Helpers\SuccessHelper::push('You Have Successfully Updated Forum Main Category Title to <b>' . $new_forum_title . '</b>', 'AdminPanel-Forum-Categories');
                         } else {
                             // Fail
                             $error[] = "Edit Forum Main Category Failed";
                         }
                     }
                 }
             } else {
                 // Get data for CatMainEdit Form
                 $data['edit_cat_main'] = true;
                 $data['data_cat_main'] = $this->forum->getCatMain($id);
                 $data['welcome_message'] = "You are about to Edit Selected Forum Main Category.";
                 // Setup Breadcrumbs
                 $data['breadcrumbs'] = "\n            <li><a href='" . DIR . "AdminPanel'><i class='glyphicon glyphicon-cog'></i> Admin Panel</a></li>\n            <li><a href='" . DIR . "AdminPanel-Forum-Categories'><i class='glyphicon glyphicon-list'></i> " . $data['title'] . "</a></li>\n            <li class='active'><i class='glyphicon glyphicon-pencil'></i> Edit Main Category</li>\n          ";
             }
         } else {
             if ($action == "CatMainUp") {
                 if ($this->forum->moveUpCatMain($id)) {
                     // Success
                     \Helpers\SuccessHelper::push('You Have Successfully Moved Up Forum Main Category', 'AdminPanel-Forum-Categories');
                 } else {
                     // Fail
                     $error[] = "Move Up Forum Main Category Failed";
                 }
             } else {
                 if ($action == "CatMainDown") {
                     if ($this->forum->moveDownCatMain($id)) {
                         // Success
                         \Helpers\SuccessHelper::push('You Have Successfully Moved Down Forum Main Category', 'AdminPanel-Forum-Categories');
                     } else {
                         // Fail
                         $error[] = "Move Down Forum Main Category Failed";
                     }
                 } else {
                     if ($action == 'CatMainNew') {
                         // Check to make sure admin is trying to update
                         if (isset($_POST['submit'])) {
                             // Check to make sure the csrf token is good
                             if (Csrf::isTokenValid()) {
                                 // Add new cate main title to database
                                 if ($_POST['action'] == "new_cat_main_title") {
                                     // Catch inputs using the Request helper
                                     $forum_title = Request::post('forum_title');
                                     // Get last order title number from db
                                     $last_order_num = $this->forum->getLastCatMain();
                                     // Attempt to add new Main Category Title to DB
                                     if ($this->forum->newCatMainTitle($forum_title, 'forum', $last_order_num)) {
                                         // Success
                                         \Helpers\SuccessHelper::push('You Have Successfully Created New Forum Main Category Title <b>' . $new_forum_title . '</b>', 'AdminPanel-Forum-Categories');
                                     } else {
                                         // Fail
                                         $error[] = "New Forum Main Category Failed";
                                     }
                                 }
                             }
                         }
                     } else {
                         if ($action == "CatSubList") {
                             // Check to make sure admin is trying to update
                             if (isset($_POST['submit'])) {
                                 // Check to make sure the csrf token is good
                                 if (Csrf::isTokenValid()) {
                                     // Add new cate main title to database
                                     if ($_POST['action'] == "new_cat_sub") {
                                         // Catch inputs using the Request helper
                                         $forum_title = Request::post('forum_title');
                                         $forum_cat = Request::post('forum_cat');
                                         $forum_des = Request::post('forum_des');
                                         // Check to see if we are adding to a new main cat
                                         if ($this->forum->checkSubCat($forum_title)) {
                                             // Get last cat sub order id
                                             $last_cat_order_id = $this->forum->getLastCatSub($forum_title);
                                             // Get forum order title id
                                             $forum_order_title = $this->forum->getForumOrderTitle($forum_title);
                                             // Run insert for new sub cat
                                             $run_sub_cat = $this->forum->newSubCat($forum_title, $forum_cat, $forum_des, $last_cat_order_id, $forum_order_title);
                                         } else {
                                             // Run update for new main cat
                                             $run_sub_cat = $this->forum->updateSubCat($id, $forum_cat, $forum_des);
                                         }
                                         // Attempt to update/insert sub cat in db
                                         if ($run_sub_cat) {
                                             // Success
                                             \Helpers\SuccessHelper::push('You Have Successfully Created Forum Sub Category', 'AdminPanel-Forum-Categories/CatSubList/' . $id);
                                         } else {
                                             // Fail
                                             $error[] = "Create Forum Sub Category Failed";
                                         }
                                     }
                                 }
                             } else {
                                 // Set goods for Forum Sub Categories Listing
                                 $data['cat_sub_list'] = true;
                                 $data['cat_main_title'] = $this->forum->getCatMain($id);
                                 $data['cat_sub_titles'] = $this->forum->getCatSubs($data['cat_main_title']);
                                 $data['fourm_cat_sub_last'] = $this->forum->getLastCatSub($data['cat_main_title']);
                                 $data['welcome_message'] = "You are viewing a complete list of sub categories for requeted main category.";
                                 // Setup Breadcrumbs
                                 $data['breadcrumbs'] = "\n            <li><a href='" . DIR . "AdminPanel'><i class='glyphicon glyphicon-cog'></i> Admin Panel</a></li>\n            <li><a href='" . DIR . "AdminPanel-Forum-Categories'><i class='glyphicon glyphicon-list'></i> " . $data['title'] . "</a></li>\n            <li class='active'><i class='glyphicon glyphicon-pencil'></i> Sub Categories List</li>\n          ";
                             }
                         } else {
                             if ($action == "CatSubEdit") {
                                 // Check to make sure admin is trying to update
                                 if (isset($_POST['submit'])) {
                                     // Check to make sure the csrf token is good
                                     if (Csrf::isTokenValid()) {
                                         // Add new cate main title to database
                                         if ($_POST['action'] == "edit_cat_sub") {
                                             // Catch inputs using the Request helper
                                             $forum_cat = Request::post('forum_cat');
                                             $forum_des = Request::post('forum_des');
                                             // Attempt to update sub cat in db
                                             if ($this->forum->updateSubCat($id, $forum_cat, $forum_des)) {
                                                 // Success
                                                 \Helpers\SuccessHelper::push('You Have Successfully Updated Forum Sub Category', 'AdminPanel-Forum-Categories/CatSubList/' . $id);
                                             } else {
                                                 // Fail
                                                 $error[] = "Update Forum Sub Category Failed";
                                             }
                                         }
                                     }
                                 } else {
                                     // Display Edit Forum for Selected Sub Cat
                                     $data['cat_sub_edit'] = true;
                                     $data['cat_sub_data'] = $this->forum->getCatSubData($id);
                                     $data['welcome_message'] = "You are about to edit requeted sub category.";
                                     // Setup Breadcrumbs
                                     $data['breadcrumbs'] = "\n            <li><a href='" . DIR . "AdminPanel'><i class='glyphicon glyphicon-cog'></i> Admin Panel</a></li>\n            <li><a href='" . DIR . "AdminPanel-Forum-Categories'><i class='glyphicon glyphicon-list'></i> " . $data['title'] . "</a></li>\n            <li><a href='" . DIR . "AdminPanel-Forum-Categories/CatSubList/{$id}'><i class='glyphicon glyphicon-list'></i> Sub Categories List</a></li>\n            <li class='active'><i class='glyphicon glyphicon-pencil'></i> Edit Sub Category</li>\n          ";
                                 }
                             } else {
                                 if ($action == "DeleteSubCat") {
                                     // Check to make sure admin is trying to update
                                     if (isset($_POST['submit'])) {
                                         // Check to make sure the csrf token is good
                                         if (Csrf::isTokenValid()) {
                                             // Add new cate main title to database
                                             if ($_POST['action'] == "delete_cat_sub") {
                                                 // Catch inputs using the Request helper
                                                 $delete_cat_sub_action = Request::post('delete_cat_sub_action');
                                                 // Get title basted on forum_id
                                                 $forum_title = $this->forum->getCatMain($id);
                                                 // Get title basted on forum_cat
                                                 $forum_cat = $this->forum->getCatSub($id);
                                                 // Check to see what delete function admin has selected
                                                 if ($delete_cat_sub_action == "delete_all") {
                                                     // Admin wants to delete Sub Cat and Everything Within it
                                                     // First we delete all related topic Replies
                                                     if ($this->forum->deleteTopicsForumID($id)) {
                                                         $success_count = $success_count + 1;
                                                     }
                                                     // Second we delete all topics
                                                     if ($this->forum->deleteTopicRepliesForumID($id)) {
                                                         $success_count = $success_count + 1;
                                                     }
                                                     // Finally we delete the main cat and all related sub cats
                                                     if ($this->forum->deleteCatForumID($id)) {
                                                         $success_count = $success_count + 1;
                                                     }
                                                     // Check to see if everything was deleted Successfully
                                                     if ($success_count > 0) {
                                                         // Success
                                                         \Helpers\SuccessHelper::push('You Have Successfully Deleted Sub Category: <b>' . $forum_title . ' > ' . $forum_cat . '</b> and Everything Within it!', 'AdminPanel-Forum-Categories');
                                                     }
                                                 } else {
                                                     // Extract forum_id from move_to_# string
                                                     $forum_id = str_replace("move_to_", "", $delete_cat_sub_action);
                                                     if (!empty($forum_id)) {
                                                         // First Update Topic Replies forum_id
                                                         if ($this->forum->updateTopicRepliesForumID($id, $forum_id)) {
                                                             $success_count = $success_count + 1;
                                                         }
                                                         // Second Update Topics forum_id
                                                         if ($this->forum->updateTopicsForumID($id, $forum_id)) {
                                                             $success_count = $success_count + 1;
                                                         }
                                                         // Last delete the sub Category
                                                         if ($this->forum->deleteCatForumID($id)) {
                                                             $success_count = $success_count + 1;
                                                         }
                                                         // Check to see if anything was done
                                                         if ($success_count > 0) {
                                                             // Success
                                                             \Helpers\SuccessHelper::push('You Have Successfully Moved Main Category From <b>' . $old_forum_title . '</b> to <b>' . $new_forum_title . '</b>', 'AdminPanel-Forum-Categories/CatSubList/' . $forum_id);
                                                         }
                                                     } else {
                                                         // User has not selected to delete or move main cat
                                                         \Helpers\ErrorHelper::push('No Action Selected.  No actions executed.', 'AdminPanel-Forum-Categories/DeleteSubCat/' . $id);
                                                     }
                                                 }
                                             }
                                         }
                                     } else {
                                         // Display Delete Cat Sub Form
                                         $data['delete_cat_sub'] = true;
                                         // Get list of all sub cats except current
                                         $data['list_all_cat_sub'] = $this->forum->catSubListExceptSel($id);
                                         // Setup Breadcrumbs
                                         $data['breadcrumbs'] = "\n            <li><a href='" . DIR . "AdminPanel'><i class='glyphicon glyphicon-cog'></i> Admin Panel</a></li>\n            <li><a href='" . DIR . "AdminPanel-Forum-Categories'><i class='glyphicon glyphicon-list'></i> " . $data['title'] . "</a></li>\n            <li><a href='" . DIR . "AdminPanel-Forum-Categories/CatSubList/" . $id . "'><i class='glyphicon glyphicon-list'></i> Sub Categories List</a></li>\n            <li class='active'><i class='glyphicon glyphicon-pencil'></i> Delete Sub Category</li>\n          ";
                                     }
                                 } else {
                                     if ($action == "CatSubUp") {
                                         // Get forum_title for cat
                                         $data['cat_main_title'] = $this->forum->getCatMain($id);
                                         // Try to move up
                                         if ($this->forum->moveUpCatSub($data['cat_main_title'], $id2)) {
                                             // Success
                                             \Helpers\SuccessHelper::push('You Have Successfully Moved Up Forum Sub Category', 'AdminPanel-Forum-Categories/CatSubList/' . $id);
                                         } else {
                                             // Fail
                                             $error[] = "Move Up Forum Main Category Failed";
                                         }
                                     } else {
                                         if ($action == "CatSubDown") {
                                             // Get forum_title for cat
                                             $data['cat_main_title'] = $this->forum->getCatMain($id);
                                             // Try to move down
                                             if ($this->forum->moveDownCatSub($data['cat_main_title'], $id2)) {
                                                 // Success
                                                 \Helpers\SuccessHelper::push('You Have Successfully Moved Down Forum Sub Category', 'AdminPanel-Forum-Categories/CatSubList/' . $id);
                                             } else {
                                                 // Fail
                                                 $error[] = "Move Down Forum Main Category Failed";
                                             }
                                         } else {
                                             if ($action == "DeleteMainCat") {
                                                 // Check to make sure admin is trying to update
                                                 if (isset($_POST['submit'])) {
                                                     // Check to make sure the csrf token is good
                                                     if (Csrf::isTokenValid()) {
                                                         // Add new cate main title to database
                                                         if ($_POST['action'] == "delete_cat_main") {
                                                             // Catch inputs using the Request helper
                                                             $delete_cat_main_action = Request::post('delete_cat_main_action');
                                                             // Get title basted on forum_id
                                                             $forum_title = $this->forum->getCatMain($id);
                                                             // Check to see what delete function admin has selected
                                                             if ($delete_cat_main_action == "delete_all") {
                                                                 // Admin wants to delete Main Cat and Everything Within it
                                                                 // Get list of all forum_id's for this Main Cat
                                                                 $forum_id_all = $this->forum->getAllForumTitleIDs($forum_title);
                                                                 $success_count = "0";
                                                                 if (isset($forum_id_all)) {
                                                                     foreach ($forum_id_all as $row) {
                                                                         // First we delete all related topic Replies
                                                                         if ($this->forum->deleteTopicsForumID($row->forum_id)) {
                                                                             $success_count = $success_count + 1;
                                                                         }
                                                                         // Second we delete all topics
                                                                         if ($this->forum->deleteTopicRepliesForumID($row->forum_id)) {
                                                                             $success_count = $success_count + 1;
                                                                         }
                                                                         // Finally we delete the main cat and all related sub cats
                                                                         if ($this->forum->deleteCatForumID($row->forum_id)) {
                                                                             $success_count = $success_count + 1;
                                                                         }
                                                                     }
                                                                 }
                                                                 if ($success_count > 0) {
                                                                     // Success
                                                                     \Helpers\SuccessHelper::push('You Have Successfully Deleted Main Category: <b>' . $forum_title . '</b> and Everything Within it!', 'AdminPanel-Forum-Categories');
                                                                 }
                                                             } else {
                                                                 // Extract forum_id from move_to_# string
                                                                 $forum_id = str_replace("move_to_", "", $delete_cat_main_action);
                                                                 if (!empty($forum_id)) {
                                                                     // Get new and old forum titles
                                                                     $new_forum_title = $this->forum->getCatMain($forum_id);
                                                                     $old_forum_title = $this->forum->getCatMain($id);
                                                                     // Get forum_order_title id for forum_title we are moving to
                                                                     $new_forum_order_title = $this->forum->getForumOrderTitle($new_forum_title);
                                                                     // Get last order id for new forum_title we are moving to
                                                                     $new_forum_order_cat = $this->forum->getLastCatSub($new_forum_title);
                                                                     // Update with the new forum title from the old one
                                                                     if ($this->forum->moveForumSubCat($old_forum_title, $new_forum_title, $new_forum_order_title, $new_forum_order_cat)) {
                                                                         // Success
                                                                         \Helpers\SuccessHelper::push('You Have Successfully Moved Main Category From <b>' . $old_forum_title . '</b> to <b>' . $new_forum_title . '</b>', 'AdminPanel-Forum-Categories/CatSubList/' . $forum_id);
                                                                     }
                                                                 } else {
                                                                     // User has not selected to delete or move main cat
                                                                     \Helpers\ErrorHelper::push('No Action Selected.  No actions executed.', 'AdminPanel-Forum-Categories/DeleteMainCat/' . $id);
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 } else {
                                                     // Show delete options for main cat
                                                     $data['delete_cat_main'] = true;
                                                     $data['welcome_message'] = "You are about to delete requested main category.  Please proceed with caution.";
                                                     // Get title for main cat admin is about to delete
                                                     $data['delete_cat_main_title'] = $this->forum->getCatMain($id);
                                                     // Get all other main cat titles
                                                     $data['list_all_cat_main'] = $this->forum->catMainListExceptSel($data['delete_cat_main_title']);
                                                     // Setup Breadcrumbs
                                                     $data['breadcrumbs'] = "\n            <li><a href='" . DIR . "AdminPanel'><i class='glyphicon glyphicon-cog'></i> Admin Panel</a></li>\n            <li><a href='" . DIR . "AdminPanel-Forum-Categories'><i class='glyphicon glyphicon-list'></i> " . $data['title'] . "</a></li>\n            <li class='active'><i class='glyphicon glyphicon-pencil'></i> Delete Main Category</li>\n          ";
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     } else {
         // Get data for main categories
         $data['cat_main'] = $this->forum->catMainList();
         // Welcome message
         $data['welcome_message'] = "You are viewing a complete list of main categories.";
         // Setup Breadcrumbs
         $data['breadcrumbs'] = "\n        <li><a href='" . DIR . "AdminPanel'><i class='glyphicon glyphicon-cog'></i> Admin Panel</a></li>\n        <li class='active'><i class='glyphicon glyphicon-list'></i> " . $data['title'] . "</li>\n      ";
     }
     // Get Last main cat order number
     $data['fourm_cat_main_last'] = $this->forum->getLastCatMain();
     // Setup CSRF token
     $data['csrf_token'] = Csrf::makeToken();
     View::renderModule('AdminPanel/views/header', $data);
     View::renderModule('AdminPanel/views/forum_categories', $data, $error, $success);
     View::renderModule('AdminPanel/views/footer', $data);
 }
 public function outbox($current_page = null)
 {
     // Check if user is logged in
     if ($this->auth->isLoggedIn()) {
         // Get Current User's ID
         $u_id = $this->auth->user_info();
     } else {
         Url::redirect();
     }
     // Check to make sure user is trying to delete messages
     if (isset($_POST['submit'])) {
         // Check to make sure the csrf token is good
         if (Csrf::isTokenValid()) {
             // Get Post Data
             $actions = Request::post('actions');
             $msg_id = Request::post('msg_id');
             // Check to see if user is deleteing messages
             if ($actions == "delete") {
                 // Delete selected messages from Outbox
                 if (isset($msg_id)) {
                     foreach ($msg_id as $del_msg_id) {
                         if ($this->model->deleteMessageOutbox($u_id, $del_msg_id)) {
                             // Success
                             $m_del_success[] = true;
                         } else {
                             // Fail
                             $m_del_error[] = true;
                         }
                     }
                     if (count($m_del_success) >= 1) {
                         // Message Delete Success Display
                         SuccessHelper::push('You Have Successfully Deleted Messages', 'MessagesOutbox');
                     } else {
                         if (count($m_del_error) >= 1) {
                             // Message Delete Error Display
                             ErrorHelper::push('Messages Delete Failed', 'MessagesOutbox');
                         }
                     }
                 } else {
                     // Fail
                     ErrorHelper::push('Nothing Was Selected to be Deleted', 'MessagesOutbox');
                 }
             }
         }
     }
     // Collect Data for view
     $data['title'] = "My Private Messages Outbox";
     $data['welcome_message'] = "Welcome to your Private Messages Outbox";
     // Sets "to" username display
     $data['tofrom'] = " to ";
     // Get all message that are to current user
     $data['messages'] = $this->model->getOutbox($u_id, $this->pages->getLimit($current_page, MESSAGE_PAGEINATOR_LIMIT));
     // Set total number of messages for paginator
     $total_num_messages = $this->model->getTotalMessagesOutbox($u_id);
     $this->pages->setTotal($total_num_messages);
     // Send page links to view
     $pageFormat = DIR . "MessagesOutbox/";
     // URL page where pages are
     $data['pageLinks'] = $this->pages->pageLinks($pageFormat, null, $current_page);
     // Message Quota Goods
     // Get total count of messages
     $data['quota_msg_ttl'] = $total_num_messages;
     $data['quota_msg_limit'] = MESSAGE_QUOTA_LIMIT;
     $data['quota_msg_percentage'] = $this->model->getPercentage($data['quota_msg_ttl'], $data['quota_msg_limit']);
     // Check to see if user has reached message limit, if so show warning
     if ($data['quota_msg_percentage'] >= "100") {
         $error[] = "<span class='glyphicon glyphicon-exclamation-sign' aria-hidden='true'></span>\n                  <b>Your Outbox is Full!</b>  You Can NOT send any messages!";
     } else {
         if ($data['quota_msg_percentage'] >= "90") {
             $error[] = "<span class='glyphicon glyphicon-exclamation-sign' aria-hidden='true'></span>\n                  <b>Warning!</b> Your Outbox is Almost Full!";
         }
     }
     // What box are we showing
     $data['what_box'] = "Outbox";
     // Setup Breadcrumbs
     $data['breadcrumbs'] = "\n\t\t\t<li><a href='" . DIR . "'>Home</a></li>\n\t\t\t<li><a href='" . DIR . "Messages'>Private Messages</a></li>\n\t\t\t<li class='active'>" . $data['title'] . "</li>\n\t\t";
     $data['csrf_token'] = Csrf::makeToken();
     // Include Java Script for check all feature
     $data['js'] = "<script src='" . Url::templatePath() . "js/form_check_all.js'></script>";
     // Check for new messages in inbox
     $data['new_messages_inbox'] = $this->model->getUnreadMessages($u_id);
     // Send data to view
     View::renderTemplate('header', $data);
     View::renderModule('Messages/views/messages_sidebar', $data);
     View::renderModule('Messages/views/messages_list', $data, $error, $success);
     View::renderTemplate('footer', $data);
 }
<?php

// Message New Displays form for user to create a new message to send
// Also works with message reply
use Core\Language, Helpers\ErrorHelper, Helpers\SuccessHelper, Core\Error, Helpers\Form;
?>

<div class='col-lg-8 col-md-8'>

  <?php 
// Display Success and Error Messages if any (TODO: Move to header file)
echo ErrorHelper::display();
echo SuccessHelper::display();
echo ErrorHelper::display_raw($error);
echo SuccessHelper::display_raw($success);
?>

	<div class='panel panel-default'>
		<div class='panel-heading'>
			<h3 class='jumbotron-heading'><?php 
echo $data['title'];
?>
</h3>
		</div>
		<div class='panel-body'>
			<p><?php 
echo $data['welcome_message'];
?>
</p>

<?php 
 /**
  * removeSweet
  *
  * delete sweet from database
  *
  * @param int $sweet_id (ID of post where sweet is)
  * @param string $sweet_location (Section of site where sweet is)
  * @param int $sweet_owner_userid (ID of user sweeting)
  * @param int $sweet_sec_id (ID of secondary post)
  * @param string $sweet_url (redirect url)
  *
  */
 public static function removeSweet($sweet_id = null, $sweet_location = null, $sweet_owner_userid = null, $sweet_sec_id = null, $sweet_url = null)
 {
     // Insert New Sweet Into Database
     self::$db = Database::get();
     $sweet_remove_data = self::$db->delete(PREFIX . 'sweets', array('sweet_id' => $sweet_id, 'sweet_location' => $sweet_location, 'sweet_owner_userid' => $sweet_owner_userid, 'sweet_sec_id' => $sweet_sec_id));
     $count = count($sweet_remove_data);
     if ($count > 0) {
         // Success
         SuccessHelper::push('You Have Successfully Deleted a ' . SWEET_BUTTON_DISPLAY, $sweet_url);
     } else {
         ErrorHelper::push('There Was an Error Deleting ' . SWEET_BUTTON_DISPLAY, $sweet_url);
     }
 }