Completed
Push — work-fleets ( cb2521...9eb2f3 )
by SuperNova.WS
08:26
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
use DBStatic\DBStaticNote;
12
use Vector\Vector;
13
14
include('common.' . substr(strrchr(__FILE__, '.'), 1));
15
lng_include('notes');
16
17
global $user;
18
19
$template = gettemplate('notes', true);
20
21
$result = array();
22
if(($result_message = sys_get_param_str('MESSAGE')) && isset(classLocale::$lang[$result_message])) {
23
  $result[] = array('STATUS' => sys_get_param_int('STATUS'), 'MESSAGE' => classLocale::$lang[$result_message]);
24
}
25
26
$note_id_edit = sys_get_param_id('note_id_edit');
27
$note_title_unsafe = sys_get_param_str_unsafe('note_title');
28
$note_text_unsafe = sys_get_param_str_unsafe('note_text');
29
if(sys_get_param('note_delete')) {
30
  try {
31
    DBStaticNote::processDelete($user, $note_id_edit);
32
  } catch(Exception $e) {
33
    $note_id_edit = 0;
34
    sn_db_transaction_rollback();
35
    $result[] = array(
36
      'STATUS'  => in_array($e->getCode(), array(ERR_NONE, ERR_WARNING, ERR_ERROR)) ? $e->getCode() : ERR_ERROR,
37
      'MESSAGE' => classLocale::$lang[$e->getMessage()],
38
    );
39
  }
40
} elseif(($note_title_unsafe = sys_get_param_str_unsafe('note_title')) || ($note_text_unsafe = sys_get_param_str('note_text'))) {
41
  $note_title_unsafe == classLocale::$lang['note_new_title'] ? $note_title_unsafe = '' : false;
42
  $note_text_unsafe == classLocale::$lang['note_new_text'] ? $note_text_unsafe = '' : false;
43
  try {
44
    $note_galaxy = max(0, min(sys_get_param_id('note_galaxy'), Vector::$knownGalaxies));
45
    $note_system = max(0, min(sys_get_param_id('note_system'), Vector::$knownSystems));
46
    $note_planet = max(0, min(sys_get_param_id('note_planet'), Vector::$knownPlanets + 1));
47
48
    if(!$note_text_unsafe && !$note_title_unsafe && !$note_galaxy && !$note_system && !$note_planet) {
49
      throw new Exception('note_err_note_empty', ERR_WARNING);
50
    }
51
52
    $note_priority = min(sys_get_param_id('note_priority', 2), count($note_priority_classes) - 1);
53
    $note_planet_type = max(1, min(sys_get_param_id('note_planet_type', 1), count(classLocale::$lang['sys_planet_type'])));
54
    $note_sticky = intval(sys_get_param_id('note_sticky')) ? 1 : 0;
55
56
    sn_db_transaction_start();
57
    if($note_id_edit) {
58
      $check_note_id = DBStaticNote::db_note_get_id_and_owner($note_id_edit);
59
      if(!$check_note_id) {
60
        throw new Exception('note_err_note_not_found', ERR_ERROR);
61
      }
62
    }
63
64
    if($note_id_edit) {
65
      if($check_note_id['owner'] != $user['id']) {
66
        throw new Exception('note_err_owner_wrong', ERR_ERROR);
67
      }
68
69
      DBStaticNote::db_note_update_by_id($note_priority, $note_title_unsafe, $note_text_unsafe, $note_galaxy, $note_system, $note_planet, $note_planet_type, $note_sticky, $note_id_edit);
70
    } else {
71
      DBStaticNote::db_note_insert($user['id'], $note_priority, $note_title_unsafe, $note_text_unsafe, $note_galaxy, $note_system, $note_planet, $note_planet_type, $note_sticky);
72
    }
73
74
    sn_db_transaction_commit();
75
    sys_redirect('notes.php?STATUS=' . ERR_NONE . '&MESSAGE=' . ($note_id_edit ? 'note_err_none_changed' : 'note_err_none_added'));
76
//    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...
77
  } catch(Exception $e) {
78
    $note_id_edit = 0;
79
    sn_db_transaction_rollback();
80
    $result[] = array(
81
      'STATUS'  => in_array($e->getCode(), array(ERR_NONE, ERR_WARNING, ERR_ERROR)) ? $e->getCode() : ERR_ERROR,
82
      'MESSAGE' => classLocale::$lang[$e->getMessage()],
83
    );
84
  }
85
}
86
87
if(!$note_id_edit) {
88
  note_assign($template, array(
89
    'id'          => 0,
90
    'time'        => SN_TIME_NOW,
91
    'priority'    => 2,
92
    'planet_type' => PT_PLANET,
93
    'title'       => classLocale::$lang['note_new_title'],
94
    'text'        => classLocale::$lang['note_new_text'],
95
  ));
96
}
97
98
$note_exist = false;
99
$notes_query = DBStaticNote::db_note_list_by_owner($user['id']);
100
while($note_row = db_fetch($notes_query)) {
101
  note_assign($template, $note_row);
102
  $note_exist = $note_exist || $note_row['id'] == $note_id_edit;
103
}
104
$note_id_edit = $note_exist ? $note_id_edit : 0;
105
106
foreach($note_priority_classes as $note_priority_id => $note_priority_class) {
107
  $template->assign_block_vars('note_priority', array(
108
    'ID'    => $note_priority_id,
109
    'CLASS' => $note_priority_classes[$note_priority_id],
110
    'TEXT'  => classLocale::$lang['sys_notes_priorities'][$note_priority_id],
111
  ));
112
}
113
114
foreach(classLocale::$lang['sys_planet_type'] as $planet_type_id => $planet_type_string) {
115
  $template->assign_block_vars('planet_type', array(
116
    'ID'   => $planet_type_id,
117
    'TEXT' => $planet_type_string,
118
  ));
119
}
120
121
foreach($result as $result_data) {
122
  $template->assign_block_vars('result', $result_data);
123
}
124
125
$template->assign_vars(array(
126
  'PAGE_HEADER'      => classLocale::$lang['note_page_header'],
127
  'NOTE_ID_EDIT'     => $note_id_edit,
128
  'NOTE_FULL_RENDER' => true,
129
));
130
131
display($template);
132