Commit 0ebea0bb authored by Michael Milette's avatar Michael Milette
Browse files

Learning Block - Fix for errors in Moodle 2.5.1 and 2.6

1) Fixes a couple of PHP notices in Moodle 2.5.1
2) Fixes a number of variable and functions that needed to be initialized before they are used in Moodle 2.6.
3) Added security check in ajax_bridge to address Moodle warning
4) Duplicate string definition removed
5) Git version is now in sync with the version published on Moodle.org which seemed to be more recent.

Signed-off-by: default avatarMichael Milette <michael.milette@instruxmedia.com>
parent 23699d3b
Loading
Loading
Loading
Loading
+6 −1
Changes for ajax_bridge.php: 6 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -37,6 +37,11 @@ $t_id = optional_param('t_id', null, PARAM_INT); // $_GET['t_id'];
$status = optional_param('status', null, PARAM_INT);  // $_GET['status'];
$hidetraining = optional_param('hidetraining', null, PARAM_INT); // $_GET['hidetraining'];
$hideusers = optional_param('hideusers', null, PARAM_INT); //$_GET['hideusers'];

require_login(0, false);
$PAGE->set_context(context_system::instance());
$PAGE->set_url('/blocks/learning_plan/ajax_bridge.php');

if($lp_id && $t_id) {
    $form = new search();
    $table = $form->display_list($lp_id, $t_id, $status);
@@ -49,7 +54,7 @@ if($lp_id && $t_id) {
                                                 lpt inner join {learning_user_trainingplan} lut on lut.lpt_id=lpt.id  where lpt.lp_id=? AND lut.u_id=?',
                                                 array ($lp_id, $u_id), $limitfrom=0, $limitnum=0);
    }
    // Find traiing on the base of lp Id.
    // Find training on the base of lp Id.
    else if($lp_id && $t) {
        $attributes =  $DB->get_records_sql_menu('SELECT t_id as id,(select training_name from  {learning_training} where id =t_id) as name FROM {learning_plan_training}
                                                 where lp_id= ?', array ($lp_id), $limitfrom=0, $limitnum=0);
+1 −1
Changes for block_learning_plan.php: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@
 * @package blocks
 * @author: Azmat Ullah, Talha Noor
 * @date: 20-Sep-2013
 * @copyright  Copyrights © 2012 - 2013 | 3i Logic (Pvt) Ltd.
 * @copyright  Copyrights © 2012 - 2013 | 3i Logic (Pvt) Ltd.
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */

−5
Changes for lang/en/block_learning_plan.php: 0 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -69,7 +69,6 @@ $string['wrong_url'] = 'Wrong URL';
$string['elearning'] = 'eLearning';
$string['classroom'] = 'Class room';
$string['onthejob'] = 'On the job';
$string['training_m'] = 'Training method';
$string['assignee'] = 'Assignee';
$string['remove'] = 'Remove';
$string['setting'] = 'Setting';
@@ -80,7 +79,3 @@ $string['learning_plan:addinstance'] = 'Add instance';
$string['learning_plan:managepages'] = 'Manage pages';
$string['learning_plan:viewpages'] = 'View pages';
$string['user'] = 'User';
 No newline at end of file



+25 −4
Changes for learning_plan_form.php: 25 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -29,19 +29,22 @@ require_once("{$CFG->libdir}/formslib.php");
class learningplan_form extends moodleform {
    public function definition() {
        $mform =& $this->_form;
        $errors= array();
        $mform->addElement('header', 'displayinfo', get_string('learningpath', 'block_learning_plan'));
        $mform->addElement('text', 'learning_plan', get_string('learningplan', 'block_learning_plan'));
        $mform->addRule('learning_plan', get_string('plan_format', 'block_learning_plan'), 'regex', '#^[A-Z0-9 ]+$#i', 'client');
        $mform->addRule('learning_plan', $errors, 'required', null, 'server');
        $mform->setType('learningplan', PARAM_RAW);
        $mform->setType('learning_plan', PARAM_RAW);
        $attributes = array('rows' => '8', 'cols' => '40');
        $mform->addElement('textarea', 'description', get_string('desc', 'block_learning_plan'), $attributes);
        $mform->setType('description', PARAM_TEXT);
        $mform->addElement('hidden', 'viewpage');
        $mform->setType('viewpage', PARAM_INT);
        $mform->addElement('hidden', 'id');
        $mform->setType('id', PARAM_INT);
        $this->add_action_buttons();
    }
    public function validation($data) {
    public function validation($data, $files) {
        global $DB;
        $errors= array();
        if($data['id']) {
@@ -122,6 +125,8 @@ class training_form extends moodleform {
        $mform =& $this->_form;
        $mform->addElement('header', 'displayinfo', get_string('add_training', 'block_learning_plan'));
        $radioarray=array();
        if (!isset($attributes)) $attributes = "";
        if (!isset($errors)) $errors = array();
        $radioarray[] =& $mform->createElement('radio', 'type_id', '', get_string('elearning', 'block_learning_plan'), 1 );
        $radioarray[] =& $mform->createElement('radio', 'type_id', '', get_string('classroom', 'block_learning_plan'), 2, $attributes);
        $radioarray[] =& $mform->createElement('radio', 'type_id', '', get_string('onthejob', 'block_learning_plan'), 3, $attributes);
@@ -130,19 +135,23 @@ class training_form extends moodleform {
        $mform->addElement('text', 'training_name', get_string('training_name', 'block_learning_plan'));
        $mform->addRule('training_name', get_string('training_format', 'block_learning_plan'), 'regex', '#^[A-Z0-9 ]+$#i', 'client');
        $mform->addRule('training_name', $errors, 'required', null, 'server');
        $mform->setType('training_name', PARAM_TEXT);
        // $attributes = array('maxbytes' => '4194304', 'accepted_types' => "*");
        // $mform->addElement('file', 'attachment', get_string('attachment', 'block_learning_plan'), $attributes );
        // $mform->addElement('filepicker', 'attachment', get_string('attachment', 'block_learning_plan'), null, $attributes);
        $mform->addElement('text', 'url', get_string('url', 'block_learning_plan'));
        $mform->addRule('url', get_string('wrong_url', 'block_learning_plan'), 'regex', '/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i', 'client');
        $mform->setType('url', PARAM_LOCALURL);
        $mform->addElement('date_time_selector', 'start_date', get_string('start_date', 'block_learning_plan'));
        $mform->addElement('date_time_selector', 'end_date', get_string('end_date', 'block_learning_plan'));
        $mform->addElement('static', 'errormsg');
        $mform->addElement('hidden', 'viewpage');
        $mform->setType('viewpage', PARAM_INT);
        $mform->addElement('hidden', 'id');
        $mform->setType('id', PARAM_INT);
        $this->add_action_buttons();
    }
    public function validation($data) {
    public function validation($data, $files) {
        global $DB;
        $errors= array();
        if($data['id']) {
@@ -246,7 +255,9 @@ class trainingmethod_form extends moodleform {
        $attributes = array('rows' => '8', 'cols' => '40');
        $mform->addElement('textarea', 'description', get_string('desc', 'block_learning_plan'), $attributes);
        $mform->addElement('hidden', 'viewpage');
        $mform->setType('viewpage', PARAM_INT);
        $mform->addElement('hidden', 'id');
        $mform->setType('id', PARAM_INT);
        $this->add_action_buttons();
    }

@@ -276,7 +287,9 @@ class assigntraining_learningplan__form extends moodleform {
                                     array('link' => $CFG->wwwroot.'/blocks/learning_plan/view.php?viewpage=2', 'label' => get_string('add_training', 'block_learning_plan')));
        $select->setmultiple(true);
        $mform->addElement('hidden', 'viewpage');
        $mform->setType('viewpage', PARAM_INT);
        $mform->addElement('hidden', 'id');
        $mform->setType('id', PARAM_INT);
        $this->add_action_buttons();
    }

@@ -348,6 +361,7 @@ class assignlerningplan_user_form extends moodleform {
    public function definition() {
        global $DB, $CFG, $USER;
        $mform =& $this->_form;
        if (!isset($attributes1)) $attributes1 = "";
        $mform->addElement('header', 'displayinfo', get_string('assign_learningplan_user', 'block_learning_plan'));
        $attributes = $DB->get_records_sql_menu('SELECT id, learning_plan FROM {learning_learningplan}', null, $limitfrom=0, $limitnum=0);
        $mform->addElement('selectwithlink', 'l_id', get_string('learningplan', 'block_learning_plan'), $attributes, null,
@@ -358,7 +372,9 @@ class assignlerningplan_user_form extends moodleform {
        $select->setMultiple(true);
        // $mform->addElement('hidden', 'assignee', $USER->id);
        $mform->addElement('hidden', 'viewpage');
        $mform->setType('viewpage', PARAM_INT);
        $mform->addElement('hidden', 'id');
        $mform->setType('id', PARAM_INT);
        $this->add_action_buttons();
    }

@@ -428,8 +444,11 @@ class trainingstatus_form extends moodleform {
        $mform->addElement('select', 'status', get_string('status', 'block_learning_plan'), $attributes);
        $attributes = array('size' => '50', 'maxlength' => '1000');
        $mform->addElement('text', 'remarks', get_string('remarks', 'block_learning_plan'), $attributes);
        $mform->setType('remarks', PARAM_TEXT);
        $mform->addElement('hidden', 'viewpage');
        $mform->setType('viewpage', PARAM_INT);
        $mform->addElement('hidden', 'id');
        $mform->setType('id', PARAM_INT);
        $this->add_action_buttons();
    }

@@ -452,10 +471,12 @@ class search extends moodleform {
        $attributes = array('In-progress', 'Not Yet Started', 'Complete', 'All Status');
        $mform->addElement('select', 'status', get_string('status', 'block_learning_plan'), $attributes);
        $mform->addElement('hidden', 'viewpage');
        $mform->setType('viewpage', PARAM_INT);
        $mform->addElement('hidden', 'id');
        $mform->setType('id', PARAM_INT);
        $mform->addElement('button', 'showuser', 'Search', array("id" => "btnajax"));
    }
    public function display_list($lp_id, $t_id, $status) {
    public function display_list($lp_id = "", $t_id = "", $status = "") {
        // if ($lp_id && $t_id) {
        global $DB, $OUTPUT, $CFG;
        $table = new html_table();
+2 −2
Changes for lib.php: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -64,7 +64,7 @@ function user_learningplan($u_id) {
    return $training;
}
function status_value($status_id) {
    $status_value;
    $status_value = '';
    if($status_id == '0') {
        $status_value = 'In-Progress';
     } else if ($status_id == '1') {
@@ -124,7 +124,7 @@ function display_list($lp_id, $u_id) {
    global $DB, $OUTPUT, $CFG;
    $table = new html_table();
    $table->id = 'statuslist';
    $table->head  = array(get_string('s_no', 'block_learning_plan'), get_string('training_m', 'block_learning_plan'), get_string('user', 'block_learning_plan'), get_string('start_date', 'block_learning_plan'), get_string('end_date', 'block_learning_plan'), get_string('status', 'block_learning_plan'), get_string('remarks', 'block_learning_plan'));
    $table->head  = array(get_string('s_no', 'block_learning_plan'), get_string('training_name', 'block_learning_plan'), get_string('user', 'block_learning_plan'), get_string('start_date', 'block_learning_plan'), get_string('end_date', 'block_learning_plan'), get_string('status', 'block_learning_plan'), get_string('remarks', 'block_learning_plan'));
    $table->size  = array('5%', '30%', '20%', '10%', '10%', '10%', '25%', '10%' );
    $table->align = array('center', 'left', 'left', 'center', 'center', 'center', 'left', 'left', 'center');
    $table->width = '100%';
Loading