-
Notifications
You must be signed in to change notification settings - Fork 1
/
admin_config.php
232 lines (149 loc) · 6.48 KB
/
admin_config.php
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<?php
// Generated e107 Plugin Admin Area
require_once(__DIR__.'/../../class2.php');
if (!getperms('P'))
{
e107::redirect('admin');
exit;
}
e107::plugLan('hits', true, true);
class hits_adminArea extends e_admin_dispatcher
{
protected $modes = array(
'main' => array(
'controller' => 'hits_ui',
'path' => null,
'ui' => 'hits_form_ui',
'uipath' => null
),
);
protected $adminMenu = array(
'main/list' => array('caption'=> LAN_MANAGE, 'perm' => 'P'),
// 'main/create' => array('caption'=> LAN_CREATE, 'perm' => 'P'),
// 'main/prefs' => array('caption'=> LAN_PREFS, 'perm' => '0'),
'main/custom' => array('caption'=> LAN_HITS_ADMIN_01, 'perm' => '0')
);
protected $adminMenuAliases = array(
'main/edit' => 'main/list'
);
protected $menuTitle = LAN_PLUGIN_HITS_TITLE;
}
class hits_ui extends e_admin_ui
{
protected $pluginTitle = LAN_PLUGIN_HITS_TITLE;
protected $pluginName = 'hits';
// protected $eventName = 'hits-hits'; // remove comment to enable event triggers in admin.
protected $table = 'hits';
protected $pid = 'hits_id';
protected $perPage = 15;
protected $batchDelete = false;
// protected $batchCopy = true;
// protected $sortField = 'somefield_order';
// protected $orderStep = 10;
// protected $tabs = array('Tabl 1','Tab 2'); // Use 'tab'=>0 OR 'tab'=>1 in the $fields below to enable.
protected $listQry = "SELECT n.news_id,n.news_title,n.news_datestamp, h.* FROM `#news` AS n LEFT JOIN `#hits` as h ON n.news_id = h.hits_itemid WHERE h.hits_type = 'news' "; // Example Custom Query. LEFT JOINS allowed. Should be without any Order or Limit.
protected $listOrder = 'news_datestamp DESC';
protected $fields = array ( 'checkboxes' => array ( 'title' => '', 'type' => null, 'data' => null, 'width' => '5%', 'thclass' => 'center', 'forced' => '1', 'class' => 'center', 'toggle' => 'e-multiselect', ),
'hits_id' => array ( 'title' => LAN_ID, 'data' => 'int', 'width' => '5%', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left', ),
'news_title' => array ( 'title' => LAN_TITLE, 'type'=>'text', 'data' => false, 'width' => '40%', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left', ),
'news_datestamp' => array ( 'title' => LAN_HITS_ADMIN_02, 'type'=>'datestamp', 'data' => false, 'width' => '10%', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left', ),
'hits_type' => array ( 'title' => LAN_TYPE, 'type' => 'text', 'data' => 'str', 'width' => 'auto', 'batch' => true, 'filter' => true, 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'left', 'thclass' => 'left', ),
'hits_itemid' => array ( 'title' => LAN_HITS_ADMIN_03, 'type' => 'number', 'data' => 'int', 'width' => 'auto', 'help' => '', 'readParms' => '', 'writeParms' => '', 'class' => 'right', 'thclass' => 'right', ),
'hits_counter' => array ( 'title' => LAN_PLUGIN_HITS_TITLE, 'type' => 'number', 'data' => 'int', 'width' => '8%', 'help' => '', 'readParms' => 'sep=,', 'writeParms' => '', 'class' => 'right', 'thclass' => 'right', ),
'hits_unique' => array ( 'title' => LAN_HITS_ADMIN_04, 'type' => 'number', 'data' => 'int', 'width' => '8%', 'help' => '', 'readParms' => 'sep=,', 'writeParms' => '', 'class' => 'right', 'thclass' => 'right', ),
'hits_lastupdated' => array ( 'title' => LAN_HITS_ADMIN_05, 'type' => 'datestamp', 'data' => 'int', 'width' => 'auto', 'help' => '', 'readParms' => 'mask=relative', 'writeParms' => '', 'class' => 'right last', 'thclass' => 'right last', ),
'options' => array ( 'title' => LAN_OPTIONS, 'type' =>'method', 'nolist'=>true, 'data' => null, 'width' => '10%', 'thclass' => 'center last', 'class' => 'center last', 'forced' => false, ),
);
protected $fieldpref = array('news_title','news_datestamp', 'hits_type', 'hits_counter', 'hits_unique', 'hits_lastupdated');
// protected $preftabs = array('General', 'Other' );
protected $prefs = array(
'Active' => array('title'=> 'Active', 'tab'=>0, 'type'=>'boolean', 'data' => 'str', 'help'=>''),
);
public function init()
{
// Set drop-down values (if any).
// $this->fields['hits_type']['writeParms']['optArray'] = array('hits_type_0','hits_type_1', 'hits_type_2'); // Example Drop-down array.
if(e_DEBUG === true)
{
$this->fields['hits_counter']['inline'] = true;
$this->fields['hits_unique']['inline'] = true;
$this->batchDelete = true;
}
else
{
unset($this->fields['checkboxes']);
}
}
// ------- Customize Create --------
public function beforeCreate($new_data,$old_data)
{
return $new_data;
}
public function afterCreate($new_data, $old_data, $id)
{
// do something
}
public function onCreateError($new_data, $old_data)
{
// do something
}
// ------- Customize Update --------
public function beforeUpdate($new_data, $old_data, $id)
{
return $new_data;
}
public function afterUpdate($new_data, $old_data, $id)
{
// do something
}
public function onUpdateError($new_data, $old_data, $id)
{
// do something
}
public function customPage()
{
if(!empty($_POST['submitHits']))
{
$sql = e107::getDb();
$data = $sql->retrieve('news','news_id',null,true);
foreach($data as $row)
{
$insertArray = array(
'hits_id' => 0,
'hits_type' => 'news',
'hits_itemid' => (int) $row['news_id'],
'hits_counter' => 0,
'hits_unique' => 0,
);
$sql->insert('hits', $insertArray);
}
e107::getMessage()->addSuccess(LAN_CREATED);
return e107::getMessage()->render();
}
$frm = e107::getForm();
$text = "<div class='alert alert-block alert-info'>". LAN_HITS_ADMIN_06."</div>";
$text .= $frm->open('createHits','post');
$text .= $frm->button('submitHits',1,'submit', LAN_CREATE);
$text .= $frm->close();
return $text;
}
function renderHelp()
{
$text = LAN_HITS_ADMIN_07;
$srch = array('[',']');
$repl = array("<a href='".e_ADMIN."menus.php'>", "</a>" );
$text = str_replace($srch, $repl, $text);
return array('caption' => LAN_HELP, 'text' => $text);
}
}
class hits_form_ui extends e_admin_form_ui
{
function options($curval,$bla,$bla2)
{
return ' ';
}
}
new hits_adminArea();
require_once(e_ADMIN."auth.php");
e107::getAdminUI()->runPage();
require_once(e_ADMIN."footer.php");