public function definition() { global $CFG, $DB, $PAGE, $USER; $mform = & $this->_form; $hierarchy = new hierarchy(); $id = $this->_customdata['id']; $classid = $this->_customdata['classid']; $classtype = $this->_customdata['classtype']; $courseid = $this->_customdata['courseid']; $classtypeid = $this->_customdata['classtypeid']; $scheduledinfo = $DB->get_record('local_scheduleclass', array('id' => $id)); if (isset($classid)) $classinfo = $DB->get_record('local_clclasses', array('id' => $classid, 'visible' => 1)); $deptid = (isset($classinfo->departmentid) ? $classinfo->departmentid : 0); $schoolid = (isset($classinfo->schoolid) ? $classinfo->schoolid : 0); $semid = (isset($classinfo->semesterid) ? $classinfo->semesterid : 0); $id = $this->_customdata['id']; $classtypes = $DB->get_records_menu('local_class_scheduletype', array('schoolid' => $schoolid), '', 'id, classtype'); $string_cltype = array('Select classtype', '-1' => 'All'); $final_classtype = $string_cltype + $classtypes; $scheduleclass = cobalt_scheduleclass::get_instance(); $hour = $scheduleclass->hour(); $min = $scheduleclass->min(); $starttime = array(); $endtime = array(); /* Start of scheduleclass startdate */ //providing semester startdate and enddate helpful to select date if ($semid) { $seminfo = $DB->get_record('local_semester', array('id' => $semid)); $seminfo->startdate = date('d M Y', $seminfo->startdate); $seminfo->enddate = date('d M Y', $seminfo->enddate); $mform->addElement('static', 'datedescription', '', get_string('classschedule_datedescription', 'local_clclasses', $seminfo)); } // $mform->addElement('', PARAM_INT); // $mform->setDefault('classtype',$classtype); if ($classtypeid && $classinfo) $this->reapeat_schedulecontent_basedon_type($classtypeid, $classinfo); $time = time(); $user = $USER->id; $mform->addElement('hidden', 'timecreated', $time); $mform->setType('timecreated', PARAM_INT); $mform->addElement('hidden', 'timemodified', $time); $mform->setType('timemodified', PARAM_INT); $mform->addElement('hidden', 'usermodified', $user); $mform->setType('usermodified', PARAM_INT); $mform->addElement('hidden', 'departmentid', $deptid); $mform->setType('departmentid', PARAM_INT); $mform->addElement('hidden', 'schoid', $schoolid); $mform->setType('schoid', PARAM_INT); $mform->addElement('hidden', 'schoolid', $schoolid); $mform->setType('schoolid', PARAM_INT); $mform->addElement('hidden', 'deptid', $deptid); $mform->setType('deptid', PARAM_INT); $mform->addElement('hidden', 'courseid', $courseid); $mform->setType('courseid', PARAM_INT); $mform->addElement('hidden', 'classid', $classid); $mform->setType('classid', PARAM_INT); $mform->addElement('hidden', 'semesterid', $semid); $mform->setType('semesterid', PARAM_INT); $mform->addElement('hidden', 'classtypeid', $classtypeid); $mform->setType('classtypeid', PARAM_INT); $mform->addElement('hidden', 'id'); $mform->setType('id', PARAM_INT); /* Start of action buttons */ $actionbutton = ($id > 0) ? get_string('scheduleclassroom', 'local_clclasses') : get_string('scheduleclassroom', 'local_clclasses'); $this->add_action_buttons($cancel = true, $actionbutton); }
function definition_after_data() { global $DB; $mform = $this->_form; $id = $this->_customdata['id']; $formatvalue = $mform->getElementValue('schoolid'); $tools = array(); if ($formatvalue) { $hierarchy = new hierarchy(); $formatvalue = $formatvalue[0]; if ($formatvalue > 0) { $tools = classes_get_school_semesters($formatvalue); /* create a semester dropdown */ $newel = $mform->createElement('select', 'semesterid', get_string('semester', 'local_semesters'), $tools); $mform->insertElementBefore($newel, 'addsemesterlisthere'); $mform->addHelpButton('semesterid', 'semester', 'local_semesters'); $mform->addRule('semesterid', get_string('missingsemester', 'local_semesters'), 'required', null, 'client'); $mform->setType('addsemesterlisthere', PARAM_RAW); /* end of the semester dropdown */ $departments = $hierarchy->get_departments_forschool($formatvalue, $none = ""); /* create a department dropdown */ $dept = $mform->createElement('select', 'departmentid', get_string('department', 'local_clclasses'), $departments); $mform->insertElementBefore($dept, 'adddepartmentlisthere'); $mform->addRule('departmentid', get_string('departmentmissing', 'local_clclasses'), 'required', null, 'client'); $mform->addHelpButton('departmentid', 'department', 'local_clclasses'); /* End of department dropdown */ $departmentvalue = $mform->getElementValue('departmentid'); $departmentvalue = $departmentvalue[0]; if ($departmentvalue > 0) { $cobaltcourses = $hierarchy->get_records_cobaltselect_menu('local_cobaltcourses', "departmentid=$departmentvalue AND visible=1", null, '', 'id,fullname', '--Select--'); $cobaltcourse = $mform->createElement('select', 'cobaltcourseid', get_string('cobaltcourse', 'local_clclasses'), $cobaltcourses); $mform->insertElementBefore($cobaltcourse, 'addcobaltcoursehere'); $mform->setType('addcobaltcoursehere', PARAM_RAW); $mform->addRule('cobaltcourseid', get_string('cobaltcoursemissing', 'local_clclasses'), 'required', null, 'client'); $mform->addHelpButton('cobaltcourseid', 'cobaltcourse', 'local_clclasses'); } } $online = $mform->getElementValue('online'); $online = $online[0]; if ($online == 1 && $id > 0) { $onlinecourses = $hierarchy->get_records_cobaltselect_menu('course', "visible=1 AND category>0", null, '', 'id,fullname', '--Select--'); $cobaltcourse2 = $mform->createElement('select', 'onlinecourseid', get_string('onlinecourse', 'local_clclasses'), $onlinecourses); $mform->addRule('onlinecourseid', get_string('required'), 'required', null, 'client'); $mform->insertElementBefore($cobaltcourse2, 'addonlinecoursehere'); $mform->setType('addonlinecoursehere', PARAM_RAW); $mform->addHelpButton('onlinecourseid', 'onlinecourse', 'local_clclasses'); } else if ($online == 2 && $id > 0) { $default = 0; $cobaltcourse2 = $mform->createElement('hidden', 'onlinecourseid', get_string('onlinecourse', 'local_clclasses'), $default); // $mform->addRule('onlinecourseid', get_string('required'), 'required', null, 'client'); $mform->insertElementBefore($cobaltcourse2, 'addonlinecoursehere'); $mform->setDefault('onlinecourseid', $default); $mform->setType('addonlinecoursehere', PARAM_RAW); } else if ($online == 1 && $id < 0) { $onlinecourses = $hierarchy->get_records_cobaltselect_menu('course', "visible=1 AND category>0", null, '', 'id,fullname', '--Select--'); $cobaltcourse2 = $mform->createElement('select', 'onlinecourseid', get_string('onlinecourse', 'local_clclasses'), $onlinecourses); $mform->addRule('onlinecourseid', get_string('required'), 'required', null, 'client'); $mform->insertElementBefore($cobaltcourse2, 'addonlinecoursehere'); $mform->setType('addonlinecoursehere', PARAM_RAW); $mform->addHelpButton('onlinecourseid', 'onlinecourse', 'local_clclasses'); } /* end of the department dropdown */ /* create a department dropdown for instructor selection */ $depts = $mform->createElement('select', 'departmentinid', get_string('department', 'local_clclasses'), $departments); $mform->insertElementBefore($depts, 'adddepartmentinhere'); $mform->addHelpButton('departmentinid', 'departmentin', 'local_clclasses'); /* End of department dropdown for instructor selection */ $departmentin = $mform->getElementValue('departmentinid'); $departmentin = $departmentin[0]; if ($departmentin > 0) { $cobaltcourses1 = $hierarchy->get_department_instructors($departmentin, $formatvalue); $instructor = $mform->createElement('select', 'instructorid', get_string('instructor', 'local_clclasses'), $cobaltcourses1); $mform->insertElementBefore($instructor, 'addinstructorhere'); $mform->setType('instructorid', PARAM_RAW); $mform->getElement('instructorid')->setMultiple(true); } $check = $mform->getElementValue('choose'); $startdate = $mform->getElementValue('startdate'); $enddate = $mform->getElementValue('enddate'); $starttime = $mform->getElementValue('starttime'); $endtime = $mform->getElementValue('endtime'); $scheduleclass = cobalt_scheduleclass::get_instance(); if ($id < 0 && $startdate > 0 && $formatvalue > 0 && $check > 0) { $classroom = $scheduleclass->classroomlist($startdate, $enddate, $starttime, $endtime, $formatvalue, $id); $two = $mform->createElement('select', 'classroomid', get_string('classroomids', 'local_classroomresources'), $classroom); $mform->insertElementBefore($two, 'beforeclassroom'); $mform->addRule('classroomid', get_string('required'), 'required', null, 'client'); } if ($id > 0 && $check > 0) { $name = $DB->get_record('local_scheduleclass', array('classid' => $id)); $names = $DB->get_record('local_classroom', array('id' => $name->classroomid)); $building = $DB->get_field('local_building', 'fullname', array('id' => $names->buildingid)); $floor = $DB->get_field('local_floor', 'fullname', array('id' => $names->floorid)); $classrooms = $scheduleclass->classroomlist($startdate, $enddate, $starttime, $endtime, $formatvalue, $id); if (!empty($name)) { $classrooms[$name->classroomid] = $building . '/' . $floor . '/' . $names->fullname; } $two = $mform->createElement('select', 'classroomid', get_string('classroomids', 'local_classroomresources'), $classrooms); $mform->insertElementBefore($two, 'beforeclassroom'); $mform->addRule('classroomid', get_string('required'), 'required', null, 'client'); } } }