Esempio n. 1
0
 function CheckFields(&$arFields, $ID = false, $effectiveUserId = null)
 {
     global $APPLICATION, $USER;
     if ($effectiveUserId === null) {
         $effectiveUserId = is_object($USER) ? intval($USER->GetID()) : 1;
     }
     if ((is_set($arFields, "TITLE") || $ID === false) && strlen($arFields["TITLE"]) <= 0) {
         $this->_errors[] = array("text" => GetMessage("TASKS_BAD_TITLE"), "id" => "ERROR_BAD_TASKS_TITLE");
     }
     // you are not allowed to clear up END_DATE_PLAN while the task is linked
     if ($ID && (isset($arFields['END_DATE_PLAN']) && (string) $arFields['END_DATE_PLAN'] == '')) {
         if (DependenceTable::checkItemLinked($ID)) {
             $this->_errors[] = array("text" => GetMessage("TASKS_IS_LINKED_END_DATE_PLAN_REMOVE"), "id" => "ERROR_TASKS_IS_LINKED");
         }
     }
     if ($ID && (isset($arFields['PARENT_ID']) && intval($arFields['PARENT_ID']) > 0)) {
         if (DependenceTable::checkLinkExists($ID, $arFields['PARENT_ID'], array('BIDIRECTIONAL' => true))) {
             $this->_errors[] = array("text" => GetMessage("TASKS_IS_LINKED_SET_PARENT"), "id" => "ERROR_TASKS_IS_LINKED");
         }
     }
     // If plan dates were set
     if (isset($arFields['START_DATE_PLAN']) && isset($arFields['END_DATE_PLAN']) && $arFields['START_DATE_PLAN'] != '' && $arFields['END_DATE_PLAN'] != '') {
         $startDate = MakeTimeStamp($arFields['START_DATE_PLAN']);
         $endDate = MakeTimeStamp($arFields['END_DATE_PLAN']);
         // and they were really set
         if ($startDate > 0 && $endDate > 0) {
             // and end date is before start date => then emit error
             if ($endDate < $startDate) {
                 $this->_errors[] = array('text' => GetMessage('TASKS_BAD_PLAN_DATES'), 'id' => 'ERROR_BAD_TASKS_PLAN_DATES');
             }
         }
     }
     if ($ID === false && !is_set($arFields, "RESPONSIBLE_ID")) {
         $this->_errors[] = array("text" => GetMessage("TASKS_BAD_RESPONSIBLE_ID"), "id" => "ERROR_TASKS_BAD_RESPONSIBLE_ID");
     }
     if ($ID === false && !is_set($arFields, "CREATED_BY")) {
         $this->_errors[] = array("text" => GetMessage("TASKS_BAD_CREATED_BY"), "id" => "ERROR_TASKS_BAD_CREATED_BY");
     }
     if (is_set($arFields, "CREATED_BY")) {
         if (!($arFields['CREATED_BY'] >= 1)) {
             $this->_errors[] = array("text" => GetMessage("TASKS_BAD_CREATED_BY"), "id" => "ERROR_TASKS_BAD_CREATED_BY");
         }
     }
     if (is_set($arFields, "RESPONSIBLE_ID")) {
         $r = CUser::GetByID($arFields["RESPONSIBLE_ID"]);
         if ($arUser = $r->Fetch()) {
             if ($ID) {
                 $rsTask = CTasks::GetList(array(), array("ID" => $ID), array("RESPONSIBLE_ID"), array('USER_ID' => $effectiveUserId));
                 if ($arTask = $rsTask->Fetch()) {
                     $currentResponsible = $arTask["RESPONSIBLE_ID"];
                 }
             }
             if (!$ID || isset($currentResponsible) && $currentResponsible != $arFields["RESPONSIBLE_ID"]) {
                 $createdBy = $arFields["CREATED_BY"];
                 $arSubDeps = CTasks::GetSubordinateDeps($createdBy);
                 if (!is_array($arUser["UF_DEPARTMENT"])) {
                     $bSubordinate = sizeof(array_intersect($arSubDeps, array($arUser["UF_DEPARTMENT"]))) > 0;
                 } else {
                     $bSubordinate = sizeof(array_intersect($arSubDeps, $arUser["UF_DEPARTMENT"])) > 0;
                 }
                 if (!$arFields["STATUS"]) {
                     $arFields["STATUS"] = self::STATE_PENDING;
                 }
                 if (!$bSubordinate) {
                     $arFields["ADD_IN_REPORT"] = "N";
                 }
                 $arFields["DECLINE_REASON"] = false;
             }
         } else {
             $this->_errors[] = array("text" => GetMessage("TASKS_BAD_RESPONSIBLE_ID_EX"), "id" => "ERROR_TASKS_BAD_RESPONSIBLE_ID_EX");
         }
     }
     if (is_set($arFields, "PARENT_ID") && intval($arFields["PARENT_ID"]) > 0) {
         $r = CTasks::GetByID($arFields["PARENT_ID"], true, array('USER_ID' => $effectiveUserId));
         if (!$r->Fetch()) {
             $this->_errors[] = array("text" => GetMessage("TASKS_BAD_PARENT_ID"), "id" => "ERROR_TASKS_BAD_PARENT_ID");
         }
     }
     if ($ID !== false && $ID == $arFields["PARENT_ID"]) {
         $this->_errors[] = array("text" => GetMessage("TASKS_PARENT_SELF"), "id" => "ERROR_TASKS_PARENT_SELF");
     }
     if ($ID !== false && is_array($arFields["DEPENDS_ON"]) && in_array($ID, $arFields["DEPENDS_ON"])) {
         $this->_errors[] = array("text" => GetMessage("TASKS_DEPENDS_ON_SELF"), "id" => "ERROR_TASKS_DEPENDS_ON_SELF");
     }
     /*
     if(!$ID)
     {
     	// since this time we dont allow to create tasks with a non-bbcode description
     	if($arFields['DESCRIPTION_IN_BBCODE'] == 'N')
     	{
     		$this->_errors[] = array("text" => GetMessage("TASKS_DESCRIPTION_IN_BBCODE_NO_NOT_ALLOWED"), "id" => "ERROR_TASKS_DESCRIPTION_IN_BBCODE_NO_NOT_ALLOWED");
     	}
     	else
     	{
     		$arFields['DESCRIPTION_IN_BBCODE'] = 'Y';
     	}
     }
     */
     if (!empty($this->_errors)) {
         $e = new CAdminException($this->_errors);
         $APPLICATION->ThrowException($e);
         return false;
     }
     //Defaults
     if (is_set($arFields, 'PRIORITY')) {
         if (!in_array((string) $arFields['PRIORITY'], array((string) self::PRIORITY_LOW, (string) self::PRIORITY_AVERAGE, (string) self::PRIORITY_HIGH), true)) {
             $arFields['PRIORITY'] = self::PRIORITY_AVERAGE;
         }
         $arFields['PRIORITY'] = (int) $arFields['PRIORITY'];
     }
     // flags
     self::checkBooleanParameter($arFields, 'ALLOW_CHANGE_DEADLINE');
     self::checkBooleanParameter($arFields, 'TASK_CONTROL');
     self::checkBooleanParameter($arFields, 'ADD_IN_REPORT');
     self::checkBooleanParameter($arFields, 'MATCH_WORK_TIME');
     self::checkBooleanParameter($arFields, 'REPLICATE');
     return true;
 }