userform.class.php 2.8 KB

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