Beispiel #1
0
        private void DoChangeURL()
        {
            string _Url     = Convert.ToString(ViewState["Url"]);
            string _Urltype = Convert.ToString(ViewState["UrlType"]);

            if (!String.IsNullOrEmpty(_Url))
            {
                var    objUrls     = new UrlController();
                string TrackingUrl = _Url;

                _Urltype = Globals.GetURLType(_Url).ToString("g").Substring(0, 1);
                if (_Urltype == "U" && (_Url.StartsWith("~/" + PortalSettings.DefaultIconLocation, StringComparison.InvariantCultureIgnoreCase)))
                {
                    _Urltype = "I";
                }
                ViewState["UrlType"] = _Urltype;
                if (_Urltype == "F")
                {
                    if (_Url.ToLower().StartsWith("fileid="))
                    {
                        TrackingUrl = _Url;
                        var objFile = FileManager.Instance.GetFile(int.Parse(_Url.Substring(7)));
                        if (objFile != null)
                        {
                            _Url = objFile.Folder + objFile.FileName;
                        }
                    }
                    else
                    {
                        //to handle legacy scenarios before the introduction of the FileServerHandler
                        var fileName   = Path.GetFileName(_Url);
                        var folderPath = _Url.Substring(0, _Url.LastIndexOf(fileName));
                        var folder     = FolderManager.Instance.GetFolder(_objPortal.PortalID, folderPath);
                        var fileId     = -1;
                        if (folder != null)
                        {
                            var file = FileManager.Instance.GetFile(folder, fileName);
                            if (file != null)
                            {
                                fileId = file.FileId;
                            }
                        }
                        TrackingUrl = "FileID=" + fileId.ToString();
                    }
                }
                if (_Urltype == "M")
                {
                    if (_Url.ToLower().StartsWith("userid="))
                    {
                        UserInfo objUser = UserController.GetUserById(_objPortal.PortalID, int.Parse(_Url.Substring(7)));
                        if (objUser != null)
                        {
                            _Url = objUser.Username;
                        }
                    }
                }
                UrlTrackingInfo objUrlTracking = objUrls.GetUrlTracking(_objPortal.PortalID, TrackingUrl, ModuleID);
                if (objUrlTracking != null)
                {
                    chkNewWindow.Checked = objUrlTracking.NewWindow;
                    chkTrack.Checked     = objUrlTracking.TrackClicks;
                    chkLog.Checked       = objUrlTracking.LogActivity;
                }
                else //the url does not exist in the tracking table
                {
                    chkTrack.Checked = false;
                    chkLog.Checked   = false;
                }
                ViewState["Url"] = _Url;
            }
            else
            {
                if (!String.IsNullOrEmpty(_Urltype))
                {
                    optType.ClearSelection();
                    if (optType.Items.FindByValue(_Urltype) != null)
                    {
                        optType.Items.FindByValue(_Urltype).Selected = true;
                    }
                    else
                    {
                        optType.Items[0].Selected = true;
                    }
                }
                else
                {
                    if (optType.Items.Count > 0)
                    {
                        optType.ClearSelection();
                        optType.Items[0].Selected = true;
                    }
                }
                chkNewWindow.Checked = false; //Need check
                chkTrack.Checked     = false; //Need check
                chkLog.Checked       = false; //Need check
            }

            //Url type changed, then we must draw the controlos for that type
            _doRenderTypeControls = true;
        }
