Example #1
0
 /**
  * @param FieldType $fieldType
  * @param array $field
  * @param array $request
  * @return null|int
  */
 protected static function extractValue(FieldType $fieldType, array $field, array $request)
 {
     $value = parent::extractValue($fieldType, $field, $request);
     if (is_array($value) && !empty($value['name']) && !empty($value['tmp_name'])) {
         if (!is_uploaded_file($value['tmp_name'])) {
             $value = null;
             static::addError(array('code' => 'ErrorValue', 'message' => Loc::getMessage('BPDT_FILE_SECURITY_ERROR'), 'parameter' => static::generateControlName($field)));
         } else {
             if (!array_key_exists('MODULE_ID', $value) || strlen($value['MODULE_ID']) <= 0) {
                 $value['MODULE_ID'] = 'bizproc';
             }
             $value = \CFile::saveFile($value, 'bizproc_wf', true, true);
             if (!$value) {
                 $value = null;
                 static::addError(array('code' => 'ErrorValue', 'message' => Loc::getMessage('BPDT_FILE_INVALID'), 'parameter' => static::generateControlName($field)));
             }
         }
     } else {
         $value = null;
     }
     return $value;
 }
Example #2
0
 public function GetFieldInputValue($documentType, $fieldType, $fieldName, $request, &$errors)
 {
     $iblockId = intval(substr($documentType, strlen("iblock_")));
     if ($iblockId <= 0) {
         throw new CBPArgumentOutOfRangeException("documentType", $documentType);
     }
     $result = array();
     if ($fieldType["Type"] == "user") {
         $value = $request[$fieldName["Field"]];
         if (strlen($value) > 0) {
             $result = CBPHelper::usersStringToArray($value, array("lists", get_called_class(), $documentType), $errors);
             if (count($errors) > 0) {
                 foreach ($errors as $e) {
                     $errors[] = $e;
                 }
             }
         } else {
             $result = null;
         }
     } elseif (array_key_exists($fieldName["Field"], $request) || array_key_exists($fieldName["Field"] . "_text", $request)) {
         $valueArray = array();
         if (array_key_exists($fieldName["Field"], $request)) {
             $valueArray = $request[$fieldName["Field"]];
             if (!is_array($valueArray) || is_array($valueArray) && CBPHelper::isAssociativeArray($valueArray)) {
                 $valueArray = array($valueArray);
             }
         }
         if (array_key_exists($fieldName["Field"] . "_text", $request)) {
             $valueArray[] = $request[$fieldName["Field"] . "_text"];
         }
         foreach ($valueArray as $value) {
             if (is_array($value) || !is_array($value) && !\CBPDocument::IsExpression(trim($value))) {
                 if ($fieldType["Type"] == "int") {
                     if (strlen($value) > 0) {
                         $value = str_replace(" ", "", $value);
                         if ($value . "|" == intval($value) . "|") {
                             $value = intval($value);
                         } else {
                             $value = null;
                             $errors[] = array("code" => "ErrorValue", "message" => GetMessage("LISTS_BIZPROC_INVALID_INT"), "parameter" => $fieldName["Field"]);
                         }
                     } else {
                         $value = null;
                     }
                 } elseif ($fieldType["Type"] == "double") {
                     if (strlen($value) > 0) {
                         $value = str_replace(" ", "", str_replace(",", ".", $value));
                         if (is_numeric($value)) {
                             $value = doubleval($value);
                         } else {
                             $value = null;
                             $errors[] = array("code" => "ErrorValue", "message" => GetMessage("LISTS_BIZPROC_INVALID_INT"), "parameter" => $fieldName["Field"]);
                         }
                     } else {
                         $value = null;
                     }
                 } elseif ($fieldType["Type"] == "select") {
                     if (!is_array($fieldType["Options"]) || count($fieldType["Options"]) <= 0 || strlen($value) <= 0) {
                         $value = null;
                     } else {
                         $ar = array_values($fieldType["Options"]);
                         if (is_array($ar[0])) {
                             $b = false;
                             foreach ($ar as $a) {
                                 if ($a[0] == $value) {
                                     $b = true;
                                     break;
                                 }
                             }
                             if (!$b) {
                                 $value = null;
                                 $errors[] = array("code" => "ErrorValue", "message" => GetMessage("LISTS_BIZPROC_INVALID_SELECT"), "parameter" => $fieldName["Field"]);
                             }
                         } else {
                             if (!array_key_exists($value, $fieldType["Options"])) {
                                 $value = null;
                                 $errors[] = array("code" => "ErrorValue", "message" => GetMessage("LISTS_BIZPROC_INVALID_SELECT"), "parameter" => $fieldName["Field"]);
                             }
                         }
                     }
                 } elseif ($fieldType["Type"] == "bool") {
                     if ($value !== "Y" && $value !== "N") {
                         if ($value === true) {
                             $value = "Y";
                         } elseif ($value === false) {
                             $value = "N";
                         } elseif (strlen($value) > 0) {
                             $value = strtolower($value);
                             if (in_array($value, array("y", "yes", "true", "1"))) {
                                 $value = "Y";
                             } elseif (in_array($value, array("n", "no", "false", "0"))) {
                                 $value = "N";
                             } else {
                                 $value = null;
                                 $errors[] = array("code" => "ErrorValue", "message" => GetMessage("BPCGWTL_INVALID45"), "parameter" => $fieldName["Field"]);
                             }
                         } else {
                             $value = null;
                         }
                     }
                 } elseif ($fieldType["Type"] == "file") {
                     if (is_array($value) && array_key_exists("name", $value) && strlen($value["name"]) > 0) {
                         if (!array_key_exists("MODULE_ID", $value) || strlen($value["MODULE_ID"]) <= 0) {
                             $value["MODULE_ID"] = "bizproc";
                         }
                         $value = CFile::saveFile($value, "bizproc_wf", true, true);
                         if (!$value) {
                             $value = null;
                             $errors[] = array("code" => "ErrorValue", "message" => GetMessage("BPCGWTL_INVALID915"), "parameter" => $fieldName["Field"]);
                         }
                     } else {
                         $value = null;
                     }
                 } elseif ($fieldType["Type"] == "date") {
                     if (strlen($value) > 0) {
                         if (!CheckDateTime($value, FORMAT_DATE)) {
                             $value = null;
                             $errors[] = array("code" => "ErrorValue", "message" => GetMessage("LISTS_BIZPROC_INVALID_DATE"), "parameter" => $fieldName["Field"]);
                         }
                     } else {
                         $value = null;
                     }
                 } elseif ($fieldType["Type"] == "datetime") {
                     if (strlen($value) > 0) {
                         $valueTemporary = array();
                         $valueTemporary["VALUE"] = $value;
                         $result = CIBlockPropertyDateTime::checkFields('', $valueTemporary);
                         if (!empty($result)) {
                             $message = '';
                             foreach ($result as $error) {
                                 $message .= $error;
                             }
                             $value = null;
                             $errors[] = array("code" => "ErrorValue", "message" => $message, "parameter" => $fieldName["Field"]);
                         }
                     } else {
                         $value = null;
                     }
                 } elseif (strpos($fieldType["Type"], ":") !== false && $fieldType["Type"] != "S:HTML") {
                     $customType = CIBlockProperty::getUserType(substr($fieldType["Type"], 2));
                     if (array_key_exists("GetLength", $customType)) {
                         if (call_user_func_array($customType["GetLength"], array(array("LINK_IBLOCK_ID" => $fieldType["Options"]), array("VALUE" => $value))) <= 0) {
                             $value = null;
                         }
                     }
                     if ($value != null && array_key_exists("CheckFields", $customType)) {
                         $errorsTemporary = call_user_func_array($customType["CheckFields"], array(array("LINK_IBLOCK_ID" => $fieldType["Options"]), array("VALUE" => $value)));
                         if (count($errorsTemporary) > 0) {
                             $value = null;
                             foreach ($errorsTemporary as $e) {
                                 $errors[] = array("code" => "ErrorValue", "message" => $e, "parameter" => $fieldName["Field"]);
                             }
                         }
                     } elseif (!array_key_exists("GetLength", $customType) && $value === '') {
                         $value = null;
                     }
                     if ($value !== null && $fieldType["Type"] == "S:employee" && COption::getOptionString("bizproc", "employee_compatible_mode", "N") != "Y") {
                         $value = "user_" . $value;
                     }
                 } else {
                     if (!is_array($value) && strlen($value) <= 0) {
                         $value = null;
                     }
                 }
             }
             if ($value !== null) {
                 $result[] = $value;
             }
         }
     }
     if (!$fieldType["Multiple"]) {
         if (is_array($result) && count($result) > 0) {
             $result = $result[0];
         } else {
             $result = null;
         }
     }
     return $result;
 }
 protected function processActionCommit()
 {
     $this->checkRequiredPostParams(array('editSessionId'));
     if ($this->errorCollection->hasErrors()) {
         $this->sendJsonErrorResponse();
     }
     $this->checkUpdatePermissions();
     $currentSession = $this->getEditSessionByCurrentUser((int) $this->request->getPost('editSessionId'));
     if (!$currentSession) {
         $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_DOC_CONTROLLER_ERROR_COULD_NOT_FIND_EDIT_SESSION'), self::ERROR_COULD_NOT_FIND_EDIT_SESSION)));
         $this->sendJsonErrorResponse();
     }
     $tmpFile = \CTempFile::getFileName(uniqid('_wd'));
     checkDirPath($tmpFile);
     $fileData = new FileData();
     $fileData->setId($currentSession->getServiceFileId());
     $fileData->setSrc($tmpFile);
     $newNameFileAfterConvert = null;
     if ($this->documentHandler->isNeedConvertExtension($this->file->getExtension())) {
         $newNameFileAfterConvert = getFileNameWithoutExtension($this->file->getName()) . '.' . $this->documentHandler->getConvertExtension($this->file->getExtension());
         $fileData->setMimeType(TypeFile::getMimeTypeByFilename($newNameFileAfterConvert));
     } else {
         $fileData->setMimeType(TypeFile::getMimeTypeByFilename($this->file->getName()));
     }
     $fileData = $this->documentHandler->downloadFile($fileData);
     if (!$fileData) {
         if ($this->documentHandler->isRequiredAuthorization()) {
             $this->sendNeedAuth();
         }
         $this->errorCollection->add($this->documentHandler->getErrors());
         $this->sendJsonErrorResponse();
     }
     $this->deleteEditSession($currentSession);
     $oldName = $this->file->getName();
     //rename in cloud service
     $renameInCloud = $fileData->getName() && $fileData->getName() != $this->file->getName();
     if ($newNameFileAfterConvert || $renameInCloud) {
         if ($newNameFileAfterConvert && $renameInCloud) {
             $newNameFileAfterConvert = getFileNameWithoutExtension($fileData->getName()) . '.' . getFileExtension($newNameFileAfterConvert);
         }
         $this->file->rename($newNameFileAfterConvert);
     }
     $fileArray = \CFile::makeFileArray($tmpFile);
     $fileArray['name'] = $this->file->getName();
     $fileArray['type'] = $fileData->getMimeType();
     $fileArray['MODULE_ID'] = Driver::INTERNAL_MODULE_ID;
     /** @noinspection PhpDynamicAsStaticMethodCallInspection */
     $fileId = \CFile::saveFile($fileArray, Driver::INTERNAL_MODULE_ID);
     if (!$fileId) {
         \CFile::delete($fileId);
         $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_DOC_CONTROLLER_ERROR_COULD_NOT_SAVE_FILE'), self::ERROR_COULD_NOT_SAVE_FILE)));
         $this->sendJsonErrorResponse();
     }
     $versionModel = $this->file->addVersion(array('ID' => $fileId, 'FILE_SIZE' => $fileArray['size']), $this->getUser()->getId(), true);
     if (!$versionModel) {
         \CFile::delete($fileId);
         $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_DOC_CONTROLLER_ERROR_COULD_NOT_ADD_VERSION'), self::ERROR_COULD_NOT_ADD_VERSION)));
         $this->errorCollection->add($this->file->getErrors());
         $this->sendJsonErrorResponse();
     }
     if ($this->isLastEditSessionForFile()) {
         $this->deleteFile($currentSession, $fileData);
     }
     $this->sendJsonSuccessResponse(array('objectId' => $this->file->getId(), 'newName' => $this->file->getName(), 'oldName' => $oldName));
 }
