Example #1
0
        /// <summary>
        /// Retrieves the HTML of a given role.
        /// </summary>
        /// <param name="idRole">The given idRole.</param>
        /// <returns>An HTML including the formatted role list and the currently selected permissions for the role.</returns>
        public static string GetRoleInfo(int idRole)
        {
            string retval    = "";
            string className = "";
            Dictionary <string, bool> roleModules = Modules.GetRoleModules(idRole);

            //Table Header
            retval  = "<table align='center' width='70%'>";
            retval += "<tr><th width='70%'>" + Text.Module + "<th>" + Text.GrantPermission + "</th><th>" + Text.RevokePermission + "</th></tr>";

            List <Module> moduleList = new List <Module>();

            moduleList = Modules.GetModuleTree(moduleList, 0, 0);

            foreach (Module tempModule in moduleList)
            {
                string elementName = tempModule.IdModule.ToString();
                bool   isGranted   = Common.GetBDNum("GrantPermission", "SELECT GrantPermission FROM RoleModules WHERE IdRole = " + idRole.ToString() + " AND IdModule = " + tempModule.IdModule.ToString()) == 1;
                bool   isRevoked   = Common.GetBDNum("RevokePermission", "SELECT RevokePermission FROM RoleModules WHERE IdRole = " + idRole.ToString() + " AND IdModule = " + tempModule.IdModule.ToString()) == 1;
                className = Common.SwitchClass(className);
                retval   += "<tr class='" + className + "'>";
                retval   += "<td>" + DepthSpacing(tempModule.Depth) + Modules.FriendlyModuleName(tempModule.Name) + "</td>";
                retval   += "<td align='center'>" + DrawInput.InputCheckbox("grt_" + elementName, "1", isGranted, "", "", "", "") + "</td>";
                retval   += "<td align='center'>" + DrawInput.InputCheckbox("rvk_" + elementName, "1", isRevoked, "", "", "", "") + "</td>";
                retval   += "</tr>";
                retval   += "<script language='JavaScript'>roles[roles.length] = new Role(" + tempModule.IdModule.ToString() + ", " + tempModule.IdModuleParent.ToString() + ");</script>";
            }

            //Table Footer
            retval += "</table>";

            return(retval);
        }
Example #2
0
        /// <summary>
        /// Retrieves the question list as an HTML string.
        /// </summary>
        /// <param name="modules">The current user modules.</param>
        /// <param name="currentPage">The current page used.</param>
        /// <param name="filter">An SQL filter.</param>
        /// <returns>The HTML string with the question list.</returns>
        public static string GetQuestionList(Dictionary <string, bool> modules, int currentPage, string filter, bool forSelection)
        {
            string retval    = "";
            string className = "";
            int    total     = 0;
            string sql       = "SELECT COUNT(IdQuestion) AS HowMany FROM ExamQuestion";

            sql = Common.StrAdd(sql, " WHERE ", filter);
            double recordsPerPage = Config.RecordsPerPage();
            double totalRecords   = Common.GetBDNum("HowMany", sql);
            int    totalPages     = Convert.ToInt32(Math.Ceiling(totalRecords / recordsPerPage));

            if (currentPage > totalPages)
            {
                currentPage = totalPages;
            }
            if (currentPage == 0)
            {
                currentPage = 1;
            }

            retval  = "<table width='100%'>";
            retval += "<tr>";

            //Table Header
            if (forSelection)
            {
                retval += "<th>&nbsp;</th>";
            }
            retval += "<th>" + Text.Identifier + "</th><th>" + Text.Question + "</th>";
            if (!forSelection)
            {
                retval += "<th>" + Text.Theme + "</th><th>" + Text.Status + "</th>";
            }
            retval += "<th>" + Text.DifficultyIndex + "</th></tr>";

            sql  = "SELECT IdQuestion, Question FROM (SELECT IdQuestion, Question, ROW_NUMBER() OVER (ORDER BY IdQuestion) AS RowNum FROM ExamQuestion";
            sql  = Common.StrAdd(sql, " WHERE ", filter);
            sql += ") AS U WHERE U.RowNum BETWEEN ((" + currentPage + " - 1) * " + recordsPerPage + ") + 1 AND " + recordsPerPage + " * (" + currentPage + ")";
            string[] idQuestionList = Common.CSVToArray(Common.GetBDList("IdQuestion", sql, false));
            foreach (string idQuestion in idQuestionList)
            {
                try
                {
                    ExamQuestion question  = new ExamQuestion(Convert.ToInt32(idQuestion));
                    ExamTheme    theme     = new ExamTheme(question.IdTheme);
                    string       themeName = "";
                    if (String.IsNullOrEmpty(theme.Theme))
                    {
                        themeName = Text.None;
                    }
                    else
                    {
                        themeName = theme.Theme;
                    }
                    className = Common.SwitchClass(className);
                    string questionStatus = Text.Inactive;
                    if (question.Status == ExamQuestionStatus.ACTIVE)
                    {
                        questionStatus = Text.Active;
                    }
                    retval += "<tr class='" + className + "' id='q_" + idQuestion + "' onClick='showQuestion(" + idQuestion + ");'>";
                    if (forSelection)
                    {
                        retval += "<td width='5%' align='center'>" + DrawInput.InputCheckbox("q_chk_" + idQuestion, "", false, "questionChk", "", "", "") + "</td>";
                    }
                    retval += "<td width='5%' align='center'>" + question.IdQuestion + "</td>";
                    retval += "<td width='60%'>" + Common.BBCodeToHTML(question.Question) + "</td>";
                    if (!forSelection)
                    {
                        retval += "<td width='20%' align='center'>" + themeName + "</td>";
                        retval += "<td width='10%' align='center'>" + questionStatus + "</td>";
                    }
                    retval += "<td width='5%' align='center'>" + String.Format("{0:0.00}", question.DifficultyIndex("")) + "</td>";
                    retval += "</tr>";
                    total++;
                }
                catch (Exception ex) { }
            }

            retval += "</table>";

            //footer / pagination
            retval += "<div align='center' class='pagination'>";
            retval += "<div align='left' style='width: 50%; display: inline-block;'>" + Common.StrLang(Text.ShowingXofY, total.ToString() + "," + totalRecords.ToString()) + " " + Text.Question_s + "</div>";
            retval += "<div align='right' style='width: 50%; display: inline-block;'>" + Common.StrLang(Text.PageXofY, currentPage.ToString() + "," + totalPages.ToString());
            retval += "&nbsp;<a href='#' class='dark' onClick='firstPage();'>&lt;&lt;</a>";
            retval += "&nbsp;<a href='#' class='dark' onClick='prevPage();'>&lt;</a>";
            retval += "&nbsp;<a href='#' class='dark' onClick='nextPage();'>&gt;</a>";
            retval += "&nbsp;<a href='#' class='dark' onClick='lastPage(" + totalPages + ");'>&gt;&gt;</a>";
            retval += "</div>";
            retval += "</div>";

            return(retval);
        }
