function moderateComment($id, $action, $fullUser) { global $dbConnectionInfo; $toReturn = ""; $act = false; if ($action == "approved") { $act = true; } $cmt = new Comment($dbConnectionInfo, "", $fullUser); $return = $cmt->moderate($id, $action); $toReturn = $return['page']; if ($return['page'] != "" && $act && $return['oldState'] == 'new') { // notify users $user = new User($dbConnectionInfo); $usersToNotify = $user->getUsersToNotify($toReturn, $id); $cmtInfo = $cmt->getInfo($id); $productTranslate = defined("__PRODUCT_NAME__") ? __PRODUCT_NAME__ : $cmtInfo['product']; $template = new Template("./templates/newComment.html"); $confirmationMsg = $template->replace(array("page" => __BASE_URL__ . $toReturn . "#" . $id, "text" => $cmtInfo['text'], "user" => $cmtInfo['name'], "productName" => $productTranslate)); foreach ($usersToNotify as $key => $value) { $mail = new Mail(); $subject = "[" . $productTranslate . "] " . Utils::translate('newCommentApproved'); $subject .= " [" . $toReturn . "]"; $mail->Subject($subject); $mail->To($value); $mail->From(__EMAIL__); $mail->Body($confirmationMsg); $mail->Send(); //$toReturn = "\nSEND to ".$value."user email='".$userEmail."'"; } } return $toReturn; }
// insert comment $result = $comment->insert($info); if ($result['rows'] > 0) { if (isset($ses->{$fullUser})) { $user = $ses->{$fullUser}; $userEmail = $ses->{$fullUser}->email; $userName = $ses->{$fullUser}->userName; $name = $ses->{$fullUser}->name; } else { $user = new User($dbConnectionInfo); $userEmail = ""; $userName = "******"; $name = "noName"; } $moderators = $user->getModeratorsEmails(); $usersToNotify = $user->getUsersToNotify($info["page"], $result['id']); // notify moderators if (defined('__MODERATE__') && !__MODERATE__) { // unmoderated list notifyUsers($userEmail, $info["page"], $result['id'], $info["text"], $userName, $info['product'], $usersToNotify); notifyModerators($result['id'], $info["page"], $info["text"], $userName, $name, $info['product'], $moderators); } else { // moderated list if ($user->level != 'user') { // moderator or admin notifyUsers($userEmail, $info["page"], $result['id'], $info["text"], $userName, $info['product'], $usersToNotify); } else { // user notifyModerators($result['id'], $info["page"], $info["text"], $userName, $name, $info['product'], $moderators); } }