$num_of_pages) { $start_page = $num_of_pages - $numberOfPageLinks; $max_page = $num_of_pages; } } $page_links = "Total Records Found: $number_of_records
\n"; // Previous page link if ($current_page > 1) { $prev_page = $current_page - 1; $page_links .= "<<< "; $page_links .= "   "; } // Indicate the current page number $page_links .= "Viewing Page: $current_page of $num_of_pages"; // Next page link if ($current_page < $num_of_pages) { $next_page = $current_page + 1; $page_links .= "   "; $page_links .= ">>>"; } $page_links .= "
\n"; $page_links .= "
\n"; // Start set of links if ($start_page > 1) { $page_links .= "1 ... "; } // Loop to create set of page links for ($i = $start_page; $i <= $max_page; $i++) { if ($i == $current_page) $page_links .= "$i "; else $page_links .= "$i "; } // End set of links if ($max_page < $num_of_pages) { $page_links .= "...$num_of_pages "; } return($page_links); } // // List a MySQL data set with edit and delete commands // function listData($results,$column_headers,$action,$commands=array(),$insert_new='Y',$column_alignment=array(),$totals_row=array(),$sequence_records='N',$additional_args="") { $msg = getLanguageText('TEXT-CONFIRM-DELETE'); if (strlen($additional_args) == 0) { $default = array( "" . "Edit Current Entry", "" . "Delete Current Entry"); } else { $default = array( "" . "Edit Current Entry", "" . "Delete Current Entry"); } // Merge the commands array passed with the default commands $commands_array = array_merge($default,$commands); listDataCustom($results,$column_headers,$action,$commands_array,$insert_new,$column_alignment,$totals_row,$sequence_records,$additional_args); } // // List a data set with edit and delete commands and drag and drop sorting // function sortData($results,$column_headers,$action,$commands=array(),$insert_new='Y',$column_alignment=array(),$totals_row=array()) { $resultsType = 'mysql'; if (is_array($results)) $resultsType = 'array'; $msg = getLanguageText('TEXT-CONFIRM-DELETE'); $default = array( "" . "Edit Current Entry", "" . "Delete Current Entry"); if (array_key_exists('javaDelete', $GLOBALS) && $GLOBALS['javaDelete'] == 'Y') { $msg = getLanguageText('TEXT-CONFIRM-DELETE'); $default = array( "" . "Edit Current Entry", "" . "Delete Current Entry"); } // Merge the commands array passed with the default commands $commands_array = array_merge($default,$commands); // Check that there are some records in data set if ($resultsType == 'mysql') $number_of_records = db_num_rows($results); else $number_of_records = count($results); if ($number_of_records <= 1) { // Display the data if (!isset($sequence_records)) $sequence_records = 'N'; if (!isset($additional_args)) $additional_args = ''; listDataCustom($results,$column_headers,$action,$commands_array,'N',$column_alignment,array(),'N',$totals_row,$sequence_records,$additional_args); if (isset($insert_new) && $insert_new == 'Y') { echo("
\n"); echo("

" . getLanguageText('TEXT-INSERT-NEW') . "

\n"); } } else { // Setup the form for the sorting echo("
\n"); // Display the data if (!isset($sequence_records)) $sequence_records = 'Y'; if (!isset($additional_args)) $additional_args = ''; listDataCustom($results,$column_headers,$action,$commands_array,'N',$column_alignment,array(),'N',$totals_row,$sequence_records,$additional_args); // Complete the form echo("
\n"); echo(" \n"); // The hidden fields for the form from the $action variable $action_array = array(); parse_str("action=$action",$action_array); foreach ($action_array as $k => $v) { echo(" \n"); } ?>
'>
" . "Edit Current Entry", "" . "Delete Current Entry", ""); } else { // Merge the commands array passed with the delete checkbox $default = array( "" . "Edit Current Entry", "" . "Delete Current Entry"); $delete = array(""); $commands = array_merge($default,$commands,$delete); } // Determine if there are any records $number_of_records = db_num_rows($results); if ($number_of_records > 0) { echo("
\n"); } listDataCustom($results,$column_headers,$action,$commands,'N',$column_alignment,$totals_row,$sequence_records,$additional_args); if ($number_of_records > 0) { echo("\n"); echo(" \n"); echo(" \n"); echo(" \n"); echo("
\n"); echo(" \n"); echo(" \n"); echo("
\n"); echo("
\n"); } // Command to add a record if (isset($insert_new) && $insert_new == 'Y') { echo("
\n"); echo("
\n"); echo("

