Completed
Push — trunk ( 8e3c77...4322e5 )
by SuperNova.WS
04:12
created

announce.php (2 issues)

1
<?php
2
3
/**
4
 * announce.php
5
 *
6
 * @copyright (c) 2010-2016 Gorlum for http://supernova.ws
7
 */
8
9
$allow_anonymous = true;
10
include('common.' . substr(strrchr(__FILE__, '.'), 1));
11
12
global $config;
13
14
nws_mark_read($user);
15
$template = gettemplate('announce', true);
16
17
$announce_id = sys_get_param_id('id');
18
$text = sys_get_param_str('text');
19
$announce_time = sys_get_param_str('dtDateTime');
20
$detail_url = sys_get_param_str('detail_url');
21
$mode = sys_get_param_str('mode');
22
23
$announce = array();
24
if ($user['authlevel'] >= 3) {
25
  if (!empty($text)) {
26
    $announce_time = strtotime($announce_time, SN_TIME_NOW);
27
    $announce_time = $announce_time ? $announce_time : SN_TIME_NOW;
28
29
    if ($mode == 'edit') {
30
      /** @noinspection SqlResolve */
31
      doquery("UPDATE `{{announce}}` SET `tsTimeStamp` = FROM_UNIXTIME({$announce_time}), `strAnnounce`='{$text}', detail_url = '{$detail_url}' WHERE `idAnnounce`={$announce_id};");
32
      /** @noinspection SqlResolve */
33
      doquery("DELETE FROM `{{survey}}` WHERE `survey_announce_id` = {$announce_id};");
34
    } else {
35
      /** @noinspection SqlResolve */
36
      doquery("INSERT INTO `{{announce}}`
37
        SET `tsTimeStamp` = FROM_UNIXTIME({$announce_time}), `strAnnounce`='{$text}', detail_url = '{$detail_url}',
38
        `user_id` = {$user['id']}, `user_name` = '" . db_escape($user['username']) . "'");
39
      $announce_id = db_insert_id();
40
    }
41
    if (($survey_question = sys_get_param_str('survey_question')) && ($survey_answers = sys_get_param('survey_answers'))) {
42
      $survey_until = strtotime($survey_until = sys_get_param_str('survey_until'), SN_TIME_NOW);
43
      $survey_until = date(FMT_DATE_TIME_SQL, $survey_until ? $survey_until : SN_TIME_NOW + PERIOD_DAY * 1);
44
      /** @noinspection SqlResolve */
45
      doquery("INSERT INTO `{{survey}}` SET `survey_announce_id` = {$announce_id}, `survey_question` = '{$survey_question}', `survey_until` = '{$survey_until}'");
46
      $survey_id = db_insert_id();
47
48
      // To remove difference between Linux/Windows/OsX/etc browsers
49
      $survey_answers = nl2br($survey_answers);
0 ignored issues
show
It seems like $survey_answers can also be of type array; however, parameter $string of nl2br() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

49
      $survey_answers = nl2br(/** @scrutinizer ignore-type */ $survey_answers);
Loading history...
50
      $survey_answers = explode('<br />', $survey_answers);
51
      foreach ($survey_answers as $survey_answer) {
52
        $survey_answer = db_escape(trim($survey_answer));
53
        /** @noinspection SqlResolve */
54
        $survey_answer ? doquery("INSERT INTO `{{survey_answers}}` SET `survey_parent_id` = {$survey_id}, `survey_answer_text` = '{$survey_answer}'") : false;
55
      }
56
    }
57
58
    if ($announce_time <= SN_TIME_NOW) {
59
      if ($announce_time > SN::$config->var_news_last && $announce_time == SN_TIME_NOW) {
60
        SN::$config->db_saveItem('var_news_last', $announce_time);
61
      }
62
63
      if (sys_get_param_int('news_mass_mail')) {
64
        $text = sys_get_param('text') . ($detail_url ? " <a href=\"{$detail_url}\"><span class=\"positive\">{$lang['news_more']}</span></a>" : '');
65
        msg_send_simple_message('*', 0, 0, MSG_TYPE_ADMIN, $lang['sys_administration'], $lang['news_title'], $text);
66
      }
67
    }
68
69
    $mode = '';
70
    $announce_id = 0;
71
  }
72
73
  $survey_answers = '';
74
  switch ($mode) {
75
    case 'del':
76
      /** @noinspection SqlResolve */
77
      doquery("DELETE FROM `{{announce}}` WHERE `idAnnounce` = {$announce_id} LIMIT 1;");
78
      $mode = '';
79
    break;
80
81
    /** @noinspection PhpMissingBreakStatementInspection */
82
    case 'edit':
0 ignored issues
show
There must be a comment when fall-through is intentional in a non-empty case body
Loading history...
83
      $template->assign_var('ID', $announce_id);
84
    case 'copy':
85
      /** @noinspection SqlResolve */
86
      $announce = doquery(
87
        "SELECT a.*, s.survey_id, s.survey_question, s.survey_until
88
        FROM `{{announce}}` AS a
89
        LEFT JOIN `{{survey}}` AS s ON s.survey_announce_id = a.idAnnounce
90
        WHERE `idAnnounce` = {$announce_id} LIMIT 1;", true);
91
      if ($announce['survey_id']) {
92
        /** @noinspection SqlResolve */
93
        $query = doquery("SELECT survey_answer_text FROM `{{survey_answers}}` WHERE survey_parent_id = {$announce['survey_id']};");
94
        $survey_answers_array = [];
95
        while ($row = db_fetch($query)) {
96
          $survey_answers_array[] = $row['survey_answer_text'];
97
        }
98
        $survey_answers = implode("\n", $survey_answers_array);
99
      }
100
    break;
101
102
    default:
103
      if ($announce_id) {
104
        $annQuery = "AND `idAnnounce` = {$announce_id} ";
105
      }
106
    break;
107
  }
108
} else {
109
  $annQuery = 'AND UNIX_TIMESTAMP(`tsTimeStamp`) <= ' . SN_TIME_NOW . ' ';
110
111
  if ($announce_id) {
112
    $annQuery .= "AND `idAnnounce` = {$announce_id} ";
113
  }
114
}
115
116
nws_render($user, $template, $annQuery, 20);
117
118
$template->assign_vars(array(
119
  'PAGE_HEADER'     => $lang['news_title'],
120
  'AUTHLEVEL'       => $user['authlevel'],
121
  'MODE'            => $mode,
122
  'ANNOUNCE_ID'     => $announce_id,
123
  'tsTimeStamp'     => $announce['tsTimeStamp'],
124
  'strAnnounce'     => $announce['strAnnounce'],
125
  'DETAIL_URL'      => $announce['detail_url'],
126
  'SURVEY_QUESTION' => $announce['survey_question'],
127
  'SURVEY_UNTIL'    => $announce['survey_until'],
128
  'SURVEY_ANSWERS'  => $survey_answers,
129
130
));
131
132
display($template, $lang['news_title']);
133