Passed
Push — 1.10.x ( 918f1f...c8b126 )
by Yannick
419:13 queued 372:02
created
main/inc/lib/internationalization_database/transliteration/x02.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@
 block discarded – undo
2 2
 // $Id: x02.php,v 1.1.8.1 2008/06/12 20:34:31 smk Exp $
3 3
 
4 4
 return array(
5
-  'en' => array('A', 'a', 'A', 'a', 'E', 'e', 'E', 'e', 'I', 'i', 'I', 'i', 'O', 'o', 'O', 'o',
5
+    'en' => array('A', 'a', 'A', 'a', 'E', 'e', 'E', 'e', 'I', 'i', 'I', 'i', 'O', 'o', 'O', 'o',
6 6
     'R', 'r', 'R', 'r', 'U', 'u', 'U', 'u', 'S', 's', 'T', 't', 'Y', 'y', 'H', 'h',
7 7
     'N', 'd', 'OU', 'ou', 'Z', 'z', 'A', 'a', 'E', 'e', 'O', 'o', 'O', 'o', 'O', 'o',
8 8
     'O', 'o', 'Y', 'y', 'l', 'n', 't', 'j', 'db', 'qp', 'A', 'C', 'c', 'L', 'T', 's',
Please login to merge, or discard this patch.
main/inc/lib/internationalization_database/transliteration/x16.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@
 block discarded – undo
2 2
 // $Id: x16.php,v 1.1.8.1 2008/06/12 20:34:31 smk Exp $
3 3
 
4 4
 return array(
5
-  'en' => array('kka', 'kk', 'nu', 'no', 'ne', 'nee', 'ni', 'na', 'mu', 'mo', 'me', 'mee', 'mi', 'ma', 'yu', 'yo',
5
+    'en' => array('kka', 'kk', 'nu', 'no', 'ne', 'nee', 'ni', 'na', 'mu', 'mo', 'me', 'mee', 'mi', 'ma', 'yu', 'yo',
6 6
     'ye', 'yee', 'yi', 'ya', 'ju', 'ju', 'jo', 'je', 'jee', 'ji', 'ji', 'ja', 'jju', 'jjo', 'jje', 'jjee',
7 7
     'jji', 'jja', 'lu', 'lo', 'le', 'lee', 'li', 'la', 'dlu', 'dlo', 'dle', 'dlee', 'dli', 'dla', 'lhu', 'lho',
8 8
     'lhe', 'lhee', 'lhi', 'lha', 'tlhu', 'tlho', 'tlhe', 'tlhee', 'tlhi', 'tlha', 'tlu', 'tlo', 'tle', 'tlee', 'tli', 'tla',
Please login to merge, or discard this patch.
main/inc/lib/internationalization_database/transliteration/x6c.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@
 block discarded – undo
2 2
 // $Id: x6c.php,v 1.1.8.1 2008/06/12 20:34:31 smk Exp $
3 3
 
4 4
 return array(
5
-  'en' => array('Lu ', 'Mu ', 'Li ', 'Tong ', 'Rong ', 'Chang ', 'Pu ', 'Luo ', 'Zhan ', 'Sao ', 'Zhan ', 'Meng ', 'Luo ', 'Qu ', 'Die ', 'Shi ',
5
+    'en' => array('Lu ', 'Mu ', 'Li ', 'Tong ', 'Rong ', 'Chang ', 'Pu ', 'Luo ', 'Zhan ', 'Sao ', 'Zhan ', 'Meng ', 'Luo ', 'Qu ', 'Die ', 'Shi ',
6 6
     'Di ', 'Min ', 'Jue ', 'Mang ', 'Qi ', 'Pie ', 'Nai ', 'Qi ', 'Dao ', 'Xian ', 'Chuan ', 'Fen ', 'Ri ', 'Nei ', NULL, 'Fu ',
7 7
     'Shen ', 'Dong ', 'Qing ', 'Qi ', 'Yin ', 'Xi ', 'Hai ', 'Yang ', 'An ', 'Ya ', 'Ke ', 'Qing ', 'Ya ', 'Dong ', 'Dan ', 'Lu ',
8 8
     'Qing ', 'Yang ', 'Yun ', 'Yun ', 'Shui ', 'San ', 'Zheng ', 'Bing ', 'Yong ', 'Dang ', 'Shitamizu ', 'Le ', 'Ni ', 'Tun ', 'Fan ', 'Gui ',
Please login to merge, or discard this patch.
main/inc/lib/internationalization_database/transliteration/xb8.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@
 block discarded – undo
2 2
 // $Id: xb8.php,v 1.1.8.1 2008/06/12 20:34:32 smk Exp $
3 3
 
4 4
 return array(
5
-  'en' => array('reoss', 'reong', 'reoj', 'reoc', 'reok', 'reot', 'reop', 'reoh', 're', 'reg', 'regg', 'regs', 'ren', 'renj', 'renh', 'red',
5
+    'en' => array('reoss', 'reong', 'reoj', 'reoc', 'reok', 'reot', 'reop', 'reoh', 're', 'reg', 'regg', 'regs', 'ren', 'renj', 'renh', 'red',
6 6
     'rel', 'relg', 'relm', 'relb', 'rels', 'relt', 'relp', 'relh', 'rem', 'reb', 'rebs', 'res', 'ress', 'reng', 'rej', 'rec',
7 7
     'rek', 'ret', 'rep', 'reh', 'ryeo', 'ryeog', 'ryeogg', 'ryeogs', 'ryeon', 'ryeonj', 'ryeonh', 'ryeod', 'ryeol', 'ryeolg', 'ryeolm', 'ryeolb',
8 8
     'ryeols', 'ryeolt', 'ryeolp', 'ryeolh', 'ryeom', 'ryeob', 'ryeobs', 'ryeos', 'ryeoss', 'ryeong', 'ryeoj', 'ryeoc', 'ryeok', 'ryeot', 'ryeop', 'ryeoh',
Please login to merge, or discard this patch.
main/inc/lib/internationalization_database/transliteration/xbd.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@
 block discarded – undo
2 2
 // $Id: xbd.php,v 1.1.8.1 2008/06/12 20:34:32 smk Exp $
3 3
 
4 4
 return array(
5
-  'en' => array('bols', 'bolt', 'bolp', 'bolh', 'bom', 'bob', 'bobs', 'bos', 'boss', 'bong', 'boj', 'boc', 'bok', 'bot', 'bop', 'boh',
5
+    'en' => array('bols', 'bolt', 'bolp', 'bolh', 'bom', 'bob', 'bobs', 'bos', 'boss', 'bong', 'boj', 'boc', 'bok', 'bot', 'bop', 'boh',
6 6
     'bwa', 'bwag', 'bwagg', 'bwags', 'bwan', 'bwanj', 'bwanh', 'bwad', 'bwal', 'bwalg', 'bwalm', 'bwalb', 'bwals', 'bwalt', 'bwalp', 'bwalh',
7 7
     'bwam', 'bwab', 'bwabs', 'bwas', 'bwass', 'bwang', 'bwaj', 'bwac', 'bwak', 'bwat', 'bwap', 'bwah', 'bwae', 'bwaeg', 'bwaegg', 'bwaegs',
8 8
     'bwaen', 'bwaenj', 'bwaenh', 'bwaed', 'bwael', 'bwaelg', 'bwaelm', 'bwaelb', 'bwaels', 'bwaelt', 'bwaelp', 'bwaelh', 'bwaem', 'bwaeb', 'bwaebs', 'bwaes',
Please login to merge, or discard this patch.
main/inc/lib/getid3/module.audio-video.flv.php 1 patch
Indentation   +401 added lines, -401 removed lines patch added patch discarded remove patch
@@ -39,12 +39,12 @@  discard block
 block discarded – undo
39 39
 //
40 40
 // $Id: module.audio-video.flv.php,v 1.7 2006/11/10 11:20:12 ah Exp $
41 41
 /**
42
- * @package chamilo.include.flv
43
- */
42
+     * @package chamilo.include.flv
43
+     */
44 44
 /**
45
- * Class
46
- * @package chamilo.include.flv
47
- */
45
+     * Class
46
+     * @package chamilo.include.flv
47
+     */
48 48
 class getid3_flv extends getid3_handler {
49 49
 
50 50
     const TAG_AUDIO    =  8;
@@ -56,522 +56,522 @@  discard block
 block discarded – undo
56 56
     const VIDEO_VP6    = 4;
57 57
 
58 58
 
59
-	public function Analyze()
60
-	{
61
-	    $info = &$this->getid3->info;
59
+    public function Analyze()
60
+    {
61
+        $info = &$this->getid3->info;
62 62
 
63
-	    $info['flv'] = array ();
64
-	    $info_flv = &$info['flv'];
63
+        $info['flv'] = array ();
64
+        $info_flv = &$info['flv'];
65 65
 
66
-		fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
66
+        fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
67 67
 
68
-		$flv_data_length = $info['avdataend'] - $info['avdataoffset'];
69
-		$flv_header = fread($this->getid3->fp, 5);
70
-
71
-		$info['fileformat'] = 'flv';
72
-		$info_flv['header']['signature'] =                           substr($flv_header, 0, 3);
73
-		$info_flv['header']['version']   = getid3_lib::BigEndian2Int(substr($flv_header, 3, 1));
74
-		$type_flags                      = getid3_lib::BigEndian2Int(substr($flv_header, 4, 1));
68
+        $flv_data_length = $info['avdataend'] - $info['avdataoffset'];
69
+        $flv_header = fread($this->getid3->fp, 5);
70
+
71
+        $info['fileformat'] = 'flv';
72
+        $info_flv['header']['signature'] =                           substr($flv_header, 0, 3);
73
+        $info_flv['header']['version']   = getid3_lib::BigEndian2Int(substr($flv_header, 3, 1));
74
+        $type_flags                      = getid3_lib::BigEndian2Int(substr($flv_header, 4, 1));
75 75
 
76
-		$info_flv['header']['hasAudio'] = (bool) ($type_flags & 0x04);
77
-		$info_flv['header']['hasVideo'] = (bool) ($type_flags & 0x01);
76
+        $info_flv['header']['hasAudio'] = (bool) ($type_flags & 0x04);
77
+        $info_flv['header']['hasVideo'] = (bool) ($type_flags & 0x01);
78 78
 
79
-		$frame_size_data_length = getid3_lib::BigEndian2Int(fread($this->getid3->fp, 4));
80
-		$flv_header_frame_length = 9;
81
-		if ($frame_size_data_length > $flv_header_frame_length) {
82
-			fseek($this->getid3->fp, $frame_size_data_length - $flv_header_frame_length, SEEK_CUR);
83
-		}
84
-
85
-		$duration = 0;
86
-		while ((ftell($this->getid3->fp) + 1) < $info['avdataend']) {
87
-
88
-			$this_tag_header = fread($this->getid3->fp, 16);
89
-
90
-			$previous_tag_length = getid3_lib::BigEndian2Int(substr($this_tag_header,  0, 4));
91
-			$tag_type            = getid3_lib::BigEndian2Int(substr($this_tag_header,  4, 1));
92
-			$data_length         = getid3_lib::BigEndian2Int(substr($this_tag_header,  5, 3));
93
-			$timestamp           = getid3_lib::BigEndian2Int(substr($this_tag_header,  8, 3));
94
-			$last_header_byte    = getid3_lib::BigEndian2Int(substr($this_tag_header, 15, 1));
95
-			$next_offset         = ftell($this->getid3->fp) - 1 + $data_length;
96
-
97
-			switch ($tag_type) {
98
-
99
-				case getid3_flv::TAG_AUDIO:
100
-					if (!isset($info_flv['audio']['audioFormat'])) {
101
-						$info_flv['audio']['audioFormat']     =  $last_header_byte & 0x07;
102
-						$info_flv['audio']['audioRate']       = ($last_header_byte & 0x30) / 0x10;
103
-						$info_flv['audio']['audioSampleSize'] = ($last_header_byte & 0x40) / 0x40;
104
-						$info_flv['audio']['audioType']       = ($last_header_byte & 0x80) / 0x80;
105
-					}
106
-					break;
107
-
108
-
109
-				case getid3_flv::TAG_VIDEO:
110
-					if (!isset($info_flv['video']['videoCodec'])) {
111
-						$info_flv['video']['videoCodec'] = $last_header_byte & 0x07;
112
-
113
-						$flv_video_header = fread($this->getid3->fp, 11);
114
-
115
-						if ($info_flv['video']['videoCodec'] != getid3_flv::VIDEO_VP6) {
116
-
117
-							$picture_size_type = (getid3_lib::BigEndian2Int(substr($flv_video_header, 3, 2))) >> 7;
118
-							$picture_size_type = $picture_size_type & 0x0007;
119
-							$info_flv['header']['videoSizeType'] = $picture_size_type;
120
-
121
-							switch ($picture_size_type) {
122
-								case 0:
123
-									$picture_size_enc = getid3_lib::BigEndian2Int(substr($flv_video_header, 5, 2));
124
-									$picture_size_enc <<= 1;
125
-									$info['video']['resolution_x'] = ($picture_size_enc & 0xFF00) >> 8;
126
-									$picture_size_enc = getid3_lib::BigEndian2Int(substr($flv_video_header, 6, 2));
127
-									$picture_size_enc <<= 1;
128
-									$info['video']['resolution_y'] = ($picture_size_enc & 0xFF00) >> 8;
129
-									break;
130
-
131
-								case 1:
132
-									$picture_size_enc = getid3_lib::BigEndian2Int(substr($flv_video_header, 5, 4));
133
-									$picture_size_enc <<= 1;
134
-									$info['video']['resolution_x'] = ($picture_size_enc & 0xFFFF0000) >> 16;
135
-
136
-									$picture_size_enc = getid3_lib::BigEndian2Int(substr($flv_video_header, 7, 4));
137
-									$picture_size_enc <<= 1;
138
-									$info['video']['resolution_y'] = ($picture_size_enc & 0xFFFF0000) >> 16;
139
-									break;
140
-
141
-								case 2:
142
-									$info['video']['resolution_x'] = 352;
143
-									$info['video']['resolution_y'] = 288;
144
-									break;
145
-
146
-								case 3:
147
-									$info['video']['resolution_x'] = 176;
148
-									$info['video']['resolution_y'] = 144;
149
-									break;
150
-
151
-								case 4:
152
-									$info['video']['resolution_x'] = 128;
153
-									$info['video']['resolution_y'] = 96;
154
-									break;
155
-
156
-								case 5:
157
-									$info['video']['resolution_x'] = 320;
158
-									$info['video']['resolution_y'] = 240;
159
-									break;
160
-
161
-								case 6:
162
-									$info['video']['resolution_x'] = 160;
163
-									$info['video']['resolution_y'] = 120;
164
-									break;
165
-
166
-								default:
167
-									$info['video']['resolution_x'] = 0;
168
-									$info['video']['resolution_y'] = 0;
169
-									break;
170
-							}
171
-						}
172
-					}
173
-					break;
174
-
175
-
176
-				// Meta tag
177
-				case getid3_flv::TAG_META:
178
-
179
-					fseek($this->getid3->fp, -1, SEEK_CUR);
180
-					$reader = new AMFReader(new AMFStream(fread($this->getid3->fp, $data_length)));
181
-					$event_name = $reader->readData();
182
-					$info['meta'][$event_name] = $reader->readData();
183
-					unset($reader);
184
-
185
-					$info['video']['frame_rate']   = @$info['meta']['onMetaData']['framerate'];
186
-					$info['video']['resolution_x'] = @$info['meta']['onMetaData']['width'];
187
-					$info['video']['resolution_y'] = @$info['meta']['onMetaData']['height'];
188
-					break;
189
-
190
-				default:
191
-					// noop
192
-					break;
193
-			}
194
-
195
-			if ($timestamp > $duration) {
196
-				$duration = $timestamp;
197
-			}
198
-
199
-			fseek($this->getid3->fp, $next_offset, SEEK_SET);
200
-		}
201
-
202
-		if ($info['playtime_seconds'] = $duration / 1000) {
203
-		    $info['bitrate'] = ($info['avdataend'] - $info['avdataoffset']) / $info['playtime_seconds'];
204
-		}
205
-
206
-		if ($info_flv['header']['hasAudio']) {
207
-			$info['audio']['codec']           = $this->FLVaudioFormat($info_flv['audio']['audioFormat']);
208
-			$info['audio']['sample_rate']     = $this->FLVaudioRate($info_flv['audio']['audioRate']);
209
-			$info['audio']['bits_per_sample'] = $this->FLVaudioBitDepth($info_flv['audio']['audioSampleSize']);
210
-
211
-			$info['audio']['channels']   = $info_flv['audio']['audioType'] + 1; // 0=mono,1=stereo
212
-			$info['audio']['lossless']   = ($info_flv['audio']['audioFormat'] ? false : true); // 0=uncompressed
213
-			$info['audio']['dataformat'] = 'flv';
214
-		}
215
-		if (@$info_flv['header']['hasVideo']) {
216
-			$info['video']['codec']      = $this->FLVvideoCodec($info_flv['video']['videoCodec']);
217
-			$info['video']['dataformat'] = 'flv';
218
-			$info['video']['lossless']   = false;
219
-		}
220
-
221
-		return true;
222
-	}
223
-
224
-
225
-	public static function FLVaudioFormat($id) {
226
-
227
-		static $lookup = array(
228
-			0 => 'uncompressed',
229
-			1 => 'ADPCM',
230
-			2 => 'mp3',
231
-			5 => 'Nellymoser 8kHz mono',
232
-			6 => 'Nellymoser',
233
-		);
234
-		return (@$lookup[$id] ? @$lookup[$id] : false);
235
-	}
236
-
237
-
238
-	public static function FLVaudioRate($id) {
239
-
240
-		static $lookup = array(
241
-			0 =>  5500,
242
-			1 => 11025,
243
-			2 => 22050,
244
-			3 => 44100,
245
-		);
246
-		return (@$lookup[$id] ? @$lookup[$id] : false);
247
-	}
248
-
249
-
250
-	public static function FLVaudioBitDepth($id) {
251
-
252
-		static $lookup = array(
253
-			0 =>  8,
254
-			1 => 16,
255
-		);
256
-		return (@$lookup[$id] ? @$lookup[$id] : false);
257
-	}
258
-
259
-
260
-	public static function FLVvideoCodec($id) {
261
-
262
-		static $lookup = array(
263
-			getid3_flv::VIDEO_H263   => 'Sorenson H.263',
264
-			getid3_flv::VIDEO_SCREEN => 'Screen video',
265
-			getid3_flv::VIDEO_VP6    => 'On2 VP6',
266
-		);
267
-		return (@$lookup[$id] ? @$lookup[$id] : false);
268
-	}
79
+        $frame_size_data_length = getid3_lib::BigEndian2Int(fread($this->getid3->fp, 4));
80
+        $flv_header_frame_length = 9;
81
+        if ($frame_size_data_length > $flv_header_frame_length) {
82
+            fseek($this->getid3->fp, $frame_size_data_length - $flv_header_frame_length, SEEK_CUR);
83
+        }
84
+
85
+        $duration = 0;
86
+        while ((ftell($this->getid3->fp) + 1) < $info['avdataend']) {
87
+
88
+            $this_tag_header = fread($this->getid3->fp, 16);
89
+
90
+            $previous_tag_length = getid3_lib::BigEndian2Int(substr($this_tag_header,  0, 4));
91
+            $tag_type            = getid3_lib::BigEndian2Int(substr($this_tag_header,  4, 1));
92
+            $data_length         = getid3_lib::BigEndian2Int(substr($this_tag_header,  5, 3));
93
+            $timestamp           = getid3_lib::BigEndian2Int(substr($this_tag_header,  8, 3));
94
+            $last_header_byte    = getid3_lib::BigEndian2Int(substr($this_tag_header, 15, 1));
95
+            $next_offset         = ftell($this->getid3->fp) - 1 + $data_length;
96
+
97
+            switch ($tag_type) {
98
+
99
+                case getid3_flv::TAG_AUDIO:
100
+                    if (!isset($info_flv['audio']['audioFormat'])) {
101
+                        $info_flv['audio']['audioFormat']     =  $last_header_byte & 0x07;
102
+                        $info_flv['audio']['audioRate']       = ($last_header_byte & 0x30) / 0x10;
103
+                        $info_flv['audio']['audioSampleSize'] = ($last_header_byte & 0x40) / 0x40;
104
+                        $info_flv['audio']['audioType']       = ($last_header_byte & 0x80) / 0x80;
105
+                    }
106
+                    break;
107
+
108
+
109
+                case getid3_flv::TAG_VIDEO:
110
+                    if (!isset($info_flv['video']['videoCodec'])) {
111
+                        $info_flv['video']['videoCodec'] = $last_header_byte & 0x07;
112
+
113
+                        $flv_video_header = fread($this->getid3->fp, 11);
114
+
115
+                        if ($info_flv['video']['videoCodec'] != getid3_flv::VIDEO_VP6) {
116
+
117
+                            $picture_size_type = (getid3_lib::BigEndian2Int(substr($flv_video_header, 3, 2))) >> 7;
118
+                            $picture_size_type = $picture_size_type & 0x0007;
119
+                            $info_flv['header']['videoSizeType'] = $picture_size_type;
120
+
121
+                            switch ($picture_size_type) {
122
+                                case 0:
123
+                                    $picture_size_enc = getid3_lib::BigEndian2Int(substr($flv_video_header, 5, 2));
124
+                                    $picture_size_enc <<= 1;
125
+                                    $info['video']['resolution_x'] = ($picture_size_enc & 0xFF00) >> 8;
126
+                                    $picture_size_enc = getid3_lib::BigEndian2Int(substr($flv_video_header, 6, 2));
127
+                                    $picture_size_enc <<= 1;
128
+                                    $info['video']['resolution_y'] = ($picture_size_enc & 0xFF00) >> 8;
129
+                                    break;
130
+
131
+                                case 1:
132
+                                    $picture_size_enc = getid3_lib::BigEndian2Int(substr($flv_video_header, 5, 4));
133
+                                    $picture_size_enc <<= 1;
134
+                                    $info['video']['resolution_x'] = ($picture_size_enc & 0xFFFF0000) >> 16;
135
+
136
+                                    $picture_size_enc = getid3_lib::BigEndian2Int(substr($flv_video_header, 7, 4));
137
+                                    $picture_size_enc <<= 1;
138
+                                    $info['video']['resolution_y'] = ($picture_size_enc & 0xFFFF0000) >> 16;
139
+                                    break;
140
+
141
+                                case 2:
142
+                                    $info['video']['resolution_x'] = 352;
143
+                                    $info['video']['resolution_y'] = 288;
144
+                                    break;
145
+
146
+                                case 3:
147
+                                    $info['video']['resolution_x'] = 176;
148
+                                    $info['video']['resolution_y'] = 144;
149
+                                    break;
150
+
151
+                                case 4:
152
+                                    $info['video']['resolution_x'] = 128;
153
+                                    $info['video']['resolution_y'] = 96;
154
+                                    break;
155
+
156
+                                case 5:
157
+                                    $info['video']['resolution_x'] = 320;
158
+                                    $info['video']['resolution_y'] = 240;
159
+                                    break;
160
+
161
+                                case 6:
162
+                                    $info['video']['resolution_x'] = 160;
163
+                                    $info['video']['resolution_y'] = 120;
164
+                                    break;
165
+
166
+                                default:
167
+                                    $info['video']['resolution_x'] = 0;
168
+                                    $info['video']['resolution_y'] = 0;
169
+                                    break;
170
+                            }
171
+                        }
172
+                    }
173
+                    break;
174
+
175
+
176
+                // Meta tag
177
+                case getid3_flv::TAG_META:
178
+
179
+                    fseek($this->getid3->fp, -1, SEEK_CUR);
180
+                    $reader = new AMFReader(new AMFStream(fread($this->getid3->fp, $data_length)));
181
+                    $event_name = $reader->readData();
182
+                    $info['meta'][$event_name] = $reader->readData();
183
+                    unset($reader);
184
+
185
+                    $info['video']['frame_rate']   = @$info['meta']['onMetaData']['framerate'];
186
+                    $info['video']['resolution_x'] = @$info['meta']['onMetaData']['width'];
187
+                    $info['video']['resolution_y'] = @$info['meta']['onMetaData']['height'];
188
+                    break;
189
+
190
+                default:
191
+                    // noop
192
+                    break;
193
+            }
194
+
195
+            if ($timestamp > $duration) {
196
+                $duration = $timestamp;
197
+            }
198
+
199
+            fseek($this->getid3->fp, $next_offset, SEEK_SET);
200
+        }
201
+
202
+        if ($info['playtime_seconds'] = $duration / 1000) {
203
+            $info['bitrate'] = ($info['avdataend'] - $info['avdataoffset']) / $info['playtime_seconds'];
204
+        }
205
+
206
+        if ($info_flv['header']['hasAudio']) {
207
+            $info['audio']['codec']           = $this->FLVaudioFormat($info_flv['audio']['audioFormat']);
208
+            $info['audio']['sample_rate']     = $this->FLVaudioRate($info_flv['audio']['audioRate']);
209
+            $info['audio']['bits_per_sample'] = $this->FLVaudioBitDepth($info_flv['audio']['audioSampleSize']);
210
+
211
+            $info['audio']['channels']   = $info_flv['audio']['audioType'] + 1; // 0=mono,1=stereo
212
+            $info['audio']['lossless']   = ($info_flv['audio']['audioFormat'] ? false : true); // 0=uncompressed
213
+            $info['audio']['dataformat'] = 'flv';
214
+        }
215
+        if (@$info_flv['header']['hasVideo']) {
216
+            $info['video']['codec']      = $this->FLVvideoCodec($info_flv['video']['videoCodec']);
217
+            $info['video']['dataformat'] = 'flv';
218
+            $info['video']['lossless']   = false;
219
+        }
220
+
221
+        return true;
222
+    }
223
+
224
+
225
+    public static function FLVaudioFormat($id) {
226
+
227
+        static $lookup = array(
228
+            0 => 'uncompressed',
229
+            1 => 'ADPCM',
230
+            2 => 'mp3',
231
+            5 => 'Nellymoser 8kHz mono',
232
+            6 => 'Nellymoser',
233
+        );
234
+        return (@$lookup[$id] ? @$lookup[$id] : false);
235
+    }
236
+
237
+
238
+    public static function FLVaudioRate($id) {
239
+
240
+        static $lookup = array(
241
+            0 =>  5500,
242
+            1 => 11025,
243
+            2 => 22050,
244
+            3 => 44100,
245
+        );
246
+        return (@$lookup[$id] ? @$lookup[$id] : false);
247
+    }
248
+
249
+
250
+    public static function FLVaudioBitDepth($id) {
251
+
252
+        static $lookup = array(
253
+            0 =>  8,
254
+            1 => 16,
255
+        );
256
+        return (@$lookup[$id] ? @$lookup[$id] : false);
257
+    }
258
+
259
+
260
+    public static function FLVvideoCodec($id) {
261
+
262
+        static $lookup = array(
263
+            getid3_flv::VIDEO_H263   => 'Sorenson H.263',
264
+            getid3_flv::VIDEO_SCREEN => 'Screen video',
265
+            getid3_flv::VIDEO_VP6    => 'On2 VP6',
266
+        );
267
+        return (@$lookup[$id] ? @$lookup[$id] : false);
268
+    }
269 269
 }
270 270
 
271 271
 
272 272
 
273 273
 class AMFStream
274 274
 {
275
-	public $bytes;
276
-	public $pos;
275
+    public $bytes;
276
+    public $pos;
277 277
 
278 278
 
279
-	public function AMFStream($bytes) {
279
+    public function AMFStream($bytes) {
280 280
 
281
-		$this->bytes = $bytes;
282
-		$this->pos = 0;
283
-	}
281
+        $this->bytes = $bytes;
282
+        $this->pos = 0;
283
+    }
284 284
 
285 285
 
286
-	public function readByte() {
286
+    public function readByte() {
287 287
 
288
-		return getid3_lib::BigEndian2Int(substr($this->bytes, $this->pos++, 1));
289
-	}
288
+        return getid3_lib::BigEndian2Int(substr($this->bytes, $this->pos++, 1));
289
+    }
290 290
 
291 291
 
292
-	public function readInt() {
292
+    public function readInt() {
293 293
 
294
-		return ($this->readByte() << 8) + $this->readByte();
295
-	}
294
+        return ($this->readByte() << 8) + $this->readByte();
295
+    }
296 296
 
297 297
 
298
-	public function readLong() {
298
+    public function readLong() {
299 299
 
300
-		return ($this->readByte() << 24) + ($this->readByte() << 16) + ($this->readByte() << 8) + $this->readByte();
301
-	}
300
+        return ($this->readByte() << 24) + ($this->readByte() << 16) + ($this->readByte() << 8) + $this->readByte();
301
+    }
302 302
 
303 303
 
304
-	public function readDouble() {
304
+    public function readDouble() {
305 305
 
306
-		return getid3_lib::BigEndian2Float($this->read(8));
307
-	}
306
+        return getid3_lib::BigEndian2Float($this->read(8));
307
+    }
308 308
 
309 309
 
310
-	public function readUTF() {
310
+    public function readUTF() {
311 311
 
312
-		$length = $this->readInt();
313
-		return $this->read($length);
314
-	}
312
+        $length = $this->readInt();
313
+        return $this->read($length);
314
+    }
315 315
 
316 316
 
317
-	public function readLongUTF() {
317
+    public function readLongUTF() {
318 318
 
319
-		$length = $this->readLong();
320
-		return $this->read($length);
321
-	}
319
+        $length = $this->readLong();
320
+        return $this->read($length);
321
+    }
322 322
 
323 323
 
324
-	public function read($length) {
324
+    public function read($length) {
325 325
 
326
-		$val = substr($this->bytes, $this->pos, $length);
327
-		$this->pos += $length;
328
-		return $val;
329
-	}
326
+        $val = substr($this->bytes, $this->pos, $length);
327
+        $this->pos += $length;
328
+        return $val;
329
+    }
330 330
 
331 331
 
332
-	public function peekByte() {
332
+    public function peekByte() {
333 333
 
334
-		$pos = $this->pos;
335
-		$val = $this->readByte();
336
-		$this->pos = $pos;
337
-		return $val;
338
-	}
334
+        $pos = $this->pos;
335
+        $val = $this->readByte();
336
+        $this->pos = $pos;
337
+        return $val;
338
+    }
339 339
 
340 340
 
341
-	public function peekInt() {
341
+    public function peekInt() {
342 342
 
343
-		$pos = $this->pos;
344
-		$val = $this->readInt();
345
-		$this->pos = $pos;
346
-		return $val;
347
-	}
343
+        $pos = $this->pos;
344
+        $val = $this->readInt();
345
+        $this->pos = $pos;
346
+        return $val;
347
+    }
348 348
 
349 349
 
350
-	public function peekLong() {
350
+    public function peekLong() {
351 351
 
352
-		$pos = $this->pos;
353
-		$val = $this->readLong();
354
-		$this->pos = $pos;
355
-		return $val;
356
-	}
352
+        $pos = $this->pos;
353
+        $val = $this->readLong();
354
+        $this->pos = $pos;
355
+        return $val;
356
+    }
357 357
 
358 358
 
359
-	public function peekDouble() {
359
+    public function peekDouble() {
360 360
 
361
-		$pos = $this->pos;
362
-		$val = $this->readDouble();
363
-		$this->pos = $pos;
364
-		return $val;
365
-	}
361
+        $pos = $this->pos;
362
+        $val = $this->readDouble();
363
+        $this->pos = $pos;
364
+        return $val;
365
+    }
366 366
 
367 367
 
368
-	public function peekUTF() {
368
+    public function peekUTF() {
369 369
 
370
-		$pos = $this->pos;
371
-		$val = $this->readUTF();
372
-		$this->pos = $pos;
373
-		return $val;
374
-	}
370
+        $pos = $this->pos;
371
+        $val = $this->readUTF();
372
+        $this->pos = $pos;
373
+        return $val;
374
+    }
375 375
 
376 376
 
377
-	public function peekLongUTF() {
377
+    public function peekLongUTF() {
378 378
 
379
-		$pos = $this->pos;
380
-		$val = $this->readLongUTF();
381
-		$this->pos = $pos;
382
-		return $val;
383
-	}
379
+        $pos = $this->pos;
380
+        $val = $this->readLongUTF();
381
+        $this->pos = $pos;
382
+        return $val;
383
+    }
384 384
 }
385 385
 
386 386
 
387 387
 
388 388
 class AMFReader
389 389
 {
390
-	public $stream;
390
+    public $stream;
391 391
 
392
-	public function __construct($stream) {
392
+    public function __construct($stream) {
393 393
 
394
-		$this->stream = $stream;
395
-	}
394
+        $this->stream = $stream;
395
+    }
396 396
 
397 397
 
398
-	public function readData() {
398
+    public function readData() {
399 399
 
400
-		$value = null;
400
+        $value = null;
401 401
 
402
-		$type = $this->stream->readByte();
402
+        $type = $this->stream->readByte();
403 403
 
404
-		switch($type) {
405
-			// Double
406
-			case 0:
407
-				$value = $this->readDouble();
408
-			break;
404
+        switch($type) {
405
+            // Double
406
+            case 0:
407
+                $value = $this->readDouble();
408
+            break;
409 409
 
410
-			// Boolean
411
-			case 1:
412
-				$value = $this->readBoolean();
413
-				break;
410
+            // Boolean
411
+            case 1:
412
+                $value = $this->readBoolean();
413
+                break;
414 414
 
415
-			// String
416
-			case 2:
417
-				$value = $this->readString();
418
-				break;
415
+            // String
416
+            case 2:
417
+                $value = $this->readString();
418
+                break;
419 419
 
420
-			// Object
421
-			case 3:
422
-				$value = $this->readObject();
423
-				break;
420
+            // Object
421
+            case 3:
422
+                $value = $this->readObject();
423
+                break;
424 424
 
425
-			// null
426
-			case 6:
427
-				return null;
428
-				break;
425
+            // null
426
+            case 6:
427
+                return null;
428
+                break;
429 429
 
430
-			// Mixed array
431
-			case 8:
432
-				$value = $this->readMixedArray();
433
-				break;
430
+            // Mixed array
431
+            case 8:
432
+                $value = $this->readMixedArray();
433
+                break;
434 434
 
435
-			// Array
436
-			case 10:
437
-				$value = $this->readArray();
438
-				break;
435
+            // Array
436
+            case 10:
437
+                $value = $this->readArray();
438
+                break;
439 439
 
440
-			// Date
441
-			case 11:
442
-				$value = $this->readDate();
443
-				break;
440
+            // Date
441
+            case 11:
442
+                $value = $this->readDate();
443
+                break;
444 444
 
445
-			// Long string
446
-			case 13:
447
-				$value = $this->readLongString();
448
-				break;
445
+            // Long string
446
+            case 13:
447
+                $value = $this->readLongString();
448
+                break;
449 449
 
450
-			// XML (handled as string)
451
-			case 15:
452
-				$value = $this->readXML();
453
-				break;
450
+            // XML (handled as string)
451
+            case 15:
452
+                $value = $this->readXML();
453
+                break;
454 454
 
455
-			// Typed object (handled as object)
456
-			case 16:
457
-				$value = $this->readTypedObject();
458
-				break;
455
+            // Typed object (handled as object)
456
+            case 16:
457
+                $value = $this->readTypedObject();
458
+                break;
459 459
 
460
-			// Long string
461
-			default:
462
-				$value = '(unknown or unsupported data type)';
463
-			break;
464
-		}
460
+            // Long string
461
+            default:
462
+                $value = '(unknown or unsupported data type)';
463
+            break;
464
+        }
465 465
 
466
-		return $value;
467
-	}
466
+        return $value;
467
+    }
468 468
 
469 469
 
470
-	public function readDouble() {
470
+    public function readDouble() {
471 471
 
472
-		return $this->stream->readDouble();
473
-	}
472
+        return $this->stream->readDouble();
473
+    }
474 474
 
475 475
 
476
-	public function readBoolean() {
476
+    public function readBoolean() {
477 477
 
478
-		return $this->stream->readByte() == 1;
479
-	}
478
+        return $this->stream->readByte() == 1;
479
+    }
480 480
 
481 481
 
482
-	public function readString() {
482
+    public function readString() {
483 483
 
484
-		return $this->stream->readUTF();
485
-	}
484
+        return $this->stream->readUTF();
485
+    }
486 486
 
487 487
 
488
-	public function readObject() {
488
+    public function readObject() {
489 489
 
490
-		// Get highest numerical index - ignored
491
-		$highestIndex = $this->stream->readLong();
490
+        // Get highest numerical index - ignored
491
+        $highestIndex = $this->stream->readLong();
492 492
 
493
-		$data = array();
493
+        $data = array();
494 494
 
495
-		while ($key = $this->stream->readUTF()) {
496
-			// Mixed array record ends with empty string (0x00 0x00) and 0x09
497
-			if (($key == '') && ($this->stream->peekByte() == 0x09)) {
498
-				// Consume byte
499
-				$this->stream->readByte();
500
-				break;
501
-			}
495
+        while ($key = $this->stream->readUTF()) {
496
+            // Mixed array record ends with empty string (0x00 0x00) and 0x09
497
+            if (($key == '') && ($this->stream->peekByte() == 0x09)) {
498
+                // Consume byte
499
+                $this->stream->readByte();
500
+                break;
501
+            }
502 502
 
503
-			$data[$key] = $this->readData();
504
-		}
503
+            $data[$key] = $this->readData();
504
+        }
505 505
 
506
-		return $data;
507
-	}
506
+        return $data;
507
+    }
508 508
 
509 509
 
510
-	public function readMixedArray() {
510
+    public function readMixedArray() {
511 511
 
512
-		// Get highest numerical index - ignored
513
-		$highestIndex = $this->stream->readLong();
512
+        // Get highest numerical index - ignored
513
+        $highestIndex = $this->stream->readLong();
514 514
 
515
-		$data = array();
515
+        $data = array();
516 516
 
517
-		while ($key = $this->stream->readUTF()) {
518
-			// Mixed array record ends with empty string (0x00 0x00) and 0x09
519
-			if (($key == '') && ($this->stream->peekByte() == 0x09)) {
520
-				// Consume byte
521
-				$this->stream->readByte();
522
-				break;
523
-			}
517
+        while ($key = $this->stream->readUTF()) {
518
+            // Mixed array record ends with empty string (0x00 0x00) and 0x09
519
+            if (($key == '') && ($this->stream->peekByte() == 0x09)) {
520
+                // Consume byte
521
+                $this->stream->readByte();
522
+                break;
523
+            }
524 524
 
525
-			if (is_numeric($key)) {
526
-				$key = (float) $key;
527
-			}
525
+            if (is_numeric($key)) {
526
+                $key = (float) $key;
527
+            }
528 528
 
529
-			$data[$key] = $this->readData();
530
-		}
529
+            $data[$key] = $this->readData();
530
+        }
531 531
 
532
-		return $data;
533
-	}
532
+        return $data;
533
+    }
534 534
 
535 535
 
536
-	public function readArray() {
536
+    public function readArray() {
537 537
 
538
-		$length = $this->stream->readLong();
538
+        $length = $this->stream->readLong();
539 539
 
540
-		$data = array();
540
+        $data = array();
541 541
 
542
-		for ($i = 0; $i < count($length); $i++) {
543
-			$data[] = $this->readData();
544
-		}
542
+        for ($i = 0; $i < count($length); $i++) {
543
+            $data[] = $this->readData();
544
+        }
545 545
 
546
-		return $data;
547
-	}
546
+        return $data;
547
+    }
548 548
 
549 549
 
550
-	public function readDate() {
550
+    public function readDate() {
551 551
 
552
-		$timestamp = $this->stream->readDouble();
553
-		$timezone = $this->stream->readInt();
554
-		return $timestamp;
555
-	}
552
+        $timestamp = $this->stream->readDouble();
553
+        $timezone = $this->stream->readInt();
554
+        return $timestamp;
555
+    }
556 556
 
557 557
 
558
-	public function readLongString() {
558
+    public function readLongString() {
559 559
 
560
-		return $this->stream->readLongUTF();
561
-	}
560
+        return $this->stream->readLongUTF();
561
+    }
562 562
 
563 563
 
564
-	public function readXML() {
564
+    public function readXML() {
565 565
 
566
-		return $this->stream->readLongUTF();
567
-	}
566
+        return $this->stream->readLongUTF();
567
+    }
568 568
 
569 569
 
570
-	public function readTypedObject() {
570
+    public function readTypedObject() {
571 571
 
572
-		$className = $this->stream->readUTF();
573
-		return $this->readObject();
574
-	}
572
+        $className = $this->stream->readUTF();
573
+        return $this->readObject();
574
+    }
575 575
 }
576 576
 
577 577
 ?>
Please login to merge, or discard this patch.
main/inc/lib/getid3/getid3.php 1 patch
Indentation   +165 added lines, -165 removed lines patch added patch discarded remove patch
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
         $class = new $class_name($this);
301 301
 
302 302
         try {
303
-             $this->option_analyze and $class->Analyze();
303
+                $this->option_analyze and $class->Analyze();
304 304
             }
305 305
         catch (getid3_exception $e) {
306 306
             throw $e;
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
             // CalculateReplayGain() {
384 384
             if (@$this->info['replay_gain']) {
385 385
                 if (!@$this->info['replay_gain']['reference_volume']) {
386
-                     $this->info['replay_gain']['reference_volume'] = 89;
386
+                        $this->info['replay_gain']['reference_volume'] = 89;
387 387
                 }
388 388
                 if (isset($this->info['replay_gain']['track']['adjustment'])) {
389 389
                     $this->info['replay_gain']['track']['volume'] = $this->info['replay_gain']['reference_volume'] - $this->info['replay_gain']['track']['adjustment'];
@@ -403,7 +403,7 @@  discard block
 block discarded – undo
403 403
 
404 404
             // ProcessAudioStreams() {
405 405
             if (@!$this->info['audio']['streams'] && (@$this->info['audio']['bitrate'] || @$this->info['audio']['channels'] || @$this->info['audio']['sample_rate'])) {
406
-                  foreach ($this->info['audio'] as $key => $value) {
406
+                    foreach ($this->info['audio'] as $key => $value) {
407 407
                     if ($key != 'streams') {
408 408
                         $this->info['audio']['streams'][0][$key] = $value;
409 409
                     }
@@ -544,7 +544,7 @@  discard block
 block discarded – undo
544 544
                             'group'     => 'audio',
545 545
                             'module'    => 'ac3',
546 546
                             'mime_type' => 'audio/ac3',
547
-                          ),
547
+                            ),
548 548
 
549 549
                 // AAC  - audio       - Advanced Audio Coding (AAC) - ADIF format
550 550
                 'adif' => array (
@@ -553,7 +553,7 @@  discard block
 block discarded – undo
553 553
                             'module'    => 'aac_adif',
554 554
                             'mime_type' => 'application/octet-stream',
555 555
                             'fail_ape'  => 'WARNING',
556
-                          ),
556
+                            ),
557 557
 
558 558
 
559 559
                 // AAC  - audio       - Advanced Audio Coding (AAC) - ADTS format (very similar to MP3)
@@ -563,7 +563,7 @@  discard block
 block discarded – undo
563 563
                             'module'    => 'aac_adts',
564 564
                             'mime_type' => 'application/octet-stream',
565 565
                             'fail_ape'  => 'WARNING',
566
-                          ),
566
+                            ),
567 567
 
568 568
 
569 569
                 // AU   - audio       - NeXT/Sun AUdio (AU)
@@ -572,7 +572,7 @@  discard block
 block discarded – undo
572 572
                             'group'     => 'audio',
573 573
                             'module'    => 'au',
574 574
                             'mime_type' => 'audio/basic',
575
-                          ),
575
+                            ),
576 576
 
577 577
                 // AVR  - audio       - Audio Visual Research
578 578
                 'avr'  => array (
@@ -580,7 +580,7 @@  discard block
 block discarded – undo
580 580
                             'group'     => 'audio',
581 581
                             'module'    => 'avr',
582 582
                             'mime_type' => 'application/octet-stream',
583
-                          ),
583
+                            ),
584 584
 
585 585
                 // BONK - audio       - Bonk v0.9+
586 586
                 'bonk' => array (
@@ -588,15 +588,15 @@  discard block
 block discarded – undo
588 588
                             'group'     => 'audio',
589 589
                             'module'    => 'bonk',
590 590
                             'mime_type' => 'audio/xmms-bonk',
591
-                          ),
591
+                            ),
592 592
 
593 593
                 // DTS  - audio       - Dolby Theatre System
594
-				'dts'  => array(
595
-							'pattern'   => '^\x7F\xFE\x80\x01',
596
-							'group'     => 'audio',
597
-							'module'    => 'dts',
598
-							'mime_type' => 'audio/dts',
599
-						),
594
+                'dts'  => array(
595
+                            'pattern'   => '^\x7F\xFE\x80\x01',
596
+                            'group'     => 'audio',
597
+                            'module'    => 'dts',
598
+                            'mime_type' => 'audio/dts',
599
+                        ),
600 600
 
601 601
                 // FLAC - audio       - Free Lossless Audio Codec
602 602
                 'flac' => array (
@@ -604,7 +604,7 @@  discard block
 block discarded – undo
604 604
                             'group'     => 'audio',
605 605
                             'module'    => 'xiph',
606 606
                             'mime_type' => 'audio/x-flac',
607
-                          ),
607
+                            ),
608 608
 
609 609
                 // LA   - audio       - Lossless Audio (LA)
610 610
                 'la'   => array (
@@ -612,7 +612,7 @@  discard block
 block discarded – undo
612 612
                             'group'     => 'audio',
613 613
                             'module'    => 'la',
614 614
                             'mime_type' => 'application/octet-stream',
615
-                          ),
615
+                            ),
616 616
 
617 617
                 // LPAC - audio       - Lossless Predictive Audio Compression (LPAC)
618 618
                 'lpac' => array (
@@ -620,7 +620,7 @@  discard block
 block discarded – undo
620 620
                             'group'     => 'audio',
621 621
                             'module'    => 'lpac',
622 622
                             'mime_type' => 'application/octet-stream',
623
-                          ),
623
+                            ),
624 624
 
625 625
                 // MIDI - audio       - MIDI (Musical Instrument Digital Interface)
626 626
                 'midi' => array (
@@ -628,7 +628,7 @@  discard block
 block discarded – undo
628 628
                             'group'     => 'audio',
629 629
                             'module'    => 'midi',
630 630
                             'mime_type' => 'audio/midi',
631
-                          ),
631
+                            ),
632 632
 
633 633
                 // MAC  - audio       - Monkey's Audio Compressor
634 634
                 'mac'  => array (
@@ -636,31 +636,31 @@  discard block
 block discarded – undo
636 636
                             'group'     => 'audio',
637 637
                             'module'    => 'monkey',
638 638
                             'mime_type' => 'application/octet-stream',
639
-                          ),
639
+                            ),
640 640
 
641 641
                 // MOD  - audio       - MODule (assorted sub-formats)
642 642
                 'mod'  => array (
643 643
                             'pattern'   => '^.{1080}(M.K.|[5-9]CHN|[1-3][0-9]CH)',
644 644
                             'mime_type' => 'audio/mod',
645
-                          ),
645
+                            ),
646 646
 
647 647
                 // MOD  - audio       - MODule (Impulse Tracker)
648 648
                 'it'   => array (
649 649
                             'pattern'   => '^IMPM',
650 650
                             'mime_type' => 'audio/it',
651
-                          ),
651
+                            ),
652 652
 
653 653
                 // MOD  - audio       - MODule (eXtended Module, various sub-formats)
654 654
                 'xm'   => array (
655 655
                             'pattern'   => '^Extended Module',
656 656
                             'mime_type' => 'audio/xm',
657
-                          ),
657
+                            ),
658 658
 
659 659
                 // MOD  - audio       - MODule (ScreamTracker)
660 660
                 's3m'  => array (
661 661
                             'pattern'   => '^.{44}SCRM',
662 662
                             'mime_type' => 'audio/s3m',
663
-                          ),
663
+                            ),
664 664
 
665 665
                 // MPC  - audio       - Musepack / MPEGplus SV7+
666 666
                 'mpc'  => array (
@@ -668,7 +668,7 @@  discard block
 block discarded – undo
668 668
                             'group'     => 'audio',
669 669
                             'module'    => 'mpc',
670 670
                             'mime_type' => 'audio/x-musepack',
671
-                          ),
671
+                            ),
672 672
 
673 673
                 // MPC  - audio       - Musepack / MPEGplus SV4-6
674 674
                 'mpc_old' => array (
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
                             'group'     => 'audio',
677 677
                             'module'    => 'mpc_old',
678 678
                             'mime_type' => 'application/octet-stream',
679
-                          ),
679
+                            ),
680 680
 
681 681
 
682 682
                 // MP3  - audio       - MPEG-audio Layer 3 (very similar to AAC-ADTS)
@@ -685,7 +685,7 @@  discard block
 block discarded – undo
685 685
                             'group'     => 'audio',
686 686
                             'module'    => 'mp3',
687 687
                             'mime_type' => 'audio/mpeg',
688
-                          ),
688
+                            ),
689 689
 
690 690
                 // OFR  - audio       - OptimFROG
691 691
                 'ofr'  => array (
@@ -693,7 +693,7 @@  discard block
 block discarded – undo
693 693
                             'group'     => 'audio',
694 694
                             'module'    => 'optimfrog',
695 695
                             'mime_type' => 'application/octet-stream',
696
-                          ),
696
+                            ),
697 697
 
698 698
                 // RKAU - audio       - RKive AUdio compressor
699 699
                 'rkau' => array (
@@ -701,7 +701,7 @@  discard block
 block discarded – undo
701 701
                             'group'     => 'audio',
702 702
                             'module'    => 'rkau',
703 703
                             'mime_type' => 'application/octet-stream',
704
-                          ),
704
+                            ),
705 705
 
706 706
                 // SHN  - audio       - Shorten
707 707
                 'shn'  => array (
@@ -711,7 +711,7 @@  discard block
 block discarded – undo
711 711
                             'mime_type' => 'audio/xmms-shn',
712 712
                             'fail_id3'  => 'ERROR',
713 713
                             'fail_ape'  => 'ERROR',
714
-                          ),
714
+                            ),
715 715
 
716 716
                 // TTA  - audio       - TTA Lossless Audio Compressor (http://tta.corecodec.org)
717 717
                 'tta'  => array (
@@ -719,7 +719,7 @@  discard block
 block discarded – undo
719 719
                             'group'     => 'audio',
720 720
                             'module'    => 'tta',
721 721
                             'mime_type' => 'application/octet-stream',
722
-                          ),
722
+                            ),
723 723
 
724 724
                 // VOC  - audio       - Creative Voice (VOC)
725 725
                 'voc'  => array (
@@ -727,7 +727,7 @@  discard block
 block discarded – undo
727 727
                             'group'     => 'audio',
728 728
                             'module'    => 'voc',
729 729
                             'mime_type' => 'audio/voc',
730
-                          ),
730
+                            ),
731 731
 
732 732
                 // VQF  - audio       - transform-domain weighted interleave Vector Quantization Format (VQF)
733 733
                 'vqf'  => array (
@@ -735,7 +735,7 @@  discard block
 block discarded – undo
735 735
                             'group'     => 'audio',
736 736
                             'module'    => 'vqf',
737 737
                             'mime_type' => 'application/octet-stream',
738
-                          ),
738
+                            ),
739 739
 
740 740
                 // WV  - audio        - WavPack (v4.0+)
741 741
                 'vw'  => array(
@@ -743,7 +743,7 @@  discard block
 block discarded – undo
743 743
                             'group'     => 'audio',
744 744
                             'module'    => 'wavpack',
745 745
                             'mime_type' => 'application/octet-stream',
746
-                          ),
746
+                            ),
747 747
 
748 748
 
749 749
                 // Audio-Video formats
@@ -754,13 +754,13 @@  discard block
 block discarded – undo
754 754
                             'group'     => 'audio-video',
755 755
                             'module'    => 'asf',
756 756
                             'mime_type' => 'video/x-ms-asf',
757
-                          ),
757
+                            ),
758 758
 
759 759
                 // BINK  - audio/video - Bink / Smacker
760 760
                 'bink' => array(
761 761
                             'pattern'   => '^(BIK|SMK)',
762 762
                             'mime_type' => 'application/octet-stream',
763
-                          ),
763
+                            ),
764 764
 
765 765
                 // FLV  - audio/video - FLash Video
766 766
                 'flv' => array(
@@ -768,13 +768,13 @@  discard block
 block discarded – undo
768 768
                             'group'     => 'audio-video',
769 769
                             'module'    => 'flv',
770 770
                             'mime_type' => 'video/x-flv',
771
-                          ),
771
+                            ),
772 772
 
773 773
                 // MKAV - audio/video - Mastroka
774 774
                 'matroska' => array (
775 775
                             'pattern'   => '^\x1A\x45\xDF\xA3',
776 776
                             'mime_type' => 'application/octet-stream',
777
-                          ),
777
+                            ),
778 778
 
779 779
                 // MPEG - audio/video - MPEG (Moving Pictures Experts Group)
780 780
                 'mpeg' => array (
@@ -782,7 +782,7 @@  discard block
 block discarded – undo
782 782
                             'group'     => 'audio-video',
783 783
                             'module'    => 'mpeg',
784 784
                             'mime_type' => 'video/mpeg',
785
-                          ),
785
+                            ),
786 786
 
787 787
                 // NSV  - audio/video - Nullsoft Streaming Video (NSV)
788 788
                 'nsv'  => array (
@@ -790,7 +790,7 @@  discard block
 block discarded – undo
790 790
                             'group'     => 'audio-video',
791 791
                             'module'    => 'nsv',
792 792
                             'mime_type' => 'application/octet-stream',
793
-                          ),
793
+                            ),
794 794
 
795 795
                 // Ogg  - audio/video - Ogg (Ogg Vorbis, OggFLAC, Speex, Ogg Theora(*), Ogg Tarkin(*))
796 796
                 'ogg'  => array (
@@ -800,7 +800,7 @@  discard block
 block discarded – undo
800 800
                             'mime_type' => 'application/ogg',
801 801
                             'fail_id3'  => 'WARNING',
802 802
                             'fail_ape'  => 'WARNING',
803
-                          ),
803
+                            ),
804 804
 
805 805
                 // QT   - audio/video - Quicktime
806 806
                 'quicktime' => array (
@@ -808,7 +808,7 @@  discard block
 block discarded – undo
808 808
                             'group'     => 'audio-video',
809 809
                             'module'    => 'quicktime',
810 810
                             'mime_type' => 'video/quicktime',
811
-                          ),
811
+                            ),
812 812
 
813 813
                 // RIFF - audio/video - Resource Interchange File Format (RIFF) / WAV / AVI / CD-audio / SDSS = renamed variant used by SmartSound QuickTracks (www.smartsound.com) / FORM = Audio Interchange File Format (AIFF)
