// catch if delete is fail
        }
        $location = $_SERVER['HTTP_REFERER'];
        header("Location: {$location}");
        exit;
    }
} else {
    // When User wants to delete repllies of forum
    $mid = $_GET['mid'];
    $params['action'] = 'delete_rep';
    // fiding the parent for the replly
    $request_info = load_info();
    $msg = new MessageBoard();
    $rep_details = $msg->get_by_id($_REQUEST['mid']);
    $cond_array = array('boardmessage_id' => $request_info['parent_id']);
    $forum_detail = MessageBoard::get_forums($cond_array);
    $owner = Group::get_admin_id($_REQUEST['ccid']);
    $params['forum_owner'] = $forum_detail[0]->user_id;
    $params['rep_owner'] = $rep_details['user_id'];
    $params['group_owner'] = $owner['user_id'];
    if (user_can($params)) {
        try {
            MessageBoard::delete($mid);
        } catch (Exception $e) {
            // catch if delete is fail
        }
        $location = $_SERVER['HTTP_REFERER'];
        header("Location: {$location}");
        exit;
    }
}
 /**
  * function used to delete all the forum and replies given by a user.
  * if group_id is given then the forums of that particular group will be deleted
  * otherwise all forums related to that in all the groups will be deleted
  */
 public function delete_user_forums()
 {
     Logger::log("Enter: function MessageBoard::delete_user_forums");
     //$forums = MessageBoard::get_forums( $params );
     // delete replies posted by user
     Dal::query("DELETE FROM {boardmessages} WHERE user_id = {$this->user_id} AND parent_type = '" . PARENT_TYPE_MESSAGE . "'");
     //find threads
     //now we have only threads left
     $sql = "SELECT  boardmessage_id FROM {boardmessages} WHERE user_id = {$this->user_id} ";
     $res = Dal::query($sql);
     if ($res->numRows() > 0) {
         while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) {
             $pid = $row->boardmessage_id;
             MessageBoard::delete_replies($pid);
             //delete replies
             MessageBoard::delete($pid);
             //delete the board message itself
         }
     }
     Logger::log("Exit: function MessageBoard::delete_user_forums");
 }