function mainSave($post) { $rs = array(); $rs['akce'] = 'error'; $rs['ok'] = FALSE; $rs['report'] = ''; $rs['data'] = ''; $recno = isset($post['recno']) ? htmlspecialchars($_POST['recno']) : -1; $uuid = $post['uuid'] != '' ? htmlspecialchars($post['uuid']) : ''; $block = $post['block'] != '' ? htmlspecialchars($post['block']) : -2; $nextblock = $post['nextblock'] != '' ? htmlspecialchars($post['nextblock']) : -2; $profil = $post['profil'] != '' ? htmlspecialchars($post['profil']) : -2; $nexprofil = $post['nextprofil'] != '' ? htmlspecialchars($post['nextprofil']) : -2; $mds = $post['mds'] != '' ? htmlspecialchars($post['mds']) : -2; $data_type = isset($post['data_type']) ? htmlspecialchars($post['data_type']) : -1; $edit_group = isset($post['edit_group']) ? htmlspecialchars($post['edit_group']) : ''; $view_group = isset($post['view_group']) ? htmlspecialchars($post['view_group']) : ''; $ende = array_key_exists('ende', $post) ? htmlspecialchars($post['ende']) : 0; if ($recno == '' || $recno < 1 || $ende == 0 || count($post) < 6 || $mds < 0) { Debugger::log('[micka_main_lib.mainSave] ' . "Not complete input data! recno={$recno}, mds={$mds}, ende={$ende}, count=" . count($post), 'ERROR'); require PHPINC_DIR . '/templates/404_record.php'; } // odstranění ošetření dat způsobeného direktivou magic_quotes_gpc if (get_magic_quotes_gpc()) { $process = array(&$post); while (list($key, $val) = each($process)) { foreach ($val as $k => $v) { unset($process[$key][$k]); if (is_array($v)) { $process[$key][$key < 5 ? $k : stripslashes($k)] = $v; $process[] =& $process[$key][$key < 5 ? $k : stripslashes($k)]; } else { $process[$key][stripslashes($k)] = stripslashes($v); } } } } if (array_key_exists('fileIdentifier_0_TXT', $post)) { // Micka Lite require PHPPRG_DIR . '/CswClient.php'; require WWW_DIR . '/lite/resources/Kote.php'; require PHPPRG_DIR . '/micka_lib_php5.php'; require PHPPRG_DIR . '/MdImport.php'; $cswClient = new CSWClient(); $input = Kote::processForm(beforeSaveRecord($post)); $params = array('datestamp' => date('Y-m-d'), 'lang' => 'cze'); $xmlstring = $cswClient->processTemplate($input, WWW_DIR . '/lite/resources/kote2iso.xsl', $params); $importer = new MetadataImport(); $importer->setTableMode('tmp'); $md = array(); $md['file_type'] = 'WMS'; $md['edit_group'] = MICKA_USER; $md['view_group'] = MICKA_USER; $md['mds'] = 0; $md['lang'] = 'cze'; $lang_main = 'cze'; $md['update_type'] = 'lite'; $report = $importer->import($xmlstring, $md['file_type'], MICKA_USER, $md['edit_group'], $md['view_group'], $md['mds'] = 0, $md['lang'], $lang_main, $params = false, $md['update_type']); $md_record = new MdRecord(); $md_record->setTableMode('tmp'); $record = $md_record->getMd('recno', $recno); // Administrace záznamu if ($record['right'] == 'w') { $data = array(); $data['data_type'] = $data_type; if ($edit_group != '') { $data['edit_group'] = $edit_group; } if ($view_group != '') { $data['view_group'] = $view_group; } $md_record->updateMdFromImport($recno, $data); } } else { // Micka $md_record = new MdRecord(); $pom = $md_record->setTmpMdValues($post); if ($pom['ok'] === FALSE) { $rs['report'] = $pom['report']; return $rs; } $record = $md_record->getMd('recno', $recno); } if ($nextblock == -1) { // -1: Ukončit editaci $rs['data'] = $record['md']; $md_record->copyTmpRecordToMd(); $md_record->deleteTmpRecords(); $rs['akce'] = 'search'; $rs['ok'] = TRUE; } elseif ($nextblock == -2) { // -2: Uložení do MD a pokračování v editaci $md_record->copyTmpRecordToMd(); } elseif ($nextblock == -20 || $nextblock == -22) { // -20: průběžné uložení a xml // -22: průběžné uložení a nabídka uložení xml $rs['akce'] = $nextblock == -22 ? 'sxml' : 'xml'; $rs['data'] = $record['md']['PXML']; return $rs; } elseif ($nextblock == -21) { // -21: průběžné uložení a validace $rs['akce'] = 'valid'; $rs['data'] = $record['md']['UUID']; return $rs; } elseif ($nextblock == -19) { // -19: validace $rs['valid'] = TRUE; } if ($nextblock != -1) { // průběžné uložení, jiný profil if ($nexprofil > -1 && $nexprofil != '-19') { $profil = $nexprofil; } if ($nextblock > -1) { $block = $nextblock; } setEditId2Session('profil', $profil); setEditId2Session('package', $block); $rs['akce'] = 'edit'; $rs['ok'] = TRUE; $rs['data']['recno'] = $recno; $rs['data']['uuid'] = ''; $rs['data']['package'] = $block; $rs['data']['profil'] = $profil; } if ($rs['akce'] == 'edit') { $redirectUrl = getUrlEditFromSession(); } else { unsetEditValue2Session(); $redirectUrl = getUrlSearchFromSession(); } //return $rs; return $redirectUrl; }
private function setRecordsValues() { $mode_md = FALSE; if (count($this->md_head) > 0) { $md_record = new MdRecord(); $md_record->setReportValidType($this->report_valid_type['type'], $this->report_valid_type['short']); $md_record->setTableMode($this->table_mode); foreach ($this->md_head as $key => $md) { if ($this->table_mode == 'md' && canActionAcl('mds', $this->md_head[$key]['iso'], 'w') === FALSE) { $this->md_head[$key]['action'] = 'skip'; $this->md_head[$key]['right'] = 'x'; $this->setReport($key, 'error', labelTranslation(MICKA_LANG, 'guest not right')); continue; } $this->md_head[$key]['ok'] = 0; $md_record->setRecordImporting(FALSE); $this->addLogImport('setRecordsValues.MD', $md); // zaznam existuje if ($md['uuid'] != '') { if ($this->micka_lite) { $md_record->setTableMode('tmp'); } else { $md_record->setTableMode('md'); $mode_md = TRUE; } $record = $md_record->getMd('uuid', $md['uuid']); if ($mode_md === TRUE && $record['report'] == 'ok' && $record['right'] == 'w') { $this->setReport($key, 'error', "INFO: " . labelTranslation(MICKA_LANG, 'The metadata record already exists. It will be replaced with the new one when you save it.')); } if ($this->micka_lite) { $record_orig = $record; } else { $md_record->setTableMode($this->table_mode); $record_orig = $md_record->getMd('uuid', $md['uuid']); } $this->addLogImport('setRecordsValues.origMD', $record_orig); $this->addLogImport('setRecordsValues.table_mode', $this->table_mode); if ($this->table_mode == 'tmp' && canActionAcl('mds', $this->md_head[$key]['iso'], 'w') === FALSE) { if ($record_orig['report'] == 'ok' && $record_orig['report'] == 'ok') { $this->md_head[$key]['action'] = 'update'; $this->md_head[$key]['recno'] = isset($record_orig['md']['RECNO']) && $record_orig['md']['RECNO'] > 0 ? $record_orig['md']['RECNO'] : -1; } else { $this->md_head[$key]['action'] = 'insert'; } $this->md_head[$key]['right'] = 'w'; } elseif ($record['report'] == 'ok' && $record['right'] != 'w') { $this->md_head[$key]['action'] = 'skip'; $this->md_head[$key]['right'] = 'x'; $this->setReport($key, 'error', labelTranslation(MICKA_LANG, 'Record exists, import cancelled. No update rights.')); } elseif ($record['report'] == 'Not rights' && $record['right'] == 'x') { $this->md_head[$key]['action'] = 'skip'; $this->md_head[$key]['right'] = 'x'; $this->setReport($key, 'error', labelTranslation(MICKA_LANG, 'Record exists, import cancelled. No update rights.')); } elseif ($record['report'] == 'ok' && $record['right'] == 'w') { if ($this->action == 'skip') { $this->md_head[$key]['action'] = 'skip'; $this->md_head[$key]['right'] = 'w'; $this->setReport($key, 'error', labelTranslation(MICKA_LANG, 'Record exists, import cancelled.')); } else { // update if ($record_orig['report'] == 'Record not found') { // nový záznam v tmp $this->md_head[$key]['action'] = 'insert'; $this->md_head[$key]['right'] = 'w'; } else { $this->md_head[$key]['recno'] = isset($record_orig['md']['RECNO']) && $record_orig['md']['RECNO'] > 0 ? $record_orig['md']['RECNO'] : -1; $this->md_head[$key]['action'] = 'update'; $this->md_head[$key]['right'] = 'w'; //$this->md_head[$key]['report'] = ''; //$this->setReport($key, 'error', "INFO: " . labelTranslation(MICKA_LANG, 'The metadata record already exists. It will be replaced with the new one when you save it.')); $md['langs'] = $this->table_mode == 'tmp' ? getUniqueMdLangs($md['langs'], $record_orig['md']['LANG']) : $md['langs']; $this->data_type = $this->data_type == -100 ? $record_orig['md']['DATA_TYPE'] : $this->data_type; } } } elseif ($record['report'] == 'Record not found') { $this->md_head[$key]['action'] = 'insert'; $this->md_head[$key]['right'] = 'w'; } else { $this->md_head[$key]['action'] = 'skip'; $this->md_head[$key]['right'] = 'x'; $this->setReport($key, 'error', labelTranslation(MICKA_LANG, 'unknow error in MD')); } } else { // Nový záznam $this->md_head[$key]['action'] = 'insert'; $this->md_head[$key]['right'] = 'w'; } // akce $data = array(); switch ($md['iso']) { case 'MD': $data['md_standard'] = 0; break; case 'MS': case 'MC': $data['md_standard'] = 10; break; case 'DC': $data['md_standard'] = 1; break; case 'FC': $data['md_standard'] = 2; break; default: $data['md_standard'] = $this->mds; } $data['lang'] = $md['langs']; $data['server_name'] = $this->server_name; if ($this->md_head[$key]['action'] == 'insert') { // vytvoření záznamu v tabulce [md] if ($md['uuid'] != '') { $data['uuid'] = $md['uuid']; } else { $data['uuid'] = getUuid(); $this->md_head[$key]['uuid'] = $data['uuid']; } $data['edit_group'] = $this->group_e != '' ? $this->group_e : $this->user; $data['view_group'] = $this->group_v != '' ? $this->group_v : $this->user; $data['data_type'] = $this->data_type == -100 ? -1 : $this->data_type; if ($this->table_mode == 'md') { $this->md_head[$key]['recno'] = $md_record->setNewRecordMd($data, $md['lang'], $import = TRUE); } else { $this->md_head[$key]['recno'] = $md_record->setNewRecord($data, $md['lang'], $import = TRUE); } } elseif ($this->md_head[$key]['action'] == 'update' && $this->md_head[$key]['recno'] > 0) { // Aktualizace [md] if ($this->micka_lite === TRUE) { if (array_key_exists('lang', $data) === TRUE) { unset($data['lang']); } } if ($this->micka_lite === FALSE) { $data['data_type'] = $this->data_type; } $md_record->updateMdFromImport($this->md_head[$key]['recno'], $data); // Smazání [md_values] if ($this->micka_lite) { $md_record->deleteMdIdFromMdValues($this->md_head[$key]['recno'], $md['langs'], $this->del_md_id[$key]); } else { $md_record->deleteMdValuesBeforeImport($this->md_head[$key]['recno']); } } if ($this->md_head[$key]['action'] == 'insert' || $this->md_head[$key]['action'] == 'update') { // Vložení nových hodnot if ($this->md_head[$key]['recno'] > 0) { $data = array(); foreach ($this->md_values[$key] as $md_values) { $md_values['recno'] = $this->md_head[$key]['recno']; if ($this->micka_lite === TRUE && isset($record_orig['md']['LANG']) && $md_values['lang'] != 'xxx') { // pokud byl odstraněn nějaký jazyk, odstranit i data if (strpos($record_orig['md']['LANG'], $md_values['lang']) !== FALSE) { array_push($data, $md_values); } } else { array_push($data, $md_values); } } if ($this->micka_lite === FALSE) { // zachovat původní datestamp $md_record->setRecordImporting(TRUE); } $md_record->setMdValues($data); $this->md_head[$key]['ok'] = 1; $this->md_head[$key]['valid'] = $md_record->getReportValid(); } } } } }