示例#1
0
 public static function Update($ID, $arFields, $strUploadDir = false)
 {
     global $DB;
     $arBinds = array();
     $err_mess = CAllVoteQuestion::err_mess() . "<br>Function: Update<br>Line: ";
     $strUploadDir = $strUploadDir === false ? "vote" : $strUploadDir;
     $ID = intVal($ID);
     if ($ID <= 0 || !CVoteQuestion::CheckFields("UPDATE", $arFields, $ID)) {
         return false;
     }
     /***************** Event onBeforeVoteQuestionUpdate ****************/
     foreach (GetModuleEvents("vote", "onBeforeVoteQuestionUpdate", true) as $arEvent) {
         if (ExecuteModuleEventEx($arEvent, array(&$ID, &$arFields)) === false) {
             return false;
         }
     }
     /***************** /Event ******************************************/
     if (empty($arFields)) {
         return false;
     }
     if (array_key_exists("IMAGE_ID", $arFields) && is_array($arFields["IMAGE_ID"]) && (!array_key_exists("MODULE_ID", $arFields["IMAGE_ID"]) || strlen($arFields["IMAGE_ID"]["MODULE_ID"]) <= 0)) {
         $arFields["IMAGE_ID"]["MODULE_ID"] = "vote";
     }
     CFile::SaveForDB($arFields, "IMAGE_ID", $strUploadDir);
     $arFields["~TIMESTAMP_X"] = $DB->GetNowFunction();
     $strUpdate = $DB->PrepareUpdate("b_vote_question", $arFields);
     if (is_set($arFields, "QUESTION")) {
         $arBinds["QUESTION"] = $arFields["QUESTION"];
     }
     if (!empty($strUpdate)) {
         $DB->QueryBind("UPDATE b_vote_question SET " . $strUpdate . " WHERE ID=" . $ID, $arBinds, false, $err_mess);
     }
     unset($GLOBALS["VOTE_CACHE"]["QUESTION"][$ID]);
     /***************** Event onAfterVoteQuestionUpdate *****************/
     foreach (GetModuleEvents("vote", "onAfterVoteQuestionUpdate", true) as $arEvent) {
         ExecuteModuleEventEx($arEvent, array($ID, $arFields));
     }
     /***************** /Event ******************************************/
     return $ID;
 }