" . getLanguageText('TEXT-INSERT-NEW') . "

\n"); echo("
\n"); } } // // List a MySQL data set with custom commands // function listDataCustom($results,$column_headers,$action,$commands=array(),$insert_new='Y',$column_alignment=array(),$totals_row=array(),$sequence_records='Y',$additional_args="") { $content = getDataCustom($results,$column_headers,$action,$commands,$insert_new,$column_alignment,$totals_row,$sequence_records,$additional_args); echo($content); } function getDataCustom($results,$column_headers,$action,$commands=array(),$insert_new='Y',$column_alignment=array(),$totals_row=array(),$sequence_records='Y',$additional_args="") { global $default_data_width, $customTableID, $displayTableHeaders, $columnFields, $columnWidths; $localContent = ""; $resultsType = 'mysql'; if (is_array($results)) $resultsType = 'array'; $table_width = $default_data_width; if (isset($GLOBALS['TableWidth']) && $GLOBALS['TableWidth'] > 0) $table_width = $GLOBALS['TableWidth']; // Check for a result dataset if (!isset($results)) { $localContent .= "

Error: Missing Data Set

\n"; return; } // Check for an array of column headers if (!isset($column_headers) || !is_array($column_headers)) { $localContent .= "

Error: Missing Column Headers

\n"; return; } $localContent .= "
\n"; // Check that there are some records in data set if ($resultsType == 'mysql') $number_of_records = db_num_rows($results); else $number_of_records = count($results); if ($number_of_records > 0) { // Start the dataset table if (!isset($GLOBALS['display_dataset_count']) || $GLOBALS['display_dataset_count'] != 'N') $localContent .= "

--- " . getLanguageText('TEXT-DISPLAYING') . " $number_of_records " . getLanguageText('TEXT-ENTRIES') . " ---

\n"; // Command to add a record if ($number_of_records > 10 && ($insert_new == 'Y' || $insert_new == 'T')) { $localContent .= "

" . getLanguageText('TEXT-INSERT-NEW') . "

