Advertisement
Guest User

Untitled

a guest
Aug 17th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.41 KB | None | 0 0
  1. <?php
  2.     include_once($_SERVER['DOCUMENT_ROOT'] . '/Phenya/helpers.inc.php');
  3.     if (file_exists(dirname(__DIR__) . '/Private/define_root_path.php'))
  4.         include_once(dirname(__DIR__) .'/Private/define_root_path.php');        //объявляем путь к корню сайта (в файловой системе)
  5.     else {
  6.         echo 'Error: cannot define path to root: ' . dirname(__DIR__) . '/Private/define_root_path.php';
  7.         exit();
  8.     }
  9.     include_once(DOC_ROOT . '/Phenya/helpers.inc.php');
  10.     session_true_start();
  11.    
  12.     //подключаемся к БД
  13.     $config = parse_ini_file(DOC_ROOT . '/ini/config_phenya.ini');
  14.     include DOC_ROOT . '/includes/db.inc.php';
  15.    
  16.         if (isset($_POST['textarea'])) {
  17.             $_SESSION['textarea'] = $_POST['textarea'];
  18.             if (isset($_POST['select'])) {
  19.                 $_SESSION['select'] = $_POST['select'];
  20.             }
  21.             header('Location: ' . $_SERVER['PHP_SELF'], true, 303);
  22.             exit();
  23.         }
  24.        
  25.         if (isset($_SESSION['textarea'])) {
  26.             $quote_text = $mysqli->real_escape_string($_SESSION['textarea']);
  27.             $sql = "INSERT INTO `quotes` SET
  28.                 `quote`='$quote_text'";
  29.             if (!$mysqli->query($sql))
  30.             {
  31.                 $error = 'Error inserting quote: ' . $mysqli->error;
  32.                 include DOC_ROOT . '/error.html.php';
  33.                 exit();
  34.             }
  35.            
  36.             if (isset($_SESSION['select'])) {
  37.                 $select = $_SESSION['select'];
  38.                 $quote_id = $mysqli->insert_id;
  39.                 $sql = "SELECT `id` FROM `categories`
  40.                         WHERE `name`='$select' LIMIT 1";
  41.                 if ($result = $mysqli->query($sql))
  42.                 {
  43.                     $category_id= mysqli_fetch_row($result)[0];
  44.                     mysqli_free_result($result);
  45.                 }
  46.                 else {
  47.                     $error = 'Error selecting quote category id: ' . $mysqli->error;
  48.                     include DOC_ROOT . '/error.html.php';
  49.                     exit();
  50.                 }
  51.                    
  52.                 $sql = "INSERT INTO `quote_category` SET
  53.                         `quote_id`=$quote_id,
  54.                         `category_id`=$category_id";
  55.                 if (!$mysqli->query($sql))
  56.                 {
  57.                     $error = 'Error inserting quote-category record: ' . $mysqli->error;
  58.                     include DOC_ROOT . '/error.html.php';
  59.                     exit();
  60.                 }
  61.             }
  62.             $_SESSION['output'] = 'Успешно добавили цитату.';
  63.             header('Location: ' . "/Phenya/Admin/tpl_main.php",true,303);
  64.             exit;
  65.         }
  66.    
  67.         if (isset($_POST['pswd'])) {
  68.             include DOC_ROOT . '/Phenya/Admin/pswd_check.php';
  69.             header('Location: ' . "/Phenya/Admin/tpl_main.php",true,303);
  70.             exit;
  71.         }
  72.        
  73.         if (isset($_POST['back'])) {
  74.             header('Location: ' . "/Phenya/",true,303);
  75.             exit;
  76.         }
  77. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement