ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjAssessmentFolderGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 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 include_once "./classes/class.ilObjectGUI.php";
25 
37 {
43 
44  public function ilObjAssessmentFolderGUI($a_data,$a_id,$a_call_by_reference)
45  {
46  global $rbacsystem;
47 
48  $this->type = "assf";
49  $this->ilObjectGUI($a_data,$a_id,$a_call_by_reference,false);
50 
51  if (!$rbacsystem->checkAccess('read',$this->object->getRefId()))
52  {
53  $this->ilias->raiseError($this->lng->txt("msg_no_perm_read_assf"),$this->ilias->error_obj->WARNING);
54  }
55  }
56 
57  public function &executeCommand()
58  {
59  $next_class = $this->ctrl->getNextClass($this);
60  $cmd = $this->ctrl->getCmd();
61  $this->prepareOutput();
62 
63  switch($next_class)
64  {
65  case 'ilpermissiongui':
66  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
67  $perm_gui =& new ilPermissionGUI($this);
68  $ret =& $this->ctrl->forwardCommand($perm_gui);
69  break;
70 
71  default:
72  if($cmd == "" || $cmd == "view")
73  {
74  $cmd = "settings";
75  }
76  $cmd .= "Object";
77  $this->$cmd();
78 
79  break;
80  }
81  return true;
82  }
83 
84 
89  public function saveObject()
90  {
91  global $rbacadmin;
92 
93  // create and insert forum in objecttree
94  $newObj = parent::saveObject();
95 
96  // put here object specific stuff
97 
98  // always send a message
99  ilUtil::sendSuccess($this->lng->txt("object_added"),true);
100 
101  $this->ctrl->redirect($this);
102  }
103 
104 
108  public function settingsObject()
109  {
110  global $ilAccess;
111 
112  include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
113  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
114  $form = new ilPropertyFormGUI();
115  $form->setFormAction($this->ctrl->getFormAction($this));
116  $form->setTableWidth("100%");
117  $form->setId("settings");
118 
119  // general properties
120  $header = new ilFormSectionHeaderGUI();
121  $header->setTitle($this->lng->txt("assessment_log_logging"));
122  $form->addItem($header);
123 
124  // assessment logging
125  $logging = new ilCheckboxInputGUI('', "chb_assessment_logging");
126  $logging->setValue(1);
127  $logging->setChecked($this->object->_enabledAssessmentLogging());
128  $logging->setOptionTitle($this->lng->txt("activate_assessment_logging"));
129  $form->addItem($logging);
130 
131  // reporting language
132  $reporting = new ilSelectInputGUI($this->lng->txt('assessment_settings_reporting_language'), "reporting_language");
133  $languages = $this->lng->getInstalledLanguages();
134  $options = array();
135  foreach ($languages as $lang)
136  {
137  $options[$lang] = $this->lng->txt("lang_" . $lang);
138  }
139  $reporting->setOptions($options);
140  $reporting->setValue($this->object->_getLogLanguage());
141  $form->addItem($reporting);
142 
143  // question settings
144  $header = new ilFormSectionHeaderGUI();
145  $header->setTitle($this->lng->txt("assf_questiontypes"));
146  $form->addItem($header);
147 
148  // available question types
149  $allowed = new ilCheckboxGroupInputGUI($this->lng->txt('assf_allowed_questiontypes'), "chb_allowed_questiontypes");
150  $questiontypes =& ilObjQuestionPool::_getQuestionTypes(TRUE);
151  $forbidden_types = $this->object->_getForbiddenQuestionTypes();
152  $allowedtypes = array();
153  foreach ($questiontypes as $qt)
154  {
155  if (!in_array($qt['question_type_id'], $forbidden_types)) array_push($allowedtypes, $qt['question_type_id']);
156  }
157  $allowed->setValue($allowedtypes);
158  foreach ($questiontypes as $type_name => $qtype)
159  {
160  $allowed->addOption(new ilCheckboxOption($type_name, $qtype["question_type_id"]));
161  }
162  $allowed->setInfo($this->lng->txt('assf_allowed_questiontypes_desc'));
163  $form->addItem($allowed);
164 
165  // manual scoring
166  $manual = new ilCheckboxGroupInputGUI($this->lng->txt('assessment_log_manual_scoring_activate'), "chb_manual_scoring");
167  $manscoring = $this->object->_getManualScoring();
168  $manual->setValue($manscoring);
169  foreach ($questiontypes as $type_name => $qtype)
170  {
171  $manual->addOption(new ilCheckboxOption($type_name, $qtype["question_type_id"]));
172  }
173  $manual->setInfo($this->lng->txt('assessment_log_manual_scoring_desc'));
174  $form->addItem($manual);
175 
176  if ($ilAccess->checkAccess("write", "", $this->object->getRefId()))
177  {
178  $form->addCommandButton("saveSettings", $this->lng->txt("save"));
179  }
180  $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
181  }
182 
186  public function saveSettingsObject()
187  {
188  global $ilAccess;
189  if (!$ilAccess->checkAccess("write", "", $this->object->getRefId())) $this->ctrl->redirect($this,'settings');
190 
191  if ($_POST["chb_assessment_logging"] == 1)
192  {
193  $this->object->_enableAssessmentLogging(1);
194  }
195  else
196  {
197  $this->object->_enableAssessmentLogging(0);
198  }
199  $this->object->_setLogLanguage($_POST["reporting_language"]);
200  $this->object->_setManualScoring($_POST["chb_manual_scoring"]);
201  include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
202  $questiontypes =& ilObjQuestionPool::_getQuestionTypes(TRUE);
203  $forbidden_types = array();
204  foreach ($questiontypes as $name => $row)
205  {
206  if (!in_array($row["question_type_id"], $_POST["chb_allowed_questiontypes"]))
207  {
208  array_push($forbidden_types, $row["question_type_id"]);
209  }
210  }
211  $this->object->_setForbiddenQuestionTypes($forbidden_types);
212  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"),true);
213 
214  $this->ctrl->redirect($this,'settings');
215  }
216 
220  public function showLogObject()
221  {
222  $from = mktime($_POST['log_from']['time']['h'], $_POST['log_from']['time']['m'], 0, $_POST['log_from']['date']['m'], $_POST['log_from']['date']['d'], $_POST['log_from']['date']['y']);
223  $until = mktime($_POST['log_until']['time']['h'], $_POST['log_until']['time']['m'], 0, $_POST['log_until']['date']['m'], $_POST['log_until']['date']['d'], $_POST['log_until']['date']['y']);
224  $test = $_POST['sel_test'];
225  $this->logsObject($from, $until, $test);
226  }
227 
231  public function exportLogObject()
232  {
233  $from = mktime($_POST['log_from']['time']['h'], $_POST['log_from']['time']['m'], 0, $_POST['log_from']['date']['m'], $_POST['log_from']['date']['d'], $_POST['log_from']['date']['y']);
234  $until = mktime($_POST['log_until']['time']['h'], $_POST['log_until']['time']['m'], 0, $_POST['log_until']['date']['m'], $_POST['log_until']['date']['d'], $_POST['log_until']['date']['y']);
235  $test = $_POST['sel_test'];
236 
237  $csv = array();
238  $separator = ";";
239  $row = array(
240  $this->lng->txt("assessment_log_datetime"),
241  $this->lng->txt("user"),
242  $this->lng->txt("assessment_log_text"),
243  $this->lng->txt("question")
244  );
245  include_once "./Modules/Test/classes/class.ilObjTest.php";
246  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
247  $available_tests =& ilObjTest::_getAvailableTests(1);
248  array_push($csv, ilUtil::processCSVRow($row, TRUE, $separator));
249  $log_output =& $this->object->getLog($from, $until, $test);
250  $users = array();
251  foreach ($log_output as $key => $log)
252  {
253  if (!array_key_exists($log["user_fi"], $users))
254  {
255  $users[$log["user_fi"]] = ilObjUser::_lookupName($log["user_fi"]);
256  }
257  $title = "";
258  if ($log["question_fi"] || $log["original_fi"])
259  {
260  $title = assQuestion::_getQuestionTitle($log["question_fi"]);
261  if (strlen($title) == 0)
262  {
263  $title = assQuestion::_getQuestionTitle($log["original_fi"]);
264  }
265  $title = $this->lng->txt("assessment_log_question") . ": " . $title;
266  }
267  $csvrow = array();
268  $date = new ilDateTime($log['tstamp'],IL_CAL_UNIX);
269  array_push($csvrow, $date->get(IL_CAL_FKT_DATE,'Y-m-d H:i'));
270  array_push($csvrow, trim($users[$log["user_fi"]]["title"] . " " . $users[$log["user_fi"]]["firstname"] . " " . $users[$log["user_fi"]]["lastname"]));
271  array_push($csvrow, trim($log["logtext"]));
272  array_push($csvrow, $title);
273  array_push($csv, ilUtil::processCSVRow($csvrow, TRUE, $separator));
274  }
275  $csvoutput = "";
276  foreach ($csv as $row)
277  {
278  $csvoutput .= join($row, $separator) . "\n";
279  }
280  ilUtil::deliverData($csvoutput, str_replace(" ", "_", "log_" . $from . "_" . $until . "_" . $available_tests[$test]).".csv");
281  }
282 
286  public function logsObject($p_from = null, $p_until = null, $p_test = null)
287  {
288  $template = new ilTemplate("tpl.assessment_logs.html", TRUE, TRUE, "Modules/Test");
289 
290  include_once "./Modules/Test/classes/class.ilObjTest.php";
291  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
292  $available_tests =& ilObjTest::_getAvailableTests(1);
293  if (count($available_tests) == 0)
294  {
295  ilUtil::sendInfo($this->lng->txt('assessment_log_no_data'));
296  return;
297  }
298 
299  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
300  $form = new ilPropertyFormGUI();
301  $form->setFormAction($this->ctrl->getFormAction($this));
302  $form->setTableWidth("100%");
303  $form->setId("logs");
304 
305  $header = new ilFormSectionHeaderGUI();
306  $header->setTitle($this->lng->txt("assessment_log"));
307  $form->addItem($header);
308 
309  // from
310  $from = new ilDateTimeInputGUI($this->lng->txt('cal_from'), "log_from");
311  $from->setShowDate(true);
312  $from->setShowTime(true);
313  $now = getdate();
314  $fromdate = ($p_from) ? $p_from : (($_GET['log_from']) ? $_GET['log_from'] : mktime(0, 0, 0, 1, 1, $now['year']));
315  $from->setDate(new ilDateTime($fromdate, IL_CAL_UNIX));
316  $form->addItem($from);
317 
318  // until
319  $until = new ilDateTimeInputGUI($this->lng->txt('cal_until'), "log_until");
320  $until->setShowDate(true);
321  $until->setShowTime(true);
322  $untildate = ($p_until) ? $p_until : (($_GET['log_until']) ? $_GET['log_until'] : time());
323  $until->setDate(new ilDateTime($untildate, IL_CAL_UNIX));
324  $form->addItem($until);
325 
326  // tests
327  $fortest = new ilSelectInputGUI($this->lng->txt('assessment_log_for_test'), "sel_test");
328  $options = array();
329  foreach ($available_tests as $key => $value)
330  {
331  $options[$key] = ilUtil::prepareFormOutput($value) . " [" . $this->object->getNrOfLogEntries($key) . " " . $this->lng->txt("assessment_log_log_entries") . "]";
332  }
333  $fortest->setOptions($options);
334  $p_test = ($p_test) ? $p_test : $_GET['sel_test'];
335  if ($p_test) $fortest->setValue($p_test);
336  $form->addItem($fortest);
337  $this->ctrl->setParameter($this, 'sel_test', $p_test);
338  $this->ctrl->setParameter($this, 'log_until', $untildate);
339  $this->ctrl->setParameter($this, 'log_from', $fromdate);
340  $form->addCommandButton("showLog", $this->lng->txt("show"));
341  $form->addCommandButton("exportLog", $this->lng->txt("export"));
342  $template->setVariable("FORM", $form->getHTML());
343 
344  if ($p_test)
345  {
346  include_once "./Modules/Test/classes/tables/class.ilAssessmentFolderLogTableGUI.php";
347  $table_gui = new ilAssessmentFolderLogTableGUI($this, 'logs');
348  $log_output =& $this->object->getLog($fromdate, $untildate, $p_test);
349  $table_gui->setData($log_output);
350  $template->setVariable('LOG', $table_gui->getHTML());
351  }
352  $this->tpl->setVariable("ADM_CONTENT", $template->get());
353  }
354 
358  public function deleteLogObject()
359  {
360  if (is_array($_POST["chb_test"]) && (count($_POST["chb_test"])))
361  {
362  $this->object->deleteLogEntries($_POST["chb_test"]);
363  ilUtil::sendSuccess($this->lng->txt("ass_log_deleted"));
364  }
365  else
366  {
367  ilUtil::sendInfo($this->lng->txt("ass_log_delete_no_selection"));
368  }
369  $this->logAdminObject();
370  }
371 
375  public function logAdminObject()
376  {
377  global $ilAccess;
378  $a_write_access = ($ilAccess->checkAccess("write", "", $this->object->getRefId())) ? true : false;
379 
380  include_once "./Modules/Test/classes/tables/class.ilAssessmentFolderLogAdministrationTableGUI.php";
381  $table_gui = new ilAssessmentFolderLogAdministrationTableGUI($this, 'logAdmin', $a_write_access);
382  include_once "./Modules/Test/classes/class.ilObjTest.php";
383  $available_tests =& ilObjTest::_getAvailableTests(true);
384  $data = array();
385  foreach ($available_tests as $obj_id => $title)
386  {
387  $nr = $this->object->getNrOfLogEntries($obj_id);
388  array_push($data, array("title" => $title, "nr" => $nr, "id" => $obj_id));
389  }
390  $table_gui->setData($data);
391  $this->tpl->setVariable('ADM_CONTENT', $table_gui->getHTML());
392  }
393 
394  public function getAdminTabs(&$tabs_gui)
395  {
396  $this->getTabs($tabs_gui);
397  }
398 
399  public function getLogdataSubtabs()
400  {
401  global $ilTabs;
402 
403  // log output
404  $ilTabs->addSubTabTarget("ass_log_output",
405  $this->ctrl->getLinkTarget($this, "logs"),
406  array("logs", "showLog", "exportLog")
407  , "");
408 
409  // log administration
410  $ilTabs->addSubTabTarget("ass_log_admin",
411  $this->ctrl->getLinkTarget($this, "logAdmin"),
412  array("logAdmin", "deleteLog"),
413  "", "");
414 
415  }
416 
420  public function defaultsObject()
421  {
422  global $ilAccess, $rbacreview, $lng, $ilCtrl, $tpl, $ilDB;
423 
424  $assessmentSetting = new ilSetting("assessment");
425  $user_criteria = array_key_exists("user_criteria", $_GET) ? $_GET["user_criteria"] : $assessmentSetting->get("user_criteria");
426  if (strlen($user_criteria) == 0) $user_criteria = 'usr_id';
427  $use_javascript = array_key_exists("use_javascript", $_GET) ? $_GET["use_javascript"] : $assessmentSetting->get("use_javascript");
428  $imap_line_color = array_key_exists("imap_line_color", $_GET) ? $_GET["imap_line_color"] : $assessmentSetting->get("imap_line_color");
429  if (strlen($imap_line_color) == 0) $imap_line_color = "FF0000";
430 
431  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
432  $form = new ilPropertyFormGUI();
433  $form->setFormAction($ilCtrl->getFormAction($this));
434  $form->setTitle($lng->txt("assessment_defaults"));
435 
436  // Enable javascript
437  $enable = new ilCheckboxInputGUI($lng->txt("assessment_use_javascript"), "use_javascript");
438  $enable->setChecked($use_javascript);
439  $enable->setInfo($lng->txt("assessment_use_javascript_desc"));
440  $form->addItem($enable);
441 
442  $linepicker = new ilColorPickerInputGUI($lng->txt("assessment_imap_line_color"), "imap_line_color");
443  $linepicker->setValue($imap_line_color);
444  $form->addItem($linepicker);
445 
446  $userCriteria = new ilSelectInputGUI($this->lng->txt("user_criteria"), "user_criteria");
447  $userCriteria->setInfo($this->lng->txt("user_criteria_desc"));
448  $userCriteria->setRequired(true);
449  $userCriteria->setValue(($isSingleline) ? 0 : 1);
450 
451  $manager = $ilDB->db->loadModule('Manager');
452  $fields = $manager->listTableFields('usr_data');
453  $usr_fields = array();
454  foreach ($fields as $field)
455  {
456  $usr_fields[$field] = $field;
457  }
458  $userCriteria->setOptions($usr_fields);
459  $userCriteria->setValue($user_criteria);
460  $form->addItem($userCriteria);
461 
462  if ($ilAccess->checkAccess("write", "", $this->object->getRefId()))
463  {
464  $form->addCommandButton("saveDefaults", $lng->txt("save"));
465  }
466 
467 
468  $tpl->setVariable("ADM_CONTENT", $form->getHTML());
469  }
470 
474  public function saveDefaultsObject()
475  {
476  global $ilCtrl;
477 
478  $assessmentSetting = new ilSetting("assessment");
479  if ($_POST["use_javascript"])
480  {
481  $assessmentSetting->set("use_javascript", "1");
482  }
483  else
484  {
485  $assessmentSetting->set("use_javascript", "0");
486  }
487  if (strlen($_POST["imap_line_color"]) == 6)
488  {
489  $assessmentSetting->set("imap_line_color", $_POST["imap_line_color"]);
490  }
491  $assessmentSetting->set("user_criteria", $_POST["user_criteria"]);
492  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
493  $ilCtrl->redirect($this, "defaults");
494  }
495 
496 
502  public function getTabs(&$tabs_gui)
503  {
504  global $rbacsystem;
505 
506  switch ($this->ctrl->getCmd())
507  {
508  case "logs":
509  case "showLog":
510  case "exportLog":
511  case "logAdmin":
512  case "deleteLog":
513  $this->getLogdataSubtabs();
514  break;
515  }
516 
517  if ($rbacsystem->checkAccess("visible,read",$this->object->getRefId()))
518  {
519  $tabs_gui->addTarget("settings",
520  $this->ctrl->getLinkTarget($this, "settings"), array("settings","","view"), "", "");
521 
522  $tabs_gui->addTarget("logs",
523  $this->ctrl->getLinkTarget($this, "logs"),
524  array("logs","showLog", "exportLog", "logAdmin", "deleteLog"),
525  "", "");
526 
527  $tabs_gui->addTarget("defaults",
528  $this->ctrl->getLinkTarget($this, "defaults"), array("defaults","saveDefaults"), "", "");
529  }
530 
531  if ($rbacsystem->checkAccess('edit_permission',$this->object->getRefId()))
532  {
533  $tabs_gui->addTarget("perm_settings",
534  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"), array("perm","info","owner"), 'ilpermissiongui');
535  }
536  }
537 } // END class.ilObjAssessmentFolderGUI
538 ?>