WfsServerBase.php 78 KB

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