Exemple #1
0
 /**
  * Form validation
  *
  * @param array $data
  * @param array $files
  * @return array $errors An array of validataion errors for the form.
  */
 function validation($data, $files)
 {
     global $COURSE, $DB;
     $errors = parent::validation($data, $files);
     $name = trim($data['name']);
     if (isset($data['idnumber'])) {
         $idnumber = trim($data['idnumber']);
     } else {
         $idnumber = '';
     }
     if ($data['id'] and $grouping = $DB->get_record('groupings', array('id' => $data['id']))) {
         if (core_text::strtolower($grouping->name) != core_text::strtolower($name)) {
             if (groups_get_grouping_by_name($COURSE->id, $name)) {
                 $errors['name'] = get_string('groupingnameexists', 'group', $name);
             }
         }
         if (!empty($idnumber) && $grouping->idnumber != $idnumber) {
             if (groups_get_grouping_by_idnumber($COURSE->id, $idnumber)) {
                 $errors['idnumber'] = get_string('idnumbertaken');
             }
         }
     } else {
         if (groups_get_grouping_by_name($COURSE->id, $name)) {
             $errors['name'] = get_string('groupingnameexists', 'group', $name);
         } else {
             if (!empty($idnumber) && groups_get_grouping_by_idnumber($COURSE->id, $idnumber)) {
                 $errors['idnumber'] = get_string('idnumbertaken');
             }
         }
     }
     return $errors;
 }
 /**
  * The form's definition.
  */
 public function definition()
 {
     $mform =& $this->_form;
     $data = $this->_customdata;
     $mform->addElement('hidden', 'action', 'upload_group_data');
     $mform->setType('action', PARAM_ALPHA);
     $mform->addElement('hidden', 'id', $data['id']);
     $mform->setType('id', PARAM_INT);
     $mform->addElement('html', get_string('upload_help', 'block_upload_group'));
     $mform->addElement('header', 'upload_group_data', get_string('upload_group_data', 'block_upload_group'));
     // Add a file manager.
     $mform->addElement('filepicker', 'group_data', '');
     // Add the encoding option.
     $choices = core_text::get_encodings();
     $mform->addElement('select', 'encoding', get_string('encoding', 'block_upload_group'), $choices);
     $mform->setDefault('encoding', 'UTF-8');
     // Add the delimiter option.
     $choices = csv_import_reader::get_delimiter_list();
     $mform->addElement('select', 'delimiter', get_string('delimiter', 'block_upload_group'), $choices);
     if (array_key_exists('cfg', $choices)) {
         $mform->setDefault('delimiter_name', 'cfg');
     } else {
         if (get_string('listsep', 'langconfig') == ';') {
             $mform->setDefault('delimiter_name', 'semicolon');
         } else {
             $mform->setDefault('delimiter_name', 'comma');
         }
     }
     $choices = array('10' => 10, '20' => 20, '100' => 100, '1000' => 1000, '100000' => 100000);
     $mform->addElement('select', 'preview_num', get_string('row_preview_num', 'block_upload_group'), $choices);
     $mform->setType('preview_num', PARAM_INT);
     $this->add_action_buttons(true, get_string('submit_group_data', 'block_upload_group'));
 }
Exemple #3
0
    function validation($data, $files) {
        global $DB, $CFG;
        $id = optional_param('id', -1, PARAM_INT);
        $errors = array();
        $errors = parent::validation($data, $files);
        if ($data['schoolid'] == 0) {
            $errors['schoolid'] = get_string('schoolrequired', 'local_collegestructure');
        }
        if ($data['id'] < 0) {
            $examtypes1 = $DB->get_record('local_examtypes', array('schoolid' => $data['schoolid'], 'examtype' => $data['examtype']));
            $exam1 = core_text::strtolower($examtypes1->examtype);
            $exam2 = core_text::strtolower($data['examtype']);
            if ($exam1 == $exam2) {
                $errors['examtype'] = get_string('examexits', 'local_examtype');
            }
        }

        if ($data['id'] > 0) {
            $exists = $DB->get_field('local_examtypes', 'examtype', array('id' => $id));
            if (!($exists === $data['examtype'] )) {
                $examtypes1 = $DB->get_record('local_examtypes', array('schoolid' => $data['schoolid'], 'examtype' => $data['examtype']));
                $exam1 = core_text::strtolower($examtypes1->examtype);
                $exam2 = core_text::strtolower($data['examtype']);
                if ($exam1 == $exam2) {
                    $errors['examtype'] = get_string('examexits', 'local_examtype');
                }
            }
        }
        return $errors;
    }
 /**
  * Defines the form, which will have:
  *  - Input for courses csv.
  *  - Input for users csv.
  *  - Input for logs csv.
  *  - Select for csv delimiter.
  *  - Select for files encoding.
  */
 public function definition()
 {
     $mform = $this->_form;
     $mform->addElement('header', 'settingsheader', get_string('upload', 'block_mycourse_recommendations'));
     $mform->addElement('static', 'description', '', get_string('upload_desc', 'block_mycourse_recommendations'));
     $mform->addElement('static', 'description', get_string('coursefile', 'block_mycourse_recommendations'), get_string('coursefile_desc', 'block_mycourse_recommendations'));
     $mform->addElement('filepicker', 'courses', '');
     $mform->addRule('courses', null, 'required');
     $mform->addElement('static', 'description', get_string('usersfile', 'block_mycourse_recommendations'), get_string('usersfile_desc', 'block_mycourse_recommendations'));
     $mform->addElement('filepicker', 'users', '');
     $mform->addRule('users', null, 'required');
     $mform->addElement('static', 'description', get_string('logsfile', 'block_mycourse_recommendations'), get_string('logsfile_desc', 'block_mycourse_recommendations'));
     $mform->addElement('filepicker', 'logs', '');
     $mform->addRule('logs', null, 'required');
     $choices = \csv_import_reader::get_delimiter_list();
     $mform->addElement('select', 'delimiter_name', get_string('csvdelimiter', 'tool_uploaduser'), $choices);
     if (array_key_exists('cfg', $choices)) {
         $mform->setDefault('delimiter_name', 'cfg');
     } else {
         if (get_string('listsep', 'langconfig') == ';') {
             $mform->setDefault('delimiter_name', 'semicolon');
         } else {
             $mform->setDefault('delimiter_name', 'comma');
         }
     }
     $choices = \core_text::get_encodings();
     $mform->addElement('select', 'encoding', get_string('encoding', 'tool_uploaduser'), $choices);
     $mform->setDefault('encoding', 'UTF-8');
     $this->add_action_buttons(false, get_string('uploaddata', 'block_mycourse_recommendations'));
 }
 /**
  * Add appropriate form elements to the criteria form
  *
  * @param stdClass $data details of overall criterion
  */
 public function config_form_criteria($data)
 {
     global $OUTPUT;
     $prefix = 'criteria-' . $this->id;
     if (count($data->criteria) > 2) {
         echo $OUTPUT->box_start();
         if (!empty($this->description)) {
             $badge = new badge($this->badgeid);
             echo $OUTPUT->box(format_text($this->description, $this->descriptionformat, array('context' => $badge->get_context())), 'criteria-description');
         }
         echo $OUTPUT->heading($this->get_title(), 2);
         $agg = $data->get_aggregation_methods();
         if (!$data->is_locked() && !$data->is_active()) {
             $editurl = new moodle_url('/badges/criteria_settings.php', array('badgeid' => $this->badgeid, 'edit' => true, 'type' => $this->criteriatype, 'crit' => $this->id));
             $editaction = $OUTPUT->action_icon($editurl, new pix_icon('t/edit', get_string('edit')), null, array('class' => 'criteria-action'));
             echo $OUTPUT->box($editaction, array('criteria-header'));
             $url = new moodle_url('criteria.php', array('id' => $data->id, 'sesskey' => sesskey()));
             echo $OUTPUT->single_select($url, 'update', $agg, $data->get_aggregation_method($this->criteriatype), null, null, array('aria-describedby' => 'overall'));
             echo html_writer::span(get_string('overallcrit', 'badges'), '', array('id' => 'overall'));
         } else {
             echo $OUTPUT->box(get_string('criteria_descr_' . $this->criteriatype, 'badges', core_text::strtoupper($agg[$data->get_aggregation_method()])), 'clearfix');
         }
         echo $OUTPUT->box_end();
     }
 }
