function delete_category($id, $delete_children)
{
    $cids = array();
    if ($delete_children === 'yes') {
        $category = new CODOF\Forum\Category(\DB::getPDO());
        $cats_tree = $category->generate_tree($category->get_categories());
        $children = $category->get_sub_categories($cats_tree, $id);
        $cids = get_cids($children);
        if ($cids !== NULL) {
            DB::table(PREFIX . 'codo_categories')->whereIn('cat_id', $cids)->delete();
        } else {
            $cids = array();
        }
    } else {
        DB::table(PREFIX . 'codo_categories')->where('cat_pid', '=', $id)->update(array('cat_pid' => 0));
    }
    DB::table(PREFIX . 'codo_categories')->where('cat_id', $id)->delete();
    //delete all topics
    if ($delete_children !== 'yes') {
        $ids = array($id);
    } else {
        $ids = array_merge(array($id), $cids);
    }
    DB::table(PREFIX . 'codo_topics')->whereIn('cat_id', $ids)->delete();
    DB::table(PREFIX . 'codo_unread_topics')->whereIn('cat_id', $ids)->delete();
    DB::table(PREFIX . 'codo_unread_categories')->whereIn('cat_id', $ids)->delete();
    //DB::table(PREFIX . 'codo_tags AS g')
    //        ->join(PREFIX . 'codo_topics AS t', 't.topic_id', '=', 'g.topic_id')
    //        ->whereIn('t.cat_id', $ids)->delete();
    $q = 'DELETE codo_tags FROM ' . PREFIX . 'codo_tags ' . ' LEFT JOIN ' . PREFIX . 'codo_topics ON ' . PREFIX . 'codo_tags.topic_id=' . PREFIX . 'codo_topics.topic_id ' . ' WHERE ' . PREFIX . 'codo_topics.cat_id IN (' . implode(',', $ids) . ')';
    \DB::delete($q);
    DB::table(PREFIX . 'codo_notify_subscribers')->whereIn('cid', $ids)->delete();
    DB::table(PREFIX . 'codo_permissions')->whereIn('cid', $ids)->delete();
    $qry = 'UPDATE ' . PREFIX . 'codo_users AS u,' . PREFIX . 'codo_posts As p SET no_posts=no_posts-' . '(SELECT COUNT(post_id) FROM codo_posts WHERE cat_id=' . $id . ' AND post_status <> 0 AND uid=u.id) 
            WHERE p.cat_id=' . $id . ' AND u.id=p.uid';
    DB::getPDO()->query($qry);
    DB::table(PREFIX . 'codo_posts')->whereIn('cat_id', $ids)->delete();
}
Esempio n. 2
0
 public function topics($page)
 {
     $cat = new \CODOF\Forum\Category($this->db);
     $topic = new \CODOF\Forum\Topic($this->db);
     //gets category name and no of topics each hold
     $raw_cats = $cat->get_categories();
     $cats = $cat->generate_tree($raw_cats);
     //get complete list of topics
     $new_topics = array();
     if (\CODOF\User\CurrentUser\CurrentUser::loggedIn()) {
         $tracker = new \CODOF\Forum\Tracker($this->db);
         $new_topics = $tracker->get_new_topic_counts();
     }
     $this->smarty->assign('new_topics', $new_topics);
     //$cat->update_count($cats);
     $api = new Ajax\forum\topics();
     $num_topics_page = \CODOF\Util::get_opt('num_posts_all_topics');
     $data = $api->get_topics($num_topics_page * ($page - 1));
     $total_topics = $topic->get_total_num_topics();
     $this->smarty->assign('load_more_hidden', false);
     if ($page * $num_topics_page >= $total_topics) {
         $this->smarty->assign('load_more_hidden', true);
     }
     $user = \CODOF\User\User::get();
     $this->smarty->assign('can_search', $user->can('use search'));
     $this->smarty->assign('topics', \CODOF\HB\Render::tpl('forum/topics', $data));
     $this->smarty->assign('total_num_topics', $total_topics);
     $this->smarty->assign('cats', $cats);
     $this->smarty->assign('subcategory_dropdown', \CODOF\Util::get_opt('subcategory_dropdown'));
     $this->smarty->assign('num_posts_per_page', $num_topics_page);
     $this->smarty->assign('curr_page', $page);
     $this->css_files = array('topics');
     $this->js_files = array(array('topics/topics.js', array('type' => 'defer')));
     $this->view = 'forum/topics';
     \CODOF\Store::set('sub_title', _t('All topics'));
     $this->smarty->assign('can_delete', $user->can(array('delete my topics', 'delete all topics')));
     $this->smarty->assign('can_merge', $user->can('merge topics'));
     $this->smarty->assign('can_move', $user->can('move topics'));
     //var_dump($user->can('move topics'));
 }