function engagements_display_advisee_engagements_page
Search API
7.x engagements.module | engagements_display_advisee_engagements_page() |
6.x engagements.module | engagements_display_advisee_engagements_page() |
File
- modules/
engagements/ engagements.module, line 330 - This is the primary module file for the engagements module.
Code
function engagements_display_advisee_engagements_page() {
global $user;
$rtn = "";
fp_set_title('');
fp_add_css(fp_get_module_path('alerts') . '/css/style.css');
$rtn .= "<p>" . t("This screen shows engagements/communications (emails and text messages) which advisees have sent, but not those which you or any other
faculty/staff member has sent. To see the complete history of engagements with an advisee, visit the advisee's
Engagements tab.") . "</p>";
$student_ids = advise_get_advisees($user->cwid);
$student_line = "''";
if ($student_ids && count($student_ids) > 0) {
$student_line = "'" . join("','", $student_ids) . "'";
}
if ($student_line) {
$student_line = " field__student_id IN ($student_line) ";
}
// We also want to show messages sent to us which might not have been from an advisee, but we are a designated recipient anyway.
$numbers = engagements_get_user_notify_sms_receipt_values($user->id);
$numbers_line = "";
$numbers_list = "''";
if ($numbers && is_array($numbers) && count($numbers) > 0) {
// Were there any txt messages sent to these number, which we have not read?
$numbers_line = "";
$numbers_list = "'" . join("','", $numbers) . "'";
}
$numbers_line = " field__to_sms_phone IN (" . $numbers_list . ") ";
$table_headers = array();
$table_headers [] = array("label" => "Actions");
$table_headers [] = array("label" => "Student");
$table_headers [] = array("label" => "Type");
$table_headers [] = array("label" => "Details/Preview");
$table_headers [] = array("label" => "Updated", "field" => "n.updated");
$limit = 25;
// Set our initial sort, if none is already set.
theme_table_header_sortable_set_initial_sort('n.updated', 'DESC');
$phones = engagements_get_from_phones();
$rtn .= "<table border='0' class='advisees-alerts'>";
// Draw our our table headers, with links....
$rtn .= 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__engagement a, content n
WHERE a.vid = n.vid
AND a.cid = n.cid
AND n.delete_flag = 0
AND n.published = 1
AND field__direction = 'received'
AND ($student_line OR $numbers_line)
AND field__engagement_type IN ('email', 'txt_msg')
AND (field__manual_entry IS NULL OR field__manual_entry != 'Y')
GROUP BY a.cid
$order_by", $filter_params, $limit, 0, "SELECT COUNT(DISTINCT(a.cid)) FROM content__engagement a, content n
WHERE a.vid = n.vid
AND a.cid = n.cid
AND n.delete_flag = 0
AND n.published = 1
AND field__direction = 'received'
AND ($student_line OR $numbers_line)
AND field__engagement_type IN ('email', 'txt_msg')
AND (field__manual_entry IS NULL OR field__manual_entry != 'Y')
GROUP BY a.cid
$order_by");
while ($cur = db_fetch_object($res)) {
$cid = $cur->cid;
$content = content_load($cid);
$updated = format_date($content->updated, 'short');
$student_id = $content->field__student_id ['value'];
$student_name = fp_get_student_name($student_id, TRUE);
$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 Engagement");
$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>";
$disp_preview = "";
if ($content->field__engagement_type ['value'] == "txt_msg") {
$msg = trim(filter_markup($content->field__engagement_msg ['value'], 'plain'));
if (strstr($msg, "~~")) {
$temp = explode("~~", $msg);
$msg = $temp [0];
}
$desc = "";
$details = engagements_get_sms_from_history($content->field__external_msg_id ['value']);
if ($details) {
$to = $details ['to_number'];
$pretty_to_number = engagements_convert_to_pretty_phone_number($to);
$desc = @$phones ['lines'][$details ['to_number']]['description'];
if (!$desc) {
$desc = @$phones ['lines'][$details ['from_number']]['description'];
}
if ($desc) {
$desc = " / $desc";
}
}
$disp_preview = "$pretty_to_number$desc: $msg";
} // txt_msg
else if ($content->field__engagement_type ['value'] == 'email') {
$disp_preview = trim(filter_markup($content->field__engagement_msg ['value'], 'plain'));
}
if (strlen($disp_preview) > 60) {
$disp_preview = trim(substr($disp_preview, 0, 57)) . "...";
}
$disp_type = $content->field__engagement_type ['display_value'];
$rtn .= "
<tr class='{$content->field__alert_status ['value']} $extra_class'>
<td class='actions'>$view_link $edit_link $remove_link $student_profile_link</td>
";
$rtn .= "<td class='student'>$student_name</td>";
$rtn .= "
<td class='short-desc'><div class='short-desc-wrapper'>$disp_type</div></td>
<td class='short-desc'><div class='short-desc-wrapper'>$disp_preview</div></td>
<td class='updated'>$updated</td>
</tr>
";
} // while cur
$rtn .= "</table>";
$rtn .= theme_pager(array(t('« newest'), t('‹ newer'), '', t('older ›'), t('oldest »')));
return $rtn;
}