Advertisement
Ninja_community

Untitled

Oct 9th, 2019
1,009
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.06 KB | None | 0 0
  1. public function forumEditSelectNumbers($underCategory){
  2.         $this->isAdmin();
  3.        
  4.         $db = new DB();
  5.         $db -> query("SELECT id,kolejnosc FROM forums WHERE kat_id = :UnderCategory ORDER BY kolejnosc ASC");
  6.         $db -> bind(':UnderCategory', $underCategory);
  7.         return $db -> resultSet();
  8.     }
  9.    
  10.     public function categoryMakeSelectNumbers(){
  11.         $this->isAdmin();
  12.        
  13.         $db = new DB();
  14.         $db -> query("SELECT id,kolejnosc FROM forum_category ORDER BY kolejnosc ASC");
  15.         return $db -> resultSet();
  16.     }
  17.    
  18.     public function changeKategory(){
  19.         $this->isAdmin();
  20.        
  21.         $db = new DB();
  22.        
  23.         //zmiana kolejnosci - tylko!
  24.         if($this->post["CatNewNumber"]>$this->post["CatOldNumber"]){
  25.             $db -> query("SELECT id,kolejnosc FROM forum_category WHERE kolejnosc > :CatOldNumber AND kolejnosc <= :CatNewNumber ORDER BY kolejnosc ASC");
  26.             $db -> bind (':CatOldNumber', $this->post["CatOldNumber"]);
  27.             $db -> bind (':CatNewNumber', $this->post["CatNewNumber"]);
  28.             $wyniki = $db -> resultSet();
  29.            
  30.             foreach($wyniki as $kategoria){
  31.                 $kategoria['kolejnosc']--;
  32.  
  33.                 $db -> query("UPDATE forum_category SET kolejnosc = :kolejnoscNowa WHERE id = :id");
  34.                 $db -> bind(':kolejnoscNowa', $kategoria['kolejnosc']);
  35.                 $db -> bind(':id', $kategoria['id']);
  36.                 $db->execute();
  37.             }
  38.            
  39.             $db -> query("UPDATE forum_category SET name = :NewName, opis = :NewDesc, kolejnosc = :CatNewNumber WHERE id = :CatId");
  40.             $db -> bind (':NewName', $this->post['CatNewName']);
  41.             $db -> bind (':NewDesc', $this->post['CatNewDesc']);
  42.             $db -> bind (':CatNewNumber', $this->post['CatNewNumber']);
  43.             $db -> bind (':CatId', $this->post['CatId']);
  44.             $db -> execute();
  45.            
  46.         }elseif($this->post["CatNewNumber"]<$this->post["CatOldNumber"]){
  47.             $db -> query("SELECT id,kolejnosc FROM forum_category WHERE kolejnosc < :CatOldNumber AND kolejnosc >= :CatNewNumber ORDER BY kolejnosc DESC");
  48.             $db -> bind (':CatOldNumber', $this->post["CatOldNumber"]);
  49.             $db -> bind (':CatNewNumber', $this->post["CatNewNumber"]);
  50.             $wyniki = $db -> resultSet();
  51.            
  52.             foreach($wyniki as $kategoria){
  53.                 $kategoria['kolejnosc']++;
  54.  
  55.                 $db -> query("UPDATE forum_category SET kolejnosc = :kolejnoscNowa WHERE id = :id");
  56.                 $db -> bind(':kolejnoscNowa', $kategoria['kolejnosc']);
  57.                 $db -> bind(':id', $kategoria['id']);
  58.                 $db->execute();
  59.             }
  60.            
  61.             $db -> query("UPDATE forum_category SET name = :NewName, opis = :NewDesc, kolejnosc = :CatNewNumber WHERE id = :CatId");
  62.             $db -> bind (':NewName', $this->post['CatNewName']);
  63.             $db -> bind (':NewDesc', $this->post['CatNewDesc']);
  64.             $db -> bind (':CatNewNumber', $this->post['CatNewNumber']);
  65.             $db -> bind (':CatId', $this->post['CatId']);
  66.             $db -> execute();
  67.         }else{
  68.             $db -> query("UPDATE forum_category SET name = :NewName, opis = :NewDesc WHERE id = :CatId");
  69.             $db -> bind (':NewName', $this->post['CatNewName']);
  70.             $db -> bind (':NewDesc', $this->post['CatNewDesc']);
  71.             $db -> bind (':CatId', $this->post['CatId']);
  72.             $db -> execute();
  73.         }
  74.         Messages::setSuccess("Kategoria zmieniona");
  75.         header("Location:http://".ROOT_APP_URL."/forum");
  76.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement