Просмотр файла modules/forum/add_post.php

Размер файла: 3.38Kb
  1. <?php
  2. /**********************************
  3. * @package: PerfCMS *
  4. * @year: 2012 *
  5. * @author: Artas *
  6. * @link: http://perfcms.pp.ua *
  7. **********************************/
  8. $locate = 'in_forum';
  9. $topic_id = abs(intval($_GET['topic_id']));
  10. if(!isset($user) || !isset($topic_id)) { header('Location:/'); }
  11. if($db->query("SELECT * FROM `forum_t` WHERE `id` = '". $topic_id ."'")->rowCount() == 0) {
  12. header('Location:/forum/');
  13. }
  14. if(isset($_POST['create']) && $_GET['act'] == 'create') {
  15.  
  16. if(!empty($_POST['text'])) { $text = substr(input($_POST['text']), 0, 3500);} else { $err = 'Message is empty'; }
  17. if(!empty($_POST['text'])) {
  18. $db->query("INSERT INTO `forum_pt` SET `text` = '".$text."', `time` = '". time() ."', `user_id` = '".$user['id']."', `topic_id` = '".$topic_id."'");
  19. $lastPostId = $db->lastInsertId();
  20. $db->query("UPDATE `forum_t` SET `time_last_post` = '". time() ."', `user_last_post` = '". $user['id'] ."' WHERE `id` = '".$topic_id."'");
  21. $file_dir = ROOT .'/files/forum/';
  22. if ($_FILES['file']['tmp_name']) {
  23. $patch = pathinfo($_FILES['file']['name']);
  24. if (!in_array($patch['extension'], explode(';', $system['files_types']))) { $err = 'File extention not allowed.<br />'; }
  25. $name_start = cyrlat($patch['filename']);
  26. $name_short = trim($name_start).time();
  27. $name_end = mb_convert_encoding($name_short, "UTF-8");
  28. $name = $name_end.'.'. $patch['extension'];
  29. if (file_exists($file_dir . $name)) { $err = 'This file exists<br />'; }
  30. if(!isset($err)) {
  31. move_uploaded_file($_FILES['file']['tmp_name'], $file_dir . $name);
  32. $db->query("UPDATE `forum_pt` SET `file` = '". input($name) ."', `file_size` = '". $_FILES['file']['size'] ."' WHERE `id` = '".$lastPostId."'");
  33. // print_r($db->errorInfo());
  34. } else { echo $err; }
  35. }
  36. // print_r($db->errorInfo());
  37. header('Location:/forum/topic'. abs(intval($topic_id)).'/?page=end');
  38. // print_r($db->errorInfo());
  39. } else { header('Location:/forum/topic'. abs(intval($topic_id)).'/?page=end'); }
  40. }
  41. $title = $lang->word('add_message');
  42. require_once(SYS.'/view/header.php');
  43. $tpl->div('title', $lang->word('add_message'));
  44. $tpl->div('menu', '<form action="/forum/add_post/'. $topic_id .'/?act=create" method="post" enctype="multipart/form-data">
  45. <b>'. $lang->word('message') .'</b>:<br/>
  46. <textarea name="text" rows="5" cols="26">'.(isset($_GET['reply_to']) ? '[b]'.$_GET['reply_to'].'[/b], ' : NULL) . (isset($_GET['quote']) ? "[b]".tnick($db->query("SELECT user_id FROM `forum_pt` WHERE `topic_id` = '". $topic_id ."' AND `id` = '". $_GET['quote'] ."'")->fetchColumn())."[/b] ".date('d.m.Y, H:i', $db->query("SELECT time FROM `forum_pt` WHERE `topic_id` = '". $topic_id ."' AND `id` = '". $_GET['quote'] ."'")->fetchColumn())."\n[quote]\n".preg_replace('/\[quote\]|\[\/quote\]/i', '', $db->query("SELECT text FROM `forum_pt` WHERE `topic_id` = '". $topic_id ."' AND `id` = '". $_GET['quote'] ."'")->fetchColumn())."\n[/quote] " : NULL) .'</textarea><br/>
  47. <b>'.$lang->word('add_file').'</b><br/>
  48. <input type="file" name="file"><br/>
  49. <input name="create" type="submit" value="'. $lang->word('create') .'" /><br/>
  50. </form>');
  51. $tpl->div('block', NAV .'<a href="/forum/topic'.$topic_id.'/">'. $lang->word('back') .'</a><br/>' . NAV .'<a href="/forum/">'. $lang->word('forum') .'</a><br/>' . HICO .'<a href="/">'. $lang->word('home').'</a>');
  52. require_once(SYS.'/view/footer.php');
  53. ?>