function CheckFields($ACTION, &$arFields, $ID = 0) { $aMsg = array(); $ID = intVal($ID); $ACTION = $ACTION == "UPDATE" ? "UPDATE" : "ADD"; $arQuestion = array(); if ($ID > 0 && $ACTION == "UPDATE") { $db_res = CVoteQuestion::GetByID($ID); if (!($db_res && ($arQuestion = $db_res->Fetch()))) { $aMsg[] = array("id" => "ID", "text" => GetMessage("VOTE_QUESTION_NOT_FOUND")); } } unset($arFields["ID"]); if (is_set($arFields, "VOTE_ID") || $ACTION == "ADD") { $arFields["VOTE_ID"] = intVal($arFields["VOTE_ID"]); if ($arFields["VOTE_ID"] <= 0) { $aMsg[] = array("id" => "VOTE_ID", "text" => GetMessage("VOTE_FORGOT_VOTE_ID")); } } if (is_set($arFields, "QUESTION") || $ACTION == "ADD") { $arFields["QUESTION"] = trim($arFields["QUESTION"]); if (empty($arFields["QUESTION"])) { $aMsg[] = array("id" => "QUESTION", "text" => GetMessage("VOTE_FORGOT_QUESTION")); } } if (is_set($arFields, "IMAGE_ID") && strLen($arFields["IMAGE_ID"]["name"]) <= 0 && strLen($arFields["IMAGE_ID"]["del"]) <= 0) { unset($arFields["IMAGE_ID"]); } elseif (is_set($arFields, "IMAGE_ID")) { if ($str = CFile::CheckImageFile($arFields["IMAGE_ID"])) { $aMsg[] = array("id" => "IMAGE_ID", "text" => $str); } else { $arFields["IMAGE_ID"]["MODULE_ID"] = "vote"; if (!empty($arQuestion)) { $arFields["IMAGE_ID"]["old_file"] = $arQuestion["IMAGE_ID"]; } } } if (is_set($arFields, "ACTIVE") || $ACTION == "ADD") { $arFields["ACTIVE"] = $arFields["ACTIVE"] == "N" ? "N" : "Y"; } unset($arFields["TIMESTAMP_X"]); if (is_set($arFields, "C_SORT") || $ACTION == "ADD") { $arFields["C_SORT"] = intVal($arFields["C_SORT"]) > 0 ? intVal($arFields["C_SORT"]) : 100; } if (is_set($arFields, "COUNTER") || $ACTION == "ADD") { $arFields["COUNTER"] = intVal($arFields["COUNTER"]); } if (is_set($arFields, "QUESTION_TYPE") || $ACTION == "ADD") { $arFields["QUESTION_TYPE"] = $arFields["QUESTION_TYPE"] == "html" ? "html" : "text"; } if (is_set($arFields, "DIAGRAM") || $ACTION == "ADD") { $arFields["DIAGRAM"] = $arFields["DIAGRAM"] == "N" ? "N" : "Y"; } if (is_set($arFields, "DIAGRAM_TYPE") && (empty($arFields["DIAGRAM_TYPE"]) || in_array($arFields["DIAGRAM_TYPE"], GetVoteDiagramArray()))) { $arFields["DIAGRAM_TYPE"] = VOTE_DEFAULT_DIAGRAM_TYPE; } if (is_set($arFields, "TEMPLATE")) { $arFields["TEMPLATE"] = substr(trim($arFields["TEMPLATE"]), 0, 255); } if (is_set($arFields, "TEMPLATE_NEW")) { $arFields["TEMPLATE_NEW"] = substr(trim($arFields["TEMPLATE_NEW"]), 0, 255); } if ((is_set($arFields, "TEMPLATE") || is_set($arFields, "TEMPLATE_NEW")) && COption::GetOptionString("vote", "VOTE_COMPATIBLE_OLD_TEMPLATE", "Y") == "Y") { $old_module_version = CVote::IsOldVersion(); if ($old_module_version != "Y") { unset($arFields["TEMPLATE"]); } else { unset($arFields["TEMPLATE_NEW"]); } } if (!empty($aMsg)) { global $APPLICATION; $e = new CAdminException(array_reverse($aMsg)); $APPLICATION->ThrowException($e); return false; } return true; }
public static function CheckFields($ACTION, &$arFields, $ID = 0) { $aMsg = array(); $ID = intVal($ID); $arVote = array(); if ($ID > 0) { $db_res = CVote::GetByID($ID); if ($db_res && ($res = $db_res->Fetch())) { $arVote = $res; } } unset($arFields["ID"]); if (is_set($arFields, "CHANNEL_ID") || $ACTION == "ADD") { $arFields["CHANNEL_ID"] = intVal($arFields["CHANNEL_ID"]); if ($arFields["CHANNEL_ID"] <= 0) { $aMsg[] = array("id" => "CHANNEL_ID", "text" => GetMessage("VOTE_EMPTY_CHANNEL_ID")); } else { $rChannel = CVoteChannel::GetList($by, $order, array('ID' => intval($arFields['CHANNEL_ID'])), $filtered); if (!($rChannel && ($arChannel = $rChannel->Fetch()))) { $aMsg[] = array("id" => "CHANNEL_ID", "text" => GetMessage("VOTE_WRONG_CHANNEL_ID")); } } } if (is_set($arFields, "C_SORT")) { $arFields["C_SORT"] = intval($arFields["C_SORT"]); } if (is_set($arFields, "ACTIVE") || $ACTION == "ADD") { $arFields["ACTIVE"] = $arFields["ACTIVE"] == "N" ? "N" : "Y"; } unset($arFields["TIMESTAMP_X"]); $date_start = false; if (is_set($arFields, "DATE_START") || $ACTION == "ADD") { $arFields["DATE_START"] = trim($arFields["DATE_START"]); $date_start = MakeTimeStamp($arFields["DATE_START"]); if (!$date_start) { $aMsg[] = array("id" => "DATE_START", "text" => GetMessage("VOTE_WRONG_DATE_START")); } } if (is_set($arFields, "DATE_END") || $ACTION == "ADD") { $arFields["DATE_END"] = trim($arFields["DATE_END"]); if (strlen($arFields["DATE_END"]) <= 0) { if ($date_start != false) { $date_end = $date_start + 2592000; $arFields["DATE_END"] = GetTime($date_end, "FULL"); } else { $date_end = 1924984799; // '31.12.2030 23:59:59' $arFields["DATE_END"] = GetTime($date_end, "FULL"); } } else { $date_end = MakeTimeStamp($arFields["DATE_END"]); } if (!$date_end) { $aMsg[] = array("id" => "DATE_END", "text" => GetMessage("VOTE_WRONG_DATE_END")); } elseif ($date_start >= $date_end && !empty($arFields["DATE_START"])) { $aMsg[] = array("id" => "DATE_END", "text" => GetMessage("VOTE_WRONG_DATE_TILL")); } } if (empty($aMsg) && (is_set($arFields, "DATE_START") || is_set($arFields, "DATE_END") || is_set($arFields, "CHANNEL_ID") || is_set($arFields, "ACTIVE"))) { $vid = 0; if ($ACTION == "ADD" && $arFields["ACTIVE"] == "Y") { $vid = CVote::WrongDateInterval(0, $arFields["DATE_START"], $arFields["DATE_END"], $arFields["CHANNEL_ID"]); } elseif ($ACTION != "ADD" && !(is_set($arFields, "ACTIVE") && $arFields["ACTIVE"] != "Y")) { $res = array("DATE_START" => is_set($arFields, "DATE_START") ? $arFields["DATE_START"] : false, "DATE_END" => is_set($arFields, "DATE_END") ? $arFields["DATE_END"] : false, "CHANNEL_ID" => is_set($arFields, "CHANNEL_ID") ? $arFields["CHANNEL_ID"] : false); $vid = CVote::WrongDateInterval($ID, $res["DATE_START"], $res["DATE_END"], $res["CHANNEL_ID"]); } if (intVal($vid) > 0) { $aMsg[] = array("id" => "DATE_START", "text" => str_replace("#ID#", $vid, GetMessage("VOTE_WRONG_INTERVAL"))); } } if (is_set($arFields, "IMAGE_ID") && strLen($arFields["IMAGE_ID"]["name"]) <= 0 && strLen($arFields["IMAGE_ID"]["del"]) <= 0) { unset($arFields["IMAGE_ID"]); } elseif (is_set($arFields, "IMAGE_ID")) { if ($str = CFile::CheckImageFile($arFields["IMAGE_ID"])) { $aMsg[] = array("id" => "IMAGE_ID", "text" => $str); } else { $arFields["IMAGE_ID"]["MODULE_ID"] = "vote"; if (!empty($arVote)) { $arFields["IMAGE_ID"]["old_file"] = $arVote["IMAGE_ID"]; } } } if (is_set($arFields, "COUNTER")) { $arFields["COUNTER"] = intVal($arFields["COUNTER"]); } if (is_set($arFields, "TITLE")) { $arFields["TITLE"] = trim($arFields["TITLE"]); } if (is_set($arFields, "DESCRIPTION")) { $arFields["DESCRIPTION"] = trim($arFields["DESCRIPTION"]); } if (is_set($arFields, "DESCRIPTION_TYPE") || $ACTION == "ADD") { $arFields["DESCRIPTION_TYPE"] = $arFields["DESCRIPTION_TYPE"] == "html" ? "html" : "text"; } if (is_set($arFields, "EVENT1")) { $arFields["EVENT1"] = trim($arFields["EVENT1"]); } if (is_set($arFields, "EVENT2")) { $arFields["EVENT2"] = trim($arFields["EVENT2"]); } if (is_set($arFields, "EVENT3")) { $arFields["EVENT3"] = trim($arFields["EVENT3"]); } if (is_set($arFields, "UNIQUE_TYPE")) { $arFields["UNIQUE_TYPE"] = intVal($arFields["UNIQUE_TYPE"]); } if (is_set($arFields, "DELAY_TYPE") || $ACTION == "ADD") { $arFields["DELAY_TYPE"] = trim($arFields["DELAY_TYPE"]); $arFields["DELAY_TYPE"] = in_array($arFields["DELAY_TYPE"], array("S", "M", "H", "D")) ? $arFields["DELAY_TYPE"] : "D"; } if (is_set($arFields, "DELAY") || $ACTION == "ADD") { $arFields["DELAY"] = intVal($arFields["DELAY"]); } unset($arFields["KEEP_IP_SEC"]); $sec = 1; switch ($arFields["DELAY_TYPE"]) { case "S": $sec = 1; break; case "M": $sec = 60; break; case "H": $sec = 3600; break; case "D": $sec = 86400; break; } $arFields["KEEP_IP_SEC"] = intval($arFields["DELAY"]) * $sec; if (is_set($arFields, "UNIQUE_TYPE") && $arFields['UNIQUE_TYPE'] < 5) { switch ($arFields['UNIQUE_TYPE']) { case 0: $arFields['UNIQUE_TYPE'] = 5; break; case 1: $arFields['UNIQUE_TYPE'] = 6; break; case 2: $arFields['UNIQUE_TYPE'] = 8; break; case 3: $arFields['UNIQUE_TYPE'] = 12; break; case 4: $arFields['UNIQUE_TYPE'] = 20; break; } } if (CVote::IsOldVersion() != "Y") { unset($arFields["TEMPLATE"]); unset($arFields["RESULT_TEMPLATE"]); } if (is_set($arFields, "TEMPLATE")) { $arFields["TEMPLATE"] = trim($arFields["TEMPLATE"]); } if (is_set($arFields, "RESULT_TEMPLATE")) { $arFields["RESULT_TEMPLATE"] = trim($arFields["RESULT_TEMPLATE"]); } if (is_set($arFields, "NOTIFY")) { $arFields["NOTIFY"] = in_array($arFields["NOTIFY"], array("Y", "N", "I")) ? $arFields["NOTIFY"] : "N"; } if (is_set($arFields, "REQUIRED")) { $arFields["REQUIRED"] = $arFields["REQUIRED"] == "Y" ? "Y" : "N"; } if (is_set($arFields, "AUTHOR_ID")) { $arFields["AUTHOR_ID"] = intval($arFields["AUTHOR_ID"]); } if (!empty($aMsg)) { global $APPLICATION; $e = new CAdminException(array_reverse($aMsg)); $APPLICATION->ThrowException($e); return false; } return true; }
# http://www.bitrix.ru # # mailto:admin@bitrix.ru # ############################################## */ require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_admin_before.php"; require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/vote/prolog.php"; $VOTE_RIGHT = $APPLICATION->GetGroupRight("vote"); if ($VOTE_RIGHT == "D") { $APPLICATION->AuthForm(GetMessage("ACCESS_DENIED")); } require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/vote/include.php"; ClearVars(); IncludeModuleLangFile(__FILE__); CModule::IncludeModule("vote"); $err_mess = "File: " . __FILE__ . "<br>Line: "; $old_module_version = CVote::IsOldVersion(); $aTabs = array(array("DIV" => "edit1", "TAB" => GetMessage("VOTE_PROP"), "ICON" => "main_vote_edit", "TITLE" => GetMessage("VOTE_PARAMS")), array("DIV" => "edit2", "TAB" => GetMessage("VOTE_DESCR"), "ICON" => "main_vote_edit", "TITLE" => GetMessage("VOTE_DESCRIPTION")), array("DIV" => "edit3", "TAB" => GetMessage("VOTE_HOSTS"), "ICON" => "main_vote_edit", "TITLE" => GetMessage("VOTE_UNIQUE_PARAMS"))); $tabControl = new CAdminTabControl("tabControl", $aTabs); $arChannels = array(); $is_filtered = false; $bVarsFromForm = false; $db_res = CVoteChannel::GetList($by = "s_c_sort", $order = "asc", array(), $is_filtered); if ($db_res && ($res = $db_res->GetNext())) { do { $arChannels[$res["ID"]] = $res; } while ($res = $db_res->GetNext()); } if (empty($arChannels)) { $APPLICATION->SetTitle(GetMessage("VOTE_NEW_RECORD")); require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_admin_after.php"; echo "<a href='vote_list.php?lang=" . LANGUAGE_ID . "' class='navchain'>" . GetMessage("VOTE_VOTE_LIST") . "</a>";