search.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. Session::write('message', Display::return_message(get_lang('NoResults'), 'warning'));
  29. Header::location(api_get_self());
  30. }
  31. } elseif ($userId > 0) {
  32. $userInfo = api_get_user_info($userId);
  33. if (empty($userInfo)) {
  34. Session::write('message', Display::return_message(get_lang('NoUser'), 'warning'));
  35. Header::location(api_get_self());
  36. }
  37. $courseList = GradebookUtils::getUserCertificatesInCourses($userId, false);
  38. $sessionList = GradebookUtils::getUserCertificatesInSessions($userId, false);
  39. if (empty($courseList) && empty($sessionList)) {
  40. Session::write(
  41. 'message',
  42. Display::return_message(
  43. sprintf(get_lang('TheUserXNotYetAchievedCertificates'), $userInfo['complete_name']),
  44. 'warning'
  45. )
  46. );
  47. Header::location(api_get_self());
  48. }
  49. }
  50. $template = new Template(get_lang('SearchCertificates'));
  51. $template->assign('search_form', $searchForm->returnForm());
  52. $template->assign('user_list', $userList);
  53. $template->assign('user_info', $userInfo);
  54. $template->assign('course_list', $courseList);
  55. $template->assign('session_list', $sessionList);
  56. if (Session::has('message')) {
  57. $template->assign('message', Session::read('message'));
  58. Session::erase('message');
  59. }
  60. $content = $template->fetch('default/gradebook/search.tpl');
  61. $template->assign('header', get_lang('SearchCertificates'));
  62. $template->assign('content', $content);
  63. $template->display_one_col_template();