/** * Edit the contact's user account * * @access public * @param void * @return null */ function edit_user_account() { $this->setTemplate('add_user_to_contact'); $contact = Contacts::findById(get_id()); if (!$contact instanceof Contact) { flash_error(lang('contact dnx')); $this->redirectTo('dashboard', 'contacts'); } // if if (!$contact->canEditUserAccount(logged_user())) { flash_error(lang('no access permissions')); $this->redirectTo('dashboard', 'contacts'); } // if if (!$contact->hasUserAccount()) { flash_error(lang('user dnx')); $this->redirectToUrl($contact->getCompany()->getViewUrl()); } $user = $contact->getUserAccount(); $company = $contact->getCompany(); $user_data = array_var($_POST, 'user'); if (!is_array($user_data)) { $user_data = array('username' => $user->getUsername(), 'email' => $user->getEmail(), 'timezone' => $user->getTimezone(), 'locale' => $user->getLocale(), 'is_admin' => $user->isAdministrator(), 'auto_assign' => $user->getAutoAssign(), 'use_LDAP' => $user->getUseLDAP(), 'can_manage_projects' => $user->canManageProjects() ? '1' : '0'); // array } // if tpl_assign('contact', $contact); tpl_assign('user', $user); tpl_assign('company', $company); tpl_assign('user_data', $user_data); if (is_array(array_var($_POST, 'user'))) { $user->setFromAttributes($user_data); try { $password = ''; // Generate random password if (array_var($user_data, 'password_generator') == 'random') { $password = substr(sha1(uniqid(rand(), true)), rand(0, 25), 13); $user->setPassword($password); // Validate user input } else { if (array_var($user_data, 'password_generator') == 'specify') { $password = array_var($user_data, 'password'); if (trim($password) == '') { throw new Error(lang('password value required')); } // if if ($password != array_var($user_data, 'password_a')) { throw new Error(lang('passwords dont match')); } // if $user->setPassword($password); } } // if $granted = 0; if (logged_user()->isAdministrator()) { $user->setIsAdmin(array_var($user_data, 'is_admin')); $user->setAutoAssign(array_var($user_data, 'auto_assign')); $granted = trim(array_var($user_data, 'can_manage_projects')) == '1' ? 1 : 0; } else { $user->setIsAdmin(0); $user->setAutoAssign(0); } DB::beginWork(); $user->save(); $user->setPermission(PermissionManager::CAN_MANAGE_PROJECTS, $granted); ApplicationLogs::createLog($user, null, ApplicationLogs::ACTION_EDIT); DB::commit(); // Send notification... try { if (array_var($user_data, 'send_email_notification')) { Notifier::updatedUserAccount($user, $password); } // if } catch (Exception $e) { } // try flash_success(lang('success edit user', $user->getDisplayName())); $this->redirectToUrl($company->getViewUrl()); // Translate to profile page } catch (Exception $e) { DB::rollback(); tpl_assign('error', $e); } // try } // if }