Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if($_GET["AJAX"] == "Y" && $_GET["IBLOCK_ID"] == $arParams["IBLOCK"]){
- $APPLICATION->RestartBuffer();
- if($_POST['data-token'] == 'mWfX4R2Pqo'){
- CModule::IncludeModule("iblock");
- $el = new CIBlockElement;
- $arProps = array();
- $arGT = Array(
- "IBLOCK_ID" => $arParams["IBLOCK"],
- "PREVIEW_TEXT_TYPE" => "TEXT",
- );
- if($_POST['data-inactive']){
- $arGT["ACTIVE"] = "N";
- } else {
- $arGT["ACTIVE"] = "Y";
- }
- $arEventFields = array();
- foreach($_POST as $key => $prop){
- if($key == "NAME"){
- $arGT["NAME"] = $prop;
- $arEventFields["NAME"] = $prop;
- } elseif($key == "PREVIEW_TEXT"){
- $arGT["PREVIEW_TEXT"] = $prop;
- $arEventFields["COMMENT"] = $prop;
- } elseif(strpos($key, "PROPERTY") !== false) {
- if(strpos($key, "_SELECT") !== false) {
- $arProps[str_replace("PROPERTY_", '', str_replace("_SELECT","",$key))] = Array("VALUE"=>$prop);
- } else {
- $arProps[str_replace("PROPERTY_", '', $key)] = $prop;
- }
- $checkbox = false;
- foreach($iblock_fields as $field){
- if($field["CODE"] == str_replace("PROPERTY_", '', str_replace("_SELECT","",$key)) && $field["PROPERTY_TYPE"] == "L"){
- $checkbox = true;
- }
- }
- if($checkbox == true){
- $propname = getPropertyEnumValueById(str_replace("PROPERTY_", '', str_replace("_SELECT","",$key)), $prop, $arResult["ID"]);
- $arEventFields[str_replace("PROPERTY_", '', str_replace("_SELECT","",$key))] = $propname;
- } else {
- $arEventFields[str_replace("PROPERTY_", '', str_replace("_SELECT","",$key))] = $prop;
- }
- }
- }
- foreach($_FILES as $k => $prop){
- if($k == "PREVIEW_PICTURE" || $k == "DETAIL_PICTURE"){
- $img = CFile::SaveFile(
- Array(
- "name" => $prop["name"],
- "size" => $prop["size"],
- "tmp_name" => $prop["tmp_name"],
- "type" => $prop["type"],
- ), "reviews"
- );
- $file = CFile::GetFileArray(intval($img));
- if (intval($img)>0){$arGT[$k] = CFile::MakeFileArray($file["SRC"]);}
- } else {
- $img = CFile::SaveFile(
- Array(
- "name" => $prop["name"],
- "size" => $prop["size"],
- "tmp_name" => $prop["tmp_name"],
- "type" => $prop["type"],
- ), "reviews"
- );
- $file = CFile::GetFileArray(intval($img));
- if (intval($img)>0){
- $arProps[str_replace("PROPERTY_", '', $k)] = CFile::MakeFileArray($file["SRC"]);
- }
- }
- }
- $arGT["PROPERTY_VALUES"] = $arProps;
- if($res=$el->Add($arGT)){
- echo 'success';
- } else {
- echo 'fail';
- }
- if($arParams["POST_EVENT"]){
- CEvent::Send($arParams["POST_EVENT"], SITE_ID, $arEventFields);
- }
- } else {
- echo 'success';
- }
- die();
- } else {
- $this->IncludeComponentTemplate();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement