ON DELETE ON UPDATE
[phpmyadmin/crack.git] / transformation_wrapper.php3
blob59766fd7da3beefb8254ce6e5b2480ca0c8a0447
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('./libraries/grab_globals.lib.php3');
12 /**
13 * Gets a core script and starts output buffering work
15 if (!defined('PMA_COMMON_LIB_INCLUDED')) {
16 include('./libraries/common.lib.php3');
19 require('./libraries/relation.lib.php3'); // foreign keys
20 require('./libraries/transformations.lib.php3'); // Transformations
21 $cfgRelation = PMA_getRelationsParam();
23 /**
24 * Ensures db and table are valid, else moves to the "parent" script
26 require('./libraries/db_table_exists.lib.php3');
29 /**
30 * Get the list of the fields of the current table
32 PMA_mysql_select_db($db);
33 $table_def = PMA_mysql_query('SHOW FIELDS FROM ' . PMA_backquote($table));
34 if (isset($primary_key)) {
35 $local_query = 'SELECT * FROM ' . PMA_backquote($table) . ' WHERE ' . $primary_key;
36 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', '');
37 $row = PMA_mysql_fetch_array($result);
38 } else {
39 $local_query = 'SELECT * FROM ' . PMA_backquote($table) . ' LIMIT 1';
40 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', '');
41 $row = PMA_mysql_fetch_array($result);
44 // No row returned
45 if (!$row) {
46 exit;
47 } // end if (no record returned)
49 $default_ct = 'application/octet-stream';
51 if ($cfgRelation['commwork'] && $cfgRelation['mimework']) {
52 $mime_map = PMA_getMime($db, $table);
53 $mime_options = PMA_transformation_getOptions((isset($mime_map[urldecode($transform_key)]['transformation_options']) ? $mime_map[urldecode($transform_key)]['transformation_options'] : ''));
55 @reset($mime_options);
56 while(list($key, $option) = each($mime_options)) {
57 if (eregi('^; charset=.*$', $option)) {
58 $mime_options['charset'] = $option;
63 // garvin: For re-usability, moved http-headers and stylesheets
64 // to a seperate file. It can now be included by header.inc.php3,
65 // queryframe.php3, querywindow.php3.
67 include('./libraries/header_http.inc.php3');
68 // [MIME]
69 $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'] : '');
70 header($content_type);
72 if (!isset($resize)) {
73 echo $row[urldecode($transform_key)];
74 } else {
75 // if image_*__inline.inc.php3 finds that we can resize,
76 // it sets $resize to jpeg or png
78 $srcImage = imagecreatefromstring($row[urldecode($transform_key)]);
79 $srcWidth = ImageSX( $srcImage );
80 $srcHeight = ImageSY( $srcImage );
82 // Check to see if the width > height or if width < height
83 // if so adjust accordingly to make sure the image
84 // stays smaller then the $newWidth and $newHeight
86 $ratioWidth = $srcWidth/$newWidth;
87 $ratioHeight = $srcHeight/$newHeight;
89 if( $ratioWidth < $ratioHeight){
90 $destWidth = $srcWidth/$ratioHeight;
91 $destHeight = $newHeight;
92 }else{
93 $destWidth = $newWidth;
94 $destHeight = $srcHeight/$ratioWidth;
97 if ($resize) {
98 $destImage = ImageCreateTrueColor( $destWidth, $destHeight);
101 // ImageCopyResized( $destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight );
102 // better quality but slower:
103 ImageCopyResampled( $destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight );
105 if ($resize == "jpeg") {
106 ImageJPEG( $destImage,"",75 );
108 if ($resize == "png") {
109 ImagePNG( $destImage);
111 ImageDestroy( $srcImage );
112 ImageDestroy( $destImage );
116 * Close MySql non-persistent connections
118 if (isset($GLOBALS['dbh']) && $GLOBALS['dbh']) {
119 @mysql_close($GLOBALS['dbh']);
121 if (isset($GLOBALS['userlink']) && $GLOBALS['userlink']) {
122 @mysql_close($GLOBALS['userlink']);