function ForumVote4User($UID, $VOTES, $bDelVote, &$strErrorMessage, &$strOKMessage) { global $USER; $arError = array(); $arNote = array(); $UID = IntVal($UID); $VOTES = IntVal($VOTES); $bDelVote = $bDelVote ? true : false; $CurrUserID = 0; if ($UID <= 0) { $arError[] = GetMessage("F_NO_VPERS"); } else { if (!$USER->IsAuthorized()) { $arError[] = GetMessage("FORUM_GV_ERROR_AUTH"); } else { $CurrUserID = IntVal($USER->GetParam("USER_ID")); if ($CurrUserID == $UID && !CForumUser::IsAdmin()) { $arError[] = GetMessage("FORUM_GV_OTHER"); } else { $arUserRank = CForumUser::GetUserRank($CurrUserID); if (IntVal($arUserRank["VOTES"]) <= 0 && !$bDelVote && !CForumUser::IsAdmin()) { $arError[] = GetMessage("FORUM_GV_ERROR_NO_VOTE"); } else { if (!CForumUser::IsAdmin() || $VOTES <= 0) { $VOTES = IntVal($arUserRank["VOTES"]); } if ($VOTES == 0) { $VOTES = 1; } // no ranks configured $arFields = array("POINTS" => $VOTES); $arUserPoints = CForumUserPoints::GetByID($CurrUserID, $UID); if ($arUserPoints) { if ($bDelVote || $VOTES <= 0) { if (CForumUserPoints::Delete($CurrUserID, $UID)) { $arNote[] = GetMessage("FORUM_GV_SUCCESS_UNVOTE"); } else { $arError[] = GetMessage("FORUM_GV_ERROR_VOTE"); } } else { if (IntVal($arUserPoints["POINTS"]) < IntVal($arUserRank["VOTES"]) || CForumUser::IsAdmin()) { if (CForumUserPoints::Update(IntVal($USER->GetParam("USER_ID")), $UID, $arFields)) { $arNote[] = GetMessage("FORUM_GV_SUCCESS_VOTE_UPD"); } else { $arError[] = GetMessage("FORUM_GV_ERROR_VOTE_UPD"); } } else { $arError[] = GetMessage("FORUM_GV_ALREADY_VOTE"); } } } else { if (!$bDelVote && $VOTES > 0) { $arFields["FROM_USER_ID"] = $USER->GetParam("USER_ID"); $arFields["TO_USER_ID"] = $UID; if (CForumUserPoints::Add($arFields)) { $arNote[] = GetMessage("FORUM_GV_SUCCESS_VOTE_ADD"); } else { $arError[] = GetMessage("FORUM_GV_ERROR_VOTE_ADD"); } } else { $arError[] = GetMessage("FORUM_GV_ERROR_A"); } } } } } } if (!empty($arError)) { $strErrorMessage .= implode(".\n", $arError) . ".\n"; } if (!empty($arNote)) { $strOKMessage .= implode(".\n", $arNote) . ".\n"; } if (empty($arError)) { return True; } else { return False; } }