PageRenderTime 62ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/modules/learning/admin/learn_question_edit.php

https://gitlab.com/alexprowars/bitrix
PHP | 1246 lines | 1108 code | 122 blank | 16 comment | 202 complexity | 9dc4bdfe1ae42c9ea74ae0e0a99f19e6 MD5 | raw file
  1. <?
  2. require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_admin_before.php");
  3. if (!CModule::IncludeModule('learning'))
  4. {
  5. require($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/prolog_admin_after.php'); // second system's prolog
  6. if (IsModuleInstalled('learning') && defined('LEARNING_FAILED_TO_LOAD_REASON'))
  7. echo LEARNING_FAILED_TO_LOAD_REASON;
  8. else
  9. CAdminMessage::ShowMessage(GetMessage('LEARNING_MODULE_NOT_FOUND'));
  10. require($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/epilog_admin.php'); // system's epilog
  11. exit();
  12. }
  13. require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/learning/prolog.php");
  14. IncludeModuleLangFile(__FILE__);
  15. ClearVars();
  16. $strWarning = "";
  17. $message = null;
  18. $bVarsFromForm = false;
  19. $ID = intval($ID);
  20. $filter_lesson_id = intval($filter_lesson_id);
  21. $lessonPath = '';
  22. if (isset($_POST['LESSON_PATH']))
  23. $lessonPath = $_POST['LESSON_PATH'];
  24. elseif (isset($_GET['LESSON_PATH']))
  25. $lessonPath = $_GET['LESSON_PATH'];
  26. else
  27. {
  28. $result = CLQuestion::GetByID($ID);
  29. $arData = $result->Fetch();
  30. $oPath = new CLearnPath($arData['LESSON_ID']);
  31. $lessonPath = $oPath->ExportUrlencoded();
  32. }
  33. $oPath = new CLearnPath();
  34. $oPath->ImportUrlencoded($lessonPath);
  35. $uriLessonPath = $oPath->ExportUrlencoded();
  36. $NEW_LESSON_ID = false;
  37. $LESSON_ID = false;
  38. if ($ID == 0)
  39. {
  40. $LESSON_ID = $oPath->PopBottom();
  41. }
  42. else
  43. {
  44. // Get lesson id from item data
  45. $result = CLQuestion::GetByID($ID);
  46. $arQuestionData = $result->ExtractFields("str_");
  47. if ($arQuestionData)
  48. {
  49. $LESSON_ID = $arQuestionData['LESSON_ID'];
  50. if (isset($_POST['LESSON_ID']) && ($_POST['LESSON_ID'] >= 1) && ($_POST['LESSON_ID'] != $LESSON_ID))
  51. $NEW_LESSON_ID = (int) $_POST['LESSON_ID'];
  52. }
  53. }
  54. if ($LESSON_ID === false)
  55. {
  56. require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_admin_after.php");
  57. CAdminMessage::ShowMessage(GetMessage('LEARNING_BAD_LESSON'));
  58. require($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/epilog_admin.php');
  59. exit();
  60. }
  61. $uriParentLessonPath = $oPath->ExportUrlencoded();
  62. unset ($lessonPath);
  63. $oAccess = CLearnAccess::GetInstance($USER->GetID());
  64. if ($oAccess->IsLessonAccessible ($LESSON_ID, CLearnAccess::OP_LESSON_WRITE))
  65. $bBadCourse = false;
  66. else
  67. $bBadCourse = true;
  68. if ($NEW_LESSON_ID !== false)
  69. {
  70. if ($oAccess->IsLessonAccessible ($NEW_LESSON_ID, CLearnAccess::OP_LESSON_WRITE))
  71. $bBadCourse = false;
  72. else
  73. $bBadCourse = true;
  74. }
  75. $aTabs = array(
  76. array("DIV" => "edit1", "TAB" => GetMessage("LEARNING_ADMIN_TAB1"), "ICON"=>"main_user_edit", "TITLE"=>GetMessage("LEARNING_ADMIN_TAB1_EX")),
  77. array("DIV" => "edit2", "TAB" => GetMessage("LEARNING_ADMIN_TAB2"), "ICON"=>"main_user_edit", "TITLE"=>GetMessage("LEARNING_ADMIN_TAB2_EX")),
  78. array("DIV" => "edit3", "TAB" => GetMessage("LEARNING_ADMIN_TAB3"), "ICON"=>"main_user_edit", "TITLE"=>GetMessage("LEARNING_ADMIN_TAB3_EX")),
  79. );
  80. $aTabs[] = $USER_FIELD_MANAGER->EditFormTab('LEARNING_QUESTIONS');
  81. $tabControl = new CAdminForm("questionTabControl", $aTabs);
  82. if (!$bBadCourse && $_SERVER["REQUEST_METHOD"] == "POST" && $Update <> '' && check_bitrix_sessid())
  83. {
  84. $arFILE_ID = $_FILES["FILE_ID"];
  85. $arFILE_ID["del"] = ${"FILE_ID_del"};
  86. $arFILE_ID["MODULE_ID"] = "learning";
  87. $arFILE_ID["description"] = ${"FILE_ID_descr"};
  88. if ($NEW_LESSON_ID !== false)
  89. $LESSON_ID = $NEW_LESSON_ID;
  90. $cq = new CLQuestion;
  91. $arFields = array(
  92. "LESSON_ID" => $LESSON_ID,
  93. "NAME" => $NAME,
  94. "QUESTION_TYPE" => $QUESTION_TYPE,
  95. "SORT" => $SORT,
  96. "SELF" => $SELF,
  97. "ACTIVE" => $ACTIVE,
  98. "CORRECT_REQUIRED" => $CORRECT_REQUIRED,
  99. "POINT" => $POINT,
  100. "FILE_ID" => $arFILE_ID,
  101. "DESCRIPTION" => $DESCRIPTION,
  102. "DESCRIPTION_TYPE" => $DESCRIPTION_TYPE,
  103. "INCORRECT_MESSAGE" => $INCORRECT_MESSAGE,
  104. "COMMENT_TEXT" => $COMMENT_TEXT,
  105. "EMAIL_ANSWER" => $EMAIL_ANSWER,
  106. "~TIMESTAMP_X" => $DB->CurrentTimeFunction()
  107. );
  108. $USER_FIELD_MANAGER->EditFormAddFields('LEARNING_QUESTIONS', $arFields);
  109. if($ID>0)
  110. {
  111. $res = $cq->Update($ID, $arFields);
  112. }
  113. else
  114. {
  115. // check, that default answer selected
  116. if ( ($QUESTION_TYPE === 'S') && (!isset($_POST['ANSWER_CORRECT'])) )
  117. {
  118. $res = false;
  119. $message = new CAdminMessage(array(
  120. 'MESSAGE' => GetMessage("LEARNING_ERROR"),
  121. 'TYPE' => 'ERROR',
  122. 'DETAILS' => GetMessage('LEARNING_ADD_RIGHT_ANSWER_NOT_SELECTED'),
  123. 'HTML' => false
  124. ));
  125. }
  126. else
  127. {
  128. $ID = $cq->Add($arFields);
  129. $res = ($ID>0);
  130. }
  131. }
  132. if(!$res)
  133. {
  134. if ($e = $APPLICATION->GetException())
  135. $message = new CAdminMessage(GetMessage("LEARNING_ERROR"), $e);
  136. $bVarsFromForm = true;
  137. }
  138. else
  139. {
  140. if ($QUESTION_TYPE != "T")
  141. {
  142. //Answers
  143. $answers = CLAnswer::GetList(Array(),Array("QUESTION_ID" => $ID));
  144. while ($a = $answers->GetNext())
  145. {
  146. //delete?
  147. if (${"ANSWER_".$a["ID"]."_DEL"} == "Y")
  148. {
  149. if(!CLAnswer::Delete($a["ID"]))
  150. {
  151. $message = new CAdminMessage(Array("MESSAGE" => GetMessage("LEARNING_DELETE_ERROR")));
  152. $bVarsFromForm = true;
  153. }
  154. }
  155. else
  156. {
  157. $arFields = Array(
  158. "QUESTION_ID" => $ID,
  159. "SORT" => ${"ANSWER_".$a["ID"]."_SORT"},
  160. "ANSWER" => ${"ANSWER_".$a["ID"]."_ANSWER"},
  161. );
  162. switch ($QUESTION_TYPE)
  163. {
  164. case "M":
  165. $arFields["CORRECT"] = (${"ANSWER_".$a["ID"]."_CORRECT"} == "Y" ? "Y" : "N");
  166. break;
  167. case "S":
  168. default:
  169. $arFields["CORRECT"] = ($a["ID"] == $ANSWER_CORRECT ? "Y" : "N");
  170. }
  171. $asw = new CLAnswer;
  172. $res = $asw->Update($a["ID"], $arFields);
  173. if (!$res)
  174. {
  175. $message = new CAdminMessage(Array("MESSAGE" => GetMessage("LEARNING_SAVE_ERROR").$a["ID"]));
  176. $bVarsFromForm = true;
  177. }
  178. }
  179. }
  180. //add new
  181. for ($i=0; $i<500; $i++)
  182. {
  183. if (${"ANSWER_n".$i."_ANSWER"} == '') continue;
  184. $arFields = Array(
  185. "SORT" => ${"ANSWER_n".$i."_SORT"},
  186. "ANSWER" => ${"ANSWER_n".$i."_ANSWER"},
  187. "QUESTION_ID" => $ID,
  188. );
  189. switch ($QUESTION_TYPE)
  190. {
  191. case "M":
  192. $arFields["CORRECT"] = (${"ANSWER_n".$i."_CORRECT"} == "Y" ? "Y" : "N");
  193. break;
  194. case "S":
  195. default:
  196. $arFields["CORRECT"] = ("n".$i == $ANSWER_CORRECT ? "Y" : "N");
  197. }
  198. $asw = new CLAnswer;
  199. $AswerID = $asw->Add($arFields);
  200. if (intval($AswerID)<=0)
  201. {
  202. if ($e = $APPLICATION->GetException())
  203. $message = new CAdminMessage(GetMessage("LEARNING_ERROR"), $e);
  204. $bVarsFromForm = true;
  205. }
  206. }
  207. }
  208. else
  209. {
  210. //Delete answers
  211. $answers = CLAnswer::GetList(Array(),Array("QUESTION_ID" => $ID));
  212. while ($a = $answers->GetNext())
  213. {
  214. CLAnswer::Delete($a["ID"]);
  215. }
  216. }
  217. //Redirect
  218. if (!$bVarsFromForm)
  219. {
  220. if($apply == '')
  221. {
  222. if ($from == "learn_admin")
  223. {
  224. LocalRedirect("/bitrix/admin/learn_unilesson_admin.php?lang=" . LANG
  225. . '&LESSON_PATH=' . $uriParentLessonPath
  226. . GetFilterParams("filter_", false)
  227. . "&from=learn_admin");
  228. }
  229. elseif ($from == "learn_menu")
  230. {
  231. LocalRedirect("/bitrix/admin/learn_question_admin.php?lang=" . LANG
  232. . '&LESSON_PATH=' . $uriLessonPath
  233. . GetFilterParams("filter_", false)
  234. . "&from=learn_menu");
  235. }
  236. elseif ($return_url <> '')
  237. LocalRedirect($return_url);
  238. else
  239. {
  240. LocalRedirect("/bitrix/admin/learn_question_admin.php?lang=" . LANG
  241. . '&LESSON_PATH=' . $uriLessonPath
  242. . GetFilterParams("filter_", false));
  243. }
  244. }
  245. LocalRedirect("/bitrix/admin/learn_question_edit.php?lang=" . LANG
  246. . '&LESSON_PATH=' . $uriLessonPath
  247. . "&ID=" . $ID
  248. . "&" . $tabControl->ActiveTabParam()
  249. . GetFilterParams("filter_", false)
  250. . ($from == "learn_admin" ? "&from=learn_admin" :""));
  251. }
  252. }
  253. }
  254. //Defaults
  255. $str_SELF = "N";
  256. $str_ACTIVE = "Y";
  257. $str_CORRECT_REQUIRED = "N";
  258. $str_COMMENT_TEXT = '';
  259. $str_DIRECTION = "V";
  260. $str_DESCRIPTION_TYPE= "text";
  261. $str_SORT = "500";
  262. $str_QUESTION_TYPE = "S";
  263. $str_POINT = 10;
  264. $str_EMAIL_ANSWER = "N";
  265. $result = CLQuestion::GetByID($ID);
  266. if(!$result->ExtractFields("str_"))
  267. $ID = 0;
  268. if($bVarsFromForm)
  269. {
  270. $ACTIVE = ($ACTIVE != "Y"? "N":"Y");
  271. $DB->InitTableVarsForEdit("b_learn_question", "", "str_");
  272. $str_FILE_ID = 0;
  273. }
  274. if (isset($QUESTION_TYPE) && mb_strlen($QUESTION_TYPE) === 1)
  275. {
  276. $str_QUESTION_TYPE = $QUESTION_TYPE;
  277. }
  278. if ($ID > 0)
  279. $APPLICATION->SetTitle(GetMessage("LEARNING_QUESTION").": ".GetMessage("LEARNING_EDIT_TITLE"));
  280. else
  281. $APPLICATION->SetTitle(GetMessage('LEARNING_QUESTION').": ".GetMessage("LEARNING_NEW_TITLE"));
  282. require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_admin_after.php");
  283. $aContext = array(
  284. array(
  285. "ICON" => "btn_list",
  286. "TEXT" => GetMessage("MAIN_ADMIN_MENU_LIST"),
  287. "LINK" => "learn_question_admin.php?lang=" . LANG
  288. . '&LESSON_PATH=' . $uriLessonPath
  289. . GetFilterParams("filter_"),
  290. "TITLE" => GetMessage("LEARNING_QUESTION_LIST")
  291. ),
  292. );
  293. if (!$bBadCourse):
  294. if ($ID > 0)
  295. {
  296. $arContextPopup = Array(
  297. Array(
  298. "TEXT" => GetMessage('LEARNING_SINGLE_CHOICE'),
  299. "ACTION" => "window.location='learn_question_edit.php?lang=" . LANG
  300. . '&LESSON_PATH=' . $uriLessonPath
  301. . GetFilterParams("filter_", false)
  302. . "&QUESTION_TYPE=S"
  303. . ($from=="learn_admin"?"&from=learn_admin":"")
  304. . "'",
  305. ),
  306. Array(
  307. "TEXT" => GetMessage('LEARNING_MULTIPLE_CHOICE'),
  308. "ACTION" => "window.location='learn_question_edit.php?lang=" . LANG
  309. . '&LESSON_PATH=' . $uriLessonPath
  310. . GetFilterParams("filter_", false)
  311. . "&QUESTION_TYPE=M"
  312. . ($from=="learn_admin"?"&from=learn_admin":"")
  313. . "'",
  314. ),
  315. Array(
  316. "TEXT" => GetMessage('LEARNING_SORTING'),
  317. "ACTION" => "window.location='learn_question_edit.php?lang=" . LANG
  318. . '&LESSON_PATH=' . $uriLessonPath
  319. . GetFilterParams("filter_", false)
  320. . "&QUESTION_TYPE=R"
  321. . ($from=="learn_admin"?"&from=learn_admin":"")
  322. . "'",
  323. ),
  324. Array(
  325. "TEXT" => GetMessage('LEARNING_TEXT_ANSWER'),
  326. "ACTION" => "window.location='learn_question_edit.php?lang=" . LANG
  327. . '&LESSON_PATH=' . $uriLessonPath
  328. . GetFilterParams("filter_", false)
  329. . "&QUESTION_TYPE=T"
  330. . ($from=="learn_admin"?"&from=learn_admin":"")
  331. . "'",
  332. ),
  333. );
  334. $aContext[] = array(
  335. "ICON" => "btn_new",
  336. "TEXT"=>GetMessage("MAIN_ADMIN_MENU_CREATE"),
  337. "MENU" => $arContextPopup,
  338. "TITLE"=>GetMessage("LEARNING_ADD")
  339. );
  340. $aContext[] = array(
  341. "ICON" => "btn_delete",
  342. "TEXT" => GetMessage("MAIN_ADMIN_MENU_DELETE"),
  343. "LINK" => "javascript:if(confirm('" . GetMessage("LEARNING_CONFIRM_DEL_MESSAGE")
  344. . "'))window.location='learn_question_admin.php?lang=" . LANG
  345. . '&LESSON_PATH=' . $uriLessonPath
  346. . "&action=delete&ID=" . $ID
  347. . "&" . bitrix_sessid_get()
  348. . urlencode(GetFilterParams("filter_", false))
  349. . "';",
  350. );
  351. }
  352. $context = new CAdminContextMenu($aContext);
  353. $context->Show();
  354. if ($message)
  355. echo $message->Show();
  356. ?>
  357. <?
  358. CAdminFileDialog::ShowScript(Array(
  359. "event" => "OpenFileBrowserWindMedia",
  360. "arResultDest" => Array("FUNCTION_NAME" => "SetUrl"),
  361. "arPath" => Array("SITE" => $_GET["site"], "PATH" =>($str_FILENAME <> '' ? GetDirPath($str_FILENAME) : '')),
  362. "select" => 'F',// F - file only, D - folder only,
  363. "operation" => 'O',// O - open, S - save
  364. "showUploadTab" => true,
  365. "showAddToMenuTab" => false,
  366. "fileFilter" => 'wmv,flv,mp4,wma,mp3',//'' - don't shjow select, 'image' - only images; "ext1,ext2" - Only files with ext1 and ext2 extentions;
  367. "allowAllFiles" => true,
  368. "SaveConfig" => true
  369. ));
  370. ?>
  371. <?php
  372. function CustomizeEditor()
  373. {
  374. ob_start()?>
  375. <div class="bxed-dialog">
  376. <table class="bx-image-dialog-tbl">
  377. <tr>
  378. <td class="bx-par-title"><?echo GetMessage("LEARNING_PATH_TO_FILE")?>:</td>
  379. <td class="bx-par-val" colspan="3">
  380. <input type="text" size="30" id="mediaPath" />
  381. <input type="button" value="..." id="OpenFileBrowserWindMedia_button">
  382. </td>
  383. </tr>
  384. <tr>
  385. <td class="bx-par-title"><?echo GetMessage("LEARNING_WIDTH")?>:</td>
  386. <td width="80px"><input type="text" size="3" id="mediaWidth" /></td>
  387. <td><?echo GetMessage("LEARNING_HEIGHT")?>:</td>
  388. <td class="bx-par-val"><input type="text" size="3" id="mediaHeight" /></td>
  389. </tr>
  390. </table>
  391. </div>
  392. <?php $dialogHTML = ob_get_clean()?>
  393. <script type="text/javascript">
  394. var pEditor;
  395. var pElement;
  396. function SetUrl(filename, path, site)
  397. {
  398. if (path.substr(-1) == "/")
  399. {
  400. path = path.substr(0, path.length - 1);
  401. }
  402. var url = path+'/'+filename;
  403. BX("mediaPath").value = url;
  404. if(BX("mediaPath").onchange)
  405. BX("mediaPath").onchange();
  406. }
  407. function _mediaParser(_str, pMainObj)
  408. {
  409. // **** Parse WMV ****
  410. // b1, b3 - quotes
  411. // b2 - id of the div
  412. // b4 - javascript config
  413. var ReplaceWMV = function(str, b1, b2, b3, b4)
  414. {
  415. var
  416. id = b2,
  417. JSConfig, w, h, prPath;
  418. try {eval('JSConfig = ' + b4); } catch (e) { JSConfig = false; }
  419. if (!id || !JSConfig)
  420. return '';
  421. var w = (parseInt(JSConfig.width) || 50);
  422. var h = (parseInt(JSConfig.height) || 25);
  423. var arTagParams = {file: JSConfig.file};
  424. var bxTag = pMainObj.GetBxTag(id);
  425. if (bxTag && bxTag && bxTag.tag == "media")
  426. {
  427. arTagParams.id = id;
  428. }
  429. return '<img id="' + pMainObj.SetBxTag(false, {tag: 'media', params: arTagParams}) + '" src="/bitrix/images/1.gif" style="border: 1px solid rgb(182, 182, 184); background-color: rgb(226, 223, 218); background-image: url(/bitrix/images/learning/icons/media.gif); background-position: center center; background-repeat: no-repeat; width: '+w+'px; height: '+h+'px;" width="'+w+'" height="'+h+'" />';
  430. }
  431. _str = _str.replace(/<script.*?silverlight\.js.*?<\/script>\s*?<script.*?wmvplayer\.js.*?<\/script>\s*?<div.*?id\s*?=\s*?("|\')(.*?)\1.*?<\/div>\s*?<script.*?jeroenwijering\.Player\(document\.getElementById\(("|\')\2\3.*?wmvplayer\.xaml.*?({.*?})\).*?<\/script>/ig, ReplaceWMV);
  432. // **** Parse FLV ****
  433. var ReplaceFLV = function(str, attr)
  434. {
  435. attr = attr.replace(/[\r\n]+/ig, ' '); attr = attr.replace(/\s+/ig, ' '); attr = jsUtils.trim(attr);
  436. var
  437. arParams = {},
  438. arFlashvars = {},
  439. w, h, id, prPath;
  440. attr.replace(/([^\w]??)(\w+?)\s*=\s*("|\')([^\3]+?)\3/ig, function(s, b0, b1, b2, b3)
  441. {
  442. b1 = b1.toLowerCase();
  443. if (b1 == 'src' || b1 == 'type' || b1 == 'allowscriptaccess' || b1 == 'allowfullscreen' || b1 == 'pluginspage' || b1 == 'wmode')
  444. return '';
  445. arParams[b1] = b3; return b0;
  446. });
  447. id = arParams.id;
  448. if (!id || !arParams.flashvars)
  449. return str;
  450. arParams.flashvars.replace(/(\w+?)=((?:\s|\S)*?)&/ig, function(s, name, val) { arFlashvars[name] = val; return ''; });
  451. var w = (parseInt(arParams.width) || 50);
  452. var h = (parseInt(arParams.height) || 25);
  453. var arTagParams = {file: arFlashvars["file"]};
  454. var bxTag = pMainObj.GetBxTag(id);
  455. if (bxTag && bxTag && bxTag.tag == "media")
  456. {
  457. arTagParams.id = id;
  458. }
  459. return '<img id="' + pMainObj.SetBxTag(false, {tag: 'media', params: arTagParams}) + '" src="/bitrix/images/1.gif" style="border: 1px solid rgb(182, 182, 184); background-color: rgb(226, 223, 218); background-image: url(/bitrix/images/learning/icons/media.gif); background-position: center center; background-repeat: no-repeat; width: '+w+'px; height: '+h+'px;" width="'+w+'" height="'+h+'" />';
  460. }
  461. _str = _str.replace(/<object.*?>.*?<embed((?:\s|\S)*?player\/mediaplayer\/player\.swf(?:\s|\S)*?)(?:>\s*?<\/embed)?(?:\/?)?>.*?<\/object>/ig, ReplaceFLV);
  462. return _str;
  463. }
  464. arContentParsers.unshift(_mediaParser);
  465. function _mediaUnParser(_node, pMainObj)
  466. {
  467. bxTag = pMainObj.GetBxTag(_node.arAttributes["id"]);
  468. if (bxTag && bxTag.tag && bxTag.tag == "media")
  469. {
  470. var ext = bxTag.params.file.substr(bxTag.params.file.length - 3);
  471. var bWM = ext == "wmv" || ext == "wma";
  472. if (!bWM) // FL
  473. {
  474. var str = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" ';
  475. str += 'id="' + _node.arAttributes["id"] + '" ';
  476. str += 'width="' + _node.arAttributes["width"] + '" ';
  477. str += 'height="' + _node.arAttributes["height"] + '" ';
  478. str += '>';
  479. str += '<param name="movie" value="/bitrix/components/bitrix/player/mediaplayer/player">';
  480. var embed = '<embed src="/bitrix/components/bitrix/player/mediaplayer/player" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" pluginspage="http:/' + '/www.macromedia.com/go/getflashplayer" ';
  481. embed += 'id="' + _node.arAttributes["id"] + '" ';
  482. var arParams = {
  483. "menu": "true",
  484. "wmode": "transparent",
  485. "width": _node.arAttributes["width"],
  486. "height": _node.arAttributes["height"],
  487. "flashvars" : {
  488. "file" : bxTag.params.file,
  489. "logo.hide" : "true",
  490. "skin": "/bitrix/components/bitrix/player/mediaplayer/skins/bitrix.swf",
  491. "repeat" : "N",
  492. "bufferlength" : "10",
  493. "dock" : "true"
  494. }
  495. }
  496. for (i in arParams)
  497. {
  498. if (i == 'flashvars')
  499. {
  500. embed += 'flashvars="';
  501. str += '<param name="flashvars" value="';
  502. for (k in arParams[i])
  503. {
  504. embed += k + '=' + arParams[i][k] + '&';
  505. str += k + '=' + arParams[i][k] + '&';
  506. }
  507. embed = embed.substring(0, embed.length - 1) + '" ';
  508. str = str.substring(0, str.length - 1) + '">';
  509. }
  510. else
  511. {
  512. embed += i + '="' + arParams[i] + '" ';
  513. str += '<param name="' + i +'" value="' + arParams[i] +'">';
  514. }
  515. }
  516. embed += '/>';
  517. str += embed +'</object>';
  518. }
  519. else // WM
  520. {
  521. str = '<script type="text/javascript" src="/bitrix/components/bitrix/player/wmvplayer/silverlight.js" /><\/script>' +
  522. '<script type="text/javascript" src="/bitrix/components/bitrix/player/wmvplayer/wmvplayer.js"><\/script>' +
  523. '<div id="' + _node.arAttributes["id"] + '">WMV Player</div>' +
  524. '<script type="text/javascript">new jeroenwijering.Player(document.getElementById("' + _node.arAttributes["id"] + '"), "/bitrix/components/bitrix/player/wmvplayer/wmvplayer.xaml", {';
  525. var arParams = {
  526. "file" : bxTag.params.file,
  527. "bufferlength" : "10",
  528. "width": _node.arAttributes["width"],
  529. "height": _node.arAttributes["height"],
  530. "windowless": "true"
  531. }
  532. for (i in arParams)
  533. str += i + ': "' + arParams[i] + '", ';
  534. str = str.substring(0, str.length - 2);
  535. str += '});<\/script>';
  536. }
  537. return str;
  538. }
  539. return false;
  540. }
  541. oBXEditorUtils.addUnParser(_mediaUnParser);
  542. var pSaveButton = new BX.CWindowButton({
  543. 'title': '<?echo GetMessage("LEARNING_SAVE")?>',
  544. 'action': function() {
  545. var path = BX('mediaPath').value;
  546. var width = BX('mediaWidth').value;
  547. var height = BX('mediaHeight').value;
  548. this.parentWindow.Close();
  549. if (path.length > 0 && parseInt(width) > 0 && parseInt(height) > 0)
  550. {
  551. if (pElement && pElement.getAttribute && pElement.getAttribute("id"))
  552. {
  553. var bxTag = pEditor.GetBxTag(pElement.getAttribute("id"))
  554. if (bxTag && bxTag.tag && bxTag.tag == "media")
  555. {
  556. bxTag.params.file = path;
  557. SAttr(pElement, "width", width);
  558. SAttr(pElement, "height", height);
  559. pElement.style.width = width + "px";
  560. pElement.style.height = height + "px";
  561. }
  562. }
  563. else
  564. {
  565. var arParams = {file: path};
  566. pEditor.insertHTML('<img id="' + pEditor.SetBxTag(false, {tag: 'media', params: arParams}) + '" src="/bitrix/images/1.gif" style="border: 1px solid rgb(182, 182, 184); background-color: rgb(226, 223, 218); background-image: url(/bitrix/images/learning/icons/media.gif); background-position: center center; background-repeat: no-repeat; width: '+width+'px; height: '+height+'px;" width="'+width+'" height="'+height+'" />');
  567. }
  568. }
  569. pElement = null;
  570. }
  571. });
  572. var pDialog = new BX.CDialog({
  573. title : '<?echo GetMessage("LEARNING_VIDEO_AUDIO")?>',
  574. content: '<?php echo CUtil::JSEscape(preg_replace("~>\s+<~", "><", trim($dialogHTML)))?>',
  575. height: 180,
  576. width: 520,
  577. resizable: false,
  578. buttons: [pSaveButton, BX.CDialog.btnClose]
  579. });
  580. var pMediaButton = [
  581. 'BXButton',
  582. {
  583. id : 'media',
  584. src : '/bitrix/images/learning/icons/media.gif',
  585. name : "<?echo GetMessage("LEARNING_VIDEO_AUDIO")?>",
  586. handler : function () {
  587. pDialog.Show();
  588. pEditor = this.pMainObj;
  589. BX("OpenFileBrowserWindMedia_button").onclick = OpenFileBrowserWindMedia;
  590. pElement = pEditor.GetSelectionObject();
  591. if (pElement && pElement.getAttribute && pElement.getAttribute("id"))
  592. {
  593. var bxTag = pEditor.GetBxTag(pElement.getAttribute("id"))
  594. if (bxTag && bxTag.tag && bxTag.tag == "media")
  595. {
  596. BX('mediaPath').value = bxTag.params.file;
  597. BX('mediaWidth').value = pElement.getAttribute("width");
  598. BX('mediaHeight').value = pElement.getAttribute("height");
  599. }
  600. }
  601. else
  602. {
  603. BX('mediaPath').value = "";
  604. BX('mediaWidth').value = "400";
  605. BX('mediaHeight').value = "300";
  606. }
  607. }
  608. }
  609. ];
  610. if (window.lightMode)
  611. {
  612. for(var i = 0, l = arGlobalToolbar.length; i < l ; i++)
  613. {
  614. var arButton = arGlobalToolbar[i];
  615. if (arButton[1] && arButton[1].id == "insert_flash" && arGlobalToolbar[i+1][1].id != "media") {
  616. arGlobalToolbar.splice(i + 1, 0, pMediaButton);
  617. break;
  618. }
  619. }
  620. }
  621. else
  622. {
  623. oBXEditorUtils.appendButton("insert_media", pMediaButton, "standart");
  624. }
  625. </script>
  626. <?php }?>
  627. <?php AddEventHandler("fileman", "OnIncludeHTMLEditorScript", "CustomizeEditor"); ?>
  628. <?php $tabControl->BeginEpilogContent();?>
  629. <?=bitrix_sessid_post()?>
  630. <?echo GetFilterHiddens("filter_");?>
  631. <input type="hidden" name="Update" value="Y">
  632. <input type="hidden" name="from" value="<?echo htmlspecialcharsbx($from)?>">
  633. <input type="hidden" name="return_url" value="<?echo htmlspecialcharsbx($return_url)?>">
  634. <input type="hidden" name="ID" value="<?echo $ID?>">
  635. <input type="hidden" name="LESSON_PATH" value="<?php echo htmlspecialcharsbx(urldecode($uriLessonPath)); ?>">
  636. <?php $tabControl->EndEpilogContent();?>
  637. <?$tabControl->Begin();?>
  638. <?$tabControl->BeginNextFormTab();?>
  639. <!-- ID -->
  640. <?php $tabControl->BeginCustomField("ID", "ID", false);?>
  641. <?if($ID>0):?>
  642. <tr>
  643. <td><?echo $tabControl->GetCustomLabelHTML()?>:</td>
  644. <td><?=$str_ID?></td>
  645. </tr>
  646. <? endif; ?>
  647. <?php $tabControl->EndCustomField("ID");?>
  648. <!-- Timestamp_X -->
  649. <?php $tabControl->BeginCustomField("TIMESTAMP_X", GetMessage("LEARNING_LAST_UPDATE"), false);?>
  650. <?if($ID>0):?>
  651. <tr>
  652. <td><?echo $tabControl->GetCustomLabelHTML()?>:</td>
  653. <td><?=$str_TIMESTAMP_X?></td>
  654. </tr>
  655. <? endif; ?>
  656. <?php $tabControl->EndCustomField("TIMESTAMP_X");?>
  657. <?php $tabControl->BeginCustomField("ACTIVE", GetMessage("LEARNING_ACTIVE"), false);?>
  658. <!-- Active -->
  659. <tr>
  660. <td><?echo $tabControl->GetCustomLabelHTML()?>:</td>
  661. <td><input type="checkbox" name="ACTIVE" value="Y"<?if($str_ACTIVE=="Y")echo " checked"?>></td>
  662. </tr>
  663. <?php $tabControl->EndCustomField("ACTIVE");?>
  664. <?php $tabControl->BeginCustomField("QUESTION_TYPE", GetMessage("LEARNING_QUESTION_TYPE"), false);?>
  665. <tr>
  666. <td width="40%"><?echo $tabControl->GetCustomLabelHTML()?>:</td>
  667. <td width="60%">
  668. <select onchange="if(this[this.selectedIndex].value!='') window.location=this[this.selectedIndex].value;"<?php echo (defined('BX_PUBLIC_MODE') && BX_PUBLIC_MODE == 1 ? "disabled=\"disabled\"" : "")?>>
  669. <option value="<?=$APPLICATION->GetCurPageParam("QUESTION_TYPE=S", array("QUESTION_TYPE","tabControl_active_tab"))?>" <?if($str_QUESTION_TYPE=="S") echo "selected"?>><?echo GetMessage("LEARNING_SINGLE_CHOICE")?></option>
  670. <option value="<?=$APPLICATION->GetCurPageParam("QUESTION_TYPE=M", array("QUESTION_TYPE", "tabControl_active_tab"))?>" <?if($str_QUESTION_TYPE=="M") echo "selected"?>><?echo GetMessage("LEARNING_MULTIPLE_CHOICE")?></option>
  671. <option value="<?=$APPLICATION->GetCurPageParam("QUESTION_TYPE=R", array("QUESTION_TYPE", "tabControl_active_tab"))?>" <?if($str_QUESTION_TYPE=="R") echo "selected"?>><?echo GetMessage("LEARNING_SORTING")?></option>
  672. <option value="<?=$APPLICATION->GetCurPageParam("QUESTION_TYPE=T", array("QUESTION_TYPE", "tabControl_active_tab"))?>" <?if($str_QUESTION_TYPE=="T") echo "selected"?>><?echo GetMessage("LEARNING_TEXT_ANSWER")?></option>
  673. </select>
  674. <input type="hidden" name="QUESTION_TYPE" value="<?=$str_QUESTION_TYPE?>">
  675. </td>
  676. </tr>
  677. <?php $tabControl->EndCustomField("QUESTION_TYPE");?>
  678. <?php $tabControl->BeginCustomField("LESSON_ID", GetMessage("LEARNING_LESSON"), false);?>
  679. <tr class="adm-detail-required-field">
  680. <td><?echo $tabControl->GetCustomLabelHTML()?>:</td>
  681. <td><?php
  682. $rsLesson = CLearnLesson::GetByID($LESSON_ID);
  683. $arLesson = $rsLesson->GetNext();
  684. $curDir = $APPLICATION->GetCurDir();
  685. if (mb_substr($curDir, -1) !== '/')
  686. $curDir .= '/';
  687. ?>
  688. <script>
  689. function module_learning_js_admin_function_change_attached_lesson(lesson_id, name)
  690. {
  691. BX('attached_lesson_id').value = lesson_id;
  692. BX('attached_lesson_name').textContent = name;
  693. }
  694. </script>
  695. <div style="padding:0px;">
  696. <span id="attached_lesson_name"><?php echo $arLesson['NAME']; ?></span>
  697. (<a href="javascript:void(0);" class="bx-action-href"
  698. onclick="window.open('<?php echo addslashes(htmlspecialcharsbx($curDir)); ?>learn_unilesson_admin.php?lang=<?php echo LANGUAGE_ID;
  699. ?>&amp;search_retpoint=module_learning_js_admin_function_change_attached_lesson&amp;search_mode_type=attach_question_to_lesson',
  700. 'module_learning_js_admin_window_select_lessons_for_attach',
  701. 'scrollbars=yes,resizable=yes,width=960,height=500,top='+Math.floor((screen.height - 560)/2-14)+',left='+Math.floor((screen.width - 960)/2-5));"
  702. ><?php echo GetMessage('LEARNING_CHANGE_ATTACHED_LESSON'); ?></a>)
  703. </div>
  704. <input id="attached_lesson_id" type="hidden" name="LESSON_ID" value="<?echo $LESSON_ID; ?>">
  705. </td>
  706. </tr>
  707. <?php $tabControl->EndCustomField("LESSON_ID");?>
  708. <?php $tabControl->BeginCustomField("NAME", GetMessage("LEARNING_NAME"), false);?>
  709. <tr class="adm-detail-required-field">
  710. <td><?echo $tabControl->GetCustomLabelHTML()?>:</td>
  711. <td valign="top">
  712. <textarea name="NAME" size="50" maxlength="255" style="width:440px"><?php echo $str_NAME; ?></textarea>
  713. </td>
  714. </tr>
  715. <?php $tabControl->EndCustomField("NAME");?>
  716. <?php $tabControl->BeginCustomField("SORT", GetMessage("LEARNING_SORT"), false);?>
  717. <!-- Sort -->
  718. <tr>
  719. <td><? echo $tabControl->GetCustomLabelHTML()?>:</td>
  720. <td>
  721. <input type="text" name="SORT" size="10" maxlength="10" value="<?echo $str_SORT?>">
  722. </td>
  723. </tr>
  724. <?php $tabControl->EndCustomField("SORT");?>
  725. <?php $tabControl->BeginCustomField("POINT", GetMessage("LEARNING_POINT"), false);?>
  726. <tr>
  727. <td><?echo $tabControl->GetCustomLabelHTML()?>:</td>
  728. <td>
  729. <input type="text" name="POINT" size="7" maxlength="10" value="<?echo $str_POINT?>">
  730. </td>
  731. </tr>
  732. <?php $tabControl->EndCustomField("POINT");?>
  733. <?php $tabControl->BeginCustomField("SELF", GetMessage("LEARNING_F_SELF"), false);?>
  734. <?php if ($str_QUESTION_TYPE != "T"):?>
  735. <tr>
  736. <td><?echo $tabControl->GetCustomLabelHTML()?>:</td>
  737. <td>
  738. <input type="checkbox" name="SELF" value="Y"<?if($str_SELF=="Y")echo " checked"?>>
  739. </td>
  740. </tr>
  741. <?php endif?>
  742. <?php $tabControl->EndCustomField("SELF");?>
  743. <?php $tabControl->BeginCustomField("CORRECT_REQUIRED", GetMessage("LEARNING_CORRECT_REQUIRED"), false);?>
  744. <tr>
  745. <td><?echo $tabControl->GetCustomLabelHTML()?>:</td>
  746. <td>
  747. <input type="checkbox" name="CORRECT_REQUIRED" value="Y"<?if($str_CORRECT_REQUIRED=="Y")echo " checked"?>>
  748. </td>
  749. </tr>
  750. <?php $tabControl->EndCustomField("CORRECT_REQUIRED");?>
  751. <?php $tabControl->BeginCustomField("INCORRECT_MESSAGE", GetMessage("LEARNING_INCORRECT_MESSAGE"), false);?>
  752. <?php if ($str_QUESTION_TYPE != "T"):?>
  753. <tr>
  754. <td><?echo $tabControl->GetCustomLabelHTML()?>:</td>
  755. <td>
  756. <input type="text" name="INCORRECT_MESSAGE" size="50" maxlength="255" value="<?echo $str_INCORRECT_MESSAGE?>">
  757. </td>
  758. </tr>
  759. <?php endif?>
  760. <?php $tabControl->EndCustomField("INCORRECT_MESSAGE");?>
  761. <?php $tabControl->BeginCustomField("COMMENT_TEXT", GetMessage("LEARNING_COMMENT"), false);?>
  762. <tr>
  763. <td><?echo $tabControl->GetCustomLabelHTML()?>:</td>
  764. <td valign="top">
  765. <textarea name="COMMENT_TEXT" size="50" style="width:440px"><?php echo $str_COMMENT_TEXT; ?></textarea>
  766. </td>
  767. </tr>
  768. <?php $tabControl->EndCustomField("COMMENT_TEXT");?>
  769. <?php $tabControl->BeginCustomField("EMAIL_ANSWER", GetMessage("LEARNING_EMAIL_ANSWER"), false);?>
  770. <?php if ($str_QUESTION_TYPE == "T"):?>
  771. <tr>
  772. <td><?echo $tabControl->GetCustomLabelHTML()?>:</td>
  773. <td>
  774. <input type="checkbox" name="EMAIL_ANSWER" value="Y"<?if($str_EMAIL_ANSWER=="Y")echo " checked"?>>
  775. </td>
  776. </tr>
  777. <?php endif?>
  778. <?php $tabControl->EndCustomField("EMAIL_ANSWER");?>
  779. <?php $tabControl->BeginCustomField("FILE_ID", GetMessage("LEARNING_PICTURE"), false);?>
  780. <tr>
  781. <td valign="top"><?echo $tabControl->GetCustomLabelHTML()?>:</td>
  782. <td>
  783. <?echo CFile::InputFile("FILE_ID", 20, $str_FILE_ID, false, 0, "IMAGE", "", 40);?><br>
  784. <?
  785. if($str_FILE_ID)
  786. {
  787. echo CFile::ShowImage($str_FILE_ID, 200, 200, "border=0", "", true);
  788. }
  789. ?>
  790. </td>
  791. </tr>
  792. <?php $tabControl->EndCustomField("FILE_ID");?>
  793. <?$tabControl->BeginNextFormTab();?>
  794. <?php $tabControl->BeginCustomField("ANSWERS", GetMessage("LEARNING_ANSWERS"), false);?>
  795. <tr>
  796. <td valign="top" colspan="2">
  797. <?php if ($str_QUESTION_TYPE != "T"):?>
  798. <table cellpadding="0" cellspacing="0" width="100%" class="internal" id="answers-table">
  799. <tbody id="answers-table-tbody">
  800. <tr class="heading">
  801. <td align="center" width="40">ID</td>
  802. <?php if ($str_QUESTION_TYPE != "R"):?><td align="center" width="40"><?echo GetMessage("LEARNING_QUESTION_ADM_CORRECT")?></td><?php endif?>
  803. <td align="center"><?echo GetMessage("LEARNING_ANSWER")?></td>
  804. <td align="center" width="40"><?echo GetMessage("LEARNING_COURSE_ADM_SORT")?></td>
  805. <td align="center" width="40"><?echo GetMessage("LEARNING_COURSE_ADM_DELETE")?></td>
  806. </tr>
  807. <?php
  808. $nextNum = 0;
  809. $arNewIDs = array();
  810. $arNewIDsInt = array();
  811. if (is_array($ANSWER_HIDDEN_ID))
  812. {
  813. foreach($ANSWER_HIDDEN_ID as $id)
  814. {
  815. if ($id[0] == "n")
  816. {
  817. $origID = intval(mb_substr($id, 1));
  818. $arNewIDs[] = "n".$origID;
  819. $arNewIDsInt[] = $origID;
  820. }
  821. }
  822. }
  823. if (sizeof($arNewIDsInt))
  824. {
  825. $nextNum = max($arNewIDsInt) + 1;
  826. }
  827. function _GetOldAndNew($answers)
  828. {
  829. global $arNewIDs;
  830. if ($tmp = $answers->ExtractFields("str_ANSWER_"))
  831. {
  832. return $tmp;
  833. }
  834. elseif ($val = current($arNewIDs))
  835. {
  836. next($arNewIDs);
  837. global $str_ANSWER_ID, $str_ANSWER_CORRECT, $str_ANSWER_ANSWER, $str_ANSWER_SORT;
  838. $str_ANSWER_ID = $val;
  839. $str_ANSWER_CORRECT = "";
  840. $str_ANSWER_ANSWER = "";
  841. $str_ANSWER_SORT = "10";
  842. return true;
  843. }
  844. return false;
  845. }
  846. $SINGLE_ID = "";
  847. $answers = CLAnswer::GetList(Array("SORT" => "ASC","ID" => "ASC"),Array("QUESTION_ID"=>$ID));
  848. while ($r = _GetOldAndNew($answers)):
  849. if ($bVarsFromForm)
  850. {
  851. $DB->InitTableVarsForEdit("b_learn_answer", "ANSWER_".$str_ANSWER_ID."_", "str_ANSWER_");
  852. if ($str_QUESTION_TYPE == "S" && isset($_POST["ANSWER_CORRECT"]))
  853. {
  854. $SINGLE_ID = $_POST["ANSWER_CORRECT"];
  855. }
  856. }
  857. ?>
  858. <tr>
  859. <td align="center" width="40" style="text-align:center;"><?echo ((int)$str_ANSWER_ID>0? $str_ANSWER_ID:"")?></td>
  860. <?php if ($str_QUESTION_TYPE != "R"):?>
  861. <td align="center" width="40" style="text-align:center;">
  862. <?if ($str_QUESTION_TYPE == "M"):?>
  863. <input type="checkbox" name="ANSWER_<?=$str_ANSWER_ID?>_CORRECT" value="Y"<?if($str_ANSWER_CORRECT=="Y")echo " checked"?>>
  864. <?else:?>
  865. <input type="radio" name="ANSWER_CORRECT" value="<?=$str_ANSWER_ID?>"<?if($str_ANSWER_CORRECT=="Y" || $SINGLE_ID == $str_ANSWER_ID)echo " checked"?>>
  866. <?endif?>
  867. </td>
  868. <?php endif?>
  869. <td align="center" style="text-align:center;">
  870. <textarea style="width: 98%" name="ANSWER_<?=$str_ANSWER_ID?>_ANSWER"><?php echo $str_ANSWER_ANSWER; ?></textarea>
  871. </td>
  872. <td align="center" width="40" style="text-align:center;">
  873. <input type="text" size="3" name="ANSWER_<?=$str_ANSWER_ID?>_SORT" value="<?=$str_ANSWER_SORT?>">
  874. </td>
  875. <td align="center" width="40" style="text-align:center;">
  876. <?if(intval($str_ANSWER_ID)>0):?>
  877. <input type="checkbox" name="ANSWER_<?=$str_ANSWER_ID?>_DEL" value="Y">
  878. <?else:?>
  879. <a href="javascript:void(0);" onclick="BX.remove(this.parentNode.parentNode)"><img src="/bitrix/themes/.default/images/actions/delete_button.gif" border="0" width="20" height="20"/></a>
  880. <?endif?>
  881. <input type="hidden" name="ANSWER_HIDDEN_ID[]" value="<?=$str_ANSWER_ID?>">
  882. </td>
  883. </tr>
  884. <?endwhile;?>
  885. </tbody>
  886. </table>
  887. <script type="text/javascript">
  888. var nextNum = <?php echo $nextNum; ?>;
  889. function addAnswer() {
  890. var uniqueCheckBoxId = 'designed_checkbox_' + (new Date().getUTCMilliseconds()) + '_' + Math.random().toString(36).substr(2, 9);
  891. var row = BX.create("tr", {
  892. children: [
  893. BX.create('td', {
  894. props: {
  895. width: '40px'
  896. },
  897. style: {
  898. textAlign: 'center',
  899. color: 'blue'
  900. },
  901. html : '&nbsp;'
  902. }),
  903. <?php
  904. if ($str_QUESTION_TYPE != "R")
  905. {
  906. ?>
  907. BX.create('td', {
  908. props: {
  909. width: '40px',
  910. align: 'center'
  911. },
  912. style: {
  913. 'color': 'gray',
  914. 'textAlign': 'center'
  915. },
  916. html : <?php
  917. if ($str_QUESTION_TYPE == "M")
  918. {
  919. echo '\'<input id="\' + uniqueCheckBoxId + \'" class="adm-designed-checkbox" type="checkbox" value="Y" name="ANSWER_n\' + nextNum + \'_CORRECT">\''
  920. . ' + \'<label class="adm-designed-checkbox-label" for="\' + uniqueCheckBoxId + \'" title=""></label>\'';
  921. }
  922. else
  923. {
  924. echo '\'<input type="radio" name="ANSWER_CORRECT" value="n\' + nextNum + \'">\'';
  925. }
  926. ?>
  927. }),
  928. <?php
  929. }
  930. ?>
  931. BX.create('td', {
  932. html : '<textarea name="ANSWER_n' + nextNum + '_ANSWER" style="width: 98%"></textarea>',
  933. props : {align: 'center'}
  934. }),
  935. BX.create('td', {
  936. props: {
  937. width: '40px',
  938. align: 'center'
  939. },
  940. style: {
  941. 'textAlign': 'center'
  942. },
  943. html : '<input type="text" size="3" name="ANSWER_n' + nextNum + '_SORT" value="10">'
  944. }),
  945. BX.create('td', {
  946. props: {
  947. width: '40px',
  948. align: 'center'
  949. },
  950. style: {
  951. 'textAlign': 'center'
  952. },
  953. html : '<a href="javascript:void(0);" onclick="BX.remove(this.parentNode.parentNode)"><img src="/bitrix/themes/.default/images/actions/delete_button.gif" border="0" width="20" height="20"/></a><input type="hidden" name="ANSWER_HIDDEN_ID[]" value="n' + nextNum + '">'
  954. })
  955. ]
  956. });
  957. nextNum++;
  958. BX("answers-table-tbody").appendChild(row);
  959. }
  960. <?php
  961. if ($ID == 0)
  962. {
  963. ?>
  964. for (i = 0; i < 4; i++)
  965. addAnswer();
  966. <?php
  967. }
  968. ?>
  969. </script>
  970. <br />
  971. <a href="javascript:void(0)" class="adm-btn" onclick="addAnswer();"><?php echo GetMessage("LEARNING_ADD_ANSWER")?></a>
  972. <?php else:?>
  973. <?php echo GetMessage("LEARNING_NO_ANSWERS")?>
  974. <?php endif?>
  975. </td>
  976. </tr>
  977. <?php $tabControl->EndCustomField("ANSWERS");?>
  978. <?$tabControl->BeginNextFormTab();?>
  979. <?php $tabControl->BeginCustomField("DESCRIPTION", GetMessage("LEARNING_DESCRIPTION"), false);?>
  980. <?if(COption::GetOptionString("learning", "use_htmledit", "Y")=="Y" && CModule::IncludeModule("fileman")):?>
  981. <tr>
  982. <td colspan="2" align="center">
  983. <?CFileMan::AddHTMLEditorFrame(
  984. "DESCRIPTION",
  985. $str_DESCRIPTION,
  986. "DESCRIPTION_TYPE",
  987. $str_DESCRIPTION_TYPE,
  988. array('width' => '100%', 'height' => '500'),
  989. "N",
  990. 0,
  991. "",
  992. "",
  993. false,
  994. true,
  995. false,
  996. array('toolbarConfig' => CFileman::GetEditorToolbarConfig("learning_".(defined('BX_PUBLIC_MODE') && BX_PUBLIC_MODE == 1 ? 'public' : 'admin')))
  997. );?>
  998. </td>
  999. </tr>
  1000. <?else:?>
  1001. <tr>
  1002. <td align="center"><?echo GetMessage("LEARNING_DESC_TYPE")?>:</td>
  1003. <td>
  1004. <input type="radio" name="DESCRIPTION_TYPE" value="text"<?if($str_DESCRIPTION_TYPE!="html")echo " checked"?>> <?echo GetMessage("LEARNING_DESC_TYPE_TEXT")?>
  1005. <input type="radio" name="DESCRIPTION_TYPE" value="html"<?if($str_DESCRIPTION_TYPE=="html")echo " checked"?>> <?echo GetMessage("LEARNING_DESC_TYPE_HTML")?>
  1006. </td>
  1007. </tr>
  1008. <tr>
  1009. <td colspan="2">
  1010. <textarea style="width:100%; height:250px;" name="DESCRIPTION" wrap="off"><?echo $str_DESCRIPTION?></textarea>
  1011. </td>
  1012. </tr>
  1013. <?endif?>
  1014. <?php $tabControl->EndCustomField("DESCRIPTION");?>
  1015. <?
  1016. $tabControl->BeginNextFormTab();
  1017. $tabControl->BeginCustomField("UFS", '', false);
  1018. $USER_FIELD_MANAGER->EditFormShowTab('LEARNING_QUESTIONS', $bVarsFromForm, $ID);
  1019. $tabControl->EndCustomField("UFS");
  1020. $tabControl->Buttons(
  1021. Array("back_url" =>
  1022. $from == "learn_admin"
  1023. ?
  1024. "learn_unilesson_admin.php?lang=" . LANG . '&LESSON_PATH=' . $uriParentLessonPath . GetFilterParams("filter_", false) . "&from=learn_admin"
  1025. :
  1026. "learn_question_admin.php?lang=".LANG . '&LESSON_PATH=' . $uriLessonPath . GetFilterParams("filter_", false)
  1027. )
  1028. );
  1029. $tabControl->arParams["FORM_ACTION"] = $APPLICATION->GetCurPage()."?lang=" . LANG . '&LESSON_PATH=' . $uriLessonPath . GetFilterParams("filter_");
  1030. $tabControl->Show();?>
  1031. <?$tabControl->ShowWarnings($tabControl->GetName(), $message);?>
  1032. <script type="text/javascript">
  1033. function OnSubmit()
  1034. {
  1035. var form = document.forms['questionTabControl'];
  1036. var ids = form.elements['ANSWER_HIDDEN_ID[]'];
  1037. //Text or Sorting
  1038. if (form.elements['QUESTION_TYPE'].value == "T" || form.elements['QUESTION_TYPE'].value == "R")
  1039. {
  1040. return true;
  1041. }
  1042. //Single
  1043. else if (form.elements['QUESTION_TYPE'].value == "S")
  1044. {
  1045. el = form.elements['ANSWER_CORRECT'];
  1046. for(i=0; i<el.length; i++)
  1047. {
  1048. if (el[i].checked == true && form.elements['ANSWER_'+el[i].value+'_ANSWER'].value != "")
  1049. return true;
  1050. }
  1051. }
  1052. //Multple
  1053. else if (form.elements['QUESTION_TYPE'].value == "M")
  1054. {
  1055. for (i=0; i < ids.length; i++)
  1056. {
  1057. if (form.elements['ANSWER_'+ids[i].value+'_CORRECT'].checked == true && form.elements['ANSWER_'+ids[i].value+'_ANSWER'].value != "")
  1058. return true;
  1059. }
  1060. }
  1061. return confirm("<?=GetMessage("LEARNING_CONFIRM_CHECK_ANSWER")?>");
  1062. }
  1063. function CheckAnswer()
  1064. {
  1065. var form = document.forms['questionTabControl'];
  1066. for (i=0; ; i++)
  1067. {
  1068. var el = form.elements['ANSWER_n'+i+'_ANSWER'];
  1069. if (el)
  1070. {
  1071. if (el.value == "")
  1072. continue;
  1073. else
  1074. return true;
  1075. }
  1076. else
  1077. return false;
  1078. }
  1079. return false;
  1080. }
  1081. function CheckRightAnswer()
  1082. {
  1083. var form = document.forms['questionTabControl'];
  1084. var answer = form.elements['ANSWER_CORRECT'];
  1085. if (answer)
  1086. {
  1087. for(i=0; i<answer.length; i++)
  1088. {
  1089. if (answer[i].checked == true)
  1090. return true;
  1091. }
  1092. }
  1093. else
  1094. {
  1095. for (i=0; ; i++)
  1096. {
  1097. var el = form.elements['ANSWER_n'+i+'_CORRECT'];
  1098. if (el)
  1099. {
  1100. if (el.checked == true)
  1101. return true;
  1102. }
  1103. else
  1104. return false;
  1105. }
  1106. }
  1107. return false;
  1108. }
  1109. </script>
  1110. <?php
  1111. else://!bBadCourse
  1112. $aContext = array(
  1113. array(
  1114. "ICON" => "btn_list",
  1115. "TEXT"=>GetMessage("MAIN_ADMIN_MENU_LIST"),
  1116. "LINK"=>"learn_unilesson_admin.php?lang=" . LANG . '&LESSON_PATH=' . $uriParentLessonPath . GetFilterParams("filter_"),
  1117. "TITLE"=>GetMessage("LEARNING_BACK_TO_ADMIN")
  1118. ),
  1119. );
  1120. $context = new CAdminContextMenu($aContext);
  1121. $context->Show();
  1122. CAdminMessage::ShowMessage(GetMessage("LEARNING_BAD_COURSE"));
  1123. endif;
  1124. require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/epilog_admin.php");