WfsServerBase.php 72 KB

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