Completed
Push — work-fleets ( 5a7baa...feefd8 )
by SuperNova.WS
06:08
created

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/**
4
 * notes.php
5
 *
6
 * Changelog:
7
 *   2.0 copyright © 2009-2012 Gorlum for http://supernova.ws
8
 *     [!] Wrote from scratch
9
 */
10
11
include('common.' . substr(strrchr(__FILE__, '.'), 1));
12
13
lng_include('notes');
14
15
$template = gettemplate('notes', true);
16
17
$result = array();
18
if(($result_message = sys_get_param_str('MESSAGE')) && isset(classLocale::$lang[$result_message])) {
19
  $result[] = array('STATUS' => sys_get_param_int('STATUS'), 'MESSAGE' => classLocale::$lang[$result_message]);
20
}
21
22
$note_id_edit = sys_get_param_id('note_id_edit');
23
if(sys_get_param('note_delete')) {
24
  try {
25
    $not = '';
26
    $query_where = '';
27
    switch(sys_get_param_str('note_delete_range')) {
28
      case 'all':
29
      break;
30
31
      case 'marked_not':
32
        $not = 'NOT';
33
      case 'marked':
34
        if(!is_array($notes_marked = sys_get_param('note'))) {
35
          throw new Exception('note_err_none_selected', ERR_WARNING);
36
        }
37
38
        $notes_marked_filtered = array();
39
        foreach($notes_marked as $note_id => $note_select) {
40
          if($note_select == 'on' && $note_id = idval($note_id)) {
41
            $notes_marked_filtered[] = $note_id;
42
          }
43
        }
44
45
        if(empty($notes_marked_filtered)) {
46
          throw new Exception('note_err_none_selected', ERR_WARNING);
47
        }
48
49
        $notes_marked_filtered = implode(',', $notes_marked_filtered);
50
        $query_where = "AND `id` {$not} IN ({$notes_marked_filtered})";
51
      break;
52
53
      default:
54
        throw new Exception('note_warn_no_range', ERR_WARNING);
55
      break;
56
    }
57
58
    sn_db_transaction_start();
59
    DBStaticNote::db_note_list_delete($user, $query_where);
60
    sn_db_transaction_commit();
61
    throw new Exception($note_id_edit ? 'note_err_none_changed' : 'note_err_none_added', ERR_NONE);
62
  } catch(Exception $e) {
63
    $note_id_edit = 0;
64
    sn_db_transaction_rollback();
65
    $result[] = array(
66
      'STATUS'  => in_array($e->getCode(), array(ERR_NONE, ERR_WARNING, ERR_ERROR)) ? $e->getCode() : ERR_ERROR,
67
      'MESSAGE' => classLocale::$lang[$e->getMessage()],
68
    );
69
  }
70
} elseif(($note_title = sys_get_param_str('note_title')) || ($note_text = sys_get_param_str('note_text'))) {
71
  $note_title == db_escape(classLocale::$lang['note_new_title']) ? $note_title = '' : false;
72
  ($note_text = sys_get_param_str('note_text')) == db_escape(classLocale::$lang['note_new_text']) ? $note_text = '' : false;
73
74
  try {
75
    $note_galaxy = max(0, min(sys_get_param_id('note_galaxy'), Vector::$knownGalaxies));
76
    $note_system = max(0, min(sys_get_param_id('note_system'), Vector::$knownSystems));
77
    $note_planet = max(0, min(sys_get_param_id('note_planet'), Vector::$knownPlanets + 1));
78
79
    if(!$note_text && !$note_title && !$note_galaxy && !$note_system && !$note_planet) {
80
      throw new exception('note_err_note_empty', ERR_WARNING);
81
    }
82
83
    $note_priority = min(sys_get_param_id('note_priority', 2), count($note_priority_classes) - 1);
84
    $note_planet_type = max(1, min(sys_get_param_id('note_planet_type', 1), count(classLocale::$lang['sys_planet_type'])));
85
    $note_sticky = intval(sys_get_param_id('note_sticky')) ? 1 : 0;
86
87
    sn_db_transaction_start();
88
    if($note_id_edit) {
89
      $check_note_id = DBStaticNote::db_note_get_id_and_owner($note_id_edit);
90
      if(!$check_note_id) {
91
        throw new Exception('note_err_note_not_found', ERR_ERROR);
92
      }
93
    }
94
95
    if($note_id_edit) {
96
      if($check_note_id['owner'] != $user['id']) {
97
        throw new Exception('note_err_owner_wrong', ERR_ERROR);
98
      }
99
100
      DBStaticNote::db_note_update_by_id($note_priority, $note_title, $note_text, $note_galaxy, $note_system, $note_planet, $note_planet_type, $note_sticky, $note_id_edit);
101
    } else {
102
      DBStaticNote::db_note_insert($user, $note_priority, $note_title, $note_text, $note_galaxy, $note_system, $note_planet, $note_planet_type, $note_sticky);
103
    }
104
105
    sn_db_transaction_commit();
106
    sys_redirect('notes.php?STATUS=' . ERR_NONE . '&MESSAGE=' . ($note_id_edit ? 'note_err_none_changed' : 'note_err_none_added'));
107
//    throw new exception($note_id_edit ? 'note_err_none_changed' : 'note_err_none_added', ERR_NONE);
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
108
  } catch(Exception $e) {
109
    $note_id_edit = 0;
110
    sn_db_transaction_rollback();
111
    $result[] = array(
112
      'STATUS'  => in_array($e->getCode(), array(ERR_NONE, ERR_WARNING, ERR_ERROR)) ? $e->getCode() : ERR_ERROR,
113
      'MESSAGE' => classLocale::$lang[$e->getMessage()],
114
    );
115
  }
116
}
117
118
if(!$note_id_edit) {
119
  note_assign($template, array(
120
    'id'          => 0,
121
    'time'        => SN_TIME_NOW,
122
    'priority'    => 2,
123
    'planet_type' => PT_PLANET,
124
    'title'       => classLocale::$lang['note_new_title'],
125
    'text'        => classLocale::$lang['note_new_text'],
126
  ));
127
}
128
129
$note_exist = false;
130
$notes_query = DBStaticNote::db_note_list_by_owner($user['id']);
131
while($note_row = db_fetch($notes_query)) {
132
  note_assign($template, $note_row);
133
  $note_exist = $note_exist || $note_row['id'] == $note_id_edit;
134
}
135
$note_id_edit = $note_exist ? $note_id_edit : 0;
136
137
foreach($note_priority_classes as $note_priority_id => $note_priority_class) {
138
  $template->assign_block_vars('note_priority', array(
139
    'ID'    => $note_priority_id,
140
    'CLASS' => $note_priority_classes[$note_priority_id],
141
    'TEXT'  => classLocale::$lang['sys_notes_priorities'][$note_priority_id],
142
  ));
143
}
144
145
foreach(classLocale::$lang['sys_planet_type'] as $planet_type_id => $planet_type_string) {
146
  $template->assign_block_vars('planet_type', array(
147
    'ID'   => $planet_type_id,
148
    'TEXT' => $planet_type_string,
149
  ));
150
}
151
152
foreach($result as $result_data) {
153
  $template->assign_block_vars('result', $result_data);
154
}
155
156
$template->assign_vars(array(
157
  'PAGE_HEADER'      => classLocale::$lang['note_page_header'],
158
  'NOTE_ID_EDIT'     => $note_id_edit,
159
  'NOTE_FULL_RENDER' => true,
160
));
161
162
display($template);
163