/**
  * Saves thread if category_id is set
  * Saves reply if parent_message_id is set
  * Makes association of category-thread / message-reply
  * @access public
  * @param set_category_id(category_id),set_parent_message_id(parent_message_id) 
  */
 function save($uid = NULL, $is_insert = 1)
 {
     Logger::log("Enter: function MessageBoard::save");
     // validate $this->user_id
     if ($this->user_id < 1 && $this->user_id !== NULL) {
         throw new PAException(INVALID_ID, "MessageBoard::user_id variable must be either NULL or a valid user ID when posting.");
     }
     //exception if anything go wrong
     // anonymous user cant start a new thread
     if ($is_insert == 1) {
         if ($this->parent_type != PARENT_TYPE_MESSAGE) {
             if (!$this->user_id || $this->user_id == '-1') {
                 Logger::log(" Throwing exception USER_NOT_LOGGED_IN | Message: {$res->getMessage}()", LOGGER_ERROR);
                 throw new PAException(USER_NOT_LOGGED_IN, "Anonymous User cant start a thread");
             }
         } else {
             // anonymous user can reply only if allowed
             $check = MessageBoard::check_annonymous_allowed($this->parent_id);
             if (!$check && !$uid) {
                 Logger::log(" Throwing exception USER_NOT_LOGGED_IN | Message: {$res->getMessage}()", LOGGER_ERROR);
                 throw new PAException(USER_NOT_LOGGED_IN, "Anonymous user cant post a comment");
             }
         }
         //exception if anything go wrong EOF
         $this->created = time();
         $this->changed = $this->created;
         if ($this->user_id == '') {
             $this->user_id = ANONYMOUS_USER_ID;
         }
         $sql = " INSERT into {boardmessages} ( title, body, created, changed, user_id, allow_anonymous, user_name, email, homepage, parent_id, parent_type) values ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )";
         $data = array($this->title, $this->body, $this->created, $this->changed, $this->user_id, $this->allow_anonymous, $this->user_name, $this->email, $this->homepage, $this->parent_id, $this->parent_type);
         Dal::query($sql, $data);
         $insert_id = Dal::insert_id();
     } else {
         $this->changed = time();
         $sql = " UPDATE {boardmessages} set title =? , body =? ,changed=? , allow_anonymous = ? WHERE  boardmessage_id=?";
         $data = array($this->title, $this->body, $this->changed, $this->allow_anonymous, $this->boardmessage_id);
         Dal::query($sql, $data);
         $insert_id = $this->boardmessage_id;
     }
     return $insert_id;
     Logger::log("Exit: function MessageBoard::save");
 }