Esempio n. 1
0
 function Delete($EVENT_ID)
 {
     $err_mess = CAllVoteEvent::err_mess() . "<br>Function: Delete<br>Line: ";
     global $DB;
     $EVENT_ID = intval($EVENT_ID);
     if ($EVENT_ID <= 0) {
         return;
     }
     // reset vote validity
     CVoteEvent::SetValid($EVENT_ID, "N");
     $DB->StartTransaction();
     // reset questions and asnwers voting events
     $DB->Query("DELETE FROM b_vote_event_answer WHERE EVENT_QUESTION_ID IN (" . "SELECT VEQ.ID FROM b_vote_event_question VEQ WHERE VEQ.EVENT_ID=" . $EVENT_ID . ")", false, $err_mess . __LINE__);
     $DB->Query("DELETE FROM b_vote_event_question WHERE EVENT_ID=" . $EVENT_ID, false, $err_mess . __LINE__);
     $DB->Update("b_vote_user", array("COUNTER" => "COUNTER - 1"), "WHERE ID IN (" . "SELECT VOTE_USER_ID FROM b_vote_event WHERE ID={$EVENT_ID})", $err_mess . __LINE__);
     // reset voting events
     $res = $DB->Query("DELETE FROM b_vote_event WHERE ID={$EVENT_ID}", false, $err_mess . __LINE__);
     $DB->Commit();
     return $res;
 }
