ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 {
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  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
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  $this->form_gui->addCommandButton(
209  'smiley-uploadSmileyObject',
210  $this->ilLng->txt('chatroom_upload_smiley')
211  );
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 {
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 
413  return $this->showEditSmileyEntryFormObject();
414  }
415 
416  $data = array();
417  $data["smiley_keywords"] = join("\n", $keywords);
418  $data["smiley_id"] = (int) $_REQUEST['smiley_id'];
419 
420  if ($this->upload->hasUploads() && !$this->upload->hasBeenProcessed()) {
421  $this->upload->process();
422 
424  $result = array_values($this->upload->getResults())[0];
426  $this->upload->moveOneFileTo(
427  $result,
429  \ILIAS\FileUpload\Location::WEB,
430  $result->getName(),
431  true
432  );
433 
434  $data['smiley_path'] = $result->getName();
435  }
436  }
437 
438  \ilChatroomSmilies::_updateSmiley($data);
439 
440  \ilUtil::sendSuccess($this->ilLng->txt('saved_successfully'), true);
441  $this->ilCtrl->redirect($this->gui, "smiley");
442  }
443 
448  public function deleteMultipleObject()
449  {
450  $this->gui->switchToVisibleMode();
451 
452  if (!$this->rbacsystem->checkAccess('write', $this->gui->ref_id)) {
453  $this->ilias->raiseError(
454  $this->ilLng->txt('msg_no_perm_write'),
455  $this->ilias->error_obj->MESSAGE
456  );
457  }
458 
459  $items = (array) $_REQUEST['smiley_id'];
460  if (count($items) == 0) {
461  ilUtil::sendInfo($this->ilLng->txt('select_one'), true);
462  $this->ilCtrl->redirect($this->gui, 'smiley');
463  }
464 
465  include_once 'Modules/Chatroom/classes/class.ilChatroomSmilies.php';
466  $smilies = ilChatroomSmilies::_getSmiliesById($items);
467  if (count($smilies) == 0) {
468  ilUtil::sendInfo($this->ilLng->txt('select_one'), true);
469  $this->ilCtrl->redirect($this->gui, 'smiley');
470  }
471 
472  require_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
473  $confirmation = new ilConfirmationGUI();
474  $confirmation->setFormAction($this->ilCtrl->getFormAction($this->gui, 'smiley'));
475  $confirmation->setHeaderText($this->ilLng->txt('chatroom_confirm_delete_smiley'));
476  $confirmation->addButton($this->ilLng->txt('confirm'), 'smiley-confirmedDeleteMultipleObject');
477  $confirmation->addButton($this->ilLng->txt('cancel'), 'smiley');
478 
479  foreach ($smilies as $s) {
480  $confirmation->addItem('sel_ids[]', $s['smiley_id'], ilUtil::img($s['smiley_fullpath'], $s['smiley_keywords']) . ' ' . $s['smiley_keywords']);
481  }
482 
483  $this->mainTpl->setContent($confirmation->getHTML());
484  }
485 
490  {
491  if (!$this->rbacsystem->checkAccess('write', $this->gui->ref_id)) {
492  $this->ilias->raiseError(
493  $this->ilLng->txt('msg_no_perm_write'),
494  $this->ilias->error_obj->MESSAGE
495  );
496  }
497 
498  $parts = $_POST["sel_ids"];
499  if (count($parts) == 0) {
500  $this->ilCtrl->redirect($this->gui, "smiley");
501  }
502 
503  include_once "Modules/Chatroom/classes/class.ilChatroomSmilies.php";
504  ilChatroomSmilies::_deleteMultipleSmilies($parts);
505 
506  $this->ilCtrl->redirect($this->gui, "smiley");
507  }
508 
513  public function uploadSmileyObject()
514  {
515  if (!$this->rbacsystem->checkAccess('write', $this->gui->ref_id)) {
516  $this->ilias->raiseError(
517  $this->ilLng->txt('msg_no_perm_write'),
518  $this->ilias->error_obj->MESSAGE
519  );
520  }
521 
522  $this->initSmiliesForm();
523 
524  require_once 'Modules/Chatroom/classes/class.ilChatroomSmilies.php';
526  ilUtil::stripSlashes($_REQUEST["chatroom_smiley_keywords"])
527  );
528 
529  $atLeastOneKeywordGiven = count($keywords) > 0;
530 
531  if (!($isFormValid = $this->form_gui->checkInput()) || !$atLeastOneKeywordGiven) {
532  if ($isFormValid) {
533  \ilUtil::sendFailure($this->ilLng->txt('form_input_not_valid'));
534  }
535 
536  $this->form_gui->setValuesByPost();
537 
538  return $this->view();
539  }
540 
541  $pathinfo = pathinfo($_FILES["chatroom_image_path"]["name"]);
542  $target_file = md5(time() + $pathinfo['basename']) . "." . $pathinfo['extension'];
543 
544  if ($this->upload->hasUploads() && !$this->upload->hasBeenProcessed()) {
545  $this->upload->process();
546 
548  $result = array_values($this->upload->getResults())[0];
550  $this->upload->moveOneFileTo(
551  $result,
553  \ILIAS\FileUpload\Location::WEB,
554  $target_file,
555  true
556  );
557 
558  ilChatroomSmilies::_storeSmiley(join("\n", $keywords), $target_file);
559  }
560  }
561 
562  \ilUtil::sendSuccess($this->ilLng->txt('saved_successfully'), true);
563  $this->ilCtrl->redirect($this->gui, "smiley");
564  }
565 }
deleteSmileyObject()
Deletes a smiley by $_REQUEST["chatroom_smiley_id"].
static makeDirParents($a_dir)
Create a new directory and all parent directories.
$path
Definition: aliased.php:25
This class provides processing control methods.
$result
This class represents a property form user interface.
global $DIC
Definition: saml.php:7
static _getExistingSmiliesTable($a_ref)
Constructor public.
static _getSmileyDir($withBaseDir=true)
This class represents a section header in a property form.
Class BaseForm.
view()
Switches GUI to visible mode and calls editSmiliesObject method which prepares and displays the table...
setValue($a_value)
Set Value.
$s
Definition: pwgen.php:45
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.
static checkUserPermissions($permissions, $ref_id, $send_info=true)
Checks user permissions by given array and ref_id.
if(isset($_POST['submit'])) $form
Class ilChatroomGUIHandler.
$values
special template class to simplify handling of ITX/PEAR
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.
if(empty($password)) $table
Definition: pwgen.php:24
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.
$data
Definition: bench.php:6
getFormAction( $a_gui_obj, $a_fallback_cmd="", $a_anchor="", $a_asynch=false, $xml_style=true)
Get form action url for gui class object.