index.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. <?php
  2. if (cfr('TASKMAN')) {
  3. $altCfg = $ubillingConfig->getAlter();
  4. /**
  5. * json reply for tasks log
  6. */
  7. if (ubRouting::checkGet('ajaxlog')) {
  8. ts_renderLogsDataAjax(ubRouting::get('edittask'));
  9. }
  10. /**
  11. * fullcalendar default display options
  12. */
  13. $fullCalendarOpts = '';
  14. if (isset($altCfg['TASKMAN_DEFAULT_VIEW'])) {
  15. if (!empty($altCfg['TASKMAN_DEFAULT_VIEW'])) {
  16. $fullCalendarOpts = "defaultView: '" . $altCfg['TASKMAN_DEFAULT_VIEW'] . "',";
  17. }
  18. }
  19. /**
  20. * new task creation
  21. */
  22. if (ubRouting::checkPost('createtask')) {
  23. if (ubRouting::checkPost(array('newstartdate', 'newtaskaddress', 'newtaskphone'))) {
  24. if (ubRouting::checkPost(array('typicalnote'))) {
  25. $newTaskNote = ubRouting::post('typicalnote') . ' ' . ubRouting::post('newjobnote');
  26. } else {
  27. $newTaskNote = ubRouting::post('newjobnote');
  28. }
  29. //date validation
  30. if (zb_checkDate(ubRouting::post('newstartdate'))) {
  31. $newTaskDate = ubRouting::post('newstartdate');
  32. $newTaskTime = ubRouting::post('newstarttime');
  33. $newTaskAddress = ubRouting::post('newtaskaddress');
  34. $newTaskLogin = ubRouting::post('newtasklogin');
  35. $newTaskPhone = ubRouting::post('newtaskphone');
  36. $newTaskJobType = ubRouting::post('newtaskjobtype');
  37. $newTaskEmployee = ubRouting::post('newtaskemployee');
  38. ts_CreateTask($newTaskDate, $newTaskTime, $newTaskAddress, $newTaskLogin, $newTaskPhone, $newTaskJobType, $newTaskEmployee, $newTaskNote);
  39. //capabdir redirects
  40. if (ubRouting::checkPost(array('unifiedformcapabdirgobackflag', 'unifiedformcapabdirgobackid'))) {
  41. $capabUrl = CapabilitiesDirectory::URL_ME . CapabilitiesDirectory::URL_CAPAB;
  42. ubRouting::nav($capabUrl . ubRouting::post('unifiedformcapabdirgobackid'));
  43. } else {
  44. //normal redirects
  45. if (!ubRouting::checkGet('gotolastid')) {
  46. ubRouting::nav('?module=taskman');
  47. } else {
  48. $lasttaskid = simple_get_lastid('taskman');
  49. ubRouting::nav('?module=taskman&edittask=' . $lasttaskid);
  50. }
  51. }
  52. } else {
  53. show_error(__('Wrong date format'));
  54. }
  55. } else {
  56. show_error(__('All fields marked with an asterisk are mandatory'));
  57. }
  58. }
  59. /**
  60. * existing task editing
  61. */
  62. if (ubRouting::checkPost('modifytask')) {
  63. if (ubRouting::checkPost(array('modifystartdate', 'modifytaskaddress', 'modifytaskphone'))) {
  64. if (zb_checkDate(ubRouting::post('modifystartdate'))) {
  65. $taskId = ubRouting::post('modifytask');
  66. $edTaskDate = ubRouting::post('modifystartdate');
  67. $edTaskTime = ubRouting::post('modifystarttime');
  68. $edTaskAddress = ubRouting::post('modifytaskaddress');
  69. $edTaskLogin = ubRouting::post('modifytasklogin');
  70. $edTaskPhone = ubRouting::post('modifytaskphone');
  71. $edTaskJobType = ubRouting::post('modifytaskjobtype');
  72. $edTaskEmployee = ubRouting::post('modifytaskemployee');
  73. $edTaskNote = ubRouting::post('modifytaskjobnote');
  74. ts_ModifyTask($taskId, $edTaskDate, $edTaskTime, $edTaskAddress, $edTaskLogin, $edTaskPhone, $edTaskJobType, $edTaskEmployee, $edTaskNote);
  75. ubRouting::nav('?module=taskman&edittask=' . $taskId);
  76. } else {
  77. show_error(__('Wrong date format'));
  78. }
  79. } else {
  80. show_error(__('All fields marked with an asterisk are mandatory'));
  81. }
  82. }
  83. /**
  84. * task start date change on drag and drop actions
  85. */
  86. if (ubRouting::checkPost(array('object_id', 'new_start_time'))) {
  87. $taskID = ubRouting::post('object_id');
  88. $newStartDT = ubRouting::post('new_start_time');
  89. $taskData = ts_GetTaskData($taskID);
  90. if (!empty($taskData)) {
  91. $newStartDT = date('Y-m-d', strtotime($newStartDT));
  92. $curTaskTime = $taskData['starttime'];
  93. $curTaskAddress = $taskData['address'];
  94. $curTaskLogin = $taskData['login'];
  95. $curTaskPhone = $taskData['phone'];
  96. $curTaskJobType = $taskData['jobtype'];
  97. $curTaskEmployee = $taskData['employee'];
  98. $curTaskNote = $taskData['jobnote'];
  99. ts_ModifyTask($taskID, $newStartDT, $curTaskTime, $curTaskAddress, $curTaskLogin, $curTaskPhone, $curTaskJobType, $curTaskEmployee, $curTaskNote);
  100. die('SUCCESS');
  101. } else {
  102. die('FAIL');
  103. }
  104. }
  105. /**
  106. * Setting task as done
  107. */
  108. if (ubRouting::checkPost('changetask')) {
  109. if (ubRouting::checkPost(array('editenddate', 'editemployeedone'))) {
  110. if (zb_checkDate(ubRouting::post('editenddate'))) {
  111. //setting task as done
  112. ts_TaskIsDone();
  113. //flushing darkvoid after changing task
  114. $darkVoid = new DarkVoid();
  115. $darkVoid->flushCache();
  116. //generate job for some user
  117. if (ubRouting::checkPost(array('generatejob', 'generatelogin', 'generatejobid'))) {
  118. $newJobLogin = ubRouting::post('generatelogin');
  119. $newJobTime = curdatetime();
  120. $newJobEmployeeDone = ubRouting::post('editemployeedone');
  121. $newJobJobType = ubRouting::post('generatejobid');
  122. $newJobTaskId = ubRouting::post('changetask');
  123. $newJobNote = 'TASKID:[' . $newJobTaskId . ']';
  124. stg_add_new_job($newJobLogin, $newJobTime, $newJobEmployeeDone, $newJobJobType, $newJobNote);
  125. log_register('TASKMAN GENJOB (' . $newJobLogin . ') VIA [' . $newJobTaskId . ']');
  126. }
  127. } else {
  128. show_error(__('Wrong date format'));
  129. }
  130. } else {
  131. show_error(__('All fields marked with an asterisk are mandatory'));
  132. }
  133. }
  134. /**
  135. * setting task as undone
  136. */
  137. if (ubRouting::checkGet('setundone')) {
  138. //setting task as undone
  139. ts_TaskIsUnDone();
  140. //flushing darkvoid after setting task as undone
  141. $darkVoid = new DarkVoid();
  142. $darkVoid->flushCache();
  143. ubRouting::nav('?module=taskman');
  144. }
  145. /**
  146. * deleting existing task
  147. */
  148. if (ubRouting::checkGet('deletetask')) {
  149. $deleteTaskId = ubRouting::get('deletetask', 'int');
  150. if (cfr('TASKMANDELETE')) {
  151. ts_DeleteTask($deleteTaskId);
  152. //flushing darkvoid after task deletion
  153. $darkVoid = new DarkVoid();
  154. $darkVoid->flushCache();
  155. ubRouting::nav('?module=taskman');
  156. } else {
  157. show_error(__('Access denied'));
  158. log_register('TASKMAN DELETE ACCESS FAIL [' . $deleteTaskId . '] ADMIN {' . whoami() . '}');
  159. }
  160. }
  161. /**
  162. * normal taskman interface rendering here
  163. */
  164. show_window(__('Manage tasks'), ts_ShowPanel());
  165. //calendar tasks filter selection
  166. if (ubRouting::checkGet('show')) {
  167. if (ubRouting::get('show') == 'undone') {
  168. $showtasks = ts_JGetUndoneTasks();
  169. }
  170. if (ubRouting::get('show') == 'done') {
  171. $showtasks = ts_JGetDoneTasks();
  172. }
  173. if (ubRouting::get('show') == 'all') {
  174. $showtasks = ts_JGetAllTasks();
  175. }
  176. } else {
  177. $showtasks = ts_JGetUndoneTasks();
  178. }
  179. if (!ubRouting::checkGet('edittask')) {
  180. if (!ubRouting::checkGet('print')) {
  181. if (ubRouting::checkGet('show') AND (ubRouting::get('show') == 'logs' and cfr('TASKMANNWATCHLOG'))) {
  182. /**
  183. * Task logs rendering
  184. */
  185. show_window(__('View log'), ts_renderLogsListAjax());
  186. } else {
  187. $showExtendedDone = $ubillingConfig->getAlterParam('TASKMAN_SHOW_DONE_EXTENDED');
  188. $extendedDoneAlterStyling = $ubillingConfig->getAlterParam('TASKMAN_DONE_EXTENDED_ALTERSTYLING');
  189. $extendedDoneAlterStylingBool = ($extendedDoneAlterStyling > 0);
  190. $extendedDoneAlterListOnly = ($extendedDoneAlterStylingBool and $extendedDoneAlterStyling == 2);
  191. //custom jobtypes color styling
  192. $customJobColorStyle = ts_GetAllJobtypesColorStyles();
  193. /** ////////////////////////////////////////
  194. * rendering of primary full calendar view
  195. * //////////////////////////////////////// */
  196. show_window('', $customJobColorStyle . wf_FullCalendar($showtasks, $fullCalendarOpts, $extendedDoneAlterStylingBool, $extendedDoneAlterListOnly, '?module=taskman'));
  197. }
  198. } else {
  199. /**
  200. * printable results
  201. */
  202. if (ubRouting::checkPost(array('printdatefrom', 'printdateto'))) {
  203. if (!ubRouting::checkPost('tableview')) {
  204. ts_PrintTasks(ubRouting::post('printdatefrom'), ubRouting::post('printdateto'));
  205. } else {
  206. ts_PrintTasksTable(ubRouting::post('printdatefrom'), ubRouting::post('printdateto'), ubRouting::checkPost('nopagebreaks'));
  207. }
  208. }
  209. /**
  210. * show printing form
  211. */
  212. show_window(__('Tasks printing'), ts_PrintDialogue());
  213. }
  214. } else {
  215. /**
  216. * SMS post sending
  217. */
  218. if (ubRouting::checkPost(array('postsendemployee', 'postsendsmstext'))) {
  219. $smsDataRaw = ts_SendSMS(ubRouting::post('postsendemployee'), ubRouting::post('postsendsmstext'));
  220. if (!empty($smsDataRaw)) {
  221. //updating SMS data in task record
  222. ts_TaskSMSDataUpdate($smsDataRaw);
  223. //flushing dark void
  224. $darkVoid = new DarkVoid();
  225. $darkVoid->flushCache();
  226. ubRouting::nav('?module=taskman&edittask=' . ubRouting::get('edittask'));
  227. }
  228. }
  229. /**
  230. * SMS data flush
  231. */
  232. if (ubRouting::checkGet('flushsmsdata')) {
  233. ts_FlushSMSData(ubRouting::get('flushsmsdata'));
  234. ubRouting::nav('?module=taskman&edittask=' . ubRouting::get('flushsmsdata'));
  235. }
  236. /**
  237. * Salary accounting actions
  238. */
  239. if ($altCfg['SALARY_ENABLED']) {
  240. if (cfr('SALARYTASKSVIEW')) {
  241. //salary job deletion
  242. if (ubRouting::checkGet('deletejobid')) {
  243. $salary = new Salary(ubRouting::get('edittask'));
  244. $salary->deleteJob(ubRouting::get('deletejobid'));
  245. ubRouting::nav($salary::URL_TS . ubRouting::get('edittask'));
  246. }
  247. //salary job editing
  248. if (ubRouting::checkPost(array('editsalaryjobid', 'editsalaryemployeeid', 'editsalaryjobtypeid'))) {
  249. $salary = new Salary(ubRouting::get('edittask'));
  250. $salary->jobEdit(ubRouting::post('editsalaryjobid'), ubRouting::post('editsalaryemployeeid'), ubRouting::post('editsalaryjobtypeid'), ubRouting::post('editsalaryfactor'), ubRouting::post('editsalaryoverprice'), ubRouting::post('editsalarynotes'));
  251. ubRouting::nav($salary::URL_TS . ubRouting::get('edittask'));
  252. }
  253. //salary job creation
  254. if (ubRouting::checkPost(array('newsalarytaskid', 'newsalaryemployeeid', 'newsalaryjobtypeid'))) {
  255. $salary = new Salary(ubrouting::get('edittask'));
  256. $salary->createSalaryJob(ubRouting::post('newsalarytaskid'), ubRouting::post('newsalaryemployeeid'), ubRouting::post('newsalaryjobtypeid'), ubRouting::post('newsalaryfactor'), ubRouting::post('newsalaryoverprice'), ubRouting::post('newsalarynotes'));
  257. ubRouting::nav($salary::URL_TS . ubRouting::get('edittask'));
  258. }
  259. }
  260. }
  261. /**
  262. * start of task body rendering
  263. */
  264. $taskData = ts_GetTaskData(ubRouting::get('edittask'));
  265. if (!empty($taskData)) {
  266. $taskExistsFlag = true;
  267. } else {
  268. $taskExistsFlag = false;
  269. }
  270. /**
  271. * access restrictions here
  272. */
  273. $taskAccess = true;
  274. $cursedFlag = ts_isMeBranchCursed();
  275. if ($cursedFlag) {
  276. if ($taskExistsFlag) {
  277. if ($taskData['status']) {
  278. //task is already done - grant access to anyone. In GULAG too.
  279. $taskAccess = true;
  280. } else {
  281. //task is open. Check is this mine?
  282. $taskAccess = false;
  283. $taskEmployeeId = $taskData['employee'];
  284. $myLogin = whoami();
  285. $myEmployeeId = ts_GetEmployeeByLogin($myLogin);
  286. if (!empty($myEmployeeId)) {
  287. if ($taskEmployeeId == $myEmployeeId) {
  288. $taskAccess = true;
  289. }
  290. }
  291. }
  292. } else {
  293. $taskAccess = false;
  294. }
  295. }
  296. if ($taskExistsFlag) {
  297. if ($taskAccess) {
  298. /**
  299. * display task change form aka task profile
  300. */
  301. ts_TaskChangeForm(ubRouting::get('edittask'));
  302. /**
  303. * Task States support
  304. */
  305. if (@$altCfg['TASKSTATES_ENABLED']) {
  306. //existing task?
  307. if (!empty($taskData)) {
  308. $taskState = $taskData['status'];
  309. $taskStates = new TaskStates();
  310. show_window(__('Task state'), $taskStates->renderStatePanel(ubRouting::get('edittask'), $taskState));
  311. if (ubRouting::checkGet('changestate', 'edittask')) {
  312. $newStateSetResult = $taskStates->setTaskState(ubRouting::get('edittask'), ubRouting::get('changestate'));
  313. if (empty($newStateSetResult)) {
  314. die($taskStates->renderStatePanel(ubRouting::get('edittask'), $taskState));
  315. } else {
  316. $messages = new UbillingMessageHelper();
  317. die($messages->getStyledMessage($newStateSetResult, 'error'));
  318. }
  319. }
  320. } else {
  321. show_error(__('Something went wrong') . ': TASKID_NOT_EXISTS [' . ubRouting::get('edittask') . ']');
  322. }
  323. }
  324. /**
  325. * Employee task notices
  326. */
  327. if (@$altCfg['TASKWHATIDO_ENABLED']) {
  328. if (!empty($taskData)) {
  329. $taskWhatIdoReadOnly = ($taskData['status']) ? true : false;
  330. $taskWhatIdo = new Stigma('TASKWHATIDO', ubRouting::get('edittask'));
  331. $taskWhatIdo->stigmaController('TASKMAN:Done');
  332. show_window(__('What I did on the task'), $taskWhatIdo->render(ubRouting::get('edittask'), '128', $taskWhatIdoReadOnly));
  333. }
  334. }
  335. /**
  336. * photostorage integration
  337. */
  338. if ($altCfg['PHOTOSTORAGE_ENABLED']) {
  339. $photoStorage = new PhotoStorage('TASKMAN', ubRouting::get('edittask'));
  340. $renderPhotoControlFlag = true;
  341. if (@$altCfg['TASKSTATES_ENABLED']) {
  342. if (isset($taskState)) {
  343. if ($taskState) {
  344. //task already closed
  345. $renderPhotoControlFlag = false;
  346. }
  347. } else {
  348. //task not exists
  349. $renderPhotoControlFlag = false;
  350. }
  351. }
  352. if ($renderPhotoControlFlag) {
  353. $photostorageControl = wf_Link('?module=photostorage&scope=TASKMAN&mode=list&itemid=' . ubRouting::get('edittask'), wf_img('skins/photostorage.png') . ' ' . __('Upload images'), false, 'ubButton');
  354. $photostorageControl .= wf_delimiter();
  355. } else {
  356. $messages = new UbillingMessageHelper();
  357. $photostorageControl = $messages->getStyledMessage(__('You cant attach images for already closed task'), 'warning') . wf_delimiter();
  358. }
  359. $photosList = $photoStorage->renderImagesRaw();
  360. show_window(__('Photostorage'), $photostorageControl . $photosList);
  361. }
  362. /**
  363. * additional comments
  364. */
  365. if ($altCfg['ADCOMMENTS_ENABLED']) {
  366. $adcomments = new ADcomments('TASKMAN');
  367. show_window(__('Additional comments'), $adcomments->renderComments(ubrouting::get('edittask')));
  368. }
  369. } else {
  370. show_error(__('Access denied'));
  371. log_register('TASKMAN TASK ACCESS FAIL [' . ubRouting::get('edittask') . '] ADMIN {' . whoami() . '}');
  372. }
  373. } else {
  374. show_error(__('Something went wrong') . ': ' . __('Task') . ' [' . ubRouting::get('edittask') . ']' . ' ' . __('Not exists'));
  375. }
  376. }
  377. zb_BillingStats(true);
  378. } else {
  379. show_error(__('Access denied'));
  380. }