Esempio n. 1
0
    public string GetUserFavorites(string userId, string ctrl)
    {
        JavaScriptSerializer js = new JavaScriptSerializer();

        string crlHash = Generic.GetHash(Generic.GetWebConfigValue("WebServiceKey"));

        //if (ctrl != crlHash) return js.Serialize("");

        db_config_users dcu = null;
        db_config_page dcp = null;

        try
        {
            // first validation to guarantee that user is greater than zero
            int auxUserId = Convert.ToInt32(userId);
            if (auxUserId < 0) return js.Serialize("");

            dcu = new db_config_users(auxUserId);
            dcu.Open();

            dcp = new db_config_page();
            dcp.Open();

            object userOptions = dcu.Get(auxUserId).UserOptions;

            if (userOptions == null) return js.Serialize("");

            OptionItems oi = new OptionItems((string)userOptions);

            List<Dictionary<string, string>> favoriteList = new List<Dictionary<string, string>>();

            foreach (string favoritePage in oi.GetList("favorites"))
            {
                try
                {
                    string title = dcp.Get(favoritePage).Title;

                    favoriteList.Add(new Dictionary<string, string>()
                    {
                        {"Name", favoritePage},
                        {"Title", title}
                    });
                }
                catch {}
            }

            return js.Serialize(favoriteList);
        }
        catch (Exception ex)
        {
            loging.Error("FrontOffice User Webservice", "Get Favorites ", ex.Message, _logRecord);
        }
        finally
        {
            if (dcu != null) dcu.Close();

            try { if(dcp != null) dcp.Close(); } catch {} // needed to open a new connection (forgot to implement a page method that accepts new  )
        }

        return js.Serialize("");
    }
Esempio n. 2
0
    public string ListAllUserPages(string userId, string ctrl)
    {
        JavaScriptSerializer js = new JavaScriptSerializer();

        string crlHash = Generic.GetHash(Generic.GetWebConfigValue("WebServiceKey"));

        //if (ctrl != crlHash) return js.Serialize("");

        db_config_page dcp = null;

        try
        {
            // first validation to guarantee that user is greater than zero
            int auxUserId = Convert.ToInt32(userId);
            if (auxUserId < 0) return js.Serialize("");

            dcp = new db_config_page();
            dcp.Open();

            db_config_users dcu = new db_config_users(dcp.Db, auxUserId);
            dcu.Open();

            // list user pages
            List<int> userPagesId = (from up in dcu.GetPages() select up.ID).ToList();

            if (userPagesId.Count > 0)
                dcp.SelectAuthenticatedObjectsFromDb(userPagesId); // list public pages and pages that user can have
            else
                dcp.SelectPublicObjectsFromDb();

            // --------------------------------
            // list pages that user dont have
            List<JsonUserPages> userPages = (from ap in dcp.AllPages
                                            select new JsonUserPages {Id = ap.ID, Title = ap.Title, Name = ap.Name}).ToList();

            return js.Serialize(userPages);
        }
        catch (Exception ex)
        {
            loging.Error("FrontOffice User Webservice", "List All User Pages ", ex.Message, _logRecord);
        }
        finally
        {
            if (dcp != null) dcp.Close();
        }

        return js.Serialize("");
    }
Esempio n. 3
0
    public string GetPageType(string pageId, string ctrl)
    {
        string crlHash = Generic.GetHash(Generic.GetWebConfigValue("WebServiceKey"));

        if (ctrl != crlHash) return string.Empty;

        db_config_page dcp = null;

        try
        {
            int id = Convert.ToInt32(pageId);

            dcp = new db_config_page(id, false);
            dcp.Open();

            Page p = dcp.Get(id);

            OptionItems oi  = new OptionItems(p.Options);

            return oi.GetSingle("page_type").ToLower() == "free_draw"
                                                            ? "free_draw"
                                                            : "table";
        }
        catch (Exception ex)
        {
            return ex.Message;
        }
        finally
        {
            if (dcp != null)
                dcp.Close();
        }
    }
