function filesize_in_bytes($file) { $size = filesize($file); return size_in_bytes($size); }
function show_attachments_list($type, $id_type, $id_author = 0) { if (!($type == 'case' || $type == 'client' || $type == 'org')) { lcm_panic("unknown type -" . $type . "-"); } $q = "SELECT * \n\t\t\tFROM lcm_" . $type . "_attachment \n\t\t\tWHERE content IS NOT NULL "; if ($id_type) { $q .= " AND id_" . $type . " = " . intval($id_type); } if ($id_author) { $q .= " AND id_author = " . intval($id_author); } $result = lcm_query($q); $i = lcm_num_rows($result); if ($i > 0) { echo '<table border="0" align="center" class="tbl_usr_dtl" width="99%">' . "\n"; echo "<tr>\n"; if ($id_author) { echo '<th class="heading" width="1%">' . _Th($type . '_input_id') . "</th>\n"; } echo '<th class="heading">' . _Th('file_input_type') . "</th>\n"; echo '<th class="heading">' . _Th('file_input_description') . "</th>\n"; echo '<th class="heading">' . _Th('file_input_size') . "</th>\n"; echo '<th class="heading">' . "</th>\n"; echo "</tr>\n"; for ($i = 0; $row = lcm_fetch_array($result); $i++) { echo "<tr>\n"; if ($id_author) { echo '<td class="tbl_cont_' . ($i % 2 ? "dark" : "light") . '" align="left">'; echo '<a href="' . $type . '_det.php?' . $type . '=' . $row['id_' . $type] . '" class="content_link">' . $row['id_' . $type] . '</a>'; echo "</td>\n"; } // Mimetype // [ML] We were using the mimetype sent by the browser, but it // ends up being rather useless, since MSIE and Firefox don't agree on // the mimetypes.. ex: .jpg = image/jpeg (FFx), but under MSIE is image/pjeg // So may as well just use the extention of the file, even if not reliable. echo '<td class="tbl_cont_' . ($i % 2 ? "dark" : "light") . '" align="left">'; echo '<a title="' . $row['type'] . '" ' . 'href="view_file.php?type=' . $type . '&file_id=' . $row['id_attachment'] . '">'; if (preg_match("/\\.([a-zA-Z0-9]+)\$/", $row['filename'], $regs) && is_file("images/mimetypes/" . strtolower($regs[1]) . ".png")) { echo '<img src="images/mimetypes/' . $regs[1] . '.png" border="0" alt="' . $row['type'] . '" />'; } else { echo '<img src="images/mimetypes/unknown.png" border="0" alt="' . $row['type'] . '" />'; } echo '</a>'; echo '</td>'; // File name (or description, if any) echo '<td class="tbl_cont_' . ($i % 2 ? "dark" : "light") . '">' . '<a title="' . $row['filename'] . '" ' . 'href="view_file.php?type=' . $type . '&file_id=' . $row['id_attachment'] . '" class="content_link">'; echo trim($row['description']) ? $row['description'] : $row['filename']; echo '</a></td>'; // Size echo '<td class="tbl_cont_' . ($i % 2 ? "dark" : "light") . '">' . size_in_bytes($row['size']) . '</td>'; // Delete icon echo '<td class="tbl_cont_' . ($i % 2 ? "dark" : "light") . '">'; if ($GLOBALS['author_session']['status'] == 'admin' || $row['id_author'] == $GLOBALS['author_session']['id_author'] && ($type == 'case' ? allowed($id_type, 'e') : true)) { echo '<label for="id_rem_file' . $row['id_attachment'] . '">'; echo '<img src="images/jimmac/stock_trash-16.png" width="16" height="16" ' . 'alt="' . _T('file_info_delete') . '" title="' . _T('file_info_delete') . '" />'; echo '</label> '; echo '<input type="checkbox" onclick="lcm_show(\'btn_delete\')" ' . 'id="id_rem_file' . $row['id_attachment'] . '" name="rem_file[]" ' . 'value="' . $row['id_attachment'] . '" />'; } echo '</td>'; echo "</tr>\n"; } echo "</table>\n"; echo '<p align="right" style="visibility: hidden">'; echo '<input type="submit" name="submit" id="btn_delete" value="' . _T('button_validate') . '" class="search_form_btn" />'; echo "</p>\n"; } else { echo '<p class="normal_text">' . _T('file_info_emptylist') . "</p>\n"; } }