コード例 #1
0
function AppendSudokuB()
{
    global $DB;
    $level1 = required_param('level1', PARAM_NUMBER);
    // action
    $level2 = required_param('level2', PARAM_NUMBER);
    // action
    $count = required_param('count', PARAM_NUMBER);
    // action
    $level = $level1;
    for ($i = 1; $i <= $count; $i++) {
        //set_time_limit( 30);
        Create($si, $sp, $level);
        $newrec->data = PackSudoku($si, $sp);
        if (strlen($newrec->data) != 81) {
            return 0;
        }
        $newrec->level = $level;
        $newrec->opened = GetOpened($si);
        $DB->insert_record('game_sudoku_database', $newrec, true);
        $level++;
        if ($level > $level2) {
            $level = $level1;
        }
        echo get_string('sudoku_creating', 'game', $i) . "<br>\r\n";
    }
}
コード例 #2
0
ファイル: variations.php プロジェクト: go38/moodle-mod_vpl
 function definition()
 {
     $mform =& $this->_form;
     if ($this->number >= 0) {
         $title = get_string('variation', VPL, "{$this->number}");
     } else {
         $title = get_string('add');
     }
     $mform->addElement('header', 'variation' . ($this->number + 100), $title);
     $mform->addElement('hidden', 'id', required_param('id', PARAM_INT));
     $mform->setType('id', PARAM_INT);
     $mform->addElement('hidden', 'varid', $this->varid);
     $mform->setType('varid', PARAM_INT);
     $mform->addElement('text', 'identification', get_string('varidentification', VPL), array('size' => '20'));
     $mform->setDefault('identification', '');
     $mform->setType('identification', PARAM_RAW);
     $mform->addElement('textarea', 'description', get_string('description', VPL), array('cols' => 45, 'rows' => 5));
     $mform->setType('description', PARAM_CLEANHTML);
     $mform->setDefault('description', '');
     $buttongroup = array();
     $buttongroup[] = $mform->createElement('submit', 'save', get_string('save', VPL));
     $buttongroup[] = $mform->createElement('submit', 'cancel', get_string('cancel'));
     if ($this->number >= 0) {
         $menssage = addslashes(get_string('delete'));
         $onclick = 'onclick="return confirm(\'' . $menssage . '\')"';
         $buttongroup[] = $mform->createElement('submit', 'delete', get_string('delete'), $onclick);
     }
     $mform->addGroup($buttongroup);
 }
コード例 #3
0
ファイル: enroledit.action.php プロジェクト: jamesmcq/elis
 /**
  * Responds to a javascript request.
  *
  * Processes incoming information and updates the relevant user's information, including learning objectives.
  * Also responds to a request for enrolment data, used when editing a single user.
  *
  * @param array $elements An array of elements to perform the action on. Although the values will differ, the indexes
  *                        will always be element IDs.
  * @param bool $bulkaction Whether this is a bulk-action or not.
  * @return array A response array, consisting of result and msg.
  */
 protected function _respond_to_js(array $elements, $bulkaction)
 {
     $classid = required_param('id', PARAM_INT);
     $mode = optional_param('mode', 'complete', PARAM_ALPHA);
     if ($mode == 'getinfo') {
         foreach ($elements as $userid => $label) {
             return array('result' => 'success', 'msg' => 'Success', 'enroldata' => $this->get_enrol_data($userid, $classid));
         }
     } else {
         set_time_limit(0);
         // Enrolment data.
         $enroldata = required_param('enroldata', PARAM_CLEAN);
         $enroldata = $this->process_enrolment_data($classid, @json_decode($enroldata));
         if (empty($enroldata)) {
             throw new Exception('Did not receive valid enrolment data.');
         }
         // Learning objectives.
         $learningobjectives = optional_param('learnobjdata', '', PARAM_CLEAN);
         $learningobjectives = !empty($learningobjectives) ? $this->process_learning_objectives_data($learningobjectives) : array();
         foreach ($elements as $userid => $label) {
             $this->do_update($userid, $classid, $enroldata, $learningobjectives);
         }
         $formattedenroldata = $this->format_enroldata_for_display($enroldata);
     }
     return array('result' => 'success', 'msg' => 'Success', 'enroldata' => $enroldata, 'displaydata' => $formattedenroldata);
 }
コード例 #4
0
 /**
  * Invoke method, every class will have its own
  * returns true/false on completion, setting both
  * errormsg and output as necessary
  */
 function invoke()
 {
     parent::invoke();
     $result = true;
     /// Set own core attributes
     $this->does_generate = ACTION_NONE;
     //$this->does_generate = ACTION_GENERATE_HTML;
     /// These are always here
     global $CFG, $XMLDB;
     /// Do the job, setting result as needed
     /// Get the dir containing the file
     $dirpath = required_param('dir', PARAM_PATH);
     $dirpath = $CFG->dirroot . $dirpath;
     /// Get the correct dirs
     if (!empty($XMLDB->dbdirs)) {
         $dbdir =& $XMLDB->dbdirs[$dirpath];
     } else {
         return false;
     }
     if (!empty($XMLDB->editeddirs)) {
         $editeddir =& $XMLDB->editeddirs[$dirpath];
         $structure =& $editeddir->xml_file->getStructure();
     }
     /// ADD YOUR CODE HERE
     /// Launch postaction if exists (leave this here!)
     if ($this->getPostAction() && $result) {
         return $this->launch($this->getPostAction());
     }
     /// Return ok if arrived here
     return $result;
 }
