ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilChatroomAdminSmileyGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
13 {
17  protected $form_gui;
18 
22  public function executeDefault($requestedMethod)
23  {
24  $this->view();
25  }
26 
31  public function view()
32  {
33  include_once 'Modules/Chatroom/classes/class.ilChatroom.php';
34 
35  ilChatroom::checkUserPermissions('read', $this->gui->ref_id);
36 
37  $this->gui->switchToVisibleMode();
38 
39  self::_checkSetup();
40 
41  $this->editSmiliesObject();
42  }
43 
44  public static function _checkSetup()
45  {
46  global $DIC;
47 
48  $path = self::_getSmileyDir();
49 
50  if (!is_dir($path)) {
51  ilUtil::sendInfo($DIC->language()->txt('chat_smilies_dir_not_exists'));
53 
54  if (!is_dir($path)) {
55  ilUtil::sendFailure($DIC->language()->txt('chat_smilies_dir_not_available'));
56  return false;
57  } else {
58  $smilies = array(
59  "icon_smile.gif",
60  "icon_wink.gif",
61  "icon_laugh.gif",
62  "icon_sad.gif",
63  "icon_shocked.gif",
64  "icon_tongue.gif",
65  "icon_cool.gif",
66  "icon_eek.gif",
67  "icon_angry.gif",
68  "icon_flush.gif",
69  "icon_idea.gif",
70  "icon_thumbup.gif",
71  "icon_thumbdown.gif",
72  );
73 
74  foreach ($smilies as $smiley) {
75  copy("templates/default/images/emoticons/$smiley", $path . "/$smiley");
76  }
77 
78  self::_insertDefaultValues();
79 
80  ilUtil::sendSuccess($DIC->language()->txt('chat_smilies_initialized'));
81  }
82  }
83 
84  if (!is_writable($path)) {
85  ilUtil::sendInfo($DIC->language()->txt('chat_smilies_dir_not_writable'));
86  }
87 
88  return true;
89  }
90 
95  public static function _getSmileyDir($withBaseDir = true)
96  {
97  $path = 'chatroom/smilies';
98 
99  if ($withBaseDir) {
100  $path = ilUtil::getWebspaceDir() . '/' . $path;
101  }
102 
103  return $path;
104  }
105 
106  private static function _insertDefaultValues()
107  {
108  $values = array(
109  array("icon_smile.gif", ":)\n:-)\n:smile:"),
110  array("icon_wink.gif", ";)\n;-)\n:wink:"),
111  array("icon_laugh.gif", ":D\n:-D\n:laugh:\n:grin:\n:biggrin:"),
112  array("icon_sad.gif", ":(\n:-(\n:sad:"),
113  array("icon_shocked.gif", ":o\n:-o\n:shocked:"),
114  array("icon_tongue.gif", ":p\n:-p\n:tongue:"),
115  array("icon_cool.gif", ":cool:"),
116  array("icon_eek.gif", ":eek:"),
117  array("icon_angry.gif", ":||\n:-||\n:angry:"),
118  array("icon_flush.gif", ":flush:"),
119  array("icon_idea.gif", ":idea:"),
120  array("icon_thumbup.gif", ":thumbup:"),
121  array("icon_thumbdown.gif", ":thumbdown:"),
122  );
123 
124  require_once 'Modules/Chatroom/classes/class.ilChatroomSmilies.php';
125  foreach ($values as $val) {
126  ilChatroomSmilies::_storeSmiley($val[1], $val[0]);
127  }
128  }
129 
134  public function editSmiliesObject()
135  {
136  if (!$this->rbacsystem->checkAccess('read', $this->gui->ref_id)) {
137  $this->ilias->raiseError(
138  $this->ilLng->txt('msg_no_perm_read'),
139  $this->gui->ilias->error_obj->MESSAGE
140  );
141  }
142 
143  include_once 'Modules/Chatroom/classes/class.ilChatroomSmilies.php';
144 
145  ilChatroomSmilies::_checkSetup();
146 
147  if (!$this->form_gui) {
148  $form = $this->initSmiliesForm();
149  } else {
150  $form = $this->form_gui;
151  }
152 
153  include_once "Modules/Chatroom/classes/class.ilChatroomSmiliesGUI.php";
154 
156 
157  $tpl_smilies = new ilTemplate(
158  "tpl.chatroom_edit_smilies.html",
159  true,
160  true,
161  "Modules/Chatroom"
162  );
163  $tpl_smilies->setVariable("SMILEY_TABLE", $table);
164  $tpl_smilies->setVariable("SMILEY_FORM", $form->getHtml());
165 
166  $this->mainTpl->setContent($tpl_smilies->get());
167  }
168 
173  public function initSmiliesForm()
174  {
175  global $DIC;
176 
177  $this->form_gui = new ilPropertyFormGUI();
178 
179  $table_nav = $_REQUEST["_table_nav"] ? "&_table_nav=" . $_REQUEST["_table_nav"] : "";
180  $this->form_gui->setFormAction(
181  $this->ilCtrl->getFormAction($this->gui, 'smiley-uploadSmileyObject') . $table_nav
182  );
183 
184  // chat server settings
185  $sec_l = new ilFormSectionHeaderGUI();
186 
187  $sec_l->setTitle($this->ilLng->txt('chatroom_add_smiley'));
188  $this->form_gui->addItem($sec_l);
189 
190  $inp = new ilImageFileInputGUI(
191  $this->ilLng->txt('chatroom_image_path'),
192  'chatroom_image_path'
193  );
194  $inp->setSuffixes(array("jpg", "jpeg", "png", "gif", "svg"));
195 
196  $inp->setRequired(true);
197  $this->form_gui->addItem($inp);
198 
199  $inp = new ilTextAreaInputGUI(
200  $this->ilLng->txt('chatroom_smiley_keywords'),
201  'chatroom_smiley_keywords'
202  );
203 
204  $inp->setRequired(true);
205  $inp->setUseRte(false);
206  $inp->setInfo($this->ilLng->txt('chatroom_smiley_keywords_one_per_line_note'));
207  $this->form_gui->addItem($inp);
208 
209 
210  if ($this->rbacsystem->checkAccess("write", $this->gui->ref_id)) {
211  $this->form_gui->addCommandButton('smiley-uploadSmileyObject', $DIC->language()->txt('chatroom_upload_smiley'));
212  }
213  return $this->form_gui;
214  }
215 
221  {
222  $this->gui->switchToVisibleMode();
223 
224  if (!$this->rbacsystem->checkAccess('read', $this->gui->ref_id)) {
225  $this->ilias->raiseError(
226  $this->ilLng->txt('msg_no_perm_read'),
227  $this->ilias->error_obj->MESSAGE
228  );
229  }
230 
231  if (!$this->form_gui) {
232  $form = $this->initSmiliesEditForm($this->getSmileyFormDataById((int) $_REQUEST['smiley_id']));
233  } else {
234  $form = $this->form_gui;
235  }
236 
237  $tpl_form = new ilTemplate(
238  "tpl.chatroom_edit_smilies.html",
239  true,
240  true,
241  "Modules/Chatroom"
242  );
243 
244  $tpl_form->setVariable("SMILEY_FORM", $form->getHTML());
245 
246  $this->mainTpl->setContent($tpl_form->get());
247  }
248 
254  protected function getSmileyFormDataById($smileyId)
255  {
256  require_once 'Modules/Chatroom/classes/class.ilChatroomSmilies.php';
257  $smiley = ilChatroomSmilies::_getSmiley($smileyId);
258 
259  $form_data = array(
260  'chatroom_smiley_id' => $smiley['smiley_id'],
261  'chatroom_smiley_keywords' => $smiley['smiley_keywords'],
262  'chatroom_current_smiley_image_path' => $smiley['smiley_fullpath'],
263  );
264 
265  return $form_data;
266  }
267 
272  public function initSmiliesEditForm($form_data)
273  {
274  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
275 
276  $this->form_gui = new ilPropertyFormGUI();
277 
278  $this->form_gui->setValuesByArray($form_data);
279 
280  $table_nav = $_REQUEST["_table_nav"] ? "&_table_nav=" . $_REQUEST["_table_nav"] : "";
281 
282  $this->ilCtrl->saveParameter($this->gui, 'smiley_id');
283 
284  $this->form_gui->setFormAction(
285  $this->ilCtrl->getFormAction($this->gui, 'smiley-updateSmiliesObject') . $table_nav
286  );
287 
288  $sec_l = new ilFormSectionHeaderGUI();
289 
290  $sec_l->setTitle($this->ilLng->txt('chatroom_edit_smiley'));
291  $this->form_gui->addItem($sec_l);
292 
293  include_once "Modules/Chatroom/classes/class.ilChatroomSmiliesCurrentSmileyFormElement.php";
294 
296  $this->ilLng->txt('chatroom_current_smiley_image_path'),
297  'chatroom_current_smiley_image_path'
298  );
299 
300  $inp->setValue($form_data['chatroom_current_smiley_image_path']);
301  $this->form_gui->addItem($inp);
302 
303  $inp = new ilImageFileInputGUI(
304  $this->ilLng->txt('chatroom_image_path'),
305  'chatroom_image_path'
306  );
307  $inp->setSuffixes(array("jpg", "jpeg", "png", "gif", "svg"));
308 
309  $inp->setRequired(false);
310  $inp->setInfo($this->ilLng->txt('chatroom_smiley_image_only_if_changed'));
311  $this->form_gui->addItem($inp);
312 
313  $inp = new ilTextAreaInputGUI(
314  $this->ilLng->txt('chatroom_smiley_keywords'),
315  'chatroom_smiley_keywords'
316  );
317 
318  $inp->setValue($form_data['chatroom_smiley_keywords']);
319  $inp->setUseRte(false);
320  $inp->setRequired(true);
321  $inp->setInfo($this->ilLng->txt('chatroom_smiley_keywords_one_per_line_note'));
322  $this->form_gui->addItem($inp);
323 
324  $inp = new ilHiddenInputGUI('chatroom_smiley_id');
325 
326  $this->form_gui->addItem($inp);
327  $this->form_gui->addCommandButton(
328  'smiley-updateSmiliesObject',
329  $this->ilLng->txt('submit')
330  );
331  $this->form_gui->addCommandButton('smiley', $this->ilLng->txt('cancel'));
332  return $this->form_gui;
333  }
334 
339  public function showDeleteSmileyFormObject()
340  {
341  $this->gui->switchToVisibleMode();
342 
343  if (!$this->rbacsystem->checkAccess('write', $this->gui->ref_id)) {
344  $this->ilias->raiseError(
345  $this->ilLng->txt('msg_no_perm_write'),
346  $this->ilias->error_obj->MESSAGE
347  );
348  }
349 
350  include_once 'Modules/Chatroom/classes/class.ilChatroomSmilies.php';
351  $smiley = ilChatroomSmilies::_getSmiley((int) $_REQUEST['smiley_id']);
352 
353  require_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
354  $confirmation = new ilConfirmationGUI();
355  $confirmation->setFormAction($this->ilCtrl->getFormAction($this->gui, 'smiley'));
356  $confirmation->setHeaderText($this->ilLng->txt('chatroom_confirm_delete_smiley'));
357  $confirmation->addButton($this->ilLng->txt('confirm'), 'smiley-deleteSmileyObject');
358  $confirmation->addButton($this->ilLng->txt('cancel'), 'smiley');
359  $confirmation->addItem('chatroom_smiley_id', $smiley['smiley_id'], ilUtil::img($smiley['smiley_fullpath'], $smiley['smiley_keywords']) . ' ' . $smiley['smiley_keywords']);
360 
361  $this->mainTpl->setContent($confirmation->getHTML());
362  }
363 
367  public function deleteSmileyObject()
368  {
369  if (!$this->rbacsystem->checkAccess('write', $this->gui->ref_id)) {
370  $this->ilias->raiseError(
371  $this->ilLng->txt('msg_no_perm_write'),
372  $this->ilias->error_obj->MESSAGE
373  );
374  }
375 
376  include_once 'Modules/Chatroom/classes/class.ilChatroomSmilies.php';
377 
378  ilChatroomSmilies::_deleteSmiley($_REQUEST["chatroom_smiley_id"]);
379 
380  $this->ilCtrl->redirect($this->gui, "smiley");
381  }
382 
388  public function updateSmiliesObject()
389  {
390  if (!$this->rbacsystem->checkAccess('write', $this->gui->ref_id)) {
391  $this->ilias->raiseError(
392  $this->ilLng->txt('msg_no_perm_write'),
393  $this->ilias->error_obj->MESSAGE
394  );
395  }
396 
397  $this->initSmiliesEditForm($this->getSmileyFormDataById((int) $_REQUEST['smiley_id']));
398 
399  require_once 'Modules/Chatroom/classes/class.ilChatroomSmilies.php';
401  ilUtil::stripSlashes($_REQUEST["chatroom_smiley_keywords"])
402  );
403 
404  $atLeastOneKeywordGiven = count($keywords) > 0;
405 
406  if (!($isFormValid = $this->form_gui->checkInput()) || !$atLeastOneKeywordGiven) {
407  if ($isFormValid) {
408  \ilUtil::sendFailure($this->ilLng->txt('form_input_not_valid'));
409  }
410 
411  $this->form_gui->setValuesByPost();
412 
414  return;
415  }
416 
417  $data = array();
418  $data["smiley_keywords"] = join("\n", $keywords);
419  $data["smiley_id"] = (int) $_REQUEST['smiley_id'];
420 
421  if ($this->upload->hasUploads() && !$this->upload->hasBeenProcessed()) {
422  $this->upload->process();
423 
425  $result = array_values($this->upload->getResults())[0];
427  $this->upload->moveOneFileTo(
428  $result,
430  \ILIAS\FileUpload\Location::WEB,
431  $result->getName(),
432  true
433  );
434 
435  $data['smiley_path'] = $result->getName();
436  }
437  }
438 
439  \ilChatroomSmilies::_updateSmiley($data);
440 
441  \ilUtil::sendSuccess($this->ilLng->txt('saved_successfully'), true);
442  $this->ilCtrl->redirect($this->gui, "smiley");
443  }
444 
449  public function deleteMultipleObject()
450  {
451  $this->gui->switchToVisibleMode();
452 
453  if (!$this->rbacsystem->checkAccess('write', $this->gui->ref_id)) {
454  $this->ilias->raiseError(
455  $this->ilLng->txt('msg_no_perm_write'),
456  $this->ilias->error_obj->MESSAGE
457  );
458  }
459 
460  $items = (array) $_REQUEST['smiley_id'];
461  if (count($items) == 0) {
462  ilUtil::sendInfo($this->ilLng->txt('select_one'), true);
463  $this->ilCtrl->redirect($this->gui, 'smiley');
464  }
465 
466  include_once 'Modules/Chatroom/classes/class.ilChatroomSmilies.php';
467  $smilies = ilChatroomSmilies::_getSmiliesById($items);
468  if (count($smilies) == 0) {
469  ilUtil::sendInfo($this->ilLng->txt('select_one'), true);
470  $this->ilCtrl->redirect($this->gui, 'smiley');
471  }
472 
473  require_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
474  $confirmation = new ilConfirmationGUI();
475  $confirmation->setFormAction($this->ilCtrl->getFormAction($this->gui, 'smiley'));
476  $confirmation->setHeaderText($this->ilLng->txt('chatroom_confirm_delete_smiley'));
477  $confirmation->addButton($this->ilLng->txt('confirm'), 'smiley-confirmedDeleteMultipleObject');
478  $confirmation->addButton($this->ilLng->txt('cancel'), 'smiley');
479 
480  foreach ($smilies as $s) {
481  $confirmation->addItem('sel_ids[]', $s['smiley_id'], ilUtil::img($s['smiley_fullpath'], $s['smiley_keywords']) . ' ' . $s['smiley_keywords']);
482  }
483 
484  $this->mainTpl->setContent($confirmation->getHTML());
485  }
486 
491  {
492  if (!$this->rbacsystem->checkAccess('write', $this->gui->ref_id)) {
493  $this->ilias->raiseError(
494  $this->ilLng->txt('msg_no_perm_write'),
495  $this->ilias->error_obj->MESSAGE
496  );
497  }
498 
499  $parts = $_POST["sel_ids"];
500  if (count($parts) == 0) {
501  $this->ilCtrl->redirect($this->gui, "smiley");
502  }
503 
504  include_once "Modules/Chatroom/classes/class.ilChatroomSmilies.php";
505  ilChatroomSmilies::_deleteMultipleSmilies($parts);
506 
507  $this->ilCtrl->redirect($this->gui, "smiley");
508  }
509 
514  public function uploadSmileyObject()
515  {
516  if (!$this->rbacsystem->checkAccess('write', $this->gui->ref_id)) {
517  $this->ilias->raiseError(
518  $this->ilLng->txt('msg_no_perm_write'),
519  $this->ilias->error_obj->MESSAGE
520  );
521  }
522 
523  $this->initSmiliesForm();
524 
525  require_once 'Modules/Chatroom/classes/class.ilChatroomSmilies.php';
527  ilUtil::stripSlashes($_REQUEST["chatroom_smiley_keywords"])
528  );
529 
530  $atLeastOneKeywordGiven = count($keywords) > 0;
531 
532  if (!($isFormValid = $this->form_gui->checkInput()) || !$atLeastOneKeywordGiven) {
533  if ($isFormValid) {
534  \ilUtil::sendFailure($this->ilLng->txt('form_input_not_valid'));
535  }
536 
537  $this->form_gui->setValuesByPost();
538 
539  $this->view();
540  return;
541  }
542 
543  $pathinfo = pathinfo($_FILES["chatroom_image_path"]["name"]);
544  $target_file = md5(time() + $pathinfo['basename']) . "." . $pathinfo['extension'];
545 
546  if ($this->upload->hasUploads() && !$this->upload->hasBeenProcessed()) {
547  $this->upload->process();
548 
550  $result = array_values($this->upload->getResults())[0];
552  $this->upload->moveOneFileTo(
553  $result,
555  \ILIAS\FileUpload\Location::WEB,
556  $target_file,
557  true
558  );
559 
560  ilChatroomSmilies::_storeSmiley(join("\n", $keywords), $target_file);
561  }
562  }
563 
564  \ilUtil::sendSuccess($this->ilLng->txt('saved_successfully'), true);
565  $this->ilCtrl->redirect($this->gui, "smiley");
566  }
567 }
deleteSmileyObject()
Deletes a smiley by $_REQUEST["chatroom_smiley_id"].
static makeDirParents($a_dir)
Create a new directory and all parent directories.
This class provides processing control methods.
$data
Definition: storeScorm.php:23
$result
This class represents a property form user interface.
static _getExistingSmiliesTable($a_ref)
Constructor public.
static _getSmileyDir($withBaseDir=true)
This class represents a section header in a property form.
Class ChatMainBarProvider .
view()
Switches GUI to visible mode and calls editSmiliesObject method which prepares and displays the table...
setValue($a_value)
Set Value.
initSmiliesForm()
Initializes smilies form and returns it.
setValue($a_value)
Sets given value as $this->value in ilChatroomSmiliesCurrentSmileyFormElement.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
initSmiliesEditForm($form_data)
Initializes SmiliesEditForm and returns it.
This class represents a hidden form property in a property form.
getFormAction( $a_gui_obj, $a_fallback_cmd="", $a_anchor="", $a_asynch=false, $xml_style=false)
Get form action url for gui class object.
static checkUserPermissions($permissions, $ref_id, $send_info=true)
Checks user permissions by given array and ref_id.
Class ilChatroomGUIHandler.
global $DIC
Definition: goto.php:24
redirection script todo: (a better solution should control the processing via a xml file) ...
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
Class ilChatroomSmiliesCurrentSmileyFormElement Class ilchatroomSmiliesCurrentSmileyFormElement simpl...
saveParameter($a_obj, $a_parameter)
Set parameters that should be passed in every form and link of a gui class.
static img($a_src, $a_alt=null, $a_width="", $a_height="", $a_border=0, $a_id="", $a_class="")
Build img tag.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
This class represents an image file property in a property form.
This class represents a text area property in a property form.
static getSmiliesBasePath()
Returns smilies basepath.
static _prepareKeywords($words)
Trims given keywords and returns them in one array.
Class ilChatroomSmileyGUI Provides methods to show, add, edit and delete smilies consisting of icon a...
showEditSmileyEntryFormObject()
Shows EditSmileyEntryForm Prepares EditSmileyEntryForm and displays it.
editSmiliesObject()
Shows existing smilies table Prepares existing smilies table and displays it.
deleteMultipleObject()
Shows confirmation view for deleting multiple smilies Prepares confirmation view for deleting multipl...
showDeleteSmileyFormObject()
Shows DeleteSmileyForm Prepares DeleteSmileyForm and displays it.
static getWebspaceDir($mode="filesystem")
get webspace directory
setSuffixes($a_suffixes)
Set Accepted Suffixes.
$_POST["username"]
setRequired($a_required)
Set Required.
confirmedDeleteMultipleObject()
Deletes multiple smilies by $_REQUEST["sel_ids"].
redirect($a_gui_obj, $a_cmd="", $a_anchor="", $a_asynch=false)
Redirect to another command.
Confirmation screen class.