userform.class.php 2.8 KB

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