/** to get all the parent vtiger_groups of the specified group * @params $groupId --> Group Id :: Type Integer * @returns updates the parent group in the varibale $parent_groups of the class */ function getAllUserGroups($userid) { $adb = PearDatabase::getInstance(); $log = vglobal('log'); $log->debug("Entering getAllUserGroups(" . $userid . ") method..."); //Retreiving from the user2grouptable $query = "select * from vtiger_users2group where userid=?"; $result = $adb->pquery($query, array($userid)); $num_rows = $adb->num_rows($result); for ($i = 0; $i < $num_rows; $i++) { $now_group_id = $adb->query_result($result, $i, 'groupid'); if (!in_array($now_group_id, $this->user_groups)) { $this->user_groups[] = $now_group_id; } } //Setting the User Role $userRole = fetchUserRole($userid); //Retreiving from the vtiger_user2role $query = "select * from vtiger_group2role where roleid=?"; $result = $adb->pquery($query, array($userRole)); $num_rows = $adb->num_rows($result); for ($i = 0; $i < $num_rows; $i++) { $now_group_id = $adb->query_result($result, $i, 'groupid'); if (!in_array($now_group_id, $this->user_groups)) { $this->user_groups[] = $now_group_id; } } //Retreiving from the user2rs $parentRoles = getParentRole($userRole); $parentRolelist = array(); foreach ($parentRoles as $par_rol_id) { array_push($parentRolelist, $par_rol_id); } array_push($parentRolelist, $userRole); $query = "select * from vtiger_group2rs where roleandsubid in (" . generateQuestionMarks($parentRolelist) . ")"; $result = $adb->pquery($query, array($parentRolelist)); $num_rows = $adb->num_rows($result); for ($i = 0; $i < $num_rows; $i++) { $now_group_id = $adb->query_result($result, $i, 'groupid'); if (!in_array($now_group_id, $this->user_groups)) { $this->user_groups[] = $now_group_id; } } foreach ($this->user_groups as $grp_id) { $focus = new GetParentGroups(); $focus->getAllParentGroups($grp_id); foreach ($focus->parent_groups as $par_grp_id) { if (!in_array($par_grp_id, $this->user_groups)) { $this->user_groups[] = $par_grp_id; } } } $log->debug("Exiting getAllUserGroups method..."); }
/** Creates a file with all the user, user-role,user-profile, user-groups informations * @param $userid -- user id:: Type integer * @returns user_privileges_userid file under the user_privileges directory */ function createUserPrivilegesfile($userid) { global $root_directory; $handle = @fopen($root_directory . 'user_privileges/user_privileges_' . $userid . '.php', "w+"); if ($handle) { $newbuf = ''; $newbuf .= "<?php\n\n"; $newbuf .= "\n"; $newbuf .= "//This is the access privilege file\n"; $user_focus = new Users(); $user_focus->retrieve_entity_info($userid, "Users"); $userInfo = array(); $user_focus->column_fields["id"] = ''; $user_focus->id = $userid; foreach ($user_focus->column_fields as $field => $value_iter) { $userInfo[$field] = $user_focus->{$field}; } if ($user_focus->is_admin == 'on') { $newbuf .= "\$is_admin=true;\n"; $newbuf .= "\n"; $newbuf .= "\$user_info=" . constructSingleStringKeyValueArray($userInfo) . ";\n"; $newbuf .= "\n"; $newbuf .= "?>"; fputs($handle, $newbuf); fclose($handle); return; } else { $newbuf .= "\$is_admin=false;\n"; $newbuf .= "\n"; $globalPermissionArr = getCombinedUserGlobalPermissions($userid); $tabsPermissionArr = getCombinedUserTabsPermissions($userid); //$tabsPermissionArr=getCombinedUserTabsPermissions($userid); $actionPermissionArr = getCombinedUserActionPermissions($userid); $user_role = fetchUserRole($userid); $user_role_info = getRoleInformation($user_role); $user_role_parent = $user_role_info[$user_role][1]; $userGroupFocus = new GetUserGroups(); $userGroupFocus->getAllUserGroups($userid); $subRoles = getRoleSubordinates($user_role); $subRoleAndUsers = getSubordinateRoleAndUsers($user_role); $def_org_share = getDefaultSharingAction(); $parentRoles = getParentRole($user_role); $newbuf .= "\$current_user_roles='" . $user_role . "';\n"; $newbuf .= "\n"; $newbuf .= "\$current_user_parent_role_seq='" . $user_role_parent . "';\n"; $newbuf .= "\n"; $newbuf .= "\$current_user_profiles=" . constructSingleArray(getUserProfile($userid)) . ";\n"; $newbuf .= "\n"; $newbuf .= "\$profileGlobalPermission=" . constructArray($globalPermissionArr) . ";\n"; $newbuf .= "\n"; $newbuf .= "\$profileTabsPermission=" . constructArray($tabsPermissionArr) . ";\n"; $newbuf .= "\n"; $newbuf .= "\$profileActionPermission=" . constructTwoDimensionalArray($actionPermissionArr) . ";\n"; $newbuf .= "\n"; $newbuf .= "\$current_user_groups=" . constructSingleArray($userGroupFocus->user_groups) . ";\n"; $newbuf .= "\n"; $newbuf .= "\$subordinate_roles=" . constructSingleCharArray($subRoles) . ";\n"; $newbuf .= "\n"; $newbuf .= "\$parent_roles=" . constructSingleCharArray($parentRoles) . ";\n"; $newbuf .= "\n"; $newbuf .= "\$subordinate_roles_users=" . constructTwoDimensionalCharIntSingleArray($subRoleAndUsers) . ";\n"; $newbuf .= "\n"; $newbuf .= "\$user_info=" . constructSingleStringKeyValueArray($userInfo) . ";\n"; $newbuf .= "?>"; fputs($handle, $newbuf); fclose($handle); } } }
public function getSameLevelRoles() { $db = PearDatabase::getInstance(); if (!$this->children) { $parentRoles = getParentRole($this->getId()); $currentRoleDepth = $this->getDepth(); $parentRoleString = ''; foreach ($parentRoles as $key => $role) { if (empty($parentRoleString)) { $parentRoleString = $role; } else { $parentRoleString = $parentRoleString . '::' . $role; } } $sql = 'SELECT * FROM vtiger_role WHERE parentrole LIKE ? AND depth = ?'; $params = array($parentRoleString . '::%', $currentRoleDepth); $result = $db->pquery($sql, $params); $noOfRoles = $db->num_rows($result); $roles = array(); for ($i = 0; $i < $noOfRoles; ++$i) { $role = self::getInstanceFromQResult($result, $i); $roles[$role->getId()] = $role; } $this->children = $roles; } return $this->children; }