search.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822
  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. ];
  226. $.each(blocks, function( index, value ) {
  227. if (window.location.hash == value) {
  228. return true;
  229. }
  230. $(value).collapse("hide");
  231. });
  232. /*$("#filiere_panel").hide();
  233. $("#dispo_panel").hide();
  234. $("#dispo_pendant_panel").hide();
  235. $("#niveau_panel").hide();
  236. $("#methode_panel").hide();
  237. $("#themes_panel").hide();
  238. $("#objectifs_panel").hide();*/
  239. $("#filiere").on("click", function() {
  240. $("#filiere_panel").toggle();
  241. return false;
  242. });
  243. $("#dispo").on("click", function() {
  244. $("#dispo_panel").toggle();
  245. return false;
  246. });
  247. $("#dispo_pendant").on("click", function() {
  248. $("#dispo_pendant_panel").toggle();
  249. return false;
  250. });
  251. $("#niveau").on("click", function() {
  252. $("#niveau_panel").toggle();
  253. return false;
  254. });
  255. $("#methode").on("click", function() {
  256. $("#methode_panel").toggle();
  257. return false;
  258. });
  259. $("#themes").on("click", function() {
  260. $("#themes_panel").toggle();
  261. return false;
  262. });
  263. $("#objectifs").on("click", function() {
  264. $("#objectifs_panel").toggle();
  265. return false;
  266. });
  267. });
  268. </script>';
  269. $userForm->addHtml('<div class="panel-group" id="search_extrafield" role="tablist" aria-multiselectable="true">');
  270. $userForm->addHtml('<div class="panel panel-default">');
  271. $userForm->addHtml('<div class="panel-heading"><a role="button" data-toggle="collapse" data-parent="#search_extrafield" href="#collapseZero" aria-expanded="true" aria-controls="collapseZero">' .
  272. get_lang('DiagnosticForm') . '</a></div>');
  273. $userForm->addHtml('<div id="collapseZero" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingZero">');
  274. $userForm->addHtml('<div class="panel-body"><p class="text-info">');
  275. $userForm->addHtml(get_lang('DiagnosticIntroduction'));
  276. $userForm->addHtml('</div></div></div></div>');
  277. $userForm->addHtml('<div class="panel-group" id="search_extrafield" role="tablist" aria-multiselectable="true">');
  278. $userForm->addHtml('<div class="panel panel-default">');
  279. $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>');
  280. $userForm->addHtml('<div id="collapseOne" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne">');
  281. $userForm->addHtml('<div class="panel-body"><p class="text-info">' . get_lang('FiliereExplanation') .'</p>');
  282. $fieldsToShow = [
  283. 'statusocial',
  284. 'filiere_user',
  285. 'filiereprecision',
  286. 'filiere_want_stage',
  287. ];
  288. $extra = $extraField->addElements(
  289. $userForm,
  290. api_get_user_id(),
  291. [],
  292. $filter,
  293. true,
  294. $fieldsToShow,
  295. $fieldsToShow,
  296. [],
  297. [],
  298. false,
  299. $forceShowFields //$forceShowFields = false
  300. );
  301. $jqueryExtra .= $extra['jquery_ready_content'];
  302. $fieldsToShow = [
  303. 'filiere'
  304. ];
  305. $extra = $extraFieldSession->addElements(
  306. $userForm,
  307. api_get_user_id(),
  308. [],
  309. $filter,
  310. true,
  311. $fieldsToShow,
  312. $fieldsToShow,
  313. [],
  314. [],
  315. false,
  316. $forceShowFields //$forceShowFields = false
  317. );
  318. $jqueryExtra .= $extra['jquery_ready_content'];
  319. $userForm->addButtonSave(get_lang('Save'), 'submit_partial[collapseOne]');
  320. $userForm->addHtml('</div></div></div>');
  321. $userForm->addHtml('<div class="panel panel-default">');
  322. $userForm->addHtml('<div class="panel-heading"><a role="button" data-toggle="collapse" data-parent="#search_extrafield" href="#collapseTwo" aria-expanded="true" aria-controls="collapseTwo">' . get_lang('DisponibiliteAvant') . '</a></div>');
  323. $userForm->addHtml('<div id="collapseTwo" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingTwo">');
  324. $userForm->addHtml('<div class="panel-body"><p class="text-info">' . get_lang('DisponibiliteAvantExplanation') . '</p>');
  325. $extra = $extraFieldSession->addElements(
  326. $userForm,
  327. '',
  328. [],
  329. $filter,
  330. true,
  331. array('access_start_date', 'access_end_date'),
  332. [],
  333. [],
  334. [],
  335. false,
  336. $forceShowFields //$forceShowFields = false
  337. );
  338. $userForm->addRule(
  339. array('extra_access_start_date', 'extra_access_end_date'),
  340. get_lang('StartDateMustBeBeforeTheEndDate'),
  341. 'compare_datetime_text',
  342. '< allow_empty'
  343. );
  344. $jqueryExtra .= $extra['jquery_ready_content'];
  345. $elements = $userForm->getElements();
  346. $variables = ['access_start_date', 'access_end_date'];
  347. foreach ($elements as $element) {
  348. $element->setAttribute('extra_label_class', 'red_underline');
  349. }
  350. $fieldsToShow = [
  351. 'heures_disponibilite_par_semaine',
  352. ];
  353. $extra = $extraField->addElements(
  354. $userForm,
  355. api_get_user_id(),
  356. [],
  357. $filter,
  358. true,
  359. $fieldsToShow,
  360. $fieldsToShow,
  361. [],
  362. [],
  363. false,
  364. $forceShowFields //$forceShowFields = false
  365. );
  366. $userForm->addButtonSave(get_lang('Save'), 'submit_partial[collapseTwo]');
  367. $jqueryExtra .= $extra['jquery_ready_content'];
  368. $userForm->addHtml('</div></div></div>');
  369. $userForm->addHtml('<div class="panel panel-default">');
  370. $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>');
  371. $userForm->addHtml('<div id="collapseThree" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingThree">');
  372. $userForm->addHtml('<div class="panel-body"><p class="text-info">' . get_lang('DisponibilitePendantMonStageExplanation') . '</p>');
  373. $fieldsToShow = [
  374. 'datedebutstage',
  375. 'datefinstage',
  376. 'je_ne_connais_pas_encore_mes_dates_de_stage',
  377. 'poursuiteapprentissagestage',
  378. 'heures_disponibilite_par_semaine_stage'
  379. ];
  380. $extra = $extraField->addElements(
  381. $userForm,
  382. api_get_user_id(),
  383. [],
  384. $filter,
  385. true,
  386. $fieldsToShow,
  387. $fieldsToShow,
  388. [],
  389. [],
  390. false,
  391. $forceShowFields //$forceShowFields = false
  392. );
  393. $userForm->addRule(
  394. array('extra_datedebutstage', 'extra_datefinstage'),
  395. get_lang('StartDateMustBeBeforeTheEndDate'),
  396. 'compare_datetime_text',
  397. '< allow_empty'
  398. );
  399. $jqueryExtra .= $extra['jquery_ready_content'];
  400. $userForm->addButtonSave(get_lang('Save'), 'submit_partial[collapseThree]');
  401. $userForm->addHtml('</div></div></div>');
  402. $userForm->addHtml('<div class="panel panel-default">');
  403. $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>');
  404. $userForm->addHtml('<div id="collapseFour" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingFour">');
  405. $userForm->addHtml('<div class="panel-body"><p class="text-info">' . get_lang('ThemesObjectifsExplanation') . '</p>');
  406. $introductionTextList = [
  407. 'domaine' => get_lang('DomaineIntroduction'),
  408. $theme => get_lang('ThemeFieldIntroduction'),
  409. ];
  410. $fieldsToShow = [
  411. 'domaine',
  412. $theme
  413. ];
  414. $extra = $extraFieldSession->addElements(
  415. $userForm,
  416. api_get_user_id(),
  417. [],
  418. $filter,
  419. false, //tag as select
  420. $fieldsToShow,
  421. $fieldsToShow,
  422. $defaults,
  423. null,
  424. true,
  425. $forceShowFields, // $forceShowFields
  426. ['domaine' => 3, $theme => 5], // $separateExtraMultipleSelect
  427. [
  428. 'domaine' => [
  429. get_lang('Domaine').' 1',
  430. get_lang('Domaine').' 2',
  431. get_lang('Domaine').' 3'
  432. ],
  433. $theme => [
  434. get_lang('ThemeField').' 1',
  435. get_lang('ThemeField').' 2',
  436. get_lang('ThemeField').' 3',
  437. get_lang('ThemeField').' 4',
  438. get_lang('ThemeField').' 5'
  439. ],
  440. ],
  441. [],
  442. true, //$addEmptyOptionSelects
  443. $introductionTextList
  444. );
  445. $jqueryExtra .= $extra['jquery_ready_content'];
  446. $userForm->addButtonSave(get_lang('Save'), 'submit_partial[collapseFour]');
  447. $userForm->addHtml('</div></div></div>');
  448. $userForm->addHtml('<div class="panel panel-default">');
  449. $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>');
  450. $userForm->addHtml('<div id="collapseFive" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingFive">');
  451. $userForm->addHtml('<div class="panel-body"><p class="text-info">' . get_lang('NiveauLangueExplanation') . '</p>');
  452. $fieldsToShow = [
  453. //'competenceniveau'
  454. 'ecouter',
  455. 'lire',
  456. 'participer_a_une_conversation',
  457. 's_exprimer_oralement_en_continu',
  458. 'ecrire'
  459. ];
  460. $extra = $extraFieldSession->addElements(
  461. $userForm,
  462. api_get_user_id(),
  463. [],
  464. $filter,
  465. true,
  466. $fieldsToShow,
  467. $fieldsToShow,
  468. $defaults,
  469. [],
  470. false, //$orderDependingDefaults = false,
  471. $forceShowFields //$forceShowFields = false
  472. );
  473. $jqueryExtra .= $extra['jquery_ready_content'];
  474. $userForm->addButtonSave(get_lang('Save'), 'submit_partial[collapseFive]');
  475. $userForm->addHtml('</div></div></div>');
  476. $userForm->addHtml('<div class="panel panel-default">');
  477. $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>');
  478. $userForm->addHtml('<div id="collapseSix" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingSix">');
  479. $userForm->addHtml('<div class="panel-body"><p class="text-info">' . get_lang('ObjectifsApprentissageExplanation') . '</p>');
  480. $fieldsToShow = [
  481. 'objectif_apprentissage'
  482. ];
  483. $extra = $extraField->addElements(
  484. $userForm,
  485. api_get_user_id(),
  486. [],
  487. $filter,
  488. false,
  489. $fieldsToShow,
  490. $fieldsToShow,
  491. [],
  492. [],
  493. false,
  494. $forceShowFields //$forceShowFields = false
  495. );
  496. $jqueryExtra .= $extra['jquery_ready_content'];
  497. $userForm->addButtonSave(get_lang('Save'), 'submit_partial[collapseSix]');
  498. $userForm->addHtml('</div></div></div>');
  499. $userForm->addHtml('<div class="panel panel-default">');
  500. $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>');
  501. $userForm->addHtml('<div id="collapseSeven" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingSeven">');
  502. $userForm->addHtml('<div class="panel-body"><p class="text-info">' . get_lang('MethodeTravailExplanation') . '</p>');
  503. $fieldsToShow = [
  504. 'methode_de_travaille',
  505. 'accompagnement'
  506. ];
  507. $extra = $extraField->addElements(
  508. $userForm,
  509. api_get_user_id(),
  510. [],
  511. $filter,
  512. true,
  513. $fieldsToShow,
  514. $fieldsToShow,
  515. [],
  516. [],
  517. false,
  518. $forceShowFields //$forceShowFields = false
  519. );
  520. $jqueryExtra .= $extra['jquery_ready_content'];
  521. $userForm->addButtonSave(get_lang('Save'), 'submit_partial[collapseSeven]');
  522. $userForm->addHtml('</div></div></div>');
  523. $userForm->addHtml('</div>');
  524. $htmlHeadXtra[] ='<script>
  525. $(document).ready(function(){
  526. '.$jqueryExtra.'
  527. });
  528. </script>';
  529. $userForm->addButtonSave(get_lang('Send'));
  530. $userForm->setDefaults($defaults);
  531. /** @var HTML_QuickForm_select $element */
  532. $domaine1 = $userForm->getElementByName('extra_domaine[0]');
  533. $domaine2 = $userForm->getElementByName('extra_domaine[1]');
  534. $domaine3 = $userForm->getElementByName('extra_domaine[2]');
  535. $domainList = array_merge(
  536. is_object($domaine1) ? $domaine1->getValue() : [],
  537. is_object($domaine3) ? $domaine3->getValue() : [],
  538. is_object($domaine2) ? $domaine2->getValue() : []
  539. );
  540. $themeList = [];
  541. $extraField = new ExtraField('session');
  542. $resultOptions = $extraField->searchOptionsFromTags(
  543. 'extra_domaine',
  544. 'extra_'.$theme,
  545. $domainList
  546. );
  547. if ($resultOptions) {
  548. $resultOptions = array_column($resultOptions, 'tag', 'id');
  549. $resultOptions = array_filter($resultOptions);
  550. for ($i = 0; $i < 5; $i++) {
  551. /** @var HTML_QuickForm_select $theme */
  552. $themeElement = $userForm->getElementByName('extra_'.$theme.'['.$i.']');
  553. foreach ($resultOptions as $key => $value) {
  554. $themeElement->addOption($value, $value);
  555. }
  556. }
  557. }
  558. if ($userForm->validate()) {
  559. // Saving to user extra fields
  560. $extraFieldValue = new ExtraFieldValue('user');
  561. $userData = $userForm->getSubmitValues();
  562. $isPartial = false;
  563. $block = '';
  564. if (isset($userData['submit_partial'])) {
  565. $block = key($userData['submit_partial']);
  566. $isPartial = true;
  567. }
  568. if ($isPartial === false) {
  569. $userData['extra_diagnosis_completed'] = 1;
  570. }
  571. $extraFieldValue->saveFieldValues(
  572. $userData,
  573. $forceShowFields,
  574. false,
  575. [],
  576. ['legal_accept']
  577. );
  578. // Saving to extra_field_saved_search
  579. /** @var \Chamilo\UserBundle\Entity\User $user */
  580. $user = $em->getRepository('ChamiloUserBundle:User')->find($userId);
  581. $sessionFields = [
  582. 'extra_access_start_date',
  583. 'extra_access_end_date',
  584. 'extra_filiere',
  585. 'extra_domaine',
  586. 'extra_domaine[0]',
  587. 'extra_domaine[1]',
  588. 'extra_domaine[3]',
  589. 'extra_temps_de_travail',
  590. //'extra_competenceniveau',
  591. 'extra_'.$theme,
  592. 'extra_'.$theme.'[0]',
  593. 'extra_'.$theme.'[1]',
  594. 'extra_'.$theme.'[2]',
  595. 'extra_'.$theme.'[3]',
  596. 'extra_'.$theme.'[4]',
  597. 'extra_ecouter',
  598. 'extra_lire',
  599. 'extra_participer_a_une_conversation',
  600. 'extra_s_exprimer_oralement_en_continu',
  601. 'extra_ecrire'
  602. ];
  603. foreach ($userData as $key => $value) {
  604. $found = strpos($key, '__persist__');
  605. if ($found === false) {
  606. continue;
  607. }
  608. }
  609. if (isset($userData['extra_filiere_want_stage']) &&
  610. isset($userData['extra_filiere_want_stage']['extra_filiere_want_stage'])
  611. ) {
  612. $wantStage = $userData['extra_filiere_want_stage']['extra_filiere_want_stage'];
  613. if ($wantStage === 'yes') {
  614. if (isset($userData['extra_filiere_user'])) {
  615. $userData['extra_filiere'] = [];
  616. $userData['extra_filiere']['extra_filiere'] = $userData['extra_filiere_user']['extra_filiere_user'];
  617. }
  618. }
  619. }
  620. // save in ExtraFieldSavedSearch.
  621. foreach ($userData as $key => $value) {
  622. if (substr($key, 0, 6) != 'extra_' && substr($key, 0, 7) != '_extra_') {
  623. continue;
  624. }
  625. if (!in_array($key, $sessionFields)) {
  626. continue;
  627. }
  628. $field_variable = substr($key, 6);
  629. $extraFieldInfo = $extraFieldValueSession
  630. ->getExtraField()
  631. ->get_handler_field_info_by_field_variable($field_variable)
  632. ;
  633. if (!$extraFieldInfo) {
  634. continue;
  635. }
  636. $extraFieldObj = $em
  637. ->getRepository('ChamiloCoreBundle:ExtraField')
  638. ->find($extraFieldInfo['id'])
  639. ;
  640. $search = [
  641. 'field' => $extraFieldObj,
  642. 'user' => $user
  643. ];
  644. /** @var ExtraFieldSavedSearch $saved */
  645. $saved = $em->getRepository('ChamiloCoreBundle:ExtraFieldSavedSearch')->findOneBy($search);
  646. if ($saved) {
  647. $saved
  648. ->setField($extraFieldObj)
  649. ->setUser($user)
  650. ->setValue($value)
  651. ;
  652. $em->merge($saved);
  653. } else {
  654. $saved = new ExtraFieldSavedSearch();
  655. $saved
  656. ->setField($extraFieldObj)
  657. ->setUser($user)
  658. ->setValue($value)
  659. ;
  660. $em->persist($saved);
  661. }
  662. $em->flush();
  663. }
  664. $superiorUserList = UserManager::getStudentBossList($userInfo['user_id']);
  665. if ($superiorUserList && $isPartial == false) {
  666. $url = api_get_path(WEB_PATH).'load_search.php?user_id='.$userInfo['user_id'];
  667. $urlContact = api_get_path(WEB_CODE_PATH) . 'messages/inbox.php?f=social';
  668. $subject = sprintf(get_lang('DiagnosisFromUserX'), $userInfo['complete_name']);
  669. $message = sprintf(get_lang('DiagnosisFromUserXLangXWithLinkXContactAtX'), $userInfo['complete_name'], $userInfo['language'], $url, $urlContact);
  670. foreach ($superiorUserList as $bossData) {
  671. $bossId = $bossData['boss_id'];
  672. MessageManager::send_message_simple(
  673. $bossId,
  674. $subject,
  675. $message
  676. );
  677. }
  678. }
  679. if ($isPartial) {
  680. header('Location:'.api_get_self().'#'.$block);
  681. } else {
  682. header('Location:'.api_get_self().'?result=1');
  683. }
  684. exit;
  685. }
  686. $userFormToString = $userForm->returnForm();
  687. $result = isset($_GET['result']) ? true : false;
  688. $tpl = new Template(get_lang('Diagnosis'));
  689. if ($result === false) {
  690. $tpl->assign('form', $userFormToString);
  691. } else {
  692. Display::addFlash(Display::return_message(get_lang('SessionSearchSavedExplanation')));
  693. }
  694. $content = $tpl->fetch($tpl->get_template('user_portal/search_extra_field.tpl'));
  695. $tpl->assign('content', $content);
  696. $tpl->display_one_col_template();