Basic detection if mime-features are available, better check on error
[phpmyadmin/crack.git] / transformation_wrapper.php3
bloba78832d6a2aa5352af7589f2ee74be39aea12f94
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
5 /**
6 * Get the variables sent or posted to this script and displays the header
7 */
8 require('./libraries/grab_globals.lib.php3');
10 /**
11 * Gets a core script and starts output buffering work
13 if (!defined('PMA_COMMON_LIB_INCLUDED')) {
14 include('./libraries/common.lib.php3');
16 if (!defined('PMA_OB_LIB_INCLUDED')) {
17 include('./libraries/ob.lib.php3');
20 require('./libraries/relation.lib.php3'); // foreign keys
21 require('./libraries/transformations.lib.php3'); // Transformations
22 $cfgRelation = PMA_getRelationsParam();
25 /**
26 * Displays the query submitted and its result
28 if (!empty($message)) {
29 if (isset($goto)) {
30 $goto_cpy = $goto;
31 $goto = 'tbl_properties.php3?'
32 . PMA_generate_common_url($db, $table)
33 . '&amp;$show_query=1'
34 . '&amp;sql_query=' . urlencode($disp_query);
35 } else {
36 $show_query = '1';
38 if (isset($sql_query)) {
39 $sql_query_cpy = $sql_query;
40 unset($sql_query);
42 if (isset($disp_query)) {
43 $sql_query = (get_magic_quotes_gpc() ? stripslashes($disp_query) : $disp_query);
45 PMA_showMessage($message);
46 if (isset($goto_cpy)) {
47 $goto = $goto_cpy;
48 unset($goto_cpy);
50 if (isset($sql_query_cpy)) {
51 $sql_query = $sql_query_cpy;
52 unset($sql_query_cpy);
55 if (get_magic_quotes_gpc()) {
56 if (!empty($sql_query)) {
57 $sql_query = stripslashes($sql_query);
59 if (!empty($primary_key)) {
60 $primary_key = stripslashes($primary_key);
62 } // end if
65 /**
66 * Defines the url to return to in case of error in a sql statement
68 if (!isset($goto)) {
69 $goto = 'db_details.php3';
71 if (!ereg('^(db_details|tbl_properties|tbl_select)', $goto)) {
72 $err_url = $goto . "?" . PMA_generate_common_url($db) . "&amp;sql_query=" . urlencode($sql_query);
73 } else {
74 $err_url = $goto . '?'
75 . PMA_generate_common_url($db)
76 . ((ereg('^(tbl_properties|tbl_select)', $goto)) ? '&amp;table=' . urlencode($table) : '');
80 /**
81 * Ensures db and table are valid, else moves to the "parent" script
83 require('./libraries/db_table_exists.lib.php3');
86 /**
87 * Sets parameters for links and displays top menu
89 $url_query = PMA_generate_common_url($db, $table)
90 . '&amp;goto=tbl_properties.php3';
92 /**
93 * Get the list of the fields of the current table
95 PMA_mysql_select_db($db);
96 $table_def = PMA_mysql_query('SHOW FIELDS FROM ' . PMA_backquote($table));
97 if (isset($primary_key)) {
98 $local_query = 'SELECT * FROM ' . PMA_backquote($table) . ' WHERE ' . $primary_key;
99 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
100 $row = PMA_mysql_fetch_array($result);
101 // No row returned
102 if (!$row) {
103 unset($row);
104 unset($primary_key);
105 $goto_cpy = $goto;
106 $goto = 'tbl_properties.php3?'
107 . PMA_generate_common_url($db, $table)
108 . '&amp;$show_query=1'
109 . '&amp;sql_query=' . urlencode($local_query);
110 if (isset($sql_query)) {
111 $sql_query_cpy = $sql_query;
112 unset($sql_query);
114 $sql_query = $local_query;
115 PMA_showMessage($strEmptyResultSet);
116 $goto = $goto_cpy;
117 unset($goto_cpy);
118 if (isset($sql_query_cpy)) {
119 $sql_query = $sql_query_cpy;
120 unset($sql_query_cpy);
122 } // end if (no record returned)
124 else
126 $local_query = 'SELECT * FROM ' . PMA_backquote($table) . ' LIMIT 1';
127 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
128 unset($row);
131 $default_ct = 'application/octet-stream';
133 if ($cfgRelation['commwork'] && $cfgRelation['mimework']) {
134 $mime_map = PMA_getMime($db, $table);
135 $mime_options = PMA_transformation_getOptions((isset($mime_map[urldecode($transform_key)]['transformation_options']) ? $mime_map[urldecode($transform_key)]['transformation_options'] : ''));
137 @reset($mime_options);
138 while(list($key, $option) = each($mime_options)) {
139 if (eregi('^; charset=.*$', $option)) {
140 $mime_options['charset'] = $option;
146 * Sends http headers
148 // Don't use cache (required for Opera)
149 $GLOBALS['now'] = gmdate('D, d M Y H:i:s') . ' GMT';
150 header('Expires: ' . $GLOBALS['now']); // rfc2616 - Section 14.21
151 header('Last-Modified: ' . $GLOBALS['now']);
152 header('Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0'); // HTTP/1.1
153 header('Pragma: no-cache'); // HTTP/1.0
154 // [MIME]
155 $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'] : '');
156 header($content_type);
158 echo $row[urldecode($transform_key)];
161 * Close MySql non-persistent connections
163 if (isset($GLOBALS['dbh']) && $GLOBALS['dbh']) {
164 @mysql_close($GLOBALS['dbh']);
166 if (isset($GLOBALS['userlink']) && $GLOBALS['userlink']) {
167 @mysql_close($GLOBALS['userlink']);