Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        //
        // ===============================================================================================
        // process new thread form
        // ===============================================================================================
        //
        private int processNewThread(CPBaseClass cp, int forumId )
        {
            CPCSBaseClass cs = cp.CSNew();
            int nextFormId = formIdNewThread;
            string sql = "";
            int threadId = 0;
            int createKey = 0;
            bool blockForm = false;
            //
            if (cp.Doc.GetProperty(rnNewThreadThreadTitle, "") == "")
            {
                cp.UserError.Add("Your thread must include a subject.");
            }
            else if (cp.Doc.GetProperty(rnNewThreadPost, "") == "")
            {
                cp.UserError.Add("Your thread must have an initial post.");
            }
            else if (!cp.User.IsAuthenticated)
            {
                cp.UserError.Add("You must be logged in to create a thread.");
                nextFormId = formIdThreadList;
            }
            if (cp.UserError.OK())
            {
                //
                // test for re-submit
                //
                createKey = cp.Utils.EncodeInteger(cp.Doc.GetProperty(rnCreateKey, ""));
                if ( createKey != 0 )
                {
                    blockForm = cs.Open("forum threads", "createKey=" + createKey.ToString(),"",true,"",1,1);
                    cs.Close();

                }
                if (!blockForm)
                {
                    //
                    // save thread
                    //
                    cs.Insert("forum threads");
                    threadId = cs.GetInteger("id");
                    cs.SetField("createKey", createKey.ToString());
                    cs.SetFormInput("name", "foInputThreadTitle");
                    cs.SetFormInput("copy", "foTextAreaPost");
                    cs.SetField( "forumId", forumId.ToString());
                    cs.Close();
                    //
                    // save uploaded file
                    //
                    if (cp.Doc.GetProperty("foInputFile","") != "")
                    {
                        cs.Insert("forum files");
                        cs.SetFormInput("name", "foInputFile");
                        cs.SetFormInput("filename", "foInputFile");
                        cs.SetField( "forumThreadId", threadId.ToString());
                        cs.Close();
                    }
                    //
                    // housekeep the changes
                    //
                    cp.Doc.SetProperty("recordId", threadId.ToString());
                    threadHousekeepClass obj = new threadHousekeepClass();
                    obj.Execute( cp );
                }
                nextFormId = formIdThreadList;
            }
            sql = "select count(id) as cnt from ccforumThreads where forumid=" + forumId;
            if (cs.OpenSQL(sql))
            {
                cp.Db.ExecuteSQL("update ccforums set threads=" + cs.GetInteger("cnt").ToString() + " where id=" + forumId, "", "1", "1", "1");
            }
            cs.Close();
            //
            return nextFormId;
        }