protected void lbnOK_Click(object sender, EventArgs e)
        {
            try
            {
                int intSelectedNodeValue = Convert.ToInt32(treeFolders.SelectedNode.Value);
                //get parameters
                if (this.Request.QueryString["Parent"] != null)
                {
                    _ParentID = Int32.Parse(this.Request.QueryString["Parent"]);
                }
                if (this.Request.QueryString["File"] != null)
                {
                    _FileID = Int32.Parse(this.Request.QueryString["File"]);
                }

                FileController fileCtrl = new FileController();
                File targetFile = fileCtrl.Get(_FileID);
                File destinationFolder = fileCtrl.Get(intSelectedNodeValue);
                if (destinationFolder == null)
                {
                    destinationFolder = new File();
                    destinationFolder.ID = -1;
                    destinationFolder.Name = "Portal Root Folder";
                }

                targetFile.ParentID = intSelectedNodeValue;
                targetFile.IsInTrash = false;
                if (UserId != -1)
                {
                    targetFile.LastModifiedByUserName = UserInfo.DisplayName;
                }
                else
                {
                    targetFile.LastModifiedByUserName = "******";
                }
                targetFile.LastModifiedByUserID = -1;
                targetFile.LastModifiedDate = System.DateTime.Now;
                fileCtrl.Update(targetFile);

                //refresh cac
                SynchronizeModule();

                //Redirect back to the portal home page
                this.Response.Redirect(Globals.NavigateURL(this.TabId, "", "Folder=" + _ParentID, "ModuleID=" + ModuleId, "UserID=" + _userIDParameter, "GroupID=" + _roleIDParameter, String.Format("Success={0} moved to: {1}", targetFile.Name, destinationFolder.Name)), true);
            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
        private void DeleteChildren(File file)
        {
            //delete ALL children items where user has delete permission

            FileController fileCtrl = new FileController();
            List<File> files = fileCtrl.GetItems(file.ID) as List<File>;
            foreach (File childFile in files)
            {
                if (file.ItemType == 0)
                {
                    DeleteChildren(childFile);
                }
            }
                //send to trash if not folder
                if (file.ItemType != 0 && file.CanDelete(UserId, PortalId, PortalSettings.AdministratorRoleId, false))
                {
                    //send to trash if not there already
                    if (!file.IsInTrash)
                    {
                        file.IsInTrash = true;
                        fileCtrl.Update(file);
                        #region "Audit"
                        //Audit: Create Item
                        AuditController ctrlAudit = new AuditController();
                        Audit deleteAudit = new Audit() { EventDate = file.LastModifiedDate, EventDetails = "", EventName = "Deleted", FileID = file.ID, UserID = UserId };
                        ctrlAudit.Create(deleteAudit);
                        #endregion
                        _deletedFilesCount++;
                        return;
                    }

                    //if file is in trash, delete permissions and file
                    if (file.IsInTrash)
                    {
                        PermissionController permCtrl = new PermissionController();

                        //delete versions and version permissions
                        List<File> versions = fileCtrl.GetItems(file.ID) as List<File>;
                        foreach (File version in versions)
                        {
                            List<Permission> versionPermissions = permCtrl.GetItems(version.ID) as List<Permission>;
                            for (int i = 0; versionPermissions.Count - 1 > i; i++)
                            {
                                permCtrl.Delete(versionPermissions[i]);
                            }
                            fileCtrl.Delete(version);
                        }

                        //delete file permissions
                        List<Permission> folderPermissions = permCtrl.GetItems(file.ID) as List<Permission>;
                        for (int i = 0; folderPermissions.Count - 1 >= i; i++)
                        {
                            permCtrl.Delete(folderPermissions[i]);
                        }

                        //delete file instead of sending to trash
                        _filesToDelete.Add(file);
                        //fileCtrl.Delete(file);

                        _permanentlyDeletedFilesCount++;
                        return;
                    }
                }

                //check if any items exist under folder and delete permission before deleting
                if (file.ItemType == 0 && file.CanDelete(UserId, PortalId, PortalSettings.AdministratorRoleId, false))
                {
                    //get current child count
                    List<File> childFiles = fileCtrl.GetItems(file.ID) as List<File>;
                    int childFilesCount = 0;

                    //count child items not in trash
                    foreach (File childFileCount in childFiles)
                    {
                        if (!childFileCount.IsInTrash)
                        {
                            childFilesCount++;
                        }
                    }

                    //no child items, permanently delete folder
                    if (childFilesCount == 0)
                    {
                        //delete folder permissions
                        PermissionController permCtrl = new PermissionController();
                        List<Permission> folderPermissions = permCtrl.GetItems(file.ID) as List<Permission>;
                        for (int i = 0; folderPermissions.Count - 1 >=  i; i++)
                        {
                            permCtrl.Delete(folderPermissions[i]);
                        }

                        //delete folder instead of sending to trash
                        _filesToDelete.Add(file);
                        //fileCtrl.Delete(file);

                        _deletedFilesCount++;
                        return;
                    }
                    else
                    {
                        _notDeletedFilesCount++;
                        return;
                    }
                }
                _notDeletedFilesCount++;
        }
Beispiel #3
0
 private void UpdateModIDFromParent(int parentID, int moduleID)
 {
     FileController ctrlFiles = new FileController();
     foreach (File file in ctrlFiles.GetItems(parentID))
     {
         file.ModuleID = moduleID;
         ctrlFiles.Update(file);
         UpdateModIDFromParent(file.ID, moduleID);
     }
 }
Beispiel #4
0
        public File CreateRootGroupsFolder(int userID, int portalID)
        {
            //create folder
            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 = "Groups Root Folder";
            rootPortalFolder.Description = "";
            rootPortalFolder.ParentID = GetRootPortalFolder(portalID, userID).ID;
            rootPortalFolder.PortalID = portalID;

            ctrl.Create(rootPortalFolder);

            //add permissions
            //admins only

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

            //unify existing user folders under default users folder
            foreach (var userFolder in ctrl.GetV702GroupFolders(portalID))
            {
                userFolder.ParentID = rootPortalFolder.ID;
                ctrl.Update(userFolder);
            }

            //return default new root users folder
            return rootPortalFolder;
        }
        protected void lbnOK_Click(object sender, EventArgs e)
        {
            try
            {
                //check for trash view
                if (this.Request.QueryString["View"] != null)
                {
                    _view = this.Request.QueryString["View"];
                }

                //can not select portal root or no selection
                if (treeFolders.SelectedNode == null || Convert.ToInt32(treeFolders.SelectedNode.Value) == -1)
                {
                    DotNetNuke.UI.Skins.Skin.AddModuleMessage(this, "Error: The item can not be moved to the selected location.  Select a different folder.", DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.RedError);
                    return;
                }
                int intSelectedNodeValue = Convert.ToInt32(treeFolders.SelectedNode.Value);

                //get parameters
                if (this.Request.QueryString["Parent"] != null)
                {
                    _ParentID = Int32.Parse(this.Request.QueryString["Parent"]);
                }
                if (this.Request.QueryString["File"] != null)
                {
                    _FileID = Int32.Parse(this.Request.QueryString["File"]);
                }

                FileController fileCtrl = new FileController();
                File targetFile = fileCtrl.Get(_FileID);
                File destinationFolder = fileCtrl.Get(intSelectedNodeValue);
                if (destinationFolder == null)
                {
                    destinationFolder = new File();
                    destinationFolder.ID = -1;
                    destinationFolder.Name = "Portal Root Folder";
                }

                var orginalLocation = fileCtrl.Get(targetFile.ParentID);

                targetFile.ParentID = intSelectedNodeValue;
                string strEventType = "Moved";
                if (targetFile.IsInTrash)
                {
                    strEventType = "Restored";
                }
                targetFile.IsInTrash = false;
                if (UserId != -1)
                {
                    targetFile.LastModifiedByUserName = UserInfo.DisplayName;
                }
                else
                {
                    targetFile.LastModifiedByUserName = "******";
                }
                targetFile.LastModifiedByUserID = -1;
                targetFile.LastModifiedDate = System.DateTime.Now;
                fileCtrl.Update(targetFile);

                #region "Audit"
                //Audit: Create Item
                AuditController ctrlAudit = new AuditController();
                Audit moveAudit;
                if (strEventType == "Moved")
                {
                    moveAudit = new Audit() { EventDate = targetFile.LastModifiedDate, EventDetails = String.Format("From: {0}(ID:{1}) to: {2}(ID:{3})", orginalLocation.Name, orginalLocation.ID.ToString(), destinationFolder.Name, destinationFolder.ID.ToString()), EventName = strEventType, FileID = targetFile.ID, UserID = UserId };
                }
                else
                {
                    moveAudit = new Audit() { EventDate = targetFile.LastModifiedDate, EventDetails = String.Format("To: {0}(ID:{1})", destinationFolder.Name, destinationFolder.ID.ToString()), EventName = strEventType, FileID = targetFile.ID, UserID = UserId };
                }
                ctrlAudit.Create(moveAudit);
                #endregion

                //refresh cac
                SynchronizeModule();

                //Redirect back to the portal home page
                this.Response.Redirect(Globals.NavigateURL(this.TabId, "", "Folder=" + _ParentID, "ModuleID=" + ModuleId, "UserID=" + _userIDParameter, "GroupID=" + _roleIDParameter, String.Format("Success={0} moved to: {1}", targetFile.Name, destinationFolder.Name), "View=" + _view), true);
            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }