X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/timetracker.git/blobdiff_plain/3fe430d82ad416d1766b9f0cd558e2e1f26900a9..cd0fdd6bdf0879f047732df3d0092a291b35ff6c:/WEB-INF/lib/ttOrgImportHelper.class.php diff --git a/WEB-INF/lib/ttOrgImportHelper.class.php b/WEB-INF/lib/ttOrgImportHelper.class.php index 0da0a7ea..2758ac21 100644 --- a/WEB-INF/lib/ttOrgImportHelper.class.php +++ b/WEB-INF/lib/ttOrgImportHelper.class.php @@ -238,7 +238,7 @@ class ttOrgImportHelper { $mapped_projects[] = $this->currentGroupProjectMap[$id]; } - $client_id = ttClientHelper::insert(array( + $client_id = $this->insertClient(array( 'group_id' => $this->current_group_id, 'org_id' => $this->org_id, 'name' => $attrs['NAME'], @@ -364,9 +364,9 @@ class ttOrgImportHelper { if ($name == 'CUSTOM_FIELD') { // We get here when processing tags for the current group. - $custom_field_id = ttCustomFieldHelper::insertField(array( + $custom_field_id = $this->insertCustomField(array( 'group_id' => $this->current_group_id, - // 'org_id' => $this->org_id, TODO: add this when org_id field is added to the table. + 'org_id' => $this->org_id, 'type' => $attrs['TYPE'], 'label' => $attrs['LABEL'], 'required' => $attrs['REQUIRED'], @@ -526,6 +526,18 @@ class ttOrgImportHelper { } return; } + + if ($name == 'USER_PARAM') { + if (!$this->insertUserParam(array( + 'group_id' => $this->current_group_id, + 'org_id' => $this->org_id, + 'user_id' => $this->currentGroupUserMap[$attrs['USER_ID']], + 'param_name' => $attrs['PARAM_NAME'], + 'param_value' => $attrs['PARAM_VALUE']))) { + $this->errors->add($i18n->get('error.db')); + } + return; + } } } @@ -779,6 +791,48 @@ class ttOrgImportHelper { return $last_id; } + // The insertClient function inserts a new client as well as client to project binds. + private function insertClient($fields) + { + $mdb2 = getConnection(); + + $group_id = (int) $fields['group_id']; + $org_id = (int) $fields['org_id']; + $name = $fields['name']; + $address = $fields['address']; + $tax = $fields['tax']; + $projects = $fields['projects']; + if ($projects) + $comma_separated = implode(',', $projects); // This is a comma-separated list of associated projects ids. + $status = $fields['status']; + + $tax = str_replace(',', '.', $tax); + if ($tax == '') $tax = 0; + + $sql = "insert into tt_clients (group_id, org_id, name, address, tax, projects, status)". + " values ($group_id, $org_id, ".$mdb2->quote($name).", ".$mdb2->quote($address).", $tax, ".$mdb2->quote($comma_separated).", ".$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']; + + 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)"; + $affected = $mdb2->exec($sql); + if (is_a($affected, 'PEAR_Error')) + return false; + } + + return $last_id; + } + // insertFavReport - inserts a favorite report in database. private function insertFavReport($fields) { $mdb2 = getConnection(); @@ -820,7 +874,7 @@ class ttOrgImportHelper { } // insertNotification function inserts a new notification into database. - static function insertNotification($fields) + private function insertNotification($fields) { $mdb2 = getConnection(); @@ -842,4 +896,47 @@ class ttOrgImportHelper { $affected = $mdb2->exec($sql); return (!is_a($affected, 'PEAR_Error')); } + + // insertUserParam - a helper function to insert a user parameter. + private function insertUserParam($fields) { + $mdb2 = getConnection(); + + $group_id = (int) $fields['group_id']; + $org_id = (int) $fields['org_id']; + $user_id = (int) $fields['user_id']; + $param_name = $fields['param_name']; + $param_value = $fields['param_value']; + + $sql = "insert into tt_config". + " (user_id, group_id, org_id, param_name, param_value)". + " values ($user_id, $group_id, $org_id, ".$mdb2->quote($param_name).", ".$mdb2->quote($param_value).")"; + $affected = $mdb2->exec($sql); + return (!is_a($affected, 'PEAR_Error')); + } + + // insertCustomField - a helper function to insert a custom field. + private function insertCustomField($fields) { + $mdb2 = getConnection(); + + $group_id = (int) $fields['group_id']; + $org_id = (int) $fields['org_id']; + $type = (int) $fields['type']; + $label = $fields['label']; + $required = (int) $fields['required']; + $status = $fields['status']; + + $sql = "insert into tt_custom_fields". + " (group_id, org_id, type, label, required, status)". + " values($group_id, $org_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; + } }