示例#1
0
 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;
 }
示例#2
0
<?php

if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) {
    die;
}
if (!CModule::IncludeModule("vote")) {
    return;
}
$arrChannels = array();
$arrVotes = array();
$arrQuestions = array();
$arDiagramType = array("-" => GetMessage("VOTE_BY_DEFAULT")) + GetVoteDiagramArray();
$rs = CVoteChannel::GetList($v1, $v2, array(), $v3);
while ($arChannel = $rs->Fetch()) {
    $arrChannels[$arChannel["SID"]] = "[" . $arChannel["SID"] . "] " . $arChannel["TITLE"];
    $rsVotes = CVote::GetList($v1, $v2, array("CHANNEL_ID" => $arChannel["ID"]), $v3);
    while ($arVote = $rsVotes->Fetch()) {
        $arrVotes[$arVote["ID"]] = "[" . $arVote["ID"] . "] (" . $arChannel["SID"] . ") " . TruncateText($arVote["TITLE"], 40);
    }
}
if (intval($arCurrentValues["VOTE_ID"]) > 0) {
    $rsQuestions = CVoteQuestion::GetList($arCurrentValues["VOTE_ID"], $vv1, $vv2, array(), $vv3);
    while ($arQuestion = $rsQuestions->Fetch()) {
        $QUESTION = $arQuestion["QUESTION_TYPE"] == "html" ? strip_tags($arQuestion["QUESTION"]) : $arQuestion["QUESTION"];
        $QUESTION = TruncateText($QUESTION, 30);
        $arrQuestions["QUESTION_DIAGRAM_" . $arQuestion["ID"]] = array("NAME" => str_replace("#QUESTION#", $QUESTION, GetMessage("VOTE_TEMPLATE_FOR_QUESTION")), "TYPE" => "LIST", "ADDITIONAL_VALUES" => "N", "VALUES" => $arDiagramType);
    }
}
$arComponentParameters = array("PARAMETERS" => array("VOTE_ID" => array("NAME" => GetMessage("VOTE_POLL_ID"), "TYPE" => "LIST", "VALUES" => $arrVotes, "DEFAULT" => "={\$_REQUEST[\"VOTE_ID\"]}", "REFRESH" => "Y", "PARENT" => "BASE", "MULTIPLE" => "N", "ADDITIONAL_VALUES" => "Y"), "VOTE_ALL_RESULTS" => array("PARENT" => "BASE", "NAME" => GetMessage("VOTE_ALL_RESULTS"), "TYPE" => "CHECKBOX", "DEFAULT" => "N"), "CACHE_TIME" => array("DEFAULT" => 1200)));
$arComponentParameters["PARAMETERS"] = array_merge($arComponentParameters["PARAMETERS"], $arrQuestions);