From 058d776c118501eb510967c8b870bc346bc39e71 Mon Sep 17 00:00:00 2001 From: anuko Date: Fri, 3 Mar 2017 22:44:02 +0000 Subject: [PATCH] Simplified Checkbox class. --- WEB-INF/lib/form/Checkbox.class.php | 16 ++++------- WEB-INF/lib/form/Form.class.php | 5 +--- WEB-INF/templates/footer.tpl | 2 +- cf_custom_field_add.php | 2 +- cf_custom_field_edit.php | 2 +- mobile/time.php | 2 +- mobile/time_edit.php | 2 +- mobile/timer.php | 2 +- profile_edit.php | 20 ++++++------- reports.php | 44 ++++++++++++++--------------- time.php | 2 +- time_edit.php | 2 +- 12 files changed, 46 insertions(+), 55 deletions(-) diff --git a/WEB-INF/lib/form/Checkbox.class.php b/WEB-INF/lib/form/Checkbox.class.php index c27cab24..c4acbc5f 100644 --- a/WEB-INF/lib/form/Checkbox.class.php +++ b/WEB-INF/lib/form/Checkbox.class.php @@ -29,27 +29,19 @@ 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\tid\" 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"; diff --git a/WEB-INF/lib/form/Form.class.php b/WEB-INF/lib/form/Form.class.php index e871743d..cb2f5203 100644 --- a/WEB-INF/lib/form/Form.class.php +++ b/WEB-INF/lib/form/Form.class.php @@ -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"]); diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 0d3bef46..04bd805b 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.10.38.3620 | Copyright © Anuko | +  Anuko Time Tracker 1.10.38.3621 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/cf_custom_field_add.php b/cf_custom_field_add.php index 1d293d37..2eba5b56 100644 --- a/cf_custom_field_add.php +++ b/cf_custom_field_add.php @@ -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()) { diff --git a/cf_custom_field_edit.php b/cf_custom_field_edit.php index b8e0f8ec..8b481a67 100644 --- a/cf_custom_field_edit.php +++ b/cf_custom_field_edit.php @@ -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')))); diff --git a/mobile/time.php b/mobile/time.php index d812864f..367579b1 100644 --- a/mobile/time.php +++ b/mobile/time.php @@ -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'))); diff --git a/mobile/time_edit.php b/mobile/time_edit.php index d9ebdd76..81e5ab8e 100644 --- a/mobile/time_edit.php +++ b/mobile/time_edit.php @@ -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'))); diff --git a/mobile/timer.php b/mobile/timer.php index 8a82bb6d..cdb32c7b 100644 --- a/mobile/timer.php +++ b/mobile/timer.php @@ -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; diff --git a/profile_edit.php b/profile_edit.php index 3504dcef..9fac75f8 100644 --- a/profile_edit.php +++ b/profile_edit.php @@ -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'))); diff --git a/reports.php b/reports.php index 989bf5f3..2e9bc26f 100644 --- a/reports.php +++ b/reports.php @@ -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',''); diff --git a/time.php b/time.php index b926e224..4a58dcc1 100644 --- 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'))); diff --git a/time_edit.php b/time_edit.php index c05b0774..4484a20c 100644 --- a/time_edit.php +++ b/time_edit.php @@ -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'))); -- 2.20.1