diff --git a/includes/ajaxHandler/comment.class.php b/includes/ajaxHandler/comment.class.php index 35c22dd1..941eb599 100644 --- a/includes/ajaxHandler/comment.class.php +++ b/includes/ajaxHandler/comment.class.php @@ -255,22 +255,15 @@ class AjaxComment extends AjaxHandler else $ok = DB::Aowow()->query('UPDATE ?_comments SET flags = flags & ~0x4 WHERE id = ?d', $this->_post['id'][0]); } + else if (DB::Aowow()->selectCell('SELECT 1 FROM ?_reports WHERE `mode` = ?d AND `reason`= ?d AND `subject` = ?d AND `userId` = ?d', 1, 17, $this->_post['id'][0], User::$id)) + return 'You\'ve already reported this.'; // ct_resp_error7 else if (User::$id && !$this->_post['reason'] || mb_strlen($this->_post['reason']) < self::REPLY_LENGTH_MIN) return 'Your message is too short.'; - else if (User::$id) // only report as outdated - { - $ok = DB::Aowow()->query( - 'INSERT INTO ?_reports (userId, mode, reason, subject, ip, description, userAgent, appName) VALUES (?d, 1, 17, ?d, ?, "", ?, ?)', - User::$id, - $this->_post['id'][0], - User::$ip, - $_SERVER['HTTP_USER_AGENT'], - get_browser(null, true)['browser'] - ); - } + else if (User::$id) // only report as outdated + $ok = Util::createReport(1, 17, $this->_post['id'][0], '[Outdated Comment] '.$this->_post['reason']); - if ($ok) // this one is very special; as in: completely retarded - return 'ok'; // the script expects the actual characters 'ok' not some string like "ok" + if ($ok) // this one is very special; as in: completely retarded + return 'ok'; // the script expects the actual characters 'ok' not some string like "ok" return Lang::main('genericError'); } @@ -342,14 +335,7 @@ class AjaxComment extends AjaxHandler if (!User::$id || !$this->_post['id']) return; - DB::Aowow()->query( - 'INSERT INTO ?_reports (userId, mode, reason, subject, ip, description, userAgent, appName) VALUES (?d, 1, 19, ?d, ?, "", ?, ?)', - User::$id, - $this->_post['id'][0], - User::$ip, - $_SERVER['HTTP_USER_AGENT'], - get_browser(null, true)['browser'] - ); + Util::createReport(1, 19, $this->_post['id'][0], '[General Reply Report]'); } protected function handleReplyUpvote() diff --git a/includes/ajaxHandler/contactus.class.php b/includes/ajaxHandler/contactus.class.php index 1a2a17d6..2da7fd57 100644 --- a/includes/ajaxHandler/contactus.class.php +++ b/includes/ajaxHandler/contactus.class.php @@ -41,6 +41,7 @@ class AjaxContactus extends AjaxHandler $app = $this->_post['appname']; $url = $this->_post['page']; $desc = $this->_post['desc']; + $subj = $this->_post['id']; $contexts = array( [1, 2, 3, 4, 5, 6, 7, 8], @@ -69,30 +70,10 @@ class AjaxContactus extends AjaxHandler // check already reported $field = User::$id ? 'userId' : 'ip'; - if (DB::Aowow()->selectCell('SELECT 1 FROM ?_reports WHERE `mode` = ?d AND `reason`= ?d AND `subject` = ?d AND ?# = ?', $mode, $rsn, $this->_post['id'], $field, User::$id ?: User::$ip)) + if (DB::Aowow()->selectCell('SELECT 1 FROM ?_reports WHERE `mode` = ?d AND `reason`= ?d AND `subject` = ?d AND ?# = ?', $mode, $rsn, $subj, $field, User::$id ?: User::$ip)) return 7; - $update = array( - 'userId' => User::$id, - 'mode' => $mode, - 'reason' => $rsn, - 'ip' => User::$ip, - 'description' => $desc, - 'userAgent' => $ua, - 'appName' => $app, - 'url' => $url - ); - - if ($_ = $this->_post['id']) - $update['subject'] = $_; - - if ($_ = $this->_post['relatedurl']) - $update['relatedurl'] = $_; - - if ($_ = $this->_post['email']) - $update['email'] = $_; - - if (DB::Aowow()->query('INSERT INTO ?_reports (?#) VALUES (?a)', array_keys($update), array_values($update))) + if (Util::createReport($mode, $rsn, $subj, $desc, $ua, $app, $url, $this->_post['relatedurl'], $this->_post['email'])) return 0; return 'save to db unsuccessful'; diff --git a/includes/utilities.php b/includes/utilities.php index 5e87ac55..bfcef81e 100644 --- a/includes/utilities.php +++ b/includes/utilities.php @@ -1419,6 +1419,32 @@ class Util round($offHand['gearscore'] * $oh) ); } + + static function createReport($mode, $reason, $subject, $desc, $userAgent = null, $appName = null, $url = null, $relUrl = null, $email = null) + { + $update = array( + 'userId' => User::$id, + 'createDate' => time(), + 'mode' => $mode, + 'reason' => $reason, + 'subject' => $subject, + 'ip' => User::$ip, + 'description' => $desc, + 'userAgent' => $userAgent ?: $_SERVER['HTTP_USER_AGENT'], + 'appName' => $appName ?: (get_browser(null, true)['browser'] ?: '') + ); + + if ($url) + $update['url'] = $url; + + if ($relUrl) + $update['relatedurl'] = $relUrl; + + if ($email) + $update['email'] = $email; + + return DB::Aowow()->query('INSERT INTO ?_reports (?#) VALUES (?a)', array_keys($update), array_values($update)); + } } ?> diff --git a/setup/db_structure.sql b/setup/db_structure.sql index 6cede6b5..8168ae51 100644 --- a/setup/db_structure.sql +++ b/setup/db_structure.sql @@ -2170,6 +2170,7 @@ CREATE TABLE `aowow_reports` ( `userId` mediumint(8) unsigned NOT NULL, `assigned` mediumint(8) unsigned NOT NULL DEFAULT 0, `status` tinyint(3) unsigned NOT NULL DEFAULT 0 COMMENT '0:new; 1:solved; 2:rejected', + `createDate` int(10) unsigned NOT NULL, `mode` tinyint(3) unsigned NOT NULL, `reason` tinyint(3) unsigned NOT NULL, `subject` mediumint(9) NOT NULL DEFAULT 0, @@ -3090,7 +3091,7 @@ UNLOCK TABLES; LOCK TABLES `aowow_dbversion` WRITE; /*!40000 ALTER TABLE `aowow_dbversion` DISABLE KEYS */; -INSERT INTO `aowow_dbversion` VALUES (1527333496,0,NULL,NULL); +INSERT INTO `aowow_dbversion` VALUES (1527343033,0,NULL,NULL); /*!40000 ALTER TABLE `aowow_dbversion` ENABLE KEYS */; UNLOCK TABLES; diff --git a/setup/updates/1527343032_01.sql b/setup/updates/1527343032_01.sql new file mode 100644 index 00000000..3bd7bb82 --- /dev/null +++ b/setup/updates/1527343032_01.sql @@ -0,0 +1,2 @@ +ALTER TABLE `aowow_reports` + ADD COLUMN `createDate` INT UNSIGNED NOT NULL AFTER `status`;