/**
	 * Add user
	 *
	 * @access public
	 * @param void
	 * @return null
	 */
	function add_user() {
		$max_users = config_option('max_users');
		if ($max_users && (Contacts::count() >= $max_users)) {
			flash_error(lang('maximum number of users reached error'));
			ajx_current("empty");
			return;
		}
		$company = Contacts::findById(get_id('company_id'));
		if (!($company instanceof Contact)) {
			$company = owner_company();
		}

		if (!can_manage_security(logged_user())) {
			flash_error(lang('no access permissions'));
			ajx_current("empty");
			return;
		} // if
		
		$user = new Contact();
		
		$user_data = array_var($_POST, 'user');
		// Populate form fields
		if (!is_array($user_data)) {
			//if it is a new user
			$contact_id = get_id('contact_id');
			$contact = Contacts::findById($contact_id);
			
			if ($contact instanceof Contact) {
				
				if (!is_valid_email($contact->getEmailAddress())){
					ajx_current("empty");
					flash_error(lang("contact email is required to create user"));
					return false;
				}
			
				//if it will be created from a contact
				$user_data = array(
					'username' => $this->generateUserNameFromContact($contact),
					'display_name' => $contact->getFirstname() . $contact->getSurname(),
					'email' => $contact->getEmailAddress('personal'),
					'contact_id' => $contact->getId(),
					'password_generator' => 'random',
					'type' => 'Executive',
					'can_manage_time' => true,
				); // array
				tpl_assign('ask_email', false);
			} else {
				// if it is new, and created from admin interface
				$user_data = array(
					'password_generator' => 'random',
					'company_id' => $company->getId(),
					'timezone' => $company->getTimezone(),
					'create_contact' => true,
					'send_email_notification' => false,
					'type' => 'Executive',
					'can_manage_time' => true,
				);
				tpl_assign('ask_email', true);
			}
			
			// System permissions
			tpl_assign('system_permissions', new SystemPermission());
			
			// Module permissions
			$module_permissions_info = array();
			$all_modules = TabPanels::findAll(array("conditions" => "`enabled` = 1", "order" => "ordering"));
			$all_modules_info = array();
			foreach ($all_modules as $module) {
				$all_modules_info[] = array('id' => $module->getId(), 'name' => lang($module->getTitle()), 'ot' => $module->getObjectTypeId());
			}
			tpl_assign('module_permissions_info', $module_permissions_info);
			tpl_assign('all_modules_info', $all_modules_info);
			
			// Member permissions
			$parameters = permission_form_parameters(0);
			tpl_assign('permission_parameters', $parameters);
			
			// Permission Groups
			$groups = PermissionGroups::getNonPersonalSameLevelPermissionsGroups('`parent_id`,`id` ASC');
			tpl_assign('groups', $groups);
			$roles= SystemPermissions::getAllRolesPermissions();
			tpl_assign('roles', $roles);
			$tabs= TabPanelPermissions::getAllRolesModules();
			tpl_assign('tabs_allowed', $tabs);
			
			
		} // if

		
		tpl_assign('user', $user);
		tpl_assign('company', $company);
		tpl_assign('user_data', $user_data);
		
		//Submit User
		if (is_array(array_var($_POST, 'user'))) {
			if (!array_var($user_data, 'createPersonalProject')) {
				$user_data['personal_project'] = 0;
			}
			try {
				Contacts::validateUser($user_data);
				
				DB::beginWork();
				$user = $this->createUser($user_data, array_var($_POST,'permissions'));
				
				DB::commit();	
				flash_success(lang('success add user', $user->getObjectName()));
				ajx_current("back");
			} catch(Exception $e) {
				DB::rollback();
				ajx_current("empty");
				flash_error($e->getMessage());
			} // try

		} // if

	} // add_user
