Beispiel #1
0
        //====================================================================================================
        /// <summary>
        /// load a feature from the current row of a contentSet
        /// </summary>
        /// <param name="CP"></param>
        /// <param name="csFeature"></param>
        /// <returns></returns>
        public static PortalDataFeatureModel loadPortalFeatureFromCs(CPBaseClass CP, CPCSBaseClass csFeature)
        {
            PortalDataFeatureModel feature = new PortalDataFeatureModel();

            try {
                feature.id         = csFeature.GetInteger("id");
                feature.name       = csFeature.GetText("name");
                feature.heading    = csFeature.GetText("heading");
                feature.sortOrder  = csFeature.GetText("sortOrder");
                feature.addPadding = csFeature.GetBoolean("addPadding");
                if (string.IsNullOrEmpty(feature.heading))
                {
                    feature.heading = feature.name;
                }
                feature.guid = csFeature.GetText("ccguid");
                if (string.IsNullOrEmpty(feature.guid))
                {
                    feature.guid = CP.Utils.CreateGuid();
                    csFeature.SetField("ccguid", feature.guid);
                }
                //
                feature.addonId         = csFeature.GetInteger("addonId");
                feature.dataContentId   = csFeature.GetInteger("dataContentId");
                feature.parentFeatureId = csFeature.GetInteger("parentFeatureId");
            } catch (Exception ex) {
                CP.Site.ErrorReport(ex, "exception in loadPortal");
                throw;
            }
            return(feature);
        }
            //
            //====================================================================================================
            /// <summary>
            /// open an existing object
            /// </summary>
            /// <param name="cp"></param>
            /// <param name="cs"></param>
            private static T loadRecord <T>(CPBaseClass cp, CPCSBaseClass cs) where T : baseModel
            {
                T instance = null;

                try {
                    if (cs.OK())
                    {
                        Type   instanceType = typeof(T);
                        string tableName    = derivedContentTableName(instanceType);
                        instance = (T)Activator.CreateInstance(instanceType);
                        foreach (PropertyInfo resultProperty in instance.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public))
                        {
                            switch (resultProperty.Name.ToLower())
                            {
                            //case "specialcasefield":
                            //    break;
                            case "sortorder":
                                //
                                // -- customization for pc, could have been in default property, db default, etc.
                                string sortOrder = cs.GetText(resultProperty.Name);
                                if ((string.IsNullOrEmpty(sortOrder)))
                                {
                                    sortOrder = "9999";
                                }
                                resultProperty.SetValue(instance, sortOrder, null);
                                break;

                            default:
                                switch (resultProperty.PropertyType.Name)
                                {
                                case "Int32":
                                    resultProperty.SetValue(instance, cs.GetInteger(resultProperty.Name), null);
                                    break;

                                case "Boolean":
                                    resultProperty.SetValue(instance, cs.GetBoolean(resultProperty.Name), null);
                                    break;

                                case "DateTime":
                                    resultProperty.SetValue(instance, cs.GetDate(resultProperty.Name), null);
                                    break;

                                case "Double":
                                    resultProperty.SetValue(instance, cs.GetNumber(resultProperty.Name), null);
                                    break;

                                default:
                                    resultProperty.SetValue(instance, cs.GetText(resultProperty.Name), null);
                                    break;
                                }
                                break;
                            }
                        }
                    }
                } catch (Exception ex) {
                    cp.Site.ErrorReport(ex);
                    throw;
                }
                return(instance);
            }
        //
        //====================================================================================================
        /// <summary>
        /// pattern get a list of objects from this model
        /// </summary>
        /// <param name="cp"></param>
        /// <param name="sqlCriteria"></param>
        /// <returns></returns>
        protected static List <T> createList <T>(CPBaseClass cp, string sqlCriteria, string sqlOrderBy) where T : baseModel
        {
            List <T> result = new List <T>();

            try
            {
                CPCSBaseClass cs = cp.CSNew();
                List <string> ignoreCacheNames = new List <string>();
                Type          instanceType     = typeof(T);
                string        contentName      = derivedContentName(instanceType);
                if ((cs.Open(contentName, sqlCriteria, sqlOrderBy)))
                {
                    T instance = default(T);
                    do
                    {
                        instance = loadRecord <T>(cp, cs);
                        if ((instance != null))
                        {
                            result.Add(instance);
                        }
                        cs.GoNext();
                    } while (cs.OK());
                }
                cs.Close();
            }
            catch (Exception ex)
            {
                cp.Site.ErrorReport(ex);
            }
            return(result);
        }
        //
        //====================================================================================================
        /// <summary>
        /// return a new model with the data selected. All cacheNames related to the object will be added to the cacheNameList.
        /// </summary>
        /// <param name="cp"></param>
        /// <param name="recordId">The id of the record to be read into the new object</param>
        protected static T create <T>(CPBaseClass cp, int recordId) where T : baseModel
        {
            T result = null;

            try
            {
                if (recordId > 0)
                {
                    Type          instanceType = typeof(T);
                    string        contentName  = derivedContentName(instanceType);
                    CPCSBaseClass cs           = cp.CSNew();
                    if (cs.Open(contentName, "(id=" + recordId.ToString() + ")"))
                    {
                        result = loadRecord <T>(cp, cs);
                    }
                    cs.Close();
                }
            }
            catch (Exception ex)
            {
                cp.Site.ErrorReport(ex);
                throw;
            }
            return(result);
        }
        //
        //====================================================================================================
        protected static int getCount <T>(CPBaseClass cp, string sqlCriteria) where T : baseModel
        {
            int result = 0;

            try
            {
                Type          instanceType = typeof(T);
                string        tableName    = derivedContentTableName(instanceType);
                CPCSBaseClass cs           = cp.CSNew();
                string        sql          = "select count(id) as cnt from " + tableName;
                if ((!string.IsNullOrEmpty(sqlCriteria)))
                {
                    sql += " where " + sqlCriteria;
                }
                if ((cs.OpenSQL(sql)))
                {
                    result = cs.GetInteger("cnt");
                }
                cs.Close();
            }
            catch (Exception ex)
            {
                cp.Site.ErrorReport(ex);
            }
            return(result);
        }
