示例#1
0
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @package    usetenrol_moodleprofile
 * @author     Remote-Learner.net Inc
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 * @copyright  (C) 2008-2013 Remote-Learner.net Inc (http://www.remote-learner.net)
 *
 */
require_once '../../../lib/setup.php';
require_once elis::plugin_file('usetenrol_moodleprofile', 'lib.php');
$id = required_param('field', PARAM_INT);
$elementName = required_param('elementName', PARAM_TEXT);
$value = optional_param('value', null, PARAM_TEXT);
require_login(0, false);
$prof_field = new stdClass();
$prof_field->fieldid = $id;
//output the innerHTML of the surrounding DIV tag
echo get_moodle_profile_field_options($prof_field, $elementName, $value);
示例#2
0
文件: lib.php 项目: jamesmcq/elis
function cluster_moodleprofile_edit_form($form, $mform, $clusterid)
{
    global $CFG, $DB, $PAGE;
    /// Only get--at most--two profile field associations for this cluster.
    if (empty($clusterid)) {
        $prof_fields = null;
    } else {
        $prof_fields = userset_profile::find(new field_filter('clusterid', $clusterid), array(), 0, 2);
    }
    $PAGE->requires->js('/local/elisprogram/enrol/userset/moodleprofile/profile_value.js');
    for ($i = 1; $i <= 2; $i++) {
        if ($prof_fields && $prof_fields->valid()) {
            $prof_field = $prof_fields->current();
            $prof_fields->next();
        } else {
            $prof_field = null;
        }
        $select = "datatype = 'menu'\n                OR datatype = 'checkbox'\n                OR datatype = 'text'";
        $profile_field_options = $DB->get_records_select_menu('user_info_field', $select, null, 'id, name');
        $profile_field_options = array(0 => get_string('dont_auto', 'usetenrol_moodleprofile', '')) + $profile_field_options;
        /// Retrieve the profile value, if set
        $value = null;
        $value_js = 'null';
        if (isset($mform->_defaultValues['profile_value' . $i])) {
            $value = $mform->_defaultValues['profile_value' . $i];
            /// Create an appropriate value for passing to Javascript
            $value_js = "'" . str_replace("'", "\\'", $value) . "'";
        }
        /// Determine if the profile field is of type "text" as it affects the behaviour
        if (!empty($prof_field->fieldid)) {
            $datatype = $DB->get_field('user_info_field', 'datatype', array('id' => $prof_field->fieldid));
            $originallyText = $datatype == 'text' ? 'true' : 'false';
            $data = array("profile_field{$i}" => $prof_field->fieldid);
            $form->set_data($data);
        } else {
            $originallyText = 'false';
        }
        /// Add field selector to form
        $js_function_call = "update_profile_value_list('{$i}', 'profile_value{$i}', {$value_js}, {$originallyText})";
        $mform->addElement('select', "profile_field{$i}", get_string('auto_associate', 'usetenrol_moodleprofile'), $profile_field_options, array('onchange' => $js_function_call));
        if ($i == 1) {
            $mform->addHelpButton('profile_field1', 'auto_associate', 'usetenrol_moodleprofile');
        }
        /// Add field options to form
        // TBD: hack below is because $mform->isFrozen() ... didn't work!
        $isfrozen = optional_param('action', '', PARAM_CLEAN) == 'view';
        $mform->addElement('static', '', get_string('set_to', 'usetenrol_moodleprofile'), html_writer::start_tag('div', array('id' => "cluster_profile_div{$i}")) . get_moodle_profile_field_options($prof_field, "profile_value{$i}", $value, $isfrozen) . html_writer::end_tag('div'));
    }
}