\n"; } $dataTableID = "data-table"; if (isset($customTableID) && strlen($customTableID)) $dataTableID = $customTableID; $localContent .= "\n"; if (!isset($displayTableHeaders) || $displayTableHeaders !== false) { $localContent .= "\n"; // Output the column headers $localContent .= " \n"; for ($i = 0; $i < count($column_headers); $i++) { $align = 'left'; $fname = ''; if (array_key_exists($i, $column_alignment)) $align = $column_alignment[$i]; if (isset($columnFields) && is_array($columnFields) && array_key_exists($i, $columnFields)) { $fname = $columnFields[$i]; } $width = ''; if (isset($columnWidths) && is_array($columnWidths) && array_key_exists($i, $columnWidths)) $width = " style='width: ".$columnWidths[$i]."px;'"; $localContent .= " \n"; } if (count($commands)) $localContent .= " \n"; $localContent .= " \n"; $localContent .= "\n"; } $localContent .= "\n"; // Display the records in the dataset $RowClasses = array("data-odd","data-even"); $count = 0; // Process each entry in data set for ($rn = 0; $rn < $number_of_records; $rn++) { // Get the next row to process if ($resultsType == 'mysql') $row = db_fetch_array($results); else $row = $results[$rn]; $bgclass = $RowClasses[$count % 2]; $rnum = $count + 1; if (isset($row['record_num'])) $rnum = $row['record_num']; $rowid = $rnum; if (isset($GLOBALS['useRowIDS']) && $GLOBALS['useRowIDS'] == true) $rowid = "row_$rnum"; $localContent .= " \n"; $count++; for ($i = 0; $i < count($column_headers); $i++) { $align = 'left'; if (array_key_exists($i, $column_alignment)) $align = $column_alignment[$i]; $col_id = $rnum . "_$i"; $colIncr = 0; $extra = ''; if (array_key_exists("colspan_$i",$row) && intval($row["colspan_$i"]) > 1) { $extra .= "colspan='" . $row["colspan_$i"] . "' "; $colIncr = intval($row["colspan_$i"]) - 1; } if (array_key_exists("class_$i",$row) && strlen($row["class_$i"])) { $extra .= "class='" . $row["class_$i"] . "' "; } $data = ''; if (array_key_exists($i, $row)) { $data = $row[$i]; if (isset($columnFields) && count($columnFields) > $i) { if (isset($row['record_num'])) { $record_num = $row['record_num']; $fname = str_replace('_','-',$columnFields[$i]); $data = "$data"; } } } $localContent .= " \n"; $i += $colIncr; } if (count($commands) || ($sequence_records == 'Y' && isset($row['sequence']) && $row['sequence'] > 0)) { $width = count($commands) * 20; $col_id = $rnum . ".$i"; if (!array_key_exists('display_commands',$row) || $row['display_commands'] != 'N') { $localContent .= " \n"; } } $localContent .= " \n"; } // Display totals row if there is one provided if (isset($totals_row) && is_array($totals_row) && count($totals_row) > 0) { // Output the column headers $localContent .= " \n"; for ($i = 0; $i < count($column_headers); $i++) { $align = 'left'; if (array_key_exists($i, $column_alignment)) $align = $column_alignment[$i]; $localContent .= " \n"; } if (count($commands)) $localContent .= " \n"; $localContent .= " \n"; } // Complete the table $localContent .= "\n"; $localContent .= "
" . $column_headers[$i] . " 
$data\n"; $localContent .= " \n"; $localContent .= " \n"; for ($i = 0; $i < count($commands); $i++) { $command = $commands[$i]; if (strlen($command)) { if (strpos($command,"command-button") == FALSE && strpos($command,"]*)>(.*)#","\\1 class='smallButton'>\\2",$command); } $numRNUM = substr_count($command,"%d"); $localContent .= " \n"; } } // if ($sequence_records == 'Y' && isset($row['sequence']) && $row['sequence'] > 0) { // $localContent .= " \n"; // } $localContent .= " \n"; $localContent .= "
"; if ($numRNUM == 1) { if (array_key_exists('delete_flag',$row) && strlen($row['delete_flag']) > 0 && strpos($command, "dflag")) { $command_string = sprintf($command,$row['record_num'],$row['delete_flag']); } else { $command_string = sprintf($command,$row['record_num'],$additional_args); } } if ($numRNUM == 2) { if (array_key_exists('delete_flag',$row) && strlen($row['delete_flag']) > 0 && strpos($command, "dflag")) { $command_string = sprintf($command,$row['record_num'],$row['record_num'],$row['delete_flag']); } else { // $command_string = sprintf($command,$row['record_num'],$row['record_num'],$row['delete_flag'],$additional_args); $command_string = sprintf($command,$row['record_num'],$row['record_num'],$additional_args); } } if (array_key_exists('delete_flag',$row) && $row['delete_flag'] == 'N' && strpos($command_string, "{DISABLED-FLAG}") !== false) { $command_string = str_replace("{DISABLED-FLAG}", "disabled", $command_string); } if (strpos($command_string, 'asnum') === false && array_key_exists('school_num', $row)) { $asnum = $row['school_num']; $command_string = str_replace("title=", "asnum='$asnum' title=", $command_string); } $command_string = str_replace("24.png", "16.png", $command_string); $localContent .= "$command_string  "; // if ($count < $number_of_records) { // $localContent .= "  "; // } // // if ($number_of_records > 1 && $count == $number_of_records) { // $localContent .= "  "; // } // // if ($count > 1) { // $localContent .= "  "; // } // else { // $localContent .= "  "; // } // $localContent .= "
\n"; $localContent .= "
" . $totals_row[$i] . " 
\n"; } else { $localContent .= "

