Beispiel #1
0
function getMdSummary()
{
    $rs = array();
    $sql = array();
    $sql[] = 'SELECT recno,uuid,data_type,md_standard,create_user,edit_group,view_group,create_date,last_update_date,title FROM md ORDER BY recno';
    $dbrs = _executeSql('select', $sql, array('all'));
    if (is_array($dbrs) && count($dbrs) > 0) {
        $rs = $dbrs;
    }
    return $rs;
}
Beispiel #2
0
function getSets()
{
    $sql = array();
    $sql[] = 'SELECT * FROM harvest';
    array_push($sql, 'ORDER BY name');
    try {
        $rs = dibi::query($sql);
        $rs = _executeSql('select', $sql, array('all'));
        foreach ($rs as $row) {
            $result[] = array("id" => $row['NAME'], "source" => $row['SOURCE'], "type" => $row['TYPE'], "h_interval" => $row['H_INTERVAL'], "HarvestInterval" => $row['PERIOD'], "handlers" => $row['HANDLERS']);
        }
    } catch (DibiException $e) {
        var_dump($e);
        $result = false;
    }
    return $result;
}
                } else {
                    $sql = 'INSERT INTO sq_ast_lookup_remap(url, remap_url, auto_remap) VALUES (:url, :remap_url, :auto_remap)';
                }
                $bind_vars = array('url' => $protocol . '://' . $url, 'remap_url' => $protocol . '://' . $updated_url, 'auto_remap' => '1');
                $records_count = _executeSql($sql, $bind_vars);
                $summary['ast_lookup_remap'] += $records_count ? $records_count : 0;
                if ($records_count === FALSE) {
                    break 2;
                }
            }
            //end foreach protocol
        }
        //end if non-unrestricted url
        // Update ast_lookup_value table
        $sql = 'UPDATE sq_ast_lookup_value SET url = :updated_url WHERE url = :url';
        $records_count = _executeSql($sql, array('updated_url' => $updated_url, 'url' => $url));
        $summary['ast_lookup_value'] += $records_count ? $records_count : 0;
        if ($records_count === FALSE) {
            break 2;
        }
    }
    //end foreach
}
//end foreach
// We will update the db only if there are no errors
if ($ERRORS) {
    $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
    echo "\nFollowing errors occured when trying to update the lookups:\n";
    echo implode("\n", $ERRORS) . "\n\n";
    echo "Please resolve these errors before running this script. DB was not updated.\n";
} else {
Beispiel #4
0
            }
        } else {
            array_push($sql, "AND {$right}");
        }
        if ($query != '') {
            array_push($sql, " AND " . setSqlLike('md_values.md_value', "'%" . $query . "%'"));
        }
        if ($contact_role != '') {
            array_push($sql, "AND m.md_id=5038 AND m.md_value=%s ", $contact_role);
        } else {
            array_push($sql, "AND m.md_id=5038 AND m.md_value IS NOT NULL");
        }
        //array_push($sql, "ORDER BY md_values.md_value");
        break;
}
$result = _executeSql('select', $sql, array('all'));
$firs_record = TRUE;
$org_lang = '';
$org_eng = '';
$org_ost = '';
if ($query_lang == '') {
    $query_lang = 'eng';
}
if ($orderBy === FALSE) {
    foreach ($result as $key => $value) {
        $rs[] = array('id' => $key + 1, "value" => $value['MD_VALUE']);
    }
    $rs = array('numresults' => count($rs), 'records' => $rs);
    header("Content-type: application/json charset=\"utf-8\"");
    echo json_encode($rs);
    exit;
Beispiel #5
0
 public function delProfilNames($profil_id)
 {
     $sql = array();
     $rs = array();
     $profil = 0;
     $rs['ok'] = 'false';
     $rs['report'] = 'error';
     if ($profil_id > 10 && $profil_id < 100 || $profil_id > 110) {
         $profil = $profil_id;
         array_push($sql, "DELETE FROM profil_names WHERE profil_id=%i", $profil_id);
     }
     if (count($sql) > 0) {
         $recordSet = _executeSql('delete', $sql, array('all'));
     }
     if ($profil > 110) {
         $sql = array();
         array_push($sql, "DELETE FROM profil_names WHERE profil_id=%i", $profil_id - 100);
         $recordSet = _executeSql('delete', $sql, array('all'));
         $sql = array();
         array_push($sql, "DELETE FROM profil WHERE profil_id=%i", $profil_id - 100);
         $recordSet = _executeSql('delete', $sql, array('all'));
     }
     if ($profil > 10 && $profil < 100) {
         $sql = array();
         array_push($sql, "DELETE FROM profil_names WHERE profil_id=%i", $profil_id + 100);
         $recordSet = _executeSql('delete', $sql, array('all'));
         $sql = array();
         array_push($sql, "DELETE FROM profil WHERE profil_id=%i", $profil_id + 100);
         $recordSet = _executeSql('delete', $sql, array('all'));
     }
     return $rs;
 }
Beispiel #6
0
 private function getMdTree($recno, $mds, $profil_id, $package_id, $md_id_start = -1)
 {
     setMickaLog("recno={$recno}, mds={$mds}, profil={$profil_id}, package={$package_id}, start={$md_id_start}", 'DEBUG', 'EditForm.getMdTree.start');
     $rs = array();
     $sql = array();
     //$mds_package = $mds;
     if ($mds == 10) {
         $mds = 0;
     }
     array_push($sql, "\n\t\t\tSELECT elements.el_id,\n\t\t\t\t\t\t elements.el_name,\n\t\t\t\t\t\t elements.form_code,\n\t\t\t\t\t\t elements.form_pack,\n\t\t\t\t\t\t elements.el_short_name,\n\t\t\t\t\t\t elements.from_codelist,\n\t\t\t\t\t\t elements.only_value,\n\t\t\t\t\t\t elements.form_ignore,\n\t\t\t\t\t\t elements.multi_lang,\n\t\t\t\t\t\t tree.md_id,\n\t\t\t\t\t\t tree.md_left,\n\t\t\t\t\t\t tree.md_right,\n\t\t\t\t\t\t tree.md_level,\n\t\t\t\t\t\t tree.mandt_code,\n\t\t\t\t\t\t tree.md_path,\n\t\t\t\t\t\t tree.max_nb,\n\t\t\t\t\t\t tree.button_exe,\n\t\t\t\t\t\t tree.package_id,\n                         tree.inspire_code,\n\t\t\t\t\t\t label.label_text,\n\t\t\t\t\t\t label.label_help\n\t\t\tFROM (label INNER JOIN elements ON label.label_join = elements.el_id) INNER JOIN tree ON elements.el_id = tree.el_id\n\t\t");
     //array_push($sql, "WHERE label.label_type='EL' AND elements.form_ignore=0");
     array_push($sql, "WHERE label.label_type='EL'");
     array_push($sql, "AND tree.md_standard=%i", $mds);
     array_push($sql, "AND label.lang=%s", MICKA_LANG);
     if ($profil_id > -1) {
         array_push($sql, "AND tree.md_id IN(SELECT md_id FROM profil WHERE profil_id=%i)", $profil_id);
     }
     if ($md_id_start > -1) {
         $start_sql = array();
         array_push($start_sql, "SELECT md_left, md_right FROM tree WHERE md_standard=%i AND md_id=%i", $mds, $md_id_start);
         $pom = _executeSql('select', $start_sql, array('all', '='));
         if (count($pom) == 1) {
             $md_left = $pom[0]['MD_LEFT'];
             $md_right = $pom[0]['MD_RIGHT'];
             array_push($sql, "AND tree.md_left>=%i  AND tree.md_right<=%i", $md_left, $md_right);
         } else {
             setMickaLog("Not found md_id={$md_id_start}!", 'ERROR', 'EditForm.getMdTree');
         }
     }
     if ($profil_id == -1 && $package_id > -1 && $md_id_start == -1) {
         $start_sql = array();
         array_push($start_sql, "SELECT md_left, md_right FROM tree WHERE md_standard=%i AND md_id=", $mds);
         array_push($start_sql, "(SELECT md_id FROM packages WHERE md_standard=%i AND package_id=%i)", $mds, $package_id);
         $pom = _executeSql('select', $start_sql, array('all', '='));
         if (count($pom) == 1) {
             $md_left = $pom[0]['MD_LEFT'];
             $md_right = $pom[0]['MD_RIGHT'];
             array_push($sql, "AND tree.md_left>=%i  AND tree.md_right<=%i", $md_left, $md_right);
         } else {
             setMickaLog("Not found left, right! Profil={$profil_id}, package={$package_id}.", 'ERROR', 'EditForm.getMdTree');
         }
     }
     if ($package_id > -1) {
         array_push($sql, "AND tree.package_id=%i", $package_id);
     }
     if ($mds == 1) {
         array_push($sql, "ORDER BY tree.md_level,tree.md_left");
     } else {
         array_push($sql, "ORDER BY tree.md_left");
     }
     if (count($sql) > 1) {
         $rs = _executeSql('select', $sql, array('all', '='));
     }
     //my_print_r($rs);
     return $rs;
 }
Beispiel #7
0
function updateMdGeom($recno, $x1, $y1, $x2, $y2, $table = 'md')
{
    $sql = array();
    if (SPATIALDB) {
        /*
        array_push($sql, "UPDATE md SET the_geom=GeomFromText('MULTIPOLYGON(((");
        array_push($sql, "%f %f,", $x1, $y1);
        array_push($sql, "%f %f,", $x1, $y2);
        array_push($sql, "%f %f,", $x2, $y2);
        array_push($sql, "%f %f,", $x2, $y1);
        array_push($sql, "%f %f", $x1, $y1);
        array_push($sql, ")))',-1),");
        array_push($sql, "x1=%f, y1=%f, x2=%f, y2=%f", $x1, $y1, $x2, $y2);
        */
        $sql[] = "\n\t\t\tUPDATE [{$table}] SET the_geom=GeomFromText('MULTIPOLYGON((({$x1} {$y1},{$x1} {$y2},{$x2} {$y2},{$x2} {$y1},{$x1} {$y1})))',-1),\n\t\t    x1={$x1}, y1={$y1}, x2={$x2}, y2={$y2}\n\t\t";
        array_push($sql, "WHERE recno=%i", $recno);
    } else {
        array_push($sql, "\n\t\t\tUPDATE [{$table}] SET x1=%f, y1=%f, x2=%f, y2=%f WHERE recno=%i\n\t\t", $x1, $y1, $x2, $y2, $recno);
    }
    $result = _executeSql('insert', $sql, array());
}
Beispiel #8
0
 private function getMdValuesAll($recno, $mds, $pid = -1, $hyper = -1)
 {
     $rs = array();
     if ($mds == 10) {
         $mds = 0;
     }
     $sql = array();
     array_push($sql, "\n\t\t\tSELECT " . setNtext2Text('md_values.', 'md_value') . ", md_values.md_id, md_values.md_path,  md_values.lang, elements.form_code, elements.el_id, elements.from_codelist\n\t\t\tFROM (elements RIGHT JOIN tree ON elements.el_id = tree.el_id) RIGHT JOIN md_values ON tree.md_id = md_values.md_id\n\t\t\tWHERE md_values.recno=%i AND tree.md_standard=%i AND (md_values.lang='xxx' OR md_values.lang='uri' OR md_values.lang=%s)\n\t\t", $recno, $mds, MICKA_LANG);
     if ($pid == -1) {
         array_push($sql, "AND md_values.package_id>0");
     } else {
         array_push($sql, "AND md_values.package_id=%i", $pid);
     }
     array_push($sql, "ORDER BY tree.md_left, md_values.md_path");
     $result = _executeSql('select', $sql, array('all'));
     foreach ($result as $row) {
         $sanit = true;
         $hle = $row['MD_VALUE'];
         if ($row['FORM_CODE'] == 'D' && MICKA_LANG == 'cze') {
             $hle = DateIso2Cz($hle);
         }
         if ($row['FORM_CODE'] == 'C') {
             if (!$row['FROM_CODELIST'] == '') {
                 $eid = $row['FROM_CODELIST'];
             } else {
                 $eid = $row['EL_ID'];
             }
             // hierarchy
             if ($mds == 0 && $row['MD_ID'] == 623) {
                 $this->hierarchy = $hle;
             }
             $hle = getLabelCodeList($hle, $eid);
         } else {
             if ($hyper == 1) {
                 if ($row['FORM_CODE'] == 'T') {
                     $hle_link = getHyperLink($hle);
                     if ($hle != $hle_link) {
                         $sanit = false;
                     }
                 }
             }
         }
         $hodnoty = array();
         $md_id = $row['MD_ID'];
         if ($sanit) {
             $hle = htmlspecialchars($hle);
         }
         $hodnoty[$md_id]['value'] = str_replace('\\', '\\\\', $hle);
         $hodnoty[$md_id]['lang'] = $row['LANG'];
         $retez = $row['MD_PATH'];
         $ret = substr($retez, 0, strlen($retez) - 1);
         $pom = explode('_', $ret);
         $c = sizeof(explode('_', $ret));
         $retez2 = "";
         for ($i = 0; $i < $c;) {
             $id1 = $pom[$i];
             $i++;
             $id2 = $pom[$i];
             $i++;
             if ($retez2 == '') {
                 $retez2 = $id1 . "_'P" . $id2 . "'";
             } else {
                 $retez2 = $retez2 . "_" . $id1 . "_'P" . $id2 . "'";
             }
         }
         $retez2 = str_replace("_", "][", $retez2);
         $hodnoty[$md_id]['path'] = '[' . $retez2 . ']';
         array_push($rs, $hodnoty);
     }
     return $rs;
 }
Beispiel #9
0
 public function getXmlTmpMd($uuid)
 {
     setMickaLog("uuid={$uuid}", 'FUNCTION', "MdExport.getXmlTmpMd.start");
     $vysl = array();
     $recno_arr = array();
     $elements_label = $this->getIdElements();
     // nacteni elementu pro prevod na kody
     $sql = array();
     $tmp_table_md = TMPTABLE_PREFIX . '_md';
     $tmp_table_md_values = TMPTABLE_PREFIX . '_md_values';
     array_push($sql, "\n\t\t\tSELECT {$tmp_table_md_values}.recno, {$tmp_table_md_values}.md_path, " . setNtext2Text($tmp_table_md_values . '.', 'md_value') . ", {$tmp_table_md_values}.lang, {$tmp_table_md}.md_standard\n\t\t\tFROM ({$tmp_table_md} JOIN {$tmp_table_md_values} ON {$tmp_table_md}.recno = {$tmp_table_md_values}.recno)\n\t\t\t\tJOIN standard ON {$tmp_table_md}.md_standard = standard.md_standard\n\t\t\tWHERE {$tmp_table_md}.sid=%s and {$tmp_table_md}.uuid=%s\n\t\t\tORDER BY {$tmp_table_md_values}.md_path\n\t\t", $this->sid, $uuid);
     $result = DB_DRIVER == 'oracle' ? _executeSql('select', array($sql), array('assoc', 'RECNO,#,=')) : _executeSql('select', array($sql), array('assoc', 'recno,#,='));
     //$result = _executeSql('select', array($pom['sql']), array('assoc', 'recno,#,='));
     $eval_text = '';
     foreach ($result as $recno => $data) {
         $recno_arr[] = $recno;
         // seznam recno
         foreach ($data as $idx => $row) {
             if ($row['MD_PATH'] == '') {
                 continue;
             }
             $mds = $row['MD_STANDARD'];
             if ($mds - 10 > -1) {
                 $mds = $mds - 10;
             }
             $path_arr = explode('_', substr($row['MD_PATH'], 0, strlen($row['MD_PATH']) - 1));
             $eval_text_tmp = '$vysl[' . $recno . ']';
             foreach ($path_arr as $key => $value) {
                 if ($key % 2 == 0) {
                     $eval_text_tmp .= "['" . $elements_label[$mds][$value] . "']";
                 } else {
                     $eval_text_tmp .= '[' . $value . ']';
                 }
             }
             $eval_text_tmp .= "['!" . $row['LANG'] . "']=" . '"' . gpc_addslashes($row['MD_VALUE']) . '";' . "\n";
             $eval_text .= $eval_text_tmp;
         }
     }
     eval($eval_text);
     $this->md = array();
     $this->setMdHeader($recno_arr);
     $this->printMDXML($vysl);
     setMickaLog($this->rs_xml, 'DEBUG', "MdExport.getXmlTmpMd.return");
     return $this->rs_xml;
 }
Beispiel #10
0
 function compare($resource)
 {
     $startPosition = 1;
     $result = array();
     $this->log("SEARCHING DELETED");
     $filter = trim($resource['filter']);
     do {
         $this->clientCSW->setParams("debug=0|ElementSetName=brief|typeNames=gmd:MD_Metadata|maxRecords=25|startPosition={$startPosition}");
         $fromDate = "1900-01-01";
         $query = "modified >= '" . $fromDate . "'";
         if ($filter) {
             $query .= " AND " . $filter;
         }
         $this->clientCSW->prepareRequest($query);
         do {
             $s = $this->clientCSW->runRequest($resource['source'], "harvest", "", "", "");
             $this->log();
             $this->log('QUERY TO DELETE: ' . $query, 1);
             $this->log('Source XML:', 2);
             $this->log($s, 2);
             libxml_clear_errors();
             $this->serverCSW->xml->loadXML($s);
             $err = libxml_get_errors();
             if (count($err)) {
                 $this->log('Record saving error:');
                 $this->log($err);
                 $this->log($s);
                 if ($tryCount > 2) {
                     return array('error' => array(3, 'Source', "Invalid source at " . htmlentities($resource['source'])));
                 }
                 $tryCount++;
                 $this->log("trying to resend request {$tryCount} ...");
                 sleep(1);
             }
         } while (count($err));
         //$s = $this->clientCSW->runRequest($resource['source'], "harvest", "", "", "");
         //$this->serverCSW->xml->loadXML($s);
         $ids = $this->serverCSW->xml->getElementsByTagNameNS('http://www.isotc211.org/2005/gmd', 'fileIdentifier');
         foreach ($ids as $id) {
             //echo "nod='". trim($id->nodeValue), "'\n";
             $result[] = trim($id->nodeValue);
         }
         $res = $this->serverCSW->xml->getElementsByTagNameNS($this->serverCSW->schemas['csw'], "SearchResults");
         //$startPosition = intval($res->item(0)->getAttribute("nextRecord"));
         //$numberOfRecordsMatched = intval($res->item(0)->getAttribute("numberOfRecordsMatched"));
         //if($startPosition > $numberOfRecordsMatched) $startPosition = 0;
         if ($res->length == 0) {
             $this->log('csw:SearchResults element not found.');
             return array('error' => array(3, 'csw:SearchResults', "Invalid CSW response " . htmlentities($resource['source'])));
         }
         $numResults = intval($res->item(0)->getAttribute("numberOfRecordsMatched"));
         $numReturned = intval($res->item(0)->getAttribute("numberOfRecordsReturned"));
         if (!$numResults) {
             return $result;
         }
         if ($numReturned > 0) {
             $startPosition += $numReturned;
         }
         if ($startPosition > $numResults) {
             $startPosition = 0;
         }
         if ($this->loglevel > 1) {
             $this->log();
             $this->log('Zdrojove XML pro smazani:');
             $this->log($s);
         }
         libxml_clear_errors();
         //if(!$startPosition) exit('Nenalezen atribut: nextRecord');
     } while ($startPosition > 1);
     $this->log("vet=" . count($result));
     // --- dotaz do databaze ---
     $sql = "SELECT uuid, title FROM md WHERE create_user='******' AND server_name=%s";
     $ids = array();
     try {
         $rs = setUpperColsName(dibi::query($sql, $resource['name']));
         $records = $rs->fetchAll();
         foreach ($records as $record) {
             $uuid = trim($record['UUID']);
             $ids[] = $uuid;
             $titles[$uuid] = trim($record['TITLE']);
         }
     } catch (DibiException $e) {
         return array('error' => array(6, "Database", "{$sql} is not valid SQL request"));
     }
     // --- porovnani ---
     $diff = array_diff($result, $ids);
     $diff2 = implode("\n", $diff);
     $this->log("Chybejici vety " . count($diff) . " :");
     $this->log($diff2);
     $diff = array_diff($ids, $result);
     if (count($diff) == 0) {
         return array();
     }
     $diff1 = "'" . implode("','", $diff) . "'";
     //echo "vet=".count($result);
     //echo "db=".count($ids);
     $this->log($result, 2);
     $this->log($diff, 2);
     //var_dump($diff);
     //exit;
     //--- vymazani ---
     try {
         $sql = "DELETE FROM md_values WHERE recno IN (SELECT recno FROM md WHERE create_user='******' AND uuid IN ({$diff1}))";
         _executeSql('delete', array($sql), array('all'));
         $sql = "DELETE FROM md WHERE create_user = '******' AND uuid IN ({$diff1})";
         _executeSql('delete', array($sql), array('all'));
         //$rs = setUpperColsName(dibi::query($sql));
         $result = array();
         foreach ($diff as $uuid) {
             $result[] = array("uuid" => $uuid, "title" => $titles[$uuid], "ok" => 2);
         }
         $this->log('DELETED');
         $this->log($result);
         return $result;
     } catch (DibiException $e) {
         return array('error' => array(6, "Database", "{$sql} is not valid SQL request"));
     }
 }
Beispiel #11
0
function getMdFc()
{
    $rs = array();
    $sql[] = "\n\t\tSELECT  md.recno, md_values.md_value, md_values.lang, md.data_type, md.create_user, md.view_group, md.edit_group\n\t\tFROM (md INNER JOIN md_values ON md.recno = md_values.recno) INNER JOIN standard ON md.md_standard = standard.md_standard";
    $sql[] = "WHERE md.md_standard=2 AND md_values.md_id=11";
    $sql[] = "ORDER BY md_values.recno";
    $result = _executeSql('select', $sql, array('assoc', 'recno,#,='));
    if (is_array($result) && count($result) > 0) {
        foreach ($result as $record) {
            if (getMdRight('view', MICKA_USER, $record[0]['DATA_TYPE'], $record[0]['CREATE_USER'], $record[0]['EDIT_GROUP'], $record[0]['VIEW_GROUP'])) {
                $title_micka = '';
                $title_eng = '';
                $title_random = '';
                foreach ($record as $row) {
                    $title_random = $row['MD_VALUE'];
                    if ($row['LANG'] == MICKA_LANG) {
                        $title_micka = $row['MD_VALUE'];
                    }
                    if ($row['LANG'] == 'eng') {
                        $title_micka = $row['MD_VALUE'];
                    }
                    $recno = $row['RECNO'];
                }
                $title = $title_micka != '' ? $title_micka : '';
                $title = $title == '' && $title_eng != '' ? $title_eng : '';
                $title = $title == '' && $title_random != '' ? $title_random : '';
                if ($title != '' && $recno > 0) {
                    $title = $title_micka;
                    $pom['recno'] = $recno;
                    $pom['title'] = $title;
                    array_push($rs, $pom);
                }
            }
        }
    }
    return $rs;
}
function setXmldata2Pxml($table, $recno)
{
    $sql = "UPDATE {$table} SET pxml = XMLPARSE(DOCUMENT xmldata) WHERE recno={$recno}";
    _executeSql('pxml', array($sql), array('all'));
}
Beispiel #13
0
 private function setSchemaMd()
 {
     $sql = array();
     $eval_text = '';
     array_push($sql, "\n\t\t\tSELECT\ttree.md_id, tree.md_path_el, tree.package_id, tree.md_left, tree.md_right, elements.multi_lang, elements.form_code\n  \t\tFROM tree INNER JOIN elements ON tree.el_id = elements.el_id\n      WHERE tree.md_standard=%i\n\t\t", $this->mds);
     $result = _executeSql('select', $sql, array('all'));
     if (count($result) < 1) {
         $this->tree_el = false;
     }
     foreach ($result as $row) {
         $el_path = $row['MD_PATH_EL'];
         $el_path = str_replace("/", "']['", $el_path);
         $el_path = substr($el_path, 2) . "']";
         $eval_text = '$this->tree_el' . $el_path . "['_p_']=" . $this->setElementsData($row) . ";";
         eval($eval_text);
     }
     //my_print_r($this->tree_el ['MD_Metadata']['contact']);
 }
Beispiel #14
0
function getPaginator($sql, $limit_find, $page_number = 1)
{
    $rs = array();
    $rs['records'] = 0;
    $rs['pages'] = 0;
    if ($limit_find < 10) {
        $limit_find = 20;
    }
    if ($sql != '') {
        $records = _executeSql('select', array($sql), array('single'));
        if ($records > 0) {
            $rs['records'] = $records;
            $rs['pages'] = Ceil($records / $limit_find);
        }
    }
    if ($rs['records'] > 0) {
        // vypocet pocatecni a koncove stranky (snazime se vypsat vzdy 10 odkazu)
        $rs['start_page'] = $page_number - 5;
        $rs['end_page'] = $page_number + 5;
        // oprava nekorektnich hodnot (zaporne nebo prilis velke)
        if ($rs['start_page'] < 1) {
            $rs['end_page'] += Abs($rs['start_page']) + 1;
        }
        if ($rs['end_page'] > $rs['pages']) {
            $rs['start_page'] = $rs['start_page'] - ($rs['end_page'] - $rs['pages']);
            $rs['end_page'] = $rs['pages'];
        }
        if ($rs['start_page'] < 1) {
            $rs['start_page'] = 1;
        }
        for ($x = $rs['start_page']; $x <= $rs['end_page']; $x++) {
            $rs['view_pages'][] = $x;
        }
        if ($page_number > $rs['end_page']) {
            $rs['page_number'] = $rs['end_page'];
            setSessionMickaSearchPage($rs['page_number']);
        } else {
            $rs['page_number'] = $page_number;
        }
    }
    return $rs;
}
Beispiel #15
0
 /**
  * Uložení kontaktu do tabulky [contacts]
  * @param array $_POST
  * @return array ('ok'=>FALSE|TRUE, 'report'='')
  */
 public function setContact($post)
 {
     $rs = array();
     $rs['ok'] = FALSE;
     $rs['report'] = '';
     if ($this->user_guest) {
         $rs['report'] = "User '" . $this->user . "' not rights";
         return $rs;
     }
     $cont_id = isset($post['cont_id']) ? htmlspecialchars($post['cont_id']) : '';
     if ($cont_id == -1) {
         $mode = 'insert';
     } elseif ($cont_id > 0) {
         $mode = 'update';
     } else {
         $rs['report'] = 'Bad input data! System error.';
         return $rs;
     }
     $data['cont_person'] = isset($post['pers']) && $post['pers'] != '' ? htmlspecialchars($post['pers']) : NULL;
     $data['cont_organisation'] = isset($post['organisation']) && $post['organisation'] != '' ? htmlspecialchars($post['organisation']) : NULL;
     $data['cont_organ_en'] = isset($post['organ_en']) && $post['organ_en'] != '' ? htmlspecialchars($post['organ_en']) : NULL;
     $data['cont_label'] = isset($post['label']) && $post['label'] != '' ? htmlspecialchars($post['label']) : NULL;
     $data['cont_function'] = isset($post['func']) && $post['func'] != '' ? htmlspecialchars($post['func']) : NULL;
     $data['cont_function_en'] = isset($post['func_en']) && $post['func_en'] != '' ? htmlspecialchars($post['func_en']) : NULL;
     $data['cont_phone'] = isset($post['phone']) && $post['phone'] != '' ? htmlspecialchars($post['phone']) : NULL;
     $data['cont_fax'] = isset($post['fax']) && $post['fax'] != '' ? htmlspecialchars($post['fax']) : NULL;
     $data['cont_point'] = isset($post['point']) && $post['point'] != '' ? htmlspecialchars($post['point']) : NULL;
     $data['cont_city'] = isset($post['city']) && $post['city'] != '' ? htmlspecialchars($post['city']) : NULL;
     $data['cont_adminarea'] = isset($post['adminarea']) && $post['adminarea'] != '' ? htmlspecialchars($post['adminarea']) : NULL;
     $data['cont_postcode'] = isset($post['postcode']) && $post['postcode'] != '' ? htmlspecialchars($post['postcode']) : NULL;
     $data['cont_country'] = isset($post['country']) && $post['country'] != '' ? htmlspecialchars($post['country']) : NULL;
     $data['cont_email'] = isset($post['email']) && $post['email'] != '' ? htmlspecialchars($post['email']) : NULL;
     $data['cont_url'] = isset($post['url']) && $post['url'] != '' ? htmlspecialchars($post['url']) : NULL;
     $data['cont_group_edit'] = isset($post['groups_e']) && $post['groups_e'] != '' ? htmlspecialchars($post['groups_e']) : NULL;
     $data['cont_group_view'] = isset($post['groups_v']) && $post['groups_v'] != '' ? htmlspecialchars($post['groups_v']) : NULL;
     $data['cont_user'] = $this->user;
     $sql = array();
     if ($mode == 'insert') {
         $data['cont_id'] = array('%i', $this->getNewContId());
         array_push($sql, 'INSERT INTO contacts', $data);
     }
     if ($mode == 'update') {
         // kontrola práv
         $record = $this->getContacts($cont_id);
         if (array_key_exists('right', $record[0]) && $record[0]['right'] == 'w') {
             array_push($sql, 'UPDATE contacts SET', $data);
             array_push($sql, 'WHERE cont_id=%i', $cont_id);
         } else {
             $rs['report'] = "Not right to contact {$cont_id}.";
             return $rs;
         }
     }
     if (count($sql) > 0) {
         $result = _executeSql('update', $sql, array('all'));
         $rs['ok'] = TRUE;
     }
     return $rs;
 }
Beispiel #16
0
function mainMdFc($akFc, $recno)
{
    $rs = array();
    if ($akFc == 'list') {
        $sql[] = "\n\t\t\tSELECT  md.recno, md_values.md_value, md_values.lang, md.data_type, md.create_user, md.view_group, md.edit_group\n\t\t\tFROM (md INNER JOIN md_values ON md.recno = md_values.recno) INNER JOIN standard ON md.md_standard = standard.md_standard";
        $sql[] = "WHERE md.md_standard=2 AND md_values.md_id=11";
        $sql[] = "ORDER BY md_values.recno";
        $result = _executeSql('select', $sql, array('assoc', 'recno,#,='));
        if (is_array($result) && count($result) > 0) {
            foreach ($result as $record) {
                if (getMdRight('view', MICKA_USER, $record[0]['DATA_TYPE'], $record[0]['CREATE_USER'], $record[0]['EDIT_GROUP'], $record[0]['VIEW_GROUP'])) {
                    $title_micka = '';
                    $title_eng = '';
                    $title_random = '';
                    foreach ($record as $row) {
                        $title_random = $row['MD_VALUE'];
                        if ($row['LANG'] == MICKA_LANG) {
                            $title_micka = $row['MD_VALUE'];
                        }
                        if ($row['LANG'] == 'eng') {
                            $title_micka = $row['MD_VALUE'];
                        }
                        $recno = $row['RECNO'];
                    }
                    $title = $title_micka != '' ? $title_micka : '';
                    $title = $title == '' && $title_eng != '' ? $title_eng : '';
                    $title = $title == '' && $title_random != '' ? $title_random : '';
                    if ($title != '' && $recno > 0) {
                        $title = $title_micka;
                        $pom['recno'] = $recno;
                        $pom['title'] = $title;
                        array_push($rs, $pom);
                    }
                }
            }
        }
    } elseif ($akFc == 'detail') {
        $md_record = new MdRecord();
        $md_record->setTableMode('md');
        $values = $md_record->getMdValues($recno);
        $rs['uuid'] = $values['md']['UUID'];
        $rs['langs'] = '';
        $rs['titles'] = '';
        $rs['hodnoty'] = array();
        $title_ap = '';
        $title = '';
        if (isset($values['md_values']) && count($values['md_values']) > 0) {
            foreach ($values['md_values'] as $row) {
                if ($row['MD_ID'] == 11) {
                    $rs['langs'] = $rs['langs'] == '' ? $row['LANG'] : '|' . $row['LANG'];
                    $rs['titles'] = $rs['titles'] == '' ? $row['MD_VALUE'] : '|' . $row['MD_VALUE'];
                    $title = $row['MD_VALUE'];
                    if ($row['LANG'] == MICKA_LANG) {
                        $title_ap = $row['MD_VALUE'];
                    }
                }
                if ($row['MD_ID'] == 13) {
                    $pom['kod'] = $row['MD_VALUE'];
                    $pom['nazev'] = $row['MD_VALUE'];
                    array_push($rs['hodnoty'], $pom);
                }
            }
        }
        $rs['title'] = $title_ap != '' ? $title_ap : $title;
    }
    return $rs;
}
Beispiel #17
0
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;
}
Beispiel #18
0
 public function copyTmpRecordToMd()
 {
     setMickaLog("Copy record to TMP", 'DEBUG', 'MdRecord.copyTmpRecordToMd');
     $rs = array();
     if (isset($this->md_record['md']) === FALSE || count($this->md_record['md']['RECNO']) < 1) {
         setMickaLog("Record not found", 'ERROR', 'MdRecord.copyTmpRecordToMp');
         $rs['report'] = 'Record not found';
         return $rs;
     }
     if ($this->md_record['user_right'] != 'w' || $this->user == 'guest') {
         setMickaLog("Not rights", 'ERROR', 'MdRecord.copyTmpRecordToMp');
         $rs['report'] = 'Not rights';
         return $rs;
     }
     // data z tmp
     $recno_tmp = $this->md_record['md']['RECNO'];
     $this->setTableMode('tmp');
     $md = $this->getMd($where_col = 'recno', $where_value = $recno_tmp);
     $data_tmp = array();
     $data_tmp = $this->md_record['md'];
     // data z md
     $this->setTableMode('md');
     $tmp_table_md_values = TMPTABLE_PREFIX . '_md_values';
     $md = $this->getMd($where_col = 'uuid', $where_value = $data_tmp['UUID']);
     if ($md['report'] == 'Record not found') {
         // Nový záznam
         setMickaLog("New record to MD", 'DEBUG', 'MdRecord.copyTmpRecordToMp');
         $data['uuid'] = $data_tmp['UUID'];
         $data['md_standard'] = $data_tmp['MD_STANDARD'];
         $data['lang'] = 'eng';
         // FIXME: optimalizace
         $data_md = array();
         $recno = $this->setNewMd($data);
         $data_md['lang'] = $data_tmp['LANG'];
         $data_md['data_type'] = $data_tmp['DATA_TYPE'];
         $data_md['last_update_user'] = $this->user;
         $data_md['last_update_date'] = DB_DRIVER == 'mssql2005' ? str_replace('-', '', getNewDate()) : getNewDate();
         $data_md['edit_group'] = $data_tmp['EDIT_GROUP'] != '' ? $data_tmp['EDIT_GROUP'] : $this->user;
         $data_md['view_group'] = $data_tmp['VIEW_GROUP'] != '' ? $data_tmp['VIEW_GROUP'] : $this->user;
         $data_md['x1'] = $data_tmp['X1'] != '' ? $data_tmp['X1'] : NULL;
         $data_md['y1'] = $data_tmp['Y1'] != '' ? $data_tmp['Y1'] : NULL;
         $data_md['x2'] = $data_tmp['X2'] != '' ? $data_tmp['X2'] : NULL;
         $data_md['y2'] = $data_tmp['Y2'] != '' ? $data_tmp['Y2'] : NULL;
         $data_md['the_geom'] = $data_tmp['THE_GEOM'] != '' ? $data_tmp['THE_GEOM'] : NULL;
         $data_md['range_begin'] = $data_tmp['RANGE_BEGIN'] != '' ? $data_tmp['RANGE_BEGIN']->format('Y-m-d') : NULL;
         $data_md['range_end'] = $data_tmp['RANGE_END'] != '' ? $data_tmp['RANGE_END']->format('Y-m-d') : NULL;
         $data_md['md_update'] = $data_tmp['MD_UPDATE'] != '' ? $data_tmp['MD_UPDATE'] : NULL;
         $data_md['title'] = $data_tmp['TITLE'] != '' ? $data_tmp['TITLE'] : NULL;
         $data_md['valid'] = $data_tmp['VALID'];
         $data_md['prim'] = $data_tmp['PRIM'];
         if (DB_DRIVER == 'oracle') {
             $xml = $data_tmp['PXML'] != '' ? $data_tmp['PXML'] : NULL;
             if ($xml != '') {
                 $conn = dibi::getConnection()->driver->getResource();
                 setXmlToClob($conn, $this->table_md, 'xmldata', "recno={$recno}", $xml);
             }
         } elseif (DB_DRIVER == 'postgre') {
             //$data_md['pxml%sql'] = ($data_tmp['PXML'] != '') ? "XMLPARSE(DOCUMENT '" . $data_tmp['PXML'] . "')" : NULL;
             $data_md['xmldata'] = $data_tmp['PXML'] != '' ? $data_tmp['PXML'] : NULL;
         } elseif (DB_DRIVER == 'mssql2005') {
             $data_md['xmldata'] = $data_tmp['PXML'] != '' ? $data_tmp['PXML'] : NULL;
         } else {
             $data_md['pxml'] = $data_tmp['PXML'] != '' ? $data_tmp['PXML'] : NULL;
         }
         $this->setMd($recno, $data_md);
         setXmldata2Pxml($this->table_md, $recno);
         $sql = array();
         array_push($sql, "\n\t\t\t\tINSERT INTO md_values (recno, md_id, md_value, md_path, lang , package_id)\n\t\t\t\tSELECT %i, md_id, md_value, md_path, lang , package_id FROM {$tmp_table_md_values} WHERE recno=%i\n\t\t\t", $recno, $recno_tmp);
         $result = _executeSql('insert', $sql, array('all'));
     } elseif ($md['report'] == 'ok' && $md['right'] == 'w') {
         // Update záznamu
         $data_md = array();
         $recno = $md['md']['RECNO'];
         $data_md['lang'] = $data_tmp['LANG'];
         $data_md['data_type'] = $data_tmp['DATA_TYPE'];
         $data_md['last_update_user'] = $this->user;
         $data_md['last_update_date'] = DB_DRIVER == 'mssql2005' ? str_replace('-', '', getNewDate()) : getNewDate();
         $data_md['edit_group'] = $data_tmp['EDIT_GROUP'] != '' ? $data_tmp['EDIT_GROUP'] : $this->user;
         $data_md['view_group'] = $data_tmp['VIEW_GROUP'] != '' ? $data_tmp['VIEW_GROUP'] : $this->user;
         $data_md['x1'] = $data_tmp['X1'] != '' ? $data_tmp['X1'] : NULL;
         $data_md['y1'] = $data_tmp['Y1'] != '' ? $data_tmp['Y1'] : NULL;
         $data_md['x2'] = $data_tmp['X2'] != '' ? $data_tmp['X2'] : NULL;
         $data_md['y2'] = $data_tmp['Y2'] != '' ? $data_tmp['Y2'] : NULL;
         $data_md['the_geom'] = $data_tmp['THE_GEOM'] != '' ? $data_tmp['THE_GEOM'] : NULL;
         $data_md['range_begin'] = $data_tmp['RANGE_BEGIN'] != '' ? $data_tmp['RANGE_BEGIN']->format('Y-m-d') : NULL;
         $data_md['range_end'] = $data_tmp['RANGE_END'] != '' ? $data_tmp['RANGE_END']->format('Y-m-d') : NULL;
         $data_md['md_update'] = $data_tmp['MD_UPDATE'] != '' ? $data_tmp['MD_UPDATE'] : NULL;
         $data_md['title'] = $data_tmp['TITLE'] != '' ? $data_tmp['TITLE'] : NULL;
         $data_md['valid'] = $data_tmp['VALID'];
         $data_md['prim'] = $data_tmp['PRIM'];
         if (DB_DRIVER == 'oracle') {
             //$data_md['pxml%sql'] = ($data_tmp['PXML'] != '') ? "XMLType('" . $data_tmp['PXML'] . "')" : NULL;
             $xml = $data_tmp['PXML'] != '' ? $data_tmp['PXML'] : NULL;
             if ($xml != '') {
                 $conn = dibi::getConnection()->driver->getResource();
                 setXmlToClob($conn, $this->table_md, 'xmldata', "recno={$recno}", $xml);
             }
         } elseif (DB_DRIVER == 'postgre') {
             //$data_md['pxml%sql'] = ($data_tmp['PXML'] != '') ? "XMLPARSE(DOCUMENT '" . $data_tmp['PXML'] . "')" : NULL;
             $data_md['xmldata'] = $data_tmp['PXML'] != '' ? $data_tmp['PXML'] : NULL;
         } elseif (DB_DRIVER == 'mssql2005') {
             $data_md['xmldata'] = $data_tmp['PXML'] != '' ? $data_tmp['PXML'] : NULL;
         } else {
             //$data_md['pxml'] = ($data_tmp['PXML'] != '') ? $data_tmp['PXML'] : NULL;
         }
         $this->setMd($recno, $data_md);
         setXmldata2Pxml($this->table_md, $recno);
         $this->deleteMdValues($recno, 100, -1, -1, array());
         $sql = array();
         array_push($sql, "\n\t\t\t\tINSERT INTO md_values (recno, md_id, md_value, md_path, lang , package_id)\n\t\t\t\tSELECT %i, md_id, md_value, md_path, lang , package_id FROM {$tmp_table_md_values} WHERE recno=%i\n\t\t\t", $recno, $recno_tmp);
         $result = _executeSql('insert', $sql, array('all'));
     } else {
         $rs['report'] = $md['report'];
         return $rs;
     }
     unset($md);
     $rs['report'] = 'ok';
     return $rs;
 }
