2 // +----------------------------------------------------------------------+
 
   3 // | Anuko Time Tracker
 
   4 // +----------------------------------------------------------------------+
 
   5 // | Copyright (c) Anuko International Ltd. (https://www.anuko.com)
 
   6 // +----------------------------------------------------------------------+
 
   7 // | LIBERAL FREEWARE LICENSE: This source code document may be used
 
   8 // | by anyone for any purpose, and freely redistributed alone or in
 
   9 // | combination with other software, provided that the license is obeyed.
 
  11 // | There are only two ways to violate the license:
 
  13 // | 1. To redistribute this code in source form, with the copyright
 
  14 // |    notice or license removed or altered. (Distributing in compiled
 
  15 // |    forms without embedded copyright notices is permitted).
 
  17 // | 2. To redistribute modified versions of this code in *any* form
 
  18 // |    that bears insufficient indications that the modifications are
 
  19 // |    not the work of the original author(s).
 
  21 // | This license applies to this document only, not any other software
 
  22 // | that it may be combined with.
 
  24 // +----------------------------------------------------------------------+
 
  26 // | https://www.anuko.com/time_tracker/credits.htm
 
  27 // +----------------------------------------------------------------------+
 
  29 require_once('initialize.php');
 
  31 import('form.DefaultCellRenderer');
 
  33 import('form.TextField');
 
  35 $durations_with_labels = array(
 
  37     'id' => 'something goes here too', // Row ideentifier.
 
  38     'label' => 'This is a label for row 0',
 
  39     'day_0' => array('id' => '0_0', 'duration' => '00:00'),
 
  40     'day_1' => array('id' => '0_1', 'duration' => '01:00'),
 
  41     'day_2' => array('id' => '0_2', 'duration' => '02:00'),
 
  42     'day_3' => array('id' => '0_3', 'duration' => null),
 
  43     'day_4' => array('id' => '0_4', 'duration' => '04:00')
 
  46     'label' => 'This is a label for row 1',
 
  47     'day_0' => array('id' => '1_0', 'duration' => '00:30'),
 
  48     'day_1' => array('id' => '1_1', 'duration' => '01:30'),
 
  49     'day_2' => array('id' => '1_2', 'duration' => '02:30'),
 
  64 // Define rendering class for a label field to the left of durations.
 
  65 class LabelCellRenderer extends DefaultCellRenderer {
 
  66   function render(&$table, $value, $row, $column, $selected = false) {
 
  67     $this->setOptions(array('width'=>200,'valign'=>'middle'));
 
  68     $this->setValue(htmlspecialchars($value));
 
  69     return $this->toString();
 
  73 // Define rendering class for a single cell for time entry in week view table.
 
  74 class TimeCellRenderer extends DefaultCellRenderer {
 
  75   function render(&$table, $value, $row, $column, $selected = false) {
 
  76     $field_name = $table->getValueAt($row,$column)['id']; // Our text field names (and ids) are like x_y (row_column).
 
  77     $field = new TextField($field_name);
 
  78     $field->setFormName($table->getFormName());
 
  80     $field->setValue($table->getValueAt($row,$column)['duration']);
 
  81     $this->setValue($field->getHtml());
 
  82     return $this->toString();
 
  86 // Elements of weekTimeForm.
 
  87 $form = new Form('weekTimeForm');
 
  89 // Create week_durations table.
 
  90 $table = new Table('week_durations');
 
  91 // $table->setIAScript('markModified'); // TODO: write a script to mark table or particular cells as modified.
 
  92 $table->setTableOptions(array('width'=>'100%','cellspacing'=>'1','cellpadding'=>'3','border'=>'0'));
 
  93 $table->setRowOptions(array('valign'=>'top','class'=>'tableHeader'));
 
  94 $table->setData($durations_with_labels);
 
  95 // Add columns to table.
 
  96 $table->addColumn(new TableColumn('label', '', new LabelCellRenderer(), $totals['label']));
 
  97 $table->addColumn(new TableColumn('day_0', 'day 0', new TimeCellRenderer(), $totals['day_0']));
 
  98 $table->addColumn(new TableColumn('day_1', 'day 1', new TimeCellRenderer(), $totals['day_1']));
 
  99 $table->addColumn(new TableColumn('day_2', 'day 2', new TimeCellRenderer(), $totals['day_2']));
 
 100 $table->addColumn(new TableColumn('day_3', 'day 3', new TimeCellRenderer(), $totals['day_3']));
 
 101 $table->addColumn(new TableColumn('day_4', 'day 4', new TimeCellRenderer(), $totals['day_4']));
 
 102 $table->addColumn(new TableColumn('day_5', 'day 5', new TimeCellRenderer()));
 
 103 $table->addColumn(new TableColumn('day_6', 'day 6', new TimeCellRenderer()));
 
 104 $table->setInteractive(false);
 
 105 $form->addInputElement($table);
 
 107 $form->addInput(array('type'=>'submit','name'=>'btn_submit','value'=>$i18n->getKey('button.submit')));
 
 110 if ($request->isPost()) {
 
 111   if ($request->getParameter('btn_submit')) {
 
 115 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
 
 116 $smarty->assign('title', $i18n->getKey('title.time'));
 
 117 $smarty->assign('content_page_name', 'table_test.tpl');
 
 118 $smarty->display('index.tpl');