Beispiel #2
0
        /// <summary>
        /// The Page_Load server event handler on this page is used to populate the role information for the page
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                //this needs to execute always to the client script code is registred in InvokePopupCal
                cmdStartCalendar.NavigateUrl = Calendar.InvokePopupCal(txtStartDate);
                cmdEndCalendar.NavigateUrl   = Calendar.InvokePopupCal(txtEndDate);

                if (!Page.IsPostBack)
                {
                    if (!String.IsNullOrEmpty(_URL))
                    {
                        lblLogURL.Text = URL; // saved for loading Log grid

                        TabType URLType = Globals.GetURLType(_URL);
                        if (URLType == TabType.File && _URL.ToLower().StartsWith("fileid=") == false)
                        {
                            // to handle legacy scenarios before the introduction of the FileServerHandler
                            FileController objFiles = new FileController();
                            lblLogURL.Text = "FileID=" + objFiles.ConvertFilePathToFileId(_URL, PortalSettings.PortalId);
                        }

                        UrlController   objUrls        = new UrlController();
                        UrlTrackingInfo objUrlTracking = objUrls.GetUrlTracking(PortalSettings.PortalId, lblLogURL.Text, ModuleID);
                        if (objUrlTracking != null)
                        {
                            if (_FormattedURL == "")
                            {
                                if (!URL.StartsWith("http") && !URL.StartsWith("mailto"))
                                {
                                    lblURL.Text = Globals.AddHTTP(Request.Url.Host);
                                }
                                lblURL.Text += Globals.LinkClick(URL, PortalSettings.ActiveTab.TabID, ModuleID, false);
                            }
                            else
                            {
                                lblURL.Text = _FormattedURL;
                            }
                            lblCreatedDate.Text = objUrlTracking.CreatedDate.ToString();

                            if (objUrlTracking.TrackClicks)
                            {
                                pnlTrack.Visible = true;
                                if (_TrackingURL == "")
                                {
                                    if (!URL.StartsWith("http"))
                                    {
                                        lblTrackingURL.Text = Globals.AddHTTP(Request.Url.Host);
                                    }
                                    lblTrackingURL.Text += Globals.LinkClick(URL, PortalSettings.ActiveTab.TabID, ModuleID, objUrlTracking.TrackClicks);
                                }
                                else
                                {
                                    lblTrackingURL.Text = _TrackingURL;
                                }
                                lblClicks.Text = objUrlTracking.Clicks.ToString();
                                if (!Null.IsNull(objUrlTracking.LastClick))
                                {
                                    lblLastClick.Text = objUrlTracking.LastClick.ToString();
                                }
                            }

                            if (objUrlTracking.LogActivity)
                            {
                                pnlLog.Visible = true;

                                txtStartDate.Text = DateAndTime.DateAdd(DateInterval.Day, -6, DateTime.Today).ToShortDateString();
                                txtEndDate.Text   = DateAndTime.DateAdd(DateInterval.Day, 1, DateTime.Today).ToShortDateString();
                            }
                        }
                    }
                    else
                    {
                        this.Visible = false;
                    }
                }
            }
            catch (Exception exc)  //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
