Completed
Push — master ( bbda49...c5c3b2 )
by Michael
02:49
created

blocksadmin.inc.php ➔ myblocksadmin_update_block()   F

Complexity

Conditions 17
Paths 560

Size

Total Lines 71
Code Lines 50

Duplication

Lines 4
Ratio 5.63 %

Importance

Changes 0
Metric Value
cc 17
eloc 50
nc 560
nop 10
dl 4
loc 71
rs 3.0985
c 0
b 0
f 0

How to fix   Long Method    Complexity    Many Parameters   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 414 and the first side effect is on line 33.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
// $Id: main.php,v 1.12 2004/01/06 09:36:20 okazu Exp $
3
//  ------------------------------------------------------------------------ //
4
//                XOOPS - PHP Content Management System                      //
5
//                    Copyright (c) 2000 XOOPS.org                           //
6
//                       <http://www.xoops.org/>                             //
7
//  ------------------------------------------------------------------------ //
8
//  This program is free software; you can redistribute it and/or modify     //
9
//  it under the terms of the GNU General Public License as published by     //
10
//  the Free Software Foundation; either version 2 of the License, or        //
11
//  (at your option) any later version.                                      //
12
//                                                                           //
13
//  You may not change or alter any portion of this comment or credits       //
14
//  of supporting developers from this source code or any supporting         //
15
//  source code which is considered copyrighted (c) material of the          //
16
//  original comment or credit authors.                                      //
17
//                                                                           //
18
//  This program is distributed in the hope that it will be useful,          //
19
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
20
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
21
//  GNU General Public License for more details.                             //
22
//                                                                           //
23
//  You should have received a copy of the GNU General Public License        //
24
//  along with this program; if not, write to the Free Software              //
25
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
26
//  ------------------------------------------------------------------------ //
27
// Author: Kazumi Ono (AKA onokazu)                                          //
28
// URL: http://www.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ //
29
// Project: The XOOPS Project                                                //
30
// ------------------------------------------------------------------------- //
31
32 View Code Duplication
if ( !is_object($xoopsUser) || !is_object($xoopsModule) || !$xoopsUser->isAdmin($xoopsModule->mid()) ) {
0 ignored issues
show
Duplication introduced by
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...
33
  exit('Access Denied');
34
}
35
include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php';
36
include XOOPS_ROOT_PATH.'/modules/system/admin/blocksadmin/blocksadmin.php';
37
38
$op = 'list';
39
40
if ( !empty($_POST['op']) ) { $op = $_POST['op']; }
41
if ( !empty($_POST['bid']) ) { $bid = intval($_POST['bid']); }
42
43
if ( isset($_GET['op']) ) {
44
  if ($_GET['op'] == 'edit' || $_GET['op'] == 'delete' || $_GET['op'] == 'delete_ok' || $_GET['op'] == 'clone' /* || $_GET['op'] == 'previewpopup'*/) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% 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...
45
    $op = $_GET['op'];
46
    $bid = isset($_GET['bid']) ? intval($_GET['bid']) : 0;
47
  }
48
}
49
50
if (isset($_POST['previewblock'])) {
51
  //if ( !admin_refcheck("/modules/$admin_mydirname/admin/") ) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% 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...
52
  //  exit('Invalid Referer');
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% 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
  //}
54
  if ( ! $xoopsGTicket->check() ) {
55
    redirect_header(XOOPS_URL.'/',3,$xoopsGTicket->getErrors());
56
  }
57
58
  if( empty( $bid ) ) die( 'Invalid bid.' ) ;
59
60
  if ( !empty($_POST['bside']) ) { $bside = intval($_POST['bside']); } else { $bside = 0; }
61
  if ( !empty($_POST['bweight']) ) { $bweight = intval($_POST['bweight']); } else { $bweight = 0; }
62
  if ( !empty($_POST['bvisible']) ) { $bvisible = intval($_POST['bvisible']); } else { $bvisible = 0; }
63
  if ( !empty($_POST['bmodule']) ) { $bmodule = $_POST['bmodule']; } else { $bmodule = array(); }
64
  if ( !empty($_POST['btitle']) ) { $btitle = $_POST['btitle']; } else { $btitle = ""; }
65
  if ( !empty($_POST['bcontent']) ) { $bcontent = $_POST['bcontent']; } else { $bcontent = ""; }
66
  if ( !empty($_POST['bctype']) ) { $bctype = $_POST['bctype']; } else { $bctype = ""; }
67
  if ( !empty($_POST['bcachetime']) ) { $bcachetime = intval($_POST['bcachetime']); } else { $bcachetime = 0; }
68
69
  xoops_cp_header();
70
  include_once XOOPS_ROOT_PATH.'/class/template.php';
71
  $xoopsTpl = new XoopsTpl();
72
  $xoopsTpl->xoops_setCaching(0);
73
  $block['bid'] = $bid;
74
75
  if ($op == 'clone_ok') {
76
    $block['form_title'] = _AM_CLONEBLOCK;
77
    $block['submit_button'] = _CLONE;
78
    $myblock = new XoopsBlock();
79
    $myblock->setVar('block_type', 'C');
80
  } else {
81
    $op = 'update' ;
82
    $block['form_title'] = _AM_EDITBLOCK;
83
    $block['submit_button'] = _SUBMIT;
84
    $myblock = new XoopsBlock($bid);
85
    $block['name'] = $myblock->getVar('name');
86
  }
87
88
  $wfmyts = MyTextSanitizer::getInstance();
89
  $myblock->setVar('title', $wfmyts->stripSlashesGPC($btitle));
90
  $myblock->setVar('content', $wfmyts->stripSlashesGPC($bcontent));
91
//  $dummyhtml = '<html><head><meta http-equiv="content-type" content="text/html; charset='._CHARSET.'" /><meta http-equiv="content-language" content="'._LANGCODE.'" /><title>'.$xoopsConfig['sitename'].'</title><link rel="stylesheet" type="text/css" media="all" href="'.getcss($xoopsConfig['theme_set']).'" /></head><body><table><tr><th>'.$myblock->getVar('title').'</th></tr><tr><td>'.$myblock->getContent('S', $bctype).'</td></tr></table></body></html>';
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% 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...
92
93
  /* $dummyfile = '_dummyfile_'.time().'.html';
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% 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...
94
  $fp = fopen(XOOPS_CACHE_PATH.'/'.$dummyfile, 'w');
95
  fwrite($fp, $dummyhtml);
96
  fclose($fp);*/
97
  $block['edit_form'] = false;
98
  $block['template'] = '';
99
  $block['op'] = $op;
100
  $block['side'] = $bside;
101
  $block['weight'] = $bweight;
102
  $block['visible'] = $bvisible;
103
  $block['title'] = $myblock->getVar('title', 'E');
104
  $block['content'] = $myblock->getVar('content', 'E');
105
  $block['modules'] =& $bmodule;
106
  $block['ctype'] = isset($bctype) ? $bctype : $myblock->getVar('c_type');
107
  $block['is_custom'] = true;
108
  $block['cachetime'] = intval($bcachetime);
109
  echo '<a href="myblocksadmin.php">'. _AM_BADMIN .'</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;'.$block['form_title'].'<br /><br />';
110
  include dirname(__FILE__).'/../admin/myblockform.php'; //GIJ
111
  //echo '<a href="admin.php?fct=blocksadmin">'. _AM_BADMIN .'</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;'.$block['form_title'].'<br /><br />';
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...
112
  //include XOOPS_ROOT_PATH.'/modules/system/admin/blocksadmin/blockform.php';
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
113
  $form->addElement( $xoopsGTicket->getTicketXoopsForm( __LINE__ ) );//GIJ
114
  $form->display();
115
116
  $original_level = error_reporting( E_ALL ) ;
117
  echo "
118
    <table width='100%' class='outer' cellspacing='1'>
119
      <tr>
120
        <th>".$myblock->getVar('title')."</th>
121
      </tr>
122
      <tr>
123
        <td class='odd'>".$myblock->getContent('S', $bctype)."</td>
124
      </tr>
125
    </table>\n" ;
126
  error_reporting( $original_level ) ;
127
128
  xoops_cp_footer();
129
  /* echo '<script type="text/javascript">
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% 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...
130
  preview_window = openWithSelfMain("'.XOOPS_URL.'/modules/system/admin.php?fct=blocksadmin&op=previewpopup&file='.$dummyfile.'", "popup", 250, 200);
131
  </script>';*/
132
133
  exit();
134
}
135
136
/* if ($op == 'previewpopup') {
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
137
  if ( !admin_refcheck("/modules/$admin_mydirname/admin/") ) {
138
    exit('Invalid Referer');
139
  }
140
  $file = str_replace('..', '', XOOPS_CACHE_PATH.'/'.trim($_GET['file']));
141
  if (file_exists($file)) {
142
    include $file;
143
    @unlink($file);
144
  }
145
  exit();
146
} */
147
148
/* if ($op == "list") {
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% 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...
149
  xoops_cp_header();
150
  list_blocks();
151
  xoops_cp_footer();
152
  exit();
153
} */
154
155
if ($op == 'order') {
156
  //if ( !admin_refcheck("/modules/$admin_mydirname/admin/") ) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% 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...
157
  //  exit('Invalid Referer');
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% 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...
158
  //}
159
  if ( ! $xoopsGTicket->check() ) {
160
    redirect_header(XOOPS_URL.'/',3,$xoopsGTicket->getErrors());
161
  }
162
  if ( !empty($_POST['side']) ) { $side = $_POST['side']; }
163
//  if ( !empty($_POST['weight']) ) { $weight = $_POST['weight']; }
0 ignored issues
show
Unused Code Comprehensibility introduced by
66% 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...
164
  if ( !empty($_POST['visible']) ) { $visible = $_POST['visible']; }
165
//  if ( !empty($_POST['oldside']) ) { $oldside = $_POST['oldside']; }
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% 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...
166
//  if ( !empty($_POST['oldweight']) ) { $oldweight = $_POST['oldweight']; }
167
//  if ( !empty($_POST['oldvisible']) ) { $oldvisible = $_POST['oldvisible']; }
168
  if ( !empty($_POST['bid']) ) { $bid = $_POST['bid']; } else { $bid = array(); }
169
  // GIJ start
170
  foreach (array_keys($bid) as $i) {
171
        if ($side[$i] < 0) {
172
            $visible[$i] = 0 ;
173
            $side[$i] = -1 ;
174
        } else {
175
            $visible[$i] = 1 ;
176
        }
177
178
        $bmodule = (isset($_POST['bmodule'][$i]) && is_array($_POST['bmodule'][$i])) ? $_POST['bmodule'][$i] : array(-1) ;
179
180
        myblocksadmin_update_block($i, $side[$i], $_POST['weight'][$i], $visible[$i], $_POST['title'][$i], null , null , $_POST['bcachetime'][$i], $bmodule, array());
181
182
//    if ( $oldweight[$i] != $weight[$i] || $oldvisible[$i] != $visible[$i] || $oldside[$i] != $side[$i] )
0 ignored issues
show
Unused Code Comprehensibility introduced by
71% 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...
183
//    order_block($bid[$i], $weight[$i], $visible[$i], $side[$i]);
184
  }
185
  $query4redirect = '?dirname=' . urlencode( strip_tags( substr( $_POST['query4redirect'] , 9 ) ) ) ;
186
  redirect_header("myblocksadmin.php$query4redirect",1,_AM_DBUPDATED);
187
  // GIJ end
188
  exit();
189
}
190
191
/* if ($op == 'save') {
0 ignored issues
show
Unused Code Comprehensibility introduced by
61% 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...
192
  if ( !admin_refcheck("/modules/$admin_mydirname/admin/") ) {
193
    exit('Invalid Referer');
194
  }
195
  if ( ! $xoopsGTicket->check() ) {
196
    redirect_header(XOOPS_URL.'/',3,$xoopsGTicket->getErrors());
197
  }
198
  if ( !empty($_POST['bside']) ) { $bside = intval($_POST['bside']); } else { $bside = 0; }
199
  if ( !empty($_POST['bweight']) ) { $bweight = intval($_POST['bweight']); } else { $bweight = 0; }
200
  if ( !empty($_POST['bvisible']) ) { $bvisible = intval($_POST['bvisible']); } else { $bvisible = 0; }
201
  if ( !empty($_POST['bmodule']) ) { $bmodule = $_POST['bmodule']; } else { $bmodule = array(); }
202
  if ( !empty($_POST['btitle']) ) { $btitle = $_POST['btitle']; } else { $btitle = ""; }
203
  if ( !empty($_POST['bcontent']) ) { $bcontent = $_POST['bcontent']; } else { $bcontent = ""; }
204
  if ( !empty($_POST['bctype']) ) { $bctype = $_POST['bctype']; } else { $bctype = ""; }
205
  if ( !empty($_POST['bcachetime']) ) { $bcachetime = intval($_POST['bcachetime']); } else { $bcachetime = 0; }
206
  save_block($bside, $bweight, $bvisible, $btitle, $bcontent, $bctype, $bmodule, $bcachetime);
207
  exit();
208
} */
209
210
if ($op == 'update') {
211
  //if ( !admin_refcheck("/modules/$admin_mydirname/admin/") ) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% 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...
212
  //  exit('Invalid Referer');
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% 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...
213
  //}
214
  if ( ! $xoopsGTicket->check() ) {
215
    redirect_header(XOOPS_URL.'/',3,$xoopsGTicket->getErrors());
216
  }
217
/*  if ( !empty($_POST['bside']) ) { $bside = intval($_POST['bside']); } else { $bside = 0; }
0 ignored issues
show
Unused Code Comprehensibility introduced by
61% 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...
218
  if ( !empty($_POST['bweight']) ) { $bweight = intval($_POST['bweight']); } else { $bweight = 0; }
219
  if ( !empty($_POST['bvisible']) ) { $bvisible = intval($_POST['bvisible']); } else { $bvisible = 0; }
220
  if ( !empty($_POST['btitle']) ) { $btitle = $_POST['btitle']; } else { $btitle = ""; }
221
  if ( !empty($_POST['bcontent']) ) { $bcontent = $_POST['bcontent']; } else { $bcontent = ""; }
222
  if ( !empty($_POST['bctype']) ) { $bctype = $_POST['bctype']; } else { $bctype = ""; }
223
  if ( !empty($_POST['bcachetime']) ) { $bcachetime = intval($_POST['bcachetime']); } else { $bcachetime = 0; }
224
  if ( !empty($_POST['bmodule']) ) { $bmodule = $_POST['bmodule']; } else { $bmodule = array(); }
225
  if ( !empty($_POST['options']) ) { $options = $_POST['options']; } else { $options = array(); }
226
  update_block($bid, $bside, $bweight, $bvisible, $btitle, $bcontent, $bctype, $bcachetime, $bmodule, $options);*/
227
228
    $bcachetime = isset($_POST['bcachetime']) ? intval($_POST['bcachetime']) : 0;
229
    $options = isset($_POST['options']) ? $_POST['options'] : array();
230
    $bcontent = isset($_POST['bcontent']) ? $_POST['bcontent'] : '';
231
    $bctype = isset($_POST['bctype']) ? $_POST['bctype'] : '';
232
    $bmodule = (isset($_POST['bmodule']) && is_array($_POST['bmodule'])) ? $_POST['bmodule'] : array(-1) ; // GIJ +
233
    $msg = myblocksadmin_update_block($_POST['bid'], $_POST['bside'], $_POST['bweight'], $_POST['bvisible'], $_POST['btitle'], $bcontent, $bctype, $bcachetime, $bmodule, $options); // GIJ !
234
    redirect_header('myblocksadmin.php',1,$msg);
235
}
236
237
if ($op == 'delete_ok') {
238
  //if ( !admin_refcheck("/modules/$admin_mydirname/admin/") ) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% 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...
239
  //  exit('Invalid Referer');
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% 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...
240
  //}
241
  if ( ! $xoopsGTicket->check() ) {
242
    redirect_header(XOOPS_URL.'/',3,$xoopsGTicket->getErrors());
243
  }
244
  // delete_block_ok($bid); GIJ imported from blocksadmin.php
245
        $myblock = new XoopsBlock($bid);
246
        if ( $myblock->getVar('block_type') != 'D' && $myblock->getVar('block_type') != 'C' ) {
247
            redirect_header('myblocksadmin.php',4,'Invalid block');
248
            exit();
249
        }
250
        $myblock->delete();
251
        if ($myblock->getVar('template') != '' && ! defined('XOOPS_ORETEKI') ) {
252
            $tplfile_handler =& xoops_gethandler('tplfile');
253
            $btemplate =& $tplfile_handler->find($GLOBALS['xoopsConfig']['template_set'], 'block', $bid);
254
            if (count($btemplate) > 0) {
255
                $tplman->delete($btemplate[0]);
256
            }
257
        }
258
        redirect_header('myblocksadmin.php',1,_AM_DBUPDATED);
259
        exit();
260
  // end of delete_block_ok() GIJ
261
  exit();
262
}
263
264
if ($op == 'delete') {
265
  xoops_cp_header();
266
  // delete_block($bid); GIJ imported from blocksadmin.php
267
        $myblock = new XoopsBlock($bid);
268
        if ( $myblock->getVar('block_type') == 'S' ) {
269
            $message = _AM_SYSTEMCANT;
270
            redirect_header('admin.php?fct=blocksadmin',4,$message);
271
            exit();
272
        } elseif ($myblock->getVar('block_type') == 'M') {
273
            $message = _AM_MODULECANT;
274
            redirect_header('admin.php?fct=blocksadmin',4,$message);
275
            exit();
276
        } else {
277
            xoops_confirm(array('fct' => 'blocksadmin', 'op' => 'delete_ok', 'bid' => $myblock->getVar('bid')) + $xoopsGTicket->getTicketArray( __LINE__ ) , 'admin.php', sprintf(_AM_RUSUREDEL,$myblock->getVar('title')));
278
        }
279
  // end of delete_block() GIJ
280
  xoops_cp_footer();
281
  exit();
282
}
283
284 View Code Duplication
if ($op == 'edit') {
0 ignored issues
show
Duplication introduced by
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...
285
286
  xoops_cp_header();
287
  // edit_block($bid); GIJ imported from blocksadmin.php
288
        $myblock = new XoopsBlock($bid);
289
290
        $db =& XoopsDatabaseFactory :: getdatabaseconnection();
291
        $sql = 'SELECT module_id FROM '.$db->prefix('block_module_link').' WHERE block_id='.intval($bid);
292
        $result = $db->query($sql);
293
        $modules = array();
294
        while ($row = $db->fetchArray($result)) {
295
            $modules[] = intval($row['module_id']);
296
        }
297
        $is_custom = ($myblock->getVar('block_type') == 'C' || $myblock->getVar('block_type') == 'E') ? true : false;
298
        $block = array('form_title' => _AM_EDITBLOCK, 'name' => $myblock->getVar('name'), 'side' => $myblock->getVar('side'), 'weight' => $myblock->getVar('weight'), 'visible' => $myblock->getVar('visible'), 'title' => $myblock->getVar('title', 'E'), 'content' => $myblock->getVar('content', 'E'), 'modules' => $modules, 'is_custom' => $is_custom, 'ctype' => $myblock->getVar('c_type'), 'cachetime' => $myblock->getVar('bcachetime'), 'op' => 'update', 'bid' => $myblock->getVar('bid'), 'edit_form' => $myblock->getOptions(), 'template' => $myblock->getVar('template'), 'options' => $myblock->getVar('options'), 'submit_button' => _SUBMIT);
299
300
        echo '<a href="myblocksadmin.php">'. _AM_BADMIN .'</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;'._AM_EDITBLOCK.'<br /><br />';
301
        include dirname(__FILE__).'/../admin/myblockform.php'; //GIJ
302
        $form->addElement( $xoopsGTicket->getTicketXoopsForm( __LINE__ ) );//GIJ
303
        $form->display();
304
  // end of edit_block() GIJ
305
  xoops_cp_footer();
306
  exit();
307
}
308
309 View Code Duplication
if ($op == 'clone') {
0 ignored issues
show
Duplication introduced by
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...
310
    xoops_cp_header();
311
    $myblock = new XoopsBlock($bid);
312
313
    $db =& XoopsDatabaseFactory :: getdatabaseconnection();
314
    $sql = 'SELECT module_id FROM '.$db->prefix('block_module_link').' WHERE block_id='.intval($bid);
315
    $result = $db->query($sql);
316
    $modules = array();
317
    while ($row = $db->fetchArray($result)) {
318
        $modules[] = intval($row['module_id']);
319
    }
320
    $is_custom = ($myblock->getVar('block_type') == 'C' || $myblock->getVar('block_type') == 'E') ? true : false;
321
    $block = array('form_title' => _AM_CLONEBLOCK, 'name' => $myblock->getVar('name'), 'side' => $myblock->getVar('side'), 'weight' => $myblock->getVar('weight'), 'visible' => $myblock->getVar('visible'), 'content' => $myblock->getVar('content', 'N'), 'title' => $myblock->getVar('title','E'), 'modules' => $modules, 'is_custom' => $is_custom, 'ctype' => $myblock->getVar('c_type'), 'cachetime' => $myblock->getVar('bcachetime'), 'op' => 'clone_ok', 'bid' => $myblock->getVar('bid'), 'edit_form' => $myblock->getOptions(), 'template' => $myblock->getVar('template'), 'options' => $myblock->getVar('options'), 'submit_button' => _CLONE);
322
    echo '<a href="myblocksadmin.php">'. _AM_BADMIN .'</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;'._AM_CLONEBLOCK.'<br /><br />';
323
    include dirname(__FILE__).'/../admin/myblockform.php';
324
    $form->addElement( $xoopsGTicket->getTicketXoopsForm( __LINE__ ) );//GIJ
325
    $form->display();
326
    xoops_cp_footer();
327
    exit();
328
}
329
330
if ($op == 'clone_ok') {
331
    // Ticket Check
332
    if ( ! $xoopsGTicket->check() ) {
333
        redirect_header(XOOPS_URL.'/',3,$xoopsGTicket->getErrors());
334
    }
335
336
    $block = new XoopsBlock($bid);
337
338
    // block type check
339
    $block_type = $block->getVar('block_type') ;
340
    if ($block_type != 'C' && $block_type != 'M' && $block_type != 'D') {
341
        redirect_header('myblocksadmin.php',4,'Invalid block');
342
    }
343
344
    if( empty( $_POST['options'] ) ) $options = array() ;
345
    else if( is_array( $_POST['options'] ) ) $options = $_POST['options'] ;
346
    else $options = explode( '|' , $_POST['options'] ) ;
347
348
    // for backward compatibility
349
    // $cblock =& $block->clone(); or $cblock =& $block->xoopsClone();
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% 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...
350
    $cblock = new XoopsBlock() ;
351
    foreach ($block->vars as $k => $v) {
352
        $cblock->assignVar( $k , $v['value'] ) ;
353
    }
354
    $cblock->setNew();
355
356
    $cblock->setVar('side', $_POST['bside']);
357
    $cblock->setVar('weight', $_POST['bweight']);
358
    $cblock->setVar('visible', $_POST['bvisible']);
359
    $cblock->setVar('title', $_POST['btitle']);
360
    //$cblock->setVar('content', $bcontent);
0 ignored issues
show
Unused Code Comprehensibility introduced by
80% 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...
361
    //$cblock->setVar('title', $btitle);
0 ignored issues
show
Unused Code Comprehensibility introduced by
80% 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...
362
    $cblock->setVar('bcachetime', $_POST['bcachetime']);
363 View Code Duplication
    if ( isset($options) && (count($options) > 0) ) {
0 ignored issues
show
Duplication introduced by
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...
364
        $options = implode('|', $options);
365
        $cblock->setVar('options', $options);
366
    }
367
    $cblock->setVar('bid', 0);
368
    $cblock->setVar('block_type', $block_type == 'C' ? 'C' : 'D' );
369
    $cblock->setVar('func_num', 255);
370
    $newid = $cblock->store();
371
    if (!$newid) {
372
        xoops_cp_header();
373
        $cblock->getHtmlErrors();
374
        xoops_cp_footer();
375
        exit();
376
    }
377
/*	if ($cblock->getVar('template') != '') {
0 ignored issues
show
Unused Code Comprehensibility introduced by
66% 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...
378
        $tplfile_handler =& xoops_gethandler('tplfile');
379
        $btemplate =& $tplfile_handler->find($GLOBALS['xoopsConfig']['template_set'], 'block', $bid);
380
        if (count($btemplate) > 0) {
381
            $tplclone =& $btemplate[0]->clone();
382
            $tplclone->setVar('tpl_id', 0);
383
            $tplclone->setVar('tpl_refid', $newid);
384
            $tplman->insert($tplclone);
385
        }
386
    } */
387
    $db =& XoopsDatabaseFactory :: getdatabaseconnection();
388
    $bmodule = (isset($_POST['bmodule']) && is_array($_POST['bmodule'])) ? $_POST['bmodule'] : array(-1) ; // GIJ +
389
    foreach ($bmodule as $bmid) {
390
        $sql = 'INSERT INTO '.$db->prefix('block_module_link').' (block_id, module_id) VALUES ('.$newid.', '.$bmid.')';
391
        $db->query($sql);
392
    }
393
394
/*	global $xoopsUser;
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% 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...
395
    $groups =& $xoopsUser->getGroups();
396
    $count = count($groups);
397
    for ($i = 0; $i < $count; ++$i) {
398
        $sql = "INSERT INTO ".$db->prefix('group_permission')." (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (".$groups[$i].", ".$newid.", 1, 'block_read')";
399
        $db->query($sql);
400
    }
401
*/
402
403
    $sql = "SELECT gperm_groupid FROM ".$db->prefix('group_permission')." WHERE gperm_name='block_read' AND gperm_modid='1' AND gperm_itemid='$bid'" ;
404
    $result = $db->query($sql);
405
    while ( list( $gid ) = $db->fetchRow( $result ) ) {
406
        $sql = "INSERT INTO ".$db->prefix('group_permission')." (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES ($gid, $newid, 1, 'block_read')";
407
        $db->query($sql);
408
    }
409
410
    redirect_header('myblocksadmin.php',1,_AM_DBUPDATED);
411
}
412
413
    // import from modules/system/admin/blocksadmin/blocksadmin.php