814 814
                 'riff' => array (
@@ -817,7 +817,7 @@  discard block
 block discarded – undo
817 817
                             'module'    => 'riff',
818 818
                             'mime_type' => 'audio/x-wave',
819 819
                             'fail_ape'  => 'WARNING',
820
-                          ),
820
+                            ),
821 821
 
822 822
                 // Real - audio/video - RealAudio, RealVideo
823 823
                 'real' => array (
@@ -825,7 +825,7 @@  discard block
 block discarded – undo
825 825
                             'group'     => 'audio-video',
826 826
                             'module'    => 'real',
827 827
                             'mime_type' => 'audio/x-realaudio',
828
-                          ),
828
+                            ),
829 829
 
830 830
                 // SWF - audio/video - ShockWave Flash
831 831
                 'swf' => array (
@@ -833,7 +833,7 @@  discard block
 block discarded – undo
833 833
                             'group'     => 'audio-video',
834 834
                             'module'    => 'swf',
835 835
                             'mime_type' => 'application/x-shockwave-flash',
836
-                          ),
836
+                            ),
837 837
 
838 838
 
839 839
                 // Still-Image formats
@@ -846,7 +846,7 @@  discard block
 block discarded – undo
846 846
                             'mime_type' => 'image/bmp',
847 847
                             'fail_id3'  => 'ERROR',
848 848
                             'fail_ape'  => 'ERROR',
849
-                          ),
849
+                            ),
850 850
 
851 851
                 // GIF  - still image - Graphics Interchange Format
852 852
                 'gif'  => array (
@@ -856,7 +856,7 @@  discard block
 block discarded – undo
856 856
                             'mime_type' => 'image/gif',
857 857
                             'fail_id3'  => 'ERROR',
858 858
                             'fail_ape'  => 'ERROR',
859
-                          ),
859
+                            ),
860 860
 
861 861
                 // JPEG - still image - Joint Photographic Experts Group (JPEG)
862 862
                 'jpeg'  => array (
@@ -866,7 +866,7 @@  discard block
 block discarded – undo
866 866
                             'mime_type' => 'image/jpeg',
867 867
                             'fail_id3'  => 'ERROR',
868 868
                             'fail_ape'  => 'ERROR',
869
-                          ),
869
+                            ),
870 870
 
871 871
                 // PCD  - still image - Kodak Photo CD
872 872
                 'pcd'  => array (
@@ -876,7 +876,7 @@  discard block
 block discarded – undo
876 876
                             'mime_type' => 'image/x-photo-cd',
877 877
                             'fail_id3'  => 'ERROR',
878 878
                             'fail_ape'  => 'ERROR',
879
-                          ),
879
+                            ),
880 880
 
881 881
 
882 882
                 // PNG  - still image - Portable Network Graphics (PNG)
@@ -887,16 +887,16 @@  discard block
 block discarded – undo
887 887
                             'mime_type' => 'image/png',
888 888
                             'fail_id3'  => 'ERROR',
889 889
                             'fail_ape'  => 'ERROR',
890
-                          ),
890
+                            ),
891 891
 
892 892
 
893 893
                 // SVG  - still image - Scalable Vector Graphics (SVG)
894
-				'svg'  => array(
895
-							'pattern'   => '<!DOCTYPE svg PUBLIC ',
896
-							'mime_type' => 'image/svg+xml',
897
-							'fail_id3'  => 'ERROR',
898
-							'fail_ape'  => 'ERROR',
899
-						),
894
+                'svg'  => array(
895
+                            'pattern'   => '<!DOCTYPE svg PUBLIC ',
896
+                            'mime_type' => 'image/svg+xml',
897
+                            'fail_id3'  => 'ERROR',
898
+                            'fail_ape'  => 'ERROR',
899
+                        ),
900 900
 
901 901
 
902 902
                 // TIFF  - still image - Tagged Information File Format (TIFF)
@@ -907,7 +907,7 @@  discard block
 block discarded – undo
907 907
                             'mime_type' => 'image/tiff',
908 908
                             'fail_id3'  => 'ERROR',
909 909
                             'fail_ape'  => 'ERROR',
910
-                          ),
910
+                            ),
911 911
 
912 912
 
913 913
                 // Data formats
@@ -917,7 +917,7 @@  discard block
 block discarded – undo
917 917
                             'mime_type' => 'application/octet-stream',
918 918
                             'fail_id3'  => 'ERROR',
919 919
                             'fail_ape'  => 'ERROR',
920
-                          ),
920
+                            ),
921 921
 
922 922
                 // ISO  - data        - International Standards Organization (ISO) CD-ROM Image
923 923
                 'iso'  => array (
@@ -927,7 +927,7 @@  discard block
 block discarded – undo
927 927
                             'mime_type' => 'application/octet-stream',
928 928
                             'fail_id3'  => 'ERROR',
929 929
                             'fail_ape'  => 'ERROR',
930
-                          ),
930
+                            ),
931 931
 
932 932
                 // RAR  - data        - RAR compressed data
933 933
                 'rar'  => array(
@@ -935,7 +935,7 @@  discard block
 block discarded – undo
935 935
                             'mime_type' => 'application/octet-stream',
936 936
                             'fail_id3'  => 'ERROR',
937 937
                             'fail_ape'  => 'ERROR',
938
-                          ),
938
+                            ),
939 939
 
940 940
                 // SZIP - audio       - SZIP compressed data
941 941
                 'szip' => array (
@@ -945,7 +945,7 @@  discard block
 block discarded – undo
945 945
                             'mime_type' => 'application/octet-stream',
946 946
                             'fail_id3'  => 'ERROR',
947 947
                             'fail_ape'  => 'ERROR',
948
-                          ),
948
+                            ),
949 949
 
950 950
                 // TAR  - data        - TAR compressed data
951 951
                 'tar'  => array(
@@ -955,7 +955,7 @@  discard block
 block discarded – undo
955 955
                             'mime_type' => 'application/x-tar',
956 956
                             'fail_id3'  => 'ERROR',
957 957
                             'fail_ape'  => 'ERROR',
958
-                          ),
958
+                            ),
959 959
 
960 960
                 // GZIP  - data        - GZIP compressed data
961 961
                 'gz'  => array(
@@ -965,7 +965,7 @@  discard block
 block discarded – undo
965 965
                             'mime_type' => 'application/x-gzip',
966 966
                             'fail_id3'  => 'ERROR',
967 967
                             'fail_ape'  => 'ERROR',
968
-                          ),
968
+                            ),
969 969
 
970 970
 
971 971
                 // ZIP  - data        - ZIP compressed data
@@ -976,33 +976,33 @@  discard block
 block discarded – undo
976 976
                             'mime_type' => 'application/zip',
977 977
                             'fail_id3'  => 'ERROR',
978 978
                             'fail_ape'  => 'ERROR',
979
-                          ),
979
+                            ),
980 980
 
981 981
 
982 982
                 // PAR2 - data        - Parity Volume Set Specification 2.0
983 983
                 'par2' => array (
984
-                			'pattern'   => '^PAR2\x00PKT',
985
-							'mime_type' => 'application/octet-stream',
986
-							'fail_id3'  => 'ERROR',
987
-							'fail_ape'  => 'ERROR',
988
-						),
984
+                            'pattern'   => '^PAR2\x00PKT',
985
+                            'mime_type' => 'application/octet-stream',
986
+                            'fail_id3'  => 'ERROR',
987
+                            'fail_ape'  => 'ERROR',
988
+                        ),
989 989
 
990 990
 
991
-                 // PDF  - data       - Portable Document Format
992
-                 'pdf' => array(
991
+                    // PDF  - data       - Portable Document Format
992
+                    'pdf' => array(
993 993
                             'pattern'   => '^\x25PDF',
994 994
                             'mime_type' => 'application/pdf',
995 995
                             'fail_id3'  => 'ERROR',
996 996
                             'fail_ape'  => 'ERROR',
997
-                           ),
997
+                            ),
998 998
 
999
-                 // DOC  - data       - Microsoft Word
1000
-                 'msoffice' => array(
999
+                    // DOC  - data       - Microsoft Word
1000
+                    'msoffice' => array(
1001 1001
                             'pattern'   => '^\xD0\xCF\x11\xE0', // D0CF11E == DOCFILE == Microsoft Office Document
1002 1002
                             'mime_type' => 'application/octet-stream',
1003 1003
                             'fail_id3'  => 'ERROR',
1004 1004
                             'fail_ape'  => 'ERROR',
1005
-                          ),
1005
+                            ),
1006 1006
             );
1007 1007
 
1008 1008
         return $format_info;
@@ -1393,99 +1393,99 @@  discard block
 block discarded – undo
1393 1393
 
1394 1394
     public static function BigEndian2Float($byte_word) {
1395 1395
 
1396
-		// ANSI/IEEE Standard 754-1985, Standard for Binary Floating Point Arithmetic
1397
-		// http://www.psc.edu/general/software/packages/ieee/ieee.html
1398
-		// http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/ieee.html
1396
+        // ANSI/IEEE Standard 754-1985, Standard for Binary Floating Point Arithmetic
1397
+        // http://www.psc.edu/general/software/packages/ieee/ieee.html
1398
+        // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/ieee.html
1399 1399
 
1400
-		$bit_word = getid3_lib::BigEndian2Bin($byte_word);
1401
-		if (!$bit_word) {
1400
+        $bit_word = getid3_lib::BigEndian2Bin($byte_word);
1401
+        if (!$bit_word) {
1402 1402
             return 0;
1403 1403
         }
1404
-		$sign_bit = $bit_word{0};
1405
-
1406
-		switch (strlen($byte_word) * 8) {
1407
-			case 32:
1408
-				$exponent_bits = 8;
1409
-				$fraction_bits = 23;
1410
-				break;
1411
-
1412
-			case 64:
1413
-				$exponent_bits = 11;
1414
-				$fraction_bits = 52;
1415
-				break;
1416
-
1417
-			case 80:
1418
-				// 80-bit Apple SANE format
1419
-				// http://www.mactech.com/articles/mactech/Vol.06/06.01/SANENormalized/
1420
-				$exponent_string = substr($bit_word, 1, 15);
1421
-				$is_normalized = intval($bit_word{16});
1422
-				$fraction_string = substr($bit_word, 17, 63);
1423
-				$exponent = pow(2, getid3_lib::Bin2Dec($exponent_string) - 16383);
1424
-				$fraction = $is_normalized + getid3_lib::DecimalBinary2Float($fraction_string);
1425
-				$float_value = $exponent * $fraction;
1426
-				if ($sign_bit == '1') {
1427
-					$float_value *= -1;
1428
-				}
1429
-				return $float_value;
1430
-				break;
1431
-
1432
-			default:
1433
-				return false;
1434
-				break;
1435
-		}
1436
-		$exponent_string = substr($bit_word, 1, $exponent_bits);
1437
-		$fraction_string = substr($bit_word, $exponent_bits + 1, $fraction_bits);
1438
-		$exponent = bindec($exponent_string);
1439
-		$fraction = bindec($fraction_string);
1440
-
1441
-		if (($exponent == (pow(2, $exponent_bits) - 1)) && ($fraction != 0)) {
1442
-			// Not a Number
1443
-			$float_value = false;
1444
-		} elseif (($exponent == (pow(2, $exponent_bits) - 1)) && ($fraction == 0)) {
1445
-			if ($sign_bit == '1') {
1446
-				$float_value = '-infinity';
1447
-			} else {
1448
-				$float_value = '+infinity';
1449
-			}
1450
-		} elseif (($exponent == 0) && ($fraction == 0)) {
1451
-			if ($sign_bit == '1') {
1452
-				$float_value = -0;
1453
-			} else {
1454
-				$float_value = 0;
1455
-			}
1456
-			$float_value = ($sign_bit ? 0 : -0);
1457
-		} elseif (($exponent == 0) && ($fraction != 0)) {
1458
-			// These are 'unnormalized' values
1459
-			$float_value = pow(2, (-1 * (pow(2, $exponent_bits - 1) - 2))) * getid3_lib::DecimalBinary2Float($fraction_string);
1460
-			if ($sign_bit == '1') {
1461
-				$float_value *= -1;
1462
-			}
1463
-		} elseif ($exponent != 0) {
1464
-			$float_value = pow(2, ($exponent - (pow(2, $exponent_bits - 1) - 1))) * (1 + getid3_lib::DecimalBinary2Float($fraction_string));
1465
-			if ($sign_bit == '1') {
1466
-				$float_value *= -1;
1467
-			}
1468
-		}
1469
-		return (float) $float_value;
1470
-	}
1471
-
1472
-
1473
-
1474
-	public static function LittleEndian2Float($byte_word) {
1475
-
1476
-		return getid3_lib::BigEndian2Float(strrev($byte_word));
1477
-	}
1478
-
1479
-
1480
-
1481
-	public static function DecimalBinary2Float($binary_numerator) {
1482
-		$numerator   = bindec($binary_numerator);
1483
-		$denominator = bindec('1'.str_repeat('0', strlen($binary_numerator)));
1484
-		return ($numerator / $denominator);
1485
-	}
1486
-
1487
-
1488
-	public static function PrintHexBytes($string, $hex=true, $spaces=true, $html_safe=true) {
1404
+        $sign_bit = $bit_word{0};
1405
+
1406
+        switch (strlen($byte_word) * 8) {
1407
+            case 32:
1408
+                $exponent_bits = 8;
1409
+                $fraction_bits = 23;
1410
+                break;
1411
+
1412
+            case 64:
1413
+                $exponent_bits = 11;
1414
+                $fraction_bits = 52;
1415
+                break;
1416
+
1417
+            case 80:
1418
+                // 80-bit Apple SANE format
1419
+                // http://www.mactech.com/articles/mactech/Vol.06/06.01/SANENormalized/
1420
+                $exponent_string = substr($bit_word, 1, 15);
1421
+                $is_normalized = intval($bit_word{16});
1422
+                $fraction_string = substr($bit_word, 17, 63);
1423
+                $exponent = pow(2, getid3_lib::Bin2Dec($exponent_string) - 16383);
1424
+                $fraction = $is_normalized + getid3_lib::DecimalBinary2Float($fraction_string);
1425
+                $float_value = $exponent * $fraction;
1426
+                if ($sign_bit == '1') {
1427
+                    $float_value *= -1;
1428
+                }
1429
+                return $float_value;
1430
+                break;
1431
+
1432
+            default:
1433
+                return false;
1434
+                break;
1435
+        }
1436
+        $exponent_string = substr($bit_word, 1, $exponent_bits);
1437
+        $fraction_string = substr($bit_word, $exponent_bits + 1, $fraction_bits);
1438
+        $exponent = bindec($exponent_string);
1439
+        $fraction = bindec($fraction_string);
1440
+
1441
+        if (($exponent == (pow(2, $exponent_bits) - 1)) && ($fraction != 0)) {
1442
+            // Not a Number
1443
+            $float_value = false;
1444
+        } elseif (($exponent == (pow(2, $exponent_bits) - 1)) && ($fraction == 0)) {
1445
+            if ($sign_bit == '1') {
1446
+                $float_value = '-infinity';
1447
+            } else {
1448
+                $float_value = '+infinity';
1449
+            }
1450
+        } elseif (($exponent == 0) && ($fraction == 0)) {
1451
+            if ($sign_bit == '1') {
1452
+                $float_value = -0;
1453
+            } else {
1454
+                $float_value = 0;
1455
+            }
1456
+            $float_value = ($sign_bit ? 0 : -0);
1457
+        } elseif (($exponent == 0) && ($fraction != 0)) {
1458
+            // These are 'unnormalized' values
1459
+            $float_value = pow(2, (-1 * (pow(2, $exponent_bits - 1) - 2))) * getid3_lib::DecimalBinary2Float($fraction_string);
1460
+            if ($sign_bit == '1') {
1461
+                $float_value *= -1;
1462
+            }
1463
+        } elseif ($exponent != 0) {
1464
+            $float_value = pow(2, ($exponent - (pow(2, $exponent_bits - 1) - 1))) * (1 + getid3_lib::DecimalBinary2Float($fraction_string));
1465
+            if ($sign_bit == '1') {
1466
+                $float_value *= -1;
1467
+            }
1468
+        }
1469
+        return (float) $float_value;
1470
+    }
1471
+
1472
+
1473
+
1474
+    public static function LittleEndian2Float($byte_word) {
1475
+
1476
+        return getid3_lib::BigEndian2Float(strrev($byte_word));
1477
+    }
1478
+
1479
+
1480
+
1481
+    public static function DecimalBinary2Float($binary_numerator) {
1482
+        $numerator   = bindec($binary_numerator);
1483
+        $denominator = bindec('1'.str_repeat('0', strlen($binary_numerator)));
1484
+        return ($numerator / $denominator);
1485
+    }
1486
+
1487
+
1488
+    public static function PrintHexBytes($string, $hex=true, $spaces=true, $html_safe=true) {
1489 1489
 
1490 1490
         $return_string = '';
1491 1491
         for ($i = 0; $i < strlen($string); $i++) {
Please login to merge, or discard this patch.
main/inc/lib/sessionmanager.lib.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -6022,7 +6022,7 @@
 block discarded – undo
6022 6022
         ]);
6023 6023
     }
6024 6024
 
6025
-	/**
6025
+    /**
6026 6026
      * Get the count of user courses in session
6027 6027
      * @param int $sessionId The session id
6028 6028
      * @return array
Please login to merge, or discard this patch.
main/inc/lib/attendance.lib.php 1 patch
Indentation   +1704 added lines, -1704 removed lines patch added patch discarded remove patch
@@ -11,50 +11,50 @@  discard block
 block discarded – undo
11 11
  */
12 12
 class Attendance
13 13
 {
14
-	private $session_id;
15
-	private $course_id;
16
-	private $date_time;
17
-	private $name;
18
-	private $description;
19
-	private $attendance_qualify_title;
20
-	private $attendance_weight;
21
-	private $course_int_id;
22
-	public $category_id;
23
-
24
-	// constants
25
-	const DONE_ATTENDANCE_LOG_TYPE = 'done_attendance_sheet';
26
-	const UPDATED_ATTENDANCE_LOG_TYPE = 'updated_attendance_sheet';
27
-	const LOCKED_ATTENDANCE_LOG_TYPE = 'locked_attendance_sheet';
28
-
29
-	/**
30
-	 * Constructor
31
-	 */
32
-	public function __construct()
33
-	{
34
-		//$this->course_int_id = api_get_course_int_id();
35
-	}
36
-
37
-	/**
38
-	 * Get the total number of attendance inside current course and current session
39
-	 * @see SortableTable#get_total_number_of_items()
40
-	 */
41
-	public static function get_number_of_attendances($active = -1)
42
-	{
43
-		$tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE);
44
-		$session_id = api_get_session_id();
45
-		$condition_session = api_get_session_condition($session_id);
46
-		$course_id = api_get_course_int_id();
47
-		$sql = "SELECT COUNT(att.id) AS total_number_of_items
14
+    private $session_id;
15
+    private $course_id;
16
+    private $date_time;
17
+    private $name;
18
+    private $description;
19
+    private $attendance_qualify_title;
20
+    private $attendance_weight;
21
+    private $course_int_id;
22
+    public $category_id;
23
+
24
+    // constants
25
+    const DONE_ATTENDANCE_LOG_TYPE = 'done_attendance_sheet';
26
+    const UPDATED_ATTENDANCE_LOG_TYPE = 'updated_attendance_sheet';
27
+    const LOCKED_ATTENDANCE_LOG_TYPE = 'locked_attendance_sheet';
28
+
29
+    /**
30
+     * Constructor
31
+     */
32
+    public function __construct()
33
+    {
34
+        //$this->course_int_id = api_get_course_int_id();
35
+    }
36
+
37
+    /**
38
+     * Get the total number of attendance inside current course and current session
39
+     * @see SortableTable#get_total_number_of_items()
40
+     */
41
+    public static function get_number_of_attendances($active = -1)
42
+    {
43
+        $tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE);
44
+        $session_id = api_get_session_id();
45
+        $condition_session = api_get_session_condition($session_id);
46
+        $course_id = api_get_course_int_id();
47
+        $sql = "SELECT COUNT(att.id) AS total_number_of_items
48 48
 				FROM $tbl_attendance att
49 49
 		        WHERE c_id = $course_id $condition_session ";
50
-		if ($active == 1 || $active == 0) {
51
-			$sql .= "AND att.active = $active";
52
-		}
53
-		$res = Database::query($sql);
54
-		$obj = Database::fetch_object($res);
50
+        if ($active == 1 || $active == 0) {
51
+            $sql .= "AND att.active = $active";
52
+        }
53
+        $res = Database::query($sql);
54
+        $obj = Database::fetch_object($res);
55 55
 
56
-		return $obj->total_number_of_items;
57
-	}
56
+        return $obj->total_number_of_items;
57
+    }
58 58
 