Example #4
0
 public static function UploadAvatar($hash, &$file, &$package, &$upload, &$error)
 {
     $post = \Bitrix\Main\Context::getCurrent()->getRequest()->getPostList()->toArray();
     $chatId = intval($post['CHAT_ID']);
     if ($chatId <= 0) {
         return false;
     }
     $chat = IM\ChatTable::getById($chatId)->fetch();
     if (!$chat) {
         return false;
     }
     $relationError = true;
     $chatRelation = CIMChat::GetRelationById($chatId);
     foreach ($chatRelation as $relation) {
         if ($relation['USER_ID'] == self::GetUserId()) {
             $relationError = false;
             break;
         }
     }
     if ($relationError) {
         $error = GetMessage('IM_DISK_ERR_AVATAR_1');
         return false;
     }
     $fileId = CFile::saveFile($file["files"]["default"], self::MODULE_ID);
     if ($fileId > 0) {
         if ($chat['AVATAR'] > 0) {
             CFile::DeLete($chat['AVATAR']);
         }
         IM\ChatTable::update($chatId, array('AVATAR' => $fileId));
         $file['chatId'] = $chatId;
         $file['chatAvatar'] = CIMChat::GetAvatarImage($fileId);
         if ($chat["ENTITY_TYPE"] != 'CALL') {
             CIMChat::AddSystemMessage(array('CHAT_ID' => $chatId, 'USER_ID' => self::GetUserId(), 'MESSAGE_CODE' => 'IM_DISK_AVATAR_CHANGE_'));
         }
         if (CModule::IncludeModule('pull')) {
             $pullMessage = array('module_id' => 'im', 'command' => 'chatAvatar', 'params' => array('chatId' => $chatId, 'chatAvatar' => $file['chatAvatar']));
             CPullStack::AddByUsers(array_keys($chatRelation), $pullMessage);
             $orm = \Bitrix\Im\ChatTable::getById($chatId);
             $chat = $orm->fetch();
             if ($chat['TYPE'] == IM_MESSAGE_OPEN) {
                 CPullWatch::AddToStack('IM_PUBLIC_' . $chat['ID'], $pullMessage);
             }
         }
     } else {
         return false;
     }
     return true;
 }
