global variable

Re: global variable

by Antonio Garmendía -
Number of replies: 0

Hi,

Finally, I get the parameter courseid from the current url using javascript and pass it to the .php file. If there is a better way, please let me now. Gareth I check the characters and in Moodle 2.4 is until 21 characters. Thanks to all!!

Cheers,

Antonio

var onclick_guardar = function(){
        
        var comments = document.getElementById('bbs_comment');
        var temparray = '';
        var courseid = QueryString.id;
        temparray = 'comment' + '=' + comments.value + '&' + 'courseid' + '=' + courseid + '&';
        Y.io(M.cfg.wwwroot + '/course/format/socmed/actions/save_comment.php', {
            on: {
                    success:M.format_socmed.success,
                    failure:M.format_socmed.failure                    
                }, context: M.format_socmed, method: 'post', data: temparray});                
    }

//save_comment.php

  
 if (!defined('AJAX_SCRIPT')) {
    define('AJAX_SCRIPT', true);
}

require_once(dirname(__FILE__).'/../../../../config.php');

global $DB, $USER, $CFG;

require_once($CFG->dirroot.'/course/format/socmed/lib.php');


$comment  = required_param('comment',PARAM_TEXT);
$courseid  = required_param('courseid',PARAM_INT);


$course = $DB->get_record('course', array('id' => $courseid),'*', MUST_EXIST);
require_login($course);


//Atributos de bbs_comment
$insert_bbs = new stdClass();
$insert_bbs->courseid  = $course->id;
$insert_bbs->userid  = $USER->id;
$insert_bbs->content = $comment;
$insert_bbs->timecreated = time();
$insert_bbs->parent_id = 0;

//Insertar bbs_comment
$resultado_comment = $DB->insert_record('bbs_comment',$insert_bbs);