Esempio n. 2
0
function VoteIsUserVoteForVote($VOTE_ID, $USER_ID = 0)
{
    if (!empty($VOTE_ID)) {
        $res = is_array($_SESSION["VOTE_ARRAY"]) && in_array($VOTE_ID, $_SESSION["VOTE_ARRAY"]);
        if (!$res) {
            $_SESSION["VOTE"] = is_array($_SESSION["VOTE"]) ? $_SESSION["VOTE"] : array();
            $_SESSION["VOTE"]["VOTES"] = is_array($_SESSION["VOTE"]["VOTES"]) ? $_SESSION["VOTE"]["VOTES"] : array();
            if (!in_array($VOTE_ID, $_SESSION["VOTE"]["VOTES"])) {
                $_SESSION["VOTE"]["VOTES"][$VOTE_ID] = false;
                $USER_ID = intval($USER_ID);
                $USER_ID = $USER_ID > 0 ? $USER_ID : $GLOBALS["USER"]->GetID();
                $arFilter = array();
                if ($USER_ID > 0) {
                    $arFilter["USER_ID"] = $USER_ID;
                } else {
                    $voteUserID = $_SESSION["VOTE_USER_ID"] ? $_SESSION["VOTE_USER_ID"] : intval($GLOBALS["APPLICATION"]->get_cookie("VOTE_USER_ID"));
                    if ($voteUserID > 0) {
                        $arFilter["VOTE_USER"] = $_SESSION["VOTE_USER_ID"] ? $_SESSION["VOTE_USER_ID"] : $GLOBALS["APPLICATION"]->get_cookie("VOTE_USER_ID");
                    }
                }
                if (!empty($arFilter)) {
                    $arFilter["VOTE_ID"] = $VOTE_ID;
                    $db_res = CVoteEvent::GetList($by, $order, $arFilter, $is_filtered, "Y");
                    if ($db_res && ($res = $db_res->Fetch())) {
                        $_SESSION["VOTE"]["VOTES"][$VOTE_ID] = $res["ID"];
                    }
                }
            }
            $res = $_SESSION["VOTE"]["VOTES"][$VOTE_ID];
        }
        return $res;
    }
    return false;
}
Esempio n. 3
0
 public static function KeepVoting()
 {
     global $DB, $VOTING_LAMP, $USER_ALREADY_VOTE, $USER_GROUP_PERMISSION, $USER;
     $err_mess = CAllVote::err_mess() . "<br>Function: KeepVoting<br>Line: ";
     $VOTING_LAMP = "green";
     $USER_ALREADY_VOTE = "N";
     $PUBLIC_VOTE_ID = intval($_REQUEST["PUBLIC_VOTE_ID"]);
     $aMsg = array();
     $VOTE_ID = 0;
     $arVote = array();
     $arQuestions = array();
     if (!(!empty($_REQUEST["vote"]) && $PUBLIC_VOTE_ID > 0 && check_bitrix_sessid())) {
         $aMsg[] = array("id" => "bad_params", "text" => GetMessage("VOTE_NOT_FOUND"));
     } elseif (($VOTE_ID = intVal(GetVoteDataByID($PUBLIC_VOTE_ID, $arChannel, $arVote, $arQuestions, $arAnswers, $arDropDown, $arMultiSelect, $arGroupAnswers, "N"))) && ($VOTE_ID <= 0 || $arVote["LAMP"] != "green")) {
         $VOTING_LAMP = "red";
         if ($VOTE_ID <= 0) {
             $aMsg[] = array("id" => "VOTE_ID", "text" => GetMessage("VOTE_NOT_FOUND"));
         } else {
             $aMsg[] = array("id" => "LAMP", "text" => GetMessage("VOTE_RED_LAMP"));
         }
     } elseif ($arChannel["USE_CAPTCHA"] == "Y" && !$USER->IsAuthorized()) {
         include_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/classes/general/captcha.php";
         $cpt = new CCaptcha();
         if (!empty($_REQUEST["captcha_word"])) {
             $captchaPass = COption::GetOptionString("main", "captcha_password", "");
             if (!$cpt->CheckCodeCrypt($_REQUEST["captcha_word"], $_REQUEST["captcha_code"], $captchaPass)) {
                 $GLOBALS["BAD_CAPTCHA"] = "Y";
                 $aMsg[] = array("id" => "CAPTCHA", "text" => GetMessage("VOTE_BAD_CAPTCHA"));
             }
         } else {
             if (!$cpt->CheckCode($_REQUEST["captcha_word"], 0)) {
                 $GLOBALS["NO_CAPTCHA"] = "Y";
                 $aMsg[] = array("id" => "CAPTCHA", "text" => GetMessage("VOTE_BAD_CAPTCHA"));
             }
         }
     }
     if (empty($aMsg)) {
         // get user id
         $_SESSION["VOTE_USER_ID"] = CVote::SetVoteUserID();
         $GLOBALS["VOTING_ID"] = $VOTE_ID;
         // check: can user vote
         $UNIQUE_TYPE = $arVote["UNIQUE_TYPE"];
         $KEEP_IP_SEC = $arVote["KEEP_IP_SEC"];
         $CHANNEL_ID = $arVote["CHANNEL_ID"];
         $StatusVote = CVote::UserAlreadyVote($VOTE_ID, $_SESSION["VOTE_USER_ID"], $UNIQUE_TYPE, $KEEP_IP_SEC, $USER->GetID());
         $USER_ALREADY_VOTE = $StatusVote != false ? "Y" : "N";
         $USER_GROUP_PERMISSION = CVote::UserGroupPermission($CHANNEL_ID);
         // if user can vote that
         if (($USER_ALREADY_VOTE == "N" || $StatusVote == 8 && $_REQUEST["REVOTE_ID"] == $VOTE_ID) && $USER_GROUP_PERMISSION >= 2) {
             $arSqlAnswers = array();
             // check answers
             foreach ($arQuestions as $qID => $arQuestion) {
                 $arSqlAnswers[$arQuestion["ID"]] = array();
                 $bIndicators = array();
                 foreach ($arQuestion["ANSWERS"] as $arAnswer) {
                     switch ($arAnswer["FIELD_TYPE"]) {
                         case 0:
                             // radio
                         // radio
                         case 2:
                             // dropdown list
                             $fieldName = ($arAnswer["FIELD_TYPE"] == 0 ? "vote_radio_" : "vote_dropdown_") . $qID;
                             $aID = intval($GLOBALS[$fieldName]);
                             if (!isset($bIndicators[$fieldName]) && array_key_exists($aID, $arQuestion["ANSWERS"])) {
                                 if (!empty($arAnswer['MESSAGE'])) {
                                     $arSqlAnswers[$qID][$aID] = array("ANSWER_ID" => $aID);
                                 }
                                 $bIndicators[$fieldName] = "Y";
                             }
                             break;
                         case 1:
                             // checkbox
                         // checkbox
                         case 3:
                             // multiselect list
                             $fieldName = ($arAnswer["FIELD_TYPE"] == 1 ? "vote_checkbox_" : "vote_multiselect_") . $qID;
                             $res = $GLOBALS[$fieldName];
                             if (!isset($bIndicators[$fieldName]) && is_array($res) && !empty($res)) {
                                 reset($res);
                                 foreach ($res as $aID) {
                                     if (array_key_exists($aID, $arQuestion["ANSWERS"])) {
                                         $arSqlAnswers[$qID][$aID] = array("ANSWER_ID" => $aID);
                                     }
                                 }
                                 $bIndicators[$fieldName] = "Y";
                             }
                             break;
                         case 4:
                             // field
                         // field
                         case 5:
                             // text
                             $aID = $arAnswer["ID"];
                             $fieldName = ($arAnswer["FIELD_TYPE"] == 4 ? "vote_field_" : "vote_memo_") . $aID;
                             $MESSAGE = trim($GLOBALS[$fieldName]);
                             if ($MESSAGE != "") {
                                 $arSqlAnswers[$qID][$aID] = array("ANSWER_ID" => $aID, "MESSAGE" => "'" . $DB->ForSql(trim($MESSAGE), 2000) . "'");
                             }
                             break;
                     }
                 }
                 if (empty($arSqlAnswers[$qID])) {
                     unset($arSqlAnswers[$qID]);
                     if ($arQuestion['REQUIRED'] == 'Y') {
                         $aMsg[] = array("id" => "QUESTION_" . $qID, "text" => GetMessage("VOTE_REQUIRED_MISSING"));
                         $GLOBALS["VOTE_REQUIRED_MISSING"] = "Y";
                         break;
                     }
                 }
             }
             if (!empty($aMsg)) {
                 /* do nothing; */
             } elseif (!empty($arSqlAnswers)) {
                 // vote event
                 $arFields = array("VOTE_ID" => $VOTE_ID, "VOTE_USER_ID" => intval($_SESSION["VOTE_USER_ID"]), "DATE_VOTE" => $DB->GetNowFunction(), "STAT_SESSION_ID" => intval($_SESSION["SESS_SESSION_ID"]), "IP" => "'" . $DB->ForSql($_SERVER["REMOTE_ADDR"], 15) . "'", "VALID" => "'Y'");
                 /***************** Event onBeforeVoting ****************************/
                 foreach (GetModuleEvents("vote", "onBeforeVoting", true) as $arEvent) {
                     if (ExecuteModuleEventEx($arEvent, array(&$arFields, &$arSqlAnswers)) === false) {
                         return false;
                     }
                 }
                 /***************** /Event ******************************************/
                 if ($StatusVote == 8 && $_REQUEST["REVOTE_ID"] == $VOTE_ID) {
                     $strSql = "SELECT VE.ID, VEQ.QUESTION_ID, VEA.ANSWER_ID" . " FROM b_vote_event VE " . "\tLEFT JOIN b_vote_event_question VEQ ON (VEQ.EVENT_ID=VE.ID)" . "\tLEFT JOIN b_vote_event_answer VEA ON (VEA.EVENT_QUESTION_ID=VEQ.ID)" . "\tLEFT JOIN b_vote_user VU ON (VE.VOTE_USER_ID = VU.ID)" . " WHERE VE.VOTE_ID=" . $VOTE_ID . " AND VU.AUTH_USER_ID=" . intval($USER->GetID()) . " ORDER BY VE.ID ASC, VEQ.QUESTION_ID ASC";
                     $db_res = $DB->Query($strSql, false, $err_mess . __LINE__);
                     if ($db_res && ($res = $db_res->Fetch())) {
                         if ($USER->GetID() > 0 && CModule::IncludeModule("im")) {
                             CIMNotify::DeleteByTag("VOTING|" . $VOTE_ID, $USER->GetID());
                         }
                         $del = false;
                         $delQ = false;
                         do {
                             if ($delQ !== $res["QUESTION_ID"]) {
                                 if ($del !== $res["ID"]) {
                                     CVoteEvent::Delete($res["ID"]);
                                     $del = $res["ID"];
                                     $arVote["COUNTER"] = intval($arVote["COUNTER"]) - 1;
                                 }
                                 $delQ = $res["QUESTION_ID"];
                                 $arQuestions[$res["QUESTION_ID"]]["COUNTER"] = intval($arQuestions[$res["QUESTION_ID"]]["COUNTER"]) - 1;
                             }
                             $arQuestions[$res["QUESTION_ID"]]["ANSWERS"][$res["ANSWER_ID"]]["COUNTER"] = intval($arQuestions[$res["QUESTION_ID"]]["ANSWERS"][$res["ANSWER_ID"]]["COUNTER"]) - 1;
                         } while ($res = $db_res->Fetch());
                     }
                     $USER_ALREADY_VOTE = "N";
                 }
                 unset($GLOBALS["VOTE_CACHE_VOTING"][$VOTE_ID]);
                 unset($GLOBALS["VOTE_CACHE"]["VOTE"][$VOTE_ID]);
                 $EVENT_ID = intval($DB->Insert("b_vote_event", $arFields, $err_mess . __LINE__));
                 if ($EVENT_ID > 0) {
                     $arSqlQuestionsID = array();
                     $arSqlAnswersID = array();
                     foreach ($arSqlAnswers as $qID => $arSqlAnswer) {
                         $arFields = array("EVENT_ID" => $EVENT_ID, "QUESTION_ID" => $qID);
                         $EVENT_QUESTION_ID = intval($DB->Insert("b_vote_event_question", $arFields, $err_mess . __LINE__));
                         if ($EVENT_QUESTION_ID > 0) {
                             $arSqlQuestionsID[] = $qID;
                             $arQuestions[$qID]["COUNTER"] = intval($arQuestions[$qID]["COUNTER"]) + 1;
                             foreach ($arSqlAnswer as $aID => $res) {
                                 $res["EVENT_QUESTION_ID"] = $EVENT_QUESTION_ID;
                                 if ($DB->Insert("b_vote_event_answer", $res, $err_mess . __LINE__)) {
                                     $arSqlAnswersID[$aID] = $qID;
                                     $arQuestions[$qID]["ANSWERS"][$aID]["COUNTER"] = intval($arQuestions[$qID]["ANSWERS"][$aID]["COUNTER"]) + 1;
                                 }
                             }
                         }
                     }
                     if (empty($arSqlQuestionsID) || empty($arSqlAnswersID)) {
                         $DB->Query("DELETE FROM b_vote_event WHERE ID=" . $EVENT_ID, $arFields, $err_mess . __LINE__);
                     } else {
                         $arFields = array("COUNTER" => "COUNTER+1");
                         $DB->Update("b_vote", $arFields, "WHERE ID='" . $VOTE_ID . "'", $err_mess . __LINE__);
                         $arVote["COUNTER"] = intval($arVote["COUNTER"]) + 1;
                         $DB->Update("b_vote_question", $arFields, "WHERE ID in (" . implode(", ", $arSqlQuestionsID) . ")", $err_mess . __LINE__);
                         $DB->Update("b_vote_answer", $arFields, "WHERE ID in (" . implode(", ", array_keys($arSqlAnswersID)) . ")", $err_mess . __LINE__);
                         // increment user counter
                         CVote::UpdateVoteUserID($_SESSION["VOTE_USER_ID"]);
                         $GLOBALS["VOTING_OK"] = "Y";
                         $_SESSION["VOTE_ARRAY"][] = $VOTE_ID;
                         if ($UNIQUE_TYPE & 8) {
                             $_SESSION["VOTE"]["VOTES"][$VOTE_ID] = $EVENT_ID;
                         }
                         // statistic module
                         if (CModule::IncludeModule("statistic")) {
                             $event3 = $arVote["EVENT3"];
                             if (!empty($event3)) {
                                 $event3 = "http://" . $_SERVER["HTTP_HOST"] . "/bitrix/admin/vote_user_results.php?EVENT_ID=" . $EVENT_ID . "&lang=" . LANGUAGE_ID;
                             }
                             CStatEvent::AddCurrent($arVote["EVENT1"], $arVote["EVENT2"], $event3);
                         }
                         // notification
                         if (!!$arVote["AUTHOR_ID"] && $arVote["AUTHOR_ID"] != $USER->GetID()) {
                             if (empty($arVote["TITLE"])) {
                                 $arQuestion = reset($arQuestions);
                                 $arVote["TITLE"] = $arQuestion["QUESTION"];
                             }
                             if ($arVote["NOTIFY"] == "I" && CModule::IncludeModule("im")) {
                                 $arVote["TOTAL_URL"] = "";
                                 if (!empty($arVote["URL"])) {
                                     if (defined('SITE_SERVER_NAME')) {
                                         $arVote["TOTAL_URL"] = SITE_SERVER_NAME;
                                     }
                                     $arVote["TOTAL_URL"] = !empty($arVote["TOTAL_URL"]) ? $arVote["TOTAL_URL"] : COption::GetOptionString("main", "server_name", $GLOBALS["SERVER_NAME"]);
                                     if (!empty($arVote["TOTAL_URL"])) {
                                         $arVote["TOTAL_URL"] = (CMain::IsHTTPS() ? "https" : "http") . "://" . $arVote["TOTAL_URL"] . $arVote["URL"];
                                     }
                                 }
                                 // send notification
                                 $gender = $USER->getParam("PERSONAL_GENDER") == "F" ? "_F" : "";
                                 $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "TO_USER_ID" => $arVote["AUTHOR_ID"], "FROM_USER_ID" => $USER->GetID(), "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "vote", "NOTIFY_EVENT" => "voting", "NOTIFY_TAG" => "VOTING|" . $VOTE_ID, "NOTIFY_MESSAGE" => !empty($arVote["URL"]) ? GetMessage("V_NOTIFY_MESSAGE_HREF" . $gender, array("#VOTE_TITLE#" => $arVote["TITLE"], "#VOTE_URL#" => $arVote["URL"])) : GetMessage("V_NOTIFY_MESSAGE" . $gender, array("#VOTE_TITLE#" => $arVote["TITLE"])), "NOTIFY_MESSAGE_OUT" => !empty($arVote["TOTAL_URL"]) ? GetMessage("V_NOTIFY_MESSAGE_OUT_HREF" . $gender, array("#VOTE_TITLE#" => $arVote["TITLE"], "#VOTE_URL#" => $arVote["TOTAL_URL"])) : GetMessage("V_NOTIFY_MESSAGE" . $gender, array("#VOTE_TITLE#" => $arVote["TITLE"])));
                                 CIMNotify::Add($arMessageFields);
                             } else {
                                 if ($arVote["NOTIFY"] == "Y") {
                                     // send e-mail
                                     $db_user = CUser::GetById($arVote["AUTHOR_ID"]);
                                     if ($db_user && ($arUser = $db_user->Fetch()) && !empty($arUser["EMAIL"])) {
                                         $arEventFields = array("EMAIL_TO" => $arUser["EMAIL"], "VOTE_STATISTIC" => "", "ID" => $EVENT_ID, "TIME" => GetTime(time(), "FULL"), "VOTE_TITLE" => $arVote["TITLE"], "VOTE_DESCRIPTION" => $arVote["DESCRIPTION"], "VOTE_ID" => $arVote["ID"], "VOTE_COUNTER" => $arVote["COUNTER"], "URL" => $arVote["URL"], "CHANNEL" => $arChannel["TITLE"], "CHANNEL_ID" => $arChannel["ID"], "VOTER_ID" => $_SESSION["VOTE_USER_ID"], "USER_NAME" => $USER->GetFullName(), "LOGIN" => $USER->GetLogin(), "USER_ID" => $USER->GetID(), "STAT_GUEST_ID" => intval($_SESSION["SESS_GUEST_ID"]), "SESSION_ID" => intval($_SESSION["SESS_SESSION_ID"]), "IP" => $_SERVER["REMOTE_ADDR"]);
                                         $arEventFields["USER_NAME"] = !!$arEventFields["USER_NAME"] ? $arEventFields["USER_NAME"] : $arEventFields["LOGIN"];
                                         // VOTE_STATISTIC
                                         $text = array();
                                         foreach ($arSqlAnswersID as $aID => $qID) {
                                             $text[$qID] = is_array($text[$qID]) ? $text[$qID] : array();
                                             if ($arQuestions[$qID]["ANSWERS"][$aID]["FIELD_TYPE"] == 4 || $arQuestions[$qID]["ANSWERS"][$aID]["FIELD_TYPE"] == 5) {
                                                 if (!empty($arSqlAnswers[$qID][$aID]["MESSAGE"])) {
                                                     $text[$qID][] = $arSqlAnswers[$qID][$aID]["MESSAGE"];
                                                 }
                                             } else {
                                                 $text[$qID][] = $arQuestions[$qID]["ANSWERS"][$aID]["MESSAGE"];
                                             }
                                         }
                                         foreach ($text as $qID => $txt) {
                                             $text[$qID] = " - " . $arQuestions[$qID]["QUESTION"] . "\n - " . implode(", ", $text[$qID]);
                                         }
                                         $arEventFields["VOTE_STATISTIC"] = "\n" . implode("\n\n", $text);
                                         $arrSites = CVoteChannel::GetSiteArray($arChannel["ID"]);
                                         CEvent::Send("VOTE_FOR", $arrSites, $arEventFields, "N");
                                     }
                                 }
                             }
                         }
                     }
                     /***************** Event onAfterVoting *****************************/
                     foreach (GetModuleEvents("vote", "onAfterVoting", true) as $arEvent) {
                         ExecuteModuleEventEx($arEvent, array($VOTE_ID, $EVENT_ID));
                     }
                     /***************** /Event ******************************************/
                 }
             } else {
                 $GLOBALS["USER_VOTE_EMPTY"] = "Y";
                 $aMsg[] = array("id" => "VOTE_ID", "text" => GetMessage("USER_VOTE_EMPTY"));
             }
         } else {
             $aMsg[] = array("id" => "VOTE_ID", "text" => $USER_GROUP_PERMISSION >= 2 ? GetMessage("VOTE_ALREADY_VOTE") : GetMessage("VOTE_ACCESS_DENIED"));
         }
     }
     if (!empty($aMsg)) {
         $e = new CAdminException($aMsg, "CVote::KeepVoting");
         $GLOBALS["APPLICATION"]->ThrowException($e);
         $GLOBALS["VOTING_OK"] = "N";
         return false;
     }
     return true;
 }