Example #5
0
 /**
  * @param         $name
  * @param         $targetElementId
  * @param TmpFile $tmpFile
  * @param array   $data
  * @return array|bool
  * @throws AccessDeniedException
  */
 public function updateFile($name, $targetElementId, TmpFile $tmpFile, array $data = array())
 {
     /** @var File $file */
     $file = File::loadById($targetElementId);
     if (!$file) {
         $this->errorCollection->add(array(new Error("Could not " . __METHOD__ . " by id {$targetElementId}", 11154)));
         $tmpFile->delete();
         return false;
     }
     if (!$file->canUpdate($this->storage->getCurrentUserSecurityContext())) {
         $tmpFile->delete();
         throw new AccessDeniedException();
     }
     /** @var array $fileArray */
     if ($tmpFile->isCloud() && $tmpFile->getContentType()) {
         /** @noinspection PhpDynamicAsStaticMethodCallInspection */
         $fileId = \CFile::saveFile(array('name' => $tmpFile->getFilename(), 'tmp_name' => $tmpFile->getAbsolutePath(), 'type' => $tmpFile->getContentType()), Driver::INTERNAL_MODULE_ID, true, true);
         /** @noinspection PhpDynamicAsStaticMethodCallInspection */
         $fileArray = \CFile::getFileArray($fileId);
         if (!$fileArray) {
             $this->errorCollection->add(array(new Error("Could not " . __METHOD__ . " getFileArray", 1115541)));
             $tmpFile->delete();
             return false;
         }
         if (!empty($data['originalTimestamp'])) {
             $fileArray['UPDATE_TIME'] = DateTime::createFromTimestamp($this->convertFromExternalVersion($data['originalTimestamp']));
         }
         if ($file->addVersion($fileArray, $this->getUser()->getId())) {
             $tmpFile->delete();
             $this->loadFormattedFolderTreeAndBreadcrumbs();
             return $this->formatFileToResponse($file);
         } else {
             \CFile::delete($fileId);
         }
     } else {
         $fileArray = \CFile::makeFileArray($tmpFile->getAbsolutePath());
         if (!$fileArray) {
             $this->errorCollection->add(array(new Error("Could not " . __METHOD__ . " MakeFileArray", 11155)));
             $tmpFile->delete();
             return false;
         }
         if (!empty($data['originalTimestamp'])) {
             $fileArray['UPDATE_TIME'] = DateTime::createFromTimestamp($this->convertFromExternalVersion($data['originalTimestamp']));
         }
         if ($file->uploadVersion($fileArray, $this->getUser()->getId())) {
             $tmpFile->delete();
             $this->loadFormattedFolderTreeAndBreadcrumbs();
             return $this->formatFileToResponse($file);
         }
     }
     $this->errorCollection->add(array(new Error("Could not " . __METHOD__ . ", uploadVersion", 11156)));
     $this->errorCollection->add($file->getErrors());
     $tmpFile->delete();
     return false;
 }