コード例 #5
0
 function definition()
 {
     global $CFG, $DB;
     $mform =& $this->_form;
     // this hack is needed for different settings of each subtype
     if (!empty($this->_instance)) {
         if ($res = $DB->get_record('resource', array('id' => $this->_instance))) {
             $type = $res->type;
         } else {
             print_error('invalidassignment', 'resource');
         }
     } else {
         $type = required_param('type', PARAM_ALPHA);
     }
     $mform->addElement('hidden', 'type', $type);
     $mform->setDefault('type', $type);
     require $CFG->dirroot . '/mod/resource/type/' . $type . '/resource.class.php';
     $resclass = 'resource_' . $type;
     $this->_resinstance = new $resclass();
     //-------------------------------------------------------------------------------
     $mform->addElement('header', 'general', get_string('general', 'form'));
     $mform->addElement('text', 'name', get_string('name'), array('size' => '48'));
     if (!empty($CFG->formatstringstriptags)) {
         $mform->setType('name', PARAM_TEXT);
     } else {
         $mform->setType('name', PARAM_CLEAN);
     }
     $mform->addRule('name', null, 'required', null, 'client');
     $this->add_intro_editor(false);
     $mform->addElement('header', 'typedesc', resource_get_name($type));
     $this->_resinstance->setup_elements($mform);
     $this->standard_coursemodule_elements();
     $this->add_action_buttons();
 }
コード例 #6
0
ファイル: locallib.php プロジェクト: sikeze/emarking
/**
 * Obtains course module ($cm), course, emarking and context
 * objects from cm id in the URL
 *
 * @return multitype:stdClass context_module unknown mixed
 */
function emarking_get_cm_course_instance()
{
    global $DB;
    // Course module id.
    $cmid = required_param('id', PARAM_INT);
    return emarking_get_cm_course_instance_by_id($cmid);
}
コード例 #7
0
 function definition()
 {
     global $DB, $PAGE, $OUTPUT;
     $id = required_param('id', PARAM_INT);
     // course module
     if (!($cm = get_coursemodule_from_id('blended', $id))) {
         error("Course Module ID was incorrect");
     }
     if (!($course = get_course($cm->course))) {
         error("Course is misconfigured");
     }
     if (!($blended = $DB->get_record('blended', array('id' => $cm->instance)))) {
         error("Course module is incorrect");
     }
     $form =& $this->_form;
     $calificables = new grade_tree($course->id);
     $items = $calificables->items;
     $ins = array();
     $assignmentname = array();
     // Obtenemos las referencias a toda la informaci�n sobre los modulos dentro del curso
     $modinfo = get_fast_modinfo($course->id);
     foreach ($modinfo->instances as $abc) {
         foreach ($abc as $cmd) {
             foreach ($items as $r => $ite) {
                 $ins[$r] = $ite->iteminstance;
                 if ($cmd->instance == $ins[$r]) {
                     $assignmentname[$r] = $cmd->name;
                 }
             }
         }
     }
     $form->addElement('select', 'activities', 'Selecciona la Tarea', $assignmentname);
 }
コード例 #8
0
ファイル: search_form.php プロジェクト: nadavkav/MoodleTAO
 function definition()
 {
     global $CFG;
     $mform =& $this->_form;
     $add = optional_param('add', 0, PARAM_ALPHA);
     $return = optional_param('return', 0, PARAM_BOOL);
     //return to course/view.php if false or mod/modname/view.php if true
     $type = optional_param('type', '', PARAM_ALPHANUM);
     $section = required_param('section', PARAM_INT);
     $course = required_param('course', PARAM_INT);
     $mform->addElement('header', 'searchheader', get_string('searchheader', 'taoresource'));
     $plugins = taoresource_get_plugins();
     // let the plugins see the form definition
     foreach ($plugins as $plugin) {
         $rc = $plugin->search_definition($mform);
         if (!$rc) {
             break;
         }
     }
     $this->add_action_buttons(true, get_string('searchtaoresource', 'taoresource'));
     if (!($course = get_record("course", "id", $course))) {
         error("This course doesn't exist");
     }
     $context = get_context_instance(CONTEXT_COURSE, $course->id);
     if (has_capability('moodle/course:manageactivities', $context)) {
         $mform->addElement('header', 'addheader', get_string('addheader', 'taoresource'));
         $addbutton = $mform->addElement('submit', 'addtaoresource', get_string('addtaoresource', 'taoresource'));
         $buttonattributes = array('title' => get_string('addtaoresource', 'taoresource'), 'onclick' => "location.href = '" . $CFG->wwwroot . "/mod/taoresource/edit.php?course={$course->id}&section={$section}&type={$type}&add={$add}&return={$return}&mode=add'; return false;");
         $addbutton->updateAttributes($buttonattributes);
     }
 }
コード例 #9
0
/**
 * This function checks for a user's access to a particular form/page.  The main check
 * is requiring a user to be logged into a particular course.  Optionally, it will check
 * for a capability and check the user's sesskey.
 *
 * @param string $capability Verify the user has this capability.
 * @param bool $checksesskey T/F indicating whether sesskey should be checked.
 * @return bool T/F indicating if access is permitted.
 *
 */
