X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/timetracker.git/blobdiff_plain/b1082e6ec27ca11586bd786b65f509d1a20220f6..db51a4b1e95f48d82bf2a214f8d0736f2485e3a2:/WEB-INF/lib/ttOrgImportHelper.class.php diff --git a/WEB-INF/lib/ttOrgImportHelper.class.php b/WEB-INF/lib/ttOrgImportHelper.class.php index 011f2081..060a7c1d 100644 --- a/WEB-INF/lib/ttOrgImportHelper.class.php +++ b/WEB-INF/lib/ttOrgImportHelper.class.php @@ -27,13 +27,8 @@ // +----------------------------------------------------------------------+ import('ttUserHelper'); -import('ttRoleHelper'); import('ttTaskHelper'); -import('ttClientHelper'); import('ttInvoiceHelper'); -import('ttTimeHelper'); -import('ttExpenseHelper'); -import('ttFavReportHelper'); // ttOrgImportHelper class is used to import organization data from an XML file // prepared by ttOrgExportHelper and consisting of nested groups with their info. @@ -63,7 +58,7 @@ class ttOrgImportHelper { // Constructor. function __construct(&$errors) { $this->errors = &$errors; - $this->top_role_id = ttRoleHelper::getRoleByRank(512, 0); + $this->top_role_id = $this->getTopRole(); } // startElement - callback handler for opening tags in XML. @@ -725,11 +720,7 @@ class ttOrgImportHelper { 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_projects', 'id'); // Insert binds into tt_project_task_binds table. if (is_array($tasks)) { @@ -764,10 +755,7 @@ class ttOrgImportHelper { if (is_a($affected, 'PEAR_Error')) return false; - $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_roles', 'id'); return $last_id; } @@ -796,11 +784,7 @@ class ttOrgImportHelper { 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) { @@ -844,13 +828,8 @@ class ttOrgImportHelper { if (is_a($affected, 'PEAR_Error')) return false; - $sql = "select last_insert_id() as last_id"; - $res = $mdb2->query($sql); - if (is_a($res, 'PEAR_Error')) - return false; - - $val = $res->fetchRow(); - return $val['last_id']; + $last_id = $mdb2->lastInsertID('tt_fav_reports', 'id'); + return $last_id; } // insertNotification function inserts a new notification into database. @@ -912,11 +891,7 @@ class ttOrgImportHelper { 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_custom_fields', 'id'); return $last_id; } @@ -935,11 +910,7 @@ class ttOrgImportHelper { 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_custom_field_options', 'id'); return $last_id; } @@ -1005,4 +976,20 @@ class ttOrgImportHelper { $affected = $mdb2->exec($sql); return (!is_a($affected, 'PEAR_Error')); } + + // getTopRole returns top role id. + private function getTopRole() { + global $user; + $mdb2 = getConnection(); + + $sql = "select id from tt_roles where group_id = 0 and rank = ".MAX_RANK." and status = 1"; + $res = $mdb2->query($sql); + + if (!is_a($res, 'PEAR_Error')) { + $val = $res->fetchRow(); + if ($val['id']) + return $val['id']; + } + return false; + } }