Documentation TYPO3 par Ameos |
00001 <?php 00002 /* $Id: relation.lib.php,v 2.37 2005/07/22 18:00:14 lem9 Exp $ */ 00003 // vim: expandtab sw=4 ts=4 sts=4: 00004 00026 function PMA_query_as_cu($sql, $show_error = TRUE, $options = 0) { 00027 global $err_url_0, $db, $dbh, $cfgRelation; 00028 00029 PMA_DBI_select_db($cfgRelation['db'], $dbh); 00030 if ($show_error) { 00031 $result = PMA_DBI_query($sql, $dbh, $options); 00032 } else { 00033 $result = @PMA_DBI_try_query($sql, $dbh, $options); 00034 } // end if... else... 00035 PMA_DBI_select_db($db, $dbh); 00036 00037 if ($result) { 00038 return $result; 00039 } else { 00040 return FALSE; 00041 } 00042 } // end of the "PMA_query_as_cu()" function 00043 00044 00065 function PMA_getRelationsParam($verbose = FALSE) 00066 { 00067 global $cfg, $server, $err_url_0, $db, $table; 00068 global $cfgRelation; 00069 00070 $cfgRelation = array(); 00071 $cfgRelation['relwork'] = FALSE; 00072 $cfgRelation['displaywork'] = FALSE; 00073 $cfgRelation['bookmarkwork']= FALSE; 00074 $cfgRelation['pdfwork'] = FALSE; 00075 $cfgRelation['commwork'] = FALSE; 00076 $cfgRelation['mimework'] = FALSE; 00077 $cfgRelation['historywork'] = FALSE; 00078 $cfgRelation['allworks'] = FALSE; 00079 00080 // No server selected -> no bookmark table 00081 // we return the array with the FALSEs in it, 00082 // to avoid some 'Unitialized string offset' errors later 00083 if ($server == 0 00084 || empty($cfg['Server']) 00085 || empty($cfg['Server']['pmadb'])) { 00086 if ($verbose == TRUE) { 00087 echo 'PMA Database ... ' 00088 . '<font color="red"><b>' . $GLOBALS['strNotOK'] . '</b></font>' 00089 . '[ <a href="Documentation.html#pmadb">' . $GLOBALS['strDocu'] . '</a> ]<br />' . "\n" 00090 . $GLOBALS['strGeneralRelationFeat'] 00091 . ' <font color="green">' . $GLOBALS['strDisabled'] . '</font>' . "\n"; 00092 } 00093 return $cfgRelation; 00094 } 00095 00096 $cfgRelation['user'] = $cfg['Server']['user']; 00097 $cfgRelation['db'] = $cfg['Server']['pmadb']; 00098 00099 // Now I just check if all tables that i need are present so I can for 00100 // example enable relations but not pdf... 00101 // I was thinking of checking if they have all required columns but I 00102 // fear it might be too slow 00103 // PMA_DBI_select_db($cfgRelation['db']); 00104 00105 $tab_query = 'SHOW TABLES FROM ' . PMA_backquote($cfgRelation['db']); 00106 $tab_rs = PMA_query_as_cu($tab_query, FALSE, PMA_DBI_QUERY_STORE); 00107 00108 if ($tab_rs) { 00109 while ($curr_table = @PMA_DBI_fetch_row($tab_rs)) { 00110 if ($curr_table[0] == $cfg['Server']['bookmarktable']) { 00111 $cfgRelation['bookmark'] = $curr_table[0]; 00112 } else if ($curr_table[0] == $cfg['Server']['relation']) { 00113 $cfgRelation['relation'] = $curr_table[0]; 00114 } else if ($curr_table[0] == $cfg['Server']['table_info']) { 00115 $cfgRelation['table_info'] = $curr_table[0]; 00116 } else if ($curr_table[0] == $cfg['Server']['table_coords']) { 00117 $cfgRelation['table_coords'] = $curr_table[0]; 00118 } else if ($curr_table[0] == $cfg['Server']['column_info']) { 00119 $cfgRelation['column_info'] = $curr_table[0]; 00120 } else if ($curr_table[0] == $cfg['Server']['pdf_pages']) { 00121 $cfgRelation['pdf_pages'] = $curr_table[0]; 00122 } else if ($curr_table[0] == $cfg['Server']['history']) { 00123 $cfgRelation['history'] = $curr_table[0]; 00124 } 00125 } // end while 00126 } 00127 00128 if (isset($cfgRelation['relation'])) { 00129 $cfgRelation['relwork'] = TRUE; 00130 if (isset($cfgRelation['table_info'])) { 00131 $cfgRelation['displaywork'] = TRUE; 00132 } 00133 } 00134 if (isset($cfgRelation['table_coords']) && isset($cfgRelation['pdf_pages'])) { 00135 $cfgRelation['pdfwork'] = TRUE; 00136 } 00137 if (isset($cfgRelation['column_info'])) { 00138 $cfgRelation['commwork'] = TRUE; 00139 00140 if ($cfg['Server']['verbose_check']) { 00141 $mime_query = 'SHOW FIELDS FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info']); 00142 $mime_rs = PMA_query_as_cu($mime_query, FALSE); 00143 00144 $mime_field_mimetype = FALSE; 00145 $mime_field_transformation = FALSE; 00146 $mime_field_transformation_options = FALSE; 00147 while ($curr_mime_field = @PMA_DBI_fetch_row($mime_rs)) { 00148 if ($curr_mime_field[0] == 'mimetype') { 00149 $mime_field_mimetype = TRUE; 00150 } else if ($curr_mime_field[0] == 'transformation') { 00151 $mime_field_transformation = TRUE; 00152 } else if ($curr_mime_field[0] == 'transformation_options') { 00153 $mime_field_transformation_options = TRUE; 00154 } 00155 } 00156 PMA_DBI_free_result($mime_rs); 00157 00158 if ($mime_field_mimetype == TRUE 00159 && $mime_field_transformation == TRUE 00160 && $mime_field_transformation_options == TRUE) { 00161 $cfgRelation['mimework'] = TRUE; 00162 } 00163 } else { 00164 $cfgRelation['mimework'] = TRUE; 00165 } 00166 } 00167 00168 if (isset($cfgRelation['history'])) { 00169 $cfgRelation['historywork'] = TRUE; 00170 } 00171 00172 if (isset($cfgRelation['bookmark'])) { 00173 $cfgRelation['bookmarkwork'] = TRUE; 00174 } 00175 00176 if ($cfgRelation['relwork'] == TRUE && $cfgRelation['displaywork'] == TRUE 00177 && $cfgRelation['pdfwork'] == TRUE && $cfgRelation['commwork'] == TRUE 00178 && $cfgRelation['mimework'] == TRUE && $cfgRelation['historywork'] == TRUE 00179 && $cfgRelation['bookmarkwork'] == TRUE) { 00180 $cfgRelation['allworks'] = TRUE; 00181 } 00182 if ($tab_rs) { 00183 PMA_DBI_free_result($tab_rs); 00184 } else { 00185 $cfg['Server']['pmadb'] = FALSE; 00186 } 00187 00188 if ($verbose == TRUE) { 00189 $shit = '<font color="red"><b>' . $GLOBALS['strNotOK'] . '</b></font> [ <a href="Documentation.html#%s">' . $GLOBALS['strDocu'] . '</a> ]'; 00190 $hit = '<font color="green"><b>' . $GLOBALS['strOK'] . '</b></font>'; 00191 $enabled = '<font color="green">' . $GLOBALS['strEnabled'] . '</font>'; 00192 $disabled = '<font color="red">' . $GLOBALS['strDisabled'] . '</font>'; 00193 00194 echo '<table>' . "\n"; 00195 echo ' <tr><th align="left">$cfg[\'Servers\'][$i][\'pmadb\'] ... </th><td align="right">' 00196 . (($cfg['Server']['pmadb'] == FALSE) ? sprintf($shit, 'pmadb') : $hit) 00197 . '</td></tr>' . "\n"; 00198 echo ' <tr><td> </td></tr>' . "\n"; 00199 00200 echo ' <tr><th align="left">$cfg[\'Servers\'][$i][\'relation\'] ... </th><td align="right">' 00201 . ((isset($cfgRelation['relation'])) ? $hit : sprintf($shit, 'relation')) 00202 . '</td></tr>' . "\n"; 00203 echo ' <tr><td colspan=2 align="center">'. $GLOBALS['strGeneralRelationFeat'] . ': ' 00204 . (($cfgRelation['relwork'] == TRUE) ? $enabled : $disabled) 00205 . '</td></tr>' . "\n"; 00206 echo ' <tr><td> </td></tr>' . "\n"; 00207 00208 echo ' <tr><th align="left">$cfg[\'Servers\'][$i][\'table_info\'] ... </th><td align="right">' 00209 . (($cfgRelation['displaywork'] == FALSE) ? sprintf($shit, 'table_info') : $hit) 00210 . '</td></tr>' . "\n"; 00211 echo ' <tr><td colspan=2 align="center">' . $GLOBALS['strDisplayFeat'] . ': ' 00212 . (($cfgRelation['displaywork'] == TRUE) ? $enabled : $disabled) 00213 . '</td></tr>' . "\n"; 00214 echo ' <tr><td> </td></tr>' . "\n"; 00215 00216 echo ' <tr><th align="left">$cfg[\'Servers\'][$i][\'table_coords\'] ... </th><td align="right">' 00217 . ((isset($cfgRelation['table_coords'])) ? $hit : sprintf($shit, 'table_coords')) 00218 . '</td></tr>' . "\n"; 00219 echo ' <tr><th align="left">$cfg[\'Servers\'][$i][\'pdf_pages\'] ... </th><td align="right">' 00220 . ((isset($cfgRelation['pdf_pages'])) ? $hit : sprintf($shit, 'table_coords')) 00221 . '</td></tr>' . "\n"; 00222 echo ' <tr><td colspan=2 align="center">' . $GLOBALS['strCreatePdfFeat'] . ': ' 00223 . (($cfgRelation['pdfwork'] == TRUE) ? $enabled : $disabled) 00224 . '</td></tr>' . "\n"; 00225 echo ' <tr><td> </td></tr>' . "\n"; 00226 00227 echo ' <tr><th align="left">$cfg[\'Servers\'][$i][\'column_info\'] ... </th><td align="right">' 00228 . ((isset($cfgRelation['column_info'])) ? $hit : sprintf($shit, 'col_com')) 00229 . '</td></tr>' . "\n"; 00230 echo ' <tr><td colspan=2 align="center">' . $GLOBALS['strColComFeat'] . ': ' 00231 . (($cfgRelation['commwork'] == TRUE) ? $enabled : $disabled) 00232 . '</td></tr>' . "\n"; 00233 echo ' <tr><td colspan=2 align="center">' . $GLOBALS['strBookmarkQuery'] . ': ' 00234 . (($cfgRelation['bookmarkwork'] == TRUE) ? $enabled : $disabled) 00235 . '</td></tr>' . "\n"; 00236 echo ' <tr><th align="left">MIME ...</th><td align="right">' 00237 . (($cfgRelation['mimework'] == TRUE) ? $hit : sprintf($shit, 'col_com')) 00238 . '</td></tr>' . "\n"; 00239 00240 if (($cfgRelation['commwork'] == TRUE) && ($cfgRelation['mimework'] != TRUE)) { 00241 echo '<tr><td colspan=2 align="left">' . $GLOBALS['strUpdComTab'] . '</td></tr>' . "\n"; 00242 } 00243 00244 echo ' <tr><th align="left">$cfg[\'Servers\'][$i][\'history\'] ... </th><td align="right">' 00245 . ((isset($cfgRelation['history'])) ? $hit : sprintf($shit, 'history')) 00246 . '</td></tr>' . "\n"; 00247 echo ' <tr><td colspan=2 align="center">' . $GLOBALS['strQuerySQLHistory'] . ': ' 00248 . (($cfgRelation['historywork'] == TRUE) ? $enabled : $disabled) 00249 . '</td></tr>' . "\n"; 00250 00251 echo '</table>' . "\n"; 00252 } // end if ($verbose == TRUE) { 00253 00254 return $cfgRelation; 00255 } // end of the 'PMA_getRelationsParam()' function 00256 00257 00276 function PMA_getForeigners($db, $table, $column = '', $source = 'both') { 00277 global $cfgRelation, $err_url_0; 00278 00279 if ($cfgRelation['relwork'] && ($source == 'both' || $source == 'internal')) { 00280 $rel_query = 'SELECT master_field, foreign_db, foreign_table, foreign_field' 00281 . ' FROM ' . PMA_backquote($cfgRelation['relation']) 00282 . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\' ' 00283 . ' AND master_table = \'' . PMA_sqlAddslashes($table) . '\' '; 00284 if (!empty($column)) { 00285 $rel_query .= ' AND master_field = \'' . PMA_sqlAddslashes($column) . '\''; 00286 } 00287 $relations = PMA_query_as_cu($rel_query); 00288 $i = 0; 00289 while ($relrow = PMA_DBI_fetch_assoc($relations)) { 00290 $field = $relrow['master_field']; 00291 $foreign[$field]['foreign_db'] = $relrow['foreign_db']; 00292 $foreign[$field]['foreign_table'] = $relrow['foreign_table']; 00293 $foreign[$field]['foreign_field'] = $relrow['foreign_field']; 00294 $i++; 00295 } // end while 00296 PMA_DBI_free_result($relations); 00297 unset($relations); 00298 } 00299 00300 if (($source == 'both' || $source == 'innodb') && !empty($table)) { 00301 $show_create_table_query = 'SHOW CREATE TABLE ' 00302 . PMA_backquote($db) . '.' . PMA_backquote($table); 00303 $show_create_table_res = PMA_DBI_query($show_create_table_query); 00304 list(,$show_create_table) = PMA_DBI_fetch_row($show_create_table_res); 00305 PMA_DBI_free_result($show_create_table_res); 00306 unset($show_create_table_res, $show_create_table_query); 00307 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table)); 00308 00309 foreach ($analyzed_sql[0]['foreign_keys'] AS $one_key) { 00310 00311 // the analyzer may return more than one column name in the 00312 // index list or the ref_index_list 00313 foreach ($one_key['index_list'] AS $i => $field) { 00314 00315 // If a foreign key is defined in the 'internal' source (pmadb) 00316 // and in 'innodb', we won't get it twice if $source='both' 00317 // because we use $field as key 00318 00319 // The parser looks for a CONSTRAINT clause just before 00320 // the FOREIGN KEY clause. It finds it (as output from 00321 // SHOW CREATE TABLE) in MySQL 4.0.13, but not in older 00322 // versions like 3.23.58. 00323 // In those cases, the FOREIGN KEY parsing will put numbers 00324 // like -1, 0, 1... instead of the constraint number. 00325 00326 if (isset($one_key['constraint'])) { 00327 $foreign[$field]['constraint'] = $one_key['constraint']; 00328 } 00329 00330 if (isset($one_key['ref_db_name'])) { 00331 $foreign[$field]['foreign_db'] = $one_key['ref_db_name']; 00332 } else { 00333 $foreign[$field]['foreign_db'] = $db; 00334 } 00335 $foreign[$field]['foreign_table'] = $one_key['ref_table_name']; 00336 $foreign[$field]['foreign_field'] = $one_key['ref_index_list'][$i]; 00337 if (isset($one_key['on_delete'])) { 00338 $foreign[$field]['on_delete'] = $one_key['on_delete']; 00339 } 00340 if (isset($one_key['on_update'])) { 00341 $foreign[$field]['on_update'] = $one_key['on_update']; 00342 } 00343 } 00344 } 00345 } 00346 00350 if (PMA_MYSQL_INT_VERSION >= 50002 && $db == 'information_schema' 00351 && ($source == 'internal' || $source == 'both')) { 00352 00353 require_once('./libraries/information_schema_relations.lib.php'); 00354 00355 if (!isset($foreign)) { 00356 $foreign = array(); 00357 } 00358 00359 if (isset($GLOBALS['information_schema_relations'][$table])) { 00360 foreach ($GLOBALS['information_schema_relations'][$table] as $field => $relations) { 00361 if ((empty($column) || $column == $field) && empty($foreign[$field])) { 00362 $foreign[$field] = $relations; 00363 } 00364 } 00365 } 00366 } 00367 00368 if (!empty($foreign) && is_array($foreign)) { 00369 return $foreign; 00370 } else { 00371 return FALSE; 00372 } 00373 00374 } // end of the 'PMA_getForeigners()' function 00375 00376 00391 function PMA_getDisplayField($db, $table) { 00392 global $cfgRelation; 00393 00397 if (trim(@$cfgRelation['table_info']) != '') { 00398 00399 $disp_query = 'SELECT display_field FROM ' . PMA_backquote($cfgRelation['table_info']) 00400 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' 00401 . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''; 00402 00403 $disp_res = PMA_query_as_cu($disp_query); 00404 $row = ($disp_res ? PMA_DBI_fetch_assoc($disp_res) : ''); 00405 PMA_DBI_free_result($disp_res); 00406 if (isset($row['display_field'])) { 00407 return $row['display_field']; 00408 } 00409 00410 } 00411 00415 if (PMA_MYSQL_INT_VERSION >= 50002 && $db == 'information_schema') { 00416 switch ($table) { 00417 case 'CHARACTER_SETS': return 'DESCRIPTION'; 00418 case 'TABLES': return 'TABLE_COMMENT'; 00419 } 00420 } 00421 00425 return FALSE; 00426 00427 } // end of the 'PMA_getDisplayField()' function 00428 00429 00445 function PMA_getComments($db, $table = '') { 00446 global $cfgRelation; 00447 00448 if ($table != '') { 00449 00450 // MySQL 4.1.x native column comments 00451 if (PMA_MYSQL_INT_VERSION >= 40100) { 00452 $fields = PMA_DBI_get_fields($db, $table); 00453 if ($fields) { 00454 foreach($fields as $key=>$field) { 00455 $tmp_col = $field['Field']; 00456 if (!empty($field['Comment'])) { 00457 $native_comment[$tmp_col] = $field['Comment']; 00458 } 00459 } 00460 } 00461 } 00462 00463 // pmadb internal column comments 00464 // (this function can be called even if $cfgRelation['commwork'] is 00465 // FALSE, to get native column comments, so recheck here) 00466 if ($cfgRelation['commwork']) { 00467 $com_qry = 'SELECT column_name, comment FROM ' . PMA_backquote($cfgRelation['db']) . '.' .PMA_backquote($cfgRelation['column_info']) 00468 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' 00469 . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''; 00470 $com_rs = PMA_query_as_cu($com_qry, TRUE, PMA_DBI_QUERY_STORE); 00471 } 00472 } else { 00473 // pmadb internal db comments 00474 $com_qry = 'SELECT ' . PMA_backquote('comment') . ' FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info']) 00475 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' 00476 . ' AND table_name = \'\'' 00477 . ' AND column_name = \'(db_comment)\''; 00478 $com_rs = PMA_query_as_cu($com_qry, TRUE, PMA_DBI_QUERY_STORE); 00479 } 00480 00481 00482 if (isset($com_rs) && PMA_DBI_num_rows($com_rs) > 0) { 00483 $i = 0; 00484 while ($row = PMA_DBI_fetch_assoc($com_rs)) { 00485 $i++; 00486 $col = ($table != '' ? $row['column_name'] : $i); 00487 00488 if (strlen($row['comment']) > 0) { 00489 $comment[$col] = $row['comment']; 00490 // if this version supports native comments and this function 00491 // was called with a table parameter 00492 if (PMA_MYSQL_INT_VERSION >= 40100 && !empty($table)) { 00493 // if native comment found, use it instead of pmadb 00494 if (!empty($native_comment[$col])) { 00495 $comment[$col] = $native_comment[$col]; 00496 } else { 00497 // no native comment, so migrate pmadb-style to native 00498 PMA_setComment($db, $table, $col, $comment[$col],'','native'); 00499 // and erase the pmadb-style comment 00500 PMA_setComment($db, $table, $col, '','','pmadb'); 00501 } 00502 } 00503 } 00504 } // end while 00505 00506 PMA_DBI_free_result($com_rs); 00507 unset($com_rs); 00508 } else { 00509 if (isset($native_comment)) { 00510 $comment = $native_comment; 00511 } 00512 } 00513 00514 if (isset($comment) && is_array($comment)) { 00515 return $comment; 00516 } else { 00517 return FALSE; 00518 } 00519 } // end of the 'PMA_getComments()' function 00520 00530 function PMA_handleSlashes($val) { 00531 return (get_magic_quotes_gpc() ? str_replace('\\"', '"', $val) : PMA_sqlAddslashes($val)); 00532 } // end of the "PMA_handleSlashes()" function 00533 00550 function PMA_setComment($db, $table, $col, $comment, $removekey = '', $mode='auto') { 00551 global $cfgRelation; 00552 00553 if ($mode=='auto') { 00554 if (PMA_MYSQL_INT_VERSION >= 40100) { 00555 $mode='native'; 00556 } else { 00557 $mode='pmadb'; 00558 } 00559 } 00560 00561 // native mode is only for column comments so we need a table name 00562 if ($mode == 'native' && !empty($table)) { 00563 $fields = PMA_DBI_get_fields($db, $table); 00564 00565 00566 // Get more complete field information 00567 // For now, this is done just for MySQL 4.1.2+ new TIMESTAMP options 00568 // but later, if the analyser returns more information, it 00569 // could be executed for any MySQL version and replace 00570 // the info given by SHOW FULL FIELDS FROM. 00571 // TODO: put this code into a require() 00572 // or maybe make it part of PMA_DBI_get_fields(); 00573 00574 if (PMA_MYSQL_INT_VERSION >= 40102) { 00575 $show_create_table_query = 'SHOW CREATE TABLE ' 00576 . PMA_backquote($db) . '.' . PMA_backquote($table); 00577 $show_create_table_res = PMA_DBI_query($show_create_table_query); 00578 list(,$show_create_table) = PMA_DBI_fetch_row($show_create_table_res); 00579 PMA_DBI_free_result($show_create_table_res); 00580 unset($show_create_table_res, $show_create_table_query); 00581 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table)); 00582 } 00583 00584 // TODO: get directly the information of $col 00585 foreach($fields as $key=>$field) { 00586 $tmp_col = $field['Field']; 00587 $types[$tmp_col] = $field['Type']; 00588 $collations[$tmp_col] = $field['Collation']; 00589 $nulls[$tmp_col] = $field['Null']; 00590 $defaults[$tmp_col] = $field['Default']; 00591 $extras[$tmp_col] = $field['Extra']; 00592 00593 if (PMA_MYSQL_INT_VERSION >= 40102 && isset($analyzed_sql[0]['create_table_fields'][$tmp_col]['on_update_current_timestamp'])) { 00594 $extras[$tmp_col] = 'ON UPDATE CURRENT_TIMESTAMP'; 00595 } 00596 00597 if (PMA_MYSQL_INT_VERSION >= 40102 && isset($analyzed_sql[0]['create_table_fields'][$tmp_col]['default_current_timestamp'])) { 00598 $default_current_timestamps[$tmp_col] = TRUE; 00599 } else { 00600 $default_current_timestamps[$tmp_col] = FALSE; 00601 } 00602 00603 if ($tmp_col == $col) { 00604 break; 00605 } 00606 } 00607 if ($nulls[$col] == 'YES') { 00608 $nulls[$col] = ''; 00609 } else { 00610 $nulls[$col] = 'NOT NULL'; 00611 } 00612 00613 $query = 'ALTER TABLE ' . PMA_backquote($table) . ' CHANGE ' 00614 . PMA_generateAlterTable($col, $col, $types[$col], $collations[$col], $nulls[$col], $defaults[$col], $default_current_timestamps[$col], $extras[$col], $comment); 00615 00616 PMA_DBI_try_query($query, NULL, PMA_DBI_QUERY_STORE); 00617 return TRUE; 00618 } 00619 00620 // $mode == 'pmadb' section: 00621 00622 $cols = array( 00623 'db_name' => 'db_name ', 00624 'table_name' => 'table_name ', 00625 'column_name' => 'column_name' 00626 ); 00627 00628 if ($removekey != '' AND $removekey != $col) { 00629 $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['column_info']) 00630 . ' WHERE ' . $cols['db_name'] . ' = \'' . PMA_sqlAddslashes($db) . '\'' 00631 . ' AND ' . $cols['table_name'] . ' = \'' . PMA_sqlAddslashes($table) . '\'' 00632 . ' AND ' . $cols['column_name'] . ' = \'' . PMA_sqlAddslashes($removekey) . '\''; 00633 PMA_query_as_cu($remove_query); 00634 unset($remove_query); 00635 } 00636 00637 $test_qry = 'SELECT ' . PMA_backquote('comment') . ', mimetype, transformation, transformation_options FROM ' . PMA_backquote($cfgRelation['column_info']) 00638 . ' WHERE ' . $cols['db_name'] . ' = \'' . PMA_sqlAddslashes($db) . '\'' 00639 . ' AND ' . $cols['table_name'] . ' = \'' . PMA_sqlAddslashes($table) . '\'' 00640 . ' AND ' . $cols['column_name'] . ' = \'' . PMA_sqlAddslashes($col) . '\''; 00641 $test_rs = PMA_query_as_cu($test_qry, TRUE, PMA_DBI_QUERY_STORE); 00642 00643 if ($test_rs && PMA_DBI_num_rows($test_rs) > 0) { 00644 $row = PMA_DBI_fetch_assoc($test_rs); 00645 PMA_DBI_free_result($test_rs); 00646 00647 if (strlen($comment) > 0 || strlen($row['mimetype']) > 0 || strlen($row['transformation']) > 0 || strlen($row['transformation_options']) > 0) { 00648 $upd_query = 'UPDATE ' . PMA_backquote($cfgRelation['column_info']) 00649 . ' SET ' . PMA_backquote('comment') . ' = \'' . PMA_sqlAddslashes($comment) . '\'' 00650 . ' WHERE ' . $cols['db_name'] . ' = \'' . PMA_sqlAddslashes($db) . '\'' 00651 . ' AND ' . $cols['table_name'] . ' = \'' . PMA_sqlAddslashes($table) . '\'' 00652 . ' AND ' . $cols['column_name'] . ' = \'' . PMA_sqlAddSlashes($col) . '\''; 00653 } else { 00654 $upd_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['column_info']) 00655 . ' WHERE ' . $cols['db_name'] . ' = \'' . PMA_sqlAddslashes($db) . '\'' 00656 . ' AND ' . $cols['table_name'] . ' = \'' . PMA_sqlAddslashes($table) . '\'' 00657 . ' AND ' . $cols['column_name'] . ' = \'' . PMA_sqlAddslashes($col) . '\''; 00658 } 00659 } else if (strlen($comment) > 0) { 00660 $upd_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['column_info']) 00661 . ' (db_name, table_name, column_name, ' . PMA_backquote('comment') . ') ' 00662 . ' VALUES(' 00663 . '\'' . PMA_sqlAddslashes($db) . '\',' 00664 . '\'' . PMA_sqlAddslashes($table) . '\',' 00665 . '\'' . PMA_sqlAddslashes($col) . '\',' 00666 . '\'' . PMA_sqlAddslashes($comment) . '\')'; 00667 } 00668 00669 if (isset($upd_query)){ 00670 $upd_rs = PMA_query_as_cu($upd_query); 00671 unset($upd_query); 00672 return true; 00673 } else { 00674 return false; 00675 } 00676 } // end of 'PMA_setComment()' function 00677 00692 function PMA_setHistory($db, $table, $username, $sqlquery) { 00693 global $cfgRelation; 00694 00695 $hist_rs = PMA_query_as_cu('INSERT INTO ' . PMA_backquote($cfgRelation['history']) . ' (' 00696 . PMA_backquote('username') . ',' 00697 . PMA_backquote('db') . ',' 00698 . PMA_backquote('table') . ',' 00699 . PMA_backquote('timevalue') . ',' 00700 . PMA_backquote('sqlquery') 00701 . ') VALUES (' 00702 . '\'' . PMA_sqlAddslashes($username) . '\',' 00703 . '\'' . PMA_sqlAddslashes($db) . '\',' 00704 . '\'' . PMA_sqlAddslashes($table) . '\',' 00705 . 'NOW(),' 00706 . '\'' . PMA_sqlAddslashes($sqlquery) . '\')'); 00707 return true; 00708 } // end of 'PMA_setHistory()' function 00709 00721 function PMA_getHistory($username) { 00722 global $cfgRelation; 00723 00724 $hist_query = 'SELECT ' 00725 . PMA_backquote('db') . ',' 00726 . PMA_backquote('table') . ',' 00727 . PMA_backquote('sqlquery') 00728 . ' FROM ' . PMA_backquote($cfgRelation['history']) 00729 . ' WHERE username = \'' . PMA_sqlAddslashes($username) . '\'' 00730 . ' ORDER BY id DESC'; 00731 00732 $hist_rs = PMA_query_as_cu($hist_query); 00733 unset($hist_query); 00734 00735 $history = array(); 00736 00737 while ($row = PMA_DBI_fetch_assoc($hist_rs)) { 00738 $history[] = $row; 00739 } 00740 PMA_DBI_free_result($hist_rs); 00741 00742 return $history; 00743 00744 } // end of 'PMA_getHistory()' function 00745 00761 function PMA_purgeHistory($username) { 00762 global $cfgRelation, $cfg; 00763 00764 $purge_query = 'SELECT timevalue FROM ' . PMA_backquote($cfgRelation['history']) 00765 . ' WHERE username = \'' . PMA_sqlAddSlashes($username) . '\'' 00766 . ' ORDER BY timevalue DESC LIMIT ' . $cfg['QueryHistoryMax'] . ', 1'; 00767 $purge_rs = PMA_query_as_cu($purge_query); 00768 $i = 0; 00769 $row = PMA_DBI_fetch_row($purge_rs); 00770 PMA_DBI_free_result($purge_rs); 00771 00772 if (is_array($row) && isset($row[0]) && $row[0] > 0) { 00773 $maxtime = $row[0]; 00774 // quotes added around $maxtime to prevent a difficult to 00775 // reproduce problem 00776 $remove_rs = PMA_query_as_cu('DELETE FROM ' . PMA_backquote($cfgRelation['history']) . ' WHERE timevalue <= "' . $maxtime . '"'); 00777 } 00778 00779 return true; 00780 } // end of 'PMA_purgeHistory()' function 00781 00796 function PMA_foreignDropdown($disp, $foreign_field, $foreign_display, $data, $max) { 00797 global $cfg; 00798 00799 $ret = '<option value=""></option>' . "\n"; 00800 00801 $reloptions = array('content-id' => array(), 'id-content' => array()); 00802 00803 foreach ($disp AS $disp_key => $relrow) { 00804 $key = $relrow[$foreign_field]; 00805 00806 // if the display field has been defined for the foreign table 00807 if ($foreign_display) { 00808 if (PMA_strlen($relrow[$foreign_display]) <= $cfg['LimitChars']) { 00809 $value = htmlspecialchars($relrow[$foreign_display]); 00810 $vtitle = ''; 00811 } else { 00812 $vtitle = htmlspecialchars($relrow[$foreign_display]); 00813 $value = htmlspecialchars(substr($vtitle, 0, $cfg['LimitChars']) . '...'); 00814 } 00815 } else { 00816 $vtitle = $value = ''; 00817 } // end if ($foreign_display) 00818 00819 $reloption = '<option value="' . htmlspecialchars($key) . '"'; 00820 if ($vtitle != '') { 00821 $reloption .= ' title="' . $vtitle . '"'; 00822 } 00823 00824 if ($key == $data) { 00825 $reloption .= ' selected="selected"'; 00826 } // end if 00827 00828 $reloptions['content-id'][] = $reloption . '>' . $value . ' - ' . htmlspecialchars($key) . '</option>' . "\n"; 00829 $reloptions['id-content'][] = $reloption . '>' . htmlspecialchars($key) . ' - ' . $value . '</option>' . "\n"; 00830 } // end while 00831 00832 // the list of keys looks better if not sorted by description 00833 if ($cfg['NaturalOrder']) { 00834 natsort($reloptions['content-id']); } 00835 else { 00836 asort($reloptions['content-id']); 00837 } 00838 00839 $c = count($cfg['ForeignKeyDropdownOrder']); 00840 if($c == 2) { 00841 $top = $reloptions[$cfg['ForeignKeyDropdownOrder'][0]]; 00842 $bot = $reloptions[$cfg['ForeignKeyDropdownOrder'][1]]; 00843 } elseif($c == 1) { 00844 $bot = $reloptions[$cfg['ForeignKeyDropdownOrder'][0]]; 00845 $top = NULL; 00846 } else { 00847 $top = $reloptions['id-content']; 00848 $bot = $reloptions['content-id']; 00849 } 00850 $str_bot = implode('', $bot); 00851 if($top !== NULL) { 00852 $str_top = implode('', $top); 00853 $top_count = count($top); 00854 if ($max == -1 || $top_count < $max) { 00855 $ret .= $str_top; 00856 if ($top_count > 0) { 00857 $ret .= '<option value=""></option>' . "\n"; 00858 $ret .= '<option value=""></option>' . "\n"; 00859 } 00860 } 00861 } 00862 $ret .= $str_bot; 00863 00864 return $ret; 00865 } // end of 'PMA_foreignDropdown()' function 00866 00867 ?>