search.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Search user certificates if them are publics
  5. * @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
  6. * @package chamilo.gradebook
  7. */
  8. $cidReset = true;
  9. require_once __DIR__.'/../inc/global.inc.php';
  10. if (api_get_setting('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::getUsersByName($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(
  44. $userId,
  45. false
  46. );
  47. if (empty($courseList) && empty($sessionList)) {
  48. Display::addFlash(
  49. Display::return_message(
  50. sprintf(
  51. get_lang('TheUserXNotYetAchievedCertificates'),
  52. $userInfo['complete_name']
  53. ),
  54. 'warning'
  55. )
  56. );
  57. header('Location: '.api_get_self());
  58. exit;
  59. }
  60. }
  61. $template = new Template(get_lang('SearchCertificates'));
  62. $template->assign('search_form', $searchForm->returnForm());
  63. $template->assign('user_list', $userList);
  64. $template->assign('user_info', $userInfo);
  65. $template->assign('course_list', $courseList);
  66. $template->assign('session_list', $sessionList);
  67. $templateName = $template->get_template('gradebook/search.tpl');
  68. $content = $template->fetch($templateName);
  69. $template->assign('header', get_lang('SearchCertificates'));
  70. $template->assign('content', $content);
  71. $template->display_one_col_template();