/** 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);
        }
    }
}
Example #2
0
/**
 * this function returns all the assigned picklist values for the given tablename for the given roleid
 * @param string $tableName - the picklist tablename
 * @param integer $roleid - the roleid of the role for which you want data
 * @param object $adb - the peardatabase object
 * @return array $val - the assigned picklist values in array format
 */
function getAssignedPicklistValues($tableName, $roleid, $adb, $lang = array())
{
    static $cache = array();
    $cacheId = $tableName . '#' . $roleid;
    if (isset($cache[$cacheId])) {
        return $cache[$cacheId];
    }
    $arr = array();
    $sub = getSubordinateRoleAndUsers($roleid, false);
    $subRoles = array($roleid);
    $subRoles = array_merge($subRoles, array_keys($sub));
    $sql = "select picklistid from vtiger_picklist where name = ?";
    $result = $adb->pquery($sql, array($tableName));
    if ($adb->num_rows($result)) {
        $picklistid = $adb->query_result($result, 0, "picklistid");
        $roleids = array();
        foreach ($subRoles as $role) {
            $roleids[] = $role;
        }
        $sql = "SELECT distinct " . $adb->sql_escape_string($tableName) . " FROM " . $adb->sql_escape_string("vtiger_{$tableName}") . " inner join vtiger_role2picklist on " . $adb->sql_escape_string("vtiger_{$tableName}") . ".picklist_valueid=vtiger_role2picklist.picklistvalueid" . " and roleid in (" . generateQuestionMarks($roleids) . ") order by sortid";
        $result = $adb->pquery($sql, $roleids);
        $count = $adb->num_rows($result);
        if ($count) {
            while ($resultrow = $adb->fetch_array($result)) {
                $pick_val = decode_html($resultrow[$tableName]);
                //$pick_val = decode_html($pick_val);  // we have to do it twice for it to work on listview!!
                if ($lang[$pick_val] != '') {
                    $arr[$pick_val] = $lang[$pick_val];
                } else {
                    $arr[$pick_val] = $pick_val;
                }
            }
        }
    }
    // END
    $cache[$cacheId] = $arr;
    return $arr;
}
Example #3
0
/**
 * this function returns all the assigned picklist values for the given tablename for the given roleid
 * @param string $tableName - the picklist tablename
 * @param integer $roleid - the roleid of the role for which you want data
 * @param object $adb - the peardatabase object
 * @return array $val - the assigned picklist values in array format
 */
function getAssignedPicklistValues($tableName, $roleid, $adb, $lang = array())
{
    $cache = Vtiger_Cache::getInstance();
    if ($cache->hasAssignedPicklistValues($tableName, $roleid)) {
        return $cache->getAssignedPicklistValues($tableName, $roleid);
    } else {
        $arr = array();
        $sql = "select picklistid from vtiger_picklist where name = ?";
        $result = $adb->pquery($sql, array($tableName));
        if ($adb->num_rows($result)) {
            $picklistid = $adb->query_result($result, 0, "picklistid");
            $sub = getSubordinateRoleAndUsers($roleid);
            $subRoles = array($roleid);
            $subRoles = array_merge($subRoles, array_keys($sub));
            $roleids = array();
            foreach ($subRoles as $role) {
                $roleids[] = $role;
            }
            $sql = 'SELECT distinct ' . $adb->sql_escape_string($tableName, true) . ' FROM ' . $adb->sql_escape_string("vtiger_{$tableName}", true) . ' inner join vtiger_role2picklist on ' . $adb->sql_escape_string("vtiger_{$tableName}", true) . '.picklist_valueid=vtiger_role2picklist.picklistvalueid' . ' and roleid in (' . $adb->generateQuestionMarks($roleids) . ') order by sortid';
            $result = $adb->pquery($sql, $roleids);
            $count = $adb->num_rows($result);
            if ($count) {
                while ($resultrow = $adb->fetch_array($result)) {
                    /** Earlier we used to save picklist values by encoding it. Now, we are directly saving those(getRaw()).
                     *  If value in DB is like "test1 &amp; test2" then $abd->fetch_array() is giving it as
                     *  "test1 &amp;$amp; test2" which we should decode two time to get result
                     */
                    $pick_val = decode_html(decode_html($resultrow[$tableName]));
                    if ($lang[$pick_val] != '') {
                        $arr[$pick_val] = $lang[$pick_val];
                    } else {
                        $arr[$pick_val] = $pick_val;
                    }
                }
            }
        }
        // END
        $cache->setAssignedPicklistValues($tableName, $roleid, $arr);
        return $arr;
    }
}
/**
 * this function returns all the assigned picklist values for the given tablename for the given roleid
 * @param string $tableName - the picklist tablename
 * @param integer $roleid - the roleid of the role for which you want data
 * @param object $adb - the peardatabase object
 * @return array $val - the assigned picklist values in array format
 */
function getAssignedPicklistValues($tableName, $roleid, $adb)
{
    $arr = array();
    $sub = getSubordinateRoleAndUsers($roleid);
    $subRoles = array($roleid);
    $subRoles = array_merge($subRoles, array_keys($sub));
    $sql = "select picklistid from vtiger_picklist where name = ?";
    $result = $adb->pquery($sql, array($tableName));
    if ($adb->num_rows($result)) {
        $picklistid = $adb->query_result($result, 0, "picklistid");
        $roleids = array();
        foreach ($subRoles as $role) {
            $roleids[] = $role;
        }
        $sql = "SELECT distinct " . $adb->sql_escape_string($tableName) . " FROM " . $adb->sql_escape_string("vtiger_{$tableName}") . " inner join vtiger_role2picklist on " . $adb->sql_escape_string("vtiger_{$tableName}") . ".picklist_valueid=vtiger_role2picklist.picklistvalueid" . " and roleid in (" . generateQuestionMarks($roleids) . ") order by sortid";
        $result = $adb->pquery($sql, $roleids);
        $count = $adb->num_rows($result);
        if ($count) {
            while ($resultrow = $adb->fetch_array($result)) {
                $arr[] = $resultrow[$tableName];
            }
        }
    }
    // END
    return $arr;
}
Example #5
0
require_once 'Smarty_setup.php';
require_once "data/Tracker.php";
require_once 'include/logging.php';
require_once 'include/utils/utils.php';
require_once "include/Zend/Json.php";
// ITS4YOU-CR SlOl 20.12.2010 R4U singlerow
require_once 'modules/ITS4YouReports/ITS4YouReports.php';
$return_html = "";
$n_c = 3;
$n_r = 5;
$n = $n_c * $n_r;
if ($_REQUEST["sel_fields"]) {
    global $current_user;
    $adb = PearDatabase::getInstance();
    $roleid = $current_user->roleid;
    $sub = getSubordinateRoleAndUsers($roleid);
    list($s_tablename, $fieldname, $s_module_field_label_str) = explode(":", $_REQUEST["currField"]);
    $s_module_field_arr = explode("_", $s_module_field_label_str);
    require_once 'modules/PickList/PickListUtils.php';
    $picklistValues = getAssignedPicklistValues($fieldname, $roleid, $adb);
    $valueArr = explode("|##|", $value);
    $pickcount = 0;
    $sel_fields = array();
    if (!empty($picklistValues)) {
        foreach ($picklistValues as $order => $pickListValue) {
            if (in_array(trim($pickListValue), array_map("trim", $valueArr))) {
                $chk_val = "selected";
                $pickcount++;
            } else {
                $chk_val = '';
            }