Project

General

Profile

1
//:Puts a Login / Logout box on your page.
2
//:Use: [[LoginBox?redirect=url]]
3
//:Absolute or relative url possible
4
//:Remember to enable frontend login in your website settings!!
5
global $database,$wb, $TEXT, $MENU, $HEADING;
6
$return_value = '<div class="login-box">'."\n";
7
$return_admin = ' ';
8
// Return a system permission
9
$get_permission = function ($name, $type = 'system') use ( $wb )
10
{
11
// Append to permission type
12
$type .= '_permissions';
13
// Check if we have a section to check for
14
if($name == 'start') {
15
return true;
16
} else {
17
// Set system permissions var
18
$system_permissions = $wb->get_session('SYSTEM_PERMISSIONS');
19
// Set module permissions var
20
$module_permissions = $wb->get_session('MODULE_PERMISSIONS');
21
// Set template permissions var
22
$template_permissions = $wb->get_session('TEMPLATE_PERMISSIONS');
23
// Return true if system perm = 1
24
if (isset($$type) && is_array($$type) && is_numeric(array_search($name, $$type))) {
25
if($type == 'system_permissions') {
26
return true;
27
} else {
28
return false;
29
}
30
} else {
31
if($type == 'system_permissions') {
32
return false;
33
} else {
34
return true;
35
}
36
}
37
}
38
};
39
$get_page_permission = function ($page, $action='admin') use ( $database, $wb )
40
{
41
if ($action!='viewing'){ $action='admin';}
42
$action_groups = $action.'_groups';
43
$action_users  = $action.'_users';
44
if (is_array($page)) {
45
$groups = $page[$action_groups];
46
$users  = $page[$action_users];
47
} else {
48
$sql  = 'SELECT '.$action_groups.','.$action_users.' FROM '.TABLE_PREFIX.'pages '
49
. 'WHERE page_id = \''.$page.'\'';
50
if($oResults = $database->query( $sql )){
51
$aResult  = $oResults->fetchRow( MYSQLI_ASSOC );
52
$groups  = explode(',', str_replace('_', '', $aResult[$action_groups]));
53
$users   = explode(',', str_replace('_', '', $aResult[$action_users]));
54
}
55
}
56
$in_group = false;
57
foreach($wb->get_groups_id() as $cur_gid){
58
if (in_array( $cur_gid, $groups )) {
59
$in_group = true;
60
}
61
}
62
if( !$in_group && !is_numeric(array_search( $wb->get_user_id(), $users )) ) {
63
return false;
64
}
65
return true;
66
};
67
// Get redirect
68
$redirect_url = ((isset($_SESSION['HTTP_REFERER']) && $_SESSION['HTTP_REFERER'] != '') ? $_SESSION['HTTP_REFERER'] : WB_URL );
69
$redirect_url = ( isset($redirect) && ($redirect!='') ? $redirect : $redirect_url);
70
if ( ( FRONTEND_LOGIN == 'enabled') && ( VISIBILITY != 'private') && ( $wb->get_session('USER_ID') == '')  )
71
{
72
$return_value .= '<form action="'.LOGIN_URL.'" method="post">'."\n";
73
$return_value .= '<input type="hidden" name="redirect" value="'.$redirect_url.'" />'."\n";
74
$return_value .= '<fieldset>'."\n";
75
$return_value .= '<h1>'.$TEXT['LOGIN'].'</h1>'."\n";
76
$return_value .= '<label for="username">'.$TEXT['USERNAME'].':</label>'."\n";
77
$return_value .= '<p><input type="text" name="username" id="username"  /></p>'."\n";
78
$return_value .= '<label for="password">'.$TEXT['PASSWORD'].':</label>'."\n";
79
$return_value .= '<p><input type="password" name="password" id="password"/></p>'."\n";
80
$return_value .= '<p><input type="submit" id="submit" value="'.$TEXT['LOGIN'].'" class="dbutton" /></p>'."\n";
81
$return_value .= '<ul class="login-advance">'."\n";
82
$return_value .= '<li class="forgot"><a href="'.FORGOT_URL.'"><span>'.$TEXT['FORGOT_DETAILS'].'</span></a></li>'."\n";
83
if (intval(FRONTEND_SIGNUP) > 0)
84
{
85
$return_value .= '<li class="sign"><a href="'.SIGNUP_URL.'">'.$TEXT['SIGNUP'].'</a></li>'."\n";
86
}
87
$return_value .= '</ul>'."\n";
88
$return_value .= '</fieldset>'."\n";
89
$return_value .= '</form>'."\n";
90
} elseif( (FRONTEND_LOGIN == 'enabled') && (is_numeric($wb->get_session('USER_ID'))) )
91
{
92
$return_value .= '<form action="'.LOGOUT_URL.'" method="post" class="login-table">'."\n";
93
$return_value .= '<input type="hidden" name="redirect" value="'.$redirect_url.'" />'."\n";
94
$return_value .= '<fieldset>'."\n";
95
$return_value .= '<h1>'.$TEXT["LOGGED_IN"].'</h1>'."\n";
96
$return_value .= '<label>'.$TEXT['WELCOME_BACK'].', '.$wb->get_display_name().'</label>'."\n";
97
$return_value .= '<p><input type="submit" name="submit" value="'.$MENU['LOGOUT'].'" class="dbutton" /></p>'."\n";
98
$return_value .= '<ul class="logout-advance">'."\n";
99
$return_value .= '<li class="preference"><a href="'.PREFERENCES_URL.'" title="'.$MENU['PREFERENCES'].'">'.$MENU['PREFERENCES'].'</a></li>'."\n";
100
if ($wb->ami_group_member('1'))  //change ot the group that should get special links
101
{
102
$return_admin .= '<li class="admin"><a target="_blank" href="'.ADMIN_URL.'/index.php" title="'.$TEXT['ADMINISTRATION'].'" class="blank_target">'.$TEXT["ADMINISTRATION"].'</a></li>'."\n";
103
//you can add more links for your users like userpage, lastchangedpages or something
104
$return_value .= $return_admin;
105
}
106
//change ot the group that should get special links
107
if( $get_permission('pages_modify') && $get_page_permission( PAGE_ID ) )
108
{
109
$return_value .= '<li class="modify"><a target="_blank" href="'.ADMIN_URL.'/pages/modify.php?page_id='.PAGE_ID.'" title="'.$HEADING['MODIFY_PAGE'].'" class="blank_target">'.$HEADING['MODIFY_PAGE'].'</a></li>'."\n";
110
}
111
$return_value .= '</ul>'."\n";
112
$return_value .= '</fieldset>'."\n";
113
$return_value .= '</form>'."\n";
114
}
115
$return_value .= '</div>'."\n";
116
return $return_value;
(2-2/17)