-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass-penguin-menu.php
More file actions
154 lines (130 loc) · 4.07 KB
/
class-penguin-menu.php
File metadata and controls
154 lines (130 loc) · 4.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php class Penguin_Menu {
private $penguin_settings;
public function __construct( $penguin_settings) {
$this->penguin_settings = $penguin_settings;
}
public function add_menu_hook() {
add_menu_page(
"Penguin LDAP", // Page title
"Penguin LDAP", // Menu title
'edit_users', // Capability
"penguin_options", // Menu slug
array ( $this, "penguin_menu" ) // Callback function
);
}
// The menu
public function penguin_menu () {
?>
<style>
hr {
display: block; height: 1px;
border: 0; border-top: 1px solid #dfdfdf;
margin: 1em 0; padding: 0;
}
#group-table tbody {
padding : 2px 8px !important;
font-size: 12px;
}
#group-table tbody th {
text-align: left;
padding-bottom: 0px !important;
}
#group-table tbody td {
display: table-cell;
line-height: 5px;
padding-left: 0px !important;
padding-bottom: 0px !important;
}
.priority-grab {
cursor: move !important;
}
</style>
<?php
if( isset( $_GET[ 'tab' ] ) ) {
$active_tab = $_GET[ 'tab' ];
} else {
$active_tab = 'general';
}
?>
<div class="wrap">
<div id="icon-themes" class="icon32"></div>
<h2>Penguin LDAP Settings</h2>
<h2 class="nav-tab-wrapper">
<a href="<?php echo add_query_arg( array('tab' => 'general'), $_SERVER['REQUEST_URI']); ?>" class="nav-tab
<?php echo $active_tab == 'general' ? 'nav-tab-active' : ''; ?>">General</a>
<a href="<?php echo add_query_arg( array('tab' => 'roles'), $_SERVER['REQUEST_URI']); ?>" class="nav-tab
<?php echo $active_tab == 'roles' ? 'nav-tab-active' : ''; ?>">Roles</a>
<a href="<?php echo add_query_arg( array('tab' => 'help'), $_SERVER['REQUEST_URI']); ?>" class="nav-tab
<?php echo $active_tab == 'help' ? 'nav-tab-active' : ''; ?>">Help</a>
</h2>
</div>
<?php
if ( $active_tab == "general" ) {
// Very important!
$this->penguin_settings->load_all_options();
?>
<div id="wrap">
<form method="POST" action="options.php">
<?php
$this->test_ldap_connect_button();
settings_fields( "pgn_general");
do_settings_sections( "pgn_general");
submit_button( );
?>
</form>
</div>
<?php
}
elseif ( $active_tab == "roles" ) {
// Very important!
$this->penguin_settings->load_all_options();
wp_enqueue_script( 'roles_tab_script' ,
plugin_dir_url( __FILE__ ) . 'javascript/roles-tab.js');
wp_enqueue_script('jquery-ui-sortable');
?>
<div id="wrap">
<form method="POST" action="options.php">
<?php
$this->penguin_settings->load_roles( );
settings_fields( "pgn_roles");
do_settings_sections( "pgn_roles");
submit_button( );
?>
</form>
</div>
<?php
}
elseif ( $active_tab == "help" ) {
$this->test_ldap_connect_button();
echo "<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum</p>";
}
}
public function test_ldap_connect_button() {
wp_enqueue_script( 'help_tab_script' ,
plugin_dir_url( __FILE__ ) . 'javascript/help-tab.js');
?>
<div id='test-section'>
<h3>Test server and port</h3>
<a class="button" id='test-button'>Test</a>
<p id="push-result" style="display:none;"></p>
</div>
<?php
}
public function add_ajax_script() {
add_action ( 'wp_ajax_my_action', array ( $this, "my_action_callback" ) );
}
public function my_action_callback() {
$this->penguin_settings->load_all_options();
$result = @ldap_connect( $this->penguin_settings->get_option( 'protocol' ) .
$this->penguin_settings->get_option( 'server' ),
$this->penguin_settings->get_option( 'port') );
if ( $result != false) {
echo "Sucessfully connected.";
}
else {
echo "Could not connect.";
}
die(); // this is required to return a proper result
}
}
?>