59 59
     /**
60 60
      * Get attendance list only the id, name and attendance_qualify_max fields
@@ -90,36 +90,36 @@  discard block
 block discarded – undo
90 90
         return $data;
91 91
     }
92 92
 
93
-	/**
94
-	 * Get the attendaces to display on the current page (fill the sortable-table)
95
-	 * @param   int     offset of first user to recover
96
-	 * @param   int     Number of users to get
97
-	 * @param   int     Column to sort on
98
-	 * @param   string  Order (ASC,DESC)
99
-	 * @see SortableTable#get_table_data($from)
100
-	 */
101
-	public static function get_attendance_data($from, $number_of_items, $column, $direction)
102
-	{
103
-		$tbl_attendance = Database::get_course_table(TABLE_ATTENDANCE);
104
-		$course_id = api_get_course_int_id();
105
-		$session_id = api_get_session_id();
106
-		$condition_session = api_get_session_condition($session_id);
107
-		$column = intval($column);
108
-		$from = intval($from);
109
-		$number_of_items = intval($number_of_items);
110
-
111
-		if (!in_array($direction, array('ASC','DESC'))) {
112
-			$direction = 'ASC';
113
-		}
114
-
115
-		$active_plus = '';
116
-		if ((isset($_GET['isStudentView']) && $_GET['isStudentView'] == 'true') ||
117
-			!api_is_allowed_to_edit(null, true)
118
-		) {
119
-			$active_plus = ' AND att.active = 1';
120
-		}
121
-
122
-		$sql = "SELECT
93
+    /**
94
+     * Get the attendaces to display on the current page (fill the sortable-table)
95
+     * @param   int     offset of first user to recover
96
+     * @param   int     Number of users to get
97
+     * @param   int     Column to sort on
98
+     * @param   string  Order (ASC,DESC)
99
+     * @see SortableTable#get_table_data($from)
100
+     */
101
+    public static function get_attendance_data($from, $number_of_items, $column, $direction)
102
+    {
103
+        $tbl_attendance = Database::get_course_table(TABLE_ATTENDANCE);
104
+        $course_id = api_get_course_int_id();
105
+        $session_id = api_get_session_id();
106
+        $condition_session = api_get_session_condition($session_id);
107
+        $column = intval($column);
108
+        $from = intval($from);
109
+        $number_of_items = intval($number_of_items);
110
+
111
+        if (!in_array($direction, array('ASC','DESC'))) {
112
+            $direction = 'ASC';
113
+        }
114
+
115
+        $active_plus = '';
116
+        if ((isset($_GET['isStudentView']) && $_GET['isStudentView'] == 'true') ||
117
+            !api_is_allowed_to_edit(null, true)
118
+        ) {
119
+            $active_plus = ' AND att.active = 1';
120
+        }
121
+
122
+        $sql = "SELECT
123 123
                     att.id AS col0,
124 124
                     att.name AS col1,
125 125
                     att.description AS col2,
@@ -134,318 +134,318 @@  discard block
 block discarded – undo
134 134
 				ORDER BY col$column $direction
135 135
 				LIMIT $from,$number_of_items ";
136 136
 
137
-		$res = Database::query($sql);
138
-		$attendances = array ();
139
-		$user_info = api_get_user_info();
140
-		$allowDelete = api_get_setting('allow_delete_attendance');
141
-
142
-		while ($attendance = Database::fetch_row($res)) {
143
-
144
-			$student_param = '';
145
-			if (api_is_drh() && $_GET['student_id']) {
146
-				$student_param = '&student_id='.intval($_GET['student_id']);
147
-			}
148
-
149
-			$session_star = '';
150
-
151
-			if (api_get_session_id() == $attendance[6]) {
152
-				$session_star = api_get_session_image(api_get_session_id(), $user_info['status']);
153
-			}
154
-			if ($attendance[5] == 1) {
155
-
156
-				$isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
157
-					api_get_user_id(),
158
-					api_get_course_info()
159
-				);
160
-
161
-				if (api_is_allowed_to_edit(null, true) || $isDrhOfCourse) {
162
-					// Link to edit
163
-					$attendance[1] = '<a href="index.php?'.api_get_cidreq().'&action=attendance_sheet_list&attendance_id='.$attendance[0].$student_param.'">'.$attendance[1].'</a>'.$session_star;
164
-				} else {
165
-					// Link to view
166
-					$attendance[1] = '<a href="index.php?'.api_get_cidreq().'&action=attendance_sheet_list_no_edit&attendance_id='.$attendance[0].$student_param.'">'.$attendance[1].'</a>'.$session_star;
167
-				}
168
-
169
-			} else {
170
-				$attendance[1] = '<a class="muted" href="index.php?'.api_get_cidreq().'&action=attendance_sheet_list&attendance_id='.$attendance[0].$student_param.'">'.$attendance[1].'</a>'.$session_star;
171
-			}
172
-
173
-			if ($attendance[5] == 1) {
174
-				$attendance[3] = '<center>'.$attendance[3].'</center>';
175
-			} else {
176
-				$attendance[3] = '<center><span class="muted">'.$attendance[3].'</span></center>';
177
-			}
178
-
179
-			$attendance[3] = '<center>'.$attendance[3].'</center>';
180
-			if (api_is_allowed_to_edit(null, true)) {
181
-				$actions  = '';
182
-				$actions .= '<center>';
183
-
184
-				if (api_is_platform_admin()) {
185
-					$actions .= '<a href="index.php?'.api_get_cidreq().'&action=attendance_edit&attendance_id='.$attendance[0].'">'.
186
-						Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a>&nbsp;';
187
-					// Visible
188
-					if ($attendance[5] == 1) {
189
-						$actions .= '<a href="index.php?'.api_get_cidreq().'&action=attendance_set_invisible&attendance_id='.$attendance[0].'">'.
190
-							Display::return_icon('visible.png', get_lang('Hide'), array(), ICON_SIZE_SMALL).'</a>';
191
-					} else {
192
-						$actions .= '<a href="index.php?'.api_get_cidreq().'&action=attendance_set_visible&attendance_id='.$attendance[0].'">'.
193
-							Display::return_icon('invisible.png', get_lang('Show'), array(), ICON_SIZE_SMALL).'</a>';
194
-						$attendance[2] = '<span class="muted">'.$attendance[2].'</span>';
195
-					}
196
-					if ($allowDelete === 'true') {
197
-						$actions .= '<a href="index.php?' . api_get_cidreq() . '&action=attendance_delete&attendance_id=' . $attendance[0]. '">' .
198
-							Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>';
199
-					}
200
-				} else {
201
-					$is_locked_attendance = self::is_locked_attendance($attendance[0]);
202
-					if ($is_locked_attendance) {
203
-						$actions .= Display::return_icon('edit_na.png', get_lang('Edit')).'&nbsp;';
204
-						$actions .= Display::return_icon('visible.png', get_lang('Hide'));
205
-					} else {
206
-						$actions .= '<a href="index.php?'.api_get_cidreq().'&action=attendance_edit&attendance_id='.$attendance[0].'">'.
207
-							Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a>&nbsp;';
208
-
209
-						if ($attendance[5] == 1) {
210
-							$actions .= ' <a href="index.php?'.api_get_cidreq().'&action=attendance_set_invisible&attendance_id='.$attendance[0].'">'.
211
-								Display::return_icon('visible.png', get_lang('Hide'), array(), ICON_SIZE_SMALL).'</a>';
212
-						} else {
213
-							$actions .= ' <a href="index.php?'.api_get_cidreq().'&action=attendance_set_visible&attendance_id='.$attendance[0].'">'.
214
-								Display::return_icon('invisible.png', get_lang('Show'), array(), ICON_SIZE_SMALL).'</a>';
215
-							$attendance[2] = '<span class="muted">'.$attendance[2].'</span>';
216
-						}
217
-						if ($allowDelete === 'true') {
218
-							$actions .= ' <a href="index.php?' . api_get_cidreq() . '&action=attendance_delete&attendance_id=' . $attendance[0].'">' .
219
-								Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>';
220
-						}
221
-					}
222
-				}
223
-
224
-				// display lock/unlock icon
225
-				$is_done_all_calendar = self::is_all_attendance_calendar_done($attendance[0]);
226
-
227
-				if ($is_done_all_calendar) {
228
-					$locked   = $attendance[4];
229
-					if ($locked == 0) {
230
-						if (api_is_platform_admin()) {
231
-							$message_alert = get_lang('AreYouSureToLockTheAttendance');
232
-						} else {
233
-							$message_alert = get_lang('UnlockMessageInformation');
234
-						}
235
-						$actions .= '&nbsp;<a onclick="javascript:if(!confirm(\''.$message_alert.'\')) return false;" href="index.php?'.api_get_cidreq().'&action=lock_attendance&attendance_id='.$attendance[0].'">'.
137
+        $res = Database::query($sql);
138
+        $attendances = array ();
139
+        $user_info = api_get_user_info();
140
+        $allowDelete = api_get_setting('allow_delete_attendance');
141
+
142
+        while ($attendance = Database::fetch_row($res)) {
143
+
144
+            $student_param = '';
145
+            if (api_is_drh() && $_GET['student_id']) {
146
+                $student_param = '&student_id='.intval($_GET['student_id']);
147
+            }
148
+
149
+            $session_star = '';
150
+
151
+            if (api_get_session_id() == $attendance[6]) {
152
+                $session_star = api_get_session_image(api_get_session_id(), $user_info['status']);
153
+            }
154
+            if ($attendance[5] == 1) {
155
+
156
+                $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
157
+                    api_get_user_id(),
158
+                    api_get_course_info()
159
+                );
160
+
161
+                if (api_is_allowed_to_edit(null, true) || $isDrhOfCourse) {
162
+                    // Link to edit
163
+                    $attendance[1] = '<a href="index.php?'.api_get_cidreq().'&action=attendance_sheet_list&attendance_id='.$attendance[0].$student_param.'">'.$attendance[1].'</a>'.$session_star;
164
+                } else {
165
+                    // Link to view
166
+                    $attendance[1] = '<a href="index.php?'.api_get_cidreq().'&action=attendance_sheet_list_no_edit&attendance_id='.$attendance[0].$student_param.'">'.$attendance[1].'</a>'.$session_star;
167
+                }
168
+
169
+            } else {
170
+                $attendance[1] = '<a class="muted" href="index.php?'.api_get_cidreq().'&action=attendance_sheet_list&attendance_id='.$attendance[0].$student_param.'">'.$attendance[1].'</a>'.$session_star;
171
+            }
172
+
173
+            if ($attendance[5] == 1) {
174
+                $attendance[3] = '<center>'.$attendance[3].'</center>';
175
+            } else {
176
+                $attendance[3] = '<center><span class="muted">'.$attendance[3].'</span></center>';
177
+            }
178
+
179
+            $attendance[3] = '<center>'.$attendance[3].'</center>';
180
+            if (api_is_allowed_to_edit(null, true)) {
181
+                $actions  = '';
182
+                $actions .= '<center>';
183
+
184
+                if (api_is_platform_admin()) {
185
+                    $actions .= '<a href="index.php?'.api_get_cidreq().'&action=attendance_edit&attendance_id='.$attendance[0].'">'.
186
+                        Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a>&nbsp;';
187
+                    // Visible
188
+                    if ($attendance[5] == 1) {
189
+                        $actions .= '<a href="index.php?'.api_get_cidreq().'&action=attendance_set_invisible&attendance_id='.$attendance[0].'">'.
190
+                            Display::return_icon('visible.png', get_lang('Hide'), array(), ICON_SIZE_SMALL).'</a>';
191
+                    } else {
192
+                        $actions .= '<a href="index.php?'.api_get_cidreq().'&action=attendance_set_visible&attendance_id='.$attendance[0].'">'.
193
+                            Display::return_icon('invisible.png', get_lang('Show'), array(), ICON_SIZE_SMALL).'</a>';
194
+                        $attendance[2] = '<span class="muted">'.$attendance[2].'</span>';
195
+                    }
196
+                    if ($allowDelete === 'true') {
197
+                        $actions .= '<a href="index.php?' . api_get_cidreq() . '&action=attendance_delete&attendance_id=' . $attendance[0]. '">' .
198
+                            Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>';
199
+                    }
200
+                } else {
201
+                    $is_locked_attendance = self::is_locked_attendance($attendance[0]);
202
+                    if ($is_locked_attendance) {
203
+                        $actions .= Display::return_icon('edit_na.png', get_lang('Edit')).'&nbsp;';
204
+                        $actions .= Display::return_icon('visible.png', get_lang('Hide'));
205
+                    } else {
206
+                        $actions .= '<a href="index.php?'.api_get_cidreq().'&action=attendance_edit&attendance_id='.$attendance[0].'">'.
207
+                            Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a>&nbsp;';
208
+
209
+                        if ($attendance[5] == 1) {
210
+                            $actions .= ' <a href="index.php?'.api_get_cidreq().'&action=attendance_set_invisible&attendance_id='.$attendance[0].'">'.
211
+                                Display::return_icon('visible.png', get_lang('Hide'), array(), ICON_SIZE_SMALL).'</a>';
212
+                        } else {
213
+                            $actions .= ' <a href="index.php?'.api_get_cidreq().'&action=attendance_set_visible&attendance_id='.$attendance[0].'">'.
214
+                                Display::return_icon('invisible.png', get_lang('Show'), array(), ICON_SIZE_SMALL).'</a>';
215
+                            $attendance[2] = '<span class="muted">'.$attendance[2].'</span>';
216
+                        }
217
+                        if ($allowDelete === 'true') {
218
+                            $actions .= ' <a href="index.php?' . api_get_cidreq() . '&action=attendance_delete&attendance_id=' . $attendance[0].'">' .
219
+                                Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>';
220
+                        }
221
+                    }
222
+                }
223
+
224
+                // display lock/unlock icon
225
+                $is_done_all_calendar = self::is_all_attendance_calendar_done($attendance[0]);
226
+
227
+                if ($is_done_all_calendar) {
228
+                    $locked   = $attendance[4];
229
+                    if ($locked == 0) {
230
+                        if (api_is_platform_admin()) {
231
+                            $message_alert = get_lang('AreYouSureToLockTheAttendance');
232
+                        } else {
233
+                            $message_alert = get_lang('UnlockMessageInformation');
234
+                        }
235
+                        $actions .= '&nbsp;<a onclick="javascript:if(!confirm(\''.$message_alert.'\')) return false;" href="index.php?'.api_get_cidreq().'&action=lock_attendance&attendance_id='.$attendance[0].'">'.
236 236
                             Display::return_icon('unlock.png', get_lang('LockAttendance')).'</a>';
237
-					} else {
238
-						if (api_is_platform_admin()) {
239
-							$actions .= '&nbsp;<a onclick="javascript:if(!confirm(\''.get_lang('AreYouSureToUnlockTheAttendance').'\')) return false;" href="index.php?'.api_get_cidreq().'&action=unlock_attendance&attendance_id='.$attendance[0].'">'.
240
-									Display::return_icon('locked.png', get_lang('UnlockAttendance')).'</a>';
241
-						} else {
242
-							$actions .= '&nbsp;'.Display::return_icon('locked_na.png', get_lang('LockedAttendance'));
243
-						}
244
-					}
245
-				}
246
-				$actions .= '</center>';
247
-
248
-				$attendances[] = array($attendance[0], $attendance[1], $attendance[2], $attendance[3],$actions);
249
-			} else {
250
-				$attendance[0] = '&nbsp;';
251
-				$attendances[] = array($attendance[0], $attendance[1], $attendance[2], $attendance[3]);
252
-			}
253
-		}
254
-		return $attendances;
255
-	}
256
-
257
-	/**
258
-	 * Get the attendances by id to display on the current page
259
-	 * @param  int     $attendance_id
260
-	 * @return array   attendance data
261
-	 */
262
-	public function get_attendance_by_id($attendance_id)
263
-	{
264
-		$tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE);
265
-		$attendance_id = intval($attendance_id);
266
-		$course_id = api_get_course_int_id();
267
-		$attendance_data = array();
268
-		$sql = "SELECT * FROM $tbl_attendance
237
+                    } else {
238
+                        if (api_is_platform_admin()) {
239
+                            $actions .= '&nbsp;<a onclick="javascript:if(!confirm(\''.get_lang('AreYouSureToUnlockTheAttendance').'\')) return false;" href="index.php?'.api_get_cidreq().'&action=unlock_attendance&attendance_id='.$attendance[0].'">'.
240
+                                    Display::return_icon('locked.png', get_lang('UnlockAttendance')).'</a>';
241
+                        } else {
242
+                            $actions .= '&nbsp;'.Display::return_icon('locked_na.png', get_lang('LockedAttendance'));
243
+                        }
244
+                    }
245
+                }
246
+                $actions .= '</center>';
247
+
248
+                $attendances[] = array($attendance[0], $attendance[1], $attendance[2], $attendance[3],$actions);
249
+            } else {
250
+                $attendance[0] = '&nbsp;';
251
+                $attendances[] = array($attendance[0], $attendance[1], $attendance[2], $attendance[3]);
252
+            }
253
+        }
254
+        return $attendances;
255
+    }
256
+
257
+    /**
258
+     * Get the attendances by id to display on the current page
259
+     * @param  int     $attendance_id
260
+     * @return array   attendance data
261
+     */
262
+    public function get_attendance_by_id($attendance_id)
263
+    {
264
+        $tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE);
265
+        $attendance_id = intval($attendance_id);
266
+        $course_id = api_get_course_int_id();
267
+        $attendance_data = array();
268
+        $sql = "SELECT * FROM $tbl_attendance
269 269
 				WHERE c_id = $course_id AND id = '$attendance_id'";
