function __form_CreateForm($SID, $__current_dir) { // check collisions $dbTmpForm = CForm::GetBySID($SID); if ($arTmpForm = $dbTmpForm->Fetch()) { return false; } //$dirName = ToLower($SID); $formConfigFile = $__current_dir . '/form.php'; $fieldsConfigFile = $__current_dir . '/fields.php'; // check config existence if (!file_exists($formConfigFile) || !file_exists($fieldsConfigFile)) { return false; } // load form config $arForm = array(); require $formConfigFile; // setup form if ($FORM_ID = CForm::Set($arForm, false, 'N')) { // load fields config $arFormFields = array(); require $fieldsConfigFile; // setup form fields foreach ($arFormFields as $key => $arField) { CFormField::Set($arField, false, 'N'); } $arStatus = array('FORM_ID' => $FORM_ID, 'TITLE' => 'DEFAULT', 'CSORT' => 100, 'ACTIVE' => 'Y', 'DEFAULT_VALUE' => 'Y', 'arPERMISSION_MOVE' => array(0)); CFormStatus::Set($arStatus, false, 'N'); } return $FORM_ID; }
function Show($WEB_FORM_VARNAME, $arrVALUES=false, $SHOW_TEMPLATE=false, $PREVIEW="N") { global $DB, $MESS, $APPLICATION, $USER, $_REQUEST, $HTTP_POST_VARS, $HTTP_GET_VARS, $arrFIELDS; $err_mess = (CAllForm::err_mess())."<br>Function: Show<br>Line: "; if ($arrVALUES===false) $arrVALUES = $_REQUEST; $z = CForm::GetBySID($WEB_FORM_VARNAME); $zr = $z->Fetch(); $WEB_FORM_ID = $FORM_ID = intval($zr["ID"]); $WEB_FORM_ID = CForm::GetDataByID($WEB_FORM_ID, $arForm, $arQuestions, $arAnswers, $arDropDown, $arMultiSelect); if (intval($WEB_FORM_ID)>0) { $F_RIGHT = CForm::GetPermission($WEB_FORM_ID); if (intval($F_RIGHT)>=10) { if (strlen(trim($SHOW_TEMPLATE))>0) $template = $SHOW_TEMPLATE; else { if (strlen(trim($arForm["SHOW_TEMPLATE"]))<=0) $template = "default.php"; else $template = $arForm["SHOW_TEMPLATE"]; } $path = COption::GetOptionString("form","SHOW_TEMPLATE_PATH"); IncludeModuleLangFile($_SERVER["DOCUMENT_ROOT"]."/freetrix/modules/form/include.php"); include(GetLangFileName($_SERVER["DOCUMENT_ROOT"].$path."lang/", "/".$template)); if ($APPLICATION->GetShowIncludeAreas()) { $arIcons = Array(); if (CModule::IncludeModule("fileman")) { $arIcons[] = Array( "URL" => "/freetrix/admin/fileman_file_edit.php?lang=".LANGUAGE_ID."&site=".SITE_ID."&full_src=Y&path=". urlencode($path.$template), "SRC" => "/freetrix/images/form/panel/edit_template.gif", "ALT" => GetMessage("FORM_PUBLIC_ICON_TEMPLATE") ); $arrUrl = parse_url($_SERVER["REQUEST_URI"]); $arIcons[] = Array( "URL" => "/freetrix/admin/fileman_file_edit.php?lang=".LANGUAGE_ID."&site=".SITE_ID."&full_src=Y&path=". urlencode($arrUrl["path"]), "SRC" => "/freetrix/images/form/panel/edit_file.gif", "ALT" => GetMessage("FORM_PUBLIC_ICON_HANDLER") ); } $arIcons[] = Array( "URL" => "/freetrix/admin/form_edit.php?lang=".LANGUAGE_ID."&ID=".$WEB_FORM_ID, "SRC" => "/freetrix/images/form/panel/edit_form.gif", "ALT" => GetMessage("FORM_PUBLIC_ICON_SETTINGS") ); echo $APPLICATION->IncludeStringBefore($arIcons); } include($_SERVER["DOCUMENT_ROOT"].$path.$template); if ($APPLICATION->GetShowIncludeAreas()) { echo $APPLICATION->IncludeStringAfter(); } } } }
function CreateForm($arForm, $arFormFields, $langFile) { if (!CModule::IncludeModule("form")) { return false; } // set defaults $arFieldDefaults = array("ACTIVE" => "Y", "C_SORT" => 0, "ADDITIONAL" => "N", "TITLE_TYPE" => "text", "IN_RESULTS_TABLE" => "Y", "IN_EXCEL_TABLE" => "Y"); foreach ($arFormFields as $key => $arField) { if ($arFormFields['ADDITIONAL'] == 'Y' && !is_set($arFormFields['C_SORT'])) { $arFormFields['C_SORT'] = 5000; } $arFieldDefaults["C_SORT"] += 100; $arFormFields[$key] = array_merge($arFieldDefaults, $arField); $arFormFields[$key]["TITLE"] = GetMessage($arField["SID"] . "_QUESTION"); } $rsLanguage = CLanguage::GetList($by, $order, array()); while ($arLanguage = $rsLanguage->Fetch()) { WizardServices::IncludeServiceLang($langFile, $arLanguage["LID"]); $arForm["arMENU"][$arLanguage["LID"]] = GetMessage(substr($arForm["SID"], 0, -3) . "_MENU_NAME"); } $dbForm = CForm::GetBySID($arForm["SID"]); if ($dbForm->Fetch()) { return; } WizardServices::IncludeServiceLang("status.php"); if ($formID = CForm::Set($arForm, false, "N")) { // setup form fields foreach ($arFormFields as $key => $arField) { $arField["FORM_ID"] = $formID; $fieldID = CFormField::Set($arField, false, "N"); } if ($arTemplates = CForm::SetMailTemplate($formID)) { CForm::Set(array('SID' => $arForm['SID'], 'arMAIL_TEMPLATE' => $arTemplates), $formID, 'N'); } $arStatuses = array(array("FORM_ID" => $formID, "TITLE" => GetMessage("STATUS_NEW"), "C_SORT" => 100, "ACTIVE" => "Y", "DEFAULT_VALUE" => "Y", "CSS" => "statusgray", "arPERMISSION_VIEW" => array(0), "arPERMISSION_MOVE" => array(0), "arPERMISSION_EDIT" => array(0), "arPERMISSION_DELETE" => array(0)), array("FORM_ID" => $formID, "TITLE" => GetMessage("STATUS_RECEIVED"), "C_SORT" => 200, "ACTIVE" => "Y", "DEFAULT_VALUE" => "N", "CSS" => "statusblue", "arPERMISSION_VIEW" => array(0)), array("FORM_ID" => $formID, "TITLE" => GetMessage("STATUS_DONE"), "C_SORT" => 300, "ACTIVE" => "Y", "DEFAULT_VALUE" => "N", "CSS" => "statusgreen", "arPERMISSION_VIEW" => array(0)), array("FORM_ID" => $formID, "TITLE" => GetMessage("STATUS_REFUSE"), "C_SORT" => 400, "ACTIVE" => "Y", "DEFAULT_VALUE" => "N", "CSS" => "statusred", "arPERMISSION_VIEW" => array(0))); foreach ($arStatuses as $key => $arStatus) { if ($STATUS_ID = CFormStatus::Set($arStatus, false, "N")) { if ($arStatus['DEFAULT_VALUE'] == 'N' && ($arTemplates = CFormStatus::SetMailTemplate($formID, $STATUS_ID))) { foreach ($arTemplates as $TEMPLATE_ID) { if (null == $em) { $em = new CEventMessage(); } $em->Update($TEMPLATE_ID, array('MESSAGE' => GetMessage('STATUS_MESSAGE'))); } CFormStatus::Set(array('FORM_ID' => $formID, 'arMAIL_TEMPLATE' => $arTemplates), $STATUS_ID, 'N'); } } } } return $formID; }
/*************************************************************************************************/ $bVarsFromCache = false; $arResult["bSimple"] = COption::GetOptionString("form", "SIMPLE", "Y") == "N" ? "N" : "Y"; $arResult["bAdmin"] = defined("ADMIN_SECTION") && ADMIN_SECTION===true ? "Y" : "N"; // if form taken from admin interface - check rights to form module if ($arResult["bAdmin"] == "Y") { $FORM_RIGHT = $APPLICATION->GetGroupRight("form"); if($FORM_RIGHT<="D") $APPLICATION->AuthForm(GetMessage("ACCESS_DENIED")); } if (intval($arParams['WEB_FORM_ID']) <= 0 && strlen($arParams['WEB_FORM_ID']) > 0) { $obForm = CForm::GetBySID($arParams['WEB_FORM_ID']); if ($arForm = $obForm->Fetch()) { $arParams['WEB_FORM_ID'] = $arForm['ID']; } } // check WEB_FORM_ID and get web form data $arParams["WEB_FORM_ID"] = CForm::GetDataByID($arParams["WEB_FORM_ID"], $arResult["arForm"], $arResult["arQuestions"], $arResult["arAnswers"], $arResult["arDropDown"], $arResult["arMultiSelect"], $arResult["bAdmin"] == "Y" || $arParams["SHOW_ADDITIONAL"] == "Y" || $arParams["EDIT_ADDITIONAL"] == "Y" ? "ALL" : "N"); $arResult["WEB_FORM_NAME"] = $arResult["arForm"]["SID"]; // if wrong WEB_FORM_ID return error; if ($arParams["WEB_FORM_ID"] > 0) { // check web form rights;
$arrNOT_SHOW_FILTER = explode(",", $arParams["NOT_SHOW_FILTER"]); if (is_array($arrNOT_SHOW_FILTER)) { array_walk($arrNOT_SHOW_FILTER, create_function("&\$item", "\$item=trim(\$item);")); } else { $arrNOT_SHOW_FILTER = array(); } $arrNOT_SHOW_TABLE = explode(",", $arParams["NOT_SHOW_TABLE"]); if (is_array($arrNOT_SHOW_TABLE)) { array_walk($arrNOT_SHOW_TABLE, create_function("&\$item", "\$item=trim(\$item);")); } else { $arrNOT_SHOW_TABLE = array(); } if (intval($WEB_FORM_ID) > 0) { $z = CForm::GetByID($WEB_FORM_ID); } else { $z = CForm::GetBySID($WEB_FORM_NAME); } if ($zr = $z->Fetch()) { $GLOBALS["WEB_FORM_ID"] = $WEB_FORM_ID = $zr["ID"]; $GLOBALS["WEB_FORM_NAME"] = $WEB_FORM_NAME = $zr["SID"]; $USER_ID = $USER->GetID(); $F_RIGHT = CForm::GetPermission($WEB_FORM_ID); if ($F_RIGHT < 15) { $APPLICATION->AuthForm(GetMessage("ACCESS_DENIED")); } /* if (is_array($ARR_RESULT) && count($ARR_RESULT)>0 && strlen($_GET['delete'])>0 && check_bitrix_sessid()) { foreach($ARR_RESULT as $rid) CFormResult::Delete($rid); } */
} // rights check inside } if (strlen($GLOBALS['strError']) <= 0) { LocalRedirect($APPLICATION->GetCurPageParam("", array("delete", "sessid", 'formresult'))); exit; } } } if (strlen($GLOBALS['strError']) > 0) { $arResult["FORM_ERROR"] .= $GLOBALS['strError']; } if (intval($arParams["WEB_FORM_ID"]) > 0) { $dbres = CForm::GetByID($arParams["WEB_FORM_ID"]); } else { $dbres = CForm::GetBySID($arParams["WEB_FORM_NAME"]); } // get form info if ($arParams["arFormInfo"] = $dbres->Fetch()) { $GLOBALS["WEB_FORM_ID"] = $arParams["WEB_FORM_ID"] = $arParams["arFormInfo"]["ID"]; $GLOBALS["WEB_FORM_NAME"] = $arParams["WEB_FORM_NAME"] = $arParams["arFormInfo"]["SID"]; // check form params $arParams["USER_ID"] = $USER->GetID(); // prepare filter $FilterArr = array("find_id", "find_id_exact_match", "find_status", "find_status_id", "find_status_id_exact_match", "find_timestamp_1", "find_timestamp_2", "find_date_create_2", "find_date_create_1", "find_date_create_2", "find_registered", "find_user_auth", "find_user_id", "find_user_id_exact_match", "find_guest_id", "find_guest_id_exact_match", "find_session_id", "find_session_id_exact_match"); $arResult["arrFORM_FILTER"] = array(); $arListFilter = array("ACTIVE" => "Y"); if (count($arParams["arrNOT_SHOW_FILTER"]) > 0) { $arListFilter["FIELD_SID"] = "~'" . implode("' & ~'", $arParams["arrNOT_SHOW_FILTER"]) . "'"; } $z = CFormField::GetFilterList($arParams["WEB_FORM_ID"], $arListFilter);
/** * Возвращает ID формы по символьному коду * @param $code * @return int|false */ protected function getFormId($code) { if ($form = \CForm::GetBySID($code)->Fetch()) { return $form['ID']; } else { return false; } }