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

index.php (15 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_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...
64
        $criteria->add( new Criteria( 'user_from', '%' . $myts->addSlashes( trim( $_POST['user_from'] ) ) . '%', 'LIKE' ) );
65
    }
66
67 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...
68
        $criteria->add( new Criteria( 'user_intrest', '%' . $myts->addSlashes( trim( $_POST['user_intrest'] ) ) . '%', 'LIKE' ) );
69
    }
70
71 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...
72
        $criteria->add( new Criteria( 'user_occ', '%' . $myts->addSlashes( trim( $_POST['user_occ'] ) ) . '%', 'LIKE' ) );
73
    }
74
75 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...
76
        $f_user_lastlog_more = intval( trim( $_POST['user_lastlog_more'] ) );
77
        $time = time() - ( 60 * 60 * 24 * $f_user_lastlog_more );
78
        if ( $time > 0 ) {
79
            $criteria->add( new Criteria( 'last_login', $time, '<' ) );
80
        }
81
    }
82
83 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...
84
        $f_user_lastlog_less = intval( trim( $_POST['user_lastlog_less'] ) );
85
        $time = time() - ( 60 * 60 * 24 * $f_user_lastlog_less );
86
        if ( $time > 0 ) {
87
            $criteria->add( new Criteria( 'last_login', $time, '>' ) );
88
        }
89
    }
90
91 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...
92
        $f_user_reg_more = intval( trim( $_POST['user_reg_more'] ) );
93
        $time = time() - ( 60 * 60 * 24 * $f_user_reg_more );
94
        if ( $time > 0 ) {
95
            $criteria->add( new Criteria( 'user_regdate', $time, '<' ) );
96
        }
97
    }
98
99 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...
100
        $f_user_reg_less = intval( $_POST['user_reg_less'] );
101
        $time = time() - ( 60 * 60 * 24 * $f_user_reg_less );
102
        if ( $time > 0 ) {
103
            $criteria->add( new Criteria( 'user_regdate', $time, '>' ) );
104
        }
105
    }
106
107 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...
108
        $criteria->add( new Criteria( 'posts', intval( $_POST['user_posts_more'] ), '>' ) );
109
    }
110
111 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...
112
        $criteria->add( new Criteria( 'posts', intval( $_POST['user_posts_less'] ), '<' ) );
113
    }
114
115
    $criteria->add( new Criteria( 'level', 0, '>' ) );
116
    $validsort = array( 'uname', 'name', 'last_login', 'user_regdate', 'posts' );
117
    $sort = ( !in_array( $xoopsModuleConfig['sortmembers'], $validsort ) ) ? 'uname' : $xoopsModuleConfig['sortmembers'];
118
    
119
	$order = 'ASC';
120
    if ( isset( $xoopsModuleConfig['membersorder'] ) && $xoopsModuleConfig['membersorder'] == 'DESC' ) {
121
        $order = 'DESC';
122
    }
123
    $limit = ( !empty( $xoopsModuleConfig['membersperpage'] ) ) ? intval( $xoopsModuleConfig['membersperpage'] ) : 20;
124
	if ( $limit == 0 || $limit > 50 ) {
125
        $limit = 50;
126
    }
127
128
    $start = ( !empty( $_POST['start'] ) ) ? intval( $_POST['start'] ) : 0;
129
    $member_handler = xoops_gethandler( 'member' );
130
    $total = $member_handler->getUserCount( $criteria );
131
    $xoopsTpl->assign( 'total_found', $total );
132
	$xoopsTpl->assign( 'totalmember', $total );
