ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilShopTopicsGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once 'Services/Payment/classes/class.ilShopTopics.php';
5 
16 {
17  private $objCurrentTopic = null;
18  private $ctrl = null;
19  private $tpl = null;
20  private $lng = null;
21  private $ask_for_deletion = false;
22 
23  public function __construct($a_gui_object)
24  {
25  global $tpl, $ilCtrl, $lng;
26 
27  $this->ctrl = $ilCtrl;
28  $this->lng = $lng;
29  $this->tpl = $tpl;
30 
31  $this->gui_object = $a_gui_object;
32 
33  $a_gui_object->tabs_gui->setTabActive('topics');
34 
35  $this->objCurrentTopic = new ilShopTopic(ilUtil::stripSlashes($_GET['topic_id']));#
36 
37  }
38 
39  public function executeCommand()
40  {
41  $cmd = $this->ctrl->getCmd();
42 // switch($this->ctrl->getNextClass($this))
43  switch($cmd)
44  {
45 
46 
47 
48  default:
49  if(!$cmd = $this->ctrl->getCmd())
50  {
51  $cmd = 'showTopicsList';
52  }
53  $this->$cmd();
54  break;
55  }
56 
57  return true;
58  }
59 
60  public function showTopicsSettings()
61  {
62  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.main_view.html','Services/Payment');
63 
65  $genSetData = $genSet->getAll();
66 
67  $form = new ilPropertyFormGUI();
68  $form->setFormAction($this->ctrl->getFormAction($this, 'saveTopicsSettings'));
69  $form->setTitle($this->lng->txt('pays_general_settings'));
70 
71  $form->addCommandButton('saveTopicsSettings',$this->lng->txt('save'));
72 
73  // use topics
74  $formItem = new ilCheckboxInputGUI($this->lng->txt('enable_topics'), 'enable_topics');
75  $formItem->setChecked((int)$genSetData['enable_topics']);
76  $formItem->setInfo($this->lng->txt('enable_topics_info'));
77  $form->addItem($formItem);
78 
79 
80  // default sorting type
81  $formItem = new ilSelectInputGUI($this->lng->txt('pay_topics_default_sorting_type'), 'topics_sorting_type');
82  $formItem->setValue($genSetData['topics_sorting_type']);
83  $options = array(
84  1 => $this->lng->txt('pay_topics_sort_by_title'),
85  2 => $this->lng->txt('pay_topics_sort_by_date'),
86  3 => $this->lng->txt('pay_topics_sort_manually')
87  );
88  $formItem->setOptions($options);
89  $form->addItem($formItem);
90 
91  // default sorting direction
92  $formItem = new ilSelectInputGUI($this->lng->txt('pay_topics_default_sorting_direction'), 'topics_sorting_direction');
93  $formItem->setValue($genSetData['topics_sorting_direction']);
94  $options = array(
95  'asc' => $this->lng->txt('sort_asc'),
96  'desc' => $this->lng->txt('sort_desc'),
97  );
98  $formItem->setOptions($options);
99  $form->addItem($formItem);
100 
101  // topics custom sorting
102  $formItem = new ilCheckboxInputGUI($this->lng->txt('pay_topics_allow_custom_sorting'), 'topics_allow_custom_sorting');
103  $formItem->setChecked((int)$genSetData['topics_allow_custom_sorting']);
104  $formItem->setInfo($this->lng->txt('pay_topics_allow_custom_sorting_info'));
105  $form->addItem($formItem);
106 
107  // show topics filter
108  $formItem = new ilCheckboxInputGUI($this->lng->txt('show_topics_filter'), 'show_topics_filter');
109  $formItem->setChecked((int)$genSetData['show_topics_filter']);
110  $formItem->setInfo($this->lng->txt('show_topics_filter_info'));
111  $form->addItem($formItem);
112 
113  $this->tpl->setVariable('FORM',$form->getHTML());
114  return true;
115 
116  }
117 
118 
119  public function saveTopicsSettings()
120  {
122  $genSet->set('enable_topics', $_POST['enable_topics'], 'gui');
123  $genSet->set('topics_allow_custom_sorting', $_POST['topics_allow_custom_sorting'], 'gui');
124  $genSet->set('topics_sorting_type', $_POST['topics_sorting_type'], 'gui');
125  $genSet->set('topics_sorting_direction', $_POST['topics_sorting_direction'], 'gui');
126  $genSet->set('show_topics_filter', $_POST['show_topics_filter'], 'gui');
127  ilUtil::sendSuccess($this->lng->txt('pays_updated_general_settings'));
128  $this->showTopicsSettings();
129  return true;
130  }
131 
132 
133  public function saveTopic()
134  {
135  $this->objCurrentTopic->setTitle(ilUtil::stripSlashes(trim($_POST['title'])));
136  $this->objCurrentTopic->setSorting((int)ilUtil::stripSlashes(trim($_POST['sorting'])));
137 
138  if($_POST['title'] == '')
139  {
140  ilUtil::sendFailure($this->lng->txt('fill_out_all_required_fields'));
141 
142  $this->showTopicForm();
143  }
144  else
145  {
146  $mode = $this->objCurrentTopic->getId() ? 'edit' : 'create';
147 
148  if($this->objCurrentTopic->save())
149  {
150  ilUtil::sendSuccess($this->lng->txt($mode == 'create' ? 'topic_saved' : 'topic_edited'));
151  }
152 
153  $this->showTopicsList();
154  }
155 
156  return true;
157  }
158 
159  public function showTopicForm()
160  {
161  $this->tpl->addBlockFile('ADM_CONTENT','adm_content', 'tpl.main_view.html', 'Services/Payment');
162 
163  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
164 
165  $form = new ilPropertyFormGUI();
166 
167  if($this->objCurrentTopic->getId())
168  {
169  $this->ctrl->setParameter($this, 'topic_id', $this->objCurrentTopic->getId());
170  }
171  $form->setFormAction($this->ctrl->getFormAction($this, 'saveTopic'));
172 
173  $form->setTitle($this->lng->txt($this->objCurrentTopic->getId() ? 'edit_topic' : 'new_topic'));
174 
175  $title = new ilTextInputGUI($this->lng->txt('title'), 'title');
176  $title->setValue($this->objCurrentTopic->getTitle());
177  $title->setRequired(true);
178  $form->addItem($title);
179 
180  $sorting = new ilTextInputGUI($this->lng->txt('pay_sorting_value'), 'sorting');
181  $sorting->setValue($this->objCurrentTopic->getSorting());
182  $sorting->setMaxLength(11);
183  $sorting->setSize(11);
184  $form->addItem($sorting);
185 
186  $form->addCommandButton('saveTopic', $this->lng->txt('save'));
187  $form->addCommandButton('showTopicsList', $this->lng->txt('cancel'));
188 
189  $this->tpl->setVariable('FORM', $form->getHTML());
190 
191  return true;
192  }
193 
194  public function confirmDeleteTopic()
195  {
196  if(!count($_POST['topic_id']))
197  {
198  ilUtil::sendInfo($this->lng->txt('select_one_topic'));
199  }
200  else
201  {
202  $this->ask_for_deletion = true;
203  }
204 
205  $this->showTopicsList();
206 
207  return true;
208  }
209 
210  public function saveSorting()
211  {
212  if(count($_POST['sorting']))
213  {
214  foreach($_POST['sorting'] as $topic_id => $sorting_value)
215  {
216  $oTopic = new ilShopTopic($topic_id);
217  $oTopic->setSorting($sorting_value);
218  $oTopic->save();
219  unset($oTopic);
220  }
221  }
222 
223  ilUtil::sendSuccess($this->lng->txt('saved_successfully'));
224 
225  $this->showTopicsList();
226 
227  return true;
228  }
229 
230  public function performDeleteTopic()
231  {
232  if(!count($_POST['topic_id']))
233  {
234  ilUtil::sendInfo($this->lng->txt('select_one_topic'));
235  }
236  else
237  {
238  foreach($_POST['topic_id'] as $topic_id)
239  {
240  $oTopic = new ilShopTopic($topic_id);
241  $oTopic->delete();
242  unset($oTopic);
243  }
244 
245  ilUtil::sendInfo($this->lng->txt('topics_deleted'));
246  }
247 
248  $this->showTopicsList();
249 
250  return true;
251  }
252 
253  public function showTopicsList()
254  {
255  $this->tpl->addBlockFile('ADM_CONTENT','adm_content', 'tpl.main_view.html', 'Services/Payment');
256 
257  if($this->ask_for_deletion)
258  {
259  include_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
260  $c_gui = new ilConfirmationGUI();
261 
262  $c_gui->setFormAction($this->ctrl->getFormAction($this, 'performDeleteTopic'));
263  $c_gui->setHeaderText($this->lng->txt('sure_delete_topics'));
264  $c_gui->setCancel($this->lng->txt('cancel'), 'showTopicsList');
265  $c_gui->setConfirm($this->lng->txt('confirm'), 'performDeleteTopic');
266 
267  foreach($_POST['topic_id'] as $topic_id)
268  {
269  $c_gui->addItem('topic_id[]', $topic_id, ilShopTopic::_lookupTitle($topic_id));
270  }
271 
272  $this->tpl->setVariable('CONFIRMATION', $c_gui->getHTML());
273 
274  return true;
275  }
276 
277  include_once 'Services/Payment/classes/class.ilShopTopicsTableGUI.php';
278  $table_gui = new ilShopTopicsTableGUI($this, 'showTopicsList');
279  $table_gui->setTitle($this->lng->txt('topics'));
281  ilShopTopics::_getInstance()->setSortingDirection('ASC');
282  ilShopTopics::_getInstance()->read();
283  $table_gui->parseRecords(ilShopTopics::_getInstance()->getTopics());
284  $table_gui->addCommandButton('showTopicForm', $this->lng->txt('add'));
285  $table_gui->addCommandButton('saveSorting', $this->lng->txt('pay_save_sorting'));
286 
287  $this->tpl->setVariable('TABLE', $table_gui->getHTML());
288 
289  return true;
290  }
291 }
292 ?>
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
$_POST['username']
Definition: cron.php:12
This class represents a selection list property in a property form.
This class represents a property form user interface.
$_GET["client_id"]
Class ilShopTopic.
Class ilShopTopicsGUI.
$cmd
Definition: sahs_server.php:35
This class represents a checkbox property in a property form.
static _lookupTitle($a_id)
__construct($a_gui_object)
global $ilCtrl
Definition: ilias.php:18
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
setChecked($a_checked)
Set Checked.
if(!is_array($argv)) $options
setValue($a_value)
Set Value.
This class represents a text property in a property form.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
Class ilShopTopicsTableGUI.
setValue($a_value)
Set Value.
Confirmation screen class.