Beispiel #6
0
        //
        // ===============================================================================
        // process Form
        // ===============================================================================
        //
        public int processForm(CPBaseClass cp, int srcFormId, string rqs, DateTime rightNow, ref int appId)
        {
            int nextFormId = srcFormId;

            try
            {
                string        button = cp.Doc.GetProperty(constants.rnButton, "");
                CPCSBaseClass cs     = cp.CSNew();
                //
                if (button != "")
                {
                    //
                    // server-side validation
                    // add client-side validation in the javascript tab of the addon. (but still always include server-side)
                    //
                    constants.checkRequiredFieldText(cp, "name", "Name");
                    //
                    if (cp.UserError.OK())
                    {
                        cs.Open("people", "id=" + cp.User.Id.ToString(), "", true, "", 1, 1);
                        cs.SetField("name", cp.Doc.GetText("name", ""));
                        cs.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                errorReport(cp, ex, "processForm");
            }
            return(nextFormId);
        }
Beispiel #7
0
 //
 // ====================================================================================================
 /// <summary>
 /// pattern get a list of objects from this model
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="cp"></param>
 /// <param name="sql"></param>
 /// <param name="pageSize"></param>
 /// <param name="pageNumber"></param>
 /// <returns></returns>
 protected static List <T> createListFromSql <T>(CPBaseClass cp, string sql, int pageSize, int pageNumber) where T : BaseDomainModel
 {
     try {
         using (CPCSBaseClass cs = cp.CSNew()) {
             List <T> result = new List <T>();
             if ((cs.OpenSQL(sql, "", pageSize, pageNumber)))
             {
                 do
                 {
                     T instance = loadRecord <T>(cp, cs);
                     if ((instance != null))
                     {
                         result.Add(instance);
                     }
                     cs.GoNext();
                 } while (cs.OK());
             }
             cs.Close();
             return(result);
         }
     } catch (Exception ex) {
         cp.Site.ErrorReport(ex);
         throw;
     }
 }
        public override string getForm(CPBaseClass cp, int dstFormId, string rqs, DateTime rightNow, applicationClass application)
        {
            string returnHtml = "";

            try
            {
                CPBlockBaseClass layout = cp.BlockNew();
                CPCSBaseClass    cs     = cp.CSNew();
                string           body;

                layout.OpenLayout("MultiFormAjaxSample - Form 3");

                // manuiplate the html, pre-populating fields, hiding parts not needed, etc.
                // get the resulting form from the layout object
                // add the srcFormId as a hidden
                // wrap it in a form for the javascript to use during submit

                body       = layout.GetHtml();
                body      += cp.Html.Hidden(commonModule.rnSrcFormId, dstFormId.ToString());
                returnHtml = cp.Html.Form(body, "", "", "mfaForm3", rqs);
            }
            catch (Exception ex)
            {
                cp.Site.ErrorReport(ex, "getForm");
            }
            return(returnHtml);
        }
Beispiel #9
0
        public override int processForm(CPBaseClass cp, int srcFormId, string rqs, DateTime rightnow, applicationClass application)
        {
            int nextFormId = srcFormId;

            try
            {
                string        button;
                CPCSBaseClass cs = cp.CSNew();
                string        firstName;
                Boolean       isInputOK = true;

                // ajax routines return a different name for button

                button = cp.Doc.GetText("ajaxButton");

                if (button == "")
                {
                    button = cp.Doc.GetText(commonModule.rnButton);
                }


                // check the input requirements
                // if user errors are handled with javascript, no need to display a message, just prevent save

                firstName = cp.Doc.GetText("firstName");
                if (firstName == "")
                {
                    isInputOK = false;
                }

                // if no user errors, process input
                // if errors, just return default nextFormId which will redisplay this form

                if (isInputOK)
                {
                    application.firstName = firstName;
                    application.changed   = true;

                    // determine the next form


                    switch (button)
                    {
                    case commonModule.buttonNext:
                        //
                        nextFormId = commonModule.formIdTwo;
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                cp.Site.ErrorReport(ex, "processForm");
            }

            return(nextFormId);
        }
 //
 // ====================================================================================================
 //
 public static string getNodeLookupContentName(CPBaseClass cp, string nodeName, int recordId, string contentName)
 {
     using (CPCSBaseClass cs = cp.CSNew()) {
         if (cs.OpenRecord(contentName, recordId, "name", false))
         {
             return(getNode(nodeName, cs.GetText("name"), false));
         }
     }
     return(getNode(nodeName, "", false));
 }
Beispiel #11
0
        //==========================================================================================
        /// <summary>
        /// handle a transient fail
        /// </summary>
        /// <param name="cp"></param>
        /// <param name="emailAddress"></param>
        private static void transientFail(CPBaseClass cp, string emailAddress, string bounceMsg)
        {
            const string spAWSGracePeriod = "AWS SES Transient Email Grace Period";
            //
            // do not clear allowBulkEmail
            // add or update email bounce list
            //
            CPCSBaseClass cs = cp.CSNew();

            if (cs.Open("Email Bounce List", "(name=" + cp.Db.EncodeSQLText(emailAddress) + ")"))
            {
                if (cs.GetBoolean("transient"))
                {
                    //
                    // previous transient failure
                    //
                    if (DateTime.Now > cs.GetDate("transientFixDeadline"))
                    {
                        //
                        // past deadline, covert to permanent fail
                        //
                        cs.Close();
                        permanentFail(cp, emailAddress, bounceMsg);
                    }
                    else
                    {
                        //
                        // not past deadline, update details
                        //
                        cs.SetField("details", bounceMsg);
                    }
                }
                else
                {
                    //
                    // previous permanent failure - do nothing
                    //
                }
            }
            else
            {
                //
                // no previous failures, add them
                //
                cs.Close();
                if (cs.Insert("Email Bounce List"))
                {
                    cs.SetField("name", emailAddress);
                    cs.SetField("details", bounceMsg);
                    cs.SetField("transient", "1");
                    cs.SetField("transientFixDeadline", DateTime.Now.AddDays(cp.Site.GetInteger(spAWSGracePeriod)).ToShortDateString());
                }
            }
            cs.Close();
        }
Beispiel #12
0
        //
        // ===============================================================================================
        // performs all housekeeping when a thread record is changed (add,mod,del)
        // ===============================================================================================
        //
        public override object Execute(Contensive.BaseClasses.CPBaseClass cp)
        {
            //int sourceFormId = 0;
            //int formId = 0;
            //int forumId = 0;
            int           threadId = 0;
            string        s        = "";
            string        sql      = "";
            CPCSBaseClass cs       = cp.CSNew();

            //
            threadId = cp.Utils.EncodeInteger(cp.Doc.GetProperty("recordId", ""));
            if (threadId == 0)
            {
                //
                // re count 'threads' in all forums
                //
                sql = "select ccforums.id as forumId"
                      + ",(select count(ccforumthreads.id) from ccforumthreads where forumId=ccForums.id) as threadCnt"
                      + ",(select count(p.id) from ccforumPosts p left join ccforumThreads t on t.id=p.threadid where t.forumId=ccforums.id) as postCnt"
                      + ",(select max(p.id) from ccforumPosts p left join ccforumThreads t on t.id=p.threadid where t.forumId=ccforums.id) as lastPostId"
                      + " from ccforums"
                      + "";
            }
            else
            {
                //
                // update forum for thread provided
                //
                sql = "select ccforums.id as forumId"
                      + ",(select count(ccforumthreads.id) from ccforumthreads where forumId=ccForums.id) as threadCnt"
                      + ",(select count(p.id) from ccforumPosts p left join ccforumThreads t on t.id=p.threadid where t.forumId=ccforums.id) as postCnt"
                      + ",(select max(p.id) from ccforumPosts p left join ccforumThreads t on t.id=p.threadid where t.forumId=ccforums.id) as lastPostId"
                      + " from ccforums"
                      + " where ccforums.id in (select forumid from ccforumthreads where id=" + threadId + ")"
                      + "";
            }
            //
            if (cs.OpenSQL2(sql, "", 1000, 1))
            {
                while (cs.OK())
                {
                    sql = "update ccforums set threads=" + cs.GetInteger("threadCnt") + ",posts=" + cs.GetInteger("postCnt") + ",lastPostId=" + cs.GetInteger("lastPostId") + " where id=" + cs.GetInteger("forumId");
                    cp.Db.ExecuteSQL(sql, "", "1", "1", "1");
                    cs.GoNext();
                }
            }
            cs.Close();
            //
            return(s);
        }
        //
        //
        //
        public static applicationClass getApplication(CPBaseClass cp, Boolean createRecordIfMissing)
        {
            applicationClass application = new applicationClass();

            try {
                CPCSBaseClass cs    = cp.CSNew();
                CPCSBaseClass csSrc = cp.CSNew();

                // get id of this user's application
                // use visit property if they keep the same application for the visit
                // use visitor property if each time they open thier browser, they get the previous application
                // use user property if they only get to the application when they are associated to the current user (they should be authenticated first)

                application.completed = false;
                application.changed   = false;
                application.id        = cp.Visit.GetInteger("multiformAjaxSample ApplicationId");

                if (application.id != 0)
                {
                    if (!cs.Open("MultiFormAjax Application", "(dateCompleted is null)"))
                    {
                        application.id = 0;
                    }
                }

                if (cs.OK())
                {
                    application.firstName = cs.GetText("firstName");
                    application.lastName  = cs.GetText("lastName");
                    application.email     = cs.GetText("email");
                }
                else
                {
                    if (csSrc.Open("people", "id=" + cp.User.Id))
                    {
                        application.firstName = csSrc.GetText("firstName");
                        application.lastName  = csSrc.GetText("lastName");
                        application.email     = csSrc.GetText("email");
                    }
                    csSrc.Close();
                }
                cs.Close();
            }
            catch (Exception ex)
            {
                cp.Site.ErrorReport(ex, "Error in getApplication");
            }

            return(application);
        }
 //====================================================================================================
 /// <summary>
 /// get a portal feature available to developers that provides tool for creating portals
 /// </summary>
 /// <param name="CP"></param>
 /// <returns></returns>
 public static string getDevTool(CPBaseClass CP, PortalDataModel portalData, string frameRqs)
 {
     try {
         string section;
         //
         // this is a feature list, display the feature list
         //
         FormSimpleClass content = new FormSimpleClass {
             title = "Developer Tool",
             body  = ""
         };
         //
         // process snapshot tool
         //
         if (CP.Doc.GetText("button") == "Take Snapshot")
         {
             CPCSBaseClass cs = CP.CSNew();
             if (cs.Open("portals", "ccguid=" + CP.Db.EncodeSQLText(portalData.guid), "", true, "", 9999, 1))
             {
                 System.Web.Script.Serialization.JavaScriptSerializer msJson = new System.Web.Script.Serialization.JavaScriptSerializer();
                 string configJson = msJson.Serialize(portalData);
                 cs.SetField("defaultConfigJson", configJson);
             }
             cs.Close();
         }
         //
         // output snapshot tool
         //
         section       = "<h3>Portal Snapshot</h3>";
         section      += "<p>Click the snapshot button to save the current features for this portal in the portal's default configuration field.</p>";
         section      += CP.Html.Button("button", "Take Snapshot");
         section      += "<p>Modify Portal and Portal Features data directly</p>";
         section      += "<ul>";
         section      += "<li><a href=\"?cid=" + CP.Content.GetID("Portals") + "\">Portals</a></li>";
         section      += "<li><a href=\"?cid=" + CP.Content.GetID("Portal Features") + "\">Portal Features</a></li>";
         section      += "<li><a href=\"?cid=" + CP.Content.GetID("Admin Framework Reports") + "\">Admin Framework Reports</a></li>";
         section      += "<li><a href=\"?cid=" + CP.Content.GetID("Admin Framework Report Columns") + "\">Admin Framework Report Columns</a></li>";
         section      += "</ul>";
         section       = CP.Html.Form(section, "", "", "", frameRqs);
         content.body += section;
         //
         //
         //
         return(content.getHtml(CP));
     } catch (Exception ex) {
         CP.Site.ErrorReport(ex, "exception in loadPortal");
         throw;
     }
 }
Beispiel #15
0
        public override int processForm(CPBaseClass cp, int srcFormId, string rqs, DateTime rightnow, applicationClass application)
        {
            int nextFormId = srcFormId;

            try
            {
                string        button;
                CPCSBaseClass cs = cp.CSNew();

                // ajax routines return a different name for button

                button = cp.Doc.GetText("ajaxButton");

                if (button == "")
                {
                    button = cp.Doc.GetText(commonModule.rnButton);
                }

                if (button == commonModule.buttonFinish)
                {
                    // process the form
                    application.completed = true;
                    application.changed   = true;
                }

                // determine the next form

                switch (button)
                {
                case commonModule.buttonPrevious:
                    //
                    nextFormId = commonModule.formIdTwo;
                    break;

                case commonModule.buttonFinish:
                    //
                    nextFormId = commonModule.formIdFour;
                    break;
                }
            }
            catch (Exception ex)
            {
                cp.Site.ErrorReport(ex, "processForm");
            }

            return(nextFormId);
        }
        //
        //
        //
        public static void saveApplication(CPBaseClass cp, applicationClass application, DateTime rightNow)
        {
            try {
                CPCSBaseClass cs = cp.CSNew();

                if (application.changed)
                {
                    if (application.id > 0)
                    {
                        cs.Open(cnMultiFormAjaxApplications, "(id=" + application.id + ")");
                    }
                    if (!cs.OK())
                    {
                        if (cs.Insert("MultiFormAjax Application"))
                        {
                            //
                            // create a new record.
                            // Set application Id incase needed later
                            // Set visit property to save the application Id
                            //
                            application.id = cs.GetInteger("id");
                            cp.Visit.SetProperty("multiformAjaxSample ApplicationId", application.id.ToString());
                            cs.SetField("visitId", cp.Visit.Id.ToString());
                        }
                    }

                    if (cs.OK())
                    {
                        cs.SetField("firstName", application.firstName);
                        cs.SetField("lastName", application.lastName);
                        cs.SetField("email", application.email);
                        if (application.completed)
                        {
                            cs.SetField("datecompleted", rightNow.ToString());
                        }
                    }

                    cs.Close();
                }
            }
            catch (Exception ex)
            {
                cp.Site.ErrorReport(ex, "Error in getApplication");
            }
        } // End saveApplication
Beispiel #17
0
 //
 // ====================================================================================================
 /// <summary>
 /// return a layout record by it's guid. If not found populate the default values
 /// </summary>
 /// <param name="cp"></param>
 /// <param name="LayoutGuid"></param>
 /// <param name="LayoutDefaultName"></param>
 /// <param name="LayoutDefaultHtml"></param>
 /// <returns></returns>
 public static string getLayoutByGuid(CPBaseClass cp, string LayoutGuid, string LayoutDefaultName, string LayoutDefaultHtml)
 {
     using (CPCSBaseClass cs = cp.CSNew()) {
         if (cs.Open("layouts", "ccguid=" + cp.Db.EncodeSQLText(LayoutGuid)))
         {
             return(cp.Html5.Form(cs.GetText("layout")));
         }
         //
         // -- record not found, create it and return the default layout
         cs.Close();
         cs.Insert("Layouts");
         cs.SetField("name", LayoutDefaultName);
         cs.SetField("ccguid", LayoutGuid);
         cs.SetField("layout", LayoutDefaultHtml);
         cs.Save();
     }
     return(cp.Html5.Form(LayoutDefaultHtml));
 }
Beispiel #18
0
 //
 //====================================================================================================
 /// <summary>
 /// get the id of the record by it's guid
 /// </summary>
 /// <param name="cp"></param>
 /// <param name="ccGuid"></param>record
 /// <returns></returns>
 protected static int getRecordId <T>(CPBaseClass cp, string ccGuid) where T : baseModel
 {
     try {
         if ((!string.IsNullOrEmpty(ccGuid)))
         {
             Type          instanceType = typeof(T);
             string        tableName    = derivedContentTableName(instanceType);
             CPCSBaseClass cs           = cp.CSNew();
             if ((cs.OpenSQL("select id from " + tableName + " where ccguid=" + cp.Db.EncodeSQLText(ccGuid))))
             {
                 return(cs.GetInteger("id"));
             }
             cs.Close();
         }
     } catch (Exception ex) {
         cp.Site.ErrorReport(ex);
     }
     return(0);
 }
Beispiel #19
0
 //
 //====================================================================================================
 /// <summary>
 /// get the name of the record by it's id
 /// </summary>
 /// <param name="cp"></param>
 /// <param name="recordId"></param>record
 /// <returns></returns>
 protected static string getRecordName <T>(CPBaseClass cp, int recordId) where T : baseModel
 {
     try {
         if ((recordId > 0))
         {
             Type          instanceType = typeof(T);
             string        tableName    = derivedContentTableName(instanceType);
             CPCSBaseClass cs           = cp.CSNew();
             if ((cs.OpenSQL("select name from " + tableName + " where id=" + recordId.ToString())))
             {
                 return(cs.GetText("name"));
             }
             cs.Close();
         }
     } catch (Exception ex) {
         cp.Site.ErrorReport(ex);
     }
     return("");
 }
Beispiel #20
0
            //
            //====================================================================================================
            /// <summary>
            /// open an existing object
            /// </summary>
            /// <param name="cp"></param>
            /// <param name="recordGuid"></param>
            protected static T create <T>(CPBaseClass cp, string recordGuid) where T : baseModel
            {
                T result = null;

                try {
                    Type          instanceType = typeof(T);
                    string        contentName  = derivedContentName(instanceType);
                    CPCSBaseClass cs           = cp.CSNew();
                    if (cs.Open(contentName, "(ccGuid=" + cp.Db.EncodeSQLText(recordGuid) + ")"))
                    {
                        result = loadRecord <T>(cp, cs);
                    }
                    cs.Close();
                } catch (Exception ex) {
                    cp.Site.ErrorReport(ex);
                    throw;
                }
                return(result);
            }
Beispiel #21
0
 //
 //=========================================================================
 //  get the field value, from cs if ok, else from stream
 //=========================================================================
 //
 public static string getFormField(CPBaseClass cp, CPCSBaseClass cs, string fieldName, string requestName)
 {
     string returnValue= "";
     try
     {
         if (cp.Doc.IsProperty(requestName))
         {
             returnValue = cp.Doc.GetText(requestName, "");
         }
         else if (cs.OK())
         {
             returnValue = cs.GetText(fieldName);
         }
     }
     catch (Exception ex)
     {
         cp.Site.ErrorReport(ex, "Unexpected Error in getFormField");
     }
     return returnValue;
 }
        //
        //=========================================================================
        //  get the field value, from cs if ok, else from stream
        //=========================================================================
        //
        public static string getFormField(CPBaseClass cp, CPCSBaseClass cs, string fieldName, string requestName)
        {
            string returnValue = "";

            try
            {
                if (cp.Doc.IsProperty(requestName))
                {
                    returnValue = cp.Doc.GetText(requestName, "");
                }
                else if (cs.OK())
                {
                    returnValue = cs.GetText(fieldName);
                }
            }
            catch (Exception ex)
            {
                cp.Site.ErrorReport(ex, "Unexpected Error in getFormField");
            }
            return(returnValue);
        }
Beispiel #23
0
        public override int processForm(CPBaseClass cp, int srcFormId, string rqs, DateTime rightnow, applicationClass application)
        {
            int nextFormId = srcFormId;

            try
            {
                string        button;
                CPCSBaseClass cs = cp.CSNew();

                // ajax routines return a different name for button

                button = cp.Doc.GetText("ajaxButton");

                if (button == "")
                {
                    button = cp.Doc.GetText(commonModule.rnButton);
                }

                if ((button == commonModule.buttonSave) | (button == commonModule.buttonOK))
                {
                    // process the form
                }

                // determine the next form

                switch (button)
                {
                case commonModule.buttonRestart:
                    //
                    nextFormId = commonModule.formIdOne;
                    break;
                }
            }
            catch (Exception ex)
            {
                cp.Site.ErrorReport(ex, "processForm");
            }

            return(nextFormId);
        }
        //==========================================================================================
        /// <summary>
        /// for each user in bounce email list that is not transient, set that their allowbulkemail to false
        /// </summary>
        /// <param name="cp"></param>
        private static void removeAllowGroupEmailFromPermanentFails(CPBaseClass cp)
        {
            try {
                using (CPCSBaseClass cs = cp.CSNew()) {
                    if (cs.Open("email bounce list", "transient=0"))
                    {
                        do
                        {
                            string emailAddress = "";
                            string recordName   = cs.GetText("name");

                            //takes into account records with names like "John Doe <*****@*****.**>"
                            int subStart = recordName.IndexOf("<");
                            int subEnd   = recordName.IndexOf(">");
                            //-2 so the final ">" is not included and thestarting "<" is not included
                            int SubLen = (recordName.Length - subStart) - 2;
                            //checks if the bounce list name name has both "<" and ">" in it
                            if ((subStart != -1) && (subEnd != -1))
                            {
                                emailAddress = recordName.Substring((subStart + 1), SubLen);
                            }
                            else
                            {
                                emailAddress = recordName;
                            }
                            cp.Db.ExecuteNonQuery("update ccmembers set allowBulkEmail=0 where email=" + cp.Db.EncodeSQLText(emailAddress));
                            cs.GoNext();
                        } while (cs.OK());
                    }
                    cs.Close();
                }
            }
            catch (Exception ex) {
                cp.Site.ErrorReport(ex);
                throw;
            }
        }
Beispiel #25
0
        //==========================================================================================
        /// <summary>
        /// handle a permanent fail
        /// </summary>
        /// <param name="cp"></param>
        /// <param name="emailAddress"></param>
        private static void permanentFail(CPBaseClass cp, string emailAddress, string bounceMsg)
        {
            //
            // -- clear allowBulkEmail
            cp.Db.ExecuteNonQuery("update ccmembers set allowBulkEmail=0 where email=" + cp.Db.EncodeSQLText(emailAddress));
            //
            // -- add or update email bounce list
            using (CPCSBaseClass cs = cp.CSNew()) {
                if (cs.Open("Email Bounce List", "name=" + cp.Db.EncodeSQLText(emailAddress)))
                {
                    //
                    // -- found in bounce list already, update
                    cs.SetField("details", bounceMsg);
                    cs.SetField("transient", "0");
                }
                else
                {
                    //
                    // -- add to bounce list
                    cs.Close();
                    if (cs.Insert("Email Bounce List"))
                    {
                        cs.SetField("name", emailAddress);
                        cs.SetField("details", bounceMsg);
                        cs.SetField("transient", "0");
                    }
                }
                cs.Close();
            }
            //
            // add to server's block list, "(programfiles)\config\SMTPBlockList_(appName).txt", vbcrlf + emailAddress + vbTab + dateTime
            //
            string filename  = "\\config\\SMTPBlockList_" + cp.Site.Name + ".txt";
            string blockList = cp.CdnFiles.Read(filename);

            cp.CdnFiles.Save(filename, blockList + "\n\r" + emailAddress + "\t" + DateTime.Now.ToString());
        }
        //
        //====================================================================================================
        /// <summary>
        /// save the instance properties to a record with matching id. If id is not provided, a new record is created.
        /// </summary>
        /// <param name="cp"></param>
        /// <returns></returns>
        protected int save(CPBaseClass cp)
        {
            try
            {
                CPCSBaseClass cs           = cp.CSNew();
                Type          instanceType = this.GetType();
                string        contentName  = derivedContentName(instanceType);
                string        tableName    = derivedContentTableName(instanceType);
                if ((id > 0))
                {
                    if (!cs.Open(contentName, "id=" + id))
                    {
                        string message = "Unable to open record in content [" + contentName + "], with id [" + id + "]";
                        cs.Close();
                        id = 0;
                        throw new ApplicationException(message);
                    }
                }
                else
                {
                    if (!cs.Insert(contentName))
                    {
                        cs.Close();
                        id = 0;
                        throw new ApplicationException("Unable to insert record in content [" + contentName + "]");
                    }
                }
                foreach (PropertyInfo resultProperty in this.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public))
                {
                    switch (resultProperty.Name.ToLower())
                    {
                    case "id":
                        id = cs.GetInteger("id");
                        break;

                    case "ccguid":
                        if ((string.IsNullOrEmpty(ccguid)))
                        {
                            ccguid = Guid.NewGuid().ToString();
                        }
                        string value = null;
                        value = resultProperty.GetValue(this, null).ToString();
                        cs.SetField(resultProperty.Name, value);
                        break;

                    default:
                        switch (resultProperty.PropertyType.Name)
                        {
                        case "Int32":
                            int integerValue = 0;
                            int.TryParse(resultProperty.GetValue(this, null).ToString(), out integerValue);
                            cs.SetField(resultProperty.Name, integerValue.ToString());
                            break;

                        case "Boolean":
                            bool booleanValue = false;
                            bool.TryParse(resultProperty.GetValue(this, null).ToString(), out booleanValue);
                            cs.SetField(resultProperty.Name, booleanValue.ToString());
                            break;

                        case "DateTime":
                            System.DateTime dateValue = default(System.DateTime);
                            System.DateTime.TryParse(resultProperty.GetValue(this, null).ToString(), out dateValue);
                            cs.SetField(resultProperty.Name, dateValue.ToString());
                            break;

                        case "Double":
                            double doubleValue = 0;
                            double.TryParse(resultProperty.GetValue(this, null).ToString(), out doubleValue);
                            cs.SetField(resultProperty.Name, doubleValue.ToString());
                            break;

                        default:
                            string stringValue = resultProperty.GetValue(this, null).ToString();
                            cs.SetField(resultProperty.Name, stringValue);
                            break;
                        }
                        break;
                    }
                }
                cs.Close();
            }
            catch (Exception ex)
            {
                cp.Site.ErrorReport(ex);
                throw;
            }
            return(id);
        }
 //
 //-------------------------------------------------
 // initialize
 //  read the report and column settings from the Db
 //  if no localGuid set, sync to Db does not work
 //  if the report does not exist in teh Db, use the input values
 //-------------------------------------------------
 //
 private void reportDbInit(CPBaseClass cp)
 {
     try {
         int    colPtr;
         string colName;
         string colCaption;
         string colSortOrder;
         string colCaptionClass;
         string colCellClass;
         bool   colSortable     = false;
         bool   colVisible      = true;
         bool   colDownloadable = true;
         string textVisible     = "";
         //string textDownloadable = "";
         CPCSBaseClass cs = cp.CSNew();
         int           reportId;
         string        sqlCriteria;
         //
         if (localGuid != "")
         {
             sqlCriteria = "ccguid=" + cp.Db.EncodeSQLText(localGuid);
             if (!cs.Open("Admin Framework Reports", sqlCriteria, "", true, "", 9999, 1))
             {
                 cs.Close();
                 if (localName == "")
                 {
                     localName = localTitle;
                 }
                 cs.Insert("Admin Framework reports");
                 cs.SetField("ccguid", localGuid);
                 cs.SetField("name", localName);
                 cs.SetField("title", localTitle);
                 //cs.SetField("description", localDescription);
             }
             reportId   = cs.GetInteger("id");
             localName  = cs.GetText("name");
             localTitle = cs.GetText("title");
             //localDescription = cs.GetText("description");
             // tmp solution for reports created with a name and no title
             if ((localTitle == "") && (localName != ""))
             {
                 localTitle = localName;
             }
             cs.Close();
             //
             //
             for (colPtr = 0; colPtr <= columnMax; colPtr++)
             {
                 colCaption      = columns[colPtr].caption;
                 colName         = columns[colPtr].name;
                 colSortOrder    = (colPtr * 10).ToString();
                 colSortOrder    = colSortOrder.PadLeft(4 - colSortOrder.Length, '0');
                 colCaptionClass = columns[colPtr].captionClass;
                 colCellClass    = columns[colPtr].cellClass;
                 colSortable     = columns[colPtr].sortable; // not part of Db config
                 colVisible      = columns[colPtr].visible;
                 colDownloadable = columns[colPtr].downloadable;
                 if (colName == "")
                 {
                     colName = colCaption;
                 }
                 if ((colName != "") && (reportId != 0))
                 {
                     if (!cs.Open("Admin Framework Report Columns", "(reportId=" + reportId.ToString() + ")and(name=" + cp.Db.EncodeSQLText(colName) + ")", "id", true, "", 9999, 1))
                     {
                         cs.Close();
                         cs.Insert("Admin Framework Report Columns");
                         cs.SetField("reportId", reportId.ToString());
                         cs.SetField("name", colName);
                         cs.SetField("caption", colCaption);
                         cs.SetField("sortOrder", colSortOrder);
                         cs.SetField("captionClass", colCaptionClass);
                         cs.SetField("cellClass", colCellClass);
                         cs.SetField("visible", colVisible.ToString());
                         // for another day
                         //cs.SetField("downloadable", colDownloadable.ToString());
                     }
                     else
                     {
                         // tmp - if name but not caption, use the other
                         colCaption = cs.GetText("caption");
                         colName    = cs.GetText("name");
                         if (colCaption == "")
                         {
                             colCaption = colName;
                         }
                         else if (colName == "")
                         {
                             colName = colCaption;
                         }
                         columns[colPtr].name         = colName;
                         columns[colPtr].caption      = colCaption;
                         columns[colPtr].captionClass = cs.GetText("captionClass");
                         columns[colPtr].cellClass    = cs.GetText("cellClass");
                         textVisible = cs.GetText("visible");
                         if (textVisible == "")
                         {
                             cs.SetField("visible", colVisible.ToString());
                         }
                         else
                         {
                             columns[colPtr].visible = cp.Utils.EncodeBoolean(textVisible);
                         }
                         // for another day
                         //textDownloadable = cs.GetText("downloadable");
                         //if (textDownloadable == "")
                         //{
                         //    cs.SetField("downloadable", textDownloadable.ToString());
                         //}
                         //else
                         //{
                         //    columns[colPtr].visible = cp.Utils.EncodeBoolean(textDownloadable);
                         //}
                     }
                     cs.Close();
                 }
             }
         }
     } catch (Exception ex) {
         cp.Site.ErrorReport(ex, "Exception in reportListClass.init");
     }
 }
Beispiel #28
0
        //
        // execute method is the only public
        //
        public override object Execute(Contensive.BaseClasses.CPBaseClass cp)
        {
            const string forumNotificationBody = ""
                                                 + "<h2>Forum Notification</h2>"
                                                 + "<p>The following forums have had changes over the past day.<p>"
                                                 + "";
            string        returnHtml = "";
            DateTime      dateLastEmail;
            DateTime      rightNow  = DateTime.Now;
            DateTime      today     = rightNow.Date;
            DateTime      yesterday = today.AddDays(-1);
            CPCSBaseClass cs        = cp.CSNew();
            int           memberId;
            bool          memberMatch;
            string        sqlCriteria        = "";
            string        forumIdChangedList = "";
            int           forumId;
            Hashtable     forumNamesRef = new Hashtable();
            string        emailBody     = "";
            string        sql;
            string        testSrc;
            int           testId           = 0;
            string        qs               = "";
            string        forumQs          = cp.Site.GetText("forum last display qs", "");
            string        sqlDateLastEmail = "";
            string        emailDomain      = cp.Site.DomainPrimary;

            //
            try
            {
                dateLastEmail = cp.Site.GetDate("Forums Notification Last Sent", yesterday.ToString());
                cp.Site.SetProperty("Forums Notification Last Sent", rightNow.ToString());
                sqlDateLastEmail = cp.Db.EncodeSQLDate(dateLastEmail);
                //
                // verify Forum Notification email
                //
                testId = cp.Content.GetRecordID("system email", "Forum Notification");
                if (testId == 0)
                {
                    if (emailDomain.IndexOf(".") < 0)
                    {
                        emailDomain = "kma.net";
                    }
                    cs.Insert("system Email");
                    cs.SetField("name", "Forum Notification");
                    cs.SetField("subject", cp.Site.DomainPrimary + " Daily Forum Updates");
                    cs.SetField("fromAddress", "ForumNotification@" + emailDomain);
                    cs.SetField("copyFilename", forumNotificationBody);
                    cs.Close();
                }
                //
                // make a list of forums with changes
                //
                sql = "select distinct f.id as forumId,f.name as forumName"
                      + " from ((ccForums f"
                      + " left join ccforumThreads t on t.forumId=f.id)"
                      + " left join ccforumPosts p on p.threadid=t.id)"
                      + " where"
                      + " (t.dateAdded>" + sqlDateLastEmail + ")"
                      + " or(p.dateAdded>" + sqlDateLastEmail + ")"
                      + " order by f.id";
                cs.OpenSQL(sql);
                while (cs.OK())
                {
                    forumId = cs.GetInteger("forumId");
                    testSrc = "," + forumIdChangedList + ",";
                    if (testSrc.IndexOf("," + forumId.ToString() + ",") < 0)
                    {
                        forumIdChangedList += "," + forumId;
                        sqlCriteria        += "or(forumId=" + forumId + ")";
                        forumNamesRef.Add(forumId, cs.GetText("forumName"));
                    }
                    cs.GoNext();
                }
                cs.Close();
                //
                // check for people who want notifications for these forums
                //
                if (sqlCriteria != "")
                {
                    sqlCriteria = "(" + sqlCriteria.Substring(2) + ")";
                    if (cs.Open("forum notification rules", sqlCriteria, "memberId,forumId", true, "memberId,forumId", 999, 1))
                    {
                        do
                        {
                            //
                            // send this member a list of forums that changed and are on his list
                            //
                            memberId  = cs.GetInteger("memberId");
                            emailBody = "";
                            do
                            {
                                memberMatch = (memberId == cs.GetInteger("memberId"));
                                if (memberMatch)
                                {
                                    forumId = cs.GetInteger("forumId");
                                    testSrc = "," + forumIdChangedList + ",";
                                    if (testSrc.IndexOf("," + forumIdChangedList.ToString() + ",") >= 0)
                                    {
                                        qs         = cp.Utils.ModifyQueryString(forumQs, "forumId", forumId.ToString(), true);
                                        emailBody += "<li><a href=\"http://" + cp.Site.DomainPrimary + cp.Site.AppRootPath + cp.Site.PageDefault + "?" + qs + "\">" + forumNamesRef[forumId].ToString() + "</a></li>";
                                    }
                                    cs.GoNext();
                                }
                            }while (cs.OK() && memberMatch);
                            if (emailBody != "")
                            {
                                emailBody = "<ul>" + emailBody + "</ul>";
                                cp.Email.sendSystem("Forum Notification", emailBody, memberId);
                            }
                        }while (cs.OK());
                    }
                }
            }
            catch (Exception ex)
            {
                errorReport(cp, ex, "execute");
            }
            return(returnHtml);
        }
Beispiel #29
0
        //
        // ===============================================================================================
        // performs all housekeeping when a post record is changed (add,mod,del)
        // ===============================================================================================
        //
        public override object Execute(Contensive.BaseClasses.CPBaseClass cp)
        {
            //int sourceFormId = 0;
            //int formId = 0;
            //int forumId = 0;
            int           threadId = 0;
            int           postId   = 0;
            string        s        = "";
            string        sql      = "";
            CPCSBaseClass cs       = cp.CSNew();

            //
            postId = cp.Utils.EncodeInteger(cp.Doc.GetProperty("recordId", ""));
            if (postId == 0)
            {
                //
                // re count posts for all threads
                //
                sql = "select ccforumThreads.id as threadId"
                      + ",(select count(p.id) from ccforumPosts p where p.threadId=ccforumThreads.id) as postCnt"
                      + ",(select max(p.id) from ccforumPosts p where p.threadId=ccforumThreads.id) as lastPostId"
                      + " from ccforumThreads"
                      + "";
            }
            else
            {
                //
                // recount posts for just the thread effected
                //
                sql = "select ccforumThreads.id as threadId"
                      + ",(select count(p.id) from ccforumPosts p where p.threadId=ccforumThreads.id) as postCnt"
                      + ",(select max(p.id) from ccforumPosts p where p.threadId=ccforumThreads.id) as lastPostId"
                      + " from ccforumThreads"
                      + " where ccforumThreads.id in (select threadid from ccforumPosts where id=" + postId + ")"
                      + "";
            }
            if (cs.OpenSQL2(sql, "", 1000, 1))
            {
                threadId = cs.GetInteger("threadId");
                while (cs.OK())
                {
                    sql = "update ccforumthreads"
                          + " set replyCnt=" + cs.GetInteger("postCnt") + ""
                          + ",lastPostId=" + cs.GetInteger("lastPostId") + ""
                          + " where id=" + cs.GetInteger("threadId");
                    cp.Db.ExecuteSQL(sql, "", "1", "1", "1");
                    cs.GoNext();
                }
                if (postId != 0)
                {
                    //
                    // this only affected one post, so only housekeep one thread
                    //
                    cp.Doc.SetProperty("recordId", threadId.ToString());
                }
            }
            cs.Close();
            //
            // this effects lastPostId, so housekeep threads also
            //
            threadHousekeepClass threadHousekeep = new threadHousekeepClass();

            threadHousekeep.Execute(cp);
            //
            return(s);
        }
 //====================================================================================================
 /// <summary>
 /// load a feature from the current row of a contentSet
 /// </summary>
 /// <param name="CP"></param>
 /// <param name="csFeature"></param>
 /// <returns></returns>
 public portalFeatureDataClass loadPortalFeatureFromCs(CPBaseClass CP, CPCSBaseClass csFeature)
 {
     portalFeatureDataClass feature = new portalFeatureDataClass();
     try
     {
         CPCSBaseClass cs2 = CP.CSNew();
         //
         feature.id = csFeature.GetInteger("id");
         feature.name = csFeature.GetText("name");
         feature.heading = csFeature.GetText("heading");
         feature.sortOrder = csFeature.GetText("sortOrder");
         feature.addPadding = csFeature.GetBoolean("addPadding");
         if (string.IsNullOrEmpty(feature.heading))
         {
             feature.heading = feature.name;
         }
         feature.guid = csFeature.GetText("ccguid");
         if (string.IsNullOrEmpty(feature.guid))
         {
             feature.guid = CP.Utils.CreateGuid();
             csFeature.SetField("ccguid", feature.guid);
         }
         //
         feature.addonId = csFeature.GetInteger("addonId");
         if (feature.addonId != 0)
         {
             if (cs2.Open("add-ons", "id=" + feature.addonId))
             {
                 feature.addonGuid = cs2.GetText("ccguid");
                 if (string.IsNullOrEmpty(feature.addonGuid))
                 {
                     feature.addonGuid = CP.Utils.CreateGuid();
                     cs2.SetField("ccguid", feature.addonGuid);
                 }
             }
             cs2.Close();
         }
         //
         feature.dataContentId = csFeature.GetInteger("dataContentId");
         if (feature.dataContentId != 0)
         {
             if (cs2.Open("content", "id=" + feature.dataContentId))
             {
                 feature.dataContentGuid = cs2.GetText("ccguid");
                 if (string.IsNullOrEmpty(feature.dataContentGuid))
                 {
                     feature.dataContentGuid = CP.Utils.CreateGuid();
                     cs2.SetField("ccguild", feature.dataContentGuid);
                 }
             }
             cs2.Close();
         }
         //
         feature.parentFeatureId = csFeature.GetInteger("parentFeatureId");
         if (feature.parentFeatureId != 0)
         {
             if (cs2.Open("portal features", "id=" + feature.parentFeatureId))
             {
                 feature.parentFeatureGuid = cs2.GetText("ccguid");
                 if (string.IsNullOrEmpty(feature.parentFeatureGuid))
                 {
                     feature.parentFeatureGuid = CP.Utils.CreateGuid();
                     cs2.SetField("ccguid", feature.parentFeatureGuid);
                 }
             }
             cs2.Close();
         }
         //
     }
     catch (Exception ex)
     {
         CP.Site.ErrorReport(ex, "exception in loadPortal");
     }
     return feature;
 }
Beispiel #31
0
 //
 //=========================================================================
 //  getFormField, variation
 //=========================================================================
 //
 public static string getFormField(CPBaseClass cp, CPCSBaseClass cs, string fieldName)
 {
     return getFormField(cp, cs, fieldName, fieldName);
 }
        //
        //-------------------------------------------------
        // getResult
        //-------------------------------------------------
        //
        public string getHtml(CPBaseClass cp)
        {
            StringBuilder s              = new StringBuilder("");
            string        row            = "";
            StringBuilder rowList        = new StringBuilder("");
            int           rowPtr         = 0;
            int           colPtr         = 0;
            int           colPtrDownload = 0;
            string        styleClass;
            string        content;
            string        userErrors;
            string        sortLink;
            string        columnSort         = cp.Doc.GetText("columnSort");
            string        sortField          = "";
            string        csvDownloadContent = "";
            DateTime      rightNow           = DateTime.Now;

            //
            // initialize - setup Db and/or read Db values
            //
            reportDbInit(cp);
            //
            if (!localFrameRqsSet)
            {
                refreshQueryString = cp.Doc.RefreshQueryString;
            }
            if (!localFormActionQueryStringSet)
            {
                // set locals not public property bc public also sets the includeForm
                localFormActionQueryString    = localFrameRqs;
                localFormActionQueryStringSet = true;
                //formActionQueryString = localFrameRqs;
            }
            //
            // add user errors
            //
            userErrors = cp.Utils.EncodeText(cp.UserError.GetList());
            if (userErrors != "")
            {
                warning = userErrors;
            }
            //
            // headers
            //
            if (formIncludeHeader)
            {
                rowList = new StringBuilder("");
                for (colPtr = 0; colPtr <= columnMax; colPtr++)
                {
                    if (columns[colPtr].visible)
                    {
                        styleClass = columns[colPtr].captionClass;
                        if (styleClass != "")
                        {
                            styleClass = " class=\"" + styleClass + "\"";
                        }
                        content   = columns[colPtr].caption;
                        sortField = columns[colPtr].name;
                        if (content == "")
                        {
                            content = "&nbsp;";
                        }
                        else if (columns[colPtr].sortable)
                        {
                            if (localFrameRqsSet)
                            {
                                sortLink = "?" + localFrameRqs + "&columnSort=" + sortField;
                            }
                            else
                            {
                                sortLink = "?" + cp.Doc.RefreshQueryString + "&columnSort=" + sortField;
                            }
                            if (columnSort == sortField)
                            {
                                sortLink += "Desc";
                            }
                            content = "<a href=\"" + sortLink + "\">" + content + "</a>";
                        }
                        rowList.Append(cr + "<th" + styleClass + ">" + content + "</th>");
                    }
                }
                s.Append(""
                         + cr + "<thead>"
                         + cr2 + "<tr>"
                         + indent(indent(rowList.ToString()))
                         + cr2 + "</tr>"
                         + cr + "</thead>"
                         + "");
                if (addCsvDownloadCurrentPage)
                {
                    colPtrDownload = 0;
                    for (colPtr = 0; colPtr <= columnMax; colPtr++)
                    {
                        if (columns[colPtr].downloadable)
                        {
                            if (colPtrDownload == 0)
                            {
                                csvDownloadContent += "\"" + columns[colPtr].caption.Replace("\"", "\"\"") + "\"";
                            }
                            else
                            {
                                csvDownloadContent += ",\"" + columns[colPtr].caption.Replace("\"", "\"\"") + "\"";
                            }
                            colPtrDownload += 1;
                        }
                    }
                }
            }
            //
            // body
            //
            rowList = new StringBuilder("");
            if (localIsEmptyReport)
            {
                styleClass = columns[0].cellClass;
                if (styleClass != "")
                {
                    styleClass = " class=\"" + styleClass + "\"";
                }
                row = cr + "<td style=\"text-align:left\" " + styleClass + " colspan=\"" + (columnMax + 1) + "\">[empty]</td>";
                rowList.Append(""
                               + cr + "<tr>"
                               + indent(row)
                               + cr + "</tr>");
            }
            else if (ReportTooLong)
            {
                // -- report is too long
                styleClass = columns[0].cellClass;
                if (styleClass != "")
                {
                    styleClass = " class=\"" + styleClass + "\"";
                }
                row = cr + "<td style=\"text-align:left\" " + styleClass + " colspan=\"" + (columnMax + 1) + "\">There are too many rows in this report. Please consider filtering the data.</td>";
                rowList.Append(""
                               + cr + "<tr>"
                               + indent(row)
                               + cr + "</tr>");
            }
            else
            {
                // -- display th report
                for (rowPtr = 0; rowPtr <= rowCnt; rowPtr++)
                {
                    row            = "";
                    colPtrDownload = 0;
                    for (colPtr = 0; colPtr <= columnMax; colPtr++)
                    {
                        styleClass = columns[colPtr].cellClass;
                        if (columns[colPtr].visible)
                        {
                            if (styleClass != "")
                            {
                                styleClass = " class=\"" + styleClass + "\"";
                            }
                            row += cr + "<td" + styleClass + ">" + localReportCells[rowPtr, colPtr] + "</td>";
                        }
                        if (addCsvDownloadCurrentPage && !localExcludeRowFromDownload[rowPtr])
                        {
                            if (columns[colPtr].downloadable)
                            {
                                if (colPtrDownload == 0)
                                {
                                    csvDownloadContent += Environment.NewLine;
                                }
                                else
                                {
                                    csvDownloadContent += ",";
                                }
                                if (!string.IsNullOrEmpty(localDownloadData[rowPtr, colPtr]))
                                {
                                    csvDownloadContent += "\"" + localDownloadData[rowPtr, colPtr].Replace("\"", "\"\"") + "\"";
                                }
                                colPtrDownload += 1;
                            }
                        }
                    }
                    styleClass = localRowClasses[rowPtr];
                    if (rowPtr % 2 != 0)
                    {
                        styleClass += " afwOdd";
                    }
                    if (styleClass != "")
                    {
                        styleClass = " class=\"" + styleClass + "\"";
                    }
                    rowList.Append(""
                                   + cr + "<tr" + styleClass + ">"
                                   + indent(row)
                                   + cr + "</tr>");
                }
            }
            string csvDownloadFilename = string.Empty;

            if (addCsvDownloadCurrentPage)
            {
                //
                // todo implement cp.db.CreateCsv()
                // 5.1 -- download
                CPCSBaseClass csDownloads = cp.CSNew();
                if (csDownloads.Insert("downloads"))
                {
                    csvDownloadFilename = csDownloads.GetFilename("filename", "export.csv");
                    cp.CdnFiles.Save(csvDownloadFilename, csvDownloadContent);
                    csDownloads.SetField("name", "Download for [" + localTitle + "], requested by [" + cp.User.Name + "]");
                    csDownloads.SetField("requestedBy", cp.User.Id.ToString());
                    csDownloads.SetField("filename", csvDownloadFilename);
                    csDownloads.SetField("dateRequested", DateTime.Now.ToString());
                    csDownloads.SetField("datecompleted", DateTime.Now.ToString());
                    csDownloads.SetField("resultmessage", "Completed");
                    csDownloads.Save();
                }
                csDownloads.Close();
            }
            s.Append(""
                     + cr + "<tbody>"
                     + indent(rowList.ToString())
                     + cr + "</tbody>"
                     + "");
            s = new StringBuilder(""
                                  + cr + "<table class=\"afwListReportTable\">"
                                  + indent(s.ToString())
                                  + cr + "</table>");
            if (localHtmlLeftOfTable != "")
            {
                s = new StringBuilder(""
                                      + cr + "<div class=\"afwLeftSideHtml\">"
                                      + indent(localHtmlLeftOfTable)
                                      + cr + "</div>"
                                      + cr + "<div class=\"afwRightSideHtml\">"
                                      + indent(s.ToString())
                                      + cr + "</div>"
                                      + cr + "<div style=\"clear:both\"></div>"
                                      + "");
            }
            if (localHtmlBeforeTable != "")
            {
                s = new StringBuilder(""
                                      + localHtmlBeforeTable
                                      + s.ToString()
                                      + "");
            }
            if (localHtmlAfterTable != "")
            {
                s.Append(localHtmlAfterTable);
            }
            //
            // headers
            //
            if (addCsvDownloadCurrentPage && (!string.IsNullOrEmpty(csvDownloadFilename)))
            {
                s = new StringBuilder(cr + "<p id=\"afwDescription\"><a href=\"" + cp.Site.FilePath + csvDownloadFilename + "\">Click here</a> to download the data.</p>" + s.ToString());
            }
            if (localDescription != "")
            {
                s = new StringBuilder(cr + "<p id=\"afwDescription\">" + localDescription + "</p>" + s.ToString());
            }
            if (localWarning != "")
            {
                s = new StringBuilder(cr + "<div id=\"afwWarning\">" + localWarning + "</div>" + s.ToString());
            }
            if (localTitle != "")
            {
                s = new StringBuilder(cr + "<h2 id=\"afwTitle\">" + localTitle + "</h2>" + s.ToString());
            }
            //
            // add form
            //
            if (localIncludeForm)
            {
                if (localButtonList != "")
                {
                    localButtonList = ""
                                      + cr + "<div class=\"afwButtonCon\">"
                                      + indent(localButtonList)
                                      + cr + "</div>";
                }
                s = new StringBuilder(cr + cp.Html.Form(localButtonList + s.ToString() + localButtonList + localHiddenList, "", "", "", localFormActionQueryString, ""));
                //body = ""
                //    + cr + cp.Html.Form( localButtonList + body + localHiddenList )
                //    + cr + "<form action=\"" + localFormAction + "\" method=\"post\" enctype=\"MULTIPART/FORM-DATA\">"
                //    + indent(localButtonList + body + localHiddenList)
                //    + cr + "</form>";
            }
            if (_includeBodyPadding)
            {
                s = new StringBuilder(cp.Html.div(s.ToString(), "", "afwBodyPad", ""));
            }
            if (_includeBodyColor)
            {
                s = new StringBuilder(cp.Html.div(s.ToString(), "", "afwBodyColor", ""));
            }
            //
            // if outer container, add styles and javascript
            //
            if (localIsOuterContainer)
            {
                //cp.Doc.AddHeadJavascript(Properties.Resources.javascript);
                //cp.Doc.AddHeadStyle(Properties.Resources.styles);
                s = new StringBuilder(""
                                      + cr + "<div id=\"afw\">"
                                      + indent(s.ToString())
                                      + cr + "</div>");
            }
            return(s.ToString());
        }
Beispiel #33
0
        //
        //====================================================================================================
        /// <summary>
        /// render the report
        /// </summary>
        /// <param name="cp"></param>
        /// <returns></returns>
        public string getHtml(CPBaseClass cp)
        {
            StringBuilder rowBuilder = new StringBuilder("");
            //string classAttribute;
            //string content;
            //string userErrors;
            string   sortLink;
            string   columnSort         = cp.Doc.GetText("columnSort");
            string   csvDownloadContent = "";
            DateTime rightNow           = DateTime.Now;

            //
            if (!localFrameRqsSet)
            {
                refreshQueryString = cp.Doc.RefreshQueryString;
            }
            if (!localFormActionQueryStringSet)
            {
                // set locals not public property bc public also sets the includeForm
                localFormActionQueryString    = localFrameRqs;
                localFormActionQueryStringSet = true;
                //formActionQueryString = localFrameRqs;
            }
            //
            // add user errors
            //
            string userErrors = cp.Utils.EncodeText(cp.UserError.GetList());

            if (!string.IsNullOrEmpty(userErrors))
            {
                warning = userErrors;
            }
            int           colPtr;
            int           colPtrDownload;
            StringBuilder result = new StringBuilder("");

            //
            // headers
            //
            if (captionIncluded)
            {
                rowBuilder = new StringBuilder("");
                for (colPtr = 0; colPtr <= columnMax; colPtr++)
                {
                    if (columns[colPtr].visible)
                    {
                        string classAttribute = columns[colPtr].captionClass;
                        if (classAttribute != "")
                        {
                            classAttribute = " class=\"" + classAttribute + "\"";
                        }
                        string content   = columns[colPtr].caption;
                        string sortField = columns[colPtr].name;
                        if (content == "")
                        {
                            content = "&nbsp;";
                        }
                        else if (columns[colPtr].sortable)
                        {
                            if (localFrameRqsSet)
                            {
                                sortLink = "?" + localFrameRqs + "&columnSort=" + sortField;
                            }
                            else
                            {
                                sortLink = "?" + cp.Doc.RefreshQueryString + "&columnSort=" + sortField;
                            }
                            if (columnSort == sortField)
                            {
                                sortLink += "Desc";
                            }
                            content = "<a href=\"" + sortLink + "\">" + content + "</a>";
                        }
                        string styleAttribute = "";
                        if (columns[colPtr].columnWidthPercent > 0)
                        {
                            styleAttribute = " style=\"width:" + columns[colPtr].columnWidthPercent.ToString() + "%;\"";
                        }
                        //row += Constants.cr + "<td" + classAttribute + styleAttribute + ">" + localReportCells[rowPtr, colPtr] + "</td>";
                        rowBuilder.Append(Constants.cr + "<th" + classAttribute + styleAttribute + ">" + content + "</th>");
                    }
                }
                result.Append(""
                              + Constants.cr + "<thead>"
                              + Constants.cr2 + "<tr>"
                              + indent(indent(rowBuilder.ToString()))
                              + Constants.cr2 + "</tr>"
                              + Constants.cr + "</thead>"
                              + "");
                if (addCsvDownloadCurrentPage)
                {
                    colPtrDownload = 0;
                    for (colPtr = 0; colPtr <= columnMax; colPtr++)
                    {
                        if (columns[colPtr].downloadable)
                        {
                            if (colPtrDownload == 0)
                            {
                                csvDownloadContent += "\"" + columns[colPtr].caption.Replace("\"", "\"\"") + "\"";
                            }
                            else
                            {
                                csvDownloadContent += ",\"" + columns[colPtr].caption.Replace("\"", "\"\"") + "\"";
                            }
                            colPtrDownload += 1;
                        }
                    }
                }
            }
            //
            // body
            //
            rowBuilder = new StringBuilder("");
            if (localIsEmptyReport)
            {
                string classAttribute = columns[0].cellClass;
                if (classAttribute != "")
                {
                    classAttribute = " class=\"" + classAttribute + "\"";
                }
                //row = Constants.cr + "<td style=\"text-align:left\" " + classAttribute + " colspan=\"" + (columnMax + 1) + "\">[empty]</td>";
                rowBuilder.Append(""
                                  + Constants.cr + "<tr>"
                                  + Constants.cr + "<td style=\"text-align:left\" " + classAttribute + " colspan=\"" + (columnMax + 1) + "\">[empty]</td>"
                                  + Constants.cr + "</tr>");
            }
            else if (ReportTooLong)
            {
                // -- report is too long
                string classAttribute = columns[0].cellClass;
                if (classAttribute != "")
                {
                    classAttribute = " class=\"" + classAttribute + "\"";
                }
                //row = Constants.cr + "<td style=\"text-align:left\" " + classAttribute + " colspan=\"" + (columnMax + 1) + "\">There are too many rows in this report. Please consider filtering the data.</td>";
                rowBuilder.Append(""
                                  + Constants.cr + "<tr>"
                                  + Constants.cr + "<td style=\"text-align:left\" " + classAttribute + " colspan=\"" + (columnMax + 1) + "\">There are too many rows in this report. Please consider filtering the data.</td>"
                                  + Constants.cr + "</tr>");
            }
            else
            {
                // -- display th report
                for (int rowPtr = 0; rowPtr <= rowCnt; rowPtr++)
                {
                    string row = "";
                    colPtrDownload = 0;
                    int colVisibleCnt = 0;
                    for (colPtr = 0; colPtr <= columnMax; colPtr++)
                    {
                        if (columns[colPtr].visible)
                        {
                            colVisibleCnt++;
                            string classAttribute2 = columns[colPtr].cellClass;
                            if (!string.IsNullOrEmpty(classAttribute2))
                            {
                                classAttribute2 = " class=\"" + classAttribute2 + "\"";
                            }
                            string rowContent = localReportCells[rowPtr, colPtr];
                            if ((colVisibleCnt == 1) && rowEllipseMenuDict.ContainsKey(rowPtr))
                            {
                                //
                                // -- add ellipse menu
                                EllipseMenuDataModel ellipseMenu = new EllipseMenuDataModel {
                                    menuId   = rowPtr,
                                    content  = rowContent,
                                    hasMenu  = true,
                                    menuList = new List <EllipseMenuDataItemModel>()
                                };
                                foreach (var menuItem in rowEllipseMenuDict[rowPtr])
                                {
                                    ellipseMenu.menuList.Add(new EllipseMenuDataItemModel {
                                        menuName = menuItem.name,
                                        menuHref = menuItem.url
                                    });
                                }
                                rowContent = cp.Mustache.Render(Properties.Resources.ellipseMenu, ellipseMenu);
                            }
                            row += Constants.cr + "<td" + classAttribute2 + ">" + rowContent + "</td>";
                        }
                        if (addCsvDownloadCurrentPage && !localExcludeRowFromDownload[rowPtr])
                        {
                            if (columns[colPtr].downloadable)
                            {
                                if (colPtrDownload == 0)
                                {
                                    csvDownloadContent += Environment.NewLine;
                                }
                                else
                                {
                                    csvDownloadContent += ",";
                                }
                                if (!string.IsNullOrEmpty(localDownloadData[rowPtr, colPtr]))
                                {
                                    csvDownloadContent += "\"" + localDownloadData[rowPtr, colPtr].Replace("\"", "\"\"") + "\"";
                                }
                                colPtrDownload += 1;
                            }
                        }
                    }
                    string classAttribute = localRowClasses[rowPtr];
                    if (rowPtr % 2 != 0)
                    {
                        classAttribute += " afwOdd";
                    }
                    if (classAttribute != "")
                    {
                        classAttribute = " class=\"" + classAttribute + "\"";
                    }
                    rowBuilder.Append(""
                                      + Constants.cr + "<tr" + classAttribute + ">"
                                      + indent(row)
                                      + Constants.cr + "</tr>");
                }
            }
            string csvDownloadFilename = string.Empty;

            if (addCsvDownloadCurrentPage)
            {
                //
                // todo implement cp.db.CreateCsv()
                // 5.1 -- download
                CPCSBaseClass csDownloads = cp.CSNew();
                if (csDownloads.Insert("downloads"))
                {
                    csvDownloadFilename = csDownloads.GetFilename("filename", "export.csv");
                    cp.CdnFiles.Save(csvDownloadFilename, csvDownloadContent);
                    csDownloads.SetField("name", "Download for [" + title + "], requested by [" + cp.User.Name + "]");
                    csDownloads.SetField("requestedBy", cp.User.Id.ToString());
                    csDownloads.SetField("filename", csvDownloadFilename);
                    csDownloads.SetField("dateRequested", DateTime.Now.ToString());
                    csDownloads.SetField("datecompleted", DateTime.Now.ToString());
                    csDownloads.SetField("resultmessage", "Completed");
                    csDownloads.Save();
                }
                csDownloads.Close();
            }
            result.Append(""
                          + Constants.cr + "<tbody>"
                          + indent(rowBuilder.ToString())
                          + Constants.cr + "</tbody>"
                          + "");
            result = new StringBuilder(Constants.cr + "<table class=\"afwListReportTable\">" + indent(result.ToString()) + Constants.cr + "</table>");
            if (htmlLeftOfTable != "")
            {
                result = new StringBuilder(""
                                           + Constants.cr + "<div class=\"afwLeftSideHtml\">" + indent(htmlLeftOfTable) + Constants.cr + "</div>"
                                           + Constants.cr + "<div class=\"afwRightSideHtml\">" + indent(result.ToString()) + Constants.cr + "</div>"
                                           + Constants.cr + "<div style=\"clear:both\"></div>"
                                           + "");
            }
            if (htmlBeforeTable != "")
            {
                result.Insert(0, "<div class=\"afwBeforeHtml\">" + htmlBeforeTable + "</div>");
            }
            if (htmlAfterTable != "")
            {
                result.Append("<div class=\"afwAfterHtml\">" + htmlAfterTable + "</div>");
            }
            //
            // headers
            //
            if (addCsvDownloadCurrentPage && (!string.IsNullOrEmpty(csvDownloadFilename)))
            {
                result = new StringBuilder(Constants.cr + "<p id=\"afwDescription\"><a href=\"" + cp.Http.CdnFilePathPrefix + csvDownloadFilename + "\">Click here</a> to download the data.</p>" + result.ToString());
            }
            if (description != "")
            {
                result = new StringBuilder(Constants.cr + "<p id=\"afwDescription\">" + description + "</p>" + result.ToString());
            }
            if (warning != "")
            {
                result = new StringBuilder(Constants.cr + "<div id=\"afwWarning\">" + warning + "</div>" + result.ToString());
            }
            if (title != "")
            {
                result = new StringBuilder(Constants.cr + "<h2 id=\"afwTitle\">" + title + "</h2>" + result.ToString());
            }
            //
            // add form
            //
            if (localIncludeForm)
            {
                if (localButtonList != "")
                {
                    localButtonList = ""
                                      + Constants.cr + "<div class=\"afwButtonCon\">"
                                      + indent(localButtonList)
                                      + Constants.cr + "</div>";
                }
                result = new StringBuilder(Constants.cr + cp.Html.Form(localButtonList + result.ToString() + localButtonList + localHiddenList, "", "", "", localFormActionQueryString, ""));
            }
            if (_includeBodyPadding)
            {
                result = new StringBuilder(cp.Html.div(result.ToString(), "", "afwBodyPad", ""));
            }
            ;
            if (_includeBodyColor)
            {
                result = new StringBuilder(cp.Html.div(result.ToString(), "", "afwBodyColor", ""));
            }
            ;
            //
            // if outer container, add styles and javascript
            //
            if (localIsOuterContainer)
            {
                cp.Doc.AddHeadJavascript(Properties.Resources.javascript);
                cp.Doc.AddHeadStyle(Properties.Resources.styles);
                result = new StringBuilder(""
                                           + Constants.cr + "<div id=\"afw\">"
                                           + indent(result.ToString())
                                           + Constants.cr + "</div>");
            }
            //
            // -- set the optional title of the portal subnav
            if (!string.IsNullOrEmpty(portalSubNavTitle))
            {
                cp.Doc.SetProperty("portalSubNavTitle", portalSubNavTitle);
            }
            return(result.ToString());
        }