Esempio n. 4
0
    public string GetUserDefaultPage(string userId, string ctrl)
    {
        JavaScriptSerializer js = new JavaScriptSerializer();

        string crlHash = Generic.GetHash(Generic.GetWebConfigValue("WebServiceKey"));

        //if (ctrl != crlHash) return js.Serialize("");

        db_config_users dcu = null; // user
        db_config_page dcp = null;  // page

        try
        {
            // first validation to guarantee that user is greater than zero
            int auxUserId = Convert.ToInt32(userId);
            if (auxUserId < 0) return js.Serialize("");

            dcu = new db_config_users(auxUserId);
            dcu.Open();

            object userOptions = dcu.Get(auxUserId).UserOptions;

            // if user does not exist leaves
            if (userOptions == null) return string.Empty;

            OptionItems oi = new OptionItems((string)userOptions);

            string pageName = oi.GetSingle("default_frontoffice_page");

            // if no default page leave
            if (pageName == string.Empty) return string.Empty;

            dcp = new db_config_page(pageName);
            dcp.Open();

            string pageTitle = dcp.Get(pageName).Title;

            Dictionary<string, string> defPage = new Dictionary<string, string>() {{"Name", pageName}, {"Title", pageTitle}};

            return js.Serialize(defPage);
        }
        catch (Exception ex)
        {
            loging.Error("FrontOffice User Webservice", "Get Default Page ", ex.Message, _logRecord);
        }
        finally
        {
            if (dcu != null) dcu.Close();

            try { if(dcp != null) dcp.Close(); } catch { }
        }

        return string.Empty;
    }
Esempio n. 5
0
    public string DeletePage(string pageId, string ctrl)
    {
        string crlHash = Generic.GetHash(Generic.GetWebConfigValue("WebServiceKey"));

        if (ctrl != crlHash) return string.Empty;

        db_config_page dcp = null;

        try
        {
            dcp = new db_config_page(Convert.ToInt32(pageId), false);
            dcp.Open();
            dcp.Delete(Convert.ToInt32(pageId));
            return "Operation Done";
        }
        catch (Exception ex)
        {
            return ex.Message;
        }
        finally
        {
            if (dcp != null) dcp.Close();
        }
    }
Esempio n. 6
0
    public string GetPageTitle(string pageId, string ctrl)
    {
        string crlHash = Generic.GetHash(Generic.GetWebConfigValue("WebServiceKey"));

        if (ctrl != crlHash) return string.Empty;

        db_config_page dcp = null;

        try
        {
            int id = Convert.ToInt32(pageId);

            dcp = new db_config_page(id, false);
            dcp.Open();

            Page p = dcp.Get(id);

            return p.Title;
        }
        catch (Exception ex)
        {
            return ex.Message;
        }
        finally
        {
            if (dcp != null)
                dcp.Close();
        }
    }
Esempio n. 7
0
    public string ListAvailablePagesToUser(string userId, string ctrl)
    {
        JavaScriptSerializer js = new JavaScriptSerializer();

        string crlHash = Generic.GetHash(Generic.GetWebConfigValue("WebServiceKey"));

        if (ctrl != crlHash) return js.Serialize("");

        db_config_page dcp = null;

        try
        {
            // first validation to guarantee that user is greater than zero
            int auxUserId = Convert.ToInt32(userId);
            if (auxUserId < 0) return js.Serialize("");

            dcp = new db_config_page();
            dcp.Open();

            db_config_users dcu = new db_config_users(dcp.Db, auxUserId);
            dcu.Open();

            // list user pages
            List<int> userPagesId = (from up in dcu.GetPages() select up.ID).ToList();

            // --------------------------------
            // list pages that user dont have
            List<JsonUserPages> noAvailableUserPages = userPagesId.Count == 0 ? (from ap in dcp.AllPages
                                                                                 select new JsonUserPages { Id = ap.ID, Title = ap.Title, Name = ap.Name }).ToList()
                                                                            : (from nup in dcp.AllPages
                                                                                where !userPagesId.Contains(nup.ID)
                                                                                select new JsonUserPages { Id = nup.ID, Title = nup.Title, Name = nup.Name }).ToList();

            return js.Serialize(noAvailableUserPages);
        }
        catch (Exception ex)
        {
            loging.Error("BackOffice User Webservice", "List All Pages ", ex.Message, _logRecord);
        }
        finally
        {
            if (dcp != null) dcp.Close();
        }

        return js.Serialize("");
    }
