public override void HandleRequest()
		{
			string output = null;
			DialogParams dialogParams = Content.FromJson<DialogParams>(); // This uses the new JSON Extensions in DotNetNuke.Common.Utilities.JsonExtensionsWeb

			string link = dialogParams.LinkUrl;
			dialogParams.LinkClickUrl = link;

			if (dialogParams != null)
			{

				if (! (dialogParams.LinkAction == "GetLinkInfo"))
				{
					if (dialogParams.Track)
					{
						string tempVar = dialogParams.LinkUrl;
						dialogParams.LinkClickUrl = GetLinkClickURL(ref dialogParams, ref tempVar);
						dialogParams.LinkUrl = tempVar;
						UrlTrackingInfo linkTrackingInfo = _urlController.GetUrlTracking(dialogParams.PortalId, dialogParams.LinkUrl, dialogParams.ModuleId);

						if (linkTrackingInfo != null)
						{
							dialogParams.Track = linkTrackingInfo.TrackClicks;
							dialogParams.TrackUser = linkTrackingInfo.LogActivity;
							dialogParams.DateCreated = linkTrackingInfo.CreatedDate.ToString();
							dialogParams.LastClick = linkTrackingInfo.LastClick.ToString();
							dialogParams.Clicks = linkTrackingInfo.Clicks.ToString();
						}
						else
						{
							dialogParams.Track = false;
							dialogParams.TrackUser = false;
						}
						dialogParams.LinkUrl = link;

					}
				}

				switch (dialogParams.LinkAction)
				{
					case "GetLoggingInfo": //also meant for the tracking tab but this is to retrieve the user information
						DateTime logStartDate = DateTime.MinValue;
						DateTime logEndDate = DateTime.MinValue;
						string logText = "<table><tr><th>Date</th><th>User</th></tr><tr><td colspan='2'>The selected date-range did<br /> not return any results.</td></tr>";

						if (DateTime.TryParse(dialogParams.LogStartDate, out logStartDate))
						{
							if (! (DateTime.TryParse(dialogParams.LogEndDate, out logEndDate)))
							{
								logEndDate = logStartDate.AddDays(1);
							}

							UrlController _urlController = new UrlController();
							ArrayList urlLog = _urlController.GetUrlLog(dialogParams.PortalId, GetLinkUrl(ref dialogParams, dialogParams.LinkUrl), dialogParams.ModuleId, logStartDate, logEndDate);

							if (urlLog != null)
							{
								logText = GetUrlLoggingInfo(urlLog);
							}

						}

						dialogParams.TrackingLog = logText;

						break;
					case "GetLinkInfo":
						if (dialogParams.Track)
						{
                            link = link.Replace(@"\", @"/");

							//this section is for when the user clicks ok in the dialog box, we actually create a record for the linkclick urls.
							if (! (dialogParams.LinkUrl.ToLower().Contains("linkclick.aspx")))
							{
								dialogParams.LinkClickUrl = GetLinkClickURL(ref dialogParams, ref link);
							}

							_urlController.UpdateUrl(dialogParams.PortalId, link, GetURLType(Globals.GetURLType(link)), dialogParams.TrackUser, true, dialogParams.ModuleId, false);

						}
						else
						{
							//this section is meant for retrieving/displaying the original links and determining if the links are being tracked(making sure the track checkbox properly checked)
							UrlTrackingInfo linkTrackingInfo = null;

							if (dialogParams.LinkUrl.Contains("fileticket"))
							{
								var queryString = dialogParams.LinkUrl.Split('=');
								var encryptedFileId = queryString[1].Split('&')[0];

								string fileID = UrlUtils.DecryptParameter(encryptedFileId, dialogParams.PortalGuid);
								FileInfo savedFile = _fileController.GetFileById(Int32.Parse(fileID), dialogParams.PortalId);

								linkTrackingInfo = _urlController.GetUrlTracking(dialogParams.PortalId, string.Format("fileID={0}", fileID), dialogParams.ModuleId);
								
							}
                            else if (dialogParams.LinkUrl.ToLowerInvariant().Contains("linkclick.aspx"))
							{
								try
								{
									if (dialogParams.LinkUrl.Contains("?"))
									{
										link = dialogParams.LinkUrl.Split('?')[1].Split('&')[0];
										if(link.Contains("="))
										{
											link = link.Split('=')[1];
										}
									}

									int tabId = 0;
									if (int.TryParse(link, out tabId)) //if it's a tabid get the tab path
									{
										var tabController = new TabController();
										dialogParams.LinkClickUrl = tabController.GetTab(tabId, dialogParams.PortalId, true).FullUrl;
										linkTrackingInfo = _urlController.GetUrlTracking(dialogParams.PortalId, tabId.ToString(), dialogParams.ModuleId);
									}
									else
									{
										dialogParams.LinkClickUrl = HttpContext.Current.Server.UrlDecode(link); //get the actual link
										linkTrackingInfo = _urlController.GetUrlTracking(dialogParams.PortalId, dialogParams.LinkClickUrl, dialogParams.ModuleId);
									}

								}
								catch (Exception ex)
								{
								    Logger.Error(ex);
									dialogParams.LinkClickUrl = dialogParams.LinkUrl;
								}
							}

							if (linkTrackingInfo == null)
							{
								dialogParams.Track = false;
								dialogParams.TrackUser = false;
							}
							else
							{
								dialogParams.Track = linkTrackingInfo.TrackClicks;
								dialogParams.TrackUser = linkTrackingInfo.LogActivity;
							}

						}
						break;
				}
				output = dialogParams.ToJson();
			}

			Response.Write(output);
		}
Exemplo n.º 2
0
 private void cmdDisplay_Click(object sender, EventArgs e)
 {
     try
     {
         string strStartDate = txtStartDate.Text;
         if (!String.IsNullOrEmpty(strStartDate))
         {
             strStartDate = strStartDate + " 00:00";
         }
         string strEndDate = txtEndDate.Text;
         if (!String.IsNullOrEmpty(strEndDate))
         {
             strEndDate = strEndDate + " 23:59";
         }
         var objUrls = new UrlController();
         //localize datagrid
         Localization.LocalizeDataGrid(ref grdLog, LocalResourceFile);
         grdLog.DataSource = objUrls.GetUrlLog(PortalSettings.PortalId, lblLogURL.Text, ModuleID, Convert.ToDateTime(strStartDate), Convert.ToDateTime(strEndDate));
         grdLog.DataBind();
     }
     catch (Exception exc) //Module failed to load
     {
         Exceptions.ProcessModuleLoadException(this, exc);
     }
 }