コード例 #1
0
 function __construct($course_id)
 {
     global $CFG, $DB;
     $global_config = get_config('block_notifications');
     $Course = new Course();
     if (!$Course->is_registered($course_id) or !$Course->uses_notifications_block($course_id)) {
         echo get_string('rss_not_enabled', 'block_notifications');
         return;
     }
     $User = new User();
     $teacher = $User->get_professor($course_id);
     // if no teacher then add a dummy mail address
     if (empty($teacher)) {
         $teacher = new \stdClass();
         $teacher->firstname = "No";
         $teacher->lastname = "Teacher";
         $teacher->email = "*****@*****.**";
     }
     $course_info = $Course->get_course_info($course_id);
     $course_registration = $Course->get_registration($course_id);
     if ($course_registration->notify_by_rss != 1) {
         return;
         // the rss is not active in the course
     }
     $now = date('r');
     $course_name = $this->standardize($course_info->fullname);
     $course_summary = $this->standardize($course_info->summary);
     $output = "<?xml version=\"1.0\"?>\n\t\t\t\t\t<rss version=\"2.0\">\n\t\t\t\t\t<channel>\n\t\t\t\t\t<title>{$course_name}</title>\n\t\t\t\t\t<link>{$CFG->wwwroot}/course/view.php?id={$course_id}</link>\n\t\t\t\t\t<description>{$course_summary}</description>\n\t\t\t\t\t<language>en-us</language>\n\t\t\t\t\t<pubDate>{$now}</pubDate>\n\t\t\t\t\t<lastBuildDate>{$now}</lastBuildDate>\n\t\t\t\t\t<docs>{$CFG->wwwroot}/course/view.php?id={$course_id}</docs>\n\t\t\t\t\t<managingEditor>{$teacher->email} ({$teacher->firstname} {$teacher->lastname})</managingEditor>\n\t\t\t\t\t<webMaster>helpdesk@elearninglab.org (Helpdesk eLab)</webMaster>";
     $logs = $Course->get_logs($course_id, $global_config->history_length);
     $events = report_eventlist_list_generator::get_all_events_list();
     if (!isset($logs) or !is_array($logs) or count($logs) == 0) {
         $output .= "<item>";
         $output .= '<title>' . get_string('rss_empty_title', 'block_notifications') . '</title>';
         $output .= '<description>' . get_string('rss_empty_description', 'block_notifications') . '</description>';
         $output .= "</item>";
     } else {
         $separator = ' - ';
         foreach ($logs as $log) {
             $output .= "<item>";
             $output .= '<title>' . get_string($log->module, 'block_notifications') . ': ' . $this->standardize($log->name) . '</title>';
             if (preg_match('/deleted/', $log->event)) {
                 $output .= "<link></link>";
             } else {
                 $output .= "<link>" . $this->extract_url($log) . "</link>";
             }
             $output .= "<description>";
             $output .= $this->standardize(preg_replace('/\\\\.*$/', '', $events[$log->event]['raweventname']) . ' on ' . date("r", $log->time_created));
             $output .= "</description>";
             $output .= "</item>";
         }
     }
     $output .= "</channel></rss>";
     header("Content-Type: application/rss+xml");
     echo $output;
 }
コード例 #2
0
<?php

include_once realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . "common.php";
use block_notifications\User;
// print_r($_POST);exit;
// check email preference
$notify_by_email = 0;
if (isset($_POST['notify_by_email']) and $_POST['notify_by_email'] == 1) {
    $notify_by_email = 1;
}
// check sms preference
$notify_by_sms = 0;
if (isset($_POST['notify_by_sms']) and $_POST['notify_by_sms'] == 1) {
    $notify_by_sms = 1;
}
// check user id
$user_id;
if (isset($_POST['user_id'])) {
    $user_id = $_POST['user_id'];
} else {
    exit;
}
// check course id
$course_id;
if (isset($_POST['course_id'])) {
    $course_id = $_POST['course_id'];
} else {
    exit;
}
$User = new User();
$User->update_preferences($user_id, $course_id, $notify_by_email, $notify_by_sms);
コード例 #3
0
 function personal_settings($course_registration)
 {
     global $CFG;
     global $COURSE;
     global $USER;
     $global_config = get_config('block_notifications');
     // if admin user or both sms and email notifications
     // are disabled in the course then do not display user preferences
     if ($global_config->email_channel != 1 and $global_config->sms_channel != 1 or $course_registration->notify_by_email == 0 and $course_registration->notify_by_sms == 0) {
         return '';
     } else {
         $User = new User();
         $user_preferences = $User->get_preferences($USER->id, $COURSE->id);
         // intialize preferences if preferences if necessary
         if (is_null($user_preferences)) {
             $user_preferences = new Object();
             $user_preferences->user_id = $USER->id;
             $user_preferences->course_id = $COURSE->id;
             $user_preferences->notify_by_email = $course_registration->email_notification_preset;
             $user_preferences->notify_by_sms = $course_registration->sms_notification_preset;
             $User->initialize_preferences($user_preferences->user_id, $user_preferences->course_id, $user_preferences->notify_by_email, $user_preferences->notify_by_sms);
         }
         // prepare mail notification status
         $mail_notification_status = '';
         if (isset($user_preferences->notify_by_email) and $user_preferences->notify_by_email == 1) {
             $mail_notification_status = 'checked="checked"';
         }
         $sms_notification_status = '';
         if (isset($user_preferences->notify_by_sms) and $user_preferences->notify_by_sms == 1) {
             $sms_notification_status = 'checked="checked"';
         }
         //user preferences interface
         $up_interface = "<script src='{$CFG->wwwroot}/blocks/notifications/js/jquery-1.4.3.js' type='text/javascript'></script>";
         $up_interface .= "<script src='{$CFG->wwwroot}/blocks/notifications/js/user_preferences_interface.php' type='text/javascript'></script>";
         $up_interface .= '<div id="notifications_config_preferences">';
         // main div
         $up_interface .= '<a id="notifications_user_preferences_trigger" href="#" onclick="show_user_preferences_panel()">';
         $up_interface .= get_string('user_preference_settings', 'block_notifications');
         $up_interface .= '</a>';
         $up_interface .= '<div id="notifications_user_preferences" style="display:none">';
         // div a
         $up_interface .= '<div>';
         // div b
         $up_interface .= get_string('user_preference_header', 'block_notifications');
         $up_interface .= '</div>';
         // div b end
         $up_interface .= '<form id="user_preferences" action="">';
         $up_interface .= '<input type="hidden" name="user_id" value="' . $USER->id . '" />';
         $up_interface .= '<input type="hidden" name="course_id" value="' . $COURSE->id . '" />';
         if ($global_config->email_channel == 1 and $course_registration->notify_by_email == 1) {
             $up_interface .= '<div>';
             // div c
             $up_interface .= "<input type='checkbox' name='notify_by_email' value='1' {$mail_notification_status} />";
             $up_interface .= get_string('notify_by_email', 'block_notifications');
             $up_interface .= '</div>';
             // div c end
         }
         if (class_exists('block_notifications\\SMS') and $global_config->sms_channel == 1 and $course_registration->notify_by_sms == 1) {
             $up_interface .= '<div>';
             // div d end
             $up_interface .= "<input type='checkbox' name='notify_by_sms' value='1' {$sms_notification_status} />";
             $up_interface .= get_string('notify_by_sms', 'block_notifications');
             $up_interface .= '</div>';
             // div d end
         }
         $up_interface .= '</form>';
         $up_interface .= '<input type="button" name="save_user_preferences" value="' . get_string('savechanges') . '" onclick="save_user_preferences()" />';
         $up_interface .= '<input type="button" name="cancel" value="' . get_string('cancel') . '" onclick="hide_user_preferences_panel()" />';
         $up_interface .= '</div>';
         // div a end
         $up_interface .= '</div>';
         // main div end
         return $up_interface;
     }
     /*
      */
 }
