Ejemplo n.º 1
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            try
            {
                Controller = new BBStoreController();

                LocaleController            lc  = new LocaleController();
                Dictionary <string, Locale> loc = lc.GetLocales(PortalId);

                ModuleController objModules = new ModuleController();

                // If this is the first visit to the page
                if (Page.IsPostBack == false)
                {
                    UnitInfo unit = null;

                    if (Request["unitid"] != null)
                    {
                        UnitId = Convert.ToInt32(Request["unitid"]);
                    }

                    // if unit exists
                    if (UnitId > 0)
                    {
                        unit = Controller.GetUnit(UnitId);
                    }

                    List <ILanguageEditorInfo> dbLangs = new List <ILanguageEditorInfo>();
                    if (unit == null)
                    {
                        txtDecimals.Text = "0";
                        foreach (KeyValuePair <string, Locale> keyValuePair in loc)
                        {
                            UnitLangInfo unitLang = new UnitLangInfo();
                            unitLang.Language = keyValuePair.Key;
                            dbLangs.Add(unitLang);
                        }
                    }
                    else
                    {
                        txtDecimals.Text = unit.Decimals.ToString();
                        foreach (UnitLangInfo unitLang in Controller.GetUnitLangs(UnitId))
                        {
                            dbLangs.Add(unitLang);
                        }
                    }
                    lngUnits.Langs = dbLangs;
                }
            }

            catch (Exception exc)
            {
                //Module failed to load
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
Ejemplo n.º 2
0
        private List <string> GetPortalLanguages()
        {
            List <string>               languages = new List <string>();
            LocaleController            lc        = new LocaleController();
            Dictionary <string, Locale> loc       = lc.GetLocales(_moduleContext.PortalId);

            foreach (KeyValuePair <string, Locale> item in loc)
            {
                string cultureCode = item.Value.Culture.Name;
                languages.Add(cultureCode);
            }
            return(languages);
        }
Ejemplo n.º 3
0
        public void UpdatePlugg(Plugg p, PluggContent pc)
        {
            //For restore if something goes wrong
            Plugg oldP = GetPlugg(p.PluggId);
            IEnumerable <PluggContent> oldPCs = GetAllContentInPlugg(p.PluggId);

            rep.UpdatePlugg(p); //No repair necessary if this fails

            //For now, remove all PluggContent and recreate in all languages from pc. Fix this when we can deal with translations
            try
            {
                foreach (PluggContent pcDelete in oldPCs)
                {
                    rep.DeletePluggContent(pcDelete);
                }

                pc.PluggId = p.PluggId;
                if (pc.LatexText != null)
                {
                    LatexToMathMLConverter myConverter = new LatexToMathMLConverter(pc.LatexText);
                    myConverter.Convert();
                    pc.LatexTextInHtml = myConverter.HTMLOutput;
                }

                LocaleController lc = new LocaleController();
                var locales         = lc.GetLocales(PortalID);
                foreach (var locale in locales)
                {
                    pc.CultureCode = locale.Key;
                    rep.CreatePluggContent(pc);
                }
            }
            catch (Exception)
            {
                //recreate old Plugg/PluggContent before rethrow
                var pcs = GetAllContentInPlugg(p.PluggId);
                foreach (PluggContent pcDelete in pcs)
                {
                    rep.DeletePluggContent(pcDelete);
                }
                rep.DeletePlugg(p);

                rep.CreatePlugg(oldP);
                foreach (PluggContent oldPC in oldPCs)
                {
                    rep.CreatePluggContent(oldPC);
                }
                throw;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// This method will save the LatexText in all Culture Codes
        /// It expects the text to be created in t.CultureCode
        /// It will call SaveLatexText(t)
        /// It then translates t into all languages and calls SaveLatexText on each text
        /// </summary>
        /// <param name="t"></param>
        public void SaveLatexTextInAllCc(PHLatex t)
        {
            SaveLatexText(t);  //Save LatexText in created language
            LocaleController lc = new LocaleController();
            var locales         = lc.GetLocales(PortalID);

            foreach (var locale in locales)
            {
                if (locale.Key != t.CultureCode)
                {
                    t.Text = TranslateText(t.CultureCode.Substring(0, 2), locale.Key.Substring(0, 2), t.Text);

                    t.LatexId           = 0;
                    t.CultureCode       = locale.Key;
                    t.CultureCodeStatus = ECultureCodeStatus.GoogleTranslated;
                    SaveLatexText(t);
                }
            }
        }
Ejemplo n.º 5
0
        //public void CreateCourse(Course c, List<CourseItemEntity> cis)
        //{
        //    rep.CreateCourse(c);

        //    try
        //    {
        //        foreach (CourseItemEntity ci in cis)
        //        {
        //            ci.CourseId = c.CourseId;
        //            rep.CreateCourseItem(ci);
        //        }
        //    }
        //    catch (Exception)
        //    {
        //        DeleteCourse(c);
        //        throw;
        //    }

        //    //Create CoursePage
        //    DNNHelper d = new DNNHelper();
        //    string pageUrl = "C" + c.CourseId.ToString();
        //    string pageName = pageUrl + ": " + c.Title;
        //    try
        //    {
        //        TabInfo newTab = d.AddCoursePage(pageName, pageUrl);
        //        c.TabId = newTab.TabID;
        //        rep.UpdateCourse(c);
        //    }
        //    catch (Exception)
        //    {
        //        DeleteCourse(c);
        //        throw;
        //    }
        //}

        //public Course GetCourse(int CourseID)
        //{
        //    return rep.GetCourse(CourseID);
        //}

        //public void DeleteCourse(Course c)
        //{
        //    // Todo: Don't delete course if: It has comments or ratings
        //    // Todo: Soft delete of Course
        //    if (c == null)
        //    {
        //        throw new Exception("Cannot delete: Course not initialized");
        //        return;
        //    }

        //    TabController tabController = new TabController();
        //    TabInfo getTab = tabController.GetTab(c.TabId);

        //    if (getTab != null)
        //    {
        //        DNNHelper h = new DNNHelper();
        //        h.DeleteTab(getTab);
        //    }

        //    var cis = rep.GetItemsInCourse(c.CourseId);
        //    foreach (CourseItem ciDelete in cis)
        //    {
        //        rep.DeleteCourseItem(ciDelete);
        //    }

        //    rep.DeleteCourse(c);
        //}

        #endregion

        #region CourseItem

        //public IEnumerable<CourseItem> GetCourseItems(int CourseID, int ItemID)
        //{
        //    return rep.GetCourseItems(CourseID, ItemID);
        //}

        //public List<CourseItem> GetItemsInCourse(int courseId)
        //{
        //    return rep.GetItemsInCourse(courseId);
        //}

        //public IList<CourseItem> FlatToHierarchy(IEnumerable<CourseItem> list, int motherId = 0)
        //{
        //    return (from i in list
        //            where i.MotherId == motherId
        //            select new CourseItem
        //            {
        //                CourseItemId = i.CourseItemId,
        //                CourseId = i.CourseId,
        //                ItemId = i.ItemId,
        //                CIOrder = i.CIOrder,
        //                ItemType = i.ItemType,
        //                MotherId = i.MotherId,
        //                //Mother = i,
        //                label = i.label,
        //                name = i.name,
        //                children = FlatToHierarchy(list, i.CourseItemId)
        //            }).ToList();
        //}

        //public IList<CourseItem> GetCourseItemsAsTree(int courseId)
        //{
        //    List<CourseItem> source = GetItemsInCourse(courseId);
        //    return FlatToHierarchy(source);
        //}

        ////It is assumed that all CourseItems are in the same course
        //public void SaveCourseItems(IList<CourseItem> cis, int courseId, int motherId = 0)
        //{
        //    CourseItemEntity cie = new CourseItemEntity();
        //    int ciOrder = 1;
        //    foreach (CourseItem ci in cis)
        //    {
        //        DeleteCourseItem(ci); //Deletes heading as well if item is a heading

        //        if (ci.ItemType == ECourseItemType.Heading)
        //        {
        //            CourseMenuHeadings ch = new CourseMenuHeadings();
        //            ch.Title = ci.name;
        //            rep.CreateHeading(ch);
        //            cie.ItemId = ch.HeadingID;
        //        }
        //        else
        //            cie.ItemId = ci.ItemId;

        //        cie.CourseId = courseId;
        //        cie.CIOrder = ciOrder;
        //        cie.ItemType = ci.ItemType;
        //        cie.MotherId = motherId;
        //        rep.CreateCourseItem(cie);
        //        ciOrder += 1;
        //        if (ci.children != null)
        //            SaveCourseItems(ci.children, courseId, cie.CourseItemId);
        //    }
        //}

        //public void CreateCourseItem(CourseItem ci)
        //{
        //    rep.CreateCourseItem(ci);
        //}

        //public void UpdateCourseItem(CourseItem ci)
        //{
        //    rep.UpdateCourseItem(ci);
        //}

        //public void DeleteCourseItem(CourseItem ci)
        //{
        //    if (ci.ItemType == ECourseItemType.Heading)
        //        rep.DeleteHeading(new CourseMenuHeadings() {HeadingID =ci.ItemId});
        //    rep.DeleteCourseItem(ci);
        //}

        #endregion

        #region PHTextAndLatex

        /// <summary>
        /// This method will save the text in all Culture Codes
        /// It expects the text to be created in t.CultureCode
        /// It will call SavePhText(t)
        /// It then translates t into all languages and calls SavePhText on each text
        /// </summary>
        /// <param name="t"></param>
        public void SavePhTextInAllCc(PHText t)
        {
            t.CultureCodeStatus = ECultureCodeStatus.InCreationLanguage;
            SavePhText(t);  //Save Text in created language
            LocaleController lc = new LocaleController();
            var    locales      = lc.GetLocales(PortalID);
            PHText translatedText;

            foreach (var locale in locales)
            {
                if (locale.Key != t.CultureCode)
                {
                    translatedText      = GetCurrentVersionText(locale.Key, t.ItemId, t.ItemType);
                    translatedText.Text = TranslateText(t.CultureCode.Substring(0, 2), locale.Key.Substring(0, 2), t.Text);
                    translatedText.CultureCodeStatus = ECultureCodeStatus.GoogleTranslated;
                    SavePhText(translatedText);
                }
            }
        }
Ejemplo n.º 6
0
        protected void formViewLang_ItemCreated(object sender, EventArgs e)
        {
            LocaleController            lc  = new LocaleController();
            Dictionary <string, Locale> loc = lc.GetLocales(PortalSettings.Current.PortalId);

            FormViewRow row = formViewLang.HeaderRow;

            if (row != null)
            {
                PlaceHolder phLanguage = row.FindControl("phLanguage") as PlaceHolder;
                int         i          = 0;
                foreach (KeyValuePair <string, Locale> item in loc)
                {
                    HtmlGenericControl div = new HtmlGenericControl("div");
                    div.Style.Add("display", "table-cell");

                    ImageButton imgBtn = new ImageButton();
                    imgBtn.ID       = "imgLanguage" + i.ToString();
                    imgBtn.Click   += Language_Selected;
                    imgBtn.ImageUrl = "~\\images\\Flags\\" + item.Key + ".gif";
                    imgBtn.Style.Add("padding", "3px 10px 5px 10px");

                    imgBtn.Style.Add("border-width", "1px");
                    imgBtn.Style.Add("border-color", "#000000");

                    if (i == formViewLang.PageIndex)
                    {
                        imgBtn.Style.Add("border-style", "solid solid hidden solid");
                        imgBtn.Style.Add("margin", "0 0 1px 0;");
                        imgBtn.Style.Add("background-color", "White");
                    }
                    else
                    {
                        imgBtn.Style.Add("border-style", "solid solid solid solid");
                        imgBtn.Style.Add("margin", "0");
                        imgBtn.Style.Add("background-color", "LightGrey");
                    }
                    div.Controls.Add(imgBtn);
                    phLanguage.Controls.Add(div);
                    i++;
                }
            }
        }
Ejemplo n.º 7
0
        public string GetProperty(string propertyName, string format, CultureInfo formatProvider, UserInfo accessingUser, Scope accessLevel, ref bool propertyNotFound)
        {
            string retVal = "";
            switch (propertyName.ToLower())
            {
                case "all":
                    int moduleId = _moduleContext.ModuleId;
                    int portalId = _moduleContext.PortalId;
                    int tabId = _moduleContext.TabId;
                    ModuleInfo module = new ModuleController().GetModule(moduleId, tabId);

                    dynamic properties = new ExpandoObject();
                    System.IO.FileInfo fi = new System.IO.FileInfo(HttpContext.Current.Server.MapPath("~/" + _moduleContext.Configuration.ModuleControl.ControlSrc.Replace(".html", "") + ".resx"));
                    string physResourceFile = fi.DirectoryName + "/App_LocalResources/" + fi.Name;
                    string relResourceFile = "/DesktopModules/" + module.DesktopModule.FolderName + "/App_LocalResources/" + fi.Name;
                    if (File.Exists(physResourceFile))
                    {
                        using (var rsxr = new ResXResourceReader(physResourceFile))
                        {
                            var res = rsxr.OfType<DictionaryEntry>()
                                .ToDictionary(
                                    entry => entry.Key.ToString().Replace(".", "_"),
                                    entry => Localization.GetString(entry.Key.ToString(), relResourceFile));

                            properties.Resources = res;
                        }
                    }
                    else
                    {
                        properties.Resources = physResourceFile + " not found";
                    }
                    properties.Settings = _moduleContext.Settings;
                    properties.Editable = _moduleContext.EditMode && _moduleContext.IsEditable;
                    properties.Admin = accessingUser.IsInRole(PortalSettings.Current.AdministratorRoleName);
                    properties.ModuleId = moduleId;
                    properties.PortalId = portalId;
                    properties.UserId = accessingUser.UserID;
                    properties.HomeDirectory = PortalSettings.Current.HomeDirectory.Substring(1);
                    properties.RawUrl = HttpContext.Current.Request.RawUrl;

                    List<string> languages = new List<string>();
                    LocaleController lc = new LocaleController();
                    Dictionary<string, Locale> loc = lc.GetLocales(_moduleContext.PortalId);
                    foreach (KeyValuePair<string, Locale> item in loc)
                    {
                        string cultureCode = item.Value.Culture.Name;
                        languages.Add(cultureCode);
                    }
                    properties.Languages = languages;
                    properties.CurrentLanguage = System.Threading.Thread.CurrentThread.CurrentCulture.Name;

                    retVal = JsonConvert.SerializeObject(properties);
                    break;
                case "view":
                    retVal = (string)_moduleContext.Settings["View"];
                    if (String.IsNullOrEmpty(retVal))
                        retVal = "View.html";
                    break;
                case "list":
                    retVal = (string)_moduleContext.Settings["List"];
                    if (String.IsNullOrEmpty(retVal))
                        retVal = "List.html";
                    break;
            }
            return retVal;

        }
Ejemplo n.º 8
0
        public override IList<SearchDocument> GetModifiedSearchDocuments(ModuleInfo modInfo, DateTime beginDate)
        {
            string partition = (string)modInfo.ModuleSettings["Partitioning"];

            int partModuleId = -1;
            int partPortalId = -1;

            switch (partition)
            {
                case "1":
                    partModuleId = modInfo.ModuleID;
                    break;
                case "2":
                    partPortalId = modInfo.PortalID;
                    break;
                case "3":
                    partPortalId = modInfo.PortalID;
                    partModuleId = modInfo.ModuleID;
                    break;
            }

            var searchDocuments = new List<SearchDocument>();

            LocaleController lc = new LocaleController();
            Dictionary<string, Locale> loc = lc.GetLocales(modInfo.PortalID);
            foreach (KeyValuePair<string, Locale> item in loc)
            {
                string cultureCode = item.Value.Culture.Name;
                List<StoryInfo> stories = DbController.Instance.GetStories(partModuleId, partPortalId, "STORY", cultureCode, false).ToList();
                

                foreach (StoryInfo story in stories)
                {
                    DateTime lastmodified = ((DateTime)story.LastModifiedOnDate).ToUniversalTime();

                    if (lastmodified > beginDate.ToUniversalTime() && lastmodified < DateTime.UtcNow)
                    {
                        var strContent = HtmlUtils.Clean(story.Story, false);

                        // Get the description string
                        var description = strContent.Length <= 500 ? strContent : HtmlUtils.Shorten(strContent, 500, "...");

                        var searchDoc = new SearchDocument
                        {
                            UniqueKey = story.StoryId.ToString(),
                            PortalId = modInfo.PortalID,
                            ModuleId = modInfo.ModuleID,
                            ModuleDefId = modInfo.ModuleDefID,
                            Title = story.Title,
                            Description = description,
                            Body = strContent,
                            ModifiedTimeUtc = lastmodified,
                            AuthorUserId = (story.CreatedByUserID ?? -1),
                            CultureCode = cultureCode,
                            IsActive = (story.StartDate == null || story.StartDate < DateTime.Now) && (story.EndDate == null || story.EndDate + new TimeSpan(1, 0, 0, 0) >= DateTime.Now),
                            SearchTypeId = 1,
                            QueryString = "#view/"+story.StoryId.ToString()
                        };

                        if (modInfo.Terms != null && modInfo.Terms.Count > 0)
                        {
                            searchDoc.Tags = CollectHierarchicalTags(modInfo.Terms);
                        }

                        searchDocuments.Add(searchDoc);
                    }
                }

            }
            return searchDocuments;
        }
Ejemplo n.º 9
0
        public void UpdatePlugg(Plugg p, PluggContent pc)
        {
            //For restore if something goes wrong
            Plugg oldP = GetPlugg(p.PluggId);
            IEnumerable<PluggContent> oldPCs = GetAllContentInPlugg(p.PluggId);

            rep.UpdatePlugg(p); //No repair necessary if this fails

            //For now, remove all PluggContent and recreate in all languages from pc. Fix this when we can deal with translations
            try
            {
                foreach (PluggContent pcDelete in oldPCs)
                {
                    rep.DeletePluggContent(pcDelete);
                }

                pc.PluggId = p.PluggId;
                if (pc.LatexText != null)
                {
                    LatexToMathMLConverter myConverter = new LatexToMathMLConverter(pc.LatexText);
                    myConverter.Convert();
                    pc.LatexTextInHtml = myConverter.HTMLOutput;
                }

                LocaleController lc = new LocaleController();
                var locales = lc.GetLocales(PortalID);
                foreach (var locale in locales)
                {
                    pc.CultureCode = locale.Key;
                    rep.CreatePluggContent(pc);
                }
            }
            catch (Exception)
            {
                //recreate old Plugg/PluggContent before rethrow
                var pcs = GetAllContentInPlugg(p.PluggId);
                foreach (PluggContent pcDelete in pcs)
                {
                    rep.DeletePluggContent(pcDelete);
                }
                rep.DeletePlugg(p);

                rep.CreatePlugg(oldP);
                foreach (PluggContent oldPC in oldPCs)
                    rep.CreatePluggContent(oldPC);
                throw;
            }
        }
Ejemplo n.º 10
0
        public void SavePlugg(PluggContainer p)
        {
            try
            {
                bool isNew = p.ThePlugg.PluggId == 0;

                //Temporary - remove soon
                p.ThePlugg.Title = "Title no longer here";
                p.ThePlugg.CreatedByUserId = 1;
                p.ThePlugg.ModifiedByUserId = 1;

                if (isNew)
                    rep.CreatePlugg(p.ThePlugg);
                else
                    rep.UpdatePlugg(p.ThePlugg);

                //Todo: Update..
                p.TheTitle.ItemId = p.ThePlugg.PluggId;
                p.TheTitle.ItemType = ETextItemType.PluggTitle;
                p.TheTitle.CcStatus = ECCStatus.InCreationLanguage;
                p.TheTitle.CreatedByUserId = p.ThePlugg.CreatedByUserId;
                p.TheTitle.ModifiedByUserId = p.ThePlugg.ModifiedByUserId;
                SavePhText(p.TheTitle);

                //Todo: Update..
                if (p.TheHtmlText != null)
                {
                    p.TheHtmlText.ItemId = p.ThePlugg.PluggId;
                    p.TheHtmlText.ItemType = ETextItemType.PluggHtml;
                    p.TheHtmlText.CcStatus = ECCStatus.InCreationLanguage;
                    p.TheHtmlText.CreatedByUserId = p.ThePlugg.CreatedByUserId;
                    p.TheHtmlText.ModifiedByUserId = p.ThePlugg.ModifiedByUserId;
                    SavePhText(p.TheHtmlText);
                }

                //Todo: Update..
                if (p.TheLatex != null)
                {
                    p.TheLatex.ItemId = p.ThePlugg.PluggId;
                    p.TheLatex.ItemType = ELatexType.Plugg;
                    p.TheLatex.CcStatus = ECCStatus.InCreationLanguage;
                    p.TheLatex.CreatedByUserId = p.ThePlugg.CreatedByUserId;
                    p.TheLatex.ModifiedByUserId = p.ThePlugg.ModifiedByUserId;
                    LatexToMathMLConverter myConverter = new LatexToMathMLConverter(p.TheLatex.Text);
                    myConverter.Convert();
                    p.TheLatex.HtmlText = myConverter.HTMLOutput;
                    SaveLatexText(p.TheLatex);
                }

                LocaleController lc = new LocaleController();
                var locales = lc.GetLocales(PortalID);
                foreach (var locale in locales)
                {
                    if (locale.Key != p.ThePlugg.CreatedInCultureCode)
                    {
                        GoogleTranslate(p.TheTitle, locale.Key);
                        if (p.TheHtmlText != null)
                            GoogleTranslate(p.TheHtmlText, locale.Key);
                        if (p.TheLatex != null)
                            GoogleTranslate(p.TheLatex, locale.Key);
                    }
                }

                //Create PluggPage
                DNNHelper d = new DNNHelper();
                string pageUrl = p.ThePlugg.PluggId.ToString();
                string pageName = pageUrl + ": " + p.TheTitle.Text;
                TabInfo newTab = d.AddPluggPage(pageName, pageUrl);
                p.ThePlugg.TabId = newTab.TabID;
                rep.UpdatePlugg(p.ThePlugg);
            }
            catch (Exception)
            {
                //Todo: Update
                DeletePlugg(p.ThePlugg);
                throw;
            }
        }
Ejemplo n.º 11
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            try
            {
                Controller = new BBStoreController();

                taxUnitCost.PercentControl         = txtTaxPercent;
                taxOriginalUnitCost.PercentControl = txtTaxPercent;

                taxPriceUnitCost.PercentControl         = txtPriceTaxPercent;
                taxPriceOriginalUnitCost.PercentControl = txtPriceTaxPercent;

                LocaleController            lc  = new LocaleController();
                Dictionary <string, Locale> loc = lc.GetLocales(PortalId);

                //TODO: Panels ausblenden wenn kein Modul verwendet

                ModuleController objModules = new ModuleController();
                if (objModules.GetModuleByDefinition(PortalId, "BBStore Product Groups") == null)
                {
                    HasProductGroupModule = false;
                }

                if (objModules.GetModuleByDefinition(PortalId, "BBStore Product Features") == null)
                {
                    HasProductFeatureModule = false;
                }

                Hashtable storeSettings = Controller.GetStoreSettings(PortalId);
                if (storeSettings != null)
                {
                    _imageDir = (string)(storeSettings["ProductImageDir"] ?? "");
                }

                // If this is the first visit to the page
                if (Page.IsPostBack == false)
                {
                    // Show Supplier ?
                    if (storeSettings != null && storeSettings["SupplierRole"] != null && (string)storeSettings["SupplierRole"] != "-1")
                    {
                        pnlSupplier.Visible = true;
                        RoleController roleController = new RoleController();
                        //RoleInfo role = roleController.GetRole(Convert.ToInt32(storeSettings["SupplierRole"]), PortalId);
                        ArrayList          aUsers = roleController.GetUsersByRoleName(PortalId, (string)storeSettings["SupplierRole"]);
                        ListItemCollection users  = new ListItemCollection();
                        foreach (UserInfo user in aUsers)
                        {
                            users.Add(new ListItem(user.DisplayName, user.UserID.ToString()));
                        }
                        string selText = Localization.GetString("SelectSupplier.Text", this.LocalResourceFile);
                        users.Insert(0, new ListItem(selText, "-1"));
                        cboSupplier.DataSource     = users;
                        cboSupplier.DataValueField = "Value";
                        cboSupplier.DataTextField  = "Text";
                        cboSupplier.DataBind();
                    }

                    // Shipping Models
                    List <ShippingModelInfo> shippingModels = Controller.GetShippingModels(PortalId);

                    cboShippingModel.DataSource     = shippingModels;
                    cboShippingModel.DataValueField = "ShippingModelId";
                    cboShippingModel.DataTextField  = "Name";
                    cboShippingModel.DataBind();

                    string selUnitText = Localization.GetString("SelectUnit.Text", this.LocalResourceFile);
                    ddlUnit.Items.Add(new ListItem(selUnitText, "-1"));
                    foreach (UnitInfo unit in Controller.GetUnits(PortalId, CurrentLanguage, "Unit"))
                    {
                        ddlUnit.Items.Add(new ListItem(unit.Unit, unit.UnitId.ToString()));
                    }
                    ddlUnit.DataValueField = "Value";
                    ddlUnit.DataTextField  = "Text";
                    ddlUnit.DataBind();


                    // Set ProductGroups Visible / not Visible
                    //pnlProductGroup.Visible = HasProductGroupModule;

                    SimpleProductInfo SimpleProduct = null;

                    if (Request["productid"] != null)
                    {
                        ProductId = Convert.ToInt32(Request["productid"]);
                    }

                    // if product exists
                    if (ProductId > 0)
                    {
                        SimpleProduct = Controller.GetSimpleProductByProductId(PortalId, ProductId);
                    }

                    List <ILanguageEditorInfo> dbLangs = new List <ILanguageEditorInfo>();

                    if (SimpleProduct == null)
                    {
                        taxUnitCost.Value         = 0.00m;
                        taxUnitCost.Mode          = "gross";
                        txtTaxPercent.Text        = 0.0m.ToString();
                        taxOriginalUnitCost.Value = 0.00m;
                        taxOriginalUnitCost.Mode  = "gross";
                        ImageSelector.Url         = _imageDir + "This_fileName-Should_not_3xist";
                        cboSupplier.SelectedValue = "-1";
                        dbLangs.Add(new SimpleProductLangInfo()
                        {
                            Language = CurrentLanguage
                        });
                        lngSimpleProducts.Langs = dbLangs;
                        txtWeight.Text          = 0.000m.ToString();
                    }
                    else
                    {
                        // Fill in the Language information
                        foreach (SimpleProductLangInfo simpleProductLang in Controller.GetSimpleProductLangs(SimpleProduct.SimpleProductId))
                        {
                            dbLangs.Add(simpleProductLang);
                        }
                        lngSimpleProducts.Langs = dbLangs;


                        // Set Image Info
                        int fileId = -1;
                        if (!String.IsNullOrEmpty(SimpleProduct.Image))
                        {
                            try
                            {
                                IFileInfo file = FileManager.Instance.GetFile(PortalId, SimpleProduct.Image);
                                if (file != null)
                                {
                                    fileId = file.FileId;
                                }
                            }
                            catch (Exception)
                            {
                                fileId = -1;
                            }
                        }
                        string imageUrl = "";
                        if (fileId > -1)
                        {
                            imageUrl = "FileID=" + fileId.ToString();
                        }
                        else
                        {
                            imageUrl = _imageDir + "This_fileName-Should_not_3xist";
                        }

                        // Set other fields
                        txtItemNo.Text            = SimpleProduct.ItemNo;
                        txtTaxPercent.Text        = SimpleProduct.TaxPercent.ToString();
                        taxUnitCost.Mode          = "gross";
                        taxUnitCost.Value         = SimpleProduct.UnitCost;
                        taxOriginalUnitCost.Mode  = "gross";
                        taxOriginalUnitCost.Value = SimpleProduct.OriginalUnitCost;
                        chkDisabled.Checked       = SimpleProduct.Disabled;
                        chkHideCost.Checked       = SimpleProduct.HideCost;
                        chkNoCart.Checked         = SimpleProduct.NoCart;
                        cboSupplier.SelectedValue = SimpleProduct.SupplierId.ToString();
                        ddlUnit.SelectedValue     = SimpleProduct.UnitId.ToString();
                        ImageSelector.Url         = imageUrl;
                        imgImage.ImageUrl         = BBStoreHelper.FileNameToImgSrc(imageUrl, PortalSettings);
                        txtWeight.Text            = SimpleProduct.Weight.ToString();

                        // Set ShippingModel
                        List <ProductShippingModelInfo> productshippingModels = Controller.GetProductShippingModelsByProduct(SimpleProduct.SimpleProductId);
                        if (productshippingModels.Count > 0)
                        {
                            cboShippingModel.SelectedValue = productshippingModels[0].ShippingModelId.ToString();
                        }
                    }

                    // Treeview Basenode
                    TreeNode newNode = new TreeNode(Localization.GetString("treeProductGroups.Text", this.LocalResourceFile), "_-1");
                    newNode.SelectAction     = TreeNodeSelectAction.Expand;
                    newNode.PopulateOnDemand = true;
                    newNode.ImageUrl         = @"~\images\category.gif";
                    newNode.ShowCheckBox     = false;
                    treeProductGroup.Nodes.Add(newNode);
                    //newNode.Expanded = false;


                    // Product Price
                    Localization.LocalizeGridView(ref grdPriceList, LocalResourceFile);
                    grdPriceList.DataSource = ProductPrices;
                    grdPriceList.DataBind();

                    RoleController roleController1 = new RoleController();
                    //RoleInfo role = roleController.GetRole(Convert.ToInt32(storeSettings["SupplierRole"]), PortalId);
                    ArrayList          aRoles = roleController1.GetPortalRoles(PortalId);
                    ListItemCollection roles  = new ListItemCollection();
                    foreach (RoleInfo role in aRoles)
                    {
                        roles.Add(new ListItem(role.RoleName, role.RoleID.ToString()));
                    }
                    string selText1 = Localization.GetString("SelectRole.Text", this.LocalResourceFile);
                    roles.Insert(0, new ListItem(selText1, "-1"));
                    ddlPriceRoleId.DataSource     = roles;
                    ddlPriceRoleId.DataValueField = "Value";
                    ddlPriceRoleId.DataTextField  = "Text";
                    ddlPriceRoleId.DataBind();
                }
                if (HasProductFeatureModule)
                {
                    FeatureGrid.ProductId = ProductId;
                }
            }

            catch (Exception exc)
            {
                //Module failed to load
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
Ejemplo n.º 12
0
 /// <summary>
 /// This method will save the text in all Culture Codes
 /// It expects the text to be created in t.CultureCode
 /// It expects the text to be decoded (actual html)
 /// It will call SavePhText(t)
 /// It then translates t into all languages and calls SavePhText on each text
 /// </summary>
 /// <param name="t"></param>
 public void SavePhTextInAllCc(PHText t)
 {
     t.CultureCodeStatus = ECultureCodeStatus.InCreationLanguage;
     SavePhText(t);  //Save Text in created language
     LocaleController lc = new LocaleController();
     var locales = lc.GetLocales(PortalID);
     PHText translatedText;
     foreach (var locale in locales)
     {
         if (locale.Key != t.CultureCode)
         {
             translatedText = GetCurrentVersionText(locale.Key, t.ItemId, t.ItemType);
             if (translatedText == null)
             {
                 translatedText = new PHText();
                 translatedText.CultureCode = locale.Key;
                 translatedText.ItemId = t.ItemId;
                 translatedText.ItemType = t.ItemType;
             }
             if (t.ItemType == ETextItemType.PluggTitle || t.ItemType == ETextItemType.PluggDescription || t.ItemType == ETextItemType.CourseTitle || t.ItemType == ETextItemType.CourseDescription )
             {
                 string translation = TranslateText(t.CultureCode.Substring(0, 2), locale.Key.Substring(0, 2), t.Text);
                 if (translation != null)
                 {
                     translatedText.Text = translation;
                     translatedText.CultureCodeStatus = ECultureCodeStatus.GoogleTranslated;
                 }
                 else
                 {
                     translatedText.Text = "";
                     translatedText.CultureCodeStatus = ECultureCodeStatus.NotTranslated;
                 }
             }
             else
             {
                 translatedText.Text = "";
                 translatedText.CultureCodeStatus = ECultureCodeStatus.NotTranslated;
             }
             if (translatedText.CreatedByUserId == 0)
                 translatedText.CreatedByUserId = t.CreatedByUserId;
             SavePhText(translatedText);
         }
     }
 }
Ejemplo n.º 13
0
 /// <summary>
 /// This method will save the text in all Culture Codes
 /// It expects the text to be created in t.CultureCode
 /// It will call SavePhText(t)
 /// It then translates t into all languages and calls SavePhText on each text
 /// </summary>
 /// <param name="t"></param>
 public void SavePhTextInAllCc(PHText t)
 {
     t.CultureCodeStatus = ECultureCodeStatus.InCreationLanguage;
     SavePhText(t);  //Save Text in created language
     LocaleController lc = new LocaleController();
     var locales = lc.GetLocales(PortalID);
     PHText translatedText;
     foreach (var locale in locales)
     {
         if (locale.Key != t.CultureCode)
         {
             translatedText = GetCurrentVersionText(locale.Key, t.ItemId, t.ItemType);
             translatedText.Text = TranslateText(t.CultureCode.Substring(0, 2), locale.Key.Substring(0, 2), t.Text);
             translatedText.CultureCodeStatus = ECultureCodeStatus.GoogleTranslated;
             SavePhText(translatedText);
         }
     }
 }
Ejemplo n.º 14
0
        public void SavePlugg(PluggContainer p)
        {
            try
            {
                bool isNew = p.ThePlugg.PluggId == 0;

                //Temporary - remove soon
                p.ThePlugg.Title            = "Title no longer here";
                p.ThePlugg.CreatedByUserId  = 1;
                p.ThePlugg.ModifiedByUserId = 1;

                if (isNew)
                {
                    rep.CreatePlugg(p.ThePlugg);
                }
                else
                {
                    rep.UpdatePlugg(p.ThePlugg);
                }

                //Todo: Update..
                p.TheTitle.ItemId           = p.ThePlugg.PluggId;
                p.TheTitle.ItemType         = ETextItemType.PluggTitle;
                p.TheTitle.CcStatus         = ECCStatus.InCreationLanguage;
                p.TheTitle.CreatedByUserId  = p.ThePlugg.CreatedByUserId;
                p.TheTitle.ModifiedByUserId = p.ThePlugg.ModifiedByUserId;
                SavePhText(p.TheTitle);

                //Todo: Update..
                if (p.TheHtmlText != null)
                {
                    p.TheHtmlText.ItemId           = p.ThePlugg.PluggId;
                    p.TheHtmlText.ItemType         = ETextItemType.PluggHtml;
                    p.TheHtmlText.CcStatus         = ECCStatus.InCreationLanguage;
                    p.TheHtmlText.CreatedByUserId  = p.ThePlugg.CreatedByUserId;
                    p.TheHtmlText.ModifiedByUserId = p.ThePlugg.ModifiedByUserId;
                    SavePhText(p.TheHtmlText);
                }

                //Todo: Update..
                if (p.TheLatex != null)
                {
                    p.TheLatex.ItemId           = p.ThePlugg.PluggId;
                    p.TheLatex.ItemType         = ELatexType.Plugg;
                    p.TheLatex.CcStatus         = ECCStatus.InCreationLanguage;
                    p.TheLatex.CreatedByUserId  = p.ThePlugg.CreatedByUserId;
                    p.TheLatex.ModifiedByUserId = p.ThePlugg.ModifiedByUserId;
                    LatexToMathMLConverter myConverter = new LatexToMathMLConverter(p.TheLatex.Text);
                    myConverter.Convert();
                    p.TheLatex.HtmlText = myConverter.HTMLOutput;
                    SaveLatexText(p.TheLatex);
                }

                LocaleController lc = new LocaleController();
                var locales         = lc.GetLocales(PortalID);
                foreach (var locale in locales)
                {
                    if (locale.Key != p.ThePlugg.CreatedInCultureCode)
                    {
                        GoogleTranslate(p.TheTitle, locale.Key);
                        if (p.TheHtmlText != null)
                        {
                            GoogleTranslate(p.TheHtmlText, locale.Key);
                        }
                        if (p.TheLatex != null)
                        {
                            GoogleTranslate(p.TheLatex, locale.Key);
                        }
                    }
                }

                //Create PluggPage
                DNNHelper d        = new DNNHelper();
                string    pageUrl  = p.ThePlugg.PluggId.ToString();
                string    pageName = pageUrl + ": " + p.TheTitle.Text;
                TabInfo   newTab   = d.AddPluggPage(pageName, pageUrl);
                p.ThePlugg.TabId = newTab.TabID;
                rep.UpdatePlugg(p.ThePlugg);
            }
            catch (Exception)
            {
                //Todo: Update
                DeletePlugg(p.ThePlugg);
                throw;
            }
        }
Ejemplo n.º 15
0
        public override List <SitemapUrl> GetUrls(int portalId, PortalSettings ps, string version)
        {
            CultureInfo current   = Thread.CurrentThread.CurrentCulture;
            CultureInfo currentUI = Thread.CurrentThread.CurrentUICulture;

            BBStoreController controller = new BBStoreController();
            List <SitemapUrl> retVal     = new List <SitemapUrl>();

            ModuleController moduleController = new ModuleController();
            ArrayList        mods             = moduleController.GetModules(portalId);

            // Lets build the Languages Collection
            LocaleController            lc  = new LocaleController();
            Dictionary <string, Locale> loc = lc.GetLocales(PortalSettings.Current.PortalId);

            // Productgroups
            foreach (var mod in mods)
            {
                ModuleInfo modInfo = (ModuleInfo)mod;
                if (modInfo.ModuleDefinition.FriendlyName == "BBStore Product Groups")
                {
                    bool fixedRoot = (modInfo.ModuleSettings["RootLevelFixed"] != null && Convert.ToBoolean(modInfo.ModuleSettings["RootLevelFixed"]));
                    int  rootLevel = (modInfo.ModuleSettings["RootLevel"] != null ? Convert.ToInt32(modInfo.ModuleSettings["RootLevel"]) : -1);
                    List <ProductGroupInfo> productGroups = new List <ProductGroupInfo>();
                    if (rootLevel > -1 && fixedRoot)
                    {
                        productGroups.Add(controller.GetProductGroup(portalId, rootLevel));
                    }
                    else if (rootLevel > -1 && !fixedRoot)
                    {
                        productGroups = controller.GetProductSubGroupsByNode(portalId, "en-US", rootLevel, false, false, false);
                    }
                    else if (rootLevel == -1 && fixedRoot)
                    {
                        productGroups.Add(new ProductGroupInfo()
                        {
                            ProductGroupId = -1
                        });
                    }
                    else
                    {
                        productGroups = controller.GetProductGroups(portalId);
                    }

                    List <ProductGroupInfo> sortedGroups = productGroups.OrderBy(p => p.ProductGroupId).ToList();
                    foreach (ProductGroupInfo productGroup in sortedGroups)
                    {
                        foreach (KeyValuePair <string, Locale> lang in loc)
                        {
                            // Set language to product Language
                            Thread.CurrentThread.CurrentCulture   = CultureInfo.CreateSpecificCulture(lang.Key);
                            Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang.Key);

                            // Lets check if we already have this
                            string name = "", url = "";
                            ProductGroupLangInfo pgl = controller.GetProductGroupLang(productGroup.ProductGroupId, lang.Key);
                            if (pgl != null)
                            {
                                name = HttpUtility.UrlEncode(pgl.ProductGroupName);
                            }
                            if (name != String.Empty)
                            {
                                url = Globals.NavigateURL(modInfo.TabID, "", "productGroup=" + productGroup.ProductGroupId.ToString(), "name=" + name);
                            }
                            else
                            {
                                url = Globals.NavigateURL(modInfo.TabID, "", "productGroup=" + productGroup.ProductGroupId.ToString());
                            }
                            if (retVal.Find(r => r.Url == url) == null)
                            {
                                var pageUrl = new SitemapUrl
                                {
                                    Url             = url,
                                    Priority        = (float)0.5,
                                    LastModified    = DateTime.Now.AddDays(-1),
                                    ChangeFrequency = SitemapChangeFrequency.Daily
                                };
                                retVal.Add(pageUrl);
                            }
                        }
                    }
                }
            }

            foreach (var mod in mods)
            {
                // First we need to know where our ProductModule sits
                ModuleInfo modInfo = (ModuleInfo)mod;
                if (modInfo.ModuleDefinition.FriendlyName == "BBStore Product" || modInfo.ModuleDefinition.FriendlyName == "BBStore Simple Product")
                {
                    int tabId = modInfo.TabID;

                    int productId = -1;
                    if (modInfo.ModuleSettings["ProductId"] != null)
                    {
                        productId = Convert.ToInt32(modInfo.ModuleSettings["ProductId"]);
                    }

                    if (productId < 0)
                    {
                        // We've got a dynamic module ! Here we show all products that are not disbaled !
                        List <SimpleProductInfo> products = controller.GetSimpleProducts(portalId).FindAll(p => p.Disabled == false);
                        foreach (SimpleProductInfo product in products)
                        {
                            foreach (KeyValuePair <string, Locale> lang in loc)
                            {
                                // Set language to product Language
                                Thread.CurrentThread.CurrentCulture   = CultureInfo.CreateSpecificCulture(lang.Key);
                                Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang.Key);

                                // Lets check if we already have this
                                string name = "", url = "";
                                SimpleProductLangInfo spl = controller.GetSimpleProductLang(product.SimpleProductId, lang.Key);
                                if (spl != null)
                                {
                                    name = HttpUtility.UrlEncode(spl.Name);
                                }
                                if (name != string.Empty)
                                {
                                    url = Globals.NavigateURL(tabId, "", "productid=" + product.SimpleProductId.ToString(), "name=" + name);
                                }
                                else
                                {
                                    url = Globals.NavigateURL(tabId, "", "productid=" + product.SimpleProductId.ToString());
                                }

                                if (retVal.Find(r => r.Url == url) == null)
                                {
                                    var pageUrl = new SitemapUrl
                                    {
                                        Url             = url,
                                        Priority        = (float)0.3,
                                        LastModified    = product.LastModifiedOnDate,
                                        ChangeFrequency = SitemapChangeFrequency.Daily
                                    };
                                    retVal.Add(pageUrl);
                                }
                            }
                        }
                    }
                    else
                    {
                        // This is a fixed module !
                        SimpleProductInfo product = controller.GetSimpleProductByProductId(portalId, productId);
                        foreach (KeyValuePair <string, Locale> lang in loc)
                        {
                            // Set language to product Language
                            Thread.CurrentThread.CurrentCulture   = CultureInfo.CreateSpecificCulture(lang.Key);
                            Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang.Key);

                            // Lets check if we already have this
                            string name = "", url = "";
                            SimpleProductLangInfo spl = controller.GetSimpleProductLang(productId, lang.Key);
                            if (spl != null)
                            {
                                name = HttpUtility.UrlEncode(spl.Name);
                            }
                            if (name != string.Empty)
                            {
                                url = Globals.NavigateURL(tabId, "", "name=" + name);
                            }
                            else
                            {
                                url = Globals.NavigateURL(tabId);
                            }

                            if (retVal.Find(r => r.Url == url) == null)
                            {
                                var pageUrl = new SitemapUrl
                                {
                                    Url             = url,
                                    Priority        = (float)0.4,
                                    LastModified    = product.LastModifiedOnDate,
                                    ChangeFrequency = SitemapChangeFrequency.Daily
                                };
                                retVal.Add(pageUrl);
                            }
                        }
                    }
                }

                // Reset values
                Thread.CurrentThread.CurrentCulture   = current;
                Thread.CurrentThread.CurrentUICulture = currentUI;
            }
            return(retVal);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// This method will save the LatexText in all Culture Codes
        /// It expects the text to be created in t.CultureCode
        /// It will call SaveLatexText(t)
        /// It then translates t into all languages and calls SaveLatexText on each text
        /// </summary>
        /// <param name="t"></param>
        public void SaveLatexTextInAllCc(PHLatex t)
        {
            SaveLatexText(t);  //Save LatexText in created language
            LocaleController lc = new LocaleController();
            var locales = lc.GetLocales(PortalID);
            foreach (var locale in locales)
            {
                if (locale.Key != t.CultureCode)
                {
                    t.Text = TranslateText(t.CultureCode.Substring(0, 2), locale.Key.Substring(0, 2), t.Text);

                    t.LatexId = 0;
                    t.CultureCode = locale.Key;
                    t.CultureCodeStatus = ECultureCodeStatus.GoogleTranslated;
                    SaveLatexText(t);
                }
            }
        }
Ejemplo n.º 17
0
        public void BindAll(int tabID)
        {
            TabID = tabID;
            var currentTab = TabController.GetTab(tabID, PortalSettings.PortalId, false);

            //Unique id of default language page
            var uniqueId = currentTab.DefaultLanguageGuid != Null.NullGuid ? currentTab.DefaultLanguageGuid : currentTab.UniqueId;

            // get all non admin pages and not deleted
            var allPages = TabController.GetTabsByPortal(PortalSettings.PortalId).Values.Where(t => t.TabID != PortalSettings.AdminTabId && (Null.IsNull(t.ParentId) || t.ParentId != PortalSettings.AdminTabId));
            allPages = allPages.Where(t => t.IsDeleted == false);
            // get all localized pages of current page
            var tabInfos = allPages as IList<TabInfo> ?? allPages.ToList();
            var localizedPages = tabInfos.Where(t => t.DefaultLanguageGuid == uniqueId || t.UniqueId == uniqueId).OrderBy(t => t.DefaultLanguageGuid).ToList();
            Dictionary<string, TabInfo> localizedTabs = null;

            // we are going to build up a list of locales
            // this is a bit more involved, since we want the default language to be first.
            // also, we do not want to add any locales the user has no access to
            var locales = new List<string>();
            var localeController = new LocaleController();
            var localeDict = localeController.GetLocales(PortalSettings.PortalId);
            if (localeDict.Count > 0)
            {
                if (localizedPages.Count() == 1 && localizedPages.First().CultureCode == "")
                {
                    // locale neutral page
                    locales.Add("");
                }
                else if (localizedPages.Count() == 1 && localizedPages.First().CultureCode != PortalSettings.DefaultLanguage)
                {
                    locales.Add(localizedPages.First().CultureCode);
                    localizedTabs = new Dictionary<string, TabInfo>();
                    localizedTabs.Add(localizedPages.First().CultureCode, localizedPages.First());
                }
                else
                {

                    //force sort order, so first add default language
                    locales.Add(PortalSettings.DefaultLanguage);

                    // build up a list of localized tabs.
                    // depending on whether or not the selected page is in the default langauge
                    // we will add the localized tabs from the current page
                    // or from the defaultlanguage page
                    if (currentTab.CultureCode == PortalSettings.DefaultLanguage)
                    {
                        localizedTabs = currentTab.LocalizedTabs;
                    }
                    else
                    {
                        // selected page is not in default language
                        // add localizedtabs from defaultlanguage page
                        if (currentTab.DefaultLanguageTab != null)
                        {
                            localizedTabs = currentTab.DefaultLanguageTab.LocalizedTabs;
                        }
                    }

                    if (localizedTabs != null)
                    {
                        // only add locales from tabs the user has at least view permissions to. 
                        // we will handle the edit permissions at a later stage
                        locales.AddRange(from localizedTab in localizedTabs where TabPermissionController.CanViewPage(localizedTab.Value) select localizedTab.Value.CultureCode);
                    }


                }
            }
            else
            {
                locales.Add("");
            }

            Data = new DnnPages(locales);

            // filter the list of localized pages to only those that have a culture we want to see
            var viewableLocalizedPages = localizedPages.Where(localizedPage => locales.Find(locale => locale == localizedPage.CultureCode) != null).ToList();
            if (viewableLocalizedPages.Count() > 4)
            {
                mainContainer.Attributes.Add("class", "container RadGrid RadGrid_Default overflow");
            }

            foreach (var tabInfo in viewableLocalizedPages)
            {
                var localTabInfo = tabInfo;
                var dnnPage = Data.Page(localTabInfo.CultureCode);
                if (!TabPermissionController.CanViewPage(tabInfo))
                {
                    Data.RemoveLocale(localTabInfo.CultureCode);
                    Data.Pages.Remove(dnnPage);
                    break;
                }
                dnnPage.TabID = localTabInfo.TabID;
                dnnPage.TabName = localTabInfo.TabName;
                dnnPage.Title = localTabInfo.Title;
                dnnPage.Description = localTabInfo.Description;
                dnnPage.Path = localTabInfo.TabPath.Substring(0, localTabInfo.TabPath.LastIndexOf("//", StringComparison.Ordinal)).Replace("//", "");
                dnnPage.HasChildren = (TabController.GetTabsByPortal(PortalSettings.PortalId).WithParentId(tabInfo.TabID).Count != 0);
                dnnPage.CanAdminPage = TabPermissionController.CanAdminPage(tabInfo);
                dnnPage.CanViewPage = TabPermissionController.CanViewPage(tabInfo);
                dnnPage.LocalResourceFile = LocalResourceFile;

                // calculate position in the form of 1.3.2...
                var SiblingTabs = tabInfos.Where(t => t.ParentId == localTabInfo.ParentId && t.CultureCode == localTabInfo.CultureCode || t.CultureCode == null).OrderBy(t => t.TabOrder).ToList();
                dnnPage.Position = (SiblingTabs.IndexOf(localTabInfo) + 1).ToString(CultureInfo.InvariantCulture);
                int ParentTabId = localTabInfo.ParentId;
                while (ParentTabId > 0)
                {
                    TabInfo ParentTab = tabInfos.Single(t => t.TabID == ParentTabId);
                    int id = ParentTabId;
                    SiblingTabs = tabInfos.Where(t => t.ParentId == id && t.CultureCode == localTabInfo.CultureCode || t.CultureCode == null).OrderBy(t => t.TabOrder).ToList();
                    dnnPage.Position = (SiblingTabs.IndexOf(localTabInfo) + 1).ToString(CultureInfo.InvariantCulture) + "." + dnnPage.Position;
                    ParentTabId = ParentTab.ParentId;
                }

                dnnPage.DefaultLanguageGuid = localTabInfo.DefaultLanguageGuid;
                dnnPage.IsTranslated = localTabInfo.IsTranslated;
                dnnPage.IsPublished = TabController.IsTabPublished(localTabInfo);
                // generate modules information
                foreach (var moduleInfo in ModuleController.GetTabModules(localTabInfo.TabID).Values.Where(m => !m.IsDeleted))
                {
                    var guid = moduleInfo.DefaultLanguageGuid == Null.NullGuid ? moduleInfo.UniqueId : moduleInfo.DefaultLanguageGuid;

                    var dnnModules = Data.Module(guid); // modules of each language
                    var dnnModule = dnnModules.Module(localTabInfo.CultureCode);
                    // detect error : 2 modules with same uniqueId on the same page
                    dnnModule.LocalResourceFile = LocalResourceFile;
                    if (dnnModule.TabModuleID > 0)
                    {
                        dnnModule.ErrorDuplicateModule = true;
                        ErrorExists = true;
                        continue;
                    }

                    dnnModule.ModuleTitle = moduleInfo.ModuleTitle;
                    dnnModule.DefaultLanguageGuid = moduleInfo.DefaultLanguageGuid;
                    dnnModule.TabId = localTabInfo.TabID;
                    dnnModule.TabModuleID = moduleInfo.TabModuleID;
                    dnnModule.ModuleID = moduleInfo.ModuleID;
                    dnnModule.CanAdminModule = ModulePermissionController.CanAdminModule(moduleInfo);
                    dnnModule.CanViewModule = ModulePermissionController.CanViewModule(moduleInfo);

                    if (moduleInfo.DefaultLanguageGuid != Null.NullGuid)
                    {
                        ModuleInfo defaultLanguageModule = ModuleController.GetModuleByUniqueID(moduleInfo.DefaultLanguageGuid);
                        if (defaultLanguageModule != null)
                        {
                            dnnModule.DefaultModuleID = defaultLanguageModule.ModuleID;
                            if (defaultLanguageModule.ParentTab.UniqueId != moduleInfo.ParentTab.DefaultLanguageGuid)
                                dnnModule.DefaultTabName = defaultLanguageModule.ParentTab.TabName;
                        }
                    }
                    dnnModule.IsTranslated = moduleInfo.IsTranslated;
                    dnnModule.IsLocalized = moduleInfo.IsLocalized;

                    dnnModule.IsShared = TabController.GetTabsByModuleID(moduleInfo.ModuleID).Values.Count(t => t.CultureCode == moduleInfo.CultureCode) > 1;

                    // detect error : the default language module is on an other page
                    dnnModule.ErrorDefaultOnOtherTab = moduleInfo.DefaultLanguageGuid != Null.NullGuid && moduleInfo.DefaultLanguageModule == null;

                    // detect error : different culture on tab and module
                    dnnModule.ErrorCultureOfModuleNotCultureOfTab = moduleInfo.CultureCode != localTabInfo.CultureCode;

                    ErrorExists = ErrorExists || dnnModule.ErrorDefaultOnOtherTab || dnnModule.ErrorCultureOfModuleNotCultureOfTab;
                }
            }

            rDnnModules.DataSource = Data.Modules;
            rDnnModules.DataBind();

        }
Ejemplo n.º 18
0
        public void BindAll(int tabID)
        {
            TabID = tabID;
            var currentTab = TabController.Instance.GetTab(tabID, PortalSettings.PortalId, false);

            //Unique id of default language page
            var uniqueId = currentTab.DefaultLanguageGuid != Null.NullGuid ? currentTab.DefaultLanguageGuid : currentTab.UniqueId;

            // get all non admin pages and not deleted
            var allPages = TabController.Instance.GetTabsByPortal(PortalSettings.PortalId).Values.Where(t => t.TabID != PortalSettings.AdminTabId && (Null.IsNull(t.ParentId) || t.ParentId != PortalSettings.AdminTabId));

            allPages = allPages.Where(t => t.IsDeleted == false);
            // get all localized pages of current page
            var tabInfos       = allPages as IList <TabInfo> ?? allPages.ToList();
            var localizedPages = tabInfos.Where(t => t.DefaultLanguageGuid == uniqueId || t.UniqueId == uniqueId).OrderBy(t => t.DefaultLanguageGuid).ToList();
            Dictionary <string, TabInfo> localizedTabs = null;

            // we are going to build up a list of locales
            // this is a bit more involved, since we want the default language to be first.
            // also, we do not want to add any locales the user has no access to
            var locales          = new List <string>();
            var localeController = new LocaleController();
            var localeDict       = localeController.GetLocales(PortalSettings.PortalId);

            if (localeDict.Count > 0)
            {
                if (localizedPages.Count() == 1 && localizedPages.First().CultureCode == "")
                {
                    // locale neutral page
                    locales.Add("");
                }
                else if (localizedPages.Count() == 1 && localizedPages.First().CultureCode != PortalSettings.DefaultLanguage)
                {
                    locales.Add(localizedPages.First().CultureCode);
                    localizedTabs = new Dictionary <string, TabInfo>();
                    localizedTabs.Add(localizedPages.First().CultureCode, localizedPages.First());
                }
                else
                {
                    //force sort order, so first add default language
                    locales.Add(PortalSettings.DefaultLanguage);

                    // build up a list of localized tabs.
                    // depending on whether or not the selected page is in the default langauge
                    // we will add the localized tabs from the current page
                    // or from the defaultlanguage page
                    if (currentTab.CultureCode == PortalSettings.DefaultLanguage)
                    {
                        localizedTabs = currentTab.LocalizedTabs;
                    }
                    else
                    {
                        // selected page is not in default language
                        // add localizedtabs from defaultlanguage page
                        if (currentTab.DefaultLanguageTab != null)
                        {
                            localizedTabs = currentTab.DefaultLanguageTab.LocalizedTabs;
                        }
                    }

                    if (localizedTabs != null)
                    {
                        // only add locales from tabs the user has at least view permissions to.
                        // we will handle the edit permissions at a later stage
                        locales.AddRange(from localizedTab in localizedTabs where TabPermissionController.CanViewPage(localizedTab.Value) select localizedTab.Value.CultureCode);
                    }
                }
            }
            else
            {
                locales.Add("");
            }

            Data = new DnnPages(locales);

            // filter the list of localized pages to only those that have a culture we want to see
            var viewableLocalizedPages = localizedPages.Where(localizedPage => locales.Find(locale => locale == localizedPage.CultureCode) != null).ToList();

            if (viewableLocalizedPages.Count() > 4)
            {
                mainContainer.Attributes.Add("class", "container RadGrid RadGrid_Default overflow");
            }

            foreach (var tabInfo in viewableLocalizedPages)
            {
                var localTabInfo = tabInfo;
                var dnnPage      = Data.Page(localTabInfo.CultureCode);
                if (!TabPermissionController.CanViewPage(tabInfo))
                {
                    Data.RemoveLocale(localTabInfo.CultureCode);
                    Data.Pages.Remove(dnnPage);
                    break;
                }
                dnnPage.TabID             = localTabInfo.TabID;
                dnnPage.TabName           = localTabInfo.TabName;
                dnnPage.Title             = localTabInfo.Title;
                dnnPage.Description       = localTabInfo.Description;
                dnnPage.Path              = localTabInfo.TabPath.Substring(0, localTabInfo.TabPath.LastIndexOf("//", StringComparison.Ordinal)).Replace("//", "");
                dnnPage.HasChildren       = (TabController.Instance.GetTabsByPortal(PortalSettings.PortalId).WithParentId(tabInfo.TabID).Count != 0);
                dnnPage.CanAdminPage      = TabPermissionController.CanAdminPage(tabInfo);
                dnnPage.CanViewPage       = TabPermissionController.CanViewPage(tabInfo);
                dnnPage.LocalResourceFile = LocalResourceFile;

                // calculate position in the form of 1.3.2...
                var SiblingTabs = tabInfos.Where(t => t.ParentId == localTabInfo.ParentId && t.CultureCode == localTabInfo.CultureCode || t.CultureCode == null).OrderBy(t => t.TabOrder).ToList();
                dnnPage.Position = (SiblingTabs.IndexOf(localTabInfo) + 1).ToString(CultureInfo.InvariantCulture);
                int ParentTabId = localTabInfo.ParentId;
                while (ParentTabId > 0)
                {
                    TabInfo ParentTab = tabInfos.Single(t => t.TabID == ParentTabId);
                    int     id        = ParentTabId;
                    SiblingTabs      = tabInfos.Where(t => t.ParentId == id && t.CultureCode == localTabInfo.CultureCode || t.CultureCode == null).OrderBy(t => t.TabOrder).ToList();
                    dnnPage.Position = (SiblingTabs.IndexOf(localTabInfo) + 1).ToString(CultureInfo.InvariantCulture) + "." + dnnPage.Position;
                    ParentTabId      = ParentTab.ParentId;
                }

                dnnPage.DefaultLanguageGuid = localTabInfo.DefaultLanguageGuid;
                dnnPage.IsTranslated        = localTabInfo.IsTranslated;
                dnnPage.IsPublished         = TabController.Instance.IsTabPublished(localTabInfo);
                // generate modules information
                foreach (var moduleInfo in ModuleController.Instance.GetTabModules(localTabInfo.TabID).Values)
                {
                    var guid = moduleInfo.DefaultLanguageGuid == Null.NullGuid ? moduleInfo.UniqueId : moduleInfo.DefaultLanguageGuid;

                    var dnnModules = Data.Module(guid); // modules of each language
                    var dnnModule  = dnnModules.Module(localTabInfo.CultureCode);
                    // detect error : 2 modules with same uniqueId on the same page
                    dnnModule.LocalResourceFile = LocalResourceFile;
                    if (dnnModule.TabModuleID > 0)
                    {
                        dnnModule.ErrorDuplicateModule = true;
                        ErrorExists = true;
                        continue;
                    }

                    dnnModule.ModuleTitle         = moduleInfo.ModuleTitle;
                    dnnModule.DefaultLanguageGuid = moduleInfo.DefaultLanguageGuid;
                    dnnModule.TabId          = localTabInfo.TabID;
                    dnnModule.TabModuleID    = moduleInfo.TabModuleID;
                    dnnModule.ModuleID       = moduleInfo.ModuleID;
                    dnnModule.CanAdminModule = ModulePermissionController.CanAdminModule(moduleInfo);
                    dnnModule.CanViewModule  = ModulePermissionController.CanViewModule(moduleInfo);
                    dnnModule.IsDeleted      = moduleInfo.IsDeleted;
                    if (moduleInfo.DefaultLanguageGuid != Null.NullGuid)
                    {
                        ModuleInfo defaultLanguageModule = ModuleController.Instance.GetModuleByUniqueID(moduleInfo.DefaultLanguageGuid);
                        if (defaultLanguageModule != null)
                        {
                            dnnModule.DefaultModuleID = defaultLanguageModule.ModuleID;
                            if (defaultLanguageModule.ParentTab.UniqueId != moduleInfo.ParentTab.DefaultLanguageGuid)
                            {
                                dnnModule.DefaultTabName = defaultLanguageModule.ParentTab.TabName;
                            }
                        }
                    }
                    dnnModule.IsTranslated = moduleInfo.IsTranslated;
                    dnnModule.IsLocalized  = moduleInfo.IsLocalized;

                    dnnModule.IsShared = TabController.Instance.GetTabsByModuleID(moduleInfo.ModuleID).Values.Count(t => t.CultureCode == moduleInfo.CultureCode) > 1;

                    // detect error : the default language module is on an other page
                    dnnModule.ErrorDefaultOnOtherTab = moduleInfo.DefaultLanguageGuid != Null.NullGuid && moduleInfo.DefaultLanguageModule == null;

                    // detect error : different culture on tab and module
                    dnnModule.ErrorCultureOfModuleNotCultureOfTab = moduleInfo.CultureCode != localTabInfo.CultureCode;

                    ErrorExists = ErrorExists || dnnModule.ErrorDefaultOnOtherTab || dnnModule.ErrorCultureOfModuleNotCultureOfTab;
                }
            }

            rDnnModules.DataSource = Data.Modules;
            rDnnModules.DataBind();
        }
Ejemplo n.º 19
0
 /// <summary>
 /// This method will save the LatexText in all Culture Codes
 /// It expects the text to be created in t.CultureCode
 /// It will call SaveLatexText(t)
 /// It then translates t into all languages and calls SaveLatexText on each text
 /// </summary>
 /// <param name="t"></param>
 public void SaveLatexTextInAllCc(PHLatex t)
 {
     t.CultureCodeStatus = ECultureCodeStatus.InCreationLanguage;
     SaveLatexText(t);  //Save LatexText in created language
     LocaleController lc = new LocaleController();
     var locales = lc.GetLocales(PortalID);
     PHLatex translatedText;
     foreach (var locale in locales)
     {
         if (locale.Key != t.CultureCode)
         {
             translatedText = GetCurrentVersionLatexText(locale.Key, t.ItemId, t.ItemType);
             if (translatedText == null)
             {
                 translatedText = new PHLatex();
                 translatedText.CultureCode = locale.Key;
                 translatedText.ItemId = t.ItemId;
                 translatedText.ItemType = t.ItemType;
             }
             translatedText.Text = t.Text;
             translatedText.HtmlText = ""; // TranslateText(t.CultureCode.Substring(0, 2), locale.Key.Substring(0, 2), t.HtmlText);
             if (translatedText.CreatedByUserId == 0)
                 translatedText.CreatedByUserId = t.CreatedByUserId;
             translatedText.CultureCodeStatus = ECultureCodeStatus.NotTranslated;
             SaveLatexText(translatedText);
         }
     }
 }