Exemplo n.º 2
0
 /**
  * Show update permissions page
  *
  * @param void
  * @return null
  */
 function update_permissions()
 {
     $user = Contacts::findById(get_id());
     if (!($user instanceof Contact && $user->isUser()) || $user->getDisabled()) {
         flash_error(lang('user dnx'));
         ajx_current("empty");
         return;
     }
     // if
     if (!$user->canUpdatePermissions(logged_user())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     // if
     $redirect_to = array_var($_GET, 'redirect_to');
     if (trim($redirect_to) == '' || !is_valid_url($redirect_to)) {
         $redirect_to = $user->getCardUserUrl();
     }
     // if
     $sys_permissions_data = array_var($_POST, 'sys_perm');
     if (!is_array($sys_permissions_data)) {
         $pg_id = $user->getPermissionGroupId();
         $parameters = permission_form_parameters($pg_id);
         // Module Permissions
         $module_permissions = TabPanelPermissions::findAll(array("conditions" => "`permission_group_id` = {$pg_id}"));
         $module_permissions_info = array();
         foreach ($module_permissions as $mp) {
             $module_permissions_info[$mp->getTabPanelId()] = 1;
         }
         $all_modules = TabPanels::findAll(array("conditions" => "`enabled` = 1", "order" => "ordering"));
         $all_modules_info = array();
         foreach ($all_modules as $module) {
             $all_modules_info[] = array('id' => $module->getId(), 'name' => lang($module->getTitle()), 'ot' => $module->getObjectTypeId());
         }
         // System Permissions
         $system_permissions = SystemPermissions::findById($pg_id);
         tpl_assign('module_permissions_info', $module_permissions_info);
         tpl_assign('all_modules_info', $all_modules_info);
         tpl_assign('system_permissions', $system_permissions);
         tpl_assign('permission_parameters', $parameters);
         $more_permissions = array();
         Hook::fire('add_user_permissions', $pg_id, $more_permissions);
         tpl_assign('more_permissions', $more_permissions);
         // Permission Groups
         $groups = PermissionGroups::getNonPersonalSameLevelPermissionsGroups('`parent_id`,`id` ASC');
         tpl_assign('groups', $groups);
         $roles = SystemPermissions::getAllRolesPermissions();
         tpl_assign('roles', $roles);
         $tabs = TabPanelPermissions::getAllRolesModules();
         tpl_assign('tabs_allowed', $tabs);
         tpl_assign('guest_groups', PermissionGroups::instance()->getGuestPermissionGroups());
     }
     tpl_assign('user', $user);
     tpl_assign('redirect_to', $redirect_to);
     if (array_var($_POST, 'submitted') == 'submitted') {
         $user_data = array_var($_POST, 'user');
         if (!is_array($user_data)) {
             $user_data = array();
         }
         try {
             DB::beginWork();
             $pg_id = $user->getPermissionGroupId();
             $user->setUserType(array_var($user_data, 'type'));
             $user->save();
             save_permissions($pg_id, $user->isGuest());
             DB::commit();
             flash_success(lang('success user permissions updated'));
             ajx_current("back");
         } catch (Exception $e) {
             DB::rollback();
             flash_error($e->getMessage());
             ajx_current("empty");
         }
     }
     // if
 }
Exemplo n.º 3
0
 function system_modules()
 {
     if (!can_manage_configuration(logged_user())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     ajx_set_no_toolbar();
     $modules = array();
     $other_modules = array();
     $disabled_modules = array();
     // mail
     $mail_info = null;
     if (!Plugins::instance()->isActivePlugin('mail')) {
         $mail_info = array('id' => 'mails-panel', 'name' => lang('email tab'), 'link' => 'http://www.fengoffice.com/web/email.php', 'ico' => 'ico-large-mail');
         $disabled_modules[] = $mail_info;
     }
     /*	$lo_info = array(
     				'id' => 'liquid-office',
     				'name' => lang('liquid office'),
     				'link' => 'https://www.liquid-office.eu/',
     				'ico' => 'ico-large-liquid-office',
     		);
     		$disabled_modules[] = $lo_info;*/
     $tab_panels = TabPanels::findAll(array('conditions' => "id<>'more-panel' AND (plugin_id is NULL OR plugin_id = 0 OR plugin_id IN (SELECT id FROM " . TABLE_PREFIX . "plugins WHERE is_installed > 0))", 'order' => 'ordering'));
     foreach ($tab_panels as $panel) {
         if ($panel->getId() == 'mails-panel' && $mail_info != null) {
             continue;
         }
         $enabled = $panel->getEnabled();
         if ($enabled && $panel->getPluginId() > 0) {
             $plugin = Plugins::findById($panel->getPluginId());
             $enabled = $enabled && $plugin instanceof Plugin && $plugin->isActive();
         }
         $modules[] = array('id' => $panel->getId(), 'name' => lang($panel->getTitle()), 'enabled' => $enabled, 'ico' => str_replace('ico-', 'ico-large-', $panel->getIconCls()), 'hint' => escape_character(lang('system module ' . $panel->getId() . ' hint')));
     }
     // gantt
     $gantt_plugin = Plugins::instance()->findOne(array('conditions' => "name='gantt'"));
     if ($gantt_plugin instanceof Plugin) {
         $gantt_info = array('id' => 'gantt', 'name' => lang('gantt chart'), 'enabled' => $gantt_plugin->isActive(), 'ico' => 'ico-large-gantt-module', 'hint' => escape_character(lang('system module gantt hint')));
         $other_modules[] = $gantt_info;
     }
     /*		
     		// member_custom_properties
     		$member_custom_properties_plugin = Plugins::instance()->findOne(array('conditions' => "name='member_custom_properties'"));
     		if ($member_custom_properties_plugin instanceof Plugin) {
     			$member_custom_properties_plugin = array(
     					'id' => 'member_custom_properties',
     					'name' => lang('member_custom_properties'),
     					'enabled' => $member_custom_properties_plugin->isActive(),
     					'ico' => 'ico-large-custom-properties',
     					'hint' => str_replace("'", "\'", ""),
     			);
     			$other_modules[] = $member_custom_properties_plugin;
     		}
     */
     /*		
     	// gantt
     	$gantt_info = array(
     			'id' => 'gantt',
     			'name' => lang('gantt chart'),
     			'ico' => 'ico-large-gantt-module',
     			'hint' => str_replace("'", "\'", lang('system module gantt hint')),
     	);
     	if (!Plugins::instance()->isActivePlugin('gantt')) {
     		if (Plugins::instance()->isActivePlugin('crpm')) {
     			$disabled_modules[] = $gantt_info;
     		}
     	} else {
     		$other_modules[] = $gantt_info;
     	}
     	
     	// expenses
     	$expenses_info = array(
     			'id' => 'expenses',
     			'name' => lang('expenses'),
     			'ico' => 'ico-large-expenses-module',
     			'hint' => str_replace("'", "\'", lang('system module expenses-panel hint')),
     	);
     	if (!Plugins::instance()->isActivePlugin('expenses')) {
     		if (Plugins::instance()->isActivePlugin('crpm')) {
     			$disabled_modules[] = $expenses_info;
     		}
     	}
     	// objectives
     	$expenses_info = array(
     			'id' => 'objectives',
     			'name' => lang('objectives'),
     			'ico' => 'ico-large-objectives-module',
     			'hint' => str_replace("'", "\'", lang('system module objectives-panel hint')),
     	);
     	if (!Plugins::instance()->isActivePlugin('objectives')) {
     		if (Plugins::instance()->isActivePlugin('crpm')) {
     			$disabled_modules[] = $expenses_info;
     		}
     	}
     */
     $active_dimensions_tmp = Dimensions::findAll(array('order' => 'default_order'));
     $active_dimensions = array();
     foreach ($active_dimensions_tmp as $dim) {
         if ($dim->getCode() == 'feng_persons') {
             continue;
         }
         $dname = $dim->getName();
         $active_dimensions[$dim->getCode()] = array('id' => $dim->getId(), 'name' => $dname, 'code' => $dim->getCode(), 'ico' => 'ico-large-' . $dim->getCode(), 'hint' => lang('system dimension ' . $dim->getCode() . ' hint'));
     }
     $dimensions_set = array_keys($active_dimensions);
     $other_dimensions = array();
     if (!isset($active_dimensions['workspaces'])) {
         $other_dimensions[] = array('name' => lang('workspaces'), 'ico' => 'ico-large-workspaces', 'hint' => lang('system dimension workspaces hint'));
     }
     if (!isset($active_dimensions['tags'])) {
         $other_dimensions[] = array('name' => lang('tags'), 'ico' => 'ico-large-tags', 'hint' => lang('system dimension tags hint'));
     }
     if (!isset($active_dimensions['customer_project'])) {
         if (Plugins::instance()->isActivePlugin('crpm')) {
             $other_dimensions[] = array('name' => lang('customer_project'), 'ico' => 'ico-large-customer_project', 'hint' => lang('system dimension customer_project hint'));
         }
     }
     $user_dimension_ids = config_option('enabled_dimensions');
     tpl_assign("modules", $modules);
     tpl_assign("other_modules", $other_modules);
     tpl_assign("disabled_modules", $disabled_modules);
     tpl_assign('active_dimensions', $active_dimensions);
     tpl_assign('other_dimensions', $other_dimensions);
     tpl_assign('user_dimension_ids', $user_dimension_ids);
 }
Exemplo n.º 4
0
 /**
  * Edit group
  *
  * @param void
  * @return null
  */
 function edit()
 {
     $this->setTemplate('add');
     if (!can_manage_security(logged_user())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     // if
     $group = PermissionGroups::findById(get_id());
     if (!$group instanceof PermissionGroup) {
         flash_error(lang('group dnx'));
         $this->redirectTo('administration', 'groups');
     }
     // if
     $group_data = array_var($_POST, 'group');
     if (!is_array($group_data)) {
         $pg_id = $group->getId();
         $parameters = permission_form_parameters($pg_id);
         // Module Permissions
         $module_permissions = TabPanelPermissions::findAll(array("conditions" => "`permission_group_id` = {$pg_id}"));
         $module_permissions_info = array();
         foreach ($module_permissions as $mp) {
             $module_permissions_info[$mp->getTabPanelId()] = 1;
         }
         $all_modules = TabPanels::findAll(array("conditions" => "`enabled` = 1", "order" => "ordering"));
         $all_modules_info = array();
         foreach ($all_modules as $module) {
             $all_modules_info[] = array('id' => $module->getId(), 'name' => lang($module->getTitle()), 'ot' => $module->getObjectTypeId());
         }
         // System Permissions
         $system_permissions = SystemPermissions::findById($pg_id);
         tpl_assign('module_permissions_info', $module_permissions_info);
         tpl_assign('all_modules_info', $all_modules_info);
         tpl_assign('system_permissions', $system_permissions);
         tpl_assign('permission_parameters', $parameters);
         // users
         $group_users = array();
         $cpgs = ContactPermissionGroups::findAll(array("conditions" => "`permission_group_id` = {$pg_id}"));
         foreach ($cpgs as $cpg) {
             $group_users[] = $cpg->getContactId();
         }
         tpl_assign('groupUserIds', $group_users);
         tpl_assign('users', Contacts::getAllUsers());
         tpl_assign('pg_id', $group->getId());
         tpl_assign('group', $group);
         tpl_assign('group_data', array('name' => $group->getName()));
         add_page_action(lang('delete'), "javascript:if(confirm(lang('confirm delete group'))) og.openLink('" . $group->getDeleteUrl() . "');", 'ico-trash', null, null, true);
     } else {
         try {
             $group->setFromAttributes($group_data);
             DB::beginWork();
             $group->save();
             // set permissions
             $pg_id = $group->getId();
             //save_permissions($pg_id);
             $gr_users = $group->getUsers();
             $gr_users_ids = array();
             if ($post_users = array_var($_POST, 'user')) {
                 foreach ($post_users as $user_id => $val) {
                     if ($val == '1' && is_numeric($user_id)) {
                         $gr_users_ids[] = $user_id;
                     }
                 }
             }
             foreach ($gr_users as $us) {
                 if (!in_array($us->getId(), $gr_users_ids)) {
                     $gr_users_ids[] = $us->getId();
                 }
             }
             // save users
             ContactPermissionGroups::delete("`permission_group_id` = {$pg_id}");
             if ($users = array_var($_POST, 'user')) {
                 foreach ($users as $user_id => $val) {
                     if ($val == '1' && is_numeric($user_id) && Contacts::findById($user_id) instanceof Contact) {
                         $cpg = new ContactPermissionGroup();
                         $cpg->setPermissionGroupId($pg_id);
                         $cpg->setContactId($user_id);
                         $cpg->save();
                     }
                 }
             }
             //ApplicationLogs::createLog($group, 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);
             return;
         }
         try {
             save_user_permissions_background(logged_user(), $pg_id, false, $gr_users_ids);
         } catch (Exception $e) {
             tpl_assign('error', $e);
         }
     }
 }
Exemplo n.º 5
0
 } else {
     $pg_id = $contact->getPermissionGroupId();
     tpl_assign('user', $contact);
 }
 $parameters = permission_form_parameters($pg_id);
 if ($contact->isNew()) {
     $parameters['root_permissions'] = $root_permissions;
     $parameters['member_permissions'] = $member_permissions;
 }
 // Module Permissions
 $module_permissions = TabPanelPermissions::findAll(array("conditions" => "`permission_group_id` = {$pg_id}"));
 $module_permissions_info = array();
 foreach ($module_permissions as $mp) {
     $module_permissions_info[$mp->getTabPanelId()] = 1;
 }
 $all_modules = TabPanels::findAll(array("conditions" => "`enabled` = 1", "order" => "ordering"));
 $all_modules_info = array();
 foreach ($all_modules as $module) {
     $all_modules_info[] = array('id' => $module->getId(), 'name' => lang($module->getTitle()), 'ot' => $module->getObjectTypeId());
 }
 // System Permissions
 $system_permissions = SystemPermissions::findById($pg_id);
 tpl_assign('module_permissions_info', $module_permissions_info);
 tpl_assign('all_modules_info', $all_modules_info);
 if (!$system_permissions instanceof SystemPermission) {
     $system_permissions = new SystemPermission();
 }
 tpl_assign('system_permissions', $system_permissions);
 tpl_assign('permission_parameters', $parameters);
 $more_permissions = array();
 Hook::fire('add_user_permissions', $pg_id, $more_permissions);