コード例 #4
0
 public function execute()
 {
     global $CFG;
     echo "\n\n****** notifications :: begin ******";
     $User = new User();
     // clean deleted users data
     $User->collect_garbage();
     $Course = new Course();
     // clean deleted courses data
     $Course->collect_garbage();
     // get the list of courses that are using this block
     $courses = $Course->get_all_courses_using_notifications_block();
     // if no courses are using this block exit
     if (!is_array($courses) or count($courses) < 1) {
         echo "\n--> None course is using notifications plugin.";
         echo "\n****** notifications :: end ******\n\n";
         return;
     }
     $global_config = get_config('block_notifications');
     echo "\n\nNumber of courses using the block: " . count($courses);
     foreach ($courses as $course) {
         // if course is not visible then skip
         if ($course->visible == 0) {
             continue;
         }
         // if the course has not been registered so far then register
         echo "\n--> Processing course: {$course->fullname}";
         if (!$Course->is_registered($course->id)) {
             $Course->register($course->id, time());
         }
         // get the course registration
         $course_registration = $Course->get_registration($course->id);
         // initialize user preferences and check for new enrolled users in this course
         $enrolled_users = $User->get_all_users_enrolled_in_the_course($course->id);
         foreach ($enrolled_users as $user) {
             // check if the user has preferences
             $user_preferences = $User->get_preferences($user->id, $course->id);
             // if the user has not preferences than set the default
             if (is_null($user_preferences)) {
                 $user_preferences = new \Object();
                 $user_preferences->user_id = $user->id;
                 $user_preferences->course_id = $course->id;
                 $user_preferences->notify_by_email = $course_registration->email_notification_preset;
                 $user_preferences->notify_by_sms = $course_registration->sms_notification_preset;
                 $User->initialize_preferences($user_preferences->user_id, $user_preferences->course_id, $user_preferences->notify_by_email, $user_preferences->notify_by_sms);
             }
         }
         // if course log entry does not exist
         // or the last notification time is older than two days
         // then reinitialize course log
         if (!$Course->log_exists($course->id) or $course_registration->last_notification_time + 48 * 3600 < time()) {
             $Course->initialize_log($course->id);
         }
         $Course->update_log($course->id);
         // check if the course has something new or not
         $changelist = $Course->get_recent_activities($course->id);
         // update the last notification time
         $Course->update_last_notification_time($course->id, time());
         if (empty($changelist)) {
             continue;
         }
         // check the next course. No new items in this one.
         foreach ($enrolled_users as $user) {
             // get user preferences
             $user_preferences = $User->get_preferences($user->id, $course->id);
             // if the email notification is enabled in the course
             // and if the user has set the emailing notification in preferences
             // then send a notification by email
             if ($global_config->email_channel == 1 and $course_registration->notify_by_email == 1 and $user_preferences->notify_by_email == 1) {
                 $eMail = new eMail();
                 $eMail->notify($changelist, $user, $course);
             }
             // if the sms notification is enabled in the course
             // and if the user has set the sms notification in preferences
             // and if the user has set the mobile phone number
             // then send a notification by sms
             if (class_exists('block_notifications\\SMS') and $global_config->sms_channel == 1 and $course_registration->notify_by_sms == 1 and $user_preferences->notify_by_sms == 1 and !empty($user->phone2)) {
                 $sms = new SMS();
                 $sms->notify($changelist, $user, $course);
             }
         }
     }
     echo "\n****** notifications :: end ******\n\n";
 }