[hermes] [patch] Hermes export cleanup

Jason M. Felice jfelice at cronosys.com
Thu Aug 14 11:40:28 PDT 2003


Attached is a patch which cleans up the hermes export screen, which appears
to be older than the Horde_Form API.

The patch contains a file addition and deletion, so watch out when
committing it to CVS.  (I'm working on a patch manager that can handle all
this silly stuff, none of the existing ones do.)

cvs add hermes/lib/Data.php
cvs remove hermes/templates/data/export.inc

-- 
 Jason M. Felice
 Cronosys, LLC <http://www.cronosys.com/>
 216.221.4600 x302
-------------- next part --------------
Index: hermes/data.php
===================================================================
RCS file: /repository/hermes/data.php,v
retrieving revision 1.13
diff -u -r1.13 data.php
--- hermes/data.php	7 Aug 2003 19:43:42 -0000	1.13
+++ hermes/data.php	14 Aug 2003 18:10:35 -0000
@@ -11,6 +11,7 @@
 define('HERMES_BASE', dirname(__FILE__));
 require_once HERMES_BASE . '/lib/base.php';
 require_once HORDE_BASE . '/lib/Data.php';
+require_once HERMES_BASE . '/lib/Data.php';
 
 if (!Auth::isAdmin()) {
     header('Location: ' . Horde::applicationUrl('index.php', true));
@@ -18,21 +19,29 @@
 }
 
 $error = false;
-$actionID = Horde::getFormData('actionID');
 
