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

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

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
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...
286
    global $criteria;
287
288
    switch ( $match ) {
289
        case XOOPS_MATCH_START:
290
            $criteria->add( new Criteria( $name, $ret . '%', 'LIKE' ) );
291
            break;
292
        case XOOPS_MATCH_END:
293
            $criteria->add( new Criteria( $name, '%' . $ret . '%', 'LIKE' ) );
294
            break;
295
        case XOOPS_MATCH_EQUAL:
296
            $criteria->add( new Criteria( $name, $ret ) );
297
            break;
298
        case XOOPS_MATCH_CONTAIN:
299
            $criteria->add( new Criteria( $name, '%' . $ret . '%', 'LIKE' ) );
300
            break;
301
    }
302
}
303