Esempio n. 1
0
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;
}
Esempio n. 2
0
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;
}
Esempio n. 3
0
     if ($_REQUEST['USE_MAIL_TEMPLATE'] && count($arr['reference_id']) == 0) {
         CForm::SetMailTemplate($res, "Y");
     } elseif (!$_REQUEST['USE_MAIL_TEMPLATE'] && count($arr['reference_id']) > 0) {
         reset($arr['reference_id']);
         while (list($num, $tmp_id) = each($arr['reference_id'])) {
             CEventMessage::Delete($tmp_id);
         }
     }
     $arr = CForm::GetTemplateList("MAIL", "xxx", $res);
     $arFields['SID'] = "SIMPLE_FORM_{$res}";
     $arFields['arMAIL_TEMPLATE'] = $arr['reference_id'];
     CForm::Set($arFields, $res);
     // create default status
     if ($ID == 0) {
         $arFields_status = array("FORM_ID" => $res, "C_SORT" => 100, "ACTIVE" => "Y", "TITLE" => "DEFAULT", "DESCRIPTION" => "DEFAULT", "CSS" => "statusgreen", "DEFAULT_VALUE" => "Y", "arPERMISSION_VIEW" => array(0), "arPERMISSION_MOVE" => array(0), "arPERMISSION_EDIT" => array(0), "arPERMISSION_DELETE" => array(0));
         CFormStatus::Set($arFields_status, 0);
     }
 }
 if (strlen($strError) <= 0 && $ID > 0) {
     $arCrmParams = array('CRM_ID' => $_REQUEST['CRM_ID'], 'LINK_TYPE' => $_REQUEST['CRM_LINK_TYPE'], 'CRM_FIELDS' => $_REQUEST['CRM_FIELD'], 'FORM_FIELDS' => $_REQUEST['CRM_FORM_FIELD']);
     CFormCrm::SetForm($ID, $arCrmParams);
 }
 $ID = $res;
 if (strlen($strError) <= 0) {
     if (strlen($_REQUEST['save']) > 0) {
         if (!empty($_REQUEST["back_url"])) {
             LocalRedirect("/" . ltrim($_REQUEST["back_url"], "/"));
         } else {
             LocalRedirect("/bitrix/admin/form_list.php?lang=" . LANGUAGE_ID);
         }
     } else {
Esempio n. 4
0
	public static function SetMailTemplate($WEB_FORM_ID, $STATUS_ID, $ADD_NEW_TEMPLATE="Y", $old_SID="", $bReturnFullInfo = false)
	{
		global $DB, $MESS, $strError;
		$err_mess = (CAllForm::err_mess())."<br>Function: SetMailTemplate<br>Line: ";
		$arrReturn = array();
		$WEB_FORM_ID = intval($WEB_FORM_ID);
		$q = CForm::GetByID($WEB_FORM_ID);
		if ($arrForm = $q->Fetch())
		{
			$dbRes = CFormStatus::GetByID($STATUS_ID);
			if ($arrStatus = $dbRes->Fetch())
			{
				$MAIL_EVENT_TYPE = "FORM_STATUS_CHANGE_".$arrForm["SID"]."_".$arrStatus['ID'];
				if (strlen($old_SID)>0)
					$old_MAIL_EVENT_TYPE = "FORM_STATUS_CHANGE_".$old_SID."_".$arrStatus['ID'];

				$et = new CEventType;
				$em = new CEventMessage;

				if (strlen($MAIL_EVENT_TYPE)>0)
					$et->Delete($MAIL_EVENT_TYPE);

				$z = CLanguage::GetList($v1, $v2);
				$OLD_MESS = $MESS;
				$MESS = array();
				while ($arLang = $z->Fetch())
				{
					IncludeModuleLangFile($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/form/admin/form_status_mail.php", $arLang["LID"]);

					$str = "";
					$str .= "#EMAIL_TO# - ".GetMessage("FORM_L_EMAIL_TO")."\n";
					$str .= "#RS_FORM_ID# - ".GetMessage("FORM_L_FORM_ID")."\n";
					$str .= "#RS_FORM_NAME# - ".GetMessage("FORM_L_NAME")."\n";
					$str .= "#RS_FORM_SID# - ".GetMessage("FORM_L_SID")."\n";
					$str .= "#RS_RESULT_ID# - ".GetMessage("FORM_L_RESULT_ID")."\n";
					$str .= "#RS_DATE_CREATE# - ".GetMessage("FORM_L_DATE_CREATE")."\n";
					$str .= "#RS_USER_ID# - ".GetMessage("FORM_L_USER_ID")."\n";
					$str .= "#RS_USER_EMAIL# - ".GetMessage("FORM_L_USER_EMAIL")."\n";
					$str .= "#RS_USER_NAME# - ".GetMessage("FORM_L_USER_NAME")."\n";
					$str .= "#RS_STATUS_ID# - ".GetMessage("FORM_L_STATUS_ID")."\n";
					$str .= "#RS_STATUS_NAME# - ".GetMessage("FORM_L_STATUS_NAME")."\n";

					$et->Add(
							Array(
							"LID"			=> $arLang["LID"],
							"EVENT_NAME"	=> $MAIL_EVENT_TYPE,
							"NAME"			=> str_replace(array('#FORM_SID#', '#STATUS_NAME#'), array($arrForm['SID'], $arrStatus['TITLE']), GetMessage("FORM_CHANGE_STATUS")),
							"DESCRIPTION"	=> $str
							)
						);
				}
				// create new event type for old templates
				if (strlen($old_MAIL_EVENT_TYPE)>0 && $old_MAIL_EVENT_TYPE!=$MAIL_EVENT_TYPE)
				{
					$e = $em->GetList($by="id",$order="desc",array("EVENT_NAME"=>$old_MAIL_EVENT_TYPE));
					while ($er=$e->Fetch())
					{
						$em->Update($er["ID"],array("EVENT_NAME"=>$MAIL_EVENT_TYPE));
					}
					if (strlen($old_MAIL_EVENT_TYPE)>0)
						$et->Delete($old_MAIL_EVENT_TYPE);
				}

				if ($ADD_NEW_TEMPLATE=="Y")
				{
					$z = CSite::GetList($v1, $v2);
					while ($arSite = $z->Fetch()) $arrSiteLang[$arSite["ID"]] = $arSite["LANGUAGE_ID"];

					$arrFormSite = CForm::GetSiteArray($WEB_FORM_ID);
					if (is_array($arrFormSite) && count($arrFormSite)>0)
					{
						foreach($arrFormSite as $sid)
						{
							IncludeModuleLangFile($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/form/admin/form_status_mail.php", $arrSiteLang[$sid]);

							$SUBJECT = GetMessage("FORM_CHANGE_STATUS_S");
							$MESSAGE = GetMessage("FORM_CHANGE_STATUS_B");

							// добавляем новый шаблон
							$arFields = Array(
								"ACTIVE"		=> "Y",
								"EVENT_NAME"	=> $MAIL_EVENT_TYPE,
								"LID"			=> $sid,
								"EMAIL_FROM"	=> "#DEFAULT_EMAIL_FROM#",
								"EMAIL_TO"		=> "#EMAIL_TO#",
								"SUBJECT"		=> $SUBJECT,
								"MESSAGE"		=> $MESSAGE,
								"BODY_TYPE"		=> "text"
								);
							//echo '<pre>'; print_r($arFields); echo '</pre>';
							$TEMPLATE_ID = $em->Add($arFields);
							if ($bReturnFullInfo)
								$arrReturn[] = array(
									'ID' => $TEMPLATE_ID,
									'FIELDS' => $arFields,
								);
							else
								$arrReturn[] = $TEMPLATE_ID;

						}
					}
				}

				CFormStatus::Set(array('FORM_ID' => $WEB_FORM_ID, 'MAIL_EVENT_TYPE' => $MAIL_EVENT_TYPE), $STATUS_ID, 'N');

				$MESS = $OLD_MESS;
			}
		}
		return $arrReturn;
	}
Esempio n. 5
0
$F_RIGHT = CForm::GetPermission($WEB_FORM_ID);
if ($F_RIGHT < 25) {
    $APPLICATION->AuthForm(GetMessage("ACCESS_DENIED"));
}
// copying
if (intval($copy_id) > 0 && check_bitrix_sessid() && $F_RIGHT >= 30) {
    $new_id = CFormStatus::Copy($copy_id);
    if (strlen($strError) <= 0 && intval($new_id) > 0) {
        LocalRedirect("form_status_edit.php?ID=" . $new_id . "&WEB_FORM_ID=" . $WEB_FORM_ID . "&lang=" . LANGUAGE_ID . "&strError=" . urlencode($strError));
    }
}
$DEFAULT_STATUS_ID = intval(CFormStatus::GetDefault($WEB_FORM_ID));
if ((strlen($save) > 0 || strlen($apply) > 0) && $REQUEST_METHOD == "POST" && $F_RIGHT >= 30 && check_bitrix_sessid()) {
    $arFields = array("FORM_ID" => $WEB_FORM_ID, "C_SORT" => $C_SORT, "ACTIVE" => $ACTIVE, "TITLE" => $TITLE, "DESCRIPTION" => $DESCRIPTION, "CSS" => $CSS, "HANDLER_OUT" => $HANDLER_OUT, "HANDLER_IN" => $HANDLER_IN, "DEFAULT_VALUE" => $DEFAULT_VALUE, "arPERMISSION_VIEW" => $arPERMISSION_VIEW, "arPERMISSION_MOVE" => $arPERMISSION_MOVE, "arPERMISSION_EDIT" => $arPERMISSION_EDIT, "arPERMISSION_DELETE" => $arPERMISSION_DELETE, "arMAIL_TEMPLATE" => $arMAIL_TEMPLATE);
    //echo "<pre>"; print_r($arFields); echo "</pre>"; die();
    $res = intval(CFormStatus::Set($arFields, $ID));
    if ($res > 0) {
        $ID = $res;
        if (strlen($strError) <= 0) {
            if (strlen($save) > 0) {
                LocalRedirect("form_status_list.php?WEB_FORM_ID=" . $WEB_FORM_ID . "&lang=" . LANGUAGE_ID);
            } else {
                LocalRedirect("form_status_edit.php?ID=" . $ID . "&WEB_FORM_ID=" . $WEB_FORM_ID . "&lang=" . LANGUAGE_ID . "&" . $tabControl->ActiveTabParam());
            }
        }
    }
    $DB->PrepareFields("b_form_status");
}
if ($ID > 0) {
    $rsStatus = CFormStatus::GetByID($ID);
}
Esempio n. 6
0
 function Copy($ID, $CHECK_RIGHTS = "Y", $NEW_FORM_ID = false)
 {
     global $DB, $APPLICATION, $strError;
     $err_mess = CAllFormStatus::err_mess() . "<br>Function: Copy<br>Line: ";
     $ID = intval($ID);
     $NEW_FORM_ID = intval($NEW_FORM_ID);
     $rsStatus = CFormStatus::GetByID($ID);
     if ($arStatus = $rsStatus->Fetch()) {
         $RIGHT_OK = "N";
         if ($CHECK_RIGHTS != "Y" || CForm::IsAdmin()) {
             $RIGHT_OK = "Y";
         } else {
             $F_RIGHT = CForm::GetPermission($arStatus["FORM_ID"]);
             // если имеем право на просмотр параметров формы
             if ($F_RIGHT >= 25) {
                 // если задана новая форма
                 if ($NEW_FORM_ID > 0) {
                     $NEW_F_RIGHT = CForm::GetPermission($NEW_FORM_ID);
                     // если имеем полный доступ на новую форму
                     if ($NEW_F_RIGHT >= 30) {
                         $RIGHT_OK = "Y";
                     }
                 } elseif ($F_RIGHT >= 30) {
                     $RIGHT_OK = "Y";
                 }
             }
         }
         // если права проверили то
         if ($RIGHT_OK == "Y") {
             CFormStatus::GetPermissionList($ID, $arPERMISSION_VIEW, $arPERMISSION_MOVE, $arPERMISSION_EDIT, $arPERMISSION_DELETE);
             // копируем
             $arFields = array("FORM_ID" => $NEW_FORM_ID > 0 ? $NEW_FORM_ID : $arStatus["FORM_ID"], "C_SORT" => $arStatus["C_SORT"], "ACTIVE" => $arStatus["ACTIVE"], "TITLE" => $arStatus["TITLE"], "DESCRIPTION" => $arStatus["DESCRIPTION"], "CSS" => $arStatus["CSS"], "HANDLER_OUT" => $arStatus["HANDLER_OUT"], "HANDLER_IN" => $arStatus["HANDLER_IN"], "DEFAULT_VALUE" => $arStatus["DEFAULT_VALUE"], "arPERMISSION_VIEW" => $arPERMISSION_VIEW, "arPERMISSION_MOVE" => $arPERMISSION_MOVE, "arPERMISSION_EDIT" => $arPERMISSION_EDIT, "arPERMISSION_DELETE" => $arPERMISSION_DELETE);
             $NEW_ID = CFormStatus::Set($arFields);
             return $NEW_ID;
         } else {
             $strError .= GetMessage("FORM_ERROR_ACCESS_DENIED") . "<br>";
         }
     } else {
         $strError .= GetMessage("FORM_ERROR_STATUS_NOT_FOUND") . "<br>";
     }
     return false;
 }