Example #6
0
 function AddAttachment($arFields)
 {
     global $DB;
     $strSql = "SELECT ATTACHMENTS FROM b_mail_message WHERE ID=" . IntVal($arFields["MESSAGE_ID"]);
     $dbr = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
     if (!($dbr_arr = $dbr->Fetch())) {
         return false;
     }
     $n = IntVal($dbr_arr["ATTACHMENTS"]) + 1;
     if (strlen($arFields["FILE_NAME"]) <= 0) {
         $arFields["FILE_NAME"] = $n . ".";
         if (strpos($arFields["CONTENT_TYPE"], "message/") === 0) {
             $arFields["FILE_NAME"] .= "msg";
         } else {
             $arFields["FILE_NAME"] .= "tmp";
         }
     }
     if (is_set($arFields, "CONTENT_TYPE")) {
         $arFields["CONTENT_TYPE"] = strtolower($arFields["CONTENT_TYPE"]);
     }
     if (strpos($arFields["CONTENT_TYPE"], "image/") === 0 && (!is_set($arFields, "IMAGE_WIDTH") || !is_set($arFields, "IMAGE_HEIGHT")) && is_set($arFields, "FILE_DATA")) {
         $filename = CTempFile::GetFileName(md5(uniqid("")) . '.tmp');
         CheckDirPath($filename);
         if (file_put_contents($filename, $arFields["FILE_DATA"]) !== false) {
             $img_arr = CFile::GetImageSize($filename);
             $arFields["IMAGE_WIDTH"] = $img_arr ? $img_arr[0] : 0;
             $arFields["IMAGE_HEIGHT"] = $img_arr ? $img_arr[1] : 0;
         }
     }
     if (is_set($arFields, "FILE_DATA") && !is_set($arFields, "FILE_SIZE")) {
         $arFields["FILE_SIZE"] = CUtil::BinStrlen($arFields["FILE_DATA"]);
     }
     $file = array('name' => md5($arFields['FILE_NAME']), 'size' => $arFields['FILE_SIZE'], 'type' => $arFields['CONTENT_TYPE'], 'content' => $arFields['FILE_DATA'], 'MODULE_ID' => 'mail');
     if (!($file_id = CFile::saveFile($file, 'mail/attachment'))) {
         return false;
     }
     unset($arFields['FILE_DATA']);
     $arFields['FILE_ID'] = $file_id;
     $ID = $DB->add('b_mail_msg_attachment', $arFields);
     if ($ID > 0) {
         $strSql = 'UPDATE b_mail_message SET ATTACHMENTS = ' . $n . ' WHERE ID = ' . intval($arFields['MESSAGE_ID']);
         $DB->query($strSql, false, 'File: ' . __FILE__ . '<br>Line: ' . __LINE__);
     }
     return $ID;
 }