Example #1
0
 function definition()
 {
     global $USER;
     $form =& $this->_form;
     // Lookup necessary information for generating the listing of invitations
     $user = CoursePrefsUser::findByUnique($USER->username);
     $teamteaches = $user->getDecisionTeamTeaches();
     // Pending team teaching invitations header
     $form->addElement('header', 'accept_teamteach', get_string('header_teamteach_accept', 'block_courseprefs'));
     $form->setHelpButton('accept_teamteach', array('teamteach_accept', get_string('teamteach_accept_help', 'block_courseprefs'), 'block_courseprefs', true));
     // Generate a listing of team teaching invitations the user needs to accept or reject
     $display = array();
     foreach ($teamteaches as $teamteach) {
         $teamteach_user = $teamteach->getSectionsUser();
         $display[$teamteach->getId()] = CoursePrefsSection::generateFullnameById($teamteach->getSectionsId()) . ' with ' . $teamteach_user->getLastname() . ' ' . $teamteach_user->getFirstname();
     }
     // Sort listing of invitations by semesters
     uasort($display, "cmpSemester");
     // Skip the remaining form definition if no invitations were found and display a message to the user
     if (!$display) {
         $form->addElement('static', null, null, get_string('no_accepts', 'block_courseprefs'));
         return;
     }
     // List the invitations for the user to accept or reject
     foreach ($display as $key => $teamteach) {
         $form->addElement('checkbox', PENDING_CHECKBOX . $key, null, $teamteach);
     }
     // Add submit and cancellation buttons
     $row = array();
     $row[] =& $form->createElement('submit', PENDING_ACCEPT_BUTTON, get_string('accept', 'block_courseprefs'));
     $row[] =& $form->createElement('submit', PENDING_REJECT_BUTTON, get_string('reject', 'block_courseprefs'));
     $form->addGroup($row, 'buttonarr', null, '', false);
 }
Example #2
0
 function definition()
 {
     global $CFG, $USER;
     $form =& $this->_form;
     $user = CoursePrefsUser::findByUnique($USER->username);
     // Generate listing of sections the user is the primary teacher
     $dropdown_items = array();
     $sections = $user->getSectionsAsPrimaryTeacher();
     foreach ($sections as $section) {
         // Skip section if the user isn't the primary teacher of it
         if (!$user->isPrimaryTeacher($section)) {
             continue;
         }
         $dropdown_items[$section->getId()] = CoursePrefsSection::generateFullnameById($section->getId());
     }
     // Sort listing of sections by semesters and prepend the default "NONE" option
     uasort($dropdown_items, "cmpSemester");
     $dropdown_items = array("NONE" => "NONE") + $dropdown_items;
     // Adding cross listing fieldset
     $form->addElement('header', 'add_crosslist', get_string('header_crosslist_add', 'block_courseprefs'));
     $form->setHelpButton('add_crosslist', array('crosslist_add', get_string('crosslist_add_help', 'block_courseprefs'), 'block_courseprefs', true));
     // Register regular expression rules for form elements
     $form->registerRule('valid_sectionsid', 'regex', SECTIONSID_PATTERN);
     // Adding dropdown element for user-owner sections
     $form->addElement('select', SECTIONSID_FIELD, get_string('crosslist_primary_section', 'block_courseprefs'), $dropdown_items);
     $form->addRule(SECTIONSID_FIELD, get_string('err_select_section', 'block_courseprefs'), 'valid_sectionsid');
     // Adding dropdown element for cross listed section
     $form->addElement('select', CR_SECTIONSID_FIELD, get_string('crosslist_secondary_section', 'block_courseprefs'), $dropdown_items);
     $form->addRule(CR_SECTIONSID_FIELD, get_string('err_select_section', 'block_courseprefs'), 'valid_sectionsid');
     // Add submit button to form
     $form->addElement('submit', 'submit', get_string('add_entry', 'block_courseprefs'));
 }
