ILIAS  Release_4_0_x_branch Revision 61816
 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  // setup rolefolder & default local roles
97  //$roles = $newObj->initDefaultRoles();
98 
99  // ...finally assign role to creator of object
100  //$rbacadmin->assignUser($roles[0], $newObj->getOwner(), "y");
101 
102  // put here object specific stuff
103 
104  // always send a message
105  ilUtil::sendSuccess($this->lng->txt("object_added"),true);
106 
107  $this->ctrl->redirect($this);
108  }
109 
110 
114  public function settingsObject()
115  {
116  global $ilAccess;
117 
118  include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
119  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
120  $form = new ilPropertyFormGUI();
121  $form->setFormAction($this->ctrl->getFormAction($this));
122  $form->setTableWidth("100%");
123  $form->setId("settings");
124 
125  // general properties
126  $header = new ilFormSectionHeaderGUI();
127  $header->setTitle($this->lng->txt("assessment_log_logging"));
128  $form->addItem($header);
129 
130  // assessment logging
131  $logging = new ilCheckboxInputGUI('', "chb_assessment_logging");
132  $logging->setValue(1);
133  $logging->setChecked($this->object->_enabledAssessmentLogging());
134  $logging->setOptionTitle($this->lng->txt("activate_assessment_logging"));
135  $form->addItem($logging);
136 
137  // reporting language
138  $reporting = new ilSelectInputGUI($this->lng->txt('assessment_settings_reporting_language'), "reporting_language");
139  $languages = $this->lng->getInstalledLanguages();
140  $options = array();
141  foreach ($languages as $lang)
142  {
143  $options[$lang] = $this->lng->txt("lang_" . $lang);
144  }
145  $reporting->setOptions($options);
146  $reporting->setValue($this->object->_getLogLanguage());
147  $form->addItem($reporting);
148 
149  // question settings
150  $header = new ilFormSectionHeaderGUI();
151  $header->setTitle($this->lng->txt("assf_questiontypes"));
152  $form->addItem($header);
153 
154  // available question types
155  $allowed = new ilCheckboxGroupInputGUI($this->lng->txt('assf_allowed_questiontypes'), "chb_allowed_questiontypes");
156  $questiontypes =& ilObjQuestionPool::_getQuestionTypes(TRUE);
157  $forbidden_types = $this->object->_getForbiddenQuestionTypes();
158  $allowedtypes = array();
159  foreach ($questiontypes as $qt)
160  {
161  if (!in_array($qt['question_type_id'], $forbidden_types)) array_push($allowedtypes, $qt['question_type_id']);
162  }
163  $allowed->setValue($allowedtypes);
164  foreach ($questiontypes as $type_name => $qtype)
165  {
166  $allowed->addOption(new ilCheckboxOption($type_name, $qtype["question_type_id"]));
167  }
168  $allowed->setInfo($this->lng->txt('assf_allowed_questiontypes_desc'));
169  $form->addItem($allowed);
170 
171  // manual scoring
172  $manual = new ilCheckboxGroupInputGUI($this->lng->txt('assessment_log_manual_scoring_activate'), "chb_manual_scoring");
173  $manscoring = $this->object->_getManualScoring();
174  $manual->setValue($manscoring);
175  foreach ($questiontypes as $type_name => $qtype)
176  {
177  $manual->addOption(new ilCheckboxOption($type_name, $qtype["question_type_id"]));
178  }
179  $manual->setInfo($this->lng->txt('assessment_log_manual_scoring_desc'));
180  $form->addItem($manual);
181 
182  if ($ilAccess->checkAccess("write", "", $this->object->getRefId()))
183  {
184  $form->addCommandButton("saveSettings", $this->lng->txt("save"));
185  }
186  $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
187  }
188 
192  public function saveSettingsObject()
193  {
194  global $ilAccess;
195  if (!$ilAccess->checkAccess("write", "", $this->object->getRefId())) $this->ctrl->redirect($this,'settings');
196 
197  if ($_POST["chb_assessment_logging"] == 1)
198  {
199  $this->object->_enableAssessmentLogging(1);
200  }
201  else
202  {
203  $this->object->_enableAssessmentLogging(0);
204  }
205  $this->object->_setLogLanguage($_POST["reporting_language"]);
206  $this->object->_setManualScoring($_POST["chb_manual_scoring"]);
207  include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
208  $questiontypes =& ilObjQuestionPool::_getQuestionTypes(TRUE);
209  $forbidden_types = array();
210  foreach ($questiontypes as $name => $row)
211  {
212  if (!in_array($row["question_type_id"], $_POST["chb_allowed_questiontypes"]))
213  {
214  array_push($forbidden_types, $row["question_type_id"]);
215  }
216  }
217  $this->object->_setForbiddenQuestionTypes($forbidden_types);
218  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"),true);
219 
220  $this->ctrl->redirect($this,'settings');
221  }
222 
226  public function showLogObject()
227  {
228  $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']);
229  $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']);
230  $test = $_POST['sel_test'];
231  $this->logsObject($from, $until, $test);
232  }
233 
237  public function exportLogObject()
238  {
239  $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']);
240  $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']);
241  $test = $_POST['sel_test'];
242 
243  $csv = array();
244  $separator = ";";
245  $row = array(
246  $this->lng->txt("assessment_log_datetime"),
247  $this->lng->txt("user"),
248  $this->lng->txt("assessment_log_text"),
249  $this->lng->txt("question")
250  );
251  include_once "./Modules/Test/classes/class.ilObjTest.php";
252  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
253  $available_tests =& ilObjTest::_getAvailableTests(1);
254  array_push($csv, ilUtil::processCSVRow($row, TRUE, $separator));
255  $log_output =& $this->object->getLog($from, $until, $test);
256  $users = array();
257  foreach ($log_output as $key => $log)
258  {
259  if (!array_key_exists($log["user_fi"], $users))
260  {
261  $users[$log["user_fi"]] = ilObjUser::_lookupName($log["user_fi"]);
262  }
263  $title = "";
264  if ($log["question_fi"] || $log["original_fi"])
265  {
266  $title = assQuestion::_getQuestionTitle($log["question_fi"]);
267  if (strlen($title) == 0)
268  {
269  $title = assQuestion::_getQuestionTitle($log["original_fi"]);
270  }
271  $title = $this->lng->txt("assessment_log_question") . ": " . $title;
272  }
273  $csvrow = array();
274  $date = new ilDateTime($log['tstamp'],IL_CAL_UNIX);
275  array_push($csvrow, $date->get(IL_CAL_FKT_DATE,'Y-m-d H:i'));
276  array_push($csvrow, trim($users[$log["user_fi"]]["title"] . " " . $users[$log["user_fi"]]["firstname"] . " " . $users[$log["user_fi"]]["lastname"]));
277  array_push($csvrow, trim($log["logtext"]));
278  array_push($csvrow, $title);
279  array_push($csv, ilUtil::processCSVRow($csvrow, TRUE, $separator));
280  }
281  $csvoutput = "";
282  foreach ($csv as $row)
283  {
284  $csvoutput .= join($row, $separator) . "\n";
285  }
286  ilUtil::deliverData($csvoutput, str_replace(" ", "_", "log_" . $from . "_" . $until . "_" . $available_tests[$test]).".csv");
287  }
288 
292  public function logsObject($p_from = null, $p_until = null, $p_test = null)
293  {
294  $template = new ilTemplate("tpl.assessment_logs.html", TRUE, TRUE, "Modules/Test");
295 
296  include_once "./Modules/Test/classes/class.ilObjTest.php";
297  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
298  $available_tests =& ilObjTest::_getAvailableTests(1);
299  if (count($available_tests) == 0)
300  {
301  ilUtil::sendInfo($this->lng->txt('assessment_log_no_data'));
302  return;
303  }
304 
305  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
306  $form = new ilPropertyFormGUI();
307  $form->setFormAction($this->ctrl->getFormAction($this));
308  $form->setTableWidth("100%");
309  $form->setId("logs");
310 
311  $header = new ilFormSectionHeaderGUI();
312  $header->setTitle($this->lng->txt("assessment_log"));
313  $form->addItem($header);
314 
315  // from
316  $from = new ilDateTimeInputGUI($this->lng->txt('cal_from'), "log_from");
317  $from->setShowDate(true);
318  $from->setShowTime(true);
319  $now = getdate();
320  $fromdate = ($p_from) ? $p_from : (($_GET['log_from']) ? $_GET['log_from'] : mktime(0, 0, 0, 1, 1, $now['year']));
321  $from->setDate(new ilDateTime($fromdate, IL_CAL_UNIX));
322  $form->addItem($from);
323 
324  // until
325  $until = new ilDateTimeInputGUI($this->lng->txt('cal_until'), "log_until");
326  $until->setShowDate(true);
327  $until->setShowTime(true);
328  $untildate = ($p_until) ? $p_until : (($_GET['log_until']) ? $_GET['log_until'] : time());
329  $until->setDate(new ilDateTime($untildate, IL_CAL_UNIX));
330  $form->addItem($until);
331 
332  // tests
333  $fortest = new ilSelectInputGUI($this->lng->txt('assessment_log_for_test'), "sel_test");
334  $options = array();
335  foreach ($available_tests as $key => $value)
336  {
337  $options[$key] = ilUtil::prepareFormOutput($value) . " [" . $this->object->getNrOfLogEntries($key) . " " . $this->lng->txt("assessment_log_log_entries") . "]";
338  }
339  $fortest->setOptions($options);
340  $p_test = ($p_test) ? $p_test : $_GET['sel_test'];
341  if ($p_test) $fortest->setValue($p_test);
342  $form->addItem($fortest);
343  $this->ctrl->setParameter($this, 'sel_test', $p_test);
344  $this->ctrl->setParameter($this, 'log_until', $untildate);
345  $this->ctrl->setParameter($this, 'log_from', $fromdate);
346  $form->addCommandButton("showLog", $this->lng->txt("show"));
347  $form->addCommandButton("exportLog", $this->lng->txt("export"));
348  $template->setVariable("FORM", $form->getHTML());
349 
350  if ($p_test)
351  {
352  include_once "./Modules/Test/classes/tables/class.ilAssessmentFolderLogTableGUI.php";
353  $table_gui = new ilAssessmentFolderLogTableGUI($this, 'logs');
354  $log_output =& $this->object->getLog($fromdate, $untildate, $p_test);
355  $table_gui->setData($log_output);
356  $template->setVariable('LOG', $table_gui->getHTML());
357  }
358  $this->tpl->setVariable("ADM_CONTENT", $template->get());
359  }
360 
364  public function deleteLogObject()
365  {
366  if (is_array($_POST["chb_test"]) && (count($_POST["chb_test"])))
367  {
368  $this->object->deleteLogEntries($_POST["chb_test"]);
369  ilUtil::sendSuccess($this->lng->txt("ass_log_deleted"));
370  }
371  else
372  {
373  ilUtil::sendInfo($this->lng->txt("ass_log_delete_no_selection"));
374  }
375  $this->logAdminObject();
376  }
377 
381  public function logAdminObject()
382  {
383  global $ilAccess;
384  $a_write_access = ($ilAccess->checkAccess("write", "", $this->object->getRefId())) ? true : false;
385 
386  include_once "./Modules/Test/classes/tables/class.ilAssessmentFolderLogAdministrationTableGUI.php";
387  $table_gui = new ilAssessmentFolderLogAdministrationTableGUI($this, 'logAdmin', $a_write_access);
388  include_once "./Modules/Test/classes/class.ilObjTest.php";
389  $available_tests =& ilObjTest::_getAvailableTests(true);
390  $data = array();
391  foreach ($available_tests as $obj_id => $title)
392  {
393  $nr = $this->object->getNrOfLogEntries($obj_id);
394  array_push($data, array("title" => $title, "nr" => $nr, "id" => $obj_id));
395  }
396  $table_gui->setData($data);
397  $this->tpl->setVariable('ADM_CONTENT', $table_gui->getHTML());
398  }
399 
400  public function getAdminTabs(&$tabs_gui)
401  {
402  $this->getTabs($tabs_gui);
403  }
404 
405  public function getLogdataSubtabs()
406  {
407  global $ilTabs;
408 
409  // log output
410  $ilTabs->addSubTabTarget("ass_log_output",
411  $this->ctrl->getLinkTarget($this, "logs"),
412  array("logs", "showLog", "exportLog")
413  , "");
414 
415  // log administration
416  $ilTabs->addSubTabTarget("ass_log_admin",
417  $this->ctrl->getLinkTarget($this, "logAdmin"),
418  array("logAdmin", "deleteLog"),
419  "", "");
420 
421  }
422 
426  public function defaultsObject()
427  {
428  global $ilAccess, $rbacreview, $lng, $ilCtrl, $tpl;
429 
430  $assessmentSetting = new ilSetting("assessment");
431  $use_javascript = array_key_exists("use_javascript", $_GET) ? $_GET["use_javascript"] : $assessmentSetting->get("use_javascript");
432  $imap_line_color = array_key_exists("imap_line_color", $_GET) ? $_GET["imap_line_color"] : $assessmentSetting->get("imap_line_color");
433  if (strlen($imap_line_color) == 0) $imap_line_color = "FF0000";
434 
435  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
436  $form = new ilPropertyFormGUI();
437  $form->setFormAction($ilCtrl->getFormAction($this));
438  $form->setTitle($lng->txt("assessment_defaults"));
439 
440  // Enable javascript
441  $enable = new ilCheckboxInputGUI($lng->txt("assessment_use_javascript"), "use_javascript");
442  $enable->setChecked($use_javascript);
443  $enable->setInfo($lng->txt("assessment_use_javascript_desc"));
444  $form->addItem($enable);
445 
446  $linepicker = new ilColorPickerInputGUI($lng->txt("assessment_imap_line_color"), "imap_line_color");
447  $linepicker->setValue($imap_line_color);
448  $form->addItem($linepicker);
449 
450  if ($ilAccess->checkAccess("write", "", $this->object->getRefId()))
451  {
452  $form->addCommandButton("saveDefaults", $lng->txt("save"));
453  }
454 
455 
456  $tpl->setVariable("ADM_CONTENT", $form->getHTML());
457  }
458 
462  public function saveDefaultsObject()
463  {
464  global $ilCtrl;
465 
466  $assessmentSetting = new ilSetting("assessment");
467  if ($_POST["use_javascript"])
468  {
469  $assessmentSetting->set("use_javascript", "1");
470  }
471  else
472  {
473  $assessmentSetting->set("use_javascript", "0");
474  }
475  if (strlen($_POST["imap_line_color"]) == 6)
476  {
477  $assessmentSetting->set("imap_line_color", $_POST["imap_line_color"]);
478  }
479  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
480  $ilCtrl->redirect($this, "defaults");
481  }
482 
483 
489  public function getTabs(&$tabs_gui)
490  {
491  global $rbacsystem;
492 
493  switch ($this->ctrl->getCmd())
494  {
495  case "logs":
496  case "showLog":
497  case "exportLog":
498  case "logAdmin":
499  case "deleteLog":
500  $this->getLogdataSubtabs();
501  break;
502  }
503 
504  if ($rbacsystem->checkAccess("visible,read",$this->object->getRefId()))
505  {
506  $tabs_gui->addTarget("settings",
507  $this->ctrl->getLinkTarget($this, "settings"), array("settings","","view"), "", "");
508 
509  $tabs_gui->addTarget("logs",
510  $this->ctrl->getLinkTarget($this, "logs"),
511  array("logs","showLog", "exportLog", "logAdmin", "deleteLog"),
512  "", "");
513 
514  $tabs_gui->addTarget("defaults",
515  $this->ctrl->getLinkTarget($this, "defaults"), array("defaults","saveDefaults"), "", "");
516  }
517 
518  if ($rbacsystem->checkAccess('edit_permission',$this->object->getRefId()))
519  {
520  $tabs_gui->addTarget("perm_settings",
521  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"), array("perm","info","owner"), 'ilpermissiongui');
522  }
523  }
524 } // END class.ilObjAssessmentFolderGUI
525 ?>