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