Ejemplo n.º 1
0
 public function create()
 {
     if ($this->f3->exists('POST.name')) {
         if ($this->f3->get('POST.name') != '') {
             $uurl = toUrl($this->f3->get('POST.name'));
             //check if the category already exists
             //if not unique name
             $uname = new Cat($this->db);
             if ($uname->catcountByUrl($uurl) > 0) {
                 $this->f3->set('COOKIE.message', 'The category name already exists!');
                 $this->f3->set('COOKIE.messagetype', 'alert-danger hide10s');
                 $this->f3->reroute('/c');
             }
             //get unique tok
             $utok = new Cat($this->db);
             $randtok = rand(100000000, 999999999);
             while ($utok->catcountByTok($randtok) > 1) {
                 $randtok = rand(100000000, 999999999);
             }
             //variables
             $category = new Cat($this->db);
             $category->tok = $randtok;
             $category->url = toUrl($this->f3->get('POST.name'));
             $category->name = preg_replace('|[^0-9A-Za-z\\-\\/+]|', '', $this->f3->get('POST.name'));
             $category->add();
             $this->f3->set('COOKIE.message', 'Category was created');
             $this->f3->set('COOKIE.messagetype', 'alert-success hide5s');
             $this->f3->reroute('/c');
         } else {
             $this->f3->set('COOKIE.message', 'Category name cannot be empty!');
             $this->f3->set('COOKIE.messagetype', 'alert-error hide5s');
             $this->f3->reroute('/c');
         }
     }
 }