Completed
Push — work-fleets ( bf14b2...c62b27 )
by SuperNova.WS
06:15
created

alliance.php (4 issues)

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
include('common.' . substr(strrchr(__FILE__, '.'), 1));
4
5 View Code Duplication
if(classSupernova::$config->game_mode == GAME_BLITZ) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
6
  message(classLocale::$lang['sys_blitz_page_disabled'], classLocale::$lang['sys_error'], 'overview.php', 10);
7
  die();
8
}
9
10
define('SN_IN_ALLY', true);
11
12
// Main admin page save themes
13
lng_include('alliance');
14
15
$mode = sys_get_param_str('mode');
16
17
if($mode == 'ainfo') {
18
  include('includes/alliance/ali_info.inc');
19
}
20
21
if(!$user['ally_id']) {
22
  $user_request = DBStaticAlly::db_ally_request_get_by_user_id($user['id']);
23
  if($user_request['id_user']) {
24
    require('includes/alliance/ali_external_request.inc');
25
  } else {
26
    switch($mode) {
27
      case 'search':
28
        require('includes/alliance/ali_external_search.inc');
29
      break;
30
31
      case 'apply':
32
        require('includes/alliance/ali_external_request.inc');
33
      break;
34
35
      case 'make':
36
        require('includes/alliance/ali_external_create_ally.inc');
37
      break;
38
39
      default:
40
        display(parsetemplate(gettemplate('ali_external', true)), classLocale::$lang['alliance']);
41
      break;
42
    }
43
  }
44
}
45
46
sn_ali_fill_user_ally($user);
47
if(!isset($user['ally'])) {
48
  DBStaticUser::db_user_set_by_id_DEPRECATED($user['id'], "`ally_id` = null, `ally_name` = null, `ally_register_time` = 0, `ally_rank_id` = 0");
0 ignored issues
show
Deprecated Code introduced by
The method DBStaticUser::db_user_set_by_id_DEPRECATED() has been deprecated.

This method has been deprecated.

Loading history...
49
  message(classLocale::$lang['ali_sys_notFound'], classLocale::$lang['your_alliance'], 'alliance.php');
50
}
51
$ally = &$user['ally'];
52
/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% 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...
53
$ally_rights = array(
54
  0 => 'name',
55
  1 => 'mail',
56
  2 => 'online',
57
  3 => 'invite',
58
  4 => 'kick',
59
  5 => 'admin',
60
  6 => 'forum',
61
  7 => 'diplomacy'
62
);
63
*/
64
$rights_old = array(
65
  0 => 'name',
66
  1 => 'mails',
67
  2 => 'onlinestatus',
68
  3 => 'bewerbungenbearbeiten',
69
  4 => 'kick',
70
  5 => 'rechtehand'
71
);
72
73
// This piece converting old ally data to new one
74
//  unset($ally['ranklist']);
75
if(!$ally['ranklist'] && $ally['ally_ranks']) {
76
  $ally_ranks = unserialize($ally['ally_ranks']);
77
  $i = 0;
78
  foreach($ally_ranks as $rank_id => $rank) {
79
    foreach($ally_rights as $key => $value) {
80
      $ranks[$i][$value] = $rank[$rights_old[$key]];
81
    }
82
    DBStaticUser::db_user_list_set_ally_deprecated_convert_ranks($user['ally_id'], $i, $rank_id);
0 ignored issues
show
Deprecated Code introduced by
The method DBStaticUser::db_user_li...recated_convert_ranks() has been deprecated.

This method has been deprecated.

Loading history...
83
    $i++;
84
  }
85
86
  if(!empty($ranks)) {
87
    ali_rank_list_save($ranks);
88
  }
89
}
90
91
$ranks = ally_get_ranks($ally);
92
93
$isAllyOwner = $ally['ally_owner'] == $user['id'];
94
$user_can_send_mails = $ranks[$user['ally_rank_id']]['mail'] || $isAllyOwner;
95
$userCanPostForum = $ranks[$user['ally_rank_id']]['forum'] || $isAllyOwner;
96
$user_onlinestatus = $ranks[$user['ally_rank_id']]['online'] || $isAllyOwner;
97
$user_admin_applications = $ranks[$user['ally_rank_id']]['invite'] || $isAllyOwner;
98
$user_can_kick = $ranks[$user['ally_rank_id']]['kick'] || $isAllyOwner;
99
$user_can_negotiate = $ranks[$user['ally_rank_id']]['diplomacy'] || $isAllyOwner;
100
$user_can_edit_rights = $user_admin = $ranks[$user['ally_rank_id']]['admin'] || $isAllyOwner;
101
102
$edit = sys_get_param_str('edit');
103
ally_pre_call();
104
switch($mode) {
105
  case 'admin':
106
    if(!array_key_exists($edit, $sn_ali_admin_internal)) {
107
      $edit = 'default';
108
    }
109
    if($sn_ali_admin_internal[$edit]['include']) {
110
      require("includes/{$sn_ali_admin_internal[$edit]['include']}");
111
    }
112
    if(isset($sn_ali_admin_internal[$edit]['function']) && is_callable($sn_ali_admin_internal[$edit]['function'])) {
113
      call_user_func($sn_ali_admin_internal[$edit]['function']);
114
    }
115
  break;
116
117
  case 'memberslist':
118
    require('includes/alliance/ali_internal_members.inc');
119
  break;
120
  case 'circular':
121
    require('includes/alliance/ali_internal_admin_mail.inc');
122
  break;
123
  default:
124
    require('includes/alliance/ali_info.inc');
125
  break;
126
}
127
128
function ally_pre_call() {
129
  $func_args = func_get_args();
130
131
  return sn_function_call(__FUNCTION__, $func_args);
132
}
133