ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilFeedbackGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 
16 {
20  function ilFeedbackGUI(){
21  global $ilCtrl;
22  global $lng;
23  $this->update = 0;
24 
25  $this->ctrl =& $ilCtrl;
26  $this->lng =& $lng;
27  $this->lng->loadLanguageModule('barometer');
28 
29  }
30 
34  function &executeCommand()
35  {
36  global $ilAccess,$ilErr;
37 
38  // deprecated - will be removed in 4.4
39 
40  if(isset($_SESSION["message"])) {
41  if(isset($_SESSION['error_post_vars']['cmd']['update'])){
42  //var_dump($_SESSION);
43  $this->ctrl->setCmd('edit');
44  }else
45  $this->ctrl->setCmd('addBarometer');
46  }
47  $params = $this->ctrl->getParameterArray($this);
48 
49  $cmd = $this->ctrl->getCmd('fbList');
50  //No write permissions, so this has to be a normal user..
51 
52  if((!$ilAccess->checkAccess('write','edit',$params['ref_id']))&&(in_array($cmd,array('fbList','save','delete','update','edit'))))
53  $cmd = 'showBarometer';
54 
55  $next_class = $this->ctrl->getNextClass($this);
56  switch($next_class){
57  default:
58  return($this->$cmd());
59  break;
60  }
61  }
62 
63  function getFeedbackHTML(){
64  global $lng;
65 
66  $tpl = new ilTemplate("tpl.feedbacklist.html", true, true, "Services/Feedback");
67  $tpl->setVariable("TXT_FEEDBACK_TITLE", $lng->txt("stimmungsb"));
68  $tpl->setVariable("TXT_TITLE", $lng->txt("title"));
69  $tpl->setVariable("TXT_STATUS", $lng->txt("status"));
70  $tpl->setVariable("TXT_ACTIVE_TIME", $lng->txt("active_time"));
71  $tpl->setVariable("TXT_OPTIONS", $lng->txt("options"));
72 
73  $tpl->setVariable("TXT_NEW_VOTE", $lng->txt("options"));
74  $tpl->parseCurrentBlock();
75  return($tpl->get());
76  }
77 
81  function fbList(){
82 
83  include_once('Services/Feedback/classes/class.ilFeedback.php');
84  $tbl =& $this->__initTableGUI();
85  $cnt=0;
86  $ilFeedback = new ilFeedback();
87  $ilFeedback->setRefId($_GET['ref_id']);
88  $barometers = $ilFeedback->getAllBarometer();
89 
90  if(is_Array($barometers)){
91  foreach($barometers as $barometer){
92  $rows[$cnt]['checkbox'] = ilUtil::formCheckbox(0,"barometer[]",$barometer->getId());;
93  $rows[$cnt]['title'] = $barometer->getTitle();
94  $rows[$cnt]['status'] = 'Aktive';
95  if(($barometer->getStarttime()>0) && ($barometer->getStarttime()>0)){
96  $rows[$cnt]['running'] = date('d.m.Y H:i',$barometer->getStarttime()).' - '.date('d.m.Y H:i',$barometer->getEndtime());
97  if(($barometer->getStarttime()<=time())&&($barometer->getEndtime()>=time()))
98  $rows[$cnt]['status'] = $this->lng->txt('active');
99  else
100  $rows[$cnt]['status'] = $this->lng->txt('inactive');
101 
102  }else{
103  $rows[$cnt]['running'] = '';
104  $rows[$cnt]['status'] = $this->lng->txt('active');
105  }
106  $rows[$cnt]['options'] = $this->getButtons($barometer->getId());
107  $barometer_ids[]=$barometer->getId();
108  $cnt++;
109  }
110  }
111 
112  $tbl->tpl->setCurrentBlock("tbl_form_header");
113  $tbl->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
114  $tbl->tpl->parseCurrentBlock();
115  $tbl->setTitle($this->lng->txt("feedb_feedback_list"),
116  "icon_feedb.png", $this->lng->txt("feedb_feedback_list"));
117  $tbl->setHeaderNames(array("",$this->lng->txt("title"),$this->lng->txt("status"),$this->lng->txt("time"),$this->lng->txt("options")));
118  $tbl->setHeaderVars(array("checkbox","title","stauts","running","options"));
119  $tbl->setData($rows);
120  $tbl->setOffset(0);
121  $tbl->setLimit(0);
122  $tbl->disable('sort');
123  $tbl->setMaxCount(count($rows));
124 
125  /* deprecated - will be removed in 4.4
126  $tbl->tpl->setCurrentBlock("plain_button");
127  $tbl->tpl->setVariable("PBTN_NAME","addBarometer");
128  $tbl->tpl->setVariable("PBTN_VALUE",$this->lng->txt("barometer_add"));
129  $tbl->tpl->parseCurrentBlock();
130  $tbl->tpl->setCurrentBlock("plain_buttons");
131  $tbl->tpl->parseCurrentBlock();
132  */
133 
134  if (!empty($rows))
135  {
136  // set checkbox toggles
137  $tbl->tpl->setCurrentBlock("tbl_action_toggle_checkboxes");
138  $tbl->tpl->setVariable("JS_VARNAME","barometer");
139  $tbl->tpl->setVariable("JS_ONCLICK",ilUtil::array_php2js($barometer_ids));
140  $tbl->tpl->setVariable("TXT_CHECKALL", $this->lng->txt("check_all"));
141  $tbl->tpl->setVariable("TXT_UNCHECKALL", $this->lng->txt("uncheck_all"));
142  $tbl->tpl->parseCurrentBlock();
143  }
144 
145 
146  $tbl->tpl->setVariable("COLUMN_COUNTS",5);
147  $tbl->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.png"));
148 
149  $tbl->tpl->setCurrentBlock("tbl_action_select");
150  //$tbl->tpl->setVariable("SELECT_ACTION",ilUtil::formSelect(1,"action",array('delete'),false,true));
151  $tbl->tpl->setVariable("BTN_NAME","delete");
152  $tbl->tpl->setVariable("BTN_VALUE",$this->lng->txt("delete"));
153  $tbl->tpl->parseCurrentBlock();
154  //$tbl->setOrderColumn('title');
155  $tbl->setOrderDirection('asc');
156  $tbl->setColumnWidth(array("","25%","25%","25%",""));
157  #$tbl->disable('sort');
158  $tbl->setFooter("tblfooter");
159  $tbl->render();
160 
161  return($tbl->tpl->get());
162 
163  }
164  function &__initTableGUI()
165  {
166  include_once "./Services/Table/classes/class.ilTableGUI.php";
167  return new ilTableGUI(0,false);
168 
169  }
170  function delete()
171  {
172  if(is_array($_POST['barometer']))
173  {
174  include_once('Services/Feedback/classes/class.ilFeedback.php');
175  $ilFB = new ilFeedback();
176  $ilFB->setIds($_POST['barometer']);
177  $ilFB->delete();
178  }
179  ilUtil::redirect($this->ctrl->getLinkTarget($this, 'fbList', '', false, false));
180  }
181  function stats(){
182 
183  include_once('Services/Feedback/classes/class.ilFeedback.php');
184 
185 
186  $tpl = new ilTemplate("tpl.feedback_stats.html", true, true, "Services/Feedback");
187  $feedback = new ilFeedback();
188  $feedback->setUserId(ilUtil::stripSlashes($_POST['chart_user']));
189  $feedback->setId($_GET['barometer_id']);
190  $chartdata = $feedback->getChartData();
191  $data = $chartdata['data'];
192  $legend = $chartdata['legend'];
193  $legendpie = $chartdata['legendpie'];
194  $datapie = $chartdata['datapie'];
195  $datatable = $chartdata['table'];
196 
197  $chartlines = '<img src="Services/Feedback/showchart.php?chart_type=lines&title='.base64_encode($this->lng->txt('chart_users')).'&data='.base64_encode(serialize($data)).'&legend='.base64_encode(serialize($legend)).'">';
198  $chartpie = '<img src="Services/Feedback/showchart.php?chart_type=pie&title='.base64_encode($this->lng->txt('chart_votes')).'&data='.base64_encode(serialize($datapie)).'&legend='.base64_encode(serialize($legendpie)).'">';
199 
200  $chart_type['lines'] = $this->lng->txt('lines');
201  $chart_type['pie'] = $this->lng->txt('pie');
202  $chart_type['table'] = $this->lng->txt('table');
203 
204  $chart_user[0] = $this->lng->txt('all_users');
205  $chart_user = $feedback->getResultUsers();
206 
207  $tpl->setVariable("TXT_USER",$this->lng->txt('user'));
208  $tpl->setVariable("TXT_CHART_TYPE",$this->lng->txt('chart_type'));
209  switch($_POST['chart_type']){
210  case 'pie':
211  $tpl->setVariable("CHART_PIE", $chartpie);
212  break;
213  case 'table':
214  if(is_array($datatable)){
215  $tpl->setCurrentBlock('tablerow');
216  $tpl->setVariable('TXT_TABLE_USERNAME',$this->lng->txt('username'));
217  $tpl->setVariable('TXT_TABLE_VOTE',$this->lng->txt('vote'));
218  $tpl->setVariable('TXT_TABLE_DATE', $this->lng->txt('date'));
219  $tpl->parseCurrentBlock();
220  $i=0;
221  foreach($datatable as $tablerow){
222  $tpl->setVariable('VALUE_NUM',(($i++ % 2) ? 1 : 2));
223  $tpl->setVariable('VALUE_VOTETIME', $tablerow['votetime']);
224  $tpl->setVariable('VALUE_USER', $tablerow['user']);
225  $tpl->setVariable('VALUE_VOTE', $tablerow['vote']);
226  $tpl->parseCurrentBlock();
227  }
228  }
229  break;
230  default:
231  $tpl->setVariable("CHART_LINES", $chartlines);
232  break;
233  }
234  $tpl->setVariable("SELECTBOX_CHART_TYPE", $this->selectbox(ilUtil::stripSlashes($_POST['chart_type']),'chart_type',$chart_type,'onChange="document.stats.submit()"'));
235  $tpl->setVariable("SELECTBOX_USER", $this->selectbox(ilUtil::stripSlashes($_POST['chart_user']),'chart_user',$chart_user,'onChange="document.stats.submit()"',$this->lng->txt('all_users')));
236 
237 
238 
239 
240  $comments = $feedback->getNotes();
241  if(is_Array($comments)){
242  $tpl->setCurrentBlock('comment_row');
243  $tpl->setVariable('TXT_USERNAME',$this->lng->txt('username'));
244  $tpl->setVariable('TXT_COMMENT',$this->lng->txt('comment'));
245  $tpl->setVariable('TXT_DATE', $this->lng->txt('date'));
246  $tpl->parseCurrentBlock();
247  $i=0;
248  foreach ($comments as $comment){
249  $tpl->setVariable('VALUE_NUM',(($i++ % 2) ? 1 : 2));
250  $tpl->setVariable('VALUE_LOGIN',$comment['user']);
251  $tpl->setVariable('VALUE_DATE',$comment['votetime']);
252  $tpl->setVariable('VALUE_NOTE',$comment['note']);
253  $tpl->parseCurrentBlock();
254  }
255  }
256  $tpl->parseCurrentBlock();
257  return($tpl->get());
258  }
259 
260 
264  function edit()
265  {
266  include_once('Services/Feedback/classes/class.ilFeedback.php');
267 
268  $ilFB = new ilFeedback($_REQUEST['barometer_id']);
269  $tpl = new ilTemplate("tpl.feedback_edit.html", true, true, "Services/Feedback");
270 
271  $data['title'] = $_POST['title'] ? $_POST['title'] : $ilFB->getTitle();
272  $data['description'] = $_POST['text'] ? $_POST['text'] : $ilFB->getDescription();
273  $data['anonymous'] = ($_POST['anonymous']!='') ? $_POST['anonymous'] : $ilFB->getAnonymous();
274  $data['required'] = ($_POST['required']!='') ? $_POST['required'] : $ilFB->getRequired();
275  $data['show_on'] = $_POST['show_on'] ? $_POST['show_on'] : $ilFB->getShowOn();
276  $data['vote'] = $_POST['vote'] ? $_POST['vote'] : unserialize($ilFB->getVotes());
277  if($_POST['extra_votes']=='')
278  $_POST['extra_votes'] = count($data['votes']);
279  $data['text_answer'] = ($_POST['text_answer']!='') ? $_POST['text_answer'] : $ilFB->getTextAnswer();
280  if($ilFB->getStarttime()>=0||isset($_POST['start_day'])){
281  $data['start_day'] = $_POST['start_day'] ? $_POST['start_day'] : date('d',$ilFB->getStarttime());
282  $data['start_month'] =$_POST['start_month'] ? $_POST['start_month'] : date('m',$ilFB->getStarttime());
283  $data['start_year'] = $_POST['start_year'] ? $_POST['start_year'] :date('Y',$ilFB->getStarttime());
284  $data['start_hour'] = $_POST['start_hour'] ? $_POST['start_hour'] :date('H',$ilFB->getStarttime());
285  $data['start_minute'] = $_POST['start_minute'] ? $_POST['start_minute'] :date('i',$ilFB->getStarttime());
286  }
287  if($ilFB->getEndtime()>=0||isset($_POST['end_day'])){
288  $data['end_day'] = $_POST['end_day'] ? $_POST['end_day'] :date('d',$ilFB->getEndtime());
289  $data['end_month'] = $_POST['end_month'] ? $_POST['end_month'] :date('m',$ilFB->getEndtime());
290  $data['end_year'] = $_POST['end_year'] ? $_POST['end_year'] :date('Y',$ilFB->getEndtime());
291  $data['end_hour'] = $_POST['end_hour'] ? $_POST['end_hour'] :date('H',$ilFB->getEndtime());
292  $data['end_minute'] = $_POST['end_minute'] ? $_POST['end_minute'] :date('i',$ilFB->getEndtime());
293  }
294 
295  $data['interval'] = $_POST['interval'] ? $_POST['interval'] : $ilFB->getInterval();
296  $data['interval_unit'] = $_POST['interval_unit'] ? $_POST['interval_unit'] : $ilFB->getIntervalUnit();
297  $data['first_vote_best'] = ($_POST['first_vote_best']!='') ? $_POST['first_vote_best'] : $ilFB->getFirstVoteBest();
298 
299  $this->ctrl->setParameter($this,"barometer_id",$_GET['barometer_id']);
300  $tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
301  $tpl->setVariable("TXT_HEADER", $this->lng->txt("feedb_edit_feedback"));
302  $tpl->setVariable("IMG_FEEDB", ilUtil::getImagePath("icon_feedb.png"));
303  $tpl->setVariable("ALT_FEEDB", $this->lng->txt("feedb_edit_feedback"));
304  $tpl->setVariable("TXT_TITLE", $this->lng->txt("title"));
305  $tpl->setVariable("VALUE_TITLE",$data['title']);
306  $tpl->setVariable("TXT_TOP_TEXT", $this->lng->txt("text"));
307  $tpl->setVariable("TXT_TIME", $this->lng->txt("feedb_time"));
308  $tpl->setVariable("VALUE_TEXT", $data['description']);
309  $tpl->setVariable("TXT_ANONYMOUS", $this->lng->txt("anonymous"));
310 
311  if($data["anonymous"]=="0")
312  $tpl->setVariable("ANONYMOUS_NO", " checked");
313  else
314  $tpl->setVariable("ANONYMOUS_YES", " checked");
315  $tpl->setVariable("TXT_YES", $this->lng->txt("yes"));
316  $tpl->setVariable("TXT_NO", $this->lng->txt("no"));
317  $tpl->setVariable("TXT_TYPE", $this->lng->txt("type"));
318  $typeSB[0] = $this->lng->txt('optional');
319  $typeSB[1] = $this->lng->txt('required');
320 
321  $tpl->setVariable("SELECT_TYPE",
322  ilUtil::formSelect($data['required'],'type',$typeSB,false,true));
323 
324  $tpl->setVariable("TXT_REQUIRED", $this->lng->txt("required"));
325  if($data["show_on"]=="course")
326  $tpl->setVariable("SHOW_CHANGE_COURSE_SELECTED", "selected");
327  else
328  $tpl->setVariable("SHOW_LOGIN_SELECTED", "selected");
329  $tpl->setVariable("TXT_LOGIN", $this->lng->txt("login"));
330  $tpl->setVariable("TXT_CHANGE_COURSE", $this->lng->txt("change_course"));
331  if($data["text_answer"]=="1")
332  $tpl->setVariable("TEXT_ANSWER_YES", " checked");
333  else
334  $tpl->setVariable("TEXT_ANSWER_NO", " checked");
335  $tpl->setVariable("TXT_TEXT_ANSWER", $this->lng->txt("text_answer"));
336  $tpl->setVariable("TXT_VOTES", $this->lng->txt("votes"));
337  $extra_votes = $_POST["extra_votes"] ? $_POST["extra_votes"]+1 : (count($data["vote"])-2);
338  if ($extra_votes<1) $extra_votes=1;
339  $tpl->setVariable("VALUE_EXTRA_VOTES", $extra_votes);
340 
341  for($i=1;$i < 3+$extra_votes ;$i++){
342  $tpl->setCurrentBlock("vote");
343  $tpl->setVariable("TXT_TEXT",$this->lng->txt("text"));
344  $tpl->setVariable("VALUE_VOTE_TEXT",$data["vote"][$i]);
345  $tpl->setVariable("VOTE_NUM",$i);
346  $tpl->parseCurrentBlock();
347  }
348 
349  $tpl->setVariable("TXT_DAY",$this->lng->txt("day"));
350  $tpl->setVariable("SELECT_ACTIVATION_START_DAY",$this->getDateSelect('day','start_day',$data['start_day']));
351  $tpl->setVariable("SELECT_ACTIVATION_START_MONTH",$this->getDateSelect('month','start_month',$data['start_month']));
352  $tpl->setVariable("SELECT_ACTIVATION_START_YEAR",$this->getDateSelect('year','start_year',$data['start_year']));
353  $tpl->setVariable("SELECT_ACTIVATION_START_HOUR",$this->getDateSelect('hour','start_hour',$data['start_hour']));
354  $tpl->setVariable("SELECT_ACTIVATION_START_MINUTE",$this->getDateSelect('minute','start_minute',$data['start_minute']));
355  $tpl->setVariable("SELECT_ACTIVATION_END_DAY",$this->getDateSelect('day','end_day',$data['end_day']));
356  $tpl->setVariable("SELECT_ACTIVATION_END_MONTH",$this->getDateSelect('month','end_month',$data['end_month']));
357  $tpl->setVariable("SELECT_ACTIVATION_END_YEAR",$this->getDateSelect('year','end_year',$data['end_year']));
358  $tpl->setVariable("SELECT_ACTIVATION_END_HOUR",$this->getDateSelect('hour','end_hour',$data['end_hour']));
359  $tpl->setVariable("SELECT_ACTIVATION_END_MINUTE",$this->getDateSelect('minute','end_minute',$data['end_minute']));
360 
361  $tpl->setVariable("TXT_MONTH",$this->lng->txt("month"));
362  $tpl->setVariable("TXT_YEAR",$this->lng->txt("year"));
363  $tpl->setVariable("TXT_FROM",$this->lng->txt("from"));
364  $tpl->setVariable("TXT_UNTIL",$this->lng->txt("until"));
365 
366  $tpl->setVariable("TXT_DURATION",$this->lng->txt("duration"));
367  $tpl->setVariable("TXT_HOURS",$this->lng->txt("hours"));
368  $tpl->setVariable("TXT_DAYS",$this->lng->txt("days"));
369  $tpl->setVariable("TXT_WEEKS",$this->lng->txt("weeks"));
370  $tpl->setVariable("TXT_MONTHS",$this->lng->txt("months"));
371  $tpl->setVariable("TXT_REPEAT",$this->lng->txt("repeat"));
372  $tpl->setVariable("TXT_FTEXT",$this->lng->txt("text"));
373 
374  for($i=0;$i < 25;$i++){
375  $interval[$i]=$i;
376  }
377  $tpl->setVariable("SELECT_INTERVAL",ilUtil::formSelect($data['interval'],'interval',$interval,false,true));
378 
379  $interval_unitSB[0] = $this->lng->txt('hours');
380  $interval_unitSB[1] = $this->lng->txt('days');
381  $interval_unitSB[2] = $this->lng->txt('weeks');
382  $interval_unitSB[3] = $this->lng->txt('months');
383  $tpl->setVariable("SELECT_INTERVAL_UNIT",ilUtil::formSelect($data['interval_unit'],'interval_unit',$interval_unitSB,false,true));
384 
385  $tpl->setVariable("TXT_FIRST_VOTE",$this->lng->txt("first_vote"));
386  $tpl->setVariable("TXT_BEST",$this->lng->txt("best"));
387  $tpl->setVariable("TXT_WORST",$this->lng->txt("worst"));
388  if($data["first_vote_best"]==1)
389  $tpl->setVariable("BEST_CHECKED", "checked");
390  else
391  $tpl->setVariable("WORST_CHECKED", "checked");
392  $tpl->setVariable("TXT_VOTE", $this->lng->txt("vote"));
393  $tpl->setVariable("TXT_NEW_VOTE", $this->lng->txt("new_vote"));
394  $tpl->setVariable("CMD_ADDVOTE", 'edit');
395  $tpl->setVariable("TXT_SUBMIT", $this->lng->txt("save"));
396  $tpl->setVariable("CMD_SUBMIT", "update");
397  $tpl->parseCurrentBlock();
398  return $tpl->get();
399 
400  }
401  function update(){
402  $this->update=1;
403 
404  return $this->save();
405  }
406  function save(){
407  //print_r($_POST);
408  global $ilias;
409  include_once('Services/Feedback/classes/class.ilFeedback.php');
410  $params = $this->ctrl->getParameterArray($this);
411  $tmp_votes=array();
412  $vote_cnt=1;
413 
414  if($_POST['anonymous'] and $_POST['type'])
415  {
416  ilUtil::sendFailure($this->lng->txt('barometer_conflict_anon_req'));
417  #$this->ctrl->setParameter($this,'barometer_id',(int) $_GET['barometer_id']);
418  #$this->ctrl->redirect($this,'edit');
419  --$_POST['extra_votes'];
420  return $this->edit();
421  }
422  foreach ($_POST['vote'] as $k=>$v)
423  {
424  if(trim($v))
425  {
426  $tmp_votes[$vote_cnt]=$v;
427  $vote_cnt++;
428  }
429  }
430  if(($_POST['title']=='')||($_POST['text']=='')|| $vote_cnt<3)
431  {
432  ilUtil::sendFailure($this->lng->txt('missing_fields'));
433  --$_POST['extra_votes'];
434  return $this->edit();
435  #$this->ctrl->setParameter($this,'a','32');
436  #$ilias->raiseError($this->lng->txt('missing_fields'),$ilias->error_obj->MESSAGE);
437  }
438  $ilFeedback = new ilFeedback();
439  $ilFeedback->setTitle(ilUtil::stripSlashes($_POST['title']));
440  $ilFeedback->setDescription(ilUtil::stripSlashes($_POST['text']));
441  $ilFeedback->setAnonymous(ilUtil::stripSlashes($_POST['anonymous']));
442  $ilFeedback->setRequired(ilUtil::stripSlashes($_POST['type']));
443  $ilFeedback->setShowOn(ilUtil::stripSlashes($_POST['show_on']));
444  $ilFeedback->setTextAnswer(ilUtil::stripSlashes($_POST['text_answer']));
445  $ilFeedback->setVotes(serialize($tmp_votes));
446  $ilFeedback->setStarttime(mktime(ilUtil::stripSlashes($_POST['start_hour']),
447  ilUtil::stripSlashes($_POST['start_minute']),0,
448  ilUtil::stripSlashes($_POST['start_month']),
449  ilUtil::stripSlashes($_POST['start_day']),
450  ilUtil::stripSlashes($_POST['start_year'])));
451  $ilFeedback->setEndtime(mktime(
452  ilUtil::stripSlashes($_POST['end_hour']),
453  ilUtil::stripSlashes($_POST['end_minute']),0,
454  ilUtil::stripSlashes($_POST['end_month']),
455  ilUtil::stripSlashes($_POST['end_day']),
456  ilUtil::stripSlashes($_POST['end_year'])));
457  $ilFeedback->setInterval(
458  ilUtil::stripSlashes($_POST['interval']));
459  $ilFeedback->setIntervalUnit(
460  ilUtil::stripSlashes($_POST['interval_unit']));
461  $ilFeedback->setFirstVoteBest(
462  ilUtil::stripSlashes($_POST['first_vote_best']));
463  $ilFeedback->setObjId($params['obj_id']);
464  $ilFeedback->setRefId($params['ref_id']);
465  if($this->update == 1 && $_GET['barometer_id'])
466  {
467  $ilFeedback->setId($_GET['barometer_id']);
468  $ilFeedback->update();
469  }
470  else
471  $ilFeedback->create();
472  ilUtil::redirect($this->ctrl->getLinkTarget($this, 'fbList', '', false, false));
473 
474  }
475 
479  function get_last($a_var, $a_value='',$pForm=true)
480  {
481  if (!empty($_POST[$a_var])) $result=$_POST[$a_var];
482  elseif (!empty($_SESSION["error_post_vars"][$a_var])) $result=$_SESSION["error_post_vars"][$a_var];
483  else {
484  $result=$a_value;
485  $pForm=false;
486  }
487 
489  }
493  function addBarometer(){
494 
495  // deprecated - will be removed in 4.4
496  exit();
497 
498  $tpl = new ilTemplate("tpl.feedback_edit.html", true, true, "Services/Feedback");
499  $tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
500  $tpl->setVariable("TXT_HEADER", $this->lng->txt("bar_create"));
501  $tpl->setVariable("IMG_FEEDB", ilUtil::getImagePath("icon_feedb.png"));
502  $tpl->setVariable("ALT_FEEDB", $this->lng->txt("bar_create"));
503  $tpl->setVariable("TXT_TITLE", $this->lng->txt("title"));
504  $tpl->setVariable("TXT_TIME", $this->lng->txt("feedb_time"));
505  $tpl->setVariable("VALUE_TITLE",$this->get_last("title"));
506  $tpl->setVariable("TXT_TOP_TEXT", $this->lng->txt("text"));
507  $tpl->setVariable("VALUE_TEXT", $this->get_last("text"));
508  $tpl->setVariable("TXT_ANONYMOUS", $this->lng->txt("anonymous"));
509  if($this->get_last("anonymous")=="0")
510  $tpl->setVariable("ANONYMOUS_NO", " checked");
511  else
512  $tpl->setVariable("ANONYMOUS_YES", " checked");
513  $tpl->setVariable("TXT_YES", $this->lng->txt("yes"));
514  $tpl->setVariable("TXT_NO", $this->lng->txt("no"));
515  $tpl->setVariable("TXT_TYPE", $this->lng->txt("type"));
516  $typeSB[0] = $this->lng->txt('optional');
517  $typeSB[1] = $this->lng->txt('required');
518  $tpl->setVariable("SELECT_TYPE", ilUtil::formSelect($this->get_last('type'),'type',$typeSB,false,true));
519 
520  $tpl->setVariable("TXT_REQUIRED", $this->lng->txt("required"));
521  if($this->get_last("show_on")=="course")
522  $tpl->setVariable("SHOW_CHANGE_COURSE_SELECTED", "selected");
523  else
524  $tpl->setVariable("SHOW_LOGIN_SELECTED", "selected");
525  $tpl->setVariable("TXT_LOGIN", $this->lng->txt("login"));
526  $tpl->setVariable("TXT_CHANGE_COURSE", $this->lng->txt("change_course"));
527  if($this->get_last("text_answer")=="1")
528  $tpl->setVariable("TEXT_ANSWER_YES", " checked");
529  else
530  $tpl->setVariable("TEXT_ANSWER_NO", " checked");
531  $tpl->setVariable("TXT_TEXT_ANSWER", $this->lng->txt("text_answer"));
532  $tpl->setVariable("TXT_VOTES", $this->lng->txt("votes"));
533  $extra_votes = $this->get_last("extra_votes",0);
534  if ($_POST['cmd']['addBarometer']) $extra_votes+=1;
535  $tpl->setVariable("VALUE_EXTRA_VOTES", $extra_votes);
536  $vote_txt=$this->get_last('vote',array(),false);
537  for($i=1;$i < 3+$extra_votes ;$i++){
538  $tpl->setCurrentBlock("vote");
539  $tpl->setVariable("TXT_TEXT",$this->lng->txt("text"));
540  $tpl->setVariable("VALUE_VOTE_TEXT",ilUtil::prepareFormOutput($vote_txt[$i]));
541  $tpl->setVariable("VOTE_NUM",$i);
542  $tpl->parseCurrentBlock();
543  }
544  $tpl->setVariable("TXT_DAY",$this->lng->txt("day"));
545  $tpl->setVariable("SELECT_ACTIVATION_START_DAY",$this->getDateSelect('day','start_day',$this->get_last('start_day')));
546  $tpl->setVariable("SELECT_ACTIVATION_START_MONTH",$this->getDateSelect('month','start_month',$this->get_last('start_month')));
547  $tpl->setVariable("SELECT_ACTIVATION_START_YEAR",$this->getDateSelect('year','start_year',$this->get_last('start_year')));
548  $tpl->setVariable("SELECT_ACTIVATION_START_HOUR",$this->getDateSelect('hour','start_hour',$this->get_last('start_hour')));
549  $tpl->setVariable("SELECT_ACTIVATION_START_MINUTE",$this->getDateSelect('minute','start_minute',$this->get_last('start_minute')));
550  $tpl->setVariable("SELECT_ACTIVATION_END_DAY",$this->getDateSelect('day','end_day',$this->get_last('end_day')));
551  $tpl->setVariable("SELECT_ACTIVATION_END_MONTH",$this->getDateSelect('month','end_month',$this->get_last('end_month')));
552  $tpl->setVariable("SELECT_ACTIVATION_END_YEAR",$this->getDateSelect('year','end_year',$this->get_last('end_year')));
553  $tpl->setVariable("SELECT_ACTIVATION_END_HOUR",$this->getDateSelect('hour','end_hour',$this->get_last('end_hour')));
554  $tpl->setVariable("SELECT_ACTIVATION_END_MINUTE",$this->getDateSelect('minute','end_minute',$this->get_last('end_minute')));
555 
556  $tpl->setVariable("TXT_MONTH",$this->lng->txt("month"));
557  $tpl->setVariable("TXT_YEAR",$this->lng->txt("year"));
558  $tpl->setVariable("TXT_FROM",$this->lng->txt("from"));
559  $tpl->setVariable("TXT_UNTIL",$this->lng->txt("until"));
560 
561  $tpl->setVariable("TXT_DURATION",$this->lng->txt("duration"));
562  $tpl->setVariable("TXT_HOURS",$this->lng->txt("hours"));
563  $tpl->setVariable("TXT_DAYS",$this->lng->txt("days"));
564  $tpl->setVariable("TXT_WEEKS",$this->lng->txt("weeks"));
565  $tpl->setVariable("TXT_MONTHS",$this->lng->txt("months"));
566  $tpl->setVariable("TXT_REPEAT",$this->lng->txt("repeat"));
567 
568  for($i=0;$i < 25;$i++){
569  $interval[$i]=$i;
570  }
571  $tpl->setVariable("SELECT_INTERVAL",ilUtil::formSelect($this->get_last('interval'),'interval',$interval,false,true));
572  $tpl->setVariable("TXT_EVERY",$this->lng->txt("every"));
573 
574  $interval_unitSB[0] = $this->lng->txt('hours');
575  $interval_unitSB[1] = $this->lng->txt('days');
576  $interval_unitSB[2] = $this->lng->txt('weeks');
577  $interval_unitSB[3] = $this->lng->txt('months');
578  $tpl->setVariable("SELECT_INTERVAL_UNIT",ilUtil::formSelect($this->get_last('interval_unit'),'interval_unit',$interval_unitSB,false,true));
579 
580  $tpl->setVariable("TXT_FIRST_VOTE",$this->lng->txt("first_vote"));
581  $tpl->setVariable("TXT_BEST",$this->lng->txt("best"));
582  $tpl->setVariable("TXT_WORST",$this->lng->txt("worst"));
583  if($this->get_last("first_vote_best")==1)
584  $tpl->setVariable("BEST_CHECKED", "checked");
585  else
586  $tpl->setVariable("WORST_CHECKED", "checked");
587 
588  $tpl->setVariable("TXT_NEW_VOTE", $this->lng->txt("new_vote"));
589  $tpl->setVariable("CMD_ADDVOTE", 'addBarometer');
590  $tpl->setVariable("TXT_SUBMIT", $this->lng->txt("save"));
591  $tpl->setVariable("CMD_SUBMIT", "save");
592  $tpl->parseCurrentBlock();
593  return($tpl->get());
594 
595  }
596  function getButtons($a_barometer_id){
597 
598  $tpl = new ilTemplate("tpl.buttons.html", true, true,"Services/Feedback");
599 
600  $tpl->setCurrentBlock("btn_cell");
601  $this->ctrl->setParameter($this,"barometer_id",$a_barometer_id);
602  $this->ctrl->setParameter($this,"ref_id",$_GET['ref_id']);
603  $tpl->setVariable("BTN_LINK", $this->ctrl->getLinkTarget($this,'stats'));
604  $tpl->setVariable("BTN_TXT", $this->lng->txt("statistics"));
605  $tpl->parseCurrentBlock();
606  $tpl->setCurrentBlock("btn_cell");
607  $tpl->setVariable("BTN_LINK", $this->ctrl->getLinkTarget($this,'edit'));
608  $tpl->setVariable("BTN_TXT", $this->lng->txt("edit"));
609  $tpl->parseCurrentBlock();
610  return($tpl->get());
611  }
612  function getDateSelect($a_type,$a_varname,$a_selected)
613  {
614  switch($a_type)
615  {
616  case "minute":
617  for($i=0;$i<60;$i++)
618  {
619  $days[$i] = $i < 10 ? "0".$i : $i;
620  }
621  return ilUtil::formSelect($a_selected,$a_varname,$days,false,true);
622 
623  case "hour":
624  for($i=0;$i<24;$i++)
625  {
626  $days[$i] = $i < 10 ? "0".$i : $i;
627  }
628  return ilUtil::formSelect($a_selected,$a_varname,$days,false,true);
629 
630  case "day":
631  for($i=1;$i<32;$i++)
632  {
633  $days[$i] = $i < 10 ? "0".$i : $i;
634  }
635  $days[0] = '';
636  return ilUtil::formSelect($a_selected,$a_varname,$days,false,true);
637 
638  case "month":
639  for($i=1;$i<13;$i++)
640  {
641  $month[$i] = $i < 10 ? "0".$i : $i;
642  }
643  $month[0] = '';
644  return ilUtil::formSelect($a_selected,$a_varname,$month,false,true);
645 
646  case "year":
647  for($i = date("Y",time());$i < date("Y",time()) + 3;++$i)
648  {
649  $year[$i] = $i;
650  }
651  $year[0] = '';
652  return ilUtil::formSelect($a_selected,$a_varname,$year,false,true);
653  }
654  }
655 
656  function showBarometerById($a_id=0, $a_header = false){
657  global $ilAccess,$ilUser;
658  include_once('Services/Feedback/classes/class.ilFeedback.php');
659  $feedback = new ilFeedback();
660  $bid = $a_id ? $a_id :$_GET['barometer_id'];
661  $feedback->setId($bid);
662  $feedback->getBarometer();
663  if($feedback->getId()&& ($feedback->canVote($ilUser->getId(),$feedback->getId())==1)){
664  $tpl = new ilTemplate("tpl.feedback_vote.html", true,true, "Services/Feedback");
665 
666  if ($a_header)
667  {
668  $tpl->setCurrentBlock("vote_head");
669  $tpl->setVariable("IMG_VHEAD", ilUtil::getImagePath("icon_crs.png"));
670  $tpl->setVariable("TXT_CRS_TITLE", ilObject::_lookupTitle($feedback->getObjId()));
671  $tpl->parseCurrentBlock();
672  }
673 
674  $tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this).'&fb_id='.$feedback->getId());
675  $tpl->setVariable("TXT_TITLE", $feedback->getTitle());
676  $tpl->setVariable("TXT_DESCRIPTION", $feedback->getDescription());
677  $votes = unserialize($feedback->getVotes());
678  $checked = 1;
679  foreach($votes as $vote => $votetext){
680  $radios.=ilUtil::formRadioButton($checked,'vote',$vote).$votetext.'<br>';
681  $checked = 0;
682  }
683  $tpl->setVariable("TXT_SAVE",$this->lng->txt('save_vote'));
684 
685  $tpl->setVariable("RADIO_VOTES",$radios);
686  if($feedback->getTextAnswer()){
687  $tpl->setCurrentBlock("text_answer");
688  $tpl->setVariable("TXT_NOTE",$this->lng->txt('note'));
689 
690  }
691  $tpl->parseCurrentBlock();
692 
693  return($tpl->get());
694  }
695 
696  }
698  {
699  global $ilUser;
700  include_once('Services/Feedback/classes/class.ilFeedback.php');
701  include_once('Modules/Course/classes/class.ilCourseParticipant.php');
702 
703 
704  $feedback = new ilFeedback();
705  $feedback->getFeedback();
706 
707  $members_obj = ilCourseParticipant::_getInstanceByObjId($feedback->getObjId(),$ilUser->getId());
708  if(($feedback->getId()) && ($members_obj->isAssigned()))
709 
710  return($feedback->getRefId());
711  else
712  return(0);
713 
714  }
715 
716  function showBarometer(){
717  global $ilUser;
718  include_once('Services/Feedback/classes/class.ilFeedback.php');
719 
720  $ilfeedback = new ilFeedback();
721  $ilfeedback->setRefId($_GET['ref_id']);
722  $feedbacks = $ilfeedback->getAllBarometer();
723 
724  //There can be more then 1 Barometer for a ref_id so we show show always only the first_vote_best
725  //Barometer a user can vote, the next time he acceses this page, he will get the next barometer a.s.o.
726  foreach($feedbacks as $feedback){
727  //Show only if there is no vote yet or enough time has passed since the last vote
728  if($feedback->getId()&& ($feedback->canVote($ilUser->getId(),$feedback->getId())==1)){
729  $tpl = new ilTemplate("tpl.feedback_vote.html", true,true, "Services/Feedback");
730  $tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this).'&fb_id='.$feedback->getId());
731  $tpl->setVariable("TXT_TITLE", $feedback->getTitle());
732  $tpl->setVariable("TXT_DESCRIPTION", $feedback->getDescription());
733  $votes = unserialize($feedback->getVotes());
734  $checked = 1;
735  foreach($votes as $vote => $votetext){
736  $radios.=ilUtil::formRadioButton($checked,'vote',$vote).$votetext.'<br>';
737  $checked = 0;
738  }
739  $tpl->setVariable("TXT_SAVE",$this->lng->txt('save_vote'));
740  $tpl->setVariable("RADIO_VOTES",$radios);
741  if($feedback->getTextAnswer()){
742  $tpl->setCurrentBlock("text_answer");
743  $tpl->setVariable("TXT_NOTE",$this->lng->txt('note'));
744 
745  }
746  $tpl->parseCurrentBlock();
747 
748  return($tpl->get());
749  }
750  }
751  }
752  function saveVote(){
753  global $ilUser;
754  include_once('Services/Feedback/classes/class.ilFeedback.php');
755 
756  $feedback = new ilFeedback();
757  $feedback->setId($_GET['fb_id']);
758  $feedback->getBarometer();
759  $feedback->setVote(ilUtil::stripSlashes($_POST['vote']));
760  $feedback->setNote(ilUtil::stripSlashes($_POST['text_answer']));
761  if($feedback->getAnonymous())
762  $feedback->setUserId(0);
763  else
764  $feedback->setUserId($ilUser->getId());
765  $feedback->saveResult();
766  $this->ctrl->returnToParent($this);
767  }
768  function selectbox($selected_itm, $name, $items, $params='',$first=''){
769  $selected_ = '';
770  $options = $first ? '<option value="">'.$first.'</option>'.chr(10) : '';
771  if(is_Array($items)){
772  foreach($items as $key => $item){
773  $selected = ($key == $selected_itm) ? ' selected' : '';
774  $options.='<option value="'.$key.'"'.$selected.'>'.$item.'</option>'.chr(10);
775 
776  }
777  }
778  $content = '<select name="'.$name.'" '.$params.'>
779  '.$options.'
780  </select>';
781  return($content);
782  }
783 
785  global $ilUser, $ilAccess;
786 
787  include_once('Services/Feedback/classes/class.ilFeedback.php');
788  $feedback = new ilFeedback();
789  $barometers = $feedback->getAllBarometer(0);
790 
791  $tpl = new ilTemplate("tpl.feedback_pdbox.html", true,true, "Services/Feedback");
792  $tpl->setVariable('TXT_TITLE',$this->lng->txt('feedback'));
793  $rownum = 0;
794  if(count($barometers)){
795  foreach ($barometers as $barometer)
796  {
797  // do not show feedback for tutors/admins
798  if ($ilAccess->checkAccess("write", "", $barometer->getRefId()))
799  {
800  continue;
801  }
802  if($barometer->canVote($ilUser->getId(),$barometer->getId())==1)
803  {
804  $tpl->setCurrentBlock('tbl_row');
805  $tpl->setVariable('ROWCOL', 'tblrow'.(($rownum++ % 2)+1));
806  $this->ctrl->setParameter($this,"barometer_id",$barometer->getId());
807  $link ='<a href="'.$this->ctrl->getLinkTargetByClass('ilfeedbackgui','voteform').'">'.$barometer->getTitle().'</a>';
808  $tpl->setVariable('BAROMETER_LINK',$link);
809  $tpl->parseCurrentBlock();
810  }
811  }
812  }
813  $output = $rownum ? $tpl->get() : '' ;
814  return($output);
815  }
816 
818  global $ilUser;
819 
820  include_once('Services/Feedback/classes/class.ilFeedback.php');
821  $feedback = new ilFeedback();
822  $feedback->setRefId($_GET['ref_id']);
823  $barometers = $feedback->getAllBarometer(0);
824 
825  $tpl = new ilTemplate("tpl.feedback_pdbox.html", true,true, "Services/Feedback");
826  $tpl->setVariable('TXT_TITLE',$this->lng->txt('feedback'));
827  $rownum = 0;
828  if(count($barometers)){
829  foreach ($barometers as $barometer){
830  if($barometer->canVote($ilUser->getId(),$barometer->getId())==1){
831  $tpl->setCurrentBlock('tbl_row');
832  $tpl->setVariable('ROWCOL', 'tblrow'.(($rownum++ % 2)+1));
833  $this->ctrl->setParameter($this,"barometer_id",$barometer->getId());
834  $link ='<a href="'.$this->ctrl->getLinkTargetByClass(array('ilinfoscreengui','ilfeedbackgui'),'fbList').'">'.$barometer->getTitle().'</a>';
835 
836  $tpl->setVariable('BAROMETER_LINK',$link);
837  $tpl->parseCurrentBlock();
838  }
839  }
840  }
841  $output = $rownum ? $tpl->get() : '' ;
842  return($output);
843  }
844 
845  function handleRequiredFeedback($a_ref_id = 0)
846  {
847  global $ilUser;
848 
849  include_once('Services/Feedback/classes/class.ilFeedback.php');
850  $feedback = new ilFeedback();
851  if ($a_ref_id > 0)
852  {
853  $feedback->setRefId($a_ref_id);
854  }
855  $barometers = $feedback->getAllBarometer(0,1);
856 
857  $rownum = 0;
858  if(count($barometers))
859  {
860  foreach ($barometers as $barometer)
861  {
862  if($barometer->canVote($ilUser->getId(),$barometer->getId())==1){
863  $this->ctrl->setParameter($this,"barometer_id",$barometer->getId());
864  $this->ctrl->redirectByClass(array("ilinfoscreengui", "ilfeedbackgui"), "showBarometerById");
865  }
866  }
867  }
868  }
869 
870  function voteform($a_barometer_id=0){
871  global $tpl;
872 
873  $barometer_id = $a_barometer_id ? $a_barometer_id :$_GET['barometer_id'];
874  //$tpl->setVariable('CONTENT',$this->showBarometerById($a_barometer_id));
875  $tpl->setContent($this->showBarometerById($a_barometer_id, true));
876  //$tpl->parseCurrentBlock();
877  $tpl->show();
878 
879  }
880 }
881 ?>