-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoptions.php
401 lines (376 loc) · 13.3 KB
/
options.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
<?php
B_PROLOG_INCLUDED === true || die();
if (LANGUAGE_ID != 'ru') {
$message = new CAdminMessage('Switch language to RU');
echo $message->show();
return;
}
/**
* @var string $mid module id from GET
*/
use Bitrix\Main\Application;
use Bitrix\Main\Config\Option;
use Bitrix\Main\Context;
use Bitrix\Main\Loader;
use Bitrix\Main\Localization\Loc;
use Bitrix\Main\Page\Asset;
use Bitrix\Main\Type\DateTime;
use Intervolga\Edu\Locator\BaseLocator;
use Intervolga\Edu\Tester;
use Intervolga\Edu\Util\Help;
CJSCore::Init([
'jquery',
'date',
'popup',
]);
Loc::loadMessages(__FILE__);
global $APPLICATION, $USER;
$module_id = 'intervolga.edu';
Loader::includeModule($module_id);
$APPLICATION->setAdditionalCSS('/bitrix/css/' . $module_id . '/admin.css');
Asset::getInstance()->addJs('/bitrix/js/' . $module_id . '/admin.js');
$options = [
'general' => [
],
];
$request = Context::getCurrent()->getRequest();
if ($request->isPost()) {
if ($optionName = $request->getPost('ADD')) {
Option::set($module_id, $optionName, date('d.m.Y H:i'));
} elseif ($optionName = $request->getPost('REMOVE')) {
Option::delete($module_id, [
'name' => $optionName
]);
}
if ($fileId = $request->getPost('deleteFile')) {
$file = CFile::GetByID($fileId);
if ($file) {
try {
CFile::Delete($fileId);
} catch (Exception $exception) {
//TODO:сделать логирование от модуля?
//\Bitrix\Main\Diag\Debug::writeToFile($exception);
}
}
}
if ($commentName = $request->getPost('COMMENT')) {
if ($comment = $request->getPost($commentName . 'Comment')) {
Option::delete($module_id, [
'name' => $commentName . "Comment"
]);
Option::set($module_id, $commentName . "Comment", $comment);
}
if ($_FILES) {
foreach ($_FILES as $key => $item) {
if (strripos($key, $commentName . 'Photo') === 0 && $item['tmp_name']) {
$path = mb_strcut($key, 0, strpos($key, 'Photo'));
$temp = array_merge($item, [
'MODULE_ID' => $module_id,
'description' => $path,
]);
try {
CFile::SaveFile($temp, $module_id, false, false, $path);
Option::set($module_id, $key, $temp['PHOTO']);
} catch (Exception $e) {
//TODO:сделать логирование от модуля?
//\Bitrix\Main\Diag\Debug::writeToFile($e);
}
}
}
}
}
LocalRedirect($request->getRequestUri());
}
$fatalThrowable = null;
try {
$testsTree = Tester::getTestsTree();
Tester::run();
} catch (Throwable $throwable) {
$fatalThrowable = $throwable;
}
$errorsTree = Tester::getErrorsTree();
$stat = [];
$claimsDatetimes = Option::getForModule($module_id);
$isFemale = CUser::GetByID($USER->GetID())->fetch()['PERSONAL_GENDER'] == 'F';
foreach ($errorsTree as $courseCode => $lessonCodes) {
$stat[$courseCode]['FAILED'] = 0;
$stat[$courseCode]['DONE'] = 0;
foreach ($lessonCodes as $lessonCode => $lessonTests) {
$stat[$courseCode]['LESSONS'][$lessonCode]['ERRORS'] = 0;
foreach ($lessonTests as $testClassName => $testError) {
$newTestCode = strtolower($testsTree[$courseCode]['LESSONS'][$lessonCode]['TESTS'][$testClassName]['CODE']);
$reportId = $courseCode . "_" . $lessonCode . "_" . $newTestCode . "_problem";
if ($testError && !array_key_exists($reportId, $claimsDatetimes)) {
$stat[$courseCode]['LESSONS'][$lessonCode]['ERRORS']++;
}
if (!$testError && array_key_exists($reportId, $claimsDatetimes)) {
Option::delete($module_id, [
'name' => $reportId
]);
}
}
if ($stat[$courseCode]['LESSONS'][$lessonCode]['ERRORS']) {
$stat[$courseCode]['FAILED']++;
} else {
$stat[$courseCode]['DONE']++;
}
}
}
$tabs = [];
foreach ($testsTree as $courseCode => $course) {
$tabs[] = [
'DIV' => $courseCode,
'TAB' => Loc::getMessage('INTERVOLGA_EDU.COURSE_TAB_HEADER', [
'#NUM#' => str_replace('course', '', $courseCode),
'#DONE#' => $stat[$courseCode]['DONE'],
'#TOTAL#' => count($course['LESSONS']),
]
),
'TITLE' => Loc::getMessage('INTERVOLGA_EDU.COURSE_HEADER', [
'#COURSE#' => $course['TITLE'],
'#DONE#' => $stat[$courseCode]['DONE'],
'#TOTAL#' => count($course['LESSONS']),
]
),
'ONSELECT' => 'intervolgaEduOnTabChanged("' . $courseCode . '");',
];
}
$tabs[] = [
'DIV' => 'sniffer',
'TAB' => Loc::getMessage('INTERVOLGA_EDU.SNIFFER_TAB'),
'TITLE' => Loc::getMessage('INTERVOLGA_EDU.SNIFFER_TITLE'),
'ONSELECT' => 'intervolgaEduOnTabChanged("checker");',
];
$tabs[] = [
'DIV' => 'info',
'TAB' => Loc::getMessage('INTERVOLGA_EDU.MODULE_TAB_INFO'),
'TITLE' => Loc::getMessage('INTERVOLGA_EDU.MODULE_INFO'),
'ONSELECT' => 'intervolgaEduOnTabChanged("info");',
];
if ($fatalThrowable) {
$message = new CAdminMessage([
'MESSAGE' => Loc::getMessage('INTERVOLGA_EDU.FATAL_ERROR', ['#ERROR#' => $fatalThrowable->getMessage()]),
'DETAILS' => $fatalThrowable->getFile() . ':' . $fatalThrowable->getLine() . '<br>' . $fatalThrowable->getTraceAsString(),
]);
echo $message->show();
}
$results = CFile::GetList([], ['MODULE_ID' => $module_id]);
$photos = [];
while ($result = $results->Fetch()) {
$photos[$result['DESCRIPTION']][] = $result;
}
$tabControl = new CAdminTabControl('tabControl', $tabs);
$tabControl->begin();
$locatorsFound = Tester::getLocatorsFound();
foreach ($testsTree as $courseCode => $course) {
$tabControl->beginNextTab();
?>
<tr>
<td>
<h2 id="<?=$courseCode?>contents"><?=Loc::getMessage('INTERVOLGA_EDU.COURSE_CONTENTS')?></h2>
<ul class="lessons-contents">
<?php foreach ($course['LESSONS'] as $lessonCode => $lesson): ?>
<?php
$title = Loc::getMessage('INTERVOLGA_EDU.LESSON_HEADER', [
'#LESSON#' => $lesson['TITLE'],
'#TOTAL#' => count($lesson['TESTS']),
'#DONE#' => count($lesson['TESTS']) - intval($stat[$courseCode]['LESSONS'][$lessonCode]['ERRORS']),
]);
?>
<li>
<a href="#<?=$courseCode?><?=$lessonCode?>">
<?php if (!$stat[$courseCode]['LESSONS'][$lessonCode]['ERRORS']): ?>
<?=Loc::getMessage('INTERVOLGA_EDU.LESSON_OK')?>
<?php else: ?>
<?=Loc::getMessage('INTERVOLGA_EDU.LESSON_FAIL')?>
<?php endif ?>
<?=$lesson['TITLE']?>
</a>
</li>
<?php endforeach ?>
</ul>
<?php
$prevLessonCode = '';
$nextLessonCode = '';
$lessonCodes = array_keys($course['LESSONS']);
$currentLessonIndex = 0;
foreach ($course['LESSONS'] as $lessonCode => $lesson) {
if ($currentLessonIndex<count($lessonCodes) + 1) {
$nextLessonCode = $lessonCodes[$currentLessonIndex + 1];
}
$title = Loc::getMessage('INTERVOLGA_EDU.LESSON_HEADER', [
'#LESSON#' => $lesson['TITLE'],
'#TOTAL#' => count($lesson['TESTS']),
'#DONE#' => count($lesson['TESTS']) - intval($stat[$courseCode]['LESSONS'][$lessonCode]['ERRORS']),
]);
$help = Help::get($courseCode, $lessonCode);
?>
<h2 id="<?=$courseCode . $lessonCode?>">
<?php if (!$stat[$courseCode]['LESSONS'][$lessonCode]['ERRORS']): ?>
<?=Loc::getMessage('INTERVOLGA_EDU.LESSON_OK')?>
<?php else: ?>
<?=Loc::getMessage('INTERVOLGA_EDU.LESSON_FAIL')?>
<?php endif ?>
<?=$title?>
<span class="contents-link">
<?php if ($prevLessonCode): ?>
<a href="#<?=$courseCode?><?=$prevLessonCode?>">
<?=Loc::getMessage('INTERVOLGA_EDU.GO_BACK')?>
</a>
<?php else: ?>
<?=Loc::getMessage('INTERVOLGA_EDU.GO_BACK')?>
<?php endif ?>
<a href="#<?=$courseCode?>contents">
<?=Loc::getMessage('INTERVOLGA_EDU.GO_UP')?>
</a>
<?php if ($nextLessonCode): ?>
<a href="#<?=$courseCode?><?=$nextLessonCode?>">
<?=Loc::getMessage('INTERVOLGA_EDU.GO_FORWARD')?>
</a>
<?php else: ?>
<?=Loc::getMessage('INTERVOLGA_EDU.GO_FORWARD')?>
<?php endif ?>
</span>
</h2>
<?php if (strlen($help)): ?>
<div class="help">
<h3><?=Loc::getMessage('INTERVOLGA_EDU.LESSON_HELP')?></h3>
<div>
<?=$help?>
</div>
</div>
<?php endif ?>
<?php
$counter = 1;
foreach ($lesson['TESTS'] as $testCode => $test) {
$errors = $errorsTree[$courseCode][$lessonCode][$testCode];
$messageParams = [
'HTML' => true,
'MESSAGE' => Loc::getMessage(
'INTERVOLGA_EDU.TEST_HEADER',
[
'#NUMBER#' => $counter,
'#TEST#' => $test['TITLE'],
'#CODE#' => $test['CODE'],
]),
];
if ($test['DESCRIPTION']) {
$messageParams['DETAILS'] = '<div class="desc">' . $test['DESCRIPTION'] . '</div>';
}
if ($errors) {
$messageParams['DETAILS'] .= implode('<br>', $errors);
} else {
$messageParams['DETAILS'] .= Loc::getMessage('INTERVOLGA_EDU.TEST_NO_ERRORS');
$messageParams['TYPE'] = 'OK';
}
if ($test['INPUTS']) {
$messageParams["DETAILS"] .= '<br>';
$messageParams["DETAILS"] .= '<form method="post" enctype="multipart/form-data">';
$messageParams["DETAILS"] .= '<br>';
$formID = $courseCode . $lessonCode . $test['CODE'];
foreach ($test['INPUTS'] as $input) {
if ($input['TYPE'] === 'image') {
$photos = $photos[$formID];
foreach ($photos as $photo) {
$pathPhoto = '/upload/' . $photo['SUBDIR'] . '/' . $photo['FILE_NAME'];
$messageParams["DETAILS"] .= '<div style="display:none;" id="' . $photo['FILE_NAME'] . '_photo"> <img src="' . $pathPhoto . '"><br>';
$messageParams["DETAILS"] .= ' <a href="' . $pathPhoto . '">' . Loc::getMessage('INTERVOLGA_EDU.FOLLOW_PHOTO') . '</a></div>';
$messageParams["DETAILS"] .= '<div><a class="show-img" id="' . $photo['FILE_NAME'] . '" onclick="showPopup(this)">' . $photo['FILE_NAME'] . '</a>';
$messageParams["DETAILS"] .= '<button style="margin-left: 3px" type="submit" name="deleteFile" title="Удалить файл" class="iv-delete-link" value="' . $photo['ID'] . '"></button></div>';
}
} elseif ($input['TYPE'] === 'text-area') {
$messageParams["DETAILS"] .= '<b>' . $input['DESCRIBE'] . '</b> <br>';
$tip = Option::get($module_id, $formID . "Comment");
$messageParams["DETAILS"] .= '<textarea name="' . $formID . 'Comment" rows="5" cols="80">' . $tip . '</textarea>';
}
if ($photos) {
$messageParams["DETAILS"] .= '<br>';
}
$messageParams["DETAILS"] .= CFile::InputFile($formID . 'Photo', 20, 0, '/upload/intervolga.edu/');
}
$messageParams["DETAILS"] .= '<button type="submit" style="margin-left: 10px" class="adm-btn" name="COMMENT" value="' . $formID . '">' . Loc::getMessage('INTERVOLGA_EDU.SEND_PHOTO') . '</button>';
$messageParams["DETAILS"] .= '</form>';
$messageParams["DETAILS"] .= '<br>';
}
$reportId = $courseCode . "_" . $lessonCode . "_" . strtolower($test['CODE']) . "_problem";
if ($messageParams['TYPE'] !== 'OK') {
$messCode = 'INTERVOLGA_EDU.REPORT_MALE';
$code = 'ADD';
$buttonClass = '';
if (array_key_exists($reportId, $claimsDatetimes)) {
$buttonClass = 'adm-btn';
$messCode = 'INTERVOLGA_EDU.REMOVE_REPORT';
$code = 'REMOVE';
} else {
$buttonClass = 'adm-btn adm-btn-save';
if ($isFemale) {
$messCode = 'INTERVOLGA_EDU.REPORT_FEMALE';
}
}
$messageParams["DETAILS"] .= '<form method="post">';
$messageParams["DETAILS"] .= '<button type="submit" class="' . $buttonClass . '" name="' . $code . '" value="' . $reportId . '">' . Loc::getMessage($messCode, ["#TIME#" => $claimsDatetimes[$reportId]]) . '</button>';
$messageParams["DETAILS"] .= '</form>';
}
if ($locatorsFound[$testCode]) {
$locatorsInfo = [];
foreach ($locatorsFound[$testCode] as $parentLocator => $locatorClasses) {
foreach ($locatorClasses as $locatorClass => $founds) {
foreach ($founds as $found) {
/**
* @var BaseLocator $parentLocator
* @var BaseLocator $locatorClass
*/
$locatorsInfo [] = $locatorClass::getReport($parentLocator, $found);
}
}
}
$messageParams["DETAILS"] .= '<div class="locators-info">' . implode('<br>', $locatorsInfo) . '</div>';
}
$message = new CAdminMessage($messageParams);
echo $message->show();
$counter++;
}
$prevLessonCode = $lessonCode;
$currentLessonIndex++;
}
?>
<div class="contents-link">
<a href="#<?=$courseCode?>contents"><?=Loc::getMessage('INTERVOLGA_EDU.GO_UP')?></a>
</div>
</td>
</tr>
<?php
}
$tabControl->beginNextTab();
include Application::getDocumentRoot() . IV_EDU_MODULE_DIR . '/lib/checker/checker.php';
$tabControl->beginNextTab();
$arModuleVersion = [];
include Application::getDocumentRoot() . IV_EDU_MODULE_DIR . '/install/version.php';
$versionDate = $arModuleVersion['VERSION_DATE'];
if ($versionDate) {
$dateTime = DateTime::tryParse($versionDate, 'Y-m-d H:i:s');
if ($dateTime) {
$versionDate = $dateTime->format('d.m.Y H:i');
}
}
?>
<tr>
<td>
<div>
<a href="/bitrix/admin/intervolga.edu_help.php"> <?=Loc::getMessage('INTERVOLGA_EDU.TAKE_PRINT_VERSION') ?></a>
</div>
<div><?=Loc::getMessage('INTERVOLGA_EDU.MODULE_VERSION', [
'#VERSION#' => $arModuleVersion['VERSION'],
])?></div>
<div><?=Loc::getMessage('INTERVOLGA_EDU.MODULE_VERSION_DATE', [
'#VERSION_DATE#' => $versionDate,
])?></div>
<div><?=Loc::getMessage('INTERVOLGA_EDU.MODULE_TESTS_COUNT', [
'#COUNT#' => Tester::getTestClassesCount(),
])?></div>
</td>
</tr>
<?php
$tabControl->end();