function alerts_advisees_alerts_form
Search API
7.x alerts.module | alerts_advisees_alerts_form($only_student_id = "", $limit = 25) |
6.x alerts.module | alerts_advisees_alerts_form($only_student_id = "", $limit = 25) |
Displays alerts for our various advisees.
File
- modules/
alerts/ alerts.module, line 374 - module file for Alerts
Code
function alerts_advisees_alerts_form($only_student_id = "", $limit = 25) {
global $user;
$html = "";
$form = array();
fp_set_title('');
fp_add_css(fp_get_module_path('alerts') . '/css/style.css');
$students_line = "'$only_student_id'";
if ($only_student_id == "") {
$student_ids = advise_get_advisees($user->cwid);
if ($student_ids && count($student_ids) > 0) {
$students_line = "'" . join("','", $student_ids) . "'";
}
}
$filter_status = @trim($_SESSION ['alerts_filter_status']);
$filter_line = "";
$filter_params = array();
$filter_params [':faculty_id'] = $user->cwid;
if ($filter_status) {
$filter_line = "AND field__alert_status = :status";
$filter_params [":status"] = $filter_status;
}
// filter options form. Ex: Status
$form ['filter_status'] = array(
'label' => t('Filter by:'),
'type' => 'select',
'options' => array('open' => 'Open', 'closed' => 'Closed'),
'value' => $filter_status,
);
$form ['submit_btn'] = array(
'type' => 'submit',
'value' => t('Submit'),
);
$table_headers = array();
$table_headers [] = array("label" => t("Actions"));
$table_headers [] = array("label" => t("Status"), "field" => "field__alert_status");
if (!$only_student_id) {
$table_headers [] = array("label" => t("Student"));
}
$table_headers [] = array("label" => t("To Faculty/Staff"));
$table_headers [] = array("label" => t("Short Description"));
$table_headers [] = array("label" => t("Author"));
$table_headers [] = array("label" => t("Updated"), "field" => "n.updated");
// Set our initial sort, if none is already set.
theme_table_header_sortable_set_initial_sort('n.updated', 'DESC');
$html .= "<table border='0' class='advisees-alerts'>";
// Draw our our table headers, with links....
$html .= theme_table_header_sortable($table_headers);
// Get our order by clause based on selected table header, if any.
$order_by = theme_table_header_sortable_order_by($table_headers);
// Now, we are going to search for alerts about these students, in the form of a pager query.
// Query for alerts for this student. We will be using a pager_query, so we can display a complete history, if we wish.
$res = pager_query("SELECT DISTINCT(a.cid) FROM content__alert a, content n
WHERE
(
(field__student_id IN ($students_line) AND a.field__exclude_advisor != 1)
OR
(field__target_faculty_id = :faculty_id)
)
AND a.vid = n.vid
AND a.cid = n.cid
AND n.delete_flag = 0
AND n.published = 1
$filter_line
$order_by", $filter_params, $limit, 0, "SELECT COUNT(DISTINCT(a.cid)) FROM content__alert a, content n
WHERE
(
(field__student_id IN ($students_line) AND a.field__exclude_advisor != 1)
OR
(field__target_faculty_id = :faculty_id)
)
AND a.vid = n.vid
AND a.cid = n.cid
AND n.delete_flag = 0
AND n.published = 1
$filter_line
$order_by");
while ($cur = db_fetch_object($res)) {
$cid = $cur->cid;
$content = content_load($cid);
$updated = format_date($content->updated, 'short');
$author = "System";
if ($content->user_id != ALERT_SYSTEM_USER_ID) {
$tuser = fp_load_user($content->user_id);
$author = fp_get_faculty_name($tuser->cwid);
}
$bool_no_student = TRUE;
$student_id = $content->field__student_id ['value'];
$faculty_id = $content->field__target_faculty_id ['value'];
$student_name = t("N/A");
if ($student_id) {
$bool_no_student = FALSE;
$student_name = fp_get_student_name($student_id, TRUE);
}
$faculty_name = t("- Advisor -");
if ($faculty_id) {
$faculty_name = fp_get_faculty_name($faculty_id);
}
$extra_class = "";
// If this content hasn't been read by this user, mark as "unread"
if (!content_get_last_access($cid)) {
$extra_class .= " unread";
}
$student_url = fp_url('student-profile', "current_student_id=$student_id");
$view_url = fp_url("content/$cid", "window_mode=popup&content_tabs=false");
$dtitle = t("View Alert");
$view_link = "<a href='javascript:fpOpenLargeIframeDialog(\"$view_url\",\"$dtitle\");' title='" . t("View") . "' class='action-link' ><i class='fa fa-eye'></i></a>";
$student_profile_link = "<a href='$student_url' title='" . t("Student Profile") . "' class='action-link'><i class='fa fa-user'></i></a>";
if ($only_student_id || $bool_no_student == TRUE) {
$student_profile_link = "";
}
$edit_link = "";
if (user_has_permission('can_edit_alerts')) {
$edit_url = fp_url("content/$cid/edit", "window_mode=popup&content_tabs=false");
$dtitle = t("Edit Alert");
$edit_link = "<a href='javascript:fpOpenLargeIframeDialog(\"$edit_url\",\"$dtitle\");' title='" . t("Edit") . "' class='action-link'><i class='fa fa-pencil'></i></a>";
}
$remove_link = "";
if (user_has_permission('can_remove_alerts')) {
// Load dialog with a custom "remove" screen. Either "Yes" or "Cancel". If we hit yes, we redirect to wherever we are supposed to, just as if we saved. Cancel closes
// the dialog window.
$remove_url = fp_url("content/$cid/remove", "window_mode=popup&content_tabs=false&type=alert");
$dtitle = t("Remove Alert");
$remove_link = "<a href='javascript:fpOpenLargeIframeDialog(\"$remove_url\",\"$dtitle\");' title='" . t("Remove") . "' class='action-link action-link-remove'><i class='fa fa-remove'></i></a>";
}
$html .= "
<tr class='{$content->field__alert_status ['value']} $extra_class'>
<td class='actions'>$view_link $edit_link $remove_link $student_profile_link</td>
<td class='status'>{$content->field__alert_status ['display_value']}</td>
";
if ($only_student_id == "") {
$html .= "<td class='student'>$student_name</td>";
}
$html .= "
<td class='faculty'>$faculty_name</td>
<td class='short-desc'><div class='short-desc-wrapper'>{$content->title}</div></td>
<td class='author'>$author</td>
<td class='updated'>$updated</td>
</tr>
";
} // while cur
$html .= "</table>";
$html .= theme_pager(array(t('« newest'), t('‹ newer'), '', t('older ›'), t('oldest »')));
$form ['mark_table'] = array(
'type' => 'markup',
'value' => $html,
);
return $form;
}