search.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. use \ChamiloSession as Session;
  9. $cidReset = true;
  10. require_once '../inc/global.inc.php';
  11. if (api_get_setting('allow_public_certificates') != 'true') {
  12. api_not_allowed(
  13. true,
  14. Display::return_message(get_lang('CertificatesNotPublic'), 'warning')
  15. );
  16. }
  17. $userId = isset($_GET['id']) ? intval($_GET['id']) : 0;
  18. $userList = $userInfo = $courseList = $sessionList = [];
  19. $searchForm = new FormValidator('search_form', 'post', null, null);
  20. $searchForm->addText('firstname', get_lang('FirstName'));
  21. $searchForm->addText('lastname', get_lang('LastName'));
  22. $searchForm->addButtonSearch();
  23. if ($searchForm->validate()) {
  24. $firstname = $searchForm->getSubmitValue('firstname');
  25. $lastname = $searchForm->getSubmitValue('lastname');
  26. $userList = UserManager::getUserByName($firstname, $lastname);
  27. if (empty($userList)) {
  28. Display::addFlash(
  29. Display::return_message(get_lang('NoResults'), 'warning')
  30. );
  31. header('Location: '.api_get_self());
  32. exit;
  33. }
  34. } elseif ($userId > 0) {
  35. $userInfo = api_get_user_info($userId);
  36. if (empty($userInfo)) {
  37. Display::addFlash(
  38. Display::return_message(get_lang('NoUser'), 'warning')
  39. );
  40. header('Location: '.api_get_self());
  41. exit;
  42. }
  43. $courseList = GradebookUtils::getUserCertificatesInCourses($userId, false);
  44. $sessionList = GradebookUtils::getUserCertificatesInSessions($userId, false);
  45. if (empty($courseList) && empty($sessionList)) {
  46. Display::addFlash(
  47. Display::return_message(
  48. sprintf(get_lang('TheUserXNotYetAchievedCertificates'), $userInfo['complete_name']),
  49. 'warning'
  50. )
  51. );
  52. header('Location: '.api_get_self());
  53. exit;
  54. }
  55. }
  56. $template = new Template(get_lang('SearchCertificates'));
  57. $template->assign('search_form', $searchForm->returnForm());
  58. $template->assign('user_list', $userList);
  59. $template->assign('user_info', $userInfo);
  60. $template->assign('course_list', $courseList);
  61. $template->assign('session_list', $sessionList);
  62. $content = $template->fetch('default/gradebook/search.tpl');
  63. $template->assign('header', get_lang('SearchCertificates'));
  64. $template->assign('content', $content);
  65. $template->display_one_col_template();