Example #1
0
 public static function Copy($ID)
 {
     global $DB;
     $err_mess = CVote::err_mess() . "<br>Function: Copy<br>Line: ";
     $ID = intval($ID);
     if ($ID <= 0) {
         return false;
     }
     $rCurrentVote = CVote::GetByID($ID);
     if (!($arCurrentVote = $rCurrentVote->Fetch())) {
         return false;
     }
     unset($arCurrentVote["ID"]);
     $arCurrentVote['ACTIVE'] = "N";
     $newImageId = false;
     if (intval($arCurrentVote['IMAGE_ID'] > 0)) {
         $imageId = $arCurrentVote['IMAGE_ID'];
         $newImageId = CFile::CopyFile($imageId);
         $arCurrentVote["IMAGE_ID"] = NULL;
     }
     $newID = CVote::Add($arCurrentVote);
     if ($newID === false) {
         return false;
     }
     $DB->Update("b_vote", array("COUNTER" => "0"), "WHERE ID=" . $newID, $err_mess . __LINE__);
     if ($newImageId) {
         $DB->Update("b_vote", array("IMAGE_ID" => $newImageId), "WHERE ID=" . $newID, $err_mess . __LINE__);
     }
     $state = true;
     $rQuestions = CVoteQuestion::GetList($ID, $by, $order, array(), $is_filtered);
     while ($arQuestion = $rQuestions->Fetch()) {
         $state = $state && CVoteQuestion::Copy($arQuestion['ID'], $newID) !== false;
     }
     if ($state == true) {
         return $newID;
     } else {
         return $state;
     }
 }