270
-		$res = Database::query($sql);
271
-		if (Database::num_rows($res) > 0) {
272
-			while ($row = Database::fetch_array($res)) {
273
-				$attendance_data = $row;
274
-			}
275
-		}
276
-		return $attendance_data;
277
-	}
278
-
279
-	/**
280
-	 * Add attendances sheet inside table. This is the *list of* dates, not
281
-	 * a specific date in itself.
282
-	 * @param  bool   true for adding link in gradebook or false otherwise (optional)
283
-	 * @return int    last attendance id
284
-	 */
285
-	public function attendance_add($link_to_gradebook = false)
286
-	{
287
-		$_course = api_get_course_info();
288
-		$tbl_attendance	= Database :: get_course_table(TABLE_ATTENDANCE);
289
-		$table_link = Database:: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
290
-		$session_id = api_get_session_id();
291
-		$user_id = api_get_user_id();
292
-		$course_code = $_course['code'];
293
-		$course_id = $_course['real_id'];
294
-		$title_gradebook= $this->attendance_qualify_title;
295
-		$value_calification = 0;
296
-		$weight_calification = floatval($this->attendance_weight);
297
-
298
-		$params = [
299
-			'c_id' => $course_id,
300
-			'name' => $this->name,
301
-			'description' => $this->description,
302
-			'attendance_qualify_title' => $title_gradebook,
303
-			'attendance_weight' => $weight_calification,
304
-			'session_id' => $session_id,
305
-			'active' => 1,
306
-			'attendance_qualify_max' => 0,
307
-			'locked' => 0
308
-		];
309
-		$last_id = Database::insert($tbl_attendance, $params);
310
-
311
-		if (!empty($last_id)) {
312
-
313
-			$sql = "UPDATE $tbl_attendance SET id = iid WHERE iid = $last_id";
314
-			Database::query($sql);
315
-
316
-			api_item_property_update(
317
-				$_course,
318
-				TOOL_ATTENDANCE,
319
-				$last_id,
320
-				"AttendanceAdded",
321
-				$user_id
322
-			);
323
-
324
-		}
325
-		// add link to gradebook
326
-		if ($link_to_gradebook && !empty($this->category_id)) {
327
-			$description = '';
270
+        $res = Database::query($sql);
271
+        if (Database::num_rows($res) > 0) {
272
+            while ($row = Database::fetch_array($res)) {
273
+                $attendance_data = $row;
274
+            }
275
+        }
276
+        return $attendance_data;
277
+    }
278
+
279
+    /**
280
+     * Add attendances sheet inside table. This is the *list of* dates, not
281
+     * a specific date in itself.
282
+     * @param  bool   true for adding link in gradebook or false otherwise (optional)
283
+     * @return int    last attendance id
284
+     */
285
+    public function attendance_add($link_to_gradebook = false)
286
+    {
287
+        $_course = api_get_course_info();
288
+        $tbl_attendance	= Database :: get_course_table(TABLE_ATTENDANCE);
289
+        $table_link = Database:: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
290
+        $session_id = api_get_session_id();
291
+        $user_id = api_get_user_id();
292
+        $course_code = $_course['code'];
293
+        $course_id = $_course['real_id'];
294
+        $title_gradebook= $this->attendance_qualify_title;
295
+        $value_calification = 0;
296
+        $weight_calification = floatval($this->attendance_weight);
297
+
298
+        $params = [
299
+            'c_id' => $course_id,
300
+            'name' => $this->name,
301
+            'description' => $this->description,
302
+            'attendance_qualify_title' => $title_gradebook,
303
+            'attendance_weight' => $weight_calification,
304
+            'session_id' => $session_id,
305
+            'active' => 1,
306
+            'attendance_qualify_max' => 0,
307
+            'locked' => 0
308
+        ];
309
+        $last_id = Database::insert($tbl_attendance, $params);
310
+
311
+        if (!empty($last_id)) {
312
+
313
+            $sql = "UPDATE $tbl_attendance SET id = iid WHERE iid = $last_id";
314
+            Database::query($sql);
315
+
316
+            api_item_property_update(
317
+                $_course,
318
+                TOOL_ATTENDANCE,
319
+                $last_id,
320
+                "AttendanceAdded",
321
+                $user_id
322
+            );
323
+
324
+        }
325
+        // add link to gradebook
326
+        if ($link_to_gradebook && !empty($this->category_id)) {
327
+            $description = '';
328 328
             $link_info = GradebookUtils::is_resource_in_course_gradebook(
329 329
                 $course_code,
330 330
                 7,
331 331
                 $last_id,
332 332
                 $session_id
333 333
             );
334
-			$link_id = $link_info['id'];
335
-			if (!$link_info) {
336
-				GradebookUtils::add_resource_to_course_gradebook(
337
-					$this->category_id,
338
-					$course_code,
339
-					7,
340
-					$last_id,
341
-					$title_gradebook,
342
-					$weight_calification,
343
-					$value_calification,
344
-					$description,
345
-					1,
346
-					$session_id
347
-				);
348
-			} else {
349
-				Database::query('UPDATE '.$table_link.' SET weight='.$weight_calification.' WHERE id='.$link_id.'');
350
-			}
351
-		}
352
-		return $last_id;
353
-	}
354
-
355
-	/**
356
-	 * edit attendances inside table
357
-	 * @param 	int	   attendance id
358
-	 * @param  	bool   true for adding link in gradebook or false otherwise (optional)
359
-	 * @return 	int    last id
360
-	 */
361
-	public function attendance_edit($attendance_id, $link_to_gradebook = false)
362
-	{
363
-		$_course = api_get_course_info();
364
-		$tbl_attendance = Database:: get_course_table(TABLE_ATTENDANCE);
365
-		$table_link = Database:: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
366
-
367
-		$session_id = api_get_session_id();
368
-		$user_id = api_get_user_id();
369
-		$attendance_id = intval($attendance_id);
370
-		$course_code = $_course['code'];
371
-		$course_id = $_course['real_id'];
372
-		$title_gradebook = $this->attendance_qualify_title;
373
-		$value_calification = 0;
374
-		$weight_calification = floatval($this->attendance_weight);
375
-
376
-		if (!empty($attendance_id)) {
377
-
378
-			$params = [
379
-				'name' => $this->name,
380
-				'description' => $this->description,
381
-				'attendance_qualify_title' => $title_gradebook,
382
-				'attendance_weight' => $weight_calification
383
-			];
384
-			Database::update(
385
-				$tbl_attendance,
386
-				$params,
387
-				['c_id = ? AND id = ?' => [$course_id, $attendance_id]]
388
-			);
389
-
390
-			api_item_property_update(
391
-				$_course,
392
-				TOOL_ATTENDANCE,
393
-				$attendance_id,
394
-				"AttendanceUpdated",
395
-				$user_id
396
-			);
397
-
398
-			// add link to gradebook
399
-			if ($link_to_gradebook && !empty($this->category_id)) {
400
-				$description = '';
401
-				$link_info = GradebookUtils::is_resource_in_course_gradebook(
402
-					$course_code,
403
-					7,
404
-					$attendance_id,
405
-					$session_id
406
-				);
407
-				if (!$link_info) {
408
-					GradebookUtils::add_resource_to_course_gradebook(
409
-						$this->category_id,
410
-						$course_code,
411
-						7,
412
-						$attendance_id,
413
-						$title_gradebook,
414
-						$weight_calification,
415
-						$value_calification,
416
-						$description,
417
-						1,
418
-						$session_id
419
-					);
420
-				} else {
421
-					Database::query('UPDATE '.$table_link.' SET weight='.$weight_calification.' WHERE id='.$link_info['id'].'');
422
-				}
423
-			}
424
-			return $attendance_id;
425
-		}
426
-		return null;
427
-	}
428
-
429
-	/**
430
-	 * Restore attendance
431
-	 * @param 	int|array	   one or many attendances id
432
-	 * @return 	int    		   affected rows
433
-	 */
434
-	public function attendance_restore($attendance_id)
435
-	{
436
-		$_course = api_get_course_info();
437
-		$tbl_attendance	= Database :: get_course_table(TABLE_ATTENDANCE);
438
-		$user_id = api_get_user_id();
439
-		$course_id = $_course['real_id'];
440
-		if (is_array($attendance_id)) {
441
-			foreach ($attendance_id as $id) {
442
-				$id	= intval($id);
443
-				$sql = "UPDATE $tbl_attendance SET active = 1
334
+            $link_id = $link_info['id'];
335
+            if (!$link_info) {
336
+                GradebookUtils::add_resource_to_course_gradebook(
337
+                    $this->category_id,
338
+                    $course_code,
339
+                    7,
340
+                    $last_id,
341
+                    $title_gradebook,
342
+                    $weight_calification,
343
+                    $value_calification,
344
+                    $description,
345
+                    1,
346
+                    $session_id
347
+                );
348
+            } else {
349
+                Database::query('UPDATE '.$table_link.' SET weight='.$weight_calification.' WHERE id='.$link_id.'');
350
+            }
351
+        }
352
+        return $last_id;
353
+    }
354
+
355
+    /**
356
+     * edit attendances inside table
357
+     * @param 	int	   attendance id
358
+     * @param  	bool   true for adding link in gradebook or false otherwise (optional)
359
+     * @return 	int    last id
360
+     */
361
+    public function attendance_edit($attendance_id, $link_to_gradebook = false)
362
+    {
363
+        $_course = api_get_course_info();
364
+        $tbl_attendance = Database:: get_course_table(TABLE_ATTENDANCE);
365
+        $table_link = Database:: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
366
+
367
+        $session_id = api_get_session_id();
368
+        $user_id = api_get_user_id();
369
+        $attendance_id = intval($attendance_id);
370
+        $course_code = $_course['code'];
371
+        $course_id = $_course['real_id'];
372
+        $title_gradebook = $this->attendance_qualify_title;
373
+        $value_calification = 0;
374
+        $weight_calification = floatval($this->attendance_weight);
375
+
376
+        if (!empty($attendance_id)) {
377
+
378
+            $params = [
379
+                'name' => $this->name,
380
+                'description' => $this->description,
381
+                'attendance_qualify_title' => $title_gradebook,
382
+                'attendance_weight' => $weight_calification
383
+            ];
384
+            Database::update(
385
+                $tbl_attendance,
386
+                $params,
387
+                ['c_id = ? AND id = ?' => [$course_id, $attendance_id]]
388
+            );
389
+
390
+            api_item_property_update(
391
+                $_course,
392
+                TOOL_ATTENDANCE,
393
+                $attendance_id,
394
+                "AttendanceUpdated",
395
+                $user_id
396
+            );
397
+
398
+            // add link to gradebook
399
+            if ($link_to_gradebook && !empty($this->category_id)) {
400
+                $description = '';
401
+                $link_info = GradebookUtils::is_resource_in_course_gradebook(
402
+                    $course_code,
403
+                    7,
404
+                    $attendance_id,
405
+                    $session_id
406
+                );
407
+                if (!$link_info) {
408
+                    GradebookUtils::add_resource_to_course_gradebook(
409
+                        $this->category_id,
410
+                        $course_code,
411
+                        7,
412
+                        $attendance_id,
413
+                        $title_gradebook,
414
+                        $weight_calification,
415
+                        $value_calification,
416
+                        $description,
417
+                        1,
418
+                        $session_id
419
+                    );
420
+                } else {
421
+                    Database::query('UPDATE '.$table_link.' SET weight='.$weight_calification.' WHERE id='.$link_info['id'].'');
422
+                }
423
+            }
424
+            return $attendance_id;
425
+        }
426
+        return null;
427
+    }
428
+
429
+    /**
430
+     * Restore attendance
431
+     * @param 	int|array	   one or many attendances id
432
+     * @return 	int    		   affected rows
433
+     */
434
+    public function attendance_restore($attendance_id)
435
+    {
436
+        $_course = api_get_course_info();
437
+        $tbl_attendance	= Database :: get_course_table(TABLE_ATTENDANCE);
438
+        $user_id = api_get_user_id();
439
+        $course_id = $_course['real_id'];
440
+        if (is_array($attendance_id)) {
441
+            foreach ($attendance_id as $id) {
442
+                $id	= intval($id);
443
+                $sql = "UPDATE $tbl_attendance SET active = 1
444 444
 						WHERE c_id = $course_id AND id = '$id'";
445
-				$result = Database::query($sql);
446
-				$affected_rows = Database::affected_rows($result);
447
-				if (!empty($affected_rows)) {
448
-					// update row item property table
445
+                $result = Database::query($sql);
446
+                $affected_rows = Database::affected_rows($result);
447
+                if (!empty($affected_rows)) {
448
+                    // update row item property table
449 449
                     api_item_property_update(
450 450
                         $_course,
451 451
                         TOOL_ATTENDANCE,
@@ -453,16 +453,16 @@  discard block
 block discarded – undo
453 453
                         "restore",
454 454
                         $user_id
455 455
                     );
456
-				}
457
-			}
458
-		} else  {
459
-			$attendance_id	= intval($attendance_id);
460
-			$sql = "UPDATE $tbl_attendance SET active = 1
456
+                }
457
+            }
458
+        } else  {
459
+            $attendance_id	= intval($attendance_id);
460
+            $sql = "UPDATE $tbl_attendance SET active = 1
461 461
 					WHERE c_id = $course_id AND id = '$attendance_id'";
462
-			$result = Database::query($sql);
463
-			$affected_rows = Database::affected_rows($result);
464
-			if (!empty($affected_rows)) {
465
-				// update row item property table
462
+            $result = Database::query($sql);
463
+            $affected_rows = Database::affected_rows($result);
464
+            if (!empty($affected_rows)) {
465
+                // update row item property table
466 466
                 api_item_property_update(
467 467
                     $_course,
468 468
                     TOOL_ATTENDANCE,
@@ -470,33 +470,33 @@  discard block
 block discarded – undo
470 470
                     "restore",
471 471
                     $user_id
472 472
                 );
473
-			}
474
-		}
475
-
476
-		return $affected_rows;
477
-	}
478
-
479
-	/**
480
-	 * Delete attendances
481
-	 * @param 	int|array	$attendance_id   one or many attendances id
482
-	 * @return 	int    		   affected rows
483
-	 */
484
-	public function attendance_delete($attendance_id)
485
-	{
486
-		$_course = api_get_course_info();
487
-		$tbl_attendance	= Database :: get_course_table(TABLE_ATTENDANCE);
473
+            }
474
+        }
475
+
476
+        return $affected_rows;
477
+    }
478
+
479
+    /**
480
+     * Delete attendances
481
+     * @param 	int|array	$attendance_id   one or many attendances id
482
+     * @return 	int    		   affected rows
483
+     */
484
+    public function attendance_delete($attendance_id)
485
+    {
486
+        $_course = api_get_course_info();
487
+        $tbl_attendance	= Database :: get_course_table(TABLE_ATTENDANCE);
488 488
         $user_id = api_get_user_id();
489 489
         $course_id = $_course['real_id'];
490 490
 
491
-		if (is_array($attendance_id)) {
492
-			foreach ($attendance_id as $id) {
493
-				$id	= intval($id);
494
-				$sql = "UPDATE $tbl_attendance SET active = 2
491
+        if (is_array($attendance_id)) {
492
+            foreach ($attendance_id as $id) {
493
+                $id	= intval($id);
494
+                $sql = "UPDATE $tbl_attendance SET active = 2
495 495
 						WHERE c_id = $course_id AND id = '$id'";
496
-				$result = Database::query($sql);
497
-				$affected_rows = Database::affected_rows($result);
498
-				if (!empty($affected_rows)) {
499
-					// update row item property table
496
+                $result = Database::query($sql);
497
+                $affected_rows = Database::affected_rows($result);
498
+                if (!empty($affected_rows)) {
499
+                    // update row item property table
500 500
                     api_item_property_update(
501 501
                         $_course,
502 502
                         TOOL_ATTENDANCE,
@@ -504,142 +504,142 @@  discard block
 block discarded – undo
504 504
                         "delete",
505 505
                         $user_id
506 506
                     );
507
-				}
508
-			}
509
-		} else  {
510
-			$attendance_id= intval($attendance_id);
511
-			$sql = "UPDATE $tbl_attendance SET active = 2
507
+                }
508
+            }
509
+        } else  {
510
+            $attendance_id= intval($attendance_id);
511
+            $sql = "UPDATE $tbl_attendance SET active = 2
512 512
 					WHERE c_id = $course_id AND id = '$attendance_id'";
513 513
 
514
-			$result = Database::query($sql);
515
-			$affected_rows = Database::affected_rows($result);
516
-			if (!empty($affected_rows)) {
517
-				// update row item property table
518
-				api_item_property_update(
519
-					$_course,
520
-					TOOL_ATTENDANCE,
521
-					$attendance_id,
522
-					"delete",
523
-					$user_id
524
-				);
525
-			}
526
-		}
527
-
528
-		return $affected_rows;
529
-	}
530
-
531
-	/**
532
-	 * Changes visibility
533
-	 * @param int|array	$attendanceId   one or many attendances id
534
-	 * @param int status
514
+            $result = Database::query($sql);
515
+            $affected_rows = Database::affected_rows($result);
516
+            if (!empty($affected_rows)) {
517
+                // update row item property table
518
+                api_item_property_update(
519
+                    $_course,
520
+                    TOOL_ATTENDANCE,
521
+                    $attendance_id,
522
+                    "delete",
523
+                    $user_id
524
+                );
525
+            }
526
+        }
527
+
528
+        return $affected_rows;
529
+    }
530
+
531
+    /**
532
+     * Changes visibility
533
+     * @param int|array	$attendanceId   one or many attendances id
534
+     * @param int status
535 535
      *
536
-	 * @return 	int affected rows
537
-	 */
538
-	public function changeVisibility($attendanceId, $status = 1)
539
-	{
540
-		$_course = api_get_course_info();
541
-		$tbl_attendance	= Database :: get_course_table(TABLE_ATTENDANCE);
542
-		$user_id = api_get_user_id();
543
-		$course_id = $_course['real_id'];
544
-		$status = intval($status);
545
-
546
-		$action = 'visible';
547
-		if ($status == 0) {
548
-			$action = 'invisible';
549
-		}
550
-
551
-		if (is_array($attendanceId)) {
552
-			foreach ($attendanceId as $id) {
553
-				$id	= intval($id);
554
-				$sql = "UPDATE $tbl_attendance SET active = $status
536
+     * @return 	int affected rows
537
+     */
538
+    public function changeVisibility($attendanceId, $status = 1)
539
+    {
540
+        $_course = api_get_course_info();
541
+        $tbl_attendance	= Database :: get_course_table(TABLE_ATTENDANCE);
542
+        $user_id = api_get_user_id();
543
+        $course_id = $_course['real_id'];
544
+        $status = intval($status);
545
+
546
+        $action = 'visible';
547
+        if ($status == 0) {
548
+            $action = 'invisible';
549
+        }
550
+
551
+        if (is_array($attendanceId)) {
552
+            foreach ($attendanceId as $id) {
553
+                $id	= intval($id);
554
+                $sql = "UPDATE $tbl_attendance SET active = $status
555 555
 						WHERE c_id = $course_id AND id = '$id'";
556
-				$result = Database::query($sql);
557
-				$affected_rows = Database::affected_rows($result);
558
-				if (!empty($affected_rows)) {
559
-					// update row item property table
560
-					api_item_property_update($_course, TOOL_ATTENDANCE, $id, $action, $user_id);
561
-				}
562
-			}
563
-		} else  {
564
-			$attendanceId	= intval($attendanceId);
565
-			$sql = "UPDATE $tbl_attendance SET active = $status
556
+                $result = Database::query($sql);
557
+                $affected_rows = Database::affected_rows($result);
558
+                if (!empty($affected_rows)) {
559
+                    // update row item property table
560
+                    api_item_property_update($_course, TOOL_ATTENDANCE, $id, $action, $user_id);
561
+                }
562
+            }
563
+        } else  {
564
+            $attendanceId	= intval($attendanceId);
565
+            $sql = "UPDATE $tbl_attendance SET active = $status
566 566
 					WHERE c_id = $course_id AND id = '$attendanceId'";
567
-			$result = Database::query($sql);
568
-			$affected_rows = Database::affected_rows($result);
569
-			if (!empty($affected_rows)) {
570
-				// update row item property table
571
-				api_item_property_update(
572
-					$_course,
573
-					TOOL_ATTENDANCE,
574
-					$attendanceId,
575
-					$action,
576
-					$user_id
577
-				);
578
-			}
579
-		}
580
-
581
-		return $affected_rows;
582
-	}
583
-
584
-	/**
585
-	 * Lock or unlock an attendance
586
-	 * @param   int     attendance id
587
-	 * @param   bool    True to lock or false otherwise
588
-	 */
589
-	public function lock_attendance($attendance_id, $lock = true)
590
-	{
591
-		$tbl_attendance = Database::get_course_table(TABLE_ATTENDANCE);
592
-		$course_id = api_get_course_int_id();
593
-		$attendance_id = intval($attendance_id);
594
-		$locked = ($lock)?1:0;
595
-		$upd = "UPDATE $tbl_attendance SET locked = $locked
567
+            $result = Database::query($sql);
568
+            $affected_rows = Database::affected_rows($result);
569
+            if (!empty($affected_rows)) {
570
+                // update row item property table
571
+                api_item_property_update(
572
+                    $_course,
573
+                    TOOL_ATTENDANCE,
574
+                    $attendanceId,
575
+                    $action,
576
+                    $user_id
577
+                );
578
+            }
579
+        }
580
+
581
+        return $affected_rows;
582
+    }
583
+
584
+    /**
585
+     * Lock or unlock an attendance
586
+     * @param   int     attendance id
587
+     * @param   bool    True to lock or false otherwise
588
+     */
589
+    public function lock_attendance($attendance_id, $lock = true)
590
+    {
591
+        $tbl_attendance = Database::get_course_table(TABLE_ATTENDANCE);
592
+        $course_id = api_get_course_int_id();
593
+        $attendance_id = intval($attendance_id);
594
+        $locked = ($lock)?1:0;
595
+        $upd = "UPDATE $tbl_attendance SET locked = $locked
596 596
 				WHERE c_id = $course_id AND id = $attendance_id";
597
-		$result = Database::query($upd);
598
-		$affected_rows = Database::affected_rows($result);
599
-		if ($affected_rows && $lock) {
600
-			// Save attendance sheet log
601
-			$lastedit_date = api_get_utc_datetime();
602
-			$lastedit_type = self::LOCKED_ATTENDANCE_LOG_TYPE;
603
-			$lastedit_user_id = api_get_user_id();
604
-			$this->save_attendance_sheet_log(
605
-				$attendance_id,
606
-				$lastedit_date,
607
-				$lastedit_type,
608
-				$lastedit_user_id
609
-			);
610
-		}
611
-		return $affected_rows;
612
-	}
613
-
614
-	/**
615
-	 * Get registered users inside current course
616
-	 * @param 	int	   $attendance_id attendance id for showing attendance result field (optional)
617
-	 * @param int $groupId
618
-	 * @return 	array  users data
619
-	 */
620
-	public function get_users_rel_course($attendance_id = 0, $groupId = null)
621
-	{
622
-		$current_session_id = api_get_session_id();
623
-		$current_course_id  = api_get_course_id();
624
-		$currentCourseIntId = api_get_course_int_id();
625
-
626
-		$studentInGroup = array();
627
-
628
-		if (!empty($current_session_id)) {
629
-			$a_course_users = CourseManager:: get_user_list_from_course_code(
630
-				$current_course_id,
631
-				$current_session_id,
632
-				'',
633
-				'lastname'
634
-			);
635
-		} else {
636
-			$a_course_users = CourseManager:: get_user_list_from_course_code(
637
-				$current_course_id,
638
-				0,
639
-				'',
640
-				'lastname'
641
-			);
642
-		}
597
+        $result = Database::query($upd);
598
+        $affected_rows = Database::affected_rows($result);
599
+        if ($affected_rows && $lock) {
600
+            // Save attendance sheet log
601
+            $lastedit_date = api_get_utc_datetime();
602
+            $lastedit_type = self::LOCKED_ATTENDANCE_LOG_TYPE;
603
+            $lastedit_user_id = api_get_user_id();
604
+            $this->save_attendance_sheet_log(
605
+                $attendance_id,
606
+                $lastedit_date,
607
+                $lastedit_type,
608
+                $lastedit_user_id
609
+            );
610
+        }
611
+        return $affected_rows;
612
+    }
613
+
614
+    /**
615
+     * Get registered users inside current course
616
+     * @param 	int	   $attendance_id attendance id for showing attendance result field (optional)
617
+     * @param int $groupId
618
+     * @return 	array  users data
619
+     */
620
+    public function get_users_rel_course($attendance_id = 0, $groupId = null)
621
+    {
622
+        $current_session_id = api_get_session_id();
623
+        $current_course_id  = api_get_course_id();
624
+        $currentCourseIntId = api_get_course_int_id();
625
+
626
+        $studentInGroup = array();
627
+
628
+        if (!empty($current_session_id)) {
629
+            $a_course_users = CourseManager:: get_user_list_from_course_code(
630
+                $current_course_id,
631
+                $current_session_id,
632
+                '',
633
+                'lastname'
634
+            );
635
+        } else {
636
+            $a_course_users = CourseManager:: get_user_list_from_course_code(
637
+                $current_course_id,
638
+                0,
639
+                '',
640
+                'lastname'
641
+            );
642
+        }
643 643
 
644 644
         if (!empty($groupId)) {
645 645
             $students = GroupManager::getStudents($groupId);
@@ -650,192 +650,192 @@  discard block
 block discarded – undo
650 650
             }
651 651
         }
652 652
 
653
-		// get registered users inside current course
654
-		$a_users = array();
655
-		foreach ($a_course_users as $key => $user_data) {
656
-			$value = array();
657
-			$uid = $user_data['user_id'];
658
-			$userInfo = api_get_user_info($uid);
659
-
660
-			$status = $user_data['status'];
661
-
662
-			if (!empty($groupId)) {
663
-				if (!isset($studentInGroup[$uid])) {
664
-					continue;
665
-				}
666
-			}
667
-
668
-			$user_status_in_session = null;
669
-			$user_status_in_course  = null;
670
-
671
-			if (api_get_session_id()) {
672
-				$user_status_in_session = SessionManager::get_user_status_in_course_session(
673
-					$uid,
674
-					$currentCourseIntId,
675
-					$current_session_id
676
-				);
677
-			} else {
678
-				$user_status_in_course = CourseManager::get_user_in_course_status(
679
-					$uid,
680
-					$current_course_id
681
-				);
682
-			}
683
-
684
-			// Not taking into account DRH or COURSEMANAGER
685
-			if ($uid <= 1 ||
686
-				$status == DRH ||
687
-				$user_status_in_course == COURSEMANAGER ||
688
-				$user_status_in_session == 2
689
-			) {
690
-				continue;
691
-			}
692
-
693
-			if (!empty($attendance_id)) {
694
-				$user_faults = $this->get_faults_of_user($uid, $attendance_id, $groupId);
695
-				$value['attendance_result'] = $user_faults['faults'].'/'.$user_faults['total'].' ('.$user_faults['faults_porcent'].'%)';
696
-				$value['result_color_bar'] 	= $user_faults['color_bar'];
697
-			}
653
+        // get registered users inside current course
654
+        $a_users = array();
655
+        foreach ($a_course_users as $key => $user_data) {
656
+            $value = array();
657
+            $uid = $user_data['user_id'];
658
+            $userInfo = api_get_user_info($uid);
659
+
660
+            $status = $user_data['status'];
661
+
662
+            if (!empty($groupId)) {
663
+                if (!isset($studentInGroup[$uid])) {
664
+                    continue;
665
+                }
666
+            }
667
+
668
+            $user_status_in_session = null;
669
+            $user_status_in_course  = null;
670
+
671
+            if (api_get_session_id()) {
672
+                $user_status_in_session = SessionManager::get_user_status_in_course_session(
673
+                    $uid,
674
+                    $currentCourseIntId,
675
+                    $current_session_id
676
+                );
677
+            } else {
678
+                $user_status_in_course = CourseManager::get_user_in_course_status(
679
+                    $uid,
680
+                    $current_course_id
681
+                );
682
+            }
683
+
684
+            // Not taking into account DRH or COURSEMANAGER
685
+            if ($uid <= 1 ||
686
+                $status == DRH ||
687
+                $user_status_in_course == COURSEMANAGER ||
688
+                $user_status_in_session == 2
689
+            ) {
690
+                continue;
691
+            }
692
+
693
+            if (!empty($attendance_id)) {
694
+                $user_faults = $this->get_faults_of_user($uid, $attendance_id, $groupId);
695
+                $value['attendance_result'] = $user_faults['faults'].'/'.$user_faults['total'].' ('.$user_faults['faults_porcent'].'%)';
696
+                $value['result_color_bar'] 	= $user_faults['color_bar'];
697
+            }
698 698
 
699 699
             $photo = Display::img($userInfo['avatar_small'], $userInfo['complete_name'], [], false);
700 700
 
701
-			$value['photo'] = $photo;
702
-			$value['firstname'] = $user_data['firstname'];
703
-			$value['lastname'] = $user_data['lastname'];
704
-			$value['username'] = $user_data['username'];
705
-			$value['user_id'] = $uid;
706
-
707
-			//Sending only 5 items in the array instead of 60
708
-			$a_users[$key] = $value;
709
-		}
710
-
711
-		return $a_users;
712
-	}
713
-
714
-	/**
715
-	 * add attendances sheet inside table
716
-	 * @param 	int	   $calendar_id attendance calendar id
717
-	 * @param  	array  $users_present present users during current class
718
-	 * @param	int	   $attendance_id
719
-	 * @return 	int    affected rows
720
-	 */
721
-	public function attendance_sheet_add($calendar_id, $users_present, $attendance_id)
722
-	{
723
-		$tbl_attendance_sheet 	= Database::get_course_table(TABLE_ATTENDANCE_SHEET);
724
-		$tbl_attendance_calendar= Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
725
-
726
-		$calendar_id = intval($calendar_id);
727
-		$attendance_id = intval($attendance_id);
728
-		$users = $this->get_users_rel_course();
729
-		$course_id = api_get_course_int_id();
730
-
731
-		$user_ids = array_keys($users);
732
-		$users_absent = array_diff($user_ids,$users_present);
733
-		$affected_rows = 0;
734
-
735
-		// get last edit type
736
-		$calendar_data = $this->get_attendance_calendar_by_id($calendar_id);
737
-		$lastedit_type = self::DONE_ATTENDANCE_LOG_TYPE;
738
-		if ($calendar_data['done_attendance']) {
739
-			$lastedit_type = self::UPDATED_ATTENDANCE_LOG_TYPE;
740
-		}
741
-
742
-		// save users present in class
743
-		foreach ($users_present as $user_present) {
744
-			$uid = intval($user_present);
745
-			// check if user already was registered with the $calendar_id
746
-			$sql = "SELECT user_id FROM $tbl_attendance_sheet
701
+            $value['photo'] = $photo;
702
+            $value['firstname'] = $user_data['firstname'];
703
+            $value['lastname'] = $user_data['lastname'];
704
+            $value['username'] = $user_data['username'];
705
+            $value['user_id'] = $uid;
706
+
707
+            //Sending only 5 items in the array instead of 60
708
+            $a_users[$key] = $value;
709
+        }
710
+
711
+        return $a_users;
712
+    }
713
+
714
+    /**
715
+     * add attendances sheet inside table
716
+     * @param 	int	   $calendar_id attendance calendar id
717
+     * @param  	array  $users_present present users during current class
718
+     * @param	int	   $attendance_id
719
+     * @return 	int    affected rows
720
+     */
721
+    public function attendance_sheet_add($calendar_id, $users_present, $attendance_id)
722
+    {
723
+        $tbl_attendance_sheet 	= Database::get_course_table(TABLE_ATTENDANCE_SHEET);
724
+        $tbl_attendance_calendar= Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
725
+
726
+        $calendar_id = intval($calendar_id);
727
+        $attendance_id = intval($attendance_id);
728
+        $users = $this->get_users_rel_course();
729
+        $course_id = api_get_course_int_id();
730
+
731
+        $user_ids = array_keys($users);
732
+        $users_absent = array_diff($user_ids,$users_present);
733
+        $affected_rows = 0;
734
+
735
+        // get last edit type
736
+        $calendar_data = $this->get_attendance_calendar_by_id($calendar_id);
737
+        $lastedit_type = self::DONE_ATTENDANCE_LOG_TYPE;
738
+        if ($calendar_data['done_attendance']) {
739
+            $lastedit_type = self::UPDATED_ATTENDANCE_LOG_TYPE;
740
+        }
741
+
742
+        // save users present in class
743
+        foreach ($users_present as $user_present) {
744
+            $uid = intval($user_present);
745
+            // check if user already was registered with the $calendar_id
746
+            $sql = "SELECT user_id FROM $tbl_attendance_sheet
747 747
 					WHERE c_id = $course_id AND user_id='$uid' AND attendance_calendar_id = '$calendar_id'";
748
-			$rs  = Database::query($sql);
749
-			if (Database::num_rows($rs) == 0) {
750
-				$sql = "INSERT INTO $tbl_attendance_sheet SET
748
+            $rs  = Database::query($sql);
749
+            if (Database::num_rows($rs) == 0) {
750
+                $sql = "INSERT INTO $tbl_attendance_sheet SET
751 751
 						c_id					= $course_id,
752 752
 						user_id 				= '$uid',
753 753
 						attendance_calendar_id 	= '$calendar_id',
754 754
 						presence 				= 1";
755
-				$result = Database::query($sql);
755
+                $result = Database::query($sql);
756 756
 
757
-				$affected_rows += Database::affected_rows($result);
758
-			} else {
759
-				$sql = "UPDATE $tbl_attendance_sheet SET presence = 1
757
+                $affected_rows += Database::affected_rows($result);
758
+            } else {
759
+                $sql = "UPDATE $tbl_attendance_sheet SET presence = 1
760 760
 						WHERE
761 761
 							c_id = $course_id AND
762 762
 							user_id ='$uid' AND
763 763
 							attendance_calendar_id = '$calendar_id'
764 764
 						";
765
-				$result = Database::query($sql);
766
-				$affected_rows += Database::affected_rows($result);
767
-			}
768
-		}
769
-
770
-		// save users absent in class
771
-		foreach ($users_absent as $user_absent) {
772
-			$uid = intval($user_absent);
773
-			// check if user already was registered with the $calendar_id
774
-			$sql = "SELECT user_id FROM $tbl_attendance_sheet
765
+                $result = Database::query($sql);
766
+                $affected_rows += Database::affected_rows($result);
767
+            }
768
+        }
769
+
770
+        // save users absent in class
771
+        foreach ($users_absent as $user_absent) {
772
+            $uid = intval($user_absent);
773
+            // check if user already was registered with the $calendar_id
774
+            $sql = "SELECT user_id FROM $tbl_attendance_sheet
775 775
 					WHERE c_id = $course_id AND user_id='$uid' AND attendance_calendar_id = '$calendar_id'";
776
-			$rs  = Database::query($sql);
777
-			if (Database::num_rows($rs) == 0) {
778
-				$sql = "INSERT INTO $tbl_attendance_sheet SET
776
+            $rs  = Database::query($sql);
777
+            if (Database::num_rows($rs) == 0) {
778
+                $sql = "INSERT INTO $tbl_attendance_sheet SET
779 779
 						c_id = $course_id,
780 780
 						user_id ='$uid',
781 781
 						attendance_calendar_id = '$calendar_id',
782 782
 						presence = 0";
783
-				$result = Database::query($sql);
783
+                $result = Database::query($sql);
784 784
 
785
-				Database::insert_id();
785
+                Database::insert_id();
786 786
 
787
-				$affected_rows += Database::affected_rows($result);
788
-			} else {
789
-				$sql = "UPDATE $tbl_attendance_sheet SET presence = 0
787
+                $affected_rows += Database::affected_rows($result);
788
+            } else {
789
+                $sql = "UPDATE $tbl_attendance_sheet SET presence = 0
790 790
 						WHERE
791 791
 							c_id = $course_id AND
792 792
 							user_id ='$uid' AND
793 793
 							attendance_calendar_id = '$calendar_id'";
794
-				$result = Database::query($sql);
795
-				$affected_rows += Database::affected_rows($result);
796
-			}
797
-		}
794
+                $result = Database::query($sql);
795
+                $affected_rows += Database::affected_rows($result);
796
+            }
797
+        }
798 798
 
799
-		// update done_attendance inside attendance calendar table
800
-		$sql = "UPDATE $tbl_attendance_calendar SET done_attendance = 1
799
+        // update done_attendance inside attendance calendar table
800
+        $sql = "UPDATE $tbl_attendance_calendar SET done_attendance = 1
801 801
 				WHERE  c_id = $course_id AND id = '$calendar_id'";
802
-		Database::query($sql);
803
-
804
-		// save users' results
805
-		$this->update_users_results($user_ids, $attendance_id);
806
-
807
-		if ($affected_rows) {
808
-			//save attendance sheet log
809
-			$lastedit_date = api_get_utc_datetime();
810
-			$lastedit_user_id = api_get_user_id();
811
-			$calendar_date_value = $calendar_data['date_time'];
812
-			$this->save_attendance_sheet_log(
813
-				$attendance_id,
814
-				$lastedit_date,
815
-				$lastedit_type,
816
-				$lastedit_user_id,
817
-				$calendar_date_value
818
-			);
819
-		}
820
-
821
-		return $affected_rows;
822
-	}
823
-
824
-	/**
825
-	 * update users' attendance results
826
-	 * @param 	array  $user_ids registered users inside current course
827
-	 * @param	int	   $attendance_id
828
-	 * @return 	void
829
-	 */
830
-	public function update_users_results($user_ids, $attendance_id)
831
-	{
832
-		$tbl_attendance_sheet = Database::get_course_table(TABLE_ATTENDANCE_SHEET);
833
-		$tbl_attendance_result = Database::get_course_table(TABLE_ATTENDANCE_RESULT);
834
-		$tbl_attendance = Database::get_course_table(TABLE_ATTENDANCE);
835
-		$course_id = api_get_course_int_id();
836
-
837
-		$attendance_id = intval($attendance_id);
838
-		// fill results about presence of students
802
+        Database::query($sql);
803
+
804
+        // save users' results
805
+        $this->update_users_results($user_ids, $attendance_id);
806
+
807
+        if ($affected_rows) {
808
+            //save attendance sheet log
809
+            $lastedit_date = api_get_utc_datetime();
810
+            $lastedit_user_id = api_get_user_id();
811
+            $calendar_date_value = $calendar_data['date_time'];
812
+            $this->save_attendance_sheet_log(
813
+                $attendance_id,
814
+                $lastedit_date,
815
+                $lastedit_type,
816
+                $lastedit_user_id,
817
+                $calendar_date_value
818
+            );
819
+        }
820
+
821
+        return $affected_rows;
822
+    }
823
+
824
+    /**
825
+     * update users' attendance results
826
+     * @param 	array  $user_ids registered users inside current course
827
+     * @param	int	   $attendance_id
828
+     * @return 	void
829
+     */
830
+    public function update_users_results($user_ids, $attendance_id)
831
+    {
832
+        $tbl_attendance_sheet = Database::get_course_table(TABLE_ATTENDANCE_SHEET);
833
+        $tbl_attendance_result = Database::get_course_table(TABLE_ATTENDANCE_RESULT);
834
+        $tbl_attendance = Database::get_course_table(TABLE_ATTENDANCE);
835
+        $course_id = api_get_course_int_id();
836
+
837
+        $attendance_id = intval($attendance_id);
838
+        // fill results about presence of students
839 839
         $attendance_calendar = $this->get_attendance_calendar(
840 840
             $attendance_id,
841 841
             'all',
@@ -843,82 +843,82 @@  discard block
 block discarded – undo
843 843
             null,
844 844
             true
845 845
         );
846
-		$calendar_ids = array();
847
-		// get all dates from calendar by current attendance
848
-		foreach ($attendance_calendar as $cal) {
849
-			$calendar_ids[] = $cal['id'];
850
-		}
851
-
852
-		// get count of presences by users inside current attendance and save like results
853
-		if (count($user_ids) > 0) {
854
-			foreach ($user_ids as $uid) {
855
-				$count_presences = 0;
856
-				if (count($calendar_ids) > 0) {
857
-					$sql = "SELECT count(presence) as count_presences
846
+        $calendar_ids = array();
847
+        // get all dates from calendar by current attendance
848
+        foreach ($attendance_calendar as $cal) {
849
+            $calendar_ids[] = $cal['id'];
850
+        }
851
+
852
+        // get count of presences by users inside current attendance and save like results
853
+        if (count($user_ids) > 0) {
854
+            foreach ($user_ids as $uid) {
855
+                $count_presences = 0;
856
+                if (count($calendar_ids) > 0) {
857
+                    $sql = "SELECT count(presence) as count_presences
858 858
 							FROM $tbl_attendance_sheet
859 859
 					        WHERE
860 860
 					        	c_id = $course_id AND
861 861
 					        	user_id = '$uid' AND
862 862
 					        	attendance_calendar_id IN (".implode(',', $calendar_ids).") AND
863 863
 					        	presence = 1";
864
-					$rs_count  = Database::query($sql);
865
-					$row_count = Database::fetch_array($rs_count);
866
-					$count_presences = $row_count['count_presences'];
867
-				}
864
+                    $rs_count  = Database::query($sql);
865
+                    $row_count = Database::fetch_array($rs_count);
866
+                    $count_presences = $row_count['count_presences'];
867
+                }
868 868
 
869
-				// save results
870
-				$sql = "SELECT id FROM $tbl_attendance_result
869
+                // save results
870
+                $sql = "SELECT id FROM $tbl_attendance_result
871 871
 						WHERE
872 872
 							c_id = $course_id AND
873 873
 							user_id = '$uid' AND
874 874
 							attendance_id = '$attendance_id' ";
875
-				$rs_check_result = Database::query($sql);
875
+                $rs_check_result = Database::query($sql);
876 876
 
877
-				if (Database::num_rows($rs_check_result) > 0) {
878
-					// update result
879
-					$sql = "UPDATE $tbl_attendance_result SET
877
+                if (Database::num_rows($rs_check_result) > 0) {
878
+                    // update result
879
+                    $sql = "UPDATE $tbl_attendance_result SET
880 880
 							score = '$count_presences'
881 881
 							WHERE
882 882
 								c_id = $course_id AND
883 883
 								user_id='$uid' AND
884 884
 								attendance_id='$attendance_id'";
885
-					Database::query($sql);
886
-				} else {
887
-					// insert new result
888
-					$sql = "INSERT INTO $tbl_attendance_result SET
885
+                    Database::query($sql);
886
+                } else {
887
+                    // insert new result
888
+                    $sql = "INSERT INTO $tbl_attendance_result SET
889 889
 							c_id = $course_id ,
890 890
 							user_id			= '$uid',
891 891
 							attendance_id 	= '$attendance_id',
892 892
 							score			= '$count_presences'";
893
-					Database::query($sql);
893
+                    Database::query($sql);
894 894
 
895
-					$insertId = Database::insert_id();
895
+                    $insertId = Database::insert_id();
896 896
                     if ($insertId) {
897 897
                         $sql = "UPDATE $tbl_attendance_result SET id = iid WHERE iid = $insertId";
898 898
                         Database::query($sql);
899 899
                     }
900
-				}
901
-			}
902
-		}
900
+                }
901
+            }
902
+        }
903 903
 
904
-		// update attendance qualify max
905
-		$count_done_calendar = self::get_done_attendance_calendar($attendance_id);
904
+        // update attendance qualify max
905
+        $count_done_calendar = self::get_done_attendance_calendar($attendance_id);
906 906
 
907
-		$sql = "UPDATE $tbl_attendance SET
907
+        $sql = "UPDATE $tbl_attendance SET
908 908
 				attendance_qualify_max = '$count_done_calendar'
909 909
 				WHERE c_id = $course_id AND id = '$attendance_id'";
910
-		Database::query($sql);
911
-	}
912
-
913
-	/**
914
-	 * update attendance_sheet_log table, is used as history of an attendance sheet
915
-	 * @param   int     Attendance id
916
-	 * @param   string  Last edit datetime
917
-	 * @param   string  Event type ('locked_attendance', 'done_attendance_sheet' ...)
918
-	 * @param   int     Last edit user id
919
-	 * @param   string  Calendar datetime value (optional, when event type is 'done_attendance_sheet')
920
-	 * @return  int     Affected rows
921
-	 */
910
+        Database::query($sql);
911
+    }
912
+
913
+    /**
914
+     * update attendance_sheet_log table, is used as history of an attendance sheet
915
+     * @param   int     Attendance id
916
+     * @param   string  Last edit datetime
917
+     * @param   string  Event type ('locked_attendance', 'done_attendance_sheet' ...)
918
+     * @param   int     Last edit user id
919
+     * @param   string  Calendar datetime value (optional, when event type is 'done_attendance_sheet')
920
+     * @return  int     Affected rows
921
+     */
922 922
     public function save_attendance_sheet_log(
923 923
         $attendance_id,
924 924
         $lastedit_date,
@@ -926,22 +926,22 @@  discard block
 block discarded – undo
926 926
         $lastedit_user_id,
927 927
         $calendar_date_value = null
928 928
     ) {
929
-		$course_id = api_get_course_int_id();
929
+        $course_id = api_get_course_int_id();
930 930
 
931
-		// define table
932
-		$tbl_attendance_sheet_log = Database::get_course_table(TABLE_ATTENDANCE_SHEET_LOG);
931
+        // define table
932
+        $tbl_attendance_sheet_log = Database::get_course_table(TABLE_ATTENDANCE_SHEET_LOG);
933 933
 
934
-		// protect data
935
-		$attendance_id = intval($attendance_id);
936
-		$lastedit_user_id = intval($lastedit_user_id);
934
+        // protect data
935
+        $attendance_id = intval($attendance_id);
936
+        $lastedit_user_id = intval($lastedit_user_id);
937 937
 
938
-		if (isset($calendar_date_value)) {
939
-			$calendar_date_value = $calendar_date_value;
940
-		} else {
941
-			$calendar_date_value = '';
942
-		}
938
+        if (isset($calendar_date_value)) {
939
+            $calendar_date_value = $calendar_date_value;
940
+        } else {
941
+            $calendar_date_value = '';
942
+        }
943 943
 
944
-		// save data
944
+        // save data
945 945
         $params = [
946 946
             'c_id' => $course_id,
947 947
             'attendance_id' => $attendance_id,
@@ -950,228 +950,228 @@  discard block
 block discarded – undo
950 950
             'lastedit_user_id' => $lastedit_user_id,
951 951
             'calendar_date_value' => $calendar_date_value,
952 952
         ];
953
-		$insertId = Database::insert($tbl_attendance_sheet_log, $params);
953
+        $insertId = Database::insert($tbl_attendance_sheet_log, $params);
954 954
         if ($insertId) {
955 955
             $sql = "UPDATE $tbl_attendance_sheet_log SET id = iid WHERE iid = $insertId";
956 956
             Database::query($sql);
957 957
         }
958 958
 
959
-		return $insertId;
960
-	}
961
-
962
-	/**
963
-	 * Get number of done attendances inside current sheet
964
-	 * @param	int	   attendance id
965
-	 * @return 	int	   number of done attendances
966
-	 */
967
-	public static function get_done_attendance_calendar($attendance_id)
968
-	{
969
-		$tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
970
-		$attendance_id = intval($attendance_id);
971
-		$course_id = api_get_course_int_id();
972
-		$sql = "SELECT count(done_attendance) as count
959
+        return $insertId;
960
+    }
961
+
962
+    /**
963
+     * Get number of done attendances inside current sheet
964
+     * @param	int	   attendance id
965
+     * @return 	int	   number of done attendances
966
+     */
967
+    public static function get_done_attendance_calendar($attendance_id)
968
+    {
969
+        $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
970
+        $attendance_id = intval($attendance_id);
971
+        $course_id = api_get_course_int_id();
972
+        $sql = "SELECT count(done_attendance) as count
973 973
                 FROM $tbl_attendance_calendar
974 974
                 WHERE
975 975
                     c_id = $course_id AND
976 976
                     attendance_id = '$attendance_id' AND
977 977
                     done_attendance = 1
978 978
                 ";
979
-		$rs  = Database::query($sql);
980
-		$row = Database::fetch_array($rs);
981
-		$count = $row['count'];
982
-		return $count;
983
-	}
984
-
985
-	/**
986
-	 * Get results of faults (absents) by user
987
-	 * @param int $user_id
988
-	 * @param int $attendance_id
989
-	 * @param int $groupId
990
-	 * @return 	array  results containing number of faults, total done attendance,
991
-	 * percent of faults and color depend on result (red, orange)
992
-	 */
993
-	public function get_faults_of_user($user_id, $attendance_id, $groupId = null)
994
-	{
995
-		// initializing database table and variables
996
-		$user_id 		= intval($user_id);
997
-		$attendance_id 	= intval($attendance_id);
998
-		$results = array();
999
-		$calendar_count = self::get_number_of_attendance_calendar($attendance_id, $groupId, NULL, $user_id);
1000
-		// $total_done_attendance 	= $attendance_data['attendance_qualify_max'];
979
+        $rs  = Database::query($sql);
980
+        $row = Database::fetch_array($rs);
981
+        $count = $row['count'];
982
+        return $count;
983
+    }
984
+
985
+    /**
986
+     * Get results of faults (absents) by user
987
+     * @param int $user_id
988
+     * @param int $attendance_id
989
+     * @param int $groupId
990
+     * @return 	array  results containing number of faults, total done attendance,
991
+     * percent of faults and color depend on result (red, orange)
992
+     */
993
+    public function get_faults_of_user($user_id, $attendance_id, $groupId = null)
994
+    {
995
+        // initializing database table and variables
996
+        $user_id 		= intval($user_id);
997
+        $attendance_id 	= intval($attendance_id);
998
+        $results = array();
999
+        $calendar_count = self::get_number_of_attendance_calendar($attendance_id, $groupId, NULL, $user_id);
1000
+        // $total_done_attendance 	= $attendance_data['attendance_qualify_max'];
1001 1001
         $total_done_attendance 	= self::get_number_of_attendance_calendar($attendance_id, $groupId, true, $user_id);
1002
-		$attendance_user_score  = $this->get_user_score($user_id, $attendance_id, $groupId);
1002
+        $attendance_user_score  = $this->get_user_score($user_id, $attendance_id, $groupId);
1003 1003
 
1004
-		//This is the main change of the BT#1381
1005
-		//$total_done_attendance = $calendar_count;
1004
+        //This is the main change of the BT#1381
1005
+        //$total_done_attendance = $calendar_count;
1006 1006
 
1007
-		// calculate results
1008
-		$faults = $total_done_attendance - $attendance_user_score;
1007
+        // calculate results
1008
+        $faults = $total_done_attendance - $attendance_user_score;
1009 1009
 
1010 1010
         if (empty($calendar_count)) {
1011 1011
             $faults = 0;
1012 1012
         }
1013 1013
 
1014 1014
         $faults = $faults > 0 ? $faults : 0;
1015
-		$faults_porcent = $calendar_count > 0 ?round(($faults*100)/$calendar_count,0):0;
1015
+        $faults_porcent = $calendar_count > 0 ?round(($faults*100)/$calendar_count,0):0;
1016 1016
         $results['faults'] = $faults;
1017 1017
         $results['total'] = $calendar_count;
1018 1018
         $results['faults_porcent'] = $faults_porcent;
1019
-		$color_bar = '';
1019
+        $color_bar = '';
1020 1020
 
1021 1021
         if ($faults_porcent > 25) {
1022 1022
             $color_bar = '#f28989';
1023
-		} else if ($faults_porcent > 10) {
1024
-			$color_bar = '#F90';
1025
-		}
1026
-		$results['color_bar'] = $color_bar;
1027
-
1028
-		return $results;
1029
-	}
1030
-
1031
-	/**
1032
-	 * Get results of faults average for all courses by user
1033
-	 * @param	int	   $user_id
1034
-	 * @return 	array  results containing number of faults, total done attendance,
1035
-	 * percentage of faults and color depend on result (red, orange)
1036
-	 */
1037
-	public function get_faults_average_inside_courses($user_id)
1038
-	{
1039
-		// get all courses of current user
1040
-		$courses = CourseManager::get_courses_list_by_user_id($user_id, true);
1041
-
1042
-		$user_id = intval($user_id);
1043
-		$results = array();
1044
-		$total_faults = $total_weight = $porcent = 0;
1045
-		foreach ($courses as $course) {
1046
-			//$course_code = $course['code'];
1047
-			//$course_info = api_get_course_info($course_code);
1048
-			$course_id = $course['real_id'];
1049
-			$tbl_attendance_result 	= Database::get_course_table(TABLE_ATTENDANCE_RESULT);
1050
-
1051
-			$attendances_by_course = $this->get_attendances_list($course_id);
1052
-
1053
-			foreach ($attendances_by_course as $attendance) {
1054
-				// get total faults and total weight
1055
-				$total_done_attendance 	= $attendance['attendance_qualify_max'];
1056
-				$sql = "SELECT score
1023
+        } else if ($faults_porcent > 10) {
1024
+            $color_bar = '#F90';
1025
+        }
1026
+        $results['color_bar'] = $color_bar;
1027
+
1028
+        return $results;
1029
+    }
1030
+
1031
+    /**
1032
+     * Get results of faults average for all courses by user
1033
+     * @param	int	   $user_id
1034
+     * @return 	array  results containing number of faults, total done attendance,
1035
+     * percentage of faults and color depend on result (red, orange)
1036
+     */
1037
+    public function get_faults_average_inside_courses($user_id)
1038
+    {
1039
+        // get all courses of current user
1040
+        $courses = CourseManager::get_courses_list_by_user_id($user_id, true);
1041
+
1042
+        $user_id = intval($user_id);
1043
+        $results = array();
1044
+        $total_faults = $total_weight = $porcent = 0;
1045
+        foreach ($courses as $course) {
1046
+            //$course_code = $course['code'];
1047
+            //$course_info = api_get_course_info($course_code);
1048
+            $course_id = $course['real_id'];
1049
+            $tbl_attendance_result 	= Database::get_course_table(TABLE_ATTENDANCE_RESULT);
1050
+
1051
+            $attendances_by_course = $this->get_attendances_list($course_id);
1052
+
1053
+            foreach ($attendances_by_course as $attendance) {
1054
+                // get total faults and total weight
1055
+                $total_done_attendance 	= $attendance['attendance_qualify_max'];
1056
+                $sql = "SELECT score
1057 1057
 						FROM $tbl_attendance_result
1058 1058
                         WHERE
1059 1059
                         	c_id = $course_id AND
1060 1060
                         	user_id = $user_id AND
1061 1061
                         	attendance_id = ".$attendance['id'];
1062
-				$rs = Database::query($sql);
1063
-				$score = 0;
1064
-				if (Database::num_rows($rs) > 0) {
1065
-					$row = Database::fetch_array($rs);
1066
-					$score = $row['score'];
1067
-				}
1068
-				$faults = $total_done_attendance-$score;
1069
-				$faults = $faults > 0 ? $faults:0;
1070
-				$total_faults += $faults;
1071
-				$total_weight += $total_done_attendance;
1072
-			}
1073
-		}
1074
-
1075
-		$porcent = $total_weight > 0 ?round(($total_faults*100)/$total_weight,0):0;
1076
-		$results['faults'] 	= $total_faults;
1077
-		$results['total']	= $total_weight;
1078
-		$results['porcent'] = $porcent;
1079
-
1080
-		return $results;
1081
-	}
1082
-
1083
-	/**
1084
-	 * Get results of faults average by course
1085
-	 * @param	int	   $user_id
1086
-	 * @param 	string	$course_code
1087
-	 * @param	int	   Session id (optional)
1088
-	 * @return 	array  results containing number of faults,
1089
-	 * total done attendance, porcent of faults and color depend on result (red, orange)
1090
-	 */
1091
-	public function get_faults_average_by_course($user_id, $course_code, $session_id = null)
1092
-	{
1093
-		// Database tables and variables
1094
-		$course_info = api_get_course_info($course_code);
1095
-		$tbl_attendance_result 	= Database::get_course_table(TABLE_ATTENDANCE_RESULT);
1096
-		$user_id = intval($user_id);
1097
-		$results = array();
1098
-		$total_faults = $total_weight = $porcent = 0;
1099
-		$attendances_by_course = $this->get_attendances_list($course_info['real_id'], $session_id);
1100
-
1101
-		foreach ($attendances_by_course as $attendance) {
1102
-			// Get total faults and total weight
1103
-			$total_done_attendance 	= $attendance['attendance_qualify_max'];
1104
-			$sql = "SELECT score FROM $tbl_attendance_result
1105
-					WHERE
1062
+                $rs = Database::query($sql);
1063
+                $score = 0;
1064
+                if (Database::num_rows($rs) > 0) {
1065
+                    $row = Database::fetch_array($rs);
1066
+                    $score = $row['score'];
1067
+                }
1068
+                $faults = $total_done_attendance-$score;
1069
+                $faults = $faults > 0 ? $faults:0;
1070
+                $total_faults += $faults;
1071
+                $total_weight += $total_done_attendance;
1072
+            }
1073
+        }
1074
+
1075
+        $porcent = $total_weight > 0 ?round(($total_faults*100)/$total_weight,0):0;
1076
+        $results['faults'] 	= $total_faults;
1077
+        $results['total']	= $total_weight;
1078
+        $results['porcent'] = $porcent;
1079
+
1080
+        return $results;
1081
+    }
1082
+
1083
+    /**
1084
+     * Get results of faults average by course
1085
+     * @param	int	   $user_id
1086
+     * @param 	string	$course_code
1087
+     * @param	int	   Session id (optional)
1088
+     * @return 	array  results containing number of faults,
1089
+     * total done attendance, porcent of faults and color depend on result (red, orange)
1090
+     */
1091
+    public function get_faults_average_by_course($user_id, $course_code, $session_id = null)
1092
+    {
1093
+        // Database tables and variables
1094
+        $course_info = api_get_course_info($course_code);
1095
+        $tbl_attendance_result 	= Database::get_course_table(TABLE_ATTENDANCE_RESULT);
1096
+        $user_id = intval($user_id);
1097
+        $results = array();
1098
+        $total_faults = $total_weight = $porcent = 0;
1099
+        $attendances_by_course = $this->get_attendances_list($course_info['real_id'], $session_id);
1100
+
1101
+        foreach ($attendances_by_course as $attendance) {
1102
+            // Get total faults and total weight
1103
+            $total_done_attendance 	= $attendance['attendance_qualify_max'];
1104
+            $sql = "SELECT score FROM $tbl_attendance_result
1105
+					WHERE
1106 1106
 						c_id = {$course_info['real_id']} AND
1107 1107
 						user_id = $user_id AND
1108 1108
 						attendance_id=".$attendance['id'];
1109
-			$rs = Database::query($sql);
1110
-			$score = 0;
1111
-			if (Database::num_rows($rs) > 0) {
1112
-				$row = Database::fetch_array($rs);
1113
-				$score = $row['score'];
1114
-			}
1115
-			$faults = $total_done_attendance-$score;
1116
-			$faults = $faults > 0 ? $faults:0;
1117
-			$total_faults += $faults;
1118
-			$total_weight += $total_done_attendance;
1119
-		}
1120
-
1121
-		$porcent = $total_weight > 0 ?round(($total_faults*100)/$total_weight,0):0;
1122
-		$results['faults'] 	= $total_faults;
1123
-		$results['total']	= $total_weight;
1124
-		$results['porcent'] = $porcent;
1125
-
1126
-		return $results;
1127
-	}
1128
-
1129
-	/**
1130
-	 * Get registered users' attendance sheet inside current course
1131
-	 * @param	int	   $attendance_id
1132
-	 * @param	int	   $user_id for showing data for only one user (optional)
1133
-	 * @return 	array  users attendance sheet data
1134
-	 */
1135
-	public function get_users_attendance_sheet($attendance_id, $user_id = 0, $groupId = null)
1136
-	{
1137
-		$tbl_attendance_sheet 	= Database::get_course_table(TABLE_ATTENDANCE_SHEET);
1138
-		$tbl_attendance_calendar= Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1139
-
1140
-		$attendance_calendar = $this->get_attendance_calendar($attendance_id, 'all', null, $groupId);
1141
-		$calendar_ids = array();
1142
-		// get all dates from calendar by current attendance
1143
-		foreach ($attendance_calendar as $cal) {
1144
-			$calendar_ids[] = $cal['id'];
1145
-		}
1146
-
1147
-		$course_id = api_get_course_int_id();
1148
-
1149
-		$data = array();
1150
-		if (empty($user_id)) {
1151
-			// get all registered users inside current course
1152
-			$users = $this->get_users_rel_course();
1153
-			$user_ids = array_keys($users);
1154
-			if (count($calendar_ids) > 0 && count($user_ids) > 0) {
1155
-				foreach ($user_ids as $uid) {
1156
-					$sql = "SELECT * FROM $tbl_attendance_sheet
1109
+            $rs = Database::query($sql);
1110
+            $score = 0;
1111
+            if (Database::num_rows($rs) > 0) {
1112
+                $row = Database::fetch_array($rs);
1113
+                $score = $row['score'];
1114
+            }
1115
+            $faults = $total_done_attendance-$score;
1116
+            $faults = $faults > 0 ? $faults:0;
1117
+            $total_faults += $faults;
1118
+            $total_weight += $total_done_attendance;
1119
+        }
1120
+
1121
+        $porcent = $total_weight > 0 ?round(($total_faults*100)/$total_weight,0):0;
1122
+        $results['faults'] 	= $total_faults;
1123
+        $results['total']	= $total_weight;
1124
+        $results['porcent'] = $porcent;
1125
+
1126
+        return $results;
1127
+    }
1128
+
1129
+    /**
1130
+     * Get registered users' attendance sheet inside current course
1131
+     * @param	int	   $attendance_id
1132
+     * @param	int	   $user_id for showing data for only one user (optional)
1133
+     * @return 	array  users attendance sheet data
1134
+     */
1135
+    public function get_users_attendance_sheet($attendance_id, $user_id = 0, $groupId = null)
1136
+    {
1137
+        $tbl_attendance_sheet 	= Database::get_course_table(TABLE_ATTENDANCE_SHEET);
1138
+        $tbl_attendance_calendar= Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1139
+
1140
+        $attendance_calendar = $this->get_attendance_calendar($attendance_id, 'all', null, $groupId);
1141
+        $calendar_ids = array();
1142
+        // get all dates from calendar by current attendance
1143
+        foreach ($attendance_calendar as $cal) {
1144
+            $calendar_ids[] = $cal['id'];
1145
+        }
1146
+
1147
+        $course_id = api_get_course_int_id();
1148
+
1149
+        $data = array();
1150
+        if (empty($user_id)) {
1151
+            // get all registered users inside current course
1152
+            $users = $this->get_users_rel_course();
1153
+            $user_ids = array_keys($users);
1154
+            if (count($calendar_ids) > 0 && count($user_ids) > 0) {
1155
+                foreach ($user_ids as $uid) {
1156
+                    $sql = "SELECT * FROM $tbl_attendance_sheet
1157 1157
 					        WHERE
1158 1158
 					        	c_id = $course_id AND
1159 1159
 					        	user_id = '$uid' AND
1160 1160
 					        	attendance_calendar_id IN(".implode(',',$calendar_ids).")
1161 1161
 							";
1162
-					$res = Database::query($sql);
1163
-					if (Database::num_rows($res) > 0) {
1164
-						while ($row = Database::fetch_array($res)) {
1165
-							$data[$uid][$row['attendance_calendar_id']]['presence'] = $row['presence'];
1166
-						}
1167
-					}
1168
-				}
1169
-			}
1170
-		} else {
1171
-			// Get attendance for current user
1172
-			$user_id = intval($user_id);
1173
-			if (count($calendar_ids) > 0) {
1174
-				$sql = "SELECT cal.date_time, att.presence
1162
+                    $res = Database::query($sql);
1163
+                    if (Database::num_rows($res) > 0) {
1164
+                        while ($row = Database::fetch_array($res)) {
1165
+                            $data[$uid][$row['attendance_calendar_id']]['presence'] = $row['presence'];
1166
+                        }
1167
+                    }
1168
+                }
1169
+            }
1170
+        } else {
1171
+            // Get attendance for current user
1172
+            $user_id = intval($user_id);
1173
+            if (count($calendar_ids) > 0) {
1174
+                $sql = "SELECT cal.date_time, att.presence
1175 1175
                         FROM $tbl_attendance_sheet att
1176 1176
 						INNER JOIN  $tbl_attendance_calendar cal
1177 1177
 						ON cal.id = att.attendance_calendar_id
@@ -1181,87 +1181,87 @@  discard block
 block discarded – undo
1181 1181
 							att.user_id = '$user_id' AND
1182 1182
 							att.attendance_calendar_id IN (".implode(',',$calendar_ids).")
1183 1183
                         ORDER BY date_time";
1184
-				$res = Database::query($sql);
1185
-				if (Database::num_rows($res) > 0) {
1186
-					while ($row = Database::fetch_array($res)) {
1187
-						$row['date_time'] = api_convert_and_format_date($row['date_time'], null, date_default_timezone_get());
1188
-						$data[$user_id][] = $row;
1189
-					}
1190
-				}
1191
-			}
1192
-		}
1193
-		return $data;
1194
-	}
1195
-
1196
-	/**
1197
-	 * Get next attendance calendar without presences (done attendances)
1198
-	 * @param	int	attendance id
1199
-	 * @return 	int attendance calendar id
1200
-	 */
1201
-	public function get_next_attendance_calendar_id($attendance_id)
1202
-	{
1203
-		$tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1204
-		$attendance_id = intval($attendance_id);
1205
-		$course_id = api_get_course_int_id();
1206
-
1207
-		$sql = "SELECT id FROM $tbl_attendance_calendar
1184
+                $res = Database::query($sql);
1185
+                if (Database::num_rows($res) > 0) {
1186
+                    while ($row = Database::fetch_array($res)) {
1187
+                        $row['date_time'] = api_convert_and_format_date($row['date_time'], null, date_default_timezone_get());
1188
+                        $data[$user_id][] = $row;
1189
+                    }
1190
+                }
1191
+            }
1192
+        }
1193
+        return $data;
1194
+    }
1195
+
1196
+    /**
1197
+     * Get next attendance calendar without presences (done attendances)
1198
+     * @param	int	attendance id
1199
+     * @return 	int attendance calendar id
1200
+     */
1201
+    public function get_next_attendance_calendar_id($attendance_id)
1202
+    {
1203
+        $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1204
+        $attendance_id = intval($attendance_id);
1205
+        $course_id = api_get_course_int_id();
1206
+
1207
+        $sql = "SELECT id FROM $tbl_attendance_calendar
1208 1208
 		        WHERE
1209 1209
 		        	c_id = $course_id AND
1210 1210
 		        	attendance_id = '$attendance_id' AND
1211 1211
 		        	done_attendance = 0
1212 1212
 		        ORDER BY date_time
1213 1213
 		        LIMIT 1";
1214
-		$rs = Database::query($sql);
1215
-		$next_calendar_id = 0;
1216
-		if (Database::num_rows($rs) > 0) {
1217
-			$row = Database::fetch_array($rs);
1218
-			$next_calendar_id = $row['id'];
1219
-		}
1220
-		return $next_calendar_id;
1221
-	}
1222
-
1223
-	/**
1224
-	 * Get next attendance calendar datetime without presences (done attendances)
1225
-	 * @param	int	attendance id
1226
-	 * @return 	int UNIX time format datetime
1227
-	 */
1228
-	public function get_next_attendance_calendar_datetime($attendance_id)
1229
-	{
1230
-		$tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1231
-		$course_id = api_get_course_int_id();
1232
-		$attendance_id = intval($attendance_id);
1233
-		$sql = "SELECT id, date_time FROM $tbl_attendance_calendar
1214
+        $rs = Database::query($sql);
1215
+        $next_calendar_id = 0;
1216
+        if (Database::num_rows($rs) > 0) {
1217
+            $row = Database::fetch_array($rs);
1218
+            $next_calendar_id = $row['id'];
1219
+        }
1220
+        return $next_calendar_id;
1221
+    }
1222
+
1223
+    /**
1224
+     * Get next attendance calendar datetime without presences (done attendances)
1225
+     * @param	int	attendance id
1226
+     * @return 	int UNIX time format datetime
1227
+     */
1228
+    public function get_next_attendance_calendar_datetime($attendance_id)
1229
+    {
1230
+        $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1231
+        $course_id = api_get_course_int_id();
1232
+        $attendance_id = intval($attendance_id);
1233
+        $sql = "SELECT id, date_time FROM $tbl_attendance_calendar
1234 1234
 				WHERE
1235 1235
 					c_id = $course_id AND
1236 1236
 					attendance_id = '$attendance_id' AND
1237 1237
 					done_attendance = 0
1238 1238
 				ORDER BY date_time
1239 1239
 				LIMIT 1";
1240
-		$rs = Database::query($sql);
1241
-		$next_calendar_datetime = 0;
1242
-		if (Database::num_rows($rs) > 0) {
1243
-			$row = Database::fetch_array($rs);
1244
-			$next_calendar_datetime = api_get_local_time($row['date_time']);
1245
-		}
1246
-
1247
-		return $next_calendar_datetime;
1248
-	}
1249
-
1250
-	/**
1251
-	 * Get user' score from current attendance
1252
-	 * @param	int	$user_id
1253
-	 * @param	int $attendance_id
1254
-	 * @return	int score
1255
-	 */
1256
-	public function get_user_score($user_id, $attendance_id, $groupId = null)
1257
-	{
1258
-		$tbl_attendance_result 	= Database::get_course_table(TABLE_ATTENDANCE_RESULT);
1240
+        $rs = Database::query($sql);
1241
+        $next_calendar_datetime = 0;
1242
+        if (Database::num_rows($rs) > 0) {
1243
+            $row = Database::fetch_array($rs);
1244
+            $next_calendar_datetime = api_get_local_time($row['date_time']);
1245
+        }
1246
+
1247
+        return $next_calendar_datetime;
1248
+    }
1249
+
1250
+    /**
1251
+     * Get user' score from current attendance
1252
+     * @param	int	$user_id
1253
+     * @param	int $attendance_id
1254
+     * @return	int score
1255
+     */
1256
+    public function get_user_score($user_id, $attendance_id, $groupId = null)
1257
+    {
1258
+        $tbl_attendance_result 	= Database::get_course_table(TABLE_ATTENDANCE_RESULT);
1259 1259
         $tbl_attendance_sheet = Database::get_course_table(TABLE_ATTENDANCE_SHEET);
1260 1260
         $tbl_attendance_cal_rel_group = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR_REL_GROUP);
