Example #1
0
}
// Group description edit
if ($groupid and $canedit and isset($mygroups[$groupid]) and data_submitted()) {
    $egroup = $DB->get_record_sql("SELECT *\n                                 FROM {groups} g\n                                WHERE g.id = ?", array($groupid));
    if (strlen($newdescription) > create_form::DESCRIPTION_MAXLEN) {
        $newdescription = substr($newdescription, 0, create_form::DESCRIPTION_MAXLEN);
    }
    $egroup->description = $newdescription;
    groups_update_group($egroup);
    echo strip_tags(groupselect_get_group_info($egroup));
    die;
}
// Student group self-creation
if ($cancreate and $isopen) {
    $data = array('id' => $id, 'description' => '');
    $mform = new create_form(null, array($data, $groupselect));
    if ($mform->is_cancelled()) {
        redirect($PAGE->url);
    }
    if ($formdata = $mform->get_data()) {
        // Create a new group and add the creator as a member of it
        $params = array($course->id);
        $names = $DB->get_records_sql("SELECT g.name\n                   FROM {groups} g\n                  WHERE g.courseid = ?", $params);
        $max = 0;
        foreach ($names as $n) {
            if (intval($n->name) >= $max) {
                $max = intval($n->name);
            }
        }
        $data = (object) array('name' => strval($max + 1), 'description' => $formdata->description, 'courseid' => $course->id);
        $id = groups_create_group($data, false);
Example #2
0
 /**
  * Adds fields to this form that are relevant to the user making the request
  */
 protected function add_user_info()
 {
     // add the standard fields
     parent::add_user_info();
     $mform =& $this->_form;
     // disable editing of firstname, lastname and email
     $mform->hardFreeze('first');
     $mform->hardFreeze('last');
     $mform->hardFreeze('email');
 }
}
// Group description edit
if ($groupid and $canedit and isset($mygroups[$groupid]) and data_submitted()) {
    $egroup = $DB->get_record_sql("SELECT *\n                                 FROM {groups} g\n                                WHERE g.id = ?", array($groupid));
    if (strlen($newdescription) > create_form::DESCRIPTION_MAXLEN) {
        $newdescription = substr($newdescription, 0, create_form::DESCRIPTION_MAXLEN);
    }
    $egroup->description = $newdescription;
    groups_update_group($egroup);
    echo strip_tags(groupselect_get_group_info($egroup));
    die;
}
// Student group self-creation
if ($cancreate and $isopen) {
    $data = array('id' => $id, 'description' => '');
    $mform = new create_form(null, array($data, $groupselect));
    if ($mform->is_cancelled()) {
        redirect($PAGE->url);
    }
    if ($formdata = $mform->get_data()) {
        // Create a new group and add the creator as a member of it
        $params = array($course->id);
        if (!$formdata->groupname) {
            $names = $DB->get_records_sql("SELECT g.name\n\t                   FROM {groups} g\n\t                  WHERE g.courseid = ?", $params);
            $max = 0;
            foreach ($names as $n) {
                if (intval($n->name) >= $max) {
                    $max = intval($n->name);
                }
            }
            $groupname = strval($max + 1);
Example #4
0
 function display_create()
 {
     // action_create()
     global $CFG, $DB;
     $target = $this->get_new_page(array('action' => 'create'), true);
     $form = new create_form($target->url);
     $data = $form->get_data();
     if ($form->is_cancelled()) {
         redirect($this->url);
         // TBV
         return;
     } else {
         if ($data) {
             global $USER;
             require_once $CFG->dirroot . '/local/elisprogram/lib/data/course.class.php';
             $request = new stdClass();
             $request->userid = $USER->id;
             $request->firstname = $data->first;
             $request->lastname = $data->last;
             $request->email = $data->email;
             if (empty($data->title)) {
                 $course_record = $DB->get_record(course::TABLE, array('id' => $data->courseid));
                 $data->title = $course_record->name;
             }
             $request->title = $data->title;
             $request->courseid = $data->courseid;
             $request->usecoursetemplate = empty($data->usecoursetemplate) ? 0 : 1;
             $request->requeststatus = 'pending';
             $request->timemodified = $request->timecreated = time();
             $id = $DB->insert_record('block_courserequest', $request);
             $fields = $DB->get_records('block_courserequest_fields');
             $fields = $fields ? $fields : array();
             foreach ($fields as $reqfield) {
                 $field = new field($reqfield->fieldid);
                 if (!$field->id || !isset($field->owners['manual'])) {
                     // skip nonexistent fields, or fields without manual editing
                     continue;
                 }
                 $fielddata = new stdClass();
                 $fielddata->requestid = $id;
                 $fielddata->fieldid = $reqfield->fieldid;
                 // key that represents the appropriate attribute on the object
                 $field_key = "field_{$field->shortname}";
                 // make sure the field was enabled, especially for preventing the
                 // storage of course fields when using an existing course
                 if (isset($data->{$field_key})) {
                     // check for multiple fields
                     if (is_array($data->{$field_key})) {
                         $fielddata->data = serialize($data->{$field_key});
                         $fielddata->multiple = '1';
                     } else {
                         $fielddata->data = $data->{$field_key};
                     }
                     // remember the context level that the field corresponds to
                     $fielddata->contextlevel = $reqfield->contextlevel;
                     $DB->insert_record('block_courserequest_data', $fielddata);
                 }
             }
             require_once $CFG->dirroot . '/local/elisprogram/lib/notifications.php';
             $syscontext = context_system::instance();
             $config = get_config('block_courserequest');
             if (has_capability('block/courserequest:approve', $syscontext)) {
                 // Since we want to automatically approve requests for people approval permission, let's go ahead and create the course/class
                 $requestid = $id;
                 if (!($request = $DB->get_record('block_courserequest', array('id' => $requestid)))) {
                     $target = str_replace($CFG->wwwroot, '', $this->url);
                     print_error('errorinvalidrequestid', 'block_courserequest', $target, $requestid);
                 }
                 $target = $this->get_new_page(array('action' => 'approveconfirm'));
                 $approveform = new pending_request_approve_form($target->url, $request);
                 $request->request = $request->id;
                 $approveform->set_data($request);
                 // We're not actually approving the request, redirect back to the approval table.
                 if ($approveform->is_cancelled()) {
                     redirect($this->url, '', 0);
                 }
                 // Do we have to create a brand new course?
                 if (empty($request->courseid)) {
                     $crsdata = array('name' => $request->title, 'idnumber' => $data->crsidnumber, 'syllabus' => '');
                     $newcourse = new course($crsdata);
                     if (!empty($config->use_course_fields)) {
                         // course fields are enabled, so add the relevant data
                         $this->add_custom_fields($request->id, 'course', $newcourse);
                     }
                     $newcourse->save();
                     // ->add()
                     // do the course role assignment, if applicable
                     if (!empty($config->course_role)) {
                         if ($context = \local_elisprogram\context\course::instance($newcourse->id)) {
                             // TBD: role_assign() now throws exceptions!
                             $result = role_assign($config->course_role, $request->userid, $context->id, ECR_CD_ROLE_COMPONENT);
                         }
                     }
                     $courseid = $newcourse->id;
                 } else {
                     $courseid = $request->courseid;
                     // TBV: addslashes()
                 }
                 // Create the new class if we are using an existing course, or if
                 // create_class_with_course is on.
                 if (!empty($request->courseid) || !empty($config->create_class_with_course)) {
                     require_once $CFG->dirroot . '/local/elisprogram/lib/data/pmclass.class.php';
                     $clsdata = array('name' => $request->title, 'courseid' => $courseid, 'idnumber' => $data->clsidnumber, 'starttimehour' => 25, 'starttimeminute' => 61, 'endtimehour' => 25, 'endtimeminute' => 61);
                     $newclass = new pmclass($clsdata);
                     $newclass->autocreate = false;
                     if (!empty($config->use_class_fields)) {
                         // class fields are enabled, so add the relevant data
                         $this->add_custom_fields($request->id, 'class', $newclass);
                     }
                     $newclass->save();
                     // ->add()
                 }
                 // Update the request record to mark it as being approved.
                 $request->requeststatus = 'approved';
                 $request->statusnote = '';
                 $DB->update_record('block_courserequest', $request);
                 // TBV: addslashes_object()
                 // assign role to requester in the newly created class
                 if (!empty($newclass->id)) {
                     if (!empty($config->class_role)) {
                         $context = \local_elisprogram\context\pmclass::instance($newclass->id);
                         // TBD: role_assign() now throws exceptions!
                         role_assign($config->class_role, $request->userid, $context->id, ECR_CI_ROLE_COMPONENT);
                     }
                 }
                 // create a new Moodle course from the course template if applicable
                 if (!empty($data->usecoursetemplate) && !empty($newclass->id)) {
                     moodle_attach_class($newclass->id, 0, '', true, true, true);
                     // copy role over into Moodle course
                     if (!empty($config->class_role)) {
                         require_once $CFG->dirroot . '/local/elisprogram/lib/data/classmoodlecourse.class.php';
                         if ($class_moodle_record = $DB->get_record(classmoodlecourse::TABLE, array('classid' => $newclass->id))) {
                             $context = context_course::instance($class_moodle_record->moodlecourseid);
                             // TBD: role_assign() now throws exceptions!
                             role_assign($config->class_role, $request->userid, $context->id, ECR_MC_ROLE_COMPONENT);
                         }
                     }
                 }
                 // Send a notification to the requesting user that their course / class is ready.
                 // set additional course / class information for use in the message
                 if (isset($newclass->idnumber) && isset($newclass->id)) {
                     $request->classidnumber = $newclass->idnumber;
                     $request->classid = $newclass->id;
                 }
                 $request->newcourseid = $courseid;
                 // calculate the actual message
                 $notice = block_courserequest_get_approval_message($request);
                 // send it to the requester
                 notification::notify($notice, $DB->get_record('user', array('id' => $request->userid)));
                 print_string('request_submitted_and_auto_approved', 'block_courserequest');
             } else {
                 // find users with approve capabilities in the system context
                 $admin = get_users_by_capability($syscontext, 'block/courserequest:approve');
                 foreach ($admin as $userto) {
                     notification::notify(get_string('new_request_notification', 'block_courserequest', $data), $userto);
                 }
                 print_string('request_submitted', 'block_courserequest');
             }
             redirect($this->url);
             return;
         }
     }
     $form->display();
 }