-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpnadminapi.php
205 lines (175 loc) · 7.29 KB
/
pnadminapi.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
<?php
/**
* Zikula Application Framework
*
* @copyright (c) 2002, Zikula Development Team
* @link http://www.zikula.org
* @version $Id$
* @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
* @package Zikula_System_Modules
* @subpackage Admin_Messages
*/
/**
* create a new Admin_Messages item
* @author Mark West
* @param string $args['title'] title of the admin message
* @param string $args['content'] text of the admin message
* @param string $args['language'] the language of the message
* @param int $args['active'] activation status of the message
* @param int $args['expire'] expiry date of the message
* @param int $args['view'] who can view the message
* @return mixed Admin_Messages item ID on success, false on failure
*/
function Admin_Messages_adminapi_create($args)
{
$dom = ZLanguage::getModuleDomain('Admin_Messages');
// Argument check
if (!isset($args['title']) ||
!isset($args['content']) ||
!isset($args['language']) ||
!isset($args['active']) ||
!isset($args['expire']) ||
!isset($args['view'])) {
return LogUtil::registerArgsError();
}
if (empty($args['title']) && empty($args['content'])) {
return LogUtil::registerArgsError();
}
// Security check
if (!SecurityUtil::checkPermission('Admin_Messages::', '::', ACCESS_ADD)) {
return LogUtil::registerPermissionError ();
}
// create the item array
$item = array('title' => $args['title'], 'content' => $args['content'],
'language' => $args['language'], 'active' => $args['active'], 'view' => $args['view']);
// add some additional modified values
if ($args['expire'] < 0) {
$args['expire'] = 0;
}
$item['expire'] = $args['expire'] * 86400; // turns days into seconds
$item['date'] = time();
if (!DBUtil::insertObject($item, 'message', 'mid')) {
return LogUtil::registerError(__('Error! Could not create the new item.', $dom));
}
// Let any hooks know that we have created a new item.
ModUtil::callHooks('item', 'create', $item['mid'], array('module' => 'Admin_Messages'));
// Return the id of the newly created item to the calling process
return $item['mid'];
}
/**
* delete an Admin_Messages item
* @author Mark West
* @param int $args['mid'] ID of the admin message to delete
* @return bool true on success, false on failure
*/
function Admin_Messages_adminapi_delete($args)
{
$dom = ZLanguage::getModuleDomain('Admin_Messages');
// Argument check
if (!isset($args['mid'])) {
return LogUtil::registerArgsError();
}
// Get the existing admin message
$item = ModUtil::apiFunc('Admin_Messages', 'user', 'get', array('mid' => $args['mid']));
if ($item == false) {
return LogUtil::registerError(__('Sorry! No such item found.', $dom));
}
// Security check
if (!SecurityUtil::checkPermission('Admin_Messages::', "$item[title]::$args[mid]", ACCESS_DELETE)) {
return LogUtil::registerPermissionError ();
}
if (!DBUtil::deleteObjectByID('message', $args['mid'], 'mid')) {
return LogUtil::registerError(__('Error! Could not perform the deletion.', $dom));
}
// Let any hooks know that we have deleted an item.
ModUtil::callHooks('item', 'delete', $args['mid'], array('module' => 'Admin_Messages'));
// The item has been modified, so we clear all cached pages of this item.
$view = Zikula_View::getInstance('Admin_Messages');
$view->clear_cache(null, UserUtil::getVar('uid'));
// Let the calling process know that we have finished successfully
return true;
}
/**
* update a Admin_Messages item
* @author Mark West
* @param int $args['mid'] the ID of the item
* @param sting $args['title'] title of the admin message
* @param string $args['content'] text of the admin message
* @param string $args['language'] the language of the message
* @param int $args['active'] activation status of the message
* @param int $args['expire'] expiry date of the message
* @param int $args['view'] who can view the message
* @return bool true if successful, false otherwise
*/
function Admin_Messages_adminapi_update($args)
{
$dom = ZLanguage::getModuleDomain('Admin_Messages');
// Argument check
if (!isset($args['mid']) ||
!isset($args['title']) ||
!isset($args['content']) ||
!isset($args['language']) ||
!isset($args['active']) ||
!isset($args['expire']) ||
!isset($args['oldtime']) ||
!isset($args['changestartday']) ||
!isset($args['view'])) {
return LogUtil::registerArgsError();
}
// Get the existing admin message
$item = ModUtil::apiFunc('Admin_Messages', 'user', 'get', array('mid' => $args['mid']));
if ($item == false) {
return LogUtil::registerError(__('Sorry! No such item found.', $dom));
}
// Security check
if (!SecurityUtil::checkPermission('Admin_Messages::', "$item[title]::$args[mid]", ACCESS_EDIT)) {
return LogUtil::registerPermissionError ();
}
// check value of change start day to today and set time
if ($args['changestartday'] == 1) {
$time = time();
} else {
$time = $args['oldtime'];
}
// check for an invalid expiry
if ($args['expire'] < 0) {
$expire = 0;
}
// create the item array
$item = array('mid' => $args['mid'], 'title' => $args['title'], 'content' => $args['content'],
'language' => $args['language'], 'active' => $args['active'], 'view' => $args['view']);
// add some additional modified values
$args['expire'] = $args['expire'] * 86400; // turns days into seconds
$args['date'] = $time;
if (!DBUtil::updateObject($args, 'message', '', 'mid')) {
return LogUtil::registerError(__('Error! Could not save your changes.'));
}
// New hook functions
ModUtil::callHooks('item', 'update', $args['mid'], array('module' => 'Admin_Messages'));
// The item has been modified, so we clear all cached pages of this item.
$view = Zikula_View::getInstance('Admin_Messages');
$view->clear_cache(null, UserUtil::getVar('uid'));
// Let the calling process know that we have finished successfully
return true;
}
/**
* get available admin panel links
*
* @author Mark West
* @return array array of admin links
*/
function admin_messages_adminapi_getlinks()
{
$dom = ZLanguage::getModuleDomain('Admin_Messages');
$links = array();
if (SecurityUtil::checkPermission('Admin_Messages::', '::', ACCESS_READ)) {
$links[] = array('url' => ModUtil::url('Admin_Messages', 'admin', 'view'), 'text' => __('Messages list', $dom));
}
if (SecurityUtil::checkPermission('Admin_Messages::', '::', ACCESS_ADD)) {
$links[] = array('url' => ModUtil::url('Admin_Messages', 'admin', 'new'), 'text' => __('Create new message', $dom));
}
if (SecurityUtil::checkPermission('Admin_Messages::', '::', ACCESS_ADMIN)) {
$links[] = array('url' => ModUtil::url('Admin_Messages', 'admin', 'modifyconfig'), 'text' => __('Settings', $dom));
}
return $links;
}