Exemple #6
0
 /**
  * Return the user devices for a specific app.
  *
  * @param string $appname the app name .
  * @param int $userid if empty take the current user.
  * @return array all the devices
  */
 public function get_user_devices($appname, $userid = null)
 {
     global $USER, $DB;
     if (empty($userid)) {
         $userid = $USER->id;
     }
     $devices = array();
     $params = array('appid' => $appname, 'userid' => $userid);
     // First, we look all the devices registered for this user in the Moodle core.
     // We are going to allow only ios devices (since these are the ones that supports PUSH notifications).
     $userdevices = $DB->get_records('user_devices', $params);
     foreach ($userdevices as $device) {
         if (core_text::strtolower($device->platform)) {
             // Check if the device is known by airnotifier.
             if (!($airnotifierdev = $DB->get_record('message_airnotifier_devices', array('userdeviceid' => $device->id)))) {
                 // We have to create the device token in airnotifier.
                 if (!$this->create_token($device->pushid)) {
                     continue;
                 }
                 $airnotifierdev = new stdClass();
                 $airnotifierdev->userdeviceid = $device->id;
                 $airnotifierdev->enable = 1;
                 $airnotifierdev->id = $DB->insert_record('message_airnotifier_devices', $airnotifierdev);
             }
             $device->id = $airnotifierdev->id;
             $device->enable = $airnotifierdev->enable;
             $devices[] = $device;
         }
     }
     return $devices;
 }
 /**
  * The standard form definiton.
  */
 public function definition()
 {
     $mform = $this->_form;
     $selectedfields = $this->_customdata['selectedfields'];
     $overrides = $this->_customdata['overrides'];
     $fields = tool_downloaddata_processor::get_valid_course_fields();
     if (empty($selectedfields)) {
         $selectedfields = array(get_string('noselectedfields', 'tool_downloaddata'));
     }
     $mform->addElement('header', 'generalhdr', get_string('downloadcourses', 'tool_downloaddata'));
     $formatchoices = array(tool_downloaddata_processor::FORMAT_CSV => get_string('formatcsv', 'tool_downloaddata'), tool_downloaddata_processor::FORMAT_XLS => get_string('formatxls', 'tool_downloaddata'));
     $mform->addElement('select', 'format', get_string('format', 'tool_downloaddata'), $formatchoices);
     $mform->setDefault('format', $this->_customdata['format']);
     $encodings = core_text::get_encodings();
     $mform->addElement('select', 'encoding', get_string('encoding', 'tool_downloaddata'), $encodings);
     $mform->setDefault('encoding', $this->_customdata['encoding']);
     $mform->disabledIf('encoding', 'format', 'noteq', tool_downloaddata_processor::FORMAT_CSV);
     $delimiters = csv_import_reader::get_delimiter_list();
     $mform->addElement('select', 'delimiter_name', get_string('csvdelimiter', 'tool_downloaddata'), $delimiters);
     $mform->setDefault('delimiter_name', $this->_customdata['delimiter_name']);
     $mform->disabledIf('delimiter_name', 'format', 'noteq', tool_downloaddata_processor::FORMAT_CSV);
     $useoverrides = array('true' => 'Yes', 'false' => 'No');
     $mform->addElement('select', 'useoverrides', get_string('useoverrides', 'tool_downloaddata'), $useoverrides);
     $mform->setDefault('useoverrides', $this->_customdata['useoverrides']);
     $mform->addHelpButton('useoverrides', 'useoverrides', 'tool_downloaddata');
     $sortbycategorypath = array('true' => 'Yes', 'false' => 'No');
     $mform->addElement('select', 'sortbycategorypath', get_string('sortbycategorypath', 'tool_downloaddata'), $sortbycategorypath);
     $mform->setDefault('sortbycategorypath', $this->_customdata['sortbycategorypath']);
     $mform->addHelpButton('sortbycategorypath', 'sortbycategorypath', 'tool_downloaddata');
     $mform->addElement('header', 'fieldshdr', get_string('fields', 'tool_downloaddata'));
     $mform->setExpanded('fieldshdr', true);
     // Creating the field selection elements.
     $objs = array();
     $objs[0] = $mform->createElement('select', 'availablefields', get_string('available', 'tool_downloaddata'), $fields, 'size="10"');
     $objs[0]->setMultiple(true);
     $objs[1] = $mform->createElement('select', 'selectedfields', get_string('selected', 'tool_downloaddata'), $selectedfields, 'size="10"');
     $objs[1]->setMultiple(true);
     $group = $mform->addElement('group', 'fieldsgroup', get_string('fields', 'tool_downloaddata'), $objs, '  ', false);
     $mform->addHelpButton('fieldsgroup', 'fields', 'tool_downloaddata');
     // Creating the buttons for the field selection elements.
     $objs = array();
     $objs[] = $mform->createElement('submit', 'addfieldselection', get_string('addfieldselection', 'tool_downloaddata'));
     $objs[] = $mform->createElement('submit', 'removefieldselection', get_string('removefieldselection', 'tool_downloaddata'));
     $objs[] = $mform->createElement('submit', 'addallfields', get_string('addallfields', 'tool_downloaddata'));
     $objs[] = $mform->createElement('submit', 'removeallfields', get_string('removeallfields', 'tool_downloaddata'));
     $group = $mform->addElement('group', 'buttonsgroup', '', $objs, array(' ', '<br/>'), false);
     $mform->addElement('header', 'overrideshdr', get_string('overrides', 'tool_downloaddata'));
     $mform->addElement('textarea', 'overrides', get_string('overrides', 'tool_downloaddata'), 'wrap="virtual" rows="3" cols="45"');
     $mform->setType('overrides', PARAM_RAW);
     $mform->setDefault('overrides', $overrides);
     $mform->addHelpButton('overrides', 'overrides', 'tool_downloaddata');
     if (empty($overrides)) {
         $mform->setExpanded('overrideshdr', false);
     } else {
         $mform->setExpanded('overrideshdr', true);
     }
     $this->add_action_buttons(false, get_string('download', 'tool_downloaddata'));
     $template = '<label class="qflabel" style="vertical-align:top">{label}</label> {element}';
     $mform->defaultRenderer()->setGroupElementTemplate($template, 'fieldsgroup');
 }
