//process the delete if (isset($_GET['delete_pet_status_wk'])) { $to_delete_key = $_GET['delete_pet_status_wk']; //update all pets to use a status of undefined if they're using the one we're deleting $sql = "UPDATE `pet` SET `status_wk` = 0, `last_update_dt` = CURRENT_TIMESTAMP() WHERE `status_wk` = {$to_delete_key};"; $database->query($sql); //now that no pets are using that status, we delete the record $to_delete = Status::find_by_id($to_delete_key); if ($to_delete->delete()) { $session->message("<strong>" . $to_delete->name . "</strong> was deleted successfully."); } else { $session->message("<strong>" . $to_delete->name . "</strong> was not deleted successfully.<br />" . $database->last_error); } //redirect back to itself without the ?delete_pet_status_wk in the URL //so the system does not try to delete something again redirect_head(file_name_without_get()); } //get all the statues $all_statuses = Status::find_all(); //process the form data if (isset($_POST['submit'])) { //an array to keep track of all changes $changes = array(); //flatten all statuses into an associated array //where the keys are the indexes //this makes searching 100% easier $flat_all_statuses = array(); foreach ($all_statuses as $value) { $flat_all_statuses[$value->status_wk] = $value->name; } //loop through all POST fields
} //grab the set of users to display $sql = "SELECT `u`.* FROM `user` AS `u` "; $sql .= "INNER JOIN `role` AS `r` ON `r`.`role_wk` = `u`.`role_wk` "; $sql .= "WHERE 1=1 "; $sql .= generate_user_where() . " "; $sql .= generate_user_order_by() . " "; $sql .= ";"; $users = User::find_by_sql($sql); //display filters $page->body = "<p><a href=\"" . file_name_without_get() . "?type=all\">All</a> | <a href=\"" . file_name_without_get() . "?type=users\">Active Users</a> | <a href=\"" . file_name_without_get() . "?type=staff\">Active Staff</a> | <a href=\"" . file_name_without_get() . "?type=admin\">Active Admin</a> | <a href=\"" . file_name_without_get() . "?type=is_deleted\">Disabled</a></p>"; //only display the table with results if //there are more than 0 users if (count($users) > 0) { //there are users to display $page->body .= "<table style=\"width:100%\">\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t<th><a href=\"" . file_name_without_get() . "?toggle=username\">Username</a></th>\n\t\t\t\t\t\t\t\t<th><a href=\"" . file_name_without_get() . "?toggle=first_name\">First Name</a></th>\t\t\n\t\t\t\t\t\t\t\t<th><a href=\"" . file_name_without_get() . "?toggle=last_name\">Last Name</a></th>\n\t\t\t\t\t\t\t\t<th><a href=\"" . file_name_without_get() . "?toggle=email_address\">Email Address</a></th>\n\t\t\t\t\t\t\t\t<th><a href=\"" . file_name_without_get() . "?toggle=role\">Role</a></th>\n\t\t\t\t\t\t\t\t<th><a href=\"" . file_name_without_get() . "?toggle=is_deleted\">Is Disabled</a></th>\n\t\t\t\t\t\t\t</tr>"; //loop through all objects foreach ($users as $value) { $page->body .= "<tr>\n\t\t\t\t\t\t\t\t<td><a href=\"" . ROOT_URL . "admin/update_user.php?user_wk=" . $value->user_wk . "\">" . $value->username . "</a></td>\n\t\t\t\t\t\t\t\t<td>" . $value->first_name . "</td>\t\t\n\t\t\t\t\t\t\t\t<td>" . $value->last_name . "</td>\n\t\t\t\t\t\t\t\t<td>" . $value->email_address . "</td>\n\t\t\t\t\t\t\t\t<td>" . $value->role_wk->name . "</td>\t\t\n\t\t\t\t\t\t\t\t<td>" . ($value->is_deleted == '1' ? 'Yes' : 'No') . "</td>\n\t\t\t\t\t\t\t</tr>"; } $page->body .= "</table>"; } $page->body .= "<p><em>Your search returned " . count($users) . " user(s).</em></p>"; //include the header require_once "../requires/template/header.php"; echo "<section class=\"container\">"; //display the page echo $page->body; echo "</section>"; //include the footer require_once "../requires/template/footer.php";
$comment_to_flag = Comment::find_by_id($_GET['flag_comment_wk']); if (!$comment_to_flag) { //if the item does not exist in the database $session->message("You must've clicked on a bad URL; please try again."); redirect_head(ROOT_URL . file_name_without_get() . "?pet_wk=" . $_GET['pet_wk']); } //now we make sure the comment is not already flagged if ($comment_to_flag->is_flagged == '1') { $session->message("That comment is already flagged."); redirect_head(ROOT_URL . file_name_without_get() . "?pet_wk=" . $_GET['pet_wk']); } //if we're here, go ahead and flag the comment $comment_to_flag->is_flagged = 1; if ($comment_to_flag->save()) { $session->message("The comment was successfully flagged."); redirect_head(ROOT_URL . file_name_without_get() . "?pet_wk=" . $_GET['pet_wk']); } } //since we're here - we're good to resume heavy processing //get all the vaccinations for the pet $pet->get_my_vaccinations(); //get all the comments for the pet $pet->get_my_comments(); require_once "requires/template/header.php"; ?> <section id="blog" class="container"> <div class="blog"> <div class="blog-item"> <img class="img-responsive img-blog" width="100%" src="uploads/<?php echo $pet->image_wk->filename; ?>
$new_page->body = $_POST["page_content"]; // if the page is successfully created, go to the page if ($new_page->save()) { $session->message("Your new page was created successfully!"); redirect_head(ROOT_URL . "view_page.php?page_wk=" . $database->insert_id()); } else { $session->message("There was an issue with your request. " . $database->last_error); } } //header template require_once "../requires/template/header.php"; ?> <!-- Create a page form --> <section id="registration" class="container"><form class="center" role="form" id="create_page" action="<?php echo file_name_without_get(); ?> " method="post" ><fieldset class="registration-form"> Page Name: <br><div class="form-group"><input type="text" class="form-control" name="page_name" value="<?php echo isset($new_page) ? $new_page->name : ''; ?> " required/> </div> Page Content: <br><div class="form-group"><textarea rows="5" cols="100" class="ckeditor" name="page_content"><?php echo isset($new_page) ? $new_page->body : ''; ?> </textarea> </div> <div class="form-group"><button type="submit" value="submit" name="submit" class="btn btn-success btn-md btn-block">Submit</button></div> </fieldset></form></section> <?php
function display_pet_blog($sql, $is_folder = false) { global $database; global $session; $return = ""; //get all the pets $pets = Pet::find_by_sql($sql); //get all the wish list items //only do this if the user is logged in if ($session->is_logged_in) { $sql = "SELECT * FROM `pet_wish_list` WHERE `user_wk` = " . $session->user_wk . ";"; $pwl = Pet_Wish_List::find_by_sql($sql); } else { $pwl = array(); } // loop through all of the pet wish list elements (if any) and get their wk's $wish_array = array(); foreach ($pwl as $wish_elem) { $wish_array[] = $wish_elem->pet_wk->pet_wk; } //only display the table with results if //there are more than 0 pets if (count($pets) > 0) { //there are pets to display $return = "<div>\n\t\t\t\t\t\t\t\tSort by: <a href=\"" . file_name_without_get() . "?toggle=name\">Name</a> | \n\t\t\t\t\t\t\t\t<a href=\"" . file_name_without_get() . "?toggle=pet_type\">Pet Type</a> | \t\t\n\t\t\t\t\t\t\t\t<a href=\"" . file_name_without_get() . "?toggle=breed\">Breed</a> | \n\t\t\t\t\t\t\t\t<a href=\"" . file_name_without_get() . "?toggle=color\">Color</a> | \n\t\t\t\t\t\t\t\t<a href=\"" . file_name_without_get() . "?toggle=status\">Status</a> | \n\t\t\t\t\t\t\t\t<a href=\"" . file_name_without_get() . "?toggle=age\">Age</a> | \n\t\t\t\t\t\t\t\t<a href=\"" . file_name_without_get() . "?toggle=weight\">Weight</a> | \n\t\t\t\t\t\t\t <a href=\"" . file_name_without_get() . "?toggle=date_added\">Date Added</a> | "; //if you're an admin or staff, display the ability to //immediately update the pet if (is_admin_or_staff()) { //$return .= "Update"; } $return .= "</div><br><br>"; //loop through all pets $rowCutter = 0; $return .= "<section class=\"blog\" style=\"width:100%\"><div class=\"row\">"; foreach ($pets as $value) { $value->get_my_comments(); $return .= "\t<div class=\""; if (is_mobile()) { $return .= "col-xs-11"; } else { $return .= "col-xs-6"; } $return .= "\">\n\t\t\t\t\t\t\t<div id=\"" . $value . "_row\" class=\"blog-item\">\n\t\t\t\t\t\t\t\t<a href=\"" . ROOT_URL . "view_pet.php?pet_wk=" . $value->pet_wk . "\"><img class=\"img-responsive img-blog\" src=\""; if ($is_folder) { $return .= "../"; } $return .= "uploads/" . $value->image_wk->filename . "\" ></a>\n\t\t\t\t\t\t\t\t<div class=\"blog-content\">\n\t\t\t\t\t\t\t\t<div class=\"entry-meta\">\n\t\t\t\t\t\t\t\t<span><i class=\"icon-calendar\"> " . date("m/d/Y h:i A", strtotime($value->create_dt)) . "</i><span>\n\t\t\t\t\t\t\t\t<span> <i class=\"icon-comment\"> " . count($value->comment) . "</i><span>\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t<h3><a href=\"" . ROOT_URL . "view_pet.php?pet_wk=" . $value->pet_wk . "\">" . $value->name . "</a></h3>\n\t\t\t\t\t\t\t\tPet Type: " . $value->breed_wk->pet_type_wk->name . "\t\n\t\t\t\t\t\t\t\t<br>Pet Breed: " . $value->breed_wk->name . "\n\t\t\t\t\t\t\t\t<br>Pet Color: " . $value->color_wk->name . "\n\t\t\t\t\t\t\t\t<br>Pet Status: " . $value->status_wk->name . "\t\t\n\t\t\t\t\t\t\t\t<br>Pet Age: " . $value->age . "\n\t\t\t\t\t\t\t\t<br>Pet Weight: " . $value->weight . "<br>"; // quick option to add/remove pet from wish list if ($session->is_logged_in) { if (in_array($value->pet_wk, $wish_array)) { $return .= "<br><input id=\"" . $value->pet_wk . "\" type=\"button\" class=\"btn btn-success btn-md btn-block\" onclick=\"wish_list(" . $value->pet_wk . ", this.id)\" value=\"Remove from Wish List\" />"; } else { $return .= "<br><input id=\"" . $value->pet_wk . "\" type=\"button\" class=\"btn btn-success btn-md btn-block\" onclick=\"wish_list(" . $value->pet_wk . ", this.id)\" value=\"Add to Wish List!\" />"; } } //if you're an admin or staff, display the ability to //immediately update the pet if (is_admin_or_staff()) { $return .= "<a href=\"" . ROOT_URL . "admin/update_pet.php?pet_wk=" . $value->pet_wk . "\" class=\"btn btn-success btn-md btn-block\">Update</a>"; } $return .= "</div></div></div>"; $rowCutter++; //end current row and start new - visually if content = 2 if (is_mobile()) { $mod_by = 1; } else { $mod_by = 2; } if ($rowCutter % $mod_by == 0) { $return .= "</div><div class=\"row\">"; } } $return .= "</div>"; } $return .= "<p><em>Your search returned " . count($pets) . " pet(s).</em></p>"; $return .= "</section>"; return $return; }
} else { $session->message("There was an error removing the watch list entry."); } } } //redirect back redirect_head(file_name_without_get()); } //grab all the watch lists for this user $watch_lists = Watch_List::find_by_sql("SELECT * FROM `watch_list` WHERE `user_wk` = " . $user->user_wk . ";"); $page->body = "<p><a href=\"create_watch_list.php\">Add new Watch List</a></p><br>"; //if there are records returned if ($watch_lists) { $page->body .= "<p><em>Your current watch lists.</em><br />"; foreach ($watch_lists as $list) { //var_dump($list); $page->body .= "<br /><strong>" . $list->name . "</strong><br />"; $page->body .= "<a href=\"" . file_name_without_get() . "?delete_watch_list_wk=" . $list->watch_list_wk . "\" style=\"margin-left:1.5em;\" >Delete</a><br />"; } $page->body .= "</p>"; } else { //there are no watch lists returned $page->body .= "<p><em>You currently don't have any watch lists.</em></p>"; } //header template require_once "../requires/template/header.php"; echo "<section id=\"blog\"><div class=\"container\"><div class=\"row\"><div class=\"col-md-12\"><div class=\"blog\"><div class=\"blog-item\"><div class=\"blog-content\">"; echo $page->body; echo "</div></div></div></div></div></div></section>"; //footer template require_once "../requires/template/footer.php";