2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Set of functions used with the relation and pdf feature
10 * returns array of options from string with options separated by comma, removes quotes
13 * PMA_transformation_getOptions("'option ,, quoted',abd,'2,3',");
15 * // 'option ,, quoted',
22 * @param string $option_string comma separated options
24 * @return array options
26 function PMA_transformation_getOptions($option_string)
30 if (! strlen($option_string)
31 ||
! $transform_options = preg_split('/,/', $option_string)
36 while (($option = array_shift($transform_options)) !== null) {
37 $trimmed = trim($option);
38 if (strlen($trimmed) > 1
40 && $trimmed[strlen($trimmed) - 1] == "'"
43 $option = substr($trimmed, 1, -1);
44 } elseif (isset($trimmed[0]) && $trimmed[0] == "'") {
46 $trimmed = ltrim($option);
47 while (($option = array_shift($transform_options)) !== null) {
49 $trimmed .= ',' . $option;
50 $rtrimmed = rtrim($trimmed);
51 if ($rtrimmed[strlen($rtrimmed) - 1] == "'") {
56 $option = substr($rtrimmed, 1, -1);
58 $result[] = stripslashes($option);
65 * Gets all available MIME-types
68 * @staticvar array mimetypes
69 * @return array array[mimetype], array[transformation]
71 function PMA_getAvailableMIMEtypes()
75 if (null !== $stack) {
82 $handle = opendir('./libraries/transformations');
88 while ($file = readdir($handle)) {
95 foreach ($filestack as $file) {
96 if (preg_match('|^.*__.*\.inc\.php$|', $file)) {
97 // File contains transformation functions.
98 $base = explode('__', str_replace('.inc.php', '', $file));
99 $mimetype = str_replace('_', '/', $base[0]);
100 $stack['mimetype'][$mimetype] = $mimetype;
102 $stack['transformation'][] = $mimetype . ': ' . $base[1];
103 $stack['transformation_file'][] = $file;
105 } elseif (preg_match('|^.*\.inc\.php$|', $file)) {
106 // File is a plain mimetype, no functions.
107 $base = str_replace('.inc.php', '', $file);
109 if ($base != 'global') {
110 $mimetype = str_replace('_', '/', $base);
111 $stack['mimetype'][$mimetype] = $mimetype;
112 $stack['empty_mimetype'][$mimetype] = $mimetype;
121 * Gets the mimetypes for all columns of a table
123 * @param string $db the name of the db to check for
124 * @param string $table the name of the table to check for
125 * @param string $strict whether to include only results having a mimetype set
129 * @return array [field_name][field_key] = field_value
131 function PMA_getMIME($db, $table, $strict = false)
133 $cfgRelation = PMA_getRelationsParam();
135 if (! $cfgRelation['commwork']) {
140 SELECT `column_name`,
143 `transformation_options`
144 FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . '
145 WHERE `db_name` = \'' . PMA_sqlAddSlashes($db) . '\'
146 AND `table_name` = \'' . PMA_sqlAddSlashes($table) . '\'
147 AND ( `mimetype` != \'\'' . (!$strict ?
'
148 OR `transformation` != \'\'
149 OR `transformation_options` != \'\'' : '') . ')';
150 return PMA_DBI_fetch_result($com_qry, 'column_name', null, $GLOBALS['controllink']);
151 } // end of the 'PMA_getMIME()' function
154 * Set a single mimetype to a certain value.
156 * @param string $db the name of the db
157 * @param string $table the name of the table
158 * @param string $key the name of the column
159 * @param string $mimetype the mimetype of the column
160 * @param string $transformation the transformation of the column
161 * @param string $transformation_options the transformation options of the column
162 * @param string $forcedelete force delete, will erase any existing
163 * comments for this column
167 * @return boolean true, if comment-query was made.
169 function PMA_setMIME($db, $table, $key, $mimetype, $transformation,
170 $transformation_options, $forcedelete = false)
172 $cfgRelation = PMA_getRelationsParam();
174 if (! $cfgRelation['commwork']) {
181 FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . '
182 WHERE `db_name` = \'' . PMA_sqlAddSlashes($db) . '\'
183 AND `table_name` = \'' . PMA_sqlAddSlashes($table) . '\'
184 AND `column_name` = \'' . PMA_sqlAddSlashes($key) . '\'';
185 $test_rs = PMA_query_as_controluser($test_qry, true, PMA_DBI_QUERY_STORE
);
187 if ($test_rs && PMA_DBI_num_rows($test_rs) > 0) {
188 $row = @PMA_DBI_fetch_assoc
($test_rs);
189 PMA_DBI_free_result($test_rs);
192 && (strlen($mimetype) ||
strlen($transformation)
193 ||
strlen($transformation_options) ||
strlen($row['comment']))
196 UPDATE ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . '
197 SET `mimetype` = \'' . PMA_sqlAddSlashes($mimetype) . '\',
198 `transformation` = \'' . PMA_sqlAddSlashes($transformation) . '\',
199 `transformation_options` = \'' . PMA_sqlAddSlashes($transformation_options) . '\'';
201 $upd_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info']);
204 WHERE `db_name` = \'' . PMA_sqlAddSlashes($db) . '\'
205 AND `table_name` = \'' . PMA_sqlAddSlashes($table) . '\'
206 AND `column_name` = \'' . PMA_sqlAddSlashes($key) . '\'';
207 } elseif (strlen($mimetype) ||
strlen($transformation)
208 ||
strlen($transformation_options)) {
209 $upd_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info'])
210 . ' (db_name, table_name, column_name, mimetype, transformation, transformation_options) '
212 . '\'' . PMA_sqlAddSlashes($db) . '\','
213 . '\'' . PMA_sqlAddSlashes($table) . '\','
214 . '\'' . PMA_sqlAddSlashes($key) . '\','
215 . '\'' . PMA_sqlAddSlashes($mimetype) . '\','
216 . '\'' . PMA_sqlAddSlashes($transformation) . '\','
217 . '\'' . PMA_sqlAddSlashes($transformation_options) . '\')';
220 if (isset($upd_query)) {
221 return PMA_query_as_controluser($upd_query);
225 } // end of 'PMA_setMIME()' function