Example #2
0
 function GetPublicList($arFilter = array(), $strSqlOrder = "ORDER BY C.C_SORT, C.ID, V.DATE_START desc", $params = array())
 {
     global $DB, $USER;
     $err_mess = CVote::err_mess() . "<br>Function: GetPublicList<br>Line: ";
     $arSqlSearch = array();
     $arFilter = is_array($arFilter) ? $arFilter : array();
     $params = is_array($params) ? $params : array();
     $left_join = "";
     foreach ($arFilter as $key => $val) {
         if (empty($val) || is_string($val) && $val === "NOT_REF") {
             continue;
         }
         $key = strtoupper($key);
         switch ($key) {
             case "SITE":
                 $val = is_array($val) ? implode(" | ", $val) : $val;
                 $match = $arFilter[$key . "_EXACT_MATCH"] == "N" ? "Y" : "N";
                 $arSqlSearch[] = GetFilterQuery("CS.SITE_ID", $val, $match);
                 $left_join = "LEFT JOIN b_vote_channel_2_site CS ON (C.ID = CS.CHANNEL_ID)";
                 break;
             case "CHANNEL":
                 $match = $arFilter[$key . "_EXACT_MATCH"] == "N" ? "Y" : "N";
                 if (is_array($val)) {
                     $arr = array();
                     foreach ($val as $v) {
                         $v = trim($v);
                         if (!empty($v)) {
                             $arr[] = GetFilterQuery("C.SYMBOLIC_NAME", $v, $match);
                         }
                     }
                     if (!empty($arr)) {
                         $arSqlSearch[] = "((" . implode(") OR (", $arr) . "))";
                     }
                 } else {
                     $arSqlSearch[] = GetFilterQuery("C.SYMBOLIC_NAME", $val, $match);
                 }
                 break;
             case "FIRST_SITE_ID":
             case "LID":
                 $match = $arFilter[$key . "_EXACT_MATCH"] == "N" ? "Y" : "N";
                 $arSqlSearch[] = GetFilterQuery("C.FIRST_SITE_ID", $val, $match);
                 break;
         }
     }
     $strSqlSearch = GetFilterSqlSearch($arSqlSearch);
     $is_admin = in_array(1, $USER->GetUserGroupArray());
     $groups = $USER->GetGroups();
     $iCnt = 0;
     if (array_key_exists("bDescPageNumbering", $params) && $params["nTopCount"] <= 0 || $params["bCount"] === true) {
         $strSql = "SELECT COUNT(V1.ID) CNT\n\t\t\t\tFROM (\n\t\t\t\t\tSELECT V.CHANNEL_ID, V.ID, " . ($is_admin ? "2" : "max(G.PERMISSION)") . " as MAX_PERMISSION\n\t\t\t\t\tFROM b_vote V\n\t\t\t\t\tINNER JOIN b_vote_channel C ON (C.ACTIVE = 'Y' AND C.HIDDEN = 'N' AND V.CHANNEL_ID = C.ID)\n\t\t\t\t\tLEFT JOIN b_vote_channel_2_group G ON (G.CHANNEL_ID = C.ID and G.GROUP_ID in ({$groups}))\n\t\t\t\t\t{$left_join}\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t{$strSqlSearch}\n\t\t\t\t\t\tAND V.ACTIVE = 'Y' AND V.DATE_START <= NOW()\n\t\t\t\t\tGROUP BY V.CHANNEL_ID, V.ID\n\t\t\t\t\t" . ($is_admin ? "" : "\n\t\t\t\t\tHAVING MAX_PERMISSION > 0") . "\n\t\t\t\t) V1";
         $db_res = $DB->Query($strSql, false, $err_mess . __LINE__);
         if ($db_res && ($res = $db_res->Fetch())) {
             $iCnt = intval($res["CNT"]);
         }
         if ($params["bCount"] === true) {
             return $iCnt;
         }
     }
     $strSql = "\n\t\t\tSELECT C.TITLE CHANNEL_TITLE, V.*,\n\t\t\t\t" . $DB->DateToCharFunction("V.DATE_START") . "\tDATE_START,\n\t\t\t\t" . $DB->DateToCharFunction("V.DATE_END") . "\tDATE_END, \n\t\t\t\tV4.MAX_PERMISSION, V4.LAMP\n\t\t\tFROM (\n\t\t\t\tSELECT V.CHANNEL_ID, V.ID,\n\t\t\t\t\t" . ($is_admin ? "2" : "max(G.PERMISSION)") . " as MAX_PERMISSION, \n\t\t\t\t\tIF((C.VOTE_SINGLE = 'Y'), \n\t\t\t\t\t\t(IF(V.ID = VV.ACTIVE_VOTE_ID, 'green', 'red')), \n\t\t\t\t\t\t(IF(V.ACTIVE = 'Y' AND V.DATE_START <= NOW() AND NOW() <= V.DATE_END, 'green', 'red'))) LAMP \n\t\t\t\tFROM b_vote V\n\t\t\t\tINNER JOIN b_vote_channel C ON (C.ACTIVE = 'Y' AND C.HIDDEN = 'N' AND V.CHANNEL_ID = C.ID)\n\t\t\t\tLEFT JOIN (\n\t\t\t\t\tSELECT VVV.CHANNEL_ID, MAX(VVV.ID) AS ACTIVE_VOTE_ID\n\t\t\t\t\tFROM b_vote VVV, b_vote_channel CCC\n\t\t\t\t\tWHERE VVV.CHANNEL_ID = CCC.ID AND CCC.VOTE_SINGLE='Y' AND VVV.ACTIVE = 'Y' \n\t\t\t\t\t\tAND NOW() >= VVV.DATE_START AND VVV.DATE_END >= NOW()\n\t\t\t\t\tGROUP BY VVV.CHANNEL_ID) VV ON (VV.CHANNEL_ID = V.CHANNEL_ID)\n\t\t\t\tLEFT JOIN b_vote_channel_2_group G ON (G.CHANNEL_ID = C.ID and G.GROUP_ID in ({$groups}))\n\t\t\t\t{$left_join}\n\t\t\t\tWHERE\n\t\t\t\t\t{$strSqlSearch}\n\t\t\t\t\tAND V.ACTIVE = 'Y' AND V.DATE_START <= NOW()\n\t\t\t\tGROUP BY V.CHANNEL_ID, V.ID\n\t\t\t\t" . ($is_admin ? "" : "\n\t\t\t\tHAVING MAX_PERMISSION > 0") . "\n\t\t\t) V4\n\t\t\tINNER JOIN b_vote V ON (V4.ID = V.ID)\n\t\t\tINNER JOIN b_vote_channel C ON (V4.CHANNEL_ID = C.ID) \n\t\t\t" . $DB->ForSql($strSqlOrder);
     if (array_key_exists("bDescPageNumbering", $params) && $params["nTopCount"] <= 0) {
         $db_res = new CDBResult();
         $db_res->NavQuery($strSql, $iCnt, $params);
     } else {
         if ($params["nTopCount"] > 0) {
             $strSql .= " LIMIT 0," . intval($params["nTopCount"]);
         }
         $db_res = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
     }
     return $db_res;
 }
