ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjUserTrackingGUI.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 include_once "classes/class.ilObjectGUI.php";
5 
21 {
27 
28  var $tpl = null;
29  var $ilErr = null;
30  var $lng = null;
31  var $ctrl = null;
32 
33  function ilObjUserTrackingGUI($a_data,$a_id,$a_call_by_reference)
34  {
35  global $tpl,$ilErr,$lng,$ilCtrl;
36 
37  $this->type = "trac";
38  $this->ilObjectGUI($a_data,$a_id,$a_call_by_reference, false);
39 
40  $this->tpl =& $tpl;
41  $this->ilErr =& $ilErr;
42  $this->lng =& $lng;
43  $this->lng->loadLanguageModule('trac');
44 
45  $this->ctrl =& $ilCtrl;
46  }
47 
48  function &executeCommand()
49  {
50  $next_class = $this->ctrl->getNextClass();
51  $this->ctrl->setReturn($this, "show");
52  $this->prepareOutput();
53 
54  switch($next_class)
55  {
56  case 'ilpermissiongui':
57  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
58  $perm_gui =& new ilPermissionGUI($this);
59  $ret =& $this->ctrl->forwardCommand($perm_gui);
60  break;
61 
62  case 'illearningprogressgui':
63  $this->tabs_gui->setTabActive('learning_progress');
64  include_once("./Services/Tracking/classes/class.ilLearningProgressGUI.php");
66  $ret =& $this->ctrl->forwardCommand($lp_gui);
67  break;
68 
69  case 'illpobjectstatisticsgui':
70  $this->tabs_gui->setTabActive('statistics');
71  include_once("./Services/Tracking/classes/class.ilLPObjectStatisticsGUI.php");
73  $ret =& $this->ctrl->forwardCommand($os_gui);
74  break;
75 
76  default:
77  $cmd = $this->ctrl->getCmd();
78  if ($cmd == "view" || $cmd == "")
79  {
80  $cmd = "settings";
81  }
82  $cmd .= "Object";
83  $this->$cmd();
84  break;
85  }
86 
87  return true;
88  }
89 
90  function getAdminTabs(&$tabs_gui)
91  {
92  $this->getTabs($tabs_gui);
93  }
94 
95  function getTabs(&$tabs_gui)
96  {
97  global $rbacsystem;
98 
99  $this->ctrl->setParameter($this,"ref_id",$this->ref_id);
100 
101  if ($rbacsystem->checkAccess("visible,read",$this->object->getRefId()))
102  {
103  $tabs_gui->addTarget("settings",
104  $this->ctrl->getLinkTarget($this,
105  "settings"),
106  "settings",
107  get_class($this));
108 
110  {
111  $tabs_gui->addTarget("statistics",
112  $this->ctrl->getLinkTargetByClass("illpobjectstatisticsgui",
113  "access"),
114  "",
115  "illpobjectstatisticsgui");
116  }
117 
119  {
120  $tabs_gui->addTarget("learning_progress",
121  $this->ctrl->getLinkTargetByClass("illearningprogressgui",
122  "show"),
123  "",
124  "illearningprogressgui");
125  }
126 
127  /*
128  $tabs_gui->addTarget("tracking_data",
129  $this->ctrl->getLinkTarget($this,
130  "trackingDataQueryForm"),
131  "trackingDataQueryForm",
132  get_class($this));
133 
134 
135  $tabs_gui->addTarget("manage_tracking_data",
136  $this->ctrl->getLinkTarget($this,
137  "manageData"),
138  "manageData",
139  get_class($this));
140  */
141 
142  $tabs_gui->addTarget("perm_settings",
143  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"),
144  array("perm","info","owner"),
145  'ilpermissiongui');
146  }
147  }
148 
149 
153  function settingsObject()
154  {
155  global $rbacsystem;
156 
157  if (!$rbacsystem->checkAccess('read',$this->object->getRefId()))
158  {
159  $ilErr->raiseError($this->lng->txt("msg_no_perm_read_track"),$ilErr->WARNING);
160  }
161 
162  $this->tabs_gui->setTabActive('settings');
163 
164  include_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
165  $form = new ilPropertyFormGUI();
166  $form->setFormAction($this->ctrl->getFormAction($this));
167  $form->setTitle($this->lng->txt('tracking_settings'));
168 
169  $activate = new ilCheckboxGroupInputGUI($this->lng->txt('activate_tracking'));
170  $form->addItem($activate);
171 
172  $lp = new ilCheckboxInputGUI($this->lng->txt('trac_learning_progress'), 'learning_progress_tracking');
173  $lp->setInfo($this->lng->txt('trac_learning_progress_settings_info'));
174  $activate->addSubItem($lp);
175 
176  /*
177  $tracking = new ilCheckboxInputGUI($this->lng->txt('trac_user_activities'), 'user_tracking');
178  $activate->addSubItem($tracking);
179  */
180 
181  $event = new ilCheckboxInputGUI($this->lng->txt('trac_repository_changes'), 'change_event_tracking');
182  $activate->addSubItem($event);
183 
184  $objstat = new ilCheckboxInputGUI($this->lng->txt('trac_object_statistics'), 'object_statistics');
185  $activate->addSubItem($objstat);
186 
187  /*
188  if($this->object->getActivationStatus() == UT_ACTIVE_BOTH ||
189  $this->object->getActivationStatus() == UT_ACTIVE_UT)
190  {
191  $tracking->setChecked(true);
192  }
193  */
194 
195  if($this->object->getActivationStatus() == UT_ACTIVE_BOTH ||
196  $this->object->getActivationStatus() == UT_ACTIVE_LP)
197  {
198  $lp->setChecked(true);
199  }
200 
201  if($this->object->isChangeEventTrackingEnabled())
202  {
203  $event->setChecked(true);
204  }
205 
206  if($this->object->isObjectStatisticsEnabled())
207  {
208  $objstat->setChecked(true);
209  }
210 
211  $access = new ilCheckboxInputGUI($this->lng->txt('trac_first_and_last_access'), 'lp_access');
212  if($this->object->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_LAST_ACCESS))
213  {
214  $access->setChecked(true);
215  }
216  $lp->addSubItem($access);
217 
218  $read = new ilCheckboxInputGUI($this->lng->txt('trac_read_count'), 'lp_count');
219  if($this->object->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_READ_COUNT))
220  {
221  $read->setChecked(true);
222  }
223  $lp->addSubItem($read);
224 
225  $spent = new ilCheckboxInputGUI($this->lng->txt('trac_spent_seconds'), 'lp_spent');
226  if($this->object->hasExtendedData(ilObjUserTracking::EXTENDED_DATA_SPENT_SECONDS))
227  {
228  $spent->setChecked(true);
229  }
230  $lp->addSubItem($spent);
231 
232  // Anonymized
233  $user = new ilCheckboxInputGUI($this->lng->txt('trac_anonymized'), 'user_related');
234  $user->setInfo($this->lng->txt('trac_anonymized_info'));
235  $user->setChecked(!$this->object->_enabledUserRelatedData());
236  $form->addItem($user);
237 
238  // Max time gap
239  $valid = new ilNumberInputGUI($this->lng->txt('trac_valid_request'), 'valid_request');
240  $valid->setMaxLength(4);
241  $valid->setSize(4);
242  $valid->setSuffix($this->lng->txt('seconds'));
243  $valid->setInfo($this->lng->txt('info_valid_request'));
244  $valid->setValue($this->object->getValidTimeSpan());
245  $form->addItem($valid);
246 
247  $form->addCommandButton('saveSettings', $this->lng->txt('save'));
248 
249  $this->tpl->setContent($form->getHTML());
250  }
251 
256  {
257  // BEGIN ChangeEvent
258  if ($_POST['user_tracking'] == '1')
259  {
260  $activation_status = ($_POST['learning_progress_tracking'] == '1') ? UT_ACTIVE_BOTH : UT_ACTIVE_UT;
261  }
262  else
263  {
264  $activation_status = ($_POST['learning_progress_tracking'] == '1') ? UT_ACTIVE_LP : UT_INACTIVE_BOTH;
265  }
266  $this->object->setActivationStatus($activation_status);
267  $this->object->setChangeEventTrackingEnabled($_POST['change_event_tracking'] == '1');
268  // END ChangeEvent
269 
270  if($_POST['learning_progress_tracking'] == '1')
271  {
272  $code = 0;
273  if($_POST['lp_access'] == '1')
274  {
276  }
277  if($_POST['lp_count'] == '1')
278  {
280  }
281  if($_POST['lp_spent'] == '1')
282  {
284  }
285  $this->object->setExtendedData($code);
286  }
287 
288  $this->object->setObjectStatisticsEnabled((bool)$_POST["object_statistics"]);
289  $this->object->enableUserRelatedData((int) !$_POST['user_related']);
290  $this->object->setValidTimeSpan($_POST['valid_request']);
291 
292  if(!$this->object->validateSettings())
293  {
294  ilUtil::sendFailure($this->lng->txt('tracking_time_span_not_valid'));
295  $this->settingsObject();
296 
297  return false;
298  }
299 
300  $this->object->updateSettings();
301  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
302  $this->ctrl->redirect($this, "settings");
303 
304  return true;
305  }
306 
310  function manageDataObject()
311  {
312  global $tpl,$lng,$ilias;
313 
314  // tracking settings
315  $tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.tracking_manage_data.html");
316  $tpl->setVariable("FORMACTION",$this->ctrl->getFormaction($this,'gateway'));
317  $tpl->setVariable("TXT_TRACKING_DATA", $this->lng->txt("tracking_data"));
318  $tpl->setVariable("TXT_MONTH", $lng->txt("month"));
319  $tpl->setVariable("TXT_NUMBER_OF_ACC", $lng->txt("number_of_accesses"));
320  $tpl->setVariable("TXT_DELETE_OLDER", $lng->txt("delete"));
321  $overw = $this->object->getMonthTotalOverview();
322  foreach($overw as $month)
323  {
324  $tpl->setCurrentBlock("load_row");
325  $rcol = ($rcol != "tblrow1") ? "tblrow1" : "tblrow2";
326  $tpl->setVariable("ROWCOL", $rcol);
327  $tpl->setVariable("VAL_MONTH", $month["month"]);
328  $tpl->setVariable("VAL_NUMBER_OF_ACC", $month["cnt"]);
329  $tpl->parseCurrentBlock();
330  }
331 // $tpl->parseCurrentBlock();
332  }
333 
338  {
339  global $tpl, $lng, $rbacsystem;
340 
341  if (!$rbacsystem->checkAccess('delete',$this->object->getRefId()))
342  {
343  $this->ilias->raiseError($this->lng->txt("msg_no_perm_delete_track"),$this->ilias->error_obj->WARNING);
344  }
345 
346  if (!isset($_POST["month"]))
347  {
348  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
349  }
350  $nr = $this->object->getTotalOlderThanMonth($_POST["month"]);
351  $tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.tracking_confirm_data_deletion.html");
352  #$tpl->setVariable("FORMACTION", "adm_object.php?ref_id=".$_GET["ref_id"].
353  # "&cmd=gateway&month=".$_POST["month"]);
354  $this->ctrl->setParameter($this,'month',$_POST['month']);
355  $tpl->setVariable("FORMACTION",$this->ctrl->getFormaction($this,'gateway'));
356 
357  $tpl->setVariable("TXT_CONFIRMATION", $this->lng->txt("tracking_data_del_confirm"));
358  $tpl->setVariable("TXT_MONTH", $lng->txt("month"));
359  $tpl->setVariable("VAL_MONTH", $_POST["month"]);
360  $tpl->setVariable("TXT_NUMBER_OF_RECORDS", $lng->txt("number_of_records"));
361  $tpl->setVariable("VAL_NUMBER_OF_RECORDS", $nr);
362  $tpl->setVariable("TXT_NUMBER_OF_ACC", $lng->txt("number_of_accesses"));
363  $tpl->setVariable("TXT_DELETE_DATA", $lng->txt("delete_tr_data"));
364  $tpl->setVariable("TXT_CANCEL", $lng->txt("cancel"));
365  }
366 
371  {
372  $this->ctrl->redirect($this,'manageData');
373  }
374 
378  function deleteDataObject()
379  {
380  global $rbacsystem;
381 
382  if (!$rbacsystem->checkAccess('read',$this->object->getRefId()))
383  {
384  $this->ilias->raiseError($this->lng->txt("msg_no_perm_delete_track"),$this->ilias->error_obj->WARNING);
385  }
386 
387  $this->object->deleteTrackingDataBeforeMonth($_GET["month"]);
388 
389  ilUtil::sendInfo($this->lng->txt("tracking_data_deleted"),true);
390  $this->ctrl->redirect($this,'manageData');
391 
392  #ilUtil::redirect("adm_object.php?ref_id=".$_GET["ref_id"]."&cmd=manageData");
393  }
394 
399  {
400  global $tpl;
401  $tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.usr_tracking.html");
402  $tpl->setVariable("FORM", $this->showForm());
403  }
404 
405  function showForm()
406  {
407  global $lng,$ilias;
408  for ($i = 2004; $i <= date("Y"); $i++) $year[] = $i;
409  $month = array(1,2,3,4,5,6,7,8,9,10,11,12);
410  $day = array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31);
411  //subject module
412  $tpl = new ilTemplate("tpl.tracking_form.html", true, true);
413 
414  // Tabs gui
415  $this->tabs_gui->setTabActive('tracking_data');
416 
418  {
419  $tpl->setCurrentBlock("user_stat");
420  $tpl->setVariable("TXT_VIEW_MODE_U", $lng->txt("vm_access_of_users"));
421  if ($_SESSION["il_track_stat"] == "u")
422  {
423  $tpl->setVariable("U_SEL", "selected");
424  }
425  $tpl->parseCurrentBlock();
426  }
427 
428  //$tpl->addBlockFile("STATUSLINE", "statusline", "tpl.statusline.html");
429  #$tpl->setVariable("SEARCH_ACTION", "adm_object.php?ref_id=".$_GET["ref_id"].
430  # "&cmd=gateway");
431 
432  $tpl->setVariable("SEARCH_ACTION",$this->ctrl->getFormaction($this,'gateway'));
433  $tpl->setVariable("TXT_TRACKING_DATA", $lng->txt("tracking_data"));
434  $tpl->setVariable("TXT_SEARCH_TERMS", $lng->txt("search_terms"));
435  $tpl->setVariable("VAL_SEARCH_TERMS", ilUtil::prepareFormOutput($_SESSION["il_track_search_terms"], true));
436  $tpl->setVariable("TXT_TIME_SEGMENT", $lng->txt("time_segment"));
437  $tpl->setVariable("TXT_VIEW_MODE", $lng->txt("view_mode"));
438  $tpl->setVariable("TXT_VIEW_MODE_H", $lng->txt("vm_times_of_day"));
439  $tpl->setVariable("TXT_VIEW_MODE_D", $lng->txt("vm_days_of_period"));
440  $tpl->setVariable("TXT_USER_LANGUAGE",$lng->txt("user_language"));
441  $tpl->setVariable("TXT_LM",$lng->txt("lm"));
442  $tpl->setVariable("TXT_HTLM",$lng->txt("htlm"));
443 # $tpl->setVariable("TXT_TST",$lng->txt("test"));
444  $tpl->setVariable("TXT_SHOW_TR_DATA",$lng->txt("query_data"));
445  $tpl->setVariable("TXT_TRACKED_OBJECTS",$lng->txt("tracked_objects"));
446  $tpl->setVariable("TXT_FILTER_AREA",$lng->txt("trac_filter_area"));
447  $tpl->setVariable("TXT_CHANGE",$lng->txt("change"));
448 
449  $languages = $lng->getInstalledLanguages();
450 
451  // get all learning modules
452  // $lms = ilObject::_getObjectsDataForType("lm", true);
453 /* $authors = ilObjUserTracking::allAuthor("usr","lm");
454  if(count($authors)>0)
455  {
456  $tpl->setCurrentBlock("javascript");
457  $tpl->setVariable("ALL_LMS", $this->lng->txt("all_lms"));
458  foreach ($authors as $author)
459  {
460  $lms = ilObjUserTracking::authorLms($author["obj_id"],"lm");
461  //echo count($lms);
462  foreach ($lms as $lm)
463  {
464  $tpl->setCurrentBlock("select_value");
465  $tpl->setVariable("VALUE", $author["title"]);
466  $tpl->setVariable("LMVALUE", $lm["title"]);
467  $tpl->parseCurrentBlock();
468  }
469 
470  }
471  $tpl->parseCurrentBlock();
472  }
473  $authors1 = ilObjUserTracking::allAuthor("usr","tst");
474  if(count($authors1)>0)
475  {
476  $tpl->setCurrentBlock("javascript1");
477  $tpl->setVariable("ALL_TSTS", $this->lng->txt("all_tsts"));
478  foreach ($authors1 as $author1)
479  {
480  $tsts = ilObjUserTracking::authorLms($author1["obj_id"],"tst");
481  foreach ($tsts as $tst)
482  {
483  $tpl->setCurrentBlock("select_value1");
484  $tpl->setVariable("VALUE1", $author1["title"]);
485  $tpl->setVariable("TSTVALUE", $tst["title"]);
486  $tpl->parseCurrentBlock();
487  }
488  }
489  $tpl->parseCurrentBlock();
490  }*/
491 
492  if ($_SESSION["il_track_yearf"] == "") $_SESSION["il_track_yearf"] = date("Y");
493 
494  if ($_SESSION["il_track_yeart"] == "") $_SESSION["il_track_yeart"] = date("Y");
495  if ($_SESSION["il_track_montht"] == "") $_SESSION["il_track_montht"] = date("m");
496  if ($_SESSION["il_track_dayt"] == "") $_SESSION["il_track_dayt"] = date("d");
497 
498  foreach($year as $key)
499  {
500  $tpl->setCurrentBlock("fromyear_selection");
501  $tpl->setVariable("YEARFR", $key);
502  $tpl->setVariable("YEARF", $key);
503  if ($_SESSION["il_track_yearf"] == $key)
504  {
505  $tpl->setVariable("YEARF_SEL", " selected=\"1\" ");
506  }
507  $tpl->parseCurrentBlock();
508  }
509  foreach($month as $key)
510  {
511  $tpl->setCurrentBlock("frommonth_selection");
512  $tpl->setVariable("MONTHFR", $key);
513  $tpl->setVariable("MONTHF", $key);
514  if ($_SESSION["il_track_monthf"] == $key)
515  {
516  $tpl->setVariable("MONTHF_SEL", " selected=\"1\" ");
517  }
518  $tpl->parseCurrentBlock();
519  }
520  foreach($day as $key)
521  {
522  $tpl->setCurrentBlock("fromday_selection");
523  $tpl->setVariable("DAYFR", $key);
524  $tpl->setVariable("DAYF", $key);
525  if ($_SESSION["il_track_dayf"] == $key)
526  {
527  $tpl->setVariable("DAYF_SEL", " selected=\"1\" ");
528  }
529  $tpl->parseCurrentBlock();
530  }
531  foreach($day as $key)
532  {
533  $tpl->setCurrentBlock("today_selection");
534  $tpl->setVariable("DAYTO", $key);
535  $tpl->setVariable("DAYT", $key);
536  if ($_SESSION["il_track_dayt"] == $key)
537  {
538  $tpl->setVariable("DAYT_SEL", " selected=\"1\" ");
539  }
540  $tpl->parseCurrentBlock();
541  }
542  foreach($month as $key)
543  {
544  $tpl->setCurrentBlock("tomonth_selection");
545  $tpl->setVariable("MONTHTO", $key);
546  $tpl->setVariable("MONTHT", $key);
547  if ($_SESSION["il_track_montht"] == $key)
548  {
549  $tpl->setVariable("MONTHT_SEL", " selected=\"1\" ");
550  }
551  $tpl->parseCurrentBlock();
552  }
553  foreach($year as $key)
554  {
555  $tpl->setCurrentBlock("toyear_selection");
556  $tpl->setVariable("YEARTO", $key);
557  $tpl->setVariable("YEART", $key);
558  if ($_SESSION["il_track_yeart"] == $key)
559  {
560  $tpl->setVariable("YEART_SEL", " selected=\"1\" ");
561  }
562  $tpl->parseCurrentBlock();
563  }
564  // language selection
565  $tpl->setCurrentBlock("language_selection");
566  $tpl->setVariable("LANG", $lng->txt("any_language"));
567  $tpl->setVariable("LANGSHORT", "0");
568  $tpl->parseCurrentBlock();
569  foreach ($languages as $lang_key)
570  {
571  $tpl->setCurrentBlock("language_selection");
572  $tpl->setVariable("LANG", $lng->txt("lang_".$lang_key));
573  $tpl->setVariable("LANGSHORT", $lang_key);
574  if ($_SESSION["il_track_language"] == $lang_key)
575  {
576  $tpl->setVariable("LANG_SEL", " selected=\"1\" ");
577  }
578  $tpl->parseCurrentBlock();
579  }
580 
581  // statistic type
582  if (!in_array($_SESSION["il_track_stat"], array("d", "h", "o", "u"))) $_SESSION["il_track_stat"] = "d";
583 
584  if ($_SESSION["il_track_stat"] == "d")
585  {
586  $tpl->setVariable("D_SEL", "selected");
587  }
588  elseif ($_SESSION["il_track_stat"] == "h")
589  {
590  $tpl->setVariable("H_SEL", "selected");
591  }
592 
593  // tracked object type
594  $tpl->setVariable(strtoupper($_SESSION["il_object_type"])."_SEL", "selected");
595 
596  // author selection
597 /* $tpl->setCurrentBlock("author_selection");
598  $tpl->setVariable("AUTHOR", 0);
599  $tpl->setVariable("AUTHOR_SELECT", $this->lng->txt("all_authors"));
600  $tpl->parseCurrentBlock();
601  foreach ($authors as $author)
602  {
603  $tpl->setCurrentBlock("author_selection");
604  $tpl->setVariable("AUTHOR", $author["title"]);
605  $tpl->setVariable("AUTHOR_SELECT", $author["title"]);
606  if ($_SESSION["il_track_author"] == $author["title"])
607  {
608  $tpl->setVariable("AUTHOR_SEL", " selected=\"1\" ");
609  }
610  $tpl->parseCurrentBlock();
611  }
612  $tpl->setCurrentBlock("author_selection_tst");
613  $tpl->setVariable("AUTHOR1", 0);
614  $tpl->setVariable("AUTHOR1_SELECT", $this->lng->txt("all_authors"));
615  $tpl->parseCurrentBlock();
616  foreach ($authors1 as $author1)
617  {
618  $tpl->setCurrentBlock("author_selection_tst");
619  $tpl->setVariable("AUTHOR1", $author1["title"]);
620  $tpl->setVariable("AUTHOR1_SELECT", $author1["title"]);
621  if ($_SESSION["il_track_author1"] == $author1["title"])
622  {
623  $tpl->setVariable("AUTHOR1_SEL", " selected=\"1\" ");
624  }
625  $tpl->parseCurrentBlock();
626  }
627  //test module
628 
629  $result_test = ilObjUserTracking::getTestId($_SESSION["AccountId"]);
630 
631  //$test = $tracking->TestTitle($_SESSION["AccountId"]);
632 
633  $tsts = ilObject::_getObjectsDataForType($type, true);
634  $tpl->setCurrentBlock("test_selection");
635  $tpl->setVariable("TEST", 0);
636  $tpl->setVariable("TEST_SELECT", $this->lng->txt("all_tsts"));
637  $tpl->parseCurrentBlock();
638  foreach($tsts as $tst)
639  {
640  $tpl->setCurrentBlock("test_selection");
641  $tpl->setVariable("TEST", $tst["id"]);
642  $tpl->setVariable("TEST_SELECT", $tst["title"]." [".$tst["id"]."]");
643  $tpl->parseCurrentBlock();
644  }*/
645 
646  return $tpl->get();
647 
648  }
649 
654  {
655  global $tpl,$lng,$ilias,$ilSetting;
656 
657  $TYPES = array(
658  'lm' => $lng->txt("lm"),
659  'htlm' => $lng->txt("htlm"),
660  'tst' => $lng->txt("test")
661  );
662 
663  include_once "./Services/Table/classes/class.ilTableGUI.php";
664 
665  if(!in_array($_POST["stat"], array("d", "h", "o", "u")))
666  {
667  $_POST["stat"] = "d";
668  }
669  if ($_POST["author"] == "") $_POST["author"] = "0";
670  if ($_POST["author1"] == "") $_POST["author1"] = "0";
671 
672  // save selected values in session
673  $_SESSION["il_track_search_terms"] = ilUtil::stripSlashes($_POST["search_terms"]);
674  $_SESSION["il_track_yearf"] = $_POST["yearf"];
675  $_SESSION["il_track_yeart"] = $_POST["yeart"];
676  $_SESSION["il_track_monthf"] = $_POST["monthf"];
677  $_SESSION["il_track_montht"] = $_POST["montht"];
678  $_SESSION["il_track_dayf"] = $_POST["dayf"];
679  $_SESSION["il_track_dayt"] = $_POST["dayt"];
680  $_SESSION["il_track_stat"] = $_POST["stat"];
681  $_SESSION["il_track_language"] = $_POST["language"];
682  $_SESSION["il_track_author"] = $_POST["author"];
683  $_SESSION["il_track_author1"] = $_POST["author1"];
684  $_SESSION["il_track_lm"] = $_POST["lm"];
685  $_SESSION["il_track_htlm"] = $_POST["htlm"];
686  $_SESSION["il_track_tst"] = $_POST["tst"];
687  $_SESSION["il_object_type"] = $_POST["object_type"];
688 
689  $yearf = $_POST["yearf"];
690  $monthf = $_POST["monthf"];
691  $dayf = $_POST["dayf"];
692  $yeart = $_POST["yeart"];
693  $montht= $_POST["montht"];
694  $dayt = $_POST["dayt"];
695  $from = date("Y-m-d", mktime(12, 0, 0, $monthf, $dayf, $yearf));
696  $to = date("Y-m-d", mktime(12, 0, 0, $montht, $dayt, $yeart));
697 
698  if(($yearf > $yeart)or($yearf==$yeart and $monthf>$montht)or($yearf==$yeart and $monthf==$montht and $dayf>$dayt))
699  {
700  $this->ilias->raiseError($lng->txt("msg_err_search_time"),
701  $this->ilias->error_obj->MESSAGE);
702  }
703 
704  $condition = $this->getCondition()." and acc_time >= '".$from." 00:00:00' and acc_time <= '".$to." 23:59:59'";
705 
706  /*
707  if($_POST["stat"]!='h' and $_POST["stat"]!='d')
708  {
709  $this->ilias->raiseError($lng->txt("msg_no_search_time"),
710  $this->ilias->error_obj->MESSAGE);
711  }*/
712 
713  $tpl->addBlockfile("ADM_CONTENT", "adm_content", "tpl.tracking_result.html");
714  $tpl->addBlockFile("STATUSLINE", "statusline", "tpl.statusline.html");
715 
716  $tpl->setVariable("FORM", $this->showForm());
717 
718  $objectCondition = "";
719 
720  if (($max_acc_objects = $this->object->countResults($condition)) == 0)
721  {
722  $this->ilias->raiseError($lng->txt("msg_no_search_result"),
723  $this->ilias->error_obj->MESSAGE);
724  }
725 
726  $max_hits = $ilias->getSetting('search_max_hits', 50);
727 
728  if ($_POST["search_terms"] != "")
729  {
730  $tplTable =& new ilTemplate("tpl.table.html", true, true);
731  $tplTable->addBlockFile("TBL_CONTENT", "tbl_content", "tpl.obj_tbl_rows.html");
732 
733  $tbl = new ilTableGUI(0, false);
734  $tbl->setTemplate($tplTable);
735 
736  $searchTermsCondition = $this->getSearchTermsCondition();
737  $acc_object = $this->object->getAccessTotalPerObj($condition,$searchTermsCondition);
738 
739  $max_acc_objects = count($acc_object);
740 
741  if ($max_acc_objects < 1)
742  {
743  $this->ilias->raiseError($lng->txt("msg_no_search_result"),
744  $this->ilias->error_obj->MESSAGE);
745  }
746  else
747  {
748  $info = sprintf($lng->txt("info_found_objects"), $TYPES[$_POST["object_type"]]);
749 
750  if ($max_hits < $max_acc_objects)
751  {
752  $info .= " ".sprintf($lng->txt("found_too_much_objects"), $max_hits);
753  unset($tmp);
754  for ($i = 0; $i < count($acc_object) && $i < $max_hits; $i++)
755  {
756  $tmp[$i] = $acc_object[$i];
757  }
758  $acc_object = $tmp;
759  $max_acc_objects = $max_hits;
760  }
761 
762  $tpl->setVariable("INFO", $info);
763  }
764 
765  $tbl->setTitle($lng->txt("found_objects"),0,0);
766 # if(($_POST["object_type"]=="lm" and $_POST["author"] == "0") or ($_POST["object_type"]=="tst" and $_POST["author1"] == "0"))
767 # {
768  $title_new = array("author", "subject", "total_dwell_time", "count","");
769  $tbl->setColumnWidth(array("20%", "30%", "20%", "10%", "*"));
770 # }
771 # else
772 # {
773 # $title_new = array("subject", "count","");
774 # $tbl->setColumnWidth(array("30%", "10%", "*"));
775 # }
776  foreach ($title_new as $val)
777  {
778  $header_names[] = $lng->txt($val);
779  }
780  $tbl->disable("sort");
781  $tbl->setHeaderNames($header_names);
782  $tbl->setMaxCount($max_acc_objects);
783  # $tbl->setStyle("table", "std");
784 
785  $max = 0;
786  unset($ids);
787  for ($i = 0; $i < count($acc_object); $i++)
788  {
789  $max = ($max > $acc_object[$i]["cnt"]) ? $max : $acc_object[$i]["cnt"];
790  $ids[$i] = $acc_object[$i]["id"];
791  }
792  if (is_array($ids))
793  {
794  $objectCondition = " AND acc_obj_id IN (".implode(",", $ids).") ";
795  }
796 
797  for ($i = 0; $i < count($acc_object); $i++)
798  {
799  unset($data);
800 # if(($_POST["object_type"]=="lm" and $_POST["author"]=="0") or ($_POST["object_type"]=="tst" and $_POST["author1"]=="0"))
801 # {
802  $data[0] = $acc_object[$i]["author"];
803  $data[1] = $acc_object[$i]["title"];
804  $data[2] = ilFormat::_secondsToString($acc_object[$i]["duration"]);
805  $data[3] = $acc_object[$i]["cnt"];
806  $width = ($max > 0)
807  ? round($data[3] / $max * 100)
808  : 0;
809  $data[4] = "<img src=\"".ilUtil::getImagePath("ray.gif")."\" border=\"0\" ".
810  "width=\"".$width."\" height=\"10\"/>";
811 /* }
812  else
813  {
814  $data[0] = $obj["title"];
815  $data[1] = $obj["cnt"];
816  $width = ($max > 0)
817  ? round($data[1] / $max * 100)
818  : 0;
819  $data[2] = "<img src=\"".ilUtil::getImagePath("ray.gif")."\" border=\"0\" ".
820  "width=\"".$width."\" height=\"10\"/>";
821  }*/
822  $css_row = $i%2==0?"tblrow1":"tblrow2";
823  foreach ($data as $key => $val)
824  {
825  if($val=="")
826  {
827  $val=0;
828  }
829  $tplTable->setCurrentBlock("text");
830  $tplTable->setVariable("TEXT_CONTENT", $val);
831  $tplTable->parseCurrentBlock();
832  $tplTable->setCurrentBlock("table_cell");
833  $tplTable->parseCurrentBlock();
834  } //foreach
835  $tplTable->setCurrentBlock("tbl_content");
836  $tplTable->setVariable("CSS_ROW", $css_row);
837  $tplTable->parseCurrentBlock();
838  } //for
839 
840  $tbl->render();
841  $tpl->setVariable("OBJECTS_TABLE", $tplTable->get());
842  $tpl->setVariable("TXT_INFO_DWELL_TIME", $lng->txt("info_dwell_time"));
843  unset($tplTable);
844  unset($tbl);
845  }
846  else
847  {
848  $tpl->setVariable("INFO", sprintf($lng->txt("info_all_objects"), $TYPES[$_POST["object_type"]]));
849  }
850 
851  if ($max_acc_objects > 0)
852  {
853 
854  $tplTable =& new ilTemplate("tpl.table.html", true, true);
855  $tplTable->addBlockFile("TBL_CONTENT", "tbl_content", "tpl.obj_tbl_rows.html");
856 
857  $tbl = new ilTableGUI(0, false);
858  $tbl->setTemplate($tplTable);
859 
860  // user access statistic
861  if($_POST["stat"] == "u") // user access
862  {
863  if($_POST["mode"] == "user")
864  {
865  $tpl->setCurrentBlock("user_mode");
866  #$tpl->setVariable("FORMACTION", "adm_object.php?ref_id=".$_GET["ref_id"].
867  #"&cmd=gateway");
868  $tpl->setVariable("FORMACTION",$this->ctrl->getFormaction($this,'gateway'));
869  if($_POST["object_type"]=="lm")
870  {
871  $tpl->setVariable("AUTHOR", "author");
872  $tpl->setVariable("AUTHORS", $_POST["author"]);
873  $tpl->setVariable("OBJECT", "lm");
874  $tpl->setVariable("OBJECTS", $_POST["lm"]);
875  }
876  else if($_POST["object_type"]=="htlm")
877  {
878  $tpl->setVariable("AUTHOR", "author");
879  $tpl->setVariable("AUTHORS", $_POST["author"]);
880  $tpl->setVariable("OBJECT", "htlm");
881  $tpl->setVariable("OBJECTS", $_POST["htlm"]);
882  }
883  else
884  {
885  $tpl->setVariable("AUTHOR", "author1");
886  $tpl->setVariable("AUTHORS", $_POST["author1"]);
887  $tpl->setVariable("OBJECT", "tst");
888  $tpl->setVariable("OBJECTS", $_POST["tst"]);
889  }
890  $tpl->setVariable("YEARF",$_POST["yearf"]);
891  $tpl->setVariable("MONTHF",$_POST["monthf"]);
892  $tpl->setVariable("DAYF",$_POST["dayf"]);
893  $tpl->setVariable("YEART",$_POST["yeart"]);
894  $tpl->setVariable("MONTHT",$_POST["montht"]);
895  $tpl->setVariable("DAYT",$_POST["dayt"]);
896  $tpl->setVariable("LAN", $_POST["language"]);
897  $tpl->setVariable("TYPE", $_POST["object_type"]);
898  $tpl->setVariable("SEARCH_TERMS", ilUtil::prepareFormOutput($_POST["search_terms"]));
899  $tpl->setVariable("FROM", $from);
900  $tpl->setVariable("TO", $to);
901  $tpl->setVariable("TXT_SHOW_USER_DATA", $lng->txt("user_statistics"));
902  $tpl->parseCurrentBlock();
903 
904  $title_new = array("user","client_ip","language","object","time");
905  $condition = $this->getConditions()." and acc_time >= '".$from." 00:00:00' and acc_time <= '".$to." 23:59:59'";
906  $searchTermsCondition = $this->getSearchTermsCondition();
907  $user_acc = $this->object->getAccessPerUserDetail($condition, $searchTermsCondition, $objectCondition);
908  $this->maxcount = count($user_acc);
909  if ($this->maxcount < 1)
910  {
911  $this->ilias->raiseError($lng->txt("msg_no_search_result"),
912  $this->ilias->error_obj->MESSAGE);
913  }
914 
915 # $tbl->setTitle($lng->txt("search_result"),0,0);
916  $tbl->setTitle($lng->txt("obj_trac").": ".$lng->txt("vm_access_of_users")." [".$lng->txt("details")."]",0,0);
917  unset($header_names);
918  foreach ($title_new as $val)
919  {
920  $header_names[] = $lng->txt($val);
921  }
922  $tbl->disable("sort");
923 
924  $tbl->setHeaderNames($header_names);
925  $tbl->setColumnWidth(array("20%", "15%", "15%", "30%", "*"));
926  $tbl->setMaxCount($this->maxcount);
927  # $tbl->setStyle("table", "std");
928 
929  $max = 0;
930 
931  $i = 0;
932  foreach ($user_acc as $user)
933  {
934  unset($data);
935  $data[0] = $user["name"];
936  $data[1] = $user["client_ip"];
937  $data[2] = $user["language"];
938  $data[3] = $user["acc_obj_id"];
939  $data[4] = $user["acc_time"];
940  $css_row = $i%2==0?"tblrow1":"tblrow2";
941  foreach ($data as $key => $val)
942  {
943  if($val=="")
944  {
945  $val=0;
946  }
947  $tplTable->setCurrentBlock("text");
948  $tplTable->setVariable("TEXT_CONTENT", $val);
949  $tplTable->parseCurrentBlock();
950  $tplTable->setCurrentBlock("table_cell");
951  $tplTable->parseCurrentBlock();
952  } //foreach
953  $tplTable->setCurrentBlock("tbl_content");
954  $tplTable->setVariable("CSS_ROW", $css_row);
955  $tplTable->parseCurrentBlock();
956  $i++;
957  } //for
958  }
959  else
960  {
961  $tpl->setCurrentBlock("user_mode");
962  #$tpl->setVariable("FORMACTION", "adm_object.php?ref_id=".$_GET["ref_id"].
963  #"&cmd=gateway");
964  $tpl->setVariable("FORMACTION",$this->ctrl->getFormaction($this,'gateway'));
965  if($_POST["object_type"]=="lm")
966  {
967  $tpl->setVariable("AUTHOR", "author");
968  $tpl->setVariable("AUTHORS", $_POST["author"]);
969  $tpl->setVariable("OBJECT", "lm");
970  $tpl->setVariable("OBJECTS", $_POST["lm"]);
971  }
972  else if($_POST["object_type"]=="htlm")
973  {
974  $tpl->setVariable("AUTHOR", "author");
975  $tpl->setVariable("AUTHORS", $_POST["author"]);
976  $tpl->setVariable("OBJECT", "htlm");
977  $tpl->setVariable("OBJECTS", $_POST["htlm"]);
978  }
979  else
980  {
981  $tpl->setVariable("AUTHOR", "author1");
982  $tpl->setVariable("AUTHORS", $_POST["author1"]);
983  $tpl->setVariable("OBJECT", "tst");
984  $tpl->setVariable("OBJECTS", $_POST["tst"]);
985  }
986  $tpl->setVariable("YEARF",$_POST["yearf"]);
987  $tpl->setVariable("MONTHF",$_POST["monthf"]);
988  $tpl->setVariable("DAYF",$_POST["dayf"]);
989  $tpl->setVariable("YEART",$_POST["yeart"]);
990  $tpl->setVariable("MONTHT",$_POST["montht"]);
991  $tpl->setVariable("DAYT",$_POST["dayt"]);
992  $tpl->setVariable("USER", "user");
993  $tpl->setVariable("LAN", $_POST["language"]);
994  $tpl->setVariable("TYPE", $_POST["object_type"]);
995  $tpl->setVariable("SEARCH_TERMS", ilUtil::prepareFormOutput($_POST["search_terms"]));
996  $tpl->setVariable("FROM", $from);
997  $tpl->setVariable("TO", $to);
998  $tpl->setVariable("TXT_SHOW_USER_DATA", $lng->txt("user_detail"));
999  $tpl->parseCurrentBlock();
1000  $title_new = array("user", "count", "");
1001 
1002  $searchTermsCondition = $this->getSearchTermsCondition();
1003  $user_acc = $this->object->getAccessTotalPerUser($condition, $searchTermsCondition, $objectCondition);
1004 
1005  $this->maxcount = count($user_acc);
1006 
1007  // check if result is given
1008  if ($this->maxcount < 1)
1009  {
1010  $this->ilias->raiseError($lng->txt("msg_no_search_result"),
1011  $this->ilias->error_obj->MESSAGE);
1012  }
1013 
1014 # $tbl->setTitle($lng->txt("search_result"),0,0);
1015  $tbl->setTitle($lng->txt("obj_trac").": ".$lng->txt("vm_access_of_users"),0,0);
1016  unset($header_names);
1017  foreach ($title_new as $val)
1018  {
1019  $header_names[] = $lng->txt($val);
1020  }
1021  $tbl->disable("sort");
1022  $tbl->setHeaderNames($header_names);
1023  $tbl->setColumnWidth(array("20%", "10%", "*"));
1024  $tbl->setMaxCount($this->maxcount);
1025  # $tbl->setStyle("table", "std");
1026 
1027  $max = 0;
1028  foreach ($user_acc as $user)
1029  {
1030  $max = ($max > $user["cnt"]) ? $max : $user["cnt"];
1031  }
1032 
1033  $i = 0;
1034  foreach ($user_acc as $user)
1035  {
1036  unset($data);
1037  $data[0] = $user["name"];
1038  $data[1] = $user["cnt"];
1039  $width = ($max > 0)
1040  ? round($data[1] / $max * 100)
1041  : 0;
1042  $data[2] = "<img src=\"".ilUtil::getImagePath("ray.gif")."\" border=\"0\" ".
1043  "width=\"".$width."\" height=\"10\"/>";
1044 
1045  $css_row = $i%2==0?"tblrow1":"tblrow2";
1046  foreach ($data as $key => $val)
1047  {
1048  if($val=="")
1049  {
1050  $val=0;
1051  }
1052  $tplTable->setCurrentBlock("text");
1053  $tplTable->setVariable("TEXT_CONTENT", $val);
1054  $tplTable->parseCurrentBlock();
1055  $tplTable->setCurrentBlock("table_cell");
1056  $tplTable->parseCurrentBlock();
1057  } //foreach
1058  $tplTable->setCurrentBlock("tbl_content");
1059  $tplTable->setVariable("CSS_ROW", $css_row);
1060  $tplTable->parseCurrentBlock();
1061  $i++;
1062  } //for
1063  }
1064 
1065  }
1066  else //user not selected
1067  {
1068  $title_new = array("time", "count", "");
1069 
1070 # $tbl->setTitle($lng->txt("obj_trac"),0,0);
1071  unset($header_names);
1072  foreach ($title_new as $val)
1073  {
1074  $header_names[] = $lng->txt($val);
1075  }
1076  $tbl->disable("sort");
1077  $tbl->setHeaderNames($header_names);
1078  if($_POST["stat"]=='h') //hours of day
1079  {
1080  $tbl->setTitle($lng->txt("obj_trac").": ".$lng->txt("vm_times_of_day"),0,0);
1081  $tbl->setColumnWidth(array("30%", "10%", "*"));
1082  }
1083  else
1084  {
1085  $tbl->setTitle($lng->txt("obj_trac").": ".$lng->txt("vm_days_of_period"),0,0);
1086  $tbl->setColumnWidth(array("15%", "10%", "*"));
1087  }
1088 
1089  if($_POST["stat"]=='h')
1090  {
1091  $num = 24;
1092  $tbl->setMaxCount($num);
1093  }
1094  else
1095  {
1096  $num = $this->numDay($from,$to);
1097  $from1 = $this->addDay($from);
1098  $tbl->setMaxCount($num);
1099  }
1100  # $tbl->setStyle("table", "std");
1101 
1102  // contition
1103  $condition = $this->getCondition();
1104 
1105  if($_POST["stat"]=='h') //hours of day
1106  {
1107  $searchTermsCondition = $this->getSearchTermsCondition();
1108  $time = $this->selectTime($from,$to,$condition,$searchTermsCondition,$objectCondition);
1109  $max = 0;
1110  for($i=0;$i<24;$i++)
1111  {
1112  $k = $i+1;
1113 
1114  // count number of accesses in hour $i
1115  $cou = 0;
1116  for($j=0;$j<count($time);$j++)
1117  {
1118  $time1 = strtotime($time[$j][0]);
1119  $day = date("d",$time1);
1120  $month = date("m",$time1);
1121  $year = date("Y",$time1);
1122  $hour = date("H",$time1);
1123  $min = date("i",$time1);
1124  $sec = date("s",$time1);
1125  $numb = date("H",mktime($hour,$min,$sec,$month,$day,$year));
1126  $numb = intval($numb);
1127  if($numb >=$i and $numb <$k)
1128  {
1129  $cou=$cou+1;
1130  }
1131  }
1132  $count[$i] = $cou;
1133  $max = ($cou > $max) ? $cou : $max;
1134  }
1135 
1136  for($i=0;$i<24;$i++)
1137  {
1138  $k = $i+1;
1139  unset($data);
1140  $data[0] = ($i < 10 ? "0".$i : $i).":00:00 ~ ".($k < 10 ? "0".$k : $k).":00:00";
1141  $data[1] = $count[$i];
1142  $width = ($max > 0)
1143  ? round($count[$i] / $max * 100)
1144  : 0;
1145  $data[2] = "<img src=\"".ilUtil::getImagePath("ray.gif")."\" border=\"0\" ".
1146  "width=\"".$width."\" height=\"10\"/>";
1147 
1148  $css_row = $i%2==0?"tblrow1":"tblrow2";
1149  foreach ($data as $key => $val)
1150  {
1151  $tplTable->setCurrentBlock("text");
1152  $tplTable->setVariable("TEXT_CONTENT", $val);
1153  $tplTable->parseCurrentBlock();
1154  $tplTable->setCurrentBlock("table_cell");
1155  $tplTable->parseCurrentBlock();
1156  }
1157  $tplTable->setCurrentBlock("tbl_content");
1158  $tplTable->setVariable("CSS_ROW", $css_row);
1159  $tplTable->parseCurrentBlock();
1160  } //for
1161  }
1162  else //day selected
1163  {
1164  $max = 0;
1165  $searchTermsCondition = $this->getSearchTermsCondition();
1166  for($i=0;$i<$num;$i++)
1167  {
1168  $fro[$i] = $from;
1169  $cou[$i] = $this->countNum($from,$from1,$condition,$searchTermsCondition,$objectCondition);
1170  $from = $from1;
1171  $from1 = $this->addDay($from);
1172  $max = ($max > $cou[$i]) ? $max : $cou[$i];
1173  }
1174  for($i=0;$i<$num;$i++)
1175  {
1176  unset($data);
1177  $data[0] = $fro[$i];
1178  $data[1] = $cou[$i];
1179  $width = ($max > 0)
1180  ? round($cou[$i] / $max * 100)
1181  : 0;
1182  $data[2] = "<img src=\"".ilUtil::getImagePath("ray.gif")."\" border=\"0\" ".
1183  "width=\"".$width."\" height=\"10\"/>";
1184 
1185  $css_row = $i%2==0?"tblrow1":"tblrow2";
1186  foreach ($data as $key => $val)
1187  {
1188  $tplTable->setCurrentBlock("text");
1189  $tplTable->setVariable("TEXT_CONTENT", $val);
1190  $tplTable->parseCurrentBlock();
1191  $tplTable->setCurrentBlock("table_cell");
1192  $tplTable->parseCurrentBlock();
1193  }
1194  $tplTable->setCurrentBlock("tbl_content");
1195  $tplTable->setVariable("CSS_ROW", $css_row);
1196  $tplTable->parseCurrentBlock();
1197  } //for
1198  }
1199  }//else
1200 
1201  $tbl->render();
1202  $tpl->setVariable("TRACK_TABLE", $tplTable->get());
1203  unset($tplTable);
1204  unset($tbl);
1205 
1206  }
1207 
1208  // output statistic settings
1209 /* $tpl->setCurrentBlock("adm_content");
1210  $tpl->setVariable("TXT_TIME_PERIOD", $lng->txt("time_segment"));
1211  switch ($_POST["stat"])
1212  {
1213  case "h":
1214  $tpl->setVariable("TXT_STATISTIC", $lng->txt("hours_of_day"));
1215  break;
1216 
1217  case "u":
1218  $tpl->setVariable("TXT_STATISTIC", $lng->txt("user_access"));
1219  break;
1220 
1221  case "d":
1222  $tpl->setVariable("TXT_STATISTIC", $lng->txt("days_of_period"));
1223  break;
1224 
1225  case "o":
1226  $tpl->setVariable("TXT_STATISTIC", $lng->txt("per_object"));
1227  break;
1228  }
1229  $tpl->setVariable("VAL_DATEF", date("Y-m-d", mktime(0,0,0,$monthf,$dayf,$yearf)));
1230  $tpl->setVariable("TXT_SEARCH_TERMS", $lng->txt("search_terms"));
1231  $tpl->setVariable("VAL_SEARCH_TERMS", ilUtil::stripSlashes($_POST["search_terms"]));
1232  $tpl->setVariable("TXT_TO", $lng->txt("to"));
1233  $tpl->setVariable("VAL_DATET", date("Y-m-d", mktime(0,0,0,$montht,$dayt,$yeart)));
1234  $tpl->setVariable("TXT_USER_LANGUAGE", $lng->txt("user_language"));
1235  if ($_POST["language"] == "0")
1236  {
1237  $tpl->setVariable("VAL_LANGUAGE", $lng->txt("any_language"));
1238  }
1239  else
1240  {
1241  $tpl->setVariable("VAL_LANGUAGE", $lng->txt("lang_".$_POST["language"]));
1242  }
1243  $tpl->setVariable("TXT_TRACKED_OBJECTS", $lng->txt("tracked_objects"));
1244  if ($_POST[$_POST["object_type"]] != 0)
1245  {
1246  $tpl->setVariable("VAL_TRACKED_OBJECTS",
1247  ilObject::_lookupTitle($_POST[$_POST["object_type"]]));
1248  }
1249  else
1250  {
1251  $tpl->setVariable("VAL_TRACKED_OBJECTS",
1252  $lng->txt("all_".$_POST["object_type"]."s"));
1253  }
1254  $tpl->parseCurrentBlock();*/
1255  }
1256 
1260  function getCondition()
1261  {
1262  $lang_cond = $this->getLanguageCondition();
1263  //echo ":$lang_cond:";
1264  if ($lang_cond == "")
1265  {
1266  $this->setConditions($this->getObjectCondition());
1267  return $this->getObjectCondition();
1268  }
1269  else
1270  {
1271  $this->setConditions($lang_cond." AND ".$this->getObjectCondition());
1272  return $lang_cond." AND ".$this->getObjectCondition();
1273  }
1274  }
1275 
1276 
1281  {
1282  global $ilDB;
1283 
1284  $type = $_POST["object_type"];
1285  $condition = "";
1286  if($_POST["object_type"]=="lm")
1287  {
1288  if($_POST["author"]=="0")
1289  {
1290  return " acc_obj_type = 'lm'";
1291  }
1292  elseif($_POST["lm"]=="0" or $_POST["lm"]=="")
1293  {
1294  if (is_array($authors = ilObjUserTracking::allAuthor("usr","lm")))
1295  {
1296  foreach ($authors as $author)
1297  {
1298  if($author["title"]==$_POST["author"])
1299  {
1300  if (is_array($lms = ilObjUserTracking::authorLms($author["obj_id"],"lm")))
1301  {
1302  foreach ($lms as $lm)
1303  {
1304  $condition = $condition." or acc_obj_id = ".$lm["obj_id"];
1305  }
1306  }
1307  }
1308  }
1309  }
1310  return " ( 0 ".$condition." ) ";
1311  }
1312  else
1313  {
1314  $condition.= " acc_obj_id = ".ilObjUserTracking::getObjId($_POST["lm"],$type);
1315  return $condition;
1316  }
1317 
1318  }
1319  else if($_POST["object_type"]=="htlm")
1320  {
1321  if($_POST["author"]=="0")
1322  {
1323  return " acc_obj_type = 'htlm'";
1324  }
1325  elseif($_POST["htlm"]=="0" or $_POST["htlm"]=="")
1326  {
1327  if (is_array($authors = ilObjUserTracking::allAuthor("usr","htlm")))
1328  {
1329  foreach ($authors as $author)
1330  {
1331  if($author["title"]==$_POST["author"])
1332  {
1333  if (is_array($htlms = ilObjUserTracking::authorLms($author["obj_id"],"htlm")))
1334  {
1335  foreach ($htlms as $htlm)
1336  {
1337  $condition = $condition." or acc_obj_id = ".$htlm["obj_id"];
1338  }
1339  }
1340  }
1341  }
1342  }
1343  return " ( 0 ".$condition." ) ";
1344  }
1345  else
1346  {
1347  $condition.= " acc_obj_id = ".ilObjUserTracking::getObjId($_POST["htlm"],$type);
1348  return $condition;
1349  }
1350 
1351  }
1352  else
1353  {
1354  if($_POST["author1"]=="0")
1355  {
1356  return " acc_obj_type = 'tst'";
1357  }
1358  elseif($_POST["tst"]=="0" or $_POST["tst"]=="")
1359  {
1360  if (is_array($authors = ilObjUserTracking::allAuthor("usr","tst")))
1361  {
1362  foreach ($authors as $author)
1363  {
1364  if($author["title"]==$_POST["author1"])
1365  {
1366  if (is_array($lms = ilObjUserTracking::authorLms($author["obj_id"],"tst")))
1367  {
1368  foreach ($lms as $lm)
1369  {
1370  $condition = $condition." or acc_obj_id = ".$lm["obj_id"];
1371  }
1372  }
1373  }
1374  }
1375  }
1376  return " ( 0 ".$condition." ) ";
1377  }
1378  else
1379  {
1380  $condition.= " acc_obj_id = ".ilObjUserTracking::getObjId($_POST["tst"],$type);
1381  return $condition;
1382  }
1383  }
1384  }
1385 
1390  {
1391  global $ilDB;
1392 
1393  if ($_POST["language"] != "0")
1394  {
1395  return "ut_access.language =".$ilDB->quote($_POST["language"], "text");
1396  }
1397 
1398  return "";
1399  }
1400 
1405  {
1406  global $ilDB;
1407 
1408  if (trim($_POST["search_terms"]) != "")
1409  {
1410  $sub_ret = "";
1411  $terms = explode(" ", $_POST["search_terms"]);
1412  for ($i = 0; $i < count($terms); $i++)
1413  {
1414  if (trim($terms[$i]) != "") $sub_ret .= "oa.title LIKE '%".ilUtil::addSlashes(trim($terms[$i]))."%' OR ";
1415  }
1416  if ($sub_ret != "")
1417  {
1418  return " INNER JOIN object_data oa ON oa.obj_id = acc_obj_id WHERE (".substr($sub_ret, 0, strlen($sub_ret)-4) . ") AND ";
1419  }
1420  }
1421 
1422  return "";
1423  }
1424 
1425  function setConditions($con)
1426  {
1427  $this->conditions = $con;
1428  }
1429  function getConditions()
1430  {
1431  return $this->conditions;
1432  }
1433 
1437  function numDay($from,$to)
1438  {
1439 
1440  $from = strtotime($from);
1441  $to = strtotime($to);
1442 
1443  $dayf = date ("d",$from);
1444  $dayt = date ("d",$to);
1445  $yearf = date ("Y",$from);
1446  $yeart = date ("Y",$to);
1447  $montht = date ("m",$to);
1448  $monthf = date ("m",$from);
1449 
1450 # $ret = ( mktime(0,0,0,$montht,$dayt,$yeart) - mktime(0,0,0,$monthf,$dayf,$yearf))/(3600*24);
1451 # return $ret;
1452 
1453  $from = mktime(12,0,0,$monthf,$dayf,$yearf);
1454  $to = mktime(12,0,0,$montht,$dayt,$yeart);
1455 
1456  $ret = (round(($to - $from) / 86400) + 1);
1457  return $ret;
1458 
1459 # $x0 = gregoriantojd($monthf,$dayf,$yearf);
1460 # $x1 = gregoriantojd($montht,$dayt,$yeart);
1461 # return (($x1 - $x0)+1);
1462  }
1463 
1467  function numHour($from,$to)
1468  {
1469  $from = strtotime($from);
1470  $to = strtotime($to);
1471  $dayf = date ("d",$from);
1472  $dayt = date ("d",$to);
1473  $yearf = date ("Y",$from);
1474  $yeart = date ("Y",$to);
1475  $montht = date ("m",$to);
1476  $monthf = date ("m",$from);
1477  $hourt = date ("h",$to);
1478  $hourf = date ("h",$from);
1479  $ret = (mktime($hourt,0,0,$montht,$dayt,$yeart)-mktime($hourf,0,0,$monthf,$dayf,$yearf))/3600;
1480  $ret = strftime($ret);
1481  return $ret;
1482  }
1483 
1487  function addHour($time)
1488  {
1489  $time = strtotime($time);
1490  $day = date("d",$time);
1491  $month = date("m",$time);
1492  $year = date("Y",$time);
1493  $hour = date("H",$time);
1494  $min = date("i",$time);
1495  $sec = date("s",$time);
1496  $hour = $hour+1;
1497  $ret = date("H:i:s", mktime($hour,$min,$sec,$month,$day,$year));
1498  return $ret;
1499  }
1500 
1504  function addDay($time)
1505  {
1506  $time = strtotime($time);
1507  $day = date("d",$time);
1508  $month = date("m",$time);
1509  $year = date("y",$time);
1510  $min = date("i",$time);
1511  $hour = date("h",$time);
1512  $sec = date("s",$time);
1513  $day = $day + 1;
1514  $ret = date ("Y-m-d", mktime($hour,$min,$sec,$month,$day,$year));
1515  return $ret;
1516  }
1517 
1521  function selectTime($from,$to,$condition,$searchTermsCondition="",$objectCondition="")
1522  {
1523  global $ilDB;
1524 
1525  $q = "SELECT acc_time from ut_access "
1526  .($searchTermsCondition != "" ? $searchTermsCondition : " WHERE ")
1527  ." (acc_time >= ".$ilDB->quote($from." 00:00:00", "timestamp")
1528  ." AND acc_time <= ".$ilDB->quote($to." 23:59:59", "timestamp").")"
1529  ." AND ".$condition
1530  .$objectCondition
1531  ." GROUP BY acc_time";
1532  $res = $this->ilias->db->query($q);
1533  for($i=0;$i<$res->numRows();$i++)
1534  {
1535  $result[$i]=$res->fetchRow();
1536  }
1537  return $result;
1538  }
1539 
1543  function countNum($from,$from1,$condition,$searchTermsCondition="",$objectCondition="")
1544  {
1545  global $ilDB;
1546 
1547  $q = "SELECT id FROM ut_access"
1548  .($searchTermsCondition != "" ? $searchTermsCondition : " WHERE ")
1549  ." (acc_time >= ".$ilDB->quote($from." 00:00:00", "timestamp")
1550  ." AND acc_time <= ".$ilDB->quote($from1." 00:00:00", "timestamp").")"
1551  ." AND ".$condition
1552  .$objectCondition
1553  ." GROUP BY id";
1554  $res = $this->ilias->db->query($q);
1555  return $res->numRows();
1556  }
1557 }
1558 ?>