/** * Send welcome message * * @param void * @return null */ function send_welcome_message() { if ($this->active_user->isNew()) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if if (!$this->active_user->canSendWelcomeMessage($this->logged_user)) { $this->httpError(HTTP_ERR_FORBIDDEN); } // if $this->skip_layout = $this->request->isAsyncCall(); $welcome_message_data = $this->request->post('welcome_message'); if (!is_array($welcome_message_data)) { $welcome_message_data = array('message' => UserConfigOptions::getValue('welcome_message', $this->active_user)); } // if $this->smarty->assign('welcome_message_data', $welcome_message_data); if ($this->request->isSubmitted()) { $welcome_message = trim(array_var($welcome_message_data, 'message')); if ($welcome_message) { UserConfigOptions::setValue('welcome_message', $welcome_message, $this->active_user); } else { UserConfigOptions::removeValue('welcome_message', $this->active_user); } // if $password = make_password(11); $this->active_user->setPassword($password); $save = $this->active_user->save(); if ($save && !is_error($save)) { $welcome_message_sent = ApplicationMailer::send(array($this->active_user), 'system/new_user', array('created_by_id' => $this->logged_user->getId(), 'created_by_name' => $this->logged_user->getDisplayName(), 'created_by_url' => $this->logged_user->getViewUrl(), 'email' => $this->active_user->getEmail(), 'password' => $password, 'login_url' => assemble_url('login'), 'welcome_body' => $welcome_message ? nl2br(clean($welcome_message)) : '')); if ($welcome_message_sent) { $message = lang('Welcome message has been sent to :name', array('name' => $this->active_user->getDisplayName())); } else { $message = lang('Failed to send welcome message to :name. Please try again later', array('name' => $this->active_user->getDisplayName())); } // if if ($this->request->isAsyncCall()) { die($message); } else { flash_success($message); $this->redirectToUrl($this->active_user->getViewUrl()); } // if } else { if ($this->request->isAsyncCall()) { $this->httpError(HTTP_ERR_OPERATION_FAILED); } else { flash_error($message); $this->redirectToUrl($this->active_user->getViewUrl()); } // if } // if } // if }