<?php defined('MOODLE_INTERNAL') || die; require_once $CFG->dirroot . '/blocks/cancelcourse/settingslib.php'; //Custom block functions //Show the heading and description $settings->add(new admin_setting_heading('headerconfig', get_string('headerconfig', 'block_cancelcourse'), get_config_description())); //Send texts? $settings->add(new admin_setting_configcheckbox('cancelcourse/sendtext', get_string('sendtext', 'block_cancelcourse'), get_string('sendtextdesc', 'block_cancelcourse'), 0)); //Shortname of the Providers custom user field $settings->add(new admin_setting_configtext('cancelcourse/providername', get_string('providername', 'block_cancelcourse'), get_string('providerdesc', 'block_cancelcourse'), '', PARAM_ALPHANUM)); //Show config field for each provider $providers = get_providers(); if ($providers[0] !== "" && get_config('cancelcourse', 'sendtext')) { foreach ($providers as $provider) { $settings->add(new admin_setting_configtext(providers_email($provider), $provider, get_string('provideremail', 'block_cancelcourse'), '', PARAM_TEXT)); } } //Send emails? $settings->add(new admin_setting_configcheckbox('cancelcourse/sendemail', get_string('sendemail', 'block_cancelcourse'), get_string('sendemaildesc', 'block_cancelcourse'), 0)); //Subject line for messages? foreach (get_string_manager()->get_list_of_translations() as $subjectlang => $key) { $settings->add(new admin_setting_configtext('cancelcourse/subject' . $subjectlang, $key, get_string('subjectline', 'block_cancelcourse'), 'Class Cancelled', PARAM_RAW)); } //Tweet? $settings->add(new admin_setting_configcheckbox('cancelcourse/sendtweet', get_string('sendtweet', 'block_cancelcourse'), get_string('sendtweetdesc', 'block_cancelcourse'), 0)); //Twitter API keys $settings->add(new admin_setting_configtext('cancelcourse/ckey', get_string('ckey', 'block_cancelcourse'), get_string('ckeydesc', 'block_cancelcourse'), '', PARAM_RAW)); $settings->add(new admin_setting_configtext('cancelcourse/csecret', get_string('csecret', 'block_cancelcourse'), get_string('csecretdesc', 'block_cancelcourse'), '', PARAM_RAW)); $settings->add(new admin_setting_configtext('cancelcourse/utoken', get_string('utoken', 'block_cancelcourse'), get_string('utokendesc', 'block_cancelcourse'), '', PARAM_RAW)); $settings->add(new admin_setting_configtext('cancelcourse/usecret', get_string('usecret', 'block_cancelcourse'), get_string('usecretdesc', 'block_cancelcourse'), '', PARAM_RAW));
?> </select></p> <label for="notes">Notes (optional):</label><br /> <div class="Clear" style="margin-bottom:10px;"></div> <textarea name="notes" id="notes" cols="65" rows="5"></textarea> </form> </div> <div id="update_form" title="Update whiteboard entry" style='display:none'> <form id="wb-update-entry" name="wb-update-entry" method="POST"> <p class="validateUpdateTips">*All fields required, except Notes field</p> <p><label for="date">Date:</label><input class="datepicker" type="text" name="appt_date" maxlength="10" /> <label >Preferred time:</label> <label for="am">AM<input type="radio" id="am" name="ampm" value="AM" /></label><label for="pm">PM<input type="radio" value="PM" name="ampm" /></label></p> <p><label for="provider">Provider:</label><select id="provider" name="provider"> <option value="" selected="selected">[Select a Provider]</option> <?php echo get_providers(); ?> </select> <label for="location">Location:</label><select id="location" name="location"> <option value="" selected="selected">[Select a location]</option> <option value="Sacramento">Sacramento, Morse</option> <option value="Roseville">Roseville, Eureka</option></select></p> <p><label for="appt_type">Appointment Type:</label><select id="appt_type" name="appt_type"> <option value="">[Select one]</option> <?php echo get_appt_types(); ?> </select></p> <label for="notes">Notes (optional):</label><br /> <div class="Clear" style="margin-bottom:10px;"></div> <textarea name="notes" id="notes" cols="65" rows="5"></textarea>
function send_textmessages() { if (get_config('cancelcourse', 'providername') && get_config('cancelcourse', 'sendtext')) { global $COURSE, $CFG; //load the global parameters $context = context_course::instance($COURSE->id); //gets the user ID $userids = get_enrolled_users($context, $withcapability = '', $groupid = 0, $userfields = 'u.*'); $addresses = array(); foreach ($userids as $userid) { //Check each enrolled user for a phone number, and sends the text message to these users. //var_dump(profile_user_record($userid)); if ($userid->phone2) { //only procede if the user has filled in the cell phone number field in their profile. $providerSN = get_config('cancelcourse', 'providername'); //get the custom user field shortname $user_prov = profile_user_record($userid->id)->{$providerSN}; //get the user's cell provider from their profile, if they specified one. //var_dump($userid->email); //for development only $prov_email = get_config('cancelcourse', preg_replace('/\\s+/', '', $user_prov)); //figure out the provider's email suffix. if ($prov_email) { //a cell provider was given. $usersPhone = preg_replace('~.*(\\d{3})[^\\d]*(\\d{3})[^\\d]*(\\d{4}).*~', '$1$2$3', $userid->phone2); //clean up the phone number $addresses[] = $usersPhone . '@' . $prov_email; } else { //no cell provider was given. We're going to have to try them all. $providers = get_providers(); //get the array of providers //$prov_emails = array(); $usersPhone = preg_replace('~.*(\\d{3})[^\\d]*(\\d{3})[^\\d]*(\\d{4}).*~', '$1$2$3', $userid->phone2); //get the user's phone number foreach ($providers as $provider) { $prov_value = get_config('cancelcourse', preg_replace('/\\s+/', '', $provider)); //figure out the provider's email suffix. if ($prov_value) { //if there's a suffix (prevents attempting to send to unconfigured providers) $addresses[] = $usersPhone . '@' . $prov_value; } } } } } return $addresses; } }