proces.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. <?php
  2. Lib::loadClass('ProcesHelper');
  3. /**
  4. * @param $_GET['EDIT'] - ID rekordu do edycji (inline)
  5. * @param $_GET['EDIT_ID'] - ID rekordu do edycji (inline)
  6. */
  7. function task_CRM_PROCES() {
  8. User_procesy5_check_access();
  9. $_GET['ADM_AREA'] = V::get('ADM_AREA', "BN%", $_GET);
  10. $_GET['EDIT'] = V::get('EDIT', 0, $_GET, 'int');
  11. if (($edit_id = V::get('EDIT_ID', 0, $_GET, 'int')) > 0) {
  12. $_GET['EDIT'] = $edit_id;
  13. }
  14. $tbl = 'CRM_PROCES';
  15. $tbl_conf = Column::getInstance($tbl);
  16. if (!$tbl_conf) {
  17. echo'<p class="red">'."Brak konfiguracji dla ".$tbl."!".'</p>';
  18. return;
  19. }
  20. $visible_cols = $tbl_conf->getVisibleFieldList();
  21. // form decorators:
  22. $tbl_search_params = array();
  23. $tbl_search_params['ID'] = 'ID';
  24. $tbl_search_params['PARENT_ID'] = 'P_ID';
  25. $tbl_search_params['TYPE'] = 'TYPE';
  26. $tbl_search_params['DESC'] = 'DESC';
  27. $tbl_search_params['OPIS'] = 'OPIS';
  28. $tbl_search_params['DESC_PL'] = 'DESC_PL';
  29. $tbl_search_params['TAGS'] = 'TAGS';
  30. $tbl_search_params['A_STATUS'] = 'A_STATUS';
  31. $tbl_search_params['L_APPOITMENT_USER'] = 'L_APPOITMENT_USER';
  32. $tbl_search_params['L_APPOITMENT_DATE'] = 'L_APPOITMENT_DATE';
  33. $tbl_search_params['L_APPOITMENT_INFO'] = 'L_APPOITMENT_INFO';
  34. $tbl_search_params['A_ADM_COMPANY'] = 'A_ADM_COMPANY';
  35. $tbl_search_params['IF_TRUE_GOTO'] = 'IF_TRUE_GOTO';
  36. $tbl_search_params['IF_TRUE_GOTO_FLAG'] = 'IF_TRUE_GOTO_FLAG';
  37. $tbl_search_params['A_RECORD_CREATE_AUTHOR'] = 'A_RECORD_CREATE_AUTHOR';
  38. $tbl_search_params['A_RECORD_CREATE_DATE'] = 'A_RECORD_CREATE_DATE';
  39. $tbl_search_params['A_RECORD_UPDATE_AUTHOR'] = 'A_RECORD_UPDATE_AUTHOR';
  40. $tbl_search_params['A_RECORD_UPDATE_DATE'] = 'A_RECORD_UPDATE_DATE';
  41. Lib::loadClass('FilterLast');
  42. $filter_last = new FilterLast( $_REQUEST, $tbl, 'session');
  43. $filter_last->add_filter( 'last_id', array('filtr_id','filtr_search_id','ID','EDIT'), "Ostatnio uzywane ID", 'int' );
  44. $filter_last->_save_args();// save args from request
  45. {// TABLE - Filter
  46. $tbl = 'CRM_PROCES';
  47. $tbl_filter = new stdClass();
  48. $tbl_filter->key = 'tbl-'.$tbl;
  49. $tbl_filter->filters = array();
  50. // TODO: stronicowanie $tbl_filter->filters: _page_nr, _limit, _total (need sql - only after change params)
  51. // read args from session, or get dafault values
  52. foreach ($tbl_search_params as $k => $req_field_name) {
  53. $tbl_filter->filters[$req_field_name] = V::get($req_field_name, '%', $_SESSION[$tbl_filter->key]);
  54. }//end foreach
  55. // read args from $_GET if isset
  56. foreach ($tbl_search_params as $k => $req_field_name) {
  57. if (isset($_GET[$req_field_name])) {
  58. $tbl_filter->filters[$req_field_name] = $_GET[$req_field_name];
  59. }
  60. }//end foreach
  61. // save args in session and $_GET
  62. foreach ($tbl_filter->filters as $req_field_name => $v) {
  63. $_SESSION[$tbl_filter->key][$req_field_name] = $v;
  64. $_GET[$req_field_name] = $v;
  65. }//end foreach
  66. echo'<div style="border:1px solid red; display:none;">';
  67. foreach ($tbl_filter->filters as $req_field_name => $v) {
  68. echo'<br />arg['.$req_field_name.'] = '.$v;
  69. }//end foreach
  70. echo'</div>';
  71. }// TABLE - Filter
  72. {// TREE - Filter
  73. $tbl = 'CRM_PROCES';
  74. $tree_procesy_filter = get_filter_for_table( $tbl );
  75. $tree_procesy_filter->set_trash( 'filtr_id', -1 );
  76. {// zapisz stan - ajax function to save filters stan and opened tree nodes, etc.
  77. $filtr_ses_key = $tree_procesy_filter->_key;
  78. $cookie_key = 'TREE_'.$tbl;
  79. $profile_key = 'Filtr_'.$filtr_ses_key;
  80. if (V::get('save_profile', '', $_REQUEST)) {
  81. $profile_val = array();
  82. $profile_val['filtr'] = $_SESSION[$filtr_ses_key];
  83. $profile_val['tree'] = $_COOKIE[$cookie_key];// cookie key from Tree class - 'TREE_'. $tbl @see __construct
  84. User::setProfile($profile_key, $profile_val);
  85. $ret = User::saveProfile();
  86. }
  87. else if (V::get('load_profile', '', $_REQUEST)) {
  88. //User::loadProfile();// proile is loaded in USERS_COLUMN_INIT after login
  89. $profile_val = User::getProfile($profile_key);
  90. $_COOKIE[$cookie_key] = $profile_val['tree'];
  91. echo'<script type="text/javascript">'."
  92. jQuery(document).ready(function(){
  93. jQuery.cookie('".$cookie_key."','" . $_COOKIE[$cookie_key] . "');
  94. });
  95. ".'</script>';
  96. $_SESSION[$filtr_ses_key] = $profile_val['filtr'];
  97. $tree_procesy_filter->_read_args( true );// force load args from session
  98. }
  99. }// zapisz stan - ajax function to save filters stan and opened tree nodes, etc.
  100. $tree_procesy_filter->_save_args();// force save_args (execute at the end of show_filters)
  101. echo'<div style="border:1px solid red; display:none;">';
  102. foreach ($tree_procesy_filter->filters as $arg => $v) {
  103. echo'<br />arg['.$arg.'] = '.$tree_procesy_filter->get_arg($arg);
  104. }//end foreach
  105. echo'</div>';
  106. }// TREE - Filter
  107. echo'<h1>';
  108. echo App::link("Procesy", array('task'=>App::get_task(), 'filtr_id'=>''));
  109. if ($tree_procesy_filter->is_trash()) {//$_GET['filtr_id'] == -1) {
  110. echo ' &raquo; '."Kosz";
  111. 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;'));
  112. } else if ($tree_procesy_filter->get_arg('filtr_id') > 0) {//$_GET['filtr_id'] > 0) {
  113. echo ' &raquo; '."Proces [".$tree_procesy_filter->get_arg('filtr_id')."]";
  114. }
  115. echo '<span class="pull-right">'.App::link("Mapa procesów", array('task'=>'VIEW_PROCES_MAP')).'</span>';
  116. echo'</h1>';
  117. $procesZasobId = ProcesHelper::getZasobTableID('CRM_PROCES');
  118. echo App::link("Pokaz Tabele", "index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID={$procesZasobId}");
  119. echo "<br>".App::link("Dodaj nowy rekord", "index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID={$procesZasobId}#CREATE");
  120. echo'<br />';
  121. $TREE = array();
  122. echo'<div id="tree"></div>';
  123. $DBG_TIME = 0;
  124. if($DBG_TIME) $time_arr = array();// [ [time, desc], [time, desc], ... ]
  125. if($DBG_TIME) $time_arr []= array(microtime(true), 'before Tree');
  126. if ($tree_procesy_filter->get_arg('filtr_view') == 'NOWY') {
  127. $filter_last->show_filters();
  128. echo'<div class="filters">';
  129. echo'<form action="'."".'" method="get" style="margin:0;padding:0;">';
  130. echo'<input type="hidden" name="task" value="'.App::get_task().'" />';
  131. $tree_procesy_filter->show_filters();
  132. {// save profile - btn
  133. echo'<nobr>';
  134. echo'<input type="submit" name="save_profile" value="'."Save".'" title="'."Save profile".'" />';
  135. echo'</nobr>';
  136. }
  137. {// load profile - btn
  138. echo'<nobr>';
  139. echo'<input type="submit" name="load_profile" value="'."Load".'" title="'."Load profile".'" />';
  140. echo'</nobr>';
  141. }
  142. echo'</form>';
  143. echo'</div>';// .filters
  144. $filter_hist = (isset($_SESSION['TREE-PROCESY']['filter_hist']))? $_SESSION['TREE-PROCESY']['filter_hist'] : array();
  145. if (!empty($filter_hist)) {
  146. echo'<form style="display:inline" action="" method="GET">';
  147. echo'<input type="hidden" name="task" value="'.App::get_task().'">';
  148. echo'<select name="filter_hist_id">';
  149. foreach ($filter_hist as $k => $v) {
  150. echo'<option value="'.$k.'">'.$v.'</option>';
  151. }
  152. echo'</select>';
  153. echo'</form>';
  154. }
  155. $tree = new Tree( $tbl );
  156. $clbk = 'tree_callback__show_item_from_'.$tbl;
  157. $tree->set_param('show_item_callback', $clbk);
  158. $tree->set_param('rozwin', ($tree_procesy_filter->get_arg('filtr_drzewo') == 'ROZWIN'));
  159. $tree->set_param('rozwin_proces', ($tree_procesy_filter->get_arg('filtr_procesy') == '+'));
  160. $tree->set_param('rozwin_zasoby', ($tree_procesy_filter->get_arg('filtr_zasoby') == '+'));
  161. $tree->set_param('rozwin_opis', ($tree_procesy_filter->get_arg('filtr_opis') == '+'));
  162. $tree->set_param('filtr_img', ($tree_procesy_filter->get_arg('filtr_img') == '+'));
  163. $tree->set_param('style', $tree_procesy_filter->get_arg('filtr_view'));
  164. $tree->set_param('search_id', $tree_procesy_filter->get_arg('filtr_search_id'));
  165. $tree->set_param('ProcesTblId', ProcesHelper::getZasobTableID('CRM_PROCES'));
  166. $tree->set_param('ZasobTblId', ProcesHelper::getZasobTableID('CRM_LISTA_ZASOBOW'));
  167. $tblPytaniaId = ProcesHelper::getZasobTableID('CRM_TESTY_PYTANIA');
  168. if ($tblPytaniaId > 0) {
  169. $userAcl = User::getAcl();
  170. $userAcl->fetchGroups();
  171. if ($userAcl->hasTableAcl($tblPytaniaId)) {
  172. $tblAcl = $userAcl->getTableAcl($tblPytaniaId);
  173. $tblAcl->init($forceTblAclInit = false);
  174. $tree->set_param('HasAclPytaniaTbl', true);
  175. }
  176. $tree->set_param('PytaniaTblId', $tblPytaniaId);
  177. }
  178. //TODO: check perm to edit
  179. if ($tree_procesy_filter->is_trash()) $tree->set_param('is_trash', true);
  180. $tree->set_param('editable', ($tree_procesy_filter->get_arg('filtr_edit') == 'TAK'));
  181. if ($tree_procesy_filter->get_arg('filtr_ajax') == 'TAK') {
  182. $tree->_limit = 300;
  183. $tree->_deep_limit = 1;
  184. }
  185. if ($tree_procesy_filter->get_arg('filtr_id') != 0) {
  186. $tree->showSubTree( $tree_procesy_filter->get_arg('filtr_id') );
  187. } else if ($tree_procesy_filter->get_arg('filtr_search_id') > 0) {
  188. $tree->showSearchNode( $tree_procesy_filter->get_arg('filtr_search_id') );
  189. } else {
  190. $tree->show();
  191. }
  192. }
  193. else {
  194. echo'<pre>';
  195. {
  196. echo'<table cellspacing="0" cellpadding="1">';
  197. echo'<tr>';
  198. echo'<td>';
  199. echo "DRZEWO ";
  200. if ($_SESSION['ZWIN_DRZEWO']) {
  201. echo App::link("ROZWIN", "?ROZWIN_DRZEWO=1#tree");
  202. } else {
  203. echo App::link("ZWIN", "?ZWIN_DRZEWO=1#tree");
  204. }
  205. echo'</td>';
  206. echo'<td>';
  207. echo "&nbsp;/&nbsp;";
  208. echo'</td>';
  209. echo'<td>';
  210. echo "PROCESY ";
  211. if ($_SESSION['ROZWIN']) {
  212. echo App::link("ZWIN", "?TREE_ZWIN=1#tree");
  213. } else {
  214. echo App::link("ROZWIN", "?TREE_ROZWIN=1#tree");
  215. }
  216. echo'</td>';
  217. echo'<td>';
  218. echo "&nbsp;/&nbsp;";
  219. echo'</td>';
  220. echo'<td>';
  221. echo "ZASOBY ";
  222. if ($_SESSION['ROZWIN_ZASOBY']) {
  223. echo App::link("ZWIN", "?TREE_ZASOBY_ZWIN=1#tree");
  224. } else {
  225. echo App::link("ROZWIN", "?TREE_ZASOBY_ROZWIN=1#tree");
  226. }
  227. echo'</td>';
  228. echo'<td>';
  229. echo "&nbsp;/&nbsp;";
  230. echo'</td>';
  231. echo'<td>';
  232. echo "OPISY ";
  233. if ($_SESSION['ROZWIN_OPIS']) {
  234. echo App::link("ZWIN", "?TREE_OPISY_ZWIN=1#tree");
  235. } else {
  236. echo App::link("ROZWIN", "?TREE_OPISY_ROZWIN=1#tree");
  237. }
  238. echo'</td>';
  239. echo'<td>';
  240. echo "&nbsp;/&nbsp;";
  241. echo'</td>';
  242. echo'<td>';
  243. $js = "window.location.href='#TREE'+this.form.id.value;return false;";
  244. echo '<form style="display:inline" action="#" method="GET">';
  245. echo "Proces ID: ";
  246. echo'<input type="text" name="id" value="" size="5" />';
  247. echo'<button onclick="'.$js.'">'."Wyszukaj ID".'</button>';
  248. echo'</form>'."\n";
  249. echo'</td>';
  250. echo'<td>';
  251. echo "&nbsp;/&nbsp;";
  252. echo'</td>';
  253. echo'<td>';
  254. echo'Widok ';
  255. echo App::link("NOWY", "?filtr_view=NOWY");
  256. echo'</td>';
  257. {
  258. echo'<td>';
  259. echo "&nbsp;/&nbsp;";
  260. echo'</td>';
  261. echo'<td>';
  262. echo'<form action="" method="GET" style="display:inline">';
  263. echo'<input type="hidden" name="'."task".'" value="'.App::get_task().'" />';
  264. echo'<nobr>';
  265. echo'<input type="submit" name="load_profile" value="'."Load".'" title="'."Load profile".'" />';
  266. echo'</nobr>';
  267. echo'</form>';
  268. echo'</td>';
  269. }
  270. echo'</tr>';
  271. echo'</table>';// btns
  272. }
  273. tree_znajdz(0, 1, 0);
  274. echo'</pre>';
  275. }
  276. if($DBG_TIME) $time_arr []= array(microtime(true), 'after Tree...');
  277. if($DBG_TIME){
  278. $time_arr []= array(microtime(true), 'end');
  279. $last_time = 0;
  280. echo'<table style="color:#e0e0e0; text-align:left;">';
  281. foreach ($time_arr as $t) {
  282. echo'<tr>';
  283. echo'<td> </td>';
  284. echo'<td> </td>';
  285. echo'<td style="text-align:left;">'.number_format(($t[0] - $last_time), 6).'</td>';
  286. echo'</tr>';
  287. echo'<tr>';
  288. echo'<td>'.$t[0].'</td>';
  289. echo'<td>'.$t[1].'</td>';
  290. echo'<td> </td>';
  291. echo'</tr>';
  292. $last_time = $t[0];
  293. }//end foreach
  294. echo'</table>';
  295. //echo'<pre style="text-align:left;">';print_r($db);echo'</pre>';
  296. //echo'<pre style="text-align:left;">';print_r($_SERVER);echo'</pre>';
  297. }
  298. }
  299. function fun_CRM_PROCES_ADD() {
  300. $redirect = "?task=".App::get_task();
  301. $msg = '';
  302. $sql_obj = new stdClass();
  303. $tbl_name = 'CRM_PROCES';
  304. Lib::loadClass('Column');
  305. $tbl_conf = Column::getInstance($tbl_name);
  306. if (!$tbl_conf) {
  307. return;
  308. }
  309. foreach ($tbl_conf->getFieldList() as $field_id => $field_name) {
  310. if ($tbl_conf->allowCreate($field_name)) {
  311. $post_arg_name = 'ADD_' . $field_name;
  312. if (isset($_POST[$post_arg_name])) {
  313. $sql_obj->$field_name = $_POST[$post_arg_name];
  314. }
  315. }
  316. }//end foreach
  317. // nowy na koniec listy
  318. $sql = "select max(t.`SORT_PRIO`) as MAX_SORT_PRIO
  319. from `CRM_PROCES` as t
  320. where
  321. t.`PARENT_ID`='".$sql_obj->PARENT_ID."'
  322. ";
  323. $res = DB::query( $sql );
  324. while ($r = DB::fetch( $res )) {
  325. $sql_obj->SORT_PRIO = $r->MAX_SORT_PRIO + 1;
  326. }
  327. //TODO: post verify
  328. $new_id = DB::ADD_NEW_OBJ('CRM_PROCES', $sql_obj);
  329. if (V::get('DEBUG', '', $_SESSION)) App::add_msg("PASSED(1) NEW RECORD ID($new_id)");
  330. if ($new_id > 0) {
  331. App::add_msg("Dodano nowy rekord (ID ".$new_id.")");
  332. $redirect .= "&EDIT=".$new_id;
  333. }
  334. else {
  335. App::add_error("Error przy dodawaniu rekordu!");
  336. }
  337. App::redirect($redirect, $msg);
  338. }
  339. /**
  340. * @param $_POST['EDIT'] - ID rekordu
  341. */
  342. function fun_CRM_PROCES_EDIT() {
  343. $redirect = "?task=".App::get_task();
  344. $msg = '';
  345. $sql_obj = new stdClass();
  346. $tbl_name = 'CRM_PROCES';
  347. $sql_obj->ID = V::get('EDIT_ID', '', $_POST, 'int');
  348. // TODO: fields can be hidden
  349. Lib::loadClass('Column');
  350. $tbl_conf = Column::getInstance($tbl_name);
  351. if (!$tbl_conf) {
  352. return;
  353. }
  354. foreach ($tbl_conf->getFieldList() as $field_id => $field_name) {
  355. if ($tbl_conf->allowWrite($field_name)) {
  356. $post_arg_name = 'EDIT_' . $field_name;
  357. if (isset($_POST[$post_arg_name])) {
  358. // TODO: convert field types?
  359. $sql_obj->$field_name = $_POST[$post_arg_name];
  360. }
  361. }
  362. }//end foreach
  363. $redirect .= "&EDIT=".$sql_obj->ID;
  364. //TODO: post verify
  365. $id = $sql_obj->ID;
  366. $affected = DB::UPDATE_OBJ( 'CRM_PROCES', $sql_obj );
  367. if (V::get('DEBUG', '', $_SESSION)) App::add_msg("PASSED($affected)");
  368. if ($affected == 2) {
  369. App::add_msg("Zmieniono rekord (ID ".$id.")");
  370. }
  371. else if ($affected == 1) {
  372. App::add_msg("Zmieniono rekord (ID ".$id.") (Error: nie zapisano hostorii)");
  373. }
  374. else if ($affected < 0) {
  375. App::add_error("Blad podczas edytowania rekordu - nic nie zmieniono");
  376. }
  377. App::redirect($redirect, $msg);
  378. }
  379. function fun_CRM_PROCES_clean_trash() {
  380. $db = DB::getDB();
  381. if (!$db) {
  382. echo '<p class="red">' . "No DB!" . '</p>';
  383. return;
  384. } else if ($db->has_errors()) {
  385. echo '<p>' . "Error DB: " . implode('<br />', $db->get_errors()) . '</p>';
  386. return;
  387. }
  388. $affected_total = 0;
  389. // remove all root trash items
  390. $sql = "update `CRM_PROCES` as p
  391. set p.`A_STATUS`='DELETED', p.`A_RECORD_UPDATE_AUTHOR`='TrashRemoveRec', p.`A_RECORD_UPDATE_DATE`=NOW()
  392. where p.`PARENT_ID`=-1 and p.`A_STATUS`!='DELETED'
  393. ";
  394. $db->query($sql);
  395. $affected = $db->affected_rows();
  396. if ($affected) {
  397. $affected_total += $affected;
  398. }
  399. // remove all child trash items - run X times
  400. $loop_limit = 50;
  401. do {
  402. $sql = "update `CRM_PROCES` as p, `CRM_PROCES` as pp
  403. set p.`A_STATUS`='DELETED', p.`A_RECORD_UPDATE_AUTHOR`='TrashRemoveRec', p.`A_RECORD_UPDATE_DATE`=NOW()
  404. where p.`PARENT_ID`=pp.`ID` and (pp.`PARENT_ID`=-1 or pp.`A_STATUS`='DELETED') and p.`A_STATUS`!='DELETED'
  405. ";
  406. $db->query($sql);
  407. $affected = $db->affected_rows();
  408. if ($affected) {
  409. $affected_total += $affected;
  410. }
  411. } while ($affected > 0 && --$loop_limit >= 0);
  412. echo '<p>' . "Usunięto " . $affected_total . " rekordów." . '</p>';
  413. }