[ Index ] |
|
Code source de phpMyAdmin 2.10.3 |
1 <?php 2 /* $Id: htmlword.php 9805 2006-12-26 16:10:47Z lem9 $ */ 3 // vim: expandtab sw=4 ts=4 sts=4: 4 5 /** 6 * Set of functions used to build CSV dumps of tables 7 */ 8 9 if (isset($plugin_list)) { 10 $plugin_list['htmlword'] = array( 11 'text' => 'strHTMLWord', 12 'extension' => 'doc', 13 'mime_type' => 'application/vnd.ms-word', 14 'force_file' => true, 15 'options' => array( 16 array('type' => 'bool', 'name' => 'structure', 'text' => 'strStructure', 'force' => 'data'), 17 array('type' => 'bgroup', 'name' => 'data', 'text' => 'strData', 'force' => 'structure'), 18 array('type' => 'text', 'name' => 'null', 'text' => 'strReplaceNULLBy'), 19 array('type' => 'bool', 'name' => 'columns', 'text' => 'strPutColNames'), 20 array('type' => 'egroup'), 21 ), 22 'options_text' => 'strHTMLWordOptions', 23 ); 24 } else { 25 26 /** 27 * Outputs comment 28 * 29 * @param string Text of comment 30 * 31 * @return bool Whether it suceeded 32 */ 33 function PMA_exportComment($text) { 34 return TRUE; 35 } 36 37 /** 38 * Outputs export footer 39 * 40 * @return bool Whether it suceeded 41 * 42 * @access public 43 */ 44 function PMA_exportFooter() { 45 return PMA_exportOutputHandler('</body></html>'); 46 } 47 48 /** 49 * Outputs export header 50 * 51 * @return bool Whether it suceeded 52 * 53 * @access public 54 */ 55 function PMA_exportHeader() { 56 global $charset, $charset_of_file; 57 return PMA_exportOutputHandler('<html xmlns:o="urn:schemas-microsoft-com:office:office" 58 xmlns:x="urn:schemas-microsoft-com:office:word" 59 xmlns="http://www.w3.org/TR/REC-html40"> 60 61 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 62 <html> 63 <head> 64 <meta http-equiv="Content-type" content="text/html;charset=' . ( isset($charset_of_file) ? $charset_of_file : $charset ) .'" /> 65 </head> 66 <body>'); 67 } 68 69 /** 70 * Outputs database header 71 * 72 * @param string Database name 73 * 74 * @return bool Whether it suceeded 75 * 76 * @access public 77 */ 78 function PMA_exportDBHeader($db) { 79 return PMA_exportOutputHandler('<h1>' . $GLOBALS['strDatabase'] . ' ' . $db . '</h1>'); 80 } 81 82 /** 83 * Outputs database footer 84 * 85 * @param string Database name 86 * 87 * @return bool Whether it suceeded 88 * 89 * @access public 90 */ 91 function PMA_exportDBFooter($db) { 92 return TRUE; 93 } 94 95 /** 96 * Outputs create database database 97 * 98 * @param string Database name 99 * 100 * @return bool Whether it suceeded 101 * 102 * @access public 103 */ 104 function PMA_exportDBCreate($db) { 105 return TRUE; 106 } 107 108 /** 109 * Outputs the content of a table in CSV format 110 * 111 * @param string the database name 112 * @param string the table name 113 * @param string the end of line sequence 114 * @param string the url to go back in case of error 115 * @param string SQL query for obtaining data 116 * 117 * @return bool Whether it suceeded 118 * 119 * @access public 120 */ 121 function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) 122 { 123 global $what; 124 125 if (!PMA_exportOutputHandler('<h2>' . $GLOBALS['strDumpingData'] . ' ' . $table . '</h2>')) { 126 return FALSE; 127 } 128 if (!PMA_exportOutputHandler('<table class="width100" cellspacing="1">')) { 129 return FALSE; 130 } 131 132 // Gets the data from the database 133 $result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED); 134 $fields_cnt = PMA_DBI_num_fields($result); 135 136 // If required, get fields name at the first line 137 if (isset($GLOBALS['htmlword_columns'])) { 138 $schema_insert = '<tr class="print-category">'; 139 for ($i = 0; $i < $fields_cnt; $i++) { 140 $schema_insert .= '<td class="print"><b>' . htmlspecialchars(stripslashes(PMA_DBI_field_name($result, $i))) . '</b></td>'; 141 } // end for 142 $schema_insert .= '</tr>'; 143 if (!PMA_exportOutputHandler($schema_insert)) { 144 return FALSE; 145 } 146 } // end if 147 148 // Format the data 149 while ($row = PMA_DBI_fetch_row($result)) { 150 $schema_insert = '<tr class="print-category">'; 151 for ($j = 0; $j < $fields_cnt; $j++) { 152 if (!isset($row[$j]) || is_null($row[$j])) { 153 $value = $GLOBALS[$what . '_null']; 154 } elseif ($row[$j] == '0' || $row[$j] != '') { 155 $value = $row[$j]; 156 } else { 157 $value = ''; 158 } 159 $schema_insert .= '<td class="print">' . htmlspecialchars($value) . '</td>'; 160 } // end for 161 $schema_insert .= '</tr>'; 162 if (!PMA_exportOutputHandler($schema_insert)) { 163 return FALSE; 164 } 165 } // end while 166 PMA_DBI_free_result($result); 167 if (!PMA_exportOutputHandler('</table>')) { 168 return FALSE; 169 } 170 171 return TRUE; 172 } 173 174 function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = false, $do_comments = false, $do_mime = false, $dates = false, $dummy) 175 { 176 global $cfgRelation; 177 178 if (!PMA_exportOutputHandler('<h2>' . $GLOBALS['strTableStructure'] . ' ' .$table . '</h2>')) { 179 return FALSE; 180 } 181 182 /** 183 * Get the unique keys in the table 184 */ 185 $keys_query = 'SHOW KEYS FROM ' . PMA_backquote($table) . ' FROM '. PMA_backquote($db); 186 $keys_result = PMA_DBI_query($keys_query); 187 $unique_keys = array(); 188 while ($key = PMA_DBI_fetch_assoc($keys_result)) { 189 if ($key['Non_unique'] == 0) { 190 $unique_keys[] = $key['Column_name']; 191 } 192 } 193 PMA_DBI_free_result($keys_result); 194 195 /** 196 * Gets fields properties 197 */ 198 PMA_DBI_select_db($db); 199 $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table); 200 $result = PMA_DBI_query($local_query); 201 $fields_cnt = PMA_DBI_num_rows($result); 202 203 // Check if we can use Relations (Mike Beck) 204 if ($do_relation && !empty($cfgRelation['relation'])) { 205 // Find which tables are related with the current one and write it in 206 // an array 207 $res_rel = PMA_getForeigners($db, $table); 208 209 if ($res_rel && count($res_rel) > 0) { 210 $have_rel = TRUE; 211 } else { 212 $have_rel = FALSE; 213 } 214 } else { 215 $have_rel = FALSE; 216 } // end if 217 218 /** 219 * Displays the table structure 220 */ 221 if (!PMA_exportOutputHandler('<table class="width100" cellspacing="1">')) { 222 return FALSE; 223 } 224 225 $columns_cnt = 4; 226 if ($do_relation && $have_rel) { 227 $columns_cnt++; 228 } 229 if ($do_comments && $cfgRelation['commwork']) { 230 $columns_cnt++; 231 } 232 if ($do_mime && $cfgRelation['mimework']) { 233 $columns_cnt++; 234 } 235 236 $schema_insert = '<tr class="print-category">'; 237 $schema_insert .= '<th class="print">' . htmlspecialchars($GLOBALS['strField']) . '</th>'; 238 $schema_insert .= '<td class="print"><b>' . htmlspecialchars($GLOBALS['strType']) . '</b></td>'; 239 $schema_insert .= '<td class="print"><b>' . htmlspecialchars($GLOBALS['strNull']) . '</b></td>'; 240 $schema_insert .= '<td class="print"><b>' . htmlspecialchars($GLOBALS['strDefault']) . '</b></td>'; 241 if ($do_relation && $have_rel) { 242 $schema_insert .= '<td class="print"><b>' . htmlspecialchars($GLOBALS['strLinksTo']) . '</b></td>'; 243 } 244 if ($do_comments && ($cfgRelation['commwork'] || PMA_MYSQL_INT_VERSION >= 40100)) { 245 $schema_insert .= '<td class="print"><b>' . htmlspecialchars($GLOBALS['strComments']) . '</b></td>'; 246 $comments = PMA_getComments($db, $table); 247 } 248 if ($do_mime && $cfgRelation['mimework']) { 249 $schema_insert .= '<td class="print"><b>' . htmlspecialchars('MIME') . '</b></td>'; 250 $mime_map = PMA_getMIME($db, $table, true); 251 } 252 $schema_insert .= '</tr>'; 253 254 if (!PMA_exportOutputHandler($schema_insert)) { 255 return FALSE; 256 } 257 258 while ($row = PMA_DBI_fetch_assoc($result)) { 259 260 $schema_insert = '<tr class="print-category">'; 261 $type = $row['Type']; 262 // reformat mysql query output - staybyte - 9. June 2001 263 // loic1: set or enum types: slashes single quotes inside options 264 if (eregi('^(set|enum)\((.+)\)$', $type, $tmp)) { 265 $tmp[2] = substr(ereg_replace('([^,])\'\'', '\\1\\\'', ',' . $tmp[2]), 1); 266 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')'; 267 $type_nowrap = ''; 268 269 $binary = 0; 270 $unsigned = 0; 271 $zerofill = 0; 272 } else { 273 $type_nowrap = ' nowrap="nowrap"'; 274 $type = eregi_replace('BINARY', '', $type); 275 $type = eregi_replace('ZEROFILL', '', $type); 276 $type = eregi_replace('UNSIGNED', '', $type); 277 if (empty($type)) { 278 $type = ' '; 279 } 280 281 $binary = eregi('BINARY', $row['Type']); 282 $unsigned = eregi('UNSIGNED', $row['Type']); 283 $zerofill = eregi('ZEROFILL', $row['Type']); 284 } 285 $strAttribute = ' '; 286 if ($binary) { 287 $strAttribute = 'BINARY'; 288 } 289 if ($unsigned) { 290 $strAttribute = 'UNSIGNED'; 291 } 292 if ($zerofill) { 293 $strAttribute = 'UNSIGNED ZEROFILL'; 294 } 295 if (!isset($row['Default'])) { 296 if ($row['Null'] != '') { 297 $row['Default'] = 'NULL'; 298 } 299 } else { 300 $row['Default'] = $row['Default']; 301 } 302 303 $fmt_pre = ''; 304 $fmt_post = ''; 305 if (in_array($row['Field'], $unique_keys)) { 306 $fmt_pre = '<b>' . $fmt_pre; 307 $fmt_post = $fmt_post . '</b>'; 308 } 309 if ($row['Key']=='PRI') { 310 $fmt_pre = '<i>' . $fmt_pre; 311 $fmt_post = $fmt_post . '</i>'; 312 } 313 $schema_insert .= '<td class="print">' . $fmt_pre . htmlspecialchars($row['Field']) . $fmt_post . '</td>'; 314 $schema_insert .= '<td class="print">' . htmlspecialchars($type) . '</td>'; 315 $schema_insert .= '<td class="print">' . htmlspecialchars($row['Null'] == '' ? $GLOBALS['strNo'] : $GLOBALS['strYes']) . '</td>'; 316 $schema_insert .= '<td class="print">' . htmlspecialchars(isset($row['Default']) ? $row['Default'] : '') . '</td>'; 317 318 $field_name = $row['Field']; 319 320 if ($do_relation && $have_rel) { 321 $schema_insert .= '<td class="print">' . (isset($res_rel[$field_name]) ? htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' (' . $res_rel[$field_name]['foreign_field'] . ')') : '') . '</td>'; 322 } 323 if ($do_comments && $cfgRelation['commwork']) { 324 $schema_insert .= '<td class="print">' . ( isset($comments[$field_name]) ? htmlspecialchars($comments[$field_name]) : '') . '</td>'; 325 } 326 if ($do_mime && $cfgRelation['mimework']) { 327 $schema_insert .= '<td class="print">' . ( isset($mime_map[$field_name]) ? htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype'])) : '') . '</td>'; 328 } 329 330 $schema_insert .= '</tr>'; 331 332 if (!PMA_exportOutputHandler($schema_insert)) { 333 return FALSE; 334 } 335 } // end while 336 PMA_DBI_free_result($result); 337 338 return PMA_exportOutputHandler('</table>'); 339 } 340 341 } 342 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 15:18:20 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |