Esempio n. 1
0
 /**
  * Simulates the web interface view of notes/index.php: trigger events
  *
  * @param int $courseid id of the course
  * @param int $userid id of the user
  * @return array of warnings and status result
  * @since Moodle 2.9
  * @throws moodle_exception
  */
 public static function view_notes($courseid, $userid = 0)
 {
     global $CFG;
     require_once $CFG->dirroot . "/notes/lib.php";
     if (empty($CFG->enablenotes)) {
         throw new moodle_exception('notesdisabled', 'notes');
     }
     $warnings = array();
     $arrayparams = array('courseid' => $courseid, 'userid' => $userid);
     $params = self::validate_parameters(self::view_notes_parameters(), $arrayparams);
     if (empty($params['courseid'])) {
         $params['courseid'] = SITEID;
     }
     $course = get_course($params['courseid']);
     if ($course->id == SITEID) {
         $context = context_system::instance();
     } else {
         $context = context_course::instance($course->id);
     }
     // First of all, validate the context before do further permission checks.
     self::validate_context($context);
     require_capability('moodle/notes:view', $context);
     if (!empty($params['userid'])) {
         $user = core_user::get_user($params['userid'], 'id, deleted', MUST_EXIST);
         if ($user->deleted) {
             throw new moodle_exception('userdeleted');
         }
         if (isguestuser($user)) {
             throw new moodle_exception('invaliduserid');
         }
         if ($course->id != SITEID and !is_enrolled($context, $user, '', true)) {
             throw new moodle_exception('notenrolledprofile');
         }
     }
     note_view($context, $params['userid']);
     $result = array();
     $result['status'] = true;
     $result['warnings'] = $warnings;
     return $result;
 }
function note_save($_POST)
{
    extract($_POST);
    require_lib("validate");
    $v = new validate();
    $v->isOk($accid, "num", 1, 9, "Invalid account id.");
    if ($v->isError()) {
        $confirm = "";
        $errors = $v->getErrors();
        foreach ($errors as $e) {
            $confirm .= "<li class='err'>{$e['msg']}</li>";
        }
        return $confirm;
    }
    // Is the account already in the saved balance sheet table?
    db_conn("cubit");
    $sql = "SELECT * FROM saved_tb_accounts WHERE accid='{$accid}'";
    $sbsacc_rslt = db_exec($sql) or errDie("Unable to retrieve saved balance sheet accounts from Cubit.");
    if (pg_num_rows($sbsacc_rslt)) {
        db_conn("cubit");
        $sql = "UPDATE saved_tb_accounts SET note='" . base64_encode($note) . "' WHERE accid='{$accid}'";
        $note_rslt = db_exec($sql) or errDie("Unable to update note.");
        $note_data = pg_fetch_array($note_rslt);
    } else {
        db_conn("core");
        $sql = "SELECT * FROM accounts WHERE accid='{$accid}'";
        $acc_rslt = db_exec($sql) or errDie("Unable to retrieve account information from Cubit.");
        $acc_data = pg_fetch_array($acc_rslt);
        db_conn("cubit");
        $sql = "\n\t\t\tINSERT INTO saved_tb_accounts (\n\t\t\t\taccid, topacc, accnum, accname, note\n\t\t\t) VALUES (\n\t\t\t\t'{$acc_data['accid']}', '{$acc_data['topacc']}', '{$acc_data['accnum']}', '{$acc_data['accname']}', '" . base64_encode($note) . "'\n\t\t\t)";
        $sbsacc_rslt = db_exec($sql) or errDie("Unable to insert account information into the accounts list.");
    }
    return note_view($_POST, "<tr class='" . bg_class() . "'><td><li>Note has been updated.</li></td></tr>");
}
Esempio n. 3
0
} else {
    $filtertype = 'course';
    $filterselect = $course->id;
    $user = $USER;
}
require_login($course);
// Output HTML.
if ($course->id == SITEID) {
    $coursecontext = context_system::instance();
} else {
    $coursecontext = context_course::instance($course->id);
}
require_capability('moodle/notes:view', $coursecontext);
$systemcontext = context_system::instance();
// Trigger event.
note_view($coursecontext, $userid);
$strnotes = get_string('notes', 'notes');
if ($userid && $course->id == SITEID) {
    $PAGE->set_context(context_user::instance($user->id));
    $PAGE->navigation->extend_for_user($user);
    // If we are looking at our own notes, then change focus to 'my notes'.
    if ($userid == $USER->id) {
        $notenode = $PAGE->navigation->find('notes', null)->make_inactive();
    }
    $notesurl = new moodle_url('/notes/index.php', array('user' => $userid));
    $PAGE->navbar->add(get_string('notes', 'notes'), $notesurl);
} else {
    if ($course->id != SITEID) {
        $notenode = $PAGE->navigation->find('currentcoursenotes', null)->make_inactive();
        $participantsurl = new moodle_url('/user/view.php', array('id' => $userid, 'course' => $course->id));
        $currentcoursenode = $PAGE->navigation->find('currentcourse', null);