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