Exemple #8
0
 function definition()
 {
     $mform = $this->_form;
     $mform->addElement('header', 'settingsheader', get_string('upload'));
     $mform->addElement('filepicker', 'userfile', get_string('file'));
     $mform->addRule('userfile', null, 'required');
     $choices = csv_import_reader::get_delimiter_list();
     $mform->addElement('select', 'delimiter_name', get_string('csvdelimiter', 'tool_uploaduser'), $choices);
     if (array_key_exists('cfg', $choices)) {
         $mform->setDefault('delimiter_name', 'cfg');
     } else {
         if (get_string('listsep', 'langconfig') == ';') {
             $mform->setDefault('delimiter_name', 'semicolon');
         } else {
             $mform->setDefault('delimiter_name', 'comma');
         }
     }
     $choices = core_text::get_encodings();
     $mform->addElement('select', 'encoding', get_string('encoding', 'tool_uploaduser'), $choices);
     $mform->setDefault('encoding', 'UTF-8');
     $choices = array('10' => 10, '20' => 20, '100' => 100, '1000' => 1000, '100000' => 100000);
     $mform->addElement('select', 'previewrows', get_string('rowpreviewnum', 'tool_uploaduser'), $choices);
     $mform->setType('previewrows', PARAM_INT);
     $this->add_action_buttons(false, get_string('uploadusers', 'tool_uploaduser'));
 }
 /**
  * Form definition
  */
 public function definition()
 {
     $mform =& $this->_form;
     $course = $this->_customdata['course'];
     $config = get_config('local_mass_enroll');
     $mform->addElement('header', 'general', '');
     // Fill in the data depending on page params.
     // Later using set_data.
     $mform->addElement('filepicker', 'attachment', get_string('location', 'enrol_flatfile'));
     $mform->addRule('attachment', null, 'required');
     $choices = csv_import_reader::get_delimiter_list();
     $mform->addElement('select', 'delimiter_name', get_string('csvdelimiter', 'tool_uploaduser'), $choices);
     if (array_key_exists('cfg', $choices)) {
         $mform->setDefault('delimiter_name', 'cfg');
     } else {
         if (get_string('listsep', 'langconfig') == ';') {
             $mform->setDefault('delimiter_name', 'semicolon');
         } else {
             $mform->setDefault('delimiter_name', 'comma');
         }
     }
     $choices = \core_text::get_encodings();
     $mform->addElement('select', 'encoding', get_string('encoding', 'tool_uploaduser'), $choices);
     $mform->setDefault('encoding', 'UTF-8');
     $ids = array('idnumber' => get_string('idnumber', 'local_mass_enroll'), 'username' => get_string('username', 'local_mass_enroll'), 'email' => get_string('email'));
     $mform->addElement('select', 'firstcolumn', get_string('firstcolumn', 'local_mass_enroll'), $ids);
     $mform->setDefault('firstcolumn', 'idnumber');
     $mform->addElement('selectyesno', 'mailreport', get_string('mailreport', 'local_mass_enroll'));
     $mform->setDefault('mailreport', (int) $config->mailreportdefault);
     // Buttons.
     $this->add_action_buttons(true, get_string('unenroll', 'local_mass_enroll'));
     $mform->addElement('hidden', 'id', $course->id);
     $mform->setType('id', PARAM_INT);
 }
