function organizer_send_message($sender, $receiver, $slot, $type, $digest = null, $customdata = array()) { global $DB; if ($type == 'register_reminder:student') { $organizer = $slot; } else { $organizer = $DB->get_record('organizer', array('id' => $slot->organizerid)); } $sender = is_int($sender) ? $DB->get_record('user', array('id' => $sender)) : $sender; $receiver = is_int($receiver) ? $DB->get_record('user', array('id' => $receiver)) : $receiver; $module = $DB->get_record('modules', array('name' => 'organizer')); $cm = $DB->get_record('course_modules', array('module' => $module->id, 'instance' => $organizer->id)); $course = $DB->get_record('course', array('id' => $cm->course)); $context = context_course::instance($cm->course); $roles = get_user_roles($context, $receiver->id); $now = time(); if (!$cm->visible || $cm->availablefrom && $cm->availablefrom > $now || $cm->availableuntil && $cm->availableuntil < $now || count($roles) == 0) { return false; } $namesplit = explode(':', $type); $strings = new stdClass(); $strings->sendername = fullname($sender); $strings->receivername = fullname($receiver); if ($type != 'register_reminder:student') { $strings->date = userdate($slot->starttime, get_string('datetemplate', 'organizer')); $strings->time = userdate($slot->starttime, get_string('timetemplate', 'organizer')); $strings->location = $slot->location; } $strings->organizername = $organizer->name; $strings->coursefullname = $course->fullname; $strings->courseshortname = $course->shortname; $strings->courseid = $course->idnumber == "" ? "" : $course->idnumber . ' '; if ($namesplit[0] == "edit_notify") { $strings->slot_teacher = $slot->teachervisible == 1 ? fullname($DB->get_record('user', array('id' => $slot->teacherid))) : get_string('teacherinvisible', 'organizer'); $strings->slot_location = organizer_location_link($slot); $strings->slot_maxparticipants = $slot->maxparticipants; $strings->slot_comments = $slot->comments; } $courseurl = new moodle_url('/mod/organizer/view.php', array('id' => $cm->id)); $strings->courselink = html_writer::link($courseurl, $course->fullname); if ($organizer->isgrouporganizer) { if (strpos($type, 'register_notify') !== false || strpos($type, 'group_registration_notify') !== false) { $group = groups_get_user_groups($organizer->course, $sender->id); $group = reset($group); $group = reset($group); $group = groups_get_group($group); } else { $group = groups_get_user_groups($organizer->course, $receiver->id); $group = reset($group); $group = reset($group); $group = groups_get_group($group); } $strings->groupname = $group->name; $type .= ":group"; } if ($namesplit[0] == "eval_notify_newappointment") { $namesplit[0] = "eval_notify"; } $message = new stdClass(); $message->modulename = 'organizer'; $message->component = 'mod_organizer'; $message->name = "{$namesplit['0']}:{$namesplit['1']}"; $message->notification = 1; $message->fullmessageformat = FORMAT_PLAIN; $message->userfrom = $sender; $message->userto = $receiver; if (isset($digest)) { $strings->digest = $digest; $type .= ":digest"; } $message->subject = get_string("{$type}:subject", 'organizer', $strings); $message->message = get_string("{$type}:fullmessage", 'organizer', $strings); $message->fullmessage = get_string("{$type}:fullmessage", 'organizer', $strings); $message->fullmessagehtml = organizer_make_html(get_string("{$type}:fullmessage", 'organizer', $strings), $organizer, $cm, $course); if (isset($customdata['custommessage'])) { $message->fullmessage = str_replace('{$a->custommessage}', $customdata['custommessage'], $message->fullmessage); $message->fullmessagehtml = str_replace('{$a->custommessage}', $customdata['custommessage'], $message->fullmessagehtml); } $message->smallmessage = get_string("{$type}:smallmessage", 'organizer', $strings); if (ORGANIZER_ENABLE_MESSAGING) { return message_send($message); } else { return false; } }
function organizer_organizer_generate_registration_table_content($columns, $params, $organizer, $context, &$popups) { global $DB; $groupmode = organizer_is_group_mode(); if ($groupmode) { $entries = organizer_organizer_organizer_get_status_table_entries_group($params); } else { $entries = organizer_organizer_get_status_table_entries($params); } $rows = array(); if (count($entries) == 0) { $row = new html_table_row(); $cell = $row->cells[] = new html_table_cell(get_string('status_no_entries', 'organizer')); $cell->colspan = 7; $cell->style .= ' vertical-align: middle; text-align: center;'; $rows[] = $row; return $rows; } foreach ($entries as $entry) { if ($entry->status == ORGANIZER_APP_STATUS_INVALID) { continue; } $row = new html_table_row(); foreach ($columns as $column) { switch ($column) { case 'group': case 'participants': if ($groupmode) { if ($params['psort'] == 'id') { $orderby = "ORDER BY idnumber {$params['pdir']}, lastname ASC, firstname ASC"; } else { $orderby = "ORDER BY lastname {$params['pdir']}, firstname {$params['pdir']}, idnumber ASC"; } $members = $DB->get_fieldset_sql('SELECT userid FROM {groups_members} gm INNER JOIN {user} u ON gm.userid = u.id WHERE groupid = :groupid ' . $orderby, array('groupid' => $entry->id)); $list = "<em>{$entry->name}</em><br/ >"; foreach ($members as $member) { $idnumber = organizer_get_user_idnumber($member); $list .= organizer_get_name_link($member) . ($idnumber ? " ({$idnumber}) " : " ") . ($entry->comments != '' ? organizer_popup_icon(ORGANIZER_ICON_STUDENT_COMMENT, $entry->comments) : organizer_get_img('pix/transparent.png', '', '')); if ($member == $entry->applicantid) { $list .= ' ' . organizer_get_img('pix/applicant.gif', 'applicant', get_string('applicant', 'organizer')) . '<br/>'; } else { $list .= ' ' . organizer_get_img('pix/transparent.png', '', '') . '<br />'; } } $cell = $row->cells[] = new html_table_cell($list); } else { $cell = $row->cells[] = new html_table_cell(organizer_get_name_link($entry->id) . ($entry->idnumber ? " ({$entry->idnumber})" : "")); } break; case 'status': $cell = $row->cells[] = new html_table_cell(organizer_get_status_icon_new($entry->status)); break; case 'datetime': $cell = $row->cells[] = new html_table_cell(organizer_date_time($entry)); $cell->style .= " text-align: left;"; break; case 'appdetails': if ($groupmode) { if ($params['psort'] == 'id') { $orderby = "ORDER BY idnumber {$params['pdir']}, lastname ASC, firstname ASC"; } else { $orderby = "ORDER BY lastname {$params['pdir']}, firstname {$params['pdir']}, idnumber ASC"; } $members = $DB->get_fieldset_sql('SELECT userid FROM {groups_members} gm INNER JOIN {user} u ON gm.userid = u.id WHERE groupid = :groupid ' . $orderby, array('groupid' => $entry->id)); $list = ''; foreach ($members as $member) { $list .= '<br />'; $list .= organizer_reg_organizer_app_details($organizer, $member); } $cell = $row->cells[] = new html_table_cell($list); } else { $cell = $row->cells[] = new html_table_cell(organizer_reg_organizer_app_details($organizer, $entry->id, $popups)); } break; case 'location': $cell = $row->cells[] = new html_table_cell(organizer_location_link($entry)); break; case 'teacher': $cell = $row->cells[] = new html_table_cell(organizer_teacher_data($params, $entry, $popups)); break; case 'actions': $cell = $row->cells[] = new html_table_cell(organizer_teacher_action_new($params, $entry, $context)); $cell->style .= " text-align: center;"; break; } $cell->style .= ' vertical-align: middle;'; } $rows[] = $row; } return $rows; }