forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deprecatedlib.php
4015 lines (3646 loc) · 129 KB
/
deprecatedlib.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/>.
/**
* deprecatedlib.php - Old functions retained only for backward compatibility
*
* Old functions retained only for backward compatibility. New code should not
* use any of these functions.
*
* @package core
* @subpackage deprecated
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @deprecated
*/
defined('MOODLE_INTERNAL') || die();
/**
* Unsupported session id rewriting.
* @deprecated
* @param string $buffer
*/
function sid_ob_rewrite($buffer) {
throw new coding_exception('$CFG->usesid support was removed completely and can not be used.');
}
/**
* Insert or update log display entry. Entry may already exist.
* $module, $action must be unique
* @deprecated
*
* @param string $module
* @param string $action
* @param string $mtable
* @param string $field
* @return void
*
*/
function update_log_display_entry($module, $action, $mtable, $field) {
global $DB;
debugging('The update_log_display_entry() is deprecated, please use db/log.php description file instead.');
}
/**
* Given some text in HTML format, this function will pass it
* through any filters that have been configured for this context.
*
* @deprecated use the text formatting in a standard way instead,
* this was abused mostly for embedding of attachments
*
* @param string $text The text to be passed through format filters
* @param int $courseid The current course.
* @return string the filtered string.
*/
function filter_text($text, $courseid = NULL) {
global $CFG, $COURSE;
if (!$courseid) {
$courseid = $COURSE->id;
}
if (!$context = get_context_instance(CONTEXT_COURSE, $courseid)) {
return $text;
}
return filter_manager::instance()->filter_text($text, $context);
}
/**
* This function indicates that current page requires the https
* when $CFG->loginhttps enabled.
*
* By using this function properly, we can ensure 100% https-ized pages
* at our entire discretion (login, forgot_password, change_password)
* @deprecated use $PAGE->https_required() instead
*/
function httpsrequired() {
global $PAGE;
$PAGE->https_required();
}
/**
* Given a physical path to a file, returns the URL through which it can be reached in Moodle.
*
* @deprecated use moodle_url factory methods instead
*
* @param string $path Physical path to a file
* @param array $options associative array of GET variables to append to the URL
* @param string $type (questionfile|rssfile|httpscoursefile|coursefile)
* @return string URL to file
*/
function get_file_url($path, $options=null, $type='coursefile') {
global $CFG;
$path = str_replace('//', '/', $path);
$path = trim($path, '/'); // no leading and trailing slashes
// type of file
switch ($type) {
case 'questionfile':
$url = $CFG->wwwroot."/question/exportfile.php";
break;
case 'rssfile':
$url = $CFG->wwwroot."/rss/file.php";
break;
case 'httpscoursefile':
$url = $CFG->httpswwwroot."/file.php";
break;
case 'coursefile':
default:
$url = $CFG->wwwroot."/file.php";
}
if ($CFG->slasharguments) {
$parts = explode('/', $path);
foreach ($parts as $key => $part) {
/// anchor dash character should not be encoded
$subparts = explode('#', $part);
$subparts = array_map('rawurlencode', $subparts);
$parts[$key] = implode('#', $subparts);
}
$path = implode('/', $parts);
$ffurl = $url.'/'.$path;
$separator = '?';
} else {
$path = rawurlencode('/'.$path);
$ffurl = $url.'?file='.$path;
$separator = '&';
}
if ($options) {
foreach ($options as $name=>$value) {
$ffurl = $ffurl.$separator.$name.'='.$value;
$separator = '&';
}
}
return $ffurl;
}
/**
* If there has been an error uploading a file, print the appropriate error message
* Numerical constants used as constant definitions not added until PHP version 4.2.0
* @deprecated removed - use new file api
*/
function print_file_upload_error($filearray = '', $returnerror = false) {
throw new coding_exception('print_file_upload_error() can not be used any more, please use new file API');
}
/**
* Handy function for resolving file conflicts
* @deprecated removed - use new file api
*/
function resolve_filename_collisions($destination,$files,$format='%s_%d.%s') {
throw new coding_exception('resolve_filename_collisions() can not be used any more, please use new file API');
}
/**
* Checks a file name for any conflicts
* @deprecated removed - use new file api
*/
function check_potential_filename($destination,$filename,$files) {
throw new coding_exception('check_potential_filename() can not be used any more, please use new file API');
}
/**
* This function prints out a number of upload form elements.
* @deprecated removed - use new file api
*/
function upload_print_form_fragment($numfiles=1, $names=null, $descriptions=null, $uselabels=false, $labelnames=null, $coursebytes=0, $modbytes=0, $return=false) {
throw new coding_exception('upload_print_form_fragment() can not be used any more, please use new file API');
}
/**
* Return the authentication plugin title
*
* @param string $authtype plugin type
* @return string
*/
function auth_get_plugin_title($authtype) {
debugging('Function auth_get_plugin_title() is deprecated, please use standard get_string("pluginname", "auth_'.$authtype.'")!');
return get_string('pluginname', "auth_{$authtype}");
}
/**
* Enrol someone without using the default role in a course
* @deprecated
*/
function enrol_into_course($course, $user, $enrol) {
error('Function enrol_into_course() was removed, please use new enrol plugins instead!');
}
/**
* Returns a role object that is the default role for new enrolments in a given course
*
* @deprecated
* @param object $course
* @return object returns a role or NULL if none set
*/
function get_default_course_role($course) {
debugging('Function get_default_course_role() is deprecated, please use individual enrol plugin settings instead!');
$student = get_archetype_roles('student');
$student = reset($student);
return $student;
}
/**
* Extremely slow enrolled courses query.
* @deprecated
*/
function get_my_courses($userid, $sort='visible DESC,sortorder ASC', $fields=NULL, $doanything=false,$limit=0) {
error('Function get_my_courses() was removed, please use new enrol_get_my_courses() or enrol_get_users_courses()!');
}
/**
* Was returning list of translations, use new string_manager instead
*
* @deprecated
* @param bool $refreshcache force refreshing of lang cache
* @param bool $returnall ignore langlist, return all languages available
* @return array An associative array with contents in the form of LanguageCode => LanguageName
*/
function get_list_of_languages($refreshcache=false, $returnall=false) {
debugging('get_list_of_languages() is deprecated, please use get_string_manager()->get_list_of_translations() instead.');
if ($refreshcache) {
get_string_manager()->reset_caches();
}
return get_string_manager()->get_list_of_translations($returnall);
}
/**
* Returns a list of currencies in the current language
* @deprecated
* @return array
*/
function get_list_of_currencies() {
debugging('get_list_of_currencies() is deprecated, please use get_string_manager()->get_list_of_currencies() instead.');
return get_string_manager()->get_list_of_currencies();
}
/**
* Returns a list of all enabled country names in the current translation
* @deprecated
* @return array two-letter country code => translated name.
*/
function get_list_of_countries() {
debugging('get_list_of_countries() is deprecated, please use get_string_manager()->get_list_of_countries() instead.');
return get_string_manager()->get_list_of_countries(false);
}
/**
* @deprecated
*/
function isteacher() {
error('Function isteacher() was removed, please use capabilities instead!');
}
/**
* @deprecated
*/
function isteacherinanycourse() {
error('Function isteacherinanycourse() was removed, please use capabilities instead!');
}
/**
* @deprecated
*/
function get_guest() {
error('Function get_guest() was removed, please use capabilities instead!');
}
/**
* @deprecated
*/
function isguest() {
error('Function isguest() was removed, please use capabilities instead!');
}
/**
* @deprecated
*/
function get_teacher() {
error('Function get_teacher() was removed, please use capabilities instead!');
}
/**
* Return all course participant for a given course
*
* @deprecated
* @param integer $courseid
* @return array of user
*/
function get_course_participants($courseid) {
return get_enrolled_users(get_context_instance(CONTEXT_COURSE, $courseid));
}
/**
* Return true if the user is a participant for a given course
*
* @deprecated
* @param integer $userid
* @param integer $courseid
* @return boolean
*/
function is_course_participant($userid, $courseid) {
return is_enrolled(get_context_instance(CONTEXT_COURSE, $courseid), $userid);
}
/**
* Searches logs to find all enrolments since a certain date
*
* used to print recent activity
*
* @global object
* @uses CONTEXT_COURSE
* @param int $courseid The course in question.
* @param int $timestart The date to check forward of
* @return object|false {@link $USER} records or false if error.
*/
function get_recent_enrolments($courseid, $timestart) {
global $DB;
$context = get_context_instance(CONTEXT_COURSE, $courseid);
$sql = "SELECT u.id, u.firstname, u.lastname, MAX(l.time)
FROM {user} u, {role_assignments} ra, {log} l
WHERE l.time > ?
AND l.course = ?
AND l.module = 'course'
AND l.action = 'enrol'
AND ".$DB->sql_cast_char2int('l.info')." = u.id
AND u.id = ra.userid
AND ra.contextid ".get_related_contexts_string($context)."
GROUP BY u.id, u.firstname, u.lastname
ORDER BY MAX(l.time) ASC";
$params = array($timestart, $courseid);
return $DB->get_records_sql($sql, $params);
}
/**
* Turn the ctx* fields in an objectlike record into a context subobject
* This allows us to SELECT from major tables JOINing with
* context at no cost, saving a ton of context lookups...
*
* Use context_instance_preload() instead.
*
* @deprecated since 2.0
* @param object $rec
* @return object
*/
function make_context_subobj($rec) {
$ctx = new StdClass;
$ctx->id = $rec->ctxid; unset($rec->ctxid);
$ctx->path = $rec->ctxpath; unset($rec->ctxpath);
$ctx->depth = $rec->ctxdepth; unset($rec->ctxdepth);
$ctx->contextlevel = $rec->ctxlevel; unset($rec->ctxlevel);
$ctx->instanceid = $rec->id;
$rec->context = $ctx;
return $rec;
}
/**
* Do some basic, quick checks to see whether $rec->context looks like a valid context object.
*
* Use context_instance_preload() instead.
*
* @deprecated since 2.0
* @param object $rec a think that has a context, for example a course,
* course category, course modules, etc.
* @param int $contextlevel the type of thing $rec is, one of the CONTEXT_... constants.
* @return bool whether $rec->context looks like the correct context object
* for this thing.
*/
function is_context_subobj_valid($rec, $contextlevel) {
return isset($rec->context) && isset($rec->context->id) &&
isset($rec->context->path) && isset($rec->context->depth) &&
isset($rec->context->contextlevel) && isset($rec->context->instanceid) &&
$rec->context->contextlevel == $contextlevel && $rec->context->instanceid == $rec->id;
}
/**
* Ensure that $rec->context is present and correct before you continue
*
* When you have a record (for example a $category, $course, $user or $cm that may,
* or may not, have come from a place that does make_context_subobj, you can use
* this method to ensure that $rec->context is present and correct before you continue.
*
* Use context_instance_preload() instead.
*
* @deprecated since 2.0
* @param object $rec a thing that has an associated context.
* @param integer $contextlevel the type of thing $rec is, one of the CONTEXT_... constants.
*/
function ensure_context_subobj_present(&$rec, $contextlevel) {
if (!is_context_subobj_valid($rec, $contextlevel)) {
$rec->context = get_context_instance($contextlevel, $rec->id);
}
}
########### FROM weblib.php ##########################################################################
/**
* Print a message in a standard themed box.
* This old function used to implement boxes using tables. Now it uses a DIV, but the old
* parameters remain. If possible, $align, $width and $color should not be defined at all.
* Preferably just use print_box() in weblib.php
*
* @deprecated
* @param string $message The message to display
* @param string $align alignment of the box, not the text (default center, left, right).
* @param string $width width of the box, including units %, for example '100%'.
* @param string $color background colour of the box, for example '#eee'.
* @param int $padding padding in pixels, specified without units.
* @param string $class space-separated class names.
* @param string $id space-separated id names.
* @param boolean $return return as string or just print it
* @return string|void Depending on $return
*/
function print_simple_box($message, $align='', $width='', $color='', $padding=5, $class='generalbox', $id='', $return=false) {
$output = '';
$output .= print_simple_box_start($align, $width, $color, $padding, $class, $id, true);
$output .= $message;
$output .= print_simple_box_end(true);
if ($return) {
return $output;
} else {
echo $output;
}
}
/**
* This old function used to implement boxes using tables. Now it uses a DIV, but the old
* parameters remain. If possible, $align, $width and $color should not be defined at all.
* Even better, please use print_box_start() in weblib.php
*
* @param string $align alignment of the box, not the text (default center, left, right). DEPRECATED
* @param string $width width of the box, including % units, for example '100%'. DEPRECATED
* @param string $color background colour of the box, for example '#eee'. DEPRECATED
* @param int $padding padding in pixels, specified without units. OBSOLETE
* @param string $class space-separated class names.
* @param string $id space-separated id names.
* @param boolean $return return as string or just print it
* @return string|void Depending on $return
*/
function print_simple_box_start($align='', $width='', $color='', $padding=5, $class='generalbox', $id='', $return=false) {
debugging('print_simple_box(_start/_end) is deprecated. Please use $OUTPUT->box(_start/_end) instead', DEBUG_DEVELOPER);
$output = '';
$divclasses = 'box '.$class.' '.$class.'content';
$divstyles = '';
if ($align) {
$divclasses .= ' boxalign'.$align; // Implement alignment using a class
}
if ($width) { // Hopefully we can eliminate these in calls to this function (inline styles are bad)
if (substr($width, -1, 1) == '%') { // Width is a % value
$width = (int) substr($width, 0, -1); // Extract just the number
if ($width < 40) {
$divclasses .= ' boxwidthnarrow'; // Approx 30% depending on theme
} else if ($width > 60) {
$divclasses .= ' boxwidthwide'; // Approx 80% depending on theme
} else {
$divclasses .= ' boxwidthnormal'; // Approx 50% depending on theme
}
} else {
$divstyles .= ' width:'.$width.';'; // Last resort
}
}
if ($color) { // Hopefully we can eliminate these in calls to this function (inline styles are bad)
$divstyles .= ' background:'.$color.';';
}
if ($divstyles) {
$divstyles = ' style="'.$divstyles.'"';
}
if ($id) {
$id = ' id="'.$id.'"';
}
$output .= '<div'.$id.$divstyles.' class="'.$divclasses.'">';
if ($return) {
return $output;
} else {
echo $output;
}
}
/**
* Print the end portion of a standard themed box.
* Preferably just use print_box_end() in weblib.php
*
* @param boolean $return return as string or just print it
* @return string|void Depending on $return
*/
function print_simple_box_end($return=false) {
$output = '</div>';
if ($return) {
return $output;
} else {
echo $output;
}
}
/**
* Given some text this function converted any URLs it found into HTML links
*
* This core function has been replaced with filter_urltolink since Moodle 2.0
*
* @param string $text Passed in by reference. The string to be searched for urls.
*/
function convert_urls_into_links($text) {
debugging('convert_urls_into_links() has been deprecated and replaced by a new filter');
}
/**
* Used to be called from help.php to inject a list of smilies into the
* emoticons help file.
*
* @return string HTML
*/
function get_emoticons_list_for_help_file() {
debugging('get_emoticons_list_for_help_file() has been deprecated, see the new emoticon_manager API');
return '';
}
/**
* Was used to replace all known smileys in the text with image equivalents
*
* This core function has been replaced with filter_emoticon since Moodle 2.0
*/
function replace_smilies(&$text) {
debugging('replace_smilies() has been deprecated and replaced with the new filter_emoticon');
}
/**
* deprecated - use clean_param($string, PARAM_FILE); instead
* Check for bad characters ?
*
* @todo Finish documenting this function - more detail needed in description as well as details on arguments
*
* @param string $string ?
* @param int $allowdots ?
* @return bool
*/
function detect_munged_arguments($string, $allowdots=1) {
if (substr_count($string, '..') > $allowdots) { // Sometimes we allow dots in references
return true;
}
if (preg_match('/[\|\`]/', $string)) { // check for other bad characters
return true;
}
if (empty($string) or $string == '/') {
return true;
}
return false;
}
/**
* Unzip one zip file to a destination dir
* Both parameters must be FULL paths
* If destination isn't specified, it will be the
* SAME directory where the zip file resides.
*
* @global object
* @param string $zipfile The zip file to unzip
* @param string $destination The location to unzip to
* @param bool $showstatus_ignored Unused
*/
function unzip_file($zipfile, $destination = '', $showstatus_ignored = true) {
global $CFG;
//Extract everything from zipfile
$path_parts = pathinfo(cleardoubleslashes($zipfile));
$zippath = $path_parts["dirname"]; //The path of the zip file
$zipfilename = $path_parts["basename"]; //The name of the zip file
$extension = $path_parts["extension"]; //The extension of the file
//If no file, error
if (empty($zipfilename)) {
return false;
}
//If no extension, error
if (empty($extension)) {
return false;
}
//Clear $zipfile
$zipfile = cleardoubleslashes($zipfile);
//Check zipfile exists
if (!file_exists($zipfile)) {
return false;
}
//If no destination, passed let's go with the same directory
if (empty($destination)) {
$destination = $zippath;
}
//Clear $destination
$destpath = rtrim(cleardoubleslashes($destination), "/");
//Check destination path exists
if (!is_dir($destpath)) {
return false;
}
$packer = get_file_packer('application/zip');
$result = $packer->extract_to_pathname($zipfile, $destpath);
if ($result === false) {
return false;
}
foreach ($result as $status) {
if ($status !== true) {
return false;
}
}
return true;
}
/**
* Zip an array of files/dirs to a destination zip file
* Both parameters must be FULL paths to the files/dirs
*
* @global object
* @param array $originalfiles Files to zip
* @param string $destination The destination path
* @return bool Outcome
*/
function zip_files ($originalfiles, $destination) {
global $CFG;
//Extract everything from destination
$path_parts = pathinfo(cleardoubleslashes($destination));
$destpath = $path_parts["dirname"]; //The path of the zip file
$destfilename = $path_parts["basename"]; //The name of the zip file
$extension = $path_parts["extension"]; //The extension of the file
//If no file, error
if (empty($destfilename)) {
return false;
}
//If no extension, add it
if (empty($extension)) {
$extension = 'zip';
$destfilename = $destfilename.'.'.$extension;
}
//Check destination path exists
if (!is_dir($destpath)) {
return false;
}
//Check destination path is writable. TODO!!
//Clean destination filename
$destfilename = clean_filename($destfilename);
//Now check and prepare every file
$files = array();
$origpath = NULL;
foreach ($originalfiles as $file) { //Iterate over each file
//Check for every file
$tempfile = cleardoubleslashes($file); // no doubleslashes!
//Calculate the base path for all files if it isn't set
if ($origpath === NULL) {
$origpath = rtrim(cleardoubleslashes(dirname($tempfile)), "/");
}
//See if the file is readable
if (!is_readable($tempfile)) { //Is readable
continue;
}
//See if the file/dir is in the same directory than the rest
if (rtrim(cleardoubleslashes(dirname($tempfile)), "/") != $origpath) {
continue;
}
//Add the file to the array
$files[] = $tempfile;
}
$zipfiles = array();
$start = strlen($origpath)+1;
foreach($files as $file) {
$zipfiles[substr($file, $start)] = $file;
}
$packer = get_file_packer('application/zip');
return $packer->archive_to_pathname($zipfiles, $destpath . '/' . $destfilename);
}
/////////////////////////////////////////////////////////////
/// Old functions not used anymore - candidates for removal
/////////////////////////////////////////////////////////////
/** various deprecated groups function **/
/**
* Get the IDs for the user's groups in the given course.
*
* @global object
* @param int $courseid The course being examined - the 'course' table id field.
* @return array|bool An _array_ of groupids, or false
* (Was return $groupids[0] - consequences!)
*/
function mygroupid($courseid) {
global $USER;
if ($groups = groups_get_all_groups($courseid, $USER->id)) {
return array_keys($groups);
} else {
return false;
}
}
/**
* Returns the current group mode for a given course or activity module
*
* Could be false, SEPARATEGROUPS or VISIBLEGROUPS (<-- Martin)
*
* @param object $course Course Object
* @param object $cm Course Manager Object
* @return mixed $course->groupmode
*/
function groupmode($course, $cm=null) {
if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
return $cm->groupmode;
}
return $course->groupmode;
}
/**
* Sets the current group in the session variable
* When $SESSION->currentgroup[$courseid] is set to 0 it means, show all groups.
* Sets currentgroup[$courseid] in the session variable appropriately.
* Does not do any permission checking.
*
* @global object
* @param int $courseid The course being examined - relates to id field in
* 'course' table.
* @param int $groupid The group being examined.
* @return int Current group id which was set by this function
*/
function set_current_group($courseid, $groupid) {
global $SESSION;
return $SESSION->currentgroup[$courseid] = $groupid;
}
/**
* Gets the current group - either from the session variable or from the database.
*
* @global object
* @param int $courseid The course being examined - relates to id field in
* 'course' table.
* @param bool $full If true, the return value is a full record object.
* If false, just the id of the record.
* @return int|bool
*/
function get_current_group($courseid, $full = false) {
global $SESSION;
if (isset($SESSION->currentgroup[$courseid])) {
if ($full) {
return groups_get_group($SESSION->currentgroup[$courseid]);
} else {
return $SESSION->currentgroup[$courseid];
}
}
$mygroupid = mygroupid($courseid);
if (is_array($mygroupid)) {
$mygroupid = array_shift($mygroupid);
set_current_group($courseid, $mygroupid);
if ($full) {
return groups_get_group($mygroupid);
} else {
return $mygroupid;
}
}
if ($full) {
return false;
} else {
return 0;
}
}
/**
* Inndicates fatal error. This function was originally printing the
* error message directly, since 2.0 it is throwing exception instead.
* The error printing is handled in default exception handler.
*
* Old method, don't call directly in new code - use print_error instead.
*
* @param string $message The message to display to the user about the error.
* @param string $link The url where the user will be prompted to continue. If no url is provided the user will be directed to the site index page.
* @return void, always throws moodle_exception
*/
function error($message, $link='') {
throw new moodle_exception('notlocalisederrormessage', 'error', $link, $message, 'error() is a deprecated function, please call print_error() instead of error()');
}
/// Deprecated DDL functions, to be removed soon ///
/**
* @deprecated
* @global object
* @param string $table
* @return bool
*/
function table_exists($table) {
global $DB;
debugging('Deprecated ddllib function used!');
return $DB->get_manager()->table_exists($table);
}
/**
* @deprecated
* @global object
* @param string $table
* @param string $field
* @return bool
*/
function field_exists($table, $field) {
global $DB;
debugging('Deprecated ddllib function used!');
return $DB->get_manager()->field_exists($table, $field);
}
/**
* @deprecated
* @global object
* @param string $table
* @param string $index
* @return bool
*/
function find_index_name($table, $index) {
global $DB;
debugging('Deprecated ddllib function used!');
return $DB->get_manager()->find_index_name($table, $index);
}
/**
* @deprecated
* @global object
* @param string $table
* @param string $index
* @return bool
*/
function index_exists($table, $index) {
global $DB;
debugging('Deprecated ddllib function used!');
return $DB->get_manager()->index_exists($table, $index);
}
/**
* @deprecated
* @global object
* @param string $table
* @param string $field
* @return bool
*/
function find_check_constraint_name($table, $field) {
global $DB;
debugging('Deprecated ddllib function used!');
return $DB->get_manager()->find_check_constraint_name($table, $field);
}
/**
* @deprecated
* @global object
*/
function check_constraint_exists($table, $field) {
global $DB;
debugging('Deprecated ddllib function used!');
return $DB->get_manager()->check_constraint_exists($table, $field);
}
/**
* @deprecated
* @global object
* @param string $table
* @param string $xmldb_key
* @return bool
*/
function find_key_name($table, $xmldb_key) {
global $DB;
debugging('Deprecated ddllib function used!');
return $DB->get_manager()->find_key_name($table, $xmldb_key);
}
/**
* @deprecated
* @global object
* @param string $table
* @return bool
*/
function drop_table($table) {
global $DB;
debugging('Deprecated ddllib function used!');
$DB->get_manager()->drop_table($table);
return true;
}
/**
* @deprecated
* @global object
* @param string $file
* @return bool
*/
function install_from_xmldb_file($file) {
global $DB;
debugging('Deprecated ddllib function used!');
$DB->get_manager()->install_from_xmldb_file($file);
return true;
}
/**
* @deprecated
* @global object
* @param string $table
* @return bool
*/
function create_table($table) {
global $DB;
debugging('Deprecated ddllib function used!');
$DB->get_manager()->create_table($table);
return true;
}
/**
* @deprecated
* @global object
* @param string $table
* @return bool
*/
function create_temp_table($table) {
global $DB;
debugging('Deprecated ddllib function used!');
$DB->get_manager()->create_temp_table($table);
return true;
}
/**
* @deprecated
* @global object
* @param string $table
* @param string $newname
* @return bool
*/
function rename_table($table, $newname) {
global $DB;
debugging('Deprecated ddllib function used!');
$DB->get_manager()->rename_table($table, $newname);
return true;
}