Example #3
0
 function GetPublicList($arFilter = array(), $strSqlOrder = "ORDER BY C.C_SORT, C.ID, V.DATE_START desc")
 {
     $err_mess = CVote::err_mess() . "<br>Function: GetPublicList<br>Line: ";
     global $DB, $USER;
     $arSqlSearch = array();
     $strSqlSearch = "";
     $arSqlSearch_1 = array();
     $strSqlSearch_1 = "";
     if (is_array($arFilter)) {
         $filter_keys = array_keys($arFilter);
         for ($i = 0; $i < count($filter_keys); $i++) {
             $key = $filter_keys[$i];
             $val = $arFilter[$filter_keys[$i]];
             if (strlen($val) <= 0 || $val == "NOT_REF") {
                 continue;
             }
             if (is_array($val) && count($val) <= 0) {
                 continue;
             }
             $match_value_set = in_array($key . "_EXACT_MATCH", $filter_keys) ? true : false;
             $key = strtoupper($key);
             switch ($key) {
                 case "SITE":
                     if (is_array($val)) {
                         $val = implode(" | ", $val);
                     }
                     $match = $arFilter[$key . "_EXACT_MATCH"] == "N" && $match_value_set ? "Y" : "N";
                     $arSqlSearch_1[] = GetFilterQuery("CS.SITE_ID", $val, $match);
                     $strSqlSearch_1 = GetFilterSqlSearch($arSqlSearch_1);
                     $where = " and exists (SELECT 'x' FROM b_vote_channel_2_site CS WHERE {$strSqlSearch_1} and C.ID = CS.CHANNEL_ID) ";
                     break;
                 case "CHANNEL":
                     $match = $arFilter[$key . "_EXACT_MATCH"] == "N" && $match_value_set ? "Y" : "N";
                     $arSqlSearch[] = GetFilterQuery("C.SYMBOLIC_NAME", $val, $match);
                     break;
                 case "FIRST_SITE_ID":
                 case "LID":
                     $match = $arFilter[$key . "_EXACT_MATCH"] == "N" && $match_value_set ? "Y" : "N";
                     $arSqlSearch[] = GetFilterQuery("C.FIRST_SITE_ID", $val, $match);
                     break;
             }
         }
     }
     $strSqlSearch = GetFilterSqlSearch($arSqlSearch);
     $arGroups = $USER->GetUserGroupArray();
     if (!is_array($arGroups)) {
         $arGroups[] = 2;
     }
     $groups = implode(",", $arGroups);
     if (!$USER->IsAdmin()) {
         $strSql = "\r\n\t\t\t\tSELECT\r\n\t\t\t\t\tC.TITLE CHANNEL_TITLE, \r\n\t\t\t\t\tV.ID, V.CHANNEL_ID, V.C_SORT, V.ACTIVE, V.COUNTER, V.TITLE, V.DESCRIPTION, V.DESCRIPTION_TYPE, V.IMAGE_ID, V.EVENT1, V.EVENT2, V.EVENT3, V.UNIQUE_TYPE, V.KEEP_IP_SEC, V.DELAY, V.DELAY_TYPE, V.TEMPLATE, V.RESULT_TEMPLATE, V.NOTIFY,\r\n\t\t\t\t\t" . $DB->DateToCharFunction("V.DATE_START") . "\t\tDATE_START,\r\n\t\t\t\t\t" . $DB->DateToCharFunction("V.DATE_END") . "\t\tDATE_END,\r\n\t\t\t\t\tmax(G.PERMISSION)\t\t\t\t\t\t\t\tMAX_PERMISSION,\r\n\t\t\t\t\tcase \r\n\t\t\t\t\t\twhen V.ACTIVE='N' or getdate() not between V.DATE_START and V.DATE_END then 'red'\r\n\t\t\t\t\t\telse 'green'\r\n\t\t\t\t\tend\t\t\t\t\t\t\t\t\t\t\t\tLAMP\r\n\t\t\t\tFROM\r\n\t\t\t\t\tb_vote V\r\n\t\t\t\tINNER JOIN b_vote_channel C ON (C.ID = V.CHANNEL_ID and C.ACTIVE = 'Y')\r\n\t\t\t\tINNER JOIN b_vote_channel_2_group G ON (G.CHANNEL_ID = C.ID and G.GROUP_ID in ({$groups}))\r\n\t\t\t\tWHERE\r\n\t\t\t\t\t{$strSqlSearch}\r\n\t\t\t\tand V.ACTIVE = 'Y'\r\n\t\t\t\tand V.DATE_START<=getdate()\t\t\t\t\t\r\n\t\t\t\t{$where}\r\n\t\t\t\tGROUP BY\r\n\t\t\t\t\tC.ID, C.TITLE, \r\n\t\t\t\t\tV.ID, V.CHANNEL_ID, V.C_SORT, V.ACTIVE, V.COUNTER, V.TITLE, V.DESCRIPTION, V.DESCRIPTION_TYPE, V.IMAGE_ID, V.EVENT1, V.EVENT2, V.EVENT3, V.UNIQUE_TYPE, V.KEEP_IP_SEC, V.DELAY, V.DELAY_TYPE, V.TEMPLATE, V.RESULT_TEMPLATE, V.NOTIFY,\r\n\t\t\t\t\tV.DATE_START, V.DATE_END, \r\n\t\t\t\t\tC.C_SORT, C.ID\r\n\t\t\t\tHAVING \r\n\t\t\t\t\tmax(G.PERMISSION)>0\r\n\t\t\t\t{$strSqlOrder}\r\n\t\t\t\t";
     } else {
         $strSql = "\r\n\t\t\t\tSELECT\r\n\t\t\t\t\tC.TITLE CHANNEL_TITLE, \r\n\t\t\t\t\tV.ID, V.CHANNEL_ID, V.C_SORT, V.ACTIVE, V.COUNTER, V.TITLE, V.DESCRIPTION, V.DESCRIPTION_TYPE, V.IMAGE_ID, V.EVENT1, V.EVENT2, V.EVENT3, V.UNIQUE_TYPE, V.KEEP_IP_SEC, V.DELAY, V.DELAY_TYPE, V.TEMPLATE, V.RESULT_TEMPLATE, V.NOTIFY,\r\n\t\t\t\t\t" . $DB->DateToCharFunction("V.DATE_START") . "\t\tDATE_START,\r\n\t\t\t\t\t" . $DB->DateToCharFunction("V.DATE_END") . "\t\tDATE_END,\r\n\t\t\t\t\t2\t\t\t\t\t\t\t\t\t\t\t\tMAX_PERMISSION,\r\n\t\t\t\t\tcase \r\n\t\t\t\t\t\twhen V.ACTIVE='N' or getdate() not between V.DATE_START and V.DATE_END then 'red'\r\n\t\t\t\t\t\telse 'green'\r\n\t\t\t\t\tend\t\t\t\t\t\t\t\t\t\t\t\tLAMP\r\n\t\t\t\tFROM\r\n\t\t\t\t\tb_vote V\r\n\t\t\t\tINNER JOIN b_vote_channel C ON (C.ID = V.CHANNEL_ID and C.ACTIVE = 'Y')\r\n\t\t\t\tWHERE\r\n\t\t\t\t\t{$strSqlSearch}\r\n\t\t\t\tand V.ACTIVE = 'Y'\r\n\t\t\t\tand V.DATE_START<=getdate()\r\n\t\t\t\t{$where}\r\n\t\t\t\tGROUP BY\r\n\t\t\t\t\tC.ID, C.TITLE, \r\n\t\t\t\t\tV.ID, V.CHANNEL_ID, V.C_SORT, V.ACTIVE, V.COUNTER, V.TITLE, V.DESCRIPTION, V.DESCRIPTION_TYPE, V.IMAGE_ID, V.EVENT1, V.EVENT2, V.EVENT3, V.UNIQUE_TYPE, V.KEEP_IP_SEC, V.DELAY, V.DELAY_TYPE, V.TEMPLATE, V.RESULT_TEMPLATE, V.NOTIFY, \r\n\t\t\t\t\tV.DATE_START, V.DATE_END,\r\n\t\t\t\t\tC.C_SORT, C.ID\r\n\t\t\t\t{$strSqlOrder}\r\n\t\t\t\t";
     }
     $res = $DB->Query($strSql, false, $err_mess . __LINE__);
     return $res;
 }
