}
return $result;
}
+
+ // validateCheckboxGroupInput - validates user input in a group of checkboxes
+ // in context of a specific database table.
+ //
+ // We need to make sure that input is a set of unique positive integers, and is
+ // "relevant" to the current group (entities exists in table).
+ //
+ // It is a safeguard against manipulation of data in posts.
+ static function validateCheckboxGroupInput($input, $table) {
+ // Empty input is valid.
+ if (!$input) return true;
+
+ // Input containing duplicates is invalid.
+ if (count($input) !== count(array_unique($input))) return false;
+
+ // Input containing anything but positive integers is invalid.
+ foreach ($input as $single_selection) {
+ if (!is_numeric($single_selection) || $single_selection <= 0) return false;
+ }
+
+ global $user;
+ $mdb2 = getConnection();
+
+ $group_id = $user->getGroup();
+ $org_id = $user->org_id;
+
+ // Now check the table. It must contain all entities associated with current group and org.
+ $comma_separated = implode(',', $input);
+ $sql = "select count(*) as item_count from $table".
+ " where id in ($comma_separated) and group_id = $group_id and org_id = $org_id and status = 1";
+ $res = $mdb2->query($sql);
+ if (is_a($res, 'PEAR_Error')) return false;
+ $val = $res->fetchRow();
+ if (count($input) != $val['item_count'])
+ return false; // Number of entities in table is different.
+
+ return true; // All is good.
+ }
}
<br>
<table cellspacing="0" cellpadding="4" width="100%" border="0">
<tr>
- <td align="center"> Anuko Time Tracker 1.18.29.4623 | Copyright © <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
+ <td align="center"> Anuko Time Tracker 1.18.29.4624 | Copyright © <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>
// Validate user input.
if (!ttValidString($cl_name)) $err->add($i18n->get('error.field'), $i18n->get('label.thing_name'));
if (!ttValidString($cl_description, true)) $err->add($i18n->get('error.field'), $i18n->get('label.description'));
+ if (!ttGroupHelper::validateCheckboxGroupInput($cl_users, 'tt_users')) $err->add($i18n->get('error.field'), $i18n->get('label.users'));
+ if (!ttGroupHelper::validateCheckboxGroupInput($cl_tasks, 'tt_tasks')) $err->add($i18n->get('error.field'), $i18n->get('label.tasks'));
if ($err->no()) {
if (!ttProjectHelper::getProjectByName($cl_name)) {
// Validate user input.
if (!ttValidString($cl_name)) $err->add($i18n->get('error.field'), $i18n->get('label.thing_name'));
if (!ttValidString($cl_description, true)) $err->add($i18n->get('error.field'), $i18n->get('label.description'));
+ if (!ttGroupHelper::validateCheckboxGroupInput($cl_users, 'tt_users')) $err->add($i18n->get('error.field'), $i18n->get('label.users'));
+ if (!ttGroupHelper::validateCheckboxGroupInput($cl_tasks, 'tt_tasks')) $err->add($i18n->get('error.field'), $i18n->get('label.tasks'));
if ($err->no()) {
if ($request->getParameter('btn_save')) {
// Validate user input.
if (!ttValidString($cl_name)) $err->add($i18n->get('error.field'), $i18n->get('label.thing_name'));
if (!ttValidString($cl_description, true)) $err->add($i18n->get('error.field'), $i18n->get('label.description'));
+ if (!ttGroupHelper::validateCheckboxGroupInput($cl_users, 'tt_users')) $err->add($i18n->get('error.field'), $i18n->get('label.users'));
+ if (!ttGroupHelper::validateCheckboxGroupInput($cl_tasks, 'tt_tasks')) $err->add($i18n->get('error.field'), $i18n->get('label.tasks'));
if ($err->no()) {
if (!ttProjectHelper::getProjectByName($cl_name)) {
// Validate user input.
if (!ttValidString($cl_name)) $err->add($i18n->get('error.field'), $i18n->get('label.thing_name'));
if (!ttValidString($cl_description, true)) $err->add($i18n->get('error.field'), $i18n->get('label.description'));
+ if (!ttGroupHelper::validateCheckboxGroupInput($cl_users, 'tt_users')) $err->add($i18n->get('error.field'), $i18n->get('label.users'));
+ if (!ttGroupHelper::validateCheckboxGroupInput($cl_tasks, 'tt_tasks')) $err->add($i18n->get('error.field'), $i18n->get('label.tasks'));
if ($err->no()) {
if ($request->getParameter('btn_save')) {