/** gives the role info, role profile info and role user info details in an array for the specified role id * @param $roleid -- role id:: Type integer * @returns $return_data -- array contains role info, role profile info and role user info. This array is used to construct the detail view for the specified role id :: Type varchar * */ function getStdOutput($roleid) { //Retreiving the related vtiger_profiles $roleProfileArr = getRoleRelatedProfiles($roleid); //Retreving the related vtiger_users $roleUserArr = getRoleUsers($roleid); //Constructing the Profile list $profileinfo = array(); foreach ($roleProfileArr as $profileId => $profileName) { $profileinfo[] = $profileId; $profileinfo[] = $profileName; $profileList .= '<a href="index.php?module=Settings&action=profilePrivileges&profileid=' . $profileId . '">' . $profileName . '</a>'; } $profileinfo = array_chunk($profileinfo, 2); //Constructing the Users List $userinfo = array(); foreach ($roleUserArr as $userId => $userName) { $userinfo[] = $userId; $userinfo[] = $userName; $userList .= '<a href="index.php?module=Settings&action=DetailView&record=' . $userId . '">' . $userName . '</a>'; } $userinfo = array_chunk($userinfo, 2); //Check for Current User global $current_user; $current_role = fetchUserRole($current_user->id); $return_data = array('profileinfo' => $profileinfo, 'userinfo' => $userinfo); return $return_data; }
/** 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..."); }
/** * this function takes in an array of values for an user and sanitizes it for export * @param array $arr - the array of values */ function sanitizeValues($arr) { global $current_user, $adb; $roleid = fetchUserRole($current_user->id); foreach ($arr as $fieldlabel => &$value) { $fieldInfo = $this->fieldsArr[$fieldlabel]; $uitype = $fieldInfo['uitype']; $fieldname = $fieldInfo['fieldname']; if ($uitype == 15 || $uitype == 16 || $uitype == 33) { //picklists if (empty($this->picklistValues[$fieldname])) { $this->picklistValues[$fieldname] = getAssignedPicklistValues($fieldname, $roleid, $adb); } $value = trim($value); } elseif ($uitype == 10) { //have to handle uitype 10 $value = trim($value); if (!empty($value)) { $parent_module = getSalesEntityType($value); $displayValueArray = getEntityName($parent_module, $value); if (!empty($displayValueArray)) { foreach ($displayValueArray as $k => $v) { $displayValue = $v; } } if (!empty($parent_module) && !empty($displayValue)) { $value = $parent_module . "::::" . $displayValue; } else { $value = ""; } } else { $value = ''; } } } return $arr; }
/** * this function takes in an array of values for an user and sanitizes it for export * @param array $arr - the array of values */ function sanitizeValues($arr) { global $current_user, $adb; $roleid = fetchUserRole($current_user->id); $decimal = $current_user->currency_decimal_separator; $numsep = $current_user->currency_grouping_separator; foreach ($arr as $fieldlabel => &$value) { $fieldInfo = $this->fieldsArr[$fieldlabel]; $uitype = $fieldInfo['uitype']; $fieldname = $fieldInfo['fieldname']; if ($uitype == 15 || $uitype == 16 || $uitype == 33) { //picklists if (empty($this->picklistValues[$fieldname])) { $this->picklistValues[$fieldname] = getAssignedPicklistValues($fieldname, $roleid, $adb); } $value = trim($value); } elseif ($uitype == 10) { //have to handle uitype 10 $value = trim($value); if (!empty($value)) { $parent_module = getSalesEntityType($value); $displayValueArray = getEntityName($parent_module, $value); if (!empty($displayValueArray)) { foreach ($displayValueArray as $k => $v) { $displayValue = $v; } } if (!empty($parent_module) && !empty($displayValue)) { $value = $parent_module . "::::" . $displayValue; } else { $value = ""; } } else { $value = ''; } } elseif ($uitype == 71 || $uitype == 72) { $value = CurrencyField::convertToUserFormat($value, null, true); } elseif ($uitype == 7 || $fieldInfo['typeofdata'] == 'N~O' || $uitype == 9) { $value = number_format($value, 2, $decimal, $numsep); } } return $arr; }
/** 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); } } }
/** This function is to retreive the vtiger_profiles associated with the the specified user * It takes the following input parameters: * $userid -- The User Id:: Type Integer * This function will return the vtiger_profiles associated to the specified vtiger_users in an Array in the following format: * $userProfileArray=(profileid1,profileid2,profileid3,...,profileidn); */ function getUserProfile($userId) { $log = vglobal('log'); $log->debug("Entering getUserProfile(" . $userId . ") method ..."); $adb = PearDatabase::getInstance(); $roleId = fetchUserRole($userId); $profArr = array(); $sql1 = "select profileid from vtiger_role2profile where roleid=?"; $result1 = $adb->pquery($sql1, array($roleId)); $num_rows = $adb->num_rows($result1); for ($i = 0; $i < $num_rows; $i++) { $profileid = $adb->query_result($result1, $i, "profileid"); $profArr[] = $profileid; } $log->debug("Exiting getUserProfile method ..."); return $profArr; }
function getUserIDS($viewscope = "all_to_me") { global $log; $log->debug("Entering getUserIDS() method ..."); global $current_user; if (empty($viewscope)) { $viewscope = "all_to_me"; } $key = "sqluserids_" . $viewscope . "_" . $current_user->id; $userIDS = getSqlCacheData($key); if (!$userIDS) { global $adb; $sec_query = ""; $userIDS = ''; if ($viewscope == "all_to_me") { $sec_query = "select id as userid from ec_users where status='Active'"; $result = $adb->getList($sec_query); $userIDS .= '('; $i = 0; foreach ($result as $row) { $userid = $row['userid']; if ($i != 0) { $userIDS .= ', '; } $userIDS .= $userid; $i++; } if ($userIDS != '(') { $userIDS .= ', ' . $current_user->id; } else { $userIDS .= $current_user->id; } $userIDS .= ')'; } elseif ($viewscope == "sub_user") { if (!isset($current_user_parent_role_seq) || $current_user_parent_role_seq == "") { $current_user_parent_role_seq = fetchUserRole($current_user->id); } $sec_query = "select ec_user2role.userid from ec_user2role inner join ec_users on ec_users.id=ec_user2role.userid inner join ec_role on ec_role.roleid=ec_user2role.roleid where ec_role.parentrole like '%" . $current_user_parent_role_seq . "::%'"; $result = $adb->getList($sec_query); $userIDS .= '('; $i = 0; foreach ($result as $row) { $userid = $row['userid']; if ($i != 0) { $userIDS .= ', '; } $userIDS .= $userid; $i++; } $userIDS .= ')'; } elseif ($viewscope == "current_user") { $userIDS .= '(' . $current_user->id; $userIDS .= ')'; } elseif ($viewscope == "current_group") { $sec_query .= "select ec_users2group.userid from ec_users2group where ec_users2group.groupid in " . getCurrentUserGroupList() . ""; $result = $adb->getList($sec_query); $userIDS .= '('; $i = 0; foreach ($result as $row) { $userid = $row['userid']; if ($i != 0) { $userIDS .= ', '; } $userIDS .= $userid; $i++; } $userIDS .= ')'; } else { $userIDS .= '(' . $viewscope . ')'; } setSqlCacheData($key, $userIDS); } if ($userIDS == "()") { $userIDS = "(-1)"; } $log->debug("Exiting getUserIDS method ..."); return $userIDS; }
function GetPicklistValues($username, $sessionid, $tablename) { global $current_user, $log, $adb; if (!validateSession($username, $sessionid)) { return null; } require_once "modules/Users/Users.php"; $seed_user = new Users(); $user_id = $seed_user->retrieve_user_id($username); $current_user = $seed_user; $current_user->retrieve_entity_info($user_id, 'Users'); require_once "include/utils/UserInfoUtil.php"; $roleid = fetchUserRole($user_id); checkFileAccessForInclusion('user_privileges/user_privileges_' . $current_user->id . '.php'); require 'user_privileges/user_privileges_' . $current_user->id . '.php'; if ($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0) { $query = "select " . $adb->sql_escape_string($tablename) . " from vtiger_" . $adb->sql_escape_string($tablename); $result1 = $adb->pquery($query, array()); for ($i = 0; $i < $adb->num_rows($result1); $i++) { $output[$i] = decode_html($adb->query_result($result1, $i, $tablename)); } } else { if (isPermitted("HelpDesk", "EditView") == "yes" && CheckFieldPermission($tablename, 'HelpDesk') == 'true') { $query = "select " . $adb->sql_escape_string($tablename) . " from vtiger_" . $adb->sql_escape_string($tablename) . " inner join vtiger_role2picklist on vtiger_role2picklist.picklistvalueid = vtiger_" . $adb->sql_escape_string($tablename) . ".picklist_valueid where roleid=? and picklistid in (select picklistid from vtiger_" . $adb->sql_escape_string($tablename) . " ) order by sortid"; $result1 = $adb->pquery($query, array($roleid)); for ($i = 0; $i < $adb->num_rows($result1); $i++) { $output[$i] = decode_html($adb->query_result($result1, $i, $tablename)); } } else { $output[] = 'Not Accessible'; } } return $output; }
/** * Function creates HTML to display number of Events, Todos and pending list in calendar under header(Eg:Total Events : 5, 2 Pending / Total To Dos: 4, 1 Pending) * @param array $cal_arr - collection of objects and strings * @param string $viewBox - string 'listview' or 'hourview'. if 'listview' means Events ListView.if 'hourview' means Events HourView. */ function get_cal_header_data(&$cal_arr, $viewBox, $subtab) { global $mod_strings, $cal_log, $current_user, $adb, $theme; $cal_log->debug("Entering get_cal_header_data() method..."); global $current_user, $app_strings; $date_format = $current_user->date_format; $format = $cal_arr['calendar']->hour_format; $hour_startat = timeString(array('hour' => date('H:i', time() + 5 * 60), 'minute' => 0), '24'); $hour_endat = timeString(array('hour' => date('H:i', time() + 60 * 60), 'minute' => 0), '24'); $time_arr = getaddEventPopupTime($hour_startat, $hour_endat, $format); $temp_ts = $cal_arr['calendar']->date_time->ts; //To get date in user selected format $temp_date = $date_format == 'dd-mm-yyyy' ? date('d-m-Y', $temp_ts) : ($date_format == 'mm-dd-yyyy' ? date('m-d-Y', $temp_ts) : ($date_format == 'yyyy-mm-dd' ? date('Y-m-d', $temp_ts) : '')); if ($current_user->column_fields['is_admin'] == 'on') { $Res = $adb->pquery("select * from vtiger_activitytype", array()); } else { $roleid = $current_user->roleid; $subrole = getRoleSubordinates($roleid); if (count($subrole) > 0) { $roleids = $subrole; array_push($roleids, $roleid); } else { $roleids = $roleid; } if (count($roleids) > 1) { $Res = $adb->pquery("select distinct activitytype from vtiger_activitytype inner join vtiger_role2picklist on vtiger_role2picklist.picklistvalueid = vtiger_activitytype.picklist_valueid where roleid in (" . generateQuestionMarks($roleids) . ") and picklistid in (select picklistid from vtiger_activitytype) order by sortid asc", array($roleids)); } else { $Res = $adb->pquery("select distinct activitytype from vtiger_activitytype inner join vtiger_role2picklist on vtiger_role2picklist.picklistvalueid = vtiger_activitytype.picklist_valueid where roleid = ? and picklistid in (select picklistid from vtiger_activitytype) order by sortid asc", array($roleid)); } } $eventlist = ''; for ($i = 0; $i < $adb->num_rows($Res); $i++) { $eventlist .= $adb->query_result($Res, $i, 'activitytype') . ";"; } $headerdata = ""; $headerdata .= "\n\t\t\t<div style='display: block;' id='mnuTab'>\n\t\t\t<form name='EventViewOption' method='POST' action='index.php' style='display:inline;'>\n\t\t\t<input type='hidden' id='complete_view' name='complete_view' value='' />\n\t\t\t<table align='center' border='0' cellpadding='5' cellspacing='0' width='98%'>\n\t\t\t<tr><td colspan='3'> </td></tr>"; if (isPermitted("Calendar", "EditView") == "yes") { $headerdata .= "<tr>\n\t\t\t\t<td>\n\t\t\t\t<table><tr><td class='calAddButton' style='cursor:pointer;height:30px' align='center' width='15%' onMouseOver='fnAddEvent(this,\"addEventDropDown\",\"" . $temp_date . "\",\"" . $temp_date . "\",\"" . $time_arr['starthour'] . "\",\"" . $time_arr['startmin'] . "\",\"" . $time_arr['startfmt'] . "\",\"" . $time_arr['endhour'] . "\",\"" . $time_arr['endmin'] . "\",\"" . $time_arr['endfmt'] . "\",\"" . $viewBox . "\",\"" . $subtab . "\",\"" . $eventlist . "\");'>\n\t\t\t\t\t" . $mod_strings['LBL_ADD'] . "\n\t\t\t\t\t<img src='" . vtiger_imageurl('menuDnArrow.gif', $theme) . "' style='padding-left: 5px;' border='0'>\n\t\t\t\t</td></tr></table> </td>"; } else { $headerdata .= "<tr><td> </td>"; } $headerdata .= "<td align='center' width='43%'><span id='total_activities'>"; //USER SELECT CUSTOMIZATION $headerdata .= getEventInfo($cal_arr, 'listcnt'); $headerdata .= "</span></td>\n\t\t\t\t<td align='center' width='40%'><table border=0 cellspacing=0 cellpadding=2><tr><td class=small><b>" . $mod_strings['LBL_VIEW'] . " : </b></td><td>"; //USER SELECT CUSTOMIZATION $view_options = getEventViewOption($cal_arr, $viewBox); // User Select Customization $view_options .= calendarview_getUserSelectOptions(calendarview_getSelectedUserId()); // END $groups_view = "<span><b>Group : </b></span><select name=\"f_groups\">"; $groups_view .= "<option value=\"default_view\">-- none --</option>"; $user_groups = array(); $currrentUserid = calendarview_getSelectedUserId(); //Retreiving from the user2grouptable $query = "select vtiger_groups.groupname from vtiger_users2group\n\t\tleft join vtiger_groups on (vtiger_users2group.groupid = vtiger_groups.groupid)\n\t\twhere vtiger_users2group.userid =?"; $result = $adb->pquery($query, array($currrentUserid)); $num_rows = $adb->num_rows($result); for ($i = 0; $i < $num_rows; $i++) { $user_groups[] = $adb->query_result($result, $i, 'groupname'); $groups_name = $adb->query_result($result, $i, 'groupname'); $groups_view .= "<option value=\"{$i}\">{$groups_name}</option>"; } //Setting the User Role $currentUserRole = fetchUserRole($currrentUserid); //Retreiving from the vtiger_user2role $query = "select vtiger_groups.groupname from vtiger_group2role\n\t\tleft join vtiger_groups on (vtiger_group2role.groupid = vtiger_groups.groupid)\n\t\twhere vtiger_group2role.roleid =?"; $result = $adb->pquery($query, array($currentUserRole)); $num_rows = $adb->num_rows($result); for ($i = 0; $i < $num_rows; $i++) { $groups_name = $adb->query_result($result, $i, 'groupname'); if (!in_array($groups_name, $user_groups)) { $groups_view .= "<option value=\"{$i}\">{$groups_name}</option>"; } } $groups_view .= "</select>"; $groups_view .= $now_group_id; $headerdata .= $view_options . $groups_view . "</td></tr></table>\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t</table></form>"; echo $headerdata; $cal_log->debug("Exiting get_cal_header_data() method..."); }