/** * 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 }
/** * Add status message * * @param void * @return void */ function add() { if (!$this->request->isApiCall() && !$this->request->isAsyncCall()) { $this->httpError(HTTP_ERR_BAD_REQUEST); } // if $this->wireframe->print_button = false; if ($this->request->isSubmitted()) { $status_data = $this->request->post('status'); $status_message = array_var($status_data, 'message'); $status_message_parent = null; $status_message_parent_id = (int) array_var($status_data, 'parent_id'); if ($status_message_parent_id) { $status_message_parent = StatusUpdates::findById($status_message_parent_id); } // if $this->active_status_update = new StatusUpdate(); $this->active_status_update->setAttributes($status_data); $this->active_status_update->setCreatedById($this->logged_user->getId()); $this->active_status_update->setCreatedByName($this->logged_user->getName()); $this->active_status_update->setCreatedByEmail($this->logged_user->getEmail()); $save = $this->active_status_update->save(); if (!$save || is_error($save)) { if ($this->request->isApiCall()) { $this->serveData($save); } else { $this->httpError(HTTP_ERR_OPERATION_FAILED); } // if } // if if ($this->request->isApiCall()) { $this->serveData($this->active_status_update, 'message'); } else { UserConfigOptions::setValue('status_update_last_visited', new DateTimeValue(), $this->logged_user); if (instance_of($status_message_parent, 'StatusUpdate')) { $this->smarty->assign('status_update', $status_message_parent); } else { $this->smarty->assign('status_update', $this->active_status_update); } // if print $this->smarty->fetch(get_template_path('_status_row', $this->controller_name, STATUS_MODULE)); die; } // if } else { $this->httpError(HTTP_ERR_BAD_REQUEST); } // if }