/** * Show permission update form * * @param void * @return null */ function permissions() { if (!active_project()->canChangePermissions(logged_user())) { flash_error(lang('no access permissions')); $this->redirectToUrl(active_project()->getOverviewUrl()); } // if $project_init = array_var($_GET, 'project_init'); tpl_assign('project_init', $project_init); tpl_assign('project_users', active_project()->getUsers(false)); tpl_assign('project_companies', active_project()->getCompanies()); tpl_assign('user_projects', logged_user()->getProjects()); $permissions = PermissionManager::getPermissionsText(); tpl_assign('permissions', $permissions); $companies = array(owner_company()); $clients = owner_company()->getClientCompanies(); if (is_array($clients)) { $companies = array_merge($companies, $clients); } // if tpl_assign('companies', $companies); if (array_var($_POST, 'process') == 'process') { try { DB::beginWork(); active_project()->clearCompanies(); active_project()->clearUsers(); $companies = array(owner_company()); $client_companies = owner_company()->getClientCompanies(); if (is_array($client_companies)) { $companies = array_merge($companies, $client_companies); } // if foreach ($companies as $company) { // Company is selected! if (array_var($_POST, 'project_company_' . $company->getId()) == 'checked') { // Owner company is automaticly included so it does not need to be in project_companies table if (!$company->isOwner()) { $project_company = new ProjectCompany(); $project_company->setProjectId(active_project()->getId()); $project_company->setCompanyId($company->getId()); $project_company->save(); } // if $users = $company->getUsers(); if (is_array($users)) { $counter = 0; foreach ($users as $user) { $user_id = $user->getId(); $counter++; if (array_var($_POST, "project_user_{$user_id}") == 'checked') { $project_user = new ProjectUser(); $project_user->setProjectId(active_project()->getId()); $project_user->setUserId($user_id); foreach ($permissions as $permission => $permission_text) { // Owner company members have all permissions $permission_value = $company->isOwner() ? true : array_var($_POST, 'project_user_' . $user_id . '_' . $permission) == 'checked'; $setter = 'set' . Inflector::camelize($permission); $project_user->{$setter}($permission_value); } // if $project_user->save(); } // if } // foreach } // if } // if } // foreach DB::commit(); flash_success(lang('success update project permissions')); if ($project_init) { $this->redirectToUrl(active_project()->getEditUrl(active_project()->getOverviewUrl())); } else { $this->redirectTo('project_settings', 'users'); } // if } catch (Exception $e) { DB::rollback(); flash_error(lang('error update project permissions')); $this->redirectTo('project_settings', 'permissions'); } // try } // if }
/** * This function will check if this user has all project permissions * * @param Project $project * @param boolean $use_cache * @return boolean */ function hasAllProjectPermissions(Project $project, $use_cache = true) { $permissions = array_keys(PermissionManager::getPermissionsText()); if (is_array($permissions)) { foreach ($permissions as $permission) { if (!$this->getProjectPermission($project, $permission)) { return false; } } // foreach } // if return true; } // hasAllProjectPermissions
/** * Show update permissions page * * @param void * @return null */ function update_permissions() { $user = Users::findById(get_id()); if (!$user instanceof User) { flash_error(lang('user dnx')); $this->redirectToReferer(get_url('dashboard')); } // if if (!$user->canUpdatePermissions(logged_user())) { flash_error(lang('no access permissions')); $this->redirectToReferer(get_url('dashboard')); } // if $company = $user->getCompany(); if (!$company instanceof Company) { flash_error(lang('company dnx')); $this->redirectToReferer(get_url('dashboard')); } // if $projects = $company->getProjects(); if (!is_array($projects) || !count($projects)) { flash_error(lang('no projects owned by company')); $this->redirectToReferer($company->getViewUrl()); } // if $permissions = PermissionManager::getPermissionsText(); $redirect_to = array_var($_GET, 'redirect_to'); if (trim($redirect_to) == '' || !is_valid_url($redirect_to)) { $redirect_to = $user->getCardUrl(); } // if tpl_assign('user', $user); tpl_assign('company', $company); tpl_assign('projects', $projects); tpl_assign('permissions', $permissions); tpl_assign('redirect_to', $redirect_to); if (array_var($_POST, 'submitted') == 'submitted') { DB::beginWork(); ProjectUsers::clearByUser($user); foreach ($projects as $project) { $permission_count = 0; $permission_all = array_var($_POST, 'project_permissions_' . $project->getId() . '_all') == 'checked'; foreach ($permissions as $permission_name => $permission_text) { $permission_value = $permission_all || array_var($_POST, 'project_permission_' . $project->getId() . '_' . $permission_name) == 'checked'; if ($permission_value) { $permission_count++; } $user->setProjectPermission($project, $permission_name, $permission_value); } // foreach if ($permission_count > 0) { $relation = new ProjectUser(); $relation->setProjectId($project->getId()); $relation->setUserId($user->getId()); $relation->save(); } } // if DB::commit(); flash_success(lang('success user permissions updated')); $this->redirectToUrl($redirect_to); } // if }
/** * Create and attach a user account to the contact * * @access public * @param void * @return null */ function add_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->canAddUserAccount(logged_user())) { flash_error(lang('no access permissions')); $this->redirectTo('dashboard', 'contacts'); } // if if ($contact->hasUserAccount()) { flash_error(lang('contact already has user')); $this->redirectToUrl($contact->getCardUrl()); } $user = new User(); $company = $contact->getCompany(); $user_data = array_var($_POST, 'user'); if (!is_array($user_data)) { $user_data = array('email' => $contact->getEmail(), 'password_generator' => 'random', 'timezone' => $company->getTimezone()); // array } // if $projects = $company->getProjects(); $permissions = PermissionManager::getPermissionsText(); tpl_assign('contact', $contact); tpl_assign('user', $user); tpl_assign('company', $company); tpl_assign('projects', $projects); tpl_assign('permissions', $permissions); tpl_assign('user_data', $user_data); if (is_array(array_var($_POST, 'user'))) { $user->setFromAttributes($user_data); try { // Generate random password if (array_var($user_data, 'password_generator') == 'random') { $password = substr(sha1(uniqid(rand(), true)), rand(0, 25), 13); // Validate user input } else { $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 } // if $user->setPassword($password); $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); $contact->setUserId($user->getId()); $contact->save(); ApplicationLogs::createLog($user, null, ApplicationLogs::ACTION_ADD); if (is_array($projects)) { foreach ($projects as $project) { if (array_var($user_data, 'project_permissions_' . $project->getId()) == 'checked') { $relation = new ProjectUser(); $relation->setProjectId($project->getId()); $relation->setUserId($user->getId()); foreach ($permissions as $permission => $permission_text) { $permission_value = array_var($user_data, 'project_permission_' . $project->getId() . '_' . $permission) == 'checked'; $setter = 'set' . Inflector::camelize($permission); $relation->{$setter}($permission_value); } // foreach $relation->save(); } // if } // forech } // if DB::commit(); // Send notification... try { if (array_var($user_data, 'send_email_notification')) { Notifier::newUserAccount($user, $password); } // if } catch (Exception $e) { } // try flash_success(lang('success add user', $user->getDisplayName())); $this->redirectToUrl($company->getViewUrl()); // Translate to profile page } catch (Exception $e) { DB::rollback(); tpl_assign('error', $e); } // try } // if }
/** * Add user * * @access public * @param void * @return null */ function add() { $this->setTemplate('add_user'); $company = Companies::findById(get_id('company_id')); if (!$company instanceof Company) { flash_error(lang('company dnx')); $this->redirectTo('administration'); } // if if (!User::canAdd(logged_user(), $company)) { flash_error(lang('no access permissions')); $this->redirectToReferer(get_url('dashboard')); } // if $user = new User(); $user_data = array_var($_POST, 'user'); if (!is_array($user_data)) { $user_data = array('password_generator' => 'random', 'company_id' => $company->getId(), 'timezone' => $company->getTimezone()); // array } // if $projects = $company->getProjects(); $permissions = PermissionManager::getPermissionsText(); tpl_assign('user', $user); tpl_assign('company', $company); tpl_assign('projects', $projects); tpl_assign('permissions', $permissions); tpl_assign('user_data', $user_data); if (is_array(array_var($_POST, 'user'))) { $user->setFromAttributes($user_data); $user->setCompanyId($company->getId()); try { // Generate random password if (array_var($user_data, 'password_generator') == 'random') { $password = substr(sha1(uniqid(rand(), true)), rand(0, 25), 13); // Validate user input } else { $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 } // if $user->setPassword($password); if (config_option('check_email_unique', '1') == '1') { if (!$user->validateUniquenessOf('email')) { throw new Error(lang('email address is already used')); } } DB::beginWork(); $user->save(); ApplicationLogs::createLog($user, null, ApplicationLogs::ACTION_ADD); if (is_array($projects)) { foreach ($projects as $project) { if (array_var($user_data, 'project_permissions_' . $project->getId()) == 'checked') { $relation = new ProjectUser(); $relation->setProjectId($project->getId()); $relation->setUserId($user->getId()); foreach ($permissions as $permission => $permission_text) { $permission_value = array_var($user_data, 'project_permission_' . $project->getId() . '_' . $permission) == 'checked'; $user->setProjectPermission($project, $permission, $permission_value); } // foreach $relation->save(); } // if } // foreach } // if DB::commit(); // Send notification... try { if (array_var($user_data, 'send_email_notification')) { Notifier::newUserAccount($user, $password); } // if } catch (Exception $e) { } // try // Add task to Welcome project... try { if (array_var($user_data, 'add welcome task')) { $task_data = array('text' => lang('welcome task text', $user->getName(), get_url('account', 'edit')), 'due date' => DateTimeValueLib::now() + 7 * 24 * 60 * 60, 'assigned_to_company_id' => $user->getCompanyId(), 'assigned_to_user_id' => $user->getId()); $task_list = ProjectTaskLists::instance()->findById(2, true); DB::beginWork(); $task = new ProjectTask(); $task->setFromAttributes($task_data); $task_list->attachTask($task); $task->save(); DB::commit(); } // if } catch (Exception $e) { DB::rollback(); } // try flash_success(lang('success add user', $user->getDisplayName())); $projects = $company->getProjects(); if (is_array($projects) || count($projects)) { $this->redirectToUrl(get_url('account', 'update_permissions', $user->getId())); // Continue to permissions page } // if $this->redirectToUrl($company->getViewUrl()); } catch (Exception $e) { DB::rollback(); tpl_assign('error', $e); } // try } // if }
/** * Add project * * @param void * @return null */ function add() { $this->setTemplate('add_project'); $this->setLayout('administration'); if (!logged_user()->canManageProjects()) { flash_error(lang('no access permissions')); $this->redirectToReferer(get_url('dashboard')); } // if $project = new Project(); $project_data = array_var($_POST, 'project'); tpl_assign('project', $project); tpl_assign('project_data', $project_data); // Submitted... if (is_array($project_data)) { $project->setFromAttributes($project_data); $default_folders = array(); if (plugin_active('files')) { $default_folders_config = str_replace(array("\r\n", "\r"), array("\n", "\n"), config_option('default_project_folders', '')); if (trim($default_folders_config) == '') { $default_folders = array(); } else { $default_folders = explode("\n", $default_folders_config); } // if } // if $default_ticket_categories = array(); if (plugin_active('tickets')) { $default_ticket_categories_config = str_replace(array("\r\n", "\r"), array("\n", "\n"), config_option('tickets_default_categories', '')); if (trim($default_ticket_categories_config) == '') { $default_ticket_categories = array(); } else { $default_ticket_categories = explode("\n", $default_ticket_categories_config); } // if } // if try { DB::beginWork(); $project->save(); $permissions = array_keys(PermissionManager::getPermissionsText()); $auto_assign_users = owner_company()->getAutoAssignUsers(); // We are getting the list of auto assign users. If current user is not in the list // add it. He's creating the project after all... if (is_array($auto_assign_users)) { $auto_assign_logged_user = false; foreach ($auto_assign_users as $user) { if ($user->getId() == logged_user()->getId()) { $auto_assign_logged_user = true; } } // if if (!$auto_assign_logged_user) { $auto_assign_users[] = logged_user(); } } else { $auto_assign_users[] = logged_user(); } // if foreach ($auto_assign_users as $auto_assign_user) { $project_user = new ProjectUser(); $project_user->setProjectId($project->getId()); $project_user->setUserId($auto_assign_user->getId()); $project_user->save(); if (is_array($permissions)) { foreach ($permissions as $permission) { $auto_assign_user->setProjectPermission($project, $permission, true); } } // if } // foreach if (count($default_folders)) { $added_folders = array(); foreach ($default_folders as $default_folder) { $folder_name = trim($default_folder); if ($folder_name == '') { continue; } // if if (in_array($folder_name, $added_folders)) { continue; } // if $folder = new ProjectFolder(); $folder->setProjectId($project->getId()); $folder->setName($folder_name); $folder->save(); $added_folders[] = $folder_name; } // foreach } // if if (count($default_ticket_categories)) { $added_categories = array(); foreach ($default_ticket_categories as $default_ticket_category) { $category_name = trim($default_ticket_category); if ($category_name == '') { continue; } // if if (in_array($category_name, $added_categories)) { continue; } // if $folder = new ProjectCategory(); $folder->setProjectId($project->getId()); $folder->setName($category_name); $folder->save(); $added_categories[] = $category_name; } // foreach } // if ApplicationLogs::createLog($project, null, ApplicationLogs::ACTION_ADD, false, true); DB::commit(); flash_success(lang('success add project', $project->getName())); $this->redirectToUrl($project->getPermissionsUrl()); } catch (Exception $e) { tpl_assign('error', $e); DB::rollback(); } // try } // if }
/** * Add project * * @param void * @return null */ function add() { $this->setTemplate('add_project'); $this->setLayout('administration'); if (!logged_user()->canManageProjects()) { flash_error(lang('no access permissions')); $this->redirectToReferer(get_url('dashboard')); } // if $project = new Project(); $project_data = array_var($_POST, 'project'); $page_name = 'project_overview'; $page_attachments = PageAttachments::getAttachmentsByPageNameAndProject($page_name, $project); $redirect_to = urldecode(array_var($_GET, 'redirect_to')); tpl_assign('project', $project); tpl_assign('project_data', $project_data); tpl_assign('page_attachments', $page_attachments); tpl_assign('redirect_to', $redirect_to); // Submitted... if (is_array($project_data)) { $project->setFromAttributes($project_data); $default_folders = array(); if (plugin_active('files')) { $default_folders_config = str_replace(array("\r\n", "\r"), array("\n", "\n"), config_option('default_project_folders', '')); if (trim($default_folders_config) == '') { $default_folders = array(); } else { $default_folders = explode("\n", $default_folders_config); } // if } // if $default_ticket_categories = array(); if (plugin_active('tickets')) { $default_ticket_categories_config = str_replace(array("\r\n", "\r"), array("\n", "\n"), config_option('tickets_default_categories', '')); if (trim($default_ticket_categories_config) == '') { $default_ticket_categories = array(); } else { $default_ticket_categories = explode("\n", $default_ticket_categories_config); } // if } // if try { DB::beginWork(); $project->save(); $permissions = array_keys(PermissionManager::getPermissionsText()); $auto_assign_users = owner_company()->getAutoAssignUsers(); // We are getting the list of auto assign users. If current user is not in the list // add it. He's creating the project after all... if (is_array($auto_assign_users)) { $auto_assign_logged_user = false; foreach ($auto_assign_users as $user) { if ($user->getId() == logged_user()->getId()) { $auto_assign_logged_user = true; } } // if if (!$auto_assign_logged_user) { $auto_assign_users[] = logged_user(); } } else { $auto_assign_users[] = logged_user(); } // if foreach ($auto_assign_users as $auto_assign_user) { $project_user = new ProjectUser(); $project_user->setProjectId($project->getId()); $project_user->setUserId($auto_assign_user->getId()); $project_user->save(); if (is_array($permissions)) { foreach ($permissions as $permission) { $auto_assign_user->setProjectPermission($project, $permission, true); } } // if } // foreach if (count($default_folders)) { $added_folders = array(); foreach ($default_folders as $default_folder) { $folder_name = trim($default_folder); if ($folder_name == '') { continue; } // if if (in_array($folder_name, $added_folders)) { continue; } // if $folder = new ProjectFolder(); $folder->setProjectId($project->getId()); $folder->setName($folder_name); $folder->save(); $added_folders[] = $folder_name; } // foreach } // if if (count($default_ticket_categories)) { $added_categories = array(); foreach ($default_ticket_categories as $default_ticket_category) { $category_name = trim($default_ticket_category); if ($category_name == '') { continue; } // if if (in_array($category_name, $added_categories)) { continue; } // if $folder = new ProjectCategory(); $folder->setProjectId($project->getId()); $folder->setName($category_name); $folder->save(); $added_categories[] = $category_name; } // foreach } // if $efqm_project = isset($project_data['efqm_project']) ? $project_data['efqm_project'] == '1' : false; if ($efqm_project) { // insert 9 milestones with task lists $efqm_template = array('efqm leadership' => array('a', 'b', 'c', 'd', 'e'), 'efqm strategy' => array('a', 'b', 'c', 'd'), 'efqm people' => array('a', 'b', 'c', 'd', 'e'), 'efqm partnership and resources' => array('a', 'b', 'c', 'd', 'e'), 'efqm processes products services' => array('a', 'b', 'c', 'd', 'e'), 'efqm customer results' => array('a', 'b'), 'efqm people results' => array('a', 'b'), 'efqm society results' => array('a', 'b'), 'efqm key results' => array('a', 'b')); foreach ($efqm_template as $criteria => $subcriteria) { $milestone = new ProjectMilestone(); $milestone->setProjectId($project->getId()); $milestone->setName(lang($criteria)); $milestone->setGoal(config_option('initial goal', 80)); $milestone->setDueDate(DateTimeValueLib::now()); $offset_in_days = config_option('due date offset', 90); $milestone->getDueDate()->advance(60 * 60 * 24 * $offset_in_days); $milestone->save(); foreach ($subcriteria as $subname) { $task_list = new ProjectTaskList(); $task_list->setMilestoneId($milestone->getId()); $task_list->setProjectId($project->getId()); $task_list->setName(lang($criteria) . ' ' . $subname); $task_list->setDueDate($milestone->getDueDate()); $task_list->setScore(config_option('initial score', 50)); $task_list->save(); } } } ApplicationLogs::createLog($project, null, ApplicationLogs::ACTION_ADD, false, true); DB::commit(); flash_success(lang('success add project', $project->getName())); $this->redirectToUrl($project->getPermissionsUrl()); } catch (Exception $e) { tpl_assign('error', $e); DB::rollback(); } // try } // if }