Просмотр файла ViPTurbo 3.0/adminpanel/forum.php

Размер файла: 5.16Kb
<?
include '../include/path.php';

if(isset($user) && ($rank&128)==128)
{

   if(isset($_POST['change']))
   {

      if($_POST['option']=='delete')
      {

         if(isset($_POST['chforum']))
         {
             foreach($_POST['chforum'] as $key=>$value){ $df[]='`id`='.intval($key); $dc[]='`f`='.intval($key);}

             if(isset($df)) sql_send('DELETE FROM `'.PRE.'forum_forums` WHERE '.implode(' OR ', $df));

         }



         if(isset($_POST['chcat']))
         {
             foreach($_POST['chcat'] as $key=>$value){ $dc[]='`id`='.intval($key);  }

             if(isset($dc))
             {

                $cats=sql_query('SELECT `id` FROM `'.PRE.'forum_cats` WHERE '.implode(' OR ', $dc));

                while($c=mysql_fetch_assoc($cats)) $dt[]='`c`='.$c['id'];

                if(isset($dt)) sql_send('DELETE FROM `'.PRE.'forum_posts` WHERE '.implode(' OR ', $dt));

                sql_send('DELETE FROM `'.PRE.'forum_cats` WHERE '.implode(' OR ', $dc));

             }


         }


      }else
      if($_POST['option']=='edit')
      {

         if(isset($_POST['chcat'])) foreach($_POST['chcat'] as $key=>$value)     sql_send('UPDATE `'.PRE.'forum_cats` SET `name`="'.filtr($_POST['cat'][$key]).'" WHERE `id`='.intval($key));

         if(isset($_POST['chforum'])) foreach($_POST['chforum'] as $key=>$value)   sql_send('UPDATE `'.PRE.'forum_forums` SET `name`="'.filtr($_POST['forum'][$key]).'" WHERE `id`='.intval($key));

      }

      header('Location: forum.php?'.SID);

   }else
   if(isset($_POST['add']) && isset($_POST['name']) && isset($_POST['type']))
   {

      if($_POST['type']=='forum' && strlen($_POST['name'])>=2) sql_send('INSERT INTO `'.PRE.'forum_forums` SET `name`="'.filtr($_POST['name']).'"');  else

        if($_POST['type']=='cat' && strlen($_POST['name'])>=2 && isset($_POST['forums']) && mysql_num_rows(sql_query('SELECT `id` FROM `'.PRE.'forum_forums` WHERE `id`='.intval($_POST['forums'])))!=0)

           sql_send('INSERT INTO `'.PRE.'forum_cats` SET `name`="'.filtr($_POST['name']).'", `f`='.intval($_POST['forums']));

      header('Location: forum.php?'.SID);

   }else
   {

       $forums=sql_query('SELECT * FROM `'.PRE.'forum_forums` WHERE `rank`<='.$user['rank'].' ORDER BY `id` ASC');

       $all_cats=sql_query('SELECT * FROM `'.PRE.'forum_cats` WHERE `rank`<='.$user['rank'].' ORDER BY `id` ASC');

       while($cats[]=mysql_fetch_assoc($all_cats)) $sq[]='`c`='.$cats[count($cats)-1]['id'];

       if(isset($sq))
       {

          $all_posts=sql_query('SELECT `posts`,`c` FROM `'.PRE.'forum_posts` WHERE `name`!="" AND ('.implode(' OR ', $sq).')');

          while($posts_c=mysql_fetch_assoc($all_posts))
          {
             $posts[$posts_c['c']]=(isset($posts[$posts_c['c']]))?$posts[$posts_c['c']]+$posts_c['posts']:$posts_c['posts'];
             $themes[$posts_c['c']]=(isset($themes[$posts_c['c']]))?$themes[$posts_c['c']]+1:1;
          }

       }


       function put_content()
       {
           global $forums,$cats,$posts,$themes;

           echo '<div class="title">Управление форумом</div>';

           echo '<form action="forum.php?'.SID.'" method="POST">';

           if(mysql_num_rows($forums)!=0)
           {

           while($forum=mysql_fetch_assoc($forums))
           {

               echo '<div class="header"><input type="checkbox" name="chforum['.$forum['id'].']"><input type="text" name="forum['.$forum['id'].']" value="'.$forum['name'].'"></div>';

               if (count($cats)==0) echo '<div></div>'; else
               {

                  echo '<div>';

                  foreach($cats as $key=>$cat)
                  {

                     if($cat['f']===$forum['id'])echo '<input type="checkbox" name="chcat['.$cat['id'].']"><input type="text" name="cat['.$cat['id'].']" value="'.$cat['name'].'"> ['.((isset($themes[$cat['id']]))?$themes[$cat['id']]:0).'/'.((isset($posts[$cat['id']]))?$posts[$cat['id']]:0).']<br>';

                  }

                  echo '</div>';

               }

               $forums2[$forum['id']]=$forum['name'];

           }

           }else echo 'Подфорумы не созданы.<br>';

            echo '<br>
                  <select name="option"><option value="edit">Изменить</option><option value="delete">Удалить</option></select>
                  <input type="submit" name="change" value="Изменить"><br>
                  <input type="text" name="name"><select name="type"><option value="forum">Форум</option><option value="cat">Категорию</option></select>

           <select name="forums">';

           foreach($forums2 as $id=>$name)echo'<option value="'.$id.'">'.$name.'</option>';

           echo'</select>';

           echo '<input type="submit" name="add" value="Добавить"></form>';

           echo '<div class="nav"><a href="index.php?'.SID.'">В панель управления</a></div>';

       }

   }

}else{
   $link = '1; URL=../';
         function put_content() {
                  echo '<a href="../">далее...</a>';
                  }
}

design();?>