-switch ($actionID) {
-case 'export':
-    $filters = array('submitted' => 1,
-                     'exported' => 0);
-    if (!Horde::getFormData('export_all')) {
+$vars = &Horde_Form::getDefaultVars();
+switch ($vars->getVar('formname')) {
+case 'hermes_exportform':
+    $filters = array('submitted' => 1);
+    $already_exported = $vars->getVar('already_exported');
+    if (empty($already_exported)) {
+        $filters['exported'] = 0;
+    }
+
+    $span_start = $vars->getVar('span_start');
+    if (!empty($span_start['year'])) {
         $filters['start'] = mktime(0, 0, 0,
-                                   Horde::getFormData('start_month'),
-                                   Horde::getFormData('start_day'),
-                                   Horde::getFormData('start_year'));
+                                   $span_start['month'],
+                                   $span_start['day'],
+                                   $span_start['year'] - 1900);
+    }
+    $span_end = $vars->getVar('span_end');
+    if (!empty($span_end['year'])) {
         $filters['end'] = mktime(0, 0, 0,
-                                 Horde::getFormData('end_month'),
-                                 Horde::getFormData('end_day'),
-                                 Horde::getFormData('end_year'));
+                                 $span_end['month'],
+                                 $span_end['day'],
+                                 $span_end['year'] - 1900);
     }
     $hours = $hermes->getHours($filters);
 
@@ -47,8 +56,9 @@
     require_once HORDE_BASE . '/lib/Identity.php';
 
     $timedata = array();
-    $format = Horde::getPost('format');
+    $format = $vars->getVar('format');
     $data = &Horde_Data::singleton(array('hermes', $format));
+
     $namecache = array();
     switch ($format) {
     case 'iif':
@@ -85,8 +95,9 @@
 require HERMES_TEMPLATES . '/common-header.inc';
 Hermes::menu();
 
-if (is_null($actionID) || $error) {
-    require HERMES_TEMPLATES . '/data/export.inc';
-}
+$renderer = &new Horde_Form_Renderer();
+
+$form = &Horde_Form::singleton('Hermes_ExportForm', $vars);
+$form->renderActive($renderer, $vars, 'data.php', 'post');
 
 require HERMES_TEMPLATES . '/common-footer.inc';
Index: hermes/templates/data/export.inc
===================================================================
diff-rm hermes/templates/data/export.inc
--- hermes/templates/data/export.inc	Thu Aug 14 14:14:54 2003
+++ hermes/templates/data/export.inc	Wed Dec 31 19:00:00 1969
@@ -1,112 +0,0 @@
-<form method="post" name="export" enctype="multipart/form-data" action="data.php">
-<?php Horde::pformInput() ?>
-<input type="hidden" name="actionID" value="export" />
-<table cellspacing="0" cellpadding="0" border="0" width="100%">
-<tr>
-  <td class="header" align="left"><?php echo _("Export Timesheet Data") ?></td>
-</tr>
-<tr>
-  <td class="item">
-  <table border="0"><tr><td>
-    <?php echo _("Select the format to export to:") ?><br />
-    <select name="format">
-      <option value="iif">QuickBooks .iif</option>
-    </select><br /><br />
-    <?php echo _("Limit the time span to export:") ?><br />
-    <table>
-    <tr>
-      <td><input type="radio" id="all" name="export_all" value="1"></td>
-      <td colspan="2"><label for="all"><?php echo _("All Time Entries") ?></label></td>
-    </tr>
-    <tr>
-      <td valign="top" rowspan="4"><input id="limit" type="radio" name="export_all" value="0" checked="checked"></td>
-      <td align="right"><label for="limit"><?php echo _("Start On") ?></label></td>
-      <td colspan="3">
-        <select name="start_year">
-<?php
-$start_year_match = date('Y');
-for ($i = -1; $i < 6; $i++) {
-    $yr = date('Y') + $i;
-    $sel = '';
-    if ($yr == $start_year_match)
-        $sel = ' selected="selected"';
-?>
-<option value="<?php echo $yr ?>"<?php echo $sel ?>><?php echo $yr ?></option>
-<?php } ?>
-</select> - <select name="start_month">
-<?php
-$start_month_match = date('n') - 1;
-for ($i = 1; $i < 13; $i++) {
-    $sel = '';
-    if ($i == $start_month_match) {
-        $sel = ' selected="selected"';
-    }
-?>
-<option value="<?php echo $i ?>"<?php echo $sel ?>><?php echo strftime('%b', mktime(1,1,1,$i,1)) ?></option>
-<?php } ?>
-</select> - <select name="start_day">
-<?php
-$start_day_match = date('j');
-for ($i = 1; $i < 32; $i++) {
-    $sel = '';
-    if ($i == $start_day_match) {
-        $sel = ' selected="selected"';
-    }
-?>
-          <option value="<?php echo $i ?>"<?php echo $sel ?>><?php echo $i ?></option>
-<?php } ?>
-        </select>
-      </td>
-    </tr>
-    <!-- end date -->
-    <tr>
-      <td align="right"><?php echo _("End On") ?></td>
-      <td>
-<?php
-$end_year_match = $start_year_match;
-$end_month_match = $start_month_match +1;
-$end_day_match = $start_day_match;
-?>
-        <select name="end_year">
-<?php
-for ($i = -1; $i < 6; $i++):
-  $yr = date('Y') + $i;
-  $sel = '';
-  if ($yr == $end_year_match)
-    $sel = ' selected="selected"';
-?>
-          <option value="<?php echo $yr ?>"<?php echo $sel ?>><?php echo $yr ?></option>
-<?php endfor; ?>
-        </select>
-        -
-        <select name="end_month">
-<?php
-for ($i = 1; $i < 13; $i++):
-  $sel = '';
-  if ($i == $end_month_match) {
-    $sel = ' selected="selected"';
-  }
-?>
-          <option value="<?php echo $i ?>"<?php echo $sel ?>><?php echo strftime('%b', mktime(1,1,1,$i,1)) ?></option>
-<?php endfor; ?>
-        </select>
-        -
-        <select name="end_day">
-<?php
-for ($i = 1; $i < 32; $i++):
-  $sel = '';
-  if ($i == $end_day_match)
-    $sel = ' selected="selected"';
-?>
-          <option value="<?php echo $i ?>"<?php echo $sel ?>><?php echo $i ?></option>
-<?php endfor; ?>
-        </select>
-      </td>
-    </tr>
-    </table><br />
-    <input type="submit" value="<?php echo _("Export") ?>" class="button" />
-  </td></tr></table>
-  </td>
-</tr>
-</table>
-</form>
Index: hermes/lib/Data.php
===================================================================
diff-add hermes/lib/Data.php
--- hermes/lib/Data.php	Wed Dec 31 19:00:00 1969
+++ hermes/lib/Data.php	Thu Aug 14 13:56:37 2003
@@ -0,0 +1,28 @@
+<?php
+/**
+ * $Horde:$
+ *
+ * Copyright 2003 Cronosys, LLC <http://www.cronosys.com>
+ *
+ * See the enclosed file LICENSE for license information (BSD). If you
+ * did not receive this file, see http://www.horde.org/licenses/bsdl.php.
+ */
+
+require_once HORDE_BASE . '/lib/Form.php';
+
+class Hermes_ExportForm extends Horde_Form {
+
+    function Hermes_ExportForm (&$vars)
+    {
+        parent::Horde_Form($vars, _("Export Timesheet Data"));
+        $this->_submit[] = _("Export");
+
+        $formats = array( 'iif' => 'QuickBooks .iif' );
+        $this->addVariable(_("Select the format to export to"), 'format', 'enum', true, false, null, array($formats));
+
+        $this->addVariable(_("Do not export entries before"), 'span_start', 'monthdayyear', false);
+        $this->addVariable(_("Do not export entries after"), 'span_end', 'monthdayyear', false);
+        $this->addVariable(_("Export already exported data?"), 'already_exported', 'boolean', true);
+    }
+
+}


More information about the hermes mailing list