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

announce.php (3 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
      doquery("UPDATE {{announce}} SET `tsTimeStamp` = FROM_UNIXTIME({$announce_time}), `strAnnounce`='{$text}', detail_url = '{$detail_url}' WHERE `idAnnounce`={$announce_id};");
31
      doquery("DELETE FROM {{survey}} WHERE `survey_announce_id` = {$announce_id};");
32
    } else {
33
      doquery("INSERT INTO {{announce}}
34
        SET `tsTimeStamp` = FROM_UNIXTIME({$announce_time}), `strAnnounce`='{$text}', detail_url = '{$detail_url}',
35
        `user_id` = {$user['id']}, `user_name` = '" . db_escape($user['username']) . "'");
36
      $announce_id = db_insert_id();
37
    }
38
    if (($survey_question = sys_get_param_str('survey_question')) && ($survey_answers = sys_get_param('survey_answers'))) {
39
      $survey_answers = explode("\r\n", $survey_answers);
0 ignored issues
show
It seems like $survey_answers can also be of type array; however, parameter $string of explode() 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

39
      $survey_answers = explode("\r\n", /** @scrutinizer ignore-type */ $survey_answers);
Loading history...
40
      $survey_until = strtotime($survey_until = sys_get_param_str('survey_until'), SN_TIME_NOW);
41
      $survey_until = date(FMT_DATE_TIME_SQL, $survey_until ? $survey_until : SN_TIME_NOW + PERIOD_DAY * 1);
42
      doquery("INSERT INTO {{survey}} SET `survey_announce_id` = {$announce_id}, `survey_question` = '{$survey_question}', `survey_until` = '{$survey_until}'");
43
      $survey_id = db_insert_id();
44
      foreach ($survey_answers as $survey_answer) {
45
        $survey_answer = db_escape(trim($survey_answer));
46
        $survey_answer ? doquery("INSERT INTO {{survey_answers}} SET `survey_parent_id` = {$survey_id}, `survey_answer_text` = '{$survey_answer}'") : false;
47
      }
48
    }
49
50
    if ($announce_time <= SN_TIME_NOW) {
51
      if ($announce_time > SN::$config->var_news_last && $announce_time == SN_TIME_NOW) {
52
        SN::$config->db_saveItem('var_news_last', $announce_time);
53
      }
54
55
      if (sys_get_param_int('news_mass_mail')) {
56
        $text = sys_get_param('text') . ($detail_url ? " <a href=\"{$detail_url}\"><span class=\"positive\">{$lang['news_more']}</span></a>" : '');
57
        msg_send_simple_message('*', 0, 0, MSG_TYPE_ADMIN, $lang['sys_administration'], $lang['news_title'], $text);
58
      }
59
    }
60
61
    $mode = '';
62
    $announce_id = 0;
63
  }
64
65
  $survey_answers = '';
66
  switch ($mode) {
67
    case 'del':
68
      doquery("DELETE FROM {{announce}} WHERE `idAnnounce` = {$announce_id} LIMIT 1;");
69
      $mode = '';
70
    break;
71
72
    case 'edit':
0 ignored issues
show
There must be a comment when fall-through is intentional in a non-empty case body
Loading history...
73
      $template->assign_var('ID', $announce_id);
74
    case 'copy':
75
      $announce = doquery(
76
        "SELECT a.*, s.survey_id, s.survey_question, s.survey_until
77
        FROM {{announce}} AS a
78
        LEFT JOIN {{survey}} AS s ON s.survey_announce_id = a.idAnnounce
79
        WHERE `idAnnounce` = {$announce_id} LIMIT 1;", true);
80
      if ($announce['survey_id']) {
81
        $query = doquery("SELECT survey_answer_text FROM {{survey_answers}} WHERE survey_parent_id = {$announce['survey_id']};");
82
        while ($row = db_fetch($query)) {
83
          $survey_answers[] = $row['survey_answer_text'];
84
        }
85
        $survey_answers = implode("\r\n", $survey_answers);
0 ignored issues
show
$survey_answers of type string is incompatible with the type array expected by parameter $pieces of implode(). ( Ignorable by Annotation )

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

85
        $survey_answers = implode("\r\n", /** @scrutinizer ignore-type */ $survey_answers);
Loading history...
86
      }
87
    break;
88
89
    default:
90
      if ($announce_id) {
91
        $annQuery = "WHERE `idAnnounce` = {$announce_id}";
92
      }
93
    break;
94
  }
95
} else {
96
  $annQuery = 'WHERE UNIX_TIMESTAMP(`tsTimeStamp`) <= ' . SN_TIME_NOW;
97
98
  if ($announce_id) {
99
    $annQuery .= " AND `idAnnounce` = {$announce_id}";
100
  }
101
}
102
103
nws_render($template, $annQuery, 20);
104
105
$template->assign_vars(array(
106
  'PAGE_HEADER'     => $lang['news_title'],
107
  'AUTHLEVEL'       => $user['authlevel'],
108
  'MODE'            => $mode,
109
  'ANNOUNCE_ID'     => $announce_id,
110
  'tsTimeStamp'     => $announce['tsTimeStamp'],
111
  'strAnnounce'     => $announce['strAnnounce'],
112
  'DETAIL_URL'      => $announce['detail_url'],
113
  'SURVEY_QUESTION' => $announce['survey_question'],
114
  'SURVEY_UNTIL'    => $announce['survey_until'],
115
  'SURVEY_ANSWERS'  => $survey_answers,
116
117
));
118
119
display($template, $lang['news_title']);
120