search.php 27 KB

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