Example #4
0
 function GetPublicList($arFilter = array(), $strSqlOrder = "ORDER BY C.C_SORT, C.ID, V.DATE_START desc")
 {
     global $DB, $USER;
     $err_mess = CVote::err_mess() . "<br>Function: GetPublicList<br>Line: ";
     $arSqlSearch = array();
     $strSqlSearch = "";
     $arFilter = is_array($arFilter) ? $arFilter : array();
     foreach ($arFilter as $key => $val) {
         if (empty($val) || is_string($val) && $val === "NOT_REF") {
             continue;
         }
         $key = strtoupper($key);
         switch ($key) {
             case "SITE":
                 $val = is_array($val) ? implode(" | ", $val) : $val;
                 $match = $arFilter[$key . "_EXACT_MATCH"] == "N" ? "Y" : "N";
                 $arSqlSearch[] = GetFilterQuery("CS.SITE_ID", $val, $match);
                 $left_join = "LEFT JOIN b_vote_channel_2_site CS ON (C.ID = CS.CHANNEL_ID)";
                 break;
             case "CHANNEL":
                 $match = $arFilter[$key . "_EXACT_MATCH"] == "N" ? "Y" : "N";
                 if (is_array($val)) {
                     $arr = array();
                     foreach ($val as $v) {
                         $v = trim($v);
                         if (strLen($v) > 0) {
                             $arr[] = GetFilterQuery("C.SYMBOLIC_NAME", $v, $match);
                         }
                     }
                     if (!empty($arr)) {
                         $arSqlSearch[] = "((" . implode(") OR (", $arr) . "))";
                     }
                 } else {
                     $arSqlSearch[] = GetFilterQuery("C.SYMBOLIC_NAME", $val, $match);
                 }
                 break;
             case "FIRST_SITE_ID":
             case "LID":
                 $match = $arFilter[$key . "_EXACT_MATCH"] == "N" ? "Y" : "N";
                 $arSqlSearch[] = GetFilterQuery("C.FIRST_SITE_ID", $val, $match);
                 break;
         }
     }
     $strSqlSearch = GetFilterSqlSearch($arSqlSearch);
     $is_admin = $USER->IsAdmin();
     $groups = $USER->GetGroups();
     $strSql = "\n\t\t\tSELECT C.TITLE CHANNEL_TITLE, V.*,\n\t\t\t\t" . $DB->DateToCharFunction("V.DATE_START") . "\tDATE_START,\n\t\t\t\t" . $DB->DateToCharFunction("V.DATE_END") . "\tDATE_END, \n\t\t\t\tV4.MAX_PERMISSION, V4.LAMP\n\t\t\tFROM (\n\t\t\t\tSELECT V.CHANNEL_ID, V.ID,\n\t\t\t\t\t" . ($is_admin ? "2" : "max(G.PERMISSION)") . " as MAX_PERMISSION, \n\t\t\t\t\tIF((C.VOTE_SINGLE = 'Y'), \n\t\t\t\t\t\t(IF(V.ID = VV.ACTIVE_VOTE_ID, 'green', 'red')), \n\t\t\t\t\t\t(IF(V.ACTIVE = 'Y' AND V.DATE_START <= NOW() AND NOW() <= V.DATE_END, 'green', 'red'))) LAMP \n\t\t\t\tFROM b_vote V\n\t\t\t\tINNER JOIN b_vote_channel C ON (C.ACTIVE = 'Y' AND C.HIDDEN = 'N' AND V.CHANNEL_ID = C.ID)\n\t\t\t\tLEFT JOIN (\n\t\t\t\t\tSELECT VVV.CHANNEL_ID, MAX(VVV.ID) AS ACTIVE_VOTE_ID\n\t\t\t\t\tFROM b_vote VVV, b_vote_channel CCC\n\t\t\t\t\tWHERE VVV.CHANNEL_ID = CCC.ID AND CCC.VOTE_SINGLE='Y' AND VVV.ACTIVE = 'Y' \n\t\t\t\t\t\tAND NOW() >= VVV.DATE_START AND VVV.DATE_END >= NOW()\n\t\t\t\t\tGROUP BY VVV.CHANNEL_ID) VV ON (VV.CHANNEL_ID = V.CHANNEL_ID)\n\t\t\t\tLEFT JOIN b_vote_channel_2_group G ON (G.CHANNEL_ID = C.ID and G.GROUP_ID in ({$groups}))\n\t\t\t\t{$left_join}\n\t\t\t\tWHERE\n\t\t\t\t\t{$strSqlSearch}\n\t\t\t\t\tAND V.ACTIVE = 'Y' AND V.DATE_START <= NOW()\n\t\t\t\tGROUP BY V.CHANNEL_ID, V.ID\n\t\t\t\t" . ($is_admin ? "" : "\n\t\t\t\tHAVING MAX_PERMISSION > 0") . "\n\t\t\t) V4\n\t\t\tINNER JOIN b_vote V ON (V4.ID = V.ID)\n\t\t\tINNER JOIN b_vote_channel C ON (V4.CHANNEL_ID = C.ID) \n\t\t\t" . $DB->ForSql($strSqlOrder);
     $res = $DB->Query($strSql, false, $err_mess . __LINE__);
     return $res;
 }