<?php
require_once 'functions/init.php';
require_once 'functions/functions.php';

include_once 'components/head.php';

if (!isset($_COOKIE['role_id']))
  header('Location: user.php');
else if ($_COOKIE['role_id'] >= 3)
  header('Location: user.php?action=view&user_id=' . $_COOKIE['user_id']);

include_once 'functions/admin_functions.php';

if (isset($_POST['action']) && isset($_POST['form_id'])) {
  switch ($_POST['action']) {
    case 'delete':
      if ($_POST['form_id'] == 'users')
        foreach ($_POST['selected_users'] as $id)
          delete_account($id);
      else if ($_POST['form_id'] == 'articles')
        foreach ($_POST['selected_articles'] as $id)
          delete_article($id);
      break;

    case 'view':
      header('Location: user.php?action=view&user_id=' . $_POST['selected_users'][0]);
  }
}

if (isset($_GET['view'])) {
  switch ($_GET['view']) {
    case 'users':
      echo admin_user_view();
      break;

    case 'articles':
      echo admin_article_view();
      break;
  }
} else {
  echo admin_article_view();
}

include_once 'components/foot.php';
