/** * Clone a course. * @param array $options options for cloning. Valid options are: * - 'classes': whether or not to clone classes (default: false) * - 'moodlecourses': whether or not to clone Moodle courses (if they were * autocreated). Values can be (default: "copyalways"): * - "copyalways": always copy course * - "copyautocreated": only copy autocreated courses * - "autocreatenew": autocreate new courses from course template * - "link": link to existing course * - 'targetcluster': the cluster id or cluster object (if any) to * associate the clones with (default: none) * @return array array of array of object IDs created. Key in outer array * is type of object (plural). Key in inner array is original object ID, * value is new object ID. Outer array also has an entry called 'errors', * which is an array of any errors encountered when duplicating the * object. */ function duplicate($options) { global $CURMAN; require_once CURMAN_DIRLOCATION . '/lib/cmclass.class.php'; require_once CURMAN_DIRLOCATION . '/lib/coursetemplate.class.php'; $objs = array('errors' => array()); if (isset($options['targetcluster'])) { $cluster = $options['targetcluster']; if (!is_object($cluster) || !is_a($cluster, 'cluster')) { $options['targetcluster'] = $cluster = new cluster($cluster); } } // clone main course object $clone = new course($this); unset($clone->id); if (isset($cluster)) { // if cluster specified, append cluster's name to course $clone->name = $clone->name . ' - ' . $cluster->name; $clone->idnumber = $clone->idnumber . ' - ' . $cluster->name; } $clone = new course(addslashes_recursive($clone)); if (!$clone->add()) { $objs['errors'][] = get_string('failclustcpycurrcrs', 'block_curr_admin', $this); return $objs; } $objs['courses'] = array($this->id => $clone->id); $options['targetcourse'] = $clone->id; // copy completion elements $compelems = $this->get_completion_elements(); if (!empty($compelems)) { foreach ($compelems as $compelem) { $compelem = addslashes_recursive($compelem); unset($compelem->id); $clone->save_completion_element($compelem); } } // copy template $template = $CURMAN->db->get_record(CTTABLE, 'courseid', $this->id); $template = new coursetemplate($template); unset($template->id); $template->courseid = $clone->id; $template->add(); // FIXME: copy tags // copy the classes if (!empty($options['classes'])) { $classes = cmclass_get_record_by_courseid($this->id); if (!empty($classes)) { $objs['classes'] = array(); foreach ($classes as $class) { $class = new cmclass($class); $rv = $class->duplicate($options); if (isset($rv['errors']) && !empty($rv['errors'])) { $objs['errors'] = array_merge($objs['errors'], $rv['errors']); } if (isset($rv['classes'])) { $objs['classes'] = $objs['classes'] + $rv['classes']; } } } } return $objs; }
/** * override print_num_items to display the max number of students allowed in this class * * @param int $numitems max number of students */ function print_num_items($classid, $max) { $students = cmclass::get_completion_counts($classid); if (!empty($students[STUSTATUS_FAILED])) { echo '<div style="float:right;">' . get_string('num_students_failed', 'block_curr_admin') . ': ' . $students[STUSTATUS_FAILED] . '</div><br />'; } if (!empty($students[STUSTATUS_PASSED])) { echo '<div style="float:right;">' . get_string('num_students_passed', 'block_curr_admin') . ': ' . $students[STUSTATUS_PASSED] . '</div><br />'; } if (!empty($students[STUSTATUS_NOTCOMPLETE])) { echo '<div style="float:right;">' . get_string('num_students_not_complete', 'block_curr_admin') . ': ' . $students[STUSTATUS_NOTCOMPLETE] . '</div><br />'; } if (!empty($max)) { echo '<div style="float:right;">' . get_string('num_max_students', 'block_curr_admin') . ': ' . $max . '</div><br />'; } }
public function delete() { $result = course::remove_environment($this->id); $result = $result && cmclass::remove_environment($this->id); return $result && parent::delete(); }
/** * Determines whether the current user is allowed to create, edit, and delete associations * between a user and a class * * @param int $userid The id of the user being associated to the class * @param int $classid The id of the class we are associating the user to * * @return boolean True if the current user has the required permissions, otherwise false */ public static function can_manage_assoc($userid, $classid) { global $USER; if (!cmclasspage::can_enrol_into_class($classid)) { //the users who satisfty this condition are a superset of those who can manage associations return false; } else { if (cmclasspage::_has_capability('block/curr_admin:track:enrol', $classid)) { //current user has the direct capability return true; } } //get the context for the "indirect" capability $context = cm_context_set::for_user_with_capability('cluster', 'block/curr_admin:class:enrol_cluster_user', $USER->id); $allowed_clusters = array(); $allowed_clusters = cmclass::get_allowed_clusters($classid); //query to get users associated to at least one enabling cluster $cluster_select = ''; if (empty($allowed_clusters)) { $cluster_select = '0=1'; } else { $cluster_select = 'clusterid IN (' . implode(',', $allowed_clusters) . ')'; } $select = "userid = {$userid} AND {$cluster_select}"; //user just needs to be in one of the possible clusters if (record_exists_select(CLSTUSERTABLE, $select)) { return true; } return false; }
/** * * @global object $CFG * @global object $CURMAN */ public function enrol() { global $CFG, $CURMAN; $this->data_delete_record(); $class = new cmclass($this->classid); $courseid = $class->get_moodle_course_id(); // enrol directly in the course $student = new student($this); $student->enrolmenttime = max(time(), $class->startdate); $student->add(); if ($courseid) { $course = $CURMAN->db->get_record('course', 'id', $this->id); // the elis plugin is treated specially if ($course->enrol != 'elis') { // send the user to the Moodle enrolment page $a = new stdClass(); $a->crs = $course; $a->class = $class; $a->wwwroot = $CFG->wwwroot; $subject = get_string('moodleenrol_subj', 'block_curr_admin', $a); $message = get_string('moodleenrol', 'block_curr_admin', $a); } } if (!isset($message)) { $a = $class->idnumber; $subject = get_string('nowenroled', 'block_curr_admin', $a); $message = get_string('nowenroled', 'block_curr_admin', $a); } $user = cm_get_moodleuser($this->userid); $from = get_admin(); notification::notify($message, $user, $from); email_to_user($user, $from, $subject, $message); }
/** * Clone a track * @param array $options options for cloning. Valid options are: * - 'targetcurriculum': the curriculum id to associate the clones with * (default: same as original track) * - 'classmap': a mapping of class IDs to use from the original track to * the cloned track. If a class from the original track is not mapped, a * new class will be created * - 'moodlecourse': whether or not to clone Moodle courses (if they were * autocreated). Values can be (default: "copyalways"): * - "copyalways": always copy course * - "copyautocreated": only copy autocreated courses * - "autocreatenew": autocreate new courses from course template * - "link": link to existing course * @return array array of array of object IDs created. Key in outer array * is type of object (plural). Key in inner array is original object ID, * value is new object ID. Outer array also has an entry called 'errors', * which is an array of any errors encountered when duplicating the * object. */ function duplicate($options = array()) { global $CURMAN; $objs = array('errors' => array()); if (isset($options['targetcluster'])) { $cluster = $options['targetcluster']; if (!is_object($cluster) || !is_a($cluster, 'cluster')) { $options['targetcluster'] = $cluster = new cluster($cluster); } } // clone main track object $clone = new track($this); unset($clone->id); if (isset($options['targetcurriculum'])) { $clone->curid = $options['targetcurriculum']; } if (isset($cluster)) { // if cluster specified, append cluster's name to track $clone->idnumber = $clone->idnumber . ' - ' . $cluster->name; $clone->name = $clone->name . ' - ' . $cluster->name; } $clone = new track(addslashes_recursive($clone)); $clone->autocreate = false; // avoid warnings if (!$clone->add()) { $objs['errors'][] = get_string('failclustcpytrk', 'block_curr_admin', $this); return $objs; } $objs['tracks'] = array($this->id => $clone->id); // associate with target cluster (if any) if (isset($cluster)) { clustertrack::associate($cluster->id, $clone->id); } // copy classes $clstrks = track_assignment_get_listing($this->id); if (!empty($clstrks)) { $objs['classes'] = array(); if (!isset($options['classmap'])) { $options['classmap'] = array(); } foreach ($clstrks as $clstrkdata) { $newclstrk = new trackassignmentclass($clstrkdata); $newclstrk->trackid = $clone->id; unset($newclstrk->id); if (isset($options['classmap'][$clstrkdata->clsid])) { // use existing duplicate class $class = new cmclass($options['classmap'][$clstrkdata->clsid]); } else { // no existing duplicate -> duplicate class $class = new cmclass($clstrkdata->clsid); $rv = $class->duplicate($options); if (isset($rv['errors']) && !empty($rv['errors'])) { $objs['errors'] = array_merge($objs['errors'], $rv['errors']); } if (isset($rv['classes'])) { $objs['classes'] = $objs['classes'] + $rv['classes']; } } $newclstrk->classid = $class->id; $newclstrk->courseid = $class->courseid; $newclstrk->add(); } } return $objs; }
function get_item_display_options($column, $class) { $classobj = new cmclass($class); if (!$classobj->is_enrollable()) { return get_string('notenrollable'); } if (student::count_enroled($class->id) < $class->maxstudents || empty($class->maxstudents)) { $action = 'savenew'; } else { $action = 'confirmwaitlist'; } return '<a href="index.php?s=crscat&section=curr&clsid=' . $class->id . '&action=' . $action . '">' . get_string('choose_label', 'block_curr_admin') . '</a>'; }
function get_body() { global $CFG, $CURMAN; $action = cm_get_param('action', ''); $confirm = cm_get_param('confirm', ''); //md5 confirmation hash $confirmuser = cm_get_param('confirmuser', 0); $trackid = cm_get_param('trackid', 0); $id = cm_get_param('id', 0); $sort = cm_get_param('sort', 'idnumber'); $dir = cm_get_param('dir', 'ASC'); $page = cm_get_param('page', 0); $perpage = cm_get_param('perpage', 30); // how many per page $namesearch = trim(cm_get_param('search', '')); $alpha = cm_get_param('alpha', ''); if (!($track = new track($trackid))) { return ' (' . $trackid . ')'; } switch ($action) { case 'add': return $this->get_add_form($trackid); break; case 'confirm': $tk = new trackassignmentclass($id); if (md5($tk->id) != $confirm) { echo cm_error('Invalid confirmation code!'); } else { if (!$tk->delete()) { echo cm_error('Course "name: ' . $tk->track->name . '" not deleted.'); } } break; case 'delete': return $this->get_delete_form($id); break; case 'edit': return $this->get_edit_form($id); break; case 'update': $id = cm_get_param('id', 0); $autoenrol = cm_get_param('autoenrol', 0); $trkassign = new trackassignmentclass($id); $trkassign->autoenrol = $autoenrol; $trkassign->data_update_record(); break; case 'savenew': $classes = cm_get_param('classes', ''); $classes = is_array($classes) ? $classes : array(); $trackid = cm_get_param('trackid', 0, PARAM_INT); if (!empty($classes) and !empty($trackid)) { $param = array('trackid' => $trackid); $trackobj = new track($trackid); foreach ($classes as $classid) { $classobj = new cmclass($classid); $param['classid'] = $classid; $param['courseid'] = $classobj->courseid; $param['autoenrol'] = 0; $param['required'] = 0; // Pull up the curricula assignment record(s) $curcourse = curriculumcourse_get_list_by_curr($trackobj->curid); // Traverse though curricula's courses until the the course the - // selected classs is assigned to comes up foreach ($curcourse as $recid => $curcourec) { // Only interested in the course that the class is assigned to if ($curcourec->courseid == $classobj->courseid) { if ($curcourec->required) { $param['required'] = 1; // Only one class assigned to course to enable auto enrol if (1 == cmclass::count_course_assignments($curcourec->courseid)) { $param['autoenrol'] = 1; } } } } // Assign class to track now $trkassignobj = new trackassignmentclass($param); $trkassignobj->assign_class_to_track(); } } break; } $columns = array('clsname' => get_string('class_id_number', 'block_curr_admin'), 'autoenrol' => get_string('auto_enrol', 'block_curr_admin')); foreach ($columns as $column => $cdesc) { if ($sort != $column) { $columnicon = ""; $columndir = "ASC"; } else { $columndir = $dir == "ASC" ? "DESC" : "ASC"; $columnicon = $dir == "ASC" ? "down" : "up"; $columnicon = " <img src=\"{$CFG->pixpath}/t/{$columnicon}.gif\" alt=\"\" />"; } ${$column} = "<a href=\"index.php?s=trkcls&section=curr&sort={$column}&" . "dir={$columndir}&search=" . urlencode(stripslashes($namesearch)) . "&alpha={$alpha}&trackid={$trackid}\">" . $cdesc . "</a>{$columnicon}"; $table->head[] = ${$column}; $table->align[] = 'left'; $table->wrap[] = false; } $table->head[] = ''; $table->align[] = 'center'; $table->wrap[] = true; $trks = track_assignment_get_listing($trackid, $sort, $dir, $page * $perpage, $perpage, $namesearch, $alpha); $numtrk = track_assignment_count_records($trackid, $namesearch, $alpha); $alphabet = explode(',', get_string('alphabet')); $strall = get_string('all'); /// Nav bar information: $bc = '<div style="float:right;">' . $numtrk . ' track(s) found.</div>' . '<span class="breadcrumb">' . get_string('trackasso_manage_crumb', 'block_curr_admin', $track->name) . '</span>'; echo cm_print_heading_block($bc, '', true); echo '<br />' . "\n"; /// Bar of first initials echo "<p style=\"text-align:center\">"; echo 'Name' . " : "; if ($alpha) { echo " <a href=\"index.php?s=trkcls&section=curr&sort=name&dir=ASC&" . "perpage={$perpage}&trackid={$trackid}\">{$strall}</a> "; } else { echo " <b>{$strall}</b> "; } foreach ($alphabet as $letter) { if ($letter == $alpha) { echo " <b>{$letter}</b> "; } else { echo " <a href=\"index.php?s=trkcls&section=curr&sort=idnumber&dir=ASC&" . "perpage={$perpage}&trackid={$trackid}&alpha={$letter}\">{$letter}</a> "; } } echo "</p>"; print_paging_bar($numtrk, $page, $perpage, "index.php?s=trkm&section=curr&sort={$sort}&dir={$dir}&perpage={$perpage}&" . "alpha={$alpha}&trackid={$trackid}&search=" . urlencode(stripslashes($namesearch)) . "&"); if (!$trks) { $match = array(); if ($namesearch !== '') { $match[] = s($namesearch); } if ($alpha) { $match[] = 'idnumber' . ": {$alpha}" . "___"; } $matchstring = implode(", ", $match); echo get_string('no_matching_track_assign', 'block_curr_admin') . $matchstring; $table = NULL; } else { $table->width = "95%"; foreach ($trks as $trk) { $deletebutton = '<a href="index.php?s=trkcls&section=curr&action=delete&' . 'id=' . $trk->id . '">' . '<img src="pix/delete.gif" alt="Delete" title="Delete" /></a>'; $editbutton = '<a href="index.php?s=trkcls&section=curr&action=edit&id=' . $trk->id . '">' . '<img src="pix/edit.gif" alt="Edit" title="Edit" /></a>'; /*$tagbutton = '<a href="index.php?s=tagins&section=curr&t=cur&i='.$trk->id.'">'. '<img src="pix/tag.gif" alt="Tags" title="Tags" /></a>'; $clusterbutton = '<a href="index.php?s=clutrk&section=curr&mode=trk&' . 'track=' . $trk->id . '"><img src="pix/cluster.gif" alt="Clusters" '. 'title="Clusters" /></a>';*/ $newarr = array(); foreach ($columns as $column => $cdesc) { if ($column == 'clsname') { $newarr[] = '<a href="index.php?s=cls§ion=curr&action=edit&id=' . $trk->classid . '">' . $trk->{$column} . '</a>'; } else { $newarr[] = $trk->{$column}; } } $newarr[] = $editbutton . ' ' . $deletebutton; $table->data[] = $newarr; } } echo "<table class=\"searchbox\" style=\"margin-left:auto;margin-right:auto\" cellpadding=\"10\"><tr><td>"; echo "<form action=\"index.php\" method=\"get\"><fieldset class=\"invisiblefieldset\">"; echo '<input type="hidden" name="s" value="trkcls" />'; echo '<input type="hidden" name="section" value="curr" />'; echo '<input type="hidden" name="sort" value="' . $sort . '" />'; echo '<input type="hidden" name="dir" value="' . $dir . '" />'; echo '<input type="hidden" name="perpage" value="' . $perpage . '" />'; echo '<input type="hidden" name="trackid" value="' . $trackid . '" />'; echo "<input type=\"text\" name=\"search\" value=\"" . s($namesearch, true) . "\" size=\"40\" />"; echo "<input type=\"submit\" value=\"" . get_string('search', 'block_curr_admin') . "\" />"; if ($namesearch) { echo "<input type=\"button\" onclick=\"document.location='index.php?s=trkcls&" . "section=curr&sort={$sort}&dir={$dir}&perpage={$perpage}&alpha={$alpha}&trackid={$trackid}';\" " . "value=\"" . get_string('show_all_curricula', 'block_curr_admin') . "\" />"; } echo "</fieldset></form>"; echo "</td></tr></table>"; if (!empty($table)) { print_heading('<a href="index.php?s=trkcls&section=curr&action=add&trackid=' . $trackid . '">' . get_string('trackasso_add_asso', 'block_curr_admin', $track->name) . '</a>'); print_table($table); print_paging_bar($numtrk, $page, $perpage, "index.php?s=trkcls&section=curr&sort={$sort}&dir={$dir}&perpage={$perpage}" . "&alpha={$alpha}&trackid={$trackid}&search=" . urlencode(stripslashes($namesearch)) . "&"); } print_heading('<a href="index.php?s=trkcls&section=curr&action=add&trackid=' . $trackid . '">' . get_string('trackasso_add_asso', 'block_curr_admin', $track->name) . '</a>'); }
/** * Check for nags... * */ function cm_check_for_nags() { $status = true; mtrace("Checking notifications<br />\n"); $status = cmclass::check_for_nags() && $status; $status = cmclass::check_for_moodle_courses() && $status; $status = course::check_for_nags() && $status; $status = curriculum::check_for_nags() && $status; return $status; }
/** * Actually process the uploaded CSV organization file upon successful upload. * * NOTE: A lot o code here is borrowed / modified from Moodle. * * @see Moodle:/admin/uploaduser.php * * @uses $CURMAN * @param array $fieldata A PHP upload file array (i.e. from the $_FILES superglobal). * @param bool $update Flag for updating existing records. * @param bool $verbose Flag for verbose output. * @return string Output for display. */ function process_input_data($filedata, $update = false, $verbose = false) { global $CURMAN; $output = ''; /// Don't check for a valid mime/type as this is causing errors for the client. /* if (!in_array($filedata['type'], $this->valid_mimetypes)) { return 'The file format uploaded was incorrect'; } */ if ($filedata['size'] === 0) { return get_string('uploaded_empty_file', 'block_curr_admin'); } /** * Large files are likely to take their time and memory. Let PHP know * that we'll take longer, and that the process should be recycled soon * to free up memory. */ @set_time_limit(0); @cm_raise_memory_limit('192M'); if (function_exists('apache_child_terminate')) { @apache_child_terminate(); } $csv_encode = '/\\&\\#44/'; $csv_delimiter = "\\,"; $csv_delimiter2 = ","; $data = ''; $file = @fopen($filedata['tmp_name'], 'rb'); if ($file) { while (!feof($file)) { $data .= fread($file, 1024); } fclose($file); } if (empty($data)) { return get_string('no_data_file', 'block_curr_admin'); } /** * Removes the BOM from unicode string - see http://unicode.org/faq/utf_bom.html * * Borrowed from Moodle code - /lib/textlib.class.php */ $bom = ""; if (strpos($data, $bom) === 0) { $data = substr($data, strlen($bom)); } /** * Fix Mac/DOS newlines * * Borrowed from Moodle code - /admin/uploaduser.php */ $data = preg_replace('!\\r\\n?!', "\n", $data); $fp = fopen($filedata['tmp_name'], 'w'); fwrite($fp, $data); fclose($fp); $fp = fopen($filedata['tmp_name'], 'r'); /** * The required and optional fields we're looking for in the CSV file. */ $required = array('studentid' => 1, 'class' => 1, 'trainernum' => 1, 'startdate' => 1, 'enddate' => 1); $optional = array('firstname' => 1, 'lastname' => 1, 'curriculum' => 1, 'status' => 1, 'completed' => 1, 'grade' => 1, 'frequency' => 1, 'timeperiod' => 1); $colpos = array(); $header = split($csv_delimiter, fgets($fp, 1024)); // Check for valid field names foreach ($header as $i => $h) { $h = trim($h); $header[$i] = $h; // remove whitespace $h = ereg_replace('^\\"|\\"$', '', $h); // strip encapsulating quotes $header[$i] = $h; if (isset($required[$h])) { $required[$h] = 0; $colpos[$i] = $h; } else { if (isset($optional[$h])) { $colpos[$i] = $h; } } } /// Check for required fields foreach ($required as $key => $value) { if ($value) { //required field missing return get_string('missing_required_field', 'block_curr_admin', $key); } } $linenum = 2; // since header is line 1 $stusnew = 0; $stuserror = 0; $stusupdated = 0; $timenow = time(); while (!feof($fp)) { //Note: commas within a field should be encoded as , (for comma separated csv files) //Note: semicolon within a field should be encoded as ; (for semicolon separated csv files) $line = split($csv_delimiter, fgets($fp, 1024)); foreach ($line as $key => $value) { if (isset($colpos[$key])) { /// decode encoded commas and strip enapsulating quotes $record[$colpos[$key]] = preg_replace($csv_encode, $csv_delimiter2, trim($value)); $record[$colpos[$key]] = ereg_replace('^\\"|\\"$', '', $record[$colpos[$key]]); } } /// Got organization data if ($record[$header[0]]) { $done = false; $users = $CURMAN->db->get_records(USRTABLE, 'idnumber', $record['studentid']); $user = NULL; /// Don't worry about the actual type. Just worry about the idnumber. if (!empty($users)) { $user = current($users); } /// Only proceed if this student and instructor users actually exists. if (!empty($user->id)) { $crsidnumber = $record['class']; $dateparts = explode('/', $record['startdate']); $startdate = mktime(0, 0, 0, $dateparts[1], $dateparts[0], $dateparts[2]); $dateparts = explode('/', $record['enddate']); $enddate = mktime(0, 0, 0, $dateparts[1], $dateparts[0], $dateparts[2]); /// Check if the class as specified exists... $clsidnumber = $record['class']; if (!($class = $CURMAN->db->get_record(CLSTABLE, 'idnumber', $clsidnumber))) { $clsidnumber = $record['class'] . '-' . $record['trainernum']; /// Need to check for old classes that didn't have dates, and remove them. if ($class = $CURMAN->db->get_record(CLSTABLE, 'idnumber', $clsidnumber)) { $class = new cmclass($class); $class->delete(); } /// If the class doesn't exist, we have to create it first. $datepart = date('Ymd', $startdate); $clsidnumber = $record['class'] . '-' . $record['trainernum'] . '-' . $datepart; $class = $CURMAN->db->get_record(CLSTABLE, 'idnumber', $clsidnumber); } if (empty($class->id) || $update && !empty($class->id)) { if ($course = $CURMAN->db->get_record(CRSTABLE, 'idnumber', $crsidnumber)) { /// Do we need to add / update curriculum info for this course??? if (isset($record['curriculum'])) { if ($cur = $CURMAN->db->get_record(CURTABLE, 'idnumber', $record['curriculum'])) { $curcrs = $CURMAN->db->get_record(CURCRSTABLE, 'curriculumid', $cur->id, 'courseid', $course->id); if (!$update && empty($curcrs->id) || $update && !empty($curcrs->id)) { $cmcrec = array('curriculumid' => $cur->id, 'courseid' => $course->id); if (!empty($record['frequency'])) { $cmcrec['frequency'] = $record['frequency']; } if (!empty($record['timeperiod'])) { $cmcrec['timeperiod'] = $record['timeperiod']; } if (empty($curcrs->id)) { $curcrs = new curriculum($cmcrec); } else { $curcrs = new curriculum($curcrs->id); foreach ($cmcrec as $key => $val) { $curcrs->{$key} = $val; } } $a = new object(); $a->courseid = $course->idnumber; $a->coursename = $course->name; $a->curid = $cur->idnumber; if ($update && !empty($curcrs->id)) { if ($curcrs->data_update_record() && $verbose) { $output .= get_string('updated_curriculum_course_info', 'block_curr_admin'); } } else { if ($curcrs->data_insert_record() && $verbose) { $output .= get_string('added_curriculum_course_info', 'block_curr_admin'); } } } } } $clsrec = array('courseid' => $course->id, 'idnumber' => $clsidnumber, 'startdate' => $startdate, 'enddate' => $enddate); if (empty($class->id)) { $class = new cmclass($clsrec); } else { $class = new cmclass($class->id); foreach ($clsrec as $key => $val) { $class->{$key} = $val; } } if ($update && !empty($class->id)) { if ($class->data_update_record() && $verbose) { $output .= get_string('updated_class_info', 'block_curr_admin') . $class->idnumber . '<br /><br />' . "\n"; } } else { if ($class->data_insert_record() && $verbose) { $output .= get_string('added_class_info', 'block_curr_admin') . $class->idnumber . '<br /><br />' . "\n"; } } if (empty($class->id) && $verbose) { $output .= get_string('error_class_not_created', 'block_curr_admin') . $class->idnumber . '<br /><br />' . "\n"; } } else { if ($verbose) { $output .= get_string('error_course_not_found', 'block_curr_admin') . $crsidnumber . '<br /><br />' . "\n"; } } } /// Only proceed if we have an actual class here... if (!empty($class->id)) { $instructors = $CURMAN->db->get_records(USRTABLE, 'idnumber', $record['trainernum']); $instructor = NULL; /// Don't worry about the actual type. Just worry about the idnumber. if (!empty($instructors)) { $instructor = current($instructors); } if (!empty($instructor->id) && !$CURMAN->db->record_exists(INSTABLE, 'classid', $class->id, 'userid', $instructor->id)) { $insrec = array('classid' => $class->id, 'userid' => $instructor->id); $newins = new instructor($insrec); if ($newins->data_insert_record() && $verbose) { $output .= get_string('added_instructor_class', 'block_curr_admin', cm_fullname($instructor)) . $class->idnumber . '<br /><br />' . "\n"; } } $student = $CURMAN->db->get_record(STUTABLE, 'classid', $class->id, 'userid', $user->id); $a = new object(); $a->name = cm_fullname($user); $a->id = $class->idnumber; if (!$update && empty($student->id) || $update && !empty($student->id)) { $sturec = array('classid' => $class->id, 'userid' => $user->id); if (isset($record['status'])) { $sturec['completestatusid'] = intval($record['status']); } if (!isset($record['completed'])) { $sturec['completetime'] = $enddate; } else { $d = explode('/', $record['completed']); if (count($d) == 3) { $day = $d[0]; $month = $d[1]; $year = $d[2]; $timestamp = mktime(0, 0, 0, $month, $day, $year); $sturec['completetime'] = $timestamp; } } if (isset($record['grade'])) { $sturec['grade'] = intval($record['grade']); } if (empty($student->id)) { $student = new student($sturec); } else { $student = new student($student->id); foreach ($sturec as $key => $val) { $student->{$key} = $val; } } if ($update && !empty($student->id)) { if ($student->data_update_record() && $verbose) { $output .= get_string('update_enrolment_info', 'block_curr_admin', $a) . '<br /><br />' . "\n"; } } else { if ($student->data_insert_record() && $verbose) { $output .= get_string('add_enrolment_info', 'block_curr_admin', $a) . '<br /><br />' . "\n"; } } } else { $student = NULL; if ($verbose) { $output .= get_string('existing_enrolment_info', 'block_curr_admin') . '<br /><br />' . "\n"; } } if (!empty($student->id)) { $done = true; } } } else { $output .= get_string('error_studentid_not_found', 'block_curr_admin') . $record['studentid'] . '<br /><br />' . "\n"; } if ($update && $done) { $stusupdated++; } else { if (!$update && $done) { $stusnew++; } else { $stuserror++; } } } } if (!empty($output)) { $output .= '<br /><br />'; } if (!$stusnew && !$stusupdated && !$stuserror) { $output .= get_string('nothing_done', 'block_curr_admin'); } if ($stusnew > 0) { $output .= get_string('added_new_students', 'block_curr_admin', $stusnew); } if ($stusupdated > 0) { $output .= get_string('updated_existing_students', 'block_curr_admin', $stusupdated); } if ($stuserror > 0) { $output .= get_string('error_not_processed', 'block_curr_admin', $stuserror); } return $output; }
/** * Converts add button data to data for our add form * * @return stdClass Form data, or null if none */ function get_default_object_for_add() { // get site-wide default values global $CURMAN; $obj = (object) cmclass::get_default(); $parent = $this->optional_param('parent', 0, PARAM_INT); if ($parent) { $obj->courseid = $parent; } return $obj; }