function mainInsert($post, $defaultValue = array()) { //my_print_r($post); $rs = array(); $md = array(); $rs['akce'] = 'error'; $rs['ok'] = FALSE; $rs['report'] = ''; $rs['data'] = ''; $md_record = new MdRecord(); //$md_record->deleteTmpRecords(); if (count($post) == 0) { setMickaLog('INSERT ERROR, POST is empty!', 'ERROR', 'micka_main_lib.main_insert'); $rs['report'] = 'Error, not complete data!'; //return $rs; Debugger::log('[micka_main_lib.mainInsert] ' . 'POST is empty!', 'ERROR'); require PHPINC_DIR . '/templates/404_record.php'; } $defaultEditGroup = array_key_exists('edit_group', $defaultValue) === TRUE ? $defaultValue['edit_group'] : MICKA_USER; $defaultViewGroup = array_key_exists('view_group', $defaultValue) === TRUE ? $defaultValue['view_group'] : MICKA_USER; // 0:ISO 19115 | 10:ISO 19119 | 1:DC | 2:FC | 99:import $md['md_standard'] = isset($post['standard']) && $post['standard'] != '' ? htmlspecialchars($post['standard']) : 0; // skupina pro prohlížení $md['view_group'] = isset($post['group_v']) && $post['group_v'] != '' ? htmlspecialchars($post['group_v']) : $defaultEditGroup; // skupina s právem editace $md['edit_group'] = isset($post['group_e']) && $post['group_e'] != '' ? htmlspecialchars($post['group_e']) : $defaultViewGroup; // hlavní jazyk záznamu $lang_main = isset($post['lang_main']) && $post['lang_main'] != '' ? htmlspecialchars($post['lang_main']) : MICKA_LANG; // seznam dalších jazyků $md['lang'] = isset($post['languages']) ? htmlspecialchars(implode($post['languages'], "|")) : ''; if ($md['lang'] == '' && $lang_main != '') { $md['lang'] = $lang_main; } // template s default hodnotami $template = ''; if ($md['md_standard'] < 99) { if ($md['md_standard'] == 0) { $template = PHPCFG_DIR . '/templateMd.xml'; } elseif ($md['md_standard'] == 10) { $template = PHPCFG_DIR . '/templateMs.xml'; } elseif ($md['md_standard'] == 1) { $template = PHPCFG_DIR . '/templateDc.xml'; } elseif ($md['md_standard'] == 2) { $template = PHPCFG_DIR . '/templateFc.xml'; } if ($template != '' && file_exists($template)) { $md['file_type'] = 'ISO19139'; $md['update_type'] = 'skip'; $md['md_standard'] = 99; } } // IMPORT if ($md['md_standard'] == 99) { $md['file_type'] = isset($post['fileType']) && $post['fileType'] != '' ? htmlspecialchars($post['fileType']) : 'ISO19139'; $md['md_rec'] = isset($post['md_rec']) && $post['md_rec'] != '' ? htmlspecialchars($post['md_rec']) : ''; $md['fc'] = isset($post['fc']) && $post['fc'] != '' ? htmlspecialchars($post['fc']) : ''; $md['service_type'] = isset($post['serviceType']) && $post['serviceType'] != '' ? htmlspecialchars($post['serviceType']) : 'WMS'; $md['url'] = isset($post['url']) && $post['url'] != '' ? htmlspecialchars($post['url']) : ''; $md['url'] = $md['url'] != '' ? str_replace('&', '&', $md['url']) : ''; $md['update_type'] = isset($post['updateType']) && $post['updateType'] != '' ? htmlspecialchars($post['updateType']) : 'skip'; } if ($md['md_standard'] < 99) { // Vytvoření nového záznamu v tmp $recno = $md_record->setNewRecord($md, $lang_main); if ($recno > 0) { $rs['akce'] = 'edit'; $rs['ok'] = TRUE; $rs['data'] = $recno; setEditId2Session('recno', 'new'); setEditId2Session('recnoTmp', $recno); $redirectUrl = substr(htmlspecialchars($_SERVER['PHP_SELF']), 0, strrpos($_SERVER['PHP_SELF'], '/')) . '?ak=edit&recno=new'; setUrlEdit2Session($redirectUrl); } //return $rs; return $redirectUrl; } if ($md['md_standard'] == 99) { // Import ze souboru nebo url require PHPPRG_DIR . '/micka_lib_php5.php'; require PHPPRG_DIR . '/micka_lib_insert.php'; require PHPPRG_DIR . '/MdImport.php'; //$prevod = DomainCodes2List(); $report = array(); $importer = new MetadataImport(); if (isset($_FILES['soubor']['tmp_name']) && $_FILES['soubor']['tmp_name'] != '' || $template != '') { if ($_FILES['soubor']['tmp_name'] != '') { if (!file_exists(PHPINC_DIR . '/temp/upload/')) { mkdir(PHPINC_DIR . '/temp/upload/', 0777); } $tmpFileName = PHPINC_DIR . '/temp/upload/' . md5(uniqid(rand(), true)) . '.xml'; if (is_uploaded_file($_FILES['soubor']['tmp_name'])) { move_uploaded_file($_FILES['soubor']['tmp_name'], $tmpFileName); } else { $tmpFileName = ''; } } else { $tmpFileName = $template; } if ($tmpFileName != '') { //$prevod = DomainCodes2List(); $xmlstring = file_get_contents($tmpFileName); $importer = new MetadataImport(); $importer->setTableMode('tmp'); $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['md_rec']); } else { $rs['report'] = "File error!"; return $rs; } } elseif ($md['url'] != '') { setMickaLog($md['url'], 'INFO', 'micka_main_lib.main_insert.url'); $importer->setTableMode('tmp'); $report = $importer->importService($md['url'], $md['service_type'], MICKA_USER, $md['edit_group'], $md['view_group'], $md['mds'] = 10, $md['lang'], $lang_main, $public = 0, $md['update_type']); } else { // není zadán soubor ani url $rs['report'] = "Unknown import type!"; return $rs; } } // zpracování reportu po importu if ($report[0]['ok'] == 1) { if (substr($report[0]['report'], 0, 11) == 'UUID exists') { $rs['report'] = "UUID exists, stop import!"; $rs['akce'] = 'error'; $rs['data'] = $report[0]; return $rs; } else { $rs['ok'] = TRUE; $rs['report'] = $report[0]['report']; $md_record->setTableMode('tmp'); $record = $md_record->getMd('uuid', $report[0]['uuid']); if (is_array($record) && count($record) > 1) { $rs['akce'] = IMPORT_VALID ? 'import' : 'edit'; if ($rs['akce'] == 'edit') { $rs['data'] = $record['md']['RECNO']; } else { $rs['data']['md'] = $record['md']; } } } } else { $rs['report'] = $report[0]['report']; $rs['data'] = $report[0]; return $rs; } if ($rs['akce'] == 'edit') { $redirectUrl = substr(htmlspecialchars($_SERVER['PHP_SELF']), 0, strrpos($_SERVER['PHP_SELF'], '/')) . '?ak=edit&recno=new'; setUrlEdit2Session($redirectUrl); } else { // TODO: zatím jen editace $redirectUrl = substr(htmlspecialchars($_SERVER['PHP_SELF']), 0, strrpos($_SERVER['PHP_SELF'], '/')) . '?ak=edit&recno=new'; setUrlEdit2Session($redirectUrl); } return $redirectUrl; }
/** * Import metadat * ===================== * @param array $data pole metadat pro uložení * @param string $mode delete|all|skip|insert|update|fc * @return array report */ public function dataToMd($data, $mode, $params = array()) { $this->addLogImport('dataToMd.start', "mode={$mode}, public=" . $this->data_type); //$this->addLogImport('dataToMd DATA', $data); //Debugger::log('[MdImport.dataToMd.data] ' . print_r($data, true), 'INFO'); $rs = array(); if (is_array($data) === FALSE) { $rs[0]['report'] = 'input data is not array'; $rs[0]['ok'] = 0; return $rs; } if (count($data) == 0) { $rs[0]['report'] = 'input data is empty'; $rs[0]['ok'] = 0; return $rs; } if ($mode == 'lite') { $this->micka_lite = TRUE; $mode = 'all'; } $this->action = $mode; $this->setMdValues($data); switch ($mode) { case 'delete': $this->deleteMd($data); break; case 'skip': // pokud záznam existuje, nic neaktualizovat // pokud záznam existuje, nic neaktualizovat case 'all': case 'insert': case 'update': case 'fc': unset($data); $this->setMds(); $this->setSchemaMd(); $this->setMdHead(); $this->processArrayMd($this->md_values); $this->setRecordsValues(); break; default: } //my_print_r($this->md_head); //echo "<hr>"; //my_print_r($this->md_values); //echo "<hr>"; //my_print_r($this->del_md_id); $this->addLogImport('dataToMd.md_head', $this->md_head); if ($mode != 'delete') { foreach ($this->md_head as $key => $value) { setEditId2Session('recno', 'new'); setEditId2Session('recnoTmp', $this->md_head[$key]['recno']); unset($this->md_head[$key]['iso']); unset($this->md_head[$key]['bbox_x1']); unset($this->md_head[$key]['bbox_x2']); unset($this->md_head[$key]['bbox_y1']); unset($this->md_head[$key]['bbox_y2']); unset($this->md_head[$key]['range_begin']); unset($this->md_head[$key]['range_end']); unset($this->md_head[$key]['recno']); unset($this->md_head[$key]['lang']); unset($this->md_head[$key]['langs']); unset($this->md_head[$key]['action']); unset($this->md_head[$key]['right']); } unset($this->md_values); unset($this->del_md_id); unset($this->tree_el); } $this->addLogImport('dataToMd.md_head.return', $this->md_head); return $this->md_head; }