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