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. $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::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->assign('search_form', $searchForm->returnForm());
  57. $template->assign('user_list', $userList);
  58. $template->assign('user_info', $userInfo);
  59. $template->assign('course_list', $courseList);
  60. $template->assign('session_list', $sessionList);
  61. $templateName = $template->get_template('gradebook/search.tpl');
  62. $content = $template->fetch($templateName);
  63. $template->assign('header', get_lang('SearchCertificates'));
  64. $template->assign('content', $content);
  65. $template->display_one_col_template();