Esempio n. 4
0
$arVoteList = array("ID" => $_REQUEST["ID"], "answer_id" => $_REQUEST["answer_id"], "request_id" => $_REQUEST["request_id"], "items" => array(), "StatusPage" => "done");
$_REQUEST["ID"] = is_array($_REQUEST["ID"]) ? $_REQUEST["ID"] : !empty($_REQUEST["ID"]) ? explode(",", $_REQUEST["ID"]) : array();
$_REQUEST["URL_TEMPLATE"] = !empty($_REQUEST["URL_TEMPLATE"]) ? $_REQUEST["URL_TEMPLATE"] : '/company/personal/user/#USER_ID#/';
$_REQUEST["NAME_TEMPLATE"] = !empty($_REQUEST["NAME_TEMPLATE"]) ? $_REQUEST["NAME_TEMPLATE"] : CSite::GetNameFormat(false);
if ((!empty($_REQUEST["ID"]) || !empty($_REQUEST["answer_id"])) && check_bitrix_sessid()) {
    $arParams["CACHE_TIME"] = 600;
    global $CACHE_MANAGER;
    $cache = new CPHPCache();
    $cache_id = "vote_user_list_" . serialize(array($arResult["nPageSize"], $_REQUEST["ID"], $_REQUEST["answer_id"], $_REQUEST["iNumPage"], $_REQUEST["NAME_TEMPLATE"], $_REQUEST["URL_TEMPLATE"]));
    $cache_path = $CACHE_MANAGER->GetCompCachePath(CComponentEngine::MakeComponentPath("voting.current"));
    $arVoteList = $arParams["CACHE_TIME"] > 0 && $cache->InitCache($arParams["CACHE_TIME"], $cache_id, $cache_path) ? $cache->GetVars() : array();
    if (!is_array($arVoteList) || empty($arVoteList)) {
        $arEventsInfo = array();
        $arVoteList = array("ID" => $_REQUEST["ID"], "answer_id" => $_REQUEST["answer_id"], "request_id" => $_REQUEST["request_id"], "items" => array(), "StatusPage" => "done");
        if (empty($_REQUEST["ID"]) && CModule::IncludeModule("vote")) {
            $db_res = CVoteEvent::GetUserAnswerStat(array(), array("ANSWER_ID" => $_REQUEST["answer_id"], "VALID" => "Y", "bGetVoters" => "Y", "bGetMemoStat" => "N"), array("nPageSize" => $arResult["nPageSize"], "bShowAll" => false, "iNumPage" => $_REQUEST["iNumPage"] > 0 ? $_REQUEST["iNumPage"] : false));
            if ($db_res && ($res = $db_res->Fetch())) {
                $arEventsInfo = $res;
                $arVoteList["StatusPage"] = $db_res->NavPageNomer >= $db_res->NavPageCount || $arResult["nPageSize"] > $db_res->NavRecordCount ? "done" : "continue";
                if ($_REQUEST["iNumPage"] <= $db_res->NavPageCount) {
                    $_REQUEST["ID"] = array();
                    do {
                        $_REQUEST["ID"][] = $res["AUTH_USER_ID"];
                    } while ($res = $db_res->Fetch());
                } else {
                    $arVoteList["StatusPage"] = "done";
                }
            }
        }
        if (!empty($_REQUEST["ID"])) {
            $db_res = CUser::GetList($by = "ID", $order = "ASC", array("ID" => implode("|", $_REQUEST["ID"])), array("FIELDS" => array("ID", "NAME", "LAST_NAME", "SECOND_NAME", "LOGIN", "PERSONAL_PHOTO")));
    $row->AddViewField("VOTE_USER_ID", "<a title=\"" . GetMessage("VOTE_USER_LIST_TITLE") . "\" href=\"vote_user_list.php?lang=" . LANGUAGE_ID . "&find_id={$f_VOTE_USER_ID}&set_filter=Y\">{$f_VOTE_USER_ID}</a>");
    if (CModule::IncludeModule("statistic")) {
        $row->AddViewField("STAT_SESSION_ID", "<a title=\"" . GetMessage("VOTE_SESSIONU_LIST_TITLE") . "\" href=\"session_list.php?lang=" . LANGUAGE_ID . "&find_id={$f_STAT_SESSION_ID}&set_filter=Y\">{$f_STAT_SESSION_ID}</a>");
    }
    if (strlen($f_TITLE) > 0) {
        $txt = "[<a title='" . GetMessage("VOTE_EDIT_TITLE") . "' href='vote_edit.php?lang=" . LANGUAGE_ID . "&ID={$f_VOTE_ID}'>{$f_VOTE_ID}</a>] {$f_TITLE}";
    } elseif ($f_DESCRIPTION_TYPE == "html") {
        $txt = "[<a title='" . GetMessage("VOTE_EDIT_TITLE") . "' href='vote_edit.php?lang=" . LANGUAGE_ID . "&ID={$f_VOTE_ID}'>{$f_VOTE_ID}</a>] " . TruncateText(strip_tags(htmlspecialcharsback($f_DESCRIPTION)), 50);
    } else {
        $txt = "[<a href='vote_edit.php?lang=" . LANGUAGE_ID . "&ID={$f_VOTE_ID}'>{$f_VOTE_ID}</a>] " . TruncateText($f_DESCRIPTION, 50);
    }
    $row->AddViewField("TITLE", $txt);
    foreach ($arAllQuestions as $arQuestion) {
        $txt = '';
        foreach ($arQuestion["ANSWERS"] as $arAnswer) {
            if ($msg = CVoteEvent::GetAnswer($arRes['ID'], $arAnswer['ID'])) {
                if ($arAnswer['FIELD_TYPE'] < 4 && intval($msg) > 0) {
                    $msg = $arAnswer['MESSAGE'];
                }
                $txt .= htmlspecialcharsbx($msg) . '<br />';
            }
        }
        $row->AddViewField("Q" . $arQuestion["ID"], $txt);
    }
    $arActions = array();
    $arActions[] = array("DEFAULT" => true, "ICON" => "view", "TEXT" => GetMessage("VOTE_RESULT"), "ACTION" => $lAdmin->ActionRedirect("vote_user_results_table.php?lang=" . LANGUAGE_ID . "&EVENT_ID=" . $f_ID));
    if ($VOTE_RIGHT == "W") {
        $arActions[] = array("ICON" => "delete", "TEXT" => GetMessage("VOTE_DELETE_U"), "ACTION" => $lAdmin->ActionRedirect("javascript:if(confirm('" . GetMessage("VOTE_DELETE_CONFIRMATION") . "')) window.location='?lang=" . LANGUAGE_ID . "&action=delete&VOTE_ID={$VOTE_ID}&ID={$f_ID}&" . bitrix_sessid_get() . "'"));
    }
    $row->AddActions($arActions);
}
                echo $field_name;
                ?>
" value="<?php 
                echo htmlspecialcharsbx($value);
                ?>
" size="<?php 
                echo $arAnswer["FIELD_WIDTH"];
                ?>
" <?php 
                echo $arAnswer["FIELD_PARAM"];
                ?>
><?php 
                break;
            case 5:
                $field_name = "vote_memo_" . $arAnswer["ID"];
                $text = CVoteEvent::GetAnswer($EVENT_ID, $arAnswer["ID"]);
                ?>
<font class="text"><?php 
                if (strlen(trim($arAnswer["MESSAGE"])) > 0) {
                    echo $arAnswer["MESSAGE"] . "<br>";
                }
                ?>
</font><textarea name="<?php 
                echo $field_name;
                ?>
" <?php 
                echo $arAnswer["FIELD_PARAM"];
                ?>
 cols="<?php 
                echo $arAnswer["FIELD_WIDTH"];
                ?>
Esempio n. 7
0
function GetVoteDataByID($VOTE_ID, &$arChannel, &$arVote, &$arQuestions, &$arAnswers, &$arDropDown, &$arMultiSelect, &$arGroupAnswers, $arAddParams = "N")
{
	$VOTE_ID = intval($VOTE_ID);
	$arChannel = array();
	$arVote = array();
	$arQuestions = array();
	$arAnswers = array();
	$arDropDown = array();
	$arMultiSelect = array();

	$GLOBALS["VOTE_CACHE_VOTING"][$VOTE_ID] = (is_array($GLOBALS["VOTE_CACHE_VOTING"][$VOTE_ID]) ? $GLOBALS["VOTE_CACHE_VOTING"][$VOTE_ID] : array());

	if (empty($GLOBALS["VOTE_CACHE_VOTING"][$VOTE_ID]))
	{
		$db_res = CVote::GetByIDEx($VOTE_ID);
		if (!($db_res && $arVote = $db_res->GetNext()))
		{
			return false;
		}

		foreach ($arVote as $key => $res)
		{
			if (strpos($key, "CHANNEL_") === 0)
			{
				$arChannel[substr($key, 8)] = $res;
			}
			elseif (strpos($key, "~CHANNEL_") === 0)
			{
				$arChannel["~".substr($key, 9)] = $res;
			}
		}
		$by = "s_c_sort"; $order = "asc";
		$db_res = CVoteQuestion::GetList($VOTE_ID, $by, $order, array("ACTIVE" => "Y"), $is_filtered);
		while ($res = $db_res->GetNext())
		{
			$arQuestions[$res["ID"]] = $res + array("ANSWERS" => array());
		}
		if (!empty($arQuestions))
		{
			$db_res = CVoteAnswer::GetListEx(
				array("C_SORT" => "ASC"),
				array("VOTE_ID" => $VOTE_ID, "ACTIVE" => "Y", "@QUESTION_ID" => array_keys($arQuestions)));
			while ($res = $db_res->GetNext())
			{
				$arQuestions[$res["QUESTION_ID"]]["ANSWERS"][$res["ID"]] = $res;

				$arAnswers[$res["QUESTION_ID"]][] = $res;

				switch ($res["FIELD_TYPE"]) // dropdown and multiselect and text inputs
				{
					case 2:
						$arDropDown[$res["QUESTION_ID"]] = (is_array($arDropDown[$res["QUESTION_ID"]]) ? $arDropDown[$res["QUESTION_ID"]] :
							array("reference" => array(), "reference_id" => array(), "~reference" => array()));
						$arDropDown[$res["QUESTION_ID"]]["reference"][] = $res["MESSAGE"];
						$arDropDown[$res["QUESTION_ID"]]["~reference"][] = $res["~MESSAGE"];
						$arDropDown[$res["QUESTION_ID"]]["reference_id"][] = $res["ID"];
					break;
					case 3:
						$arMultiSelect[$res["QUESTION_ID"]] = (is_array($arMultiSelect[$res["QUESTION_ID"]]) ? $arMultiSelect[$res["QUESTION_ID"]] :
							array("reference" => array(), "reference_id" => array(), "~reference" => array()));
						$arMultiSelect[$res["QUESTION_ID"]]["reference"][] = $res["MESSAGE"];
						$arMultiSelect[$res["QUESTION_ID"]]["~reference"][] = $res["~MESSAGE"];
						$arMultiSelect[$res["QUESTION_ID"]]["reference_id"][] = $res["ID"];
					break;
				}
			}
			$event_id = intval($arAddParams["bRestoreVotedData"] == "Y" && !!$_SESSION["VOTE"]["VOTES"][$VOTE_ID] ?
				$_SESSION["VOTE"]["VOTES"][$VOTE_ID] : 0);
			$db_res = CVoteEvent::GetUserAnswerStat($VOTE_ID,
				array("bGetMemoStat" => "N", "bGetEventResults" => $event_id));
			if ($db_res && ($res = $db_res->Fetch()))
			{
				do
				{
					if (isset($arQuestions[$res["QUESTION_ID"]]) && is_array($arQuestions[$res["QUESTION_ID"]]["ANSWERS"][$res["ANSWER_ID"]]) && is_array($res))
					{
						$arQuestions[$res["QUESTION_ID"]]["ANSWERS"][$res["ANSWER_ID"]] += $res;
						if ($event_id > 0 && !empty($res["RESTORED_ANSWER_ID"]))
						{
							switch ($arQuestions[$res["QUESTION_ID"]]["ANSWERS"][$res["ANSWER_ID"]]["FIELD_TYPE"]):
								case 0: // radio
								case 2: // dropdown list
									$fieldName = ($arQuestions[$res["QUESTION_ID"]]["ANSWERS"][$res["ANSWER_ID"]]["FIELD_TYPE"] == 0 ?
										"vote_radio_" : "vote_dropdown_").$res["QUESTION_ID"];
									$_REQUEST[$fieldName] = $res["RESTORED_ANSWER_ID"];
									break;
								case 1: // checkbox
								case 3: // multiselect list
									$fieldName = ($arQuestions[$res["QUESTION_ID"]]["ANSWERS"][$res["ANSWER_ID"]]["FIELD_TYPE"] == 1 ?
										"vote_checkbox_" : "vote_multiselect_").$res["QUESTION_ID"];
									$_REQUEST[$fieldName] = (is_array($_REQUEST[$fieldName]) ? $_REQUEST[$fieldName] : array());
									$_REQUEST[$fieldName][] = $res["ANSWER_ID"];
									break;
								case 4: // field
								case 5: // text
									// do not restored
									break;
							endswitch;
						}
					}
				} while ($res = $db_res->Fetch());
			}
		}

		reset($arChannel);
		reset($arVote);
		reset($arQuestions);
		reset($arDropDown);
		reset($arMultiSelect);
		reset($arAnswers);

		$GLOBALS["VOTE_CACHE_VOTING"][$VOTE_ID] = array(
			"V" => $arVote,
			"C" => $arChannel,
			"QA" => array(
				"Q" => $arQuestions,
				"A" => $arAnswers,
				"M" => $arMultiSelect,
				"D" => $arDropDown,
				"G" => array(),
				"GA" => "N"
			)
		);
	}

	if ($arAddParams["bGetMemoStat"] == "Y" && $GLOBALS["VOTE_CACHE_VOTING"][$VOTE_ID]["QA"]["GA"] == "N")
	{
		$db_res = CVoteEvent::GetUserAnswerStat($VOTE_ID, array("bGetMemoStat" => "Y"));
		while($res = $db_res->GetNext(true, false))
		{
			$arGroupAnswers[$res['ANSWER_ID']][] = $res;
		}
		$GLOBALS["VOTE_CACHE_VOTING"][$VOTE_ID]["QA"]["G"] = $arGroupAnswers;
		$GLOBALS["VOTE_CACHE_VOTING"][$VOTE_ID]["QA"]["GA"] = "Y";
	}

	$arVote = $GLOBALS["VOTE_CACHE_VOTING"][$VOTE_ID]["V"];
	$arChannel = $GLOBALS["VOTE_CACHE_VOTING"][$VOTE_ID]["C"];
	$arQuestions =	$GLOBALS["VOTE_CACHE_VOTING"][$VOTE_ID]["QA"]["Q"];
	$arAnswers = $GLOBALS["VOTE_CACHE_VOTING"][$VOTE_ID]["QA"]["A"];
	$arMultiSelect = $GLOBALS["VOTE_CACHE_VOTING"][$VOTE_ID]["QA"]["M"];
	$arDropDown = $GLOBALS["VOTE_CACHE_VOTING"][$VOTE_ID]["QA"]["D"];
	$arGroupAnswers = $GLOBALS["VOTE_CACHE_VOTING"][$VOTE_ID]["QA"]["G"];
	return $arVote["ID"];
}
        switch ($_REQUEST['action']) {
            case "delete":
                if (!CVoteEvent::Delete($ID)) {
                    $lAdmin->AddGroupError(GetMessage("DELETE_ERROR"), $ID);
                }
                break;
            case "validate":
            case "devalidate":
                $varVALID = $_REQUEST['action'] == "validate" ? "Y" : "N";
                CVoteEvent::SetValid($ID, $varVALID);
                break;
        }
    }
}
/************** Initial list - Get data ****************************/
$rsData = CVoteEvent::GetList($by, $order, $arFilter, $is_filtered);
$rsData = new CAdminResult($rsData, $sTableID);
$rsData->NavStart();
/************** Initial list - Navigation **************************/
$lAdmin->NavText($rsData->GetNavPrint(GetMessage("VOTE_PAGES")));
$lAdmin->AddHeaders(array(array("id" => "ID", "content" => "ID", "sort" => "s_id", "default" => true), array("id" => "VOTE_USER_ID", "content" => GetMessage("VOTE_USER"), "sort" => "s_vote_user", "default" => true), array("id" => "STAT_SESSION_ID", "content" => GetMessage("VOTE_SESSION"), "sort" => "s_session", "default" => true), array("id" => "IP", "content" => "IP", "sort" => "s_ip", "default" => true), array("id" => "DATE_VOTE", "content" => GetMessage("VOTE_DATE"), "sort" => "s_date", "default" => true), array("id" => "TITLE", "content" => GetMessage("VOTE_VOTE"), "sort" => "s_vote", "default" => true), array("id" => "VALID", "content" => GetMessage("VOTE_VALID"), "sort" => "s_valid", "default" => true)));
$arrUsers = array();
while ($arRes = $rsData->NavNext(true, "f_")) {
    $row =& $lAdmin->AddRow($f_ID, $arRes);
    $row->AddViewField("VALID", $f_VALID == "Y" ? GetMessage("MAIN_YES") : GetMessage("MAIN_NO"));
    $row->AddViewField("VOTE_USER_ID", "<a title=\"" . GetMessage("VOTE_USER_LIST_TITLE") . "\" href=\"vote_user_list.php?lang=" . LANGUAGE_ID . "&find_id={$f_VOTE_USER_ID}&set_filter=Y\">{$f_VOTE_USER_ID}</a>");
    if (CModule::IncludeModule("statistic")) {
        $row->AddViewField("STAT_SESSION_ID", "<a title=\"" . GetMessage("VOTE_SESSIONU_LIST_TITLE") . "\" href=\"session_list.php?lang=" . LANGUAGE_ID . "&find_id={$f_STAT_SESSION_ID}&set_filter=Y\">{$f_STAT_SESSION_ID}</a>");
    }
    if (strlen($f_TITLE) > 0) {
        $txt = "[<a title='" . GetMessage("VOTE_EDIT_TITLE") . "' href='vote_edit.php?lang=" . LANGUAGE_ID . "&ID={$f_VOTE_ID}'>{$f_VOTE_ID}</a>] {$f_TITLE}";