Пример #1
0
        public void ProcessRequest(HttpContext context)
        {
            #region "Initialize"

            var strOut = "";

            var paramCmd = Utils.RequestQueryStringParam(context, "cmd");
            var itemId = Utils.RequestQueryStringParam(context, "itemid");
            var ctlType = Utils.RequestQueryStringParam(context, "ctltype");
            var idXref = Utils.RequestQueryStringParam(context, "idxref");
            var xpathpdf = Utils.RequestQueryStringParam(context, "pdf");
            var xpathref = Utils.RequestQueryStringParam(context, "pdfref");
            var lang = Utils.RequestQueryStringParam(context, "lang");
            var language = Utils.RequestQueryStringParam(context, "language");
            var moduleId = Utils.RequestQueryStringParam(context, "mid");
            var moduleKey = Utils.RequestQueryStringParam(context, "mkey");
            var parentid = Utils.RequestQueryStringParam(context, "parentid");
            var entryid = Utils.RequestQueryStringParam(context, "entryid");
            var entryxid = Utils.RequestQueryStringParam(context, "entryxid");
            var catid = Utils.RequestQueryStringParam(context, "catid");
            var catxid = Utils.RequestQueryStringParam(context, "catxid");
            var templatePrefix = Utils.RequestQueryStringParam(context, "tprefix");
            var value = Utils.RequestQueryStringParam(context, "value");
            var itemListName = Utils.RequestQueryStringParam(context, "listname");
            if (itemListName == "") itemListName = "ItemList";
            if (itemListName == "*") itemListName = "ItemList";

            #region "setup language"

            // because we are using a webservice the system current thread culture might not be set correctly,
            //  so use the lang/lanaguge param to set it.
            if (lang == "") lang = language;
            if (!string.IsNullOrEmpty(lang)) _lang = lang;
            // default to current thread if we have no language.
            if (_lang == "") _lang = System.Threading.Thread.CurrentThread.CurrentCulture.ToString();

            System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture(_lang);

            #endregion

            #endregion

            #region "Do processing of command"

            var intModuleId = 0;
            if (Utils.IsNumeric(moduleId)) intModuleId = Convert.ToInt32(moduleId);

            var objCtrl = new NBrightBuyController();

            var uInfo = new UserDataInfo(UserController.GetCurrentUserInfo().PortalID, intModuleId, objCtrl, ctlType);
            strOut = "ERROR!! - No Security rights for current user!";
            switch (paramCmd)
            {
                case "test":
                    strOut = "<root>" + UserController.GetCurrentUserInfo().Username + "</root>";
                    break;
                case "setdata":
                    break;
                case "deldata":
                    break;
                //case "setcategoryadminform":
                //    if (CheckRights()) strOut = SetCategoryForm(context);
                //    break;
                case "getdata":
                    strOut = GetReturnData(context);
                    break;
                case "additemlist":
                    if (Utils.IsNumeric(itemId))
                    {
                        var cw = new ItemListData(itemListName);
                        cw.Add(itemId);
                        strOut = cw.ItemList;
                    }
                    break;
                case "removeitemlist":
                    if (Utils.IsNumeric(itemId))
                    {
                        var cw1 = new ItemListData(itemListName);
                        cw1.Remove(itemId);
                        strOut = cw1.ItemList;
                    }
                    break;
                case "deleteitemlist":
                        var cw2 = new ItemListData(itemListName);
                        cw2.Delete();
                        strOut = "deleted";
                    break;
                case "getproductselectlist":
                    strOut = GetProductList(context);
                    break;
                case "getproductlist":
                    strOut = GetProductList(context);
                    break;
                case "getcategoryproductlist":
                    strOut = GetCategoryProductList(context);
                    break;
                case "setdefaultcategory":
                    if (CheckRights()) strOut = SetDefaultCategory(context);
                    break;
                case "deletecatxref":
                    if (CheckRights()) strOut = DeleteCatXref(context);
                    break;
                case "selectcatxref":
                    if (CheckRights()) strOut = SelectCatXref(context);
                    break;
                case "deleteallcatxref":
                    if (CheckRights()) strOut = DeleteAllCatXref(context);
                    break;
                case "copyallcatxref":
                    if (CheckRights()) strOut = CopyAllCatXref(context);
                    break;
                case "moveallcatxref":
                    if (CheckRights()) strOut = CopyAllCatXref(context,true);
                    break;
                case "editproduct":
                    if (CheckRights()) strOut = GetProductGeneralData(context);
                    break;
                case "productdescription":
                    if (CheckRights()) strOut = GetProductDescription(context);
                    break;
                case "productmodels":
                    if (CheckRights()) strOut = GetProductModels(context);
                    break;
                case "productoptions":
                    if (CheckRights()) strOut = GetProductOptions(context);
                    break;
                case "productoptionvalues":
                    if (CheckRights()) strOut = GetProductOptionValues(context);
                    break;
                case "productimages":
                    if (CheckRights()) strOut = GetProductImages(context);
                    break;
                case "productdocs":
                    if (CheckRights()) strOut = GetProductDocs(context);
                    break;
                case "productrelatedproducts":
                    if (CheckRights()) strOut = GetProductModels(context);
                    break;
                case "productcategories":
                    if (CheckRights()) strOut = GetProductCategories(context);
                    break;
                case "productisincategory":
                    if (CheckRights()) strOut = ProductIsInCategory(context).ToString();
                    break;
                case "productgroupcategories":
                    if (CheckRights()) strOut = GetProductGroupCategories(context);
                    break;
                case "productrelated":
                    if (CheckRights()) strOut = GetProductRelated(context);
                    break;
                case "addproductmodels":
                    if (CheckRights()) strOut = AddProductModels(context);
                    break;
                case "addproductoptions":
                    if (CheckRights()) strOut = AddProductOptions(context);
                    break;
                case "addproductoptionvalues":
                    if (CheckRights()) strOut = AddProductOptionValues(context);
                    break;
                case "addproductcategory":
                    if (CheckRights()) strOut = AddProductCategory(context);
                    break;
                case "addproductgroupcategory":
                    if (CheckRights()) strOut = AddProductGroupCategory(context);
                    break;
                case "removeproductcategory":
                    if (CheckRights()) strOut = RemoveProductCategory(context);
                    break;
                case "removeproductgroupcategory":
                    if (CheckRights()) strOut = RemoveProductGroupCategory(context);
                    break;
                case "populatecategorylist":
                    if (CheckRights()) strOut = GetGroupCategoryListBox(context);
                    break;
                case "addrelatedproduct":
                    if (CheckRights()) strOut = AddRelatedProduct(context);
                    break;
                case "removerelatedproduct":
                    if (CheckRights()) strOut = RemoveRelatedProduct(context);
                    break;
                case "clientdiscountcodes":
                    if (CheckRights()) strOut = GetClientDiscountCodes(context);
                    break;
                case "addclientdiscountcode":
                    if (CheckRights()) strOut = AddClientDiscountCodes(context);
                    break;
                case "clientvouchercodes":
                    if (CheckRights()) strOut = GetClientVoucherCodes(context);
                    break;
                case "addclientvouchercode":
                    if (CheckRights()) strOut = AddClientVoucherCodes(context);
                    break;
                case "moveproductadmin":
                    if (CheckRights()) strOut = MoveProductAdmin(context);
                    break;
                case "fileupload":
                    if (CheckRights() && Utils.IsNumeric(itemId))
                    {
                        strOut = FileUpload(context);
                    }
                    break;
                case "updateproductimages":
                    if (CheckRights())
                    {
                        UpdateProductImages(context);
                        strOut = GetProductImages(context);
                    }
                    break;
            }

            #endregion

            #region "return results"

                //send back xml as plain text
                context.Response.Clear();
                context.Response.ContentType = "text/plain";
                context.Response.Write(strOut);
                context.Response.End();

            #endregion
        }