function blocks_skills_group_verify_access($capability = null, $checksesskey = false)
{
    $courseid = required_param('courseid', PARAM_INT);
    try {
        require_login($courseid, false);
    } catch (Exception $e) {
        echo get_string('nologin', BLOCK_SG_LANG_TABLE);
        return false;
    }
    if ($capability != null) {
        if (!has_capability($capability, context_course::instance($courseid))) {
            echo get_string('noaccess', BLOCK_SG_LANG_TABLE);
            return false;
        }
    }
    try {
        if ($checksesskey != false) {
            if (!confirm_sesskey()) {
                echo get_string('badsesskey', BLOCK_SG_LANG_TABLE);
                return false;
            }
        }
    } catch (Exception $e) {
        echo get_string('badsesskey', BLOCK_SG_LANG_TABLE);
        return false;
    }
    return true;
}
コード例 #10
0
ファイル: view_headm.php プロジェクト: jerab/moodle-mod-praxe
 function praxe_view_headm()
 {
     global $USER, $cm, $tab, $tab_modes, $CFG, $context;
     //$praxeaction = optional_param('praxeaction', null, PARAM_ALPHAEXT);
     //$school = optional_param('school', null, PARAM_INT);
     switch ($tab) {
         case PRAXE_TAB_HEADM_HOME:
             //$schoolid = optional_param('schoolid', 0, PARAM_INT);
             if ($schools = praxe_get_schools($USER->id)) {
                 $this->content .= self::show_schools($schools, array('mode' => $tab_modes['headm'][PRAXE_TAB_HEADM_EDITSCHOOL]));
             } else {
                 $this->content .= get_string('noschoolsavailable', 'praxe');
             }
             break;
         case PRAXE_TAB_HEADM_ADDSCHOOL:
             self::addschool_form();
             break;
         case PRAXE_TAB_HEADM_TEACHERS:
             $schoolid = optional_param('schoolid', 0, PARAM_INT);
             if ($schoolid > 0) {
                 $this->content .= self::school_teachers_by_schools($USER->id, $schoolid);
             } else {
                 $this->content .= self::school_teachers_by_schools($USER->id);
             }
             break;
         case PRAXE_TAB_HEADM_LOCATIONS:
             $schoolid = optional_param('schoolid', 0, PARAM_INT);
             if ($schoolid > 0) {
                 $this->content .= self::show_locations($schoolid);
             } else {
                 $this->content .= self::show_locations(null, $USER->id);
                 $this->content .= "<p>" . get_string('to_create_location_choose_school', 'praxe') . "</p>";
             }
             break;
         case PRAXE_TAB_HEADM_EDITSCHOOL:
             $schoolid = required_param('schoolid', PARAM_INT);
             $school = praxe_get_school($schoolid);
             if (!praxe_has_capability('editownschool') || !is_object($school) || !$school->headmaster == $USER->id) {
                 print_error('notallowedaction', 'praxe');
             }
             self::addschool_form();
             $this->form->set_form_to_edit($school);
             break;
         case PRAXE_TAB_HEADM_ASSIGNTEACHERS:
             require_capability('mod/praxe:assignteachertoownschool', $context, $USER->id);
             $schoolid = required_param('schoolid', PARAM_INT);
             require_once $CFG->dirroot . '/mod/praxe/c_assignteachers.php';
             $this->form = new praxe_assignteachers($schoolid);
             break;
         case PRAXE_TAB_HEADM_ADDLOCATION:
             require_capability('mod/praxe:createownlocation', $context, $USER->id);
             $schoolid = required_param('schoolid', PARAM_INT);
             require_once $CFG->dirroot . '/mod/praxe/c_addlocation.php';
             $this->form = new praxe_addlocation($schoolid);
             break;
         default:
             redirect($CFG->wwwroot . '/mod/praxe/view.php?id=' . $cm->id);
             break;
     }
 }
コード例 #11
0
ファイル: mod_form.php プロジェクト: r007/PMoodle
 function definition()
 {
     global $CFG;
     $mform =& $this->_form;
     // this hack is needed for different settings of each subtype
     if (!empty($this->_instance)) {
         if ($res = get_record('resource', 'id', (int) $this->_instance)) {
             $type = $res->type;
         } else {
             error('incorrect assignment');
         }
     } else {
         $type = required_param('type', PARAM_ALPHA);
     }
     $mform->addElement('hidden', 'type', $type);
     $mform->setDefault('type', $type);
     require $CFG->dirroot . '/mod/resource/type/' . $type . '/resource.class.php';
     $resclass = 'resource_' . $type;
     $this->_resinstance = new $resclass();
     //-------------------------------------------------------------------------------
     $mform->addElement('header', 'general', get_string('general', 'form'));
     //        $mform->addElement('static', 'statictype', get_string('assignmenttype', 'assignment'), get_string('type'.$type,'assignment'));
     $mform->addElement('text', 'name', get_string('name'), array('size' => '48'));
     $mform->setType('name', PARAM_TEXT);
     $mform->addRule('name', null, 'required', null, 'client');
     $mform->addElement('htmleditor', 'summary', get_string('summary'));
     $mform->setType('summary', PARAM_RAW);
     $mform->setHelpButton('summary', array('summary', get_string('summary'), 'resource'));
     // summary should be optional again MDL-9485
     //$mform->addRule('summary', get_string('required'), 'required', null, 'client');
     $mform->addElement('header', 'typedesc', get_string('resourcetype' . $type, 'resource'));
     $this->_resinstance->setup_elements($mform);
     $this->standard_coursemodule_elements(array('groups' => false, 'groupmembersonly' => true, 'gradecat' => false));
     $this->add_action_buttons();
 }
コード例 #12
0
 function action_default()
 {
     global $USER, $CURMAN;
     $id = required_param('id', PARAM_INT);
     $contexts = clone trackpage::get_contexts('block/curr_admin:track:enrol');
     //look up student's cluster assignments with necessary capability
     $cluster_contexts = cm_context_set::for_user_with_capability('cluster', 'block/curr_admin:track:enrol_cluster_user', $USER->id);
     //calculate our filter condition based on cluster accessibility
     $cluster_filter = $cluster_contexts->sql_filter_for_context_level('clst.id', 'cluster');
     //query for getting tracks based on clusters
     $sql = "SELECT trk.id\n                FROM {$CURMAN->db->prefix_table(CLSTTABLE)} clst\n                JOIN {$CURMAN->db->prefix_table(CLSTTRKTABLE)} clsttrk\n                ON clst.id = clsttrk.clusterid\n                JOIN {$CURMAN->db->prefix_table(TRACKTABLE)} trk\n                ON clsttrk.trackid = trk.id\n                WHERE {$cluster_filter}";
     //assign the appropriate track ids
     $recordset = get_recordset_sql($sql);
     if ($recordset && $recordset->RecordCount() > 0) {
         if (!isset($contexts->contexts['track'])) {
             $contexts->contexts['track'] = array();
         }
         $new_tracks = array();
         while ($record = rs_fetch_next_record($recordset)) {
             $new_tracks[] = $record->id;
         }
         $contexts->contexts['track'] = array_merge($contexts->contexts['track'], $new_tracks);
     }
     $columns = array('idnumber' => get_string('track_idnumber', 'block_curr_admin'), 'name' => get_string('track_name', 'block_curr_admin'), 'description' => get_string('track_description', 'block_curr_admin'), 'numclasses' => get_string('num_classes', 'block_curr_admin'), 'manage' => '');
     $items = usertrack::get_tracks($id);
     $formatters = $this->create_link_formatters(array('idnumber', 'name'), 'trackpage', 'trackid');
     $this->print_list_view($items, $columns, $formatters, 'tracks');
     //get the listing specifically for this user
     $this->print_dropdown(track_get_listing('name', 'ASC', 0, 0, '', '', 0, 0, $contexts, $id), $items, 'userid', 'trackid', 'savenew', 'idnumber');
 }
コード例 #13
0
ファイル: view_xml.class.php プロジェクト: nigeldaley/moodle
 /**
  * Invoke method, every class will have its own
  * returns true/false on completion, setting both
  * errormsg and output as necessary
  */
 function invoke()
 {
     parent::invoke();
     $result = true;
     /// Set own core attributes
     $this->does_generate = ACTION_GENERATE_XML;
     /// These are always here
     global $CFG, $XMLDB;
     /// Do the job, setting result as needed
     /// Get the file parameter
     $file = required_param('file', PARAM_PATH);
     $file = $CFG->dirroot . $file;
     /// File must be under $CFG->wwwroot and
     ///  under one db directory (simple protection)
     if (substr($file, 0, strlen($CFG->dirroot)) == $CFG->dirroot && substr(dirname($file), -2, 2) == 'db') {
         /// Everything is ok. Load the file to memory
         $this->output = file_get_contents($file);
     } else {
         /// Switch to HTML and error
         $this->does_generate = ACTION_GENERATE_HTML;
         $this->errormsg = 'File not viewable (' . $file . ')';
         $result = false;
     }
     /// Return ok if arrived here
     return $result;
 }
コード例 #14
0
 function process_form()
 {
     if (optional_param('index', '', PARAM_TEXT)) {
         return lightboxgallery_index_thumbnail($this->gallery->course, $this->gallery, $this->image);
     } else {
         if (optional_param('reset', '', PARAM_TEXT)) {
             $offsetx = 0;
             $offsety = 0;
         } else {
             $move = required_param('move', PARAM_INT);
             $offset = optional_param('offset', 20, PARAM_INT);
             switch ($move) {
                 case 1:
                     $offsetx = 0;
                     $offsety = -$offset;
                     break;
                 case 2:
                     $offsetx = 0;
                     $offsety = $offset;
                     break;
                 case 3:
                     $offsetx = -$offset;
                     $offsety = 0;
                     break;
                 case 4:
                     $offsetx = $offset;
                     $offsety = 0;
                     break;
             }
         }
     }
     $this->imageobj->create_thumbnail($offsetx, $offsety);
 }
コード例 #15
0
 /**
  * Invoke method, every class will have its own
  * returns true/false on completion, setting both
  * errormsg and output as necessary
  */
 function invoke()
 {
     parent::invoke();
     $result = true;
     // Set own core attributes
     $this->does_generate = ACTION_NONE;
     //$this->does_generate = ACTION_GENERATE_HTML;
     // These are always here
     global $CFG, $XMLDB;
     // Do the job, setting result as needed
     // Get the dir containing the file
     $dirpath = required_param('dir', PARAM_PATH);
     $dirpath = $CFG->dirroot . $dirpath;
     // Get the correct dirs
     if (!empty($XMLDB->dbdirs)) {
         $dbdir =& $XMLDB->dbdirs[$dirpath];
     } else {
         return false;
     }
     if (!empty($XMLDB->editeddirs)) {
         $editeddir =& $XMLDB->editeddirs[$dirpath];
         $structure =& $editeddir->xml_file->getStructure();
     }
     // If the changeme table exists, just get it and continue
     $changeme_exists = false;
     if ($tables =& $structure->getTables()) {
         if ($table =& $structure->getTable('changeme')) {
             $changeme_exists = true;
         }
     }
     if (!$changeme_exists) {
         // Lets create the table
         $field = new xmldb_field('id');
         $field->setType(XMLDB_TYPE_INTEGER);
         $field->setLength(10);
         $field->setNotNull(true);
         $field->setUnsigned(true);
         $field->setSequence(true);
         $field->setLoaded(true);
         $field->setChanged(true);
         $key = new xmldb_key('primary');
         $key->setType(XMLDB_KEY_PRIMARY);
         $key->setFields(array('id'));
         $key->setLoaded(true);
         $key->setChanged(true);
         $table = new xmldb_table('changeme');
         $table->setComment('Default comment for the table, please edit me');
         $table->addField($field);
         $table->addKey($key);
         // Finally, add the whole retrofitted table to the structure
         // in the place specified
         $structure->addTable($table);
     }
     // Launch postaction if exists (leave this here!)
     if ($this->getPostAction() && $result) {
         return $this->launch($this->getPostAction());
     }
     // Return ok if arrived here
     return $result;
 }
