示例#1
0
    $now = time();
    $get_reminders = $db->Query("SELECT  r.*, t.*, p.*\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' AND r.start_time < ?\n                                                       AND r.last_sent + r.how_often < ?\n                           ORDER BY  r.reminder_id", array(time(), time()));
    while ($row = $db->FetchRow($get_reminders)) {
        $jabber_users = array();
        $email_users = array();
        // Get the user's notification type and address
        $get_details = $db->Query("SELECT  notify_type, jabber_id, email_address\n                                 FROM  {users}\n                                WHERE  user_id = ?", array($row['to_user_id']));
        while ($subrow = $db->FetchRow($get_details)) {
            if ($fs->prefs['user_notify'] == '1' && $subrow['notify_type'] == '1' or $fs->prefs['user_notify'] == '2') {
                $email_users[] = $subrow['email_address'];
            } elseif ($fs->prefs['user_notify'] == '1' && $subrow['notify_type'] == '2' or $fs->prefs['user_notify'] == '3') {
                $jabber_users[] = $subrow['jabber_id'];
            }
        }
        $subject = L('notifyfromfs');
        $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);
}
if (isset($conf['general']['reminder_daemon']) && $conf['general']['reminder_daemon'] == 1) {
    send_reminders();
} else {
    die("reminder daemon is disabled");
}
 function sendReminders()
 {
     include_once "application/cron_functions.php";
     send_reminders();
 }
示例#3
0
/**
 * Function to update reminders via a batching method to improve performance and decrease memory overhead.
 *
 * Function that updates reminders and returns an array with a specific data structure.
 * <pre>The data structure of the return array includes the following elements
 *  'total_active_actions'         - Number of active actions.
 *  'total_pre_active_reminders'   - Number of active reminders before processing.
 *  'total_pre_unsent_reminders'   - Number of unsent reminders before processing.
 *  'total_post_active_reminders'  - Number of active reminders after processing.
 *  'total_post_unsent_reminders'  - Number of unsent reminders after processing.
 *  'number_new_reminders'         - Number of new reminders
 *  'number_updated_reminders'     - Number of updated reminders (due_status change)
 *  'number_inactivated_reminders' - Number of inactivated reminders.
 *  'number_unchanged_reminders'   - Number of unchanged reminders.
 * </pre>
 *
 * @param  string   $dateTarget  target date (format Y-m-d H:i:s). If blank then will test with current date as target.
 * @param  integer  $batchSize   number of patients to batch (default is 25; plan to optimize this default setting in the future)
 * @param  integer  $report_id   id of report in database (if already bookmarked)
 * @param  boolean  $also_send   if TRUE, then will also call send_reminder when done
 * @return array                 see above for data structure of returned array
 */
