[dev] [patches] displaying zeroes

Francois Marier francois at nit.ca
Fri Jul 30 10:10:30 PDT 2004


Hi,

Here's a few patches fixing a small problem that I noticed while
adding a user called "User 0" to the address book.

Basically, in a lot of the fields we display, if the contents of the
field is just '0', it's not displayed.  The reason is that the "empty()"
PHP function will return true in these cases.

The work-around is to check for (!empty($field) || ($field == '0'))
instead of just !empty($field).  That way, it still returns true for
empty strings but false for a variable containing only 0.

I fixed this small annoyance in Turba, Nag, Mnemo and the
framework.

Francois
-------------- next part --------------
diff -rpuN -X ../ignorelist ../build/framework/Form/Form/Renderer.php framework/Form/Form/Renderer.php
--- ../build/framework/Form/Form/Renderer.php	Wed Jul 21 06:50:08 2004
+++ framework/Form/Form/Renderer.php	Thu Jul 29 19:56:42 2004
@@ -406,7 +406,7 @@ if (document.' . $this->_name . '.' . $t
 
     function _sectionHeader($title, $extra = '')
     {
-        if (!empty($title)) {
+        if (!empty($title) || ($title == '0')) {
             echo '<table border="0" cellpadding="2" cellspacing="0" width="100%">
 <tr><td align="left" class="header"><b>' . $title . '</b></td>';
             if (!empty($extra)) {
-------------- next part --------------
diff -rpuN -X ../ignorelist ../build/mnemo/templates/list/memo_summaries.inc mnemo/templates/list/memo_summaries.inc
--- ../build/mnemo/templates/list/memo_summaries.inc	Mon Jun 28 10:56:12 2004
+++ mnemo/templates/list/memo_summaries.inc	Fri Jul 30 12:55:27 2004
@@ -6,7 +6,7 @@
     <?php endif; ?>
   </td>
   <td nowrap="nowrap" class="linedRow">
-    <?php echo Horde::linkTooltip(Horde::applicationUrl($viewurl), _("View Note Details"), '', '', '', ($memo['body'] != $memo['desc']) ? wordwrap($memo['body']) : '') . ($memo['desc'] ? htmlspecialchars($memo['desc']) : '<i>' . _("Empty Note") . '</i>') ?></a>
+    <?php echo Horde::linkTooltip(Horde::applicationUrl($viewurl), _("View Note Details"), '', '', '', ($memo['body'] != $memo['desc']) ? wordwrap($memo['body']) : '') . ((($memo['desc'] == '0') || !empty($memo['desc'])) ? htmlspecialchars($memo['desc']) : '<i>' . _("Empty Note") . '</i>') ?></a>
   </td>
   <td class="linedRow" style="background-color: <?php echo $color ?>;"><?php echo htmlspecialchars($memo['category'] ? $memo['category'] : _("Unfiled")) ?></td>
 </tr>
-------------- next part --------------
diff -rpuN -X ../ignorelist ../build/nag/templates/list/task_summaries.inc nag/templates/list/task_summaries.inc
--- ../build/nag/templates/list/task_summaries.inc	Sat Jul 24 20:34:45 2004
+++ nag/templates/list/task_summaries.inc	Fri Jul 30 13:00:02 2004
@@ -14,7 +14,7 @@
       <?php echo Horde::link($task['edit_link'], _("Edit Task"), 'widget') . Horde::img('edit.gif', _("Edit Task")) . '</a>' ?>
     <?php endif; ?>
   </td>
-  <td nowrap="nowrap" class="<?php echo $style ?>"><?php $link = empty($task['desc']) ? 'link' : 'linkTooltip'; echo Horde::$link($task['view_link'], _("View Task Details"), $tstyle, '', '', wordwrap($task['desc'])) . (!empty($task['name']) ? htmlspecialchars($task['name']) : _("[none]")) ?></a></td>
+  <td nowrap="nowrap" class="<?php echo $style ?>"><?php $link = empty($task['desc']) ? 'link' : 'linkTooltip'; echo Horde::$link($task['view_link'], _("View Task Details"), $tstyle, '', '', wordwrap($task['desc'])) . ((!empty($task['name']) || ($task['name'] == '0')) ? htmlspecialchars($task['name']) : _("[none]")) ?></a></td>
   <td class="<?php echo $style ?>"><?php echo !empty($task['desc']) ? Horde::img('note.gif', _("Task Note")) : '&nbsp;' ?></td>
   <td class="<?php echo $style ?>"><?php echo (!empty($task['alarm']) && !empty($task['due'])) ?
     Horde::img('alarm.gif', _("Task Alarm")) : '&nbsp;' ?>
-------------- next part --------------
diff -rpuN -X ../ignorelist ../build/turba/lib/Source.php turba/lib/Source.php
--- ../build/turba/lib/Source.php	Fri Feb 20 14:44:54 2004
+++ turba/lib/Source.php	Tue Jul 13 18:56:24 2004
@@ -179,7 +179,7 @@ class Turba_Source {
             foreach ($this->map as $key => $val) {
                 if (!is_array($val)) {
                     $new_entry[$key] = null;
-                    if (isset($entry[$val]) && !empty($entry[$val]) && !is_null($entry[$val])) {
+                    if (isset($entry[$val]) && (($entry[$val] == '0') || !empty($entry[$val])) && !is_null($entry[$val])) {
                         $new_entry[$key] = $entry[$val];
                     }
                 }
diff -rpuN -X ../ignorelist ../build/turba/display.php turba/display.php
--- ../build/turba/display.php	Wed Jun 30 23:41:24 2004
+++ turba/display.php	Thu Jul 29 19:55:42 2004
@@ -83,7 +83,8 @@ foreach ($log->getData() as $entry) {
 $view->setupForm($form);
 
 $vars = &new Variables(array('object' => $vars));
-if ($title = $vars->get('object[name]')) {
+$title = $vars->get('object[name]');
+if (!empty($title) || ($title == '0')) {
     $form->setTitle($title);
 }
 


More information about the dev mailing list