Example #1
0
 /**
  * Execute test client WS request
  * @param string $serverurl server url (including token parameter or username/password parameters)
  * @param string $function function name
  * @param array $params parameters of the called function
  * @return mixed
  */
 public function simpletest($serverurl, $function, $params)
 {
     global $CFG;
     $url = new moodle_url($serverurl);
     $token = $url->get_param('wstoken');
     require_once $CFG->dirroot . '/webservice/xmlrpc/lib.php';
     $client = new webservice_xmlrpc_client($serverurl, $token);
     return $client->call($function, $params);
 }
Example #2
0
 /**
  * Obtains the filename from the moodle_url.
  * @param moodle_url $url URL
  * @return string Filename only (not escaped)
  */
 public function get_filename(moodle_url $url)
 {
     // Use the 'file' parameter if provided (for links created when
     // slasharguments was off). If not present, just use URL path.
     $path = $url->get_param('file');
     if (!$path) {
         $path = $url->get_path();
     }
     // Remove everything before last / if present. Does not use textlib as / is UTF8-safe.
     $slash = strrpos($path, '/');
     if ($slash !== false) {
         $path = substr($path, $slash + 1);
     }
     return $path;
 }
 /**
  *
  */
 public static function get_filter_options_from_url(moodle_url $url = null)
 {
     $filteroptions = array('id' => array('filter', 0, PARAM_INT), 'entrytype' => array('uentrytype', 0, PARAM_TEXT), 'perpage' => array('uperpage', 0, PARAM_INT), 'selection' => array('uselection', 0, PARAM_INT), 'groupby' => array('ugroupby', 0, PARAM_INT), 'search' => array('usearch', '', PARAM_RAW), 'customsort' => array('usort', '', PARAM_RAW), 'customsearch' => array('ucsearch', '', PARAM_RAW), 'filters' => array('ufilter', array(), PARAM_INT), 'page' => array('page', 0, PARAM_INT), 'eids' => array('eids', '', PARAM_TAGLIST), 'users' => array('users', '', PARAM_SEQUENCE), 'groups' => array('groups', '', PARAM_SEQUENCE));
     $options = array();
     foreach ($filteroptions as $option => $args) {
         list($name, $default, $type) = $args;
         // Get the value.
         if ($url) {
             $val = $url->get_param($name);
         } else {
             if (is_array($default)) {
                 $val = optional_param_array($name, null, $type);
             } else {
                 $val = optional_param($name, null, $type);
             }
         }
         // Get the option.
         if (!is_null($val)) {
             if ($option == 'customsort') {
                 $options[$option] = self::get_sort_options_from_query($val);
             } else {
                 if ($option == 'customsearch') {
                     $searchoptions = self::get_search_options_from_query($val);
                     $options[$option] = $searchoptions;
                 } else {
                     if ($option == 'search') {
                         $options[$option] = urldecode($val);
                     } else {
                         $options[$option] = $val;
                     }
                 }
             }
         }
     }
     return $options;
 }
 public function view_bulk_certificates(moodle_url $url, array $selectedusers = null)
 {
     global $OUTPUT, $CFG, $DB;
     $course_context = context_course::instance($this->get_course()->id);
     $page = $url->get_param('page');
     $perpage = $url->get_param('perpage');
     $issuelist = $url->get_param('issuelist');
     $action = $url->get_param('action');
     $groupid = 0;
     $groupmode = groups_get_activity_groupmode($this->coursemodule);
     if ($groupmode) {
         $groupid = groups_get_activity_group($this->coursemodule, true);
     }
     $page_start = intval($page * $perpage);
     $usercount = 0;
     if (!$selectedusers) {
         $users = get_enrolled_users($course_context, '', $groupid);
         $usercount = count($users);
         $users = array_slice($users, $page_start, $perpage);
     } else {
         list($sqluserids, $params) = $DB->get_in_or_equal($selectedusers);
         $sql = "SELECT * FROM {user} WHERE id {$sqluserids}";
         //Adding sort
         $sort = '';
         $override = new stdClass();
         $override->firstname = 'firstname';
         $override->lastname = 'lastname';
         $fullnamelanguage = get_string('fullnamedisplay', '', $override);
         if ($CFG->fullnamedisplay == 'firstname lastname' or $CFG->fullnamedisplay == 'firstname' or $CFG->fullnamedisplay == 'language' and $fullnamelanguage == 'firstname lastname') {
             $sort = " ORDER BY firstname, lastname";
         } else {
             // ($CFG->fullnamedisplay == 'language' and $fullnamelanguage == 'lastname firstname')
             $sort = " ORDER BY lastname, firstname";
         }
         $users = $DB->get_records_sql($sql . $sort, $params);
     }
     if (!$action) {
         echo $OUTPUT->header();
         $this->show_tabs($url);
         groups_print_activity_menu($this->coursemodule, $url);
         $selectoptions = array('completed' => get_string('completedusers', 'simplecertificate'), 'allusers' => get_string('allusers', 'simplecertificate'));
         $select = new single_select($url, 'issuelist', $selectoptions, $issuelist);
         $select->label = get_string('showusers', 'simplecertificate');
         echo $OUTPUT->render($select);
         echo '<br>';
         echo '<form id="bulkissue" name="bulkissue" method="post" action="view.php">';
         echo html_writer::label(get_string('bulkaction', 'simplecertificate'), 'menutype', true);
         echo '&nbsp;';
         $selectoptions = array('pdf' => get_string('onepdf', 'simplecertificate'), 'zip' => get_string('multipdf', 'simplecertificate'), 'email' => get_string('sendtoemail', 'simplecertificate'));
         echo html_writer::select($selectoptions, 'type', 'pdf');
         $table = new html_table();
         $table->width = "95%";
         $table->tablealign = "center";
         //strgrade
         $table->head = array(' ', get_string('fullname'), get_string('grade'));
         $table->align = array("left", "left", "center");
         $table->size = array('1%', '89%', '10%');
         foreach ($users as $user) {
             $canissue = $this->can_issue($user, $issuelist != 'allusers');
             if (empty($canissue)) {
                 $chkbox = html_writer::checkbox('selectedusers[]', $user->id, false);
                 $name = $OUTPUT->user_picture($user) . fullname($user);
                 $table->data[] = array($chkbox, $name, $this->get_grade($user->id));
             }
         }
         $downloadbutton = $OUTPUT->single_button($url->out_as_local_url(false, array('action' => 'download')), get_string('bulkbuttonlabel', 'simplecertificate'));
         echo $OUTPUT->paging_bar($usercount, $page, $perpage, $url);
         echo '<br />';
         echo html_writer::table($table);
         echo html_writer::tag('div', $downloadbutton, array('style' => 'text-align: center'));
         echo '</form>';
     } else {
         if ($action == 'download') {
             $type = $url->get_param('type');
             // Calculate file name
             $filename = str_replace(' ', '_', clean_filename($this->get_instance()->coursename . ' ' . get_string('modulenameplural', 'simplecertificate') . ' ' . strip_tags(format_string($this->get_instance()->name, true)) . '.' . strip_tags(format_string($type, true))));
             switch ($type) {
                 //One pdf with all certificates
                 case 'pdf':
                     $pdf = $this->create_pdf_object();
                     foreach ($users as $user) {
                         $canissue = $this->can_issue($user, $issuelist != 'allusers');
                         if (empty($canissue)) {
                             //To one pdf file
                             $issuecert = $this->get_issue($user);
                             $this->create_pdf($issuecert, $pdf, true);
                             //Save certificate PDF
                             if (!$this->issue_file_exists($issuecert)) {
                                 //To force file creation
                                 $issuecert->haschage = true;
                                 $this->get_issue_file($issuecert);
                             }
                         }
                     }
                     $pdf->Output($filename, 'D');
                     break;
                     //One zip with all certificates in separated files
                 //One zip with all certificates in separated files
                 case 'zip':
                     $filesforzipping = array();
                     foreach ($users as $user) {
                         $canissue = $this->can_issue($user, $issuelist != 'allusers');
                         if (empty($canissue)) {
                             $issuecert = $this->get_issue($user);
                             if ($file = $this->get_issue_file($issuecert)) {
                                 $fileforzipname = $file->get_filename();
                                 $filesforzipping[$fileforzipname] = $file;
                             } else {
                                 error_log(get_string('filenotfound', 'simplecertificate'));
                                 print_error(get_string('filenotfound', 'simplecertificate'));
                             }
                         }
                     }
                     $tempzip = $this->create_temp_file('issuedcertificate_');
                     //zipping files
                     $zipper = new zip_packer();
                     if ($zipper->archive_to_pathname($filesforzipping, $tempzip)) {
                         //send file and delete after sending.
                         send_temp_file($tempzip, $filename);
                     }
                     break;
                 case 'email':
                     foreach ($users as $user) {
                         $canissue = $this->can_issue($user, $issuelist != 'allusers');
                         if (empty($canissue)) {
                             $issuecert = $this->get_issue($user);
                             if ($this->get_issue_file($issuecert)) {
                                 $this->send_certificade_email($issuecert);
                             } else {
                                 error_log(get_string('filenotfound', 'simplecertificate'));
                                 print_error('filenotfound', 'simplecertificate');
                             }
                         }
                     }
                     $url->remove_params('action', 'type');
                     redirect($url, get_string('emailsent', 'simplecertificate'), 5);
                     break;
             }
             exit;
         }
     }
     echo $OUTPUT->footer();
 }
