public void Update(Permission item)
 {
     using (IDataContext ctx = DataContext.Instance())
     {
         var rep = ctx.GetRepository<Permission>();
         rep.Update(item);
     }
 }
Beispiel #2
0
        public File CreateGroupFolder(int roleID, int portalID, UserInfo currentUser)
        {
            FileController ctrl = new FileController();
            File rootGroupFolder = new File();

            //rootGroupFolder.ChildCount = 0;
            rootGroupFolder.CreatedByUserID = currentUser.UserID;
            rootGroupFolder.CreatedByUserName = currentUser.DisplayName;
            rootGroupFolder.CreatedDate = System.DateTime.Now;
            rootGroupFolder.IsInTrash = false;
            rootGroupFolder.IsFolder = true;
            rootGroupFolder.ItemType = 0;
            rootGroupFolder.LastModifiedByUserID = currentUser.UserID;
            rootGroupFolder.LastModifiedByUserName = currentUser.DisplayName;
            rootGroupFolder.LastModifiedDate = System.DateTime.Now;
            RoleController ctrlRole = new RoleController();
            RoleInfo role = ctrlRole.GetRole(roleID, portalID);
            rootGroupFolder.Name = role.RoleName;
            rootGroupFolder.ParentID = GetRootGroupsFolder(portalID, currentUser.UserID).ID;
            rootGroupFolder.PortalID = portalID;
            rootGroupFolder.RoleID = roleID;

            ctrl.Create(rootGroupFolder);

            Permission permission = new Permission();
            permission.CanAddFiles = true;
            permission.CanAddFolders = true;
            permission.CanDelete = false;
            permission.CanModify = false;
            permission.CanModifyPermission = false;
            permission.CanSee = true;
            permission.FileID = rootGroupFolder.ID;
            permission.ModuleID = 0;
            permission.PortalID = portalID;
            permission.RoleID = role.RoleID;
            permission.RoleName = role.RoleName;

            PermissionController ctrlPerm = new PermissionController();
            ctrlPerm.Create(permission);

            return rootGroupFolder;
        }
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Page_Load runs when the control is loaded
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        protected void Page_Load(System.Object sender, System.EventArgs e)
        {
            try
            {
                //Determine ItemId of CustomerSelfService to Update
                if(this.Request.QueryString["Type"] !=null)
                {
                    ItemType = Convert.ToInt32(this.Request.QueryString["Type"]);
                }
                if (this.Request.QueryString["Parent"] != null)
                {
                    ParentID = Int32.Parse(this.Request.QueryString["Parent"]);
                }
                //check for userID
                if (this.Request.QueryString["UserID"] != null) //if none, then _userIDParam = -1
                {
                    _userIDParameter = Int32.Parse(this.Request.QueryString["UserID"]);
                }
                //check for groupID
                if (this.Request.QueryString["GroupID"] != null) //if none, then _roleIDParam = -1
                {
                    _roleIDParameter = Int32.Parse(this.Request.QueryString["GroupID"]);
                }

                //If this is the first visit to the page, bind the role data to the datalist
                //get parent permissions by default
                if (!Page.IsPostBack)
                {

                    if(ItemType != Null.NullInteger)
                    {
                        if (ItemType == 0) //Folder
                        {
                            lblName.Text = "Folder Name";
                            lblName.HelpText = "Type the name of the folder";
                            FileFormItem.Visible = false;
                            HyperlinkFormItem.Visible = false;
                            gridPermissions.Columns[3].Visible = true;
                            gridPermissions.Columns[4].Visible = true;
                        }
                        else if (ItemType == 1) //File
                        {
                            NameFormItem.Visible = false;
                            HyperlinkFormItem.Visible = false;

                            //async uploader
                            string strAllowedFiles = DotNetNuke.Entities.Controllers.HostController.Instance.GetString("FileExtensions");
                            string[] strSearchPatterns = strAllowedFiles.Split(',');
                            asyncFileUpload.AllowedFileExtensions = strSearchPatterns;
                            asyncFileUpload.EnableInlineProgress = true;
                            asyncFileUpload.MaxFileInputsCount = 1;

                            //asyncFileUpload.MultipleFileSelection = Telerik.Web.UI.AsyncUpload.MultipleFileSelection.Disabled;
                        }
                        else if (ItemType == 2) //Hyperlink
                        {
                            lblName.Text = "Hyperlink Caption";
                            lblName.HelpText = "Type the caption of the hyperlink";
                            txtHyperlink.Text = "http://";
                            FileFormItem.Visible = false;
                        }
                        else
                        {
                            Response.Redirect(Globals.NavigateURL(), true);
                        }
                    }
                    else
                    {
                        Response.Redirect(Globals.NavigateURL(), true);
                    }

                    //create permissions grid and add parent permissions
                    //get permissions grid array
                    aryPermissions = new ArrayList();

                    //add roles to permissions grid
                    List<RoleInfo> roles = new List<RoleInfo>();
                    foreach (RoleInfo role in TestableRoleController.Instance.GetRoles(PortalId))
                    {
                        roles.Add(role);
                    }

                    //add 'all users, unauthenticated users, registered users'
                    RoleInfo allUsers = new RoleInfo();
                    allUsers.RoleName = "All Users";
                    allUsers.RoleID = 1000000;
                    allUsers.PortalID = PortalId;
                    roles.Add(allUsers);
                    RoleInfo unauthenticatedUsers = new RoleInfo();
                    unauthenticatedUsers.RoleID = 1000001;
                    unauthenticatedUsers.RoleName = "Unauthenticated Users";
                    unauthenticatedUsers.PortalID = PortalId;
                    roles.Add(unauthenticatedUsers);

                    //Add arraylist items to list
                    List<RoleInfo> listRoles = new List<RoleInfo>();
                    foreach (RoleInfo role in roles)
                    {
                        listRoles.Add(role);
                    }

                    //sort the roles
                    listRoles.Sort((a1, a2) => a1.RoleName.CompareTo(a2.RoleName));

                    foreach (RoleInfo role in listRoles)
                    {
                        if (role.PortalID == PortalId)
                        {
                            Permission perm = new Permission();
                            perm.RoleName = role.RoleName;
                            perm.RoleID = role.RoleID;
                            aryPermissions.Add(perm);
                        }
                    }

                    //Check for parent permissions and add if found
                    if (this.Request.QueryString["Parent"] != null)
                    {
                        ParentID = Int32.Parse(this.Request.QueryString["Parent"]);
                        if (ParentID > 0)
                        {
                            //get parent file permissions
                            PermissionController permCtrl = new PermissionController();
                            List<Permission> existingPermissions = permCtrl.GetItems(ParentID) as List<Permission>;
                            //loop parent permissions and find matching permissions
                            //add permissions to list
                            foreach (Permission existingPermission in existingPermissions)
                            {
                                //loop permissions and set if role id matches
                                if (existingPermission.RoleID > 0)
                                {
                                    foreach (Permission permission in aryPermissions)
                                    {
                                        if (permission.RoleID == existingPermission.RoleID)
                                        {
                                            permission.CanAddFiles = existingPermission.CanAddFiles;
                                            permission.CanAddFolders = existingPermission.CanAddFolders;
                                            permission.CanDelete = existingPermission.CanDelete;
                                            permission.CanModify = existingPermission.CanModify;
                                            permission.CanModifyPermission = existingPermission.CanModifyPermission;
                                            permission.CanSee = existingPermission.CanSee;
                                            permission.RoleID = existingPermission.RoleID;
                                            permission.RoleName = existingPermission.RoleName;
                                        }
                                    }
                                    continue;
                                }

                                //add user permission
                                if (existingPermission.UserID > 0)
                                {
                                    aryPermissions.Add(existingPermission);
                                }
                            }
                        }
                    }

                    //get current user permission
                    if (UserId != -1)
                    {
                        Permission userPermission = new Permission();
                        userPermission.CanSee = true;
                        userPermission.CanModify = true;
                        userPermission.CanDelete = true;
                        userPermission.CanModifyPermission = true;
                        userPermission.CanAddFiles = true;
                        userPermission.CanAddFolders = true;
                        userPermission.PortalID = PortalId;
                        userPermission.UserID = UserId;
                        userPermission.UserName = UserInfo.Username;

                        bool permExists = false;
                        foreach (Permission existPerm in aryPermissions)
                        {
                            if (existPerm.UserID == UserId)
                            {
                                existPerm.CanSee = true;
                                existPerm.CanModify = true;
                                existPerm.CanDelete = true;
                                existPerm.CanModifyPermission = true;
                                existPerm.CanAddFiles = true;
                                existPerm.CanAddFolders = true;
                                permExists = true;
                            }
                        }
                        if (permExists == false)
                        {
                            aryPermissions.Add(userPermission);
                        }
                    }

                    //bind permissions to grid
                    gridPermissions.DataSource = aryPermissions;
                    gridPermissions.DataBind();

                    Session["aryPermissions"] = aryPermissions;
                }

            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
        protected void lbnOK_Click(object sender, EventArgs e)
        {
            try
            {

                //check file type first
                //if (fileUpload.HasFile)
                //{
                //    string strAllowedFiles = DotNetNuke.Entities.Controllers.HostController.Instance.GetString("FileExtensions");
                //    string[] strSearchPatterns = strAllowedFiles.Split(',');
                //    string uploadType = fileUpload.PostedFile.FileName.Substring(fileUpload.PostedFile.FileName.LastIndexOf('.')+1);
                //    if (!strAllowedFiles.Contains(uploadType))
                //    {
                //        DotNetNuke.UI.Skins.Skin.AddModuleMessage(this, "File type not allowed", DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.RedError);
                //        return;
                //    }
                //}

                //create file
                DNNQuickApps.Modules.QuickDocsPro.FileController objQuickFiles = new DNNQuickApps.Modules.QuickDocsPro.FileController();
                DNNQuickApps.Modules.QuickDocsPro.File objFile = new DNNQuickApps.Modules.QuickDocsPro.File();
                //if (!Convert.ToBoolean(Settings["IsSearchable"].ToString()))
                //{
                //    objFile.ModuleID = ModuleId;
                //}
                objFile.PortalID = PortalId;
                objFile.CreatedByUserID = UserId;
                objFile.CreatedDate = System.DateTime.Now;
                objFile.LastModifiedDate = System.DateTime.Now;
                objFile.LastModifiedByUserID = UserId;
                objFile.VersionsToKeep = -1;
                objFile.VersionNumber = 1;

                //check files type (shared, user, groups)
                String strFilesModuleType = Settings["FilesMode"].ToString();
                if (strFilesModuleType == "UserFiles" || strFilesModuleType == "GroupFiles")
                {
                    if (strFilesModuleType == "UserFiles")
                    {
                        //get UserID parameter
                        if (this.Request.QueryString["UserID"] != null)
                        {
                            _userIDParameter = Convert.ToInt32(this.Request.QueryString["UserID"]);
                        }
                        objFile.HomeFolderUserID = _userIDParameter;
                    }
                    else //group files
                    {
                        //get UserID parameter
                        if (this.Request.QueryString["GroupID"] != null)
                        {
                            _roleIDParameter = Convert.ToInt32(this.Request.QueryString["GroupID"]);
                        }
                        objFile.RoleID = _roleIDParameter;
                    }
                }

                if (UserId != -1)
                {
                    objFile.CreatedByUserName = UserInfo.DisplayName;
                    objFile.LastModifiedByUserName = UserInfo.DisplayName;
                }
                else
                {
                    objFile.CreatedByUserName = "******";
                    objFile.LastModifiedByUserName = "******";
                }

                //create file or folder
                if (this.Request.QueryString["Type"] != null)
                {
                    ItemType = Convert.ToInt32(this.Request.QueryString["Type"]);
                }

                if (ItemType == 1)//File
                {
                    //check file exists
                    if (asyncFileUpload.UploadedFiles.Count == 0)
                    {
                        DotNetNuke.UI.Skins.Skin.AddModuleMessage(this, "Please select a valid file to upload", DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.RedError);
                        return;
                    }

                    objFile.Name = "File Upload";
                    objFile.ItemType = 1;
                }
                else if (ItemType == 0) //folder
                {
                    objFile.Name = txtName.Text;
                    objFile.ItemType = 0;
                    objFile.IsFolder = true;
                }
                else if (ItemType == 2) //Hyperlink
                {
                    objFile.Name = txtName.Text;
                    objFile.ItemType = 2;
                    objFile.LinkURL = txtHyperlink.Text;
                }
                else
                {
                    Response.Redirect(Globals.NavigateURL(), true);
                }

                if (this.Request.QueryString["Parent"] != null)
                {
                    ParentID = Int32.Parse(this.Request.QueryString["Parent"]);
                }
                objFile.ParentID = ParentID;
                objFile.Description = "";

                //create file

                objQuickFiles.Create(objFile);

                if (ItemType == 1) //file
                {

                    //create file version and copy attributes from current version
                    DNNQuickApps.Modules.QuickDocsPro.File objVersionFile = new DNNQuickApps.Modules.QuickDocsPro.File();
                    //if (!Convert.ToBoolean(Settings["IsSearchable"].ToString()))
                    //{
                    //    objVersionFile.ModuleID = ModuleId;
                    //}
                    objVersionFile.PortalID = PortalId;
                    objVersionFile.CreatedByUserID = objFile.CreatedByUserID;
                    objVersionFile.CreatedDate = objFile.LastModifiedDate;
                    objVersionFile.CreatedByUserName = objFile.CreatedByUserName;
                    objVersionFile.LastModifiedDate = objFile.LastModifiedDate;
                    objVersionFile.LastModifiedByUserID = objFile.LastModifiedByUserID;
                    objVersionFile.LastModifiedByUserName = objFile.LastModifiedByUserName;
                    objVersionFile.LinkURL = objFile.LinkURL;
                    objVersionFile.ItemType = objFile.ItemType;
                    objVersionFile.VersionsToKeep = -1;
                    objVersionFile.VersionNumber = objFile.VersionNumber;
                    objVersionFile.ParentID = objFile.ID;
                    objVersionFile.Name = "Version Upload";
                    objVersionFile.Description = objFile.Description;
                    objVersionFile.HomeFolderUserID = objFile.HomeFolderUserID;
                    objVersionFile.RoleID = objFile.RoleID;

                    objQuickFiles.Create(objVersionFile);

                    //upload file version
                    FileConfigurationController configCtrl = new FileConfigurationController();
                    List<FileConfiguration> configs = configCtrl.GetItems(PortalId) as List<FileConfiguration>;

                    if (configs[0].StorageType == "UNC")
                    {
                        objVersionFile.CreatePath(configs[0].FilesLocation);
                        //fileUpload.SaveAs(configs[0].FilesLocation + objVersionFile.GetFullPath());
                        asyncFileUpload.UploadedFiles[0].SaveAs(configs[0].FilesLocation + objVersionFile.GetFullPath());
                    }
                    else
                    {
                        objVersionFile.CreatePath(Server.MapPath(configs[0].FilesLocation));
                        //fileUpload.SaveAs(Server.MapPath(configs[0].FilesLocation) + objVersionFile.GetFullPath());
                        asyncFileUpload.UploadedFiles[0].SaveAs(Server.MapPath(configs[0].FilesLocation) + objVersionFile.GetFullPath());
                    }

                    //List<string> fileNameAndExtension = objVersionFile.GetFileNameAndExtension(fileUpload.FileName);
                    List<string> fileNameAndExtension = objVersionFile.GetFileNameAndExtension(asyncFileUpload.UploadedFiles[0].FileName);

                    objVersionFile.AttachmentName = asyncFileUpload.UploadedFiles[0].FileName;// fileUpload.FileName;
                    objVersionFile.AttachmentPath = objVersionFile.GetFullPath();
                    objVersionFile.FileType = asyncFileUpload.UploadedFiles[0].ContentType;// fileUpload.PostedFile.ContentType;
                    objVersionFile.FileLength = (int)asyncFileUpload.UploadedFiles[0].ContentLength;// fileUpload.PostedFile.ContentLength;
                    objVersionFile.Name = fileNameAndExtension[0];
                    objVersionFile.Extension = fileNameAndExtension[1];

                    objFile.AttachmentPath = objVersionFile.GetFullPath();
                    objFile.FileType = asyncFileUpload.UploadedFiles[0].ContentType;// fileUpload.PostedFile.ContentType;
                    objFile.FileLength = (int)asyncFileUpload.UploadedFiles[0].ContentLength;// fileUpload.PostedFile.ContentLength;
                    objFile.Name = fileNameAndExtension[0];
                    objFile.Extension = fileNameAndExtension[1];

                    objQuickFiles.Update(objVersionFile);
                    objQuickFiles.Update(objFile);
                }

                    //create permissions
                    PermissionController objQuickPermissions = new PermissionController();

                    foreach (GridViewRow row in gridPermissions.Rows)
                    {
                        if ((((CheckBox)row.FindControl("chkCanSee")).Checked))
                        {
                            Permission perm = new Permission();
                            perm.CanSee = true;
                            perm.CanAddFiles = ((CheckBox)row.FindControl("chkCanAddFolders")).Checked;
                            perm.CanAddFolders = ((CheckBox)row.FindControl("chkCanAddItems")).Checked;
                            perm.CanModify = ((CheckBox)row.FindControl("chkCanModify")).Checked;
                            perm.CanDelete = ((CheckBox)row.FindControl("chkCanDelete")).Checked;
                            perm.CanModifyPermission = ((CheckBox)row.FindControl("chkCanModifyPermission")).Checked;
                            perm.FileID = objFile.ID;

                            int userID = Int32.Parse(row.Cells[8].Text);
                            int roleID = Int32.Parse(row.Cells[10].Text);
                            string userName = row.Cells[9].Text;
                            string roleName = row.Cells[11].Text;

                            if (userID > 0)
                            {
                                perm.UserID = userID;
                                perm.UserName = userName;
                            }

                            if (roleID > 0)
                            {
                                perm.RoleID = roleID;
                                perm.RoleName = roleName;
                            }

                            objQuickPermissions.Create(perm);
                        }
                    }

                //refresh cac
                SynchronizeModule();

                //Redirect back to the parent folder page
                //Redirect back to the portal home page

                string strItemType = "Folder";
                switch (ItemType)
                {
                    case 0:
                        strItemType = "Folder";
                        break;
                    case 1:
                        strItemType = "File";
                        break;
                    case 2:
                        strItemType = "Hyperlink";
                        break;
                }

                #region "Audit"
                //Audit: Create Item
                AuditController ctrlAudit = new AuditController();
                Audit createAudit = new Audit() { EventDate = objFile.CreatedDate, EventDetails = "File name: " + objFile.Name, EventName = "Created", FileID = objFile.ID, UserID = UserId };
                ctrlAudit.Create(createAudit);
                #endregion

                string successMessage = String.Format("Success=New {0} '{1}' created.", strItemType, objFile.Name);

                this.Response.Redirect(Globals.NavigateURL(this.TabId, "", "Folder=" + objFile.ParentID, "ModuleID=" + ModuleId.ToString(), "UserID=" + _userIDParameter, "GroupID=" + _roleIDParameter, successMessage), true);

            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
        protected void lbnAddUser_Click(object sender, EventArgs e)
        {
            UserController userCtrl = new UserController();
            UserInfo newUserPermission = userCtrl.GetUserByUsername(PortalId, txtUser.Text);
            if (newUserPermission == null)
            {
                divUserNotFoundError.Visible = true;
                return;
            }

            txtUser.Text = "";
            divUserNotFoundError.Visible = false;

            aryPermissions = (ArrayList)Session["aryPermissions"];

            //look for existing permission
            foreach (Permission perm in aryPermissions)
            {
                if (perm.UserID == newUserPermission.UserID)
                {
                    return;
                }
            }
            Permission newPerm = new Permission();
            newPerm.UserName = newUserPermission.Username;
            newPerm.UserID = newUserPermission.UserID;
            aryPermissions.Add(newPerm);
            gridPermissions.DataSource = aryPermissions;
            gridPermissions.DataBind();

            Session["aryPermissions"] = aryPermissions;
        }
Beispiel #6
0
        private int GetPermissionValue(Permission perm)
        {
            int value = 0;

            if (perm.CanSee == true)
            {
                value += 1;
            }

            if (perm.CanAddFiles == true)
            {
                value += 2;
            }

            if (perm.CanAddFolders == true)
            {
                value += 4;
            }

            if (perm.CanModify == true)
            {
                value += 8;
            }

            if (perm.CanDelete == true)
            {
                value += 16;
            }

            if (perm.CanModifyPermission == true)
            {
                value += 32;
            }

            return value;
        }
Beispiel #7
0
        public File CreateUserFolder(int userID, int portalID, UserInfo currentUser)
        {
            FileController ctrl = new FileController();
            File rootUserFolder = new File();
            //rootUserFolder.ChildCount = 0;
            rootUserFolder.CreatedByUserID = currentUser.UserID;
            rootUserFolder.CreatedByUserName = currentUser.DisplayName;
            rootUserFolder.CreatedDate = System.DateTime.Now;
            rootUserFolder.IsInTrash = false;
            rootUserFolder.IsFolder = true;
            rootUserFolder.ItemType = 0;
            rootUserFolder.LastModifiedByUserID = currentUser.UserID;
            rootUserFolder.LastModifiedByUserName = currentUser.DisplayName;
            rootUserFolder.LastModifiedDate = System.DateTime.Now;
            UserController ctrlUser = new UserController();
            UserInfo user = ctrlUser.GetUser(portalID, userID);
            rootUserFolder.Name = user.DisplayName;
            rootUserFolder.ParentID = GetRootUsersFolder(portalID, userID).ID;
            rootUserFolder.PortalID = portalID;
            rootUserFolder.HomeFolderUserID = user.UserID;

            ctrl.Create(rootUserFolder);

            //all users read permission
            Permission AllUserspermission = new Permission();
            AllUserspermission.CanAddFiles = false;
            AllUserspermission.CanAddFolders = false;
            AllUserspermission.CanDelete = false;
            AllUserspermission.CanModify = false;
            AllUserspermission.CanModifyPermission = false;
            AllUserspermission.CanSee = true;
            AllUserspermission.FileID = rootUserFolder.ID;
            AllUserspermission.ModuleID = 0;
            AllUserspermission.PortalID = portalID;
            AllUserspermission.RoleID = 1000000;
            AllUserspermission.RoleName = "All Users";

            PermissionController ctrlPerm = new PermissionController();
            ctrlPerm.Create(AllUserspermission);

            //add user add items permission
            Permission userPermission = new Permission();
            userPermission.CanAddFiles = true;
            userPermission.CanAddFolders = true;
            userPermission.CanDelete = false;
            userPermission.CanModify = false;
            userPermission.CanModifyPermission = false;
            userPermission.CanSee = true;
            userPermission.FileID = rootUserFolder.ID;
            userPermission.ModuleID = 0;
            userPermission.PortalID = portalID;
            userPermission.UserID = user.UserID;
            userPermission.UserName = user.Username;

            ctrlPerm.Create(userPermission);

            return rootUserFolder;
        }
Beispiel #8
0
        public File CreateRootSharedFolder(int userID, int portalID)
        {
            FileController ctrl = new FileController();
            UserController ctrlUser = new UserController();
            UserInfo user = ctrlUser.GetUser(portalID, userID);

            //create root shared folder
            File rootPortalFolder = new File();
            //rootPortalFolder.ChildCount = 0;
            rootPortalFolder.CreatedByUserID = userID;
            rootPortalFolder.CreatedByUserName = user.DisplayName;
            rootPortalFolder.CreatedDate = System.DateTime.Now;
            rootPortalFolder.IsInTrash = false;
            rootPortalFolder.IsFolder = true;
            rootPortalFolder.ItemType = 0;
            rootPortalFolder.LastModifiedByUserID = userID;
            rootPortalFolder.LastModifiedByUserName = user.DisplayName;
            rootPortalFolder.LastModifiedDate = System.DateTime.Now;
            rootPortalFolder.Name = "Site Root Folder";
            rootPortalFolder.Description = "";
            rootPortalFolder.ParentID = -1;
            rootPortalFolder.PortalID = portalID;

            ctrl.Create(rootPortalFolder);

            //add default permission
            PermissionController ctrlPerm = new PermissionController();
            Permission perm = new Permission();
            perm.CanAddFiles = true;
            perm.CanAddFolders = true;
            perm.CanSee = true;
            perm.FileID = rootPortalFolder.ID;
            perm.PortalID = portalID;
            perm.RoleID = 1000000;
            perm.RoleName = "All Users";

            ctrlPerm.Create(perm);

            //update files config
            FileConfigurationController ctrlConfig = new FileConfigurationController();
            var configs = ctrlConfig.GetItems(portalID) as List<FileConfiguration>;
            configs[0].RootUsersFolderID = rootPortalFolder.ID;
            ctrlConfig.Update(configs[0]);

            return rootPortalFolder;
        }
        private void ApplyPermissionsToDirectChildren(File file, List<Permission> filePermissions)
        {
            FileController fileCtrl = new FileController();
            PermissionController permCtrl = new PermissionController();
            //List<File> childFiles = fileCtrl.GetItemsByParent(file.ID, UserId, PortalId, PortalSettings.AdministratorRoleId, "");
            List<File> childFiles = fileCtrl.GetItems(file.ID) as List<File>;
            foreach (File childFile in childFiles)
            {
                //check edit permission
                if (childFile.CanEditPermissions(UserId, PortalId, PortalSettings.AdministratorRoleId, false))
                {
                    //delete existing permissions
                    List<Permission> deletePermissions = permCtrl.GetItems(childFile.ID) as List<Permission>;
                    foreach (Permission deletePermission in deletePermissions)
                    {
                        Permission permissionToDelete = permCtrl.Get(deletePermission.ID, childFile.ID);
                        permCtrl.Delete(permissionToDelete);
                    }

                    //add file permissions
                    foreach (Permission filePermission in filePermissions)
                    {
                        Permission newPermission = new Permission();
                        newPermission.ID = filePermission.ID;
                        newPermission.ModuleID = filePermission.ModuleID;
                        newPermission.PortalID = filePermission.PortalID;
                        newPermission.CanSee = filePermission.CanSee;
                        newPermission.CanModify = filePermission.CanModify;
                        newPermission.CanAddFiles = filePermission.CanAddFiles;
                        newPermission.CanAddFolders = filePermission.CanAddFolders;
                        newPermission.CanDelete = filePermission.CanDelete;
                        newPermission.CanModifyPermission = filePermission.CanModifyPermission;
                        newPermission.IsOwner = filePermission.IsOwner;
                        newPermission.RoleID = filePermission.RoleID;
                        newPermission.RoleName = filePermission.RoleName;
                        newPermission.UserID = filePermission.UserID;
                        newPermission.UserName = filePermission.UserName;

                        //assign new permission to child item
                        newPermission.FileID = childFile.ID;
                        permCtrl.Create(newPermission);
                    }

                    //report updated file
                    _updatedPermissionFiles.Add(childFile);
                }
                else
                {
                    //report non-updated file
                    _notUpdatedPermissionFiles.Add(childFile);
                }

                //do child files
                ApplyPermissionsToDirectChildren(childFile, filePermissions);
            }
        }
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Page_Load runs when the control is loaded
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        protected void Page_Load(System.Object sender, System.EventArgs e)
        {
            try
            {
                if (this.Request.QueryString["ID"] != null)
                {
                    ItemID = Int32.Parse(this.Request.QueryString["ID"]);
                }
                //check for userID
                if (this.Request.QueryString["UserID"] != null) //if none, then _userIDParam = -1
                {
                    _userIDParameter = Int32.Parse(this.Request.QueryString["UserID"]);
                }
                //check for groupID
                if (this.Request.QueryString["GroupID"] != null) //if none, then _roleIDParam = -1
                {
                    _roleIDParameter = Int32.Parse(this.Request.QueryString["GroupID"]);
                }
                if (this.Request.QueryString["View"] != null)
                {
                    _sourceView = this.Request.QueryString["View"];
                }

                //If this is the first visit to the page, bind the role data to the datalist
                if (!Page.IsPostBack)
                {
                    DNNQuickApps.Modules.QuickDocsPro.FileController objQuickFiles = new DNNQuickApps.Modules.QuickDocsPro.FileController();
                    DNNQuickApps.Modules.QuickDocsPro.File objFile = objQuickFiles.Get(ItemID);

                    //legacy, now sending to delete form
                    //set confirmation messages
                    //if (objFile.IsInTrash)
                    //{
                    //    lbnDelete.Attributes.Add("onClick", "javascript:return confirm('Are you sure you wish to permanently delete this item?');");
                    //}
                    //else
                    //{
                    //    lbnDelete.Attributes.Add("onClick", "javascript:return confirm('" + Localization.GetString("DeleteItem") + "');");
                    //}

                    //delete confirmation for delete versions
                    lbnDeleteVersions.Attributes.Add("onClick", "javascript:return confirm('Are you sure you wish to delete the selected version(s)?');");

                    //verify permissions
                    ApplyPermissions(objFile);

                    txtName.Text = objFile.Name;
                    lblCreatedBy.Text = "<b>" + objFile.CreatedByUserName + "</b> " + objFile.CreatedDate.ToString();
                    //lblCreatedDate.Text = objFile.CreatedDate.ToString();
                    if (objFile.CreatedByUserID != -1)
                    {
                        imgCreatedByProfile.ImageUrl = UserController.GetUserById(PortalId, objFile.CreatedByUserID).Profile.PhotoURL;
                    }
                    imgCreatedByProfile.Height = 24;
                    lblModifiedBy.Text = "<b>" + objFile.LastModifiedByUserName + "</b> " + objFile.LastModifiedDate.ToString();
                    //lblModifiedDate.Text = objFile.LastModifiedDate.ToString();
                    if (objFile.LastModifiedByUserID != -1)
                    {
                        imgLastModifiedByProfile.ImageUrl = UserController.GetUserById(PortalId, objFile.LastModifiedByUserID).Profile.PhotoURL;
                    }
                    imgLastModifiedByProfile.Height = 24;
                    txtDescription.Text = objFile.Description;
                    txtVersionsToKeep.Text = objFile.VersionsToKeep.ToString();

                    #region "Load Audit"

                    if (Settings["ShowAuditHistory"] != null)
                    {
                        if (Convert.ToBoolean(Settings["ShowAuditHistory"].ToString()) == true)
                        {
                            AuditController ctrlAudit = new AuditController();
                            var auditData = ctrlAudit.Get10ItemAuditHistory(ItemID);
                            Session["AuditData"] = auditData;
                            gridAudit.DataSource = Session["AuditData"];
                            gridAudit.DataBind();

                            if (gridAudit.Rows.Count == 10)
                            {
                                lbnLoadFullAudit.Visible = true;
                            }
                            else
                            {
                                lbnLoadFullAudit.Visible = false;
                            }
                        }
                        else
                        {
                            liAudit.Visible = false;
                            lbnLoadFullAudit.Visible = false;
                        }
                    }
                    else
                    {
                        liAudit.Visible = false;
                        lbnLoadFullAudit.Visible = false;
                    }
                    #endregion

                    if (objFile.ItemType == 0) //folder
                    {
                        if (_userIDParameter != -1)
                        {
                            _directLink = Globals.NavigateURL(TabId, "", "Folder=" + objFile.ID.ToString(), "UserID=" + _userIDParameter.ToString());
                        }
                        else
                        {
                            _directLink = Globals.NavigateURL(TabId, "", "Folder=" + objFile.ID.ToString());
                        }
                        lblDirectLink.Text = _directLink;
                        lblNameLabel.Text = "Folder Name";
                        liVersions.Visible = false;

                        formItemVersionCount.Visible = false;
                        formItemVersions.Visible = false;
                        formItemVersionsToKeep.Visible = false;
                        lbnDeleteVersions.Visible = false;
                        FormItemHyperlink.Visible = false;

                        gridPermissions.Columns[3].Visible = true;
                        gridPermissions.Columns[4].Visible = true;

                    }

                    if (objFile.ItemType == 1) //file
                    {
                        if (_userIDParameter != -1)
                        {
                            _directLink = Globals.NavigateURL(TabId, "", "Open=" + objFile.ID.ToString(), "UserID=" + _userIDParameter.ToString());
                        }
                        else
                        {
                            _directLink = Globals.NavigateURL(TabId, "", "Open=" + objFile.ID.ToString());
                        }
                        lblDirectLink.Text = _directLink;
                        lblNameLabel.Text = "File Name";
                        liVersions.Visible = true;
                        FormItemHyperlink.Visible = false;

                        BindVersions(objFile);
                    }

                    if (objFile.ItemType == 2) //Link
                    {
                        if (_userIDParameter != -1)
                        {
                            _directLink = Globals.NavigateURL(TabId, "", "Open=" + objFile.ID.ToString(), "UserID=" + _userIDParameter.ToString());
                        }
                        else
                        {
                            _directLink = Globals.NavigateURL(TabId, "", "Open=" + objFile.ID.ToString());
                        }
                        lblDirectLink.Text = _directLink;
                        lblNameLabel.Text = "Hyperlink Caption";
                        txtHyperlink.Text = objFile.LinkURL;
                        liVersions.Visible = false;

                        formItemVersionCount.Visible = false;
                        formItemVersions.Visible = false;
                        formItemVersionsToKeep.Visible = false;
                        lbnDeleteVersions.Visible = false;
                        linkAddVersion.Visible = false;
                    }

                    //Social Share
                    socialShare.TitleToShare = objFile.Name;
                    socialShare.UrlToShare = lblDirectLink.Text;

                    socialEmail.TitleToShare = objFile.Name;
                    socialEmail.UrlToShare = lblDirectLink.Text;

                    //get permissions grid array
                    aryPermissions = new ArrayList();

                    //add roles to permissions grid
                    List<RoleInfo> roles = new List<RoleInfo>();
                    foreach (RoleInfo role in TestableRoleController.Instance.GetRoles(PortalId))
                    {
                        roles.Add(role);
                    }

                    //add 'all users, unauthenticated users, registered users'
                    RoleInfo allUsers = new RoleInfo();
                    allUsers.RoleName = "All Users";
                    allUsers.RoleID = 1000000;
                    allUsers.PortalID = PortalId;
                    roles.Add(allUsers);
                    RoleInfo unauthenticatedUsers = new RoleInfo();
                    unauthenticatedUsers.RoleID = 1000001;
                    unauthenticatedUsers.PortalID = PortalId;
                    unauthenticatedUsers.RoleName = "Unauthenticated Users";
                    roles.Add(unauthenticatedUsers);

                    //Add arraylist items to list
                    List<RoleInfo> listRoles = new List<RoleInfo>();
                    foreach (RoleInfo role in roles)
                    {
                        listRoles.Add(role);
                    }

                    //sort the roles
                    listRoles.Sort((a1, a2) => a1.RoleName.CompareTo(a2.RoleName));

                    foreach (RoleInfo role in listRoles)
                    {
                        if (role.PortalID == PortalId)
                        {
                            Permission perm = new Permission();
                            perm.RoleName = role.RoleName;
                            perm.RoleID = role.RoleID;
                            aryPermissions.Add(perm);
                        }
                    }

                    //get existing file permissions
                    PermissionController permCtrl = new PermissionController();
                    List<Permission> existingPermissions = permCtrl.GetItems(ItemID) as List<Permission>;
                    //loop existing permissions and find matching permissions
                    //add user permissions to list
                    foreach (Permission existingPermission in existingPermissions)
                    {
                        //loop permissions and set if role id matches
                        if (existingPermission.RoleID > 0)
                        {
                            foreach (Permission permission in aryPermissions)
                            {
                                if (permission.RoleID == existingPermission.RoleID)
                                {
                                    permission.CanAddFiles = existingPermission.CanAddFiles;
                                    permission.CanAddFolders = existingPermission.CanAddFolders;
                                    permission.CanDelete = existingPermission.CanDelete;
                                    permission.CanModify = existingPermission.CanModify;
                                    permission.CanModifyPermission = existingPermission.CanModifyPermission;
                                    permission.CanSee = existingPermission.CanSee;
                                    permission.RoleID = existingPermission.RoleID;
                                    permission.RoleName = existingPermission.RoleName;
                                }
                            }
                            continue;
                        }

                        //add user permission
                        if (existingPermission.UserID > 0)
                        {
                            aryPermissions.Add(existingPermission);
                        }
                    }

                    //bind permissions to grid
                    gridPermissions.DataSource = aryPermissions;
                    gridPermissions.DataBind();

                    Session["aryPermissions"] = aryPermissions;

                    //set add version url and delete
                    linkAddVersion.NavigateUrl = EditUrl("File", objFile.ID.ToString(), "AddVersion", "Parent=" + objFile.ParentID.ToString(), "UserID=" + _userIDParameter, "GroupID=" + _roleIDParameter);
                    linkDelete.NavigateUrl = EditUrl("File", objFile.ID.ToString(), "Delete", "Parent=" + objFile.ParentID.ToString(), "View=" + _sourceView, "UserID=" + _userIDParameter, "GroupID=" + _roleIDParameter);

                }

               }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
        protected void lbnOK_Click(object sender, EventArgs e)
        {
            try
            {

                ParentID = -1;
                if (this.Request.QueryString["Parent"] != null)
                {
                    ParentID = Int32.Parse(this.Request.QueryString["Parent"]);
                }

                if (this.Request.QueryString["View"] != null)
                {
                    _sourceView = this.Request.QueryString["View"];
                }

                if (this.Request.QueryString["ID"] != null)
                {
                    this.ItemID = Int32.Parse(this.Request.QueryString["ID"]);
                }
                else
                {
                    this.Response.Redirect(Globals.NavigateURL(this.TabId, "", "Folder=" + ParentID.ToString(), "UserID=" + _userIDParameter, "GroupID=" + _roleIDParameter, "Warning=Could not save updates.  File not found."), true);
                }

                //get file
                DNNQuickApps.Modules.QuickDocsPro.FileController objQuickFiles = new DNNQuickApps.Modules.QuickDocsPro.FileController();
                DNNQuickApps.Modules.QuickDocsPro.File objFile = objQuickFiles.Get(ItemID);
                objFile.ModuleID = ModuleId;
                objFile.LastModifiedDate = System.DateTime.Now;
                objFile.Name = txtName.Text;
                objFile.Description = txtDescription.Text;
                objFile.LastModifiedByUserID = UserId;

                //update link url
                if (objFile.ItemType == 2) //link
                {
                    objFile.LinkURL = txtHyperlink.Text;
                }

                if (UserId != -1)
                {
                    objFile.LastModifiedByUserName = UserInfo.DisplayName;
                }
                else
                {
                    objFile.LastModifiedByUserName = "******";
                }

                try
                {
                    objFile.VersionsToKeep = Int32.Parse(txtVersionsToKeep.Text);
                }
                catch
                {

                }

                if (objFile.CanEditPermissions(UserId, PortalId, PortalSettings.AdministratorRoleId, true))
                {
                    //delete existing permissions
                    PermissionController permCtrl = new PermissionController();
                    List<Permission> permissionsToDelete = permCtrl.GetItems(objFile.ID) as List<Permission>;
                    for (int i = 0; i < permissionsToDelete.Count; i++)
                    {
                        permCtrl.Delete(permissionsToDelete[i]);
                    }

                    //create updated permissions
                    PermissionController objQuickPermissions = new PermissionController();
                    foreach (GridViewRow row in gridPermissions.Rows)
                    {
                        if ((((CheckBox)row.FindControl("chkCanSee")).Checked))
                        {
                            Permission perm = new Permission();
                            perm.CanSee = true;
                            perm.CanAddFiles = ((CheckBox)row.FindControl("chkCanAddItems")).Checked;
                            perm.CanAddFolders = ((CheckBox)row.FindControl("chkCanAddFolders")).Checked;
                            perm.CanModify = ((CheckBox)row.FindControl("chkCanModify")).Checked;
                            perm.CanDelete = ((CheckBox)row.FindControl("chkCanDelete")).Checked;
                            perm.CanModifyPermission = ((CheckBox)row.FindControl("chkCanModifyPermission")).Checked;
                            perm.FileID = objFile.ID;

                            int userID = Int32.Parse(row.Cells[8].Text);
                            int roleID = Int32.Parse(row.Cells[10].Text);
                            string userName = row.Cells[9].Text;
                            string roleName = row.Cells[11].Text;

                            if (userID > 0)
                            {
                                perm.UserID = userID;
                                perm.UserName = userName;
                            }

                            if (roleID > 0)
                            {
                                perm.RoleID = roleID;
                                perm.RoleName = roleName;
                            }

                            objQuickPermissions.Create(perm);
                        }
                    }
                }

                objQuickFiles.Update(objFile);

                #region "Audit"
                //Audit: Updated Item
                AuditController ctrlAudit = new AuditController();
                Audit updatedAudit = new Audit() { EventDate = objFile.LastModifiedDate, EventDetails = "", EventName = "Updated", FileID = objFile.ID, UserID = UserId };
                ctrlAudit.Create(updatedAudit);
                #endregion

                //refresh cache
                SynchronizeModule();

                if (chkApplyToSubItems.Checked)
                {
                    //apply permissions to sub-items
                    ApplyPermissionsToSubItems(objFile);
                    return;
                }

                //Redirect back to the portal home page
                this.Response.Redirect(Globals.NavigateURL(this.TabId, "", "Folder=" + ParentID.ToString(), "View=" + _sourceView, "UserID=" + _userIDParameter, "GroupID=" + _roleIDParameter, "Success=Changes saved."), true);
            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }