예제 #1
0
 /**
  * @return Bengine_Admin_Controller_Globalmail
  */
 protected function send()
 {
     $subject = Str::validateXHTML($this->getParam("subject"));
     $message = richtext(nl2br($this->getParam("message")));
     if (Str::length($message) < 10) {
         Core::getTPL()->assign("messageError", Logger::getMessageField("MESSAGE_TOO_SHORT"));
         $error = true;
     }
     if (Str::length($subject) == 0) {
         Core::getTPL()->assign("subjectError", Logger::getMessageField("SUBJECT_TOO_SHORT"));
         $error = true;
     }
     if (!empty($error)) {
         return $this;
     }
     $sql = "INSERT INTO `" . PREFIX . "message` (`mode`, `time`, `sender`, `receiver`, `subject`, `message`, `read`) SELECT ?, ?, NULL, " . PREFIX . "user.userid, ?, ?, ? FROM " . PREFIX . "user";
     Core::getDB()->query($sql, array(1, TIME, $subject, $message, 0));
     return $this;
 }
예제 #2
0
 /**
  * Allows the user to write a global mail to all alliance member.
  *
  * @param string $reply
  * @return Bengine_Game_Controller_Alliance
  */
 protected function globalMailAction($reply)
 {
     $result = Core::getQuery()->select("user2ally u2a", array("a.founder", "ar.CAN_WRITE_GLOBAL_MAILS"), "LEFT JOIN " . PREFIX . "alliance a ON (a.aid = u2a.aid) LEFT JOIN " . PREFIX . "allyrank ar ON (ar.rankid = u2a.rank)", Core::getDB()->quoteInto("u2a.userid = ?", Core::getUser()->get("userid")));
     if ($row = $result->fetchRow()) {
         $result->closeCursor();
         if ($row["CAN_WRITE_GLOBAL_MAILS"] || $row["founder"] == Core::getUser()->get("userid")) {
             Core::getLanguage()->load("Message");
             if ($this->isPost()) {
                 $message = richtext($this->getParam("message"));
                 $length = Str::length(strip_tags($message));
                 $subject = Str::validateXHTML(trim($this->getParam("subject")));
                 $receiver = $this->getParam("receiver");
                 if ($length > 2 && $length <= Core::getOptions()->get("MAX_PM_LENGTH") && Str::length($subject) > 0 && Str::length($subject) < 101) {
                     Hook::event("SendGlobalMail", array($subject, &$message));
                     if ($receiver == "foo") {
                         $where = Core::getDB()->quoteInto("aid = ?", $this->aid);
                     } else {
                         $where = Core::getDB()->quoteInto("rank = ? AND aid = ?", array($receiver, $this->aid));
                     }
                     $_result = Core::getQuery()->select("user2ally", "userid", "", $where);
                     foreach ($_result->fetchAll() as $_row) {
                         Core::getQuery()->insert("message", array("mode" => 6, "time" => TIME, "sender" => Core::getUser()->get("userid"), "receiver" => $_row["userid"], "message" => $message, "subject" => $subject, "read" => $_row["userid"] == Core::getUser()->get("userid") ? 1 : 0));
                     }
                     $_result->closeCursor();
                     Logger::addMessage("SENT_SUCCESSFUL", "success");
                 } else {
                     if ($length < 3) {
                         Core::getTPL()->assign("messageError", Logger::getMessageField("MESSAGE_TOO_SHORT"));
                     }
                     if ($length > Core::getOptions()->get("MAX_PM_LENGTH")) {
                         Core::getTPL()->assign("messageError", Logger::getMessageField("MESSAGE_TOO_LONG"));
                     }
                     if (Str::length($subject) == 0) {
                         Core::getTPL()->assign("subjectError", Logger::getMessageField("SUBJECT_TOO_SHORT"));
                     }
                     if (Str::length($subject) > 100) {
                         Core::getTPL()->assign("subjectError", Logger::getMessageField("SUBJECT_TOO_LONG"));
                     }
                     Core::getTPL()->assign("subject", $this->getParam("subject"))->assign("message", $this->getParam("message"));
                 }
             } else {
                 if ($reply) {
                     $reply = preg_replace("#((RE|FW):\\s)+#is", "\\1", $reply);
                     Core::getTPL()->assign("subject", $reply);
                 }
             }
             $ranks = Core::getQuery()->select("allyrank", array("rankid", "name"), "", Core::getDB()->quoteInto("aid = ?", $this->aid));
             Core::getTPL()->assign("maxpmlength", fNumber(Core::getOptions()->get("MAX_PM_LENGTH")));
             Core::getTPL()->addLoop("ranks", $ranks);
         } else {
             Logger::dieMessage("MISSING_RIGHTS_FOR_GLOBAL_MAIL", "warning");
         }
     } else {
         Logger::dieMessage("MISSING_RIGHTS_FOR_GLOBAL_MAIL", "warning");
     }
     return $this;
 }
