Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once ('../includes/functions.php');
- $task = (isset($_GET['task']) ? $_GET['task'] : 'default');
- switch ($task) {
- case 'add':
- if (empty($_POST)) {
- include_once 'forms/adddata.php';
- } else {
- $name = $_POST['name'];
- $shortDescription = $_POST['short_rescription'];
- $fullDescription = $_POST['full_description'];
- $created = date("Y-m-d H:i:s");
- $createdBy = (int) $_SESSION['id'];
- if (mysql_query("INSERT INTO data(name, full_description, short_description, created, created_by)
- VALUES('$name', '$fullDescription', '$shortDescription', '$created', '$createdBy')")) {
- $dataId = mysql_insert_id();
- $query = '';
- $query.="INSERT INTO data_category(data_id, subcat_id, maincat_id) VALUES ";
- foreach ($_POST['subcat_id'] as $subcatId) {
- $mainCatId = getMainCatId($subcatId);
- $query.="('$dataId', '$subcatId', '$mainCatId'),";
- }
- $query = substr(trim($query), 0, -1);
- if (mysql_query($query)) {
- $torrentLinks = explode("\r\n", $_POST['torrent_links']);
- $linksCount = count($torrentLinks);
- if ($linksCount != 0) {
- $query = "INSERT INTO torrent_links(torrent_link, data_id) VALUES ";
- for ($i = 0; $i < $linksCount; $i++) {
- $query.="('" . $torrentLinks[$i] . "','" . $dataId . "'), ";
- }
- $query = substr(trim($query), 0, -1);
- if (!mysql_query($query)) {
- die(mysql_error());
- }
- }
- if ($_FILES['photos']['name'][0] != "") {
- $photoDir = ROOT_PATH . '/photos/' . $dataId . '/';
- if (mkdir($photoDir, 0777)) {
- for ($i = 0; $i < count($_FILES['photos']['name']); $i++) {
- $fileName = md5(microtime()) . '.jpg';
- $filePath = $photoDir . $fileName;
- if (move_uploaded_file($_FILES['photos']['tmp_name'][$i], $filePath)) {
- if (!mysql_query("INSERT INTO photos(data_id, filename) VALUES('$dataId', '$fileName')")) {
- die(mysql_error() . '::' . __LINE__);
- }
- }
- }
- } else {
- echo "Невозможно создать директорию: <b>" . ROOT_PATH . '/photos/' . $dataId . '/' . "</b>";
- }
- }
- }
- else
- die(mysql_error() . '::' . __LINE__);
- }
- else
- die(mysql_error() . '::' . __LINE__);
- }
- break;
- case 'list':
- break;
- default:
- header("Location: index.php");
- break;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement