public function start($taskId) { global $CACHE_MANAGER, $USER; // Stop timer of user (if it is run) $this->stop(); $oTaskItem = CTaskItem::getInstance($taskId, $this->userId); $arTask = $oTaskItem->getData(false); if (!$oTaskItem->isActionAllowed(CTaskItem::ACTION_START_TIME_TRACKING)) { return false; } // Run timer for given task $arTimer = CTaskTimerCore::start($this->userId, $taskId); $this->cachedLastTimer = null; $arAffectedUsers = array_unique(array_merge(array($this->userId, $arTask['RESPONSIBLE_ID']), (array) $arTask['ACCOMPLICES'])); foreach ($arAffectedUsers as $userId) { $CACHE_MANAGER->ClearByTag('tasks_user_' . $userId); } if ($arTimer === false) { return false; } else { // Add task to day plan if (isset($USER) && is_object($USER) && $USER->getId() == $this->userId) { $arTasksInDayPlan = CTaskPlannerMaintance::getCurrentTasksList(); if (!in_array($taskId, $arTasksInDayPlan)) { CTaskPlannerMaintance::plannerActions(array('add' => array($taskId))); } } if ($arTask['REAL_STATUS'] != CTasks::STATE_IN_PROGRESS) { if (!$oTaskItem->isActionAllowed(CTaskItem::ACTION_START) && $oTaskItem->isActionAllowed(CTaskItem::ACTION_RENEW)) { $oTaskItem->renew(); } if ($oTaskItem->isActionAllowed(CTaskItem::ACTION_START)) { $oTaskItem->startExecution(); } } return $arTimer; } }
function tasksGetItemMenu($task, $arPaths, $site_id = SITE_ID, $bGantt = false, $top = false, $bSkipJsMenu = false) { global $USER; $arAllowedTaskActions = array(); if (isset($task['META:ALLOWED_ACTIONS'])) { $arAllowedTaskActions = $task['META:ALLOWED_ACTIONS']; } elseif ($task['ID']) { $oTask = CTaskItem::getInstanceFromPool($task['ID'], $USER->getId()); $arAllowedTaskActions = $oTask->getAllowedTaskActionsAsStrings(); $task['META:ALLOWED_ACTIONS'] = $arAllowedTaskActions; } $viewUrl = CComponentEngine::MakePathFromTemplate($arPaths["PATH_TO_TASKS_TASK"], array("task_id" => $task["ID"], "action" => "view")); $editUrl = CComponentEngine::MakePathFromTemplate($arPaths["PATH_TO_TASKS_TASK"], array("task_id" => $task["ID"], "action" => "edit")); $copyUrl = CComponentEngine::MakePathFromTemplate($arPaths["PATH_TO_TASKS_TASK"], array("task_id" => 0, "action" => "edit")); $createUrl = CComponentEngine::MakePathFromTemplate($arPaths["PATH_TO_TASKS_TASK"], array("task_id" => 0, "action" => "edit")); $createUrl = $createUrl . (strpos($createUrl, "?") === false ? "?" : "&") . "PARENT_ID=" . $task["ID"]; ?> { text : "<?php echo GetMessage("TASKS_VIEW_TASK"); ?> ", title : "<?php echo GetMessage("TASKS_VIEW_TASK_EX"); ?> ", className : "task-menu-popup-item-view", href : "<?php echo CUtil::JSEscape($viewUrl); ?> ", <?php if (!$bSkipJsMenu) { ?> onclick : function(event) {<?php if ($top) { ?> window.top.<?php } ?> ShowPopupTask(<?php echo $task["ID"]; ?> , event); this.popupWindow.close();} <?php } ?> }, <?php if ($arAllowedTaskActions['ACTION_EDIT']) { ?> { text : "<?php echo GetMessage("TASKS_EDIT_TASK"); ?> ", title : "<?php echo GetMessage("TASKS_EDIT_TASK_EX"); ?> ", className : "task-menu-popup-item-edit", href : "<?php echo CUtil::JSEscape($editUrl); ?> ", <?php if (!$bSkipJsMenu) { ?> onclick : function(event) {<?php if ($top) { ?> window.top.<?php } ?> EditPopupTask(<?php echo $task["ID"]; ?> , event); this.popupWindow.close();} <?php } ?> }, <?php } ?> { text : "<?php echo GetMessage("TASKS_ADD_SUBTASK"); ?> ", title : "<?php echo GetMessage("TASKS_ADD_SUBTASK"); ?> ", className : "task-menu-popup-item-create", href : "<?php echo CUtil::JSEscape($createUrl); ?> ", <?php if (!$bSkipJsMenu) { ?> onclick : function(event) {<?php if ($top) { ?> window.top.<?php } ?> AddPopupSubtask(<?php echo $task["ID"]; ?> , event); this.popupWindow.close();} <?php } ?> }, <?php if (!$bSkipJsMenu) { if (!$bGantt) { ?> { text : "<?php echo GetMessage("TASKS_ADD_QUICK_SUBTASK"); ?> ", title : "<?php echo GetMessage("TASKS_ADD_QUICK_SUBTASK"); ?> ", className : "task-menu-popup-item-create-quick", onclick : function(event) { ShowQuickTask( null, { parent: <?php echo $task["ID"]; if ($task["GROUP_ID"]) { ?> , group:{ id: <?php echo $task["GROUP_ID"]; ?> , title: '<?php echo CUtil::JSEscape($task["GROUP_NAME"]); ?> ' }<?php } ?> } ); this.popupWindow.close(); } },<?php } elseif ($arAllowedTaskActions['ACTION_EDIT'] || $arAllowedTaskActions['ACTION_CHANGE_DEADLINE']) { ?> { text : "<?php if (!$task["DEADLINE"]) { echo GetMessage("TASKS_ADD_DEADLINE"); } else { echo GetMessage("TASKS_REMOVE_DEADLINE"); } ?> ", title : "<?php if (!$task["DEADLINE"]) { echo GetMessage("TASKS_ADD_DEADLINE"); } else { echo GetMessage("TASKS_REMOVE_DEADLINE"); } ?> ", className : "<?php if (!$task["DEADLINE"]) { ?> task-menu-popup-item-add-deadline<?php } else { ?> task-menu-popup-item-remove-deadline<?php } ?> ", onclick : function(event, item) { <?php if ($top) { ?> var BX = window.top.BX; <?php } ?> if (BX.hasClass(item.layout.item, "task-menu-popup-item-add-deadline")) { BX.removeClass(item.layout.item, "task-menu-popup-item-add-deadline"); BX.addClass(item.layout.item, "task-menu-popup-item-remove-deadline"); item.layout.text.innerHTML = "<?php echo GetMessage("TASKS_REMOVE_DEADLINE"); ?> "; var deadline = BX.GanttChart.convertDateFromUTC(this.params.task.dateEnd); deadline.setDate(deadline.getDate() + 3); this.params.task.setDateDeadline(deadline); this.params.task.redraw(); this.popupWindow.close(); var data = { mode : "deadline", sessid : BX.message("bitrix_sessid"), id : this.params.task.id, deadline : tasksFormatDate(deadline) }; BX.ajax.post(ajaxUrl, data); } else { BX.removeClass(item.layout.item, "task-menu-popup-item-remove-deadline"); BX.addClass(item.layout.item, "task-menu-popup-item-add-deadline"); item.layout.text.innerHTML = "<?php echo GetMessage("TASKS_ADD_DEADLINE"); ?> "; this.params.task.setDateDeadline(null); this.params.task.redraw(); this.popupWindow.close(); var data = { mode : "deadline", sessid : BX.message("bitrix_sessid"), id : this.params.task.id, deadline : "" }; BX.ajax.post(ajaxUrl, data); } } },<?php } } if (!$bSkipJsMenu) { if ($arAllowedTaskActions['ACTION_COMPLETE']) { ?> { text : "<?php echo GetMessage("TASKS_CLOSE_TASK"); ?> ", title : "<?php echo GetMessage("TASKS_CLOSE_TASK"); ?> ", className : "task-menu-popup-item-complete", onclick : function() { <?php if ($top) { ?> window.top.<?php } ?> CloseTask(<?php echo $task["ID"]; ?> ); this.popupWindow.close();} },<?php } if ($arAllowedTaskActions['ACTION_ACCEPT']) { ?> { text : "<?php echo GetMessage("TASKS_ACCEPT_TASK"); ?> ", title : "<?php echo GetMessage("TASKS_ACCEPT_TASK"); ?> ", className : "task-menu-popup-item-take", onclick : function(event) { <?php if ($top) { ?> window.top.<?php } ?> AcceptTask(<?php echo $task["ID"]; ?> ); this.popupWindow.close();} },<?php } if ($arAllowedTaskActions['ACTION_START']) { ?> { text : "<?php echo GetMessage("TASKS_START_TASK"); ?> ", title : "<?php echo GetMessage("TASKS_START_TASK"); ?> ", className : "task-menu-popup-item-begin", onclick : function(event) { <?php if ($top) { ?> window.top.<?php } ?> StartTask(<?php echo $task["ID"]; ?> ); this.popupWindow.close();} },<?php } if ($arAllowedTaskActions['ACTION_PAUSE']) { ?> { text : "<?php echo GetMessage("TASKS_PAUSE_TASK"); ?> ", title : "<?php echo GetMessage("TASKS_PAUSE_TASK"); ?> ", className : "task-menu-popup-item-pause", onclick : function(event) { <?php if ($top) { ?> window.top.<?php } ?> PauseTask(<?php echo $task["ID"]; ?> ); this.popupWindow.close();} },<?php } if ($arAllowedTaskActions['ACTION_DECLINE']) { ?> { text : "<?php echo GetMessage("TASKS_DECLINE_TASK"); ?> ", title : "<?php echo GetMessage("TASKS_DECLINE_TASK"); ?> ", className : "task-menu-popup-item-decline", onclick : function(event) { <?php if ($top) { ?> window.top.<?php } ?> DeclineTask(<?php echo $task["ID"]; ?> ); this.popupWindow.close();} },<?php } if ($arAllowedTaskActions['ACTION_RENEW']) { ?> { text : "<?php echo GetMessage("TASKS_RENEW_TASK"); ?> ", title : "<?php echo GetMessage("TASKS_RENEW_TASK"); ?> ", className : "task-menu-popup-item-reopen", onclick : function(event) { <?php if ($top) { ?> window.top.<?php } ?> RenewTask(<?php echo $task["ID"]; ?> ); this.popupWindow.close();} },<?php } if ($arAllowedTaskActions['ACTION_DEFER']) { ?> { text : "<?php echo GetMessage("TASKS_DEFER_TASK"); ?> ", title : "<?php echo GetMessage("TASKS_DEFER_TASK"); ?> ", className : "task-menu-popup-item-hold", onclick : function(event) { <?php if ($top) { ?> window.top.<?php } ?> DeferTask(<?php echo $task["ID"]; ?> ); this.popupWindow.close();} },<?php } if ($arAllowedTaskActions['ACTION_APPROVE']) { ?> { text : "<?php echo GetMessage("TASKS_APPROVE_TASK"); ?> ", title : "<?php echo GetMessage("TASKS_APPROVE_TASK"); ?> ", className : "task-menu-popup-item-accept", onclick : function(event) { <?php if ($top) { ?> window.top.<?php } ?> tasksListNS.approveTask(<?php echo $task["ID"]; ?> ); this.popupWindow.close();} },<?php } if ($arAllowedTaskActions['ACTION_DISAPPROVE']) { ?> { text : "<?php echo GetMessage("TASKS_REDO_TASK"); ?> ", title : "<?php echo GetMessage("TASKS_REDO_TASK"); ?> ", className : "task-menu-popup-item-remake", onclick : function(event) { <?php if ($top) { ?> window.top.<?php } ?> tasksListNS.disapproveTask(<?php echo $task["ID"]; ?> ); this.popupWindow.close();} },<?php } } ?> { text : "<?php echo GetMessage("TASKS_COPY_TASK"); ?> ", title : "<?php echo GetMessage("TASKS_COPY_TASK_EX"); ?> ", className : "task-menu-popup-item-copy", href : "<?php echo $copyUrl . (strpos($copyUrl, "?") === false ? "?" : "&") . "COPY=" . $task["ID"]; ?> ", <?php if (!$bSkipJsMenu) { ?> onclick : function(event) {<?php if ($top) { ?> window.top.<?php } ?> CopyPopupTask(<?php echo $task["ID"]; ?> , event); this.popupWindow.close();} <?php } ?> }, <?php if (!$bSkipJsMenu) { // Only responsible person and accomplices can add task to day plan // And we must be not at extranet site if (($task["RESPONSIBLE_ID"] == $USER->GetID() || is_array($task['ACCOMPLICES']) && in_array($USER->GetID(), $task['ACCOMPLICES'])) && (!CModule::IncludeModule('extranet') || !CExtranet::IsExtranetSite())) { $arTasksInPlan = CTaskPlannerMaintance::getCurrentTasksList(); // If not in day plan already if (!(is_array($arTasksInPlan) && in_array($task["ID"], $arTasksInPlan))) { ?> { text : "<?php echo GetMessage("TASKS_ADD_TASK_TO_TIMEMAN"); ?> ", title : "<?php echo GetMessage("TASKS_ADD_TASK_TO_TIMEMAN_EX"); ?> ", className : "task-menu-popup-item-add-to-tm", onclick : function(event, item) { <?php if ($top) { echo 'top.Add2Timeman(this, ' . (int) $task["ID"] . ')'; } else { echo 'Add2Timeman(this, ' . (int) $task["ID"] . ')'; } ?> } },<?php } } } ?> <?php if (!$bSkipJsMenu) { if ($arAllowedTaskActions['ACTION_REMOVE']) { ?> { text : "<?php echo GetMessage("TASKS_DELETE_TASK"); ?> ", title : "<?php echo GetMessage("TASKS_DELETE_TASK"); ?> ", className : "task-menu-popup-item-delete", onclick : function(event) { if(confirm("<?php echo GetMessage("TASKS_DELETE_TASKS_CONFIRM"); ?> ")) { this.menuItems = []; this.bindElement.onclick = function() { return (false); }; <?php if ($top) { ?> top.<?php } ?> DeleteTask(<?php echo $task["ID"]; ?> ); } this.popupWindow.close(); } },<?php } } ?> {} <?php }
public static function plannerActions($arActions, $site_id = SITE_ID) { global $USER, $CACHE_MANAGER; self::$SITE_ID = $site_id; self::$USER_ID = $USER->GetID(); $lastTaskId = 0; $arTasks = self::getCurrentTasksList(); if (!is_array($arTasks)) { $arTasks = array(); } if (strlen($arActions['name']) > 0) { $obt = new CTasks(); $ID = $obt->Add(array('RESPONSIBLE_ID' => self::$USER_ID, 'TITLE' => $arActions['name'], 'TAGS' => array(), 'STATUS' => 2, 'SITE_ID' => self::$SITE_ID)); if ($ID) { if (!is_array($arActions['add'])) { $arActions['add'] = array($ID); } else { $arActions['add'][] = $ID; } } } if (is_array($arActions['add'])) { $task_id = $lastTaskId; foreach ($arActions['add'] as $task_id) { $arTasks[] = intval($task_id); } $lastTaskId = $task_id; } $arTasks = array_unique($arTasks); if (is_array($arActions['remove'])) { $arActions['remove'] = array_unique($arActions['remove']); foreach ($arActions['remove'] as $task_id) { $task_id = intval($task_id); if (($key = array_search($task_id, $arTasks)) !== false) { unset($arTasks[$key]); } } } $CACHE_MANAGER->ClearByTag('tasks_user_' . self::$USER_ID); self::setCurrentTasksList($arTasks); return $lastTaskId; }
$arResult['TASK'] = $oTask->getData(); $arResult['TASK']['META:ALLOWED_ACTIONS_CODES'] = $oTask->getAllowedTaskActions(); $arResult['TASK']['META:ALLOWED_ACTIONS'] = $arResult['ALLOWED_ACTIONS']; $arResult['TASK']['META:IN_DAY_PLAN'] = 'N'; $arResult['TASK']['META:CAN_ADD_TO_DAY_PLAN'] = 'N'; // Was task created from template? if ($arResult['TASK']['FORKED_BY_TEMPLATE_ID']) { $rsTemplate = CTaskTemplates::GetByID($arResult['TASK']['FORKED_BY_TEMPLATE_ID']); if ($arTemplate = $rsTemplate->Fetch()) { $arTemplate['REPLICATE_PARAMS'] = unserialize($arTemplate['REPLICATE_PARAMS']); $arResult['TASK']['FORKED_BY_TEMPLATE'] = $arTemplate; } } if (($arResult['TASK']["RESPONSIBLE_ID"] == $arResult['LOGGED_IN_USER'] || in_array($arResult['LOGGED_IN_USER'], $arResult['TASK']['ACCOMPLICES'])) && CModule::IncludeModule("timeman") && (!CModule::IncludeModule('extranet') || !CExtranet::IsExtranetSite())) { $arResult['TASK']['META:CAN_ADD_TO_DAY_PLAN'] = 'Y'; $arTasksInPlan = CTaskPlannerMaintance::getCurrentTasksList(); // If in day plan already if (is_array($arTasksInPlan) && in_array($arResult['TASK']["ID"], $arTasksInPlan)) { $arResult['TASK']['META:IN_DAY_PLAN'] = 'Y'; $arResult['TASK']['META:CAN_ADD_TO_DAY_PLAN'] = 'N'; } } } if (isset($arParams['TASK_ID']) && (in_array('buttons', $arResult['BLOCKS']) || in_array('right_sidebar', $arResult['BLOCKS']))) { if (!isset($arParams['TIMER'])) { $oTimer = CTaskTimerManager::getInstance($arResult['LOGGED_IN_USER']); $arTimer = $oTimer->getLastTimer(false); $arResult['TIMER'] = $arTimer; } else { $arResult['TIMER'] = $arParams['TIMER']; }
/** * Inject info about timeman */ protected static function injectTimemanFields($userId, array $parameters, array &$data, array &$can) { if (empty($data)) { return; } if (Loader::includeModule('timeman') && (!Loader::includeModule('extranet') || !\CExtranet::IsExtranetSite())) { $plan = \CTaskPlannerMaintance::getCurrentTasksList(); if (is_array($plan) && !empty($plan)) { $plan = array_flip($plan); foreach ($data as &$task) { $inDayPlan = false; $canAddToPlan = false; if ($task["RESPONSIBLE_ID"] == $userId || is_array($task['ACCOMPLICES']) && in_array($userId, $task['ACCOMPLICES'])) { $canAddToPlan = true; // If in day plan already if (isset($plan[$task['ID']])) { $inDayPlan = true; $canAddToPlan = false; } } $task['IN_DAY_PLAN'] = $inDayPlan; $can[$task['ID']]['ACTION']['ADD_TO_DAY_PLAN'] = $canAddToPlan; } } } }
$templateData = CTaskTemplates::GetList(false, array('ID' => intval($arResult['COPY_PARAMS']['ORIGIN_TEMPLATE'])), false, array('USER_ID' => $loggedInUserId), array('ID'))->fetch(); if (is_array($templateData)) { $oTask->addChildTasksByTemplate(intval($arResult['COPY_PARAMS']['ORIGIN_TEMPLATE'])); // task access rights check inside } } } catch (Exception $e) { if ($e->GetCode() & TasksException::TE_FLAG_SERIALIZED_ERRORS_IN_MESSAGE) { $arResult['ERRORS'] = unserialize($e->GetMessage()); } else { $arResult['ERRORS'][] = array('text' => 'UNKNOWN ERROR OCCURED', 'id' => 'ERROR_TASKS_UNKNOWN'); } } } if ($_POST["ADD_TO_TIMEMAN"] == "Y") { CTaskPlannerMaintance::plannerActions(array('add' => array($taskID))); } if ($arFields["REPLICATE"] == "Y") { unset($arTemplateFields["DEADLINE"], $arTemplateFields["START_DATE_PLAN"], $arTemplateFields["END_DATE_PLAN"]); $arTemplateFields["TASK_ID"] = $taskID; $arTemplateFields["ACCOMPLICES"] = sizeof($arTemplateFields["ACCOMPLICES"]) ? serialize($arTemplateFields["ACCOMPLICES"]) : false; $arTemplateFields["AUDITORS"] = sizeof($arTemplateFields["AUDITORS"]) ? serialize($arTemplateFields["AUDITORS"]) : false; $arTemplateFields["TAGS"] = strlen(trim($arTemplateFields["TAGS"])) > 0 ? serialize(explode(",", $arTemplateFields["TAGS"])) : false; $arTemplateFields["FILES"] = sizeof($arTemplateFields["FILES"]) ? serialize($arTemplateFields["FILES"]) : false; $arTemplateFields["DEPENDS_ON"] = sizeof($arTemplateFields["DEPENDS_ON"]) ? serialize($arTemplateFields["DEPENDS_ON"]) : false; $arTemplateFields["REPLICATE_PARAMS"] = serialize($arTemplateFields["REPLICATE_PARAMS"]); $taskTemplate = new CTaskTemplates(); $templateId = $taskTemplate->Add($arTemplateFields, array('CHECK_RIGHTS_ON_FILES' => 'Y', 'USER_ID' => $USER->getId())); if (intval($templateId)) { // checklist if (is_array($_POST['CHECKLIST_ITEM_ID'])) {