1261 1261
         $tbl_attendance_cal = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1262
-		$user_id = intval($user_id);
1263
-		$attendance_id = intval($attendance_id);
1264
-		$course_id = api_get_course_int_id();
1262
+        $user_id = intval($user_id);
1263
+        $attendance_id = intval($attendance_id);
1264
+        $course_id = api_get_course_int_id();
1265 1265
         if (empty($groupId)) {
1266 1266
             $sql = "SELECT score FROM $tbl_attendance_result
1267 1267
                     WHERE
@@ -1285,68 +1285,68 @@  discard block
 block discarded – undo
1285 1285
                         )
1286 1286
                     ";
1287 1287
         }
1288
-		$rs = Database::query($sql);
1289
-		$score = 0;
1290
-		if (Database::num_rows($rs) > 0) {
1291
-			$row = Database::fetch_array($rs);
1292
-			$score = $row['score'];
1293
-		}
1294
-
1295
-		return $score;
1296
-	}
1297
-
1298
-	/**
1299
-	 * Get attendance calendar data by id
1300
-	 * @param	int	attendance calendar id
1301
-	 * @return	array attendance calendar data
1302
-	 */
1303
-	public function get_attendance_calendar_by_id($calendar_id)
1304
-	{
1305
-		$tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1306
-		$calendar_id = intval($calendar_id);
1307
-		$course_id = api_get_course_int_id();
1308
-		$sql = "SELECT * FROM $tbl_attendance_calendar
1288
+        $rs = Database::query($sql);
1289
+        $score = 0;
1290
+        if (Database::num_rows($rs) > 0) {
1291
+            $row = Database::fetch_array($rs);
1292
+            $score = $row['score'];
1293
+        }
1294
+
1295
+        return $score;
1296
+    }
1297
+
1298
+    /**
1299
+     * Get attendance calendar data by id
1300
+     * @param	int	attendance calendar id
1301
+     * @return	array attendance calendar data
1302
+     */
1303
+    public function get_attendance_calendar_by_id($calendar_id)
1304
+    {
1305
+        $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1306
+        $calendar_id = intval($calendar_id);
1307
+        $course_id = api_get_course_int_id();
1308
+        $sql = "SELECT * FROM $tbl_attendance_calendar
1309 1309
 				WHERE c_id = $course_id AND id = '$calendar_id' ";
1310
-		$rs = Database::query($sql);
1311
-		$data = array();
1312
-		if (Database::num_rows($rs) > 0) {
1313
-			while ($row = Database::fetch_array($rs)) {
1314
-				$row['date_time'] = api_get_local_time($row['date_time']);
1315
-				$data = $row;
1316
-			}
1317
-		}
1318
-
1319
-		return $data;
1320
-	}
1321
-
1322
-	/**
1323
-	 * Get all attendance calendar data inside current attendance
1324
-	 * @param int	$attendance_id
1325
-	 * @param string $type
1326
-	 * @param int $calendar_id
1327
-	 * @param int $groupId
1328
-	 * @param bool $showAll = false show group calendar items or not
1329
-	 *
1330
-	 * @return	array attendance calendar data
1331
-	 */
1332
-	public function get_attendance_calendar(
1333
-		$attendance_id,
1334
-		$type = 'all',
1335
-		$calendar_id = null,
1336
-		$groupId = null,
1337
-		$showAll = false
1338
-	) {
1339
-		$tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1310
+        $rs = Database::query($sql);
1311
+        $data = array();
1312
+        if (Database::num_rows($rs) > 0) {
1313
+            while ($row = Database::fetch_array($rs)) {
1314
+                $row['date_time'] = api_get_local_time($row['date_time']);
1315
+                $data = $row;
1316
+            }
1317
+        }
1318
+
1319
+        return $data;
1320
+    }
1321
+
1322
+    /**
1323
+     * Get all attendance calendar data inside current attendance
1324
+     * @param int	$attendance_id
1325
+     * @param string $type
1326
+     * @param int $calendar_id
1327
+     * @param int $groupId
1328
+     * @param bool $showAll = false show group calendar items or not
1329
+     *
1330
+     * @return	array attendance calendar data
1331
+     */
1332
+    public function get_attendance_calendar(
1333
+        $attendance_id,
1334
+        $type = 'all',
1335
+        $calendar_id = null,
1336
+        $groupId = null,
1337
+        $showAll = false
1338
+    ) {
1339
+        $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1340 1340
         $tbl_acrg = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR_REL_GROUP);
1341
-		$attendance_id = intval($attendance_id);
1342
-		$course_id = api_get_course_int_id();
1343
-		$groupCondition = null;
1341
+        $attendance_id = intval($attendance_id);
1342
+        $course_id = api_get_course_int_id();
1343
+        $groupCondition = null;
1344 1344
 
1345
-		if ($showAll) {
1346
-			$sql = "SELECT * FROM $tbl_attendance_calendar c
1345
+        if ($showAll) {
1346
+            $sql = "SELECT * FROM $tbl_attendance_calendar c
1347 1347
 					WHERE c_id = $course_id AND attendance_id = '$attendance_id'";
1348
-		} else {
1349
-			$sql = "SELECT * FROM $tbl_attendance_calendar c
1348
+        } else {
1349
+            $sql = "SELECT * FROM $tbl_attendance_calendar c
1350 1350
 					WHERE
1351 1351
 						c_id = $course_id AND
1352 1352
 						attendance_id = '$attendance_id' AND
@@ -1355,11 +1355,11 @@  discard block
 block discarded – undo
1355 1355
 							WHERE c_id = $course_id AND group_id != 0 AND group_id IS NOT NULL
1356 1356
 						)
1357 1357
 					";
1358
-		}
1358
+        }
1359 1359
 
1360
-		if (!empty($groupId)) {
1361
-			$groupId = intval($groupId);
1362
-			$sql = "SELECT c.* FROM $tbl_attendance_calendar c
1360
+        if (!empty($groupId)) {
1361
+            $groupId = intval($groupId);
1362
+            $sql = "SELECT c.* FROM $tbl_attendance_calendar c
1363 1363
 					INNER JOIN $tbl_acrg g
1364 1364
 					ON c.c_id = g.c_id AND c.id = g.calendar_id
1365 1365
 					WHERE
@@ -1367,62 +1367,62 @@  discard block
 block discarded – undo
1367 1367
 					    g.group_id = '$groupId' AND
1368 1368
 					    c.attendance_id = '$attendance_id'
1369 1369
                    ";
1370
-		}
1371
-
1372
-		if (!in_array($type, array('today', 'all', 'all_done', 'all_not_done','calendar_id'))) {
1373
-			$type = 'all';
1374
-		}
1375
-
1376
-		switch ($type) {
1377
-			case 'calendar_id':
1378
-				$calendar_id = intval($calendar_id);
1379
-				if (!empty($calendar_id)) {
1380
-					$sql.= " AND c.id = $calendar_id";
1381
-				}
1382
-				break;
1383
-			case 'today':
1384
-				//$sql .= ' AND DATE_FORMAT(date_time,"%d-%m-%Y") = DATE_FORMAT("'.api_get_utc_datetime().'", "%d-%m-%Y" )';
1385
-				break;
1386
-			case 'all_done':
1387
-				$sql .= " AND done_attendance = 1 ";
1388
-				break;
1389
-			case 'all_not_done':
1390
-				$sql .= " AND done_attendance = 0 ";
1391
-				break;
1392
-			case 'all':
1393
-			default:
1394
-				break;
1395
-		}
1396
-		$sql .= " ORDER BY date_time ";
1370
+        }
1397 1371
 
1398
-		$rs = Database::query($sql);
1399
-		$data = array();
1400
-		if (Database::num_rows($rs) > 0) {
1401
-			while ($row = Database::fetch_array($rs,'ASSOC')) {
1402
-				$row['db_date_time'] = $row['date_time'];
1403
-				$row['date_time'] = api_get_local_time($row['date_time']);
1404
-				$row['date'] = api_format_date($row['date_time'], DATE_FORMAT_SHORT);
1405
-				$row['time'] = api_format_date($row['date_time'], TIME_NO_SEC_FORMAT);
1406
-				$row['groups'] = $this->getGroupListByAttendanceCalendar($row['id'], $course_id);
1407
-				if ($type == 'today') {
1408
-					if (date('d-m-Y', api_strtotime($row['date_time'], 'UTC')) == date('d-m-Y', time())) {
1409
-						$data[] = $row;
1410
-					}
1411
-				} else {
1412
-					$data[] = $row;
1413
-				}
1414
-			}
1415
-		}
1416
-
1417
-		return $data;
1418
-	}
1419
-
1420
-	/**
1421
-	 * Get number of attendance calendar inside current attendance
1422
-	 * @param	int	$attendance_id
1423
-	 * @param	int	$groupId
1424
-	 * @return	int number of dates in attendance calendar
1425
-	 */
1372
+        if (!in_array($type, array('today', 'all', 'all_done', 'all_not_done','calendar_id'))) {
1373
+            $type = 'all';
1374
+        }
1375
+
1376
+        switch ($type) {
1377
+            case 'calendar_id':
1378
+                $calendar_id = intval($calendar_id);
1379
+                if (!empty($calendar_id)) {
1380
+                    $sql.= " AND c.id = $calendar_id";
1381
+                }
1382
+                break;
1383
+            case 'today':
1384
+                //$sql .= ' AND DATE_FORMAT(date_time,"%d-%m-%Y") = DATE_FORMAT("'.api_get_utc_datetime().'", "%d-%m-%Y" )';
1385
+                break;
1386
+            case 'all_done':
1387
+                $sql .= " AND done_attendance = 1 ";
1388
+                break;
1389
+            case 'all_not_done':
1390
+                $sql .= " AND done_attendance = 0 ";
1391
+                break;
1392
+            case 'all':
1393
+            default:
1394
+                break;
1395
+        }
1396
+        $sql .= " ORDER BY date_time ";
1397
+
1398
+        $rs = Database::query($sql);
1399
+        $data = array();
1400
+        if (Database::num_rows($rs) > 0) {
1401
+            while ($row = Database::fetch_array($rs,'ASSOC')) {
1402
+                $row['db_date_time'] = $row['date_time'];
1403
+                $row['date_time'] = api_get_local_time($row['date_time']);
1404
+                $row['date'] = api_format_date($row['date_time'], DATE_FORMAT_SHORT);
1405
+                $row['time'] = api_format_date($row['date_time'], TIME_NO_SEC_FORMAT);
1406
+                $row['groups'] = $this->getGroupListByAttendanceCalendar($row['id'], $course_id);
1407
+                if ($type == 'today') {
1408
+                    if (date('d-m-Y', api_strtotime($row['date_time'], 'UTC')) == date('d-m-Y', time())) {
1409
+                        $data[] = $row;
1410
+                    }
1411
+                } else {
1412
+                    $data[] = $row;
1413
+                }
1414
+            }
1415
+        }
1416
+
1417
+        return $data;
1418
+    }
1419
+
1420
+    /**
1421
+     * Get number of attendance calendar inside current attendance
1422
+     * @param	int	$attendance_id
1423
+     * @param	int	$groupId
1424
+     * @return	int number of dates in attendance calendar
1425
+     */
1426 1426
     public static function get_number_of_attendance_calendar($attendance_id, $groupId = 0, $done_attendance = NULL, $userId = 0)