Esempio n. 8
0
    public string ListFrames(string pageId, string ctrl)
    {
        JavaScriptSerializer js = new JavaScriptSerializer();

        string crlHash = Generic.GetHash(Generic.GetWebConfigValue("WebServiceKey"));

        if (ctrl != crlHash) return string.Empty;

        db_config_page dcp = null;

        try
        {
            int id = Convert.ToInt32(pageId);

            dcp = new db_config_page(id, true);
            dcp.Open();

            List<Frame> frames = dcp.GetAllFrames(id);

            List<Dictionary<string, object>> rows = frames.Select(f => new Dictionary<string, object>
                                                                    {
                                                                        {"ID", f.ID},
                                                                        {"Title", f.Title},
                                                                        {"FrameType", f.FrameType},
                                                                        {"X", f.X},
                                                                        {"Y", f.Y},
                                                                        {"Width", f.Width},
                                                                        {"Height", f.Height},
                                                                        {"IsActive", f.IsActive},
                                                                        {"Columnspan", new OptionItems(f.Options).GetSingle("columnspan")},
                                                                        {"Rowspan", new OptionItems(f.Options).GetSingle("rowspan")},
                                                                    }).ToList();

            return js.Serialize(rows);
        }
        catch (Exception ex)
        {
            loging.Error("BackOffice Frames Webservice", "List Frames", ex.Message, _logRecord);
        }
        finally
        {
            if (dcp != null) dcp.Close();
        }

        return js.Serialize("");
    }
Esempio n. 9
0
    /************************ Selector Box ************************/
    /// <summary>
    ///  Build page selector if ID  is negative then it will select first item
    /// </summary>
    private void BuildPageSelector(int currentPageId)
    {
        db_config_page dcp = null;

        // Clear all items
        f_pageid.Items.Clear();

        try
        {
            dcp = new db_config_page();
            dcp.Open();

            List<Page> allPages = dcp.AllPages.OrderBy(x=>x.Title).ToList();

            for (int i = 0; i < allPages.Count; i++)
            {
                f_pageid.Items.Add(new ListItem(
                                                allPages[i].Title,
                                                allPages[i].ID.ToString(CultureInfo.InvariantCulture)
                                                ));

                // Get the page position then set the selector index
                if (allPages[i].ID == currentPageId)
                    f_pageid.SelectedIndex = i;
            }
        }
        catch (Exception ex)
        {
            throw new Exception("error: building page list " + ex.Message);
        }
        finally
        {
            if (dcp != null)
                dcp.Close();
        }
    }
Esempio n. 10
0
        /// <summary>
        /// Transforms the list of hyperlink into a list 
        /// of cases that will be used in javascript
        /// </summary>
        /// <param name="listHyperlinks"></param>
        private void BuildFilters(List<string> listHyperlinks, int thisPageId)
        {
            foreach (string link in listHyperlinks)
            {
                string[] lk = link.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                if (lk.Length != 4) continue;

                string columnName = lk[0].Trim();
                string pageName = lk[1].Trim();
                string masterFilterName = lk[2].Trim();
                string filterCondition = lk[3].Trim();

                db_config_page dcp = null;

                try
                {
                    _columnNames.Add(columnName);

                    /*
                        case 'sin_req':

                            pageIdHash = '123123123123';
                            filterTitleHash = '1asfa2324q23';
                            isCurrentPage = false

                            filter = "sin_req = 'value'".replace('value', value.toString());
                    */

                    dcp = new db_config_page(pageName);
                    dcp.Open();

                    DbConfig.Page p = dcp.Get(pageName);

                    int pageId = p.ID;

                    string pageHashId           = Generic.GetHash(pageId.ToString(CultureInfo.InvariantCulture));
                    string masterFilterNameHash = Generic.GetHash(masterFilterName);

                    string js = string.Empty;
                    js += "case '" + columnName + "': \n";
                    js += " pageName = '" + pageName + "'; \n";
                    js += " pageIdHash = '" + pageHashId + "'; \n";
                    js += " filterTitle = '" + masterFilterName + "'; \n";
                    js += " filterTitleHash = '" + masterFilterNameHash + "'; \n";
                    js += " isCurrentPage = " + (pageId == thisPageId ? "true" : "false") + "; \n";
                    js += " \n";
                    js += " filter = \"" + filterCondition + "\".replace('value', value.toString()); \n";

                    _jsSwith.Add(js);
                }
                finally
                {
                    if (dcp != null)
                        dcp.Close();
                }
            }
        }
