<?php
/*
=====================================================
DataLife Engine - by SoftNews Media Group
-----------------------------------------------------
http://dle-news.ru/
-----------------------------------------------------
Copyright (c) 2004,2009 SoftNews Media Group
=====================================================
Данный код защищен авторскими правами
=====================================================
Файл: stats.php
-----------------------------------------------------
Назначение: статистика сайта
=====================================================
*/
if( ! defined( 'DATALIFEENGINE' ) ) { die( "Hacking attempt!" ); }
$module = array( 'title', 'speedbar' );
$module['title'] = "Создание нового тикета";
if( isset( $_POST['submit'] ) )
{
$priority = intval( $_POST['priority'] );
$subject = $db->safesql( htmlspecialchars( stripslashes( $_POST['subject'] ) ) );
$message = htmlspecialchars( stripslashes( $_POST['message'] ) );
$send_email = intval( $_POST['send_email'] );
$error = "";
if( !$priority ) $error .= "<li>Вы не указали приоритет тикета.</li>";
if( !$subject ) $error .= "<li>Введите тему тикета.</li>";
if( !$message ) $error .= "<li>Введите само сообщение.</li>";
$file = $_FILES['file']['tmp_name'];
$file_size = $_FILES['file']['size'];
$file_name = $_FILES['file']['name'];
$file_name = str_replace( " ", "_", $file_name );
$file_name_arr = explode( ".",$file_name );
$type = end( $file_name_arr );
$allowed_type = array( "rar", "zip", "tar", "gz", "txt", "jpg", "gif", "png", "bmp", "pdf", "doc" );
if( is_uploaded_file( $file ) && $file )
{
if( in_array( strtolower( $type ), $allowed_type ) and $file_name )
{
$file_prefix = time() + rand( 1, 100 );
$upload_file_name = "{$file_prefix}_{$file_name}";
if( !file_exists( ROOT_DIR."/uploads/tickets/{$upload_file_name}" ) )
{
$upload_file = ROOT_DIR."/uploads/tickets/{$upload_file_name}";
$res = @move_uploaded_file( $file, $upload_file );
if( $res )
{
if( @filesize( $upload_file ) > 3145728 )
{
@unlink( $upload_file );
$error .= "<li>Файл имеет слишком большой размер</li>";
}
else
{
@chmod( $upload_file, 0666 );
}
}
else
{
$error .= "<li>Файл не загружен</li>";
}
}
else
{
$error .= "<li>Произошла ошибка, файл уже существует. Попробуйте загрузить его ещё раз</li>";
}
}
else
{
$error .= "<li>Данный тип файлов запрещён для загрузки</li>";
}
}
else
{
if( $file ) $error .= "<li>Файл не может быть загружен</li>";
}
if( !empty( $error ) )
{
$tpl->Load_Template( "info.tpl" );
$tpl->set( "{title}", "Ошибка" );
$tpl->set( "{error}", "При создании тикета возникли ошибки:<br /><ol>{$error}</ol><a href=\"{$link_add_ticket}\">Вернуться назад</a>" );
$tpl->compile( "tickets" );
$tpl->clear();
}
else
{
function ReplaceCode( $code ){
$code = str_replace( " ", " ", $code );
$code = "<!--ticket code-->{$code}<!--End ticket code-->";
return $code;
}
$message = str_replace( "\n", "<br/>\n", $message );
$message = str_replace( "\r", "", $message );
$message = preg_replace( "#\\[code\\](.+?)\\[/code\\]#ies", "ReplaceCode( '\\1' );", $message );
$message = $db->safesql( $message );
$user = stripslashes( $member_id['name'] );
$user_id = $member_id['user_id'];
$date = date( "Y-m-d H:i:s" );
if( $send_email ) $send_email = $member_id['email'];
$db->query( "INSERT INTO ".PREFIX."_tickets (`title`,`status`,`user_id`,`user`,`date`,`email`,`priority`,`quest`,`answer`,`last_quest`) VALUES ('$subject','1','$user_id','$user','$date','$send_email','$priority','1','0','$date')" );
$id = $db->insert_id();
$db->query( "INSERT INTO ".PREFIX."_tickets_text (`text`,`user_id`,`user`,`official`,`date`,`ticket`,`file`,`file_server`) VALUES ('$message','$user_id','$user','0','$date','$id','$file_name','$upload_file_name')" );
if( $tickets_config['email_create'] == "yes" && $tickets_config['email'] != "" )
{
$host = $_SERVER['HTTP_HOST'];
$link_email = "http://{$host}/".$config['admin_path']."?mod=tickets&action=read&id={$id}";
require_once( ENGINE_DIR.'/data/tickets.tpl.config.php' );
include_once ENGINE_DIR.'/classes/mail.class.php';
$mail = new dle_mail( $config );
$tickets_email['create'] = stripslashes( $tickets_email['create'] );
$tickets_email['create'] = str_replace( "%time%", $date, $tickets_email['create'] );
$tickets_email['create'] = str_replace( "%user_create%", $user, $tickets_email['create'] );
$tickets_email['create'] = str_replace( "%title%", $subject, $tickets_email['create'] );
$tickets_email['create'] = str_replace( "%link%", $link_email, $tickets_email['create'] );
$mail->send( $tickets_config['email'], "Создан новый тикет", $tickets_email['create'] );
}
if( $config['allow_alt_url'] == "yes" )
{
$link_ticket_read = "/tickets/read/{$id}/";
}
else
{
$link_ticket_read = "/index.php?do=tickets&action=read&id={$id}";
}
$tpl->Load_Template( "info.tpl" );
$tpl->set( "{title}", "Информация" );
$tpl->set( "{error}", "Вопрос успешно добавлен. <a href=\"{$link_ticket_read}\">Перейти в него</a>" );
$tpl->compile( "tickets" );
$tpl->clear();
@header( "Location: {$link_ticket_read}" );
}
}
else
{
$tpl->load_template( "tickets/addtickets.tpl" );
$tpl->set( "{link->all-tickets}", $link_all_tickets );
$tpl->set( "{link->add-ticket}", $link_add_ticket );
$tpl->set( "{content}", stripslashes( $tpl->result['tickets'] ) );
$tpl->compile( 'tickets' );
$tpl->clear();
}
?>