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 // Class ttCustomFieldHelper is used to help with custom field related tasks.
 
  30 class ttCustomFieldHelper {
 
  32   // The insertField function inserts a new custom field in database.
 
  33   static function insertField($fields)
 
  35     $mdb2 = getConnection();
 
  37     $group_id = (int) $fields['group_id'];
 
  38     $type = (int) $fields['type'];
 
  39     $label = $fields['label'];
 
  40     $required = (int) $fields['required'];
 
  41     $status = $fields['status'];
 
  43     $sql = "insert into tt_custom_fields (group_id, type, label, required, status)".
 
  44       " values ($group_id, $type, ".$mdb2->quote($label).", $required, ".$mdb2->quote($status).")";
 
  46     $affected = $mdb2->exec($sql);
 
  47     if (is_a($affected, 'PEAR_Error'))
 
  51     $sql = "select last_insert_id() as last_insert_id";
 
  52     $res = $mdb2->query($sql);
 
  53     $val = $res->fetchRow();
 
  54     $last_id = $val['last_insert_id'];
 
  59   // The insertOption function inserts a new custom field option in database.
 
  60   static function insertOption($fields)
 
  62     $mdb2 = getConnection();
 
  64     $field_id = (int) $fields['field_id'];
 
  65     $value = $fields['value'];
 
  67     $sql = "insert into tt_custom_field_options (field_id, value) 
 
  68       values ($field_id, ".$mdb2->quote($value).")";
 
  70     $affected = $mdb2->exec($sql);
 
  71     if (is_a($affected, 'PEAR_Error'))
 
  75     $sql = "select last_insert_id() as last_insert_id";
 
  76     $res = $mdb2->query($sql);
 
  77     $val = $res->fetchRow();
 
  78     $last_id = $val['last_insert_id'];
 
  83   // The insertLogEntry function inserts a new custom field log entry in database.
 
  84   static function insertLogEntry($fields)
 
  86     $mdb2 = getConnection();
 
  88     $log_id = (int) $fields['log_id'];
 
  89     $field_id = (int) $fields['field_id'];
 
  90     $option_id = $fields['option_id'];
 
  91     $value = $fields['value'];
 
  92     $status = $fields['status'];
 
  94     $sql = "insert into tt_custom_field_log (log_id, field_id, option_id, value, status) 
 
  95       values ($log_id, $field_id, ".$mdb2->quote($option_id).", ".$mdb2->quote($value).", ".$mdb2->quote($status).")";
 
  97     $affected = $mdb2->exec($sql);
 
  98     return (!is_a($affected, 'PEAR_Error'));