Beispiel #3
0
        void FillTypeColumns(int moduleId, TokenReplace objTokenReplace, PortalSettings portalSettings,
                             TabController tabCtrl,
                             DataRow row, FieldSetting field)
        {
            var link = row[field.Title].ToString();
            //Link showed to the user
            bool openInNewWindow;

            if (field.ShowOpenInNewWindow)  //mit URL gepeicherten Wert lesen
            {
                openInNewWindow = UrlUtil.OpenUrlInNewWindow(link);
            }
            else
            {
                switch (Globals.GetURLType(UrlUtil.StripURL(link)))
                {
                case TabType.File:
                    openInNewWindow = true;
                    break;

                case TabType.Tab:     //link to internal tab
                    openInNewWindow = false;
                    break;

                default:
                    openInNewWindow = link.Like(Globals.ApplicationMapPath + "*");
                    break;
                }
            }

            //set caption:
            var caption = field.OutputFormat;

            if (!string.IsNullOrEmpty(caption))
            {
                caption = objTokenReplace.ReplaceEnvironmentTokens(caption, row);
            }
            var isLink = true;

            //Link readable by browsers
            link = UrlUtil.StripURL(link);
            var url = Globals.LinkClick(link, portalSettings.ActiveTab.TabID, moduleId, field.TrackDownloads, field.EnforceDownload);

            if (link != string.Empty)
            {
                switch (Globals.GetURLType(link))
                {
                case TabType.Tab:
                    var tab = tabCtrl.GetTab(int.Parse(link), portalSettings.PortalId, false);
                    if (tab != null)
                    {
                        if (caption == string.Empty)
                        {
                            if (!field.Abbreviate)
                            {
                                var strPath = string.Empty;
                                if (tab.BreadCrumbs != null && tab.BreadCrumbs.Count > 0)
                                {
                                    foreach (TabInfo b in tab.BreadCrumbs)
                                    {
                                        var strLabel = b.TabName;
                                        if (strPath != string.Empty)
                                        {
                                            strPath +=
                                                string.Format(
                                                    "<img src=\"{0}/images/breadcrumb.gif\" border=\"0\" alt=\"Spacer\"/>",
                                                    Globals.ApplicationPath);
                                        }
                                        strPath += strLabel;
                                    }
                                }
                                caption = tab.TabPath.Replace("//",
                                                              string.Format(
                                                                  "<img src=\"{0}/images/breadcrumb.gif\" border=\"0\" alt=\"Spacer\"/>",
                                                                  Globals.ApplicationPath));
                            }
                            else
                            {
                                caption = tab.TabName;
                            }
                        }
                        url = field.EnforceDownload ? url : Globals.NavigateURL(int.Parse(link));
                    }
                    else
                    {
                        caption = Localization.GetString("PageNotFound.ErrorMessage",
                                                         Globals.ResolveUrl(
                                                             string.Format("~{0}{1}/SharedResources.resx",
                                                                           Definition.PathOfModule,
                                                                           Localization.LocalResourceDirectory)));
                        url    = string.Empty;
                        isLink = false;
                    }
                    break;

                case TabType.File:
                    if (caption == string.Empty)
                    {
                        if (link.ToLowerInvariant().StartsWith("fileid="))
                        {
                            var file = FileManager.Instance.GetFile(int.Parse(link.Substring(7)));
                            if (file != null)
                            {
                                if (!field.Abbreviate)
                                {
                                    caption = file.Folder + file.FileName;
                                }
                                else
                                {
                                    caption = file.FileName;
                                }
                            }
                        }
                        else if (field.Abbreviate && link.IndexOf("/", StringComparison.Ordinal) > -1)
                        {
                            caption = link.Substring(Convert.ToInt32(link.LastIndexOf("/", StringComparison.Ordinal) + 1));
                        }
                        else
                        {
                            caption = link;
                        }
                    }
                    break;

                case TabType.Url:
                case TabType.Normal:
                    if (caption == string.Empty)
                    {
                        if (field.Abbreviate && link.IndexOf("/", StringComparison.Ordinal) > -1)
                        {
                            caption = link.Substring(Convert.ToInt32(link.LastIndexOf("/", StringComparison.Ordinal) + 1));
                        }
                        else
                        {
                            caption = link;
                        }
                    }
                    if (!field.TrackDownloads)
                    {
                        url = link;
                    }
                    break;
                }


                if (field.EnforceDownload)
                {
                    url += "&amp;forcedownload=true";
                }

                string strFieldvalue;
                if (isLink)
                {
                    strFieldvalue = string.Format("<!--{1}--><a href=\"{0}\"{2}>{1}</a>", url,
                                                  caption, (openInNewWindow ? " target=\"_blank\"" : ""));
                }
                else
                {
                    strFieldvalue = caption;
                }
                row[field.Title] = strFieldvalue;
                row[field.Title + DataTableColumn.Appendix_Caption]  = caption;
                row[field.Title + DataTableColumn.Appendix_Original] = link;
                row[field.Title + DataTableColumn.Appendix_Url]      = url;
            }
        }
