This repository has been archived by the owner on Jul 16, 2019. It is now read-only.
forked from projectestac/moodle-mod_geogebra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
locallib.php
1437 lines (1237 loc) · 56.5 KB
/
locallib.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Internal library of functions for module geogebra
*
* All the geogebra specific functions, needed to implement the module
* logic, should go here. Never include this file from your lib.php!
*
* @package mod
* @subpackage geogebra
* @copyright 2011 Departament d'Ensenyament de la Generalitat de Catalunya
* @author Sara Arjona Téllez <sarjona@xtec.cat>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once("$CFG->libdir/filelib.php");
function geogebra_before_add_or_update(&$geogebra, $mform) {
geogebra_update_attributes($geogebra);
if ($mform->get_data()->filetype === GEOGEBRA_FILE_TYPE_LOCAL) {
$geogebra->url = $mform->get_data()->geogebrafile;
} else {
$geogebra->url = $geogebra->geogebraurl;
}
return true;
}
function geogebra_after_add_or_update($geogebra, $mform) {
global $DB;
if ($mform->get_data()->filetype === GEOGEBRA_FILE_TYPE_LOCAL) {
$filename = geogebra_set_mainfile($geogebra);
$geogebra->url = $filename;
$result = $DB->update_record('geogebra', $geogebra);
}
if ($geogebra->timedue) {
$event = new stdClass();
if ($event->id = $DB->get_field('event', 'id', array('modulename' => 'geogebra', 'instance' => $geogebra->id))) {
$event->name = $geogebra->name;
$event->description = format_module_intro('geogebra', $geogebra, $geogebra->coursemodule);
$event->timestart = $geogebra->timedue;
$calendarevent = calendar_event::load($event->id);
$calendarevent->update($event);
} else {
$event = new stdClass();
$event->name = $geogebra->name;
$event->description = format_module_intro('geogebra', $geogebra, $geogebra->coursemodule);
$event->courseid = $geogebra->course;
$event->groupid = 0;
$event->userid = 0;
$event->modulename = 'geogebra';
$event->instance = $geogebra->id;
$event->eventtype = 'due';
$event->timestart = $geogebra->timedue;
$event->timeduration = 0;
calendar_event::create($event);
}
} else {
$DB->delete_records('event', array('modulename' => 'geogebra', 'instance' => $geogebra->id));
}
// get existing grade item
geogebra_grade_item_update($geogebra);
return true;
}
/**
* Get an array with the file types
*
* @return array The array with each file type
*/
function geogebra_get_file_types() {
$filetypes = array(GEOGEBRA_FILE_TYPE_LOCAL => get_string('filetypelocal', 'geogebra'));
$filetypes[GEOGEBRA_FILE_TYPE_EXTERNAL] = get_string('filetypeexternal', 'geogebra');
return $filetypes;
}
/**
* Display the geogebra intro
*
*/
function geogebra_view_intro($geogebra, $cm) {
global $OUTPUT, $CFG;
echo $OUTPUT->heading(format_string($geogebra->name, false));
echo $OUTPUT->box_start('generalbox boxaligncenter', 'intro');
echo format_module_intro('geogebra', $geogebra, $cm->id);
echo $OUTPUT->box_end();
}
/**
* Display the geogebra dates
*
* Prints the geogebra start and end dates in a box.
*/
function geogebra_view_dates($geogebra, $cm, $timenow=null) {
global $OUTPUT;
if (!$geogebra->timeavailable && !$geogebra->timedue) {
return;
}
if (is_null($timenow)) {
$timenow = time();
}
echo $OUTPUT->box_start('generalbox boxaligncenter geogebradates', 'dates');
if ($geogebra->timeavailable) {
echo '<div class="title-time">'.get_string('availabledate', 'assignment').': </div>';
echo '<div class="data-time">'.userdate($geogebra->timeavailable).'</div>';
}
if ($geogebra->timedue) {
echo '<div class="title-time">'.get_string('duedate', 'assignment').': </div>';
echo '<div class="data-time">'.userdate($geogebra->timedue).'</div>';
}
echo $OUTPUT->box_end();
}
/**
* Display the geogebra applet
*
* @param type $geogebra
* @param type $cm
* @param type $context
* @param type $attempt
* @param type $ispreview if is a preview or not
* @param type $timenow
*/
function geogebra_view_applet($geogebra, $cm, $context, $attempt = null, $ispreview = false) {
global $OUTPUT, $PAGE, $CFG, $USER;
$timenow = time();
if ($attempt) {
$viewmode = 'view';
$userid = $attempt->userid;
} else {
$userid = $USER->id;
if ($ispreview) {
$viewmode = 'preview';
} else {
$viewmode = 'submit';
}
}
$isopen = (empty($geogebra->timeavailable) || $geogebra->timeavailable < $timenow);
if (!$isopen) {
$content .= $OUTPUT->notify(get_string('notopenyet', 'geogebra', userdate($geogebra->timeavailable)));
if (!$ispreview) {
return $content;
}
}
$isclosed = (!empty($geogebra->timedue) && $geogebra->timedue < $timenow);
if ($isclosed) {
$content .= $OUTPUT->notify(get_string('expired', 'geogebra', userdate($geogebra->timedue)));
if (!$ispreview) {
return $content;
}
}
$attempts = geogebra_count_finished_attempts($geogebra->id, $userid);
if ($ispreview || $geogebra->maxattempts < 0 || $attempts < $geogebra->maxattempts) {
// Show results when viewmode is "view"
if (!empty($attempt)) {
// TODO: Change $USER by selected userid
geogebra_view_userid_results($geogebra, $userid, $cm, $context, $viewmode, $attempt);
} else if (!$ispreview) {
echo $OUTPUT->box_start('generalbox');
if ($geogebra->maxattempts < 0) {
echo get_string('unlimitedattempts', 'geogebra').'<br/>';
} else if ($attempts == $geogebra->maxattempts - 1) {
echo get_string('lastattemptremaining', 'geogebra').'<br/>';
} else {
echo get_string('attemptsremaining', 'geogebra').($geogebra->maxattempts - $attempts).'<br/>';
}
// If there is some unfinished attempt, show it
$attempt = geogebra_get_unfinished_attempt($geogebra->id, $userid);
if (!empty($attempt)) {
echo '('.get_string('resumeattempt', 'geogebra').')';
}
echo $OUTPUT->box_end();
}
geogebra_print_content($geogebra, $context);
// If not preview mode, load state
$parsedvars = null;
if ($attempt) {
parse_str($attempt->vars, $parsedvars);
}
if (isset($parsedvars['state'])) {
// Continue previuos attempt
$eduxtecadapterparameters = http_build_query(array(
'state' => $parsedvars['state'],
'grade' => $parsedvars['grade'],
'duration' => $parsedvars['duration'],
'attempts' => $parsedvars['attempts']
), '', '&');
} else {
// New attempt
$attempts = geogebra_count_finished_attempts($geogebra->id, $userid) + 1;
$eduxtecadapterparameters = http_build_query(array(
'attempts' => $attempts
), '', '&');
}
$PAGE->requires->js('/mod/geogebra/geogebra_view.js');
echo '<form id="geogebra_form" method="POST" action="attempt.php">';
echo '<input type="hidden" name="appletInformation" />';
echo '<input type="hidden" name="id" value="'.$context->instanceid.'"/>';
echo '<input type="hidden" name="n" value="'.$geogebra->id.'"/>';
echo '<input type="hidden" name="f" value="0"/>';
// Only show submit buttons if not view mode
if (empty($attempt) || !$attempt->finished) {
echo '<input id="geogebra_form_save" type="button" value="' . get_string('savewithoutsubmitting', 'geogebra') . '" />';
echo '<input id="geogebra_form_submit" type="button" value="' . get_string('submitandfinish', 'geogebra') . '" />';
}
echo '<input type="hidden" name="prevAppletInformation" value="' . $eduxtecadapterparameters . '" />';
echo ' </form>';
} else {
echo $OUTPUT->box(get_string('msg_noattempts', 'geogebra'), 'generalbox boxaligncenter');
}
geogebra_view_dates($geogebra, $context, $timenow);
}
function geogebra_get_id($url) {
$parts = explode('/', $url);
foreach ($parts as $i => $part) {
if ($part == 'id') {
return $parts[$i + 1];
}
}
return false;
}
function geogebra_get_script_param($name, $attributes) {
return (isset($attributes[$name]) && $attributes[$name]) ? 'true' : 'false';
}
function geogebra_print_content($geogebra, $context) {
global $CFG;
parse_str($geogebra->attributes, $attributes);
$attribnames = array('enableRightClick', 'showAlgebraInput', 'showMenuBar', 'showToolBar',
'showToolBarHelp', 'enableLabelDrags', 'showResetIcon');
$attribs = array(
'width' => $geogebra->width,
'height' => $geogebra->height,
'language' => $attributes['language']
);
if (geogebra_is_valid_external_url($geogebra->url)) {
// Get contents if specified GGB is external
$materialid = geogebra_get_id($geogebra->url);
if (!$materialid) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $geogebra->url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$content = curl_exec($curl);
curl_close($curl);
}
} else {
$fs = get_file_storage();
$file = $fs->get_file($context->id, 'mod_geogebra', 'content', 0, '/', $geogebra->url);
if ($file) {
$content = $file->get_content();
}
}
if (isset($content) && !empty($content)) {
$attribs['ggbBase64'] = base64_encode($content);
// $attribs['ggbBase64'] = 'UEsDBBQACAAIAE9scT8AAAAAAAAAAAAAAAAWAAAAZ2VvZ2VicmFfdGh1bWJuYWlsLnBuZ+sM8HPn5ZLiYmBg4PX0cAkC0ieAuIuDDUi+P8H6k4GBUdnTxTGk4tbby4a8DAw8hzd8Ur+rdGPn+TYBTc2CLpYEAQMOCRYeJjbG5gbHAwoJAiBMSAgijF+IoZmwEAPcCnxCHphiSI7DKYTiBRxCEGF7tk1VK5+EZV6/Cww1Bk9XP5d1TglNAFBLBwjFXudDhwAAAFwBAABQSwMEFAAIAAgAT2xxPwAAAAAAAAAAAAAAACsAAAAwM2IyYmI2Yzk5MmU2NDA3MzAxMzcyMmNhZTEyZjkzYlx0cm9uY28ucG5n6wzwc+flkuJiYGDg9fRwCQLSCiDMwQYki6uqvgApN08Xx5CKW2/PbeRlUOBhPqgzR9KIz1Y4xThAioX7iEj+y9j5qc+C0kq3Prx3aS+7gXIUEwMK+M8kYs2QKl3guruLo+TrKpCQp6ufyzqnhCYAUEsHCA5KlDpvAAAAfwAAAFBLAwQUAAgACABPbHE/AAAAAAAAAAAAAAAALwAAAGY5YzQzOWM2NzA2OGNlZTE5OTc3OWMzMWNiMzRiN2NlXGNvcGFfYXJib2wucG5nAUYBuf6JUE5HDQoaCgAAAA1JSERSAAAAIAAAACAIBgAAAHN6evQAAAENSURBVHja5de/agJBEMdxn3YMChrsNBCQ2PgaeQIrC6sTUiaNRRDBxjYqhJTx33cKF4mXY/fc2ymcD3fNHcyP4+52tpZl2dHyqOnJt37wBPnHM/Qe3/IOMIEEmuLmAN+QG9Txi1IBXiGRvCEoQA8S2QheAcaQiuxQGOAAqVhhAEngEbkBVpBEcgNIQl2YBjg/BRdghtQB9nABWkgd4B0ugBgYwDSArhP3HWAI05fwAy7AJ0w/Q/MfkVYDqZq/4CrABqaLkdYDqm7eR+FEZD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fmfxXZ+bxi7TK90wJ1gxZDC+zl732RTlK8IqVvIWpVwwhofZ1/QYO+NWK1YoFxxv3deMD5rR4nKDfLbujPinZPojDF8iFFw7kcfAy16Xinc05VEBr3bNLVlVcU+jM1XifLTugXtoODOExNjRQkL3ZSeU+YKCPgLQIY1NXhMMX2v1fUEsHCNhju8z6AwAAPgoAAFBLAQIUABQACAAIAE9scT/FXudDhwAAAFwBAAAWAAAAAAAAAAAAAAAAAAAAAABnZW9nZWJyYV90aHVtYm5haWwucG5nUEsBAhQAFAAIAAgAT2xxPw5KlDpvAAAAfwAAACsAAAAAAAAAAAAAAAAAywAAADAzYjJiYjZjOTkyZTY0MDczMDEzNzIyY2FlMTJmOTNiXHRyb25jby5wbmdQSwECFAAUAAgACABPbHE/u9OdWUsBAABGAQAALwAAAAAAAAAAAAAAAACTAQAAZjljNDM5YzY3MDY4Y2VlMTk5Nzc5YzMxY2IzNGI3Y2VcY29wYV9hcmJvbC5wbmdQSwECFAAUAAgACABPbHE/zknhF6sCAACmAgAALQAAAAAAAAAAAAAAAAA7AwAAOWFjNjJiNTRlZTI3ZDhkNWRhNWM4OGU4MjE3MDg5MWNcbWFuemFuYXMucG5nUEsBAhQAFAAIAAgAT2xxP64bZWDfBAAAuhkAABIAAAAAAAAAAAAAAAAAQQYAAGdlb2dlYnJhX21hY3JvLnhtbFBLAQIUABQACAAIAE9scT/WN725GQAAABcAAAAWAAAAAAAAAAAAAAAAAGALAABnZW9nZWJyYV9qYXZhc2NyaXB0LmpzUEsBAhQAFAAIAAgAT2xxP9hju8z6AwAAPgoAAAwAAAAAAAAAAAAAAAAAvQsAAGdlb2dlYnJhLnhtbFBLBQYAAAAABwAHABMCAADxDwAAAAA=';
} else if (isset($materialid) && !empty($materialid)) {
$attribs['material_id'] = $materialid;
} else {
return false;
}
echo '<script type="text/javascript" src="//www.geogebratube.org/scripts/deployggb.js"></script>';
echo '<script>window.onload = function() {
var applet = new GGBApplet({';
foreach ($attribnames as $name) {
echo $name.': '.geogebra_get_script_param($name, $attributes).',';
}
foreach ($attribs as $name => $value) {
echo $name.': "'.$value.'",';
}
echo '}, true);
applet.inject("applet_container", "preferHTML5");
}
</script>
<div id="applet_container" style="width: 100%; height: '.$geogebra->height.'px;"></div>';
// Include also javascript code from GGB file
geogebra_get_js_from_geogebra($context, $geogebra);
return;
}
/**
* Execute Javascript that is embedded in the geogebra file, if it exists
* File must be named geogebra_javascript.js
* @param object $context Of the activity to get the files
* @param object $geogebra object with the activity info
*/
function geogebra_get_js_from_geogebra($context, $geogebra) {
global $CFG;
$content = false;
if (geogebra_is_valid_external_url($geogebra->url)) {
require_once("$CFG->libdir/filestorage/zip_packer.php");
// Prepare tmp dir (create if not exists, download ggb file...)
$dirname = 'mod_geogebra_'.time();
$tmpdir = make_temp_directory($dirname);
if (!$tmpdir) {
debugging("Cannot create temp directory $dirname");
return;
}
$materialid = geogebra_get_id($geogebra->url);
if ($materialid) {
$ggbfile = "http://tube.geogebra.org/material/download/format/file/id/$materialid";
} else {
$ggbfile = $geogebra->url;
}
$filename = pathinfo($ggbfile, PATHINFO_FILENAME);
$tmpggbfile = tempnam($tmpdir, $filename.'_');
// Download external GGB and extract javascript file
if (!download_file_content($ggbfile, null, null, false, 300, 20, false, $tmpggbfile)) {
debugging("Error copying from $ggbfile");
return;
}
// Extract geogebra js from GGB file
$zip = new zip_packer();
$extract = $zip->extract_to_pathname($tmpggbfile, $tmpdir, array('geogebra_javascript.js'));
if ($extract && $extract['geogebra_javascript.js']) {
unlink($tmpggbfile);
} else {
@unlink($tmpggbfile);
@rmdir($tmpdir);
debugging("Cannot open zipfile $tmpggbfile");
return;
}
$content = file_get_contents($tmpdir.'/geogebra_javascript.js');
// Delete temporary files
unlink($tmpdir.'/geogebra_javascript.js');
rmdir($tmpdir);
} else {
$fs = get_file_storage();
$file = $fs->get_file($context->id, 'mod_geogebra', 'extracted_files', 0, '/', 'geogebra_javascript.js');
if ($file) {
$content = $file->get_content();
}
}
if (empty($content)) {
debugging("Empty content");
return;
}
echo '<script type="text/javascript">
if (typeof ggbApplet == \'undefined\') {
ggbApplet = document.ggbApplet;
}
' .$content . '</script>';
}
/**
* Returns a link with info about the state of the geogebra attempts
*
* This is used by view_header to put this link at the top right of the page.
* For teachers it gives the number of attempted geogebras with a link
* For students it gives the time of their last attempt.
*
* @global object
* @global object
* @param bool $allgroup print all groups info if user can access all groups, suitable for index.php
* @return string
*/
function geogebra_submittedlink($allgroups = false) {
global $USER;
global $CFG;
$submitted = '';
$urlbase = "{$CFG->wwwroot}/mod/geogebra/";
/* $context = context_module::instance($this->cm->id);
if (has_capability('moodle/grade:viewall', $context)) {
if ($allgroups and has_capability('moodle/site:accessallgroups', $context)) {
$group = 0;
} else {
$group = groups_get_activity_group($this->cm);
}
$submitted = 'teacher';
} else {
if (isloggedin()) {
$submitted = 'student';
}
}
*/
return $submitted;
}
/**
* Get moodle server
*
* @return string myserver.com:port
*/
function geogebra_get_server() {
global $CFG;
if (!empty($CFG->wwwroot)) {
$url = parse_url($CFG->wwwroot);
}
if (!empty($url['host'])) {
$hostname = $url['host'];
} else if (!empty($_SERVER['SERVER_NAME'])) {
$hostname = $_SERVER['SERVER_NAME'];
} else if (!empty($_ENV['SERVER_NAME'])) {
$hostname = $_ENV['SERVER_NAME'];
} else if (!empty($_SERVER['HTTP_HOST'])) {
$hostname = $_SERVER['HTTP_HOST'];
} else if (!empty($_ENV['HTTP_HOST'])) {
$hostname = $_ENV['HTTP_HOST'];
} else {
notify('Warning: could not find the name of this server!');
return false;
}
if (!empty($url['port'])) {
$hostname .= ':'.$url['port'];
} else if (!empty($_SERVER['SERVER_PORT'])) {
if ($_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) {
$hostname .= ':'.$_SERVER['SERVER_PORT'];
}
}
return $hostname;
}
/**
* Get moodle path
*
* @return string /path_to_moodle
*/
function geogebra_get_path() {
global $CFG;
$path = '/';
if (!empty($CFG->wwwroot)) {
$url = parse_url($CFG->wwwroot);
if (array_key_exists('path', $url)) {
$path = $url['path'];
}
}
return $path;
}
function geogebra_get_filemanager_options() {
$options = array();
$options['return_types'] = 3; // 3 == FILE_EXTERNAL & FILE_INTERNAL. These two constant names are defined in repository/lib.php
$options['accepted_types'] = 'archive';
$options['accepted_types'] = '*'; // array('.ggb');
$options['maxbytes'] = 0;
$options['subdirs'] = 0;
$options['maxfiles'] = 1;
return $options;
}
function geogebra_set_mainfile($data) {
$cmid = $data->coursemodule;
$draftitemid = $data->url;
$context = context_module::instance($cmid);
if ($draftitemid) {
file_save_draft_area_files($draftitemid, $context->id, 'mod_geogebra', 'content', 0, geogebra_get_filemanager_options());
}
$filename = geogebra_extract_package($cmid);
/* Codi antic
$fs = get_file_storage();
$files = $fs->get_area_files($context->id, 'mod_geogebra', 'content', 0, 'sortorder', false);
if (count($files) == 1) {
// only one file attached, set it as main file automatically
$file = reset($files);
file_set_sortorder($context->id, 'mod_geogebra', 'content', 0, $file->get_filepath(), $file->get_filename(), 1);
$filename = $file->get_filename();
}
*/
return $filename;
}
/**
* Extracts GGB package, sets up all variables.
* @param int $cmid
* @return filename
*/
function geogebra_extract_package($cmid) {
global $DB;
$fs = get_file_storage();
$context = context_module::instance($cmid);
$files = $fs->get_area_files($context->id, 'mod_geogebra', 'content', 0, 'sortorder', false);
if (count($files) == 1) {
// only one file attached, set it as main file automatically
$package = reset($files);
file_set_sortorder($context->id, 'mod_geogebra', 'content', 0, $package->get_filepath(), $package->get_filename(), 1);
$filename = $package->get_filename();
// Extract files
$fs->delete_area_files($context->id, 'mod_geogebra', 'extracted_files');
$packer = get_file_packer('application/zip');
$package->extract_to_storage($packer, $context->id, 'mod_geogebra', 'extracted_files', 0, '/');
}
return $filename;
}
function geogebra_is_valid_external_url($url) {
return preg_match('/(http:\/\/|https:\/\/|www).*\/*(\?[a-z+&\$_.-][a-z0-9;:@&%=+\/\$_.-]*)?$/i', $url);
}
function geogebra_is_valid_file($filename) {
return preg_match('/.ggb$/i', $filename);
}
// Attempts
/**
* Convert specified time (in milliseconds) to XX' YY'' format
*
* @param type $time time (in milliseconds) to format
*/
function geogebra_format_time($time) {
return floor($time / 60000)."' ".round(fmod($time, 60000) / 1000, 0)."''";
}
/**
* Format time from milliseconds to string
*
* @return string Formated string [x' y''], where x are the minutes and y are the seconds.
* @param int $time The time (in ms)
*/
function geogebra_time2str($time) {
$minutes = floor($time / 60);
$seconds = sprintf("%02s", round(fmod((double)$time, 60), 0));
return ($minutes > 0 ? $minutes . "' " : " ") . $seconds . "''";
}
function geogebra_view_results($geogebra, $context, $cm, $course, $action) {
global $CFG, $DB, $OUTPUT, $PAGE, $USER;
if ($action == 'submitgrade') {
// Upgrade submitted grade
$grade = optional_param('grade', '', PARAM_INT);
$gradecomment = optional_param_array('comment_editor', '', PARAM_RAW);
$attemptid = optional_param('attemptid', '', PARAM_INT);
$attempt = geogebra_get_attempt($attemptid);
parse_str($attempt->vars, $parsedvars);
$parsedvars['grade'] = $grade;
$attempt->vars = http_build_query($parsedvars, '', '&');
geogebra_update_attempt($attemptid, $attempt->vars, GEOGEBRA_UPDATE_TEACHER, $gradecomment['text']);
}
// Show students list with their results
require_once($CFG->libdir.'/gradelib.php');
$perpage = optional_param('perpage', 10, PARAM_INT);
$perpage = ($perpage <= 0) ? 10 : $perpage;
$page = optional_param('page', 0, PARAM_INT);
// Find out current groups mode
$groupmode = groups_get_activity_groupmode($cm);
$currentgroup = groups_get_activity_group($cm, true);
// Get all ppl that are allowed to submit geogebra
list($esql, $params) = get_enrolled_sql($context, 'mod/geogebra:submit', $currentgroup);
$sql = "SELECT u.id FROM {user} u ".
"LEFT JOIN ($esql) eu ON eu.id=u.id ".
"WHERE u.deleted = 0 AND eu.id=u.id ";
$users = $DB->get_records_sql($sql, $params);
if (!empty($users)) {
$users = array_keys($users);
}
// If groupmembersonly used, remove users who are not in any group
if ($users and !empty($CFG->enablegroupmembersonly) and $cm->groupmembersonly) {
if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) {
$users = array_intersect($users, array_keys($groupingusers));
}
}
// TODO: Review to show all users information
if (!empty($users)) {
// Create results table
$extrafields = get_extra_user_fields($context);
$tablecolumns = array_merge(array('picture', 'fullname'), $extrafields,
array('attempts', 'duration', 'grade', 'comment', 'datestudent', 'dateteacher', 'status'));
$extrafieldnames = array();
foreach ($extrafields as $field) {
$extrafieldnames[] = get_user_field_name($field);
}
$tableheaders = array_merge(
array('', get_string('fullnameuser')),
$extrafieldnames,
array(
get_string('attempts', 'geogebra'),
get_string('duration', 'geogebra'),
get_string('grade'),
get_string('comment', 'geogebra'),
get_string('lastmodifiedsubmission', 'geogebra'),
get_string('lastmodifiedgrade', 'geogebra'),
get_string('status', 'geogebra'),
));
require_once($CFG->libdir.'/tablelib.php');
$table = new flexible_table('mod-geogebra-results');
$table->define_columns($tablecolumns);
$table->define_headers($tableheaders);
$table->define_baseurl($CFG->wwwroot.'/mod/geogebra/report.php?id='.$cm->id.'&currentgroup='.$currentgroup);
$table->sortable(true, 'lastname'); // Sorted by lastname by default
$table->collapsible(true);
$table->initialbars(true);
$table->column_suppress('picture');
$table->column_suppress('fullname');
$table->column_class('picture', 'picture');
$table->column_class('fullname', 'fullname');
foreach ($extrafields as $field) {
$table->column_class($field, $field);
}
$table->set_attribute('cellspacing', '0');
$table->set_attribute('id', 'attempts');
$table->set_attribute('class', 'results generaltable generalbox');
$table->set_attribute('width', '100%');
$table->no_sorting('attempts');
$table->no_sorting('duration');
$table->no_sorting('grade');
$table->no_sorting('comment');
$table->no_sorting('datestudent');
$table->no_sorting('dateteacher');
$table->no_sorting('status');
// Start working -- this is necessary as soon as the niceties are over
$table->setup();
// Construct the SQL
list($where, $params) = $table->get_sql_where();
if ($where) {
$where .= ' AND ';
}
if ($sort = $table->get_sql_sort()) {
$sort = ' ORDER BY '.$sort;
}
$ufields = user_picture::fields('u', $extrafields);
$select = "SELECT $ufields ";
$sql = 'FROM {user} u WHERE '.$where.'u.id IN ('.implode(',', $users).') ';
$ausers = $DB->get_records_sql($select.$sql.$sort, $params, $table->get_page_start(), $table->get_page_size());
$table->pagesize($perpage, count($users));
$offset = $page * $perpage; // Offset used to calculate index of student in that particular query, needed for the pop up to know who's next
if ($ausers !== false) {
// $grading_info = grade_get_grades($course->id, 'mod', 'geogebra', $geogebra->id, array_keys($ausers));
foreach ($ausers as $auser) {
$picture = $OUTPUT->user_picture($auser);
$userlink = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $auser->id . '&course=' . $course->id . '">' .
fullname($auser, has_capability('moodle/site:viewfullnames', $context)) . '</a>';
$row = array($picture, $userlink);
$extradata = array();
foreach ($extrafields as $field) {
$extradata[] = $auser->{$field};
}
$row += $extradata;
// Attempts summary
$attempts = geogebra_get_user_attempts($geogebra->id, $auser->id);
$attemptssummary = geogebra_get_user_grades($geogebra, $auser->id);
if ($attemptssummary) {
$row[] = $attemptssummary->attempts;
$row[] = geogebra_time2str($attemptssummary->duration);
$row[] = $attemptssummary->grade;
$rowclass = ($attemptssummary->attempts > 0)?'summary-row':"";
} else {
$row[] = "";
$row[] = "";
$row[] = "";
$rowclass = "";
}
$row[] = "";
$row[] = "";
$row[] = "";
$row[] = "";
$table->add_data($row, $rowclass);
// Show attempts information
foreach ($attempts as $attempt) {
$row = array();
// In the attempts row, show only the summary of the attempt (it's not necessary to repeat user information)
for ($i = 0; $i < count($extradata) + 2; $i++) {
array_push($row, '');
}
// Attempt information
$row = geogebra_get_attempt_row($geogebra, $attempt, $auser, $cm, $context, $row);
/*array_push($row, $attempt->duration);
array_push($row, $attempt->grade);
array_push($row, $attempt->comment);*/
$table->add_data($row);
}
}
}
$table->print_html(); // Print the whole table
} else {
echo $OUTPUT->notification(get_string('msg_nosessions', 'geogebra'), 'notifymessage');
}
}
function geogebra_get_results_table_columns($cm = null) {
// $tablecolumns = array('picture', 'fullname', 'attempts', 'duration', 'grade', 'comment', 'datestudent', 'dateteacher', 'status');
// $tablecolumns = array('attempts', 'duration', 'grade', 'comment', 'datestudent', 'dateteacher', 'status');
$tablecolumns = array('attempts', 'duration', 'grade');
if (!empty($cm)) {
array_push($tablecolumns, 'comment');
}
array_push($tablecolumns, 'datestudent');
array_push($tablecolumns, 'dateteacher');
if (!empty($cm)) {
array_push($tablecolumns, 'status');
}
$tableheaders = array();
foreach ($tablecolumns as $tablecolumn) {
$tableheaders[] = get_string($tablecolumn, 'geogebra');
}
return array('tablecolumns' => $tablecolumns, 'tableheaders' => $tableheaders);
}
function geogebra_view_userid_results($geogebra, $userid, $cm, $context, $action, $attempt = null) {
global $CFG, $DB, $OUTPUT, $PAGE, $USER;
require_once($CFG->libdir.'/tablelib.php');
$table = new flexible_table('mod-geogebra-results');
$user = $DB->get_record('user', array('id' => $userid));
$tablecolumns = geogebra_get_results_table_columns($action == 'view' ? null : $cm);
$table->define_columns($tablecolumns['tablecolumns']);
$table->define_headers($tablecolumns['tableheaders']);
$table->define_baseurl($CFG->wwwroot.'/mod/geogebra/view.php?id='.$cm->id);
$table->set_attribute('cellspacing', '0');
$table->set_attribute('id', 'attempts');
$table->set_attribute('class', 'results generaltable generalbox');
$table->set_attribute('width', '100%');
// Start working -- this is necessary as soon as the niceties are over
$table->setup();
// Construct the SQL
list($where, $params) = $table->get_sql_where();
if ($where) {
$where .= ' AND ';
}
// $sort = ' ORDER BY attemptid';
// Show results only for specified user
if (!empty($attempt)) {
// Show only results of specified attempt
$table = new html_table();
$table->size = array('10%', '90%');
parse_str($attempt->vars, $parsedvars);
$numattempt = $parsedvars['attempts'];
if (!$attempt->finished) {
$numattempt .= ' (' . get_string('unfinished', 'geogebra') . ')';
}
$duration = geogebra_time2str($parsedvars['duration']);
$grade = $parsedvars['grade'];
if ($grade < 0 ) {
$grade = '';
}
if (is_siteadmin() || has_capability('moodle/grade:viewall', $context, $USER->id, false)) {
// Show form to grade and comment this attempt
require_once('gradeform.php');
$data = new stdClass();
$data->id = $cm->id;
$data->student = $user->id;
$data->attemptid = $attempt->id;
$data->attempt = $numattempt;
$data->duration = $duration;
$data->grade = $grade;
$data->comment_editor['text'] = $attempt->gradecomment;
$data->comment_editor['format'] = FORMAT_HTML;
// Create form
$mform = new mod_geogebra_grade_form(null, array($geogebra, $data, null), 'post', '', array('class' => 'gradeform'));
} else {
if ($geogebra->grade < 0 ) {
// Get scale name
$grademenu = make_grades_menu($geogebra->grade);
if (!empty($grade)) {
$grade = $grademenu[$grade];
}
}
// Show attempt
geogebra_add_table_row_tuple($table, get_string('attempt', 'geogebra'), $numattempt);
geogebra_add_table_row_tuple($table, get_string('duration', 'geogebra'), $duration);
geogebra_add_table_row_tuple($table, get_string('grade'), $grade);
geogebra_add_table_row_tuple($table, get_string('comment', 'geogebra'), $attempt->gradecomment);
}
// Print attempt information with grade and comment form if user can grade
if (!empty($mform)) {
// Print user information
$picture = $OUTPUT->user_picture($user);
$userlink = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $user->id . '&course=' . $geogebra->course . '">'
. fullname($user, has_capability('moodle/site:viewfullnames', $context)) . '</a>';
echo $picture.' '.$userlink.' ('.$user->email.')';
// Print form
$mform->display();
} else {
echo html_writer::table($table);
}
} else {
// Show all attempts information
$attempts = geogebra_get_user_attempts($geogebra->id, $user->id);
foreach ($attempts as $attempt) {
$row = geogebra_get_attempt_row($geogebra, $attempt, $user, $cm, $context);
$rowclass = '';
$table->add_data($row, $rowclass);
}
$table->print_html(); // Print the whole table
}
}
/**
*
* @global type $CFG
* @param type $attempt
* @param type $user
* @param type $cm
* @param array $row
* @return array
*/
function geogebra_get_attempt_row($geogebra, $attempt, $user, $cm = null, $context = null, $row = null) {
global $CFG, $USER;
if (empty($row)) {
$row = array();
}
parse_str($attempt->vars, $parsedvars);
$numattempt = $parsedvars['attempts'];
if (!$attempt->finished) {
$numattempt .= ' (' . get_string('unfinished', 'geogebra') . ')';
}
array_push($row, $numattempt);
$duration = geogebra_time2str($parsedvars['duration']);
array_push($row, $duration);
$grade = $parsedvars['grade'];
if ($grade < 0 ) {
$grade = '-';
} else if ($geogebra->grade < 0 ) {
// Get scale name
$grademenu = make_grades_menu($geogebra->grade);
$grade = $grademenu[$grade];
}
array_push($row, $grade);
// $row = array($numattempt, $duration, $grade, $gradecomment, $datestudent, $dateteacher);
if (!empty($cm)) {
$gradecomment = !empty($attempt->gradecomment) ? shorten_text(trim(strip_tags(format_text($attempt->gradecomment))), 25) : '';
array_push($row, $gradecomment);
}
$datestudent = !empty($attempt->datestudent) ? userdate($attempt->datestudent) : '';
array_push($row, $datestudent);
$dateteacher = !empty($attempt->dateteacher) ? userdate($attempt->dateteacher) : '';
array_push($row, $dateteacher);
if (!empty($cm)) {
$textlink = get_string('viewattempt', 'geogebra');
if (is_siteadmin() || has_capability('moodle/grade:viewall', $context, $USER->id, false)) {
if ($attempt->dateteacher < $attempt->datestudent ) {
$textlink = '<span class="pendinggrade" >'. get_string('grade'). '</span>';
} else {
$textlink = get_string('update');
}
}
$status = '<a href="' . $CFG->wwwroot . '/mod/geogebra/view.php?id=' . $cm->id . '&student=' . $user->id .'&attemptid='.$attempt->id.'"> ' . $textlink . '</a>';
array_push($row, $status);
}
return $row;
}
function geogebra_add_table_row_tuple(html_table $table, $first, $second) {
$row = new html_table_row();
$cell1 = new html_table_cell('<b>'.$first.'</b>');
$cell2 = new html_table_cell($second);
$row->cells = array($cell1, $cell2);
$table->data[] = $row;
}
/**
* Workaround to fix an Oracle's bug when inserting a row with date
*/
function geogebra_normalize_date () {
global $CFG, $DB;
if ($CFG->dbtype == 'oci') {
$sql = "ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'";
$DB->execute($sql);
}
}
/**
* Count the finished attempts done by the $userid
*/
function geogebra_count_finished_attempts($geogebraid, $userid) {
global $DB;
return $DB->count_records('geogebra_attempts', array('userid' => $userid, 'geogebra' => $geogebraid, 'finished' => '1'));
}
/**
* Return the unfinished attempt of a user. Only 1 attempt for each (user, geogebra) can be unfinished
*
* @param type $geogebra_id ID of an instance of this module
* @param type $user_id ID of a user
* @return mixed null/geogebra attempt object
*/
function geogebra_get_unfinished_attempt($geogebraid, $userid) {
global $DB;
return $DB->get_record('geogebra_attempts', array('userid' => $userid, 'geogebra' => $geogebraid, 'finished' => '0'));
}
/**
* Returns a geogebra attempt
*