Messages: Better contact image efficiency. Display images in Contacts list.
This commit is contained in:
@@ -90,9 +90,11 @@
|
||||
if (is_array($contact) && sizeof($contact) != 0) {
|
||||
foreach ($contact as $number => $field) {
|
||||
if (is_uuid($field['contact_uuid'])) {
|
||||
$sql = "select contact_name_given, contact_name_family from v_contacts ";
|
||||
$sql .= "where contact_uuid = '".$field['contact_uuid']."' ";
|
||||
$sql .= "and (domain_uuid = '".$domain_uuid."' or domain_uuid is null) ";
|
||||
$sql = "select c.contact_name_given, c.contact_name_family, ";
|
||||
$sql .= "(select ce.email_address from v_contact_emails as ce where ce.contact_uuid = c.contact_uuid and ce.email_primary = 1) as contact_email ";
|
||||
$sql .= "from v_contacts as c ";
|
||||
$sql .= "where c.contact_uuid = '".$field['contact_uuid']."' ";
|
||||
$sql .= "and (c.domain_uuid = '".$domain_uuid."' or c.domain_uuid is null) ";
|
||||
$prep_statement = $db->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
$row = $prep_statement->fetch(PDO::FETCH_NAMED);
|
||||
@@ -100,6 +102,7 @@
|
||||
$contact[$number]['contact_uuid'] = $field['contact_uuid'];
|
||||
$contact[$number]['contact_name_given'] = $row['contact_name_given'];
|
||||
$contact[$number]['contact_name_family'] = $row['contact_name_family'];
|
||||
$contact[$number]['contact_email'] = $row['contact_email'];
|
||||
}
|
||||
unset($prep_statement, $sql);
|
||||
}
|
||||
@@ -117,7 +120,6 @@
|
||||
$prep_statement = $db->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
$rows = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
||||
//view_array($rows);
|
||||
if (is_array($rows) && sizeof($rows)) {
|
||||
foreach ($rows as $row) {
|
||||
$destinations[] = $row['destination_number'];
|
||||
@@ -126,45 +128,87 @@
|
||||
unset ($prep_statement, $sql, $row, $record);
|
||||
$numbers = array_diff($numbers, $destinations);
|
||||
|
||||
//alternate the row style
|
||||
$c = 0;
|
||||
$row_style["0"] = "row_style0";
|
||||
$row_style["1"] = "row_style1";
|
||||
//get contact (primary attachment) images and cache them
|
||||
if (is_array($numbers) && sizeof($numbers) != 0) {
|
||||
foreach ($numbers as $number) {
|
||||
$contact_uuids[] = $contact[$number]['contact_uuid'];
|
||||
}
|
||||
if (is_array($contact_uuids) && sizeof($contact_uuids) != 0) {
|
||||
$sql = "select contact_uuid as uuid, attachment_filename as filename, attachment_content as image from v_contact_attachments ";
|
||||
$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
|
||||
$sql .= "and ( 0 = 1 ";
|
||||
foreach ($contact_uuids as $contact_uuid) {
|
||||
$sql .= "or contact_uuid = '".$contact_uuid."' ";
|
||||
}
|
||||
$sql .= ") ";
|
||||
$sql .= "and attachment_primary = 1 ";
|
||||
$prep_statement = $db->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
$contact_ems = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
||||
|
||||
if (is_array($contact_ems) && sizeof($contact_ems) != 0) {
|
||||
foreach ($contact_ems as $contact_em) {
|
||||
$_SESSION['tmp']['messages']['contact_em'][$contact_em['uuid']]['filename'] = $contact_em['filename'];
|
||||
$_SESSION['tmp']['messages']['contact_em'][$contact_em['uuid']]['image'] = $contact_em['image'];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
unset($sql, $prep_statement, $contact_uuids, $contact_ems, $contact_em);
|
||||
}
|
||||
|
||||
//contacts list
|
||||
if (is_array($numbers) && sizeof($numbers) != 0) {
|
||||
echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
|
||||
foreach($numbers as $number) {
|
||||
if ($current_contact != '' && $number == $current_contact) {
|
||||
echo "<tr><td valign='top' class='".$row_style[$c]." contact_selected' style='cursor: default;'>\n";
|
||||
echo "<tr><td valign='top' class='row_style0 contact_selected' style='cursor: default;'>\n";
|
||||
$selected = true;
|
||||
}
|
||||
else {
|
||||
echo "<tr><td valign='top' class='".$row_style[$c]."' onclick=\"load_thread('".urlencode($number)."', '".$contact[$number]['contact_uuid']."');\">\n";
|
||||
echo "<tr><td valign='top' class='row_style1' onclick=\"load_thread('".urlencode($number)."', '".$contact[$number]['contact_uuid']."');\">\n";
|
||||
$selected = false;
|
||||
}
|
||||
if ($contact[$number]['contact_name_given'] != '' || $contact[$number]['contact_name_family'] != '') {
|
||||
echo "<i>".escape($contact[$number]['contact_name_given'].' '.$contact[$number]['contact_name_family']).'</i>';
|
||||
echo "<span style='float: right; font-size: 65%; line-height: 60%; margin-top: 5px; margin-left: 5px; margin-right: ".($selected ? '-4px' : '0').";'>".escape(format_phone($number)).'</span>';
|
||||
if ($selected) {
|
||||
$contact_name = escape($contact[$number]['contact_name_given'].' '.$contact[$number]['contact_name_family']);
|
||||
$contact_html = (permission_exists('contact_view') ? "<a href='".PROJECT_PATH."/app/contacts/contact_edit.php?id=".$contact[$number]['contact_uuid']."' target='_blank'>".$contact_name."</a>" : $contact_name)." : <a href='callto:".escape($number)."'>".escape(format_phone($number))."</a>";
|
||||
echo "<script>$('#contact_current_name').html(\"".$contact_html."\");</script>\n";
|
||||
//contact image
|
||||
if (is_array($_SESSION['tmp']['messages']['contact_em'][$contact[$number]['contact_uuid']]) && sizeof($_SESSION['tmp']['messages']['contact_em'][$contact[$number]['contact_uuid']]) != 0) {
|
||||
$attachment_type = strtolower(pathinfo($_SESSION['tmp']['messages']['contact_em'][$contact[$number]['contact_uuid']]['filename'], PATHINFO_EXTENSION));
|
||||
echo "<img id='src_message-bubble-image-em_".$contact[$number]['contact_uuid']."' style='display: none;' src='data:image/".$attachment_type.";base64,".$_SESSION['tmp']['messages']['contact_em'][$contact[$number]['contact_uuid']]['image']."'>\n";
|
||||
echo "<img id='contact_image_".$contact[$number]['contact_uuid']."' class='contact_list_image' src='data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'>\n";
|
||||
}
|
||||
}
|
||||
else {
|
||||
echo escape(format_phone($number));
|
||||
if ($selected) {
|
||||
echo "<script>$('#contact_current_name').html(\"<a href='callto:".escape($number)."'>".escape(format_phone($number))."</a>\");</script>\n";
|
||||
//contact name/number
|
||||
if ($contact[$number]['contact_name_given'] != '' || $contact[$number]['contact_name_family'] != '') {
|
||||
echo "<div style='float: right; margin-top: 8px; margin-right: ".($selected ? '-1' : '4')."px;' title=\"".$text['label-view_contact']."\"><a href='/app/contacts/contact_edit.php?id=".$contact[$number]['contact_uuid']."' target='_blank'><i class='glyphicon glyphicon-user'></i></a></div>\n";
|
||||
echo "<strong style='display: inline-block; margin: 8px 0 5px 0;'>".escape($contact[$number]['contact_name_given'].' '.$contact[$number]['contact_name_family']).'</strong><br>';
|
||||
echo "<span style='font-size: 80%; white-space: nowrap;'><a href='callto:".escape($number)."'><i class='glyphicon glyphicon-phone' style='margin-right: 5px;'></i>".escape(format_phone($number)).'</a></span><br>';
|
||||
if (valid_email($contact[$number]['contact_email'])) {
|
||||
echo "<span style='font-size: 80%; white-space: nowrap;'><a href='mailto:".escape($contact[$number]['contact_email'])."'><i class='glyphicon glyphicon-envelope' style='margin-right: 5px;'></i>".$text['label-send_email']."</a></span><br>";
|
||||
}
|
||||
if ($selected) {
|
||||
$contact_name = escape($contact[$number]['contact_name_given'].' '.$contact[$number]['contact_name_family']);
|
||||
$contact_html = (permission_exists('contact_view') ? "<a href='".PROJECT_PATH."/app/contacts/contact_edit.php?id=".$contact[$number]['contact_uuid']."' target='_blank'>".$contact_name."</a>" : $contact_name)." : <a href='callto:".escape($number)."'>".escape(format_phone($number))."</a>";
|
||||
echo "<script>$('#contact_current_name').html(\"".$contact_html."\");</script>\n";
|
||||
}
|
||||
}
|
||||
else {
|
||||
echo escape(format_phone($number));
|
||||
if ($selected) {
|
||||
echo "<script>$('#contact_current_name').html(\"<a href='callto:".escape($number)."'>".escape(format_phone($number))."</a>\");</script>\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
echo "</td></tr>\n";
|
||||
$c = $c == 0 ? 1 : 0;
|
||||
}
|
||||
echo "</table>\n";
|
||||
echo "<center>\n";
|
||||
echo " <span id='contacts_refresh_state'><img src='resources/images/refresh_active.gif' style='width: 16px; height: 16px; border: none; margin-top: 3px; cursor: pointer;' onclick=\"refresh_contacts_stop();\" alt=\"".$text['label-refresh_pause']."\" title=\"".$text['label-refresh_pause']."\"></span> ";
|
||||
echo "</center>\n";
|
||||
|
||||
echo "<script>\n";
|
||||
foreach ($numbers as $number) {
|
||||
if (is_array($_SESSION['tmp']['messages']['contact_em'][$contact[$number]['contact_uuid']]) && sizeof($_SESSION['tmp']['messages']['contact_em'][$contact[$number]['contact_uuid']]) != 0) {
|
||||
echo "$('img#contact_image_".$contact[$number]['contact_uuid']."').css('backgroundImage', 'url(' + $('img#src_message-bubble-image-em_".$contact[$number]['contact_uuid']."').attr('src') + ')');\n";
|
||||
}
|
||||
}
|
||||
echo "</script>\n";
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user