예제 #1
0
 /**
  * Create a task by a template.
  *
  * @param integer $templateId - Id of task template.
  * @param integer $executiveUserId User id. Put 1 here to skip rights.
  * @param mixed[] $overrideTaskData Task data needs to be overrided externally.
  * @param mixed[] $parameters Various set of parameters.
  * 
  * 		<li> TEMPLATE_DATA mixed[] 			pre-cached data, if available we can get rid of additional queries
  * 		<li> CREATE_CHILD_TASKS boolean 	if false, sub-tasks wont be created
  * 		<li> CREATE_MULTITASK boolean		if false, discards template rule of "copying task to several responsibles"
  * 		<li> BEFORE_ADD_CALLBACK callable 		callback called before each task added, allows to modify data passed to CTaskItem::add()
  * 
  * @throws TasksException - on access denied, task not found
  * @throws CTaskAssertException
  * @throws Exception - on unexpected error
  *
  * @return CTaskItem[]
  */
 public static function addByTemplate($templateId, $executiveUserId, $overrideTaskData = array(), $parameters = array('TEMPLATE_DATA' => array(), 'CREATE_CHILD_TASKS' => true, 'CREATE_MULTITASK' => true, 'BEFORE_ADD_CALLBACK' => null, 'SPAWNED_BY_AGENT' => false))
 {
     CTaskAssert::assertLaxIntegers($executiveUserId);
     CTaskAssert::assert($executiveUserId > 0);
     global $DB;
     $templateId = (int) $templateId;
     if (!$templateId) {
         return array();
         // template id not set
     }
     if (!is_array($overrideTaskData)) {
         $overrideTaskData = array();
     }
     if (!is_array($parameters)) {
         $parameters = array();
     }
     if (!isset($parameters['CREATE_CHILD_TASKS'])) {
         $parameters['CREATE_CHILD_TASKS'] = true;
     }
     if (!isset($parameters['CREATE_MULTITASK'])) {
         $parameters['CREATE_MULTITASK'] = true;
     }
     if (!isset($parameters['BEFORE_ADD_CALLBACK'])) {
         $parameters['BEFORE_ADD_CALLBACK'] = null;
     }
     if (!isset($parameters['SPAWNED_BY_AGENT'])) {
         $parameters['SPAWNED_BY_AGENT'] = false;
     }
     // read template data
     if (is_array($parameters['TEMPLATE_DATA']) && !empty($parameters['TEMPLATE_DATA'])) {
         $arTemplate = $parameters['TEMPLATE_DATA'];
     } else {
         $arFilter = array('ID' => $templateId);
         $rsTemplate = CTaskTemplates::GetList(array(), $arFilter);
         $arTemplate = $rsTemplate->Fetch();
         if (!$arTemplate) {
             return array();
             // nothing to do
         }
     }
     $arTemplate = array_merge($arTemplate, $overrideTaskData);
     if (!isset($arTemplate['CHECK_LIST'])) {
         // get template checklist
         $arTemplate['CHECK_LIST'] = array();
         $res = \Bitrix\Tasks\Template\CheckListItemTable::getList(array('filter' => array('TEMPLATE_ID' => $templateId), 'select' => array('IS_COMPLETE', 'SORT_INDEX', 'TITLE')));
         while ($item = $res->fetch()) {
             $arTemplate['CHECK_LIST'][] = $item;
         }
     }
     //////////////////////////////////////////////
     //////////////////////////////////////////////
     //////////////////////////////////////////////
     unset($arTemplate['STATUS']);
     $arFields = $arTemplate;
     $arFields['CREATED_DATE'] = date($DB->DateFormatToPHP(CSite::GetDateFormat('FULL')), time() + CTimeZone::GetOffset());
     $arFields['ACCOMPLICES'] = unserialize($arFields['ACCOMPLICES']);
     $arFields['AUDITORS'] = unserialize($arFields['AUDITORS']);
     $arFields['TAGS'] = unserialize($arFields['TAGS']);
     $arFields['FILES'] = unserialize($arFields['FILES']);
     $arFields['DEPENDS_ON'] = unserialize($arFields['DEPENDS_ON']);
     $arFields['REPLICATE'] = 'N';
     $arFields['CHANGED_BY'] = $arFields['CREATED_BY'];
     $arFields['CHANGED_DATE'] = $arFields['CREATED_DATE'];
     if (!$arFields['ACCOMPLICES']) {
         $arFields['ACCOMPLICES'] = array();
     }
     if (!$arFields['AUDITORS']) {
         $arFields['AUDITORS'] = array();
     }
     unset($arFields['ID'], $arFields['REPLICATE'], $arFields['REPLICATE_PARAMS']);
     if ($arTemplate['DEADLINE_AFTER']) {
         $deadlineAfter = $arTemplate['DEADLINE_AFTER'] / (24 * 60 * 60);
         $deadline = strtotime(date('Y-m-d 00:00') . ' +' . $deadlineAfter . ' days');
         $arFields['DEADLINE'] = date($DB->DateFormatToPHP(CSite::GetDateFormat('SHORT')), $deadline);
     }
     $multitaskMode = false;
     if ($parameters['CREATE_MULTITASK']) {
         $arFields['RESPONSIBLES'] = unserialize($arFields['RESPONSIBLES']);
         // copy task to multiple responsibles
         if ($arFields['MULTITASK'] == 'Y' && !empty($arFields['RESPONSIBLES'])) {
             $arFields['RESPONSIBLE_ID'] = $arFields['CREATED_BY'];
             $multitaskMode = true;
         } else {
             $arFields['RESPONSIBLES'] = array();
         }
     } else {
         $arFields['MULTITASK'] = 'N';
         $arFields['RESPONSIBLES'] = array();
     }
     $arFields['FORKED_BY_TEMPLATE_ID'] = $templateId;
     // add main task to the create list
     $tasksToCreate = array($arFields);
     // if MULTITASK where set to Y, create a duplicate task for each of RESPONSIBLES
     if (!empty($arFields['RESPONSIBLES'])) {
         $arFields['MULTITASK'] = 'N';
         foreach ($arFields['RESPONSIBLES'] as $responsible) {
             $arFields['RESPONSIBLE_ID'] = $responsible;
             $tasksToCreate[] = $arFields;
         }
     }
     // get sub-templates
     $subTasksToCreate = array();
     if ($parameters['CREATE_CHILD_TASKS'] !== false) {
         $subTasksToCreate = static::getChildTemplateData($templateId);
     }
     $created = array();
     // first, create ROOT tasks
     $multitaskTaskId = false;
     $i = 0;
     foreach ($tasksToCreate as $arFields) {
         if ($multitaskMode && $i > 0) {
             if ($multitaskTaskId) {
                 // all following tasks will be subtasks of a base task in case of MULTITASK was turned on
                 $arFields['PARENT_ID'] = $multitaskTaskId;
             } else {
                 break;
                 // no child tasks will be created, because parent task failed to be created
             }
         }
         $add = true;
         if (is_callable($parameters['BEFORE_ADD_CALLBACK'])) {
             $result = call_user_func_array($parameters['BEFORE_ADD_CALLBACK'], array(&$arFields));
             if ($result === false) {
                 $add = false;
             }
         }
         if ($add) {
             // temporary commented out, because there is currently no way to pass
             // 'SPAWNED_BY_AGENT' => true
             // parameter to CTaskTemplate::add() :
             //$taskInstance = static::add($arFields, $executiveUserId);
             //$taskId = $taskInstance->getId();
             $task = new CTasks();
             $taskId = $task->Add($arFields, array('SPAWNED_BY_AGENT' => !!$parameters['SPAWNED_BY_AGENT'], 'USER_ID' => $executiveUserId));
             if (intval($taskId)) {
                 $taskInstance = static::getInstance($taskId, $executiveUserId);
                 // the first task should be mom in case of multitasking
                 if ($multitaskMode && $i == 0) {
                     $multitaskTaskId = $taskId;
                 }
                 // check list items for root task
                 foreach ($arTemplate['CHECK_LIST'] as $item) {
                     CTaskCheckListItem::add($taskInstance, $item);
                 }
                 $created[$taskId] = $taskInstance;
                 if (!empty($subTasksToCreate)) {
                     $notifADWasDisabled = CTaskNotifications::disableAutoDeliver();
                     $createdSubtasks = $taskInstance->addChildTasksByTemplate($templateId, array('CHILD_TEMPLATE_DATA' => $subTasksToCreate, 'BEFORE_ADD_CALLBACK' => $parameters['BEFORE_ADD_CALLBACK'], 'SPAWNED_BY_AGENT' => $parameters['SPAWNED_BY_AGENT']));
                     if ($notifADWasDisabled) {
                         CTaskNotifications::enableAutoDeliver();
                     }
                     if (is_array($createdSubtasks) && !empty($createdSubtasks)) {
                         foreach ($createdSubtasks as $ctId => $ctInst) {
                             $created[$ctId] = $ctInst;
                         }
                     }
                 }
             }
         }
         $i++;
     }
     return $created;
 }