" . getLanguageText('ERRORMSG-NO-RECORDS') . "

\n"; } // Command to add a record if (isset($insert_new) && $insert_new == 'Y') { $localContent .= "
\n"; $localContent .= "

" . getLanguageText('TEXT-INSERT-NEW') . "

\n"; } $localContent .= "
\n"; return($localContent); } // // List a MySQL data set with thumbnails and custom commands // function listImageData($results,$column_headers,$photo_path="",$commands=array()) { global $default_data_width; // Check for a mysql result dataset if (!isset($results)) { echo("

Error: Missing Data Set

\n"); return; } // Check for an array of column headers if (!isset($column_headers) || !is_array($column_headers)) { echo("

Error: Missing Column Headers

\n"); return; } echo("
\n"); // Check that there are some records in data set $number_of_records = db_num_rows($results); if ($number_of_records > 0) { // Start the dataset table echo("

--- " . getLanguageText('TEXT-DISPLAYING') . " $number_of_records " . getLanguageText('TEXT-ENTRIES') . " ---

\n"); echo("\n"); // Output the column headers echo(" \n"); echo(" \n"); for ($i = 1; $i < count($column_headers); $i++) { echo(" \n"); } if (count($commands)) echo(" \n"); echo(" \n"); // Display the records in the dataset $RowClasses = array("data-odd","data-even"); $count = 0; while ($row = db_fetch_array($results)) { echo(" \n"); $bgclass = $RowClasses[$count % 2]; $count++; // Treat the first parameter as the image name $thumb = $row[0]; if (is_file("$photo_path/$thumb")) { $image = ""; $large = ""; if (isset($row['photo'])) { $large = $row['photo']; } if (isset($row['large'])) { $large = $row['large']; } if (strlen($large) > 0) { $image = "$image"; } echo(" \n"); } else { echo(" \n"); } for ($i = 1; $i < count($column_headers); $i++) { echo(" \n"); } if (count($commands) || (isset($row['sequence']) && $row['sequence'] > 0)) { $width = count($commands) * 30; echo(" \n"); } echo(" \n"); } // Complete the table echo("
" . $column_headers[0] . "" . $column_headers[$i] . " 
$imageImage Not Found" . $row[$i] . ""); echo(" \n"); echo(" \n"); for ($i = 0; $i < count($commands); $i++) { $command = $commands[$i]; if (strlen($command)) { echo(" \n"); } } // if (isset($row['sequence']) && $row['sequence'] > 0) { // echo(" \n"); // } echo(" \n"); echo("
 "); printf($command,$row['record_num']); echo("   "); // if ($count < $number_of_records) { // echo("  "); // } // // if ($number_of_records > 2 && $count == $number_of_records) { // echo("  "); // } // // if ($count > 1) { // echo("  "); // } // echo("
\n"); echo("
\n"); } else { echo("

" . getLanguageText('ERRORMSG-NO-RECORDS') . "