Exemple #10
0
 /**
  * Define this form - called by the parent constructor
  */
 public function definition()
 {
     global $COURSE, $USER;
     $mform = $this->_form;
     $params = $this->_customdata;
     $mform->addElement('header', 'uploadgrades', get_string('uploadgrades', 'assignfeedback_offline'));
     $fileoptions = array('subdirs' => 0, 'maxbytes' => $COURSE->maxbytes, 'accepted_types' => 'csv', 'maxfiles' => 1, 'return_types' => FILE_INTERNAL);
     $mform->addElement('filepicker', 'gradesfile', get_string('uploadafile'), null, $fileoptions);
     $mform->addRule('gradesfile', get_string('uploadnofilefound'), 'required', null, 'client');
     $mform->addHelpButton('gradesfile', 'gradesfile', 'assignfeedback_offline');
     $encodings = core_text::get_encodings();
     $mform->addElement('select', 'encoding', get_string('encoding', 'grades'), $encodings);
     $mform->addHelpButton('encoding', 'encoding', 'grades');
     $radio = array();
     $radio[] = $mform->createElement('radio', 'separator', null, get_string('septab', 'grades'), 'tab');
     $radio[] = $mform->createElement('radio', 'separator', null, get_string('sepcomma', 'grades'), 'comma');
     $radio[] = $mform->createElement('radio', 'separator', null, get_string('sepcolon', 'grades'), 'colon');
     $radio[] = $mform->createElement('radio', 'separator', null, get_string('sepsemicolon', 'grades'), 'semicolon');
     $mform->addGroup($radio, 'separator', get_string('separator', 'grades'), ' ', false);
     $mform->addHelpButton('separator', 'separator', 'grades');
     $mform->setDefault('separator', 'comma');
     $mform->addElement('checkbox', 'ignoremodified', '', get_string('ignoremodified', 'assignfeedback_offline'));
     $mform->addHelpButton('ignoremodified', 'ignoremodified', 'assignfeedback_offline');
     $mform->addElement('hidden', 'id', $params['cm']);
     $mform->setType('id', PARAM_INT);
     $mform->addElement('hidden', 'action', 'viewpluginpage');
     $mform->setType('action', PARAM_ALPHA);
     $mform->addElement('hidden', 'pluginaction', 'uploadgrades');
     $mform->setType('pluginaction', PARAM_ALPHA);
     $mform->addElement('hidden', 'plugin', 'offline');
     $mform->setType('plugin', PARAM_PLUGIN);
     $mform->addElement('hidden', 'pluginsubtype', 'assignfeedback');
     $mform->setType('pluginsubtype', PARAM_PLUGIN);
     $this->add_action_buttons(true, get_string('uploadgrades', 'assignfeedback_offline'));
 }
 /**
  * Determine output for the name column.
  *
  * @param stdClass   $recording The recording row being worked on.
  * @return string    The output to display.
  */
 public function col_name($recording)
 {
     if (\core_text::strlen($recording->name) > 60) {
         return \core_text::substr($recording->name, 0, 55) . '&#8230;';
     }
     return $recording->name;
 }
Exemple #12
0
 /**
  *
  */
 protected function definition_expimp_settings()
 {
     $mform =& $this->_form;
     $mform->addElement('header', 'expimpsettingshdr', get_string('expimpsettings', 'dataformview_csv'));
     // Enable import  (param4).
     $mform->addElement('advcheckbox', 'param4', get_string('export', 'grades'), get_string('enable'), null, array(0, 1));
     $mform->setDefault('param4', 1);
     // Enable import  (param4).
     $mform->addElement('advcheckbox', 'param5', get_string('import'), get_string('enable'), null, array(0, 1));
     $mform->setDefault('param5', 1);
     // Allow update existing entries  (param4)
     // $mform->addElement('advcheckbox', 'updateexisting',  null, get_string('allowupdateexisting', 'dataformview_csv'), null, array(0, 1));
     // $mform->disabledIf('updateexisting', 'importenable', 'eq', 0);.
     // Delimiter.
     $delimiters = csv_import_reader::get_delimiter_list();
     $mform->addElement('select', 'delimiter', get_string('csvdelimiter', 'dataform'), $delimiters);
     $mform->setDefault('delimiter', 'comma');
     // Enclosure.
     $mform->addElement('text', 'enclosure', get_string('csvenclosure', 'dataform'), array('size' => '10'));
     $mform->setType('enclosure', PARAM_NOTAGS);
     $mform->setDefault('enclosure', '');
     // Encoding.
     $choices = core_text::get_encodings();
     $mform->addElement('select', 'encoding', get_string('encoding', 'grades'), $choices);
     $mform->setDefault('encoding', 'UTF-8');
 }
Exemple #13
0
 /**
  * Definition method.
  */
 public function definition()
 {
     global $COURSE;
     $mform = $this->_form;
     if (isset($this->_customdata)) {
         // Hardcoding plugin names here is hacky.
         $features = $this->_customdata;
     } else {
         $features = array();
     }
     // Course id needs to be passed for auth purposes.
     $mform->addElement('hidden', 'id', optional_param('id', 0, PARAM_INT));
     $mform->setType('id', PARAM_INT);
     $mform->addElement('header', 'general', get_string('pluginname', 'gradeimport_direct'));
     // Data upload from copy/paste.
     $mform->addElement('textarea', 'userdata', 'Data', array('rows' => 10, 'class' => 'gradeimport_data_area'));
     $mform->addRule('userdata', null, 'required');
     $mform->setType('userdata', PARAM_RAW);
     $encodings = core_text::get_encodings();
     $mform->addElement('select', 'encoding', get_string('encoding', 'grades'), $encodings);
     if (!empty($features['verbosescales'])) {
         $options = array(1 => get_string('yes'), 0 => get_string('no'));
         $mform->addElement('select', 'verbosescales', get_string('verbosescales', 'grades'), $options);
     }
     $options = array('10' => 10, '20' => 20, '100' => 100, '1000' => 1000, '100000' => 100000);
     $mform->addElement('select', 'previewrows', get_string('rowpreviewnum', 'grades'), $options);
     $mform->setType('previewrows', PARAM_INT);
     $mform->addElement('hidden', 'groupid', groups_get_course_group($COURSE));
     $mform->setType('groupid', PARAM_INT);
     $this->add_action_buttons(false, get_string('uploadgrades', 'grades'));
 }
