function SetMailTemplate($WEB_FORM_ID, $ADD_NEW_TEMPLATE = "Y", $old_SID = "", $bReturnFullInfo = false)
 {
     global $DB, $MESS, $strError;
     $err_mess = CAllForm::err_mess() . "<br>Function: SetMailTemplates<br>Line: ";
     $arrReturn = array();
     $WEB_FORM_ID = intval($WEB_FORM_ID);
     $q = CForm::GetByID($WEB_FORM_ID);
     if ($arrForm = $q->Fetch()) {
         $MAIL_EVENT_TYPE = "FORM_FILLING_" . $arrForm["SID"];
         if (strlen($old_SID) > 0) {
             $old_MAIL_EVENT_TYPE = "FORM_FILLING_" . $old_SID;
         }
         $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;
         while ($arLang = $z->Fetch()) {
             IncludeModuleLangFile($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/form/admin/form_mail.php", $arLang["LID"]);
             $str = "";
             $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_USER_AUTH# - " . GetMessage("FORM_L_USER_AUTH") . "\n";
             $str .= "#RS_STAT_GUEST_ID# - " . GetMessage("FORM_L_STAT_GUEST_ID") . "\n";
             $str .= "#RS_STAT_SESSION_ID# - " . GetMessage("FORM_L_STAT_SESSION_ID") . "\n";
             $strFIELDS = "";
             $w = CFormField::GetList($WEB_FORM_ID, "ALL", $by, $order, array(), $is_filtered);
             while ($wr = $w->Fetch()) {
                 if (strlen($wr["RESULTS_TABLE_TITLE"]) > 0) {
                     $FIELD_TITLE = $wr["RESULTS_TABLE_TITLE"];
                 } elseif (strlen($wr["TITLE"]) > 0) {
                     $FIELD_TITLE = $wr["TITLE_TYPE"] == "html" ? htmlspecialcharsback(strip_tags($wr["TITLE"])) : $wr["TITLE"];
                 } else {
                     $FIELD_TITLE = TrimEx($wr["FILTER_TITLE"], ":");
                 }
                 $str .= "#" . $wr["SID"] . "# - " . $FIELD_TITLE . "\n";
                 $str .= "#" . $wr["SID"] . "_RAW# - " . $FIELD_TITLE . " (" . GetMessage('FORM_L_RAW') . ")\n";
                 $strFIELDS .= $FIELD_TITLE . "\n*******************************\n#" . $wr["SID"] . "#\n\n";
             }
             $et->Add(array("LID" => $arLang["LID"], "EVENT_NAME" => $MAIL_EVENT_TYPE, "NAME" => GetMessage("FORM_FILLING") . " \"" . $arrForm["SID"] . "\"", "DESCRIPTION" => $str));
         }
         // задаем новый тип событи¤ дл¤ старых шаблонов
         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_mail.php", $arrSiteLang[$sid]);
                     $SUBJECT = "#SERVER_NAME#: " . GetMessage("FORM_FILLING_S") . " [#RS_FORM_ID#] #RS_FORM_NAME#";
                     $MESSAGE = "#SERVER_NAME#\n\n" . GetMessage("FORM_FILLING") . ": [#RS_FORM_ID#] #RS_FORM_NAME#\n-------------------------------------------------------\n\n" . GetMessage("FORM_DATE_CREATE") . "#RS_DATE_CREATE#\n" . GetMessage("FORM_RESULT_ID") . "#RS_RESULT_ID#\n" . GetMessage("FORM_USER") . "[#RS_USER_ID#] #RS_USER_NAME# #RS_USER_AUTH#\n" . GetMessage("FORM_STAT_GUEST_ID") . "#RS_STAT_GUEST_ID#\n" . GetMessage("FORM_STAT_SESSION_ID") . "#RS_STAT_SESSION_ID#\n\n\n{$strFIELDS}\n" . GetMessage("FORM_VIEW") . "\nhttp://#SERVER_NAME#/bitrix/admin/form_result_view.php?lang=" . $arrSiteLang[$sid] . "&WEB_FORM_ID=#RS_FORM_ID#&RESULT_ID=#RS_RESULT_ID#\n\n-------------------------------------------------------\n" . GetMessage("FORM_GENERATED_AUTOMATICALLY") . "\n\t\t\t\t\t\t";
                     // добавл¤ем новый шаблон
                     $arFields = array("ACTIVE" => "Y", "EVENT_NAME" => $MAIL_EVENT_TYPE, "LID" => $sid, "EMAIL_FROM" => "#DEFAULT_EMAIL_FROM#", "EMAIL_TO" => "#DEFAULT_EMAIL_FROM#", "SUBJECT" => $SUBJECT, "MESSAGE" => $MESSAGE, "BODY_TYPE" => "text");
                     $TEMPLATE_ID = $em->Add($arFields);
                     if ($bReturnFullInfo) {
                         $arrReturn[] = array('ID' => $TEMPLATE_ID, 'FIELDS' => $arFields);
                     } else {
                         $arrReturn[] = $TEMPLATE_ID;
                     }
                 }
             }
         }
         $MESS = $OLD_MESS;
     }
     return $arrReturn;
 }
Esempio n. 2
0
	protected static function _getAllFormFields($WEB_FORM_ID, $RESULT_ID, $arAnswers)
	{
		global $APPLICATION;

		$strResult = "";

		$w = CFormField::GetList($WEB_FORM_ID, "ALL", $by, $order, array("ACTIVE" => "Y"), $is_filtered);
		while ($wr=$w->Fetch())
		{
			$answer = "";
			$answer_raw = '';
			if (is_array($arAnswers[$wr["SID"]]))
			{
				$bHasDiffTypes = false;
				$lastType = '';
				foreach ($arAnswers[$wr['SID']] as $arrA)
				{
					if ($lastType == '') $lastType = $arrA['FIELD_TYPE'];
					elseif ($arrA['FIELD_TYPE'] != $lastType)
					{
						$bHasDiffTypes = true;
						break;
					}
				}

				foreach($arAnswers[$wr["SID"]] as $arrA)
				{
					if ($wr['ADDITIONAL'] == 'Y')
					{
						$arrA['FIELD_TYPE'] = $wr['FIELD_TYPE'];
					}

					$USER_TEXT_EXIST = (strlen(trim($arrA["USER_TEXT"]))>0);
					$ANSWER_TEXT_EXIST = (strlen(trim($arrA["ANSWER_TEXT"]))>0);
					$ANSWER_VALUE_EXIST = (strlen(trim($arrA["ANSWER_VALUE"]))>0);
					$USER_FILE_EXIST = (intval($arrA["USER_FILE_ID"])>0);

					if (
						$bHasDiffTypes
						&& !$USER_TEXT_EXIST
						&& (
							$arrA['FIELD_TYPE'] == 'text'
							||
							$arrA['FIELD_TYPE'] == 'textarea'
						)
					)
					{
						continue;
					}

					if (strlen(trim($answer)) > 0)
						$answer .= "\n";
					if (strlen(trim($answer_raw)) > 0)
						$answer_raw .= ",";

					if ($ANSWER_TEXT_EXIST)
						$answer .= $arrA["ANSWER_TEXT"].': ';

					switch ($arrA['FIELD_TYPE'])
					{
						case 'text':
						case 'textarea':
						case 'email':
						case 'url':
						case 'hidden':
						case 'date':
						case 'password':

							if ($USER_TEXT_EXIST)
							{
								$answer .= trim($arrA["USER_TEXT"]);
								$answer_raw .= trim($arrA["USER_TEXT"]);
							}

						break;

						case 'checkbox':
						case 'multiselect':
						case 'radio':
						case 'dropdown':

							if ($ANSWER_TEXT_EXIST)
							{
								$answer = substr($answer, 0, -2).' ';
								$answer_raw .= $arrA['ANSWER_TEXT'];
							}

							if ($ANSWER_VALUE_EXIST)
							{
								$answer .= '('.$arrA['ANSWER_VALUE'].') ';
								if (!$ANSWER_TEXT_EXIST)
								{
									$answer_raw .= $arrA['ANSWER_VALUE'];
								}
							}

							if (!$ANSWER_VALUE_EXIST && !$ANSWER_TEXT_EXIST)
							{
								$answer_raw .= $arrA['ANSWER_ID'];
							}

							$answer .= '['.$arrA['ANSWER_ID'].']';

						break;

						case 'file':
						case 'image':

							if ($USER_FILE_EXIST)
							{
								$f = CFile::GetByID($arrA["USER_FILE_ID"]);
								if ($fr = $f->Fetch())
								{
									$file_size = CFile::FormatSize($fr["FILE_SIZE"]);
									$url = ($APPLICATION->IsHTTPS() ? "https://" : "http://").$_SERVER["HTTP_HOST"]. "/freetrix/tools/form_show_file.php?rid=".$RESULT_ID. "&hash=".$arrA["USER_FILE_HASH"]."&action=download&lang=".LANGUAGE_ID;

									if ($arrA["USER_FILE_IS_IMAGE"]=="Y")
									{
										$answer .= $arrA["USER_FILE_NAME"]." [".$fr["WIDTH"]." x ".$fr["HEIGHT"]."] (".$file_size.")\n".$url;
									}
									else
									{
										$answer .= $arrA["USER_FILE_NAME"]." (".$file_size.")\n".$url."&action=download";
									}
								}

								$answer_raw .= $arrA['USER_FILE_NAME'];
							}

						break;
					}
				}
			}

			$strResult .= $wr["TITLE"].":\r\n".(strlen($answer)<=0 ? " " : $answer)."\r\n\r\n";
		}

		return $strResult;
	}
