Example #1
0
/**
* This funciton will enroll a single student in all classes (terms) for a course.
* Need to decide how to deal with a student that drops out...
*
[SectionID] => 96420d9b-8bb7-4181-8922-ecb8238d72f0
[username] => mknichel
[tsn] => CTE-AIT - I
[BuildingID] => 13
[SchoolYear] => 2010-2011
[TakesAttendance] => 1
[isTeacher] => 1
[TGUID] => 9dfa30cd-d054-42ef-9c00-804faa2b2f5c
[STGUID] => f1504c04-9ecb-4ca8-b4a2-02b10f056461
[isActive] => 1
[FirstName] => Kyle
[LastName] => Porter
* @param array $regi
* @return array error {true/false} message string
*/
function OLD_registerStudentInCourse($regi)
{
    global $db;
    $terms = array();
    $today = strtotime(date('Y-m-d'));
    // ues to compare with terms...
    $schoolYearList = get_school_years_list();
    $schoolYearID = array_search($regi['SchoolYear'], $schoolYearList);
    $result = get_terms($schoolYearID, $regi['center_id'], 'term_ord');
    while ($row = $result->fetch_assoc()) {
        if ($today >= strtotime("-10 days", strtotime($row['term_start_date'])) && $today <= strtotime($row['term_end_date'])) {
            array_push($terms, $row['term_id']);
        }
    }
    $classes = get_classes_for_course($regi['course_id']);
    $message = '';
    while ($row = $classes->fetch_assoc()) {
        if (!in_array($row['term_id'], $terms)) {
            continue;
        }
        $error = false;
        $classID = $row['class_id'];
        $sql = "INSERT into student2class (class_id, user_id) VALUES(" . $row['class_id'] . "," . $regi['student_id'] . ")";
        $result = $db->query($sql);
        $errmsg = "Registering student {" . $regi['student_id'] . "} in class {" . $row['class_id'] . "}<br>\n";
        if (!$result) {
            $error = true;
            $errmsg .= "There was an error executing the query \n\"" . $sql . " \"\n around line " . __LINE__ . " in file " . __FILE__ . "<br>\n" . $db->error;
        } else {
            $sql2 = "SELECT assignments.assignment_id from assignments, categories, classes\r\n            WHERE assignments.category_id=categories.category_id AND categories.class_id=" . $row['class_id'];
            $result2 = $db->query($sql2);
            if (!$result2) {
                $error = true;
                $errmsg .= "There was an error executing the query \n\"" . $sql2 . " \"\n around line " . __LINE__ . " in file " . __FILE__ . "<br>\n" . $db->error;
            } else {
                while ($row2 = $result2->fetch_assoc()) {
                    $sql3 = "INSERT into grades (student_id, assignment_id) VALUES(" . $regi['student_id'] . "," . $row2['assignment_id'] . ")<br>\n";
                    $result3 = $db->query($sql3);
                }
            }
        }
        if ($error) {
            email_admin('Q3AIT.ORG ERROR! Problem registering students in classes.', $errmsg);
        }
        $message .= $errmsg;
    }
    return array('error' => $error, 'message' => $message);
}
Example #2
0
exit;
$q3aitClassRosters = make_assoc_array_from_sql(getClassRostersForSMS(), 'SectionID', 'my');
$q3aitUsers = make_assoc_array_from_sql(getCurrentStudentsForSMS(), 'STGUID', 'my');
$q3aitCourses = make_assoc_array_from_sql(getCoursesForSMS(), 'SectionID', 'my');
$register = array();
// user_id, class_id
//displayArray($smsClassRosters);exit;
//displayArray($q3aitCourses);
//displayArray($q3aitUsers);
foreach ($smsClassRosters as $row) {
    if (array_key_exists($row['SectionID'], $q3aitCourses)) {
        if (array_key_exists($row['STGUID'], $q3aitUsers)) {
            if ($row['DateExited'] == NULL) {
                $student_id = $regi['student_id'] = $q3aitUsers[$row['STGUID']]['user_id'];
                $course_id = $regi['course_id'] = $q3aitCourses[$row['SectionID']]['course_id'];
                $classes = get_classes_for_course($course_id);
                while ($row2 = $classes->fetch_assoc()) {
                    array_push($register, array('user_id' => $student_id, 'class_id' => $row2['class_id']));
                }
            }
        } else {
            //print "Student {STGUID=".$row['STGUID']."} is not in the q3ait db.<br>\n";
            //continue;
        }
    } else {
        //print "Course {SectionID=".$row['SectionID']."} is not in the q3ait db.<br>\n";
        //continue;
    }
}
$errors = registerStudentInCourse($register);
if ($errors['error']) {