Пример #1
0
 /**
  * Email admin
  * @param string $status Message status e.g. error, success, debug
  * @param string $msg Message to email
  * @param boolean $email Email to admin, default false
  * @return boolean
  */
 public static function emailAdmin($status, $msg)
 {
     // Check admin email constants are defined
     if (!defined('EMAIL_FROM')) {
         status::Output('ERROR', 'EMAIL_FROM not specified');
         return;
     }
     if (!defined('AUTHOR_NAME')) {
         status::Output('ERROR', 'AUTHOR_NAME not specified');
         return;
     }
     if (!defined('AUTHOR_EMAIL')) {
         status::Output('ERROR', 'AUTHOR_EMAIL not specified');
         return;
     }
     // Create email
     $email = new Email();
     if (defined('EMAIL_SMTP') && EMAIL_SMTP) {
         $email->setSMTPStream();
     } else {
         $email->setPHPMail();
     }
     // Set message
     $email->addHTML("\n\t\t\t<p>CLI email from " . EMAIL_DOMAIN . ":<br />\n\t\t\tstatus: " . $status . "<br />\n\t\t\tmessage: " . nl2br($msg) . "\n\t\t\t</p>\n\t\t");
     // Send to admin
     $email->addRecipient(AUTHOR_EMAIL, AUTHOR_NAME);
     if ($email->Send(EMAIL_FROM, 'CLI Message') && !\Sonic\Message::count('error')) {
         return TRUE;
     } else {
         return FALSE;
     }
 }
 /**
  * Update user
  * @param string $user_first_name First name
  * @param string $user_last_name Last name
  * @param string $user_email Email address
  * @param string $user_password_current (Optional) Current password
  * @param string $user_password (Optional) New password
  * @param string $user_password_confirm (Optional) Password confirmation
  */
 public function update()
 {
     $this->template = 'admin/settings/index.tpl';
     $user = new \Sonic\Model\User();
     $user->fromPost(TRUE, array('first_name', 'last_name', 'email'));
     $user->set('id', $this->user->get('id'));
     if (\Sonic\Message::count('error')) {
         return;
     }
     $exclude = array();
     if ($user->get('password')) {
         $this->user->readAttribute('password');
         if (!$this->user->checkPassword($this->getArg('user_password_current'))) {
             new \Sonic\Message('error', 'Your current password is not valid, please try again');
             return;
         } else {
             if ($user->get('password') !== $this->getArg('user_password_confirm')) {
                 new \Sonic\Message('error', 'Your new passwords did not match, please try again');
                 return;
             }
         }
     } else {
         $exclude[] = 'password';
     }
     if (!$user->update($exclude)) {
         new \Sonic\Message('error', 'Settings update failed, please try again');
         return;
     }
     $this->user->read();
     new \Sonic\Message('success', 'Settings updated');
 }
Пример #3
0
 /**
  * Edit user
  * @param string $edit_user (Optional) Whether to edit a user
  * @param string $user_id User ID
  * @param string $user_first_name First name
  * @param string $user_last_name Last name
  * @param string $user_email Email address
  * @param string $user_active Active status
  * @param string $user_admin Admin status
  * @param string $user_password (Optional) New password
  * @param string $user_password_confirm (Optional) Password confirmation
  */
 public function edit()
 {
     $id = $this->getArg('id');
     if (!\Sonic\Model\User::_IDexists($id)) {
         new \Sonic\Resource\Redirect('index', array('error' => 'Invalid User'));
     }
     $user = \Sonic\Model\User::_read($id);
     $this->view->assignByRef('newuser', $user);
     if ($this->getArg('edit_user')) {
         // User data
         $user->fromPost(TRUE, array('first_name', 'last_name', 'email', 'active', 'admin'));
         if (\Sonic\Message::count('error')) {
             return FALSE;
         }
         // New password
         $exclude = array();
         if ($user->get('password')) {
             if ($user->get('password') !== $this->getArg('user_password_confirm')) {
                 new \Sonic\Message('error', 'The new passwords did not match, please try again');
                 return;
             }
         } else {
             $exclude[] = 'password';
         }
         // Update
         if (!$user->update($exclude)) {
             new \Sonic\Message('error', 'User update failed, please try again');
             return;
         }
         // Success
         $user->read();
         new \Sonic\Message('success', 'User Updated');
     }
 }
function smarty_function_messages($params, &$tpl)
{
    // Set valid message types
    $validTypes = array('success', 'error');
    // Set messages
    $messages = '<div class="message_container">';
    // If the URL flag is true
    if (isset($params['url']) && $params['url']) {
        // Set messages
        if (isset($_GET['message'])) {
            new \Sonic\Message('success', $_GET['message']);
        }
        if (isset($_GET['error'])) {
            new \Sonic\Message('error', $_GET['error']);
        }
    }
    // If there is a type
    if (isset($params['type']) && in_array($params['type'], $validTypes)) {
        // If there are any messages
        if (\Sonic\Message::count($params['type']) > 0) {
            // Generate messages
            $message = \Sonic\Message::getString($params['type'], '<p>', '</p>');
            $tpl->assign('message', $message);
            $messages .= $tpl->fetch('message/' . $params['type'] . '.tpl', 'message|' . $params['type'] . '|' . md5($message));
            // Reset messages
            \Sonic\Message::reset($params['type']);
        }
    } else {
        // If there are any messages
        if (\Sonic\Message::count()) {
            // Generate messages
            $messageTypes = array_keys(\Sonic\Message::get());
            foreach ($messageTypes as $type) {
                if (!in_array($type, $validTypes)) {
                    continue;
                }
                $message = \Sonic\Message::getString($type, '<p>', '</p>');
                $tpl->assign('message', $message);
                $messages .= $tpl->fetch('message/' . $type . '.tpl', 'message|' . $type . '|' . md5($message));
            }
            // Reset messages
            \Sonic\Message::reset();
        }
    }
    // Close messages
    $messages .= '</div>';
    // Return messages
    return $messages;
}