コード例 #16
0
 /**
  * Move incoming usersets to be a subuset of current userset.
  * @throws moodle_exception
  * @param array $elements An array of userset information to assign to the track.
  * @param bool $bulkaction Whether this is a bulk-action or not.
  * @return array An array to format as JSON and return to the Javascript.
  */
 protected function _respond_to_js(array $elements, $bulkaction)
 {
     global $DB, $USER;
     // The userset that will be the new parent set.
     $curusersetid = required_param('id', PARAM_INT);
     // Limit incoming usersets to possible-to-move usersets.
     $possiblesubsets = cluster_get_possible_sub_clusters($curusersetid);
     $elements = array_intersect_key($elements, $possiblesubsets);
     unset($possiblesubsets);
     // We need edit permissions.
     $perm = 'local/elisprogram:userset_edit';
     $userseteditctx = pm_context_set::for_user_with_capability('cluster', $perm, $USER->id);
     if ($userseteditctx->context_allowed($curusersetid, 'cluster') !== true) {
         throw new moodle_exception('not_permitted', 'local_elisprogram');
     }
     // Loop through requested elements to move. Check for permissions and do an sanity check on IDs and parent ID, then move.
     foreach ($elements as $tomoveusersetid => $label) {
         // Ensure user has edit perm on $tomoveusersetid.
         if ($userseteditctx->context_allowed($tomoveusersetid, 'cluster')) {
             $tomove = new userset($tomoveusersetid);
             $tomove->load();
             // The userset we're moving shouldn't be the userset we're moving below, and it shouldn't already be a child
             // of the new parent.
             if ($tomove->id !== $curusersetid && $tomove->parent !== $curusersetid) {
                 $tomove->parent = $curusersetid;
                 $tomove->save();
             }
         }
     }
     return array('result' => 'success', 'msg' => 'Success');
 }
コード例 #17
0
 public function process_form()
 {
     $caption = required_param('caption', PARAM_NOTAGS);
     $fs = get_file_storage();
     $stored_file = $fs->get_file($this->context->id, 'mod_lightboxgallery', 'gallery_images', '0', '/', $this->image);
     $image = new lightboxgallery_image($stored_file, $this->gallery, $this->cm);
     $image->set_caption($caption);
 }
コード例 #18
0
 public function process_form()
 {
     $angle = required_param('angle', PARAM_INT);
     $fs = get_file_storage();
     $storedfile = $fs->get_file($this->context->id, 'mod_lightboxgallery', 'gallery_images', '0', '/', $this->image);
     $image = new lightboxgallery_image($storedfile, $this->gallery, $this->cm);
     $this->image = $image->rotate_image($angle);
 }
コード例 #19
0
ファイル: mod_form.php プロジェクト: JackCanada/moodle-hacks
 function definition()
 {
     global $CFG;
     $mform =& $this->_form;
     // this hack is needed for different settings of each subtype
     if (!empty($this->_instance)) {
         if ($ass = get_record('assignment', 'id', (int) $this->_instance)) {
             $type = $ass->assignmenttype;
         } else {
             error('incorrect assignment');
         }
     } else {
         $type = required_param('type', PARAM_ALPHA);
     }
     $mform->addElement('hidden', 'assignmenttype', $type);
     $mform->setDefault('assignmenttype', $type);
     $mform->addElement('hidden', 'type', $type);
     $mform->setDefault('type', $type);
     require $CFG->dirroot . '/mod/assignment/type/' . $type . '/assignment.class.php';
     $assignmentclass = 'assignment_' . $type;
     $assignmentinstance = new $assignmentclass();
     //-------------------------------------------------------------------------------
     $mform->addElement('header', 'general', get_string('general', 'form'));
     //        $mform->addElement('static', 'statictype', get_string('assignmenttype', 'assignment'), get_string('type'.$type,'assignment'));
     $mform->addElement('text', 'name', get_string('assignmentname', 'assignment'), array('size' => '64'));
     if (!empty($CFG->formatstringstriptags)) {
         $mform->setType('name', PARAM_TEXT);
     } else {
         $mform->setType('name', PARAM_CLEAN);
     }
     $mform->addRule('name', null, 'required', null, 'client');
     $mform->addElement('htmleditor', 'description', get_string('description', 'assignment'));
     $mform->setType('description', PARAM_RAW);
     $mform->setHelpButton('description', array('writing', 'questions', 'richtext'), false, 'editorhelpbutton');
     $mform->addRule('description', get_string('required'), 'required', null, 'client');
     $mform->addElement('modgrade', 'grade', get_string('grade'));
     $mform->setDefault('grade', 100);
     $mform->addElement('date_time_selector', 'timeavailable', get_string('availabledate', 'assignment'), array('optional' => true));
     $mform->setDefault('timeavailable', time());
     $mform->addElement('date_time_selector', 'timedue', get_string('duedate', 'assignment'), array('optional' => true));
     $mform->setDefault('timedue', time() + 7 * 24 * 3600);
     $ynoptions = array(0 => get_string('no'), 1 => get_string('yes'));
     $mform->addElement('select', 'preventlate', get_string('preventlate', 'assignment'), $ynoptions);
     $mform->setDefault('preventlate', 0);
     $typetitle = get_string('type' . $type, 'assignment');
     // hack to support pluggable assignment type titles
     if ($typetitle === '[[type' . $type . ']]') {
         $typetitle = get_string('type' . $type, 'assignment_' . $type);
     }
     $mform->addElement('header', 'typedesc', $typetitle);
     $assignmentinstance->setup_elements($mform);
     $features = new stdClass();
     $features->groups = true;
     $features->groupings = true;
     $features->groupmembersonly = true;
     $this->standard_coursemodule_elements($features);
     $this->add_action_buttons();
 }
