public function ins_topics($topic_info, $pid, $use_passed_pid)
 {
     $cats = array();
     $i = 0;
     $defs = array("last_post_id" => 0, "topic_updated" => 0);
     foreach ($topic_info as $cat) {
         $cats[$i] = $this->set_value($cat, $defs);
         $cats[$i] += $cat;
         //$cats[$i]['topic_id'] = $tid;
         if ($use_passed_pid) {
             $cats[$i]['post_id'] = ++$pid;
         }
         $cats[$i]['title'] = Format::title($cat['title']);
         //does all last post details exist ?
         if (\CODOF\Util::is_set($cat, array('last_post_id', 'last_post_uid', 'last_post_name', 'last_post_time'))) {
             //correct last post time
             if ($cat['last_post_time'] == null || $cat['last_post_time'] == 0) {
                 $cats[$i]['last_post_time'] = $cat['topic_created'];
             }
         } else {
             $cats[$i]['last_post_id'] = 0;
             $cats[$i]['last_post_uid'] = NULL;
             $cats[$i]['last_post_name'] = NULL;
             $cats[$i]['last_post_time'] = $cat['topic_created'];
         }
         if (isset($cat['no_views'])) {
             $cats[$i]['no_views'] = $cat['no_views'];
         } else {
             $cats[$i]['no_views'] = 0;
         }
         $i++;
     }
     // var_dump($cats);
     $attrs = array("topic_id", "title", "cat_id", "post_id", "uid", "last_post_id", "last_post_uid", "last_post_name", "topic_created", "topic_updated", "last_post_time", "no_views");
     $qry = $this->prepare_ins_qry($cats, $attrs, "codo_topics");
     $this->query .= $qry;
     return $pid;
 }
 public function register($do)
 {
     if (isset($_SESSION[UID . 'USER']['id'])) {
         header('Location: ' . \CODOF\User\User::getProfileUrl());
         exit;
     }
     $this->view = 'user/register';
     $set_fields = array('username', 'password', 'mail');
     $req_fields = array('username', 'password', 'mail');
     $this->js_files = array(array(DATA_PATH . 'assets/js/user/register.js', array('type' => 'defer')));
     if (\CODOF\Util::is_set($_REQUEST, $set_fields) && !\CODOF\Util::is_empty($_REQUEST, $req_fields) && $do) {
         $register = new \CODOF\User\Register($this->db);
         $register->username = str_replace('"', '"', $_REQUEST['username']);
         $register->name = null;
         //$_REQUEST['name'];
         $register->password = $_REQUEST["password"];
         $register->mail = $_REQUEST['mail'];
         $register->rid = ROLE_UNVERIFIED;
         $errors = $register->get_errors();
         if (empty($errors)) {
             $errors = $register->register_user();
             $register->login();
             header('Location: ' . \CODOF\User\User::getProfileUrl());
             exit;
         }
         $this->smarty->assign('errors', $errors);
     } else {
         $register = new \stdClass();
         $register->username = null;
         $register->name = null;
         //$_REQUEST['name'];
         $register->password = null;
         $register->mail = null;
     }
     if (\CODOF\Util::get_opt('captcha') == "enabled") {
         $publickey = \CODOF\Util::get_opt('captcha_public_key');
         // you got this from the signup page
         $this->smarty->assign('recaptcha', '<div class="g-recaptcha col-md-6" data-sitekey="' . $publickey . '"></div>');
         $this->js_files[] = array('https://www.google.com/recaptcha/api.js', array('type' => 'remote'));
     }
     $this->smarty->assign('min_pass_len', \CODOF\Util::get_opt('register_pass_min'));
     $this->smarty->assign('min_username_len', \CODOF\Util::get_opt('register_username_min'));
     $this->smarty->assign('register', $register);
     \CODOF\Store::set('sub_title', 'Register');
 }