search.php 2.6 KB

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