Completed
Pull Request — master (#7)
by
unknown
01:15
created

index.php (19 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
 * Xoops Members Module
4
 *
5
 * You may not change or alter any portion of this comment or credits
6
 * of supporting developers from this source code or any supporting source code
7
 * which is considered copyrighted (c) material of the original comment or credit authors.
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * @copyright The XOOPS Project http://sourceforge.net/projects/xoops/
13
 * @license http://www.fsf.org/copyleft/gpl.html GNU public license
14
 * @package Xoops Members
15
 * @since 2.3.0
16
 * @author onokazu
17
 * @author John Neill
18
 * @version $Id: index.php catzwolf$
19
 */
20
include dirname( dirname( dirname( __FILE__ ) ) ) . DIRECTORY_SEPARATOR . 'mainfile.php';
21
//include_once 'header.php';
22
//global $pathIcon16;
23
24
global $xoopsModule;
25
$pathIcon16 = $xoopsModule->getInfo('icons16');
26
27
    $xoopsOption['template_main'] = 'xoopsmembers_index.tpl';
28
    include XOOPS_ROOT_PATH . '/header.php';
29
	
30
	$member_handler = xoops_gethandler('member');
31
    $total = $member_handler->getUserCount( new Criteria( 'level', 0, '>' ) );
32
33
    $iamadmin = $xoopsUserIsAdmin;
34
    $myts = MyTextSanitizer::getInstance();
35
    $criteria = new CriteriaCompo();
36
37 View Code Duplication
    if ( !empty( $_POST['user_uname'] ) ) {
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...
38
        $match = ( !empty( $_POST['user_uname_match'] ) ) ? intval( $_POST['user_uname_match'] ) : XOOPS_MATCH_START;
39
        $ret = $myts->addSlashes( trim( $_POST['user_uname'] ) );
40
        xoops_Criteria( $criteria, 'uname', $ret, $match );
41
    }
42
43 View Code Duplication
    if ( !empty( $_POST['user_name'] ) ) {
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...
44
        $match = ( !empty( $_POST['user_name_match'] ) ) ? intval( $_POST['user_name_match'] ) : XOOPS_MATCH_START;
45
        $ret = $myts->addSlashes( trim( $_POST['user_uname'] ) );
46
        xoops_Criteria( $criteria, 'name', $ret, $match );
47
    }
48
49 View Code Duplication
    if ( !empty( $_POST['user_email'] ) ) {
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...
50
        $match = ( !empty( $_POST['user_email_match'] ) ) ? intval( $_POST['user_email_match'] ) : XOOPS_MATCH_START;
51
        $ret = $myts->addSlashes( trim( $_POST['user_email'] ) );
52
        xoops_Criteria( $criteria, 'name', $ret, $match );
53
        if ( !$iamadmin ) {
54
            $criteria->add( new Criteria( 'user_viewemail', 1 ) );
55
        }
56
    }
57
58 View Code Duplication
    if ( !empty( $_POST['user_url'] ) ) {
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...
59
        $url = formatURL( trim( $_POST['user_url'] ) );
60
        $criteria->add( new Criteria( 'url', $myts->addSlashes( $url ) . '%', 'LIKE' ) );
61
    }
62
63 View Code Duplication
    if ( !empty( $_POST['user_icq'] ) ) {
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...
64
        $match = ( !empty( $_POST['user_icq_match'] ) ) ? intval( $_POST['user_icq_match'] ) : XOOPS_MATCH_START;
65
        $ret = $myts->addSlashes( trim( $_POST['user_icq'] ) );
66
        xoops_Criteria( $criteria, 'user_icq', $ret, $match );
67
    }
68
69 View Code Duplication
    if ( !empty( $_POST['user_aim'] ) ) {
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...
70
        $match = ( !empty( $_POST['user_aim_match'] ) ) ? intval( $_POST['user_aim_match'] ) : XOOPS_MATCH_START;
71
        $ret = $myts->addSlashes( trim( $_POST['user_aim'] ) );
72
        xoops_Criteria( $criteria, 'user_aim', $ret, $match );
73
    }
74
75 View Code Duplication
    if ( !empty( $_POST['user_yim'] ) ) {
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...
76
        $match = ( !empty( $_POST['user_yim_match'] ) ) ? intval( $_POST['user_yim_match'] ) : XOOPS_MATCH_START;
77
        $ret = $myts->addSlashes( trim( $_POST['user_yim'] ) );
78
        xoops_Criteria( $criteria, 'user_yim', $ret, $match );
79
    }
80
81 View Code Duplication
    if ( !empty( $_POST['user_msnm'] ) ) {
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...
82
        $match = ( !empty( $_POST['user_msnm_match'] ) ) ? intval( $_POST['user_msnm_match'] ) : XOOPS_MATCH_START;
83
        $ret = $myts->addSlashes( trim( $_POST['user_msnm'] ) );
84
        xoops_Criteria( $criteria, 'user_msnm', $ret, $match );
85
    }
86
87 View Code Duplication
    if ( !empty( $_POST['user_from'] ) ) {
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...
88
        $criteria->add( new Criteria( 'user_from', '%' . $myts->addSlashes( trim( $_POST['user_from'] ) ) . '%', 'LIKE' ) );
89
    }
90
91 View Code Duplication
    if ( !empty( $_POST['user_intrest'] ) ) {
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...
92
        $criteria->add( new Criteria( 'user_intrest', '%' . $myts->addSlashes( trim( $_POST['user_intrest'] ) ) . '%', 'LIKE' ) );
93
    }
94
95 View Code Duplication
    if ( !empty( $_POST['user_occ'] ) ) {
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...
96
        $criteria->add( new Criteria( 'user_occ', '%' . $myts->addSlashes( trim( $_POST['user_occ'] ) ) . '%', 'LIKE' ) );
97
    }
98
99 View Code Duplication
    if ( !empty( $_POST['user_lastlog_more'] ) && is_numeric( $_POST['user_lastlog_more'] ) ) {
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...
100
        $f_user_lastlog_more = intval( trim( $_POST['user_lastlog_more'] ) );
101
        $time = time() - ( 60 * 60 * 24 * $f_user_lastlog_more );
102
        if ( $time > 0 ) {
103
            $criteria->add( new Criteria( 'last_login', $time, '<' ) );
104
        }
105
    }
106
107 View Code Duplication
    if ( !empty( $_POST['user_lastlog_less'] ) && is_numeric( $_POST['user_lastlog_less'] ) ) {
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...
108
        $f_user_lastlog_less = intval( trim( $_POST['user_lastlog_less'] ) );
109
        $time = time() - ( 60 * 60 * 24 * $f_user_lastlog_less );
110
        if ( $time > 0 ) {
111
            $criteria->add( new Criteria( 'last_login', $time, '>' ) );
112
        }
113
    }
114
115 View Code Duplication
    if ( !empty( $_POST['user_reg_more'] ) && is_numeric( $_POST['user_reg_more'] ) ) {
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...
116
        $f_user_reg_more = intval( trim( $_POST['user_reg_more'] ) );
117
        $time = time() - ( 60 * 60 * 24 * $f_user_reg_more );
118
        if ( $time > 0 ) {
119
            $criteria->add( new Criteria( 'user_regdate', $time, '<' ) );
120
        }
121
    }
122
123 View Code Duplication
    if ( !empty( $_POST['user_reg_less'] ) && is_numeric( $_POST['user_reg_less'] ) ) {
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...
124
        $f_user_reg_less = intval( $_POST['user_reg_less'] );
125
        $time = time() - ( 60 * 60 * 24 * $f_user_reg_less );
126
        if ( $time > 0 ) {
127
            $criteria->add( new Criteria( 'user_regdate', $time, '>' ) );
128
        }
129
    }
130
131 View Code Duplication
    if ( isset( $_POST['user_posts_more'] ) && is_numeric( $_POST['user_posts_more'] ) ) {
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...
132
        $criteria->add( new Criteria( 'posts', intval( $_POST['user_posts_more'] ), '>' ) );
133
    }
134
135 View Code Duplication
    if ( !empty( $_POST['user_posts_less'] ) && is_numeric( $_POST['user_posts_less'] ) ) {
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...
136
        $criteria->add( new Criteria( 'posts', intval( $_POST['user_posts_less'] ), '<' ) );
137
    }
138
139
    $criteria->add( new Criteria( 'level', 0, '>' ) );
140
    $validsort = array( 'uname', 'name', 'last_login', 'user_regdate', 'posts' );
141
    $sort = ( !in_array( $xoopsModuleConfig['sortmembers'], $validsort ) ) ? 'uname' : $xoopsModuleConfig['sortmembers'];
142
    
143
	$order = 'ASC';
144
    if ( isset( $xoopsModuleConfig['membersorder'] ) && $xoopsModuleConfig['membersorder'] == 'DESC' ) {
145
        $order = 'DESC';
146
    }
147
    $limit = ( !empty( $xoopsModuleConfig['membersperpage'] ) ) ? intval( $xoopsModuleConfig['membersperpage'] ) : 20;
148
	if ( $limit == 0 || $limit > 50 ) {
149
        $limit = 50;
150
    }
151
152
    $start = ( !empty( $_POST['start'] ) ) ? intval( $_POST['start'] ) : 0;
153
    $member_handler = xoops_gethandler( 'member' );
154
    $total = $member_handler->getUserCount( $criteria );
155
    $xoopsTpl->assign( 'total_found', $total );
156
	$xoopsTpl->assign( 'totalmember', $total );
157
158 View Code Duplication
    if ( $total == 0 ) {
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...
159
    } elseif ( $start < $total ) {
160
        if ( $iamadmin ) {
161
            $xoopsTpl->assign( 'is_admin', true );
162
        }
163
        $criteria->setSort( $sort );
164
        $criteria->setOrder( $order );
165
        $criteria->setStart( $start );
166
        $criteria->setLimit( $limit );
167
        $foundusers = $member_handler->getUsers( $criteria, true );
168
        foreach ( array_keys( $foundusers ) as $j ) {
169
            $userdata["avatar"] = $foundusers[$j]->getVar( 'user_avatar' ) ? '<img src="' . XOOPS_UPLOAD_URL . '/' . $foundusers[$j]->getVar( 'user_avatar' ) . '" alt="" />' : '&nbsp;';
170
            $userdata["realname"] = $foundusers[$j]->getVar( 'name' ) ? $foundusers[$j]->getVar( 'name' ) : '&nbsp;';
171
            $userdata["name"] = $foundusers[$j]->getVar( 'uname' );
172
            $userdata["id"] = $foundusers[$j]->getVar( 'uid' );
173
            if ( $foundusers[$j]->getVar( 'user_viewemail' ) == 1 || $iamadmin ) {
174
                $userdata["email"] = '<a href="mailto:' . $foundusers[$j]->getVar( 'email' ) . '"><img src="' . XOOPS_URL . '/images/icons/email.gif" border="0" alt="' . sprintf( _SENDEMAILTO, $foundusers[$j]->getVar( 'uname', "e" ) ) . '" /></a>';
175
            } else {
176
                $userdata["email"] = '&nbsp;';
177
            }
178
            if ( $xoopsUser ) {
179
                $userdata["pmlink"] = '<a href="javascript:openWithSelfMain(\'' . XOOPS_URL . '/pmlite.php?send2=1&amp;to_userid=' . $foundusers[$j]->getVar( 'uid' ) . '\',\'pmlite\',450,370);"><img src="' . XOOPS_URL . '/images/icons/pm.gif" border="0" alt="' . sprintf( _SENDPMTO, $foundusers[$j]->getVar( 'uname', "e" ) ) . '" /></a>';
180
            } else {
181
                $userdata["pmlink"] = '&nbsp;';
182
            }
183
            if ( $foundusers[$j]->getVar( 'url', "e" ) != '' ) {
184
                $userdata["website"] = '<a href="' . $foundusers[$j]->getVar( 'url', "e" ) . '" target="_blank"><img src="' . XOOPS_URL . '/images/icons/www.gif" border="0" alt="' . _VISITWEBSITE . '" /></a>';
185
            } else {
186
                $userdata["website"] = '&nbsp;';
187
            }
188
            $userdata["registerdate"] = formatTimeStamp( $foundusers[$j]->getVar( 'user_regdate' ), 's' );
189
            if ( $foundusers[$j]->getVar( 'last_login' ) != 0 ) {
190
                $userdata["lastlogin"] = formatTimeStamp( $foundusers[$j]->getVar( 'last_login' ), "m" );
191
            } else {
192
                $userdata["lastlogin"] = '&nbsp;';
193
            }
194
            $userdata["posts"] = $foundusers[$j]->getVar( 'posts' );
195
            if ( $iamadmin ) {
196
                $userdata["adminlink"] = '<a href="' . XOOPS_URL . '/modules/system/admin.php?fct=users&amp;uid=' . $foundusers[$j]->getVar( 'uid' ) . '&amp;op=users_edit">' . '<img src='. $pathIcon16 .'/edit.png'." alt='" . _EDIT . "' title='" . _EDIT . "' />"
197
198
                . '</a> | <a href="' . XOOPS_URL . '/modules/system/admin.php?fct=users&amp;op=users_delete&amp;uid=' . $foundusers[$j]->getVar( 'uid' ) . '">' . '<img src='. $pathIcon16 .'/delete.png'." alt='" . _DELETE . "' title='" . _DELETE . "' />" . '</a>';
199
            }
200
            $xoopsTpl->append( "users", $userdata );
201
        }
202
203
        $totalpages = ceil( $total / $limit );
204
        if ( $totalpages > 1 ) {
205
            $hiddenform = '<form name="findnext" action="index.php" method="post">';
206
            foreach ( $_POST as $k => $v ) {
207
                $hiddenform .= '<input type="hidden" name="' . $myts->htmlSpecialChars( $k ) . '" value="' . $myts->previewTarea( $v ) . '" />';
208
            }
209
            if ( !isset( $_POST['limit'] ) ) {
210
                $hiddenform .= '<input type="hidden" name="limit" value="' . $limit . '" />';
211
            }
212
            if ( !isset( $_POST['start'] ) ) {
213
                $hiddenform .= '<input type="hidden" name="start" value="' . $start . '" />';
214
            }
215
            $prev = $start - $limit;
216
            if ( $start - $limit >= 0 ) {
217
                $hiddenform .= '<a href="#0" onclick="javascript:document.findnext.start.value=' . $prev . ';document.findnext.submit();">' . _MD_XM_PREVIOUS . '</a>&nbsp;';
218
            }
219
            $counter = 1;
220
            $currentpage = ( $start + $limit ) / $limit;
221
            while ( $counter <= $totalpages ) {
222
                if ( $counter == $currentpage ) {
223
                    $hiddenform .= '<b>' . $counter . '</b> ';
224
                } elseif ( ( $counter > $currentpage-4 && $counter < $currentpage + 4 ) || $counter == 1 || $counter == $totalpages ) {
225
                    if ( $counter == $totalpages && $currentpage < $totalpages-4 ) {
226
                        $hiddenform .= '... ';
227
                    }
228
                    $hiddenform .= '<a href="#' . $counter . '" onclick="javascript:document.findnext.start.value=' . ( $counter-1 ) * $limit . ';document.findnext.submit();">' . $counter . '</a> ';
229
                    if ( $counter == 1 && $currentpage > 5 ) {
230
                        $hiddenform .= '... ';
231
                    }
232
                }
233
                $counter++;
234
            }
235
            $next = $start + $limit;
236
            if ( $total > $next ) {
237
                $hiddenform .= '&nbsp;<a href="#' . $total . '" onclick="javascript:document.findnext.start.value=' . $next . ';document.findnext.submit();">' . _MD_XM_NEXT . '</a>';
238
            }
239
            $hiddenform .= '</form>';
240
            $xoopsTpl->assign( 'pagenav', $hiddenform );
241
            $xoopsTpl->assign( 'lang_numfound', sprintf( _MD_XM_USERSFOUND, $total ) );
242
        }
243
    }
244
245
246
include_once XOOPS_ROOT_PATH . '/footer.php';
247
exit();
248
249
/**
250
 * xoops_Criteria()
251
 *
252
 * @return
253
 */
254 View Code Duplication
function xoops_Criteria( &$criteria, $name = '', $ret = '', $match = '' ) {
0 ignored issues
show
This function seems to be duplicated in 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...
255
    global $criteria;
256
257
    switch ( $match ) {
258
        case XOOPS_MATCH_START:
259
            $criteria->add( new Criteria( $name, $ret . '%', 'LIKE' ) );
260
            break;
261
        case XOOPS_MATCH_END:
262
            $criteria->add( new Criteria( $name, '%' . $ret . '%', 'LIKE' ) );
263
            break;
264
        case XOOPS_MATCH_EQUAL:
265
            $criteria->add( new Criteria( $name, $ret ) );
266
            break;
267
        case XOOPS_MATCH_CONTAIN:
268
            $criteria->add( new Criteria( $name, '%' . $ret . '%', 'LIKE' ) );
269
            break;
270
    }
271
}
272