X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/timetracker.git/blobdiff_plain/b1082e6ec27ca11586bd786b65f509d1a20220f6..dd0021e48080a708591d7ad763c63f5fb98e3fb7:/WEB-INF/lib/ttOrgImportHelper.class.php diff --git a/WEB-INF/lib/ttOrgImportHelper.class.php b/WEB-INF/lib/ttOrgImportHelper.class.php index 011f2081..cbf7d28a 100644 --- a/WEB-INF/lib/ttOrgImportHelper.class.php +++ b/WEB-INF/lib/ttOrgImportHelper.class.php @@ -27,13 +27,7 @@ // +----------------------------------------------------------------------+ 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 +57,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. @@ -172,7 +166,7 @@ class ttOrgImportHelper { if ($name == 'TASK') { // We get here when processing tags for the current group. - $task_id = ttTaskHelper::insert(array( + $task_id = $this->insertTask(array( 'group_id' => $this->current_group_id, 'org_id' => $this->org_id, 'name' => $attrs['NAME'], @@ -705,6 +699,29 @@ class ttOrgImportHelper { return (!is_a($affected, 'PEAR_Error')); } + // insertTask function inserts a new task into database. + private function insertTask($fields) + { + $mdb2 = getConnection(); + + $group_id = (int) $fields['group_id']; + $org_id = (int) $fields['org_id']; + $name = $fields['name']; + $description = $fields['description']; + $projects = $fields['projects']; + $status = $fields['status']; + + $sql = "insert into tt_tasks (group_id, org_id, name, description, status) + values ($group_id, $org_id, ".$mdb2->quote($name).", ".$mdb2->quote($description).", ".$mdb2->quote($status).")"; + $affected = $mdb2->exec($sql); + $last_id = 0; + if (is_a($affected, 'PEAR_Error')) + return false; + + $last_id = $mdb2->lastInsertID('tt_tasks', 'id'); + return $last_id; + } + // insertProject - a helper function to insert a project as well as project to task binds. private function insertProject($fields) { @@ -725,11 +742,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 +777,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 +806,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 +850,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 +913,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 +932,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 +998,19 @@ class ttOrgImportHelper { $affected = $mdb2->exec($sql); return (!is_a($affected, 'PEAR_Error')); } + + // getTopRole returns top role id. + private function getTopRole() { + $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; + } }