19
19
* along with Xibo. If not, see <http://www.gnu.org/licenses/>.
21
21
namespace Xibo\Controller;
23
use Xibo\Exception\AccessDeniedException;
24
use Xibo\Factory\HelpFactory;
25
use Xibo\Service\ConfigServiceInterface;
26
use Xibo\Service\DateServiceInterface;
27
use Xibo\Service\LogServiceInterface;
28
use Xibo\Service\SanitizerServiceInterface;
32
* @package Xibo\Controller
24
use Xibo\Helper\ApplicationState;
25
use Xibo\Helper\Theme;
27
defined('XIBO') or die("Sorry, you are not allowed to directly access this page.<br /> Please press the back button in your browser.");
34
29
class Help extends Base
42
* Set common dependencies.
43
* @param LogServiceInterface $log
44
* @param SanitizerServiceInterface $sanitizerService
45
* @param \Xibo\Helper\ApplicationState $state
46
* @param \Xibo\Entity\User $user
47
* @param \Xibo\Service\HelpServiceInterface $help
48
* @param DateServiceInterface $date
49
* @param ConfigServiceInterface $config
50
* @param HelpFactory $helpFactory
52
public function __construct($log, $sanitizerService, $state, $user, $help, $date, $config, $helpFactory)
54
$this->setCommonDependencies($log, $sanitizerService, $state, $user, $help, $date, $config);
56
$this->helpFactory = $helpFactory;
34
* No display page functionaility
62
37
function displayPage()
64
$this->getState()->template = 'help-page';
67
public function grid()
69
$helpLinks = $this->helpFactory->query($this->gridRenderSort(), $this->gridRenderFilter());
71
foreach ($helpLinks as $row) {
72
/* @var \Xibo\Entity\Help $row */
39
// Configure the theme
41
Theme::Set('id', $id);
42
Theme::Set('form_meta', '<input type="hidden" name="p" value="help"><input type="hidden" name="q" value="Grid">');
43
Theme::Set('pager', ApplicationState::Pager($id));
45
// Call to render the template
46
Theme::Set('header_text', __('Help Links'));
47
Theme::Set('form_fields', array());
48
$this->getState()->html .= Theme::RenderReturn('grid_render');
55
array('title' => __('Add Help Link'),
56
'class' => 'XiboFormButton',
58
'link' => 'index.php?p=help&q=AddForm',
59
'help' => __('Add a new Help page'),
65
public function Grid()
68
$user = $this->getUser();
69
$response = $this->getState();
71
//display the display table
73
SELECT HelpID, Topic, Category, Link
75
ORDER BY Topic, Category
78
// Load results into an array
79
$helplinks = $db->GetArray($SQL);
81
if (!is_array($helplinks)) {
82
trigger_error($db->error());
83
trigger_error(__('Error getting list of helplinks'), E_USER_ERROR);
87
array('name' => 'topic', 'title' => __('Topic')),
88
array('name' => 'category', 'title' => __('Category')),
89
array('name' => 'link', 'title' => __('Link'))
91
Theme::Set('table_cols', $cols);
95
foreach ($helplinks as $row) {
97
$row['helpid'] = \Xibo\Helper\Sanitize::int($row['HelpID']);
98
$row['topic'] = \Xibo\Helper\Sanitize::string($row['Topic']);
99
$row['category'] = \Xibo\Helper\Sanitize::string($row['Category']);
100
$row['link'] = \Xibo\Helper\Sanitize::string($row['Link']);
102
$row['buttons'] = array();
74
104
// we only want to show certain buttons, depending on the user logged in
75
if ($this->getUser()->userTypeId == 1) {
105
if ($user->usertypeid == 1) {
78
$row->buttons[] = array(
108
$row['buttons'][] = array(
79
109
'id' => 'help_button_edit',
80
'url' => $this->urlFor('help.edit.form', ['id' => $row->helpId]),
110
'url' => 'index.php?p=help&q=EditForm&HelpID=' . $row['helpid'],
81
111
'text' => __('Edit')
85
$row->buttons[] = array(
115
$row['buttons'][] = array(
86
116
'id' => 'help_button_delete',
87
'url' => $this->urlFor('help.delete.form', ['id' => $row->helpId]),
117
'url' => 'index.php?p=help&q=DeleteForm&HelpID=' . $row['helpid'],
88
118
'text' => __('Delete')
92
$row->buttons[] = array(
122
$row['buttons'][] = array(
93
123
'id' => 'help_button_test',
94
'url' => $this->getHelp()->link($row->topic, $row->category),
124
'url' => Help::Link($row['topic'], $row['category']),
95
125
'text' => __('Test')
100
$this->getState()->template = 'grid';
101
$this->getState()->recordsTotal = $this->helpFactory->countLast();
102
$this->getState()->setData($helpLinks);
132
Theme::Set('table_rows', $rows);
134
$output = Theme::RenderReturn('table_render');
136
$response->SetGridResponse($output);
108
public function addForm()
140
public function AddForm()
110
if ($this->getUser()->userTypeId != 1)
111
throw new AccessDeniedException();
113
$this->getState()->template = 'help-form-add';
142
$response = $this->getState();
144
// Set some information about the form
145
Theme::Set('form_id', 'HelpAddForm');
146
Theme::Set('form_action', 'index.php?p=help&q=Add');
148
$formFields = array();
149
$formFields[] = FormManager::AddText('Topic', __('Topic'), NULL,
150
__('The Topic for this Help Link'), 't', 'maxlength="254" required');
152
$formFields[] = FormManager::AddText('Category', __('Category'), NULL,
153
__('The Category for this Help Link'), 'c', 'maxlength="254" required');
155
$formFields[] = FormManager::AddText('Link', __('Link'), NULL,
156
__('The Link to open for this help topic and category'), 'c', 'maxlength="254" required');
158
Theme::Set('form_fields', $formFields);
160
$response->SetFormRequestResponse(NULL, __('Add Help Link'), '350px', '325px');
161
$response->AddButton(__('Cancel'), 'XiboDialogClose()');
162
$response->AddButton(__('Save'), '$("#HelpAddForm").submit()');
120
public function editForm($helpId)
169
public function EditForm()
122
if ($this->getUser()->userTypeId != 1)
123
throw new AccessDeniedException();
125
$help = $this->helpFactory->getById($helpId);
127
$this->getState()->template = 'help-form-edit';
128
$this->getState()->setData([
172
$user = $this->getUser();
173
$response = $this->getState();
175
$helpId = \Xibo\Helper\Sanitize::getInt('HelpID');
177
// Pull the currently known info from the DB
178
$SQL = "SELECT HelpID, Topic, Category, Link FROM `help` WHERE HelpID = %d ";
179
$SQL = sprintf($SQL, $helpId);
181
if (!$row = $db->GetSingleRow($SQL)) {
182
trigger_error($db->error());
183
trigger_error(__('Error getting Help Link'));
186
// Set some information about the form
187
Theme::Set('form_id', 'HelpEditForm');
188
Theme::Set('form_action', 'index.php?p=help&q=Edit');
189
Theme::Set('form_meta', '<input type="hidden" name="HelpID" value="' . $helpId . '" />');
191
$formFields = array();
192
$formFields[] = FormManager::AddText('Topic', __('Topic'), \Xibo\Helper\Sanitize::string($row['Topic']),
193
__('The Topic for this Help Link'), 't', 'maxlength="254" required');
195
$formFields[] = FormManager::AddText('Category', __('Category'), \Xibo\Helper\Sanitize::string($row['Category']),
196
__('The Category for this Help Link'), 'c', 'maxlength="254" required');
198
$formFields[] = FormManager::AddText('Link', __('Link'), \Xibo\Helper\Sanitize::string($row['Link']),
199
__('The Link to open for this help topic and category'), 'c', 'maxlength="254" required');
201
Theme::Set('form_fields', $formFields);
203
$response->SetFormRequestResponse(NULL, __('Edit Help Link'), '350px', '325px');
204
$response->AddButton(__('Cancel'), 'XiboDialogClose()');
205
$response->AddButton(__('Save'), '$("#HelpEditForm").submit()');
134
210
* Delete Help Link Form
137
public function deleteForm($helpId)
212
public function DeleteForm()
139
if ($this->getUser()->userTypeId != 1)
140
throw new AccessDeniedException();
142
$help = $this->helpFactory->getById($helpId);
144
$this->getState()->template = 'help-form-delete';
145
$this->getState()->setData([
215
$response = $this->getState();
216
$helpId = \Xibo\Helper\Sanitize::getInt('HelpID');
218
// Set some information about the form
219
Theme::Set('form_id', 'HelpDeleteForm');
220
Theme::Set('form_action', 'index.php?p=help&q=Delete');
221
Theme::Set('form_meta', '<input type="hidden" name="HelpID" value="' . $helpId . '" />');
223
Theme::Set('form_fields', array(FormManager::AddMessage(__('Are you sure you want to delete?'))));
225
$response->SetFormRequestResponse(NULL, __('Delete Help Link'), '350px', '175px');
226
$response->AddButton(__('No'), 'XiboDialogClose()');
227
$response->AddButton(__('Yes'), '$("#HelpDeleteForm").submit()');
151
232
* Adds a help link
153
public function add()
234
public function Add()
155
if ($this->getUser()->userTypeId != 1)
156
throw new AccessDeniedException();
158
$help = $this->helpFactory->createEmpty();
159
$help->topic = $this->getSanitizer()->getString('topic');
160
$help->category = $this->getSanitizer()->getString('category');
161
$help->link = $this->getSanitizer()->getString('link');
166
$this->getState()->hydrate([
167
'message' => sprintf(__('Added %s'), $help->topic),
168
'id' => $help->helpId,
238
$response = $this->getState();
240
$topic = \Xibo\Helper\Sanitize::getString('Topic');
241
$category = \Xibo\Helper\Sanitize::getString('Category');
242
$link = \Xibo\Helper\Sanitize::getString('Link');
244
// Deal with the Edit
246
$helpObject = new Help($db);
248
if (!$helpObject->Add($topic, $category, $link))
249
trigger_error($helpObject->GetErrorMessage(), E_USER_ERROR);
251
$response->SetFormSubmitResponse(__('Help Link Added'), false);
174
256
* Edits a help link
177
public function edit($helpId)
258
public function Edit()
179
if ($this->getUser()->userTypeId != 1)
180
throw new AccessDeniedException();
182
$help = $this->helpFactory->getById($helpId);
183
$help->topic = $this->getSanitizer()->getString('topic');
184
$help->category = $this->getSanitizer()->getString('category');
185
$help->link = $this->getSanitizer()->getString('link');
190
$this->getState()->hydrate([
191
'message' => sprintf(__('Edited %s'), $help->topic),
192
'id' => $help->helpId,
262
$response = $this->getState();
264
$helpId = \Xibo\Helper\Sanitize::getInt('HelpID');
265
$topic = \Xibo\Helper\Sanitize::getString('Topic');
266
$category = \Xibo\Helper\Sanitize::getString('Category');
267
$link = \Xibo\Helper\Sanitize::getString('Link');
269
// Deal with the Edit
271
$helpObject = new Help($db);
273
if (!$helpObject->Edit($helpId, $topic, $category, $link))
274
trigger_error($helpObject->GetErrorMessage(), E_USER_ERROR);
276
$response->SetFormSubmitResponse(__('Help Link Edited'), false);
200
* @throws \Xibo\Exception\NotFoundException
202
public function delete($helpId)
280
public function Delete()
204
if ($this->getUser()->userTypeId != 1)
205
throw new AccessDeniedException();
207
$help = $this->helpFactory->getById($helpId);
211
$this->getState()->hydrate([
212
'message' => sprintf(__('Deleted %s'), $help->topic)
284
$response = $this->getState();
286
$helpId = \Xibo\Helper\Sanitize::getInt('HelpID');
288
// Deal with the Edit
290
$helpObject = new Help($db);
292
if (!$helpObject->Delete($helpId))
293
trigger_error($helpObject->GetErrorMessage(), E_USER_ERROR);
295
$response->SetFormSubmitResponse(__('Help Link Deleted'), false);