Beispiel #4
0
        private void ShowControls()
        {
            UrlController objUrls = new UrlController();

            // set url type
            if (optType.SelectedItem == null)
            {
                if (!String.IsNullOrEmpty(_Url))
                {
                    string TrackingUrl = _Url;

                    _UrlType = Globals.GetURLType(_Url).ToString("g").Substring(0, 1);

                    if (_UrlType == "F")
                    {
                        FileController objFiles = new FileController();
                        if (_Url.ToLower().StartsWith("fileid="))
                        {
                            TrackingUrl = _Url;
                            FileInfo objFile = objFiles.GetFileById(int.Parse(_Url.Substring(7)), _objPortal.PortalID);
                            if (objFile != null)
                            {
                                _Url = objFile.Folder + objFile.FileName;
                            }
                        }
                        else
                        {
                            // to handle legacy scenarios before the introduction of the FileServerHandler
                            TrackingUrl = "FileID=" + objFiles.ConvertFilePathToFileId(_Url, _objPortal.PortalID);
                        }
                    }

                    if (_UrlType == "M")
                    {
                        if (_Url.ToLower().StartsWith("userid="))
                        {
                            UserInfo objUser = UserController.GetUser(_objPortal.PortalID, int.Parse(_Url.Substring(7)), false);
                            if (objUser != null)
                            {
                                _Url = objUser.Username;
                            }
                        }
                    }

                    UrlTrackingInfo objUrlTracking = objUrls.GetUrlTracking(_objPortal.PortalID, TrackingUrl, ModuleID);
                    if (objUrlTracking != null)
                    {
                        optType.Items.FindByValue(objUrlTracking.UrlType).Selected = true;
                        chkNewWindow.Checked = objUrlTracking.NewWindow;
                        chkTrack.Checked     = objUrlTracking.TrackClicks;
                        chkLog.Checked       = objUrlTracking.LogActivity;
                    }
                    else // the url does not exist in the tracking table
                    {
                        optType.Items.FindByValue(_UrlType).Selected = true;
                        chkNewWindow.Checked = false;
                        chkTrack.Checked     = true;
                        chkLog.Checked       = false;
                    }
                }
                else
                {
                    if (!String.IsNullOrEmpty(_UrlType))
                    {
                        if (optType.Items.FindByValue(_UrlType) != null)
                        {
                            optType.Items.FindByValue(_UrlType).Selected = true;
                        }
                        else
                        {
                            optType.Items[0].Selected = true;
                        }
                    }
                    else
                    {
                        optType.Items[0].Selected = true;
                    }
                    chkNewWindow.Checked = false;
                    chkTrack.Checked     = true;
                    chkLog.Checked       = false;
                }
            }

            // load listitems
            switch (optType.SelectedItem.Value)
            {
            case "N":     // None

                URLRow.Visible  = false;
                TabRow.Visible  = false;
                FileRow.Visible = false;
                UserRow.Visible = false;
                break;

            case "U":     // Url

                URLRow.Visible  = true;
                TabRow.Visible  = false;
                FileRow.Visible = false;
                UserRow.Visible = false;

                if (txtUrl.Text == "")
                {
                    txtUrl.Text = _Url;
                }
                if (txtUrl.Text == "")
                {
                    txtUrl.Text = "http://";
                }
                txtUrl.Visible = true;

                cmdSelect.Visible = true;

                cboUrls.Items.Clear();
                cboUrls.DataSource = objUrls.GetUrls(_objPortal.PortalID);
                cboUrls.DataBind();
                if (cboUrls.Items.FindByValue(_Url) != null)
                {
                    cboUrls.Items.FindByValue(_Url).Selected = true;
                }
                cboUrls.Visible = false;

                cmdAdd.Visible    = false;
                cmdDelete.Visible = false;
                break;

            case "T":     // tab

                URLRow.Visible  = false;
                TabRow.Visible  = true;
                FileRow.Visible = false;
                UserRow.Visible = false;

                cboTabs.Items.Clear();

                cboTabs.DataSource = Globals.GetPortalTabs(_objPortal.PortalID, !_Required, true, false, false, false);
                cboTabs.DataBind();
                if (cboTabs.Items.FindByValue(_Url) != null)
                {
                    cboTabs.Items.FindByValue(_Url).Selected = true;
                }
                break;

            case "F":     // file

                URLRow.Visible  = false;
                TabRow.Visible  = false;
                FileRow.Visible = true;
                UserRow.Visible = false;

                LoadFolders();

                if (cboFolders.Items.Count == 0)
                {
                    lblMessage.Text = Localization.GetString("NoPermission", this.LocalResourceFile);
                    FileRow.Visible = false;
                    return;
                }

                // select folder
                string FileName;
                string FolderPath;
                if (_Url != string.Empty)
                {
                    FileName   = _Url.Substring(_Url.LastIndexOf("/") + 1);
                    FolderPath = _Url.Replace(FileName, "");
                }
                else
                {
                    FileName   = _Url;
                    FolderPath = string.Empty;
                }
                if (cboFolders.Items.FindByValue(FolderPath) != null)
                {
                    cboFolders.Items.FindByValue(FolderPath).Selected = true;
                }
                else
                {
                    cboFolders.Items[0].Selected = true;
                    FolderPath = cboFolders.SelectedValue;
                }

                //cboFiles.DataSource = GetFileList(FileFilter, !_Required, cboFolders.SelectedItem.Value);
                cboFiles.DataSource = GetFileList(!_Required);
                cboFiles.DataBind();
                if (cboFiles.Items.FindByText(FileName) != null)
                {
                    cboFiles.Items.FindByText(FileName).Selected = true;
                }
                cboFiles.Visible = true;
                txtFile.Visible  = false;

                string strWriteRoles = GetWriteRoles(FolderPath);
                cmdUpload.Visible = PortalSecurity.IsInRoles(strWriteRoles) && _ShowUpLoad;

                SetStorageLocationType();

                txtUrl.Visible    = false;
                cmdSave.Visible   = false;
                cmdCancel.Visible = false;
                break;

            case "M":     // membership users

                URLRow.Visible  = false;
                TabRow.Visible  = false;
                FileRow.Visible = false;
                UserRow.Visible = true;

                if (txtUser.Text == "")
                {
                    txtUser.Text = _Url;
                }
                break;
            }
        }