Esempio n. 3
0
                if (!$DB->Update("b_form_field", $arFieldsStore, "WHERE ID='" . $ID . "'", $err_mess . __LINE__)) {
                    $DB->Rollback();
                    $lAdmin->AddGroupError(GetMessage("DELETE_ERROR"), $ID);
                }
                $DB->Commit();
                break;
        }
    }
    if (!$_REQUEST["mode"]) {
        LocalRedirect("form_field_list.php?lang=" . LANGUAGE_ID . "&WEB_FORM_ID=" . $WEB_FORM_ID . "&additional=" . $additional);
    }
}
$sDocTitle = $additional == "Y" ? GetMessage("FORM_PAGE_ADDITIONAL_TITLE") : GetMessage("FORM_PAGE_TITLE");
$APPLICATION->SetTitle(str_replace("#ID#", "{$WEB_FORM_ID}", $sDocTitle));
//////////////////////////////////////////////////////////////////////
$rsData = CFormField::GetList($WEB_FORM_ID, $additional, $by, $order, $arFilter, $is_filtered);
$rsData = new CAdminResult($rsData, $sTableID);
$rsData->NavStart();
$lAdmin->NavText($rsData->GetNavPrint($additional == "Y" ? GetMessage("FORM_PAGES") : GetMessage("FORM_PAGES_Q")));
$headers = array();
$headers[] = array("id" => "ID", "content" => "ID", "sort" => "s_id", "default" => true);
$headers[] = array("id" => "ACTIVE", "content" => GetMessage("FORM_ACTIVE"), "sort" => "s_active", "default" => true);
$headers[] = array("id" => "C_SORT", "content" => GetMessage("FORM_C_SORT"), "sort" => "s_sort", "default" => true);
if ($additional != 'Y') {
    $headers[] = array("id" => "REQUIRED", "content" => GetMessage("FORM_REQUIRED"), "sort" => "s_required", "default" => true);
}
if (!$bSimple) {
    $headers[] = array("id" => "SID", "content" => GetMessage("FORM_SID"), "sort" => "s_sid", "default" => true);
}
if ($additional == "Y") {
    $headers[] = array("id" => "TITLE", "content" => GetMessage("FORM_ADDITIONAL_TITLE"), "sort" => "s_title", "default" => true);
Esempio n. 4
0
    $arCRMServers = array();
    $dbRes = CFormCrm::GetList(array('NAME' => 'ASC', 'ID' => 'ASC'), array());
    while ($arServer = $dbRes->Fetch()) {
        $arCRMServers[] = $arServer;
    }
    $dbRes = CFormCrm::GetByFormID($ID);
    $bLinkCreated = false;
    if ($arFormCrmLink = $dbRes->Fetch()) {
        $bLinkCreated = true;
        $dbRes = CFormCrm::GetFields($arFormCrmLink['ID']);
        $arFormCrmFields = array();
        while ($arFld = $dbRes->Fetch()) {
            $arFormCrmFields[] = $arFld;
        }
    }
    $dbRes = CFormField::GetList($ID, 'ALL', $by, $order, array(), $is_filtered);
    $arFormFields = array();
    while ($arFld = $dbRes->Fetch()) {
        $arFormFields[] = $arFld;
    }
    if (false && !$bLinkCreated) {
        ?>
	<tr>
		<td colspan="2" align="center"><?php 
        echo BeginNote(), GetMessage('FORM_CRM_NOT_SET'), EndNote();
        ?>
</td>
	</tr>
<?php 
    } else {
        ?>
Esempio n. 5
0
									<?php 
            }
            //endif(CModule::IncludeModule("statistic"));
            ?>
								</table></td>
							<?php 
        }
        //endif;($F_RIGHT>=25)
        ?>
							<?php 
        if ($res_counter > 0) {
            $arFilter = array("IN_RESULTS_TABLE" => "Y", "RESULT_ID" => implode(" | ", $arRID));
            CForm::GetResultAnswerArray($WEB_FORM_ID, $arrColumns, $arrAnswers, $arrAnswersSID, $arFilter);
        } else {
            $arFilter = array("IN_RESULTS_TABLE" => "Y");
            $rsFields = CFormField::GetList($WEB_FORM_ID, "ALL", $v1 = "s_c_sort", $v2 = "asc", $arFilter, $v3);
            while ($arField = $rsFields->Fetch()) {
                $arrColumns[$arField["ID"]] = $arField;
            }
        }
        $colspan = 4;
        if (is_array($arrColumns)) {
            reset($arrColumns);
            while (list($key, $arrCol) = each($arrColumns)) {
                if (!is_array($arrNOT_SHOW_TABLE) || !in_array($arrCol["SID"], $arrNOT_SHOW_TABLE)) {
                    if ($arrCol["ADDITIONAL"] == "Y" && $SHOW_ADDITIONAL == "Y" || $arrCol["ADDITIONAL"] != "Y") {
                        $colspan++;
                        if (strlen($arrCol["RESULTS_TABLE_TITLE"]) <= 0) {
                            $title = $arrCol["TITLE_TYPE"] == "html" ? strip_tags($arrCol["TITLE"]) : htmlspecialchars($arrCol["TITLE"]);
                            $title = TruncateText($title, 100);
                        } else {
Esempio n. 6
0
	/**
	 * <p>Создает почтовое событие для отсылки данных <a href="http://dev.1c-bitrix.ru/api_help/form/terms.php#result">результата</a> по e-mail. Возвращает "true" в случае успеха, в противном случае - "false".</p>
	 *
	 *
	 *
	 *
	 * @param int $result_id  ID <a href="http://dev.1c-bitrix.ru/api_help/form/terms.php#result">результата</a>.
	 *
	 *
	 *
	 * @param mixed $template_id = false ID почтового шаблона.<br><br> Параметр необязательный. По умолчанию -
	 * "false" (будут использованы почтовые шаблоны из настроек
	 * соответствующей веб-формы).
	 *
	 *
	 *
	 * @return bool 
	 *
	 *
	 * <h4>Example</h4> 
	 * <pre>
	 * &lt;?
	 * $RESULT_ID = 189; // ID результата
	 * 
	 * // создадим почтовое событие для отсылки по EMail данных результата
	 * if (<b>CFormResult::Mail</b>($RESULT_ID))
	 * {
	 *     echo "Почтовое событие успешно создано.";
	 * }
	 * else // ошибка
	 * {
	 *     global $strError;
	 *     echo $strError;
	 * }
	 * ?&gt;
	 * </pre>
	 *
	 *
	 * @static
	 * @link http://dev.1c-bitrix.ru/api_help/form/classes/cformresult/mail.php
	 * @author Bitrix
	 */
	public static function Mail($RESULT_ID, $TEMPLATE_ID = false)
	{
		global $APPLICATION, $DB, $MESS, $strError;

		$err_mess = (CAllFormResult::err_mess())."<br>Function: Mail<br>Line: ";
		$RESULT_ID = intval($RESULT_ID);

		CTimeZone::Disable();
		$arrResult = CFormResult::GetDataByID($RESULT_ID, array(), $arrRES, $arrANSWER);
		CTimeZone::Enable();
		if ($arrResult)
		{
			$z = CForm::GetByID($arrRES["FORM_ID"]);
			if ($arrFORM = $z->Fetch())
			{
				$TEMPLATE_ID = intval($TEMPLATE_ID);

				$arrFormSites = CForm::GetSiteArray($arrRES["FORM_ID"]);
				$arrFormSites = (is_array($arrFormSites)) ? $arrFormSites : array();

				if (!defined('SITE_ID') || !in_array(SITE_ID, $arrFormSites))
					return true;

				$rs = CSite::GetList(($by="sort"), ($order="asc"), array('ID' => implode('|', $arrFormSites)));
				$arrSites = array();
				while ($ar = $rs->Fetch())
				{
					if ($ar["DEF"]=="Y") $def_site_id = $ar["ID"];
					$arrSites[$ar["ID"]] = $ar;
				}

				$arrFormTemplates = CForm::GetMailTemplateArray($arrRES["FORM_ID"]);
				$arrFormTemplates = (is_array($arrFormTemplates)) ? $arrFormTemplates : array();

				$arrTemplates = array();
				$rs = CEventMessage::GetList($by="id", $order="asc", array(
					"ACTIVE"		=> "Y",
					"SITE_ID"		=> SITE_ID,
					"EVENT_NAME"	=> $arrFORM["MAIL_EVENT_TYPE"]
					));

				while ($ar = $rs->Fetch())
				{
					if ($TEMPLATE_ID>0)
					{
						if ($TEMPLATE_ID == $ar["ID"])
						{
							$arrTemplates[$ar["ID"]] = $ar;
							break;
						}
					}
					elseif (in_array($ar["ID"],$arrFormTemplates)) $arrTemplates[$ar["ID"]] = $ar;
				}

				foreach($arrTemplates as $arrTemplate)
				{

					$OLD_MESS = $MESS;
					$MESS = array();
					IncludeModuleLangFile($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/form/admin/form_mail.php", $arrSites[$arrTemplate["SITE_ID"]]["LANGUAGE_ID"]);

					$USER_AUTH = " ";
					if (intval($arrRES["USER_ID"])>0)
					{
						$w = CUser::GetByID($arrRES["USER_ID"]);
						$arrUSER = $w->Fetch();
						$USER_ID = $arrUSER["ID"];
						$USER_EMAIL = $arrUSER["EMAIL"];
						$USER_NAME = $arrUSER["NAME"]." ".$arrUSER["LAST_NAME"];
						if ($arrRES["USER_AUTH"]!="Y") $USER_AUTH="(".GetMessage("FORM_NOT_AUTHORIZED").")";
					}
					else
					{
						$USER_ID = GetMessage("FORM_NOT_REGISTERED");
						$USER_NAME = "";
						$USER_AUTH = "";
						$USER_EMAIL = "";
					}

					$arEventFields = array(
						"RS_FORM_ID"			=> $arrFORM["ID"],
						"RS_FORM_NAME"			=> $arrFORM["NAME"],
						"RS_FORM_VARNAME"		=> $arrFORM["SID"],
						"RS_FORM_SID"			=> $arrFORM["SID"],
						"RS_RESULT_ID"			=> $arrRES["ID"],
						"RS_DATE_CREATE"		=> $arrRES["DATE_CREATE"],
						"RS_USER_ID"			=> $USER_ID,
						"RS_USER_EMAIL"			=> $USER_EMAIL,
						"RS_USER_NAME"			=> $USER_NAME,
						"RS_USER_AUTH"			=> $USER_AUTH,
						"RS_STAT_GUEST_ID"		=> $arrRES["STAT_GUEST_ID"],
						"RS_STAT_SESSION_ID"	=> $arrRES["STAT_SESSION_ID"]
						);
					$w = CFormField::GetList($arrFORM["ID"], "ALL", $by, $order, array(), $is_filtered);
					while ($wr=$w->Fetch())
					{
						$answer = "";
						$answer_raw = '';
						if (is_array($arrResult[$wr["SID"]]))
						{
							//echo '<pre>'; print_r($wr); echo '</pre>';
							//echo '<pre>'; print_r($arrResult[$wr['SID']]);

							$bHasDiffTypes = false;
							$lastType = '';
							foreach ($arrResult[$wr['SID']] as $arrA)
							{
								if ($lastType == '') $lastType = $arrA['FIELD_TYPE'];
								elseif ($arrA['FIELD_TYPE'] != $lastType)
								{
									$bHasDiffTypes = true;
									break;
								}
							}

							foreach($arrResult[$wr["SID"]] as $arrA)
							{
								if ($wr['ADDITIONAL'] == 'Y')
									$arrA['FIELD_TYPE'] = $wr['FIELD_TYPE'];

								$USER_TEXT_EXIST = (strlen(trim($arrA["USER_TEXT"]))>0);
								$ANSWER_TEXT_EXIST = (strlen(trim($arrA["ANSWER_TEXT"]))>0);
								$ANSWER_VALUE_EXIST = (strlen(trim($arrA["ANSWER_VALUE"]))>0);
								$USER_FILE_EXIST = (intval($arrA["USER_FILE_ID"])>0);

								//echo 'USER_TEXT_EXIST '.$USER_TEXT_EXIST.' '.$USER_TEXT.'<br />';
								//echo 'ANSWER_TEXT_EXIST '.$ANSWER_TEXT_EXIST.' '.$ANSWER_TEXT.'<br />';
								//echo 'ANSWER_VALUE_EXIST '.$ANSWER_VALUE_EXIST.' '.$ANSWER_VALUE.'<br />';
								//echo 'USER_FILE_EXIST '.$USER_FILE_EXIST.' '.$USER_FILE.'<br />';

								if ($arrTemplate["BODY_TYPE"]=="html")
								{
									if (
										$bHasDiffTypes
										&&
										!$USER_TEXT_EXIST
										&&
										(
											$arrA['FIELD_TYPE'] == 'text'
											||
											$arrA['FIELD_TYPE'] == 'textarea'
										)
									)
										continue;

									if (strlen(trim($answer))>0) $answer .= "<br />";
									if (strlen(trim($answer_raw))>0) $answer_raw .= ",";

									if ($ANSWER_TEXT_EXIST)
										$answer .= $arrA["ANSWER_TEXT"].': ';

									switch ($arrA['FIELD_TYPE'])
									{
										case 'text':
										case 'textarea':
										case 'hidden':
										case 'date':
										case 'password':
										case 'integer':

											if ($USER_TEXT_EXIST)
											{
												$answer .= trim($arrA["USER_TEXT"]);
												$answer_raw .= trim($arrA["USER_TEXT"]);
											}

										break;

										case 'email':
										case 'url':

											if ($USER_TEXT_EXIST)
											{
												$answer .= '<a href="'.($arrA['FIELD_TYPE'] == 'email' ? 'mailto:' : '').trim($arrA["USER_TEXT"]).'">'.trim($arrA["USER_TEXT"]).'</a>';
												$answer_raw .= trim($arrA["USER_TEXT"]);
											}

										break;

										case 'checkbox':
										case 'multiselect':
										case 'radio':
										case 'dropdown':

											if ($ANSWER_TEXT_EXIST)
											{
												$answer = substr($answer, 0, -2).' ';
												$answer_raw .= $arrA['ANSWER_TEXT'];
											}

											if ($ANSWER_VALUE_EXIST)
											{
												$answer .= '('.$arrA['ANSWER_VALUE'].') ';
												if (!$ANSWER_TEXT_EXIST)
													$answer_raw .= $arrA['ANSWER_VALUE'];
											}

											if (!$ANSWER_VALUE_EXIST && !$ANSWER_TEXT_EXIST)
												$answer_raw .= $arrA['ANSWER_ID'];

											$answer .= '['.$arrA['ANSWER_ID'].']';

										break;

										case 'file':
										case 'image':

											if ($USER_FILE_EXIST)
											{
												$f = CFile::GetByID($arrA["USER_FILE_ID"]);
												if ($fr = $f->Fetch())
												{
													$file_size = CFile::FormatSize($fr["FILE_SIZE"]);
													$url = ($APPLICATION->IsHTTPS() ? "https://" : "http://").$_SERVER["HTTP_HOST"]. "/bitrix/tools/form_show_file.php?rid=".$RESULT_ID. "&hash=".$arrA["USER_FILE_HASH"]."&lang=".LANGUAGE_ID;

													if ($arrA["USER_FILE_IS_IMAGE"]=="Y")
													{
														$answer .= "<a href=\"$url\">".$arrA["USER_FILE_NAME"]."</a> [".$fr["WIDTH"]." x ".$fr["HEIGHT"]."] (".$file_size.")";
													}
													else
													{
														$answer .= "<a href=\"$url&action=download\">".$arrA["USER_FILE_NAME"]."</a> (".$file_size.")";
													}

													$answer_raw .= $arrA['USER_FILE_NAME'];
												}
											}

										break;
									}
								}
								else
								{
									//echo $bHasDiffTypes.'*'.$USER_TEXT_EXIST.'<br />';

									if (
										$bHasDiffTypes
										&&
										!$USER_TEXT_EXIST
										&&
										(
											$arrA['FIELD_TYPE'] == 'text'
											||
											$arrA['FIELD_TYPE'] == 'textarea'
										)
									)
										continue;

									if (strlen(trim($answer)) > 0) $answer .= "\n";
									if (strlen(trim($answer_raw)) > 0) $answer_raw .= ",";

									if ($ANSWER_TEXT_EXIST)
										$answer .= $arrA["ANSWER_TEXT"].': ';

									switch ($arrA['FIELD_TYPE'])
									{
										case 'text':
										case 'textarea':
										case 'email':
										case 'url':
										case 'hidden':
										case 'date':
										case 'password':
										case 'integer':

											if ($USER_TEXT_EXIST)
											{
												$answer .= trim($arrA["USER_TEXT"]);
												$answer_raw .= trim($arrA["USER_TEXT"]);
											}

										break;

										case 'checkbox':
										case 'multiselect':
										case 'radio':
										case 'dropdown':

											if ($ANSWER_TEXT_EXIST)
											{
												$answer = substr($answer, 0, -2).' ';
												$answer_raw .= $arrA['ANSWER_TEXT'];
											}

											if ($ANSWER_VALUE_EXIST)
											{
												$answer .= '('.$arrA['ANSWER_VALUE'].') ';
												if (!$ANSWER_TEXT_EXIST)
												{
													$answer_raw .= $arrA['ANSWER_VALUE'];
												}
											}

											if (!$ANSWER_VALUE_EXIST && !$ANSWER_TEXT_EXIST)
											{
												$answer_raw .= $arrA['ANSWER_ID'];
											}

											$answer .= '['.$arrA['ANSWER_ID'].']';

										break;

										case 'file':
										case 'image':

											if ($USER_FILE_EXIST)
											{
												$f = CFile::GetByID($arrA["USER_FILE_ID"]);
												if ($fr = $f->Fetch())
												{
													$file_size = CFile::FormatSize($fr["FILE_SIZE"]);
													$url = ($APPLICATION->IsHTTPS() ? "https://" : "http://").$_SERVER["HTTP_HOST"]. "/bitrix/tools/form_show_file.php?rid=".$RESULT_ID. "&hash=".$arrA["USER_FILE_HASH"]."&action=download&lang=".LANGUAGE_ID;

													if ($arrA["USER_FILE_IS_IMAGE"]=="Y")
													{
														$answer .= $arrA["USER_FILE_NAME"]." [".$fr["WIDTH"]." x ".$fr["HEIGHT"]."] (".$file_size.")\n".$url;
													}
													else
													{
														$answer .= $arrA["USER_FILE_NAME"]." (".$file_size.")\n".$url."&action=download";
													}
												}

												$answer_raw .= $arrA['USER_FILE_NAME'];
											}

										break;
									}
								}
							}
						}

						$arEventFields[$wr["SID"]] = (strlen($answer)<=0) ? " " : $answer;
						$arEventFields[$wr["SID"].'_RAW'] = (strlen($answer_raw)<=0) ? " " : $answer_raw;
					}

					CEvent::Send($arrTemplate["EVENT_NAME"], $arrTemplate["SITE_ID"], $arEventFields, "Y", $arrTemplate["ID"]);
					$MESS = $OLD_MESS;
				} //foreach($arrTemplates as $arrTemplate)
				return true;
			}
			else $strError .= GetMessage("FORM_ERROR_FORM_NOT_FOUND")."<br>";
		}
		else $strError .= GetMessage("FORM_ERROR_RESULT_NOT_FOUND")."<br>";
		return false;
	}
Esempio n. 7
0
 function GetFieldList($WEB_FORM_ID, $additional, &$by, &$order, $arFilter = array(), &$is_filtered)
 {
     return CFormField::GetList($WEB_FORM_ID, $additional, $by, $order, $arFilter, $is_filtered);
 }
Esempio n. 8
0
	function GetList($WEB_FORM_ID, &$by, &$order, $arFilter=Array(), &$is_filtered, $CHECK_RIGHTS="Y", $records_limit=false)
	{
		$err_mess = (CFormResult::err_mess())."<br>Function: GetList<br>Line: ";
		global $DB, $USER, $strError;

		$CHECK_RIGHTS = ($CHECK_RIGHTS=="Y") ? "Y" : "N";
		$WEB_FORM_ID = intval($WEB_FORM_ID);

		$F_RIGHT = CForm::GetPermission($WEB_FORM_ID);

		$USER_ID = intval($USER->GetID());
		$arSqlSearch = array();
		$arr["FIELDS"] = array();
		$strSqlSearch = "";
		if (is_array($arFilter))
		{
			$arFilter = CFormResult::PrepareFilter($WEB_FORM_ID, $arFilter);

			$z = CForm::GetByID($WEB_FORM_ID);
			$form = $z->Fetch();

			/***********************/

			$z = CFormField::GetList($WEB_FORM_ID, "", $v1, $v2, array(), $v3);

			while ($zr=$z->Fetch())
			{
				$arPARAMETER_NAME = array("ANSWER_TEXT", "ANSWER_VALUE", "USER");
				CFormField::GetFilterTypeList($arrUSER, $arrANSWER_TEXT, $arrANSWER_VALUE, $arrFIELD);
				foreach ($arPARAMETER_NAME as $PARAMETER_NAME)
				{
					switch ($PARAMETER_NAME)
					{
						case "ANSWER_TEXT":
							$arFILTER_TYPE = $arrANSWER_TEXT["reference_id"];
							break;
						case "ANSWER_VALUE":
							$arFILTER_TYPE = $arrANSWER_VALUE["reference_id"];
							break;
						case "USER":
							$arFILTER_TYPE = $arrUSER["reference_id"];
							break;
					}
					foreach ($arFILTER_TYPE as $FILTER_TYPE)
					{
						$arrUF = array();
						$arrUF["ID"] = $zr["ID"];
						$arrUF["PARAMETER_NAME"] = $PARAMETER_NAME;
						$arrUF["FILTER_TYPE"] = $FILTER_TYPE;
						$FID = $form["SID"]."_".$zr["SID"]."_".$PARAMETER_NAME."_".$FILTER_TYPE;
						if ($FILTER_TYPE=="date" || $FILTER_TYPE=="integer")
						{
							$arrUF["SIDE"] = "1";
							$arrFORM_FILTER[$FID."_1"] = $arrUF;
							$arrUF["SIDE"] = "2";
							$arrFORM_FILTER[$FID."_2"] = $arrUF;
							$arrUF["SIDE"] = "0";
							$arrFORM_FILTER[$FID."_0"] = $arrUF;
						}
						else $arrFORM_FILTER[$FID] = $arrUF;
					}
				}
			}
			if (is_array($arrFORM_FILTER)) $arrFORM_FILTER_KEYS = array_keys($arrFORM_FILTER);

			//echo "arFilter:<pre>"; print_r($arFilter); echo "</pre>";
			//echo "arrFORM_FILTER:<pre>"; print_r($arrFORM_FILTER); echo "</pre>";
			//echo "arrFORM_FILTER_KEYS:<pre>"; print_r($arrFORM_FILTER_KEYS); echo "</pre>";

			$t = 0;
			$filter_keys = array_keys($arFilter);
			for ($i=0; $i<count($filter_keys); $i++)
			{
				$key = $filter_keys[$i];
				$val = $arFilter[$filter_keys[$i]];
				if(is_array($val))
				{
					if(count($val) <= 0)
						continue;
				}
				else
				{
				if( (strlen($val) <= 0) || ($val === "NOT_REF") )
					continue;
				}
				$match_value_set = (in_array($key."_EXACT_MATCH", $filter_keys)) ? true : false;
				$key = strtoupper($key);
				switch($key)
				{
					case "ID":
						$match = ($arFilter[$key."_EXACT_MATCH"]=="N" && $match_value_set) ? "Y" : "N";
						$arSqlSearch[] = GetFilterQuery("R.ID", $val, $match);
						break;
					case "STATUS":
						$arSqlSearch[] = "R.STATUS_ID='".intval($val)."'";
						break;
					case "STATUS_ID":
						$match = ($arFilter[$key."_EXACT_MATCH"]=="N" && $match_value_set) ? "Y" : "N";
						$arSqlSearch[] = GetFilterQuery("R.STATUS_ID", $val, $match);
						break;
					case "TIMESTAMP_1":
						$arSqlSearch[] = "R.TIMESTAMP_X>=".$DB->CharToDateFunction($val, "SHORT");
						break;
					case "TIMESTAMP_2":
						$arSqlSearch[] = "R.TIMESTAMP_X<".$DB->CharToDateFunction($val, "SHORT")." + INTERVAL 1 DAY";
						break;
					case "DATE_CREATE_1":
						$arSqlSearch[] = "R.DATE_CREATE>=".$DB->CharToDateFunction($val, "SHORT");
						break;
					case "DATE_CREATE_2":
						$arSqlSearch[] = "R.DATE_CREATE<".$DB->CharToDateFunction($val, "SHORT")." + INTERVAL 1 DAY";
						break;
					case "TIME_CREATE_1":
						$arSqlSearch[] = "R.DATE_CREATE>=".$DB->CharToDateFunction($val, "FULL");
						break;
					case "TIME_CREATE_2":
						$arSqlSearch[] = "R.DATE_CREATE<".$DB->CharToDateFunction($val, "FULL");
						break;
					case "REGISTERED":
						$arSqlSearch[] = ($val=="Y") ? "R.USER_ID>0" : "(R.USER_ID<=0 or R.USER_ID is null)";
						break;
					case "USER_AUTH":
						$arSqlSearch[] = ($val=="Y") ? "(R.USER_AUTH='Y' and R.USER_ID>0)" : "(R.USER_AUTH='N' and R.USER_ID>0)";
						break;
					case "USER_ID":
						$match = ($arFilter[$key."_EXACT_MATCH"]=="N" && $match_value_set) ? "Y" : "N";
						$arSqlSearch[] = GetFilterQuery("R.USER_ID", $val, $match);
						break;
					case "GUEST_ID":
						$match = ($arFilter[$key."_EXACT_MATCH"]=="N" && $match_value_set) ? "Y" : "N";
						$arSqlSearch[] = GetFilterQuery("R.STAT_GUEST_ID", $val, $match);
						break;
					case "SESSION_ID":
						$match = ($arFilter[$key."_EXACT_MATCH"]=="N" && $match_value_set) ? "Y" : "N";
						$arSqlSearch[] = GetFilterQuery("R.STAT_SESSION_ID", $val, $match);
						break;
					case "SENT_TO_CRM":
						$arSqlSearch[] = GetFilterQuery("R.SENT_TO_CRM", $val, "Y");
						break;
					default:
						if (is_array($arrFORM_FILTER))
						{
							$key = $filter_keys[$i];
							if (in_array($key, $arrFORM_FILTER_KEYS))
							{
								$arrF = $arrFORM_FILTER[$key];
								if (is_array($arr["FIELDS"]) && !in_array($arrF["ID"],$arr["FIELDS"]))
								{
									$t++;
									$A = "A".$t;
									$arr["TABLES"][] = "b_form_result_answer ".$A;
									$arr["WHERE"][] = "(".$A.".RESULT_ID=R.ID and ".$A.".FIELD_ID='".$arrF["ID"]."')";
									$arr["FIELDS"][] = $arrF["ID"];
								}
								switch(strtoupper($arrF["FILTER_TYPE"]))
								{
									case "EXIST":

										if ($arrF["PARAMETER_NAME"]=="ANSWER_TEXT")
											$arSqlSearch[] = "length(".$A.".ANSWER_TEXT)+0>0";

										elseif ($arrF["PARAMETER_NAME"]=="ANSWER_VALUE")
											$arSqlSearch[] = "length(".$A.".ANSWER_VALUE)+0>0";

										elseif ($arrF["PARAMETER_NAME"]=="USER")
											$arSqlSearch[] = "length(".$A.".USER_TEXT)+0>0";

										break;
									case "TEXT":
										$match = ($arFilter[$key."_exact_match"]=="Y") ? "N" : "Y";
										$sql = "";

										if ($arrF["PARAMETER_NAME"]=="ANSWER_TEXT")
											$sql = GetFilterQuery($A.".ANSWER_TEXT_SEARCH", ToUpper($val), $match);

										elseif ($arrF["PARAMETER_NAME"]=="ANSWER_VALUE")
											$sql = GetFilterQuery($A.".ANSWER_VALUE_SEARCH", ToUpper($val), $match);

										elseif ($arrF["PARAMETER_NAME"]=="USER")
											$sql = GetFilterQuery($A.".USER_TEXT_SEARCH", ToUpper($val), $match);

										if ($sql!=="0" && strlen(trim($sql))>0) $arSqlSearch[] = $sql;
										break;
									case "DROPDOWN":
									case "ANSWER_ID":
											$arSqlSearch[] = $A.".ANSWER_ID=".intval($val);
										break;
									case "DATE":
										if ($arrF["PARAMETER_NAME"]=="USER")
										{
											if (CheckDateTime($val))
											{
												if ($arrF["SIDE"]=="1")
													$arSqlSearch[] = $A.".USER_DATE>=".$DB->CharToDateFunction($val, "SHORT");
												elseif ($arrF["SIDE"]=="2")
													$arSqlSearch[] = $A.".USER_DATE<".$DB->CharToDateFunction($val, "SHORT")." + INTERVAL 1 DAY";
												elseif ($arrF["SIDE"]=="0")
													$arSqlSearch[] = $A.".USER_DATE=".$DB->CharToDateFunction($val);
											}
										}
										break;
									case "INTEGER":
										if ($arrF["PARAMETER_NAME"]=="USER")
										{
											if ($arrF["SIDE"]=="1")
												$arSqlSearch[] = $A.".USER_TEXT+0>=".intval($val);
											elseif ($arrF["SIDE"]=="2")
												$arSqlSearch[] = $A.".USER_TEXT+0<=".intval($val);
											elseif ($arrF["SIDE"]=="0")
												$arSqlSearch[] = $A.".USER_TEXT='".intval($val)."'";
										}
										elseif ($arrF["PARAMETER_NAME"]=="ANSWER_TEXT")
										{
											if ($arrF["SIDE"]=="1")
												$arSqlSearch[] = $A.".ANSWER_TEXT+0>=".intval($val);
											elseif ($arrF["SIDE"]=="2")
												$arSqlSearch[] = $A.".ANSWER_TEXT+0<=".intval($val);
											elseif ($arrF["SIDE"]=="0")
												$arSqlSearch[] = $A.".ANSWER_TEXT='".intval($val)."'";
										}
										elseif ($arrF["PARAMETER_NAME"]=="ANSWER_VALUE")
										{
											if ($arrF["SIDE"]=="1")
												$arSqlSearch[] = $A.".ANSWER_VALUE+0>=".intval($val);
											elseif ($arrF["SIDE"]=="2")
												$arSqlSearch[] = $A.".ANSWER_VALUE+0<=".intval($val);
											elseif ($arrF["SIDE"]=="0")
												$arSqlSearch[] = $A.".ANSWER_VALUE='".intval($val)."'";
										}
										break;
								}
							}
						}
				}
			}
		}
		if ($by == "s_id")				$strSqlOrder = "ORDER BY R.ID";
		elseif ($by == "s_date_create")	$strSqlOrder = "ORDER BY R.DATE_CREATE";
		elseif ($by == "s_timestamp")	$strSqlOrder = "ORDER BY R.TIMESTAMP_X";
		elseif ($by == "s_user_id")		$strSqlOrder = "ORDER BY R.USER_ID";
		elseif ($by == "s_guest_id")	$strSqlOrder = "ORDER BY R.STAT_GUEST_ID";
		elseif ($by == "s_session_id")	$strSqlOrder = "ORDER BY R.STAT_SESSION_ID";
		elseif ($by == "s_status")		$strSqlOrder = "ORDER BY R.STATUS_ID";
		elseif ($by == "s_sent_to_crm")	$strSqlOrder = "ORDER BY R.SENT_TO_CRM";
		else
		{
			$by = "s_timestamp";
			$strSqlOrder = "ORDER BY R.TIMESTAMP_X";
		}
		if ($order!="asc")
		{
			$strSqlOrder .= " desc ";
			$order="desc";
		}
		$strSqlSearch = GetFilterSqlSearch($arSqlSearch);
		if (is_array($arr["TABLES"]))
			$str1 = implode(",\n				",$arr["TABLES"]);
		if (is_array($arr["WHERE"]))
			$str2 = implode("\n			and ",$arr["WHERE"]);
		if (strlen($str1)>0) $str1 = ",\n				".$str1;
		if (strlen($str2)>0) $str2 = "\n			and ".$str2;

		if ($records_limit===false)
		{
			$records_limit = "LIMIT ".intval(COption::GetOptionString("form","RECORDS_LIMIT"));
		}
		else
		{
			$records_limit = intval($records_limit);
			if ($records_limit>0)
			{
				$records_limit = "LIMIT ".$records_limit;
			}
		}

		//this hack is for mysql <3.23. we no longer support that dino.
		//$DB->Query("SET SQL_BIG_TABLES=1", false, $err_mess.__LINE__);
		if ($CHECK_RIGHTS!="Y" || $F_RIGHT >= 30 || CForm::IsAdmin())
		{
			$strSql = "
				SELECT
					R.ID, R.USER_ID, R.USER_AUTH, R.STAT_GUEST_ID, R.STAT_SESSION_ID, R.STATUS_ID, R.SENT_TO_CRM,
					".$DB->DateToCharFunction("R.DATE_CREATE")."	DATE_CREATE,
					".$DB->DateToCharFunction("R.TIMESTAMP_X")."	TIMESTAMP_X,
					S.TITLE				STATUS_TITLE,
					S.CSS				STATUS_CSS
				FROM
					b_form_result R,
					b_form_status S
					$str1
				WHERE
				$strSqlSearch
				$str2
				and R.FORM_ID = '$WEB_FORM_ID'
				and S.ID = R.STATUS_ID
				GROUP BY
					R.ID, R.USER_ID, R.USER_AUTH, R.STAT_GUEST_ID, R.STAT_SESSION_ID, R.DATE_CREATE, R.STATUS_ID, R.SENT_TO_CRM
				$strSqlOrder
				$records_limit
				";
			$res = $DB->Query($strSql, false, $err_mess.__LINE__);
			//echo '<pre>'.$strSql.'</pre>';
		}
		elseif ($F_RIGHT>=15)
		{
			$arGroups = $USER->GetUserGroupArray();
			if (!is_array($arGroups)) $arGroups[] = 2;
			if (is_array($arGroups) && count($arGroups)>0) $groups = implode(",",$arGroups);
			if ($F_RIGHT<20) $str3 = "and ifnull(R.USER_ID,0) = $USER_ID";

			$strSql = "
				SELECT
					R.ID, R.USER_ID, R.USER_AUTH, R.STAT_GUEST_ID, R.STAT_SESSION_ID, R.STATUS_ID, R.SENT_TO_CRM,
					".$DB->DateToCharFunction("R.DATE_CREATE")."	DATE_CREATE,
					".$DB->DateToCharFunction("R.TIMESTAMP_X")."	TIMESTAMP_X,
					S.TITLE				STATUS_TITLE,
					S.CSS				STATUS_CSS
				FROM
					b_form_result R,
					b_form_status S,
					b_form_status_2_group G$str1
				WHERE
				$strSqlSearch
				$str2
				$str3
				and R.FORM_ID = '$WEB_FORM_ID'
				and S.ID = R.STATUS_ID
				and G.STATUS_ID = S.ID
				and (
					(G.GROUP_ID in ($groups)) or
					(G.GROUP_ID in ($groups,0) and ifnull(R.USER_ID,0) = $USER_ID and $USER_ID>0)
					)
				and G.PERMISSION in ('VIEW', 'EDIT', 'DELETE')
				GROUP BY
					R.ID, R.USER_ID, R.USER_AUTH, R.STAT_GUEST_ID,
					R.STAT_SESSION_ID, R.SENT_TO_CRM, R.DATE_CREATE, R.STATUS_ID, R.SENT_TO_CRM
				$strSqlOrder
				$records_limit
				";
			$res = $DB->Query($strSql, false, $err_mess.__LINE__);
		}
		else
		{
			$res = new CDBResult();
			$res->InitFromArray(array());
		}
		//echo "<pre>".$strSql."</pre>";
		//echo "<pre>".$strSqlSearch."</pre>";
		$is_filtered = (IsFiltered($strSqlSearch));
		return $res;
	}
Esempio n. 9
0
<?php

if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) {
    die;
}
if (!CModule::IncludeModule("form")) {
    return;
}
$arrForms = array();
$rsForm = CForm::GetList($by = 's_sort', $order = 'asc', !empty($_REQUEST["site"]) ? array("SITE" => $_REQUEST["site"]) : array(), $v3);
while ($arForm = $rsForm->Fetch()) {
    $arrForms[$arForm["ID"]] = "[" . $arForm["ID"] . "] " . $arForm["NAME"];
}
if (intval($arCurrentValues["WEB_FORM_ID"]) > 0) {
    $show_list = true;
    $rsFieldList = CFormField::GetList(intval($arCurrentValues["WEB_FORM_ID"]), "ALL", $by = "s_sort", $order = "asc", array(), $is_filtered);
    $arFieldList = array();
    while ($arField = $rsFieldList->GetNext()) {
        $arFieldList[$arField["SID"]] = "[" . $arField["SID"] . "] " . $arField["TITLE"];
    }
} else {
    $show_list = false;
}
$arYesNo = array("Y" => GetMessage("FORM_COMP_VALUE_YES"), "N" => GetMessage("FORM_COMP_VALUE_NO"));
$arComponentParameters = array("GROUPS" => array("FORM_PARAMS" => array("NAME" => GetMessage("COMP_FORM_GROUP_PARAMS"))), "PARAMETERS" => array("VARIABLE_ALIASES" => array(), "SEF_MODE" => array(), "WEB_FORM_ID" => array("NAME" => GetMessage("COMP_FORM_PARAMS_WEB_FORM_ID"), "TYPE" => "LIST", "VALUES" => $arrForms, "REFRESH" => "Y", "ADDITIONAL_VALUES" => "Y", "DEFAULT" => "={\$_REQUEST[WEB_FORM_ID]}", "PARENT" => "DATA_SOURCE"), "VIEW_URL" => array("NAME" => GetMessage("COMP_FORM_PARAMS_VIEW_URL"), "TYPE" => "STRING", "DEFAULT" => "result_view.php", "PARENT" => "FORM_PARAMS"), "EDIT_URL" => array("NAME" => GetMessage("COMP_FORM_PARAMS_EDIT_URL"), "TYPE" => "STRING", "DEFAULT" => "result_edit.php", "PARENT" => "FORM_PARAMS"), "NEW_URL" => array("NAME" => GetMessage("COMP_FORM_PARAMS_NEW_URL"), "TYPE" => "STRING", "DEFAULT" => "result_new.php", "PARENT" => "FORM_PARAMS"), "SHOW_ADDITIONAL" => array("NAME" => GetMessage("COMP_FORM_PARAMS_SHOW_ADDITIONAL"), "TYPE" => "CHECKBOX", "ADDITIONAL_VALUES" => "N", "DEFAULT" => "N", "PARENT" => "FORM_PARAMS"), "SHOW_ANSWER_VALUE" => array("NAME" => GetMessage("COMP_FORM_PARAMS_SHOW_ANSWER_VALUE"), "TYPE" => "CHECKBOX", "ADDITIONAL_VALUES" => "N", "DEFAULT" => "N", "PARENT" => "FORM_PARAMS"), "SHOW_STATUS" => array("NAME" => GetMessage("COMP_FORM_PARAMS_SHOW_STATUS"), "TYPE" => "CHECKBOX", "ADDITIONAL_VALUES" => "N", "DEFAULT" => "Y", "PARENT" => "FORM_PARAMS"), "NOT_SHOW_FILTER" => array("NAME" => $show_list ? GetMessage("COMP_FORM_PARAMS_NOT_SHOW_FILTER_LIST") : GetMessage("COMP_FORM_PARAMS_NOT_SHOW_FILTER"), "TYPE" => $show_list ? "LIST" : "STRING", "MULTIPLE" => $show_list ? "Y" : "", "VALUES" => $show_list ? $arFieldList : "", "ADDITIONAL_VALUES" => $show_list ? "Y" : "", "DEFAULT" => "", "PARENT" => "FORM_PARAMS"), "NOT_SHOW_TABLE" => array("NAME" => $show_list ? GetMessage("COMP_FORM_PARAMS_NOT_SHOW_TABLE_LIST") : GetMessage("COMP_FORM_PARAMS_NOT_SHOW_TABLE_LIST"), "TYPE" => $show_list ? "LIST" : "STRING", "MULTIPLE" => $show_list ? "Y" : "", "VALUES" => $show_list ? $arFieldList : "", "ADDITIONAL_VALUES" => $show_list ? "Y" : "", "DEFAULT" => "", "PARENT" => "FORM_PARAMS"), "CHAIN_ITEM_TEXT" => array("NAME" => GetMessage("COMP_FORM_PARAMS_CHAIN_ITEM_TEXT"), "TYPE" => "STRING", "DEFAULT" => "", "PARENT" => "FORM_PARAMS"), "CHAIN_ITEM_LINK" => array("NAME" => GetMessage("COMP_FORM_PARAMS_CHAIN_ITEM_LINK"), "TYPE" => "STRING", "DEFAULT" => "", "PARENT" => "FORM_PARAMS")));
Esempio n. 10
0
    /**
     * @return string
     */
    public function getForm()
    {
        /*
         * select form list
         */
        $formList = array();
        $formDb = \CForm::GetList($by = "s_sort", $order = "asc", array(), $filtered);
        while ($form = $formDb->Fetch()) {
            $formList[] = array('ID' => $form['ID'], 'NAME' => $form['NAME']);
        }
        if (!empty($formList)) {
            $formList = array_merge(array(array('ID' => '', 'NAME' => Loc::getMessage('sender_connector_form_select'))), $formList);
        } else {
            $formList = array_merge(array(array('ID' => '', 'NAME' => Loc::getMessage('sender_connector_form_empty'))), $formList);
        }
        /*
         * select properties from all forms
         */
        $propertyToForm = array();
        $propertyList = array();
        $propertyList[''][] = array('ID' => '', 'NAME' => Loc::getMessage('sender_connector_form_select'));
        $propertyList['EMPTY'][] = array('ID' => '', 'NAME' => Loc::getMessage('sender_connector_form_prop_empty'));
        foreach ($formList as $form) {
            if (empty($form['ID'])) {
                continue;
            }
            $formFieldsDb = \CFormField::GetList($form['ID'], 'N', $by = "s_sort", $order = "asc", array(), $filtered);
            while ($formFields = $formFieldsDb->Fetch()) {
                if ($formFields['TITLE_TYPE'] != 'text') {
                    continue;
                }
                // add default value
                if (!array_key_exists($formFields['FORM_ID'], $propertyList)) {
                    $propertyList[$formFields['FORM_ID']][] = array('ID' => '', 'NAME' => Loc::getMessage('sender_connector_form_field_select'));
                }
                // add property
                $propertyList[$formFields['FORM_ID']][] = array('ID' => $formFields['ID'], 'NAME' => $formFields['TITLE']);
                // add property link to iblock
                $propertyToForm[$formFields['ID']] = $formFields['FORM_ID'];
            }
        }
        /*
         * create html-control of form list
         */
        $formInput = '<select name="' . $this->getFieldName('FORM') . '" id="' . $this->getFieldId('FORM') . '" onChange="FormSelect' . $this->getFieldId('FORM') . '()">';
        foreach ($formList as $form) {
            $inputSelected = $form['ID'] == $this->getFieldValue('FORM') ? 'selected' : '';
            $formInput .= '<option value="' . $form['ID'] . '" ' . $inputSelected . '>';
            $formInput .= htmlspecialcharsbx($form['NAME']);
            $formInput .= '</option>';
        }
        $formInput .= '</select>';
        /*
         * create html-control of properties list for name
         */
        $formPropertyNameInput = '<select name="' . $this->getFieldName('PROPERTY_NAME') . '" id="' . $this->getFieldId('PROPERTY_NAME') . '">';
        if (array_key_exists($this->getFieldValue('PROPERTY_NAME', 0), $propertyToForm)) {
            $arProp = $propertyList[$propertyToForm[$this->getFieldValue('PROPERTY_NAME', 0)]];
        } else {
            $arProp = $propertyList[''];
        }
        foreach ($arProp as $property) {
            $inputSelected = $property['ID'] == $this->getFieldValue('PROPERTY_NAME') ? 'selected' : '';
            $formPropertyNameInput .= '<option value="' . $property['ID'] . '" ' . $inputSelected . '>';
            $formPropertyNameInput .= htmlspecialcharsbx($property['NAME']);
            $formPropertyNameInput .= '</option>';
        }
        $formPropertyNameInput .= '</select>';
        /*
         *  create html-control of properties list for email
         */
        $formPropertyEmailInput = '<select name="' . $this->getFieldName('PROPERTY_EMAIL') . '" id="' . $this->getFieldId('PROPERTY_EMAIL') . '">';
        if (array_key_exists($this->getFieldValue('PROPERTY_EMAIL', 0), $propertyToForm)) {
            $arProp = $propertyList[$propertyToForm[$this->getFieldValue('PROPERTY_EMAIL', 0)]];
        } else {
            $arProp = $propertyList[''];
        }
        foreach ($arProp as $property) {
            $inputSelected = $property['ID'] == $this->getFieldValue('PROPERTY_EMAIL') ? 'selected' : '';
            $formPropertyEmailInput .= '<option value="' . $property['ID'] . '" ' . $inputSelected . '>';
            $formPropertyEmailInput .= htmlspecialcharsbx($property['NAME']);
            $formPropertyEmailInput .= '</option>';
        }
        $formPropertyEmailInput .= '</select>';
        $jsScript = "\n\t\t<script>\n\t\t\tfunction FormSelect" . $this->getFieldId('FORM') . "()\n\t\t\t{\n\t\t\t\tvar iblock = BX('" . $this->getFieldId('FORM') . "');\n\t\t\t\tFormPropertyAdd(iblock, BX('" . $this->getFieldId('PROPERTY_NAME') . "'));\n\t\t\t\tFormPropertyAdd(iblock, BX('" . $this->getFieldId('PROPERTY_EMAIL') . "'));\n\t\t\t}\n\t\t\tfunction FormPropertyAdd(iblock, iblockProperty)\n\t\t\t{\n\t\t\t\tif(iblockProperty.length>0)\n\t\t\t\t{\n\t\t\t\t\tfor (var j in iblockProperty.options)\n\t\t\t\t\t{\n\t\t\t\t\t\tiblockProperty.options.remove(j);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tvar propList = {};\n\t\t\t\tif(formProperties[iblock.value] && formProperties[iblock.value].length>0)\n\t\t\t\t\tpropList = formProperties[iblock.value];\n\t\t\t\telse\n\t\t\t\t\tpropList = formProperties['EMPTY'];\n\t\t\t\tfor(var i in propList)\n\t\t\t\t{\n\t\t\t\t\tvar optionName = propList[i]['NAME'];\n\t\t\t\t\tvar optionValue = propList[i]['ID'];\n\t\t\t\t\tiblockProperty.options.add(new Option(optionName, optionValue));\n\t\t\t\t}\n\n\t\t\t}\n\n\t\t\tvar formProperties = " . \CUtil::PhpToJSObject($propertyList) . ";\n\t\t</script>\n\t\t";
        return '
			' . Loc::getMessage('sender_connector_form_required_settings') . '
			<br/><br/>
			<table>
				<tr>
					<td>' . Loc::getMessage('sender_connector_form_field_form') . '</td>
					<td>' . $formInput . '</td>
				</tr>
				<tr>
					<td>' . Loc::getMessage('sender_connector_form_field_name') . '</td>
					<td>' . $formPropertyNameInput . '</td>
				</tr>
				<tr>
					<td>' . Loc::getMessage('sender_connector_form_field_email') . '</td>
					<td>' . $formPropertyEmailInput . '</td>
				</tr>
			</table>
			' . $jsScript . '
		';
    }
Esempio n. 11
0
 function GetList($WEB_FORM_ID, &$by, &$order, $arFilter = array(), &$is_filtered, $CHECK_RIGHTS = "Y", $records_limit = false)
 {
     $err_mess = CFormResult::err_mess() . "<br>Function: GetList<br>Line: ";
     global $DB, $USER, $strError;
     $CHECK_RIGHTS = $CHECK_RIGHTS == "Y" ? "Y" : "N";
     $WEB_FORM_ID = intval($WEB_FORM_ID);
     $F_RIGHT = CForm::GetPermission($WEB_FORM_ID);
     $USER_ID = intval($USER->GetID());
     $arSqlSearch = array();
     $arrSEARCH = array();
     $arrFIELDS = array();
     $strSqlSearch = "";
     if (is_array($arFilter)) {
         $arFilter = CFormResult::PrepareFilter($WEB_FORM_ID, $arFilter);
         $z = CForm::GetByID($WEB_FORM_ID);
         $form = $z->Fetch();
         $z = CFormField::GetList($WEB_FORM_ID, "", $v1, $v2, array(), $v3);
         while ($zr = $z->Fetch()) {
             $arPARAMETER_NAME = array("ANSWER_TEXT", "ANSWER_VALUE", "USER");
             CFormField::GetFilterTypeList($arrUSER, $arrANSWER_TEXT, $arrANSWER_VALUE, $arrFIELD);
             foreach ($arPARAMETER_NAME as $PARAMETER_NAME) {
                 switch ($PARAMETER_NAME) {
                     case "ANSWER_TEXT":
                         $arFILTER_TYPE = $arrANSWER_TEXT["reference_id"];
                         break;
                     case "ANSWER_VALUE":
                         $arFILTER_TYPE = $arrANSWER_VALUE["reference_id"];
                         break;
                     case "USER":
                         $arFILTER_TYPE = $arrUSER["reference_id"];
                         break;
                 }
                 foreach ($arFILTER_TYPE as $FILTER_TYPE) {
                     $arrUF = array();
                     $arrUF["ID"] = $zr["ID"];
                     $arrUF["PARAMETER_NAME"] = $PARAMETER_NAME;
                     $arrUF["FILTER_TYPE"] = $FILTER_TYPE;
                     $FID = $form["SID"] . "_" . $zr["SID"] . "_" . $PARAMETER_NAME . "_" . $FILTER_TYPE;
                     if ($FILTER_TYPE == "date" || $FILTER_TYPE == "integer") {
                         $arrUF["SIDE"] = "1";
                         $arrFORM_FILTER[$FID . "_1"] = $arrUF;
                         $arrUF["SIDE"] = "2";
                         $arrFORM_FILTER[$FID . "_2"] = $arrUF;
                         $arrUF["SIDE"] = "0";
                         $arrFORM_FILTER[$FID . "_0"] = $arrUF;
                     } else {
                         $arrFORM_FILTER[$FID] = $arrUF;
                     }
                 }
             }
         }
         if (is_array($arrFORM_FILTER)) {
             $arrFORM_FILTER_KEYS = array_keys($arrFORM_FILTER);
         }
         //echo "arFilter:<pre>"; print_r($arFilter); echo "</pre>";
         //echo "arrFORM_FILTER:<pre>"; print_r($arrFORM_FILTER); echo "</pre>";
         //echo "arrFORM_FILTER_KEYS:<pre>"; print_r($arrFORM_FILTER_KEYS); echo "</pre>";
         $t = 0;
         $filter_keys = array_keys($arFilter);
         for ($i = 0; $i < count($filter_keys); $i++) {
             $key = $filter_keys[$i];
             $val = $arFilter[$filter_keys[$i]];
             if (strlen($val) <= 0 || "{$val}" == "NOT_REF") {
                 continue;
             }
             if (is_array($val) && count($val) <= 0) {
                 continue;
             }
             $match_value_set = in_array($key . "_EXACT_MATCH", $filter_keys) ? true : false;
             $key = strtoupper($key);
             switch ($key) {
                 case "ID":
                     $match = $arFilter[$key . "_EXACT_MATCH"] == "N" && $match_value_set ? "Y" : "N";
                     $arSqlSearch[] = GetFilterQuery("R.ID", $val, $match);
                     break;
                 case "STATUS":
                     $arSqlSearch[] = "R.STATUS_ID='" . intval($val) . "'";
                     break;
                 case "STATUS_ID":
                     $match = $arFilter[$key . "_EXACT_MATCH"] == "N" && $match_value_set ? "Y" : "N";
                     $arSqlSearch[] = GetFilterQuery("R.STATUS_ID", $val, $match);
                     break;
                 case "TIMESTAMP_1":
                     $arSqlSearch[] = "R.TIMESTAMP_X>=" . $DB->CharToDateFunction($val, "SHORT");
                     break;
                 case "TIMESTAMP_2":
                     $arSqlSearch[] = "R.TIMESTAMP_X<" . $DB->CharToDateFunction($val, "SHORT") . "+1";
                     break;
                 case "DATE_CREATE_1":
                     $arSqlSearch[] = "R.DATE_CREATE>=" . $DB->CharToDateFunction($val, "SHORT");
                     break;
                 case "DATE_CREATE_2":
                     $arSqlSearch[] = "R.DATE_CREATE<" . $DB->CharToDateFunction($val, "SHORT") . "+1";
                     break;
                 case "TIME_CREATE_1":
                     $arSqlSearch[] = "R.DATE_CREATE>=" . $DB->CharToDateFunction($val, "FULL");
                     break;
                 case "TIME_CREATE_2":
                     $arSqlSearch[] = "R.DATE_CREATE<" . $DB->CharToDateFunction($val, "FULL");
                     break;
                 case "REGISTERED":
                     $arSqlSearch[] = $val == "Y" ? "R.USER_ID>0" : "(R.USER_ID<=0 or R.USER_ID is null)";
                     break;
                 case "USER_AUTH":
                     $arSqlSearch[] = $val == "Y" ? "(R.USER_AUTH='Y' and R.USER_ID>0)" : "(R.USER_AUTH='N' and R.USER_ID>0)";
                     break;
                 case "USER_ID":
                     $match = $arFilter[$key . "_EXACT_MATCH"] == "N" && $match_value_set ? "Y" : "N";
                     $arSqlSearch[] = GetFilterQuery("R.USER_ID", $val, $match);
                     break;
                 case "GUEST_ID":
                     $match = $arFilter[$key . "_EXACT_MATCH"] == "N" && $match_value_set ? "Y" : "N";
                     $arSqlSearch[] = GetFilterQuery("R.STAT_GUEST_ID", $val, $match);
                     break;
                 case "SESSION_ID":
                     $match = $arFilter[$key . "_EXACT_MATCH"] == "N" && $match_value_set ? "Y" : "N";
                     $arSqlSearch[] = GetFilterQuery("R.STAT_SESSION_ID", $val, $match);
                     break;
                 default:
                     if (is_array($arrFORM_FILTER)) {
                         $key = $filter_keys[$i];
                         if (in_array($key, $arrFORM_FILTER_KEYS)) {
                             $arrF = $arrFORM_FILTER[$key];
                             if (!in_array($arrF["ID"], $arrFIELDS)) {
                                 $t++;
                                 $arSqlSearch_f = array();
                                 $A = "A" . $t;
                                 $arrFIELDS[$t] = $arrF["ID"];
                             }
                             switch (strtoupper($arrF["FILTER_TYPE"])) {
                                 case "EXIST":
                                     if ($arrF["PARAMETER_NAME"] == "ANSWER_TEXT") {
                                         $arSqlSearch_f[] = $A . ".ANSWER_TEXT is not null";
                                     } elseif ($arrF["PARAMETER_NAME"] == "ANSWER_VALUE") {
                                         $arSqlSearch_f[] = $A . ".ANSWER_VALUE is not null";
                                     } elseif ($arrF["PARAMETER_NAME"] == "USER") {
                                         $arSqlSearch_f[] = $A . ".USER_TEXT is not null";
                                     }
                                     break;
                                 case "TEXT":
                                     $match = $arFilter[$key . "_exact_match"] == "Y" ? "N" : "Y";
                                     $sql = "";
                                     if ($arrF["PARAMETER_NAME"] == "ANSWER_TEXT") {
                                         $sql = GetFilterQuery($A . ".ANSWER_TEXT_SEARCH", ToUpper($val), $match, array(), "Y", "Y", "Y");
                                     } elseif ($arrF["PARAMETER_NAME"] == "ANSWER_VALUE") {
                                         $sql = GetFilterQuery($A . ".ANSWER_VALUE_SEARCH", ToUpper($val), $match, array(), "Y", "Y", "Y");
                                     } elseif ($arrF["PARAMETER_NAME"] == "USER") {
                                         $sql = GetFilterQuery($A . ".USER_TEXT_SEARCH", ToUpper($val), $match, array(), "Y", "Y", "Y");
                                     }
                                     if ($sql !== "0" && strlen(trim($sql)) > 0) {
                                         $arSqlSearch_f[] = $sql;
                                     }
                                     break;
                                 case "DROPDOWN":
                                 case "ANSWER_ID":
                                     $arSqlSearch_f[] = $A . ".ANSWER_ID=" . intval($val);
                                     break;
                                 case "DATE":
                                     if ($arrF["PARAMETER_NAME"] == "USER") {
                                         if (CheckDateTime($val)) {
                                             if ($arrF["SIDE"] == "1") {
                                                 $arSqlSearch_f[] = $A . ".USER_DATE>=" . $DB->CharToDateFunction($val, "SHORT");
                                             } elseif ($arrF["SIDE"] == "2") {
                                                 $arSqlSearch_f[] = $A . ".USER_DATE<" . $DB->CharToDateFunction($val, "SHORT") . "+1";
                                             } elseif ($arrF["SIDE"] == "0") {
                                                 $arSqlSearch_f[] = $A . ".USER_DATE=" . $DB->CharToDateFunction($val);
                                             }
                                         }
                                     }
                                     break;
                                 case "INTEGER":
                                     if ($arrF["PARAMETER_NAME"] == "USER") {
                                         if ($arrF["SIDE"] == "1") {
                                             $arSqlSearch_f[] = "\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tCONVERT_TO_NUMBER(\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tDBMS_LOB.SUBSTR(" . $A . ".USER_TEXT, \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tDBMS_LOB.GETLENGTH(" . $A . ".USER_TEXT),\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t1)\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t)>=" . intval($val);
                                         } elseif ($arrF["SIDE"] == "2") {
                                             $arSqlSearch_f[] = "\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tCONVERT_TO_NUMBER(\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tDBMS_LOB.SUBSTR(" . $A . ".USER_TEXT,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tDBMS_LOB.GETLENGTH(" . $A . ".USER_TEXT),\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t1)\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t)<=" . intval($val);
                                         } elseif ($arrF["SIDE"] == "0") {
                                             $arSqlSearch_f[] = "\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tCONVERT_TO_NUMBER(\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tDBMS_LOB.SUBSTR(" . $A . ".USER_TEXT,\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tDBMS_LOB.GETLENGTH(" . $A . ".USER_TEXT),\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t1)\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t)=" . intval($val);
                                         }
                                     } elseif ($arrF["PARAMETER_NAME"] == "ANSWER_TEXT") {
                                         if ($arrF["SIDE"] == "1") {
                                             $arSqlSearch_f[] = "CONVERT_TO_NUMBER(" . $A . ".ANSWER_TEXT)>=" . intval($val);
                                         } elseif ($arrF["SIDE"] == "2") {
                                             $arSqlSearch_f[] = "CONVERT_TO_NUMBER(" . $A . ".ANSWER_TEXT)<=" . intval($val);
                                         } elseif ($arrF["SIDE"] == "0") {
                                             $arSqlSearch_f[] = "CONVERT_TO_NUMBER(" . $A . ".ANSWER_TEXT)=" . intval($val);
                                         }
                                     } elseif ($arrF["PARAMETER_NAME"] == "ANSWER_VALUE") {
                                         if ($arrF["SIDE"] == "1") {
                                             $arSqlSearch_f[] = "CONVERT_TO_NUMBER(" . $A . ".ANSWER_VALUE)>=" . intval($val);
                                         } elseif ($arrF["SIDE"] == "2") {
                                             $arSqlSearch_f[] = "CONVERT_TO_NUMBER(" . $A . ".ANSWER_VALUE)<=" . intval($val);
                                         } elseif ($arrF["SIDE"] == "0") {
                                             $arSqlSearch_f[] = "CONVERT_TO_NUMBER(" . $A . ".ANSWER_VALUE)=" . intval($val);
                                         }
                                     }
                                     break;
                             }
                             if (is_array($arSqlSearch_f) && count($arSqlSearch_f) > 0) {
                                 $arrSEARCH[$t] = $arSqlSearch_f;
                             }
                         }
                     }
             }
         }
     }
     if ($by == "s_id") {
         $strSqlOrder = "ORDER BY R.ID";
     } elseif ($by == "s_date_create") {
         $strSqlOrder = "ORDER BY R.DATE_CREATE";
     } elseif ($by == "s_timestamp") {
         $strSqlOrder = "ORDER BY R.TIMESTAMP_X";
     } elseif ($by == "s_user_id") {
         $strSqlOrder = "ORDER BY R.USER_ID";
     } elseif ($by == "s_guest_id") {
         $strSqlOrder = "ORDER BY R.STAT_GUEST_ID";
     } elseif ($by == "s_session_id") {
         $strSqlOrder = "ORDER BY R.STAT_SESSION_ID";
     } elseif ($by == "s_valid") {
         $strSqlOrder = "ORDER BY R.VALID";
     } else {
         $by = "s_timestamp";
         $strSqlOrder = "ORDER BY R.TIMESTAMP_X";
     }
     if ($order != "asc") {
         $strSqlOrder .= " desc ";
         $order = "desc";
     }
     $strSqlSearch = GetFilterSqlSearch($arSqlSearch);
     $strSqlSearch_F = "";
     if (is_array($arrSEARCH) && count($arrSEARCH) > 0) {
         reset($arrSEARCH);
         while (list($index, $arrS) = each($arrSEARCH)) {
             $field = intval($arrFIELDS[$index]);
             if ($field > 0) {
                 $str = implode(" and ", $arrS);
                 $strSqlSearch_F .= "\r\n\t\t\t\t\t\tand EXISTS (\r\n\t\t\t\t\t\t\tSELECT 'x' FROM b_form_result_answer A{$index} \r\n\t\t\t\t\t\t\tWHERE\r\n\t\t\t\t\t\t\t\tA{$index}.RESULT_ID=R.ID \r\n\t\t\t\t\t\t\tand A{$index}.FIELD_ID={$field}\r\n\t\t\t\t\t\t\tand {$str}\r\n\t\t\t\t\t\t)\r\n\t\t\t\t\t\t";
             }
         }
     }
     $records_limit = $records_limit === false ? intval(COption::GetOptionString("form", "RECORDS_LIMIT")) : intval($records_limit);
     if ($CHECK_RIGHTS != "Y" || CForm::IsAdmin()) {
         $strSql = "\r\n\t\t\t\tSELECT \r\n\t\t\t\t\tR.ID, R.USER_ID, R.USER_AUTH, R.STAT_GUEST_ID, R.STAT_SESSION_ID, R.STATUS_ID,\r\n\t\t\t\t\t" . $DB->DateToCharFunction("R.DATE_CREATE") . "\tDATE_CREATE,\r\n\t\t\t\t\t" . $DB->DateToCharFunction("R.TIMESTAMP_X") . "\tTIMESTAMP_X,\r\n\t\t\t\t\tS.TITLE\t\t\t\tSTATUS_TITLE,\r\n\t\t\t\t\tS.CSS\t\t\t\tSTATUS_CSS\r\n\t\t\t\tFROM \r\n\t\t\t\t\tb_form_result R, \r\n\t\t\t\t\tb_form_status S\r\n\t\t\t\tWHERE \r\n\t\t\t\t{$strSqlSearch}\r\n\t\t\t\t{$strSqlSearch_F}\r\n\t\t\t\tand R.FORM_ID='{$WEB_FORM_ID}'\r\n\t\t\t\tand S.ID = R.STATUS_ID\r\n\t\t\t\tGROUP BY \r\n\t\t\t\t\tR.ID, R.USER_ID, R.USER_AUTH, R.STAT_GUEST_ID, R.STAT_SESSION_ID, R.DATE_CREATE, R.TIMESTAMP_X, R.STATUS_ID, S.ID, S.TITLE, S.CSS\r\n\t\t\t\t{$strSqlOrder}\r\n\t\t\t\t";
         if ($records_limit > 0) {
             $strSql = "SELECT * FROM ({$strSql}) WHERE ROWNUM<=" . $records_limit;
         }
         $res = $DB->Query($strSql, false, $err_mess . __LINE__);
     } elseif ($F_RIGHT >= 15) {
         $arGroups = $USER->GetUserGroupArray();
         if (!is_array($arGroups)) {
             $arGroups[] = 2;
         }
         if (is_array($arGroups) && count($arGroups) > 0) {
             $groups = implode(",", $arGroups);
         }
         if ($F_RIGHT < 20) {
             $str3 = "and nvl(R.USER_ID,0) = {$USER_ID}";
         }
         $strSql = "\r\n\t\t\t\tSELECT \r\n\t\t\t\t\tR.ID, R.USER_ID, R.USER_AUTH, R.STAT_GUEST_ID, R.STAT_SESSION_ID, R.STATUS_ID,\r\n\t\t\t\t\t" . $DB->DateToCharFunction("R.DATE_CREATE") . "\tDATE_CREATE,\r\n\t\t\t\t\t" . $DB->DateToCharFunction("R.TIMESTAMP_X") . "\tTIMESTAMP_X,\r\n\t\t\t\t\tS.TITLE\t\t\t\tSTATUS_TITLE,\r\n\t\t\t\t\tS.CSS\t\t\t\tSTATUS_CSS\r\n\t\t\t\tFROM \r\n\t\t\t\t\tb_form_result R, \r\n\t\t\t\t\tb_form_status S, \r\n\t\t\t\t\tb_form_status_2_group G\r\n\t\t\t\tWHERE \r\n\t\t\t\t{$strSqlSearch}\r\n\t\t\t\t{$strSqlSearch_F}\r\n\t\t\t\tand R.FORM_ID='{$WEB_FORM_ID}'\r\n\t\t\t\tand S.ID = R.STATUS_ID\r\n\t\t\t\tand G.STATUS_ID = S.ID\r\n\t\t\t\tand (\r\n\t\t\t\t\t(G.GROUP_ID in ({$groups})) or\r\n\t\t\t\t\t(G.GROUP_ID in ({$groups},0) and nvl(R.USER_ID,0) = {$USER_ID} and {$USER_ID}>0)\r\n\t\t\t\t\t)\r\n\t\t\t\tand G.PERMISSION in ('VIEW', 'EDIT', 'DELETE')\r\n\t\t\t\tGROUP BY \r\n\t\t\t\t\tR.ID, R.USER_ID, R.USER_AUTH, R.STAT_GUEST_ID, R.STAT_SESSION_ID, R.DATE_CREATE, R.TIMESTAMP_X, R.STATUS_ID, S.ID, S.TITLE, S.CSS\r\n\t\t\t\t{$strSqlOrder}\r\n\t\t\t\t";
         if ($records_limit > 0) {
             $strSql = "SELECT * FROM ({$strSql}) WHERE ROWNUM<=" . $records_limit;
         }
         $res = $DB->Query($strSql, false, $err_mess . __LINE__);
     } else {
         $res = new CDBResult();
         $res->InitFromArray(array());
     }
     //echo "<pre>".$strSqlSearch."</pre>";
     //echo "<pre>".$strSql."</pre>";
     $is_filtered = IsFiltered($strSqlSearch) || strlen($strSqlSearch_F) > 0;
     return $res;
 }
Esempio n. 12
0
		}

		// get columns titles
		if ($arResult["res_counter"] > 0)
		{
			$arFilter = array(
				"IN_RESULTS_TABLE"	=> "Y",
				"RESULT_ID"			=> implode(" | ", $arResult["arRID"])
				);
			CForm::GetResultAnswerArray($arParams["WEB_FORM_ID"], $arResult["arrColumns"], $arResult["arrAnswers"], $arResult["arrAnswersSID"], $arFilter);
		}
		else
		{
			$arFilter = array("IN_RESULTS_TABLE" => "Y");

			$rsFields = CFormField::GetList($arParams["WEB_FORM_ID"], "ALL", ($v1="s_c_sort"), ($v2="asc"), $arFilter, $v3);
			while ($arField = $rsFields->Fetch())
			{
				$arResult["arrColumns"][$arField["ID"]] = $arField;
			}
		}

		if (is_array($arResult["arrAnswers"]))
		{
			foreach ($arResult["arrAnswers"] as $res_key => $arrResult)
			{
				foreach ($arrResult as $q_key => $arAnswers)
				{
					foreach ($arAnswers as $a_key => $arrA)
					{
						if (strlen(trim($arrA["USER_TEXT"]))>0)
Esempio n. 13
0
 function Mail($RESULT_ID, $TEMPLATE_ID = false)
 {
     global $DB, $MESS, $strError;
     $err_mess = CAllFormResult::err_mess() . "<br>Function: Mail<br>Line: ";
     $RESULT_ID = intval($RESULT_ID);
     if ($arrResult = CFormResult::GetDataByID($RESULT_ID, array(), $arrRES, $arrANSWER)) {
         $z = CForm::GetByID($arrRES["FORM_ID"]);
         if ($arrFORM = $z->Fetch()) {
             $TEMPLATE_ID = intval($TEMPLATE_ID);
             $rs = CSite::GetList($by = "sort", $order = "asc");
             while ($ar = $rs->Fetch()) {
                 $arrSites[$ar["ID"]] = $ar;
             }
             $arrFormSites = CForm::GetSiteArray($arrRES["FORM_ID"]);
             $arrFormSites = is_array($arrFormSites) ? $arrFormSites : array();
             $arrFormTemplates = CForm::GetMailTemplateArray($arrRES["FORM_ID"]);
             $arrFormTemplates = is_array($arrFormTemplates) ? $arrFormTemplates : array();
             $arrTemplates = array();
             $rs = CEventMessage::GetList($by = "id", $order = "asc", array("ACTIVE" => "Y", "SITE_ID" => $arrFormSites, "EVENT_NAME" => $arrFORM["MAIL_EVENT_TYPE"]));
             while ($ar = $rs->Fetch()) {
                 if ($TEMPLATE_ID > 0) {
                     if ($TEMPLATE_ID == $ar["ID"]) {
                         $arrTemplates[$ar["ID"]] = $ar;
                         break;
                     }
                 } elseif (in_array($ar["ID"], $arrFormTemplates)) {
                     $arrTemplates[$ar["ID"]] = $ar;
                 }
             }
             foreach ($arrTemplates as $arrTemplate) {
                 $OLD_MESS = $MESS;
                 $MESS = array();
                 IncludeModuleLangFile($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/form/form_mail.php", $arrSites[$arrTemplate["SITE_ID"]]["LANGUAGE_ID"]);
                 $USER_AUTH = " ";
                 if (intval($arrRES["USER_ID"]) > 0) {
                     $w = CUser::GetByID($arrRES["USER_ID"]);
                     $arrUSER = $w->Fetch();
                     $USER_ID = $arrUSER["ID"];
                     $USER_EMAIL = $arrUSER["EMAIL"];
                     $USER_NAME = $arrUSER["NAME"] . " " . $arrUSER["LAST_NAME"];
                     if ($arrRES["USER_AUTH"] != "Y") {
                         $USER_AUTH = "(" . GetMessage("FORM_NOT_AUTHORIZED") . ")";
                     }
                 } else {
                     $USER_ID = GetMessage("FORM_NOT_REGISTERED");
                     $USER_NAME = "";
                     $USER_AUTH = "";
                     $USER_EMAIL = "";
                 }
                 $arEventFields = array("RS_FORM_ID" => $arrFORM["ID"], "RS_FORM_NAME" => $arrFORM["NAME"], "RS_FORM_VARNAME" => $arrFORM["SID"], "RS_FORM_SID" => $arrFORM["SID"], "RS_RESULT_ID" => $arrRES["ID"], "RS_DATE_CREATE" => $arrRES["DATE_CREATE"], "RS_USER_ID" => $USER_ID, "RS_USER_EMAIL" => $USER_EMAIL, "RS_USER_NAME" => $USER_NAME, "RS_USER_AUTH" => $USER_AUTH, "RS_STAT_GUEST_ID" => $arrRES["STAT_GUEST_ID"], "RS_STAT_SESSION_ID" => $arrRES["STAT_SESSION_ID"]);
                 $w = CFormField::GetList($arrFORM["ID"], "ALL", $by, $order, array(), $is_filtered);
                 while ($wr = $w->Fetch()) {
                     $answer = "";
                     if (is_array($arrResult[$wr["SID"]])) {
                         foreach ($arrResult[$wr["SID"]] as $arrA) {
                             $USER_TEXT_EXIST = strlen(trim($arrA["USER_TEXT"])) > 0;
                             $ANSWER_TEXT_EXIST = strlen(trim($arrA["ANSWER_TEXT"])) > 0;
                             $ANSWER_VALUE_EXIST = strlen(trim($arrA["ANSWER_VALUE"])) > 0;
                             $USER_FILE_EXIST = intval($arrA["USER_FILE_ID"]) > 0;
                             if ($arrTemplate["BODY_TYPE"] == "html") {
                                 if (strlen(trim($answer)) > 0) {
                                     $answer .= "<br>";
                                 }
                                 if ($USER_TEXT_EXIST) {
                                     $answer .= $arrA["USER_TEXT"];
                                     if ($ANSWER_TEXT_EXIST || $ANSWER_VALUE_EXIST || $USER_FILE_EXIST) {
                                         $answer .= " ";
                                     }
                                 }
                                 if ($ANSWER_TEXT_EXIST) {
                                     $answer .= $arrA["ANSWER_TEXT"];
                                     if ($ANSWER_VALUE_EXIST || $USER_FILE_EXIST) {
                                         $answer .= " ";
                                     }
                                 }
                                 if ($ANSWER_VALUE_EXIST) {
                                     $answer .= $arrA["ANSWER_VALUE"];
                                     if ($USER_FILE_EXIST) {
                                         $answer .= " ";
                                     }
                                 }
                                 if ($USER_FILE_EXIST) {
                                     $f = CFile::GetByID($arrA["USER_FILE_ID"]);
                                     if ($fr = $f->Fetch()) {
                                         $a = array("b", "Kb", "Mb", "Gb");
                                         $pos = 0;
                                         $size = $arrA["USER_FILE_SIZE"];
                                         while ($size >= 1024) {
                                             $size /= 1024;
                                             $pos++;
                                         }
                                         $file_size = round($size, 2) . " " . $a[$pos];
                                         if ($arrA["USER_FILE_IS_IMAGE"] == "Y") {
                                             $url = "http://" . $_SERVER["HTTP_HOST"] . "/" . COption::GetOptionString("main", "upload_dir", "upload") . "/" . $fr["SUBDIR"] . "/" . $fr["FILE_NAME"];
                                             $answer .= "<a href=\"{$url}\">" . $arrA["USER_FILE_NAME"] . "</a> [" . $fr["WIDTH"] . " x " . $fr["HEIGHT"] . "] (" . $file_size . ")";
                                         } else {
                                             $url = "http://" . $_SERVER["HTTP_HOST"] . "/bitrix/tools/form_show_file.php?rid=" . $RESULT_ID . "&hash=" . $arrA["USER_FILE_HASH"] . "&action=download&&lang=" . LANGUAGE_ID;
                                             $answer .= "<a href=\"{$url}\">" . $arrA["USER_FILE_NAME"] . "</a> (" . $file_size . ")";
                                         }
                                     }
                                 }
                             } else {
                                 if (strlen(trim($answer)) > 0) {
                                     $answer .= "\n";
                                 }
                                 if ($USER_TEXT_EXIST) {
                                     $answer .= trim($arrA["USER_TEXT"]);
                                     if ($ANSWER_TEXT_EXIST || $ANSWER_VALUE_EXIST || $USER_FILE_EXIST) {
                                         $answer .= " ";
                                     }
                                 }
                                 if ($ANSWER_TEXT_EXIST) {
                                     $answer .= $arrA["ANSWER_TEXT"];
                                     if ($ANSWER_VALUE_EXIST || $USER_FILE_EXIST) {
                                         $answer .= " ";
                                     }
                                 }
                                 if ($ANSWER_VALUE_EXIST) {
                                     $answer .= $arrA["ANSWER_VALUE"];
                                     if ($USER_FILE_EXIST) {
                                         $answer .= " ";
                                     }
                                 }
                                 if ($USER_FILE_EXIST) {
                                     $f = CFile::GetByID($arrA["USER_FILE_ID"]);
                                     if ($fr = $f->Fetch()) {
                                         $a = array("b", "Kb", "Mb", "Gb");
                                         $pos = 0;
                                         $size = $arrA["USER_FILE_SIZE"];
                                         while ($size >= 1024) {
                                             $size /= 1024;
                                             $pos++;
                                         }
                                         $file_size = round($size, 2) . " " . $a[$pos];
                                         if ($arrA["USER_FILE_IS_IMAGE"] == "Y") {
                                             $url = "http://" . $_SERVER["HTTP_HOST"] . "/" . COption::GetOptionString("main", "upload_dir", "upload") . "/" . $fr["SUBDIR"] . "/" . $fr["FILE_NAME"];
                                             $answer .= $arrA["USER_FILE_NAME"] . " [" . $fr["WIDTH"] . " x " . $fr["HEIGHT"] . "] (" . $file_size . ")\n" . $url;
                                         } else {
                                             $url = "http://" . $_SERVER["HTTP_HOST"] . "/bitrix/tools/form_show_file.php?rid=" . $RESULT_ID . "&hash=" . $arrA["USER_FILE_HASH"] . "&action=download&&lang=" . LANGUAGE_ID;
                                             $answer .= $arrA["USER_FILE_NAME"] . " (" . $file_size . ")\n" . $url;
                                         }
                                     }
                                 }
                             }
                         }
                     }
                     $arEventFields[$wr["SID"]] = strlen($answer) <= 0 ? " " : $answer;
                 }
                 //echo "<pre>"; print_r($arEventFields); echo "</pre>";
                 CEvent::Send($arrTemplate["EVENT_NAME"], $arrTemplate["SITE_ID"], $arEventFields, "Y", $arrTemplate["ID"]);
                 $MESS = $OLD_MESS;
             }
             //foreach($arrTemplates as $arrTemplate)
             return true;
         } else {
             $strError .= GetMessage("FORM_ERROR_FORM_NOT_FOUND") . "<br>";
         }
     } else {
         $strError .= GetMessage("FORM_ERROR_RESULT_NOT_FOUND") . "<br>";
     }
     return false;
 }