Beispiel #19
0
function replaceMdValue($mode, $replaceEl, $pathEl, $valueFind, $replaceAll, $valueReplace)
{
    $rs = array();
    $rs['replaceRecords'] = 0;
    $rs['affectedRecords'] = 0;
    $rs['records'] = array();
    switch ($replaceEl) {
        case 'email':
            $md_id = array();
            $sql = array();
            $sql[] = 'SELECT md_id FROM tree WHERE ' . setSqlLike('md_path_el', "'%electronicMailAddress'");
            $row_md_id = _executeSql('select', $sql, array('all'));
            if (is_array($row_md_id) && count($row_md_id) > 0) {
                foreach ($row_md_id as $row) {
                    $md_id[] = $row['MD_ID'];
                }
            } else {
                return $rs;
            }
            break;
        case 'name_md':
            $md_id = array(152);
            break;
        case 'name_data':
            $md_id = array(186, 5028);
            break;
        case 'title':
            $md_id = array(11, 5063);
            break;
        case 'any':
            $md_id = array();
            break;
        case 'optional':
            $sql = array();
            array_push($sql, 'SELECT md_id FROM tree WHERE md_path_el LIKE %s', $pathEl . '%');
            $row_md_id = _executeSql('select', $sql, array('all'));
            if (is_array($row_md_id) && count($row_md_id) > 0) {
                foreach ($row_md_id as $row) {
                    $md_id[] = $row['MD_ID'];
                }
            } else {
                return $rs;
            }
            break;
        default:
            return $rs;
    }
    $sql_equality = '=';
    if (strpos($valueFind, '*') !== FALSE) {
        //$sql_equality = DB_DRIVER == 'postgre' ?  ' ILIKE ' : ' LIKE ';
        $sql_equality = ' LIKE ';
        $valueFind = str_replace('*', '%', $valueFind);
    }
    $sql = array();
    array_push($sql, 'SELECT DISTINCT md.recno, md.uuid, md.title, md.md_standard');
    array_push($sql, 'FROM md INNER JOIN md_values ON md.recno=md_values.recno');
    array_push($sql, 'WHERE md_values.md_value' . $sql_equality . '%s', $valueFind);
    if (count($md_id) > 0) {
        array_push($sql, 'AND md_values.md_id IN %in', $md_id);
    }
    array_push($sql, 'ORDER BY md.recno');
    $replaceRecords = _executeSql('select', $sql, array('all'));
    if ($mode == 'replace' && $valueReplace != '') {
        $sql = array();
        if ($replaceAll === TRUE) {
            array_push($sql, 'UPDATE md_values SET md_value=%s', $valueReplace);
        } else {
            array_push($sql, 'UPDATE md_values SET md_value=REPLACE(md_value,%s,%s)', getValueFind($valueFind), $valueReplace);
        }
        array_push($sql, 'WHERE md_values.md_value' . $sql_equality . '%s', $valueFind);
        if (count($md_id) > 0) {
            array_push($sql, 'AND md_id IN %in', $md_id);
        }
        $rs['affectedRecords'] = _executeSql('update', $sql, array('all'));
        // aktualizace XML
        $md_record = new MdRecord();
        foreach ($replaceRecords as $row) {
            //$result = $md_record->updateOnlyXmlData($row['UUID'], $row['RECNO']);
            $md_record->setStopDatestamp(FALSE);
            $result = $md_record->updateTableMd('uuid', $row['UUID']);
        }
    }
    if ($replaceRecords == '') {
        $replaceRecords = array();
    }
    $rs['replaceRecords'] = 0;
    $rs['records'] = $replaceRecords;
    //my_print_r($rs);
    return $rs;
}