function __MPF_ImageResizeHandler(&$arCustomFile, $arParams = null)
 {
     static $arResizeParams = array();
     if ($arParams !== null) {
         if (is_array($arParams) && array_key_exists("width", $arParams) && array_key_exists("height", $arParams)) {
             $arResizeParams = $arParams;
         } elseif (intVal($arParams) > 0) {
             $arResizeParams = array("width" => intVal($arParams), "height" => intVal($arParams));
         }
     }
     if (!is_array($arCustomFile) || !isset($arCustomFile['fileID'])) {
         return false;
     }
     $fileID = $arCustomFile['fileID'];
     $arFile = CFile::MakeFileArray($fileID);
     if (CFile::CheckImageFile($arFile) === null) {
         $aImgThumb = CFile::ResizeImageGet($fileID, array("width" => 90, "height" => 90), BX_RESIZE_IMAGE_EXACT, true);
         $arCustomFile['img_thumb_src'] = $aImgThumb['src'];
         if (!empty($arResizeParams)) {
             $aImgSource = CFile::ResizeImageGet($fileID, array("width" => $arResizeParams["width"], "height" => $arResizeParams["height"]), BX_RESIZE_IMAGE_PROPORTIONAL, true);
             $arCustomFile['img_source_src'] = $aImgSource['src'];
             $arCustomFile['img_source_width'] = $aImgSource['width'];
             $arCustomFile['img_source_height'] = $aImgSource['height'];
         }
     }
 }
Esempio n. 2
0
function __main_post_form_image_resize(&$arCustomFile, $arParams = null)
{
    static $arResizeParams = array();
    if ($arParams !== null) {
        if (is_array($arParams) && array_key_exists("width", $arParams) && array_key_exists("height", $arParams)) {
            $arResizeParams = $arParams;
        } elseif (intVal($arParams) > 0) {
            $arResizeParams = array("width" => intVal($arParams), "height" => intVal($arParams));
        }
    }
    if (!is_array($arCustomFile) || !isset($arCustomFile['fileID'])) {
        return false;
    }
    if (array_key_exists("ID", $arCustomFile)) {
        $arFile = $arCustomFile;
        $fileID = $arCustomFile['ID'];
    } else {
        $fileID = $arCustomFile['fileID'];
        $arFile = CFile::MakeFileArray($fileID);
        $arFile1 = CFile::GetByID($fileID)->fetch();
        if (is_array($arFile) && is_array($arFile1)) {
            $arCustomFile = array_merge($arFile, $arFile1, $arCustomFile);
        }
    }
    if (CFile::CheckImageFile($arFile) === null) {
        $aImgThumb = CFile::ResizeImageGet($fileID, array("width" => 90, "height" => 90), BX_RESIZE_IMAGE_EXACT, true);
        $arCustomFile['img_thumb_src'] = $aImgThumb['src'];
        if (!empty($arResizeParams)) {
            $aImgSource = CFile::ResizeImageGet($fileID, array("width" => $arResizeParams["width"], "height" => $arResizeParams["height"]), BX_RESIZE_IMAGE_PROPORTIONAL, true);
            $arCustomFile['img_source_src'] = $aImgSource['src'];
            $arCustomFile['img_source_width'] = $aImgSource['width'];
            $arCustomFile['img_source_height'] = $aImgSource['height'];
        }
    }
}
Esempio n. 3
0
 public function CheckFields(&$arFields, $ID = false)
 {
     global $DB, $USER;
     $arMsg = array();
     if ((is_set($arFields, "NAME") || $ID === false) && strlen(trim($arFields["NAME"])) <= 0) {
         $arMsg[] = array("id" => "NAME", "text" => GetMessage("LEARNING_BAD_NAME"));
     }
     if (is_set($arFields, "FILE_ID")) {
         $error = CFile::CheckImageFile($arFields["FILE_ID"]);
         if (strlen($error) > 0) {
             $arMsg[] = array("id" => "FILE_ID", "text" => $error);
         }
     }
     if (strlen($this->LAST_ERROR) <= 0) {
         if ($ID === false && !is_set($arFields, "LESSON_ID") || is_set($arFields, "LESSON_ID") && intval($arFields["LESSON_ID"]) < 1) {
             $arMsg[] = array("id" => "LESSON_ID", "text" => GetMessage("LEARNING_BAD_LESSON_ID"));
         } elseif (is_set($arFields, "LESSON_ID")) {
             $res = CLearnLesson::GetByID($arFields["LESSON_ID"]);
             if ($arRes = $res->Fetch()) {
                 $oAccess = CLearnAccess::GetInstance($USER->GetID());
                 $bAccessLessonModify = $oAccess->IsBaseAccess(CLearnAccess::OP_LESSON_WRITE) || $oAccess->IsLessonAccessible($arFields["LESSON_ID"], CLearnAccess::OP_LESSON_WRITE);
                 if (!$bAccessLessonModify) {
                     $arMsg[] = array("id" => "LESSON_ID", "text" => GetMessage("LEARNING_BAD_LESSON_ID_EX"));
                 }
             } else {
                 $arMsg[] = array("id" => "LESSON_ID", "text" => GetMessage("LEARNING_BAD_LESSON_ID_EX"));
             }
         }
     }
     if (!empty($arMsg)) {
         $e = new CAdminException($arMsg);
         $GLOBALS["APPLICATION"]->ThrowException($e);
         return false;
     }
     if (is_set($arFields, "QUESTION_TYPE") && !in_array($arFields["QUESTION_TYPE"], array("S", "M", "T", "R"))) {
         $arFields["QUESTION_TYPE"] = "S";
     }
     if (is_set($arFields, "DESCRIPTION_TYPE") && $arFields["DESCRIPTION_TYPE"] != "html") {
         $arFields["DESCRIPTION_TYPE"] = "text";
     }
     if (is_set($arFields, "DIRECTION") && $arFields["DIRECTION"] != "H") {
         $arFields["DIRECTION"] = "V";
     }
     if (is_set($arFields, "SELF") && $arFields["SELF"] != "Y") {
         $arFields["SELF"] = "N";
     }
     if (is_set($arFields, "ACTIVE") && $arFields["ACTIVE"] != "Y") {
         $arFields["ACTIVE"] = "N";
     }
     if (is_set($arFields, "EMAIL_ANSWER") && $arFields["EMAIL_ANSWER"] != "Y") {
         $arFields["EMAIL_ANSWER"] = "N";
     }
     if (is_set($arFields, "CORRECT_REQUIRED") && $arFields["CORRECT_REQUIRED"] != "Y") {
         $arFields["CORRECT_REQUIRED"] = "N";
     }
     return true;
 }
Esempio n. 4
0
 function CheckFields($ACTION, &$arFields, $ID = 0)
 {
     global $DB;
     if ((is_set($arFields, "USER_ID") || $ACTION == "ADD") && IntVal($arFields["USER_ID"]) <= 0) {
         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("BLG_GU_EMPTY_USER_ID"), "EMPTY_USER_ID");
         return false;
     } elseif (is_set($arFields, "USER_ID")) {
         $dbResult = CUser::GetByID($arFields["USER_ID"]);
         if (!$dbResult->Fetch()) {
             $GLOBALS["APPLICATION"]->ThrowException(GetMessage("BLG_GU_ERROR_NO_USER_ID"), "ERROR_NO_USER_ID");
             return false;
         }
     }
     if (is_set($arFields, "ALIAS") && strlen($arFields["ALIAS"]) > 0) {
         $dbResult = CBlogUser::GetList(array(), array("ALIAS" => $arFields["ALIAS"], "!ID" => IntVal($ID)), false, false, array("ID"));
         if ($dbResult->Fetch()) {
             $GLOBALS["APPLICATION"]->ThrowException(GetMessage("BLG_GU_ERROR_DUPL_ALIAS"), "ERROR_DUPL_ALIAS");
             return false;
         }
     }
     if (is_set($arFields, "LAST_VISIT") && !$DB->IsDate($arFields["LAST_VISIT"], false, LANG, "FULL")) {
         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("BLG_GU_ERROR_LAST_VISIT"), "ERROR_LAST_VISIT");
         return false;
     }
     if (is_set($arFields, "DATE_REG") && !$DB->IsDate($arFields["DATE_REG"], false, LANG, "FULL")) {
         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("BLG_GU_ERROR_DATE_REG"), "ERROR_DATE_REG");
         return false;
     }
     if ((is_set($arFields, "ALLOW_POST") || $ACTION == "ADD") && $arFields["ALLOW_POST"] != "Y" && $arFields["ALLOW_POST"] != "N") {
         $arFields["ALLOW_POST"] = "Y";
     }
     if (is_set($arFields, "AVATAR") && strlen($arFields["AVATAR"]["name"]) <= 0 && strlen($arFields["AVATAR"]["del"]) <= 0) {
         unset($arFields["AVATAR"]);
     }
     if (is_set($arFields, "AVATAR")) {
         $max_size = COption::GetOptionInt("blog", "avatar_max_size", 30000);
         //$max_width = COption::GetOptionInt("blog", "avatar_max_width", 100);
         //$max_height = COption::GetOptionInt("blog", "avatar_max_height", 100);
         $res = CFile::CheckImageFile($arFields["AVATAR"], $max_size, 0, 0);
         if (strlen($res) > 0) {
             $GLOBALS["APPLICATION"]->ThrowException($res, "ERROR_AVATAR");
             return false;
         }
     }
     return True;
 }
Esempio n. 5
0
 function __MPF_ImageResizeHandler(&$arCustomFile)
 {
     $arResizeParams = array("width" => 400, "height" => 400);
     if (!is_array($arCustomFile) || !isset($arCustomFile['fileID'])) {
         return false;
     }
     $fileID = $arCustomFile['fileID'];
     $arFile = CFile::MakeFileArray($fileID);
     if (CFile::CheckImageFile($arFile) === null) {
         $aImgThumb = CFile::ResizeImageGet($fileID, array("width" => 90, "height" => 90), BX_RESIZE_IMAGE_EXACT, true);
         $arCustomFile['img_thumb_src'] = $aImgThumb['src'];
         if (!empty($arResizeParams)) {
             $aImgSource = CFile::ResizeImageGet($fileID, array("width" => $arResizeParams["width"], "height" => $arResizeParams["height"]), BX_RESIZE_IMAGE_PROPORTIONAL, true);
             $arCustomFile['img_source_src'] = $aImgSource['src'];
             $arCustomFile['img_source_width'] = $aImgSource['width'];
             $arCustomFile['img_source_height'] = $aImgSource['height'];
         }
     }
 }
Esempio n. 6
0
 function CheckFields($arFields, $ID = false)
 {
     global $DB;
     $arMsg = array();
     if ((is_set($arFields, "NAME") || $ID === false) && strlen(trim($arFields["NAME"])) <= 0) {
         $arMsg[] = array("id" => "NAME", "text" => GetMessage("LEARNING_BAD_NAME"));
     }
     if (is_set($arFields, "ACTIVE_FROM") && strlen($arFields["ACTIVE_FROM"]) > 0 && !$DB->IsDate($arFields["ACTIVE_FROM"], false, LANG, "FULL")) {
         $arMsg[] = array("id" => "ACTIVE_FROM", "text" => GetMessage("LEARNING_BAD_ACTIVE_FROM"));
     }
     if (is_set($arFields, "ACTIVE_TO") && strlen($arFields["ACTIVE_TO"]) > 0 && !$DB->IsDate($arFields["ACTIVE_TO"], false, LANG, "FULL")) {
         $arMsg[] = array("id" => "ACTIVE_TO", "text" => GetMessage("LEARNING_BAD_ACTIVE_TO"));
     }
     if (is_set($arFields, "PREVIEW_PICTURE") && is_array($arFields["PREVIEW_PICTURE"])) {
         $error = CFile::CheckImageFile($arFields["PREVIEW_PICTURE"]);
         if (strlen($error) > 0) {
             $arMsg[] = array("id" => "PREVIEW_PICTURE", "text" => $error);
         }
     }
     //Sites
     if ($ID === false && !is_set($arFields, "SITE_ID") || is_set($arFields, "SITE_ID") && (!is_array($arFields["SITE_ID"]) || empty($arFields["SITE_ID"]))) {
         $arMsg[] = array("id" => "SITE_ID[]", "text" => GetMessage("LEARNING_BAD_SITE_ID"));
     } elseif (is_set($arFields, "SITE_ID")) {
         $tmp = "";
         foreach ($arFields["SITE_ID"] as $lang) {
             $res = CSite::GetByID($lang);
             if (!$res->Fetch()) {
                 $tmp .= "'" . $lang . "' - " . GetMessage("LEARNING_BAD_SITE_ID_EX") . "<br>";
             }
         }
         if ($tmp != "") {
             $arMsg[] = array("id" => "SITE_ID[]", "text" => $tmp);
         }
     }
     if (!empty($arMsg)) {
         $e = new CAdminException($arMsg);
         $GLOBALS["APPLICATION"]->ThrowException($e);
         return false;
     }
     return true;
 }
