Advertisement
Guest User

это он

a guest
Sep 18th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.88 KB | None | 0 0
  1. if($_GET["AJAX"] == "Y" && $_GET["IBLOCK_ID"] == $arParams["IBLOCK"]){
  2.         $APPLICATION->RestartBuffer();
  3.  
  4.         if($_POST['data-token'] == 'mWfX4R2Pqo'){
  5.             CModule::IncludeModule("iblock");
  6.             $el = new CIBlockElement;
  7.             $arProps = array();
  8.  
  9.             $arGT = Array(
  10.                 "IBLOCK_ID" => $arParams["IBLOCK"],
  11.                 "PREVIEW_TEXT_TYPE" => "TEXT",
  12.             );
  13.  
  14.             if($_POST['data-inactive']){
  15.                 $arGT["ACTIVE"] = "N";
  16.             } else {
  17.                 $arGT["ACTIVE"] = "Y";
  18.             }
  19.  
  20.             $arEventFields = array();
  21.  
  22.             foreach($_POST as $key => $prop){
  23.                 if($key == "NAME"){
  24.                     $arGT["NAME"] = $prop;
  25.                     $arEventFields["NAME"] = $prop;
  26.                 } elseif($key == "PREVIEW_TEXT"){
  27.                     $arGT["PREVIEW_TEXT"] = $prop;
  28.                     $arEventFields["COMMENT"] = $prop;
  29.                 } elseif(strpos($key, "PROPERTY") !== false) {
  30.                     if(strpos($key, "_SELECT") !== false) {
  31.                         $arProps[str_replace("PROPERTY_", '', str_replace("_SELECT","",$key))] = Array("VALUE"=>$prop);
  32.                     } else {
  33.                         $arProps[str_replace("PROPERTY_", '', $key)] = $prop;
  34.                     }
  35.                     $checkbox = false;
  36.                     foreach($iblock_fields as $field){
  37.                         if($field["CODE"] == str_replace("PROPERTY_", '', str_replace("_SELECT","",$key)) && $field["PROPERTY_TYPE"] == "L"){
  38.                             $checkbox = true;
  39.                         }
  40.                     }
  41.                     if($checkbox == true){
  42.                         $propname = getPropertyEnumValueById(str_replace("PROPERTY_", '', str_replace("_SELECT","",$key)), $prop, $arResult["ID"]);
  43.                         $arEventFields[str_replace("PROPERTY_", '', str_replace("_SELECT","",$key))] = $propname;
  44.                     } else {
  45.                         $arEventFields[str_replace("PROPERTY_", '', str_replace("_SELECT","",$key))] = $prop;
  46.                     }
  47.                 }
  48.             }
  49.            
  50.             foreach($_FILES as $k => $prop){
  51.                 if($k == "PREVIEW_PICTURE" || $k == "DETAIL_PICTURE"){
  52.                     $img = CFile::SaveFile(
  53.                         Array(
  54.                             "name" => $prop["name"],
  55.                             "size" => $prop["size"],
  56.                             "tmp_name" => $prop["tmp_name"],
  57.                             "type" => $prop["type"],
  58.                         ), "reviews"
  59.                     );
  60.                     $file = CFile::GetFileArray(intval($img));
  61.                     if (intval($img)>0){$arGT[$k] = CFile::MakeFileArray($file["SRC"]);}
  62.                 } else {
  63.                     $img = CFile::SaveFile(
  64.                         Array(
  65.                             "name" => $prop["name"],
  66.                             "size" => $prop["size"],
  67.                             "tmp_name" => $prop["tmp_name"],
  68.                             "type" => $prop["type"],
  69.                         ), "reviews"
  70.                     );
  71.                     $file = CFile::GetFileArray(intval($img));
  72.                     if (intval($img)>0){
  73.                         $arProps[str_replace("PROPERTY_", '', $k)] = CFile::MakeFileArray($file["SRC"]);
  74.                     }
  75.                 }
  76.             }
  77.  
  78.             $arGT["PROPERTY_VALUES"] = $arProps;
  79.  
  80.             if($res=$el->Add($arGT)){
  81.                 echo 'success';
  82.             } else {
  83.                 echo 'fail';
  84.             }
  85.             if($arParams["POST_EVENT"]){
  86.                 CEvent::Send($arParams["POST_EVENT"], SITE_ID, $arEventFields);
  87.             }
  88.         } else {
  89.             echo 'success';
  90.         }
  91.         die();
  92.    
  93. } else {
  94.     $this->IncludeComponentTemplate();
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement