search.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CoreBundle\Entity\ExtraFieldSavedSearch;
  4. $cidReset = true;
  5. require_once 'main/inc/global.inc.php';
  6. api_block_anonymous_users();
  7. $userId = api_get_user_id();
  8. $userInfo = api_get_user_info();
  9. $em = Database::getManager();
  10. $form = new FormValidator('search', 'post', api_get_self());
  11. $form->addHeader(get_lang('Diagnosis'));
  12. /** @var ExtraFieldSavedSearch $saved */
  13. $search = [
  14. 'user' => $userId,
  15. ];
  16. $items = $em->getRepository('ChamiloCoreBundle:ExtraFieldSavedSearch')->findBy($search);
  17. $extraFieldSession = new ExtraField('session');
  18. $extraFieldValueSession = new ExtraFieldValue('session');
  19. $filter = false;
  20. $extraFieldValue = new ExtraFieldValue('user');
  21. $wantStage = $extraFieldValue->get_values_by_handler_and_field_variable(
  22. api_get_user_id(),
  23. 'filiere_want_stage'
  24. );
  25. $diagnosisComplete = $extraFieldValue->get_values_by_handler_and_field_variable(
  26. api_get_user_id(),
  27. 'diagnosis_completed'
  28. );
  29. if ($diagnosisComplete && isset($diagnosisComplete['value']) && $diagnosisComplete['value'] == 1) {
  30. if (!isset($_GET['result'])) {
  31. //header('Location:'.api_get_self().'?result=1');
  32. //exit;
  33. }
  34. }
  35. $hide = true;
  36. if ($wantStage !== false) {
  37. $hide = $wantStage['value'] === 'yes';
  38. }
  39. $defaultValueStatus = 'extraFiliere.hide()';
  40. if ($hide === false) {
  41. $defaultValueStatus = '';
  42. }
  43. $url = api_get_path(WEB_AJAX_PATH).'extra_field.ajax.php?a=order&user_id='.$userId;
  44. // Use current user language
  45. $targetLanguage = $userInfo['language'];
  46. // Theme fix
  47. /*
  48. $targetLanguage = api_get_interface_language();
  49. $targetLanguageInfo = $extraFieldValue->get_values_by_handler_and_field_variable(
  50. api_get_user_id(),
  51. 'langue_cible'
  52. );
  53. if (!empty($targetLanguageInfo)) {
  54. $targetLanguage = strtolower($targetLanguageInfo['value']);
  55. }*/
  56. $theme = 'theme_fr';
  57. switch ($targetLanguage) {
  58. case 'italian':
  59. $theme = 'theme_it';
  60. break;
  61. case 'polish':
  62. $theme = 'theme_pl';
  63. break;
  64. case 'spanish':
  65. $theme = 'theme_es';
  66. break;
  67. case 'french2':
  68. case 'french':
  69. $theme = 'theme_fr';
  70. break;
  71. case 'german2':
  72. case 'german':
  73. $theme = 'theme_de';
  74. break;
  75. }
  76. $htmlHeadXtra[] = '<script>
  77. $(document).ready(function() {
  78. var themeDefault = "extra_'.$theme.'";
  79. var extraFiliere = $("input[name=\'extra_filiere[extra_filiere]\']").parent().parent().parent().parent();
  80. '.$defaultValueStatus.'
  81. $("input[name=\'extra_filiere_want_stage[extra_filiere_want_stage]\']").change(function() {
  82. if ($(this).val() == "no") {
  83. extraFiliere.show();
  84. } else {
  85. extraFiliere.hide();
  86. }
  87. });
  88. $("#extra_theme").parent().append(
  89. $("<a>", {
  90. "class": "btn ajax btn-default",
  91. "href": "'.$url.'&field_variable=extra_theme",
  92. "text": "'.get_lang('Order').'"
  93. })
  94. );
  95. $("#extra_theme_fr").parent().append(
  96. $("<a>", {
  97. "class": "btn ajax btn-default",
  98. "href": "'.$url.'&field_variable=extra_theme_fr",
  99. "text": "'.get_lang('Order').'"
  100. })
  101. );
  102. $("#extra_theme_de").parent().append(
  103. $("<a>", {
  104. "class": "btn ajax btn-default",
  105. "href": "'.$url.'&field_variable=extra_theme_de",
  106. "text": "'.get_lang('Order').'"
  107. })
  108. );
  109. $("#extra_theme_it").parent().append(
  110. $("<a>", {
  111. "class": "btn ajax btn-default",
  112. "href": "'.$url.'&field_variable=extra_theme_it",
  113. "text": "'.get_lang('Order').'"
  114. })
  115. );
  116. $("#extra_theme_es").parent().append(
  117. $("<a>", {
  118. "class": "btn ajax btn-default",
  119. "href": "'.$url.'&field_variable=extra_theme_es",
  120. "text": "'.get_lang('Order').'"
  121. })
  122. );
  123. $("#extra_theme_pl").parent().append(
  124. $("<a>", {
  125. "class": "btn ajax btn-default",
  126. "href": "'.$url.'&field_variable=extra_theme_pl",
  127. "text": "'.get_lang('Order').'"
  128. })
  129. );
  130. $("#extra_domaine_0, #extra_domaine_1, #extra_domaine_2").on("change", function() {
  131. var domainList = [];
  132. $("#extra_domaine_0 option:selected").each(function() {
  133. domainList.push($(this).val());
  134. });
  135. $("#extra_domaine_1 option:selected").each(function() {
  136. domainList.push($(this).val());
  137. });
  138. $("#extra_domaine_2 option:selected").each(function() {
  139. domainList.push($(this).val());
  140. });
  141. var domainListToString = JSON.stringify(domainList);
  142. $.ajax({
  143. contentType: "application/x-www-form-urlencoded",
  144. type: "GET",
  145. url: "'.api_get_path(WEB_AJAX_PATH).'extra_field.ajax.php?a=search_options_from_tags&type=session&from=extra_domaine&search="+themeDefault+"&options="+domainListToString,
  146. success: function(data) {
  147. var selectToString = "";
  148. selectToString += "<option></option>";
  149. jQuery.each(JSON.parse(data), function(i, item) {
  150. selectToString += "<optgroup label=\'"+item.text+"\'>";
  151. // Add empty value
  152. jQuery.each(item.children, function(j, data) {
  153. if (data.text != "") {
  154. selectToString += "<option value=\'"+data.text+"\'> " +data.text+"</option>"
  155. }
  156. });
  157. selectToString += "</optgroup>";
  158. });
  159. for (i = 0; i <= 5; i++) {
  160. var themeId = "#"+themeDefault+"_"+i;
  161. var beforeValue = $(themeId).find(":selected").val()
  162. $(themeId).find("option").remove().end();
  163. $(themeId).empty();
  164. $(themeId).html(selectToString);
  165. $(themeId).val(beforeValue);
  166. $(themeId).selectpicker("refresh");
  167. }
  168. }
  169. });
  170. });
  171. });
  172. </script>';
  173. $form->addButtonSave(get_lang('Save'), 'save');
  174. $result = SessionManager::getGridColumns('simple');
  175. $columns = $result['columns'];
  176. $column_model = $result['column_model'];
  177. $defaults = [];
  178. $tagsData = [];
  179. if (!empty($items)) {
  180. /** @var ExtraFieldSavedSearch $item */
  181. foreach ($items as $item) {
  182. $variable = 'extra_'.$item->getField()->getVariable();
  183. if ($item->getField()->getFieldType() == Extrafield::FIELD_TYPE_TAG) {
  184. $tagsData[$variable] = $item->getValue();
  185. }
  186. $defaults[$variable] = $item->getValue();
  187. }
  188. }
  189. $form->setDefaults($defaults);
  190. $filterToSend = '';
  191. if ($form->validate()) {
  192. $params = $form->getSubmitValues();
  193. /** @var \Chamilo\UserBundle\Entity\User $user */
  194. $user = $em->getRepository('ChamiloUserBundle:User')->find($userId);
  195. if (isset($params['save'])) {
  196. MessageManager::send_message_simple(
  197. $userId,
  198. get_lang('DiagnosisFilledSubject'),
  199. get_lang('DiagnosisFilledDescription')
  200. );
  201. $drhList = UserManager::getDrhListFromUser($userId);
  202. if ($drhList) {
  203. foreach ($drhList as $drhId) {
  204. $subject = sprintf(get_lang('UserXHasFilledTheDiagnosis'), $userInfo['complete_name']);
  205. $content = sprintf(get_lang('UserXHasFilledTheDiagnosisDescription'), $userInfo['complete_name']);
  206. MessageManager::send_message_simple($drhId, $subject, $content);
  207. }
  208. }
  209. Display::addFlash(Display::return_message(get_lang('Saved')));
  210. header("Location: ".api_get_self());
  211. exit;
  212. } else {
  213. // Search
  214. $filters = [];
  215. // Parse params.
  216. foreach ($params as $key => $value) {
  217. if (substr($key, 0, 6) != 'extra_' && substr($key, 0, 7) != '_extra_') {
  218. continue;
  219. }
  220. if (!empty($value)) {
  221. $filters[$key] = $value;
  222. }
  223. }
  224. $filterToSend = [];
  225. if (!empty($filters)) {
  226. $filterToSend = ['groupOp' => 'AND'];
  227. if ($filters) {
  228. $count = 1;
  229. $countExtraField = 1;
  230. foreach ($result['column_model'] as $column) {
  231. if ($count > 5) {
  232. if (isset($filters[$column['name']])) {
  233. $defaultValues['jqg'.$countExtraField] = $filters[$column['name']];
  234. $filterToSend['rules'][] = ['field' => $column['name'], 'op' => 'cn', 'data' => $filters[$column['name']]];
  235. }
  236. $countExtraField++;
  237. }
  238. $count++;
  239. }
  240. }
  241. }
  242. }
  243. }
  244. $forceShowFields = true;
  245. $extraField = new ExtraField('user');
  246. $userForm = new FormValidator('user_form', 'post', api_get_self());
  247. $jqueryExtra = '';
  248. $htmlHeadXtra[] = '<script>
  249. $(document).ready(function() {
  250. var blocks = [
  251. "#collapseOne",
  252. "#collapseTwo",
  253. "#collapseThree",
  254. "#collapseFour",
  255. "#collapseFive",
  256. "#collapseSix",
  257. "#collapseSeven",
  258. "#collapseEight"
  259. ];
  260. $.each(blocks, function( index, value ) {
  261. if (window.location.hash == value) {
  262. return true;
  263. }
  264. $(value).collapse("hide");
  265. });
  266. $("#filiere").on("click", function() {
  267. $("#filiere_panel").toggle();
  268. return false;
  269. });
  270. $("#dispo").on("click", function() {
  271. $("#dispo_panel").toggle();
  272. return false;
  273. });
  274. $("#dispo_pendant").on("click", function() {
  275. $("#dispo_pendant_panel").toggle();
  276. return false;
  277. });
  278. $("#niveau").on("click", function() {
  279. $("#niveau_panel").toggle();
  280. return false;
  281. });
  282. $("#methode").on("click", function() {
  283. $("#methode_panel").toggle();
  284. return false;
  285. });
  286. $("#enviroment").on("click", function() {
  287. $("#enviroment_panel").toggle();
  288. return false;
  289. });
  290. $("#themes").on("click", function() {
  291. $("#themes_panel").toggle();
  292. return false;
  293. });
  294. $("#objectifs").on("click", function() {
  295. $("#objectifs_panel").toggle();
  296. return false;
  297. });
  298. });
  299. </script>';
  300. $userForm->addHtml('<div class="panel-group" id="search_extrafield" role="tablist" aria-multiselectable="true">');
  301. $userForm->addHtml('<div class="panel panel-default">');
  302. $userForm->addHtml('<div class="panel-heading"><a role="button" data-toggle="collapse" data-parent="#search_extrafield" href="#collapseZero" aria-expanded="true" aria-controls="collapseZero">'.
  303. get_lang('DiagnosticForm').'</a></div>');
  304. $userForm->addHtml('<div id="collapseZero" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingZero">');
  305. $userForm->addHtml('<div class="panel-body"><p class="text-info">');
  306. $userForm->addHtml(get_lang('DiagnosticIntroduction'));
  307. $userForm->addHtml('</div></div></div></div>');
  308. $userForm->addHtml('<div class="panel-group" id="search_extrafield" role="tablist" aria-multiselectable="true">');
  309. $userForm->addHtml('<div class="panel panel-default">');
  310. $userForm->addHtml('<div class="panel-heading"><a role="button" data-toggle="collapse" data-parent="#search_extrafield" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">'.get_lang('Filiere').'</a></div>');
  311. $userForm->addHtml('<div id="collapseOne" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne">');
  312. $userForm->addHtml('<div class="panel-body"><p class="text-info">'.get_lang('FiliereExplanation').'</p>');
  313. $fieldsToShow = [
  314. 'statusocial',
  315. 'filiere_user',
  316. 'filiereprecision',
  317. 'filiere_want_stage',
  318. ];
  319. $extra = $extraField->addElements(
  320. $userForm,
  321. api_get_user_id(),
  322. [],
  323. $filter,
  324. true,
  325. $fieldsToShow,
  326. $fieldsToShow,
  327. [],
  328. false,
  329. $forceShowFields //$forceShowFields = false
  330. );
  331. $jqueryExtra .= $extra['jquery_ready_content'];
  332. $fieldsToShow = [
  333. 'filiere',
  334. ];
  335. $extra = $extraFieldSession->addElements(
  336. $userForm,
  337. api_get_user_id(),
  338. [],
  339. $filter,
  340. true,
  341. $fieldsToShow,
  342. $fieldsToShow,
  343. [],
  344. false,
  345. $forceShowFields //$forceShowFields = false
  346. );
  347. $jqueryExtra .= $extra['jquery_ready_content'];
  348. $userForm->addButtonSave(get_lang('Save'), 'submit_partial[collapseOne]');
  349. $userForm->addHtml('</div></div></div>');
  350. $userForm->addHtml('<div class="panel panel-default">');
  351. $userForm->addHtml(
  352. '<div class="panel-heading"><a role="button" data-toggle="collapse" data-parent="#search_extrafield" href="#collapseTwo" aria-expanded="true" aria-controls="collapseTwo">'.
  353. get_lang('DisponibiliteAvant').'</a></div>'
  354. );
  355. $userForm->addHtml('<div id="collapseTwo" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingTwo">');
  356. $userForm->addHtml('<div class="panel-body"><p class="text-info">'.get_lang('DisponibiliteAvantExplanation').'</p>');
  357. $extra = $extraFieldSession->addElements(
  358. $userForm,
  359. '',
  360. [],
  361. $filter,
  362. true,
  363. ['access_start_date', 'access_end_date'],
  364. [],
  365. [],
  366. false,
  367. $forceShowFields //$forceShowFields = false
  368. );
  369. $userForm->addRule(
  370. ['extra_access_start_date', 'extra_access_end_date'],
  371. get_lang('StartDateMustBeBeforeTheEndDate'),
  372. 'compare_datetime_text',
  373. '< allow_empty'
  374. );
  375. $jqueryExtra .= $extra['jquery_ready_content'];
  376. $elements = $userForm->getElements();
  377. $variables = ['access_start_date', 'access_end_date'];
  378. foreach ($elements as $element) {
  379. $element->setAttribute('extra_label_class', 'red_underline');
  380. }
  381. $fieldsToShow = [
  382. 'heures_disponibilite_par_semaine',
  383. 'moment_de_disponibilite',
  384. ];
  385. $extra = $extraField->addElements(
  386. $userForm,
  387. api_get_user_id(),
  388. [],
  389. $filter,
  390. true,
  391. $fieldsToShow,
  392. $fieldsToShow,
  393. [],
  394. false,
  395. $forceShowFields //$forceShowFields = false
  396. );
  397. $userForm->addButtonSave(get_lang('Save'), 'submit_partial[collapseTwo]');
  398. $jqueryExtra .= $extra['jquery_ready_content'];
  399. $userForm->addHtml('</div></div></div>');
  400. $userForm->addHtml('<div class="panel panel-default">');
  401. $userForm->addHtml('<div class="panel-heading"><a role="button" data-toggle="collapse" data-parent="#search_extrafield" href="#collapseThree" aria-expanded="true" aria-controls="collapseThree">'.get_lang('DisponibilitePendantMonStage').'</a></div>');
  402. $userForm->addHtml('<div id="collapseThree" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingThree">');
  403. $userForm->addHtml('<div class="panel-body"><p class="text-info">'.get_lang('DisponibilitePendantMonStageExplanation').'</p>');
  404. $fieldsToShow = [
  405. 'datedebutstage',
  406. 'datefinstage',
  407. 'je_ne_connais_pas_encore_mes_dates_de_stage',
  408. 'deja_sur_place',
  409. 'poursuiteapprentissagestage',
  410. 'heures_disponibilite_par_semaine_stage',
  411. ];
  412. $extra = $extraField->addElements(
  413. $userForm,
  414. api_get_user_id(),
  415. [],
  416. $filter,
  417. true,
  418. $fieldsToShow,
  419. $fieldsToShow,
  420. [],
  421. false,
  422. $forceShowFields //$forceShowFields = false
  423. );
  424. $userForm->addRule(
  425. ['extra_datedebutstage', 'extra_datefinstage'],
  426. get_lang('StartDateMustBeBeforeTheEndDate'),
  427. 'compare_datetime_text',
  428. '< allow_empty'
  429. );
  430. $jqueryExtra .= $extra['jquery_ready_content'];
  431. $userForm->addButtonSave(get_lang('Save'), 'submit_partial[collapseThree]');
  432. $userForm->addHtml('</div></div></div>');
  433. $userForm->addHtml('<div class="panel panel-default">');
  434. $userForm->addHtml('<div class="panel-heading"><a role="button" data-toggle="collapse" data-parent="#search_extrafield" href="#collapseFour" aria-expanded="true" aria-controls="collapseFour">'.get_lang('ThemesObjectifs').'</a></div>');
  435. $userForm->addHtml('<div id="collapseFour" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingFour">');
  436. $userForm->addHtml('<div class="panel-body"><p class="text-info">'.get_lang('ThemesObjectifsExplanation').'</p>');
  437. $introductionTextList = [
  438. 'domaine' => get_lang('DomaineIntroduction'),
  439. $theme => get_lang('ThemeFieldIntroduction'),
  440. ];
  441. $fieldsToShow = [
  442. 'domaine',
  443. $theme,
  444. ];
  445. $extra = $extraFieldSession->addElements(
  446. $userForm,
  447. api_get_user_id(),
  448. [],
  449. $filter,
  450. false, //tag as select
  451. $fieldsToShow,
  452. $fieldsToShow,
  453. $defaults,
  454. true,
  455. $forceShowFields, // $forceShowFields
  456. ['domaine' => 3, $theme => 5], // $separateExtraMultipleSelect
  457. [
  458. 'domaine' => [
  459. get_lang('Domaine').' 1',
  460. get_lang('Domaine').' 2',
  461. get_lang('Domaine').' 3',
  462. ],
  463. $theme => [
  464. get_lang('ThemeField').' 1',
  465. get_lang('ThemeField').' 2',
  466. get_lang('ThemeField').' 3',
  467. get_lang('ThemeField').' 4',
  468. get_lang('ThemeField').' 5',
  469. ],
  470. ],
  471. true, //$addEmptyOptionSelects
  472. $introductionTextList
  473. );
  474. $jqueryExtra .= $extra['jquery_ready_content'];
  475. $userForm->addButtonSave(get_lang('Save'), 'submit_partial[collapseFour]');
  476. $userForm->addHtml('</div></div></div>');
  477. $userForm->addHtml('<div class="panel panel-default">');
  478. $userForm->addHtml('<div class="panel-heading"><a role="button" data-toggle="collapse" data-parent="#search_extrafield" href="#collapseFive" aria-expanded="true" aria-controls="collapseFive">'.get_lang('NiveauLangue').'</a></div>');
  479. $userForm->addHtml('<div id="collapseFive" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingFive">');
  480. $userForm->addHtml('<div class="panel-body"><p class="text-info">'.get_lang('NiveauLangueExplanation').'</p>');
  481. $fieldsToShow = [
  482. //'competenceniveau'
  483. 'ecouter',
  484. 'lire',
  485. 'participer_a_une_conversation',
  486. 's_exprimer_oralement_en_continu',
  487. 'ecrire',
  488. ];
  489. $extra = $extraFieldSession->addElements(
  490. $userForm,
  491. api_get_user_id(),
  492. [],
  493. $filter,
  494. true,
  495. $fieldsToShow,
  496. $fieldsToShow,
  497. $defaults,
  498. false, //$orderDependingDefaults = false,
  499. $forceShowFields //$forceShowFields = false
  500. );
  501. $jqueryExtra .= $extra['jquery_ready_content'];
  502. $userForm->addButtonSave(get_lang('Save'), 'submit_partial[collapseFive]');
  503. $userForm->addHtml('</div></div></div>');
  504. $userForm->addHtml('<div class="panel panel-default">');
  505. $userForm->addHtml('<div class="panel-heading"><a role="button" data-toggle="collapse" data-parent="#search_extrafield" href="#collapseSix" aria-expanded="true" aria-controls="collapseSix">'.get_lang('ObjectifsApprentissage').'</a></div>');
  506. $userForm->addHtml('<div id="collapseSix" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingSix">');
  507. $userForm->addHtml('<div class="panel-body"><p class="text-info">'.get_lang('ObjectifsApprentissageExplanation').'</p>');
  508. $fieldsToShow = [
  509. 'objectif_apprentissage',
  510. ];
  511. $extra = $extraField->addElements(
  512. $userForm,
  513. api_get_user_id(),
  514. [],
  515. $filter,
  516. false,
  517. $fieldsToShow,
  518. $fieldsToShow,
  519. [],
  520. false,
  521. $forceShowFields //$forceShowFields = false
  522. );
  523. $jqueryExtra .= $extra['jquery_ready_content'];
  524. $userForm->addButtonSave(get_lang('Save'), 'submit_partial[collapseSix]');
  525. $userForm->addHtml('</div></div></div>');
  526. $userForm->addHtml('<div class="panel panel-default">');
  527. $userForm->addHtml('<div class="panel-heading"><a role="button" data-toggle="collapse" data-parent="#search_extrafield" href="#collapseSeven" aria-expanded="true" aria-controls="collapseSeven">'.get_lang('MethodeTravail').'</a></div>');
  528. $userForm->addHtml('<div id="collapseSeven" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingSeven">');
  529. $userForm->addHtml('<div class="panel-body"><p class="text-info">'.get_lang('MethodeTravailExplanation').'</p>');
  530. $fieldsToShow = [
  531. 'methode_de_travaille',
  532. 'accompagnement',
  533. ];
  534. $extra = $extraField->addElements(
  535. $userForm,
  536. api_get_user_id(),
  537. [],
  538. $filter,
  539. true,
  540. $fieldsToShow,
  541. $fieldsToShow,
  542. [],
  543. false,
  544. $forceShowFields //$forceShowFields = false
  545. );
  546. $jqueryExtra .= $extra['jquery_ready_content'];
  547. $userForm->addButtonSave(get_lang('Save'), 'submit_partial[collapseSeven]');
  548. $userForm->addHtml('</div></div></div>');
  549. // Enviroment
  550. $userForm->addHtml('<div class="panel panel-default">');
  551. $userForm->addHtml(
  552. '<div class="panel-heading">
  553. <a role="button" data-toggle="collapse" data-parent="#search_extrafield" href="#collapseEight" aria-expanded="true" aria-controls="collapseEight">'.
  554. get_lang('MonEnvironnementDeTravail').'</a></div>');
  555. $userForm->addHtml('<div id="collapseEight" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingEight">');
  556. $userForm->addHtml('<div class="panel-body"><p class="text-info">'.get_lang('MonEnvironnementDeTravailExplanation').'</p>');
  557. $fieldsToShow = [
  558. 'outil_de_travail_ordinateur',
  559. 'outil_de_travail_ordinateur_so',
  560. 'outil_de_travail_tablette',
  561. 'outil_de_travail_tablette_so',
  562. 'outil_de_travail_smartphone',
  563. 'outil_de_travail_smartphone_so',
  564. ];
  565. $userForm->addLabel(null, get_lang('MonEnvironnementDeTravailExplanationIntro1'));
  566. $extra = $extraField->addElements(
  567. $userForm,
  568. api_get_user_id(),
  569. [],
  570. $filter,
  571. true,
  572. $fieldsToShow,
  573. $fieldsToShow,
  574. [],
  575. false,
  576. $forceShowFields //$forceShowFields = false
  577. );
  578. $userForm->addLabel(null, get_lang('MonEnvironnementDeTravailExplanationIntro2'));
  579. $jqueryExtra .= $extra['jquery_ready_content'];
  580. $fieldsToShow = [
  581. 'browser_platforme',
  582. 'browser_platforme_autre',
  583. 'browser_platforme_version',
  584. ];
  585. $extra = $extraField->addElements(
  586. $userForm,
  587. api_get_user_id(),
  588. [],
  589. $filter,
  590. true,
  591. $fieldsToShow,
  592. $fieldsToShow,
  593. [],
  594. false,
  595. $forceShowFields //$forceShowFields = false
  596. );
  597. $jqueryExtra .= $extra['jquery_ready_content'];
  598. $userForm->addHtml('<p class="text-info">'.get_lang('MonEnvironnementDeTravailRenvoiFAQ').'</p>');
  599. $userForm->addButtonSave(get_lang('Save'), 'submit_partial[collapseEight]');
  600. $userForm->addHtml('</div></div></div>');
  601. $userForm->addHtml('</div>');
  602. $userForm->addHtml('</div>');
  603. $htmlHeadXtra[] = '<script>
  604. $(document).ready(function(){
  605. '.$jqueryExtra.'
  606. });
  607. </script>';
  608. $userForm->addButtonSave(get_lang('Send'));
  609. $userForm->setDefaults($defaults);
  610. /** @var HTML_QuickForm_select $element */
  611. $domaine1 = $userForm->getElementByName('extra_domaine[0]');
  612. $domaine2 = $userForm->getElementByName('extra_domaine[1]');
  613. $domaine3 = $userForm->getElementByName('extra_domaine[2]');
  614. $domainList = array_merge(
  615. is_object($domaine1) ? $domaine1->getValue() : [],
  616. is_object($domaine3) ? $domaine3->getValue() : [],
  617. is_object($domaine2) ? $domaine2->getValue() : []
  618. );
  619. $themeList = [];
  620. $extraField = new ExtraField('session');
  621. $resultOptions = $extraField->searchOptionsFromTags(
  622. 'extra_domaine',
  623. 'extra_'.$theme,
  624. $domainList
  625. );
  626. if ($resultOptions) {
  627. $resultOptions = array_column($resultOptions, 'tag', 'id');
  628. $resultOptions = array_filter($resultOptions);
  629. for ($i = 0; $i < 5; $i++) {
  630. /** @var HTML_QuickForm_select $theme */
  631. $themeElement = $userForm->getElementByName('extra_'.$theme.'['.$i.']');
  632. foreach ($resultOptions as $key => $value) {
  633. $themeElement->addOption($value, $value);
  634. }
  635. }
  636. }
  637. if ($userForm->validate()) {
  638. // Saving to user extra fields
  639. $extraFieldValue = new ExtraFieldValue('user');
  640. $userData = $userForm->getSubmitValues();
  641. $isPartial = false;
  642. $block = '';
  643. if (isset($userData['submit_partial'])) {
  644. $block = key($userData['submit_partial']);
  645. $isPartial = true;
  646. }
  647. if ($isPartial === false) {
  648. $userData['extra_diagnosis_completed'] = 1;
  649. }
  650. $extraFieldValue->saveFieldValues(
  651. $userData,
  652. $forceShowFields,
  653. false,
  654. [],
  655. ['legal_accept']
  656. );
  657. // Saving to extra_field_saved_search
  658. /** @var \Chamilo\UserBundle\Entity\User $user */
  659. $user = $em->getRepository('ChamiloUserBundle:User')->find($userId);
  660. $sessionFields = [
  661. 'extra_access_start_date',
  662. 'extra_access_end_date',
  663. 'extra_filiere',
  664. 'extra_domaine',
  665. 'extra_domaine[0]',
  666. 'extra_domaine[1]',
  667. 'extra_domaine[3]',
  668. 'extra_temps_de_travail',
  669. //'extra_competenceniveau',
  670. 'extra_'.$theme,
  671. 'extra_'.$theme.'[0]',
  672. 'extra_'.$theme.'[1]',
  673. 'extra_'.$theme.'[2]',
  674. 'extra_'.$theme.'[3]',
  675. 'extra_'.$theme.'[4]',
  676. 'extra_ecouter',
  677. 'extra_lire',
  678. 'extra_participer_a_une_conversation',
  679. 'extra_s_exprimer_oralement_en_continu',
  680. 'extra_ecrire',
  681. ];
  682. foreach ($userData as $key => $value) {
  683. $found = strpos($key, '__persist__');
  684. if ($found === false) {
  685. continue;
  686. }
  687. }
  688. if (isset($userData['extra_filiere_want_stage']) &&
  689. isset($userData['extra_filiere_want_stage']['extra_filiere_want_stage'])
  690. ) {
  691. $wantStage = $userData['extra_filiere_want_stage']['extra_filiere_want_stage'];
  692. if ($wantStage === 'yes') {
  693. if (isset($userData['extra_filiere_user'])) {
  694. $userData['extra_filiere'] = [];
  695. $userData['extra_filiere']['extra_filiere'] = $userData['extra_filiere_user']['extra_filiere_user'];
  696. }
  697. }
  698. }
  699. // save in ExtraFieldSavedSearch.
  700. foreach ($userData as $key => $value) {
  701. if (substr($key, 0, 6) != 'extra_' && substr($key, 0, 7) != '_extra_') {
  702. continue;
  703. }
  704. if (!in_array($key, $sessionFields)) {
  705. continue;
  706. }
  707. $field_variable = substr($key, 6);
  708. $extraFieldInfo = $extraFieldValueSession
  709. ->getExtraField()
  710. ->get_handler_field_info_by_field_variable($field_variable)
  711. ;
  712. if (!$extraFieldInfo) {
  713. continue;
  714. }
  715. $extraFieldObj = $em
  716. ->getRepository('ChamiloCoreBundle:ExtraField')
  717. ->find($extraFieldInfo['id'])
  718. ;
  719. $search = [
  720. 'field' => $extraFieldObj,
  721. 'user' => $user,
  722. ];
  723. /** @var ExtraFieldSavedSearch $saved */
  724. $saved = $em->getRepository('ChamiloCoreBundle:ExtraFieldSavedSearch')->findOneBy($search);
  725. if ($saved) {
  726. $saved
  727. ->setField($extraFieldObj)
  728. ->setUser($user)
  729. ->setValue($value)
  730. ;
  731. $em->merge($saved);
  732. } else {
  733. $saved = new ExtraFieldSavedSearch();
  734. $saved
  735. ->setField($extraFieldObj)
  736. ->setUser($user)
  737. ->setValue($value)
  738. ;
  739. $em->persist($saved);
  740. }
  741. $em->flush();
  742. }
  743. $superiorUserList = UserManager::getStudentBossList($userInfo['user_id']);
  744. if ($superiorUserList && $isPartial == false) {
  745. $url = api_get_path(WEB_PATH).'load_search.php?user_id='.$userInfo['user_id'];
  746. $urlContact = api_get_path(WEB_CODE_PATH).'messages/inbox.php?f=social';
  747. $subject = sprintf(get_lang('DiagnosisFromUserX'), $userInfo['complete_name']);
  748. $message = sprintf(get_lang('DiagnosisFromUserXLangXWithLinkXContactAtX'), $userInfo['complete_name'], $userInfo['language'], $url, $urlContact);
  749. foreach ($superiorUserList as $bossData) {
  750. $bossId = $bossData['boss_id'];
  751. MessageManager::send_message_simple(
  752. $bossId,
  753. $subject,
  754. $message
  755. );
  756. }
  757. }
  758. if ($isPartial) {
  759. header('Location:'.api_get_self().'#'.$block);
  760. } else {
  761. header('Location:'.api_get_self().'?result=1');
  762. }
  763. exit;
  764. }
  765. $userFormToString = $userForm->returnForm();
  766. $result = isset($_GET['result']) ? true : false;
  767. $tpl = new Template(get_lang('Diagnosis'));
  768. if ($result === false) {
  769. $tpl->assign('form', $userFormToString);
  770. } else {
  771. Display::addFlash(Display::return_message(get_lang('SessionSearchSavedExplanation')));
  772. }
  773. $content = $tpl->fetch($tpl->get_template('user_portal/search_extra_field.tpl'));
  774. $tpl->assign('content', $content);
  775. $tpl->display_one_col_template();