Merge branch 'MDL-44952-30' of git://github.com/marinaglancy/moodle into MOODLE_30_STABLE
[moodle.git] / lib / uploadlib.php
blob4d746097f337a92e05ce9e4ee20b50a66642a75f
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * uploadlib.php - This class handles all aspects of fileuploading
21 * @package core
22 * @subpackage file
23 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 defined('MOODLE_INTERNAL') || die();
29 /**
30 * This class handles all aspects of fileuploading
32 * @deprecated since 2.7 - use new file pickers instead
34 * @package moodlecore
35 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38 class upload_manager {
40 /**
41 * Constructor, sets up configuration stuff so we know how to act.
43 * Note: destination not taken as parameter as some modules want to use the insertid in the path and we need to check the other stuff first.
45 * @deprecated since 2.7 - use new file pickers instead
48 function __construct($inputname='', $deleteothers=false, $handlecollisions=false, $course=null, $recoverifmultiple=false, $modbytes=0, $silent=false, $allownull=false, $allownullmultiple=true) {
49 throw new coding_exception('upload_manager class can not be used any more, please use file picker instead');
53 /**************************************************************************************
54 THESE FUNCTIONS ARE OUTSIDE THE CLASS BECAUSE THEY NEED TO BE CALLED FROM OTHER PLACES.
55 FOR EXAMPLE CLAM_HANDLE_INFECTED_FILE AND CLAM_REPLACE_INFECTED_FILE USED FROM CRON
56 UPLOAD_PRINT_FORM_FRAGMENT DOESN'T REALLY BELONG IN THE CLASS BUT CERTAINLY IN THIS FILE
57 ***************************************************************************************/
59 /**
60 * Emails admins about a clam outcome
62 * @param string $notice The body of the email to be sent.
64 function clam_message_admins($notice) {
66 $site = get_site();
68 $subject = get_string('clamemailsubject', 'moodle', format_string($site->fullname));
69 $admins = get_admins();
70 foreach ($admins as $admin) {
71 $eventdata = new stdClass();
72 $eventdata->component = 'moodle';
73 $eventdata->name = 'errors';
74 $eventdata->userfrom = get_admin();
75 $eventdata->userto = $admin;
76 $eventdata->subject = $subject;
77 $eventdata->fullmessage = $notice;
78 $eventdata->fullmessageformat = FORMAT_PLAIN;
79 $eventdata->fullmessagehtml = '';
80 $eventdata->smallmessage = '';
81 message_send($eventdata);
85 /**
86 * Returns the string equivalent of a numeric clam error code
88 * @param int $returncode The numeric error code in question.
89 * @return string The definition of the error code
91 function get_clam_error_code($returncode) {
92 $returncodes = array();
93 $returncodes[0] = 'No virus found.';
94 $returncodes[1] = 'Virus(es) found.';
95 $returncodes[2] = ' An error occured'; // specific to clamdscan
96 // all after here are specific to clamscan
97 $returncodes[40] = 'Unknown option passed.';
98 $returncodes[50] = 'Database initialization error.';
99 $returncodes[52] = 'Not supported file type.';
100 $returncodes[53] = 'Can\'t open directory.';
101 $returncodes[54] = 'Can\'t open file. (ofm)';
102 $returncodes[55] = 'Error reading file. (ofm)';
103 $returncodes[56] = 'Can\'t stat input file / directory.';
104 $returncodes[57] = 'Can\'t get absolute path name of current working directory.';
105 $returncodes[58] = 'I/O error, please check your filesystem.';
106 $returncodes[59] = 'Can\'t get information about current user from /etc/passwd.';
107 $returncodes[60] = 'Can\'t get information about user \'clamav\' (default name) from /etc/passwd.';
108 $returncodes[61] = 'Can\'t fork.';
109 $returncodes[63] = 'Can\'t create temporary files/directories (check permissions).';
110 $returncodes[64] = 'Can\'t write to temporary directory (please specify another one).';
111 $returncodes[70] = 'Can\'t allocate and clear memory (calloc).';
112 $returncodes[71] = 'Can\'t allocate memory (malloc).';
113 if ($returncodes[$returncode])
114 return $returncodes[$returncode];
115 return get_string('clamunknownerror');