Ejemplo n.º 1
0
        public static bool checkApplicationLogin(string loginName, string loginPassword)
        {
            int userId = 0;

            // open db..
            cData db = new cData();

            db.openDB();

            userId = db.getUserIDFromLogin(loginName, loginPassword, "application");
            loadUser(userId);

            // audit trail..
            if (userId == 0)
            {
                db.auditEvent(cConstants.eventUserLoginFailed, 0, loginName);  // login failed..
            }
            else
            {
                db.auditEvent(cConstants.eventUserLogin, 0, "Application Login"); // login successful
            }
            db.closeDB();                                                         // cleanup

            return(userId != 0);
        }
Ejemplo n.º 2
0
        private void saveClient()
        {
            ClientData client = new ClientData();

            client.clientid   = m_idref;
            client.clientref  = txtClientRef.Text;
            client.clientname = txtClientName.Text;

            int newClientID = m_data.saveClient(client);

            // audit trail
            if (m_idref == 0)
            {
                m_data.auditEvent(cConstants.eventClientNew, newClientID);
            }
            else
            {
                m_data.auditEvent(cConstants.eventClientEdit, newClientID);
            }


            if (newClientID != 0)
            {
                Response.Redirect("~/audit/clients");
            }
        }
Ejemplo n.º 3
0
        public static void logout()
        {
            // audit trail..
            if (userID() != 0)
            {
                cData db = new cData();
                if (db.openDB())
                {
                    db.auditEvent(cConstants.eventUserLogout);
                    db.closeDB();   // cleanup
                }
            }

            HttpContext.Current.Session["user.id"]         = "0";
            HttpContext.Current.Session["user.object"]     = null;
            HttpContext.Current.Session["UserAgreesTerms"] = "";
            HttpContext.Current.Response.Redirect("~/login");
        }
