more improvements to printVal
authorchriskl <chriskl>
Mon, 19 May 2003 06:08:07 +0000 (06:08 +0000)
committerchriskl <chriskl>
Mon, 19 May 2003 06:08:07 +0000 (06:08 +0000)
classes/Misc.php
display.php
sql.php
tables.php

index 9e890cccb729936f923995503a841cdf8c832c0b..cc7b2a2a84a0c1275ed2fce512920d9e02881de7 100644 (file)
@@ -2,7 +2,7 @@
        /**
         * Class to hold various commonly used functions
         *
-        * $Id: Misc.php,v 1.32 2003/05/15 09:48:40 chriskl Exp $
+        * $Id: Misc.php,v 1.33 2003/05/19 06:08:07 chriskl Exp $
         */
         
        class Misc {
                /**
                 * Replace all spaces with &nbsp; in a string
                 * @param $str The string to change
+                * @param $shownull True to show NULLs, false otherwise
                 * @return The string with replacements
                 */
-               function printVal($str) {
-                       // If the string contains at least one instance of >1 space in a row, then
+               function printVal($str, $shownull = false) {
+                       // If the string contains at least one instance of >1 space in a row, a tab character, a
+                       // space at the start of a line, or a space at the start of the whole string then
                        // substitute all spaces for &nbsp;s
-                       if ($str === null) return '<i>NULL</i>';
-                       elseif (strstr($str, '  '))
-                               return nl2br(str_replace(' ', '&nbsp;', htmlspecialchars($str)));
+                       if ($str === null && $shownull) return '<i>NULL</i>';
+                       elseif (strstr($str, '  ') || strstr($str, "\t") || strstr($str, "\n ") || ereg('^[ ]', $str)) {
+                               $str = str_replace(' ', '&nbsp;', htmlspecialchars($str));
+                               // Replace tabs with 8 spaces
+                               $str = str_replace("\t", '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', $str);
+                               return nl2br($str);
+                       }
                        else
                                return nl2br(htmlspecialchars($str));
                }
index d90fe4249cc09e04427f1c8423ba16d74fe81f1f..6af57012253e731d1fe739825d787bf5e92f4ea0 100644 (file)
@@ -9,7 +9,7 @@
         * @param $return_desc The return link name
         * @param $page The current page
         *
-        * $Id: display.php,v 1.16 2003/05/18 11:53:27 chriskl Exp $
+        * $Id: display.php,v 1.17 2003/05/19 06:08:07 chriskl Exp $
         */
 
        // Include application functions
@@ -59,7 +59,7 @@
                        $id = (($i % 2) == 0 ? '1' : '2');
                        echo "<tr>\n";
                        foreach ($rs->f as $k => $v) {
-                               echo "<td class=\"data{$id}\">", $misc->printVal($v), "</td>";
+                               echo "<td class=\"data{$id}\">", $misc->printVal($v, true), "</td>";
                        }                                                       
                        echo "</tr>\n";
                        $rs->moveNext();
diff --git a/sql.php b/sql.php
index c6c3b9fdfe42d6cb0ba8afd4fd19144ce23c6658..45a6180a6eaa0fa0d0d68cef8f04fdc47c2dcf6e 100644 (file)
--- a/sql.php
+++ b/sql.php
@@ -8,7 +8,7 @@
         * @param $return_url The return URL
         * @param $return_desc The return link name
         *
-        * $Id: sql.php,v 1.3 2003/05/06 06:17:23 chriskl Exp $
+        * $Id: sql.php,v 1.4 2003/05/19 06:08:07 chriskl Exp $
         */
 
        // Include application functions
@@ -45,7 +45,7 @@
                                        $id = (($i % 2) == 0 ? '1' : '2');
                                        echo "<tr>\n";
                                        foreach ($rs->f as $k => $v) {
-                                               echo "<td class=\"data{$id}\">", $misc->printVal($v), "</td>";
+                                               echo "<td class=\"data{$id}\">", $misc->printVal($v, true), "</td>";
                                        }                                                       
                                        echo "</tr>\n";
                                        $rs->moveNext();
index 2d6b327ae940ba194407bb54c26a9a88cb90fec9..e958ec667da1e7e33e984d3ff9f170f36a7f5997 100644 (file)
@@ -3,7 +3,7 @@
        /**
         * List tables in a database
         *
-        * $Id: tables.php,v 1.23 2003/05/15 14:37:42 chriskl Exp $
+        * $Id: tables.php,v 1.24 2003/05/19 06:08:07 chriskl Exp $
         */
 
        // Include application functions
                                                if ($_REQUEST['strings'] == 'collapsed' && strlen($v) > $conf['max_chars']) {                                                   
                                                        $v = substr($v, 0, $conf['max_chars'] - 1) . $lang['strellipsis'];
                                                }
-                                               echo "<td class=\"data{$id}\" nowrap=\"nowrap\">", $misc->printVal($v), "</td>";
+                                               echo "<td class=\"data{$id}\" nowrap=\"nowrap\">", $misc->printVal($v, true), "</td>";
                                        }
                                }
                                echo "</tr>\n";