search.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use \ChamiloSession as Session;
  4. /**
  5. * Search user certificates if them are publics
  6. * @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
  7. * @package chamilo.gradebook
  8. */
  9. $cidReset = true;
  10. if (api_get_setting('course.allow_public_certificates') != 'true') {
  11. api_not_allowed(
  12. true,
  13. Display::return_message(get_lang('CertificatesNotPublic'), 'warning')
  14. );
  15. }
  16. $userId = isset($_GET['id']) ? intval($_GET['id']) : 0;
  17. $userList = $userInfo = $courseList = $sessionList = [];
  18. $searchForm = new FormValidator('search_form', 'post', null, null);
  19. $searchForm->addText('firstname', get_lang('FirstName'));
  20. $searchForm->addText('lastname', get_lang('LastName'));
  21. $searchForm->addButtonSearch();
  22. if ($searchForm->validate()) {
  23. $firstname = $searchForm->getSubmitValue('firstname');
  24. $lastname = $searchForm->getSubmitValue('lastname');
  25. $userList = UserManager::getUserByName($firstname, $lastname);
  26. if (empty($userList)) {
  27. Display::addFlash(
  28. Display::return_message(get_lang('NoResults'), 'warning')
  29. );
  30. header('Location: '.api_get_self());
  31. exit;
  32. }
  33. } elseif ($userId > 0) {
  34. $userInfo = api_get_user_info($userId);
  35. if (empty($userInfo)) {
  36. Display::addFlash(
  37. Display::return_message(get_lang('NoUser'), 'warning')
  38. );
  39. header('Location: '.api_get_self());
  40. exit;
  41. }
  42. $courseList = GradebookUtils::getUserCertificatesInCourses($userId, false);
  43. $sessionList = GradebookUtils::getUserCertificatesInSessions($userId, false);
  44. if (empty($courseList) && empty($sessionList)) {
  45. Display::addFlash(
  46. Display::return_message(
  47. sprintf(get_lang('TheUserXNotYetAchievedCertificates'), $userInfo['complete_name']),
  48. 'warning'
  49. )
  50. );
  51. header('Location: '.api_get_self());
  52. exit;
  53. }
  54. }
  55. //$template = new Template(get_lang('SearchCertificates'));
  56. $template = \Chamilo\CoreBundle\Framework\Container::getTwig();
  57. $template->addGlobal('search_form', $searchForm->returnForm());
  58. $template->addGlobal('user_list', $userList);
  59. $template->addGlobal('user_info', $userInfo);
  60. $template->addGlobal('course_list', $courseList);
  61. $template->addGlobal('session_list', $sessionList);
  62. $template->addGlobal('header', get_lang('SearchCertificates'));
  63. echo $template->render('@template_style/gradebook/search.html.twig');