X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/timetracker.git/blobdiff_plain/dd0021e48080a708591d7ad763c63f5fb98e3fb7..a2f024d2184505a889e51d92337d9f40e392a1be:/WEB-INF/lib/ttOrgImportHelper.class.php diff --git a/WEB-INF/lib/ttOrgImportHelper.class.php b/WEB-INF/lib/ttOrgImportHelper.class.php index cbf7d28a..34933411 100644 --- a/WEB-INF/lib/ttOrgImportHelper.class.php +++ b/WEB-INF/lib/ttOrgImportHelper.class.php @@ -27,7 +27,6 @@ // +----------------------------------------------------------------------+ import('ttUserHelper'); -import('ttInvoiceHelper'); // ttOrgImportHelper class is used to import organization data from an XML file // prepared by ttOrgExportHelper and consisting of nested groups with their info. @@ -160,7 +159,9 @@ class ttOrgImportHelper { if ($role_id) { // Add a mapping. $this->currentGroupRoleMap[$attrs['ID']] = $role_id; - } else $this->errors->add($i18n->get('error.db')); + } else { + $this->errors->add($i18n->get('error.db')); + } return; } @@ -228,7 +229,9 @@ class ttOrgImportHelper { if ($client_id) { // Add a mapping. $this->currentGroupClientMap[$attrs['ID']] = $client_id; - } else $this->errors->add($i18n->get('error.db')); + } else { + $this->errors->add($i18n->get('error.db')); + } return; } @@ -251,7 +254,9 @@ class ttOrgImportHelper { if ($user_id) { // Add a mapping. $this->currentGroupUserMap[$attrs['ID']] = $user_id; - } else $this->errors->add($i18n->get('error.db')); + } else { + $this->errors->add($i18n->get('error.db')); + } return; } @@ -270,7 +275,7 @@ class ttOrgImportHelper { if ($name == 'INVOICE') { // We get here when processing tags for the current group. - $invoice_id = ttInvoiceHelper::insert(array( + $invoice_id = $this->insertInvoice(array( 'group_id' => $this->current_group_id, 'org_id' => $this->org_id, 'name' => $attrs['NAME'], @@ -280,7 +285,9 @@ class ttOrgImportHelper { if ($invoice_id) { // Add a mapping. $this->currentGroupInvoiceMap[$attrs['ID']] = $invoice_id; - } else $this->errors->add($i18n->get('error.db')); + } else { + $this->errors->add($i18n->get('error.db')); + } return; } @@ -781,6 +788,28 @@ class ttOrgImportHelper { return $last_id; } + // insertInvoice - inserts an invoice in database. + private function insertInvoice($fields) + { + $mdb2 = getConnection(); + + $group_id = (int) $fields['group_id']; + $org_id = (int) $fields['org_id']; + $name = $fields['name']; + $client_id = (int) $fields['client_id']; + $date = $fields['date']; + $status = $fields['status']; + + // Insert a new invoice record. + $sql = "insert into tt_invoices (group_id, org_id, name, date, client_id, status)". + " values($group_id, $org_id, ".$mdb2->quote($name).", ".$mdb2->quote($date).", $client_id, ".$mdb2->quote($fields['status']).")"; + $affected = $mdb2->exec($sql); + if (is_a($affected, 'PEAR_Error')) return false; + + $last_id = $mdb2->lastInsertID('tt_invoices', 'id'); + return $last_id; + } + // The insertClient function inserts a new client as well as client to project binds. private function insertClient($fields) {