/** Gives an array which contains the information for what all roles, groups and user's related module data that is to be shared  for the specified parent module and shared module 
 * @param $par_mod -- parent module name:: Type varchar
 * @param $share_mod -- shared module name:: Type varchar
 * @param $userid -- user id:: Type integer
 * @param $def_org_share -- default organization sharing permission array:: Type array
 * @param $mod_sharingrule_members -- Sharing Rule Members array:: Type array
 * @param $$mod_share_read_per -- Sharing Module Read Permission array:: Type array
 * @param $$mod_share_write_per -- Sharing Module Write Permission array:: Type array
 * @returns $related_mod_sharing_permission; -- array which contains the id of roles,group and users related module data to be shared 
 */
function getRelatedModuleSharingArray($par_mod, $share_mod, $mod_sharingrule_members, $mod_share_read_per, $mod_share_write_per, $def_org_share)
{
    global $adb;
    $related_mod_sharing_permission = array();
    $mod_share_read_permission = array();
    $mod_share_write_permission = array();
    $mod_share_read_permission['ROLE'] = array();
    $mod_share_write_permission['ROLE'] = array();
    $mod_share_read_permission['GROUP'] = array();
    $mod_share_write_permission['GROUP'] = array();
    $par_mod_id = getTabid($par_mod);
    $share_mod_id = getTabid($share_mod);
    if ($def_org_share[$share_mod_id] == 3 || $def_org_share[$share_mod_id] == 0) {
        $role_read_per = array();
        $role_write_per = array();
        $grp_read_per = array();
        $grp_write_per = array();
        foreach ($mod_sharingrule_members as $sharingid => $sharingInfoArr) {
            $query = "select vtiger_datashare_relatedmodule_permission.* from vtiger_datashare_relatedmodule_permission inner join vtiger_datashare_relatedmodules on vtiger_datashare_relatedmodules.datashare_relatedmodule_id=vtiger_datashare_relatedmodule_permission.datashare_relatedmodule_id where vtiger_datashare_relatedmodule_permission.shareid=? and vtiger_datashare_relatedmodules.tabid=? and vtiger_datashare_relatedmodules.relatedto_tabid=?";
            $result = $adb->pquery($query, array($sharingid, $par_mod_id, $share_mod_id));
            $share_permission = $adb->query_result($result, 0, 'permission');
            foreach ($sharingInfoArr as $shareType => $shareEntArr) {
                foreach ($shareEntArr as $key => $shareEntId) {
                    if ($shareType == 'ROLE') {
                        if ($share_permission == 1) {
                            if ($def_org_share[$share_mod_id] == 3) {
                                if (!array_key_exists($shareEntId, $role_read_per)) {
                                    if (array_key_exists($shareEntId, $mod_share_read_per['ROLE'])) {
                                        $share_role_users = $mod_share_read_per['ROLE'][$shareEntId];
                                    } elseif (array_key_exists($shareEntId, $mod_share_write_per['ROLE'])) {
                                        $share_role_users = $mod_share_write_per['ROLE'][$shareEntId];
                                    } else {
                                        $share_role_users = getRoleUserIds($shareEntId);
                                    }
                                    $role_read_per[$shareEntId] = $share_role_users;
                                }
                            }
                            if (!array_key_exists($shareEntId, $role_write_per)) {
                                if (array_key_exists($shareEntId, $mod_share_read_per['ROLE'])) {
                                    $share_role_users = $mod_share_read_per['ROLE'][$shareEntId];
                                } elseif (array_key_exists($shareEntId, $mod_share_write_per['ROLE'])) {
                                    $share_role_users = $mod_share_write_per['ROLE'][$shareEntId];
                                } else {
                                    $share_role_users = getRoleUserIds($shareEntId);
                                }
                                $role_write_per[$shareEntId] = $share_role_users;
                            }
                        } elseif ($share_permission == 0 && $def_org_share[$share_mod_id] == 3) {
                            if (!array_key_exists($shareEntId, $role_read_per)) {
                                if (array_key_exists($shareEntId, $mod_share_read_per['ROLE'])) {
                                    $share_role_users = $mod_share_read_per['ROLE'][$shareEntId];
                                } elseif (array_key_exists($shareEntId, $mod_share_write_per['ROLE'])) {
                                    $share_role_users = $mod_share_write_per['ROLE'][$shareEntId];
                                } else {
                                    $share_role_users = getRoleUserIds($shareEntId);
                                }
                                $role_read_per[$shareEntId] = $share_role_users;
                            }
                        }
                    } elseif ($shareType == 'GROUP') {
                        if ($share_permission == 1) {
                            if ($def_org_share[$share_mod_id] == 3) {
                                if (!array_key_exists($shareEntId, $grp_read_per)) {
                                    if (array_key_exists($shareEntId, $mod_share_read_per['GROUP'])) {
                                        $share_grp_users = $mod_share_read_per['GROUP'][$shareEntId];
                                    } elseif (array_key_exists($shareEntId, $mod_share_write_per['GROUP'])) {
                                        $share_grp_users = $mod_share_write_per['GROUP'][$shareEntId];
                                    } else {
                                        $focusGrpUsers = new GetGroupUsers();
                                        $focusGrpUsers->getAllUsersInGroup($shareEntId);
                                        $share_grp_users = $focusGrpUsers->group_users;
                                        foreach ($focusGrpUsers->group_subgroups as $subgrpid => $subgrpusers) {
                                            if (!array_key_exists($subgrpid, $grp_read_per)) {
                                                $grp_read_per[$subgrpid] = $subgrpusers;
                                            }
                                        }
                                    }
                                    $grp_read_per[$shareEntId] = $share_grp_users;
                                }
                            }
                            if (!array_key_exists($shareEntId, $grp_write_per)) {
                                if (!array_key_exists($shareEntId, $grp_write_per)) {
                                    if (array_key_exists($shareEntId, $mod_share_read_per['GROUP'])) {
                                        $share_grp_users = $mod_share_read_per['GROUP'][$shareEntId];
                                    } elseif (array_key_exists($shareEntId, $mod_share_write_per['GROUP'])) {
                                        $share_grp_users = $mod_share_write_per['GROUP'][$shareEntId];
                                    } else {
                                        $focusGrpUsers = new GetGroupUsers();
                                        $focusGrpUsers->getAllUsersInGroup($shareEntId);
                                        $share_grp_users = $focusGrpUsers->group_users;
                                        foreach ($focusGrpUsers->group_subgroups as $subgrpid => $subgrpusers) {
                                            if (!array_key_exists($subgrpid, $grp_write_per)) {
                                                $grp_write_per[$subgrpid] = $subgrpusers;
                                            }
                                        }
                                    }
                                    $grp_write_per[$shareEntId] = $share_grp_users;
                                }
                            }
                        } elseif ($share_permission == 0 && $def_org_share[$share_mod_id] == 3) {
                            if (!array_key_exists($shareEntId, $grp_read_per)) {
                                if (array_key_exists($shareEntId, $mod_share_read_per['GROUP'])) {
                                    $share_grp_users = $mod_share_read_per['GROUP'][$shareEntId];
                                } elseif (array_key_exists($shareEntId, $mod_share_write_per['GROUP'])) {
                                    $share_grp_users = $mod_share_write_per['GROUP'][$shareEntId];
                                } else {
                                    $focusGrpUsers = new GetGroupUsers();
                                    $focusGrpUsers->getAllUsersInGroup($shareEntId);
                                    $share_grp_users = $focusGrpUsers->group_users;
                                    foreach ($focusGrpUsers->group_subgroups as $subgrpid => $subgrpusers) {
                                        if (!array_key_exists($subgrpid, $grp_read_per)) {
                                            $grp_read_per[$subgrpid] = $subgrpusers;
                                        }
                                    }
                                }
                                $grp_read_per[$shareEntId] = $share_grp_users;
                            }
                        }
                    }
                }
            }
        }
        $mod_share_read_permission['ROLE'] = $role_read_per;
        $mod_share_write_permission['ROLE'] = $role_write_per;
        $mod_share_read_permission['GROUP'] = $grp_read_per;
        $mod_share_write_permission['GROUP'] = $grp_write_per;
    }
    $related_mod_sharing_permission['read'] = $mod_share_read_permission;
    $related_mod_sharing_permission['write'] = $mod_share_write_permission;
    return $related_mod_sharing_permission;
}
Exemplo n.º 2
0
 private function getSubRoleUserIds($roleid)
 {
     $subRoleUserIds = array();
     $subordinateUsers = getRoleAndSubordinateUsers($roleid);
     if (!empty($subordinateUsers) && count($subordinateUsers) > 0) {
         $currRoleUserIds = getRoleUserIds($roleid);
         $subRoleUserIds = array_diff($subordinateUsers, $currRoleUserIds);
     }
     return $subRoleUserIds;
 }