예제 #2
0
     $dbRes = CIBlock::GetList(array(), array("SITE_ID" => WIZARD_SITE_ID, "CODE" => "group_photogallery_" . WIZARD_SITE_ID));
     if ($arRes = $dbRes->Fetch()) {
         $photoGroupIBlockID = $arRes["ID"];
     }
 }
 // tasks 2.0
 $arTasks = array(array("CREATED_BY" => 1, "RESPONSIBLE_ID" => 1, "PRIORITY" => 1, "STATUS" => 2, "TITLE" => GetMessage("SONET_TASK_TITLE_1"), "DESCRIPTION" => GetMessage("SONET_TASK_DESCRIPTION_1"), "SITE_ID" => WIZARD_SITE_ID, "XML_ID" => md5(GetMessage("SONET_TASK_TITLE_1") . GetMessage("SONET_TASK_DESCRIPTION_1") . WIZARD_SITE_ID)), array("CREATED_BY" => 1, "RESPONSIBLE_ID" => 1, "PRIORITY" => 1, "STATUS" => 2, "TITLE" => GetMessage("SONET_TASK_TITLE_2"), "DESCRIPTION" => GetMessage("SONET_TASK_DESCRIPTION_2"), "SITE_ID" => WIZARD_SITE_ID, "XML_ID" => md5(GetMessage("SONET_TASK_TITLE_2") . GetMessage("SONET_TASK_DESCRIPTION_2") . WIZARD_SITE_ID)));
 if (CModule::IncludeModule("tasks")) {
     foreach ($arTasks as $task) {
         $obTask = new CTasks();
         $strSql = "SELECT ID FROM b_tasks WHERE XML_ID = '" . $task["XML_ID"] . "'";
         $rsTask = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         if ($oldTask = $rsTask->Fetch()) {
             $obTask->Update($oldTask["ID"], $task);
         } else {
             $obTask->Add($task);
         }
     }
 }
 // tasks
 $tasksIblockId = 0;
 $tasksForumId = 0;
 if (CModule::IncludeModule("iblock")) {
     $iblockCode = "intranet_tasks";
     $iblockType = "services";
     $rsIBlock = CIBlock::GetList(array(), array("XML_ID" => $iblockCode, "TYPE" => $iblockType));
     if ($arIBlock = $rsIBlock->Fetch()) {
         $tasksIblockId = $arIBlock["ID"];
     }
     if ($tasksIblockId == 0) {
         $tasksIblockId = WizardServices::ImportIBlockFromXML(WIZARD_SERVICE_RELATIVE_PATH . "/xml/" . LANGUAGE_ID . "/tasks.xml", $iblockCode, $iblockType, WIZARD_SITE_ID, array("1" => "X", "2" => "R", WIZARD_PORTAL_ADMINISTRATION_GROUP => "X"));
예제 #3
0
 public static function SaveTask($tasksData)
 {
     $rc = false;
     if (!$GLOBALS['USER']->IsAuthorized()) {
         return false;
     }
     $delegateToUser = false;
     if (isset($tasksData['META::DELEGATE_TO_USER'])) {
         $delegateToUser = (int) $tasksData['META::DELEGATE_TO_USER'];
     }
     $bDelegate = false;
     if ($delegateToUser > 0) {
         $bDelegate = true;
     }
     $curUserId = (int) $GLOBALS['USER']->GetID();
     if (!CModule::IncludeModule('socialnetwork')) {
         return false;
     }
     $arNewTaskFields = false;
     $bErrorOccuredOnTaskCreation = false;
     if (isset($tasksData['TASK_ID']) && check_bitrix_sessid()) {
         $bCreateMode = true;
         if ($tasksData['TASK_ID'] > 0) {
             $bCreateMode = false;
         }
         // We are in edit mode
         if ($bCreateMode && $bDelegate) {
             throw new Exception('$bCreateMode && $bDelegate');
         }
         if (!$bCreateMode && $bDelegate) {
             $arNewTaskFields = array();
             if (intval($delegateToUser) !== $curUserId) {
                 $arNewTaskFields['RESPONSIBLE_ID'] = $delegateToUser;
                 $arNewTaskFields['STATUS'] = CTasks::STATE_PENDING;
                 $rsTask = CTasks::GetByID($tasksData['TASK_ID']);
                 $arTask = $rsTask->Fetch();
                 if (!$arTask || !isset($arTask['ID'])) {
                     return false;
                 }
                 if (sizeof($arTask['AUDITORS'] > 0)) {
                     if (!in_array($curUserId, $arTask['AUDITORS'])) {
                         $arNewTaskFields['AUDITORS'] = $arTask['AUDITORS'];
                         $arNewTaskFields['AUDITORS'][] = $curUserId;
                     }
                 } else {
                     $arNewTaskFields['AUDITORS'] = array($curUserId);
                 }
             } else {
                 return false;
             }
         } else {
             $arNewTaskFields = array('TITLE' => $tasksData['TITLE'], 'DESCRIPTION' => $tasksData['DESCRIPTION'], 'RESPONSIBLE_ID' => $tasksData['RESPONSIBLE_ID'], 'PRIORITY' => $tasksData['PRIORITY'], 'DEADLINE' => CAllDatabase::FormatDate(str_replace('T', ' ', $tasksData['DEADLINE']), 'YYYY-MM-DD HH:MI:SS', FORMAT_DATETIME));
             if (isset($tasksData['ACCOMPLICES'])) {
                 if ($tasksData['ACCOMPLICES'] == -1) {
                     $arNewTaskFields['ACCOMPLICES'] = array();
                 } else {
                     $arNewTaskFields['ACCOMPLICES'] = $tasksData['ACCOMPLICES'];
                 }
             }
             if (isset($tasksData['AUDITORS'])) {
                 if ($tasksData['AUDITORS'] == -1) {
                     $arNewTaskFields['AUDITORS'] = array();
                 } else {
                     $arNewTaskFields['AUDITORS'] = $tasksData['AUDITORS'];
                 }
             }
             $arNewTaskFields['GROUP_ID'] = 0;
             if (isset($tasksData['GROUP_ID']) && intval($tasksData['GROUP_ID']) > 0) {
                 if (CSocNetFeaturesPerms::CurrentUserCanPerformOperation(SONET_ENTITY_GROUP, (int) $tasksData['GROUP_ID'], 'tasks', 'create_tasks')) {
                     $arNewTaskFields['GROUP_ID'] = (int) $tasksData['GROUP_ID'];
                 } else {
                     unset($arNewTaskFields['GROUP_ID']);
                 }
             }
             if ($bCreateMode) {
                 $arNewTaskFields['CREATED_BY'] = $curUserId;
             }
         }
         if (isset($tasksData['META::EVENT_GUID'])) {
             $arNewTaskFields['META::EVENT_GUID'] = $tasksData['META::EVENT_GUID'];
         }
         if ($bCreateMode) {
             $arNewTaskFields['ID'] = 0;
         } else {
             $arNewTaskFields['ID'] = (int) $tasksData['TASK_ID'];
         }
         $oTask = new CTasks();
         if (!$bCreateMode) {
             $rc = $oTask->Update($arNewTaskFields['ID'], $arNewTaskFields);
         } else {
             $arNewTaskFields['MULTITASK'] = 'N';
             $arNewTaskFields['DESCRIPTION_IN_BBCODE'] = 'Y';
             // Only creator or priveleged user can set responsible person.
             $arNewTaskFields['RESPONSIBLE_ID'] = $curUserId;
             if ($arNewTaskFields['CREATED_BY'] === $curUserId || $GLOBALS['USER']->IsAdmin() || CTasksTools::IsPortalB24Admin()) {
                 $arNewTaskFields['RESPONSIBLE_ID'] = (int) $tasksData['RESPONSIBLE_ID'];
             }
             $arNewTaskFields['SITE_ID'] = SITE_ID;
             $rc = $oTask->Add($arNewTaskFields);
             if ($rc > 0) {
                 $arNewTaskFields['ID'] = $rc;
             } else {
                 $bErrorOccuredOnTaskCreation = true;
             }
         }
         $rc = $arNewTaskFields['ID'];
     }
     if ($bErrorOccuredOnTaskCreation) {
         return false;
     }
     return $rc;
 }
예제 #4
0
 }
 if ($GROUP_ID > 0) {
     if (CSocNetFeaturesPerms::CurrentUserCanPerformOperation(SONET_ENTITY_GROUP, $GROUP_ID, "tasks", "create_tasks")) {
         $arFields["GROUP_ID"] = $GROUP_ID;
     }
 }
 if ($DB->FormatDate($_POST["deadline"], CSite::GetDateFormat("FULL"))) {
     $arFields["DEADLINE"] = $_POST["deadline"];
 }
 $depth = intval($_POST["depth"]);
 if (intval($_POST["parent"]) > 0) {
     $arFields["PARENT_ID"] = intval($_POST["parent"]);
 }
 $arFields["STATUS"] = $status;
 $task = new CTasks();
 $ID = $task->Add($arFields);
 if ($ID) {
     $rsTask = CTasks::GetByID($ID);
     if ($task = $rsTask->GetNext()) {
         $APPLICATION->RestartBuffer();
         ob_start();
         if ($task["GROUP_ID"]) {
             $arGroup = CSocNetGroup::GetByID($task["GROUP_ID"]);
             if ($arGroup) {
                 $task["GROUP_NAME"] = $arGroup["NAME"];
             }
         }
         $params = array("PATHS" => $arPaths, "PLAIN" => false, "DEFER" => true, "SITE_ID" => $SITE_ID, "TASK_ADDED" => true, 'IFRAME' => 'N', "NAME_TEMPLATE" => $nameTemplate, 'DATA_COLLECTION' => array(array("CHILDREN_COUNT" => 0, "DEPTH" => $depth, "UPDATES_COUNT" => 0, "PROJECT_EXPANDED" => true, 'ALLOWED_ACTIONS' => null, "TASK" => $task)));
         $columnsOrder = null;
         if (isset($_POST['columnsOrder'])) {
             $columnsOrder = array_map('intval', $_POST['columnsOrder']);
예제 #5
0
 function UpdateListItems($listName, $updates)
 {
     global $USER, $DB;
     $arPaths = array('user' => COption::GetOptionString('intranet', 'path_task_user_entry', '/company/personal/user/#USER_ID#/tasks/task/view/#TASK_ID#/'), 'group' => COption::GetOptionString('intranet', 'path_task_group_entry', '/workgroups/group/#GROUP_ID#/tasks/task/view/#TASK_ID#/'));
     if (!$this->__Init()) {
         return $this->error;
     }
     if (!($listName_original = CIntranetUtils::checkGUID($listName))) {
         return new CSoapFault('Data error', 'Wrong GUID - ' . $listName);
     }
     $listName = ToUpper(CIntranetUtils::makeGUID($listName_original));
     $obResponse = new CXMLCreator('Results');
     $obBatch = $updates->children[0];
     $atrONERROR = $obBatch->getAttribute('OnError');
     $atrDATEINUTC = $obBatch->getAttribute('DateInUtc');
     $atrPROPERTIES = $obBatch->getAttribute('Properties');
     $arChanges = $obBatch->children;
     $arResultIDs = array();
     $dateStart = ConvertTimeStamp(strtotime('-1 hour'), 'FULL');
     $arResponseRows = array();
     $arResponseRowsError = array();
     $arReplicationIDs = array();
     foreach ($arChanges as $obMethod) {
         $arData = array('_command' => $obMethod->getAttribute('Cmd'));
         $ID = false;
         $bUpdate = true;
         $arElement = false;
         $arSection = $this->arUsersSection;
         foreach ($obMethod->children as $obField) {
             $name = $obField->getAttribute('Name');
             if ($name == 'MetaInfo') {
                 $name .= '_' . $obField->getAttribute('Property');
             }
             $arData[$name] = $obField->content;
         }
         $obResponseRow = new CXMLCreator('Result');
         $obResponseRow->setAttribute('ID', $obMethod->getAttribute('ID') . ',' . $arData['_command']);
         $obResponseRow->setAttribute('List', $listName);
         $obResponseRow->addChild($obErrorCode = new CXMLCreator('ErrorCode'));
         if ($arData['ID'] > 0) {
             $rsElement = CTasks::GetById($arData['ID']);
             if ($rsElement && ($arElement = $rsElement->Fetch())) {
                 if (!is_array($arElement)) {
                     $obErrorCode->setData('0x81020016');
                     $bUpdate = false;
                 } else {
                     if ($arElement['taskType'] == "group") {
                         $arGroupTmp = CSocNetGroup::GetByID($arElement['ownerId']);
                         if ($arGroupTmp["CLOSED"] == "Y") {
                             if (COption::GetOptionString("socialnetwork", "work_with_closed_groups", "N") != "Y") {
                                 return new CSoapFault('Cannot modify archive group task', 'Cannot modify archive group task');
                             }
                         }
                     }
                     $arElement['arParams'] = array(intval($arElement['GROUP_ID']) > 0 ? 'PATH_TO_USER_TASKS_TASK' : 'PATH_TO_GROUP_TASKS_TASK' => str_replace(array('#USER_ID#', '#GROUP_ID#', '#TASK_ID#'), array($USER->GetID(), $arSection['XML_ID'], $arElement['ID']), $arPaths[$arElement['taskType']]));
                 }
             } else {
                 $obErrorCode->setData('0x81020016');
                 $bUpdate = false;
             }
         }
         if ($bUpdate) {
             if ($arData['_command'] == 'Delete' && $arElement["CREATED_BY"] == $USER->GetID()) {
                 $arError = false;
                 if (!CTasks::Delete($arElement['ID'])) {
                     $obErrorCode->setData('0x81020014');
                 } else {
                     $obErrorCode->setData('0x00000000');
                 }
             } elseif ($arData['_command'] == 'New' || $arData['_command'] == 'Update') {
                 $arData['Body'] = trim($arData['Body']);
                 $arData['Body'] = str_replace(array("&#10;", "&#13;", '&nbsp;'), "", $arData['Body']);
                 $arData['Body'] = preg_replace("/<![^>]*>/", '', $arData['Body']);
                 if (($pos = strpos($arData['Body'], '<BODY>')) !== false) {
                     $arData['Body'] = substr($arData['Body'], $pos + 6);
                 }
                 echo $pos . ' ';
                 if (($pos = strpos($arData['Body'], '</BODY>')) !== false) {
                     $arData['Body'] = substr($arData['Body'], 0, $pos);
                 }
                 echo $pos . ' ';
                 $TZBias = intval(date('Z'));
                 $arData['StartDate'] = $arData['StartDate'] ? $this->__makeTS($arData['StartDate']) + $TZBias : '';
                 $arData['DueDate'] = $arData['DueDate'] ? $this->__makeTS($arData['DueDate']) + $TZBias : '';
                 $arData['MetaInfo_DateComplete'] = $arData['MetaInfo_DateComplete'] ? $this->__makeTS($arData['EndDate']) + $TZBias : '';
                 $probablyHtmlInDescription = strpos($arData['Body'], '<') !== false && strpos($arData['Body'], '>');
                 $arFields = array('DESCRIPTION_IN_BBCODE' => $probablyHtmlInDescription ? 'N' : 'Y', 'CHANGED_BY' => $USER->GetID(), 'CHANGED_DATE' => date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL")), time()), 'SITE_ID' => SITE_ID, 'TITLE' => $arData['Title'], 'START_DATE_PLAN' => $arData['StartDate'] ? ConvertTimeStamp($arData['StartDate']) : '', 'DEADLINE' => $arData['DueDate'] ? ConvertTimeStamp($arData['DueDate']) : '', 'DESCRIPTION' => $arData['Body'], 'PRIORITY' => isset($arData['Priority']) ? intval($arData['Priority']) : 1, 'DURATION_PLAN' => $arData['MetaInfo_TotalWork'] / 60, 'DURATION_FACT' => $arData['MetaInfo_ActualWork'] / 60, 'CLOSED_DATE' => $arData['MetaInfo_DateComplete'] ? ConvertTimeStamp($arData['MetaInfo_DateComplete']) : '');
                 if (in_array($arData['Status'], $this->arStatuses)) {
                     $arFields["STATUS"] = $arData['Status'];
                 }
                 if ($assigned_to = $arData['AssignedTo']) {
                     if ($USER_ID = $this->__getUser($assigned_to)) {
                         $arFields['RESPONSIBLE_ID'] = $USER_ID;
                     } else {
                         $obErrorCode->setData('0x81020054');
                         $bUpdate = false;
                     }
                 } else {
                     $arFields['RESPONSIBLE_ID'] = $USER->getId();
                 }
                 if ($bUpdate) {
                     CTimeZone::Disable();
                     $ID = 0;
                     $obTask = new CTasks();
                     $arError = false;
                     if ($arData['_command'] == 'New') {
                         if ($arFields["RESPONSIBLE_ID"] == $USER->GetID() || CTasks::IsSubordinate($arFields["RESPONSIBLE_ID"], $USER->GetID())) {
                             $arFields["STATUS"] = 2;
                         } else {
                             $arFields["STATUS"] = 1;
                         }
                         $arFields['OUTLOOK_VERSION'] = 1;
                         $arFields["CREATED_BY"] = $USER->GetID();
                         $arFields["CREATED_DATE"] = date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL")), time());
                         if ($ID = $obTask->Add($arFields)) {
                             $arReplicationIDs[$ID] = $arData['MetaInfo_ReplicationID'];
                             $obErrorCode->setData('0x00000000');
                         }
                     } else {
                         if ($arElement["CREATED_BY"] == $USER->GetID() || $arElement["RESPONSIBLE_ID"] == $USER->GetID()) {
                             if ($arElement["CREATED_BY"] != $USER->GetID()) {
                                 unset($arFields["TITLE"], $arFields["START_DATE_PLAN"], $arFields["DESCRIPTION"], $arFields["PRIORITY"], $arFields["DURATION_PLAN"], $arFields["CLOSED_DATE"]);
                                 if ($arElement["ALLOW_CHANGE_DEADLINE"] != "Y") {
                                     unset($arFields["DEADLINE"]);
                                 }
                                 if ($arElement["TASK_CONTROL"] != "Y" && $arFields["STATUS"] == 5) {
                                     $arFields["STATUS"] = 4;
                                 }
                             } elseif ($arElement["RESPONSIBLE_ID"] != $USER->GetID() && ($arFields["STATUS"] == 6 || $arFields["STATUS"] == 3)) {
                                 unset($arFields["STATUS"]);
                             }
                             $arFields['OUTLOOK_VERSION'] = $arData['owshiddenversion'];
                             if (sizeof($arFields) > 0) {
                                 if ($obTask->Update($arData['ID'], $arFields)) {
                                     $ID = $arData['ID'];
                                     $obErrorCode->setData('0x00000000');
                                 }
                             }
                         }
                     }
                     CTimeZone::Enable();
                     if (is_array($obTask->GetErrors()) && count($obTask->GetErrors()) > 0) {
                         $ID = 0;
                         $obErrorCode->setData('0x81020014');
                         $bUpdate = false;
                     } else {
                         $taskType = $arElement ? $arElement['taskType'] : 'user';
                         $ownerId = $arElement ? $arElement['ownerId'] : $USER->GetID();
                         $arParams = $arElement ? $arElement['arParams'] : array('PATH_TO_USER_TASKS_TASK' => str_replace(array('#USER_ID#', '#GROUP_ID#', '#TASK_ID#'), array($USER->GetID(), $arSection['XML_ID'], $ID), $arPaths['user']));
                     }
                 }
             }
         }
         if ($ID > 0) {
             $arResponseRows[$ID] = $obResponseRow;
         } else {
             $arResponseRowsError[] = $obResponseRow;
         }
     }
     if (sizeof($arResponseRows) > 0) {
         $dbRes = CTasks::GetList(array('ID' => 'ASC'), array('ID' => array_keys($arResponseRows), 'MEMBER' => $USER->GetID()));
         while ($arRes = $dbRes->Fetch()) {
             if ($arResponseRows[$arRes['ID']]) {
                 $rsFiles = CTaskFiles::GetList(array(), array("TASK_ID" => $arRes["ID"]));
                 $arRes["FILES"] = array();
                 while ($arFiles = $rsFiles->Fetch()) {
                     $arRes["FILES"][] = $arFiles["FILE_ID"];
                 }
                 $obRow = $this->__getRow($arRes, $listName, $last_change = 0);
                 if ($arReplicationIDs[$arRes['ID']]) {
                     $obRow->setAttribute('ows_MetaInfo_ReplicationID', $arReplicationIDs[$arRes['ID']]);
                 }
                 $obRow->setAttribute('xmlns:z', "#RowsetSchema");
                 $arResponseRows[$arRes['ID']]->addChild($obRow);
                 $obResponse->addChild($arResponseRows[$arRes['ID']]);
             }
         }
     }
     foreach ($arResponseRowsError as $obChange) {
         $obResponse->addChild($obChange);
     }
     return array('UpdateListItemsResult' => $obResponse);
 }
예제 #6
0
         $arTaskFields = array('RESPONSIBLE_ID' => $responsibleId > 0 ? $responsibleId : $USER->GetID(), 'TITLE' => strlen($arFields['TITLE']) > 0 ? $arFields['TITLE'] : $arResult['MEETING']['AGENDA'][$key]['TITLE'], 'DEADLINE' => $taskDeadline, 'TAGS' => array(), 'STATUS' => array_key_exists($arFields['RESPONSIBLE'][0], $arEmplIDs) ? 2 : 1, 'SITE_ID' => SITE_ID);
         if ($arResult['MEETING']['OWNER_ID'] && $arResult['MEETING']['OWNER_ID'] != $USER->GetID()) {
             $arTaskFields['CREATED_BY'] = $arResult['MEETING']['OWNER_ID'];
             $arTaskFields['AUDITORS'] = array($USER->GetID());
         }
         if ($_REQUEST['GROUP_ID'] > 0) {
             $arTaskFields['GROUP_ID'] = (int) $_REQUEST['GROUP_ID'];
         } elseif ($arParams['MEETING_ID'] > 0) {
             $rsTasks_rsMeetingData = CMeeting::GetList(array(), array('ID' => $arParams['MEETING_ID']));
             if ($arTasks_arMeetingData = $rsTasks_rsMeetingData->Fetch()) {
                 if ($arTasks_arMeetingData['GROUP_ID'] > 0) {
                     $arTaskFields['GROUP_ID'] = (int) $arTasks_arMeetingData['GROUP_ID'];
                 }
             }
         }
         $TASK_ID = $obt->Add($arTaskFields);
     }
     if ($TASK_ID > 0) {
         $arNewAgendaTasks[$key] = $TASK_ID;
         $arFields['TASK_ID'] = $TASK_ID;
     }
 }
 if ($bNew) {
     if (!$arFields['ITEM_ID']) {
         $arFields['ITEM_ID'] = CMeetingItem::Add($arFields, true);
         $INSTANCE_ID = CMeetingInstance::Add($arFields);
     } else {
         $INSTANCE_ID = CMeetingInstance::Add($arFields);
     }
     $arNewAgendaMap[$key] = array($INSTANCE_ID, $arFields['ITEM_ID']);
 } else {
예제 #7
0
 public function Execute()
 {
     if (!CModule::IncludeModule("tasks")) {
         return CBPActivityExecutionStatus::Closed;
     }
     $rootActivity = $this->GetRootActivity();
     $documentId = $rootActivity->GetDocumentId();
     $arFields = $this->Fields;
     $arFields["CREATED_BY"] = CBPHelper::ExtractUsers($this->Fields["CREATED_BY"], $documentId, true);
     $arFields["RESPONSIBLE_ID"] = CBPHelper::ExtractUsers($this->Fields["RESPONSIBLE_ID"], $documentId, true);
     $arFields["ACCOMPLICES"] = CBPHelper::ExtractUsers($this->Fields["ACCOMPLICES"], $documentId);
     $arFields["AUDITORS"] = CBPHelper::ExtractUsers($this->Fields["AUDITORS"], $documentId);
     if (isset($this->Fields['DESCRIPTION'])) {
         $arFields['DESCRIPTION'] = preg_replace('/\\[url=(.*)\\](.*)\\[\\/url\\]/i' . BX_UTF_PCRE_MODIFIER, '<a href="${1}">${2}</a>', $this->Fields['DESCRIPTION']);
     }
     if (!$arFields["SITE_ID"]) {
         $arFields["SITE_ID"] = SITE_ID;
     }
     if ($this->AUTO_LINK_TO_CRM_ENTITY && CModule::IncludeModule('crm')) {
         $rootActivity = $this->GetRootActivity();
         $documentId = $rootActivity->GetDocumentId();
         $documentType = $rootActivity->GetDocumentType();
         $letter = CCrmOwnerTypeAbbr::ResolveByTypeID(CCrmOwnerType::ResolveID($documentType[2]));
         $arFields['UF_CRM_TASK'] = array(str_replace($documentType[2], $letter, $documentId[2]));
     }
     $arUnsetFields = array();
     foreach ($arFields as $fieldName => $fieldValue) {
         if (substr($fieldName, -5) === '_text') {
             $arFields[substr($fieldName, 0, -5)] = $fieldValue;
             $arUnsetFields[] = $fieldName;
         }
     }
     foreach ($arUnsetFields as $fieldName) {
         unset($arFields[$fieldName]);
     }
     // Check fields for "white" list
     $arFieldsChecked = array();
     foreach (array_keys($arFields) as $fieldName) {
         if (in_array($fieldName, static::$arAllowedTasksFieldNames, true) || strlen($fieldName) > 3 && substr($fieldName, 0, 3) === 'UF_') {
             if ('UF_TASK_WEBDAV_FILES' == $fieldName && is_array($arFields[$fieldName])) {
                 foreach ($arFields[$fieldName] as $key => $fileId) {
                     if (!empty($fileId) && is_string($fileId) && substr($fileId, 0, 1) != 'n') {
                         if (CModule::IncludeModule("disk") && \Bitrix\Disk\Configuration::isSuccessfullyConverted()) {
                             $item = \Bitrix\Disk\Internals\FileTable::getList(array('select' => array('ID'), 'filter' => array('=XML_ID' => $fileId, 'TYPE' => \Bitrix\Disk\Internals\FileTable::TYPE_FILE)))->fetch();
                             if ($item) {
                                 $arFields[$fieldName][$key] = 'n' . $item['ID'];
                             }
                         }
                     }
                 }
                 unset($fileId);
             }
             $arFieldsChecked[$fieldName] = $arFields[$fieldName];
         }
     }
     $task = new CTasks();
     $result = $task->Add($arFieldsChecked, array('USER_ID' => 1));
     if (!$result) {
         $arErrors = $task->GetErrors();
         if (count($arErrors) > 0) {
             $errorDesc = array();
             if (is_array($arErrors) && !empty($arErrors)) {
                 foreach ($arErrors as $error) {
                     $errorDesc[] = $error['text'] . ' (' . $error['id'] . ')';
                 }
             }
             $this->WriteToTrackingService(GetMessage("BPSA_TRACK_ERROR") . (!empty($errorDesc) ? ' ' . implode(', ', $errorDesc) : ''));
         }
         return CBPActivityExecutionStatus::Closed;
     }
     $this->TaskId = $result;
     $this->WriteToTrackingService(str_replace("#VAL#", $result, GetMessage("BPSA_TRACK_OK")));
     if ($this->isInEventActivityMode || !$this->HoldToClose) {
         return CBPActivityExecutionStatus::Closed;
     }
     $this->Subscribe($this);
     $this->isInEventActivityMode = false;
     $this->WriteToTrackingService(GetMessage("BPSA_TRACK_SUBSCR"));
     return CBPActivityExecutionStatus::Executing;
 }
예제 #8
0
                $strSql = "SELECT * FROM b_tasks WHERE XML_ID = '" . $newTask["XML_ID"] . "'";
                $rsTask = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
                if ($arTask = $rsTask->Fetch()) {
                    $updateID = $arTask["ID"];
                }
            } else {
                $strSql = "SELECT * FROM b_tasks WHERE CREATED_BY = '" . $newTask["CREATED_BY"] . "' AND CREATED_DATE = '" . $newTask["CREATED_DATE"] . "'";
                $rsTask = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
                while ($arTask = $rsTask->Fetch()) {
                    $updateID = $arTask["ID"];
                }
            }
            if ($updateID) {
                $oTask->Update($updateID, $newTask);
            } else {
                $oTask->Add($newTask);
            }
            if (sizeof($oTask->GetErrors()) == 0) {
                $CNT++;
            }
            if (microtime(true) - $start_time > 1) {
                header("Location: ?ID=" . $ID . "&CNT=" . $CNT . "&IBN=" . $i);
            }
        }
        $ID = 0;
    }
    require $_SERVER["DOCUMENT_ROOT"] . BX_ROOT . "/modules/main/include/prolog_admin_after.php";
    COption::SetOptionString("intranet", "use_tasks_2_0", "Y");
    CAdminMessage::ShowNote(str_replace("#TASKS_NUM#", $CNT, GetMessage("TASKS_ADDED")));
    echo "<form action=\"/bitrix/admin/module_admin.php\"><input type=\"hidden\" name=\"lang\" value=\"" . LANG . "\" /><input type=\"submit\" value=\"" . GetMessage("MOD_BACK") . "\" />";
}
예제 #9
0
 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;
 }