コード例 #20
0
 /**
  * Retrieves ajax parameters for content and update or delete
  * user data depending on params.
  *
  * @throws \coding_exception
  */
 public static function handle_ajax()
 {
     global $DB;
     // Query String Parameters.
     $content_id = required_param('content_id', PARAM_INT);
     $data_id = required_param('data_type', PARAM_RAW);
     $sub_content_id = required_param('sub_content_id', PARAM_INT);
     // Form Data.
     $data = optional_param('data', null, PARAM_RAW);
     $pre_load = optional_param('preload', null, PARAM_INT);
     $invalidate = optional_param('invalidate', null, PARAM_INT);
     if ($content_id === null || $data_id === null || $sub_content_id === null) {
         \H5PCore::ajaxError(get_string('missingparameters', 'hvp'));
         exit;
         // Missing parameters.
     }
     // Saving data
     if ($data !== NULL && $pre_load !== NULL && $invalidate !== NULL) {
         // Validate token
         if (!\H5PCore::validToken('contentuserdata', required_param('token', PARAM_RAW))) {
             \H5PCore::ajaxError(get_string('invalidtoken', 'hvp'));
             exit;
         }
         // Use context id if supplied
         $context_id = optional_param('contextId', null, PARAM_INT);
         if ($context_id) {
             $context = \context::instance_by_id($context_id);
         } else {
             // Otherwise try to find it from content id
             $context = \context_course::instance($DB->get_field('hvp', 'course', array('id' => $content_id)));
         }
         // Check permissions
         if (!has_capability('mod/hvp:savecontentuserdata', $context)) {
             \H5PCore::ajaxError(get_string('nopermissiontosavecontentuserdata', 'hvp'));
             http_response_code(403);
             exit;
         }
         if ($data === '0') {
             // Delete user data.
             self::delete_user_data($content_id, $sub_content_id, $data_id);
         } else {
             // Save user data.
             self::save_user_data($content_id, $sub_content_id, $data_id, $pre_load, $invalidate, $data);
         }
         \H5PCore::ajaxSuccess();
     } else {
         // Fetch user data
         $user_data = self::get_user_data($content_id, $sub_content_id, $data_id);
         if ($user_data === false) {
             // Did not find data, return nothing
             \H5PCore::ajaxSuccess();
         } else {
             // Found data, return encoded data
             \H5PCore::ajaxSuccess($user_data->data);
         }
     }
     exit;
 }
コード例 #21
0
 /**
  * Decides which content types the editor should have.
  *
  * Two usecases:
  * 1. No input, will list all the available content types.
  * 2. Libraries supported are specified, load additional data and verify
  * that the content types are available. Used by e.g. the Presentation Tool
  * Editor that already knows which content types are supported in its
  * slides.
  *
  * @param array $libraries List of library names + version to load info for
  * @return array List of all libraries loaded
  */
 public function getLibraries($libraries = null)
 {
     global $DB;
     $context_id = required_param('contextId', PARAM_RAW);
     $super_user = has_capability('mod/hvp:userestrictedlibraries', \context::instance_by_id($context_id));
     if ($libraries !== null) {
         // Get details for the specified libraries only.
         $librarieswithdetails = array();
         foreach ($libraries as $library) {
             // Look for library
             $details = $DB->get_record_sql("SELECT title,\n                                runnable,\n                                restricted,\n                                tutorial_url\n                           FROM {hvp_libraries}\n                          WHERE machine_name = ?\n                            AND major_version = ?\n                            AND minor_version = ?\n                            AND semantics IS NOT NULL\n                        ", array($library->name, $library->majorVersion, $library->minorVersion));
             if ($details) {
                 // Library found, add details to list
                 $library->tutorialUrl = $details->tutorial_url;
                 $library->title = $details->title;
                 $library->runnable = $details->runnable;
                 $library->restricted = $super_user ? false : ($details->restricted === '1' ? true : false);
                 $librarieswithdetails[] = $library;
             }
         }
         // Done, return list with library details
         return $librarieswithdetails;
     }
     // Load all libraries
     $libraries = array();
     $librariesresult = $DB->get_records_sql("SELECT id,\n                        machine_name AS name,\n                        title,\n                        major_version,\n                        minor_version,\n                        tutorial_url,\n                        restricted\n                   FROM {hvp_libraries}\n                  WHERE runnable = 1\n                    AND semantics IS NOT NULL\n               ORDER BY title");
     foreach ($librariesresult as $library) {
         // Remove unique index
         unset($library->id);
         // Convert snakes to camels
         $library->majorVersion = (int) $library->major_version;
         unset($library->major_version);
         $library->minorVersion = (int) $library->minor_version;
         unset($library->minor_version);
         if (!empty($library->tutorial_url)) {
             $library->tutorialUrl = $library->tutorial_url;
         }
         unset($library->tutorial_url);
         // Make sure we only display the newest version of a library.
         foreach ($libraries as $key => $existinglibrary) {
             if ($library->name === $existinglibrary->name) {
                 // Found library with same name, check versions
                 if ($library->majorVersion === $existinglibrary->majorVersion && $library->minorVersion > $existinglibrary->minorVersion || $library->majorVersion > $existinglibrary->majorVersion) {
                     // This is a newer version
                     $existinglibrary->isOld = true;
                 } else {
                     // This is an older version
                     $library->isOld = true;
                 }
             }
         }
         // Check to see if content type should be restricted
         $library->restricted = $super_user ? false : ($library->restricted === '1' ? true : false);
         // Add new library
         $libraries[] = $library;
     }
     return $libraries;
 }
コード例 #22
0
 /**
  * Invoke method, every class will have its own
  * returns true/false on completion, setting both
  * errormsg and output as necessary
  */
 function invoke()
 {
     parent::invoke();
     $result = true;
     /// Set own core attributes
     $this->does_generate = ACTION_GENERATE_HTML;
     /// These are always here
     global $CFG, $XMLDB, $DB;
     $dbman = $DB->get_manager();
     /// Do the job, setting result as needed
     /// Get the dir containing the file
     $dirpath = required_param('dir', PARAM_PATH);
     $dirpath = $CFG->dirroot . $dirpath;
     /// Get the correct dirs
     if (!empty($XMLDB->dbdirs)) {
         $dbdir =& $XMLDB->dbdirs[$dirpath];
     } else {
         return false;
     }
     if (!empty($XMLDB->editeddirs)) {
         $editeddir =& $XMLDB->editeddirs[$dirpath];
         $structure =& $editeddir->xml_file->getStructure();
     }
     /// ADD YOUR CODE HERE
     /// Get parameters
     $tableparam = required_param('table', PARAM_PATH);
     if (!($table = $structure->getTable($tableparam))) {
         $this->errormsg = 'Wrong table specified: ' . $tableparam;
         return false;
     }
     /// The back to edit table button
     $b = ' <p class="centerpara buttons">';
     $b .= '<a href="index.php?action=edit_table&amp;table=' . $tableparam . '&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['back'] . ']</a>';
     $b .= '</p>';
     $o = $b;
     $o .= '    <table id="formelements" class="boxaligncenter" cellpadding="5">';
     $o .= '      <tr><td><textarea cols="80" rows="32">';
     /// Get an array of statements
     if ($starr = $DB->get_manager()->generator->getCreateTableSQL($table)) {
         $starr = $dbman->generator->getEndedStatements($starr);
         $sqltext = '';
         foreach ($starr as $st) {
             $sqltext .= s($st) . "\n\n";
         }
         $sqltext = trim($sqltext);
         $o .= $sqltext;
     }
     $o .= '</textarea></td></tr>';
     $o .= '    </table>';
     $this->output = $o;
     /// Launch postaction if exists (leave this here!)
     if ($this->getPostAction() && $result) {
         return $this->launch($this->getPostAction());
     }
     /// Return ok if arrived here
     return $result;
 }
