3#############################################
4# Bitrix Site Manager Forum #
5# Copyright (c) 2002-2009 Bitrix #
7# mailto:admin@bitrixsoft.com #
8#############################################
21 $arQuestion =
array();
27 "text" =>
GetMessage(
"VOTE_QUESTION_NOT_FOUND"));
47 if (!
$USER ||
$USER->CanDoOperation(
'edit_php') !==
true)
53 $aMsg[] = [
"id" =>
"QUESTION",
"text" =>
GetMessage(
"VOTE_FORGOT_QUESTION")];
68 $arFields[
"IMAGE_ID"][
"MODULE_ID"] =
"vote";
69 if (!empty($arQuestion)):
70 $arFields[
"IMAGE_ID"][
"old_file"] = $arQuestion[
"IMAGE_ID"];
89 && COption::GetOptionString(
"vote",
"VOTE_COMPATIBLE_OLD_TEMPLATE",
"N") ==
"Y")
111 $strUploadDir = ($strUploadDir ===
false ?
"vote" : $strUploadDir);
116 foreach (
GetModuleEvents(
"vote",
"onBeforeVoteQuestionAdd",
true) as $arEvent)
127 !array_key_exists(
"MODULE_ID",
$arFields[
"IMAGE_ID"])
128 ||
$arFields[
"IMAGE_ID"][
"MODULE_ID"] ==
''
131 $arFields[
"IMAGE_ID"][
"MODULE_ID"] =
"vote";
133 CFile::SaveForDB(
$arFields,
"IMAGE_ID", $strUploadDir);
135 if (
$DB->type ==
"ORACLE")
143 $arInsert =
$DB->PrepareInsert(
"b_vote_question",
$arFields);
145 $DB->QueryBind(
"INSERT INTO b_vote_question (".$arInsert[0].
", TIMESTAMP_X) VALUES(".$arInsert[1].
", ".
$DB->GetNowFunction().
")",
array(
"QUESTION" =>
$arFields[
"QUESTION"]),
false);
149 foreach (
GetModuleEvents(
"vote",
"onAfterVoteQuestionAdd",
true) as $arEvent)
160 $strUploadDir = ($strUploadDir ===
false ?
"vote" : $strUploadDir);
166 foreach (
GetModuleEvents(
"vote",
"onBeforeVoteQuestionUpdate",
true) as $arEvent)
177 !array_key_exists(
"MODULE_ID",
$arFields[
"IMAGE_ID"])
178 ||
$arFields[
"IMAGE_ID"][
"MODULE_ID"] ==
''
181 $arFields[
"IMAGE_ID"][
"MODULE_ID"] =
"vote";
183 CFile::SaveForDB(
$arFields,
"IMAGE_ID", $strUploadDir);
191 $strUpdate =
$DB->PrepareUpdate(
"b_vote_question",
$arFields);
193 $arBinds[
"QUESTION"] =
$arFields[
"QUESTION"];
195 if (!empty($strUpdate))
196 $DB->QueryBind(
"UPDATE b_vote_question SET ".$strUpdate.
" WHERE ID=".
$ID, $arBinds);
200 foreach (
GetModuleEvents(
"vote",
"onAfterVoteQuestionUpdate",
true) as $arEvent)
211 $newVoteID = intval($newVoteID);
215 if (!($arQuestion =
$res->Fetch()))
217 $arQuestion[
'VOTE_ID'] = $newVoteID;
218 unset($arQuestion[
'ID']);
220 if ($newQuestionID ===
false)
224 while ($arAnswer = $rAnswers->Fetch())
226 $arAnswer[
'QUESTION_ID'] = $newQuestionID;
227 unset($arAnswer[
'ID']);
230 if (!$state)
return $state;
233 return $newQuestionID;
240 $VOTE_ID = intval($VOTE_ID);
241 $strSql =
"SELECT max(C_SORT) as MAX_SORT FROM b_vote_question WHERE VOTE_ID='$VOTE_ID'";
242 $z =
$DB->Query($strSql);
244 return (intval(
$zr[
"MAX_SORT"]) + 100);
254 if (!is_array(
$GLOBALS[
"VOTE_CACHE"][
"QUESTION"]))
257 if (!array_key_exists(
$ID,
$GLOBALS[
"VOTE_CACHE"][
"QUESTION"]))
272 $VOTE_ID = (int) $VOTE_ID;
284 $strNegative = $key_res[
'NEGATIVE'];
285 $strOperation = $key_res[
'OPERATION'];
286 $key = strtoupper($key_res[
'FIELD']);
291 $match = ((
$arFilter[
$key .
'_EXACT_MATCH'] ??
'Y') ===
'N' ?
'Y' :
'N');
297 $arSqlSearch[] = ($strNegative ===
'Y' ?
' Q.' .
$key .
' IS NULL OR NOT ' :
'')
298 .
' (Q.' .
$key .
' ' . $strOperation .
' \'' .
$DB->ForSql(
$val) .
'\')
';
301 $match = (($arFilter[$key . '_EXACT_MATCH
'] ?? 'Y
') !== 'N
' ? 'Y
' : 'N
'); //turn on
302 $arSqlSearch[] = GetFilterQuery('Q.QUESTION
', $val, $match);
307 $arSqlSearch[] = 'Q.VOTE_ID =
' . $VOTE_ID;
310 $by = strtoupper(strpos($by, 's_
') === 0 ? substr($by, 2) : $by);
311 $by = in_array($by, ['ID
', 'TIMESTAMP_X
', 'ACTIVE
', 'DIAGRAM
', 'C_SORT
', 'REQUIRED
']) ? $by : 'C_SORT
';
312 $order = ($order !== 'desc
' ? 'asc
' : 'desc
');
313 $strSqlOrder = 'Q.
' . $by . ' ' . $order;
316 $strSqlSearch = GetFilterSqlSearch($arSqlSearch);
319 ' . $DB->DateToCharFunction('Q.TIMESTAMP_X
','SHORT
') . ' TIMESTAMP_X
320 FROM b_vote_question Q
321 WHERE
' . $strSqlSearch . '
322 ORDER BY
' . $strSqlOrder;
323 $res = $DB->Query($strSql);
328 public static function GetListEx($arOrder = array("ID" => "ASC"), $arFilter=array())
332 $arSqlSearch = array();
334 $arSqlOrder = array();
337 $arFilter = (is_array($arFilter) ? $arFilter : array());
338 foreach ($arFilter as $key => $val)
340 if($val === "NOT_REF")
342 $key_res = VoteGetFilterOperation($key);
343 $strNegative = $key_res["NEGATIVE"];
344 $strOperation = $key_res["OPERATION"];
345 $key = mb_strtoupper($key_res["FIELD"]);
351 $str = ($strNegative=="Y"?"NOT":"")."(VQ.".$key." IS NULL OR VQ.".$key."<=0)";
354 $str = ($strNegative=="Y"?" VQ.".$key." IS NULL OR NOT ":"")."(VQ.".$key." ".$strOperation." ".intval($val).")";
355 if ($strOperation == "IN")
357 $val = array_unique(array_map("intval", (is_array($val) ? $val : explode(",", $val))), SORT_NUMERIC);
360 $str = ($strNegative=="Y"?" NOT ":"")."(VQ.".$key." IN (".implode(",", $val)."))";
364 $arSqlSearch[] = $str;
368 $arSqlSearch[] = ($strNegative=="Y"?"NOT":"")."(V.".$key." IS NULL OR V.".$key."<=0)";
370 $arSqlSearch[] = ($strNegative=="Y"?" V.".$key." IS NULL OR NOT ":"")."(V.".$key." ".$strOperation." ".intval($val).")";
374 $arSqlSearch[] = ($strNegative=="Y"?"NOT":"")."(VQ.".$key." IS NULL OR ".($DB->type == "MSSQL" ? "LEN" : "LENGTH")."(VQ.".$key.")<=0)";
376 $arSqlSearch[] = ($strNegative=="Y"?" VQ.".$key." IS NULL OR NOT ":"")."(VQ.".$key." ".$strOperation." '".$DB->ForSql($val)."')";
380 if (count($arSqlSearch) > 0)
381 $strSqlSearch = " AND (".implode(") AND (", $arSqlSearch).") ";
383 foreach ($arOrder as $by => $order)
385 $by = mb_strtoupper($by);
386 $order = mb_strtoupper($order);
387 $by = ($by == "ACTIVE" ? $by : "ID");
388 if ($order!="ASC") $order = "DESC";
389 if ($by == "ACTIVE") $arSqlOrder[] = " VQ.ACTIVE ".$order." ";
390 else $arSqlOrder[] = " VQ.ID ".$order." ";
392 DelDuplicateSort($arSqlOrder);
393 if (count($arSqlOrder) > 0)
394 $strSqlOrder = " ORDER BY ".implode(", ", $arSqlOrder);
399 b_vote_question VQ, b_vote V
400 WHERE VQ.VOTE_ID = V.ID ".
403 return $DB->Query($strSql);
406 public static function Delete($ID, $VOTE_ID = false)
409/***************** Event onBeforeVoteQuestionDelete ****************/
410 foreach (GetModuleEvents("vote", "onBeforeVoteQuestionDelete", true) as $arEvent)
411 if (ExecuteModuleEventEx($arEvent, array(&$ID, &$VOTE_ID)) === false)
413/***************** /Event ******************************************/
414 if (!CVoteAnswer::Delete(false, $ID, $VOTE_ID))
417 $ID = (intval($ID) > 0 ? intval($ID) : false);
418 $VOTE_ID = (intval($VOTE_ID) > 0 ? intval($VOTE_ID) : false);
419 if ($ID === false && $VOTE_ID === false):
421 elseif ($ID === false):
422 $strSqlID = "SELECT Q.ID FROM b_vote_question Q WHERE Q.VOTE_ID=".$VOTE_ID;
424 $strSqlID = "".$ID."";
427 $DB->StartTransaction();
428 $strSql = "SELECT IMAGE_ID FROM b_vote_question WHERE ID IN (".$strSqlID.") AND IMAGE_ID > 0";
429 $z = $DB->Query($strSql);
430 while ($zr = $z->Fetch()) CFile::Delete($zr["IMAGE_ID"]);
432 // drop question events
433 if (!$DB->Query("DELETE FROM b_vote_event_question WHERE QUESTION_ID IN (".$strSqlID.")")):
439 $strSql = "DELETE FROM b_vote_question WHERE VOTE_ID=".$VOTE_ID;
441 $strSql = "DELETE FROM b_vote_question WHERE ID=".$ID;
444 if (!$DB->Query($strSql)):
450/***************** Cleaning cache **********************************/
452 unset($GLOBALS["VOTE_CACHE"]["QUESTION"]);
454 unset($GLOBALS["VOTE_CACHE"]["QUESTION"][$ID]);
456/***************** Cleaning cache/**********************************/
458/***************** Event onAfterForumDelete ************************/
459 foreach (GetModuleEvents("vote", "onAfterVoteQuestionDelete", true) as $arEvent)
460 ExecuteModuleEventEx($arEvent, array($ID, $VOTE_ID));
461/***************** /Event ******************************************/
465 public static function Reset($ID, $VOTE_ID = false)
469 $ID = (intval($ID) > 0 ? intval($ID) : false);
470 $VOTE_ID = (intval($VOTE_ID) > 0 ? intval($VOTE_ID) : false);
473 $strSqlID = "".$ID."";
474 elseif ($VOTE_ID > 0):
475 $strSqlID = "SELECT Q.ID FROM b_vote_question Q WHERE Q.VOTE_ID=".$VOTE_ID;
480 // drop answer events
481 $DB->Query("DELETE FROM b_vote_event_answer WHERE EVENT_QUESTION_ID IN (
482 SELECT ID FROM b_vote_event_question WHERE QUESTION_ID IN (".$strSqlID."))");
483 // drop question events
484 $DB->Query("DELETE FROM b_vote_event_question WHERE QUESTION_ID IN (".$strSqlID.")");
486 // zeroize answers counter
487 $arFields = array("COUNTER"=>"0");
488 $DB->Update("b_vote_answer", $arFields, "WHERE QUESTION_ID IN (".$strSqlID.")");
490 // zeroize questions counter
491 $arFields = array("COUNTER" => "0");
492 $DB->Update("b_vote_question", $arFields, "WHERE ".(
493 $ID > 0 ? "ID = ".$ID."" : "VOTE_ID = ".$VOTE_ID.""));
496/***************** Cleaning cache **********************************/
498 unset($GLOBALS["VOTE_CACHE"]["QUESTION"]);
500 unset($GLOBALS["VOTE_CACHE"]["QUESTION"][$ID]);
501/***************** Cleaning cache/**********************************/
505 public static function setActive($ID, $activate = true)
510 $activate = (!!$activate);
511/***************** Event onBeforeVoteQuestionUpdate ****************/
512 foreach (GetModuleEvents("vote", "onVoteQuestionActivate", true) as $arEvent)
513 if (ExecuteModuleEventEx($arEvent, array($ID, $activate)) === false)
515/***************** /Event ******************************************/
519 $strUpdate = $DB->PrepareUpdate("b_vote_question", array("ACTIVE" => ($activate ? "Y" : "N"), "~TIMESTAMP_X" => $DB->GetNowFunction()));
520 $DB->QueryBind("UPDATE b_vote_question SET ".$strUpdate." WHERE ID=".$ID, array());
521 unset($GLOBALS["VOTE_CACHE"]["QUESTION"][$ID]);
static cleanText(?string $text)
static GetList($QUESTION_ID, $by="s_c_sort", $order="asc", $arFilter=array(), $arAddParams=array())
static GetList($VOTE_ID, $by='s_c_sort', $order='asc', $arFilter=[])
static GetNextSort($VOTE_ID)
static Update($ID, $arFields, $strUploadDir=false)
static CheckFields($ACTION, &$arFields, $ID=0)
static Copy($ID, $newVoteID)
static Reset($ID, $VOTE_ID=false)
static Add($arFields, $strUploadDir=false)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
ExecuteModuleEventEx($arEvent, $arParams=[])
GetModuleEvents($MODULE_ID, $MESSAGE_ID, $bReturnArray=false)
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
GetMessage($name, $aReplace=null)
$GLOBALS['____1690880296']
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
if(empty($signedUserToken)) $key
VoteGetFilterOperation($key)
const VOTE_DEFAULT_DIAGRAM_TYPE