/** * Metainformation catalogue * -------------------------------------------------- * * MICKA_LIB_INSERT.PHP for MicKa * * @link http://www.bnhelp.cz * @package Micka * @category Metadata * @version 20101120 * @authors DZ */ function deleteMd($user, $type, $value, $mode, $par = NULL) { setMickaLog('micka_lib_insert.php (deleteMd)', 'DEBUG', "user={$user}, {$type}={$value}, mode={$mode}, par={$par}"); $rs = FALSE; // autorizace if ($user == 'guest' || !canAction()) { return $rs; } $record = getMdHeader($type, $value, $col = '', $fetch = array('all', '=')); if (isset($record[0]['RECNO']) && $record[0]['RECNO'] > -1) { if (!getMdRight('edit', $user, $record[0]['DATA_TYPE'], $record[0]['CREATE_USER'], $record[0]['EDIT_GROUP'], $record[0]['VIEW_GROUP'])) { return $rs; } else { $sql = array(); if ($mode == 'all') { array_push($sql, 'DELETE FROM [md_values] WHERE [recno]=%i;', $record[0]['RECNO']); array_push($sql, 'DELETE FROM [md] WHERE [recno]=%i;', $record[0]['RECNO']); } elseif ($mode == 'value') { array_push($sql, 'DELETE FROM [md_values] WHERE [recno]=%i AND md_id<>38;', $record[0]['RECNO']); } dibi::begin(); try { dibi::query($sql); dibi::commit(); $rs = TRUE; } catch (DibiException $e) { setMickaLog($e, 'ERROR', 'micka_lib_insert.php (deleteMd)'); dibi::rollback(); } } } //Debug::dump($rs); setMickaLog('micka_lib_insert.php (deleteMd)', 'DEBUG', "return={$rs}"); return $rs; }
public function setRecordAdmin($form_akce, $form_data) { $rs = 'error'; if ($form_data['recno'] == '') { return $rs; } $del_lang = array(); $recno = $form_data['recno']; $record = $this->getMdValues($recno, 'xxx', 0, 0); if ($record['report'] != 'ok' || $this->md_record['md']['RECNO'] != $recno) { setMickaLog($record['report'], 'ERROR', 'MdRecord.setRecordAdmin'); //$rs['report'] = $md['report']; return $rs; } if ($this->md_record['user_right'] == 'r') { setMickaLog("Not edit rights", 'ERROR', 'MdRecord.setRecordAdmin'); //$rs['report'] = 'Not rights'; return $rs; } if (isset($record['md']['RECNO']) && $record['md']['RECNO'] > -1) { // jazyk metadat $md_lang = ''; if ($record['md']['MD_STANDARD'] == 0 || $record['md']['MD_STANDARD'] == 10) { foreach ($record['md_values'] as $row) { if ($row['MD_ID'] == 5527) { $md_lang = $row['MD_VALUE']; break; } } } if ($md_lang != '' && strpos($form_data['lang'], $md_lang) === FALSE) { $form_data['lang'] = $form_data['lang'] == '' ? $md_lang : $md_lang . '|' . $form_data['lang']; } $langs = explode('|', $form_data['lang']); $orig_lang = explode('|', $record['md']['LANG']); foreach ($orig_lang as $kl => $hod) { $key = array_search($hod, $langs); if ($key === false) { $del_lang[] = $hod; } } if ($form_akce == 'form' && count($del_lang) > 0) { $_SESSION['micka']['rec_admin']['recno'] = $form_data['recno']; $_SESSION['micka']['rec_admin']['edit_group'] = $form_data['edit_group']; $_SESSION['micka']['rec_admin']['view_group'] = $form_data['view_group']; //$_SESSION['micka']['rec_admin']['data_type'] = $form_data['data_type']; $_SESSION['micka']['rec_admin']['lang'] = $form_data['lang']; return 'warning'; } elseif ($form_akce == 'warning' && count($del_lang) > 0) { $this->deleteMdValues($recno, -1, -1, -1, $del_lang); } if ($this->setMd($recno, $form_data)) { $rs = 'ok'; } } return $rs; }
function getMdRecord($user, $uuid, $akce) { setMickaLog("user={$user}, uuid={$uuid}, akce={$akce}", 'DEBUG', 'MdDetail.getMdRecord.start'); $rs = array(); $rs['data'] = FALSE; $col = 'recno, uuid, md_standard, lang, data_type, create_user, edit_group, view_group, x1 ,x2, y1, y2, title, valid'; $record = getMdHeader('uuid', $uuid, $col, array('all', '=')); if (isset($record[0]['RECNO']) && $record[0]['RECNO'] > -1) { // autorizace if (!getMdRight('view', $user, $record[0]['DATA_TYPE'], $record[0]['CREATE_USER'], $record[0]['EDIT_GROUP'], $record[0]['VIEW_GROUP'])) { setMickaLog("Not right", 'ERROR', 'MdDetail.php (getMdRecord)'); return $rs; } $rs['head']['edit'] = 0; if (getMdRight('edit', $user, $record[0]['DATA_TYPE'], $record[0]['CREATE_USER'], $record[0]['EDIT_GROUP'], $record[0]['VIEW_GROUP']) === TRUE) { $rs['head']['edit'] = 1; } $this->mds = $record[0]['MD_STANDARD']; $rs['head']['recno'] = $record[0]['RECNO']; $rs['head']['mds'] = $record[0]['MD_STANDARD']; $rs['head']['uuid'] = $record[0]['UUID']; $rs['head']['title'] = $record[0]['TITLE']; $rs['head']['valid'] = $record[0]['VALID'] != '' ? $record[0]['VALID'] : ''; $rs['head']['x1'] = array_key_exists('X1', $record[0]) ? (string) str_replace(",", ".", $record[0]['X1']) : ''; $rs['head']['y1'] = array_key_exists('Y1', $record[0]) ? (string) str_replace(",", ".", $record[0]['Y1']) : ''; $rs['head']['x2'] = array_key_exists('X2', $record[0]) ? (string) str_replace(",", ".", $record[0]['X2']) : ''; $rs['head']['y2'] = array_key_exists('Y2', $record[0]) ? (string) str_replace(",", ".", $record[0]['Y2']) : ''; $rs['head']['hierarchy'] = ''; if ($akce == 'detail') { if ($record[0]['MD_STANDARD'] == 0 || $record[0]['MD_STANDARD'] == 10) { $rs['data'] = $this->getMdValuesMdId($record[0]['RECNO'], $record[0]['MD_STANDARD'], $this->getLangValue($record[0]['LANG'])); // Rodicovske zaznamy $master = isset($rs['data'][121][0]) ? $rs['data'][121][0] : ''; $rs['head']['master'] = $this->getMdMaster($master); // Je rodicem pro zaznamy $rs['head']['slave'] = $this->getMdSlave($record[0]['UUID']); $rs['head']['repre'] = $this->getSpatialRep($record[0]['RECNO']); } elseif ($record[0]['MD_STANDARD'] == 1) { $rs['data'] = $this->getMdValuesMdId($record[0]['RECNO'], $record[0]['MD_STANDARD'], $this->getLangValue($record[0]['LANG'])); } elseif ($record[0]['MD_STANDARD'] == 2) { //$pom = $this->getMdValuesMdId($record[0]['RECNO'], $record[0]['MD_STANDARD'], $this->getLangValue($record[0]['LANG']), 'no_lang'); $pom = getMdValues($record[0]['RECNO'], $record[0]['MD_STANDARD'], $this->getLangValue($record[0]['LANG']), 'no_lang'); if (isset($pom[0][0])) { $rs['data'] = $pom[0][0]; } } } elseif ($akce == 'detailall') { $rs['data'] = $this->getMdDetailView($record[0]['RECNO'], $record[0]['MD_STANDARD']); if ($record[0]['MD_STANDARD'] == 0 || $record[0]['MD_STANDARD'] == 10) { foreach ($rs['data'] as $value) { if ($value['id'] == 11 || $value['id'] == 5063) { $rs['head']['title'] = $value['hodnota']; break; } } } } } $rs['head']['hierarchy'] = $this->hierarchy; setMickaLog($rs, 'DEBUG', 'MdDetail.getMdRecord.return'); return $rs; }
function main_rec_admin($post) { $rs = array(); $rs['akce'] = 'error'; $rs['ok'] = FALSE; $rs['report'] = ''; $rs['data'] = ''; //$recno = ($post['recno'] != '') ? htmlspecialchars($post['recno']) : -1; $recno = $_REQUEST['recno'] != '' ? htmlspecialchars($_REQUEST['recno']) : -1; if ($recno == -1) { setMickaLog('Recno=-1, not edit', 'ERROR', 'micka_main_lib.main_rec_admin'); $rs['report'] = 'Bad input! (recno -1)'; return $rs; } $form_akce = isset($post['form_akce']) ? htmlspecialchars($post['form_akce']) : 'new'; $md_record = new MdRecord(); $md_record->setTableMode('tmp'); if ($form_akce == 'new') { // editační formulář $record = $md_record->getMdValues($recno, 'xxx', 0, 0); if (isset($record['report']) && $record['report'] != 'ok') { setMickaLog("Recno={$recno}, " . $record['report'], 'ERROR', 'micka_main_lib.main_rec_admin'); $rs['report'] = $record['report']; return $rs; } $rs['ok'] = TRUE; $rs['akce'] = 'record_admin'; $rs['data']['form_akce'] = 'new'; $rs['data']['RECNO'] = $record['md']['RECNO']; //$rs['data']['DATA_TYPE'] = $record['md']['DATA_TYPE']; $rs['data']['LANG'] = $record['md']['LANG']; //$rs['data']['EDIT_GROUP'] = $record['md']['EDIT_GROUP']; //$rs['data']['VIEW_GROUP'] = $record['md']['VIEW_GROUP']; // jazyk metadat $rs['data']['md_lang'] = ''; if ($record['md']['MD_STANDARD'] == 0 || $record['md']['MD_STANDARD'] == 10) { foreach ($record['md_values'] as $row) { if ($row['MD_ID'] == 5527) { $rs['data']['md_lang'] = $row['MD_VALUE']; break; } } } } elseif ($form_akce == 'form' && count($post) > 1) { $form_data['recno'] = $recno; //$form_data['edit_group'] = $post['edit_group']; //$form_data['view_group'] = $post['view_group']; //$form_data['data_type'] = isset($post['public']) ? 1 : 0; $form_data['lang'] = isset($post['rec_lang']) && count($post['rec_lang']) > 0 ? implode('|', $post['rec_lang']) : ''; $rs['ok'] = TRUE; $rs['akce'] = 'record_admin'; $rs['data']['form_akce'] = $md_record->setRecordAdmin($form_akce, $form_data); $rs['data']['RECNO'] = $recno; //$rs['data']['DATA_TYPE'] = ''; $rs['data']['LANG'] = ''; //$rs['data']['EDIT_GROUP'] = ''; //$rs['data']['VIEW_GROUP'] = ''; } elseif ($form_akce == 'form' && count($post) < 0) { setMickaLog('Not complete input!', 'ERROR', 'micka_main_lib.main_rec_admin'); $rs['report'] = 'Not complete input!'; } elseif ($form_akce == 'warning') { $recno = isset($post['recno']) ? htmlspecialchars($post['recno']) : -1; $form_data['recno'] = $_SESSION['micka']['rec_admin']['recno']; //$form_data['edit_group'] = $_SESSION['micka']['rec_admin']['edit_group']; //$form_data['view_group'] = $_SESSION['micka']['rec_admin']['view_group']; //$form_data['data_type'] = $_SESSION['micka']['rec_admin']['data_type']; $form_data['lang'] = $_SESSION['micka']['rec_admin']['lang']; unset($_SESSION['micka']['rec_admin']); $rs['ok'] = TRUE; $rs['akce'] = 'record_admin'; $rs['data']['form_akce'] = $md_record->setRecordAdmin($form_akce, $form_data); } return $rs; }
function getMdIdFromMdPath($md_path) { $rs = ''; $md_path = substr($md_path, 0, strlen($md_path) - 1); $pom = explode('_', $md_path); if (count($pom) > 1) { $idx = count($pom) - 2; $rs = $pom[$idx]; } if ($rs == '') { setMickaLog("BAD md_path={$md_path}", 'ERROR', 'micka_lib.getMdIdFromMdPath'); } return $rs; }
function checkProfilSelect($mdid, $profil) { setMickaLog("BEGIN", 'DEBUG', 'Tree.php (checkProfilSelect)'); $sql = array(); $rs = array(); $sql[] = "SELECT profil_id,md_id FROM profil WHERE md_id IN ({$mdid}) AND profil_id IN ({$profil})"; $result = _executeSql('select', $sql, array('all')); foreach ($result as $row) { $mdid = $row['MD_ID']; $profil = $row['PROFIL_ID']; $rs[$mdid][$profil] = $row['MD_ID']; } return $rs; }
public function getEditForm($mds, $recno, $md_langs, $profil, $package, $md_values) { setMickaLog("mds={$mds}, recno={$recno}, profil={$profil}, package={$package}", 'DEBUG', 'EditForm.getEditForm'); $md_id_start = -1; $this->setMdLangs($md_langs); $this->setCodeListArray(getIsInspirePackage($mds, $profil)); $this->setButtonLabelArray(); $this->setFormValuesArray($md_values); if ($mds == 10 && $profil == -1 && $package == 1) { $md_id_start = 4752; } if ($mds == 0 && $profil == -1 && $package == 1) { $md_id_start = 1; } $this->recno = $recno; $this->mds = $mds; $this->profil = $profil; $this->package = $package; $this->getFormData($this->getMdTree($recno, $mds, $profil, $package, $md_id_start)); $this->getRepeat(1, 1); return $this->form_data; }
function updateXml($user, $type, $value) { $rs = FALSE; $xsltemplate = 'micka2one19139.xsl'; $recno = -1; $uuid = ''; if ($type == 'uuid' && $value != '') { $uuid = $value; } elseif ($type == 'recno' && $value > -1) { $recno = $value; $uuid = getMdHeader($type, $value, 'uuid', array('single')); $type = 'uuid'; } if ($type == 'uuid' && $uuid != '') { $xml = getXml($user, $uuid, $xsltemplate, 'data'); if ($xml === FALSE || $xml == '') { setMickaLog('$xml === FALSE', 'ERROR', 'micka_lib_xml.php (updateXml)'); } else { $sql = array(); array_push($sql, "UPDATE md SET pxml=%s WHERE uuid=%s", $xml, $uuid); $rs = _executeSql('update', $sql, array('all')); } } return $rs; }
public function getData($in) { setMickaLog($in, 'FUNCTION', "MdExport.getData.start"); $rs = array(); $rs['paginator']['records'] = 0; $this->xml_from = 'summary'; $this->setQueryIn($in); $in = $this->query_in; $pom = $this->setQuery($in); if ($pom == -1) { setMickaLog('SQL == -1', 'ERROR', 'MdExport.getData'); // TODO: návrat chyby /* if ($this->query_status === FALSE) { //my_print_r($this->query_error); } */ return -1; } elseif ($pom['paginator']['records'] > 0) { $result = dibi::query($pom['sql']); $rs['data'] = DB_DRIVER == 'oracle' ? setUpperColsName($result->fetchAssoc('RECNO,#,=')) : setUpperColsName($result->fetchAssoc('recno,#,=')); $rs['paginator'] = $pom['paginator']; } if (isset($rs['data']) && count($rs['data']) > 0) { $rs['data'] = $this->setData2Micka($rs['data']); } setMickaLog($rs, 'DEBUG', "MdExport.getData.return"); return $rs; }
/** * Provedení sql dotazu a předání nalezených záznamů v požadovaném tvaru * * <b>Příklady:</b><br> * první políčko výsledku<br> * <code>_executeSql('select', $sql, array('single'));</code> * celá tabulka do indexovaného pole<br> * <code>_executeSql('select', $sql, array('all'));</code> * celá tabulka do asociativního pole a klíčem je políčko ‚recno‘ * <code>_executeSql('select', array($pom['sql']), array('assoc', 'recno,#,='));</code> * asociativního pole klíč ⇒ hodnota * <code>_executeSql('select', array($pom['sql']), array('pairs', 'recno', 'xmldata'));</code> * update, insert, delete * <code>_executeSql('update', $sql, array());</code> * * @param string $type 'select', 'update', 'insert', 'delete' * @param array $sql * @param array $fetch 'single', 'all', 'assoc', 'pairs' */ function _executeSql($type, $sql, $fetch, $upper = TRUE) { //setMickaLog("SQL TYPE=$type, fetch=" . $fetch[0], 'FUNCTION', 'micka_lib_db._executeSql.start'); $rs = FALSE; if (count($sql) == 0) { setMickaLog("empty SQL", 'ERROR', 'micka_lib_db._executeSql'); return $sql; } if (is_array($sql) && is_array($fetch) && $type == 'select') { $result = dibi::query($sql); setMickaLog(preg_replace("/\\s{2,}/", ' ', dibi::$sql), 'SQL', 'micka_lib_db._executeSql.sql'); //Debugger::log('[micka_lib_db._executeSql.select] ' . dibi::$sql, 'INFO'); //Debugger::log('[micka_lib_db._executeSql.select] ' . print_r($sql, true), 'INFO'); if ($fetch[0] == 'single') { $rs = trim($result->fetchSingle()); } elseif ($fetch[0] == 'all') { //setMickaLog("FETCH ALL START", 'DEBUG', 'micka_lib_db._executeSql'); $blob = 'OCI-Lob'; //if (count($result) > 0) { // FIXME: ORACLE - nefunguje foreach ($result as $n => $row) { foreach ($row as $key => $value) { if (DB_DRIVER == 'oracle') { if ($value instanceof $blob) { $rs[$n][$key] = $value->load(); } else { $rs[$n][$key] = is_string($value) ? rtrim($value) : $value; } } else { $rs[$n][strtoupper($key)] = is_string($value) ? rtrim($value) : $value; } } } //} //setMickaLog("FETCH ALL END", 'DEBUG', 'micka_lib_db._executeSql'); } elseif ($fetch[0] == 'assoc') { $rs = setUpperColsName($result->fetchAssoc($fetch[1])); } elseif ($fetch[0] == 'pairs' && count($fetch) == 3) { if (DB_DRIVER == 'oracle') { $rs = $upper ? setUpperColsName($result->fetchPairs(strtoupper($fetch[1]), strtoupper($fetch[2]))) : $result->fetchPairs(strtoupper($fetch[1]), strtoupper($fetch[2])); } else { $rs = $upper ? setUpperColsName($result->fetchPairs($fetch[1], $fetch[2])) : $result->fetchPairs($fetch[1], $fetch[2]); } } } elseif (is_array($sql) && ($type == 'update' || $type == 'insert' || $type == 'delete')) { $rs = dibi::query($sql); setMickaLog(preg_replace("/\\s{2,}/", ' ', dibi::$sql), 'SQL', 'micka_lib_db._executeSql.sql'); //Debugger::log('[micka_lib_db._executeSql.update] ' . dibi::$sql, 'INFO'); } elseif (is_array($sql) && $type == 'pxml') { //Debugger::log('[micka_lib_db._executeSql.pxml] ' . $sql[0], 'INFO'); $rs = dibi::query($sql[0]); //Debugger::log('[micka_lib_db._executeSql.pxml] OK', 'INFO'); } else { setMickaLog("unknow TYPE SQL", 'ERROR', 'micka_lib_db._executeSql'); } unset($result); setMickaLog("", 'FUNCTION', 'micka_lib_db._executeSql.end'); return $rs; }
private function addLogImport($fc, $text) { setMickaLog($text, 'DEBUG', "MdImport.{$fc}"); }