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