function LogIp($UserID) { if ($this->Context->Configuration['LOG_ALL_IPS']) { $s = $this->Context->ObjectFactory->NewContextObject($this->Context, 'SqlBuilder'); $s->SetMainTable('IpHistory', 'i'); $s->AddFieldNameValue('UserID', $UserID); $s->AddFieldNameValue('RemoteIp', GetRemoteIp(1)); $s->AddFieldNameValue('DateLogged', MysqlDateTime()); $this->Context->Database->Insert($s, $this->Name, 'LogIp', 'An error occurred while logging user data.'); } }
function SaveComment(&$Comment, $SkipValidation = 0) { // Set the user's default comment format to the most recently selected one if ($Comment->AuthUserID > 0 && $Comment->AuthUserID != $this->Context->Session->UserID) { // Unless the user is editing another user's comments, then do nothing } else { $FormatTypeUserID = $Comment->AuthUserID; if ($FormatTypeUserID == 0) { $FormatTypeUserID = $this->Context->Session->UserID; } $um = $this->Context->ObjectFactory->NewContextObject($this->Context, 'UserManager'); $um->SetDefaultFormatType($FormatTypeUserID, $Comment->FormatType); } // If not editing, and the posted comment count is less than the // user's current comment count, silently skip the posting and // redirect as if everything is normal. if (!$SkipValidation && $Comment->CommentID == 0 && $Comment->UserCommentCount < $this->Context->Session->User->CountComments) { // Silently fail to post the data // Need to get the user's last posted commentID in this discussion and direct them to it $s = $this->Context->ObjectFactory->NewContextObject($this->Context, 'SqlBuilder'); $s->SetMainTable('Comment', 'c'); $s->AddSelect('CommentID', 'c'); $s->AddWhere('c', 'AuthUserID', '', $this->Context->Session->UserID, '='); $s->AddWhere('c', 'DiscussionID', '', $Comment->DiscussionID, '='); $s->AddOrderBy('DateCreated', 'c', 'desc'); $s->AddLimit(0, 1); $LastCommentData = $this->Context->Database->Select($s, $this->Name, 'SaveComment', 'An error occurred while retrieving your last comment in this discussion.'); while ($Row = $this->Context->Database->GetRow($LastCommentData)) { $Comment->CommentID = ForceInt($Row['CommentID'], 0); } // Make sure we got it if ($Comment->CommentID == 0) { $this->Context->ErrorManager->AddError($this->Context, $this->Name, 'SaveComment', 'Your last comment in this discussion could not be found.'); } } else { // Validate the properties $SaveComment = $Comment; if (!$SkipValidation) { if (!$this->Context->Session->User->Permission('PERMISSION_ADD_COMMENTS')) { $this->Context->WarningCollector->Add($this->Context->GetDefinition('ErrPermissionAddComments')); } $this->ValidateComment($SaveComment); $this->ValidateWhisperUsername($SaveComment); } if ($this->Context->WarningCollector->Iif()) { $s = $this->Context->ObjectFactory->NewContextObject($this->Context, 'SqlBuilder'); // If creating a new object if ($SaveComment->CommentID == 0) { // Update the user info & check for spam if (!$SkipValidation) { $UserManager = $this->Context->ObjectFactory->NewContextObject($this->Context, 'UserManager'); $UserManager->UpdateUserCommentCount($this->Context->Session->UserID); } $this->DelegateParameters['Comment'] =& $SaveComment; // Format the values for db input $SaveComment->FormatPropertiesForDatabaseInput(); // Proceed with the save if there are no warnings if ($this->Context->WarningCollector->Count() == 0) { $this->CallDelegate('PreSaveNewComment'); $Comment = $SaveComment; $s->SetMainTable('Comment', 'm'); $s->AddFieldNameValue('Body', $Comment->Body); $s->AddFieldNameValue('FormatType', $Comment->FormatType); $s->AddFieldNameValue('RemoteIp', GetRemoteIp(1)); $s->AddFieldNameValue('DiscussionID', $Comment->DiscussionID); $s->AddFieldNameValue('AuthUserID', $this->Context->Session->UserID); $s->AddFieldNameValue('DateCreated', MysqlDateTime()); $s->AddFieldNameValue('WhisperUserID', $Comment->WhisperUserID); $Comment->CommentID = $this->Context->Database->Insert($s, $this->Name, 'SaveComment', 'An error occurred while creating a new discussion comment.'); $this->CallDelegate('PostSaveNewComment'); // If there were no errors, update the discussion count & time if ($Comment->WhisperUserID) { // Whisper-to table if ($Comment->WhisperUserID != $this->Context->Session->UserID) { // Only record the whisper to if the user is not whispering to him/herself - this is to make sure that the counts come out correctly when counting replies for a discussion $s->Clear(); $s->SetMainTable('DiscussionUserWhisperTo', 'tuwt'); $s->AddFieldNameValue('CountWhispers', $this->Context->DatabaseColumns['DiscussionUserWhisperTo']['CountWhispers'] . '+1', '0'); $s->AddFieldNameValue('DateLastActive', MysqlDateTime()); $s->AddFieldNameValue('LastUserID', $this->Context->Session->UserID); $s->AddWhere('tuwt', 'DiscussionID', '', $Comment->DiscussionID, '='); $s->AddWhere('tuwt', 'WhisperToUserID', '', $Comment->WhisperUserID, '='); if ($this->Context->Database->Update($s, $this->Name, 'SaveComment', "An error occurred while updating the discussion's comment summary.") <= 0) { // If no records were updated, then insert a new row to the table for this discussion/user whisper $s->Clear(); $s->SetMainTable('DiscussionUserWhisperTo', 'tuwt'); $s->AddFieldNameValue('CountWhispers', '1'); $s->AddFieldNameValue('DateLastActive', MysqlDateTime()); $s->AddFieldNameValue('DiscussionID', $Comment->DiscussionID); $s->AddFieldNameValue('WhisperToUserID', $Comment->WhisperUserID); $s->AddFieldNameValue('LastUserID', $this->Context->Session->UserID); $this->Context->Database->Insert($s, $this->Name, 'SaveComment', "An error occurred while updating the discussion's comment summary."); } } // Whisper-from table $s->Clear(); $s->SetMainTable('DiscussionUserWhisperFrom', 'tuwf'); $s->AddFieldNameValue('CountWhispers', $this->Context->DatabaseColumns['DiscussionUserWhisperFrom']['CountWhispers'] . '+1', '0'); $s->AddFieldNameValue('DateLastActive', MysqlDateTime()); $s->AddFieldNameValue('LastUserID', $this->Context->Session->UserID); $s->AddWhere('tuwf', 'DiscussionID', '', $Comment->DiscussionID, '='); $s->AddWhere('tuwf', 'WhisperFromUserID', '', $this->Context->Session->UserID, '='); if ($this->Context->Database->Update($s, $this->Name, 'SaveComment', "An error occurred while updating the discussion's comment summary.") <= 0) { // If no records were updated, then insert a new row to the table for this discussion/user whisper $s->Clear(); $s->SetMainTable('DiscussionUserWhisperFrom', 'tuwf'); $s->AddFieldNameValue('CountWhispers', '1'); $s->AddFieldNameValue('DateLastActive', MysqlDateTime()); $s->AddFieldNameValue('DiscussionID', $Comment->DiscussionID); $s->AddFieldNameValue('WhisperFromUserID', $this->Context->Session->UserID); $s->AddFieldNameValue('LastUserID', $this->Context->Session->UserID); $this->Context->Database->Insert($s, $this->Name, 'SaveComment', "An error occurred while updating the discussion's comment summary."); } // Update the discussion table $s->Clear(); $s->SetMainTable('Discussion', 't'); $s->AddFieldNameValue('DateLastWhisper', MysqlDateTime()); $s->AddFieldNameValue('WhisperToLastUserID', $Comment->WhisperUserID); $s->AddFieldNameValue('WhisperFromLastUserID', $this->Context->Session->UserID); $s->AddFieldNameValue('TotalWhisperCount', $this->Context->DatabaseColumns['Discussion']['TotalWhisperCount'] . '+1', 0); $s->AddWhere('t', 'DiscussionID', '', $Comment->DiscussionID, '='); $this->Context->Database->Update($s, $this->Name, 'SaveComment', "An error occurred while updating the discussion's whisper summary."); } else { // First update the counts & last user $s->Clear(); $s->SetMainTable('Discussion', 't'); $s->AddFieldNameValue('CountComments', $this->Context->DatabaseColumns['Discussion']['CountComments'] . '+1', '0'); $s->AddFieldNameValue('LastUserID', $this->Context->Session->UserID); $s->AddWhere('t', 'DiscussionID', '', $Comment->DiscussionID, '='); $this->Context->Database->Update($s, $this->Name, 'SaveComment', "An error occurred while updating the discussion's comment summary."); // Now only update the DateLastActive if the discussion isn't set to Sink $s->Clear(); $s->SetMainTable('Discussion', 't'); $s->AddFieldNameValue('DateLastActive', MysqlDateTime()); $s->AddWhere('t', 'DiscussionID', '', $Comment->DiscussionID, '='); $s->AddWhere('t', 'Sink', '', '1', '<>', 'and'); $this->Context->Database->Update($s, $this->Name, 'SaveComment', "An error occurred while updating the discussion's last active date."); } } } else { $Comment = $SaveComment; // Format the values for db input $Comment->FormatPropertiesForDatabaseInput(); // Get information about the comment being edited $s->SetMainTable('Comment', 'm'); $s->AddSelect(array('AuthUserID', 'WhisperUserID', 'DeleteUserID'), 'm'); $s->AddWhere('m', 'CommentID', '', $Comment->CommentID, '='); $CommentData = $this->Context->Database->Select($s, $this->Name, 'SaveComment', 'An error occurred while retrieving information about the comment.'); $WhisperToUserID = 0; $WhisperFromUserID = 0; while ($Row = $this->Context->Database->GetRow($CommentData)) { $WhisperToUserID = ForceInt($Row['WhisperUserID'], 0); $WhisperFromUserID = ForceInt($Row['AuthUserID'], 0); $DeleteUserID = ForceInt($Row['DeleteUserID'], 0); } if ($DeleteUserID == 0) { if ($WhisperToUserID > 0 && $Comment->WhisperUserID == 0) { // If the original comment was whispered and the new one isn't // 1. Update the whisper count for this discussion $this->UpdateWhisperCount($Comment->DiscussionID, $WhisperFromUserID, $WhisperToUserID, '-'); // 2. Update the comment count for this discussion $this->UpdateCommentCount($Comment->DiscussionID, '+'); } elseif ($WhisperToUserID == 0 && $Comment->WhisperUserID > 0) { // If the original comment was not whispered and the new one is // 1. Update the comment count for this discussion $this->UpdateCommentCount($Comment->DiscussionID, '-'); // 2. Update the whisper count for this discussion $this->UpdateWhisperCount($Comment->DiscussionID, $WhisperFromUserID, $Comment->WhisperUserID, '+'); } elseif ($WhisperToUserID > 0 && $Comment->WhisperUserID > 0 && $WhisperToUserID != $Comment->WhisperUserID) { // If the original comment was whispered to a different person // 1. Remove traces of the old whisper $this->UpdateWhisperCount($Comment->DiscussionID, $WhisperFromUserID, $WhisperToUserID, '-'); // 2. Update the whisper count for this new whisper $this->UpdateWhisperCount($Comment->DiscussionID, $WhisperFromUserID, $Comment->WhisperUserID, '+'); } else { // Otherwise, the counts do not need to be manipulated } } // Finally, update the comment $s->Clear(); $s->SetMainTable('Comment', 'm'); $s->AddFieldNameValue('WhisperUserID', $Comment->WhisperUserID); $s->AddFieldNameValue('Body', $Comment->Body); $s->AddFieldNameValue('FormatType', $Comment->FormatType); $s->AddFieldNameValue('RemoteIp', GetRemoteIp(1)); $s->AddFieldNameValue('EditUserID', $this->Context->Session->UserID); $s->AddFieldNameValue('DateEdited', MysqlDateTime()); $s->AddWhere('m', 'CommentID', '', $Comment->CommentID, '='); $this->Context->Database->Update($s, $this->Name, 'SaveComment', 'An error occurred while attempting to update the discussion comment.'); // Make sure that the discussion reflects this user's comment (if someone turned a non-whisper into a whisper or vice versa). $this->UpdateLastCommenter($Comment->DiscussionID); } } } return $this->Context->WarningCollector->Iif($Comment, false); }
function LogIp($UserID) { if ($this->Context->Configuration['LOG_ALL_IPS']) { $Query = "insert into LUM_IpHistory\n\t\t\t\t(UserID, RemoteIp, DateLogged)\n\t\t\t\tvalues ('" . $UserID . "', '" . GetRemoteIp(1) . "', '" . MysqlDateTime() . "')"; $this->Context->Database->Execute($Query, 'Authenticator', 'LogIp', 'An error occurred while logging your IP address.', false); // fail silently } }
function LogIp($UserID) { if ($this->Context->Configuration['LOG_ALL_IPS']) { $s = $this->Context->ObjectFactory->NewContextObject($this->Context, 'SqlBuilder'); $s->SetMainTable('IpHistory', 'i'); $s->AddFieldNameValue('UserID', $UserID); $s->AddFieldNameValue('RemoteIp', GetRemoteIp(1)); $s->AddFieldNameValue('DateLogged', MysqlDateTime()); $this->Context->Database->Insert($s, 'Authenticator', 'LogIp', 'An error occurred while logging your IP address.', false); // fail silently } }
function SaveComment(&$Comment, $SkipValidation = 0) { if (!$this->Context->Session->User->CanPostComment) { $this->Context->WarningCollector->Add($this->Context->GetDefinition("ErrPermissionAddComments")); } else { // If not editing, and the posted comment count is less than the // user's current comment count, silently skip the posting and // redirect as if everything is normal. if (!$SkipValidation && $Comment->CommentID == 0 && $Comment->UserCommentCount < $this->Context->Session->User->CountComments) { // Silently fail to post the data // Need to get the user's last posted commentID in this discussion and direct them to it $s = $this->Context->ObjectFactory->NewContextObject($this->Context, "SqlBuilder"); $s->SetMainTable("Comment", "c"); $s->AddSelect("CommentID", "c"); $s->AddWhere("AuthUserID", $this->Context->Session->UserID, "="); $s->AddWhere("DiscussionID", $Comment->DiscussionID, "="); $s->AddOrderBy("DateCreated", "c", "desc"); $s->AddLimit(0, 1); $LastCommentData = $this->Context->Database->Select($this->Context, $s, $this->Name, "SaveComment", "An error occurred while retrieving your last comment in this discussion."); while ($Row = $this->Context->Database->GetRow($LastCommentData)) { $Comment->CommentID = ForceInt($Row["CommentID"], 0); } // Make sure we got it if ($Comment->CommentID == 0) { $this->Context->ErrorManager->AddError($this->Context, $this->Name, "SaveComment", "Your last comment in this discussion could not be found."); } } else { // Validate the properties $SaveComment = $Comment; if (!$SkipValidation) { $this->ValidateComment($SaveComment); $this->ValidateWhisperUsername($SaveComment); } if ($this->Context->WarningCollector->Iif()) { $s = $this->Context->ObjectFactory->NewContextObject($this->Context, "SqlBuilder"); // If creating a new object if ($SaveComment->CommentID == 0) { // Update the user info & check for spam if (!$SkipValidation) { $UserManager = $this->Context->ObjectFactory->NewContextObject($this->Context, "UserManager"); $UserManager->UpdateUserCommentCount($this->Context->Session->UserID); } // Format the values for db input $SaveComment->FormatPropertiesForDatabaseInput(); // Proceed with the save if there are no warnings if ($this->Context->WarningCollector->Count() == 0) { // This SaveComment was put in because if a spam block went into effect, the user's text would then be display in the comment box in a database-saving format. $Comment = $SaveComment; $s->SetMainTable("Comment", "m"); $s->AddFieldNameValue("Body", $Comment->Body); $s->AddFieldNameValue("FormatType", $Comment->FormatType); $s->AddFieldNameValue("RemoteIp", GetRemoteIp(1)); $s->AddFieldNameValue("DiscussionID", $Comment->DiscussionID); $s->AddFieldNameValue("AuthUserID", $this->Context->Session->UserID); $s->AddFieldNameValue("DateCreated", MysqlDateTime()); $s->AddFieldNameValue("WhisperUserID", $Comment->WhisperUserID); $Comment->CommentID = $this->Context->Database->Insert($this->Context, $s, $this->Name, "SaveComment", "An error occurred while creating a new discussion comment."); // If there were no errors, update the discussion count & time if ($Comment->WhisperUserID) { // Whisper-to table if ($Comment->WhisperUserID != $this->Context->Session->UserID) { // Only record the whisper to if the user is not whispering to him/herself - this is to make sure that the counts come out correctly when counting replies for a discussion $s->Clear(); $s->SetMainTable("DiscussionUserWhisperTo", "tuwt"); $s->AddFieldNameValue("CountWhispers", "CountWhispers+1", "0"); $s->AddFieldNameValue("DateLastActive", MysqlDateTime()); $s->AddFieldNameValue("LastUserID", $this->Context->Session->UserID); $s->AddWhere("DiscussionID", $Comment->DiscussionID, "="); $s->AddWhere("WhisperToUserID", $Comment->WhisperUserID, "="); if ($this->Context->Database->Update($this->Context, $s, $this->Name, "SaveComment", "An error occurred while updating the discussion's comment summary.") <= 0) { // If no records were updated, then insert a new row to the table for this discussion/user whisper $s->Clear(); $s->SetMainTable("DiscussionUserWhisperTo", "tuwt"); $s->AddFieldNameValue("CountWhispers", "1"); $s->AddFieldNameValue("DateLastActive", MysqlDateTime()); $s->AddFieldNameValue("DiscussionID", $Comment->DiscussionID); $s->AddFieldNameValue("WhisperToUserID", $Comment->WhisperUserID); $s->AddFieldNameValue("LastUserID", $this->Context->Session->UserID); $this->Context->Database->Insert($this->Context, $s, $this->Name, "SaveComment", "An error occurred while updating the discussion's comment summary."); } } // Whisper-from table $s->Clear(); $s->SetMainTable("DiscussionUserWhisperFrom", "tuwf"); $s->AddFieldNameValue("CountWhispers", "CountWhispers+1", "0"); $s->AddFieldNameValue("DateLastActive", MysqlDateTime()); $s->AddFieldNameValue("LastUserID", $this->Context->Session->UserID); $s->AddWhere("DiscussionID", $Comment->DiscussionID, "="); $s->AddWhere("WhisperFromUserID", $this->Context->Session->UserID, "="); if ($this->Context->Database->Update($this->Context, $s, $this->Name, "SaveComment", "An error occurred while updating the discussion's comment summary.") <= 0) { // If no records were updated, then insert a new row to the table for this discussion/user whisper $s->Clear(); $s->SetMainTable("DiscussionUserWhisperFrom", "tuwf"); $s->AddFieldNameValue("CountWhispers", "1"); $s->AddFieldNameValue("DateLastActive", MysqlDateTime()); $s->AddFieldNameValue("DiscussionID", $Comment->DiscussionID); $s->AddFieldNameValue("WhisperFromUserID", $this->Context->Session->UserID); $s->AddFieldNameValue("LastUserID", $this->Context->Session->UserID); $this->Context->Database->Insert($this->Context, $s, $this->Name, "SaveComment", "An error occurred while updating the discussion's comment summary."); } // Update the discussion table $s->Clear(); $s->SetMainTable("Discussion", "t"); $s->AddFieldNameValue("DateLastWhisper", MysqlDateTime()); $s->AddFieldNameValue("WhisperToLastUserID", $Comment->WhisperUserID); $s->AddFieldNameValue("WhisperFromLastUserID", $this->Context->Session->UserID); $s->AddFieldNameValue("TotalWhisperCount", "TotalWhisperCount+1", 0); $s->AddWhere("DiscussionID", $Comment->DiscussionID, "="); $this->Context->Database->Update($this->Context, $s, $this->Name, "SaveComment", "An error occurred while updating the discussion's whisper summary."); } else { $s->Clear(); $s->SetMainTable("Discussion", "t"); $s->AddFieldNameValue("CountComments", "CountComments+1", "0"); $s->AddFieldNameValue("DateLastActive", MysqlDateTime()); $s->AddFieldNameValue("LastUserID", $this->Context->Session->UserID); $s->AddWhere("DiscussionID", $Comment->DiscussionID, "="); $this->Context->Database->Update($this->Context, $s, $this->Name, "SaveComment", "An error occurred while updating the discussion's comment summary."); } } } else { // Format the values for db input $Comment->FormatPropertiesForDatabaseInput(); // Get information about the comment being edited $s->SetMainTable("Comment", "m"); $s->AddSelect(array("AuthUserID", "WhisperUserID"), "m"); $s->AddWhere("CommentID", $Comment->CommentID, "="); $CommentData = $this->Context->Database->Select($this->Context, $s, $this->Name, "SaveComment", "An error occurred while retrieving information about the comment."); $WhisperToUserID = 0; $WhisperFromUserID = 0; while ($Row = $this->Context->Database->GetRow($CommentData)) { $WhisperToUserID = ForceInt($Row["WhisperUserID"], 0); $WhisperFromUserID = ForceInt($Row["AuthUserID"], 0); } if ($WhisperToUserID > 0 && $Comment->WhisperUserID == 0) { // If the original comment was whispered and the new one isn't // 1. Update the whisper count for this discussion $this->UpdateWhisperCount($Comment->DiscussionID, $WhisperFromUserID, $WhisperToUserID, "-"); // 2. Update the comment count for this discussion $this->UpdateCommentCount($Comment->DiscussionID, "+"); } elseif ($WhisperToUserID == 0 && $Comment->WhisperUserID > 0) { // If the original comment was not whispered and the new one is // 1. Update the comment count for this discussion $this->UpdateCommentCount($Comment->DiscussionID, "-"); // 2. Update the whisper count for this discussion $this->UpdateWhisperCount($Comment->DiscussionID, $WhisperFromUserID, $Comment->WhisperUserID, "+"); } else { // Otherwise, the counts do not need to be manipulated } // Finally, update the comment $s->Clear(); $s->SetMainTable("Comment", "m"); $s->AddFieldNameValue("WhisperUserID", $Comment->WhisperUserID); $s->AddFieldNameValue("Body", $Comment->Body); $s->AddFieldNameValue("FormatType", $Comment->FormatType); $s->AddFieldNameValue("RemoteIp", GetRemoteIp(1)); $s->AddFieldNameValue("EditUserID", $this->Context->Session->UserID); $s->AddFieldNameValue("DateEdited", MysqlDateTime()); $s->AddWhere("CommentID", $Comment->CommentID, "="); $this->Context->Database->Update($this->Context, $s, $this->Name, "SaveComment", "An error occurred while attempting to update the discussion comment."); } } } } return $this->Context->WarningCollector->Iif($Comment, false); }
function UpdateGuestLastActive() { $s = $this->Context->ObjectFactory->NewContextObject($this->Context, "SqlBuilder"); if (isset($_COOKIE['IpHistoryID'])) { $s->Clear(); $s->SetMainTable("IpHistory", "i"); $s->AddFieldNameValue("DateLogged", "now()", 0); $s->AddWhere("i", "IpHistoryID", "", $_COOKIE['IpHistoryID'], "="); $result = $this->Context->Database->Update($s, $this->Name, "UpdateGuestLastActive", "An error occurred while logging user data."); } else { $my_ip = GetRemoteIp(1); $ip_letter = $this->GetNextIpLetter($my_ip); $s->Clear(); $s->SetMainTable("IpHistory", "i"); $s->AddFieldNameValue("UserID", 0); $s->AddFieldNameValue("RemoteIp", $my_ip . $ip_letter); $s->AddFieldNameValue("DateLogged", "Now()", 0); $this->Context->Database->Insert($s, $this->Name, "UpdateGuestLastActive", "An error occurred while logging user data."); setcookie('IpHistoryID', $this->GetIpHistoryID($my_ip . $ip_letter)); } }
function SaveComment(&$Comment, $SkipValidation = 0) { if (!$this->Context->Session->User->CanPostComment) { $this->Context->WarningCollector->Add($this->Context->GetDefinition("ErrPermissionAddComments")); } else { // If not editing, and the posted comment count is less than the // user's current comment count, silently skip the posting and // redirect as if everything is normal. if (!$SkipValidation && $Comment->CommentID == 0 && $Comment->UserCommentCount < $this->Context->Session->User->CountComments) { // Silently fail to post the data // Need to get the user's last posted commentID in this discussion and direct them to it $s = $this->Context->ObjectFactory->NewContextObject($this->Context, "SqlBuilder"); $s->SetMainTable("Comment", "c"); $s->AddSelect("CommentID", "c"); $s->AddWhere("AuthUserID", $this->Context->Session->UserID, "="); $s->AddWhere("DiscussionID", $Comment->DiscussionID, "="); $s->AddOrderBy("DateCreated", "c", "desc"); $s->AddLimit(0, 1); $LastCommentData = $this->Context->Database->Select($this->Context, $s, $this->Name, "SaveComment", "An error occurred while retrieving your last comment in this discussion."); while ($Row = $this->Context->Database->GetRow($LastCommentData)) { $Comment->CommentID = ForceInt($Row["CommentID"], 0); } // Make sure we got it if ($Comment->CommentID == 0) { $this->Context->ErrorManager->AddError($this->Context, $this->Name, "SaveComment", "Your last comment in this discussion could not be found."); } } else { // Validate the properties $SaveComment = $Comment; if (!$SkipValidation) { $this->ValidateComment($SaveComment); } if ($this->Context->WarningCollector->Iif()) { $s = $this->Context->ObjectFactory->NewContextObject($this->Context, "SqlBuilder"); // If creating a new object if ($SaveComment->CommentID == 0) { // Update the user info & check for spam if (!$SkipValidation) { $UserManager = $this->Context->ObjectFactory->NewContextObject($this->Context, "UserManager"); $UserManager->UpdateUserCommentCount($this->Context->Session->UserID); $UserManager->RemoveBookmark($this->Context->Session->UserID, $Comment->DiscussionID); $UserManager->AddBookmark($this->Context->Session->UserID, $Comment->DiscussionID); } // Format the values for db input $SaveComment->FormatPropertiesForDatabaseInput(); // Proceed with the save if there are no warnings if ($this->Context->WarningCollector->Count() == 0) { $Comment = $SaveComment; $s->SetMainTable("Comment", "m"); $s->AddFieldNameValue("Body", $Comment->Body); $s->AddFieldNameValue("FormatType", $Comment->FormatType); $s->AddFieldNameValue("RemoteIp", GetRemoteIp(1)); $s->AddFieldNameValue("DiscussionID", $Comment->DiscussionID); $s->AddFieldNameValue("AuthUserID", $this->Context->Session->UserID); $s->AddFieldNameValue("DateCreated", MysqlDateTime()); $Comment->CommentID = $this->Context->Database->Insert($this->Context, $s, $this->Name, "SaveComment", "An error occurred while creating a new discussion comment."); $s->Clear(); $s->SetMainTable("Discussion", "t"); $s->AddFieldNameValue("CountComments", "CountComments+1", "0"); $s->AddFieldNameValue("DateLastActive", MysqlDateTime()); $s->AddFieldNameValue("LastUserID", $this->Context->Session->UserID); $s->AddWhere("DiscussionID", $Comment->DiscussionID, "="); $this->Context->Database->Update($this->Context, $s, $this->Name, "SaveComment", "An error occurred while updating the discussion's comment summary."); } } else { // Format the values for db input $Comment->FormatPropertiesForDatabaseInput(); // Finally, update the comment $s->Clear(); $s->SetMainTable("Comment", "m"); $s->AddFieldNameValue("Body", $Comment->Body); $s->AddFieldNameValue("FormatType", $Comment->FormatType); $s->AddFieldNameValue("RemoteIp", GetRemoteIp(1)); $s->AddFieldNameValue("EditUserID", $this->Context->Session->UserID); $s->AddFieldNameValue("DateEdited", MysqlDateTime()); $s->AddWhere("CommentID", $Comment->CommentID, "="); $this->Context->Database->Update($this->Context, $s, $this->Name, "SaveComment", "An error occurred while attempting to update the discussion comment."); } } } } $n = $this->Context->ObjectFactory->NewContextObject($this->Context, "Notify"); $n->NotifyComment($Comment->CommentID, $this); return $this->Context->WarningCollector->Iif($Comment, false); }
$s->AddFieldNameValue("StyleID", 1); $s->AddFieldNameValue("UtilizeEmail", 0); $s->AddFieldNameValue("RemoteIP", GetRemoteIp(1)); if (!@mysql_query($s->GetInsert(), $Connection)) { $WarningCollector->Add("Something bad happened when we were trying to create your administrative user account. Mysql said: " . mysql_error($Connection)); } else { // Now insert the role history assignment $NewUserID = mysql_insert_id($Connection); $s->Clear(); $s->SetMainTable("UserRoleHistory", "h"); $s->AddFieldNameValue("UserID", $NewUserID); $s->AddFieldNameValue("RoleID", 6); $s->AddFieldNameValue("Date", MysqlDateTime()); $s->AddFieldNameValue("AdminUserID", $NewUserID); $s->AddFieldNameValue("Notes", "Initial administrative account created"); $s->AddFieldNameValue("RemoteIp", GetRemoteIp(1)); // Fail silently on this one @mysql_query($s->GetInsert(), $Connection); } } // Close the database connection @mysql_close($Connection); // Save the application constants if ($WarningCollector->Count() == 0) { $ConstantsFile = $WorkingDirectory . "appg/settings.php"; $ConstantManager = new ConstantManager($Context); $ConstantManager->DefineConstantsFromFile($ConstantsFile); // Set the constants to their new values $ConstantManager->SetConstant("agSUPPORT_EMAIL", $SupportEmail); $ConstantManager->SetConstant("agSUPPORT_NAME", $SupportName); $ConstantManager->SetConstant("agAPPLICATION_TITLE", $ApplicationTitle);
function UpdateLastVisit($UserID, $VerificationKey) { $s = $this->Context->ObjectFactory->NewContextObject($this->Context, "SqlBuilder"); $s->SetMainTable("User", "u"); $s->AddFieldNameValue("DateLastActive", MysqlDateTime()); $s->AddFieldNameValue("VerificationKey", $VerificationKey); $s->AddFieldNameValue("CountVisit", "CountVisit+1", 0); $s->AddFieldNameValue("RemoteIp", GetRemoteIp(1)); $s->AddWhere("UserID", $UserID, "="); $this->Context->Database->Update($this->Context, $s, $this->Name, "UpdateLastVisit", "An error occurred while updating your account."); $this->LogIp($UserID); }
$s->AddFieldNameValue('StyleID', 1); $s->AddFieldNameValue('UtilizeEmail', 0); $s->AddFieldNameValue('RemoteIp', GetRemoteIp(1)); if (!@mysql_query($s->GetInsert(), $Connection)) { $Context->WarningCollector->Add('Something bad happened when we were trying to create your administrative user account. Mysql said: ' . mysql_error($Connection)); } else { // Now insert the role history assignment $NewUserID = mysql_insert_id($Connection); $s->Clear(); $s->SetMainTable('UserRoleHistory', 'h'); $s->AddFieldNameValue('UserID', $NewUserID); $s->AddFieldNameValue('RoleID', 4); $s->AddFieldNameValue('Date', MysqlDateTime()); $s->AddFieldNameValue('AdminUserID', $NewUserID); $s->AddFieldNameValue('Notes', 'Initial administrative account created'); $s->AddFieldNameValue('RemoteIp', GetRemoteIp(1)); // Fail silently on this one @mysql_query($s->GetInsert(), $Connection); } // Create the default Vanilla style entry in the db $s->Clear(); $s->SetMainTable('Style', 's'); $s->AddFieldNameValue('Name', 'Vanilla'); $s->AddFieldNameValue('Url', $ThemeDirectory . 'vanilla modern/styles/default/'); @mysql_query($s->GetInsert(), $Connection); } // Close the database connection @mysql_close($Connection); // Save the application constants if ($Context->WarningCollector->Count() == 0) { $SettingsManager->DefineSetting('SUPPORT_EMAIL', $SupportEmail, 1);