コード例 #23
0
 /**
  * Invoke method, every class will have its own
  * returns true/false on completion, setting both
  * errormsg and output as necessary
  */
 function invoke()
 {
     parent::invoke();
     $result = true;
     /// Set own core attributes
     $this->does_generate = ACTION_GENERATE_XML;
     /// These are always here
     global $CFG, $XMLDB;
     /// Do the job, setting result as needed
     /// Get the file parameter
     $select = required_param('select', PARAM_ALPHA);
     //original/edited
     /// Get the dir containing the file
     $dirpath = required_param('dir', PARAM_PATH);
     $dirpath = $CFG->dirroot . stripslashes_safe($dirpath);
     /// Get the correct dir
     if ($select == 'original') {
         if (!empty($XMLDB->dbdirs)) {
             $base =& $XMLDB->dbdirs[$dirpath];
         }
     } else {
         if ($select == 'edited') {
             if (!empty($XMLDB->editeddirs)) {
                 $base =& $XMLDB->editeddirs[$dirpath];
             }
         } else {
             $this->errormsg = 'Cannot access to ' . $select . ' info';
             $result = false;
         }
     }
     if ($base) {
         /// Only if the directory exists and it has been loaded
         if (!$base->path_exists || !$base->xml_loaded) {
             $this->errormsg = 'Directory ' . $dirpath . ' not loaded';
             return false;
         }
     } else {
         $this->errormsg = 'Problem handling ' . $select . ' files';
         return false;
     }
     /// Get the structure
     if ($result) {
         if (!($structure =& $base->xml_file->getStructure())) {
             $this->errormsg = 'Error retrieving ' . $select . ' structure';
             $result = false;
         }
     }
     if ($result) {
         /// Everything is ok. Generate the XML output
         $this->output = $structure->xmlOutput();
     } else {
         /// Switch to HTML and error
         $this->does_generate = ACTION_GENERATE_HTML;
     }
     /// Return ok if arrived here
     return $result;
 }
コード例 #24
0
 function print_header()
 {
     $id = required_param('id', PARAM_INT);
     parent::print_header();
     $mode = optional_param('mode', '', PARAM_ACTION);
     if ($mode != 'bare') {
         $this->print_tabs();
     }
 }
コード例 #25
0
function validate_request()
{
    $cmid = required_param('cmid', PARAM_INT);
    $userid = required_param('user', PARAM_INT);
    $filenum = required_param('cn', PARAM_INT);
    $vmsession = required_param('sesseionkey', PARAM_FILE);
    $data = required_param('record_data', PARAM_RAW);
    return array($cmid, $userid, $filenum, $vmsession, $data);
}
コード例 #26
0
 /**
  * Invoke method, every class will have its own
  * returns true/false on completion, setting both
  * errormsg and output as necessary
  */
 function invoke()
 {
     parent::invoke();
     $result = true;
     /// Set own core attributes
     $this->does_generate = ACTION_NONE;
     //$this->does_generate = ACTION_GENERATE_HTML;
     /// These are always here
     global $CFG, $XMLDB;
     /// Do the job, setting $result as needed
     /// Get the dir containing the file
     $dirpath = required_param('dir', PARAM_PATH);
     $dirpath = $CFG->dirroot . stripslashes_safe($dirpath);
     /// Get the correct dir
     if (!empty($XMLDB->dbdirs)) {
         $dbdir =& $XMLDB->dbdirs[$dirpath];
         if ($dbdir) {
             /// Set some defaults
             $dbdir->xml_exists = false;
             $dbdir->xml_writeable = false;
             $dbdir->xml_loaded = false;
             ///Only if the directory exists
             if (!$dbdir->path_exists) {
                 return false;
             }
             $xmldb_file = new XMLDBFile($dbdir->path . '/install.xml');
             ///Set the XML DTD and schema
             $xmldb_file->setDTD($CFG->dirroot . '/lib/xmldb/xmldb.dtd');
             $xmldb_file->setSchema($CFG->dirroot . '/lib/xmldb/xmldb.xsd');
             /// Set dbdir as necessary
             if ($xmldb_file->fileExists()) {
                 $dbdir->xml_exists = true;
             }
             if ($xmldb_file->fileWriteable()) {
                 $dbdir->xml_writeable = true;
             }
             /// Load the XML contents to structure
             $loaded = $xmldb_file->loadXMLStructure();
             if ($loaded && $xmldb_file->isLoaded()) {
                 $dbdir->xml_loaded = true;
                 $dbdir->filemtime = filemtime($dbdir->path . '/install.xml');
             }
             $dbdir->xml_file = $xmldb_file;
         } else {
             $this->errormsg = 'Wrong directory (' . $dirpath . ')';
             $result = false;
         }
     } else {
         $this->errormsg = 'XMLDB structure not found';
         $result = false;
     }
     /// Launch postaction if exists
     if ($this->getPostAction() && $result) {
         return $this->launch($this->getPostAction());
     }
     return $result;
 }
