Completed
Push — master ( 9803ae...780aff )
by Michael
27s queued 10s
created

index.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: 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
    $criteria->add( new Criteria( 'level', 0, '>' ) );
38
    $validsort = array( 'uname', 'name', 'last_login', 'user_regdate', 'posts' );
39
    $sort = ( !in_array( $xoopsModuleConfig['sortmembers'], $validsort ) ) ? 'uname' : $xoopsModuleConfig['sortmembers'];
40
    
41
	$order = 'ASC';
42
    if ( isset( $xoopsModuleConfig['membersorder'] ) && $xoopsModuleConfig['membersorder'] == 'DESC' ) {
43
        $order = 'DESC';
44
    }
45
    $limit = ( !empty( $xoopsModuleConfig['membersperpage'] ) ) ? intval( $xoopsModuleConfig['membersperpage'] ) : 20;
46
	if ( $limit == 0 || $limit > 50 ) {
47
        $limit = 50;
48
    }
49
50
    $start = ( !empty( $_POST['start'] ) ) ? intval( $_POST['start'] ) : 0;
51
    $member_handler = xoops_gethandler( 'member' );
52
    $total = $member_handler->getUserCount( $criteria );
53
	$xoopsTpl->assign( 'totalmember', $total );
54
55 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...
56
    } elseif ( $start < $total ) {
57
        if ( $iamadmin ) {
58
            $xoopsTpl->assign( 'is_admin', true );
59
        }
60
        $criteria->setSort( $sort );
61
        $criteria->setOrder( $order );
62
        $criteria->setStart( $start );
63
        $criteria->setLimit( $limit );
64
        $foundusers = $member_handler->getUsers( $criteria, true );
65
        foreach ( array_keys( $foundusers ) as $j ) {
66
            $userdata["avatar"] = $foundusers[$j]->getVar( 'user_avatar' ) ? '<img src="' . XOOPS_UPLOAD_URL . '/' . $foundusers[$j]->getVar( 'user_avatar' ) . '" alt="" />' : '&nbsp;';
67
            $userdata["realname"] = $foundusers[$j]->getVar( 'name' ) ? $foundusers[$j]->getVar( 'name' ) : '&nbsp;';
68
            $userdata["name"] = $foundusers[$j]->getVar( 'uname' );
69
            $userdata["id"] = $foundusers[$j]->getVar( 'uid' );
70
            if ( $foundusers[$j]->getVar( 'user_viewemail' ) == 1 || $iamadmin ) {
71
                $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>';
72
            } else {
73
                $userdata["email"] = '&nbsp;';
74
            }
75
            if ( $xoopsUser ) {
76
                $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>';
77
            } else {
78
                $userdata["pmlink"] = '&nbsp;';
79
            }
80
            if ( $foundusers[$j]->getVar( 'url', "e" ) != '' ) {
81
                $userdata["website"] = '<a href="' . $foundusers[$j]->getVar( 'url', "e" ) . '" target="_blank"><img src="' . XOOPS_URL . '/images/icons/www.gif" border="0" alt="' . _VISITWEBSITE . '" /></a>';
82
            } else {
83
                $userdata["website"] = '&nbsp;';
84
            }
85
            $userdata["registerdate"] = formatTimeStamp( $foundusers[$j]->getVar( 'user_regdate' ), 's' );
86
            if ( $foundusers[$j]->getVar( 'last_login' ) != 0 ) {
87
                $userdata["lastlogin"] = formatTimeStamp( $foundusers[$j]->getVar( 'last_login' ), "m" );
88
            } else {
89
                $userdata["lastlogin"] = '&nbsp;';
90
            }
91
            $userdata["posts"] = $foundusers[$j]->getVar( 'posts' );
92
            if ( $iamadmin ) {
93
                $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 . "' />"
94
95
                . '</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>';
96
            }
97
            $xoopsTpl->append( "users", $userdata );
98
        }
99
100
        $totalpages = ceil( $total / $limit );
101
        if ( $totalpages > 1 ) {
102
            $hiddenform = '<form name="findnext" action="index.php" method="post">';
103
            foreach ( $_POST as $k => $v ) {
104
                $hiddenform .= '<input type="hidden" name="' . $myts->htmlSpecialChars( $k ) . '" value="' . $myts->previewTarea( $v ) . '" />';
105
            }
106
            if ( !isset( $_POST['limit'] ) ) {
107
                $hiddenform .= '<input type="hidden" name="limit" value="' . $limit . '" />';
108
            }
109
            if ( !isset( $_POST['start'] ) ) {
110
                $hiddenform .= '<input type="hidden" name="start" value="' . $start . '" />';
111
            }
112
            $prev = $start - $limit;
113
            if ( $start - $limit >= 0 ) {
114
                $hiddenform .= '<a href="#0" onclick="javascript:document.findnext.start.value=' . $prev . ';document.findnext.submit();">' . _MD_XM_PREVIOUS . '</a>&nbsp;';
115
            }
116
            $counter = 1;
117
            $currentpage = ( $start + $limit ) / $limit;
118
            while ( $counter <= $totalpages ) {
119
                if ( $counter == $currentpage ) {
120
                    $hiddenform .= '<b>' . $counter . '</b> ';
121
                } elseif ( ( $counter > $currentpage-4 && $counter < $currentpage + 4 ) || $counter == 1 || $counter == $totalpages ) {
122
                    if ( $counter == $totalpages && $currentpage < $totalpages-4 ) {
123
                        $hiddenform .= '... ';
124
                    }
125
                    $hiddenform .= '<a href="#' . $counter . '" onclick="javascript:document.findnext.start.value=' . ( $counter-1 ) * $limit . ';document.findnext.submit();">' . $counter . '</a> ';
126
                    if ( $counter == 1 && $currentpage > 5 ) {
127
                        $hiddenform .= '... ';
128
                    }
129
                }
130
                $counter++;
131
            }
132
            $next = $start + $limit;
133
            if ( $total > $next ) {
134
                $hiddenform .= '&nbsp;<a href="#' . $total . '" onclick="javascript:document.findnext.start.value=' . $next . ';document.findnext.submit();">' . _MD_XM_NEXT . '</a>';
135
            }
136
            $hiddenform .= '</form>';
137
            $xoopsTpl->assign( 'pagenav', $hiddenform );
138
            $xoopsTpl->assign( 'lang_numfound', sprintf( _MD_XM_USERSFOUND, $total ) );
139
        }
140
    }
141
142
143
include_once XOOPS_ROOT_PATH . '/footer.php';
144
exit();
145
146
/**
147
 * xoops_Criteria()
148
 *
149
 * @return
150
 */
151 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...
152
    global $criteria;
153
154
    switch ( $match ) {
155
        case XOOPS_MATCH_START:
156
            $criteria->add( new Criteria( $name, $ret . '%', 'LIKE' ) );
157
            break;
158
        case XOOPS_MATCH_END:
159
            $criteria->add( new Criteria( $name, '%' . $ret . '%', 'LIKE' ) );
160
            break;
161
        case XOOPS_MATCH_EQUAL:
162
            $criteria->add( new Criteria( $name, $ret ) );
163
            break;
164
        case XOOPS_MATCH_CONTAIN:
165
            $criteria->add( new Criteria( $name, '%' . $ret . '%', 'LIKE' ) );
166
            break;
167
    }
168
}
169