function user_student_edit_student_courses_form
Search API
7.x user.student.inc | user_student_edit_student_courses_form() |
6.x user.student.inc | user_student_edit_student_courses_form() |
5.x user.student.inc | user_student_edit_student_courses_form() |
This is the form which we will use to manage a student's courses they've taken.
File
- modules/
user/ user.student.inc, line 494 - Keep track of functions dealing specifically with student user management
Code
function user_student_edit_student_courses_form() {
fp_add_js(fp_get_module_path("user") . "/js/user.js");
$m = 0;
$form = array();
$student_cwid = $_REQUEST ["student_cwid"]; // now getting it from argument
$user_id = db_get_user_id_from_cwid($student_cwid, "student");
$de_catalog_year = @$_REQUEST ["de_catalog_year"];
// Figure out what the page's sub-tabs should be, and set them.
$tab_array = array();
$tab_array [0]["title"] = t("Edit Student");
$tab_array [0]["active"] = FALSE;
$tab_array [0]["on_click"] = "window.location=\"" . fp_url("admin/users/edit-student-user", "student_cwid=$student_cwid&de_catalog_year=$de_catalog_year") . "\"";
$tab_array [1]["title"] = t("Edit Student Courses");
$tab_array [1]["active"] = TRUE;
$tab_array [1]["on_click"] = "window.location=\"" . fp_url("admin/users/edit-student-user/courses", "student_cwid=$student_cwid&de_catalog_year=$de_catalog_year") . "\"";
// If there are attributes for a student, then show the tab.
$attributes = user_get_registered_attributes();
foreach ($attributes as $def) {
if (@$def ['settings']['user_type'] == 'student' || @$def ['settings']['user_type'] == 'all') {
$tab_array [2]["title"] = t("Edit User Attributes");
$tab_array [2]["active"] = FALSE;
$tab_array [2]["on_click"] = "window.location=\"" . fp_url("admin/users/edit-student-user/attributes", "user_id=$user_id&user_type=student&student_cwid=$student_cwid&de_catalog_year=$de_catalog_year") . "\"";
break;
}
}
fp_set_page_sub_tabs($tab_array);
if ($student_cwid != "new") {
$name = fp_get_student_name($student_cwid);
fp_set_title(t("Edit Student Courses @name (@id)", array("@name" => $name, "@id" => $student_cwid)));
}
else {
// A new student! We can't create a new student until a CWID is assigned.
fp_set_title(t("Create New Student User"));
$form ["mark_sorry"] = array(
"type" => "markup",
"value" => "<p>" . t("Sorry, but you cannot add student courses until the student
has been fully created (and given a CWID). Use the Edit Student button above
to return to that screen.") . "</p>",
);
return $form;
}
$form ["user_id"] = array(
"type" => "hidden",
"value" => $user_id,
);
$form ["perform_action2"] = array(
"type" => "hidden",
"value" => "",
);
$form ["student_cwid"] = array(
"type" => "hidden",
"value" => $student_cwid,
);
// Okay, let's create a table in which we will place the student's courses.
$form ["mark" . $m++] = array(
"value" => "<p>
" . ("Enter the student's local (non-transfer) courses they have enrolled in at your institution.") . "
<ul>
<li>" . t("Course: Enter the full course subject ID and num, separated by a space. Ex: ACCT 101") . "</li>
<li>" . t("Term: Enter the term code that this student enrolled in this course. Ex: 201540") . "</li>
<li>" . t("Grade: Enter the grade they earned. Ex: B") . "</li>
<li>" . t("Hrs: Enter the hours awarded. Ex: 3") . "</li>
<li>" . t("Lvl: (optional), enter the level code for this course. Ex: UG") . "</li>
</ul>
" . t("<b>Note:</b> If you have any routines which might overwrite this data (in the student_courses table), then this
data may be ignored or deleted!") . "
</p>",
);
$form ["warn_me"] = array(
"type" => "checkbox",
"label" => t("Warn me if I enter a course which doesn't exist in draft_courses (good for catching typos)"),
"value" => "yes",
);
$form ["mark" . $m++] = array(
"value" => "
<table border='0' width='100%' cellpadding='3' cellspacing='0'>
<tr>
<th>" . t("Course") . "</th>
<th>" . t("Term") . "</th>
<th>" . t("Grade") . "</th>
<th>" . t("Hrs") . "</th>
<th>" . t("Lvl") . "</th>
</tr>",
);
// Let's get an array of what courses the student has already taken (if any)
$courses = array();
$res = db_query("SELECT * FROM student_courses
WHERE student_id = '?'
ORDER BY subject_id, course_num", $student_cwid);
while ($cur = db_fetch_array($res)) {
$courses [] = array(
"course" => $cur ["subject_id"] . " " . $cur ["course_num"],
"term" => $cur ["term_id"],
"grade" => $cur ["grade"],
"hrs" => $cur ["hours_awarded"] * 1, // will trim excess zeroes if there
"lvl" => $cur ["level_code"],
);
}
// Let's add 10 additional (blank) lines to the courses array.
for ($t = 0; $t < 10; $t++) {
$courses [] = array(
"course" => "",
"term" => "",
"grade" => "",
"hrs" => "",
"lvl" => "",
);
}
// Okay, now let's go through the courses array and display in the table...
$stripe = "";
foreach ($courses as $t => $val) {
if ($stripe == "") {
$stripe = "style='background-color: beige;'";
}
else {
$stripe = "";
}
$form ["course_$t"] = array(
"prefix" => "<tr $stripe >
<td valign='top'>",
"type" => "textfield",
"size" => 12,
"suffix" => "</td>",
"value" => $val ["course"],
);
$form ["term_$t"] = array(
"prefix" => "<td valign='top'>",
"type" => "textfield",
"size" => 8,
"suffix" => "</td>",
"value" => $val ["term"],
);
$form ["grade_$t"] = array(
"prefix" => "<td valign='top'>",
"type" => "textfield",
"size" => 4,
"suffix" => "</td>",
"value" => $val ["grade"],
);
$form ["hrs_$t"] = array(
"prefix" => "<td valign='top'>",
"type" => "textfield",
"size" => 4,
"suffix" => "</td>",
"value" => $val ["hrs"],
);
$form ["lvl_$t"] = array(
"prefix" => "<td valign='top'>",
"type" => "textfield",
"size" => 4,
"suffix" => "</td>
</tr>",
"value" => $val ["lvl"],
);
} // for loop
$form ["number_of_courses"] = array(
"type" => "hidden",
"value" => count($courses),
);
// close table.
$form ["mark" . $m++] = array(
"value" => "</table>
<p>" . t("Rows without Course entered will be skipped.
<br><br><b>Note:</b> To add more blank rows, save your work. When the page reloads, there will be additional
blank rows to add new courses.") . "</p>",
);
$form ["submit_btn"] = array(
"type" => "submit",
"value" => "Submit",
);
return $form;
}