Пример #2
0
        private void PageLoad()
        {
            NBrightInfo objCat = null;

            #region "Data Repeater"
            if (_templD.Trim() != "")  // if we don;t have a template, don't do anything
            {

                if (_displayentrypage)
                {
                    // get correct itemid, based on eid given
                    if (_ename != "")
                    {
                        var o = ModCtrl.GetByGuidKey(PortalId, ModuleId, EntityTypeCodeLang, _ename);
                        if (o == null)
                        {
                            o = ModCtrl.GetByGuidKey(PortalId, ModuleId, EntityTypeCode, _ename);
                            if (o != null)
                            {
                                _eid = o.ItemID.ToString("");
                            }
                        }
                        else
                        {
                            _eid = o.ParentItemId.ToString("");
                        }
                    }

                    DisplayDataEntryRepeater(_eid);

                }
                else
                {
                    #region "Order BY"
                    // get orderby from header if it's there
                    var cachekey = "GetSqlOrderBy*rpDataH" + _templH + "*" + ModuleId.ToString();
                    _strOrder = (String)Utils.GetCache(cachekey);
                    if (_strOrder == null || StoreSettings.Current.DebugMode)
                    {
                        _strOrder = GenXmlFunctions.GetSqlOrderBy(rpDataH);
                    }

                    //Default orderby if not set
                    if (String.IsNullOrEmpty(_strOrder)) _strOrder = " Order by ModifiedDate DESC  ";
                    // NOTE: This setting may be overwritten by the navigatedata class in the filter setup
                    #endregion

                    #region "Get Paging setup"
                    //See if we have a pagesize, uses the "searchpagesize" tag token.
                    // : This can be overwritten by the cookie value if we need user selection of pagesize.
                    CtrlPaging.Visible = false;

                    #region "Get pagesize, from best place"
                    var pageSize = 0;
                    if (Utils.IsNumeric(_navigationdata.PageSize)) pageSize = Convert.ToInt32(_navigationdata.PageSize);
                    if (!Utils.IsNumeric(pageSize) && Utils.IsNumeric(ModSettings.Get("pagesize"))) pageSize = Convert.ToInt32(ModSettings.Get("pagesize"));
                    //check for url param page size
                    if (Utils.IsNumeric(_pagesize) && (_pagemid == "" | _pagemid == ModuleId.ToString(CultureInfo.InvariantCulture))) pageSize = Convert.ToInt32(_pagesize);
                    if (pageSize == 0)
                    {
                        var strPgSize = "";
                        if (_templateHeader != null) strPgSize = _templateHeader.GetHiddenFieldValue("searchpagesize");
                        if (_templateHeader != null && strPgSize == "") strPgSize = _templateHeader.GetHiddenFieldValue("pagesize");
                        if (Utils.IsNumeric(strPgSize)) pageSize = Convert.ToInt32(strPgSize);
                    }
                    if (pageSize > 0) CtrlPaging.Visible = true;
                    _navigationdata.PageSize = pageSize.ToString("");
                    #endregion

                    var pageNumber = 1;
                    //check for url param paging
                    if (Utils.IsNumeric(_pagenum) && (_pagemid == "" | _pagemid == ModuleId.ToString(CultureInfo.InvariantCulture)))
                    {
                        pageNumber = Convert.ToInt32(_pagenum);
                    }

                    //Get returnlimt from module settings
                    var returnlimit = 0;
                    var strreturnlimit = ModSettings.Get("returnlimit");
                    if (Utils.IsNumeric(strreturnlimit)) returnlimit = Convert.ToInt32(strreturnlimit);

                    #endregion

                    #region "Get filter setup"

                        // check the display header to see if we have a sqlfilter defined.
                        var strFilter = "";
                        cachekey = "GetSqlSearchFilters*rpDataH" + _templH + "*" + ModuleId.ToString();
                        var strHeaderFilter = (String)Utils.GetCache(cachekey);
                        if (strHeaderFilter == null || StoreSettings.Current.DebugMode)
                        {
                            strHeaderFilter = GenXmlFunctions.GetSqlSearchFilters(rpDataH);
                        }

                        // filter mode and will persist past category selection.
                        if ((_catid == "" && _catname == ""))
                        {
                            if (!_navigationdata.FilterMode) _navigationdata.CategoryId = ""; // filter mode persist catid

                            // if navdata is not deleted then get filter from navdata, created by productsearch module.
                            strFilter = _navigationdata.Criteria;
                            if (!strFilter.Contains(strHeaderFilter)) strFilter += " " + strHeaderFilter;
                            if (!String.IsNullOrEmpty(_navigationdata.OrderBy)) _strOrder = _navigationdata.OrderBy;

                            if (_navigationdata.Mode.ToLower() =="s") _navigationdata.ResetSearch(); // single search so clear after
                        }
                        else
                        {
                            _navigationdata.ResetSearch();

                            // We have a category selected (in url), so overwrite categoryid navigationdata.
                            // This allows the return to the same category after a returning from a entry view.
                            _navigationdata.CategoryId = _catid;
                            strFilter = strHeaderFilter;
                        }

                    #endregion

                    #region "Get Category select setup"

                    //get default catid.
                    var catseo = _catid;
                    var defcatid = ModSettings.Get("defaultcatid");
                    if (Utils.IsNumeric(defcatid))
                    {
                        // if we have no filter use the default category
                        if (_catid == "" && strFilter.Trim() == "") _catid = defcatid;

                        // If we have a static list,then always display the default category
                        if (ModSettings.Get("staticlist") == "True")
                        {
                            _catid = defcatid;
                        }
                    }
                    else
                    {
                        defcatid = ModSettings.Get("defaultpropertyid");
                        if (Utils.IsNumeric(defcatid))
                        {
                            // if we have no filter use the default category
                            if (_catid == "" && strFilter.Trim() == "") _catid = defcatid;

                            // If we have a static list,then always display the default category
                            if (ModSettings.Get("staticlist") == "True")
                            {
                                _catid = defcatid;
                            }
                        }
                    }

                    //check if we are display categories
                    // get category list data
                    if (_catname != "") // if catname passed in url, calculate what the catid is
                    {
                        objCat = ModCtrl.GetByGuidKey(PortalId, ModuleId, "CATEGORYLANG", _catname);
                        if (objCat == null)
                        {
                            // check it's not just a single language
                            objCat = ModCtrl.GetByGuidKey(PortalId, ModuleId, "CATEGORY", _catname);
                            if (objCat != null) _catid = objCat.ItemID.ToString("");
                        }
                        else
                        {
                            _catid = objCat.ParentItemId.ToString("");
                            if (!String.IsNullOrEmpty(objCat.GUIDKey) && Utils.IsNumeric(_catid) && objCat.Lang != Utils.GetCurrentCulture())
                            {
                                // do a 301 redirect to correct url for the langauge (If the langauge is changed on the product list, we need to make sure we have the correct catref for the langauge)
                                var catGrpCtrl = new GrpCatController(Utils.GetCurrentCulture());
                                var activeCat = catGrpCtrl.GetCategory(Convert.ToInt32(_catid));
                                if (activeCat != null && (activeCat.categoryrefGUIDKey == _catname))
                                {
                                    var redirecturl = "";
                                    if (Utils.IsNumeric(_eid))
                                    {
                                        var prdData = ProductUtils.GetProductData(Convert.ToInt32(_eid), Utils.GetCurrentCulture());
                                        redirecturl = NBrightBuyUtils.GetEntryUrl(PortalId, _eid, _modkey, prdData.SEOName, TabId.ToString(), "", activeCat.categoryrefGUIDKey);
                                    }
                                    else
                                    {
                                        redirecturl = catGrpCtrl.GetCategoryUrl(activeCat, TabId, objCat.Lang);
                                    }

                                    try
                                    {
                                        if (redirecturl != "")
                                        {
                                            Response.Redirect(redirecturl, false);
                                            Response.StatusCode = (int)System.Net.HttpStatusCode.MovedPermanently;
                                            Response.End();
                                        }
                                    }
                                    catch (Exception)
                                    {
                                        // catch err
                                    }
                                }
                            }
                        }
                        // We have a category selected (in url), so overwrite categoryid navigationdata.
                        // This allows the return to the same category after a returning from a entry view.
                        _navigationdata.CategoryId = _catid;
                        catseo = _catid;
                    }

                    if (Utils.IsNumeric(_catid))
                    {
                        var objQual = DotNetNuke.Data.DataProvider.Instance().ObjectQualifier;
                        var dbOwner = DataProvider.Instance().DatabaseOwner;
                        if (ModSettings.Get("chkcascaderesults").ToLower() == "true")
                        {
                            strFilter = strFilter + " and NB1.[ItemId] in (select parentitemid from " + dbOwner + "[" + objQual + "NBrightBuy] where (typecode = 'CATCASCADE' or typecode = 'CATXREF') and XrefItemId = " + _catid + ") ";
                        }
                        else
                            strFilter = strFilter + " and NB1.[ItemId] in (select parentitemid from " + dbOwner + "[" + objQual + "NBrightBuy] where typecode = 'CATXREF' and XrefItemId = " + _catid + ") ";

                        if (Utils.IsNumeric(catseo))
                        {
                            var objSEOCat = ModCtrl.GetData(Convert.ToInt32(catseo), "CATEGORYLANG", Utils.GetCurrentCulture());
                            if (objSEOCat != null && _eid == "") // we may have a detail page and listonly module, in which can we need the product detail as page title
                            {
                                //Page Title
                                var seoname = objSEOCat.GetXmlProperty("genxml/lang/genxml/textbox/txtseoname");
                                if (seoname == "") seoname = objSEOCat.GetXmlProperty("genxml/lang/genxml/textbox/txtcategoryname");

                                var newBaseTitle = objSEOCat.GetXmlProperty("genxml/lang/genxml/textbox/txtseopagetitle");
                                if (newBaseTitle == "") newBaseTitle = objSEOCat.GetXmlProperty("genxml/lang/genxml/textbox/txtseoname");
                                if (newBaseTitle == "") newBaseTitle = objSEOCat.GetXmlProperty("genxml/lang/genxml/textbox/txtcategoryname");
                                if (newBaseTitle != "") BasePage.Title = newBaseTitle;
                                //Page KeyWords
                                var newBaseKeyWords = objSEOCat.GetXmlProperty("genxml/lang/genxml/textbox/txtmetakeywords");
                                if (newBaseKeyWords != "") BasePage.KeyWords = newBaseKeyWords;
                                //Page Description
                                var newBaseDescription = objSEOCat.GetXmlProperty("genxml/lang/genxml/textbox/txtmetadescription");
                                if (newBaseDescription == "") newBaseDescription = objSEOCat.GetXmlProperty("genxml/lang/genxml/textbox/txtcategorydesc");
                                if (newBaseDescription != "") BasePage.Description = newBaseDescription;

                                if (PortalSettings.HomeTabId == TabId)
                                    PageIncludes.IncludeCanonicalLink(Page, Globals.AddHTTP(PortalSettings.PortalAlias.HTTPAlias)); //home page always default of site.
                                else
                                {
                                    PageIncludes.IncludeCanonicalLink(Page, NBrightBuyUtils.GetListUrl(PortalId, TabId, objSEOCat.ItemID, seoname, Utils.GetCurrentCulture()));
                                }
                            }
                        }

                        if (_strOrder == "{bycategoryproduct}") _strOrder += _catid; // do special custom sort in each cateogry

                    }
                    else
                    {
                        if (!_navigationdata.FilterMode) _navigationdata.CategoryId = ""; // filter mode persist catid
                        if (_strOrder == "{bycategoryproduct}") _strOrder = " Order by ModifiedDate DESC  ";
                    }

                    #endregion

                    #region "Apply provider product filter"
                    // Special filtering can be done, by using the ProductFilter interface.
                    var productfilterkey = "";
                    if (_templateHeader != null) productfilterkey = _templateHeader.GetHiddenFieldValue("providerfilterkey");
                    if (productfilterkey != "")
                    {
                        var provfilter = FilterInterface.Instance(productfilterkey);
                        if (provfilter != null) strFilter = provfilter.GetFilter(strFilter, _navigationdata, ModSettings, Context);
                    }
                    #endregion

                    #region "itemlists (wishlist)"

                    // if we have a itemListName field then get the itemlist cookie.
                    if (_templateHeader != null) _itemListName = _templateHeader.GetHiddenFieldValue("itemlistname");
                    if (_itemListName != "")
                    {
                        var cw = new ItemListData(_itemListName);
                            if (cw.Exists && cw.ItemCount > 0)
                            {
                                strFilter = " and (";
                                foreach (var i in cw.GetItemList())
                                {
                                    strFilter += " NB1.itemid = '" + i + "' or";
                                }
                                strFilter = strFilter.Substring(0, (strFilter.Length - 3)) + ") "; // remove the last "or"
                            }
                            else
                            {
                                //no data in list so select false itemid to stop anything displaying
                                strFilter += " and (NB1.itemid = '-1') ";
                            }
                    }

                    #endregion

                    // save navigation data
                    _navigationdata.PageModuleId = Utils.RequestParam(Context, "pagemid");
                    _navigationdata.PageNumber = Utils.RequestParam(Context, "page");
                    if (Utils.IsNumeric(_catid)) _navigationdata.PageName = NBrightBuyUtils.GetCurrentPageName(Convert.ToInt32(_catid));

                    // save the last active modulekey to a cookie, so it can be used by the "NBrightBuyUtils.GetReturnUrl" function
                    NBrightCore.common.Cookie.SetCookieValue(PortalId, "NBrigthBuyLastActive", "ModuleKey", ModuleKey,1);

                    strFilter += " and (NB3.Visible = 1) "; // get only visible products

                    var recordCount = ModCtrl.GetDataListCount(PortalId, ModuleId, "PRD", strFilter, "PRDLANG", Utils.GetCurrentCulture(), DebugMode);

                    _navigationdata.RecordCount = recordCount.ToString("");
                    _navigationdata.Save();

                    if (returnlimit > 0 && returnlimit < recordCount) recordCount = returnlimit;

                    var l = ModCtrl.GetDataList(PortalId, ModuleId, "PRD", "PRDLANG", Utils.GetCurrentCulture(), strFilter, _strOrder, DebugMode, "", returnlimit, pageNumber, pageSize, recordCount);
                    rpData.DataSource = l;
                    rpData.DataBind();

                    if (_navigationdata.SingleSearchMode) _navigationdata.ResetSearch();

                    if (pageSize > 0)
                    {
                        CtrlPaging.PageSize = pageSize;
                        CtrlPaging.CurrentPage = pageNumber;
                        CtrlPaging.TotalRecords = recordCount;
                        CtrlPaging.BindPageLinks();
                    }

                    // display header (Do header after the data return so the productcount works)
                    if (objCat == null)
                        base.DoDetail(rpDataH,ModuleId);
                    else
                    {
                        if (StoreSettings.Current.DebugModeFileOut) objCat.XMLDoc.Save(PortalSettings.HomeDirectoryMapPath + "debug_categoryproductheader.xml");
                        DoDetail(rpDataH, objCat);
                    }

                }
            }

            #endregion

            // display footer
            base.DoDetail(rpDataF);
        }
        private void RazorPageLoad()
        {
            NBrightInfo objCat = null;

            if (_templD.Trim() != "")  // if we don;t have a template, don't do anything
            {

                if (_displayentrypage)
                {
                    // get correct itemid, based on eid given
                    _eid = GetEntryIdFromName(_eid);
                    RazorDisplayDataEntry(_eid);

                }
                else
                {
                    // Get meta data from template

                    var metaTokens = NBrightBuyUtils.RazorPreProcessTempl(_templD, ControlPath, ModSettings.ThemeFolder, Utils.GetCurrentCulture(), ModSettings.Settings(), ModuleId.ToString());

                    #region "Order BY"

                    ////////////////////////////////////////////
                    // get ORDERBY SORT
                    ////////////////////////////////////////////
                    if (_orderbyindex != "") // if we have orderby set in url, find the meta tags
                    {
                        if (metaTokens.ContainsKey("orderby" + _orderbyindex))
                        {
                            _navigationdata.OrderBy = " Order by " + metaTokens["orderby" + _orderbyindex];
                        }
                    }
                    else
                    {
                        if (String.IsNullOrEmpty(_navigationdata.OrderBy) && metaTokens.ContainsKey("orderby"))
                        {
                            _navigationdata.OrderBy = " Order by " + metaTokens["orderby"];
                            _navigationdata.Save();
                        }
                    }

                    #endregion

                    #region "Get Paging setup"

                    //See if we have a pagesize, uses the "searchpagesize" tag token.
                    // : This can be overwritten by the cookie value if we need user selection of pagesize.
                    CtrlPaging.Visible = false;

                    #region "Get pagesize, from best place"

                    var pageSize = 0;
                    if (Utils.IsNumeric(ModSettings.Get("pagesize"))) pageSize = Convert.ToInt32(ModSettings.Get("pagesize"));
                    // overwrite default module pagesize , if we have a pagesize control in the template
                    if (metaTokens.ContainsKey("selectpagesize") && Utils.IsNumeric(_navigationdata.PageSize))
                    {
                        pageSize = Convert.ToInt32(_navigationdata.PageSize);
                    }
                    //check for url param page size
                    if (Utils.IsNumeric(_pagesize) && (_pagemid == "" | _pagemid == ModuleId.ToString(CultureInfo.InvariantCulture))) pageSize = Convert.ToInt32(_pagesize);
                    if (pageSize == 0)
                    {
                        var strPgSize = "";
                        if (metaTokens.ContainsKey("searchpagesize")) strPgSize = metaTokens["searchpagesize"];
                        if (metaTokens.ContainsKey("pagesize") && strPgSize == "") strPgSize = metaTokens["pagesize"];
                        if (Utils.IsNumeric(strPgSize)) pageSize = Convert.ToInt32(strPgSize);
                    }
                    if (pageSize > 0) CtrlPaging.Visible = true;
                    _navigationdata.PageSize = pageSize.ToString("");

                    #endregion

                    var pageNumber = 1;
                    //check for url param paging
                    if (Utils.IsNumeric(_pagenum) && (_pagemid == "" | _pagemid == ModuleId.ToString(CultureInfo.InvariantCulture)))
                    {
                        pageNumber = Convert.ToInt32(_pagenum);
                    }

                    //Get returnlimt from module settings
                    var returnlimit = 0;
                    var strreturnlimit = ModSettings.Get("returnlimit");
                    if (Utils.IsNumeric(strreturnlimit)) returnlimit = Convert.ToInt32(strreturnlimit);

                    #endregion

                    #region "Get filter setup"

                    // check the display header to see if we have a sqlfilter defined.
                    var strFilter = "";
                    var sqlTemplateFilter = "";
                    if (metaTokens.ContainsKey("sqlfilter")) sqlTemplateFilter = GenXmlFunctions.StripSqlCommands(metaTokens["sqlfilter"]);

                    if (_navigationdata.HasCriteria)
                    {
                        var paramcatid = Utils.RequestQueryStringParam(Context, "catid");
                        if (Utils.IsNumeric(paramcatid))
                        {
                            if (_navigationdata.CategoryId != Convert.ToInt32(paramcatid)) // filter mode DOES NOT persist catid (stop confusion when user selects a category)
                            {
                                _navigationdata.ResetSearch();
                            }
                        }

                        // if navdata is not deleted then get filter from navdata, created by productsearch module.
                        strFilter = _navigationdata.Criteria;
                        if (!strFilter.Contains(sqlTemplateFilter)) strFilter += " " + sqlTemplateFilter;

                        if (_navigationdata.Mode.ToLower() == "s") _navigationdata.ResetSearch(); // single search so clear after
                    }
                    else
                    {
                        // reset search if category selected
                        // NOTE: keeping search across categories is VERY confusing for cleint, although it works logically.
                        _navigationdata.ResetSearch();
                        strFilter = sqlTemplateFilter;
                    }

                    #endregion

                    #region "Get Category select setup"

                    var objQual = DotNetNuke.Data.DataProvider.Instance().ObjectQualifier;
                    var dbOwner = DataProvider.Instance().DatabaseOwner;

                    //get default catid.
                    var catseo = _catid;
                    var defcatid = ModSettings.Get("defaultcatid");
                    if (Utils.IsNumeric(defcatid))
                    {
                        // if we have no filter use the default category
                        if (_catid == "" && strFilter.Trim() == "") _catid = defcatid;
                    }
                    else
                    {
                        defcatid = ModSettings.Get("defaultpropertyid");
                        if (Utils.IsNumeric(defcatid))
                        {
                            // if we have no filter use the default category
                            if (_catid == "" && strFilter.Trim() == "") _catid = defcatid;
                        }
                    }

                    // If we have a static list,then always display the default category
                    if (ModSettings.Get("staticlist") == "True")
                    {
                        if (catseo == "") catseo = _catid;
                        _catid = defcatid;
                        if (ModSettings.Get("chkcascaderesults").ToLower() == "true")
                            strFilter = strFilter + " and NB1.[ItemId] in (select parentitemid from " + dbOwner + "[" + objQual + "NBrightBuy] where (typecode = 'CATCASCADE' or typecode = 'CATXREF') and XrefItemId = " + _catid + ") ";
                        else
                            strFilter = strFilter + " and NB1.[ItemId] in (select parentitemid from " + dbOwner + "[" + objQual + "NBrightBuy] where typecode = 'CATXREF' and XrefItemId = " + _catid + ") ";

                        if (ModSettings.Get("caturlfilter") == "True" && catseo != "" && catseo != _catid)
                        {
                            // add aditional filter for catid filter on url (catseo holds catid from url)
                            if (ModSettings.Get("chkcascaderesults").ToLower() == "true")
                                strFilter = strFilter + " and NB1.[ItemId] in (select parentitemid from " + dbOwner + "[" + objQual + "NBrightBuy] where (typecode = 'CATCASCADE' or typecode = 'CATXREF') and XrefItemId = " + catseo + ") ";
                            else
                                strFilter = strFilter + " and NB1.[ItemId] in (select parentitemid from " + dbOwner + "[" + objQual + "NBrightBuy] where typecode = 'CATXREF' and XrefItemId = " + catseo + ") ";
                        }
                    }
                    else
                    {
                        #region "use url to get category to display"

                        //check if we are display categories
                        // get category list data
                        if (_catname != "") // if catname passed in url, calculate what the catid is
                        {
                            objCat = ModCtrl.GetByGuidKey(PortalId, ModuleId, "CATEGORYLANG", _catname);
                            if (objCat == null)
                            {
                                // check it's not just a single language
                                objCat = ModCtrl.GetByGuidKey(PortalId, ModuleId, "CATEGORY", _catname);
                                if (objCat != null) _catid = objCat.ItemID.ToString("");
                            }
                            else
                            {
                                _catid = objCat.ParentItemId.ToString("");
                                if (!String.IsNullOrEmpty(objCat.GUIDKey) && Utils.IsNumeric(_catid) && objCat.Lang != Utils.GetCurrentCulture())
                                {
                                    // do a 301 redirect to correct url for the langauge (If the langauge is changed on the product list, we need to make sure we have the correct catref for the langauge)
                                    var catGrpCtrl = new GrpCatController(Utils.GetCurrentCulture());
                                    var activeCat = catGrpCtrl.GetCategory(Convert.ToInt32(_catid));
                                    if (activeCat != null)
                                    {
                                        var redirecturl = "";
                                        if (Utils.IsNumeric(_eid))
                                        {
                                            var prdData = ProductUtils.GetProductData(Convert.ToInt32(_eid), Utils.GetCurrentCulture(), true, EntityTypeCode);
                                            redirecturl = NBrightBuyUtils.GetEntryUrl(PortalId, _eid, _modkey, prdData.SEOName, TabId.ToString(), "", activeCat.categoryrefGUIDKey);
                                        }
                                        else
                                        {
                                            redirecturl = catGrpCtrl.GetCategoryUrl(activeCat, TabId);
                                        }

                                        try
                                        {
                                            if (redirecturl != "")
                                            {
                                                Response.Redirect(redirecturl, false);
                                                Response.StatusCode = (int) System.Net.HttpStatusCode.MovedPermanently;
                                                Response.End();
                                            }
                                        }
                                        catch (Exception)
                                        {
                                            // catch err
                                        }
                                    }
                                }
                            }
                            // We have a category selected (in url), so overwrite categoryid navigationdata.
                            // This allows the return to the same category after a returning from a entry view.
                            if (Utils.IsNumeric(_catid)) _navigationdata.CategoryId = Convert.ToInt32(_catid);
                            catseo = _catid;
                        }

                        if (Utils.IsNumeric(_catid))
                        {

                            if (ModSettings.Get("chkcascaderesults").ToLower() == "true")
                                strFilter = strFilter + " and NB1.[ItemId] in (select parentitemid from " + dbOwner + "[" + objQual + "NBrightBuy] where (typecode = 'CATCASCADE' or typecode = 'CATXREF') and XrefItemId = " + _catid + ") ";
                            else
                                strFilter = strFilter + " and NB1.[ItemId] in (select parentitemid from " + dbOwner + "[" + objQual + "NBrightBuy] where typecode = 'CATXREF' and XrefItemId = " + _catid + ") ";

                            if (Utils.IsNumeric(catseo))
                            {
                                var objSEOCat = ModCtrl.GetData(Convert.ToInt32(catseo), "CATEGORYLANG", Utils.GetCurrentCulture());
                                if (objSEOCat != null && _eid == "") // we may have a detail page and listonly module, in which can we need the product detail as page title
                                {
                                    //Page Title
                                    var seoname = objSEOCat.GetXmlProperty("genxml/lang/genxml/textbox/txtseoname");
                                    if (seoname == "") seoname = objSEOCat.GetXmlProperty("genxml/lang/genxml/textbox/txtcategoryname");

                                    var newBaseTitle = objSEOCat.GetXmlProperty("genxml/lang/genxml/textbox/txtseopagetitle");
                                    if (newBaseTitle == "") newBaseTitle = objSEOCat.GetXmlProperty("genxml/lang/genxml/textbox/txtseoname");
                                    if (newBaseTitle == "") newBaseTitle = objSEOCat.GetXmlProperty("genxml/lang/genxml/textbox/txtcategoryname");
                                    if (newBaseTitle != "") BasePage.Title = newBaseTitle;
                                    //Page KeyWords
                                    var newBaseKeyWords = objSEOCat.GetXmlProperty("genxml/lang/genxml/textbox/txtmetakeywords");
                                    if (newBaseKeyWords != "") BasePage.KeyWords = newBaseKeyWords;
                                    //Page Description
                                    var newBaseDescription = objSEOCat.GetXmlProperty("genxml/lang/genxml/textbox/txtmetadescription");
                                    if (newBaseDescription == "") newBaseDescription = objSEOCat.GetXmlProperty("genxml/lang/genxml/textbox/txtcategorydesc");
                                    if (newBaseDescription != "") BasePage.Description = newBaseDescription;

                                    if (PortalSettings.HomeTabId == TabId)
                                        PageIncludes.IncludeCanonicalLink(Page, Globals.AddHTTP(PortalSettings.PortalAlias.HTTPAlias)); //home page always default of site.
                                    else
                                    {
                                        PageIncludes.IncludeCanonicalLink(Page, NBrightBuyUtils.GetListUrl(PortalId, TabId, objSEOCat.ItemID, seoname, Utils.GetCurrentCulture()));
                                    }
                                }
                            }

                            // do special custom sort in each cateogry, this passes the catid to the SQL SPROC, whcih process the '{bycategoryproduct}' and orders by product/category seq.
                            if (_navigationdata.OrderBy.Contains("{bycategoryproduct}")) _navigationdata.OrderBy = "{bycategoryproduct}" +  _catid;

                        }
                        else
                        {
                            if (!_navigationdata.FilterMode) _navigationdata.CategoryId = 0; // filter mode persist catid
                            if (_navigationdata.OrderBy.Contains("{bycategoryproduct}")) _navigationdata.OrderBy = " Order by ModifiedDate DESC  ";
                        }

                        #endregion
                    }

                    // This allows the return to the same category after a returning from a entry view. + Gives support for current category in razor tokens
                    if (Utils.IsNumeric(_catid)) _navigationdata.CategoryId = Convert.ToInt32(_catid);

                    #endregion

                    #region "Apply provider product filter"

                    // Special filtering can be done, by using the ProductFilter interface.
                    var productfilterkey = "";
                    if (metaTokens.ContainsKey("providerfilterkey")) productfilterkey = metaTokens["providerfilterkey"];
                    if (productfilterkey != "")
                    {
                        var provfilter = FilterInterface.Instance(productfilterkey);
                        if (provfilter != null) strFilter = provfilter.GetFilter(strFilter, _navigationdata, ModSettings, Context);
                    }

                    #endregion

                    #region "itemlists (wishlist)"

                    // if we have a itemListName field then get the itemlist cookie.
                    if (ModSettings.Get("displaytype") == "2") // displaytype 2 = "selected list"
                    {
                        if (metaTokens.ContainsKey("itemlistname")) _itemListName = metaTokens["itemlistname"];
                        if (_itemListName == "") _itemListName = Utils.RequestParam(Context, "itemlistname"); // see if we've passed a wishlist name in url
                        if (_itemListName != "")
                        {
                            var cw = new ItemListData(_itemListName);
                            if (cw.Exists && cw.ItemCount > 0)
                            {
                                strFilter = " and (";
                                foreach (var i in cw.GetItemList())
                                {
                                    strFilter += " NB1.itemid = '" + i + "' or";
                                }
                                strFilter = strFilter.Substring(0, (strFilter.Length - 3)) + ") "; // remove the last "or"
                            }
                            else
                            {
                                //no data in list so select false itemid to stop anything displaying
                                strFilter += " and (NB1.itemid = '-1') ";
                            }
                        }
                    }

                    #endregion

                    // insert page header text
                    NBrightBuyUtils.RazorIncludePageHeader(ModuleId, Page, Path.GetFileNameWithoutExtension(_templD) + "_head" + Path.GetExtension(_templD), ControlPath, ModSettings.ThemeFolder, ModSettings.Settings());

                    // save navigation data
                    _navigationdata.PageModuleId = Utils.RequestParam(Context, "pagemid");
                    _navigationdata.PageNumber = Utils.RequestParam(Context, "page");
                    if (Utils.IsNumeric(_catid)) _navigationdata.PageName = NBrightBuyUtils.GetCurrentPageName(Convert.ToInt32(_catid));

                    // save the last active modulekey to a cookie, so it can be used by the "NBrightBuyUtils.GetReturnUrl" function
                    NBrightCore.common.Cookie.SetCookieValue(PortalId, "NBrigthBuyLastActive", "ModuleKey", ModuleKey, 1);

                    strFilter += " and (NB3.Visible = 1) "; // get only visible products

                    var recordCount = ModCtrl.GetDataListCount(PortalId, ModuleId, EntityTypeCode, strFilter, EntityTypeCodeLang, Utils.GetCurrentCulture(), DebugMode);

                    _navigationdata.RecordCount = recordCount.ToString("");
                    _navigationdata.Save();

                    if (returnlimit > 0 && returnlimit < recordCount) recordCount = returnlimit;

                    // **** check if we already have the template cached, if so no need for DB call or razor call ****
                    // get same cachekey used for DB return, and use for razor.
                    var razorcachekey = ModCtrl.GetDataListCacheKey(PortalId, ModuleId, EntityTypeCode, EntityTypeCodeLang, Utils.GetCurrentCulture(), strFilter, _navigationdata.OrderBy, DebugMode, "", returnlimit, pageNumber, pageSize, recordCount);
                    var cachekey = "NBrightBuyRazorOutput" + _templD + "*" + razorcachekey + PortalId.ToString();
                    var strOut = (String) NBrightBuyUtils.GetModCache(cachekey);
                    if (strOut == null || StoreSettings.Current.DebugMode)
                    {
                        var l = ModCtrl.GetDataList(PortalId, ModuleId, EntityTypeCode, EntityTypeCodeLang, Utils.GetCurrentCulture(), strFilter, _navigationdata.OrderBy, DebugMode, "", returnlimit, pageNumber, pageSize, recordCount);
                        strOut = NBrightBuyUtils.RazorTemplRenderList(_templD, ModuleId, razorcachekey, l, ControlPath, ModSettings.ThemeFolder, Utils.GetCurrentCulture(), ModSettings.Settings());
                    }

                    var lit = new Literal();
                    lit.Text = strOut;
                    phData.Controls.Add(lit);

                    if (_navigationdata.SingleSearchMode) _navigationdata.ResetSearch();

                    if (pageSize > 0)
                    {
                        CtrlPaging.PageSize = pageSize;
                        CtrlPaging.CurrentPage = pageNumber;
                        CtrlPaging.TotalRecords = recordCount;
                        CtrlPaging.BindPageLinks();
                    }

                }
            }
        }
