X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=WEB-INF%2Flib%2FttOrgImportHelper.class.php;h=a14d9714b737a8779ffbb9d69488f30b08f77d28;hb=6f1a57ddce604840c432915d97574f175b935475;hp=9907f6e711be9d146656ba3c643bc9f0bb8813a8;hpb=dc298aa5a82fc2aa86a27a1c106cf42881376004;p=timetracker.git diff --git a/WEB-INF/lib/ttOrgImportHelper.class.php b/WEB-INF/lib/ttOrgImportHelper.class.php index 9907f6e7..a14d9714 100644 --- a/WEB-INF/lib/ttOrgImportHelper.class.php +++ b/WEB-INF/lib/ttOrgImportHelper.class.php @@ -32,7 +32,6 @@ import('ttTaskHelper'); import('ttClientHelper'); import('ttInvoiceHelper'); import('ttTimeHelper'); -import('ttCustomFieldHelper'); import('ttExpenseHelper'); import('ttFavReportHelper'); @@ -364,9 +363,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'], @@ -388,9 +387,9 @@ class ttOrgImportHelper { if ($name == 'CUSTOM_FIELD_OPTION') { // We get here when processing tags for the current group. - $custom_field_option_id = ttCustomFieldHelper::insertOption(array( - // 'group_id' => $this->current_group_id, TODO: add this when group_id field is added to the table. - // 'org_id' => $this->org_id, TODO: add this when org_id field is added to the table. + $custom_field_option_id = $this->insertCustomFieldOption(array( + 'group_id' => $this->current_group_id, + 'org_id' => $this->org_id, 'field_id' => $this->currentGroupCustomFieldMap[$attrs['FIELD_ID']], 'value' => $attrs['VALUE'])); if ($custom_field_option_id) { @@ -402,9 +401,9 @@ class ttOrgImportHelper { if ($name == 'CUSTOM_FIELD_LOG_ENTRY') { // We get here when processing tags for the current group. - if (!ttCustomFieldHelper::insertLogEntry(array( - // 'group_id' => $this->current_group_id, TODO: add this when group_id field is added to the table. - // 'org_id' => $this->org_id, TODO: add this when org_id field is added to the table. + if (!$this->insertCustomFieldLogEntry(array( + 'group_id' => $this->current_group_id, + 'org_id' => $this->org_id, 'log_id' => $this->currentGroupLogMap[$attrs['LOG_ID']], 'field_id' => $this->currentGroupCustomFieldMap[$attrs['FIELD_ID']], 'option_id' => $this->currentGroupCustomFieldOptionMap[$attrs['OPTION_ID']], @@ -526,6 +525,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; + } } } @@ -884,4 +895,88 @@ 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; + } + + // insertCustomFieldOption - a helper function to insert a custom field option. + private function insertCustomFieldOption($fields) { + $mdb2 = getConnection(); + + $group_id = (int) $fields['group_id']; + $org_id = (int) $fields['org_id']; + $field_id = (int) $fields['field_id']; + $value = $fields['value']; + + $sql = "insert into tt_custom_field_options (group_id, org_id, field_id, value)". + " values ($group_id, $org_id, $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; + } + + // insertCustomFieldLogEntry - a helper function to insert a custom field log entry. + private function insertCustomFieldLogEntry($fields) { + $mdb2 = getConnection(); + + $group_id = (int) $fields['group_id']; + $org_id = (int) $fields['org_id']; + $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 (group_id, org_id, log_id, field_id, option_id, value, status)". + " values ($group_id, $org_id, $log_id, $field_id, ".$mdb2->quote($option_id).", ".$mdb2->quote($value).", ".$mdb2->quote($status).")"; + $affected = $mdb2->exec($sql); + return (!is_a($affected, 'PEAR_Error')); + } }