} } } $iconShowed = false; if ($isDBFile) { $ftype = ""; if ($pSet->getViewFormat($field) == FORMAT_DATABASE_IMAGE) { if (!$value) { $value = myfile_get_contents('images/no_image.gif'); } $ftype = SupposeImageType($value); } if (!$ftype) { $ftype = getContentTypeByExtension(substr($fileName, strrpos($fileName, '.'))); } $fsize = strlen_bin($value); } else { if ($sessionFile != null) { $isThumbnail = false; $isSRC = false; if ($isPDF) { $isThumbnail = isset($params["thumbnail"]); $isSRC = isset($params['src']); } else { $isThumbnail = postvalue("thumbnail") != ""; $isSRC = postvalue('src') == 1; } if (postvalue("icon") != "") { $fsFileName = "images/icons/" . getIconByFileType($sessionFile["type"], $sessionFile["name"]); $fsize = filesize(getabspath($fsFileName)); $ftype = "image/png";
function GetImageFromDB($gQuery, $forPDF = false, $params = array()) { global $conn; if (!$forPDF) { $table = postvalue("table"); $strTableName = GetTableByShort($table); $settings = new ProjectSettings($strTableName); if (!checkTableName($table)) { return ''; } //include("include/".$table."_variables.php"); @ini_set("display_errors", "1"); @ini_set("display_startup_errors", "1"); if (!isLogged() || !CheckSecurity(@$_SESSION["_" . $strTableName . "_OwnerID"], "Search")) { header("Location: login.php"); return; } $field = postvalue("field"); if (!$settings->checkFieldPermissions($field)) { return DisplayNoImage(); } // construct sql $keysArr = $settings->getTableKeys(); $keys = array(); foreach ($keysArr as $ind => $k) { $keys[$k] = postvalue("key" . ($ind + 1)); } } else { $table = @$params["table"]; $strTableName = GetTableByShort($table); if (!checkTableName($table)) { exit(0); } $settings = new ProjectSettings($strTableName); $field = @$params["field"]; // construct sql $keysArr = $settings->getTableKeys(); $keys = array(); foreach ($keysArr as $ind => $k) { $keys[$k] = @$params["key" . ($ind + 1)]; } } if (!$gQuery->HasGroupBy()) { // Do not select any fields except current (image) field. // If query has 'group by' clause then other fields are used in it and we may not simply cut 'em off. // Just don't do anything in that case. $gQuery->RemoveAllFieldsExcept($settings->getFieldIndex($field)); } $where = KeyWhere($keys); $sql = $gQuery->gSQLWhere($where); $rs = db_query($sql, $conn); if ($forPDF) { if ($rs && ($data = db_fetch_array($rs))) { return $data[$field]; } } else { if (!$rs || !($data = db_fetch_array($rs))) { return DisplayNoImage(); } if (postvalue('src') == 1 && strlen($data[$field]) > 51200) { $value = myfile_get_contents('images/icons/jpg.png'); } else { $value = db_stripslashesbinary($data[$field]); } if (!$value) { if (postvalue("alt")) { $value = db_stripslashesbinary($data[postvalue("alt")]); if (!$value) { return DisplayNoImage(); } } else { return DisplayNoImage(); } } $itype = SupposeImageType($value); if (!$itype) { return DisplayFile(); } if (!isset($pdf)) { header("Content-Type: " . $itype); header("Cache-Control: private"); SendContentLength(strlen_bin($value)); } echoBinary($value); return ''; } }
/** * @intellisense */ function GetImageFromDB($gQuery, $forPDF = false, $params = array()) { global $cman; if (!$forPDF) { $table = postvalue("table"); $strTableName = GetTableByShort($table); $settings = new ProjectSettings($strTableName); if (!checkTableName($table)) { return ''; } @ini_set("display_errors", "1"); @ini_set("display_startup_errors", "1"); $field = postvalue("field"); if (!$settings->checkFieldPermissions($field)) { return DisplayNoImage(); } // construct sql $keysArr = $settings->getTableKeys(); $keys = array(); foreach ($keysArr as $ind => $k) { $keys[$k] = postvalue("key" . ($ind + 1)); } } else { $table = @$params["table"]; $strTableName = GetTableByShort($table); if (!checkTableName($table)) { exit(0); } $settings = new ProjectSettings($strTableName); $field = @$params["field"]; // construct sql $keysArr = $settings->getTableKeys(); $keys = array(); foreach ($keysArr as $ind => $k) { $keys[$k] = @$params["key" . ($ind + 1)]; } } $connection = $cman->byTable($strTableName); if (!$gQuery->HasGroupBy()) { // Do not select any fields except current (image) field. // If query has 'group by' clause then other fields are used in it and we may not simply cut 'em off. // Just don't do anything in that case. $gQuery->RemoveAllFieldsExcept($settings->getFieldIndex($field)); } $where = KeyWhere($keys); $sql = $gQuery->gSQLWhere($where); $data = $connection->query($sql)->fetchAssoc(); if ($forPDF) { if ($data) { return $data[$field]; } } else { if (!$data) { return DisplayNoImage(); } if (postvalue('src') == 1) { $value = myfile_get_contents('images/icons/jpg.png'); } else { $value = $connection->stripSlashesBinary($data[$field]); } if (!$value) { if (postvalue("alt")) { $value = $connection->stripSlashesBinary($data[postvalue("alt")]); if (!$value) { return DisplayNoImage(); } } else { return DisplayNoImage(); } } $itype = SupposeImageType($value); if (!$itype) { return DisplayFile(); } if (!isset($pdf)) { header("Content-Type: " . $itype); header("Cache-Control: private"); SendContentLength(strlen_bin($value)); } echoBinary($value); return ''; } }