Пример #4
0
        public override TestOfData TestOfDataBinding(object sender, EventArgs e)
        {
            var rtnData = new TestOfData();
            rtnData.DataValue = null;
            rtnData.TestValue = null;
            var lc = (Literal)sender;
            var container = (IDataItemContainer)lc.NamingContainer;
            try
            {
                NBrightInfo info;

                ProductData prodData;
                CatProdXref xrefData;

                var xmlDoc = new XmlDocument();
                CartData currentcart;

                xmlDoc.LoadXml("<root>" + lc.Text + "</root>");
                var xmlNod = xmlDoc.SelectSingleNode("root/tag");

                if (container.DataItem != null && xmlNod != null && (xmlNod.Attributes != null && xmlNod.Attributes["function"] != null))
                {
                    rtnData.DataValue = "FALSE";

                    XmlNode nod;
                    var testValue = "";
                    if ((xmlNod.Attributes["testvalue"] != null)) testValue = xmlNod.Attributes["testvalue"].Value;

                    // check for setting key
                    var settingkey = "";
                    if ((xmlNod.Attributes["key"] != null)) settingkey = xmlNod.Attributes["key"].Value;

                    var role = "";
                    if ((xmlNod.Attributes["role"] != null)) role = xmlNod.Attributes["role"].Value;

                    var index = "";
                    if ((xmlNod.Attributes["index"] != null)) index = xmlNod.Attributes["index"].Value;

                    var modulekey = "";
                    if ((xmlNod.Attributes["modulekey"] != null)) modulekey = xmlNod.Attributes["modulekey"].Value;

                    var targetmodulekey = "";
                    if ((xmlNod.Attributes["targetmodulekey"] != null)) targetmodulekey = xmlNod.Attributes["targetmodulekey"].Value;

                    // do special tests for named fucntions
                    switch (xmlNod.Attributes["function"].Value.ToLower())
                    {
                        case "searchactive":
                            var navdata2 = new NavigationData(PortalSettings.Current.PortalId, targetmodulekey);
                            if (navdata2.Criteria == "") rtnData.DataValue = "FALSE";
                            else rtnData.DataValue = "TRUE";
                            break;
                        case "productcount":
                            var navdata = new NavigationData(PortalSettings.Current.PortalId, modulekey);
                            rtnData.DataValue = navdata.RecordCount;
                            break;
                        case "price":
                            rtnData.DataValue = GetFromPrice((NBrightInfo) container.DataItem);
                            break;
                        case "dealerprice":
                            rtnData.DataValue = GetDealerPrice((NBrightInfo) container.DataItem);
                            break;
                        case "saleprice":
                            rtnData.DataValue = GetSalePrice((NBrightInfo) container.DataItem);
                            break;
                        case "imgexists":
                            rtnData.DataValue = testValue;
                            nod = GenXmlFunctions.GetGenXmLnode(DataBinder.Eval(container.DataItem, _databindColumn).ToString(), "genxml/imgs/genxml[" + rtnData.DataValue + "]");
                            if (nod == null) rtnData.DataValue = "FALSE";
                            break;
                        case "modelexists":
                            rtnData.DataValue = testValue;
                            nod = GenXmlFunctions.GetGenXmLnode(DataBinder.Eval(container.DataItem, _databindColumn).ToString(), "genxml/models/genxml[" + rtnData.DataValue + "]");
                            if (nod == null) rtnData.DataValue = "FALSE";
                            break;
                        case "optionexists":
                            rtnData.DataValue = testValue;
                            nod = GenXmlFunctions.GetGenXmLnode(DataBinder.Eval(container.DataItem, _databindColumn).ToString(), "genxml/options/genxml[" + rtnData.DataValue + "]");
                            if (nod == null) rtnData.DataValue = "FALSE";
                            break;
                        case "isinstock":
                            if (IsInStock((NBrightInfo) container.DataItem))
                            {
                                rtnData.DataValue = "TRUE";
                                rtnData.TestValue = "TRUE";
                            }
                            break;
                        case "ismodelinstock":
                            if (IsModelInStock((NBrightInfo) container.DataItem))
                            {
                                rtnData.DataValue = "TRUE";
                                rtnData.TestValue = "TRUE";
                            }
                            break;
                        case "inwishlist":
                            var productid = DataBinder.Eval(container.DataItem, "ItemId").ToString();
                            if (Utils.IsNumeric(productid))
                            {
                                var listname = "ItemList";
                                if ((xmlNod.Attributes["listname"] != null)) listname = xmlNod.Attributes["listname"].Value;

                                var wl = new ItemListData(listname);
                                if (wl.IsInList(productid))
                                {
                                    rtnData.DataValue = "TRUE";
                                    rtnData.TestValue = "TRUE";
                                }
                            }
                            break;
                        case "isonsale":
                            var saleprice = GetSalePriceDouble((NBrightInfo) container.DataItem);
                            if (saleprice > 0)
                            {
                                rtnData.DataValue = "TRUE";
                                rtnData.TestValue = "TRUE";
                            }
                            break;
                        case "hasrelateditems":
                            info = (NBrightInfo) container.DataItem;
                            prodData = ProductUtils.GetProductData(info.ItemID, info.Lang);
                            if (prodData.GetRelatedProducts().Count > 0)
                            {
                                rtnData.DataValue = "TRUE";
                                rtnData.TestValue = "TRUE";
                            }
                            break;
                        case "hasdocuments":
                            info = (NBrightInfo) container.DataItem;
                            prodData = ProductUtils.GetProductData(info.ItemID, info.Lang);
                            if (prodData.Docs.Count > 0)
                            {
                                rtnData.DataValue = "TRUE";
                                rtnData.TestValue = "TRUE";
                            }
                            break;
                        case "haspurchasedocuments":
                            info = (NBrightInfo) container.DataItem;
                            prodData = ProductUtils.GetProductData(info.ItemID, info.Lang);
                            if (prodData.Docs.Select(i => i.GetXmlProperty("genxml/checkbox/chkpurchase") == "True").Any())
                            {
                                rtnData.DataValue = "TRUE";
                                rtnData.TestValue = "TRUE";
                            }
                            break;
                        case "hasproperty":
                            info = (NBrightInfo) container.DataItem;
                            xrefData = new CatProdXref();
                            if (xrefData.IsProductInCategory(info.ItemID,testValue))
                            {
                                rtnData.DataValue = "TRUE";
                                rtnData.TestValue = "TRUE";
                            }
                            break;
                        case "isincategory":
                            info = (NBrightInfo) container.DataItem;
                            xrefData = new CatProdXref();
                            if (xrefData.IsProductInCategory(info.ItemID,testValue))
                            {
                                rtnData.DataValue = "TRUE";
                                rtnData.TestValue = "TRUE";
                            }
                            break;
                        case "isdocpurchasable":
                            nod = GenXmlFunctions.GetGenXmLnode(DataBinder.Eval(container.DataItem, _databindColumn).ToString(), "genxml/docs/genxml[" + index + "]/hidden/docid");
                            if (nod != null)
                            {
                                info = (NBrightInfo) container.DataItem;
                                prodData = ProductUtils.GetProductData(info.ItemID, info.Lang);
                                if (prodData.Docs.Select(i => i.GetXmlProperty("genxml/checkbox/chkpurchase") == "True" && i.GetXmlProperty("genxml/hidden/docid") == nod.InnerText).Any())
                                {
                                    rtnData.DataValue = "TRUE";
                                    rtnData.TestValue = "TRUE";
                                }
                            }
                            break;
                        case "isdocpurchased":
                            nod = GenXmlFunctions.GetGenXmLnode(DataBinder.Eval(container.DataItem, _databindColumn).ToString(), "genxml/docs/genxml[" + index + "]/hidden/docid");
                            if (nod != null && Utils.IsNumeric(nod.InnerText))
                            {
                                var uInfo = UserController.GetCurrentUserInfo();
                                //[TODO: work out method of finding if user purchased document.]
                                //if (NBrightBuyV2Utils.DocHasBeenPurchasedByDocId(uInfo.UserID, Convert.ToInt32(nod.InnerText)))
                                //{
                                //    rtnData.DataValue = "TRUE";
                                //    rtnData.TestValue = "TRUE";
                                //}
                            }
                            break;
                        case "hasmodelsoroptions":
                            nod = GenXmlFunctions.GetGenXmLnode(DataBinder.Eval(container.DataItem, _databindColumn).ToString(), "genxml/models/genxml[2]/hidden/modelid");
                            if (nod != null && nod.InnerText != "")
                            {
                                rtnData.DataValue = "TRUE";
                                rtnData.TestValue = "TRUE";
                            }
                            if (rtnData.DataValue == "FALSE")
                            {
                                nod = GenXmlFunctions.GetGenXmLnode(DataBinder.Eval(container.DataItem, _databindColumn).ToString(), "genxml/options/genxml[1]/hidden/optionid");
                                if (nod != null && nod.InnerText != "")
                                {
                                    rtnData.DataValue = "TRUE";
                                    rtnData.TestValue = "TRUE";
                                }
                            }
                            break;
                        case "isproductincart":
                            var cartData = new CartData(PortalSettings.Current.PortalId);
                            info = (NBrightInfo) container.DataItem;
                            if (cartData.GetCartItemList().Select(i => i.GetXmlProperty("genxml/productid") == info.ItemID.ToString("")).Any())
                            {
                                rtnData.DataValue = "TRUE";
                                rtnData.TestValue = "TRUE";
                            }
                            break;
                        case "settings":
                            if (_settings != null && _settings.ContainsKey(settingkey) && _settings[settingkey] == testValue)
                            {
                                rtnData.DataValue = "TRUE";
                                rtnData.TestValue = "TRUE";
                            }
                            break;
                        case "debugmode":
                            if (StoreSettings.Current.DebugMode)
                            {
                                rtnData.DataValue = "TRUE";
                                rtnData.TestValue = "TRUE";
                            }
                            break;
                        case "isinrole":
                            if (CmsProviderManager.Default.IsInRole(role))
                            {
                                rtnData.DataValue = "TRUE";
                                rtnData.TestValue = "TRUE";
                            }
                            break;
                        case "issuperuser":
                            if (UserController.GetCurrentUserInfo().IsSuperUser)
                            {
                                rtnData.DataValue = "TRUE";
                                rtnData.TestValue = "TRUE";
                            }
                            break;
                        case "isuser":
                            if (UserController.GetCurrentUserInfo().UserID >= 0)
                            {
                                rtnData.DataValue = "TRUE";
                                rtnData.TestValue = "TRUE";
                            }
                            break;
                        case "isclientordermode":
                            currentcart = new CartData(PortalSettings.Current.PortalId);
                            if (currentcart.IsClientOrderMode())
                            {
                                rtnData.DataValue = "TRUE";
                                rtnData.TestValue = "TRUE";
                            }
                            break;
                        case "carteditmode":
                            currentcart = new CartData(PortalSettings.Current.PortalId);
                            var editmode = currentcart.GetInfo().GetXmlProperty("genxml/carteditmode");
                            if (editmode == testValue)
                            {
                                rtnData.DataValue = "TRUE";
                                rtnData.TestValue = "TRUE";
                            }
                            break;
                        case "iscartempty":
                            currentcart = new CartData(PortalSettings.Current.PortalId);
                            var l = currentcart.GetCartItemList();
                            if (!l.Any())
                            {
                                rtnData.DataValue = "TRUE";
                                rtnData.TestValue = "TRUE";
                            }
                            break;
                        case "hasshippingproviders":
                            var pluginData = new PluginData(PortalSettings.Current.PortalId);
                            var provList = pluginData.GetShippingProviders();
                            if (provList.Count > 1)
                            {
                                rtnData.DataValue = "TRUE";
                                rtnData.TestValue = "TRUE";
                            }
                            break;
                        case "profile":
                            var userInfo = UserController.GetCurrentUserInfo();
                            if (userInfo.UserID >= 0) rtnData.DataValue = userInfo.Profile.GetPropertyValue(settingkey);
                            break;
                        case "static":
                            break;
                        default:
                            rtnData.DataValue = null;
                            break;
                    }
                }
            }
            catch (Exception)
            {
                lc.Text = "";
            }
            return rtnData;
        }