예제 #3
0
 /**
  * Executes an invitation.
  *
  * @param integer $eventid
  * @param string $name
  * @param string $username
  *
  * @return Bengine_Game_Controller_Mission
  */
 protected function invite($eventid, $name, $username)
 {
     $this->noAction = true;
     $where = Core::getDB()->quoteInto("(mode = ? OR mode = ?) AND user = ? AND eventid = ?", array(10, 12, Core::getUser()->get("userid"), $eventid));
     $result = Core::getQuery()->select("events", "time", "", $where);
     if ($row = $result->fetchRow()) {
         $result->closeCursor();
         $error = "";
         $time = $row["time"];
         $result = Core::getQuery()->select("user u", array("u.userid", "u2a.aid"), "LEFT JOIN " . PREFIX . "user2ally u2a ON (u2a.userid = u.userid)", Core::getDB()->quoteInto("u.username = ?", $username));
         $row = $result->fetchRow();
         $userid = $row["userid"];
         $aid = $row["aid"];
         $Relation = new Bengine_Game_User_Relation(Core::getUser()->get("userid"), Core::getUser()->get("aid"));
         if (!$Relation->hasRelation($userid, $aid)) {
             $error[] = "UNABLE_TO_INVITE_USER";
         }
         unset($Relation);
         if (Str::length($name) > 0 && Str::length($name) <= 128) {
             $name = Str::validateXHTML($name);
             Core::getQuery()->update("attack_formation", array("name" => $name), "eventid = ?", array($eventid));
         } else {
             $error[] = "ENTER_FORMATION_NAME";
         }
         if (empty($error)) {
             Core::getQuery()->insert("formation_invitation", array("eventid" => $eventid, "userid" => $userid));
         } else {
             foreach ($error as $_error) {
                 Logger::addMessage($_error);
             }
         }
     }
     $this->formation($eventid);
     return $this;
 }
예제 #4
0
 /**
  * Sends a message.
  *
  * @param string $receiver	Receiver name
  * @param string $subject	Subject
  * @param string $message	Message
  *
  * @return Bengine_Game_Controller_MSG
  */
 protected function sendMessage($receiver, $subject, $message)
 {
     $this->checkForSpam();
     $receiver = trim($receiver);
     $subject = trim($subject);
     $message = richText($message);
     $messageLength = Str::length(strip_tags($message));
     if ($messageLength >= 3 && $messageLength <= Core::getOptions()->get("MAX_PM_LENGTH") && Str::length($subject) > 0 && Str::length($subject) < 101) {
         $result = Core::getQuery()->select("user", "userid", "", Core::getDB()->quoteInto("username = ?", $receiver));
         if ($row = $result->fetchRow()) {
             $result->closeCursor();
             if ($row["userid"] != Core::getUser()->get("userid")) {
                 $subject = preg_replace("#((RE|FW):\\s)+#is", "\\1", $subject);
                 // Remove excessive reply or forward notes
                 Hook::event("SendPrivateMessage", array(&$row, $receiver, &$subject, &$message));
                 Core::getQuery()->insert("message", array("mode" => 1, "time" => TIME, "sender" => Core::getUser()->get("userid"), "receiver" => $row["userid"], "subject" => Str::validateXHTML($subject), "message" => $message, "read" => 0));
                 Core::getQuery()->insert("message", array("mode" => 2, "time" => TIME, "sender" => $row["userid"], "receiver" => Core::getUser()->get("userid"), "subject" => Str::validateXHTML($subject), "message" => $message, "read" => 1));
                 $msgid = Core::getDB()->lastInsertId();
                 if ($msgid > 10000000) {
                     $TableCleaner = new Recipe_Maintenance_TableCleaner("message", "msgid");
                     $TableCleaner->clean();
                 }
                 Logger::addMessage("SENT_SUCCESSFUL", "success");
             } else {
                 Core::getTPL()->assign("userError", Logger::getMessageField("SELF_MESSAGE"));
             }
         } else {
             $result->closeCursor();
             Core::getTPL()->assign("userError", Logger::getMessageField("USER_NOT_FOUND"));
         }
     } else {
         if ($messageLength < 3) {
             Core::getTPL()->assign("messageError", Logger::getMessageField("MESSAGE_TOO_SHORT"));
         }
         if ($messageLength > Core::getOptions()->get("MAX_PM_LENGTH")) {
             Core::getTPL()->assign("messageError", Logger::getMessageField("MESSAGE_TOO_LONG"));
         }
         if (Str::length($subject) == 0 || Str::length($subject) > 50) {
             Core::getTPL()->assign("subjectError", Logger::getMessageField("SUBJECT_TOO_SHORT"));
         }
     }
     return $this;
 }
예제 #5
0
 /**
  * @param string $var
  * @param string $type
  * @param string $options
  * @param string $description
  * @param integer $groupid
  * @return Bengine_Admin_Controller_Config
  */
 protected function saveVariable($var, $type, $options, $description, $groupid)
 {
     $options = $this->serialize($options);
     $spec = array("type" => $type, "options" => $options, "description" => Str::validateXHTML($description), "groupid" => $groupid);
     Core::getQuery()->update("config", $spec, "var = ?", array($var));
     Logger::addMessage("Saving_Successful", "success");
     return $this;
 }