private int Compare (int sortColumnIndex, DocumentInfo objX, DocumentInfo objY)
        {
            var objSortColumn = default(DocumentsSortColumnInfo);
            int intResult = 0;

            if (sortColumnIndex >= mobjSortColumns.Count) {
                return 0;
            }

            objSortColumn = (DocumentsSortColumnInfo) mobjSortColumns [sortColumnIndex];

            if (objSortColumn.Direction == DocumentsSortColumnInfo.SortDirection.Ascending) {
                intResult = CompareValues (objSortColumn.ColumnName, objX, objY);
            }
            else {
                intResult = CompareValues (objSortColumn.ColumnName, objY, objX);
            }

            // Difference not found, sort by next sort column
            if (intResult == 0) {
                return Compare (sortColumnIndex + 1, objX, objY);
            }

            return intResult;
        }
Exemplo n.º 2
0
		/// <summary>
		/// Compares two documents and returns a value indicating whether one is less than, 
		/// equal to, or greater than the other. This method is of Comparison<T> delegate type
		/// </summary>
		/// <param name="x">First document.</param>
		/// <param name="y">Second document.</param>
		public int Compare (DocumentInfo x, DocumentInfo y)
		{
			if (mobjSortColumns.Count == 0)
				return 0;

			return Compare (0, x, y);
		}
Exemplo n.º 3
0
		/// -----------------------------------------------------------------------------
		/// <summary>
		/// ImportModule implements the IPortable ImportModule Interface
		/// </summary>
		/// <remarks>
		/// </remarks>
		/// <param name="ModuleID">The Id of the module to be imported</param>
		/// <history>
		///		[cnurse]	    17 Nov 2004	documented
		///		[aglenwright]	18 Feb 2006	Added new fields: Createddate, description, 
		///                             modifiedbyuser, modifieddate, OwnedbyUser, SortorderIndex
		///                             Added DocumentsSettings
		///   [togrean]     10 Jul 2007 Fixed issues with importing documet settings since new fileds 
		///                             were added: AllowSorting, default folder, list name    
		///   [togrean]     13 Jul 2007 Added support for importing documents Url tracking options     
		/// </history>
		/// -----------------------------------------------------------------------------
		public void ImportModule (int moduleId, string content, string version, int userId)
		{
            var mCtrl = new ModuleController ();
            var module = mCtrl.GetModule (moduleId, Null.NullInteger);
			
			var xmlDocuments = Globals.GetContent (content, "documents");
			var documentNodes = xmlDocuments.SelectNodes ("document");

            foreach (XmlNode documentNode in documentNodes)
			{
                var document = new DocumentInfo ();
				document.ModuleId = moduleId;
				document.Title = documentNode ["title"].InnerText;
				
                var strUrl = documentNode ["url"].InnerText;
                document.Url = strUrl.StartsWith ("fileid=", StringComparison.InvariantCultureIgnoreCase) ?
                    strUrl : Globals.ImportUrl (moduleId, strUrl);

				document.Category = documentNode ["category"].InnerText;
				document.Description = XmlUtils.GetNodeValue (documentNode, "description");
				document.OwnedByUserId = XmlUtils.GetNodeValueInt (documentNode, "ownedbyuserid");
				document.SortOrderIndex = XmlUtils.GetNodeValueInt (documentNode, "sortorderindex");
                document.LinkAttributes = XmlUtils.GetNodeValue (documentNode, "linkattributes");
                document.ForceDownload = XmlUtils.GetNodeValueBoolean (documentNode, "forcedownload");
                document.IsPublished = XmlUtils.GetNodeValueBoolean (documentNode, "ispublished");

				document.CreatedByUserId = userId;
				document.ModifiedByUserId = userId;
				
				var now = DateTime.Now;
				document.CreatedDate = now;
				document.ModifiedDate = now;

				Add<DocumentInfo> (document);

				// Update Tracking options
                var urlType = document.Url.StartsWith ("fileid=", StringComparison.InvariantCultureIgnoreCase)? "F" : "U";

                var urlCtrl = new UrlController ();
				// If nodes not found, all values will be false
				urlCtrl.UpdateUrl (module.PortalID, document.Url, urlType, XmlUtils.GetNodeValueBoolean (documentNode, "logactivity"), XmlUtils.GetNodeValueBoolean (documentNode, "trackclicks", true), moduleId, XmlUtils.GetNodeValueBoolean (documentNode, "newwindow"));
			}

            var xmlSettings = Globals.GetContent (content, "documents/settings");
			if (xmlSettings != null)
			{
				var settings = new DocumentsSettings (module);
			
				settings.AllowUserSort = XmlUtils.GetNodeValueBoolean (xmlSettings, "allowusersort");
				settings.ShowTitleLink = XmlUtils.GetNodeValueBoolean (xmlSettings, "showtitlelink");
				settings.UseCategoriesList = XmlUtils.GetNodeValueBoolean (xmlSettings, "usecategorieslist");
				settings.CategoriesListName = XmlUtils.GetNodeValue (xmlSettings, "categorieslistname");
				settings.DefaultFolder = Utils.ParseToNullableInt (XmlUtils.GetNodeValue (xmlSettings, "defaultfolder"));
				settings.DisplayColumns = XmlUtils.GetNodeValue (xmlSettings, "displaycolumns");
				settings.SortOrder = XmlUtils.GetNodeValue (xmlSettings, "sortorder");

				// Need Utils.SynchronizeModule() call
			}
		}
