Ongoing refactoring, replacing the method to obtain last insert ids.
authorNik Okuntseff <support@anuko.com>
Fri, 30 Nov 2018 13:22:19 +0000 (13:22 +0000)
committerNik Okuntseff <support@anuko.com>
Fri, 30 Nov 2018 13:22:19 +0000 (13:22 +0000)
WEB-INF/lib/ttClientHelper.class.php
WEB-INF/lib/ttCustomFieldHelper.class.php [deleted file]
WEB-INF/lib/ttUserHelper.class.php
WEB-INF/templates/footer.tpl

index 24d00d2..3dc60bd 100644 (file)
@@ -189,12 +189,7 @@ class ttClientHelper {
     if (is_a($affected, 'PEAR_Error'))
       return false;
 
-    $last_id = 0;
-    $sql = "select last_insert_id() as last_insert_id";
-    $res = $mdb2->query($sql);
-    $val = $res->fetchRow();
-    $last_id = $val['last_insert_id'];
-
+    $last_id = $mdb2->lastInsertID('tt_clients', 'id');
     if (count($projects) > 0)
       foreach ($projects as $p_id) {
         $sql = "insert into tt_client_project_binds (client_id, project_id, group_id, org_id) values($last_id, $p_id, $group_id, $org_id)";
diff --git a/WEB-INF/lib/ttCustomFieldHelper.class.php b/WEB-INF/lib/ttCustomFieldHelper.class.php
deleted file mode 100644 (file)
index 15c7ca0..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-<?php
-// +----------------------------------------------------------------------+
-// | Anuko Time Tracker
-// +----------------------------------------------------------------------+
-// | Copyright (c) Anuko International Ltd. (https://www.anuko.com)
-// +----------------------------------------------------------------------+
-// | LIBERAL FREEWARE LICENSE: This source code document may be used
-// | by anyone for any purpose, and freely redistributed alone or in
-// | combination with other software, provided that the license is obeyed.
-// |
-// | There are only two ways to violate the license:
-// |
-// | 1. To redistribute this code in source form, with the copyright
-// |    notice or license removed or altered. (Distributing in compiled
-// |    forms without embedded copyright notices is permitted).
-// |
-// | 2. To redistribute modified versions of this code in *any* form
-// |    that bears insufficient indications that the modifications are
-// |    not the work of the original author(s).
-// |
-// | This license applies to this document only, not any other software
-// | that it may be combined with.
-// |
-// +----------------------------------------------------------------------+
-// | Contributors:
-// | https://www.anuko.com/time_tracker/credits.htm
-// +----------------------------------------------------------------------+
-
-// Class ttCustomFieldHelper is used to help with custom field related tasks.
-class ttCustomFieldHelper {
-       
-  // The insertField function inserts a new custom field in database.
-  static function insertField($fields)
-  {
-    $mdb2 = getConnection();
-
-    $group_id = (int) $fields['group_id'];
-    $type = (int) $fields['type'];
-    $label = $fields['label'];
-    $required = (int) $fields['required'];
-    $status = $fields['status'];
-    
-    $sql = "insert into tt_custom_fields (group_id, type, label, required, status)".
-      " values ($group_id, $type, ".$mdb2->quote($label).", $required, ".$mdb2->quote($status).")";
-      
-    $affected = $mdb2->exec($sql);
-    if (is_a($affected, 'PEAR_Error'))
-      return false;
-      
-    $last_id = 0;
-    $sql = "select last_insert_id() as last_insert_id";
-    $res = $mdb2->query($sql);
-    $val = $res->fetchRow();
-    $last_id = $val['last_insert_id'];
-      
-    return $last_id;
-  }
-  
-  // The insertOption function inserts a new custom field option in database.
-  static function insertOption($fields)
-  {
-    $mdb2 = getConnection();
-
-    $field_id = (int) $fields['field_id'];
-    $value = $fields['value'];
-    
-    $sql = "insert into tt_custom_field_options (field_id, value) 
-      values ($field_id, ".$mdb2->quote($value).")";
-      
-    $affected = $mdb2->exec($sql);
-    if (is_a($affected, 'PEAR_Error'))
-      return false;
-      
-    $last_id = 0;
-    $sql = "select last_insert_id() as last_insert_id";
-    $res = $mdb2->query($sql);
-    $val = $res->fetchRow();
-    $last_id = $val['last_insert_id'];
-      
-    return $last_id;
-  }
-  
-  // The insertLogEntry function inserts a new custom field log entry in database.
-  static function insertLogEntry($fields)
-  {
-    $mdb2 = getConnection();
-
-    $log_id = (int) $fields['log_id'];
-    $field_id = (int) $fields['field_id'];
-    $option_id = $fields['option_id'];
-    $value = $fields['value'];
-    $status = $fields['status'];
-    
-    $sql = "insert into tt_custom_field_log (log_id, field_id, option_id, value, status) 
-      values ($log_id, $field_id, ".$mdb2->quote($option_id).", ".$mdb2->quote($value).", ".$mdb2->quote($status).")";
-      
-    $affected = $mdb2->exec($sql);
-    return (!is_a($affected, 'PEAR_Error'));
-  }
-}
index 2ff774f..42d7c91 100644 (file)
@@ -120,11 +120,7 @@ class ttUserHelper {
 
     // Now deal with project assignment.
     if (!is_a($affected, 'PEAR_Error')) {
-      $sql = "SELECT LAST_INSERT_ID() AS last_id";
-      $res = $mdb2->query($sql);
-      $val = $res->fetchRow();
-      $last_id = $val['last_id'];
-
+      $last_id = $mdb2->lastInsertID('tt_users', 'id');
       $projects = isset($fields['projects']) ? $fields['projects'] : array();
       if (count($projects) > 0) {
         // We have at least one project assigned. Insert corresponding entries in tt_user_project_binds table.
index 9f251f4..501ebf7 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.18.28.4543 | Copyright &copy; <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
+          <td align="center">&nbsp;Anuko Time Tracker 1.18.28.4544 | 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>