Exemplo n.º 1
0
 /// <summary>
 /// Adds an entry to the System Log.
 /// </summary>
 /// <param name="idUser">The current IdUser performing an action.</param>
 /// <param name="kind">The LogKind.Kind of action being performed.</param>
 /// <param name="idModule">The current IdModule.</param>
 /// <param name="idRelated">The current IdRelated (if present), this takes the value of any entity.</param>
 /// <param name="desc">An associated description (if provided).</param>
 public static void Add(int idUser, int kind, int idModule, int idRelated, string desc)
 {
     SystemLog systemLog = new SystemLog();
     systemLog.IdUser = idUser;
     systemLog.Kind = kind;
     systemLog.IdModule = idModule;
     systemLog.IdRelated = idRelated;
     systemLog.Description = desc;
     systemLog.Create();
 }
Exemplo n.º 2
0
        /// <summary>
        /// Retrieves an HTML String with the full listing of records.
        /// </summary>
        /// <param name="currentPage">The current page.</param>
        /// <param name="filter">A given SQL Statement filter.</param>
        /// <returns>An HTML including the log list.</returns>
        public static string GetLogList(int currentPage, string filter)
        {
            string retval = "";
            string className = "";
            int total = 0;
            double recordsPerPage = Config.RecordsPerPage();
            string sql = "SELECT COUNT(IdLog) AS howMany FROM SystemLog";
            if (SessionHandler.Id != -1)
            {
                filter = Common.StrAdd(filter, " AND ", "IdUser <> -1");
            }
            sql = Common.StrAdd(sql, " WHERE ", filter);
            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%'>";

            //Table Header
            retval += "<tr><th>" + Text.DateTime + "</th><th>" + Text.Username + "</th><th>" + Text.Action + "</th><th>" + Text.Description + "</th></tr>";

            sql = "SELECT IdLog, TimeStamp FROM (SELECT IdLog, TimeStamp, ROW_NUMBER() OVER (ORDER BY TimeStamp DESC) AS RowNum FROM SystemLog";
            sql = Common.StrAdd(sql, " WHERE ", filter);
            sql += ") AS SL WHERE SL.RowNum BETWEEN ((" + currentPage + " - 1) * " + recordsPerPage + ") + 1 AND " + recordsPerPage + " * (" + currentPage + ")";
            string[] idLogList = Common.CSVToArray(Common.GetBDList("IdLog", sql, false));
            foreach (string idLog in idLogList)
            {
                try
                {
                    SystemLog log = new SystemLog(Convert.ToInt32(idLog));
                    User user = new User(log.IdUser);
                    string description = log.Description.Replace("#SESSION_START#", Text.SessionStarted + ": ").Replace("#SESSION_END#", Text.SessionClosed).Replace("#LOGIN_FAILED#", Text.LoginFailed + ": ").Replace("#FIELD_SEQUENCE#", Text.FieldSequence);
                    if (log.IdModule != 0)
                    {
                        Module module = new Module(log.IdModule);
                        description = Common.StrAdd(Modules.FriendlyModuleName(module.Name), ": ", description);
                        description += " [" + log.IdRelated + "]";
                        if (log.IdModule == Modules.IMPORT_USERS || log.IdModule == Modules.EVAL_IMPORT_EXAMS || log.IdModule == Modules.EVAL_ASSIGN || log.IdModule == Modules.EVAL_IMPORT_RESULTS)
                        {
                            description += "&nbsp;[<a href='#' class='dark' onClick='viewLog(" + log.IdRelated + "); return false;'>" + Text.Detail + "</a>]";
                        }
                    }
                    className = Common.SwitchClass(className);
                    retval += "<tr class='" + className + "'>";
                    retval += "<td>" + log.TimeStamp.ToString() + "</td>";
                    retval += "<td>" + user.Username + "</td>";
                    retval += "<td>" + LogKind.Name(log.Kind) + "</td>";
                    retval += "<td>" + description + "</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.Records + "</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;
        }