Esempio n. 1
0
function send_reminders()
{
    global $db, $fs, $proj;
    $notify = new Notifications();
    $user = new User(0);
    $now = time();
    $get_reminders = $db->Query("SELECT r.*, t.*, u.*\n              FROM {reminders} r\n              INNER JOIN {users}    u ON u.user_id = r.to_user_id\n              INNER JOIN {tasks}    t ON r.task_id = t.task_id\n              INNER JOIN {projects} p ON t.project_id = p.project_id\n              WHERE t.is_closed = '0'\n              AND r.start_time < ?\n              AND r.last_sent + r.how_often < ?\n              ORDER BY r.reminder_id", array($now, $now));
    while ($row = $db->FetchRow($get_reminders)) {
        // So that the sender in emails will is the right project, not 'Default project'
        // and also to get the projects default language, if needed.
        $proj = new Project($row['project_id']);
        $jabber_users = array();
        $email_users = array();
        if (($fs->prefs['user_notify'] == 1 || $fs->prefs['user_notify'] == 2) && ($row['notify_type'] == 1 || $row['notify_type'] == 3)) {
            $email_users[] = $row['email_address'];
        }
        if (($fs->prefs['user_notify'] == 1 || $fs->prefs['user_notify'] == 3) && ($row['notify_type'] == 2 || $row['notify_type'] == 3)) {
            $jabber_users[] = $row['jabber_id'];
        }
        if (!empty($row['lang_code'])) {
            $lang = $row['lang_code'];
        } else {
            if (!empty($proj->prefs['lang_code'])) {
                $lang = $proj->prefs['lang_code'];
            } else {
                $lang = $fs->prefs['lang_code'];
            }
        }
        $subject = tL('notifyfromfs', $lang);
        $message = $row['reminder_message'];
        // Pass the recipients and message onto the notification function
        $notify->SendEmail($email_users, $subject, $message);
        $notify->StoreJabber($jabber_users, $subject, $message);
        // Update the database with the time sent
        $update_db = $db->Query("UPDATE {reminders}\n      SET last_sent = ?\n      WHERE reminder_id = ?", array(time(), $row['reminder_id']));
    }
    // send those stored notifications
    $notify->SendJabber();
    unset($notify, $user);
}
Esempio n. 2
0
} else {
    $user = new User(0, $proj);
}
// don't allow anonymous users to access this page at all
if ($user->isAnon()) {
    die(L('nopermission'));
}
load_translations();
if (!Post::has('csrftoken')) {
    header(':', true, 428);
    # 'Precondition Required'
    die('missingtoken');
} elseif (Post::val('csrftoken') == $_SESSION['csrftoken']) {
    # empty
} else {
    header(':', true, 412);
    # 'Precondition Failed'
    die('wrongtoken');
}
if (!$user->perms('is_admin')) {
    header(':', true, 403);
    # 'Forbidden'
    die(L('nopermission'));
}
$notify = new Notifications();
$result = $notify->SendEmail($user->infos['email_address'], 'test', 'testcontent', 1);
if ($result != 1) {
    header(':', true, 406);
    # 'not acceptable'
}
echo 'ok';