Ejemplo n.º 1
0
function initiate_watch_list($pet_wk = 0, $type = "")
{
    global $session;
    global $database;
    global $am_i_local;
    //first thing's first, get a list of all watch lists that are eligible
    $all_eligile_watch_lists = Watch_List::find_by_sql("SELECT DISTINCT `wl`.* FROM `user` AS `u` \n\t\tINNER JOIN `watch_list` AS `wl` ON `wl`.`user_wk` = `u`.`user_wk`\n\t\tWHERE `u`.`is_deleted` = 0 AND `u`.`is_notifications_enabled` = 1;");
    //we retain an array of all user_wk's that are eligible to receive an e-mail
    $temp_users = array();
    //now that we have a list of all of them, we need to loop through each item
    //and we determine wether or not there are any people who should receive an e-mail
    foreach ($all_eligile_watch_lists as $all_eligile_watch_lists) {
        if (Watch_List::is_watch_list_eligible((int) $pet_wk, (int) $all_eligile_watch_lists->watch_list_wk)) {
            $temp_users[] = $all_eligile_watch_lists->user_wk;
        }
    }
    //by this point, we have a list of all users that are eligible to receive an e-mail
    //now, we need to de-dupe the list by people in case someone is in the list more than once
    $temp_users = array_unique($temp_users);
    //at this point, we have a list of all users to send an e-mail to
    foreach ($temp_users as $user) {
        //compose the email
        //only if we're not in a local environment
        if (!$am_i_local) {
            $to = $user->email_address;
            $subject = "Watch List Alert!";
            $message = "\n\t\t\t\t<html>\n\t\t\t\t\t<head>\n\t\t\t\t\t\t<title>" . $subject . "</title>\n\t\t\t\t\t</head>\n\t\t\t\t\t<body>\n\t\t\t\t\t\t<p><strong>" . $user->username . "</strong>, we have an " . $type . " pet that meets at least one of your Watch Lists!</p>\n\t\t\t\t\t\t<p>Please the link below to view the pet!</p>\n\t\t\t\t\t\t<p><a href=\"" . ROOT_URL . "view_pet.php?pet_wk=" . $pet_wk . "\">" . ROOT_URL . "rview_pet.php?pet_wk=" . $pet_wk . "</a></p>\n\t\t\t\t\t\t<br /><br />\n\t\t\t\t\t\t<p>If you no longer wish to receive these e-mails, you can either delete your watch list or opt out of all e-mail notifications through your account.</p>\n\t\t\t\t\t</body>\n\t\t\t\t</html>\n\t\t\t\t";
            // Always set content-type when sending HTML email
            $headers = "MIME-Version: 1.0" . "\r\n";
            $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
            // More headers
            $headers .= 'From: <support@pet_adoption.com>' . "\r\n";
            //send out the email
            mail($to, $subject, $message, $headers);
        }
    }
    //we're done!
}
Ejemplo n.º 2
0
        } else {
            //if we're here, we actually need to delete it
            //and all the entries from it
            $sql = "DELETE FROM `watch_list_detail` WHERE `watch_list_wk` = " . $to_delete->watch_list_wk . ";";
            if ($to_delete->delete() && $database->query($sql)) {
                $session->message("Your watch list was successfully removed!");
            } 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
Ejemplo n.º 3
0
<?php

//require the framework
require_once "../requires/initialize.php";
$page = new Page();
$page->name = "Add New Watch Lists";
$page->is_user_only = true;
//process the form
if (isset($_POST['submit'])) {
    //first thing's first, make the watch list entry
    $new_watch_list = new Watch_List();
    $new_watch_list->name = $_POST['name'];
    $new_watch_list->user_wk = $user->user_wk;
    if (!$new_watch_list->save()) {
        $session->message("There was an issue, please try again.");
        redirect_head(current_url());
    }
    $new_watch_list->watch_list_wk = $database->insert_id();
    foreach ($_POST as $key => $value) {
        //skip the submit field and name field
        if ($key != 'submit' && $key != 'name') {
            if (!empty($value)) {
                //only process if the value is not empty
                //instantiate the new object
                $new_value = new Watch_List_Detail();
                //set it the watch list key
                $new_value->watch_list_wk = $new_watch_list->watch_list_wk;
                //set it the column name
                $new_value->column_name = $key;
                if (is_array($value)) {
                    //the value we're processing is an array