コード例 #27
0
 function process_form()
 {
     $angle = required_param('angle', PARAM_INT);
     $info = lightboxgallery_image_info($this->imagepath);
     if ($im = lightboxgallery_imagecreatefromtype($info->imagesize[2], $this->imagepath)) {
         $rotated = imagerotate($im, $angle, 0);
         $this->save_image_resource($rotated, $info->imagesize[2]);
     }
 }
コード例 #28
0
 function action_default()
 {
     $id = required_param('id', PARAM_INT);
     $columns = array('name' => get_string('tag_name', 'block_curr_admin'), 'description' => get_string('tag_description', 'block_curr_admin'), 'manage' => '');
     $items = taginstance::get_instance_tags($this->instance_type, $id);
     $formatters = $this->create_link_formatters(array('name'), 'tagpage', 'tagid');
     $this->print_list_view($items, $columns, $formatters, 'tags');
     $this->print_dropdown(tag_get_listing(), $items, 'instanceid', 'tagid');
 }
コード例 #29
0
 /**
  * Invoke method, every class will have its own
  * returns true/false on completion, setting both
  * errormsg and output as necessary
  */
 function invoke()
 {
     parent::invoke();
     $result = true;
     // Set own core attributes
     $this->does_generate = ACTION_NONE;
     // These are always here
     global $CFG, $XMLDB;
     // Do the job, setting result as needed
     // Get the dir containing the file
     $dirpath = required_param('dir', PARAM_PATH);
     $dirpath = $CFG->dirroot . $dirpath;
     $unload = optional_param('unload', true, PARAM_BOOL);
     // Get the edited dir
     if (!empty($XMLDB->editeddirs)) {
         if (isset($XMLDB->editeddirs[$dirpath])) {
             $editeddir = $XMLDB->editeddirs[$dirpath];
         }
     }
     // Copy the edited dir over the original one
     if (!empty($XMLDB->dbdirs)) {
         if (isset($XMLDB->dbdirs[$dirpath])) {
             $XMLDB->dbdirs[$dirpath] = unserialize(serialize($editeddir));
             $dbdir = $XMLDB->dbdirs[$dirpath];
         }
     }
     // Check for perms
     if (!is_writeable($dirpath . '/install.xml')) {
         $this->errormsg = $this->str['filenotwriteable'] . '(' . $dirpath . '/install.xml)';
         return false;
     }
     // Save the original dir
     $result = $dbdir->xml_file->saveXMLFile();
     if ($result) {
         // Delete the edited dir
         unset($XMLDB->editeddirs[$dirpath]);
         // Unload de originaldir
         unset($XMLDB->dbdirs[$dirpath]->xml_file);
         unset($XMLDB->dbdirs[$dirpath]->xml_loaded);
         unset($XMLDB->dbdirs[$dirpath]->xml_changed);
         unset($XMLDB->dbdirs[$dirpath]->xml_exists);
         unset($XMLDB->dbdirs[$dirpath]->xml_writeable);
     } else {
         $this->errormsg = 'Error saving XML file (' . $dirpath . ')';
         return false;
     }
     // If unload has been disabled, simulate it by reloading the file now
     if (!$unload) {
         return $this->launch('load_xml_file');
     }
     // Launch postaction if exists (leave this here!)
     if ($this->getPostAction() && $result) {
         return $this->launch($this->getPostAction());
     }
     // Return ok if arrived here
     return $result;
 }
コード例 #30
0
 function praxe_view_extteacher()
 {
     global $CFG, $tab, $USER, $tab_modes, $context;
     switch ($tab) {
         case PRAXE_TAB_EXTTEACHER_HOME:
             require_capability('mod/praxe:viewrecordstoownlocation', $context);
             $detail = optional_param('recordid', 0, PARAM_INT);
             if ($detail > 0 && ($record = praxe_get_record($detail))) {
                 if ($record->teacherid != $USER->id) {
                     print_error('notallowedaction', 'praxe');
                 }
                 $schid = optional_param('scheduleid', 0, PARAM_INT);
                 if ($schid > 0 && ($schedule = praxe_get_schedule($schid))) {
                     $this->content .= self::show_schedule_detail($schedule) . "<hr>";
                 }
                 $this->content .= self::show_record_detail($record);
             } else {
                 $this->content .= self::show_records();
             }
             break;
         case PRAXE_TAB_EXTTEACHER_MYLOCATIONS:
             $factual = optional_param('factualloc', 0, PARAM_INT);
             $fyear = optional_param('fyearloc', 0, PARAM_INT);
             $this->content .= self::show_all_my_locations($factual, $fyear);
             break;
         case PRAXE_TAB_EXTTEACHER_MYSCHOOLS:
             $schoolid = optional_param('schoolid', 0, PARAM_INT);
             $schools = praxe_get_schools(null, $USER->id);
             if ($schoolid == 0) {
                 $this->content .= self::show_schools($schools);
             } else {
                 if (isset($schools[$schoolid])) {
                     require_once $CFG->dirroot . '/mod/praxe/view_headm.php';
                     $this->content .= praxe_view_headm::show_school($schoolid);
                 } else {
                     redirect(praxe_get_base_url(), get_string('notallowedaction', 'praxe'));
                 }
             }
             break;
         case PRAXE_TAB_EXTTEACHER_EDITLOCATION:
             $locid = required_param('locationid', PARAM_INT);
             if (!($loc = praxe_get_location($locid, $USER->id))) {
                 print_error('notallowedaction', 'praxe');
             }
             require_once $CFG->dirroot . '/mod/praxe/c_addlocation.php';
             $this->form = new praxe_addlocation($loc->school);
             $this->form->set_redirect_url(null, array('mode' => $tab_modes['extteacher'][PRAXE_TAB_EXTTEACHER_MYLOCATIONS]));
             $this->form->set_form_to_edit($loc);
             break;
         case PRAXE_TAB_EXTTEACHER_COPYLOCATION:
             // TODO
             break;
         default:
             break;
     }
 }