Przypomnij.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970
  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. $tblName = 'ADMIN_USERS';
  422. $tblZasobId = ProcesHelper::getZasobTableID($tblName);
  423. if (!$userAcl->hasTableAcl($tblZasobId)) {
  424. DBG::_('DBG_P', '>2', '!hasTableAcl', null, __CLASS__, __FUNCTION__, __LINE__);
  425. return null;
  426. }
  427. $tblAcl = $userAcl->getTableAcl($tblZasobId);
  428. if (!$tblAcl->hasFieldPerm($tblAcl->getFieldIdByName('ID'), 'R')) {
  429. DBG::_('DBG_P', '>2', '!$tblAcl->hasFieldPerm(ID, R)', $tblAcl, __CLASS__, __FUNCTION__, __LINE__);
  430. return null;
  431. }
  432. $ds = $tblAcl->getDataSource();
  433. $sqlAclFltr = '';
  434. if ($ds->hasAclGroupFields()) {
  435. $fldGroupWrite = $ds->getFieldGroupWrite();
  436. $fldGroupRead = $ds->getFieldGroupRead();
  437. $sqlFltr = "
  438. t.`{$fldGroupWrite}` in({$sqlUsrAclGroups})
  439. and t.`{$fldGroupRead}` in({$sqlUsrAclGroups})
  440. ";
  441. $sqlAclFltr = " and {$sqlFltr}";
  442. }
  443. else {
  444. DBG::_('DBG_P', '>0', '!hasAclGroupFields tblAcl', $tblAcl, __CLASS__, __FUNCTION__, __LINE__);
  445. }
  446. $sqlFoundUsers = array_keys($allowedUsers);
  447. $sqlFoundUsers = "'" . implode("','", $sqlFoundUsers) . "'";
  448. $sql = "select t.`ADM_ACCOUNT`
  449. from `{$tblName}` t
  450. where t.`ADM_ACCOUNT` in({$sqlFoundUsers})
  451. {$sqlAclFltr}
  452. ";
  453. DBG::_('DBG_P', '>2', 'sql', $sql, __CLASS__, __FUNCTION__, __LINE__);
  454. $res = $db->query($sql) or die("blad zapytania do bazy {$sql}");
  455. while ($r = $db->fetch($res)) {
  456. $allowedUsersFiltered[$r->ADM_ACCOUNT] = true;
  457. }
  458. $allowedUsers = $allowedUsersFiltered;
  459. }
  460. DBG::_('DBG_P', '>2', 'allowedUsersFiltered', $allowedUsersFiltered, __CLASS__, __FUNCTION__, __LINE__);
  461. ksort($allowedUsers);
  462. return $allowedUsers;
  463. }
  464. private function _createCacheTable() {
  465. $db = DB::getDB();
  466. $sql = "CREATE TABLE IF NOT EXISTS `_PRZYPOMNIJ_CACHE` (
  467. `ID` int(11) NOT NULL AUTO_INCREMENT,
  468. `ID_PROJECT` int(11) NOT NULL,
  469. `_l_app_user` varchar(40) NOT NULL DEFAULT '',
  470. `P_ID` varchar(20) NOT NULL DEFAULT '0',
  471. `A_RECORD_CREATE_DATE` datetime NOT NULL,
  472. `A_RECORD_CREATE_AUTHOR` varchar(40) NOT NULL DEFAULT '',
  473. `A_RECORD_UPDATE_DATE` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  474. `A_RECORD_UPDATE_AUTHOR` varchar(40) NOT NULL DEFAULT '',
  475. `L_APPOITMENT_DATE` varchar(30) NOT NULL DEFAULT '',
  476. `L_APPOITMENT_USER` varchar(40) NOT NULL DEFAULT '',
  477. `L_APPOITMENT_INFO` varchar(200) NOT NULL DEFAULT '',
  478. `L_CALENDAR` enum('NO','YES') NOT NULL DEFAULT 'NO',
  479. `A_STATUS` enum('WAITING','NORMAL','MONITOR','WARNING','OFF_SOFT','OFF_HARD','DELETED') NOT NULL DEFAULT 'WAITING',
  480. `M_DIST_DATE` date NOT NULL DEFAULT '0000-00-00',
  481. `M_DIST_TYPE` varchar(64) NOT NULL DEFAULT 'INNE',
  482. `M_DIST_DESC` varchar(255) NOT NULL DEFAULT '',
  483. `M_DISTRIBUTOR` varchar(200) NOT NULL DEFAULT '',
  484. PRIMARY KEY (`ID`),
  485. KEY `P_ID` (`P_ID`),
  486. KEY `ID_PROJECT` (`ID_PROJECT`)
  487. ) ENGINE=MyISAM DEFAULT CHARSET=latin2;
  488. ";
  489. 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>';}
  490. $db->query($sql);
  491. }
  492. private function _updateCacheTable() {
  493. $db = DB::getDB();
  494. $sql = "truncate table `_PRZYPOMNIJ_CACHE`; ";
  495. $db->query($sql);
  496. $sql = "insert into `_PRZYPOMNIJ_CACHE` (`ID_PROJECT`,`P_ID`,`_l_app_user`,`L_APPOITMENT_USER`,`L_APPOITMENT_DATE`)
  497. select `ID`,`P_ID`,`L_APPOITMENT_USER`,`L_APPOITMENT_USER`,`L_APPOITMENT_DATE`
  498. from `IN7_MK_BAZA_DYSTRYBUCJI`
  499. where 1=1
  500. ";
  501. $db->query($sql);
  502. // test recurse update l_app
  503. $sql = "select c._l_app_user
  504. , p.L_APPOITMENT_USER
  505. , p1.L_APPOITMENT_USER
  506. , p2.L_APPOITMENT_USER
  507. , p3.L_APPOITMENT_USER
  508. , p4.L_APPOITMENT_USER
  509. , p5.L_APPOITMENT_USER
  510. , p.ID
  511. , p1.ID
  512. , p2.ID
  513. , p3.ID
  514. , p4.ID
  515. , p5.ID
  516. from `_PRZYPOMNIJ_CACHE` as c
  517. left join `IN7_MK_BAZA_DYSTRYBUCJI` as p on (p.ID=c.ID_PROJECT)
  518. left join `IN7_MK_BAZA_DYSTRYBUCJI` as p1 on (p1.ID=p.P_ID)
  519. left join `IN7_MK_BAZA_DYSTRYBUCJI` as p2 on (p2.ID=p1.P_ID)
  520. left join `IN7_MK_BAZA_DYSTRYBUCJI` as p3 on (p3.ID=p2.P_ID)
  521. left join `IN7_MK_BAZA_DYSTRYBUCJI` as p4 on (p4.ID=p3.P_ID)
  522. left join `IN7_MK_BAZA_DYSTRYBUCJI` as p5 on (p5.ID=p4.P_ID)
  523. where c.`_l_app_user`=''
  524. ";
  525. // for i to recurse limit
  526. $sql = "update `_PRZYPOMNIJ_CACHE` as c
  527. left join `IN7_MK_BAZA_DYSTRYBUCJI` as p on (p.ID=c.ID_PROJECT)
  528. left join `IN7_MK_BAZA_DYSTRYBUCJI` as p1 on (p1.ID=p.P_ID)
  529. left join `IN7_MK_BAZA_DYSTRYBUCJI` as p2 on (p2.ID=p1.P_ID)
  530. left join `IN7_MK_BAZA_DYSTRYBUCJI` as p3 on (p3.ID=p2.P_ID)
  531. left join `IN7_MK_BAZA_DYSTRYBUCJI` as p4 on (p4.ID=p3.P_ID)
  532. left join `IN7_MK_BAZA_DYSTRYBUCJI` as p5 on (p5.ID=p4.P_ID)
  533. set
  534. c.`_l_app_user`=IF(p.`L_APPOITMENT_USER`!='', p.`L_APPOITMENT_USER`
  535. , IF(p1.`L_APPOITMENT_USER`!='', p1.`L_APPOITMENT_USER`
  536. , IF(p2.`L_APPOITMENT_USER`!='', p2.`L_APPOITMENT_USER`
  537. , IF(p3.`L_APPOITMENT_USER`!='', p3.`L_APPOITMENT_USER`
  538. , IF(p4.`L_APPOITMENT_USER`!='', p4.`L_APPOITMENT_USER`
  539. , IF(p5.`L_APPOITMENT_USER`!='', p5.`L_APPOITMENT_USER`
  540. , ''
  541. )
  542. )
  543. )
  544. )
  545. )
  546. )
  547. where c.`_l_app_user`=''
  548. ";
  549. $db->query($sql);
  550. }
  551. public function orderByDateAsc($t1, $t2) {
  552. return $this->orderByDate($t1, $t2, true);
  553. }
  554. public function orderByDateDesc($t1, $t2) {
  555. return $this->orderByDate($t1, $t2, false);
  556. }
  557. public function orderByDate($t1, $t2, $asc = true) {
  558. $a = $t1->_l_app_date;
  559. $b = $t2->_l_app_date;
  560. if ($a == $b) {
  561. return 0;
  562. }
  563. if ($asc) {
  564. return ($a > $b)? 1 : -1;
  565. } else {
  566. return ($a < $b)? 1 : -1;
  567. }
  568. }
  569. public function getTasksByDate($asc = true) {
  570. $tasks = array();
  571. foreach ($this->_data as $kType => $vTasks) {
  572. foreach ($vTasks as $kId => $vTask) {
  573. $tasks[] = $vTask;
  574. }
  575. }
  576. if ($asc) {
  577. usort($tasks, array($this, 'orderByDateAsc'));
  578. } else {
  579. usort($tasks, array($this, 'orderByDateDesc'));
  580. }
  581. return $tasks;
  582. }
  583. public function getZasobIdByType($type) {
  584. if (!isset($this->_tblIdCache[$type])) {
  585. $this->_tblIdCache[$type] = null;
  586. $allowedTypes = array('projekt', 'proces', 'koresp', 'task', 'zasob');
  587. if (empty($type) || !in_array($type, $allowedTypes)) {
  588. echo '<div class="alert alert-danger cls-line-' . __LINE__ . '">' . "Brak dostępu #" . __LINE__ . '</div>';
  589. return null;
  590. }
  591. Lib::loadClass('ProcesHelper');
  592. switch ($type) {
  593. case 'projekt':
  594. $this->_tblIdCache[$type] = ProcesHelper::getZasobTableID('IN7_MK_BAZA_DYSTRYBUCJI');
  595. break;
  596. case 'koresp':
  597. $this->_tblIdCache[$type] = ProcesHelper::getZasobTableID('IN7_DZIENNIK_KORESP');
  598. break;
  599. case 'proces':
  600. $this->_tblIdCache[$type] = ProcesHelper::getZasobTableID('CRM_PROCES');
  601. break;
  602. case 'task':
  603. $this->_tblIdCache[$type] = ProcesHelper::getZasobTableID('PROBLEMS');
  604. break;
  605. case 'zasob':
  606. $this->_tblIdCache[$type] = ProcesHelper::getZasobTableID('CRM_LISTA_ZASOBOW');
  607. break;
  608. default:
  609. echo '<div class="alert alert-danger cls-line-' . __LINE__ . '">' . "Brak dostępu #" . __LINE__ . '</div>';
  610. return null;
  611. }
  612. }
  613. return $this->_tblIdCache[$type];
  614. }
  615. private function getTblAclByType($type) {
  616. if (!isset($this->_tblAclCache[$type])) {
  617. $this->_tblAclCache[$type] = null;
  618. $zasobID = $this->getZasobIdByType($type);
  619. if (!$zasobID) {
  620. echo '<div class="alert alert-danger cls-line-' . __LINE__ . '">' . "Brak dostępu" . '</div>';
  621. return null;
  622. }
  623. Lib::loadClass('ProcesHelper');
  624. $zasobObj = ProcesHelper::getZasobTableInfo($zasobID);
  625. if (!$zasobObj) {
  626. echo '<div class="alert alert-danger cls-line-' . __LINE__ . '">' . "Zasob TABELA ID={$zasobID} nie istnieje" . '</div>';
  627. return null;
  628. }
  629. $userAcl = User::getAcl();
  630. $userAcl->fetchGroups();
  631. if (!$userAcl->hasTableAcl($zasobObj->ID)) {
  632. echo '<div class="alert alert-danger cls-line-' . __LINE__ . '">' . "Brak uprawnień do tabeli ID={$zasobObj->ID}" . '</div>';
  633. return null;
  634. }
  635. $tblAcl = $userAcl->getTableAcl($zasobObj->ID);
  636. $this->_tblAclCache[$type] = $tblAcl;
  637. }
  638. return $this->_tblAclCache[$type];
  639. }
  640. private function getDataSource($tblAcl) {
  641. $tblName = $tblAcl->getName();
  642. if (!isset($this->_dSource[$tblName])) {
  643. $this->_dSource[$tblName] = $tblAcl->getDataSource();
  644. }
  645. return $this->_dSource[$tblName];
  646. }
  647. private function getEditAppDateFields() {
  648. $fields = array();
  649. $fields[] = 'L_APPOITMENT_DATE';
  650. $fields[] = 'L_APPOITMENT_USER';
  651. $fields[] = 'L_APPOITMENT_INFO';
  652. return $fields;
  653. }
  654. public function sendAjaxEditAppDateInline() {
  655. // $_GET [rowid] => 2286, [type] => proces, [fldId] => date
  656. $rowID = V::get('rowid', 0, $_GET, 'int');
  657. $type = V::get('type', '', $_GET);
  658. $fields = $this->getEditAppDateFields();
  659. $DBG = ('1' == V::get('DBG', '', $_REQUEST));
  660. header("Content-type: text/plain");
  661. if ($rowID <= 0) {
  662. echo '<div class="alert alert-danger cls-line-' . __LINE__ . '">' . "Brak dostępu" . '</div>';
  663. exit;
  664. }
  665. $tblAcl = $this->getTblAclByType($type);
  666. if (!$tblAcl) {
  667. echo '<div class="alert alert-danger cls-line-' . __LINE__ . '">' . "Brak dostępu (acl)" . '</div>';
  668. exit;
  669. }
  670. $tblAcl->init();
  671. $dataSource = $this->getDataSource($tblAcl);
  672. if (!$dataSource) {
  673. echo '<div class="alert alert-danger cls-line-' . __LINE__ . '">' . "Brak danych" . '</div>';
  674. exit;
  675. }
  676. $row = $dataSource->getItem($rowID);
  677. if (!$row) {
  678. echo "404: No item ID({$rowID})";
  679. exit;
  680. }
  681. ?>
  682. <blockquote>Rekord <strong><?php echo $row->ID; ?></strong> typu <?php echo $type; ?></blockquote>
  683. <?php
  684. foreach ($fields as $fieldName) {
  685. $fieldID = $tblAcl->getFieldIdByName($fieldName);
  686. if (!$fieldID) {
  687. if ($DBG) echo "404: No field by name ({$fieldName})";
  688. continue;
  689. }
  690. if ($DBG) echo "fieldID: {$fieldID}\n";
  691. if (!$tblAcl->isAllowed($fieldID, 'R', $row)) {
  692. if ($DBG) echo " R not allowed\n";
  693. } else {
  694. if ($DBG) echo " R allowed\n";
  695. }
  696. if (!$tblAcl->isAllowed($fieldID, 'W', $row)) {
  697. if ($DBG) echo " W not allowed\n";
  698. } else {
  699. if ($DBG) echo " W allowed\n";
  700. }
  701. $fieldVal = '';
  702. if ($tblAcl->isAllowed($fieldID, 'R', $row)) {
  703. $fieldVal = V::get($fieldName, $fieldVal, $row);
  704. }
  705. $fieldVal = V::get("f{$fieldID}", $fieldVal, $_POST);
  706. $vCol = $tblAcl->getField($fieldID);
  707. $vCol['label'] = (!empty($vCol['label']))? $vCol['label'] : $vCol['name'];
  708. $tsValues = array();
  709. Lib::loadClass('Typespecial');
  710. $typeSpecial = Typespecial::getInstance($fieldID, $vCol['name']);
  711. if ($typeSpecial) {
  712. 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>';}
  713. $specialValues = $typeSpecial->getEditSelectedValuesByIds($zasobID, $row->ID, $fieldName, V::get($fieldName, $fieldVal, $row));
  714. 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>';}
  715. if (!empty($specialValues)) {
  716. $tsValues[$row->ID] = implode('<br>', $specialValues);
  717. }
  718. }
  719. ?>
  720. <label for="<?php echo "f{$fieldID}"; ?>" class="AjaxTableEdit-label">
  721. <strong title="<?php echo "[{$fieldID}] {$fieldName}"; ?>"><?php echo "{$vCol['label']}"; ?></strong>
  722. <?php if (!empty($vCol['opis'])) : ?>
  723. <em><?php echo $vCol['opis']; ?></em>
  724. <?php endif; ?>
  725. </label>
  726. <?php
  727. $fieldParams = array('widthClass'=>'inside-modal', 'maxGrid'=>6);
  728. if (!empty($tsValues[$row->ID])) {
  729. $fieldParams['typespecialValue'] = $tsValues[$row->ID];
  730. }
  731. $vDefault = $dataSource->getColDefault($fieldName);
  732. if (!empty($vDefault)) {
  733. $fieldParams['default'] = $vDefault;
  734. }
  735. echo $tblAcl->showFormItem('W', $fieldID, "f{$fieldID}", $fieldVal, $fieldParams, $row);
  736. }
  737. echo '<p style="padding:100px 0;"></p>';
  738. exit;
  739. }
  740. public function _getDateFltrTypes() {
  741. $fltrDate = array();
  742. $fltrDate[] = 'BRAK';
  743. $fltrDate[] = 'PO_TERMINIE';
  744. $fltrDate[] = 'DZISIAJ';
  745. $fltrDate[] = 'W_CIAGU_7_DNI';
  746. $fltrDate[] = 'PO_7_DNIACH';
  747. return $fltrDate;
  748. }
  749. public function getDateHideFltrTypes() {
  750. $fltrDate = $this->_getDateFltrTypes();
  751. foreach ($fltrDate as $i => $fltr) {
  752. $fltrDate[$i] = "fltr-hide_{$fltr}";
  753. }
  754. return $fltrDate;
  755. }
  756. public function getDateFltrTypes() {
  757. $fltrDate = $this->_getDateFltrTypes();
  758. foreach ($fltrDate as $i => $fltr) {
  759. $fltrDate[$i] = "date-{$fltr}";
  760. }
  761. return $fltrDate;
  762. }
  763. public function getTaskDateFltrType($taskDate) {
  764. $nowDay = date("Y-m-d");
  765. $nowDayPlus7 = date("Y-m-d", mktime(0,0,0, date("m"), date("d") + 7, date("Y")));
  766. $clsData = '';
  767. $appDay = substr($taskDate, 0, 10);
  768. if (empty($taskDate)) {
  769. $clsData = 'date-BRAK';
  770. } else if ($appDay < $nowDay) {
  771. $clsData = 'date-PO_TERMINIE';
  772. } else if ($appDay == $nowDay) {
  773. $clsData = 'date-DZISIAJ';
  774. } else if ($appDay > $nowDay && $appDay <= $nowDayPlus7) {
  775. $clsData = 'date-W_CIAGU_7_DNI';
  776. } else {
  777. $clsData = 'date-PO_7_DNIACH';
  778. }
  779. return $clsData;
  780. }
  781. public function sendAjaxEditAppDateInlineSave() {
  782. $DBG = ('1' == V::get('DBG', '', $_REQUEST));
  783. sleep(1);// TODO: RMME DBG loading
  784. $rowID = V::get('rowid', 0, $_POST, 'int');
  785. $type = V::get('type', '', $_POST);
  786. $fields = $this->getEditAppDateFields();
  787. if ($rowID <= 0) {
  788. echo '<div class="alert alert-danger cls-line-' . __LINE__ . '">' . "Brak dostępu" . '</div>';
  789. exit;
  790. }
  791. $tblAcl = $this->getTblAclByType($type);
  792. if (!$tblAcl) {
  793. echo '<div class="alert alert-danger cls-line-' . __LINE__ . '">' . "Brak dostępu (acl)" . '</div>';
  794. exit;
  795. }
  796. $tblAcl->init();
  797. $dataSource = $this->getDataSource($tblAcl);
  798. if (!$dataSource) {
  799. echo '<div class="alert alert-danger cls-line-' . __LINE__ . '">' . "Brak danych" . '</div>';
  800. exit;
  801. }
  802. $row = $dataSource->getItem($rowID);
  803. if (!$row) {
  804. echo "404: No item ID({$rowID})";
  805. exit;
  806. }
  807. $sqlObj = new stdClass();
  808. $allData = new stdClass();
  809. foreach ($fields as $fieldName) {
  810. $fieldID = $tblAcl->getFieldIdByName($fieldName);
  811. if (!$fieldID) {
  812. if ($DBG) echo "404: No field by name ({$fieldName})";
  813. continue;
  814. }
  815. if ($DBG) echo "fieldID: {$fieldID}\n";
  816. if (!$tblAcl->isAllowed($fieldID, 'W', $row)) {
  817. if ($DBG) echo " W not allowed\n";
  818. continue;
  819. } else {
  820. if ($DBG) echo " W allowed\n";
  821. }
  822. $fieldVal = V::get($fieldName, '', $row);
  823. $sqlObj->{$fieldName} = V::get("f{$fieldID}", $fieldVal, $_POST);
  824. if (empty($_POST["f{$fieldID}"]) && strlen($_POST["f{$fieldID}"]) == 0) {// fix bug in input type date and value="0000-00-00"
  825. $sqlObj->{$fieldName} = $tblAcl->fixEmptyValueFromUser($fieldID);
  826. }
  827. }
  828. 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>';}
  829. $sqlObj->ID = $row->ID;
  830. $dbID = $tblAcl->getDB();
  831. $db = DB::getDB($dbID);
  832. if (!$db) {
  833. header('HTTP/1.0 406 Not Acceptable');
  834. exit;
  835. }
  836. $tblName = $tblAcl->getName();
  837. $sqlObj->ID = $rowID;
  838. 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>';}
  839. $allData = array();
  840. $allData['L_APPOITMENT_DATE'] = $sqlObj->L_APPOITMENT_DATE;
  841. $allData['L_APPOITMENT_USER'] = $sqlObj->L_APPOITMENT_USER;
  842. $allData['L_APPOITMENT_INFO'] = $sqlObj->L_APPOITMENT_INFO;
  843. $ret = $db->UPDATE_OBJ($tblName, $sqlObj);
  844. if ($ret > 0) {
  845. echo '<div class="alert alert-success">';
  846. echo "Rekord zapisany pomyślnie";//"Record saved successfully";
  847. echo '</div>';
  848. echo '<div class="EditAppDateInlineSave" style="display:none">';
  849. echo '<span class="l_app_date">' . $allData['L_APPOITMENT_DATE'] . '</span>';
  850. echo '<span class="l_app_user">' . $allData['L_APPOITMENT_USER'] . '</span>';
  851. echo '<span class="l_app_info">' . $allData['L_APPOITMENT_INFO'] . '</span>';
  852. echo '<span class="date_fltr_type">' . $this->getTaskDateFltrType($allData['L_APPOITMENT_DATE']) . '</span>';
  853. echo '</div>';
  854. } else if ($ret == 0) {
  855. echo '<div class="alert alert-info">';
  856. echo "Nie wprowadzono żadnych zmian";
  857. if ($db->has_errors()) {
  858. $errors = $db->get_errors();
  859. echo implode('<br>', $errors);
  860. }
  861. echo '</div>';
  862. } else {
  863. echo '<div class="alert alert-danger">';
  864. echo '<h4>' . "Wystąpiły błędy!" . '</h4>';
  865. if ($db->has_errors()) {
  866. $errors = $db->get_errors();
  867. echo implode('<br>', $errors);
  868. }
  869. echo '</div>';
  870. }
  871. exit;
  872. }
  873. }