Ejemplo n.º 1
0
<?php

require_once "requires/initialize.php";
// check if the user is logged in
if (!$session->is_logged_in) {
    echo "You must be logged in to add a pet to your wish list!";
} else {
    $pwl = Pet_Wish_List::find_by_sql("SELECT * FROM `pet_wish_list` WHERE `pet_wk` = " . $_GET["p"] . " AND `user_wk` = " . $session->user_wk . " LIMIT 1;");
    // if the pet is already on the user's wish list
    if ($pwl) {
        if ($pwl[0]->delete()) {
            echo "";
        } else {
            echo "";
        }
    } else {
        $new_wish = new Pet_Wish_List();
        $new_wish->user_wk = $session->user_wk;
        $new_wish->pet_wk = $_GET["p"];
        if ($new_wish->save()) {
            echo "";
        } else {
            echo "";
        }
    }
}
Ejemplo n.º 2
0
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:&nbsp;&nbsp;&nbsp;<a href=\"" . file_name_without_get() . "?toggle=name\">Name</a> &nbsp;&nbsp;|&nbsp;&nbsp;\n\t\t\t\t\t\t\t\t<a href=\"" . file_name_without_get() . "?toggle=pet_type\">Pet Type</a>&nbsp;&nbsp;|&nbsp;&nbsp;\t\t\n\t\t\t\t\t\t\t\t<a href=\"" . file_name_without_get() . "?toggle=breed\">Breed</a>&nbsp;&nbsp;|&nbsp;&nbsp;\n\t\t\t\t\t\t\t\t<a href=\"" . file_name_without_get() . "?toggle=color\">Color</a>&nbsp;&nbsp;|&nbsp;&nbsp;\n\t\t\t\t\t\t\t\t<a href=\"" . file_name_without_get() . "?toggle=status\">Status</a>&nbsp;&nbsp;|&nbsp;&nbsp;\n\t\t\t\t\t\t\t\t<a href=\"" . file_name_without_get() . "?toggle=age\">Age</a>&nbsp;&nbsp;|&nbsp;&nbsp;\n\t\t\t\t\t\t\t\t<a href=\"" . file_name_without_get() . "?toggle=weight\">Weight</a>&nbsp;&nbsp;|&nbsp;&nbsp;\n\t\t\t\t\t\t\t    <a href=\"" . file_name_without_get() . "?toggle=date_added\">Date Added</a>&nbsp;&nbsp;|&nbsp;&nbsp;";
        //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\">&nbsp;" . date("m/d/Y h:i A", strtotime($value->create_dt)) . "</i><span>\n\t\t\t\t\t\t\t\t<span>&nbsp;&nbsp;&nbsp;&nbsp;<i class=\"icon-comment\">&nbsp;" . 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;
}