Example #3
0
        /// <summary>
        /// Builds the HTML code for a given field.
        /// </summary>
        /// <returns>The HTML string of the field.</returns>
        public string GetFieldHTML()
        {
            string retval             = "";
            string fieldId            = "data_" + IdData.ToString();
            string validationFunction = "";

            switch (Kind)
            {
            case Data.SIMPLE_TEXT:
                retval = DrawInput.InputTextField(fieldId, Value, "", "", "", "", "");
                break;

            case Data.YES_NO:
                retval = DrawInput.InputSelect(fieldId, Value, Common.CSVToArray("," + Text.Yes + "," + Text.No), "", "", "", "");
                break;

            case Data.OPTIONS:
                retval = DrawInput.InputSelect(fieldId, Value, Common.CSVToArray('|', "|" + AuxValues), "", "", "", "");
                break;

            case Data.INTEGER:
                NumberJSON numberJSON = JsonConvert.DeserializeObject <NumberJSON>(AuxValues);
                if ((numberJSON.from == numberJSON.to) && (numberJSON.to == 0))
                {
                    validationFunction   = "validateInt($(this), event);";
                    numberJSON.maxLength = "10";
                }
                else
                {
                    validationFunction = "validateInt($(this), event, " + numberJSON.from + ", " + numberJSON.to + ");";
                }
                retval = DrawInput.InputTextField(fieldId, Value, numberJSON.maxLength, "", validationFunction, "width: 50px;", "title=\"" + Common.StrLang(Text.EnterValueBetweenXandY, numberJSON.from + "," + numberJSON.to) + "\" onKeyUp=\"validateInt($(this), event);\"");
                break;

            case Data.FLOAT:
                NumberJSON numberJSONf = JsonConvert.DeserializeObject <NumberJSON>(AuxValues);
                if ((numberJSONf.from == numberJSONf.to) && (numberJSONf.to == 0))
                {
                    validationFunction    = "validateFloat($(this), event);";
                    numberJSONf.maxLength = "10";
                }
                else
                {
                    validationFunction = "validateFloat($(this), event, " + numberJSONf.from + ", " + numberJSONf.to + ");";
                }
                retval = DrawInput.InputTextField(fieldId, Value, numberJSONf.maxLength, "", validationFunction, "width: 50px;", "title=\"" + Common.StrLang(Text.EnterValueBetweenXandY, numberJSONf.from + "," + numberJSONf.to) + "\" onKeyUp=\"validateFloat($(this), event);\"");
                break;

            case Data.DATE:
                retval = DrawInput.InputTextField(fieldId, Value, "", "datePicker", "", "width: 85px;", "");
                break;

            case Data.CHECKBOX:
                retval = DrawInput.InputCheckbox(fieldId, Value, (Value == "1"), "", "", "", "onChange='toggleCheckbox($(this));'");
                break;

            case Data.TREE:
                retval  = DrawInput.InputHiddenField(fieldId, Value, "", "");
                retval += "<div id='tree_" + fieldId + "'></div>";
                retval += "<script language='JavaScript'>";
                retval += "$('#tree_" + fieldId + "').treeSelectJSON({";
                retval += "  source: " + AuxValues + ",";
                retval += "  target: '" + fieldId + "',";
                retval += "  defaultText: '- " + Common.SQSF(Text.Select) + " -',";
                retval += "  preselected: '" + Value + "'";
                retval += "});";
                retval += "</script>";
                break;

            case Data.MULTI_TEXT:
                retval = DrawInput.InputTextArea(fieldId, Value, "4", "", "", "", "width: 100%;", "");
                break;

            case Data.SLIDER:
                if (String.IsNullOrEmpty(Value))
                {
                    Value = "0";
                }
                retval  = DrawInput.InputHiddenField(fieldId, Value, "", "");
                retval += "<div id='" + fieldId + "_slider'></div>";
                retval += "<script language='JavaScript'>";
                retval += "$('#" + fieldId + "_slider').slider({ value: " + Value + ", max: " + AuxValues + ", change: function() { $('#" + fieldId + "').val($('#" + fieldId + "_slider').slider('option', 'value')) }});";
                retval += "</script>";
                break;

            case Data.EMAIL:
                retval = DrawInput.InputTextField(fieldId, Value, "", "", "validateEmail($(this));", "", "title=\"" + Text.InvalidEmail + "\" placeholder=\"[email protected]\"");
                break;

            case Data.LABEL:
                retval = "<div align='center'>" + AuxValues + "</div>";
                break;

            default:
                break;
            }
            return(retval);
        }