Completed
Push — master ( 780aff...629710 )
by Michael
14s queued 11s
created

searchmembers.php (2 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: searchmembers.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
$op = ( isset( $_POST['op'] ) && $_POST['op'] == 'submit' ) ? 'submit' : 'form';
28
29
if ( $op == 'form' ) {
30
    $xoopsOption['template_main'] = 'xoopsmembers_searchform.tpl';
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', 'searchmembers.php' );
39
    $uname_text = new XoopsFormText( '', 'user_uname', 30, 60 );
40
    $uname_match = new XoopsFormSelectMatchOption( '', 'user_uname_match' );
41
    $uname_tray = new XoopsFormElementTray( _MD_XM_UNAME, '&nbsp;' );
42
    $uname_tray->addElement( $uname_match );
43
    $uname_tray->addElement( $uname_text );
44
    $form->addElement( $uname_tray );
45
46 View Code Duplication
    if ($xoopsModuleConfig['displayrealname'] == 1){
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...
47
    $name_text = new XoopsFormText( '', 'user_name', 30, 60 );
48
    $name_match = new XoopsFormSelectMatchOption( '', 'user_name_match' );
49
    $name_tray = new XoopsFormElementTray( _MD_XM_REALNAME, '&nbsp;' );
50
    $name_tray->addElement( $name_match );
51
    $name_tray->addElement( $name_text );
52
    $form->addElement( $name_tray );
53
    }
54
	
55 View Code Duplication
	if ($xoopsModuleConfig['displayemail'] == 1){
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...
56
    $email_text = new XoopsFormText( '', 'user_email', 30, 60 );
57
    $email_match = new XoopsFormSelectMatchOption( '', 'user_email_match' );
58
    $email_tray = new XoopsFormElementTray( _MD_XM_EMAIL, '&nbsp;' );
59
    $email_tray->addElement( $email_match );
60
    $email_tray->addElement( $email_text );
61
    $form->addElement( $email_tray );
62
    }
63
	
64
	if ($xoopsModuleConfig['displayurl'] == 1){
65
    $form->addElement( new XoopsFormText( _MD_XM_URLC, 'user_url', 30, 100 ) );
66
    }
67
	if ($xoopsModuleConfig['displayfrom'] == 1){
68
	$form->addElement( new XoopsFormText( _MD_XM_LOCATION, 'user_from', 30, 100 ) );
69
	}
70
	if ($xoopsModuleConfig['displayoccupation'] == 1){
71
    $form->addElement( new XoopsFormText( _MD_XM_OCCUPATION, 'user_occ', 30, 100 ) );
72
	}
73
	if ($xoopsModuleConfig['displayinterest'] == 1){
74
    $form->addElement( new XoopsFormText( _MD_XM_INTEREST, 'user_intrest', 30, 100 ) );
75
	}
76
	if ($xoopsModuleConfig['displaylastlogin'] == 1){
77
    $form->addElement( new XoopsFormText( _MD_XM_LASTLOGMORE, 'user_lastlog_more', 10, 5 ) );
78
    $form->addElement( new XoopsFormText( _MD_XM_LASTLOGLESS, 'user_lastlog_less', 10, 5 ) );
79
	}
80
	if ($xoopsModuleConfig['displayregdate'] == 1){
81
    $form->addElement( new XoopsFormText( _MD_XM_REGMORE, 'user_reg_more', 10, 5 ) );
82
    $form->addElement( new XoopsFormText( _MD_XM_REGLESS, 'user_reg_less', 10, 5 ) );
83
	}
84
	if ($xoopsModuleConfig['displayposts'] == 1){
85
    $form->addElement( new XoopsFormText( _MD_XM_POSTSMORE, 'user_posts_more', 10, 5 ) );
86
    $form->addElement( new XoopsFormText( _MD_XM_POSTSLESS, 'user_posts_less', 10, 5 ) );
87
	}
88
    
89
	$sort_select = new XoopsFormSelect( _MD_XM_SORT, 'user_sort' );
90
    $sort_select->addOptionArray( array( 'uname' => _MD_XM_UNAME, 'name' => _MD_XM_REALNAME, 'last_login' => _MD_XM_LASTLOGIN, 'user_regdate' => _MD_XM_REGDATE, 'posts' => _MD_XM_POSTS ) );
91
    $form->addElement( $sort_select );
92
93
    $order_select = new XoopsFormSelect( _MD_XM_ORDER, 'user_order' );
94
    $order_select->addOptionArray( array( 'ASC' => _MD_XM_ASC, 'DESC' => _MD_XM_DESC ) );
95
    $form->addElement( $order_select );
96
97
    $form->addElement( new XoopsFormText( _MD_XM_LIMIT, 'limit', 6, 2 ) );
98
    $form->addElement( new XoopsFormHidden( 'op', 'submit' ) );
99
    $form->addElement( new XoopsFormButton( '', 'user_submit', _SUBMIT, 'submit' ) );
100
    $form->assign( $xoopsTpl );
101
    $xoopsTpl->assign( 'totalmember', $total );
102
}
103
104
if ( $op == 'submit' ) {
105
    $xoopsOption['template_main'] = 'xoopsmembers_searchresults.tpl';
106
    include XOOPS_ROOT_PATH . '/header.php';
107
108
    $iamadmin = $xoopsUserIsAdmin;
109
    $myts = MyTextSanitizer::getInstance();
110
    $criteria = new CriteriaCompo();
111
112 View Code Duplication
    if ( !empty( $_POST['user_uname'] ) ) {
113
        $match = ( !empty( $_POST['user_uname_match'] ) ) ? intval( $_POST['user_uname_match'] ) : XOOPS_MATCH_START;
114
        $ret = $myts->addSlashes( trim( $_POST['user_uname'] ) );
115
        xoops_Criteria( $criteria, 'uname', $ret, $match );
116
    }
117
118 View Code Duplication
    if ( !empty( $_POST['user_name'] ) ) {
119
        $match = ( !empty( $_POST['user_name_match'] ) ) ? intval( $_POST['user_name_match'] ) : XOOPS_MATCH_START;
120
        $ret = $myts->addSlashes( trim( $_POST['user_uname'] ) );
121
        xoops_Criteria( $criteria, 'name', $ret, $match );
122
    }
123
124
    if ( !empty( $_POST['user_email'] ) ) {
125
        $match = ( !empty( $_POST['user_email_match'] ) ) ? intval( $_POST['user_email_match'] ) : XOOPS_MATCH_START;
126
        $ret = $myts->addSlashes( trim( $_POST['user_email'] ) );
127
        xoops_Criteria( $criteria, 'name', $ret, $match );
128
        if ( !$iamadmin ) {
129
            $criteria->add( new Criteria( 'user_viewemail', 1 ) );
130
        }
131
    }
132
133 View Code Duplication
    if ( !empty( $_POST['user_url'] ) ) {
134
        $url = formatURL( trim( $_POST['user_url'] ) );
135
        $criteria->add( new Criteria( 'url', $myts->addSlashes( $url ) . '%', 'LIKE' ) );
136
    }
137
138 View Code Duplication
    if ( !empty( $_POST['user_from'] ) ) {
139
        $criteria->add( new Criteria( 'user_from', '%' . $myts->addSlashes( trim( $_POST['user_from'] ) ) . '%', 'LIKE' ) );
140
    }
141
142 View Code Duplication
    if ( !empty( $_POST['user_intrest'] ) ) {
143
        $criteria->add( new Criteria( 'user_intrest', '%' . $myts->addSlashes( trim( $_POST['user_intrest'] ) ) . '%', 'LIKE' ) );
144
    }
145
146 View Code Duplication
    if ( !empty( $_POST['user_occ'] ) ) {
147
        $criteria->add( new Criteria( 'user_occ', '%' . $myts->addSlashes( trim( $_POST['user_occ'] ) ) . '%', 'LIKE' ) );
148
    }
149
150 View Code Duplication
    if ( !empty( $_POST['user_lastlog_more'] ) && is_numeric( $_POST['user_lastlog_more'] ) ) {
151
        $f_user_lastlog_more = intval( trim( $_POST['user_lastlog_more'] ) );
152
        $time = time() - ( 60 * 60 * 24 * $f_user_lastlog_more );
153
        if ( $time > 0 ) {
154
            $criteria->add( new Criteria( 'last_login', $time, '<' ) );
155
        }
156
    }
157
158 View Code Duplication
    if ( !empty( $_POST['user_lastlog_less'] ) && is_numeric( $_POST['user_lastlog_less'] ) ) {
159
        $f_user_lastlog_less = intval( trim( $_POST['user_lastlog_less'] ) );
160
        $time = time() - ( 60 * 60 * 24 * $f_user_lastlog_less );
161
        if ( $time > 0 ) {
162
            $criteria->add( new Criteria( 'last_login', $time, '>' ) );
163
        }
164
    }
165
166 View Code Duplication
    if ( !empty( $_POST['user_reg_more'] ) && is_numeric( $_POST['user_reg_more'] ) ) {
167
        $f_user_reg_more = intval( trim( $_POST['user_reg_more'] ) );
168
        $time = time() - ( 60 * 60 * 24 * $f_user_reg_more );
169
        if ( $time > 0 ) {
170
            $criteria->add( new Criteria( 'user_regdate', $time, '<' ) );
171
        }
172
    }
173
174 View Code Duplication
    if ( !empty( $_POST['user_reg_less'] ) && is_numeric( $_POST['user_reg_less'] ) ) {
175
        $f_user_reg_less = intval( $_POST['user_reg_less'] );
176
        $time = time() - ( 60 * 60 * 24 * $f_user_reg_less );
177
        if ( $time > 0 ) {
178
            $criteria->add( new Criteria( 'user_regdate', $time, '>' ) );
179
        }
180
    }
181
182 View Code Duplication
    if ( isset( $_POST['user_posts_more'] ) && is_numeric( $_POST['user_posts_more'] ) ) {
183
        $criteria->add( new Criteria( 'posts', intval( $_POST['user_posts_more'] ), '>' ) );
184
    }
185
186 View Code Duplication
    if ( !empty( $_POST['user_posts_less'] ) && is_numeric( $_POST['user_posts_less'] ) ) {
187
        $criteria->add( new Criteria( 'posts', intval( $_POST['user_posts_less'] ), '<' ) );
188
    }
189
190
    $criteria->add( new Criteria( 'level', 0, '>' ) );
191
    $validsort = array( 'uname', 'email', 'last_login', 'user_regdate', 'posts' );
192
    $sort = ( !in_array( $_POST['user_sort'], $validsort ) ) ? 'uname' : $_POST['user_sort'];
193
    $order = 'ASC';
194
    if ( isset( $_POST['user_order'] ) && $_POST['user_order'] == 'DESC' ) {
195
        $order = 'DESC';
196
    }
197
    $limit = ( !empty( $_POST['limit'] ) ) ? intval( $_POST['limit'] ) : 20;
198
    if ( $limit == 0 || $limit > 50 ) {
199
        $limit = 50;
200
    }
201
202
    $start = ( !empty( $_POST['start'] ) ) ? intval( $_POST['start'] ) : 0;
203
    $member_handler = xoops_gethandler( 'member' );
204
    $total = $member_handler->getUserCount( $criteria );
205
    $xoopsTpl->assign( 'total_found', $total );
206
207 View Code Duplication
    if ( $total == 0 ) {
208
    } elseif ( $start < $total ) {
209
        if ( $iamadmin ) {
210
            $xoopsTpl->assign( 'is_admin', true );
211
        }
212
        $criteria->setSort( $sort );
213
        $criteria->setOrder( $order );
214
        $criteria->setStart( $start );
215
        $criteria->setLimit( $limit );
216
        $foundusers = $member_handler->getUsers( $criteria, true );
217
        foreach ( array_keys( $foundusers ) as $j ) {
218
            $userdata["avatar"] = $foundusers[$j]->getVar( 'user_avatar' ) ? '<img src="' . XOOPS_UPLOAD_URL . '/' . $foundusers[$j]->getVar( 'user_avatar' ) . '" alt="" />' : '&nbsp;';
219
            $userdata["realname"] = $foundusers[$j]->getVar( 'name' ) ? $foundusers[$j]->getVar( 'name' ) : '&nbsp;';
220
            $userdata["name"] = $foundusers[$j]->getVar( 'uname' );
221
            $userdata["id"] = $foundusers[$j]->getVar( 'uid' );
222
            if ( $foundusers[$j]->getVar( 'user_viewemail' ) == 1 || $iamadmin ) {
223
                $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>';
224
            } else {
225
                $userdata["email"] = '&nbsp;';
226
            }
227
            if ( $xoopsUser ) {
228
                $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>';
229
            } else {
230
                $userdata["pmlink"] = '&nbsp;';
231
            }
232
            if ( $foundusers[$j]->getVar( 'url', "e" ) != '' ) {
233
                $userdata["website"] = '<a href="' . $foundusers[$j]->getVar( 'url', "e" ) . '" target="_blank"><img src="' . XOOPS_URL . '/images/icons/www.gif" border="0" alt="' . _VISITWEBSITE . '" /></a>';
234
            } else {
235
                $userdata["website"] = '&nbsp;';
236
            }
237
            $userdata["registerdate"] = formatTimeStamp( $foundusers[$j]->getVar( 'user_regdate' ), 's' );
238
            if ( $foundusers[$j]->getVar( 'last_login' ) != 0 ) {
239
                $userdata["lastlogin"] = formatTimeStamp( $foundusers[$j]->getVar( 'last_login' ), "m" );
240
            } else {
241
                $userdata["lastlogin"] = '&nbsp;';
242
            }
243
            $userdata["posts"] = $foundusers[$j]->getVar( 'posts' );
244
            if ( $iamadmin ) {
245
                $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 . "' />"
246
247
                . '</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>';
248
            }
249
            $xoopsTpl->append( "users", $userdata );
250
        }
251
252
        $totalpages = ceil( $total / $limit );
253
        if ( $totalpages > 1 ) {
254
            $hiddenform = '<form name="findnext" action="searchmembers.php" method="post">';
255
            foreach ( $_POST as $k => $v ) {
256
                $hiddenform .= '<input type="hidden" name="' . $myts->htmlSpecialChars( $k ) . '" value="' . $myts->previewTarea( $v ) . '" />';
257
            }
258
            if ( !isset( $_POST['limit'] ) ) {
259
                $hiddenform .= '<input type="hidden" name="limit" value="' . $limit . '" />';
260
            }
261
            if ( !isset( $_POST['start'] ) ) {
262
                $hiddenform .= '<input type="hidden" name="start" value="' . $start . '" />';
263
            }
264
            $prev = $start - $limit;
265
            if ( $start - $limit >= 0 ) {
266
                $hiddenform .= '<a href="#0" onclick="javascript:document.findnext.start.value=' . $prev . ';document.findnext.submit();">' . _MD_XM_PREVIOUS . '</a>&nbsp;';
267
            }
268
            $counter = 1;
269
            $currentpage = ( $start + $limit ) / $limit;
270
            while ( $counter <= $totalpages ) {
271
                if ( $counter == $currentpage ) {
272
                    $hiddenform .= '<b>' . $counter . '</b> ';
273
                } elseif ( ( $counter > $currentpage-4 && $counter < $currentpage + 4 ) || $counter == 1 || $counter == $totalpages ) {
274
                    if ( $counter == $totalpages && $currentpage < $totalpages-4 ) {
275
                        $hiddenform .= '... ';
276
                    }
277
                    $hiddenform .= '<a href="#' . $counter . '" onclick="javascript:document.findnext.start.value=' . ( $counter-1 ) * $limit . ';document.findnext.submit();">' . $counter . '</a> ';
278
                    if ( $counter == 1 && $currentpage > 5 ) {
279
                        $hiddenform .= '... ';
280
                    }
281
                }
282
                $counter++;
283
            }
284
            $next = $start + $limit;
285
            if ( $total > $next ) {
286
                $hiddenform .= '&nbsp;<a href="#' . $total . '" onclick="javascript:document.findnext.start.value=' . $next . ';document.findnext.submit();">' . _MD_XM_NEXT . '</a>';
287
            }
288
            $hiddenform .= '</form>';
289
            $xoopsTpl->assign( 'pagenav', $hiddenform );
290
            $xoopsTpl->assign( 'lang_numfound', sprintf( _MD_XM_USERSFOUND, $total ) );
291
        }
292
    }
293
}
294
295
include 'footer.php';
296
include_once XOOPS_ROOT_PATH . '/footer.php';
297
exit();
298
299
/**
300
 * xoops_Criteria()
301
 *
302
 * @return
303
 */
304 View Code Duplication
function xoops_Criteria( &$criteria, $name = '', $ret = '', $match = '' ) {
305
    global $criteria;
306
307
    switch ( $match ) {
308
        case XOOPS_MATCH_START:
309
            $criteria->add( new Criteria( $name, $ret . '%', 'LIKE' ) );
310
            break;
311
        case XOOPS_MATCH_END:
312
            $criteria->add( new Criteria( $name, '%' . $ret . '%', 'LIKE' ) );
313
            break;
314
        case XOOPS_MATCH_EQUAL:
315
            $criteria->add( new Criteria( $name, $ret ) );
316
            break;
317
        case XOOPS_MATCH_CONTAIN:
318
            $criteria->add( new Criteria( $name, '%' . $ret . '%', 'LIKE' ) );
319
            break;
320
    }
321
}
322