Esempio n. 11
0
    /// <summary>
    /// Generate header bar
    /// </summary>
    private void FillMenuBar(OptionItems foOptions)
    {
        string username = "******";

        try
        {
            headerContainer.Controls.Clear();

            UserLoginData user = (UserLoginData)db_config_sessions.GetUserAuthentication();
            OptionItems userOi = null;

            db_config_master_page dcmp = new db_config_master_page(); dcmp.Open();

            List<string> userFavorites = new List<string>();

            // user not autenticated show just public pages
            if (user == null)
            {
                dcmp.SelectPublicObjectsFromDb();
            }
            else
            {
                // user autenticated show public pages and user pages
                dcmp.SelectAuthenticatedObjectsFromDb(user.UserPages);
                userOi = new OptionItems(user.User.UserOptions);

                userFavorites = userOi.GetList("favorites");

                // prepare username to be used in error exception.
                username = user.User.Name;
            }

            // set url to use when the page start
            SelectDefaultPage(foOptions.GetSingle("default_page"), user != null
                                                                        ? userOi.GetSingle("default_frontoffice_page")
                                                                        : "");

            MenuBar mb = new MenuBar();
            mb.AddHeader("Home", "frontoffice.aspx");

            // just show data if is not refresh
            if (!IsPostBack)
            {
                mb.AddHeader("Site pages", ""); // site pages
                int headerId = mb.GetHeaderPosition("Site pages");

                db_config_page dcp;

                foreach (DbConfig.MasterPage item in dcmp.AllMasterPages)
                {
                    // just show pages that admin dont want to hide from you :)
                    List<DbConfig.Page> visiblePages = (from p in dcmp.GetAllPages(item.ID)
                                                        where (new OptionItems(p.Options).GetSingle("hidden_from_frontoffice").Equals("true")) == false
                                                        select p).ToList();

                    dcp = new db_config_page(dcmp.Db, visiblePages, item.ID);

                    if (user == null)
                        dcp.SelectPublicObjectsFromDb();
                    else
                        dcp.SelectAuthenticatedObjectsFromDb(user.UserPages);

                    // will just add master page if it has visible pages to show,
                    // if the master page does not have pages will not get here.
                    if (dcp.AllPages.Count > 0)
                    {
                        // add master page to menu
                        mb.AddMenuItem(headerId, item.Title, "");
                        int menuItemId = mb.GetMenuPosition(headerId, item.Title);

                        // add pages to sub menus
                        foreach (DbConfig.Page subItem in dcp.AllPages)
                            mb.AddSubMenuItem(headerId, menuItemId, subItem.Title, "page.aspx?nm=" + subItem.Name);
                    }

                    dcp.Close();
                }

                if (userFavorites.Count > 0) // favorites
                {
                    mb.AddHeader("Favorites", "");
                    int favItemId = mb.GetHeaderPosition("Favorites");

                    dcp = new db_config_page(dcmp.Db, new List<DbConfig.Page>(), -1); dcp.Refresh();

                    foreach (string favpage in userFavorites)
                    {
                        if (!dcp.PageExists(favpage)) continue;

                        DbConfig.Page p = dcp.Get(favpage);
                        mb.AddMenuItem(favItemId, p.Title, "page.aspx?nm=" + p.Name);
                    }

                    dcp.Close();
                }
            }

            dcmp.Close();

            headerContainer.Controls.Add(mb.Get());
            Generic.JavaScriptInjector("js", mb.GetLoginJavascript());
        }
        catch (Exception ex)
        {
            throw new Exception("error: fill menu bar for user " + username + " - " + ex.Message + " ...");
        }
    }
Esempio n. 12
0
    private static void SavePage(int id, int masterPageID, string name, string title, string xmlFolder, string xmlUrl, string options)
    {
        try
        {

            db_config_page dcp = new db_config_page();
            dcp.Open();

            Page p = id >= 0
                        ? dcp.Get(id)
                        : new Page();

            p.IDMasterPage = masterPageID;
            p.Name = name;
            p.Title = title;
            p.XMLFolderPath = xmlFolder;
            p.XMLURL = xmlUrl;
            p.Options = options;

            if (id >= 0)
                dcp.Commit();
            else
                dcp.Add(p);

            dcp.Close();
        }
        catch (Exception ex)
        {
            throw new Exception("error: Save Page: " + ex.Message);
        }
    }
Esempio n. 13
0
    private void LoadPage(string id)
    {
        try
        {
            int pId = Convert.ToInt32(id);

            db_config_page dcp = new db_config_page(pId, false);
            dcp.Open();

            DbConfig.Page p = dcp.Get(pId);

            p_id.Value = p.ID.ToString(CultureInfo.InvariantCulture);
            p_name.Value = p.Name;
            p_title.Value = p.Title;
            p_xml_folder.Value = p.XMLFolderPath;
            p_xml_url.Value = p.XMLURL;
            p_options.Value = p.Options;

            BuildPageSelector(p.IDMasterPage);
            SetPageTitle(p.Title);

            dcp.Close();
        }
        catch (Exception ex)
        {
            Generic.JavaScriptInjector("alert('" + ex.Message + "');");
        }
    }