function organizer_prepare_and_send_message($data, $type) { global $DB, $USER; require_once 'lib.php'; switch ($type) { case 'edit_notify:student': foreach ($data->slots as $slotid) { $apps = $DB->get_records('organizer_slot_appointments', array('slotid' => $slotid)); $slot = $DB->get_record('organizer_slots', array('id' => $slotid)); foreach ($apps as $app) { if ($app->groupid && !groups_is_member($app->groupid, $app->userid)) { continue; } organizer_send_message(intval($slot->teacherid), intval($app->userid), $slot, $type); } } break; case 'edit_notify:teacher': foreach ($data->slots as $slotid) { $slot = $DB->get_record('organizer_slots', array('id' => $slotid)); if ($USER->id != $slot->teacherid) { organizer_send_message(intval($USER->id), intval($slot->teacherid), $slot, $type); } } break; case 'eval_notify:student': if (isset($data->apps) && count($data->apps) > 0) { foreach ($data->apps as $appid => $app) { $app = $DB->get_record('organizer_slot_appointments', array('id' => $appid)); if ($app->groupid && !groups_is_member($app->groupid, $app->userid)) { continue; } $slot = $DB->get_record('organizer_slots', array('id' => $app->slotid)); if ($app->allownewappointments == 1) { $type = 'eval_notify_newappointment:student'; } organizer_send_message(intval($USER->id), intval($app->userid), $slot, $type); } } break; case 'register_notify:teacher:register': // TODO: check how it was actually originally defined $slot = $DB->get_record('organizer_slots', array('id' => $data)); $organizer = $DB->get_record('organizer', array('id' => $slot->organizerid)); if ($organizer->emailteachers == ORGANIZER_MESSAGES_ALL) { organizer_send_message(intval($USER->id), intval($slot->teacherid), $slot, $type); } break; case 'register_notify:teacher:reregister': case 'register_notify:teacher:unregister': $slot = $DB->get_record('organizer_slots', array('id' => $data)); $organizer = $DB->get_record('organizer', array('id' => $slot->organizerid)); if ($organizer->emailteachers == ORGANIZER_MESSAGES_RE_UNREG || $organizer->emailteachers == ORGANIZER_MESSAGES_ALL) { organizer_send_message(intval($USER->id), intval($slot->teacherid), $slot, $type); } break; case 'group_registration_notify:student:register': case 'group_registration_notify:student:reregister': case 'group_registration_notify:student:unregister': $slot = $DB->get_record('organizer_slots', array('id' => $data)); $apps = $DB->get_records('organizer_slot_appointments', array('slotid' => $slot->id)); foreach ($apps as $app) { if ($app->groupid && !groups_is_member($app->groupid, $app->userid)) { continue; } if ($app->userid != $USER->id) { organizer_send_message(intval($USER->id), intval($app->userid), $slot, $type); } } break; case 'register_reminder:student': return organizer_send_message(intval($USER->id), intval($data['user']), $data['organizer'], $type, null, array('custommessage' => $data['custommessage'])); default: print_error('Not debugged yet!'); } return; }
function organizer_delete_appointment_slot($id) { global $DB, $USER; if (!$DB->get_record('organizer_slots', array('id' => $id))) { return false; } $eventid = $DB->get_field('organizer_slots', 'eventid', array('id' => $id)); // if student is registered to this slot, send a message $appointments = $DB->get_records('organizer_slot_appointments', array('slotid' => $id)); $notified_users = 0; if (count($appointments) > 0) { // someone was allready registered to this slot $slot = new organizer_slot($id); foreach ($appointments as $appointment) { $reciever = intval($appointment->userid); organizer_send_message($USER, $reciever, $slot, 'slotdeleted_notify:student'); $notified_users++; } } $DB->delete_records('event', array('id' => $eventid)); $DB->delete_records('organizer_slot_appointments', array('slotid' => $id)); $DB->delete_records('organizer_slots', array('id' => $id)); return $notified_users; }
function organizer_create_digest($teacherid) { require_once dirname(__FILE__) . '/messaging.php'; global $DB; $now = time(); $success = true; $params = array('now' => $now, 'teacherid' => $teacherid); $slotsquery = 'SELECT * FROM {organizer_slots} s WHERE s.starttime - s.notificationtime < :now AND s.notified = 0 AND s.teacherid = :teacherid'; $digest = ''; $slots = $DB->get_records_sql($slotsquery, $params); foreach ($slots as $slot) { if (isset($slot)) { $date = userdate($slot->starttime, get_string('datetemplate', 'organizer')); $time = userdate($slot->starttime, get_string('timetemplate', 'organizer')); } $digest .= $date . ', ' . $time . ' @ ' . $slot->location . '; '; $slot->notified = 1; $DB->update_record('organizer_slots', $slot); } $success = organizer_send_message(intval($slot->teacherid), intval($slot->teacherid), $slot, 'appointment_reminder:teacher:digest', $digest); return $success; }