Initial import.
[openemr.git] / interface / main / myadmin / transformation_wrapper.php
blob2b3b5fc6dcf4dbf2a1b9d470eefec51b7f6b4b33
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
5 $is_transformation_wrapper = true;
7 /**
8 * Get the variables sent or posted to this script and displays the header
9 */
10 require_once('./libraries/grab_globals.lib.php');
12 /**
13 * Gets a core script and starts output buffering work
15 require_once('./libraries/common.lib.php');
16 require_once('./libraries/relation.lib.php'); // foreign keys
17 require_once('./libraries/transformations.lib.php'); // Transformations
18 $cfgRelation = PMA_getRelationsParam();
20 /**
21 * Ensures db and table are valid, else moves to the "parent" script
23 require_once('./libraries/db_table_exists.lib.php');
26 /**
27 * Get the list of the fields of the current table
29 PMA_mysql_select_db($db);
30 $table_def = PMA_mysql_query('SHOW FIELDS FROM ' . PMA_backquote($table));
31 if (isset($primary_key)) {
32 $local_query = 'SELECT * FROM ' . PMA_backquote($table) . ' WHERE ' . $primary_key;
33 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', '');
34 $row = PMA_mysql_fetch_array($result);
35 } else {
36 $local_query = 'SELECT * FROM ' . PMA_backquote($table) . ' LIMIT 1';
37 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', '');
38 $row = PMA_mysql_fetch_array($result);
41 // No row returned
42 if (!$row) {
43 exit;
44 } // end if (no record returned)
46 $default_ct = 'application/octet-stream';
48 if ($cfgRelation['commwork'] && $cfgRelation['mimework']) {
49 $mime_map = PMA_getMime($db, $table);
50 $mime_options = PMA_transformation_getOptions((isset($mime_map[urldecode($transform_key)]['transformation_options']) ? $mime_map[urldecode($transform_key)]['transformation_options'] : ''));
52 foreach($mime_options AS $key => $option) {
53 if (substr($option, 0, 10) == '; charset=') {
54 $mime_options['charset'] = $option;
59 // garvin: For re-usability, moved http-headers and stylesheets
60 // to a seperate file. It can now be included by header.inc.php,
61 // queryframe.php, querywindow.php.
63 require_once('./libraries/header_http.inc.php');
64 // [MIME]
65 $content_type = 'Content-Type: ' . (isset($mime_map[urldecode($transform_key)]['mimetype']) ? str_replace('_', '/', $mime_map[urldecode($transform_key)]['mimetype']) : $default_ct) . (isset($mime_options['charset']) ? $mime_options['charset'] : '');
66 header($content_type);
68 if (!isset($resize)) {
69 echo $row[urldecode($transform_key)];
70 } else {
71 // if image_*__inline.inc.php finds that we can resize,
72 // it sets $resize to jpeg or png
74 $srcImage = imagecreatefromstring($row[urldecode($transform_key)]);
75 $srcWidth = ImageSX( $srcImage );
76 $srcHeight = ImageSY( $srcImage );
78 // Check to see if the width > height or if width < height
79 // if so adjust accordingly to make sure the image
80 // stays smaller then the $newWidth and $newHeight
82 $ratioWidth = $srcWidth/$newWidth;
83 $ratioHeight = $srcHeight/$newHeight;
85 if( $ratioWidth < $ratioHeight){
86 $destWidth = $srcWidth/$ratioHeight;
87 $destHeight = $newHeight;
88 }else{
89 $destWidth = $newWidth;
90 $destHeight = $srcHeight/$ratioWidth;
93 if ($resize) {
94 $destImage = ImageCreateTrueColor( $destWidth, $destHeight);
97 // ImageCopyResized( $destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight );
98 // better quality but slower:
99 ImageCopyResampled( $destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight );
101 if ($resize == 'jpeg') {
102 ImageJPEG( $destImage,'',75 );
104 if ($resize == 'png') {
105 ImagePNG( $destImage);
107 ImageDestroy( $srcImage );
108 ImageDestroy( $destImage );
112 * Close MySql non-persistent connections
114 if (isset($GLOBALS['dbh']) && $GLOBALS['dbh']) {
115 @mysql_close($GLOBALS['dbh']);
117 if (isset($GLOBALS['userlink']) && $GLOBALS['userlink']) {
118 @mysql_close($GLOBALS['userlink']);