/** * Form initializing and checking. If form's wrong, returns false * Use ShowErrorMsg() to output error code * * @param array $arParams * @return bool */ function Init($arParams, $admin = false) { global $APPLICATION, $USER; $this->bSimple = COption::GetOptionString("form", "SIMPLE", "Y") == "Y" ? true : false; $this->comp2 = !empty($arParams["COMPONENT"]); $this->SHOW_INCLUDE_AREAS = $APPLICATION->GetShowIncludeAreas(); if ($admin) { $FORM_RIGHT = $APPLICATION->GetGroupRight("form"); if ($FORM_RIGHT <= "D") { $APPLICATION->AuthForm(GetMessage("ACCESS_DENIED")); } $this->__admin = true; } $this->arParams = $arParams; $this->RESULT_ID = intval($arParams["RESULT_ID"]); if (intval($this->RESULT_ID) <= 0) { $this->RESULT_ID = intval($_REQUEST["RESULT_ID"]); } // if there's result ID try to get form ID if (intval($this->RESULT_ID) > 0) { $DBRes = CFormResult::GetByID($this->RESULT_ID); if ($arrResult = $DBRes->Fetch()) { $this->WEB_FORM_ID = intval($arrResult["FORM_ID"]); } } if (intval($this->WEB_FORM_ID) <= 0) { $this->WEB_FORM_ID = intval($arParams["WEB_FORM_ID"]); } // if there's no WEB_FORM_ID, try to get it from $_REQUEST; if (intval($this->WEB_FORM_ID) <= 0) { $this->WEB_FORM_ID = intval($_REQUEST["WEB_FORM_ID"]); } // check WEB_FORM_ID and get web form data $this->WEB_FORM_ID = CForm::GetDataByID($this->WEB_FORM_ID, $this->arForm, $this->arQuestions, $this->arAnswers, $this->arDropDown, $this->arMultiSelect, $this->__admin || $this->arParams["SHOW_ADDITIONAL"] == "Y" || $this->arParams["EDIT_ADDITIONAL"] == "Y" ? "ALL" : "N", $this->__admin ? 'Y' : 'N'); $this->WEB_FORM_NAME = $this->arForm["SID"]; // if wrong WEB_FORM_ID return error; if ($this->WEB_FORM_ID > 0) { // insert chain item if (strlen($this->arParams["CHAIN_ITEM_TEXT"]) > 0) { $APPLICATION->AddChainItem($this->arParams["CHAIN_ITEM_TEXT"], $this->arParams["CHAIN_ITEM_LINK"]); } // check web form rights; $this->F_RIGHT = intval(CForm::GetPermission($this->WEB_FORM_ID)); // in no form access - return error if ($this->isAccessForm()) { if (!empty($_REQUEST["strFormNote"])) { $this->strFormNote = $_REQUEST["strFormNote"]; } if (!$this->comp2 || $this->arParams["COMPONENT"]["componentName"] != "bitrix:form.result.list" || $this->isAccessFormResultList()) { if ($this->RESULT_ID) { if ($this->isAccessFormResult($arrResult)) { $this->arrRESULT_PERMISSION = CFormResult::GetPermissions($this->RESULT_ID, $v); // check result rights if (!$this->comp2 && !$this->isAccessFormResultEdit() || $this->comp2 && ($this->arParams["COMPONENT"]["componentName"] == "bitrix:form.result.edit" && !$this->isAccessFormResultEdit() || $this->arParams["COMPONENT"]["componentName"] == "bitrix:form.result.view" && !$this->isAccessFormResultView())) { $this->__error_msg = "FORM_RESULT_ACCESS_DENIED"; } else { if (!$arrResult) { $z = CFormResult::GetByID($this->RESULT_ID); $this->arResult = $z->Fetch(); } else { $this->arResult = $arrResult; } if ($this->arResult) { if ($this->comp2 && $this->arParams["COMPONENT"]["componentName"] == "bitrix:form.result.view") { CForm::GetResultAnswerArray($this->WEB_FORM_ID, $this->arrResultColumns, $this->arrVALUES, $this->arrResultAnswersSID, array("RESULT_ID" => $this->RESULT_ID)); $this->arrVALUES = $this->arrVALUES[$this->RESULT_ID]; } else { $this->arrVALUES = CFormResult::GetDataByIDForHTML($this->RESULT_ID, $this->arParams["EDIT_ADDITIONAL"]); } } else { $this->__error_msg = "FORM_RECORD_NOT_FOUND"; } } } else { $this->__error_msg = "FORM_ACCESS_DENIED"; } $this->arForm["USE_CAPTCHA"] = "N"; } else { // if form uses CAPCHA initialize it if ($this->arForm["USE_CAPTCHA"] == "Y") { $this->CaptchaInitialize(); } } } else { $this->__error_msg = "FORM_ACCESS_DENIED"; } } else { $this->__error_msg = "FORM_ACCESS_DENIED"; } // endif ($F_RIGHT>=10); } else { $this->__error_msg = "FORM_NOT_FOUND"; } // endif ($WEB_FORM_ID>0); return empty($this->__error_msg); }
function GetDataByIDForWeb($RESULT_ID, $GET_ADDITIONAL = "N") { return CFormResult::GetDataByIDForHTML($RESULT_ID, $GET_ADDITIONAL); }
<form name="form1" action="/bitrix/admin/form_result_edit.php?lang=<?php echo LANG; ?> &WEB_FORM_ID=<?php echo $WEB_FORM_ID; if ($RESULT_ID > 0) { echo '&RESULT_ID=' . $RESULT_ID; } ?> " method="POST" enctype="multipart/form-data"> <input type="hidden" name="MAX_FILE_SIZE" value="20000000" /> <?php echo bitrix_sessid_post(); $WEB_FORM_ID = CForm::GetDataByID($WEB_FORM_ID, $arForm, $arQuestions, $arAnswers, $arDropDown, $arMultiSelect, $EDIT_ADDITIONAL == 'Y' ? 'ALL' : 'N'); if (!$strError && $RESULT_ID > 0) { $arrVALUES = CFormResult::GetDataByIDForHTML($RESULT_ID, $EDIT_ADDITIONAL); } $bResultStatusChangeAccess = in_array("EDIT", $arrRESULT_PERMISSION); $arUser = null; $rsUser = null; if (intval($arrVALUES['USER_ID'] <= 0)) { if ($RESULT_ID > 0) { if (intval($arrResult["USER_ID"]) > 0) { $rsUser = CUser::GetByID($arrResult["USER_ID"]); } } else { $rsUser = CUser::GetByID($USER->GetID()); } } else { $rsUser = CUser::GetByID($arrVALUES["USER_ID"]); }
} else { if (!$arResultData) { $z = CFormResult::GetByID($arParams["RESULT_ID"]); $arResult["arResultData"] = $z->Fetch(); } else { $arResult["arResultData"] = $arResultData; } if ($arResult["arResultData"]) { $arResult["arrVALUES"] = CFormResult::GetDataByIDForHTML($arParams["RESULT_ID"], $arParams["EDIT_ADDITIONAL"]); } else { $arResult["ERROR"] = "FORM_RECORD_NOT_FOUND"; } } } else { $arResult["ERROR"] = "FORM_ACCESS_DENIED"; } $arResult["arForm"]["USE_CAPTCHA"] = "N"; } else
function GetResultValuesFromDB($RESULT_ID, $GET_ADDITIONAL = "N") { return CFormResult::GetDataByIDForHTML($RESULT_ID, $GET_ADDITIONAL); }