1427 1427
     {
1428 1428
         $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
@@ -1508,111 +1508,111 @@  discard block
 block discarded – undo
1508 1508
 
1509 1509
 
1510 1510
     /**
1511
-	 * Get count dates inside attendance calendar by attendance id
1512
-	 * @param	int	$attendance_id
1513
-	 * @return	int     count of dates
1514
-	 */
1515
-	public static function get_count_dates_inside_attendance_calendar($attendance_id)
1516
-	{
1517
-		$tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1518
-		$attendance_id = intval($attendance_id);
1519
-		$course_id = api_get_course_int_id();
1520
-		$sql = "SELECT count(id) FROM $tbl_attendance_calendar
1511
+     * Get count dates inside attendance calendar by attendance id
1512
+     * @param	int	$attendance_id
1513
+     * @return	int     count of dates
1514
+     */
1515
+    public static function get_count_dates_inside_attendance_calendar($attendance_id)
1516
+    {
1517
+        $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1518
+        $attendance_id = intval($attendance_id);
1519
+        $course_id = api_get_course_int_id();
1520
+        $sql = "SELECT count(id) FROM $tbl_attendance_calendar
1521 1521
                 WHERE
1522 1522
                 	c_id = $course_id AND
1523 1523
                 	attendance_id = '$attendance_id'";
1524
-		$rs = Database::query($sql);
1525
-		$count = 0;
1526
-		if (Database::num_rows($rs) > 0) {
1527
-			$row = Database::fetch_row($rs);
1528
-			$count = $row[0];
1529
-		}
1530
-		return $count;
1531
-	}
1532
-
1533
-	/**
1534
-	 * check if all calendar of an attendance is done
1535
-	 * @param   int     $attendance_id
1536
-	 * @return  bool    True if all calendar is done, otherwise false
1537
-	 */
1538
-	public static function is_all_attendance_calendar_done($attendance_id)
1539
-	{
1540
-		$attendance_id = intval($attendance_id);
1541
-		$done_calendar = self::get_done_attendance_calendar($attendance_id);
1542
-		$count_dates_in_calendar = self::get_count_dates_inside_attendance_calendar($attendance_id);
1543
-		$number_of_dates = self::get_number_of_attendance_calendar($attendance_id);
1544
-
1545
-		$result = false;
1546
-		if ($number_of_dates && (intval($count_dates_in_calendar) == intval($done_calendar))) {
1547
-			$result = true;
1548
-		}
1549
-		return $result;
1550
-	}
1551
-
1552
-	/**
1553
-	 * check if an attendance is locked
1554
-	 * @param   int $attendance_id
1555
-	 * @param   bool
1556
-	 */
1557
-	public static function is_locked_attendance($attendance_id)
1558
-	{
1559
-		//use gradebook lock
1560
-		$result = api_resource_is_locked_by_gradebook($attendance_id, LINK_ATTENDANCE);
1561
-		return $result;
1562
-	}
1563
-
1564
-	/**
1565
-	 * Add new datetime inside attendance calendar table
1566
-	 * @param	int		$attendance_id
1567
-	 * @param 	array 	$groupList
1568
-	 * @return	int affected rows
1569
-	 */
1570
-	public function attendance_calendar_add($attendance_id, $groupList = array())
1571
-	{
1572
-		$tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1573
-		$affected_rows = 0;
1574
-		$attendance_id = intval($attendance_id);
1575
-		$course_id = api_get_course_int_id();
1576
-		// check if datetime already exists inside the table
1577
-		/*$sql = "SELECT id FROM $tbl_attendance_calendar
1524
+        $rs = Database::query($sql);
1525
+        $count = 0;
1526
+        if (Database::num_rows($rs) > 0) {
1527
+            $row = Database::fetch_row($rs);
1528
+            $count = $row[0];
1529
+        }
1530
+        return $count;
1531
+    }
1532
+
1533
+    /**
1534
+     * check if all calendar of an attendance is done
1535
+     * @param   int     $attendance_id
1536
+     * @return  bool    True if all calendar is done, otherwise false
1537
+     */
1538
+    public static function is_all_attendance_calendar_done($attendance_id)
1539
+    {
1540
+        $attendance_id = intval($attendance_id);
1541
+        $done_calendar = self::get_done_attendance_calendar($attendance_id);
1542
+        $count_dates_in_calendar = self::get_count_dates_inside_attendance_calendar($attendance_id);
1543
+        $number_of_dates = self::get_number_of_attendance_calendar($attendance_id);
1544
+
1545
+        $result = false;
1546
+        if ($number_of_dates && (intval($count_dates_in_calendar) == intval($done_calendar))) {
1547
+            $result = true;
1548
+        }
1549
+        return $result;
1550
+    }
1551
+
1552
+    /**
1553
+     * check if an attendance is locked
1554
+     * @param   int $attendance_id
1555
+     * @param   bool
1556
+     */
1557
+    public static function is_locked_attendance($attendance_id)
1558
+    {
1559
+        //use gradebook lock
1560
+        $result = api_resource_is_locked_by_gradebook($attendance_id, LINK_ATTENDANCE);
1561
+        return $result;
1562
+    }
1563
+
1564
+    /**
1565
+     * Add new datetime inside attendance calendar table
1566
+     * @param	int		$attendance_id
1567
+     * @param 	array 	$groupList
1568
+     * @return	int affected rows
1569
+     */
1570
+    public function attendance_calendar_add($attendance_id, $groupList = array())
1571
+    {
1572
+        $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1573
+        $affected_rows = 0;
1574
+        $attendance_id = intval($attendance_id);
1575
+        $course_id = api_get_course_int_id();
1576
+        // check if datetime already exists inside the table
1577
+        /*$sql = "SELECT id FROM $tbl_attendance_calendar
1578 1578
 		        WHERE
1579 1579
 		        	c_id = $course_id AND
1580 1580
 		        	date_time='".Database::escape_string($this->date_time)."' AND
1581 1581
 		        	attendance_id = '$attendance_id'";
1582 1582
 		$rs = Database::query($sql);
1583 1583
 		if (Database::num_rows($rs) == 0) {*/
1584
-			$params = array(
1585
-				'c_id' =>  $course_id,
1586
-				'date_time' => $this->date_time,
1587
-				'attendance_id' => $attendance_id
1588
-			);
1589
-			$id = Database::insert($tbl_attendance_calendar, $params);
1590
-
1591
-			if ($id) {
1592
-				$sql = "UPDATE $tbl_attendance_calendar SET id = iid WHERE iid = $id";
1593
-				Database::query($sql);
1594
-				$affected_rows++;
1595
-			}
1596
-			$this->addAttendanceCalendarToGroup($id, $course_id, $groupList);
1597
-		//}
1598
-
1599
-		// update locked attendance
1600
-		$is_all_calendar_done = self::is_all_attendance_calendar_done($attendance_id);
1601
-		if (!$is_all_calendar_done) {
1602
-			self::lock_attendance($attendance_id, false);
1603
-		} else {
1604
-			self::lock_attendance($attendance_id);
1605
-		}
1606
-		return $affected_rows;
1607
-	}
1608
-
1609
-	/**
1610
-	 * @param int   $calendarId
1611
-	 * @param int 	$courseId
1612
-	 * @param array $groupList
1613
-	 */
1614
-	public function addAttendanceCalendarToGroup($calendarId, $courseId, $groupList)
1615
-	{
1584
+            $params = array(
1585
+                'c_id' =>  $course_id,
1586
+                'date_time' => $this->date_time,
1587
+                'attendance_id' => $attendance_id
1588
+            );
1589
+            $id = Database::insert($tbl_attendance_calendar, $params);
1590
+
1591
+            if ($id) {
1592
+                $sql = "UPDATE $tbl_attendance_calendar SET id = iid WHERE iid = $id";
1593
+                Database::query($sql);
1594
+                $affected_rows++;
1595
+            }
1596
+            $this->addAttendanceCalendarToGroup($id, $course_id, $groupList);
1597
+        //}
1598
+
1599
+        // update locked attendance
1600
+        $is_all_calendar_done = self::is_all_attendance_calendar_done($attendance_id);
1601
+        if (!$is_all_calendar_done) {
1602
+            self::lock_attendance($attendance_id, false);
1603
+        } else {
1604
+            self::lock_attendance($attendance_id);
1605
+        }
1606
+        return $affected_rows;
1607
+    }
1608
+
1609
+    /**
1610
+     * @param int   $calendarId
1611
+     * @param int 	$courseId
1612
+     * @param array $groupList
1613
+     */
1614
+    public function addAttendanceCalendarToGroup($calendarId, $courseId, $groupList)
1615
+    {
1616 1616
         if (empty($groupList)) {
1617 1617
             return false;
1618 1618
         }
@@ -1640,506 +1640,506 @@  discard block
 block discarded – undo
1640 1640
                 Database::insert($table, $params);
1641 1641
             }
1642 1642
         }
1643
-	}
1644
-
1645
-	/**
1646
-	 * @param int $calendarId
1647
-	 * @param int $courseId
1648
-	 * @param int $groupId
1649
-	 * @return array
1650
-	 */
1651
-	public function getGroupListByAttendanceCalendar($calendarId, $courseId)
1652
-	{
1653
-		$table = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR_REL_GROUP);
1654
-		return Database::select(
1655
-			'*',
1656
-			$table,
1657
-			array('where'=>
1658
-				array(
1659
-					'calendar_id = ? AND c_id = ?' => array($calendarId, $courseId)
1660
-				)
1661
-			)
1662
-		);
1663
-	}
1664
-
1665
-	/**
1666
-	 * @param int $calendarId
1667
-	 * @param int $courseId
1668
-	 * @param int $groupId
1669
-	 * @return array
1670
-	 */
1671
-	public function getAttendanceCalendarGroup($calendarId, $courseId, $groupId)
1672
-	{
1673
-		$table = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR_REL_GROUP);
1674
-		return Database::select(
1675
-			'*',
1676
-			$table,
1677
-			array('where'=>
1678
-				array(
1679
-					'calendar_id = ? AND c_id = ? AND group_id = ?' => array($calendarId, $courseId, $groupId)
1680
-				)
1681
-			)
1682
-		);
1683
-	}
1684
-
1685
-	/**
1686
-	 * @param int $calendarId
1687
-	 * @param int $courseId
1688
-	 * @param int $groupId
1643
+    }
1644
+
1645
+    /**
1646
+     * @param int $calendarId
1647
+     * @param int $courseId
1648
+     * @param int $groupId
1649
+     * @return array
1650
+     */
1651
+    public function getGroupListByAttendanceCalendar($calendarId, $courseId)
1652
+    {
1653
+        $table = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR_REL_GROUP);
1654
+        return Database::select(
1655
+            '*',
1656
+            $table,
1657
+            array('where'=>
1658
+                array(
1659
+                    'calendar_id = ? AND c_id = ?' => array($calendarId, $courseId)
1660
+                )
1661
+            )
1662
+        );
1663
+    }
1664
+
1665
+    /**
1666
+     * @param int $calendarId
1667
+     * @param int $courseId
1668
+     * @param int $groupId
1669
+     * @return array
1670
+     */
1671
+    public function getAttendanceCalendarGroup($calendarId, $courseId, $groupId)
1672
+    {
1673
+        $table = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR_REL_GROUP);
1674
+        return Database::select(
1675
+            '*',
1676
+            $table,
1677
+            array('where'=>
1678
+                array(
1679
+                    'calendar_id = ? AND c_id = ? AND group_id = ?' => array($calendarId, $courseId, $groupId)
1680
+                )
1681
+            )
1682
+        );
1683
+    }
1684
+
1685
+    /**
1686
+     * @param int $calendarId
1687
+     * @param int $courseId
1688
+     * @param int $groupId
1689 1689
      *
1690
-	 * @return array
1691
-	 */
1692
-	public function deleteAttendanceCalendarGroup($calendarId, $courseId)
1693
-	{
1694
-		$table = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR_REL_GROUP);
1695
-		Database::delete(
1696
-			$table,
1697
-			array(
1698
-				'calendar_id = ? AND c_id = ?' => array($calendarId, $courseId)
1699
-			)
1700
-		);
1701
-	}
1702
-
1703
-	/**
1704
-	 * save repeated date inside attendance calendar table
1705
-	 * @param int $attendance_id
1706
-	 * @param int $start_date start date in tms
1707
-	 * @param int $end_date end date in tms
1708
-	 * @param string $repeat_type daily, weekly, monthlyByDate
1709
-	 * @param array $groupList
1710
-	 */
1711
-	public function attendance_repeat_calendar_add(
1712
-		$attendance_id,
1713
-		$start_date,
1714
-		$end_date,
1715
-		$repeat_type,
1716
-		$groupList = array()
1717
-	) {
1718
-		$attendance_id = intval($attendance_id);
1719
-		// save start date
1720
-		$datetimezone = api_get_utc_datetime($start_date);
1721
-		$this->set_date_time($datetimezone);
1722
-		$this->attendance_calendar_add($attendance_id, $groupList);
1723
-
1724
-		// 86400 = 24 hours in seconds
1725
-		// 604800 = 1 week in seconds
1726
-		// Saves repeated dates
1727
-		switch ($repeat_type) {
1728
-			case 'daily':
1729
-				$j = 1;
1730
-				for ($i = $start_date + 86400; ($i <= $end_date); $i += 86400) {
1731
-					$datetimezone = api_get_utc_datetime($i);
1732
-					$this->set_date_time($datetimezone);
1733
-					$this->attendance_calendar_add($attendance_id, $groupList);
1734
-					$j++;
1735
-				}
1736
-				break;
1737
-			case 'weekly':
1738
-				$j = 1;
1739
-				for ($i = $start_date + 604800; ($i <= $end_date); $i += 604800) {
1740
-					$datetimezone = api_get_utc_datetime($i);
1741
-					$this->set_date_time($datetimezone);
1742
-					$this->attendance_calendar_add($attendance_id, $groupList);
1743
-					$j++;
1744
-				}
1745
-				break;
1746
-			case 'monthlyByDate':
1747
-				$j = 1;
1748
-				//@todo fix bug with february
1749
-				for ($i = $start_date + 2419200; ($i <= $end_date); $i += 2419200) {
1750
-					$datetimezone = api_get_utc_datetime($i);
1751
-					$this->set_date_time($datetimezone);
1752
-					$this->attendance_calendar_add($attendance_id, $groupList);
1753
-					$j++;
1754
-				}
1755
-				break;
1756
-		}
1757
-	}
1758
-
1759
-	/**
1760
-	 * Adds x months to a UNIX timestamp
1761
-	 * @param   int     The timestamp
1762
-	 * @param   int     The number of years to add
1763
-	 * @return  int     The new timestamp
1764
-	 */
1765
-	private function add_month($timestamp, $num=1)
1766
-	{
1767
-		$values = api_get_utc_datetime($timestamp);
1768
-		$values = str_replace(array(':','-',' '), '/', $values);
1769
-		list($y, $m, $d, $h, $n, $s) = split('/',$values);
1770
-		if($m+$num>12) {
1771
-			$y += floor($num/12);
1772
-			$m += $num%12;
1773
-		} else {
1774
-			$m += $num;
1775
-		}
1776
-		//date_default_timezone_set('UTC');
1777
-		// return mktime($h, $n, $s, $m, $d, $y);
1778
-		$result = api_strtotime($y.'-'.$m.'-'.$d.' '.$h.':'.$n.':'.$s, 'UTC');
1779
-		if (!empty($result)) {
1780
-			return $result;
1781
-		}
1782
-		return false;
1783
-	}
1784
-
1785
-	/**
1786
-	 * edit a datetime inside attendance calendar table
1787
-	 * @param	int	attendance calendar id
1788
-	 * @param	int	attendance id
1789
-	 * @return	int affected rows
1790
-	 */
1791
-	public function attendance_calendar_edit($calendar_id, $attendance_id)
1792
-	{
1793
-		$tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1794
-		$affected_rows = 0;
1795
-		$attendance_id = intval($attendance_id);
1796
-		$course_id = api_get_course_int_id();
1797
-		// check if datetime already exists inside the table
1798
-		$sql = "SELECT id FROM $tbl_attendance_calendar
1690
+     * @return array
1691
+     */
1692
+    public function deleteAttendanceCalendarGroup($calendarId, $courseId)
1693
+    {
1694
+        $table = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR_REL_GROUP);
1695
+        Database::delete(
1696
+            $table,
1697
+            array(
1698
+                'calendar_id = ? AND c_id = ?' => array($calendarId, $courseId)
1699
+            )
1700
+        );
1701
+    }
1702
+
1703
+    /**
1704
+     * save repeated date inside attendance calendar table
1705
+     * @param int $attendance_id
1706
+     * @param int $start_date start date in tms
1707
+     * @param int $end_date end date in tms
1708
+     * @param string $repeat_type daily, weekly, monthlyByDate
1709
+     * @param array $groupList
1710
+     */
1711
+    public function attendance_repeat_calendar_add(
1712
+        $attendance_id,
1713
+        $start_date,
1714
+        $end_date,
1715
+        $repeat_type,
1716
+        $groupList = array()
1717
+    ) {
1718
+        $attendance_id = intval($attendance_id);
1719
+        // save start date
1720
+        $datetimezone = api_get_utc_datetime($start_date);
1721
+        $this->set_date_time($datetimezone);
1722
+        $this->attendance_calendar_add($attendance_id, $groupList);
1723
+
1724
+        // 86400 = 24 hours in seconds
1725
+        // 604800 = 1 week in seconds
1726
+        // Saves repeated dates
1727
+        switch ($repeat_type) {
1728
+            case 'daily':
1729
+                $j = 1;
1730
+                for ($i = $start_date + 86400; ($i <= $end_date); $i += 86400) {
1731
+                    $datetimezone = api_get_utc_datetime($i);
1732
+                    $this->set_date_time($datetimezone);
1733
+                    $this->attendance_calendar_add($attendance_id, $groupList);
1734
+                    $j++;
1735
+                }
1736
+                break;
1737
+            case 'weekly':
1738
+                $j = 1;
1739
+                for ($i = $start_date + 604800; ($i <= $end_date); $i += 604800) {
1740
+                    $datetimezone = api_get_utc_datetime($i);
1741
+                    $this->set_date_time($datetimezone);
1742
+                    $this->attendance_calendar_add($attendance_id, $groupList);
1743
+                    $j++;
1744
+                }
1745
+                break;
1746
+            case 'monthlyByDate':
1747
+                $j = 1;
1748
+                //@todo fix bug with february
1749
+                for ($i = $start_date + 2419200; ($i <= $end_date); $i += 2419200) {
1750
+                    $datetimezone = api_get_utc_datetime($i);
1751
+                    $this->set_date_time($datetimezone);
1752
+                    $this->attendance_calendar_add($attendance_id, $groupList);
1753
+                    $j++;
1754
+                }
1755
+                break;
1756
+        }
1757
+    }
1758
+
1759
+    /**
1760
+     * Adds x months to a UNIX timestamp
1761
+     * @param   int     The timestamp
1762
+     * @param   int     The number of years to add
1763
+     * @return  int     The new timestamp
1764
+     */
1765
+    private function add_month($timestamp, $num=1)
1766
+    {
1767
+        $values = api_get_utc_datetime($timestamp);
1768
+        $values = str_replace(array(':','-',' '), '/', $values);
1769
+        list($y, $m, $d, $h, $n, $s) = split('/',$values);
1770
+        if($m+$num>12) {
1771
+            $y += floor($num/12);
1772
+            $m += $num%12;
1773
+        } else {
1774
+            $m += $num;
1775
+        }
1776
+        //date_default_timezone_set('UTC');
1777
+        // return mktime($h, $n, $s, $m, $d, $y);
1778
+        $result = api_strtotime($y.'-'.$m.'-'.$d.' '.$h.':'.$n.':'.$s, 'UTC');
1779
+        if (!empty($result)) {
1780
+            return $result;
1781
+        }
1782
+        return false;
1783
+    }
1784
+
1785
+    /**
1786
+     * edit a datetime inside attendance calendar table
1787
+     * @param	int	attendance calendar id
1788
+     * @param	int	attendance id
1789
+     * @return	int affected rows
1790
+     */
1791
+    public function attendance_calendar_edit($calendar_id, $attendance_id)
1792
+    {
1793
+        $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1794
+        $affected_rows = 0;
1795
+        $attendance_id = intval($attendance_id);
1796
+        $course_id = api_get_course_int_id();
1797
+        // check if datetime already exists inside the table
1798
+        $sql = "SELECT id FROM $tbl_attendance_calendar
1799 1799
 		        WHERE
1800 1800
 		        	c_id = $course_id AND
1801 1801
 		        	date_time = '".Database::escape_string($this->date_time)."' AND
1802 1802
 		        	attendance_id = '$attendance_id'";
1803
-		$rs = Database::query($sql);
1803
+        $rs = Database::query($sql);
1804 1804
 
1805
-		if (Database::num_rows($rs) == 0) {
1806
-			$sql = "UPDATE $tbl_attendance_calendar
1805
+        if (Database::num_rows($rs) == 0) {
1806
+            $sql = "UPDATE $tbl_attendance_calendar
1807 1807
 					SET date_time='".Database::escape_string($this->date_time)."'
1808 1808
 					WHERE c_id = $course_id AND id = '".intval($calendar_id)."'";
1809
-			Database::query($sql);
1810
-		}
1811
-
1812
-		// update locked attendance
1813
-		$is_all_calendar_done = self::is_all_attendance_calendar_done($attendance_id);
1814
-		if (!$is_all_calendar_done) {
1815
-			self::lock_attendance($attendance_id, false);
1816
-		} else {
1817
-			self::lock_attendance($attendance_id);
1818
-		}
1819
-
1820
-		return $affected_rows;
1821
-	}
1822
-
1823
-	/**
1824
-	 * delete a datetime from attendance calendar table
1825
-	 * @param	int		attendance calendar id
1826
-	 * @param	int		attendance id
1827
-	 * @param	bool	true for removing all calendar inside current attendance, false for removing by calendar id
1828
-	 * @return	int affected rows
1829
-	 */
1830
-	public function attendance_calendar_delete($calendar_id, $attendance_id , $all_delete = false)
1831
-	{
1832
-		$tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1833
-		$tbl_attendance_sheet = Database::get_course_table(TABLE_ATTENDANCE_SHEET);
1834
-
1835
-		$attendance_id = intval($attendance_id);
1836
-		// get all registered users inside current course
1837
-		$users = $this->get_users_rel_course();
1838
-		$user_ids = array_keys($users);
1839
-		$course_id = api_get_course_int_id();
1840
-		$affected_rows = 0;
1841
-		if ($all_delete) {
1842
-			$attendance_calendar = $this->get_attendance_calendar($attendance_id);
1843
-			// get all dates from calendar by current attendance
1844
-			if (!empty($attendance_calendar)) {
1845
-				foreach ($attendance_calendar as $cal) {
1846
-					// delete all data from attendance sheet
1847
-					$sql = "DELETE FROM $tbl_attendance_sheet
1809
+            Database::query($sql);
1810
+        }
1811
+
1812
+        // update locked attendance
1813
+        $is_all_calendar_done = self::is_all_attendance_calendar_done($attendance_id);
1814
+        if (!$is_all_calendar_done) {
1815
+            self::lock_attendance($attendance_id, false);
1816
+        } else {
1817
+            self::lock_attendance($attendance_id);
1818
+        }
1819
+
1820
+        return $affected_rows;
1821
+    }
1822
+
1823
+    /**
1824
+     * delete a datetime from attendance calendar table
1825
+     * @param	int		attendance calendar id
1826
+     * @param	int		attendance id
1827
+     * @param	bool	true for removing all calendar inside current attendance, false for removing by calendar id
1828
+     * @return	int affected rows
1829
+     */
1830
+    public function attendance_calendar_delete($calendar_id, $attendance_id , $all_delete = false)
1831
+    {
1832
+        $tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR);
1833
+        $tbl_attendance_sheet = Database::get_course_table(TABLE_ATTENDANCE_SHEET);
1834
+
1835
+        $attendance_id = intval($attendance_id);
1836
+        // get all registered users inside current course
1837
+        $users = $this->get_users_rel_course();
1838
+        $user_ids = array_keys($users);
1839
+        $course_id = api_get_course_int_id();
1840
+        $affected_rows = 0;
1841
+        if ($all_delete) {
1842
+            $attendance_calendar = $this->get_attendance_calendar($attendance_id);
1843
+            // get all dates from calendar by current attendance
1844
+            if (!empty($attendance_calendar)) {
1845
+                foreach ($attendance_calendar as $cal) {
1846
+                    // delete all data from attendance sheet
1847
+                    $sql = "DELETE FROM $tbl_attendance_sheet
1848 1848
 							WHERE c_id = $course_id AND attendance_calendar_id = '".intval($cal['id'])."'";
1849
-					Database::query($sql);
1850
-					// delete data from attendance calendar
1851
-					$sql = "DELETE FROM $tbl_attendance_calendar
1849
+                    Database::query($sql);
1850
+                    // delete data from attendance calendar
1851
+                    $sql = "DELETE FROM $tbl_attendance_calendar
1852 1852
 							WHERE c_id = $course_id AND id = '".intval($cal['id'])."'";
1853
-					Database::query($sql);
1854
-
1855
-					$this->deleteAttendanceCalendarGroup($cal['id'], $course_id);
1856
-					$affected_rows++;
1857
-				}
1858
-			}
1859
-		} else {
1860
-			// delete just one row from attendance sheet by the calendar id
1861
-			$sql = "DELETE FROM $tbl_attendance_sheet
1853
+                    Database::query($sql);
1854
+
1855
+                    $this->deleteAttendanceCalendarGroup($cal['id'], $course_id);
1856
+                    $affected_rows++;
1857
+                }
1858
+            }
1859
+        } else {
1860
+            // delete just one row from attendance sheet by the calendar id
1861
+            $sql = "DELETE FROM $tbl_attendance_sheet
1862 1862
 					WHERE c_id = $course_id AND attendance_calendar_id = '".intval($calendar_id)."'";
1863
-			Database::query($sql);
1864
-			// delete data from attendance calendar
1865
-			$sql = "DELETE FROM $tbl_attendance_calendar
1863
+            Database::query($sql);
1864
+            // delete data from attendance calendar
1865
+            $sql = "DELETE FROM $tbl_attendance_calendar
1866 1866
 					WHERE c_id = $course_id AND id = '".intval($calendar_id)."'";
1867
-			Database::query($sql);
1868
-
1869
-			$this->deleteAttendanceCalendarGroup($calendar_id, $course_id);
1870
-			$affected_rows++;
1871
-		}
1872
-
1873
-		// update users' results
1874
-		$this->update_users_results($user_ids, $attendance_id);
1875
-
1876
-		return $affected_rows;
1877
-	}
1878
-
1879
-	/** Setters for fields of attendances tables **/
1880
-	public function set_session_id($session_id)
1881
-	{
1882
-		$this->session_id = $session_id;
1883
-	}
1884
-
1885
-	public function set_course_id($course_id)
1886
-	{
1887
-		$this->course_id = $course_id;
1888
-	}
1889
-
1890
-	public function set_date_time($datetime)
1891
-	{
1892
-		$this->date_time = $datetime;
1893
-	}
1894
-
1895
-	public function set_name($name)
1896
-	{
1897
-		$this->name = $name;
1898
-	}
1899
-
1900
-	public function set_description($description)
1901
-	{
1902
-		$this->description = $description;
1903
-	}
1904
-
1905
-	public function set_attendance_qualify_title($attendance_qualify_title)
1906
-	{
1907
-		$this->attendance_qualify_title = $attendance_qualify_title;
1908
-	}
1909
-
1910
-	public function set_attendance_weight($attendance_weight)
1911
-	{
1912
-		$this->attendance_weight = $attendance_weight;
1913
-	}
1914
-
1915
-	/** Getters for fields of attendances tables **/
1916
-	public function get_session_id()
1917
-	{
1918
-		return $this->session_id;
1919
-	}
1920
-
1921
-	public function get_course_id()
1922
-	{
1923
-		return $this->course_id;
1924
-	}
1925
-
1926
-	public function get_date_time()
1927
-	{
1928
-		return $this->date_time;
1929
-	}
1930
-
1931
-	public function get_name()
1932
-	{
1933
-		return $this->name;
1934
-	}
1935
-
1936
-	public function get_description()
1937
-	{
1938
-		return $this->description;
1939
-	}
1940
-
1941
-	public function get_attendance_qualify_title()
1942
-	{
1943
-		return $this->attendance_qualify_title;
1944
-	}
1945
-
1946
-	public function get_attendance_weight()
1947
-	{
1948
-		return $this->attendance_weight;
1949
-	}
1950
-
1951
-	/**
1952
-	 * @param string $startDate in UTC time
1953
-	 * @param string $endDate in UTC time
1954
-	 *
1955
-	 * @return array
1956
-	 */
1957
-	public function getAttendanceLogin($startDate, $endDate)
1958
-	{
1959
-		if (empty($startDate) || $startDate == '0000-00-00' ||
1960
-			empty($endDate) || $endDate == '0000-00-00'
1961
-		) {
1962
-			return false;
1963
-		}
1964
-
1965
-		$sessionId = api_get_session_id();
1966
-		$courseCode  = api_get_course_id();
1967
-		if (!empty($sessionId)) {
1968
-			$users = CourseManager:: get_user_list_from_course_code(
1969
-				$courseCode,
1970
-				$sessionId,
1971
-				'',
1972
-				'lastname',
1973
-				0
1974
-			);
1975
-		} else {
1976
-			$users = CourseManager:: get_user_list_from_course_code(
1977
-				$courseCode,
1978
-				0,
1979
-				'',
1980
-				'lastname',
1981
-				STUDENT
1982
-			);
1983
-		}
1984
-
1985
-		$dateTimeStartOriginal = new DateTime($startDate);
1986
-		$dateTimeStart = new DateTime($startDate);
1987
-		$dateTimeEnd= new DateTime($endDate);
1988
-		$interval = $dateTimeStart->diff($dateTimeEnd);
1989
-		$days = intval($interval->format('%a'));
1990
-
1991
-		$dateList = array($dateTimeStart->format('Y-m-d'));
1992
-		$headers = array(
1993
-			get_lang('User'),
1994
-			$dateTimeStart->format('Y-m-d')
1995
-		);
1996
-
1997
-		for ($i = 0; $i < $days; $i++) {
1998
-			$dateTimeStart = $dateTimeStart->add(new DateInterval('P1D'));
1999
-			$date = $dateTimeStart->format('Y-m-d');
2000
-			$dateList[] = $date;
2001
-			$headers[] = $date;
2002
-		}
2003
-
2004
-		$accessData = CourseManager::getCourseAccessPerCourseAndSession(
2005
-			$courseCode,
2006
-			$sessionId,
2007
-			$dateTimeStartOriginal->format('Y-m-d H:i:s'),
2008
-			$dateTimeEnd->format('Y-m-d H:i:s')
2009
-		);
2010
-
2011
-		$results = array();
2012
-		if (!empty($accessData)) {
2013
-			foreach ($accessData as $data) {
2014
-				$onlyDate = substr($data['login_course_date'], 0, 10);
2015
-				$results[$data['user_id']][$onlyDate] = true;
2016
-			}
2017
-		}
2018
-
2019
-		return array(
2020
-			'users' => $users,
2021
-			'dateList' => $dateList,
2022
-			'headers' => $headers,
2023
-			'results' => $results
2024
-		);
2025
-	}
2026
-
2027
-	/**
2028
-	 * @param string $startDate in UTC time
2029
-	 * @param string $endDate in UTC time
2030
-	 *
2031
-	 * @return string
2032
-	 */
2033
-	public function getAttendanceLoginTable($startDate, $endDate)
2034
-	{
2035
-		$data = $this->getAttendanceLogin($startDate, $endDate);
2036
-
2037
-		if (!$data) {
2038
-			return null;
2039
-		}
2040
-
2041
-		$headers = $data['headers'];
2042
-		$dateList = $data['dateList'];
2043
-		$users = $data['users'];
2044
-		$results = $data['results'];
2045
-
2046
-		$table = new HTML_Table(array('class' => 'data_table'));
2047
-		$row = 0;
2048
-		$column = 0;
2049
-		foreach ($headers as $header) {
2050
-			$table->setHeaderContents($row, $column, $header);
2051
-			$column++;
2052
-		}
2053
-		$row = 1;
2054
-		foreach ($users as $user) {
2055
-			$table->setCellContents(
2056
-				$row,
2057
-				0,
2058
-				$user['lastname'].' '.$user['firstname'].' ('.$user['username'].')'
2059
-			);
2060
-			$row ++;
2061
-		}
2062
-
2063
-		$column = 1;
2064
-		$row = 1;
2065
-		foreach ($users as $user) {
2066
-			foreach ($dateList as $date) {
2067
-				$status = null;
2068
-				if (isset($results[$user['user_id']]) &&
2069
-					isset($results[$user['user_id']][$date])
2070
-				) {
2071
-					$status = 'X';
2072
-				}
2073
-				$table->setCellContents($row, $column, $status);
2074
-				$column++;
2075
-			}
2076
-			$row++;
2077
-			$column = 1;
2078
-		}
2079
-
2080
-		return $table->toHtml();
2081
-	}
2082
-
2083
-	/**
2084
-	 * @param string $startDate in UTC time
2085
-	 * @param string $endDate in UTC time
2086
-	 *
2087
-	 * @return string
2088
-	 */
2089
-	public function exportAttendanceLogin($startDate, $endDate)
2090
-	{
2091
-		$data = $this->getAttendanceLogin($startDate, $endDate);
2092
-
2093
-		if (!$data) {
2094
-			return null;
2095
-		}
2096
-		$users = $data['users'];
2097
-		$results = $data['results'];
2098
-
2099
-		$table = new HTML_Table(array('class' => 'data_table'));
2100
-
2101
-		$table->setHeaderContents(0, 0, get_lang('User'));
2102
-		$table->setHeaderContents(0, 1, get_lang('Date'));
2103
-
2104
-		$row = 1;
2105
-		foreach ($users as $user) {
2106
-			$table->setCellContents(
2107
-				$row,
2108
-				0,
2109
-				$user['lastname'].' '.$user['firstname'].' ('.$user['username'].')'
2110
-			);
2111
-			$row++;
2112
-		}
2113
-		$table->setColAttributes(0, array('style' => 'width:28%'));
2114
-
2115
-		$row = 1;
2116
-		foreach ($users as $user) {
2117
-			if (isset($results[$user['user_id']]) &&
2118
-				!empty($results[$user['user_id']])
2119
-			) {
2120
-				$dates = implode(', ', array_keys($results[$user['user_id']]));
2121
-				$table->setCellContents($row, 1, $dates);
2122
-			}
2123
-			$row++;
2124
-		}
2125
-
2126
-		//$tableToString = null;
2127
-
2128
-		//$sessionInfo = api_get_session_info(api_get_session_id());
2129
-		//if (!empty($sessionInfo)) {
2130
-		/*$tableToString .= '<strong>'.get_lang('PeriodToDisplay').'</strong>: '.
1867
+            Database::query($sql);
1868
+
1869
+            $this->deleteAttendanceCalendarGroup($calendar_id, $course_id);
1870
+            $affected_rows++;
1871
+        }
1872
+
1873
+        // update users' results
1874
+        $this->update_users_results($user_ids, $attendance_id);
1875
+
1876
+        return $affected_rows;
1877
+    }
1878
+
1879
+    /** Setters for fields of attendances tables **/
1880
+    public function set_session_id($session_id)
1881
+    {
1882
+        $this->session_id = $session_id;
1883
+    }
1884
+
1885
+    public function set_course_id($course_id)
1886
+    {
1887
+        $this->course_id = $course_id;
1888
+    }
1889
+
1890
+    public function set_date_time($datetime)
1891
+    {
1892
+        $this->date_time = $datetime;
1893
+    }
1894
+
1895
+    public function set_name($name)
1896
+    {
1897
+        $this->name = $name;
1898
+    }
1899
+
1900
+    public function set_description($description)
1901
+    {
1902
+        $this->description = $description;
1903
+    }
1904
+
1905
+    public function set_attendance_qualify_title($attendance_qualify_title)
1906
+    {
1907
+        $this->attendance_qualify_title = $attendance_qualify_title;
1908
+    }
1909
+
1910
+    public function set_attendance_weight($attendance_weight)
1911
+    {
1912
+        $this->attendance_weight = $attendance_weight;
1913
+    }
1914
+
1915
+    /** Getters for fields of attendances tables **/
1916
+    public function get_session_id()
1917
+    {
1918
+        return $this->session_id;
1919
+    }
1920
+
1921
+    public function get_course_id()
1922
+    {
1923
+        return $this->course_id;
1924
+    }
1925
+
1926
+    public function get_date_time()
1927
+    {
1928
+        return $this->date_time;
1929
+    }
1930
+
1931
+    public function get_name()
1932
+    {
1933
+        return $this->name;
1934
+    }
1935
+
1936
+    public function get_description()
1937
+    {
1938
+        return $this->description;
1939
+    }
1940
+
1941
+    public function get_attendance_qualify_title()
1942
+    {
1943
+        return $this->attendance_qualify_title;
1944
+    }
1945
+
1946
+    public function get_attendance_weight()
1947
+    {
1948
+        return $this->attendance_weight;
1949
+    }
1950
+
1951
+    /**
1952
+     * @param string $startDate in UTC time
1953
+     * @param string $endDate in UTC time
1954
+     *
1955
+     * @return array
1956
+     */
1957
+    public function getAttendanceLogin($startDate, $endDate)
1958
+    {
1959
+        if (empty($startDate) || $startDate == '0000-00-00' ||
1960
+            empty($endDate) || $endDate == '0000-00-00'
1961
+        ) {
1962
+            return false;
1963
+        }
1964
+
1965
+        $sessionId = api_get_session_id();
1966
+        $courseCode  = api_get_course_id();
1967
+        if (!empty($sessionId)) {
1968
+            $users = CourseManager:: get_user_list_from_course_code(
1969
+                $courseCode,
1970
+                $sessionId,
1971
+                '',
1972
+                'lastname',
1973
+                0
1974
+            );
1975
+        } else {
1976
+            $users = CourseManager:: get_user_list_from_course_code(
1977
+                $courseCode,
1978
+                0,
1979
+                '',
1980
+                'lastname',
1981
+                STUDENT
1982
+            );
1983
+        }
1984
+
1985
+        $dateTimeStartOriginal = new DateTime($startDate);
1986
+        $dateTimeStart = new DateTime($startDate);
1987
+        $dateTimeEnd= new DateTime($endDate);
1988
+        $interval = $dateTimeStart->diff($dateTimeEnd);
1989
+        $days = intval($interval->format('%a'));
1990
+
1991
+        $dateList = array($dateTimeStart->format('Y-m-d'));
1992
+        $headers = array(
1993
+            get_lang('User'),
1994
+            $dateTimeStart->format('Y-m-d')
1995
+        );
1996
+
1997
+        for ($i = 0; $i < $days; $i++) {
1998
+            $dateTimeStart = $dateTimeStart->add(new DateInterval('P1D'));
1999
+            $date = $dateTimeStart->format('Y-m-d');
2000
+            $dateList[] = $date;
2001
+            $headers[] = $date;
2002
+        }
2003
+
2004
+        $accessData = CourseManager::getCourseAccessPerCourseAndSession(
2005
+            $courseCode,
2006
+            $sessionId,
2007
+            $dateTimeStartOriginal->format('Y-m-d H:i:s'),
2008
+            $dateTimeEnd->format('Y-m-d H:i:s')
2009
+        );
2010
+
2011
+        $results = array();
2012
+        if (!empty($accessData)) {
2013
+            foreach ($accessData as $data) {
2014
+                $onlyDate = substr($data['login_course_date'], 0, 10);
2015
+                $results[$data['user_id']][$onlyDate] = true;
2016
+            }
2017
+        }
2018
+
2019
+        return array(
2020
+            'users' => $users,
2021
+            'dateList' => $dateList,
2022
+            'headers' => $headers,
2023
+            'results' => $results
2024
+        );
2025
+    }
2026
+
2027
+    /**
2028
+     * @param string $startDate in UTC time
2029
+     * @param string $endDate in UTC time
2030
+     *
2031
+     * @return string
2032
+     */
2033
+    public function getAttendanceLoginTable($startDate, $endDate)
2034
+    {
2035
+        $data = $this->getAttendanceLogin($startDate, $endDate);
2036
+
2037
+        if (!$data) {
2038
+            return null;
2039
+        }
2040
+
2041
+        $headers = $data['headers'];
2042
+        $dateList = $data['dateList'];
2043
+        $users = $data['users'];
2044
+        $results = $data['results'];
2045
+
2046
+        $table = new HTML_Table(array('class' => 'data_table'));
2047
+        $row = 0;
2048
+        $column = 0;
2049
+        foreach ($headers as $header) {
2050
+            $table->setHeaderContents($row, $column, $header);
2051
+            $column++;
2052
+        }
2053
+        $row = 1;
2054
+        foreach ($users as $user) {
2055
+            $table->setCellContents(
2056
+                $row,
2057
+                0,
2058
+                $user['lastname'].' '.$user['firstname'].' ('.$user['username'].')'
2059
+            );
2060
+            $row ++;
2061
+        }
2062
+
2063
+        $column = 1;
2064
+        $row = 1;
2065
+        foreach ($users as $user) {
2066
+            foreach ($dateList as $date) {
2067
+                $status = null;
2068
+                if (isset($results[$user['user_id']]) &&
2069
+                    isset($results[$user['user_id']][$date])
2070
+                ) {
2071
+                    $status = 'X';
2072
+                }
2073
+                $table->setCellContents($row, $column, $status);
2074
+                $column++;
2075
+            }
2076
+            $row++;
2077
+            $column = 1;
2078
+        }
2079
+
2080
+        return $table->toHtml();
2081
+    }
2082
+
2083
+    /**
2084
+     * @param string $startDate in UTC time
2085
+     * @param string $endDate in UTC time
2086
+     *
2087
+     * @return string
2088
+     */
2089
+    public function exportAttendanceLogin($startDate, $endDate)
2090
+    {
2091
+        $data = $this->getAttendanceLogin($startDate, $endDate);
2092
+
2093
+        if (!$data) {
2094
+            return null;
2095
+        }
2096
+        $users = $data['users'];
2097
+        $results = $data['results'];
2098
+
2099
+        $table = new HTML_Table(array('class' => 'data_table'));
2100
+
2101
+        $table->setHeaderContents(0, 0, get_lang('User'));
2102
+        $table->setHeaderContents(0, 1, get_lang('Date'));
2103
+
2104
+        $row = 1;
2105
+        foreach ($users as $user) {
2106
+            $table->setCellContents(
2107
+                $row,
2108
+                0,
2109
+                $user['lastname'].' '.$user['firstname'].' ('.$user['username'].')'
2110
+            );
2111
+            $row++;
2112
+        }
2113
+        $table->setColAttributes(0, array('style' => 'width:28%'));
2114
+
2115
+        $row = 1;
2116
+        foreach ($users as $user) {
2117
+            if (isset($results[$user['user_id']]) &&
2118
+                !empty($results[$user['user_id']])
2119
+            ) {
2120
+                $dates = implode(', ', array_keys($results[$user['user_id']]));
2121
+                $table->setCellContents($row, 1, $dates);
2122
+            }
2123
+            $row++;
2124
+        }
2125
+
2126
+        //$tableToString = null;
2127
+
2128
+        //$sessionInfo = api_get_session_info(api_get_session_id());
2129
+        //if (!empty($sessionInfo)) {
2130
+        /*$tableToString .= '<strong>'.get_lang('PeriodToDisplay').'</strong>: '.
2131 2131
 			sprintf(get_lang('FromDateXToDateY'), $startDate, $endDate);*/
2132
-		//}
2133
-
2134
-		$tableToString = $table->toHtml();
2135
-
2136
-		$params = array(
2137
-			'filename' => get_lang('Attendance') . '_' . api_get_utc_datetime(),
2138
-			'pdf_title' => get_lang('Attendance'),
2139
-			'course_code' => api_get_course_id(),
2140
-			'show_real_course_teachers' => true
2141
-		);
2142
-		$pdf = new PDF('A4', null, $params);
2143
-		$pdf->html_to_pdf_with_template($tableToString);
2144
-	}
2132
+        //}
2133
+
2134
+        $tableToString = $table->toHtml();
2135
+
2136
+        $params = array(
2137
+            'filename' => get_lang('Attendance') . '_' . api_get_utc_datetime(),
2138
+            'pdf_title' => get_lang('Attendance'),
2139
+            'course_code' => api_get_course_id(),
2140
+            'show_real_course_teachers' => true
2141
+        );
2142
+        $pdf = new PDF('A4', null, $params);
2143
+        $pdf->html_to_pdf_with_template($tableToString);
2144
+    }
2145 2145
 }
Please login to merge, or discard this patch.