Exemple #14
0
/**
 * Returns location information
 * @param string $ip
 * @return array
 */
function iplookup_find_location($ip)
{
    global $CFG;
    $info = array('city' => null, 'country' => null, 'longitude' => null, 'latitude' => null, 'error' => null, 'note' => '', 'title' => array());
    if (!empty($CFG->geoip2file) and file_exists($CFG->geoip2file)) {
        $reader = new GeoIp2\Database\Reader($CFG->geoip2file);
        $record = $reader->city($ip);
        if (empty($record)) {
            $info['error'] = get_string('iplookupfailed', 'error', $ip);
            return $info;
        }
        $info['city'] = core_text::convert($record->city->name, 'iso-8859-1', 'utf-8');
        $info['title'][] = $info['city'];
        $countrycode = $record->country->isoCode;
        $countries = get_string_manager()->get_list_of_countries(true);
        if (isset($countries[$countrycode])) {
            // Prefer our localized country names.
            $info['country'] = $countries[$countrycode];
        } else {
            $info['country'] = $record->country->names['en'];
        }
        $info['title'][] = $info['country'];
        $info['longitude'] = $record->location->longitude;
        $info['latitude'] = $record->location->latitude;
        $info['note'] = get_string('iplookupmaxmindnote', 'admin');
        return $info;
    } else {
        require_once $CFG->libdir . '/filelib.php';
        if (strpos($ip, ':') !== false) {
            // IPv6 is not supported by geoplugin.net.
            $info['error'] = get_string('invalidipformat', 'error');
            return $info;
        }
        $ipdata = download_file_content('http://www.geoplugin.net/json.gp?ip=' . $ip);
        if ($ipdata) {
            $ipdata = preg_replace('/^geoPlugin\\((.*)\\)\\s*$/s', '$1', $ipdata);
            $ipdata = json_decode($ipdata, true);
        }
        if (!is_array($ipdata)) {
            $info['error'] = get_string('cannotgeoplugin', 'error');
            return $info;
        }
        $info['latitude'] = (double) $ipdata['geoplugin_latitude'];
        $info['longitude'] = (double) $ipdata['geoplugin_longitude'];
        $info['city'] = s($ipdata['geoplugin_city']);
        $countrycode = $ipdata['geoplugin_countryCode'];
        $countries = get_string_manager()->get_list_of_countries(true);
        if (isset($countries[$countrycode])) {
            // prefer our localized country names
            $info['country'] = $countries[$countrycode];
        } else {
            $info['country'] = s($ipdata['geoplugin_countryName']);
        }
        $info['note'] = get_string('iplookupgeoplugin', 'admin');
        $info['title'][] = $info['city'];
        $info['title'][] = $info['country'];
        return $info;
    }
}
 /**
  * Gets quoted csv variable string.
  *
  * @param string $varstr csv variable string
  * @return quoted csv variable string
  */
 public function quote($varstr)
 {
     if ($this->_excelcsv) {
         return core_text::convert('"' . str_replace('"', "'", $varstr) . '"', 'UTF-8', 'UTF-16LE');
     } else {
         return '"' . str_replace('"', "'", $varstr) . '"';
     }
 }
Exemple #16
0
 function validation($data, $files)
 {
     $errors = parent::validation($data, $files);
     if (empty($data['shorten']) and core_text::strlen($data['search']) < core_text::strlen($data['replace'])) {
         $errors['shorten'] = get_string('required');
     }
     return $errors;
 }
Exemple #17
0
/**
 * Sets user course sorting preference in course_overview block
 *
 * @param array $sortorder list of course ids
 */