Пример #5
0
        public void ProcessRequest(HttpContext context)
        {
            #region "Initialize"

            var strOut = "";

            var paramCmd = Utils.RequestQueryStringParam(context, "cmd");
            var itemId = Utils.RequestQueryStringParam(context, "itemid");
            var ctlType = Utils.RequestQueryStringParam(context, "ctltype");
            var idXref = Utils.RequestQueryStringParam(context, "idxref");
            var xpathpdf = Utils.RequestQueryStringParam(context, "pdf");
            var xpathref = Utils.RequestQueryStringParam(context, "pdfref");
            var lang = Utils.RequestQueryStringParam(context, "lang");
            var language = Utils.RequestQueryStringParam(context, "language");
            var moduleId = Utils.RequestQueryStringParam(context, "mid");
            var moduleKey = Utils.RequestQueryStringParam(context, "mkey");
            var parentid = Utils.RequestQueryStringParam(context, "parentid");
            var entryid = Utils.RequestQueryStringParam(context, "entryid");
            var entryxid = Utils.RequestQueryStringParam(context, "entryxid");
            var catid = Utils.RequestQueryStringParam(context, "catid");
            var catxid = Utils.RequestQueryStringParam(context, "catxid");
            var templatePrefix = Utils.RequestQueryStringParam(context, "tprefix");
            var value = Utils.RequestQueryStringParam(context, "value");
            var itemListName = Utils.RequestQueryStringParam(context, "listname");
            if (itemListName == "") itemListName = "ItemList";
            if (itemListName == "*") itemListName = "ItemList";

            #region "setup language"

            // because we are using a webservice the system current thread culture might not be set correctly,
            SetContextLangauge(context);

            #endregion

            #endregion

            try
            {

                #region "Do processing of command"

                var intModuleId = 0;
                if (Utils.IsNumeric(moduleId)) intModuleId = Convert.ToInt32(moduleId);

                var objCtrl = new NBrightBuyController();

                var uInfo = new UserDataInfo(UserController.Instance.GetCurrentUserInfo().PortalID, intModuleId, objCtrl,
                    ctlType);
                strOut = "ERROR!! - No Security rights for current user!";
                switch (paramCmd)
                {
                    case "test":
                        strOut = "<root>" + UserController.Instance.GetCurrentUserInfo().Username + "</root>";
                        break;
                    case "setdata":
                        break;
                    case "deldata":
                        break;
                    //case "setcategoryadminform":
                    //    if (NBrightBuyUtils.CheckRights()) strOut = SetCategoryForm(context);
                    //    break;
                    case "getdata":
                        strOut = GetReturnData(context);
                        break;
                    case "additemlist":
                        if (Utils.IsNumeric(itemId))
                        {
                            var cw = new ItemListData(itemListName);
                            cw.Add(itemId);
                            strOut = cw.ItemList;
                        }
                        break;
                    case "removeitemlist":
                        if (Utils.IsNumeric(itemId))
                        {
                            var cw1 = new ItemListData(itemListName);
                            cw1.Remove(itemId);
                            strOut = cw1.ItemList;
                        }
                        break;
                    case "deleteitemlist":
                        var cw2 = new ItemListData(itemListName);
                        cw2.Delete();
                        strOut = "deleted";
                        break;
                    case "getproductselectlist":
                        strOut = GetProductList(context);
                        break;
                    case "getproductlist":
                        strOut = GetProductList(context);
                        break;
                    case "getcategoryproductlist":
                        strOut = GetCategoryProductList(context);
                        break;
                    case "setdefaultcategory":
                        if (NBrightBuyUtils.CheckRights()) strOut = SetDefaultCategory(context);
                        break;
                    case "deletecatxref":
                        if (NBrightBuyUtils.CheckRights()) strOut = DeleteCatXref(context);
                        break;
                    case "selectcatxref":
                        if (NBrightBuyUtils.CheckRights()) strOut = SelectCatXref(context);
                        break;
                    case "deleteallcatxref":
                        if (NBrightBuyUtils.CheckRights()) strOut = DeleteAllCatXref(context);
                        break;
                    case "copyallcatxref":
                        if (NBrightBuyUtils.CheckRights()) strOut = CopyAllCatXref(context);
                        break;
                    case "moveallcatxref":
                        if (NBrightBuyUtils.CheckRights()) strOut = CopyAllCatXref(context, true);
                        break;
                    case "editproduct":
                        if (NBrightBuyUtils.CheckRights()) strOut = GetProductGeneralData(context);
                        break;
                    case "productdescription":
                        if (NBrightBuyUtils.CheckRights()) strOut = GetProductDescription(context);
                        break;
                    case "productmodels":
                        if (NBrightBuyUtils.CheckRights()) strOut = GetProductModels(context);
                        break;
                    case "productoptions":
                        if (NBrightBuyUtils.CheckRights()) strOut = GetProductOptions(context);
                        break;
                    case "productoptionvalues":
                        if (NBrightBuyUtils.CheckRights()) strOut = GetProductOptionValues(context);
                        break;
                    case "productimages":
                        if (NBrightBuyUtils.CheckRights()) strOut = GetProductImages(context);
                        break;
                    case "productdocs":
                        if (NBrightBuyUtils.CheckRights()) strOut = GetProductDocs(context);
                        break;
                    case "productrelatedproducts":
                        if (NBrightBuyUtils.CheckRights()) strOut = GetProductModels(context);
                        break;
                    case "productcategories":
                        if (NBrightBuyUtils.CheckRights()) strOut = GetProductCategories(context);
                        break;
                    case "productisincategory":
                        if (NBrightBuyUtils.CheckRights()) strOut = ProductIsInCategory(context).ToString();
                        break;
                    case "productgroupcategories":
                        if (NBrightBuyUtils.CheckRights()) strOut = GetProductGroupCategories(context);
                        break;
                    case "productrelated":
                        if (NBrightBuyUtils.CheckRights()) strOut = GetProductRelated(context);
                        break;
                    case "productclients":
                        if (NBrightBuyUtils.CheckRights()) strOut = GetProductClients(context);
                        break;
                    case "getclientselectlist":
                        if (NBrightBuyUtils.CheckRights()) strOut = GetClientSelectList(context);
                        break;
                    case "addproductmodels":
                        if (NBrightBuyUtils.CheckRights()) strOut = AddProductModels(context);
                        break;
                    case "addproductoptions":
                        if (NBrightBuyUtils.CheckRights()) strOut = AddProductOptions(context);
                        break;
                    case "addproductoptionvalues":
                        if (NBrightBuyUtils.CheckRights()) strOut = AddProductOptionValues(context);
                        break;
                    case "addproductcategory":
                        if (NBrightBuyUtils.CheckRights()) strOut = AddProductCategory(context);
                        break;
                    case "addproductgroupcategory":
                        if (NBrightBuyUtils.CheckRights()) strOut = AddProductGroupCategory(context);
                        break;
                    case "removeproductcategory":
                        if (NBrightBuyUtils.CheckRights()) strOut = RemoveProductCategory(context);
                        break;
                    case "removeproductgroupcategory":
                        if (NBrightBuyUtils.CheckRights()) strOut = RemoveProductGroupCategory(context);
                        break;
                    case "populatecategorylist":
                        if (NBrightBuyUtils.CheckRights()) strOut = GetGroupCategoryListBox(context);
                        break;
                    case "addrelatedproduct":
                        if (NBrightBuyUtils.CheckRights()) strOut = AddRelatedProduct(context);
                        break;
                    case "removerelatedproduct":
                        if (NBrightBuyUtils.CheckRights()) strOut = RemoveRelatedProduct(context);
                        break;
                    case "addproductclient":
                        if (NBrightBuyUtils.CheckRights()) strOut = AddProductClient(context);
                        break;
                    case "removeproductclient":
                        if (NBrightBuyUtils.CheckRights()) strOut = RemoveProductClient(context);
                        break;
                    case "clientdiscountcodes":
                        if (NBrightBuyUtils.CheckRights()) strOut = GetClientDiscountCodes(context);
                        break;
                    case "addclientdiscountcode":
                        if (NBrightBuyUtils.CheckRights()) strOut = AddClientDiscountCodes(context);
                        break;
                    case "clientvouchercodes":
                        if (NBrightBuyUtils.CheckRights()) strOut = GetClientVoucherCodes(context);
                        break;
                    case "addclientvouchercode":
                        if (NBrightBuyUtils.CheckRights()) strOut = AddClientVoucherCodes(context);
                        break;
                    case "moveproductadmin":
                        if (NBrightBuyUtils.CheckRights()) strOut = MoveProductAdmin(context);
                        break;
                    case "fileupload":
                        if (NBrightBuyUtils.CheckRights() && Utils.IsNumeric(itemId))
                        {
                            strOut = FileUpload(context);
                        }
                        break;
                    case "fileclientupload":
                        if (StoreSettings.Current.GetBool("allowupload"))
                        {
                            strOut = FileUpload(context, itemId);
                        }
                        break;
                    case "updateproductimages":
                        if (NBrightBuyUtils.CheckRights())
                        {
                            UpdateProductImages(context);
                            strOut = GetProductImages(context);
                        }
                        break;
                    case "updateproductdocs":
                        if (NBrightBuyUtils.CheckRights())
                        {
                            UpdateProductDocs(context);
                            strOut = GetProductDocs(context);
                        }
                        break;
                    case "addtobasket":
                        strOut = AddToBasket(context);
                        break;
                    case "addalltobasket":
                        strOut = AddAllToBasket(context);
                        break;
                    case "addcookietobasket":
                        break;
                    case "docdownload":
                        var fname = Utils.RequestQueryStringParam(context, "filename");
                        strOut = fname; // return this is error.
                        var downloadname = Utils.RequestQueryStringParam(context, "downloadname");
                        var fpath = HttpContext.Current.Server.MapPath(fname);
                        if (downloadname == "") downloadname = Path.GetFileName(fname);
                        Utils.ForceDocDownload(fpath, downloadname, context.Response);
                        break;
                    case "printproduct":
                        break;
                    case "removefromcart":
                        RemoveFromCart(context);
                        strOut = "removefromcart";
                        break;
                    case "recalculatecart":
                        RecalculateCart(context);
                        strOut = "recalculatecart";
                        break;
                    case "recalculatesummary":
                        RecalculateSummary(context);
                        strOut = "recalculatecart";
                        break;
                    case "redirecttopayment":
                        strOut = RedirectToPayment(context);
                        break;
                    case "updatebilladdress":
                        strOut = UpdateCartAddress(context, "bill");
                        break;
                    case "updateshipaddress":
                        strOut = UpdateCartAddress(context, "ship");
                        break;
                    case "updateshipoption":
                        strOut = UpdateCartAddress(context, "shipoption");
                        break;
                    case "rendercart":
                        strOut = RenderCart(context);
                        break;
                    case "renderpostdata":
                        strOut = RenderPostData(context);
                        break;
                    case "clearcart":
                        var currentcart = new CartData(PortalSettings.Current.PortalId);
                        currentcart.DeleteCart();
                        strOut = "clearcart";
                        break;
                    case "shippingprovidertemplate":
                        strOut = GetShippingProviderTemplates(context);
                        break;
                    case "getsettings":
                        strOut = GetSettings(context);
                        break;
                    case "savesettings":
                        if (NBrightBuyUtils.CheckRights()) strOut = SaveSettings(context);
                        break;
                    case "updateprofile":
                        strOut = UpdateProfile(context);
                        break;
                    case "dosearch":
                        strOut = DoSearch(context);
                        break;
                    case "resetsearch":
                        strOut = ResetSearch(context);
                        break;
                    case "orderby":
                        strOut = DoOrderBy(context);
                        break;
                    case "orderadmin_getlist":
                        strOut = OrderAdminList(context);
                        break;
                    case "orderadmin_getdetail":
                        strOut = OrderAdminDetail(context);
                        break;
                    case "orderadmin_reorder":
                        strOut = OrderAdminReOrder(context);
                        break;
                    case "orderadmin_edit":
                        strOut = OrderAdminEdit(context);
                        break;
                    case "orderadmin_save":
                        strOut = OrderAdminSave(context);
                        break;
                    case "orderadmin_removeinvoice":
                        strOut = OrderAdminRemoveInvoice(context);
                        break;
                    case "orderadmin_sendemail":
                        strOut = OrderAdminEmail(context);
                        break;
                }

                #endregion

            }
            catch (Exception ex)
            {
                strOut = ex.ToString();
                Exceptions.LogException(ex);
            }

            #region "return results"

            //send back xml as plain text
            context.Response.Clear();
            context.Response.ContentType = "text/plain";
            context.Response.Write(strOut);
            context.Response.End();

            #endregion
        }