37
37
);
38
38
} else {
39
39
$ errors = import_pdfs ($ subDir );
40
- if (count ($ errors ) == 0 ) {
41
- error_log ('Course intros imported successfully in ' .__FILE__ .', line ' .__LINE__ );
42
- }
43
40
}
44
41
}
45
42
}
46
43
47
- if (count ($ errors ) != 0 ) {
44
+ if (! empty ($ errors )) {
48
45
$ error_message = '<ul> ' ;
49
46
foreach ($ errors as $ index => $ error_course ) {
50
47
$ error_message .= '<li> ' .get_lang ('Course ' ).': ' .$ error_course ['Title ' ].' ( ' .$ error_course ['Code ' ].')</li> ' ;
51
48
}
52
49
$ error_message .= '</ul> ' ;
53
50
Display::addFlash (Display::return_message ($ error_message , 'normal ' , false ));
54
- } elseif (isset ($ _POST ['formSent ' ])) {
55
- Display::addFlash (
56
- Display::return_message (
57
- get_lang ('CourseIntroductionsAllImportedSuccessfully ' ),
58
- 'confirmation ' ,
59
- false
60
- )
61
- );
62
51
}
63
52
64
53
Display::display_header ($ tool_name );
101
90
*
102
91
* @param string $subDir The subdirectory in which to put the files in each course
103
92
*
104
- * @return array List of possible errors found
93
+ * @return bool| array List of possible errors found
105
94
*/
106
95
function import_pdfs ($ subDir = '/ ' )
107
96
{
@@ -112,9 +101,7 @@ function import_pdfs($subDir = '/')
112
101
@mkdir ($ baseDir .$ uploadPath );
113
102
}
114
103
if (!unzip_uploaded_file ($ _FILES ['import_file ' ], $ uploadPath , $ baseDir , 1024 * 1024 * 1024 )) {
115
- error_log ('Could not unzip uploaded file in ' .__FILE__ .', line ' .__LINE__ );
116
-
117
- return $ errors ;
104
+ return false ;
118
105
}
119
106
$ list = scandir ($ baseDir .$ uploadPath );
120
107
$ i = 0 ;
@@ -174,7 +161,6 @@ function import_pdfs($subDir = '/')
174
161
$ course_description ->insert ();
175
162
}
176
163
} else {
177
- error_log ($ parts [0 ].' is not a course, apparently ' );
178
164
$ errors [] = ['Line ' => 0 , 'Code ' => $ parts [0 ], 'Title ' => $ parts [0 ].' - ' .get_lang ('CodeDoesNotExists ' )];
179
165
}
180
166
$ i ++; //found at least one entry that is not a dir or a .
@@ -183,5 +169,15 @@ function import_pdfs($subDir = '/')
183
169
$ errors [] = ['Line ' => 0 , 'Code ' => '. ' , 'Title ' => get_lang ('NoPDFFoundAtRoot ' )];
184
170
}
185
171
172
+ if (empty ($ errors )) {
173
+ Display::addFlash (
174
+ Display::return_message (
175
+ get_lang ('CourseIntroductionsAllImportedSuccessfully ' ),
176
+ 'confirmation ' ,
177
+ false
178
+ )
179
+ );
180
+ }
181
+
186
182
return $ errors ;
187
183
}
0 commit comments