WfsServerBase.php 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623
  1. <?php
  2. Lib::loadClass('Api_WfsException');
  3. Lib::loadClass('Api_WfsGeomTypeConverter');
  4. Lib::loadClass('Api_WfsNs');
  5. Lib::loadClass('Request');
  6. Lib::loadClass('Core_AclHelper');
  7. class Api_WfsServerBase {
  8. public $_usrAcl;
  9. public $_typeConverter;
  10. public $_apiBaseUri;
  11. protected $_logFile;
  12. public function __construct($usrAcl) {
  13. $this->_usrAcl = $usrAcl;
  14. $this->_typeConverter = new Api_WfsGeomTypeConverter();
  15. $this->_apiBaseUri = '';
  16. }
  17. public function setBaseUri($uri) {
  18. $this->_apiBaseUri = $uri;
  19. }
  20. public function getBaseUri() {// TODO: RMME
  21. return $this->_apiBaseUri;
  22. }
  23. /**
  24. * @param string $typeName - 'p5_default_db:TEST_PERMS'
  25. */
  26. public function getAclFromTypeName($typeName) {
  27. $typeEx = explode(':', $typeName);
  28. $sourceName = null;
  29. if (2 != count($typeEx)) throw new Api_WfsException("Could not get acl for '{$typeName}' - syntax error");
  30. if ('p5_' == substr($typeEx[0], 0, 3)) $sourceName = substr($typeEx[0], 3);
  31. else if ('default_db__x3A__' == substr($typeEx[0], 0, 17)) $sourceName = 'default_db';
  32. else if ('default_objects' == $typeEx[0]) $sourceName = 'default_objects';
  33. else if ('default_db' == $typeEx[0]) $sourceName = 'default_db';
  34. if (!$sourceName) throw new Api_WfsException("Type not found '{$typeName}'", 404);
  35. $objName = $typeEx[1];
  36. $acl = $this->_usrAcl->getObjectAcl($sourceName, $objName);
  37. if (!$acl) throw new Api_WfsException("Could not get acl for '{$typeName}'");
  38. $forceTblAclInit = 0;//('1' == V::get('_force', '', $_GET));
  39. $acl->init($forceTblAclInit);
  40. return $acl;
  41. }
  42. /**
  43. * @param $_GET [ , POST Body - XML file ]
  44. * @return array $args
  45. * TODO: get $acl and check more restrictions
  46. */
  47. public function parseGetFeatureArgsFromRequest() {
  48. $rawArgs = $_GET;// $_REQUEST; ($_POST values not allowed, only xml in post body)
  49. $args = array();
  50. $args['xsd:type'] = null;// @from: TYPENAME, typeName (typename)
  51. $args['typePrefix'] = null;// @from: TYPENAME, typeName (typename)
  52. $args['typeName'] = null;// @from: TYPENAME, typeName (typename)
  53. $args['srsname'] = null;// @from: SRSNAME (srsname)
  54. $args['limit'] = 0;// @from: MAXFEATURES, maxFeatures, COUNT (maxfeatures, count)
  55. $args['offset'] = 0;// @from: startIndex (startindex, count)
  56. $args['ogc:filter'] = null;// @from: FILTER, Filter (filter)
  57. $args['sortBy'] = null;// @from: sortBy (sortby)
  58. $args['wfs:propertyName'] = null;// @from: propertyName (propertyname)
  59. $args['filterFields'] = array();// array of field names to show - @from: propertyName
  60. $args['resultType'] = null;// @from: resultType (resulttype)
  61. $args['bbox'] = null;// @from: BBOX (bbox)
  62. $args['wfs:featureID'] = null;// @from: featureID, featureId (featureid)
  63. $args['primaryKey'] = null;// primaryKey type - @from: featureID
  64. $lowerArgs = array(); foreach ($rawArgs as $name => $value) $lowerArgs[ strtolower($name) ] = trim($value);
  65. $args['xsd:type'] = V::get('typename', '', $lowerArgs);
  66. $exType = explode(':', $args['xsd:type']);
  67. if (count($exType) != 2) throw new HttpException("Wrong param TYPENAME", 400);
  68. $args['typePrefix'] = $exType[0];
  69. $args['typeName'] = $exType[1];
  70. $args['srsname'] = V::get('SRSNAME', '', $lowerArgs);// eg. EPSG:4326
  71. $args['limit'] = V::get('maxfeatures', $args['limit'], $lowerArgs, 'int');
  72. $args['limit'] = V::get('count', $args['limit'], $lowerArgs, 'int');
  73. if ($args['limit'] <= 0) $args['limit'] = 10000;// default limit
  74. $args['offset'] = V::get('startindex', 0, $lowerArgs, 'int');
  75. $args['ogc:filter'] = urldecode(V::get('filter', '', $lowerArgs));
  76. if (empty($args['ogc:filter'])) {// read ogc:Filter from POST body if not defined in GET
  77. $reqBody = Request::getRequestBody();
  78. if (!empty($reqBody)) {
  79. $args['ogc:filter'] = $this->convertOgcFilterFromRequestBody($reqBody);
  80. if (empty($args['ogc:filter'])) throw new Api_WfsException("Error Processing ogc:Filter", 501);
  81. }
  82. }
  83. $args['sortBy'] = V::get('sortby', '', $lowerArgs);// TODO: split to array of array(fieldName, (asc | desc))
  84. $args['wfs:propertyName'] = trim(V::get('propertyname', '', $lowerArgs));// TODO: fields to show - split by ','
  85. if (strlen($args['wfs:propertyName']) > 0) {
  86. $args['filterFields'] = array();
  87. $exFields = explode(',', $args['wfs:propertyName']);
  88. foreach ($exFields as $fieldName) {
  89. $fieldName = trim($fieldName);
  90. if (!empty($fieldName)) $args['filterFields'][] = $fieldName;
  91. }
  92. }
  93. $args['resultType'] = V::get('resulttype', '', $lowerArgs);
  94. $args['bbox'] = V::get('bbox', '', $lowerArgs);
  95. if (!empty($args['bbox'])) {
  96. // BBOX may have EPSG at then end - example: ",EPSG:4326"
  97. $num = "\d+.?\d*?";// "\d+(.\d+)?"
  98. if (!preg_match("/^({$num}),({$num}),({$num}),({$num})(\,EPSG:\d+)?$/", $args['bbox'], $matches)) throw new Exception("Illegal BBOX format");
  99. // QGIS may send BBOX in wrong order: 54.23580872176457,18.46844302390853,54.25220902538883,18.492990600812696
  100. // first number should be smaller then second
  101. // example $matches:
  102. // [0] => 18.492990600812696,54.23580872176457,18.46844302390853,54.25220902538883
  103. // [1] => 18.492990600812696
  104. // [2] => 54.23580872176457
  105. // [3] => 18.46844302390853
  106. // [4] => 54.25220902538883
  107. // (optional) EPGS
  108. $bboxPoints = ($matches[1] > $matches[2])
  109. ? [ $matches[2], $matches[3], $matches[4], $matches[1] ]
  110. : [ $matches[1], $matches[2], $matches[3], $matches[4] ];
  111. $searchParams['f_the_geom'] = "BBOX:" . implode(",", $bboxPoints);
  112. }
  113. $args['wfs:featureID'] = V::get('featureid', null, $lowerArgs);// TODO: allow multiply feature id (csv)
  114. if ($args['wfs:featureID']) {
  115. $dotPos = strpos($args['wfs:featureID'], '.');
  116. if (!$dotPos) throw new Exception("Wrong param fetureID");
  117. if ($args['typeName'] != substr($args['wfs:featureID'], 0, $dotPos)) throw new Exception("Wrong typeName in param fetureID");
  118. $args['primaryKey'] = substr($args['wfs:featureID'], $dotPos + 1);
  119. }
  120. if(DBG::isActive() && V::get('DBG', 0, $_GET)){ echo "\$lowerArgs:";print_r($lowerArgs); }
  121. if(DBG::isActive() && V::get('DBG', 0, $_GET)){ echo "\$args:";print_r($args); }
  122. return $args;
  123. }
  124. public function _getCapabilities($wfsServerUrl, $serviceTitle, $serviceDescription) {
  125. if (V::get('DBG_ACL', '', $_GET)) {
  126. {
  127. echo "Core_AclHelper::getAclList = [" . "\n";
  128. foreach (Core_AclHelper::getAclList() as $typeName) {
  129. echo "|\t{$typeName}" . "\n";
  130. }
  131. echo "]// .EOF Core_AclHelper::getAclList" . "\n";
  132. }
  133. $fullTblAclList = $this->_usrAcl->getTablesAcl();
  134. print_r($fullTblAclList);
  135. die("\n" . '.EOF - DBG_ACL');
  136. }
  137. echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
  138. ?>
  139. <WFS_Capabilities
  140. xmlns="http://www.opengis.net/wfs"
  141. xmlns:ogc="http://www.opengis.net/ogc"
  142. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  143. <?= $this->_printXmlNamespaceList(); ?>
  144. <?= $this->_getXmlSchemaLocation(); ?>
  145. version="1.0.0">
  146. <Service>
  147. <Name>WFS</Name>
  148. <Title><?= $serviceTitle; ?></Title>
  149. <Abstract><?= $serviceDescription; ?></Abstract>
  150. <Keywords>WFS, WMS</Keywords>
  151. <OnlineResource><?= $wfsServerUrl; ?></OnlineResource>
  152. <Fees>NONE</Fees>
  153. <AccessConstraints>NONE</AccessConstraints>
  154. </Service>
  155. <Capability>
  156. <Request>
  157. <?php $this->_printGetCapabilitiesXml($wfsServerUrl); ?>
  158. <?php $this->_printDescribeFeatureTypeXml($wfsServerUrl); ?>
  159. <?php $this->_printGetFeatureXml($wfsServerUrl); ?>
  160. <?php $this->_printTransactionXml($wfsServerUrl); ?>
  161. <?php $this->_printLockFeatureXml($wfsServerUrl); ?>
  162. <?php $this->_printGetFeatureWithLockXml($wfsServerUrl); ?>
  163. </Request>
  164. </Capability>
  165. <FeatureTypeList>
  166. <Operations>
  167. <Query />
  168. <Insert />
  169. <Update />
  170. <Delete />
  171. <Lock />
  172. </Operations>
  173. <?php $this->_printFeatureTypeListXml(); ?>
  174. </FeatureTypeList>
  175. <ogc:Filter_Capabilities>
  176. <ogc:Spatial_Capabilities>
  177. <ogc:Spatial_Operators>
  178. <ogc:Disjoint />
  179. <ogc:Equals />
  180. <ogc:DWithin />
  181. <ogc:Beyond />
  182. <ogc:Intersect />
  183. <ogc:Touches />
  184. <ogc:Crosses />
  185. <ogc:Within />
  186. <ogc:Contains />
  187. <ogc:Overlaps />
  188. <ogc:BBOX />
  189. </ogc:Spatial_Operators>
  190. </ogc:Spatial_Capabilities>
  191. <ogc:Scalar_Capabilities>
  192. <ogc:Logical_Operators />
  193. <ogc:Comparison_Operators>
  194. <ogc:Simple_Comparisons />
  195. <ogc:Between />
  196. <ogc:Like />
  197. <ogc:NullCheck />
  198. </ogc:Comparison_Operators>
  199. <ogc:Arithmetic_Operators>
  200. <ogc:Simple_Arithmetic />
  201. <ogc:Functions>
  202. <ogc:Function_Names>
  203. <ogc:Function_Name nArgs="1">abs</ogc:Function_Name>
  204. <ogc:Function_Name nArgs="1">abs_2</ogc:Function_Name>
  205. <ogc:Function_Name nArgs="1">abs_3</ogc:Function_Name>
  206. <ogc:Function_Name nArgs="1">abs_4</ogc:Function_Name>
  207. <ogc:Function_Name nArgs="1">acos</ogc:Function_Name>
  208. <ogc:Function_Name nArgs="2">AddCoverages</ogc:Function_Name>
  209. <ogc:Function_Name nArgs="4">Aggregate</ogc:Function_Name>
  210. <ogc:Function_Name nArgs="1">Area</ogc:Function_Name>
  211. <ogc:Function_Name nArgs="1">area2</ogc:Function_Name>
  212. <ogc:Function_Name nArgs="3">AreaGrid</ogc:Function_Name>
  213. <ogc:Function_Name nArgs="1">asin</ogc:Function_Name>
  214. <ogc:Function_Name nArgs="1">atan</ogc:Function_Name>
  215. <ogc:Function_Name nArgs="2">atan2</ogc:Function_Name>
  216. <ogc:Function_Name nArgs="14">BarnesSurface</ogc:Function_Name>
  217. <ogc:Function_Name nArgs="3">between</ogc:Function_Name>
  218. <ogc:Function_Name nArgs="1">boundary</ogc:Function_Name>
  219. <ogc:Function_Name nArgs="1">boundaryDimension</ogc:Function_Name>
  220. <ogc:Function_Name nArgs="1">Bounds</ogc:Function_Name>
  221. <ogc:Function_Name nArgs="2">buffer</ogc:Function_Name>
  222. <ogc:Function_Name nArgs="3">BufferFeatureCollection</ogc:Function_Name>
  223. <ogc:Function_Name nArgs="3">bufferWithSegments</ogc:Function_Name>
  224. <ogc:Function_Name nArgs="7">Categorize</ogc:Function_Name>
  225. <ogc:Function_Name nArgs="1">ceil</ogc:Function_Name>
  226. <ogc:Function_Name nArgs="1">Centroid</ogc:Function_Name>
  227. <ogc:Function_Name nArgs="2">classify</ogc:Function_Name>
  228. <ogc:Function_Name nArgs="2">Clip</ogc:Function_Name>
  229. <ogc:Function_Name nArgs="1">CollectGeometries</ogc:Function_Name>
  230. <ogc:Function_Name nArgs="1">Collection_Average</ogc:Function_Name>
  231. <ogc:Function_Name nArgs="1">Collection_Bounds</ogc:Function_Name>
  232. <ogc:Function_Name nArgs="0">Collection_Count</ogc:Function_Name>
  233. <ogc:Function_Name nArgs="1">Collection_Max</ogc:Function_Name>
  234. <ogc:Function_Name nArgs="1">Collection_Median</ogc:Function_Name>
  235. <ogc:Function_Name nArgs="1">Collection_Min</ogc:Function_Name>
  236. <ogc:Function_Name nArgs="1">Collection_Sum</ogc:Function_Name>
  237. <ogc:Function_Name nArgs="1">Collection_Unique</ogc:Function_Name>
  238. <ogc:Function_Name nArgs="1">Concatenate</ogc:Function_Name>
  239. <ogc:Function_Name nArgs="2">contains</ogc:Function_Name>
  240. <ogc:Function_Name nArgs="7">Contour</ogc:Function_Name>
  241. <ogc:Function_Name nArgs="2">convert</ogc:Function_Name>
  242. <ogc:Function_Name nArgs="1">convexHull</ogc:Function_Name>
  243. <ogc:Function_Name nArgs="1">cos</ogc:Function_Name>
  244. <ogc:Function_Name nArgs="1">Count</ogc:Function_Name>
  245. <ogc:Function_Name nArgs="2">CropCoverage</ogc:Function_Name>
  246. <ogc:Function_Name nArgs="2">crosses</ogc:Function_Name>
  247. <ogc:Function_Name nArgs="2">dateFormat</ogc:Function_Name>
  248. <ogc:Function_Name nArgs="2">dateParse</ogc:Function_Name>
  249. <ogc:Function_Name nArgs="2">difference</ogc:Function_Name>
  250. <ogc:Function_Name nArgs="1">dimension</ogc:Function_Name>
  251. <ogc:Function_Name nArgs="2">disjoint</ogc:Function_Name>
  252. <ogc:Function_Name nArgs="2">disjoint3D</ogc:Function_Name>
  253. <ogc:Function_Name nArgs="2">distance</ogc:Function_Name>
  254. <ogc:Function_Name nArgs="2">distance3D</ogc:Function_Name>
  255. <ogc:Function_Name nArgs="1">double2bool</ogc:Function_Name>
  256. <ogc:Function_Name nArgs="1">endAngle</ogc:Function_Name>
  257. <ogc:Function_Name nArgs="1">endPoint</ogc:Function_Name>
  258. <ogc:Function_Name nArgs="1">env</ogc:Function_Name>
  259. <ogc:Function_Name nArgs="1">envelope</ogc:Function_Name>
  260. <ogc:Function_Name nArgs="2">EqualInterval</ogc:Function_Name>
  261. <ogc:Function_Name nArgs="2">equalsExact</ogc:Function_Name>
  262. <ogc:Function_Name nArgs="3">equalsExactTolerance</ogc:Function_Name>
  263. <ogc:Function_Name nArgs="2">equalTo</ogc:Function_Name>
  264. <ogc:Function_Name nArgs="1">exp</ogc:Function_Name>
  265. <ogc:Function_Name nArgs="1">exteriorRing</ogc:Function_Name>
  266. <ogc:Function_Name nArgs="3">Feature</ogc:Function_Name>
  267. <ogc:Function_Name nArgs="1">floor</ogc:Function_Name>
  268. <ogc:Function_Name nArgs="1">geometryType</ogc:Function_Name>
  269. <ogc:Function_Name nArgs="1">geomFromWKT</ogc:Function_Name>
  270. <ogc:Function_Name nArgs="1">geomLength</ogc:Function_Name>
  271. <ogc:Function_Name nArgs="2">getGeometryN</ogc:Function_Name>
  272. <ogc:Function_Name nArgs="1">getX</ogc:Function_Name>
  273. <ogc:Function_Name nArgs="1">getY</ogc:Function_Name>
  274. <ogc:Function_Name nArgs="1">getz</ogc:Function_Name>
  275. <ogc:Function_Name nArgs="2">greaterEqualThan</ogc:Function_Name>
  276. <ogc:Function_Name nArgs="2">greaterThan</ogc:Function_Name>
  277. <ogc:Function_Name nArgs="5">Grid</ogc:Function_Name>
  278. <ogc:Function_Name nArgs="7">Heatmap</ogc:Function_Name>
  279. <ogc:Function_Name nArgs="0">id</ogc:Function_Name>
  280. <ogc:Function_Name nArgs="2">IEEEremainder</ogc:Function_Name>
  281. <ogc:Function_Name nArgs="3">if_then_else</ogc:Function_Name>
  282. <ogc:Function_Name nArgs="11">in10</ogc:Function_Name>
  283. <ogc:Function_Name nArgs="3">in2</ogc:Function_Name>
  284. <ogc:Function_Name nArgs="4">in3</ogc:Function_Name>
  285. <ogc:Function_Name nArgs="5">in4</ogc:Function_Name>
  286. <ogc:Function_Name nArgs="6">in5</ogc:Function_Name>
  287. <ogc:Function_Name nArgs="7">in6</ogc:Function_Name>
  288. <ogc:Function_Name nArgs="8">in7</ogc:Function_Name>
  289. <ogc:Function_Name nArgs="9">in8</ogc:Function_Name>
  290. <ogc:Function_Name nArgs="10">in9</ogc:Function_Name>
  291. <ogc:Function_Name nArgs="2">InclusionFeatureCollection</ogc:Function_Name>
  292. <ogc:Function_Name nArgs="1">int2bbool</ogc:Function_Name>
  293. <ogc:Function_Name nArgs="1">int2ddouble</ogc:Function_Name>
  294. <ogc:Function_Name nArgs="1">interiorPoint</ogc:Function_Name>
  295. <ogc:Function_Name nArgs="2">interiorRingN</ogc:Function_Name>
  296. <ogc:Function_Name nArgs="3">Interpolate</ogc:Function_Name>
  297. <ogc:Function_Name nArgs="2">intersection</ogc:Function_Name>
  298. <ogc:Function_Name nArgs="7">IntersectionFeatureCollection</ogc:Function_Name>
  299. <ogc:Function_Name nArgs="2">intersects</ogc:Function_Name>
  300. <ogc:Function_Name nArgs="2">intersects3D</ogc:Function_Name>
  301. <ogc:Function_Name nArgs="1">isClosed</ogc:Function_Name>
  302. <ogc:Function_Name nArgs="0">isCoverage</ogc:Function_Name>
  303. <ogc:Function_Name nArgs="1">isEmpty</ogc:Function_Name>
  304. <ogc:Function_Name nArgs="2">isLike</ogc:Function_Name>
  305. <ogc:Function_Name nArgs="1">isNull</ogc:Function_Name>
  306. <ogc:Function_Name nArgs="2">isometric</ogc:Function_Name>
  307. <ogc:Function_Name nArgs="1">isRing</ogc:Function_Name>
  308. <ogc:Function_Name nArgs="1">isSimple</ogc:Function_Name>
  309. <ogc:Function_Name nArgs="1">isValid</ogc:Function_Name>
  310. <ogc:Function_Name nArgs="3">isWithinDistance</ogc:Function_Name>
  311. <ogc:Function_Name nArgs="3">isWithinDistance3D</ogc:Function_Name>
  312. <ogc:Function_Name nArgs="2">Jenks</ogc:Function_Name>
  313. <ogc:Function_Name nArgs="1">length</ogc:Function_Name>
  314. <ogc:Function_Name nArgs="2">lessEqualThan</ogc:Function_Name>
  315. <ogc:Function_Name nArgs="2">lessThan</ogc:Function_Name>
  316. <ogc:Function_Name nArgs="1">list</ogc:Function_Name>
  317. <ogc:Function_Name nArgs="1">log</ogc:Function_Name>
  318. <ogc:Function_Name nArgs="4">LRSGeocode</ogc:Function_Name>
  319. <ogc:Function_Name nArgs="5">LRSMeasure</ogc:Function_Name>
  320. <ogc:Function_Name nArgs="5">LRSSegment</ogc:Function_Name>
  321. <ogc:Function_Name nArgs="2">max</ogc:Function_Name>
  322. <ogc:Function_Name nArgs="2">max_2</ogc:Function_Name>
  323. <ogc:Function_Name nArgs="2">max_3</ogc:Function_Name>
  324. <ogc:Function_Name nArgs="2">max_4</ogc:Function_Name>
  325. <ogc:Function_Name nArgs="2">min</ogc:Function_Name>
  326. <ogc:Function_Name nArgs="2">min_2</ogc:Function_Name>
  327. <ogc:Function_Name nArgs="2">min_3</ogc:Function_Name>
  328. <ogc:Function_Name nArgs="2">min_4</ogc:Function_Name>
  329. <ogc:Function_Name nArgs="1">mincircle</ogc:Function_Name>
  330. <ogc:Function_Name nArgs="1">minimumdiameter</ogc:Function_Name>
  331. <ogc:Function_Name nArgs="1">minrectangle</ogc:Function_Name>
  332. <ogc:Function_Name nArgs="2">modulo</ogc:Function_Name>
  333. <ogc:Function_Name nArgs="2">MultiplyCoverages</ogc:Function_Name>
  334. <ogc:Function_Name nArgs="3">Nearest</ogc:Function_Name>
  335. <ogc:Function_Name nArgs="1">not</ogc:Function_Name>
  336. <ogc:Function_Name nArgs="2">notEqualTo</ogc:Function_Name>
  337. <ogc:Function_Name nArgs="2">numberFormat</ogc:Function_Name>
  338. <ogc:Function_Name nArgs="5">numberFormat2</ogc:Function_Name>
  339. <ogc:Function_Name nArgs="1">numGeometries</ogc:Function_Name>
  340. <ogc:Function_Name nArgs="1">numInteriorRing</ogc:Function_Name>
  341. <ogc:Function_Name nArgs="1">numPoints</ogc:Function_Name>
  342. <ogc:Function_Name nArgs="1">octagonalenvelope</ogc:Function_Name>
  343. <ogc:Function_Name nArgs="3">offset</ogc:Function_Name>
  344. <ogc:Function_Name nArgs="2">overlaps</ogc:Function_Name>
  345. <ogc:Function_Name nArgs="1">parameter</ogc:Function_Name>
  346. <ogc:Function_Name nArgs="1">parseBoolean</ogc:Function_Name>
  347. <ogc:Function_Name nArgs="1">parseDouble</ogc:Function_Name>
  348. <ogc:Function_Name nArgs="1">parseInt</ogc:Function_Name>
  349. <ogc:Function_Name nArgs="1">parseLong</ogc:Function_Name>
  350. <ogc:Function_Name nArgs="0">pi</ogc:Function_Name>
  351. <ogc:Function_Name nArgs="4">PointBuffers</ogc:Function_Name>
  352. <ogc:Function_Name nArgs="2">pointN</ogc:Function_Name>
  353. <ogc:Function_Name nArgs="7">PointStacker</ogc:Function_Name>
  354. <ogc:Function_Name nArgs="6">PolygonExtraction</ogc:Function_Name>
  355. <ogc:Function_Name nArgs="2">pow</ogc:Function_Name>
  356. <ogc:Function_Name nArgs="1">property</ogc:Function_Name>
  357. <ogc:Function_Name nArgs="1">PropertyExists</ogc:Function_Name>
  358. <ogc:Function_Name nArgs="2">Quantile</ogc:Function_Name>
  359. <ogc:Function_Name nArgs="3">Query</ogc:Function_Name>
  360. <ogc:Function_Name nArgs="0">random</ogc:Function_Name>
  361. <ogc:Function_Name nArgs="5">RangeLookup</ogc:Function_Name>
  362. <ogc:Function_Name nArgs="1">RasterAsPointCollection</ogc:Function_Name>
  363. <ogc:Function_Name nArgs="4">RasterZonalStatistics</ogc:Function_Name>
  364. <ogc:Function_Name nArgs="5">Recode</ogc:Function_Name>
  365. <ogc:Function_Name nArgs="2">RectangularClip</ogc:Function_Name>
  366. <ogc:Function_Name nArgs="2">relate</ogc:Function_Name>
  367. <ogc:Function_Name nArgs="3">relatePattern</ogc:Function_Name>
  368. <ogc:Function_Name nArgs="3">Reproject</ogc:Function_Name>
  369. <ogc:Function_Name nArgs="1">rint</ogc:Function_Name>
  370. <ogc:Function_Name nArgs="1">round</ogc:Function_Name>
  371. <ogc:Function_Name nArgs="1">round_2</ogc:Function_Name>
  372. <ogc:Function_Name nArgs="1">roundDouble</ogc:Function_Name>
  373. <ogc:Function_Name nArgs="6">ScaleCoverage</ogc:Function_Name>
  374. <ogc:Function_Name nArgs="4">sdo_nn</ogc:Function_Name>
  375. <ogc:Function_Name nArgs="2">setCRS</ogc:Function_Name>
  376. <ogc:Function_Name nArgs="3">Simplify</ogc:Function_Name>
  377. <ogc:Function_Name nArgs="1">sin</ogc:Function_Name>
  378. <ogc:Function_Name nArgs="3">Snap</ogc:Function_Name>
  379. <ogc:Function_Name nArgs="1">sqrt</ogc:Function_Name>
  380. <ogc:Function_Name nArgs="2">StandardDeviation</ogc:Function_Name>
  381. <ogc:Function_Name nArgs="1">startAngle</ogc:Function_Name>
  382. <ogc:Function_Name nArgs="1">startPoint</ogc:Function_Name>
  383. <ogc:Function_Name nArgs="1">strCapitalize</ogc:Function_Name>
  384. <ogc:Function_Name nArgs="2">strConcat</ogc:Function_Name>
  385. <ogc:Function_Name nArgs="2">strEndsWith</ogc:Function_Name>
  386. <ogc:Function_Name nArgs="2">strEqualsIgnoreCase</ogc:Function_Name>
  387. <ogc:Function_Name nArgs="2">strIndexOf</ogc:Function_Name>
  388. <ogc:Function_Name nArgs="2">strLastIndexOf</ogc:Function_Name>
  389. <ogc:Function_Name nArgs="1">strLength</ogc:Function_Name>
  390. <ogc:Function_Name nArgs="2">strMatches</ogc:Function_Name>
  391. <ogc:Function_Name nArgs="3">strPosition</ogc:Function_Name>
  392. <ogc:Function_Name nArgs="4">strReplace</ogc:Function_Name>
  393. <ogc:Function_Name nArgs="2">strStartsWith</ogc:Function_Name>
  394. <ogc:Function_Name nArgs="3">strSubstring</ogc:Function_Name>
  395. <ogc:Function_Name nArgs="2">strSubstringStart</ogc:Function_Name>
  396. <ogc:Function_Name nArgs="1">strToLowerCase</ogc:Function_Name>
  397. <ogc:Function_Name nArgs="1">strToUpperCase</ogc:Function_Name>
  398. <ogc:Function_Name nArgs="1">strTrim</ogc:Function_Name>
  399. <ogc:Function_Name nArgs="3">strTrim2</ogc:Function_Name>
  400. <ogc:Function_Name nArgs="2">StyleCoverage</ogc:Function_Name>
  401. <ogc:Function_Name nArgs="2">symDifference</ogc:Function_Name>
  402. <ogc:Function_Name nArgs="1">tan</ogc:Function_Name>
  403. <ogc:Function_Name nArgs="1">toDegrees</ogc:Function_Name>
  404. <ogc:Function_Name nArgs="1">toRadians</ogc:Function_Name>
  405. <ogc:Function_Name nArgs="2">touches</ogc:Function_Name>
  406. <ogc:Function_Name nArgs="1">toWKT</ogc:Function_Name>
  407. <ogc:Function_Name nArgs="2">Transform</ogc:Function_Name>
  408. <ogc:Function_Name nArgs="2">union</ogc:Function_Name>
  409. <ogc:Function_Name nArgs="2">UnionFeatureCollection</ogc:Function_Name>
  410. <ogc:Function_Name nArgs="2">Unique</ogc:Function_Name>
  411. <ogc:Function_Name nArgs="2">UniqueInterval</ogc:Function_Name>
  412. <ogc:Function_Name nArgs="6">VectorToRaster</ogc:Function_Name>
  413. <ogc:Function_Name nArgs="3">VectorZonalStatistics</ogc:Function_Name>
  414. <ogc:Function_Name nArgs="1">vertices</ogc:Function_Name>
  415. <ogc:Function_Name nArgs="2">within</ogc:Function_Name>
  416. </ogc:Function_Names>
  417. </ogc:Functions>
  418. </ogc:Arithmetic_Operators>
  419. </ogc:Scalar_Capabilities>
  420. </ogc:Filter_Capabilities>
  421. </WFS_Capabilities>
  422. <?php
  423. exit;
  424. }
  425. public function _getXmlSchemaLocation() {
  426. $schemaLocations = array();
  427. //$schemaLocations[] = 'http://www.opengis.net/wfs http://webgis.regione.sardegna.it:80/geoserver/schemas/wfs/1.0.0/WFS-capabilities.xsd';// @from http://webgis.regione.sardegna.it/geoserver/ows?service=WFS&request=GetCapabilities
  428. return (!empty($schemaLocations))? 'xsi:schemaLocation="' . implode(' ', $schemaLocations) . '"' : '';
  429. }
  430. public function _printXmlNamespaceList() {
  431. $listNs = array();
  432. foreach (Api_WfsNs::getNsList() as $uri => $prefix) {
  433. $listNs[] = 'xmlns:' . $prefix . '="' . $uri . '"';
  434. }
  435. return implode("\n", $listNs);
  436. }
  437. public function _getSourceNsList() {
  438. $usrObjList = array();
  439. $tblsAcl = $this->_usrAcl->getTablesAcl();
  440. foreach ($tblsAcl as $tblAcl) {
  441. $dataSourceName = 'default_db';// TODO: getSourceName
  442. $tblName = $tblAcl->getName();
  443. $usrObjList[] = array($dataSourceName, $tblName);
  444. }
  445. $usrObjList[] = array('objects', 'File');
  446. $usrObjList[] = array('objects', 'TestPerms');
  447. $usrObjList[] = array('objects', 'Korespondencja');
  448. return $usrObjList;
  449. }
  450. public function _printGetCapabilitiesXml($wfsServerUrl) {
  451. ?>
  452. <GetCapabilities>
  453. <DCPType>
  454. <HTTP>
  455. <Get onlineResource="<?php echo $wfsServerUrl; ?>?REQUEST=GetCapabilities" />
  456. </HTTP>
  457. </DCPType>
  458. <DCPType>
  459. <HTTP>
  460. <Post onlineResource="<?php echo $wfsServerUrl; ?>" />
  461. </HTTP>
  462. </DCPType>
  463. </GetCapabilities>
  464. <?php
  465. }
  466. public function _printDescribeFeatureTypeXml($wfsServerUrl) {
  467. ?>
  468. <DescribeFeatureType>
  469. <SchemaDescriptionLanguage>
  470. <XMLSCHEMA />
  471. </SchemaDescriptionLanguage>
  472. <DCPType>
  473. <HTTP>
  474. <Get onlineResource="<?php echo $wfsServerUrl; ?>?REQUEST=DescribeFeatureType" />
  475. </HTTP>
  476. </DCPType>
  477. <DCPType>
  478. <HTTP>
  479. <Post onlineResource="<?php echo $wfsServerUrl; ?>" />
  480. </HTTP>
  481. </DCPType>
  482. </DescribeFeatureType>
  483. <?php
  484. }
  485. public function _printGetFeatureXml($wfsServerUrl) {
  486. ?>
  487. <GetFeature>
  488. <ResultFormat>
  489. <WFSKMLOutputFormat />
  490. <GML2 />
  491. <GML3 />
  492. <SHAPE-ZIP />
  493. <CSV />
  494. <JSON />
  495. </ResultFormat>
  496. <DCPType>
  497. <HTTP>
  498. <Get onlineResource="<?php echo $wfsServerUrl; ?>?REQUEST=GetFeature" />
  499. </HTTP>
  500. </DCPType>
  501. <DCPType>
  502. <HTTP>
  503. <Post onlineResource="<?php echo $wfsServerUrl; ?>" />
  504. </HTTP>
  505. </DCPType>
  506. </GetFeature>
  507. <?php
  508. }
  509. public function _printTransactionXml($wfsServerUrl) {
  510. ?>
  511. <Transaction>
  512. <DCPType>
  513. <HTTP>
  514. <Get onlineResource="<?php echo $wfsServerUrl; ?>?request=Transaction" />
  515. </HTTP>
  516. </DCPType>
  517. <DCPType>
  518. <HTTP>
  519. <Post onlineResource="<?php echo $wfsServerUrl; ?>" />
  520. </HTTP>
  521. </DCPType>
  522. </Transaction>
  523. <?php
  524. }
  525. public function _printLockFeatureXml($wfsServerUrl) {
  526. ?>
  527. <LockFeature>
  528. <DCPType>
  529. <HTTP>
  530. <Get onlineResource="<?php echo $wfsServerUrl; ?>?REQUEST=LockFeature" />
  531. </HTTP>
  532. </DCPType>
  533. <DCPType>
  534. <HTTP>
  535. <Post onlineResource="<?php echo $wfsServerUrl; ?>" />
  536. </HTTP>
  537. </DCPType>
  538. </LockFeature>
  539. <?php
  540. }
  541. public function _printGetFeatureWithLockXml($wfsServerUrl) {
  542. ?>
  543. <GetFeatureWithLock>
  544. <ResultFormat>
  545. <GML2 />
  546. </ResultFormat>
  547. <DCPType>
  548. <HTTP>
  549. <Get onlineResource="<?php echo $wfsServerUrl; ?>?REQUEST=GetFeatureWithLock" />
  550. </HTTP>
  551. </DCPType>
  552. <DCPType>
  553. <HTTP>
  554. <Post onlineResource="<?php echo $wfsServerUrl; ?>" />
  555. </HTTP>
  556. </DCPType>
  557. </GetFeatureWithLock>
  558. <?php
  559. }
  560. public function _printFeatureTypeListXml() {
  561. $featureTypes = array();
  562. foreach ($this->_getTableAclList() as $tblAcl) {
  563. $dataSourceName = 'default_db';// TODO: getSourceName
  564. $tblName = $tblAcl->getName();
  565. $usrObjList[] = array($dataSourceName, $tblName);
  566. $featureType = array();
  567. $featureType['ns'] = "p5_{$dataSourceName}";
  568. $featureType['Name'] = $tblAcl->getName();
  569. $featureType['Title'] = $tblAcl->getRawLabel();
  570. $featureType['Abstract'] = $tblAcl->getRawOpis();
  571. $featureType['Keywords'] = array();
  572. $featureType['Keywords'][] = $tblAcl->getID();
  573. $featureType['Keywords'][] = $tblName;
  574. $featureType['Keywords'][] = $tblAcl->getRawLabel();
  575. $featureType['Keywords'] = implode(", ", $featureType['Keywords']);
  576. $featureType['SRS'] = "EPSG:4326";
  577. $featureType['LatLongBoundingBox'] = array();// TODO: feature LatLongBoundingBox
  578. $featureType['LatLongBoundingBox']['minx'] = "8.12328509871721";
  579. $featureType['LatLongBoundingBox']['miny'] = "38.8575126897477";
  580. $featureType['LatLongBoundingBox']['maxx'] = "9.838674658246807";
  581. $featureType['LatLongBoundingBox']['maxy'] = "41.31378404137082";
  582. $featureTypes[] = $featureType;
  583. }
  584. foreach (Core_AclHelper::getAclList() as $typeName) {
  585. $exTypeName = explode(':', $typeName);
  586. $featureType = array();
  587. $featureType['ns'] = $exTypeName[0];
  588. $featureType['Name'] = $exTypeName[1];
  589. $featureType['Title'] = $exTypeName[1];
  590. $featureType['Abstract'] = $exTypeName[1];
  591. $featureType['Keywords'] = $exTypeName[1];
  592. $featureType['SRS'] = "EPSG:4326";
  593. $featureTypes[] = $featureType;
  594. }
  595. /*
  596. <FeatureType>
  597. <Name>ppr06:AMBITIPAESAGGIO</Name>
  598. <Title>AMBITIPAESAGGIO</Title>
  599. <Abstract />
  600. <Keywords>features, AMBITIPAESAGGIO</Keywords>
  601. <SRS>EPSG:4326</SRS>
  602. <LatLongBoundingBox minx="8.12328509871721" miny="38.8575126897477" maxx="9.838674658246807" maxy="41.31378404137082" />
  603. </FeatureType>
  604. */
  605. $featureTypesXml = '';
  606. foreach ($featureTypes as $feature) {
  607. $nsUriFeature = Api_WfsNs::getNsUri($feature['ns']);
  608. $featureTypesXml .= " " . '<FeatureType xmlns:' . $feature['ns'] . '="' . $nsUriFeature . '">' . "\n";
  609. $featureTypesXml .= " " . '<Name>' . "{$feature['ns']}:{$feature['Name']}" . '</Name>' . "\n";
  610. $featureTypesXml .= " " . '<Title>' . "{$feature['Title']}" . '</Title>' . "\n";
  611. if (!empty($feature['Abstract'])) {
  612. $featureTypesXml .= " " . '<Abstract>' . "{$feature['Abstract']}" . '</Abstract>' . "\n";
  613. } else {
  614. $featureTypesXml .= " " . '<Abstract/>' . "\n";
  615. }
  616. if (!empty($feature['Keywords'])) {
  617. $featureTypesXml .= " " . '<Keywords>' . "{$feature['Keywords']}" . '</Keywords>' . "\n";
  618. } else {
  619. $featureTypesXml .= " " . '<Keywords/>' . "\n";
  620. }
  621. $featureTypesXml .= " " . '<SRS>' . "{$feature['SRS']}" . '</SRS>' . "\n";
  622. if (!empty($feature['LatLongBoundingBox'])) {
  623. $latLongBoundingBoxOut = array();
  624. $latLongBoundingBoxOut[] = 'minx="' . $feature['LatLongBoundingBox']['minx'] . '"';
  625. $latLongBoundingBoxOut[] = 'miny="' . $feature['LatLongBoundingBox']['miny'] . '"';
  626. $latLongBoundingBoxOut[] = 'maxx="' . $feature['LatLongBoundingBox']['maxx'] . '"';
  627. $latLongBoundingBoxOut[] = 'maxy="' . $feature['LatLongBoundingBox']['maxy'] . '"';
  628. $featureTypesXml .= " " . '<LatLongBoundingBox ' . implode(' ', $latLongBoundingBoxOut) . ' />' . "\n";
  629. }
  630. $featureTypesXml .= " " . '</FeatureType>' . "\n";
  631. }
  632. echo $featureTypesXml;
  633. }
  634. public function _parseTransactionXmlStruct($requestXml, $requestXmlTags) {
  635. $DBG = V::get('DBG_XML', 0, $_GET, 'int');// TODO: Profiler
  636. $rootTagName = V::get('tag', '', $requestXmlTags[0]);
  637. if ('Transaction' != $rootTagName) throw new Api_WfsException("Parse Request XML Error - Missing Transaction as root xml tag", __LINE__, null, 'TransactionParseError', 'request');
  638. // TODO: special actions if action on nested objects
  639. // 1. convert request: wfs.transaction.convert-wfs-request.xsl
  640. // 2. validate converted request: wfs.transaction-converted-request.xsd
  641. // 3. execute request in data source
  642. // if($DBG){echo 'L.' . __LINE__ . ' $requestXmlTags:';print_r($requestXmlTags);echo "\n";}
  643. /*
  644. <Transaction
  645. xmlns="http://www.opengis.net/wfs"
  646. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  647. version="1.0.0"
  648. service="WFS"
  649. xmlns:p5_objects="https://biuro.biall-net.pl/wfs/objects"
  650. xmlns:gml="http://www.opengis.net/gml">
  651. <Insert xmlns="http://www.opengis.net/wfs">
  652. <TestPerms xmlns="https://biuro.biall-net.pl/wfs/objects">
  653. <plik xmlns="https://biuro.biall-net.pl/wfs/objects">
  654. <p5_objects:File>
  655. <p5_objects:name>blank-wfs.gif</p5_objects:name>
  656. <p5_objects:content>R0lGODlhAQABAIAAAP///////yH+EUNyZWF0ZWQgd2l0aCBHSU1QACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==</p5_objects:content>
  657. </p5_objects:File>
  658. </plik>
  659. </TestPerms>
  660. </Insert>
  661. </Transaction>
  662. */
  663. $actionXmlTags = array();// // [ 0 => [ 'action'=>Insert, 'typeName'=>str, 'tags'=>[] ]
  664. {// split xml for action tags (Insert, Update, Delete)
  665. $tagsCount = count($requestXmlTags);
  666. for ($i = 1, $actionTagName = null, $actionIdx = -1, $tagLvl = 0; $i < $tagsCount - 1; $i++) {// skip Transaction open/close tag
  667. $tag = $requestXmlTags[$i];
  668. if (null == $actionTagName) {
  669. $actionTagName = $tag['tag'];
  670. $tagLvl = $tag['level'];
  671. $actionIdx += 1;
  672. $actionXmlTags[$actionIdx] = array();
  673. $actionXmlTags[$actionIdx]['action'] = $actionTagName;
  674. $actionXmlTags[$actionIdx]['typeName'] = V::get('typeName', '', $tag['attributes']);
  675. $actionXmlTags[$actionIdx]['isDeepObject'] = null;// null - unknown, false - not seed, true - deep
  676. $actionXmlTags[$actionIdx]['tags'] = array();
  677. } else if ($tag['tag'] == $actionTagName && 'close' == $tag['type'] && $tagLvl == $tag['level']) {
  678. $actionTagName = null;
  679. } else {
  680. $actionXmlTags[$actionIdx]['tags'][] = $tag;
  681. }
  682. }
  683. }
  684. {// Validate Request: WFS allow multiple tags inside Insert tag
  685. // TODO: implement multiple tags in Insert tag if reauired. Use array_splice($actionXmlTags, $actionIdx, 0, $insertTags);
  686. {// throw (Not Implemented, 501) if found multiple tags in Insert tag
  687. foreach ($actionXmlTags as $actionIdx => $action) {
  688. if ('Insert' !== $action['action']) continue;
  689. $lvl = $action['tags'][0]['level'];
  690. for ($i = 1, $cnt = count($action['tags']); $i < $cnt - 1; $i++) {
  691. $tag = $action['tags'][$i];
  692. // if($DBG){echo 'L.' . __LINE__ . " actionXmlTags loop({$i}) \$tag:";print_r($tag);echo "\n";}
  693. if ($tag['level'] == $lvl) throw new Exception("Error Processing Request - multiple tags inside Insert tag is not implemented", 501);
  694. }
  695. }
  696. }
  697. }
  698. {// Insert tag - fix typeName from first tag, remove first and last tag - leave only fields
  699. foreach ($actionXmlTags as $actionIdx => $action) {
  700. if ('Insert' !== $action['action']) continue;
  701. array_pop($action['tags']);// remove last tag (close tag)
  702. $tag = array_shift($action['tags']);// remove last tag (close tag)
  703. $typeName = $tag['tag'];// eg. with prefix 'p5_objects:File' or without prefix but with @xmlns
  704. if (false === strpos($typeName, ':')) {
  705. $nsType = V::get('xmlns', '', $tag['attributes']);
  706. if (!$nsType) throw new Exception("Error Processing Request - Missing object namespace '{$tag['tag']}'");
  707. $prefix = Api_WfsNs::getNsPrefix($nsType);
  708. if (!$prefix) {
  709. if ($typeName == substr(rtrim($nsType, '/'), -1 * strlen($typeName))) {// typeName may be added to ns uri
  710. $nsBaseForType = substr(rtrim($nsType, '/'), 0, -1 * strlen($typeName) - 1);
  711. $prefix = Api_WfsNs::getNsPrefix($nsBaseForType);
  712. }
  713. }
  714. if (!$prefix) throw new Exception("Error Processing Request - Unrecognized namespace uri '{$nsType}' for object '{$tag['tag']}'");
  715. $typeName = "{$prefix}:{$typeName}";
  716. }
  717. $action['typeName'] = $typeName;
  718. $actionXmlTags[$actionIdx] = $action;
  719. }
  720. }
  721. {// validate
  722. // if($DBG){echo 'L.' . __LINE__ . ' before validate $actionXmlTags:';print_r($actionXmlTags);echo "\n";}
  723. foreach ($actionXmlTags as $actionIdx => $action) {
  724. if ('Insert' == $action['action']) {
  725. if (empty($action['typeName'])) throw new Exception("Error Processing Request - unknown object typeName to Insert");
  726. $acl = $this->getAclFromTypeName($action['typeName']);
  727. $actionXmlTags[$actionIdx] = $acl->validateInsertXml($action);
  728. } else if ('Update' == $action['action']) {
  729. $acl = $this->getAclFromTypeName($action['typeName']);
  730. $actionXmlTags[$actionIdx] = $acl->validateUpdateXml($action);
  731. } else if ('Delete' == $action['action']) {
  732. if($DBG>1){echo'<pre>$action: ';print_r($action);echo'</pre>';}
  733. $acl = $this->getAclFromTypeName($action['typeName']);
  734. $actionXmlTags[$actionIdx] = $acl->validateDeleteXml($action);
  735. } else {
  736. if($DBG>1){echo'<pre>$action: ';print_r($action);echo'</pre>';}
  737. throw new Exception("{$action['action']} action not implemented", 501);
  738. }
  739. // continue;// TODO: validate all by type
  740. }
  741. }
  742. if ('1' == V::get('DBG_DONT_CHANGE_DB', '', $_REQUEST)) {
  743. echo "----------------- action xml tags: ---------------" . "\n";
  744. print_r($actionXmlTags);
  745. die(".EOF\n");
  746. }
  747. {// execute
  748. $returnIds = array();
  749. $changesList = array();
  750. foreach ($actionXmlTags as $actionIdx => $action) {
  751. if ('Insert' == $action['action']) {
  752. if (empty($action['typeName'])) throw new Exception("Error Processing Request - unknown object typeName to Insert");
  753. $acl = $this->getAclFromTypeName($action['typeName']);
  754. $newId = $acl->insertXml($action);
  755. $returnIds[$actionIdx] = $newId;
  756. $changesList[$actionIdx] = array('Status'=>(($newId > 0)? 'SUCCESS' : 'FAILED'), 'Message'=>"created {$newId}.", 'Action' => $action['action']);
  757. if ($newId > 0) $changesList[$actionIdx]['fid'] = $acl->getName() . '.' . $newId;
  758. } else if ('Update' == $action['action']) {
  759. if($DBG>1){echo'<pre>$action: ';print_r($action);echo'</pre>';}
  760. $acl = $this->getAclFromTypeName($action['typeName']);
  761. $affected = $acl->updateXml($action);
  762. $changesList[$actionIdx] = array('Status'=>(($affected >= 0)? 'SUCCESS' : 'FAILED'), 'Message'=>"affected {$affected}.", 'Action' => $action['action']);
  763. } else if ('Delete' == $action['action']) {
  764. $acl = $this->getAclFromTypeName($action['typeName']);
  765. $affected = $acl->deleteXml($action);
  766. $changesList[$actionIdx] = array('Status'=>(($affected >= 0)? 'SUCCESS' : 'FAILED'), 'Message'=>"deleted {$affected}.", 'Action' => $action['action']);
  767. } else throw new Exception("TODO: {$action['action']} action not implemented", 501);
  768. }
  769. if($DBG){echo 'L.' . __LINE__ . ' $changesList:';print_r($changesList);echo "\n";}
  770. }
  771. return $this->_transactionResponse($changesList);
  772. }
  773. public function _transactionResponse($changesList) {
  774. // <WFS_TransactionResponse>
  775. // <TransactionResult>
  776. // <Status> : SUCCESS / FAILED / PARTIAL
  777. // [<Locator]
  778. // [<Message]
  779. $messageTag = '';
  780. $statusTag = '';
  781. $statusIsFailed = false;
  782. $statusAll = null;
  783. $createdFetureId = array();
  784. foreach ($changesList as $featureId => $change) {
  785. if ('FAILED' == $change['Status']) {
  786. $statusIsFailed = true;
  787. }
  788. if ('SUCCESS' == $change['Status'] && !empty($change['fid'])) {
  789. $createdFetureId[] = $change['fid'];
  790. }
  791. // if (!empty($change['Message'])) $messageTag .= "Feature '{$featureId}' {$change['Status']}: {$change['Message']}\n";
  792. }
  793. $statusTag = ($statusIsFailed)? 'FAILED' : 'SUCCESS';
  794. $statusTag = "<wfs:{$statusTag}/>";
  795. $messageTag = '';//"<wfs:Message>{$messageTag}</wfs:Message>";
  796. /* Example:
  797. <?xml version="1.0" encoding="UTF-8"?>
  798. <wfs:WFS_TransactionResponse version="1.0.0" xmlns:wfs="http://www.opengis.net/wfs"
  799. xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  800. xsi:schemaLocation="http://www.opengis.net/wfs http://localhost:8080/geoserver/schemas/wfs/1.0.0/WFS-transaction.xsd">
  801. <wfs:InsertResult>
  802. <ogc:FeatureId fid="archsites.26" />
  803. </wfs:InsertResult>
  804. <wfs:TransactionResult handle="Updating Signature rock label">
  805. <wfs:Status>
  806. <wfs:SUCCESS />
  807. </wfs:Status>
  808. </wfs:TransactionResult>
  809. </wfs:WFS_TransactionResponse>*/
  810. // TODO: build xml by DOMDocument
  811. // TODO: xsi:schemaLocation="http://www.opengis.net/wfs http://localhost:8080/geoserver/schemas/wfs/1.0.0/WFS-transaction.xsd"
  812. $wfsInsertResult = '';
  813. if (!empty($createdFetureId)) {
  814. $wfsInsertResult = "\n<wfs:InsertResult>\n";
  815. foreach ($createdFetureId as $fid) {
  816. $wfsInsertResult .= '<ogc:FeatureId fid="' . $fid . '" xmlns:ogc="http://www.opengis.net/ogc"/>' . "\n";
  817. }
  818. $wfsInsertResult .= "\n</wfs:InsertResult>\n";
  819. EOF;
  820. }
  821. $tranRes = <<<EOF
  822. <wfs:WFS_TransactionResponse version="1.0.0"
  823. xmlns:wfs="http://www.opengis.net/wfs"
  824. xmlns:ogc="http://www.opengis.net/ogc"
  825. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  826. {$wfsInsertResult}
  827. <wfs:TransactionResult>
  828. <wfs:Status>{$statusTag}</wfs:Status>
  829. {$messageTag}
  830. </wfs:TransactionResult>
  831. </wfs:WFS_TransactionResponse>
  832. EOF;
  833. return $tranRes;
  834. }
  835. public function _convertTransactionXml($requestXmlString, $sourceNsList) {
  836. $DBG = (V::get('DBG_XSL', '', $_GET) > 0);// TODO: Profiler
  837. if($DBG){echo 'L.' . __LINE__ . ' sourceNsList:';print_r($sourceNsList);echo "\n";}
  838. $updateActionsXsd = array();
  839. $insertActionsXsd = array();
  840. $deleteActionsXsd = array();
  841. //<!-- TODO: create tag Update{X} where X is namespace index -->
  842. foreach ($sourceNsList as $nsInd => $sourceNs) {
  843. // <Update>
  844. $theGeomField = 'the_geom';// TODO: get from fields list
  845. $typeName = "p5_{$sourceNs[0]}:{$sourceNs[1]}";
  846. if($DBG){echo 'L.' . __LINE__ . ' typeName:';print_r($typeName);echo "\n";}
  847. $updateElementName = "UpdateNs{$nsInd}";
  848. $geomCoordsUpdateXpath = "//wfs:Value/*/gml:outerBoundaryIs/gml:LinearRing/gml:coordinates";
  849. $geomCoordsInsertXpath = "//*/gml:outerBoundaryIs/gml:LinearRing/gml:coordinates";
  850. $acl = $this->getAclFromTypeName($typeName);
  851. $geomType = $acl->getGeomFieldType($theGeomField);
  852. if ('polygon' == $geomType) {
  853. $geomCoordsUpdateXpath = ".//wfs:Value/*/gml:outerBoundaryIs/gml:LinearRing/gml:coordinates";
  854. $geomCoordsUpdateXpath = "((<xsl:value-of select=\"{$geomCoordsUpdateXpath}\"/>))";
  855. $geomCoordsInsertXpath = ".//*/gml:outerBoundaryIs/gml:LinearRing/gml:coordinates";
  856. $geomCoordsInsertXpath = "((<xsl:value-of select=\"{$geomCoordsInsertXpath}\"/>))";
  857. } else if ('linestring' == $geomType) {
  858. $geomCoordsUpdateXpath = ".//wfs:Value/*/gml:coordinates";
  859. $geomCoordsUpdateXpath = "(<xsl:value-of select=\"{$geomCoordsUpdateXpath}\"/>)";
  860. $geomCoordsInsertXpath = ".//*/gml:coordinates";
  861. $geomCoordsInsertXpath = "(<xsl:value-of select=\"{$geomCoordsInsertXpath}\"/>)";
  862. } else if ('point' == $geomType) {
  863. $geomCoordsUpdateXpath = ".//wfs:Value/*/gml:coordinates";
  864. $geomCoordsUpdateXpath = "(<xsl:value-of select=\"{$geomCoordsUpdateXpath}\"/>)";
  865. $geomCoordsInsertXpath = ".//*/gml:coordinates";
  866. $geomCoordsInsertXpath = "(<xsl:value-of select=\"{$geomCoordsInsertXpath}\"/>)";
  867. }
  868. $actionXsd = <<<EOF
  869. <xsl:when test="@typeName = '{$typeName}'">
  870. <xsl:element name="{$updateElementName}">
  871. <xsl:attribute name="typeName"><xsl:value-of select="@typeName" /></xsl:attribute>
  872. <xsl:attribute name="featureId"><xsl:value-of select="ogc:Filter/ogc:FeatureId/@fid" /></xsl:attribute>
  873. <xsl:for-each select="wfs:Property">
  874. <xsl:element name="{wfs:Name}">
  875. <xsl:choose>
  876. <xsl:when test="wfs:Name = '{$theGeomField}'"><xsl:value-of select="local-name(//wfs:Value/*[1])"/>{$geomCoordsUpdateXpath}</xsl:when>
  877. <xsl:otherwise><xsl:value-of select="wfs:Value"/></xsl:otherwise>
  878. </xsl:choose>
  879. </xsl:element>
  880. </xsl:for-each>
  881. </xsl:element>
  882. </xsl:when>
  883. EOF;
  884. $updateActionsXsd[] = $actionXsd;
  885. $typeName = "{$sourceNs[1]}";//"p5_{$sourceNs[0]}:{$sourceNs[1]}";
  886. $insertElementName = "InsertNs{$nsInd}";
  887. $actionXsd = <<<EOF
  888. <xsl:when test="local-name() = '{$typeName}'">
  889. <xsl:element name="{$insertElementName}">
  890. <xsl:attribute name="typeName"><xsl:value-of select="local-name()" /></xsl:attribute>
  891. <xsl:attribute name="typeNsUri"><xsl:value-of select="namespace-uri()" /></xsl:attribute>
  892. <xsl:for-each select="*">
  893. <xsl:element name="{local-name()}">
  894. <xsl:choose>
  895. <xsl:when test="local-name() = '{$theGeomField}'"><xsl:value-of select="local-name(*[1])"/>{$geomCoordsInsertXpath}</xsl:when>
  896. <xsl:otherwise><xsl:value-of select="."/></xsl:otherwise>
  897. </xsl:choose>
  898. </xsl:element>
  899. </xsl:for-each>
  900. </xsl:element>
  901. </xsl:when>
  902. EOF;
  903. $insertActionsXsd[] = $actionXsd;
  904. $deleteElementName = "DeleteNs{$nsInd}";
  905. $typeName = "p5_{$sourceNs[0]}:{$sourceNs[1]}";
  906. $actionXsd = <<<EOF
  907. <xsl:when test="@typeName = '{$typeName}'">
  908. <xsl:variable name="typeName" select="@typeName" />
  909. <xsl:for-each select="ogc:Filter/ogc:FeatureId">
  910. <xsl:element name="{$deleteElementName}">
  911. <xsl:attribute name="typeName"><xsl:value-of select="\$typeName" /></xsl:attribute>
  912. <xsl:attribute name="featureId"><xsl:value-of select="@fid" /></xsl:attribute>
  913. </xsl:element>
  914. </xsl:for-each>
  915. </xsl:when>
  916. EOF;
  917. $deleteActionsXsd[] = $actionXsd;
  918. }
  919. if (!empty($updateActionsXsd)) {
  920. $updateActionsXsd = implode("\n", $updateActionsXsd);
  921. $updateActionsXsd = <<<EOF
  922. <xsl:choose>
  923. {$updateActionsXsd}
  924. </xsl:choose>
  925. EOF;
  926. } else {
  927. $updateActionsXsd = '';
  928. }
  929. if (!empty($insertActionsXsd)) {
  930. $insertActionsXsd = implode("\n", $insertActionsXsd);
  931. $insertActionsXsd = <<<EOF
  932. <xsl:choose>
  933. {$insertActionsXsd}
  934. </xsl:choose>
  935. EOF;
  936. } else {
  937. $insertActionsXsd = '';
  938. }
  939. if (!empty($deleteActionsXsd)) {
  940. $deleteActionsXsd = implode("\n", $deleteActionsXsd);
  941. $deleteActionsXsd = <<<EOF
  942. <xsl:choose>
  943. {$deleteActionsXsd}
  944. </xsl:choose>
  945. EOF;
  946. } else {
  947. $deleteActionsXsd = '';
  948. }
  949. $convertTransactionXslString = '<?xml version="1.0"?>';
  950. $convertTransactionXslString .= <<<EOF
  951. <xsl:transform version="1.0"
  952. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  953. xmlns:wfs="http://www.opengis.net/wfs"
  954. xmlns:ogc="http://www.opengis.net/ogc"
  955. xmlns:gml="http://www.opengis.net/gml">
  956. <xsl:template match="/">
  957. <xsl:for-each select="wfs:Transaction">
  958. <Transaction>
  959. <xsl:attribute name="version"><xsl:value-of select="@version" /></xsl:attribute>
  960. <xsl:attribute name="service"><xsl:value-of select="@service" /></xsl:attribute>
  961. <xsl:for-each select="wfs:Update">
  962. {$updateActionsXsd}
  963. </xsl:for-each>
  964. <xsl:for-each select="wfs:Insert/*">
  965. {$insertActionsXsd}
  966. </xsl:for-each>
  967. <xsl:for-each select="wfs:Delete">
  968. {$deleteActionsXsd}
  969. </xsl:for-each>
  970. <!-- TODO: Native -->
  971. </Transaction>
  972. </xsl:for-each>
  973. </xsl:template>
  974. </xsl:transform>
  975. EOF;
  976. if($DBG){echo 'L.' . __LINE__ . ' $convertTransactionXslString:' . $convertTransactionXslString . "\n";}
  977. $requestXml = new DOMDocument();
  978. $requestXml->loadXml($requestXmlString);
  979. $convertTransactionXsl = new DOMDocument();
  980. $convertTransactionXsl->loadXml($convertTransactionXslString);
  981. $proc = new XSLTProcessor();
  982. $proc->importStylesheet($convertTransactionXsl);
  983. return $proc->transformToXML($requestXml);
  984. }
  985. public function _validateConvertedTransactionXml($convertedTransaction, $sourceNsList) {
  986. $DBG = (V::get('DBG_XSD', '', $_GET) > 0);// TODO: Profiler
  987. if($DBG){echo 'L.' . __LINE__ . ' sourceNsList:';print_r($sourceNsList);echo "\n";}
  988. $dom = new DOMDocument('1.0', 'utf-8');
  989. $dom->formatOutput = true;
  990. $dom->preserveWhiteSpace = false;
  991. $rootNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:schema');
  992. $dom->appendChild($rootNode);
  993. $rootNode->setAttribute('elementFormDefault', 'qualified');
  994. $rootNode->setAttribute('version', '1.0');
  995. {// <xsd:element name="Transaction" type="TransactionType">
  996. $elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
  997. $rootNode->appendChild($elNode);
  998. $elNode->setAttribute('name', 'Transaction');
  999. $elNode->setAttribute('type', 'TransactionType');
  1000. $cTypeNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:complexType');
  1001. $rootNode->appendChild($cTypeNode);
  1002. $cTypeNode->setAttribute('name', 'TransactionType');
  1003. $seqNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:sequence');
  1004. $cTypeNode->appendChild($seqNode);
  1005. $choiceNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:choice');
  1006. $seqNode->appendChild($choiceNode);
  1007. $choiceNode->setAttribute('minOccurs', '0');
  1008. $choiceNode->setAttribute('maxOccurs', 'unbounded');
  1009. // <!-- <xsd:element ref="Update"/> -->
  1010. foreach ($sourceNsList as $nsInd => $sourceNs) {
  1011. $typeName = "p5_{$sourceNs[0]}:{$sourceNs[1]}";
  1012. $updateElementName = "UpdateNs{$nsInd}";
  1013. $updateElementType = "UpdateNs{$nsInd}ElementType";
  1014. $updateElemNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
  1015. $choiceNode->appendChild($updateElemNode);
  1016. $updateElemNode->setAttribute('name', $updateElementName);
  1017. $updateElemNode->setAttribute('type', $updateElementType);
  1018. }
  1019. // <!-- <xsd:element ref="Insert"/> -->
  1020. foreach ($sourceNsList as $nsInd => $sourceNs) {
  1021. $typeName = "p5_{$sourceNs[0]}:{$sourceNs[1]}";
  1022. $insertElementName = "InsertNs{$nsInd}";
  1023. $insertElementType = "InsertNs{$nsInd}ElementType";
  1024. $insertElemNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
  1025. $choiceNode->appendChild($insertElemNode);
  1026. $insertElemNode->setAttribute('name', $insertElementName);
  1027. $insertElemNode->setAttribute('type', $insertElementType);
  1028. }
  1029. // <!-- <xsd:element ref="Delete"/> -->
  1030. foreach ($sourceNsList as $nsInd => $sourceNs) {
  1031. $typeName = "p5_{$sourceNs[0]}:{$sourceNs[1]}";
  1032. $deleteElementName = "DeleteNs{$nsInd}";
  1033. $deleteElementType = "DeleteNs{$nsInd}ElementType";
  1034. $deleteElemNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
  1035. $choiceNode->appendChild($deleteElemNode);
  1036. $deleteElemNode->setAttribute('name', $deleteElementName);
  1037. $deleteElemNode->setAttribute('type', $deleteElementType);
  1038. }
  1039. // <!-- <xsd:element ref="Native"/> -->
  1040. $attrNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:attribute');
  1041. $cTypeNode->appendChild($attrNode);
  1042. $attrNode->setAttribute('name', 'version');
  1043. $attrNode->setAttribute('type', 'xsd:string');
  1044. $attrNode->setAttribute('use', 'required');
  1045. $attrNode->setAttribute('fixed', '1.0.0');
  1046. $attrNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:attribute');
  1047. $cTypeNode->appendChild($attrNode);
  1048. $attrNode->setAttribute('name', 'service');
  1049. $attrNode->setAttribute('type', 'xsd:string');
  1050. $attrNode->setAttribute('use', 'required');
  1051. $attrNode->setAttribute('fixed', 'WFS');
  1052. }
  1053. foreach ($sourceNsList as $nsInd => $sourceNs) {
  1054. $transactionTypesList = array();
  1055. $transactionTypesList[] = 'Update';
  1056. $transactionTypesList[] = 'Insert';
  1057. foreach ($transactionTypesList as $transactionType) {
  1058. $typeName = "p5_{$sourceNs[0]}:{$sourceNs[1]}";
  1059. if($DBG){echo 'L.' . __LINE__ . ' TODO: get acl typeName:';print_r($typeName);echo "\n";}
  1060. $acl = $this->getAclFromTypeName($typeName);
  1061. $updateElementName = "{$transactionType}Ns{$nsInd}";
  1062. $updateElementType = "{$transactionType}Ns{$nsInd}ElementType";
  1063. /*
  1064. <xsd:complexType name="{$updateElementType}">
  1065. <xsd:sequence>
  1066. <xsd:element name="PARENT_ID" minOccurs="0" maxOccurs="1" type="xsd:integer" />
  1067. </xsd:sequence>
  1068. */
  1069. $updateTypeNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:complexType');
  1070. $rootNode->appendChild($updateTypeNode);
  1071. $updateTypeNode->setAttribute('name', $updateElementType);
  1072. {
  1073. $seqNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:all');
  1074. $updateTypeNode->appendChild($seqNode);
  1075. {
  1076. $pKeyField = $acl->getPrimaryKeyField();
  1077. $fldList = $this->_getFieldListFromAcl($acl);
  1078. // fields without geometry fields
  1079. foreach ($fldList as $fldName) {
  1080. if ($acl->isGeomField($fldName)) continue;
  1081. $elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
  1082. $seqNode->appendChild($elNode);
  1083. $elNode->setAttribute('name', $fldName);
  1084. $minOccurs = 0;
  1085. if ($pKeyField == $fldName) {
  1086. $minOccurs = '1';
  1087. } else {
  1088. $minOccurs = '0';
  1089. }
  1090. $elNode->setAttribute('minOccurs', $minOccurs);
  1091. $fldType = null;
  1092. if ($acl->isIntegerField($fldName)) {
  1093. $fldType = 'xsd:integer';
  1094. }
  1095. else if ($acl->isDecimalField($fldName)) {
  1096. $fldType = 'xsd:decimal';
  1097. }
  1098. else if ($acl->isDateField($fldName)) {
  1099. $fldType = 'xsd:date';
  1100. }
  1101. else if ($acl->isDateTimeField($fldName)) {
  1102. // $fldType = 'xsd:dateTime';
  1103. $fldType = null;// 'xsd:string';
  1104. $patternDataTime = "(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2})(:(\d{2}))?";
  1105. // <xsd:element name="..." minOccurs="0" nillable="true">
  1106. // <xsd:simpleType>
  1107. // <xsd:restriction base="xsd:string">
  1108. // <xsd:pattern value="[a-zA-Z]+\(\((\-?\d+\.?\d*,\-?\d+\.?\d*)( \-?\d+\.?\d*,\-?\d+\.?\d*)+\)\)"/>
  1109. // </xsd:restriction>
  1110. // </xsd:simpleType>
  1111. // </xsd:element>
  1112. $simpleTypeNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:simpleType');
  1113. $restrictionNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:restriction');
  1114. $patternNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:pattern');
  1115. $restrictionNode->setAttribute('base', 'xsd:string');
  1116. $patternNode->setAttribute('value', $patternDataTime);
  1117. $restrictionNode->appendChild($patternNode);
  1118. $simpleTypeNode->appendChild($restrictionNode);
  1119. $elNode->appendChild($simpleTypeNode);
  1120. // continue;// TODO: ? below added nillable = true, minOccurs = 0, type = $fldType
  1121. }
  1122. else if ($acl->isBinaryField($fldName)) {
  1123. $fldType = 'xsd:base64Binary';
  1124. }
  1125. else {
  1126. $fldType = 'xsd:string';
  1127. }
  1128. if ($fldType) $elNode->setAttribute('type', $fldType);
  1129. $elNode->setAttribute('nillable', 'true');
  1130. $elNode->setAttribute('minOccurs', '0');
  1131. }
  1132. // only geometry fields
  1133. foreach ($fldList as $fldName) {
  1134. if (!$acl->isGeomField($fldName)) continue;
  1135. $elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
  1136. $seqNode->appendChild($elNode);
  1137. $elNode->setAttribute('name', $fldName);
  1138. $minOccurs = 0;
  1139. if ($pKeyField == $fldName) {
  1140. $minOccurs = '1';
  1141. } else {
  1142. $minOccurs = '0';
  1143. }
  1144. $elNode->setAttribute('minOccurs', $minOccurs);
  1145. if ($acl->isGeomField($fldName)) {
  1146. //$fldType = 'gml:GeometryPropertyType';
  1147. // TODO: use geom types from gml to wkt
  1148. // TODO: pattern wg atrybutów gml:coordinates decimal="." cs="," ts=" "
  1149. $patternWkt = '';// TODO: error if empty - unsupported geom type
  1150. $patternNum = '\-?\d+\.?\d*';
  1151. $patternPoint = $patternNum . ',' . $patternNum;
  1152. $patternPoints = '(' . $patternPoint . ')( ' . $patternPoint . ')+';
  1153. $geomType = $acl->getGeomFieldType($fldName);
  1154. if ('polygon' == $geomType) {
  1155. // [a-zA-Z]+\(\((\-?\d+\.?\d*,\-?\d+\.?\d*)( (\-?\d+\.?\d*,\-?\d+\.?\d*))+\)\)
  1156. $patternWkt = '[a-zA-Z]+\(\(' . $patternPoints . '\)\)';
  1157. } else if ('linestring' == $geomType) {
  1158. // [a-zA-Z]+\((\-?\d+\.?\d*,\-?\d+\.?\d*)( (\-?\d+\.?\d*,\-?\d+\.?\d*))+\)
  1159. $patternWkt = '[a-zA-Z]+\(' . $patternPoints . '\)';
  1160. } else if ('point' == $geomType) {
  1161. // [a-zA-Z]+\(\-?\d\.?\d*,\-?\d\.?\d*\)
  1162. $patternWkt = '[a-zA-Z]+\(' . $patternPoint . '\)';
  1163. }
  1164. $simpleTypeNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:simpleType');
  1165. $restrictionNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:restriction');
  1166. $patternNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:pattern');
  1167. $restrictionNode->setAttribute('base', 'xsd:string');
  1168. $patternNode->setAttribute('value', $patternWkt);
  1169. $restrictionNode->appendChild($patternNode);
  1170. $simpleTypeNode->appendChild($restrictionNode);
  1171. $elNode->appendChild($simpleTypeNode);
  1172. }
  1173. $elNode->setAttribute('nillable', 'true');
  1174. $elNode->setAttribute('minOccurs', '0');
  1175. }
  1176. }
  1177. }
  1178. $attrNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:attribute');
  1179. $updateTypeNode->appendChild($attrNode);
  1180. $attrNode->setAttribute('name', 'typeName');
  1181. $attrNode->setAttribute('type', 'xsd:token');
  1182. $attrNode->setAttribute('use', 'required');
  1183. if ($transactionType == 'Insert') {
  1184. $attrNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:attribute');
  1185. $updateTypeNode->appendChild($attrNode);
  1186. $attrNode->setAttribute('name', 'typeNsUri');
  1187. $attrNode->setAttribute('type', 'xsd:anyURI');
  1188. $attrNode->setAttribute('use', 'required');
  1189. }
  1190. if ($transactionType == 'Update') {
  1191. $attrNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:attribute');
  1192. $updateTypeNode->appendChild($attrNode);
  1193. $attrNode->setAttribute('name', 'featureId');
  1194. $attrNode->setAttribute('use', 'required');
  1195. $sTypeNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:simpleType');
  1196. $attrNode->appendChild($sTypeNode);
  1197. $resNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:restriction');
  1198. $sTypeNode->appendChild($resNode);
  1199. $resNode->setAttribute('base', 'xsd:string');
  1200. $patternNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:pattern');
  1201. $resNode->appendChild($patternNode);
  1202. $patternNode->setAttribute('value', '[a-zA-Z_][a-zA-Z0-9_]*\.[0-9]*');
  1203. }
  1204. }
  1205. {// 'Delete'
  1206. $typeName = "p5_{$sourceNs[0]}:{$sourceNs[1]}";
  1207. $acl = $this->getAclFromTypeName($typeName);
  1208. $deleteElementType = "DeleteNs{$nsInd}ElementType";
  1209. $deleteTypeNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:complexType');
  1210. $rootNode->appendChild($deleteTypeNode);
  1211. $deleteTypeNode->setAttribute('name', $deleteElementType);
  1212. /* <xsd:attribute name="typeName" type="xsd:token" use="required"/> */
  1213. $attrNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:attribute');
  1214. $deleteTypeNode->appendChild($attrNode);
  1215. $attrNode->setAttribute('name', 'typeName');
  1216. $attrNode->setAttribute('type', 'xsd:token');
  1217. $attrNode->setAttribute('use', 'required');
  1218. /* <xsd:attribute name="featureId" use="required"> */
  1219. $attrNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:attribute');
  1220. $deleteTypeNode->appendChild($attrNode);
  1221. $attrNode->setAttribute('name', 'featureId');
  1222. $attrNode->setAttribute('use', 'required');
  1223. $sTypeNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:simpleType');
  1224. $attrNode->appendChild($sTypeNode);
  1225. $resNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:restriction');
  1226. $sTypeNode->appendChild($resNode);
  1227. $resNode->setAttribute('base', 'xsd:string');
  1228. $patternNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:pattern');
  1229. $resNode->appendChild($patternNode);
  1230. $patternNode->setAttribute('value', '[a-zA-Z_][a-zA-Z0-9_]*\.[0-9]*');
  1231. }
  1232. }
  1233. $validateConvertedTransactionXsdString = $dom->saveXml();
  1234. if($DBG){echo 'L.' . __LINE__ . ' $validateConvertedTransactionXsdString:';print_r($validateConvertedTransactionXsdString);echo "\n";}
  1235. $reqXml = new DOMDocument();
  1236. $reqXml->loadXml($convertedTransaction);
  1237. // TODO: fetch PHP Warning: DOMDocument::schemaValidateSource(): Element 'PARENT_ID': 'abc' is not a valid value of the atomic type 'xs:integer'.
  1238. return $reqXml->schemaValidateSource($validateConvertedTransactionXsdString);
  1239. }
  1240. public function _getDescribeFeatureType($nsPrefix, $type, $simple = true) {
  1241. return $this->_getDescribeFeatureTypes(array(array($nsPrefix, $type)), $simple);
  1242. }
  1243. public function _parseDescribeFeatureTypeRequest($reqContent, $simple = true) {
  1244. $parserXml = xml_parser_create();
  1245. xml_parser_set_option($parserXml, XML_OPTION_CASE_FOLDING, 0);
  1246. xml_parser_set_option($parserXml, XML_OPTION_SKIP_WHITE, 1);
  1247. if (0 == xml_parse_into_struct($parserXml, $reqContent, $tags)) {
  1248. throw new Exception("Error parsing xml");
  1249. }
  1250. xml_parser_free($parserXml);
  1251. if (empty($tags)) {
  1252. throw new Exception("Empty structure from request");
  1253. }
  1254. $rootTagName = V::get('tag', '', $tags[0]);
  1255. if ('DescribeFeatureType' != $rootTagName) {
  1256. throw new Api_WfsException("Wrong xml root tag '{$rootTagName}' #" . __LINE__, 501);
  1257. }
  1258. $requestXmlTags = $tags;
  1259. $DBG = (V::get('DBG_XML', '', $_GET) > 0);// TODO: Profiler
  1260. $rootTagName = V::get('tag', '', $requestXmlTags[0]);
  1261. if ('DescribeFeatureType' != $rootTagName) {
  1262. throw new Exception("Parse Request xml error #" . __LINE__);
  1263. }
  1264. /*[1] => Array(
  1265. [tag] => TypeName
  1266. [type] => complete
  1267. [level] => 2
  1268. [value] => p5_default_db:Rozdzielcza_rurociag_wsg84)
  1269. */
  1270. $typeNames = array();
  1271. $totalTypes = count($requestXmlTags) - 1;
  1272. for ($i = 1; $i < $totalTypes; $i++) {
  1273. if($DBG){echo "TAG[{$i}]:" . json_encode($requestXmlTags[$i]) . "\n";}
  1274. $typeNames[] = explode(':', $requestXmlTags[$i]['value'], 2);
  1275. }
  1276. //echo "typeNames: " . json_encode($typeNames) . "\n";
  1277. return $this->_getDescribeFeatureTypes($typeNames, $simple);
  1278. }
  1279. public function _getDescribeFeatureAllTypes($simple = true) {
  1280. $db = DB::getDB();
  1281. $idDefaultDB = $db->_zasob_id;
  1282. $tblsAcl = $this->_getTableAclList();
  1283. foreach ($tblsAcl as $tblAcl) {
  1284. $dataSourceName = 'default_db';// TODO: getSourceName
  1285. $tblName = $tblAcl->getName();
  1286. $typeNames[] = array("p5_{$dataSourceName}", $tblName);
  1287. }
  1288. $typeNames[] = array("p5_objects", 'File');
  1289. return $this->_getDescribeFeatureTypes($typeNames, $simple);
  1290. }
  1291. // @param $typeNames = array( array( $nsPrefix, $type ) )
  1292. public function _getDescribeFeatureTypes($typeNames, $simple = true) {
  1293. if (empty($typeNames)) throw new HttpException("Feature Type Names not defined", 400);
  1294. $this->DBG("types:" . json_encode($typeNames), __LINE__, __FUNCTION__, __CLASS__);
  1295. $baseNsUri = Api_WfsNs::getBaseWfsUri();
  1296. $rootWfsNs = 'p5';
  1297. $rootWfsNsUri = "{$baseNsUri}";
  1298. $featureTypeUri = Api_WfsNs::getBaseWfsUri() . "?SERVICE=WFS&VERSION=1.0.0&REQUEST=DescribeFeatureType";
  1299. header('Content-type: application/xml');
  1300. // <xsd:import namespace="http://www.opengis.net/gml" schemaLocation="http://webgis.regione.sardegna.it:80/geoserver/schemas/gml/2.1.2/feature.xsd"/>
  1301. // <xsd:element name="{type}" substitutionGroup="gml:_Feature" type="dbu:{typeName}"/>
  1302. $dom = new DOMDocument('1.0', 'utf-8');
  1303. $dom->formatOutput = true;
  1304. $dom->preserveWhiteSpace = false;
  1305. $rootNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:schema');
  1306. $dom->appendChild($rootNode);
  1307. $rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:gml', 'http://www.opengis.net/gml');
  1308. foreach (Api_WfsNs::getNsList() as $uri => $prefix) {
  1309. $rootNode->setAttributeNS('http://www.w3.org/2000/xmlns/', "xmlns:{$prefix}", $uri);
  1310. }
  1311. $rootNode->setAttribute('elementFormDefault', 'qualified');
  1312. // $rootNode->setAttribute('targetNamespace', Api_WfsNs::getNsUri('p5_default_db'));// TODO:? what targetNamespace if showing types from p5_objects and p5_default_db
  1313. {// <xsd:import namespace="http://www.opengis.net/gml" schemaLocation="...../gml/2.1.2/feature.xsd"/>
  1314. $elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:import');
  1315. $rootNode->appendChild($elNode);
  1316. $elNode->setAttribute('namespace', "http://www.opengis.net/gml");
  1317. $elNode->setAttribute('schemaLocation', Request::getPathUri() . "schema/gml/2.1.2/feature.xsd");
  1318. }
  1319. foreach ($typeNames as $typeNameEx) {
  1320. $nsPrefix = $typeNameEx[0];
  1321. $type = $typeNameEx[1];
  1322. $typeName = "{$nsPrefix}:{$type}";
  1323. $acl = $this->getAclFromTypeName($typeName);
  1324. $rootNode->setAttribute('targetNamespace', Api_WfsNs::getNsUri($acl->getSourceName()));
  1325. $typeName = $type . 'Type';
  1326. $fldList = $this->_getFieldListFromAcl($acl);
  1327. DBG::_('DBG_XSD', '>1', "field list", $fldList, __CLASS__, __FUNCTION__, __LINE__);
  1328. $cTypeNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:complexType');
  1329. $rootNode->appendChild($cTypeNode);
  1330. $cTypeNode->setAttribute('name', $typeName);
  1331. if (!$simple) $cTypeNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:web_link", Request::getPathUri() . "index.php?_route=ViewTableAjax&namespace=" . $acl->getNamespace());
  1332. $cConNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:complexContent');
  1333. $cTypeNode->appendChild($cConNode);
  1334. $extNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:extension');
  1335. $cConNode->appendChild($extNode);
  1336. $extNode->setAttribute('base', 'gml:AbstractFeatureType');
  1337. $seqNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:sequence');
  1338. $extNode->appendChild($seqNode);
  1339. // <xsd:element maxOccurs="1" minOccurs="0" name="{$fldName}" nillable="true" type="xsd:integer"/>
  1340. $pKeyField = $acl->getPrimaryKeyField();
  1341. $p5Attributes = ($simple)? array() : $acl->getAttributesFromZasoby();
  1342. foreach ($fldList as $fldName) {
  1343. $elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
  1344. $seqNode->appendChild($elNode);
  1345. $minOccurs = 0;
  1346. if ($pKeyField == $fldName) {
  1347. $minOccurs = '1';
  1348. } else {
  1349. $minOccurs = '0';
  1350. }
  1351. $elNode->setAttribute('minOccurs', $minOccurs);
  1352. $elNode->setAttribute('maxOccurs', '1');
  1353. $fldType = $acl->getXsdFieldType($fldName);
  1354. if (!$simple && $acl->isEnumerationField($fldName)) {
  1355. $fldType = "{$nsPrefix}:{$fldName}Type";
  1356. }
  1357. if ('ref:' == substr($fldType, 0, 4)) {
  1358. $elNode->setAttribute('ref', substr($fldType, 4));
  1359. $elNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:name", $fldName);
  1360. } else if ('local_ref:' == substr($fldType, 0, 10)) {
  1361. $elNode->setAttribute('type', "{$fldName}Type");
  1362. $elNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:name", $fldName);
  1363. } else if ('alias_ref:' == substr($fldType, 0, 10)) {
  1364. $elNode->setAttribute('ref', "p5_" . $acl->getSourceName() . ":{$fldName}");
  1365. $elNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:name", $fldName);
  1366. } else {
  1367. $elNode->setAttribute('name', $fldName);
  1368. $elNode->setAttribute('type', $fldType);
  1369. $elNode->setAttribute('nillable', 'true');// nillable not allowed in ref
  1370. }
  1371. if (!$simple) {
  1372. if (!empty($p5Attributes[$fldName])) {
  1373. $p5attrs = $p5Attributes[$fldName];
  1374. if (!empty($p5attrs['id_zasob'])) $elNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:id_zasob", $p5attrs['id_zasob']);
  1375. if (!empty($p5attrs['label'])) $elNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:label", $p5attrs['label']);
  1376. if (!empty($p5attrs['description'])) $elNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:description", $p5attrs['description']);
  1377. }
  1378. if ($acl->canWriteField($fldName)) $elNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:allow_write", "true");
  1379. if ($acl->canCreateField($fldName)) $elNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:allow_create", "true");
  1380. if (!$acl->canReadField($fldName)) $elNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:allow_read", "false");
  1381. }
  1382. }
  1383. $elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
  1384. $rootNode->appendChild($elNode);
  1385. $elNode->setAttribute('name', $type);
  1386. $elNode->setAttribute('type', $nsPrefix . ':' . $typeName);// TODO: $acl->getSourceName() != $nsPrefix
  1387. $elNode->setAttribute('substitutionGroup', 'gml:_Feature');// gml:AbstractFeature in gml 3
  1388. foreach ($fldList as $fldName) {
  1389. $fldType = $acl->getXsdFieldType($fldName);
  1390. if ('alias_ref:' == substr($fldType, 0, 10)) {
  1391. $localRefType = substr($fldType, 10);
  1392. // <xsd:element name="{$fldName}" ref="{$localRefType}">
  1393. $ctNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
  1394. $rootNode->appendChild($ctNode);
  1395. $ctNode->setAttribute('name', $fldName);
  1396. $ctNode->setAttribute('type', $localRefType);
  1397. } else if ('local_ref:' == substr($fldType, 0, 10)) {
  1398. $localRefType = substr($fldType, 10);
  1399. // <xsd:complexType name="produkt_Type">
  1400. // <xsd:sequence>
  1401. // <xsd:element name="idProd" type="xsd:integer" />
  1402. // <xsd:element name="nazwa" type="xsd:string" />
  1403. // <xsd:element name="cena" type="xsd:decimal" />
  1404. // </xsd:sequence>
  1405. // </xsd:complexType>
  1406. $ctNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:complexType');
  1407. $rootNode->appendChild($ctNode);
  1408. $ctNode->setAttribute('name', "{$fldName}Type");
  1409. $seqNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:sequence');
  1410. $ctNode->appendChild($seqNode);
  1411. $elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
  1412. $seqNode->appendChild($elNode);
  1413. $elNode->setAttribute('name', "test_id");
  1414. $elNode->setAttribute('type', "xsd:integer");
  1415. $elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
  1416. $seqNode->appendChild($elNode);
  1417. $elNode->setAttribute('name', "test_opis");
  1418. $elNode->setAttribute('type', "xsd:string");
  1419. $elNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:element');
  1420. $seqNode->appendChild($elNode);
  1421. $elNode->setAttribute('name', "test_decimal");
  1422. $elNode->setAttribute('type', "xsd:decimal");
  1423. }
  1424. }
  1425. if (!$simple) {
  1426. foreach ($fldList as $fldName) {
  1427. if ($acl->isEnumerationField($fldName)) {
  1428. $enum = $acl->getEnumerations($fldName);
  1429. $stNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:simpleType');
  1430. $stNode->setAttribute('name', "{$fldName}Type");//"{$nsPrefix}:{$fldName}Type");
  1431. $rootNode->appendChild($stNode);
  1432. $resNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:restriction');
  1433. $stNode->appendChild($resNode);
  1434. $resNode->setAttribute('base', 'xsd:string');
  1435. // TODO: if (!empty($p5Attributes[$fldName]['valuesMap'])) -> show only this values
  1436. foreach ($enum as $val => $label) {
  1437. $enumNode = $dom->createElementNS('http://www.w3.org/2001/XMLSchema', 'xsd:enumeration');
  1438. $resNode->appendChild($enumNode);
  1439. $enumNode->setAttribute('value', "{$val}");
  1440. if (!empty($p5Attributes[$fldName]['valuesMap'][$val])) {
  1441. $enumNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:label", $p5Attributes[$fldName]['valuesMap'][$val]);
  1442. }
  1443. }
  1444. }
  1445. }
  1446. }
  1447. }
  1448. return $dom->saveXML();
  1449. }
  1450. public function _getTableAclList() {// Use only Tables from default_db
  1451. $tblAclList = array();
  1452. $db = DB::getDB();
  1453. $idDefaultDB = $db->_zasob_id;
  1454. $fullTblAclList = $this->_usrAcl->getTablesAcl();
  1455. foreach ($fullTblAclList as $tblAcl) {
  1456. $dataSourceName = 'default_db';// TODO: getSourceName
  1457. $tblName = $tblAcl->getName();
  1458. if ($idDefaultDB != $tblAcl->getDB()) {// hide non default_db tables
  1459. continue;
  1460. }
  1461. try {
  1462. $acl = $this->getAclFromTypeName($typeName = "p5_{$dataSourceName}:{$tblName}");
  1463. } catch (Exception $e) {
  1464. // echo "Error for table({$tblName}): " . $e->getMessage() . "\n";
  1465. }
  1466. if (!$acl) {
  1467. // TODO: error log msg
  1468. continue;
  1469. }
  1470. $tblAclList[] = $tblAcl;
  1471. }
  1472. return $tblAclList;
  1473. }
  1474. public function _getFieldListFromAcl($acl) {
  1475. $fldList = $acl->getRealFieldListByIdZasob();
  1476. return $fldList;
  1477. }
  1478. public function setLogger($logger) {
  1479. $this->_logger = $logger;
  1480. }
  1481. public function DBG($reqLog, $lineNr = null, $funName = null, $className = null) {
  1482. if (!$this->_logger) return;
  1483. $this->_logger->DBG($reqLog, $lineNr, $funName, $className);
  1484. }
  1485. public function convertOgcFilterFromRequestBody($requestOgcFilter) {
  1486. $ogcFilter = '';
  1487. if (empty($requestOgcFilter)) return '';
  1488. {
  1489. $convertOgcFilterXslString .= <<<EOF
  1490. <xsl:transform version="1.0"
  1491. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  1492. xmlns:wfs="http://www.opengis.net/wfs"
  1493. xmlns:ogc="http://www.opengis.net/ogc"
  1494. xmlns:gml="http://www.opengis.net/gml">
  1495. <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
  1496. <xsl:template match="/">
  1497. <xsl:for-each select="//*[local-name() = 'GetFeature']">
  1498. <xsl:copy-of select="ogc:Filter"/>
  1499. </xsl:for-each>
  1500. </xsl:template>
  1501. </xsl:transform>
  1502. EOF;
  1503. DBG::_('DBG_XML', '>2', "convertOgcFilterXslString", $convertOgcFilterXslString, __CLASS__, __FUNCTION__, __LINE__);
  1504. $convertTransactionXsl = new DOMDocument();
  1505. $convertTransactionXsl->loadXml($convertOgcFilterXslString);
  1506. $requestXml = new DOMDocument();
  1507. $requestXml->loadXml($requestOgcFilter);
  1508. $proc = new XSLTProcessor();
  1509. $proc->importStylesheet($convertTransactionXsl);
  1510. $ogcFilter = $proc->transformToXML($requestXml);
  1511. DBG::_('DBG_XML', '>2', "ogcFilter", $ogcFilter, __CLASS__, __FUNCTION__, __LINE__);
  1512. }
  1513. return $ogcFilter;
  1514. }
  1515. }