proces.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. <?php
  2. Lib::loadClass('ProcesHelper');
  3. Lib::loadClass('DebugExecutionTime');
  4. Lib::loadClass('UI');
  5. /**
  6. * @param $_GET['EDIT'] - ID rekordu do edycji (inline)
  7. * @param $_GET['EDIT_ID'] - ID rekordu do edycji (inline)
  8. */
  9. function task_CRM_PROCES() {
  10. User_procesy5_check_access();
  11. UI::setTitleJsTag("⋋ Procesy (drzewo)");
  12. $_GET['ADM_AREA'] = V::get('ADM_AREA', "BN%", $_GET);
  13. $_GET['EDIT'] = V::get('EDIT', 0, $_GET, 'int');
  14. if (($edit_id = V::get('EDIT_ID', 0, $_GET, 'int')) > 0) {
  15. $_GET['EDIT'] = $edit_id;
  16. }
  17. $tbl = 'CRM_PROCES';
  18. $DBG_TIME = ('1' == V::get('DBG_TIME', '', $_GET));
  19. $dbgExecTime = new DebugExecutionTime();
  20. if ($DBG_TIME) $dbgExecTime->activate();
  21. $dbgExecTime->log('start');
  22. // form decorators:
  23. $tbl_search_params = array();
  24. $tbl_search_params['ID'] = 'ID';
  25. $tbl_search_params['PARENT_ID'] = 'P_ID';
  26. $tbl_search_params['TYPE'] = 'TYPE';
  27. $tbl_search_params['DESC'] = 'DESC';
  28. $tbl_search_params['OPIS'] = 'OPIS';
  29. $tbl_search_params['DESC_PL'] = 'DESC_PL';
  30. $tbl_search_params['TAGS'] = 'TAGS';
  31. $tbl_search_params['A_STATUS'] = 'A_STATUS';
  32. $tbl_search_params['L_APPOITMENT_USER'] = 'L_APPOITMENT_USER';
  33. $tbl_search_params['L_APPOITMENT_DATE'] = 'L_APPOITMENT_DATE';
  34. $tbl_search_params['L_APPOITMENT_INFO'] = 'L_APPOITMENT_INFO';
  35. $tbl_search_params['A_ADM_COMPANY'] = 'A_ADM_COMPANY';
  36. $tbl_search_params['IF_TRUE_GOTO'] = 'IF_TRUE_GOTO';
  37. $tbl_search_params['IF_TRUE_GOTO_FLAG'] = 'IF_TRUE_GOTO_FLAG';
  38. $tbl_search_params['A_RECORD_CREATE_AUTHOR'] = 'A_RECORD_CREATE_AUTHOR';
  39. $tbl_search_params['A_RECORD_CREATE_DATE'] = 'A_RECORD_CREATE_DATE';
  40. $tbl_search_params['A_RECORD_UPDATE_AUTHOR'] = 'A_RECORD_UPDATE_AUTHOR';
  41. $tbl_search_params['A_RECORD_UPDATE_DATE'] = 'A_RECORD_UPDATE_DATE';
  42. Lib::loadClass('FilterLast');
  43. $filter_last = new FilterLast( $_REQUEST, $tbl, 'session');
  44. $filter_last->add_filter( 'last_id', array('filtr_id','filtr_search_id','ID','EDIT'), "Ostatnio uzywane ID", 'int' );
  45. $filter_last->_save_args();// save args from request
  46. {// TABLE - Filter
  47. $tbl = 'CRM_PROCES';
  48. $tbl_filter = new stdClass();
  49. $tbl_filter->key = 'tbl-'.$tbl;
  50. $tbl_filter->filters = array();
  51. // TODO: stronicowanie $tbl_filter->filters: _page_nr, _limit, _total (need sql - only after change params)
  52. // read args from session, or get dafault values
  53. foreach ($tbl_search_params as $k => $req_field_name) {
  54. $tbl_filter->filters[$req_field_name] = V::get($req_field_name, '%', $_SESSION[$tbl_filter->key]);
  55. }
  56. // read args from $_GET if isset
  57. foreach ($tbl_search_params as $k => $req_field_name) {
  58. if (isset($_GET[$req_field_name])) {
  59. $tbl_filter->filters[$req_field_name] = $_GET[$req_field_name];
  60. }
  61. }
  62. // save args in session and $_GET
  63. foreach ($tbl_filter->filters as $req_field_name => $v) {
  64. $_SESSION[$tbl_filter->key][$req_field_name] = $v;
  65. $_GET[$req_field_name] = $v;
  66. }
  67. echo'<div style="border:1px solid red; display:none;">';
  68. foreach ($tbl_filter->filters as $req_field_name => $v) {
  69. echo'<br />arg['.$req_field_name.'] = '.$v;
  70. }
  71. echo'</div>';
  72. }// TABLE - Filter
  73. {// TREE - Filter
  74. $tbl = 'CRM_PROCES';
  75. Lib::loadClass('FilterFactory');
  76. $tree_procesy_filter = FilterFactory::build($tbl);
  77. $tree_procesy_filter->setArgs($_GET);
  78. $tree_procesy_filter->set_trash('filtr_id', -1);
  79. {// zapisz stan - ajax function to save filters stan and opened tree nodes, etc.
  80. $filtr_ses_key = $tree_procesy_filter->_key;
  81. $cookie_key = 'TREE_'.$tbl;
  82. $profile_key = 'Filtr_'.$filtr_ses_key;
  83. if (V::get('save_profile', '', $_REQUEST)) {
  84. $profile_val = array();
  85. $profile_val['filtr'] = $_SESSION[$filtr_ses_key];
  86. $profile_val['tree'] = $_COOKIE[$cookie_key];// cookie key from Tree class - 'TREE_'. $tbl @see __construct
  87. User::setProfile($profile_key, $profile_val);
  88. $ret = User::saveProfile();
  89. }
  90. else if (V::get('load_profile', '', $_REQUEST)) {
  91. //User::loadProfile();// proile is loaded in USERS_COLUMN_INIT after login
  92. $profile_val = User::getProfile($profile_key);
  93. $_COOKIE[$cookie_key] = $profile_val['tree'];
  94. echo'<script type="text/javascript">'."
  95. jQuery(document).ready(function(){
  96. jQuery.cookie('".$cookie_key."','" . $_COOKIE[$cookie_key] . "');
  97. });
  98. ".'</script>';
  99. $_SESSION[$filtr_ses_key] = $profile_val['filtr'];
  100. $tree_procesy_filter->_read_args( true );// force load args from session
  101. }
  102. }// zapisz stan - ajax function to save filters stan and opened tree nodes, etc.
  103. $tree_procesy_filter->_save_args();// force save_args (execute at the end of show_filters)
  104. echo'<div style="border:1px solid red; display:none;">';
  105. foreach ($tree_procesy_filter->filters as $arg => $v) {
  106. echo'<br />arg['.$arg.'] = '.$tree_procesy_filter->get_arg($arg);
  107. }
  108. echo'</div>';
  109. }// TREE - Filter
  110. echo'<h1>';
  111. echo App::link("Procesy", array('task'=>App::get_task(), 'filtr_id'=>''));
  112. if ($tree_procesy_filter->is_trash()) {//$_GET['filtr_id'] == -1) {
  113. echo ' &raquo; '."Kosz";
  114. echo " " . App::link("czyść", array('task'=>App::get_task(), 'function_init'=>"fun_CRM_PROCES_clean_trash"), array('title'=>"Ustaw status rekordów w koszu na DELETED", 'class'=>'btn-p5', 'style'=>'font-size:13px;'));
  115. } else if ($tree_procesy_filter->get_arg('filtr_id') > 0) {//$_GET['filtr_id'] > 0) {
  116. echo ' &raquo; '."Proces [".$tree_procesy_filter->get_arg('filtr_id')."]";
  117. }
  118. echo '<span class="pull-right">'.App::link("Mapa procesów", array('task'=>'VIEW_PROCES_MAP')).'</span>';
  119. echo'</h1>';
  120. UI::startTag('ul', ['class' => "breadcrumb"]);
  121. UI::startTag('li');
  122. UI::tag('a', ['href'=>"index.php?_route=ViewTableAjax&namespace=default_db/CRM_PROCES"], "Tabela Procesy <i style=\"color:silver\">(CRM_PROCES)</i>");
  123. UI::endTag('li');
  124. UI::startTag('li');
  125. UI::tag('a', ['href'=>"index.php?_route=ViewTableAjax&namespace=default_db/CRM_PROCES#CREATE"], "<span class=\"glyphicon glyphicon-plus\"></span> Dodaj nowy rekord");
  126. UI::endTag('li');
  127. UI::endTag('ul');
  128. $TREE = array();
  129. echo'<div id="tree"></div>';
  130. session_write_close();// End the current session and store session data. Below $_SESSION is read-only.
  131. $dbgExecTime->log('show...');
  132. if ($tree_procesy_filter->get_arg('filtr_view') == 'NOWY') {
  133. $filter_last->show_filters();
  134. echo'<div class="filters">';
  135. echo'<form action="'."".'" method="get" style="margin:0;padding:0;">';
  136. echo'<input type="hidden" name="task" value="'.App::get_task().'" />';
  137. $tree_procesy_filter->show_filters();
  138. {// save profile - btn
  139. echo'<nobr>';
  140. echo'<input type="submit" name="save_profile" value="'."Save".'" title="'."Save profile".'" />';
  141. echo'</nobr>';
  142. }
  143. {// load profile - btn
  144. echo'<nobr>';
  145. echo'<input type="submit" name="load_profile" value="'."Load".'" title="'."Load profile".'" />';
  146. echo'</nobr>';
  147. }
  148. echo'</form>';
  149. echo'</div>';// .filters
  150. $filter_hist = (isset($_SESSION['TREE-PROCESY']['filter_hist']))? $_SESSION['TREE-PROCESY']['filter_hist'] : array();
  151. if (!empty($filter_hist)) {
  152. echo'<form style="display:inline" action="" method="GET">';
  153. echo'<input type="hidden" name="task" value="'.App::get_task().'">';
  154. echo'<select name="filter_hist_id">';
  155. foreach ($filter_hist as $k => $v) {
  156. echo'<option value="'.$k.'">'.$v.'</option>';
  157. }
  158. echo'</select>';
  159. echo'</form>';
  160. }
  161. $tree = new Tree( $tbl );
  162. $tree->setProfiler($dbgExecTime);
  163. $clbk = 'tree_callback__show_item_from_'.$tbl;
  164. $tree->set_param('show_item_callback', $clbk);
  165. $tree->set_param('rozwin', ($tree_procesy_filter->get_arg('filtr_drzewo') == 'ROZWIN'));
  166. $tree->set_param('rozwin_proces', ($tree_procesy_filter->get_arg('filtr_procesy') == '+'));
  167. $tree->set_param('rozwin_zasoby', ($tree_procesy_filter->get_arg('filtr_zasoby') == '+'));
  168. $tree->set_param('rozwin_opis', ($tree_procesy_filter->get_arg('filtr_opis') == '+'));
  169. $tree->set_param('filtr_img', ($tree_procesy_filter->get_arg('filtr_img') == '+'));
  170. $tree->set_param('style', $tree_procesy_filter->get_arg('filtr_view'));
  171. $tree->set_param('search_id', $tree_procesy_filter->get_arg('filtr_search_id'));
  172. $tree->set_param('ProcesTblId', ProcesHelper::getZasobTableID('CRM_PROCES'));
  173. $tree->set_param('ZasobTblId', ProcesHelper::getZasobTableID('CRM_LISTA_ZASOBOW'));
  174. $tree->set_param('WskaznikTblId', ProcesHelper::getZasobTableID('CRM_WSKAZNIK'));
  175. $tblPytaniaId = ProcesHelper::getZasobTableID('CRM_TESTY_PYTANIA');
  176. if ($tblPytaniaId > 0) {
  177. $userAcl = User::getAcl();
  178. $userAcl->fetchGroups();
  179. if ($userAcl->hasTableAcl($tblPytaniaId)) {
  180. $tblAcl = $userAcl->getTableAcl($tblPytaniaId);
  181. $tblAcl->init($forceTblAclInit = false);
  182. $tree->set_param('HasAclPytaniaTbl', true);
  183. }
  184. $tree->set_param('PytaniaTblId', $tblPytaniaId);
  185. }
  186. //TODO: check perm to edit
  187. if ($tree_procesy_filter->is_trash()) $tree->set_param('is_trash', true);
  188. $tree->set_param('editable', ($tree_procesy_filter->get_arg('filtr_edit') == 'TAK'));
  189. if ($tree_procesy_filter->get_arg('filtr_ajax') == 'TAK') {
  190. $tree->_limit = 300;
  191. $tree->_deep_limit = 1;
  192. }
  193. if ($tree_procesy_filter->get_arg('filtr_id') != 0) {
  194. $tree->showSubTree( $tree_procesy_filter->get_arg('filtr_id') );
  195. $dbgExecTime->log('done tree->showSubTree()');
  196. } else if ($tree_procesy_filter->get_arg('filtr_search_id') > 0) {
  197. $tree->showSearchNode( $tree_procesy_filter->get_arg('filtr_search_id') );
  198. $dbgExecTime->log('done tree->showSearchNode()');
  199. } else {
  200. $tree->show();
  201. $dbgExecTime->log('done tree->show()');
  202. }
  203. }
  204. else {
  205. echo'<pre>';
  206. {
  207. echo'<table cellspacing="0" cellpadding="1">';
  208. echo'<tr>';
  209. echo'<td>';
  210. echo "DRZEWO ";
  211. if ($_SESSION['ZWIN_DRZEWO']) {
  212. echo App::link("ROZWIN", "?ROZWIN_DRZEWO=1#tree");
  213. } else {
  214. echo App::link("ZWIN", "?ZWIN_DRZEWO=1#tree");
  215. }
  216. echo'</td>';
  217. echo'<td>';
  218. echo "&nbsp;/&nbsp;";
  219. echo'</td>';
  220. echo'<td>';
  221. echo "PROCESY ";
  222. if ($_SESSION['ROZWIN']) {
  223. echo App::link("ZWIN", "?TREE_ZWIN=1#tree");
  224. } else {
  225. echo App::link("ROZWIN", "?TREE_ROZWIN=1#tree");
  226. }
  227. echo'</td>';
  228. echo'<td>';
  229. echo "&nbsp;/&nbsp;";
  230. echo'</td>';
  231. echo'<td>';
  232. echo "ZASOBY ";
  233. if ($_SESSION['ROZWIN_ZASOBY']) {
  234. echo App::link("ZWIN", "?TREE_ZASOBY_ZWIN=1#tree");
  235. } else {
  236. echo App::link("ROZWIN", "?TREE_ZASOBY_ROZWIN=1#tree");
  237. }
  238. echo'</td>';
  239. echo'<td>';
  240. echo "&nbsp;/&nbsp;";
  241. echo'</td>';
  242. echo'<td>';
  243. echo "OPISY ";
  244. if ($_SESSION['ROZWIN_OPIS']) {
  245. echo App::link("ZWIN", "?TREE_OPISY_ZWIN=1#tree");
  246. } else {
  247. echo App::link("ROZWIN", "?TREE_OPISY_ROZWIN=1#tree");
  248. }
  249. echo'</td>';
  250. echo'<td>';
  251. echo "&nbsp;/&nbsp;";
  252. echo'</td>';
  253. echo'<td>';
  254. $js = "window.location.href='#TREE'+this.form.id.value;return false;";
  255. echo '<form style="display:inline" action="#" method="GET">';
  256. echo "Proces ID: ";
  257. echo'<input type="text" name="id" value="" size="5" />';
  258. echo'<button onclick="'.$js.'">'."Wyszukaj ID".'</button>';
  259. echo'</form>'."\n";
  260. echo'</td>';
  261. echo'<td>';
  262. echo "&nbsp;/&nbsp;";
  263. echo'</td>';
  264. echo'<td>';
  265. echo'Widok ';
  266. echo App::link("NOWY", "?filtr_view=NOWY");
  267. echo'</td>';
  268. {
  269. echo'<td>';
  270. echo "&nbsp;/&nbsp;";
  271. echo'</td>';
  272. echo'<td>';
  273. echo'<form action="" method="GET" style="display:inline">';
  274. echo'<input type="hidden" name="'."task".'" value="'.App::get_task().'" />';
  275. echo'<nobr>';
  276. echo'<input type="submit" name="load_profile" value="'."Load".'" title="'."Load profile".'" />';
  277. echo'</nobr>';
  278. echo'</form>';
  279. echo'</td>';
  280. }
  281. echo'</tr>';
  282. echo'</table>';// btns
  283. }
  284. tree_znajdz(0, 1, 0);
  285. echo'</pre>';
  286. }
  287. if($DBG_TIME){
  288. $dbgExecTime->log('end');
  289. $dbgExecTime->printDebug();
  290. }
  291. }
  292. function fun_CRM_PROCES_clean_trash() {
  293. $db = DB::getDB();
  294. if (!$db) {
  295. echo '<p class="red">' . "No DB!" . '</p>';
  296. return;
  297. } else if ($db->has_errors()) {
  298. echo '<p>' . "Error DB: " . implode('<br />', $db->get_errors()) . '</p>';
  299. return;
  300. }
  301. $affected_total = 0;
  302. // remove all root trash items
  303. $sql = "update `CRM_PROCES` as p
  304. set p.`A_STATUS`='DELETED', p.`A_RECORD_UPDATE_AUTHOR`='TrashRemoveRec', p.`A_RECORD_UPDATE_DATE`=NOW()
  305. where p.`PARENT_ID`=-1 and p.`A_STATUS`!='DELETED'
  306. ";
  307. $db->query($sql);
  308. $affected = $db->affected_rows();
  309. if ($affected) {
  310. $affected_total += $affected;
  311. }
  312. // remove all child trash items - run X times
  313. $loop_limit = 50;
  314. do {
  315. $sql = "update `CRM_PROCES` as p, `CRM_PROCES` as pp
  316. set p.`A_STATUS`='DELETED', p.`A_RECORD_UPDATE_AUTHOR`='TrashRemoveRec', p.`A_RECORD_UPDATE_DATE`=NOW()
  317. where p.`PARENT_ID`=pp.`ID` and (pp.`PARENT_ID`=-1 or pp.`A_STATUS`='DELETED') and p.`A_STATUS`!='DELETED'
  318. ";
  319. $db->query($sql);
  320. $affected = $db->affected_rows();
  321. if ($affected) {
  322. $affected_total += $affected;
  323. }
  324. } while ($affected > 0 && --$loop_limit >= 0);
  325. echo '<p>' . "Usunięto " . $affected_total . " rekordów." . '</p>';
  326. }