/** * @param array $fileData * @param string $siteID * @param array $params * @return int|false */ public static function saveFile(array $fileData, $storageTypeID = 0, $siteID = '', $params = array()) { if (!is_integer($storageTypeID)) { $storageTypeID = (int) $storageTypeID; } if (!StorageType::isDefined($storageTypeID)) { $storageTypeID = StorageType::getDefaultTypeID(); } if ($storageTypeID === StorageType::Disk) { return DiskManager::saveFile($fileData, $siteID, $params); } elseif ($storageTypeID === StorageType::WebDav) { return \CCrmWebDavHelper::saveFile($fileData, $siteID, $params); } throw new Main\NotSupportedException("Storage type: '{$storageTypeID}' is not supported in current context"); }
public static function SetDefaultStorageTypeID($storageTypeID) { $storageTypeID = (int) $storageTypeID; if (!StorageType::isDefined($storageTypeID)) { $storageTypeID = StorageType::getDefaultTypeID(); } if ($storageTypeID === self::$STORAGE_TYPE_ID) { return; } self::$STORAGE_TYPE_ID = $storageTypeID; CUserOptions::SetOption('crm', 'activity_storage_type_id', $storageTypeID); }
die; } elseif (is_dir($actionFilePath)) { $actionFilePath = $actionFilePath . '/payment.php'; if (!file_exists($actionFilePath)) { echo CUtil::PhpToJSObject(array('ERROR' => 'COULD NOT FIND PAYMENT SYSTEM ACTION FILE!')); die; } } CSalePaySystemAction::InitParamArrays($paymentData['ORDER'], 0, $paySysActionFields['PARAMS'], array("PROPERTIES" => $paymentData['PROPERTIES'], "BASKET_ITEMS" => $paymentData['CART_ITEMS'], "TAX_LIST" => $paymentData["TAX_LIST"])); $pdfContent = (include $actionFilePath); $fileName = "quote_{$quoteID}.pdf"; $fileData = array('name' => $fileName, 'type' => 'file', 'content' => $pdfContent, 'MODULE_ID' => 'crm'); $fileID = CFile::SaveFile($fileData, 'crm'); if ($fileID > 0) { $fileArray = CFile::GetFileArray($fileID); $storageTypeID = \Bitrix\Crm\Integration\StorageType::getDefaultTypeID(); if ($storageTypeID !== \Bitrix\Crm\Integration\StorageType::File) { $storageFileID = \Bitrix\Crm\Integration\StorageManager::saveEmailAttachment($fileArray, $storageTypeID); $fileInfo = $storageFileID > 0 ? \Bitrix\Crm\Integration\StorageManager::getFileInfo($storageFileID, $storageTypeID) : null; if (is_array($fileInfo)) { if ($storageTypeID === \Bitrix\Crm\Integration\StorageType::WebDav) { echo CUtil::PhpToJSObject(array('webdavelement' => $fileInfo)); } elseif ($storageTypeID === \Bitrix\Crm\Integration\StorageType::Disk) { echo CUtil::PhpToJSObject(array('diskfile' => $fileInfo)); } } } else { echo CUtil::PhpToJSObject(array('file' => array("fileName" => $fileArray['FILE_NAME'], "fileID" => $fileID, "fileSize" => CFile::FormatSize($fileArray['FILE_SIZE']), "src" => $fileArray['SRC']))); } } die;
public static function GetDefaultStorageTypeID() { if (self::$STORAGE_TYPE_ID === StorageType::Undefined) { self::$STORAGE_TYPE_ID = intval(CUserOptions::GetOption('crm', 'quote_storage_type_id', StorageType::Undefined)); if (self::$STORAGE_TYPE_ID === StorageType::Undefined || !StorageType::isDefined(self::$STORAGE_TYPE_ID)) { self::$STORAGE_TYPE_ID = StorageType::getDefaultTypeID(); } } return self::$STORAGE_TYPE_ID; }
$actionFilePath = "{$actionPath}/payment.php"; if (!(is_dir($actionPath) && file_exists($actionFilePath))) { __CrmMobileInvoiceEditEndResonse(array('ERROR' => GetMessage('CRM_INVOICE_COULD_NOT_FIND_PAY_SYSTEM_HANDLER'))); } //HACK: params for pdf handler $_REQUEST['pdf'] = 'Y'; $_REQUEST['GET_CONTENT'] = 'Y'; $content = (include $actionFilePath); if ($content === '') { __CrmMobileInvoiceEditEndResonse(array('ERROR' => GetMessage('CRM_INVOICE_NO_PDF_CONTENT'))); } $accountNumber = isset($order['ACCOUNT_NUMBER']) ? $order['ACCOUNT_NUMBER'] : ''; if ($accountNumber !== '') { $accountNumber = preg_replace('/[^a-zA-Z0-9_-]/', '', $accountNumber); } if ($accountNumber === '') { $accountNumber = strval($ID); } $fileID = CFile::SaveFile(array('name' => "invoice_{$accountNumber}.pdf", 'type' => 'file', 'content' => $content, 'MODULE_ID' => 'crm'), 'crm'); if (!(is_int($fileID) && $fileID > 0)) { __CrmMobileInvoiceEditEndResonse(array('ERROR' => GetMessage('CRM_INVOICE_COULD_NOT_CREATE_FILE'))); } $storageTypeID = StorageType::getDefaultTypeID(); $elementID = StorageManager::saveEmailAttachment(CFile::GetFileArray($fileID), $storageTypeID); if (!(is_int($elementID) && $elementID > 0)) { __CrmMobileInvoiceEditEndResonse(array('ERROR' => GetMessage('CRM_INVOICE_COULD_NOT_CREATE_WEBDAV_ELEMENT'))); } __CrmMobileInvoiceEditEndResonse(array('RESULT_DATA' => array('ELEMENT_INFO' => StorageManager::getFileInfo($elementID, $storageTypeID)))); } else { __CrmMobileInvoiceEditEndResonse(array('ERROR' => 'Action is not supported in current context.')); }