function setAsAdministrator($setAsAdmin = true) { if (!logged_user() instanceof User || can_manage_security(logged_user())) { if ($setAsAdmin && !$this->isAdministrator()) { $group_user = new GroupUser(); $group_user->setUserId($this->getId()); $group_user->setGroupId(Group::CONST_ADMIN_GROUP_ID); $group_user->save(); } if (!$setAsAdmin && $this->getId() != 1 && $this->isAdministrator()) { GroupUsers::delete('user_id = ' . $this->getId() . ' and group_id = ' . Group::CONST_ADMIN_GROUP_ID); } } }
/** * Edit group * * @param void * @return null */ function edit_group() { $this->setTemplate('add_group'); if (!can_manage_security(logged_user())) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } // if $group = Groups::findById(get_id()); if (!$group instanceof Group) { flash_error(lang('group dnx')); $this->redirectTo('administration', 'groups'); } // if if (logged_user()->isAdministrator()) { $projects = Projects::getAll(); } else { $projects = null; } $permissions = ProjectUsers::getNameTextArray(); $group_data = array_var($_POST, 'group'); if (!is_array($group_data)) { $group_data = array('name' => $group->getName(), 'can_edit_company_data' => $group->getCanEditCompanyData(), 'can_manage_security' => $group->getCanManageSecurity(), 'can_manage_workspaces' => $group->getCanManageWorkspaces(), 'can_manage_configuration' => $group->getCanManageConfiguration(), 'can_manage_contacts' => $group->getCanManageContacts(), 'can_manage_templates' => $group->getCanManageTemplates(), 'can_manage_reports' => $group->getCanManageReports(), 'can_manage_time' => $group->getCanManageTime(), 'can_add_mail_accounts' => $group->getCanAddMailAccounts()); // array } // if $users = GroupUsers::getUsersByGroup($group->getId()); if ($users) { foreach ($users as $usr) { $group_data['user[' . $usr->getId() . ']'] = true; } } tpl_assign('group', $group); tpl_assign('group_data', $group_data); tpl_assign('permissions', $permissions); tpl_assign('projects', $projects); if (is_array(array_var($_POST, 'group'))) { $group->setFromAttributes($group_data); if (array_var($group_data, "can_edit_company_data") != 'checked') { $group->setCanEditCompanyData(false); } if (array_var($group_data, "can_manage_security") != 'checked') { $group->setCanManageSecurity(false); } if (array_var($group_data, "can_manage_configuration") != 'checked') { $group->setCanManageConfiguration(false); } if (array_var($group_data, "can_manage_workspaces") != 'checked') { $group->setCanManageWorkspaces(false); } if (array_var($group_data, "can_manage_contacts") != 'checked') { $group->setCanManageContacts(false); } if (array_var($group_data, "can_manage_templates") != 'checked') { $group->setCanManageTemplates(false); } if (array_var($group_data, "can_manage_reports") != 'checked') { $group->setCanManageReports(false); } if (array_var($group_data, "can_manage_time") != 'checked') { $group->setCanManageTime(false); } if (array_var($group_data, "can_add_mail_accounts") != 'checked') { $group->setCanAddMailAccounts(false); } try { DB::beginWork(); //set permissions $permissionsString = array_var($_POST, 'permissions'); if ($permissionsString && $permissionsString != '') { $permissions = json_decode($permissionsString); } if (is_array($permissions) && count($permissions) > 0) { //Clear old modified permissions $ids = array(); foreach ($permissions as $perm) { $ids[] = $perm->wsid; } ProjectUsers::clearByUser($group, implode(',', $ids)); //Add new permissions //TODO - Make batch update of these permissions foreach ($permissions as $perm) { if (ProjectUser::hasAnyPermissions($perm->pr, $perm->pc)) { $relation = new ProjectUser(); $relation->setProjectId($perm->wsid); $relation->setUserId($group->getId()); $relation->setCheckboxPermissions($perm->pc); $relation->setRadioPermissions($perm->pr); $relation->save(); } //endif //else if the user has no permissions at all, he is not a project_user. ProjectUser is not created } //end foreach } // if $group->save(); GroupUsers::clearByGroup($group); if (array_var($_POST, 'user')) { foreach (array_var($_POST, 'user') as $user_id => $val) { if ($val == 'checked' && is_numeric($user_id) && Users::findById($user_id) instanceof User) { $gu = new GroupUser(); $gu->setGroupId($group->getId()); $gu->setUserId($user_id); $gu->save(); } } } ApplicationLogs::createLog($group, null, ApplicationLogs::ACTION_EDIT); DB::commit(); flash_success(lang('success edit group', $group->getName())); ajx_current("back"); } catch (Exception $e) { DB::rollback(); tpl_assign('error', $e); } // try } // if }
/** * Finish the installation - create owner company and administrator * * @param void * @return null */ function complete_installation() { if (Companies::getOwnerCompany() instanceof Company) { die('Owner company already exists'); // Somebody is trying to access this method even if the user already exists } // if $form_data = array_var($_POST, 'form'); tpl_assign('form_data', $form_data); if (array_var($form_data, 'submited') == 'submited') { try { $admin_password = trim(array_var($form_data, 'admin_password')); $admin_password_a = trim(array_var($form_data, 'admin_password_a')); if (trim($admin_password) == '') { throw new Error(lang('password value required')); } // if if ($admin_password != $admin_password_a) { throw new Error(lang('passwords dont match')); } // if DB::beginWork(); Users::delete(); // clear users table Companies::delete(); // clear companies table // Create the administrator user $administrator = new User(); $administrator->setId(1); $administrator->setCompanyId(1); $administrator->setUsername(array_var($form_data, 'admin_username')); $administrator->setEmail(array_var($form_data, 'admin_email')); $administrator->setPassword($admin_password); $administrator->setCanEditCompanyData(true); $administrator->setCanManageConfiguration(true); $administrator->setCanManageSecurity(true); $administrator->setCanManageWorkspaces(true); $administrator->setCanManageContacts(true); $administrator->setCanManageTemplates(true); $administrator->setCanManageReports(true); $administrator->setCanManageTime(true); $administrator->setCanAddMailAccounts(true); $administrator->setAutoAssign(false); $administrator->setPersonalProjectId(1); $administrator->setType('admin'); $administrator->save(); $group = new Group(); $group->setName('administrators'); $group->setAllPermissions(true); $group->setId(Group::CONST_ADMIN_GROUP_ID); $group->save(); $group_user = new GroupUser(); $group_user->setGroupId(Group::CONST_ADMIN_GROUP_ID); $group_user->setUserId($administrator->getId()); $group_user->save(); $project = new Project(); $project->setId(1); $project->setP1(1); $project->setName(new_personal_project_name($administrator->getUsername())); $project->setDescription(lang('files')); $project->setCreatedById($administrator->getId()); $project->save(); $project_user = new ProjectUser(); $project_user->setProjectId($project->getId()); $project_user->setUserId($administrator->getId()); $project_user->setCreatedById($administrator->getId()); $project_user->setAllPermissions(true); $project_user->save(); // Create a company $company = new Company(); $company->setId(1); $company->setClientOfId(0); $company->setName(array_var($form_data, 'company_name')); $company->setCreatedById(1); $company->save(); DB::commit(); $this->redirectTo('access', 'login'); } catch (Exception $e) { tpl_assign('error', $e); DB::rollback(); } // try } // if }