TableAjax.php 158 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545
  1. <?php
  2. Lib::loadClass('ViewAjax');
  3. class TableAjax extends ViewAjax {
  4. private $_cnf = '';// Column
  5. private $_htmlID = '';
  6. private $_dataSource = null;
  7. private $_rowFunctions = array();
  8. private $_pageSizes = array();
  9. private $_filterInit = null;
  10. private $_forceFilterInit = null;
  11. private $_showProcesInit = true;
  12. public function __construct($tblAcl) {
  13. $this->_tbl = $tblAcl->getName();
  14. $this->_acl = $tblAcl;
  15. $this->_zasobID = $tblAcl->getID();
  16. $this->_dataSource = $tblAcl->getDataSource();
  17. $this->_pageSizes = array(10, 20, 50, 100);// default page sizes
  18. $this->_filterInit = new stdClass();
  19. $hash = V::get('_hash', '', $_GET);
  20. if ($hash) {
  21. $this->_htmlID = $hash;
  22. $this->_readState();
  23. } else {
  24. $this->_htmlID = $this->generateHtmlID();
  25. $this->_readState();
  26. }
  27. $this->_geomFields = $this->_dataSource->getGeomFields();
  28. }
  29. public function showProcesInit($bool = true) {
  30. $this->_showProcesInit = $bool;
  31. }
  32. private function _hasStateFilterInit() {
  33. return array_key_exists($this->_htmlID, $_SESSION['TableAjax_Cache']) && array_key_exists('_filterInit', $_SESSION['TableAjax_Cache'][$this->_htmlID]);
  34. }
  35. // TODO: read state from cache by key $this->_htmlID
  36. // TODO: load filters and state: table, edit, add, etc.
  37. // TODO: save this data in Workspace 1, 2, 3, etc.
  38. // TODO: default filters in VIEWTABLE_AJAX
  39. // $tbl->setLabel($zasobObj->OPIS);
  40. // $tbl->setFilterInit($filterInit);
  41. // $tbl->addRowFunction('edit');
  42. // $tbl->addRowFunction('hist');
  43. // $tbl->addRowFunction('files');
  44. // $tbl->addRowFunction('cp');
  45. private function _readState() {
  46. if (!array_key_exists('TableAjax_Cache', $_SESSION)) {
  47. $_SESSION['TableAjax_Cache'] = array();
  48. }
  49. //trigger_error("F." . __FUNCTION__ . " (" . (array_key_exists($this->_htmlID, $_SESSION['TableAjax_Cache'])) . ")", E_USER_NOTICE);
  50. //trigger_error("F." . __FUNCTION__ . " (".basename($_SERVER['SCRIPT_FILENAME'])."::_filterInit: " . json_encode($_SESSION['TableAjax_Cache'][$this->_htmlID]['_filterInit']) . ")", E_USER_NOTICE);
  51. if (array_key_exists($this->_htmlID, $_SESSION['TableAjax_Cache'])) {
  52. foreach ($_SESSION['TableAjax_Cache'][$this->_htmlID] as $k => $v) {
  53. //trigger_error("F." . __FUNCTION__ . " key: ({$k})", E_USER_NOTICE);
  54. switch ($k) {
  55. case '_label':
  56. $this->_label = $v;
  57. break;
  58. case '_filterInit':
  59. $this->_filterInit = $v;
  60. break;
  61. case '_rowFunctions':
  62. $this->_rowFunctions = $v;
  63. break;
  64. default:
  65. }
  66. }
  67. }
  68. }
  69. protected function _saveState($key = null) {
  70. if (!array_key_exists('TableAjax_Cache', $_SESSION)) {
  71. $_SESSION['TableAjax_Cache'] = array();
  72. }
  73. if (!array_key_exists($this->_htmlID, $_SESSION['TableAjax_Cache'])) {
  74. $_SESSION['TableAjax_Cache'][$this->_htmlID] = array();
  75. }
  76. if (!$key) {
  77. $_SESSION['TableAjax_Cache'][$this->_htmlID]['_label'] = $this->_label;
  78. $_SESSION['TableAjax_Cache'][$this->_htmlID]['_filterInit'] = $this->_filterInit;
  79. $_SESSION['TableAjax_Cache'][$this->_htmlID]['_rowFunctions'] = $this->_rowFunctions;
  80. } else if ($key == '_label') {
  81. $_SESSION['TableAjax_Cache'][$this->_htmlID]['_label'] = $this->_label;
  82. } else if ($key == '_filterInit') {
  83. $_SESSION['TableAjax_Cache'][$this->_htmlID]['_filterInit'] = $this->_filterInit;
  84. } else if ($key == '_rowFunctions') {
  85. $_SESSION['TableAjax_Cache'][$this->_htmlID]['_rowFunctions'] = $this->_rowFunctions;
  86. }
  87. }
  88. public function setPageSizes($pageSizes) {
  89. $this->_pageSizes = $pageSizes;
  90. }
  91. public function setFilterInit($filterInit) {
  92. if ($this->_hasStateFilterInit()) {
  93. return;
  94. }
  95. $this->_filterInit = (object)$filterInit;
  96. $this->_saveState();
  97. }
  98. /**
  99. * @param array $forceFilterInit
  100. */
  101. public function setForceFilterInit($forceFilterInit) {
  102. $this->_forceFilterInit = (object)$forceFilterInit;
  103. }
  104. private function setFilters($filterInit) {
  105. $this->_filterInit = (object)$filterInit;
  106. $this->_saveState();
  107. }
  108. public function addRowFunction($funName, $funParams = array()) {
  109. $defaultRowFunction = array();
  110. //$defaultRowFunction['edit'] = '<a href="#EDIT/{0}" class="ico-pencil" title="Edytuj rekord"></a>';
  111. //$defaultRowFunction['hist'] = '<a href="#HIST/{0}" class="ico-book" title="Historia"></a>';
  112. //$defaultRowFunction['files'] = '<a href="#FILES/{0}" class="ico-folder-open" title="Pliki"></a>';
  113. //$defaultRowFunction['cp'] = '<a href="#" class="ico-plus-sign" title="Kopiuj rekord" onclick="return tableAjaxCopy({0});"></a>';
  114. $defaultRowFunction['edit'] = array('href'=>'#EDIT/{0}', 'ico'=>'ico-pencil', 'title'=>'Edytuj rekord');
  115. $defaultRowFunction['hist'] = array('href'=>'#HIST/{0}', 'ico'=>'ico-book', 'title'=>'Historia');
  116. $defaultRowFunction['files'] = array('href'=>'#FILES/{0}', 'ico'=>'ico-folder-open', 'title'=>'Pliki');
  117. $defaultRowFunction['cp'] = array('href'=>'#', 'ico'=>'ico-plus-sign', 'title'=>'Kopiuj rekord', 'onclick'=>'return tableAjaxCopy({0});');
  118. if (array_key_exists($funName, $defaultRowFunction)) {
  119. $this->_rowFunctions[$funName] = $defaultRowFunction[$funName];
  120. }
  121. else {
  122. $this->_rowFunctions[$funName] = $funParams;
  123. }
  124. $this->_saveState('_rowFunctions');
  125. }
  126. private function _parseRowFunctions($recordID = null, $pomin = array(), $showLabel = false) {
  127. $rowFunctions = array();
  128. foreach ($this->_rowFunctions as $kFunName => $vParams) {
  129. if (in_array($kFunName, $pomin)) continue;
  130. //$rowFunctionsOut .= str_replace('{0}', $recordID, $vUrl);
  131. $attrs = array();
  132. // $defaultRowFunction['cp'] = (object)array('href'=>'#', 'ico'=>'ico-plus-sign', 'title'=>'Kopiuj rekord', 'onclick'=>'return tableAjaxCopy({0});');
  133. $label = '';
  134. $ico = '';
  135. foreach ($vParams as $kParamName => $v) {
  136. if ($kParamName == 'ico') {
  137. if ($showLabel) {
  138. $ico = '<span class="' . $v . '"></span>';
  139. } else {
  140. $attrs[] = 'class="' . $v . '"';
  141. }
  142. continue;
  143. }
  144. $attr = $v;
  145. if ($recordID > 0) {
  146. $attr = str_replace('{0}', $recordID, $attr);
  147. }
  148. if ($showLabel && $kParamName == 'title') {
  149. $label = $attr;
  150. }
  151. $attr = $kParamName . '="' . $attr . '"';
  152. $attrs[] = $attr;
  153. }
  154. $rowFunctions[$kFunName] = '<a ' . implode(' ', $attrs) . '>' . "{$ico}{$label} " . '</a>';
  155. }
  156. return $rowFunctions;
  157. }
  158. private function _showRowFunctions($recordID = null, $pomin = array(), $showLabel = false) {
  159. $rowFunctionsOut = $this->_parseRowFunctions($recordID, $pomin, $showLabel);
  160. $rowFunctionsOut = implode('', $rowFunctionsOut);
  161. return $rowFunctionsOut;
  162. }
  163. private function _showRowFunctionsJson($recordID = null, $pomin = array(), $showLabel = false) {
  164. $rowFunctions = $this->_parseRowFunctions($recordID, $pomin, $showLabel);
  165. $rowFunctions = (object)$rowFunctions;
  166. return $rowFunctions;
  167. }
  168. private function getProcesInitSelected() {
  169. $userAcl = User::getAcl();
  170. return $userAcl->getPermsProcesId();
  171. }
  172. private function _fetchConnectedProcesInitList() {
  173. $pInitList = array();// [proces_init_id] => label (DESC)
  174. if (!$this->_showProcesInit) {
  175. return $pInitList;
  176. }
  177. $userAcl = User::getAcl();
  178. $pInitListRaw = $userAcl->getProcesInitList($this->_zasobID);
  179. if (empty($pInitListRaw)) {
  180. return $pInitList;
  181. }
  182. $db = DB::getDB();
  183. $sql = "select p.`ID`, p.`DESC`
  184. from `CRM_PROCES` as p
  185. where p.`ID` in(" . implode(",", array_values($pInitListRaw)) . ")
  186. and p.`TYPE`='PROCES_INIT'
  187. ";
  188. $res = $db->query($sql);
  189. while ($r = $db->fetch($res)) {
  190. $pInitList[$r->ID] = $r->DESC;
  191. }
  192. return $pInitList;
  193. }
  194. public function allowTreeView() {
  195. if ($this->_tbl == 'CRM_LISTA_ZASOBOW') return true;
  196. if ($this->_tbl == 'CRM_PROCES') return true;
  197. return false;
  198. }
  199. public function hasGeomFields() {
  200. $hasGeomFields = false;
  201. $fieldsList = $this->_acl->getFields();
  202. foreach ($fieldsList as $kID => $vCol) {
  203. if ($this->_dataSource->isGeomField($vCol['name'])) {
  204. if ($this->_acl->hasFieldPerm($kID, 'R')) {
  205. $hasGeomFields = true;
  206. break;
  207. }
  208. }
  209. }
  210. return $hasGeomFields;
  211. }
  212. public function render() {
  213. $pInitList = $this->_fetchConnectedProcesInitList();
  214. $pInitListSelected = $this->getProcesInitSelected();
  215. $hasGeomFlds = $this->hasGeomFields();
  216. $tblAjaxMap = null;
  217. if ($hasGeomFlds) {
  218. Lib::loadClass('TableAjaxMap');
  219. $tblAjaxMap = new TableAjaxMap($this->_acl, 512, 300);
  220. }
  221. ob_start();
  222. ?>
  223. <?php if ($tblAjaxMap) $tblAjaxMap->printCSS(); ?>
  224. <?php if ($tblAjaxMap) $tblAjaxMap->printJS(); ?>
  225. <link rel="stylesheet" type="text/css" href="stuff/jquery-ui-smoothness/jquery-ui-1.10.4.custom.min.css">
  226. <style type="text/css">
  227. .AjaxTable{max-width:100%;background-color:transparent;border-collapse:collapse;border-spacing:0;}
  228. .AjaxTableCont {position:relative; margin:10px 0; width:100%; overflow-x:auto; border:none;}
  229. .AjaxTable *,
  230. .AjaxTableCont .foot * {font-size:12px !important;}
  231. .AjaxTable.table {white-space:nowrap; width:auto;}
  232. .AjaxTable p {margin:0;}
  233. .AjaxTable td, .AjaxTable th {line-height:18px;}
  234. .AjaxTable i {margin: 0 0 0 2px;opacity: 0.5;}
  235. .AjaxTable span.filter {background-color:#999;}
  236. .AjaxTable .indeterminate {opacity: 0.4;-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=40)";filter:alpha(opacity=40);}
  237. .AjaxTable .columnpicker li, .AjaxTable .actions li {padding-left:5px;}
  238. .AjaxTableCont .btn-toolbar {margin:2px 0 0 0;}
  239. .AjaxTableCont .btn-toolbar .btn-group {vertical-align:top;}
  240. .AjaxTable input[type=checkbox] {margin:0;padding:0;height:13px;}
  241. .AjaxTable input[type=text].filter {margin:0;padding:0;box-shadow:none;width:100%;background:#eee;float:left;color:#000;}
  242. .AjaxTable input[type=text].filter {border-width:2px 0;border-color:#eee;border-style:solid;}
  243. .AjaxTable input[type=text].filter-active {border-color:#00ACCC;}
  244. .AjaxTable .date-wrap {width:100%;min-width:115px;}
  245. .AjaxTable .dateWrap .add-on {margin:0;padding:0;background:none;border:none;float:right;cursor:pointer;}
  246. .AjaxTableCont .dropdown-menu {max-height:250px;padding:0 20px 0 0;overflow:auto;}
  247. .AjaxTable .actions a {padding:0;margin:0;}
  248. .AjaxTableCont .text-right {text-align:right}
  249. .AjaxTableCont .breadcrumb em {color:#bbb;}
  250. .AjaxTable-loading .foot .foot-info {padding-left:20px; background:url(./icon/loading.gif) no-repeat left top;}
  251. .AjaxTable-loading .head-info {background:url(./icon/loading.gif) no-repeat left top; background-position:0 6px;}
  252. .AjaxTable-loading .loading-info,
  253. .AjaxTableCont .inlineEditBox .loading-info {display:block; padding:0 0 0 20px; background:url(./icon/loading.gif) no-repeat left top;}
  254. .AjaxTableCont .loading-info {display:none;}
  255. .AjaxTableCont .inlineEditBox .loading-info {display:block;}
  256. .AjaxTable .stickyCol2 input[type=text].filter {width:50px;}
  257. .AjaxTableCont .table {margin-bottom:0px;}
  258. .AjaxTableCont .foot {margin:10px;}
  259. .AjaxTableCont .stickyCol1 a:hover { }
  260. .AjaxTableTaskCnt {padding:0 10px 10px 10px;}
  261. .AjaxTable .tbl-short-txt{max-width:140px; overflow:hidden;}
  262. .AjaxTable .tbl-short-txt span{display:block; height:18px;}
  263. .AjaxTable .tooltip-inner{white-space:normal;}
  264. .AjaxTable thead .sort .ta-ordering {cursor:pointer;}
  265. .AjaxTable thead .sort .ta-ordering span {margin:0 14px 0 0; padding:0 14px 0 0; background-repeat:no-repeat; background-position:right top;}
  266. .AjaxTable thead .sort .ta-ordering-down span {background-image:url(stuff/twitter-bootstrap/img/ordering-down.png);}
  267. .AjaxTable thead .sort .ta-ordering-up span {background-image:url(stuff/twitter-bootstrap/img/ordering-up.png);}
  268. .AjaxTable thead .sort .ta-ordering {position:relative;}
  269. .AjaxTable thead .sort th .hover-show:hover{background-color:#000; background-image:url(stuff/twitter-bootstrap/img/glyphicons-halflings-white.png);}
  270. .AjaxTable thead .sort th .hover-show{display:none;}
  271. .AjaxTable thead .sort th:hover .hover-show{display:inline;}
  272. .AjaxTable thead .sort .ta-ordering .remove-cell {position:absolute; top:6px; right:2px; display:none;}
  273. .AjaxTable thead .sort .ta-ordering:hover .remove-cell {display:block;}
  274. .AjaxTableCont .foot .foot-info { float:left; padding:0 20px; }
  275. .AjaxTableCont .foot .foot-info p { line-height:16px; margin:5px 0; }
  276. .AjaxTableCont .pagination { margin:0; }
  277. .AjaxTableCont .pagination a { line-height:16px; }
  278. .AjaxTableCont .AjaxTableEdit-label { display:block; margin:0 0 3px 0; font-size:12px !important; line-height:16px !important; }
  279. .AjaxTableCont .AjaxTableEdit-label code { padding:0; white-space:nowrap; background-color:transparent; border:none; color:#777; font-size:10px !important; line-height:14px !important; }
  280. .AjaxTableCont .AjaxTableEdit .show-last-value .btn-appendBack,
  281. .AjaxTableCont .AjaxFrmHorizontalEdit .show-last-value .btn-appendBack {display:none;}
  282. .AjaxTableHist em {color:silver;}
  283. .TableAjax-SpecialFilter {margin:0;padding:4px 4px 4px 127px;}
  284. .TableAjax-SpecialFilter .btn-group {margin:0 4px;padding:0;}
  285. /* overwrite bootstrap table border */
  286. .AjaxTable, .AjaxTableEdit,
  287. .AjaxTable td, .AjaxTableEdit td,
  288. .AjaxTable th, .AjaxTableEdit th { border-color:#999; }
  289. /* */
  290. .AjaxTable .cell-A_STATUS-NORMAL { background:#aeffae; color:#000; text-align:center; }
  291. .AjaxTable .cell-A_STATUS-WAITING { background:#ffd2ff; color:#000; text-align:center; }
  292. .AjaxTable .cell-A_STATUS-MONITOR { background:#cccaff; color:#000; text-align:center; }
  293. .AjaxTable .cell-A_STATUS-WARNING { background:#ffbaba; color:#000; text-align:center; }
  294. .AjaxTable .cell-A_STATUS-DELETED { background:#e0e0e0; color:#808080; text-align:center; }
  295. .AjaxTable .cell-A_STATUS-OFF_SOFT { background:#fce3b7; color:#808080; text-align:center; }
  296. .AjaxTable .cell-A_STATUS-OFF_HARD { background:#eee; color:#808080; text-align:center; }
  297. /* map */
  298. .AjaxTable .cell-mapfld { cursor:pointer; }
  299. .AjaxTable .cell-mapfld:hover { opacity:1; }
  300. .AjaxTableCont .mapEditor { position:absolute; bottom:0; right:6px; width:512px; height:318px; overflow:hidden; background:#eee; border:1px solid #999; }
  301. .AjaxTableCont .mapEditor-panel { height:16px; padding:0 6px; background:#999; border-bottom:1px solid #eee; }
  302. .AjaxTableCont .mapEditor-panel a { display:block; float:right; padding:0 6px; font-weight:bold; font-size:12px; line-height:16px; color:#fff; }
  303. .AjaxTableCont .mapEditor-panel a:hover { color:#006CD7; text-decoration:none; }
  304. .AjaxTableCont .mapEditor-panel a.mapEditor-panel-close:hover { color:#f00; }
  305. .AjaxTableCont .mapEditor-map { background:#fff; height:300px; }
  306. .AjaxTableCont .valign-btns-bottom a { vertical-align:text-bottom; font-weight:normal; font-size:12px; line-height:14px; }
  307. </style>
  308. <div class="AjaxTableCont">
  309. <ul class="breadcrumb">
  310. <li><a href="#" onclick="return tableAjaxBackToTable();"><?php echo $this->getLabelHtml(); ?></a></li>
  311. <?php if (!empty($pInitList)) : ?>
  312. <div class="btn-group pull-right">
  313. <a class="btn btn-mini btn-info dropdown-toggle" data-toggle="dropdown" href="#" title="Uruchom filtr procesu powiązanego z tabelą <?php echo $this->getLabel(); ?>">
  314. Filtr procesu
  315. <span class="caret"></span>
  316. </a>
  317. <ul class="dropdown-menu pull-left">
  318. <?php foreach ($pInitList as $kId => $vLabel) : ?>
  319. <?php if ($pInitListSelected && $pInitListSelected == $kId) : ?>
  320. <li class="disabled">
  321. <?php else : ?>
  322. <li>
  323. <?php endif; ?>
  324. <a href="index.php?FUNCTION_INIT=MENU_SELECT_PROCES&_action=setPermsByProces&id_proces=<?php echo $kId; ?>&MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=<?php echo $this->_zasobID; ?>" title="<?php echo htmlspecialchars("{{$kId}} {$vLabel}"); ?>"><?php echo "{{$kId}} " . V::strShortUtf8($vLabel, 50); ?></a>
  325. </li>
  326. <?php endforeach; ?>
  327. </ul>
  328. </div>
  329. <?php endif; ?>
  330. <?php if ($this->_tbl == 'IN7_MK_BAZA_DYSTRYBUCJI') : ?>
  331. <a class="pull-right" style="padding:0 20px 0 0;" href="<?php echo "index.php?MENU_INIT=TREEJS&ZASOB_ID={$this->_zasobID}"; ?>"><i class="icon-eye-open"></i> Drzewo</a>
  332. <?php elseif ($this->allowTreeView()) : ?>
  333. <a class="pull-right" style="padding:0 20px 0 0;" href="<?php echo "index.php?MENU_INIT=VIEWTREE_AJAX&ZASOB_ID={$this->_zasobID}"; ?>"><i class="icon-eye-open"></i> Drzewo</a>
  334. <?php endif; ?>
  335. </ul>
  336. <div id="<?php echo $this->_htmlID; ?>"></div>
  337. </div>
  338. <script>
  339. (function ($, undefined) {
  340. var TableAjax = function () {
  341. var priv = {}; //private api
  342. var publ = {}; //public api
  343. priv.options = {};
  344. var defaults = {
  345. url: '', //webservice url
  346. urlData: '', //webservice params
  347. urlPost: false, //use POST instead of GET
  348. debug: false, //prints debug info to console
  349. filter: false, //show filter row
  350. filterInit: false,// init filters data
  351. forceFilterInit: false,
  352. columnPicker: false, //show columnpicker
  353. checkboxes: false, //show body checkboxes
  354. actions: '', //holds action links
  355. pageSize: 10, //current pagesize
  356. pageSizes: [10, 20, 30, 40, 50, 'All'], //available pagesizes
  357. hidePagerOnEmpty: false, //removes pager if no rows
  358. types: { //type specific options
  359. string: {},
  360. number: {},
  361. bool: {},
  362. date: {}
  363. },
  364. rowFunctions: false,
  365. tblFunctions: false,
  366. specialFilterFunctions: false,
  367. filtersClean: false,
  368. router: false,
  369. longDesc: false,
  370. mapEditor: false // mapEditor visible or not
  371. };
  372. var _cont; // container holding table
  373. var _table; // the table
  374. var _head; // table header
  375. var _headSort; // table header sorting row
  376. var _headFilter; // table header columns filter row
  377. var _headSpecialFilter; // table header special filter row
  378. var _body; // table body
  379. var _foot; // table footer
  380. var _inlineEditBox; // inline edit box with form
  381. var _popoverCell; // inline popover cell
  382. var _popoverCellCurrent; // inline popover cell
  383. var _popoverCellAjaxXhr;
  384. var _mapEditor; // map editor node
  385. var _mapEditorWrap; // map editor wrapper node
  386. var _mapEditorDialog; // map editor jquery ui dialog node
  387. var _data; //columns and rows
  388. var _currPage = 1; // current page
  389. var _pageSize; // current pagesize
  390. var _totalPages; // total pages
  391. var _currSortCol; // current sorting column
  392. var _currSortFlip = false; // current sorting direction
  393. var _currDpOp; // clicked datepicker operator
  394. var _filterCols = {}; // array with current filters
  395. var _filterFields = {}; // array with filter DOM elements
  396. var _specialFilters = {}; // array with current special filters
  397. var _filterTimeout; // timer for delayed filtering
  398. var _uniqueCol; // reference to column with the unique property
  399. var _uniqueCols = {}; // array with checked rows
  400. var _checkToggleChecked = false; // check-all toggle state
  401. var _tableWidth;
  402. /*
  403. initialize the plugin.
  404. */
  405. priv.init = function () {
  406. _cont = priv.options.id;
  407. priv.options.types.string = ((priv.options.types || {}).string || {});
  408. priv.options.types.number = ((priv.options.types || {}).number || {});
  409. priv.options.types.bool = ((priv.options.types || {}).bool || {});
  410. priv.options.types.date = ((priv.options.types || {}).date || {});
  411. if (priv.options.specialFilterFunctions && priv.options.filterInit) {
  412. $.map(priv.options.specialFilterFunctions, function(groupObj, groupName) {
  413. var fltrName = 'sf_' + groupName;
  414. if (fltrName in priv.options.filterInit) {
  415. _specialFilters[groupName] = priv.options.filterInit[fltrName];
  416. }
  417. });
  418. }
  419. //try call webservice for data
  420. priv.update(priv.options.router);
  421. if (typeof priv.options.router == "function") {
  422. $(window).bind('hashchange', function() {
  423. //console.log('hashchange: location.hash: ' + location.hash);
  424. priv.options.router.apply(this);
  425. });
  426. }
  427. };
  428. /*
  429. creates the table with all its parts and handlers.
  430. note that only the parts we need is created.
  431. (yeah, the function is huge)
  432. */
  433. priv.createTable = function () {
  434. //create table itself
  435. if (!_table) {
  436. _head = _body = _foot = undefined;
  437. _table = $('<table class="AjaxTable table table-striped table-hover table-bordered table-condensed"></table>').appendTo(_cont);
  438. }
  439. //create the header which will later hold both sorting and filtering
  440. if (!_head) {
  441. _table.find('thead').remove();
  442. _headSort = _headFilter = _headSpecialFilter = undefined;
  443. _head = $('<thead></thead>').prependTo(_table);
  444. }
  445. // TODO: test colgroup
  446. //_table.find('colgroup').remove();
  447. //$('<colgroup><col span="1" style="background-color:red"><col span="10" style="width:200px;overlow-x:auto"></colgroup>').prependTo(_table);
  448. //sort the columns in index order
  449. var colsSorted = Object.keys(_data.cols).sort(function (a, b) {
  450. return _data.cols[a].index - _data.cols[b].index;
  451. });
  452. //create the header sorting row
  453. if (!_headSort) {
  454. _head.find('.sort i').tooltip('hide');
  455. _head.find('.sort').remove();
  456. _headSort = $('<tr class="sort"></tr>').prependTo(_head);
  457. //create the functions column
  458. if (priv.options.rowFunctions || priv.options.filtersClean) {
  459. var headCell = $('<th class="text-right head-info stickyCol1"></th>').appendTo(_headSort);
  460. $.map(priv.options.tblFunctions, function(funObj, funName){
  461. var funHtml = $('<a></a>');
  462. funHtml.attr('href', funObj.href || '#');
  463. if (funObj.title) funHtml.attr('title', funObj.title);
  464. if (funObj.icon) funHtml.attr('class', 'ico-' + funObj.icon);
  465. if (funObj.method) funHtml.on('click', priv[funObj.method]);
  466. funHtml.appendTo(headCell);
  467. });
  468. }
  469. //create the checkall toggle
  470. if (_uniqueCol && priv.options.checkboxes) {
  471. var checked = _checkToggleChecked ? 'checked' : '';
  472. var headCell = $('<th></th>').appendTo(_headSort);
  473. var elem = $('<input {0} class="checkToggle" type="checkbox" />'.f(checked)).appendTo(headCell);
  474. elem.on('change', priv.checkToggleChanged);
  475. }
  476. //create the sortable headers
  477. for (var i = 0; i < colsSorted.length; i++) {
  478. var column = colsSorted[i];
  479. var props = _data.cols[column];
  480. if (!props.hidden) {
  481. var headCell = $('<th class="ta-ordering"></th>').appendTo(_headSort);
  482. if (i == 1) headCell.addClass('stickyCol2');
  483. if (false) {// TODO: old way
  484. var link = $('<a class="pull-left" href="#">{0}</a>'.f(props.friendly || column));
  485. link.on('click', {column: column}, priv.columnClicked).appendTo(headCell);
  486. if (props.tooltip) {
  487. $('<i class="icon-info-sign"></i>').tooltip({
  488. title: props.tooltip.trim(),
  489. html: true,
  490. container: 'body',
  491. placement: "top",
  492. delay: {
  493. show: 500,
  494. hide: 100
  495. }
  496. }).appendTo(link);
  497. }
  498. //Add sort arrow
  499. if (column == _currSortCol) {
  500. if (_currSortFlip) $('<i class="icon-chevron-down pull-right"></i>').appendTo(headCell);
  501. else $('<i class="icon-chevron-up pull-right"></i>').appendTo(headCell);
  502. }
  503. //Add hide btn
  504. if (column != 'ID') {
  505. var hideColBtn = $('<i class="icon-remove pull-right hover-show"></i>');
  506. hideColBtn.on('click', {column: column}, priv.columnHideClicked);
  507. hideColBtn.appendTo(headCell);
  508. }
  509. }
  510. if (props.type != 'special' && props.type != 'geom') {
  511. headCell.on('click', {column: column}, priv.columnClicked);
  512. }
  513. var colTitle = column;
  514. if (props._tsRetId) {
  515. colTitle = 'Kliknij na pole i przejdź do powiązanych rekordów (' + colTitle + ')';
  516. }
  517. if (props.friendly) {
  518. var headCnt = $('<span class="pull-left" title="{1}">{0}</span>'.f(props.friendly, colTitle));
  519. } else {
  520. var headCnt = $('<span class="pull-left" title="{1}">{0}</span>'.f(column, colTitle));
  521. }
  522. headCnt.appendTo(headCell);
  523. //Add sort arrow
  524. if (column == _currSortCol) {
  525. if (_currSortFlip) headCell.addClass('ta-ordering-down');
  526. else headCell.addClass('ta-ordering-up');
  527. }
  528. if (column != 'ID') {
  529. var hideColBtn = $('<i class="icon-remove remove-cell"></i>');
  530. hideColBtn.on('click', {column: column}, priv.columnHideClicked);
  531. hideColBtn.appendTo(headCell);
  532. }
  533. }
  534. }
  535. }
  536. //create the header filtering row
  537. if (!_headFilter && priv.options.filter) {
  538. _head.find(".filter").remove();
  539. _headFilter = $('<tr class="filter"></tr>').appendTo(_head);
  540. var headCell;
  541. var elem;
  542. var placeHolder = '';
  543. var tooltip = '';
  544. //create the functions column
  545. if (priv.options.rowFunctions || priv.options.filtersClean) {
  546. var headCell = $('<th class="text-right stickyCol1"></th>').appendTo(_headFilter);
  547. if (priv.options.filtersClean) {
  548. var elem = $('<a href="#" title="Kasuj filtry" class="ico-remove">&nbsp;</a>').appendTo(headCell);
  549. elem.on('click', priv.filtersClean);
  550. }
  551. }
  552. //create the filter checkbox
  553. if (_uniqueCol && priv.options.checkboxes) {
  554. tooltip = priv.options.types.bool.filterTooltip || 'Toggle between:<br/>indeterminate,<br/>checked,<br/>unchecked';
  555. headCell = $('<th></th>').appendTo(_headFilter);
  556. elem = $('<input class="filter indeterminate" checked type="checkbox" />').appendTo(headCell);
  557. $.map(_filterCols, function (colProps, col) {
  558. if (col == "unique") {
  559. if (colProps.filter) elem.prop('checked', true).removeClass('indeterminate');
  560. else if (!colProps.filter) elem.prop('checked', false).removeClass('indeterminate');
  561. else if (colProps.filter == '') elem.addClass('indeterminate');
  562. }
  563. });
  564. if (tooltip) {
  565. elem.tooltip({
  566. title: tooltip.trim(),
  567. html: true,
  568. container: 'body',
  569. trigger: 'hover',
  570. placement: 'top',
  571. delay: {
  572. show: 500,
  573. hide: 100
  574. }
  575. });
  576. }
  577. elem.on('click', {column: "unique"}, priv.filterChanged);
  578. }
  579. //create the column filters
  580. for (var i = 0; i < colsSorted.length; i++) {
  581. var column = colsSorted[i];
  582. var props = _data.cols[column];
  583. tooltip = props.filterTooltip === true ? undefined : props.filterTooltip === false ? '' : props.filterTooltip;
  584. placeHolder = props.placeHolder === true ? undefined : props.placeHolder === false ? '' : props.placeHolder;
  585. if (!props.hidden) {
  586. headCell = $('<th></th>').appendTo(_headFilter);
  587. if (i == 1) headCell.addClass('stickyCol2');
  588. // @mark MarkTableAjaxFilterColType
  589. switch (props.type || 'string') {
  590. case "number":
  591. if (placeHolder == undefined) placeHolder = priv.options.types.number.placeHolder;
  592. placeHolder = (placeHolder === true || placeHolder == undefined) ? '10..20 =50' : placeHolder === false ? '' : placeHolder;
  593. if (tooltip == undefined) tooltip = priv.options.types.number.filterTooltip;
  594. tooltip = (tooltip === true || tooltip == undefined) ? 'Values 10 to 20:<br/>10..20<br/>Values exactly 50:<br/>=50' : tooltip === false ? '' : tooltip;
  595. elem = $('<input placeholder="{0}" class="filter" type="text" />'.f(placeHolder));
  596. elem.on('keyup', {column: column}, priv.filterChanged);
  597. break;
  598. case "date":
  599. if (placeHolder == undefined) placeHolder = priv.options.types.date.placeHolder;
  600. placeHolder = (placeHolder === true || placeHolder == undefined) ? '-7..0' : placeHolder === false ? '' : placeHolder;
  601. if (tooltip == undefined) tooltip = priv.options.types.date.filterTooltip;
  602. tooltip = (tooltip === true || tooltip == undefined) ? 'Today:<br/>0..1<br/>A week today excluded:<br/>-7..0' : tooltip === false ? '' : tooltip;
  603. elem = $('<div><input placeholder="{0}" class="filter" type="text" /></div>'.f(placeHolder));
  604. if (priv.options.types.date.datePicker === true || priv.options.types.date.datePicker == undefined)
  605. {
  606. if ($().datepicker)
  607. {
  608. elem.addClass('date-wrap');
  609. var today = 0;//new priv.ext.XDate(false).setHours(0, 0, 0, 0).toString('yyyy-MM-dd');
  610. var dp = $('<div style="float:right" class="date" data-date="{0}" data-date-format="{1}" />'.f(today, 'yyyy-mm-dd')).appendTo(elem);
  611. $('<input style="display:none" type="text" />').appendTo(dp);
  612. $('<span class="add-on"><i class="icon-chevron-right"></i></span>').on('click', {op: "l"}, priv.dpOpChanged).appendTo(dp);
  613. $('<span class="add-on"><i class="icon-chevron-left"></i></span>').on('click', {op: "r"}, priv.dpOpChanged).appendTo(dp);
  614. dp.datepicker({weekStart:1});
  615. dp.on('changeDate', {column: column, input: $('input.filter', elem)}, priv.dpClicked);
  616. }
  617. else
  618. if (priv.options.debug) console.log('datepicker plugin not found');
  619. }
  620. elem.on('keyup', 'input.filter', {column: column}, priv.filterChanged);
  621. break;
  622. case "bool":
  623. if (tooltip == undefined) tooltip = priv.options.types.bool.filterTooltip;
  624. tooltip = (tooltip === true || tooltip == undefined) ? 'Toggle between:<br/>indeterminate,<br/>checked,<br/>unchecked' : tooltip === false ? '' : tooltip;
  625. elem = $('<input class="filter indeterminate" checked type="checkbox" />');
  626. elem.on('click', {column: column}, priv.filterChanged);
  627. break;
  628. case "string":
  629. if (placeHolder == undefined) placeHolder = priv.options.types.string.placeHolder;
  630. placeHolder = (placeHolder === true || placeHolder == undefined) ? '%' : placeHolder === false ? '' : placeHolder;
  631. if (tooltip == undefined) tooltip = priv.options.types.string.filterTooltip;
  632. tooltip = (tooltip === true || tooltip == undefined) ? 'Find str: str<br/>Find all but str: !str<br/>Find str inside: %str%' : tooltip === false ? '' : tooltip;
  633. elem = $('<input placeholder="{0}" class="filter" type="text" size="8" />'.f(placeHolder));
  634. elem.on('keyup', {column: column}, priv.filterChanged);
  635. break;
  636. case "special":
  637. elem = $('<div>&nbsp;</div>');
  638. break;
  639. case "geom":
  640. if (placeHolder == undefined) placeHolder = priv.options.types.string.placeHolder;
  641. placeHolder = (placeHolder === true || placeHolder == undefined) ? '%' : placeHolder === false ? '' : placeHolder;
  642. elem = $('<input placeholder="{0}" class="filter" type="text" size="8" />'.f(placeHolder));
  643. elem.on('keyup', {column: column}, priv.filterChanged);
  644. break;
  645. case "none":
  646. elem = $('<div>&nbsp;</div>');
  647. break;
  648. }
  649. if (false) {// tooltip OFF - (tooltip)
  650. elem.tooltip({
  651. title: tooltip.trim(),
  652. html: true,
  653. container: 'body',
  654. trigger: 'focus',
  655. placement: 'top',
  656. delay: {
  657. show: 500,
  658. hide: 100
  659. }
  660. });
  661. }
  662. if (elem && props.filter) {
  663. $.map(_filterCols, function (colProps, col) {
  664. if (col == column) {
  665. if (colProps.col.type == 'bool') {
  666. if (colProps.filter) elem.prop('checked', true).removeClass('indeterminate');
  667. else if (!colProps.filter) elem.prop('checked', false).removeClass('indeterminate');
  668. else if (colProps.filter == '') elem.addClass('indeterminate');
  669. }
  670. else elem.val(colProps.filter);
  671. }
  672. });
  673. if (priv.options.forceFilterInit && undefined !== priv.options.forceFilterInit[column]) {
  674. elem.prop('disabled', true);
  675. }
  676. elem.appendTo(headCell);
  677. _filterFields[column] = elem;
  678. }
  679. }
  680. }
  681. }
  682. //create the header special filters row
  683. if (!_headSpecialFilter && priv.options.specialFilterFunctions) {
  684. //create the functions column
  685. if (priv.options.specialFilterFunctions) {
  686. jQuery(_cont).prev('.TableAjax-SpecialFilter').remove();
  687. var _headSpecialFilter = $('<div class="btn-toolbar TableAjax-SpecialFilter"></div>').insertBefore(_cont);
  688. $.map(priv.options.specialFilterFunctions, function(groupObj, groupName) {
  689. var btnHtml, btnSelected, groupHtml = $('<div class="btn-group"></div>');
  690. // _specialFilters[e.data.group] = e.data.value;
  691. if (groupName in _specialFilters) {
  692. btnSelected = _specialFilters[groupName];
  693. }
  694. if (groupObj.icon) {
  695. $('<button class="btn btn-mini" title="' + groupName + '"><i class="' + groupObj.icon + '"></i></button>').appendTo(groupHtml);
  696. }
  697. $.map(groupObj.btns, function(btnObj, btnName) {
  698. btnHtml = $('<button class="btn btn-mini' + ((btnSelected && btnSelected == btnObj.value)? ' active' : '') + '">' + btnName + '</button>').appendTo(groupHtml);
  699. btnHtml.on('click', {group: groupName, value: btnObj.value}, priv.specialFilterChanged);
  700. });
  701. btnHtml = $('<button class="btn btn-mini' + ((!btnSelected)? ' disabled' : '') + '" title="Kasuj filtr"><i class="icon-remove"></i></button>').appendTo(groupHtml);
  702. btnHtml.on('click', {group: groupName, value: ''}, priv.specialFilterChanged);
  703. groupHtml.appendTo(_headSpecialFilter);
  704. });
  705. }
  706. }
  707. //create the body
  708. if (!_body) {
  709. _table.find('tbody').remove();
  710. _body = $('<tbody></tbody>').insertAfter(_head);
  711. _body.on('change', '.unique', priv.rowChecked);
  712. //_body.on('click', 'td', priv.rowClicked);
  713. //_body.on('dbclick', 'td', priv.rowDBClicked);
  714. //find out what rows to show next...
  715. var rowsAdded = 0;
  716. _data.toRow = _data.fromRow + priv.options.pageSize;
  717. if (_data.toRow > _data.total)
  718. _data.toRow = _data.total;
  719. //slice out the chunk of data we need and create rows
  720. //$.each(_data.rows.slice(_data.fromRow, _data.toRow), function (index, props) {
  721. $.each(_data.rows, function (index, props) {
  722. var row = $('<tr></tr>').appendTo(_body);
  723. if (priv.options.rowFunctions || priv.options.filtersClean) {
  724. var cell = $('<td class="text-right stickyCol1"></td>').appendTo(row);
  725. var cellID = _uniqueCol || 'ID';
  726. cellID = (cellID in props)? props[cellID] : null;
  727. $.map(priv.options.rowFunctions, function(funObj, funName){
  728. $(funObj.f(cellID)).appendTo(cell);
  729. });
  730. }
  731. //create checkbox
  732. if (_uniqueCol && priv.options.checkboxes) {
  733. var check = _uniqueCols[props[_uniqueCol]] != undefined ? 'checked' : '';
  734. var checkable = props['checkable'] === false ? 'disabled' : '';
  735. var cell = $('<td></td>').appendTo(row);
  736. $('<input class="unique" {0} {1} type="checkbox" />'.f(check, checkable)).appendTo(cell);
  737. }
  738. //create cells
  739. for (var i = 0; i < colsSorted.length; i++) {
  740. var key = colsSorted[i];
  741. var val = props[key];
  742. if (!_data.cols[key]) return;
  743. if (_data.cols[key].unique) row.data('unique', val);
  744. var cellID = _uniqueCol || 'ID';
  745. cellID = (cellID in props)? props[cellID] : null;
  746. if (!_data.cols[key].hidden) {
  747. var cell = $('<td></td>').appendTo(row);
  748. cell.on('dblclick', {id:cellID, col:key}, priv.rowDblClicked);
  749. var cellCnt = $('<span></span>').appendTo(cell);
  750. if (i == 1) cell.addClass('stickyCol2');
  751. cell.data('column', key);
  752. if (val === undefined) continue;
  753. var format = props[key + 'Format'] || _data.cols[key].format || '{0}';
  754. var showTooltip = true;
  755. switch (_data.cols[key].type) {
  756. case "string":
  757. cellCnt.html(format.f(val));
  758. break;
  759. case "number":
  760. val = Number(val);
  761. var forceDecimals = !isNaN(_data.cols[key].decimals);
  762. if (forceDecimals) cellCnt.html(format.f(val.toFixed(_data.cols[key].decimals)));
  763. else {
  764. (val || 0) % 1 === 0
  765. ? cellCnt.html(format.f(val))
  766. : cellCnt.html(format.f(val.toFixed(priv.options.types.number.decimals || 2)));
  767. }
  768. break;
  769. case "date":
  770. cellCnt.html(format.f(val));
  771. break;
  772. case "bool":
  773. $('<input type="checkbox" {0} disabled />'.f(val ? "checked" : "")).appendTo(cellCnt);
  774. break;
  775. case "special":
  776. cellCnt.html(format.f(val));
  777. break;
  778. case "geom":
  779. cellCnt.html('<i class="cell-mapfld icon-map-marker"></i>');
  780. cellCnt.on('click', {recordID: cellID, fieldValue: val}, function(e) {
  781. priv.mapEditorShow();
  782. _mapEditor.TableAjaxMapSelectRecord(e.data.recordID, e.data.fieldValue);
  783. });
  784. break;
  785. }
  786. if (_data.cols[key]._tsRetId) {
  787. showTooltip = false;
  788. if (_data.cols[key]._tsRetId > 0) {
  789. cellCnt.on('click', {id:cellID, col:key, friendly:_data.cols[key].friendly, value:format.f(val)}, priv.popoverCell);
  790. }
  791. }
  792. if (i > 1 && priv.options.longDesc) {
  793. cell.addClass('tbl-short-txt');
  794. if (showTooltip) {
  795. cellCnt.tooltip({title: cellCnt.text(), placement: 'left'});
  796. }
  797. }
  798. }
  799. }
  800. rowsAdded++;
  801. //enough rows created?
  802. if (rowsAdded >= priv.options.pageSize) {
  803. _data.toRow = _data.fromRow + rowsAdded;
  804. return false;
  805. }
  806. });
  807. if (_currPage == 1) {
  808. _pageSize = rowsAdded;
  809. _totalPages = Math.round(Math.ceil(_data.total / _pageSize));
  810. }
  811. //pad with empty rows if we're at last page.
  812. if (_currPage == _totalPages) {
  813. while (rowsAdded < _pageSize) {
  814. var row = $('<tr></tr>').appendTo(_body);
  815. if (_uniqueCol && priv.options.checkboxes) {
  816. var cell = $('<td></td>').appendTo(row);
  817. $('<input disabled type="checkbox" />').appendTo(cell);
  818. }
  819. if (priv.options.rowFunctions || priv.options.filtersClean) {
  820. $('<td class="text-right stickyCol1">&nbsp;</td>').appendTo(row);
  821. }
  822. var i = 0;
  823. $.each(_data.cols, function (column, props) {
  824. i++;
  825. if (props.hidden) return;
  826. if (i == 1) {
  827. $('<td class="stickyCol2">&nbsp;</td>').appendTo(row);
  828. } else {
  829. $('<td>&nbsp;</td>').appendTo(row);
  830. }
  831. });
  832. rowsAdded++;
  833. }
  834. }
  835. }
  836. //create the footer
  837. if (!_foot) {
  838. _table.find('tfoot').remove();
  839. _foot = $('<tfoot></tfoot>').insertAfter(_body);
  840. //var footRow = $('<tr></tr>').appendTo(_foot);
  841. //var footCell = $('<td colspan="999"></td>').appendTo(footRow);
  842. // TODO: test load footer after table
  843. $(_cont).next('.foot').remove();
  844. _foot = $('<div class="foot"></div>').insertAfter(_cont);
  845. //create summary
  846. if (_data.total > 0) {
  847. $('<div class="foot-info"><p>Wiersze od {0} do {1} z {2}</p></div>'.f(_data.fromRow + 1, Math.min(_data.toRow, _data.total), _data.total)).appendTo(_foot);
  848. } else {
  849. $('<div><p>Brak wierszy pasujących do kryteriów wyszukiwania</p></div>').appendTo(_foot);
  850. _totalPages = 0;
  851. }
  852. //create the pager.
  853. var lowerPage = _currPage - 2;
  854. var upperPage = _currPage + 2;
  855. if (upperPage > _totalPages) {
  856. var diff = upperPage - _totalPages;
  857. upperPage = _totalPages;
  858. lowerPage -= diff;
  859. }
  860. if (lowerPage < 1) lowerPage = 1;
  861. if (upperPage < 5) upperPage = 5;
  862. var footToolbar = $('<div class="btn-toolbar"></div>').appendTo(_foot);
  863. var footDiv = $('<div class="btn-group"></div>').appendTo(footToolbar);
  864. var footPagerDiv = $('<div class="pagination"></div>').appendTo(footDiv);
  865. var footPagerUl = $('<ul></ul>').appendTo(footPagerDiv);
  866. $('<li class="{0}"><a href="#">&lt;&lt;</a></li>'.f(_currPage == 1 ? 'disabled' : ''))
  867. .on('click', {pageIndex: 1}, priv.pageChanged).appendTo(footPagerUl);
  868. $('<li class="{0}"><a href="#">&lt;</a></li>'.f(_currPage == 1 ? 'disabled' : ''))
  869. .on('click', {pageIndex: _currPage - 1}, priv.pageChanged).appendTo(footPagerUl);
  870. for (var i = lowerPage; i <= upperPage; i++) {
  871. var link;
  872. if (i != _currPage) link = $('<li class="{1}"><a href="#">{0}</a></li>'.f(i, i > _totalPages ? 'disabled' : ''));
  873. if (i == _currPage) link = $('<li class="active"><a href="#">{0}</a></li>'.f(i));
  874. if (link) {
  875. link.on('click', {pageIndex: i}, priv.pageChanged);
  876. link.appendTo(footPagerUl);
  877. }
  878. }
  879. $('<li class="{0}"><a href="#">&gt;</a></li>'.f(_currPage == _totalPages ? 'disabled' : ''))
  880. .on('click', {pageIndex: _currPage + 1}, priv.pageChanged).appendTo(footPagerUl);
  881. $('<li class="{0}"><a href="#">&gt;&gt;</a></li>'.f(_currPage == _totalPages ? 'disabled' : ''))
  882. .on('click', {pageIndex: _totalPages}, priv.pageChanged).appendTo(footPagerUl);
  883. //create pagesize dropdown
  884. if (priv.options.pageSizes.length) {
  885. var div = $('<div class="btn-group dropup pagesize"></div>').appendTo(footToolbar);
  886. var btn = $('<button class="btn btn-small dropdown-toggle" data-toggle="dropdown" href="#">Liczba wierszy&nbsp;</button>').appendTo(div);
  887. var span = $('<span class="caret"></span>').appendTo(btn);
  888. var ul = $('<ul class="dropdown-menu">').appendTo(div);
  889. $.each(priv.options.pageSizes, function (index, val) {
  890. var li = $('<li></li>').appendTo(ul);
  891. $('<a href="#">{0}</a>'.f(val)).appendTo(li);
  892. });
  893. div.on('click', 'a', priv.pageSizeChanged);
  894. }
  895. //create columnpicker dropdown
  896. if (priv.options.columnPicker) {
  897. var div = $('<div class="btn-group dropup columnpicker"></div>').appendTo(footToolbar);
  898. var btn = $('<button class="btn btn-small dropdown-toggle" data-toggle="dropdown" href="#">Kolumny&nbsp;</button>').appendTo(div);
  899. var span = $('<span class="caret"></span>').appendTo(btn);
  900. var ul = $('<ul class="dropdown-menu">').appendTo(div);
  901. $.each(_data.cols, function (col, props) {
  902. if (props.type != "unique" && col != 'ID') {
  903. var li = $('<li></li>').appendTo(ul);
  904. $('<input {0} type="checkbox" title="{1}" value="{1}" >&nbsp;{2}</input>'.f((props.hidden) ? '' : 'checked', col, props.friendly || col)).appendTo(li);
  905. }
  906. });
  907. div.on('click', 'input', priv.columnPickerClicked);
  908. }
  909. if (priv.options.rowFunctions) {
  910. $.map(priv.options.tblFunctions, function(funObj, funName){
  911. var div = $('<div class="btn-group"></div>').appendTo(footToolbar);
  912. var funHtml = $('<button class="btn btn-small"></button>');
  913. if (funObj.title) funHtml.attr('title', funObj.title);
  914. if (funObj.method) funHtml.on('click', priv[funObj.method]);
  915. else if (funObj.href) funHtml.on('click', {hash:funObj.href}, priv.routeChanged);
  916. var funIconHtml = $('<i></i>');
  917. if (funObj.icon) funIconHtml.attr('class', 'icon-' + funObj.icon);
  918. funIconHtml.prependTo(funHtml);
  919. funHtml.addClass('btn');
  920. funHtml.appendTo(div);
  921. });
  922. }
  923. //create actions dropdown
  924. if (priv.options.actions) {
  925. var div = $('<div class="btn-group dropup actions"></div>').appendTo(footToolbar);
  926. var btn = $('<button class="btn dropdown-toggle" data-toggle="dropdown" href="#"><i class="icon-list"></i>&nbsp;</button>').appendTo(div);
  927. var span = $('<span class="caret"></span>').appendTo(btn);
  928. var ul = $('<ul class="dropdown-menu">').appendTo(div);
  929. if (priv.options.actions.filter) {
  930. var li = $('<li></li>').appendTo(ul);
  931. $('<input {0} type="checkbox" >&nbsp;Filter</input>'.f(priv.options.filter ? 'checked' : '')).appendTo(li);
  932. li.on('click', 'input', function (e) {
  933. priv.options.filter = !priv.options.filter;
  934. _head = undefined;
  935. priv.createTable();
  936. });
  937. }
  938. if (priv.options.actions.columnPicker) {
  939. var li = $('<li></li>').appendTo(ul);
  940. $('<input {0} type="checkbox" >&nbsp;ColumnPicker</input>'.f(priv.options.columnPicker ? 'checked' : '')).appendTo(li);
  941. li.on('click', 'input', function (e) {
  942. priv.options.columnPicker = !priv.options.columnPicker;
  943. _foot = undefined;
  944. priv.createTable();
  945. });
  946. }
  947. if (priv.options.actions.custom) {
  948. $.each(priv.options.actions.custom, function (index, val) {
  949. var li = $('<li></li>').appendTo(ul);
  950. $(val).appendTo(li);
  951. });
  952. }
  953. }
  954. }
  955. var stickyCol1Width = 55;
  956. var stickyCol2Width = 50;
  957. if (undefined === _tableWidth) {
  958. _tableWidth = true;
  959. var contW = jQuery(_cont).width();
  960. //console.log('_cont.width: ' + jQuery(_cont).width());
  961. var th1 = _table.find('.stickyCol1:first');
  962. var th2 = th1.next();
  963. var th1W = th1.innerWidth();
  964. var th2W = 50 + 2 * 5;//th2.innerWidth();
  965. var colsW = stickyCol1Width + 2 * 5 + 1 + stickyCol2Width + 2 * 5 + 1;
  966. //console.log('thF.width: ' + th1W + '; ' + th2W + '; colsW: ' + colsW);
  967. //jQuery(_cont).width(contW - colsW);
  968. jQuery(_cont).css({width:'' + (contW - colsW) + 'px', marginLeft:'' + colsW + 'px', overflowX:'scroll', overflowY:'visible', paddingBottom:'1px'});
  969. //console.log('_cont.width new: ' + jQuery(_cont).width());
  970. }
  971. _table.find('.stickyCol1').css({position:'absolute',
  972. left:'0',
  973. top:'auto',
  974. width:'' + stickyCol1Width + 'px',
  975. });
  976. _table.find('.stickyCol2').css({position:'absolute',
  977. left:'' + (stickyCol1Width + 2 * 5 + 1) + 'px',
  978. top:'auto',
  979. width:'' + stickyCol2Width + 'px',
  980. borderRight: '1px solid silver'
  981. });
  982. if (_data.total == 0 && priv.options.hidePagerOnEmpty) {
  983. $('.btn-toolbar', _foot).remove();
  984. }
  985. if (priv.options.debug) console.log('table created L.<?php echo __LINE__; ?>');
  986. if (typeof priv.options.tableCreated == 'function') {
  987. priv.options.tableCreated.call(_table.get(0), {table: _table.get(0)});
  988. }
  989. if (!_inlineEditBox) {
  990. $(_foot).next('.inlineEditBox').remove();
  991. _inlineEditBox = $('<div class="inlineEditBox modal hide fade" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"></div>').insertAfter(_foot);
  992. var frmInlineEdit = $('<form style="margin:0;padding:0;"></form>').appendTo(_inlineEditBox);
  993. var iebHead = $('<div class="modal-header">').appendTo(frmInlineEdit);
  994. $('<button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="icon-remove"></i></button>').appendTo(iebHead);
  995. $('<h3 id="myModalLabel">Edytuj</h3>').appendTo(iebHead);
  996. var iebBody = $('<div class="modal-body"></div>').appendTo(frmInlineEdit);
  997. $('<input type="hidden" name="ID" value="">').appendTo(iebBody);
  998. $('<input type="hidden" name="col" value="">').appendTo(iebBody);
  999. $('<div class="inlineEditBox-cnt"></div>').appendTo(iebBody);
  1000. var iebFoot = $('<div class="modal-footer"></div>').appendTo(frmInlineEdit);
  1001. $('<button class="btn" data-dismiss="modal" aria-hidden="true">Zamknij</button>').appendTo(iebFoot);
  1002. var iebBtnSave = $('<input type="submit" value="Zapisz" class="btn btn-primary btn-save">').appendTo(iebFoot);
  1003. frmInlineEdit.on('submit', function() {
  1004. var data = _inlineEditBox.find('form').serialize();
  1005. _inlineEditBox.find('.inlineEditBox-cnt').html('<span class="loading-info"> loading ...</span>');
  1006. jQuery.ajax({
  1007. url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=EDIT_INLINE_SAVE',
  1008. type: 'POST',
  1009. dataType: 'text',
  1010. data: data,
  1011. async: true,
  1012. success: function (data) {
  1013. //console.log('_inlineEditBox submit ajax data:', data);
  1014. _inlineEditBox.find('.inlineEditBox-cnt').html(data);
  1015. _inlineEditBox.find('.btn-save').hide();
  1016. publ.loadPage(_currPage);
  1017. },
  1018. error: function (jhr, textStatus, errorThrown) {
  1019. console.log('_inlineEditBox submit ajax error');
  1020. }
  1021. });
  1022. return false;
  1023. });
  1024. }
  1025. if (!_popoverCell) {
  1026. $(_foot).next('.popoverCell').remove();
  1027. _popoverCell = $('<div class="popoverCell" style="display:none"></div>').insertAfter(_foot);
  1028. }
  1029. if (!_mapEditorWrap) {
  1030. $(_foot).next('.mapEditor').remove();
  1031. _mapEditorWrap = $('<div class="mapEditor" style="display:none"></div>').insertAfter(_foot);
  1032. _mapEditor = $('<div class="mapEditor-map"></div>').appendTo(_mapEditorWrap);
  1033. }
  1034. };
  1035. /*
  1036. calls the webservice(if defined).
  1037. used only inside priv.init
  1038. */
  1039. priv.update = function (callback, skipCols, resetChecked) {
  1040. if (!priv.options.url) {
  1041. if (priv.options.debug) console.log('no url found L.<?php echo __LINE__; ?>');
  1042. return;
  1043. }
  1044. if (priv.options.debug) console.log('requesting data from url:{0} data:{1} L.<?php echo __LINE__; ?>'.f(priv.options.url, JSON.stringify(priv.options.urlData) || ''));
  1045. var initUrlAdd = '',
  1046. reqData = {},
  1047. filtersInitSet = false;
  1048. if (priv.options.filterInit) {
  1049. $.map(priv.options.filterInit, function (fltrProps, fltr) {
  1050. switch (fltr) {
  1051. case 'currSortCol':
  1052. _currSortCol = fltrProps;
  1053. initUrlAdd += '&currSortCol=' + fltrProps;
  1054. break;
  1055. case 'currSortFlip':
  1056. _currSortFlip = (fltrProps == 'desc')? true : false;
  1057. initUrlAdd += '&currSortFlip=' + fltrProps;
  1058. break;
  1059. default:
  1060. if (fltr.substr(0, 3) == 'sf_') {
  1061. reqData[fltr] = fltrProps;
  1062. filtersInitSet = true;
  1063. }
  1064. else if (fltr.substr(0, 2) == 'f_') {
  1065. reqData[fltr] = fltrProps;
  1066. filtersInitSet = true;
  1067. }
  1068. }
  1069. });
  1070. }
  1071. if (priv.options.forceFilterInit) {
  1072. $.map(priv.options.forceFilterInit, function (fltrProps, fltr) {
  1073. reqData['f_' + fltr] = fltrProps;
  1074. filtersInitSet = true;
  1075. });
  1076. }
  1077. $.ajax({
  1078. url: priv.options.url + initUrlAdd,
  1079. type: priv.options.urlPost ? 'POST' : 'GET',
  1080. dataType: 'json',
  1081. contentType: "application/json; charset=utf-8",
  1082. data: reqData,
  1083. async: true,
  1084. success: function (data) {
  1085. if (priv.options.debug) console.log('request finished L.<?php echo __LINE__; ?>');
  1086. //assign the new data
  1087. if (data.d && data.d.cols)
  1088. priv.setData(data.d, skipCols, resetChecked);
  1089. else
  1090. priv.setData(data, skipCols, resetChecked);
  1091. // set initial filters
  1092. if (filtersInitSet && _data && _data.cols) {
  1093. $.map(reqData, function(fltrValue, fltr){
  1094. var colName = null;
  1095. if (fltr.substr(0, 3) == 'sf_') {
  1096. colName = fltr.substr(3);
  1097. }
  1098. else if (fltr.substr(0, 2) == 'f_') {
  1099. colName = fltr.substr(2);
  1100. }
  1101. if (colName && _data.cols[colName]) {
  1102. //add the filter to the filter array
  1103. _filterCols[colName] = {
  1104. filter: fltrValue,
  1105. col: _data.cols[colName]
  1106. };
  1107. }
  1108. });
  1109. }
  1110. //assign the new data
  1111. if (data.d && data.d.cols)
  1112. priv.setData(data.d, skipCols, resetChecked);
  1113. else
  1114. priv.setData(data, skipCols, resetChecked);
  1115. if (typeof callback == "function")
  1116. callback.call(this);
  1117. },
  1118. error: function (err) {
  1119. //console.log('request error: {0}'.f(JSON.stringify(err)));
  1120. if (typeof callback == "function")
  1121. callback.call(this);
  1122. }
  1123. });
  1124. };
  1125. /*
  1126. assigns the new data.
  1127. */
  1128. priv.setData = function (pData, skipCols, resetChecked) {
  1129. var data = $.extend(true, {}, pData);
  1130. data.fromRow = _data && _data.fromRow || 0;
  1131. data.toRow = _data && _data.toRow || 0;
  1132. //use previous column definitions?
  1133. skipCols = skipCols || false;
  1134. if (skipCols) data.cols = _data.cols;
  1135. //else _filterCols = {};
  1136. _data = data;
  1137. _data.rowsOrg = _data.rows;
  1138. //we might have more/less data now. Recalculate stuff.
  1139. if (_currPage > 1) {
  1140. _data.toRow = Math.min(_data.total, _data.toRow);
  1141. _data.fromRow = _data.toRow - _pageSize;
  1142. _data.fromRow = Math.max(_data.fromRow, 0);
  1143. _currPage = Math.ceil(_data.fromRow / _pageSize) + 1;
  1144. _totalPages = Math.ceil(_data.total / _pageSize);
  1145. } else {
  1146. _data.fromRow = 0;
  1147. if (priv.options.pageSize != -1)
  1148. _data.toRow = _data.fromRow + priv.options.pageSize;
  1149. _data.toRow = Math.max(_data.toRow, _data.total);
  1150. }
  1151. //wash the new data a bit
  1152. _uniqueCol = "";
  1153. $.each(_data.cols, function (col, props) {
  1154. //set sorting
  1155. if (!_currSortCol && props.sortOrder) {
  1156. _currSortCol = col;
  1157. _currSortFlip = props.sortOrder != "asc";
  1158. }
  1159. //default to string type if missing
  1160. if (!props.type) _data.cols[col].type = "string";
  1161. //if several unique columns is defined, use the first.
  1162. if (props.unique) {
  1163. if (!_uniqueCol) _uniqueCol = col;
  1164. else props.unique = false;
  1165. }
  1166. //if index property is missing, create one
  1167. if (!props.index) _data.cols[col].index = new Number(0);//priv.ext.XDate();
  1168. props.column = col;
  1169. //set any initial filter
  1170. if (!skipCols) {
  1171. if (props.filter == undefined) props.filter = true;
  1172. if (props.filter && typeof props.type != "bool" && typeof props.filter != "boolean") {
  1173. _filterCols[col] = _filterCols[col] || {
  1174. filter: String(props.filter),
  1175. col: props
  1176. };
  1177. }
  1178. }
  1179. });
  1180. //keep any previously checked rows around?
  1181. if (resetChecked === true || resetChecked === undefined)
  1182. _uniqueCols = {};
  1183. else {
  1184. for (var key in _uniqueCols)
  1185. _uniqueCols[key] = priv.getRow(key);
  1186. }
  1187. if (_uniqueCol) {
  1188. //create a unique column definition
  1189. _data.cols["unique"] = {
  1190. column: "unique",
  1191. type: "unique",
  1192. index: -1,
  1193. hidden: true
  1194. };
  1195. //add rows that needs to be pre-checked
  1196. $.each(_data.rows, function (index, row) {
  1197. if (row["checked"] === true)
  1198. _uniqueCols[row[_uniqueCol]] = row;
  1199. });
  1200. }
  1201. if (!skipCols) {
  1202. _head = undefined;
  1203. }
  1204. _body = undefined;
  1205. _foot = undefined;
  1206. priv.createTable();
  1207. };
  1208. /**
  1209. * Filters the data.
  1210. */
  1211. priv.filter = function () {
  1212. if (!priv.options.filter) return;
  1213. if (Object.keys(_filterCols).length == 0) return;
  1214. publ.loadPage(0);
  1215. };
  1216. /*
  1217. sorts the data on the current sorting column
  1218. */
  1219. priv.sort = function () {
  1220. if (!_data.cols[_currSortCol]) _currSortCol = "";
  1221. if (!_currSortCol) return;
  1222. publ.loadPage(0);
  1223. };
  1224. /*
  1225. helper that returns the underlying data by the unique value
  1226. */
  1227. priv.getRow = function (unique) {
  1228. var row;
  1229. $.each(_data.rowsOrg, function (i, r) {
  1230. if (r[_uniqueCol] == unique) {
  1231. row = r;
  1232. return false;
  1233. }
  1234. });
  1235. return row;
  1236. };
  1237. /*
  1238. when: typing a filter
  1239. what: triggers filtering on the value
  1240. */
  1241. priv.filterChanged = function (e) {
  1242. //clear old timer if we're typing fast enough
  1243. if (_filterTimeout) {
  1244. clearTimeout(_filterTimeout);
  1245. if (priv.options.debug) console.log('filtering cancelled');
  1246. }
  1247. var filter = this.value
  1248. , fltr = $(this)
  1249. , col = _data.cols[e.data.column]
  1250. , timeout = 300;
  1251. if (this.value) {
  1252. if (!fltr.hasClass('filter-active')) {
  1253. fltr.addClass('filter-active');
  1254. }
  1255. } else {
  1256. if (fltr.hasClass('filter-active')) {
  1257. fltr.removeClass('filter-active');
  1258. }
  1259. }
  1260. //boolean filters needs some special care
  1261. if (col.type == "bool" || col.type == "unique") {
  1262. timeout = 0;
  1263. var elem = $(this);
  1264. var cssClass = 'indeterminate';
  1265. if (elem.hasClass(cssClass)) {
  1266. e.preventDefault();
  1267. elem.removeClass(cssClass);
  1268. filter = true;
  1269. } else {
  1270. if (!elem.is(':checked')) {
  1271. filter = false;
  1272. } else {
  1273. elem.addClass(cssClass);
  1274. filter = '';
  1275. }
  1276. }
  1277. }
  1278. //add the filter to the filter array
  1279. _filterCols[col.column] = {
  1280. filter: filter,
  1281. col: col
  1282. };
  1283. //wait a few deciseconds before filtering
  1284. _filterTimeout = setTimeout(function () {
  1285. _filterTimeout = undefined;
  1286. priv.filter();
  1287. }, timeout);
  1288. };
  1289. priv.filtersClean = function (e) {
  1290. if (_filterTimeout) {
  1291. clearTimeout(_filterTimeout);
  1292. if (priv.options.debug) console.log('filtering cancelled - filtersClean');
  1293. }
  1294. var filtersActive = false;
  1295. $.map(_filterCols, function (colProps, col) {
  1296. if (colProps.filter.length > 0) {
  1297. filtersActive = true;
  1298. colProps.filter = '';
  1299. }
  1300. });
  1301. if (filtersActive) {
  1302. // TODO: dont remove value from forceFilterInit fields - no field names in search fields?
  1303. var elems = _head.find('tr.filter').find('input');
  1304. _head.find('tr.filter').find('input').val('').prop('disabled', false);
  1305. priv.filter();
  1306. }
  1307. return false;
  1308. },
  1309. /**
  1310. * Filters the data by specialFilter.
  1311. * when: click on special filter
  1312. * what: triggers filtering on the value
  1313. */
  1314. priv.specialFilterChanged = function (e) {
  1315. console.log('specialFilterChanged...');
  1316. console.log(e.data);
  1317. _specialFilters[e.data.group] = e.data.value;
  1318. publ.loadPage(0);
  1319. };
  1320. priv.longTextChanged = function(e) {
  1321. priv.options.longDesc = !priv.options.longDesc;
  1322. _body.find('td').each(function(ind, el){
  1323. var $el = jQuery(el);
  1324. if (!$el.attr('class') || $el.attr('class') == 'tbl-short-txt') {
  1325. //console.log(el.attr('class') + ': ' + el.text());
  1326. if (el.firstChild && el.firstChild.nodeName == 'SPAN') {
  1327. if (priv.options.longDesc) {
  1328. $el.addClass('tbl-short-txt');
  1329. var $elSpan = jQuery(el.firstChild);
  1330. $elSpan.tooltip({title: $elSpan.text(), placement: 'left'});
  1331. } else {
  1332. $el.removeClass('tbl-short-txt');
  1333. }
  1334. }
  1335. }
  1336. });
  1337. return false;
  1338. },
  1339. priv.mapEditorHide = function() {
  1340. priv.options.mapEditor = false;
  1341. //_mapEditorDialog.dialog("close");
  1342. _mapEditorDialog.dialog("destroy");
  1343. }
  1344. priv.mapEditorShow = function() {
  1345. priv.options.mapEditor = true;
  1346. _mapEditorWrap.show();
  1347. _mapEditor.TableAjaxMap({
  1348. wpsUrl: 'http://biuro.biall-net.pl/wps',
  1349. wfsUrl: 'http://biuro.biall-net.pl/wps',
  1350. layerName: '<?php echo $this->getLabelHtml(); ?>',
  1351. onSaveFeature: function(selectedRecordId, selectedFeatureExtent) {
  1352. console.log('onSaveFeature (',selectedRecordId,'/',selectedFeatureExtent,') ', this);
  1353. if (!selectedRecordId) {
  1354. alert('Brak zaznaczonego rekordu - wybierz rekord z tabeli');
  1355. return;
  1356. }
  1357. $.ajax({
  1358. data: {polygon: selectedFeatureExtent},
  1359. type: "POST",
  1360. url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=THE_GEOM_SAVE&ID=' + selectedRecordId
  1361. })
  1362. .done(function(data, textStatus, jqXHR){
  1363. //TODO: update table cell data; that.data("treetable").updateNodeHtmlData(id, jqXHR.responseText);
  1364. jQuery.notify('Aktualizacja danych dla rekordu ' + selectedRecordId, 'success');
  1365. })
  1366. .fail(function(jqXHR){// jqXHR.fail(function( jqXHR, textStatus, errorThrown ) {});
  1367. var txt = jqXHR.responseText || 'Error';
  1368. if (jqXHR.status == 404) {
  1369. jQuery.notify(jqXHR.responseText, 'error');
  1370. } else {
  1371. jQuery.notify(jqXHR.responseText, 'warn');
  1372. }
  1373. });
  1374. },
  1375. onSelectBox: function(bounds) {
  1376. if (undefined !== OpenLayers.Bounds && bounds instanceof OpenLayers.Bounds) {
  1377. var column = 'the_geom';
  1378. if (undefined !== _filterFields['the_geom']) {
  1379. var filter = 'BBOX:' + bounds.top + ',' + bounds.right + ',' + bounds.bottom + ',' + bounds.left;
  1380. _filterFields[column].val(filter);
  1381. _filterCols[column] = {
  1382. filter: filter,
  1383. col: _data.cols[column]
  1384. };
  1385. priv.filter();
  1386. }
  1387. }
  1388. }
  1389. });
  1390. _mapEditorDialog = _mapEditorWrap.dialog({
  1391. width: 540,
  1392. minWidth: 400,
  1393. minHeight: 300,
  1394. resizeStop: function(){
  1395. _mapEditor.TableAjaxMapUpdateSize(); //to prevent drag-zoom error
  1396. },
  1397. dragStop: function(){
  1398. _mapEditor.TableAjaxMapUpdateSize(); //to prevent drag-zoom error
  1399. }
  1400. });
  1401. _mapEditorWrap.bind('dialogclose', function(e) {
  1402. priv.options.mapEditor = false;
  1403. });
  1404. }
  1405. priv.mapEditorChanged = function(e) {
  1406. console.log('mapEditorChanged option(',priv.options.mapEditor,') e:', e);
  1407. priv.options.mapEditor = !priv.options.mapEditor;
  1408. if (priv.options.mapEditor) {
  1409. priv.mapEditorShow();
  1410. }
  1411. else {
  1412. priv.mapEditorHide();
  1413. }
  1414. return false;
  1415. },
  1416. /*
  1417. when: changing page in pager
  1418. what: triggers table to be created with new page
  1419. */
  1420. priv.pageChanged = function (e) {
  1421. e.preventDefault();
  1422. if (e.data.pageIndex < 1 || e.data.pageIndex > _totalPages) return;
  1423. //set the new page
  1424. _currPage = e.data.pageIndex;
  1425. if (priv.options.debug) console.log('paging to index:{0} L.<?php echo __LINE__; ?>'.f(_currPage));
  1426. //find out what rows to create
  1427. _data.fromRow = ((_currPage - 1) * _pageSize);
  1428. _data.toRow = _data.fromRow + _pageSize;
  1429. if (_data.toRow > _data.rows.length) _data.toRow = _data.rows.length;
  1430. //trigger callback
  1431. if (typeof priv.options.pageChanged == 'function') {
  1432. priv.options.pageChanged.call(e.target, {
  1433. event: e,
  1434. page: _currPage
  1435. });
  1436. }
  1437. _body = undefined;
  1438. _foot = undefined;
  1439. priv.createTable();
  1440. };
  1441. /*
  1442. when: changing pagesize in pagesize dropdown
  1443. what: triggers table to be created with new pagesize
  1444. */
  1445. priv.pageSizeChanged = function (e) {
  1446. e.preventDefault();
  1447. var val = $(this).text().toLowerCase();
  1448. if (priv.options.debug) console.log('pagesize changed to:{0}'.f(val));
  1449. //set the new pagesize
  1450. if (val == "all") priv.options.pageSize = _data.rows.length;
  1451. else priv.options.pageSize = parseInt(val);
  1452. //revert to first page, as its gets messy otherwise.
  1453. _currPage = 1;
  1454. _data.fromRow = 0;
  1455. _data.toRow = _data.fromRow + priv.options.pageSize;
  1456. if (_data.toRow > _data.rows.length) _data.toRow = _data.rows.length;
  1457. //trigger callback
  1458. if (typeof priv.options.pageSizeChanged == 'function') {
  1459. priv.options.pageSizeChanged.call(e.target, {
  1460. event: e,
  1461. pageSize: priv.options.pageSize
  1462. });
  1463. }
  1464. _body = undefined;
  1465. _foot = undefined;
  1466. priv.createTable();
  1467. };
  1468. /*
  1469. when: clicking a column
  1470. what: triggers table to be sorted by the column
  1471. */
  1472. priv.columnClicked = function (e) {
  1473. e.preventDefault();
  1474. if (priv.options.debug) console.log('col:{0} clicked'.f(e.data.column));
  1475. //set the new sorting column
  1476. if (_currSortCol == e.data.column) _currSortFlip = !_currSortFlip;
  1477. _currSortCol = e.data.column;
  1478. //trigger callback
  1479. if (typeof priv.options.columnClicked == 'function') {
  1480. priv.options.columnClicked.call(e.target, {
  1481. event: e,
  1482. column: _data.cols[_currSortCol],
  1483. descending: _currSortFlip
  1484. });
  1485. }
  1486. _headSort = undefined;
  1487. _body = undefined;
  1488. priv.sort();
  1489. };
  1490. priv.saveHiddenCols = function() {
  1491. var reqData = {};
  1492. $.each(_data.cols, function (col, props) {
  1493. if (props.type != "unique" && col != 'unique' && col != 'ID') {
  1494. reqData[col] = (props.hidden)? 'HIDE' : 'SHOW';
  1495. }
  1496. });
  1497. $.ajax({
  1498. url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=HIDDEN_COLS_SAVE',
  1499. type: 'POST',
  1500. dataType: 'text',
  1501. data: reqData,
  1502. async: true,
  1503. success: function (data) {
  1504. //console.log('hidden cols saved');
  1505. },
  1506. error: function (err) {
  1507. console.log('request error: {0}'.f(JSON.stringify(err)));
  1508. }
  1509. });
  1510. };
  1511. /*
  1512. when: clicking a column in columnpicker
  1513. what: triggers table to show/hide the column
  1514. */
  1515. priv.columnPickerClicked = function (e) {
  1516. e.stopPropagation();
  1517. var column = $(this).val();
  1518. //toggle column visibility
  1519. _data.cols[column].hidden = !_data.cols[column].hidden;
  1520. priv.saveHiddenCols();
  1521. //_data.cols[column].index = new priv.ext.XDate();
  1522. _head = undefined;
  1523. _body = undefined;
  1524. priv.createTable();
  1525. };
  1526. priv.columnHideClicked = function (e) {
  1527. e.stopPropagation();
  1528. var column;
  1529. if (e.data && e.data.column) {
  1530. column = e.data.column;
  1531. } else {
  1532. return;
  1533. }
  1534. //toggle column visibility
  1535. _data.cols[column].hidden = !_data.cols[column].hidden;
  1536. priv.saveHiddenCols();
  1537. //_data.cols[column].index = new priv.ext.XDate();
  1538. _head = undefined;
  1539. _body = undefined;
  1540. _foot = undefined;
  1541. priv.createTable();
  1542. };
  1543. /*
  1544. when: clicking a row checkbox
  1545. what: toggles checked state on row, and add/removes it from checked array
  1546. */
  1547. priv.rowChecked = function (e) {
  1548. var elem = $(this);
  1549. //get the row's unique value
  1550. var unique = elem.closest('tr').data('unique');
  1551. if (priv.options.debug) console.log('row({0}) {1}'.f(unique, elem.is(':checked') ? 'checked' : 'unchecked'));
  1552. //store the row in checked array
  1553. if (elem.is(':checked')) _uniqueCols[unique] = priv.getRow(unique);
  1554. else delete _uniqueCols[unique];
  1555. };
  1556. /*
  1557. when: clicking anywhere on a row
  1558. what: row data and other info is returned to caller
  1559. */
  1560. priv.rowClicked = function (e) {
  1561. if (!_uniqueCol) {
  1562. if (priv.options.debug) console.log('no unique column specified');
  1563. return;
  1564. }
  1565. //gather callback data
  1566. var elem = $(this);
  1567. var column = _data.cols[elem.data('column')];
  1568. var unique = elem.closest('tr').data('unique');
  1569. var row = priv.getRow(unique);
  1570. var isChecked = elem.closest('tr').find('.unique').is(':checked');
  1571. //trigger callback
  1572. if (typeof priv.options.rowClicked == 'function') {
  1573. priv.options.rowClicked.call(e.target, {
  1574. event: e,
  1575. row: row,
  1576. column: column,
  1577. checked: isChecked
  1578. });
  1579. }
  1580. };
  1581. /**
  1582. * Inline edit.
  1583. */
  1584. priv.rowDblClicked = function (e) {
  1585. // hide popover for typespecial fld on click
  1586. if (_popoverCellCurrent) {
  1587. _popoverCellCurrent.popover('hide');
  1588. }
  1589. // e.clientX: 1002; e.clientY: 245
  1590. if ('id' in e.data && 'col' in e.data && e.data.id > 0) {
  1591. _inlineEditBox.modal();
  1592. //_inlineEditBox.css({'position':'absolute', 'top':'100px', 'left':'100px'});
  1593. _inlineEditBox.show();
  1594. _inlineEditBox.find('input[name=ID]').val(e.data.id);
  1595. _inlineEditBox.find('input[name=col]').val(e.data.col);
  1596. _inlineEditBox.find('.inlineEditBox-cnt').html('<span class="loading-info"> loading ...</span>');
  1597. $.ajax({
  1598. url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=EDIT_INLINE&ID=' + e.data.id + '&col=' + e.data.col,
  1599. type: 'GET',
  1600. dataType: 'text',
  1601. data: '',
  1602. async: true,
  1603. success: function (data) {
  1604. _inlineEditBox.find('.inlineEditBox-cnt').html(data);
  1605. _inlineEditBox.find('.btn-save').show();
  1606. _inlineEditBox.find('.se_type-date').datepicker({
  1607. format: "yyyy-mm-dd"
  1608. , language: 'pl'
  1609. , todayBtn: "linked"
  1610. });
  1611. _inlineEditBox.find('.se_type-datetime').parent().datetimepicker({
  1612. language: 'pl'
  1613. , format: 'yyyy-MM-dd hh:mm'
  1614. , weekStart: 1
  1615. });
  1616. _inlineEditBox.find('textarea').autosize();
  1617. var fld = _inlineEditBox.find('input[id^="f"]');
  1618. if (fld && !fld.hasClass('se_type-date')) {
  1619. fld.focus();
  1620. fld.keydown(function(event) {
  1621. console.log('input keydown: ', event.which);
  1622. if (event.which == 13) {
  1623. event.preventDefault();
  1624. _inlineEditBox.find('form').submit();
  1625. }
  1626. });
  1627. }
  1628. },
  1629. error: function (err) {
  1630. console.log('err');
  1631. }
  1632. });
  1633. } else {
  1634. console.log('NO data');
  1635. return false;
  1636. }
  1637. };
  1638. priv.ajaxLoadTypeSpeciallCell = function(id, col) {
  1639. //console.log('ajaxLoadTypeSpeciallCell load id=' + id + ' col=' + col);
  1640. if (_popoverCellAjaxXhr) {
  1641. _popoverCellAjaxXhr.abort();
  1642. }
  1643. var _popoverCellAjaxXhr = $.ajax({
  1644. type: 'GET',
  1645. url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=TYPESPECIALL_CELL&ID=' + id + '&col=' + col,
  1646. dataType: 'json',
  1647. contentType: "application/json; charset=utf-8",
  1648. data: '',
  1649. success: function(req){
  1650. //console.log('ajaxLoadTypeSpeciallCell Data: ', req);
  1651. if (req.data && req.data.tbl_id > 0) {
  1652. var addHtml = '';
  1653. for(var i in req.data.items){
  1654. var url = 'index.php?MENU_INIT=VIEWTABLE_AJAX';
  1655. url += '&ZASOB_ID=' + req.data.tbl_id;
  1656. url += '&f_' + req.data.fld_name + '=' + req.data.items[i].id;
  1657. url += '&_hash=' + Math.random().toString(36).substring(2);
  1658. addHtml += '<a href="' + url + '">Wyszukaj ' + req.data.items[i].id + '</a>: ' + req.data.items[i].label;
  1659. addHtml += '<br>';
  1660. }
  1661. _popoverCell.append(addHtml);
  1662. jQuery('#popoverCellContent').append(addHtml);
  1663. }
  1664. }
  1665. });
  1666. };
  1667. priv.popoverCell = function (e) {
  1668. e.preventDefault();
  1669. e.stopPropagation();
  1670. if ('id' in e.data && 'col' in e.data && e.data.id > 0) {
  1671. var lastId = _popoverCell.data('rowid'),
  1672. lastCol = _popoverCell.data('col');
  1673. if (lastId == e.data.id && lastCol == e.data.col) {
  1674. //_popoverCellCurrent.popover('toggle');
  1675. }
  1676. else {
  1677. if (_popoverCellCurrent) {
  1678. _popoverCellCurrent.popover('destroy');
  1679. }
  1680. _popoverCell.data('rowid', e.data.id);
  1681. _popoverCell.data('col', e.data.col);
  1682. _popoverCell.html(e.data.value + '<div id="popoverCellContent"></div>');
  1683. if (_data.cols[e.data.col]) {
  1684. if (_data.cols[e.data.col]._tsRetId > 0) {
  1685. priv.ajaxLoadTypeSpeciallCell(e.data.id, e.data.col);
  1686. }
  1687. }
  1688. _popoverCellCurrent = jQuery(e.currentTarget);
  1689. // title : '<span class="text-info"><strong>title</strong></span> <button type="button" id="close" class="close">&times;</button>'
  1690. var opts = {
  1691. placement: 'left'
  1692. , trigger: 'click'
  1693. // , title: e.data.col + '<a href="#" class="icon-remove pull-right" onclick="return hidePopover();"></a>'
  1694. , title: '<div style="display:block;position:relative;padding:0 20px 0 0;">' + (e.data.friendly || e.data.col) + ' <button type="button" class="close" onclick="return hidePopover();" style="position:absolute;right:0;top:0;">&times;</button>' + '</div>'
  1695. , html: true
  1696. , content: _popoverCell.html()
  1697. }
  1698. _popoverCellCurrent.popover(opts);
  1699. _popoverCellCurrent.popover('show');
  1700. }
  1701. } else {
  1702. console.log('NO data');
  1703. return false;
  1704. }
  1705. return;
  1706. };
  1707. priv.routeChanged = function(e) {
  1708. hash = e.data.hash || '';
  1709. if (hash.length == 0) {
  1710. return;
  1711. }
  1712. if (hash.substring(0, 1) != '#') {
  1713. hash = '#' + hash;
  1714. }
  1715. location.hash = hash;
  1716. },
  1717. publ.init = function (options) {
  1718. if (priv.options.debug) console.log('TableAjax initialization...');
  1719. //merge supplied options with defaults
  1720. $.extend(priv.options, defaults, options);
  1721. priv.init();
  1722. return publ;
  1723. };
  1724. publ.loadPage = function(page, pageSize) {
  1725. var skipCols = true, // skipCols = true - prevent columns delete
  1726. resetChecked = false;
  1727. var reqData = {
  1728. page: page,
  1729. pageSize: (pageSize || priv.options.pageSize),
  1730. currSortCol: (_currSortCol || ''),
  1731. currSortFlip: _currSortFlip ? "desc" : "asc"
  1732. };
  1733. if (Object.keys(_filterCols).length > 0) {
  1734. $.each(_filterCols, function (col, colProps) {
  1735. if (colProps.filter && colProps.filter.length > 0) {
  1736. reqData['f_' + col] = colProps.filter;
  1737. }
  1738. });
  1739. skipCols = true;
  1740. }
  1741. // specialFilters
  1742. $.each(_specialFilters, function(groupName, btnValue) {
  1743. if (btnValue.length > 0) {
  1744. reqData['sf_' + groupName] = btnValue;
  1745. }
  1746. });
  1747. if (priv.options.forceFilterInit) {
  1748. $.map(priv.options.forceFilterInit, function (fltrProps, fltr) {
  1749. reqData['f_' + fltr] = fltrProps;
  1750. filtersInitSet = true;
  1751. });
  1752. }
  1753. _table.parent().parent().addClass('AjaxTable-loading');
  1754. $.ajax({
  1755. url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>',
  1756. type: 'GET',
  1757. dataType: 'json',
  1758. contentType: "application/json; charset=utf-8",
  1759. data: reqData,
  1760. async: true,
  1761. success: function (data) {
  1762. if (data.d && data.d.cols)
  1763. priv.setData(data.d, skipCols, resetChecked);
  1764. else
  1765. priv.setData(data, skipCols, resetChecked);
  1766. if (typeof callback == "function")
  1767. callback.call(this);
  1768. _table.parent().parent().removeClass('AjaxTable-loading');
  1769. },
  1770. error: function (err) {
  1771. //console.log('request error: {0}'.f(JSON.stringify(err)));
  1772. }
  1773. });
  1774. };
  1775. publ.getCurrentPage = function() {
  1776. return _currPage;
  1777. };
  1778. publ.popoverCellRemove = function () {
  1779. _popoverCellCurrent.popover('destroy');
  1780. _popoverCell.data('rowid', -1);
  1781. _popoverCell.data('col', -1);
  1782. _popoverCell.html('');
  1783. };
  1784. return publ;
  1785. }
  1786. $.fn.TableAjax = function (options) {
  1787. options = options || {};
  1788. return this.each(function () {
  1789. options.id = this;
  1790. $(this).data('TableAjax', new TableAjax().init(options));
  1791. });
  1792. };
  1793. $.fn.TableAjaxLoadPage = function (page, pageSize) {
  1794. //console.log('TableAjaxLoadPage: ' + page + ' size: ' + pageSize);
  1795. return this.each(function () {
  1796. var tblAjax = jQuery(this).data('TableAjax');
  1797. var curPage = page || tblAjax.getCurrentPage();
  1798. if (tblAjax) tblAjax.loadPage(curPage, pageSize);
  1799. });
  1800. };
  1801. String.prototype.format = String.prototype.f = function () {
  1802. var s = this;
  1803. i = arguments.length;
  1804. while (i--) s = s.replace(new RegExp('\\{' + i + '\\}', 'gm'), arguments[i]);
  1805. return s;
  1806. };
  1807. })(jQuery);
  1808. </script>
  1809. <?php
  1810. $filterInit = $this->_filterInit;
  1811. $forceFilterInit = $this->_forceFilterInit;
  1812. $pageSizes = $this->_pageSizes;
  1813. $rowFunctions = $this->_showRowFunctionsJson();
  1814. ?>
  1815. <script>
  1816. jQuery(document).ready(function(){
  1817. jQuery('#<?php echo $this->_htmlID; ?>').TableAjax({
  1818. url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>',
  1819. columnPicker: true,
  1820. filter: true,
  1821. filterInit: <?php echo json_encode($filterInit); ?>,
  1822. forceFilterInit: <?php echo json_encode($forceFilterInit); ?>,
  1823. debug: false, // TODO: DBG
  1824. height: 400, // TODO: ?
  1825. sorting: true, // TODO: ?
  1826. paging: true, // TODO: ?
  1827. pageSizes: <?php echo json_encode($pageSizes); ?>,
  1828. pageChanged: function(args) {
  1829. var con = jQuery('#<?php echo $this->_htmlID; ?>');
  1830. con.TableAjaxLoadPage(args.page);
  1831. },
  1832. pageSizeChanged: function(args) {
  1833. var con = jQuery('#<?php echo $this->_htmlID; ?>');
  1834. con.TableAjaxLoadPage(0, args.pageSize);
  1835. },
  1836. tblFunctions: {
  1837. shortdesc: {
  1838. icon: 'align-left',
  1839. title: 'Long desc',
  1840. method: 'longTextChanged'
  1841. },
  1842. <?php if ($hasGeomFlds) : ?>
  1843. mapeditor: {
  1844. icon: 'map-marker',
  1845. title: 'Mapa',
  1846. method: 'mapEditorChanged'
  1847. },
  1848. <?php endif; ?>
  1849. create: {
  1850. href: '#CREATE',
  1851. icon: 'plus',
  1852. title: 'Dodaj nowy rekord'
  1853. }
  1854. },
  1855. rowFunctions: <?php echo json_encode($rowFunctions); ?>,
  1856. specialFilterFunctions: <?php
  1857. $fltrs = $this->_dataSource->getSpecialFilters();
  1858. if (!empty($fltrs)) {
  1859. echo json_encode($fltrs);
  1860. } else {
  1861. echo 'false';
  1862. }
  1863. echo ',';
  1864. ?>
  1865. router: function () {
  1866. var routes = {
  1867. EDIT: function (args) {
  1868. var recordID = args;
  1869. if (typeof args == 'object') {
  1870. recordID = args.shift();
  1871. recordID = parseInt(recordID);
  1872. }
  1873. if (typeof recordID !== 'number' || recordID <= 0) {
  1874. // TODO: msg
  1875. return false;
  1876. }
  1877. var cont = jQuery('#<?php echo $this->_htmlID; ?>').parent();
  1878. cont.hide();
  1879. // remove previous task content
  1880. var taskCnt = jQuery('#<?php echo $this->_htmlID; ?>_task');
  1881. taskCnt.parent().remove();
  1882. taskCnt.remove();
  1883. var taskCont = jQuery('<div class="AjaxTableCont"></div>').insertBefore(cont);
  1884. jQuery('<ul class="breadcrumb">' +
  1885. '<li><a href="#" onclick="return tableAjaxBackToTable();"><?php echo $this->getLabelHtml(); ?></a> <span class="divider">/</span></li>' +
  1886. '<li class="active">Edytuj rekord</li>' +
  1887. '</ul>').appendTo(taskCont);
  1888. taskCnt = jQuery('<div id="<?php echo $this->_htmlID . '_task'; ?>" class="AjaxTableTaskCnt AjaxTable-loading"></div>').appendTo(taskCont);
  1889. jQuery('<span class="loading-info"> loading ...</span>').appendTo(taskCnt);
  1890. jQuery.ajax({
  1891. url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=EDIT&ID=' + recordID,
  1892. type: 'GET',
  1893. dataType: 'text',
  1894. data: '',
  1895. async: true,
  1896. success: function (data) {
  1897. taskCnt.removeClass('AjaxTable-loading');
  1898. //console.log('request finished L.<?php echo __LINE__; ?>');
  1899. jQuery(data).appendTo(taskCnt);
  1900. taskCnt.find('.se_type-date').datepicker({
  1901. format: "yyyy-mm-dd"
  1902. , language: 'pl'
  1903. , todayBtn: "linked"
  1904. });
  1905. taskCnt.find('.se_type-datetime').parent().datetimepicker({
  1906. language: 'pl'
  1907. , format: 'yyyy-MM-dd hh:mm'
  1908. , weekStart: 1
  1909. });
  1910. },
  1911. error: function (err) {
  1912. taskCnt.removeClass('AjaxTable-loading');
  1913. //console.log('request error: {0}'.f(err));
  1914. }
  1915. });
  1916. //return false;
  1917. },
  1918. HIST: function (args) {
  1919. var recordID = args;
  1920. if (typeof args == 'object') {
  1921. recordID = args.shift();
  1922. recordID = parseInt(recordID);
  1923. }
  1924. if (typeof recordID !== 'number' || recordID <= 0) {
  1925. // TODO: msg
  1926. return false;
  1927. }
  1928. var cont = jQuery('#<?php echo $this->_htmlID; ?>').parent();
  1929. cont.hide();
  1930. // remove previous task content
  1931. var taskCnt = jQuery('#<?php echo $this->_htmlID; ?>_task');
  1932. taskCnt.parent().remove();
  1933. taskCnt.remove();
  1934. var taskCont = jQuery('<div class="AjaxTableCont"></div>').insertBefore(cont);
  1935. jQuery('<ul class="breadcrumb">' +
  1936. '<li><a href="#" onclick="return tableAjaxBackToTable();"><?php echo $this->getLabelHtml(); ?></a> <span class="divider">/</span></li>' +
  1937. '<li class="active">Historia rekordu</li>' +
  1938. '</ul>').appendTo(taskCont);
  1939. var taskCnt = jQuery('<div id="<?php echo $this->_htmlID . '_task'; ?>" class="AjaxTableTaskCnt AjaxTable-loading"></div>').appendTo(taskCont);
  1940. jQuery('<span class="loading-info"> loading ...</span>').appendTo(taskCnt);
  1941. jQuery.ajax({
  1942. url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=HIST&ID=' + recordID,
  1943. type: 'GET',
  1944. dataType: 'text',
  1945. data: '',
  1946. async: true,
  1947. success: function (data) {
  1948. taskCnt.removeClass('AjaxTable-loading');
  1949. //console.log('request finished L.<?php echo __LINE__; ?>');
  1950. jQuery(data).appendTo(taskCnt);
  1951. },
  1952. error: function (err) {
  1953. taskCnt.removeClass('AjaxTable-loading');
  1954. //console.log('request error: {0}'.f(err));
  1955. }
  1956. });
  1957. //return false;
  1958. },
  1959. FILES: function tableAjaxFiles(args) {
  1960. var recordID = args;
  1961. if (typeof args == 'object') {
  1962. recordID = args.shift();
  1963. recordID = parseInt(recordID);
  1964. }
  1965. if (typeof recordID !== 'number' || recordID <= 0) {
  1966. // TODO: msg
  1967. return false;
  1968. }
  1969. var cont = jQuery('#<?php echo $this->_htmlID; ?>').parent();
  1970. cont.hide();
  1971. // remove previous task content
  1972. var taskCnt = jQuery('#<?php echo $this->_htmlID; ?>_task');
  1973. taskCnt.parent().remove();
  1974. taskCnt.remove();
  1975. var taskCont = jQuery('<div class="AjaxTableCont"></div>').insertBefore(cont);
  1976. jQuery('<ul class="breadcrumb">' +
  1977. '<li><a href="#" onclick="return tableAjaxBackToTable();"><?php echo $this->getLabelHtml(); ?></a> <span class="divider">/</span></li>' +
  1978. '<li class="active">Pliki</li>' +
  1979. '</ul>').appendTo(taskCont);
  1980. var taskCnt = jQuery('<div id="<?php echo $this->_htmlID . '_task'; ?>" class="AjaxTable-loading"></div>').appendTo(taskCont);
  1981. jQuery('<span class="loading-info"> loading ...</span>').appendTo(taskCnt);
  1982. jQuery.ajax({
  1983. url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=FILES&ID=' + recordID,
  1984. type: 'GET',
  1985. dataType: 'text',
  1986. data: '',
  1987. async: true,
  1988. success: function (data) {
  1989. taskCnt.removeClass('AjaxTable-loading');
  1990. //console.log('request finished L.<?php echo __LINE__; ?>', data);
  1991. jQuery(data).appendTo(taskCnt);
  1992. },
  1993. error: function (jqXHR, textStatus, errorThrown) {
  1994. //console.log('request error:', jqXHR.status, 'txt:', jqXHR.responseText, 'err:', jqXHR);
  1995. taskCnt.removeClass('AjaxTable-loading');
  1996. var txt = jqXHR.responseText || 'Error';
  1997. if (jqXHR.status == 404) {
  1998. jQuery('<div class="container"><div class="alert alert-error">' + txt + '</div></div>').appendTo(taskCnt);
  1999. } else {
  2000. jQuery('<div class="container"><div class="alert alert-error">' + txt + '</div></div>').appendTo(taskCnt);
  2001. }
  2002. }
  2003. });
  2004. //return false;
  2005. },
  2006. CREATE: function tableAjaxCreate() {
  2007. var cont = jQuery('#<?php echo $this->_htmlID; ?>').parent();
  2008. cont.hide();
  2009. // remove previous task content
  2010. var taskCnt = jQuery('#<?php echo $this->_htmlID; ?>_task');
  2011. taskCnt.parent().remove();
  2012. taskCnt.remove();
  2013. var taskCont = jQuery('<div class="AjaxTableCont"></div>').insertBefore(cont);
  2014. jQuery('<ul class="breadcrumb">' +
  2015. '<li><a href="#" onclick="return tableAjaxBackToTable();"><?php echo $this->getLabelHtml(); ?></a> <span class="divider">/</span></li>' +
  2016. '<li class="active">Dodaj nowy rekord</li>' +
  2017. '</ul>').appendTo(taskCont);
  2018. taskCnt = jQuery('<div id="<?php echo $this->_htmlID . '_task'; ?>" class="AjaxTableTaskCnt AjaxTable-loading"></div>').appendTo(taskCont);
  2019. jQuery('<span class="loading-info"> loading ...</span>').appendTo(taskCnt);
  2020. var reqData = {};
  2021. var forceFilterInit = <?php echo json_encode($forceFilterInit);// TODO: read from TableAjax ?>;
  2022. if (forceFilterInit) {
  2023. $.map(forceFilterInit, function (fltrProps, fltr) {
  2024. reqData['ff_' + fltr] = fltrProps;
  2025. });
  2026. }
  2027. jQuery.ajax({
  2028. url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=CREATE',
  2029. type: 'GET',
  2030. dataType: 'text',
  2031. data: reqData,
  2032. async: true,
  2033. success: function (data) {
  2034. taskCnt.removeClass('AjaxTable-loading');
  2035. //console.log('request finished L.<?php echo __LINE__; ?>');
  2036. jQuery(data).appendTo(taskCnt);
  2037. taskCnt.find('.se_type-date').datepicker({
  2038. format: "yyyy-mm-dd"
  2039. , language: 'pl'
  2040. , todayBtn: "linked"
  2041. });
  2042. taskCnt.find('.se_type-datetime').parent().datetimepicker({
  2043. language: 'pl'
  2044. , format: 'yyyy-MM-dd hh:mm'
  2045. , weekStart: 1
  2046. });
  2047. },
  2048. error: function (err) {
  2049. taskCnt.removeClass('AjaxTable-loading');
  2050. //console.log('request error: {0}'.f(err));
  2051. }
  2052. });
  2053. //return false;
  2054. }
  2055. };
  2056. var routePath = location.hash;
  2057. //console.log('location.hash: ' + routePath);
  2058. if (location.hash == '' || location.hash == '#') {
  2059. return false;
  2060. }
  2061. if (routePath.charAt(0) == '#') {
  2062. routePath = routePath.substr(1);
  2063. }
  2064. //console.log('routePath: ' + routePath);
  2065. var parts = routePath.split('/');
  2066. var task = parts.shift();
  2067. //console.log('task(' + task + ') parts:');
  2068. //console.log(parts);
  2069. if (task in routes && typeof routes[task] == 'function') {
  2070. routes[task](parts);
  2071. } else {
  2072. return false;
  2073. }
  2074. },
  2075. filtersClean: true,
  2076. longDesc: true
  2077. });
  2078. });
  2079. function tableAjaxBackToTable() {
  2080. var cont = jQuery('#<?php echo $this->_htmlID; ?>').parent();
  2081. cont.show();
  2082. var taskCont = jQuery('#<?php echo $this->_htmlID . '_task'; ?>').parent();
  2083. taskCont.remove();
  2084. // reload first page
  2085. var con = jQuery('#<?php echo $this->_htmlID; ?>');
  2086. con.TableAjaxLoadPage(0);// TODO: load current page
  2087. }
  2088. function tableAjaxCopy(args) {
  2089. var recordID = args;
  2090. if (typeof args == 'object') {
  2091. recordID = args.shift();
  2092. recordID = parseInt(recordID);
  2093. }
  2094. if (typeof recordID !== 'number' || recordID <= 0) {
  2095. // TODO: msg
  2096. return false;
  2097. }
  2098. if (!confirm('Czy na pewno chcesz utworzyc nowy rekord na podstawie danych z rekordu ID = ' + recordID + '?')) {
  2099. return false;
  2100. }
  2101. var cont = jQuery('#<?php echo $this->_htmlID; ?>').parent();
  2102. //cont.hide();
  2103. //var taskCont = jQuery('#<?php echo $this->_htmlID . '_task'; ?>').parent();
  2104. //taskCont.remove();
  2105. cont.children('.alert').fadeOut('slow');
  2106. var alert = jQuery('<div class="alert fade in"><strong>Kopiuj rekord</strong> ... </div>').prependTo(cont);
  2107. jQuery.ajax({
  2108. url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=COPY&ID=' + recordID,
  2109. type: 'GET',
  2110. dataType: 'text',
  2111. data: '',
  2112. async: true,
  2113. success: function (data) {
  2114. //console.log('data: ', data);
  2115. alert.remove();
  2116. alert = jQuery(data).prependTo(cont);
  2117. alert.alert();
  2118. var con = jQuery('#<?php echo $this->_htmlID; ?>');
  2119. con.TableAjaxLoadPage(0);
  2120. },
  2121. error: function (err) {
  2122. alert.remove();
  2123. console.log(err);
  2124. }
  2125. });
  2126. return false;
  2127. }
  2128. function hidePopover() {
  2129. var con = jQuery('#<?php echo $this->_htmlID; ?>');
  2130. if (con) {
  2131. var tblAjax = con.data('TableAjax');
  2132. if (tblAjax) {
  2133. tblAjax.popoverCellRemove();
  2134. }
  2135. }
  2136. return false;
  2137. }
  2138. </script>
  2139. <?php
  2140. $out = ob_get_contents();
  2141. ob_end_clean();
  2142. return $out;
  2143. }
  2144. public function ajaxTask($task) {
  2145. switch ($task) {
  2146. case 'EDIT': {
  2147. $id = V::get('ID', 0, $_REQUEST, 'int');
  2148. if ($id > 0) {
  2149. $this->sendAjaxEdit($id, $_REQUEST);
  2150. } else {
  2151. echo '404';
  2152. }
  2153. break;
  2154. }
  2155. case 'EDIT_SAVE': {
  2156. $id = V::get('ID', 0, $_REQUEST, 'int');
  2157. if ($id > 0) {
  2158. $this->sendAjaxEditSave($id, $_REQUEST);
  2159. } else {
  2160. echo '404';
  2161. }
  2162. break;
  2163. }
  2164. case 'EDIT_INLINE': {
  2165. $id = V::get('ID', 0, $_REQUEST, 'int');
  2166. $col = V::get('col', '', $_REQUEST);
  2167. if ($id > 0 && !empty($col)) {
  2168. $this->sendAjaxEditInline($id, $col, $_REQUEST);
  2169. } else {
  2170. echo '404';
  2171. }
  2172. break;
  2173. }
  2174. case 'EDIT_INLINE_SAVE': {
  2175. $id = V::get('ID', 0, $_REQUEST, 'int');
  2176. $col = V::get('col', '', $_REQUEST);
  2177. if ($id > 0 && !empty($col)) {
  2178. $this->sendAjaxEditInlineSave($id, $col, $_REQUEST);
  2179. } else {
  2180. echo '404';
  2181. }
  2182. break;
  2183. }
  2184. case 'COPY': {
  2185. $id = V::get('ID', 0, $_REQUEST, 'int');
  2186. if ($id > 0) {
  2187. $this->sendAjaxCopy($id, $_REQUEST);
  2188. } else {
  2189. echo '404';
  2190. }
  2191. break;
  2192. }
  2193. case 'CREATE': {
  2194. $this->sendAjaxCreate($_REQUEST);
  2195. break;
  2196. }
  2197. case 'CREATE_SAVE': {
  2198. $this->sendAjaxCreateSave($_REQUEST);
  2199. break;
  2200. }
  2201. case 'HIST': {
  2202. $id = V::get('ID', 0, $_REQUEST, 'int');
  2203. if ($id > 0) {
  2204. $this->sendAjaxHistory($id, $_REQUEST);
  2205. } else {
  2206. echo '404';
  2207. }
  2208. break;
  2209. }
  2210. case 'FILES': {
  2211. $id = V::get('ID', 0, $_REQUEST, 'int');
  2212. if ($id > 0) {
  2213. $this->sendAjaxFiles($id, $_REQUEST);
  2214. } else {
  2215. echo '404';
  2216. }
  2217. break;
  2218. }
  2219. case 'FILES_UPLOAD': {
  2220. $id = V::get('ID', 0, $_REQUEST, 'int');
  2221. if ($id > 0) {
  2222. $this->sendAjaxFilesUpload($id, $_REQUEST);
  2223. } else {
  2224. echo '404';
  2225. }
  2226. break;
  2227. }
  2228. case 'FILES_LIST': {
  2229. $id = V::get('ID', 0, $_REQUEST, 'int');
  2230. if ($id > 0) {
  2231. $this->sendAjaxFilesList($id, $_REQUEST);
  2232. } else {
  2233. echo '404';
  2234. }
  2235. break;
  2236. }
  2237. case 'FILE_REMOVE': {
  2238. $id = V::get('ID', 0, $_REQUEST, 'int');
  2239. if ($id > 0) {
  2240. $this->sendAjaxFileRemove($id, $_REQUEST);
  2241. } else {
  2242. echo '404';
  2243. }
  2244. break;
  2245. }
  2246. case 'FILES_CONN_TBL_LIST': {
  2247. $id = V::get('ID', 0, $_REQUEST, 'int');
  2248. if ($id > 0) {
  2249. $this->sendAjaxFilesConnTblList($id, $_REQUEST);
  2250. } else {
  2251. echo '404';
  2252. }
  2253. break;
  2254. }
  2255. case 'TYPESPECIAL': {
  2256. $fldID = V::get('fldID', 0, $_REQUEST, 'int');
  2257. if ($fldID > 0) {
  2258. $this->sendTypeSpecial($fldID, $_REQUEST);
  2259. } else {
  2260. echo '404';
  2261. }
  2262. break;
  2263. }
  2264. case 'TYPESPECIALL_CELL': {
  2265. $id = V::get('ID', 0, $_REQUEST, 'int');
  2266. $col = V::get('col', '', $_REQUEST);
  2267. if ($id > 0 && !empty($col)) {
  2268. $this->sendTypeSpecialCell($id, $col, $_REQUEST);
  2269. } else {
  2270. echo '404';
  2271. }
  2272. break;
  2273. }
  2274. case 'HIDDEN_COLS_SAVE': {
  2275. $this->sendHiddenColsSave($_REQUEST);
  2276. break;
  2277. }
  2278. case 'THE_GEOM_SAVE': {
  2279. $this->sendTheGeomSave($_REQUEST);
  2280. break;
  2281. }
  2282. default:
  2283. $this->sendAjaxData($_REQUEST);
  2284. }
  2285. }
  2286. /**
  2287. * ajax url: &_task=EDIT_INLINE
  2288. * @param $rowID - $_GET['ID']
  2289. * @param $fieldName - $_GET['col']
  2290. */
  2291. private function sendAjaxEditInline($rowID, $fieldName, $args) {
  2292. $DBG = ('1' == V::get('DBG', '', $_REQUEST));
  2293. header("Content-type: text/plain");
  2294. $fieldID = $this->_acl->getFieldIdByName($fieldName);
  2295. if (!$fieldID) {
  2296. echo "404: No field by name ({$fieldName})";
  2297. exit;
  2298. }
  2299. if ($DBG) echo "fieldID: {$fieldID}\n";
  2300. $row = $this->_dataSource->getItem($rowID);
  2301. if (!$row) {
  2302. echo "404: No item ID({$rowID})";
  2303. exit;
  2304. }
  2305. if (!$this->_acl->isAllowed($fieldID, 'R', $row)) {
  2306. if ($DBG) echo " R not allowed\n";
  2307. } else {
  2308. if ($DBG) echo " R allowed\n";
  2309. }
  2310. if (!$this->_acl->isAllowed($fieldID, 'W', $row)) {
  2311. if ($DBG) echo " W not allowed\n";
  2312. } else {
  2313. if ($DBG) echo " W allowed\n";
  2314. }
  2315. $fieldVal = '';
  2316. if ($this->_acl->isAllowed($fieldID, 'R', $row)) {
  2317. $fieldVal = V::get($fieldName, $fieldVal, $row);
  2318. } else {
  2319. $fieldVal = '*****';
  2320. }
  2321. $fieldVal = V::get("f{$fieldID}", $fieldVal, $_POST);
  2322. $vCol = $this->_acl->getField($fieldID);
  2323. $vCol['label'] = (!empty($vCol['label']))? $vCol['label'] : $vCol['name'];
  2324. $tsValues = array();
  2325. Lib::loadClass('Typespecial');
  2326. $typeSpecial = Typespecial::getInstance($fieldID, $vCol['name']);
  2327. if ($typeSpecial) {
  2328. 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>';}
  2329. $specialValues = $typeSpecial->getEditSelectedValuesByIds($this->_zasobID, $row->ID, $fieldName, V::get($fieldName, $fieldVal, $row));
  2330. 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>';}
  2331. if (!empty($specialValues)) {
  2332. $tsValues[$row->ID] = implode('<br>', $specialValues);
  2333. }
  2334. }
  2335. Lib::loadClass('SE_Layout');
  2336. ?>
  2337. <label for="<?php echo "f{$fieldID}"; ?>" class="AjaxTableEdit-label">
  2338. <strong title="<?php echo "[{$fieldID}] {$fieldName}"; ?>"><?php echo "{$vCol['label']}"; ?></strong>
  2339. <?php if (!empty($vCol['opis'])) : ?>
  2340. <em><?php echo $vCol['opis']; ?></em>
  2341. <?php $perms = $this->_acl->getFieldPerms($fieldID); SE_Layout::hotKeyDBG($perms); ?>
  2342. <?php endif; ?>
  2343. </label>
  2344. <?php
  2345. $fieldParams = array('widthClass'=>'inside-modal', 'maxGrid'=>6);
  2346. if (!empty($tsValues[$row->ID])) {
  2347. $fieldParams['typespecialValue'] = $tsValues[$row->ID];
  2348. }
  2349. $vDefault = $this->_dataSource->getColDefault($fieldName);
  2350. if (!empty($vDefault)) {
  2351. $fieldParams['default'] = $vDefault;
  2352. }
  2353. echo $this->_acl->showFormItem('W', $fieldID, "f{$fieldID}", $fieldVal, $fieldParams, $row);
  2354. if ($typeSpecial) {
  2355. echo '<p style="padding:100px 0;"></p>';
  2356. }
  2357. exit;
  2358. }
  2359. private function sendAjaxEditInlineSave($rowID, $fieldName, $args) {
  2360. $DBG = ('1' == V::get('DBG', '', $_REQUEST));
  2361. sleep(1);// TODO: RMME DBG loading
  2362. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">TODO: save ID(' . $id . ') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($args);echo'</pre>';}
  2363. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">acl (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($this->_acl);echo'</pre>';}
  2364. $dbID = $this->_acl->getDB();
  2365. $db = DB::getDB($dbID);
  2366. if (!$db) {
  2367. header('HTTP/1.0 406 Not Acceptable');
  2368. exit;
  2369. }
  2370. $tblName = $this->_acl->getName();
  2371. $fieldID = $this->_acl->getFieldIdByName($fieldName);
  2372. if (!$fieldID) {
  2373. header('HTTP/1.0 404 Not Found');
  2374. echo "404: No field by name ({$fieldName})";
  2375. exit;
  2376. }
  2377. $row = $this->_dataSource->getItem($rowID);
  2378. if (!$row) {
  2379. header('HTTP/1.0 404 Not Found');
  2380. echo "404: No item ID({$rowID})";
  2381. exit;
  2382. }
  2383. if (!$this->_acl->isAllowed($fieldID, 'W', $row)) {
  2384. header('HTTP/1.0 403 Forbidden');
  2385. echo "403: field not allowed to Write ({$fieldName})";
  2386. exit;
  2387. } else {
  2388. if ($DBG) echo " Write allowed\n";
  2389. }
  2390. $sqlObj = new stdClass();
  2391. if (array_key_exists("f{$fieldID}", $args)) {
  2392. if (!$this->_acl->isAllowed($fieldID, 'R', $record) && '*****' == $args["f{$fieldID}"]) {
  2393. // default value for perms 'W' without 'R' is '*****'
  2394. }
  2395. else {
  2396. $sqlObj->{$fieldName} = $args["f{$fieldID}"];
  2397. if (empty($args["f{$fieldID}"]) && strlen($args["f{$fieldID}"]) == 0) {// fix bug in input type date and value="0000-00-00"
  2398. $sqlObj->{$fieldName} = $this->_acl->fixEmptyValueFromUser($fieldID);
  2399. }
  2400. }
  2401. }
  2402. else {
  2403. if ($DBG) echo " TODO: field value not set\n";
  2404. }
  2405. $sqlObj->ID = $rowID;
  2406. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">E('.$tblName.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sqlObj);echo'</pre>';}
  2407. $ret = $db->UPDATE_OBJ($tblName, $sqlObj);
  2408. if ($ret > 0) {
  2409. echo '<div class="alert alert-success">';
  2410. echo "Rekord zapisany pomyślnie";//"Record saved successfully";
  2411. echo '</div>';
  2412. } else if ($ret == 0) {
  2413. echo '<div class="alert alert-info">';
  2414. echo "Nie wprowadzono żadnych zmian";
  2415. if ($db->has_errors()) {
  2416. //echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">db errors: (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($db->get_errors());echo'</pre>';
  2417. }
  2418. echo '</div>';
  2419. } else {
  2420. echo '<div class="alert alert-error">';
  2421. echo '<h4>' . "Wystąpiły błędy!" . '</h4>';
  2422. if ($db->has_errors()) {
  2423. $errors = $db->get_errors();
  2424. echo implode('<br>', $errors);
  2425. }
  2426. echo '</div>';
  2427. }
  2428. exit;
  2429. }
  2430. private function sendAjaxEdit($id, $args) {
  2431. header("Content-type: text/plain");
  2432. $DBG = ('1' == V::get('DBG', '', $_REQUEST));
  2433. $cols = array();
  2434. $record = $this->_dataSource->getItem($id);
  2435. if (!$this->_acl->canWriteRecord($record) && !$this->_acl->hasPermSuperWrite()) {
  2436. echo '<div class="alert alert-error">';
  2437. echo "Brak dostępu do rekordu";// TODO: more info - reason
  2438. echo '</div>';
  2439. return;
  2440. }
  2441. $fieldsList = $this->_acl->getFields();
  2442. foreach ($fieldsList as $kID => $vCol) {
  2443. if ($vCol['name'] == 'ID') {
  2444. unset($fieldsList[$kID]);
  2445. continue;
  2446. }
  2447. $cols[$kID] = '';
  2448. if ($this->_acl->isAllowed($kID, 'R', $record)) {
  2449. $cols[$kID] = V::get($vCol['name'], '', $record);
  2450. } else {
  2451. $cols[$kID] = '*****';
  2452. }
  2453. $cols[$kID] = V::get("f{$kID}", $cols[$kID], $_POST);
  2454. $fieldsList[$kID]['label'] = (!empty($vCol['label']))? $vCol['label'] : str_replace('_', ' ', $vCol['name']);
  2455. }
  2456. $tsValues = array();
  2457. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">fieldsList (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($fieldsList);echo'</pre>';}
  2458. if (!empty($fieldsList)) {
  2459. Lib::loadClass('Typespecial');
  2460. foreach ($fieldsList as $vColID => $vCol) {
  2461. $typeSpecial = Typespecial::getInstance($vColID, $vCol['name']);
  2462. if ($typeSpecial) {
  2463. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">Typespecial('.$vColID.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($typeSpecial);echo'</pre>';}
  2464. $colValue = V::get($vCol['name'], '', $record);
  2465. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">V::get('.$vCol['name'].', "", $record) (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($colValue);echo'</pre>';}
  2466. $specialValues = $typeSpecial->getEditSelectedValuesByIds($this->_zasobID, $record->ID, $vCol['name'], $colValue);
  2467. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">Typespecial('.$vColID.') specialValues (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($specialValues);echo'</pre>';}
  2468. if (!empty($specialValues)) {
  2469. $tsValues[$vColID] = implode('<br>', $specialValues);
  2470. }
  2471. }
  2472. }
  2473. }
  2474. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">tsValues (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($tsValues);echo'</pre>';}
  2475. $rowFunctionsOut = $this->_showRowFunctions($record->ID, array('edit', 'cp'), true);
  2476. Lib::loadClass('SE_Layout');
  2477. ?>
  2478. <div class="container AjaxFrmHorizontalEdit">
  2479. <form class="form-horizontal" action="" method="post" id="EDIT_FRM_<?php echo $this->_htmlID; ?>">
  2480. <fieldset>
  2481. <legend>Edycja rekordu Nr <?php echo $record->ID; ?><span class="pull-right valign-btns-bottom"><?php echo $rowFunctionsOut; ?></span></legend>
  2482. <?php $tabindex = 0; foreach ($fieldsList as $kID => $vCol) : ?>
  2483. <?php if ($this->_acl->isAllowed($kID, 'W', $record)) : ?>
  2484. <div class="control-group">
  2485. <label class="control-label" for="<?php echo "f{$kID}"; ?>"><?php echo $vCol['label']; ?>
  2486. <i class="icon-info-sign frm-help" data-toggle="popover" data-trigger="hover" title="" data-content="<?php echo htmlspecialchars($vCol['opis']); ?>" data-original-title="<?php echo "[{$kID}] {$vCol['name']}"; ?>"></i>
  2487. <?php $perms = $this->_acl->getFieldPerms($kID); SE_Layout::hotKeyDBG($perms); ?>
  2488. </label>
  2489. <div class="controls">
  2490. <?php
  2491. $fieldParams = array('appendBack'=>true, 'tabindex'=>(++$tabindex), 'maxGrid'=>8);
  2492. if (!empty($tsValues[$kID])) {
  2493. $fieldParams['typespecialValue'] = $tsValues[$kID];
  2494. }
  2495. echo $this->_acl->showFormItem('W', $kID, "f{$kID}", $cols[$kID], $fieldParams, $record);
  2496. ?>
  2497. </div>
  2498. </div>
  2499. <?php elseif ($this->_acl->isAllowed($kID, 'R', $record)) : ?>
  2500. <div class="control-group">
  2501. <label class="control-label" for="<?php echo "f{$kID}"; ?>"><?php echo $vCol['label']; ?>
  2502. <i class="icon-info-sign frm-help" data-toggle="popover" data-trigger="hover" title="" data-content="<?php echo htmlspecialchars($vCol['opis']); ?>" data-original-title="<?php echo "[{$kID}] {$vCol['name']}"; ?>"></i>
  2503. <?php $perms = $this->_acl->getFieldPerms($kID); SE_Layout::hotKeyDBG($perms); ?>
  2504. </label>
  2505. <div class="controls">
  2506. <p style="margin-top:5px;">
  2507. <?php
  2508. //echo $this->_acl->showFormItem('R', $kID, "f{$kID}", $cols[$kID], array('appendBack'=>true), $record);
  2509. if (!empty($tsValues[$kID])) {
  2510. echo $tsValues[$kID];
  2511. } else if (!empty($record->{$vCol['name']})) {
  2512. echo $record->{$vCol['name']};
  2513. }
  2514. ?>
  2515. </p>
  2516. </div>
  2517. </div>
  2518. <?php endif; ?>
  2519. <?php endforeach; ?>
  2520. <div class="control-group">
  2521. <div class="controls">
  2522. <button type="submit" class="btn btn-primary" tabindex="<?php echo (++$tabindex); ?>">Zapisz</button>
  2523. </div>
  2524. </div>
  2525. </fieldset>
  2526. </form>
  2527. <p style="padding:100px 0;"></p>
  2528. </div>
  2529. <script>
  2530. jQuery(document).ready(function(){
  2531. jQuery('textarea').autosize();
  2532. jQuery('.frm-help').popover({trigger:'hover'});
  2533. jQuery('#EDIT_FRM_<?php echo $this->_htmlID; ?>').on('submit', function(){
  2534. var data = jQuery(this).serialize();
  2535. // TODO: change Edit btn to return to edit record with fields -> show form
  2536. var taskCont = jQuery('#<?php echo $this->_htmlID; ?>_task').parent();
  2537. //taskCont.empty();
  2538. taskCont.children().fadeOut('slow');
  2539. var alertCntWrap = jQuery('<div class="AjaxTableAlert AjaxTable-loading"></div>').prependTo(taskCont)
  2540. , alertCnt = jQuery('<div class="container"></div>').prependTo(alertCntWrap);
  2541. jQuery('<div class="alert alert-error"><div style="padding:0 0 0 20px; background:url(./icon/loading.gif) no-repeat left top;"> zapisywanie ... </div></div>').appendTo(alertCnt);
  2542. jQuery.ajax({
  2543. url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=EDIT_SAVE&ID=<?php echo $record->ID; ?>',
  2544. type: 'POST',
  2545. dataType: 'text',
  2546. data: data,
  2547. async: true,
  2548. success: function (data) {
  2549. alertCntWrap.removeClass('AjaxTable-loading');
  2550. //console.log('request finished L.<?php echo __LINE__; ?>');
  2551. alertCnt.empty();
  2552. var out = '';
  2553. out += data;
  2554. out += '<div class="breadcrumb">' +
  2555. ' <a href="#" onclick="return tableAjaxBackToTable();" class="btn btn-link btn-small"> <i class="icon-arrow-left"></i> Wróć do tabeli <?php echo $this->getLabelHtml(); ?></a>' +
  2556. '<span class="divider">/</span>' +
  2557. ' <a href="#EDIT/<?php echo $id; ?>/' + Math.random(1).toString().substr(2) + '" class="btn btn-link btn-small"> <i class="icon-pencil"></i> Edytuj rekord <?php echo $id; ?></a>' +
  2558. '</div>';
  2559. jQuery(out).appendTo(alertCnt);
  2560. },
  2561. error: function (jhr, textStatus, errorThrown) {
  2562. var errorTxt = jhr.responseText || 'Error';
  2563. alertCntWrap.removeClass('AjaxTable-loading');
  2564. //console.log('Request Error: {0}: {1}'.f(textStatus, errorThrown));
  2565. alertCnt.empty();
  2566. jQuery(errorTxt).appendTo(alertCnt);
  2567. var errLinks = jQuery('<div class="breadcrumb"></div>').appendTo(alertCnt);
  2568. jQuery('<a href="#" onclick="return tableAjaxBackToTable();"> <i class="icon-arrow-left"></i> Wróć do tabeli <?php echo $this->getLabelHtml(); ?></a>').appendTo(errLinks);
  2569. 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);
  2570. backToEditBtn.on('click', function(){
  2571. alertCnt.remove();
  2572. taskCont.children().fadeIn('slow');
  2573. return false;
  2574. });
  2575. }
  2576. });
  2577. return false;
  2578. });
  2579. jQuery('#EDIT_FRM_<?php echo $this->_htmlID; ?>').find('.show-last-value input').on('input', function(e) {
  2580. var input, btn;
  2581. input = jQuery(e.target);
  2582. btn = input.next();
  2583. if (btn.is('button')) {
  2584. if (btn.attr('title') != input.val()) {
  2585. btn.show();
  2586. } else {
  2587. btn.hide();
  2588. }
  2589. }
  2590. });
  2591. jQuery('#EDIT_FRM_<?php echo $this->_htmlID; ?>').find('.show-last-value button.btn-appendBack').on('click', function(e) {
  2592. var input, btn;
  2593. btn = jQuery(e.target);
  2594. input = btn.prev();
  2595. if (input.is('input')) {
  2596. if (btn.attr('title') != input.val()) {
  2597. input.val(btn.attr('title'));
  2598. btn.hide();
  2599. }
  2600. }
  2601. });
  2602. });
  2603. </script>
  2604. <?php
  2605. exit;
  2606. }
  2607. private function sendAjaxEditSave($id, $args) {
  2608. $DBG = ('1' == V::get('DBG', '', $_REQUEST));
  2609. sleep(1);// TODO: RMME DBG loading
  2610. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">TODO: save ID(' . $id . ') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($args);echo'</pre>';}
  2611. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">acl (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($this->_acl);echo'</pre>';}
  2612. $dbID = $this->_acl->getDB();
  2613. $db = DB::getDB($dbID);
  2614. if (!$db) {
  2615. header('HTTP/1.0 406 Not Acceptable');
  2616. exit;
  2617. }
  2618. $tblName = $this->_acl->getName();
  2619. $record = $db->get_by_id($tblName, $id);
  2620. if (!$this->_acl->canWriteRecord($record) && !$this->_acl->hasPermSuperWrite()) {
  2621. echo '<div class="alert alert-error">';
  2622. echo "Brak dostępu do rekordu";// TODO: more info - reason
  2623. echo '</div>';
  2624. }
  2625. $sqlObj = new stdClass();
  2626. $fields = $this->_acl->getFields();
  2627. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">fields (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($fields);echo'</pre>';}
  2628. foreach ($fields as $kID => $vField) {
  2629. if (!$this->_acl->isAllowed($kID, 'W', $record)) {
  2630. continue;
  2631. }
  2632. if (array_key_exists("f{$kID}", $args)) {
  2633. if (!$this->_acl->isAllowed($kID, 'R', $record) && '*****' == $args["f{$kID}"]) {
  2634. // default value for perms 'W' without 'R' is '*****'
  2635. }
  2636. else {
  2637. $sqlObj->{$vField['name']} = $args["f{$kID}"];
  2638. if (empty($args["f{$kID}"]) && strlen($args["f{$kID}"]) == 0) {// fix bug in input type date and value="0000-00-00"
  2639. $sqlObj->{$vField['name']} = $this->_acl->fixEmptyValueFromUser($kID);
  2640. }
  2641. }
  2642. }
  2643. }
  2644. $sqlObj->ID = $id;
  2645. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;"> (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sqlObj);echo'</pre>';}
  2646. $ret = $db->UPDATE_OBJ($tblName, $sqlObj);
  2647. if ($ret > 0) {
  2648. echo '<div class="alert alert-success">';
  2649. echo "Rekord zapisany pomyślnie";//"Record saved successfully";
  2650. echo '</div>';
  2651. } else if ($ret == 0) {
  2652. echo '<div class="alert alert-info">';
  2653. echo "Nie wprowadzono żadnych zmian";
  2654. echo '</div>';
  2655. } else {
  2656. header('HTTP/1.0 404 Not Found');
  2657. echo '<div class="alert alert-error">';
  2658. echo '<h4>' . "Wystąpiły błędy!" . '</h4>';
  2659. if ($db->has_errors()) {
  2660. $errors = $db->get_errors();
  2661. echo implode('<br>', $errors);
  2662. }
  2663. echo '</div>';
  2664. }
  2665. exit;
  2666. }
  2667. private function sendAjaxCreate($args) {
  2668. header("Content-type: text/plain");
  2669. $DBG = ('1' == V::get('DBG', '', $_REQUEST));
  2670. $cols = array();
  2671. $forceFilterInit = array();
  2672. foreach ($_GET as $k => $v) {
  2673. if (strlen($k) > 4 && substr($k, 0, 3) == 'ff_' && !empty($v)) {// force filter prefix
  2674. $fldName = substr($k, 3);
  2675. $forceFilterInit[$fldName] = $v;
  2676. }
  2677. }
  2678. $fieldsList = $this->_acl->getFields();
  2679. foreach ($fieldsList as $kID => $vCol) {
  2680. $defaultValue = '';
  2681. if ($vCol['name'] == 'ID') {
  2682. unset($fieldsList[$kID]);
  2683. continue;
  2684. }
  2685. if (!empty($forceFilterInit[$vCol['name']])) {
  2686. $defaultValue = $forceFilterInit[$vCol['name']];
  2687. }
  2688. // TODO: read from session cache
  2689. $cols[$kID] = V::get("f{$kID}", $defaultValue, $_POST);
  2690. $fieldsList[$kID]['label'] = (!empty($vCol['label']))? $vCol['label'] : $vCol['name'];
  2691. }
  2692. Lib::loadClass('SE_Layout');
  2693. ?>
  2694. <div class="container AjaxFrmHorizontalEdit">
  2695. <form class="form-horizontal" action="" method="post" id="CREATE_FRM_<?php echo $this->_htmlID; ?>">
  2696. <fieldset>
  2697. <legend>Dodaj nowy rekord</legend>
  2698. <?php $tabindex = 0; foreach ($fieldsList as $kID => $vCol) : ?>
  2699. <?php if ($this->_acl->isAllowed($kID, 'C')) : ?>
  2700. <div class="control-group">
  2701. <label class="control-label" for="<?php echo "f{$kID}"; ?>"><?php echo $vCol['label']; ?>
  2702. <i class="icon-info-sign frm-help" data-toggle="popover" data-trigger="hover" title="" data-content="<?php echo htmlspecialchars($vCol['opis']); ?>" data-original-title="<?php echo "[{$kID}] {$vCol['name']}"; ?>"></i>
  2703. <?php $perms = $this->_acl->getFieldPerms($kID); SE_Layout::hotKeyDBG($perms); ?>
  2704. </label>
  2705. <div class="controls">
  2706. <?php
  2707. $fieldParams = array('appendBack'=>true, 'tabindex'=>(++$tabindex), 'maxGrid'=>8);
  2708. echo $this->_acl->showFormItem('C', $kID, "f{$kID}", $cols[$kID], $fieldParams);
  2709. ?>
  2710. </div>
  2711. </div>
  2712. <?php endif; ?>
  2713. <?php endforeach; ?>
  2714. <div class="control-group">
  2715. <div class="controls">
  2716. <button type="submit" class="btn btn-primary" tabindex="<?php echo (++$tabindex); ?>">Dodaj rekord</button>
  2717. </div>
  2718. </div>
  2719. </fieldset>
  2720. </form>
  2721. </div>
  2722. <script>
  2723. jQuery(document).ready(function(){
  2724. jQuery('textarea').autosize();
  2725. jQuery('.frm-help').popover({trigger:'hover'});
  2726. jQuery('#CREATE_FRM_<?php echo $this->_htmlID; ?>').on('submit', function(){
  2727. var data = jQuery(this).serialize();
  2728. var taskContLast = jQuery('#<?php echo $this->_htmlID; ?>_task'),
  2729. taskCont = taskContLast.parent();
  2730. taskContLast.fadeOut('slow');
  2731. var taskCnt = jQuery('<div id="<?php echo $this->_htmlID . '_task'; ?>" class="AjaxTableTaskCnt AjaxTable-loading"></div>').appendTo(taskCont);
  2732. jQuery('<div class="alert alert-error"><div style="padding:0 0 0 20px; background:url(./icon/loading.gif) no-repeat left top;"> save ... </div></div>').appendTo(taskCnt);
  2733. jQuery.ajax({
  2734. url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=CREATE_SAVE',
  2735. type: 'POST',
  2736. dataType: 'json',
  2737. data: data,
  2738. async: true,
  2739. success: function(data) {
  2740. //console.log('success L.<?php echo __LINE__; ?> data', data);
  2741. },
  2742. error: function(xhr) {
  2743. //console.log('error L.<?php echo __LINE__; ?> xhr', xhr);
  2744. },
  2745. complete: function(xhr) {
  2746. if (xhr.responseJSON) {
  2747. var data = xhr.responseJSON;
  2748. } else {
  2749. // TODO: error
  2750. }
  2751. taskCnt.removeClass('AjaxTable-loading');
  2752. taskCnt.empty();
  2753. if (typeof data == 'object') {
  2754. if (data.type == 'ERROR') {
  2755. var out = '<div class="container">' +
  2756. '<div class="alert alert-error">' +
  2757. '<h4>Wystąpiły błędy!</h4>' + data.msg +
  2758. '</div>';
  2759. out += '<div class="breadcrumb">' +
  2760. ' <a class="create-fix" href="#CREATE/' + Math.random(1).toString().substr(2) + '" class="btn btn-link btn-small"> <i class="icon-arrow-left"></i> Wróć do formularza i popraw dane</a></li>' +
  2761. '</div>' +
  2762. '</div>';
  2763. jQuery(out).appendTo(taskCnt);
  2764. var taskContLastNode = taskContLast
  2765. , taskCntNode = taskCnt;
  2766. taskCnt.find('.create-fix').click(function(){
  2767. taskCntNode.remove();
  2768. taskContLastNode.fadeIn('slow');
  2769. return false;
  2770. });
  2771. }
  2772. else if (data.type == 'SUCCESS') {
  2773. var msg = '';
  2774. if (data.id && data.id > 0) {
  2775. msg = 'Utworzono pomyślnie rekord: ID = ' + data.id;
  2776. } else if (data.msg) {
  2777. msg = data.msg;
  2778. } else {
  2779. msg = 'OK';
  2780. }
  2781. var out = '<div class="container">';
  2782. out += '<div class="alert alert-success">' + msg + '</div>';
  2783. out += '<div class="breadcrumb">' +
  2784. ' <a href="#" onclick="return tableAjaxBackToTable();" class="btn btn-link btn-small"> <i class="icon-arrow-left"></i> Wróć do tabeli <?php echo $this->getLabelHtml(); ?></a>' +
  2785. '<span class="divider">/</span>' +
  2786. ' <a href="#EDIT/' + data.id + '" class="btn btn-link btn-small"> <i class="icon-pencil"></i> Edytuj rekord ' + data.id + '</a>' +
  2787. '<span class="divider">/</span>' +
  2788. ' <a href="#CREATE/' + Math.random(1).toString().substr(2) + '" class="btn btn-link btn-small"> <i class="icon-plus"></i> Dodaj nowy rekord</a></li>' +
  2789. '</div>';
  2790. out += '</div>';
  2791. jQuery(out).appendTo(taskCnt);
  2792. }
  2793. }
  2794. }
  2795. });
  2796. return false;
  2797. });
  2798. });
  2799. </script>
  2800. <?php
  2801. exit;
  2802. }
  2803. private function sendAjaxCreateSave($args) {
  2804. header("Content-type: application/json");
  2805. $DBG = ('1' == V::get('DBG', '', $_REQUEST));
  2806. sleep(1);// TODO: RMME DBG loading
  2807. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">TODO: save ID(' . $id . ') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($args);echo'</pre>';}
  2808. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">acl (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($this->_acl);echo'</pre>';}
  2809. $dbID = $this->_acl->getDB();
  2810. $db = DB::getDB($dbID);
  2811. if (!$db) {
  2812. header('HTTP/1.0 406 Not Acceptable');
  2813. echo '{"type":"ERROR", "msg": "' . "Błąd połączenia z bazą danych!" . '"}';
  2814. exit;
  2815. }
  2816. $tblName = $this->_acl->getName();
  2817. $sqlObj = new stdClass();
  2818. $fields = $this->_acl->getFields();
  2819. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">fields (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($fields);echo'</pre>';}
  2820. foreach ($fields as $kID => $vField) {
  2821. if (!$this->_acl->isAllowed($kID, 'C')) {
  2822. continue;
  2823. }
  2824. if (array_key_exists("f{$kID}", $args)) {
  2825. $sqlObj->{$vField['name']} = $args["f{$kID}"];
  2826. if (empty($args["f{$kID}"]) && strlen($args["f{$kID}"]) == 0) {// fix bug in input type date and value="0000-00-00"
  2827. $sqlObj->{$vField['name']} = $this->_acl->fixEmptyValueFromUser($kID);
  2828. }
  2829. }
  2830. }
  2831. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;"> (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sqlObj);echo'</pre>';}
  2832. $retID = $db->ADD_NEW_OBJ($tblName, $sqlObj);
  2833. $retJson = new stdClass();
  2834. $retJson->type = '';
  2835. $retJson->msg = '';
  2836. if ($retID > 0) {
  2837. $retJson->type = 'SUCCESS';
  2838. $retJson->msg = "Utworzono pomyślnie rekord: ID = {$retID}";
  2839. $retJson->id = $retID;
  2840. } else {
  2841. header('HTTP/1.0 404 Not Found');
  2842. $retJson->type = 'ERROR';
  2843. $retJson->msg = "";
  2844. if ($db->has_errors()) {
  2845. $outArr = array();
  2846. $errorsSql = $db->get_errors();
  2847. foreach ($errorsSql as $vErr) {
  2848. if (substr($vErr, 0, 18) == 'SQL QUERY FAILED: ') {
  2849. $vErr = substr($vErr, 18);
  2850. // Duplicate entry '123456-1' for key 'P_NIP'
  2851. if (substr($vErr, 0, 16) == 'Duplicate entry ') {
  2852. }
  2853. }
  2854. $outArr[] = $vErr;
  2855. }
  2856. $retJson->msg .= implode('<br>', $outArr);
  2857. }
  2858. }
  2859. echo json_encode($retJson);
  2860. exit;
  2861. }
  2862. private function sendAjaxCopy($id, $args) {
  2863. header("Content-type: text/plain");
  2864. sleep(1);// TODO: RMME DBG loading
  2865. $dbID = $this->_acl->getDB();
  2866. $db = DB::getDB($dbID);
  2867. if (!$db) {
  2868. header('HTTP/1.0 406 Not Acceptable');
  2869. exit;
  2870. }
  2871. $row = $this->_dataSource->getItem($id);
  2872. if (!$row) {
  2873. header('HTTP/1.0 404 Not Found');
  2874. echo "404: No item ID({$rowID})";
  2875. exit;
  2876. }
  2877. $tblName = $this->_acl->getName();
  2878. $types = $this->_acl->getTypes();
  2879. $uniqKeys = $this->_acl->getUniqueKeys();
  2880. $sqlObj = new stdClass();
  2881. foreach ($types as $kName => $vType) {
  2882. if ($kName == 'ID') {
  2883. continue;
  2884. } else if (in_array($kName, array('A_RECORD_UPDATE_AUTHOR','A_RECORD_UPDATE_DATE'))) {
  2885. continue;
  2886. }
  2887. $sqlObj->{$kName} = V::get($kName, '', $row);
  2888. if (in_array($kName, $uniqKeys)) {
  2889. $sqlObj->{$kName} .= '?';
  2890. }
  2891. }
  2892. $ret = $db->ADD_NEW_OBJ($tblName, $sqlObj);
  2893. if ($ret > 0) {
  2894. echo '<div class="alert alert-success">';
  2895. echo '<button type="button" class="close" data-dismiss="alert"><i class="icon-remove"></i></button>';
  2896. echo "Rekord skopiowany pomyślnie - utworzono rekord nr {$ret}";//"Record saved successfully";
  2897. echo '</div>';
  2898. } else if ($ret == 0) {
  2899. echo '<div class="alert alert-error">';
  2900. echo '<button type="button" class="close" data-dismiss="alert"><i class="icon-remove"></i></button>';
  2901. echo "Nie udało się skopiować rekordu";
  2902. if ($db->has_errors()) {
  2903. echo '<br>' . implode("<br>", $db->get_errors());
  2904. }
  2905. echo '</div>';
  2906. } else {
  2907. echo '<div class="alert alert-error">';
  2908. echo '<button type="button" class="close" data-dismiss="alert"><i class="icon-remove"></i></button>';
  2909. echo "Błąd bazy danych";
  2910. echo '</div>';
  2911. }
  2912. exit;
  2913. }
  2914. private function sendAjaxHistory($id, $args) {
  2915. header("Content-type: text/plain");
  2916. $record = $this->_dataSource->getItem($id);
  2917. if (!$record) {
  2918. header('HTTP/1.0 404 Not Found');
  2919. echo "404: No item ID({$rowID})";
  2920. exit;
  2921. }
  2922. $visibleCols = $this->_acl->getRealFieldList();
  2923. $rowsHist = $this->_dataSource->getHistItems($id);
  2924. $rowFunctionsOut = $this->_showRowFunctions($record->ID, array('hist', 'cp'), true);
  2925. $visibleColsWithIds = array();
  2926. $visibleColsLabels = array();
  2927. foreach ($visibleCols as $vColName) {
  2928. $fldId = $this->_acl->getFieldIdByName($vColName);
  2929. if ($fldId) {
  2930. $visibleColsWithIds[$fldId] = $vColName;
  2931. $label = $this->_acl->getFieldLabel($fldId);
  2932. $label = (!$label)? $vColName : '<span title="' . "[{$fldId}] {$vColName}" . '">' . $label . '</span>';
  2933. $visibleColsLabels[$fldId] = $label;
  2934. }
  2935. }
  2936. ?>
  2937. <fieldset>
  2938. <legend>Historia rekordu Nr <?php echo $id; ?>
  2939. <span class="pull-right valign-btns-bottom"><?php echo $rowFunctionsOut; ?></span>
  2940. </legend>
  2941. </fieldset>
  2942. <?php if (empty($rowsHist)) : ?>
  2943. <div class="alert alert-info">
  2944. <h4>Brak danych</h4>
  2945. </div>
  2946. <?php else: ?>
  2947. <table class="table table-striped table-hover table-bordered table-condensed AjaxTableHist">
  2948. <thead>
  2949. <tr>
  2950. <th>Data</th>
  2951. <th>User</th>
  2952. <th>Zmiany</th>
  2953. </tr>
  2954. </thead>
  2955. <tbody>
  2956. <?php foreach ($rowsHist as $row) : ?>
  2957. <tr>
  2958. <td style="white-space:nowrap"><?php echo $row->_created; ?></td>
  2959. <td><?php echo $row->_author; ?></td>
  2960. <td>
  2961. <?php foreach ($visibleColsWithIds as $fldId => $colName) : ?>
  2962. <?php if (in_array($colName, array('ID', 'A_RECORD_UPDATE_DATE', 'A_RECORD_UPDATE_AUTHOR', 'A_RECORD_CREATE_DATE', 'A_RECORD_CREATE_AUTHOR'))) continue; ?>
  2963. <?php if ($row->$colName == 'N/S;') continue; ?>
  2964. <p><em><?php echo $visibleColsLabels[$fldId]; ?></em>:
  2965. <?php if ($this->_acl->isAllowed($fldId, 'R', $record)) : ?>
  2966. <?php echo $row->$colName; ?>
  2967. <?php else : ?>
  2968. <span title="Brak uprawnień do odczytu tego pola">*****</span>
  2969. <?php endif; ?>
  2970. </p>
  2971. <?php endforeach; ?>
  2972. </td>
  2973. </tr>
  2974. <?php endforeach; ?>
  2975. </tbody>
  2976. </table>
  2977. <div style="overflow-x:scroll; overflow-y:visible; padding-bottom:1px; margin:10px 0;">
  2978. <table class="table table-striped table-hover table-bordered table-condensed AjaxTableHist">
  2979. <thead>
  2980. <tr>
  2981. <?php foreach ($visibleColsWithIds as $fldId => $colName) : ?>
  2982. <th><?php echo str_replace('_', ' ', $visibleColsLabels[$fldId]); ?></th>
  2983. <?php endforeach; ?>
  2984. </tr>
  2985. </thead>
  2986. <tbody>
  2987. <?php foreach ($rowsHist as $row) : ?>
  2988. <tr>
  2989. <?php foreach ($visibleColsWithIds as $fldId => $colName) : ?>
  2990. <td>
  2991. <?php if ($row->$colName == 'N/S;') : ?>
  2992. <em>N/S;</em>
  2993. <?php elseif ($this->_acl->isAllowed($fldId, 'R', $record)) : ?>
  2994. <?php echo $row->$colName; ?>
  2995. <?php else : ?>
  2996. <span title="Brak uprawnień do odczytu tego pola">*****</span>
  2997. <?php endif; ?>
  2998. </td>
  2999. <?php endforeach; ?>
  3000. </tr>
  3001. <?php endforeach; ?>
  3002. </tbody>
  3003. </table>
  3004. </div>
  3005. <?php endif; ?>
  3006. <?php
  3007. exit;
  3008. }
  3009. /**
  3010. * Returns text/plain with type at first line: ERROR, WARNING, INFO, SUCCESS
  3011. */
  3012. private function sendAjaxFilesUpload($id, $args) {
  3013. // http://www.sitepoint.com/html5-ajax-file-upload/
  3014. //$ajaxFileName = (isset($_SERVER['HTTP_X_FILENAME']) ? $_SERVER['HTTP_X_FILENAME'] : false);
  3015. //header("Content-type: text/plain");
  3016. header("Content-type: application/json");
  3017. $DBG = ('1' == V::get('DBG', '', $_REQUEST));
  3018. $dbID = $this->_acl->getDB();
  3019. $db = DB::getDB($dbID);
  3020. if (!$db) {
  3021. header('HTTP/1.0 406 Not Acceptable');
  3022. echo '{"type":"ERROR", "string": "No DB (' . $dbID . ')"}';
  3023. exit;
  3024. }
  3025. $record = $this->_dataSource->getItem($id);
  3026. if (!$record) {
  3027. header('HTTP/1.0 404 Not Found');
  3028. echo '{"type":"ERROR", "string": "No item ID(' . $rowID . ')"}';
  3029. exit;
  3030. }
  3031. $tblName = $this->_acl->getName();
  3032. $confTblName = "{$tblName}_COLUMN";
  3033. Lib::loadClass('FoldersConfig');
  3034. $folderConfAll = FoldersConfig::getRawData();
  3035. if (!FoldersConfig::hasConfig($confTblName)) {
  3036. header('HTTP/1.0 404 Not Found');
  3037. echo '{"type":"ERROR", "string": "Brak danych konfiguracyjnych(' . $tblName . ')"}';
  3038. exit;
  3039. }
  3040. $folderConf = FoldersConfig::getAll($confTblName);
  3041. Lib::loadClass('FileUploader');
  3042. $uploader = new FileUploader($confTblName, $record);
  3043. $errMsg = '';
  3044. if (!$uploader->setConfig($folderConf, $errMsg)) {
  3045. header('HTTP/1.0 404 Not Found');
  3046. echo '{"type":"ERROR", "string": "Błąd danych konfiguracyjnych(' . $tblName . ') <br>' . $errMsg . '"}';
  3047. exit;
  3048. }
  3049. $uploader->findFolder();
  3050. $errorMsg = '';
  3051. if (!empty($_POST['SCANS_COLUMN_ADD'])) {
  3052. $uploaded = $uploader->tryMoveFromScanAjax($errorMsg);
  3053. }
  3054. else {
  3055. $uploaded = $uploader->tryUploadAjax($errorMsg);
  3056. }
  3057. /*
  3058. //$errorMsg = "wykonalem funkcje move dla parametrow ".$_FILES['M_DIST_FILES_NAME']['tmp_name']." oraz ".$IN7_FILERENAME['M_DIST_FILES_DEST_FOLDER']."/".$IN7_FILERENAME['DST_FILE_NAME'] ." <br>Informacje dodatkowe :".$IN7_FILERENAME['INFO']." <br> EOL <br> ";
  3059. // TODO: IN7_POST_HISTORY($TABLE, array('M_DIST_FILES'), array(" Wgrano plik z przegladarki WWW ".$_SERVER['REMOTE_ADDR']." ".$_FILES['M_DIST_FILES_NAME']['name']." do ".$IN7_FILERENAME['M_DIST_FILES_DEST_FOLDER']."/".$IN7_FILERENAME['DST_FILE_NAME']." "), $thiss, $SESSION);
  3060. // TODO: IN7_POST_HISTORY($TABLE, array('M_DIST_FILES'), array(" Wgrano plik z przegladarki WWW ".$_SERVER['REMOTE_ADDR']." ".$_FILES['M_DIST_FILES_NAME']['name']." do ".$IN7_FILERENAME['M_DIST_FILES_DEST_FOLDER']."/".$IN7_FILERENAME['DST_FILE_NAME']." "), $thiss, $SESSION);
  3061. */
  3062. if ($uploaded) {
  3063. $uploadedFileName = '';
  3064. $uploadedFile = $uploader->getLastUploadedFile();
  3065. if ($uploadedFile) {
  3066. $uploadedFileName = explode('/', $uploadedFile);
  3067. $uploadedFileName = end($uploadedFileName);
  3068. }
  3069. echo '{"type":"SUCCESS", "string": "Plik został poprawnie wgrany do odpowiedniego katalogu '.$uploadedFileName.'"}';
  3070. if (!empty($uploadedFileName)) {
  3071. $sqlObj = new stdClass();
  3072. $sqlObj->ID = $record->ID;
  3073. $sqlObj->M_DIST_FILES = "Wgrano plik {$uploadedFileName}";
  3074. $db->UPDATE_OBJ($this->_tbl, $sqlObj);
  3075. }
  3076. } else {
  3077. echo '{"type":"ERROR", "string": "' . $errorMsg . '"}';
  3078. }
  3079. exit;
  3080. }
  3081. private function sendAjaxFileRemove($id, $args) {
  3082. header("Content-type: application/json");
  3083. $DBG = ('1' == V::get('DBG', '', $_REQUEST));
  3084. if (empty($_POST['filename'])) {
  3085. echo '{"type":"ERROR", "string": "Nie wybrano pliku do usunięcia"}';
  3086. exit;
  3087. }
  3088. $dbID = $this->_acl->getDB();
  3089. $db = DB::getDB($dbID);
  3090. if (!$db) {
  3091. header('HTTP/1.0 406 Not Acceptable');
  3092. echo '{"type":"ERROR", "string": "No DB (' . $dbID . ')"}';
  3093. exit;
  3094. }
  3095. $record = $this->_dataSource->getItem($id);
  3096. if (!$record) {
  3097. header('HTTP/1.0 404 Not Found');
  3098. echo '{"type":"ERROR", "string": "No item ID(' . $rowID . ')"}';
  3099. exit;
  3100. }
  3101. $tblName = $this->_acl->getName();
  3102. $confTblName = "{$tblName}_COLUMN";
  3103. Lib::loadClass('FoldersConfig');
  3104. $folderConfAll = FoldersConfig::getRawData();
  3105. if (!FoldersConfig::hasConfig($confTblName)) {
  3106. header('HTTP/1.0 404 Not Found');
  3107. echo '{"type":"ERROR", "string": "Brak danych konfiguracyjnych (' . $tblName . ')"}';
  3108. exit;
  3109. }
  3110. $folderConf = FoldersConfig::getAll($confTblName);
  3111. Lib::loadClass('FileUploader');
  3112. $uploader = new FileUploader($confTblName, $record);
  3113. if (!$uploader->setConfig($folderConf)) {
  3114. header('HTTP/1.0 404 Not Found');
  3115. echo '{"type":"ERROR", "string": "Błąd danych konfiguracyjnych (' . $tblName . ')"}';
  3116. exit;
  3117. }
  3118. $uploader->findFolder();
  3119. $errorMsg = '';
  3120. $removed = $uploader->tryRemoveFromAjax($_POST['filename'], $errorMsg);
  3121. if (!$removed) {
  3122. echo '{"type":"ERROR", "string": "{' . $errorMsg . '}"}';
  3123. } else {
  3124. echo '{"type":"SUCCESS","string":"Plik został poprawnie usunięty"}';
  3125. }
  3126. exit;
  3127. }
  3128. private function sendAjaxFilesList($id, $args) {
  3129. header("Content-type: application/json");
  3130. $dbID = $this->_acl->getDB();
  3131. $db = DB::getDB($dbID);
  3132. if (!$db) {
  3133. header('HTTP/1.0 406 Not Acceptable');
  3134. echo '{"type":"ERROR", "string": "No DB (' . $dbID . ')"}';
  3135. exit;
  3136. }
  3137. $record = $this->_dataSource->getItem($id);
  3138. if (!$record) {
  3139. header('HTTP/1.0 404 Not Found');
  3140. echo '{"type":"ERROR", "string": "No item ID(' . $rowID . ')"}';
  3141. exit;
  3142. }
  3143. $tblName = $this->_acl->getName();
  3144. $confTblName = "{$tblName}_COLUMN";
  3145. Lib::loadClass('FoldersConfig');
  3146. $folderConfAll = FoldersConfig::getRawData();
  3147. if (!FoldersConfig::hasConfig($confTblName)) {
  3148. header('HTTP/1.0 404 Not Found');
  3149. echo '{"type":"ERROR", "string": "Brak danych konfiguracyjnych (' . $tblName . ')"}';
  3150. exit;
  3151. }
  3152. $folderConf = FoldersConfig::getAll($confTblName);
  3153. Lib::loadClass('FileUploader');
  3154. $uploader = new FileUploader($confTblName, $record);
  3155. if (!$uploader->setConfig($folderConf)) {
  3156. header('HTTP/1.0 404 Not Found');
  3157. echo '{"type":"ERROR", "string": "Błąd danych konfiguracyjnych (' . $tblName . ')"}';
  3158. exit;
  3159. }
  3160. $uploader->findFolder();
  3161. $mainFolder = $uploader->getDestFolder();
  3162. $files = $uploader->getFilesFromFolder($mainFolder, false, true);
  3163. $localPath = $uploader->getLocalPath();
  3164. $folderWeb = $uploader->getFolderWeb();
  3165. $jsonFiles = $this->convertFileListToJson($files, $folderWeb, $localPath, $mainFolder);
  3166. echo json_encode($jsonFiles);
  3167. exit;
  3168. }
  3169. private function sendAjaxFilesConnTblList($id, $args) {
  3170. header("Content-type: application/json");
  3171. $DBG = ('1' == V::get('DBG', '', $_REQUEST));
  3172. $dbID = $this->_acl->getDB();
  3173. $db = DB::getDB($dbID);
  3174. if (!$db) {
  3175. header('HTTP/1.0 406 Not Acceptable');
  3176. echo 'No DB (' . $dbID . ')';
  3177. exit;
  3178. }
  3179. $record = $this->_dataSource->getItem($id);
  3180. if (!$record) {
  3181. header('HTTP/1.0 404 Not Found');
  3182. echo 'No item ID(' . $rowID . ')';
  3183. exit;
  3184. }
  3185. $connTblName = '';
  3186. $connTblID = V::get('connTblID', 0, $_REQUEST, 'int');
  3187. if ($connTblID <= 0) {
  3188. header('HTTP/1.0 406 Not Acceptable');
  3189. echo 'No conn Table ID';
  3190. exit;
  3191. }
  3192. $connTblTypespecials = $this->getConnectedTblTypespecials($connTblID);
  3193. if (empty($connTblTypespecials)) {
  3194. header('HTTP/1.0 406 Not Acceptable');
  3195. echo "No conn Table (ID={$connTblID})";
  3196. exit;
  3197. }
  3198. 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>';}
  3199. if(1) {
  3200. header('HTTP/1.0 404 Not Found');
  3201. echo 'TODO: ...';
  3202. exit;
  3203. }
  3204. $tblName = $this->_acl->getName();
  3205. $confTblName = "{$tblName}_COLUMN";
  3206. Lib::loadClass('FoldersConfig');
  3207. $folderConfAll = FoldersConfig::getRawData();
  3208. if (!FoldersConfig::hasConfig($confTblName)) {
  3209. header('HTTP/1.0 404 Not Found');
  3210. echo '{"type":"ERROR", "string": "Brak danych konfiguracyjnych (' . $tblName . ')"}';
  3211. exit;
  3212. }
  3213. $folderConf = FoldersConfig::getAll($confTblName);
  3214. Lib::loadClass('FileUploader');
  3215. $uploader = new FileUploader($confTblName, $record);
  3216. if (!$uploader->setConfig($folderConf)) {
  3217. header('HTTP/1.0 404 Not Found');
  3218. echo '{"type":"ERROR", "string": "Błąd danych konfiguracyjnych (' . $tblName . ')"}';
  3219. exit;
  3220. }
  3221. $uploader->findFolder();
  3222. $mainFolder = $uploader->getDestFolder();
  3223. $files = $uploader->getFilesFromFolder($mainFolder, false, true);
  3224. $localPath = $uploader->getLocalPath();
  3225. $folderWeb = $uploader->getFolderWeb();
  3226. $jsonFiles = $this->convertFileListToJson($files, $folderWeb, $localPath, $mainFolder);
  3227. echo json_encode($jsonFiles);
  3228. exit;
  3229. }
  3230. public function convertFileListToJson($files, $folderWeb, $localPath, $mainFolder) {
  3231. sort($files);
  3232. $jsonFiles = array();
  3233. foreach ($files as $vFilePath) {
  3234. $file = new stdClass();
  3235. $file->name = str_replace("{$localPath}/{$mainFolder}/", '', $vFilePath);
  3236. //$file->name = explode('/', $vFilePath);
  3237. //$file->name = end($file->name);
  3238. $file->size = filesize($vFilePath);
  3239. $file->sizeStr = round($file->size, 2) . "B";
  3240. if ($file->size > 1024 * 1024) {
  3241. $file->sizeStr = round(($file->size / (1024 * 1024)), 2) . "M";
  3242. } else if ($file->size > 1024) {
  3243. $file->sizeStr = round(($file->size / 1024), 2) . "K";
  3244. }
  3245. $file->type = '';
  3246. $file->created = date("Y-m-d H:i:s", filectime($vFilePath));
  3247. $file->web = str_replace($localPath, $folderWeb, $vFilePath);
  3248. $jsonFiles[] = $file;
  3249. }
  3250. return $jsonFiles;
  3251. }
  3252. private function getConnectedTables() {
  3253. $connTbls = array();
  3254. return $connTbls;// TODO: OFF - hardlinki tworzone w bash_sync_perms.php
  3255. $fields = $this->_acl->getVisibleFieldList();
  3256. if (!empty($fields)) {
  3257. Lib::loadClass('Typespecial');
  3258. foreach ($fields as $vColID => $vCol) {
  3259. $typeSpecial = Typespecial::getInstance($vColID);
  3260. if ($typeSpecial) {
  3261. $tsConnTbls = $typeSpecial->getTblAliasList();
  3262. if (!empty($tsConnTbls)) {
  3263. foreach ($tsConnTbls as $kID => $vName) {
  3264. $connTbls[$kID] = $vName;
  3265. }
  3266. }
  3267. }
  3268. }
  3269. }
  3270. return $connTbls;
  3271. }
  3272. private function getConnectedTblTypespecials($connTblID) {
  3273. $connTblTypespecials = array();
  3274. $fields = $this->_acl->getVisibleFieldList();
  3275. if (!empty($fields)) {
  3276. Lib::loadClass('Typespecial');
  3277. foreach ($fields as $vColID => $vCol) {
  3278. $typeSpecial = Typespecial::getInstance($vColID);
  3279. if ($typeSpecial) {
  3280. $tsConnTbls = $typeSpecial->getTblAliasList();
  3281. if (array_key_exists($connTblID, $tsConnTbls)) {
  3282. $connTblTypespecials[] = $typeSpecial;
  3283. }
  3284. }
  3285. }
  3286. }
  3287. return $connTblTypespecials;
  3288. }
  3289. private function sendAjaxFiles($id, $args) {
  3290. header("Content-type: text/plain");
  3291. $DBG = ('1' == V::get('DBG', '', $_REQUEST));
  3292. $dbID = $this->_acl->getDB();
  3293. $db = DB::getDB($dbID);
  3294. if (!$db) {
  3295. header('HTTP/1.0 406 Not Acceptable');
  3296. exit;
  3297. }
  3298. $record = $this->_dataSource->getItem($id);
  3299. if (!$record) {
  3300. header('HTTP/1.0 404 Not Found');
  3301. echo "404: No item ID({$rowID})";
  3302. exit;
  3303. }
  3304. $tblName = $this->_acl->getName();
  3305. $confTblName = "{$tblName}_COLUMN";
  3306. Lib::loadClass('FoldersConfig');
  3307. $folderConfAll = FoldersConfig::getRawData();
  3308. if (!FoldersConfig::hasConfig($confTblName)) {
  3309. header('HTTP/1.0 404 Not Found');
  3310. echo "Brak danych konfiguracyjnych";
  3311. exit;
  3312. }
  3313. $folderConf = FoldersConfig::getAll($confTblName);
  3314. //echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">$folderConf (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($folderConf);echo'</pre>';
  3315. Lib::loadClass('FileUploader');
  3316. $uploader = new FileUploader($confTblName, $record);
  3317. $errMsg = '';
  3318. if (!$uploader->setConfig($folderConf, $errMsg)) {
  3319. header('HTTP/1.0 404 Not Found');
  3320. echo "Błąd danych konfiguracyjnych ({$tblName})";
  3321. echo '<br>' . "\n" . $errMsg;
  3322. exit;
  3323. }
  3324. $uploader->findFolder();
  3325. 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>'; }
  3326. $mainFolder = $uploader->getDestFolder();
  3327. 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>'; }
  3328. $files = $uploader->getFilesFromFolder($mainFolder, false, true);
  3329. 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>'; }
  3330. $sharePoint = V::get('share_point', null, $folderConf);
  3331. if ($sharePoint) {
  3332. $sharePoint = FoldersConfig::getNfsOsPath() . "{$sharePoint}/{$mainFolder}";
  3333. }
  3334. $localPath = $uploader->getLocalPath();
  3335. $folderWeb = $uploader->getFolderWeb();
  3336. $jsonFiles = $this->convertFileListToJson($files, $folderWeb, $localPath, $mainFolder);
  3337. 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>'; }
  3338. $folderSkanyConf = FoldersConfig::getAll('SCANS_COLUMN');
  3339. $skanyLocalPath = V::get('mount_point', null, $folderSkanyConf);
  3340. $skanySharePoint = V::get('share_point', null, $folderSkanyConf);
  3341. $skanyFolderWeb = V::get('www_share_point', null, $folderSkanyConf);
  3342. $skanyFiles = $uploader->getFilesFromSkany($folderSkanyConf, false);
  3343. sort($skanyFiles);
  3344. $fileTypes = FoldersConfig::getAll('m_dist_files_types');
  3345. $rowFunctionsOut = $this->_showRowFunctions($record->ID, array('files', 'cp'), true);
  3346. ?>
  3347. <script src="stuff/jquery.form.js"></script>
  3348. <div class="container">
  3349. <h4 style="margin:20px 0 3px 0;">Pliki w katalogu
  3350. <?php if ($sharePoint) : ?>
  3351. <a href="<?php echo $sharePoint; ?>"><code><?php echo $mainFolder; ?></code></a>
  3352. <?php else : ?>
  3353. <code><?php echo $mainFolder; ?></code>
  3354. <?php endif; ?>
  3355. <span class="pull-right valign-btns-bottom"><?php echo $rowFunctionsOut; ?></span>
  3356. </h4>
  3357. <div style="max-height:180px; overflow:auto; border-bottom:1px solid #ddd;">
  3358. <table class="table table-bordered table-hover">
  3359. <colgroup>
  3360. <col style="">
  3361. <col style="width:30px;">
  3362. <?php if ($sharePoint) : ?>
  3363. <col style="width:30px;">
  3364. <?php endif; ?>
  3365. <col style="width:80px;">
  3366. <col style="width:140px;">
  3367. </colgroup>
  3368. <tbody id="FILES_LIST_<?php echo $this->_htmlID; ?>">
  3369. <?php if (empty($mainFolder)) : ?>
  3370. <tr>
  3371. <td colspan="5">
  3372. <div class="alert alert-warning">
  3373. <h4>Brak folderu!</h4>
  3374. Folder dla tego rekordu nie został utworzony.
  3375. </div>
  3376. </td>
  3377. </tr>
  3378. <?php elseif (empty($files)) : ?>
  3379. <tr>
  3380. <td colspan="5">
  3381. <div class="alert alert-info">
  3382. <h4>Brak plików</h4>
  3383. </div>
  3384. </td>
  3385. </tr>
  3386. <?php endif; ?>
  3387. </tbody>
  3388. </table>
  3389. </div>
  3390. <br>
  3391. <br>
  3392. <div id="FILES_CONN_TBLS_<?php echo $this->_htmlID; ?>"></div>
  3393. <form enctype="multipart/form-data" method="POST" action="" id="FILES_FRM_<?php echo $this->_htmlID; ?>" class="form-inline">
  3394. <input type="hidden" name="M_DIST_UPLOAD_SOURCE" value="local">
  3395. <ul id="FILES_TAB_<?php echo $this->_htmlID; ?>" class="nav nav-tabs" style="margin:0;">
  3396. <li class="active"><a href="#local" data-toggle="local">Wybierz plik lokalny</a></li>
  3397. <li><a href="#scan" data-toggle="scan">Wybierz plik ze skanów</a></li>
  3398. </ul>
  3399. <div id="myTabContent" class="tab-content">
  3400. <div class="tab-pane fade in active" id="local" style="text-align: center;">
  3401. <input name="M_DIST_FILES_NAME" type="file" size="60" class="field-upload btn" style="width:86%;margin:10px auto;padding:10px 4%;background:#eee;text-align:center;" ondragover="this.style.backgroundColor='#D9EDF7'" ondragleave="this.style.backgroundColor='#eee'" ondragend="this.style.backgroundColor='#eee'">
  3402. </div>
  3403. <div class="tab-pane fade" id="scan">
  3404. <?php if (empty($skanyFiles)) : ?>
  3405. <div class="alert alert-info">
  3406. <h4>Brak plików</h4>
  3407. <?php if(!empty($skanyFolderWeb)) echo "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>"; ?>
  3408. </div>
  3409. <?php else : ?>
  3410. <div style="max-height:150px; overflow:auto; border-bottom:1px solid #ddd;">
  3411. <table class="table table-bordered table-hover">
  3412. <colgroup>
  3413. <col style="width:30px;">
  3414. <col style="">
  3415. <col style="width:30px;">
  3416. <col style="width:80px;">
  3417. <col style="width:140px;">
  3418. </colgroup>
  3419. <tbody>
  3420. <?php foreach ($skanyFiles as $vFilePath) : ?>
  3421. <tr>
  3422. <?php
  3423. $vFileName = explode('/', $vFilePath);
  3424. $vFileName = end($vFileName);
  3425. $vFileSize = filesize($vFilePath);
  3426. $vFileSizeOut = round($vFileSize, 2) . "B";
  3427. if ($vFileSize > 1024 * 1024) {
  3428. $vFileSizeOut = round(($vFileSize / (1024 * 1024)), 2) . "M";
  3429. } else if ($vFileSize > 1024) {
  3430. $vFileSizeOut = round(($vFileSize / 1024), 0) . "K";
  3431. }
  3432. ?>
  3433. <td><input style="margin:0;" type="radio" name="SCANS_COLUMN_ADD" value="<?php echo $vFileName; ?>"></td>
  3434. <td><div style="overflow:hidden; white-space:nowrap;" title="<?php echo $vFileName; ?>"><?php echo $vFileName; ?></div></td>
  3435. <td style="white-space:nowrap; text-align:center;"><a href="<?php echo str_replace($skanyLocalPath, $skanyFolderWeb, $vFilePath); ?>" target="_blank" class="ico-download-alt"></a></td>
  3436. <td style="white-space:nowrap;"><?php echo $vFileSizeOut; ?></td>
  3437. <td style="white-space:nowrap;"><?php echo date("Y-m-d H:i:s", filectime($vFilePath)); ?></td>
  3438. </tr>
  3439. <?php endforeach; ?>
  3440. </tbody>
  3441. </table>
  3442. </div>
  3443. <?php endif; ?>
  3444. </div>
  3445. </div>
  3446. <script>
  3447. $('#FILES_TAB_<?php echo $this->_htmlID; ?> a').click(function (e) {
  3448. e.preventDefault();
  3449. $(this).tab('show');
  3450. })
  3451. .on('shown', function (e) {
  3452. var fileSource = $(e.target).data('toggle')
  3453. , frm = jQuery('#FILES_FRM_<?php echo $this->_htmlID; ?>').get(0);
  3454. if (frm['M_DIST_UPLOAD_SOURCE']) {
  3455. frm['M_DIST_UPLOAD_SOURCE'].value = fileSource;
  3456. }
  3457. })
  3458. </script>
  3459. <br>
  3460. <table style="width:100%" class="table table-noborder">
  3461. <tr>
  3462. <td colspan="5">
  3463. <h4>Ustal nazwę pliku zgodną z obiegiem dokumentów
  3464. <?php //TODO: link do procesu o obiegu dokumentów <i class="icon-question-sign" style="cursor:help" title="działa w nowszych przeglądarkach jak Firefox, Chrome"></i> ?>
  3465. </h4>
  3466. </td>
  3467. </tr>
  3468. <tr>
  3469. <th style="border-right:1px solid #eee">ID</th>
  3470. <th style="border-right:1px solid #eee">TYP</th>
  3471. <th style="border-right:1px solid #eee">Opis <i class="icon-question-sign" title="kogo dotyczy / czego / sprawa / nazwa_firmy itp"></i></th>
  3472. <th style="border-right:1px solid #eee">Data Wersji</th>
  3473. <th>Numer Wersji</th>
  3474. </tr>
  3475. <tr>
  3476. <td style="border-right:1px solid #eee;">
  3477. <?php echo $record->ID; ?>
  3478. </td>
  3479. <td style="border-right:1px solid #eee;">
  3480. <select name="M_DIST_FILES_TYPE">
  3481. <?php foreach ($fileTypes as $kType => $vLabel) : ?>
  3482. <option value="<?php echo $kType; ?>"<?php if ($kType == 'TODO') { echo ' selected="selected"'; } ?> ><?php echo $vLabel; ?></option>
  3483. <?php endforeach; ?>
  3484. </select>
  3485. <br>
  3486. <label class="checkbox">
  3487. <input type="checkbox" name="M_DIST_FILES_TYPE_AUTO">
  3488. Wykrycie automatyczne TYPU z wysylanego pliku
  3489. </label>
  3490. <label class="checkbox">
  3491. <input type="checkbox" name="M_DIST_FILES_TEMP">
  3492. Plik tymczasowy / roboczy / nieoficjalny (_TEMP)
  3493. </label>
  3494. </td>
  3495. <td style="border-right:1px solid #eee;">
  3496. <input type="text" name="M_DIST_FILES_DESCRIPTION" value="<?php echo $M_DIST_FILES_DESCRIPTION; ?>" maxlength="50">
  3497. <br><label>jeśli nie zostanie podany to zostanie automatycznie wygenerowany na podstawie nazwy pliku wysyłanego</label>
  3498. </td>
  3499. <td style="border-right:1px solid #eee;">
  3500. <input type="date" name="M_DIST_FILES_DATE" value="<?php echo date('Y-m-d');?>" maxlength="10" class="span2">
  3501. <br><label>jeśli nie zostanie podana to zostanie ustawiona na dzisiaj (<?php echo date('Y-m-d');?>)</label>
  3502. </td>
  3503. <td>
  3504. <input type="number" name="M_DIST_FILES_VERSION" class="span2">
  3505. <br>
  3506. <label class="checkbox">
  3507. <input type="checkbox" name="M_DIST_FILES_VERSION_AUTO">
  3508. Automatycznie dodaj wersje
  3509. </label>
  3510. </td>
  3511. </tr>
  3512. <tr>
  3513. <td colspan="5">
  3514. <div id="FRM_UPLOAD_RESULTS_<?php echo $this->_htmlID; ?>"></div>
  3515. <p>
  3516. <input type="submit" value="Wyślij" class="btn btn-primary"> wybrany plik do folderu:
  3517. </p>
  3518. <p>
  3519. <code><b><?php echo $uploader->getDestPathShare(true); ?></b></code>
  3520. <br><i style="color:#777">(Jeśli folder nie istnieje to zostanie utworzony automatycznie)</i>
  3521. </p>
  3522. </td>
  3523. </tr>
  3524. </table>
  3525. </form>
  3526. </div>
  3527. <script>
  3528. function fileListUpdateAjax<?php echo $this->_htmlID; ?>() {
  3529. var postData = {};
  3530. jQuery.ajax({
  3531. url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=FILES_LIST&ID=<?php echo $record->ID; ?>',
  3532. type: 'POST',
  3533. //dataType: 'json',
  3534. //contentType: "application/json; charset=utf-8",
  3535. data: postData,
  3536. async: true,
  3537. success: function (data) {
  3538. fileListUpdate<?php echo $this->_htmlID; ?>(data);
  3539. },
  3540. error: function (jhr, textStatus, errorThrown) {
  3541. console.log('request error: ', errorThrown, ' textStatus: ', textStatus);
  3542. }
  3543. });
  3544. }
  3545. function fileListUpdate<?php echo $this->_htmlID; ?>(fileListJson) {
  3546. var fileListNode = jQuery('#FILES_LIST_<?php echo $this->_htmlID; ?>');
  3547. fileListNode.empty();
  3548. fileListJson.map(function(file){
  3549. var node = $('<tr></tr>');
  3550. var fFun = $('<i class="ico-remove" style="cursor:pointer" data-filename="' + file.name + '"></i>');
  3551. var fNameCell = $('<td style="overflow: hidden;"></td>');
  3552. var fName = $('<div style="overflow:hidden; white-space:nowrap;" title="' + file.name + '"></div>');
  3553. fName.append(fFun);
  3554. fName.append(file.name);
  3555. fName.appendTo(fNameCell);
  3556. node.append(fNameCell);
  3557. node.append('<td style="overflow:hidden; white-space:nowrap; text-align:center;">' + '<a href="' + file.web + '" target="_blank" class="ico-download-alt"></a>' + '</td>');
  3558. <?php if ($sharePoint) : ?>
  3559. node.append('<td style="overflow:hidden; white-space:nowrap; text-align:center;">' + '<a href="<?php echo $sharePoint; ?>/' + file.name + '" target="_blank" class="ico-folder-open"></a>' + '</td>');
  3560. <?php endif; ?>
  3561. node.append('<td style="overflow:hidden; white-space:nowrap; text-align:right;">' + file.sizeStr + '</td>');
  3562. node.append('<td style="overflow:hidden; white-space:nowrap;">' + file.created + '</td>');
  3563. node.appendTo(fileListNode);
  3564. $(fFun).click(function(e){
  3565. var n = $(e.target);
  3566. var fname= n.data('filename');
  3567. if (!fname) {
  3568. return false;
  3569. }
  3570. if (confirm('Czy jesteś pewien, że chcesz usunąć plik o nazwie ' + fname + '?')) {
  3571. var postData = {filename: fname};
  3572. jQuery.ajax({
  3573. url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=FILE_REMOVE&ID=<?php echo $record->ID; ?>',
  3574. type: 'POST',
  3575. //dataType: 'json',
  3576. //contentType: "application/json; charset=utf-8",
  3577. data: postData,
  3578. async: true,
  3579. success: function (data) {
  3580. if (data && data.type) {
  3581. if (data.type == 'SUCCESS') {
  3582. n.parents('tr').remove();
  3583. //console.log('TODO: SUCCESS msg: ', data.string);
  3584. }
  3585. else if (data.type == 'ERROR') {
  3586. //console.log('TODO: ERROR msg: ', data.string);
  3587. }
  3588. } else {
  3589. console.log('TODO: ??? data: ', data);
  3590. }
  3591. },
  3592. error: function (jhr, textStatus, errorThrown) {
  3593. console.log('rm error: ', errorThrown, ' textStatus: ', textStatus);
  3594. }
  3595. });
  3596. }
  3597. });
  3598. });
  3599. }
  3600. function connTblListUpdateAjax<?php echo $this->_htmlID; ?>(connTblID) {
  3601. var postData = {};
  3602. // clear current file list
  3603. jQuery('#FILES_CONN_TBLS_<?php echo $this->_htmlID; ?>').find('.files-list').empty();
  3604. jQuery.ajax({
  3605. url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=FILES_CONN_TBL_LIST&ID=<?php echo $record->ID; ?>&connTblID=' + connTblID,
  3606. type: 'POST',
  3607. //dataType: 'json',
  3608. //contentType: "application/json; charset=utf-8",
  3609. data: postData,
  3610. async: true,
  3611. success: function (data) {
  3612. connTblListUpdate<?php echo $this->_htmlID; ?>(data);
  3613. },
  3614. error: function (jqXHR, textStatus, errorThrown) {
  3615. var txt = jqXHR.responseText || 'Error';
  3616. jQuery('#FILES_CONN_TBLS_<?php echo $this->_htmlID; ?>').find('.files-list').html('<tr><td colspan="6"><div class="alert alert-error">' + txt + '</div></td></tr>');
  3617. console.log('connTblListUpdateAjax error: ', errorThrown, ' textStatus: ', textStatus);
  3618. }
  3619. });
  3620. }
  3621. function connTblListUpdate<?php echo $this->_htmlID; ?>(fileListJson) {
  3622. var fileListNode = jQuery('#FILES_CONN_TBLS_<?php echo $this->_htmlID; ?>').find('.files-list');
  3623. fileListNode.empty();
  3624. fileListJson.map(function(file){
  3625. var node = $('<tr></tr>');
  3626. var fNameCell = $('<td style="overflow: hidden;"></td>');
  3627. var fName = $('<div style="overflow:hidden; white-space:nowrap;" title="' + file.name + '"></div>');
  3628. fName.append(file.name);
  3629. fName.appendTo(fNameCell);
  3630. node.append(fNameCell);
  3631. node.append('<td style="overflow:hidden; white-space:nowrap; text-align:center;">' + '<a href="' + file.web + '" target="_blank" class="ico-download-alt"></a>' + '</td>');
  3632. node.append('<td style="overflow:hidden; white-space:nowrap; text-align:right;">' + file.sizeStr + '</td>');
  3633. node.append('<td style="overflow:hidden; white-space:nowrap;">' + file.created + '</td>');
  3634. node.appendTo(fileListNode);
  3635. });
  3636. }
  3637. jQuery(document).ready(function(){
  3638. jQuery('#FILES_FRM_<?php echo $this->_htmlID; ?>').ajaxForm({
  3639. url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=FILES_UPLOAD&ID=<?php echo $record->ID; ?>',
  3640. beforeSubmit: function(args, $form, options) {
  3641. var argsMap = [];
  3642. args.map(function(v, k) {
  3643. argsMap[v.name] = v.value;
  3644. });
  3645. // validate
  3646. if (argsMap['M_DIST_UPLOAD_SOURCE'] == 'local') {
  3647. if (!argsMap['M_DIST_FILES_NAME']) {
  3648. console.log('TODO: nie wybrano lokalnego pliku!');
  3649. return false;
  3650. }
  3651. }
  3652. else if (argsMap['M_DIST_UPLOAD_SOURCE'] == 'scan') {
  3653. if (!argsMap['SCANS_COLUMN_ADD']) {
  3654. console.log('TODO: nie wybrano pliku ze skanów!');
  3655. return false;
  3656. }
  3657. }
  3658. else {
  3659. console.log('TODO: nie wybrano źródła pliku!');
  3660. return false;
  3661. }
  3662. var $out = $('#FRM_UPLOAD_RESULTS_<?php echo $this->_htmlID; ?>');
  3663. $out.html('Wysyłanie...');
  3664. },
  3665. success: function(data) {
  3666. var $out = $('#FRM_UPLOAD_RESULTS_<?php echo $this->_htmlID; ?>');
  3667. var btnClose = '<button type="button" class="close" data-dismiss="alert"><i class="icon-remove"></i></button>';
  3668. if (typeof data == 'object') {
  3669. if (data.type == 'ERROR') {
  3670. $out.html('<div class="alert alert-error">' + btnClose + data.string + '</div>');
  3671. } else if (data.type == 'SUCCESS') {
  3672. $out.html('<div class="alert alert-success">' + btnClose + data.string + '</div>');
  3673. fileListUpdateAjax<?php echo $this->_htmlID; ?>();
  3674. }
  3675. } else {
  3676. if (data.substr(0, 7) == 'WARNING') {
  3677. data = data.substr(7);
  3678. $out.html('<div class="alert alert-warning">' + btnClose + data + '</div>');
  3679. } else if (data.substr(0, 5) == 'ERROR') {
  3680. data = data.substr(5);
  3681. $out.html('<div class="alert alert-error">' + btnClose + data + '</div>');
  3682. } else if (data.substr(0, 7) == 'SUCCESS') {
  3683. data = data.substr(7);
  3684. $out.html('<div class="alert alert-success">' + btnClose + data + '</div>');
  3685. fileListUpdateAjax<?php echo $this->_htmlID; ?>();
  3686. } else if (data.substr(0, 4) == 'INFO') {
  3687. data = data.substr(4);
  3688. $out.html('<div class="alert alert-info">' + btnClose + data + '</div>');
  3689. }
  3690. }
  3691. }
  3692. });
  3693. var fileList = <?php echo json_encode($jsonFiles); ?>;
  3694. fileListUpdate<?php echo $this->_htmlID; ?>(fileList);
  3695. var connTbls = <?php echo json_encode($this->getConnectedTables()); ?>;
  3696. if (connTbls) {
  3697. var connTblsOut = '';
  3698. for(var key in connTbls) {
  3699. connTblsOut += '<button class="btn btn-small conn-tbl-load" data-zasobid="' + key + '">' + connTbls[key] + '</button>';
  3700. };
  3701. if (connTblsOut) {
  3702. connTblsOut = 'Pliki w powiązanych tabelach: <div class="btn-group">' + connTblsOut + '</div>';
  3703. connTblsOut += '<div style="max-height:180px; overflow:auto; border-bottom:1px solid #ddd;">' +
  3704. '<table class="table table-bordered table-hover">' +
  3705. '<colgroup>' +
  3706. '<col style="">' +
  3707. '<col style="width:30px;">' +
  3708. <?php if ($sharePoint) : ?>
  3709. '<col style="width:30px;">' +
  3710. <?php endif; ?>
  3711. '<col style="width:80px;">' +
  3712. '<col style="width:140px;">' +
  3713. '</colgroup>' +
  3714. '<tbody class="files-list">' +
  3715. '</tbody>' +
  3716. '</table>' +
  3717. '</div>';
  3718. var _connTblsWrap = jQuery('#FILES_CONN_TBLS_<?php echo $this->_htmlID; ?>');
  3719. _connTblsWrap.css('marginBottom', '26px');
  3720. _connTblsWrap.html(connTblsOut);
  3721. _connTblsWrap.find('.conn-tbl-load').each(function(){
  3722. jQuery(this).click(function(e){
  3723. var tblID = jQuery(e.target).data('zasobid');
  3724. console.log('clicked: ', tblID);
  3725. if (tblID) {
  3726. connTblListUpdateAjax<?php echo $this->_htmlID; ?>(tblID);
  3727. }// TODO: else show error
  3728. });
  3729. });
  3730. }
  3731. }
  3732. });
  3733. </script>
  3734. <?php
  3735. exit;
  3736. }
  3737. private function sendTypeSpecial($fldID, $args) {
  3738. $DBG = ('1' == V::get('DBG', '', $_REQUEST));
  3739. header("Content-type: application/json");
  3740. $fldName = '';
  3741. $fld = $this->_acl->getField($fldID);
  3742. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">fld('.$fldID.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($fld);echo'</pre>';}
  3743. if (!$fld) {
  3744. // 404
  3745. } else {
  3746. $fldName = $fld['name'];
  3747. }
  3748. $jsonData = array();
  3749. Lib::loadClass('Typespecial');
  3750. $typeSpecial = Typespecial::getInstance($fldID, $fldName);
  3751. if ($typeSpecial) {
  3752. $query = V::get('q', '', $_REQUEST);
  3753. $rawRows = null;
  3754. $rows = $typeSpecial->getValuesWithExports($query);
  3755. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">rows('.$query.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($rows);echo'</pre>';}
  3756. foreach ($rows as $kID => $vItem) {
  3757. $itemJson = new stdClass();
  3758. $itemJson->id = $vItem->id;
  3759. $itemJson->name = $vItem->param_out;
  3760. if (!empty($vItem->exports)) {
  3761. $itemJson->exports = $vItem->exports;
  3762. }
  3763. $jsonData[] = $itemJson;
  3764. }
  3765. }
  3766. /*
  3767. MENU_INIT:VIEWTABLE_AJAX
  3768. ZASOB_ID:1188
  3769. _task:TYPESPECIAL
  3770. fldID:3866
  3771. Form Dataview sourceview URL encoded
  3772. q:te
  3773. */
  3774. echo json_encode($jsonData);
  3775. exit;
  3776. }
  3777. private function sendTypeSpecialCell($id, $fldName, $args) {
  3778. $DBG = ('1' == V::get('DBG', '', $_REQUEST));
  3779. header("Content-type: application/json");
  3780. $jsonData = new stdClass();
  3781. $fldID = $this->_acl->getFieldIdByName($fldName);
  3782. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">fld('.$fldName.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($fldID);echo'</pre>';}
  3783. $item = $this->_dataSource->getItem($id);
  3784. if (!$this->_acl->isAllowed($fldID, 'R', $item)) {
  3785. $jsonData->msg = 'Brak dostępu';
  3786. echo json_encode($jsonData);
  3787. exit;
  3788. }
  3789. if (!$fldID) {
  3790. $jsonData->msg = 'Wrong field';
  3791. echo json_encode($jsonData);
  3792. exit;
  3793. }
  3794. Lib::loadClass('Typespecial');
  3795. $typeSpecial = Typespecial::getInstance($fldID, $fldName);
  3796. if ($typeSpecial) {
  3797. $jsonData->data = $typeSpecial->getReturnData($this->_zasobID, $id, $fldName, '');
  3798. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">specialValuesByIds('.$id.'/'.$fldName.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($specialValuesByIds);echo'</pre>';}
  3799. }
  3800. echo json_encode($jsonData);
  3801. exit;
  3802. }
  3803. private function sendAjaxData($args) {
  3804. $DBG = ('1' == V::get('DBG', '', $_REQUEST));
  3805. header("Content-type: application/json");
  3806. //sleep(1);// TODO: TEST
  3807. $pageSize = V::get('pageSize', 10, $args, 'int');
  3808. $page = V::get('page', 0, $args, 'int');
  3809. $currSortCol = V::get('currSortCol', '', $args);
  3810. $currSortFlip = V::get('currSortFlip', '', $args);
  3811. if ($page > 0) {
  3812. $page -= 1;
  3813. }
  3814. else {
  3815. }
  3816. $params = array();
  3817. $params['limit'] = $pageSize;
  3818. $params['limitstart'] = $page * $params['limit'];
  3819. $params['order_by'] = ($currSortCol)? $currSortCol : '';
  3820. $params['order_dir'] = $currSortFlip;
  3821. $filters = new stdClass();
  3822. $filters->currSortCol = $currSortCol;
  3823. $filters->currSortFlip = $currSortFlip;
  3824. foreach ($args as $k => $v) {
  3825. if (strlen($k) > 3 && substr($k, 0, 2) == 'f_' && strlen($v) > 0) {// filter prefix
  3826. $params[$k] = $v;
  3827. $filters->{$k} = $v;
  3828. }
  3829. else if (strlen($k) > 4 && substr($k, 0, 3) == 'sf_' && strlen($v) > 0) {// special filter prefix
  3830. $params[$k] = $v;
  3831. $filters->{$k} = $v;
  3832. }
  3833. }
  3834. $this->setFilters($filters);
  3835. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">_dataSource (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($this->_dataSource);echo'</pre>';}
  3836. $vCols = $this->_acl->getVirtualFieldList();
  3837. if (!empty($vCols)) {
  3838. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">vCols (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($vCols);echo'</pre>';}
  3839. }
  3840. Lib::loadClass('Typespecial');
  3841. $total = $this->_dataSource->getTotal($params);
  3842. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">get_total (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($total);echo'</pre>';}
  3843. $items = $this->_dataSource->getItems($params);
  3844. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">items (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($items);echo'</pre>';}
  3845. // TODO: add virtual data by Typespecial
  3846. if (!empty($vCols) && !empty($items)) {
  3847. foreach ($vCols as $vColID => $vCol) {
  3848. $colType = $this->_acl->getFieldTypeById($vColID);
  3849. if ($colType) {
  3850. continue;// pomin Typespecial dla realnych komorek w bazie danych
  3851. }
  3852. $typeSpecial = Typespecial::getInstance($vColID, $vCol);
  3853. if ($typeSpecial) {
  3854. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">Typespecial('.$vColID.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($typeSpecial);echo'</pre>';}
  3855. $ids = array_keys($items);
  3856. $specialValues = $typeSpecial->getValuesByIds($this->_zasobID, $ids);
  3857. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">Typespecial('.$vCol.') specialValues (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($specialValues);echo'</pre>';}
  3858. if (!empty($specialValues)) foreach ($specialValues as $kItemID => $vValues) {
  3859. $tsValue = implode('<br>', $vValues);
  3860. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">Item['.$kItemID.'].'.$vCol.' specialValues (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($items[$kItemID]);echo'</pre>';}
  3861. if (!empty($items[$kItemID]->{$vCol}) && !empty($tsValue)) {
  3862. $items[$kItemID]->{$vCol} .= ": {$tsValue}";
  3863. } else {
  3864. $items[$kItemID]->{$vCol} = $tsValue;
  3865. }
  3866. }
  3867. }
  3868. }
  3869. }
  3870. $visibleCols = $this->_acl->getVisibleFieldList();
  3871. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">visibleCols (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($visibleCols);echo'</pre>';}
  3872. $jsonData = new stdClass();
  3873. $jsonData->total = $total;
  3874. $jsonData->cols = new stdClass();
  3875. $ind = 0;
  3876. foreach ($visibleCols as $fieldID => $col) {
  3877. $ind++;
  3878. $jsonData->cols->{$col} = (object)array('index'=>$ind);
  3879. if ($col == 'ID') {
  3880. // /SE/se-dev/index.php?MENU_INIT=USERS2_MARKETING_EDIT&ARG1=EDIT&ARG1_VAL=31105
  3881. $jsonData->cols->{$col}->format = '<a href="#EDIT/{0}">{0}</a>';
  3882. $jsonData->cols->{$col}->unique = true;
  3883. }
  3884. else if (in_array($col, array('A_STATUS','A_STATUS_CURRENT','A_SERVICES_STATUS_CURRENT'))) {
  3885. $jsonData->cols->{$col}->format = '<div class="cell-A_STATUS-{0}">{0}</div>';
  3886. }
  3887. else if (in_array($col, array('Status'))) {
  3888. // Ahmes problems Status colors
  3889. $jsonData->cols->{$col}->format = '<div class="cell-Status-{0}">{0}</div>';
  3890. }
  3891. else if ($this->_dataSource->isGeomField($col)) {
  3892. $jsonData->cols->{$col}->type = 'geom';
  3893. }
  3894. if ('' !== ($label = $this->_acl->getFieldLabel($fieldID))) {
  3895. $jsonData->cols->{$col}->friendly = $label;
  3896. }
  3897. $colType = $this->_acl->getFieldType($col);
  3898. if ($colType) {// @see MarkTableAjaxFilterColType
  3899. if ($colType['type'] == 'date') {
  3900. //$jsonData->cols->{$col}->type = 'date';// TODO: require datepicker
  3901. }
  3902. } else {// typespecial - no type
  3903. $jsonData->cols->{$col}->type = 'special';
  3904. }
  3905. $typeSpecial = Typespecial::getInstance($fieldID, $col);
  3906. if ($typeSpecial) {
  3907. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">typeSpecial (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($typeSpecial);echo'</pre>';}
  3908. $jsonData->cols->{$col}->_tsRetId = $typeSpecial->getReturnId();
  3909. }
  3910. // @see sendHiddenColsSave
  3911. // $_SESSION['USER_PROFILE'][$this->_zasobID][fld_id] => boolean
  3912. if (isset($_SESSION['USER_PROFILE'][$this->_zasobID])) {
  3913. if (isset($_SESSION['USER_PROFILE'][$this->_zasobID][$fieldID])) {
  3914. if ($_SESSION['USER_PROFILE'][$this->_zasobID][$fieldID] != 1) {
  3915. $jsonData->cols->{$col}->hidden = true;
  3916. }
  3917. }
  3918. }
  3919. }
  3920. $jsonData->rows = array();
  3921. foreach ($items as $vItem) {
  3922. // TODO: hide items without 'R'
  3923. foreach ($visibleCols as $kID => $vCol) {
  3924. // TODO: ID default 'R'
  3925. if (!$this->_acl->isAllowed($kID, 'R', $vItem)) {
  3926. $vItem->{$vCol} = '*****';
  3927. }
  3928. // null => empty string
  3929. if (!isset($vItem->{$vCol}) || (!$vItem->{$vCol} && $vItem->{$vCol} !== '0')) {
  3930. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">isEmptyString['.$vCol.'] (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($vItem->{$vCol});echo'</pre>';}
  3931. $vItem->{$vCol} = '';
  3932. }
  3933. }
  3934. $jsonData->rows[] = $vItem;
  3935. }
  3936. //echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">this->_dataSource (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($this->_dataSource);echo'</pre>';
  3937. //echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">jsonData (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($jsonData);echo'</pre>';
  3938. echo json_encode($jsonData);
  3939. exit;
  3940. }
  3941. private function fixEmptyValueFromUser($fieldID) {// TODO: moved to TableAcl->fixEmptyValueFromUser
  3942. $value = '';
  3943. $type = $this->_acl->getFieldTypeById($fieldID);
  3944. if ($type) {
  3945. if ($type['type'] == 'date') {
  3946. $value = $type['default'];
  3947. }
  3948. // fix bug when field is unique and is null allowed: change empty string to null
  3949. if ($type['null']) {
  3950. $value = 'NULL';
  3951. }
  3952. // fix bug when field is enum and is set to '0': for php '0' is empty
  3953. if (substr($type['type'], 0, 4) == 'enum') {// && $args["f{$fieldID}"] === '0') {
  3954. if (false !== strpos($type['type'], "''")) {
  3955. // enum('', '1','2')
  3956. $value = '';
  3957. } else if (false !== strpos($type['type'], "'0'")) {
  3958. // enum('0', '1','2')
  3959. $value = '0';
  3960. } else {
  3961. $value = $type['default'];
  3962. }
  3963. }
  3964. }
  3965. return $value;
  3966. }
  3967. /**
  3968. * set hidden cols in $_SESSION['USER_PROFILE'][$this->_zasobID];
  3969. * $_SESSION['USER_PROFILE'][$this->_zasobID][fld_id] => boolean
  3970. */
  3971. private function sendHiddenColsSave($args) {
  3972. if (empty($_POST)) {
  3973. exit;
  3974. }
  3975. Lib::loadClass('UserProfile');
  3976. UserProfile::load();
  3977. // clean up old, wrong values
  3978. if (array_key_exists("{$this->_tbl}_COLUMN", $_SESSION['USER_PROFILE'])) {
  3979. unset($_SESSION['USER_PROFILE']["{$this->_tbl}_COLUMN"]);
  3980. }
  3981. $colVis = array();
  3982. if (array_key_exists($this->_zasobID, $_SESSION['USER_PROFILE'])) {
  3983. $colVis = $_SESSION['USER_PROFILE'][$this->_zasobID];
  3984. }
  3985. $fields = $this->_acl->getFields();
  3986. foreach ($fields as $kFldId => $vFld) {
  3987. $vFldName = $vFld['name'];
  3988. if (isset($_POST[$vFldName])) {
  3989. if ($_POST[$vFldName] == 'SHOW') {
  3990. $colVis[$kFldId] = 1;
  3991. } else if ($_POST[$vFldName] == 'HIDE') {
  3992. $colVis[$kFldId] = 0;
  3993. }
  3994. }
  3995. }
  3996. $_SESSION['USER_PROFILE'][$this->_zasobID] = $colVis;
  3997. UserProfile::save();
  3998. }
  3999. private function sendTheGeomSave($args) {
  4000. $id = V::get('ID', 0, $args, 'int');
  4001. $polygon = V::get('polygon', 0, $args);
  4002. $geomFieldName = 'the_geom';
  4003. if ($id <= 0) {
  4004. header('HTTP/1.0 404 Not Found');
  4005. echo "Wrong param ID";
  4006. exit;
  4007. }
  4008. // 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)))
  4009. $tblName = $this->_acl->getName();
  4010. $db = DB::getDB();
  4011. $record = $db->get_by_id($tblName, $id);
  4012. if (!$this->_acl->canWriteRecord($record) && !$this->_acl->hasPermSuperWrite()) {
  4013. header('HTTP/1.0 403.3 - Write access forbidden');
  4014. echo "Brak dostępu do rekordu";
  4015. exit;
  4016. }
  4017. $theGeomFieldId = $this->_acl->getFieldIdByName($geomFieldName);
  4018. if (!$this->_acl->isAllowed($theGeomFieldId, 'W', $record)) {
  4019. header('HTTP/1.0 403.3 - Write access forbidden');
  4020. echo "Brak dostępu do zapisu dla pola {$geomFieldName}";
  4021. exit;
  4022. }
  4023. $sqlObj = new stdClass();
  4024. $sqlObj->{$geomFieldName} = "GeomFromText('{$polygon}')";
  4025. $sqlObj->ID = $id;
  4026. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;"> (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sqlObj);echo'</pre>';}
  4027. $ret = $db->UPDATE_OBJ($tblName, $sqlObj);
  4028. if ($ret > 0) {
  4029. echo '<div class="alert alert-success">';
  4030. echo "Rekord zapisany pomyślnie";//"Record saved successfully";
  4031. echo '</div>';
  4032. } else if ($ret == 0) {
  4033. echo '<div class="alert alert-info">';
  4034. echo "Nie wprowadzono żadnych zmian";
  4035. echo '</div>';
  4036. } else {
  4037. header('HTTP/1.0 404 Not Found');
  4038. echo '<div class="alert alert-error">';
  4039. echo '<h4>' . "Wystąpiły błędy!" . '</h4>';
  4040. if ($db->has_errors()) {
  4041. $errors = $db->get_errors();
  4042. echo implode('<br>', $errors);
  4043. }
  4044. echo '</div>';
  4045. }
  4046. exit;
  4047. }
  4048. }