diff options
97 files changed, 4482 insertions, 3985 deletions
@@ -17,6 +17,7 @@ $Source$ - clarified some variable names * db_sarch.php: fixed bug: Undefined variable: num_tables + * [really much files]: (not complete) PEAR coding standard 2006-01-16 Marc Delisle <lem9@users.sourceforge.net> * server_privileges.php: typo diff --git a/db_datadict.php b/db_datadict.php index 0f0746c354..b16cd6c80d 100644 --- a/db_datadict.php +++ b/db_datadict.php @@ -52,7 +52,7 @@ if ($cfgRelation['commwork']) { * Selects the database and gets tables names */ PMA_DBI_select_db($db); -$rowset = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($db) . ';', NULL, PMA_DBI_QUERY_STORE); +$rowset = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($db) . ';', null, PMA_DBI_QUERY_STORE); $count = 0; while ($row = PMA_DBI_fetch_assoc($rowset)) { @@ -128,7 +128,7 @@ while ($row = PMA_DBI_fetch_assoc($rowset)) { /** * Gets fields properties */ - $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';', NULL, PMA_DBI_QUERY_STORE); + $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE); $fields_cnt = PMA_DBI_num_rows($result); // Check if we can use Relations (Mike Beck) if (!empty($cfgRelation['relation'])) { @@ -141,8 +141,7 @@ while ($row = PMA_DBI_fetch_assoc($rowset)) { } else { $have_rel = FALSE; } - } - else { + } else { $have_rel = FALSE; } // end if @@ -237,7 +236,7 @@ while ($row = PMA_DBI_fetch_assoc($rowset)) { <td<?php echo $type_nowrap; ?> xml:lang="en" dir="ltr"><?php echo $type; ?></td> <?php /* <td<?php echo $type_nowrap; ?>><?php echo $strAttribute; ?></td>*/ ?> <td><?php echo (($row['Null'] == '' || $row['Null'] == 'NO') ? $strNo : $strYes); ?></td> - <td nowrap="nowrap"><?php if (isset($row['Default'])) echo $row['Default']; ?></td> + <td nowrap="nowrap"><?php if (isset($row['Default'])) { echo $row['Default']; } ?></td> <?php /* <td<?php echo $type_nowrap; ?>><?php echo $row['Extra']; ?></td>*/ ?> <?php if ($have_rel) { diff --git a/db_details_importdocsql.php b/db_details_importdocsql.php index a60a240693..38c3c1c746 100644 --- a/db_details_importdocsql.php +++ b/db_details_importdocsql.php @@ -62,7 +62,7 @@ if (isset($cfg['docSQLDir']) && !empty($cfg['docSQLDir'])) { if (isset($lines) && is_array($lines) && count($lines) > 0) { foreach ($lines AS $lkey => $line) { //echo '<p>' . $line . '</p>'; - $inf = explode('|',$line); + $inf = explode('|', $line); if (!empty($inf[1]) && strlen(trim($inf[1])) > 0) { $qry = ' INSERT INTO @@ -125,14 +125,11 @@ if (isset($cfg['docSQLDir']) && !empty($cfg['docSQLDir'])) { if (empty($DOCUMENT_ROOT)) { if (!empty($_SERVER) && isset($_SERVER['DOCUMENT_ROOT'])) { $DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT']; - } - else if (!empty($_ENV) && isset($_ENV['DOCUMENT_ROOT'])) { + } elseif (!empty($_ENV) && isset($_ENV['DOCUMENT_ROOT'])) { $DOCUMENT_ROOT = $_ENV['DOCUMENT_ROOT']; - } - else if (@getenv('DOCUMENT_ROOT')) { + } elseif (@getenv('DOCUMENT_ROOT')) { $DOCUMENT_ROOT = getenv('DOCUMENT_ROOT'); - } - else { + } else { $DOCUMENT_ROOT = '.'; } } // end if @@ -173,15 +170,13 @@ if (isset($cfg['docSQLDir']) && !empty($cfg['docSQLDir'])) { echo $strFileCouldNotBeRead; exit(); } - } - else { + } else { $sql_file_new = $tmp_subdir . basename($sql_file); move_uploaded_file($sql_file, $sql_file_new); $docsql_text = PMA_readFile($sql_file_new, $sql_file_compression); unlink($sql_file_new); } - } - else { + } else { // read from the normal upload dir $docsql_text = PMA_readFile($sql_file, $sql_file_compression); } @@ -228,7 +223,7 @@ if (isset($cfg['docSQLDir']) && !empty($cfg['docSQLDir'])) { */ ?> - <form method="post" action="db_details_importdocsql.php" <?php if ($is_upload) echo ' enctype="multipart/form-data"'; ?>> + <form method="post" action="db_details_importdocsql.php" <?php if ($is_upload) { echo ' enctype="multipart/form-data"'; } ?>> <?php echo PMA_generate_common_hidden_inputs($db); ?> <input type="hidden" name="submit_show" value="true" /> <input type="hidden" name="do" value="import" /> diff --git a/db_details_structure.php b/db_details_structure.php index 061f09b30f..fe7a71727b 100644 --- a/db_details_structure.php +++ b/db_details_structure.php @@ -152,7 +152,7 @@ $row_count = 0; $hidden_fields = array(); $odd_row = true; foreach ( $tables as $keyname => $each_table ) { - if ( $each_table['TABLE_ROWS'] === NULL || $each_table['TABLE_ROWS'] < $GLOBALS['cfg']['MaxExactCount']) { + if ( $each_table['TABLE_ROWS'] === null || $each_table['TABLE_ROWS'] < $GLOBALS['cfg']['MaxExactCount']) { $each_table['TABLE_ROWS'] = PMA_countRecords( $db, $each_table['TABLE_NAME'], $return = true, $force_exact = true ); } @@ -452,21 +452,21 @@ echo ' <option value="' . $strAnalyzeTable . '" >' /* Printable view of a table */ echo '<p>'; echo '<a href="db_printview.php?' . $url_query . '">'; -if ( $cfg['PropertiesIconic'] ) { +if ($cfg['PropertiesIconic']) { echo '<img class="icon" src="' . $pmaThemeImage .'b_print.png" width="16" height="16" alt="" />'; } echo $strPrintView . '</a> '; echo '<a href="./db_datadict.php?' . $url_query . '">'; -if($cfg['PropertiesIconic']){ +if ($cfg['PropertiesIconic']) { echo '<img class="icon" src="' . $pmaThemeImage .'b_tblanalyse.png" width="16" height="16" alt="" />'; } echo $strDataDict . '</a>'; echo '</p>'; -if ( empty( $db_is_information_schema ) ) { +if (empty($db_is_information_schema)) { require('./libraries/display_create_table.lib.php'); } // end if (Create Table dialog) diff --git a/db_operations.php b/db_operations.php index 3f3788b7dd..575b39134a 100644 --- a/db_operations.php +++ b/db_operations.php @@ -80,7 +80,7 @@ if (isset($db) && // Duplicate the bookmarks for this db (done once for each db) if ($db != $newname) { - $get_fields = array('user','label','query'); + $get_fields = array('user', 'label', 'query'); $where_fields = array('dbase' => $db); $new_fields = array('dbase' => $newname); PMA_duplicate_table_info('bookmarkwork', 'bookmark', $get_fields, @@ -332,7 +332,7 @@ if ($cfgRelation['pdfwork'] && $num_tables > 0) { ?> SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages']) . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\''; - $test_rs = PMA_query_as_cu($test_query, NULL, PMA_DBI_QUERY_STORE); + $test_rs = PMA_query_as_cu($test_query, null, PMA_DBI_QUERY_STORE); if ($test_rs && PMA_DBI_num_rows($test_rs) > 0) { ?> <!-- PDF schema --> diff --git a/db_printview.php b/db_printview.php index 09ac084bdc..46d5ae6ca9 100644 --- a/db_printview.php +++ b/db_printview.php @@ -44,7 +44,7 @@ if ($cfg['SkipLockedTables'] == TRUE) { unset($result); if (isset($sot_cache)) { - $result = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($db) . ';', NULL, PMA_DBI_QUERY_STORE); + $result = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($db) . ';', null, PMA_DBI_QUERY_STORE); if ($result != FALSE && PMA_DBI_num_rows($result) > 0) { while ($tmp = PMA_DBI_fetch_row($result)) { if (!isset($sot_cache[$tmp[0]])) { @@ -134,7 +134,7 @@ else { if (isset($sts_data['Type'])) { if ($sts_data['Type'] == 'MRG_MyISAM') { $mergetable = TRUE; - } else if (!preg_match('@ISAM|HEAP@i', $sts_data['Type'])) { + } elseif (!preg_match('@ISAM|HEAP@i', $sts_data['Type'])) { $nonisam = TRUE; } } @@ -149,18 +149,17 @@ else { } else { list($formated_size, $unit) = PMA_formatByteDown($tblsize, 3, 0); } - } else if ($cfg['ShowStats']) { + } elseif ($cfg['ShowStats']) { $formated_size = ' - '; $unit = ''; } $sum_entries += $sts_data['Rows']; } // MyISAM MERGE Table - else if ($cfg['ShowStats'] && $mergetable == TRUE) { + elseif ($cfg['ShowStats'] && $mergetable == TRUE) { $formated_size = ' - '; $unit = ''; - } - else if ($cfg['ShowStats']) { + } elseif ($cfg['ShowStats']) { $formated_size = 'unknown'; $unit = ''; } @@ -59,10 +59,11 @@ header('Content-Type: text/html; charset=' . $charset); <body> <h1>phpMyAdmin - <?php echo $type; ?></h1> <p><?php -if (get_magic_quotes_gpc()) +if (get_magic_quotes_gpc()) { echo PMA_sanitize(stripslashes($_REQUEST['error'])); -else +} else { echo PMA_sanitize($_REQUEST['error']); +} ?></p> </body> </html> diff --git a/export.php b/export.php index 3f3de6544a..a9d03fc5c9 100644 --- a/export.php +++ b/export.php @@ -80,7 +80,7 @@ function PMA_exportOutputHandler($line) $dump_buffer = bzcompress($dump_buffer); } // as a gzipped file - else if ($GLOBALS['compression'] == 'gzip' && @function_exists('gzencode')) { + elseif ($GLOBALS['compression'] == 'gzip' && @function_exists('gzencode')) { // without the optional parameter level because it bug $dump_buffer = gzencode($dump_buffer); } @@ -172,17 +172,26 @@ $onfly_compression = $GLOBALS['cfg']['CompressOnFly'] && isset($compression) && if ($onfly_compression) { $memory_limit = trim(@ini_get('memory_limit')); // 2 MB as default - if (empty($memory_limit)) $memory_limit = 2 * 1024 * 1024; + if (empty($memory_limit)) { + $memory_limit = 2 * 1024 * 1024; + } - if (strtolower(substr($memory_limit, -1)) == 'm') $memory_limit = (int)substr($memory_limit, 0, -1) * 1024 * 1024; - elseif (strtolower(substr($memory_limit, -1)) == 'k') $memory_limit = (int)substr($memory_limit, 0, -1) * 1024; - elseif (strtolower(substr($memory_limit, -1)) == 'g') $memory_limit = (int)substr($memory_limit, 0, -1) * 1024 * 1024 * 1024; - else $memory_limit = (int)$memory_limit; + if (strtolower(substr($memory_limit, -1)) == 'm') { + $memory_limit = (int)substr($memory_limit, 0, -1) * 1024 * 1024; + } elseif (strtolower(substr($memory_limit, -1)) == 'k') { + $memory_limit = (int)substr($memory_limit, 0, -1) * 1024; + } elseif (strtolower(substr($memory_limit, -1)) == 'g') { + $memory_limit = (int)substr($memory_limit, 0, -1) * 1024 * 1024 * 1024; + } else { + $memory_limit = (int)$memory_limit; + } // Some of memory is needed for other thins and as treshold. // Nijel: During export I had allocated (see memory_get_usage function) // approx 1.2MB so this comes from that. - if ($memory_limit > 1500000) $memory_limit -= 1500000; + if ($memory_limit > 1500000) { + $memory_limit -= 1500000; + } // Some memory is needed for compression, assume 1/3 $memory_limit *= 2/3; @@ -193,17 +202,17 @@ if ($asfile) { $pma_uri_parts = parse_url($cfg['PmaAbsoluteUri']); if ($export_type == 'server') { if (isset($remember_template)) { - setcookie('pma_server_filename_template', $filename_template , 0, $GLOBALS['cookie_path'], '' , $GLOBALS['is_https']); + setcookie('pma_server_filename_template', $filename_template, 0, $GLOBALS['cookie_path'], '', $GLOBALS['is_https']); } $filename = str_replace('__SERVER__', $GLOBALS['cfg']['Server']['host'], strftime($filename_template)); } elseif ($export_type == 'database') { if (isset($remember_template)) { - setcookie('pma_db_filename_template', $filename_template , 0, $GLOBALS['cookie_path'], '' , $GLOBALS['is_https']); + setcookie('pma_db_filename_template', $filename_template, 0, $GLOBALS['cookie_path'], '', $GLOBALS['is_https']); } $filename = str_replace('__DB__', $db, str_replace('__SERVER__', $GLOBALS['cfg']['Server']['host'], strftime($filename_template))); } else { if (isset($remember_template)) { - setcookie('pma_table_filename_template', $filename_template , 0, $GLOBALS['cookie_path'], '' , $GLOBALS['is_https']); + setcookie('pma_table_filename_template', $filename_template, 0, $GLOBALS['cookie_path'], '', $GLOBALS['is_https']); } $filename = str_replace('__TABLE__', $table, str_replace('__DB__', $db, str_replace('__SERVER__', $GLOBALS['cfg']['Server']['host'], strftime($filename_template)))); } @@ -219,22 +228,22 @@ if ($asfile) { if ($type == 'csv') { $filename .= '.csv'; $mime_type = 'text/comma-separated-values'; - } else if ($type == 'htmlexcel') { + } elseif ($type == 'htmlexcel') { $filename .= '.xls'; $mime_type = 'application/vnd.ms-excel'; - } else if ($type == 'htmlword') { + } elseif ($type == 'htmlword') { $filename .= '.doc'; $mime_type = 'application/vnd.ms-word'; - } else if ($type == 'xls') { + } elseif ($type == 'xls') { $filename .= '.xls'; $mime_type = 'application/vnd.ms-excel'; - } else if ($type == 'xml') { + } elseif ($type == 'xml') { $filename .= '.xml'; $mime_type = 'text/xml'; - } else if ($type == 'latex') { + } elseif ($type == 'latex') { $filename .= '.tex'; $mime_type = 'application/x-tex'; - } else if ($type == 'pdf') { + } elseif ($type == 'pdf') { $filename .= '.pdf'; $mime_type = 'application/pdf'; } else { @@ -255,7 +264,7 @@ if ($asfile) { // browsers don't like this: //$content_encoding = 'x-bzip2'; $mime_type = 'application/x-bzip2'; - } else if (isset($compression) && $compression == 'gzip') { + } elseif (isset($compression) && $compression == 'gzip') { $filename .= '.gz'; // Needed to avoid recompression by server modules like mod_gzip. // It seems necessary to check about zlib.output_compression @@ -264,7 +273,7 @@ if ($asfile) { $content_encoding = 'x-gzip'; $mime_type = 'application/x-gzip'; } - } else if (isset($compression) && $compression == 'zip') { + } elseif (isset($compression) && $compression == 'zip') { $filename .= '.zip'; $mime_type = 'application/zip'; } @@ -272,7 +281,7 @@ if ($asfile) { // Open file on server if needed if ($save_on_server) { - $save_filename = PMA_userDir($cfg['SaveDir']) . preg_replace('@[/\\\\]@','_',$filename); + $save_filename = PMA_userDir($cfg['SaveDir']) . preg_replace('@[/\\\\]@', '_', $filename); unset($message); if (file_exists($save_filename) && empty($onserverover)) { $message = sprintf($strFileAlreadyExists, htmlspecialchars($save_filename)); @@ -317,9 +326,9 @@ if (!$save_on_server) { } header('Content-Type: ' . $mime_type); header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT'); - // lem9: Tested behavior of + // lem9: Tested behavior of // IE 5.50.4807.2300 - // IE 6.0.2800.1106 (small glitch, asks twice when I click Open) + // IE 6.0.2800.1106 (small glitch, asks twice when I click Open) // IE 6.0.2900.2180 // Firefox 1.0.6 // in http and https @@ -374,7 +383,9 @@ if ($export_type == 'database') { do { // Add possibly some comments to export -if (!PMA_exportHeader()) break; +if (!PMA_exportHeader()) { + break; +} // Will we need relation & co. setup? $do_relation = isset($GLOBALS[$what . '_relation']); @@ -411,29 +422,35 @@ if ($export_type == 'server') { foreach ($dblist AS $current_db) { if ((isset($tmp_select) && strpos(' ' . $tmp_select, '|' . $current_db . '|')) || !isset($tmp_select)) { - if (!PMA_exportDBHeader($current_db)) + if (!PMA_exportDBHeader($current_db)) { break 2; - if (!PMA_exportDBCreate($current_db)) + } + if (!PMA_exportDBCreate($current_db)) { break 2; + } $tables = PMA_DBI_get_tables($current_db); foreach ($tables as $table) { $local_query = 'SELECT * FROM ' . PMA_backquote($current_db) . '.' . PMA_backquote($table); if (isset($GLOBALS[$what . '_structure'])) { - if (!PMA_exportStructure($current_db, $table, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates)) + if (!PMA_exportStructure($current_db, $table, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates)) { break 3; + } } if (isset($GLOBALS[$what . '_data'])) { - if (!PMA_exportData($current_db, $table, $crlf, $err_url, $local_query)) + if (!PMA_exportData($current_db, $table, $crlf, $err_url, $local_query)) { break 3; + } } } - if (!PMA_exportDBFooter($current_db)) + if (!PMA_exportDBFooter($current_db)) { break 2; + } } } } elseif ($export_type == 'database') { - if (!PMA_exportDBHeader($db)) + if (!PMA_exportDBHeader($db)) { break; + } if (isset($table_select)) { $tmp_select = implode($table_select, '|'); @@ -446,20 +463,24 @@ if ($export_type == 'server') { || !isset($tmp_select)) { if (isset($GLOBALS[$what . '_structure'])) { - if (!PMA_exportStructure($db, $table, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates)) + if (!PMA_exportStructure($db, $table, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates)) { break 2; + } } if (isset($GLOBALS[$what . '_data'])) { - if (!PMA_exportData($db, $table, $crlf, $err_url, $local_query)) + if (!PMA_exportData($db, $table, $crlf, $err_url, $local_query)) { break 2; + } } } } - if (!PMA_exportDBFooter($db)) + if (!PMA_exportDBFooter($db)) { break; + } } else { - if (!PMA_exportDBHeader($db)) + if (!PMA_exportDBHeader($db)) { break; + } // We export just one table if ($limit_to > 0 && $limit_from >= 0) { @@ -478,17 +499,22 @@ if ($export_type == 'server') { } if (isset($GLOBALS[$what . '_structure'])) { - if (!PMA_exportStructure($db, $table, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates)) + if (!PMA_exportStructure($db, $table, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates)) { break; + } } if (isset($GLOBALS[$what . '_data'])) { - if (!PMA_exportData($db, $table, $crlf, $err_url, $local_query)) + if (!PMA_exportData($db, $table, $crlf, $err_url, $local_query)) { break; + } } - if (!PMA_exportDBFooter($db)) + if (!PMA_exportDBFooter($db)) { break; + } +} +if (!PMA_exportFooter()) { + break; } -if (!PMA_exportFooter()) break; } while (FALSE); // End of fake loop @@ -528,7 +554,7 @@ if (!empty($asfile)) { } } // 2. as a bzipped file - else if (isset($compression) && $compression == 'bzip') { + elseif (isset($compression) && $compression == 'bzip') { if (@function_exists('bzcompress')) { $dump_buffer = bzcompress($dump_buffer); if ($dump_buffer === -8) { @@ -539,7 +565,7 @@ if (!empty($asfile)) { } } // 3. as a gzipped file - else if (isset($compression) && $compression == 'gzip') { + elseif (isset($compression) && $compression == 'gzip') { if (@function_exists('gzencode')) { // without the optional parameter level because it bug $dump_buffer = gzencode($dump_buffer); @@ -592,7 +618,7 @@ else { if (document.getElementById('textSQLDUMP')) { bodyWidth = self.innerWidth; bodyHeight = self.innerHeight; - if(!bodyWidth && !bodyHeight){ + if (!bodyWidth && !bodyHeight) { if (document.compatMode && document.compatMode == "BackCompat") { bodyWidth = document.body.clientWidth; bodyHeight = document.body.clientHeight; diff --git a/import.php b/import.php index f7efe34193..a674908273 100644 --- a/import.php +++ b/import.php @@ -125,7 +125,7 @@ if (!empty($id_bookmark)) { require_once('./libraries/bookmark.lib.php'); switch ($action_bookmark) { case 0: // bookmarked query that have to be run - $import_text = PMA_queryBookmarks($db, $cfg['Bookmark'], $id_bookmark,'id', isset($action_bookmark_all)); + $import_text = PMA_queryBookmarks($db, $cfg['Bookmark'], $id_bookmark, 'id', isset($action_bookmark_all)); if (isset($bookmark_variable) && !empty($bookmark_variable)) { $import_text = preg_replace('|/\*(.*)\[VARIABLE\](.*)\*/|imsU', '${1}' . PMA_sqlAddslashes($bookmark_variable) . '${2}', $import_text); } @@ -156,7 +156,7 @@ if (!empty($bkm_label) && !empty($import_text)) { // Should we replace bookmark? if (isset($bkm_replace)) { $bookmarks = PMA_listBookmarks($db, $cfg['Bookmark']); - foreach($bookmarks as $key => $val) { + foreach ($bookmarks as $key => $val) { if ($val == $bkm_label) { PMA_deleteBookmarks($db, $cfg['Bookmark'], $key); } @@ -180,10 +180,15 @@ if ($memory_limit = -1) { } // Calculate value of the limit -if (strtolower(substr($memory_limit, -1)) == 'm') $memory_limit = (int)substr($memory_limit, 0, -1) * 1024 * 1024; -elseif (strtolower(substr($memory_limit, -1)) == 'k') $memory_limit = (int)substr($memory_limit, 0, -1) * 1024; -elseif (strtolower(substr($memory_limit, -1)) == 'g') $memory_limit = (int)substr($memory_limit, 0, -1) * 1024 * 1024 * 1024; -else $memory_limit = (int)$memory_limit; +if (strtolower(substr($memory_limit, -1)) == 'm') { + $memory_limit = (int)substr($memory_limit, 0, -1) * 1024 * 1024; +} elseif (strtolower(substr($memory_limit, -1)) == 'k') { + $memory_limit = (int)substr($memory_limit, 0, -1) * 1024; +} elseif (strtolower(substr($memory_limit, -1)) == 'g') { + $memory_limit = (int)substr($memory_limit, 0, -1) * 1024 * 1024 * 1024; +} else { + $memory_limit = (int)$memory_limit; +} $read_limit = $memory_limit / 4; // Just to be sure, there might be lot of memory needed for uncompression @@ -194,7 +199,7 @@ if (!empty($local_import_file) && !empty($cfg['UploadDir'])) { $local_import_file = PMA_securePath($local_import_file); $import_file = PMA_userDir($cfg['UploadDir']) . $local_import_file; -} else if (empty($import_file) || !is_uploaded_file($import_file)) { +} elseif (empty($import_file) || !is_uploaded_file($import_file)) { $import_file = 'none'; } @@ -300,7 +305,7 @@ if ($cfg['AllowAnywhereRecoding'] && $allow_recoding if ($charset_of_file != $charset) { $charset_conversion = TRUE; } -} else if (PMA_MYSQL_INT_VERSION >= 40100 +} elseif (PMA_MYSQL_INT_VERSION >= 40100 && isset($charset_of_file) && $charset_of_file != 'utf8') { PMA_DBI_query('SET NAMES \'' . $charset_of_file . '\''); // We can not show query in this case, it is in different charset @@ -48,11 +48,9 @@ session_write_close(); if (empty($HTTP_HOST)) { if (!empty($_ENV) && isset($_ENV['HTTP_HOST'])) { $HTTP_HOST = $_ENV['HTTP_HOST']; - } - elseif (@getenv('HTTP_HOST')) { + } elseif (@getenv('HTTP_HOST')) { $HTTP_HOST = getenv('HTTP_HOST'); - } - else { + } else { $HTTP_HOST = ''; } } @@ -72,7 +70,7 @@ unset( $cfgRelation ); $drops = array( 'lang', 'server', 'convcharset', 'collation_connection', 'db', 'table' ); -foreach( $drops as $each_drop ) { +foreach ( $drops as $each_drop ) { if ( ! array_key_exists( $each_drop, $_GET ) ) { unset( $_GET[$each_drop] ); } @@ -122,7 +120,7 @@ header('Content-Type: text/html; charset=' . $GLOBALS['charset']); <script type="text/javascript" language="javascript"> // <![CDATA[ // definitions used in querywindow.js - var common_query = '<?php echo PMA_generate_common_url('','','&');?>'; + var common_query = '<?php echo PMA_generate_common_url('', '', '&');?>'; var opendb_url = '<?php echo $GLOBALS['cfg']['DefaultTabDatabase']; ?>'; var safari_browser = <?php echo PMA_USR_BROWSER_AGENT == 'SAFARI' ? 'true' : 'false' ?>; var querywindow_height = <?php echo $GLOBALS['cfg']['QueryWindowHeight']; ?>; @@ -430,7 +430,7 @@ function PMA_displayTableList($tables, $visible = false, } else { echo '<ul id="subel' . $element_counter . '" style="display: none">'; } - foreach( $tables as $group => $table ) { + foreach ( $tables as $group => $table ) { if ( isset( $table['is' . $sep . 'group'] ) ) { $common_url_query = $GLOBALS['common_url_query'] . '&tbl_group=' . urlencode( $tab_group_full . $group ); diff --git a/libraries/Config.class.php b/libraries/Config.class.php index 853d676f93..2b13e227b0 100644 --- a/libraries/Config.class.php +++ b/libraries/Config.class.php @@ -158,7 +158,7 @@ class PMA_Config } elseif (preg_match('@OmniWeb/([0-9].[0-9]{1,2})@', $HTTP_USER_AGENT, $log_version)) { $this->set('PMA_USR_BROWSER_VER', $log_version[1]); $this->set('PMA_USR_BROWSER_AGENT', 'OMNIWEB'); - //} else if (ereg('Konqueror/([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)) { + //} elseif (ereg('Konqueror/([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)) { // Konqueror 2.2.2 says Konqueror/2.2.2 // Konqueror 3.0.3 says Konqueror/3 } elseif (preg_match('@(Konqueror/)(.*)(;)@', $HTTP_USER_AGENT, $log_version)) { diff --git a/libraries/Theme_Manager.class.php b/libraries/Theme_Manager.class.php index 74efceeb46..4612419782 100644 --- a/libraries/Theme_Manager.class.php +++ b/libraries/Theme_Manager.class.php @@ -34,53 +34,56 @@ class PMA_Theme_Manager { /** * @var object PMA_Theme active theme */ - var $theme = NULL; + var $theme = null; - function __construct() { - $this->themes_path = trim( $GLOBALS['cfg']['ThemePath'] ) ; + function __construct() + { + $this->themes_path = trim($GLOBALS['cfg']['ThemePath']) ; $this->per_server = (bool) $GLOBALS['cfg']['ThemePerServer']; $this->theme = new PMA_Theme; - if ( ! $this->_checkThemeFolder( $this->themes_path ) ) { + if ( ! $this->_checkThemeFolder($this->themes_path)) { return; } - $this->loadThemes( $this->themes_path ); + $this->loadThemes($this->themes_path); - if ( ! $this->checkTheme( $GLOBALS['cfg']['ThemeDefault'] ) ) { + if ( ! $this->checkTheme($GLOBALS['cfg']['ThemeDefault'])) { $GLOBALS['PMA_errors'][] = sprintf( $GLOBALS['strThemeDefaultNotFound'], $GLOBALS['cfg']['ThemeDefault'] ); trigger_error( - sprintf( $GLOBALS['strThemeDefaultNotFound'], - $GLOBALS['cfg']['ThemeDefault'] ), - E_USER_WARNING ); + sprintf($GLOBALS['strThemeDefaultNotFound'], + $GLOBALS['cfg']['ThemeDefault']), + E_USER_WARNING); $GLOBALS['cfg']['ThemeDefault'] = false; } $this->theme_default = $GLOBALS['cfg']['ThemeDefault']; // check if user have a theme cookie - if ( ! $this->getThemeCookie() - || ! $this->setActiveTheme( $this->getThemeCookie() ) ) { - if ( $GLOBALS['cfg']['ThemeDefault'] ) { - $this->setActiveTheme( $GLOBALS['cfg']['ThemeDefault'] ); + if (! $this->getThemeCookie() + || ! $this->setActiveTheme($this->getThemeCookie())) { + if ($GLOBALS['cfg']['ThemeDefault']) { + $this->setActiveTheme($GLOBALS['cfg']['ThemeDefault']); } else { - $this->setActiveTheme( 'original' ); + $this->setActiveTheme('original'); } } } - function __wakeup() { - $this->loadThemes( $this->themes_path ); + function __wakeup() + { + $this->loadThemes($this->themes_path); } - function setActiveTheme( $theme = NULL ) { - if ( ! $this->checkTheme( $theme ) ) { - $GLOBALS['PMA_errors'][] = sprintf( $GLOBALS['strThemeNotFound'], - $theme ); + function setActiveTheme($theme = null) + { + if ( ! $this->checkTheme($theme)) { + $GLOBALS['PMA_errors'][] = sprintf($GLOBALS['strThemeNotFound'], + $theme); trigger_error( - sprintf( $GLOBALS['strThemeNotFound'], $theme ), - E_USER_WARNING ); + sprintf($GLOBALS['strThemeNotFound'], $theme), + E_USER_WARNING); return false; } @@ -96,9 +99,10 @@ class PMA_Theme_Manager { /** * @return string cookie name */ - function getThemeCookieName() { + function getThemeCookieName() + { // Allow different theme per server - if ( isset( $GLOBALS['server'] ) && $this->per_server ) { + if (isset($GLOBALS['server']) && $this->per_server) { return $this->cookie_name . '-' . $GLOBALS['server']; } else { return $this->cookie_name; @@ -109,8 +113,9 @@ class PMA_Theme_Manager { * returns name of theme stored in the cookie * @return string theme name from cookie */ - function getThemeCookie() { - if ( isset( $_COOKIE[$this->getThemeCookieName()] ) ) { + function getThemeCookie() + { + if (isset($_COOKIE[$this->getThemeCookieName()])) { return $_COOKIE[$this->getThemeCookieName()]; } @@ -126,16 +131,18 @@ class PMA_Theme_Manager { * @uses PMA_Theme_Manager::$theme_default * @uses PMA_Theme::getId() */ - function setThemeCookie() { - PMA_setCookie( $this->getThemeCookieName(), $this->theme->id, - $this->theme_default ); + function setThemeCookie() + { + PMA_setCookie($this->getThemeCookieName(), $this->theme->id, + $this->theme_default); return true; } /** * old PHP 4 constructor */ - function PMA_Theme_Manager() { + function PMA_Theme_Manager() + { $this->__construct(); } @@ -144,15 +151,16 @@ class PMA_Theme_Manager { * @param string $folder * @return boolean */ - /*private*/ function _checkThemeFolder( $folder ) { - if ( ! is_dir( $folder ) ) { + /*private*/ function _checkThemeFolder($folder) + { + if (! is_dir($folder)) { $GLOBALS['PMA_errors'][] = - sprintf( $GLOBALS['strThemePathNotFound'], - $folder ); + sprintf($GLOBALS['strThemePathNotFound'], + $folder); trigger_error( - sprintf( $GLOBALS['strThemePathNotFound'], - $folder ), - E_USER_WARNING ); + sprintf($GLOBALS['strThemePathNotFound'], + $folder), + E_USER_WARNING); return false; } @@ -164,31 +172,32 @@ class PMA_Theme_Manager { * * @param string $folder themes folders */ - function loadThemes( $folder ) { - if ( $handleThemes = opendir( $folder ) ) { + function loadThemes($folder) + { + if ($handleThemes = opendir($folder)) { // check for themes directory - while ( FALSE !== ($PMA_Theme = readdir($handleThemes)) ) { - if ( array_key_exists( $PMA_Theme, $this->themes ) ) { + while (FALSE !== ($PMA_Theme = readdir($handleThemes))) { + if (array_key_exists($PMA_Theme, $this->themes)) { $new_themes[$PMA_Theme] = $this->themes[$PMA_Theme]; continue; } - $new_theme = PMA_Theme::load( $folder . '/' . $PMA_Theme ); - if ( $new_theme ) { - $new_theme->setId( $PMA_Theme ); + $new_theme = PMA_Theme::load($folder . '/' . $PMA_Theme); + if ($new_theme) { + $new_theme->setId($PMA_Theme); $new_themes[$PMA_Theme] = $new_theme; } } // end get themes - closedir( $handleThemes ); + closedir($handleThemes); } else { trigger_error( 'phpMyAdmin-ERROR: can not open themes folder: ' . $folder, - E_USER_WARNING ); + E_USER_WARNING); return false; } // end check for themes directory $this->themes = $new_themes; - ksort( $this->themes ); + ksort($this->themes); } /** @@ -196,8 +205,9 @@ class PMA_Theme_Manager { * * @param string $theme name fo theme to check for */ - function checkTheme( $theme ) { - if ( ! array_key_exists( $theme, $this->themes ) ) { + function checkTheme($theme) + { + if (! array_key_exists($theme, $this->themes)) { return false; } @@ -209,10 +219,11 @@ class PMA_Theme_Manager { * * @param boolean $form wether enclosed by from tags or not */ - function getHtmlSelectBox( $form = true ) { + function getHtmlSelectBox($form = true) + { $select_box = ''; - if ( $form ) { + if ($form) { $select_box .= '<form name="setTheme" method="post" action="index.php"' .' target="_parent">'; $select_box .= PMA_generate_common_hidden_inputs(); @@ -227,16 +238,16 @@ class PMA_Theme_Manager { $select_box .= '<select name="set_theme" xml:lang="en" dir="ltr"' .' onchange="this.form.submit();" >'; - foreach ( $this->themes as $each_theme_id => $each_theme ) { + foreach ($this->themes as $each_theme_id => $each_theme) { $select_box .= '<option value="' . $each_theme_id . '"'; - if ( $this->active_theme === $each_theme_id ) { + if ($this->active_theme === $each_theme_id) { $select_box .= ' selected="selected"'; } - $select_box .= '>' . htmlspecialchars( $each_theme->getName() ) . '</option>'; + $select_box .= '>' . htmlspecialchars($each_theme->getName()) . '</option>'; } $select_box .= '</select>'; - if ( $form ) { + if ($form) { $select_box .= '<noscript><input type="submit" value="' . $GLOBALS['strGo'] . '" /></noscript>'; $select_box .= '</form>'; } @@ -247,7 +258,8 @@ class PMA_Theme_Manager { /** * enables backward compatibility */ - function makeBc() { + function makeBc() + { $GLOBALS['theme'] = $this->theme->getId(); $GLOBALS['pmaThemePath'] = $this->theme->getPath(); $GLOBALS['pmaThemeImage'] = $this->theme->getImgPath(); @@ -255,8 +267,8 @@ class PMA_Theme_Manager { /** * load layout file if exists */ - if ( @file_exists( $GLOBALS['pmaThemePath'] . 'layout.inc.php' ) ) { - include( $GLOBALS['pmaThemePath'] . 'layout.inc.php' ); + if (@file_exists($GLOBALS['pmaThemePath'] . 'layout.inc.php')) { + include $GLOBALS['pmaThemePath'] . 'layout.inc.php'; } @@ -268,9 +280,9 @@ class PMA_Theme_Manager { * @uses $this->themes * @uses PMA_Theme::printPreview() */ - function printPreviews() { - foreach ( $this->themes as $each_theme ) { - + function printPreviews() + { + foreach ($this->themes as $each_theme) { $each_theme->printPreview(); } // end 'open themes' } diff --git a/libraries/auth/cookie.auth.lib.php b/libraries/auth/cookie.auth.lib.php index 375ed7927b..d2eb8ff3b2 100644 --- a/libraries/auth/cookie.auth.lib.php +++ b/libraries/auth/cookie.auth.lib.php @@ -82,14 +82,12 @@ function PMA_auth() // server name if (!empty($GLOBALS['pma_cookie_servername'])) { $default_server = $GLOBALS['pma_cookie_servername']; - } - else if (!empty($_COOKIE) && isset($_COOKIE['pma_cookie_servername-' . $server])) { + } elseif (!empty($_COOKIE) && isset($_COOKIE['pma_cookie_servername-' . $server])) { $default_server = $_COOKIE['pma_cookie_servername-' . $server]; } $autocomplete = ''; - } - else { + } else { $default_user = ''; $autocomplete = ' autocomplete="off"'; } @@ -231,7 +229,7 @@ echo sprintf( $GLOBALS['strWelcome'], <?php if ( ! empty( $GLOBALS['PMA_errors'] ) && is_array( $GLOBALS['PMA_errors'] ) ) { - foreach( $GLOBALS['PMA_errors'] as $error ) { + foreach ( $GLOBALS['PMA_errors'] as $error ) { echo '<div class="error">' . $error . '</div>' . "\n"; } } @@ -297,11 +295,11 @@ function PMA_auth_check() // The user wants to be logged out -> delete password cookie if (!empty($old_usr)) { - setcookie('pma_cookie_password-' . $server, '', 0, $GLOBALS['cookie_path'], '' , $GLOBALS['is_https']); + setcookie('pma_cookie_password-' . $server, '', 0, $GLOBALS['cookie_path'], '', $GLOBALS['is_https']); } // The user just logged in - else if (!empty($pma_username)) { + elseif (!empty($pma_username)) { $PHP_AUTH_USER = $pma_username; $PHP_AUTH_PW = (empty($pma_password)) ? '' : $pma_password; if ($GLOBALS['cfg']['AllowArbitraryServer']) { @@ -319,8 +317,7 @@ function PMA_auth_check() if (!empty($pma_cookie_servername)) { $pma_auth_server = $pma_cookie_servername; $from_cookie = TRUE; - } - else if (!empty($_COOKIE) && isset($_COOKIE['pma_cookie_servername-' . $server])) { + } elseif (!empty($_COOKIE) && isset($_COOKIE['pma_cookie_servername-' . $server])) { $pma_auth_server = $_COOKIE['pma_cookie_servername-' . $server]; $from_cookie = TRUE; } @@ -356,11 +353,9 @@ function PMA_auth_check() // password if (!empty($pma_cookie_password)) { $PHP_AUTH_PW = $pma_cookie_password; - } - else if (!empty($_COOKIE) && isset($_COOKIE['pma_cookie_password-' . $server])) { + } elseif (!empty($_COOKIE) && isset($_COOKIE['pma_cookie_password-' . $server])) { $PHP_AUTH_PW = $_COOKIE['pma_cookie_password-' . $server]; - } - else { + } else { $from_cookie = FALSE; } $PHP_AUTH_PW = PMA_blowfish_decrypt($PHP_AUTH_PW, $GLOBALS['cfg']['blowfish_secret'] . $decrypted_time); @@ -458,7 +453,7 @@ function PMA_auth_set_user() $GLOBALS['is_https']); } else { // Delete servername cookie - setcookie('pma_cookie_servername-' . $server, '', 0, $GLOBALS['cookie_path'], '' , $GLOBALS['is_https']); + setcookie('pma_cookie_servername-' . $server, '', 0, $GLOBALS['cookie_path'], '', $GLOBALS['is_https']); } } @@ -502,19 +497,19 @@ function PMA_auth_fails() global $conn_error, $server; // Deletes password cookie and displays the login form - setcookie('pma_cookie_password-' . $server, '', 0, $GLOBALS['cookie_path'], '' , $GLOBALS['is_https']); + setcookie('pma_cookie_password-' . $server, '', 0, $GLOBALS['cookie_path'], '', $GLOBALS['is_https']); if (isset($GLOBALS['allowDeny_forbidden']) && $GLOBALS['allowDeny_forbidden']) { $conn_error = $GLOBALS['strAccessDenied']; - } else if (isset($GLOBALS['no_activity']) && $GLOBALS['no_activity']) { - $conn_error = sprintf($GLOBALS['strNoActivity'],$GLOBALS['cfg']['LoginCookieValidity']); + } elseif (isset($GLOBALS['no_activity']) && $GLOBALS['no_activity']) { + $conn_error = sprintf($GLOBALS['strNoActivity'], $GLOBALS['cfg']['LoginCookieValidity']); // Remember where we got timeout to return on same place if (isset($_SERVER['SCRIPT_NAME'])) { $GLOBALS['target'] = basename($_SERVER['SCRIPT_NAME']); } - } else if (PMA_DBI_getError()) { + } elseif (PMA_DBI_getError()) { $conn_error = PMA_sanitize(PMA_DBI_getError()); - } else if (isset($php_errormsg)) { + } elseif (isset($php_errormsg)) { $conn_error = $php_errormsg; } else { $conn_error = $GLOBALS['strCannotLogin']; diff --git a/libraries/auth/http.auth.lib.php b/libraries/auth/http.auth.lib.php index df1771fc4b..704670cc7f 100644 --- a/libraries/auth/http.auth.lib.php +++ b/libraries/auth/http.auth.lib.php @@ -21,7 +21,7 @@ */ function PMA_auth() { - header('WWW-Authenticate: Basic realm="phpMyAdmin ' . sprintf($GLOBALS['strRunning'], (empty($GLOBALS['cfg']['Server']['verbose']) ? str_replace('\'', '\\\'',$GLOBALS['cfg']['Server']['host']) : str_replace('\'', '\\\'', $GLOBALS['cfg']['Server']['verbose']))) . '"'); + header('WWW-Authenticate: Basic realm="phpMyAdmin ' . sprintf($GLOBALS['strRunning'], (empty($GLOBALS['cfg']['Server']['verbose']) ? str_replace('\'', '\\\'', $GLOBALS['cfg']['Server']['host']) : str_replace('\'', '\\\'', $GLOBALS['cfg']['Server']['verbose']))) . '"'); header('HTTP/1.0 401 Unauthorized'); header('status: 401 Unauthorized'); @@ -83,19 +83,19 @@ function PMA_auth_check() $PHP_AUTH_USER = $_SERVER['PHP_AUTH_USER']; } // CGI, might be encoded, see bellow - else if (@getenv('REMOTE_USER')) { + elseif (@getenv('REMOTE_USER')) { $PHP_AUTH_USER = getenv('REMOTE_USER'); } // WebSite Professional - else if (@getenv('AUTH_USER')) { + elseif (@getenv('AUTH_USER')) { $PHP_AUTH_USER = getenv('AUTH_USER'); } // IIS, might be encoded, see bellow - else if (@getenv('HTTP_AUTHORIZATION')) { + elseif (@getenv('HTTP_AUTHORIZATION')) { $PHP_AUTH_USER = getenv('HTTP_AUTHORIZATION'); } // FastCGI, might be encoded, see bellow - else if (@getenv('Authorization')) { + elseif (@getenv('Authorization')) { $PHP_AUTH_USER = getenv('Authorization'); } } @@ -107,11 +107,11 @@ function PMA_auth_check() $PHP_AUTH_PW = $_SERVER['PHP_AUTH_PW']; } // Apache/CGI - else if (@getenv('REMOTE_PASSWORD')) { + elseif (@getenv('REMOTE_PASSWORD')) { $PHP_AUTH_PW = getenv('REMOTE_PASSWORD'); } // WebSite Professional - else if (@getenv('AUTH_PASSWORD')) { + elseif (@getenv('AUTH_PASSWORD')) { $PHP_AUTH_PW = getenv('AUTH_PASSWORD'); } } diff --git a/libraries/blowfish.php b/libraries/blowfish.php index 4e7cfff08d..86fe752632 100644 --- a/libraries/blowfish.php +++ b/libraries/blowfish.php @@ -441,10 +441,10 @@ class Horde_Cipher_blowfish { $R = null; $retarray = array_values(unpack('N*', $block)); - if(isset($retarray[0])) { + if (isset($retarray[0])) { $L = $retarray[0]; } - if(isset($retarray[1])) { + if (isset($retarray[1])) { $R = $retarray[1]; } // end change for phpMyAdmin @@ -534,7 +534,7 @@ function PMA_blowfish_encrypt($data, $secret) { for ($i=0; $i<strlen($data); $i+=8) { $block = substr($data, $i, 8); if (strlen($block) < 8) { - $block = full_str_pad($block,8,"\0", 1); + $block = full_str_pad($block, 8, "\0", 1); } $encrypt .= $pma_cipher->encryptBlock($block, $secret); } diff --git a/libraries/bookmark.lib.php b/libraries/bookmark.lib.php index c303679a3c..4c9278bb17 100644 --- a/libraries/bookmark.lib.php +++ b/libraries/bookmark.lib.php @@ -102,7 +102,9 @@ function PMA_queryBookmarks($db, $cfgBookmark, $id, $id_field = 'id', $action_bo . ' OR user = \'\')' ) . ' AND ' . PMA_backquote($id_field) . ' = ' . $id; $result = PMA_DBI_try_query($query, $controllink); - if (!$result) return FALSE; + if (!$result) { + return FALSE; + } list($bookmark_query) = PMA_DBI_fetch_row($result) or array(FALSE); return $bookmark_query; @@ -132,7 +134,7 @@ function &PMA_queryDBBookmarks($db, $cfgBookmark, &$table_array) } $search_for = array(); - foreach($table_array AS $table => $table_sortkey) { + foreach ($table_array AS $table => $table_sortkey) { $search_for[] = "'" . PMA_sqlAddslashes($table) . "'"; } @@ -140,7 +142,9 @@ function &PMA_queryDBBookmarks($db, $cfgBookmark, &$table_array) . ' WHERE dbase = \'' . PMA_sqlAddslashes($db) . '\'' . (count($search_for) > 0 ? ' AND label IN (' . implode(', ', $search_for) . ')' : ''); $result = PMA_DBI_try_query($query, $controllink, PMA_DBI_QUERY_STORE); - if (!$result || PMA_DBI_num_rows($result) < 1) return $bookmarks; + if (!$result || PMA_DBI_num_rows($result) < 1) { + return $bookmarks; + } while ($row = PMA_DBI_fetch_assoc($result)) { $bookmarks[$row['label']] = $row['query']; } diff --git a/libraries/charset_conversion.lib.php b/libraries/charset_conversion.lib.php index 3cad4cf2d7..7c93ef2bb0 100644 --- a/libraries/charset_conversion.lib.php +++ b/libraries/charset_conversion.lib.php @@ -24,7 +24,7 @@ if (isset($cfg['AllowAnywhereRecoding']) } } $PMA_recoding_engine = 'recode'; - } else if ($cfg['RecodingEngine'] == 'iconv') { + } elseif ($cfg['RecodingEngine'] == 'iconv') { if (!@extension_loaded('iconv')) { PMA_dl('iconv'); if (!@extension_loaded('iconv')) { @@ -36,7 +36,7 @@ if (isset($cfg['AllowAnywhereRecoding']) } else { if (@extension_loaded('iconv')) { $PMA_recoding_engine = 'iconv'; - } else if (@extension_loaded('recode')) { + } elseif (@extension_loaded('recode')) { $PMA_recoding_engine = 'recode'; } else { PMA_dl('iconv'); @@ -75,7 +75,7 @@ if (isset($cfg['AllowAnywhereRecoding']) if ($PMA_recoding_engine == 'iconv') { if (@function_exists('iconv')) { $PMA_recoding_engine = PMA_CHARSET_ICONV; - } else if (@function_exists('libiconv')) { + } elseif (@function_exists('libiconv')) { $PMA_recoding_engine = PMA_CHARSET_LIBICONV; } else { $PMA_recoding_engine = PMA_CHARSET_NONE; @@ -87,7 +87,7 @@ if (isset($cfg['AllowAnywhereRecoding']) require_once('./libraries/footer.inc.php'); exit(); } - } else if ($PMA_recoding_engine == 'recode') { + } elseif ($PMA_recoding_engine == 'recode') { if (@function_exists('recode_string')) { $PMA_recoding_engine = PMA_CHARSET_RECODE; } else { @@ -101,7 +101,7 @@ if (isset($cfg['AllowAnywhereRecoding']) } else { if (@function_exists('iconv')) { $PMA_recoding_engine = PMA_CHARSET_ICONV; - } else if (@function_exists('libiconv')) { + } elseif (@function_exists('libiconv')) { $PMA_recoding_engine = PMA_CHARSET_LIBICONV; } elseif (@function_exists('recode_string')) { $PMA_recoding_engine = PMA_CHARSET_RECODE; @@ -143,8 +143,7 @@ function PMA_convert_display_charset($what) { // this constant is not defined before the login: || (defined('PMA_MYSQL_INT_VERSION') && PMA_MYSQL_INT_VERSION >= 40100) ) { // lem9: even if AllowAnywhereRecoding is TRUE, do not recode for MySQL >= 4.1.x since MySQL does the job return $what; - } - else if (is_array($what)) { + } elseif (is_array($what)) { $result = array(); foreach ($what AS $key => $val) { if (is_string($val) || is_array($val)) { @@ -158,8 +157,7 @@ function PMA_convert_display_charset($what) { } } // end while return $result; - } - else if (is_string($what)) { + } elseif (is_string($what)) { switch ($GLOBALS['PMA_recoding_engine']) { case PMA_CHARSET_RECODE: @@ -171,8 +169,7 @@ function PMA_convert_display_charset($what) { default: return $what; } - } - else if (is_object($what)) { + } elseif (is_object($what)) { // isn't it object returned from mysql_fetch_field ? if (@is_string($what->name)) { $what->name = PMA_convert_display_charset($what->name); @@ -184,8 +181,7 @@ function PMA_convert_display_charset($what) { $what->Database = PMA_convert_display_charset($what->Database); } return $what; - } - else { + } else { // when we don't know what it is we don't touch it... return $what; } @@ -243,7 +239,9 @@ function PMA_convert_charset($what) { * @author nijel */ function PMA_convert_string($src_charset, $dest_charset, $what) { - if ($src_charset == $dest_charset) return $what; + if ($src_charset == $dest_charset) { + return $what; + } switch ($GLOBALS['PMA_recoding_engine']) { case PMA_CHARSET_RECODE: return recode_string($src_charset . '..' . $dest_charset, $what); diff --git a/libraries/check_user_privileges.lib.php b/libraries/check_user_privileges.lib.php index 89c9a8906c..d6ce3d48ba 100644 --- a/libraries/check_user_privileges.lib.php +++ b/libraries/check_user_privileges.lib.php @@ -9,7 +9,7 @@ /** * returns true (int > 0) if current user is superuser * otherwise 0 - * + * * @return integer $is_superuser */ function PMA_isSuperuser() { @@ -33,9 +33,9 @@ function PMA_analyseShowGrant($rs_usr, &$is_create_db_priv, &$db_to_create, &$is $re0 = '(^|(\\\\\\\\)+|[^\])'; // non-escaped wildcards $re1 = '(^|[^\])(\\\)+'; // escaped wildcards while ($row = PMA_DBI_fetch_row($rs_usr)) { - $show_grants_dbname = substr($row[0], strpos($row[0], ' ON ') + 4,(strpos($row[0], '.', strpos($row[0], ' ON ')) - strpos($row[0], ' ON ') - 4)); - $show_grants_dbname = ereg_replace('^`(.*)`','\\1', $show_grants_dbname); - $show_grants_str = substr($row[0],6,(strpos($row[0],' ON ')-6)); + $show_grants_dbname = substr($row[0], strpos($row[0], ' ON ') + 4, (strpos($row[0], '.', strpos($row[0], ' ON ')) - strpos($row[0], ' ON ') - 4)); + $show_grants_dbname = ereg_replace('^`(.*)`', '\\1', $show_grants_dbname); + $show_grants_str = substr($row[0], 6, (strpos($row[0], ' ON ') - 6)); if ($show_grants_str == 'RELOAD') { $is_reload_priv = true; } @@ -47,13 +47,12 @@ function PMA_analyseShowGrant($rs_usr, &$is_create_db_priv, &$db_to_create, &$is $db_to_create = ''; $dbs_where_create_table_allowed[] = '*'; break; - } // end if - else { + } else { // this array may contain wildcards $dbs_where_create_table_allowed[] = $show_grants_dbname; - + // before MySQL 4.1.0, we cannot use backquotes around a dbname - // for the USE command, so the USE will fail if the dbname contains + // for the USE command, so the USE will fail if the dbname contains // a "-" and we cannot detect if such a db already exists; // since 4.1.0, we need to use backquotes if the dbname contains a "-" // in a USE command @@ -67,7 +66,7 @@ function PMA_analyseShowGrant($rs_usr, &$is_create_db_priv, &$db_to_create, &$is if ( (ereg($re0 . '%|_', $show_grants_dbname) && !ereg('\\\\%|\\\\_', $show_grants_dbname)) // does this db exist? - || (!PMA_DBI_try_query('USE ' . ereg_replace($re1 .'(%|_)', '\\1\\3',$dbname_to_test), NULL, PMA_DBI_QUERY_STORE) && substr(PMA_DBI_getError(), 1, 4) != 1044) + || (!PMA_DBI_try_query('USE ' . ereg_replace($re1 .'(%|_)', '\\1\\3', $dbname_to_test), null, PMA_DBI_QUERY_STORE) && substr(PMA_DBI_getError(), 1, 4) != 1044) ) { $db_to_create = ereg_replace($re0 . '%', '\\1...', ereg_replace($re0 . '_', '\\1?', $show_grants_dbname)); $db_to_create = ereg_replace($re1 . '(%|_)', '\\1\\3', $db_to_create); @@ -78,7 +77,7 @@ function PMA_analyseShowGrant($rs_usr, &$is_create_db_priv, &$db_to_create, &$is // // we don't break, we want all possible databases //break; - } // end if + } // end if } // end elseif } // end if } // end while @@ -93,7 +92,7 @@ function PMA_analyseShowGrant($rs_usr, &$is_create_db_priv, &$db_to_create, &$is if (PMA_MYSQL_INT_VERSION >= 40102) { $rs_usr = PMA_DBI_try_query('SHOW GRANTS', $userlink, PMA_DBI_QUERY_STORE); if ($rs_usr) { - PMA_analyseShowGrant($rs_usr,$is_create_db_priv, $db_to_create, $is_reload_priv, $dbs_where_create_table_allowed); + PMA_analyseShowGrant($rs_usr, $is_create_db_priv, $db_to_create, $is_reload_priv, $dbs_where_create_table_allowed); PMA_DBI_free_result($rs_usr); unset($rs_usr); } @@ -104,7 +103,7 @@ if (PMA_MYSQL_INT_VERSION >= 40102) { // $userlink so maybe the SELECT will fail if (!$is_create_db_priv) { - $res = PMA_DBI_query('SELECT USER();', NULL, PMA_DBI_QUERY_STORE); + $res = PMA_DBI_query('SELECT USER();', null, PMA_DBI_QUERY_STORE); list($mysql_cur_user_and_host) = PMA_DBI_fetch_row($res); $mysql_cur_user = substr($mysql_cur_user_and_host, 0, strrpos($mysql_cur_user_and_host, '@')); @@ -149,8 +148,7 @@ if (PMA_MYSQL_INT_VERSION >= 40102) { } // end while PMA_DBI_free_result($rs_usr); unset($rs_usr, $row, $re0, $re1); - } // end if - else { + } else { // Finally, let's try to get the user's privileges by using SHOW // GRANTS... // Maybe we'll find a little CREATE priv there :) @@ -162,7 +160,7 @@ if (PMA_MYSQL_INT_VERSION >= 40102) { } unset($local_query); if ($rs_usr) { - PMA_analyseShowGrant($rs_usr,$is_create_db_priv, $db_to_create, $is_reload_priv, $dbs_where_create_table_allowed); + PMA_analyseShowGrant($rs_usr, $is_create_db_priv, $db_to_create, $is_reload_priv, $dbs_where_create_table_allowed); PMA_DBI_free_result($rs_usr); unset($rs_usr); } // end if diff --git a/libraries/common.lib.php b/libraries/common.lib.php index fe789ffcb2..57a5338e41 100644 --- a/libraries/common.lib.php +++ b/libraries/common.lib.php @@ -54,7 +54,7 @@ function PMA_securePath($path) { // change .. to . - $path = preg_replace('@\.\.*@','.',$path); + $path = preg_replace('@\.\.*@', '.', $path); return $path; } // end function @@ -280,8 +280,7 @@ function PMA_safe_db_list($only_db_check, $controllink, $dblist_cnt, $userlink, while ($uva_row = PMA_DBI_fetch_row($uva_alldbs)) { $dblist[] = $uva_row[0]; } // end while - } // end if - else { + } else { while ($uva_row = PMA_DBI_fetch_row($uva_alldbs)) { $uva_db = $uva_row[0]; if (isset($uva_mydbs[$uva_db]) && $uva_mydbs[$uva_db] == 1) { @@ -648,11 +647,11 @@ if (!defined('PMA_MINIMUM_COMMON')) { } break; case 'html': - $formatted_sql = PMA_SQP_formatHtml($parsed_sql,'color'); + $formatted_sql = PMA_SQP_formatHtml($parsed_sql, 'color'); break; case 'text': //$formatted_sql = PMA_SQP_formatText($parsed_sql); - $formatted_sql = PMA_SQP_formatHtml($parsed_sql,'text'); + $formatted_sql = PMA_SQP_formatHtml($parsed_sql, 'text'); break; default: break; @@ -677,7 +676,9 @@ if (!defined('PMA_MINIMUM_COMMON')) { { global $cfg; - if ($cfg['MySQLManualType'] == 'none' || empty($cfg['MySQLManualBase'])) return ''; + if ($cfg['MySQLManualType'] == 'none' || empty($cfg['MySQLManualBase'])) { + return ''; + } // Fixup for newly used names: $chapter = str_replace('_', '-', strtolower($chapter)); @@ -685,19 +686,25 @@ if (!defined('PMA_MINIMUM_COMMON')) { switch ($cfg['MySQLManualType']) { case 'chapters': - if (empty($chapter)) $chapter = 'index'; + if (empty($chapter)) { + $chapter = 'index'; + } $url = $cfg['MySQLManualBase'] . '/' . $chapter . '.html#' . $link; break; case 'big': $url = $cfg['MySQLManualBase'] . '#' . $link; break; case 'searchable': - if (empty($link)) $link = 'index'; + if (empty($link)) { + $link = 'index'; + } $url = $cfg['MySQLManualBase'] . '/' . $link . '.html'; break; case 'viewable': default: - if (empty($link)) $link = 'index'; + if (empty($link)) { + $link = 'index'; + } $mysql = '5.0'; if (defined('PMA_MYSQL_INT_VERSION')) { if (PMA_MYSQL_INT_VERSION < 50000) { @@ -716,7 +723,7 @@ if (!defined('PMA_MINIMUM_COMMON')) { return '<a href="' . $url . '" target="mysql_doc"><img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 'b_sqlhelp.png" width="16" height="16" alt="' . $GLOBALS['strDocu'] . '" title="' . $GLOBALS['strDocu'] . '" /></a>'; } elseif ($GLOBALS['cfg']['ReplaceHelpImg']) { return '<a href="' . $url . '" target="mysql_doc"><img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 'b_help.png" width="11" height="11" alt="' . $GLOBALS['strDocu'] . '" title="' . $GLOBALS['strDocu'] . '" /></a>'; - }else{ + } else { return '[<a href="' . $url . '" target="mysql_doc">' . $GLOBALS['strDocu'] . '</a>]'; } } // end of the 'PMA_showMySQLDocu()' function @@ -789,7 +796,7 @@ if (!defined('PMA_MINIMUM_COMMON')) { // --- // modified to show me the help on sql errors (Michael Keck) echo ' <p><strong>' . $GLOBALS['strSQLQuery'] . ':</strong>' . "\n"; - if (strstr(strtolower($formatted_sql),'select')) { // please show me help to the error on select + if (strstr(strtolower($formatted_sql), 'select')) { // please show me help to the error on select echo PMA_showMySQLDocu('SQL-Syntax', 'SELECT'); } if ($is_modify_link && isset($db)) { @@ -1044,7 +1051,7 @@ if (!defined('PMA_MINIMUM_COMMON')) { uksort($tables, 'strnatcasecmp'); } } - + if (count($tables) < 1) { return $tables; } @@ -1816,8 +1823,7 @@ window.parent.updateTableTitle('<?php echo $uni_tbl; ?>', '<?php echo PMA_jsForm if ($tab['text'] == $GLOBALS['strEmpty'] || $tab['text'] == $GLOBALS['strDrop']) { $tab['class'] = 'caution'; - } - elseif (!empty($tab['active']) + } elseif (!empty($tab['active']) || (isset($GLOBALS['active_page']) && $GLOBALS['active_page'] == $tab['link']) || basename($_SERVER['PHP_SELF']) == $tab['link']) @@ -1910,24 +1916,22 @@ window.parent.updateTableTitle('<?php echo $uni_tbl; ?>', '<?php echo PMA_jsForm function PMA_linkOrButton($url, $message, $tag_params = array(), $new_form = true, $strip_img = false, $target = '') { - if (!is_array($tag_params)) - { + if (! is_array($tag_params)) { $tmp = $tag_params; $tag_params = array(); - if (!empty($tmp)) - { + if (!empty($tmp)) { $tag_params['onclick'] = 'return confirmLink(this, \'' . $tmp . '\')'; } unset($tmp); } - if (!empty($target)) { + if (! empty($target)) { $tag_params['target'] = htmlentities($target); } $tag_params_strings = array(); foreach ($tag_params as $par_name => $par_value) { // htmlentities() only on non javascript - $par_value = substr($par_name,0 ,2) == 'on' + $par_value = substr($par_name, 0, 2) == 'on' ? $par_value : htmlentities($par_value); $tag_params_strings[] = $par_name . '="' . $par_value . '"'; @@ -1939,8 +1943,7 @@ window.parent.updateTableTitle('<?php echo $uni_tbl; ?>', '<?php echo PMA_jsForm $ret = "\n" . '<a href="' . $url . '" ' . implode(' ', $tag_params_strings) . '>' . $message . '</a>' . "\n"; - } - else { + } else { // no spaces (linebreaks) at all // or after the hidden fields // IE will display them all @@ -2103,14 +2106,18 @@ window.parent.updateTableTitle('<?php echo $uni_tbl; ?>', '<?php echo PMA_jsForm { global $PHP_SELF, $checked_special; - if (!isset($checked_special)) $checked_special = false; + if (!isset($checked_special)) { + $checked_special = false; + } $reported_script_name = basename($PHP_SELF); $found_error = false; $error_message = ''; foreach ($params AS $param) { - if ($request && $param != 'db' && $param != 'table') $checked_special = true; + if ($request && $param != 'db' && $param != 'table') { + $checked_special = true; + } if (!isset($GLOBALS[$param])) { $error_message .= $reported_script_name . ': Missing parameter: ' . $param . ' <a href="./Documentation.html#faqmissingparameters" target="documentation"> (FAQ 2.8)</a><br />'; @@ -2313,7 +2320,7 @@ window.parent.updateTableTitle('<?php echo $uni_tbl; ?>', '<?php echo PMA_jsForm $i = $sliceStart; $x = $nbTotalPage - $sliceEnd; $met_boundary = false; - while($i <= $x) { + while ($i <= $x) { if ($i >= ($pageNow - $range) && $i <= ($pageNow + $range)) { // If our pageselector comes near the current page, we use 1 // counter increments @@ -2392,7 +2399,7 @@ window.parent.updateTableTitle('<?php echo $uni_tbl; ?>', '<?php echo PMA_jsForm } } - if ($default_current_timestamp && strpos(' ' . strtoupper($type),'TIMESTAMP') == 1) { + if ($default_current_timestamp && strpos(' ' . strtoupper($type), 'TIMESTAMP') == 1) { $query .= ' DEFAULT CURRENT_TIMESTAMP'; // 0 is empty in PHP } elseif (!empty($default) || $default == '0' || $default != $default_orig) { diff --git a/libraries/database_interface.lib.php b/libraries/database_interface.lib.php index 5fb226c6f9..7c85e5b38b 100644 --- a/libraries/database_interface.lib.php +++ b/libraries/database_interface.lib.php @@ -288,7 +288,7 @@ function PMA_DBI_get_tables_full($database, $table = false, FROM `information_schema`.`TABLES` WHERE `TABLE_SCHEMA` IN (\'' . implode("', '", $databases) . '\') ' . $sql_where_table; - $tables = PMA_DBI_fetch_result($sql, array('TABLE_SCHEMA','TABLE_NAME'), + $tables = PMA_DBI_fetch_result($sql, array('TABLE_SCHEMA', 'TABLE_NAME'), null, $link); unset( $sql_where_table, $sql ); } else { @@ -964,7 +964,7 @@ function PMA_DBI_fetch_result( $result, $key = null, $value = null, if ( is_array($key) ) { while ( $row = $fetch_function($result) ) { $result_target =& $resultrows; - foreach( $key as $key_index ) { + foreach ( $key as $key_index ) { if ( ! isset( $result_target[$row[$key_index]] ) ) { $result_target[$row[$key_index]] = array(); } @@ -981,7 +981,7 @@ function PMA_DBI_fetch_result( $result, $key = null, $value = null, if ( is_array($key) ) { while ( $row = $fetch_function($result) ) { $result_target =& $resultrows; - foreach( $key as $key_index ) { + foreach ( $key as $key_index ) { if ( ! isset( $result_target[$row[$key_index]] ) ) { $result_target[$row[$key_index]] = array(); } diff --git a/libraries/db_details_db_info.inc.php b/libraries/db_details_db_info.inc.php index cc78d3491b..32cd056a47 100644 --- a/libraries/db_details_db_info.inc.php +++ b/libraries/db_details_db_info.inc.php @@ -68,7 +68,7 @@ if ( true === $cfg['SkipLockedTables'] ) { PMA_DBI_free_result($db_info_result); if (isset($sot_cache)) { - $db_info_result = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($db) . $tbl_group_sql . ';', NULL, PMA_DBI_QUERY_STORE); + $db_info_result = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($db) . $tbl_group_sql . ';', null, PMA_DBI_QUERY_STORE); if ($db_info_result != FALSE && PMA_DBI_num_rows($db_info_result) > 0) { while ($tmp = PMA_DBI_fetch_row($db_info_result)) { if (!isset($sot_cache[$tmp[0]])) { @@ -123,7 +123,7 @@ if ( ! isset( $sot_ready ) ) { } if ( $cfg['ShowTooltip'] ) { - foreach( $tables as $each_table ) { + foreach ( $tables as $each_table ) { fillTooltip( $tooltip_truename, $tooltip_aliasname, $each_table ); } } diff --git a/libraries/db_details_links.inc.php b/libraries/db_details_links.inc.php index 0cfc531010..2dc725e994 100644 --- a/libraries/db_details_links.inc.php +++ b/libraries/db_details_links.inc.php @@ -19,7 +19,7 @@ if (empty($sub_part)) { // priv CREATE TEMPORARY TABLES or LOCK TABLES can do a 'USE mysql' // (even if they cannot see the tables) -$is_superuser = PMA_DBI_try_query('SELECT COUNT(*) FROM mysql.user', NULL, PMA_DBI_QUERY_STORE); +$is_superuser = PMA_DBI_try_query('SELECT COUNT(*) FROM mysql.user', null, PMA_DBI_QUERY_STORE); /** * Prepares links diff --git a/libraries/db_table_exists.lib.php b/libraries/db_table_exists.lib.php index ce5e33a326..a8897b2188 100644 --- a/libraries/db_table_exists.lib.php +++ b/libraries/db_table_exists.lib.php @@ -21,7 +21,7 @@ if (!isset($is_db) || !$is_db) { if (!isset($is_table) || !$is_table) { // Not a valid table name -> back to the db_details.php if (isset($table) && strlen($table)) { - $is_table = PMA_DBI_try_query('SHOW TABLES LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\';', NULL, PMA_DBI_QUERY_STORE); + $is_table = PMA_DBI_try_query('SHOW TABLES LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\';', null, PMA_DBI_QUERY_STORE); } if (! isset($table) && ! strlen($table) || !($is_table && @PMA_DBI_num_rows($is_table))) { @@ -31,7 +31,7 @@ if (!isset($is_table) || !$is_table) { if (isset($table) && strlen($table)) { PMA_DBI_free_result($is_table); // SHOW TABLES doesn't show temporary tables, so try select (as it can happen just in case temporary table, it should be fast): - $is_table2 = PMA_DBI_try_query('SELECT COUNT(*) FROM `' . PMA_sqlAddslashes($table, TRUE) . '`;', NULL, PMA_DBI_QUERY_STORE); + $is_table2 = PMA_DBI_try_query('SELECT COUNT(*) FROM `' . PMA_sqlAddslashes($table, TRUE) . '`;', null, PMA_DBI_QUERY_STORE); $redirect = !($is_table2 && @PMA_DBI_num_rows($is_table2)); PMA_DBI_free_result($is_table2); } @@ -40,8 +40,10 @@ if (!isset($is_table) || !$is_table) { PMA_sendHeaderLocation($cfg['PmaAbsoluteUri'] . 'db_details.php?' . PMA_generate_common_url($db, '', '&') . (isset($message) ? '&message=' . urlencode($message) : '') . '&reload=1'); } } - if ($redirect) exit; - } else if (isset($is_table)) { + if ($redirect) { + exit; + } + } elseif (isset($is_table)) { PMA_DBI_free_result($is_table); } } // end if (ensures table exists) diff --git a/libraries/dbg/profiling.php b/libraries/dbg/profiling.php index 54cb961a40..77d8b81391 100644 --- a/libraries/dbg/profiling.php +++ b/libraries/dbg/profiling.php @@ -67,8 +67,8 @@ if ( ! empty( $GLOBALS['DBG'] ) if ( $time_avg_hit > $GLOBALS['cfg']['DBG']['profile']['threshold'] ) { echo '<tr class="' . $odd_row ? 'odd' : 'even' . '">' . - // gma changed "$mod_name" to "substr($mod_name,$cwdlen+1)" - '<td>' . substr($mod_name,$cwdlen+1) . '</td>' . + // gma changed "$mod_name" to "substr($mod_name, $cwdlen+1)" + '<td>' . substr($mod_name, $cwdlen+1) . '</td>' . '<td>' . $line_no . '</td>' . '<td>' . $dbg_prof_results['hit_count'][$idx] . '</td>' . '<td>' . $time_avg_hit . '</td>' . diff --git a/libraries/dbi/mysql.dbi.lib.php b/libraries/dbi/mysql.dbi.lib.php index cf5d1d1112..98cb171e49 100644 --- a/libraries/dbi/mysql.dbi.lib.php +++ b/libraries/dbi/mysql.dbi.lib.php @@ -60,7 +60,7 @@ function PMA_DBI_connect($user, $password, $is_controluser = FALSE) { return $link; } -function PMA_DBI_select_db($dbname, $link = NULL) { +function PMA_DBI_select_db($dbname, $link = null) { if (empty($link)) { if (isset($GLOBALS['userlink'])) { $link = $GLOBALS['userlink']; @@ -74,7 +74,7 @@ function PMA_DBI_select_db($dbname, $link = NULL) { return mysql_select_db($dbname, $link); } -function PMA_DBI_try_query($query, $link = NULL, $options = 0) { +function PMA_DBI_try_query($query, $link = null, $options = 0) { if (empty($link)) { if (isset($GLOBALS['userlink'])) { $link = $GLOBALS['userlink']; @@ -106,7 +106,9 @@ function PMA_mysql_fetch_array($result, $type = FALSE) { } /* No data returned => do not touch it */ - if (! $data) return $data; + if (! $data) { + return $data; + } if (!defined('PMA_MYSQL_INT_VERSION') || PMA_MYSQL_INT_VERSION >= 40100 || !(isset($cfg['AllowAnywhereRecoding']) && $cfg['AllowAnywhereRecoding'] && $allow_recoding)) { @@ -121,11 +123,19 @@ function PMA_mysql_fetch_array($result, $type = FALSE) { $flags = mysql_field_flags($result, $i); /* Field is BINARY (either marked manually, or it is BLOB) => do not convert it */ if (stristr($flags, 'BINARY')) { - if (isset($data[$i])) $ret[$i] = $data[$i]; - if (isset($data[$name])) $ret[PMA_convert_display_charset($name)] = $data[$name]; + if (isset($data[$i])) { + $ret[$i] = $data[$i]; + } + if (isset($data[$name])) { + $ret[PMA_convert_display_charset($name)] = $data[$name]; + } } else { - if (isset($data[$i])) $ret[$i] = PMA_convert_display_charset($data[$i]); - if (isset($data[$name])) $ret[PMA_convert_display_charset($name)] = PMA_convert_display_charset($data[$name]); + if (isset($data[$i])) { + $ret[$i] = PMA_convert_display_charset($data[$i]); + } + if (isset($data[$name])) { + $ret[PMA_convert_display_charset($name)] = PMA_convert_display_charset($data[$name]); + } } } return $ret; @@ -165,15 +175,16 @@ function PMA_DBI_free_result() { * @param resource $link mysql link * @return string type of connection used */ -function PMA_DBI_get_host_info( $link = NULL ) { - if ( NULL === $link ) { - if ( isset( $GLOBALS['userlink'] ) ) { +function PMA_DBI_get_host_info($link = null) +{ + if (null === $link) { + if (isset($GLOBALS['userlink'])) { $link = $GLOBALS['userlink']; } else { return false; } } - return mysql_get_host_info( $link ); + return mysql_get_host_info($link); } /** @@ -183,15 +194,16 @@ function PMA_DBI_get_host_info( $link = NULL ) { * @param resource $link mysql link * @return integer version of the MySQL protocol used */ -function PMA_DBI_get_proto_info( $link = NULL ) { - if ( NULL === $link ) { - if ( isset( $GLOBALS['userlink'] ) ) { +function PMA_DBI_get_proto_info($link = null) +{ + if (null === $link) { + if (isset($GLOBALS['userlink'])) { $link = $GLOBALS['userlink']; } else { return false; } } - return mysql_get_proto_info( $link ); + return mysql_get_proto_info($link); } /** @@ -219,9 +231,10 @@ function PMA_DBI_get_client_info() { * @param resource $link mysql link * @return string|boolean $error or false */ -function PMA_DBI_getError( $link = NULL ) { - unset( $GLOBALS['errno'] ); - if ( NULL === $link && isset( $GLOBALS['userlink'] ) ) { +function PMA_DBI_getError($link = null) +{ + unset($GLOBALS['errno']); + if (null === $link && isset($GLOBALS['userlink'])) { $link =& $GLOBALS['userlink']; // Do not stop now. On the initial connection, we don't have a $link, @@ -230,38 +243,39 @@ function PMA_DBI_getError( $link = NULL ) { // return FALSE; } - if ( NULL !== $link ) { - $error_number = mysql_errno( $link ); - $error_message = mysql_error( $link ); + if (null !== $link) { + $error_number = mysql_errno($link); + $error_message = mysql_error($link); } else { $error_number = mysql_errno(); $error_message = mysql_error(); } - if ( 0 == $error_number ) { + if (0 == $error_number) { return false; } // keep the error number for further check after the call to PMA_DBI_getError() $GLOBALS['errno'] = $error_number; - if ( ! empty( $error_message ) ) { - $error_message = PMA_DBI_convert_message( $error_message ); + if (! empty($error_message)) { + $error_message = PMA_DBI_convert_message($error_message); } // Some errors messages cannot be obtained by mysql_error() - if ( $error_number == 2002 ) { + if ($error_number == 2002) { $error = '#' . ((string) $error_number) . ' - ' . $GLOBALS['strServerNotResponding'] . ' ' . $GLOBALS['strSocketProblem']; - } elseif ( $error_number == 2003 ) { - $error = '#' . ((string) $error_number ) . ' - ' . $GLOBALS['strServerNotResponding']; - } elseif ( defined('PMA_MYSQL_INT_VERSION') && PMA_MYSQL_INT_VERSION >= 40100 ) { - $error = '#' . ((string) $error_number ) . ' - ' . $error_message; + } elseif ($error_number == 2003 ) { + $error = '#' . ((string) $error_number) . ' - ' . $GLOBALS['strServerNotResponding']; + } elseif (defined('PMA_MYSQL_INT_VERSION') && PMA_MYSQL_INT_VERSION >= 40100) { + $error = '#' . ((string) $error_number) . ' - ' . $error_message; } else { - $error = '#' . ((string) $error_number ) . ' - ' . PMA_convert_display_charset( $error_message ); + $error = '#' . ((string) $error_number) . ' - ' . PMA_convert_display_charset($error_message); } return $error; } -function PMA_DBI_close($link = NULL) { +function PMA_DBI_close($link = null) +{ if (empty($link)) { if (isset($GLOBALS['userlink'])) { $link = $GLOBALS['userlink']; @@ -280,7 +294,8 @@ function PMA_DBI_num_rows($result) { } } -function PMA_DBI_insert_id($link = NULL) { +function PMA_DBI_insert_id($link = null) +{ if (empty($link)) { if (isset($GLOBALS['userlink'])) { $link = $GLOBALS['userlink']; @@ -291,7 +306,8 @@ function PMA_DBI_insert_id($link = NULL) { return mysql_insert_id($link); } -function PMA_DBI_affected_rows($link = NULL) { +function PMA_DBI_affected_rows($link = null) +{ if (empty($link)) { if (isset($GLOBALS['userlink'])) { $link = $GLOBALS['userlink']; diff --git a/libraries/dbi/mysqli.dbi.lib.php b/libraries/dbi/mysqli.dbi.lib.php index 6d411fb222..768241ba8c 100644 --- a/libraries/dbi/mysqli.dbi.lib.php +++ b/libraries/dbi/mysqli.dbi.lib.php @@ -31,7 +31,8 @@ define('NUM_FLAG', 32768); define('PART_KEY_FLAG', 16384); define('UNIQUE_FLAG', 65536); -function PMA_DBI_connect($user, $password, $is_controluser = FALSE) { +function PMA_DBI_connect($user, $password, $is_controluser = FALSE) +{ global $cfg, $php_errormsg; $server_port = (empty($cfg['Server']['port'])) @@ -44,7 +45,7 @@ function PMA_DBI_connect($user, $password, $is_controluser = FALSE) { // NULL enables connection to the default socket $server_socket = (empty($cfg['Server']['socket'])) - ? NULL + ? null : $cfg['Server']['socket']; $link = mysqli_init(); @@ -64,7 +65,8 @@ function PMA_DBI_connect($user, $password, $is_controluser = FALSE) { return $link; } -function PMA_DBI_select_db($dbname, $link = NULL) { +function PMA_DBI_select_db($dbname, $link = null) +{ if (empty($link)) { if (isset($GLOBALS['userlink'])) { $link = $GLOBALS['userlink']; @@ -78,7 +80,8 @@ function PMA_DBI_select_db($dbname, $link = NULL) { return mysqli_select_db($link, $dbname); } -function PMA_DBI_try_query($query, $link = NULL, $options = 0) { +function PMA_DBI_try_query($query, $link = null, $options = 0) +{ if ($options == ($options | PMA_DBI_QUERY_STORE)) { $method = MYSQLI_STORE_RESULT; } elseif ($options == ($options | PMA_DBI_QUERY_UNBUFFERED)) { @@ -107,7 +110,8 @@ function PMA_DBI_try_query($query, $link = NULL, $options = 0) { // The following function is meant for internal use only. // Do not call it from outside this library! -function PMA_mysqli_fetch_array($result, $type = FALSE) { +function PMA_mysqli_fetch_array($result, $type = FALSE) +{ global $cfg, $allow_recoding, $charset, $convcharset; if ($type != FALSE) { @@ -117,7 +121,9 @@ function PMA_mysqli_fetch_array($result, $type = FALSE) { } /* No data returned => do not touch it */ - if (! $data) return $data; + if (! $data) { + return $data; + } if (!defined('PMA_MYSQL_INT_VERSION') || PMA_MYSQL_INT_VERSION >= 40100 || !(isset($cfg['AllowAnywhereRecoding']) && $cfg['AllowAnywhereRecoding'] && $allow_recoding)) { @@ -167,15 +173,18 @@ function PMA_mysqli_fetch_array($result, $type = FALSE) { } } -function PMA_DBI_fetch_array($result) { +function PMA_DBI_fetch_array($result) +{ return PMA_mysqli_fetch_array($result, MYSQLI_BOTH); } -function PMA_DBI_fetch_assoc($result) { +function PMA_DBI_fetch_assoc($result) +{ return PMA_mysqli_fetch_array($result, MYSQLI_ASSOC); } -function PMA_DBI_fetch_row($result) { +function PMA_DBI_fetch_row($result) +{ return PMA_mysqli_fetch_array($result, MYSQLI_NUM); } @@ -184,10 +193,11 @@ function PMA_DBI_fetch_row($result) { * * @param result $result,... one or more mysql result resources */ -function PMA_DBI_free_result() { - foreach ( func_get_args() as $result ) { - if ( is_object($result) - && is_a($result, 'mysqli_result') ) { +function PMA_DBI_free_result() +{ + foreach (func_get_args() as $result) { + if (is_object($result) + && is_a($result, 'mysqli_result')) { mysqli_free_result($result); } } @@ -200,15 +210,16 @@ function PMA_DBI_free_result() { * @param resource $link mysql link * @return string type of connection used */ -function PMA_DBI_get_host_info( $link = NULL ) { - if ( NULL === $link ) { - if ( isset( $GLOBALS['userlink'] ) ) { +function PMA_DBI_get_host_info($link = null) +{ + if (null === $link) { + if (isset($GLOBALS['userlink'])) { $link = $GLOBALS['userlink']; } else { return false; } } - return mysqli_get_host_info( $link ); + return mysqli_get_host_info($link); } /** @@ -218,15 +229,16 @@ function PMA_DBI_get_host_info( $link = NULL ) { * @param resource $link mysql link * @return integer version of the MySQL protocol used */ -function PMA_DBI_get_proto_info( $link = NULL ) { - if ( NULL === $link ) { - if ( isset( $GLOBALS['userlink'] ) ) { +function PMA_DBI_get_proto_info( $link = null ) +{ + if (null === $link) { + if (isset($GLOBALS['userlink'])) { $link = $GLOBALS['userlink']; } else { return false; } } - return mysqli_get_proto_info( $link ); + return mysqli_get_proto_info($link); } /** @@ -256,10 +268,11 @@ function PMA_DBI_get_client_info() { * @param resource $link mysql link * @return string|boolean $error or false */ -function PMA_DBI_getError( $link = NULL ) { - unset( $GLOBALS['errno'] ); +function PMA_DBI_getError($link = null) +{ + unset($GLOBALS['errno']); - if ( NULL === $link && isset( $GLOBALS['userlink'] ) ) { + if (null === $link && isset($GLOBALS['userlink'])) { $link =& $GLOBALS['userlink']; // Do not stop now. We still can get the error code // with mysqli_connect_errno() @@ -267,27 +280,27 @@ function PMA_DBI_getError( $link = NULL ) { // return false; } - if ( NULL !== $link ) { - $error_number = mysqli_errno( $link ); - $error_message = mysqli_error( $link ); + if (null !== $link) { + $error_number = mysqli_errno($link); + $error_message = mysqli_error($link); } else { $error_number = mysqli_connect_errno(); $error_message = mysqli_connect_error(); } - if ( 0 == $error_number ) { + if (0 == $error_number) { return false; } // keep the error number for further check after the call to PMA_DBI_getError() $GLOBALS['errno'] = $error_number; - if ( ! empty( $error_message ) ) { - $error_message = PMA_DBI_convert_message( $error_message ); + if (! empty($error_message)) { + $error_message = PMA_DBI_convert_message($error_message); } - if ( $error_number == 2002 ) { + if ($error_number == 2002) { $error = '#' . ((string) $error_number) . ' - ' . $GLOBALS['strServerNotResponding'] . ' ' . $GLOBALS['strSocketProblem']; - } elseif ( defined( 'PMA_MYSQL_INT_VERSION' ) && PMA_MYSQL_INT_VERSION >= 40100 ) { + } elseif (defined('PMA_MYSQL_INT_VERSION') && PMA_MYSQL_INT_VERSION >= 40100) { $error = '#' . ((string) $error_number) . ' - ' . $error_message; } else { $error = '#' . ((string) $error_number) . ' - ' . PMA_convert_display_charset($error_message); @@ -295,7 +308,8 @@ function PMA_DBI_getError( $link = NULL ) { return $error; } -function PMA_DBI_close($link = NULL) { +function PMA_DBI_close($link = null) +{ if (empty($link)) { if (isset($GLOBALS['userlink'])) { $link = $GLOBALS['userlink']; @@ -306,7 +320,8 @@ function PMA_DBI_close($link = NULL) { return @mysqli_close($link); } -function PMA_DBI_num_rows($result) { +function PMA_DBI_num_rows($result) +{ // see the note for PMA_DBI_try_query(); if (!is_bool($result)) { return @mysqli_num_rows($result); @@ -315,7 +330,8 @@ function PMA_DBI_num_rows($result) { } } -function PMA_DBI_insert_id($link = '') { +function PMA_DBI_insert_id($link = '') +{ if (empty($link)) { if (isset($GLOBALS['userlink'])) { $link = $GLOBALS['userlink']; @@ -326,7 +342,8 @@ function PMA_DBI_insert_id($link = '') { return mysqli_insert_id($link); } -function PMA_DBI_affected_rows($link = NULL) { +function PMA_DBI_affected_rows($link = null) +{ if (empty($link)) { if (isset($GLOBALS['userlink'])) { $link = $GLOBALS['userlink']; @@ -337,7 +354,8 @@ function PMA_DBI_affected_rows($link = NULL) { return mysqli_affected_rows($link); } -function PMA_DBI_get_fields_meta($result) { +function PMA_DBI_get_fields_meta($result) +{ // Build an associative array for a type look up $typeAr = Array(); $typeAr[MYSQLI_TYPE_DECIMAL] = 'real'; @@ -392,23 +410,27 @@ function PMA_DBI_get_fields_meta($result) { return $fields; } -function PMA_DBI_num_fields($result) { +function PMA_DBI_num_fields($result) +{ return mysqli_num_fields($result); } -function PMA_DBI_field_len($result, $i) { +function PMA_DBI_field_len($result, $i) +{ $info = mysqli_fetch_field_direct($result, $i); // stdClass::$length will be integrated in // mysqli-ext when mysql4.1 has been released. return @$info->length; } -function PMA_DBI_field_name($result, $i) { +function PMA_DBI_field_name($result, $i) +{ $info = mysqli_fetch_field_direct($result, $i); return $info->name; } -function PMA_DBI_field_flags($result, $i) { +function PMA_DBI_field_flags($result, $i) +{ $f = mysqli_fetch_field_direct($result, $i); $f = $f->flags; $flags = ''; diff --git a/libraries/display_create_database.lib.php b/libraries/display_create_database.lib.php index 2ff5730182..319307c9a8 100644 --- a/libraries/display_create_database.lib.php +++ b/libraries/display_create_database.lib.php @@ -17,7 +17,7 @@ if ($is_create_db_priv) { <?php if (PMA_MYSQL_INT_VERSION >= 40101) { require_once('./libraries/mysql_charsets.lib.php'); - echo PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION, 'db_collation', NULL, NULL, TRUE, 5); + echo PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION, 'db_collation', null, null, TRUE, 5); } ?> <input type="submit" value="<?php echo $strCreate; ?>" id="buttonGo" /> diff --git a/libraries/display_create_table.lib.php b/libraries/display_create_table.lib.php index 3aec0a8d52..ad00e1938a 100644 --- a/libraries/display_create_table.lib.php +++ b/libraries/display_create_table.lib.php @@ -22,7 +22,7 @@ if (PMA_MYSQL_INT_VERSION >= 40100) { $is_create_table_priv = true; } -foreach( $dbs_where_create_table_allowed as $allowed_db ) { +foreach ( $dbs_where_create_table_allowed as $allowed_db ) { // if we find the exact db name, we stop here if ($allowed_db == $db) { diff --git a/libraries/display_export.lib.php b/libraries/display_export.lib.php index cdb913095a..223811a234 100644 --- a/libraries/display_export.lib.php +++ b/libraries/display_export.lib.php @@ -853,7 +853,7 @@ function show_checked_option() { $temp_charset = reset($cfg['AvailableCharsets']); echo ' <select id="select_charset_of_file" name="charset_of_file" size="1">' . "\n"; - foreach($cfg['AvailableCharsets'] as $key => $temp_charset) { + foreach ($cfg['AvailableCharsets'] as $key => $temp_charset) { echo ' <option value="' . $temp_charset . '"'; if ((empty($cfg['Export']['charset']) && $temp_charset == $charset) || $temp_charset == $cfg['Export']['charset']) { diff --git a/libraries/display_import.lib.php b/libraries/display_import.lib.php index b4652b2d2d..1bedc3623d 100644 --- a/libraries/display_import.lib.php +++ b/libraries/display_import.lib.php @@ -48,8 +48,10 @@ echo PMA_pluginGetJavascript($import_list); <?php if (!empty($cfg['UploadDir'])) { $extensions = ''; - foreach($import_list as $key => $val) { - if (!empty($extensions)) $extensions .= '|'; + foreach ($import_list as $key => $val) { + if (!empty($extensions)) { + $extensions .= '|'; + } $extensions .= $val['extension']; } $matcher = '@\.(' . $extensions . ')(\.(' . PMA_supportedDecompressions() . '))?$@'; @@ -101,9 +103,15 @@ echo '</div>' . "\n"; // zip, gzip and bzip2 encode features $compressions = $strNone; -if ($cfg['GZipDump'] && @function_exists('gzopen')) $compressions .= ', gzip'; -if ($cfg['BZipDump'] && @function_exists('bzopen')) $compressions .= ', bzip2'; -if ($cfg['ZipDump'] && @function_exists('gzinflate')) $compressions .= ', zip'; +if ($cfg['GZipDump'] && @function_exists('gzopen')) { + $compressions .= ', gzip'; +} +if ($cfg['BZipDump'] && @function_exists('bzopen')) { + $compressions .= ', bzip2'; +} +if ($cfg['ZipDump'] && @function_exists('gzinflate')) { + $compressions .= ', zip'; +} // We don't have show anything about compression, when no supported if ($compressions != $strNone) { diff --git a/libraries/display_tbl.lib.php b/libraries/display_tbl.lib.php index a7e212531b..11c3de6153 100644 --- a/libraries/display_tbl.lib.php +++ b/libraries/display_tbl.lib.php @@ -86,7 +86,7 @@ function PMA_setDisplayMode(&$the_disp_mode, &$the_total) // 2.1 Statement is a "SELECT COUNT", a // "CHECK/ANALYZE/REPAIR/OPTIMIZE", an "EXPLAIN" one or // contains a "PROC ANALYSE" part - else if ($GLOBALS['is_count'] || $GLOBALS['is_analyse'] || $GLOBALS['is_maint'] || $GLOBALS['is_explain']) { + elseif ($GLOBALS['is_count'] || $GLOBALS['is_analyse'] || $GLOBALS['is_maint'] || $GLOBALS['is_explain']) { $do_display['edit_lnk'] = 'nn'; // no edit link $do_display['del_lnk'] = 'nn'; // no delete link $do_display['sort_lnk'] = (string) '0'; @@ -101,14 +101,13 @@ function PMA_setDisplayMode(&$the_disp_mode, &$the_total) $do_display['pview_lnk'] = (string) '1'; } // 2.2 Statement is a "SHOW..." - else if ($GLOBALS['is_show']) { + elseif ($GLOBALS['is_show']) { // 2.2.1 TODO : defines edit/delete links depending on show statement $tmp = preg_match('@^SHOW[[:space:]]+(VARIABLES|(FULL[[:space:]]+)?PROCESSLIST|STATUS|TABLE|GRANTS|CREATE|LOGS|DATABASES|FIELDS)@i', $GLOBALS['sql_query'], $which = array() ); if (isset($which[1]) && strpos(' ' . strtoupper($which[1]), 'PROCESSLIST') > 0) { $do_display['edit_lnk'] = 'nn'; // no edit link $do_display['del_lnk'] = 'kp'; // "kill process" type edit link - } - else { + } else { // Default case -> no links $do_display['edit_lnk'] = 'nn'; // no edit link $do_display['del_lnk'] = 'nn'; // no delete link @@ -155,8 +154,7 @@ function PMA_setDisplayMode(&$the_disp_mode, &$the_total) // 3. Gets the total number of rows if it is unknown if (isset($unlim_num_rows) && $unlim_num_rows != '') { $the_total = $unlim_num_rows; - } - else if (($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1') + } elseif (($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1') && (isset($db) && strlen($db) && !empty($table))) { $the_total = PMA_countRecords($db, $table, TRUE); } @@ -477,10 +475,10 @@ function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $ // we need $sort_expression and $sort_expression_nodir // even if there are many table references - $sort_expression = trim(str_replace(' ', ' ',$analyzed_sql[0]['order_by_clause'])); + $sort_expression = trim(str_replace(' ', ' ', $analyzed_sql[0]['order_by_clause'])); // Get rid of ASC|DESC (TODO: analyzer) - preg_match('@(.*)([[:space:]]*(ASC|DESC))@si',$sort_expression,$matches = array()); + preg_match('@(.*)([[:space:]]*(ASC|DESC))@si', $sort_expression, $matches = array()); $sort_expression_nodir = isset($matches[1]) ? trim($matches[1]) : $sort_expression; // sorting by indexes, only if it makes sense (only one table ref) @@ -526,9 +524,15 @@ function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $ if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') { $span = $fields_cnt; - if ($is_display['edit_lnk'] != 'nn') $span++; - if ($is_display['del_lnk'] != 'nn') $span++; - if ($is_display['del_lnk'] != 'kp' && $is_display['del_lnk'] != 'nn') $span++; + if ($is_display['edit_lnk'] != 'nn') { + $span++; + } + if ($is_display['del_lnk'] != 'nn') { + $span++; + } + if ($is_display['del_lnk'] != 'kp' && $is_display['del_lnk'] != 'nn') { + $span++; + } } else { $span = $num_rows + floor($num_rows/$repeat_cells) + 1; } @@ -651,7 +655,7 @@ function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $ } // end vertical mode } - // ... else if no button, displays empty(ies) col(s) if required + // ... elseif no button, displays empty(ies) col(s) if required elseif ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')) { $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 0; @@ -807,10 +811,10 @@ function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $ // enable sord order swapping for image $order_link_params = array(); if (isset($order_img) && $order_img!='') { - if (strstr($order_img,'asc')) { + if (strstr($order_img, 'asc')) { $order_link_params['onmouseover'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }'; $order_link_params['onmouseout'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }'; - } else if (strstr($order_img,'desc')) { + } elseif (strstr($order_img, 'desc')) { $order_link_params['onmouseover'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }'; $order_link_params['onmouseout'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }'; } @@ -825,7 +829,7 @@ function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $ if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') { ?> -<th <?php echo $column_style; ?> <?php if ($disp_direction == 'horizontalflipped') echo 'valign="bottom"'; ?>> +<th <?php echo $column_style; ?> <?php if ($disp_direction == 'horizontalflipped') { echo 'valign="bottom"'; } ?>> <?php echo $order_link; ?> <?php echo $comments; ?> </th> @@ -841,7 +845,7 @@ function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $ else { if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') { ?> -<th <?php echo $column_style; ?> <?php if ($disp_direction == 'horizontalflipped') echo 'valign="bottom"'; ?> <?php echo ($disp_direction == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'css' ? 'style="direction: ltr; writing-mode: tb-rl;"' : ''); ?>> +<th <?php echo $column_style; ?> <?php if ($disp_direction == 'horizontalflipped') { echo 'valign="bottom"'; } ?> <?php echo ($disp_direction == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'css' ? 'style="direction: ltr; writing-mode: tb-rl;"' : ''); ?>> <?php echo ($disp_direction == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'fake'? PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), "<br />\n") : htmlspecialchars($fields_meta[$i]->name)) . "\n"; ?> <?php echo $comments; ?> </th> @@ -875,9 +879,9 @@ function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $ } // end vertical mode } - // ... else if no button, displays empty cols if required + // ... elseif no button, displays empty cols if required // (unless coming from Browse mode print view) - else if ($GLOBALS['cfg']['ModifyDeleteAtRight'] + elseif ($GLOBALS['cfg']['ModifyDeleteAtRight'] && ($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn') && (!$GLOBALS['is_header_sent'])) { $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 1; @@ -1118,7 +1122,7 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) { $del_str .= ' ' . $GLOBALS['strDelete'] . '</div>'; } } - } else if ($is_display['del_lnk'] == 'kp') { // kill process case + } elseif ($is_display['del_lnk'] == 'kp') { // kill process case $lnk_goto = 'sql.php' . '?' . str_replace('&', '&', $url_query) . '&sql_query=' . urlencode($url_sql_query) @@ -1223,7 +1227,7 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) { //if (!isset($row[$meta->name]) if (!isset($row[$i]) || is_null($row[$i])) { $vertical_display['data'][$row_no][$i] = ' <td align="right"' . $column_style . $bgcolor . '><i>NULL</i></td>' . "\n"; - } else if ($row[$i] != '') { + } elseif ($row[$i] != '') { $vertical_display['data'][$row_no][$i] = ' <td align="right"' . $column_style . $bgcolor . ' class="nowrap">'; if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) { @@ -1245,16 +1249,14 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) { . ' FROM ' . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . ' = ' . $row[$i]; - $dispresult = PMA_DBI_try_query($dispsql, NULL, PMA_DBI_QUERY_STORE); + $dispresult = PMA_DBI_try_query($dispsql, null, PMA_DBI_QUERY_STORE); if ($dispresult && PMA_DBI_num_rows($dispresult) > 0) { list($dispval) = PMA_DBI_fetch_row($dispresult, 0); - } - else { + } else { $dispval = $GLOBALS['strLinkNotFound']; } @PMA_DBI_free_result($dispresult); - } - else { + } else { $dispval = ''; } // end if... else... @@ -1279,7 +1281,7 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) { // b l o b - } else if ($GLOBALS['cfg']['ShowBlob'] == FALSE && stristr($meta->type, 'BLOB')) { + } elseif ($GLOBALS['cfg']['ShowBlob'] == FALSE && stristr($meta->type, 'BLOB')) { // loic1 : PMA_mysql_fetch_fields returns BLOB in place of // TEXT fields type, however TEXT fields must be displayed // even if $GLOBALS['cfg']['ShowBlob'] is false -> get the true type @@ -1302,7 +1304,7 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) { } else { if (!isset($row[$i]) || is_null($row[$i])) { $vertical_display['data'][$row_no][$i] = ' <td' . $column_style . $bgcolor . '><i>NULL</i></td>' . "\n"; - } else if ($row[$i] != '') { + } elseif ($row[$i] != '') { // garvin: if a transform function for blob is set, none of these replacements will be made if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && ($dontlimitchars != 1)) { $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...'; @@ -1319,7 +1321,7 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) { } else { if (!isset($row[$i]) || is_null($row[$i])) { $vertical_display['data'][$row_no][$i] = ' <td' . $column_style . $bgcolor . '><i>NULL</i></td>' . "\n"; - } else if ($row[$i] != '') { + } elseif ($row[$i] != '') { // loic1: support blanks in the key $relation_id = $row[$i]; @@ -1371,16 +1373,14 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) { . ' FROM ' . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . ' = \'' . PMA_sqlAddslashes($row[$i]) . '\''; - $dispresult = PMA_DBI_try_query($dispsql, NULL, PMA_DBI_QUERY_STORE); + $dispresult = PMA_DBI_try_query($dispsql, null, PMA_DBI_QUERY_STORE); if ($dispresult && PMA_DBI_num_rows($dispresult) > 0) { list($dispval) = PMA_DBI_fetch_row($dispresult); @PMA_DBI_free_result($dispresult); - } - else { + } else { $dispval = $GLOBALS['strLinkNotFound']; } - } - else { + } else { $dispval = ''; } $title = (!empty($dispval))? ' title="' . htmlspecialchars($dispval) . '"' : ''; @@ -1716,7 +1716,7 @@ function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql) ? $total - 1 : $pos_next - 1; PMA_showMessage($GLOBALS['strShowingRecords'] . " $pos - $last_shown_rec (" . PMA_formatNumber( $total, 0 ) . ' ' . $GLOBALS['strTotal'] . $selectstring . ', ' . sprintf($GLOBALS['strQueryTime'], $GLOBALS['querytime']) . ')'); - } else if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') { + } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') { PMA_showMessage($GLOBALS['strSQLQuery']); } @@ -1735,7 +1735,7 @@ function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql) if ($is_display['nav_bar'] == '1') { PMA_displayTableNavigation($pos_next, $pos_prev, $encoded_sql_query); echo "\n"; - } else if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') { + } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') { echo "\n" . '<br /><br />' . "\n"; } @@ -1762,7 +1762,7 @@ function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql) $exist_rel = PMA_getForeigners($db, $table, '', 'both'); if ($exist_rel) { foreach ($exist_rel AS $master_field => $rel) { - $display_field = PMA_getDisplayField($rel['foreign_db'],$rel['foreign_table']); + $display_field = PMA_getDisplayField($rel['foreign_db'], $rel['foreign_table']); $map[$master_field] = array($rel['foreign_table'], $rel['foreign_field'], $display_field, @@ -1862,7 +1862,7 @@ function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql) if ($is_display['nav_bar'] == '1') { echo '<br />' . "\n"; PMA_displayTableNavigation($pos_next, $pos_prev, $encoded_sql_query); - } else if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') { + } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') { echo "\n" . '<br /><br />' . "\n"; } } // end of the 'PMA_displayTable()' function diff --git a/libraries/display_tbl_links.lib.php b/libraries/display_tbl_links.lib.php index b09496c605..2264c1354c 100644 --- a/libraries/display_tbl_links.lib.php +++ b/libraries/display_tbl_links.lib.php @@ -28,7 +28,7 @@ if ( $doWriteModifyAt == 'left' ){ . PMA_linkOrButton($del_url, $del_str, (isset($js_conf) ? $js_conf : ''), FALSE) . ' </td>' . "\n"; } -} else if ($doWriteModifyAt == 'right') { +} elseif ($doWriteModifyAt == 'right') { if (!empty($del_url)) { echo ' <td align="center">' . "\n" . PMA_linkOrButton($del_url, $del_str, (isset($js_conf) ? $js_conf : ''), FALSE) diff --git a/libraries/export/csv.php b/libraries/export/csv.php index 431c60d82f..180f66a317 100644 --- a/libraries/export/csv.php +++ b/libraries/export/csv.php @@ -124,7 +124,7 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { global $escaped; // Gets the data from the database - $result = PMA_DBI_query($sql_query, NULL, PMA_DBI_QUERY_UNBUFFERED); + $result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED); $fields_cnt = PMA_DBI_num_fields($result); // If required, get fields name at the first line @@ -141,7 +141,9 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { $schema_insert .= $export_separator; } // end for $schema_insert =trim(substr($schema_insert, 0, -1)); - if (!PMA_exportOutputHandler($schema_insert . $add_character)) return FALSE; + if (!PMA_exportOutputHandler($schema_insert . $add_character)) { + return FALSE; + } } // end if // Format the data @@ -150,8 +152,7 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { for ($j = 0; $j < $fields_cnt; $j++) { if (!isset($row[$j]) || is_null($row[$j])) { $schema_insert .= $GLOBALS[$what . '_replace_null']; - } - else if ($row[$j] == '0' || $row[$j] != '') { + } elseif ($row[$j] == '0' || $row[$j] != '') { // loic1 : always enclose fields if ($what == 'excel') { $row[$j] = ereg_replace("\015(\012)?", "\012", $row[$j]); @@ -163,8 +164,7 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { . str_replace($enclosed, $escaped . $enclosed, $row[$j]) . $enclosed; } - } - else { + } else { $schema_insert .= ''; } if ($j < $fields_cnt-1) { @@ -172,7 +172,9 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { } } // end for - if (!PMA_exportOutputHandler($schema_insert . $add_character)) return FALSE; + if (!PMA_exportOutputHandler($schema_insert . $add_character)) { + return FALSE; + } } // end while PMA_DBI_free_result($result); diff --git a/libraries/export/htmlexcel.php b/libraries/export/htmlexcel.php index 01ea416eb4..d2788750aa 100644 --- a/libraries/export/htmlexcel.php +++ b/libraries/export/htmlexcel.php @@ -122,7 +122,7 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { global $what; // Gets the data from the database - $result = PMA_DBI_query($sql_query, NULL, PMA_DBI_QUERY_UNBUFFERED); + $result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED); $fields_cnt = PMA_DBI_num_fields($result); // If required, get fields name at the first line @@ -132,7 +132,9 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { $schema_insert .= '<td class=xl2216681 nowrap><b>' . htmlspecialchars(stripslashes(PMA_DBI_field_name($result, $i))) . '</b></td>'; } // end for $schema_insert .= '</tr>'; - if (!PMA_exportOutputHandler($schema_insert)) return FALSE; + if (!PMA_exportOutputHandler($schema_insert)) { + return FALSE; + } } // end if // Format the data @@ -141,7 +143,7 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { for ($j = 0; $j < $fields_cnt; $j++) { if (!isset($row[$j]) || is_null($row[$j])) { $value = $GLOBALS[$what . '_replace_null']; - } else if ($row[$j] == '0' || $row[$j] != '') { + } elseif ($row[$j] == '0' || $row[$j] != '') { $value = $row[$j]; } else { $value = ''; @@ -149,7 +151,9 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { $schema_insert .= '<td class=xl2216681 nowrap>' . htmlspecialchars($value) . '</td>'; } // end for $schema_insert .= '</tr>'; - if (!PMA_exportOutputHandler($schema_insert)) return FALSE; + if (!PMA_exportOutputHandler($schema_insert)) { + return FALSE; + } } // end while PMA_DBI_free_result($result); diff --git a/libraries/export/htmlword.php b/libraries/export/htmlword.php index 72a991f59c..7a4794c632 100644 --- a/libraries/export/htmlword.php +++ b/libraries/export/htmlword.php @@ -101,14 +101,19 @@ function PMA_exportDBCreate($db) { * * @access public */ -function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { +function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) +{ global $what; - if (!PMA_exportOutputHandler('<h2>' . $GLOBALS['strDumpingData'] . ' ' .$table . '</h2>')) return FALSE; - if (!PMA_exportOutputHandler('<table class="width100" cellspacing="1">')) return FALSE; + if (!PMA_exportOutputHandler('<h2>' . $GLOBALS['strDumpingData'] . ' ' . $table . '</h2>')) { + return FALSE; + } + if (!PMA_exportOutputHandler('<table class="width100" cellspacing="1">')) { + return FALSE; + } // Gets the data from the database - $result = PMA_DBI_query($sql_query, NULL, PMA_DBI_QUERY_UNBUFFERED); + $result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED); $fields_cnt = PMA_DBI_num_fields($result); // If required, get fields name at the first line @@ -118,7 +123,9 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { $schema_insert .= '<td class="print"><b>' . htmlspecialchars(stripslashes(PMA_DBI_field_name($result, $i))) . '</b></td>'; } // end for $schema_insert .= '</tr>'; - if (!PMA_exportOutputHandler($schema_insert)) return FALSE; + if (!PMA_exportOutputHandler($schema_insert)) { + return FALSE; + } } // end if // Format the data @@ -127,7 +134,7 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { for ($j = 0; $j < $fields_cnt; $j++) { if (!isset($row[$j]) || is_null($row[$j])) { $value = $GLOBALS[$what . '_replace_null']; - } else if ($row[$j] == '0' || $row[$j] != '') { + } elseif ($row[$j] == '0' || $row[$j] != '') { $value = $row[$j]; } else { $value = ''; @@ -135,10 +142,14 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { $schema_insert .= '<td class="print">' . htmlspecialchars($value) . '</td>'; } // end for $schema_insert .= '</tr>'; - if (!PMA_exportOutputHandler($schema_insert)) return FALSE; + if (!PMA_exportOutputHandler($schema_insert)) { + return FALSE; + } } // end while PMA_DBI_free_result($result); - if (!PMA_exportOutputHandler('</table>')) return FALSE; + if (!PMA_exportOutputHandler('</table>')) { + return FALSE; + } return TRUE; } @@ -147,7 +158,9 @@ function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = fals { global $cfgRelation; - if (!PMA_exportOutputHandler('<h2>' . $GLOBALS['strTableStructure'] . ' ' .$table . '</h2>')) return FALSE; + if (!PMA_exportOutputHandler('<h2>' . $GLOBALS['strTableStructure'] . ' ' .$table . '</h2>')) { + return FALSE; + } /** * Get the unique keys in the table @@ -156,7 +169,9 @@ function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = fals $keys_result = PMA_DBI_query($keys_query); $unique_keys = array(); while ($key = PMA_DBI_fetch_assoc($keys_result)) { - if ($key['Non_unique'] == 0) $unique_keys[] = $key['Column_name']; + if ($key['Non_unique'] == 0) { + $unique_keys[] = $key['Column_name']; + } } PMA_DBI_free_result($keys_result); @@ -179,15 +194,16 @@ function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = fals } else { $have_rel = FALSE; } - } - else { + } else { $have_rel = FALSE; } // end if /** * Displays the table structure */ - if (!PMA_exportOutputHandler('<table class="width100" cellspacing="1">')) return FALSE; + if (!PMA_exportOutputHandler('<table class="width100" cellspacing="1">')) { + return FALSE; + } $columns_cnt = 4; if ($do_relation && $have_rel) { @@ -218,7 +234,9 @@ function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = fals } $schema_insert .= '</tr>'; - if (!PMA_exportOutputHandler($schema_insert)) return FALSE; + if (!PMA_exportOutputHandler($schema_insert)) { + return FALSE; + } while ($row = PMA_DBI_fetch_assoc($result)) { @@ -294,7 +312,9 @@ function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = fals $schema_insert .= '</tr>'; - if (!PMA_exportOutputHandler($schema_insert)) return FALSE; + if (!PMA_exportOutputHandler($schema_insert)) { + return FALSE; + } } // end while PMA_DBI_free_result($result); diff --git a/libraries/export/latex.php b/libraries/export/latex.php index 78d302c4d3..4b74142ae8 100644 --- a/libraries/export/latex.php +++ b/libraries/export/latex.php @@ -129,7 +129,7 @@ function PMA_exportDBCreate($db) { * @access public */ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { - $result = PMA_DBI_try_query($sql_query, NULL, PMA_DBI_QUERY_UNBUFFERED); + $result = PMA_DBI_try_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED); $columns_cnt = PMA_DBI_num_fields($result); for ($i = 0; $i < $columns_cnt; $i++) { @@ -150,7 +150,9 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { $buffer .= ' \\caption{' . str_replace('__TABLE__', PMA_texEscape($table), $GLOBALS['latex_data_caption']) . '} \\label{' . str_replace('__TABLE__', $table, $GLOBALS['latex_data_label']) . '} \\\\'; } - if (!PMA_exportOutputHandler($buffer)) return FALSE; + if (!PMA_exportOutputHandler($buffer)) { + return FALSE; + } // show column names if (isset($GLOBALS['latex_showcolumns'])) { @@ -159,14 +161,20 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { $buffer .= '\\multicolumn{1}{|c|}{\\textbf{' . PMA_texEscape(stripslashes($columns[$i])) . '}} & '; } - $buffer = substr($buffer,0,-2) . '\\\\ \\hline \hline '; - if (!PMA_exportOutputHandler($buffer . ' \\endfirsthead ' . $crlf)) return FALSE; + $buffer = substr($buffer, 0, -2) . '\\\\ \\hline \hline '; + if (!PMA_exportOutputHandler($buffer . ' \\endfirsthead ' . $crlf)) { + return FALSE; + } if (isset($GLOBALS['latex_caption'])) { if (!PMA_exportOutputHandler('\\caption{' . str_replace('__TABLE__', PMA_texEscape($table), $GLOBALS['latex_data_continued_caption']) . '} \\\\ ')) return FALSE; } - if (!PMA_exportOutputHandler($buffer . '\\endhead \\endfoot' . $crlf)) return FALSE; + if (!PMA_exportOutputHandler($buffer . '\\endhead \\endfoot' . $crlf)) { + return FALSE; + } } else { - if (!PMA_exportOutputHandler('\\\\ \hline')) return FALSE; + if (!PMA_exportOutputHandler('\\\\ \hline')) { + return FALSE; + } } // print the whole table @@ -189,11 +197,15 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { } } $buffer .= ' \\\\ \\hline ' . $crlf; - if (!PMA_exportOutputHandler($buffer)) return FALSE; + if (!PMA_exportOutputHandler($buffer)) { + return FALSE; + } } $buffer = ' \\end{longtable}' . $crlf; - if (!PMA_exportOutputHandler($buffer)) return FALSE; + if (!PMA_exportOutputHandler($buffer)) { + return FALSE; + } PMA_DBI_free_result($result); return TRUE; @@ -227,7 +239,9 @@ function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = fals $keys_result = PMA_DBI_query($keys_query); $unique_keys = array(); while ($key = PMA_DBI_fetch_assoc($keys_result)) { - if ($key['Non_unique'] == 0) $unique_keys[] = $key['Column_name']; + if ($key['Non_unique'] == 0) { + $unique_keys[] = $key['Column_name']; + } } PMA_DBI_free_result($keys_result); @@ -250,8 +264,7 @@ function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = fals } else { $have_rel = FALSE; } - } - else { + } else { $have_rel = FALSE; } // end if @@ -260,7 +273,9 @@ function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = fals */ $buffer = $crlf . '%' . $crlf . '% ' . $GLOBALS['strStructure'] . ': ' . $table . $crlf . '%' . $crlf . ' \\begin{longtable}{'; - if (!PMA_exportOutputHandler($buffer)) return FALSE; + if (!PMA_exportOutputHandler($buffer)) { + return FALSE; + } $columns_cnt = 4; $alignment = '|l|c|c|c|'; @@ -308,7 +323,9 @@ function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = fals } $buffer .= $header . ' \\\\ \\hline \\hline \\endhead \\endfoot '; - if (!PMA_exportOutputHandler($buffer)) return FALSE; + if (!PMA_exportOutputHandler($buffer)) { + return FALSE; + } while ($row = PMA_DBI_fetch_assoc($result)) { @@ -379,16 +396,18 @@ function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = fals $local_buffer = PMA_texEscape($local_buffer); if ($row['Key']=='PRI') { $pos=strpos($local_buffer, "\000"); - $local_buffer = '\\textit{' . substr($local_buffer,0,$pos) . '}' . substr($local_buffer,$pos); + $local_buffer = '\\textit{' . substr($local_buffer, 0, $pos) . '}' . substr($local_buffer, $pos); } if (in_array($field_name, $unique_keys)) { $pos=strpos($local_buffer, "\000"); - $local_buffer = '\\textbf{' . substr($local_buffer,0,$pos) . '}' . substr($local_buffer,$pos); + $local_buffer = '\\textbf{' . substr($local_buffer, 0, $pos) . '}' . substr($local_buffer, $pos); } $buffer = str_replace("\000", ' & ', $local_buffer); $buffer .= ' \\\\ \\hline ' . $crlf; - if (!PMA_exportOutputHandler($buffer)) return FALSE; + if (!PMA_exportOutputHandler($buffer)) { + return FALSE; + } } // end while PMA_DBI_free_result($result); diff --git a/libraries/export/pdf.php b/libraries/export/pdf.php index b434f6b8b6..6237005942 100644 --- a/libraries/export/pdf.php +++ b/libraries/export/pdf.php @@ -83,7 +83,7 @@ class PMA_PDF extends PMA_FPDF } $this->SetY(($this->tMargin) - ($this->FontSizePt/$this->k)*2); $this->cellFontSize = $this->FontSizePt ; - $this->SetFont(PMA_PDF_FONT, '' ,($this->titleFontSize ? $this->titleFontSize : $this->FontSizePt )); + $this->SetFont(PMA_PDF_FONT, '', ($this->titleFontSize ? $this->titleFontSize : $this->FontSizePt)); $this->Cell(0, $this->FontSizePt, $this->titleText, 0, 1, 'C'); $l = ($this->lMargin); $this->SetFont(PMA_PDF_FONT, '', $this->cellFontSize); @@ -204,7 +204,7 @@ class PMA_PDF extends PMA_FPDF // Pass 1 for column widths // TODO: force here a LIMIT to speed up pass 1 ? - $this->results = PMA_DBI_query($query, NULL, PMA_DBI_QUERY_UNBUFFERED); + $this->results = PMA_DBI_query($query, null, PMA_DBI_QUERY_UNBUFFERED); $this->numFields = PMA_DBI_num_fields($this->results); $this->fields = PMA_DBI_get_fields_meta($this->results); @@ -272,7 +272,7 @@ class PMA_PDF extends PMA_FPDF // Pass 2 - $this->results = PMA_DBI_query($query, NULL, PMA_DBI_QUERY_UNBUFFERED); + $this->results = PMA_DBI_query($query, null, PMA_DBI_QUERY_UNBUFFERED); $this->Open(); $this->setY($this->tMargin); $this->AddPage(); diff --git a/libraries/export/sql.php b/libraries/export/sql.php index daebc9f835..ff2ed33be9 100644 --- a/libraries/export/sql.php +++ b/libraries/export/sql.php @@ -14,7 +14,7 @@ $GLOBALS['comment_marker'] = '-- '; * Avoids undefined variables, use NULL so isset() returns false */ if ( ! isset( $use_backquotes ) ) { - $use_backquotes = NULL; + $use_backquotes = null; } /** @@ -24,7 +24,8 @@ if ( ! isset( $use_backquotes ) ) { * * @return bool Whether it suceeded */ -function PMA_exportComment($text) { +function PMA_exportComment($text) +{ return PMA_exportOutputHandler($GLOBALS['comment_marker'] . $text . $GLOBALS['crlf']); } @@ -35,7 +36,8 @@ function PMA_exportComment($text) { * * @access public */ -function PMA_exportFooter() { +function PMA_exportFooter() +{ global $crlf; $foot = ''; @@ -58,7 +60,8 @@ function PMA_exportFooter() { * * @access public */ -function PMA_exportHeader() { +function PMA_exportHeader() +{ global $crlf; global $cfg; @@ -107,10 +110,13 @@ function PMA_exportHeader() { * * @access public */ -function PMA_exportDBCreate($db) { +function PMA_exportDBCreate($db) +{ global $crlf; if (isset($GLOBALS['drop_database'])) { - if (!PMA_exportOutputHandler('DROP DATABASE ' . (isset($GLOBALS['use_backquotes']) ? PMA_backquote($db) : $db) . ';' . $crlf)) return FALSE; + if (!PMA_exportOutputHandler('DROP DATABASE ' . (isset($GLOBALS['use_backquotes']) ? PMA_backquote($db) : $db) . ';' . $crlf)) { + return FALSE; + } } $create_query = 'CREATE DATABASE ' . (isset($GLOBALS['use_backquotes']) ? PMA_backquote($db) : $db); if (PMA_MYSQL_INT_VERSION >= 40101) { @@ -122,7 +128,9 @@ function PMA_exportDBCreate($db) { } } $create_query .= ';' . $crlf; - if (!PMA_exportOutputHandler($create_query)) return FALSE; + if (!PMA_exportOutputHandler($create_query)) { + return FALSE; + } if (isset($GLOBALS['use_backquotes']) && PMA_MYSQL_INT_VERSION >= 40100 && isset($GLOBALS['sql_compat']) && $GLOBALS['sql_compat'] == 'NONE') { return PMA_exportOutputHandler('USE ' . PMA_backquote($db) . ';' . $crlf); } @@ -138,7 +146,8 @@ function PMA_exportDBCreate($db) { * * @access public */ -function PMA_exportDBHeader($db) { +function PMA_exportDBHeader($db) +{ global $crlf; $head = $GLOBALS['comment_marker'] . $crlf . $GLOBALS['comment_marker'] . $GLOBALS['strDatabase'] . ': ' . (isset($GLOBALS['use_backquotes']) ? PMA_backquote($db) : '\'' . $db . '\''). $crlf @@ -155,7 +164,8 @@ function PMA_exportDBHeader($db) { * * @access public */ -function PMA_exportDBFooter($db) { +function PMA_exportDBFooter($db) +{ $result = TRUE; if (isset($GLOBALS['sql_constraints'])) { $result = PMA_exportOutputHandler($GLOBALS['sql_constraints']); @@ -193,7 +203,7 @@ function PMA_getTableDef($db, $table, $crlf, $error_url, $show_dates = false) $new_crlf = $crlf; // need to use PMA_DBI_QUERY_STORE with PMA_DBI_num_rows() in mysqli - $result = PMA_DBI_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . PMA_sqlAddslashes($table) . '\'', NULL, PMA_DBI_QUERY_STORE); + $result = PMA_DBI_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . PMA_sqlAddslashes($table) . '\'', null, PMA_DBI_QUERY_STORE); if ($result != FALSE) { if (PMA_DBI_num_rows($result) > 0) { $tmpres = PMA_DBI_fetch_assoc($result); @@ -233,7 +243,7 @@ function PMA_getTableDef($db, $table, $crlf, $error_url, $show_dates = false) PMA_DBI_query('SET SQL_QUOTE_SHOW_CREATE = 0'); } - $result = PMA_DBI_query('SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table), NULL, PMA_DBI_QUERY_UNBUFFERED); + $result = PMA_DBI_query('SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table), null, PMA_DBI_QUERY_UNBUFFERED); if ($result != FALSE && ($row = PMA_DBI_fetch_row($result))) { $create_query = $row[1]; unset($row); @@ -261,7 +271,9 @@ function PMA_getTableDef($db, $table, $crlf, $error_url, $show_dates = false) // lets find first line with constraints for ($i = 0; $i < $sql_count; $i++) { - if (preg_match('@^[\s]*(CONSTRAINT|FOREIGN[\s]+KEY)@', $sql_lines[$i])) break; + if (preg_match('@^[\s]*(CONSTRAINT|FOREIGN[\s]+KEY)@', $sql_lines[$i])) { + break; + } } // If we really found a constraint @@ -292,7 +304,7 @@ function PMA_getTableDef($db, $table, $crlf, $error_url, $show_dates = false) $sql_constraints .= 'ALTER TABLE ' . PMA_backquote($table) . $crlf; $first = TRUE; - for($j = $i; $j < $sql_count; $j++) { + for ($j = $i; $j < $sql_count; $j++) { if (preg_match('@CONSTRAINT|FOREIGN[\s]+KEY@', $sql_lines[$j])) { if (!$first) { $sql_constraints .= $crlf; @@ -362,13 +374,14 @@ function PMA_getTableComments($db, $table, $crlf, $do_relation = false, $do_comm } else { $have_rel = FALSE; } - } - else { + } else { $have_rel = FALSE; } // end if if ($do_mime && $cfgRelation['mimework']) { - if (!($mime_map = PMA_getMIME($db, $table, true))) unset($mime_map); + if (!($mime_map = PMA_getMIME($db, $table, true))) { + unset($mime_map); + } } if (isset($comments_map) && count($comments_map) > 0) { @@ -422,7 +435,8 @@ function PMA_getTableComments($db, $table, $crlf, $do_relation = false, $do_comm * * @access public */ -function PMA_exportStructure($db, $table, $crlf, $error_url, $relation = FALSE, $comments = FALSE, $mime = FALSE, $dates = FALSE) { +function PMA_exportStructure($db, $table, $crlf, $error_url, $relation = FALSE, $comments = FALSE, $mime = FALSE, $dates = FALSE) +{ $formatted_table_name = (isset($GLOBALS['use_backquotes'])) ? PMA_backquote($table) : '\'' . $table . '\''; @@ -475,7 +489,9 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) . $GLOBALS['comment_marker'] . $GLOBALS['strDumpingData'] . ' ' . $formatted_table_name . $crlf . $GLOBALS['comment_marker'] . $crlf .$crlf; - if (!PMA_exportOutputHandler($head)) return FALSE; + if (!PMA_exportOutputHandler($head)) { + return FALSE; + } $buffer = ''; @@ -484,7 +500,7 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) // are used, we did not get the true column name in case of aliases) $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($sql_query)); - $result = PMA_DBI_query($sql_query, NULL, PMA_DBI_QUERY_UNBUFFERED); + $result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED); if ($result != FALSE) { $fields_cnt = PMA_DBI_num_fields($result); @@ -506,8 +522,9 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) if (isset($GLOBALS['sql_type']) && $GLOBALS['sql_type'] == 'update') { // update $schema_insert = 'UPDATE '; - if (isset($GLOBALS['sql_ignore'])) + if (isset($GLOBALS['sql_ignore'])) { $schema_insert .= 'IGNORE '; + } $schema_insert .= PMA_backquote($table, $use_backquotes) . ' SET '; } else { // insert or replace @@ -543,7 +560,7 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) $search = array("\x00", "\x0a", "\x0d", "\x1a"); //\x08\\x09, not required $replace = array('\0', '\n', '\r', '\Z'); $current_row = 0; - $query_size = 0; + $query_size = 0; $separator = isset($GLOBALS['extended_ins']) ? ',' : ';'; while ($row = PMA_DBI_fetch_row($result)) { @@ -554,7 +571,7 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) $values[] = 'NULL'; // a number // timestamp is numeric on some MySQL 4.1, BLOBs are sometimes numeric - } elseif ($fields_meta[$j]->numeric && $fields_meta[$j]->type != 'timestamp' + } elseif ($fields_meta[$j]->numeric && $fields_meta[$j]->type != 'timestamp' && ! $fields_meta[$j]->blob) { $values[] = $row[$j]; // a binary field @@ -601,7 +618,9 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) } else { $insert_line = '(' . implode(', ', $values) . ')'; if (isset($GLOBALS['max_query_size']) && $GLOBALS['max_query_size'] > 0 && $query_size + strlen($insert_line) > $GLOBALS['max_query_size']) { - if (!PMA_exportOutputHandler(';' . $crlf)) return FALSE; + if (!PMA_exportOutputHandler(';' . $crlf)) { + return FALSE; + } $query_size = 0; $current_row = 1; $insert_line = $schema_insert . $insert_line; @@ -616,11 +635,15 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) } unset($values); - if (!PMA_exportOutputHandler(($current_row == 1 ? '' : $separator . $crlf) . $insert_line)) return FALSE; + if (!PMA_exportOutputHandler(($current_row == 1 ? '' : $separator . $crlf) . $insert_line)) { + return FALSE; + } } // end while if ($current_row > 0) { - if (!PMA_exportOutputHandler(';' . $crlf)) return FALSE; + if (!PMA_exportOutputHandler(';' . $crlf)) { + return FALSE; + } } } // end if ($result != FALSE) PMA_DBI_free_result($result); diff --git a/libraries/export/xls.php b/libraries/export/xls.php index 0a3f1c65fa..43fef0a339 100644 --- a/libraries/export/xls.php +++ b/libraries/export/xls.php @@ -15,7 +15,8 @@ require_once('Spreadsheet/Excel/Writer.php'); * * @return bool Whether it suceeded */ -function PMA_exportComment($text) { +function PMA_exportComment($text) +{ return TRUE; } @@ -26,7 +27,8 @@ function PMA_exportComment($text) { * * @access public */ -function PMA_exportFooter() { +function PMA_exportFooter() +{ global $workbook; global $tmp_filename; @@ -35,7 +37,9 @@ function PMA_exportFooter() { echo $res->getMessage(); return FALSE; } - if (!PMA_exportOutputHandler(file_get_contents($tmp_filename))) return FALSE; + if (!PMA_exportOutputHandler(file_get_contents($tmp_filename))) { + return FALSE; + } unlink($tmp_filename); return TRUE; @@ -48,11 +52,14 @@ function PMA_exportFooter() { * * @access public */ -function PMA_exportHeader() { +function PMA_exportHeader() +{ global $workbook; global $tmp_filename; - if (empty($GLOBALS['cfg']['TempDir'])) return FALSE; + if (empty($GLOBALS['cfg']['TempDir'])) { + return FALSE; + } $tmp_filename = tempnam(realpath($GLOBALS['cfg']['TempDir']), 'pma_xls_'); $workbook = new Spreadsheet_Excel_Writer($tmp_filename); @@ -68,7 +75,8 @@ function PMA_exportHeader() { * * @access public */ -function PMA_exportDBHeader($db) { +function PMA_exportDBHeader($db) +{ return TRUE; } @@ -81,7 +89,8 @@ function PMA_exportDBHeader($db) { * * @access public */ -function PMA_exportDBFooter($db) { +function PMA_exportDBFooter($db) +{ return TRUE; } @@ -94,7 +103,8 @@ function PMA_exportDBFooter($db) { * * @access public */ -function PMA_exportDBCreate($db) { +function PMA_exportDBCreate($db) +{ return TRUE; } @@ -111,7 +121,8 @@ function PMA_exportDBCreate($db) { * * @access public */ -function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { +function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) +{ global $what; global $workbook; @@ -119,7 +130,7 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { $workbook->setTempDir(realpath($GLOBALS['cfg']['TempDir'])); // Gets the data from the database - $result = PMA_DBI_query($sql_query, NULL, PMA_DBI_QUERY_UNBUFFERED); + $result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED); $fields_cnt = PMA_DBI_num_fields($result); $col = 0; @@ -138,7 +149,7 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { for ($j = 0; $j < $fields_cnt; $j++) { if (!isset($row[$j]) || is_null($row[$j])) { $worksheet->write($col, $j, $GLOBALS['xls_replace_null']); - } else if ($row[$j] == '0' || $row[$j] != '') { + } elseif ($row[$j] == '0' || $row[$j] != '') { // FIXME: we should somehow handle character set here! $worksheet->write($col, $j, $row[$j]); } else { diff --git a/libraries/export/xml.php b/libraries/export/xml.php index 14488d9708..a66f84a27e 100644 --- a/libraries/export/xml.php +++ b/libraries/export/xml.php @@ -124,7 +124,7 @@ function PMA_exportDBCreate($db) { * @access public */ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { - $result = PMA_DBI_query($sql_query, NULL, PMA_DBI_QUERY_UNBUFFERED); + $result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED); $columns_cnt = PMA_DBI_num_fields($result); for ($i = 0; $i < $columns_cnt; $i++) { @@ -133,7 +133,9 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { unset($i); $buffer = ' <!-- ' . $GLOBALS['strTable'] . ' ' . $table . ' -->' . $crlf; - if (!PMA_exportOutputHandler($buffer)) return FALSE; + if (!PMA_exportOutputHandler($buffer)) { + return FALSE; + } while ($record = PMA_DBI_fetch_row($result)) { $buffer = ' <' . $table . '>' . $crlf; @@ -145,7 +147,9 @@ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { } $buffer .= ' </' . $table . '>' . $crlf; - if (!PMA_exportOutputHandler($buffer)) return FALSE; + if (!PMA_exportOutputHandler($buffer)) { + return FALSE; + } } PMA_DBI_free_result($result); diff --git a/libraries/file_listing.php b/libraries/file_listing.php index c7a9812c0e..d54b29aba6 100644 --- a/libraries/file_listing.php +++ b/libraries/file_listing.php @@ -10,7 +10,8 @@ * @param string regullar expression to match files * @returns array sorted file list on success, FALSE on failure */ -function PMA_getDirContent($dir, $expression = '') { +function PMA_getDirContent($dir, $expression = '') +{ if ($handle = @opendir($dir)) { $result = array(); if (substr($dir, -1) != '/') { @@ -37,11 +38,14 @@ function PMA_getDirContent($dir, $expression = '') { * @param string currently active choice * @returns array sorted file list on success, FALSE on failure */ -function PMA_getFileSelectOptions($dir, $extensions = '', $active = '') { +function PMA_getFileSelectOptions($dir, $extensions = '', $active = '') +{ $list = PMA_getDirContent($dir, $extensions); - if ($list === FALSE) return FALSE; + if ($list === FALSE) { + return FALSE; + } $result = ''; - foreach($list as $key => $val) { + foreach ($list as $key => $val) { $result .= '<option value="'. htmlspecialchars($val) . '"'; if ($val == $active) { $result .= ' selected="selected"'; @@ -56,21 +60,28 @@ function PMA_getFileSelectOptions($dir, $extensions = '', $active = '') { * * @returns string | separated list of extensions usable in PMA_getDirContent */ -function PMA_supportedDecompressions() { +function PMA_supportedDecompressions() +{ global $cfg; $compressions = ''; if ($cfg['GZipDump'] && @function_exists('gzopen')) { - if (!empty($compressions)) $compressions .= '|'; + if (!empty($compressions)) { + $compressions .= '|'; + } $compressions .= 'gz'; } if ($cfg['BZipDump'] && @function_exists('bzopen')) { - if (!empty($compressions)) $compressions .= '|'; + if (!empty($compressions)) { + $compressions .= '|'; + } $compressions .= 'bz2'; } if ($cfg['ZipDump'] && @function_exists('gzinflate')) { - if (!empty($compressions)) $compressions .= '|'; + if (!empty($compressions)) { + $compressions .= '|'; + } $compressions .= 'zip'; } diff --git a/libraries/footer.inc.php b/libraries/footer.inc.php index 507c3cdbf7..36277887f5 100644 --- a/libraries/footer.inc.php +++ b/libraries/footer.inc.php @@ -68,13 +68,17 @@ require_once('./libraries/relation.lib.php'); // for PMA_setHistory() <?php // Link to itself to replicate windows including frameset -if (!isset($GLOBALS['checked_special'])) $GLOBALS['checked_special'] = FALSE; +if (!isset($GLOBALS['checked_special'])) { + $GLOBALS['checked_special'] = FALSE; +} if (isset($_SERVER['SCRIPT_NAME']) && empty($_POST) && !$GLOBALS['checked_special']) { echo '<div id="selflink">' . "\n"; echo '<a href="index.php?target=' . basename($_SERVER['SCRIPT_NAME']); $url = PMA_generate_common_url(isset($GLOBALS['db']) ? $GLOBALS['db'] : '', isset($GLOBALS['table']) ? $GLOBALS['table'] : ''); - if (!empty($url)) echo '&' . $url; + if (!empty($url)) { + echo '&' . $url; + } echo '" target="_blank">' . $GLOBALS['strOpenNewWindow'] . '</a>' . "\n"; echo '</div>' . "\n"; } diff --git a/libraries/fpdf/fpdf.php b/libraries/fpdf/fpdf.php index f5b967c18f..1e49e856ff 100644 --- a/libraries/fpdf/fpdf.php +++ b/libraries/fpdf/fpdf.php @@ -1,1629 +1,1887 @@ <?php -/******************************************************************************* -* Software: FPDF * -* Version: 1.52 * -* Date: 2003-12-30 * -* Author: Olivier PLATHEY * -* License: Freeware * -* * -* You may use, modify and redistribute this software as you wish. * -*******************************************************************************/ - -if(!class_exists('FPDF')) -{ -define('FPDF_VERSION','1.52'); - -class FPDF -{ -//Private properties -var $page; //current page number -var $n; //current object number -var $offsets; //array of object offsets -var $buffer; //buffer holding in-memory PDF -var $pages; //array containing pages -var $state; //current document state -var $compress; //compression flag -var $DefOrientation; //default orientation -var $CurOrientation; //current orientation -var $OrientationChanges; //array indicating orientation changes -var $k; //scale factor (number of points in user unit) -var $fwPt,$fhPt; //dimensions of page format in points -var $fw,$fh; //dimensions of page format in user unit -var $wPt,$hPt; //current dimensions of page in points -var $w,$h; //current dimensions of page in user unit -var $lMargin; //left margin -var $tMargin; //top margin -var $rMargin; //right margin -var $bMargin; //page break margin -var $cMargin; //cell margin -var $x,$y; //current position in user unit for cell positioning -var $lasth; //height of last cell printed -var $LineWidth; //line width in user unit -var $CoreFonts; //array of standard font names -var $fonts; //array of used fonts -var $FontFiles; //array of font files -var $diffs; //array of encoding differences -var $images; //array of used images -var $PageLinks; //array of links in pages -var $links; //array of internal links -var $FontFamily; //current font family -var $FontStyle; //current font style -var $underline; //underlining flag -var $CurrentFont; //current font info -var $FontSizePt; //current font size in points -var $FontSize; //current font size in user unit -var $DrawColor; //commands for drawing color -var $FillColor; //commands for filling color -var $TextColor; //commands for text color -var $ColorFlag; //indicates whether fill and text colors are different -var $ws; //word spacing -var $AutoPageBreak; //automatic page breaking -var $PageBreakTrigger; //threshold used to trigger page breaks -var $InFooter; //flag set when processing footer -var $ZoomMode; //zoom display mode -var $LayoutMode; //layout display mode -var $title; //title -var $subject; //subject -var $author; //author -var $keywords; //keywords -var $creator; //creator -var $AliasNbPages; //alias for total number of pages - -/******************************************************************************* -* * -* Public methods * -* * -*******************************************************************************/ -function FPDF($orientation='P',$unit='mm',$format='A4') -{ - //Some checks - $this->_dochecks(); - //Initialization of properties - $this->page=0; - $this->n=2; - $this->buffer=''; - $this->pages=array(); - $this->OrientationChanges=array(); - $this->state=0; - $this->fonts=array(); - $this->FontFiles=array(); - $this->diffs=array(); - $this->images=array(); - $this->links=array(); - $this->InFooter=false; - $this->lasth=0; - $this->FontFamily=''; - $this->FontStyle=''; - $this->FontSizePt=12; - $this->underline=false; - $this->DrawColor='0 G'; - $this->FillColor='0 g'; - $this->TextColor='0 g'; - $this->ColorFlag=false; - $this->ws=0; - //Standard fonts - $this->CoreFonts=array('courier'=>'Courier','courierB'=>'Courier-Bold','courierI'=>'Courier-Oblique','courierBI'=>'Courier-BoldOblique', - 'helvetica'=>'Helvetica','helveticaB'=>'Helvetica-Bold','helveticaI'=>'Helvetica-Oblique','helveticaBI'=>'Helvetica-BoldOblique', - 'times'=>'Times-Roman','timesB'=>'Times-Bold','timesI'=>'Times-Italic','timesBI'=>'Times-BoldItalic', - 'symbol'=>'Symbol','zapfdingbats'=>'ZapfDingbats'); - //Scale factor - if($unit=='pt') - $this->k=1; - elseif($unit=='mm') - $this->k=72/25.4; - elseif($unit=='cm') - $this->k=72/2.54; - elseif($unit=='in') - $this->k=72; - else - $this->Error('Incorrect unit: '.$unit); - //Page format - if(is_string($format)) - { - $format=strtolower($format); - if($format=='a3') - $format=array(841.89,1190.55); - elseif($format=='a4') - $format=array(595.28,841.89); - elseif($format=='a5') - $format=array(420.94,595.28); - elseif($format=='letter') - $format=array(612,792); - elseif($format=='legal') - $format=array(612,1008); - else - $this->Error('Unknown page format: '.$format); - $this->fwPt=$format[0]; - $this->fhPt=$format[1]; - } - else - { - $this->fwPt=$format[0]*$this->k; - $this->fhPt=$format[1]*$this->k; - } - $this->fw=$this->fwPt/$this->k; - $this->fh=$this->fhPt/$this->k; - //Page orientation - $orientation=strtolower($orientation); - if($orientation=='p' or $orientation=='portrait') - { - $this->DefOrientation='P'; - $this->wPt=$this->fwPt; - $this->hPt=$this->fhPt; - } - elseif($orientation=='l' or $orientation=='landscape') - { - $this->DefOrientation='L'; - $this->wPt=$this->fhPt; - $this->hPt=$this->fwPt; - } - else - $this->Error('Incorrect orientation: '.$orientation); - $this->CurOrientation=$this->DefOrientation; - $this->w=$this->wPt/$this->k; - $this->h=$this->hPt/$this->k; - //Page margins (1 cm) - $margin=28.35/$this->k; - $this->SetMargins($margin,$margin); - //Interior cell margin (1 mm) - $this->cMargin=$margin/10; - //Line width (0.2 mm) - $this->LineWidth=.567/$this->k; - //Automatic page break - $this->SetAutoPageBreak(true,2*$margin); - //Full width display mode - $this->SetDisplayMode('fullwidth'); - //Compression - $this->SetCompression(true); -} - -function SetMargins($left,$top,$right=-1) -{ - //Set left, top and right margins - $this->lMargin=$left; - $this->tMargin=$top; - if($right==-1) - $right=$left; - $this->rMargin=$right; -} - -function SetLeftMargin($margin) -{ - //Set left margin - $this->lMargin=$margin; - if($this->page>0 and $this->x<$margin) - $this->x=$margin; -} - -function SetTopMargin($margin) -{ - //Set top margin - $this->tMargin=$margin; -} - -function SetRightMargin($margin) -{ - //Set right margin - $this->rMargin=$margin; -} - -function SetAutoPageBreak($auto,$margin=0) -{ - //Set auto page break mode and triggering margin - $this->AutoPageBreak=$auto; - $this->bMargin=$margin; - $this->PageBreakTrigger=$this->h-$margin; -} - -function SetDisplayMode($zoom,$layout='continuous') -{ - //Set display mode in viewer - if($zoom=='fullpage' or $zoom=='fullwidth' or $zoom=='real' or $zoom=='default' or !is_string($zoom)) - $this->ZoomMode=$zoom; - else - $this->Error('Incorrect zoom display mode: '.$zoom); - if($layout=='single' or $layout=='continuous' or $layout=='two' or $layout=='default') - $this->LayoutMode=$layout; - else - $this->Error('Incorrect layout display mode: '.$layout); -} - -function SetCompression($compress) -{ - //Set page compression - if(function_exists('gzcompress')) - $this->compress=$compress; - else - $this->compress=false; -} - -function SetTitle($title) -{ - //Title of document - $this->title=$title; -} - -function SetSubject($subject) -{ - //Subject of document - $this->subject=$subject; -} - -function SetAuthor($author) -{ - //Author of document - $this->author=$author; -} - -function SetKeywords($keywords) -{ - //Keywords of document - $this->keywords=$keywords; -} - -function SetCreator($creator) -{ - //Creator of document - $this->creator=$creator; -} - -function AliasNbPages($alias='{nb}') -{ - //Define an alias for total number of pages - $this->AliasNbPages=$alias; -} - -function Error($msg) -{ - //Fatal error - die('<B>FPDF error: </B>'.$msg); -} - -function Open() -{ - //Begin document - if($this->state==0) - $this->_begindoc(); -} - -function Close() -{ - //Terminate document - if($this->state==3) - return; - if($this->page==0) - $this->AddPage(); - //Page footer - $this->InFooter=true; - $this->Footer(); - $this->InFooter=false; - //Close page - $this->_endpage(); - //Close document - $this->_enddoc(); -} - -function AddPage($orientation='') -{ - //Start a new page - if($this->state==0) - $this->Open(); - $family=$this->FontFamily; - $style=$this->FontStyle.($this->underline ? 'U' : ''); - $size=$this->FontSizePt; - $lw=$this->LineWidth; - $dc=$this->DrawColor; - $fc=$this->FillColor; - $tc=$this->TextColor; - $cf=$this->ColorFlag; - if($this->page>0) - { - //Page footer - $this->InFooter=true; - $this->Footer(); - $this->InFooter=false; - //Close page - $this->_endpage(); - } - //Start new page - $this->_beginpage($orientation); - //Set line cap style to square - $this->_out('2 J'); - //Set line width - $this->LineWidth=$lw; - $this->_out(sprintf('%.2f w',$lw*$this->k)); - //Set font - if($family) - $this->SetFont($family,$style,$size); - //Set colors - $this->DrawColor=$dc; - if($dc!='0 G') - $this->_out($dc); - $this->FillColor=$fc; - if($fc!='0 g') - $this->_out($fc); - $this->TextColor=$tc; - $this->ColorFlag=$cf; - //Page header - $this->Header(); - //Restore line width - if($this->LineWidth!=$lw) - { - $this->LineWidth=$lw; - $this->_out(sprintf('%.2f w',$lw*$this->k)); - } - //Restore font - if($family) - $this->SetFont($family,$style,$size); - //Restore colors - if($this->DrawColor!=$dc) - { - $this->DrawColor=$dc; - $this->_out($dc); - } - if($this->FillColor!=$fc) - { - $this->FillColor=$fc; - $this->_out($fc); - } - $this->TextColor=$tc; - $this->ColorFlag=$cf; -} - -function Header() -{ - //To be implemented in your own inherited class -} - -function Footer() -{ - //To be implemented in your own inherited class -} - -function PageNo() -{ - //Get current page number - return $this->page; -} - -function SetDrawColor($r,$g=-1,$b=-1) -{ - //Set color for all stroking operations - if(($r==0 and $g==0 and $b==0) or $g==-1) - $this->DrawColor=sprintf('%.3f G',$r/255); - else - $this->DrawColor=sprintf('%.3f %.3f %.3f RG',$r/255,$g/255,$b/255); - if($this->page>0) - $this->_out($this->DrawColor); -} - -function SetFillColor($r,$g=-1,$b=-1) -{ - //Set color for all filling operations - if(($r==0 and $g==0 and $b==0) or $g==-1) - $this->FillColor=sprintf('%.3f g',$r/255); - else - $this->FillColor=sprintf('%.3f %.3f %.3f rg',$r/255,$g/255,$b/255); - $this->ColorFlag=($this->FillColor!=$this->TextColor); - if($this->page>0) - $this->_out($this->FillColor); -} - -function SetTextColor($r,$g=-1,$b=-1) -{ - //Set color for text - if(($r==0 and $g==0 and $b==0) or $g==-1) - $this->TextColor=sprintf('%.3f g',$r/255); - else - $this->TextColor=sprintf('%.3f %.3f %.3f rg',$r/255,$g/255,$b/255); - $this->ColorFlag=($this->FillColor!=$this->TextColor); -} - -function GetStringWidth($s) -{ - //Get width of a string in the current font - $s=(string)$s; - $cw=&$this->CurrentFont['cw']; - $w=0; - $l=strlen($s); - for($i=0;$i<$l;$i++) - $w+=$cw[$s{$i}]; - return $w*$this->FontSize/1000; -} - -function SetLineWidth($width) -{ - //Set line width - $this->LineWidth=$width; - if($this->page>0) - $this->_out(sprintf('%.2f w',$width*$this->k)); -} - -function Line($x1,$y1,$x2,$y2) -{ - //Draw a line - $this->_out(sprintf('%.2f %.2f m %.2f %.2f l S',$x1*$this->k,($this->h-$y1)*$this->k,$x2*$this->k,($this->h-$y2)*$this->k)); -} - -function Rect($x,$y,$w,$h,$style='') -{ - //Draw a rectangle - if($style=='F') - $op='f'; - elseif($style=='FD' or $style=='DF') - $op='B'; - else - $op='S'; - $this->_out(sprintf('%.2f %.2f %.2f %.2f re %s',$x*$this->k,($this->h-$y)*$this->k,$w*$this->k,-$h*$this->k,$op)); -} - -function AddFont($family,$style='',$file='') -{ - //Add a TrueType or Type1 font - $family=strtolower($family); - if($family=='arial') - $family='helvetica'; - $style=strtoupper($style); - if($style=='IB') - $style='BI'; - if(isset($this->fonts[$family.$style])) - $this->Error('Font already added: '.$family.' '.$style); - if($file=='') - $file=str_replace(' ','',$family).strtolower($style).'.php'; - if(defined('FPDF_FONTPATH')) - $file=FPDF_FONTPATH.$file; - include($file); - if(!isset($name)) - $this->Error('Could not include font definition file'); - $i=count($this->fonts)+1; - $this->fonts[$family.$style]=array('i'=>$i,'type'=>$type,'name'=>$name,'desc'=>$desc,'up'=>$up,'ut'=>$ut,'cw'=>$cw,'enc'=>$enc,'file'=>$file); - if($diff) - { - //Search existing encodings - $d=0; - $nb=count($this->diffs); - for($i=1;$i<=$nb;$i++) - if($this->diffs[$i]==$diff) - { - $d=$i; - break; - } - if($d==0) - { - $d=$nb+1; - $this->diffs[$d]=$diff; - } - $this->fonts[$family.$style]['diff']=$d; - } - if($file) - { - if($type=='TrueType') - $this->FontFiles[$file]=array('length1'=>$originalsize); - else - $this->FontFiles[$file]=array('length1'=>$size1,'length2'=>$size2); - } -} - -function SetFont($family,$style='',$size=0) -{ - //Select a font; size given in points - global $fpdf_charwidths; - - $family=strtolower($family); - if($family=='') - $family=$this->FontFamily; - if($family=='arial') - $family='helvetica'; - elseif($family=='symbol' or $family=='zapfdingbats') - $style=''; - $style=strtoupper($style); - if(is_int(strpos($style,'U'))) - { - $this->underline=true; - $style=str_replace('U','',$style); - } - else - $this->underline=false; - if($style=='IB') - $style='BI'; - if($size==0) - $size=$this->FontSizePt; - //Test if font is already selected - if($this->FontFamily==$family and $this->FontStyle==$style and $this->FontSizePt==$size) - return; - //Test if used for the first time - $fontkey=$family.$style; - if(!isset($this->fonts[$fontkey])) - { - //Check if one of the standard fonts - if(isset($this->CoreFonts[$fontkey])) - { - if(!isset($fpdf_charwidths[$fontkey])) - { - //Load metric file - $file=$family; - if($family=='times' or $family=='helvetica') - $file.=strtolower($style); - $file.='.php'; - if(defined('FPDF_FONTPATH')) - $file=FPDF_FONTPATH.$file; - include($file); - if(!isset($fpdf_charwidths[$fontkey])) - $this->Error('Could not include font metric file'); - } - $i=count($this->fonts)+1; - $this->fonts[$fontkey]=array('i'=>$i,'type'=>'core','name'=>$this->CoreFonts[$fontkey],'up'=>-100,'ut'=>50,'cw'=>$fpdf_charwidths[$fontkey]); - } - else - $this->Error('Undefined font: '.$family.' '.$style); - } - //Select it - $this->FontFamily=$family; - $this->FontStyle=$style; - $this->FontSizePt=$size; - $this->FontSize=$size/$this->k; - $this->CurrentFont=&$this->fonts[$fontkey]; - if($this->page>0) - $this->_out(sprintf('BT /F%d %.2f Tf ET',$this->CurrentFont['i'],$this->FontSizePt)); -} - -function SetFontSize($size) -{ - //Set font size in points - if($this->FontSizePt==$size) - return; - $this->FontSizePt=$size; - $this->FontSize=$size/$this->k; - if($this->page>0) - $this->_out(sprintf('BT /F%d %.2f Tf ET',$this->CurrentFont['i'],$this->FontSizePt)); -} - -function AddLink() -{ - //Create a new internal link - $n=count($this->links)+1; - $this->links[$n]=array(0,0); - return $n; -} - -function SetLink($link,$y=0,$page=-1) -{ - //Set destination of internal link - if($y==-1) - $y=$this->y; - if($page==-1) - $page=$this->page; - $this->links[$link]=array($page,$y); -} - -function Link($x,$y,$w,$h,$link) -{ - //Put a link on the page - $this->PageLinks[$this->page][]=array($x*$this->k,$this->hPt-$y*$this->k,$w*$this->k,$h*$this->k,$link); -} - -function Text($x,$y,$txt) -{ - //Output a string - $s=sprintf('BT %.2f %.2f Td (%s) Tj ET',$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt)); - if($this->underline and $txt!='') - $s.=' '.$this->_dounderline($x,$y,$txt); - if($this->ColorFlag) - $s='q '.$this->TextColor.' '.$s.' Q'; - $this->_out($s); -} - -function AcceptPageBreak() -{ - //Accept automatic page break or not - return $this->AutoPageBreak; -} - -function Cell($w,$h=0,$txt='',$border=0,$ln=0,$align='',$fill=0,$link='') -{ - //Output a cell - $k=$this->k; - if($this->y+$h>$this->PageBreakTrigger and !$this->InFooter and $this->AcceptPageBreak()) - { - //Automatic page break - $x=$this->x; - $ws=$this->ws; - if($ws>0) - { - $this->ws=0; - $this->_out('0 Tw'); - } - $this->AddPage($this->CurOrientation); - $this->x=$x; - if($ws>0) - { - $this->ws=$ws; - $this->_out(sprintf('%.3f Tw',$ws*$k)); - } - } - if($w==0) - $w=$this->w-$this->rMargin-$this->x; - $s=''; - if($fill==1 or $border==1) - { - if($fill==1) - $op=($border==1) ? 'B' : 'f'; - else - $op='S'; - $s=sprintf('%.2f %.2f %.2f %.2f re %s ',$this->x*$k,($this->h-$this->y)*$k,$w*$k,-$h*$k,$op); - } - if(is_string($border)) - { - $x=$this->x; - $y=$this->y; - if(is_int(strpos($border,'L'))) - $s.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-$y)*$k,$x*$k,($this->h-($y+$h))*$k); - if(is_int(strpos($border,'T'))) - $s.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-$y)*$k); - if(is_int(strpos($border,'R'))) - $s.=sprintf('%.2f %.2f m %.2f %.2f l S ',($x+$w)*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-($y+$h))*$k); - if(is_int(strpos($border,'B'))) - $s.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-($y+$h))*$k,($x+$w)*$k,($this->h-($y+$h))*$k); - } - if($txt!='') - { - if($align=='R') - $dx=$w-$this->cMargin-$this->GetStringWidth($txt); - elseif($align=='C') - $dx=($w-$this->GetStringWidth($txt))/2; - else - $dx=$this->cMargin; - if($this->ColorFlag) - $s.='q '.$this->TextColor.' '; - $txt2=str_replace(')','\\)',str_replace('(','\\(',str_replace('\\','\\\\',$txt))); - $s.=sprintf('BT %.2f %.2f Td (%s) Tj ET',($this->x+$dx)*$k,($this->h-($this->y+.5*$h+.3*$this->FontSize))*$k,$txt2); - if($this->underline) - $s.=' '.$this->_dounderline($this->x+$dx,$this->y+.5*$h+.3*$this->FontSize,$txt); - if($this->ColorFlag) - $s.=' Q'; - if($link) - $this->Link($this->x+$dx,$this->y+.5*$h-.5*$this->FontSize,$this->GetStringWidth($txt),$this->FontSize,$link); - } - if($s) - $this->_out($s); - $this->lasth=$h; - if($ln>0) - { - //Go to next line - $this->y+=$h; - if($ln==1) - $this->x=$this->lMargin; - } - else - $this->x+=$w; -} - -function MultiCell($w,$h,$txt,$border=0,$align='J',$fill=0) -{ - //Output text with automatic or explicit line breaks - $cw=&$this->CurrentFont['cw']; - if($w==0) - $w=$this->w-$this->rMargin-$this->x; - $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; - $s=str_replace("\r",'',$txt); - $nb=strlen($s); - if($nb>0 and $s[$nb-1]=="\n") - $nb--; - $b=0; - if($border) - { - if($border==1) - { - $border='LTRB'; - $b='LRT'; - $b2='LR'; - } - else - { - $b2=''; - if(is_int(strpos($border,'L'))) - $b2.='L'; - if(is_int(strpos($border,'R'))) - $b2.='R'; - $b=is_int(strpos($border,'T')) ? $b2.'T' : $b2; - } - } - $sep=-1; - $i=0; - $j=0; - $l=0; - $ns=0; - $nl=1; - while($i<$nb) - { - //Get next character - $c=$s{$i}; - if($c=="\n") - { - //Explicit line break - if($this->ws>0) - { - $this->ws=0; - $this->_out('0 Tw'); - } - $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); - $i++; - $sep=-1; - $j=$i; - $l=0; - $ns=0; - $nl++; - if($border and $nl==2) - $b=$b2; - continue; - } - if($c==' ') - { - $sep=$i; - $ls=$l; - $ns++; - } - $l+=isset($cw[ord($c)])?$cw[ord($c)]:0; - if($l>$wmax) - { - //Automatic line break - if($sep==-1) - { - if($i==$j) - $i++; - if($this->ws>0) - { - $this->ws=0; - $this->_out('0 Tw'); - } - $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); - } - else - { - if($align=='J') - { - $this->ws=($ns>1) ? ($wmax-$ls)/1000*$this->FontSize/($ns-1) : 0; - $this->_out(sprintf('%.3f Tw',$this->ws*$this->k)); - } - $this->Cell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill); - $i=$sep+1; - } - $sep=-1; - $j=$i; - $l=0; - $ns=0; - $nl++; - if($border and $nl==2) - $b=$b2; - } - else - $i++; - } - //Last chunk - if($this->ws>0) - { - $this->ws=0; - $this->_out('0 Tw'); - } - if($border and is_int(strpos($border,'B'))) - $b.='B'; - $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); - $this->x=$this->lMargin; -} - -function Write($h,$txt,$link='') -{ - //Output text in flowing mode - $cw=&$this->CurrentFont['cw']; - $w=$this->w-$this->rMargin-$this->x; - $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; - $s=str_replace("\r",'',$txt); - $nb=strlen($s); - $sep=-1; - $i=0; - $j=0; - $l=0; - $nl=1; - while($i<$nb) - { - //Get next character - $c=$s{$i}; - if($c=="\n") - { - //Explicit line break - $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',0,$link); - $i++; - $sep=-1; - $j=$i; - $l=0; - if($nl==1) - { - $this->x=$this->lMargin; - $w=$this->w-$this->rMargin-$this->x; - $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; - } - $nl++; - continue; - } - if($c==' ') - $sep=$i; - $l+=$cw[$c]; - if($l>$wmax) - { - //Automatic line break - if($sep==-1) - { - if($this->x>$this->lMargin) - { - //Move to next line - $this->x=$this->lMargin; - $this->y+=$h; - $w=$this->w-$this->rMargin-$this->x; - $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; - $i++; - $nl++; - continue; - } - if($i==$j) - $i++; - $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',0,$link); - } - else - { - $this->Cell($w,$h,substr($s,$j,$sep-$j),0,2,'',0,$link); - $i=$sep+1; - } - $sep=-1; - $j=$i; - $l=0; - if($nl==1) - { - $this->x=$this->lMargin; - $w=$this->w-$this->rMargin-$this->x; - $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; - } - $nl++; - } - else - $i++; - } - //Last chunk - if($i!=$j) - $this->Cell($l/1000*$this->FontSize,$h,substr($s,$j),0,0,'',0,$link); -} - -function Image($file,$x,$y,$w=0,$h=0,$type='',$link='') -{ - //Put an image on the page - if(!isset($this->images[$file])) - { - //First use of image, get info - if($type=='') - { - $pos=strrpos($file,'.'); - if(!$pos) - $this->Error('Image file has no extension and no type was specified: '.$file); - $type=substr($file,$pos+1); - } - $type=strtolower($type); - $mqr=get_magic_quotes_runtime(); - set_magic_quotes_runtime(0); - if($type=='jpg' or $type=='jpeg') - $info=$this->_parsejpg($file); - elseif($type=='png') - $info=$this->_parsepng($file); - else - { - //Allow for additional formats - $mtd='_parse'.$type; - if(!method_exists($this,$mtd)) - $this->Error('Unsupported image type: '.$type); - $info=$this->$mtd($file); - } - set_magic_quotes_runtime($mqr); - $info['i']=count($this->images)+1; - $this->images[$file]=$info; - } - else - $info=$this->images[$file]; - //Automatic width and height calculation if needed - if($w==0 and $h==0) - { - //Put image at 72 dpi - $w=$info['w']/$this->k; - $h=$info['h']/$this->k; - } - if($w==0) - $w=$h*$info['w']/$info['h']; - if($h==0) - $h=$w*$info['h']/$info['w']; - $this->_out(sprintf('q %.2f 0 0 %.2f %.2f %.2f cm /I%d Do Q',$w*$this->k,$h*$this->k,$x*$this->k,($this->h-($y+$h))*$this->k,$info['i'])); - if($link) - $this->Link($x,$y,$w,$h,$link); -} - -function Ln($h='') -{ - //Line feed; default value is last cell height - $this->x=$this->lMargin; - if(is_string($h)) - $this->y+=$this->lasth; - else - $this->y+=$h; -} - -function GetX() -{ - //Get x position - return $this->x; -} - -function SetX($x) -{ - //Set x position - if($x>=0) - $this->x=$x; - else - $this->x=$this->w+$x; -} - -function GetY() -{ - //Get y position - return $this->y; -} - -function SetY($y) -{ - //Set y position and reset x - $this->x=$this->lMargin; - if($y>=0) - $this->y=$y; - else - $this->y=$this->h+$y; -} - -function SetXY($x,$y) -{ - //Set x and y positions - $this->SetY($y); - $this->SetX($x); -} - -function Output($name='',$dest='') -{ - //Output PDF to some destination - // lem9 - //global $HTTP_SERVER_VARS; - - //Finish document if necessary - if($this->state<3) - $this->Close(); - //Normalize parameters - if(is_bool($dest)) - $dest=$dest ? 'D' : 'F'; - $dest=strtoupper($dest); - if($dest=='') - { - if($name=='') - { - $name='doc.pdf'; - $dest='I'; - } - else - $dest='F'; - } - switch($dest) - { - case 'I': - //Send to standard output - // lem9 - //if(isset($HTTP_SERVER_VARS['SERVER_NAME'])) - if(isset($_SERVER['SERVER_NAME'])) - { - //We send to a browser - Header('Content-Type: application/pdf'); - if(headers_sent()) - $this->Error('Some data has already been output to browser, can\'t send PDF file'); - Header('Content-Length: '.strlen($this->buffer)); - Header('Content-disposition: inline; filename="'.$name.'"'); - } - echo $this->buffer; - break; - case 'D': - //Download file - // lem9 - //if(isset($HTTP_SERVER_VARS['HTTP_USER_AGENT']) and strpos($HTTP_SERVER_VARS['HTTP_USER_AGENT'],'MSIE')) - if(isset($_SERVER['HTTP_USER_AGENT']) and strpos($_SERVER['HTTP_USER_AGENT'],'MSIE')) - Header('Content-Type: application/force-download'); - else - Header('Content-Type: application/octet-stream'); - if(headers_sent()) - $this->Error('Some data has already been output to browser, can\'t send PDF file'); - Header('Content-Length: '.strlen($this->buffer)); - Header('Content-disposition: attachment; filename="'.$name.'"'); - echo $this->buffer; - break; - case 'F': - //Save to local file - $f=fopen($name,'wb'); - if(!$f) - $this->Error('Unable to create output file: '.$name); - fwrite($f,$this->buffer,strlen($this->buffer)); - fclose($f); - break; - case 'S': - //Return as a string - return $this->buffer; - default: - $this->Error('Incorrect output destination: '.$dest); - } - return ''; -} - -/******************************************************************************* -* * -* Protected methods * -* * -*******************************************************************************/ -function _dochecks() -{ - //Check for locale-related bug - if(1.1==1) - $this->Error('Don\'t alter the locale before including class file'); - //Check for decimal separator - if(sprintf('%.1f',1.0)!='1.0') - setlocale(LC_NUMERIC,'C'); -} - -function _begindoc() -{ - //Start document - $this->state=1; - $this->_out('%PDF-1.3'); -} - -function _strreplace($what, $to, $where) { - return str_replace($what, $to, $where); -} - -function _putpages() -{ - $nb=$this->page; - if(!empty($this->AliasNbPages)) - { - //Replace number of pages - for($n=1;$n<=$nb;$n++) - $this->pages[$n]=$this->_strreplace($this->AliasNbPages,$nb,$this->pages[$n]); - } - if($this->DefOrientation=='P') - { - $wPt=$this->fwPt; - $hPt=$this->fhPt; - } - else - { - $wPt=$this->fhPt; - $hPt=$this->fwPt; - } - $filter=($this->compress) ? '/Filter /FlateDecode ' : ''; - for($n=1;$n<=$nb;$n++) - { - //Page - $this->_newobj(); - $this->_out('<</Type /Page'); - $this->_out('/Parent 1 0 R'); - if(isset($this->OrientationChanges[$n])) - $this->_out(sprintf('/MediaBox [0 0 %.2f %.2f]',$hPt,$wPt)); - $this->_out('/Resources 2 0 R'); - if(isset($this->PageLinks[$n])) - { - //Links - $annots='/Annots ['; - foreach($this->PageLinks[$n] as $pl) - { - $rect=sprintf('%.2f %.2f %.2f %.2f',$pl[0],$pl[1],$pl[0]+$pl[2],$pl[1]-$pl[3]); - $annots.='<</Type /Annot /Subtype /Link /Rect ['.$rect.'] /Border [0 0 0] '; - if(is_string($pl[4])) - $annots.='/A <</S /URI /URI '.$this->_textstring($pl[4]).'>>>>'; - else - { - $l=$this->links[$pl[4]]; - $h=isset($this->OrientationChanges[$l[0]]) ? $wPt : $hPt; - $annots.=sprintf('/Dest [%d 0 R /XYZ 0 %.2f null]>>',1+2*$l[0],$h-$l[1]*$this->k); - } - } - $this->_out($annots.']'); - } - $this->_out('/Contents '.($this->n+1).' 0 R>>'); - $this->_out('endobj'); - //Page content - $p=($this->compress) ? gzcompress($this->pages[$n]) : $this->pages[$n]; - $this->_newobj(); - $this->_out('<<'.$filter.'/Length '.strlen($p).'>>'); - $this->_putstream($p); - $this->_out('endobj'); - } - //Pages root - $this->offsets[1]=strlen($this->buffer); - $this->_out('1 0 obj'); - $this->_out('<</Type /Pages'); - $kids='/Kids ['; - for($i=0;$i<$nb;$i++) - $kids.=(3+2*$i).' 0 R '; - $this->_out($kids.']'); - $this->_out('/Count '.$nb); - $this->_out(sprintf('/MediaBox [0 0 %.2f %.2f]',$wPt,$hPt)); - $this->_out('>>'); - $this->_out('endobj'); -} - -function _putfonts() -{ - $nf=$this->n; - foreach($this->diffs as $diff) - { - //Encodings - $this->_newobj(); - $this->_out('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$diff.']>>'); - $this->_out('endobj'); - } - $mqr=get_magic_quotes_runtime(); - set_magic_quotes_runtime(0); - foreach($this->FontFiles as $file=>$info) - { - //Font file embedding - $this->_newobj(); - $this->FontFiles[$file]['n']=$this->n; - if(defined('FPDF_FONTPATH')) - $file=FPDF_FONTPATH.$file; - $size=filesize($file); - if(!$size) - $this->Error('Font file not found'); - $this->_out('<</Length '.$size); - if(substr($file,-2)=='.z') - $this->_out('/Filter /FlateDecode'); - $this->_out('/Length1 '.$info['length1']); - if(isset($info['length2'])) - $this->_out('/Length2 '.$info['length2'].' /Length3 0'); - $this->_out('>>'); - $f=fopen($file,'rb'); - $this->_putstream(fread($f,$size)); - fclose($f); - $this->_out('endobj'); - } - set_magic_quotes_runtime($mqr); - foreach($this->fonts as $k=>$font) - { - //Font objects - $this->fonts[$k]['n']=$this->n+1; - $type=$font['type']; - $name=$font['name']; - if($type=='core') - { - //Standard font - $this->_newobj(); - $this->_out('<</Type /Font'); - $this->_out('/BaseFont /'.$name); - $this->_out('/Subtype /Type1'); - if($name!='Symbol' and $name!='ZapfDingbats') - $this->_out('/Encoding /WinAnsiEncoding'); - $this->_out('>>'); - $this->_out('endobj'); - } - elseif($type=='Type1' or $type=='TrueType') - { - //Additional Type1 or TrueType font - $this->_newobj(); - $this->_out('<</Type /Font'); - $this->_out('/BaseFont /'.$name); - $this->_out('/Subtype /'.$type); - $this->_out('/FirstChar 32 /LastChar 255'); - $this->_out('/Widths '.($this->n+1).' 0 R'); - $this->_out('/FontDescriptor '.($this->n+2).' 0 R'); - if($font['enc']) - { - if(isset($font['diff'])) - $this->_out('/Encoding '.($nf+$font['diff']).' 0 R'); - else - $this->_out('/Encoding /WinAnsiEncoding'); - } - $this->_out('>>'); - $this->_out('endobj'); - //Widths - $this->_newobj(); - $cw=&$font['cw']; - $s='['; - for($i=32;$i<=255;$i++) - $s.=$cw[chr($i)].' '; - $this->_out($s.']'); - $this->_out('endobj'); - //Descriptor - $this->_newobj(); - $s='<</Type /FontDescriptor /FontName /'.$name; - foreach($font['desc'] as $k=>$v) - $s.=' /'.$k.' '.$v; - $file=$font['file']; - if($file) - $s.=' /FontFile'.($type=='Type1' ? '' : '2').' '.$this->FontFiles[$file]['n'].' 0 R'; - $this->_out($s.'>>'); - $this->_out('endobj'); - } - else - { - //Allow for additional types - $mtd='_put'.strtolower($type); - if(!method_exists($this,$mtd)) - $this->Error('Unsupported font type: '.$type); - $this->$mtd($font); - } - } -} - -function _putimages() -{ - $filter=($this->compress) ? '/Filter /FlateDecode ' : ''; - reset($this->images); - while(list($file,$info)=each($this->images)) - { - $this->_newobj(); - $this->images[$file]['n']=$this->n; - $this->_out('<</Type /XObject'); - $this->_out('/Subtype /Image'); - $this->_out('/Width '.$info['w']); - $this->_out('/Height '.$info['h']); - if($info['cs']=='Indexed') - $this->_out('/ColorSpace [/Indexed /DeviceRGB '.(strlen($info['pal'])/3-1).' '.($this->n+1).' 0 R]'); - else - { - $this->_out('/ColorSpace /'.$info['cs']); - if($info['cs']=='DeviceCMYK') - $this->_out('/Decode [1 0 1 0 1 0 1 0]'); - } - $this->_out('/BitsPerComponent '.$info['bpc']); - $this->_out('/Filter /'.$info['f']); - if(isset($info['parms'])) - $this->_out($info['parms']); - if(isset($info['trns']) and is_array($info['trns'])) - { - $trns=''; - for($i=0;$i<count($info['trns']);$i++) - $trns.=$info['trns'][$i].' '.$info['trns'][$i].' '; - $this->_out('/Mask ['.$trns.']'); - } - $this->_out('/Length '.strlen($info['data']).'>>'); - $this->_putstream($info['data']); - unset($this->images[$file]['data']); - $this->_out('endobj'); - //Palette - if($info['cs']=='Indexed') - { - $this->_newobj(); - $pal=($this->compress) ? gzcompress($info['pal']) : $info['pal']; - $this->_out('<<'.$filter.'/Length '.strlen($pal).'>>'); - $this->_putstream($pal); - $this->_out('endobj'); - } - } -} - -function _putresources() -{ - $this->_putfonts(); - $this->_putimages(); - //Resource dictionary - $this->offsets[2]=strlen($this->buffer); - $this->_out('2 0 obj'); - $this->_out('<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]'); - $this->_out('/Font <<'); - foreach($this->fonts as $font) - $this->_out('/F'.$font['i'].' '.$font['n'].' 0 R'); - $this->_out('>>'); - if(count($this->images)) - { - $this->_out('/XObject <<'); - foreach($this->images as $image) - $this->_out('/I'.$image['i'].' '.$image['n'].' 0 R'); - $this->_out('>>'); - } - $this->_out('>>'); - $this->_out('endobj'); -} - -function _putinfo() -{ - $this->_out('/Producer '.$this->_textstring('FPDF '.FPDF_VERSION)); - if(!empty($this->title)) - $this->_out('/Title '.$this->_textstring($this->title)); - if(!empty($this->subject)) - $this->_out('/Subject '.$this->_textstring($this->subject)); - if(!empty($this->author)) - $this->_out('/Author '.$this->_textstring($this->author)); - if(!empty($this->keywords)) - $this->_out('/Keywords '.$this->_textstring($this->keywords)); - if(!empty($this->creator)) - $this->_out('/Creator '.$this->_textstring($this->creator)); - $this->_out('/CreationDate '.$this->_textstring('D:'.date('YmdHis'))); -} - -function _putcatalog() -{ - $this->_out('/Type /Catalog'); - $this->_out('/Pages 1 0 R'); - if($this->ZoomMode=='fullpage') - $this->_out('/OpenAction [3 0 R /Fit]'); - elseif($this->ZoomMode=='fullwidth') - $this->_out('/OpenAction [3 0 R /FitH null]'); - elseif($this->ZoomMode=='real') - $this->_out('/OpenAction [3 0 R /XYZ null null 1]'); - elseif(!is_string($this->ZoomMode)) - $this->_out('/OpenAction [3 0 R /XYZ null null '.($this->ZoomMode/100).']'); - if($this->LayoutMode=='single') - $this->_out('/PageLayout /SinglePage'); - elseif($this->LayoutMode=='continuous') - $this->_out('/PageLayout /OneColumn'); - elseif($this->LayoutMode=='two') - $this->_out('/PageLayout /TwoColumnLeft'); -} - -function _puttrailer() -{ - $this->_out('/Size '.($this->n+1)); - $this->_out('/Root '.$this->n.' 0 R'); - $this->_out('/Info '.($this->n-1).' 0 R'); -} - -function _enddoc() -{ - $this->_putpages(); - $this->_putresources(); - //Info - $this->_newobj(); - $this->_out('<<'); - $this->_putinfo(); - $this->_out('>>'); - $this->_out('endobj'); - //Catalog - $this->_newobj(); - $this->_out('<<'); - $this->_putcatalog(); - $this->_out('>>'); - $this->_out('endobj'); - //Cross-ref - $o=strlen($this->buffer); - $this->_out('xref'); - $this->_out('0 '.($this->n+1)); - $this->_out('0000000000 65535 f '); - for($i=1;$i<=$this->n;$i++) - $this->_out(sprintf('%010d 00000 n ',$this->offsets[$i])); - //Trailer - $this->_out('trailer'); - $this->_out('<<'); - $this->_puttrailer(); - $this->_out('>>'); - $this->_out('startxref'); - $this->_out($o); - $this->_out('%%EOF'); - $this->state=3; -} - -function _beginpage($orientation) -{ - $this->page++; - $this->pages[$this->page]=''; - $this->state=2; - $this->x=$this->lMargin; - $this->y=$this->tMargin; - $this->FontFamily=''; - //Page orientation - if(!$orientation) - $orientation=$this->DefOrientation; - else - { - $orientation=strtoupper($orientation{0}); - if($orientation!=$this->DefOrientation) - $this->OrientationChanges[$this->page]=true; - } - if($orientation!=$this->CurOrientation) - { - //Change orientation - if($orientation=='P') - { - $this->wPt=$this->fwPt; - $this->hPt=$this->fhPt; - $this->w=$this->fw; - $this->h=$this->fh; - } - else - { - $this->wPt=$this->fhPt; - $this->hPt=$this->fwPt; - $this->w=$this->fh; - $this->h=$this->fw; - } - $this->PageBreakTrigger=$this->h-$this->bMargin; - $this->CurOrientation=$orientation; - } -} - -function _endpage() -{ - //End of page contents - $this->state=1; -} - -function _newobj() -{ - //Begin a new object - $this->n++; - $this->offsets[$this->n]=strlen($this->buffer); - $this->_out($this->n.' 0 obj'); -} - -function _dounderline($x,$y,$txt) -{ - //Underline text - $up=$this->CurrentFont['up']; - $ut=$this->CurrentFont['ut']; - $w=$this->GetStringWidth($txt)+$this->ws*substr_count($txt,' '); - return sprintf('%.2f %.2f %.2f %.2f re f',$x*$this->k,($this->h-($y-$up/1000*$this->FontSize))*$this->k,$w*$this->k,-$ut/1000*$this->FontSizePt); -} - -function _parsejpg($file) -{ - //Extract info from a JPEG file - $a=GetImageSize($file); - if(!$a) - $this->Error('Missing or incorrect image file: '.$file); - if($a[2]!=2) - $this->Error('Not a JPEG file: '.$file); - if(!isset($a['channels']) or $a['channels']==3) - $colspace='DeviceRGB'; - elseif($a['channels']==4) - $colspace='DeviceCMYK'; - else - $colspace='DeviceGray'; - $bpc=isset($a['bits']) ? $a['bits'] : 8; - //Read whole file - $f=fopen($file,'rb'); - $data=''; - while(!feof($f)) - $data.=fread($f,4096); - fclose($f); - return array('w'=>$a[0],'h'=>$a[1],'cs'=>$colspace,'bpc'=>$bpc,'f'=>'DCTDecode','data'=>$data); -} - -function _parsepng($file) -{ - //Extract info from a PNG file - $f=fopen($file,'rb'); - if(!$f) - $this->Error('Can\'t open image file: '.$file); - //Check signature - if(fread($f,8)!=chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) - $this->Error('Not a PNG file: '.$file); - //Read header chunk - fread($f,4); - if(fread($f,4)!='IHDR') - $this->Error('Incorrect PNG file: '.$file); - $w=$this->_freadint($f); - $h=$this->_freadint($f); - $bpc=ord(fread($f,1)); - if($bpc>8) - $this->Error('16-bit depth not supported: '.$file); - $ct=ord(fread($f,1)); - if($ct==0) - $colspace='DeviceGray'; - elseif($ct==2) - $colspace='DeviceRGB'; - elseif($ct==3) - $colspace='Indexed'; - else - $this->Error('Alpha channel not supported: '.$file); - if(ord(fread($f,1))!=0) - $this->Error('Unknown compression method: '.$file); - if(ord(fread($f,1))!=0) - $this->Error('Unknown filter method: '.$file); - if(ord(fread($f,1))!=0) - $this->Error('Interlacing not supported: '.$file); - fread($f,4); - $parms='/DecodeParms <</Predictor 15 /Colors '.($ct==2 ? 3 : 1).' /BitsPerComponent '.$bpc.' /Columns '.$w.'>>'; - //Scan chunks looking for palette, transparency and image data - $pal=''; - $trns=''; - $data=''; - do - { - $n=$this->_freadint($f); - $type=fread($f,4); - if($type=='PLTE') - { - //Read palette - $pal=fread($f,$n); - fread($f,4); - } - elseif($type=='tRNS') - { - //Read transparency info - $t=fread($f,$n); - if($ct==0) - $trns=array(ord(substr($t,1,1))); - elseif($ct==2) - $trns=array(ord(substr($t,1,1)),ord(substr($t,3,1)),ord(substr($t,5,1))); - else - { - $pos=strpos($t,chr(0)); - if(is_int($pos)) - $trns=array($pos); - } - fread($f,4); - } - elseif($type=='IDAT') - { - //Read image data block - $data.=fread($f,$n); - fread($f,4); - } - elseif($type=='IEND') - break; - else - fread($f,$n+4); - } - while($n); - if($colspace=='Indexed' and empty($pal)) - $this->Error('Missing palette in '.$file); - fclose($f); - return array('w'=>$w,'h'=>$h,'cs'=>$colspace,'bpc'=>$bpc,'f'=>'FlateDecode','parms'=>$parms,'pal'=>$pal,'trns'=>$trns,'data'=>$data); -} - -function _freadint($f) -{ - //Read a 4-byte integer from file - $i=ord(fread($f,1))<<24; - $i+=ord(fread($f,1))<<16; - $i+=ord(fread($f,1))<<8; - $i+=ord(fread($f,1)); - return $i; -} - -function _textstring($s) -{ - //Format a text string - return '('.$this->_escape($s).')'; -} - -function _escape($s) -{ - //Add \ before \, ( and ) - return str_replace(')','\\)',str_replace('(','\\(',str_replace('\\','\\\\',$s))); -} - -function _putstream($s) -{ - $this->_out('stream'); - $this->_out($s); - $this->_out('endstream'); -} - -function _out($s) -{ - //Add a line to the document - if($this->state==2) - $this->pages[$this->page].=$s."\n"; - else - $this->buffer.=$s."\n"; -} -//End of class -} - -//Handle special IE contype request -// lem9 -//if(isset($HTTP_SERVER_VARS['HTTP_USER_AGENT']) and $HTTP_SERVER_VARS['HTTP_USER_AGENT']=='contype') -if(isset($_SERVER['HTTP_USER_AGENT']) and $_SERVER['HTTP_USER_AGENT']=='contype') -{ - Header('Content-Type: application/pdf'); - exit; -} - -} +/** + * Software: FPDF * + * + * Version: 1.52 * + * + * Date: 2003-12-30 * + * + * Author: Olivier PLATHEY * + * + * License: Freeware * + * + * + * + * You may use, modify and redistribute this software as you wish. * + */ + +if (!class_exists('FPDF')) { + define('FPDF_VERSION', '1.52'); + + class FPDF { + // Private properties + var $page; //current page number + var $n; //current object number + var $offsets; //array of object offsets + var $buffer; //buffer holding in-memory PDF + var $pages; //array containing pages + var $state; //current document state + var $compress; //compression flag + var $DefOrientation; //default orientation + var $CurOrientation; //current orientation + var $OrientationChanges; //array indicating orientation changes + var $k; //scale factor (number of points in user unit) + var $fwPt, $fhPt; //dimensions of page format in points + var $fw, $fh; //dimensions of page format in user unit + var $wPt, $hPt; //current dimensions of page in points + var $w, $h; //current dimensions of page in user unit + var $lMargin; //left margin + var $tMargin; //top margin + var $rMargin; //right margin + var $bMargin; //page break margin + var $cMargin; //cell margin + var $x, $y; //current position in user unit for cell positioning + var $lasth; //height of last cell printed + var $LineWidth; //line width in user unit + var $CoreFonts; //array of standard font names + var $fonts; //array of used fonts + var $FontFiles; //array of font files + var $diffs; //array of encoding differences + var $images; //array of used images + var $PageLinks; //array of links in pages + var $links; //array of internal links + var $FontFamily; //current font family + var $FontStyle; //current font style + var $underline; //underlining flag + var $CurrentFont; //current font info + var $FontSizePt; //current font size in points + var $FontSize; //current font size in user unit + var $DrawColor; //commands for drawing color + var $FillColor; //commands for filling color + var $TextColor; //commands for text color + var $ColorFlag; //indicates whether fill and text colors are different + var $ws; //word spacing + var $AutoPageBreak; //automatic page breaking + var $PageBreakTrigger; //threshold used to trigger page breaks + var $InFooter; //flag set when processing footer + var $ZoomMode; //zoom display mode + var $LayoutMode; //layout display mode + var $title; //title + var $subject; //subject + var $author; //author + var $keywords; //keywords + var $creator; //creator + var $AliasNbPages; //alias for total number of pages + + /** + * Public methods * + */ + + function FPDF($orientation = 'P', $unit = 'mm', $format = 'A4') + { + // Some checks + $this->_dochecks(); + // Initialization of properties + $this->page = 0; + $this->n = 2; + $this->buffer = ''; + $this->pages = array(); + $this->OrientationChanges = array(); + $this->state = 0; + $this->fonts = array(); + $this->FontFiles = array(); + $this->diffs = array(); + $this->images = array(); + $this->links = array(); + $this->InFooter = false; + $this->lasth = 0; + $this->FontFamily = ''; + $this->FontStyle = ''; + $this->FontSizePt = 12; + $this->underline = false; + $this->DrawColor = '0 G'; + $this->FillColor = '0 g'; + $this->TextColor = '0 g'; + $this->ColorFlag = false; + $this->ws = 0; + // Standard fonts + $this->CoreFonts = array('courier' => 'Courier', 'courierB' => 'Courier-Bold', 'courierI' => 'Courier-Oblique', 'courierBI' => 'Courier-BoldOblique', + 'helvetica' => 'Helvetica', 'helveticaB' => 'Helvetica-Bold', 'helveticaI' => 'Helvetica-Oblique', 'helveticaBI' => 'Helvetica-BoldOblique', + 'times' => 'Times-Roman', 'timesB' => 'Times-Bold', 'timesI' => 'Times-Italic', 'timesBI' => 'Times-BoldItalic', + 'symbol' => 'Symbol', 'zapfdingbats' => 'ZapfDingbats'); + // Scale factor + if ($unit == 'pt') { + $this->k = 1; + } elseif ($unit == 'mm') { + $this->k = 72 / 25.4; + } elseif ($unit == 'cm') { + $this->k = 72 / 2.54; + } elseif ($unit == 'in') { + $this->k = 72; + } else { + $this->Error('Incorrect unit: ' . $unit); + } + // Page format + if (is_string($format)) { + $format = strtolower($format); + + if ($format == 'a3') { + $format = array(841.89, 1190.55); + } elseif ($format == 'a4') { + $format = array(595.28, 841.89); + } elseif ($format == 'a5') { + $format = array(420.94, 595.28); + } elseif ($format == 'letter') { + $format = array(612, 792); + } elseif ($format == 'legal') { + $format = array(612, 1008); + } else { + $this->Error('Unknown page format: ' . $format); + } + + $this->fwPt = $format[0]; + $this->fhPt = $format[1]; + } else { + $this->fwPt = $format[0] * $this->k; + $this->fhPt = $format[1] * $this->k; + } + + $this->fw = $this->fwPt / $this->k; + $this->fh = $this->fhPt / $this->k; + // Page orientation + $orientation = strtolower($orientation); + + if ($orientation == 'p' or $orientation == 'portrait') { + $this->DefOrientation = 'P'; + $this->wPt = $this->fwPt; + $this->hPt = $this->fhPt; + } elseif ($orientation == 'l' or $orientation == 'landscape') { + $this->DefOrientation = 'L'; + $this->wPt = $this->fhPt; + $this->hPt = $this->fwPt; + } else { + $this->Error('Incorrect orientation: ' . $orientation); + } + $this->CurOrientation = $this->DefOrientation; + $this->w = $this->wPt / $this->k; + $this->h = $this->hPt / $this->k; + // Page margins (1 cm) + $margin = 28.35 / $this->k; + + $this->SetMargins($margin, $margin); + // Interior cell margin (1 mm) + $this->cMargin = $margin / 10; + // Line width (0.2 mm) + $this->LineWidth = .567 / $this->k; + // Automatic page break + $this->SetAutoPageBreak(true, 2 * $margin); + // Full width display mode + $this->SetDisplayMode('fullwidth'); + // Compression + $this->SetCompression(true); + } + + function SetMargins($left, $top, $right = -1) + { + // Set left, top and right margins + $this->lMargin = $left; + + $this->tMargin = $top; + + if ($right == -1) { + $right = $left; + } + + $this->rMargin = $right; + } + + function SetLeftMargin($margin) + { + // Set left margin + $this->lMargin = $margin; + + if ($this->page > 0 and $this->x < $margin) { + $this->x = $margin; + } + } + + function SetTopMargin($margin) + { + // Set top margin + $this->tMargin = $margin; + } + + function SetRightMargin($margin) + { + // Set right margin + $this->rMargin = $margin; + } + + function SetAutoPageBreak($auto, $margin = 0) + { + // Set auto page break mode and triggering margin + $this->AutoPageBreak = $auto; + $this->bMargin = $margin; + $this->PageBreakTrigger = $this->h - $margin; + } + + function SetDisplayMode($zoom, $layout = 'continuous') + { + // Set display mode in viewer + if ($zoom == 'fullpage' or $zoom == 'fullwidth' or $zoom == 'real' or $zoom == 'default' or !is_string($zoom)) { + $this->ZoomMode = $zoom; + } else { + $this->Error('Incorrect zoom display mode: ' . $zoom); + } + + if ($layout == 'single' or $layout == 'continuous' or $layout == 'two' or $layout == 'default') { + $this->LayoutMode = $layout; + } else { + $this->Error('Incorrect layout display mode: ' . $layout); + } + } + + function SetCompression($compress) + { + // Set page compression + if (function_exists('gzcompress')) { + $this->compress = $compress; + } else { + $this->compress = false; + } + } + + function SetTitle($title) + { + // Title of document + $this->title = $title; + } + + function SetSubject($subject) + { + // Subject of document + $this->subject = $subject; + } + + function SetAuthor($author) + { + // Author of document + $this->author = $author; + } + + function SetKeywords($keywords) + { + // Keywords of document + $this->keywords = $keywords; + } + + function SetCreator($creator) + { + // Creator of document + $this->creator = $creator; + } + + function AliasNbPages($alias = '{nb}') + { + // Define an alias for total number of pages + $this->AliasNbPages = $alias; + } + + function Error($msg) + { + // Fatal error + die('<B>FPDF error: </B>' . $msg); + } + + function Open() + { + // Begin document + if ($this->state == 0) { + $this->_begindoc(); + } + } + + function Close() + { + // Terminate document + if ($this->state == 3) { + return; + } + + if ($this->page == 0) { + $this->AddPage(); + } + // Page footer + $this->InFooter = true; + $this->Footer(); + $this->InFooter = false; + // Close page + $this->_endpage(); + // Close document + $this->_enddoc(); + } + + function AddPage($orientation = '') + { + // Start a new page + if ($this->state == 0) { + $this->Open(); + } + + $family = $this->FontFamily; + $style = $this->FontStyle . ($this->underline ? 'U' : ''); + $size = $this->FontSizePt; + $lw = $this->LineWidth; + $dc = $this->DrawColor; + $fc = $this->FillColor; + $tc = $this->TextColor; + $cf = $this->ColorFlag; + + if ($this->page > 0) { + // Page footer + $this->InFooter = true; + $this->Footer(); + $this->InFooter = false; + // Close page + $this->_endpage(); + } + // Start new page + $this->_beginpage($orientation); + // Set line cap style to square + $this->_out('2 J'); + // Set line width + $this->LineWidth = $lw; + + $this->_out(sprintf('%.2f w', $lw * $this->k)); + // Set font + if ($family) { + $this->SetFont($family, $style, $size); + } + // Set colors + $this->DrawColor = $dc; + + if ($dc != '0 G') { + $this->_out($dc); + } + + $this->FillColor = $fc; + + if ($fc != '0 g') { + $this->_out($fc); + } + + $this->TextColor = $tc; + $this->ColorFlag = $cf; + // Page header + $this->Header(); + // Restore line width + if ($this->LineWidth != $lw) { + $this->LineWidth = $lw; + $this->_out(sprintf('%.2f w', $lw * $this->k)); + } + // Restore font + if ($family) { + $this->SetFont($family, $style, $size); + } + // Restore colors + if ($this->DrawColor != $dc) { + $this->DrawColor = $dc; + $this->_out($dc); + } + + if ($this->FillColor != $fc) { + $this->FillColor = $fc; + $this->_out($fc); + } + + $this->TextColor = $tc; + $this->ColorFlag = $cf; + } + + function Header() + { + // To be implemented in your own inherited class + } + + function Footer() + { + // To be implemented in your own inherited class + } + + function PageNo() + { + // Get current page number + return $this->page; + } + + function SetDrawColor($r, $g = -1, $b = -1) + { + // Set color for all stroking operations + if (($r == 0 and $g == 0 and $b == 0) or $g == -1) { + $this->DrawColor = sprintf('%.3f G', $r / 255); + } else { + $this->DrawColor = sprintf('%.3f %.3f %.3f RG', $r / 255, $g / 255, $b / 255); + } + + if ($this->page > 0) { + $this->_out($this->DrawColor); + } + } + + function SetFillColor($r, $g = -1, $b = -1) + { + // Set color for all filling operations + if (($r == 0 and $g == 0 and $b == 0) or $g == -1) { + $this->FillColor = sprintf('%.3f g', $r / 255); + } else { + $this->FillColor = sprintf('%.3f %.3f %.3f rg', $r / 255, $g / 255, $b / 255); + } + + $this->ColorFlag = ($this->FillColor != $this->TextColor); + + if ($this->page > 0) { + $this->_out($this->FillColor); + } + } + + function SetTextColor($r, $g = -1, $b = -1) + { + // Set color for text + if (($r == 0 and $g == 0 and $b == 0) or $g == -1) { + $this->TextColor = sprintf('%.3f g', $r / 255); + } else { + $this->TextColor = sprintf('%.3f %.3f %.3f rg', $r / 255, $g / 255, $b / 255); + } + + $this->ColorFlag = ($this->FillColor != $this->TextColor); + } + + function GetStringWidth($s) + { + // Get width of a string in the current font + $s = (string)$s; + $cw = &$this->CurrentFont['cw']; + $w = 0; + $l = strlen($s); + + for ($i = 0;$i < $l;$i++) { + $w += $cw[$s{$i}]; + } + + return $w * $this->FontSize / 1000; + } + + function SetLineWidth($width) + { + // Set line width + $this->LineWidth = $width; + + if ($this->page > 0) { + $this->_out(sprintf('%.2f w', $width * $this->k)); + } + } + + function Line($x1, $y1, $x2, $y2) + { + // Draw a line + $this->_out(sprintf('%.2f %.2f m %.2f %.2f l S', $x1 * $this->k, ($this->h - $y1) * $this->k, $x2 * $this->k, ($this->h - $y2) * $this->k)); + } + + function Rect($x, $y, $w, $h, $style = '') + { + // Draw a rectangle + if ($style == 'F') { + $op = 'f'; + } elseif ($style == 'FD' or $style == 'DF') { + $op = 'B'; + } else { + $op = 'S'; + } + + $this->_out(sprintf('%.2f %.2f %.2f %.2f re %s', $x * $this->k, ($this->h - $y) * $this->k, $w * $this->k, - $h * $this->k, $op)); + } + + function AddFont($family, $style = '', $file = '') + { + // Add a TrueType or Type1 font + $family = strtolower($family); + + if ($family == 'arial') { + $family = 'helvetica'; + } + + $style = strtoupper($style); + + if ($style == 'IB') { + $style = 'BI'; + } + + if (isset($this->fonts[$family . $style])) { + $this->Error('Font already added: ' . $family . ' ' . $style); + } + + if ($file == '') { + $file = str_replace(' ', '', $family) . strtolower($style) . '.php'; + } + + if (defined('FPDF_FONTPATH')) { + $file = FPDF_FONTPATH . $file; + } + + include($file); + + if (!isset($name)) { + $this->Error('Could not include font definition file'); + } + + $i = count($this->fonts) + 1; + $this->fonts[$family . $style] = array('i' => $i, 'type' => $type, 'name' => $name, 'desc' => $desc, 'up' => $up, 'ut' => $ut, 'cw' => $cw, 'enc' => $enc, 'file' => $file); + + if ($diff) { + // Search existing encodings + $d = 0; + $nb = count($this->diffs); + + for ($i = 1;$i <= $nb;$i++) { + if ($this->diffs[$i] == $diff) { + $d = $i; + break; + } + } + + if ($d == 0) { + $d = $nb + 1; + $this->diffs[$d] = $diff; + } + + $this->fonts[$family . $style]['diff'] = $d; + } + + if ($file) { + if ($type == 'TrueType') { + $this->FontFiles[$file] = array('length1' => $originalsize); + } else { + $this->FontFiles[$file] = array('length1' => $size1, 'length2' => $size2); + } + } + } + + function SetFont($family, $style = '', $size = 0) + { + // Select a font; size given in points + global $fpdf_charwidths; + + $family = strtolower($family); + + if ($family == '') { + $family = $this->FontFamily; + } + + if ($family == 'arial') { + $family = 'helvetica'; + } elseif ($family == 'symbol' or $family == 'zapfdingbats') { + $style = ''; + } + + $style = strtoupper($style); + + if (is_int(strpos($style, 'U'))) { + $this->underline = true; + $style = str_replace('U', '', $style); + } else { + $this->underline = false; + } + + if ($style == 'IB') { + $style = 'BI'; + } + + if ($size == 0) { + $size = $this->FontSizePt; + } + // Test if font is already selected + if ($this->FontFamily == $family and $this->FontStyle == $style and $this->FontSizePt == $size) { + return; + } + // Test if used for the first time + $fontkey = $family . $style; + + if (!isset($this->fonts[$fontkey])) { + // Check if one of the standard fonts + if (isset($this->CoreFonts[$fontkey])) { + if (!isset($fpdf_charwidths[$fontkey])) { + // Load metric file + $file = $family; + + if ($family == 'times' or $family == 'helvetica') { + $file .= strtolower($style); + } + + $file .= '.php'; + + if (defined('FPDF_FONTPATH')) { + $file = FPDF_FONTPATH . $file; + } + + include($file); + + if (!isset($fpdf_charwidths[$fontkey])) { + $this->Error('Could not include font metric file'); + } + } + + $i = count($this->fonts) + 1; + $this->fonts[$fontkey] = array('i' => $i, 'type' => 'core', 'name' => $this->CoreFonts[$fontkey], 'up' => -100, 'ut' => 50, 'cw' => $fpdf_charwidths[$fontkey]); + } else { + $this->Error('Undefined font: ' . $family . ' ' . $style); + } + } + // Select it + $this->FontFamily = $family; + $this->FontStyle = $style; + $this->FontSizePt = $size; + $this->FontSize = $size / $this->k; + $this->CurrentFont = &$this->fonts[$fontkey]; + + if ($this->page > 0) { + $this->_out(sprintf('BT /F%d %.2f Tf ET', $this->CurrentFont['i'], $this->FontSizePt)); + } + } + + function SetFontSize($size) + { + // Set font size in points + if ($this->FontSizePt == $size) { + return; + } + + $this->FontSizePt = $size; + $this->FontSize = $size / $this->k; + + if ($this->page > 0) { + $this->_out(sprintf('BT /F%d %.2f Tf ET', $this->CurrentFont['i'], $this->FontSizePt)); + } + } + + function AddLink() + { + // Create a new internal link + $n = count($this->links) + 1; + $this->links[$n] = array(0, 0); + return $n; + } + + function SetLink($link, $y = 0, $page = -1) + { + // Set destination of internal link + if ($y == -1) { + $y = $this->y; + } + + if ($page == -1) { + $page = $this->page; + } + + $this->links[$link] = array($page, $y); + } + + function Link($x, $y, $w, $h, $link) + { + // Put a link on the page + $this->PageLinks[$this->page][] = array($x * $this->k, $this->hPt - $y * $this->k, $w * $this->k, $h * $this->k, $link); + } + + function Text($x, $y, $txt) + { + // Output a string + $s = sprintf('BT %.2f %.2f Td (%s) Tj ET', $x * $this->k, ($this->h - $y) * $this->k, $this->_escape($txt)); + + if ($this->underline and $txt != '') { + $s .= ' ' . $this->_dounderline($x, $y, $txt); + } + + if ($this->ColorFlag) { + $s = 'q ' . $this->TextColor . ' ' . $s . ' Q'; + } + + $this->_out($s); + } + + function AcceptPageBreak() + { + // Accept automatic page break or not + return $this->AutoPageBreak; + } + + function Cell($w, $h = 0, $txt = '', $border = 0, $ln = 0, $align = '', $fill = 0, $link = '') + { + // Output a cell + $k = $this->k; + + if ($this->y + $h > $this->PageBreakTrigger and !$this->InFooter and $this->AcceptPageBreak()) { + // Automatic page break + $x = $this->x; + $ws = $this->ws; + + if ($ws > 0) { + $this->ws = 0; + $this->_out('0 Tw'); + } + + $this->AddPage($this->CurOrientation); + $this->x = $x; + + if ($ws > 0) { + $this->ws = $ws; + $this->_out(sprintf('%.3f Tw', $ws * $k)); + } + } + + if ($w == 0) { + $w = $this->w - $this->rMargin - $this->x; + } + + $s = ''; + + if ($fill == 1 or $border == 1) { + if ($fill == 1) { + $op = ($border == 1) ? 'B' : 'f'; + } else { + $op = 'S'; + } + + $s = sprintf('%.2f %.2f %.2f %.2f re %s ', $this->x * $k, ($this->h - $this->y) * $k, $w * $k, - $h * $k, $op); + } + + if (is_string($border)) { + $x = $this->x; + $y = $this->y; + + if (is_int(strpos($border, 'L'))) { + $s .= sprintf('%.2f %.2f m %.2f %.2f l S ', $x * $k, ($this->h - $y) * $k, $x * $k, ($this->h - ($y + $h)) * $k); + } + + if (is_int(strpos($border, 'T'))) { + $s .= sprintf('%.2f %.2f m %.2f %.2f l S ', $x * $k, ($this->h - $y) * $k, ($x + $w) * $k, ($this->h - $y) * $k); + } + + if (is_int(strpos($border, 'R'))) { + $s .= sprintf('%.2f %.2f m %.2f %.2f l S ', ($x + $w) * $k, ($this->h - $y) * $k, ($x + $w) * $k, ($this->h - ($y + $h)) * $k); + } + + if (is_int(strpos($border, 'B'))) { + $s .= sprintf('%.2f %.2f m %.2f %.2f l S ', $x * $k, ($this->h - ($y + $h)) * $k, ($x + $w) * $k, ($this->h - ($y + $h)) * $k); + } + } + + if ($txt != '') { + if ($align == 'R') { + $dx = $w - $this->cMargin - $this->GetStringWidth($txt); + } elseif ($align == 'C') { + $dx = ($w - $this->GetStringWidth($txt)) / 2; + } else { + $dx = $this->cMargin; + } + + if ($this->ColorFlag) { + $s .= 'q ' . $this->TextColor . ' '; + } + + $txt2 = str_replace(')', '\\)', str_replace('(', '\\(', str_replace('\\', '\\\\', $txt))); + + $s .= sprintf('BT %.2f %.2f Td (%s) Tj ET', ($this->x + $dx) * $k, ($this->h - ($this->y + .5 * $h + .3 * $this->FontSize)) * $k, $txt2); + + if ($this->underline) { + $s .= ' ' . $this->_dounderline($this->x + $dx, $this->y + .5 * $h + .3 * $this->FontSize, $txt); + } + + if ($this->ColorFlag) { + $s .= ' Q'; + } + + if ($link) { + $this->Link($this->x + $dx, $this->y + .5 * $h - .5 * $this->FontSize, $this->GetStringWidth($txt), $this->FontSize, $link); + } + } + + if ($s) { + $this->_out($s); + } + + $this->lasth = $h; + + if ($ln > 0) { + // Go to next line + $this->y += $h; + if ($ln == 1) { + $this->x = $this->lMargin; + } + } else { + $this->x += $w; + } + } + + function MultiCell($w, $h, $txt, $border = 0, $align = 'J', $fill = 0) + { + // Output text with automatic or explicit line breaks + $cw = &$this->CurrentFont['cw']; + + if ($w == 0) { + $w = $this->w - $this->rMargin - $this->x; + } + + $wmax = ($w-2 * $this->cMargin) * 1000 / $this->FontSize; + $s = str_replace("\r", '', $txt); + $nb = strlen($s); + + if ($nb > 0 and $s[$nb-1] == "\n") { + $nb--; + } + + $b = 0; + + if ($border) { + if ($border == 1) { + $border = 'LTRB'; + $b = 'LRT'; + $b2 = 'LR'; + } else { + $b2 = ''; + if (is_int(strpos($border, 'L'))) { + $b2 .= 'L'; + } + + if (is_int(strpos($border, 'R'))) { + $b2 .= 'R'; + } + + $b = is_int(strpos($border, 'T')) ? $b2 . 'T' : $b2; + } + } + + $sep = -1; + $i = 0; + $j = 0; + $l = 0; + $ns = 0; + $nl = 1; + + while ($i < $nb) { + // Get next character + $c = $s{$i}; + + if ($c == "\n") { + // Explicit line break + if ($this->ws > 0) { + $this->ws = 0; + $this->_out('0 Tw'); + } + + $this->Cell($w, $h, substr($s, $j, $i - $j), $b, 2, $align, $fill); + $i++; + $sep = -1; + $j = $i; + $l = 0; + $ns = 0; + $nl++; + + if ($border and $nl == 2) { + $b = $b2; + } + + continue; + } + + if ($c == ' ') { + $sep = $i; + $ls = $l; + $ns++; + } + + $l += isset($cw[ord($c)])?$cw[ord($c)]:0; + + if ($l > $wmax) { + // Automatic line break + if ($sep == -1) { + if ($i == $j) { + $i++; + } + + if ($this->ws > 0) { + $this->ws = 0; + $this->_out('0 Tw'); + } + + $this->Cell($w, $h, substr($s, $j, $i - $j), $b, 2, $align, $fill); + } else { + if ($align == 'J') { + $this->ws = ($ns > 1) ? ($wmax - $ls) / 1000 * $this->FontSize / ($ns-1) : 0; + $this->_out(sprintf('%.3f Tw', $this->ws * $this->k)); + } + + $this->Cell($w, $h, substr($s, $j, $sep - $j), $b, 2, $align, $fill); + $i = $sep + 1; + } + + $sep = -1; + $j = $i; + $l = 0; + $ns = 0; + $nl++; + + if ($border and $nl == 2) { + $b = $b2; + } + } else { + $i++; + } + } + // Last chunk + if ($this->ws > 0) { + $this->ws = 0; + $this->_out('0 Tw'); + } + + if ($border and is_int(strpos($border, 'B'))) { + $b .= 'B'; + } + + $this->Cell($w, $h, substr($s, $j, $i - $j), $b, 2, $align, $fill); + $this->x = $this->lMargin; + } + + function Write($h, $txt, $link = '') + { + // Output text in flowing mode + $cw = &$this->CurrentFont['cw']; + $w = $this->w - $this->rMargin - $this->x; + $wmax = ($w-2 * $this->cMargin) * 1000 / $this->FontSize; + $s = str_replace("\r", '', $txt); + $nb = strlen($s); + $sep = -1; + $i = 0; + $j = 0; + $l = 0; + $nl = 1; + + while ($i < $nb) { + // Get next character + $c = $s{$i}; + + if ($c == "\n") { + // Explicit line break + $this->Cell($w, $h, substr($s, $j, $i - $j), 0, 2, '', 0, $link); + $i++; + $sep = -1; + $j = $i; + $l = 0; + + if ($nl == 1) { + $this->x = $this->lMargin; + $w = $this->w - $this->rMargin - $this->x; + $wmax = ($w-2 * $this->cMargin) * 1000 / $this->FontSize; + } + + $nl++; + continue; + } + + if ($c == ' ') { + $sep = $i; + } + + $l += $cw[$c]; + + if ($l > $wmax) { + // Automatic line break + if ($sep == -1) { + if ($this->x > $this->lMargin) { + // Move to next line + $this->x = $this->lMargin; + $this->y += $h; + $w = $this->w - $this->rMargin - $this->x; + $wmax = ($w-2 * $this->cMargin) * 1000 / $this->FontSize; + $i++; + $nl++; + continue; + } + + if ($i == $j) { + $i++; + } + + $this->Cell($w, $h, substr($s, $j, $i - $j), 0, 2, '', 0, $link); + } else { + $this->Cell($w, $h, substr($s, $j, $sep - $j), 0, 2, '', 0, $link); + $i = $sep + 1; + } + + $sep = -1; + $j = $i; + $l = 0; + + if ($nl == 1) { + $this->x = $this->lMargin; + $w = $this->w - $this->rMargin - $this->x; + $wmax = ($w-2 * $this->cMargin) * 1000 / $this->FontSize; + } + + $nl++; + } else { + $i++; + } + } + // Last chunk + if ($i != $j) { + $this->Cell($l / 1000 * $this->FontSize, $h, substr($s, $j), 0, 0, '', 0, $link); + } + } + + function Image($file, $x, $y, $w = 0, $h = 0, $type = '', $link = '') + { + // Put an image on the page + if (!isset($this->images[$file])) { + // First use of image, get info + if ($type == '') { + $pos = strrpos($file, '.'); + if (!$pos) { + $this->Error('Image file has no extension and no type was specified: ' . $file); + } + + $type = substr($file, $pos + 1); + } + + $type = strtolower($type); + $mqr = get_magic_quotes_runtime(); + set_magic_quotes_runtime(0); + + if ($type == 'jpg' or $type == 'jpeg') { + $info = $this->_parsejpg($file); + } elseif ($type == 'png') { + $info = $this->_parsepng($file); + } else { + // Allow for additional formats + $mtd = '_parse' . $type; + + if (!method_exists($this, $mtd)) { + $this->Error('Unsupported image type: ' . $type); + } + + $info = $this->$mtd($file); + } + + set_magic_quotes_runtime($mqr); + $info['i'] = count($this->images) + 1; + $this->images[$file] = $info; + } else { + $info = $this->images[$file]; + } + // Automatic width and height calculation if needed + if ($w == 0 and $h == 0) { + // Put image at 72 dpi + $w = $info['w'] / $this->k; + $h = $info['h'] / $this->k; + } + + if ($w == 0) { + $w = $h * $info['w'] / $info['h']; + } + + if ($h == 0) { + $h = $w * $info['h'] / $info['w']; + } + + $this->_out(sprintf('q %.2f 0 0 %.2f %.2f %.2f cm /I%d Do Q', $w * $this->k, $h * $this->k, $x * $this->k, ($this->h - ($y + $h)) * $this->k, $info['i'])); + + if ($link) { + $this->Link($x, $y, $w, $h, $link); + } + } + + function Ln($h = '') + { + // Line feed; default value is last cell height + $this->x = $this->lMargin; + + if (is_string($h)) { + $this->y += $this->lasth; + } else { + $this->y += $h; + } + } + + function GetX() + { + // Get x position + return $this->x; + } + + function SetX($x) + { + // Set x position + if ($x >= 0) { + $this->x = $x; + } else { + $this->x = $this->w + $x; + } + } + + function GetY() + { + // Get y position + return $this->y; + } + + function SetY($y) + { + // Set y position and reset x + $this->x = $this->lMargin; + + if ($y >= 0) { + $this->y = $y; + } else { + $this->y = $this->h + $y; + } + } + + function SetXY($x, $y) + { + // Set x and y positions + $this->SetY($y); + $this->SetX($x); + } + + function Output($name = '', $dest = '') + { + // Output PDF to some destination + // lem9 + // global $HTTP_SERVER_VARS; + // Finish document if necessary + if ($this->state < 3) { + $this->Close(); + } + // Normalize parameters + if (is_bool($dest)) { + $dest = $dest ? 'D' : 'F'; + } + + $dest = strtoupper($dest); + + if ($dest == '') { + if ($name == '') { + $name = 'doc.pdf'; + $dest = 'I'; + } else { + $dest = 'F'; + } + } + + switch ($dest) { + case 'I': + // Send to standard output + // lem9 + // if (isset($HTTP_SERVER_VARS['SERVER_NAME'])) + if (isset($_SERVER['SERVER_NAME'])) { + // We send to a browser + header('Content-Type: application/pdf'); + + if (headers_sent()) { + $this->Error('Some data has already been output to browser, can\'t send PDF file'); + } + + header('Content-Length: ' . strlen($this->buffer)); + header('Content-disposition: inline; filename="' . $name . '"'); + } + + echo $this->buffer; + break; + + case 'D': + // Download file + // lem9 + // if (isset($HTTP_SERVER_VARS['HTTP_USER_AGENT']) and strpos($HTTP_SERVER_VARS['HTTP_USER_AGENT'], 'MSIE')) + if (isset($_SERVER['HTTP_USER_AGENT']) and strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')) { + header('Content-Type: application/force-download'); + } else { + header('Content-Type: application/octet-stream'); + } + + if (headers_sent()) { + $this->Error('Some data has already been output to browser, can\'t send PDF file'); + } + + header('Content-Length: ' . strlen($this->buffer)); + header('Content-disposition: attachment; filename="' . $name . '"'); + echo $this->buffer; + break; + + case 'F': + // Save to local file + $f = fopen($name, 'wb'); + + if (!$f) { + $this->Error('Unable to create output file: ' . $name); + } + + fwrite($f, $this->buffer, strlen($this->buffer)); + fclose($f); + break; + + case 'S': + // Return as a string + return $this->buffer; + + default: + + $this->Error('Incorrect output destination: ' . $dest); + } + + return ''; + } + + /** + * Protected methods * + */ + + function _dochecks() + { + // Check for locale-related bug + if (1.1 == 1) { + $this->Error('Don\'t alter the locale before including class file'); + } + // Check for decimal separator + if (sprintf('%.1f', 1.0) != '1.0') { + setlocale(LC_NUMERIC, 'C'); + } + } + + function _begindoc() + { + // Start document + $this->state = 1; + $this->_out('%PDF-1.3'); + } + + function _strreplace($what, $to, $where) + { + return str_replace($what, $to, $where); + } + + function _putpages() + { + $nb = $this->page; + + if (!empty($this->AliasNbPages)) { + // Replace number of pages + for ($n = 1; $n <= $nb; $n++) { + $this->pages[$n] = $this->_strreplace($this->AliasNbPages, $nb, $this->pages[$n]); + } + } + + if ($this->DefOrientation == 'P') { + $wPt = $this->fwPt; + $hPt = $this->fhPt; + } else { + $wPt = $this->fhPt; + $hPt = $this->fwPt; + } + + $filter = ($this->compress) ? '/Filter /FlateDecode ' : ''; + + for ($n = 1; $n <= $nb; $n++) { + // Page + $this->_newobj(); + $this->_out('<</Type /Page'); + $this->_out('/Parent 1 0 R'); + + if (isset($this->OrientationChanges[$n])) { + $this->_out(sprintf('/MediaBox [0 0 %.2f %.2f]', $hPt, $wPt)); + } + + $this->_out('/Resources 2 0 R'); + + if (isset($this->PageLinks[$n])) { + // Links + $annots = '/Annots ['; + + foreach ($this->PageLinks[$n] as $pl) { + $rect = sprintf('%.2f %.2f %.2f %.2f', $pl[0], $pl[1], $pl[0] + $pl[2], $pl[1] - $pl[3]); + $annots .= '<</Type /Annot /Subtype /Link /Rect [' . $rect . '] /Border [0 0 0] '; + + if (is_string($pl[4])) { + $annots .= '/A <</S /URI /URI ' . $this->_textstring($pl[4]) . '>>>>'; + } else { + $l = $this->links[$pl[4]]; + $h = isset($this->OrientationChanges[$l[0]]) ? $wPt : $hPt; + $annots .= sprintf('/Dest [%d 0 R /XYZ 0 %.2f null]>>', 1 + 2 * $l[0], $h - $l[1] * $this->k); + } + } + + $this->_out($annots . ']'); + } + + $this->_out('/Contents ' . ($this->n + 1) . ' 0 R>>'); + $this->_out('endobj'); + // Page content + $p = ($this->compress) ? gzcompress($this->pages[$n]) : $this->pages[$n]; + $this->_newobj(); + $this->_out('<<' . $filter . '/Length ' . strlen($p) . '>>'); + $this->_putstream($p); + $this->_out('endobj'); + } + // Pages root + $this->offsets[1] = strlen($this->buffer); + $this->_out('1 0 obj'); + $this->_out('<</Type /Pages'); + $kids = '/Kids ['; + for ($i = 0; $i < $nb; $i++) { + $kids .= (3 + 2 * $i) . ' 0 R '; + } + $this->_out($kids . ']'); + $this->_out('/Count ' . $nb); + $this->_out(sprintf('/MediaBox [0 0 %.2f %.2f]', $wPt, $hPt)); + $this->_out('>>'); + $this->_out('endobj'); + } + + function _putfonts() + { + $nf = $this->n; + + foreach ($this->diffs as $diff) { + // Encodings + $this->_newobj(); + $this->_out('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences [' . $diff . ']>>'); + $this->_out('endobj'); + } + + $mqr = get_magic_quotes_runtime(); + set_magic_quotes_runtime(0); + + foreach ($this->FontFiles as $file => $info) { + // Font file embedding + $this->_newobj(); + $this->FontFiles[$file]['n'] = $this->n; + + if (defined('FPDF_FONTPATH')) { + $file = FPDF_FONTPATH . $file; + } + + $size = filesize($file); + + if (!$size) { + $this->Error('Font file not found'); + } + + $this->_out('<</Length ' . $size); + + if (substr($file, -2) == '.z') { + $this->_out('/Filter /FlateDecode'); + } + + $this->_out('/Length1 ' . $info['length1']); + + if (isset($info['length2'])) { + $this->_out('/Length2 ' . $info['length2'] . ' /Length3 0'); + } + + $this->_out('>>'); + $f = fopen($file, 'rb'); + $this->_putstream(fread($f, $size)); + fclose($f); + $this->_out('endobj'); + } + + set_magic_quotes_runtime($mqr); + + foreach ($this->fonts as $k => $font) { + // Font objects + $this->fonts[$k]['n'] = $this->n + 1; + $type = $font['type']; + $name = $font['name']; + + if ($type == 'core') { + // Standard font + $this->_newobj(); + $this->_out('<</Type /Font'); + $this->_out('/BaseFont /' . $name); + $this->_out('/Subtype /Type1'); + + if ($name != 'Symbol' and $name != 'ZapfDingbats') { + $this->_out('/Encoding /WinAnsiEncoding'); + } + + $this->_out('>>'); + $this->_out('endobj'); + } elseif ($type == 'Type1' or $type == 'TrueType') { + // Additional Type1 or TrueType font + $this->_newobj(); + $this->_out('<</Type /Font'); + $this->_out('/BaseFont /' . $name); + $this->_out('/Subtype /' . $type); + $this->_out('/FirstChar 32 /LastChar 255'); + $this->_out('/Widths ' . ($this->n + 1) . ' 0 R'); + $this->_out('/FontDescriptor ' . ($this->n + 2) . ' 0 R'); + + if ($font['enc']) { + if (isset($font['diff'])) { + $this->_out('/Encoding ' . ($nf + $font['diff']) . ' 0 R'); + } else { + $this->_out('/Encoding /WinAnsiEncoding'); + } + } + + $this->_out('>>'); + $this->_out('endobj'); + // Widths + $this->_newobj(); + $cw = &$font['cw']; + $s = '['; + + for ($i = 32; $i <= 255; $i++) { + $s .= $cw[chr($i)] . ' '; + } + + $this->_out($s . ']'); + $this->_out('endobj'); + // Descriptor + $this->_newobj(); + $s = '<</Type /FontDescriptor /FontName /' . $name; + + foreach ($font['desc'] as $k => $v) { + $s .= ' /' . $k . ' ' . $v; + } + + $file = $font['file']; + + if ($file) { + $s .= ' /FontFile' . ($type == 'Type1' ? '' : '2') . ' ' . $this->FontFiles[$file]['n'] . ' 0 R'; + } + + $this->_out($s . '>>'); + $this->_out('endobj'); + } else { + // Allow for additional types + $mtd = '_put' . strtolower($type); + + if (!method_exists($this, $mtd)) { + $this->Error('Unsupported font type: ' . $type); + } + + $this->$mtd($font); + } + } + } + + function _putimages() + { + $filter = ($this->compress) ? '/Filter /FlateDecode ' : ''; + reset($this->images); + + while (list($file, $info) = each($this->images)) { + $this->_newobj(); + $this->images[$file]['n'] = $this->n; + $this->_out('<</Type /XObject'); + $this->_out('/Subtype /Image'); + $this->_out('/Width ' . $info['w']); + $this->_out('/Height ' . $info['h']); + + if ($info['cs'] == 'Indexed') { + $this->_out('/ColorSpace [/Indexed /DeviceRGB ' . (strlen($info['pal']) / 3-1) . ' ' . ($this->n + 1) . ' 0 R]'); + } else { + $this->_out('/ColorSpace /' . $info['cs']); + if ($info['cs'] == 'DeviceCMYK') { + $this->_out('/Decode [1 0 1 0 1 0 1 0]'); + } + } + + $this->_out('/BitsPerComponent ' . $info['bpc']); + $this->_out('/Filter /' . $info['f']); + + if (isset($info['parms'])) { + $this->_out($info['parms']); + } + + if (isset($info['trns']) and is_array($info['trns'])) { + $trns = ''; + for ($i = 0; $i < count($info['trns']); $i++) { + $trns .= $info['trns'][$i] . ' ' . $info['trns'][$i] . ' '; + } + $this->_out('/Mask [' . $trns . ']'); + } + + $this->_out('/Length ' . strlen($info['data']) . '>>'); + $this->_putstream($info['data']); + unset($this->images[$file]['data']); + $this->_out('endobj'); + // Palette + if ($info['cs'] == 'Indexed') { + $this->_newobj(); + $pal = ($this->compress) ? gzcompress($info['pal']) : $info['pal']; + $this->_out('<<' . $filter . '/Length ' . strlen($pal) . '>>'); + $this->_putstream($pal); + $this->_out('endobj'); + } + } + } + + function _putresources() + { + $this->_putfonts(); + $this->_putimages(); + // Resource dictionary + $this->offsets[2] = strlen($this->buffer); + $this->_out('2 0 obj'); + $this->_out('<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]'); + $this->_out('/Font <<'); + + foreach ($this->fonts as $font) { + $this->_out('/F' . $font['i'] . ' ' . $font['n'] . ' 0 R'); + } + $this->_out('>>'); + if (count($this->images)) { + $this->_out('/XObject <<'); + foreach ($this->images as $image) { + $this->_out('/I' . $image['i'] . ' ' . $image['n'] . ' 0 R'); + } + $this->_out('>>'); + } + $this->_out('>>'); + $this->_out('endobj'); + } + + function _putinfo() + { + $this->_out('/Producer ' . $this->_textstring('FPDF ' . FPDF_VERSION)); + + if (!empty($this->title)) { + $this->_out('/Title ' . $this->_textstring($this->title)); + } + + if (!empty($this->subject)) { + $this->_out('/Subject ' . $this->_textstring($this->subject)); + } + + if (!empty($this->author)) { + $this->_out('/Author ' . $this->_textstring($this->author)); + } + + if (!empty($this->keywords)) { + $this->_out('/Keywords ' . $this->_textstring($this->keywords)); + } + + if (!empty($this->creator)) { + $this->_out('/Creator ' . $this->_textstring($this->creator)); + } + + $this->_out('/CreationDate ' . $this->_textstring('D:' . date('YmdHis'))); + } + + function _putcatalog() + { + $this->_out('/Type /Catalog'); + $this->_out('/Pages 1 0 R'); + + if ($this->ZoomMode == 'fullpage') { + $this->_out('/OpenAction [3 0 R /Fit]'); + } elseif ($this->ZoomMode == 'fullwidth') { + $this->_out('/OpenAction [3 0 R /FitH null]'); + } elseif ($this->ZoomMode == 'real') { + $this->_out('/OpenAction [3 0 R /XYZ null null 1]'); + } elseif (!is_string($this->ZoomMode)) { + $this->_out('/OpenAction [3 0 R /XYZ null null ' . ($this->ZoomMode / 100) . ']'); + } + if ($this->LayoutMode == 'single') { + $this->_out('/PageLayout /SinglePage'); + } elseif ($this->LayoutMode == 'continuous') { + $this->_out('/PageLayout /OneColumn'); + } elseif ($this->LayoutMode == 'two') { + $this->_out('/PageLayout /TwoColumnLeft'); + } + } + + function _puttrailer() + { + $this->_out('/Size ' . ($this->n + 1)); + $this->_out('/Root ' . $this->n . ' 0 R'); + $this->_out('/Info ' . ($this->n-1) . ' 0 R'); + } + + function _enddoc() + { + $this->_putpages(); + $this->_putresources(); + // Info + $this->_newobj(); + $this->_out('<<'); + $this->_putinfo(); + $this->_out('>>'); + $this->_out('endobj'); + // Catalog + $this->_newobj(); + $this->_out('<<'); + $this->_putcatalog(); + $this->_out('>>'); + $this->_out('endobj'); + // Cross-ref + $o = strlen($this->buffer); + $this->_out('xref'); + $this->_out('0 ' . ($this->n + 1)); + $this->_out('0000000000 65535 f '); + for ($i = 1; $i <= $this->n; $i++) { + $this->_out(sprintf('%010d 00000 n ', $this->offsets[$i])); + } + // Trailer + $this->_out('trailer'); + $this->_out('<<'); + $this->_puttrailer(); + $this->_out('>>'); + $this->_out('startxref'); + $this->_out($o); + $this->_out('%%EOF'); + $this->state = 3; + } + + function _beginpage($orientation) + { + $this->page++; + $this->pages[$this->page] = ''; + $this->state = 2; + $this->x = $this->lMargin; + $this->y = $this->tMargin; + $this->FontFamily = ''; + // Page orientation + if (!$orientation) { + $orientation = $this->DefOrientation; + } else { + $orientation = strtoupper($orientation{0}); + if ($orientation != $this->DefOrientation) { + $this->OrientationChanges[$this->page] = true; + } + } + + if ($orientation != $this->CurOrientation) { + // Change orientation + if ($orientation == 'P') { + $this->wPt = $this->fwPt; + $this->hPt = $this->fhPt; + $this->w = $this->fw; + $this->h = $this->fh; + } else { + $this->wPt = $this->fhPt; + $this->hPt = $this->fwPt; + $this->w = $this->fh; + $this->h = $this->fw; + } + + $this->PageBreakTrigger = $this->h - $this->bMargin; + $this->CurOrientation = $orientation; + } + } + + function _endpage() + { + // End of page contents + $this->state = 1; + } + + function _newobj() + { + // Begin a new object + $this->n++; + $this->offsets[$this->n] = strlen($this->buffer); + $this->_out($this->n . ' 0 obj'); + } + + function _dounderline($x, $y, $txt) + { + // Underline text + $up = $this->CurrentFont['up']; + $ut = $this->CurrentFont['ut']; + $w = $this->GetStringWidth($txt) + $this->ws * substr_count($txt, ' '); + return sprintf('%.2f %.2f %.2f %.2f re f', $x * $this->k, ($this->h - ($y - $up / 1000 * $this->FontSize)) * $this->k, $w * $this->k, - $ut / 1000 * $this->FontSizePt); + } + + function _parsejpg($file) + { + // Extract info from a JPEG file + $a = GetImageSize($file); + + if (!$a) { + $this->Error('Missing or incorrect image file: ' . $file); + } + + if ($a[2] != 2) { + $this->Error('Not a JPEG file: ' . $file); + } + + if (!isset($a['channels']) or $a['channels'] == 3) { + $colspace = 'DeviceRGB'; + } elseif ($a['channels'] == 4) { + $colspace = 'DeviceCMYK'; + } else { + $colspace = 'DeviceGray'; + } + + $bpc = isset($a['bits']) ? $a['bits'] : 8; + // Read whole file + $f = fopen($file, 'rb'); + $data = ''; + + while (!feof($f)) { + $data .= fread($f, 4096); + } + + fclose($f); + + return array('w' => $a[0], 'h' => $a[1], 'cs' => $colspace, 'bpc' => $bpc, 'f' => 'DCTDecode', 'data' => $data); + } + + function _parsepng($file) + { + // Extract info from a PNG file + $f = fopen($file, 'rb'); + + if (!$f) { + $this->Error('Can\'t open image file: ' . $file); + } + // Check signature + if (fread($f, 8) != chr(137) . 'PNG' . chr(13) . chr(10) . chr(26) . chr(10)) { + $this->Error('Not a PNG file: ' . $file); + } + // Read header chunk + fread($f, 4); + + if (fread($f, 4) != 'IHDR') { + $this->Error('Incorrect PNG file: ' . $file); + } + + $w = $this->_freadint($f); + $h = $this->_freadint($f); + $bpc = ord(fread($f, 1)); + + if ($bpc > 8) { + $this->Error('16-bit depth not supported: ' . $file); + } + + $ct = ord(fread($f, 1)); + + if ($ct == 0) { + $colspace = 'DeviceGray'; + } elseif ($ct == 2) { + $colspace = 'DeviceRGB'; + } elseif ($ct == 3) { + $colspace = 'Indexed'; + } else { + $this->Error('Alpha channel not supported: ' . $file); + } + + if (ord(fread($f, 1)) != 0) { + $this->Error('Unknown compression method: ' . $file); + } + + if (ord(fread($f, 1)) != 0) { + $this->Error('Unknown filter method: ' . $file); + } + + if (ord(fread($f, 1)) != 0) { + $this->Error('Interlacing not supported: ' . $file); + } + + fread($f, 4); + $parms = '/DecodeParms <</Predictor 15 /Colors ' . ($ct == 2 ? 3 : 1) . ' /BitsPerComponent ' . $bpc . ' /Columns ' . $w . '>>'; + // Scan chunks looking for palette, transparency and image data + $pal = ''; + $trns = ''; + $data = ''; + + do { + $n = $this->_freadint($f); + $type = fread($f, 4); + if ($type == 'PLTE') { + // Read palette + $pal = fread($f, $n); + fread($f, 4); + } elseif ($type == 'tRNS') { + // Read transparency info + $t = fread($f, $n); + if ($ct == 0) { + $trns = array(ord(substr($t, 1, 1))); + } elseif ($ct == 2) { + $trns = array(ord(substr($t, 1, 1)), ord(substr($t, 3, 1)), ord(substr($t, 5, 1))); + } else { + $pos = strpos($t, chr(0)); + if (is_int($pos)) { + $trns = array($pos); + } + } + fread($f, 4); + } elseif ($type == 'IDAT') { + // Read image data block + $data .= fread($f, $n); + fread($f, 4); + } elseif ($type == 'IEND') { + break; + } else { + fread($f, $n + 4); + } + } while ($n); { + if ($colspace == 'Indexed' and empty($pal)) { + $this->Error('Missing palette in ' . $file); + } + } + + fclose($f); + return array('w' => $w, 'h' => $h, 'cs' => $colspace, 'bpc' => $bpc, 'f' => 'FlateDecode', 'parms' => $parms, 'pal' => $pal, 'trns' => $trns, 'data' => $data); + } + + function _freadint($f) + { + // Read a 4-byte integer from file + $i = ord(fread($f, 1)) << 24; + $i += ord(fread($f, 1)) << 16; + $i += ord(fread($f, 1)) << 8; + $i += ord(fread($f, 1)); + return $i; + } + + function _textstring($s) + { + // Format a text string + return '(' . $this->_escape($s) . ')'; + } + + function _escape($s) + { + // Add \ before \, ( and ) + return str_replace(')', '\\)', str_replace('(', '\\(', str_replace('\\', '\\\\', $s))); + } + + function _putstream($s) + { + $this->_out('stream'); + $this->_out($s); + $this->_out('endstream'); + } + + function _out($s) + { + // Add a line to the document + if ($this->state == 2) { + $this->pages[$this->page] .= $s . "\n"; + } else { + $this->buffer .= $s . "\n"; + } + } + // End of class + } + // Handle special IE contype request + // lem9 + // if (isset($HTTP_SERVER_VARS['HTTP_USER_AGENT']) and $HTTP_SERVER_VARS['HTTP_USER_AGENT']=='contype') + if (isset($_SERVER['HTTP_USER_AGENT']) and $_SERVER['HTTP_USER_AGENT'] == 'contype') { + Header('Content-Type: application/pdf'); + exit; + } +} + ?> diff --git a/libraries/fpdf/ufpdf.php b/libraries/fpdf/ufpdf.php index a6fff165eb..d012204097 100644 --- a/libraries/fpdf/ufpdf.php +++ b/libraries/fpdf/ufpdf.php @@ -1,483 +1,592 @@ <?php -/******************************************************************************* -* Software: UFPDF, Unicode Free PDF generator * -* Version: 0.1 * -* based on FPDF 1.52 by Olivier PLATHEY * -* Date: 2004-09-01 * -* Author: Steven Wittens <steven@acko.net> * -* License: GPL * -* * -* UFPDF is a modification of FPDF to support Unicode through UTF-8. * -* * -*******************************************************************************/ - -if(!class_exists('UFPDF')) -{ -define('UFPDF_VERSION','0.1'); - -include_once './libraries/fpdf/fpdf.php'; - -class UFPDF extends FPDF -{ - -/******************************************************************************* -* * -* Public methods * -* * -*******************************************************************************/ -function UFPDF($orientation='P',$unit='mm',$format='A4') -{ - FPDF::FPDF($orientation, $unit, $format); -} - -function GetStringWidth($s) -{ - //Get width of a string in the current font - $s = (string)$s; - $codepoints=$this->utf8_to_codepoints($s); - $cw=&$this->CurrentFont['cw']; - $w=0; - foreach($codepoints as $cp) - $w+=isset($cw[$cp])?$cw[$cp]:0; - return $w*$this->FontSize/1000; -} - -function AddFont($family,$style='',$file='') -{ - //Add a TrueType or Type1 font - $family=strtolower($family); - if($family=='arial') - $family='helvetica'; - $style=strtoupper($style); - if($style=='IB') - $style='BI'; - if(isset($this->fonts[$family.$style])) - $this->Error('Font already added: '.$family.' '.$style); - if($file=='') - $file=str_replace(' ','',$family).strtolower($style).'.php'; - if(defined('FPDF_FONTPATH')) - $file=FPDF_FONTPATH.$file; - include($file); - if(!isset($name)) - $this->Error('Could not include font definition file'); - $i=count($this->fonts)+1; - $this->fonts[$family.$style]=array('i'=>$i,'type'=>$type,'name'=>$name,'desc'=>$desc,'up'=>$up,'ut'=>$ut,'cw'=>$cw,'file'=>$file,'ctg'=>$ctg); - if($file) - { - if($type=='TrueTypeUnicode') - $this->FontFiles[$file]=array('length1'=>$originalsize); - else - $this->FontFiles[$file]=array('length1'=>$size1,'length2'=>$size2); - } -} - -function Text($x,$y,$txt) -{ - //Output a string - $s=sprintf('BT %.2f %.2f Td %s Tj ET',$x*$this->k,($this->h-$y)*$this->k,$this->_escapetext($txt)); - if($this->underline and $txt!='') - $s.=' '.$this->_dounderline($x,$y,$this->GetStringWidth($txt),$txt); - if($this->ColorFlag) - $s='q '.$this->TextColor.' '.$s.' Q'; - $this->_out($s); -} - -function AcceptPageBreak() -{ - //Accept automatic page break or not - return $this->AutoPageBreak; -} - -function Cell($w,$h=0,$txt='',$border=0,$ln=0,$align='',$fill=0,$link='') -{ - //Output a cell - $k=$this->k; - if($this->y+$h>$this->PageBreakTrigger and !$this->InFooter and $this->AcceptPageBreak()) - { - //Automatic page break - $x=$this->x; - $ws=$this->ws; - if($ws>0) - { - $this->ws=0; - $this->_out('0 Tw'); - } - $this->AddPage($this->CurOrientation); - $this->x=$x; - if($ws>0) - { - $this->ws=$ws; - $this->_out(sprintf('%.3f Tw',$ws*$k)); - } - } - if($w==0) - $w=$this->w-$this->rMargin-$this->x; - $s=''; - if($fill==1 or $border==1) - { - if($fill==1) - $op=($border==1) ? 'B' : 'f'; - else - $op='S'; - $s=sprintf('%.2f %.2f %.2f %.2f re %s ',$this->x*$k,($this->h-$this->y)*$k,$w*$k,-$h*$k,$op); - } - if(is_string($border)) - { - $x=$this->x; - $y=$this->y; - if(is_int(strpos($border,'L'))) - $s.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-$y)*$k,$x*$k,($this->h-($y+$h))*$k); - if(is_int(strpos($border,'T'))) - $s.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-$y)*$k); - if(is_int(strpos($border,'R'))) - $s.=sprintf('%.2f %.2f m %.2f %.2f l S ',($x+$w)*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-($y+$h))*$k); - if(is_int(strpos($border,'B'))) - $s.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-($y+$h))*$k,($x+$w)*$k,($this->h-($y+$h))*$k); - } - if($txt!='') - { - $width = $this->GetStringWidth($txt); - if($align=='R') - $dx=$w-$this->cMargin-$width; - elseif($align=='C') - $dx=($w-$width)/2; - else - $dx=$this->cMargin; - if($this->ColorFlag) - $s.='q '.$this->TextColor.' '; - $txtstring=$this->_escapetext($txt); - $s.=sprintf('BT %.2f %.2f Td %s Tj ET',($this->x+$dx)*$k,($this->h-($this->y+.5*$h+.3*$this->FontSize))*$k,$txtstring); - if($this->underline) - $s.=' '.$this->_dounderline($this->x+$dx,$this->y+.5*$h+.3*$this->FontSize,$width,$txt); - if($this->ColorFlag) - $s.=' Q'; - if($link) - $this->Link($this->x+$dx,$this->y+.5*$h-.5*$this->FontSize,$width,$this->FontSize,$link); - } - if($s) - $this->_out($s); - $this->lasth=$h; - if($ln>0) - { - //Go to next line - $this->y+=$h; - if($ln==1) - $this->x=$this->lMargin; - } - else - $this->x+=$w; -} - -/******************************************************************************* -* * -* Protected methods * -* * -*******************************************************************************/ - -function _puttruetypeunicode($font) { - //Type0 Font - $this->_newobj(); - $this->_out('<</Type /Font'); - $this->_out('/Subtype /Type0'); - $this->_out('/BaseFont /'. $font['name'] .'-UCS'); - $this->_out('/Encoding /Identity-H'); - $this->_out('/DescendantFonts ['. ($this->n + 1) .' 0 R]'); - $this->_out('>>'); - $this->_out('endobj'); - - //CIDFont - $this->_newobj(); - $this->_out('<</Type /Font'); - $this->_out('/Subtype /CIDFontType2'); - $this->_out('/BaseFont /'. $font['name']); - $this->_out('/CIDSystemInfo <</Registry (Adobe) /Ordering (UCS) /Supplement 0>>'); - $this->_out('/FontDescriptor '. ($this->n + 1) .' 0 R'); - $c = 0; - $widths = ''; - foreach ($font['cw'] as $i => $w) { - $widths .= $i .' ['. $w.'] '; - } - $this->_out('/W ['. $widths .']'); - $this->_out('/CIDToGIDMap '. ($this->n + 2) .' 0 R'); - $this->_out('>>'); - $this->_out('endobj'); - - //Font descriptor - $this->_newobj(); - $this->_out('<</Type /FontDescriptor'); - $this->_out('/FontName /'.$font['name']); - $s = ''; - foreach ($font['desc'] as $k => $v) { - $s .= ' /'. $k .' '. $v; - } - if ($font['file']) { - $s .= ' /FontFile2 '. $this->FontFiles[$font['file']]['n'] .' 0 R'; - } - $this->_out($s); - $this->_out('>>'); - $this->_out('endobj'); - - //Embed CIDToGIDMap - $this->_newobj(); - if(defined('FPDF_FONTPATH')) - $file=FPDF_FONTPATH.$font['ctg']; - else - $file=$font['ctg']; - $size=filesize($file); - if(!$size) - $this->Error('Font file not found'); - $this->_out('<</Length '.$size); - if(substr($file,-2) == '.z') - $this->_out('/Filter /FlateDecode'); - $this->_out('>>'); - $f = fopen($file,'rb'); - $this->_putstream(fread($f,$size)); - fclose($f); - $this->_out('endobj'); -} - -function _dounderline($x,$y,$width,$txt) -{ - //Underline text - $up=$this->CurrentFont['up']; - $ut=$this->CurrentFont['ut']; - $w=$width+$this->ws*substr_count($txt,' '); - return sprintf('%.2f %.2f %.2f %.2f re f',$x*$this->k,($this->h-($y-$up/1000*$this->FontSize))*$this->k,$w*$this->k,-$ut/1000*$this->FontSizePt); -} - -function _textstring($s) -{ - //Convert to UTF-16BE - $s = $this->utf8_to_utf16be($s); - //Escape necessary characters - return '('. strtr($s, array(')' => '\\)', '(' => '\\(', '\\' => '\\\\')) .')'; -} - -function _strreplace($what, $to, $where) { - $to = '' . $to; - return str_replace($this->utf8_to_utf16be($what, false), $this->utf8_to_utf16be($to, false), $where); -} - -function _escapetext($s) -{ - //Convert to UTF-16BE - $s = $this->utf8_to_utf16be($s, false); - //Escape necessary characters - return '('. strtr($s, array(')' => '\\)', '(' => '\\(', '\\' => '\\\\')) .')'; -} - -function _putinfo() -{ - $this->_out('/Producer '.$this->_textstring('UFPDF '. UFPDF_VERSION)); - if(!empty($this->title)) - $this->_out('/Title '.$this->_textstring($this->title)); - if(!empty($this->subject)) - $this->_out('/Subject '.$this->_textstring($this->subject)); - if(!empty($this->author)) - $this->_out('/Author '.$this->_textstring($this->author)); - if(!empty($this->keywords)) - $this->_out('/Keywords '.$this->_textstring($this->keywords)); - if(!empty($this->creator)) - $this->_out('/Creator '.$this->_textstring($this->creator)); - $this->_out('/CreationDate '.$this->_textstring('D:'.date('YmdHis'))); -} - -// UTF-8 to UTF-16BE conversion. -// Correctly handles all illegal UTF-8 sequences. -function utf8_to_utf16be(&$txt, $bom = true) { - $l = strlen($txt); - $out = $bom ? "\xFE\xFF" : ''; - for ($i = 0; $i < $l; ++$i) { - $c = ord($txt{$i}); - // ASCII - if ($c < 0x80) { - $out .= "\x00". $txt{$i}; - } - // Lost continuation byte - else if ($c < 0xC0) { - $out .= "\xFF\xFD"; - continue; - } - // Multibyte sequence leading byte - else { - if ($c < 0xE0) { - $s = 2; - } - else if ($c < 0xF0) { - $s = 3; - } - else if ($c < 0xF8) { - $s = 4; - } - // 5/6 byte sequences not possible for Unicode. - else { - $out .= "\xFF\xFD"; - while (ord($txt{$i + 1}) >= 0x80 && ord($txt{$i + 1}) < 0xC0) { ++$i; } - continue; - } - - $q = array($c); - // Fetch rest of sequence - $l = strlen($txt); - while ($i + 1 < $l && ord($txt{$i + 1}) >= 0x80 && ord($txt{$i + 1}) < 0xC0) { ++$i; $q[] = ord($txt{$i}); } - - // Check length - if (count($q) != $s) { - $out .= "\xFF\xFD"; - continue; - } - - switch ($s) { - case 2: - $cp = (($q[0] ^ 0xC0) << 6) | ($q[1] ^ 0x80); - // Overlong sequence - if ($cp < 0x80) { - $out .= "\xFF\xFD"; - } - else { - $out .= chr($cp >> 8); - $out .= chr($cp & 0xFF); - } - continue; - - case 3: - $cp = (($q[0] ^ 0xE0) << 12) | (($q[1] ^ 0x80) << 6) | ($q[2] ^ 0x80); - // Overlong sequence - if ($cp < 0x800) { - $out .= "\xFF\xFD"; - } - // Check for UTF-8 encoded surrogates (caused by a bad UTF-8 encoder) - else if ($c > 0xD800 && $c < 0xDFFF) { - $out .= "\xFF\xFD"; - } - else { - $out .= chr($cp >> 8); - $out .= chr($cp & 0xFF); - } - continue; - - case 4: - $cp = (($q[0] ^ 0xF0) << 18) | (($q[1] ^ 0x80) << 12) | (($q[2] ^ 0x80) << 6) | ($q[3] ^ 0x80); - // Overlong sequence - if ($cp < 0x10000) { - $out .= "\xFF\xFD"; - } - // Outside of the Unicode range - else if ($cp >= 0x10FFFF) { - $out .= "\xFF\xFD"; - } - else { - // Use surrogates - $cp -= 0x10000; - $s1 = 0xD800 | ($cp >> 10); - $s2 = 0xDC00 | ($cp & 0x3FF); - - $out .= chr($s1 >> 8); - $out .= chr($s1 & 0xFF); - $out .= chr($s2 >> 8); - $out .= chr($s2 & 0xFF); - } - continue; - } - } - } - return $out; -} - -// UTF-8 to codepoint array conversion. -// Correctly handles all illegal UTF-8 sequences. -function utf8_to_codepoints(&$txt) { - $l = strlen($txt); - $out = array(); - for ($i = 0; $i < $l; ++$i) { - $c = ord($txt{$i}); - // ASCII - if ($c < 0x80) { - $out[] = ord($txt{$i}); - } - // Lost continuation byte - else if ($c < 0xC0) { - $out[] = 0xFFFD; - continue; - } - // Multibyte sequence leading byte - else { - if ($c < 0xE0) { - $s = 2; - } - else if ($c < 0xF0) { - $s = 3; - } - else if ($c < 0xF8) { - $s = 4; - } - // 5/6 byte sequences not possible for Unicode. - else { - $out[] = 0xFFFD; - while (ord($txt{$i + 1}) >= 0x80 && ord($txt{$i + 1}) < 0xC0) { ++$i; } - continue; - } - - $q = array($c); - // Fetch rest of sequence - $l = strlen($txt); - while ($i + 1 < $l && ord($txt{$i + 1}) >= 0x80 && ord($txt{$i + 1}) < 0xC0) { ++$i; $q[] = ord($txt{$i}); } - - // Check length - if (count($q) != $s) { - $out[] = 0xFFFD; - continue; - } - - switch ($s) { - case 2: - $cp = (($q[0] ^ 0xC0) << 6) | ($q[1] ^ 0x80); - // Overlong sequence - if ($cp < 0x80) { - $out[] = 0xFFFD; - } - else { - $out[] = $cp; - } - continue; - - case 3: - $cp = (($q[0] ^ 0xE0) << 12) | (($q[1] ^ 0x80) << 6) | ($q[2] ^ 0x80); - // Overlong sequence - if ($cp < 0x800) { - $out[] = 0xFFFD; - } - // Check for UTF-8 encoded surrogates (caused by a bad UTF-8 encoder) - else if ($c > 0xD800 && $c < 0xDFFF) { - $out[] = 0xFFFD; - } - else { - $out[] = $cp; - } - continue; - - case 4: - $cp = (($q[0] ^ 0xF0) << 18) | (($q[1] ^ 0x80) << 12) | (($q[2] ^ 0x80) << 6) | ($q[3] ^ 0x80); - // Overlong sequence - if ($cp < 0x10000) { - $out[] = 0xFFFD; - } - // Outside of the Unicode range - else if ($cp >= 0x10FFFF) { - $out[] = 0xFFFD; - } - else { - $out[] = $cp; - } - continue; - } - } - } - return $out; -} - -//End of class -} - -} + +/** + * Software: UFPDF, Unicode Free PDF generator * + * + * Version: 0.1 * + * + * based on FPDF 1.52 by Olivier PLATHEY * + * + * Date: 2004-09-01 * + * + * Author: Steven Wittens <steven@acko.net> * + * + * License: GPL * + * + * + * + * UFPDF is a modification of FPDF to support Unicode through UTF-8. * + */ + +if (!class_exists('UFPDF')) { + define('UFPDF_VERSION', '0.1'); + + include_once './libraries/fpdf/fpdf.php'; + + class UFPDF extends FPDF { + /** + * Public methods * + */ + + function UFPDF($orientation = 'P', $unit = 'mm', $format = 'A4') + { + FPDF::FPDF($orientation, $unit, $format); + } + + function GetStringWidth($s) + { + // Get width of a string in the current font + $s = (string)$s; + $codepoints = $this->utf8_to_codepoints($s); + $cw = &$this->CurrentFont['cw']; + $w = 0; + + foreach ($codepoints as $cp) { + $w += isset($cw[$cp])?$cw[$cp]:0; + } + + return $w * $this->FontSize / 1000; + } + + function AddFont($family, $style = '', $file = '') + { + // Add a TrueType or Type1 font + $family = strtolower($family); + + if ($family == 'arial') { + $family = 'helvetica'; + } + + $style = strtoupper($style); + + if ($style == 'IB') { + $style = 'BI'; + } + + if (isset($this->fonts[$family . $style])) { + $this->Error('Font already added: ' . $family . ' ' . $style); + } + + if ($file == '') { + $file = str_replace(' ', '', $family) . strtolower($style) . '.php'; + } + + if (defined('FPDF_FONTPATH')) { + $file = FPDF_FONTPATH . $file; + } + + include($file); + + if (!isset($name)) { + $this->Error('Could not include font definition file'); + } + + $i = count($this->fonts) + 1; + $this->fonts[$family . $style] = array('i' => $i, 'type' => $type, 'name' => $name, 'desc' => $desc, 'up' => $up, 'ut' => $ut, 'cw' => $cw, 'file' => $file, 'ctg' => $ctg); + + if ($file) { + if ($type == 'TrueTypeUnicode') { + $this->FontFiles[$file] = array('length1' => $originalsize); + } else { + $this->FontFiles[$file] = array('length1' => $size1, 'length2' => $size2); + } + } + } + + function Text($x, $y, $txt) + { + // Output a string + $s = sprintf('BT %.2f %.2f Td %s Tj ET', $x * $this->k, ($this->h - $y) * $this->k, $this->_escapetext($txt)); + + if ($this->underline and $txt != '') { + $s .= ' ' . $this->_dounderline($x, $y, $this->GetStringWidth($txt), $txt); + } + + if ($this->ColorFlag) { + $s = 'q ' . $this->TextColor . ' ' . $s . ' Q'; + } + + $this->_out($s); + } + + function AcceptPageBreak() + { + // Accept automatic page break or not + return $this->AutoPageBreak; + } + + function Cell($w, $h = 0, $txt = '', $border = 0, $ln = 0, $align = '', $fill = 0, $link = '') + { + // Output a cell + $k = $this->k; + + if ($this->y + $h > $this->PageBreakTrigger and !$this->InFooter and $this->AcceptPageBreak()) { + // Automatic page break + $x = $this->x; + $ws = $this->ws; + + if ($ws > 0) { + $this->ws = 0; + $this->_out('0 Tw'); + } + + $this->AddPage($this->CurOrientation); + $this->x = $x; + + if ($ws > 0) { + $this->ws = $ws; + $this->_out(sprintf('%.3f Tw', $ws * $k)); + } + } + + if ($w == 0) { + $w = $this->w - $this->rMargin - $this->x; + } + + $s = ''; + + if ($fill == 1 or $border == 1) { + if ($fill == 1) { + $op = ($border == 1) ? 'B' : 'f'; + } else { + $op = 'S'; + } + + $s = sprintf('%.2f %.2f %.2f %.2f re %s ', $this->x * $k, ($this->h - $this->y) * $k, $w * $k, - $h * $k, $op); + } + + if (is_string($border)) { + $x = $this->x; + $y = $this->y; + + if (is_int(strpos($border, 'L'))) { + $s .= sprintf('%.2f %.2f m %.2f %.2f l S ', $x * $k, ($this->h - $y) * $k, $x * $k, ($this->h - ($y + $h)) * $k); + } + + if (is_int(strpos($border, 'T'))) { + $s .= sprintf('%.2f %.2f m %.2f %.2f l S ', $x * $k, ($this->h - $y) * $k, ($x + $w) * $k, ($this->h - $y) * $k); + } + + if (is_int(strpos($border, 'R'))) { + $s .= sprintf('%.2f %.2f m %.2f %.2f l S ', ($x + $w) * $k, ($this->h - $y) * $k, ($x + $w) * $k, ($this->h - ($y + $h)) * $k); + } + + if (is_int(strpos($border, 'B'))) { + $s .= sprintf('%.2f %.2f m %.2f %.2f l S ', $x * $k, ($this->h - ($y + $h)) * $k, ($x + $w) * $k, ($this->h - ($y + $h)) * $k); + } + } + + if ($txt != '') { + $width = $this->GetStringWidth($txt); + + if ($align == 'R') { + $dx = $w - $this->cMargin - $width; + } elseif ($align == 'C') { + $dx = ($w - $width) / 2; + } else { + $dx = $this->cMargin; + } + + if ($this->ColorFlag) { + $s .= 'q ' . $this->TextColor . ' '; + } + + $txtstring = $this->_escapetext($txt); + $s .= sprintf('BT %.2f %.2f Td %s Tj ET', ($this->x + $dx) * $k, ($this->h - ($this->y + .5 * $h + .3 * $this->FontSize)) * $k, $txtstring); + + if ($this->underline) { + $s .= ' ' . $this->_dounderline($this->x + $dx, $this->y + .5 * $h + .3 * $this->FontSize, $width, $txt); + } + + if ($this->ColorFlag) { + $s .= ' Q'; + } + + if ($link) { + $this->Link($this->x + $dx, $this->y + .5 * $h - .5 * $this->FontSize, $width, $this->FontSize, $link); + } + } + + if ($s) { + $this->_out($s); + } + + $this->lasth = $h; + + if ($ln > 0) { + // Go to next line + $this->y += $h; + + if ($ln == 1) { + $this->x = $this->lMargin; + } + } else { + $this->x += $w; + } + } + + /** + * Protected methods * + */ + + function _puttruetypeunicode($font) + { + // Type0 Font + $this->_newobj(); + $this->_out('<</Type /Font'); + $this->_out('/Subtype /Type0'); + $this->_out('/BaseFont /' . $font['name'] . '-UCS'); + $this->_out('/Encoding /Identity-H'); + $this->_out('/DescendantFonts [' . ($this->n + 1) . ' 0 R]'); + $this->_out('>>'); + $this->_out('endobj'); + // CIDFont + $this->_newobj(); + $this->_out('<</Type /Font'); + $this->_out('/Subtype /CIDFontType2'); + $this->_out('/BaseFont /' . $font['name']); + $this->_out('/CIDSystemInfo <</Registry (Adobe) /Ordering (UCS) /Supplement 0>>'); + $this->_out('/FontDescriptor ' . ($this->n + 1) . ' 0 R'); + $c = 0; + $widths = ''; + + foreach ($font['cw'] as $i => $w) { + $widths .= $i . ' [' . $w . '] '; + } + + $this->_out('/W [' . $widths . ']'); + $this->_out('/CIDToGIDMap ' . ($this->n + 2) . ' 0 R'); + $this->_out('>>'); + $this->_out('endobj'); + // Font descriptor + $this->_newobj(); + $this->_out('<</Type /FontDescriptor'); + $this->_out('/FontName /' . $font['name']); + $s = ''; + + foreach ($font['desc'] as $k => $v) { + $s .= ' /' . $k . ' ' . $v; + } + + if ($font['file']) { + $s .= ' /FontFile2 ' . $this->FontFiles[$font['file']]['n'] . ' 0 R'; + } + + $this->_out($s); + $this->_out('>>'); + $this->_out('endobj'); + // Embed CIDToGIDMap + $this->_newobj(); + + if (defined('FPDF_FONTPATH')) { + $file = FPDF_FONTPATH . $font['ctg']; + } else { + $file = $font['ctg']; + } + + $size = filesize($file); + + if (!$size) { + $this->Error('Font file not found'); + } + + $this->_out('<</Length ' . $size); + + if (substr($file, -2) == '.z') { + $this->_out('/Filter /FlateDecode'); + } + + $this->_out('>>'); + $f = fopen($file, 'rb'); + $this->_putstream(fread($f, $size)); + fclose($f); + $this->_out('endobj'); + } + + function _dounderline($x, $y, $width, $txt) + { + // Underline text + $up = $this->CurrentFont['up']; + $ut = $this->CurrentFont['ut']; + $w = $width + $this->ws * substr_count($txt, ' '); + return sprintf('%.2f %.2f %.2f %.2f re f', $x * $this->k, ($this->h - ($y - $up / 1000 * $this->FontSize)) * $this->k, $w * $this->k, - $ut / 1000 * $this->FontSizePt); + } + + function _textstring($s) + { + // Convert to UTF-16BE + $s = $this->utf8_to_utf16be($s); + // Escape necessary characters + return '(' . strtr($s, array(')' => '\\)', '(' => '\\(', '\\' => '\\\\')) . ')'; + } + + function _strreplace($what, $to, $where) + { + $to = '' . $to; + return str_replace($this->utf8_to_utf16be($what, false), $this->utf8_to_utf16be($to, false), $where); + } + + function _escapetext($s) + { + // Convert to UTF-16BE + $s = $this->utf8_to_utf16be($s, false); + // Escape necessary characters + return '(' . strtr($s, array(')' => '\\)', '(' => '\\(', '\\' => '\\\\')) . ')'; + } + + function _putinfo() + { + $this->_out('/Producer ' . $this->_textstring('UFPDF ' . UFPDF_VERSION)); + + if (!empty($this->title)) { + $this->_out('/Title ' . $this->_textstring($this->title)); + } + + if (!empty($this->subject)) { + $this->_out('/Subject ' . $this->_textstring($this->subject)); + } + + if (!empty($this->author)) { + $this->_out('/Author ' . $this->_textstring($this->author)); + } + + if (!empty($this->keywords)) { + $this->_out('/Keywords ' . $this->_textstring($this->keywords)); + } + + if (!empty($this->creator)) { + $this->_out('/Creator ' . $this->_textstring($this->creator)); + } + + $this->_out('/CreationDate ' . $this->_textstring('D:' . date('YmdHis'))); + } + // UTF-8 to UTF-16BE conversion. + // Correctly handles all illegal UTF-8 sequences. + function utf8_to_utf16be(&$txt, $bom = true) + { + $l = strlen($txt); + $out = $bom ? "\xFE\xFF" : ''; + + for ($i = 0; $i < $l; ++$i) { + $c = ord($txt{$i}); + // ASCII + if ($c < 0x80) { + $out .= "\x00" . $txt{$i}; + } + // Lost continuation byte + elseif ($c < 0xC0) { + $out .= "\xFF\xFD"; + + continue; + } + // Multibyte sequence leading byte + else { + if ($c < 0xE0) { + $s = 2; + } elseif ($c < 0xF0) { + $s = 3; + } elseif ($c < 0xF8) { + $s = 4; + } + // 5/6 byte sequences not possible for Unicode. + else { + $out .= "\xFF\xFD"; + + while (ord($txt{$i + 1}) >= 0x80 && ord($txt{$i + 1}) < 0xC0) { + ++$i; + } + + continue; + } + + $q = array($c); + // Fetch rest of sequence + $l = strlen($txt); + + while ($i + 1 < $l && ord($txt{$i + 1}) >= 0x80 && ord($txt{$i + 1}) < 0xC0) { + ++$i; + $q[] = ord($txt{$i}); + } + // Check length + if (count($q) != $s) { + $out .= "\xFF\xFD"; + + continue; + } + + switch ($s) { + case 2: + + $cp = (($q[0] ^ 0xC0) << 6) | ($q[1] ^ 0x80); + // Overlong sequence + if ($cp < 0x80) { + $out .= "\xFF\xFD"; + } else { + $out .= chr($cp >> 8); + + $out .= chr($cp &0xFF); + } + + continue; + + case 3: + + $cp = (($q[0] ^ 0xE0) << 12) | (($q[1] ^ 0x80) << 6) | ($q[2] ^ 0x80); + // Overlong sequence + if ($cp < 0x800) { + $out .= "\xFF\xFD"; + } + // Check for UTF-8 encoded surrogates (caused by a bad UTF-8 encoder) + elseif ($c > 0xD800 && $c < 0xDFFF) { + $out .= "\xFF\xFD"; + } else { + $out .= chr($cp >> 8); + + $out .= chr($cp &0xFF); + } + + continue; + + case 4: + + $cp = (($q[0] ^ 0xF0) << 18) | (($q[1] ^ 0x80) << 12) | (($q[2] ^ 0x80) << 6) | ($q[3] ^ 0x80); + // Overlong sequence + if ($cp < 0x10000) { + $out .= "\xFF\xFD"; + } + // Outside of the Unicode range + elseif ($cp >= 0x10FFFF) { + $out .= "\xFF\xFD"; + } else { + // Use surrogates + $cp -= 0x10000; + + $s1 = 0xD800 | ($cp >> 10); + + $s2 = 0xDC00 | ($cp &0x3FF); + + $out .= chr($s1 >> 8); + + $out .= chr($s1 &0xFF); + + $out .= chr($s2 >> 8); + + $out .= chr($s2 &0xFF); + } + + continue; + } + } + } + + return $out; + } + // UTF-8 to codepoint array conversion. + // Correctly handles all illegal UTF-8 sequences. + function utf8_to_codepoints(&$txt) + { + $l = strlen($txt); + $out = array(); + + for ($i = 0; $i < $l; ++$i) { + $c = ord($txt{$i}); + // ASCII + if ($c < 0x80) { + $out[] = ord($txt{$i}); + } + // Lost continuation byte + elseif ($c < 0xC0) { + $out[] = 0xFFFD; + + continue; + } + // Multibyte sequence leading byte + else { + if ($c < 0xE0) { + $s = 2; + } elseif ($c < 0xF0) { + $s = 3; + } elseif ($c < 0xF8) { + $s = 4; + } + // 5/6 byte sequences not possible for Unicode. + else { + $out[] = 0xFFFD; + + while (ord($txt{$i + 1}) >= 0x80 && ord($txt{$i + 1}) < 0xC0) { + ++$i; + } + + continue; + } + + $q = array($c); + // Fetch rest of sequence + $l = strlen($txt); + + while ($i + 1 < $l && ord($txt{$i + 1}) >= 0x80 && ord($txt{$i + 1}) < 0xC0) { + ++$i; + $q[] = ord($txt{$i}); + } + // Check length + if (count($q) != $s) { + $out[] = 0xFFFD; + + continue; + } + + switch ($s) { + case 2: + + $cp = (($q[0] ^ 0xC0) << 6) | ($q[1] ^ 0x80); + // Overlong sequence + if ($cp < 0x80) { + $out[] = 0xFFFD; + } else { + $out[] = $cp; + } + + continue; + + case 3: + + $cp = (($q[0] ^ 0xE0) << 12) | (($q[1] ^ 0x80) << 6) | ($q[2] ^ 0x80); + // Overlong sequence + if ($cp < 0x800) { + $out[] = 0xFFFD; + } + // Check for UTF-8 encoded surrogates (caused by a bad UTF-8 encoder) + elseif ($c > 0xD800 && $c < 0xDFFF) { + $out[] = 0xFFFD; + } else { + $out[] = $cp; + } + + continue; + + case 4: + + $cp = (($q[0] ^ 0xF0) << 18) | (($q[1] ^ 0x80) << 12) | (($q[2] ^ 0x80) << 6) | ($q[3] ^ 0x80); + // Overlong sequence + if ($cp < 0x10000) { + $out[] = 0xFFFD; + } + // Outside of the Unicode range + elseif ($cp >= 0x10FFFF) { + $out[] = 0xFFFD; + } else { + $out[] = $cp; + } + + continue; + } + } + } + + return $out; + } + // End of class + } +} + ?> diff --git a/libraries/get_foreign.lib.php b/libraries/get_foreign.lib.php index 09ae74049f..c934e6e790 100644 --- a/libraries/get_foreign.lib.php +++ b/libraries/get_foreign.lib.php @@ -64,8 +64,7 @@ if ($foreigners && isset($foreigners[$field])) { } @PMA_DBI_free_result($disp); } - } - else { + } else { unset($disp_row); $foreign_link = true; } diff --git a/libraries/header.inc.php b/libraries/header.inc.php index 4a725bdaf5..1252f6759b 100644 --- a/libraries/header.inc.php +++ b/libraries/header.inc.php @@ -63,7 +63,7 @@ if (empty($GLOBALS['is_header_sent'])) { </script> <script src="./js/functions.js" type="text/javascript" language="javascript"></script> <?php - } else if (isset($js_to_run) && $js_to_run == 'user_password.js') { + } elseif (isset($js_to_run) && $js_to_run == 'user_password.js') { echo "\n"; ?> // js form validation stuff @@ -75,7 +75,7 @@ if (empty($GLOBALS['is_header_sent'])) { </script> <script src="./js/user_password.js" type="text/javascript" language="javascript"></script> <?php - } else if (isset($js_to_run) && $js_to_run == 'server_privileges.js') { + } elseif (isset($js_to_run) && $js_to_run == 'server_privileges.js') { echo "\n"; ?> // js form validation stuff @@ -88,7 +88,7 @@ if (empty($GLOBALS['is_header_sent'])) { <script src="./js/server_privileges.js" type="text/javascript" language="javascript"></script> <script src="./js/functions.js" type="text/javascript" language="javascript"></script> <?php - } else if (isset($js_to_run) && $js_to_run == 'indexes.js') { + } elseif (isset($js_to_run) && $js_to_run == 'indexes.js') { echo "\n"; ?> // js index validation stuff @@ -98,7 +98,7 @@ if (empty($GLOBALS['is_header_sent'])) { </script> <script src="./js/indexes.js" type="text/javascript" language="javascript"></script> <?php - } else if (isset($js_to_run) && $js_to_run == 'tbl_change.js') { + } elseif (isset($js_to_run) && $js_to_run == 'tbl_change.js') { echo "\n"; ?> //--> @@ -194,7 +194,7 @@ if (empty($GLOBALS['is_header_sent'])) { */ if (!empty($show_comment) && !isset($GLOBALS['avoid_show_comment'])) { if (strstr($show_comment, '; InnoDB free')) { - $show_comment = preg_replace('@; InnoDB free:.*?$@' , '', $show_comment); + $show_comment = preg_replace('@; InnoDB free:.*?$@', '', $show_comment); } echo '<span class="table_comment" id="span_table_comment">' .'"' . htmlspecialchars($show_comment) diff --git a/libraries/header_meta_style.inc.php b/libraries/header_meta_style.inc.php index a104a5998a..3e21282b52 100644 --- a/libraries/header_meta_style.inc.php +++ b/libraries/header_meta_style.inc.php @@ -28,10 +28,11 @@ echo "<?xml version=\"1.0\" encoding=\"" . $GLOBALS['charset'] . "\"?".">"; <link rel="icon" href="./favicon.ico" type="image/x-icon" /> <link rel="shortcut icon" href="./favicon.ico" type="image/x-icon" /> <title><?php - if(!empty($page_title)) + if (!empty($page_title)) { echo htmlspecialchars($page_title); - else + } else { echo 'phpMyAdmin'; + } ?></title> <meta http-equiv="Content-Type" content="text/html; charset=<?php echo $GLOBALS['charset']; ?>" /> <link rel="stylesheet" type="text/css" href="<?php echo defined('PMA_PATH_TO_BASEDIR') ? PMA_PATH_TO_BASEDIR : './'; ?>css/phpmyadmin.css.php?<?php echo PMA_generate_common_url(); ?>&js_frame=<?php echo isset($print_view) ? 'print' : 'right'; ?>" /> diff --git a/libraries/import.lib.php b/libraries/import.lib.php index 9d91dda812..61bcad686c 100644 --- a/libraries/import.lib.php +++ b/libraries/import.lib.php @@ -15,7 +15,8 @@ define('PMA_CHK_DROP', 1); * @return boolean true if timeout is close * @access public */ -function PMA_checkTimeout() { +function PMA_checkTimeout() +{ global $timestamp, $maximum_time, $timeout_passed; if ($maximum_time == 0) { return FALSE; @@ -37,16 +38,23 @@ function PMA_checkTimeout() { * @return string MIME type of compression, none for none * @access public */ -function PMA_detectCompression($filepath) { +function PMA_detectCompression($filepath) +{ $file = @fopen($filepath, 'rb'); if (!$file) { return FALSE; } $test = fread($file, 4); fclose($file); - if ($test[0] == chr(31) && $test[1] == chr(139)) return 'application/gzip'; - if (substr($test, 0, 3) == 'BZh') return 'application/bzip2'; - if ($test == "PK\003\004") return 'application/zip'; + if ($test[0] == chr(31) && $test[1] == chr(139)) { + return 'application/gzip'; + } + if (substr($test, 0, 3) == 'BZh') { + return 'application/bzip2'; + } + if ($test == "PK\003\004") { + return 'application/zip'; + } return 'none'; } @@ -58,7 +66,8 @@ function PMA_detectCompression($filepath) { * @param string query to display, this might be commented * @access public */ -function PMA_importRunQuery($sql = '', $full = '') { +function PMA_importRunQuery($sql = '', $full = '') +{ global $import_run_buffer, $go_sql, $complete_query, $display_query, $sql_query, $cfg, $my_die, $error, $reload, $finished, $timeout_passed, $skip_queries, $executed_queries, $max_sql_len, $read_multiply, $cfg, $sql_query_disabled, $db, $run_query, $is_superuser; $read_multiply = 1; if (isset($import_run_buffer)) { @@ -110,7 +119,7 @@ function PMA_importRunQuery($sql = '', $full = '') { $error = TRUE; return; } - } else if ($cfg['VerboseMultiSubmit']) { + } elseif ($cfg['VerboseMultiSubmit']) { $a_num_rows = (int)@PMA_DBI_num_rows($result); $a_aff_rows = (int)@PMA_DBI_affected_rows(); if ($a_num_rows > 0) { @@ -181,19 +190,29 @@ function PMA_importRunQuery($sql = '', $full = '') { * @return string part of file/buffer * @access public */ -function PMA_importGetNextChunk($size = 32768) { +function PMA_importGetNextChunk($size = 32768) +{ global $import_file, $import_text, $finished, $compression, $import_handle, $offset, $charset_conversion, $charset_of_file, $charset, $read_multiply, $read_limit; // Add some progression while reading large amount of data - if ($read_multiply <= 8) $size *= $read_multiply; - else $size *= 8; + if ($read_multiply <= 8) { + $size *= $read_multiply; + } else { + $size *= 8; + } $read_multiply++; // We can not read too much - if ($size > $read_limit) $size = $read_limit; + if ($size > $read_limit) { + $size = $read_limit; + } - if (PMA_checkTimeout()) return FALSE; - if ($finished) return TRUE; + if (PMA_checkTimeout()) { + return FALSE; + } + if ($finished) { + return TRUE; + } if ($import_file == 'none') { // Well this is not yet supported and tested, but should return content of textarea diff --git a/libraries/import/csv.php b/libraries/import/csv.php index 5d2ba8ecbe..c45c6f031c 100644 --- a/libraries/import/csv.php +++ b/libraries/import/csv.php @@ -75,7 +75,7 @@ if ($plugin_param == 'table') { } $val = trim($val); $found = FALSE; - foreach($tmp_fields as $id => $field) { + foreach ($tmp_fields as $id => $field) { if ($field['Field'] == $val) { $found = TRUE; break; @@ -118,7 +118,9 @@ if ($plugin_param == 'table') { $buffer .= $data; // Do not parse string when we're not at the end and don't have new line inside if (($csv_new_line == 'auto' && strpos($buffer, "\r") === FALSE && strpos($buffer, "\n") === FALSE) - || ($csv_new_line != 'auto' && strpos($buffer, $csv_new_line) === FALSE)) continue; + || ($csv_new_line != 'auto' && strpos($buffer, $csv_new_line) === FALSE)) { + continue; + } } // Current length of our buffer @@ -140,7 +142,9 @@ if ($plugin_param == 'table') { // Grab empty field if ($ch == $csv_terminated) { $values[] = ''; - if ($i == $len - 1) break; + if ($i == $len - 1) { + break; + } $i++; $ch = $buffer[$i]; continue; @@ -149,7 +153,9 @@ if ($plugin_param == 'table') { // Grab one field if ($ch == $csv_enclosed) { $need_end = TRUE; - if ($i == $len - 1) break; + if ($i == $len - 1) { + break; + } $i++; $ch = $buffer[$i]; } else { @@ -157,7 +163,7 @@ if ($plugin_param == 'table') { } $fail = FALSE; $value = ''; - while(($need_end && $ch != $csv_enclosed) || (!$need_end && !($ch == $csv_terminated || $ch == $csv_new_line || ($csv_new_line == 'auto' && ($ch == "\r" || $ch == "\n"))))) { + while (($need_end && $ch != $csv_enclosed) || (!$need_end && !($ch == $csv_terminated || $ch == $csv_new_line || ($csv_new_line == 'auto' && ($ch == "\r" || $ch == "\n"))))) { if ($ch == $csv_escaped) { if ($i == $len - 1) { $fail = TRUE; @@ -176,11 +182,15 @@ if ($plugin_param == 'table') { $i++; $ch = $buffer[$i]; } - if ($fail) break; + if ($fail) { + break; + } $values[] = $value; // Need to strip trailing enclosing char? if ($need_end && $ch == $csv_enclosed) { - if ($i == $len - 1) break; + if ($i == $len - 1) { + break; + } $i++; $ch = $buffer[$i]; } @@ -190,7 +200,9 @@ if ($plugin_param == 'table') { } // Go to next char if ($ch == $csv_terminated) { - if ($i == $len - 1) break; + if ($i == $len - 1) { + break; + } $i++; $ch = $buffer[$i]; } @@ -199,7 +211,9 @@ if ($plugin_param == 'table') { // End of line if ($csv_finish || $ch == $csv_new_line || ($csv_new_line == 'auto' && ($ch == "\r" || $ch == "\n"))) { if ($csv_new_line == 'auto' && $ch == "\r") { // Handle "\r\n" - if ($i >= ($len - 2) && !$finished) break; // We need more data to decide new line + if ($i >= ($len - 2) && !$finished) { + break; // We need more data to decide new line + } if ($buffer[$i + 1] == "\n") { $i++; } @@ -218,7 +232,7 @@ if ($plugin_param == 'table') { $first = TRUE; $sql = $sql_template; - foreach($values as $key => $val) { + foreach ($values as $key => $val) { if (!$first) { $sql .= ', '; } diff --git a/libraries/import/sql.php b/libraries/import/sql.php index bad3193f8d..204eeeb31d 100644 --- a/libraries/import/sql.php +++ b/libraries/import/sql.php @@ -29,34 +29,52 @@ if (isset($plugin_list)) { // Append new data to buffer $buffer .= $data; // Do not parse string when we're not at the end and don't have ; inside - if ((strpos($buffer, ';') === FALSE) && !$finished) continue; + if ((strpos($buffer, ';') === FALSE) && !$finished) { + continue; + } } // Current length of our buffer $len = strlen($buffer); // Grab some SQL queries out of it - while($i < $len) { + while ($i < $len) { // Find first interesting character, several strpos seem to be faster than simple loop in php: - //while(($i < $len) && (strpos('\'";#-/', $buffer[$i]) === FALSE)) $i++; + //while (($i < $len) && (strpos('\'";#-/', $buffer[$i]) === FALSE)) $i++; //if ($i == $len) break; $oi = $i; $p1 = strpos($buffer, '\'', $i); - if ($p1 === FALSE) $p1 = 2147483647; + if ($p1 === FALSE) { + $p1 = 2147483647; + } $p2 = strpos($buffer, '"', $i); - if ($p2 === FALSE) $p2 = 2147483647; + if ($p2 === FALSE) { + $p2 = 2147483647; + } $p3 = strpos($buffer, ';', $i); - if ($p3 === FALSE) $p3 = 2147483647; + if ($p3 === FALSE) { + $p3 = 2147483647; + } $p4 = strpos($buffer, '#', $i); - if ($p4 === FALSE) $p4 = 2147483647; + if ($p4 === FALSE) { + $p4 = 2147483647; + } $p5 = strpos($buffer, '--', $i); - if ($p5 === FALSE) $p5 = 2147483647; + if ($p5 === FALSE) { + $p5 = 2147483647; + } $p6 = strpos($buffer, '/*', $i); - if ($p6 === FALSE) $p6 = 2147483647; + if ($p6 === FALSE) { + $p6 = 2147483647; + } $p7 = strpos($buffer, '`', $i); - if ($p7 === FALSE) $p7 = 2147483647; + if ($p7 === FALSE) { + $p7 = 2147483647; + } $i = min ($p1, $p2, $p3, $p4, $p5, $p6, $p7); if ($i == 2147483647) { $i = $oi; - if (!$finished) break; + if (!$finished) { + break; + } // at the end there might be some whitespace... if (trim($buffer) == '') { $buffer = ''; @@ -94,7 +112,9 @@ if (isset($plugin_list)) { // Skip the string $i = $pos; } - if (!$endq) break; + if (!$endq) { + break; + } $i++; // Aren't we at the end? if ($finished && $i == $len) { @@ -131,7 +151,9 @@ if (isset($plugin_list)) { } } // Skip * - if ($ch == '/') $i++; + if ($ch == '/') { + $i++; + } // Skip last char $i++; // Next query part will start here @@ -161,7 +183,9 @@ if (isset($plugin_list)) { $i = 0; $start_pos = 0; // Any chance we will get a complete query? - if ((strpos($buffer, ';') === FALSE) && !$finished) break; + if ((strpos($buffer, ';') === FALSE) && !$finished) { + break; + } } else { $i++; $start_pos = $i; diff --git a/libraries/ip_allow_deny.lib.php b/libraries/ip_allow_deny.lib.php index 2d47612b45..d4caadb2c2 100644 --- a/libraries/ip_allow_deny.lib.php +++ b/libraries/ip_allow_deny.lib.php @@ -25,88 +25,72 @@ function PMA_getIp() if (empty($REMOTE_ADDR)) { if (!empty($_SERVER) && isset($_SERVER['REMOTE_ADDR'])) { $REMOTE_ADDR = $_SERVER['REMOTE_ADDR']; - } - else if (!empty($_ENV) && isset($_ENV['REMOTE_ADDR'])) { + } elseif (!empty($_ENV) && isset($_ENV['REMOTE_ADDR'])) { $REMOTE_ADDR = $_ENV['REMOTE_ADDR']; - } - else if (@getenv('REMOTE_ADDR')) { + } elseif (@getenv('REMOTE_ADDR')) { $REMOTE_ADDR = getenv('REMOTE_ADDR'); } } // end if if (empty($HTTP_X_FORWARDED_FOR)) { if (!empty($_SERVER) && isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $HTTP_X_FORWARDED_FOR = $_SERVER['HTTP_X_FORWARDED_FOR']; - } - else if (!empty($_ENV) && isset($_ENV['HTTP_X_FORWARDED_FOR'])) { + } elseif (!empty($_ENV) && isset($_ENV['HTTP_X_FORWARDED_FOR'])) { $HTTP_X_FORWARDED_FOR = $_ENV['HTTP_X_FORWARDED_FOR']; - } - else if (@getenv('HTTP_X_FORWARDED_FOR')) { + } elseif (@getenv('HTTP_X_FORWARDED_FOR')) { $HTTP_X_FORWARDED_FOR = getenv('HTTP_X_FORWARDED_FOR'); } } // end if if (empty($HTTP_X_FORWARDED)) { if (!empty($_SERVER) && isset($_SERVER['HTTP_X_FORWARDED'])) { $HTTP_X_FORWARDED = $_SERVER['HTTP_X_FORWARDED']; - } - else if (!empty($_ENV) && isset($_ENV['HTTP_X_FORWARDED'])) { + } elseif (!empty($_ENV) && isset($_ENV['HTTP_X_FORWARDED'])) { $HTTP_X_FORWARDED = $_ENV['HTTP_X_FORWARDED']; - } - else if (@getenv('HTTP_X_FORWARDED')) { + } elseif (@getenv('HTTP_X_FORWARDED')) { $HTTP_X_FORWARDED = getenv('HTTP_X_FORWARDED'); } } // end if if (empty($HTTP_FORWARDED_FOR)) { if (!empty($_SERVER) && isset($_SERVER['HTTP_FORWARDED_FOR'])) { $HTTP_FORWARDED_FOR = $_SERVER['HTTP_FORWARDED_FOR']; - } - else if (!empty($_ENV) && isset($_ENV['HTTP_FORWARDED_FOR'])) { + } elseif (!empty($_ENV) && isset($_ENV['HTTP_FORWARDED_FOR'])) { $HTTP_FORWARDED_FOR = $_ENV['HTTP_FORWARDED_FOR']; - } - else if (@getenv('HTTP_FORWARDED_FOR')) { + } elseif (@getenv('HTTP_FORWARDED_FOR')) { $HTTP_FORWARDED_FOR = getenv('HTTP_FORWARDED_FOR'); } } // end if if (empty($HTTP_FORWARDED)) { if (!empty($_SERVER) && isset($_SERVER['HTTP_FORWARDED'])) { $HTTP_FORWARDED = $_SERVER['HTTP_FORWARDED']; - } - else if (!empty($_ENV) && isset($_ENV['HTTP_FORWARDED'])) { + } elseif (!empty($_ENV) && isset($_ENV['HTTP_FORWARDED'])) { $HTTP_FORWARDED = $_ENV['HTTP_FORWARDED']; - } - else if (@getenv('HTTP_FORWARDED')) { + } elseif (@getenv('HTTP_FORWARDED')) { $HTTP_FORWARDED = getenv('HTTP_FORWARDED'); } } // end if if (empty($HTTP_VIA)) { if (!empty($_SERVER) && isset($_SERVER['HTTP_VIA'])) { $HTTP_VIA = $_SERVER['HTTP_VIA']; - } - else if (!empty($_ENV) && isset($_ENV['HTTP_VIA'])) { + } elseif (!empty($_ENV) && isset($_ENV['HTTP_VIA'])) { $HTTP_VIA = $_ENV['HTTP_VIA']; - } - else if (@getenv('HTTP_VIA')) { + } elseif (@getenv('HTTP_VIA')) { $HTTP_VIA = getenv('HTTP_VIA'); } } // end if if (empty($HTTP_X_COMING_FROM)) { if (!empty($_SERVER) && isset($_SERVER['HTTP_X_COMING_FROM'])) { $HTTP_X_COMING_FROM = $_SERVER['HTTP_X_COMING_FROM']; - } - else if (!empty($_ENV) && isset($_ENV['HTTP_X_COMING_FROM'])) { + } elseif (!empty($_ENV) && isset($_ENV['HTTP_X_COMING_FROM'])) { $HTTP_X_COMING_FROM = $_ENV['HTTP_X_COMING_FROM']; - } - else if (@getenv('HTTP_X_COMING_FROM')) { + } elseif (@getenv('HTTP_X_COMING_FROM')) { $HTTP_X_COMING_FROM = getenv('HTTP_X_COMING_FROM'); } } // end if if (empty($HTTP_COMING_FROM)) { if (!empty($_SERVER) && isset($_SERVER['HTTP_COMING_FROM'])) { $HTTP_COMING_FROM = $_SERVER['HTTP_COMING_FROM']; - } - else if (!empty($_ENV) && isset($_ENV['HTTP_COMING_FROM'])) { + } elseif (!empty($_ENV) && isset($_ENV['HTTP_COMING_FROM'])) { $HTTP_COMING_FROM = $_ENV['HTTP_COMING_FROM']; - } - else if (@getenv('HTTP_COMING_FROM')) { + } elseif (@getenv('HTTP_COMING_FROM')) { $HTTP_COMING_FROM = getenv('HTTP_COMING_FROM'); } } // end if @@ -120,19 +104,19 @@ function PMA_getIp() $proxy_ip = ''; if (!empty($HTTP_X_FORWARDED_FOR)) { $proxy_ip = $HTTP_X_FORWARDED_FOR; - } else if (!empty($HTTP_X_FORWARDED)) { + } elseif (!empty($HTTP_X_FORWARDED)) { $proxy_ip = $HTTP_X_FORWARDED; - } else if (!empty($HTTP_FORWARDED_FOR)) { + } elseif (!empty($HTTP_FORWARDED_FOR)) { $proxy_ip = $HTTP_FORWARDED_FOR; - } else if (!empty($HTTP_FORWARDED)) { + } elseif (!empty($HTTP_FORWARDED)) { $proxy_ip = $HTTP_FORWARDED; - } else if (!empty($HTTP_VIA)) { + } elseif (!empty($HTTP_VIA)) { $proxy_ip = $HTTP_VIA; - } else if (!empty($HTTP_X_COMING_FROM)) { + } elseif (!empty($HTTP_X_COMING_FROM)) { $proxy_ip = $HTTP_X_COMING_FROM; - } else if (!empty($HTTP_COMING_FROM)) { + } elseif (!empty($HTTP_COMING_FROM)) { $proxy_ip = $HTTP_COMING_FROM; - } // end if... else if... + } // end if... elseif... // Returns the true IP if it has been found, else FALSE if (empty($proxy_ip)) { diff --git a/libraries/mult_submits.inc.php b/libraries/mult_submits.inc.php index 64d4be9400..e0f8d9cbe6 100644 --- a/libraries/mult_submits.inc.php +++ b/libraries/mult_submits.inc.php @@ -232,7 +232,7 @@ if ( !empty($submit_mult) && !empty($what)) { echo PMA_generate_common_hidden_inputs($db); } elseif (strpos(' ' . $action, 'tbl_properties') == 1 || $what == 'row_delete') { - echo PMA_generate_common_hidden_inputs($db,$table); + echo PMA_generate_common_hidden_inputs($db, $table); } else { echo PMA_generate_common_hidden_inputs(); } @@ -393,7 +393,7 @@ elseif ($mult_btn == $strYes) { break; } // end switch - // All "DROP TABLE","DROP FIELD", "OPTIMIZE TABLE" and "REPAIR TABLE" + // All "DROP TABLE", "DROP FIELD", "OPTIMIZE TABLE" and "REPAIR TABLE" // statements will be run at once below if ($run_parts) { $sql_query .= $a_query . ';' . "\n"; diff --git a/libraries/mysql_charsets.lib.php b/libraries/mysql_charsets.lib.php index ba75d66a9e..ea92037fc2 100644 --- a/libraries/mysql_charsets.lib.php +++ b/libraries/mysql_charsets.lib.php @@ -50,7 +50,7 @@ if (PMA_MYSQL_INT_VERSION >= 40100){ define('PMA_CSDROPDOWN_COLLATION', 0); define('PMA_CSDROPDOWN_CHARSET', 1); - function PMA_generateCharsetDropdownBox($type = PMA_CSDROPDOWN_COLLATION, $name = NULL, $id = NULL, $default = NULL, $label = TRUE, $indent = 0, $submitOnChange = FALSE, $displayUnavailable = FALSE) { + function PMA_generateCharsetDropdownBox($type = PMA_CSDROPDOWN_COLLATION, $name = null, $id = null, $default = null, $label = TRUE, $indent = 0, $submitOnChange = FALSE, $displayUnavailable = FALSE) { global $mysql_charsets, $mysql_charsets_descriptions, $mysql_charsets_available, $mysql_collations, $mysql_collations_available; if (empty($name)) { diff --git a/libraries/plugin_interface.lib.php b/libraries/plugin_interface.lib.php index c119fab895..55c76aed33 100644 --- a/libraries/plugin_interface.lib.php +++ b/libraries/plugin_interface.lib.php @@ -242,7 +242,7 @@ function PMA_pluginGetJavascript(&$list) { //<![CDATA[ function hide_them_all() { '; - foreach($list as $plugin_name => $val) { + foreach ($list as $plugin_name => $val) { $ret .= 'document.getElementById("' . $plugin_name . '_options").style.display = "none";' . "\n"; } $ret .= ' @@ -251,7 +251,7 @@ function PMA_pluginGetJavascript(&$list) { function init_options() { hide_them_all(); '; - foreach($list as $plugin_name => $val) { + foreach ($list as $plugin_name => $val) { $ret .= 'if (document.getElementById("radio_plugin_' . $plugin_name . '").checked) {' . "\n"; $ret .= 'document.getElementById("' . $plugin_name . '_options").style.display = "block";' . "\n"; $ret .= ' } else ' . "\n"; @@ -269,7 +269,7 @@ function PMA_pluginGetJavascript(&$list) { if (farr[len - 1] == "gz" || farr[len - 1] == "bz2" || farr[len -1] == "zip") len--; switch (farr[len - 1]) { '; - foreach($list as $plugin_name => $val) { + foreach ($list as $plugin_name => $val) { $ret .= 'case "' . $val['extension'] . '" :'; $ret .= 'document.getElementById("radio_plugin_' . $plugin_name . '").checked = true;'; $ret .= 'init_options();'; diff --git a/libraries/read_dump.lib.php b/libraries/read_dump.lib.php index e2d823a677..809ca93069 100644 --- a/libraries/read_dump.lib.php +++ b/libraries/read_dump.lib.php @@ -44,7 +44,7 @@ function PMA_splitSqlFile(&$ret, $sql, $release) } // Backquotes or no backslashes before quotes: it's indeed the // end of the string -> exit the loop - else if ($string_start == '`' || $sql[$i-1] != '\\') { + elseif ($string_start == '`' || $sql[$i-1] != '\\') { $string_start = ''; $in_string = FALSE; break; @@ -74,17 +74,19 @@ function PMA_splitSqlFile(&$ret, $sql, $release) } // end if (in string) // lets skip comments (/*, -- and #) - else if (($char == '-' && $sql_len > $i + 2 && $sql[$i + 1] == '-' && $sql[$i + 2] <= ' ') || $char == '#' || ($char == '/' && $sql_len > $i + 1 && $sql[$i + 1] == '*')) { + elseif (($char == '-' && $sql_len > $i + 2 && $sql[$i + 1] == '-' && $sql[$i + 2] <= ' ') || $char == '#' || ($char == '/' && $sql_len > $i + 1 && $sql[$i + 1] == '*')) { $i = strpos($sql, $char == '/' ? '*/' : "\n", $i); // didn't we hit end of string? if ($i === FALSE) { break; } - if ($char == '/') $i++; + if ($char == '/') { + $i++; + } } // We are not in a string, first check for delimiter... - else if ($char == ';') { + elseif ($char == ';') { // if delimiter found, add the parsed part to the returned array $ret[] = array('query' => substr($sql, 0, $i), 'empty' => $nothing); $nothing = TRUE; @@ -96,14 +98,14 @@ function PMA_splitSqlFile(&$ret, $sql, $release) // The submited statement(s) end(s) here return TRUE; } - } // end else if (is delimiter) + } // end elseif (is delimiter) // ... then check for start of a string,... - else if (($char == '"') || ($char == '\'') || ($char == '`')) { + elseif (($char == '"') || ($char == '\'') || ($char == '`')) { $in_string = TRUE; $nothing = FALSE; $string_start = $char; - } // end else if (is start of string) + } // end elseif (is start of string) elseif ($nothing) { $nothing = FALSE; @@ -151,8 +153,12 @@ function PMA_readFile($path, $mime = '') { } $test = fread($file, 3); fclose($file); - if ($test[0] == chr(31) && $test[1] == chr(139)) return PMA_readFile($path, 'application/x-gzip'); - if ($test == 'BZh') return PMA_readFile($path, 'application/x-bzip'); + if ($test[0] == chr(31) && $test[1] == chr(139)) { + return PMA_readFile($path, 'application/x-gzip'); + } + if ($test == 'BZh') { + return PMA_readFile($path, 'application/x-bzip'); + } return PMA_readFile($path, 'text/plain'); case 'text/plain': $file = @fopen($path, 'rb'); diff --git a/libraries/relation.lib.php b/libraries/relation.lib.php index a2d06f950f..ba1e531c2c 100644 --- a/libraries/relation.lib.php +++ b/libraries/relation.lib.php @@ -119,17 +119,17 @@ function PMA_getRelationsParam($verbose = FALSE) while ($curr_table = @PMA_DBI_fetch_row($tab_rs)) { if ($curr_table[0] == $cfg['Server']['bookmarktable']) { $cfgRelation['bookmark'] = $curr_table[0]; - } else if ($curr_table[0] == $cfg['Server']['relation']) { + } elseif ($curr_table[0] == $cfg['Server']['relation']) { $cfgRelation['relation'] = $curr_table[0]; - } else if ($curr_table[0] == $cfg['Server']['table_info']) { + } elseif ($curr_table[0] == $cfg['Server']['table_info']) { $cfgRelation['table_info'] = $curr_table[0]; - } else if ($curr_table[0] == $cfg['Server']['table_coords']) { + } elseif ($curr_table[0] == $cfg['Server']['table_coords']) { $cfgRelation['table_coords'] = $curr_table[0]; - } else if ($curr_table[0] == $cfg['Server']['column_info']) { + } elseif ($curr_table[0] == $cfg['Server']['column_info']) { $cfgRelation['column_info'] = $curr_table[0]; - } else if ($curr_table[0] == $cfg['Server']['pdf_pages']) { + } elseif ($curr_table[0] == $cfg['Server']['pdf_pages']) { $cfgRelation['pdf_pages'] = $curr_table[0]; - } else if ($curr_table[0] == $cfg['Server']['history']) { + } elseif ($curr_table[0] == $cfg['Server']['history']) { $cfgRelation['history'] = $curr_table[0]; } } // end while @@ -157,9 +157,9 @@ function PMA_getRelationsParam($verbose = FALSE) while ($curr_mime_field = @PMA_DBI_fetch_row($mime_rs)) { if ($curr_mime_field[0] == 'mimetype') { $mime_field_mimetype = TRUE; - } else if ($curr_mime_field[0] == 'transformation') { + } elseif ($curr_mime_field[0] == 'transformation') { $mime_field_transformation = TRUE; - } else if ($curr_mime_field[0] == 'transformation_options') { + } elseif ($curr_mime_field[0] == 'transformation_options') { $mime_field_transformation_options = TRUE; } } @@ -315,7 +315,7 @@ function PMA_getForeigners($db, $table, $column = '', $source = 'both') { $show_create_table_query = 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table); $show_create_table_res = PMA_DBI_query($show_create_table_query); - list(,$show_create_table) = PMA_DBI_fetch_row($show_create_table_res); + list(, $show_create_table) = PMA_DBI_fetch_row($show_create_table_res); PMA_DBI_free_result($show_create_table_res); unset($show_create_table_res, $show_create_table_query); $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table)); @@ -468,7 +468,7 @@ function PMA_getComments($db, $table = '') { if (PMA_MYSQL_INT_VERSION >= 40100) { $fields = PMA_DBI_get_fields($db, $table); if ($fields) { - foreach($fields as $key=>$field) { + foreach ($fields as $key=>$field) { $tmp_col = $field['Field']; if (!empty($field['Comment'])) { $native_comment[$tmp_col] = $field['Comment']; @@ -520,9 +520,9 @@ function PMA_getComments($db, $table = '') { $comment[$col] = $native_comment[$col]; } else { // no native comment, so migrate pmadb-style to native - PMA_setComment($db, $table, $col, $comment[$col],'','native'); + PMA_setComment($db, $table, $col, $comment[$col], '', 'native'); // and erase the pmadb-style comment - PMA_setComment($db, $table, $col, '','','pmadb'); + PMA_setComment($db, $table, $col, '', '', 'pmadb'); } } } @@ -583,7 +583,7 @@ function PMA_setComment($db, $table, $col, $comment, $removekey = '', $mode='aut if ($mode == 'native' && isset($table) && strlen($table)) { $query = 'ALTER TABLE ' . PMA_backquote($table) . ' CHANGE ' . PMA_generateAlterTable($col, $col, '', '', '', '', FALSE, '', FALSE, '', $comment, '', ''); - PMA_DBI_try_query($query, NULL, PMA_DBI_QUERY_STORE); + PMA_DBI_try_query($query, null, PMA_DBI_QUERY_STORE); return TRUE; } @@ -636,7 +636,7 @@ function PMA_setComment($db, $table, $col, $comment, $removekey = '', $mode='aut AND ' . $cols['table_name'] . ' = \'' . PMA_sqlAddslashes($table) . '\' AND ' . $cols['column_name'] . ' = \'' . PMA_sqlAddslashes($col) . '\''; } - } else if (strlen($comment) > 0) { + } elseif (strlen($comment) > 0) { $upd_query = ' INSERT INTO ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . ' @@ -879,18 +879,18 @@ function PMA_foreignDropdown($disp, $foreign_field, $foreign_display, $data, $ma // put the dropdown sections in correct order $c = count($cfg['ForeignKeyDropdownOrder']); - if($c == 2) { + if ($c == 2) { $top = $reloptions[$cfg['ForeignKeyDropdownOrder'][0]]; $bot = $reloptions[$cfg['ForeignKeyDropdownOrder'][1]]; - } elseif($c == 1) { + } elseif ($c == 1) { $bot = $reloptions[$cfg['ForeignKeyDropdownOrder'][0]]; - $top = NULL; + $top = null; } else { $top = $reloptions['id-content']; $bot = $reloptions['content-id']; } $str_bot = implode('', $bot); - if($top !== NULL) { + if ($top !== null) { $str_top = implode('', $top); $top_count = count($top); if ($max == -1 || $top_count < $max) { diff --git a/libraries/select_lang.lib.php b/libraries/select_lang.lib.php index b823998f1e..1b1567085b 100644 --- a/libraries/select_lang.lib.php +++ b/libraries/select_lang.lib.php @@ -23,10 +23,11 @@ * @uses explode() * @return bool success if valid lang is found, otherwise false */ -function PMA_langCheck() { +function PMA_langCheck() +{ // check forced language - if ( ! empty( $GLOBALS['cfg']['Lang'] ) ) { - if ( PMA_langSet( $GLOBALS['cfg']['Lang'] ) ) { + if (! empty($GLOBALS['cfg']['Lang'])) { + if (PMA_langSet($GLOBALS['cfg']['Lang'])) { return true; } else { $GLOBALS['lang_failed_cfg'] = $GLOBALS['cfg']['Lang']; @@ -34,8 +35,8 @@ function PMA_langCheck() { } // check user requested language - if ( ! empty( $_REQUEST['lang'] ) ) { - if ( PMA_langSet( $_REQUEST['lang'] ) ) { + if (! empty($_REQUEST['lang'])) { + if (PMA_langSet($_REQUEST['lang'])) { return true; } else { $GLOBALS['lang_failed_request'] = $_REQUEST['lang']; @@ -43,8 +44,8 @@ function PMA_langCheck() { } // check previous set language - if ( ! empty( $_COOKIE['pma_lang'] ) ) { - if ( PMA_langSet( $_COOKIE['pma_lang'] ) ) { + if (! empty($_COOKIE['pma_lang'])) { + if (PMA_langSet($_COOKIE['pma_lang'])) { return true; } else { $GLOBALS['lang_failed_cookie'] = $_COOKIE['pma_lang']; @@ -52,21 +53,21 @@ function PMA_langCheck() { } // try to findout user's language by checking its HTTP_ACCEPT_LANGUAGE variable - if ( ! empty($_SERVER['HTTP_ACCEPT_LANGUAGE']) ) { - foreach ( explode( ',', $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) as $lang ) { - if ( PMA_langDetect( $lang, 1 ) ) { + if (! empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { + foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $lang) { + if (PMA_langDetect($lang, 1)) { return true; } } } // try to findout user's language by checking its HTTP_USER_AGENT variable - if ( PMA_langDetect($_SERVER['HTTP_USER_AGENT'], 2) ) { + if (PMA_langDetect($_SERVER['HTTP_USER_AGENT'], 2)) { return true; } // Didn't catch any valid lang : we use the default settings - if ( PMA_langSet($GLOBALS['cfg']['DefaultLang']) ) { + if (PMA_langSet($GLOBALS['cfg']['DefaultLang'])) { return true; } @@ -82,8 +83,9 @@ function PMA_langCheck() { * @param string $lang language to set * @return bool success */ -function PMA_langSet( &$lang ) { - if ( empty( $lang ) || empty( $GLOBALS['available_languages'][$lang] ) ) { +function PMA_langSet(&$lang) +{ + if (empty($lang) || empty($GLOBALS['available_languages'][$lang])) { return false; } $GLOBALS['lang'] = $lang; @@ -103,9 +105,14 @@ function PMA_langSet( &$lang ) { * * @access private */ -function PMA_langDetect( &$str, $envType ) { - if ( empty( $str ) ) return false; - if ( empty( $GLOBALS['available_languages'] ) ) return false; +function PMA_langDetect(&$str, $envType) +{ + if (empty($str)) { + return false; + } + if (empty($GLOBALS['available_languages'])) { + return false; + } foreach ($GLOBALS['available_languages'] as $lang => $value) { // $envType = 1 for the 'HTTP_ACCEPT_LANGUAGE' environment variable, @@ -116,7 +123,7 @@ function PMA_langDetect( &$str, $envType ) { } if (($envType == 1 && eregi('^(' . $expr . ')(;q=[0-9]\\.[0-9])?$', $str)) || ($envType == 2 && eregi('(\(|\[|;[[:space:]])(' . $expr . ')(;|\]|\))', $str))) { - if ( PMA_langSet( $lang ) ) { + if (PMA_langSet($lang)) { return true; } } @@ -133,14 +140,14 @@ $lang_path = './lang/'; /** * first check for lang dir exists */ -if ( ! is_dir( $lang_path ) ) { +if (! is_dir($lang_path)) { // language directory not found - trigger_error( 'phpMyAdmin-ERROR: path not found: ' + trigger_error('phpMyAdmin-ERROR: path not found: ' . $lang_path . ', check your language directory.', - E_USER_WARNING ); + E_USER_WARNING); // and tell the user - PMA_sendHeaderLocation( 'error.php?error=' - . urlencode( 'path to languages is invalid: ' . $lang_path ) ); + PMA_sendHeaderLocation('error.php?error=' + . urlencode( 'path to languages is invalid: ' . $lang_path)); // stop execution exit; } @@ -318,9 +325,9 @@ $available_languages = array( ); // Language filtering support -if ( ! empty( $GLOBALS['cfg']['FilterLanguages'] ) ) { +if (! empty($GLOBALS['cfg']['FilterLanguages'])) { $new_lang = array(); - foreach($available_languages as $key => $val) { + foreach ($available_languages as $key => $val) { if (preg_match('@' . $GLOBALS['cfg']['FilterLanguages'] . '@', $key)) { $new_lang[$key] = $val; } @@ -328,18 +335,18 @@ if ( ! empty( $GLOBALS['cfg']['FilterLanguages'] ) ) { if (count($new_lang) > 0) { $available_languages = $new_lang; } - unset( $key, $val, $new_lang ); + unset($key, $val, $new_lang); } /** * check for language files */ -foreach ( $available_languages as $each_lang_key => $each_lang ) { - if ( ! file_exists( $lang_path . $each_lang[1] . '.inc.php' ) ) { - unset( $available_languages[$each_lang_key] ); +foreach ($available_languages as $each_lang_key => $each_lang) { + if (! file_exists($lang_path . $each_lang[1] . '.inc.php')) { + unset($available_languages[$each_lang_key]); } } -unset( $each_lang_key, $each_lang ); +unset($each_lang_key, $each_lang); // MySQL charsets map $mysql_charset_map = array( @@ -373,7 +380,7 @@ $mysql_charset_map = array( */ // Checks whether charset recoding should be allowed or not $allow_recoding = FALSE; // Default fallback value -if ( empty($convcharset) ) { +if (empty($convcharset)) { if (isset($_COOKIE['pma_charset'])) { $convcharset = $_COOKIE['pma_charset']; } else { @@ -381,36 +388,36 @@ if ( empty($convcharset) ) { } } -if ( ! PMA_langCheck() ) { +if (! PMA_langCheck()) { // fallback language $fall_back_lang = 'en-utf-8'; $line = __LINE__; - if ( ! PMA_langSet( $fall_back_lang ) ) { - trigger_error( 'phpMyAdmin-ERROR: invalid lang code: ' + if (! PMA_langSet($fall_back_lang)) { + trigger_error('phpMyAdmin-ERROR: invalid lang code: ' . __FILE__ . '#' . $line . ', check hard coded fall back language.', - E_USER_WARNING ); + E_USER_WARNING); // stop execution // and tell the user that his choosen language is invalid - PMA_sendHeaderLocation( 'error.php?error=' - . urlencode( 'Could not load any language, please check your language settings and folder' ) ); + PMA_sendHeaderLocation('error.php?error=' + . urlencode('Could not load any language, please check your language settings and folder')); exit; } } // Defines the associated filename and load the translation $lang_file = $lang_path . $available_languages[$GLOBALS['lang']][1] . '.inc.php'; -require_once( $lang_file ); +require_once($lang_file); // now, that we have loaded the language strings we can send the errors -if ( $lang_failed_cfg ) { - $GLOBALS['PMA_errors'][] = sprintf( $strLanguageUnknown, $lang_failed_cfg ); +if ($lang_failed_cfg) { + $GLOBALS['PMA_errors'][] = sprintf($strLanguageUnknown, $lang_failed_cfg); } -if ( $lang_failed_cookie ) { - $GLOBALS['PMA_errors'][] = sprintf( $strLanguageUnknown, $lang_failed_cookie ); +if ($lang_failed_cookie) { + $GLOBALS['PMA_errors'][] = sprintf($strLanguageUnknown, $lang_failed_cookie); } -if ( $lang_failed_request ) { - $GLOBALS['PMA_errors'][] = sprintf( $strLanguageUnknown, $lang_failed_request ); +if ($lang_failed_request) { + $GLOBALS['PMA_errors'][] = sprintf($strLanguageUnknown, $lang_failed_request); } -unset( $lang_file, $lang_path, $strLanguageFileNotFound, $line, $fall_back_lang, - $lang_failed_cfg, $lang_failed_cookie, $lang_failed_request, $strLanguageUnknown ); +unset($lang_file, $lang_path, $strLanguageFileNotFound, $line, $fall_back_lang, + $lang_failed_cfg, $lang_failed_cookie, $lang_failed_request, $strLanguageUnknown); ?> diff --git a/libraries/select_server.lib.php b/libraries/select_server.lib.php index 0de2d765c8..022d12de4c 100644 --- a/libraries/select_server.lib.php +++ b/libraries/select_server.lib.php @@ -56,7 +56,7 @@ function PMA_select_server($form, $left) { if ($list){ if ($selected && !$left) { echo '» <b>' . htmlspecialchars($label) . '</b><br />'; - }else{ + } else { echo '» <a class="item" href="index.php?server=' . $key . '&lang=' . $lang . '&convcharset=' . $convcharset . '" target="_top">' . htmlspecialchars($label) . '</a><br />'; } } else { diff --git a/libraries/server_common.inc.php b/libraries/server_common.inc.php index 342d276633..7d7460e6fe 100644 --- a/libraries/server_common.inc.php +++ b/libraries/server_common.inc.php @@ -51,7 +51,7 @@ if ($is_superuser) { } $has_binlogs = FALSE; -$binlogs = PMA_DBI_try_query('SHOW MASTER LOGS', NULL, PMA_DBI_QUERY_STORE); +$binlogs = PMA_DBI_try_query('SHOW MASTER LOGS', null, PMA_DBI_QUERY_STORE); if ($binlogs) { if (PMA_DBI_num_rows($binlogs) > 0) { $binary_logs = array(); diff --git a/libraries/session.inc.php b/libraries/session.inc.php index 1d9fab90ef..306c77f3ca 100644 --- a/libraries/session.inc.php +++ b/libraries/session.inc.php @@ -24,52 +24,50 @@ if (!@function_exists('session_name')) { require_once('./libraries/select_lang.lib.php'); // Displays the error message // (do not use & for parameters sent by header) - header( 'Location: error.php' - . '?lang=' . urlencode( $available_languages[$lang][2] ) - . '&char=' . urlencode( $charset ) - . '&dir=' . urlencode( $text_dir ) - . '&type=' . urlencode( $strError ) - . '&error=' . urlencode( - sprintf($strCantLoad, 'session')) - ); + header('Location: error.php' + . '?lang=' . urlencode($available_languages[$lang][2]) + . '&char=' . urlencode($charset) + . '&dir=' . urlencode($text_dir) + . '&type=' . urlencode($strError) + . '&error=' . urlencode(sprintf($strCantLoad, 'session'))); exit(); } // session cookie settings -session_set_cookie_params( 0, PMA_Config::getCookiePath(), - '', PMA_Config::isHttps() ); +session_set_cookie_params(0, PMA_Config::getCookiePath(), + '', PMA_Config::isHttps()); // disable starting of sessions before all settings are done -ini_set( 'session.auto_start', false ); +ini_set('session.auto_start', false); // cookies are safer -ini_set( 'session.use_cookies', true ); +ini_set('session.use_cookies', true); // but not all user allow cookies -ini_set( 'session.use_only_cookies', false ); -ini_set( 'session.use_trans_sid', true ); -ini_set( 'url_rewriter.tags', - 'a=href,frame=src,input=src,form=fakeentry,fieldset=' ); -ini_set( 'arg_separator.output' , '&' ); +ini_set('session.use_only_cookies', false); +ini_set('session.use_trans_sid', true); +ini_set('url_rewriter.tags', + 'a=href,frame=src,input=src,form=fakeentry,fieldset='); +ini_set('arg_separator.output', '&'); // delete session/cookies when browser is closed -ini_set( 'session.cookie_lifetime', 0 ); +ini_set('session.cookie_lifetime', 0); // warn but dont work with bug -ini_set( 'session.bug_compat_42', false ); -ini_set( 'session.bug_compat_warn', true ); +ini_set('session.bug_compat_42', false); +ini_set('session.bug_compat_warn', true); // use more secure session ids (with PHP 5) -if ( version_compare( PHP_VERSION, '5.0.0', 'ge' ) - && substr( PHP_OS, 0 ,3 ) != 'WIN' ) { - ini_set( 'session.hash_function', 1 ); - ini_set( 'session.hash_bits_per_character', 6 ); +if (version_compare( PHP_VERSION, '5.0.0', 'ge') + && substr(PHP_OS, 0, 3) != 'WIN') { + ini_set('session.hash_function', 1); + ini_set('session.hash_bits_per_character', 6); } // start the session // on some servers (for example, sourceforge.net), we get a permission error // on the session data directory, so I add some "@" -@session_name( 'phpMyAdmin' ); +@session_name('phpMyAdmin'); @session_start(); /** @@ -82,12 +80,13 @@ if ( version_compare( PHP_VERSION, '5.0.0', 'ge' ) * @uses strip_tags() to prevent XSS attacks in SID * @uses function_exists() for session_regenerate_id() */ -function PMA_secureSession() { +function PMA_secureSession() +{ // prevent session fixation and XSS - if ( function_exists( 'session_regenerate_id' ) ) { - session_regenerate_id( true ); + if (function_exists('session_regenerate_id')) { + session_regenerate_id(true); } else { - session_id( strip_tags( session_id() ) ); + session_id(strip_tags(session_id())); } } ?> diff --git a/libraries/sql_query_form.lib.php b/libraries/sql_query_form.lib.php index c5fe924949..5354334433 100644 --- a/libraries/sql_query_form.lib.php +++ b/libraries/sql_query_form.lib.php @@ -58,9 +58,10 @@ require_once('./libraries/bookmark.lib.php'); // used for file listing * what part to display * false if not inside querywindow */ -function PMA_sqlQueryForm( $query = true, $display_tab = false ) { +function PMA_sqlQueryForm($query = true, $display_tab = false) +{ // check tab to display if inside querywindow - if ( ! $display_tab ) { + if (! $display_tab) { $display_tab = 'full'; $is_querywindow = false; } else { @@ -68,12 +69,12 @@ function PMA_sqlQueryForm( $query = true, $display_tab = false ) { } // query to show - if ( true === $query ) { - $query = empty( $GLOBALS['sql_query'] ) ? '' : $GLOBALS['sql_query']; + if (true === $query) { + $query = empty($GLOBALS['sql_query']) ? '' : $GLOBALS['sql_query']; } // set enctype to multipart for file uploads - if ( $GLOBALS['is_upload'] ) { + if ($GLOBALS['is_upload']) { $enctype = ' enctype="multipart/form-data"'; } else { $enctype = ''; @@ -81,25 +82,25 @@ function PMA_sqlQueryForm( $query = true, $display_tab = false ) { $table = ''; $db = ''; - if ( ! isset( $GLOBALS['db'] ) || ! strlen($GLOBALS['db']) ) { + if (! isset($GLOBALS['db']) || ! strlen($GLOBALS['db'])) { // prepare for server related - $goto = empty( $GLOBALS['goto'] ) ? + $goto = empty($GLOBALS['goto']) ? 'server_sql.php' : $GLOBALS['goto']; - } elseif ( ! isset( $GLOBALS['table'] ) || ! strlen($GLOBALS['table']) ) { + } elseif (! isset($GLOBALS['table']) || ! strlen($GLOBALS['table'])) { // prepare for db related $db = $GLOBALS['db']; - $goto = empty( $GLOBALS['goto'] ) ? + $goto = empty($GLOBALS['goto']) ? 'db_details.php' : $GLOBALS['goto']; } else { $table = $GLOBALS['table']; $db = $GLOBALS['db']; - $goto = empty( $GLOBALS['goto'] ) ? + $goto = empty($GLOBALS['goto']) ? 'tbl_properties.php' : $GLOBALS['goto']; } // start output - if ( $is_querywindow ) { + if ($is_querywindow) { ?> <form method="post" id="sqlqueryform" target="frame_content" action="import.php"<?php echo $enctype; ?> name="sqlform" @@ -113,45 +114,45 @@ function PMA_sqlQueryForm( $query = true, $display_tab = false ) { .' onsubmit="return checkSqlQuery(this)" name="sqlform">' . "\n"; } - if ( $is_querywindow ) { + if ($is_querywindow) { echo '<input type="hidden" name="focus_querywindow" value="true" />' ."\n"; - if ( $display_tab != 'sql' && $display_tab != 'full' ) { + if ($display_tab != 'sql' && $display_tab != 'full') { echo '<input type="hidden" name="sql_query" value="" />' . "\n"; echo '<input type="hidden" name="show_query" value="1" />' . "\n"; } } echo '<input type="hidden" name="is_js_confirmed" value="0" />' . "\n" - .PMA_generate_common_hidden_inputs( $db, $table ) . "\n" + .PMA_generate_common_hidden_inputs($db, $table) . "\n" .'<input type="hidden" name="pos" value="0" />' . "\n" .'<input type="hidden" name="goto" value="' - .htmlspecialchars( $goto ) . '" />' . "\n" + .htmlspecialchars($goto) . '" />' . "\n" .'<input type="hidden" name="zero_rows" value="' - . htmlspecialchars( $GLOBALS['strSuccess'] ) . '" />' . "\n" + . htmlspecialchars($GLOBALS['strSuccess']) . '" />' . "\n" .'<input type="hidden" name="prev_sql_query" value="' - . htmlspecialchars( $query ) . '" />' . "\n"; + . htmlspecialchars($query) . '" />' . "\n"; // display querybox - if ( $display_tab === 'full' || $display_tab === 'sql' ) { - PMA_sqlQueryFormInsert( $query, $is_querywindow ); + if ($display_tab === 'full' || $display_tab === 'sql') { + PMA_sqlQueryFormInsert($query, $is_querywindow); } // display uploads - if ( $display_tab === 'files' && $GLOBALS['is_upload'] ) { + if ($display_tab === 'files' && $GLOBALS['is_upload']) { PMA_sqlQueryFormUpload(); } // Bookmark Support - if ( $display_tab === 'full' || $display_tab === 'history' ) { - if ( ! empty( $GLOBALS['cfg']['Bookmark'] ) + if ($display_tab === 'full' || $display_tab === 'history') { + if (! empty( $GLOBALS['cfg']['Bookmark']) && $GLOBALS['cfg']['Bookmark']['db'] - && $GLOBALS['cfg']['Bookmark']['table'] ) { + && $GLOBALS['cfg']['Bookmark']['table']) { PMA_sqlQueryFormBookmark(); } } // Encoding setting form appended by Y.Kawada - if ( function_exists('PMA_set_enc_form') ) { + if (function_exists('PMA_set_enc_form')) { echo PMA_set_enc_form(' '); } @@ -177,17 +178,18 @@ function PMA_sqlQueryForm( $query = true, $display_tab = false ) { * @param string $query query to display in the textarea * @param boolean $is_querywindow if inside querywindow or not */ -function PMA_sqlQueryFormInsert( $query = '', $is_querywindow = false ) { +function PMA_sqlQueryFormInsert($query = '', $is_querywindow = false) +{ // enable auto select text in textarea - if ( $GLOBALS['cfg']['TextareaAutoSelect'] ) { + if ($GLOBALS['cfg']['TextareaAutoSelect']) { $auto_sel = ' onfocus="selectContent( this, sql_box_locked, true )"'; } else { $auto_sel = ''; } // enable locking if inside query window - if ( $is_querywindow ) { + if ($is_querywindow) { $locking = ' onkeypress="document.sqlform.elements[\'LockFromUpdate\'].' .'checked = true;"'; } else { @@ -197,29 +199,29 @@ function PMA_sqlQueryFormInsert( $query = '', $is_querywindow = false ) { $table = ''; $db = ''; $fields_list = array(); - if ( ! isset( $GLOBALS['db'] ) || ! strlen($GLOBALS['db']) ) { + if (! isset($GLOBALS['db']) || ! strlen($GLOBALS['db'])) { // prepare for server related - $legend = sprintf( $GLOBALS['strRunSQLQueryOnServer'], + $legend = sprintf($GLOBALS['strRunSQLQueryOnServer'], htmlspecialchars( - $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['host'] ) ); - } elseif ( ! isset( $GLOBALS['table'] ) || ! strlen($GLOBALS['table']) ) { + $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['host'])); + } elseif (! isset($GLOBALS['table']) || ! strlen($GLOBALS['table'])) { // prepare for db related $db = $GLOBALS['db']; // if you want navigation: $strDBLink = '<a href="' . $GLOBALS['cfg']['DefaultTabDatabase'] - . '?' . PMA_generate_common_url( $db ) . '"'; - if ( $is_querywindow ) { + . '?' . PMA_generate_common_url($db) . '"'; + if ($is_querywindow) { $strDBLink .= ' target="_self"' . ' onclick="this.target=window.opener.frames[1].name"'; } $strDBLink .= '>' - . htmlspecialchars( $db ) . '</a>'; + . htmlspecialchars($db) . '</a>'; // else use - // $strDBLink = htmlspecialchars( $db ); - $legend = sprintf( $GLOBALS['strRunSQLQuery'], $strDBLink ); - if ( empty( $query ) ) { - $query = str_replace( '%d', - PMA_backquote( $db ), $GLOBALS['cfg']['DefaultQueryDatabase'] ); + // $strDBLink = htmlspecialchars($db); + $legend = sprintf($GLOBALS['strRunSQLQuery'], $strDBLink); + if (empty($query)) { + $query = str_replace('%d', + PMA_backquote($db), $GLOBALS['cfg']['DefaultQueryDatabase']); } } else { $table = $GLOBALS['table']; @@ -228,37 +230,37 @@ function PMA_sqlQueryFormInsert( $query = '', $is_querywindow = false ) { // we do a try_query here, because we could be in the query window, // trying to synchonize and the table has not yet been created $fields_list = PMA_DBI_fetch_result( - 'SHOW FULL COLUMNS FROM ' . PMA_backquote( $db ) - . '.' . PMA_backquote( $GLOBALS['table'] )); + 'SHOW FULL COLUMNS FROM ' . PMA_backquote($db) + . '.' . PMA_backquote($GLOBALS['table'])); $strDBLink = '<a href="' . $GLOBALS['cfg']['DefaultTabDatabase'] - . '?' . PMA_generate_common_url( $db ) . '"'; - if ( $is_querywindow ) { + . '?' . PMA_generate_common_url($db) . '"'; + if ($is_querywindow) { $strDBLink .= ' target="_self"' . ' onclick="this.target=window.opener.frames[1].name"'; } $strDBLink .= '>' - . htmlspecialchars( $db ) . '</a>'; + . htmlspecialchars($db) . '</a>'; // else use - // $strDBLink = htmlspecialchars( $db ); - $legend = sprintf( $GLOBALS['strRunSQLQuery'], $strDBLink ); - if ( empty( $query ) && count( $fields_list ) ) { + // $strDBLink = htmlspecialchars($db); + $legend = sprintf($GLOBALS['strRunSQLQuery'], $strDBLink); + if (empty($query) && count($fields_list)) { $field_names = array(); - foreach ( $fields_list as $field ) { + foreach ($fields_list as $field) { $field_names[] = PMA_backquote($field['Field']); } $query = - str_replace( '%d', PMA_backquote( $db ), - str_replace( '%t', PMA_backquote( $table ), - str_replace( '%f', - implode( ', ', $field_names ), - $GLOBALS['cfg']['DefaultQueryTable'] ) ) ); + str_replace('%d', PMA_backquote($db), + str_replace('%t', PMA_backquote($table), + str_replace('%f', + implode(', ', $field_names ), + $GLOBALS['cfg']['DefaultQueryTable']))); unset($field_names); } } - $legend .= ': ' . PMA_showMySQLDocu( 'SQL-Syntax', 'SELECT' ); + $legend .= ': ' . PMA_showMySQLDocu('SQL-Syntax', 'SELECT'); - if ( count( $fields_list ) ) { + if (count($fields_list)) { $sqlquerycontainer_id = 'sqlquerycontainer'; } else { $sqlquerycontainer_id = 'sqlquerycontainerfull'; @@ -277,17 +279,17 @@ function PMA_sqlQueryFormInsert( $query = '', $is_querywindow = false ) { .$auto_sel . $locking . '>' . $query . '</textarea>' . "\n"; echo '</div>' . "\n"; - if ( count( $fields_list ) ) { + if (count($fields_list)) { echo '<div id="tablefieldscontainer">' . "\n" .'<label>' . $GLOBALS['strFields'] . '</label>' . "\n" .'<select id="tablefields" name="dummy" ' .'size="' . ($GLOBALS['cfg']['TextareaRows'] - 2) . '" ' .'multiple="multiple" ondblclick="insertValueQuery()">' . "\n"; - foreach ( $fields_list as $field ) { + foreach ($fields_list as $field) { echo '<option value="' - .PMA_backquote( htmlspecialchars( $field['Field'] ) ) . '"'; - if ( isset( $field['Field'] ) && strlen($field['Field']) && isset($field['Comment']) ) { - echo ' title="' . htmlspecialchars( $field['Comment'] ) . '"'; + .PMA_backquote(htmlspecialchars($field['Field'])) . '"'; + if (isset($field['Field']) && strlen($field['Field']) && isset($field['Comment'])) { + echo ' title="' . htmlspecialchars($field['Comment']) . '"'; } echo '>' . htmlspecialchars( $field['Field'] ) . '</option>' . "\n"; } @@ -309,9 +311,9 @@ function PMA_sqlQueryFormInsert( $query = '', $is_querywindow = false ) { echo '<div class="clearfloat"></div>' . "\n"; echo '</div>' . "\n"; - if ( ! empty( $GLOBALS['cfg']['Bookmark'] ) + if (! empty($GLOBALS['cfg']['Bookmark']) && $GLOBALS['cfg']['Bookmark']['db'] - && $GLOBALS['cfg']['Bookmark']['table'] ) { + && $GLOBALS['cfg']['Bookmark']['table']) { ?> <div id="bookmarkoptions"> <div class="formelement"> @@ -341,7 +343,7 @@ function PMA_sqlQueryFormInsert( $query = '', $is_querywindow = false ) { echo '<fieldset id="queryboxfooter" class="tblFooters">' . "\n"; echo '<div class="formelement">' . "\n"; - if ( $is_querywindow ) { + if ($is_querywindow) { ?> <script type="text/javascript" language="javascript"> //<![CDATA[ @@ -382,9 +384,10 @@ function PMA_sqlQueryFormInsert( $query = '', $is_querywindow = false ) { * @uses count() * @uses htmlspecialchars() */ -function PMA_sqlQueryFormBookmark() { +function PMA_sqlQueryFormBookmark() +{ $bookmark_list = PMA_listBookmarks(isset($GLOBALS['db']) ? $GLOBALS['db'] : '', $GLOBALS['cfg']['Bookmark'] ); - if ( ! $bookmark_list || count( $bookmark_list ) < 1 ) { + if (! $bookmark_list || count($bookmark_list) < 1) { return; } @@ -394,16 +397,16 @@ function PMA_sqlQueryFormBookmark() { echo '<div class="formelement">'; echo '<select name="id_bookmark">' . "\n"; echo '<option value=""></option>' . "\n"; - foreach ( $bookmark_list as $key => $value ) { - echo '<option value="' . htmlspecialchars( $key ) . '">' - .htmlspecialchars( $value ) . '</option>' . "\n"; + foreach ($bookmark_list as $key => $value) { + echo '<option value="' . htmlspecialchars($key) . '">' + .htmlspecialchars($value) . '</option>' . "\n"; } // is required for correct display with styles/line height echo '</select> ' . "\n"; echo '</div>' . "\n"; echo '<div class="formelement">' . "\n"; echo $GLOBALS['strVar']; - if ( $GLOBALS['cfg']['ReplaceHelpImg'] ) { + if ($GLOBALS['cfg']['ReplaceHelpImg']) { echo ' <a href="./Documentation.html#faqbookmark"' .' target="documentation">' .'<img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 'b_help.png"' @@ -470,7 +473,7 @@ function PMA_sqlQueryFormBookmark() { * @uses PMA_CSDROPDOWN_CHARSET * @uses empty() */ -function PMA_sqlQueryFormUpload() { +function PMA_sqlQueryFormUpload(){ $errors = array (); $matcher = '@\.sql(\.(' . PMA_supportedDecompressions() . '))?$@'; // we allow only SQL here @@ -487,9 +490,9 @@ function PMA_sqlQueryFormUpload() { echo $GLOBALS['strLocationTextfile'] . '</legend>'; echo '<div class="formelement">'; echo '<input type="file" name="sql_file" class="textfield" /> '; - echo PMA_displayMaximumUploadSize( $GLOBALS['max_upload_size'] ); + echo PMA_displayMaximumUploadSize($GLOBALS['max_upload_size']); // some browsers should respect this :) - echo PMA_generateHiddenMaxFileSize( $GLOBALS['max_upload_size'] ) . "\n"; + echo PMA_generateHiddenMaxFileSize($GLOBALS['max_upload_size']) . "\n"; echo '</div>'; if ($files === FALSE) { @@ -514,25 +517,25 @@ function PMA_sqlQueryFormUpload() { && $GLOBALS['allow_recoding'] ) { echo $GLOBALS['strCharsetOfFile'] . "\n" . '<select name="charset_of_file" size="1">' . "\n"; - foreach( $GLOBALS['cfg']['AvailableCharsets'] as $temp_charset ) { + foreach ($GLOBALS['cfg']['AvailableCharsets'] as $temp_charset) { echo '<option value="' . $temp_charset . '"'; - if ( $temp_charset == $GLOBALS['charset'] ) { + if ($temp_charset == $GLOBALS['charset']) { echo ' selected="selected"'; } echo '>' . $temp_charset . '</option>' . "\n"; } echo '</select>' . "\n"; - } elseif ( PMA_MYSQL_INT_VERSION >= 40100 ) { + } elseif (PMA_MYSQL_INT_VERSION >= 40100) { echo $GLOBALS['strCharsetOfFile'] . "\n"; - echo PMA_generateCharsetDropdownBox( PMA_CSDROPDOWN_CHARSET, - 'charset_of_file', NULL, 'utf8', FALSE ); + echo PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_CHARSET, + 'charset_of_file', null, 'utf8', FALSE); } // end if (recoding) echo '<input type="submit" name="SQL" value="' . $GLOBALS['strGo'] .'" />' . "\n"; echo '<div class="clearfloat"></div>' . "\n"; echo '</fieldset>'; - foreach( $errors as $error => $message ) { + foreach ( $errors as $error => $message ) { echo '<div>' . $error . '</div>'; echo '<div>' . $message . '</div>'; } diff --git a/libraries/sqlparser.lib.php b/libraries/sqlparser.lib.php index 6bc9c13371..4a63294ebc 100644 --- a/libraries/sqlparser.lib.php +++ b/libraries/sqlparser.lib.php @@ -64,7 +64,7 @@ if ( ! defined( 'PMA_MINIMUM_COMMON' ) ) { global $timer; $t = $timer; - $arr[] = array('type' => $type, 'data' => $data , 'time' => $t); + $arr[] = array('type' => $type, 'data' => $data, 'time' => $t); $timer = microtime(); $arrsize++; } // end of the "PMA_SQP_arrayAdd()" function @@ -77,7 +77,8 @@ if ( ! defined( 'PMA_MINIMUM_COMMON' ) ) { * @access public */ // Added, Robbat2 - 13 Janurary 2003, 2:59PM - function PMA_SQP_resetError() { + function PMA_SQP_resetError() + { global $SQP_errorString; $SQP_errorString = ''; unset($SQP_errorString); @@ -91,7 +92,8 @@ if ( ! defined( 'PMA_MINIMUM_COMMON' ) ) { * @access public */ // Added, Robbat2 - 13 Janurary 2003, 2:59PM - function PMA_SQP_getErrorString() { + function PMA_SQP_getErrorString() + { global $SQP_errorString; return isset($SQP_errorString) ? $SQP_errorString : ''; } @@ -104,7 +106,8 @@ if ( ! defined( 'PMA_MINIMUM_COMMON' ) ) { * @access public */ // Added, Robbat2 - 13 Janurary 2003, 2:59PM - function PMA_SQP_isError() { + function PMA_SQP_isError() + { global $SQP_errorString; return isset($SQP_errorString) && !empty($SQP_errorString); } @@ -320,7 +323,7 @@ if ( ! defined( 'PMA_MINIMUM_COMMON' ) ) { if (($pos < $len) && PMA_STR_charIsEscaped($sql, $pos)) { $pos ++; continue; - } else if (($pos + 1 < $len) && (PMA_substr($sql, $pos, 1) == $quotetype) && (PMA_substr($sql, $pos + 1, 1) == $quotetype)) { + } elseif (($pos + 1 < $len) && (PMA_substr($sql, $pos, 1) == $quotetype) && (PMA_substr($sql, $pos + 1, 1) == $quotetype)) { $pos = $pos + 2; continue; } else { @@ -394,11 +397,15 @@ if ( ! defined( 'PMA_MINIMUM_COMMON' ) ) { if ($is_hex_digit) { $count2++; $pos = strspn($sql, '0123456789abcdefABCDEF', $count2); - if ($pos > $count2) $count2 = $pos; + if ($pos > $count2) { + $count2 = $pos; + } unset($pos); } elseif ($is_digit) { $pos = strspn($sql, '0123456789', $count2); - if ($pos > $count2) $count2 = $pos; + if ($pos > $count2) { + $count2 = $pos; + } unset($pos); } } @@ -451,13 +458,12 @@ if ( ! defined( 'PMA_MINIMUM_COMMON' ) ) { $type = 'digit'; if ($is_float_digit) { $type .= '_float'; - } else if ($is_hex_digit) { + } elseif ($is_hex_digit) { $type .= '_hex'; } else { $type .= '_integer'; } - } - else { + } else { if ($is_sql_variable != FALSE) { $type = 'alpha_variable'; } else { @@ -499,12 +505,10 @@ if ( ! defined( 'PMA_MINIMUM_COMMON' ) ) { break; } PMA_SQP_arrayAdd($sql_array, 'punct' . $t_suffix, $punct_data, $arraysize); - } - else if (PMA_STR_binarySearchInArr($punct_data, $allpunct_list_pair, $allpunct_list_pair_size)) { + } elseif (PMA_STR_binarySearchInArr($punct_data, $allpunct_list_pair, $allpunct_list_pair_size)) { // Ok, we have one of the valid combined punct expressions PMA_SQP_arrayAdd($sql_array, 'punct', $punct_data, $arraysize); - } - else { + } else { // Bad luck, lets split it up more $first = $punct_data[0]; $first2 = $punct_data[0] . $punct_data[1]; @@ -513,17 +517,17 @@ if ( ! defined( 'PMA_MINIMUM_COMMON' ) ) { if (($first == ',') || ($first == ';') || ($first == '.') || ($first == '*')) { $count2 = $count1 + 1; $punct_data = $first; - } else if (($last2 == '/*') || (($last2 == '--') && ($count2 == $len || PMA_substr($sql, $count2, 1) <= ' ') )) { + } elseif (($last2 == '/*') || (($last2 == '--') && ($count2 == $len || PMA_substr($sql, $count2, 1) <= ' ') )) { $count2 -= 2; $punct_data = PMA_substr($sql, $count1, $count2 - $count1); - } else if (($last == '-') || ($last == '+') || ($last == '!')) { + } elseif (($last == '-') || ($last == '+') || ($last == '!')) { $count2--; $punct_data = PMA_substr($sql, $count1, $count2 - $count1); // TODO: for negation operator, split in 2 tokens ? // "select x&~1 from t" // becomes "select x & ~ 1 from t" ? - } else if ($last != '~') { + } elseif ($last != '~') { $debugstr = $GLOBALS['strSQPBugUnknownPunctuation'] . ' @ ' . ($count1+1) . "\n" . 'STR: ' . htmlspecialchars($punct_data); PMA_SQP_throwError($debugstr, $sql); @@ -531,7 +535,7 @@ if ( ! defined( 'PMA_MINIMUM_COMMON' ) ) { } PMA_SQP_arrayAdd($sql_array, 'punct', $punct_data, $arraysize); continue; - } // end if... else if... else + } // end if... elseif... else continue; } @@ -547,116 +551,116 @@ if ( ! defined( 'PMA_MINIMUM_COMMON' ) ) { if ($arraysize > 0) { - $t_next = $sql_array[0]['type']; - $t_prev = ''; - $t_bef_prev = ''; - $t_cur = ''; - $d_next = $sql_array[0]['data']; - $d_prev = ''; - $d_bef_prev = ''; - $d_cur = ''; - $d_next_upper = $t_next == 'alpha' ? strtoupper($d_next) : $d_next; - $d_prev_upper = ''; - $d_bef_prev_upper = ''; - $d_cur_upper = ''; + $t_next = $sql_array[0]['type']; + $t_prev = ''; + $t_bef_prev = ''; + $t_cur = ''; + $d_next = $sql_array[0]['data']; + $d_prev = ''; + $d_bef_prev = ''; + $d_cur = ''; + $d_next_upper = $t_next == 'alpha' ? strtoupper($d_next) : $d_next; + $d_prev_upper = ''; + $d_bef_prev_upper = ''; + $d_cur_upper = ''; } for ($i = 0; $i < $arraysize; $i++) { - $t_bef_prev = $t_prev; - $t_prev = $t_cur; - $t_cur = $t_next; - $d_bef_prev = $d_prev; - $d_prev = $d_cur; - $d_cur = $d_next; - $d_bef_prev_upper = $d_prev_upper; - $d_prev_upper = $d_cur_upper; - $d_cur_upper = $d_next_upper; - if (($i + 1) < $arraysize) { - $t_next = $sql_array[$i + 1]['type']; - $d_next = $sql_array[$i + 1]['data']; - $d_next_upper = $t_next == 'alpha' ? strtoupper($d_next) : $d_next; - } else { - $t_next = ''; - $d_next = ''; - $d_next_upper = ''; - } - - //DEBUG echo "[prev: <b>".$d_prev."</b> ".$t_prev."][cur: <b>".$d_cur."</b> ".$t_cur."][next: <b>".$d_next."</b> ".$t_next."]<br />"; - - if ($t_cur == 'alpha') { - $t_suffix = '_identifier'; - if (($t_next == 'punct_qualifier') || ($t_prev == 'punct_qualifier')) { - $t_suffix = '_identifier'; - } else if (($t_next == 'punct_bracket_open_round') - && PMA_STR_binarySearchInArr($d_cur_upper, $PMA_SQPdata_function_name, $PMA_SQPdata_function_name_cnt)) { - // FIXME-2005-10-16: in the case of a CREATE TABLE containing a TIMESTAMP, - // since TIMESTAMP() is also a function, it's found here and - // the token is wrongly marked as alpha_functionName. But we - // compensate for this when analysing for timestamp_not_null - // later in this script. - $t_suffix = '_functionName'; - } else if (PMA_STR_binarySearchInArr($d_cur_upper, $PMA_SQPdata_column_type, $PMA_SQPdata_column_type_cnt)) { - $t_suffix = '_columnType'; - - // Temporary fix for BUG #621357 - //TODO FIX PROPERLY NEEDS OVERHAUL OF SQL TOKENIZER - if ($d_cur_upper == 'SET' && $t_next != 'punct_bracket_open_round') { - $t_suffix = '_reservedWord'; - } - //END OF TEMPORARY FIX - - // CHARACTER is a synonym for CHAR, but can also be meant as - // CHARACTER SET. In this case, we have a reserved word. - if ($d_cur_upper == 'CHARACTER' && $d_next_upper == 'SET') { - $t_suffix = '_reservedWord'; - } - - // experimental - // current is a column type, so previous must not be - // a reserved word but an identifier - // CREATE TABLE SG_Persons (first varchar(64)) - - //if ($sql_array[$i-1]['type'] =='alpha_reservedWord') { - // $sql_array[$i-1]['type'] = 'alpha_identifier'; - //} - - } else if (PMA_STR_binarySearchInArr($d_cur_upper, $PMA_SQPdata_reserved_word, $PMA_SQPdata_reserved_word_cnt)) { - $t_suffix = '_reservedWord'; - } else if (PMA_STR_binarySearchInArr($d_cur_upper, $PMA_SQPdata_column_attrib, $PMA_SQPdata_column_attrib_cnt)) { - $t_suffix = '_columnAttrib'; - // INNODB is a MySQL table type, but in "SHOW INNODB STATUS", - // it should be regarded as a reserved word. - if ($d_cur_upper == 'INNODB' && $d_prev_upper == 'SHOW' && $d_next_upper == 'STATUS') { - $t_suffix = '_reservedWord'; - } - - if ($d_cur_upper == 'DEFAULT' && $d_next_upper == 'CHARACTER') { - $t_suffix = '_reservedWord'; - } - // Binary as character set - if ($d_cur_upper == 'BINARY' && ( - ($d_bef_prev_upper == 'CHARACTER' && $d_prev_upper == 'SET') - || ($d_bef_prev_upper == 'SET' && $d_prev_upper == '=') - || ($d_bef_prev_upper == 'CHARSET' && $d_prev_upper == '=') - || $d_prev_upper == 'CHARSET' - ) && PMA_STR_binarySearchInArr($d_cur, $mysql_charsets, count($mysql_charsets))) { - $t_suffix = '_charset'; - } - } elseif (PMA_STR_binarySearchInArr($d_cur, $mysql_charsets, $mysql_charsets_count) - || PMA_STR_binarySearchInArr($d_cur, $mysql_collations_flat, $mysql_collations_count) - || ($d_cur{0} == '_' && PMA_STR_binarySearchInArr(substr($d_cur, 1), $mysql_charsets, $mysql_charsets_count))) { - $t_suffix = '_charset'; + $t_bef_prev = $t_prev; + $t_prev = $t_cur; + $t_cur = $t_next; + $d_bef_prev = $d_prev; + $d_prev = $d_cur; + $d_cur = $d_next; + $d_bef_prev_upper = $d_prev_upper; + $d_prev_upper = $d_cur_upper; + $d_cur_upper = $d_next_upper; + if (($i + 1) < $arraysize) { + $t_next = $sql_array[$i + 1]['type']; + $d_next = $sql_array[$i + 1]['data']; + $d_next_upper = $t_next == 'alpha' ? strtoupper($d_next) : $d_next; } else { - // Do nothing + $t_next = ''; + $d_next = ''; + $d_next_upper = ''; } - // check if present in the list of forbidden words - if ($t_suffix == '_reservedWord' && PMA_STR_binarySearchInArr($d_cur_upper, $PMA_SQPdata_forbidden_word, $PMA_SQPdata_forbidden_word_cnt)) { - $sql_array[$i]['forbidden'] = TRUE; - } else { - $sql_array[$i]['forbidden'] = FALSE; + + //DEBUG echo "[prev: <b>".$d_prev."</b> ".$t_prev."][cur: <b>".$d_cur."</b> ".$t_cur."][next: <b>".$d_next."</b> ".$t_next."]<br />"; + + if ($t_cur == 'alpha') { + $t_suffix = '_identifier'; + if (($t_next == 'punct_qualifier') || ($t_prev == 'punct_qualifier')) { + $t_suffix = '_identifier'; + } elseif (($t_next == 'punct_bracket_open_round') + && PMA_STR_binarySearchInArr($d_cur_upper, $PMA_SQPdata_function_name, $PMA_SQPdata_function_name_cnt)) { + // FIXME-2005-10-16: in the case of a CREATE TABLE containing a TIMESTAMP, + // since TIMESTAMP() is also a function, it's found here and + // the token is wrongly marked as alpha_functionName. But we + // compensate for this when analysing for timestamp_not_null + // later in this script. + $t_suffix = '_functionName'; + } elseif (PMA_STR_binarySearchInArr($d_cur_upper, $PMA_SQPdata_column_type, $PMA_SQPdata_column_type_cnt)) { + $t_suffix = '_columnType'; + + // Temporary fix for BUG #621357 + //TODO FIX PROPERLY NEEDS OVERHAUL OF SQL TOKENIZER + if ($d_cur_upper == 'SET' && $t_next != 'punct_bracket_open_round') { + $t_suffix = '_reservedWord'; + } + //END OF TEMPORARY FIX + + // CHARACTER is a synonym for CHAR, but can also be meant as + // CHARACTER SET. In this case, we have a reserved word. + if ($d_cur_upper == 'CHARACTER' && $d_next_upper == 'SET') { + $t_suffix = '_reservedWord'; + } + + // experimental + // current is a column type, so previous must not be + // a reserved word but an identifier + // CREATE TABLE SG_Persons (first varchar(64)) + + //if ($sql_array[$i-1]['type'] =='alpha_reservedWord') { + // $sql_array[$i-1]['type'] = 'alpha_identifier'; + //} + + } elseif (PMA_STR_binarySearchInArr($d_cur_upper, $PMA_SQPdata_reserved_word, $PMA_SQPdata_reserved_word_cnt)) { + $t_suffix = '_reservedWord'; + } elseif (PMA_STR_binarySearchInArr($d_cur_upper, $PMA_SQPdata_column_attrib, $PMA_SQPdata_column_attrib_cnt)) { + $t_suffix = '_columnAttrib'; + // INNODB is a MySQL table type, but in "SHOW INNODB STATUS", + // it should be regarded as a reserved word. + if ($d_cur_upper == 'INNODB' && $d_prev_upper == 'SHOW' && $d_next_upper == 'STATUS') { + $t_suffix = '_reservedWord'; + } + + if ($d_cur_upper == 'DEFAULT' && $d_next_upper == 'CHARACTER') { + $t_suffix = '_reservedWord'; + } + // Binary as character set + if ($d_cur_upper == 'BINARY' && ( + ($d_bef_prev_upper == 'CHARACTER' && $d_prev_upper == 'SET') + || ($d_bef_prev_upper == 'SET' && $d_prev_upper == '=') + || ($d_bef_prev_upper == 'CHARSET' && $d_prev_upper == '=') + || $d_prev_upper == 'CHARSET' + ) && PMA_STR_binarySearchInArr($d_cur, $mysql_charsets, count($mysql_charsets))) { + $t_suffix = '_charset'; + } + } elseif (PMA_STR_binarySearchInArr($d_cur, $mysql_charsets, $mysql_charsets_count) + || PMA_STR_binarySearchInArr($d_cur, $mysql_collations_flat, $mysql_collations_count) + || ($d_cur{0} == '_' && PMA_STR_binarySearchInArr(substr($d_cur, 1), $mysql_charsets, $mysql_charsets_count))) { + $t_suffix = '_charset'; + } else { + // Do nothing + } + // check if present in the list of forbidden words + if ($t_suffix == '_reservedWord' && PMA_STR_binarySearchInArr($d_cur_upper, $PMA_SQPdata_forbidden_word, $PMA_SQPdata_forbidden_word_cnt)) { + $sql_array[$i]['forbidden'] = TRUE; + } else { + $sql_array[$i]['forbidden'] = FALSE; + } + $sql_array[$i]['type'] .= $t_suffix; } - $sql_array[$i]['type'] .= $t_suffix; - } } // end for // Stores the size of the array inside the array, as count() is a slow @@ -684,7 +688,7 @@ if ( ! defined( 'PMA_MINIMUM_COMMON' ) ) { return TRUE; } else { if (strpos($whatWeWant, $typeSeperator) === FALSE) { - return strncmp($whatWeWant, $toCheck , strpos($toCheck, $typeSeperator)) == 0; + return strncmp($whatWeWant, $toCheck, strpos($toCheck, $typeSeperator)) == 0; } else { return FALSE; } @@ -703,7 +707,9 @@ if ( ! defined( 'PMA_MINIMUM_COMMON' ) ) { */ function PMA_SQP_analyze($arr) { - if ($arr == array()) return array(); + if ($arr == array()) { + return array(); + } $result = array(); $size = $arr['len']; $subresult = array( @@ -959,7 +965,7 @@ if ( ! defined( 'PMA_MINIMUM_COMMON' ) ) { // ============================================================== if ($arr[$i]['type'] == 'alpha_reservedWord' // && $arr[$i]['forbidden'] == FALSE) { - ){ + ) { // We don't know what type of query yet, so run this if ($subresult['querytype'] == '') { $subresult['querytype'] = strtoupper($arr[$i]['data']); @@ -1019,13 +1025,13 @@ if ( ! defined( 'PMA_MINIMUM_COMMON' ) ) { //TODO: check embedded double quotes or backticks? // and/or remove just the first and last character? case 'quote_backtick': - $identifier = str_replace('`','',$arr[$i]['data']); + $identifier = str_replace('`', '', $arr[$i]['data']); break; case 'quote_double': - $identifier = str_replace('"','',$arr[$i]['data']); + $identifier = str_replace('"', '', $arr[$i]['data']); break; case 'quote_single': - $identifier = str_replace("'","",$arr[$i]['data']); + $identifier = str_replace("'", "", $arr[$i]['data']); break; } // end switch @@ -1243,9 +1249,9 @@ if ( ! defined( 'PMA_MINIMUM_COMMON' ) ) { // but it's a modifier of the GROUP_CONCAT so // it's not the real end of table refs if (($i == $size-1) - || ($arr[$i]['type'] == 'alpha_reservedWord' - && !$in_group_concat - && PMA_STR_binarySearchInArr($upper_data, $words_ending_table_ref, $words_ending_table_ref_cnt))) { + || ($arr[$i]['type'] == 'alpha_reservedWord' + && !$in_group_concat + && PMA_STR_binarySearchInArr($upper_data, $words_ending_table_ref, $words_ending_table_ref_cnt))) { $seen_end_of_table_ref = TRUE; // to be able to save the last table ref, but do not // set it true if we found a word like "ON" that has @@ -1726,7 +1732,7 @@ if ( ! defined( 'PMA_MINIMUM_COMMON' ) ) { if ($arr[$i]['type'] == 'quote_backtick') { // remove backquotes - $identifier = str_replace('`','',$arr[$i]['data']); + $identifier = str_replace('`', '', $arr[$i]['data']); } else { $identifier = $arr[$i]['data']; } @@ -1763,7 +1769,7 @@ if ( ! defined( 'PMA_MINIMUM_COMMON' ) ) { } else { // for MySQL 4.0.16, identifier is // `table` or `db.table` - $db_table = explode('.',$identifier); + $db_table = explode('.', $identifier); if (isset($db_table[1])) { $foreign[$foreign_key_number]['ref_db_name'] = $db_table[0]; $foreign[$foreign_key_number]['ref_table_name'] = $db_table[1]; @@ -1978,7 +1984,7 @@ if ( ! defined( 'PMA_MINIMUM_COMMON' ) ) { // array_push($typearr, $arr[$i + 1]['type']); $typearr[4] = $arr[$i + 1]['type']; } else { - //array_push($typearr, NULL); + //array_push($typearr, null); $typearr[4] = ''; } diff --git a/libraries/sqlvalidator.class.php b/libraries/sqlvalidator.class.php index e6aab9cda2..26329779c9 100644 --- a/libraries/sqlvalidator.class.php +++ b/libraries/sqlvalidator.class.php @@ -54,8 +54,8 @@ if (!function_exists('class_exists') || !class_exists('SOAP_Client')) { var $connection_technology_version; var $interactive; - var $service_link = NULL; - var $session_data = NULL; + var $service_link = null; + var $session_data = null; /** @@ -103,7 +103,7 @@ if (!function_exists('class_exists') || !class_exists('SOAP_Client')) { $interactive) { $use_array = array( "a_userName" => $username, "a_password" => $password, "a_callingProgram" => $calling_program, "a_callingProgramVersion" => $calling_program_version, "a_targetDbms" => $target_dbms, "a_targetDbmsVersion" => $target_dbms_version, "a_connectionTechnology" => $connection_technology, "a_connectionTechnologyVersion" => $connection_technology_version, "a_interactive" => $interactive); - $ret = $obj->call("openSession",$use_array); + $ret = $obj->call("openSession", $use_array); // This is the old version that needed the overload extension /* $ret = $obj->openSession($username, $password, @@ -131,7 +131,7 @@ if (!function_exists('class_exists') || !class_exists('SOAP_Client')) { function _validateSQL($obj, $session, $sql, $method) { $use_array = array("a_sessionId" => $session->sessionId, "a_sessionKey" => $session->sessionKey, "a_SQL" => $sql, "a_resultType" => $this->output_type); - $res = $obj->call("validateSQL",$use_array); + $res = $obj->call("validateSQL", $use_array); // This is the old version that needed the overload extension // $res = $obj->validateSQL($session->sessionId, $session->sessionKey, $sql, $this->output_type); @@ -185,8 +185,8 @@ if (!function_exists('class_exists') || !class_exists('SOAP_Client')) { $this->connection_technology_version = phpversion(); $this->interactive = 1; - $this->service_link = NULL; - $this->session_data = NULL; + $this->service_link = null; + $this->session_data = null; } // end of the "PMA_SQLValidator()" function @@ -347,7 +347,7 @@ if (!function_exists('class_exists') || !class_exists('SOAP_Client')) { $this->connection_technology, $this->connection_technology_version, $this->interactive); - if (isset($this->session_data) && ($this->session_data != NULL) + if (isset($this->session_data) && ($this->session_data != null) && ($this->session_data->target != $this->url)) { // Reopens the service on the new URL that was provided $url = $this->session_data->target; diff --git a/libraries/string.lib.php b/libraries/string.lib.php index 76329e14e0..649e8b5260 100644 --- a/libraries/string.lib.php +++ b/libraries/string.lib.php @@ -371,7 +371,7 @@ function PMA_STR_binarySearchInArr($str, $arr, $arrsize) $res = strcmp($str, $arr[$mid]); if ($res == 0) { $found = TRUE; - } else if ($res < 0) { + } elseif ($res < 0) { $top = $mid - 1; } else { $bottom = $mid + 1; diff --git a/libraries/tbl_indexes.lib.php b/libraries/tbl_indexes.lib.php index 16f5953acc..93449b8b17 100644 --- a/libraries/tbl_indexes.lib.php +++ b/libraries/tbl_indexes.lib.php @@ -60,14 +60,14 @@ function PMA_check_indexes($idx_collection, $table = true) { return $output; } - foreach($idx_collection['ALL'] AS $w_keyname => $w_count) { + foreach ($idx_collection['ALL'] AS $w_keyname => $w_count) { if (isset($idx_collection['PRIMARY'][$w_keyname]) && (isset($idx_collection['INDEX'][$w_keyname]) || isset($idx_collection['UNIQUE'][$w_keyname]))) { $output .= PMA_index_warning(sprintf($GLOBALS['strIndexWarningPrimary'], htmlspecialchars($w_keyname)), $table); } elseif (isset($idx_collection['UNIQUE'][$w_keyname]) && isset($idx_collection['INDEX'][$w_keyname])) { $output .= PMA_index_warning(sprintf($GLOBALS['strIndexWarningUnique'], htmlspecialchars($w_keyname)), $table); } - foreach($index_types AS $index_type) { + foreach ($index_types AS $index_type) { if (isset($idx_collection[$index_type][$w_keyname]) && $idx_collection[$index_type][$w_keyname] > 1) { $output .= PMA_index_warning(sprintf($GLOBALS['strIndexWarningMultiple'], $index_type, htmlspecialchars($w_keyname)), $table); } diff --git a/libraries/tbl_move_copy.php b/libraries/tbl_move_copy.php index de3b9a886b..f28d91e2eb 100644 --- a/libraries/tbl_move_copy.php +++ b/libraries/tbl_move_copy.php @@ -169,7 +169,7 @@ function PMA_table_move_copy($source_db, $source_table, $target_db, $target_tabl for ($j = $i; $j < $cnt; $j++) { if ($parsed_sql[$j]['type'] == 'alpha_reservedWord' - && strtoupper($parsed_sql[$j]['data']) == 'CONSTRAINT') { + && strtoupper($parsed_sql[$j]['data']) == 'CONSTRAINT') { if ($parsed_sql[$j+1]['type'] == 'quote_backtick') { $parsed_sql[$j+1]['data'] = ''; } diff --git a/libraries/tbl_properties.inc.php b/libraries/tbl_properties.inc.php index 0c36231dbc..b6d96b3d6b 100644 --- a/libraries/tbl_properties.inc.php +++ b/libraries/tbl_properties.inc.php @@ -4,7 +4,7 @@ // Check parameters require_once('./libraries/common.lib.php'); -PMA_checkParameters(array('db','table','action','num_fields')); +PMA_checkParameters(array('db', 'table', 'action', 'num_fields')); // Get available character sets and storage engines @@ -50,8 +50,7 @@ if ($action == 'tbl_create.php') { ?> <input type="hidden" name="reload" value="1" /> <?php -} -elseif ($action == 'tbl_addfield.php') { +} elseif ($action == 'tbl_addfield.php') { ?> <input type="hidden" name="field_where" value="<?php echo $field_where; ?>" /> <input type="hidden" name="after_field" value="<?php echo $after_field; ?>" /> @@ -244,8 +243,7 @@ for ( $i = 0 ; $i <= $num_fields; $i++ ) { if (empty($row['Type'])) { $row['Type'] = ''; $type = ''; - } - else { + } else { $type = $row['Type']; } // set or enum types: slashes single quotes inside options @@ -323,7 +321,7 @@ for ( $i = 0 ; $i <= $num_fields; $i++ ) { $ci++; if (PMA_MYSQL_INT_VERSION >= 40100) { - $tmp_collation = empty($row['Collation']) ? NULL : $row['Collation']; + $tmp_collation = empty($row['Collation']) ? null : $row['Collation']; $content_cells[$i][$ci] = PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION, 'field_collation[]', 'field_' . $i . '_' . ($ci - $ci_offset), $tmp_collation, FALSE); unset($tmp_collation); $ci++; @@ -403,7 +401,7 @@ for ( $i = 0 ; $i <= $num_fields; $i++ ) { $ci++; if (isset($row) - && !isset($row['Default']) && isset($row['Null']) && $row['Null'] == 'YES') { + && !isset($row['Default']) && isset($row['Null']) && $row['Null'] == 'YES') { $row['Default'] = 'NULL'; } @@ -613,7 +611,7 @@ var odd_row = <?php echo $odd_row; ?>; function addField() { var new_fields = document.getElementById('added_fields').value; var new_field_container = document.getElementById('table_columns'); - var new_field = '<?php echo preg_replace( '°\s+°', ' ', preg_replace( '°\'°', '\\\'', $new_field ) ); ?>'; + var new_field = '<?php echo preg_replace( '�\s+�', ' ', preg_replace( '�\'�', '\\\'', $new_field ) ); ?>'; var i = 0; for ( i = 0; i < new_fields; i++ ) { if ( odd_row ) { @@ -653,13 +651,13 @@ if ($action == 'tbl_create.php') { </td> <td width="25"> </td> <td> -<?php echo PMA_generateEnginesDropdown('tbl_type', NULL, FALSE, (isset($GLOBALS['tbl_type']) ? $GLOBALS['tbl_type'] : NULL), 3); ?> +<?php echo PMA_generateEnginesDropdown('tbl_type', null, FALSE, (isset($GLOBALS['tbl_type']) ? $GLOBALS['tbl_type'] : null), 3); ?> </td> <?php if ( PMA_MYSQL_INT_VERSION >= 40100 ) { echo ' <td width="25"> </td>' . "\n" . ' <td>' . "\n" - . PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION, 'tbl_collation', NULL, (isset($tbl_collation) ? $tbl_collation : NULL), FALSE, 3) + . PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION, 'tbl_collation', null, (isset($tbl_collation) ? $tbl_collation : null), FALSE, 3) . ' </td>' . "\n"; } ?> diff --git a/libraries/tbl_properties_common.php b/libraries/tbl_properties_common.php index 17a34e2b20..b182f0c13e 100644 --- a/libraries/tbl_properties_common.php +++ b/libraries/tbl_properties_common.php @@ -10,7 +10,7 @@ require_once('./libraries/common.lib.php'); require_once('./libraries/bookmark.lib.php'); // Check parameters -PMA_checkParameters(array('db','table')); +PMA_checkParameters(array('db', 'table')); if ( PMA_MYSQL_INT_VERSION >= 50002 && $db === 'information_schema' ) { $db_is_information_schema = true; diff --git a/libraries/tbl_properties_links.inc.php b/libraries/tbl_properties_links.inc.php index 7e1b6fbcc8..dbfe7943c5 100644 --- a/libraries/tbl_properties_links.inc.php +++ b/libraries/tbl_properties_links.inc.php @@ -66,7 +66,7 @@ $tabs['export']['args']['single_table'] = 'true'; $tabs['export']['text'] = $strExport; /** - * Don't display , "Import", "Operations" and "Empty" + * Don't display "Import", "Operations" and "Empty" * for views and information_schema */ if ( ! $tbl_is_view && ! (isset($db_is_information_schema) && $db_is_information_schema )) { diff --git a/libraries/tbl_replace_fields.inc.php b/libraries/tbl_replace_fields.inc.php index 716a39a3a9..ba9b68c88b 100644 --- a/libraries/tbl_replace_fields.inc.php +++ b/libraries/tbl_replace_fields.inc.php @@ -9,7 +9,7 @@ require_once('./libraries/common.lib.php'); -PMA_checkParameters(array('db','encoded_key')); +PMA_checkParameters(array('db', 'encoded_key')); // f i e l d u p l o a d e d f r o m a f i l e @@ -112,8 +112,11 @@ if (!$check_stop) { // f i e l d v a l u e i n t h e f o r m - if (isset($me_fields_type[$encoded_key])) $type = $me_fields_type[$encoded_key]; - else $type = ''; + if (isset($me_fields_type[$encoded_key])) { + $type = $me_fields_type[$encoded_key]; + } else { + $type = ''; + } $f = 'field_' . md5($key); $t_fval = (isset($$f) ? $$f : null); diff --git a/libraries/transformations.lib.php b/libraries/transformations.lib.php index 258df9bf78..a342e85f90 100644 --- a/libraries/transformations.lib.php +++ b/libraries/transformations.lib.php @@ -19,7 +19,7 @@ function PMA_transformation_getOptions($string) { // strip possible slashes to behave like documentation says $result = array(); - foreach($transform_options as $val) { + foreach ($transform_options as $val) { $result[] = stripslashes($val); } return $result; @@ -59,7 +59,7 @@ function PMA_getAvailableMIMEtypes() { $stack['transformation'][] = $mimetype . ': ' . $base[1]; $stack['transformation_file'][] = $file; - } else if (preg_match('|^.*\.inc\.php$|', trim($file), $match)) { + } elseif (preg_match('|^.*\.inc\.php$|', trim($file), $match)) { // File is a plain mimetype, no functions. $base = str_replace('.inc.php', '', $file); @@ -161,7 +161,7 @@ function PMA_setMIME($db, $table, $key, $mimetype, $transformation, $transformat . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'' . ' AND column_name = \'' . PMA_sqlAddslashes($key) . '\''; } - } else if (strlen($mimetype) > 0 || strlen($transformation) > 0 || strlen($transformation_options) > 0) { + } elseif (strlen($mimetype) > 0 || strlen($transformation) > 0 || strlen($transformation_options) > 0) { $upd_query = 'INSERT INTO ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . ' (db_name, table_name, column_name, mimetype, transformation, transformation_options) ' . ' VALUES(' diff --git a/libraries/unzip.lib.php b/libraries/unzip.lib.php index ad3096b743..df3264f495 100644 --- a/libraries/unzip.lib.php +++ b/libraries/unzip.lib.php @@ -106,8 +106,9 @@ * @uses SimpleUnzip::ReadFile() Opens file on new if specified * @since 1.0 */ - function SimpleUnzip($in_FileName = '') { - if($in_FileName !== '') { + function SimpleUnzip($in_FileName = '') + { + if ($in_FileName !== '') { SimpleUnzip::ReadFile($in_FileName); } } // end of the 'SimpleUnzip' constructor @@ -120,7 +121,8 @@ * @uses $Entries * @since 1.0 */ - function Count() { + function Count() + { return count($this->Entries); } // end of the 'Count()' method @@ -133,7 +135,8 @@ * @access public * @since 1.0 */ - function GetData($in_Index) { + function GetData($in_Index) + { return $this->Entries[$in_Index]->Data; } // end of the 'GetData()' method @@ -146,7 +149,8 @@ * @access public * @since 1.0 */ - function GetEntry($in_Index) { + function GetEntry($in_Index) + { return $this->Entries[$in_Index]; } // end of the 'GetEntry()' method @@ -159,7 +163,8 @@ * @access public * @since 1.0 */ - function GetError($in_Index) { + function GetError($in_Index) + { return $this->Entries[$in_Index]->Error; } // end of the 'GetError()' method @@ -172,7 +177,8 @@ * @access public * @since 1.0 */ - function GetErrorMsg($in_Index) { + function GetErrorMsg($in_Index) + { return $this->Entries[$in_Index]->ErrorMsg; } // end of the 'GetErrorMsg()' method @@ -185,7 +191,8 @@ * @access public * @since 1.0 */ - function GetName($in_Index) { + function GetName($in_Index) + { return $this->Entries[$in_Index]->Name; } // end of the 'GetName()' method @@ -198,7 +205,8 @@ * @access public * @since 1.0 */ - function GetPath($in_Index) { + function GetPath($in_Index) + { return $this->Entries[$in_Index]->Path; } // end of the 'GetPath()' method @@ -211,7 +219,8 @@ * @access public * @since 1.0 */ - function GetTime($in_Index) { + function GetTime($in_Index) + { return $this->Entries[$in_Index]->Time; } // end of the 'GetTime()' method @@ -224,7 +233,8 @@ * @access public * @since 1.0 */ - function ReadFile($in_FileName) { + function ReadFile($in_FileName) + { $this->Entries = array(); // Get file parameters @@ -261,7 +271,7 @@ array_shift($aE); // Loop through the entries - foreach($aE as $vZ) { + foreach ($aE as $vZ) { $aI = array(); $aI['E'] = 0; $aI['EM'] = ''; @@ -272,7 +282,7 @@ $nF = $aP['FNL']; // Special case : value block after the compressed data - if($aP['GPF'] & 0x0008) { + if ($aP['GPF'] & 0x0008) { $aP1 = unpack('V1CRC/V1CS/V1UCS', substr($vZ, -12)); $aP['CRC'] = $aP1['CRC']; @@ -285,7 +295,7 @@ // Getting stored filename $aI['N'] = substr($vZ, 26, $nF); - if(substr($aI['N'], -1) == '/') { + if (substr($aI['N'], -1) == '/') { // is a directory entry - will be skipped continue; } @@ -297,16 +307,14 @@ $vZ = substr($vZ, 26 + $nF); - if(strlen($vZ) != $aP['CS']) { + if (strlen($vZ) != $aP['CS']) { $aI['E'] = 1; $aI['EM'] = 'Compressed size is not equal with the value in header information.'; - } - else { - if($bE) { + } else { + if ($bE) { $aI['E'] = 5; $aI['EM'] = 'File is encrypted, which is not supported from this class.'; - } - else { + } else { switch($aP['CM']) { case 0: // Stored // Here is nothing to do, the file ist flat. @@ -318,21 +326,19 @@ case 12: // BZIP2 // 2003-12-02 - HB > - if(! extension_loaded('bz2')) { - if(strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') { + if (! extension_loaded('bz2')) { + if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') { @dl('php_bz2.dll'); - } - else { + } else { @dl('bz2.so'); } } - if(extension_loaded('bz2')) { + if (extension_loaded('bz2')) { // 2003-12-02 - HB < $vZ = bzdecompress($vZ); // 2003-12-02 - HB > - } - else { + } else { $aI['E'] = 7; $aI['EM'] = "PHP BZIP2 extension not available."; } @@ -346,19 +352,17 @@ } // 2003-12-02 - HB > - if(! $aI['E']) { + if (! $aI['E']) { // 2003-12-02 - HB < - if($vZ === FALSE) { + if ($vZ === FALSE) { $aI['E'] = 2; $aI['EM'] = 'Decompression of data failed.'; - } - else { - if(strlen($vZ) != $aP['UCS']) { + } else { + if (strlen($vZ) != $aP['UCS']) { $aI['E'] = 3; $aI['EM'] = 'Uncompressed size is not equal with the value in header information.'; - } - else { - if(crc32($vZ) != $aP['CRC']) { + } else { + if (crc32($vZ) != $aP['CRC']) { $aI['E'] = 4; $aI['EM'] = 'CRC32 checksum is not equal with the value in header information.'; } @@ -475,7 +479,8 @@ * @access public * @since 1.0 */ - function SimpleUnzipEntry($in_Entry) { + function SimpleUnzipEntry($in_Entry) + { $this->Data = $in_Entry['D']; $this->Error = $in_Entry['E']; $this->ErrorMsg = $in_Entry['EM']; diff --git a/libraries/url_generating.lib.php b/libraries/url_generating.lib.php index 6dd07b97c2..46a8af7e89 100644 --- a/libraries/url_generating.lib.php +++ b/libraries/url_generating.lib.php @@ -65,17 +65,21 @@ function PMA_generate_common_hidden_inputs( $db = '', $table = '', $indent = 0, } if ( ! is_array($skip) ) { - if ( isset( $params[$skip] ) ) unset( $params[$skip] ); + if ( isset( $params[$skip] ) ) { + unset( $params[$skip] ); + } } else { - foreach( $skip as $skipping ) { - if ( isset( $params[$skipping] ) ) unset( $params[$skipping] ); + foreach ( $skip as $skipping ) { + if ( isset( $params[$skipping] ) ) { + unset( $params[$skipping] ); + } } } $spaces = str_repeat( ' ', $indent ); $return = ''; - foreach( $params as $key => $val ) { + foreach ( $params as $key => $val ) { $return .= $spaces . '<input type="hidden" name="' . htmlspecialchars( $key ) . '" value="' . htmlspecialchars( $val ) . '" />' . "\n"; } @@ -166,25 +170,25 @@ function PMA_generate_common_url ($db = '', $table = '', $delim = '&') } if ( $GLOBALS['server'] != $GLOBALS['cfg']['ServerDefault'] - && ! empty( $GLOBALS['server'] ) ) { + && ! empty( $GLOBALS['server'] ) ) { $params['server'] = $GLOBALS['server']; } if ( empty( $_COOKIE['pma_lang'] ) - && ! empty( $GLOBALS['lang'] ) ) { + && ! empty( $GLOBALS['lang'] ) ) { $params['lang'] = $GLOBALS['lang']; } if ( empty( $_COOKIE['pma_charset'] ) - && ! empty( $GLOBALS['convcharset'] ) ) { + && ! empty( $GLOBALS['convcharset'] ) ) { $params['convcharset'] = $GLOBALS['convcharset']; } if ( empty( $_COOKIE['pma_collation_connection'] ) - && ! empty( $GLOBALS['collation_connection'] ) ) { + && ! empty( $GLOBALS['collation_connection'] ) ) { $params['collation_connection'] = $GLOBALS['collation_connection']; } $param_strings = array(); - foreach( $params as $key => $val ) { + foreach ( $params as $key => $val ) { $param_strings[] = urlencode( $key ) . '=' . urlencode( $val ); } @@ -90,8 +90,8 @@ if (!$cfg['LeftDisplayServers'] && (count($cfg['Servers']) > 1 || $server == 0 & if ( $server > 0 ) { echo '<ul>' . "\n"; - PMA_printListItem( $strProtocolVersion . ': ' . PMA_DBI_get_proto_info() - , 'li_mysql_proto' ); + PMA_printListItem( $strProtocolVersion . ': ' . PMA_DBI_get_proto_info(), + 'li_mysql_proto' ); PMA_printListItem( $strServer . ': ' . $server_info, 'li_server_info' ); PMA_printListItem( $strUser . ': ' . htmlspecialchars( $mysql_cur_user_and_host ), 'li_user_info' ); @@ -131,7 +131,7 @@ if ( $server > 0 ) { . ' </li>' . "\n" . ' <li id="li_select_mysql_collation">'; echo ' <form method="post" action="index.php" target="_parent">' . "\n" - . PMA_generate_common_hidden_inputs(NULL, NULL, 4, 'collation_connection') + . PMA_generate_common_hidden_inputs(null, null, 4, 'collation_connection') . ' <label for="select_collation_connection">' . "\n" . ' ' . $strMySQLConnectionCollation . ': ' . "\n" . ' </label>' . "\n" @@ -172,7 +172,7 @@ if ( $server > 0 ) { './server_privileges.php?' . $common_url_query ); } - $binlogs = PMA_DBI_try_query('SHOW MASTER LOGS', NULL, PMA_DBI_QUERY_STORE); + $binlogs = PMA_DBI_try_query('SHOW MASTER LOGS', null, PMA_DBI_QUERY_STORE); if ( $binlogs ) { if (PMA_DBI_num_rows($binlogs) > 0) { PMA_printListItem( $strBinaryLog, 'li_mysql_binlogs', @@ -235,7 +235,7 @@ if (empty($cfg['Lang'])) { if ( isset($cfg['AllowAnywhereRecoding']) && $cfg['AllowAnywhereRecoding'] - && $server != 0 && $allow_recoding && PMA_MYSQL_INT_VERSION < 40100) { + && $server != 0 && $allow_recoding && PMA_MYSQL_INT_VERSION < 40100) { echo '<li id="li_select_charset">'; ?> <form method="post" action="index.php" target="_parent"> @@ -300,7 +300,7 @@ PMA_printListItem( $strHomepageOfficial, 'li_pma_homepage', 'http://www.phpMyAdm <?php if ( ! empty( $GLOBALS['PMA_errors'] ) && is_array( $GLOBALS['PMA_errors'] ) ) { - foreach( $GLOBALS['PMA_errors'] as $error ) { + foreach ( $GLOBALS['PMA_errors'] as $error ) { echo '<div class="error">' . $error . '</div>' . "\n"; } } @@ -371,19 +371,20 @@ if (defined('PMA_MYSQL_INT_VERSION') && PMA_MYSQL_INT_VERSION < 32332) { * @param string $id id, used for css styles * @param string $url make item as link with $url as target */ -function PMA_printListItem( $name, $id = NULL, $url = NULL, $mysql_help_page = NULL ) { +function PMA_printListItem($name, $id = null, $url = null, $mysql_help_page = null) +{ echo '<li id="' . $id . '">'; - if ( NULL !== $url ) { + if (null !== $url) { echo '<a href="' . $url . '">'; } echo $name; - if ( NULL !== $url ) { + if (null !== $url) { echo '</a>' . "\n"; } - if ( NULL !== $mysql_help_page ) { - echo PMA_showMySQLDocu( '', $mysql_help_page ); + if (null !== $mysql_help_page) { + echo PMA_showMySQLDocu('', $mysql_help_page); } echo '</li>'; } diff --git a/pdf_pages.php b/pdf_pages.php index 9403ca5b3e..c4890a26e5 100644 --- a/pdf_pages.php +++ b/pdf_pages.php @@ -99,7 +99,7 @@ if ($cfgRelation['pdfwork']) { // first put all the master tables at beginning // of the list, so they are near the center of // the schema - while (list(,$master_table) = PMA_DBI_fetch_row($master_tables_rs)) { + while (list(, $master_table) = PMA_DBI_fetch_row($master_tables_rs)) { $all_tables[] = $master_table; } @@ -223,7 +223,7 @@ if ($cfgRelation['pdfwork']) { // We will need an array of all tables in this db $selectboxall = array('--'); - $alltab_rs = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($db) . ';', NULL, PMA_DBI_QUERY_STORE); + $alltab_rs = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($db) . ';', null, PMA_DBI_QUERY_STORE); while ($val = @PMA_DBI_fetch_row($alltab_rs)) { $selectboxall[] = $val[0]; } diff --git a/pdf_schema.php b/pdf_schema.php index 69d8a821fb..811faf2c9c 100644 --- a/pdf_schema.php +++ b/pdf_schema.php @@ -1,18 +1,15 @@ <?php /* $Id$ */ // vim: expandtab sw=4 ts=4 sts=4: - /** * Contributed by Maxime Delorme and merged by lem9 */ - /** * Gets some core scripts */ require_once('./libraries/common.lib.php'); - /** * Settings for relation stuff */ @@ -21,7 +18,6 @@ require_once('./libraries/transformations.lib.php'); $cfgRelation = PMA_getRelationsParam(); - /** * Now in ./libraries/relation.lib.php we check for all tables * that we need, but if we don't find them we are quiet about it @@ -36,11 +32,10 @@ if (!$cfgRelation['pdfwork']) { echo sprintf($strRelationNotWorking, $url_to_goto, '</a>') . "\n"; } - /** * Gets the "fpdf" libraries and defines the pdf font path, use unicode version for unicode. */ -define('FPDF_FONTPATH','./libraries/fpdf/font/'); +define('FPDF_FONTPATH', './libraries/fpdf/font/'); if ($charset == 'utf-8') { define('PMA_PDF_FONT', 'FreeSans'); require_once('./libraries/fpdf/ufpdf.php'); @@ -53,16 +48,13 @@ if ($charset == 'utf-8') { }; } - /** * Extends the "FPDF" class and prepares the work * - * @access public - * - * @see FPDF + * @access public + * @see FPDF */ -class PMA_PDF extends PMA_FPDF -{ +class PMA_PDF extends PMA_FPDF { /** * Defines private properties */ @@ -73,7 +65,7 @@ class PMA_PDF extends PMA_FPDF var $scale; var $title; var $PMA_links; - var $Outlines=array(); + var $Outlines = array(); var $def_outlines; var $Alias ; var $widths; @@ -84,14 +76,12 @@ class PMA_PDF extends PMA_FPDF * This function just refers to the "FPDF" constructor: with PHP3 a class * must have a constructor * - * @param string The page orientation (p, portrait, l or landscape) - * @param string The unit for sizes (pt, mm, cm or in) - * @param mixed The page format (A3, A4, A5, letter, legal or an array - * with page sizes) - * + * @param string $ The page orientation (p, portrait, l or landscape) + * @param string $ The unit for sizes (pt, mm, cm or in) + * @param mixed $ The page format (A3, A4, A5, letter, legal or an array + * with page sizes) * @access public - * - * @see FPDF::FPDF() + * @see FPDF::FPDF() */ function PMA_PDF($orientation = 'L', $unit = 'mm', $format = 'A4') { @@ -104,12 +94,11 @@ class PMA_PDF extends PMA_FPDF } function _putpages() { - if (count($this->Alias) > 0) - { - $nb=$this->page; + if (count($this->Alias) > 0) { + $nb = $this->page; foreach ($this->Alias AS $alias => $value) { - for ($n=1;$n<=$nb;$n++) - $this->pages[$n]=$this->_strreplace($alias,$value,$this->pages[$n]); + for ($n = 1;$n <= $nb;$n++) + $this->pages[$n] = $this->_strreplace($alias, $value, $this->pages[$n]); } } parent::_putpages(); @@ -118,19 +107,18 @@ class PMA_PDF extends PMA_FPDF /** * Sets the scaling factor, defines minimum coordinates and margins * - * @param double The scaling factor - * @param double The minimum X coordinate - * @param double The minimum Y coordinate - * @param double The left margin - * @param double The top margin - * + * @param double $ The scaling factor + * @param double $ The minimum X coordinate + * @param double $ The minimum Y coordinate + * @param double $ The left margin + * @param double $ The top margin * @access public */ function PMA_PDF_setScale($scale = 1, $x_min = 0, $y_min = 0, $l_marg = -1, $t_marg = -1) { - $this->scale = $scale; - $this->x_min = $x_min; - $this->y_min = $y_min; + $this->scale = $scale; + $this->x_min = $x_min; + $this->y_min = $y_min; if ($this->l_marg != -1) { $this->l_marg = $l_marg; } @@ -138,42 +126,34 @@ class PMA_PDF extends PMA_FPDF $this->t_marg = $t_marg; } } // end of the "PMA_PDF_setScale" function - - /** * Outputs a scaled cell * - * @param double The cell width - * @param double The cell height - * @param string The text to output - * @param mixed Wether to add borders or not - * @param integer Where to put the cursor once the output is done - * @param string Align mode - * @param integer Whether to fill the cell with a color or not - * + * @param double $ The cell width + * @param double $ The cell height + * @param string $ The text to output + * @param mixed $ Wether to add borders or not + * @param integer $ Where to put the cursor once the output is done + * @param string $ Align mode + * @param integer $ Whether to fill the cell with a color or not * @access public - * - * @see FPDF::Cell() + * @see FPDF::Cell() */ - function PMA_PDF_cellScale($w, $h = 0, $txt = '', $border = 0, $ln = 0, $align = '', $fill = 0,$link ='') + function PMA_PDF_cellScale($w, $h = 0, $txt = '', $border = 0, $ln = 0, $align = '', $fill = 0, $link = '') { $h = $h / $this->scale; $w = $w / $this->scale; - $this->Cell($w, $h, $txt, $border, $ln, $align, $fill,$link); + $this->Cell($w, $h, $txt, $border, $ln, $align, $fill, $link); } // end of the "PMA_PDF_cellScale" function - - /** * Draws a scaled line * - * @param double The horizontal position of the starting point - * @param double The vertical position of the starting point - * @param double The horizontal position of the ending point - * @param double The vertical position of the ending point - * + * @param double $ The horizontal position of the starting point + * @param double $ The vertical position of the starting point + * @param double $ The horizontal position of the ending point + * @param double $ The vertical position of the ending point * @access public - * - * @see FPDF::Line() + * @see FPDF::Line() */ function PMA_PDF_lineScale($x1, $y1, $x2, $y2) { @@ -183,17 +163,13 @@ class PMA_PDF extends PMA_FPDF $y2 = ($y2 - $this->y_min) / $this->scale + $this->t_marg; $this->Line($x1, $y1, $x2, $y2); } // end of the "PMA_PDF_lineScale" function - - /** * Sets x and y scaled positions * - * @param double The x position - * @param double The y position - * + * @param double $ The x position + * @param double $ The y position * @access public - * - * @see FPDF::SetXY() + * @see FPDF::SetXY() */ function PMA_PDF_setXyScale($x, $y) { @@ -201,32 +177,24 @@ class PMA_PDF extends PMA_FPDF $y = ($y - $this->y_min) / $this->scale + $this->t_marg; $this->SetXY($x, $y); } // end of the "PMA_PDF_setXyScale" function - - /** * Sets the X scaled positions * - * @param double The x position - * + * @param double $ The x position * @access public - * - * @see FPDF::SetX() + * @see FPDF::SetX() */ function PMA_PDF_setXScale($x) { $x = ($x - $this->x_min) / $this->scale + $this->l_marg; $this->SetX($x); } // end of the "PMA_PDF_setXScale" function - - /** * Sets the scaled font size * - * @param double The font size (in points) - * + * @param double $ The font size (in points) * @access public - * - * @see FPDF::SetFontSize() + * @see FPDF::SetFontSize() */ function PMA_PDF_setFontSizeScale($size) { @@ -234,40 +202,32 @@ class PMA_PDF extends PMA_FPDF $size = $size / $this->scale; $this->SetFontSize($size); } // end of the "PMA_PDF_setFontSizeScale" function - - /** * Sets the scaled line width * - * @param double The line width - * + * @param double $ The line width * @access public - * - * @see FPDF::SetLineWidth() + * @see FPDF::SetLineWidth() */ function PMA_PDF_setLineWidthScale($width) { $width = $width / $this->scale; $this->SetLineWidth($width); } // end of the "PMA_PDF_setLineWidthScale" function - - /** * Displays an error message * - * @param string the error mesage - * - * @global array the PMA configuration array - * @global integer the current server id - * @global string the current language - * @global string the charset to convert to - * @global string the current database name - * @global string the current charset - * @global string the current text direction - * @global string a localized string - * @global string an other localized string - * - * @access public + * @param string $ the error mesage + * @global array the PMA configuration array + * @global integer the current server id + * @global string the current language + * @global string the charset to convert to + * @global string the current database name + * @global string the current charset + * @global string the current text direction + * @global string a localized string + * @global string an other localized string + * @access public */ function PMA_PDF_die($error_message = '') { @@ -277,7 +237,7 @@ class PMA_PDF extends PMA_FPDF require_once('./libraries/header.inc.php'); - echo '<p><b>PDF - '. $GLOBALS['strError'] . '</b></p>' . "\n"; + echo '<p><b>PDF - ' . $GLOBALS['strError'] . '</b></p>' . "\n"; if (!empty($error_message)) { $error_message = htmlspecialchars($error_message); } @@ -286,274 +246,264 @@ class PMA_PDF extends PMA_FPDF echo '</p>' . "\n"; echo '<a href="db_details_structure.php?' . PMA_generate_common_url($db) - . '">' . $GLOBALS['strBack'] . '</a>'; + . '">' . $GLOBALS['strBack'] . '</a>'; echo "\n"; require_once('./libraries/footer.inc.php'); } // end of the "PMA_PDF_die()" function - - /** * Aliases the "Error()" function from the FPDF class to the * "PMA_PDF_die()" one * - * @param string the error mesage - * - * @access public - * - * @see PMA_PDF_die() + * @param string $ the error mesage + * @access public + * @see PMA_PDF_die */ function Error($error_message = '') { $this->PMA_PDF_die($error_message); } // end of the "Error()" method - - function Header(){ - //$datefmt + function Header() + { + // $datefmt // We only show this if we find something in the new pdf_pages table - // - // This function must be named "Header" to work with the FPDF library - global $cfgRelation,$db,$pdf_page_number,$with_doc; - if ($with_doc){ - $test_query = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages']) - . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' - . ' AND page_nr = \'' . $pdf_page_number . '\''; - $test_rs = PMA_query_as_cu($test_query); - $pages = @PMA_DBI_fetch_assoc($test_rs); - $this->SetFont('', 'B', 14); - $this->Cell(0,6, ucfirst($pages['page_descr']),'B',1,'C'); - $this->SetFont('', ''); - $this->Ln(); - } + // This function must be named "Header" to work with the FPDF library + global $cfgRelation, $db, $pdf_page_number, $with_doc; + if ($with_doc) { + $test_query = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages']) + . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' + . ' AND page_nr = \'' . $pdf_page_number . '\''; + $test_rs = PMA_query_as_cu($test_query); + $pages = @PMA_DBI_fetch_assoc($test_rs); + $this->SetFont('', 'B', 14); + $this->Cell(0, 6, ucfirst($pages['page_descr']), 'B', 1, 'C'); + $this->SetFont('', ''); + $this->Ln(); + } } - function Footer(){ + function Footer() + { // This function must be named "Footer" to work with the FPDF library global $with_doc; - if ($with_doc){ + if ($with_doc) { $this->SetY(-15); - $this->SetFont('', '',14); - $this->Cell(0,6, $GLOBALS['strPageNumber'] .' '.$this->PageNo() .'/{nb}','T',0,'C'); - $this->Cell(0,6, PMA_localisedDate(),0,1,'R'); + $this->SetFont('', '', 14); + $this->Cell(0, 6, $GLOBALS['strPageNumber'] . ' ' . $this->PageNo() . '/{nb}', 'T', 0, 'C'); + $this->Cell(0, 6, PMA_localisedDate(), 0, 1, 'R'); $this->SetY(20); } } - function Bookmark($txt,$level=0,$y=0) -{ - //Add a bookmark - $this->Outlines[0][]=$level; - $this->Outlines[1][]=$txt; - $this->Outlines[2][]=$this->page; - if ($y==-1) - $y=$this->GetY(); - $this->Outlines[3][]=round($this->hPt-$y*$this->k,2); -} + function Bookmark($txt, $level = 0, $y = 0) + { + // Add a bookmark + $this->Outlines[0][] = $level; + $this->Outlines[1][] = $txt; + $this->Outlines[2][] = $this->page; + if ($y == -1) { + $y = $this->GetY(); + } + $this->Outlines[3][] = round($this->hPt - $y * $this->k, 2); + } -function _putbookmarks() -{ - if (count($this->Outlines)>0) - { - //Save object number - $memo_n = $this->n; - //Take the number of sub elements for an outline - $nb_outlines=sizeof($this->Outlines[0]); - $first_level=array(); - $parent=array(); - $parent[0]=1; - for ($i=0; $i<$nb_outlines; $i++) - { - $level=$this->Outlines[0][$i]; - $kids=0; - $last=-1; - $prev=-1; - $next=-1; - if ($i>0 ) - { - $cursor=$i-1; - //Take the previous outline in the same level - while ($this->Outlines[0][$cursor] > $level && $cursor > 0) - $cursor--; - if ($this->Outlines[0][$cursor] == $level) - $prev=$cursor; - } - if ($i<$nb_outlines-1) - { - $cursor=$i+1; - while (isset($this->Outlines[0][$cursor]) && $this->Outlines[0][$cursor] > $level) - { - //Take the immediate kid in level + 1 - if ($this->Outlines[0][$cursor] == $level+1) - { - $kids++; - $last=$cursor; - } - $cursor++; + function _putbookmarks() + { + if (count($this->Outlines) > 0) { + // Save object number + $memo_n = $this->n; + // Take the number of sub elements for an outline + $nb_outlines = sizeof($this->Outlines[0]); + $first_level = array(); + $parent = array(); + $parent[0] = 1; + for ($i = 0; $i < $nb_outlines; $i++) { + $level = $this->Outlines[0][$i]; + $kids = 0; + $last = -1; + $prev = -1; + $next = -1; + if ($i > 0) { + $cursor = $i-1; + // Take the previous outline in the same level + while ($this->Outlines[0][$cursor] > $level && $cursor > 0) + $cursor--; + if ($this->Outlines[0][$cursor] == $level) { + $prev = $cursor; + } + } + if ($i < $nb_outlines-1) { + $cursor = $i + 1; + while (isset($this->Outlines[0][$cursor]) && $this->Outlines[0][$cursor] > $level) { + // Take the immediate kid in level + 1 + if ($this->Outlines[0][$cursor] == $level + 1) { + $kids++; + $last = $cursor; + } + $cursor++; + } + $cursor = $i + 1; + // Take the next outline in the same level + while ($this->Outlines[0][$cursor] > $level && ($cursor + 1 < sizeof($this->Outlines[0]))) + $cursor++; + if ($this->Outlines[0][$cursor] == $level) { + $next = $cursor; + } + } + $this->_newobj(); + $parent[$level + 1] = $this->n; + if ($level == 0) { + $first_level[] = $this->n; + } + $this->_out('<<'); + $this->_out('/Title (' . $this->Outlines[1][$i] . ')'); + $this->_out('/Parent ' . $parent[$level] . ' 0 R'); + if ($prev != -1) { + $this->_out('/Prev ' . ($memo_n + $prev + 1) . ' 0 R'); + } + if ($next != -1) { + $this->_out('/Next ' . ($this->n + $next - $i) . ' 0 R'); + } + $this->_out('/Dest [' . (1 + (2 * $this->Outlines[2][$i])) . ' 0 R /XYZ null ' . $this->Outlines[3][$i] . ' null]'); + if ($kids > 0) { + $this->_out('/First ' . ($this->n + 1) . ' 0 R'); + $this->_out('/Last ' . ($this->n + $last - $i) . ' 0 R'); + $this->_out('/Count -' . $kids); + } + $this->_out('>>'); + $this->_out('endobj'); } - $cursor=$i+1; - //Take the next outline in the same level - while ($this->Outlines[0][$cursor] > $level && ($cursor+1 < sizeof($this->Outlines[0]))) - $cursor++; - if ($this->Outlines[0][$cursor] == $level) - $next=$cursor; - } - $this->_newobj(); - $parent[$level+1]=$this->n; - if ($level == 0) - $first_level[]=$this->n; - $this->_out('<<'); - $this->_out('/Title ('.$this->Outlines[1][$i].')'); - $this->_out('/Parent '.$parent[$level].' 0 R'); - if ($prev != -1) - $this->_out('/Prev '.($memo_n+$prev+1).' 0 R'); - if ($next != -1) - $this->_out('/Next '.($this->n+$next-$i).' 0 R'); - $this->_out('/Dest ['.(1+(2*$this->Outlines[2][$i])).' 0 R /XYZ null '.$this->Outlines[3][$i].' null]'); - if ($kids > 0) - { - $this->_out('/First '.($this->n+1).' 0 R'); - $this->_out('/Last '.($this->n+$last-$i).' 0 R'); - $this->_out('/Count -'.$kids); - } - $this->_out('>>'); - $this->_out('endobj'); - } - //First page of outlines - $this->_newobj(); - $this->def_outlines = $this->n; - $this->_out('<<'); - $this->_out('/Type'); - $this->_out('/Outlines'); - $this->_out('/First '.$first_level[0].' 0 R'); - $this->_out('/Last '.$first_level[sizeof($first_level)-1].' 0 R'); - $this->_out('/Count '.sizeof($first_level)); - $this->_out('>>'); - $this->_out('endobj'); - } -} - -function _putresources() -{ - parent::_putresources(); - $this->_putbookmarks(); -} + // First page of outlines + $this->_newobj(); + $this->def_outlines = $this->n; + $this->_out('<<'); + $this->_out('/Type'); + $this->_out('/Outlines'); + $this->_out('/First ' . $first_level[0] . ' 0 R'); + $this->_out('/Last ' . $first_level[sizeof($first_level)-1] . ' 0 R'); + $this->_out('/Count ' . sizeof($first_level)); + $this->_out('>>'); + $this->_out('endobj'); + } + } -function _putcatalog() -{ - parent::_putcatalog(); - if (count($this->Outlines)>0) - { - $this->_out('/Outlines '.$this->def_outlines.' 0 R'); - $this->_out('/PageMode /UseOutlines'); - } -} -function SetWidths($w) -{ - // column widths - $this->widths=$w; -} + function _putresources() + { + parent::_putresources(); + $this->_putbookmarks(); + } -function Row($data,$links) -{ - // line height - $nb=0; - $data_cnt = count($data); - for ($i=0;$i<$data_cnt;$i++) - $nb=max($nb,$this->NbLines($this->widths[$i],$data[$i])); - $il = $this->FontSize; - $h=($il+1)*$nb; - // page break if necessary - $this->CheckPageBreak($h); - // draw the cells - $data_cnt = count($data); - for ($i=0;$i<$data_cnt;$i++) - { - $w=$this->widths[$i]; - // save current position - $x=$this->GetX(); - $y=$this->GetY(); - // draw the border - $this->Rect($x,$y,$w,$h); - if (isset($links[$i])) - $this->Link($x,$y,$w,$h,$links[$i]); - // print text - $this->MultiCell($w,$il+1,$data[$i],0,'L'); - // go to right side - $this->SetXY($x+$w,$y); - } - // go to line - $this->Ln($h); -} + function _putcatalog() + { + parent::_putcatalog(); + if (count($this->Outlines) > 0) { + $this->_out('/Outlines ' . $this->def_outlines . ' 0 R'); + $this->_out('/PageMode /UseOutlines'); + } + } + function SetWidths($w) + { + // column widths + $this->widths = $w; + } -function CheckPageBreak($h) -{ - // if height h overflows, manual page break - if ($this->GetY()+$h>$this->PageBreakTrigger) - $this->AddPage($this->CurOrientation); -} + function Row($data, $links) + { + // line height + $nb = 0; + $data_cnt = count($data); + for ($i = 0;$i < $data_cnt;$i++) + $nb = max($nb, $this->NbLines($this->widths[$i], $data[$i])); + $il = $this->FontSize; + $h = ($il + 1) * $nb; + // page break if necessary + $this->CheckPageBreak($h); + // draw the cells + $data_cnt = count($data); + for ($i = 0;$i < $data_cnt;$i++) { + $w = $this->widths[$i]; + // save current position + $x = $this->GetX(); + $y = $this->GetY(); + // draw the border + $this->Rect($x, $y, $w, $h); + if (isset($links[$i])) { + $this->Link($x, $y, $w, $h, $links[$i]); + } + // print text + $this->MultiCell($w, $il + 1, $data[$i], 0, 'L'); + // go to right side + $this->SetXY($x + $w, $y); + } + // go to line + $this->Ln($h); + } -function NbLines($w,$txt) -{ - // compute number of lines used by a multicell of width w - $cw=&$this->CurrentFont['cw']; - if ($w==0) - $w=$this->w-$this->rMargin-$this->x; - $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; - $s=str_replace("\r",'',$txt); - $nb=strlen($s); - if ($nb>0 and $s[$nb-1]=="\n") - $nb--; - $sep=-1; - $i=0; - $j=0; - $l=0; - $nl=1; - while ($i<$nb) - { - $c=$s[$i]; - if ($c=="\n") - { - $i++; - $sep=-1; - $j=$i; - $l=0; - $nl++; - continue; - } - if ($c==' ') - $sep=$i; - $l+=isset($cw[ord($c)])?$cw[ord($c)]:0 ; - if ($l>$wmax) - { - if ($sep==-1) - { - if ($i==$j) - $i++; - } - else - $i=$sep+1; - $sep=-1; - $j=$i; - $l=0; - $nl++; - } - else - $i++; - } - return $nl; -} + function CheckPageBreak($h) + { + // if height h overflows, manual page break + if ($this->GetY() + $h > $this->PageBreakTrigger) { + $this->AddPage($this->CurOrientation); + } + } + function NbLines($w, $txt) + { + // compute number of lines used by a multicell of width w + $cw = &$this->CurrentFont['cw']; + if ($w == 0) { + $w = $this->w - $this->rMargin - $this->x; + } + $wmax = ($w-2 * $this->cMargin) * 1000 / $this->FontSize; + $s = str_replace("\r", '', $txt); + $nb = strlen($s); + if ($nb > 0 and $s[$nb-1] == "\n") { + $nb--; + } + $sep = -1; + $i = 0; + $j = 0; + $l = 0; + $nl = 1; + while ($i < $nb) { + $c = $s[$i]; + if ($c == "\n") { + $i++; + $sep = -1; + $j = $i; + $l = 0; + $nl++; + continue; + } + if ($c == ' ') { + $sep = $i; + } + $l += isset($cw[ord($c)])?$cw[ord($c)]:0 ; + if ($l > $wmax) { + if ($sep == -1) { + if ($i == $j) { + $i++; + } + } else { + $i = $sep + 1; + } + $sep = -1; + $j = $i; + $l = 0; + $nl++; + } else { + $i++; + } + } + return $nl; + } } // end of the "PMA_PDF" class - - /** * Draws tables schema * - * @access private - * - * @see PMA_RT + * @access private + * @see PMA_RT */ -class PMA_RT_Table -{ +class PMA_RT_Table { /** * Defines private properties */ @@ -561,27 +511,23 @@ class PMA_RT_Table var $table_name; var $width = 0; var $height; - var $fields = array(); + var $fields = array(); var $height_cell = 6; var $x, $y; - var $primary = array(); - + var $primary = array(); /** * Sets the width of the table * - * @param integer The font size - * - * @global object The current PDF document - * - * @access private - * - * @see PMA_PDF + * @param integer $ The font size + * @global object The current PDF document + * @access private + * @see PMA_PDF */ function PMA_RT_Table_setWidth($ff) { - // this looks buggy to me... does it really work if - // there are fields that require wider cells than the name of the table? + // this looks buggy to me... does it really work if + // there are fields that require wider cells than the name of the table? global $pdf; foreach ($this->fields AS $field) { @@ -592,34 +538,27 @@ class PMA_RT_Table $this->width = max($this->width, $pdf->GetStringWidth(' ' . $this->table_name)); $pdf->SetFont($ff, ''); } // end of the "PMA_RT_Table_setWidth()" method - - /** * Sets the height of the table * - * @access private + * @access private */ function PMA_RT_Table_setHeight() { $this->height = (count($this->fields) + 1) * $this->height_cell; } // end of the "PMA_RT_Table_setHeight()" method - - /** * Do draw the table * - * @param boolean Whether to display table position or not - * @param integer The font size - * @param boolean Whether to display color - * @param integer The max. with among tables - * - * @global object The current PDF document - * - * @access private - * - * @see PMA_PDF + * @param boolean $ Whether to display table position or not + * @param integer $ The font size + * @param boolean $ Whether to display color + * @param integer $ The max. with among tables + * @global object The current PDF document + * @access private + * @see PMA_PDF */ - function PMA_RT_Table_draw($show_info, $ff, $setcolor=0) + function PMA_RT_Table_draw($show_info, $ff, $setcolor = 0) { global $pdf, $with_doc; @@ -629,9 +568,13 @@ class PMA_RT_Table $pdf->SetTextColor(200); $pdf->SetFillColor(0, 0, 128); } - if ($with_doc) $pdf->SetLink($pdf->PMA_links['RT'][$this->table_name]['-'],-1); - else $pdf->PMA_links['doc'][$this->table_name]['-'] = ''; - if ($show_info){ + if ($with_doc) { + $pdf->SetLink($pdf->PMA_links['RT'][$this->table_name]['-'], -1); + } else { + $pdf->PMA_links['doc'][$this->table_name]['-'] = ''; + } + + if ($show_info) { $pdf->PMA_PDF_cellScale($this->width, $this->height_cell, sprintf('%.0f', $this->width) . 'x' . sprintf('%.0f', $this->height) . ' ' . $this->table_name, 1, 1, 'C', $setcolor, $pdf->PMA_links['doc'][$this->table_name]['-']); } else { $pdf->PMA_PDF_cellScale($this->width, $this->height_cell, $this->table_name, 1, 1, 'C', $setcolor, $pdf->PMA_links['doc'][$this->table_name]['-']); @@ -645,53 +588,49 @@ class PMA_RT_Table // loic1 : PHP3 fix // if (in_array($field, $this->primary)) { if ($setcolor) { - if ( in_array($field, $this->primary) ) { + if (in_array($field, $this->primary)) { $pdf->SetFillColor(215, 121, 123); } if ($field == $this->displayfield) { $pdf->SetFillColor(142, 159, 224); } } - if ($with_doc) $pdf->SetLink($pdf->PMA_links['RT'][$this->table_name][$field],-1); - else $pdf->PMA_links['doc'][$this->table_name][$field] = ''; - + if ($with_doc) { + $pdf->SetLink($pdf->PMA_links['RT'][$this->table_name][$field], -1); + } else { + $pdf->PMA_links['doc'][$this->table_name][$field] = ''; + } - $pdf->PMA_PDF_cellScale($this->width, $this->height_cell, ' ' . $field, 1, 1, 'L', $setcolor,$pdf->PMA_links['doc'][$this->table_name][$field]); + $pdf->PMA_PDF_cellScale($this->width, $this->height_cell, ' ' . $field, 1, 1, 'L', $setcolor, $pdf->PMA_links['doc'][$this->table_name][$field]); $pdf->PMA_PDF_setXScale($this->x); $pdf->SetFillColor(255); } // end while - /*if ($pdf->PageNo() > 1) { $pdf->PMA_PDF_die($GLOBALS['strScaleFactorSmall']); } */ } // end of the "PMA_RT_Table_draw()" method - - /** * The "PMA_RT_Table" constructor * - * @param string The table name - * @param integer The font size - * @param integer The max. with among tables - * - * @global object The current PDF document - * @global integer The current page number (from the - * $cfg['Servers'][$i]['table_coords'] table) - * @global array The relations settings - * @global string The current db name - * - * @access private - * - * @see PMA_PDF, PMA_RT_Table::PMA_RT_Table_setWidth, - * PMA_RT_Table::PMA_RT_Table_setHeight + * @param string $ The table name + * @param integer $ The font size + * @param integer $ The max. with among tables + * @global object The current PDF document + * @global integer The current page number (from the + * $cfg['Servers'][$i]['table_coords'] table) + * @global array The relations settings + * @global string The current db name + * @access private + * @see PMA_PDF, PMA_RT_Table::PMA_RT_Table_setWidth, + PMA_RT_Table::PMA_RT_Table_setHeight */ function PMA_RT_Table($table_name, $ff, &$same_wide_width) { global $pdf, $pdf_page_number, $cfgRelation, $db; $this->table_name = $table_name; - $sql = 'DESCRIBE ' . PMA_backquote($table_name); - $result = PMA_DBI_try_query($sql, NULL, PMA_DBI_QUERY_STORE); + $sql = 'DESCRIBE ' . PMA_backquote($table_name); + $result = PMA_DBI_try_query($sql, null, PMA_DBI_QUERY_STORE); if (!$result || !PMA_DBI_num_rows($result)) { $pdf->PMA_PDF_die(sprintf($GLOBALS['strPdfInvalidTblName'], $table_name)); } @@ -699,21 +638,19 @@ class PMA_RT_Table while ($row = PMA_DBI_fetch_row($result)) { $this->fields[] = $row[0]; } - - //height and width + // height and width $this->PMA_RT_Table_setWidth($ff); $this->PMA_RT_Table_setHeight(); if ($same_wide_width < $this->width) { $same_wide_width = $this->width; } - - //x and y - $sql = 'SELECT x, y FROM ' - . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) - . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' - . ' AND table_name = \'' . PMA_sqlAddslashes($table_name) . '\'' - . ' AND pdf_page_number = ' . $pdf_page_number; - $result = PMA_query_as_cu($sql, FALSE, PMA_DBI_QUERY_STORE); + // x and y + $sql = 'SELECT x, y FROM ' + . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) + . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' + . ' AND table_name = \'' . PMA_sqlAddslashes($table_name) . '\'' + . ' AND pdf_page_number = ' . $pdf_page_number; + $result = PMA_query_as_cu($sql, false, PMA_DBI_QUERY_STORE); if (!$result || !PMA_DBI_num_rows($result)) { $pdf->PMA_PDF_die(sprintf($GLOBALS['strConfigureTableCoord'], $table_name)); @@ -723,9 +660,8 @@ class PMA_RT_Table $this->y = (double) $this->y; // displayfield $this->displayfield = PMA_getDisplayField($db, $table_name); - // index - $result = PMA_DBI_query('SHOW INDEX FROM ' . PMA_backquote($table_name) . ';', NULL, PMA_DBI_QUERY_STORE); + $result = PMA_DBI_query('SHOW INDEX FROM ' . PMA_backquote($table_name) . ';', null, PMA_DBI_QUERY_STORE); if (PMA_DBI_num_rows($result) > 0) { while ($row = PMA_DBI_fetch_assoc($result)) { if ($row['Key_name'] == 'PRIMARY') { @@ -735,18 +671,13 @@ class PMA_RT_Table } // end if } // end of the "PMA_RT_Table()" method } // end class "PMA_RT_Table" - - - /** * Draws relation links * - * @access private - * - * @see PMA_RT + * @access private + * @see PMA_RT */ -class PMA_RT_Relation -{ +class PMA_RT_Relation { /** * Defines private properties */ @@ -756,16 +687,13 @@ class PMA_RT_Relation var $x_dest, $y_dest; var $w_tick = 5; - /** * Gets arrows coordinates * - * @param string The current table name - * @param string The relation column name - * - * @return array Arrows coordinates - * - * @access private + * @param string $ The current table name + * @param string $ The relation column name + * @return array Arrows coordinates + * @access private */ function PMA_RT_Relation_getXy($table, $column) { @@ -773,51 +701,44 @@ class PMA_RT_Relation // x_left, x_right, y return array($table->x, $table->x + + $table->width, $table->y + ($pos + 1.5) * $table->height_cell); } // end of the "PMA_RT_Relation_getXy()" method - - /** * Do draws relation links * - * @param boolean Whether to use one color per relation or not - * @param integer The id of the link to draw - * - * @global object The current PDF document - * - * @access private - * - * @see PMA_PDF + * @param boolean $ Whether to use one color per relation or not + * @param integer $ The id of the link to draw + * @global object The current PDF document + * @access private + * @see PMA_PDF */ function PMA_RT_Relation_draw($change_color, $i) { global $pdf; - if ($change_color){ - $d = $i % 6; - $j = ($i - $d) / 6; - $j = $j % 4; + if ($change_color) { + $d = $i % 6; + $j = ($i - $d) / 6; + $j = $j % 4; $j++; $case = array( - array(1, 0, 0), - array(0, 1, 0), - array(0, 0, 1), - array(1, 1, 0), - array(1, 0, 1), - array(0, 1, 1) - ); + array(1, 0, 0), + array(0, 1, 0), + array(0, 0, 1), + array(1, 1, 0), + array(1, 0, 1), + array(0, 1, 1) + ); list ($a, $b, $c) = $case[$d]; - $e = (1 - ($j - 1) / 6); - $pdf->SetDrawColor($a * 255 * $e, $b * 255 * $e, $c * 255 * $e); } - else { + $e = (1 - ($j - 1) / 6); + $pdf->SetDrawColor($a * 255 * $e, $b * 255 * $e, $c * 255 * $e); + } else { $pdf->SetDrawColor(0); } // end if... else... - $pdf->PMA_PDF_setLineWidthScale(0.2); $pdf->PMA_PDF_lineScale($this->x_src, $this->y_src, $this->x_src + $this->src_dir * $this->w_tick, $this->y_src); $pdf->PMA_PDF_lineScale($this->x_dest + $this->dest_dir * $this->w_tick, $this->y_dest, $this->x_dest, $this->y_dest); $pdf->PMA_PDF_setLineWidthScale(0.1); $pdf->PMA_PDF_lineScale($this->x_src + $this->src_dir * $this->w_tick, $this->y_src, $this->x_dest + $this->dest_dir * $this->w_tick, $this->y_dest); - - //arrow + // arrow $root2 = 2 * sqrt(2); $pdf->PMA_PDF_lineScale($this->x_src + $this->src_dir * $this->w_tick * 0.75, $this->y_src, $this->x_src + $this->src_dir * (0.75 - 1 / $root2) * $this->w_tick, $this->y_src + $this->w_tick / $root2); $pdf->PMA_PDF_lineScale($this->x_src + $this->src_dir * $this->w_tick * 0.75, $this->y_src, $this->x_src + $this->src_dir * (0.75 - 1 / $root2) * $this->w_tick, $this->y_src - $this->w_tick / $root2); @@ -826,97 +747,86 @@ class PMA_RT_Relation $pdf->PMA_PDF_lineScale($this->x_dest + $this->dest_dir * $this->w_tick / 2, $this->y_dest, $this->x_dest + $this->dest_dir * (0.5 + 1 / $root2) * $this->w_tick, $this->y_dest - $this->w_tick / $root2); $pdf->SetDrawColor(0); } // end of the "PMA_RT_Relation_draw()" method - - /** * The "PMA_RT_Relation" constructor * - * @param string The master table name - * @param string The relation field in the master table - * @param string The foreign table name - * @param string The relation field in the foreign table - * - * - * @access private - * - * @see PMA_RT_Relation::PMA_RT_Relation_getXy + * @param string $ The master table name + * @param string $ The relation field in the master table + * @param string $ The foreign table name + * @param string $ The relation field in the foreign table + * @access private + * @see PMA_RT_Relation::PMA_RT_Relation_getXy */ - function PMA_RT_Relation($master_table, $master_field, $foreign_table, $foreign_field) + function PMA_RT_Relation($master_table, $master_field, $foreign_table, $foreign_field) { - $src_pos = $this->PMA_RT_Relation_getXy($master_table , $master_field); - $dest_pos = $this->PMA_RT_Relation_getXy($foreign_table, $foreign_field); - $src_left = $src_pos[0] - $this->w_tick; - $src_right = $src_pos[1] + $this->w_tick; - $dest_left = $dest_pos[0] - $this->w_tick; + $src_pos = $this->PMA_RT_Relation_getXy($master_table, $master_field); + $dest_pos = $this->PMA_RT_Relation_getXy($foreign_table, $foreign_field); + $src_left = $src_pos[0] - $this->w_tick; + $src_right = $src_pos[1] + $this->w_tick; + $dest_left = $dest_pos[0] - $this->w_tick; $dest_right = $dest_pos[1] + $this->w_tick; - $d1 = abs($src_left - $dest_left); + $d1 = abs($src_left - $dest_left); $d2 = abs($src_right - $dest_left); - $d3 = abs($src_left - $dest_right); + $d3 = abs($src_left - $dest_right); $d4 = abs($src_right - $dest_right); - $d = min($d1, $d2, $d3, $d4); + $d = min($d1, $d2, $d3, $d4); if ($d == $d1) { - $this->x_src = $src_pos[0]; - $this->src_dir = -1; - $this->x_dest = $dest_pos[0]; + $this->x_src = $src_pos[0]; + $this->src_dir = -1; + $this->x_dest = $dest_pos[0]; $this->dest_dir = -1; - } else if ($d == $d2) { - $this->x_src = $src_pos[1]; - $this->src_dir = 1; - $this->x_dest = $dest_pos[0]; + } elseif ($d == $d2) { + $this->x_src = $src_pos[1]; + $this->src_dir = 1; + $this->x_dest = $dest_pos[0]; $this->dest_dir = -1; - } else if ($d == $d3) { - $this->x_src = $src_pos[0]; - $this->src_dir = -1; - $this->x_dest = $dest_pos[1]; + } elseif ($d == $d3) { + $this->x_src = $src_pos[0]; + $this->src_dir = -1; + $this->x_dest = $dest_pos[1]; $this->dest_dir = 1; } else { - $this->x_src = $src_pos[1]; - $this->src_dir = 1; - $this->x_dest = $dest_pos[1]; + $this->x_src = $src_pos[1]; + $this->src_dir = 1; + $this->x_dest = $dest_pos[1]; $this->dest_dir = 1; } - $this->y_src = $src_pos[2]; - $this->y_dest = $dest_pos[2]; + $this->y_src = $src_pos[2]; + $this->y_dest = $dest_pos[2]; } // end of the "PMA_RT_Relation()" method } // end of the "PMA_RT_Relation" class - - - /** * Draws and send the database schema * - * @access public - * - * @see PMA_PDF + * @access public + * @see PMA_PDF */ -class PMA_RT -{ +class PMA_RT { /** * Defines private properties */ - var $tables = array(); + var $tables = array(); var $relations = array(); - var $ff = PMA_PDF_FONT; - var $x_max = 0; - var $y_max = 0; + var $ff = PMA_PDF_FONT; + var $x_max = 0; + var $y_max = 0; var $scale; - var $x_min = 100000; - var $y_min = 100000; - var $t_marg = 10; - var $b_marg = 10; - var $l_marg = 10; - var $r_marg = 10; + var $x_min = 100000; + var $y_min = 100000; + var $t_marg = 10; + var $b_marg = 10; + var $l_marg = 10; + var $r_marg = 10; var $tablewidth; var $same_wide = 0; /** * Sets X and Y minimum and maximum for a table cell * - * @param string The table name - * - * @access private + * @param string $ The table name + * @access private */ function PMA_RT_setMinMax($table) { @@ -925,21 +835,17 @@ class PMA_RT $this->x_min = min($this->x_min, $table->x); $this->y_min = min($this->y_min, $table->y); } // end of the "PMA_RT_setMinMax()" method - - /** * Defines relation objects * - * @param string The master table name - * @param string The relation field in the master table - * @param string The foreign table name - * @param string The relation field in the foreign table - * - * @access private - * - * @see PMA_RT_setMinMax() + * @param string $ The master table name + * @param string $ The relation field in the master table + * @param string $ The foreign table name + * @param string $ The relation field in the foreign table + * @access private + * @see PMA_RT_setMinMax */ - function PMA_RT_addRelation($master_table , $master_field, $foreign_table, $foreign_field) + function PMA_RT_addRelation($master_table, $master_field, $foreign_table, $foreign_field) { if (!isset($this->tables[$master_table])) { $this->tables[$master_table] = new PMA_RT_Table($master_table, $this->ff, $this->tablewidth); @@ -951,16 +857,12 @@ class PMA_RT } $this->relations[] = new PMA_RT_Relation($this->tables[$master_table], $master_field, $this->tables[$foreign_table], $foreign_field); } // end of the "PMA_RT_addRelation()" method - - /** * Draws the grid * - * @global object the current PMA_PDF instance - * - * @access private - * - * @see PMA_PDF + * @global object the current PMA_PDF instance + * @access private + * @see PMA_PDF */ function PMA_RT_strokeGrid() { @@ -968,7 +870,6 @@ class PMA_RT $pdf->SetMargins(0, 0); $pdf->SetDrawColor(200, 200, 200); - // Draws horizontal lines for ($l = 0; $l < 21; $l++) { $pdf->line(0, $l * 10, $pdf->fh, $l * 10); @@ -979,7 +880,6 @@ class PMA_RT $pdf->Cell(5, 5, ' ' . $label); } // end if } // end for - // Draws vertical lines for ($j = 0; $j < 30 ;$j++) { $pdf->line($j * 10, 0, $j * 10, $pdf->fw); @@ -988,16 +888,12 @@ class PMA_RT $pdf->Cell(5, 7, $label); } // end for } // end of the "PMA_RT_strokeGrid()" method - - /** * Draws relation arrows * - * @param boolean Whether to use one color per relation or not - * - * @access private - * - * @see PMA_RT_Relation::PMA_RT_Relation_draw() + * @param boolean $ Whether to use one color per relation or not + * @access private + * @see PMA_RT_Relation::PMA_RT_Relation_draw() */ function PMA_RT_drawRelations($change_color) { @@ -1007,36 +903,28 @@ class PMA_RT $i++; } // end while } // end of the "PMA_RT_drawRelations()" method - - /** * Draws tables * - * @param boolean Whether to display table position or not - * - * @access private - * - * @see PMA_RT_Table::PMA_RT_Table_draw() + * @param boolean $ Whether to display table position or not + * @access private + * @see PMA_RT_Table::PMA_RT_Table_draw() */ - function PMA_RT_drawTables($show_info,$draw_color=0) + function PMA_RT_drawTables($show_info, $draw_color = 0) { foreach ($this->tables AS $table) { - $table->PMA_RT_Table_draw($show_info, $this->ff,$draw_color); + $table->PMA_RT_Table_draw($show_info, $this->ff, $draw_color); } } // end of the "PMA_RT_drawTables()" method - - /** * Ouputs the PDF document to a file * - * @global object The current PDF document - * @global string The current database name - * @global integer The current page number (from the - * $cfg['Servers'][$i]['table_coords'] table) - * - * @access private - * - * @see PMA_PDF + * @global object The current PDF document + * @global string The current database name + * @global integer The current page number (from the + * $cfg['Servers'][$i]['table_coords'] table) + * @access private + * @see PMA_PDF */ function PMA_RT_showRt() { @@ -1045,10 +933,10 @@ class PMA_RT $pdf->SetFontSize(14); $pdf->SetLineWidth(0.2); $pdf->SetDisplayMode('fullpage'); - // Get the name of this pdfpage to use as filename (Mike Beck) - $_name_sql = 'SELECT page_descr FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages']) - . ' WHERE page_nr = ' . $pdf_page_number; - $_name_rs = PMA_query_as_cu($_name_sql); + // Get the name of this pdfpage to use as filename (Mike Beck) + $_name_sql = 'SELECT page_descr FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages']) + . ' WHERE page_nr = ' . $pdf_page_number; + $_name_rs = PMA_query_as_cu($_name_sql); if ($_name_rs) { $_name_row = PMA_DBI_fetch_row($_name_rs); $filename = $_name_row[0] . '.pdf'; @@ -1057,41 +945,35 @@ class PMA_RT if (empty($filename)) { $filename = $pdf_page_number . '.pdf'; } - //$pdf->Output($db . '_' . $filename, TRUE); + // $pdf->Output($db . '_' . $filename, TRUE); $pdf->Output($db . '_' . $filename, 'I'); // destination: Inline } // end of the "PMA_RT_showRt()" method - - /** * The "PMA_RT" constructor * - * @param mixed The scaling factor - * @param integer The page number to draw (from the - * $cfg['Servers'][$i]['table_coords'] table) - * @param boolean Whether to display table position or not - * @param boolean Was originally whether to use one color per - * relation or not, now enables/disables color - * everywhere, due to some problems printing with color - * @param boolean Whether to draw grids or not - * @param boolean Whether all tables should have the same width or not - * - * @global object The current PDF document - * @global string The current db name - * @global array The relations settings - * - * @access private - * - * @see PMA_PDF + * @param mixed $ The scaling factor + * @param integer $ The page number to draw (from the + * $cfg['Servers'][$i]['table_coords'] table) + * @param boolean $ Whether to display table position or not + * @param boolean $ Was originally whether to use one color per + * relation or not, now enables/disables color + * everywhere, due to some problems printing with color + * @param boolean $ Whether to draw grids or not + * @param boolean $ Whether all tables should have the same width or not + * @global object The current PDF document + * @global string The current db name + * @global array The relations settings + * @access private + * @see PMA_PDF */ - function PMA_RT( $which_rel, $show_info = 0, $change_color = 0 , $show_grid = 0, $all_tab_same_wide = 0, $orientation = 'L', $paper = 'A4') + function PMA_RT($which_rel, $show_info = 0, $change_color = 0, $show_grid = 0, $all_tab_same_wide = 0, $orientation = 'L', $paper = 'A4') { global $pdf, $db, $cfgRelation, $with_doc; $this->same_wide = $all_tab_same_wide; - // Initializes a new document - $pdf = new PMA_PDF('L', 'mm', $paper); - $pdf->title = sprintf($GLOBALS['strPdfDbSchema'], $GLOBALS['db'], $which_rel); + $pdf = new PMA_PDF('L', 'mm', $paper); + $pdf->title = sprintf($GLOBALS['strPdfDbSchema'], $GLOBALS['db'], $which_rel); $pdf->cMargin = 0; $pdf->Open(); $pdf->SetTitle($pdf->title); @@ -1101,37 +983,34 @@ class PMA_RT if ($GLOBALS['charset'] == 'utf-8') { // Force FreeSans for utf-8 $this->ff = 'FreeSans'; - $pdf->AddFont('FreeSans','','FreeSans.php'); - $pdf->AddFont('FreeSans','B','FreeSansBold.php'); - } else if ($GLOBALS['charset'] == 'iso-8859-2') { + $pdf->AddFont('FreeSans', '', 'FreeSans.php'); + $pdf->AddFont('FreeSans', 'B', 'FreeSansBold.php'); + } elseif ($GLOBALS['charset'] == 'iso-8859-2') { // fonts added to phpMyAdmin and considered non-standard by fpdf // (Note: those tahoma fonts are iso-8859-2 based) $this->ff == 'tahoma'; - $pdf->AddFont('tahoma','','tahoma.php'); - $pdf->AddFont('tahoma','B','tahomab.php'); + $pdf->AddFont('tahoma', '', 'tahoma.php'); + $pdf->AddFont('tahoma', 'B', 'tahomab.php'); } else { $this->ff == 'helvetica'; } $pdf->SetFont($this->ff, '', 14); $pdf->SetAutoPageBreak('auto'); - // Gets tables on this page - $tab_sql = 'SELECT table_name FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) - . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' - . ' AND pdf_page_number = ' . $which_rel; - $tab_rs = PMA_query_as_cu($tab_sql, NULL, PMA_DBI_QUERY_STORE); + $tab_sql = 'SELECT table_name FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['table_coords']) + . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' + . ' AND pdf_page_number = ' . $which_rel; + $tab_rs = PMA_query_as_cu($tab_sql, null, PMA_DBI_QUERY_STORE); if (!$tab_rs || !PMA_DBI_num_rows($tab_rs) > 0) { $pdf->PMA_PDF_die($GLOBALS['strPdfNoTables']); -// die('No tables'); - } - while ($curr_table = @PMA_DBI_fetch_assoc($tab_rs)) { + // die('No tables'); + } while ($curr_table = @PMA_DBI_fetch_assoc($tab_rs)) { $alltables[] = PMA_sqlAddslashes($curr_table['table_name']); - //$intable = '\'' . implode('\', \'', $alltables) . '\''; + // $intable = '\'' . implode('\', \'', $alltables) . '\''; } - - // make doc // + // make doc // if ($with_doc) { - $pdf->SetAutoPageBreak('auto',15); + $pdf->SetAutoPageBreak('auto', 15); $pdf->cMargin = 1; PMA_RT_DOC($alltables); $pdf->SetAutoPageBreak('auto'); @@ -1140,23 +1019,22 @@ class PMA_RT $pdf->Addpage(); - if ($with_doc) { - $pdf->SetLink($pdf->PMA_links['RT']['-'],-1); + $pdf->SetLink($pdf->PMA_links['RT']['-'], -1); $pdf->Bookmark($GLOBALS['strRelationalSchema']); $pdf->SetAlias('{00}', $pdf->PageNo()) ; $this->t_marg = 18; $this->b_marg = 18; } - /* snip */ + /* snip */ foreach ($alltables AS $table) { if (!isset($this->tables[$table])) { $this->tables[$table] = new PMA_RT_Table($table, $this->ff, $this->tablewidth); } - if ($this->same_wide){ + if ($this->same_wide) { $this->tables[$table]->width = $this->tablewidth; } $this->PMA_RT_setMinMax($this->tables[$table]); @@ -1164,8 +1042,6 @@ class PMA_RT // Defines the scale factor $this->scale = ceil(max(($this->x_max - $this->x_min) / ($pdf->fh - $this->r_marg - $this->l_marg), ($this->y_max - $this->y_min) / ($pdf->fw - $this->t_marg - $this->b_marg)) * 100) / 100; $pdf->PMA_PDF_setScale($this->scale, $this->x_min, $this->y_min, $this->l_marg, $this->t_marg); - - // Builds and save the PDF document $pdf->PMA_PDF_setLineWidthScale(0.1); @@ -1174,106 +1050,97 @@ class PMA_RT $this->PMA_RT_strokeGrid(); } $pdf->PMA_PDF_setFontSizeScale(14); - - -// $sql = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation']) -// . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\' ' -// . ' AND foreign_db = \'' . PMA_sqlAddslashes($db) . '\' ' -// . ' AND master_table IN (' . $intable . ')' -// . ' AND foreign_table IN (' . $intable . ')'; -// $result = PMA_query_as_cu($sql); -// -// lem9: -// previous logic was checking master tables and foreign tables -// but I think that looping on every table of the pdf page as a master -// and finding its foreigns is OK (then we can support innodb) - - $seen_a_relation = FALSE; + // $sql = 'SELECT * FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation']) + // . ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\' ' + // . ' AND foreign_db = \'' . PMA_sqlAddslashes($db) . '\' ' + // . ' AND master_table IN (' . $intable . ')' + // . ' AND foreign_table IN (' . $intable . ')'; + // $result = PMA_query_as_cu($sql); + + // lem9: + // previous logic was checking master tables and foreign tables + // but I think that looping on every table of the pdf page as a master + // and finding its foreigns is OK (then we can support innodb) + $seen_a_relation = false; foreach ($alltables AS $one_table) { - $exist_rel = PMA_getForeigners($db, $one_table, '', 'both'); if ($exist_rel) { - $seen_a_relation = TRUE; + $seen_a_relation = true; foreach ($exist_rel AS $master_field => $rel) { // put the foreign table on the schema only if selected // by the user // (do not use array_search() because we would have to // to do a === FALSE and this is not PHP3 compatible) - - if ( in_array($rel['foreign_table'], $alltables) ) { - $this->PMA_RT_addRelation($one_table , $master_field, $rel['foreign_table'], $rel['foreign_field']); + if (in_array($rel['foreign_table'], $alltables)) { + $this->PMA_RT_addRelation($one_table, $master_field, $rel['foreign_table'], $rel['foreign_field']); } - } // end while } // end if } // end while - // loic1: also show tables without relations -// $norelations = TRUE; -// if ($result && PMA_DBI_num_rows($result) > 0) { -// $norelations = FALSE; -// while ($row = PMA_DBI_fetch_assoc($result)) { -// $this->PMA_RT_addRelation($row['master_table'] , $row['master_field'], $row['foreign_table'], $row['foreign_field']); -// } -// } - - -// if ($norelations == FALSE) { + // $norelations = TRUE; + // if ($result && PMA_DBI_num_rows($result) > 0) { + // $norelations = FALSE; + // while ($row = PMA_DBI_fetch_assoc($result)) { + // $this->PMA_RT_addRelation($row['master_table'], $row['master_field'], $row['foreign_table'], $row['foreign_field']); + // } + // } + // if ($norelations == FALSE) { if ($seen_a_relation) { $this->PMA_RT_drawRelations($change_color); } - $this->PMA_RT_drawTables($show_info,$change_color); + $this->PMA_RT_drawTables($show_info, $change_color); $this->PMA_RT_showRt(); } // end of the "PMA_RT()" method } // end of the "PMA_RT" class -function PMA_RT_DOC($alltables ){ - global $db, $pdf, $orientation, $paper; - //TOC +function PMA_RT_DOC($alltables) +{ + global $db, $pdf, $orientation, $paper; + // TOC $pdf->addpage($GLOBALS['orientation']); - $pdf->Cell(0,9, $GLOBALS['strTableOfContents'],1,0,'C'); + $pdf->Cell(0, 9, $GLOBALS['strTableOfContents'], 1, 0, 'C'); $pdf->Ln(15); $i = 1; foreach ($alltables AS $table) { $pdf->PMA_links['doc'][$table]['-'] = $pdf->AddLink(); $pdf->SetX(10); - //$pdf->Ln(1); - $pdf->Cell(0,6,$GLOBALS['strPageNumber'] . ' {'.sprintf("%02d", $i).'}',0,0,'R',0,$pdf->PMA_links['doc'][$table]['-']); + // $pdf->Ln(1); + $pdf->Cell(0, 6, $GLOBALS['strPageNumber'] . ' {' . sprintf("%02d", $i) . '}', 0, 0, 'R', 0, $pdf->PMA_links['doc'][$table]['-']); $pdf->SetX(10); - $pdf->Cell(0,6,$i.' '. $table,0,1,'L',0,$pdf->PMA_links['doc'][$table]['-']); - - //$pdf->Ln(1); - $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';'); + $pdf->Cell(0, 6, $i . ' ' . $table, 0, 1, 'L', 0, $pdf->PMA_links['doc'][$table]['-']); + // $pdf->Ln(1); + $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';'); while ($row = PMA_DBI_fetch_assoc($result)) { $pdf->SetX(20); $field_name = $row['Field']; - $pdf->PMA_links['doc'][$table][$field_name] =$pdf->AddLink(); - //$pdf->Cell(0,6,$field_name,0,1,'L',0,$pdf->PMA_links['doc'][$table][$field_name]); + $pdf->PMA_links['doc'][$table][$field_name] = $pdf->AddLink(); + // $pdf->Cell(0, 6, $field_name,0,1,'L',0, $pdf->PMA_links['doc'][$table][$field_name]); } $lasttable = $table; $i++; } - $pdf->PMA_links['RT']['-'] =$pdf->AddLink(); + $pdf->PMA_links['RT']['-'] = $pdf->AddLink(); $pdf->SetX(10); - $pdf->Cell(0,6,$GLOBALS['strPageNumber'] . ' {00}',0,0,'R',0,$pdf->PMA_links['doc'][$lasttable]['-']); + $pdf->Cell(0, 6, $GLOBALS['strPageNumber'] . ' {00}', 0, 0, 'R', 0, $pdf->PMA_links['doc'][$lasttable]['-']); $pdf->SetX(10); - $pdf->Cell(0,6,$i.' '. $GLOBALS['strRelationalSchema'],0,1,'L',0,$pdf->PMA_links['RT']['-']); + $pdf->Cell(0, 6, $i . ' ' . $GLOBALS['strRelationalSchema'], 0, 1, 'L', 0, $pdf->PMA_links['RT']['-']); $z = 0; foreach ($alltables AS $table) { $z++; $pdf->addpage($GLOBALS['orientation']); $pdf->Bookmark($table); - $pdf->SetAlias('{'.sprintf("%02d", $z).'}', $pdf->PageNo()) ; - $pdf->PMA_links['RT'][$table]['-'] =$pdf->AddLink(); - $pdf->SetLink($pdf->PMA_links['doc'][$table]['-'],-1); - $pdf->SetFont('', 'B',18); - $pdf->Cell(0,8, $z .' '.$table,1,1,'C',0,$pdf->PMA_links['RT'][$table]['-']); - $pdf->SetFont('', '',8); + $pdf->SetAlias('{' . sprintf("%02d", $z) . '}', $pdf->PageNo()) ; + $pdf->PMA_links['RT'][$table]['-'] = $pdf->AddLink(); + $pdf->SetLink($pdf->PMA_links['doc'][$table]['-'], -1); + $pdf->SetFont('', 'B', 18); + $pdf->Cell(0, 8, $z . ' ' . $table, 1, 1, 'C', 0, $pdf->PMA_links['RT'][$table]['-']); + $pdf->SetFont('', '', 8); $pdf->ln(); - $cfgRelation = PMA_getRelationsParam(); + $cfgRelation = PMA_getRelationsParam(); if ($cfgRelation['commwork'] || PMA_MYSQL_INT_VERSION >= 40100) { $comments = PMA_getComments($db, $table); } @@ -1281,71 +1148,65 @@ function PMA_RT_DOC($alltables ){ $mime_map = PMA_getMIME($db, $table, true); } - /** * Gets table informations */ - $result = PMA_DBI_query('SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\';', NULL, PMA_DBI_QUERY_STORE); - $showtable = PMA_DBI_fetch_assoc($result); - $num_rows = (isset($showtable['Rows']) ? $showtable['Rows'] : 0); + $result = PMA_DBI_query('SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, true) . '\';', null, PMA_DBI_QUERY_STORE); + $showtable = PMA_DBI_fetch_assoc($result); + $num_rows = (isset($showtable['Rows']) ? $showtable['Rows'] : 0); $show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : ''); - $create_time = (isset($showtable['Create_time']) ? PMA_localisedDate(strtotime($showtable['Create_time'])) : ''); - $update_time = (isset($showtable['Update_time']) ? PMA_localisedDate(strtotime($showtable['Update_time'])) : ''); - $check_time = (isset($showtable['Check_time']) ? PMA_localisedDate(strtotime($showtable['Check_time'])) : ''); + $create_time = (isset($showtable['Create_time']) ? PMA_localisedDate(strtotime($showtable['Create_time'])) : ''); + $update_time = (isset($showtable['Update_time']) ? PMA_localisedDate(strtotime($showtable['Update_time'])) : ''); + $check_time = (isset($showtable['Check_time']) ? PMA_localisedDate(strtotime($showtable['Check_time'])) : ''); PMA_DBI_free_result($result); unset($result); - /** * Gets table keys and retains them */ - $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';'); - $primary = ''; - $indexes = array(); - $lastIndex = ''; + $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';'); + $primary = ''; + $indexes = array(); + $lastIndex = ''; $indexes_info = array(); $indexes_data = array(); - $pk_array = array(); // will be use to emphasis prim. keys in the table - // view + $pk_array = array(); // will be use to emphasis prim. keys in the table + // view while ($row = PMA_DBI_fetch_assoc($result)) { // Backups the list of primary keys if ($row['Key_name'] == 'PRIMARY') { - $primary .= $row['Column_name'] . ', '; + $primary .= $row['Column_name'] . ', '; $pk_array[$row['Column_name']] = 1; } // Retains keys informations - if ($row['Key_name'] != $lastIndex ){ + if ($row['Key_name'] != $lastIndex) { $indexes[] = $row['Key_name']; $lastIndex = $row['Key_name']; } - $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index']; - $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique']; + $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index']; + $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique']; if (isset($row['Cardinality'])) { $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality']; } // I don't know what does following column mean.... // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed']; - $indexes_info[$row['Key_name']]['Comment'] = $row['Comment']; + $indexes_info[$row['Key_name']]['Comment'] = $row['Comment']; - $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name']; + $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name']; if (isset($row['Sub_part'])) { $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part']; } - } // end while if ($result) { PMA_DBI_free_result($result); } - /** * Gets fields properties */ - $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';', NULL, PMA_DBI_QUERY_STORE); - $fields_cnt = PMA_DBI_num_rows($result); - - + $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE); + $fields_cnt = PMA_DBI_num_rows($result); // Check if we can use Relations (Mike Beck) if (!empty($cfgRelation['relation'])) { // Find which tables are related with the current one and write it in @@ -1353,56 +1214,53 @@ function PMA_RT_DOC($alltables ){ $res_rel = PMA_getForeigners($db, $table); if (count($res_rel) > 0) { - $have_rel = TRUE; + $have_rel = true; } else { - $have_rel = FALSE; + $have_rel = false; } - } - else { - $have_rel = FALSE; + } else { + $have_rel = false; } // end if - - /** * Displays the comments of the table if MySQL >= 3.23 */ $break = false; if (!empty($show_comment)) { - $pdf->Cell(0,3,$GLOBALS['strTableComments'] . ' : ' . $show_comment,0,1); + $pdf->Cell(0, 3, $GLOBALS['strTableComments'] . ' : ' . $show_comment, 0, 1); $break = true; } if (!empty($create_time)) { - $pdf->Cell(0,3,$GLOBALS['strStatCreateTime'] . ': ' . $create_time,0,1); + $pdf->Cell(0, 3, $GLOBALS['strStatCreateTime'] . ': ' . $create_time, 0, 1); $break = true; } if (!empty($update_time)) { - $pdf->Cell(0,3,$GLOBALS['strStatUpdateTime'] . ': ' . $update_time,0,1); + $pdf->Cell(0, 3, $GLOBALS['strStatUpdateTime'] . ': ' . $update_time, 0, 1); $break = true; } if (!empty($check_time)) { - $pdf->Cell(0,3,$GLOBALS['strStatCheckTime'] . ': ' . $check_time,0,1); + $pdf->Cell(0, 3, $GLOBALS['strStatCheckTime'] . ': ' . $check_time, 0, 1); $break = true; } if ($break == true) { - $pdf->Cell(0,3,'',0,1); + $pdf->Cell(0, 3, '', 0, 1); $pdf->Ln(); } $i = 0; $pdf->SetFont('', 'B'); if (isset($orientation) && $orientation == 'L') { - $pdf->Cell(25,8,ucfirst($GLOBALS['strField']),1,0,'C'); - $pdf->Cell(20,8,ucfirst($GLOBALS['strType']),1,0,'C'); - $pdf->Cell(20,8,ucfirst($GLOBALS['strAttr']),1,0,'C'); - $pdf->Cell(10,8,ucfirst($GLOBALS['strNull']),1,0,'C'); - $pdf->Cell(20,8,ucfirst($GLOBALS['strDefault']),1,0,'C'); - $pdf->Cell(25,8,ucfirst($GLOBALS['strExtra']),1,0,'C'); - $pdf->Cell(45,8,ucfirst($GLOBALS['strLinksTo']),1,0,'C'); + $pdf->Cell(25, 8, ucfirst($GLOBALS['strField']), 1, 0, 'C'); + $pdf->Cell(20, 8, ucfirst($GLOBALS['strType']), 1, 0, 'C'); + $pdf->Cell(20, 8, ucfirst($GLOBALS['strAttr']), 1, 0, 'C'); + $pdf->Cell(10, 8, ucfirst($GLOBALS['strNull']), 1, 0, 'C'); + $pdf->Cell(20, 8, ucfirst($GLOBALS['strDefault']), 1, 0, 'C'); + $pdf->Cell(25, 8, ucfirst($GLOBALS['strExtra']), 1, 0, 'C'); + $pdf->Cell(45, 8, ucfirst($GLOBALS['strLinksTo']), 1, 0, 'C'); if ($paper == 'A4') { $comments_width = 67; @@ -1411,20 +1269,20 @@ function PMA_RT_DOC($alltables ){ // TODO: find optimal width for all formats $comments_width = 50; } - $pdf->Cell($comments_width,8,ucfirst($GLOBALS['strComments']),1,0,'C'); - $pdf->Cell(45,8,'MIME',1,1,'C'); - $pdf->SetWidths(array(25,20,20,10,20,25,45,$comments_width,45)); + $pdf->Cell($comments_width, 8, ucfirst($GLOBALS['strComments']), 1, 0, 'C'); + $pdf->Cell(45, 8, 'MIME', 1, 1, 'C'); + $pdf->SetWidths(array(25, 20, 20, 10, 20, 25, 45, $comments_width, 45)); } else { - $pdf->Cell(20,8,ucfirst($GLOBALS['strField']),1,0,'C'); - $pdf->Cell(20,8,ucfirst($GLOBALS['strType']),1,0,'C'); - $pdf->Cell(20,8,ucfirst($GLOBALS['strAttr']),1,0,'C'); - $pdf->Cell(10,8,ucfirst($GLOBALS['strNull']),1,0,'C'); - $pdf->Cell(15,8,ucfirst($GLOBALS['strDefault']),1,0,'C'); - $pdf->Cell(15,8,ucfirst($GLOBALS['strExtra']),1,0,'C'); - $pdf->Cell(30,8,ucfirst($GLOBALS['strLinksTo']),1,0,'C'); - $pdf->Cell(30,8,ucfirst($GLOBALS['strComments']),1,0,'C'); - $pdf->Cell(30,8,'MIME',1,1,'C'); - $pdf->SetWidths(array(20,20,20,10,15,15,30,30,30)); + $pdf->Cell(20, 8, ucfirst($GLOBALS['strField']), 1, 0, 'C'); + $pdf->Cell(20, 8, ucfirst($GLOBALS['strType']), 1, 0, 'C'); + $pdf->Cell(20, 8, ucfirst($GLOBALS['strAttr']), 1, 0, 'C'); + $pdf->Cell(10, 8, ucfirst($GLOBALS['strNull']), 1, 0, 'C'); + $pdf->Cell(15, 8, ucfirst($GLOBALS['strDefault']), 1, 0, 'C'); + $pdf->Cell(15, 8, ucfirst($GLOBALS['strExtra']), 1, 0, 'C'); + $pdf->Cell(30, 8, ucfirst($GLOBALS['strLinksTo']), 1, 0, 'C'); + $pdf->Cell(30, 8, ucfirst($GLOBALS['strComments']), 1, 0, 'C'); + $pdf->Cell(30, 8, 'MIME', 1, 1, 'C'); + $pdf->SetWidths(array(20, 20, 20, 10, 15, 15, 30, 30, 30)); } $pdf->SetFont('', ''); @@ -1432,31 +1290,31 @@ function PMA_RT_DOC($alltables ){ $bgcolor = ($i % 2) ?$GLOBALS['cfg']['BgcolorOne'] : $GLOBALS['cfg']['BgcolorTwo']; $i++; - $type = $row['Type']; + $type = $row['Type']; // reformat mysql query output - staybyte - 9. June 2001 // loic1: set or enum types: slashes single quotes inside options if (preg_match('@^(set|enum)\((.+)\)$@i', $type, $tmp = array())) { - $tmp[2] = substr(preg_replace("@([^,])''@", "\\1\\'", ',' . $tmp[2]), 1); - $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')'; - $type_nowrap = ''; + $tmp[2] = substr(preg_replace("@([^,])''@", "\\1\\'", ',' . $tmp[2]), 1); + $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')'; + $type_nowrap = ''; - $binary = 0; - $unsigned = 0; - $zerofill = 0; + $binary = 0; + $unsigned = 0; + $zerofill = 0; } else { - $type_nowrap = ' nowrap="nowrap"'; - $type = preg_replace('@BINARY@i', '', $type); - $type = preg_replace('@ZEROFILL@i', '', $type); - $type = preg_replace('@UNSIGNED@i', '', $type); + $type_nowrap = ' nowrap="nowrap"'; + $type = preg_replace('@BINARY@i', '', $type); + $type = preg_replace('@ZEROFILL@i', '', $type); + $type = preg_replace('@UNSIGNED@i', '', $type); if (empty($type)) { - $type = ' '; + $type = ' '; } - $binary = stristr($row['Type'], 'BINARY'); - $unsigned = stristr($row['Type'], 'UNSIGNED'); - $zerofill = stristr($row['Type'], 'ZEROFILL'); + $binary = stristr($row['Type'], 'BINARY'); + $unsigned = stristr($row['Type'], 'UNSIGNED'); + $zerofill = stristr($row['Type'], 'ZEROFILL'); } - $strAttribute = ' '; + $strAttribute = ' '; if ($binary) { $strAttribute = 'BINARY'; } @@ -1472,69 +1330,72 @@ function PMA_RT_DOC($alltables ){ } } $field_name = $row['Field']; - //$pdf->Ln(); - $pdf->PMA_links['RT'][$table][$field_name] =$pdf->AddLink(); - $pdf->Bookmark($field_name,1,-1); - $pdf->SetLink($pdf->PMA_links['doc'][$table][$field_name],-1); - $pdf_row = array($field_name , - $type , - $strAttribute , - ($row['Null'] == '' || $row['Null'] == 'NO') ? $GLOBALS['strNo'] : $GLOBALS['strYes'], - ((isset($row['Default'])) ? $row['Default'] : ''), - $row['Extra'] , - ((isset($res_rel[$field_name])) ? $res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'] : ''), - ((isset($comments[$field_name])) ? $comments[$field_name] : '' ), - ((isset($mime_map) && isset($mime_map[$field_name])) ? str_replace('_', '/', $mime_map[$field_name]['mimetype']) : '' ) - ); + // $pdf->Ln(); + $pdf->PMA_links['RT'][$table][$field_name] = $pdf->AddLink(); + $pdf->Bookmark($field_name, 1, -1); + $pdf->SetLink($pdf->PMA_links['doc'][$table][$field_name], -1); + $pdf_row = array($field_name, + $type, + $strAttribute, + ($row['Null'] == '' || $row['Null'] == 'NO') ? $GLOBALS['strNo'] : $GLOBALS['strYes'], + ((isset($row['Default'])) ? $row['Default'] : ''), + $row['Extra'], + ((isset($res_rel[$field_name])) ? $res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'] : ''), + ((isset($comments[$field_name])) ? $comments[$field_name] : ''), + ((isset($mime_map) && isset($mime_map[$field_name])) ? str_replace('_', '/', $mime_map[$field_name]['mimetype']) : '') + ); $links[0] = $pdf->PMA_links['RT'][$table][$field_name]; if (isset($res_rel[$field_name]['foreign_table']) AND - isset($res_rel[$field_name]['foreign_field']) AND - isset($pdf->PMA_links['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']]) - ) $links[6] = $pdf->PMA_links['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']]; - else unset($links[6]); + isset($res_rel[$field_name]['foreign_field']) AND + isset($pdf->PMA_links['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']]) + ) + { + $links[6] = $pdf->PMA_links['doc'][$res_rel[$field_name]['foreign_table']][$res_rel[$field_name]['foreign_field']]; + } else { + unset($links[6]); + } $pdf->Row($pdf_row, $links); - /*$pdf->Cell(20,8,$field_name,1,0,'L',0,$pdf->PMA_links['RT'][$table][$field_name]); + /*$pdf->Cell(20, 8, $field_name, 1, 0, 'L', 0, $pdf->PMA_links['RT'][$table][$field_name]); //echo ' ' . $field_name . ' ' . "\n"; } - $pdf->Cell(20,8,$type,1,0,'L'); - $pdf->Cell(20,8,$strAttribute,1,0,'L'); - $pdf->Cell(15,8,,1,0,'L'); - $pdf->Cell(15,8,((isset($row['Default'])) ? $row['Default'] : ''),1,0,'L'); - $pdf->Cell(15,8,$row['Extra'],1,0,'L'); + $pdf->Cell(20, 8, $type, 1, 0, 'L'); + $pdf->Cell(20, 8, $strAttribute, 1, 0, 'L'); + $pdf->Cell(15, 8, , 1, 0, 'L'); + $pdf->Cell(15, 8, ((isset($row['Default'])) ? $row['Default'] : ''),1,0,'L'); + $pdf->Cell(15, 8, $row['Extra'], 1, 0, 'L'); if ($have_rel) { if (isset($res_rel[$field_name])) { - $pdf->Cell(30,8,$res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'],1,0,'L'); + $pdf->Cell(30, 8, $res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'],1,0,'L'); } } if ($cfgRelation['commwork']) { if (isset($comments[$field_name])) { - $pdf->Cell(0,8,$comments[$field_name],1,0,'L'); + $pdf->Cell(0, 8, $comments[$field_name], 1, 0, 'L'); } } */ } // end while - $pdf->SetFont('', '',14); + $pdf->SetFont('', '', 14); PMA_DBI_free_result($result); - }//end each - - + } //end each } // end function PMA_RT_DOC - /** * Main logic */ if (!isset($pdf_page_number)) { - $pdf_page_number = 1; + $pdf_page_number = 1; } -$show_grid = (isset($show_grid) && $show_grid == 'on') ? 1 : 0; -$show_color = (isset($show_color) && $show_color == 'on') ? 1 : 0; -$show_table_dimension = (isset($show_table_dimension) && $show_table_dimension == 'on') ? 1 : 0; -$all_tab_same_wide = (isset($all_tab_same_wide) && $all_tab_same_wide == 'on') ? 1 : 0; -$with_doc = (isset($with_doc) && $with_doc == 'on') ? 1 : 0; -$orientation = (isset($orientation) && $orientation == 'P') ? 'P' : 'L'; -$paper = isset($paper) ? $paper : 'A4'; + +$show_grid = (isset($show_grid) && $show_grid == 'on') ? 1 : 0; +$show_color = (isset($show_color) && $show_color == 'on') ? 1 : 0; +$show_table_dimension = (isset($show_table_dimension) && $show_table_dimension == 'on') ? 1 : 0; +$all_tab_same_wide = (isset($all_tab_same_wide) && $all_tab_same_wide == 'on') ? 1 : 0; +$with_doc = (isset($with_doc) && $with_doc == 'on') ? 1 : 0; +$orientation = (isset($orientation) && $orientation == 'P') ? 'P' : 'L'; +$paper = isset($paper) ? $paper : 'A4'; PMA_DBI_select_db($db); $rt = new PMA_RT($pdf_page_number, $show_table_dimension, $show_color, $show_grid, $all_tab_same_wide, $orientation, $paper); + ?> diff --git a/scripts/decode_bug.php b/scripts/decode_bug.php index 16d1b8d29b..589f149922 100644 --- a/scripts/decode_bug.php +++ b/scripts/decode_bug.php @@ -93,8 +93,7 @@ if (!empty($bug_encoded)) { } else { $result = 'Error: "gzuncompress()" is unavailable!' . "\n"; } - } - else { + } else { $result = PMA_printDecodedBug($bug_decoded); } // end if... else... diff --git a/scripts/setup.php b/scripts/setup.php index bbc2bf9e15..53dde2ed1e 100644 --- a/scripts/setup.php +++ b/scripts/setup.php @@ -339,7 +339,7 @@ function get_action($name, $title, $added = '', $enabled = TRUE) { function get_url_action($url, $title, $params = array()) { $ret = ''; $ret .= '<form class="action" method="GET" action="' . $url . '" target="_blank">'; - foreach($params as $key => $val) { + foreach ($params as $key => $val) { $ret .= '<input type="hidden" name="' . $key . '" value="' . $val . '" />'; } $ret .= '<input type="submit" value="' . $title . '" />'; @@ -418,7 +418,7 @@ function get_cfg_val($name, $val) { $ret = ''; if (is_array($val)) { $ret .= "\n"; - foreach($val as $k => $v) { + foreach ($val as $k => $v) { if (!isset($type)) { if (is_string($k)) { $type = 'string'; @@ -463,9 +463,9 @@ function get_cfg_string($cfg) { if (count($c['Servers']) > 0) { $ret .= "/* Servers configuration */\n\$i = 0;\n"; - foreach($c['Servers'] as $cnt => $srv) { + foreach ($c['Servers'] as $cnt => $srv) { $ret .= "\n/* Server " . get_server_name($srv, $cnt) . " */\n\$i++;\n"; - foreach($srv as $key => $val) { + foreach ($srv as $key => $val) { $ret .= get_cfg_val("\$cfg['Servers'][\$i]['$key']", $val); } } @@ -473,7 +473,7 @@ function get_cfg_string($cfg) { } unset($c['Servers']); - foreach($c as $key => $val) { + foreach ($c as $key => $val) { $ret .= get_cfg_val("\$cfg['$key']", $val); } @@ -510,12 +510,15 @@ function compress_servers(&$cfg) { * * @return array array with grabbed values */ -function grab_values($list) { +function grab_values($list) +{ $a = split(';', $list); $res = array(); - foreach($a as $val) { + foreach ($a as $val) { $v = split(':', $val); - if (!isset($v[1])) $v[1] = ''; + if (!isset($v[1])) { + $v[1] = ''; + } switch($v[1]) { case 'bool': $res[$v[0]] = isset($_POST[$v[0]]); @@ -535,7 +538,7 @@ function grab_values($list) { $cur = $_POST[$v[0]]; if ($cur == 'TRUE') { $res[$v[0]] = TRUE; - } else if ($cur == 'FALSE') { + } elseif ($cur == 'FALSE') { $res[$v[0]] = FALSE; } else { $res[$v[0]] = $cur; @@ -566,7 +569,7 @@ function grab_values($list) { function show_overview($title, $list, $buttons = '') { echo '<fieldset class="overview">' . "\n"; echo '<legend>' . $title . '</legend>' . "\n"; - foreach($list as $val) { + foreach ($list as $val) { echo '<div class="row">'; echo '<div class="desc">'; echo $val[0]; @@ -605,18 +608,24 @@ function show_overview($title, $list, $buttons = '') { function show_config_form($list, $legend, $help, $defaults = array(), $save = '', $prefix = '') { global $PMA_Config; - if (empty($save)) $save = 'Update'; + if (empty($save)) { + $save = 'Update'; + } echo '<fieldset class="optbox">' . "\n"; echo '<legend>' . $legend . '</legend>' . "\n"; echo '<p>' . $help . '</p>' . "\n"; - foreach($list as $val) { + foreach ($list as $val) { echo '<div class="opts">'; $type = 'text'; if (isset($val[3])) { - if (is_array($val[3])) $type = 'select'; - elseif (is_bool($val[3])) $type = 'check'; - elseif ($val[3] == 'password') $type = 'password'; + if (is_array($val[3])) { + $type = 'select'; + } elseif (is_bool($val[3])) { + $type = 'check'; + } elseif ($val[3] == 'password') { + $type = 'password'; + } } switch ($type) { case 'text': @@ -866,7 +875,7 @@ function show_server_form($defaults = array(), $number = FALSE) { echo '<input type="hidden" name="server" value="' . $number . '" />'; } $hi = array ('bookmarktable', 'relation', 'table_info', 'table_coords', 'pdf_pages', 'column_info', 'history', 'AllowDeny'); - foreach($hi as $k) { + foreach ($hi as $k) { if (isset($defaults[$k]) && (!is_string($defaults[$k]) || strlen($defaults[$k]) > 0)) { echo '<input type="hidden" name="' . $k . '" value="' . htmlspecialchars(serialize($defaults[$k])) . '" />'; } @@ -1078,7 +1087,9 @@ function show_window_form($defaults = array()) { * @return string HTML for server selection */ function get_server_selection($cfg) { - if (count($cfg['Servers']) == 0) return ''; + if (count($cfg['Servers']) == 0) { + return ''; + } $ret = '<select name="server">'; foreach ($cfg['Servers'] as $key => $val) { $ret .= '<option value="' . $key . '">' . get_server_name($val, $key) . '</option>'; @@ -1287,7 +1298,7 @@ switch ($action) { } if (function_exists('mysqli_get_client_info')) { $defaults['extension'] = 'mysqli'; - } else if (function_exists('mysql_get_client_info')) { + } elseif (function_exists('mysql_get_client_info')) { $defaults['extension'] = 'mysql'; } else { message('warning', 'Could not load neither mysql nor mysqli extension, you might not be able to use phpMyAdmin!'); @@ -1300,11 +1311,15 @@ switch ($action) { show_server_form($defaults); break; case 'editserver': - if (!isset($_POST['server'])) footer(); + if (!isset($_POST['server'])) { + footer(); + } show_server_form($configuration['Servers'][$_POST['server']], $_POST['server']); break; case 'deleteserver': - if (!isset($_POST['server'])) footer(); + if (!isset($_POST['server'])) { + footer(); + } message('notice', 'Deleted server ' . get_server_name($configuration['Servers'][$_POST['server']], $_POST['server'])); unset($configuration['Servers'][$_POST['server']]); compress_servers($configuration); @@ -1314,7 +1329,7 @@ switch ($action) { if (count($configuration['Servers']) == 0) { message('notice', 'No servers defined, so none can be shown'); } else { - foreach($configuration['Servers'] as $i => $srv) { + foreach ($configuration['Servers'] as $i => $srv) { $data = array(); if (!empty($srv['verbose'])) { $data[] = array('Verbose name', $srv['verbose']); @@ -1434,7 +1449,7 @@ switch ($action) { if (!isset($d['RecodingEngine'])) { if (@extension_loaded('iconv')) { $d['RecodingEngine'] = 'iconv'; - } else if (@extension_loaded('recode')) { + } elseif (@extension_loaded('recode')) { $d['RecodingEngine'] = 'recode'; } else { PMA_dl('iconv'); diff --git a/scripts/upgrade.pl b/scripts/upgrade.pl index 0962285328..d7ec7ca84a 100755 --- a/scripts/upgrade.pl +++ b/scripts/upgrade.pl @@ -77,7 +77,7 @@ if (open(LATEST, "wget -o /dev/null -O - $source_url|")) { my $i = 0; - while(my $line = <LATEST>) { + while (my $line = <LATEST>) { chomp($line); if ($line =~ /http/) { $urls[$i++] = $line; @@ -107,7 +107,7 @@ if (open(DEFINES, $targetdirectory .'/libraries/Config.class.php')) { my $versionStatus = 0; $installedversion = "unknownversion"; - while(my $line = <DEFINES>) { + while (my $line = <DEFINES>) { next unless $line =~ /'PMA_VERSION',\ '(.*)?'\);$/; $installedversion = $1; diff --git a/server_binlog.php b/server_binlog.php index e525206519..43f26280a7 100644 --- a/server_binlog.php +++ b/server_binlog.php @@ -24,7 +24,9 @@ echo '<h2>' . "\n" . ' ' . $strBinaryLog . "\n" . '</h2>' . "\n"; -if (!isset($log)) $log = ''; +if (!isset($log)) { + $log = ''; +} /** * Display log selector. @@ -35,7 +37,7 @@ if (count($binary_logs) > 1) { echo '<fieldset><legend>'; echo $strSelectBinaryLog; echo '</legend><select name="log">'; - foreach($binary_logs as $name) { + foreach ($binary_logs as $name) { echo '<option value="' . $name . '"' . ($name == $log ? ' selected="selected"' : '') . '>' . $name . '</option>'; } echo '</select>'; @@ -48,7 +50,9 @@ if (count($binary_logs) > 1) { $sql_query = 'SHOW BINLOG EVENTS'; -if (!empty($log)) $sql_query .= ' IN \'' . $log . '\''; +if (!empty($log)) { + $sql_query .= ' IN \'' . $log . '\''; +} /** * Sends the query and buffers the result diff --git a/server_databases.php b/server_databases.php index 56f4bea1d1..a01a37e050 100644 --- a/server_databases.php +++ b/server_databases.php @@ -110,8 +110,8 @@ echo '<h2>' . "\n" /** * Gets the databases list */ -if ( $server > 0 ) { - $databases = PMA_DBI_get_databases_full( NULL, $dbstats ); +if ($server > 0) { + $databases = PMA_DBI_get_databases_full(null, $dbstats); } else { $databases = array(); } @@ -120,13 +120,13 @@ if ( $server > 0 ) { /** * Displays the page */ -if ( count($databases) > 0 ) { +if (count($databases) > 0) { // sorts the array usort( $databases, 'PMA_dbCmp' ); // table col order // there is no db specific collation or charset prior 4.1.0 - if ( PMA_MYSQL_INT_VERSION >= 40100 ) { + if (PMA_MYSQL_INT_VERSION >= 40100) { $column_order['DEFAULT_COLLATION_NAME'] = array( 'disp_name' => $strCollation, 'description_function' => 'PMA_getCollationDescr', diff --git a/server_privileges.php b/server_privileges.php index dfad93ca16..a039f423cc 100644 --- a/server_privileges.php +++ b/server_privileges.php @@ -120,7 +120,7 @@ function PMA_extractPrivInfo($row = '', $enableHTML = FALSE) $GLOBALS['userlink'] ); $row1 = PMA_DBI_fetch_assoc($res); PMA_DBI_free_result($res); - $av_grants = explode ('\',\'' , substr($row1['Type'], 5, strlen($row1['Type']) - 7)); + $av_grants = explode ('\',\'', substr($row1['Type'], 5, strlen($row1['Type']) - 7)); unset($row1); $users_grants = explode(',', $row['Table_priv']); foreach ($av_grants as $current_grant) { @@ -158,7 +158,7 @@ function PMA_extractPrivInfo($row = '', $enableHTML = FALSE) } else { $privs[] = 'USAGE'; } - } else if ($allPrivileges && (!isset($GLOBALS['grant_count']) || count($privs) == $GLOBALS['grant_count'])) { + } elseif ($allPrivileges && (!isset($GLOBALS['grant_count']) || count($privs) == $GLOBALS['grant_count'])) { if ($enableHTML) { $privs = array('<dfn title="' . $GLOBALS['strPrivDescAllPrivileges'] . '">ALL PRIVILEGES</dfn>'); } else { @@ -255,7 +255,7 @@ function PMA_displayPrivTable($db = '*', $table = '*', $submit = TRUE, $indent = if ($table == '*') { if ($db == '*') { $sql_query = 'SHOW COLUMNS FROM `mysql`.`user`;'; - } else if ($table == '*') { + } elseif ($table == '*') { $sql_query = 'SHOW COLUMNS FROM `mysql`.`db`;'; } $res = PMA_DBI_query($sql_query); @@ -282,7 +282,7 @@ function PMA_displayPrivTable($db = '*', $table = '*', $submit = TRUE, $indent = $row1 = PMA_DBI_fetch_assoc($res); PMA_DBI_free_result($res); - $av_grants = explode ('\',\'' , substr($row1['Type'], strpos($row1['Type'], '(') + 2, strpos($row1['Type'], ')') - strpos($row1['Type'], '(') - 3)); + $av_grants = explode ('\',\'', substr($row1['Type'], strpos($row1['Type'], '(') + 2, strpos($row1['Type'], ')') - strpos($row1['Type'], '(') - 3)); unset($res, $row1); $users_grants = explode(',', $row['Table_priv']); @@ -349,7 +349,7 @@ function PMA_displayPrivTable($db = '*', $table = '*', $submit = TRUE, $indent = // privs that are not attached to a specific column echo $spaces . ' <div class="item">' . "\n"; - foreach($row as $current_grant => $current_grant_value) { + foreach ($row as $current_grant => $current_grant_value) { if (in_array(substr($current_grant, 0, (strlen($current_grant) - 5)), array('Select', 'Insert', 'Update', 'References'))) { continue; } @@ -374,7 +374,7 @@ function PMA_displayPrivTable($db = '*', $table = '*', $submit = TRUE, $indent = echo $spaces . ' <label for="checkbox_' . $current_grant . '"><tt><dfn title="' . (isset($GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5))]) ? $GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5))] : $GLOBALS['strPrivDesc' . substr($tmp_current_grant, 0, (strlen($tmp_current_grant) - 5)) . 'Tbl']) . '">' . strtoupper(substr($current_grant, 0, strlen($current_grant) - 5)) . '</dfn></tt></label>' . "\n" . $spaces . ' </div>' . "\n"; - } // end foreach() + } // end foreach () echo $spaces . ' </div>' . "\n"; // for Safari 2.0.2 @@ -563,15 +563,19 @@ function PMA_displayLoginInformationFields($mode = 'new', $indent = 0 ) { $fields_info = PMA_DBI_get_fields('mysql', 'user'); $username_length = 16; $hostname_length = 41; - foreach($fields_info as $key => $val) { + foreach ($fields_info as $key => $val) { if ($val['Field'] == 'User') { strtok($val['Type'], '()'); $v = strtok('()'); - if (is_int($v)) $username_length = $v; + if (is_int($v)) { + $username_length = $v; + } } elseif ($val['Field'] == 'Host') { strtok($val['Type'], '()'); $v = strtok('()'); - if (is_int($v)) $hostname_length = $v; + if (is_int($v)) { + $hostname_length = $v; + } } } unset($fields_info); @@ -743,7 +747,7 @@ if (!empty($adduser_submit) || !empty($change_copy)) { .' = ' . PMA_convert_using(PMA_sqlAddslashes($username), 'quoted') .' AND ' . PMA_convert_using('Host') .' = ' . PMA_convert_using($hostname, 'quoted') . ';', - NULL, PMA_DBI_QUERY_STORE ); + null, PMA_DBI_QUERY_STORE); if (PMA_DBI_num_rows($res) == 1) { PMA_DBI_free_result($res); $message = sprintf($GLOBALS['strUserAlreadyExists'], '[i]\'' . $username . '\'@\'' . $hostname . '\'[/i]'); @@ -751,7 +755,7 @@ if (!empty($adduser_submit) || !empty($change_copy)) { } else { PMA_DBI_free_result($res); - if ( 50002 <= PMA_MYSQL_INT_VERSION ) { + if (50002 <= PMA_MYSQL_INT_VERSION) { // MySQL 5 requires CREATE USER before any GRANT on this user can done $create_user_real = 'CREATE USER \'' . PMA_sqlAddslashes($username) . '\'@\'' . $hostname . '\''; } @@ -884,7 +888,7 @@ if (!empty($change_copy)) { .' AND ' . PMA_convert_using('`Table_name`') .' = ' . PMA_convert_using($row['Table_name'], 'quoted') .';', - NULL, PMA_DBI_QUERY_STORE ); + null, PMA_DBI_QUERY_STORE); $tmp_privs1 = PMA_extractPrivInfo($row); $tmp_privs2 = array( @@ -1062,9 +1066,9 @@ if (!empty($change_pw)) { $sql_query = 'SET PASSWORD FOR \'' . $username . '\'@\'' . $hostname . '\' = \'\';'; PMA_DBI_query($sql_query); $message = sprintf($GLOBALS['strPasswordChanged'], '\'' . $username . '\'@\'' . $hostname . '\''); - } else if (empty($pma_pw) || empty($pma_pw2)) { + } elseif (empty($pma_pw) || empty($pma_pw2)) { $message = $GLOBALS['strPasswordEmpty']; - } else if ($pma_pw != $pma_pw2) { + } elseif ($pma_pw != $pma_pw2) { $message = $GLOBALS['strPasswordNotSame']; } else { $hidden_pw = ''; @@ -1286,16 +1290,16 @@ if ( empty( $adduser ) && ( ! isset( $checkprivs ) || ! strlen($checkprivs) ) ) $sql_query .= (isset($initial) ? PMA_RangeOfUsers($initial) : ''); $sql_query .= ' ORDER BY `User` ASC, `Host` ASC;'; - $res = PMA_DBI_try_query($sql_query, NULL, PMA_DBI_QUERY_STORE); + $res = PMA_DBI_try_query($sql_query, null, PMA_DBI_QUERY_STORE); - if ( ! $res ) { + if (! $res) { // the query failed! This may have two reasons: // - the user does not have enough privileges // - the privilege tables use a structure of an earlier version. // so let's try a more simple query $sql_query = 'SELECT * FROM `mysql`.`user`'; - $res = PMA_DBI_try_query($sql_query, NULL, PMA_DBI_QUERY_STORE); + $res = PMA_DBI_try_query($sql_query, null, PMA_DBI_QUERY_STORE); if (!$res) { echo '<i>' . $GLOBALS['strNoPrivileges'] . '</i>' . "\n"; @@ -1377,7 +1381,7 @@ if ( empty( $adduser ) && ( ! isset( $checkprivs ) || ! strlen($checkprivs) ) ) } } - $initials = PMA_DBI_try_query('SELECT DISTINCT UPPER(LEFT(' . PMA_convert_using('User') . ',1)) FROM `user` ORDER BY `User` ASC', NULL, PMA_DBI_QUERY_STORE); + $initials = PMA_DBI_try_query('SELECT DISTINCT UPPER(LEFT(' . PMA_convert_using('User') . ',1)) FROM `user` ORDER BY `User` ASC', null, PMA_DBI_QUERY_STORE); while (list($tmp_initial) = PMA_DBI_fetch_row($initials)) { $array_initials[$tmp_initial] = TRUE; } @@ -1557,7 +1561,7 @@ if ( empty( $adduser ) && ( ! isset( $checkprivs ) || ! strlen($checkprivs) ) ) } } echo ' : ' . $GLOBALS['strEditPrivileges'] . '</h2>' . "\n"; - $res = PMA_DBI_query('SELECT \'foo\' FROM `mysql`.`user` WHERE ' . PMA_convert_using('User') . ' = ' . PMA_convert_using(PMA_sqlAddslashes($username), 'quoted') . ' AND ' . PMA_convert_using('Host') . ' = ' . PMA_convert_using($hostname, 'quoted') . ';', NULL, PMA_DBI_QUERY_STORE); + $res = PMA_DBI_query('SELECT \'foo\' FROM `mysql`.`user` WHERE ' . PMA_convert_using('User') . ' = ' . PMA_convert_using(PMA_sqlAddslashes($username), 'quoted') . ' AND ' . PMA_convert_using('Host') . ' = ' . PMA_convert_using($hostname, 'quoted') . ';', null, PMA_DBI_QUERY_STORE); $user_does_not_exists = (PMA_DBI_num_rows( $res ) < 1); PMA_DBI_free_result($res); unset($res); @@ -1842,7 +1846,7 @@ if ( empty( $adduser ) && ( ! isset( $checkprivs ) || ! strlen($checkprivs) ) ) } else { echo ' <input type="hidden" name="dbname" value="' . htmlspecialchars($dbname) . '"/>' . "\n" . ' <label for="text_tablename">' . $GLOBALS['strAddPrivilegesOnTbl'] . ':</label>' . "\n"; - if ($res = @PMA_DBI_try_query('SHOW TABLES FROM ' . PMA_backquote($dbname) . ';', NULL, PMA_DBI_QUERY_STORE)) { + if ($res = @PMA_DBI_try_query('SHOW TABLES FROM ' . PMA_backquote($dbname) . ';', null, PMA_DBI_QUERY_STORE)) { $pred_tbl_array = array(); while ($row = PMA_DBI_fetch_row($res)) { if (!isset($found_rows) || !in_array($row[0], $found_rows)) { @@ -2121,7 +2125,7 @@ if ( empty( $adduser ) && ( ! isset( $checkprivs ) || ! strlen($checkprivs) ) ) } echo '</tbody>' . "\n" . '</table>' . "\n"; -} // end if (empty($adduser) && empty($checkprivs)) ... else if ... else ... +} // end if (empty($adduser) && empty($checkprivs)) ... elseif ... else ... /** diff --git a/server_status.php b/server_status.php index 73278e65d5..3deabe1064 100644 --- a/server_status.php +++ b/server_status.php @@ -304,7 +304,7 @@ foreach ( $server_status as $name => $value ) { unset( $server_status[$name] ); } else { foreach ( $allocations as $filter => $section ) { - if ( preg_match( '°^' . $filter . '°i', $name ) + if ( preg_match( '�^' . $filter . '�i', $name ) && isset( $server_status[$name] ) ) { unset( $server_status[$name] ); $sections[$section]['vars'][$name] = $value; @@ -446,7 +446,7 @@ foreach ( $sections as $section_name => $section ) { $server_status['Connections'] > 0 ? number_format( $server_status['Aborted_clients'] * 100 / $server_status['Connections'], - 2 , $GLOBALS['number_decimal_separator'], + 2, $GLOBALS['number_decimal_separator'], $GLOBALS['number_thousands_separator']) . '%' : '--- '; ?></td> </tr> @@ -276,7 +276,7 @@ else { // Gets the number of rows per page if (empty($session_max_rows)) { $session_max_rows = $cfg['MaxRows']; - } else if ($session_max_rows != 'all') { + } elseif ($session_max_rows != 'all') { $cfg['MaxRows'] = $session_max_rows; } // Defines the display mode (horizontal/vertical) and header "frequency" @@ -303,19 +303,19 @@ else { $is_count = !$is_group && (preg_match('@^SELECT[[:space:]]+COUNT\((.*\.+)?.*\)@i', $sql_query)); $is_export = (preg_match('@[[:space:]]+INTO[[:space:]]+OUTFILE[[:space:]]+@i', $sql_query)); $is_analyse = (preg_match('@[[:space:]]+PROCEDURE[[:space:]]+ANALYSE@i', $sql_query)); - } else if (preg_match('@^EXPLAIN[[:space:]]+@i', $sql_query)) { + } elseif (preg_match('@^EXPLAIN[[:space:]]+@i', $sql_query)) { $is_explain = TRUE; - } else if (preg_match('@^DELETE[[:space:]]+@i', $sql_query)) { + } elseif (preg_match('@^DELETE[[:space:]]+@i', $sql_query)) { $is_delete = TRUE; $is_affected = TRUE; - } else if (preg_match('@^(INSERT|LOAD[[:space:]]+DATA|REPLACE)[[:space:]]+@i', $sql_query)) { + } elseif (preg_match('@^(INSERT|LOAD[[:space:]]+DATA|REPLACE)[[:space:]]+@i', $sql_query)) { $is_insert = TRUE; $is_affected = TRUE; - } else if (preg_match('@^UPDATE[[:space:]]+@i', $sql_query)) { + } elseif (preg_match('@^UPDATE[[:space:]]+@i', $sql_query)) { $is_affected = TRUE; - } else if (preg_match('@^SHOW[[:space:]]+@i', $sql_query)) { + } elseif (preg_match('@^SHOW[[:space:]]+@i', $sql_query)) { $is_show = TRUE; - } else if (preg_match('@^(CHECK|ANALYZE|REPAIR|OPTIMIZE)[[:space:]]+TABLE[[:space:]]+@i', $sql_query)) { + } elseif (preg_match('@^(CHECK|ANALYZE|REPAIR|OPTIMIZE)[[:space:]]+TABLE[[:space:]]+@i', $sql_query)) { $is_maint = TRUE; } @@ -372,15 +372,14 @@ else { if (isset($GLOBALS['show_as_php']) || !empty($GLOBALS['validatequery'])) { unset($result); $num_rows = 0; - } - else { + } else { // garvin: Measure query time. TODO-Item http://sourceforge.net/tracker/index.php?func=detail&aid=571934&group_id=23067&atid=377411 - list($usec, $sec) = explode(' ',microtime()); + list($usec, $sec) = explode(' ', microtime()); $querytime_before = ((float)$usec + (float)$sec); - $result = @PMA_DBI_try_query($full_sql_query, NULL, PMA_DBI_QUERY_STORE); + $result = @PMA_DBI_try_query($full_sql_query, null, PMA_DBI_QUERY_STORE); - list($usec, $sec) = explode(' ',microtime()); + list($usec, $sec) = explode(' ', microtime()); $querytime_after = ((float)$usec + (float)$sec); $GLOBALS['querytime'] = $querytime_after - $querytime_before; @@ -401,7 +400,7 @@ else { if (!$is_affected) { $num_rows = ($result) ? @PMA_DBI_num_rows($result) : 0; - } else if (!isset($num_rows)) { + } elseif (!isset($num_rows)) { $num_rows = @PMA_DBI_affected_rows(); } @@ -409,7 +408,7 @@ else { // This could happen if the user sends a query like "USE `database`;" $res = PMA_DBI_query('SELECT DATABASE() AS \'db\';'); $row = PMA_DBI_fetch_row($res); - if (is_array($row) && isset($row[0]) && (strcasecmp($db,$row[0]) != 0)) { + if (is_array($row) && isset($row[0]) && (strcasecmp($db, $row[0]) != 0)) { $db = $row[0]; $reload = 1; } @@ -430,8 +429,7 @@ else { // if we did not append a limit, set this to get a correct // "Showing rows..." message $GLOBALS['session_max_rows'] = 'all'; - } - else if ($is_select) { + } elseif ($is_select) { // c o u n t q u e r y @@ -465,7 +463,7 @@ else { if (isset($analyzed_sql[0]['queryflags']['distinct'])) { $count_what = 'DISTINCT '; $first_expr = TRUE; - foreach($analyzed_sql[0]['select_expr'] as $part) { + foreach ($analyzed_sql[0]['select_expr'] as $part) { $count_what .= (!$first_expr ? ', ' : '') . $part['expr']; $first_expr = FALSE; } @@ -599,14 +597,14 @@ else { if ($num_rows < 1 || $is_affected) { if ($is_delete) { $message = $strDeletedRows . ' ' . $num_rows; - } else if ($is_insert) { + } elseif ($is_insert) { $message = $strInsertedRows . ' ' . $num_rows; $insert_id = PMA_DBI_insert_id(); if ($insert_id != 0) { // insert_id is id of FIRST record inserted in one insert, so if we inserted multiple rows, we had to increment this $message .= '[br]'.$strInsertedRowId . ' ' . ($insert_id + $num_rows - 1); } - } else if ($is_affected) { + } elseif ($is_affected) { $message = $strAffectedRows . ' ' . $num_rows; // Ok, here is an explanation for the !$is_select. @@ -617,11 +615,11 @@ else { // The $zero_rows containing $strSuccess and sent with // the form should not have priority over // errors like $strEmptyResultSet - } else if (!empty($zero_rows) && !$is_select) { + } elseif (!empty($zero_rows) && !$is_select) { $message = $zero_rows; - } else if (!empty($GLOBALS['show_as_php'])) { + } elseif (!empty($GLOBALS['show_as_php'])) { $message = $strPhp; - } else if (!empty($GLOBALS['validatequery'])) { + } elseif (!empty($GLOBALS['validatequery'])) { $message = $strValidateSQL; } else { $message = $strEmptyResultSet; @@ -643,7 +641,7 @@ else { if (!isset($table)) { $goto = 'db_details.php'; } else { - $is_table = @PMA_DBI_query('SHOW TABLES LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\';', NULL, PMA_DBI_QUERY_STORE); + $is_table = @PMA_DBI_query('SHOW TABLES LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\';', null, PMA_DBI_QUERY_STORE); if (!($is_table && @PMA_DBI_num_rows($is_table))) { $goto = 'db_details.php'; unset($table); @@ -675,8 +673,7 @@ else { } $active_page = $goto; require('./' . $goto); - } // end if file_exist - else { + } else { PMA_sendHeaderLocation($cfg['PmaAbsoluteUri'] . str_replace('&', '&', $goto) . '&message=' . urlencode($message)); } // end else exit(); @@ -747,7 +744,7 @@ else { // BEGIN INDEX CHECK See if indexes should be checked. if (isset($query_type) && $query_type == 'check_tbl' && isset($selected) && is_array($selected)) { - foreach($selected AS $idx => $tbl_name) { + foreach ($selected AS $idx => $tbl_name) { $indexes = $indexes_info = $indexes_data = array(); $tbl_ret_keys = PMA_get_indexes(urldecode($tbl_name), $err_url_0); diff --git a/tbl_addfield.php b/tbl_addfield.php index db42fa4f18..7a66e41d86 100644 --- a/tbl_addfield.php +++ b/tbl_addfield.php @@ -32,7 +32,7 @@ if (isset($submit_num_fields)) { } $num_fields = $orig_num_fields + $added_fields; $regenerate = TRUE; -} else if (isset($do_save_data)) { +} elseif (isset($do_save_data)) { $query = ''; // Transforms the radio button field_key into 3 arrays diff --git a/tbl_change.php b/tbl_change.php index 036175fc3e..1f5be6ebc9 100644 --- a/tbl_change.php +++ b/tbl_change.php @@ -136,7 +136,7 @@ unset($show_create_table); * Get the list of the fields of the current table */ PMA_DBI_select_db($db); -$table_def = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';', NULL, PMA_DBI_QUERY_STORE); +$table_def = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE); if (isset($primary_key)) { if (is_array($primary_key)) { $primary_key_array = $primary_key; @@ -148,7 +148,7 @@ if (isset($primary_key)) { $result = array(); foreach ($primary_key_array AS $rowcount => $primary_key) { $local_query = 'SELECT * FROM ' . PMA_backquote($table) . ' WHERE ' . $primary_key . ';'; - $result[$rowcount] = PMA_DBI_query($local_query, NULL, PMA_DBI_QUERY_STORE); + $result[$rowcount] = PMA_DBI_query($local_query, null, PMA_DBI_QUERY_STORE); $row[$rowcount] = PMA_DBI_fetch_assoc($result[$rowcount]); $primary_keys[$rowcount] = $primary_key; @@ -178,7 +178,7 @@ if (isset($primary_key)) { } // end if (no record returned) } } else { - $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($table) . ' LIMIT 1;', NULL, PMA_DBI_QUERY_STORE); + $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($table) . ' LIMIT 1;', null, PMA_DBI_QUERY_STORE); unset($row); } @@ -212,7 +212,7 @@ document.onkeydown = onKeyDownArrowsHandler; <?php } ?> <!-- Change table properties form --> -<form method="post" action="tbl_replace.php" name="insertForm" <?php if ($is_upload) echo ' enctype="multipart/form-data"'; ?>> +<form method="post" action="tbl_replace.php" name="insertForm" <?php if ($is_upload) { echo ' enctype="multipart/form-data"'; } ?>> <?php echo PMA_generate_common_hidden_inputs($db, $table); ?> <input type="hidden" name="goto" value="<?php echo urlencode($goto); ?>" /> <input type="hidden" name="pos" value="<?php echo isset($pos) ? $pos : 0; ?>" /> @@ -361,7 +361,7 @@ foreach ($loop_array AS $vrowcount => $vrow) { && !isset($row_table_def['Default']) && isset($row_table_def['Null']) && $row_table_def['Null'] == 'YES') { - $row_table_def['Default'] = NULL; + $row_table_def['Default'] = null; } if ($row_table_def['Type'] == 'datetime' @@ -378,7 +378,7 @@ foreach ($loop_array AS $vrowcount => $vrow) { // UPDATE case with an empty and not NULL value under PHP4 elseif (empty($vrow[$rowfield]) && is_null($vrow[$rowfield])) { $vrow[$rowfield] = date('Y-m-d H:i:s', time()); - } // end if... else if... + } // end if... elseif... } $len = (preg_match('@float|double@', $row_table_def['Type'])) ? 100 @@ -484,7 +484,7 @@ foreach ($loop_array AS $vrowcount => $vrow) { if (($cfg['ProtectBinary'] && $is_blob && !$is_upload) || ($cfg['ProtectBinary'] == 'all' && $is_binary)) { echo ' <td align="center" bgcolor="'. $bgcolor . '">' . $strBinary . '</td>' . "\n"; - } else if (strstr($row_table_def['True_Type'], 'enum') || strstr($row_table_def['True_Type'], 'set')) { + } elseif (strstr($row_table_def['True_Type'], 'enum') || strstr($row_table_def['True_Type'], 'set')) { echo ' <td align="center" bgcolor="'. $bgcolor . '">--</td>' . "\n"; } else { ?> @@ -591,9 +591,9 @@ foreach ($loop_array AS $vrowcount => $vrow) { } else { $onclick .= '2, '; } - } else if (strstr($row_table_def['True_Type'], 'set')) { + } elseif (strstr($row_table_def['True_Type'], 'set')) { $onclick .= '3, '; - } else if ($foreigners && isset($foreigners[$field])) { + } elseif ($foreigners && isset($foreigners[$field])) { $onclick .= '4, '; } else { $onclick .= '5, '; @@ -624,7 +624,7 @@ foreach ($loop_array AS $vrowcount => $vrow) { </script> </td> <?php - } else if (isset($disp_row) && is_array($disp_row)) { + } elseif (isset($disp_row) && is_array($disp_row)) { ?> <td bgcolor="<?php echo $bgcolor; ?>"> <?php echo $backup_field . "\n"; ?> @@ -636,8 +636,7 @@ foreach ($loop_array AS $vrowcount => $vrow) { </td> <?php unset($disp_row); - } - else if ($cfg['LongtextDoubleTextarea'] && strstr($type, 'longtext')) { + } elseif ($cfg['LongtextDoubleTextarea'] && strstr($type, 'longtext')) { ?> <td bgcolor="<?php echo $bgcolor; ?>"> </td> </tr> @@ -648,8 +647,7 @@ foreach ($loop_array AS $vrowcount => $vrow) { <?php echo $chg_evt_handler; ?>="return unNullify('<?php echo urlencode($field); ?>', '<?php echo $jsvkey; ?>')" tabindex="<?php echo ($tabindex + $tabindex_for_value); ?>"><?php echo $special_chars; ?></textarea> </td> <?php - } - else if (strstr($type, 'text')) { + } elseif (strstr($type, 'text')) { ?> <td bgcolor="<?php echo $bgcolor; ?>"> <?php echo $backup_field . "\n"; ?> @@ -661,8 +659,7 @@ foreach ($loop_array AS $vrowcount => $vrow) { if (strlen($special_chars) > 32000) { echo ' <td bgcolor="' . $bgcolor . '">' . $strTextAreaLength . '</td>' . "\n"; } - } - else if ($type == 'enum') { + } elseif ($type == 'enum') { $enum = PMA_getEnumSetOptions($row_table_def['Type']); $enum_cnt = count($enum); ?> @@ -698,8 +695,7 @@ foreach ($loop_array AS $vrowcount => $vrow) { ?> </select> <?php - } // end if - else { + } else { echo "\n"; for ($j = 0; $j < $enum_cnt; $j++) { // Removes automatic MySQL escape format @@ -721,8 +717,7 @@ foreach ($loop_array AS $vrowcount => $vrow) { </td> <?php echo "\n"; - } - else if ($type == 'set') { + } elseif ($type == 'set') { $set = PMA_getEnumSetOptions($row_table_def['Type']); if (isset($vset)) { @@ -757,7 +752,7 @@ foreach ($loop_array AS $vrowcount => $vrow) { } // Change by Bernard M. Piller <bernard@bmpsystems.com> // We don't want binary data destroyed - else if ($is_binary || $is_blob) { + elseif ($is_binary || $is_blob) { if (($cfg['ProtectBinary'] && $is_blob) || ($cfg['ProtectBinary'] == 'all' && $is_binary)) { echo "\n"; @@ -775,7 +770,7 @@ foreach ($loop_array AS $vrowcount => $vrow) { <input type="hidden" name="fields_type<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="protected" /> <input type="hidden" name="fields<?php echo $vkey; ?>[<?php echo urlencode($field); ?>]" value="" /> <?php - } else if ($is_blob) { + } elseif ($is_blob) { echo "\n"; ?> <td bgcolor="<?php echo $bgcolor; ?>"> @@ -844,7 +839,7 @@ foreach ($loop_array AS $vrowcount => $vrow) { echo '</td>'; - } // end else if ( binary or blob) + } // end elseif ( binary or blob) else { // For char or varchar, respect the maximum length (M); for other // types (int or float), the length is not a limit on the values that @@ -855,8 +850,7 @@ foreach ($loop_array AS $vrowcount => $vrow) { if ($is_char) { $fieldsize = (($len > 40) ? 40 : $len); $maxlength = $len; - } - else { + } else { $fieldsize = 20; $maxlength = 99; } // end if... else... @@ -948,15 +942,15 @@ if (!empty($disp_message)) { <option value="back" <?php echo $selected_after_insert_back; ?>><?php echo $strAfterInsertBack; ?></option> <option value="new_insert" <?php echo $selected_after_insert_new_insert; ?>><?php echo $strAfterInsertNewInsert; ?></option> <?php -if (isset($primary_key)) -{?> +if (isset($primary_key)) { + ?> <option value="same_insert"><?php echo $strAfterInsertSame; ?></option> -<?php + <?php // If we have just numeric primary key, we can also edit next if (preg_match('@^[\s]*`[^`]*` = [0-9]+@', $primary_key)) { -?> + ?> <option value="edit_next"><?php echo $strAfterInsertNext; ?></option> -<?php + <?php } } ?> diff --git a/tbl_create.php b/tbl_create.php index 793e955e99..40c0b52acf 100644 --- a/tbl_create.php +++ b/tbl_create.php @@ -37,7 +37,7 @@ $abort = FALSE; if (isset($submit_num_fields)) { $regenerate = TRUE; $num_fields = $orig_num_fields + $added_fields; -} else if (isset($do_save_data)) { +} elseif (isset($do_save_data)) { $sql_query = $query_cpy = ''; // Transforms the radio button field_key into 3 arrays diff --git a/tbl_indexes.php b/tbl_indexes.php index 53472423b0..c7ec2e6183 100644 --- a/tbl_indexes.php +++ b/tbl_indexes.php @@ -36,7 +36,7 @@ if (!defined('PMA_IDX_INCLUDED')) { // Not a valid table name -> back to the default db_details sub-page if ( isset($table) && strlen($table) ) { $is_table = PMA_DBI_query('SHOW TABLES LIKE \'' - . PMA_sqlAddslashes($table, TRUE) . '\'', NULL, PMA_DBI_QUERY_STORE); + . PMA_sqlAddslashes($table, TRUE) . '\'', null, PMA_DBI_QUERY_STORE); } if ( ! isset($table) || ! strlen($table) || !( $is_table && PMA_DBI_num_rows($is_table) ) ) { @@ -125,10 +125,10 @@ if (!defined('PMA_IDX_INCLUDED') if ($index_type == 'PRIMARY') { if ($index == '') { $index = 'PRIMARY'; - } else if ($index != 'PRIMARY') { + } elseif ($index != 'PRIMARY') { PMA_mysqlDie($strPrimaryKeyName, '', FALSE, $err_url); } - } else if ($index == 'PRIMARY') { + } elseif ($index == 'PRIMARY') { PMA_mysqlDie($strCantRenameIdxToPrimary, '', FALSE, $err_url); } @@ -191,7 +191,7 @@ if (!defined('PMA_IDX_INCLUDED') /** * Edits an index or defines a new one */ -else if (!defined('PMA_IDX_INCLUDED') +elseif (!defined('PMA_IDX_INCLUDED') && (isset($index) || isset($create_index))) { // Prepares the form values @@ -227,9 +227,9 @@ else if (!defined('PMA_IDX_INCLUDED') || (PMA_MYSQL_INT_VERSION >= 40002 && $edited_index_info['Index_type'] == 'FULLTEXT')) { $index_type = 'FULLTEXT'; - } else if ($index == 'PRIMARY') { + } elseif ($index == 'PRIMARY') { $index_type = 'PRIMARY'; - } else if ($edited_index_info['Non_unique'] == '0') { + } elseif ($edited_index_info['Non_unique'] == '0') { $index_type = 'UNIQUE'; } else { $index_type = 'INDEX'; @@ -343,7 +343,7 @@ else if (!defined('PMA_IDX_INCLUDED') <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>"> <td><select name="column[]"> <option value="--ignore--" - <?php if ('--ignore--' == $selected) echo ' selected="selected"'; ?>> + <?php if ('--ignore--' == $selected) { echo ' selected="selected"'; } ?>> -- <?php echo $strIgnore; ?> --</option> <?php foreach ($fields_names AS $key => $val) { diff --git a/tbl_move_copy.php b/tbl_move_copy.php index 43213f3094..53ccd83ea2 100644 --- a/tbl_move_copy.php +++ b/tbl_move_copy.php @@ -43,11 +43,11 @@ if (isset($new_name) && trim($new_name) != '') { } else { $pma_uri_parts = parse_url($cfg['PmaAbsoluteUri']); if (isset($switch_to_new) && $switch_to_new == 'true') { - setcookie('pma_switch_to_new', 'true', 0, $GLOBALS['cookie_path'], '' , $GLOBALS['is_https']); + setcookie('pma_switch_to_new', 'true', 0, $GLOBALS['cookie_path'], '', $GLOBALS['is_https']); $db = $target_db; $table = $new_name; } else { - setcookie('pma_switch_to_new', '', 0, $GLOBALS['cookie_path'], '' , $GLOBALS['is_https']); + setcookie('pma_switch_to_new', '', 0, $GLOBALS['cookie_path'], '', $GLOBALS['is_https']); } } } diff --git a/tbl_printview.php b/tbl_printview.php index 8e3f1b9842..6ecb51153f 100644 --- a/tbl_printview.php +++ b/tbl_printview.php @@ -44,12 +44,12 @@ PMA_DBI_select_db($db); /** - * Multi-tables printview thanks to Christophe Gesché from the "MySQL Form + * Multi-tables printview thanks to Christophe Gesch� from the "MySQL Form * Generator for PHPMyAdmin" (http://sourceforge.net/projects/phpmysqlformgen/) */ if (isset($selected_tbl) && is_array($selected_tbl)) { $the_tables = $selected_tbl; -} else if (isset($table)) { +} elseif (isset($table)) { $the_tables[] = $table; } $multi_tables = (count($the_tables) > 1); @@ -102,7 +102,7 @@ foreach ($the_tables AS $key => $table) { /** * Gets fields properties */ - $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';', NULL, PMA_DBI_QUERY_STORE); + $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE); $fields_cnt = PMA_DBI_num_rows($result); // Check if we can use Relations (Mike Beck) @@ -116,8 +116,7 @@ foreach ($the_tables AS $key => $table) { } else { $have_rel = FALSE; } - } - else { + } else { $have_rel = FALSE; } // end if @@ -220,7 +219,7 @@ foreach ($the_tables AS $key => $table) { <td width="80" class="print"<?php echo $type_nowrap; ?>><?php echo $type; ?><bdo dir="ltr"></bdo></td> <!--<td width="50" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php echo $strAttribute; ?></td>--> <td width="40" class="print"><?php echo (($row['Null'] == '' || $row['Null'] == 'NO') ? $strNo : $strYes); ?> </td> - <td width="70" class="print" nowrap="nowrap"><?php if (isset($row['Default'])) echo $row['Default']; ?> </td> + <td width="70" class="print" nowrap="nowrap"><?php if (isset($row['Default'])) {7echo $row['Default']; } ?> </td> <!--<td width="50" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php echo $row['Extra']; ?> </td>--> <?php echo "\n"; @@ -413,7 +412,7 @@ foreach ($the_tables AS $key => $table) { echo ' '; if ($showtable['Row_format'] == 'Fixed') { echo $strFixed; - } else if ($showtable['Row_format'] == 'Dynamic') { + } elseif ($showtable['Row_format'] == 'Dynamic') { echo $strDynamic; } else { echo $showtable['Row_format']; diff --git a/tbl_properties_operations.php b/tbl_properties_operations.php index 74ec9af921..b5b23035bb 100644 --- a/tbl_properties_operations.php +++ b/tbl_properties_operations.php @@ -215,7 +215,7 @@ if (strstr($show_comment, '; InnoDB free') === false) { } } else { // remove InnoDB comment from end, just the minimal part (*? is non greedy) - $comment = preg_replace('@; InnoDB free:.*?$@' , '', $show_comment); + $comment = preg_replace('@; InnoDB free:.*?$@', '', $show_comment); } // PACK_KEYS: MyISAM or ISAM diff --git a/tbl_properties_structure.php b/tbl_properties_structure.php index 58d6e7a149..5678fff041 100644 --- a/tbl_properties_structure.php +++ b/tbl_properties_structure.php @@ -75,7 +75,7 @@ while ($row = PMA_DBI_fetch_assoc($result)) { PMA_DBI_free_result($result); // 3. Get fields -$fields_rs = PMA_DBI_query('SHOW FULL FIELDS FROM ' . PMA_backquote($table) . ';', NULL, PMA_DBI_QUERY_STORE); +$fields_rs = PMA_DBI_query('SHOW FULL FIELDS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE); $fields_cnt = PMA_DBI_num_rows($fields_rs); // Get more complete field information @@ -362,7 +362,7 @@ while ($row = PMA_DBI_fetch_assoc($fields_rs)) { <?php echo PMA_MYSQL_INT_VERSION >= 40100 ? ' <td>' . (empty($field_charset) ? '' : '<dfn title="' . PMA_getCollationDescr($field_charset) . '">' . $field_charset . '</dfn>') . '</td>' . "\n" : '' ?> <td nowrap="nowrap" style="font-size: 70%"><?php echo $attribute; ?></td> <td><?php echo (($row['Null'] == 'YES') ? $strYes : $strNo); ?></td> - <td nowrap="nowrap"><?php if (isset($row['Default'])) echo $row['Default']; ?></td> + <td nowrap="nowrap"><?php if (isset($row['Default'])) { echo $row['Default']; } ?></td> <td nowrap="nowrap"><?php echo $row['Extra']; ?></td> <td align="center"> <a href="sql.php?<?php echo $url_query; ?>&sql_query=<?php echo urlencode( 'SELECT COUNT(*) AS `' . $strRows . '`, `' . $row['Field'] . '` FROM `' . $table . '` GROUP BY `' . $row['Field'] . '` ORDER BY `' . $row['Field'] . '`' ); ?>"> @@ -411,7 +411,7 @@ while ($row = PMA_DBI_fetch_assoc($fields_rs)) { } else { echo "\n"; ?> - <a href="sql.php?<?php echo $url_query; ?>&sql_query=<?php echo urlencode('ALTER TABLE ' . PMA_backquote($table) . ' ADD INDEX(' . PMA_backquote($row['Field']) . ')'); ?>&zero_rows=<?php echo urlencode(sprintf($strAnIndex ,htmlspecialchars($row['Field']))); ?>"> + <a href="sql.php?<?php echo $url_query; ?>&sql_query=<?php echo urlencode('ALTER TABLE ' . PMA_backquote($table) . ' ADD INDEX(' . PMA_backquote($row['Field']) . ')'); ?>&zero_rows=<?php echo urlencode(sprintf($strAnIndex, htmlspecialchars($row['Field']))); ?>"> <?php echo $titles['Index']; ?></a> <?php } @@ -425,7 +425,7 @@ while ($row = PMA_DBI_fetch_assoc($fields_rs)) { } else { echo "\n"; ?> - <a href="sql.php?<?php echo $url_query; ?>&sql_query=<?php echo urlencode('ALTER TABLE ' . PMA_backquote($table) . ' ADD UNIQUE(' . PMA_backquote($row['Field']) . ')'); ?>&zero_rows=<?php echo urlencode(sprintf($strAnIndex , htmlspecialchars($row['Field']))); ?>"> + <a href="sql.php?<?php echo $url_query; ?>&sql_query=<?php echo urlencode('ALTER TABLE ' . PMA_backquote($table) . ' ADD UNIQUE(' . PMA_backquote($row['Field']) . ')'); ?>&zero_rows=<?php echo urlencode(sprintf($strAnIndex, htmlspecialchars($row['Field']))); ?>"> <?php echo $titles['Unique']; ?></a> <?php } @@ -438,7 +438,7 @@ while ($row = PMA_DBI_fetch_assoc($fields_rs)) { echo "\n"; ?> <td align="center" nowrap="nowrap"> - <a href="sql.php?<?php echo $url_query; ?>&sql_query=<?php echo urlencode('ALTER TABLE ' . PMA_backquote($table) . ' ADD FULLTEXT(' . PMA_backquote($row['Field']) . ')'); ?>&zero_rows=<?php echo urlencode(sprintf($strAnIndex , htmlspecialchars($row['Field']))); ?>"> + <a href="sql.php?<?php echo $url_query; ?>&sql_query=<?php echo urlencode('ALTER TABLE ' . PMA_backquote($table) . ' ADD FULLTEXT(' . PMA_backquote($row['Field']) . ')'); ?>&zero_rows=<?php echo urlencode(sprintf($strAnIndex, htmlspecialchars($row['Field']))); ?>"> <?php echo $titles['IdxFulltext']; ?></a> </td> <?php @@ -461,7 +461,7 @@ while ($row = PMA_DBI_fetch_assoc($fields_rs)) { echo '</tbody>' . "\n" .'</table>' . "\n"; -$checkall_url = 'tbl_properties_structure.php?' . PMA_generate_common_url($db,$table); +$checkall_url = 'tbl_properties_structure.php?' . PMA_generate_common_url($db, $table); ?> <img class="selectallarrow" src="<?php echo $pmaThemeImage . 'arrow_' . $text_dir . '.png'; ?>" @@ -723,11 +723,9 @@ if ( $cfg['ShowStats'] ) { <td class="value"><?php if ($showtable['Row_format'] == 'Fixed') { echo $strFixed; - } - else if ($showtable['Row_format'] == 'Dynamic') { + } elseif ($showtable['Row_format'] == 'Dynamic') { echo $strDynamic; - } - else { + } else { echo $showtable['Row_format']; } ?></td> diff --git a/tbl_relation.php b/tbl_relation.php index fe2c42d9b9..47feb2655a 100644 --- a/tbl_relation.php +++ b/tbl_relation.php @@ -39,8 +39,8 @@ $options_array = array('CASCADE' => 'CASCADE', 'SET_NULL' => 'SET NULL', 'NO_ACT * * @access public */ -function PMA_generate_dropdown($dropdown_question,$radio_name,$choices,$selected_value) { - +function PMA_generate_dropdown($dropdown_question, $radio_name, $choices, $selected_value) +{ echo $dropdown_question . ' '; echo '<select name="' . $radio_name . '">' . "\n"; @@ -281,7 +281,7 @@ if ($cfgRelation['relwork'] || $tbl_type=='INNODB') { } // [0] of the row is the name - $tab_rs = PMA_DBI_query($tab_query, NULL, PMA_DBI_QUERY_STORE); + $tab_rs = PMA_DBI_query($tab_query, null, PMA_DBI_QUERY_STORE); $selectboxall['nix'] = '--'; $selectboxall_innodb['nix'] = '--'; @@ -290,7 +290,7 @@ if ($cfgRelation['relwork'] || $tbl_type=='INNODB') { PMA_DBI_select_db($db); // need to use PMA_DBI_QUERY_STORE with PMA_DBI_num_rows() in mysqli - $fi_rs = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($curr_table[0]) . ';', NULL, PMA_DBI_QUERY_STORE); + $fi_rs = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($curr_table[0]) . ';', null, PMA_DBI_QUERY_STORE); if ($fi_rs && PMA_DBI_num_rows($fi_rs) > 0) { $seen_a_primary = FALSE; while ($curr_field = PMA_DBI_fetch_assoc($fi_rs)) { @@ -337,7 +337,7 @@ if ($cfgRelation['relwork'] || $tbl_type=='INNODB') { PMA_DBI_select_db($db); // need to use PMA_DBI_QUERY_STORE with PMA_DBI_num_rows() in mysqli - $fi_rs = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($curr_table[0]) . ';', NULL, PMA_DBI_QUERY_STORE); + $fi_rs = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($curr_table[0]) . ';', null, PMA_DBI_QUERY_STORE); if ($fi_rs && PMA_DBI_num_rows($fi_rs) > 0) { while ($curr_field = PMA_DBI_fetch_assoc($fi_rs)) { $field_full = $db . '.' . $curr_field['Table'] . '.' . $curr_field['Column_name']; @@ -358,7 +358,7 @@ if ($cfgRelation['relwork'] || $tbl_type=='INNODB') { // Now find out the columns of our $table // need to use PMA_DBI_QUERY_STORE with PMA_DBI_num_rows() in mysqli -$col_rs = PMA_DBI_try_query('SHOW COLUMNS FROM ' . PMA_backquote($table) . ';', NULL, PMA_DBI_QUERY_STORE); +$col_rs = PMA_DBI_try_query('SHOW COLUMNS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE); if ($col_rs && PMA_DBI_num_rows($col_rs) > 0) { while ($row = PMA_DBI_fetch_assoc($col_rs)) { diff --git a/tbl_replace.php b/tbl_replace.php index bbe5adffa7..f67e44b9db 100644 --- a/tbl_replace.php +++ b/tbl_replace.php @@ -8,7 +8,7 @@ require_once('./libraries/common.lib.php'); // Check parameters -PMA_checkParameters(array('db','table','goto')); +PMA_checkParameters(array('db', 'table', 'goto')); PMA_DBI_select_db($db); @@ -122,7 +122,9 @@ $message = ''; foreach ($loop_array AS $primary_key_index => $enc_primary_key) { // skip fields to be ignored - if (!$using_key && isset($GLOBALS['insert_ignore_' . $enc_primary_key])) continue; + if (!$using_key && isset($GLOBALS['insert_ignore_' . $enc_primary_key])) { + continue; + } // Restore the "primary key" to a convenient format $primary_key = urldecode($enc_primary_key); @@ -155,9 +157,9 @@ foreach ($loop_array AS $primary_key_index => $enc_primary_key) { if (empty($me_funcs[$encoded_key])) { $cur_value = $val . ', '; - } else if (preg_match('@^(UNIX_TIMESTAMP)$@', $me_funcs[$encoded_key]) && $val != '\'\'') { + } elseif (preg_match('@^(UNIX_TIMESTAMP)$@', $me_funcs[$encoded_key]) && $val != '\'\'') { $cur_value = $me_funcs[$encoded_key] . '(' . $val . '), '; - } else if (preg_match('@^(NOW|CURDATE|CURTIME|UNIX_TIMESTAMP|RAND|USER|LAST_INSERT_ID)$@', $me_funcs[$encoded_key])) { + } elseif (preg_match('@^(NOW|CURDATE|CURTIME|UNIX_TIMESTAMP|RAND|USER|LAST_INSERT_ID)$@', $me_funcs[$encoded_key])) { $cur_value = $me_funcs[$encoded_key] . '(), '; } else { $cur_value = $me_funcs[$encoded_key] . '(' . $val . '), '; @@ -166,17 +168,17 @@ foreach ($loop_array AS $primary_key_index => $enc_primary_key) { if ($is_insert) { // insert, no need to add column $valuelist .= $cur_value; - } else if (isset($me_fields_null_prev) && isset($me_fields_null_prev[$encoded_key]) && !isset($me_fields_null[$encoded_key])) { + } elseif (isset($me_fields_null_prev) && isset($me_fields_null_prev[$encoded_key]) && !isset($me_fields_null[$encoded_key])) { // field had the null checkbox // field no longer has the null checkbox // field does not have the same value $valuelist .= PMA_backquote($key) . ' = ' . $cur_value; - } else if (empty($me_funcs[$encoded_key]) + } elseif (empty($me_funcs[$encoded_key]) && isset($me_fields_prev) && isset($me_fields_prev[$encoded_key]) && ("'" . PMA_sqlAddslashes(urldecode($me_fields_prev[$encoded_key])) . "'" == $val)) { // No change for this column and no MySQL function is used -> next column continue; - } else if (!empty($val)) { + } elseif (!empty($val)) { // TODO: avoid setting a field to NULL when it's already NULL $valuelist .= PMA_backquote($key) . ' = ' . $cur_value; } diff --git a/tbl_select.php b/tbl_select.php index 92f866903f..b66ad38d66 100644 --- a/tbl_select.php +++ b/tbl_select.php @@ -49,7 +49,7 @@ if (!isset($param) || $param[0] == '') { $err_url = $goto . '?' . PMA_generate_common_url($db, $table); // Gets the list and number of fields - $result = PMA_DBI_query('SHOW' . (PMA_MYSQL_INT_VERSION >= 40100 ? ' FULL' : '') . ' FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db) . ';', NULL, PMA_DBI_QUERY_STORE); + $result = PMA_DBI_query('SHOW' . (PMA_MYSQL_INT_VERSION >= 40100 ? ' FULL' : '') . ' FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db) . ';', null, PMA_DBI_QUERY_STORE); $fields_cnt = PMA_DBI_num_rows($result); // rabue: we'd better ensure, that all arrays are empty. $fields_list = $fields_null = $fields_type = $fields_collation = array(); diff --git a/transformation_wrapper.php b/transformation_wrapper.php index 944721a972..da1325a358 100644 --- a/transformation_wrapper.php +++ b/transformation_wrapper.php @@ -22,12 +22,12 @@ require_once('./libraries/db_table_exists.lib.php'); * Get the list of the fields of the current table */ PMA_DBI_select_db($db); -$table_def = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table), NULL, PMA_DBI_QUERY_STORE); +$table_def = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table), null, PMA_DBI_QUERY_STORE); if (isset($primary_key)) { - $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($table) . ' WHERE ' . $primary_key . ';', NULL, PMA_DBI_QUERY_STORE); + $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($table) . ' WHERE ' . $primary_key . ';', null, PMA_DBI_QUERY_STORE); $row = PMA_DBI_fetch_assoc($result); } else { - $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($table) . ' LIMIT 1;', NULL, PMA_DBI_QUERY_STORE); + $result = PMA_DBI_query('SELECT * FROM ' . PMA_backquote($table) . ' LIMIT 1;', null, PMA_DBI_QUERY_STORE); $row = PMA_DBI_fetch_assoc($result); } @@ -87,7 +87,7 @@ if (!isset($resize)) { if ($ratioWidth < $ratioHeight){ $destWidth = $srcWidth/$ratioHeight; $destHeight = $newHeight; - }else{ + } else { $destWidth = $newWidth; $destHeight = $srcHeight/$ratioWidth; } @@ -101,7 +101,7 @@ if (!isset($resize)) { ImageCopyResampled( $destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight ); if ($resize == 'jpeg') { - ImageJPEG( $destImage,'',75 ); + ImageJPEG( $destImage, '', 75 ); } if ($resize == 'png') { ImagePNG( $destImage); |