414
    function myblocksadmin_update_block($bid, $bside, $bweight, $bvisible, $btitle, $bcontent, $bctype, $bcachetime, $bmodule, $options=array())
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
415
    {
416
        global $xoopsConfig;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
417
        /* if (empty($bmodule)) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% 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...
418
            xoops_cp_header();
419
            xoops_error(sprintf(_AM_NOTSELNG, _AM_VISIBLEIN));
420
            xoops_cp_footer();
421
            exit();
422
        } */
423
        $myblock = new XoopsBlock($bid);
424
        // $myblock->setVar('side', $bside); GIJ -
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% 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...
425
        if( $bside >= 0 ) $myblock->setVar('side', $bside); // GIJ +
426
        $myblock->setVar('weight', $bweight);
427
        $myblock->setVar('visible', $bvisible);
428
        $myblock->setVar('title', $btitle);
429
        if( isset( $bcontent ) ) $myblock->setVar('content', $bcontent);
430
        if( isset( $bctype ) ) $myblock->setVar('c_type', $bctype);
431
        $myblock->setVar('bcachetime', $bcachetime);
432 View Code Duplication
        if ( isset($options) && (count($options) > 0) ) {
0 ignored issues
show
Duplication introduced by
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...
433
            $options = implode('|', $options);
434
            $myblock->setVar('options', $options);
435
        }
436
        if ( $myblock->getVar('block_type') == 'C') {
437
            switch ( $myblock->getVar('c_type') ) {
438
            case 'H':
439
                $name = _AM_CUSTOMHTML;
440
                break;
441
            case 'P':
442
                $name = _AM_CUSTOMPHP;
443
                break;
444
            case 'S':
445
                $name = _AM_CUSTOMSMILE;
446
                break;
447
            default:
448
                $name = _AM_CUSTOMNOSMILE;
449
                break;
450
            }
451
            $myblock->setVar('name', $name);
452
        }
453
        $msg = _AM_DBUPDATED;
454
        if ($myblock->store() != false) {
455
            $db =& XoopsDatabaseFactory :: getdatabaseconnection();
456
            $sql = sprintf("DELETE FROM %s WHERE block_id = %u", $db->prefix('block_module_link'), $bid);
457
            $db->query($sql);
458
            foreach ($bmodule as $bmid) {
459
                $sql = sprintf("INSERT INTO %s (block_id, module_id) VALUES (%u, %d)", $db->prefix('block_module_link'), $bid, intval($bmid));
460
                $db->query($sql);
461
            }
462
            include_once XOOPS_ROOT_PATH.'/class/template.php';
463
            $xoopsTpl = new XoopsTpl();
464
            $xoopsTpl->xoops_setCaching(2);
465
            if ($myblock->getVar('template') != '') {
466
                if ($xoopsTpl->is_cached('db:'.$myblock->getVar('template'))) {
467
                    if (!$xoopsTpl->clear_cache('db:'.$myblock->getVar('template'))) {
468
                        $msg = 'Unable to clear cache for block ID'.$bid;
469
                    }
470
                }
471
            } else {
472
                if ($xoopsTpl->is_cached('db:system_dummy.html', 'block'.$bid)) {
473
                    if (!$xoopsTpl->clear_cache('db:system_dummy.html', 'block'.$bid)) {
474
                        $msg = 'Unable to clear cache for block ID'.$bid;
475
                    }
476
                }
477
            }
478
        } else {
479
            $msg = 'Failed update of block. ID:'.$bid;
480
        }
481
        // redirect_header('admin.php?fct=blocksadmin&amp;t='.time(),1,$msg);
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% 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...
482
        // exit(); GIJ -
0 ignored issues
show
Unused Code Comprehensibility introduced by
45% 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...
483
        return $msg ; // GIJ +
484
    }
485