function update_reminders_batch_method($dateTarget = '', $batchSize = 25, $report_id = NULL, $also_send = FALSE)
{
    // Default to a batchsize, if empty
    if (empty($batchSize)) {
        $batchSize = 25;
    }
    // Collect total number of pertinent patients (to calculate batching parameters)
    $totalNumPatients = buildPatientArray('', '', '', NULL, NULL, TRUE);
    // Cycle through the batches and collect/combine results
    if ($totalNumPatients % $batchSize > 0) {
        $totalNumberBatches = floor($totalNumPatients / $batchSize) + 1;
    } else {
        $totalNumberBatches = floor($totalNumPatients / $batchSize);
    }
    // Prepare the database to track/store results
    if ($also_send) {
        $report_id = beginReportDatabase("process_send_reminders", '', $report_id);
    } else {
        $report_id = beginReportDatabase("process_reminders", '', $report_id);
    }
    setTotalItemsReportDatabase($report_id, $totalNumPatients);
    $patient_counter = 0;
    for ($i = 0; $i < $totalNumberBatches; $i++) {
        $patient_counter = $batchSize * ($i + 1);
        if ($patient_counter > $totalNumPatients) {
            $patient_counter = $totalNumPatients;
        }
        $update_rem_log_batch = update_reminders($dateTarget, '', $batchSize * $i + 1, $batchSize);
        if ($i == 0) {
            // For first cycle, simply copy it to update_rem_log
            $update_rem_log = $update_rem_log_batch;
        } else {
            // Debug statements
            //error_log("CDR: ".print_r($update_rem_log,TRUE),0);
            //error_log("CDR: ".($batchSize*$i). " records",0);
            // Integrate batch results into main update_rem_log
            $update_rem_log['total_active_actions'] = $update_rem_log['total_active_actions'] + $update_rem_log_batch['total_active_actions'];
            $update_rem_log['total_pre_active_reminders'] = $update_rem_log['total_pre_active_reminders'] + $update_rem_log_batch['total_pre_active_reminders'];
            $update_rem_log['total_pre_unsent_reminders'] = $update_rem_log['total_pre_unsent_reminders'] + $update_rem_log_batch['total_pre_unsent_reminders'];
            $update_rem_log['number_new_reminders'] = $update_rem_log['number_new_reminders'] + $update_rem_log_batch['number_new_reminders'];
            $update_rem_log['number_updated_reminders'] = $update_rem_log['number_updated_reminders'] + $update_rem_log_batch['number_updated_reminders'];
            $update_rem_log['number_unchanged_reminders'] = $update_rem_log['number_unchanged_reminders'] + $update_rem_log_batch['number_unchanged_reminders'];
            $update_rem_log['number_inactivated_reminders'] = $update_rem_log['number_inactivated_reminders'] + $update_rem_log_batch['number_inactivated_reminders'];
            $update_rem_log['total_post_active_reminders'] = $update_rem_log['total_post_active_reminders'] + $update_rem_log_batch['total_post_active_reminders'];
            $update_rem_log['total_post_unsent_reminders'] = $update_rem_log['total_post_unsent_reminders'] + $update_rem_log_batch['total_post_unsent_reminders'];
        }
        //Update database to track results
        updateReportDatabase($report_id, $patient_counter);
    }
    // Create an array for saving to database (allows combining with the send log)
    $save_log = array();
    $save_log[] = $update_rem_log;
    // Send reminders, if this was selected
    if ($also_send) {
        $log_send = send_reminders();
        $save_log[] = $log_send;
    }
    // Record combo results in database
    finishReportDatabase($report_id, json_encode($save_log));
    // Just return the process reminders array
    return $update_rem_log;
}
示例#4
0
</span><br>
      <span class="text"><?php 
echo htmlspecialchars(xl('Total updated reminders'), ENT_NOQUOTES) . ": " . $update_rem_log['number_updated_reminders'];
?>
</span><br>
      <span class="text"><?php 
echo htmlspecialchars(xl('Total inactivated reminders'), ENT_NOQUOTES) . ": " . $update_rem_log['number_inactivated_reminders'];
?>
</span><br>
      <span class="text"><?php 
echo htmlspecialchars(xl('Total unchanged reminders'), ENT_NOQUOTES) . ": " . $update_rem_log['number_unchanged_reminders'];
?>
</span><br>

    <?php 
$send_rem_log = send_reminders();
?>

    <br><span class="text"><?php 
echo htmlspecialchars(xl('The patient reminders have been sent'), ENT_NOQUOTES) . ":";
?>
</span><br>
      <span class="text"><?php 
echo htmlspecialchars(xl('Total unsent reminders before sending process'), ENT_NOQUOTES) . ": " . $send_rem_log['total_pre_unsent_reminders'];
?>
</span><br>
      <span class="text"><?php 
echo htmlspecialchars(xl('Total unsent reminders after sending process'), ENT_NOQUOTES) . ": " . $send_rem_log['total_post_unsent_reminders'];
?>
</span><br>
      <span class="text"><?php