Simplified Checkbox class.
authoranuko <support@anuko.com>
Fri, 3 Mar 2017 22:44:02 +0000 (22:44 +0000)
committeranuko <support@anuko.com>
Fri, 3 Mar 2017 22:44:02 +0000 (22:44 +0000)
12 files changed:
WEB-INF/lib/form/Checkbox.class.php
WEB-INF/lib/form/Form.class.php
WEB-INF/templates/footer.tpl
cf_custom_field_add.php
cf_custom_field_edit.php
mobile/time.php
mobile/time_edit.php
mobile/timer.php
profile_edit.php
reports.php
time.php
time_edit.php

index c27cab2..c4acbc5 100644 (file)
 import('form.FormElement');
 
 class Checkbox extends FormElement {
-  var $checked = false;
-    var $mOptions      = null;
 
   function __construct($name) {
     $this->class = 'Checkbox';
     $this->name = $name;
   }
 
-       function setChecked($value) { $this->checked = $value; }
-       function isChecked() { return $this->checked; }
-       
-       function setData($value)        { $this->mOptions = $value; }
-       function getData() { return $this->mOptions; }
-
   function getHtml() {
     if ($this->id == '') $this->id = $this->name;
 
     $html = "\n\t<input type=\"checkbox\"";
     $html.= " id=\"$this->id\" name=\"$this->name\"";
 
-    if ($this->checked || (($this->value == $this->mOptions) && ($this->value != null)))
+    if ($this->value)
       $html.= " checked=\"true\"";
 
                if ($this->on_change!="")
@@ -62,8 +54,10 @@ class Checkbox extends FormElement {
                   
                if (!$this->isEnabled())
                   $html .= " disabled=\"disabled\"";
-                  
-               $html .= " value=\"".htmlspecialchars($this->mOptions)."\"";
+
+      // Provide a value so that we pass "1" for set checkboxes on form submit.
+      // Otherwise the default is "on" string, which is not what we want.
+      $html .= " value=\"1\"";
                
                $html .= "/>\n";   
                
index e871743..cb2f520 100644 (file)
@@ -85,12 +85,9 @@ class Form {
       case 'checkbox':
         import('form.Checkbox');
         $el = new Checkbox($params['name']);
-        if (isset($params['checked'])) $el->setChecked($params['checked']);
+        break;
 
 // TODO: refactoring ongoing down from here.
-                           $el->setData(@$params["data"]);
-                           break;
-                           
                        case "checkboxgroup":
                            import('form.CheckboxGroup');
                            $el = new CheckboxGroup($params["name"]);
index 0d3bef4..04bd805 100644 (file)
@@ -12,7 +12,7 @@
       <br>
       <table cellspacing="0" cellpadding="4" width="100%" border="0">
         <tr>
-          <td align="center">&nbsp;Anuko Time Tracker 1.10.38.3620 | Copyright &copy; <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
+          <td align="center">&nbsp;Anuko Time Tracker 1.10.38.3621 | Copyright &copy; <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
             <a href="https://www.anuko.com/lp/tt_4.htm" target="_blank">{$i18n.footer.credits}</a> |
             <a href="https://www.anuko.com/lp/tt_5.htm" target="_blank">{$i18n.footer.license}</a> |
             <a href="https://www.anuko.com/lp/tt_7.htm" target="_blank">{$i18n.footer.improve}</a>
index 1d293d3..2eba5b5 100644 (file)
@@ -50,7 +50,7 @@ $form->addInput(array('type'=>'combobox','name'=>'type',
   'data'=>array(CustomFields::TYPE_TEXT=>$i18n->getKey('label.type_text'),
                 CustomFields::TYPE_DROPDOWN=>$i18n->getKey('label.type_dropdown'))
 ));
-$form->addInput(array('type'=>'checkbox','name'=>'required','data'=>1,'value'=>'0'));
+$form->addInput(array('type'=>'checkbox','name'=>'required'));
 $form->addInput(array('type'=>'submit','name'=>'btn_add','value'=>$i18n->getKey('button.add')));       
 
 if ($request->isPost()) {
index b8e0f8e..8b481a6 100644 (file)
@@ -45,7 +45,7 @@ $form = new Form('fieldForm');
 if ($err->no()) {
   $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'name','value'=>$field['label']));
   $form->addInput(array('type'=>'hidden','name'=>'id','value'=>$cl_id));
-  $form->addInput(array('type'=>'checkbox','name'=>'required','data'=>1,'value'=>$field['required']));
+  $form->addInput(array('type'=>'checkbox','name'=>'required','value'=>$field['required']));
   $form->addInput(array('type'=>'combobox','name'=>'type','value'=>$field['type'],
     'data'=>array(CustomFields::TYPE_TEXT=>$i18n->getKey('label.type_text'),
                   CustomFields::TYPE_DROPDOWN=>$i18n->getKey('label.type_dropdown'))));
index d812864..367579b 100644 (file)
@@ -165,7 +165,7 @@ if ((TYPE_DURATION == $user->record_type) || (TYPE_ALL == $user->record_type))
   $form->addInput(array('type'=>'text','name'=>'duration','value'=>$cl_duration,'onchange'=>"formDisable('duration');"));
 $form->addInput(array('type'=>'textarea','name'=>'note','style'=>'width: 250px; height: 60px;','value'=>$cl_note));
 if ($user->isPluginEnabled('iv'))
-  $form->addInput(array('type'=>'checkbox','name'=>'billable','data'=>1,'value'=>$cl_billable));
+  $form->addInput(array('type'=>'checkbox','name'=>'billable','value'=>$cl_billable));
 $form->addInput(array('type'=>'hidden','name'=>'browser_today','value'=>'')); // User current date, which gets filled in on btn_submit click.
 $form->addInput(array('type'=>'submit','name'=>'btn_submit','onclick'=>'browser_today.value=get_date()','value'=>$i18n->getKey('button.submit')));
 
index d9ebdd7..81e5ab8 100644 (file)
@@ -202,7 +202,7 @@ if ($custom_fields && $custom_fields->fields[0]) {
 // Hidden control for record id.
 $form->addInput(array('type'=>'hidden','name'=>'id','value'=>$cl_id));
 if ($user->isPluginEnabled('iv'))
-  $form->addInput(array('type'=>'checkbox','name'=>'billable','data'=>1,'value'=>$cl_billable));
+  $form->addInput(array('type'=>'checkbox','name'=>'billable','value'=>$cl_billable));
 $form->addInput(array('type'=>'hidden','name'=>'browser_today','value'=>'')); // User current date, which gets filled in on btn_save click.
 $form->addInput(array('type'=>'submit','name'=>'btn_save','onclick'=>'browser_today.value=get_date()','value'=>$i18n->getKey('button.save')));
 $form->addInput(array('type'=>'submit','name'=>'btn_delete','value'=>$i18n->getKey('label.delete')));
index 8a82bb6..cdb32c7 100644 (file)
@@ -155,7 +155,7 @@ if (MODE_PROJECTS_AND_TASKS == $user->tracking_mode) {
     'empty'=>array(''=>$i18n->getKey('dropdown.select'))));
 }
 if ($user->isPluginEnabled('iv'))
-  $form->addInput(array('type'=>'checkbox','name'=>'billable','data'=>1,'value'=>$cl_billable,'enable'=>$enable_controls));
+  $form->addInput(array('type'=>'checkbox','name'=>'billable','value'=>$cl_billable,'enable'=>$enable_controls));
 $form->addInput(array('type'=>'hidden','name'=>'browser_today','value'=>'')); // User current date, which gets filled in on button click.
 $form->addInput(array('type'=>'hidden','name'=>'browser_time','value'=>''));  // User current time, which gets filled in on button click.
 $enable_start = $uncompleted ? false : true;
index 3504dce..9fac75f 100644 (file)
@@ -176,17 +176,17 @@ if ($user->canManageTeam()) {
   $uncompleted_indicators_options[UNCOMPLETED_INDICATORS] = $i18n->getKey('form.profile.uncompleted_indicators_show');
   $form->addInput(array('type'=>'combobox','name'=>'uncompleted_indicators','style'=>'width: 150px;','data'=>$uncompleted_indicators_options,'value'=>$cl_uncompleted_indicators));
 
-  $form->addInput(array('type'=>'checkbox','name'=>'charts','data'=>1,'value'=>$cl_charts));
-  $form->addInput(array('type'=>'checkbox','name'=>'clients','data'=>1,'value'=>$cl_clients,'onchange'=>'handlePluginCheckboxes()'));
-  $form->addInput(array('type'=>'checkbox','name'=>'client_required','data'=>1,'value'=>$cl_client_required));
+  $form->addInput(array('type'=>'checkbox','name'=>'charts','value'=>$cl_charts));
+  $form->addInput(array('type'=>'checkbox','name'=>'clients','value'=>$cl_clients,'onchange'=>'handlePluginCheckboxes()'));
+  $form->addInput(array('type'=>'checkbox','name'=>'client_required','value'=>$cl_client_required));
 
-  $form->addInput(array('type'=>'checkbox','name'=>'invoices','data'=>1,'value'=>$cl_invoices));
-  $form->addInput(array('type'=>'checkbox','name'=>'custom_fields','data'=>1,'value'=>$cl_custom_fields,'onchange'=>'handlePluginCheckboxes()'));
-  $form->addInput(array('type'=>'checkbox','name'=>'expenses','data'=>1,'value'=>$cl_expenses,'onchange'=>'handlePluginCheckboxes()'));
-  $form->addInput(array('type'=>'checkbox','name'=>'tax_expenses','data'=>1,'value'=>$cl_tax_expenses));
-  $form->addInput(array('type'=>'checkbox','name'=>'notifications','data'=>1,'value'=>$cl_notifications,'onchange'=>'handlePluginCheckboxes()'));
-  $form->addInput(array('type'=>'checkbox','name'=>'locking','data'=>1,'value'=>$cl_locking,'onchange'=>'handlePluginCheckboxes()'));
-  $form->addInput(array('type'=>'checkbox','name'=>'quotas','data'=>1,'value'=>$cl_quotas,'onchange'=>'handlePluginCheckboxes()'));
+  $form->addInput(array('type'=>'checkbox','name'=>'invoices','value'=>$cl_invoices));
+  $form->addInput(array('type'=>'checkbox','name'=>'custom_fields','value'=>$cl_custom_fields,'onchange'=>'handlePluginCheckboxes()'));
+  $form->addInput(array('type'=>'checkbox','name'=>'expenses','value'=>$cl_expenses,'onchange'=>'handlePluginCheckboxes()'));
+  $form->addInput(array('type'=>'checkbox','name'=>'tax_expenses','value'=>$cl_tax_expenses));
+  $form->addInput(array('type'=>'checkbox','name'=>'notifications','value'=>$cl_notifications,'onchange'=>'handlePluginCheckboxes()'));
+  $form->addInput(array('type'=>'checkbox','name'=>'locking','value'=>$cl_locking,'onchange'=>'handlePluginCheckboxes()'));
+  $form->addInput(array('type'=>'checkbox','name'=>'quotas','value'=>$cl_quotas,'onchange'=>'handlePluginCheckboxes()'));
 }
 $form->addInput(array('type'=>'submit','name'=>'btn_save','value'=>$i18n->getKey('button.save')));
 
index 989bf5f..2e9bc26 100644 (file)
@@ -172,24 +172,24 @@ $form->addInput(array('type'=>'datefield','maxlength'=>'20','name'=>'end_date'))
 
 // Add checkboxes for fields.
 if ($user->isPluginEnabled('cl'))
-  $form->addInput(array('type'=>'checkbox','name'=>'chclient','data'=>1));
+  $form->addInput(array('type'=>'checkbox','name'=>'chclient'));
 if (($user->canManageTeam() || $user->isClient()) && $user->isPluginEnabled('iv'))
-  $form->addInput(array('type'=>'checkbox','name'=>'chinvoice','data'=>1));
+  $form->addInput(array('type'=>'checkbox','name'=>'chinvoice'));
 if (MODE_PROJECTS == $user->tracking_mode || MODE_PROJECTS_AND_TASKS == $user->tracking_mode)
-  $form->addInput(array('type'=>'checkbox','name'=>'chproject','data'=>1));
+  $form->addInput(array('type'=>'checkbox','name'=>'chproject'));
 if (MODE_PROJECTS_AND_TASKS == $user->tracking_mode)
-  $form->addInput(array('type'=>'checkbox','name'=>'chtask','data'=>1));
+  $form->addInput(array('type'=>'checkbox','name'=>'chtask'));
 if ((TYPE_START_FINISH == $user->record_type) || (TYPE_ALL == $user->record_type)) {
-  $form->addInput(array('type'=>'checkbox','name'=>'chstart','data'=>1));
-  $form->addInput(array('type'=>'checkbox','name'=>'chfinish','data'=>1));
+  $form->addInput(array('type'=>'checkbox','name'=>'chstart'));
+  $form->addInput(array('type'=>'checkbox','name'=>'chfinish'));
 }
-$form->addInput(array('type'=>'checkbox','name'=>'chduration','data'=>1));
-$form->addInput(array('type'=>'checkbox','name'=>'chnote','checked'=>true, 'data'=>1));
+$form->addInput(array('type'=>'checkbox','name'=>'chduration'));
+$form->addInput(array('type'=>'checkbox','name'=>'chnote'));
 if (defined('COST_ON_REPORTS') && isTrue(COST_ON_REPORTS))
-  $form->addInput(array('type'=>'checkbox','name'=>'chcost','data'=>1));
+  $form->addInput(array('type'=>'checkbox','name'=>'chcost'));
 // If we have a custom field - add a checkbox for it.
 if ($custom_fields && $custom_fields->fields[0])
-  $form->addInput(array('type'=>'checkbox','name'=>'chcf_1','data'=>1));
+  $form->addInput(array('type'=>'checkbox','name'=>'chcf_1'));
 
 // Add group by control.
 $group_by_options['no_grouping'] = $i18n->getKey('form.reports.group_by_no');
@@ -206,7 +206,7 @@ if ($custom_fields && $custom_fields->fields[0] && $custom_fields->fields[0]['ty
   $group_by_options['cf_1'] = $custom_fields->fields[0]['label'];
 }
 $form->addInput(array('type'=>'combobox','onchange'=>'handleCheckboxes();','name'=>'group_by','data'=>$group_by_options));
-$form->addInput(array('type'=>'checkbox','name'=>'chtotalsonly','data'=>1));
+$form->addInput(array('type'=>'checkbox','name'=>'chtotalsonly'));
 
 // Add text field for a new favorite report name.
 $form->addInput(array('type'=>'text','name'=>'new_fav_report','maxlength'=>'30','style'=>'width: 250px;'));
@@ -225,17 +225,17 @@ if (($request->getMethod() == 'GET') && !$bean->isSaved()) {
   $period = new Period(INTERVAL_THIS_MONTH, new DateAndTime($user->date_format));
   $form->setValueByElement('start_date', $period->getBeginDate());
   $form->setValueByElement('end_date', $period->getEndDate());
-  $form->setValueByElement('chclient', 1);
-  $form->setValueByElement('chinvoice', 0);
-  $form->setValueByElement('chproject', 1);
-  $form->setValueByElement('chstart', 1);  
-  $form->setValueByElement('chduration', 1);
-  $form->setValueByElement('chcost', 0);
-  $form->setValueByElement('chtask', 1);
-  $form->setValueByElement('chfinish', 1);
-  $form->setValueByElement('chnote', 1);
-  $form->setValueByElement('chcf_1', 0);
-  $form->setValueByElement('chtotalsonly', 0);
+  $form->setValueByElement('chclient', '1');
+  $form->setValueByElement('chinvoice', '0');
+  $form->setValueByElement('chproject', '1');
+  $form->setValueByElement('chstart', '1');
+  $form->setValueByElement('chduration', '1');
+  $form->setValueByElement('chcost', '0');
+  $form->setValueByElement('chtask', '1');
+  $form->setValueByElement('chfinish', '1');
+  $form->setValueByElement('chnote', '1');
+  $form->setValueByElement('chcf_1', '0');
+  $form->setValueByElement('chtotalsonly', '0');
 }
 
 $form->setValueByElement('fav_report_changed','');
index b926e22..4a58dcc 100644 (file)
--- a/time.php
+++ b/time.php
@@ -200,7 +200,7 @@ if (!defined('NOTE_INPUT_HEIGHT'))
 $form->addInput(array('type'=>'textarea','name'=>'note','style'=>'width: 600px; height:'.NOTE_INPUT_HEIGHT.'px;','value'=>$cl_note));
 $form->addInput(array('type'=>'calendar','name'=>'date','value'=>$cl_date)); // calendar
 if ($user->isPluginEnabled('iv'))
-  $form->addInput(array('type'=>'checkbox','name'=>'billable','data'=>1,'value'=>$cl_billable));
+  $form->addInput(array('type'=>'checkbox','name'=>'billable','value'=>$cl_billable));
 $form->addInput(array('type'=>'hidden','name'=>'browser_today','value'=>'')); // User current date, which gets filled in on btn_submit click.
 $form->addInput(array('type'=>'submit','name'=>'btn_submit','onclick'=>'browser_today.value=get_date()','value'=>$i18n->getKey('button.submit')));
 
index c05b077..4484a20 100644 (file)
@@ -202,7 +202,7 @@ if ($custom_fields && $custom_fields->fields[0]) {
 // Hidden control for record id.
 $form->addInput(array('type'=>'hidden','name'=>'id','value'=>$cl_id));
 if ($user->isPluginEnabled('iv'))
-  $form->addInput(array('type'=>'checkbox','name'=>'billable','data'=>1,'value'=>$cl_billable));
+  $form->addInput(array('type'=>'checkbox','name'=>'billable','value'=>$cl_billable));
 $form->addInput(array('type'=>'hidden','name'=>'browser_today','value'=>'')); // User current date, which gets filled in on btn_save or btn_copy click.
 $form->addInput(array('type'=>'submit','name'=>'btn_save','onclick'=>'browser_today.value=get_date()','value'=>$i18n->getKey('button.save')));
 $form->addInput(array('type'=>'submit','name'=>'btn_copy','onclick'=>'browser_today.value=get_date()','value'=>$i18n->getKey('button.copy')));