function block_course_overview_update_myorder($sortorder)
{
    $value = implode(',', $sortorder);
    if (core_text::strlen($value) > 1333) {
        // The value won't fit into the user preference. Remove courses in the end of the list (mostly likely user won't even notice).
        $value = preg_replace('/,[\\d]*$/', '', core_text::substr($value, 0, 1334));
    }
    set_user_preference('course_overview_course_sortorder', $value);
}
function csv_quote($value)
{
    global $excel;
    if ($excel) {
        return core_text::convert('"' . str_replace('"', "'", $value) . '"', 'UTF-8', 'UTF-16LE');
    } else {
        return '"' . str_replace('"', "'", $value) . '"';
    }
}
Exemple #19
0
 function definition()
 {
     global $COURSE;
     $mform =& $this->_form;
     if (isset($this->_customdata)) {
         // hardcoding plugin names here is hacky
         $features = $this->_customdata;
     } else {
         $features = array();
     }
     // course id needs to be passed for auth purposes
     $mform->addElement('hidden', 'id', optional_param('id', 0, PARAM_INT));
     $mform->setType('id', PARAM_INT);
     $mform->addElement('header', 'general', get_string('importfile', 'grades'));
     // Restrict the possible upload file types.
     if (!empty($features['acceptedtypes'])) {
         $acceptedtypes = $features['acceptedtypes'];
     } else {
         $acceptedtypes = '*';
     }
     // File upload.
     $mform->addElement('filepicker', 'userfile', get_string('file'), null, array('accepted_types' => $acceptedtypes));
     $mform->addRule('userfile', null, 'required');
     $encodings = core_text::get_encodings();
     $mform->addElement('select', 'encoding', get_string('encoding', 'grades'), $encodings);
     $mform->addHelpButton('encoding', 'encoding', 'grades');
     if (!empty($features['includeseparator'])) {
         $radio = array();
         $radio[] = $mform->createElement('radio', 'separator', null, get_string('septab', 'grades'), 'tab');
         $radio[] = $mform->createElement('radio', 'separator', null, get_string('sepcomma', 'grades'), 'comma');
         $radio[] = $mform->createElement('radio', 'separator', null, get_string('sepcolon', 'grades'), 'colon');
         $radio[] = $mform->createElement('radio', 'separator', null, get_string('sepsemicolon', 'grades'), 'semicolon');
         $mform->addGroup($radio, 'separator', get_string('separator', 'grades'), ' ', false);
         $mform->addHelpButton('separator', 'separator', 'grades');
         $mform->setDefault('separator', 'comma');
     }
     if (!empty($features['verbosescales'])) {
         $options = array(1 => get_string('yes'), 0 => get_string('no'));
         $mform->addElement('select', 'verbosescales', get_string('verbosescales', 'grades'), $options);
         $mform->addHelpButton('verbosescales', 'verbosescales', 'grades');
     }
     $options = array('10' => 10, '20' => 20, '100' => 100, '1000' => 1000, '100000' => 100000);
     $mform->addElement('select', 'previewrows', get_string('rowpreviewnum', 'grades'), $options);
     // TODO: localize
     $mform->addHelpButton('previewrows', 'rowpreviewnum', 'grades');
     $mform->setType('previewrows', PARAM_INT);
     $mform->addElement('checkbox', 'forceimport', get_string('forceimport', 'grades'));
     $mform->addHelpButton('forceimport', 'forceimport', 'grades');
     $mform->setDefault('forceimport', false);
     $mform->setType('forceimport', PARAM_BOOL);
     $mform->addElement('hidden', 'groupid', groups_get_course_group($COURSE));
     $mform->setType('groupid', PARAM_INT);
     $this->add_action_buttons(false, get_string('uploadgrades', 'grades'));
 }
Exemple #20
0
/**
 * @uses LABEL_MAX_NAME_LENGTH
 * @param object $label
 * @return string
 */
function get_label_name($label)
{
    $name = strip_tags(format_string($label->intro, true));
    if (core_text::strlen($name) > LABEL_MAX_NAME_LENGTH) {
        $name = core_text::substr($name, 0, LABEL_MAX_NAME_LENGTH) . "...";
    }
    if (empty($name)) {
        // arbitrary name
        $name = get_string('modulename', 'label');
    }
    return $name;
}
 /**
  * Use internal moodles own core_text to encode mimeheaders.
  * Fall back to phpmailers inbuilt functions if not 
  */
 public function encodeHeader($str, $position = 'text')
 {
     $encoded = core_text::encode_mimeheader($str, $this->CharSet);
     if ($encoded !== false) {
         $encoded = str_replace("\n", $this->LE, $encoded);
         if ($position === 'phrase') {
             return "\"{$encoded}\"";
         }
         return $encoded;
     }
     return parent::encodeHeader($str, $position);
 }
 public function definition()
 {
     global $CFG;
     $mform =& $this->_form;
     // General options.
     $mform->addElement('header', 'general', get_string('general', 'form'));
     $mform->addElement('text', 'name', get_string('name'), array('size' => '48', 'maxlength' => '255'));
     $mform->setType('name', PARAM_TEXT);
     $mform->addRule('name', null, 'required', null, 'client');
     $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
     if ($CFG->branch < 29) {
         $this->add_intro_editor(true, get_string('description'));
     } else {
         $this->standard_intro_elements();
     }
     // Advanced options.
     $mform->addElement('header', 'galleryoptions', get_string('advanced'));
     $mform->addElement('select', 'perpage', get_string('imagesperpage', 'lightboxgallery'), $this->get_perpage_options());
     $mform->setType('perpage', PARAM_INTEGER);
     $mform->addElement('select', 'perrow', get_string('imagesperrow', 'lightboxgallery'), $this->get_perrow_options());
     $mform->setType('perrow', PARAM_INTEGER);
     $yesno = array(0 => get_string('no'), 1 => get_string('yes'));
     $mform->addElement('select', 'captionfull', get_string('captionfull', 'lightboxgallery'), $yesno);
     $captionposopts = array('0' => get_string('position_bottom', 'lightboxgallery'), '1' => get_string('position_top', 'lightboxgallery'), '2' => get_string('hide'));
     $mform->addElement('select', 'captionpos', get_string('captionpos', 'lightboxgallery'), $captionposopts);
     $autoresizegroup = array();
     $autoresizegroup[] =& $mform->createElement('select', 'autoresize', get_string('autoresize', 'lightboxgallery'), $this->get_autoresize_options());
     $autoresizegroup[] =& $mform->createElement('checkbox', 'autoresizedisabled', null, get_string('disable'));
     $mform->addGroup($autoresizegroup, 'autoresizegroup', get_string('autoresize', 'lightboxgallery'), ' ', false);
     $mform->setType('autoresize', PARAM_INTEGER);
     $mform->disabledIf('autoresizegroup', 'autoresizedisabled', 'checked');
     $mform->addHelpButton('autoresizegroup', 'autoresize', 'lightboxgallery');
     $mform->addElement('select', 'resize', sprintf('%s (%s)', get_string('edit_resize', 'lightboxgallery'), core_text::strtolower(get_string('upload'))), lightboxgallery_resize_options());
     $mform->setType('resize', PARAM_INTEGER);
     $mform->disabledIf('resize', 'autoresize', 'eq', 1);
     $mform->disabledIf('resize', 'autoresizedisabled', 'checked');
     $mform->addElement('select', 'comments', get_string('allowcomments', 'lightboxgallery'), $yesno);
     $mform->setType('comments', PARAM_INTEGER);
     $mform->addElement('select', 'ispublic', get_string('makepublic', 'lightboxgallery'), $yesno);
     $mform->setType('ispublic', PARAM_INTEGER);
     if (lightboxgallery_rss_enabled()) {
         $mform->addElement('select', 'rss', get_string('allowrss', 'lightboxgallery'), $yesno);
         $mform->setType('rss', PARAM_INTEGER);
     } else {
         $mform->addElement('static', 'rssdisabled', get_string('allowrss', 'lightboxgallery'), get_string('rssglobaldisabled', 'admin'));
     }
     $mform->addElement('select', 'extinfo', get_string('extendedinfo', 'lightboxgallery'), $yesno);
     $mform->setType('extinfo', PARAM_INTEGER);
     // Module options.
     $features = array('groups' => false, 'groupings' => false, 'groupmembersonly' => false, 'outcomes' => false, 'gradecat' => false, 'idnumber' => false);
     $this->standard_coursemodule_elements($features);
     $this->add_action_buttons();
 }
