load_search.php 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CoreBundle\Entity\ExtraFieldSavedSearch;
  4. use ChamiloSession as Session;
  5. $cidReset = true;
  6. require_once 'main/inc/global.inc.php';
  7. $htmlHeadXtra[] = '<link href="'.api_get_path(WEB_PATH).'web/assets/cropper/dist/cropper.min.css" rel="stylesheet">';
  8. $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_PATH).'web/assets/cropper/dist/cropper.min.js"></script>';
  9. $htmlHeadXtra[] = '<script>
  10. $(document).ready(function() {
  11. $("#filiere").on("click", function() {
  12. $("#filiere_panel").toggle();
  13. return false;
  14. });
  15. $("#dispo").on("click", function() {
  16. $("#dispo_panel").toggle();
  17. return false;
  18. });
  19. $("#dispo_pendant").on("click", function() {
  20. $("#dispo_pendant_panel").toggle();
  21. return false;
  22. });
  23. $("#niveau").on("click", function() {
  24. $("#niveau_panel").toggle();
  25. return false;
  26. });
  27. $("#methode").on("click", function() {
  28. $("#methode_panel").toggle();
  29. return false;
  30. });
  31. $("#themes").on("click", function() {
  32. $("#themes_panel").toggle();
  33. return false;
  34. });
  35. $("#objectifs").on("click", function() {
  36. $("#objectifs_panel").toggle();
  37. return false;
  38. });
  39. });
  40. </script>';
  41. api_block_anonymous_users();
  42. $allowToSee = api_is_drh() || api_is_student_boss() || api_is_platform_admin();
  43. if ($allowToSee === false) {
  44. api_not_allowed(true);
  45. }
  46. $userId = api_get_user_id();
  47. $userInfo = api_get_user_info();
  48. $userToLoad = isset($_GET['user_id']) ? $_GET['user_id'] : '';
  49. $userToLoadInfo = [];
  50. if ($userToLoad) {
  51. $userToLoadInfo = api_get_user_info($userToLoad);
  52. }
  53. $action = isset($_GET['action']) ? $_GET['action'] : '';
  54. switch ($action) {
  55. case 'subscribe_user':
  56. $sessionId = isset($_GET['session_id']) ? $_GET['session_id'] : '';
  57. SessionManager::subscribeUsersToSession(
  58. $sessionId,
  59. [$userToLoad],
  60. SESSION_VISIBLE_READ_ONLY,
  61. false
  62. );
  63. Display::addFlash(Display::return_message(get_lang('UserAdded')));
  64. header("Location: ".api_get_self().'?user_id='.$userToLoad.'#session-table');
  65. exit;
  66. break;
  67. case 'unsubscribe_user':
  68. $sessionId = isset($_GET['session_id']) ? $_GET['session_id'] : '';
  69. SessionManager::unsubscribe_user_from_session($sessionId, $userToLoad);
  70. Display::addFlash(Display::return_message(get_lang('Unsubscribed')));
  71. header("Location: ".api_get_self().'?user_id='.$userToLoad.'#session-table');
  72. break;
  73. }
  74. $em = Database::getManager();
  75. $formSearch = new FormValidator('load', 'get', api_get_self());
  76. $formSearch->addHeader(get_lang('LoadDiagnosis'));
  77. if (!empty($userInfo)) {
  78. $users = [];
  79. switch ($userInfo['status']) {
  80. case DRH:
  81. $users = UserManager::get_users_followed_by_drh($userId);
  82. break;
  83. case STUDENT_BOSS:
  84. $users = UserManager::getUsersFollowedByStudentBoss($userId);
  85. break;
  86. }
  87. if (!empty($users)) {
  88. $userList = [];
  89. foreach ($users as $user) {
  90. $userList[$user['user_id']] = api_get_person_name($user['firstname'], $user['lastname']);
  91. }
  92. $formSearch->addSelect('user_id', get_lang('User'), $userList);
  93. }
  94. }
  95. if ($userToLoad) {
  96. $formSearch->setDefaults(['user_id' => $userToLoad]);
  97. }
  98. $formSearch->addButtonSearch(get_lang('ShowDiagnostic'), 'save');
  99. $form = new FormValidator('search', 'post', api_get_self().'?user_id='.$userToLoad.'#session-table');
  100. $form->addHeader(get_lang('Diagnosis'));
  101. $form->addHidden('user_id', $userToLoad);
  102. /** @var ExtraFieldSavedSearch $saved */
  103. $search = [
  104. 'user' => $userToLoad,
  105. ];
  106. $items = $em->getRepository('ChamiloCoreBundle:ExtraFieldSavedSearch')->findBy($search);
  107. if (empty($items)) {
  108. Display::addFlash(Display::return_message('NoData'));
  109. }
  110. $defaults = [];
  111. $tagsData = [];
  112. if (!empty($items)) {
  113. /** @var ExtraFieldSavedSearch $item */
  114. foreach ($items as $item) {
  115. $variable = 'extra_'.$item->getField()->getVariable();
  116. if ($item->getField()->getFieldType() == ExtraField::FIELD_TYPE_TAG) {
  117. $tagsData[$variable] = $item->getValue();
  118. }
  119. $defaults[$variable] = $item->getValue();
  120. }
  121. }
  122. $extraField = new ExtraField('session');
  123. $extraFieldValue = new ExtraFieldValue('session');
  124. $extraFieldValueUser = new ExtraFieldValue('user');
  125. $theme = 'theme_fr';
  126. $lang = $defaultLangCible = api_get_interface_language();
  127. if ($userToLoadInfo) {
  128. $lang = $userToLoadInfo['language'];
  129. $targetLanguageInfo = $extraFieldValueUser->get_values_by_handler_and_field_variable(
  130. $userToLoad,
  131. 'langue_cible'
  132. );
  133. if (!empty($targetLanguageInfo)) {
  134. $defaultLangCible = $targetLanguageInfo['value'];
  135. }
  136. switch ($lang) {
  137. case 'italian':
  138. $theme = 'theme_it';
  139. break;
  140. case 'polish':
  141. $theme = 'theme_pl';
  142. break;
  143. case 'spanish':
  144. $theme = 'theme_es';
  145. break;
  146. case 'french2':
  147. case 'french':
  148. $theme = 'theme_fr';
  149. break;
  150. case 'german2':
  151. case 'german':
  152. $theme = 'theme_de';
  153. break;
  154. }
  155. }
  156. $extraFieldUser = new ExtraField('user');
  157. $userForm = new FormValidator('user_form', 'post', api_get_self());
  158. $jqueryExtra = '';
  159. $userForm->addHtml('<div class="panel-group" id="search_extrafield" role="tablist" aria-multiselectable="true">');
  160. $userForm->addHtml('<div class="panel panel-default">');
  161. $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>');
  162. $userForm->addHtml('<div id="collapseOne" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne">');
  163. $userForm->addHtml('<div class="panel-body"><p class="text-info">'.get_lang('FiliereExplanation').'</p>');
  164. $fieldsToShow = [
  165. 'statusocial',
  166. 'filiere_user',
  167. 'filiereprecision',
  168. 'filiere_want_stage',
  169. ];
  170. $forceShowFields = true;
  171. $filter = false;
  172. $extra = $extraFieldUser->addElements(
  173. $userForm,
  174. $userToLoad,
  175. [],
  176. $filter,
  177. true,
  178. $fieldsToShow,
  179. $fieldsToShow,
  180. [],
  181. false,
  182. $forceShowFields, //$forceShowFields = false
  183. [],
  184. []
  185. );
  186. $userForm->addHtml('</div></div></div>');
  187. $userForm->addHtml('<div class="panel panel-default">');
  188. $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>');
  189. $userForm->addHtml('<div id="collapseThree" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingThree">');
  190. $userForm->addHtml('<div class="panel-body"><p class="text-info">'.get_lang('DisponibilitePendantMonStageExplanation').'</p>');
  191. $fieldsToShow = [
  192. 'datedebutstage',
  193. 'datefinstage',
  194. 'deja_sur_place',
  195. 'poursuiteapprentissagestage',
  196. 'heures_disponibilite_par_semaine_stage',
  197. ];
  198. $extra = $extraFieldUser->addElements(
  199. $userForm,
  200. $userToLoad,
  201. [],
  202. $filter,
  203. true,
  204. $fieldsToShow,
  205. $fieldsToShow,
  206. [],
  207. false,
  208. $forceShowFields, //$forceShowFields = false
  209. [],
  210. []
  211. );
  212. $userForm->addHtml('</div></div></div>');
  213. $userForm->addHtml('<div class="panel panel-default">');
  214. $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>');
  215. $userForm->addHtml('<div id="collapseSix" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingSix">');
  216. $userForm->addHtml('<div class="panel-body"><p class="text-info">'.get_lang('ObjectifsApprentissageExplanation').'</p>');
  217. $fieldsToShow = [
  218. 'objectif_apprentissage',
  219. ];
  220. $extra = $extraFieldUser->addElements(
  221. $userForm,
  222. $userToLoad,
  223. [],
  224. $filter,
  225. false,
  226. $fieldsToShow,
  227. $fieldsToShow,
  228. $defaults,
  229. false,
  230. $forceShowFields,//$forceShowFields = false
  231. [],
  232. []
  233. );
  234. $userForm->addHtml('</div></div></div>');
  235. $userForm->addHtml('<div class="panel panel-default">');
  236. $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>');
  237. $userForm->addHtml('<div id="collapseSeven" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingSeven">');
  238. $userForm->addHtml('<div class="panel-body"><p class="text-info">'.get_lang('MethodeTravailExplanation').'</p>');
  239. $fieldsToShow = [
  240. 'methode_de_travaille',
  241. 'accompagnement',
  242. ];
  243. $extra = $extraFieldUser->addElements(
  244. $userForm,
  245. $userToLoad,
  246. [],
  247. $filter,
  248. true,
  249. $fieldsToShow,
  250. $fieldsToShow,
  251. [],
  252. false,
  253. $forceShowFields, //$forceShowFields = false
  254. [],
  255. []
  256. );
  257. $userForm->addHtml('</div></div></div>');
  258. if (isset($_POST) && !empty($_POST)) {
  259. $searchChecked1 = isset($_POST['search_using_1']) ? 'checked' : '';
  260. $searchChecked2 = isset($_POST['search_using_2']) ? 'checked' : '';
  261. $searchChecked3 = isset($_POST['search_using_3']) ? 'checked' : '';
  262. Session::write('search_using_1', $searchChecked1);
  263. Session::write('search_using_2', $searchChecked2);
  264. Session::write('search_using_3', $searchChecked3);
  265. } else {
  266. $searchChecked1 = Session::read('search_using_1');
  267. $searchChecked1 = $searchChecked1 === null ? 'checked' : $searchChecked1;
  268. $searchChecked2 = Session::read('search_using_2');
  269. $searchChecked2 = $searchChecked2 === null ? 'checked' : $searchChecked2;
  270. $searchChecked3 = Session::read('search_using_3');
  271. $searchChecked3 = $searchChecked3 === null ? 'checked' : $searchChecked3;
  272. }
  273. $form->addHtml('<div class="panel panel-default">');
  274. $form->addHtml('<div class="panel-heading"><input type="checkbox" name="search_using_1" '.$searchChecked1.' />&nbsp;<a role="button" data-toggle="collapse" data-parent="#search_extrafield" href="#collapseTwo" aria-expanded="true" aria-controls="collapseTwo">'.get_lang('DisponibiliteAvant').'</a></div>');
  275. $form->addHtml('<div id="collapseTwo" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingTwo">');
  276. $form->addHtml('<div class="panel-body"><p class="text-info">'.get_lang('DisponibiliteAvantExplanation').'</p>');
  277. // Session fields
  278. $showOnlyThisFields = [
  279. 'access_start_date',
  280. 'access_end_date',
  281. ];
  282. $extra = $extraField->addElements(
  283. $form,
  284. '',
  285. [],
  286. false, //filter
  287. true,
  288. $showOnlyThisFields,
  289. $showOnlyThisFields,
  290. $defaults,
  291. false, //$orderDependingDefaults
  292. true, // force
  293. [], // $separateExtraMultipleSelect
  294. []
  295. );
  296. $fieldsToShow = [
  297. 'heures_disponibilite_par_semaine',
  298. 'moment_de_disponibilite',
  299. //'langue_cible',
  300. ];
  301. $extra = $extraFieldUser->addElements(
  302. $form,
  303. $userToLoad,
  304. [],
  305. $filter,
  306. true,
  307. $fieldsToShow,
  308. $fieldsToShow,
  309. [],
  310. false,
  311. $forceShowFields //$forceShowFields = false
  312. );
  313. $form->addHtml('</div></div></div>');
  314. $form->addHtml('<div class="panel panel-default">');
  315. $form->addHtml('<div class="panel-heading"><input type="checkbox" name="search_using_2" '.$searchChecked2.' />&nbsp;<a role="button" data-toggle="collapse" data-parent="#search_extrafield" href="#collapseFour" aria-expanded="true" aria-controls="collapseFour">'.get_lang('ThemesObjectifs').'</a></div>');
  316. $form->addHtml('<div id="collapseFour" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingFour">');
  317. $form->addHtml('<div class="panel-body"><p class="text-info">'.get_lang('ThemesObjectifsExplanation').'</p>');
  318. $showOnlyThisFields = [
  319. 'domaine',
  320. 'filiere',
  321. $theme,
  322. ];
  323. $extra = $extraField->addElements(
  324. $form,
  325. '',
  326. [],
  327. false, //filter
  328. true,
  329. $showOnlyThisFields,
  330. $showOnlyThisFields,
  331. $defaults,
  332. false, //$orderDependingDefaults
  333. true, // force
  334. ['domaine' => 3, $theme => 5], // $separateExtraMultipleSelect
  335. [
  336. 'domaine' => [
  337. get_lang('Domaine').' 1',
  338. get_lang('Domaine').' 2',
  339. get_lang('Domaine').' 3',
  340. ],
  341. $theme => [
  342. get_lang('ThemeField').' 1',
  343. get_lang('ThemeField').' 2',
  344. get_lang('ThemeField').' 3',
  345. get_lang('ThemeField').' 4',
  346. get_lang('ThemeField').' 5',
  347. ],
  348. ],
  349. true
  350. );
  351. // Commented because BT#15776
  352. $fieldsToShow = [
  353. 'langue_cible',
  354. ];
  355. $extra = $extraFieldUser->addElements(
  356. $form,
  357. $userToLoad,
  358. [],
  359. $filter,
  360. true,
  361. $fieldsToShow,
  362. $fieldsToShow,
  363. [],
  364. false,
  365. $forceShowFields //$forceShowFields = false
  366. );
  367. $form->addHtml('</div></div></div>');
  368. $form->addHtml('<div class="panel panel-default">');
  369. $form->addHtml('<div class="panel-heading"><input type="checkbox" name="search_using_3" '.$searchChecked3.' />&nbsp;<a role="button" data-toggle="collapse" data-parent="#search_extrafield" href="#collapseFive" aria-expanded="true" aria-controls="collapseFive">'.get_lang('NiveauLangue').'</a></div>');
  370. $form->addHtml('<div id="collapseFive" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingFive">');
  371. $form->addHtml('<div class="panel-body"><p class="text-info">'.get_lang('NiveauLangueExplanation').'</p>');
  372. $showOnlyThisFields = [
  373. 'ecouter',
  374. 'lire',
  375. 'participer_a_une_conversation',
  376. 's_exprimer_oralement_en_continu',
  377. 'ecrire',
  378. ];
  379. $extra = $extraField->addElements(
  380. $form,
  381. '',
  382. [],
  383. false, //filter
  384. true,
  385. $showOnlyThisFields,
  386. $showOnlyThisFields,
  387. $defaults,
  388. false, //$orderDependingDefaults
  389. true, // force
  390. ['domaine' => 3, $theme => 5], // $separateExtraMultipleSelect
  391. [
  392. 'domaine' => [
  393. get_lang('Domaine').' 1',
  394. get_lang('Domaine').' 2',
  395. get_lang('Domaine').' 3',
  396. ],
  397. $theme => [
  398. get_lang('Theme').' 1',
  399. get_lang('Theme').' 2',
  400. get_lang('Theme').' 3',
  401. get_lang('Theme').' 4',
  402. get_lang('Theme').' 5',
  403. ],
  404. ]
  405. );
  406. $form->addHtml('</div></div></div>');
  407. // Enviroment
  408. $userForm->addHtml('<div class="panel panel-default">');
  409. $userForm->addHtml(
  410. '<div class="panel-heading">
  411. <a role="button" data-toggle="collapse" data-parent="#search_extrafield" href="#collapseEight" aria-expanded="true" aria-controls="collapseEight">'.
  412. get_lang('MonEnvironnementDeTravail').'</a></div>');
  413. $userForm->addHtml('<div id="collapseEight" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingEight">');
  414. $userForm->addHtml('<div class="panel-body"><p class="text-info">'.get_lang('MonEnvironnementDeTravailExplanation').'</p>');
  415. $fieldsToShow = [
  416. 'outil_de_travail_ordinateur',
  417. 'outil_de_travail_ordinateur_so',
  418. 'outil_de_travail_tablette',
  419. 'outil_de_travail_tablette_so',
  420. 'outil_de_travail_smartphone',
  421. 'outil_de_travail_smartphone_so',
  422. ];
  423. $userForm->addLabel(null, get_lang('MonEnvironnementDeTravailExplanationIntro1'));
  424. $extra = $extraFieldUser->addElements(
  425. $userForm,
  426. $userToLoad,
  427. [],
  428. $filter,
  429. true,
  430. $fieldsToShow,
  431. $fieldsToShow,
  432. [],
  433. false,
  434. $forceShowFields
  435. );
  436. $userForm->addLabel(null, get_lang('MonEnvironnementDeTravailExplanationIntro2'));
  437. $jqueryExtra .= $extra['jquery_ready_content'];
  438. $fieldsToShow = [
  439. 'browser_platforme',
  440. 'browser_platforme_autre',
  441. 'browser_platforme_version',
  442. ];
  443. $extra = $extraFieldUser->addElements(
  444. $userForm,
  445. $userToLoad,
  446. [],
  447. $filter,
  448. true,
  449. $fieldsToShow,
  450. $fieldsToShow,
  451. [],
  452. false,
  453. $forceShowFields, //$forceShowFields = false
  454. [],
  455. []
  456. );
  457. $jqueryExtra .= $extra['jquery_ready_content'];
  458. $userForm->addHtml('<p class="text-info">'.get_lang('MonEnvironnementDeTravailRenvoiFAQ').'</p>');
  459. $userForm->addButtonSave(get_lang('Save'), 'submit_partial[collapseEight]');
  460. $userForm->addHtml('</div></div></div>');
  461. $form->addButtonSave(get_lang('SaveDiagnosticChanges'), 'save');
  462. $form->addButtonSearch(get_lang('SearchSessions'), 'search');
  463. $extraFieldsToFilter = $extraField->get_all(['variable = ?' => 'temps_de_travail']);
  464. $extraFieldToSearch = [];
  465. if (!empty($extraFieldsToFilter)) {
  466. foreach ($extraFieldsToFilter as $filter) {
  467. $extraFieldToSearch[] = $filter['id'];
  468. }
  469. }
  470. $extraFieldListToString = implode(',', $extraFieldToSearch);
  471. $result = SessionManager::getGridColumns('simple', $extraFieldsToFilter);
  472. $columns = $result['columns'];
  473. $column_model = $result['column_model'];
  474. $form->setDefaults($defaults);
  475. /** @var HTML_QuickForm_select $element */
  476. $domaine1 = $form->getElementByName('extra_domaine[0]');
  477. $domaine2 = $form->getElementByName('extra_domaine[1]');
  478. $domaine3 = $form->getElementByName('extra_domaine[2]');
  479. $userForm->setDefaults($defaults);
  480. $domainList = array_merge(
  481. is_object($domaine1) && !empty($domaine1->getValue()) ? $domaine1->getValue() : [],
  482. is_object($domaine3) && !empty($domaine3->getValue()) ? $domaine3->getValue() : [],
  483. is_object($domaine2) && !empty($domaine2->getValue()) ? $domaine2->getValue() : []
  484. );
  485. $themeList = [];
  486. $extraField = new ExtraField('session');
  487. $resultOptions = $extraField->searchOptionsFromTags('extra_domaine', 'extra_'.$theme, $domainList);
  488. if ($resultOptions) {
  489. $resultOptions = array_column($resultOptions, 'tag', 'id');
  490. $resultOptions = array_filter($resultOptions);
  491. for ($i = 0; $i < 5; $i++) {
  492. /** @var HTML_QuickForm_select $theme */
  493. $themeElement = $form->getElementByName('extra_'.$theme.'['.$i.']');
  494. foreach ($resultOptions as $key => $value) {
  495. $themeElement->addOption($value, $value);
  496. }
  497. }
  498. }
  499. $filterToSend = '';
  500. if ($formSearch->validate()) {
  501. $formSearchParams = $formSearch->getSubmitValues();
  502. }
  503. // Search filter
  504. $filters = [];
  505. foreach ($defaults as $key => $value) {
  506. if (substr($key, 0, 6) != 'extra_' && substr($key, 0, 7) != '_extra_') {
  507. continue;
  508. }
  509. if (!empty($value)) {
  510. $filters[$key] = $value;
  511. }
  512. }
  513. $filterToSend = [];
  514. if (!empty($filters)) {
  515. $filterToSend = ['groupOp' => 'AND'];
  516. if ($filters) {
  517. $count = 1;
  518. $countExtraField = 1;
  519. foreach ($result['column_model'] as $column) {
  520. if ($count > 5) {
  521. if (isset($filters[$column['name']])) {
  522. $defaultValues['jqg'.$countExtraField] = $filters[$column['name']];
  523. /*switch ($column['name']) {
  524. case 'extra_theme_it':
  525. case 'extra_theme_de':
  526. case 'extra_theme_es':
  527. case 'extra_theme_fr':
  528. break;
  529. case 'extra_domaine':
  530. break;
  531. case '':
  532. break;
  533. }*/
  534. $filterToSend['rules'][] = ['field' => $column['name'], 'op' => 'cn', 'data' => $filters[$column['name']]];
  535. }
  536. $countExtraField++;
  537. }
  538. $count++;
  539. }
  540. }
  541. }
  542. $params = [];
  543. if ($form->validate()) {
  544. $params = $form->getSubmitValues();
  545. $save = false;
  546. $search = false;
  547. if (isset($params['search'])) {
  548. unset($params['search']);
  549. $search = true;
  550. }
  551. if (isset($params['save'])) {
  552. $save = true;
  553. unset($params['save']);
  554. }
  555. $form->setDefaults($params);
  556. $filters = [];
  557. // Search
  558. if ($search) {
  559. // Parse params.
  560. foreach ($params as $key => $value) {
  561. if (substr($key, 0, 6) != 'extra_' && substr($key, 0, 7) != '_extra_') {
  562. continue;
  563. }
  564. if (!empty($value)) {
  565. $filters[$key] = $value;
  566. }
  567. }
  568. $filterToSend = [];
  569. if (!empty($filters)) {
  570. $filterToSend = ['groupOp' => 'AND'];
  571. if ($filters) {
  572. $count = 1;
  573. $countExtraField = 1;
  574. foreach ($result['column_model'] as $column) {
  575. if ($count > 5) {
  576. if (isset($filters[$column['name']])) {
  577. $defaultValues['jqg'.$countExtraField] = $filters[$column['name']];
  578. $filterToSend['rules'][] = [
  579. 'field' => $column['name'],
  580. 'op' => 'cn',
  581. 'data' => $filters[$column['name']],
  582. ];
  583. }
  584. $countExtraField++;
  585. }
  586. $count++;
  587. }
  588. }
  589. }
  590. }
  591. if ($save) {
  592. $userData = $params;
  593. // Update extra_heures_disponibilite_par_semaine
  594. $extraFieldValue = new ExtraFieldValue('user');
  595. $userDataToSave = [
  596. 'item_id' => $userToLoad,
  597. 'extra_heures_disponibilite_par_semaine' => isset($userData['extra_heures_disponibilite_par_semaine']) ? $userData['extra_heures_disponibilite_par_semaine'] : '',
  598. 'extra_langue_cible' => isset($userData['extra_langue_cible']) ? $userData['extra_langue_cible'] : '',
  599. ];
  600. $extraFieldValue->saveFieldValues(
  601. $userDataToSave,
  602. true,
  603. false,
  604. ['heures_disponibilite_par_semaine' , 'langue_cible']
  605. );
  606. // Save session search
  607. /** @var \Chamilo\UserBundle\Entity\User $user */
  608. $user = $em->getRepository('ChamiloUserBundle:User')->find($userToLoad);
  609. $extraFieldValueSession = new ExtraFieldValue('session');
  610. $sessionFields = [
  611. 'extra_access_start_date',
  612. 'extra_access_end_date',
  613. 'extra_filiere',
  614. 'extra_domaine',
  615. 'extra_domaine[0]',
  616. 'extra_domaine[1]',
  617. 'extra_domaine[3]',
  618. 'extra_temps_de_travail',
  619. //'extra_competenceniveau',
  620. 'extra_'.$theme,
  621. 'extra_ecouter',
  622. 'extra_lire',
  623. 'extra_participer_a_une_conversation',
  624. 'extra_s_exprimer_oralement_en_continu',
  625. 'extra_ecrire',
  626. ];
  627. foreach ($userData as $key => $value) {
  628. $found = strpos($key, '__persist__');
  629. if ($found === false) {
  630. continue;
  631. }
  632. }
  633. if (isset($userData['extra_filiere_want_stage']) &&
  634. isset($userData['extra_filiere_want_stage']['extra_filiere_want_stage'])
  635. ) {
  636. $wantStage = $userData['extra_filiere_want_stage']['extra_filiere_want_stage'];
  637. if ($wantStage === 'yes') {
  638. if (isset($userData['extra_filiere_user'])) {
  639. $userData['extra_filiere'] = [];
  640. $userData['extra_filiere']['extra_filiere'] = $userData['extra_filiere_user']['extra_filiere_user'];
  641. }
  642. }
  643. }
  644. // save in ExtraFieldSavedSearch.
  645. foreach ($userData as $key => $value) {
  646. if (substr($key, 0, 6) != 'extra_' && substr($key, 0, 7) != '_extra_') {
  647. continue;
  648. }
  649. if (!in_array($key, $sessionFields)) {
  650. continue;
  651. }
  652. $field_variable = substr($key, 6);
  653. $extraFieldInfo = $extraFieldValueSession
  654. ->getExtraField()
  655. ->get_handler_field_info_by_field_variable($field_variable);
  656. if (!$extraFieldInfo) {
  657. continue;
  658. }
  659. $extraFieldObj = $em->getRepository('ChamiloCoreBundle:ExtraField')->find($extraFieldInfo['id']);
  660. $search = [
  661. 'field' => $extraFieldObj,
  662. 'user' => $user,
  663. ];
  664. /** @var ExtraFieldSavedSearch $saved */
  665. $saved = $em->getRepository('ChamiloCoreBundle:ExtraFieldSavedSearch')->findOneBy($search);
  666. if ($saved) {
  667. $saved
  668. ->setField($extraFieldObj)
  669. ->setUser($user)
  670. ->setValue($value)
  671. ;
  672. $em->merge($saved);
  673. } else {
  674. $saved = new ExtraFieldSavedSearch();
  675. $saved
  676. ->setField($extraFieldObj)
  677. ->setUser($user)
  678. ->setValue($value)
  679. ;
  680. $em->persist($saved);
  681. }
  682. $em->flush();
  683. }
  684. Display::addFlash(Display::return_message(get_lang('Saved'), 'success'));
  685. header('Location: '.api_get_self().'?user_id='.$userToLoad);
  686. exit;
  687. }
  688. }
  689. $view = $form->returnForm();
  690. $jsTag = '';
  691. if (!empty($tagsData)) {
  692. foreach ($tagsData as $extraField => $tags) {
  693. foreach ($tags as $tag) {
  694. $tag = api_htmlentities($tag);
  695. }
  696. }
  697. }
  698. $htmlHeadXtra[] = '<script>
  699. $(function() {
  700. '.$jqueryExtra.'
  701. '.$jsTag.'
  702. });
  703. </script>';
  704. if (!empty($filterToSend)) {
  705. if (isset($params['search_using_1'])) {
  706. // Get start and end date from ExtraFieldSavedSearch
  707. $defaultExtraStartDate = isset($defaults['extra_access_start_date']) ? $defaults['extra_access_start_date'] : '';
  708. $defaultExtraEndDate = isset($defaults['extra_access_end_date']) ? $defaults['extra_access_end_date'] : '';
  709. $userStartDate = isset($params['extra_access_start_date']) ? $params['extra_access_start_date'] : $defaultExtraStartDate;
  710. $userEndDate = isset($params['extra_access_end_date']) ? $params['extra_access_end_date'] : $defaultExtraEndDate;
  711. // Minus 3 days
  712. $date = new DateTime($userStartDate);
  713. $date->sub(new DateInterval('P3D'));
  714. $userStartDateMinus = $date->format('Y-m-d h:i:s');
  715. // Plus 2 days
  716. $date = new DateTime($userEndDate);
  717. $date->add(new DateInterval('P2D'));
  718. $userEndDatePlus = $date->format('Y-m-d h:i:s');
  719. // Ofaj fix
  720. $userStartDateMinus = api_get_utc_datetime(substr($userStartDateMinus, 0, 11).'00:00:00');
  721. $userEndDatePlus = api_get_utc_datetime(substr($userEndDatePlus, 0, 11).'23:59:59');
  722. // Special OFAJ date logic
  723. if ($userEndDate == '') {
  724. $sql = " AND (
  725. (s.access_start_date >= '$userStartDateMinus') OR
  726. ((s.access_start_date = '' OR s.access_start_date IS NULL) AND (s.access_end_date = '' OR s.access_end_date IS NULL))
  727. )";
  728. } else {
  729. $sql = " AND (
  730. (s.access_start_date >= '$userStartDateMinus' AND s.access_end_date < '$userEndDatePlus') OR
  731. (s.access_start_date >= '$userStartDateMinus' AND (s.access_end_date = '' OR s.access_end_date IS NULL)) OR
  732. ((s.access_start_date = '' OR s.access_start_date IS NULL) AND (s.access_end_date = '' OR s.access_end_date IS NULL))
  733. )";
  734. }
  735. }
  736. $deleteFiliere = false;
  737. $extraFieldOptions = new ExtraFieldOption('session');
  738. $extraFieldSession = new ExtraField('session');
  739. // Special filters
  740. // see https://task.beeznest.com/issues/10849#change-81902
  741. foreach ($filterToSend['rules'] as &$filterItem) {
  742. if (isset($filterItem['field'])) {
  743. switch ($filterItem['field']) {
  744. case 'extra_filiere':
  745. case 'extra_domaine':
  746. case 'extra_theme_it':
  747. case 'extra_theme_fr':
  748. case 'extra_theme_de':
  749. case 'extra_theme_pl':
  750. if (!isset($params['search_using_2'])) {
  751. $filterItem = null;
  752. }
  753. break;
  754. }
  755. switch ($filterItem['field']) {
  756. case 'extra_ecouter':
  757. case 'extra_lire':
  758. case 'extra_participer_a_une_conversation':
  759. case 'extra_s_exprimer_oralement_en_continu':
  760. case 'extra_ecrire':
  761. if (!isset($params['search_using_3'])) {
  762. $filterItem = null;
  763. break;
  764. }
  765. $selectedValue = '';
  766. $fieldExtra = str_replace('extra_', '', $filterItem['field']);
  767. $extraFieldSessionData = $extraFieldSession->get_handler_field_info_by_field_variable($fieldExtra);
  768. if (is_array($filterItem['data'])) {
  769. $myOrder = [];
  770. foreach ($filterItem['data'] as $option) {
  771. foreach ($extraFieldSessionData['options'] as $optionValue) {
  772. if ($option == $optionValue['option_value']) {
  773. $myOrder[$optionValue['option_order']] = $optionValue['option_value'];
  774. }
  775. }
  776. }
  777. if (!empty($myOrder)) {
  778. // Taking last from list
  779. $selectedValue = end($myOrder);
  780. }
  781. } else {
  782. $selectedValue = $filterItem['data'];
  783. }
  784. $newOptions = array_column(
  785. $extraFieldSessionData['options'],
  786. 'option_value',
  787. 'option_order'
  788. );
  789. $searchOptions = [];
  790. for ($i = 1; $i < count($newOptions); $i++) {
  791. if ($selectedValue == $newOptions[$i]) {
  792. if (isset($newOptions[$i - 1])) {
  793. $searchOptions[] = $newOptions[$i - 1];
  794. }
  795. if (isset($newOptions[$i])) {
  796. $searchOptions[] = $newOptions[$i];
  797. }
  798. if (isset($newOptions[$i + 1])) {
  799. $searchOptions[] = $newOptions[$i + 1];
  800. }
  801. break;
  802. }
  803. }
  804. $filterItem['data'] = $searchOptions;
  805. break;
  806. case 'extra_domaine':
  807. if (!isset($params['search_using_2'])) {
  808. break;
  809. }
  810. // Special condition see:
  811. // https://task.beeznest.com/issues/10849#note-218
  812. // Remove filiere
  813. $list = [
  814. 'vie-quotidienne',
  815. //'competente-dans-mon-domaine-de-specialite',
  816. 'arrivee-sur-mon-poste-de-travail',
  817. ];
  818. $deleteFiliere = false;
  819. if (is_array($filterItem['data'])) {
  820. $myOrder = [];
  821. foreach ($filterItem['data'] as $option) {
  822. if (in_array($option, $list)) {
  823. $deleteFiliere = true;
  824. break;
  825. }
  826. }
  827. } else {
  828. if (in_array($filterItem['data'], $list)) {
  829. $deleteFiliere = true;
  830. }
  831. }
  832. break;
  833. }
  834. }
  835. if ($deleteFiliere) {
  836. foreach ($filterToSend['rules'] as &$filterItem) {
  837. if (isset($filterItem['field']) && $filterItem['field'] == 'extra_filiere') {
  838. $filterItem = [];
  839. }
  840. }
  841. }
  842. }
  843. // Language
  844. $lang = isset($params['extra_langue_cible']) ? $params['extra_langue_cible'] : $defaultLangCible;
  845. $lang = strtolower($lang);
  846. if (isset($params['search_using_1'])) {
  847. if ($userStartDate && !empty($userStartDate)) {
  848. $filterToSend['custom_dates'] = $sql;
  849. }
  850. }
  851. $filterToSend = json_encode($filterToSend);
  852. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_sessions&_search=true&load_extra_field='.
  853. $extraFieldListToString.'&_force_search=true&rows=20&page=1&sidx=&sord=asc&filters2='.$filterToSend;
  854. if (isset($params['search_using_2'])) {
  855. $url .= '&lang='.$lang;
  856. }
  857. } else {
  858. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_sessions&_search=true&load_extra_field='.
  859. $extraFieldListToString.'&_force_search=true&rows=20&page=1&sidx=&sord=asc';
  860. }
  861. // Autowidth
  862. $extra_params['autowidth'] = 'true';
  863. // height auto
  864. $extra_params['height'] = 'auto';
  865. $extra_params['postData'] = [
  866. 'filters' => [
  867. 'groupOp' => 'AND',
  868. 'rules' => $result['rules'],
  869. ],
  870. ];
  871. $sessionByUserList = SessionManager::get_sessions_by_user($userToLoad, true, true);
  872. $sessionUserList = [];
  873. if (!empty($sessionByUserList)) {
  874. foreach ($sessionByUserList as $sessionByUser) {
  875. $sessionUserList[] = (string) $sessionByUser['session_id'];
  876. }
  877. }
  878. $action_links = 'function action_formatter(cellvalue, options, rowObject) {
  879. var sessionList = '.json_encode($sessionUserList).';
  880. var id = options.rowId.toString();
  881. if (sessionList.indexOf(id) == -1) {
  882. return \'<a href="'.api_get_self().'?action=subscribe_user&user_id='.$userToLoad.'&session_id=\'+id+\'">'.Display::return_icon('add.png', addslashes(get_lang('Subscribe')), '', ICON_SIZE_SMALL).'</a>'.'\';
  883. } else {
  884. return \'<a href="'.api_get_self().'?action=unsubscribe_user&user_id='.$userToLoad.'&session_id=\'+id+\'">'.Display::return_icon('delete.png', addslashes(get_lang('Delete')), '', ICON_SIZE_SMALL).'</a>'.'\';
  885. }
  886. }';
  887. $htmlHeadXtra[] = api_get_jqgrid_js();
  888. $griJs = Display::grid_js(
  889. 'sessions',
  890. $url,
  891. $columns,
  892. $column_model,
  893. $extra_params,
  894. [],
  895. $action_links,
  896. true
  897. );
  898. $grid = '<div id="session-table" class="table-responsive">';
  899. $grid .= Display::grid_html('sessions');
  900. $grid .= '</div>';
  901. $htmlHeadXtra[] = '<style>
  902. .control-label {
  903. width: 25% !important;
  904. }
  905. </style>';
  906. $htmlHeadXtra[] = '<script>
  907. $(document).ready(function() {
  908. var blocks = [
  909. "#collapseOne",
  910. "#collapseTwo",
  911. "#collapseThree",
  912. "#collapseFour",
  913. "#collapseFive",
  914. "#collapseSix",
  915. "#collapseSeven",
  916. "#collapseEight"
  917. ];
  918. $.each(blocks, function( index, value ) {
  919. $(value).collapse("hide");
  920. });
  921. });
  922. </script>';
  923. $tpl = new Template(get_lang('Diagnosis'));
  924. if (empty($items)) {
  925. $view = '';
  926. $grid = '';
  927. $griJs = '';
  928. }
  929. $tpl->assign('form', $view);
  930. $tpl->assign('form_search', $formSearch->returnForm().$userForm->returnForm());
  931. $table = new HTML_Table(['class' => 'data_table']);
  932. $column = 0;
  933. $row = 0;
  934. $total = '0';
  935. $sumHours = '0';
  936. $numHours = '0';
  937. $field = 'heures_disponibilite_par_semaine';
  938. $extraField = new ExtraFieldValue('user');
  939. $data = $extraField->get_values_by_handler_and_field_variable($userToLoad, $field);
  940. $availableHoursPerWeek = 0;
  941. function dateDiffInWeeks($date1, $date2)
  942. {
  943. if ($date1 > $date2) {
  944. return dateDiffInWeeks($date2, $date1);
  945. }
  946. $first = new \DateTime($date1);
  947. $second = new \DateTime($date2);
  948. return floor($first->diff($second)->days / 7);
  949. }
  950. if ($data) {
  951. $availableHoursPerWeek = $data['value'];
  952. $numberWeeks = 0;
  953. if ($form->validate()) {
  954. $formData = $form->getSubmitValues();
  955. if (isset($formData['extra_access_start_date']) && isset($formData['extra_access_end_date'])) {
  956. $startDate = $formData['extra_access_start_date'];
  957. $endDate = $formData['extra_access_end_date'];
  958. $numberWeeks = dateDiffInWeeks($startDate, $endDate);
  959. }
  960. } else {
  961. if ($defaults) {
  962. if (isset($defaults['extra_access_start_date']) && isset($defaults['extra_access_end_date'])) {
  963. $startDate = $defaults['extra_access_start_date'];
  964. $endDate = $defaults['extra_access_end_date'];
  965. $numberWeeks = dateDiffInWeeks($startDate, $endDate);
  966. }
  967. }
  968. }
  969. $total = $numberWeeks * $availableHoursPerWeek;
  970. $sessions = SessionManager::getSessionsFollowedByUser($userToLoad);
  971. if ($sessions) {
  972. $sessionFieldValue = new ExtraFieldValue('session');
  973. foreach ($sessions as $session) {
  974. $sessionId = $session['id'];
  975. $data = $sessionFieldValue->get_values_by_handler_and_field_variable(
  976. $sessionId,
  977. 'temps_de_travail'
  978. );
  979. if ($data) {
  980. $sumHours += $data['value'];
  981. }
  982. }
  983. }
  984. }
  985. $numHours = $total - $sumHours;
  986. $headers = [
  987. get_lang('TotalAvailableHours') => $total,
  988. get_lang('SumHoursSessionsSubscribed') => $sumHours,
  989. get_lang('CountHoursAvailable') => $numHours,
  990. ];
  991. foreach ($headers as $header => $value) {
  992. $table->setCellContents($row, 0, $header);
  993. $table->updateCellAttributes($row, 0, 'width="250px"');
  994. $table->setCellContents($row, 1, $value);
  995. $row++;
  996. }
  997. $button = '';
  998. if ($userToLoad) {
  999. $button = Display::url(
  1000. get_lang('OfajEndOfLearnPath'),
  1001. api_get_path(WEB_CODE_PATH).'messages/new_message.php?prefill=ofaj&send_to_user='.$userToLoad,
  1002. ['class' => 'btn btn-default']
  1003. );
  1004. $button .= '<br /><br />';
  1005. }
  1006. $userReportButton = Display::url(
  1007. get_lang('DiagnosticValidateLearningPath'),
  1008. api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?student='.$userToLoad,
  1009. ['class' => 'btn btn-primary']
  1010. );
  1011. $tpl->assign('grid', $grid.$button.$table->toHtml().$userReportButton);
  1012. $tpl->assign('grid_js', $griJs);
  1013. $content = $tpl->fetch('default/user_portal/search_extra_field.tpl');
  1014. $tpl->assign('content', $content);
  1015. $tpl->display_one_col_template();