userform.class.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Class UserForm
  5. * Extends formvalidator with import and export forms.
  6. *
  7. * @author Stijn Konings
  8. *
  9. * @package chamilo.gradebook
  10. */
  11. class UserForm extends FormValidator
  12. {
  13. public const TYPE_USER_INFO = 1;
  14. public const TYPE_SIMPLE_SEARCH = 3;
  15. /**
  16. * Builds a form containing form items based on a given parameter.
  17. *
  18. * @param int form_type 1 = user_info
  19. * @param user array
  20. * @param string form name
  21. * @param string $method
  22. * @param string $action
  23. */
  24. public function __construct($form_type, $user, $form_name, $method = 'post', $action = null)
  25. {
  26. parent::__construct($form_name, $method, $action);
  27. $this->form_type = $form_type;
  28. if (isset($user)) {
  29. $this->user_info = $user;
  30. }
  31. if (isset($result_object)) {
  32. $this->result_object = $result_object;
  33. }
  34. if ($this->form_type == self::TYPE_USER_INFO) {
  35. $this->build_user_info_form();
  36. } elseif ($this->form_type == self::TYPE_SIMPLE_SEARCH) {
  37. $this->build_simple_search();
  38. }
  39. $this->setDefaults();
  40. }
  41. public function display()
  42. {
  43. parent::display();
  44. }
  45. public function setDefaults($defaults = [], $filter = null)
  46. {
  47. parent::setDefaults($defaults, $filter);
  48. }
  49. protected function build_simple_search()
  50. {
  51. if (isset($_GET['search']) && (!empty($_GET['search']))) {
  52. $this->setDefaults([
  53. 'keyword' => Security::remove_XSS($_GET['search']),
  54. ]);
  55. }
  56. $renderer = &$this->defaultRenderer();
  57. $renderer->setCustomElementTemplate('<span>{element}</span> ');
  58. $this->addElement('text', 'keyword', '');
  59. $this->addButtonSearch(get_lang('Search'), 'submit');
  60. }
  61. protected function build_user_info_form()
  62. {
  63. if (api_is_western_name_order()) {
  64. $this->addElement('static', 'fname', get_lang('First name'), $this->user_info['firstname']);
  65. $this->addElement('static', 'lname', get_lang('Last name'), $this->user_info['lastname']);
  66. } else {
  67. $this->addElement('static', 'lname', get_lang('Last name'), $this->user_info['lastname']);
  68. $this->addElement('static', 'fname', get_lang('First name'), $this->user_info['firstname']);
  69. }
  70. $this->addElement('static', 'uname', get_lang('Username'), $this->user_info['username']);
  71. $this->addElement(
  72. 'static',
  73. 'email',
  74. get_lang('e-mail'),
  75. '<a href="mailto:'.$this->user_info['email'].'">'.$this->user_info['email'].'</a>'
  76. );
  77. $this->addElement('static', 'ofcode', get_lang('Code'), $this->user_info['official_code']);
  78. $this->addElement('static', 'phone', get_lang('Phone'), $this->user_info['phone']);
  79. $this->addButtonSave(get_lang('Back'), 'submit');
  80. }
  81. }