WfsServerBase.php 71 KB

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