Example #3
0
 function definition()
 {
     global $USER;
     $form =& $this->_form;
     $user = CoursePrefsUser::findByUnique($USER->username);
     // Remove team teaching invitations header
     $form->addElement('header', 'remove_teamteach', get_string('header_teamteach_remove', 'block_courseprefs'));
     $form->setHelpButton('remove_teamteach', array('teamteach_remove', get_string('teamteach_remove_help', 'block_courseprefs'), 'block_courseprefs', true));
     // Generate a listing of team teaching invitations
     $teamteaches = $user->getRequestedTeamTeaches();
     $display = array();
     foreach ($teamteaches as $teamteach) {
         $display[$teamteach->getId()] = CoursePrefsSection::generateFullnameById($teamteach->getSectionsId()) . ' with ' . CoursePrefsSection::generateFullnameById($teamteach->getTtSectionsId());
     }
     // Skip the remaining form definition if no invitations were found and display a message to the user
     if (!$display) {
         $form->addElement('static', null, null, get_string('no_deletes', 'block_courseprefs'));
         return;
     }
     // Sort listing of invitations by semesters
     uasort($display, "cmpSemester");
     // Add checkbox elements for each team teach invitation the user can remove
     foreach ($display as $key => $teamteach) {
         $form->addElement('checkbox', DELETE_GROUP . $key, null, $teamteach);
     }
     $form->addElement('submit', 'delete_submit', get_string('remove', 'block_courseprefs'));
 }
Example #4
0
 function definition()
 {
     global $USER;
     $form =& $this->_form;
     $user = CoursePrefsUser::findByUnique($USER->username);
     $teamteaches = $user->getRequestedTeamTeaches();
     // Pending team teaching invitations header
     $form->addElement('header', 'pending_teamteach', get_string('header_teamteach_pending', 'block_courseprefs'));
     $form->setHelpButton('pending_teamteach', array('teamteach_pending', get_string('teamteach_pending_help', 'block_courseprefs'), 'block_courseprefs', true));
     // Generate a listing of team teaching invitation the user has made of other teachers which
     // need to be approved or rejected
     $display = array();
     foreach ($teamteaches as $teamteach) {
         // Skip the team teaching invitation if it doesn't need to be approved
         if (!$teamteach->getApprovalFlag()) {
             continue;
         }
         // Lookup information about the requesting user and user's section
         $teamteach_user = $teamteach->getTtUser();
         $display[$teamteach->getId()] = CoursePrefsSection::generateFullnameById($teamteach->getTtSectionsId()) . ' with ' . $teamteach_user->getLastname() . ' ' . $teamteach_user->getFirstname();
     }
     // Skip the remaining form definition if no invitations were found and display a message to the user
     if (!$display) {
         $form->addElement('static', null, null, get_string('no_requests', 'block_courseprefs'));
         return;
     }
     // Sort listing of invitations by semesters
     uasort($display, "cmpSemester");
     // Add static elements for each team teach invitiation that hasn't been accepted or rejected yet
     foreach ($display as $key => $teamteach) {
         $form->addElement('static', null, null, $teamteach);
     }
 }