\n"); } echo("
\n"); } // // Produce an XLS file from a data set // function xlsData($data,$column_headers=array(),$filename='data.xls',$titles=array()) { // Initialize the spreadsheet document type header('Pragma: public'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Cache-Control: private',false); header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=$filename"); header('Content-Transfer-Encoding: text'); echo "\xEF\xBB\xBF"; // If there are titles if (count($titles)) { for ($i = 0; $i < count($titles); $i++) { $title = $titles[$i]; for ($j = 0; $j < count($title); $j++) { $text = $title[$j]; echo("\"$text\","); } echo("\n"); } } // If there are column headers if (count($column_headers)) { for ($i = 0; $i < count($column_headers); $i++) { if ($i > 0) echo(","); $header = $column_headers[$i]; echo("\"$header\""); } echo("\n"); } // Determine the data type of the data set $resultsType = 'mysql'; if (is_array($data)) $resultsType = 'array'; // Check that there are some records in data set if ($resultsType == 'mysql') $number_of_records = db_num_rows($data); else $number_of_records = count($data); // Process each record of the data set if ($number_of_records > 0) { for ($rn = 0; $rn < $number_of_records; $rn++) { // Get the next row to process if ($resultsType == 'mysql') $row = db_fetch_array($data); else $row = $data[$rn]; if (is_array($row)) { for ($i = 0; $i < count($row); $i++) { if ($i > 0) echo(","); if (array_key_exists($i,$row)) { $field = $row[$i]; if (is_numeric($field)) echo($field); else { $field = str_replace('"',"\"\"",$field); echo("\"$field\""); } } } } else echo($row); echo("\n"); } } } // // List an array of data records with edit and delete commands // function listArray($data,$column_headers,$action) { global $default_data_width; // Check for an array of data if (!isset($data) || !is_array($data)) { echo("

Error: Missing or Invalid Data Array

\n"); return; } // Check for an array of column headers if (!isset($column_headers) || !is_array($column_headers)) { echo("

Error: Missing Column Headers

\n"); return; } echo("
\n"); if (count($data) > 0) { // Start the dataset table echo("\n"); // Output the column headers echo(" \n"); for ($i = 0; $i < count($column_headers); $i++) { echo(" \n"); } echo(" \n"); echo(" \n"); // Display the records in the dataset $RowClasses = array("data-odd","data-even"); $count = 0; for ($n = 0; $n < count($data); $n++) { $row = $data[$n]; echo(" \n"); $bgclass = $RowClasses[$count % 2]; $count++; for ($i = 0; $i < count($column_headers); $i++) { echo(" \n"); } echo(" \n"); echo(" \n"); } // Complete the table echo("
" . $column_headers[$i] . " 
" . $row[$i] . ""); echo("[Edit] "); echo("[Delete]"); echo("
\n"); } else { echo("

" . getLanguageText('ERRORMSG-NO-RECORDS') . "

\n"); } // Command to add a record echo("
\n"); echo("

[" . getLanguageText('TEXT-INSERT-NEW') . "]

