TableAjax.php 158 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552
  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. $defaultAclGroup = User::getDefaultAclGroup();
  2673. if ($defaultAclGroup) {
  2674. $forceFilterInit['A_ADM_COMPANY'] = $defaultAclGroup;
  2675. $forceFilterInit['A_CLASSIFIED'] = $defaultAclGroup;
  2676. }
  2677. foreach ($_GET as $k => $v) {
  2678. if (strlen($k) > 4 && substr($k, 0, 3) == 'ff_' && !empty($v)) {// force filter prefix
  2679. $fldName = substr($k, 3);
  2680. $forceFilterInit[$fldName] = $v;
  2681. }
  2682. }
  2683. $fieldsList = $this->_acl->getFields();
  2684. foreach ($fieldsList as $kID => $vCol) {
  2685. $defaultValue = '';
  2686. if ($vCol['name'] == 'ID') {
  2687. unset($fieldsList[$kID]);
  2688. continue;
  2689. }
  2690. if (!empty($forceFilterInit[$vCol['name']])) {
  2691. $defaultValue = $forceFilterInit[$vCol['name']];
  2692. }
  2693. // TODO: read from session cache
  2694. $cols[$kID] = V::get("f{$kID}", $defaultValue, $_POST);
  2695. $fieldsList[$kID]['label'] = (!empty($vCol['label']))? $vCol['label'] : $vCol['name'];
  2696. }
  2697. Lib::loadClass('SE_Layout');
  2698. ?>
  2699. <div class="container AjaxFrmHorizontalEdit">
  2700. <form class="form-horizontal" action="" method="post" id="CREATE_FRM_<?php echo $this->_htmlID; ?>">
  2701. <fieldset>
  2702. <legend>Dodaj nowy rekord</legend>
  2703. <?php $tabindex = 0; foreach ($fieldsList as $kID => $vCol) : ?>
  2704. <?php if ($this->_acl->isAllowed($kID, 'C')) : ?>
  2705. <div class="control-group">
  2706. <label class="control-label" for="<?php echo "f{$kID}"; ?>"><?php echo $vCol['label']; ?>
  2707. <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>
  2708. <?php $perms = $this->_acl->getFieldPerms($kID); SE_Layout::hotKeyDBG($perms); ?>
  2709. </label>
  2710. <div class="controls">
  2711. <?php
  2712. $fieldParams = array('appendBack'=>true, 'tabindex'=>(++$tabindex), 'maxGrid'=>8);
  2713. echo $this->_acl->showFormItem('C', $kID, "f{$kID}", $cols[$kID], $fieldParams);
  2714. ?>
  2715. </div>
  2716. </div>
  2717. <?php endif; ?>
  2718. <?php endforeach; ?>
  2719. <div class="control-group">
  2720. <div class="controls">
  2721. <button type="submit" class="btn btn-primary" tabindex="<?php echo (++$tabindex); ?>">Dodaj rekord</button>
  2722. </div>
  2723. </div>
  2724. </fieldset>
  2725. </form>
  2726. </div>
  2727. <script>
  2728. jQuery(document).ready(function(){
  2729. jQuery('textarea').autosize();
  2730. jQuery('.frm-help').popover({trigger:'hover'});
  2731. jQuery('#CREATE_FRM_<?php echo $this->_htmlID; ?>').on('submit', function(){
  2732. var data = jQuery(this).serialize();
  2733. var taskContLast = jQuery('#<?php echo $this->_htmlID; ?>_task'),
  2734. taskCont = taskContLast.parent();
  2735. taskContLast.fadeOut('slow');
  2736. var taskCnt = jQuery('<div id="<?php echo $this->_htmlID . '_task'; ?>" class="AjaxTableTaskCnt AjaxTable-loading"></div>').appendTo(taskCont);
  2737. 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);
  2738. jQuery.ajax({
  2739. url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=CREATE_SAVE',
  2740. type: 'POST',
  2741. dataType: 'json',
  2742. data: data,
  2743. async: true,
  2744. success: function(data) {
  2745. //console.log('success L.<?php echo __LINE__; ?> data', data);
  2746. },
  2747. error: function(xhr) {
  2748. //console.log('error L.<?php echo __LINE__; ?> xhr', xhr);
  2749. },
  2750. complete: function(xhr) {
  2751. if (xhr.responseJSON) {
  2752. var data = xhr.responseJSON;
  2753. } else {
  2754. // TODO: error
  2755. }
  2756. taskCnt.removeClass('AjaxTable-loading');
  2757. taskCnt.empty();
  2758. if (typeof data == 'object') {
  2759. if (data.type == 'ERROR') {
  2760. var out = '<div class="container">' +
  2761. '<div class="alert alert-error">' +
  2762. '<h4>Wystąpiły błędy!</h4>' + data.msg +
  2763. '</div>';
  2764. out += '<div class="breadcrumb">' +
  2765. ' <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>' +
  2766. '</div>' +
  2767. '</div>';
  2768. jQuery(out).appendTo(taskCnt);
  2769. var taskContLastNode = taskContLast
  2770. , taskCntNode = taskCnt;
  2771. taskCnt.find('.create-fix').click(function(){
  2772. taskCntNode.remove();
  2773. taskContLastNode.fadeIn('slow');
  2774. return false;
  2775. });
  2776. }
  2777. else if (data.type == 'SUCCESS') {
  2778. var msg = '';
  2779. if (data.id && data.id > 0) {
  2780. msg = 'Utworzono pomyślnie rekord: ID = ' + data.id;
  2781. } else if (data.msg) {
  2782. msg = data.msg;
  2783. } else {
  2784. msg = 'OK';
  2785. }
  2786. var out = '<div class="container">';
  2787. out += '<div class="alert alert-success">' + msg + '</div>';
  2788. out += '<div class="breadcrumb">' +
  2789. ' <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>' +
  2790. '<span class="divider">/</span>' +
  2791. ' <a href="#EDIT/' + data.id + '" class="btn btn-link btn-small"> <i class="icon-pencil"></i> Edytuj rekord ' + data.id + '</a>' +
  2792. '<span class="divider">/</span>' +
  2793. ' <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>' +
  2794. '</div>';
  2795. out += '</div>';
  2796. jQuery(out).appendTo(taskCnt);
  2797. }
  2798. }
  2799. }
  2800. });
  2801. return false;
  2802. });
  2803. });
  2804. </script>
  2805. <?php
  2806. exit;
  2807. }
  2808. private function sendAjaxCreateSave($args) {
  2809. header("Content-type: application/json");
  2810. $DBG = ('1' == V::get('DBG', '', $_REQUEST));
  2811. sleep(1);// TODO: RMME DBG loading
  2812. 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>';}
  2813. 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>';}
  2814. $dbID = $this->_acl->getDB();
  2815. $db = DB::getDB($dbID);
  2816. if (!$db) {
  2817. header('HTTP/1.0 406 Not Acceptable');
  2818. echo '{"type":"ERROR", "msg": "' . "Błąd połączenia z bazą danych!" . '"}';
  2819. exit;
  2820. }
  2821. $tblName = $this->_acl->getName();
  2822. $sqlObj = new stdClass();
  2823. $fields = $this->_acl->getFields();
  2824. 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>';}
  2825. foreach ($fields as $kID => $vField) {
  2826. if (!$this->_acl->isAllowed($kID, 'C')) {
  2827. continue;
  2828. }
  2829. if (array_key_exists("f{$kID}", $args)) {
  2830. $sqlObj->{$vField['name']} = $args["f{$kID}"];
  2831. if (empty($args["f{$kID}"]) && strlen($args["f{$kID}"]) == 0) {// fix bug in input type date and value="0000-00-00"
  2832. $sqlObj->{$vField['name']} = $this->_acl->fixEmptyValueFromUser($kID);
  2833. }
  2834. }
  2835. }
  2836. 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>';}
  2837. $retID = $db->ADD_NEW_OBJ($tblName, $sqlObj);
  2838. $retJson = new stdClass();
  2839. $retJson->type = '';
  2840. $retJson->msg = '';
  2841. if ($retID > 0) {
  2842. $retJson->type = 'SUCCESS';
  2843. $retJson->msg = "Utworzono pomyślnie rekord: ID = {$retID}";
  2844. $retJson->id = $retID;
  2845. } else {
  2846. header('HTTP/1.0 404 Not Found');
  2847. $retJson->type = 'ERROR';
  2848. $retJson->msg = "";
  2849. if ($db->has_errors()) {
  2850. $outArr = array();
  2851. $errorsSql = $db->get_errors();
  2852. foreach ($errorsSql as $vErr) {
  2853. if (substr($vErr, 0, 18) == 'SQL QUERY FAILED: ') {
  2854. $vErr = substr($vErr, 18);
  2855. // Duplicate entry '123456-1' for key 'P_NIP'
  2856. if (substr($vErr, 0, 16) == 'Duplicate entry ') {
  2857. }
  2858. }
  2859. $outArr[] = $vErr;
  2860. }
  2861. $retJson->msg .= implode('<br>', $outArr);
  2862. }
  2863. }
  2864. echo json_encode($retJson);
  2865. exit;
  2866. }
  2867. private function sendAjaxCopy($id, $args) {
  2868. header("Content-type: text/plain");
  2869. sleep(1);// TODO: RMME DBG loading
  2870. $dbID = $this->_acl->getDB();
  2871. $db = DB::getDB($dbID);
  2872. if (!$db) {
  2873. header('HTTP/1.0 406 Not Acceptable');
  2874. exit;
  2875. }
  2876. $row = $this->_dataSource->getItem($id);
  2877. if (!$row) {
  2878. header('HTTP/1.0 404 Not Found');
  2879. echo "404: No item ID({$rowID})";
  2880. exit;
  2881. }
  2882. $tblName = $this->_acl->getName();
  2883. $types = $this->_acl->getTypes();
  2884. $uniqKeys = $this->_acl->getUniqueKeys();
  2885. $sqlObj = new stdClass();
  2886. foreach ($types as $kName => $vType) {
  2887. if ($kName == 'ID') {
  2888. continue;
  2889. } else if (in_array($kName, array('A_RECORD_UPDATE_AUTHOR','A_RECORD_UPDATE_DATE'))) {
  2890. continue;
  2891. }
  2892. $sqlObj->{$kName} = V::get($kName, '', $row);
  2893. if (in_array($kName, $uniqKeys)) {
  2894. $sqlObj->{$kName} .= '?';
  2895. }
  2896. }
  2897. $ret = $db->ADD_NEW_OBJ($tblName, $sqlObj);
  2898. if ($ret > 0) {
  2899. echo '<div class="alert alert-success">';
  2900. echo '<button type="button" class="close" data-dismiss="alert"><i class="icon-remove"></i></button>';
  2901. echo "Rekord skopiowany pomyślnie - utworzono rekord nr {$ret}";//"Record saved successfully";
  2902. echo '</div>';
  2903. } else if ($ret == 0) {
  2904. echo '<div class="alert alert-error">';
  2905. echo '<button type="button" class="close" data-dismiss="alert"><i class="icon-remove"></i></button>';
  2906. echo "Nie udało się skopiować rekordu";
  2907. if ($db->has_errors()) {
  2908. echo '<br>' . implode("<br>", $db->get_errors());
  2909. }
  2910. echo '</div>';
  2911. } else {
  2912. echo '<div class="alert alert-error">';
  2913. echo '<button type="button" class="close" data-dismiss="alert"><i class="icon-remove"></i></button>';
  2914. echo "Błąd bazy danych";
  2915. echo '</div>';
  2916. }
  2917. exit;
  2918. }
  2919. private function sendAjaxHistory($id, $args) {
  2920. header("Content-type: text/plain");
  2921. $record = $this->_dataSource->getItem($id);
  2922. if (!$record) {
  2923. header('HTTP/1.0 404 Not Found');
  2924. echo "404: No item ID({$rowID})";
  2925. exit;
  2926. }
  2927. $visibleCols = $this->_acl->getRealFieldList();
  2928. $rowsHist = $this->_dataSource->getHistItems($id);
  2929. $rowFunctionsOut = $this->_showRowFunctions($record->ID, array('hist', 'cp'), true);
  2930. $visibleColsWithIds = array();
  2931. $visibleColsLabels = array();
  2932. foreach ($visibleCols as $vColName) {
  2933. $fldId = $this->_acl->getFieldIdByName($vColName);
  2934. if ($fldId) {
  2935. $visibleColsWithIds[$fldId] = $vColName;
  2936. $label = $this->_acl->getFieldLabel($fldId);
  2937. $label = (!$label)? $vColName : '<span title="' . "[{$fldId}] {$vColName}" . '">' . $label . '</span>';
  2938. $visibleColsLabels[$fldId] = $label;
  2939. }
  2940. }
  2941. ?>
  2942. <fieldset>
  2943. <legend>Historia rekordu Nr <?php echo $id; ?>
  2944. <span class="pull-right valign-btns-bottom"><?php echo $rowFunctionsOut; ?></span>
  2945. </legend>
  2946. </fieldset>
  2947. <?php if (empty($rowsHist)) : ?>
  2948. <div class="alert alert-info">
  2949. <h4>Brak danych</h4>
  2950. </div>
  2951. <?php else: ?>
  2952. <table class="table table-striped table-hover table-bordered table-condensed AjaxTableHist">
  2953. <thead>
  2954. <tr>
  2955. <th>Data</th>
  2956. <th>User</th>
  2957. <th>Zmiany</th>
  2958. </tr>
  2959. </thead>
  2960. <tbody>
  2961. <?php foreach ($rowsHist as $row) : ?>
  2962. <tr>
  2963. <td style="white-space:nowrap"><?php echo $row->_created; ?></td>
  2964. <td><?php echo $row->_author; ?></td>
  2965. <td>
  2966. <?php foreach ($visibleColsWithIds as $fldId => $colName) : ?>
  2967. <?php if (in_array($colName, array('ID', 'A_RECORD_UPDATE_DATE', 'A_RECORD_UPDATE_AUTHOR', 'A_RECORD_CREATE_DATE', 'A_RECORD_CREATE_AUTHOR'))) continue; ?>
  2968. <?php if ($row->$colName == 'N/S;') continue; ?>
  2969. <p><em><?php echo $visibleColsLabels[$fldId]; ?></em>:
  2970. <?php if ($this->_acl->isAllowed($fldId, 'R', $record)) : ?>
  2971. <?php echo $row->$colName; ?>
  2972. <?php else : ?>
  2973. <span title="Brak uprawnień do odczytu tego pola">*****</span>
  2974. <?php endif; ?>
  2975. </p>
  2976. <?php endforeach; ?>
  2977. </td>
  2978. </tr>
  2979. <?php endforeach; ?>
  2980. </tbody>
  2981. </table>
  2982. <div style="overflow-x:scroll; overflow-y:visible; padding-bottom:1px; margin:10px 0;">
  2983. <table class="table table-striped table-hover table-bordered table-condensed AjaxTableHist">
  2984. <thead>
  2985. <tr>
  2986. <?php foreach ($visibleColsWithIds as $fldId => $colName) : ?>
  2987. <th><?php echo str_replace('_', ' ', $visibleColsLabels[$fldId]); ?></th>
  2988. <?php endforeach; ?>
  2989. </tr>
  2990. </thead>
  2991. <tbody>
  2992. <?php foreach ($rowsHist as $row) : ?>
  2993. <tr>
  2994. <?php foreach ($visibleColsWithIds as $fldId => $colName) : ?>
  2995. <td>
  2996. <?php if ($row->$colName == 'N/S;') : ?>
  2997. <em>N/S;</em>
  2998. <?php elseif ($this->_acl->isAllowed($fldId, 'R', $record)) : ?>
  2999. <?php echo $row->$colName; ?>
  3000. <?php else : ?>
  3001. <span title="Brak uprawnień do odczytu tego pola">*****</span>
  3002. <?php endif; ?>
  3003. </td>
  3004. <?php endforeach; ?>
  3005. </tr>
  3006. <?php endforeach; ?>
  3007. </tbody>
  3008. </table>
  3009. </div>
  3010. <?php endif; ?>
  3011. <?php
  3012. exit;
  3013. }
  3014. /**
  3015. * Returns text/plain with type at first line: ERROR, WARNING, INFO, SUCCESS
  3016. */
  3017. private function sendAjaxFilesUpload($id, $args) {
  3018. // http://www.sitepoint.com/html5-ajax-file-upload/
  3019. //$ajaxFileName = (isset($_SERVER['HTTP_X_FILENAME']) ? $_SERVER['HTTP_X_FILENAME'] : false);
  3020. //header("Content-type: text/plain");
  3021. header("Content-type: application/json");
  3022. $DBG = ('1' == V::get('DBG', '', $_REQUEST));
  3023. $dbID = $this->_acl->getDB();
  3024. $db = DB::getDB($dbID);
  3025. if (!$db) {
  3026. header('HTTP/1.0 406 Not Acceptable');
  3027. echo '{"type":"ERROR", "string": "No DB (' . $dbID . ')"}';
  3028. exit;
  3029. }
  3030. $record = $this->_dataSource->getItem($id);
  3031. if (!$record) {
  3032. header('HTTP/1.0 404 Not Found');
  3033. echo '{"type":"ERROR", "string": "No item ID(' . $rowID . ')"}';
  3034. exit;
  3035. }
  3036. $tblName = $this->_acl->getName();
  3037. $confTblName = "{$tblName}_COLUMN";
  3038. Lib::loadClass('FoldersConfig');
  3039. $folderConfAll = FoldersConfig::getRawData();
  3040. if (!FoldersConfig::hasConfig($confTblName)) {
  3041. header('HTTP/1.0 404 Not Found');
  3042. echo '{"type":"ERROR", "string": "Brak danych konfiguracyjnych(' . $tblName . ')"}';
  3043. exit;
  3044. }
  3045. $folderConf = FoldersConfig::getAll($confTblName);
  3046. Lib::loadClass('FileUploader');
  3047. $uploader = new FileUploader($confTblName, $record);
  3048. $errMsg = '';
  3049. if (!$uploader->setConfig($folderConf, $errMsg)) {
  3050. header('HTTP/1.0 404 Not Found');
  3051. echo '{"type":"ERROR", "string": "Błąd danych konfiguracyjnych(' . $tblName . ') <br>' . $errMsg . '"}';
  3052. exit;
  3053. }
  3054. $uploader->findFolder();
  3055. $errorMsg = '';
  3056. if (!empty($_POST['SCANS_COLUMN_ADD'])) {
  3057. $uploaded = $uploader->tryMoveFromScanAjax($errorMsg);
  3058. }
  3059. else {
  3060. $uploaded = $uploader->tryUploadAjax($errorMsg);
  3061. }
  3062. /*
  3063. //$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> ";
  3064. // 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);
  3065. // 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);
  3066. */
  3067. if ($uploaded) {
  3068. $uploadedFileName = '';
  3069. $uploadedFile = $uploader->getLastUploadedFile();
  3070. if ($uploadedFile) {
  3071. $uploadedFileName = explode('/', $uploadedFile);
  3072. $uploadedFileName = end($uploadedFileName);
  3073. }
  3074. echo '{"type":"SUCCESS", "string": "Plik został poprawnie wgrany do odpowiedniego katalogu '.$uploadedFileName.'"}';
  3075. if (!empty($uploadedFileName)) {
  3076. $sqlObj = new stdClass();
  3077. $sqlObj->ID = $record->ID;
  3078. $sqlObj->M_DIST_FILES = "Wgrano plik {$uploadedFileName}";
  3079. $db->UPDATE_OBJ($this->_tbl, $sqlObj);
  3080. }
  3081. } else {
  3082. echo '{"type":"ERROR", "string": "' . $errorMsg . '"}';
  3083. }
  3084. exit;
  3085. }
  3086. private function sendAjaxFileRemove($id, $args) {
  3087. header("Content-type: application/json");
  3088. $DBG = ('1' == V::get('DBG', '', $_REQUEST));
  3089. if (empty($_POST['filename'])) {
  3090. echo '{"type":"ERROR", "string": "Nie wybrano pliku do usunięcia"}';
  3091. exit;
  3092. }
  3093. $dbID = $this->_acl->getDB();
  3094. $db = DB::getDB($dbID);
  3095. if (!$db) {
  3096. header('HTTP/1.0 406 Not Acceptable');
  3097. echo '{"type":"ERROR", "string": "No DB (' . $dbID . ')"}';
  3098. exit;
  3099. }
  3100. $record = $this->_dataSource->getItem($id);
  3101. if (!$record) {
  3102. header('HTTP/1.0 404 Not Found');
  3103. echo '{"type":"ERROR", "string": "No item ID(' . $rowID . ')"}';
  3104. exit;
  3105. }
  3106. $tblName = $this->_acl->getName();
  3107. $confTblName = "{$tblName}_COLUMN";
  3108. Lib::loadClass('FoldersConfig');
  3109. $folderConfAll = FoldersConfig::getRawData();
  3110. if (!FoldersConfig::hasConfig($confTblName)) {
  3111. header('HTTP/1.0 404 Not Found');
  3112. echo '{"type":"ERROR", "string": "Brak danych konfiguracyjnych (' . $tblName . ')"}';
  3113. exit;
  3114. }
  3115. $folderConf = FoldersConfig::getAll($confTblName);
  3116. Lib::loadClass('FileUploader');
  3117. $uploader = new FileUploader($confTblName, $record);
  3118. if (!$uploader->setConfig($folderConf)) {
  3119. header('HTTP/1.0 404 Not Found');
  3120. echo '{"type":"ERROR", "string": "Błąd danych konfiguracyjnych (' . $tblName . ')"}';
  3121. exit;
  3122. }
  3123. $uploader->findFolder();
  3124. $errorMsg = '';
  3125. $removed = $uploader->tryRemoveFromAjax($_POST['filename'], $errorMsg);
  3126. if (!$removed) {
  3127. echo '{"type":"ERROR", "string": "{' . $errorMsg . '}"}';
  3128. } else {
  3129. echo '{"type":"SUCCESS","string":"Plik został poprawnie usunięty"}';
  3130. }
  3131. exit;
  3132. }
  3133. private function sendAjaxFilesList($id, $args) {
  3134. header("Content-type: application/json");
  3135. $dbID = $this->_acl->getDB();
  3136. $db = DB::getDB($dbID);
  3137. if (!$db) {
  3138. header('HTTP/1.0 406 Not Acceptable');
  3139. echo '{"type":"ERROR", "string": "No DB (' . $dbID . ')"}';
  3140. exit;
  3141. }
  3142. $record = $this->_dataSource->getItem($id);
  3143. if (!$record) {
  3144. header('HTTP/1.0 404 Not Found');
  3145. echo '{"type":"ERROR", "string": "No item ID(' . $rowID . ')"}';
  3146. exit;
  3147. }
  3148. $tblName = $this->_acl->getName();
  3149. $confTblName = "{$tblName}_COLUMN";
  3150. Lib::loadClass('FoldersConfig');
  3151. $folderConfAll = FoldersConfig::getRawData();
  3152. if (!FoldersConfig::hasConfig($confTblName)) {
  3153. header('HTTP/1.0 404 Not Found');
  3154. echo '{"type":"ERROR", "string": "Brak danych konfiguracyjnych (' . $tblName . ')"}';
  3155. exit;
  3156. }
  3157. $folderConf = FoldersConfig::getAll($confTblName);
  3158. Lib::loadClass('FileUploader');
  3159. $uploader = new FileUploader($confTblName, $record);
  3160. if (!$uploader->setConfig($folderConf)) {
  3161. header('HTTP/1.0 404 Not Found');
  3162. echo '{"type":"ERROR", "string": "Błąd danych konfiguracyjnych (' . $tblName . ')"}';
  3163. exit;
  3164. }
  3165. $uploader->findFolder();
  3166. $mainFolder = $uploader->getDestFolder();
  3167. $files = $uploader->getFilesFromFolder($mainFolder, false, true);
  3168. $localPath = $uploader->getLocalPath();
  3169. $folderWeb = $uploader->getFolderWeb();
  3170. $jsonFiles = $this->convertFileListToJson($files, $folderWeb, $localPath, $mainFolder);
  3171. echo json_encode($jsonFiles);
  3172. exit;
  3173. }
  3174. private function sendAjaxFilesConnTblList($id, $args) {
  3175. header("Content-type: application/json");
  3176. $DBG = ('1' == V::get('DBG', '', $_REQUEST));
  3177. $dbID = $this->_acl->getDB();
  3178. $db = DB::getDB($dbID);
  3179. if (!$db) {
  3180. header('HTTP/1.0 406 Not Acceptable');
  3181. echo 'No DB (' . $dbID . ')';
  3182. exit;
  3183. }
  3184. $record = $this->_dataSource->getItem($id);
  3185. if (!$record) {
  3186. header('HTTP/1.0 404 Not Found');
  3187. echo 'No item ID(' . $rowID . ')';
  3188. exit;
  3189. }
  3190. $connTblName = '';
  3191. $connTblID = V::get('connTblID', 0, $_REQUEST, 'int');
  3192. if ($connTblID <= 0) {
  3193. header('HTTP/1.0 406 Not Acceptable');
  3194. echo 'No conn Table ID';
  3195. exit;
  3196. }
  3197. $connTblTypespecials = $this->getConnectedTblTypespecials($connTblID);
  3198. if (empty($connTblTypespecials)) {
  3199. header('HTTP/1.0 406 Not Acceptable');
  3200. echo "No conn Table (ID={$connTblID})";
  3201. exit;
  3202. }
  3203. 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>';}
  3204. if(1) {
  3205. header('HTTP/1.0 404 Not Found');
  3206. echo 'TODO: ...';
  3207. exit;
  3208. }
  3209. $tblName = $this->_acl->getName();
  3210. $confTblName = "{$tblName}_COLUMN";
  3211. Lib::loadClass('FoldersConfig');
  3212. $folderConfAll = FoldersConfig::getRawData();
  3213. if (!FoldersConfig::hasConfig($confTblName)) {
  3214. header('HTTP/1.0 404 Not Found');
  3215. echo '{"type":"ERROR", "string": "Brak danych konfiguracyjnych (' . $tblName . ')"}';
  3216. exit;
  3217. }
  3218. $folderConf = FoldersConfig::getAll($confTblName);
  3219. Lib::loadClass('FileUploader');
  3220. $uploader = new FileUploader($confTblName, $record);
  3221. if (!$uploader->setConfig($folderConf)) {
  3222. header('HTTP/1.0 404 Not Found');
  3223. echo '{"type":"ERROR", "string": "Błąd danych konfiguracyjnych (' . $tblName . ')"}';
  3224. exit;
  3225. }
  3226. $uploader->findFolder();
  3227. $mainFolder = $uploader->getDestFolder();
  3228. $files = $uploader->getFilesFromFolder($mainFolder, false, true);
  3229. $localPath = $uploader->getLocalPath();
  3230. $folderWeb = $uploader->getFolderWeb();
  3231. $jsonFiles = $this->convertFileListToJson($files, $folderWeb, $localPath, $mainFolder);
  3232. echo json_encode($jsonFiles);
  3233. exit;
  3234. }
  3235. public function convertFileListToJson($files, $folderWeb, $localPath, $mainFolder) {
  3236. sort($files);
  3237. $jsonFiles = array();
  3238. foreach ($files as $vFilePath) {
  3239. $file = new stdClass();
  3240. $file->name = str_replace("{$localPath}/{$mainFolder}/", '', $vFilePath);
  3241. //$file->name = explode('/', $vFilePath);
  3242. //$file->name = end($file->name);
  3243. $file->size = filesize($vFilePath);
  3244. $file->sizeStr = round($file->size, 2) . "B";
  3245. if ($file->size > 1024 * 1024) {
  3246. $file->sizeStr = round(($file->size / (1024 * 1024)), 2) . "M";
  3247. } else if ($file->size > 1024) {
  3248. $file->sizeStr = round(($file->size / 1024), 2) . "K";
  3249. }
  3250. $file->type = '';
  3251. $file->created = date("Y-m-d H:i:s", filectime($vFilePath));
  3252. $file->web = str_replace($localPath, $folderWeb, $vFilePath);
  3253. $jsonFiles[] = $file;
  3254. }
  3255. return $jsonFiles;
  3256. }
  3257. private function getConnectedTables() {
  3258. $connTbls = array();
  3259. return $connTbls;// TODO: OFF - hardlinki tworzone w bash_sync_perms.php
  3260. $fields = $this->_acl->getVisibleFieldList();
  3261. if (!empty($fields)) {
  3262. Lib::loadClass('Typespecial');
  3263. foreach ($fields as $vColID => $vCol) {
  3264. $typeSpecial = Typespecial::getInstance($vColID);
  3265. if ($typeSpecial) {
  3266. $tsConnTbls = $typeSpecial->getTblAliasList();
  3267. if (!empty($tsConnTbls)) {
  3268. foreach ($tsConnTbls as $kID => $vName) {
  3269. $connTbls[$kID] = $vName;
  3270. }
  3271. }
  3272. }
  3273. }
  3274. }
  3275. return $connTbls;
  3276. }
  3277. private function getConnectedTblTypespecials($connTblID) {
  3278. $connTblTypespecials = array();
  3279. $fields = $this->_acl->getVisibleFieldList();
  3280. if (!empty($fields)) {
  3281. Lib::loadClass('Typespecial');
  3282. foreach ($fields as $vColID => $vCol) {
  3283. $typeSpecial = Typespecial::getInstance($vColID);
  3284. if ($typeSpecial) {
  3285. $tsConnTbls = $typeSpecial->getTblAliasList();
  3286. if (array_key_exists($connTblID, $tsConnTbls)) {
  3287. $connTblTypespecials[] = $typeSpecial;
  3288. }
  3289. }
  3290. }
  3291. }
  3292. return $connTblTypespecials;
  3293. }
  3294. private function sendAjaxFiles($id, $args) {
  3295. header("Content-type: text/plain");
  3296. $DBG = ('1' == V::get('DBG', '', $_REQUEST));
  3297. $dbID = $this->_acl->getDB();
  3298. $db = DB::getDB($dbID);
  3299. if (!$db) {
  3300. header('HTTP/1.0 406 Not Acceptable');
  3301. exit;
  3302. }
  3303. $record = $this->_dataSource->getItem($id);
  3304. if (!$record) {
  3305. header('HTTP/1.0 404 Not Found');
  3306. echo "404: No item ID({$rowID})";
  3307. exit;
  3308. }
  3309. $tblName = $this->_acl->getName();
  3310. $confTblName = "{$tblName}_COLUMN";
  3311. Lib::loadClass('FoldersConfig');
  3312. $folderConfAll = FoldersConfig::getRawData();
  3313. if (!FoldersConfig::hasConfig($confTblName)) {
  3314. header('HTTP/1.0 404 Not Found');
  3315. echo "Brak danych konfiguracyjnych";
  3316. exit;
  3317. }
  3318. $folderConf = FoldersConfig::getAll($confTblName);
  3319. //echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">$folderConf (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($folderConf);echo'</pre>';
  3320. Lib::loadClass('FileUploader');
  3321. $uploader = new FileUploader($confTblName, $record);
  3322. $errMsg = '';
  3323. if (!$uploader->setConfig($folderConf, $errMsg)) {
  3324. header('HTTP/1.0 404 Not Found');
  3325. echo "Błąd danych konfiguracyjnych ({$tblName})";
  3326. echo '<br>' . "\n" . $errMsg;
  3327. exit;
  3328. }
  3329. $uploader->findFolder();
  3330. 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>'; }
  3331. $mainFolder = $uploader->getDestFolder();
  3332. 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>'; }
  3333. $files = $uploader->getFilesFromFolder($mainFolder, false, true);
  3334. 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>'; }
  3335. $sharePoint = V::get('share_point', null, $folderConf);
  3336. if ($sharePoint) {
  3337. $sharePoint = FoldersConfig::getNfsOsPath() . "{$sharePoint}/{$mainFolder}";
  3338. }
  3339. $localPath = $uploader->getLocalPath();
  3340. $folderWeb = $uploader->getFolderWeb();
  3341. $jsonFiles = $this->convertFileListToJson($files, $folderWeb, $localPath, $mainFolder);
  3342. 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>'; }
  3343. $folderSkanyConf = FoldersConfig::getAll('SCANS_COLUMN');
  3344. $skanyLocalPath = V::get('mount_point', null, $folderSkanyConf);
  3345. $skanySharePoint = V::get('share_point', null, $folderSkanyConf);
  3346. $skanyFolderWeb = V::get('www_share_point', null, $folderSkanyConf);
  3347. $skanyFiles = $uploader->getFilesFromSkany($folderSkanyConf, false);
  3348. sort($skanyFiles);
  3349. $fileTypes = FoldersConfig::getAll('m_dist_files_types');
  3350. $rowFunctionsOut = $this->_showRowFunctions($record->ID, array('files', 'cp'), true);
  3351. ?>
  3352. <script src="stuff/jquery.form.js"></script>
  3353. <div class="container">
  3354. <h4 style="margin:20px 0 3px 0;">Pliki w katalogu
  3355. <?php if ($sharePoint) : ?>
  3356. <a href="<?php echo $sharePoint; ?>"><code><?php echo $mainFolder; ?></code></a>
  3357. <?php else : ?>
  3358. <code><?php echo $mainFolder; ?></code>
  3359. <?php endif; ?>
  3360. <span class="pull-right valign-btns-bottom"><?php echo $rowFunctionsOut; ?></span>
  3361. </h4>
  3362. <div style="max-height:180px; overflow:auto; border-bottom:1px solid #ddd;">
  3363. <table class="table table-bordered table-hover">
  3364. <colgroup>
  3365. <col style="">
  3366. <col style="width:30px;">
  3367. <?php if ($sharePoint) : ?>
  3368. <col style="width:30px;">
  3369. <?php endif; ?>
  3370. <col style="width:80px;">
  3371. <col style="width:140px;">
  3372. </colgroup>
  3373. <tbody id="FILES_LIST_<?php echo $this->_htmlID; ?>">
  3374. <?php if (empty($mainFolder)) : ?>
  3375. <tr>
  3376. <td colspan="5">
  3377. <div class="alert alert-warning">
  3378. <h4>Brak folderu!</h4>
  3379. Folder dla tego rekordu nie został utworzony.
  3380. </div>
  3381. </td>
  3382. </tr>
  3383. <?php elseif (empty($files)) : ?>
  3384. <tr>
  3385. <td colspan="5">
  3386. <div class="alert alert-info">
  3387. <h4>Brak plików</h4>
  3388. </div>
  3389. </td>
  3390. </tr>
  3391. <?php endif; ?>
  3392. </tbody>
  3393. </table>
  3394. </div>
  3395. <br>
  3396. <br>
  3397. <div id="FILES_CONN_TBLS_<?php echo $this->_htmlID; ?>"></div>
  3398. <form enctype="multipart/form-data" method="POST" action="" id="FILES_FRM_<?php echo $this->_htmlID; ?>" class="form-inline">
  3399. <input type="hidden" name="M_DIST_UPLOAD_SOURCE" value="local">
  3400. <ul id="FILES_TAB_<?php echo $this->_htmlID; ?>" class="nav nav-tabs" style="margin:0;">
  3401. <li class="active"><a href="#local" data-toggle="local">Wybierz plik lokalny</a></li>
  3402. <li><a href="#scan" data-toggle="scan">Wybierz plik ze skanów</a></li>
  3403. </ul>
  3404. <div id="myTabContent" class="tab-content">
  3405. <div class="tab-pane fade in active" id="local" style="text-align: center;">
  3406. <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'">
  3407. </div>
  3408. <div class="tab-pane fade" id="scan">
  3409. <?php if (empty($skanyFiles)) : ?>
  3410. <div class="alert alert-info">
  3411. <h4>Brak plików</h4>
  3412. <?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>"; ?>
  3413. </div>
  3414. <?php else : ?>
  3415. <div style="max-height:150px; overflow:auto; border-bottom:1px solid #ddd;">
  3416. <table class="table table-bordered table-hover">
  3417. <colgroup>
  3418. <col style="width:30px;">
  3419. <col style="">
  3420. <col style="width:30px;">
  3421. <col style="width:80px;">
  3422. <col style="width:140px;">
  3423. </colgroup>
  3424. <tbody>
  3425. <?php foreach ($skanyFiles as $vFilePath) : ?>
  3426. <tr>
  3427. <?php
  3428. $vFileName = explode('/', $vFilePath);
  3429. $vFileName = end($vFileName);
  3430. $vFileSize = filesize($vFilePath);
  3431. $vFileSizeOut = round($vFileSize, 2) . "B";
  3432. if ($vFileSize > 1024 * 1024) {
  3433. $vFileSizeOut = round(($vFileSize / (1024 * 1024)), 2) . "M";
  3434. } else if ($vFileSize > 1024) {
  3435. $vFileSizeOut = round(($vFileSize / 1024), 0) . "K";
  3436. }
  3437. ?>
  3438. <td><input style="margin:0;" type="radio" name="SCANS_COLUMN_ADD" value="<?php echo $vFileName; ?>"></td>
  3439. <td><div style="overflow:hidden; white-space:nowrap;" title="<?php echo $vFileName; ?>"><?php echo $vFileName; ?></div></td>
  3440. <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>
  3441. <td style="white-space:nowrap;"><?php echo $vFileSizeOut; ?></td>
  3442. <td style="white-space:nowrap;"><?php echo date("Y-m-d H:i:s", filectime($vFilePath)); ?></td>
  3443. </tr>
  3444. <?php endforeach; ?>
  3445. </tbody>
  3446. </table>
  3447. </div>
  3448. <?php endif; ?>
  3449. </div>
  3450. </div>
  3451. <script>
  3452. $('#FILES_TAB_<?php echo $this->_htmlID; ?> a').click(function (e) {
  3453. e.preventDefault();
  3454. $(this).tab('show');
  3455. })
  3456. .on('shown', function (e) {
  3457. var fileSource = $(e.target).data('toggle')
  3458. , frm = jQuery('#FILES_FRM_<?php echo $this->_htmlID; ?>').get(0);
  3459. if (frm['M_DIST_UPLOAD_SOURCE']) {
  3460. frm['M_DIST_UPLOAD_SOURCE'].value = fileSource;
  3461. }
  3462. })
  3463. </script>
  3464. <br>
  3465. <table style="width:100%" class="table table-noborder">
  3466. <tr>
  3467. <td colspan="5">
  3468. <h4>Ustal nazwę pliku zgodną z obiegiem dokumentów
  3469. <?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> ?>
  3470. </h4>
  3471. </td>
  3472. </tr>
  3473. <tr>
  3474. <th style="border-right:1px solid #eee">ID</th>
  3475. <th style="border-right:1px solid #eee">TYP</th>
  3476. <th style="border-right:1px solid #eee">Opis <i class="icon-question-sign" title="kogo dotyczy / czego / sprawa / nazwa_firmy itp"></i></th>
  3477. <th style="border-right:1px solid #eee">Data Wersji</th>
  3478. <th>Numer Wersji</th>
  3479. </tr>
  3480. <tr>
  3481. <td style="border-right:1px solid #eee;">
  3482. <?php echo $record->ID; ?>
  3483. </td>
  3484. <td style="border-right:1px solid #eee;">
  3485. <select name="M_DIST_FILES_TYPE">
  3486. <?php foreach ($fileTypes as $kType => $vLabel) : ?>
  3487. <option value="<?php echo $kType; ?>"<?php if ($kType == 'TODO') { echo ' selected="selected"'; } ?> ><?php echo $vLabel; ?></option>
  3488. <?php endforeach; ?>
  3489. </select>
  3490. <br>
  3491. <label class="checkbox">
  3492. <input type="checkbox" name="M_DIST_FILES_TYPE_AUTO">
  3493. Wykrycie automatyczne TYPU z wysylanego pliku
  3494. </label>
  3495. <label class="checkbox">
  3496. <input type="checkbox" name="M_DIST_FILES_TEMP">
  3497. Plik tymczasowy / roboczy / nieoficjalny (_TEMP)
  3498. </label>
  3499. </td>
  3500. <td style="border-right:1px solid #eee;">
  3501. <input type="text" name="M_DIST_FILES_DESCRIPTION" value="<?php echo $M_DIST_FILES_DESCRIPTION; ?>" maxlength="50">
  3502. <br><label>jeśli nie zostanie podany to zostanie automatycznie wygenerowany na podstawie nazwy pliku wysyłanego</label>
  3503. </td>
  3504. <td style="border-right:1px solid #eee;">
  3505. <input type="date" name="M_DIST_FILES_DATE" value="<?php echo date('Y-m-d');?>" maxlength="10" class="span2">
  3506. <br><label>jeśli nie zostanie podana to zostanie ustawiona na dzisiaj (<?php echo date('Y-m-d');?>)</label>
  3507. </td>
  3508. <td>
  3509. <input type="number" name="M_DIST_FILES_VERSION" class="span2">
  3510. <br>
  3511. <label class="checkbox">
  3512. <input type="checkbox" name="M_DIST_FILES_VERSION_AUTO">
  3513. Automatycznie dodaj wersje
  3514. </label>
  3515. </td>
  3516. </tr>
  3517. <tr>
  3518. <td colspan="5">
  3519. <div id="FRM_UPLOAD_RESULTS_<?php echo $this->_htmlID; ?>"></div>
  3520. <p>
  3521. <input type="submit" value="Wyślij" class="btn btn-primary"> wybrany plik do folderu:
  3522. </p>
  3523. <p>
  3524. <code><b><?php echo $uploader->getDestPathShare(true); ?></b></code>
  3525. <br><i style="color:#777">(Jeśli folder nie istnieje to zostanie utworzony automatycznie)</i>
  3526. </p>
  3527. </td>
  3528. </tr>
  3529. </table>
  3530. </form>
  3531. </div>
  3532. <script>
  3533. function fileListUpdateAjax<?php echo $this->_htmlID; ?>() {
  3534. var postData = {};
  3535. jQuery.ajax({
  3536. 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; ?>',
  3537. type: 'POST',
  3538. //dataType: 'json',
  3539. //contentType: "application/json; charset=utf-8",
  3540. data: postData,
  3541. async: true,
  3542. success: function (data) {
  3543. fileListUpdate<?php echo $this->_htmlID; ?>(data);
  3544. },
  3545. error: function (jhr, textStatus, errorThrown) {
  3546. console.log('request error: ', errorThrown, ' textStatus: ', textStatus);
  3547. }
  3548. });
  3549. }
  3550. function fileListUpdate<?php echo $this->_htmlID; ?>(fileListJson) {
  3551. var fileListNode = jQuery('#FILES_LIST_<?php echo $this->_htmlID; ?>');
  3552. fileListNode.empty();
  3553. fileListJson.map(function(file){
  3554. var node = $('<tr></tr>');
  3555. var fFun = $('<i class="ico-remove" style="cursor:pointer" data-filename="' + file.name + '"></i>');
  3556. var fNameCell = $('<td style="overflow: hidden;"></td>');
  3557. var fName = $('<div style="overflow:hidden; white-space:nowrap;" title="' + file.name + '"></div>');
  3558. fName.append(fFun);
  3559. fName.append(file.name);
  3560. fName.appendTo(fNameCell);
  3561. node.append(fNameCell);
  3562. node.append('<td style="overflow:hidden; white-space:nowrap; text-align:center;">' + '<a href="' + file.web + '" target="_blank" class="ico-download-alt"></a>' + '</td>');
  3563. <?php if ($sharePoint) : ?>
  3564. 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>');
  3565. <?php endif; ?>
  3566. node.append('<td style="overflow:hidden; white-space:nowrap; text-align:right;">' + file.sizeStr + '</td>');
  3567. node.append('<td style="overflow:hidden; white-space:nowrap;">' + file.created + '</td>');
  3568. node.appendTo(fileListNode);
  3569. $(fFun).click(function(e){
  3570. var n = $(e.target);
  3571. var fname= n.data('filename');
  3572. if (!fname) {
  3573. return false;
  3574. }
  3575. if (confirm('Czy jesteś pewien, że chcesz usunąć plik o nazwie ' + fname + '?')) {
  3576. var postData = {filename: fname};
  3577. jQuery.ajax({
  3578. 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; ?>',
  3579. type: 'POST',
  3580. //dataType: 'json',
  3581. //contentType: "application/json; charset=utf-8",
  3582. data: postData,
  3583. async: true,
  3584. success: function (data) {
  3585. if (data && data.type) {
  3586. if (data.type == 'SUCCESS') {
  3587. n.parents('tr').remove();
  3588. //console.log('TODO: SUCCESS msg: ', data.string);
  3589. }
  3590. else if (data.type == 'ERROR') {
  3591. //console.log('TODO: ERROR msg: ', data.string);
  3592. }
  3593. } else {
  3594. console.log('TODO: ??? data: ', data);
  3595. }
  3596. },
  3597. error: function (jhr, textStatus, errorThrown) {
  3598. console.log('rm error: ', errorThrown, ' textStatus: ', textStatus);
  3599. }
  3600. });
  3601. }
  3602. });
  3603. });
  3604. }
  3605. function connTblListUpdateAjax<?php echo $this->_htmlID; ?>(connTblID) {
  3606. var postData = {};
  3607. // clear current file list
  3608. jQuery('#FILES_CONN_TBLS_<?php echo $this->_htmlID; ?>').find('.files-list').empty();
  3609. jQuery.ajax({
  3610. 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,
  3611. type: 'POST',
  3612. //dataType: 'json',
  3613. //contentType: "application/json; charset=utf-8",
  3614. data: postData,
  3615. async: true,
  3616. success: function (data) {
  3617. connTblListUpdate<?php echo $this->_htmlID; ?>(data);
  3618. },
  3619. error: function (jqXHR, textStatus, errorThrown) {
  3620. var txt = jqXHR.responseText || 'Error';
  3621. 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>');
  3622. console.log('connTblListUpdateAjax error: ', errorThrown, ' textStatus: ', textStatus);
  3623. }
  3624. });
  3625. }
  3626. function connTblListUpdate<?php echo $this->_htmlID; ?>(fileListJson) {
  3627. var fileListNode = jQuery('#FILES_CONN_TBLS_<?php echo $this->_htmlID; ?>').find('.files-list');
  3628. fileListNode.empty();
  3629. fileListJson.map(function(file){
  3630. var node = $('<tr></tr>');
  3631. var fNameCell = $('<td style="overflow: hidden;"></td>');
  3632. var fName = $('<div style="overflow:hidden; white-space:nowrap;" title="' + file.name + '"></div>');
  3633. fName.append(file.name);
  3634. fName.appendTo(fNameCell);
  3635. node.append(fNameCell);
  3636. node.append('<td style="overflow:hidden; white-space:nowrap; text-align:center;">' + '<a href="' + file.web + '" target="_blank" class="ico-download-alt"></a>' + '</td>');
  3637. node.append('<td style="overflow:hidden; white-space:nowrap; text-align:right;">' + file.sizeStr + '</td>');
  3638. node.append('<td style="overflow:hidden; white-space:nowrap;">' + file.created + '</td>');
  3639. node.appendTo(fileListNode);
  3640. });
  3641. }
  3642. jQuery(document).ready(function(){
  3643. jQuery('#FILES_FRM_<?php echo $this->_htmlID; ?>').ajaxForm({
  3644. 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; ?>',
  3645. beforeSubmit: function(args, $form, options) {
  3646. var argsMap = [];
  3647. args.map(function(v, k) {
  3648. argsMap[v.name] = v.value;
  3649. });
  3650. // validate
  3651. if (argsMap['M_DIST_UPLOAD_SOURCE'] == 'local') {
  3652. if (!argsMap['M_DIST_FILES_NAME']) {
  3653. console.log('TODO: nie wybrano lokalnego pliku!');
  3654. return false;
  3655. }
  3656. }
  3657. else if (argsMap['M_DIST_UPLOAD_SOURCE'] == 'scan') {
  3658. if (!argsMap['SCANS_COLUMN_ADD']) {
  3659. console.log('TODO: nie wybrano pliku ze skanów!');
  3660. return false;
  3661. }
  3662. }
  3663. else {
  3664. console.log('TODO: nie wybrano źródła pliku!');
  3665. return false;
  3666. }
  3667. var $out = $('#FRM_UPLOAD_RESULTS_<?php echo $this->_htmlID; ?>');
  3668. $out.html('Wysyłanie...');
  3669. },
  3670. success: function(data) {
  3671. var $out = $('#FRM_UPLOAD_RESULTS_<?php echo $this->_htmlID; ?>');
  3672. var btnClose = '<button type="button" class="close" data-dismiss="alert"><i class="icon-remove"></i></button>';
  3673. if (typeof data == 'object') {
  3674. if (data.type == 'ERROR') {
  3675. $out.html('<div class="alert alert-error">' + btnClose + data.string + '</div>');
  3676. } else if (data.type == 'SUCCESS') {
  3677. $out.html('<div class="alert alert-success">' + btnClose + data.string + '</div>');
  3678. fileListUpdateAjax<?php echo $this->_htmlID; ?>();
  3679. }
  3680. } else {
  3681. if (data.substr(0, 7) == 'WARNING') {
  3682. data = data.substr(7);
  3683. $out.html('<div class="alert alert-warning">' + btnClose + data + '</div>');
  3684. } else if (data.substr(0, 5) == 'ERROR') {
  3685. data = data.substr(5);
  3686. $out.html('<div class="alert alert-error">' + btnClose + data + '</div>');
  3687. } else if (data.substr(0, 7) == 'SUCCESS') {
  3688. data = data.substr(7);
  3689. $out.html('<div class="alert alert-success">' + btnClose + data + '</div>');
  3690. fileListUpdateAjax<?php echo $this->_htmlID; ?>();
  3691. } else if (data.substr(0, 4) == 'INFO') {
  3692. data = data.substr(4);
  3693. $out.html('<div class="alert alert-info">' + btnClose + data + '</div>');
  3694. }
  3695. }
  3696. }
  3697. });
  3698. var fileList = <?php echo json_encode($jsonFiles); ?>;
  3699. fileListUpdate<?php echo $this->_htmlID; ?>(fileList);
  3700. var connTbls = <?php echo json_encode($this->getConnectedTables()); ?>;
  3701. if (connTbls) {
  3702. var connTblsOut = '';
  3703. for(var key in connTbls) {
  3704. connTblsOut += '<button class="btn btn-small conn-tbl-load" data-zasobid="' + key + '">' + connTbls[key] + '</button>';
  3705. };
  3706. if (connTblsOut) {
  3707. connTblsOut = 'Pliki w powiązanych tabelach: <div class="btn-group">' + connTblsOut + '</div>';
  3708. connTblsOut += '<div style="max-height:180px; overflow:auto; border-bottom:1px solid #ddd;">' +
  3709. '<table class="table table-bordered table-hover">' +
  3710. '<colgroup>' +
  3711. '<col style="">' +
  3712. '<col style="width:30px;">' +
  3713. <?php if ($sharePoint) : ?>
  3714. '<col style="width:30px;">' +
  3715. <?php endif; ?>
  3716. '<col style="width:80px;">' +
  3717. '<col style="width:140px;">' +
  3718. '</colgroup>' +
  3719. '<tbody class="files-list">' +
  3720. '</tbody>' +
  3721. '</table>' +
  3722. '</div>';
  3723. var _connTblsWrap = jQuery('#FILES_CONN_TBLS_<?php echo $this->_htmlID; ?>');
  3724. _connTblsWrap.css('marginBottom', '26px');
  3725. _connTblsWrap.html(connTblsOut);
  3726. _connTblsWrap.find('.conn-tbl-load').each(function(){
  3727. jQuery(this).click(function(e){
  3728. var tblID = jQuery(e.target).data('zasobid');
  3729. console.log('clicked: ', tblID);
  3730. if (tblID) {
  3731. connTblListUpdateAjax<?php echo $this->_htmlID; ?>(tblID);
  3732. }// TODO: else show error
  3733. });
  3734. });
  3735. }
  3736. }
  3737. });
  3738. </script>
  3739. <?php
  3740. exit;
  3741. }
  3742. private function sendTypeSpecial($fldID, $args) {
  3743. $DBG = ('1' == V::get('DBG', '', $_REQUEST));
  3744. header("Content-type: application/json");
  3745. $fldName = '';
  3746. $fld = $this->_acl->getField($fldID);
  3747. 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>';}
  3748. if (!$fld) {
  3749. // 404
  3750. } else {
  3751. $fldName = $fld['name'];
  3752. }
  3753. $jsonData = array();
  3754. Lib::loadClass('Typespecial');
  3755. $typeSpecial = Typespecial::getInstance($fldID, $fldName);
  3756. if ($typeSpecial) {
  3757. $query = V::get('q', '', $_REQUEST);
  3758. $rawRows = null;
  3759. $rows = $typeSpecial->getValuesWithExports($query);
  3760. 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>';}
  3761. foreach ($rows as $kID => $vItem) {
  3762. $itemJson = new stdClass();
  3763. $itemJson->id = $vItem->id;
  3764. $itemJson->name = $vItem->param_out;
  3765. if (!empty($vItem->exports)) {
  3766. $itemJson->exports = $vItem->exports;
  3767. }
  3768. $jsonData[] = $itemJson;
  3769. }
  3770. }
  3771. /*
  3772. MENU_INIT:VIEWTABLE_AJAX
  3773. ZASOB_ID:1188
  3774. _task:TYPESPECIAL
  3775. fldID:3866
  3776. Form Dataview sourceview URL encoded
  3777. q:te
  3778. */
  3779. echo json_encode($jsonData);
  3780. exit;
  3781. }
  3782. private function sendTypeSpecialCell($id, $fldName, $args) {
  3783. $DBG = ('1' == V::get('DBG', '', $_REQUEST));
  3784. header("Content-type: application/json");
  3785. $jsonData = new stdClass();
  3786. $fldID = $this->_acl->getFieldIdByName($fldName);
  3787. 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>';}
  3788. $item = $this->_dataSource->getItem($id);
  3789. if (!$this->_acl->isAllowed($fldID, 'R', $item)) {
  3790. $jsonData->msg = 'Brak dostępu';
  3791. echo json_encode($jsonData);
  3792. exit;
  3793. }
  3794. if (!$fldID) {
  3795. $jsonData->msg = 'Wrong field';
  3796. echo json_encode($jsonData);
  3797. exit;
  3798. }
  3799. Lib::loadClass('Typespecial');
  3800. $typeSpecial = Typespecial::getInstance($fldID, $fldName);
  3801. if ($typeSpecial) {
  3802. $jsonData->data = $typeSpecial->getReturnData($this->_zasobID, $id, $fldName, '');
  3803. 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>';}
  3804. }
  3805. echo json_encode($jsonData);
  3806. exit;
  3807. }
  3808. private function sendAjaxData($args) {
  3809. $DBG = ('1' == V::get('DBG', '', $_REQUEST));
  3810. header("Content-type: application/json");
  3811. //sleep(1);// TODO: TEST
  3812. $pageSize = V::get('pageSize', 10, $args, 'int');
  3813. $page = V::get('page', 0, $args, 'int');
  3814. $currSortCol = V::get('currSortCol', '', $args);
  3815. $currSortFlip = V::get('currSortFlip', '', $args);
  3816. if ($page > 0) {
  3817. $page -= 1;
  3818. }
  3819. else {
  3820. }
  3821. $params = array();
  3822. $params['limit'] = $pageSize;
  3823. $params['limitstart'] = $page * $params['limit'];
  3824. $params['order_by'] = ($currSortCol)? $currSortCol : '';
  3825. $params['order_dir'] = $currSortFlip;
  3826. $filters = new stdClass();
  3827. $filters->currSortCol = $currSortCol;
  3828. $filters->currSortFlip = $currSortFlip;
  3829. foreach ($args as $k => $v) {
  3830. if (strlen($k) > 3 && substr($k, 0, 2) == 'f_' && strlen($v) > 0) {// filter prefix
  3831. $params[$k] = $v;
  3832. $filters->{$k} = $v;
  3833. }
  3834. else if (strlen($k) > 4 && substr($k, 0, 3) == 'sf_' && strlen($v) > 0) {// special filter prefix
  3835. $params[$k] = $v;
  3836. $filters->{$k} = $v;
  3837. }
  3838. }
  3839. $this->setFilters($filters);
  3840. 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>';}
  3841. $vCols = $this->_acl->getVirtualFieldList();
  3842. if (!empty($vCols)) {
  3843. 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>';}
  3844. }
  3845. Lib::loadClass('Typespecial');
  3846. $total = $this->_dataSource->getTotal($params);
  3847. 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>';}
  3848. $items = $this->_dataSource->getItems($params);
  3849. 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>';}
  3850. // TODO: add virtual data by Typespecial
  3851. if (!empty($vCols) && !empty($items)) {
  3852. foreach ($vCols as $vColID => $vCol) {
  3853. $colType = $this->_acl->getFieldTypeById($vColID);
  3854. if ($colType) {
  3855. continue;// pomin Typespecial dla realnych komorek w bazie danych
  3856. }
  3857. $typeSpecial = Typespecial::getInstance($vColID, $vCol);
  3858. if ($typeSpecial) {
  3859. 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>';}
  3860. $ids = array_keys($items);
  3861. $specialValues = $typeSpecial->getValuesByIds($this->_zasobID, $ids);
  3862. 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>';}
  3863. if (!empty($specialValues)) foreach ($specialValues as $kItemID => $vValues) {
  3864. $tsValue = implode('<br>', $vValues);
  3865. 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>';}
  3866. if (!empty($items[$kItemID]->{$vCol}) && !empty($tsValue)) {
  3867. $items[$kItemID]->{$vCol} .= ": {$tsValue}";
  3868. } else {
  3869. $items[$kItemID]->{$vCol} = $tsValue;
  3870. }
  3871. }
  3872. }
  3873. }
  3874. }
  3875. $visibleCols = $this->_acl->getVisibleFieldList();
  3876. 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>';}
  3877. $jsonData = new stdClass();
  3878. $jsonData->total = $total;
  3879. $jsonData->cols = new stdClass();
  3880. $ind = 0;
  3881. foreach ($visibleCols as $fieldID => $col) {
  3882. $ind++;
  3883. $jsonData->cols->{$col} = (object)array('index'=>$ind);
  3884. if ($col == 'ID') {
  3885. // /SE/se-dev/index.php?MENU_INIT=USERS2_MARKETING_EDIT&ARG1=EDIT&ARG1_VAL=31105
  3886. $jsonData->cols->{$col}->format = '<a href="#EDIT/{0}">{0}</a>';
  3887. $jsonData->cols->{$col}->unique = true;
  3888. }
  3889. else if (in_array($col, array('A_STATUS','A_STATUS_CURRENT','A_SERVICES_STATUS_CURRENT'))) {
  3890. $jsonData->cols->{$col}->format = '<div class="cell-A_STATUS-{0}">{0}</div>';
  3891. }
  3892. else if (in_array($col, array('Status'))) {
  3893. // Ahmes problems Status colors
  3894. $jsonData->cols->{$col}->format = '<div class="cell-Status-{0}">{0}</div>';
  3895. }
  3896. else if ($this->_dataSource->isGeomField($col)) {
  3897. $jsonData->cols->{$col}->type = 'geom';
  3898. }
  3899. if ('' !== ($label = $this->_acl->getFieldLabel($fieldID))) {
  3900. $jsonData->cols->{$col}->friendly = $label;
  3901. }
  3902. $colType = $this->_acl->getFieldType($col);
  3903. if ($colType) {// @see MarkTableAjaxFilterColType
  3904. if ($colType['type'] == 'date') {
  3905. //$jsonData->cols->{$col}->type = 'date';// TODO: require datepicker
  3906. }
  3907. } else {// typespecial - no type
  3908. $jsonData->cols->{$col}->type = 'special';
  3909. }
  3910. $typeSpecial = Typespecial::getInstance($fieldID, $col);
  3911. if ($typeSpecial) {
  3912. 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>';}
  3913. $jsonData->cols->{$col}->_tsRetId = $typeSpecial->getReturnId();
  3914. }
  3915. // @see sendHiddenColsSave
  3916. // $_SESSION['USER_PROFILE'][$this->_zasobID][fld_id] => boolean
  3917. if (isset($_SESSION['USER_PROFILE'][$this->_zasobID])) {
  3918. if (isset($_SESSION['USER_PROFILE'][$this->_zasobID][$fieldID])) {
  3919. if ($_SESSION['USER_PROFILE'][$this->_zasobID][$fieldID] != 1) {
  3920. $jsonData->cols->{$col}->hidden = true;
  3921. }
  3922. }
  3923. }
  3924. }
  3925. $jsonData->rows = array();
  3926. foreach ($items as $vItem) {
  3927. // TODO: hide items without 'R'
  3928. foreach ($visibleCols as $kID => $vCol) {
  3929. // TODO: ID default 'R'
  3930. if (!$this->_acl->isAllowed($kID, 'R', $vItem)) {
  3931. $vItem->{$vCol} = '*****';
  3932. }
  3933. // null => empty string
  3934. if (!isset($vItem->{$vCol}) || (!$vItem->{$vCol} && $vItem->{$vCol} !== '0')) {
  3935. 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>';}
  3936. $vItem->{$vCol} = '';
  3937. }
  3938. }
  3939. $jsonData->rows[] = $vItem;
  3940. }
  3941. //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>';
  3942. //echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">jsonData (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($jsonData);echo'</pre>';
  3943. echo json_encode($jsonData);
  3944. exit;
  3945. }
  3946. private function fixEmptyValueFromUser($fieldID) {// TODO: moved to TableAcl->fixEmptyValueFromUser
  3947. $value = '';
  3948. $type = $this->_acl->getFieldTypeById($fieldID);
  3949. if ($type) {
  3950. if ($type['type'] == 'date') {
  3951. $value = $type['default'];
  3952. }
  3953. // fix bug when field is unique and is null allowed: change empty string to null
  3954. if ($type['null']) {
  3955. $value = 'NULL';
  3956. }
  3957. // fix bug when field is enum and is set to '0': for php '0' is empty
  3958. if (substr($type['type'], 0, 4) == 'enum') {// && $args["f{$fieldID}"] === '0') {
  3959. if (false !== strpos($type['type'], "''")) {
  3960. // enum('', '1','2')
  3961. $value = '';
  3962. } else if (false !== strpos($type['type'], "'0'")) {
  3963. // enum('0', '1','2')
  3964. $value = '0';
  3965. } else {
  3966. $value = $type['default'];
  3967. }
  3968. }
  3969. }
  3970. return $value;
  3971. }
  3972. /**
  3973. * set hidden cols in $_SESSION['USER_PROFILE'][$this->_zasobID];
  3974. * $_SESSION['USER_PROFILE'][$this->_zasobID][fld_id] => boolean
  3975. */
  3976. private function sendHiddenColsSave($args) {
  3977. if (empty($_POST)) {
  3978. exit;
  3979. }
  3980. Lib::loadClass('UserProfile');
  3981. UserProfile::load();
  3982. // clean up old, wrong values
  3983. if (array_key_exists("{$this->_tbl}_COLUMN", $_SESSION['USER_PROFILE'])) {
  3984. unset($_SESSION['USER_PROFILE']["{$this->_tbl}_COLUMN"]);
  3985. }
  3986. $colVis = array();
  3987. if (array_key_exists($this->_zasobID, $_SESSION['USER_PROFILE'])) {
  3988. $colVis = $_SESSION['USER_PROFILE'][$this->_zasobID];
  3989. }
  3990. $fields = $this->_acl->getFields();
  3991. foreach ($fields as $kFldId => $vFld) {
  3992. $vFldName = $vFld['name'];
  3993. if (isset($_POST[$vFldName])) {
  3994. if ($_POST[$vFldName] == 'SHOW') {
  3995. $colVis[$kFldId] = 1;
  3996. } else if ($_POST[$vFldName] == 'HIDE') {
  3997. $colVis[$kFldId] = 0;
  3998. }
  3999. }
  4000. }
  4001. $_SESSION['USER_PROFILE'][$this->_zasobID] = $colVis;
  4002. UserProfile::save();
  4003. }
  4004. private function sendTheGeomSave($args) {
  4005. $id = V::get('ID', 0, $args, 'int');
  4006. $polygon = V::get('polygon', 0, $args);
  4007. $geomFieldName = 'the_geom';
  4008. if ($id <= 0) {
  4009. header('HTTP/1.0 404 Not Found');
  4010. echo "Wrong param ID";
  4011. exit;
  4012. }
  4013. // 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)))
  4014. $tblName = $this->_acl->getName();
  4015. $db = DB::getDB();
  4016. $record = $db->get_by_id($tblName, $id);
  4017. if (!$this->_acl->canWriteRecord($record) && !$this->_acl->hasPermSuperWrite()) {
  4018. header('HTTP/1.0 403.3 - Write access forbidden');
  4019. echo "Brak dostępu do rekordu";
  4020. exit;
  4021. }
  4022. $theGeomFieldId = $this->_acl->getFieldIdByName($geomFieldName);
  4023. if (!$this->_acl->isAllowed($theGeomFieldId, 'W', $record)) {
  4024. header('HTTP/1.0 403.3 - Write access forbidden');
  4025. echo "Brak dostępu do zapisu dla pola {$geomFieldName}";
  4026. exit;
  4027. }
  4028. $sqlObj = new stdClass();
  4029. $sqlObj->{$geomFieldName} = "GeomFromText('{$polygon}')";
  4030. $sqlObj->ID = $id;
  4031. 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>';}
  4032. $ret = $db->UPDATE_OBJ($tblName, $sqlObj);
  4033. if ($ret > 0) {
  4034. echo '<div class="alert alert-success">';
  4035. echo "Rekord zapisany pomyślnie";//"Record saved successfully";
  4036. echo '</div>';
  4037. } else if ($ret == 0) {
  4038. echo '<div class="alert alert-info">';
  4039. echo "Nie wprowadzono żadnych zmian";
  4040. echo '</div>';
  4041. } else {
  4042. header('HTTP/1.0 404 Not Found');
  4043. echo '<div class="alert alert-error">';
  4044. echo '<h4>' . "Wystąpiły błędy!" . '</h4>';
  4045. if ($db->has_errors()) {
  4046. $errors = $db->get_errors();
  4047. echo implode('<br>', $errors);
  4048. }
  4049. echo '</div>';
  4050. }
  4051. exit;
  4052. }
  4053. }