Ejemplo n.º 1
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"];
}
Ejemplo n.º 2
0
 function GetAdminListViewHTML($arUserField, $arHtmlControl)
 {
     $return = ' ';
     $return_url = $GLOBALS["APPLICATION"]->GetCurPageParam("", array("admin_history", "mode", "table_id"));
     if ($arHtmlControl["VALUE"] > 0) {
         $db_res = CVote::GetByIDEx($arHtmlControl["VALUE"]);
         if ($db_res && ($arVote = $db_res->GetNext())) {
             if ($arVote["LAMP"] == "yellow") {
                 $arVote["LAMP"] = $arVote["ID"] == CVote::GetActiveVoteId($arVote["CHANNEL_ID"]) ? "green" : "red";
             }
             $return = "<div class=\"lamp-red\" title=\"" . ($arVote["ACTIVE"] != 'Y' ? GetMessage("VOTE_NOT_ACTIVE") : GetMessage("VOTE_ACTIVE_RED_LAMP")) . "\"  style=\"display:inline-block;\"></div>";
             if ($arVote["LAMP"] == "green") {
                 $return = "<div class=\"lamp-green\" title=\"" . GetMessage("VOTE_LAMP_ACTIVE") . "\" style=\"display:inline-block;\"></div>";
             }
             $return .= " [<a href='vote_edit.php?lang=" . LANGUAGE_ID . "&ID=" . $arVote["ID"] . "&return_url=" . urlencode($return_url) . "' title='" . GetMessage("VOTE_EDIT_TITLE") . "'>" . $arVote["ID"] . "</a>] ";
             $return .= $arVote["TITLE"] . (!empty($arVote["DESCRIPTION"]) ? " <i>(" . $arVote["DESCRIPTION"] . ")</i>" : "");
             if ($arVote["COUNTER"] > 0) {
                 $return .= GetMessage("VOTE_VOTES") . " <a href=\"vote_user_votes.php?lang=" . LANGUAGE_ID . "&find_vote_id=" . $arVote["ID"] . "&find_valid=Y&set_filter=Y\">" . $arVote["COUNTER"] . "</a>";
             }
         }
     }
     return $return;
 }
Ejemplo n.º 3
0
if ($arParams["CACHE_TYPE"] == "Y" || $arParams["CACHE_TYPE"] == "A" && COption::GetOptionString("main", "component_cache_on", "Y") == "Y") {
    $arParams["CACHE_TIME"] = intval($arParams["CACHE_TIME"]);
} else {
    $arParams["CACHE_TIME"] = 0;
}
/********************************************************************
				/Input params
********************************************************************/
$obCache = new CPHPCache();
$cache_path = str_replace(array(":", "//"), "/", "/" . SITE_ID . "/" . $componentName . "/" . $arParams["CHANNEL_SID"] . "/");
$cache_id = "vote_current_" . serialize($arParams) . (($tzOffset = CTimeZone::GetOffset()) != 0 ? "_" . $tzOffset : "");
if (!$obCache->InitCache($arParams["CACHE_TIME"], $cache_id, $cache_path)) {
    $arVote = array();
    $db_res = false;
    if (!!$arParams["VOTE_ID"]) {
        $db_res = CVote::GetByIDEx($arParams["VOTE_ID"]);
    } else {
        $obChannel = CVoteChannel::GetList($by, $order, array("SID" => $arParams["CHANNEL_SID"], "SID_EXACT_MATCH" => "Y", "SITE" => SITE_ID, "ACTIVE" => "Y", "HIDDEN" => "N"), $is_filtered);
        if ($obChannel && ($arChannel = $obChannel->Fetch())) {
            $db_res = CVote::GetList($by, $order, array("CHANNEL_ID" => $arChannel["ID"], "LAMP" => "green"), $is_filtered);
        }
    }
    $arVote = $db_res ? $db_res->Fetch() : array();
    if (empty($arVote) || $arVote["CHANNEL_ACTIVE"] != "Y" || $arVote["ACTIVE"] != "Y") {
        return false;
    }
    $arResult = array("VOTE" => $arVote, "VOTE_ID" => $arVote["ID"], "VOTE_RESULT_TEMPLATE" => $APPLICATION->GetCurPageParam("", array("VOTE_SUCCESSFULL", "VOTE_ID", "view_form")), "ADDITIONAL_CACHE_ID" => "current_vote");
    $obCache->StartDataCache();
    CVoteCacheManager::SetTag($cache_path, array("C" => $arVote["CHANNEL_ID"], "V" => $arVote["ID"]));
    $obCache->EndDataCache(array("arResult" => $arResult));
} else {