Esempio n. 7
0
    }
}
IncludeModuleLangFile(__FILE__);
ClearVars();
$errorMessage = '';
$bVarsFromForm = false;
$userId = (int) $USER->GetID();
$entityId = "CAT_STORE";
if ($_SERVER["REQUEST_METHOD"] == "POST" && strlen($_REQUEST["Update"]) > 0 && !$bReadOnly && check_bitrix_sessid()) {
    $arPREVIEW_PICTURE = $_FILES["IMAGE_ID"];
    $arPREVIEW_PICTURE["del"] = $IMAGE_ID_del;
    $arPREVIEW_PICTURE["MODULE_ID"] = "catalog";
    $ISSUING_CENTER = $_POST["ISSUING_CENTER"] == 'Y' ? 'Y' : 'N';
    $SHIPPING_CENTER = $_POST["SHIPPING_CENTER"] == 'Y' ? 'Y' : 'N';
    $fileId = 0;
    $isImage = CFile::CheckImageFile($arPREVIEW_PICTURE);
    if (trim($ADDRESS) == '') {
        $errorMessage .= GetMessage("ADDRESS_EMPTY") . "<br>";
    }
    if (strlen($isImage) == 0 && (strlen($arPREVIEW_PICTURE["name"]) > 0 || strlen($arPREVIEW_PICTURE["del"]) > 0)) {
        $fileId = CFile::SaveFile($arPREVIEW_PICTURE, "catalog");
    } elseif (strlen($isImage) > 0) {
        $errorMessage .= $isImage . "<br>";
    }
    $arFields = array("TITLE" => isset($_POST['TITLE']) ? $_POST['TITLE'] : '', "SORT" => isset($_POST['CSTORE_SORT']) ? (int) $_POST['CSTORE_SORT'] : 0, "ACTIVE" => isset($_POST['ACTIVE']) && $_POST['ACTIVE'] == 'Y' ? 'Y' : 'N', "ADDRESS" => isset($_POST['ADDRESS']) ? $_POST['ADDRESS'] : '', "DESCRIPTION" => isset($_POST['DESCRIPTION']) ? $_POST['DESCRIPTION'] : '', "GPS_N" => isset($_POST['GPS_N']) ? $_POST['GPS_N'] : '', "GPS_S" => isset($_POST['GPS_S']) ? $_POST['GPS_S'] : '', "PHONE" => isset($_POST['PHONE']) ? $_POST['PHONE'] : '', "SCHEDULE" => isset($_POST['SCHEDULE']) ? $_POST['SCHEDULE'] : '', "XML_ID" => isset($_POST['XML_ID']) ? $_POST['XML_ID'] : '', "USER_ID" => $userId, "MODIFIED_BY" => $userId, "EMAIL" => isset($_POST["EMAIL"]) ? $_POST["EMAIL"] : '', "ISSUING_CENTER" => $ISSUING_CENTER, "SHIPPING_CENTER" => $SHIPPING_CENTER, "SITE_ID" => $_POST["SITE_ID"]);
    $USER_FIELD_MANAGER->EditFormAddFields($entityId, $arFields);
    if (intval($fileId) > 0) {
        $arFields["IMAGE_ID"] = intval($fileId);
    } elseif ($fileId === "NULL") {
        $arFields["IMAGE_ID"] = "null";
    }
Esempio n. 8
0
 protected function CheckFields($action, &$arFields)
 {
     if (isset($arFields["EXTERNAL_AUTH_ID"]) && strlen($arFields["EXTERNAL_AUTH_ID"]) <= 0) {
         return false;
     }
     if (isset($arFields["SITE_ID"]) && strlen($arFields["SITE_ID"]) <= 0) {
         $arFields["SITE_ID"] = SITE_ID;
     }
     if (!isset($arFields["USER_ID"])) {
         $arFields["USER_ID"] = $GLOBALS["USER"]->GetID();
     }
     if (is_set($arFields, "PERSONAL_PHOTO")) {
         $res = CFile::CheckImageFile($arFields["PERSONAL_PHOTO"]);
         if (strlen($res) > 0) {
             unset($arFields["PERSONAL_PHOTO"]);
         } else {
             $arFields["PERSONAL_PHOTO"]["MODULE_ID"] = "socialservices";
             CFile::SaveForDB($arFields, "PERSONAL_PHOTO", "socialservices");
         }
     }
     return true;
 }
Esempio n. 9
0
 function SaveFile($name, $arRestriction = array())
 {
     $wizard = $this->GetWizard();
     $deleteFile = $wizard->GetVar($name . "_del");
     $wizard->UnSetVar($name . "_del");
     $oldFileID = $wizard->GetVar($name);
     $fileNew = $wizard->GetRealName($name . "_new");
     if (!array_key_exists($fileNew, $_FILES) || strlen($_FILES[$fileNew]["name"]) <= 0 && $deleteFile === null) {
         return;
     }
     if (strlen($_FILES[$fileNew]["tmp_name"]) <= 0 && $deleteFile === null) {
         $this->SetError(GetMessage("MAIN_WIZARD_FILE_UPLOAD_ERROR"), $name . "_new");
         return;
     }
     $arFile = $_FILES[$fileNew] + array("del" => $deleteFile == "Y" ? "Y" : "", "old_file" => intval($oldFileID) > 0 ? intval($oldFileID) : 0, "MODULE_ID" => "tmp_wizard");
     $max_file_size = array_key_exists("max_file_size", $arRestriction) ? intval($arRestriction["max_file_size"]) : 0;
     $max_width = array_key_exists("max_width", $arRestriction) ? intval($arRestriction["max_width"]) : 0;
     $max_height = array_key_exists("max_height", $arRestriction) ? intval($arRestriction["max_height"]) : 0;
     $extensions = array_key_exists("extensions", $arRestriction) && strlen($arRestriction["extensions"]) > 0 ? trim($arRestriction["extensions"]) : false;
     $make_preview = array_key_exists("make_preview", $arRestriction) && $arRestriction["make_preview"] == "Y" ? true : false;
     $error = CFile::CheckFile($arFile, $max_file_size, false, $extensions);
     if (strlen($error) > 0) {
         $this->SetError($error, $name . "_new");
         return;
     }
     if ($make_preview && $max_width > 0 && $max_height > 0) {
         list($sourceWidth, $sourceHeight, $type, $attr) = CFile::GetImageSize($arFile["tmp_name"]);
         if ($sourceWidth > $max_width || $sourceHeight > $max_height) {
             $success = CWizardUtil::CreateThumbnail($arFile["tmp_name"], $arFile["tmp_name"], $max_width, $max_height);
             if ($success) {
                 $arFile["size"] = @filesize($arFile["tmp_name"]);
             }
         }
     } elseif ($max_width > 0 || $max_height > 0) {
         $error = CFile::CheckImageFile($arFile, $max_file_size, $max_width, $max_height);
         if (strlen($error) > 0) {
             $this->SetError($error, $name . "_new");
             return;
         }
     }
     $fileID = (int) CFile::SaveFile($arFile, "tmp");
     if ($fileID > 0) {
         $wizard->SetVar($name, $fileID);
     } else {
         $wizard->UnSetVar($name);
     }
     return $fileID;
 }
Esempio n. 10
0
$fileName = '';
if ($REQUEST_METHOD == "POST" && $forumPermissions >= "W" && (strlen($save) > 0 || strlen($apply) > 0)) {
    if (isset($_FILES["IMAGE"]["name"])) {
        $fileName = RemoveScriptExtension($_FILES["IMAGE"]["name"]);
    }
    if (!check_bitrix_sessid()) {
        $arError[] = array("id" => "bad_sessid", "text" => GetMessage("ERROR_BAD_SESSID"));
    } elseif ($ID > 0 && !CForumNew::CanUserUpdateForum($ID, $USER->GetUserGroupArray(), $USER->GetID())) {
        $arError[] = array("id" => "not_right_for_edit", "text" => GetMessage("FE_NO_PERMS2UPDATE"));
    } elseif ($ID <= 0 && !CForumNew::CanUserAddForum($USER->GetUserGroupArray(), $USER->GetID())) {
        $arError[] = array("id" => "not_right_for_add", "text" => GetMessage("FE_NO_PERMS2ADD"));
    } elseif (!empty($_FILES["IMAGE"]["tmp_name"])) {
        $sUploadDir = $_SERVER["DOCUMENT_ROOT"] . BX_ROOT . "/images/forum/" . ($_REQUEST["TYPE"] == "I" ? "icon" : "smile") . "/";
        CheckDirPath($sUploadDir);
        $arSmile = $ID > 0 ? CForumSmile::GetByID($ID) : $arSmile;
        $res = CFile::CheckImageFile($_FILES["IMAGE"], COption::GetOptionString("forum", "file_max_size", 50000), 0, 0);
        if (strLen($res) > 0) {
            $arError[] = array("id" => "IMAGE", "text" => $res);
        } elseif (file_exists($sUploadDir . $fileName) && !(isset($arSmile["IMAGE"]) && $arSmile["IMAGE"] != $fileName)) {
            $arError[] = array("id" => "IMAGE", "text" => GetMessage("ERROR_EXISTS_IMAGE", array("#FILE#" => str_replace("//", "/", "/" . BX_ROOT . "/images/forum/" . ($_REQUEST["TYPE"] == "I" ? "icon" : "smile") . "/" . $fileName))));
        } elseif (!@copy($_FILES["IMAGE"]["tmp_name"], $sUploadDir . $fileName)) {
            $arError[] = array("id" => "IMAGE", "text" => GetMessage("ERROR_COPY_IMAGE"));
        } else {
            @chmod($sUploadDir . $fileName, BX_FILE_PERMISSIONS);
        }
    }
    if (empty($arError)) {
        $GLOBALS["APPLICATION"]->ResetException();
        $arFields = array("SORT" => $_REQUEST["SORT"], "TYPE" => $_REQUEST["TYPE"], "TYPING" => trim($_REQUEST["TYPING"]), "DESCRIPTION" => $_REQUEST["DESCRIPTION"], "LANG" => array());
        if (!empty($_FILES["IMAGE"]["tmp_name"])) {
            $arFields["IMAGE"] = $fileName;
Esempio n. 11
0
 /**
  * Prepares array of fields with values for query to DB.
  * Also, uploads/removes files, if there are.
  * @throws LearnException on error. Errcodes are: LearnException::EXC_ERR_GN_CHECK_PARAMS,
  *         LearnException::EXC_ERR_GN_FILE_UPLOAD
  */
 protected static function _PrepareDataForQuery($arFieldsMap, $arFields, $lessonId)
 {
     global $DB;
     $arLessonData = false;
     // if data prepartation for update - cache data about lesson to be updated
     if ($lessonId !== false) {
         // if lesson data not cached - get it
         if ($arLessonData === false) {
             $arLessonData = self::GetByID($lessonId);
         }
     }
     $arFieldsToDb = array();
     foreach ($arFields as $field => $value) {
         $fieldNameInDB = $arFieldsMap[$field]['field'];
         if ($field === 'PREVIEW_PICTURE' || $field === 'DETAIL_PICTURE' || $fieldNameInDB === 'PREVIEW_PICTURE' || $fieldNameInDB === 'DETAIL_PICTURE') {
             $error = CFile::CheckImageFile($value);
             if (strlen($error) > 0) {
                 throw new LearnException('EA_PARAMS: ' . $error, LearnException::EXC_ERR_GN_CHECK_PARAMS);
             }
             // if data prepartation for update - gets prev pictures names
             if ($lessonId !== false) {
                 if (!array_key_exists($field, $arLessonData)) {
                     throw new LearnException('EA_LOGIC', LearnException::EXC_ERR_ALL_LOGIC);
                 }
                 $arFields[$field]['old_file'] = $arLessonData[$field];
                 $value = $arFields[$field];
             }
             // throws LearnException on error, returns FALSE if id of image not updated
             $fileId = self::_UploadFile($fieldNameInDB, $value);
             if ($fileId === false) {
                 continue;
             }
             // id of image not updated
             // replace value for current field to fileId
             $value = $arFields[$field] = $fileId;
         }
         if ($value === NULL) {
             $arFieldsToDb[$fieldNameInDB] = false;
         } else {
             $arFieldsToDb[$fieldNameInDB] = $value;
         }
     }
     return $arFieldsToDb;
 }
Esempio n. 12
0
 public static function CheckFields($ACTION, &$arFields, $ID = 0)
 {
     $aMsg = array();
     $ID = intVal($ID);
     $arVote = array();
     if ($ID > 0) {
         $db_res = CVote::GetByID($ID);
         if ($db_res && ($res = $db_res->Fetch())) {
             $arVote = $res;
         }
     }
     unset($arFields["ID"]);
     if (is_set($arFields, "CHANNEL_ID") || $ACTION == "ADD") {
         $arFields["CHANNEL_ID"] = intVal($arFields["CHANNEL_ID"]);
         if ($arFields["CHANNEL_ID"] <= 0) {
             $aMsg[] = array("id" => "CHANNEL_ID", "text" => GetMessage("VOTE_EMPTY_CHANNEL_ID"));
         } else {
             $rChannel = CVoteChannel::GetList($by, $order, array('ID' => intval($arFields['CHANNEL_ID'])), $filtered);
             if (!($rChannel && ($arChannel = $rChannel->Fetch()))) {
                 $aMsg[] = array("id" => "CHANNEL_ID", "text" => GetMessage("VOTE_WRONG_CHANNEL_ID"));
             }
         }
     }
     if (is_set($arFields, "C_SORT")) {
         $arFields["C_SORT"] = intval($arFields["C_SORT"]);
     }
     if (is_set($arFields, "ACTIVE") || $ACTION == "ADD") {
         $arFields["ACTIVE"] = $arFields["ACTIVE"] == "N" ? "N" : "Y";
     }
     unset($arFields["TIMESTAMP_X"]);
     $date_start = false;
     if (is_set($arFields, "DATE_START") || $ACTION == "ADD") {
         $arFields["DATE_START"] = trim($arFields["DATE_START"]);
         $date_start = MakeTimeStamp($arFields["DATE_START"]);
         if (!$date_start) {
             $aMsg[] = array("id" => "DATE_START", "text" => GetMessage("VOTE_WRONG_DATE_START"));
         }
     }
     if (is_set($arFields, "DATE_END") || $ACTION == "ADD") {
         $arFields["DATE_END"] = trim($arFields["DATE_END"]);
         if (strlen($arFields["DATE_END"]) <= 0) {
             if ($date_start != false) {
                 $date_end = $date_start + 2592000;
                 $arFields["DATE_END"] = GetTime($date_end, "FULL");
             } else {
                 $date_end = 1924984799;
                 // '31.12.2030 23:59:59'
                 $arFields["DATE_END"] = GetTime($date_end, "FULL");
             }
         } else {
             $date_end = MakeTimeStamp($arFields["DATE_END"]);
         }
         if (!$date_end) {
             $aMsg[] = array("id" => "DATE_END", "text" => GetMessage("VOTE_WRONG_DATE_END"));
         } elseif ($date_start >= $date_end && !empty($arFields["DATE_START"])) {
             $aMsg[] = array("id" => "DATE_END", "text" => GetMessage("VOTE_WRONG_DATE_TILL"));
         }
     }
     if (empty($aMsg) && (is_set($arFields, "DATE_START") || is_set($arFields, "DATE_END") || is_set($arFields, "CHANNEL_ID") || is_set($arFields, "ACTIVE"))) {
         $vid = 0;
         if ($ACTION == "ADD" && $arFields["ACTIVE"] == "Y") {
             $vid = CVote::WrongDateInterval(0, $arFields["DATE_START"], $arFields["DATE_END"], $arFields["CHANNEL_ID"]);
         } elseif ($ACTION != "ADD" && !(is_set($arFields, "ACTIVE") && $arFields["ACTIVE"] != "Y")) {
             $res = array("DATE_START" => is_set($arFields, "DATE_START") ? $arFields["DATE_START"] : false, "DATE_END" => is_set($arFields, "DATE_END") ? $arFields["DATE_END"] : false, "CHANNEL_ID" => is_set($arFields, "CHANNEL_ID") ? $arFields["CHANNEL_ID"] : false);
             $vid = CVote::WrongDateInterval($ID, $res["DATE_START"], $res["DATE_END"], $res["CHANNEL_ID"]);
         }
         if (intVal($vid) > 0) {
             $aMsg[] = array("id" => "DATE_START", "text" => str_replace("#ID#", $vid, GetMessage("VOTE_WRONG_INTERVAL")));
         }
     }
     if (is_set($arFields, "IMAGE_ID") && strLen($arFields["IMAGE_ID"]["name"]) <= 0 && strLen($arFields["IMAGE_ID"]["del"]) <= 0) {
         unset($arFields["IMAGE_ID"]);
     } elseif (is_set($arFields, "IMAGE_ID")) {
         if ($str = CFile::CheckImageFile($arFields["IMAGE_ID"])) {
             $aMsg[] = array("id" => "IMAGE_ID", "text" => $str);
         } else {
             $arFields["IMAGE_ID"]["MODULE_ID"] = "vote";
             if (!empty($arVote)) {
                 $arFields["IMAGE_ID"]["old_file"] = $arVote["IMAGE_ID"];
             }
         }
     }
     if (is_set($arFields, "COUNTER")) {
         $arFields["COUNTER"] = intVal($arFields["COUNTER"]);
     }
     if (is_set($arFields, "TITLE")) {
         $arFields["TITLE"] = trim($arFields["TITLE"]);
     }
     if (is_set($arFields, "DESCRIPTION")) {
         $arFields["DESCRIPTION"] = trim($arFields["DESCRIPTION"]);
     }
     if (is_set($arFields, "DESCRIPTION_TYPE") || $ACTION == "ADD") {
         $arFields["DESCRIPTION_TYPE"] = $arFields["DESCRIPTION_TYPE"] == "html" ? "html" : "text";
     }
     if (is_set($arFields, "EVENT1")) {
         $arFields["EVENT1"] = trim($arFields["EVENT1"]);
     }
     if (is_set($arFields, "EVENT2")) {
         $arFields["EVENT2"] = trim($arFields["EVENT2"]);
     }
     if (is_set($arFields, "EVENT3")) {
         $arFields["EVENT3"] = trim($arFields["EVENT3"]);
     }
     if (is_set($arFields, "UNIQUE_TYPE")) {
         $arFields["UNIQUE_TYPE"] = intVal($arFields["UNIQUE_TYPE"]);
     }
     if (is_set($arFields, "DELAY_TYPE") || $ACTION == "ADD") {
         $arFields["DELAY_TYPE"] = trim($arFields["DELAY_TYPE"]);
         $arFields["DELAY_TYPE"] = in_array($arFields["DELAY_TYPE"], array("S", "M", "H", "D")) ? $arFields["DELAY_TYPE"] : "D";
     }
     if (is_set($arFields, "DELAY") || $ACTION == "ADD") {
         $arFields["DELAY"] = intVal($arFields["DELAY"]);
     }
     unset($arFields["KEEP_IP_SEC"]);
     $sec = 1;
     switch ($arFields["DELAY_TYPE"]) {
         case "S":
             $sec = 1;
             break;
         case "M":
             $sec = 60;
             break;
         case "H":
             $sec = 3600;
             break;
         case "D":
             $sec = 86400;
             break;
     }
     $arFields["KEEP_IP_SEC"] = intval($arFields["DELAY"]) * $sec;
     if (is_set($arFields, "UNIQUE_TYPE") && $arFields['UNIQUE_TYPE'] < 5) {
         switch ($arFields['UNIQUE_TYPE']) {
             case 0:
                 $arFields['UNIQUE_TYPE'] = 5;
                 break;
             case 1:
                 $arFields['UNIQUE_TYPE'] = 6;
                 break;
             case 2:
                 $arFields['UNIQUE_TYPE'] = 8;
                 break;
             case 3:
                 $arFields['UNIQUE_TYPE'] = 12;
                 break;
             case 4:
                 $arFields['UNIQUE_TYPE'] = 20;
                 break;
         }
     }
     if (CVote::IsOldVersion() != "Y") {
         unset($arFields["TEMPLATE"]);
         unset($arFields["RESULT_TEMPLATE"]);
     }
     if (is_set($arFields, "TEMPLATE")) {
         $arFields["TEMPLATE"] = trim($arFields["TEMPLATE"]);
     }
     if (is_set($arFields, "RESULT_TEMPLATE")) {
         $arFields["RESULT_TEMPLATE"] = trim($arFields["RESULT_TEMPLATE"]);
     }
     if (is_set($arFields, "NOTIFY")) {
         $arFields["NOTIFY"] = in_array($arFields["NOTIFY"], array("Y", "N", "I")) ? $arFields["NOTIFY"] : "N";
     }
     if (is_set($arFields, "REQUIRED")) {
         $arFields["REQUIRED"] = $arFields["REQUIRED"] == "Y" ? "Y" : "N";
     }
     if (is_set($arFields, "AUTHOR_ID")) {
         $arFields["AUTHOR_ID"] = intval($arFields["AUTHOR_ID"]);
     }
     if (!empty($aMsg)) {
         global $APPLICATION;
         $e = new CAdminException(array_reverse($aMsg));
         $APPLICATION->ThrowException($e);
         return false;
     }
     return true;
 }
Esempio n. 13
0
 function convert_attachment($fileID = "", $p = "", $type = "", $text = "")
 {
     if (is_array($fileID)) {
         $text = $fileID[0];
         $p = $fileID[3];
         $fileID = $fileID[2];
     }
     $fileID = intval($fileID);
     $type = strtolower(empty($type) ? $this->type : $type);
     $type = in_array($type, array("html", "mail", "bbcode", "rss")) ? $type : "html";
     $this->arFiles = is_array($this->arFiles) ? $this->arFiles : array($this->arFiles);
     if ($fileID <= 0 || !array_key_exists($fileID, $this->arFiles) && !in_array($fileID, $this->arFiles)) {
         return $text;
     }
     if (!array_key_exists($fileID, $this->arFiles) && in_array($fileID, $this->arFiles)) {
         // array(fileID10, fileID12, fileID14)
         unset($this->arFiles[array_search($fileID, $this->arFiles)]);
         $this->arFiles[$fileID] = $fileID;
         // array(fileID10 => fileID10, fileID12 => fileID12, fileID14 => fileID14)
     }
     if (!is_array($this->arFiles[$fileID])) {
         $this->arFiles[$fileID] = CFile::GetFileArray($fileID);
     }
     // array(fileID10 => array about file, ....)
     if (!is_array($this->arFiles[$fileID])) {
         // if file does not exist
         unset($this->arFiles[$fileID]);
         return $text;
     }
     if (!array_key_exists($fileID, $this->arFilesParsed) || empty($this->arFilesParsed[$fileID][$type])) {
         $arFile = $this->arFiles[$fileID];
         if ($type == "html" || $type == "rss") {
             $width = 0;
             $height = 0;
             if (preg_match_all("/width\\=(?P<width>\\d+)|height\\=(?P<height>\\d+)/is" . BX_UTF_PCRE_MODIFIER, $p, $matches)) {
                 $width = intval(!empty($matches["width"][0]) ? $matches["width"][0] : $matches["width"][1]);
                 $height = intval(!empty($matches["height"][0]) ? $matches["height"][0] : $matches["height"][1]);
             }
             $arFile[$type] = $GLOBALS["APPLICATION"]->IncludeComponent("bitrix:forum.interface", "show_file", array("FILE" => $arFile, "SHOW_MODE" => $type == "html" ? "THUMB" : "RSS", "SIZE" => array("width" => $width, "height" => $height), "MAX_SIZE" => array("width" => $this->imageWidth, "height" => $this->imageHeight), "HTML_SIZE" => array("width" => $this->imageHtmlWidth, "height" => $this->imageHtmlHeight), "CONVERT" => "N", "NAME_TEMPLATE" => $this->userNameTemplate, "FAMILY" => "FORUM", "SINGLE" => "Y", "RETURN" => "Y"), $this->component, array("HIDE_ICONS" => "Y"));
         } else {
             $path = '/bitrix/components/bitrix/forum.interface/show_file.php?fid=' . $arFile["ID"];
             $bIsImage = CFile::CheckImageFile(CFile::MakeFileArray($fileID)) === null;
             //				$path = ($bIsImage && !empty($arFile["SRC"]) ? $arFile["SRC"] : !$bIsImage && !empty($arFile["URL"]) ? $arFile["URL"] : $path);
             $path = preg_replace("'(?<!:)/+'s", "/", substr($path, 0, 1) == "/" ? CHTTP::URN2URI($path, $this->serverName) : $path);
             switch ($type) {
                 case "bbcode":
                     $arFile["bbcode"] = $bIsImage ? '[IMG]' . $path . '[/IMG]' : '[URL=' . $path . ']' . $arFile["ORIGINAL_NAME"] . '[/URL]';
                     break;
                 case "mail":
                     $arFile["mail"] = $arFile["ORIGINAL_NAME"] . ($bIsImage ? " (IMAGE: " . $path . ")" : " (URL: " . $path . ")");
                     break;
             }
         }
         $this->arFilesParsed[$fileID] = $arFile;
     }
     $this->arFilesIDParsed[] = $fileID;
     return $this->arFilesParsed[$fileID][$type];
 }
Esempio n. 14
0
 function CheckFields(&$arFields, $ID = false)
 {
     global $DB, $APPLICATION, $USER;
     $this->LAST_ERROR = "";
     $bInternal = false;
     if ($ID > 0 && !is_set($arFields, "EXTERNAL_AUTH_ID")) {
         $strSql = "SELECT EXTERNAL_AUTH_ID FROM b_user WHERE ID=" . IntVal($ID);
         $dbr = $DB->Query($strSql, false, "FILE: " . __FILE__ . "<br> LINE: " . __LINE__);
         if (($ar = $dbr->Fetch()) && strlen($ar['EXTERNAL_AUTH_ID']) <= 0) {
             $bInternal = true;
         }
     } elseif (!is_set($arFields, "EXTERNAL_AUTH_ID") || strlen(trim($arFields["EXTERNAL_AUTH_ID"])) <= 0) {
         $bInternal = true;
     }
     if ($bInternal) {
         if ($ID === false) {
             if (!isset($arFields["LOGIN"])) {
                 $this->LAST_ERROR .= GetMessage("user_login_not_set") . "<br>";
             }
             if (!isset($arFields["PASSWORD"])) {
                 $this->LAST_ERROR .= GetMessage("user_pass_not_set") . "<br>";
             }
             if (!isset($arFields["EMAIL"])) {
                 $this->LAST_ERROR .= GetMessage("user_email_not_set") . "<br>";
             }
         }
         if (is_set($arFields, "LOGIN") && $arFields["LOGIN"] != Trim($arFields["LOGIN"])) {
             $this->LAST_ERROR .= GetMessage("LOGIN_WHITESPACE") . "<br>";
         }
         if (is_set($arFields, "LOGIN") && strlen($arFields["LOGIN"]) < 3) {
             $this->LAST_ERROR .= GetMessage("MIN_LOGIN") . "<br>";
         }
         if (is_set($arFields, "PASSWORD")) {
             if (array_key_exists("GROUP_ID", $arFields)) {
                 $arGroups = array();
                 if (is_array($arFields["GROUP_ID"])) {
                     foreach ($arFields["GROUP_ID"] as $arGroup) {
                         if (is_array($arGroup)) {
                             $arGroups[] = $arGroup["GROUP_ID"];
                         } else {
                             $arGroups[] = $arGroup;
                         }
                     }
                 }
                 $arPolicy = $this->GetGroupPolicy($arGroups);
             } elseif ($ID !== false) {
                 $arPolicy = $this->GetGroupPolicy($ID);
             } else {
                 $arPolicy = $this->GetGroupPolicy(array());
             }
             $password_min_length = intval($arPolicy["PASSWORD_LENGTH"]);
             if ($password_min_length <= 0) {
                 $password_min_length = 6;
             }
             if (strlen($arFields["PASSWORD"]) < $password_min_length) {
                 $this->LAST_ERROR .= GetMessage("MAIN_FUNCTION_REGISTER_PASSWORD_LENGTH", array("#LENGTH#" => $arPolicy["PASSWORD_LENGTH"])) . "<br>";
             }
             if ($arPolicy["PASSWORD_UPPERCASE"] === "Y" && !preg_match("/[A-Z]/", $arFields["PASSWORD"])) {
                 $this->LAST_ERROR .= GetMessage("MAIN_FUNCTION_REGISTER_PASSWORD_UPPERCASE") . "<br>";
             }
             if ($arPolicy["PASSWORD_LOWERCASE"] === "Y" && !preg_match("/[a-z]/", $arFields["PASSWORD"])) {
                 $this->LAST_ERROR .= GetMessage("MAIN_FUNCTION_REGISTER_PASSWORD_LOWERCASE") . "<br>";
             }
             if ($arPolicy["PASSWORD_DIGITS"] === "Y" && !preg_match("/[0-9]/", $arFields["PASSWORD"])) {
                 $this->LAST_ERROR .= GetMessage("MAIN_FUNCTION_REGISTER_PASSWORD_DIGITS") . "<br>";
             }
             if ($arPolicy["PASSWORD_PUNCTUATION"] === "Y" && !preg_match("/[,.<>\\/?;:'\"[\\]\\{\\}\\\\|`~!@#\$%^&*()_+=-]/", $arFields["PASSWORD"])) {
                 $this->LAST_ERROR .= GetMessage("MAIN_FUNCTION_REGISTER_PASSWORD_PUNCTUATION") . "<br>";
             }
         }
         if (is_set($arFields, "EMAIL")) {
             if (strlen($arFields["EMAIL"]) < 3 || !check_email($arFields["EMAIL"], true)) {
                 $this->LAST_ERROR .= GetMessage("WRONG_EMAIL") . "<br>";
             } elseif ($ID === false && COption::GetOptionString("main", "new_user_email_uniq_check", "N") === "Y") {
                 $res = CUser::GetList($b, $o, array("=EMAIL" => $arFields["EMAIL"]));
                 if ($res->Fetch()) {
                     $this->LAST_ERROR .= GetMessage("USER_WITH_EMAIL_EXIST", array("#EMAIL#" => htmlspecialcharsbx($arFields["EMAIL"]))) . "<br>";
                 }
             }
         }
         if (is_set($arFields, "PASSWORD") && is_set($arFields, "CONFIRM_PASSWORD") && $arFields["PASSWORD"] !== $arFields["CONFIRM_PASSWORD"]) {
             $this->LAST_ERROR .= GetMessage("WRONG_CONFIRMATION") . "<br>";
         }
         if (is_array($arFields["GROUP_ID"]) && count($arFields["GROUP_ID"]) > 0) {
             if (is_array($arFields["GROUP_ID"][0]) && count($arFields["GROUP_ID"][0]) > 0) {
                 foreach ($arFields["GROUP_ID"] as $arGroup) {
                     if (strlen($arGroup["DATE_ACTIVE_FROM"]) > 0 && !CheckDateTime($arGroup["DATE_ACTIVE_FROM"])) {
                         $error = str_replace("#GROUP_ID#", $arGroup["GROUP_ID"], GetMessage("WRONG_DATE_ACTIVE_FROM"));
                         $this->LAST_ERROR .= $error . "<br>";
                     }
                     if (strlen($arGroup["DATE_ACTIVE_TO"]) > 0 && !CheckDateTime($arGroup["DATE_ACTIVE_TO"])) {
                         $error = str_replace("#GROUP_ID#", $arGroup["GROUP_ID"], GetMessage("WRONG_DATE_ACTIVE_TO"));
                         $this->LAST_ERROR .= $error . "<br>";
                     }
                 }
             }
         }
     }
     if (is_set($arFields, "PERSONAL_PHOTO") && strlen($arFields["PERSONAL_PHOTO"]["name"]) <= 0 && strlen($arFields["PERSONAL_PHOTO"]["del"]) <= 0) {
         unset($arFields["PERSONAL_PHOTO"]);
     }
     if (is_set($arFields, "PERSONAL_PHOTO")) {
         $res = CFile::CheckImageFile($arFields["PERSONAL_PHOTO"]);
         if (strlen($res) > 0) {
             $this->LAST_ERROR .= $res . "<br>";
         }
     }
     if (is_set($arFields, "PERSONAL_BIRTHDAY") && strlen($arFields["PERSONAL_BIRTHDAY"]) > 0 && !CheckDateTime($arFields["PERSONAL_BIRTHDAY"])) {
         $this->LAST_ERROR .= GetMessage("WRONG_PERSONAL_BIRTHDAY") . "<br>";
     }
     if (is_set($arFields, "WORK_LOGO") && strlen($arFields["WORK_LOGO"]["name"]) <= 0 && strlen($arFields["WORK_LOGO"]["del"]) <= 0) {
         unset($arFields["WORK_LOGO"]);
     }
     if (is_set($arFields, "WORK_LOGO")) {
         $res = CFile::CheckImageFile($arFields["WORK_LOGO"]);
         if (strlen($res) > 0) {
             $this->LAST_ERROR .= $res . "<br>";
         }
     }
     if (is_set($arFields, "LOGIN")) {
         $res = $DB->Query("SELECT 'x' " . "FROM b_user " . "WHERE LOGIN='******'\t" . "\t" . ($ID === false ? "" : " AND ID<>" . IntVal($ID)) . "\t" . (!$bInternal ? "\tAND EXTERNAL_AUTH_ID='" . $DB->ForSql($arFields["EXTERNAL_AUTH_ID"]) . "' " : " AND (EXTERNAL_AUTH_ID IS NULL OR " . $DB->Length("EXTERNAL_AUTH_ID") . "<=0)"));
         if ($res->Fetch()) {
             $this->LAST_ERROR .= str_replace("#LOGIN#", htmlspecialcharsbx($arFields["LOGIN"]), GetMessage("USER_EXIST")) . "<br>";
         }
     }
     if (is_object($APPLICATION)) {
         $APPLICATION->ResetException();
         if ($ID === false) {
             $db_events = GetModuleEvents("main", "OnBeforeUserAdd");
         } else {
             $arFields["ID"] = $ID;
             $db_events = GetModuleEvents("main", "OnBeforeUserUpdate");
         }
         while ($arEvent = $db_events->Fetch()) {
             $bEventRes = ExecuteModuleEventEx($arEvent, array(&$arFields));
             if ($bEventRes === false) {
                 if ($err = $APPLICATION->GetException()) {
                     $this->LAST_ERROR .= $err->GetString() . " ";
                 } else {
                     $APPLICATION->ThrowException("Unknown error");
                     $this->LAST_ERROR .= "Unknown error. ";
                 }
                 break;
             }
         }
     }
     if (is_object($APPLICATION)) {
         $APPLICATION->ResetException();
     }
     if (!$GLOBALS["USER_FIELD_MANAGER"]->CheckFields("USER", $ID, $arFields)) {
         if (is_object($APPLICATION) && $APPLICATION->GetException()) {
             $e = $APPLICATION->GetException();
             $this->LAST_ERROR .= $e->GetString();
             $APPLICATION->ResetException();
         } else {
             $this->LAST_ERROR .= "Unknown error. ";
         }
     }
     if (strlen($this->LAST_ERROR) > 0) {
         return false;
     }
     return true;
 }
Esempio n. 15
0
// Unique ID of the Image uploader on the page
if (isset($_REQUEST["view_mode"])) {
    $arParams["VIEW_MODE"] = $_REQUEST["view_mode"] == "form" ? "form" : "applet";
    CUserOptions::SetOption('photogallery', "view_mode_" . $arParams["UPLOADER_ID"], $arParams["VIEW_MODE"]);
    return LocalRedirect($arParams["ACTION_URL"]);
} else {
    $arParams["VIEW_MODE"] = CUserOptions::GetOption('photogallery', "view_mode_" . $arParams["UPLOADER_ID"], "form");
}
$arParams["VIEW_MODE"] = $arParams["VIEW_MODE"] == "form" ? "form" : "applet";
if ($arParams["USE_WATERMARK"] == "Y") {
    if (isset($_REQUEST['watermark_iframe']) && $_REQUEST['watermark_iframe'] == 'Y' && check_bitrix_sessid()) {
        $UploadError = false;
        $pathto = '';
        if ($_SERVER['REQUEST_METHOD'] == "POST") {
            $file = $_FILES['watermark_img'];
            $checkImgMsg = CFile::CheckImageFile($file);
            if ($file['error'] != 0) {
                $UploadError = "[IU_WM01] " . GetMessage("P_WM_IMG_ERROR01");
            } elseif (strlen($checkImgMsg) > 0 || $checkImgMsg === "") {
                $UploadError = "[IU_WM02] " . ($checkImgMsg === "" ? GetMessage("P_WM_IMG_ERROR02") : $checkImgMsg);
            } else {
                $imgArray = CFile::GetImageSize($file["tmp_name"]);
                if (is_array($imgArray)) {
                    $width = $imgArray[0];
                    $height = $imgArray[1];
                }
                $pathto = CTempFile::GetDirectoryName(1) . '/' . "watermark_" . md5($file["name"]) . GetFileExtension($file["name"]);
                CheckDirPath($pathto);
                $pathtoRel = substr($pathto, strlen($_SERVER["DOCUMENT_ROOT"]));
                if (!move_uploaded_file($file["tmp_name"], $pathto)) {
                    $UploadError = "[IU_WM03] " . GetMessage("P_WM_IMG_ERROR03");
Esempio n. 16
0
 if (!isset($arResult["strMessage"])) {
     $moduleId = "uf";
     $arFile = $_FILES["file"];
     $arFile["MODULE_ID"] = $moduleId;
     $ufCode = isset($arFileStorage["DISC_FOLDER"]) || isset($arFileStorage["WEBDAV_DATA"]) ? "UF_SONET_COM_DOC" : "UF_SONET_COM_FILE";
     $arPostFields = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFields("SONET_COMMENT", 0, LANGUAGE_ID);
     if (empty($arPostFields[$ufCode])) {
         $arResult["strMessage"] = "Userfield not exists";
     }
 }
 if (!isset($arResult["strMessage"])) {
     $pos = strpos($arFile["name"], '?');
     if ($pos !== false) {
         $arFile["name"] = substr($arFile["name"], 0, $pos);
     }
     $res = '' . CFile::CheckImageFile($arFile, intval($arPostFields[$ufCode]['SETTINGS']['MAX_ALLOWED_SIZE']) > 0 ? $arPostFields[$ufCode]['SETTINGS']['MAX_ALLOWED_SIZE'] : 5000000, 0, 0);
     if ($res !== '') {
         $arResult["strMessage"] = "Incorrect file";
     }
 }
 if (!isset($arResult["strMessage"])) {
     $arSaveResult = CMobileHelper::SaveFile($arFile, $arFileStorage);
     if (!$arSaveResult || !isset($arSaveResult["ID"])) {
         $arResult["strMessage"] = "Can't save file";
     }
 }
 if (!isset($arResult["strMessage"])) {
     if (isset($arFileStorage["DISC_FOLDER"])) {
         $comment_text = "[DISK FILE ID=n" . $arSaveResult["ID"] . "]";
     } elseif (isset($arFileStorage["WEBDAV_DATA"])) {
         $comment_text = "[DOCUMENT ID=" . $arSaveResult["ID"] . "]";
 foreach ($arPropertyPopup as $action => $acValue) {
     if ($action == 'CODE') {
         foreach ($arAllProperties as $key => $value) {
             if ($value["CODE"] == $acValue["CODE"]) {
                 $arReplace['#' . $acValue["CODE"] . '#'] = $arPropertySaveValues[$arAllProperties[$key]['ID']];
             }
         }
     }
 }
 $arIBlockElementAdd = array("NAME" => null, "IBLOCK_ID" => $subIBlockId, "ACTIVE" => "Y");
 if (0 >= $subPropValue) {
     $arIBlockElementAdd['TMP_ID'] = $subTmpId;
 }
 if (is_array($arImageCombinationResult) && $imageRowId !== null) {
     foreach ($arImageCombinationResult as $propertyId => $arImageType) {
         if (CFile::CheckImageFile($arImageType[$imageRowId]) == '') {
             switch ($propertyId) {
                 case 'DETAIL':
                     $arIBlockElementAdd['DETAIL_PICTURE'] = $arImageType[$imageRowId];
                     break;
                 case 'ANNOUNCE':
                     $arIBlockElementAdd['PREVIEW_PICTURE'] = $arImageType[$imageRowId];
                     break;
                 default:
                     $arPropertySaveValues[$propertyId] = $arImageType[$imageRowId];
             }
         }
     }
 }
 if (!empty($arDirProperties)) {
     foreach ($arDirProperties as $arOneConvert) {
Esempio n. 18
0
 public static function checkFields($data, $action = 'update', $throwException = false)
 {
     // 1. Способ накопления ошибок (массив?)
     // 2. во внешней авторизации пропускаются проверки, которые должны быть стандартными
     //    может передавать в checkFields параметр excludes? а может просто сделать копию data без этих полей
     if (is_set($data, "PERSONAL_PHOTO")) {
         if (strlen($data["PERSONAL_PHOTO"]["name"]) <= 0 && strlen($data["PERSONAL_PHOTO"]["del"]) <= 0) {
             unset($data["PERSONAL_PHOTO"]);
         } else {
             $result = CFile::CheckImageFile($data["PERSONAL_PHOTO"]);
             if (strlen($result) > 0) {
                 static::$errors[] = $result;
             }
         }
     }
     //		if(is_set($data, "PERSONAL_BIRTHDAY") && strlen($data["PERSONAL_BIRTHDAY"])>0 && !CheckDateTime($data["PERSONAL_BIRTHDAY"]))
     //		{
     //			static::$errors[] = GetMessage("WRONG_PERSONAL_BIRTHDAY");
     //		}
     if (is_set($data, "WORK_LOGO")) {
         if (strlen($data["WORK_LOGO"]["name"]) <= 0 && strlen($data["WORK_LOGO"]["del"]) <= 0) {
             unset($data["WORK_LOGO"]);
         } else {
             $result = CFile::CheckImageFile($data["WORK_LOGO"]);
             if (strlen($result) > 0) {
                 static::$errors[] = $result;
             }
         }
     }
     parent::checkFields($data, $action, $throwException);
 }
Esempio n. 19
0
 function CheckFields(&$arFields, $ID = false, $bCheckDiskQuota = true)
 {
     global $DB, $APPLICATION, $USER;
     $this->LAST_ERROR = "";
     $APPLICATION->ResetException();
     if ($ID === false) {
         $db_events = GetModuleEvents("iblock", "OnStartIBlockElementAdd", true);
     } else {
         $arFields["ID"] = $ID;
         $db_events = GetModuleEvents("iblock", "OnStartIBlockElementUpdate", true);
     }
     foreach ($db_events as $arEvent) {
         $bEventRes = ExecuteModuleEventEx($arEvent, array(&$arFields));
         if ($bEventRes === false) {
             break;
         }
     }
     if (($ID === false || is_set($arFields, "NAME")) && strlen($arFields["NAME"]) <= 0) {
         $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_ELEMENT_NAME") . "<br>";
     }
     if (isset($arFields["ACTIVE_FROM"]) && $arFields["ACTIVE_FROM"] != '' && !$DB->IsDate($arFields["ACTIVE_FROM"], false, LANG, "FULL")) {
         $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_ACTIVE_FROM") . "<br>";
     }
     if (isset($arFields["ACTIVE_TO"]) && $arFields["ACTIVE_TO"] != '' && !$DB->IsDate($arFields["ACTIVE_TO"], false, LANG, "FULL")) {
         $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_ACTIVE_TO") . "<br>";
     }
     if (is_set($arFields, "PREVIEW_PICTURE")) {
         if (is_array($arFields["PREVIEW_PICTURE"]) && array_key_exists("bucket", $arFields["PREVIEW_PICTURE"]) && is_object($arFields["PREVIEW_PICTURE"]["bucket"])) {
             //This is trusted image from xml import
         } elseif (is_array($arFields["PREVIEW_PICTURE"])) {
             $error = CFile::CheckImageFile($arFields["PREVIEW_PICTURE"]);
             if (strlen($error) > 0) {
                 $this->LAST_ERROR .= $error . "<br>";
             } elseif (($error = CFile::checkForDb($arFields, "PREVIEW_PICTURE")) !== "") {
                 $this->LAST_ERROR .= GetMessage("IBLOCK_ERR_PREVIEW_PICTURE") . "<br>" . $error . "<br>";
             }
         } elseif (intval($arFields["PREVIEW_PICTURE"]) > 0) {
             if (intval($arFields["WF_PARENT_ELEMENT_ID"]) <= 0 || CIBlockElement::DeleteFile($arFields["PREVIEW_PICTURE"], $ID, "PREVIEW", intval($arFields["WF_PARENT_ELEMENT_ID"]), $arFields["IBLOCK_ID"], true) <= 0) {
                 $this->LAST_ERROR .= GetMessage("IBLOCK_ERR_PREVIEW_PICTURE") . "<br>";
             }
         }
     }
     if (is_set($arFields, "DETAIL_PICTURE")) {
         if (is_array($arFields["DETAIL_PICTURE"]) && array_key_exists("bucket", $arFields["DETAIL_PICTURE"]) && is_object($arFields["DETAIL_PICTURE"]["bucket"])) {
             //This is trusted image from xml import
         } elseif (is_array($arFields["DETAIL_PICTURE"])) {
             $error = CFile::CheckImageFile($arFields["DETAIL_PICTURE"]);
             if (strlen($error) > 0) {
                 $this->LAST_ERROR .= $error . "<br>";
             } elseif (($error = CFile::checkForDb($arFields, "DETAIL_PICTURE")) !== "") {
                 $this->LAST_ERROR .= GetMessage("IBLOCK_ERR_DETAIL_PICTURE") . "<br>" . $error . "<br>";
             }
         } elseif (intval($arFields["DETAIL_PICTURE"]) > 0) {
             if (intval($arFields["WF_PARENT_ELEMENT_ID"]) <= 0 || CIBlockElement::DeleteFile($arFields["DETAIL_PICTURE"], $ID, "DETAIL", intval($arFields["WF_PARENT_ELEMENT_ID"]), $arFields["IBLOCK_ID"], true) <= 0) {
                 $this->LAST_ERROR .= GetMessage("IBLOCK_ERR_DETAIL_PICTURE") . "<br>";
             }
         }
     }
     if (array_key_exists("TAGS", $arFields) && CModule::IncludeModule('search')) {
         $arFields["TAGS"] = implode(", ", tags_prepare($arFields["TAGS"]));
     }
     if ($ID === false && !is_set($arFields, "IBLOCK_ID")) {
         $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_BLOCK_ID") . "<br>";
     }
     if ($ID !== false && is_set($arFields, "XML_ID") && strlen($arFields["XML_ID"]) <= 0) {
         $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_EXTERNAL_CODE") . "<br>";
     }
     //Find out IBLOCK_ID from fields or from element
     $IBLOCK_ID = intval($arFields["IBLOCK_ID"]);
     if ($IBLOCK_ID <= 0) {
         $IBLOCK_ID = 0;
         $res = $DB->Query("SELECT IBLOCK_ID FROM b_iblock_element WHERE ID=" . IntVal($ID));
         if ($ar = $res->Fetch()) {
             $IBLOCK_ID = (int) $ar["IBLOCK_ID"];
         }
     }
     //Read iblock metadata
     static $IBLOCK_CACHE = array();
     if (!isset($IBLOCK_CACHE[$IBLOCK_ID])) {
         if ($IBLOCK_ID > 0) {
             $IBLOCK_CACHE[$IBLOCK_ID] = CIBlock::GetArrayByID($IBLOCK_ID);
         } else {
             $IBLOCK_CACHE[$IBLOCK_ID] = false;
         }
     }
     if ($IBLOCK_CACHE[$IBLOCK_ID]) {
         $arFields["IBLOCK_ID"] = $IBLOCK_ID;
     } else {
         $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_BLOCK_ID") . "<br>";
     }
     if (is_set($arFields, 'IBLOCK_SECTION') && !empty($arFields['IBLOCK_SECTION'])) {
         if (!is_array($arFields['IBLOCK_SECTION'])) {
             $arFields['IBLOCK_SECTION'] = array($arFields['IBLOCK_SECTION']);
         }
         $arFields['IBLOCK_SECTION'] = array_filter($arFields['IBLOCK_SECTION']);
     }
     if ($IBLOCK_CACHE[$IBLOCK_ID]) {
         $ar = $IBLOCK_CACHE[$IBLOCK_ID]["FIELDS"];
         if (is_array($ar)) {
             $WF_PARENT_ELEMENT_ID = isset($arFields["WF_PARENT_ELEMENT_ID"]) ? intval($arFields["WF_PARENT_ELEMENT_ID"]) : 0;
             if (($WF_PARENT_ELEMENT_ID == 0 || $WF_PARENT_ELEMENT_ID == intval($ID)) && array_key_exists("CODE", $arFields) && strlen($arFields["CODE"]) > 0 && is_array($ar["CODE"]["DEFAULT_VALUE"]) && $ar["CODE"]["DEFAULT_VALUE"]["UNIQUE"] == "Y") {
                 $res = $DB->Query("\n\t\t\t\t\t\tSELECT ID\n\t\t\t\t\t\tFROM b_iblock_element\n\t\t\t\t\t\tWHERE IBLOCK_ID = " . $IBLOCK_ID . "\n\t\t\t\t\t\tAND CODE = '" . $DB->ForSQL($arFields["CODE"]) . "'\n\t\t\t\t\t\tAND WF_PARENT_ELEMENT_ID IS NULL\n\t\t\t\t\t\tAND ID <> " . intval($ID));
                 if ($res->Fetch()) {
                     $this->LAST_ERROR .= GetMessage("IBLOCK_DUP_ELEMENT_CODE") . "<br>";
                 }
             }
             $arOldElement = false;
             foreach ($ar as $FIELD_ID => $field) {
                 if (preg_match("/^(SECTION_|LOG_)/", $FIELD_ID)) {
                     continue;
                 }
                 if ($field["IS_REQUIRED"] === "Y") {
                     switch ($FIELD_ID) {
                         case "NAME":
                         case "ACTIVE":
                         case "PREVIEW_TEXT_TYPE":
                         case "DETAIL_TEXT_TYPE":
                         case "SORT":
                             //We should never check for this fields
                             break;
                         case "IBLOCK_SECTION":
                             if ($ID === false || array_key_exists($FIELD_ID, $arFields)) {
                                 $sum = 0;
                                 if (is_array($arFields[$FIELD_ID])) {
                                     foreach ($arFields[$FIELD_ID] as $k => $v) {
                                         if (intval($v) > 0) {
                                             $sum += intval($v);
                                         }
                                     }
                                 } else {
                                     $sum = intval($arFields[$FIELD_ID]);
                                 }
                                 if ($sum <= 0) {
                                     $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_FIELD", array("#FIELD_NAME#" => $field["NAME"])) . "<br>";
                                 }
                             }
                             break;
                         case "PREVIEW_PICTURE":
                         case "DETAIL_PICTURE":
                             if ($ID !== false && !$arOldElement) {
                                 $rs = $DB->Query("SELECT PREVIEW_PICTURE, DETAIL_PICTURE from b_iblock_element WHERE ID = " . intval($ID));
                                 $arOldElement = $rs->Fetch();
                             }
                             if ($arOldElement && $arOldElement[$FIELD_ID] > 0) {
                                 //There was an picture so just check that it is not deleted
                                 if (array_key_exists($FIELD_ID, $arFields) && is_array($arFields[$FIELD_ID]) && $arFields[$FIELD_ID]["del"] === "Y") {
                                     $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_FIELD", array("#FIELD_NAME#" => $field["NAME"])) . "<br>";
                                 }
                             } else {
                                 //There was NO picture so it MUST be present
                                 if (!array_key_exists($FIELD_ID, $arFields)) {
                                     $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_FIELD", array("#FIELD_NAME#" => $field["NAME"])) . "<br>";
                                 } elseif (is_array($arFields[$FIELD_ID])) {
                                     if ($arFields[$FIELD_ID]["del"] === "Y" || array_key_exists("error", $arFields[$FIELD_ID]) && $arFields[$FIELD_ID]["error"] !== 0 || $arFields[$FIELD_ID]["size"] <= 0) {
                                         $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_FIELD", array("#FIELD_NAME#" => $field["NAME"])) . "<br>";
                                     }
                                 } else {
                                     if (intval($arFields[$FIELD_ID]) <= 0) {
                                         $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_FIELD", array("#FIELD_NAME#" => $field["NAME"])) . "<br>";
                                     }
                                 }
                             }
                             break;
                         default:
                             if ($ID === false || array_key_exists($FIELD_ID, $arFields)) {
                                 if (is_array($arFields[$FIELD_ID])) {
                                     $val = implode("", $arFields[$FIELD_ID]);
                                 } else {
                                     $val = $arFields[$FIELD_ID];
                                 }
                                 if (strlen($val) <= 0) {
                                     $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_FIELD", array("#FIELD_NAME#" => $field["NAME"])) . "<br>";
                                 }
                             }
                             break;
                     }
                 }
             }
         }
     }
     if (array_key_exists("PROPERTY_VALUES", $arFields) && is_array($arFields["PROPERTY_VALUES"])) {
         //First "normalize" properties to form:
         //$arFields["PROPERTY_VALUES"][<PROPERTY_ID>][<PROPERTY_VALUE_ID>] => $value
         $arProperties = array();
         foreach ($arFields["PROPERTY_VALUES"] as $key => $property_values) {
             $arProperties[$key] = array();
             if (is_array($property_values)) {
                 if (array_key_exists("VALUE", $property_values)) {
                     $arProperties[$key][] = $property_values["VALUE"];
                 } elseif (array_key_exists("tmp_name", $property_values)) {
                     $arProperties[$key][] = $property_values;
                 } else {
                     foreach ($property_values as $key2 => $property_value) {
                         if (is_array($property_value) && array_key_exists("VALUE", $property_value)) {
                             //each of these may be "complex"
                             $arProperties[$key][] = $property_value["VALUE"];
                         } else {
                             //or simple
                             $arProperties[$key][] = $property_value;
                         }
                     }
                 }
             } else {
                 $arProperties[$key][] = $property_values;
             }
         }
         foreach ($arProperties as $key => $property_values) {
             $arProperty = CIBlockProperty::GetPropertyArray($key, $IBLOCK_ID);
             if ($arProperty["USER_TYPE"] != "") {
                 $arUserType = CIBlockProperty::GetUserType($arProperty["USER_TYPE"]);
             } else {
                 $arUserType = array();
             }
             if (array_key_exists("CheckFields", $arUserType)) {
                 foreach ($property_values as $key2 => $property_value) {
                     $arError = call_user_func_array($arUserType["CheckFields"], array($arProperty, array("VALUE" => $property_value)));
                     if (is_array($arError)) {
                         foreach ($arError as $err_mess) {
                             $this->LAST_ERROR .= $err_mess . "<br>";
                         }
                     }
                 }
             }
             //Files check
             $bError = false;
             if ($arProperty["IS_REQUIRED"] == "Y" && $arProperty['PROPERTY_TYPE'] == 'F') {
                 //New element
                 if ($ID === false) {
                     $bError = true;
                     foreach ($property_values as $key2 => $property_value) {
                         if (is_array($property_value) && array_key_exists("tmp_name", $property_value) && array_key_exists("size", $property_value)) {
                             if ($property_value['size'] > 0) {
                                 $bError = false;
                                 break;
                             }
                         } elseif (intval($property_value) > 0) {
                             //This is history copy of the file
                             $bError = false;
                             break;
                         }
                     }
                 } else {
                     $dbProperty = CIBlockElement::GetProperty($arProperty["IBLOCK_ID"], $ID, "sort", "asc", array("ID" => $arProperty["ORIG_ID"], "EMPTY" => "N"));
                     $bCount = 0;
                     while ($a = $dbProperty->Fetch()) {
                         if ($a["VALUE"] > 0) {
                             $bCount++;
                         }
                     }
                     foreach ($property_values as $key2 => $property_value) {
                         if (is_array($property_value)) {
                             if ($property_value['size'] > 0) {
                                 $bCount++;
                                 break;
                             } elseif ($property_value['del'] == 'Y') {
                                 $bCount--;
                             }
                         } elseif (intval($property_value) > 0) {
                             //This is history copy of the file
                             $bCount++;
                             break;
                         }
                     }
                     $bError = $bCount <= 0;
                 }
             }
             if ($arProperty["IS_REQUIRED"] == "Y" && $arProperty['PROPERTY_TYPE'] != 'F') {
                 $len = 0;
                 foreach ($property_values as $key2 => $property_value) {
                     if (array_key_exists("GetLength", $arUserType)) {
                         $len += call_user_func_array($arUserType["GetLength"], array($arProperty, array("VALUE" => $property_value)));
                     } else {
                         $len += strlen($property_value);
                     }
                     if ($len > 0) {
                         break;
                     }
                 }
                 $bError = $len <= 0;
             }
             if ($bError) {
                 $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_PROPERTY", array("#PROPERTY#" => $arProperty["NAME"])) . "<br>";
             }
             // check file properties for correctness
             if ($arProperty['PROPERTY_TYPE'] == 'F') {
                 $bImageOnly = False;
                 $arImageExtentions = explode(",", strtoupper(CFile::GetImageExtensions()));
                 if (strlen($arProperty["FILE_TYPE"])) {
                     $bImageOnly = True;
                     $arAvailTypes = explode(",", strtoupper($arProperty["FILE_TYPE"]));
                     foreach ($arAvailTypes as $avail_type) {
                         if (!in_array(trim($avail_type), $arImageExtentions)) {
                             $bImageOnly = False;
                             break;
                         }
                     }
                 }
                 foreach ($property_values as $key2 => $property_value) {
                     if (!is_array($property_value) && intval($property_value) > 0 && intval($arFields["WF_PARENT_ELEMENT_ID"]) > 0) {
                         if (CIBlockElement::DeleteFile($property_value, $ID, "PROPERTY", intval($arFields["WF_PARENT_ELEMENT_ID"]), $arFields["IBLOCK_ID"], true) <= 0) {
                             $this->LAST_ERROR .= GetMessage("IBLOCK_ERR_FILE_PROPERTY") . "<br>";
                         }
                     } elseif (is_array($property_value)) {
                         if (is_object($property_value["bucket"])) {
                             //This is trusted image from xml import
                             $error = "";
                         } else {
                             if ($bImageOnly) {
                                 $error = CFile::CheckImageFile($property_value);
                             } else {
                                 $error = CFile::CheckFile($property_value, 0, false, $arProperty["FILE_TYPE"]);
                             }
                         }
                         //For user without edit php permissions
                         //we allow only pictures upload
                         if (!is_object($USER) || !$USER->IsAdmin()) {
                             if (HasScriptExtension($property_value["name"])) {
                                 $error = GetMessage("FILE_BAD_TYPE") . " (" . $property_value["name"] . ").";
                             }
                         }
                         if (strlen($error) > 0) {
                             $this->LAST_ERROR .= $error . "<br>";
                         }
                     }
                 }
             }
         }
     }
     $APPLICATION->ResetException();
     if ($ID === false) {
         $db_events = GetModuleEvents("iblock", "OnBeforeIBlockElementAdd", true);
     } else {
         $arFields["ID"] = $ID;
         $db_events = GetModuleEvents("iblock", "OnBeforeIBlockElementUpdate", true);
     }
     foreach ($db_events as $arEvent) {
         $bEventRes = ExecuteModuleEventEx($arEvent, array(&$arFields));
         if ($bEventRes === false) {
             if ($err = $APPLICATION->GetException()) {
                 $this->LAST_ERROR .= $err->GetString() . "<br>";
             } else {
                 $APPLICATION->ThrowException("Unknown error");
                 $this->LAST_ERROR .= "Unknown error.<br>";
             }
             break;
         }
     }
     /****************************** QUOTA ******************************/
     if ($bCheckDiskQuota && empty($this->LAST_ERROR) && COption::GetOptionInt("main", "disk_space") > 0) {
         $quota = new CDiskQuota();
         if (!$quota->checkDiskQuota($arFields)) {
             $this->LAST_ERROR = $quota->LAST_ERROR;
         }
     }
     /****************************** QUOTA ******************************/
     if (!empty($this->LAST_ERROR)) {
         return false;
     }
     return true;
 }
Esempio n. 20
0
						} else {
							$objE = CIBlockElement::GetList(array(), array('IBLOCK_ID' => $intBlockID, 'ID' => $intAdvertID, 'SECTION_ID' => $intRootSection, 'INCLUDE_SUBSECTIONS' => 'Y', 'ACTIVE' => 'Y'));
							if ($arrAdvert = $objE->GetNext()) {
								$arrPhoto = CFile::ResizeImageGet($arrAdvert[$arrField[$strNameField]], array('width' => 100, 'height' => 100), BX_RESIZE_IMAGE_EXACT, true);
								$arrResult['src'] = $arrPhoto['src'];
							}
						}//\\ if
					}//\\ if
				}//\\ if
			} elseif(isset($arrFieldProp[$strNameField])) {
				if ($_REQUEST['action'] == 'upload') {
					// Сохраним файл
					$arrFile = $_FILES[$strNameField];
					$arrFile['MODULE_ID'] = 'iblock';

					$res = CFile::CheckImageFile($arrFile, 20971520, 4000, 4000);
					if (strlen($res)) {
						$arrResult['error'] = $res;
						$arrResult['result'] = 'fail';
					} else {
						if (count($arrAdvert[$arrFieldProp[$strNameField]]) >=5) {
							$arrResult['result'] = 'fail';
							$arrResult['error'] = 'Максимальное количество фотографий - 5 шт.';
						} else {
							if ($strTypeBlock == 'A') {
								// Это свойство объявления
								CIBlockElement::SetPropertyValueCode($intAdvertID, $arrFieldProp[$strNameField], array('VALUE' => $arrFile));
								
								// Получим заново свойство
								$arrAdvert[$arrFieldProp[$strNameField]] = array();
								//$arrFileNew = array();
Esempio n. 21
0
 function CheckFields($arFields, $BANNER_ID, $CHECK_RIGHTS = "Y")
 {
     global $strError;
     $str = "";
     if ($CHECK_RIGHTS == "Y") {
         $isAdmin = CAdvContract::IsAdmin();
         $isManager = CAdvContract::IsManager();
     } else {
         $isAdmin = true;
         $isManager = true;
     }
     $arrKeys = array_keys($arFields);
     if (!in_array("CONTRACT_ID", $arrKeys) && $BANNER_ID > 0) {
         $rsBanner = CAdvBanner::GetByID($BANNER_ID, "N");
         $arBanner = $rsBanner->Fetch();
         $CONTRACT_ID = intval($arBanner["CONTRACT_ID"]);
     } else {
         $CONTRACT_ID = intval($arFields["CONTRACT_ID"]);
     }
     if ($CONTRACT_ID > 0) {
         $access = false;
         if ($isAdmin || $isManager) {
             $access = true;
         } else {
             $arrPERM = CAdvContract::GetUserPermissions($CONTRACT_ID);
             $arrPERM = $arrPERM[$CONTRACT_ID];
             if (in_array("ADD", $arrPERM)) {
                 $access = true;
             }
         }
         if ($access) {
             if (strlen($arFields["DATE_SHOW_FROM"]) > 0) {
                 if (!CheckDateTime($arFields["DATE_SHOW_FROM"])) {
                     $str .= GetMessage("AD_ERROR_WRONG_DATE_SHOW_FROM_BANNER") . "<br>";
                 }
             }
             if (strlen($arFields["DATE_SHOW_TO"]) > 0) {
                 if (!CheckDateTime($arFields["DATE_SHOW_TO"])) {
                     $str .= GetMessage("AD_ERROR_WRONG_DATE_SHOW_TO_BANNER") . "<br>";
                 }
             }
             if (in_array("arrIMAGE_ID", $arrKeys)) {
                 $arIMAGE = $arFields["arrIMAGE_ID"];
                 $arIMAGE["MODULE_ID"] = "advertising";
                 $strRes = CFile::CheckImageFile($arIMAGE, 0, 0, 0, array("FLASH", "IMAGE"));
                 if (strlen($strRes) > 0) {
                     $str .= $strRes . "<br>";
                 }
             }
             if (in_array("arrFlashIMAGE_ID", $arrKeys)) {
                 $arIMAGE = $arFields["arrFlashIMAGE_ID"];
                 $arIMAGE["MODULE_ID"] = "advertising";
                 $strRes = CFile::CheckImageFile($arIMAGE, 0, 0, 0, array("IMAGE"));
                 if (strlen($strRes) > 0) {
                     $str .= $strRes . "<br>";
                 }
             }
             if ($arFields["FLYUNIFORM"] == "Y") {
                 if (strlen($arFields["DATE_SHOW_FROM"]) <= 0 or strlen($arFields["DATE_SHOW_TO"]) <= 0) {
                     $str .= GetMessage("AD_ERROR_FROMTO_DATE_HAVETOBE_SET") . "<br>";
                 }
                 if ($arFields["FIX_SHOW"] != "Y") {
                     $str .= GetMessage("AD_ERROR_FIXSHOW_HAVETOBE_SET") . "<br>";
                 }
                 if (intval($arFields["MAX_SHOW_COUNT"]) <= 0) {
                     $str .= GetMessage("AD_ERROR_MAX_SHOW_COUNT_HAVETOBE_SET") . "<br>";
                 }
             }
         } else {
             if ($BANNER_ID > 0) {
                 $str .= GetMessage("AD_ERROR_NOT_ENOUGH_PERMISSIONS_BANNER") . "<br>";
             } else {
                 $str .= GetMessage("AD_ERROR_NOT_ENOUGH_PERMISSIONS_CONTRACT") . "<br>";
             }
         }
     } else {
         $str .= GetMessage("AD_ERROR_INCORRECT_CONTRACT_ID") . "<br>";
     }
     $strError .= $str;
     if (strlen($str) > 0) {
         return false;
     } else {
         return true;
     }
 }
Esempio n. 22
0
 function OnCommentAdd($entityType, $entityID, &$arPost)
 {
     global $USER;
     $arParams =& $this->component->arParams;
     $arResult =& $this->component->arResult;
     $iFileSize = intval(COption::GetOptionString("forum", "file_max_size", 5242880));
     $_REQUEST['FILE_NEW'] = isset($_REQUEST['FILE_NEW']) && is_array($_REQUEST['FILE_NEW']) ? $_REQUEST['FILE_NEW'] : array();
     $arPost["FILES"] = array();
     foreach ($_REQUEST['FILE_NEW'] as $fileID) {
         $arPost["FILES"][$fileID] = array("FILE_ID" => $fileID);
         $attach_file = CFile::MakeFileArray(intval($fileID));
         $attach = "";
         if ($attach_file && is_set($attach_file, "name")) {
             if ($arParams["ALLOW_UPLOAD"] == "Y") {
                 $attach = CFile::CheckImageFile($attach_file, $iFileSize, 0, 0);
             } elseif ($arParams["ALLOW_UPLOAD"] == "F") {
                 $attach = CFile::CheckFile($attach_file, $iFileSize, false, $arParams["ALLOW_UPLOAD_EXT"]);
             } elseif ($arParams["ALLOW_UPLOAD"] == "A") {
                 $attach = CFile::CheckFile($attach_file, $iFileSize, false, false);
             }
             if ($attach != '') {
                 unset($arPost['FILES'][$fileID]);
                 $arPost['ERROR'] = $attach_file['name'] . ': ' . $attach;
                 return false;
             }
         }
     }
     return true;
 }
Esempio n. 23
0
 function CheckFields($arFields, $FORM_ID, $CHECK_RIGHTS = "Y")
 {
     $err_mess = CAllForm::err_mess() . "<br>Function: CheckFields<br>Line: ";
     global $DB, $strError, $APPLICATION, $USER;
     $str = "";
     $FORM_ID = intval($FORM_ID);
     $RIGHT_OK = "N";
     if ($CHECK_RIGHTS != "Y" || CForm::IsAdmin()) {
         $RIGHT_OK = "Y";
     } else {
         if ($FORM_ID > 0) {
             $F_RIGHT = CForm::GetPermission($FORM_ID);
             if ($F_RIGHT >= 30) {
                 $RIGHT_OK = "Y";
             }
         }
     }
     if ($RIGHT_OK == "Y") {
         if (strlen($arFields["SID"]) > 0) {
             $arFields["VARNAME"] = $arFields["SID"];
         } elseif (strlen($arFields["VARNAME"]) > 0) {
             $arFields["SID"] = $arFields["VARNAME"];
         }
         if ($FORM_ID <= 0 || $FORM_ID > 0 && is_set($arFields, "NAME")) {
             if (strlen(trim($arFields["NAME"])) <= 0) {
                 $str .= GetMessage("FORM_ERROR_FORGOT_NAME") . "<br>";
             }
         }
         if ($FORM_ID <= 0 || $FORM_ID > 0 && is_set($arFields, "SID")) {
             if (strlen(trim($arFields["SID"])) <= 0) {
                 $str .= GetMessage("FORM_ERROR_FORGOT_SID") . "<br>";
             }
             if (preg_match("/[^A-Za-z_01-9]/", $arFields["SID"])) {
                 $str .= GetMessage("FORM_ERROR_INCORRECT_SID") . "<br>";
             } else {
                 $strSql = "SELECT ID FROM b_form WHERE SID='" . $DB->ForSql(trim($arFields["SID"]), 50) . "' and ID<>'{$FORM_ID}'";
                 $z = $DB->Query($strSql, false, $err_mess . __LINE__);
                 if ($zr = $z->Fetch()) {
                     $s = str_replace("#TYPE#", GetMessage("FORM_TYPE_FORM"), GetMessage("FORM_ERROR_WRONG_SID"));
                     $s = str_replace("#ID#", $zr["ID"], $s);
                     $str .= $s . "<br>";
                 } else {
                     $strSql = "SELECT ID, ADDITIONAL FROM b_form_field WHERE SID='" . $DB->ForSql(trim($arFields["SID"]), 50) . "'";
                     $z = $DB->Query($strSql, false, $err_mess . __LINE__);
                     if ($zr = $z->Fetch()) {
                         $s = $zr["ADDITIONAL"] == "Y" ? str_replace("#TYPE#", GetMessage("FORM_TYPE_FIELD"), GetMessage("FORM_ERROR_WRONG_SID")) : str_replace("#TYPE#", GetMessage("FORM_TYPE_QUESTION"), GetMessage("FORM_ERROR_WRONG_SID"));
                         $s = str_replace("#ID#", $zr["ID"], $s);
                         $str .= $s . "<br>";
                     }
                 }
             }
         }
         $str .= CFile::CheckImageFile($arFields["arIMAGE"]);
     } else {
         $str .= GetMessage("FORM_ERROR_ACCESS_DENIED");
     }
     $strError .= $str;
     if (strlen($str) > 0) {
         return false;
     } else {
         return true;
     }
 }
Esempio n. 24
0
 function CheckFields($ACTION, &$arFields, $ID = 0)
 {
     global $DB, $arSocNetAllowedInitiatePerms, $arSocNetAllowedSpamPerms;
     if ($ACTION != "ADD" && IntVal($ID) <= 0) {
         $GLOBALS["APPLICATION"]->ThrowException("System error 870164", "ERROR");
         return false;
     }
     if ($ID === 0 && !is_set($arFields, "SITE_ID") || is_set($arFields, "SITE_ID") && (is_array($arFields["SITE_ID"]) && count($arFields["SITE_ID"]) <= 0 || !is_array($arFields["SITE_ID"]) && strlen($arFields["SITE_ID"]) <= 0)) {
         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("SONET_GG_EMPTY_SITE_ID"), "EMPTY_SITE_ID");
         return false;
     } elseif (is_set($arFields, "SITE_ID")) {
         if (!is_array($arFields["SITE_ID"])) {
             $arFields["SITE_ID"] = array($arFields["SITE_ID"]);
         }
         foreach ($arFields["SITE_ID"] as $v) {
             $r = CSite::GetByID($v);
             if (!$r->Fetch()) {
                 $GLOBALS["APPLICATION"]->ThrowException(str_replace("#ID#", $v, GetMessage("SONET_GG_ERROR_NO_SITE")), "ERROR_NO_SITE");
                 return false;
             }
         }
     }
     if ((is_set($arFields, "NAME") || $ACTION == "ADD") && strlen($arFields["NAME"]) <= 0) {
         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("SONET_GB_EMPTY_NAME"), "EMPTY_NAME");
         return false;
     }
     if (is_set($arFields, "DATE_CREATE") && !$DB->IsDate($arFields["DATE_CREATE"], false, LANG, "FULL")) {
         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("SONET_GB_EMPTY_DATE_CREATE"), "EMPTY_DATE_CREATE");
         return false;
     }
     if (is_set($arFields, "DATE_UPDATE") && !$DB->IsDate($arFields["DATE_UPDATE"], false, LANG, "FULL")) {
         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("SONET_GB_EMPTY_DATE_UPDATE"), "EMPTY_DATE_UPDATE");
         return false;
     }
     if (is_set($arFields, "DATE_ACTIVITY") && !$DB->IsDate($arFields["DATE_ACTIVITY"], false, LANG, "FULL")) {
         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("SONET_GB_EMPTY_DATE_ACTIVITY"), "EMPTY_DATE_ACTIVITY");
         return false;
     }
     if ((is_set($arFields, "OWNER_ID") || $ACTION == "ADD") && IntVal($arFields["OWNER_ID"]) <= 0) {
         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("SONET_GB_EMPTY_OWNER_ID"), "EMPTY_OWNER_ID");
         return false;
     } elseif (is_set($arFields, "OWNER_ID")) {
         $dbResult = CUser::GetByID($arFields["OWNER_ID"]);
         if (!$dbResult->Fetch()) {
             $GLOBALS["APPLICATION"]->ThrowException(GetMessage("SONET_GB_ERROR_NO_OWNER_ID"), "ERROR_NO_OWNER_ID");
             return false;
         }
     }
     if ((is_set($arFields, "SUBJECT_ID") || $ACTION == "ADD") && IntVal($arFields["SUBJECT_ID"]) <= 0) {
         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("SONET_GB_EMPTY_SUBJECT_ID"), "EMPTY_SUBJECT_ID");
         return false;
     } elseif (is_set($arFields, "SUBJECT_ID")) {
         $arResult = CSocNetGroupSubject::GetByID($arFields["SUBJECT_ID"]);
         if ($arResult == false) {
             $GLOBALS["APPLICATION"]->ThrowException(GetMessage("SONET_GB_ERROR_NO_SUBJECT_ID"), "ERROR_NO_SUBJECT_ID");
             return false;
         }
     }
     if ((is_set($arFields, "ACTIVE") || $ACTION == "ADD") && $arFields["ACTIVE"] != "Y" && $arFields["ACTIVE"] != "N") {
         $arFields["ACTIVE"] = "Y";
     }
     if ((is_set($arFields, "VISIBLE") || $ACTION == "ADD") && $arFields["VISIBLE"] != "Y" && $arFields["VISIBLE"] != "N") {
         $arFields["VISIBLE"] = "Y";
     }
     if ((is_set($arFields, "OPENED") || $ACTION == "ADD") && $arFields["OPENED"] != "Y" && $arFields["OPENED"] != "N") {
         $arFields["OPENED"] = "N";
     }
     if ((is_set($arFields, "CLOSED") || $ACTION == "ADD") && $arFields["CLOSED"] != "Y" && $arFields["CLOSED"] != "N") {
         $arFields["CLOSED"] = "N";
     }
     if ((is_set($arFields, "INITIATE_PERMS") || $ACTION == "ADD") && strlen($arFields["INITIATE_PERMS"]) <= 0) {
         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("SONET_UG_EMPTY_INITIATE_PERMS"), "EMPTY_INITIATE_PERMS");
         return false;
     } elseif (is_set($arFields, "INITIATE_PERMS") && !in_array($arFields["INITIATE_PERMS"], $arSocNetAllowedInitiatePerms)) {
         $GLOBALS["APPLICATION"]->ThrowException(str_replace("#ID#", $arFields["INITIATE_PERMS"], GetMessage("SONET_UG_ERROR_NO_INITIATE_PERMS")), "ERROR_NO_INITIATE_PERMS");
         return false;
     }
     if ((is_set($arFields, "SPAM_PERMS") || $ACTION == "ADD") && strlen($arFields["SPAM_PERMS"]) <= 0) {
         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("SONET_UG_EMPTY_SPAM_PERMS"), "EMPTY_SPAM_PERMS");
         return false;
     } elseif (is_set($arFields, "SPAM_PERMS") && !in_array($arFields["SPAM_PERMS"], $arSocNetAllowedSpamPerms)) {
         $GLOBALS["APPLICATION"]->ThrowException(str_replace("#ID#", $arFields["SPAM_PERMS"], GetMessage("SONET_UG_ERROR_NO_SPAM_PERMS")), "ERROR_NO_SPAM_PERMS");
         return false;
     }
     if (is_set($arFields, "IMAGE_ID") && strlen($arFields["IMAGE_ID"]["name"]) <= 0 && (strlen($arFields["IMAGE_ID"]["del"]) <= 0 || $arFields["IMAGE_ID"]["del"] != "Y")) {
         unset($arFields["IMAGE_ID"]);
     }
     if (is_set($arFields, "IMAGE_ID")) {
         $arResult = CFile::CheckImageFile($arFields["IMAGE_ID"], 0, 0, 0);
         if (strlen($arResult) > 0) {
             $GLOBALS["APPLICATION"]->ThrowException(GetMessage("SONET_GP_ERROR_IMAGE_ID") . ": " . $arResult, "ERROR_IMAGE_ID");
             return false;
         }
     }
     if (!$GLOBALS["USER_FIELD_MANAGER"]->CheckFields("SONET_GROUP", $ID, $arFields)) {
         return false;
     }
     return True;
 }
Esempio n. 25
0
 function OnCommentAdd($entityType, $entityID, &$arPost)
 {
     global $USER;
     $arParams =& $this->component->arParams;
     $arResult =& $this->component->arResult;
     $arForum =& $arResult['FORUM'];
     $iFileSize = intval(COption::GetOptionString("forum", "file_max_size", 50000));
     $arCommentParams = array("FORUM_ID" => $arParams["FORUM_ID"], "TOPIC_ID" => null, "USER_ID" => $USER->IsAuthorized() ? $USER->GetID() : null);
     $arFiles = $arNewFiles = array();
     if (isset($_REQUEST['FILE_NEW']) && is_array($_REQUEST['FILE_NEW'])) {
         foreach ($_REQUEST['FILE_NEW'] as $val) {
             $arNewFiles[$val] = array("FILE_ID" => $val);
         }
     }
     if (isset($_REQUEST['FILES']) && is_array($_REQUEST['FILES'])) {
         foreach ($_REQUEST['FILES'] as $val) {
             if (in_array($val, $_REQUEST["FILES_TO_UPLOAD"])) {
                 $arFiles[$val] = array("FILE_ID" => $val);
             }
         }
     }
     if (!empty($arNewFiles)) {
         CForumFiles::Add(array_keys($arNewFiles), $arCommentParams);
     }
     $arFiles = $arFiles + $arNewFiles;
     if (!isset($arPost['FILES'])) {
         $arPost['FILES'] = array();
     }
     $arPost['FILES'] = array_merge($arPost['FILES'], $arFiles);
     foreach ($arPost['FILES'] as $fileIndex => $fileArr) {
         $fileID = $fileArr['FILE_ID'];
         $attach_file = CFile::MakeFileArray(intval($fileID));
         $attach = "";
         if ($attach_file && is_set($attach_file, "name")) {
             // Y - Image files		F - Files of specified type		A - All files
             if ($arForum["ALLOW_UPLOAD"] == "Y") {
                 $attach = CFile::CheckImageFile($attach_file, $iFileSize, 0, 0);
             } elseif ($arForum["ALLOW_UPLOAD"] == "F") {
                 $attach = CFile::CheckFile($attach_file, $iFileSize, false, $arForum["ALLOW_UPLOAD_EXT"]);
             } elseif ($arForum["ALLOW_UPLOAD"] == "A") {
                 $attach = CFile::CheckFile($attach_file, $iFileSize, false, false);
             }
             if ($attach != '') {
                 unset($arPost['FILES'][$fileIndex]);
                 $arPost['ERROR'] = $attach_file['name'] . ': ' . $attach;
                 return false;
             }
         }
     }
 }
Esempio n. 26
0
			$mid = 'main';
		for($i = 0; $i < $count; $i++)
		{
			$fileName = CUtil::ConvertToLangCharset($_FILES["mfi_files"]["name"][$i]);
			$arFile = array(
				"name" => $fileName,
				"size" => $_FILES["mfi_files"]["size"][$i],
				"tmp_name" => $_FILES["mfi_files"]["tmp_name"][$i],
				"type" => $_FILES["mfi_files"]["type"][$i],
				"MODULE_ID" => $mid
			);

			$res = '';

			if ($arParams["ALLOW_UPLOAD"] == "I"):
				$res = CFile::CheckImageFile($arFile, $max_file_size, 0, 0);
			elseif ($arParams["ALLOW_UPLOAD"] == "F"):
				$res = CFile::CheckFile($arFile, $max_file_size, false, $arParams["ALLOW_UPLOAD_EXT"]);
			else:
				$res = CFile::CheckFile($arFile, $max_file_size, false, false);
			endif;

			if (strlen($res) <= 0)
			{
				$fileID = CFile::SaveFile($arFile, $mid);

				$tmp = array(
					"fileName" => $fileName,
					"fileID" => $fileID
				);
Esempio n. 27
0
 function CheckFields($ACTION, &$arFields, $ID = 0)
 {
     global $DB;
     if ((is_set($arFields, "TITLE") || $ACTION == "ADD") && strlen($arFields["TITLE"]) <= 0) {
         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("BLG_GP_EMPTY_TITLE"), "EMPTY_TITLE");
         return false;
     }
     if ((is_set($arFields, "DETAIL_TEXT") || $ACTION == "ADD") && strlen($arFields["DETAIL_TEXT"]) <= 0) {
         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("BLG_GP_EMPTY_DETAIL_TEXT"), "EMPTY_DETAIL_TEXT");
         return false;
     }
     if ((is_set($arFields, "BLOG_ID") || $ACTION == "ADD") && IntVal($arFields["BLOG_ID"]) <= 0) {
         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("BLG_GP_EMPTY_BLOG_ID"), "EMPTY_BLOG_ID");
         return false;
     } elseif (is_set($arFields, "BLOG_ID")) {
         $arResult = CBlog::GetByID($arFields["BLOG_ID"]);
         if (!$arResult) {
             $GLOBALS["APPLICATION"]->ThrowException(str_replace("#ID#", $arFields["BLOG_ID"], GetMessage("BLG_GP_ERROR_NO_BLOG")), "ERROR_NO_BLOG");
             return false;
         }
     }
     if ((is_set($arFields, "AUTHOR_ID") || $ACTION == "ADD") && IntVal($arFields["AUTHOR_ID"]) <= 0) {
         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("BLG_GP_EMPTY_AUTHOR_ID"), "EMPTY_AUTHOR_ID");
         return false;
     } elseif (is_set($arFields, "AUTHOR_ID")) {
         $dbResult = CUser::GetByID($arFields["AUTHOR_ID"]);
         if (!$dbResult->Fetch()) {
             $GLOBALS["APPLICATION"]->ThrowException(GetMessage("BLG_GP_ERROR_NO_AUTHOR"), "ERROR_NO_AUTHOR");
             return false;
         }
     }
     if (is_set($arFields, "DATE_CREATE") && !$DB->IsDate($arFields["DATE_CREATE"], false, LANG, "FULL")) {
         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("BLG_GP_ERROR_DATE_CREATE"), "ERROR_DATE_CREATE");
         return false;
     }
     if (is_set($arFields, "DATE_PUBLISH") && !$DB->IsDate($arFields["DATE_PUBLISH"], false, LANG, "FULL")) {
         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("BLG_GP_ERROR_DATE_PUBLISH"), "ERROR_DATE_PUBLISH");
         return false;
     }
     $arFields["PREVIEW_TEXT_TYPE"] = strtolower($arFields["PREVIEW_TEXT_TYPE"]);
     if ((is_set($arFields, "PREVIEW_TEXT_TYPE") || $ACTION == "ADD") && $arFields["PREVIEW_TEXT_TYPE"] != "text" && $arFields["PREVIEW_TEXT_TYPE"] != "html") {
         $arFields["PREVIEW_TEXT_TYPE"] = "text";
     }
     //$arFields["DETAIL_TEXT_TYPE"] = strtolower($arFields["DETAIL_TEXT_TYPE"]);
     if ((is_set($arFields, "DETAIL_TEXT_TYPE") || $ACTION == "ADD") && strtolower($arFields["DETAIL_TEXT_TYPE"]) != "text" && strtolower($arFields["DETAIL_TEXT_TYPE"]) != "html") {
         $arFields["DETAIL_TEXT_TYPE"] = "text";
     }
     if (strlen($arFields["DETAIL_TEXT_TYPE"]) > 0) {
         $arFields["DETAIL_TEXT_TYPE"] = strtolower($arFields["DETAIL_TEXT_TYPE"]);
     }
     $arStatus = array_keys($GLOBALS["AR_BLOG_PUBLISH_STATUS"]);
     if ((is_set($arFields, "PUBLISH_STATUS") || $ACTION == "ADD") && !in_array($arFields["PUBLISH_STATUS"], $arStatus)) {
         $arFields["PUBLISH_STATUS"] = $arStatus[0];
     }
     if ((is_set($arFields, "ENABLE_TRACKBACK") || $ACTION == "ADD") && $arFields["ENABLE_TRACKBACK"] != "Y" && $arFields["ENABLE_TRACKBACK"] != "N") {
         $arFields["ENABLE_TRACKBACK"] = "Y";
     }
     if ((is_set($arFields, "ENABLE_COMMENTS") || $ACTION == "ADD") && $arFields["ENABLE_COMMENTS"] != "Y" && $arFields["ENABLE_COMMENTS"] != "N") {
         $arFields["ENABLE_COMMENTS"] = "Y";
     }
     if (is_set($arFields, "ATTACH_IMG")) {
         $res = CFile::CheckImageFile($arFields["ATTACH_IMG"], 0, 0, 0);
         if (strlen($res) > 0) {
             $GLOBALS["APPLICATION"]->ThrowException(GetMessage("BLG_GP_ERROR_ATTACH_IMG") . ": " . $res, "ERROR_ATTACH_IMG");
             return false;
         }
     } else {
         $arFields["ATTACH_IMG"] = false;
     }
     if (is_set($arFields, "NUM_COMMENTS")) {
         $arFields["NUM_COMMENTS"] = IntVal($arFields["NUM_COMMENTS"]);
     }
     if (is_set($arFields, "NUM_TRACKBACKS")) {
         $arFields["NUM_TRACKBACKS"] = IntVal($arFields["NUM_TRACKBACKS"]);
     }
     if (is_set($arFields, "FAVORITE_SORT")) {
         $arFields["FAVORITE_SORT"] = IntVal($arFields["FAVORITE_SORT"]);
         if ($arFields["FAVORITE_SORT"] <= 0) {
             $arFields["FAVORITE_SORT"] = false;
         }
     }
     if (is_set($arFields, "CODE") && strlen($arFields["CODE"]) > 0) {
         $arFields["CODE"] = preg_replace("/[^a-zA-Z0-9_-]/is", "", Trim($arFields["CODE"]));
         if (in_array(strtolower($arFields["CODE"]), $GLOBALS["AR_BLOG_POST_RESERVED_CODES"])) {
             $GLOBALS["APPLICATION"]->ThrowException(str_replace("#CODE#", $arFields["CODE"], GetMessage("BLG_GP_RESERVED_CODE")), "CODE_RESERVED");
             return false;
         }
         $arFilter = array("CODE" => $arFields["CODE"]);
         if (IntVal($ID) > 0) {
             $arPost = CBlogPost::GetByID($ID);
             $arFilter["!ID"] = $arPost["ID"];
             $arFilter["BLOG_ID"] = $arPost["BLOG_ID"];
         } else {
             if (IntVal($arFields["BLOG_ID"]) > 0) {
                 $arFilter["BLOG_ID"] = $arFields["BLOG_ID"];
             }
         }
         $dbItem = CBlogPost::GetList(array(), $arFilter, false, array("nTopCount" => 1), array("ID", "CODE", "BLOG_ID"));
         if ($dbItem->Fetch()) {
             $GLOBALS["APPLICATION"]->ThrowException(GetMessage("BLG_GP_CODE_EXIST", array("#CODE#" => $arFields["CODE"])), "CODE_EXIST");
             return false;
         }
     }
     return True;
 }
Esempio n. 28
0
 public function CheckFields(&$arFields, $ID = false)
 {
     /** @global CMain $APPLICATION */
     global $APPLICATION;
     $this->LAST_ERROR = "";
     $NAME = isset($arFields["NAME"]) ? $arFields["NAME"] : "";
     if (($ID === false || array_key_exists("NAME", $arFields)) && strlen($NAME) <= 0) {
         $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_NAME") . "<br>";
     }
     if ($ID === false && !is_set($arFields, "IBLOCK_TYPE_ID")) {
         $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_BLOCK_TYPE") . "<br>";
     }
     if ($ID === false) {
         //For new record take default values
         $WORKFLOW = array_key_exists("WORKFLOW", $arFields) ? $arFields["WORKFLOW"] : "Y";
         $BIZPROC = array_key_exists("BIZPROC", $arFields) ? $arFields["BIZPROC"] : "N";
     } else {
         //For existing one read old values
         $arIBlock = CIBlock::GetArrayByID($ID);
         $WORKFLOW = array_key_exists("WORKFLOW", $arFields) ? $arFields["WORKFLOW"] : $arIBlock["WORKFLOW"];
         $BIZPROC = array_key_exists("BIZPROC", $arFields) ? $arFields["BIZPROC"] : $arIBlock["BIZPROC"];
         if ($BIZPROC != "Y") {
             $BIZPROC = "N";
         }
         //This is cache compatibility issue
     }
     if ($WORKFLOW == "Y" && $BIZPROC == "Y") {
         $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_WORKFLOW_AND_BIZPROC") . "<br>";
     }
     if (is_set($arFields, "IBLOCK_TYPE_ID")) {
         $r = CIBlockType::GetByID($arFields["IBLOCK_TYPE_ID"]);
         if (!$r->Fetch()) {
             $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_BLOCK_TYPE_ID") . "<br>";
         }
     }
     if (is_array($arFields["PICTURE"]) && array_key_exists("bucket", $arFields["PICTURE"]) && is_object($arFields["PICTURE"]["bucket"])) {
         //This is trusted image from xml import
     } elseif (isset($arFields["PICTURE"]) && is_array($arFields["PICTURE"]) && isset($arFields["PICTURE"]["name"])) {
         $error = CFile::CheckImageFile($arFields["PICTURE"]);
         if (strlen($error) > 0) {
             $this->LAST_ERROR .= $error . "<br>";
         }
     }
     if ($ID === false && !is_set($arFields, "LID") || is_set($arFields, "LID") && (is_array($arFields["LID"]) && count($arFields["LID"]) <= 0 || !is_array($arFields["LID"]) && strlen($arFields["LID"]) <= 0)) {
         $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_SITE_ID_NA") . "<br>";
     } elseif (is_set($arFields, "LID")) {
         if (!is_array($arFields["LID"])) {
             $arFields["LID"] = array($arFields["LID"]);
         }
         foreach ($arFields["LID"] as $v) {
             $r = CSite::GetByID($v);
             if (!$r->Fetch()) {
                 $this->LAST_ERROR .= "'" . $v . "' - " . GetMessage("IBLOCK_BAD_SITE_ID") . "<br>";
             }
         }
     }
     $APPLICATION->ResetException();
     if ($ID === false) {
         $db_events = GetModuleEvents("iblock", "OnBeforeIBlockAdd", true);
     } else {
         $arFields["ID"] = $ID;
         $db_events = GetModuleEvents("iblock", "OnBeforeIBlockUpdate", true);
     }
     foreach ($db_events as $arEvent) {
         $bEventRes = ExecuteModuleEventEx($arEvent, array(&$arFields));
         if ($bEventRes === false) {
             if ($err = $APPLICATION->GetException()) {
                 $this->LAST_ERROR .= $err->GetString() . "<br>";
             } else {
                 $APPLICATION->ThrowException("Unknown error");
                 $this->LAST_ERROR .= "Unknown error.<br>";
             }
             break;
         }
     }
     /****************************** QUOTA ******************************/
     if (empty($this->LAST_ERROR) && COption::GetOptionInt("main", "disk_space") > 0) {
         $quota = new CDiskQuota();
         if (!$quota->checkDiskQuota($arFields)) {
             $this->LAST_ERROR = $quota->LAST_ERROR;
         }
     }
     /****************************** QUOTA ******************************/
     if (strlen($this->LAST_ERROR) > 0) {
         return false;
     }
     return true;
 }
Esempio n. 29
0
            $_iLevel = (int) $arElement['DEPTH_LEVEL'] - (CWikiSocnet::IsSocNet() ? 2 : 1);
            $_sSeparator = '';
            if ($_iLevel > 0) {
                $_sSeparator = str_pad('', $_iLevel, '--');
            }
            $arTree[$arElement['NAME']] = $_sSeparator . CWikiUtils::htmlspecialcharsback($arElement['NAME'], false);
        }
        $arResult['TREE'] = $arTree;
    }
} else {
    if ($arResult['IMAGE_UPLOAD'] == 'Y') {
        $APPLICATION->RestartBuffer();
        header("Pragma: no-cache");
        if (isset($_POST['do_upload'])) {
            if (!empty($_FILES['FILE_ID']) && $_FILES['FILE_ID']['size'] > 0) {
                $iCheckResult = CFile::CheckImageFile($_FILES['FILE_ID']);
                if (strlen($iCheckResult) == 0) {
                    $_imgID = $CWiki->addImage($arParams['ELEMENT_ID'], $arParams['IBLOCK_ID'], $_FILES['FILE_ID']);
                    $rsFile = CFile::GetByID($_imgID);
                    $arFile = $rsFile->Fetch();
                    $arResult['IMAGE'] = array('ID' => $_imgID, 'ORIGINAL_NAME' => $arFile['ORIGINAL_NAME'], 'FILE_SHOW' => CFile::ShowImage($_imgID, 100, 100, "id=\"{$_imgID}\" border=\"0\" style=\"cursor:pointer;\" onclick=\"doInsert(\\'[File:" . CUtil::JSEscape($arFile['ORIGINAL_NAME']) . "]\\',\\'\\',false, \\'{$_imgID}\\')\" title=\"" . GetMessage('WIKI_IMAGE_INSERT') . "\""));
                } else {
                    $arResult['ERROR_MESSAGE'] = GetMessage('WIKI_IMAGE_UPLOAD_ERROR');
                }
            } else {
                $arResult['ERROR_MESSAGE'] = GetMessage('WIKI_IMAGE_UPLOAD_ERROR');
            }
        }
    } else {
        //$arResult['TOPLINKS'] = CWikiUtils::getRightsLinks(array('article', $arResult['WIKI_oper']), $arParams);
        $CWikiParser = new CWikiParser();
Esempio n. 30
0
 function CheckFields(&$arFields, $ID = false)
 {
     global $DB, $APPLICATION;
     $this->LAST_ERROR = "";
     if (($ID === false || is_set($arFields, "NAME")) && strlen($arFields["NAME"]) <= 0) {
         $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_SECTION") . "<br>";
     }
     if (is_array($arFields["PICTURE"]) && array_key_exists("bucket", $arFields["PICTURE"]) && is_object($arFields["PICTURE"]["bucket"])) {
         //This is trusted image from xml import
     } elseif (isset($arFields["PICTURE"]) && is_array($arFields["PICTURE"]) && isset($arFields["PICTURE"]["name"])) {
         $error = CFile::CheckImageFile($arFields["PICTURE"]);
         if (strlen($error) > 0) {
             $this->LAST_ERROR .= $error . "<br>";
         }
     }
     if (is_array($arFields["DETAIL_PICTURE"]) && array_key_exists("bucket", $arFields["DETAIL_PICTURE"]) && is_object($arFields["DETAIL_PICTURE"]["bucket"])) {
         //This is trusted image from xml import
     } elseif (isset($arFields["DETAIL_PICTURE"]) && is_array($arFields["DETAIL_PICTURE"]) && isset($arFields["DETAIL_PICTURE"]["name"])) {
         $error = CFile::CheckImageFile($arFields["DETAIL_PICTURE"]);
         if (strlen($error) > 0) {
             $this->LAST_ERROR .= $error . "<br>";
         }
     }
     $arIBlock = false;
     $arThis = false;
     if ($ID === false) {
         if (!array_key_exists("IBLOCK_ID", $arFields)) {
             $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_BLOCK_ID") . "<br>";
         } else {
             $arIBlock = CIBlock::GetArrayByID($arFields["IBLOCK_ID"]);
             if (!$arIBlock) {
                 $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_BLOCK_ID") . "<br>";
             }
         }
     } else {
         $rsThis = $DB->Query("SELECT ID, IBLOCK_ID, DETAIL_PICTURE, PICTURE FROM b_iblock_section WHERE ID = " . intval($ID));
         $arThis = $rsThis->Fetch();
         if (!$arThis) {
             $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_SECTION_ID", array("#ID#" => intval($ID))) . "<br>";
         } else {
             $arIBlock = CIBlock::GetArrayByID($arThis["IBLOCK_ID"]);
             if (!$arIBlock) {
                 $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_BLOCK_ID") . "<br>";
             }
         }
     }
     $arParent = false;
     $IBLOCK_SECTION_ID = isset($arFields["IBLOCK_SECTION_ID"]) ? intval($arFields["IBLOCK_SECTION_ID"]) : 0;
     if ($IBLOCK_SECTION_ID > 0 && strlen($this->LAST_ERROR) <= 0) {
         $rsParent = $DB->Query("SELECT ID, IBLOCK_ID FROM b_iblock_section WHERE ID = " . $IBLOCK_SECTION_ID);
         $arParent = $rsParent->Fetch();
         if (!$arParent) {
             $this->LAST_ERROR = GetMessage("IBLOCK_BAD_BLOCK_SECTION_PARENT") . "<br>";
         }
     }
     if ($arParent && $arIBlock) {
         if ($arParent["IBLOCK_ID"] != $arIBlock["ID"]) {
             $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_BLOCK_SECTION_ID_PARENT") . "<br>";
         }
     }
     if ($arParent && strlen($this->LAST_ERROR) <= 0) {
         $rch = $DB->Query("\n\t\t\t\tSELECT 'x'\n\t\t\t\tFROM\n\t\t\t\t\tb_iblock_section bsto\n\t\t\t\t\t,b_iblock_section bsfrom\n\t\t\t\tWHERE\n\t\t\t\t\tbsto.ID = " . $arParent["ID"] . "\n\t\t\t\t\tAND bsfrom.ID = " . intval($ID) . "\n\t\t\t\t\tAND bsto.LEFT_MARGIN >= bsfrom.LEFT_MARGIN\n\t\t\t\t\tAND bsto.LEFT_MARGIN <= bsfrom.RIGHT_MARGIN\n\t\t\t");
         if ($rch->Fetch()) {
             $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_BLOCK_SECTION_RECURSE") . "<br>";
         }
     }
     if ($arIBlock) {
         if (array_key_exists("CODE", $arFields) && strlen($arFields["CODE"]) && is_array($arIBlock["FIELDS"]["SECTION_CODE"]["DEFAULT_VALUE"]) && $arIBlock["FIELDS"]["SECTION_CODE"]["DEFAULT_VALUE"]["UNIQUE"] == "Y") {
             $res = $DB->Query("\n\t\t\t\t\tSELECT ID\n\t\t\t\t\tFROM b_iblock_section\n\t\t\t\t\tWHERE IBLOCK_ID = " . $arIBlock["ID"] . "\n\t\t\t\t\tAND CODE = '" . $DB->ForSQL($arFields["CODE"]) . "'\n\t\t\t\t\tAND ID <> " . intval($ID));
             if ($res->Fetch()) {
                 $this->LAST_ERROR .= GetMessage("IBLOCK_DUP_SECTION_CODE") . "<br>";
             }
         }
         foreach ($arIBlock["FIELDS"] as $FIELD_ID => $field) {
             if (!preg_match("/^SECTION_(.+)\$/", $FIELD_ID, $match)) {
                 continue;
             }
             $FIELD_ID = $match[1];
             if ($field["IS_REQUIRED"] === "Y") {
                 switch ($FIELD_ID) {
                     case "NAME":
                     case "DESCRIPTION_TYPE":
                         //We should never check for this fields
                         break;
                     case "PICTURE":
                         $field["NAME"] = GetMessage("IBLOCK_FIELD_PICTURE");
                     case "DETAIL_PICTURE":
                         if ($arThis && $arThis[$FIELD_ID] > 0) {
                             //There was an picture so just check that it is not deleted
                             if (array_key_exists($FIELD_ID, $arFields) && is_array($arFields[$FIELD_ID]) && $arFields[$FIELD_ID]["del"] === "Y") {
                                 $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_SECTION_FIELD", array("#FIELD_NAME#" => $field["NAME"])) . "<br>";
                             }
                         } else {
                             //There was NO picture so it MUST be present
                             if (!array_key_exists($FIELD_ID, $arFields)) {
                                 $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_SECTION_FIELD", array("#FIELD_NAME#" => $field["NAME"])) . "<br>";
                             } elseif (is_array($arFields[$FIELD_ID])) {
                                 if ($arFields[$FIELD_ID]["del"] === "Y" || array_key_exists("error", $arFields[$FIELD_ID]) && $arFields[$FIELD_ID]["error"] !== 0 || $arFields[$FIELD_ID]["size"] <= 0) {
                                     $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_SECTION_FIELD", array("#FIELD_NAME#" => $field["NAME"])) . "<br>";
                                 }
                             } else {
                                 if (intval($arFields[$FIELD_ID]) <= 0) {
                                     $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_SECTION_FIELD", array("#FIELD_NAME#" => $field["NAME"])) . "<br>";
                                 }
                             }
                         }
                         break;
                     default:
                         if ($ID === false || array_key_exists($FIELD_ID, $arFields)) {
                             if (is_array($arFields[$FIELD_ID])) {
                                 $val = implode("", $arFields[$FIELD_ID]);
                             } else {
                                 $val = $arFields[$FIELD_ID];
                             }
                             if (strlen($val) <= 0) {
                                 $this->LAST_ERROR .= GetMessage("IBLOCK_BAD_SECTION_FIELD", array("#FIELD_NAME#" => $field["NAME"])) . "<br>";
                             }
                         }
                         break;
                 }
             }
         }
     }
     $APPLICATION->ResetException();
     if ($ID === false) {
         $db_events = GetModuleEvents("iblock", "OnBeforeIBlockSectionAdd");
     } else {
         $arFields["ID"] = $ID;
         $arFields["IBLOCK_ID"] = $arIBlock["ID"];
         $db_events = GetModuleEvents("iblock", "OnBeforeIBlockSectionUpdate");
     }
     /****************************** QUOTA ******************************/
     if (empty($this->LAST_ERROR) && COption::GetOptionInt("main", "disk_space") > 0) {
         $quota = new CDiskQuota();
         if (!$quota->checkDiskQuota($arFields)) {
             $this->LAST_ERROR = $quota->LAST_ERROR;
         }
     }
     /****************************** QUOTA ******************************/
     while ($arEvent = $db_events->Fetch()) {
         $bEventRes = ExecuteModuleEventEx($arEvent, array(&$arFields));
         if ($bEventRes === false) {
             if ($err = $APPLICATION->GetException()) {
                 $this->LAST_ERROR .= $err->GetString() . "<br>";
             } else {
                 $APPLICATION->ThrowException("Unknown error");
                 $this->LAST_ERROR .= "Unknown error.<br>";
             }
             break;
         }
     }
     if (strlen($this->LAST_ERROR) > 0) {
         return false;
     }
     return true;
 }