Exemplo n.º 4
0
		public void UpdateDocumentUrl (DocumentInfo document, string oldUrl, int PortalId, int ModuleId)
		{
			if (document.Url != oldUrl)
			{
				var ctrlUrl = new UrlController ();
	
				// get tracking data for the old URL
				var url = ctrlUrl.GetUrlTracking (PortalId, oldUrl, ModuleId);
				
				// delete old URL tracking data
				DataProvider.Instance ().DeleteUrlTracking (PortalId, oldUrl, ModuleId);
				
				// create new URL tracking data
				ctrlUrl.UpdateUrl (PortalId, document.Url, url.UrlType, url.LogActivity, url.TrackClicks, ModuleId, url.NewWindow);
			}
		}
Exemplo n.º 5
0
        /// <summary>
        /// Deletes the resource, accociated with the document (only files and URLs are supported).
        /// </summary>
        /// <param name="document">Document.</param>
        /// <param name="portalId">Portal identifier.</param>
        public int DeleteDocumentResource (DocumentInfo document, int portalId)
        {
            // count resource references
            var count = GetObjects<DocumentInfo> ("WHERE [ItemID] <> @0 AND [Url] = @1", document.ItemId, document.Url).Count ();

            // if no other document references it
            if (count == 0)
            {
                switch (Globals.GetURLType (document.Url))
                {
                    // delete file
                    case TabType.File:
                        var file = FileManager.Instance.GetFile (Utils.GetResourceId (document.Url));
                        if (file != null)
                            FileManager.Instance.DeleteFile (file);
                        break;

                    // delete URL
                    case TabType.Url:
                        new UrlController ().DeleteUrl (portalId, document.Url);
                        break;
                }
            }

            return count;
        }
 public DocumentInfoFormatter (DocumentInfo document)
 {
     Document = document;
 }
        private int CompareValues (string columnName, DocumentInfo objX, DocumentInfo objY)
        {
            switch (columnName) {
                case DocumentsDisplayColumnInfo.COLUMN_SORTORDER:
                    if (objX.SortOrderIndex.CompareTo (objY.SortOrderIndex) != 0) {
                        return objX.SortOrderIndex.CompareTo (objY.SortOrderIndex);
                    }
                    break;

                case DocumentsDisplayColumnInfo.COLUMN_CATEGORY:
                    if (objX.Category.CompareTo (objY.Category) != 0) {
                        return objX.Category.CompareTo (objY.Category);
                    }
                    break;

                case DocumentsDisplayColumnInfo.COLUMN_CREATEDBY:
                    if (objX.CreatedByUser.CompareTo (objY.CreatedByUser) != 0) {
                        return objX.CreatedByUser.CompareTo (objY.CreatedByUser);
                    }
                    break;

                case DocumentsDisplayColumnInfo.COLUMN_CREATEDDATE:
                    if (objX.CreatedDate.CompareTo (objY.CreatedDate) != 0) {
                        return objX.CreatedDate.CompareTo (objY.CreatedDate);
                    }
                    break;

                case DocumentsDisplayColumnInfo.COLUMN_DESCRIPTION:
                    if (objX.Description.CompareTo (objY.Description) != 0) {
                        return objX.Description.CompareTo (objY.Description);
                    }
                    break;
                case DocumentsDisplayColumnInfo.COLUMN_MODIFIEDBY:
                    if (objX.ModifiedByUser.CompareTo (objY.ModifiedByUser) != 0) {
                        return objX.ModifiedByUser.CompareTo (objY.ModifiedByUser);
                    }
                    break;

                case DocumentsDisplayColumnInfo.COLUMN_MODIFIEDDATE:
                    if (objX.ModifiedDate.CompareTo (objY.ModifiedDate) != 0) {
                        return objX.ModifiedDate.CompareTo (objY.ModifiedDate);
                    }
                    break;

                case DocumentsDisplayColumnInfo.COLUMN_OWNEDBY:
                    if (objX.OwnedByUser.CompareTo (objY.OwnedByUser) != 0) {
                        return objX.OwnedByUser.CompareTo (objY.OwnedByUser);
                    }
                    break;

                case DocumentsDisplayColumnInfo.COLUMN_SIZE:
                    if (objX.Size.CompareTo (objY.Size) != 0) {
                        return objX.Size.CompareTo (objY.Size);
                    }
                    break;

                case DocumentsDisplayColumnInfo.COLUMN_TITLE:
                    if (objX.Title.CompareTo (objY.Title) != 0) {
                        return objX.Title.CompareTo (objY.Title);
                    }
                    break;

                case DocumentsDisplayColumnInfo.COLUMN_CLICKS:
                    if (objX.Clicks.CompareTo (objY.Clicks) != 0) {
                        return objX.Clicks.CompareTo (objY.Clicks);
                    }
                    break;
            }

            return 0;
        }
