Пример #1
0
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('&amp;', '&', $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;
}
Пример #2
0
 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();
                 }
             }
         }
     }
 }