133
134 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...
135
    } elseif ( $start < $total ) {
136
        if ( $iamadmin ) {
137
            $xoopsTpl->assign( 'is_admin', true );
138
        }
139
        $criteria->setSort( $sort );
140
        $criteria->setOrder( $order );
141
        $criteria->setStart( $start );
142
        $criteria->setLimit( $limit );
143
        $foundusers = $member_handler->getUsers( $criteria, true );
144
        foreach ( array_keys( $foundusers ) as $j ) {
145
            $userdata["avatar"] = $foundusers[$j]->getVar( 'user_avatar' ) ? '<img src="' . XOOPS_UPLOAD_URL . '/' . $foundusers[$j]->getVar( 'user_avatar' ) . '" alt="" />' : '&nbsp;';
146
            $userdata["realname"] = $foundusers[$j]->getVar( 'name' ) ? $foundusers[$j]->getVar( 'name' ) : '&nbsp;';
147
            $userdata["name"] = $foundusers[$j]->getVar( 'uname' );
148
            $userdata["id"] = $foundusers[$j]->getVar( 'uid' );
149
            if ( $foundusers[$j]->getVar( 'user_viewemail' ) == 1 || $iamadmin ) {
150
                $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>';
151
            } else {
152
                $userdata["email"] = '&nbsp;';
153
            }
154
            if ( $xoopsUser ) {
155
                $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>';
156
            } else {
157
                $userdata["pmlink"] = '&nbsp;';
158
            }
159
            if ( $foundusers[$j]->getVar( 'url', "e" ) != '' ) {
160
                $userdata["website"] = '<a href="' . $foundusers[$j]->getVar( 'url', "e" ) . '" target="_blank"><img src="' . XOOPS_URL . '/images/icons/www.gif" border="0" alt="' . _VISITWEBSITE . '" /></a>';
161
            } else {
162
                $userdata["website"] = '&nbsp;';
163
            }
164
            $userdata["registerdate"] = formatTimeStamp( $foundusers[$j]->getVar( 'user_regdate' ), 's' );
165
            if ( $foundusers[$j]->getVar( 'last_login' ) != 0 ) {
166
                $userdata["lastlogin"] = formatTimeStamp( $foundusers[$j]->getVar( 'last_login' ), "m" );
167
            } else {
168
                $userdata["lastlogin"] = '&nbsp;';
169
            }
170
            $userdata["posts"] = $foundusers[$j]->getVar( 'posts' );
171
            if ( $iamadmin ) {
172
                $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 . "' />"
173
174
                . '</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>';
175
            }
176
            $xoopsTpl->append( "users", $userdata );
177
        }
178
179
        $totalpages = ceil( $total / $limit );
180
        if ( $totalpages > 1 ) {
181
            $hiddenform = '<form name="findnext" action="index.php" method="post">';
182
            foreach ( $_POST as $k => $v ) {
183
                $hiddenform .= '<input type="hidden" name="' . $myts->htmlSpecialChars( $k ) . '" value="' . $myts->previewTarea( $v ) . '" />';
184
            }
185
            if ( !isset( $_POST['limit'] ) ) {
186
                $hiddenform .= '<input type="hidden" name="limit" value="' . $limit . '" />';
187
            }
188
            if ( !isset( $_POST['start'] ) ) {
189
                $hiddenform .= '<input type="hidden" name="start" value="' . $start . '" />';
190
            }
191
            $prev = $start - $limit;
192
            if ( $start - $limit >= 0 ) {
193
                $hiddenform .= '<a href="#0" onclick="javascript:document.findnext.start.value=' . $prev . ';document.findnext.submit();">' . _MD_XM_PREVIOUS . '</a>&nbsp;';
194
            }
195
            $counter = 1;
196
            $currentpage = ( $start + $limit ) / $limit;
197
            while ( $counter <= $totalpages ) {
198
                if ( $counter == $currentpage ) {
199
                    $hiddenform .= '<b>' . $counter . '</b> ';
200
                } elseif ( ( $counter > $currentpage-4 && $counter < $currentpage + 4 ) || $counter == 1 || $counter == $totalpages ) {
201
                    if ( $counter == $totalpages && $currentpage < $totalpages-4 ) {
202
                        $hiddenform .= '... ';
203
                    }
204
                    $hiddenform .= '<a href="#' . $counter . '" onclick="javascript:document.findnext.start.value=' . ( $counter-1 ) * $limit . ';document.findnext.submit();">' . $counter . '</a> ';
205
                    if ( $counter == 1 && $currentpage > 5 ) {
206
                        $hiddenform .= '... ';
207
                    }
208
                }
209
                $counter++;
210
            }
211
            $next = $start + $limit;
212
            if ( $total > $next ) {
213
                $hiddenform .= '&nbsp;<a href="#' . $total . '" onclick="javascript:document.findnext.start.value=' . $next . ';document.findnext.submit();">' . _MD_XM_NEXT . '</a>';
214
            }
215
            $hiddenform .= '</form>';
216
            $xoopsTpl->assign( 'pagenav', $hiddenform );
217
            $xoopsTpl->assign( 'lang_numfound', sprintf( _MD_XM_USERSFOUND, $total ) );
218
        }
219
    }
220
221
222
include_once XOOPS_ROOT_PATH . '/footer.php';
223
exit();
224
225
/**
226
 * xoops_Criteria()
227
 *
228
 * @return
229
 */
230 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...
231
    global $criteria;
232
233
    switch ( $match ) {
234
        case XOOPS_MATCH_START:
235
            $criteria->add( new Criteria( $name, $ret . '%', 'LIKE' ) );
236
            break;
237
        case XOOPS_MATCH_END:
238
            $criteria->add( new Criteria( $name, '%' . $ret . '%', 'LIKE' ) );
239
            break;
240
        case XOOPS_MATCH_EQUAL:
241
            $criteria->add( new Criteria( $name, $ret ) );
242
            break;
243
        case XOOPS_MATCH_CONTAIN:
244
            $criteria->add( new Criteria( $name, '%' . $ret . '%', 'LIKE' ) );
245
            break;
246
    }
247
}
248