diff --git a/php/app/config/config.local.neon.dist b/php/app/config/config.local.neon.dist index d8bab8c..9074fd2 100644 --- a/php/app/config/config.local.neon.dist +++ b/php/app/config/config.local.neon.dist @@ -5,11 +5,11 @@ parameters: app: # URL - mickaUrl = https://www.server.domain/micka + #mickaUrl = https://www.server.domain/micka # UI theme layoutTheme = default # UI langauges (must have translation files) - langs = 'cze,eng' + langs = 'eng,cze,spa' # dafult profile used startProfil = 5 #records per page @@ -24,11 +24,8 @@ parameters: directSummary = TRUE directDetail = TRUE directXml = TRUE - formSign = FALSE defaultEditGroup = editor defaultViewGroup = reader - # record indication for access from csw etc. - mdDataType = "-1=>'semifinished',0=>'private',1=>'public',2=>'portal'" # admin IP list adminIP = '127.0.0.1' # web proxy address diff --git a/php/app/config/config.neon.dist b/php/app/config/config.neon.dist index 02e12a1..ea97649 100644 --- a/php/app/config/config.neon.dist +++ b/php/app/config/config.neon.dist @@ -3,6 +3,9 @@ # https://nette.org/security-warning # parameters: + mdDataType: + 0: private + 1: public langCodes: cs: cze da: dan diff --git a/php/app/model/CswClient.php b/php/app/model/CswClient.php index 460d086..d9345ef 100644 --- a/php/app/model/CswClient.php +++ b/php/app/model/CswClient.php @@ -1,499 +1,499 @@ -xmlHead = "<"."?xml version=\"1.0\" encoding=\"UTF-8\"?".">"; - $this->xp = new XsltProcessor(); - $this->xp->registerPhpFunctions(); - $this->xml = new DomDocument; - $this->xsl = new DomDocument; - //$this->xsl->substituteEntities = true; - } - - function setParams($params){ - if(!$params) return; - $paramList = explode("|", $params); - foreach($paramList as $param){ - $pom = explode("=",$param); - eval("\$this->".$pom[0]."='".$pom[1]."';"); - } - } - - function getDataByGet($url, $name, $id, $template){ - $url = $url."?service=CSW&version=2.0.2&request=GetRecordById&ID=".$id."&TypeNames=gmd:MD_Metadata&OutputSchema=http://www.isotc211.org/2005/gmd&elementSetName=full"; - $s= $this->getDataByURL($url); - $par = Array("theName"=>$name, "lang"=>$this->lang); - if($params) $par = array_merge($par, $params); - if($template) return $this->processTemplate($s, $template, $par); - else return($s); - } - - function getDataByURL($url){ - $ch = curl_init ($url); - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); - curl_setopt($ch, CURLOPT_TIMEOUT, 20); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // potlačena kontrola certifikátu - if(defined('CONNECTION_PROXY')){ - $proxy = CONNECTION_PROXY; - if(defined('CONNECTION_PORT')) $proxy .= ':'. CONNECTION_PORT; - curl_setopt($ch, CURLOPT_PROXY, $proxy); - } - curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); - $data = curl_exec ($ch); - if($this->debug>1){ - var_dump(curl_getinfo($ch)); - } - curl_close ($ch); - return $data; - } - - function pos($s, $left, $right, $start=0){ - $count = 0; - $pos = 0; - $out = true; - for($i=$start;$imethod=="Soap") { - $headers = array( - "POST ".$path." HTTP/1.1", - "Content-type: application/soap+xml; charset=\"utf-8\"", - "Cache-Control: no-cache", - "Pragma: no-cache", - "SOAPAction: \"run\"", - "Content-length: ".strlen($content) - ); - } - else{ - $headers = array( - "POST ".$path." HTTP/1.1", - "Content-type: text/xml; charset=\"utf-8\"", - "Cache-Control: no-cache", - "Pragma: no-cache", - "Content-length: ".strlen($content) - ); - - } - if($usr) $headers[] = "Authorization: Basic ".base64_encode($usr.":".$pwd); - //var_dump($headers); - //do curl connection and request - //$out = $this->getCURL($url,$content,$headers); - $ch = curl_init ($url); - curl_setopt($ch, CURLOPT_HTTPHEADER,$headers); - //curl_setopt($ch, CURLOPT_COOKIE, session_name().'='.session_id() ); - //or with own headers - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); - curl_setopt($ch, CURLOPT_POST, true); - curl_setopt($ch, CURLOPT_POSTFIELDS, $content); - curl_setopt($ch, CURLOPT_TIMEOUT, 20); - //curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')); // kvuli VUMOP - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // potlačena kontrola certifikátu - if(defined('CONNECTION_PROXY')){ - $proxy = CONNECTION_PROXY; - if(defined('CONNECTION_PORT')) $proxy .= ':'. CONNECTION_PORT; - curl_setopt($ch, CURLOPT_PROXY, $proxy); - } - if(defined('CONNECTION_PASSWORD') && CONNECTION_PASSWORD != ""){ - curl_setopt ($ch, CURLOPT_PROXYUSERPWD, CONNECTION_USER.':'.CONNECTION_PASSWORD); - } - curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); - //$useragent='HSRS CSW Client'; - //curl_setopt ($ch,CURLOPT_USERAGENT,$useragent); - $file = curl_exec ($ch); - if($this->debug>1){ - var_dump(curl_getinfo($ch)); - } - curl_close ($ch); - return $file; - } - - function formatXML1($s){ - $s = str_replace("<", "\n<", $s); - $s = str_replace("\n\n)(<)(\/*)/', "$1\n$2$3", $xml); - - // now indent the tags - $token = strtok($xml, "\n"); - $result = ''; // holds formatted version as it is built - $pad = 0; // initial indent - $matches = array(); // returns from preg_matches() - - // scan each line and adjust indent based on opening/closing tags - while ($token !== false) : - - // test for the various tag states - - // 1. open and closing tags on same line - no change - if (preg_match('/.+<\/\w[^>]*>$/', $token, $matches)) : - $indent=0; - // 2. closing tag - outdent now - elseif (preg_match('/^<\/\w/', $token, $matches)) : - $pad--; - // 3. opening tag - don't pad this one, only subsequent tags - elseif (preg_match('/^<\w[^>]*[^\/]>.*$/', $token, $matches)) : - $indent=1; - // 4. no indentation needed - else : - $indent = 0; - endif; - - // pad the line with the required number of leading spaces - $line = str_pad($token, strlen($token)+$pad, ' ', STR_PAD_LEFT); - $result .= $line . "\n"; // add to the cumulative result, with linefeed - $token = strtok("\n"); // get the next token - $pad += $indent; // update the pad size for subsequent lines - endwhile; - - return highlight_string(htmlentities($result), true); - } - - private function cql2filter_($s, $prefix=""){ - $i = 0; - $tokens = array(); - $tnum = 0; - $in = false; - - while($ipos($s, "(", ")", $i+1); - $tokens[$tnum]="(".$this->cql2filter_(substr($s,$i+1,$pos-$i-1),$prefix); - $i=$pos; - break; - case "'": - $pos = strpos($s, "'", $i+1); - $tokens[$tnum] = substr($s,$i+1,$pos-$i-1); - $i=$pos; - //$tnum++; - //var_dump($tokens); - - break; - case ">": - case "<": - case "!": - case "=": - $ch1 = substr($s,$i-1,1); - if(!strpos(". !<>=",$ch1)) $tnum++; - // POZOR, break tam neni schvalne !!! - default: - if (!isset($tokens[$tnum])) $tokens[$tnum]=""; - $tokens[$tnum] .= $ch; - if(strpos(". !<>=",$ch)){ - $ch1 = substr($s,$i+1,1); - if(!strpos(". =",$ch1)) $tnum++; - } - break; - } - $i++; - } - - $tpos = 0; - $resh = ""; - $result = ''; - while($tpos < (count($tokens))){ - switch(strtoupper($tokens[$tpos])){ - case 'AND': $resh = "ogc:And"; $tpos++; break; - case 'OR': $resh = "ogc:Or"; $tpos++; break; - case 'BBOX': - $pom = explode(" ", str_replace(',', ' ', $tokens[$tpos+2])); - $result .= "".$prefix."BoundingBox - $pom[0] $pom[1]" - ."$pom[2] $pom[3]" - .""; - $tpos +=3; - break; - case 'IBBOX': - $pom = explode(" ", str_replace(',', ' ', $tokens[$tpos+2])); - $result .= "".$prefix."BoundingBox - $pom[0] $pom[1]" - ."$pom[2] $pom[3]" - .""; - $tpos +=3; - break; - case 'OBBOX': - $pom = explode(" ", str_replace(',', ' ', $tokens[$tpos+2])); - $result .= "$pom[0] $pom[1]" - ."$pom[2] $pom[3]" - ."" - ."".$prefix."BoundingBox"; - $tpos +=3; - break; - default: - if(substr($tokens[$tpos],0,1)=="("){ - $result .= substr($tokens[$tpos],1); $tpos++; - } - else{ - $par = ""; - switch($tokens[$tpos+1]){ - case '=': $operator = "ogc:PropertyIsEqualTo"; break; - case '!=': - case '<>': $operator = "ogc:PropertyIsNotEqualTo"; break; - case 'like': $operator = "ogc:PropertyIsLike"; $par=" wildCard=\"*\" singleChar=\"@\" escapeChar=\"\\\""; break; - case '>': $operator = "ogc:PropertyIsGreaterThan"; break; - case '>=': $operator = "ogc:PropertyIsGreaterThanOrEqualTo"; break; - case '<': $operator = "ogc:PropertyIsLessThan"; break; - case '<=': $operator = "ogc:PropertyIsLessThanOrEqualTo"; break; - case 'gt': $operator = "ogc:GreaterThan"; break; - default: $operator = "err-".$tokens[$tpos+1]; break; // kvuli chybam - } - if($this->sw == "gn") $name = $tokens[$tpos]; // hack kvuli geonetwork - else $name = $prefix.$tokens[$tpos]; - if($prefix=='dc:'){ - if($tokens[$tpos]=='AnyText') $name = "csw:".$tokens[$tpos]; - else if($tokens[$tpos]=='modified') $name = "dct:".$tokens[$tpos]; - } - $result .= "<$operator$par>".$name."".$tokens[$tpos+2].""; - $tpos += 3; - } - break; - } - } - if($resh) $result = "<$resh> - $result"; - return $result; -} - - function readServerList($listFile){ - $xml = new DomDocument; - $xml->load($listFile); - $servers = $xml->getElementsByTagName("server"); - foreach($servers as $server){ - $attribs = $server->attributes; - $name = $server->getAttribute("name"); - foreach($attribs as $attrib){ - $cswlist[$name][$attrib->name] = $attrib->value; - } - } - return $cswlist; - } - - function cql2filter($s, $prefix){ - return $this->xmlHead - . '' - . $this->cql2filter_($s, $prefix) - . ''; - } - - - /*********************************************** - * vytvori XML pro dotaz pomoci getRecordById - * - * @ids - seznam identifikatoru oddelenych carkou - * @schema - output schema - * @version - verze sluzby (nepovinne) - ***********************************************/ - function prepareRequestById($ids, $schema, $version=""){ - $id_array = explode(",",$ids); - $s = ""; - foreach($id_array as $id) $s .= "".trim($id).""; - $this->xml->loadXML($this->xmlHead."$s"); - if($this->sw=="gn"){ - $pom = file_get_contents(CSW_XSL."/client2GetRecordByIdRequest$version".$this->method.".xsl"); - $pom = str_replace("outputSchema=","OutputSchema=",$pom); // to je to ono - $this->xsl->loadXML($pom); - } - else{ - $this->xsl->load(CSW_XSL."/client2GetRecordByIdRequest$version".$this->method.".xsl"); - } - $this->xp->importStyleSheet($this->xsl); - $this->xp->setParameter("", "ElementSetName", $this->ElementSetName); - if($this->debug) $this->xp->setParameter("", "debug", $this->debug); - $this->xp->setParameter("", "outputSchema", $schema); - $this->xp->setParameter("", "id", $id_array[0]); //TODO pro vice Id - //if(substr($this->ElementSetName,0,2)=="dc") $outputSchema = OS_DC; else $outputSchema = OS_GMD; - //$this->xp->setParameter("", "outputSchema", $outputSchema); - $this->reqData = $this->xp->transformToXML($this->xml); // vrazi retezec s XML dotazem - } - - /*********************************************** - * vytvori XML pro dotaz pomoci getRecords - * - * cql - dotaz - * version - verze - podle toho se zvoli patricne xsl - ***********************************************/ - function prepareRequest($cql, $version=""){ - if(substr($this->typeNames,0,3)=="csw"){ - $prefix = "dc:"; - $outputSchema = OS_DC; - //$prefix = "csw:"; $outputSchema = OS_DC; // quli Intergrafu - } - else { - $prefix = "apiso:"; - $outputSchema = OS_GMD; - } - if($cql) $this->xml->loadXML($this->cql2filter($cql, $prefix)); - // hack - Geonetwork - if($this->sw=="gn"){ - $pom = file_get_contents(CSW_XSL."/client2GetRecordsRequest$version".$this->method.".xsl"); - $pom = str_replace("outputSchema=","OutputSchema=",$pom); - $this->xsl->loadXML($pom); - } - else { - $this->xsl->load(CSW_XSL."/client2GetRecordsRequest$version".$this->method.".xsl"); // verze 2 s kopirovanim stromu - } - $this->xp->importStyleSheet($this->xsl); - //if($this->debug) $this->xp->setParameter("", "debug", $this->debug); - $this->xp->setParameter("", "debug", $this->debug ? $this->debug : ''); - $this->xp->setParameter("", "ElementSetName", $this->ElementSetName); - $this->xp->setParameter("", "resultType", $this->resultType); - $this->xp->setParameter("", "typeNames", $this->typeNames); - $this->xp->setParameter("", "outputSchema", $outputSchema); - $this->xp->setParameter("", "startPosition", $this->startPosition); - $this->xp->setParameter("", "maxRecords", $this->maxRecords); - $this->xp->setParameter("", "hopCount", $this->hopCount); - $this->xp->setParameter("", "sortBy", $this->sortBy); - $this->xp->setParameter("", "id", "req-123"); - $this->reqData = $this->xp->transformToXML($this->xml); // vrazi retezec s XML dotazem - } - - /*********************************************** - * vytvori XML pro dotaz pomoci Update - * - * data - XML s daty - * - ***********************************************/ - function prepareUpdate($data){ - $this->xml->loadXML($data); - $this->xsl->load(CSW_XSL."/client2update.xsl"); // verze 2 s kopirovanim stromu - $this->xp->importStyleSheet($this->xsl); - $this->xp->setParameter("", "debug", $this->debug); - $this->xp->setParameter("", "ElementSetName", $this->ElementSetName); - $this->xp->setParameter("", "outputSchema", $this->outputSchema); - $this->xp->setParameter("", "hopCount", $this->hopCount); - $this->reqData = $this->xp->transformToXML($this->xml); // vrazi retezec s XML dotazem - } - - function saveRequest($name){ - if(!$this->reqData) return false; - return file_put_contents(CSW_TMP."/".$name, $this->reqData); - } - - function loadRequest($name){ - $s = file_get_contents(CSW_TMP."/".$name); - if(!$s) return false; - $this->reqData = $s; - //obnova parametru - $this->xml->loadXML($s); - $this->xsl->load(CSW_XSL."/filter2micka.xsl"); - $this->xp->importStyleSheet($this->xsl); - $s = explode("|",$this->xp->transformToXML($this->xml)); - eval($s[1]); - $this->debug = $params["DEBUG"]; - return true; - } - - function setXMLParam($name, $value){ - $root = $this->xml->getElementsByTagName('GetRecords')->item(0); - $root->setAttribute($name, $value); - $this->reqData = $this->xml->saveXML(); - } - - function getRequest(){ - return $this->reqData; - } - - /****************************************** - * Odesle a zpracuje dotaz - synchronne - * - * url - adresa csw serveru - * sablona - XSL sablona pro zpracovani vysledku - * - *****************************************/ - function runRequest($url, $name, $template='', $user='', $password='', $params=Array()){ - - if(!$this->reqData) exit('No query data available, run prepareRequest first!'); - $s = $this->getDataByPost($url, $this->reqData, $user, $password); - // --- ladici hlaska --- - if($this->debug){ - return "request: ".$this->formatXML($this->reqData)."
response:
". $this->formatXML($s)."
"; - } - if(!$s) return -1; - //if(!$s) $s = $this->xmlHead.""; - // --- transformace do HTML apod - $par = Array("theName"=>$name, "lang"=>$this->lang); - if($params) $par = array_merge($par, $params); - if($template) return $this->processTemplate($s, $template, $par); - else return($s); - } - - function processTemplate($xmlString, $template, $params=Array()){ - if($xmlString) @$this->xml->loadXML($xmlString); - if(!$this->xml) { - return ""; - } - $this->xsl->load($template); - $this->xp->importStyleSheet($this->xsl); - if(count($params) > 0){ - $this->xp->setParameter("", $params); - } - return $this->xp->transformToXML($this->xml); - } - - function processTemplateFile($xmlName, $template, $params=Array()){ - if($xmlName) $this->xml->load($xmlName); - $this->xsl->load($template); - $this->xp->importStyleSheet($this->xsl); - if(count($params) > 0){ - reset($params); - while(list($name, $value) = each($params)){ - $this->xp->setParameter("", $name, $value); - } - } - return $this->xp->transformToXML($this->xml); - } - -} // konec tridy - +xmlHead = "<"."?xml version=\"1.0\" encoding=\"UTF-8\"?".">"; + $this->xp = new XsltProcessor(); + $this->xp->registerPhpFunctions(); + $this->xml = new DomDocument; + $this->xsl = new DomDocument; + //$this->xsl->substituteEntities = true; + } + + function setParams($params){ + if(!$params) return; + $paramList = explode("|", $params); + foreach($paramList as $param){ + $pom = explode("=",$param); + eval("\$this->".$pom[0]."='".$pom[1]."';"); + } + } + + function getDataByGet($url, $name, $id, $template){ + $url = $url."?service=CSW&version=2.0.2&request=GetRecordById&ID=".$id."&TypeNames=gmd:MD_Metadata&OutputSchema=http://www.isotc211.org/2005/gmd&elementSetName=full"; + $s= $this->getDataByURL($url); + $par = Array("theName"=>$name, "lang"=>$this->lang); + if($params) $par = array_merge($par, $params); + if($template) return $this->processTemplate($s, $template, $par); + else return($s); + } + + function getDataByURL($url){ + $ch = curl_init ($url); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($ch, CURLOPT_TIMEOUT, 20); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // potlačena kontrola certifikátu + if(defined('CONNECTION_PROXY')){ + $proxy = CONNECTION_PROXY; + if(defined('CONNECTION_PORT')) $proxy .= ':'. CONNECTION_PORT; + curl_setopt($ch, CURLOPT_PROXY, $proxy); + } + curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); + $data = curl_exec ($ch); + if($this->debug>1){ + var_dump(curl_getinfo($ch)); + } + curl_close ($ch); + return $data; + } + + function pos($s, $left, $right, $start=0){ + $count = 0; + $pos = 0; + $out = true; + for($i=$start;$imethod=="Soap") { + $headers = array( + "POST ".$path." HTTP/1.1", + "Content-type: application/soap+xml; charset=\"utf-8\"", + "Cache-Control: no-cache", + "Pragma: no-cache", + "SOAPAction: \"run\"", + "Content-length: ".strlen($content) + ); + } + else{ + $headers = array( + "POST ".$path." HTTP/1.1", + "Content-type: text/xml; charset=\"utf-8\"", + "Cache-Control: no-cache", + "Pragma: no-cache", + "Content-length: ".strlen($content) + ); + + } + if($usr) $headers[] = "Authorization: Basic ".base64_encode($usr.":".$pwd); + //var_dump($headers); + //do curl connection and request + //$out = $this->getCURL($url,$content,$headers); + $ch = curl_init ($url); + curl_setopt($ch, CURLOPT_HTTPHEADER,$headers); + //curl_setopt($ch, CURLOPT_COOKIE, session_name().'='.session_id() ); + //or with own headers + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, $content); + curl_setopt($ch, CURLOPT_TIMEOUT, 20); + //curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')); // kvuli VUMOP + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // potlačena kontrola certifikátu + if(defined('CONNECTION_PROXY')){ + $proxy = CONNECTION_PROXY; + if(defined('CONNECTION_PORT')) $proxy .= ':'. CONNECTION_PORT; + curl_setopt($ch, CURLOPT_PROXY, $proxy); + } + if(defined('CONNECTION_PASSWORD') && CONNECTION_PASSWORD != ""){ + curl_setopt ($ch, CURLOPT_PROXYUSERPWD, CONNECTION_USER.':'.CONNECTION_PASSWORD); + } + curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); + //$useragent='HSRS CSW Client'; + //curl_setopt ($ch,CURLOPT_USERAGENT,$useragent); + $file = curl_exec ($ch); + if($this->debug>1){ + var_dump(curl_getinfo($ch)); + } + curl_close ($ch); + return $file; + } + + function formatXML1($s){ + $s = str_replace("<", "\n<", $s); + $s = str_replace("\n\n)(<)(\/*)/', "$1\n$2$3", $xml); + + // now indent the tags + $token = strtok($xml, "\n"); + $result = ''; // holds formatted version as it is built + $pad = 0; // initial indent + $matches = array(); // returns from preg_matches() + + // scan each line and adjust indent based on opening/closing tags + while ($token !== false) : + + // test for the various tag states + + // 1. open and closing tags on same line - no change + if (preg_match('/.+<\/\w[^>]*>$/', $token, $matches)) : + $indent=0; + // 2. closing tag - outdent now + elseif (preg_match('/^<\/\w/', $token, $matches)) : + $pad--; + // 3. opening tag - don't pad this one, only subsequent tags + elseif (preg_match('/^<\w[^>]*[^\/]>.*$/', $token, $matches)) : + $indent=1; + // 4. no indentation needed + else : + $indent = 0; + endif; + + // pad the line with the required number of leading spaces + $line = str_pad($token, strlen($token)+$pad, ' ', STR_PAD_LEFT); + $result .= $line . "\n"; // add to the cumulative result, with linefeed + $token = strtok("\n"); // get the next token + $pad += $indent; // update the pad size for subsequent lines + endwhile; + + return highlight_string(htmlentities($result), true); + } + + private function cql2filter_($s, $prefix=""){ + $i = 0; + $tokens = array(); + $tnum = 0; + $in = false; + + while($ipos($s, "(", ")", $i+1); + $tokens[$tnum]="(".$this->cql2filter_(substr($s,$i+1,$pos-$i-1),$prefix); + $i=$pos; + break; + case "'": + $pos = strpos($s, "'", $i+1); + $tokens[$tnum] = substr($s,$i+1,$pos-$i-1); + $i=$pos; + //$tnum++; + //var_dump($tokens); + + break; + case ">": + case "<": + case "!": + case "=": + $ch1 = substr($s,$i-1,1); + if(!strpos(". !<>=",$ch1)) $tnum++; + // POZOR, break tam neni schvalne !!! + default: + if (!isset($tokens[$tnum])) $tokens[$tnum]=""; + $tokens[$tnum] .= $ch; + if(strpos(". !<>=",$ch)){ + $ch1 = substr($s,$i+1,1); + if(!strpos(". =",$ch1)) $tnum++; + } + break; + } + $i++; + } + + $tpos = 0; + $resh = ""; + $result = ''; + while($tpos < (count($tokens))){ + switch(strtoupper($tokens[$tpos])){ + case 'AND': $resh = "ogc:And"; $tpos++; break; + case 'OR': $resh = "ogc:Or"; $tpos++; break; + case 'BBOX': + $pom = explode(" ", str_replace(',', ' ', $tokens[$tpos+2])); + $result .= "".$prefix."BoundingBox + $pom[0] $pom[1]" + ."$pom[2] $pom[3]" + .""; + $tpos +=3; + break; + case 'IBBOX': + $pom = explode(" ", str_replace(',', ' ', $tokens[$tpos+2])); + $result .= "".$prefix."BoundingBox + $pom[0] $pom[1]" + ."$pom[2] $pom[3]" + .""; + $tpos +=3; + break; + case 'OBBOX': + $pom = explode(" ", str_replace(',', ' ', $tokens[$tpos+2])); + $result .= "$pom[0] $pom[1]" + ."$pom[2] $pom[3]" + ."" + ."".$prefix."BoundingBox"; + $tpos +=3; + break; + default: + if(substr($tokens[$tpos],0,1)=="("){ + $result .= substr($tokens[$tpos],1); $tpos++; + } + else{ + $par = ""; + switch($tokens[$tpos+1]){ + case '=': $operator = "ogc:PropertyIsEqualTo"; break; + case '!=': + case '<>': $operator = "ogc:PropertyIsNotEqualTo"; break; + case 'like': $operator = "ogc:PropertyIsLike"; $par=" wildCard=\"*\" singleChar=\"@\" escapeChar=\"\\\""; break; + case '>': $operator = "ogc:PropertyIsGreaterThan"; break; + case '>=': $operator = "ogc:PropertyIsGreaterThanOrEqualTo"; break; + case '<': $operator = "ogc:PropertyIsLessThan"; break; + case '<=': $operator = "ogc:PropertyIsLessThanOrEqualTo"; break; + case 'gt': $operator = "ogc:GreaterThan"; break; + default: $operator = "err-".$tokens[$tpos+1]; break; // kvuli chybam + } + if($this->sw == "gn") $name = $tokens[$tpos]; // hack kvuli geonetwork + else $name = $prefix.$tokens[$tpos]; + if($prefix=='dc:'){ + if($tokens[$tpos]=='AnyText') $name = "csw:".$tokens[$tpos]; + else if($tokens[$tpos]=='modified') $name = "dct:".$tokens[$tpos]; + } + $result .= "<$operator$par>".$name."".$tokens[$tpos+2].""; + $tpos += 3; + } + break; + } + } + if($resh) $result = "<$resh> + $result"; + return $result; +} + + function readServerList($listFile){ + $xml = new DomDocument; + $xml->load($listFile); + $servers = $xml->getElementsByTagName("server"); + foreach($servers as $server){ + $attribs = $server->attributes; + $name = $server->getAttribute("name"); + foreach($attribs as $attrib){ + $cswlist[$name][$attrib->name] = $attrib->value; + } + } + return $cswlist; + } + + function cql2filter($s, $prefix){ + return $this->xmlHead + . '' + . $this->cql2filter_($s, $prefix) + . ''; + } + + + /*********************************************** + * vytvori XML pro dotaz pomoci getRecordById + * + * @ids - seznam identifikatoru oddelenych carkou + * @schema - output schema + * @version - verze sluzby (nepovinne) + ***********************************************/ + function prepareRequestById($ids, $schema, $version=""){ + $id_array = explode(",",$ids); + $s = ""; + foreach($id_array as $id) $s .= "".trim($id).""; + $this->xml->loadXML($this->xmlHead."$s"); + if($this->sw=="gn"){ + $pom = file_get_contents(CSW_XSL."/client2GetRecordByIdRequest$version".$this->method.".xsl"); + $pom = str_replace("outputSchema=","OutputSchema=",$pom); // to je to ono + $this->xsl->loadXML($pom); + } + else{ + $this->xsl->load(CSW_XSL."/client2GetRecordByIdRequest$version".$this->method.".xsl"); + } + $this->xp->importStyleSheet($this->xsl); + $this->xp->setParameter("", "ElementSetName", $this->ElementSetName); + if($this->debug) $this->xp->setParameter("", "debug", $this->debug); + $this->xp->setParameter("", "outputSchema", $schema); + $this->xp->setParameter("", "id", $id_array[0]); //TODO pro vice Id + //if(substr($this->ElementSetName,0,2)=="dc") $outputSchema = OS_DC; else $outputSchema = OS_GMD; + //$this->xp->setParameter("", "outputSchema", $outputSchema); + $this->reqData = $this->xp->transformToXML($this->xml); // vrazi retezec s XML dotazem + } + + /*********************************************** + * vytvori XML pro dotaz pomoci getRecords + * + * cql - dotaz + * version - verze - podle toho se zvoli patricne xsl + ***********************************************/ + function prepareRequest($cql, $version=""){ + if(substr($this->typeNames,0,3)=="csw"){ + $prefix = "dc:"; + $outputSchema = OS_DC; + //$prefix = "csw:"; $outputSchema = OS_DC; // quli Intergrafu + } + else { + $prefix = "apiso:"; + $outputSchema = OS_GMD; + } + if($cql) $this->xml->loadXML($this->cql2filter($cql, $prefix)); + // hack - Geonetwork + if($this->sw=="gn"){ + $pom = file_get_contents(CSW_XSL."/client2GetRecordsRequest$version".$this->method.".xsl"); + $pom = str_replace("outputSchema=","OutputSchema=",$pom); + $this->xsl->loadXML($pom); + } + else { + $this->xsl->load(CSW_XSL."/client2GetRecordsRequest$version".$this->method.".xsl"); // verze 2 s kopirovanim stromu + } + $this->xp->importStyleSheet($this->xsl); + //if($this->debug) $this->xp->setParameter("", "debug", $this->debug); + $this->xp->setParameter("", "debug", $this->debug ? $this->debug : ''); + $this->xp->setParameter("", "ElementSetName", $this->ElementSetName); + $this->xp->setParameter("", "resultType", $this->resultType); + $this->xp->setParameter("", "typeNames", $this->typeNames); + $this->xp->setParameter("", "outputSchema", $outputSchema); + $this->xp->setParameter("", "startPosition", $this->startPosition); + $this->xp->setParameter("", "maxRecords", $this->maxRecords); + $this->xp->setParameter("", "hopCount", $this->hopCount); + $this->xp->setParameter("", "sortBy", $this->sortBy); + $this->xp->setParameter("", "id", "req-123"); + $this->reqData = $this->xp->transformToXML($this->xml); // vrazi retezec s XML dotazem + } + + /*********************************************** + * vytvori XML pro dotaz pomoci Update + * + * data - XML s daty + * + ***********************************************/ + function prepareUpdate($data){ + $this->xml->loadXML($data); + $this->xsl->load(CSW_XSL."/client2update.xsl"); // verze 2 s kopirovanim stromu + $this->xp->importStyleSheet($this->xsl); + $this->xp->setParameter("", "debug", $this->debug); + $this->xp->setParameter("", "ElementSetName", $this->ElementSetName); + $this->xp->setParameter("", "outputSchema", $this->outputSchema); + $this->xp->setParameter("", "hopCount", $this->hopCount); + $this->reqData = $this->xp->transformToXML($this->xml); // vrazi retezec s XML dotazem + } + + function saveRequest($name){ + if(!$this->reqData) return false; + return file_put_contents(CSW_TMP."/".$name, $this->reqData); + } + + function loadRequest($name){ + $s = file_get_contents(CSW_TMP."/".$name); + if(!$s) return false; + $this->reqData = $s; + //obnova parametru + $this->xml->loadXML($s); + $this->xsl->load(CSW_XSL."/filter2micka.xsl"); + $this->xp->importStyleSheet($this->xsl); + $s = explode("|",$this->xp->transformToXML($this->xml)); + eval($s[1]); + $this->debug = $params["DEBUG"]; + return true; + } + + function setXMLParam($name, $value){ + $root = $this->xml->getElementsByTagName('GetRecords')->item(0); + $root->setAttribute($name, $value); + $this->reqData = $this->xml->saveXML(); + } + + function getRequest(){ + return $this->reqData; + } + + /****************************************** + * Odesle a zpracuje dotaz - synchronne + * + * url - adresa csw serveru + * sablona - XSL sablona pro zpracovani vysledku + * + *****************************************/ + function runRequest($url, $name, $template='', $user='', $password='', $params=Array()){ + + if(!$this->reqData) exit('No query data available, run prepareRequest first!'); + $s = $this->getDataByPost($url, $this->reqData, $user, $password); + // --- ladici hlaska --- + if($this->debug){ + return "request: ".$this->formatXML($this->reqData)."
response:
". $this->formatXML($s)."
"; + } + if(!$s) return -1; + //if(!$s) $s = $this->xmlHead.""; + // --- transformace do HTML apod + $par = Array("theName"=>$name, "lang"=>$this->lang); + if($params) $par = array_merge($par, $params); + if($template) return $this->processTemplate($s, $template, $par); + else return($s); + } + + function processTemplate($xmlString, $template, $params=Array()){ + if($xmlString) @$this->xml->loadXML($xmlString); + if(!$this->xml) { + return ""; + } + $this->xsl->load($template); + $this->xp->importStyleSheet($this->xsl); + if(count($params) > 0){ + $this->xp->setParameter("", $params); + } + return $this->xp->transformToXML($this->xml); + } + + function processTemplateFile($xmlName, $template, $params=Array()){ + if($xmlName) $this->xml->load($xmlName); + $this->xsl->load($template); + $this->xp->importStyleSheet($this->xsl); + if(count($params) > 0){ + reset($params); + while(list($name, $value) = each($params)){ + $this->xp->setParameter("", $name, $value); + } + } + return $this->xp->transformToXML($this->xml); + } + +} // konec tridy + diff --git a/php/app/model/RecordModel.php b/php/app/model/RecordModel.php index 5952fc4..cc9e8c4 100644 --- a/php/app/model/RecordModel.php +++ b/php/app/model/RecordModel.php @@ -45,8 +45,9 @@ protected function setRecordMdById($id, $typeTableMd, $right) } $this->typeTableMd = $typeTableMd == 'edit_md' ? 'edit_md' : 'md'; if ($this->typeTableMd == 'edit_md') { + $user = isset($this->user->identity->username) ? $this->user->identity->username : 'guest'; $this->recordMd = $this->db->query( - "SELECT * FROM edit_md WHERE [edit_user]=%s AND [uuid]=%s", $this->user->getIdentity()->username, $id)->fetch(); + "SELECT * FROM edit_md WHERE [edit_user]=%s AND [uuid]=%s", $user, $id)->fetch(); } else { $this->recordMd = $this->db->query( "SELECT * FROM md WHERE [uuid]=%s", $id)->fetch(); @@ -160,11 +161,12 @@ protected function seMdValues($data, $recno=0) private function updateEditMD($recno) { + $user = isset($this->user->identity->username) ? $this->user->identity->username : 'guest'; $data = []; $data['data_type'] = $this->recordMd->data_type; $data['edit_group'] = $this->recordMd->edit_group; $data['view_group'] = $this->recordMd->view_group; - $data['last_update_user'] = isset($this->user->identity->username) ? $this->user->identity->username : 'guest'; + $data['last_update_user'] = $user; $data['last_update_date'] = Date("Y-m-d"); if ($this->langMd !== NULL) { $data['lang'] = $this->langMd; @@ -181,7 +183,7 @@ private function updateEditMD($recno) $data['md_update'] = $this->recordMd->md_update != '' ? $this->recordMd->md_update : NULL; //$data['valid'] = $this->recordMd->valid != '' ? $this->recordMd->valid : NULL; //$data['prim'] = $this->recordMd->prim != '' ? $this->recordMd->prim : NULL; - $this->db->query('UPDATE edit_md SET', $data , 'WHERE [edit_user]=%s AND [recno]=%i', $this->user->getIdentity()->username, $recno); + $this->db->query('UPDATE edit_md SET', $data , 'WHERE [edit_user]=%s AND [recno]=%i', $user, $recno); $x1 = $data['x1']; $x2 = $data['x2']; $y1 = $data['y1']; @@ -437,7 +439,7 @@ private function setNewEditMdRecord($httpRequest) $post = $httpRequest->getPost(); $date = new \DateTime(); $md = []; - $md['edit_user'] = $this->user->getIdentity()->username; + $md['edit_user'] = isset($this->user->identity->username) ? $this->user->identity->username : 'guest'; $md['edit_timestamp'] = $date->getTimestamp(); $md['recno'] = $this->getNewRecno('edit_md'); $md['md_recno'] = 0; @@ -546,39 +548,46 @@ public function getRecordMdValues() public function controlIsEditUse() { - $date = new \DateTime(); - $ts_lock = $date->getTimestamp() - $this->recordEditLock; - $use = $this->db->query( - 'SELECT COUNT([recno]) FROM edit_md WHERE [md_recno]=%i AND [edit_timestamp]>%i', - $this->recordMd->recno, - $ts_lock - )->fetchSingle(); - return $use > 0 ? true : false; + if (isset($this->appParameters['editLock']) && $this->appParameters['editLock'] === true) { + $date = new \DateTime(); + $ts_lock = $date->getTimestamp() - $this->recordEditLock; + $use = $this->db->query( + 'SELECT COUNT([recno]) FROM edit_md WHERE [md_recno]=%i AND [edit_timestamp]>%i', + $this->recordMd->recno, + $ts_lock + )->fetchSingle(); + return $use > 0 ? true : false; + } else { + return false; + } } public function deleteExpiredEditRecords() { - $recno = isset($this->recordMd->recno) && $this->recordMd->recno > 0 ? $this->recordMd->recno : 0; - $date = new \DateTime(); - $ts_lock = $date->getTimestamp() - $this->recordEditLock; - $tmp = $this->db->query(" - SELECT [recno] FROM edit_md WHERE [edit_timestamp]<%i - UNION - SELECT [recno] FROM edit_md WHERE [edit_user]=%s AND [md_recno]=%i - ", $ts_lock, $this->user->identity->username, $recno)->fetchAll(); - $recno_del = array(); - foreach($tmp as $row) { - $recno_del[] = $row->recno; + if (isset($this->user->identity->username)) { + $recno = isset($this->recordMd->recno) && $this->recordMd->recno > 0 ? $this->recordMd->recno : 0; + $date = new \DateTime(); + $ts_lock = $date->getTimestamp() - $this->recordEditLock; + $tmp = $this->db->query(" + SELECT [recno] FROM edit_md WHERE [edit_timestamp]<%i + UNION + SELECT [recno] FROM edit_md WHERE [edit_user]=%s AND [md_recno]=%i + ", $ts_lock, $this->user->identity->username, $recno)->fetchAll(); + $recno_del = array(); + foreach($tmp as $row) { + $recno_del[] = $row->recno; + } + $this->db->query('DELETE FROM edit_md WHERE [recno] IN %in', $recno_del); + $this->db->query('DELETE FROM edit_md_values WHERE [recno] IN %in', $recno_del); } - $this->db->query('DELETE FROM edit_md WHERE [recno] IN %in', $recno_del); - $this->db->query('DELETE FROM edit_md_values WHERE [recno] IN %in', $recno_del); } public function deleteEditRecordByUuid($uuid) { - $this->db->query('DELETE FROM edit_md_values WHERE [recno] IN(SELECT [recno] FROM edit_md WHERE [uuid]=%s AND [edit_user]=%s)', $uuid, $this->user->identity->username); - $this->db->query('DELETE FROM edit_md WHERE [uuid]=%s AND [edit_user]=%s', $uuid, $this->user->identity->username); + $user = isset($this->user->identity->username) ? $this->user->identity->username : 'guest'; + $this->db->query('DELETE FROM edit_md_values WHERE [recno] IN(SELECT [recno] FROM edit_md WHERE [uuid]=%s AND [edit_user]=%s)', $uuid, $user); + $this->db->query('DELETE FROM edit_md WHERE [uuid]=%s AND [edit_user]=%s', $uuid, $user); } public function getMdTitle($lang) @@ -1157,8 +1166,9 @@ private function applyXslTemplate2Xml($xsltemplate) protected function updateEditMdXml($recno, $xml) { + $user = isset($this->user->identity->username) ? $this->user->identity->username : 'guest'; $xml = $xml == '' ? NULL : str_replace("'", "'", $xml); - $this->db->query("UPDATE edit_md SET pxml=XMLPARSE(DOCUMENT %s) WHERE [edit_user]=%s AND [recno]=%i", $xml, $this->user->getIdentity()->username, $recno); + $this->db->query("UPDATE edit_md SET pxml=XMLPARSE(DOCUMENT %s) WHERE [edit_user]=%s AND [recno]=%i", $xml, $user, $recno); } protected function updateMd($editRecno, $recno) diff --git a/php/app/modules/Admin/templates/default/@layout.latte b/php/app/modules/Admin/templates/default/@layout.latte deleted file mode 100644 index a089df5..0000000 --- a/php/app/modules/Admin/templates/default/@layout.latte +++ /dev/null @@ -1,89 +0,0 @@ -{dump} - - - - - - - MICKA - {_messages.frontend.admin} - - - - - - - - - - - - -
- - - - {* FLASH *} - {snippet flashes} - - {/snippet flashes} - - - {include content} - - - - -
- - diff --git a/php/app/modules/Base/BasePresenter.php b/php/app/modules/Base/BasePresenter.php index c00cfc8..7c964ba 100644 --- a/php/app/modules/Base/BasePresenter.php +++ b/php/app/modules/Base/BasePresenter.php @@ -110,6 +110,9 @@ public function beforeRender() $this->template->action = $this->action; $this->template->navigation = []; $this->template->hs_initext = ''; + $this->template->edit_guest = isset($this->context->parameters['editGuest']) && $this->context->parameters['editGuest'] === true + ? true + : false; $this->template->langCodes = $this->langCodes; $this->template->pageTitle = isset($this->context->parameters['app']['pageTitle'][$this->appLang]) && $this->context->parameters['app']['pageTitle'][$this->appLang] != '' ? $this->context->parameters['app']['pageTitle'][$this->appLang] diff --git a/php/app/modules/Catalog/RecordPresenter.php b/php/app/modules/Catalog/RecordPresenter.php index 2c5aca3..cf7ea0a 100644 --- a/php/app/modules/Catalog/RecordPresenter.php +++ b/php/app/modules/Catalog/RecordPresenter.php @@ -123,7 +123,9 @@ public function renderNew() $this->context->parameters ); $this->template->mdStandard = $mcl->getStandardsLabel($this->appLang, TRUE); - $this->template->groups = isset($this->user->getIdentity()->data['groups']) ? $this->user->getIdentity()->data['groups'] : array(); + $this->template->groups = isset($this->user->getIdentity()->data['groups']) + ? $this->user->getIdentity()->data['groups'] + : array('guest'); $this->template->edit_group = $this->context->parameters['app']['defaultEditGroup']; $this->template->view_group = $this->context->parameters['app']['defaultViewGroup']; $this->template->mdLangs = $mcl->getLangsLabel($this->appLang); @@ -242,12 +244,9 @@ public function renderEdit($id) $this->context->parameters ); - $mdDataType = []; - if ($this->context->parameters['app']['mdDataType'] != '') { - eval('$tmp=['.$this->context->parameters['app']['mdDataType'].'];'); - foreach ($tmp as $key => $value) { - $mdDataType[$key] = $this->translator->translate('messages.frontend.'.$value); - } + $mdDataType = array(); + foreach ($this->context->parameters['mdDataType'] as $key => $value) { + $mdDataType[$key] = $this->translator->translate('messages.frontend.'.$value); } $this->template->record = [ 'recno'=>$recno, diff --git a/php/app/modules/Catalog/templates/default/@layout.latte b/php/app/modules/Catalog/templates/default/@layout.latte index 5bcca53..2544b0b 100644 --- a/php/app/modules/Catalog/templates/default/@layout.latte +++ b/php/app/modules/Catalog/templates/default/@layout.latte @@ -35,7 +35,7 @@