Example #5
0
 function definition()
 {
     global $CFG, $USER;
     $form =& $this->_form;
     $user = CoursePrefsUser::findByUnique($USER->username);
     $sections = $user->getSectionsInfoAsPrimaryTeacher();
     $courses = $user->getCoursesAsPrimaryTeacher();
     // Builds a lookup table associating sections with its parent course
     $coursesid_to_sections = array();
     $semester_cache = array();
     foreach ($sections as $sectionsid => $section) {
         $semestersid = $section->semestersid;
         $coursesid = $section->coursesid;
         // Lookup semester object and store in cache if not found
         if (!array_key_exists($semestersid, $semester_cache)) {
             $semester_cache[$semestersid] = CoursePrefsSemester::findById($semestersid);
         }
         $semester = $semester_cache[$semestersid];
         $course = $courses[$coursesid];
         // Associate section with course and build sorting string for cmpSemester
         if (!array_key_exists($coursesid, $coursesid_to_sections)) {
             $coursesid_to_sections[$coursesid] = array();
         }
         $section_fullname = CoursePrefsSection::generateFullname($semester->getYear(), $semester->getName(), $course->getDepartment(), $course->getCourseNumber(), $section->section_number);
         $coursesid_to_sections[$coursesid][$sectionsid] = $section_fullname;
     }
     // Generate course-specific field sets
     foreach ($courses as $coursesid => $course) {
         $courses_sections = $coursesid_to_sections[$coursesid];
         // Build information to be substituted in listing
         $a = new stdClass();
         $a->course_department = $course->getDepartment();
         $a->course_number = $course->getCourseNumber();
         $form->addElement('header', 'course_settings' . $coursesid, get_string('unwanted_label_fieldset', 'block_courseprefs', $a));
         $form->addElement('static', UNWANTED_COURSE_FIELD . $coursesid, '', '<a onclick="toggleUnwanted(\'' . $coursesid . '\', true)" href="javascript:void(0)">' . get_string('all') . '</a>/<a onclick="toggleUnwanted(\'' . $coursesid . '\', false)" href="javascript:void(0)">' . get_string('none') . '</a>');
         uasort($courses_sections, "cmpSemester");
         foreach ($courses_sections as $sectionsid => $fullname) {
             $section = $sections[$sectionsid];
             $semester = $semester_cache[$section->semestersid];
             // Build information to be substituted in listing
             $a = new stdClass();
             $a->semester_year = $semester->getYear();
             $a->semester_name = $semester->getName();
             $a->section_number = $section->section_number;
             $form->addElement('checkbox', UNWANTED_SECTION_FIELD . $sectionsid . '_' . $coursesid, '<span class="choiceindenter">', get_string('unwanted_label_section', 'block_courseprefs', $a));
         }
     }
     // Adding submit and cancel buttons to form
     $buttons = array();
     $buttons[] =& $form->createElement('submit', 'submitbutton', get_string('savechanges'));
     $buttons[] =& $form->createElement('cancel');
     $form->addGroup($buttons, 'buttonar', '', array(' '), false);
     $form->closeHeaderBefore('buttonar');
 }
Example #6
0
 function definition()
 {
     global $CFG, $USER;
     $form =& $this->_form;
     $user = CoursePrefsUser::findByUnique($USER->username);
     // Remove cross listing header
     $form->addElement('header', 'remove_crosslist', get_string('header_crosslist_remove', 'block_courseprefs'));
     $form->setHelpButton('remove_crosslist', array('crosslist_remove', get_string('crosslist_remove_help', 'block_courseprefs'), 'block_courseprefs', true));
     // Generate a listing of existing cross listing entries to delete
     $crosslists = $user->getCrosslists();
     $display = array();
     $display_secondary = array();
     foreach ($crosslists as $crosslist) {
         $sectionsid = $crosslist->getSectionsId();
         $display[$sectionsid] = CoursePrefsSection::generateFullnameById($sectionsid);
         // Create array for secondary sections if it hasn't been created yet
         if (!$display_secondary[$sectionsid]) {
             $display_secondary[$sectionsid] = array();
         }
         // Associate secondary section with primary section
         $display_secondary[$sectionsid][$crosslist->getId()] = CoursePrefsSection::generateFullnameById($crosslist->getCrSectionsId());
     }
     // Skip the remaining form definition if no cross listing entries were found and display a message to the user
     if (!$display) {
         $form->addElement('static', null, null, get_string('no_cl_deletes', 'block_courseprefs'));
         return;
     }
     // Sort listing of cross listing entries by semesters
     uasort($display, "cmpSemester");
     // Iterate over primary sections of cross listed sections to generate form elements
     foreach ($display as $key => $value) {
         // Sort listing of secondary sections this section is cross listed with
         uasort($display_secondary[$key], "cmpSemester");
         // Iterate over secondary sections and generate necessary form elements
         foreach ($display_secondary[$key] as $id => $value_secondary) {
             // Build information to be substituted in listing
             $a = new stdClass();
             $a->primary_section = $value;
             $a->secondary_section = $value_secondary;
             $form->addElement('checkbox', CROSSLIST_DELETE_GROUP . $id, null, get_string('crosslist_with', 'block_courseprefs', $a));
         }
     }
     $form->addElement('submit', 'delete_submit', get_string('remove', 'block_courseprefs'));
 }