Exemplo n.º 8
0
		private void Update (bool Override)
		{
			try
			{
				// Only Update if Input Data is Valid

				if (Page.IsValid == true)
				{
					if (!Override)
					{
						// Test file exists, security
						if (!CheckFileExists (ctlUrl.Url) || !CheckFileSecurity (ctlUrl.Url))
						{
							this.cmdUpdateOverride.Visible = true;
							this.cmdUpdate.Visible = false;

							// '' Display page-level warning instructing users to click update again if they want to ignore the warning
							DotNetNuke.UI.Skins.Skin.AddPageMessage (this.Page, Localization.GetString ("msgFileWarningHeading.Text", this.LocalResourceFile), DotNetNuke.Services.Localization.Localization.GetString ("msgFileWarning.Text", this.LocalResourceFile), DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.YellowWarning);
							return;
						}
					}

					// Get existing document record
					var objDocument = DocumentsController.GetDocument (ItemID, ModuleId);

					if (objDocument == null)
					{
						// New record
						objDocument = new DocumentInfo ();
						objDocument.ItemId = ItemID;
						objDocument.ModuleId = ModuleId;
						
						objDocument.CreatedByUserId = UserInfo.UserID;
						
						// Default ownerid value for new documents is current user, may be changed
						// by the value of the dropdown list (below)
						objDocument.OwnedByUserId = UserId;
					}
				
					objDocument.IsPublished = checkIsPublished.Checked;
					objDocument.ModifiedByUserId = UserInfo.UserID;

					objDocument.Title = txtName.Text;
					objDocument.Description = txtDescription.Text;
					objDocument.ForceDownload = chkForceDownload.Checked;

					var oldUrl = objDocument.Url;
					objDocument.Url = ctlUrl.Url;
                    objDocument.LinkAttributes = textLinkAttributes.Text;
					
					if (lstOwner.Visible)
					{
						if (lstOwner.SelectedValue != string.Empty)
						{
							objDocument.OwnedByUserId = Convert.ToInt32 (lstOwner.SelectedValue);
						}
						else
						{
							objDocument.OwnedByUserId = -1;
						}
					}
					else
					{
						// User never clicked "change", leave ownedbyuserid as is
					}

					if (txtCategory.Visible)
					{
						objDocument.Category = txtCategory.Text;
					}
					else
					{
						if (lstCategory.SelectedItem.Text == Localization.GetString ("None_Specified"))
						{
							objDocument.Category = "";
						}
						else
						{
							objDocument.Category = lstCategory.SelectedItem.Value;
						}
					}

					// getting sort index
					int sortIndex;
					objDocument.SortOrderIndex = int.TryParse (txtSortIndex.Text, out sortIndex) ? sortIndex : 0;

					#region Update date & time

					var now = DateTime.Now;
					
					if (pickerCreatedDate.SelectedDate != null)
					{
						if (Null.IsNull (ItemID) || objDocument.CreatedDate != pickerCreatedDate.SelectedDate.Value)
							objDocument.CreatedDate = pickerCreatedDate.SelectedDate.Value;
						// else leave CreatedDate as is
					}
					else
					{
						objDocument.CreatedDate = now;
					}

					if (pickerLastModifiedDate.SelectedDate != null)
					{
                        if (!checkDontUpdateLastModifiedDate.Checked)
                        {
                            if (Null.IsNull (ItemID) || objDocument.ModifiedDate != pickerLastModifiedDate.SelectedDate.Value)
    							objDocument.ModifiedDate = pickerLastModifiedDate.SelectedDate.Value;
                            else 
    							// update ModifiedDate
    							objDocument.ModifiedDate = now;
                        }
					}
					else
					{
						objDocument.ModifiedDate = now;
					}

					#endregion

					if (Null.IsNull (ItemID))
					{
						DocumentsController.Add (objDocument);
					}
					else
					{
						DocumentsController.Update (objDocument);
						if (objDocument.Url != oldUrl)
						{
							// delete old URL tracking data
							DocumentsController.DeleteDocumentUrl (oldUrl, PortalId, ModuleId);
						}
					}

					// add or update URL tracking
					var ctrlUrl = new UrlController ();
					ctrlUrl.UpdateUrl (PortalId, ctlUrl.Url, ctlUrl.UrlType, ctlUrl.Log, ctlUrl.Track, ModuleId, ctlUrl.NewWindow);

                    Synchronize ();
					
					// Redirect back to the portal home page
					Response.Redirect (Globals.NavigateURL (), true);

				}
				//Module failed to load
			}
			catch (Exception exc)
			{
				Exceptions.ProcessModuleLoadException (this, exc);
			}
		}