1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* File for training_data_storage class
|
|
|
19 |
*/
|
|
|
20 |
|
|
|
21 |
use phpbrowscap\Browscap;
|
|
|
22 |
|
|
|
23 |
/**
|
|
|
24 |
* Storage Class creates the object class element
|
|
|
25 |
*
|
|
|
26 |
* @package report_training
|
|
|
27 |
* @copyright 2016 Mark Heumueller <mark.heumueller@gmx.de>
|
|
|
28 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
29 |
*/
|
|
|
30 |
class training_data_storage{
|
|
|
31 |
|
|
|
32 |
/**
|
|
|
33 |
* @var Object $instance holds the a instance of the class
|
|
|
34 |
*/
|
|
|
35 |
private static $instance;
|
|
|
36 |
|
|
|
37 |
/**
|
|
|
38 |
* init the instance for events.php
|
|
|
39 |
* @see db/events.php
|
|
|
40 |
*/
|
|
|
41 |
public function __construct() {
|
|
|
42 |
self::$instance = $this;
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
/**
|
|
|
46 |
* init the instace for events.php
|
|
|
47 |
* @return training_data_storage $instance
|
|
|
48 |
* @deprecated
|
|
|
49 |
*/
|
|
|
50 |
public static function getinstance() {
|
|
|
51 |
if (self::$instance === null) {
|
|
|
52 |
self::$instance = new self();
|
|
|
53 |
}
|
|
|
54 |
return self::$instance;
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
/**
|
|
|
58 |
* create the saved object
|
|
|
59 |
* @return int object id form db table
|
|
|
60 |
*/
|
|
|
61 |
public function training_user_loggedin() {
|
|
|
62 |
global $USER;
|
|
|
63 |
global $DB;
|
|
|
64 |
global $CFG;
|
|
|
65 |
|
|
|
66 |
$ipcurrent = getremoteaddr();
|
|
|
67 |
//var_dump($ipcurren);
|
|
|
68 |
|
|
|
69 |
$pluginsetting = $DB->get_record('report_training', array(), '*');
|
|
|
70 |
if ($pluginsetting->status == 0) {
|
|
|
71 |
return 0;
|
|
|
72 |
}
|
|
|
73 |
if ($pluginsetting->adminlog == 0) {
|
|
|
74 |
if ($this->getusersystemrole($USER->id) == 'admin') {
|
|
|
75 |
return 0;
|
|
|
76 |
}
|
|
|
77 |
}
|
|
|
78 |
|
|
|
79 |
$currentdevicedata = new training_data_object();
|
|
|
80 |
if ($pluginsetting->anonymous == 0) {
|
|
|
81 |
$currentdevicedata->userid = $USER->id;
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
$currentdevicedata->userhash = training_data_object::get_identify_hash($_SESSION['USER']);
|
|
|
85 |
$alreadyexits = $DB->get_record_sql('SELECT * FROM {report_training_data} WHERE userhash = ?',
|
|
|
86 |
array($currentdevicedata->userhash));
|
|
|
87 |
|
|
|
88 |
if (!empty($alreadyexits) || is_null($alreadyexits)) {
|
|
|
89 |
return 0;
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
$currentdevicedata->userrole = $this->getusersystemrole($USER->id);
|
|
|
93 |
$currentdevicedata->objectdate = time();
|
|
|
94 |
$currentdevicedata->activemoodlelang = $USER->lang;
|
|
|
95 |
|
|
|
96 |
$browscap = new Browscap($CFG->dataroot.'/cache/');
|
|
|
97 |
$browscap->doAutoUpdate = false;
|
|
|
98 |
$info = $browscap->getBrowser();
|
|
|
99 |
|
|
|
100 |
//var_dump($info);
|
|
|
101 |
//die();
|
|
|
102 |
|
|
|
103 |
|
|
|
104 |
|
|
|
105 |
|
|
|
106 |
$devicetype = $info->Device_Type;
|
|
|
107 |
$currentdevicedata->devicetype = $devicetype;
|
|
|
108 |
$currentdevicedata->devicebrand = $info->Parent;
|
|
|
109 |
$currentdevicedata->devicesystem = $info->Platform;
|
|
|
110 |
$currentdevicedata->devicebrowser = $info->Browser;
|
|
|
111 |
$currentdevicedata->devicebrowserversion = $info->Version;
|
|
|
112 |
$currentdevicedata->devicepointingmethod = $info->Device_Pointing_Method;
|
|
|
113 |
$currentdevicedata->ip = $ipcurrent;
|
|
|
114 |
|
|
|
115 |
|
|
|
116 |
$insertid = $DB->insert_record('report_training_data', $currentdevicedata, true);
|
|
|
117 |
return $insertid;
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
/**
|
|
|
121 |
* insert the js enabled sizes
|
|
|
122 |
* @see ajaxcall.php
|
|
|
123 |
* @param int $insertid row_id
|
|
|
124 |
* @param int $devicedisplaysizex display width
|
|
|
125 |
* @param int $devicedisplaysizey display height
|
|
|
126 |
* @param int $devicewindowsizex window width
|
|
|
127 |
* @param int $devicewindowsizey window height
|
|
|
128 |
*/
|
|
|
129 |
public function report_training_update_screensize(
|
|
|
130 |
$insertid,
|
|
|
131 |
$devicedisplaysizex,
|
|
|
132 |
$devicedisplaysizey,
|
|
|
133 |
$devicewindowsizex,
|
|
|
134 |
$devicewindowsizey) {
|
|
|
135 |
global $DB;
|
|
|
136 |
$recordwithout = $DB->get_record('report_training_data', array('id' => $insertid), '*');
|
|
|
137 |
$recordwithout->devicedisplaysizex = $devicedisplaysizex;
|
|
|
138 |
$recordwithout->devicedisplaysizey = $devicedisplaysizey;
|
|
|
139 |
$recordwithout->devicewindowsizex = $devicewindowsizex;
|
|
|
140 |
$recordwithout->devicewindowsizey = $devicewindowsizey;
|
|
|
141 |
|
|
|
142 |
$DB->update_record('report_training_data', $recordwithout);
|
|
|
143 |
}
|
|
|
144 |
|
|
|
145 |
/**
|
|
|
146 |
* check if user is admin
|
|
|
147 |
* @return String isadmin
|
|
|
148 |
* @param int $userid userid
|
|
|
149 |
*/
|
|
|
150 |
private function getusersystemrole($userid) {
|
|
|
151 |
if (is_siteadmin($userid)) {
|
|
|
152 |
return "admin";
|
|
|
153 |
} else {
|
|
|
154 |
return "user";
|
|
|
155 |
}
|
|
|
156 |
}
|
|
|
157 |
|
|
|
158 |
/**
|
|
|
159 |
*
|
|
|
160 |
*/
|
|
|
161 |
public function getlastaccess() {
|
|
|
162 |
global $CFG;
|
|
|
163 |
global $DB;
|
|
|
164 |
global $USER;
|
|
|
165 |
|
|
|
166 |
$userid = $USER->id;
|
|
|
167 |
|
|
|
168 |
|
|
|
169 |
|
|
|
170 |
$records = $DB->get_records('report_training_lastaccess', ['userid' => $userid], "timeaccess DESC LIMIT 1");
|
|
|
171 |
|
|
|
172 |
if($records) {
|
|
|
173 |
$record_lastaccess = array_pop($records);
|
|
|
174 |
|
|
|
175 |
$now = time();
|
|
|
176 |
|
|
|
177 |
$record_course = $DB->get_record('course', ['id' => $record_lastaccess->courseid ]);
|
|
|
178 |
if($record_course && $record_course->visible && $record_course->startdate <= $now) {
|
|
|
179 |
|
|
|
180 |
$record_module = $DB->get_record('course_modules', ['course' => $record_lastaccess->courseid, 'id' => $record_lastaccess->cmid ]);
|
|
|
181 |
if($record_module && $record_module->visible && $record_module->visibleoncoursepage) {
|
|
|
182 |
|
|
|
183 |
$viewurl = $record_lastaccess->viewurl;
|
|
|
184 |
if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
|
|
|
185 |
$viewurl = str_replace('http:', 'https:', $viewurl);
|
|
|
186 |
}
|
|
|
187 |
|
|
|
188 |
return $viewurl;
|
|
|
189 |
|
|
|
190 |
}
|
|
|
191 |
}
|
|
|
192 |
}
|
|
|
193 |
|
|
|
194 |
|
|
|
195 |
$viewurl= $CFG->wwwroot . '/my';
|
|
|
196 |
if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
|
|
|
197 |
$viewurl = str_replace('http:', 'https:', $viewurl);
|
|
|
198 |
}
|
|
|
199 |
|
|
|
200 |
return $viewurl;
|
|
|
201 |
|
|
|
202 |
|
|
|
203 |
|
|
|
204 |
}
|
|
|
205 |
|
|
|
206 |
}
|