Example #7
0
File: lib.php Project: rrusso/EARS
 /**
  * PROCESS ENROLLMENT FILE
  * Expects a file of format: Semester|Student PawsID|Campus|Department|Course #|Section #|Status Code|HRS|Real Date|EFFECTIVE DATE|FERP
  */
 function parse_enrollfile($now, $line)
 {
     $fields = array_map('addslashes', array_map('trim', explode('|', $line)));
     // Process only if we have the correct number of fields
     if (count($fields) != 11) {
         $a->file = $this->files['enrollfile'];
         $a->line = $line;
         $this->errorlog[] = get_string('malformed', 'block_courseprefs', $a);
         return;
     }
     // Lookup necessary foreign keys for enrollment lookup; throw exception if any are missing
     list($year, $semester_name) = $this->parse_semester($fields[0]);
     $semester = CoursePrefsSemester::findByUnique($year, $semester_name, $fields[2]);
     if (!$semester) {
         $this->errorlog[] = 'Unable to lookup semester entry for enrollment in ' . $this->files['enrollfile'] . ': ' . $line;
         return;
     }
     $user = CoursePrefsUser::findByUnique($fields[1]);
     if (!$user) {
         $this->errorlog[] = 'Unable to lookup user entry for enrollment in ' . $this->files['enrollfile'] . ': ' . $line;
         return;
     }
     $course = CoursePrefsCourse::findByUnique($fields[3], $fields[4]);
     if (!$course) {
         $this->errorlog[] = 'Unable to lookup course entry for enrollment in ' . $this->files['enrollfile'] . ': ' . $line;
         return;
     }
     $section = CoursePrefsSection::findByUnique($semester->getId(), $course->getId(), $fields[5]);
     if (!$section) {
         $this->errorlog[] = 'Unable to lookup section entry for enrollment in ' . $this->files['enrollfile'] . ': ' . $line;
         return;
     }
     try {
         $new_fields = array(1, $fields[6], $fields[8], $fields[9], $fields[7]);
         $this->process_enrollment($user, $section, $new_fields);
     } catch (Exception $e) {
         $this->errorlog[] = $e->getMessage() . ' from ' . $this->files['enrollfile'] . ': ' . $line;
     }
     $user->setFerpa($fields[10]);
     try {
         $user->save();
     } catch (Exception $e) {
         $this->errorlog[] = $e->getMessage() . ' from ' . $this->files['enrollfile'] . ': ' . $line;
     }
 }
Example #8
0
/**
 * Send an email announcing that a teacher is revoking his/her team teaching invitation
 */
function delete_email($teamteach, $current_user)
{
    $to_user = $teamteach->getTtUser();
    $to = get_record('user', 'username', $to_user->getUsername());
    $from = get_record('user', 'username', $current_user->getUsername());
    // Build information to be substituted in email
    $a = new stdClass();
    $a->to_name = $to_user->getFirstname() . ' ' . $to_user->getLastname();
    $a->to_section = CoursePrefsSection::generateFullnameById($teamteach->getTtSectionsId());
    $a->from_name = $current_user->getFirstname() . ' ' . $current_user->getLastname();
    $a->from_section = CoursePrefsSection::generateFullnameById($teamteach->getSectionsId());
    // Send revocation email to user
    email_to_user($to, $from->email, get_string('remove_email_subject', 'block_courseprefs'), get_string('remove_email', 'block_courseprefs', $a));
}
Example #9
0
 /**
  * Returns true if the user is a primary instructor of that section
  */
 function isPrimaryTeacher(CoursePrefsSection $section)
 {
     return $this->sections_primary[$section->getId()];
 }
