Example #1
0
 /**
  * Logs an Error, should be in Config, but that doesn't extend permissions
  * @param string $error The error stacktrace
  * @throws \Exception
  */
 public function logError($error)
 {
     if (!is_string($error)) {
         throw $this->throwException(2003);
     }
     $error = strip_tags($error);
     Log::addToLog('-------------------------------------------');
     Log::addToLog(date('r') . ':');
     Log::addToLog($error);
     Log::addToLog('-------------------------------------------');
     $mailer = new Mailer();
     $message = 'An error occurred at ' . date('r') . ' on ' . SITENAME . "\r\nThe stacktrace is:\r\n" . $error;
     $mailer->sendPlainMail(SYSMAIL, SYSMAIL, 'Bright Error', $message);
 }
Example #2
0
 /**
  * Submits the form
  */
 public function submit()
 {
     $this->check();
     if (count($this->_errors) == 0) {
         // Valid form
         switch ($this->_action) {
             case self::ACTION_EMAIL:
                 // Send the form
                 if (!$this->_recipient) {
                     throw new \Exception($this->_exceptions[Form::EXCEPTION_INVALID_EMAIL], Form::EXCEPTION_INVALID_EMAIL);
                 }
                 $emldata = array('bodytext' => $this->_bodytext, 'title' => $this->_title, 'fields' => $this->_data);
                 $smarty = new \Smarty();
                 $ds = DIRECTORY_SEPARATOR;
                 $smarty->assign($emldata)->setCacheDir(BASEPATH . "bright{$ds}cache{$ds}smarty")->setCompileDir(BASEPATH . "bright{$ds}cache{$ds}smarty_c")->enableSecurity()->addTemplateDir(BASEPATH . "bright{$ds}library{$ds}Bright{$ds}templates{$ds}")->registerPlugin(\Smarty::PLUGIN_FUNCTION, 'getLabel', array($this, '_getLabel'))->registerPlugin(\Smarty::PLUGIN_FUNCTION, 'getValue', array($this, '_getValue'))->php_handling = \Smarty::PHP_REMOVE;
                 ob_start();
                 $smarty->display('FormMailTemplate.tpl');
                 $html = ob_get_clean();
                 ob_start();
                 $smarty->display('FormMailPlainTemplate.tpl');
                 $plain = ob_get_clean();
                 $mailer = new Mailer();
                 $res = $mailer->sendHtmlMail(MAILINGFROM, $this->_recipient, $this->_subject, $html, $plain);
                 if ($res && $this->_pageAfterSuccess != null) {
                     $t = new Tree();
                     $path = $t->getPath($this->_pageAfterSuccess);
                     if (USEPREFIX) {
                         $path = $_SESSION['language'] . '/' . $path;
                     }
                     $path = BASEURL . $path;
                     header("Location: {$path}");
                     exit;
                 }
                 break;
             case self::ACTION_STORE:
                 // Store the data
                 throw new \Exception($this->_exceptions[Form::EXCEPTION_NOT_IMPLEMENTED] . ' ACTION_STORE', Form::EXCEPTION_NOT_IMPLEMENTED);
                 break;
         }
     }
     return $this;
 }
Example #3
0
 private function _send($pid, $email)
 {
     if (is_string($email)) {
         $email = array($email);
     }
     $parsed = $this->_parse($pid);
     $mailer = new Mailer();
     $emails = array();
     $decorated = array();
     $template = new Template();
     $tpl = $template->getUserTemplate();
     foreach ($email as $em) {
         if (is_string($em)) {
             $emails[] = $em;
         } else {
             $emails[] = $em->email;
             $decoration = array('{email}' => $em->email, '[email]' => $em->email, '[code]' => $em->activationcode, '{code}' => $em->activationcode);
             if ($tpl) {
                 foreach ($tpl->fields as $field) {
                     if (isset($em->content->{$field->label})) {
                         $decoration['[' . $field->label . ']'] = $em->content->{$field->label}->tpl;
                     }
                 }
             }
             $decorated[$em->email] = $decoration;
         }
     }
     if (count($decorated) == 0) {
         $decorated = null;
     }
     $mailer->sendMassMail(array(MAILINGFROM => SITENAME), $emails, $parsed->page->content->loc_title, $parsed->parsed, $decorated);
 }
Example #4
0
 /**
  * Creates a user<br/>
  * @param OUserObject $user The user to create
  * @param boolean $sendMail Indicates whether an email with his credentials should be send to the newly created user
  * @param string $password When $sendMail is true, you have to pass the non-hashed password to this method in order to include it in the e-mail
  * @return array An array of all the users
  * @throws \Exception
  */
 private function _createUser($user, $sendMail = false, $password = '')
 {
     $email = Connection::getInstance()->escape_string($user->email);
     $result = $this->conn->getRow("SELECT count(userId) as ids \n\t\t\t\t\t\t\t\t\tFROM user \n\t\t\t\t\t\t\t\t\tWHERE email = '{$email}' and (deleted IS NULL OR YEAR(deleted) = 0)");
     if ($result->ids > 0) {
         throw $this->throwException(8002);
     }
     $this->_hashPassword($user->password, $user->email);
     $activationCode = md5(time() . $user->password);
     $activated = $user->activated ? 1 : 0;
     $user->itemType = (int) $user->itemType;
     $insert = $this->conn->insertRow('INSERT INTO user (`label`, `itemType`, `email`, `password`, `registrationdate`, `modificationdate`, `activationcode`, `activated`) ' . "VALUES ('" . Connection::getInstance()->escape_string($user->label) . "',\n\t\t\t\t\t\t\t\t\t\t\t{$user->itemType},\n\t\t\t\t\t\t\t\t\t\t\t'{$email}',\n\t\t\t\t\t\t\t\t\t\t\t'" . Connection::getInstance()->escape_string($user->password) . "',\n\t\t\t\t\t\t\t\t\t\t\tNOW(),\n\t\t\t\t\t\t\t\t\t\t\t" . time() . ",\n\t\t\t\t\t\t\t\t\t\t\t'{$activationCode}',\n\t\t\t\t\t\t\t\t\t\t\t{$activated})");
     if ($insert > 0) {
         $user->userId = $insert;
         if ($sendMail) {
             ob_start();
             include 'registration.txt';
             $content = ob_get_contents();
             ob_end_clean();
             $content = str_replace('###sitename###', SITENAME, $content);
             $content = str_replace('###baseurl###', BASEURL, $content);
             $content = str_replace('###email###', $user->email, $content);
             $content = str_replace('###password###', $password, $content);
             $ma = new Mailer();
             $ma->sendPlainMail(MAILINGFROM, $user->email, 'Your account for ' . SITENAME . ' is ready', $content);
         }
         return $user->userId;
     }
     throw $this->throwException(UserException::INSERT_ERROR);
 }