Przypomnij.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971
  1. <?php
  2. class Przypomnij {
  3. private $_data;
  4. private $_fltrs;
  5. private $_deepRecurseLimit;
  6. private $_dSource = array();
  7. private $_tblIdCache = array();
  8. private $_tblAclCache = array();
  9. public function __construct() {
  10. $this->_data = array();// [type][id] = {id, _title, _type, _l_app, _l_app_date}
  11. $this->_data['projekt'] = array();
  12. $this->_data['koresp'] = array();
  13. $this->_data['proces'] = array();
  14. $this->_fltrs = array();// type => selected value
  15. $this->_fltrs['user'] = '';// L_APPOITMENT_USER
  16. $this->_fltrs['date_from'] = '';
  17. $this->_fltrs['date_to'] = '';
  18. $this->_deepRecurseLimit = 3;
  19. }
  20. public function setRecurseLimit($deepRecurseLimit) {
  21. $this->_deepRecurseLimit = $deepRecurseLimit;
  22. }
  23. public function getRawData() {
  24. return $this->_data;
  25. }
  26. public function fetchData() {
  27. $db = DB::getDB();
  28. $userLogin = User::getLogin();
  29. $usrAclGroups = User::getLdapGroupsNames();
  30. //$usrAclGroups[] = '';// TODO: empty group not allowed to view for everyone?
  31. $sqlUsrAclGroups = "'" . implode("','", $usrAclGroups) . "'";
  32. $sqlFltr_TODO = "
  33. t.`A_ADM_COMPANY` in({$sqlUsrAclGroups})
  34. and t.`A_CLASSIFIED` in({$sqlUsrAclGroups})
  35. ";
  36. $sqlAclFltrKoresp = "
  37. and (kor.`A_ADM_COMPANY` in({$sqlUsrAclGroups})
  38. or kor.`A_CLASSIFIED` in({$sqlUsrAclGroups})
  39. or kor.`L_APPOITMENT_USER`='{$userLogin}'
  40. )
  41. ";
  42. $sql = "select kor.ID
  43. , kor.ID_PROJECT
  44. , kor.A_STATUS
  45. , kor.L_APPOITMENT_USER
  46. , kor.L_APPOITMENT_DATE
  47. , kor.L_APPOITMENT_INFO
  48. , kor.A_RECORD_CREATE_DATE
  49. , kor.A_RECORD_CREATE_AUTHOR
  50. , kor.K_TYP_KORESP, kor.K_TYP_RODZAJ
  51. -- ? , kor.K_TYP_RODZAJ_OPIS
  52. , kor.K_OD_KOGO
  53. , kor.OD_KOGO_ADRES
  54. , kor.K_ZAWARTOS
  55. -- TODO: , proj.M_DIST_DESC
  56. , kor.K_LOKALIZACJA
  57. , kor.K_LOKALIZACJA_OPIS
  58. from `IN7_DZIENNIK_KORESP` as kor
  59. where kor.`A_STATUS` not in ('OFF_HARD','DELETED')
  60. {$sqlAclFltrKoresp}
  61. ";
  62. $res = $db->query($sql);
  63. while ($r = $db->fetch($res)) {
  64. $r->_task_type = 'koresp';
  65. $r->_show = false;
  66. $r->_acl_proj_id = (int)$r->ID_PROJECT;
  67. $r->_title = "<strong>{$r->K_OD_KOGO}</strong><br><em>{$r->OD_KOGO_ADRES}</em><br>{$r->K_ZAWARTOS}";
  68. $r->_type = "{$r->K_TYP_KORESP}-{$r->K_TYP_RODZAJ}";
  69. $r->_l_app = $r->L_APPOITMENT_USER;
  70. $r->_l_app_date = $r->L_APPOITMENT_DATE;
  71. $this->_data['koresp'][$r->ID] = $r;
  72. }
  73. $sqlAclFltrProj = "
  74. and (proj.`A_ADM_COMPANY` in({$sqlUsrAclGroups})
  75. or proj.`A_CLASSIFIED` in({$sqlUsrAclGroups})
  76. or proj.`L_APPOITMENT_USER`='{$userLogin}'
  77. )
  78. ";
  79. $sql = "select proj.ID
  80. , proj.P_ID
  81. , proj.A_STATUS
  82. , proj.M_DIST_DESC
  83. , proj.M_DIST_TYPE
  84. , proj.L_APPOITMENT_DATE
  85. , proj.L_APPOITMENT_USER
  86. , proj.L_APPOITMENT_INFO
  87. , proj.A_RECORD_CREATE_DATE
  88. , proj.A_RECORD_CREATE_AUTHOR
  89. , proj.M_DISTRIBUTOR
  90. -- ? , proj.M_DIST_DATE
  91. -- ? , proj.A_RECORD_CREATE_AUTHOR, proj.A_RECORD_UPDATE_AUTHOR, proj.A_RECORD_UPDATE_DATE
  92. -- ? , proj.A_PROBLEM, proj.A_PROBLEM_DATE, proj.A_PROBLEM_DESC
  93. from `IN7_MK_BAZA_DYSTRYBUCJI` as proj
  94. where proj.`A_STATUS` NOT IN ('OFF_HARD','DELETED')
  95. {$sqlAclFltrProj}
  96. ";
  97. $res = $db->query($sql);
  98. while ($r = $db->fetch($res)) {
  99. $r->M_DIST_DESC = htmlspecialchars($r->M_DIST_DESC);// TODO: fix bug in html a href inside M_DIST_DESC
  100. $r->_task_type = 'projekt';
  101. $r->_show = false;
  102. $r->_acl_proj_id = (int)$r->P_ID;
  103. $r->_title = $r->M_DIST_DESC;
  104. $r->_type = $r->M_DIST_TYPE;
  105. $r->_l_app = $r->L_APPOITMENT_USER;
  106. $r->_l_app_date = $r->L_APPOITMENT_DATE;
  107. $this->_data['projekt'][$r->ID] = $r;
  108. }
  109. $sqlAclFltrProces = "
  110. and (p.`A_ADM_COMPANY` in({$sqlUsrAclGroups})
  111. or p.`A_CLASSIFIED` in({$sqlUsrAclGroups})
  112. or p.`L_APPOITMENT_USER`='{$userLogin}'
  113. )
  114. ";
  115. $sql = "select p.ID
  116. , p.`DESC`
  117. , p.`A_STATUS`
  118. , p.`TYPE`
  119. , p.`L_APPOITMENT_DATE`
  120. , p.`L_APPOITMENT_USER`
  121. , p.`L_APPOITMENT_INFO`
  122. from `CRM_PROCES` as p
  123. where p.`A_STATUS` in('NORMAL', 'WAITING')
  124. and p.`TYPE`='PROCES_INIT'
  125. and p.`L_APPOITMENT_DATE`!=''
  126. and p.`L_APPOITMENT_USER`!=''
  127. {$sqlAclFltrProces}
  128. ";
  129. $res = $db->query($sql);
  130. while ($r = $db->fetch($res)) {
  131. $r->_task_type = 'proces';
  132. $r->_show = false;
  133. $r->_title = $r->DESC;
  134. $r->_type = $r->TYPE;
  135. $r->_l_app = $r->L_APPOITMENT_USER;
  136. $r->_l_app_date = $r->L_APPOITMENT_DATE;
  137. $this->_data['proces'][$r->ID] = $r;
  138. }
  139. $sqlAclFltrProblems = "
  140. and (probl.`A_ADM_COMPANY` in({$sqlUsrAclGroups})
  141. or probl.`A_CLASSIFIED` in({$sqlUsrAclGroups})
  142. or probl.`L_APPOITMENT_USER`='{$userLogin}'
  143. )
  144. ";
  145. $sql = "select probl.ID
  146. , probl.PARENT_ID
  147. , probl.A_STATUS
  148. , probl.L_APPOITMENT_DATE
  149. , probl.L_APPOITMENT_USER
  150. , probl.L_APPOITMENT_INFO
  151. , probl.A_RECORD_CREATE_DATE
  152. , probl.A_RECORD_CREATE_AUTHOR
  153. , probl.A_PROBLEM
  154. , probl.A_PROBLEM_DESC
  155. from `PROBLEMS` as probl
  156. where probl.`A_STATUS` NOT IN ('OFF_HARD','DELETED')
  157. and probl.`L_APPOITMENT_DATE`!=''
  158. and probl.`L_APPOITMENT_USER`!=''
  159. {$sqlAclFltrProblems}
  160. ";
  161. $res = $db->query($sql);
  162. while ($r = $db->fetch($res)) {
  163. $r->A_PROBLEM_DESC = htmlspecialchars($r->A_PROBLEM_DESC);
  164. $r->_task_type = 'task';
  165. $r->_show = false;
  166. $r->_title = $r->A_PROBLEM_DESC;
  167. $r->_type = $r->M_DIST_TYPE;
  168. $r->_l_app = $r->L_APPOITMENT_USER;
  169. $r->_l_app_date = $r->L_APPOITMENT_DATE;
  170. $this->_data['task'][$r->ID] = $r;
  171. }
  172. $sqlAclFltrProces = "
  173. and (p.`A_ADM_COMPANY` in({$sqlUsrAclGroups})
  174. or p.`A_CLASSIFIED` in({$sqlUsrAclGroups})
  175. or p.`L_APPOITMENT_USER`='{$userLogin}'
  176. )
  177. ";
  178. $sql = "select p.ID
  179. , p.`DESC`
  180. , p.`A_STATUS`
  181. , p.`TYPE`
  182. , p.`L_APPOITMENT_DATE`
  183. , p.`L_APPOITMENT_USER`
  184. , p.`L_APPOITMENT_INFO`
  185. from `CRM_LISTA_ZASOBOW` as p
  186. where p.`A_STATUS` in('NORMAL', 'WAITING')
  187. and p.`L_APPOITMENT_DATE`!=''
  188. and p.`L_APPOITMENT_USER`!=''
  189. {$sqlAclFltrProces}
  190. ";
  191. $res = $db->query($sql);
  192. while ($r = $db->fetch($res)) {
  193. $r->_task_type = 'zasob';
  194. $r->_show = false;
  195. $r->_title = $r->DESC;
  196. $r->_type = $r->TYPE;
  197. $r->_l_app = $r->L_APPOITMENT_USER;
  198. $r->_l_app_date = $r->L_APPOITMENT_DATE;
  199. $this->_data['zasob'][$r->ID] = $r;
  200. }
  201. $this->_fetchLAppUsers();
  202. }
  203. public function setFltrUser($userName) {
  204. foreach ($this->_data as $kType => $vTasks) {
  205. foreach ($vTasks as $kId => $vTask) {
  206. if (!$userName) {
  207. $this->_data[$kType][$kId]->_show = true;
  208. } else {
  209. if ($vTask->_l_app == $userName) {
  210. $this->_data[$kType][$kId]->_show = true;
  211. } else {
  212. $this->_data[$kType][$kId]->_show = false;
  213. }
  214. }
  215. }
  216. }
  217. }
  218. private function _fetchLAppUsers() {
  219. $this->_createCacheTable();
  220. $this->_updateCacheTable();
  221. $projTodo = array();
  222. foreach ($this->_data['projekt'] as $kID => $vProj) {
  223. if (empty($vProj->_l_app)) {
  224. if ($vProj->_acl_proj_id > 0) {
  225. $projTodo[$vProj->_acl_proj_id][$vProj->ID] = 'projekt';
  226. }
  227. }
  228. }
  229. foreach ($this->_data['koresp'] as $kID => $vKoresp) {
  230. if (empty($vKoresp->_l_app)) {
  231. if ($vKoresp->_acl_proj_id > 0) {
  232. $projTodo[$vKoresp->_acl_proj_id][$vKoresp->ID] = 'koresp';
  233. }
  234. }
  235. }
  236. if (empty($projTodo)) {
  237. return;
  238. }
  239. $db = DB::getDB();
  240. $projIds = array_keys($projTodo);
  241. $sql = "select c.`ID`, c.`ID_PROJECT`, c.`L_APPOITMENT_USER`, c.`L_APPOITMENT_DATE`
  242. from `_PRZYPOMNIJ_CACHE` as c
  243. where c.`ID_PROJECT` in(" . implode(",", $projIds) . ")
  244. ";
  245. if(V::get('DBG_P', '', $_GET) > 2){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">sql (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql);echo'</pre>';}
  246. $res = $db->query($sql);
  247. if (!$res) {
  248. if ($db->has_errors()) {
  249. 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>';
  250. }
  251. }
  252. while ($r = $db->fetch($res)) {
  253. foreach ($projTodo[$r->ID_PROJECT] as $kRowId => $vType) {
  254. if ($vType == 'projekt') {
  255. if (isset($this->_data['projekt'][$kRowId])) {
  256. if (!empty($r->L_APPOITMENT_USER)) {
  257. $this->_data['projekt'][$kRowId]->_l_app = $r->L_APPOITMENT_USER;
  258. }
  259. } else {
  260. //echo '<p style="color:red">'."Error not set \$this->_data['projekt'][$kRowId]".'</p>';
  261. }
  262. }
  263. else if ($vType == 'koresp') {
  264. if (!empty($r->L_APPOITMENT_USER)) {
  265. $this->_data['koresp'][$kRowId]->_l_app = $r->L_APPOITMENT_USER;
  266. if (!empty($r->L_APPOITMENT_DATE) && empty($this->_data['koresp'][$kRowId]->_l_app_date)) {
  267. //$this->_data['koresp'][$kRowId]->_l_app_date = $r->L_APPOITMENT_DATE;
  268. $this->_data['koresp'][$kRowId]->_l_app_date = '0000-00-00';
  269. }
  270. }
  271. }
  272. }
  273. }
  274. }
  275. private function _fetchLAppUsersRec() {
  276. $projTodo = array();
  277. $db = DB::getDB();
  278. $loopLimit = $this->_deepRecurseLimit;
  279. $firstLoop = true;
  280. do {
  281. if(V::get('DBG_P', '', $_GET) > 2){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">loop(' . ($this->_deepRecurseLimit - $loopLimit) . ') start projTodo (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($projTodo);echo'</pre>';}
  282. foreach ($this->_data['projekt'] as $kID => $vProj) {
  283. if (empty($vProj->_l_app)) {
  284. if ($vProj->_acl_proj_id > 0) {
  285. if (isset($this->_data['projekt'][$vProj->_acl_proj_id])) {// already fetched from DB
  286. if (!empty($this->_data['projekt'][$vProj->_acl_proj_id]->_l_app)) {
  287. $this->_data['projekt'][$vProj->ID]->_l_app = $this->_data['projekt'][$vProj->_acl_proj_id]->_l_app;
  288. } else {
  289. $this->_data['projekt'][$vProj->ID]->_acl_proj_id = $this->_data['projekt'][$vProj->_acl_proj_id]->_acl_proj_id;
  290. }
  291. } else {
  292. $projTodo[$vProj->_acl_proj_id][$vProj->ID] = 'projekt';
  293. }
  294. } else if (!$vProj->_acl_proj_id) {
  295. //if ($firstLoop) echo '<p>'."Error: Projekt {$vProj->ID} nie ma P_ID ani L_APPOITMENT_USER! Autor: {$vProj->A_RECORD_CREATE_AUTHOR} / {$vProj->A_RECORD_CREATE_DATE}".'</p>';
  296. $this->_data['projekt'][$kID]->_acl_proj_id = -1;// set error
  297. } else if ($vProj->_acl_proj_id < 0) {
  298. //if ($firstLoop) echo '<p>'."Error: Projekt {$vProj->ID} ma P_ID = -1, brak L_APPOITMENT_USER! Autor: {$vProj->A_RECORD_CREATE_AUTHOR} / {$vProj->A_RECORD_CREATE_DATE}".'</p>';
  299. $this->_data['projekt'][$kID]->_acl_proj_id = -1;// set error
  300. }
  301. }
  302. }
  303. foreach ($this->_data['koresp'] as $kID => $vKoresp) {
  304. if (empty($vKoresp->_l_app)) {
  305. if ($vKoresp->_acl_proj_id > 0) {
  306. if (!empty($this->_data['projekt'][$vKoresp->_acl_proj_id]->_l_app)) {
  307. $this->_data['koresp'][$vKoresp->ID]->_l_app = $this->_data['projekt'][$vKoresp->_acl_proj_id]->_l_app;
  308. } else {
  309. $this->_data['koresp'][$vKoresp->ID]->_acl_proj_id = $this->_data['projekt'][$vKoresp->_acl_proj_id]->_acl_proj_id;
  310. if ($vKoresp->_acl_proj_id > 0) {
  311. $projTodo[$vKoresp->_acl_proj_id][$vKoresp->ID] = 'koresp';
  312. } else {
  313. //echo '<p style="color:red">'."Error: brak l_app w projektach dla Koresp {$vKoresp->ID}".'</p>';
  314. }
  315. }
  316. } else {
  317. //if ($firstLoop) echo '<p>'."Error: Korespondencja {$vKoresp->ID} ma ID_PROJECT = {$vKoresp->_acl_proj_id}, brak L_APPOITMENT_USER! Autor: {$vKoresp->A_RECORD_CREATE_AUTHOR} / {$vKoresp->A_RECORD_CREATE_DATE}".'</p>';
  318. $this->_data['koresp'][$kID]->_acl_proj_id = -1;// set error
  319. }
  320. }
  321. }
  322. if ($firstLoop) $firstLoop = false;
  323. if (empty($projTodo)) {
  324. if(V::get('DBG_P', '', $_GET) > 2){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">loop(' . ($this->_deepRecurseLimit - $loopLimit) . ') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r("break loop " . ($this->_deepRecurseLimit - $loopLimit));echo'</pre>';}
  325. break;
  326. }
  327. if(V::get('DBG_P', '', $_GET) > 2){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">loop(' . ($this->_deepRecurseLimit - $loopLimit) . ') $projTodo (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($projTodo);echo'</pre>';}
  328. $projIds = array_keys($projTodo);
  329. $sql = "select `ID`, `P_ID`, `L_APPOITMENT_USER`, `L_APPOITMENT_USER`
  330. from `IN7_MK_BAZA_DYSTRYBUCJI`
  331. where `ID` in(" . implode(",", $projIds) . ")
  332. ";
  333. if(V::get('DBG_P', '', $_GET) > 2){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">loop(' . ($this->_deepRecurseLimit - $loopLimit) . ') sql (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql);echo'</pre>';}
  334. $res = $db->query($sql);
  335. if (!$res) {
  336. if ($db->has_errors()) {
  337. 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>';
  338. }
  339. }
  340. while ($r = $db->fetch($res)) {
  341. //if(V::get('DBG_P', '', $_GET) > 2){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">loop(' . ($this->_deepRecurseLimit - $loopLimit) . ') r [isset($projTodo[$r->ID]) = '.isset($projTodo[$r->ID]).'] (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($r);echo'</pre>';}
  342. foreach ($projTodo[$r->ID] as $kRowId => $vType) {
  343. if ($vType == 'projekt') {
  344. if (isset($this->_data['projekt'][$kRowId])) {
  345. $this->_data['projekt'][$kRowId]->_acl_proj_id = (int)$r->P_ID;
  346. if (!empty($r->L_APPOITMENT_USER)) {
  347. $this->_data['projekt'][$kRowId]->_l_app = $r->L_APPOITMENT_USER;
  348. //if (!empty($r->L_APPOINTMENT_DATE)) {
  349. // $this->_data['projekt'][$kRowId]->_l_app = $r->L_APPOITMENT_USER;
  350. //}
  351. }
  352. } else {
  353. echo '<p style="color:red">'."Error not set \$this->_data['projekt'][$kRowId]".'</p>';
  354. }
  355. } else if ($vType == 'koresp') {
  356. $this->_data['koresp'][$kRowId]->_acl_proj_id = (int)$r->P_ID;
  357. if (!empty($r->L_APPOITMENT_USER)) {
  358. $this->_data['koresp'][$kRowId]->_l_app = $r->L_APPOITMENT_USER;
  359. //if (!empty($r->L_APPOINTMENT_DATE)) {
  360. // $this->_data['projekt'][$kRowId]->_l_app = $r->L_APPOITMENT_USER;
  361. //}
  362. }
  363. }
  364. }
  365. unset($projTodo[$r->ID]);
  366. }
  367. if(V::get('DBG_P', '', $_GET) > 2){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">loop(' . ($this->_deepRecurseLimit - $loopLimit) . ') this->_data (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($this->_data);echo'</pre>';}
  368. } while (--$loopLimit);
  369. }
  370. public function getAllowedUsersList() {
  371. $allowedUsers = array();
  372. $db = DB::getDB();
  373. $userLogin = User::getLogin();
  374. $usrAclGroups = User::getLdapGroupsNames();
  375. //$usrAclGroups[] = '';// TODO: allow empty for everyone?
  376. $sqlUsrAclGroups = "'" . implode("','", $usrAclGroups) . "'";
  377. DBG::_('DBG_P', '>2', 'sqlUsrAclGroups', $sqlUsrAclGroups, __CLASS__, __FUNCTION__, __LINE__);
  378. $tblsToSearch = array();
  379. $tblsToSearch[] = 'IN7_MK_BAZA_DYSTRYBUCJI';
  380. $tblsToSearch[] = 'IN7_DZIENNIK_KORESP';
  381. $tblsToSearch[] = 'CRM_PROCES';
  382. $tblsToSearch[] = 'CRM_LISTA_ZASOBOW';
  383. $tblsToSearch[] = 'PROBLEMS';
  384. $userAcl = User::getAcl();
  385. foreach ($tblsToSearch as $tblName) {
  386. $tblZasobId = ProcesHelper::getZasobTableID($tblName);
  387. if ($userAcl->hasTableAcl($tblZasobId)) {
  388. $tblAcl = $userAcl->getTableAcl($tblZasobId);
  389. if ($tblAcl->hasFieldPerm($tblAcl->getFieldIdByName('ID'), 'R')) {
  390. $ds = $tblAcl->getDataSource();
  391. $sqlAclFltr = '';
  392. if ($ds->hasAclGroupFields()) {
  393. $fldGroupWrite = $ds->getFieldGroupWrite();
  394. $fldGroupRead = $ds->getFieldGroupRead();
  395. $fldOwner = $ds->getFieldOwner();
  396. $sqlFltr = "
  397. t.`{$fldGroupWrite}` in({$sqlUsrAclGroups})
  398. and t.`{$fldGroupRead}` in({$sqlUsrAclGroups})
  399. ";
  400. if ($fldOwner) {
  401. $sqlFltr = "( ({$sqlFltr}) or t.`{$fldOwner}`='{$userLogin}' )";
  402. }
  403. $sqlAclFltr = " and {$sqlFltr}";
  404. }
  405. $sql = "select distinct t.`L_APPOITMENT_USER`
  406. from `{$tblName}` t
  407. where t.`L_APPOITMENT_USER`!=''
  408. and t.`A_STATUS` not in ('OFF_HARD','DELETED')
  409. {$sqlAclFltr}
  410. ";
  411. $res = $db->query($sql) or die("blad zapytania do bazy {$sql}");
  412. while ($r = $db->fetch($res)) {
  413. $allowedUsers[$r->L_APPOITMENT_USER] = true;
  414. }
  415. DBG::_('DBG_P', '>2', 'allowedUsers after '.$tblName.'', implode(',', array_keys($allowedUsers)), __CLASS__, __FUNCTION__, __LINE__);
  416. }
  417. }
  418. }
  419. if (!empty($allowedUsers)) {
  420. $allowedUsersFiltered = array();
  421. $allowedUsersFiltered[User::getLogin()] = true;
  422. $tblName = 'ADMIN_USERS';
  423. $tblZasobId = ProcesHelper::getZasobTableID($tblName);
  424. if (!$userAcl->hasTableAcl($tblZasobId)) {
  425. DBG::_('DBG_P', '>2', '!hasTableAcl', null, __CLASS__, __FUNCTION__, __LINE__);
  426. return $allowedUsersFiltered;
  427. }
  428. $tblAcl = $userAcl->getTableAcl($tblZasobId);
  429. if (!$tblAcl->hasFieldPerm($tblAcl->getFieldIdByName('ID'), 'R')) {
  430. DBG::_('DBG_P', '>2', '!$tblAcl->hasFieldPerm(ID, R)', $tblAcl, __CLASS__, __FUNCTION__, __LINE__);
  431. return $allowedUsersFiltered;
  432. }
  433. $ds = $tblAcl->getDataSource();
  434. $sqlAclFltr = '';
  435. if ($ds->hasAclGroupFields()) {
  436. $fldGroupWrite = $ds->getFieldGroupWrite();
  437. $fldGroupRead = $ds->getFieldGroupRead();
  438. $sqlFltr = "
  439. t.`{$fldGroupWrite}` in({$sqlUsrAclGroups})
  440. and t.`{$fldGroupRead}` in({$sqlUsrAclGroups})
  441. ";
  442. $sqlAclFltr = " and {$sqlFltr}";
  443. }
  444. else {
  445. DBG::_('DBG_P', '>0', '!hasAclGroupFields tblAcl', $tblAcl, __CLASS__, __FUNCTION__, __LINE__);
  446. }
  447. $sqlFoundUsers = array_keys($allowedUsers);
  448. $sqlFoundUsers = "'" . implode("','", $sqlFoundUsers) . "'";
  449. $sql = "select t.`ADM_ACCOUNT`
  450. from `{$tblName}` t
  451. where t.`ADM_ACCOUNT` in({$sqlFoundUsers})
  452. {$sqlAclFltr}
  453. ";
  454. DBG::_('DBG_P', '>2', 'sql', $sql, __CLASS__, __FUNCTION__, __LINE__);
  455. $res = $db->query($sql) or die("blad zapytania do bazy {$sql}");
  456. while ($r = $db->fetch($res)) {
  457. $allowedUsersFiltered[$r->ADM_ACCOUNT] = true;
  458. }
  459. $allowedUsers = $allowedUsersFiltered;
  460. }
  461. DBG::_('DBG_P', '>2', 'allowedUsersFiltered', $allowedUsersFiltered, __CLASS__, __FUNCTION__, __LINE__);
  462. ksort($allowedUsers);
  463. return $allowedUsers;
  464. }
  465. private function _createCacheTable() {
  466. $db = DB::getDB();
  467. $sql = "CREATE TABLE IF NOT EXISTS `_PRZYPOMNIJ_CACHE` (
  468. `ID` int(11) NOT NULL AUTO_INCREMENT,
  469. `ID_PROJECT` int(11) NOT NULL,
  470. `_l_app_user` varchar(40) NOT NULL DEFAULT '',
  471. `P_ID` varchar(20) NOT NULL DEFAULT '0',
  472. `A_RECORD_CREATE_DATE` datetime NOT NULL,
  473. `A_RECORD_CREATE_AUTHOR` varchar(40) NOT NULL DEFAULT '',
  474. `A_RECORD_UPDATE_DATE` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  475. `A_RECORD_UPDATE_AUTHOR` varchar(40) NOT NULL DEFAULT '',
  476. `L_APPOITMENT_DATE` varchar(30) NOT NULL DEFAULT '',
  477. `L_APPOITMENT_USER` varchar(40) NOT NULL DEFAULT '',
  478. `L_APPOITMENT_INFO` varchar(200) NOT NULL DEFAULT '',
  479. `L_CALENDAR` enum('NO','YES') NOT NULL DEFAULT 'NO',
  480. `A_STATUS` enum('WAITING','NORMAL','MONITOR','WARNING','OFF_SOFT','OFF_HARD','DELETED') NOT NULL DEFAULT 'WAITING',
  481. `M_DIST_DATE` date NOT NULL DEFAULT '0000-00-00',
  482. `M_DIST_TYPE` varchar(64) NOT NULL DEFAULT 'INNE',
  483. `M_DIST_DESC` varchar(255) NOT NULL DEFAULT '',
  484. `M_DISTRIBUTOR` varchar(200) NOT NULL DEFAULT '',
  485. PRIMARY KEY (`ID`),
  486. KEY `P_ID` (`P_ID`),
  487. KEY `ID_PROJECT` (`ID_PROJECT`)
  488. ) ENGINE=MyISAM DEFAULT CHARSET=latin2;
  489. ";
  490. if(V::get('DBG_P', '', $_GET) > 3){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">sql (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql);echo'</pre>';}
  491. $db->query($sql);
  492. }
  493. private function _updateCacheTable() {
  494. $db = DB::getDB();
  495. $sql = "truncate table `_PRZYPOMNIJ_CACHE`; ";
  496. $db->query($sql);
  497. $sql = "insert into `_PRZYPOMNIJ_CACHE` (`ID_PROJECT`,`P_ID`,`_l_app_user`,`L_APPOITMENT_USER`,`L_APPOITMENT_DATE`)
  498. select `ID`,`P_ID`,`L_APPOITMENT_USER`,`L_APPOITMENT_USER`,`L_APPOITMENT_DATE`
  499. from `IN7_MK_BAZA_DYSTRYBUCJI`
  500. where 1=1
  501. ";
  502. $db->query($sql);
  503. // test recurse update l_app
  504. $sql = "select c._l_app_user
  505. , p.L_APPOITMENT_USER
  506. , p1.L_APPOITMENT_USER
  507. , p2.L_APPOITMENT_USER
  508. , p3.L_APPOITMENT_USER
  509. , p4.L_APPOITMENT_USER
  510. , p5.L_APPOITMENT_USER
  511. , p.ID
  512. , p1.ID
  513. , p2.ID
  514. , p3.ID
  515. , p4.ID
  516. , p5.ID
  517. from `_PRZYPOMNIJ_CACHE` as c
  518. left join `IN7_MK_BAZA_DYSTRYBUCJI` as p on (p.ID=c.ID_PROJECT)
  519. left join `IN7_MK_BAZA_DYSTRYBUCJI` as p1 on (p1.ID=p.P_ID)
  520. left join `IN7_MK_BAZA_DYSTRYBUCJI` as p2 on (p2.ID=p1.P_ID)
  521. left join `IN7_MK_BAZA_DYSTRYBUCJI` as p3 on (p3.ID=p2.P_ID)
  522. left join `IN7_MK_BAZA_DYSTRYBUCJI` as p4 on (p4.ID=p3.P_ID)
  523. left join `IN7_MK_BAZA_DYSTRYBUCJI` as p5 on (p5.ID=p4.P_ID)
  524. where c.`_l_app_user`=''
  525. ";
  526. // for i to recurse limit
  527. $sql = "update `_PRZYPOMNIJ_CACHE` as c
  528. left join `IN7_MK_BAZA_DYSTRYBUCJI` as p on (p.ID=c.ID_PROJECT)
  529. left join `IN7_MK_BAZA_DYSTRYBUCJI` as p1 on (p1.ID=p.P_ID)
  530. left join `IN7_MK_BAZA_DYSTRYBUCJI` as p2 on (p2.ID=p1.P_ID)
  531. left join `IN7_MK_BAZA_DYSTRYBUCJI` as p3 on (p3.ID=p2.P_ID)
  532. left join `IN7_MK_BAZA_DYSTRYBUCJI` as p4 on (p4.ID=p3.P_ID)
  533. left join `IN7_MK_BAZA_DYSTRYBUCJI` as p5 on (p5.ID=p4.P_ID)
  534. set
  535. c.`_l_app_user`=IF(p.`L_APPOITMENT_USER`!='', p.`L_APPOITMENT_USER`
  536. , IF(p1.`L_APPOITMENT_USER`!='', p1.`L_APPOITMENT_USER`
  537. , IF(p2.`L_APPOITMENT_USER`!='', p2.`L_APPOITMENT_USER`
  538. , IF(p3.`L_APPOITMENT_USER`!='', p3.`L_APPOITMENT_USER`
  539. , IF(p4.`L_APPOITMENT_USER`!='', p4.`L_APPOITMENT_USER`
  540. , IF(p5.`L_APPOITMENT_USER`!='', p5.`L_APPOITMENT_USER`
  541. , ''
  542. )
  543. )
  544. )
  545. )
  546. )
  547. )
  548. where c.`_l_app_user`=''
  549. ";
  550. $db->query($sql);
  551. }
  552. public function orderByDateAsc($t1, $t2) {
  553. return $this->orderByDate($t1, $t2, true);
  554. }
  555. public function orderByDateDesc($t1, $t2) {
  556. return $this->orderByDate($t1, $t2, false);
  557. }
  558. public function orderByDate($t1, $t2, $asc = true) {
  559. $a = $t1->_l_app_date;
  560. $b = $t2->_l_app_date;
  561. if ($a == $b) {
  562. return 0;
  563. }
  564. if ($asc) {
  565. return ($a > $b)? 1 : -1;
  566. } else {
  567. return ($a < $b)? 1 : -1;
  568. }
  569. }
  570. public function getTasksByDate($asc = true) {
  571. $tasks = array();
  572. foreach ($this->_data as $kType => $vTasks) {
  573. foreach ($vTasks as $kId => $vTask) {
  574. $tasks[] = $vTask;
  575. }
  576. }
  577. if ($asc) {
  578. usort($tasks, array($this, 'orderByDateAsc'));
  579. } else {
  580. usort($tasks, array($this, 'orderByDateDesc'));
  581. }
  582. return $tasks;
  583. }
  584. public function getZasobIdByType($type) {
  585. if (!isset($this->_tblIdCache[$type])) {
  586. $this->_tblIdCache[$type] = null;
  587. $allowedTypes = array('projekt', 'proces', 'koresp', 'task', 'zasob');
  588. if (empty($type) || !in_array($type, $allowedTypes)) {
  589. echo '<div class="alert alert-danger cls-line-' . __LINE__ . '">' . "Brak dostępu #" . __LINE__ . '</div>';
  590. return null;
  591. }
  592. Lib::loadClass('ProcesHelper');
  593. switch ($type) {
  594. case 'projekt':
  595. $this->_tblIdCache[$type] = ProcesHelper::getZasobTableID('IN7_MK_BAZA_DYSTRYBUCJI');
  596. break;
  597. case 'koresp':
  598. $this->_tblIdCache[$type] = ProcesHelper::getZasobTableID('IN7_DZIENNIK_KORESP');
  599. break;
  600. case 'proces':
  601. $this->_tblIdCache[$type] = ProcesHelper::getZasobTableID('CRM_PROCES');
  602. break;
  603. case 'task':
  604. $this->_tblIdCache[$type] = ProcesHelper::getZasobTableID('PROBLEMS');
  605. break;
  606. case 'zasob':
  607. $this->_tblIdCache[$type] = ProcesHelper::getZasobTableID('CRM_LISTA_ZASOBOW');
  608. break;
  609. default:
  610. echo '<div class="alert alert-danger cls-line-' . __LINE__ . '">' . "Brak dostępu #" . __LINE__ . '</div>';
  611. return null;
  612. }
  613. }
  614. return $this->_tblIdCache[$type];
  615. }
  616. private function getTblAclByType($type) {
  617. if (!isset($this->_tblAclCache[$type])) {
  618. $this->_tblAclCache[$type] = null;
  619. $zasobID = $this->getZasobIdByType($type);
  620. if (!$zasobID) {
  621. echo '<div class="alert alert-danger cls-line-' . __LINE__ . '">' . "Brak dostępu" . '</div>';
  622. return null;
  623. }
  624. Lib::loadClass('ProcesHelper');
  625. $zasobObj = ProcesHelper::getZasobTableInfo($zasobID);
  626. if (!$zasobObj) {
  627. echo '<div class="alert alert-danger cls-line-' . __LINE__ . '">' . "Zasob TABELA ID={$zasobID} nie istnieje" . '</div>';
  628. return null;
  629. }
  630. $userAcl = User::getAcl();
  631. $userAcl->fetchGroups();
  632. if (!$userAcl->hasTableAcl($zasobObj->ID)) {
  633. echo '<div class="alert alert-danger cls-line-' . __LINE__ . '">' . "Brak uprawnień do tabeli ID={$zasobObj->ID}" . '</div>';
  634. return null;
  635. }
  636. $tblAcl = $userAcl->getTableAcl($zasobObj->ID);
  637. $this->_tblAclCache[$type] = $tblAcl;
  638. }
  639. return $this->_tblAclCache[$type];
  640. }
  641. private function getDataSource($tblAcl) {
  642. $tblName = $tblAcl->getName();
  643. if (!isset($this->_dSource[$tblName])) {
  644. $this->_dSource[$tblName] = $tblAcl->getDataSource();
  645. }
  646. return $this->_dSource[$tblName];
  647. }
  648. private function getEditAppDateFields() {
  649. $fields = array();
  650. $fields[] = 'L_APPOITMENT_DATE';
  651. $fields[] = 'L_APPOITMENT_USER';
  652. $fields[] = 'L_APPOITMENT_INFO';
  653. return $fields;
  654. }
  655. public function sendAjaxEditAppDateInline() {
  656. // $_GET [rowid] => 2286, [type] => proces, [fldId] => date
  657. $rowID = V::get('rowid', 0, $_GET, 'int');
  658. $type = V::get('type', '', $_GET);
  659. $fields = $this->getEditAppDateFields();
  660. $DBG = ('1' == V::get('DBG', '', $_REQUEST));
  661. header("Content-type: text/plain");
  662. if ($rowID <= 0) {
  663. echo '<div class="alert alert-danger cls-line-' . __LINE__ . '">' . "Brak dostępu" . '</div>';
  664. exit;
  665. }
  666. $tblAcl = $this->getTblAclByType($type);
  667. if (!$tblAcl) {
  668. echo '<div class="alert alert-danger cls-line-' . __LINE__ . '">' . "Brak dostępu (acl)" . '</div>';
  669. exit;
  670. }
  671. $tblAcl->init();
  672. $dataSource = $this->getDataSource($tblAcl);
  673. if (!$dataSource) {
  674. echo '<div class="alert alert-danger cls-line-' . __LINE__ . '">' . "Brak danych" . '</div>';
  675. exit;
  676. }
  677. $row = $dataSource->getItem($rowID);
  678. if (!$row) {
  679. echo "404: No item ID({$rowID})";
  680. exit;
  681. }
  682. ?>
  683. <blockquote>Rekord <strong><?php echo $row->ID; ?></strong> typu <?php echo $type; ?></blockquote>
  684. <?php
  685. foreach ($fields as $fieldName) {
  686. $fieldID = $tblAcl->getFieldIdByName($fieldName);
  687. if (!$fieldID) {
  688. if ($DBG) echo "404: No field by name ({$fieldName})";
  689. continue;
  690. }
  691. if ($DBG) echo "fieldID: {$fieldID}\n";
  692. if (!$tblAcl->isAllowed($fieldID, 'R', $row)) {
  693. if ($DBG) echo " R not allowed\n";
  694. } else {
  695. if ($DBG) echo " R allowed\n";
  696. }
  697. if (!$tblAcl->isAllowed($fieldID, 'W', $row)) {
  698. if ($DBG) echo " W not allowed\n";
  699. } else {
  700. if ($DBG) echo " W allowed\n";
  701. }
  702. $fieldVal = '';
  703. if ($tblAcl->isAllowed($fieldID, 'R', $row)) {
  704. $fieldVal = V::get($fieldName, $fieldVal, $row);
  705. }
  706. $fieldVal = V::get("f{$fieldID}", $fieldVal, $_POST);
  707. $vCol = $tblAcl->getField($fieldID);
  708. $vCol['label'] = (!empty($vCol['label']))? $vCol['label'] : $vCol['name'];
  709. $tsValues = array();
  710. Lib::loadClass('Typespecial');
  711. $typeSpecial = Typespecial::getInstance($fieldID, $vCol['name']);
  712. if ($typeSpecial) {
  713. 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>';}
  714. $specialValues = $typeSpecial->getEditSelectedValuesByIds($zasobID, $row->ID, $fieldName, V::get($fieldName, $fieldVal, $row));
  715. 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>';}
  716. if (!empty($specialValues)) {
  717. $tsValues[$row->ID] = implode('<br>', $specialValues);
  718. }
  719. }
  720. ?>
  721. <label for="<?php echo "f{$fieldID}"; ?>" class="AjaxTableEdit-label">
  722. <strong title="<?php echo "[{$fieldID}] {$fieldName}"; ?>"><?php echo "{$vCol['label']}"; ?></strong>
  723. <?php if (!empty($vCol['opis'])) : ?>
  724. <em><?php echo $vCol['opis']; ?></em>
  725. <?php endif; ?>
  726. </label>
  727. <?php
  728. $fieldParams = array('widthClass'=>'inside-modal', 'maxGrid'=>6);
  729. if (!empty($tsValues[$row->ID])) {
  730. $fieldParams['typespecialValue'] = $tsValues[$row->ID];
  731. }
  732. $vDefault = $dataSource->getColDefault($fieldName);
  733. if (!empty($vDefault)) {
  734. $fieldParams['default'] = $vDefault;
  735. }
  736. echo $tblAcl->showFormItem('W', $fieldID, "f{$fieldID}", $fieldVal, $fieldParams, $row);
  737. }
  738. echo '<p style="padding:100px 0;"></p>';
  739. exit;
  740. }
  741. public function _getDateFltrTypes() {
  742. $fltrDate = array();
  743. $fltrDate[] = 'BRAK';
  744. $fltrDate[] = 'PO_TERMINIE';
  745. $fltrDate[] = 'DZISIAJ';
  746. $fltrDate[] = 'W_CIAGU_7_DNI';
  747. $fltrDate[] = 'PO_7_DNIACH';
  748. return $fltrDate;
  749. }
  750. public function getDateHideFltrTypes() {
  751. $fltrDate = $this->_getDateFltrTypes();
  752. foreach ($fltrDate as $i => $fltr) {
  753. $fltrDate[$i] = "fltr-hide_{$fltr}";
  754. }
  755. return $fltrDate;
  756. }
  757. public function getDateFltrTypes() {
  758. $fltrDate = $this->_getDateFltrTypes();
  759. foreach ($fltrDate as $i => $fltr) {
  760. $fltrDate[$i] = "date-{$fltr}";
  761. }
  762. return $fltrDate;
  763. }
  764. public function getTaskDateFltrType($taskDate) {
  765. $nowDay = date("Y-m-d");
  766. $nowDayPlus7 = date("Y-m-d", mktime(0,0,0, date("m"), date("d") + 7, date("Y")));
  767. $clsData = '';
  768. $appDay = substr($taskDate, 0, 10);
  769. if (empty($taskDate)) {
  770. $clsData = 'date-BRAK';
  771. } else if ($appDay < $nowDay) {
  772. $clsData = 'date-PO_TERMINIE';
  773. } else if ($appDay == $nowDay) {
  774. $clsData = 'date-DZISIAJ';
  775. } else if ($appDay > $nowDay && $appDay <= $nowDayPlus7) {
  776. $clsData = 'date-W_CIAGU_7_DNI';
  777. } else {
  778. $clsData = 'date-PO_7_DNIACH';
  779. }
  780. return $clsData;
  781. }
  782. public function sendAjaxEditAppDateInlineSave() {
  783. $DBG = ('1' == V::get('DBG', '', $_REQUEST));
  784. sleep(1);// TODO: RMME DBG loading
  785. $rowID = V::get('rowid', 0, $_POST, 'int');
  786. $type = V::get('type', '', $_POST);
  787. $fields = $this->getEditAppDateFields();
  788. if ($rowID <= 0) {
  789. echo '<div class="alert alert-danger cls-line-' . __LINE__ . '">' . "Brak dostępu" . '</div>';
  790. exit;
  791. }
  792. $tblAcl = $this->getTblAclByType($type);
  793. if (!$tblAcl) {
  794. echo '<div class="alert alert-danger cls-line-' . __LINE__ . '">' . "Brak dostępu (acl)" . '</div>';
  795. exit;
  796. }
  797. $tblAcl->init();
  798. $dataSource = $this->getDataSource($tblAcl);
  799. if (!$dataSource) {
  800. echo '<div class="alert alert-danger cls-line-' . __LINE__ . '">' . "Brak danych" . '</div>';
  801. exit;
  802. }
  803. $row = $dataSource->getItem($rowID);
  804. if (!$row) {
  805. echo "404: No item ID({$rowID})";
  806. exit;
  807. }
  808. $sqlObj = new stdClass();
  809. $allData = new stdClass();
  810. foreach ($fields as $fieldName) {
  811. $fieldID = $tblAcl->getFieldIdByName($fieldName);
  812. if (!$fieldID) {
  813. if ($DBG) echo "404: No field by name ({$fieldName})";
  814. continue;
  815. }
  816. if ($DBG) echo "fieldID: {$fieldID}\n";
  817. if (!$tblAcl->isAllowed($fieldID, 'W', $row)) {
  818. if ($DBG) echo " W not allowed\n";
  819. continue;
  820. } else {
  821. if ($DBG) echo " W allowed\n";
  822. }
  823. $fieldVal = V::get($fieldName, '', $row);
  824. $sqlObj->{$fieldName} = V::get("f{$fieldID}", $fieldVal, $_POST);
  825. if (empty($_POST["f{$fieldID}"]) && strlen($_POST["f{$fieldID}"]) == 0) {// fix bug in input type date and value="0000-00-00"
  826. $sqlObj->{$fieldName} = $tblAcl->fixEmptyValueFromUser($fieldID);
  827. }
  828. }
  829. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">TODO: save type ('.$type.') ID(' . $rowid . ') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sqlObj);echo'</pre>';}
  830. $sqlObj->ID = $row->ID;
  831. $dbID = $tblAcl->getDB();
  832. $db = DB::getDB($dbID);
  833. if (!$db) {
  834. header('HTTP/1.0 406 Not Acceptable');
  835. exit;
  836. }
  837. $tblName = $tblAcl->getName();
  838. $sqlObj->ID = $rowID;
  839. if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">TODO: Save ('.$tblName.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sqlObj);echo'</pre>';}
  840. $allData = array();
  841. $allData['L_APPOITMENT_DATE'] = $sqlObj->L_APPOITMENT_DATE;
  842. $allData['L_APPOITMENT_USER'] = $sqlObj->L_APPOITMENT_USER;
  843. $allData['L_APPOITMENT_INFO'] = $sqlObj->L_APPOITMENT_INFO;
  844. $ret = $db->UPDATE_OBJ($tblName, $sqlObj);
  845. if ($ret > 0) {
  846. echo '<div class="alert alert-success">';
  847. echo "Rekord zapisany pomyślnie";//"Record saved successfully";
  848. echo '</div>';
  849. echo '<div class="EditAppDateInlineSave" style="display:none">';
  850. echo '<span class="l_app_date">' . $allData['L_APPOITMENT_DATE'] . '</span>';
  851. echo '<span class="l_app_user">' . $allData['L_APPOITMENT_USER'] . '</span>';
  852. echo '<span class="l_app_info">' . $allData['L_APPOITMENT_INFO'] . '</span>';
  853. echo '<span class="date_fltr_type">' . $this->getTaskDateFltrType($allData['L_APPOITMENT_DATE']) . '</span>';
  854. echo '</div>';
  855. } else if ($ret == 0) {
  856. echo '<div class="alert alert-info">';
  857. echo "Nie wprowadzono żadnych zmian";
  858. if ($db->has_errors()) {
  859. $errors = $db->get_errors();
  860. echo implode('<br>', $errors);
  861. }
  862. echo '</div>';
  863. } else {
  864. echo '<div class="alert alert-danger">';
  865. echo '<h4>' . "Wystąpiły błędy!" . '</h4>';
  866. if ($db->has_errors()) {
  867. $errors = $db->get_errors();
  868. echo implode('<br>', $errors);
  869. }
  870. echo '</div>';
  871. }
  872. exit;
  873. }
  874. }