예제 #10
0
        $arNewTaskFields['CREATED_BY'] = (int) $GLOBALS['USER']->GetID();
        if ($USER->IsAdmin() || CTasksTools::IsPortalB24Admin()) {
            $arNewTaskFields['CREATED_BY'] = (int) $_POST['CREATED_BY'];
        }
        $rc = $oTask->Update($arNewTaskFields['ID'], $arNewTaskFields);
    } else {
        $arNewTaskFields['MULTITASK'] = 'N';
        $arNewTaskFields['CREATED_BY'] = (int) $GLOBALS['USER']->GetID();
        $arNewTaskFields['DESCRIPTION_IN_BBCODE'] = 'Y';
        // Only creator or priveleged user can set responsible person.
        $arNewTaskFields['RESPONSIBLE_ID'] = (int) $GLOBALS['USER']->GetID();
        if ($arNewTaskFields['CREATED_BY'] === $arParams['USER_ID'] || $USER->IsAdmin() || CTasksTools::IsPortalB24Admin()) {
            $arNewTaskFields['RESPONSIBLE_ID'] = (int) $_POST['RESPONSIBLE_ID'];
        }
        $arNewTaskFields['SITE_ID'] = SITE_ID;
        $rc = $oTask->Add($arNewTaskFields);
        if ($rc > 0) {
            $arNewTaskFields['ID'] = $rc;
        } else {
            $bErrorOccuredOnTaskCreation = true;
        }
    }
    unset($oTask);
    // Redirect to view details of this task
    if ($arNewTaskFields['ID'] > 0) {
        LocalRedirect(str_replace(array('#task_id#', '#TASK_ID#'), $arNewTaskFields['ID'], $arParams['PATH_TO_TASKS_TASK']));
    }
    exit;
}
// Edit existing task?
if ($arParams['TASK_ID'] > 0) {
예제 #11
0
 public function TaskActions($arActions, $site_id = SITE_ID)
 {
     if ($last_entry = $this->_GetLastData()) {
         $this->SITE_ID = $site_id;
         $arTasks = $last_entry['TASKS'];
         if (!is_array($arTasks)) {
             $arTasks = array();
         }
         if (strlen($arActions['name']) > 0) {
             $obt = new CTasks();
             if ($ID = $obt->Add(array('RESPONSIBLE_ID' => $this->USER_ID, 'TITLE' => $arActions['name'], 'TAGS' => array(), 'STATUS' => 2, 'SITE_ID' => $this->SITE_ID))) {
                 if (!is_array($arActions['add'])) {
                     $arActions['add'] = array($ID);
                 } else {
                     $arActions['add'][] = $ID;
                 }
             }
         }
         if (is_array($arActions['add'])) {
             foreach ($arActions['add'] as $task_id) {
                 $arTasks[] = intval($task_id);
             }
             $GLOBALS['BX_TIMEMAN_RECENTLY_ADDED_TASK_ID'] = $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 (false !== ($key = array_search($task_id, $arTasks))) {
                     unset($arTasks[$key]);
                 }
             }
         }
         $arFields = array('TASKS' => array());
         if (count($arTasks) > 0) {
             $arCheck = $this->GetTasks($arTasks);
             foreach ($arCheck as $a) {
                 $arFields['TASKS'][] = $a['ID'];
             }
         }
         if (CTimeManEntry::Update($last_entry['ID'], $arFields)) {
             return $this->_GetLastData(true);
         }
     }
     return false;
 }