Exemple #23
0
/**
 * @uses COURSECLASSROOM_MAX_NAME_LENGTH
 * @param object $trainingevent
 * @return string
 */
function get_trainingevent_name($trainingevent)
{
    $name = strip_tags(format_string($trainingevent->name, true));
    if (core_text::strlen($name) > COURSECLASSROOM_MAX_NAME_LENGTH) {
        $name = core_text::substr($name, 0, COURSECLASSROOM_MAX_NAME_LENGTH) . "...";
    }
    if (empty($name)) {
        // Arbitrary name.
        $name = get_string('modulename', 'trainingevent');
    }
    return $name;
}
Exemple #24
0
 /**
  * Validates a value using a range comparison
  *
  * @param     string    $value      Value to be checked
  * @param     mixed     $options    Int for length, array for range
  * @access    public
  * @return    boolean   true if value is valid
  */
 function validate($value, $options = null)
 {
     $length = core_text::strlen($value);
     switch ($this->name) {
         case 'minlength':
             return $length >= $options;
         case 'maxlength':
             return $length <= $options;
         default:
             return $length >= $options[0] && $length <= $options[1];
     }
 }
 /**
  * Processes the message and sends a notification via airnotifier
  *
  * @param stdClass $eventdata the event data submitted by the message sender plus $eventdata->savedmessageid
  * @return true if ok, false if error
  */
 public function send_message($eventdata)
 {
     global $CFG;
     require_once $CFG->libdir . '/filelib.php';
     if (!empty($CFG->noemailever)) {
         // Hidden setting for development sites, set in config.php if needed.
         debugging('$CFG->noemailever active, no airnotifier message sent.', DEBUG_MINIMAL);
         return true;
     }
     // Skip any messaging suspended and deleted users.
     if ($eventdata->userto->auth === 'nologin' or $eventdata->userto->suspended or $eventdata->userto->deleted) {
         return true;
     }
     // Site id, to map with Moodle Mobile stored sites.
     $siteid = md5($CFG->wwwroot . $eventdata->userto->username);
     // Mandatory notification data that need to be sent in the payload. They have variable length.
     // We need to take them in consideration to calculate the maximum message size.
     $notificationdata = array("site" => $siteid, "type" => $eventdata->component . '_' . $eventdata->name, "device" => "xxxxxxxxxx", "notif" => "x", "userfrom" => !empty($eventdata->userfrom) ? fullname($eventdata->userfrom) : '');
     // Calculate the size of the message knowing Apple payload must be lower than 256 bytes.
     // Airnotifier using few bytes of the payload, we must limit our message to even less characters.
     $maxmsgsize = 205 - core_text::strlen(json_encode($notificationdata));
     $message = s($eventdata->smallmessage);
     // If the message size is too big make it shorter.
     if (core_text::strlen($message) >= $maxmsgsize) {
         // Cut the message to the maximum possible size. -4 for the the ending 3 dots (...).
         $message = core_text::substr($message, 0, $maxmsgsize - 4);
         // We need to check when the message is "escaped" then the message is not too long.
         $encodedmsgsize = core_text::strlen(json_encode($message));
         if ($encodedmsgsize > $maxmsgsize) {
             $totalescapedchar = $encodedmsgsize - core_text::strlen($message);
             // Cut the message to the maximum possible size (taking the escaped character in account).
             $message = core_text::substr($message, 0, $maxmsgsize - 4 - $totalescapedchar);
         }
         $message = $message . '...';
     }
     // We are sending to message to all devices.
     $airnotifiermanager = new message_airnotifier_manager();
     $devicetokens = $airnotifiermanager->get_user_devices($CFG->airnotifiermobileappname, $eventdata->userto->id);
     foreach ($devicetokens as $devicetoken) {
         if (!$devicetoken->enable) {
             continue;
         }
         // Sending the message to the device.
         $serverurl = $CFG->airnotifierurl . ':' . $CFG->airnotifierport . '/notification/';
         $header = array('Accept: application/json', 'X-AN-APP-NAME: ' . $CFG->airnotifierappname, 'X-AN-APP-KEY: ' . $CFG->airnotifieraccesskey);
         $curl = new curl();
         $curl->setHeader($header);
         $params = array('alert' => $message, 'date' => !empty($eventdata->timecreated) ? $eventdata->timecreated : time(), 'site' => $siteid, 'type' => $eventdata->component . '_' . $eventdata->name, 'userfrom' => !empty($eventdata->userfrom) ? fullname($eventdata->userfrom) : '', 'device' => $devicetoken->platform, 'notif' => !empty($eventdata->notification) ? '1' : '0', 'token' => $devicetoken->pushid);
         $resp = $curl->post($serverurl, $params);
     }
     return true;
 }