Ejemplo n.º 4
0
        public static void handleEvent(int eventId, int surveyId)
        {
            // open up the db
            cData m_data = new cData();

            if (!m_data.openDB())
            {
                return;
            }

            /*
             *  load up the audit details & convert id's to text
             */
            SurveySummaryData survey   = m_data.loadSurvey(surveyId);
            LocationData      location = m_data.loadLocation(survey.locationid);
            ClientData        client   = m_data.loadClient(location.clientid);

            // convert id's to text
            string sqlCmd       = "SELECT templatename FROM templates WHERE templateid=" + survey.templateid;
            string templateName = m_data.runSql(sqlCmd);
            string jobRef       = client.clientname + " - " + location.businessunit + " - " + location.locationname + " - " + templateName + " - " + survey.dateofaudit;


            /*
             *  Set up the email, SMTP settings and links to the job
             */
            //load up the standard template file.
            string emailTemplate = loadTemplateFile();

            if (emailTemplate == string.Empty)
            {
                return;
            }

            // get our email server settings..
            string emailSenderName      = cTools.cStrExt(ConfigurationManager.AppSettings["SenderName"]);
            string emailSenderEmail     = cTools.cStrExt(ConfigurationManager.AppSettings["SenderEMail"]);
            string emailRootFolder      = cTools.cStrExt(ConfigurationManager.AppSettings["EmailFolder"]);
            int    notifyUserOnSendToHQ = cTools.cIntExt(ConfigurationManager.AppSettings["NotifyUserOnSendToHQ"]);

            string emailSubjectLine   = string.Empty;
            string emailHtml          = string.Empty;
            string notificationsBlock = string.Empty;
            string sendToEmail        = string.Empty;
            string sendToName         = string.Empty;
            string siteUrl            = "http://" + HttpContext.Current.Request.ServerVariables["SERVER_NAME"];

            if (siteUrl.Contains("localhost"))
            {
                siteUrl += "/coylegroup";                              // dev server
            }
            string linkToJob = siteUrl + "/audit/summary/" + surveyId; // all notification links go to summary page..

            /*
             *  Customise the email depending on what action was just taken
             */
            switch (eventId)
            {
            case cConstants.eventSurveyConsultantChanged_Notification:
                emailSubjectLine   = "Audit Notification: Contractor Assigned";
                notificationsBlock = "You have been assigned as the <b>Contractor</b> for the following audit.";
                if (survey.auditorid != 0)
                {
                    WebUser userDetails = m_data.loadUser(survey.auditorid);
                    sendToEmail = userDetails.emailaddress;
                    sendToName  = userDetails.firstname;
                }
                break;

            case cConstants.eventQuestionSubmitToHQ_Notification:
                emailSubjectLine   = "Audit Notification: For Internal Review";
                notificationsBlock = "This audit has been <b>Sent to HQ</b> for internal review.";
                if (notifyUserOnSendToHQ != 0)
                {
                    WebUser userDetails = m_data.loadUser(notifyUserOnSendToHQ);
                    sendToEmail = userDetails.emailaddress;
                    sendToName  = userDetails.firstname;
                }
                break;

            case cConstants.eventSurveyStatusReadyForClientReview_Notification:
                emailSubjectLine   = "Audit Notification: Pending Client Approval";
                notificationsBlock = "An audit is available <b>Pending Client Approval</b>";
                if (survey.client_mgruserid != 0)
                {
                    WebUser userDetails = m_data.loadUser(survey.client_mgruserid);
                    sendToEmail = userDetails.emailaddress;
                    sendToName  = userDetails.firstname;
                }
                break;

            case cConstants.eventClientApprovalAccept_Notification:
                emailSubjectLine   = "Audit Notification: Approved by Client";
                notificationsBlock = "This audit has been <b>Approved by the Client</b>.";
                if (survey.client_approvalcomments != "")
                {
                    notificationsBlock += "<br><br>Client Comments:<br>" +
                                          "<i>" + survey.client_approvalcomments + "</i>";
                }

                if (notifyUserOnSendToHQ != 0)
                {
                    WebUser userDetails = m_data.loadUser(notifyUserOnSendToHQ);
                    sendToEmail = userDetails.emailaddress;
                    sendToName  = userDetails.firstname;
                }
                break;

            case cConstants.eventClientApprovalReject_Notification:
                emailSubjectLine   = "Audit Notification: Rejected by Client";
                notificationsBlock = "This audit has been <b>Rejected by the Client</b>.";
                if (survey.client_approvalcomments != "")
                {
                    notificationsBlock += "<br><br>Client Comments:<br>" +
                                          "<i>" + survey.client_approvalcomments + "</i>";
                }
                if (notifyUserOnSendToHQ != 0)
                {
                    WebUser userDetails = m_data.loadUser(notifyUserOnSendToHQ);
                    sendToEmail = userDetails.emailaddress;
                    sendToName  = userDetails.firstname;
                }
                break;

            case cConstants.eventClientResponsesClosed_NotifyClientMgr:
                emailSubjectLine   = "Audit Notification: All Client Actions Closed";
                notificationsBlock = "Congratulations - All action items have been <b>closed</b> on this audit.";
                if (survey.client_mgruserid != 0)
                {
                    WebUser userDetails = m_data.loadUser(survey.client_mgruserid);
                    sendToEmail = userDetails.emailaddress;
                    sendToName  = userDetails.firstname;
                }
                break;

            case cConstants.eventClientResponsesClosed_NotifyClientAdmin:
                emailSubjectLine   = "Audit Notification: All Client Actions Closed";
                notificationsBlock = "Congratulations - All action items have been <b>closed</b> on this audit.";
                // don't send if no admin user set or if it's the same as the manager..
                if (survey.client_adminuserid != 0 && survey.client_adminuserid != survey.client_mgruserid)
                {
                    WebUser userDetails = m_data.loadUser(survey.client_adminuserid);
                    sendToEmail = userDetails.emailaddress;
                    sendToName  = userDetails.firstname;
                }
                break;
            }

            // while testing...
            // sendToName += " (" + sendToEmail + ")";
            // sendToEmail = "*****@*****.**";

            // if no email associated with this task then off ye go..
            if (sendToEmail == string.Empty)
            {
                return;
            }

            // record in the audit trail that we've handled this notification
            string auditEntry = string.Format("To: {0} ({1})\n{2}",
                                              sendToName, sendToEmail, notificationsBlock);

            m_data.auditEvent(eventId, surveyId, auditEntry);

            // start with a fresh template & replace with content for this user
            emailHtml = emailTemplate;
            emailHtml = emailHtml.Replace("%sendtoname%", sendToName);
            emailHtml = emailHtml.Replace("%content%", notificationsBlock);
            emailHtml = emailHtml.Replace("%datestamp%", cTools.cDateAndShortTime(DateTime.Now));
            emailHtml = emailHtml.Replace("%linktojob%", linkToJob);
            emailHtml = emailHtml.Replace("%jobref%", jobRef);

            // set up today's email folder..
            string folderName = String.Format("{0}/{1}",
                                              emailRootFolder,
                                              DateTime.Now.ToString("ddMMMyyyy")); // folder changes daily

            System.IO.Directory.CreateDirectory(folderName);

            string mailFilename = String.Format("{0}/notifications_{1}.htm",
                                                folderName,
                                                sendToEmail); // append all emails for person per day to one file

            // write the file to the local server for later retrieval
            cFiles.writeFile(mailFilename, emailHtml, true);

            // send the email now..we store the output in a subfolder in the logs if enabled
            cTools.log("Sending notification email to: " + sendToEmail);

            // send the email now..unless it's on my dev machine..
            if (!siteUrl.Contains("localhost"))
            {
                cMailer.sendMail(sendToName, sendToEmail, emailSenderName, emailSenderEmail, emailSubjectLine, emailHtml);
            }

            // send me a copy..
            cMailer.sendMail("Gary Alerts", "*****@*****.**", emailSenderName, emailSenderEmail, emailSubjectLine, emailHtml);

            // cleanup
            m_data.closeDB();
        }