Example #10
0
 function validation($data)
 {
     global $USER;
     $errorlog = array();
     $form_errorlog = $this->_form->_errors;
     // Skip processing group if there were errors with any of the related group fields
     if ($form_errorlog[TEXTBOX_GROUP] || $form_errorlog[SECTIONSID_FIELD]) {
         return $errorlog;
     }
     // Parse form submission and glean necessary information
     $section_id = $data[SECTIONSID_FIELD];
     $department = $data[DEPARTMENT_FIELD];
     $course_number = $data[COURSE_NUMBER_FIELD];
     $section_number = $data[SECTION_NUMBER_FIELD];
     // Build sections ID to courses ID lookup for data validation
     $user = CoursePrefsUser::findByUnique($USER->username);
     $sections = $user->getSectionsAsTeacher();
     // Log an error if the user isn't the primary teacher of the section selected
     if (!($sections[$section_id] && $user->isPrimaryTeacher($sections[$section_id]))) {
         $errorlog[TEXTBOX_GROUP] = get_string('err_not_primary', 'block_courseprefs');
         return $errorlog;
     }
     // Log an error if the section selected doesn't exist
     $users_section = $sections[$section_id];
     if (!$users_section) {
         $errorlog[TEXTBOX_GROUP] = get_string('err_unknown_section', 'block_courseprefs');
         return $errorlog;
     }
     // Retrieve course related to critera and log an error if course doesn't exist
     $course = CoursePrefsCourse::findByUnique($department, $course_number);
     if (!$course) {
         $errorlog[TEXTBOX_GROUP] = get_string('err_unknown_course', 'block_courseprefs');
         return $errorlog;
     }
     // Retrieve section related to critera and log an error if course doesn't exist
     $section = CoursePrefsSection::findByUnique($users_section->getSemestersId(), $course->getId(), $section_number);
     if (!$section) {
         $errorlog[TEXTBOX_GROUP] = get_string('err_unknown_section', 'block_courseprefs');
         return $errorlog;
     }
     // Log an error if the user has already selected these sections to be team taught
     if (CoursePrefsTeamTeach::findByUnique($user->getId(), $users_section->getId(), $section->getId())) {
         $errorlog[TEXTBOX_GROUP] = get_string('err_same_teamteach', 'block_courseprefs');
         return $errorlog;
     }
     // Determine the primary teacher of the foreign section
     $teachers = CoursePrefsTeacher::findBySectionId($section->getId());
     $teacher_primary = null;
     foreach ($teachers as $teacher) {
         // Skip if teacher is not the primary teacher
         if (!$teacher->getPrimaryFlag()) {
             continue;
         }
         $teacher_primary = $teacher;
         break;
     }
     // Log an error if there isn't a primary teacher to notify or if the user teaches both courses.
     // Otherwise, store the ids of the sections selected for team teaching
     if (!$teacher_primary) {
         $errorlog[TEXTBOX_GROUP] = get_string('no_instructor', 'block_courseprefs');
     } else {
         if ($teacher_primary->getUsersId() == $user->getId()) {
             $errorlog[TEXTBOX_GROUP] = get_string('same_teacher', 'block_courseprefs');
         } else {
             $this->section_selections = $section_id;
             $this->secondary_teamteaches = $section->getId();
         }
     }
     return $errorlog;
 }
Example #11
0
File: lib.php Project: rrusso/EARS
function print_changes($label, $the_prefs)
{
    $html = '';
    if (!empty($the_prefs)) {
        $html = '<span class="label">' . $label . '</span>';
        $html .= "<ul>";
        foreach ($the_prefs as $bucket => $sections) {
            $html .= '<li>Changes for Course ' . $bucket . '</li>';
            $html .= '<ul>';
            foreach ($sections as $section) {
                $html .= '<li>' . CoursePrefsSection::generateFullname($section->year, $section->name, $section->department, $section->course_number, $section->section_number) . '</li>';
            }
            $html .= '</ul>';
        }
        $html .= "</ul>";
    }
    return $html;
}