function get_books_structure_publisher($publisher, $isbn = false)
{
    global $OUTPUT;
    set_time_limit(0);
    $books = get_books($publisher);
    try {
        if (!empty($books)) {
            //  Fix bug, when there is just one received book
            if (!is_array($books) || !isset($books[0])) {
                $books = array($books);
            }
            echo '<ol>';
            foreach ($books as $book) {
                // Disable scorm import
                $bookformat = core_text::strtolower($book['formato']);
                if (!in_array($bookformat, rcommon_book::$allowedformats)) {
                    continue;
                }
                $codisbn = $book['isbn'];
                // Si se ha especificado un isbn guarda el libro
                if (!$isbn || $codisbn == $isbn) {
                    $message = 'ISBN: ' . $codisbn;
                    // Obtiene los datos del indice del libro
                    try {
                        $instance = new StdClass();
                        $instance->isbn = $codisbn;
                        $instance->name = $book['titulo'];
                        $instance->summary = $book['titulo'];
                        $instance->format = $bookformat;
                        $instance->levelid = isset($book['nivel']) ? $book['nivel'] : false;
                        $instance->publisherid = $publisher->id;
                        rcommon_book::add_update($instance);
                        get_book_structure($publisher, $codisbn);
                        echo '<li>' . $OUTPUT->notification($message, 'notifysuccess') . '</li>';
                    } catch (Exception $e) {
                        $message .= " - Error: " . $e->getMessage();
                        echo '<li>' . $OUTPUT->notification($message) . '</li>';
                    }
                }
            }
            echo '</ol>';
            return true;
        } else {
            echo get_string('nobooks', 'local_rcommon');
            return true;
        }
    } catch (Exception $fault) {
        $message = rcommon_ws_error('get_books_structure_publisher', $fault->getMessage());
        throw new Exception($message);
    }
    return false;
}
Exemple #27
0
 /**
  * Set the title of the worksheet inside a spreadsheet
  *
  * For some formats this will be ignored.
  *
  * @param string $title
  */
 public function set_sheettitle($title)
 {
     if (!$title) {
         return;
     }
     // Replace any characters in the name that ODS cannot cope with.
     $title = strtr(trim($title, "'"), '[]*/\\?:', '       ');
     // Shorten the title if necessary.
     $title = \core_text::substr($title, 0, 31);
     // After the substr, we might now have a single quote on the end.
     $title = trim($title, "'");
     $this->sheettitle = $title;
 }
 /**
  * Prevent name from exceeding 255 chars.
  */
 public static function shorten_post_name($name)
 {
     $strre = get_string('re', 'hsuforum');
     if (\core_text::strlen($name) > 255) {
         $shortened = shorten_text($name, 255);
         if (trim(str_ireplace($strre, '', $shortened)) === '...' || \core_text::strlen($shortened) > 255) {
             // Make a 2nd pass with the 'exact' param true, as shortening on word boundary failed or exceeded 255 chars.
             $shortened = shorten_text($name, 255, true);
         }
         $name = $shortened;
     }
     return $name;
 }
Exemple #29
0
 /**
  * Defines forms elements
  */
 public function definition()
 {
     global $COURSE, $DB, $CFG;
     $criteria = $this->_customdata['criteria'];
     $context = $this->_customdata['context'];
     $cmid = $this->_customdata['id'];
     $emarking = $this->_customdata['emarking'];
     $action = $this->_customdata['action'];
     $totalpages = $this->_customdata['totalpages'];
     $mform = $this->_form;
     // Add header.
     $mform->addElement('header', 'general', $action === 'addmarkers' ? get_string('assignmarkerstocriteria', 'mod_emarking') : get_string('assignpagestocriteria', 'mod_emarking'));
     // Hide course module id.
     $mform->addElement('hidden', 'id', $cmid);
     $mform->setType('id', PARAM_INT);
     // Hide action.
     $mform->addElement('hidden', 'action', $action);
     $mform->setType('action', PARAM_ALPHA);
     $mform->addElement('html', '<table class="addmarkerstable"><tr><td>');
     if ($action === "addmarkers") {
         // Array of motives for regrading.
         $markers = get_enrolled_users($context, 'mod/assign:grade');
         $chkmarkers = array();
         foreach ($markers as $marker) {
             $chkmarkers[$marker->id] = $marker->firstname . " " . $marker->lastname;
         }
         $select = $mform->addElement('select', 'datamarkers', get_string('markers', 'mod_emarking'), $chkmarkers, null);
         $select->setMultiple(true);
     } else {
         $chkpages = array();
         for ($i = 1; $i <= $totalpages; $i++) {
             $chkpages[$i] = get_string('page', 'mod_emarking') . " " . $i;
         }
         $select = $mform->addElement('select', 'datapages', core_text::strtotitle(get_string('pages', 'mod_emarking')), $chkpages, null);
         $select->setMultiple(true);
     }
     $criteriaitems = array();
     foreach ($criteria as $criterion) {
         $criteriaitems[$criterion['id']] = $criterion['description'];
     }
     $mform->addElement('html', '</td><td>');
     if ($action === "addmarkers") {
         $select = $mform->addElement('select', 'criteriamarkers', get_string('criteria', 'mod_emarking'), $criteriaitems, null);
     } else {
         $select = $mform->addElement('select', 'criteriapages', get_string('criteria', 'mod_emarking'), $criteriaitems, null);
     }
     $select->setMultiple(true);
     $mform->addElement('html', '</td></tr></table>');
     // Add action buttons.
     $this->add_action_buttons();
 }
 function validation($data, $files)
 {
     $errors = array();
     foreach ($data as $key => $value) {
         if ($value == 'null') {
             if (core_text::substr($key, 0, 2) == 'of') {
                 $errors[$key] = get_string('overallfairnessrequired', 'mod_emarking');
             } else {
                 $errors[$key] = get_string('expectationrealityrequired', 'mod_emarking');
             }
         }
     }
     return $errors;
 }