Example #5
0
/**
 * Returns navigation controls (tabtree) to be displayed on cohort management pages
 *
 * @param context $context system or category context where cohorts controls are about to be displayed
 * @param moodle_url $currenturl
 * @return null|renderable
 */
function cohort_edit_controls(context $context, moodle_url $currenturl)
{
    $tabs = array();
    $currenttab = 'view';
    $viewurl = new moodle_url('/cohort/index.php', array('contextid' => $context->id));
    if ($searchquery = $currenturl->get_param('search')) {
        $viewurl->param('search', $searchquery);
    }
    if ($context->contextlevel == CONTEXT_SYSTEM) {
        $tabs[] = new tabobject('view', new moodle_url($viewurl, array('showall' => 0)), get_string('systemcohorts', 'cohort'));
        $tabs[] = new tabobject('viewall', new moodle_url($viewurl, array('showall' => 1)), get_string('allcohorts', 'cohort'));
        if ($currenturl->get_param('showall')) {
            $currenttab = 'viewall';
        }
    } else {
        $tabs[] = new tabobject('view', $viewurl, get_string('cohorts', 'cohort'));
    }
    if (has_capability('moodle/cohort:manage', $context)) {
        $addurl = new moodle_url('/cohort/edit.php', array('contextid' => $context->id));
        $tabs[] = new tabobject('addcohort', $addurl, get_string('addcohort', 'cohort'));
        if ($currenturl->get_path() === $addurl->get_path() && !$currenturl->param('id')) {
            $currenttab = 'addcohort';
        }
        $uploadurl = new moodle_url('/cohort/upload.php', array('contextid' => $context->id));
        $tabs[] = new tabobject('uploadcohorts', $uploadurl, get_string('uploadcohorts', 'cohort'));
        if ($currenturl->get_path() === $uploadurl->get_path()) {
            $currenttab = 'uploadcohorts';
        }
    }
    if (count($tabs) > 1) {
        return new tabtree($tabs, $currenttab);
    }
    return null;
}
 /**
  * Return random question form.
  * @param \moodle_url $thispageurl the canonical URL of this page.
  * @param \question_edit_contexts $contexts the relevant question bank contexts.
  * @param array $pagevars the variables from {@link \question_edit_setup()}.
  * @return string HTML to output.
  */
 protected function random_question_form(\moodle_url $thispageurl, \question_edit_contexts $contexts, array $pagevars)
 {
     if (!$contexts->have_cap('moodle/question:useall')) {
         return '';
     }
     $randomform = new \offlinequiz_add_random_form(new \moodle_url('/mod/offlinequiz/addrandom.php'), array('contexts' => $contexts, 'cat' => $pagevars['cat'], 'groupnumber' => $thispageurl->get_param('groupnumber')));
     $randomform->set_data(array('category' => $pagevars['cat'], 'returnurl' => $thispageurl->out_as_local_url(true), 'randomnumber' => 1, 'cmid' => $thispageurl->param('cmid')));
     return html_writer::div($randomform->render(), 'randomquestionformforpopup');
 }
 *
 * @package    mod
 * @subpackage oublog
 * @copyright  2014 The Open University
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
define('AJAX_SCRIPT', true);
require_once dirname(__FILE__) . '/../../config.php';
header('Content-Type: text/plain');
try {
    // Test session - These functions throw exceptions so trap and exit if they fail.
    // This saves 404 errors and sends a smaller page.
    require_login(null, true);
    require_sesskey();
} catch (moodle_exception $e) {
    $pid = 0;
    $url = '/mod/oublog/editpost.php';
    if (!empty($_SERVER['HTTP_REFERER'])) {
        $url = new moodle_url($_SERVER['HTTP_REFERER']);
        $rpid = $url->get_param('post');
        if (!empty($rpid)) {
            $pid = $rpid;
        }
        $url = $url->out_as_local_url();
    }
    $params = array('context' => context_system::instance(), 'other' => array('page' => $url, 'pid' => $pid));
    $event = \mod_oublog\event\save_failed::create($params);
    $event->trigger();
    exit;
}
echo 'ok';
 *
 * @package    mod
 * @subpackage ouwiki
 * @copyright  2013 The Open University
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
define('AJAX_SCRIPT', true);
require_once dirname(__FILE__) . '/../../config.php';
header('Content-Type: text/plain');
try {
    // Test session - These functions throw exceptions so trap and exit if they fail.
    // This saves 404 errors and sends a smaller page.
    require_login(null, true);
    require_sesskey();
} catch (moodle_exception $e) {
    $pid = 0;
    $url = '/mod/ouwiki/edit.php';
    if (!empty($_SERVER['HTTP_REFERER'])) {
        $url = new moodle_url($_SERVER['HTTP_REFERER']);
        $rpid = $url->get_param('id');
        if (!empty($rpid)) {
            $pid = $rpid;
        }
        $url = $url->out_as_local_url();
    }
    $params = array('context' => context_system::instance(), 'other' => array('page' => $url, 'pid' => $pid));
    $event = \mod_ouwiki\event\save_failed::create($params);
    $event->trigger();
    exit;
}
echo 'ok';
 /**
  * Upgrade the submission from the old assignment to the new one
  *
  * @param context $oldcontext - the database for the old assignment context
  * @param stdClass $oldassignment The data record for the old assignment
  * @param stdClass $oldsubmission The data record for the old submission
  * @param stdClass $submission The data record for the new submission
  * @param string $log Record upgrade messages in the log
  * @return bool true or false - false will trigger a rollback
  */
 public function upgrade(context $oldcontext, stdClass $oldassignment, stdClass $oldsubmission, stdClass $submission, &$log)
 {
     global $DB;
     $maharadata = unserialize($oldsubmission->data2);
     $maharasubmission = new stdClass();
     $maharasubmission->viewid = $maharadata['id'];
     $maharasubmission->viewurl = $maharadata['url'];
     $maharasubmission->viewtitle = $maharadata['title'];
     $url = new moodle_url($maharadata['url']);
     if ($url->get_param('mt')) {
         $maharasubmission->viewstatus = self::STATUS_SUBMITTED;
     }
     $maharasubmission->submission = $submission->id;
     $maharasubmission->assignment = $this->assignment->get_instance()->id;
     if (!$DB->insert_record('assignsubmission_mahara', $maharasubmission) > 0) {
         $log .= get_string('couldnotconvertsubmission', 'mod_assign', $submission->userid);
         return false;
     }
     return true;
 }