/** * Update user's company and role information * * @param void * @return null */ function edit_company_and_role() { $this->wireframe->print_button = false; if ($this->active_user->isNew()) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if if (!$this->active_user->canChangeRole($this->logged_user)) { $this->httpError(HTTP_ERR_FORBIDDEN); } // if $last_administrator = $this->active_user->isAdministrator() && Users::countAdministrators() <= 1; if ($last_administrator) { $this->wireframe->addPageMessage(lang('This user is the last adminstrator on the system. His role cannot be changed')); } // if $user_data = $this->request->post('user'); if (!is_array($user_data)) { $user_data = array('company_id' => $this->active_user->getCompanyId(), 'role_id' => $this->active_user->getRoleId()); } // if $this->smarty->assign(array('user_data' => $user_data, 'last_administrator' => $last_administrator)); if ($this->request->isSubmitted()) { db_begin_work(); $this->active_user->setAttributes($user_data); $save = $this->active_user->save(); if ($save && !is_error($save)) { db_commit(); flash_success(":display's company and role information has been updated", array('display' => $this->active_user->getDisplayName())); $this->redirectToUrl($this->active_user->getViewUrl()); } else { db_rollback(); $this->smarty->assign('errors', $save); } // if } // if }