Completed
Push — master ( ff4558...64abdf )
by Michael
01:19
created

index.php (1 issue)

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';
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
22
//global $pathIcon16;
23
24
global $xoopsModule;
25
$pathIcon16 = $xoopsModule->getInfo('icons16');
26
27
$op = ( isset( $_POST['op'] ) && $_POST['op'] == 'submit' ) ? 'submit' : 'form';
28
29
if ( $op == 'form' ) {
30
    $xoopsOption['template_main'] = 'xoopsmembers_searchform.html';
31
    include XOOPS_ROOT_PATH . '/header.php';
32
33
    $member_handler = &xoops_gethandler( 'member' );
34
    $total = $member_handler->getUserCount( new Criteria( 'level', 0, '>' ) );
35
36
    include_once XOOPS_ROOT_PATH . "/class/xoopsformloader.php";
37
38
    $form = new XoopsThemeForm( '', 'searchform', 'index.php' );
39
    $uname_text = new XoopsFormText( '', 'user_uname', 30, 60 );
40
    $uname_match = new XoopsFormSelectMatchOption( '', 'user_uname_match' );
41
    $uname_tray = new XoopsFormElementTray( _XO_LA_UNAME, '&nbsp;' );
42
    $uname_tray->addElement( $uname_match );
43
    $uname_tray->addElement( $uname_text );
44
    $form->addElement( $uname_tray );
45
46
    $name_text = new XoopsFormText( '', 'user_name', 30, 60 );
47
    $name_match = new XoopsFormSelectMatchOption( '', 'user_name_match' );
48
    $name_tray = new XoopsFormElementTray( _XO_LA_REALNAME, '&nbsp;' );
49
    $name_tray->addElement( $name_match );
50
    $name_tray->addElement( $name_text );
51
    $form->addElement( $name_tray );
52
53
    $email_text = new XoopsFormText( '', 'user_email', 30, 60 );
54
    $email_match = new XoopsFormSelectMatchOption( '', 'user_email_match' );
55
    $email_tray = new XoopsFormElementTray( _XO_LA_EMAIL, '&nbsp;' );
56
    $email_tray->addElement( $email_match );
57
    $email_tray->addElement( $email_text );
58
    $form->addElement( $email_tray );
59
60
    $form->addElement( new XoopsFormText( _XO_LA_URLC, 'user_url', 30, 100 ) );
61
62
    $icq_text = new XoopsFormText( '', 'user_icq', 30, 100 );
63
    $icq_match = new XoopsFormSelectMatchOption( '', 'user_icq_match' );
64
    $icq_tray = new XoopsFormElementTray( _XO_LA_ICQ, '&nbsp;' );
65
    $icq_tray->addElement( $icq_match );
66
    $icq_tray->addElement( $icq_text );
67
    $form->addElement( $icq_tray );
68
69
    $aim_text = new XoopsFormText( '', 'user_aim', 30, 100 );
70
    $aim_match = new XoopsFormSelectMatchOption( '', 'user_aim_match' );
71
    $aim_tray = new XoopsFormElementTray( _XO_LA_AIM, '&nbsp;' );
72
    $aim_tray->addElement( $aim_match );
73
    $aim_tray->addElement( $aim_text );
74
    $form->addElement( $aim_tray );
75
76
    $yim_text = new XoopsFormText( '', 'user_yim', 30, 100 );
77
    $yim_match = new XoopsFormSelectMatchOption( '', 'user_yim_match' );
78
    $yim_tray = new XoopsFormElementTray( _XO_LA_YIM, '&nbsp;' );
79
    $yim_tray->addElement( $yim_match );
80
    $yim_tray->addElement( $yim_text );
81
    $form->addElement( $yim_tray );
82
83
    $msnm_text = new XoopsFormText( '', 'user_msnm', 30, 100 );
84
    $msnm_match = new XoopsFormSelectMatchOption( '', 'user_msnm_match' );
85
    $msnm_tray = new XoopsFormElementTray( _XO_LA_MSNM, '&nbsp;' );
86
    $msnm_tray->addElement( $msnm_match );
87
    $msnm_tray->addElement( $msnm_text );
88
    $form->addElement( $msnm_tray );
89
90
    $form->addElement( new XoopsFormText( _XO_LA_LOCATION, 'user_from', 30, 100 ) );
91
    $form->addElement( new XoopsFormText( _XO_LA_OCCUPATION, 'user_occ', 30, 100 ) );
92
    $form->addElement( new XoopsFormText( _XO_LA_INTEREST, 'user_intrest', 30, 100 ) );
93
    $form->addElement( new XoopsFormText( _XO_LA_LASTLOGMORE, 'user_lastlog_more', 10, 5 ) );
94
    $form->addElement( new XoopsFormText( _XO_LA_LASTLOGLESS, 'user_lastlog_less', 10, 5 ) );
95
    $form->addElement( new XoopsFormText( _XO_LA_REGMORE, 'user_reg_more', 10, 5 ) );
96
    $form->addElement( new XoopsFormText( _XO_LA_REGLESS, 'user_reg_less', 10, 5 ) );
97
    $form->addElement( new XoopsFormText( _XO_LA_POSTSMORE, 'user_posts_more', 10, 5 ) );
98
    $form->addElement( new XoopsFormText( _XO_LA_POSTSLESS, 'user_posts_less', 10, 5 ) );
99
100
    $sort_select = new XoopsFormSelect( _XO_LA_SORT, 'user_sort' );
101
    $sort_select->addOptionArray( array( 'uname' => _XO_LA_UNAME, 'email' => _XO_LA_EMAIL, 'last_login' => _XO_LA_LASTLOGIN, 'user_regdate' => _XO_LA_REGDATE, 'posts' => _XO_LA_POSTS ) );
102
    $form->addElement( $sort_select );
103
104
    $order_select = new XoopsFormSelect( _XO_LA_ORDER, 'user_order' );
105
    $order_select->addOptionArray( array( 'ASC' => _XO_LA_ASC, 'DESC' => _XO_LA_DESC ) );
106
    $form->addElement( $order_select );
107
108
    $form->addElement( new XoopsFormText( _XO_LA_LIMIT, 'limit', 6, 2 ) );
109
    $form->addElement( new XoopsFormHidden( 'op', 'submit' ) );
110
    $form->addElement( new XoopsFormButton( '', 'user_submit', _SUBMIT, 'submit' ) );
111
    $form->assign( $xoopsTpl );
112
    $xoopsTpl->assign( 'totalmember', $total );
113
}
114
115
if ( $op == 'submit' ) {
116
    $xoopsOption['template_main'] = 'xoopsmembers_searchresults.html';
117
    include XOOPS_ROOT_PATH . '/header.php';
118
119
    $iamadmin = $xoopsUserIsAdmin;
120
    $myts = &MyTextSanitizer::getInstance();
121
    $criteria = new CriteriaCompo();
122
123 View Code Duplication
    if ( !empty( $_POST['user_uname'] ) ) {
124
        $match = ( !empty( $_POST['user_uname_match'] ) ) ? intval( $_POST['user_uname_match'] ) : XOOPS_MATCH_START;
125
        $ret = $myts->addSlashes( trim( $_POST['user_uname'] ) );
126
        xoops_Criteria( $criteria, 'uname', $ret, $match );
127
    }
128
129 View Code Duplication
    if ( !empty( $_POST['user_name'] ) ) {
130
        $match = ( !empty( $_POST['user_name_match'] ) ) ? intval( $_POST['user_name_match'] ) : XOOPS_MATCH_START;
131
        $ret = $myts->addSlashes( trim( $_POST['user_uname'] ) );
132
        xoops_Criteria( $criteria, 'name', $ret, $match );
133
    }
134
135
    if ( !empty( $_POST['user_email'] ) ) {
136
        $match = ( !empty( $_POST['user_email_match'] ) ) ? intval( $_POST['user_email_match'] ) : XOOPS_MATCH_START;
137
        $ret = $myts->addSlashes( trim( $_POST['user_email'] ) );
138
        xoops_Criteria( $criteria, 'name', $ret, $match );
139
        if ( !$iamadmin ) {
140
            $criteria->add( new Criteria( 'user_viewemail', 1 ) );
141
        }
142
    }
143
144 View Code Duplication
    if ( !empty( $_POST['user_url'] ) ) {
145
        $url = formatURL( trim( $_POST['user_url'] ) );
146
        $criteria->add( new Criteria( 'url', $myts->addSlashes( $url ) . '%', 'LIKE' ) );
147
    }
148
149 View Code Duplication
    if ( !empty( $_POST['user_icq'] ) ) {
150
        $match = ( !empty( $_POST['user_icq_match'] ) ) ? intval( $_POST['user_icq_match'] ) : XOOPS_MATCH_START;
151
        $ret = $myts->addSlashes( trim( $_POST['user_icq'] ) );
152
        xoops_Criteria( $criteria, 'user_icq', $ret, $match );
153
    }
154
155 View Code Duplication
    if ( !empty( $_POST['user_aim'] ) ) {
156
        $match = ( !empty( $_POST['user_aim_match'] ) ) ? intval( $_POST['user_aim_match'] ) : XOOPS_MATCH_START;
157
        $ret = $myts->addSlashes( trim( $_POST['user_aim'] ) );
158
        xoops_Criteria( $criteria, 'user_aim', $ret, $match );
159
    }
160
161 View Code Duplication
    if ( !empty( $_POST['user_yim'] ) ) {
162
        $match = ( !empty( $_POST['user_yim_match'] ) ) ? intval( $_POST['user_yim_match'] ) : XOOPS_MATCH_START;
163
        $ret = $myts->addSlashes( trim( $_POST['user_yim'] ) );
164
        xoops_Criteria( $criteria, 'user_yim', $ret, $match );
165
    }
166
167 View Code Duplication
    if ( !empty( $_POST['user_msnm'] ) ) {
168
        $match = ( !empty( $_POST['user_msnm_match'] ) ) ? intval( $_POST['user_msnm_match'] ) : XOOPS_MATCH_START;
169
        $ret = $myts->addSlashes( trim( $_POST['user_msnm'] ) );
170
        xoops_Criteria( $criteria, 'user_msnm', $ret, $match );
171
    }
172
173 View Code Duplication
    if ( !empty( $_POST['user_from'] ) ) {
174
        $criteria->add( new Criteria( 'user_from', '%' . $myts->addSlashes( trim( $_POST['user_from'] ) ) . '%', 'LIKE' ) );
175
    }
176
177 View Code Duplication
    if ( !empty( $_POST['user_intrest'] ) ) {
178
        $criteria->add( new Criteria( 'user_intrest', '%' . $myts->addSlashes( trim( $_POST['user_intrest'] ) ) . '%', 'LIKE' ) );
179
    }
180
181 View Code Duplication
    if ( !empty( $_POST['user_occ'] ) ) {
182
        $criteria->add( new Criteria( 'user_occ', '%' . $myts->addSlashes( trim( $_POST['user_occ'] ) ) . '%', 'LIKE' ) );
183
    }
184
185 View Code Duplication
    if ( !empty( $_POST['user_lastlog_more'] ) && is_numeric( $_POST['user_lastlog_more'] ) ) {
186
        $f_user_lastlog_more = intval( trim( $_POST['user_lastlog_more'] ) );
187
        $time = time() - ( 60 * 60 * 24 * $f_user_lastlog_more );
188
        if ( $time > 0 ) {
189
            $criteria->add( new Criteria( 'last_login', $time, '<' ) );
190
        }
191
    }
192
193 View Code Duplication
    if ( !empty( $_POST['user_lastlog_less'] ) && is_numeric( $_POST['user_lastlog_less'] ) ) {
194
        $f_user_lastlog_less = intval( trim( $_POST['user_lastlog_less'] ) );
195
        $time = time() - ( 60 * 60 * 24 * $f_user_lastlog_less );
196
        if ( $time > 0 ) {
197
            $criteria->add( new Criteria( 'last_login', $time, '>' ) );
198
        }
199
    }
200
201 View Code Duplication
    if ( !empty( $_POST['user_reg_more'] ) && is_numeric( $_POST['user_reg_more'] ) ) {
202
        $f_user_reg_more = intval( trim( $_POST['user_reg_more'] ) );
203
        $time = time() - ( 60 * 60 * 24 * $f_user_reg_more );
204
        if ( $time > 0 ) {
205
            $criteria->add( new Criteria( 'user_regdate', $time, '<' ) );
206
        }
207
    }
208
209 View Code Duplication
    if ( !empty( $_POST['user_reg_less'] ) && is_numeric( $_POST['user_reg_less'] ) ) {
210
        $f_user_reg_less = intval( $_POST['user_reg_less'] );
211
        $time = time() - ( 60 * 60 * 24 * $f_user_reg_less );
212
        if ( $time > 0 ) {
213
            $criteria->add( new Criteria( 'user_regdate', $time, '>' ) );
214
        }
215
    }
216
217 View Code Duplication
    if ( isset( $_POST['user_posts_more'] ) && is_numeric( $_POST['user_posts_more'] ) ) {
218
        $criteria->add( new Criteria( 'posts', intval( $_POST['user_posts_more'] ), '>' ) );
219
    }
220
221 View Code Duplication
    if ( !empty( $_POST['user_posts_less'] ) && is_numeric( $_POST['user_posts_less'] ) ) {
222
        $criteria->add( new Criteria( 'posts', intval( $_POST['user_posts_less'] ), '<' ) );
223
    }
224
225
    $criteria->add( new Criteria( 'level', 0, '>' ) );
226
    $validsort = array( 'uname', 'email', 'last_login', 'user_regdate', 'posts' );
227
    $sort = ( !in_array( $_POST['user_sort'], $validsort ) ) ? 'uname' : $_POST['user_sort'];
228
    $order = 'ASC';
229
    if ( isset( $_POST['user_order'] ) && $_POST['user_order'] == 'DESC' ) {
230
        $order = 'DESC';
231
    }
232
    $limit = ( !empty( $_POST['limit'] ) ) ? intval( $_POST['limit'] ) : 20;
233
    if ( $limit == 0 || $limit > 50 ) {
234
        $limit = 50;
235
    }
236
237
    $start = ( !empty( $_POST['start'] ) ) ? intval( $_POST['start'] ) : 0;
238
    $member_handler = &xoops_gethandler( 'member' );
239
    $total = $member_handler->getUserCount( $criteria );
240
    $xoopsTpl->assign( 'total_found', $total );
241
242
    if ( $total == 0 ) {
243
    } elseif ( $start < $total ) {
244
        if ( $iamadmin ) {
245
            $xoopsTpl->assign( 'is_admin', true );
246
        }
247
        $criteria->setSort( $sort );
248
        $criteria->setOrder( $order );
249
        $criteria->setStart( $start );
250
        $criteria->setLimit( $limit );
251
        $foundusers = &$member_handler->getUsers( $criteria, true );
252
        foreach ( array_keys( $foundusers ) as $j ) {
253
            $userdata["avatar"] = $foundusers[$j]->getVar( 'user_avatar' ) ? '<img src="' . XOOPS_UPLOAD_URL . '/' . $foundusers[$j]->getVar( 'user_avatar' ) . '" alt="" />' : '&nbsp;';
254
            $userdata["realname"] = $foundusers[$j]->getVar( 'name' ) ? $foundusers[$j]->getVar( 'name' ) : '&nbsp;';
255
            $userdata["name"] = $foundusers[$j]->getVar( 'uname' );
256
            $userdata["id"] = $foundusers[$j]->getVar( 'uid' );
257
            if ( $foundusers[$j]->getVar( 'user_viewemail' ) == 1 || $iamadmin ) {
258
                $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>';
259
            } else {
260
                $userdata["email"] = '&nbsp;';
261
            }
262
            if ( $xoopsUser ) {
263
                $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>';
264
            } else {
265
                $userdata["pmlink"] = '&nbsp;';
266
            }
267
            if ( $foundusers[$j]->getVar( 'url', "e" ) != '' ) {
268
                $userdata["website"] = '<a href="' . $foundusers[$j]->getVar( 'url', "e" ) . '" target="_blank"><img src="' . XOOPS_URL . '/images/icons/www.gif" border="0" alt="' . _VISITWEBSITE . '" /></a>';
269
            } else {
270
                $userdata["website"] = '&nbsp;';
271
            }
272
            $userdata["registerdate"] = formatTimeStamp( $foundusers[$j]->getVar( 'user_regdate' ), 's' );
273
            if ( $foundusers[$j]->getVar( 'last_login' ) != 0 ) {
274
                $userdata["lastlogin"] = formatTimeStamp( $foundusers[$j]->getVar( 'last_login' ), "m" );
275
            } else {
276
                $userdata["lastlogin"] = '&nbsp;';
277
            }
278
            $userdata["posts"] = $foundusers[$j]->getVar( 'posts' );
279
            if ( $iamadmin ) {
280
                $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 . "' />"
281
282
                . '</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>';
283
            }
284
            $xoopsTpl->append( "users", $userdata );
285
        }
286
287
        $totalpages = ceil( $total / $limit );
288
        if ( $totalpages > 1 ) {
289
            $hiddenform = '<form name="findnext" action="index.php" method="post">';
290
            foreach ( $_POST as $k => $v ) {
291
                $hiddenform .= '<input type="hidden" name="' . $myts->htmlSpecialChars( $k ) . '" value="' . $myts->previewTarea( $v ) . '" />';
292
            }
293
            if ( !isset( $_POST['limit'] ) ) {
294
                $hiddenform .= '<input type="hidden" name="limit" value="' . $limit . '" />';
295
            }
296
            if ( !isset( $_POST['start'] ) ) {
297
                $hiddenform .= '<input type="hidden" name="start" value="' . $start . '" />';
298
            }
299
            $prev = $start - $limit;
300
            if ( $start - $limit >= 0 ) {
301
                $hiddenform .= '<a href="#0" onclick="javascript:document.findnext.start.value=' . $prev . ';document.findnext.submit();">' . _XO_LA_PREVIOUS . '</a>&nbsp;';
302
            }
303
            $counter = 1;
304
            $currentpage = ( $start + $limit ) / $limit;
305
            while ( $counter <= $totalpages ) {
306
                if ( $counter == $currentpage ) {
307
                    $hiddenform .= '<b>' . $counter . '</b> ';
308
                } elseif ( ( $counter > $currentpage-4 && $counter < $currentpage + 4 ) || $counter == 1 || $counter == $totalpages ) {
309
                    if ( $counter == $totalpages && $currentpage < $totalpages-4 ) {
310
                        $hiddenform .= '... ';
311
                    }
312
                    $hiddenform .= '<a href="#' . $counter . '" onclick="javascript:document.findnext.start.value=' . ( $counter-1 ) * $limit . ';document.findnext.submit();">' . $counter . '</a> ';
313
                    if ( $counter == 1 && $currentpage > 5 ) {
314
                        $hiddenform .= '... ';
315
                    }
316
                }
317
                $counter++;
318
            }
319
            $next = $start + $limit;
320
            if ( $total > $next ) {
321
                $hiddenform .= '&nbsp;<a href="#' . $total . '" onclick="javascript:document.findnext.start.value=' . $next . ';document.findnext.submit();">' . _XO_LA_NEXT . '</a>';
322
            }
323
            $hiddenform .= '</form>';
324
            $xoopsTpl->assign( 'pagenav', $hiddenform );
325
            $xoopsTpl->assign( 'lang_numfound', sprintf( _XO_LA_USERSFOUND, $total ) );
326
        }
327
    }
328
}
329
330
include_once XOOPS_ROOT_PATH . '/footer.php';
331
exit();
332
333
/**
334
 * xoops_Criteria()
335
 *
336
 * @return
337
 */
338
function xoops_Criteria( &$criteria, $name = '', $ret = '', $match = '' ) {
339
    global $criteria;
340
341
    switch ( $match ) {
342
        case XOOPS_MATCH_START:
343
            $criteria->add( new Criteria( $name, $ret . '%', 'LIKE' ) );
344
            break;
345
        case XOOPS_MATCH_END:
346
            $criteria->add( new Criteria( $name, '%' . $ret . '%', 'LIKE' ) );
347
            break;
348
        case XOOPS_MATCH_EQUAL:
349
            $criteria->add( new Criteria( $name, $ret ) );
350
            break;
351
        case XOOPS_MATCH_CONTAIN:
352
            $criteria->add( new Criteria( $name, '%' . $ret . '%', 'LIKE' ) );
353
            break;
354
    }
355
}
356