示例#1
0
 public static function is_watch_list_eligible($pet_wk, $watch_list_wk)
 {
     global $session;
     global $database;
     $pet = Pet::find_by_id($pet_wk);
     $watch_list_detail = Watch_List_Detail::find_by_sql("SELECT * FROM `watch_list_detail` WHERE `watch_list_wk` = " . $watch_list_wk . ";");
     //echo '<pre>' . var_export($watch_list_detail, true) . '</pre>'; //debug
     //generate the dynamic MySQL statement
     $sql = "SELECT `p`.* FROM `pet` AS `p` ";
     $sql .= "INNER JOIN `breed` AS `b` ON `b`.`breed_wk` = `p`.`breed_wk` ";
     $sql .= "INNER JOIN `pet_type` AS `pt` ON `pt`.`pet_type_wk` = `b`.`pet_type_wk` ";
     $sql .= "WHERE `p`.`is_deleted` = 0 AND `p`.`pet_wk` = " . $pet_wk . " ";
     //loop through each criteria, determine if it's eligible
     foreach ($watch_list_detail as $item) {
         //if one of the min or max fields
         if (in_array($item->column_name, array('age_min', 'age_max', 'weight_min', 'weight_max'))) {
             if ($item->column_name == 'age_min') {
                 $sql .= "AND `age` >= " . $item->value . " ";
             } else {
                 if ($item->column_name == 'age_max') {
                     $sql .= "AND `age` <= " . $item->value . " ";
                 } else {
                     if ($item->column_name == 'weight_min') {
                         $sql .= "AND `weight` >= " . $item->value . " ";
                     } else {
                         if ($item->column_name == 'weight_max') {
                             $sql .= "AND `weight` <= " . $item->value . " ";
                         }
                     }
                 }
             }
         } else {
             //not one of the min or max fields
             $sql .= "AND " . ($item->column_name == 'pet_type' ? '`pt`' : '`p`') . ".`" . $item->column_name . "_wk` = " . $item->value . " ";
         }
     }
     $sql .= ";";
     $result = Pet::find_by_sql($sql);
     //if the count of animals returned is 1, return true
     //else, return false
     if (count($result) == 1) {
         return true;
     } else {
         return false;
     }
 }
示例#2
0
<?php

//require the framework
require_once "../requires/initialize.php";
// create the page
$page = new Page();
$page->name = "Delete Pet";
$page->is_admin_only = true;
// check if pet_wk is set
if (!isset($_GET["pet_wk"])) {
    $session->message("There is an error with the pet you were trying to access.");
    redirect_head(ROOT_URL);
}
$pet_wk = $_GET["pet_wk"];
$pet_found = Pet::find_by_id($pet_wk);
// check that the pet_wk exists
if (!$pet_found) {
    $session->message("There is an error with the pet you were trying to access.");
    redirect_head(ROOT_URL);
}
// check if the pet is deleted
if ($pet_found->is_deleted == "1") {
    $session->message("The pet you are trying to delete has already been deleted.");
    redirect_head(ROOT_URL);
}
// if the user confirmd we're deleting the pet
if (isset($_POST["confirm"])) {
    // delete the pet
    $pet_found->delete();
    $session->message("The pet was successfully deleted!");
    redirect_head(ROOT_URL . "search_pets.php");
示例#3
0
<?php

//require the framework
require_once "requires/initialize.php";
//construct the page
$page = new Page();
$page->name = "View a Pet";
//set the AJAX code
$page->script = "<script>\n\t\tfunction wish_list(pet, clicked_id)\n\t\t{\n\t\t\tvar doc_root = \"" . ROOT_URL . "\";\n\t\t\tvar xhttp = new XMLHttpRequest();\n\t\t\txhttp.onreadystatechange = function() {\n\t\t\t\tif (xhttp.readyState == 4 && xhttp.status == 200)\n\t\t\t\t{\t\n\t\t\t\t\tvar response = xhttp.responseText.trim();\n\t\t\t\t\tvar msg_elem = document.getElementById(\"ajax_message\");\n\t\t\t\t\tvar wl_button = document.getElementById(clicked_id);\n\t\t\t\t\t\n\t\t\t\t\t// display the message\n\t\t\t\t\tmsg_elem.innerHTML = response;\n\t\t\t\t\t\n\t\t\t\t\t// change the text of the button\n\t\t\t\t\tif (wl_button.innerHTML == \"Add to Wish List!\") // if the pet was added, change to delete\n\t\t\t\t\t{\n\t\t\t\t\t\twl_button.innerHTML = \"Remove from Wish List\";\n\t\t\t\t\t}\n\t\t\t\t\telse // if the pet was deleted, remove row from the table\n\t\t\t\t\t{\n\t\t\t\t\t\twl_button.innerHTML = \"Add to Wish List!\";\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t};\n\t\t\txhttp.open(\"GET\", doc_root + \"ajax_wish_list.php?p=\" + pet, true);\n\t\t\txhttp.send();\n\t\t};\n\n\t\t</script>";
// check if pet_wk is set
if (!isset($_GET["pet_wk"])) {
    $session->message("There is an error with the pet you were trying to view.");
    redirect_head(ROOT_URL);
}
//get the pet info
$pet = Pet::find_by_id($_GET["pet_wk"]);
// check that the pet_wk exists
if (!$pet) {
    $session->message("There is an error with the pet you were trying to view.");
    redirect_head(ROOT_URL);
}
// check if the pet is deleted
if ($pet->is_deleted == "1") {
    $session->message("The pet you are trying to view has been deleted.");
    redirect_head(ROOT_URL);
}
//PROCESS NEW COMMENTS HERE
if (isset($_POST['submit'])) {
    //first of all, make sure user is logged in before we do any processing
    //just in case of hacking attempt
    if (!$session->is_logged_in) {
示例#4
0
<?php

//require the framework
require_once "../requires/initialize.php";
$page = new Page();
$page->name = "Update Pet";
$page->is_admin_only = true;
// check if pet_wk is set
if (!isset($_GET["pet_wk"])) {
    $session->message("There is an error with the page you were trying to access.");
    redirect_head(ROOT_URL);
}
// grab the pet so it's content can be pre-loaded into the form
$update_pet = Pet::find_by_id($_GET["pet_wk"]);
// check that the pet_wk exists
if (!$update_pet) {
    $session->message("There is an error with the page you were trying to access.");
    redirect_head(ROOT_URL);
}
//make sure the pet is not deleted
if ($update_pet->is_deleted == '1') {
    $session->message("The pet you are trying to update has been deleted.");
    redirect_head(ROOT_URL);
}
//get all the vaccinations for the pet
$update_pet->get_my_vaccinations();
//now we loop through all the vaccinations and put all the keys
//into a 1D array so we can easily keep track of which ones this pet has
$pets_vaccinations = array();
foreach ($update_pet->vaccination as $value) {
    $pets_vaccinations[$value->vaccination_wk] = $value->vaccination_name;