\n"); echo("
\n"); } // // List an array of report titles // function reportTitles($titles,$alignment=array(),$color="") { if (isset($color) && strlen($color) > 0) $bgcolor = " bgcolor='$color'"; echo(" \n"); for ($i = 0; $i < count($titles); $i++) { if (isset($alignment[$i])) $align = " align='" . $alignment[$i] . "'"; echo(" " . $titles[$i] . "\n"); } echo(" \n"); } // // List a report line of data from an array // function reportLine($data,$alignment=array(),$color="") { if (isset($color) && strlen($color) > 0) $bgcolor = " bgcolor='$color'"; echo(" \n"); $keys = array_keys($data); for ($i = 0; $i < count($keys); $i++) { if (isset($alignment[$i])) $align = " align='" . $alignment[$i] . "'"; echo(" " . $data[$keys[$i]] . "\n"); } echo(" \n"); } // // Extract an array into the GLOBAL space // function array_extract($data,$mode="") { $keys = array_keys($data); for ($i = 0; $i < count($keys); $i++) { switch ($mode) { case 'SPECIAL': $GLOBALS[$keys[$i]] = htmlspecialchars($data[$keys[$i]],ENT_QUOTES); break; case 'STRIP': default: $GLOBALS[$keys[$i]] = stripslashes($data[$keys[$i]]); } } } // // Function to parse the array parameter and return a string // function parseArray($var,$var_name='') { // Return if parameter is not an array if (!is_array($var)) return(''); // Return if the array has no elements if (count($var) == 0) return(''); // Create the result string $result = ""; if (strlen($var_name) > 0) $result .= "ARRAY NAME: $" . $var_name . "\n\n"; $keys = array_keys($var); foreach($keys as $name) { $value = $var[$name]; if (!is_array($value)) $result .= "$name => $value\n"; else parseArray($value, $name); $result .= "+++++++++\n"; } return($result); } // // Function to strip excess characters from currency value // function trimNumber($num) { $patterns = array('/\$/','/'.chr(163).'/','/,/'); return(preg_replace($patterns,"",$num)); } // // Function to URL encode an array // function encodeArray($args) { if (is_array($args)) { $argString = ""; foreach ($args as $key => $value) { if (strlen($argString) > 0) $argString .= "&"; $argString .= "$key="; if (is_string($value) && strlen($value)) $argString .= urlencode($value); } } return($argString); } // // Format numbers to currency // function formatCurrency($amount) { global $currencySymbol; $sign = ''; if ($amount < 0) $sign = '-'; $text = $sign . $currencySymbol . number_format(abs($amount),2); return($text); } // // Format URL's in text // function formatUrlsInText($text){ $reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/"; preg_match_all($reg_exUrl, $text, $matches); $usedPatterns = array(); foreach($matches[0] as $pattern){ if(!array_key_exists($pattern, $usedPatterns)){ $usedPatterns[$pattern]=true; $text = str_replace($pattern, "{$pattern} ", $text); } } return $text; } // // str_match() // // Map PHP strstr to a more consistent format // function str_match($pattern, $string) { return(strstr($string,$pattern)); } // // stri_match() // // Map PHP strstr to a more consistent format // function stri_match($pattern, $string) { return(stristr($string,$pattern)); } // // encrypt_password() // function encrypt_password($password = "") { global $userSALT; if (strlen($password) == 0) return -1; $password_crypt = crypt($password,$userSALT); return($password_crypt); } // Check if parent account has an email address function emailCheck() { global $school_num, $action; if (array_key_exists('action', $_GET)) $action = $_GET['action']; if ($action == "account") return; if ($_SESSION['UserInfo']['type'] != 'Parent') return; if (strlen($_SESSION['UserInfo']['email'])) return; $unum = $_SESSION['UserInfo']['record_num']; $email = db_getVal("SELECT email FROM users WHERE school_num = $school_num AND record_num = $unum"); if (strlen($email)) return; return(-1); } // // Resize image if required // function resizeImage($image, $image_path, $maxImageDimension = 900, $maxThumbDimension = 200) { global $school_record; $image_path = rtrim($image_path, '/'); // startLog("resizeImage"); // writeLog("image: $image"); // writeLog("image_path: $image_path"); // writeLog("$image_path/$image"); $mimetype = mime_content_type("$image_path/$image"); if (strpos($mimetype, "image") !== 0) { // writeLog("Not an Image"); return; } // Setup image conversion if required $cmd="/usr/bin/convert"; $tempImage = "$image_path/temp"; // Set thumbnail name $segments = explode('.',$image); $lastSegment = count($segments) - 1; $fname = ""; $ext = $segments[$lastSegment]; for ($i = 0; $i < $lastSegment; $i++) { if (strlen($fname)) $fname .= '.'; $fname .= $segments[$i]; } $thumbnail = $fname."-tn.".$ext; // writeLog("thumbnail: $thumbnail"); if (is_file($tempImage)) { // writeLog("temp image exists"); // writeLog("unlink $tempImage"); unlink($tempImage); } // Get image info $image_size = GetImageSize("$image_path/$image"); $image_width = $image_size[0]; $image_height = $image_size[1]; // writeLog("image_width: $image_width"); // writeLog("image_height: $image_height"); if (is_file("$image_path/$thumbnail")) { // writeLog("unlink $image_path/$thumbnail"); unlink("$image_path/$thumbnail"); } // Check which is largest dimension if ($image_width >= $image_height) { if ($image_width > $maxImageDimension) { $height = intval($image_height * $maxImageDimension / $image_width); $command = "$cmd -size {$image_width}x$image_height $image_path/$image -resize {$maxImageDimension}x$height +profile \"*\" $tempImage"; exec($command); if (is_file($tempImage)) { unlink("$image_path/$image"); rename($tempImage,"$image_path/$image"); } } } else { if ($image_height > $maxImageDimension) { $width = intval($image_width * $maxImageDimension / $image_height); $command = "$cmd -size {$image_width}x{$image_height} $image_path/$image -resize {$width}x{$maxImageDimension} +profile \"*\" $tempImage"; exec($command); if (is_file($tempImage)) { unlink("$image_path/$image"); rename($tempImage,"$image_path/$image"); } } } // Create the thumbnail $width = intval($image_width * $maxThumbDimension / $image_height); $width = $maxThumbDimension; $height = intval($image_height * $maxThumbDimension / $image_width); $command = "$cmd -size {$image_width}x{$image_height} $image_path/$image -resize {$width}x{$maxThumbDimension} +profile \"*\" $tempImage"; exec($command); if (is_file($tempImage)) { $res = rename($tempImage,"$image_path/$thumbnail"); if (!$res) copy("$image_path/$image","$image_path/$thumbnail"); return($thumbnail); } return(''); } // // Create a thumbnail image "-tn" // function createThumbnail($image, $imagedir) { global $school_record, $maxImageDimension, $maxThumbDimension; // startLog("createThumbnail"); // Setup image conversion if required $cmd="/usr/bin/convert"; $target = "$imagedir/temp"; if (is_file($target)) { // writeLog("target exists"); unlink("$imagedir/$image"); } // Get image info $image_size = GetImageSize("$imagedir/$image"); $image_width = $image_size[0]; $image_height = $image_size[1]; // writeLog("image_width: $image_width"); // writeLog("image_height: $image_height"); // Determine name of thumbnail image $segments = explode('.',$image); $lastSegment = count($segments) - 1; $fname = ""; $ext = $segments[$lastSegment]; for ($i = 0; $i < $lastSegment; $i++) { if (strlen($fname)) $fname .= '.'; $fname .= $segments[$i]; } $thumbnail = $fname."-tn.".$ext; if (is_file("$imagedir/$thumbnail")) { unlink("$imagedir/$thumbnail"); } // writeLog("maxImageDimension: $maxImageDimension"); // Check which is largest dimension if ($image_width > 0 && $image_width >= $image_height) { // Create the thumbnail $height = intval($image_height * $maxThumbDimension / $image_width); $command = "$cmd -size {$image_width}x$image_height $imagedir/$image -resize {$maxThumbDimension}x$height +profile \"*\" $target"; // writeLog("command: $command"); exec($command); if (is_file($target)) { $res = rename($target,"$imagedir/$thumbnail"); if (!$res) copy("$imagedir/$image","$imagedir/$thumbnail"); } } else { if ($image_height > 0) { // Create the thumbnail $width = intval($image_width * $maxThumbDimension / $image_height); $command = "$cmd -size {$image_width}x{$image_height} $imagedir/$image -resize {$width}x{$maxThumbDimension} +profile \"*\" $target"; // writeLog("command: $command"); exec($command); if (is_file($target)) { $res = rename($target,"$imagedir/$thumbnail"); if (!$res) copy("$imagedir/$image","$imagedir/$thumbnail"); } } } return($thumbnail); } // // Reset OP cache if in development mode // function resetCache() { $mode = 'Production'; $mode = 'Development'; if (function_exists('opcache_reset') && $mode == 'Development') opcache_reset(); } // // Help message for form fields // function displayHelp($msg, $align='right') { if (strlen($msg) == 0) return; if (substr($msg,0,5) === 'TEXT-') $msg = getLanguageText($msg); $text = "\n" . "$msg\n" . ""; echo($text); } ?>