TableAjax.php 105 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651
  1. <?php
  2. Lib::loadClass('ViewAjax');
  3. Lib::loadClass('TableAjaxMap');
  4. Lib::loadClass('Typespecial');
  5. Lib::loadClass('UI');
  6. Lib::loadClass('FoldersConfig');
  7. Lib::loadClass('FileUploader');
  8. Lib::loadClass('UserProfile');
  9. Lib::loadClass('ProcesHelper');
  10. Lib::loadClass('Router');
  11. Lib::loadClass('Route_UrlAction');
  12. Lib::loadClass('Core_AclHelper');
  13. Lib::loadClass('AntAclBase');
  14. // TODO: change all links: MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID={idZasob} to _route=ViewTableAjax&typeName=p5_default_db:{tableName}
  15. class TableAjax extends ViewAjax {
  16. public $_cnf = '';// Column
  17. public $_htmlID = '';
  18. public $_rowFunctions = array();
  19. public $_pageSize = 10;
  20. public $_pageSizes = array();
  21. public $_filterInit = null;
  22. public $_forceFilterInit = null;
  23. public $showProcesInitFiltr = null;
  24. public $showTableTools = null;
  25. public $useUserTableFilter = false;
  26. public $syncUrl = null;
  27. public function __construct($tblAcl) {
  28. $this->_tbl = $tblAcl->getName();
  29. $this->_acl = $tblAcl;
  30. $this->_zasobID = $tblAcl->getID();
  31. $this->_pageSize = 10;
  32. {
  33. UserProfile::load();
  34. $tableAjaxSettings = UserProfile::getTableAjaxSettings();
  35. $this->_pageSize = V::get('pageSize', 10, $tableAjaxSettings, 'int');
  36. }
  37. $this->_pageSizes = array(10, 20, 50, 100);// default page sizes
  38. $this->_filterInit = new stdClass();
  39. $hash = V::get('_hash', '', $_GET);
  40. if ($hash) {
  41. $this->_htmlID = $hash;
  42. $this->_readState();
  43. } else {
  44. $this->_htmlID = $this->generateHtmlID();
  45. $this->_readState();
  46. }
  47. }
  48. public function setSyncUrl($syncUrl) { $this->syncUrl = $syncUrl; }
  49. public function setRootUrl($rootUrl) { $this->rootUrl = $rootUrl; }
  50. private function _hasStateFilterInit() {
  51. return array_key_exists($this->_htmlID, $_SESSION['TableAjax_Cache']) && array_key_exists('_filterInit', $_SESSION['TableAjax_Cache'][$this->_htmlID]);
  52. }
  53. // TODO: read state from cache by key $this->_htmlID
  54. // TODO: load filters and state: table, edit, add, etc.
  55. // TODO: save this data in Workspace 1, 2, 3, etc.
  56. // TODO: default filters in VIEWTABLE_AJAX
  57. // $tbl->setLabel($zasobObj->OPIS);
  58. // $tbl->setFilterInit($filterInit);
  59. // $tbl->addRowFunction('edit');
  60. // $tbl->addRowFunction('hist');
  61. // $tbl->addRowFunction('files');
  62. // $tbl->addRowFunction('cp');
  63. private function _readState() {
  64. if (!array_key_exists('TableAjax_Cache', $_SESSION)) {
  65. $_SESSION['TableAjax_Cache'] = array();
  66. }
  67. //trigger_error("F." . __FUNCTION__ . " (" . (array_key_exists($this->_htmlID, $_SESSION['TableAjax_Cache'])) . ")", E_USER_NOTICE);
  68. //trigger_error("F." . __FUNCTION__ . " (".basename($_SERVER['SCRIPT_FILENAME'])."::_filterInit: " . json_encode($_SESSION['TableAjax_Cache'][$this->_htmlID]['_filterInit']) . ")", E_USER_NOTICE);
  69. if (array_key_exists($this->_htmlID, $_SESSION['TableAjax_Cache'])) {
  70. foreach ($_SESSION['TableAjax_Cache'][$this->_htmlID] as $k => $v) {
  71. //trigger_error("F." . __FUNCTION__ . " key: ({$k})", E_USER_NOTICE);
  72. switch ($k) {
  73. case '_label':
  74. $this->_label = $v;
  75. break;
  76. case '_filterInit':
  77. $this->_filterInit = $v;
  78. break;
  79. case '_rowFunctions':
  80. $this->_rowFunctions = $v;
  81. break;
  82. default:
  83. }
  84. }
  85. }
  86. }
  87. protected function _saveState($key = null) {
  88. if (!array_key_exists('TableAjax_Cache', $_SESSION)) {
  89. $_SESSION['TableAjax_Cache'] = array();
  90. }
  91. if (!array_key_exists($this->_htmlID, $_SESSION['TableAjax_Cache'])) {
  92. $_SESSION['TableAjax_Cache'][$this->_htmlID] = array();
  93. }
  94. if (!$key) {
  95. $_SESSION['TableAjax_Cache'][$this->_htmlID]['_label'] = $this->_label;
  96. $_SESSION['TableAjax_Cache'][$this->_htmlID]['_filterInit'] = $this->_filterInit;
  97. $_SESSION['TableAjax_Cache'][$this->_htmlID]['_rowFunctions'] = $this->_rowFunctions;
  98. } else if ($key == '_label') {
  99. $_SESSION['TableAjax_Cache'][$this->_htmlID]['_label'] = $this->_label;
  100. } else if ($key == '_filterInit') {
  101. $_SESSION['TableAjax_Cache'][$this->_htmlID]['_filterInit'] = $this->_filterInit;
  102. } else if ($key == '_rowFunctions') {
  103. $_SESSION['TableAjax_Cache'][$this->_htmlID]['_rowFunctions'] = $this->_rowFunctions;
  104. }
  105. }
  106. public function setPageSizes($pageSizes) {
  107. $this->_pageSizes = $pageSizes;
  108. }
  109. public function setBackRefFilter($backRefFilter) {
  110. $this->_backRefFilter = $backRefFilter;
  111. }
  112. public function setChildRefFilter($childRefFilter) {
  113. $this->_childRefFilter = $childRefFilter;
  114. }
  115. public function setFilterInit($filterInit) {
  116. if ($this->_hasStateFilterInit()) {
  117. return;
  118. }
  119. $this->_filterInit = (object)$filterInit;
  120. $this->_saveState();
  121. }
  122. /**
  123. * @param array $forceFilterInit
  124. */
  125. public function setForceFilterInit($forceFilterInit) {
  126. $this->_forceFilterInit = (object)$forceFilterInit;
  127. }
  128. private function setFilters($filterInit) {
  129. $this->_filterInit = (object)$filterInit;
  130. $this->_saveState();
  131. }
  132. public function setRowFunctions($functions) {
  133. $this->_rowFunctions = [];
  134. $defaultRowFunction = array();
  135. $defaultRowFunction['edit'] = [ 'href'=>'#EDIT/{0}', 'ico'=>'glyphicon glyphicon-pencil', 'title'=>'Edytuj rekord', 'class' => "btn btn-xs btn-link" ];
  136. $defaultRowFunction['hist'] = [ 'href'=>'#HIST/{0}', 'ico'=>'glyphicon glyphicon-book', 'title'=>'Historia', 'class' => "btn btn-xs btn-link" ];
  137. $defaultRowFunction['files'] = [ 'href'=>'#FILES/{0}', 'ico'=>'glyphicon glyphicon-folder-open', 'title'=>'Pliki', 'class' => "btn btn-xs btn-link" ];
  138. $defaultRowFunction['cp'] = [ 'href'=>'#', 'ico'=>'glyphicon glyphicon-plus-sign', 'title'=>'Kopiuj rekord', 'onclick'=>'return tableAjaxCopy({0});', 'class' => "btn btn-xs btn-link" ];
  139. $defaultRowFunction['msgs'] = [ 'href'=>"index.php?_route=TableMsgs&_task=tableRow&idTable={$this->_zasobID}&idRow={0}", 'ico'=>'glyphicon glyphicon-envelope', 'title'=>'Wiadomości', 'class' => "btn btn-xs btn-link" ];
  140. foreach ($functions as $funName => $params) {
  141. if (true === $params) {
  142. if (array_key_exists($funName, $defaultRowFunction)) {
  143. $this->_rowFunctions[$funName] = $defaultRowFunction[$funName];
  144. } else {
  145. throw new Exception("Row function not defined '{$funName}'");
  146. }
  147. }
  148. if (is_array($params)) {
  149. $this->_rowFunctions[$funName] = $params;
  150. }
  151. }
  152. $this->_saveState('_rowFunctions');
  153. }
  154. public function addRowFunction($funName, $funParams = array()) {
  155. $defaultRowFunction = array();
  156. //$defaultRowFunction['edit'] = '<a href="#EDIT/{0}" class="glyphicon glyphicon-pencil" title="Edytuj rekord"></a>';
  157. //$defaultRowFunction['hist'] = '<a href="#HIST/{0}" class="glyphicon glyphicon-book" title="Historia"></a>';
  158. //$defaultRowFunction['files'] = '<a href="#FILES/{0}" class="glyphicon glyphicon-folder-open" title="Pliki"></a>';
  159. //$defaultRowFunction['cp'] = '<a href="#" class="glyphicon glyphicon-plus-sign" title="Kopiuj rekord" onclick="return tableAjaxCopy({0});"></a>';
  160. $defaultRowFunction['edit'] = [ 'href'=>'#EDIT/{0}', 'ico'=>'glyphicon glyphicon-pencil', 'title'=>'Edytuj rekord', 'class' => "btn btn-xs btn-link" ];
  161. $defaultRowFunction['hist'] = [ 'href'=>'#HIST/{0}', 'ico'=>'glyphicon glyphicon-book', 'title'=>'Historia', 'class' => "btn btn-xs btn-link" ];
  162. $defaultRowFunction['files'] = [ 'href'=>'#FILES/{0}', 'ico'=>'glyphicon glyphicon-folder-open', 'title'=>'Pliki', 'class' => "btn btn-xs btn-link" ];
  163. $defaultRowFunction['cp'] = [ 'href'=>'#', 'ico'=>'glyphicon glyphicon-plus-sign', 'title'=>'Kopiuj rekord', 'onclick'=>'return tableAjaxCopy({0});', 'class' => "btn btn-xs btn-link" ];
  164. $defaultRowFunction['msgs'] = [ 'href'=>"index.php?_route=TableMsgs&_task=tableRow&idTable={$this->_zasobID}&idRow={0}", 'ico'=>'glyphicon glyphicon-envelope', 'title'=>'Wiadomości', 'class' => "btn btn-xs btn-link" ];
  165. if (array_key_exists($funName, $defaultRowFunction)) {
  166. $this->_rowFunctions[$funName] = $defaultRowFunction[$funName];
  167. }
  168. else {
  169. $this->_rowFunctions[$funName] = $funParams;
  170. }
  171. $this->_saveState('_rowFunctions');
  172. }
  173. private function _parseRowFunctions($idRecord = null, $pomin = array(), $showLabel = false) {
  174. $rowFunctions = array();
  175. foreach ($this->_rowFunctions as $kFunName => $vParams) {
  176. if (in_array($kFunName, $pomin)) continue;
  177. //$rowFunctionsOut .= str_replace('{0}', $idRecord, $vUrl);
  178. $attrs = array();
  179. // $defaultRowFunction['cp'] = (object)array('href'=>'#', 'ico'=>'glyphicon glyphicon-plus-sign', 'title'=>'Kopiuj rekord', 'onclick'=>'return tableAjaxCopy({0});');
  180. $label = '';
  181. $ico = '';
  182. foreach ($vParams as $kParamName => $v) {
  183. if ($kParamName == 'ico') {
  184. $ico = '<span class="' . $v . '"></span>';
  185. continue;
  186. }
  187. $attr = $v;
  188. if ($idRecord > 0) {
  189. $attr = str_replace('{0}', $idRecord, $attr);
  190. }
  191. if ($showLabel && $kParamName == 'title') {
  192. $label = $attr;
  193. }
  194. $attr = $kParamName . '="' . $attr . '"';
  195. $attrs[] = $attr;
  196. }
  197. $rowFunctions[$kFunName] = '<a ' . implode(' ', $attrs) . '>' . "{$ico} {$label} " . '</a>';
  198. }
  199. return $rowFunctions;
  200. }
  201. private function _showRowFunctions($idRecord = null, $pomin = array(), $showLabel = false) {
  202. $rowFunctionsOut = $this->_parseRowFunctions($idRecord, $pomin, $showLabel);
  203. $rowFunctionsOut = implode('', $rowFunctionsOut);
  204. return $rowFunctionsOut;
  205. }
  206. private function _showRowFunctionsJson($idRecord = null, $pomin = array(), $showLabel = false) {
  207. $rowFunctions = $this->_parseRowFunctions($idRecord, $pomin, $showLabel);
  208. $rowFunctions = (object)$rowFunctions;
  209. return $rowFunctions;
  210. }
  211. public function allowTreeView() {
  212. if ($this->_tbl == 'CRM_LISTA_ZASOBOW') return true;
  213. if ($this->_tbl == 'CRM_PROCES') return true;
  214. return false;
  215. }
  216. public function renderStatic($tblAjaxMap = null) {
  217. static $_rendered = false;
  218. if ($_rendered) return;
  219. if ($tblAjaxMap) $tblAjaxMap->printCSS();
  220. if ($tblAjaxMap) $tblAjaxMap->printJS();
  221. echo UI::h('script', ['src'=>"static/sweetalert2.min.js"]);
  222. echo UI::h('script', ['src'=>"static/jquery.doubleScroll.js"]);
  223. echo UI::h('link', ['rel'=>"stylesheet", 'type'=>"text/css", 'href'=>"stuff/jquery-ui-smoothness/jquery-ui-1.10.4.custom.min.css"]);
  224. echo UI::h('link', ['rel'=>"stylesheet", 'type'=>"text/css", 'href'=>"static/sweetalert2.min.css"]);
  225. echo UI::h('style', ['type'=>"text/css"], "
  226. .AjaxTable{max-width:100%;background-color:transparent;border-collapse:collapse;border-spacing:0;}
  227. .AjaxTableCont {position:relative; margin:10px 0; width:100%; overflow-x:auto; border:none;}
  228. .AjaxTable *,
  229. .AjaxTable.table {white-space:nowrap; width:auto;}
  230. .AjaxTable .popover * {white-space:normal;}
  231. .AjaxTable p {margin:0;}
  232. .AjaxTable td, .AjaxTable th {line-height:18px;}
  233. .AjaxTable i {margin: 0 0 0 2px;opacity: 0.5;}
  234. .AjaxTable span.filter {background-color:#999;}
  235. .AjaxTable .indeterminate {opacity: 0.4;-ms-filter:\"progid:DXImageTransform.Microsoft.Alpha(Opacity=40)\";filter:alpha(opacity=40);}
  236. .AjaxTable .columnpicker li, .AjaxTable .actions li {padding-left:5px;}
  237. .AjaxTableCont .btn-toolbar {margin:2px 0 0 0;}
  238. .AjaxTableCont .btn-toolbar .btn-group {vertical-align:top;}
  239. .AjaxTable input[type=checkbox] {margin:0;padding:0;height:13px;}
  240. .AjaxTable input[type=text].filter {margin:0;padding:0 5px;box-shadow:none;width:100%;background:#eee;color:#000;}
  241. .AjaxTable input[type=text].filter {border-width:2px 0;border-color:#eee;border-style:solid;}
  242. .AjaxTable input[type=text].filter-active {border-color:#00ACCC;}
  243. .AjaxTable .date-wrap {width:100%;min-width:115px;}
  244. .AjaxTable .dateWrap .add-on {margin:0;padding:0;background:none;border:none;float:right;cursor:pointer;}
  245. .AjaxTable .actions a {padding:0;margin:0;}
  246. .AjaxTableCont .text-right {text-align:right}
  247. .AjaxTableCont .breadcrumb em {color:#bbb;}
  248. .AjaxTable-loading .head-info {background:url(./icon/loading.gif) no-repeat left top; background-position:0 6px;}
  249. .AjaxTable-loading .loading-info,
  250. .AjaxTableCont .tblAjax__inlineEditBox .loading-info {display:block; padding:0 0 0 20px; background:url(./icon/loading.gif) no-repeat left top;}
  251. .AjaxTableCont .loading-info {display:none;}
  252. .AjaxTableCont .tblAjax__inlineEditBox .loading-info {display:block;}
  253. .AjaxTableCont .table {margin-bottom:0px;}
  254. .AjaxTableCont .stickyCol1 a { color:#333; }
  255. .AjaxTableCont .stickyCol1 a:hover { color:#337AB7; text-decoration:none; }
  256. .AjaxTableTaskCnt {padding:0 10px 10px 10px;}
  257. .AjaxTable .tbl-short-txt{max-width:140px; overflow:hidden;}
  258. .AjaxTable .tbl-short-txt span{display:block; height:18px;}
  259. .AjaxTable .tooltip-inner{white-space:normal;}
  260. .AjaxTable thead .sort .ta-ordering {cursor:pointer;}
  261. .AjaxTable thead .sort .ta-ordering span {margin:0 10px 0 0; padding:0; background-repeat:no-repeat; background-position:right top;}
  262. .AjaxTable thead .sort .ta-ordering-down span:after{content:\"\\e252\";font-family:\"Glyphicons Halflings\";line-height:1;margin:0 0 0 3px;display:inline-block;color:#bbb;}
  263. .AjaxTable thead .sort .ta-ordering-up span:after{content:\"\\e253\";font-family:\"Glyphicons Halflings\";line-height:1;margin:0 0 0 3px;display:inline-block;color:#bbb;}
  264. .AjaxTable thead .sort .ta-ordering {position:relative;}
  265. .AjaxTable thead .sort th .hover-show:hover{background-color:#000; background-image:url(stuff/twitter-bootstrap/img/glyphicons-halflings-white.png);}
  266. .AjaxTable thead .sort th .hover-show{display:none;}
  267. .AjaxTable thead .sort th:hover .hover-show{display:inline;}
  268. .AjaxTable thead .sort .ta-ordering .remove-cell {position:absolute; top:6px; right:2px; display:none; color:#f00;}
  269. .AjaxTable thead .sort .ta-ordering:hover .remove-cell {display:block;}
  270. .AjaxTableCont .pagination { margin:0; }
  271. .AjaxTableCont .pagination a { line-height:16px; }
  272. .AjaxTableCont .AjaxTableEdit-label { display:block; margin:0 0 3px 0; font-size:12px !important; line-height:16px !important; }
  273. .AjaxTableCont .AjaxTableEdit-label code { padding:0; white-space:nowrap; background-color:transparent; border:none; color:#777; font-size:10px !important; line-height:14px !important; }
  274. .AjaxTableCont .AjaxTableEdit .show-last-value .button-appendBack .glyphicon,
  275. .AjaxTableCont .AjaxFrmHorizontalEdit .show-last-value .button-appendBack .glyphicon {display:none;}
  276. .AjaxTableHist em {color:silver;}
  277. .AjaxTableCont .foot * { font-size:12px !important; }
  278. .AjaxTableCont .foot { margin:10px; }
  279. .AjaxTableCont .foot .foot-info { float:left; padding:0 20px; }
  280. .AjaxTableCont .foot .foot-info p { line-height:16px; margin:5px 0; }
  281. .AjaxTable-loading .foot .foot-info {padding-left:20px; background:url(./icon/loading.gif) no-repeat left top;}
  282. .tblAjax__head__specialFilter {margin:0;padding:4px 4px 4px 127px;}
  283. .tblAjax__head__specialFilter .btn-group {margin:0 4px;padding:0;}
  284. .tblAjax__head__specialFilter .btn-group .glyphicon-remove {color:#f00;}
  285. .tblAjax__head__specialFilter .btn-group button.disabled .glyphicon-remove {color:#bbb;}
  286. /* overwrite bootstrap table border */
  287. .AjaxTable, .AjaxTableEdit,
  288. .AjaxTable td, .AjaxTableEdit td,
  289. .AjaxTable th, .AjaxTableEdit th { border-color:#999; }
  290. /* cell A_STATUS */
  291. .AjaxTable .cell-A_STATUS-NORMAL { background:#aeffae; color:#000; text-align:center; }
  292. .AjaxTable .cell-A_STATUS-WAITING { background:#ffd2ff; color:#000; text-align:center; }
  293. .AjaxTable .cell-A_STATUS-MONITOR { background:#cccaff; color:#000; text-align:center; }
  294. .AjaxTable .cell-A_STATUS-WARNING { background:#ffbaba; color:#000; text-align:center; }
  295. .AjaxTable .cell-A_STATUS-DELETED { background:#e0e0e0; color:#808080; text-align:center; }
  296. .AjaxTable .cell-A_STATUS-OFF_SOFT { background:#fce3b7; color:#808080; text-align:center; }
  297. .AjaxTable .cell-A_STATUS-OFF_HARD { background:#eee; color:#808080; text-align:center; }
  298. /* cell Status */
  299. .AjaxTable .cell-Status-U { background:rgb(0,176,80); color:#000; text-align:center; }
  300. .AjaxTable .cell-Status-NU { background:#f00; color:#000; text-align:center; }
  301. .AjaxTable .cell-Status-P { background:rgb(112,48,160); color:#000; text-align:center; }
  302. .AjaxTable .cell-Status-PT { background:rgb(127,127,127); color:#000; text-align:center; }
  303. .AjaxTable .cell-Status-O { background:rgb(0,176,240); color:#000; text-align:center; }
  304. .AjaxTable .cell-Status-DZ { background:rgb(0,112,192); color:#000; text-align:center; }
  305. .AjaxTable .cell-Status-Z {}
  306. /* map */
  307. .AjaxTable .cell-mapfld { cursor:pointer; }
  308. .AjaxTable .cell-mapfld:hover { opacity:1; }
  309. .AjaxTable .cell-mapfld-remove { display:none; }
  310. .AjaxTable .cell-mapfld-hasValue .cell-mapfld-select { color:#f00; }
  311. .AjaxTable .cell-mapfld-hasValue .cell-mapfld-remove { display:inline-block; }
  312. .AjaxTableCont .mapEditor { position:absolute; bottom:0; right:6px; width:512px; height:318px; overflow:hidden; color:#eee; border:1px solid #999; }
  313. .AjaxTableCont .mapEditor-panel { height:16px; padding:0 6px; background:#999; border-bottom:1px solid #eee; }
  314. .AjaxTableCont .mapEditor-panel a { display:block; float:right; padding:0 6px; font-weight:bold; font-size:12px; line-height:16px; color:#fff; }
  315. .AjaxTableCont .mapEditor-panel a:hover { color:#006CD7; text-decoration:none; }
  316. .AjaxTableCont .mapEditor-panel a.mapEditor-panel-close:hover { color:#f00; }
  317. .AjaxTableCont .mapEditor-map { background:#fff; height:400px; }
  318. .AjaxTableCont-mapEditorContainer .mapEditor-map { border:1px solid #999; overflow:hidden; }
  319. /* .mapEditor-btnBackToWindow \"olControlSave\",overview_replacement */
  320. .olControlEditingToolbar .mapEditor-btnBackToWindowItemInactive,
  321. .olControlEditingToolbar .mapEditor-btnBackToWindowItemActive {
  322. background-image: url(icon/map.window.png);
  323. background-position: 0 0;
  324. background-repeat: no-repeat;
  325. }
  326. /*
  327. .mapEditor-btnBackToWindowItemInactive { background-image: url(stuff/open-layers/theme/default/img/overview_replacement.gif); }
  328. .mapEditor-btnBackToWindowItemActive { background-image: url(stuff/open-layers/theme/default/img/overview_replacement.gif); }
  329. */
  330. .ui-dialog-content .mapEditor-btnBackToWindowItemInactive,
  331. .ui-dialog-content .mapEditor-btnBackToWindowItemActive { display:none; }
  332. .AjaxTableCont .valign-btns-bottom .btn { vertical-align:text-bottom; font-weight:normal; font-size:12px; line-height:14px; }
  333. .ui-resizable-s { bottom:0; }
  334. .ui-resizable-e { right:0; }
  335. .AjaxTableCont-mapEditorContainer .ui-resizable-s { background-color:#ddd; }
  336. .AjaxTableCont-mapEditorContainer .ui-resizable-s:hover { background-color:#888; }
  337. ");
  338. echo UI::h('script', [ 'src' => "static/vendor.js" ]); // window.p5VendorJs: {React, ReactDOM, createReactClass, Redux}
  339. echo UI::h('script', [ 'src' => "static/p5UI/buildDom.js" ]);
  340. $_rendered = true;
  341. }
  342. public function render() {
  343. $acl = $this->_acl;
  344. $hasGeomFlds = Core_AclHelper::hasGeomFields($acl);
  345. $tblAjaxMap = ($hasGeomFlds) ? new TableAjaxMap($acl, 512, 400) : null;
  346. $hasPermCreate = Core_AclHelper::hasCreatePerms($acl);
  347. $jsToogleFiltrProcesuFunctionName = 'tableAjaxToggleFiltrProcesInit';
  348. $jsToogleTableToolsFunctionName = 'tableAjaxToggleTableTools';
  349. ob_start();
  350. $this->renderStatic($tblAjaxMap);
  351. UI::startContainer();
  352. UI::showMessagesForTable($this->_tbl);
  353. UI::endContainer();
  354. $namespace = $acl->getNamespace();
  355. echo UI::h('div', [ 'class' => "AjaxTableCont" ], [
  356. UI::h('ul', [ 'class' => "breadcrumb" ], [
  357. UI::h('li', [], [
  358. UI::h('a', [ 'href' => "#", 'onclick' => "return tableAjaxBackToTable();" ], $this->getLabelHtml() ),
  359. ]),
  360. ($hasPermCreate)
  361. ? UI::h('li', [], [
  362. UI::h('a', [ 'title' => "Dodaj nowy rekord", 'class' => "", 'href' => "#CREATE" ], [
  363. UI::h('span', [ 'class' => "glyphicon glyphicon-plus" ]),
  364. " Dodaj nowy rekord",
  365. ]),
  366. ])
  367. : '',
  368. ($this->showProcesInitFiltr)
  369. ? UI::h('div', [ 'class' => "btn-group pull-right" ], [
  370. UI::h('a', [ 'class' => "btn btn-xs btn-info dropdown-toggle",
  371. 'data-toggle' => "dropdown",
  372. 'href' => "#",
  373. 'title' => "Uruchom filtr procesu powiązanego z tabelą " . $this->getLabel(),
  374. 'onclick' => "return {$jsToogleFiltrProcesuFunctionName}(this);",
  375. ], "Filtr procesu <span class=\"caret\"></span>"),
  376. UI::h('ul', [ 'class' => "dropdown-menu pull-left", 'style' => "max-height:250px;overflow:auto;" ], [
  377. UI::h('li', [ 'class' => "disabled" ], [
  378. UI::h('a', [ 'href' => "#", 'onclick' => "return false;" ], " loading ... "),
  379. ]),
  380. ]),
  381. ])
  382. : '',
  383. ($this->showTableTools)
  384. ? UI::h('div', [ 'class' => "btn-group pull-right" ], [
  385. UI::h('a', [ 'class' => "btn btn-xs btn-default dropdown-toggle",
  386. 'style' => "margin-right:16px",
  387. 'data-toggle' => "dropdown",
  388. 'href' => "#",
  389. 'title' => "Narzędzia powiązane z tabelą " . $this->getLabel(),
  390. 'onclick' => "return {$jsToogleTableToolsFunctionName}(this);",
  391. ], "Narzędzia <span class=\"caret\"></span>"),
  392. UI::h('ul', [ 'class' => "dropdown-menu pull-left", 'style' => "max-height:250px;overflow:auto;" ], [
  393. UI::h('li', [ 'class' => "disabled" ], [
  394. UI::h('a', [ 'href' => "#", 'onclick' => "return false;" ], " loading ... "),
  395. ]),
  396. ]),
  397. ])
  398. : '',
  399. ($this->_tbl == 'IN7_MK_BAZA_DYSTRYBUCJI')
  400. ? UI::h('a', [ 'class' => "pull-right", 'style' => "padding:0 20px 0 0", 'href' => "index.php?MENU_INIT=TREEJS&ZASOB_ID={$this->_zasobID}" ], "<i class=\"glyphicon glyphicon-eye-open\"></i> Drzewo")
  401. : '',
  402. ($this->_tbl !== 'IN7_MK_BAZA_DYSTRYBUCJI' && $this->allowTreeView())
  403. ? UI::h('a', [ 'class' => "pull-right", 'style' => "padding:0 20px 0 0", 'href' => "index.php?MENU_INIT=VIEWTREE_AJAX&ZASOB_ID={$this->_zasobID}" ], "<i class=\"glyphicon glyphicon-eye-open\"></i> Drzewo")
  404. : '',
  405. ($this->_tbl == 'WMS_MAP_GEOREFERENCES')
  406. ? UI::h('a', [ 'class' => "pull-right", 'style' => "padding:0 20px 0 0", 'href' => "index.php?_route=GeoreferencesManager" ], "<i class=\"glyphicon glyphicon glyphicon-wrench\"></i> Zarządzaj punktami")
  407. : '',
  408. ]),
  409. ($this->_backRefFilter)
  410. ? UI::h('div', [ 'class' => "container" ], [
  411. UI::h('div', [ 'class' => "alert alert-info" ], [
  412. "Rekordy powiązane z rekordem {$this->_backRefFilter['primaryKey']} z ",
  413. UI::h('a', [
  414. 'href' => "index.php?_route=ViewTableAjax&namespace={$this->_backRefFilter['namespace']}",
  415. ], $this->_backRefFilter['namespace']),
  416. " - ",
  417. UI::h('a', [
  418. 'href' => $this->rootUrl,
  419. 'style' => "color:red",
  420. ], "usuń filtr"),
  421. ]),
  422. ])
  423. : '',
  424. ($this->_childRefFilter)
  425. ? UI::h('div', [ 'class' => "container" ], [
  426. UI::h('div', [ 'class' => "alert alert-info" ], [
  427. "Rekordy powiązane z rekordem {$this->_childRefFilter['primaryKey']} z ",
  428. UI::h('a', [
  429. 'href' => "index.php?_route=ViewTableAjax&namespace={$this->_childRefFilter['namespace']}",
  430. ], $this->_childRefFilter['namespace']),
  431. " - ",
  432. UI::h('a', [
  433. 'href' => $this->rootUrl,
  434. 'style' => "color:red",
  435. ], "usuń filtr"),
  436. ]),
  437. ])
  438. : '',
  439. UI::h('div', [ 'id' => $this->_htmlID ]),
  440. ]);
  441. UI::inlineJS(__FILE__ . '.generateFunctionNode.js');
  442. UI::inlineJS(__FILE__ . '.GeomField.js');
  443. if ($this->showProcesInitFiltr) {
  444. UI::inlineJS(__FILE__ . '.procesInitFiltr.js', [
  445. 'JS_FUNCTION_NAME' => $jsToogleFiltrProcesuFunctionName,
  446. 'URL_GET_PROCES_INIT_FILTR' => $this->showProcesInitFiltr,
  447. 'ID_ZASOB' => $this->_zasobID,
  448. ]);
  449. }
  450. if ($this->showTableTools) {
  451. UI::inlineJS(__FILE__ . '.tableTools.js', [
  452. 'JS_FUNCTION_NAME' => $jsToogleTableToolsFunctionName,
  453. 'URL_GET_TABLE_TOOLS' => $this->showTableTools,
  454. ]);
  455. }
  456. UI::inlineJS(__FILE__ . '.TableAjax.js', [
  457. 'URI_BASE' => Request::getPathUri(),
  458. ]);
  459. $filterInit = $this->_filterInit;
  460. $forceFilterInit = $this->_forceFilterInit;
  461. $pageSizes = $this->_pageSizes;
  462. $pageSize = $this->_pageSize;
  463. $rowFunctions = $this->_rowFunctions;//$this->_showRowFunctionsJson();
  464. $exportFields = Core_AclHelper::getExportFieldList($acl);
  465. UI::inlineJS(__FILE__ . '.hist.js', [
  466. 'TABLE_AJAX_NODE_ID' => $this->_htmlID,
  467. 'TABLE_AJAX_LABEL' => $this->getLabelHtml(),
  468. 'URL_HIST_BASE' => "index-ajax.php?_zasobID={$this->_zasobID}&_cls=" . __CLASS__ . "&_hash={$this->_htmlID}&_task=HIST", // &ID=...
  469. 'FUNCTION_HIST_ROUTE' => "TableAjax__HIST_Route",
  470. ]);
  471. UI::inlineJS(__FILE__ . '.create.js', [
  472. 'TABLE_AJAX_NODE_ID' => $this->_htmlID,
  473. 'TABLE_AJAX_LABEL' => $this->getLabelHtml(),
  474. 'NAMESPACE' => $acl->getNamespace(),
  475. 'FIRCE_FILTER_INIT' => $forceFilterInit,
  476. 'FUNCTION_CREATE_ROUTE' => "TableAjax__CREATE_Route",
  477. 'URL_CREATE_FORM_AJAX' => "{$this->syncUrl}&_hash={$this->_htmlID}&_task=createFormJson",
  478. ]);
  479. UI::inlineJS(__FILE__ . '.edit.js', [
  480. 'TABLE_AJAX_NODE_ID' => $this->_htmlID,
  481. 'TABLE_AJAX_LABEL' => $this->getLabelHtml(),
  482. 'NAMESPACE' => $acl->getNamespace(),
  483. 'FUNCTION_EDIT_ROUTE' => "TableAjax__EDIT_Route",
  484. 'URL_EDIT_FORM_AJAX' => "{$this->syncUrl}&_hash={$this->_htmlID}&_task=editFormJson&_primaryKey=",
  485. ]);
  486. UI::inlineJS(__FILE__ . '.openRef.js', []); // p5UI__tableAjaxOpenRefCell
  487. $specialFilters = (method_exists($acl, 'getSpecialFilters')) ? $acl->getSpecialFilters() : null;
  488. $className = __CLASS__;
  489. UI::inlineJS(__FILE__ . '.init.js', [
  490. 'TABLE_AJAX_NODE_ID' => $this->_htmlID,
  491. 'NAMESPACE' => $acl->getNamespace(),
  492. 'FUNCTION_HIST_ROUTE' => 'TableAjax__HIST_Route',
  493. 'FUNCTION_EDIT_ROUTE' => 'TableAjax__EDIT_Route',
  494. 'URL_LOAD_AJAX_BASE' => $this->syncUrl . '&_hash=' . $this->_htmlID . '&_task=loadDataAjax',
  495. 'URL_USER_TABLE_FILTER' => ($this->useUserTableFilter) ? $this->useUserTableFilter : '',
  496. 'FILTER_INIT' => $filterInit,
  497. 'FIRCE_FILTER_INIT' => $forceFilterInit,
  498. 'PAGE_SIZE' => $pageSize,
  499. 'PAGE_SIZES' => $pageSizes,
  500. 'URL_REMOVE_THE_GEOM_AJAX' => "{$this->syncUrl}&_hash={$this->_htmlID}&_task=removeTheGeomAjax",
  501. 'URL_MORE_FUNCTIONS_CELL_AJAX' => "{$this->syncUrl}&_hash={$this->_htmlID}&_task=moreFunctionsCellAjax",
  502. 'URL_EDIT_INLINE_SAVE' => "index-ajax.php?_zasobID={$this->_zasobID}&_cls={$className}&_hash={$this->_htmlID}&_task=EDIT_INLINE_SAVE",
  503. 'URL_THE_GEOM_SAVE' => "index-ajax.php?_zasobID={$this->_zasobID}&_cls={$className}&_hash={$this->_htmlID}&_task=THE_GEOM_SAVE",
  504. 'URL_PAGE_SIZE_SAVE' => "index-ajax.php?_zasobID={$this->_zasobID}&_cls={$className}&_hash={$this->_htmlID}&_task=PAGE_SIZE_SAVE",
  505. 'URL_HIDDEN_COLS_SAVE' => "index-ajax.php?_zasobID={$this->_zasobID}&_cls={$className}&_hash={$this->_htmlID}&_task=HIDDEN_COLS_SAVE",
  506. 'URL_EDIT_INLINE' => "index-ajax.php?_zasobID={$this->_zasobID}&_cls={$className}&_hash={$this->_htmlID}&_task=EDIT_INLINE",
  507. 'URL_RECORD_COPY' => "index-ajax.php?_zasobID={$this->_zasobID}&_cls={$className}&_hash={$this->_htmlID}&_task=COPY",
  508. 'URL_RECORD_FILES' => "index-ajax.php?_zasobID={$this->_zasobID}&_cls={$className}&_hash={$this->_htmlID}&_task=FILES",
  509. 'HAS_ADDITIONAL_LAYERS' => $this->hasAdditionalLayers() ? 1 : 0,
  510. 'URL_ADD_USER_TABLE_FILTER_AJAX' => Request::getPathUri() . "index.php?_route=ViewTableAjax&_task=addUserTableFilterAjax",
  511. 'URL_RM_USER_TABLE_FILTER_AJAX' => Request::getPathUri() . "index.php?_route=ViewTableAjax&_task=rmUserTableFilterAjax",
  512. 'LABEL_HTML' => $this->getLabelHtml(),
  513. 'SPECIAL_FILTER_FUNCTIONS' => (!empty($specialFilters)) ? $specialFilters : 'false',
  514. 'ROW_FUNCTIONS' => $rowFunctions,
  515. 'TABLE_FUNCTIONS' => array_merge(
  516. [ 'shortdesc' => [ 'icon' => "align-left", 'title' => "Long desc", 'method' => "longTextChanged" ] ],
  517. ($hasGeomFlds)
  518. ? [ 'mapeditor' => [ 'icon' => "map-marker", 'title' => "Mapa", 'method' => 'mapEditorChanged' ] ]
  519. : [],
  520. [ 'create' => [ 'href' => '#CREATE', 'icon' => 'plus', 'title' => "Dodaj nowy rekord" ] ],
  521. [ 'refresh' => [ 'icon' => 'refresh', 'title' => "Odśwież dane", 'method' => "refresh" ] ]
  522. ),
  523. 'EXPORT_FIELDS' => $exportFields,
  524. ]);
  525. UI::inlineJS(__FILE__ . '.upload.js', [
  526. 'URL_UPLOAD_FILES_AJAX' => "index.php?_route=ViewTableAjax&_task=uploadFilesAjax",
  527. ]);
  528. UI::setTitle($this->_acl->getRawLabel(100) . " - " . UI::getTitle());
  529. return ob_get_clean();
  530. }
  531. public function _viewProcesInitListItem($vInitId, $gotoIds, $pInitList) {
  532. $vLabel = $pInitList[$vInitId];
  533. $kId = $vInitId;
  534. echo UI::h('a', [
  535. 'href' => "index.php?FUNCTION_INIT=MENU_SELECT_PROCES&_action=setPermsByProces&id_proces={$kId}&MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID={$this->_zasobID}",
  536. 'title' => htmlspecialchars("{{$kId}} {$vLabel}"),
  537. ], [
  538. UI::h('i', [
  539. 'class' => "glyphicon glyphicon-info-sign",
  540. 'onclick' => "window.open('procesy5.php?task=PROCES_VIEW_LIST&id_proces={$kId}&HIDE_PANEL=0&show_big_img=1&group_stanowiska=1');return false;",
  541. 'style' => "color:#aaa",
  542. 'onmouseover' => "this.style.color='#337AB7'",
  543. 'onmouseout' => "this.style.color='#aaa'"]),
  544. "{{$kId}} {$vLabel}"
  545. ]);
  546. }
  547. public function _viewProcesGotoAndRetListItem($vGotoId, $pInitList) {
  548. $vLabel = $pInitList[$vGotoId];
  549. $kId = $vGotoId;
  550. // TODO:?: prevent to execute procedure
  551. echo UI::h('a', [
  552. 'href' => "index.php?FUNCTION_INIT=MENU_SELECT_PROCES&_action=setPermsByProces&id_proces={$kId}&MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID={$this->_zasobID}",
  553. 'title' => htmlspecialchars("{{$kId}} {$vLabel}"),
  554. ], [
  555. UI::h('span', [ 'style' => "padding:10px;"]),
  556. UI::h('i', [ 'class' => "glyphicon glyphicon-arrow-right", 'style' => "color:#aaa"]),
  557. UI::h('i', [ 'class' => "glyphicon glyphicon-info-sign",
  558. 'onclick' => "window.open('procesy5.php?task=PROCES_VIEW_LIST&id_proces={$kId}&HIDE_PANEL=0&show_big_img=1&group_stanowiska=1');return false;",
  559. 'style' => "color:#aaa",
  560. 'onmouseover' => "this.style.color='#337AB7'",
  561. 'onmouseout' => "this.style.color='#aaa'"]),
  562. "{{$kId}} {$vLabel}",
  563. ]);
  564. }
  565. public function _viewProcesGotoAndRetLvl2ListItem($vGotoLvl2Id, $pInitList) {
  566. $vLabel = $pInitList[$vGotoLvl2Id];
  567. $kId = $vGotoLvl2Id;
  568. // TODO:?: prevent to execute procedure
  569. echo UI::h('a', [
  570. 'href' => "index.php?FUNCTION_INIT=MENU_SELECT_PROCES&_action=setPermsByProces&id_proces={$kId}&MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID={$this->_zasobID}",
  571. 'title' => htmlspecialchars("{{$kId}} {$vLabel}"),
  572. ], [
  573. UI::h('span', [ 'style' => "padding:20px;" ]),
  574. UI::h('i', [ 'class' => "glyphicon glyphicon-arrow-right", 'style' => "color:#aaa" ]),
  575. UI::h('i', [ 'class' => "glyphicon glyphicon-info-sign",
  576. 'onclick' => "window.open('procesy5.php?task=PROCES_VIEW_LIST&id_proces={$kId}&HIDE_PANEL=0&show_big_img=1&group_stanowiska=1');return false;",
  577. 'style' => "color:#aaa",
  578. 'onmouseover' => "this.style.color='#337AB7'",
  579. 'onmouseout' => "this.style.color='#aaa'"]),
  580. "{{$kId}} {$vLabel}",
  581. ]);
  582. }
  583. public function hasAdditionalLayers() {
  584. $layers = TableAjaxMap::getAdditionalLayers($this->_zasobID);
  585. return !empty($layers);
  586. }
  587. public function ajaxTask($task) {
  588. switch ($task) {
  589. case 'EDIT_INLINE': {
  590. $this->sendAjaxResponseJson('ajaxInlineEdit', $_REQUEST);
  591. break;
  592. }
  593. case 'EDIT_INLINE_SAVE': {
  594. $this->sendAjaxResponseJson('ajaxEditInlineSave', $_REQUEST);
  595. break;
  596. }
  597. case 'COPY': {
  598. $this->sendAjaxResponseJson('ajaxCopy', $_REQUEST);
  599. break;
  600. }
  601. case 'CREATE_SAVE': { // TODO: mv to _route = ViewTableAjax & _task = createSaveAjax
  602. $this->sendAjaxResponseJson('ajaxCreateSave', $_REQUEST);
  603. break;
  604. }
  605. case 'HIST': {
  606. $this->sendAjaxResponseJson('ajaxHist', $_REQUEST);
  607. break;
  608. }
  609. case 'FILES': {
  610. try {
  611. $id = V::get('ID', 0, $_REQUEST, 'int');
  612. if ($id <= 0) throw new HttpException("404", 404);
  613. $this->sendAjaxFiles($id, $_REQUEST);
  614. } catch (HttpException $e) {
  615. Http::sendHeaderByCode($e->getCode());
  616. echo $e->getMessage();
  617. //UI::alert('danger', $e->getMessage());
  618. } catch (Exception $e) {
  619. echo '<div class="container">';
  620. UI::alert('danger', $e->getMessage());
  621. echo '</div>';
  622. }
  623. break;
  624. }
  625. case 'FILES_UPLOAD': {
  626. $this->sendAjaxResponseJson('ajaxFileUpload', $_REQUEST);
  627. break;
  628. }
  629. case 'FILES_LIST': {
  630. $this->sendAjaxResponseJson('ajaxFileList', $_REQUEST);
  631. break;
  632. }
  633. case 'filePermsRefresh': {
  634. $this->sendAjaxResponseJson('ajaxFilePermsRefresh', $_REQUEST);
  635. break;
  636. }
  637. case 'FILES_CONN_TBL_LIST': {
  638. $id = V::get('ID', 0, $_REQUEST, 'int');
  639. if ($id > 0) {
  640. $this->sendAjaxFilesConnTblList($id, $_REQUEST);
  641. } else {
  642. echo '404';
  643. }
  644. break;
  645. }
  646. case 'TYPESPECIAL': {
  647. $fldID = V::get('fldID', 0, $_REQUEST, 'int');
  648. if ($fldID > 0) {
  649. $this->sendTypeSpecial($fldID, $_REQUEST);
  650. } else {
  651. echo '404';
  652. }
  653. break;
  654. }
  655. case 'HIDDEN_COLS_SAVE': {
  656. $this->sendAjaxResponseJson('ajaxHiddenColsSave', $_POST);
  657. break;
  658. }
  659. case 'PAGE_SIZE_SAVE': {
  660. $this->sendAjaxResponseJson('ajaxPageSizeSave', $_POST);
  661. break;
  662. }
  663. case 'THE_GEOM_SAVE': {
  664. $this->sendAjaxResponseJson('ajaxTheGeomSave', $_REQUEST);
  665. break;
  666. }
  667. default:
  668. $this->sendAjaxResponseJson('ajaxData', $_REQUEST);
  669. }
  670. }
  671. /**
  672. * ajax url: &_task=EDIT_INLINE
  673. * @param $rowID - $_GET['ID']
  674. * @param $fieldName - $_GET['col']
  675. */
  676. private function ajaxInlineEdit() {
  677. $DBG = ('1' == V::get('DBG', '', $_REQUEST));
  678. $args = $_REQUEST;
  679. $idRecord = V::get('ID', 0, $_REQUEST, 'int');
  680. $fieldName = V::get('col', '', $_REQUEST);
  681. if ($idRecord <= 0 || empty($fieldName)) throw new HttpException("404", 404);
  682. $response = array();
  683. ob_start();
  684. $fieldID = $this->_acl->getFieldIdByName($fieldName);
  685. if (!$fieldID) die("404: No field by name ({$fieldName})");
  686. $response['idZasob'] = $fieldID;
  687. $response['htmlFieldName'] = "f{$fieldID}";
  688. if ($DBG) echo "fieldID: {$fieldID}\n";
  689. $record = $this->_acl->buildQuery([])->getItem($idRecord);
  690. if (!$record) die("404: No item ID({$idRecord})");
  691. $fieldVal = '';
  692. if ($this->_acl->canReadObjectField($fieldName, $record)) {
  693. $fieldVal = V::get($fieldName, $fieldVal, $record);
  694. } else {
  695. $fieldVal = '*****';
  696. }
  697. $fieldVal = V::get("f{$fieldID}", $fieldVal, $_POST);
  698. $vCol = $this->_acl->getField($fieldID);
  699. $vCol['label'] = (!empty($vCol['label']))? $vCol['label'] : $vCol['name'];
  700. $response['fieldLabel'] = $vCol['label'];
  701. $tsValues = array();
  702. $typeSpecial = Typespecial::getInstance($fieldID, $vCol['name']);
  703. if ($typeSpecial) {
  704. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">Typespecial('.$fieldID.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($typeSpecial);echo'</pre>';}
  705. $specialValues = $typeSpecial->getEditSelectedValuesByIds($this->_zasobID, $record['ID'], $fieldName, V::get($fieldName, $fieldVal, $record));
  706. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">Typespecial('.$fieldID.') specialValues (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($specialValues);echo'</pre>';}
  707. if (!empty($specialValues)) {
  708. $tsValues[ $record['ID'] ] = implode('<br>', $specialValues);
  709. }
  710. }
  711. $fieldParams = array('widthClass'=>'inside-modal', 'maxGrid'=>6);
  712. if (!empty($tsValues[ $record['ID'] ])) $fieldParams['typespecialValue'] = $tsValues[ $record['ID'] ];
  713. if (!empty($tsValues[ $record['ID'] ])) $response['typespecialValue'] = $tsValues[ $record['ID'] ];
  714. $vDefault = $this->_acl->getFieldDefaultValue($fieldName);
  715. if (!empty($vDefault)) $fieldParams['default'] = $vDefault;
  716. if (!empty($vDefault)) $response['defaultValue'] = $vDefault;
  717. {
  718. try {
  719. $item = $this->_acl->getFormItem('W', $fieldID, "f{$fieldID}", $fieldVal, $fieldParams, $record);
  720. $response['formItem'] = $item;
  721. if (!empty($item['rawColType']['simpleType'])) $response['simpleType'] = $item['rawColType']['simpleType'];
  722. if (!empty($item['rawColType']['restrictions'])) $response['restrictions'] = $item['rawColType']['restrictions'];
  723. echo '<div style="display:none">';
  724. DBG::_(true, true, "item", $item, __CLASS__, __FUNCTION__, __LINE__);
  725. echo '</div>';
  726. } catch (Exception $e) {
  727. echo '<div style="display:none">';
  728. UI::alert('danger', $e->getMessage());
  729. echo '</div>';
  730. }
  731. }
  732. ?>
  733. <label for="<?= "f{$fieldID}"; ?>" class="AjaxTableEdit-label">
  734. <strong title="<?= "[{$fieldID}] {$fieldName}"; ?>"><?= "{$vCol['label']}"; ?></strong>
  735. <?php if (!empty($vCol['opis'])) : ?>
  736. <em><?= $vCol['opis']; ?></em>
  737. <?php endif; ?>
  738. </label>
  739. <?php
  740. if (!$this->_acl->canWriteObjectField($fieldName, $record)) {
  741. // TODO: hide Zapisz btn on frontend side
  742. if (!$this->_acl->canReadObjectField($fieldName, $record)) {
  743. UI::alert('warning', "Brak uprawnień do odczytu i zapisu");
  744. } else {
  745. echo '<p style="margin-top:16px">' . $fieldVal . '</p>';
  746. UI::alert('warning', "Brak uprawnień do zapisu");
  747. }
  748. } else {
  749. echo $this->_acl->showFormItem('W', $fieldID, "f{$fieldID}", $fieldVal, $fieldParams, $record);
  750. if ($typeSpecial
  751. || $this->_acl->isDateField($fieldName)
  752. || $this->_acl->isDateTimeField($fieldName)
  753. ) {
  754. echo '<p style="padding:120px 0;"></p>';
  755. }
  756. }
  757. $response['legacy_html'] = ob_get_clean();
  758. //$response['legacy_html'] = utf8_encode($response['legacy_html']);// pl chars bug
  759. return $response;
  760. }
  761. private function ajaxEditInlineSave($args) {
  762. $primaryKeyField = $this->_acl->getPrimaryKeyField();
  763. $primaryKey = V::get($primaryKeyField, 0, $args, 'int');
  764. $fieldName = V::get('col', '', $_REQUEST);
  765. if (empty($primaryKey)) throw new HttpException("Wrong param id!", 400);
  766. if (empty($fieldName)) throw new HttpException("Wrong param col!", 400);
  767. $fieldID = $this->_acl->getFieldIdByName($fieldName);
  768. if (!$fieldID) throw new HttpException("Field not exists!", 404);
  769. $item = $this->_acl->buildQuery([])->getItem($primaryKey);
  770. if (!$item) throw new HttpException("Item not exists!", 404);
  771. $itemFromUser = $this->_acl->convertObjectFromUserInput($args, $type = 'array_by_id', $prefix = 'f');
  772. if (!isset($itemFromUser[$fieldName])) throw new HttpException("Field not set!", 400);
  773. $itemPatch = array();
  774. $itemPatch[$fieldName] = V::get($fieldName, null, $itemFromUser);
  775. $itemPatch[$primaryKeyField] = $primaryKey;
  776. $response = new stdClass();
  777. try {
  778. $affected = $this->_acl->updateItem($itemPatch);
  779. if ($affected > 0) {
  780. $response->type = 'success';
  781. $response->msg = "Rekord zapisany pomyślnie";//"Record saved successfully";
  782. } else if ($affected == 0) {
  783. $response->type = 'info';
  784. $response->msg = "Nie wprowadzono żadnych zmian";
  785. }
  786. $response->record = $this->_acl->buildQuery([])->getItem($primaryKey);
  787. }
  788. catch (Exception $e) {
  789. $response->type = 'error';
  790. $response->msg = $e->getMessage();
  791. }
  792. return $response;
  793. }
  794. public function sendAjaxEdit($id, $args) { // TODO: not used @see ViewTableAjax::editFormAction
  795. header("Content-type: text/plain");
  796. $acl = $this->_acl;
  797. $record = $acl->buildQuery([])->getItem($id);
  798. if (!$acl->canWriteRecord($record) && !$acl->hasPermSuperWrite()) {
  799. UI::alert('danger', "Brak dostępu do rekordu");
  800. return;
  801. }
  802. $fieldsList = array();
  803. foreach ($acl->getFieldListByIdZasob() as $kID => $fieldName) {
  804. if ($fieldName == 'ID') continue;
  805. $field['name'] = $fieldName;
  806. $field['opis'] = $acl->getFieldOpis($fieldName);
  807. $field['label'] = $acl->getFieldLabel($fieldName);
  808. if (empty($field['label'])) $field['label'] = str_replace('_', ' ', $fieldName);
  809. $fieldsList[$kID] = $field;
  810. }
  811. $cols = array();
  812. foreach ($fieldsList as $kID => $field) {
  813. $cols[$kID] = '';
  814. if ($this->_acl->canReadObjectField($field['name'], $record)) {
  815. $cols[$kID] = V::get($field['name'], '', $record);
  816. } else {
  817. $cols[$kID] = '*****';
  818. }
  819. // if ($acl->canReadObjectField($field['name'])) {
  820. // $cols[$kID] = V::get($field['name'], '', $record);
  821. // } else {
  822. // $cols[$kID] = '*****';
  823. // }
  824. $cols[$kID] = V::get("f{$kID}", $cols[$kID], $_POST);
  825. }
  826. $tsValues = array();
  827. if (!empty($fieldsList)) {
  828. foreach ($fieldsList as $vColID => $vCol) {
  829. $typeSpecial = Typespecial::getInstance($vColID, $vCol['name']);
  830. if ($typeSpecial) {
  831. $colValue = V::get($vCol['name'], '', $record);
  832. $specialValues = $typeSpecial->getEditSelectedValuesByIds($this->_zasobID, $record['ID'], $vCol['name'], $colValue);
  833. if (!empty($specialValues)) {
  834. $tsValues[$vColID] = implode('<br>', $specialValues);
  835. }
  836. }
  837. }
  838. }
  839. $rowFunctionsOut = $this->_showRowFunctions($record['ID'], array('edit', 'cp'), true);
  840. ?>
  841. <div class="container AjaxFrmHorizontalEdit" style="max-width:940px">
  842. <form class="form-horizontal" action="" method="post" id="EDIT_FRM_<?= $this->_htmlID; ?>">
  843. <fieldset>
  844. <legend>Edycja rekordu Nr <?= $record['ID']; ?><span class="pull-right valign-btns-bottom"><?= $rowFunctionsOut; ?></span></legend>
  845. <?php $tabindex = 0; foreach ($fieldsList as $kID => $vCol) : ?>
  846. <?php if ($acl->canWriteObjectField($vCol['name'], $record)) : ?>
  847. <div class="form-group">
  848. <label class="col-xs-12 col-sm-3 col-md-2 control-label" for="<?= "f{$kID}"; ?>"><?= $vCol['label']; ?>
  849. <i class="glyphicon glyphicon-info-sign frm-help" data-toggle="popover" data-trigger="hover" title="" data-content="<?= htmlspecialchars($vCol['opis']); ?>" data-original-title="<?= "[{$kID}] {$vCol['name']}"; ?>"></i>
  850. </label>
  851. <div class="col-xs-12 col-sm-9 col-md-10">
  852. <?php
  853. $fieldParams = array('appendBack'=>true, 'tabindex'=>(++$tabindex), 'maxGrid'=>8);
  854. if (!empty($tsValues[$kID])) {
  855. $fieldParams['typespecialValue'] = $tsValues[$kID];
  856. }
  857. echo $acl->showFormItem('W', $kID, "f{$kID}", $cols[$kID], $fieldParams, $record);
  858. ?>
  859. </div>
  860. </div>
  861. <?php elseif ($acl->canReadObjectField($vCol['name'], $record)) : ?>
  862. <div class="form-group">
  863. <label class="col-xs-12 col-sm-3 col-md-2 control-label" for="<?= "f{$kID}"; ?>"><?= $vCol['label']; ?>
  864. <i class="glyphicon glyphicon-info-sign frm-help" data-toggle="popover" data-trigger="hover" title="" data-content="<?= htmlspecialchars($vCol['opis']); ?>" data-original-title="<?= "[{$kID}] {$vCol['name']}"; ?>"></i>
  865. </label>
  866. <div class="col-xs-12 col-sm-9 col-md-10">
  867. <p style="margin-top:5px;">
  868. <?php
  869. //echo $acl->showFormItem('R', $kID, "f{$kID}", $cols[$kID], array('appendBack'=>true), $record);
  870. if (!empty($tsValues[$kID])) {
  871. echo $tsValues[$kID];
  872. } else if (!empty($record[ $vCol['name'] ])) {
  873. echo $record[ $vCol['name'] ];
  874. }
  875. ?>
  876. </p>
  877. </div>
  878. </div>
  879. <?php endif; ?>
  880. <?php endforeach; ?>
  881. <div class="form-group">
  882. <div class="col-xs-offset-0 col-xs-12 col-sm-offset-3 col-sm-9 col-md-offset-2 col-md-10">
  883. <button type="submit" class="btn btn-primary" tabindex="<?= (++$tabindex); ?>">Zapisz</button>
  884. </div>
  885. </div>
  886. </fieldset>
  887. </form>
  888. <p style="padding:100px 0;"></p>
  889. </div>
  890. <script>
  891. jQuery(document).ready(function(){
  892. jQuery('textarea').autosize();
  893. jQuery('.frm-help').popover({trigger:'hover'});
  894. jQuery('#EDIT_FRM_<?php echo $this->_htmlID; ?>').on('submit', function(){
  895. var formData = {};
  896. jQuery(this).serializeArray().map(function(i) { formData[i.name] = i.value; });// TODO: edit Widget - send only updated fields
  897. // TODO: change Edit btn to return to edit record with fields -> show form
  898. var taskCont = jQuery('#<?php echo $this->_htmlID; ?>_task').parent();
  899. //taskCont.empty();
  900. taskCont.children().fadeOut('slow');
  901. var alertCntWrap = jQuery('<div class="AjaxTableAlert AjaxTable-loading"></div>').prependTo(taskCont)
  902. , alertCnt = jQuery('<div class="container"></div>').prependTo(alertCntWrap);
  903. jQuery('<div class="alert alert-danger"><div style="padding:0 0 0 20px; background:url(./icon/loading.gif) no-repeat left top;"> zapisywanie ... </div></div>').appendTo(alertCnt);
  904. function notifyAjaxCallback(data) {
  905. var notify = {}, outMsg = '';
  906. notify.type = (data && data.type)? data.type : '';
  907. notify.msg = (data && data.msg)? data.msg : '';
  908. switch (notify.type) {
  909. case 'success':
  910. if (!notify.msg) notify.msg = 'Dane poprawnie zaktualizowane';
  911. break;
  912. case 'info':
  913. if (!notify.msg) notify.msg = 'Nie wprowadzono żadnych zmian';
  914. break;
  915. case 'error':
  916. if (!notify.msg) notify.msg = 'Wystąpiły błędy';
  917. break;
  918. case 'warning':
  919. notify.type = 'warn';
  920. if (!notify.msg) notify.msg = 'Wystąpiły błędy';
  921. break;
  922. default:
  923. notify.msg = 'Nieznany błąd';
  924. if (data && data.errorCode) notify.msg += ' ' + data.errorCode;
  925. notify.type = '';
  926. }
  927. jQuery.notify(notify.msg, notify.type);
  928. var alertType = ('error' == data.type) ? 'danger' : data.type;
  929. outMsg = '<div class="alert alert-' + alertType + '">' + notify.msg + '</div>';
  930. return outMsg;
  931. }
  932. superagent
  933. .post('<?= $this->syncUrl; ?>&_hash=<?= $this->_htmlID; ?>&_task=editSaveAjax')
  934. .type('json') // header ĺapplication/x-www-form-urlencoded' requires type('form');
  935. .send({
  936. namespace: '<?= $acl->getNamespace(); ?>',
  937. primaryKey: '<?= $record['ID']; ?>',
  938. form: formData
  939. })
  940. .set('Accept', 'application/json')
  941. .end(function(err, res) {
  942. var payload;
  943. if (err || !res.ok || 'application/json' !== res.type) {
  944. payload = {type: 'warning', msg: res.body.msg || 'Wystąpiły błędy', body: res.body};
  945. } else {
  946. payload = {type: 'success', msg: res.body.msg || '', body: res.body};
  947. }
  948. var data = res.body;
  949. alertCntWrap.removeClass('AjaxTable-loading');
  950. alertCnt.empty();
  951. if (false === ['success', 'info'].indexOf(payload.type)) {
  952. jQuery(errorTxt).appendTo(alertCnt);
  953. var errLinks = jQuery('<div class="breadcrumb"></div>').appendTo(alertCnt);
  954. jQuery('<a href="#" onclick="return tableAjaxBackToTable();"> <i class="icon-arrow-left"></i> Wróć do tabeli <?php echo $this->getLabelHtml(); ?></a>').appendTo(errLinks);
  955. var backToEditBtn = jQuery('<a href="#EDIT/<?php echo $id; ?>/' + Math.random(1).toString().substr(2) + '" class="btn btn-link btn-small"> <i class="icon-pencil"></i> Popraw dane <?php echo $id; ?></a>').appendTo(errLinks);
  956. backToEditBtn.on('click', function(){
  957. alertCnt.remove();
  958. taskCont.children().fadeIn('slow');
  959. return false;
  960. });
  961. } else {
  962. var outMsg = notifyAjaxCallback(payload);
  963. var out = '';
  964. out += outMsg;
  965. out += '<div class="breadcrumb">' +
  966. ' <a href="#" onclick="return tableAjaxBackToTable();" class="btn btn-link btn-sm"> <i class="glyphicon glyphicon-arrow-left"></i> Wróć do tabeli <?php echo $this->getLabelHtml(); ?></a>' +
  967. ' <a href="#EDIT/<?php echo $id; ?>/' + Math.random(1).toString().substr(2) + '" class="btn btn-link btn-sm"> <i class="glyphicon glyphicon-pencil"></i> Edytuj rekord <?php echo $id; ?></a>' +
  968. '</div>';
  969. jQuery(out).appendTo(alertCnt);
  970. // add rowFunctions from response
  971. if (data && data.rowFunctions && data.primaryKey) {
  972. var rowFunWrapNode = $('<div class="container"></div>').insertAfter(alertCnt);
  973. var rowFunListNode = $('<ul></ul>').appendTo(rowFunWrapNode);
  974. var keys = Object.keys(data.rowFunctions),
  975. total = keys.length,
  976. moreFuncBtnNode,
  977. moreFunctions = [],
  978. idx
  979. ;
  980. moreFunctions = keys.splice(3);
  981. keys.forEach(function(key) {
  982. var cellNode = $('<li></li>');
  983. var funObj = data.rowFunctions[key],
  984. funcNode = p5UI_TableAjax_generateFunctionNode(funObj, data.primaryKey, {ico: true, label: true})
  985. ;
  986. funcNode.appendTo(cellNode);
  987. cellNode.appendTo(rowFunListNode);
  988. });
  989. }
  990. }
  991. });
  992. return false;
  993. });
  994. jQuery('#EDIT_FRM_<?php echo $this->_htmlID; ?>').find('.show-last-value input').on('input', function(e) {
  995. var input, btn, btnIco;
  996. input = jQuery(e.target);
  997. btn = input.next('.button-appendBack');
  998. btnIco = btn.find('.glyphicon');
  999. if (btn.attr('title') != input.val()) {
  1000. btnIco.show();
  1001. } else {
  1002. btnIco.hide();
  1003. }
  1004. });
  1005. jQuery('#EDIT_FRM_<?php echo $this->_htmlID; ?>').find('.show-last-value').find('.button-appendBack').on('click', function(e) {
  1006. var input, btn, btnIco;
  1007. btn = jQuery(this);
  1008. btnIco = btn.find('.glyphicon');
  1009. input = btn.prev();
  1010. if (input.is('input')) {
  1011. if (btn.attr('title') != input.val()) {
  1012. input.val(btn.attr('title'));
  1013. btnIco.hide();
  1014. }
  1015. }
  1016. });
  1017. });
  1018. </script>
  1019. <?php
  1020. exit;
  1021. }
  1022. public function sendAjaxCreate($args = []) {
  1023. $acl = $this->_acl;
  1024. header("Content-type: text/plain");
  1025. $DBG = ('1' == V::get('DBG', '', $_REQUEST));
  1026. if (!Core_AclHelper::hasCreatePerms($acl)) {
  1027. UI::alert('danger', "Brak uprawnień do utworzenia nowego rekordu.");
  1028. return;
  1029. }
  1030. $cols = array();
  1031. $forceFilterInit = array();
  1032. $defaultAclGroup = User::getDefaultAclGroup();
  1033. if ($defaultAclGroup) {
  1034. $forceFilterInit['A_ADM_COMPANY'] = $defaultAclGroup;
  1035. $forceFilterInit['A_CLASSIFIED'] = $defaultAclGroup;
  1036. }
  1037. foreach ($_GET as $k => $v) {
  1038. if (strlen($k) > 4 && substr($k, 0, 3) == 'ff_' && !empty($v)) {// force filter prefix
  1039. $fldName = substr($k, 3);
  1040. $forceFilterInit[$fldName] = $v;
  1041. }
  1042. }
  1043. $pkField = $acl->getPrimaryKeyField();
  1044. $fieldsList = $acl->getFields();
  1045. $fieldsList = array_filter($fieldsList, function ($vCol) {
  1046. return ($vCol['name'] != $pkField);
  1047. });
  1048. foreach ($fieldsList as $kID => $vCol) {
  1049. $defaultValue = '';
  1050. if (!empty($forceFilterInit[$vCol['name']])) {
  1051. $defaultValue = $forceFilterInit[$vCol['name']];
  1052. }
  1053. // TODO: read from session cache
  1054. $cols[$kID] = V::get("f{$kID}", $defaultValue, $_POST);
  1055. $label = V::get('label', '', $vCol);
  1056. $fieldsList[$kID]['label'] = ($label) ? $label : $vCol['name'];
  1057. }
  1058. ?>
  1059. <div class="container AjaxFrmHorizontalEdit" style="max-width:940px">
  1060. <form action="" method="post" id="CREATE_FRM_<?php echo $this->_htmlID; ?>">
  1061. <fieldset>
  1062. <legend>Dodaj nowy rekord</legend>
  1063. <?php $tabindex = 0; foreach ($fieldsList as $kID => $vCol) : ?>
  1064. <?php if ($acl->canCreateField($vCol['name'])) : ?>
  1065. <div class="form-group">
  1066. <label class="control-label" for="<?php echo "f{$kID}"; ?>"><?= V::get('label', $vCol['name'], $vCol); ?>
  1067. <i class="glyphicon glyphicon-info-sign frm-help" data-toggle="popover" data-trigger="hover" title="" data-content="<?php echo htmlspecialchars(V::get('opis', '', $vCol)); ?>" data-original-title="<?php echo "[{$kID}] {$vCol['name']}"; ?>"></i>
  1068. </label>
  1069. <div>
  1070. <?php
  1071. $fieldParams = array('appendBack'=>true, 'tabindex'=>(++$tabindex), 'maxGrid'=>8);
  1072. echo $acl->showFormItem('C', $kID, "f{$kID}", $cols[$kID], $fieldParams);
  1073. ?>
  1074. </div>
  1075. </div>
  1076. <?php endif; ?>
  1077. <?php endforeach; ?>
  1078. <div class="form-group">
  1079. <button type="submit" class="btn btn-primary" tabindex="<?php echo (++$tabindex); ?>">Dodaj rekord</button>
  1080. </div>
  1081. </fieldset>
  1082. </form>
  1083. </div>
  1084. <script>
  1085. jQuery(document).ready(function(){
  1086. jQuery('textarea').autosize();
  1087. jQuery('.frm-help').popover({trigger:'hover'});
  1088. jQuery('#CREATE_FRM_<?php echo $this->_htmlID; ?>').on('submit', function(){
  1089. var data = jQuery(this).serialize();
  1090. var taskContLast = jQuery('#<?php echo $this->_htmlID; ?>_task'),
  1091. taskCont = taskContLast.parent();
  1092. taskContLast.fadeOut('slow');
  1093. var taskCnt = jQuery('<div id="<?php echo $this->_htmlID . '_task'; ?>" class="AjaxTableTaskCnt AjaxTable-loading"></div>').appendTo(taskCont);
  1094. jQuery('<div class="alert alert-danger"><div style="padding:0 0 0 20px; background:url(./icon/loading.gif) no-repeat left top;"> save ... </div></div>').appendTo(taskCnt);
  1095. function notifyAjaxCallback(data) {
  1096. var notify = {};
  1097. notify.type = (data && data.type)? data.type : '';
  1098. notify.msg = (data && data.msg)? data.msg : '';
  1099. switch (notify.type) {
  1100. case 'success':
  1101. if (!notify.msg) notify.msg = 'OK';
  1102. break;
  1103. case 'info':
  1104. if (!notify.msg) notify.msg = '';
  1105. break;
  1106. case 'error':
  1107. if (!notify.msg) notify.msg = 'Wystąpiły błędy';
  1108. break;
  1109. case 'warning':
  1110. notify.type = 'warn';
  1111. if (!notify.msg) notify.msg = 'Wystąpiły błędy';
  1112. break;
  1113. default:
  1114. notify.msg = 'Nieznany błąd';
  1115. if (data && data.errorCode) notify.msg += ' ' + data.errorCode;
  1116. notify.type = '';
  1117. }
  1118. jQuery.notify(notify.msg, notify.type);
  1119. }
  1120. $.ajax({
  1121. data: data,
  1122. dataType: 'json',
  1123. type: "POST",
  1124. async: true,
  1125. url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=CREATE_SAVE'
  1126. })
  1127. .always(function(dataOrJqXHR){
  1128. var data;
  1129. if (dataOrJqXHR && 'readyState' in dataOrJqXHR && 'status' in dataOrJqXHR) {
  1130. if ('responseJSON' in dataOrJqXHR) {
  1131. data = dataOrJqXHR.responseJSON;
  1132. } else {
  1133. data = {};
  1134. data.msg = dataOrJqXHR.responseText || 'Nieznany błąd';
  1135. if (dataOrJqXHR.status == 404) {
  1136. data.type = 'error';
  1137. } else {
  1138. data.type = 'warning';
  1139. }
  1140. }
  1141. }
  1142. else {
  1143. data = dataOrJqXHR;
  1144. }
  1145. notifyAjaxCallback(data);
  1146. taskCnt.removeClass('AjaxTable-loading');
  1147. taskCnt.empty();
  1148. if (data.type == 'error' || data.type == 'warning') {
  1149. var out = '<div class="container">' +
  1150. '<div class="alert alert-danger">' +
  1151. '<h4>Wystąpiły błędy!</h4>' + data.msg +
  1152. (('errors' in data)? '<p>' + data.errors + '</p>' : '') +
  1153. '</div>';
  1154. out += '<div class="breadcrumb">' +
  1155. ' <a class="create-fix" href="#CREATE/' + Math.random(1).toString().substr(2) + '" class="btn btn-link btn-sm"> <i class="glyphicon glyphicon-arrow-left"></i> Wróć do formularza i popraw dane</a></li>' +
  1156. '</div>' +
  1157. '</div>';
  1158. jQuery(out).appendTo(taskCnt);
  1159. var taskContLastNode = taskContLast
  1160. , taskCntNode = taskCnt;
  1161. taskCnt.find('.create-fix').click(function(){
  1162. taskCntNode.remove();
  1163. taskContLastNode.fadeIn('slow');
  1164. return false;
  1165. });
  1166. }
  1167. else if (data.type == 'success') {
  1168. var msg = '';
  1169. if (data.id && data.id > 0) {
  1170. msg = 'Utworzono pomyślnie rekord: ID = ' + data.id;
  1171. } else if (data.msg) {
  1172. msg = data.msg;
  1173. } else {
  1174. msg = 'OK';
  1175. }
  1176. var out = '<div class="container">';
  1177. out += '<div class="alert alert-success">' + msg + '</div>';
  1178. out += '<div class="breadcrumb">' +
  1179. ' <a href="#" onclick="return tableAjaxBackToTable();" class="btn btn-link btn-sm"> <i class="glyphicon glyphicon-arrow-left"></i> Wróć do tabeli <?php echo $this->getLabelHtml(); ?></a>' +
  1180. ' <a href="#EDIT/' + data.id + '" class="btn btn-link btn-sm"> <i class="glyphicon glyphicon-pencil"></i> Edytuj rekord ' + data.id + '</a>' +
  1181. ' <a href="#CREATE/' + Math.random(1).toString().substr(2) + '" class="btn btn-link btn-sm"> <i class="glyphicon glyphicon-plus"></i> Dodaj nowy rekord</a></li>' +
  1182. '</div>';
  1183. out += '</div>';
  1184. jQuery(out).appendTo(taskCnt);
  1185. }
  1186. });
  1187. return false;
  1188. });
  1189. });
  1190. </script>
  1191. <?php
  1192. exit;
  1193. }
  1194. private function ajaxCreateSave($args) {
  1195. DBG::log($args, 'array', "ajaxCreateSave");
  1196. $acl = $this->_acl;
  1197. $response = new stdClass();
  1198. $createdId = null;
  1199. try {
  1200. $item = $acl->convertObjectFromUserInput($args, $type = 'array_by_id', $prefix = 'f');
  1201. $createdId = $acl->addItem($item);
  1202. if ($createdId) {
  1203. $response->type = 'success';
  1204. $response->msg = "Utworzono pomyślnie rekord nr {$createdId}";
  1205. $response->id = $createdId;
  1206. $response->record = $acl->buildQuery([])->getItem($createdId);
  1207. }
  1208. else {
  1209. $response->type = 'error';
  1210. $response->msg = "Nie udało się utworzyć nowego rekordu!";
  1211. }
  1212. }
  1213. catch (Exception $e) {
  1214. $response->type = 'error';
  1215. $response->msg = $e->getMessage();
  1216. }
  1217. return $response;
  1218. }
  1219. private function ajaxCopy($args) {
  1220. $acl = $this->_acl;
  1221. $id = V::get('ID', 0, $_REQUEST, 'int');
  1222. if ($id <= 0) {
  1223. throw new HttpException("Wrong param ID!", 404);
  1224. }
  1225. $item = $acl->buildQuery([])->getItem($id);
  1226. if (!$item) {
  1227. throw new HttpException("Item '{$id}' not exists!", 404);
  1228. }
  1229. $response = new stdClass();
  1230. $itemCopy = $acl->createItemCopy($item);
  1231. $createdId = null;
  1232. try {
  1233. $createdId = $acl->addItem($itemCopy);
  1234. if ($createdId) {
  1235. $response->type = 'success';
  1236. $response->msg = "Rekord skopiowany pomyślnie - utworzono rekord nr {$createdId}";
  1237. $response->id = $createdId;
  1238. $response->record = $acl->buildQuery([])->getItem($createdId);
  1239. }
  1240. else {
  1241. $response->type = 'error';
  1242. $response->msg = "Nie udało się skopiować rekordu!";
  1243. }
  1244. }
  1245. catch (Exception $e) {
  1246. $response->type = 'error';
  1247. $response->msg = "Wystąpiły błędy!";
  1248. $response->msg = $e->getMessage();
  1249. }
  1250. return $response;
  1251. }
  1252. private function ajaxHist($args) {
  1253. $jsonResponse = array();
  1254. $id = V::get('ID', 0, $args, 'int');
  1255. $acl = $this->_acl;
  1256. $record = $acl->buildQuery([])->getItem($id);
  1257. if (!$record) throw new HttpException("404: No item ID({$id})", 404);
  1258. $visibleCols = $acl->getRealFieldList();
  1259. try {
  1260. $rowsHist = $acl->getHistItems($id);
  1261. } catch (Exception $e) {
  1262. DBG::log($e);
  1263. $rowsHist = [];
  1264. }
  1265. $jsonResponse['row_functions'] = $this->_parseRowFunctions($record['ID'], array('hist', 'cp'), $showLabel = true);
  1266. $visibleColsWithIds = array();
  1267. $visibleColsLabels = array();
  1268. foreach ($visibleCols as $vColName) {
  1269. $fldId = $acl->getFieldIdByName($vColName);
  1270. if ($fldId) {
  1271. $visibleColsWithIds[$fldId] = $vColName;
  1272. $label = $acl->getFieldLabel($vColName);
  1273. $label = (!$label)? $vColName : '<span title="' . "[{$fldId}] {$vColName}" . '">' . $label . '</span>';
  1274. $visibleColsLabels[$fldId] = $label;
  1275. }
  1276. }
  1277. $jsonResponse['label'] = "Historia rekordu Nr {$id}";
  1278. $jsonResponse['fields'] = array_values($visibleColsWithIds);
  1279. $jsonResponse['field_label'] = $visibleColsLabels;
  1280. if (empty($rowsHist)) return $jsonResponse;
  1281. $jsonResponse['rows'] = array();
  1282. foreach ($rowsHist as $histRow) {
  1283. $histItem = array();
  1284. $histItem['ID'] = V::get('ID', '', $histRow);
  1285. $histItem['_created'] = V::get('_created', '', $histRow);
  1286. $histItem['_author'] = V::get('_author', '', $histRow);
  1287. $histItem['changes'] = array();
  1288. foreach ($visibleColsWithIds as $fldId => $fieldName) {
  1289. if (!array_key_exists($fieldName, (array)$histRow)) continue;
  1290. $value = V::get($fieldName, '', $histRow);
  1291. if ('N/S;' == $value) continue;
  1292. $changeItem = array();
  1293. $changeItem['fieldName'] = $fieldName;
  1294. $changeItem['acl_read'] = $acl->canReadObjectField($fieldName, $record);
  1295. if ($changeItem['acl_read']) {
  1296. $changeItem['value'] = V::get($fieldName, '', $histRow);
  1297. }
  1298. if ('the_geom' == $fieldName && $acl->canWriteObjectField($fieldName, $record)) {
  1299. $sourceName = $acl->getSourceName();
  1300. if ('default_db' == $sourceName && !empty($value)) {
  1301. $typeName = $acl->getName();
  1302. $idHist = V::get('ID', '', $histRow);
  1303. $changeItem['revert_function_url'] = Request::getPathUri() . "index.php?_route=ViewTableAjax&typeName=p5_{$sourceName}:{$typeName}&_task=revertFromHistAjax&ID={$id}&idHist={$idHist}&fieldName={$fieldName}";
  1304. $changeItem['revert_function_data'] = "ID={$id}&idHist={$idHist}&fieldName={$fieldName}";
  1305. }
  1306. }
  1307. $histItem['changes'][$fieldName] = $changeItem;
  1308. }
  1309. $jsonResponse['rows'][] = $histItem;
  1310. }
  1311. return $jsonResponse;
  1312. }
  1313. public function ajaxFileUpload($args) {
  1314. $id = V::get('ID', 0, $args, 'int');
  1315. if ($id <= 0) throw new HttpException("404", 404);
  1316. $dbID = $this->_acl->getDB();
  1317. $db = DB::getDB($dbID);
  1318. if (!$db) throw new HttpException("No DB ({$dbID})", 406);
  1319. $record = $this->_acl->buildQuery([])->getItem($id);
  1320. if (!$record) throw new HttpException("No item ID({$id})", 404);
  1321. if (!$this->_acl->canReadRecord($record)) throw new Exception("Brak uprawnień do odczytu");
  1322. if (!$this->_acl->canWriteRecord($record)) throw new Exception("Brak uprawnień do zapisu");
  1323. $tblName = $this->_acl->getName();
  1324. $confTblName = "{$tblName}_COLUMN";
  1325. $folderConfAll = FoldersConfig::getRawData();
  1326. if (!FoldersConfig::hasConfig($confTblName)) throw new HttpException("Brak danych konfiguracyjnych ({$tblName})", 404);
  1327. $folderConf = FoldersConfig::getAll($confTblName);
  1328. $uploader = new FileUploader($confTblName, (object)$record);
  1329. if (!$uploader->setConfig($folderConf)) throw new HttpException("Błąd danych konfiguracyjnych ({$tblName})", 404);
  1330. $uploader->findFolder();
  1331. $errorMsg = '';
  1332. if (!empty($args['SCANS_COLUMN_ADD'])) {
  1333. $uploaded = $uploader->tryMoveFromScanAjax($errorMsg);
  1334. }
  1335. else {
  1336. $uploaded = $uploader->tryUploadAjax($errorMsg);
  1337. }
  1338. $retJson = new stdClass();
  1339. if (!$uploaded) throw new Exception($errorMsg);
  1340. $uploadedFileName = '';
  1341. $uploadedFile = $uploader->getLastUploadedFile();
  1342. if ($uploadedFile) {
  1343. $uploadedFileName = explode('/', $uploadedFile);
  1344. $uploadedFileName = end($uploadedFileName);
  1345. }
  1346. //echo '{"type":"SUCCESS", "string": "Plik został poprawnie wgrany do odpowiedniego katalogu '.$uploadedFileName.'"}';
  1347. $retJson->type = 'SUCCESS';
  1348. $retJson->msg = "Plik został poprawnie wgrany do odpowiedniego katalogu {$uploadedFileName}";
  1349. if (!empty($uploadedFileName)) {
  1350. $sqlObj = new stdClass();
  1351. $sqlObj->ID = $record['ID'];
  1352. $sqlObj->M_DIST_FILES = "Wgrano plik {$uploadedFileName}";
  1353. $db->UPDATE_OBJ($this->_tbl, $sqlObj);
  1354. }
  1355. return $retJson;
  1356. }
  1357. public function ajaxFileList($args) {
  1358. $id = V::get('ID', 0, $args, 'int');
  1359. if ($id <= 0) throw new HttpException("404", 404);
  1360. $dbID = $this->_acl->getDB();
  1361. $db = DB::getDB($dbID);
  1362. if (!$db) throw new HttpException("No DB ({$dbID})", 406);
  1363. $record = $this->_acl->buildQuery([])->getItem($id);
  1364. if (!$record) throw new HttpException("No item ID({$id})", 404);
  1365. if (!$this->_acl->canReadRecord($record)) throw new Exception("Brak uprawnień do odczytu");
  1366. $tblName = $this->_acl->getName();
  1367. $confTblName = "{$tblName}_COLUMN";
  1368. $folderConfAll = FoldersConfig::getRawData();
  1369. if (!FoldersConfig::hasConfig($confTblName)) throw new HttpException("Brak danych konfiguracyjnych ({$tblName})", 404);
  1370. $folderConf = FoldersConfig::getAll($confTblName);
  1371. $uploader = new FileUploader($confTblName, (object)$record);
  1372. if (!$uploader->setConfig($folderConf)) throw new HttpException("Błąd danych konfiguracyjnych ({$tblName})", 404);
  1373. $uploader->findFolder();
  1374. $mainFolder = $uploader->getDestFolder();
  1375. $files = $uploader->getFilesFromFolder($mainFolder, false, true);
  1376. $localPath = $uploader->getLocalPath();
  1377. $folderWeb = $uploader->getFolderWeb();
  1378. $jsonFiles = $this->convertFileListToJson($files, $folderWeb, $localPath, $mainFolder);
  1379. return $jsonFiles;
  1380. }
  1381. private function ajaxFilePermsRefresh($args) {
  1382. $id = V::get('ID', 0, $args, 'int');
  1383. if ($id <= 0) throw new HttpException("Wrong param ID", 404);
  1384. $dbID = $this->_acl->getDB();
  1385. $db = DB::getDB($dbID);
  1386. if (!$db) throw new HttpException("No DB", 406);
  1387. $record = $this->_acl->buildQuery([])->getItem($id);
  1388. if (!$record) throw new Exception("No item ID({$id})", 404);
  1389. $tblName = $this->_acl->getName();
  1390. // TODO: SyncPermsCustomTables->getRecordTask($tbl, $id);
  1391. $sql_L_APPOITMENT_USER = V::get('L_APPOITMENT_USER', '', $record);
  1392. $sql_A_ADM_COMPANY = V::get('A_ADM_COMPANY', '', $record);
  1393. $sql_A_CLASSIFIED = V::get('A_CLASSIFIED', '', $record);
  1394. $mainDB = DB::getDB();
  1395. if ('IN7_MK_BAZA_DYSTRYBUCJI' == $tblName) {
  1396. $sql = "insert into `_SYNC_FILE_PERMS` (
  1397. `ID_PROJECT`,
  1398. `A_SYNCHRONIZED`
  1399. )
  1400. values (
  1401. '{$record['ID']}'
  1402. , 0
  1403. )
  1404. ON DUPLICATE KEY UPDATE
  1405. `A_SYNCHRONIZED`=0
  1406. ";
  1407. }
  1408. else if ('IN7_DZIENNIK_KORESP' == $tblName) {
  1409. $sql = "insert into `_SYNC_FILE_PERMS` (
  1410. `ID_PROJECT`,
  1411. `A_SYNCHRONIZED`
  1412. )
  1413. values (
  1414. '{$record['ID_PROJECT']}'
  1415. , 0
  1416. )
  1417. ON DUPLICATE KEY UPDATE
  1418. `A_SYNCHRONIZED`=0
  1419. ";
  1420. }
  1421. else {
  1422. $sql = "insert into `_SYNC_TABLE_FILE_PERMS` (
  1423. `TBL_NAME`,
  1424. `TBL_ID`,
  1425. `L_APPOITMENT_USER`,
  1426. `A_ADM_COMPANY`,
  1427. `A_CLASSIFIED`,
  1428. `A_SYNCHRONIZED`
  1429. )
  1430. values (
  1431. '{$tblName}'
  1432. , '{$id}'
  1433. , '{$sql_L_APPOITMENT_USER}'
  1434. , '{$sql_A_ADM_COMPANY}'
  1435. , '{$sql_A_CLASSIFIED}'
  1436. , 0
  1437. )
  1438. ON DUPLICATE KEY UPDATE
  1439. `A_SYNCHRONIZED`=0
  1440. ";
  1441. }
  1442. $res = $mainDB->query($sql);
  1443. if ($mainDB->has_errors()) {
  1444. //echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;"> (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql);echo'</pre>';
  1445. //echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;"> (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($mainDB->get_errors());echo'</pre>';
  1446. throw new Exception("Nie udało się dodać zadania");
  1447. }
  1448. // TODO: this blocks browser ajax query
  1449. //$limit = 3;
  1450. //while ($limit--) {
  1451. // sleep(10);
  1452. // TODO: check if task is done
  1453. //}
  1454. $confTblName = "{$tblName}_COLUMN";
  1455. $folderConfAll = FoldersConfig::getRawData();
  1456. if (!FoldersConfig::hasConfig($confTblName)) {
  1457. throw new Exception("Brak danych konfiguracyjnych ({$tblName})", 404);
  1458. }
  1459. $folderConf = FoldersConfig::getAll($confTblName);
  1460. $uploader = new FileUploader($confTblName, (object)$record);
  1461. if (!$uploader->setConfig($folderConf)) {
  1462. throw new Exception("Błąd danych konfiguracyjnych ({$tblName})", 404);
  1463. }
  1464. $uploader->findFolder();
  1465. $mainFolder = $uploader->getDestFolder();
  1466. $files = $uploader->getFilesFromFolder($mainFolder, false, true);
  1467. $localPath = $uploader->getLocalPath();
  1468. $folderWeb = $uploader->getFolderWeb();
  1469. $jsonData = new stdClass();
  1470. $jsonData->msg = 'Zadanie dodane';
  1471. $jsonData->type = 'success';
  1472. $jsonData->files = $this->convertFileListToJson($files, $folderWeb, $localPath, $mainFolder);
  1473. return $jsonData;
  1474. }
  1475. private function sendAjaxFilesConnTblList($id, $args) {
  1476. header("Content-type: application/json");
  1477. $DBG = ('1' == V::get('DBG', '', $_REQUEST));
  1478. $dbID = $this->_acl->getDB();
  1479. $db = DB::getDB($dbID);
  1480. if (!$db) {
  1481. header('HTTP/1.0 406 Not Acceptable');
  1482. echo 'No DB (' . $dbID . ')';
  1483. exit;
  1484. }
  1485. $record = $this->_acl->buildQuery([])->getItem($id);
  1486. if (!$record) {
  1487. header('HTTP/1.0 404 Not Found');
  1488. echo 'No item ID(' . $rowID . ')';
  1489. exit;
  1490. }
  1491. $connTblName = '';
  1492. $connTblID = V::get('connTblID', 0, $_REQUEST, 'int');
  1493. if ($connTblID <= 0) {
  1494. header('HTTP/1.0 406 Not Acceptable');
  1495. echo 'No conn Table ID';
  1496. exit;
  1497. }
  1498. $connTblTypespecials = $this->getConnectedTblTypespecials($connTblID);
  1499. if (empty($connTblTypespecials)) {
  1500. header('HTTP/1.0 406 Not Acceptable');
  1501. echo "No conn Table (ID={$connTblID})";
  1502. exit;
  1503. }
  1504. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">connTblTypespecials (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($connTblTypespecials);echo'</pre>';}
  1505. if(1) {
  1506. header('HTTP/1.0 404 Not Found');
  1507. echo 'TODO: ...';
  1508. exit;
  1509. }
  1510. $tblName = $this->_acl->getName();
  1511. $confTblName = "{$tblName}_COLUMN";
  1512. $folderConfAll = FoldersConfig::getRawData();
  1513. if (!FoldersConfig::hasConfig($confTblName)) {
  1514. header('HTTP/1.0 404 Not Found');
  1515. echo '{"type":"ERROR", "string": "Brak danych konfiguracyjnych (' . $tblName . ')"}';
  1516. exit;
  1517. }
  1518. $folderConf = FoldersConfig::getAll($confTblName);
  1519. $uploader = new FileUploader($confTblName, (object)$record);
  1520. if (!$uploader->setConfig($folderConf)) {
  1521. header('HTTP/1.0 404 Not Found');
  1522. echo '{"type":"ERROR", "string": "Błąd danych konfiguracyjnych (' . $tblName . ')"}';
  1523. exit;
  1524. }
  1525. $uploader->findFolder();
  1526. $mainFolder = $uploader->getDestFolder();
  1527. $files = $uploader->getFilesFromFolder($mainFolder, false, true);
  1528. $localPath = $uploader->getLocalPath();
  1529. $folderWeb = $uploader->getFolderWeb();
  1530. $jsonFiles = $this->convertFileListToJson($files, $folderWeb, $localPath, $mainFolder);
  1531. echo json_encode($jsonFiles);
  1532. exit;
  1533. }
  1534. public function convertFileListToJson($files, $folderWeb, $localPath, $mainFolder) {
  1535. $jsonFiles = array();
  1536. if (!is_array($files) || empty($files)) {
  1537. return $jsonFiles;
  1538. }
  1539. sort($files);
  1540. foreach ($files as $vFilePath) {
  1541. $file = new stdClass();
  1542. $file->name = str_replace("{$localPath}/{$mainFolder}/", '', $vFilePath);
  1543. //$file->name = explode('/', $vFilePath);
  1544. //$file->name = end($file->name);
  1545. $file->size = filesize($vFilePath);
  1546. $file->sizeStr = V::humanFileSize($file->size);
  1547. $file->type = '';
  1548. $file->created = date("Y-m-d H:i:s", filectime($vFilePath));
  1549. $file->web = str_replace($localPath, $folderWeb, $vFilePath);
  1550. $jsonFiles[] = $file;
  1551. }
  1552. return $jsonFiles;
  1553. }
  1554. private function getConnectedTables() {
  1555. $connTbls = array();
  1556. return $connTbls;// TODO: OFF - hardlinki tworzone w bash_sync_perms.php
  1557. $fields = $this->_acl->getVirtualFieldListByIdZasob();
  1558. if (!empty($fields)) {
  1559. foreach ($fields as $vColID => $vCol) {
  1560. $typeSpecial = Typespecial::getInstance($vColID);
  1561. if ($typeSpecial) {
  1562. $tsConnTbls = $typeSpecial->getTblAliasList();
  1563. if (!empty($tsConnTbls)) {
  1564. foreach ($tsConnTbls as $kID => $vName) {
  1565. $connTbls[$kID] = $vName;
  1566. }
  1567. }
  1568. }
  1569. }
  1570. }
  1571. return $connTbls;
  1572. }
  1573. private function getConnectedTblTypespecials($connTblID) {
  1574. $connTblTypespecials = array();
  1575. $fields = $this->_acl->getVirtualFieldListByIdZasob();
  1576. if (!empty($fields)) {
  1577. foreach ($fields as $vColID => $vCol) {
  1578. $typeSpecial = Typespecial::getInstance($vColID);
  1579. if ($typeSpecial) {
  1580. $tsConnTbls = $typeSpecial->getTblAliasList();
  1581. if (array_key_exists($connTblID, $tsConnTbls)) {
  1582. $connTblTypespecials[] = $typeSpecial;
  1583. }
  1584. }
  1585. }
  1586. }
  1587. return $connTblTypespecials;
  1588. }
  1589. private function sendAjaxFiles($id, $args) {
  1590. header("Content-type: text/plain");
  1591. $DBG = ('1' == V::get('DBG', '', $_REQUEST));
  1592. $acl = $this->_acl;
  1593. $dbID = $acl->getDB();
  1594. $db = DB::getDB($dbID);
  1595. if (!$db) throw new HttpException("", 406);
  1596. $record = $acl->buildQuery([])->getItem($id);
  1597. if (!$record) throw new HttpException("404: No item ID({$rowID})", 404);
  1598. if (!$acl->canReadRecord($record)) throw new Exception("Brak uprawnień do odczytu");
  1599. $tblName = $acl->getName();
  1600. $confTblName = "{$tblName}_COLUMN";
  1601. $folderConfAll = FoldersConfig::getRawData();
  1602. if (!FoldersConfig::hasConfig($confTblName)) throw new HttpException("Brak danych konfiguracyjnych", 404);
  1603. $folderConf = FoldersConfig::getAll($confTblName);
  1604. //echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">$folderConf (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($folderConf);echo'</pre>';
  1605. $uploader = new FileUploader($confTblName, (object)$record);
  1606. $errMsg = '';
  1607. if (!$uploader->setConfig($folderConf, $errMsg)) throw new HttpException("Błąd danych konfiguracyjnych ({$tblName})" . '<br>' . "\n" . $errMsg, 404);
  1608. $uploader->findFolder();
  1609. if($DBG){ echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">uploader (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($uploader);echo'</pre>'; }
  1610. $mainFolder = $uploader->getDestFolder();
  1611. if($DBG){ echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">mainFolder (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($mainFolder);echo'</pre>'; }
  1612. if (!$mainFolder) {
  1613. $destFolderPath = $uploader->getDestLocalPath(true);
  1614. $folderCreated = $uploader->tryCreateDestFolder($destFolderPath);
  1615. if ($folderCreated) {
  1616. //UI::alert('info', "Utworzono katalog");
  1617. $uploader->findFolder();
  1618. $mainFolder = $uploader->getDestFolder();
  1619. } else {
  1620. UI::alert('warning', "Nie udało się utworzyć katalogu");
  1621. }
  1622. }
  1623. $files = $uploader->getFilesFromFolder($mainFolder, false, true);
  1624. if($DBG){ echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">files (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($files);echo'</pre>'; }
  1625. $sharePoint = V::get('share_point', null, $folderConf);
  1626. if ($sharePoint) {
  1627. if ('//' == substr($mainFolder, 0, 2)) {
  1628. $sharePoint = FoldersConfig::getNfsOsPath() . "{$mainFolder}";
  1629. } else {
  1630. $sharePoint = FoldersConfig::getNfsOsPath() . "{$sharePoint}/{$mainFolder}";
  1631. }
  1632. }
  1633. $localPath = $uploader->getLocalPath();
  1634. $folderWeb = $uploader->getFolderWeb();
  1635. $jsonFiles = $this->convertFileListToJson($files, $folderWeb, $localPath, $mainFolder);
  1636. if($DBG){ echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">jsonFiles (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($jsonFiles);echo'</pre>'; }
  1637. $folderSkanyConf = FoldersConfig::getAll('SCANS_COLUMN');
  1638. $skanyLocalPath = V::get('mount_point', null, $folderSkanyConf);
  1639. $skanySharePoint = V::get('share_point', null, $folderSkanyConf);
  1640. $skanyFolderWeb = V::get('www_share_point', null, $folderSkanyConf);
  1641. $skanyFiles = $uploader->getFilesFromSkany($folderSkanyConf, false);
  1642. sort($skanyFiles);
  1643. $fileTypes = FoldersConfig::getAll('m_dist_files_types');
  1644. $rowFunctionsOut = $this->_showRowFunctions($record['ID'], array('files', 'cp'), true);
  1645. $fileIndexField = V::get('DEST_FILE_INDEX_FIELD', 'ID', $folderConf);
  1646. $fileIndex = V::get($fileIndexField, $record['ID'], $record);
  1647. $namespace = $acl->getNamespace();
  1648. echo UI::h('div', [ 'class' => "container" ], [
  1649. UI::h('h4', [ 'style' => "margin:20px 0 3px 0;" ], [
  1650. "Pliki w katalogu ",
  1651. ($sharePoint)
  1652. ? UI::h('a', [ 'href' => $sharePoint ], [
  1653. UI::h('span', [ 'class' => "glyphicon glyphicon-folder-open" ]),
  1654. UI::h('code', [ 'style' => "margin-left:6px" ], $mainFolder),
  1655. ])
  1656. : UI::h('code', [], $mainFolder),
  1657. UI::h('span', [ 'class' => "pull-right valign-btns-bottom" ], [
  1658. UI::h('span', [ 'id' => "FILES_LIST_ACTIONS_{$this->_htmlID}" ]),
  1659. " {$rowFunctionsOut}",
  1660. ]),
  1661. ]),
  1662. UI::h('div', [ 'style' => "clear:both; max-height:180px; overflow:auto; border-bottom:1px solid #ddd;" ], [
  1663. UI::h('table', [ 'class' => "table table-bordered table-hover" ], [
  1664. UI::h('colgroup', [], [
  1665. UI::h('col', [ 'style' => "" ]),
  1666. UI::h('col', [ 'style' => "width:30px" ]),
  1667. ($sharePoint)
  1668. ? UI::h('col', [ 'style' => "width:30px" ])
  1669. : '',
  1670. UI::h('col', [ 'style' => "width:80px" ]),
  1671. UI::h('col', [ 'style' => "width:140px" ]),
  1672. ]),
  1673. UI::h('tbody', [ 'id' => "FILES_LIST_{$this->_htmlID}" ], [
  1674. (empty($mainFolder) || empty($files))
  1675. ? UI::h('tr', [], [
  1676. UI::h('td', [ 'colspan' => "5" ], [
  1677. (empty($mainFolder))
  1678. ? UI::h('div', [ 'class' => "alert alert-warning" ], [
  1679. UI::h('h4', [], "Brak folderu!"),
  1680. "Folder dla tego rekordu nie został utworzony."
  1681. ])
  1682. : UI::h('div', [ 'class' => "alert alert-info" ], [
  1683. UI::h('h4', [], "Brak plików!"),
  1684. ])
  1685. ]),
  1686. ])
  1687. : '',
  1688. ]),
  1689. ]),
  1690. ]),
  1691. UI::h('br'),
  1692. UI::h('br'),
  1693. (!$this->_acl->canWriteRecord($record))
  1694. ? UI::h('div', [ 'class' => "alert alert-warning" ], [
  1695. "Brak uprawnień do dodawania plików",
  1696. ])
  1697. : UI::h('div', [ 'id' => "FILES_CONN_TBLS_{$this->_htmlID}" ]),
  1698. (!$this->_acl->canWriteRecord($record))
  1699. ? ''
  1700. : UI::h('form', [ 'enctype' => "multipart/form-data", 'method' => "POST", 'action' => "", 'id' => "FILES_FRM_{$this->_htmlID}", 'class' => "form-inline" ], [
  1701. UI::h('input', [ 'type' => "hidden", 'name' => "M_DIST_UPLOAD_SOURCE", 'value' => "local" ]),
  1702. UI::h('ul', [ 'id' => "FILES_TAB_{$this->_htmlID}", 'class' => "nav nav-tabs", 'style' => "margin:0;"], [
  1703. UI::h('li', [ 'class' => "active" ], [ UI::h('a', [ 'href' => "#local", 'data-toggle' => "local" ], "Wybierz plik lokalny"), ]),
  1704. UI::h('li', [], [ UI::h('a', [ 'href' => "#scan", 'data-toggle' => "scan" ], "Wybierz plik ze skanów" ), ]),
  1705. UI::h('li', [], [ UI::h('a', [ 'href' => "#multiple", 'data-toggle' => "multiple" ], "Wgraj wiele plików" ), ]),
  1706. ]),
  1707. UI::h('div', [ 'id' => "myTabContent", 'class' => "tab-content" ], [
  1708. UI::h('div', [ 'class' => "tab-pane fade in active", 'id' => "local", 'style' => "text-align: center;" ], [
  1709. UI::h('input', [ 'name' => "M_DIST_FILES_NAME", 'type' => "file", 'size' => "60", 'class' => "field-upload btn",
  1710. 'style' => "width:86%;margin:10px auto;padding:10px 4%;background:#eee;text-align:center",
  1711. 'ondragover' => "this.style.backgroundColor='#D9EDF7'",
  1712. 'ondragleave' => "this.style.backgroundColor='#eee'",
  1713. 'ondragend' => "this.style.backgroundColor='#eee'",
  1714. ]),
  1715. ]),
  1716. UI::h('div', [ 'class' => "tab-pane fade", 'id' => "multiple" ], [
  1717. UI::h('div', [
  1718. 'id' => "FILES_MULTIPLE_UPLOAD_{$this->_htmlID}",
  1719. 'style' => "width:86%; margin:10px auto; padding:40px 100px; background-color:#eee; border-radius:4px; text-align:center",
  1720. 'ondrop' => "p5TAFiles_onDropMultiple(event, this, '{$id}', '{$namespace}')",
  1721. 'ondragover' => "p5TAFiles_onDragOverMultiple(event, this)", // "event.preventDefault(); this.style.backgroundColor='#D9EDF7'",
  1722. 'ondragleave' => "p5TAFiles_onDragLeaveMultiple(event, this)", // "event.preventDefault(); this.style.backgroundColor='#eee'",
  1723. 'ondragend' => "p5TAFiles_onDragEndMultiple(event, this)", // "event.preventDefault(); this.style.backgroundColor='#eee'",
  1724. ], [
  1725. "Upuść pliki tutaj",
  1726. ]),
  1727. ]),
  1728. UI::h('div', [ 'class' => "tab-pane fade", 'id' => "scan" ], [
  1729. (empty($skanyFiles))
  1730. ? UI::h('div', [ 'class' => "alert alert-info" ], [
  1731. UI::h('h4', [], "Brak plików"),
  1732. (!empty($skanyFolderWeb))
  1733. ? "skonfiguruj urządzenie biurowe aby wysyłało skany na ftp://skaner:(h*a*s*l*o)@".$_SERVER['SERVER_NAME']." <br> lub <a href=".FoldersConfig::getNfsOsPath().$skanySharePoint.">".FoldersConfig::getNfsOsPath().$skanySharePoint."</a>"
  1734. : '',
  1735. ])
  1736. : UI::h('div', [ 'style' => "max-height:150px; overflow:auto; border-bottom:1px solid #ddd;" ], [
  1737. UI::h('table', [ 'class' => "table table-bordered table-hover" ], [
  1738. UI::h('colgroup', [], [
  1739. UI::h('col', [ 'style' => "width:30px;" ]),
  1740. UI::h('col', [ 'style' => "" ]),
  1741. UI::h('col', [ 'style' => "width:30px;" ]),
  1742. UI::h('col', [ 'style' => "width:80px;" ]),
  1743. UI::h('col', [ 'style' => "width:140px;" ]),
  1744. ]),
  1745. UI::h('tbody', [], array_map(function ($vFilePath) use ($skanyLocalPath, $skanyFolderWeb) {
  1746. $vFileName = explode('/', $vFilePath);
  1747. $vFileName = end($vFileName);
  1748. $vFileSize = filesize($vFilePath);
  1749. $vFileSizeOut = V::humanFileSize($vFileSize);
  1750. return UI::h('tr', [], [
  1751. UI::h('td', [], [ UI::h('input', [ 'style' => "margin:0", 'type' => "radio", 'name' => "SCANS_COLUMN_ADD", 'value' => $vFileName]) ]),
  1752. UI::h('td', [], [ UI::h('div', [ 'style' => "overflow:hidden; white-space:nowrap", 'title' => $vFileName ], $vFileName) ]),
  1753. UI::h('td', [ 'style' => "white-space:nowrap; text-align:center" ], [
  1754. UI::h('a', [ 'href' => str_replace($skanyLocalPath, $skanyFolderWeb, $vFilePath), 'target' => "_blank", 'class' => "glyphicon glyphicon-download-alt" ])
  1755. ]),
  1756. UI::h('td', [ 'style' => "white-space:nowrap; text-align:right" ], $vFileSizeOut),
  1757. UI::h('td', [ 'style' => "white-space:nowrap" ], date("Y-m-d H:i:s", filectime($vFilePath))),
  1758. ]);
  1759. }, $skanyFiles)),
  1760. ])
  1761. ]),
  1762. ])
  1763. ]),
  1764. UI::h('br'),
  1765. UI::h('h4', [], [
  1766. "Ustal nazwę pliku zgodną z obiegiem dokumentów",
  1767. //TODO: link do procesu o obiegu dokumentów <i class="glyphicon glyphicon-question-sign" style="cursor:help" title="działa w nowszych przeglądarkach jak Firefox, Chrome"></i>
  1768. ]),
  1769. UI::h('table', [ 'style' => "width:100%", 'class' => "table table-bordered" ], [
  1770. UI::h('tr', [], [
  1771. UI::h('th', [], "Nr"),
  1772. UI::h('th', [], "Typ"),
  1773. UI::h('th', [ 'style' => "width:40%" ], [
  1774. "Opis ",
  1775. UI::h('i', [ 'class' => "glyphicon glyphicon-question-sign", 'title' => "kogo dotyczy / czego / sprawa / nazwa_firmy itp" ]),
  1776. ]),
  1777. UI::h('th', [ 'style' => "width:16%" ], "Data wersji"),
  1778. UI::h('th', [ 'style' => "width:12%" ], "Numer wersji"),
  1779. ]),
  1780. UI::h('tr', [], [
  1781. UI::h('td', [], $fileIndex),
  1782. UI::h('td', [], [
  1783. UI::h('select', [ 'class' => "form-control", 'name' => "M_DIST_FILES_TYPE" ], array_map(function ($vLabel, $kType) {
  1784. return UI::h('option', array_merge([ 'value' => $kType],
  1785. ($kType == 'TODO')
  1786. ? [ 'selected' => "selected"]
  1787. : []
  1788. ), $vLabel);
  1789. }, $fileTypes, array_keys($fileTypes)) ),
  1790. UI::h('br'),
  1791. UI::h('label', [ 'class' => "checkbox" ], [
  1792. UI::h('input', [ 'type' => "checkbox", 'name' => "M_DIST_FILES_TYPE_AUTO" ]),
  1793. " Wykrycie automatyczne typu z wysylanego pliku",
  1794. ]),
  1795. UI::h('label', [ 'class' => "checkbox" ], [
  1796. UI::h('input', [ 'type' => "checkbox", 'name' => "M_DIST_FILES_TEMP" ]),
  1797. " Plik tymczasowy / roboczy / nieoficjalny (_TEMP)",
  1798. ]),
  1799. ]),
  1800. UI::h('td', [], [
  1801. UI::h('input', [ 'class' => "form-control", 'style' => "width:100%", 'type' => "text", 'name' => "M_DIST_FILES_DESCRIPTION", 'value' => "", 'maxlength' => "50" ]),
  1802. "<br><label>jeśli nie zostanie podany to zostanie automatycznie wygenerowany na podstawie nazwy pliku wysyłanego</label>",
  1803. ]),
  1804. UI::h('td', [], [
  1805. UI::h('div', [ 'class' => "input-group" ], [
  1806. UI::h('input', [ 'name' => "M_DIST_FILES_DATE", 'type' => "text", 'value' => date('Y-m-d'), 'class' => "se_type-date form-control", 'data-format' => "yyyy-MM-dd", 'maxlength' => "10" ]),
  1807. UI::h('span', [ 'class' => "input-group-addon" ], [
  1808. UI::h('span', [ 'class' => "glyphicon glyphicon-calendar" ]),
  1809. ]),
  1810. ]),
  1811. // UI::h('input', [ 'class' => "form-control", 'type' => "date", 'name' => "M_DIST_FILES_DATE", 'value' => date('Y-m-d'), 'maxlength' => "10" ]),
  1812. "<br><label>jeśli nie zostanie podana to zostanie ustawiona na dzisiaj (" . date('Y-m-d') . ")</label>",
  1813. ]),
  1814. UI::h('td', [], [
  1815. UI::h('input', [ 'class' => "form-control", 'style' => "width:100%", 'type' => "number", 'name' => "M_DIST_FILES_VERSION" ]),
  1816. UI::h('br'),
  1817. UI::h('label', [ 'class' => "checkbox" ], [
  1818. UI::h('input', [ 'type' => "checkbox", 'name' => "M_DIST_FILES_VERSION_AUTO" ]),
  1819. " Automatycznie dodaj wersje",
  1820. ]),
  1821. ]),
  1822. ]),
  1823. UI::h('tr', [], [
  1824. UI::h('td', [ 'colspan' => "5" ], [
  1825. UI::h('div', [ 'id' => "FRM_UPLOAD_RESULTS_{$this->_htmlID}" ]),
  1826. UI::h('p', [], [
  1827. UI::h('input', [ 'type' => "submit", 'value' => "Wyślij", 'class' => "btn btn-primary" ], "wybrany plik do folderu:"),
  1828. ]),
  1829. UI::h('p', [], [
  1830. UI::h('code', [], [
  1831. UI::h('b', [], $uploader->getDestPathShare(true)),
  1832. ]),
  1833. UI::h('br'),
  1834. UI::h('i', [ 'style' => "color:#777" ], "(Jeśli folder nie istnieje to zostanie utworzony automatycznie)"),
  1835. ]),
  1836. ]),
  1837. ]),
  1838. ]),
  1839. ]),
  1840. ]);
  1841. $className = __CLASS__;
  1842. $namespace = $acl->getNamespace();
  1843. UI::inlineJS(__FILE__ . '.files.js', [
  1844. 'UNIQ_HASH' => $this->_htmlID,
  1845. 'FUNCTION_FILE_LIST_UPDATE_AJAX' => "fileListUpdateAjax{$this->_htmlID}", // fileListUpdateAjax
  1846. 'FUNCTION_FILE_LIST_UPDATE' => "fileListUpdate{$this->_htmlID}", // fileListUpdate
  1847. 'FUNCTION_CONN_TBL_LIST_UPDATE_AJAX' => "connTblListUpdateAjax{$this->_htmlID}", // connTblListUpdateAjax
  1848. 'FUNCTION_CONN_TBL_LIST_UPDATE' => "connTblListUpdate{$this->_htmlID}", // connTblListUpdate
  1849. 'FUNCTION_FILE_LIST_ACTIONS' => "fileListActions{$this->_htmlID}", // fileListActions
  1850. 'CONN_TABLES' => $this->getConnectedTables(),
  1851. 'NODE_ID_FILES_FRM' => "FILES_FRM_{$this->_htmlID}",
  1852. 'NODE_ID_FRM_UPLOAD_RESULTS' => "FRM_UPLOAD_RESULTS_{$this->_htmlID}",
  1853. 'NODE_ID_FILES_TAB' => "FILES_TAB_{$this->_htmlID}",
  1854. 'NODE_ID_FILES_LIST' => "FILES_LIST_{$this->_htmlID}",
  1855. 'NODE_ID_FILES_CONN_TBLS' => "FILES_CONN_TBLS_{$this->_htmlID}",
  1856. 'NODE_ID_FILES_LIST_ACTIONS' => "FILES_LIST_ACTIONS_{$this->_htmlID}",
  1857. 'NODE_ID_FILES_MULTIPLE_UPLOAD' => "FILES_MULTIPLE_UPLOAD_{$this->_htmlID}",
  1858. 'URL_FILE_LIST_UPDATE_AJAX' => "index-ajax.php?_zasobID={$this->_zasobID};&_cls={$className}&_hash={$this->_htmlID}&_task=FILES_LIST&ID={$record['ID']}",
  1859. 'URL_FILE_REMOVE_AJAX' => "index.php?_route=ViewTableAjax&namespace={$namespace}&_task=removeFileAjax&ID={$record['ID']}",
  1860. 'URL_CONNECTED_TABLE_LIST' => "index-ajax.php?_zasobID={$this->_zasobID}&_cls={$className}&_hash={$this->_htmlID}&_task=FILES_CONN_TBL_LIST&ID={$record['ID']}",
  1861. 'URL_FILE_PERMS_REFRESH' => "index-ajax.php?_zasobID={$this->_zasobID}&_cls={$className}&_hash={$this->_htmlID}&_task=filePermsRefresh&ID={$record['ID']}",
  1862. 'URL_FILE_UPLOAD' => "index-ajax.php?_zasobID={$this->_zasobID}&_cls={$className}&_hash={$this->_htmlID}&_task=FILES_UPLOAD&ID={$record['ID']}",
  1863. 'CAN_WRITE_RECORD' => (int)$this->_acl->canWriteRecord($record),
  1864. 'SHARE_POINT' => $sharePoint,
  1865. 'JSON_FILES' => $jsonFiles,
  1866. ]);
  1867. exit;
  1868. }
  1869. private function sendTypeSpecial($fldID, $args) {
  1870. $DBG = ('1' == V::get('DBG', '', $_REQUEST));
  1871. header("Content-type: application/json");
  1872. $fldName = '';
  1873. $fld = $this->_acl->getField($fldID);
  1874. DBG::log($fld, 'array', "\$fld({$fldID})");
  1875. if (!$fld) {
  1876. // 404
  1877. } else {
  1878. $fldName = $fld['name'];
  1879. }
  1880. $jsonData = array();
  1881. $typeSpecial = Typespecial::getInstance($fldID, $fldName);
  1882. if ($typeSpecial) {
  1883. $query = V::get('q', '', $_REQUEST);
  1884. DBG::log("\$query({$query})");
  1885. $rawRows = null;
  1886. $rows = $typeSpecial->getValuesWithExports($query);
  1887. DBG::log($rows, 'array', "\$rows({$query})");
  1888. foreach ($rows as $kID => $vItem) {
  1889. $itemJson = new stdClass();
  1890. $itemJson->id = $vItem->id;
  1891. $itemJson->name = $vItem->param_out;
  1892. if (!empty($vItem->exports)) {
  1893. $itemJson->exports = $vItem->exports;
  1894. }
  1895. if (!empty($vItem->{'$order'})) {
  1896. $itemJson->{'$order'} = $vItem->{'$order'};
  1897. }
  1898. $jsonData[] = $itemJson;
  1899. }
  1900. }
  1901. /*
  1902. MENU_INIT:VIEWTABLE_AJAX
  1903. ZASOB_ID:1188
  1904. _task:TYPESPECIAL
  1905. fldID:3866
  1906. Form Dataview sourceview URL encoded
  1907. q:te
  1908. */
  1909. echo json_encode($jsonData);
  1910. exit;
  1911. }
  1912. public function ajaxData($args) {// executed from url: "{$this->syncUrl"&_hash={$this->_htmlID}&_task=loadDataAjax"
  1913. $acl = $this->_acl;
  1914. $pageSize = V::get('pageSize', $this->_pageSize, $args, 'int');
  1915. $page = V::get('page', 0, $args, 'int');
  1916. $page = ($page > 0) ? $page - 1 : $page;
  1917. $currSortCol = V::get('currSortCol', '', $args);
  1918. $currSortFlip = V::get('currSortFlip', '', $args);
  1919. $params = array();
  1920. $params['limit'] = $pageSize;
  1921. $params['limitstart'] = $page * $params['limit'];
  1922. $params['order_by'] = ($currSortCol)? $currSortCol : '';
  1923. $params['order_dir'] = $currSortFlip;
  1924. foreach ($args as $k => $v) {
  1925. if (strlen($k) > 3 && substr($k, 0, 2) == 'f_' && strlen($v) > 0) {// filter prefix
  1926. $params[$k] = $v;
  1927. }
  1928. else if (strlen($k) > 4 && substr($k, 0, 3) == 'sf_' && strlen($v) > 0) {// special filter prefix
  1929. $params[$k] = $v;
  1930. }
  1931. }
  1932. if ($this->_backRefFilter) {
  1933. $params['__backRef'] = $this->_backRefFilter;
  1934. DBG::log($params, 'array', '$params __backRef');
  1935. }
  1936. if ($this->_childRefFilter) {
  1937. $params['__childRef'] = $this->_childRefFilter;
  1938. DBG::log($params, 'array', '$params __childRef');
  1939. }
  1940. $filters = new stdClass();
  1941. $filters->currSortCol = $currSortCol;
  1942. $filters->currSortFlip = $currSortFlip;
  1943. foreach ($args as $k => $v) {
  1944. if (strlen($k) > 3 && substr($k, 0, 2) == 'f_' && strlen($v) > 0) {// filter prefix
  1945. $filters->{$k} = $v;
  1946. }
  1947. else if (strlen($k) > 4 && substr($k, 0, 3) == 'sf_' && strlen($v) > 0) {// special filter prefix
  1948. $filters->{$k} = $v;
  1949. }
  1950. }
  1951. $this->setFilters($filters);
  1952. $vCols = $acl->getVirtualFieldListByIdZasob();
  1953. DBG::log($vCols, 'array', "\$vCols");
  1954. $visibleCols = $acl->getVisibleFieldListByIdZasob();
  1955. DBG::log($visibleCols, 'array', "\$visibleCols");
  1956. $jsonData = new stdClass();
  1957. $jsonData->page = $page + 1;
  1958. $jsonData->pageSize = $pageSize;
  1959. $jsonData->filters = $filters;
  1960. $jsonData->cols = new stdClass();
  1961. $jsonData->primaryKey = $acl->getPrimaryKeyField();
  1962. $ind = 0;
  1963. foreach ($visibleCols as $fieldID => $col) {
  1964. $ind++;
  1965. $columnConfig = (object)array('index'=>$ind);
  1966. if (in_array($col, array('A_STATUS','A_STATUS_CURRENT','A_SERVICES_STATUS_CURRENT'))) {
  1967. $columnConfig->format = '<div class="cell-A_STATUS-{0}">{0}</div>';
  1968. }
  1969. else if (in_array($col, array('Status'))) {
  1970. // Ahmes problems Status colors
  1971. $columnConfig->format = '<div class="cell-Status-{0}">{0}</div>';
  1972. }
  1973. else if ($acl->isGeomField($col)) {
  1974. $columnConfig->type = 'geom';
  1975. }
  1976. if ('' !== ($label = $acl->getFieldLabel($col))) {
  1977. $columnConfig->friendly = $label;
  1978. }
  1979. $colType = $acl->getFieldType($col);
  1980. if ($colType) {// @see MarkTableAjaxFilterColType
  1981. if ($colType['type'] == 'date') {
  1982. // $columnConfig->type = 'date';// TODO: require datetimepicker
  1983. }
  1984. if (!empty($colType['simpleType'])) $columnConfig->type = $colType['simpleType'];
  1985. } else {// typespecial - no type
  1986. $columnConfig->type = 'special';
  1987. }
  1988. $columnConfig->xsdType = $acl->getXsdFieldType($col);
  1989. if ($columnConfig->xsdType) {
  1990. list($prefix, $typeName, $refTypeName) = explode(":", $columnConfig->xsdType);
  1991. DBG::log([$prefix, $typeName, $refTypeName], 'array', "col '{$col}' xsdType");
  1992. switch ($prefix) {
  1993. case 'ref':
  1994. case 'alias_ref':
  1995. if (!$refTypeName) throw new HttpException("Schema Error for field({$col}) xsdType({$columnConfig->xsdType})", 500);
  1996. $columnConfig->type = 'ref';
  1997. $columnConfig->xsdRefUri = Api_WfsNs::getNsUri($typeName);
  1998. $columnConfig->xsdRefType = $refTypeName;
  1999. $columnConfig->xsdRefNsPrefix = $typeName;
  2000. break;
  2001. case 'xsd':
  2002. switch ($typeName) {
  2003. case 'string': $columnConfig->type = 'string'; break;
  2004. case 'NMTOKEN': $columnConfig->type = 'string'; break; // xsd:NMTOKEN - non empty string without space - pattern: \c+
  2005. case 'NCName': $columnConfig->type = 'string'; break; // xsd:NCName - non empty without ':' and not started with '-' - pattern: [\i-[:]][\c-[:]]*
  2006. case 'integer': $columnConfig->type = 'number'; break;
  2007. case 'int': $columnConfig->type = 'number'; break;
  2008. case 'long': $columnConfig->type = 'number'; break;
  2009. }
  2010. break;
  2011. case 'p5':
  2012. switch ($typeName) {
  2013. case 'enum': $columnConfig->type = 'string'; break;
  2014. case 'alias': {
  2015. if ($format = $acl->getXsdFieldParam($col, 'format')) $columnConfig->format = $format;
  2016. if ($aliasMap = $acl->getXsdFieldParam($col, 'aliasMap')) $columnConfig->aliasMap = $aliasMap;
  2017. } break;
  2018. case 'string': {
  2019. $columnConfig->type = 'p5:string';
  2020. $columnConfig->formatByValue = $acl->getXsdFieldParam($col, 'formatByValue');
  2021. if ($aliasMap = $acl->getXsdFieldParam($col, 'aliasMap')) $columnConfig->aliasMap = $aliasMap;
  2022. } break;
  2023. }
  2024. break;
  2025. case 'p5Type':
  2026. switch ($typeName) {
  2027. case 'enum': $columnConfig->type = 'string'; break;
  2028. case 'alias': {
  2029. $format = $acl->getXsdFieldParam($col, 'format');
  2030. if ($format) $columnConfig->format = $format;
  2031. } break;
  2032. case 'integer': $columnConfig->type = 'number'; break;
  2033. case 'string': {
  2034. $columnConfig->type = 'p5:string';
  2035. $columnConfig->formatByValue = $acl->getXsdFieldParam($col, 'formatByValue');
  2036. if ($aliasMap = $acl->getXsdFieldParam($col, 'aliasMap')) $columnConfig->aliasMap = $aliasMap;
  2037. } break;
  2038. }
  2039. break;
  2040. }
  2041. }
  2042. $typeSpecial = Typespecial::getInstance($fieldID, $col);
  2043. if ($typeSpecial) {
  2044. DBG::log($typeSpecial, 'array', "\$typeSpecial id({$fieldID}) col({$col})");
  2045. $columnConfig->_tsRetId = $typeSpecial->getReturnId();
  2046. if ($columnConfig->_tsRetId == 0) {
  2047. $tsParamOut = V::get('param_out', null, $typeSpecial);
  2048. if ($tsParamOut) {
  2049. $tsFormat = V::get('format', null, $tsParamOut);
  2050. $tsValues = V::get('values', null, $tsParamOut);
  2051. $tsAliases = V::get('alias', null, $tsParamOut);
  2052. if (false !== strpos($tsFormat, '<a') && !empty($tsValues) && !empty($tsAliases)) {
  2053. $tsAliasMap = array();
  2054. /* [values] => Array([ID] => 1467), [alias] => Array([1467] => ID) */
  2055. $bugTsColsNotVisible = array();
  2056. foreach ($tsValues as $kVarName => $vIdZasob) {
  2057. if (array_key_exists($vIdZasob, $tsAliases)) {
  2058. $tsAliasMap[$kVarName] = $tsAliases[$vIdZasob];
  2059. } else {
  2060. $bugTsColsNotVisible[] = "noAliasFor {$vIdZasob}";
  2061. }
  2062. if (!array_key_exists($vIdZasob, $visibleCols)) {
  2063. $bugTsColsNotVisible[] = $vIdZasob;
  2064. }
  2065. }
  2066. if (empty($bugTsColsNotVisible)) {
  2067. $tsSimpleLink = new stdClass();
  2068. $tsSimpleLink->format = $tsFormat;
  2069. $tsSimpleLink->aliasMap = $tsAliasMap;
  2070. $columnConfig->_tsSimpleLink = $tsSimpleLink;
  2071. $columnConfig->type = 'simpleLink';
  2072. } else {
  2073. $columnConfig->_tsSimpleLinkBug = $bugTsColsNotVisible;
  2074. }
  2075. }
  2076. }
  2077. }
  2078. }
  2079. if ($columnConfig->xsdType) {// fix fields type p5:typeSpecialSimpleLink (previously defined by Typespecial)
  2080. switch ($columnConfig->xsdType) {
  2081. case 'p5:typeSpecialSimpleLink': {
  2082. $columnConfig->type = 'simpleLink';
  2083. $columnConfig->_tsRetId = 0;
  2084. $columnConfig->_tsSimpleLink = new stdClass();
  2085. $columnConfig->_tsSimpleLink->format = $acl->getXsdFieldParam($col, 'format');
  2086. $columnConfig->_tsSimpleLink->aliasMap = $acl->getXsdFieldParam($col, 'aliasMap');
  2087. } break;
  2088. }
  2089. }
  2090. // @see ajaxHiddenColsSave
  2091. if (UserProfile::isHiddenColumn($acl->getID(), $fieldID)) {
  2092. $columnConfig->hidden = true;
  2093. }
  2094. $columnConfig->description = $acl->getFieldOpis($col);
  2095. $jsonData->cols->{$col} = $columnConfig;
  2096. }
  2097. DBG::log($jsonData->cols, 'array', "\$jsonData->cols");
  2098. $jsonData->rows = array();
  2099. if ($acl instanceof AntAclBase) {
  2100. $params['f_is_instance'] = $acl->getNamespace();
  2101. }
  2102. $queryFeatures = $acl->buildQuery($params);
  2103. $jsonData->total = $queryFeatures->getTotal();
  2104. $listItems = $queryFeatures->getItems();
  2105. $primaryKeyField = $acl->getPrimaryKeyField();
  2106. $items = []; foreach ($listItems as $item) $items[ $item[$primaryKeyField] ] = $item;
  2107. // TODO: add virtual data by Typespecial
  2108. if (!empty($vCols) && !empty($items)) {
  2109. foreach ($vCols as $vColID => $vCol) {
  2110. $colType = $acl->getFieldTypeById($vColID);
  2111. if ($colType) continue;// pomin Typespecial dla realnych komorek w bazie danych
  2112. $typeSpecial = Typespecial::getInstance($vColID, $vCol);
  2113. if ($typeSpecial) {
  2114. $columnConfig = V::get($vCol, null, $jsonData->cols);
  2115. if ($columnConfig && !empty($columnConfig->_tsSimpleLink)) {
  2116. // pomin simple link values - mved to js render
  2117. } else {
  2118. DBG::log($typeSpecial, 'array', "Typespecial({$vColID})");
  2119. $ids = array_keys($items);
  2120. $specialValues = $typeSpecial->getValuesByIds($this->_zasobID, $ids);
  2121. DBG::log($specialValues, 'array', "Typespecial({$vColID}) \$specialValues");
  2122. if (!empty($specialValues)) foreach ($specialValues as $kItemID => $vValues) {
  2123. $tsValue = implode('<br>', $vValues);
  2124. DBG::log($items[$kItemID], 'array', "Typespecial({$vColID}) Item[{$kItemID}].{$vCol}");
  2125. if (!empty($items[$kItemID][$vCol]) && !empty($tsValue)) {
  2126. $items[$kItemID][$vCol] .= ": {$tsValue}";
  2127. } else {
  2128. $items[$kItemID][$vCol] = $tsValue;
  2129. }
  2130. }
  2131. }
  2132. }
  2133. }
  2134. }
  2135. {
  2136. if(V::get('DBG', '', $_GET)){$jsonData->__DBG__ = [];}
  2137. $p5Alias = [];
  2138. foreach ((array)$jsonData->cols as $fieldName => $conf) {
  2139. if ('p5:alias' == V::get('xsdType', '', $conf)) {
  2140. if(V::get('DBG', '', $_GET)){$jsonData->__DBG__[$fieldName] = $conf;}
  2141. $aliasType = $acl->getXsdFieldParam($fieldName, 'type');// 'type' => 'sql_table_alias',
  2142. if ('sql_table_alias' == $aliasType) {
  2143. $p5Alias[$fieldName] = (array)$conf;
  2144. $p5Alias[$fieldName]['type'] = 'sql_table_alias';
  2145. $p5Alias[$fieldName]['local_join_key'] = $acl->getXsdFieldParam($fieldName, 'local_join_key');// 'local_join_key' => 'ID',
  2146. $p5Alias[$fieldName]['remote_table_name'] = $acl->getXsdFieldParam($fieldName, 'remote_table_name');// 'remote_table_name' => 'CRM_LISTA_ZASOBOW_ORDERS_summary_view',
  2147. $p5Alias[$fieldName]['remote_join_key'] = $acl->getXsdFieldParam($fieldName, 'remote_join_key');// 'remote_join_key' => 'ID',
  2148. $p5Alias[$fieldName]['remote_column_value'] = $acl->getXsdFieldParam($fieldName, 'remote_column_value');// 'remote_column_value' => 'SUM_POS',
  2149. } else if ('sql_query_alias' == $aliasType) {
  2150. $p5Alias[$fieldName] = (array)$conf;
  2151. $p5Alias[$fieldName]['type'] = 'sql_query_alias';
  2152. $p5Alias[$fieldName]['local_join_key'] = $acl->getXsdFieldParam($fieldName, 'local_join_key');
  2153. $p5Alias[$fieldName]['join_query_format'] = $acl->getXsdFieldParam($fieldName, 'join_query_format');
  2154. }
  2155. }
  2156. }
  2157. if(V::get('DBG', '', $_GET)){$jsonData->__DBG__['$p5Alias'] = $p5Alias;}
  2158. if(V::get('DBG', '', $_GET)){$jsonData->__DBG__['$aliasValuesRaw'] = [];}
  2159. if ($p5Alias) {
  2160. $sqlLocalTableName = $acl->getRootTableName();
  2161. $primaryKeyField = $acl->getPrimaryKeyField();
  2162. foreach ($p5Alias as $fieldName => $conf) {
  2163. $aliasValuesRaw = [];
  2164. if ('sql_table_alias' == $conf['type']) {
  2165. $localKeys = [];
  2166. $localKeyName = V::get('local_join_key', '', $conf);
  2167. if ($localKeyName) {
  2168. if (!array_key_exists($localKeyName, $localKeys)) {
  2169. $localKeys[$localKeyName] = [];
  2170. foreach ($items as $item) {
  2171. $keyLocal = V::get($localKeyName, 0, $item);
  2172. if ($keyLocal) $localKeys[$localKeyName][] = DB::getPDO()->quote($keyLocal, PDO::PARAM_STR);
  2173. }
  2174. }
  2175. if(V::get('DBG', '', $_GET)){$jsonData->__DBG__['$localKeys'] = $localKeys;}
  2176. if (!empty($localKeys[$localKeyName])) {
  2177. $sqlRemoteTable = V::get('remote_table_name', '', $conf);
  2178. $sqlRemoteValueFieldName = V::get('remote_column_value', '', $conf);
  2179. $sqlRemoteKeyName = V::get('remote_join_key', '', $conf);
  2180. $sqlLocalKeyName = $acl->getSqlFieldName($localKeyName);
  2181. try {
  2182. $aliasValuesRaw = DB::getPDO()->fetchAllByKey("
  2183. select r.{$sqlRemoteKeyName} as {$sqlLocalKeyName}, r.{$sqlRemoteValueFieldName} as remote_value
  2184. from {$sqlRemoteTable} r
  2185. where r.{$sqlRemoteKeyName} in(" . implode(",", $localKeys[$localKeyName]) . ")
  2186. ", $sqlLocalKeyName);
  2187. } catch (Exception $e) {
  2188. // TODO: error msg for GUI
  2189. DBG::log($e);
  2190. }
  2191. if(V::get('DBG', '', $_GET)){$jsonData->__DBG__['$aliasValuesRaw'][$fieldName] = $aliasValuesRaw;}
  2192. }
  2193. }
  2194. } else if ('sql_query_alias' == $conf['type']) {
  2195. $localKeys = [];
  2196. $localKeyName = V::get('local_join_key', '', $conf);
  2197. $sqlFormat = V::get('join_query_format', '', $conf);
  2198. if ($localKeyName && $sqlFormat) {
  2199. if (!array_key_exists($localKeyName, $localKeys)) {
  2200. $localKeys[$localKeyName] = [];
  2201. foreach ($items as $item) {
  2202. $keyLocal = V::get($localKeyName, 0, $item);
  2203. if ($keyLocal) $localKeys[$localKeyName][] = DB::getPDO()->quote($keyLocal, PDO::PARAM_STR);
  2204. }
  2205. }
  2206. }
  2207. if (!empty($localKeys[$localKeyName])) {
  2208. $sql = str_replace('{sql_in_local_join_key}', implode(",", $localKeys[$localKeyName]), $sqlFormat);
  2209. $sqlLocalKeyName = $acl->getSqlFieldName($localKeyName);
  2210. try {
  2211. $aliasValuesRaw = DB::getPDO()->fetchAllByKey($sql, $sqlLocalKeyName);
  2212. } catch (Exception $e) {
  2213. // TODO: error msg for GUI
  2214. DBG::log($e);
  2215. }
  2216. }
  2217. }
  2218. DBG::log($aliasValuesRaw, 'array', '$aliasValuesRaw');
  2219. if (!empty($aliasValuesRaw)) {
  2220. DBG::log($aliasValuesRaw, 'array', "DBG_P5: \$aliasValuesRaw");
  2221. array_walk($items, function (&$item) use ($fieldName, $sqlLocalKeyName, $aliasValuesRaw) {
  2222. $sqlValue = V::get($sqlLocalKeyName, null, $item);
  2223. DBG::log($sqlValue, 'array', "DBG_P5: \$sqlValue");
  2224. DBG::log($aliasValuesRaw[$sqlValue]['remote_value'], 'array', "DBG_P5: \$aliasValuesRaw[{$sqlValue}]['remote_value']");
  2225. DBG::log($item, 'array', "DBG_P5: \$item");
  2226. if ($sqlValue !== null && array_key_exists($sqlValue, $aliasValuesRaw)) {
  2227. DBG::log($aliasValuesRaw[$sqlValue]['remote_value'], 'array', "DBG_P5: TODO_update_value");
  2228. $item[$fieldName] = $aliasValuesRaw[$sqlValue]['remote_value'];
  2229. DBG::log($item[$fieldName], 'array', "DBG_P5: TODO_updated_value");
  2230. }
  2231. });
  2232. }
  2233. }
  2234. }
  2235. }
  2236. foreach ($items as $item) {
  2237. // TODO: hide items without 'R'
  2238. foreach ($visibleCols as $fieldName) {
  2239. // TODO: ID default 'R'
  2240. if (!$acl->canReadObjectField($fieldName, $item)) $item[$fieldName] = '*****';
  2241. // null => empty string
  2242. if (!isset($item[$fieldName]) || (!$item[$fieldName] && $item[$fieldName] !== '0')) {
  2243. // DBG::log($item[$fieldName], 'array', "isEmptyString[{$fieldName}]");
  2244. $item[$fieldName] = '';
  2245. }
  2246. }
  2247. $jsonData->rows[] = $item;
  2248. }
  2249. $jsonData->type = 'success';
  2250. $jsonData->msg = 'pobrano nowe dane';
  2251. // { // TODO: BUG - race condition in requests
  2252. // session_write_close();
  2253. // if (!empty($params['f_L_APPOITMENT_USER']) && strlen($params['f_L_APPOITMENT_USER']) === 3) sleep(2); // TODO: DBG
  2254. // if (!empty($params['f_L_APPOITMENT_USER']) && strlen($params['f_L_APPOITMENT_USER']) === 3) $jsonData->__DBG__sleep = 2; // TODO: DBG
  2255. // }
  2256. return $jsonData;
  2257. }
  2258. private function fixEmptyValueFromUser($fieldID) {// TODO: moved to TableAcl->fixEmptyValueFromUser
  2259. $value = '';
  2260. $type = $this->_acl->getFieldTypeById($fieldID);
  2261. if ($type) {
  2262. if ($type['type'] == 'date') {
  2263. $value = $type['default'];
  2264. }
  2265. // fix bug when field is unique and is null allowed: change empty string to null
  2266. if ($type['null']) {
  2267. $value = 'NULL';
  2268. }
  2269. // fix bug when field is enum and is set to '0': for php '0' is empty
  2270. if (substr($type['type'], 0, 4) == 'enum') {// && $args["f{$fieldID}"] === '0') {
  2271. if (false !== strpos($type['type'], "''")) {
  2272. // enum('', '1','2')
  2273. $value = '';
  2274. } else if (false !== strpos($type['type'], "'0'")) {
  2275. // enum('0', '1','2')
  2276. $value = '0';
  2277. } else {
  2278. $value = $type['default'];
  2279. }
  2280. }
  2281. }
  2282. return $value;
  2283. }
  2284. /**
  2285. * set hidden cols in $_SESSION['USER_PROFILE'][$this->_zasobID];
  2286. * $_SESSION['USER_PROFILE'][$this->_zasobID][fld_id] => boolean
  2287. */
  2288. private function ajaxHiddenColsSave($args) {
  2289. $response = new stdClass();
  2290. if (empty($args)) {
  2291. $response->type = 'info';
  2292. return $response;
  2293. }
  2294. UserProfile::load();
  2295. // clean up old, wrong values
  2296. if (array_key_exists("{$this->_tbl}_COLUMN", $_SESSION['USER_PROFILE'])) {
  2297. unset($_SESSION['USER_PROFILE']["{$this->_tbl}_COLUMN"]);
  2298. }
  2299. $colVis = UserProfile::getHiddenCols($this->_zasobID);
  2300. $fields = $this->_acl->getFieldListByIdZasob();
  2301. foreach ($fields as $idField => $fieldName) {
  2302. if (isset($args[$fieldName])) {
  2303. if ($args[$fieldName] == 'SHOW') {
  2304. $colVis[$idField] = 1;
  2305. } else if ($args[$fieldName] == 'HIDE') {
  2306. $colVis[$idField] = 0;
  2307. }
  2308. }
  2309. }
  2310. UserProfile::setHiddenCols($this->_zasobID, $colVis);
  2311. UserProfile::save();
  2312. $response->type = 'success';
  2313. return $response;
  2314. }
  2315. private function ajaxPageSizeSave($args) {
  2316. $response = new stdClass();
  2317. if (empty($args)) {
  2318. $response->type = 'info';
  2319. return $response;
  2320. }
  2321. $pageSize = V::get('pageSize', 0, $args, 'int');
  2322. UserProfile::load();
  2323. // clean up old, wrong values
  2324. if (array_key_exists("{$this->_tbl}_COLUMN", $_SESSION['USER_PROFILE'])) {
  2325. unset($_SESSION['USER_PROFILE']["{$this->_tbl}_COLUMN"]);
  2326. }
  2327. $tableAjaxSettings = UserProfile::getTableAjaxSettings();
  2328. $tableAjaxSettings['pageSize'] = $pageSize;
  2329. UserProfile::setTableAjaxSettings($tableAjaxSettings);
  2330. UserProfile::save();
  2331. $response->type = 'success';
  2332. return $response;
  2333. }
  2334. private function ajaxTheGeomSave($args) {
  2335. $primaryKeyField = $this->_acl->getPrimaryKeyField();
  2336. $primaryKey = V::get($primaryKeyField, 0, $args, 'int');
  2337. $polygon = V::get('polygon', 0, $args);
  2338. $geomFieldName = 'the_geom';
  2339. if ($primaryKey <= 0) {
  2340. throw new HttpException("Wrong param ID", 404);
  2341. }
  2342. // TODO: validate polygon - ex.: POLYGON((2072030.2315435 7234115.910678,2072029.4815435 7234093.660678,2072115.2315435 7234091.160678,2072115.4815435 7234113.660678,2072115.2315435 7234113.660678,2072094.2315435 7234113.910678,2072030.2315435 7234115.910678)))
  2343. $record = $this->_acl->buildQuery([])->getItem($primaryKey);
  2344. if (!$this->_acl->canWriteRecord($record) && !$this->_acl->hasPermSuperWrite()) {
  2345. throw new HttpException("Brak dostępu do rekordu", 403);
  2346. }
  2347. if (!$this->_acl->canWriteObjectField($geomFieldName, $record)) {
  2348. throw new HttpException("Brak dostępu do zapisu dla pola {$geomFieldName}", 403);
  2349. }
  2350. $itemPatch = array();
  2351. $itemPatch[$geomFieldName] = "GeomFromText('{$polygon}')";
  2352. $itemPatch[$primaryKeyField] = $primaryKey;
  2353. $response = new stdClass();
  2354. try {
  2355. $affected = $this->_acl->updateItem($itemPatch);
  2356. if ($affected > 0) {
  2357. $response->type = 'success';
  2358. $response->msg = "Rekord zapisany pomyślnie";//"Record saved successfully";
  2359. } else if ($affected == 0) {
  2360. $response->type = 'info';
  2361. $response->msg = "Nie wprowadzono żadnych zmian";
  2362. }
  2363. $response->record = $this->_acl->buildQuery([])->getItem($primaryKey);
  2364. }
  2365. catch (Exception $e) {
  2366. $response->type = 'error';
  2367. $response->msg = $e->getMessage();
  2368. }
  2369. return $response;
  2370. }
  2371. public function sendAjaxResponseJson($method, $args) {
  2372. try {
  2373. $response = $this->{$method}($args);
  2374. }
  2375. catch (HttpException $e) {
  2376. $response = new stdClass();
  2377. $response->type = 'error';
  2378. $response->msg = $e->getMessage();
  2379. $response->errorCode = $e->getCode();
  2380. Http::sendHeaderByCode($e->getCode());
  2381. }
  2382. catch (Exception $e) {
  2383. $response = new stdClass();
  2384. $response->type = 'error';
  2385. $response->msg = $e->getMessage();
  2386. $response->errorCode = $e->getCode();
  2387. }
  2388. header('Content-type: application/json');
  2389. if (!$response) $response = new stdClass();
  2390. echo json_encode($response);
  2391. exit;
  2392. }
  2393. }