event_email_template.class.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Class EventEmailTemplate
  5. */
  6. class EventEmailTemplate extends Model
  7. {
  8. public $table;
  9. public $columns = array(
  10. 'id',
  11. 'message',
  12. 'subject',
  13. 'event_type_name',
  14. 'activated',
  15. );
  16. /**
  17. * Constructor
  18. */
  19. public function __construct()
  20. {
  21. $this->table = Database::get_main_table(TABLE_EVENT_EMAIL_TEMPLATE);
  22. }
  23. /**
  24. * @param array $where_conditions
  25. * @return array
  26. */
  27. public function get_all($where_conditions = array())
  28. {
  29. return Database::select(
  30. '*',
  31. $this->table,
  32. array('where' => $where_conditions, 'order' => 'name ASC')
  33. );
  34. }
  35. /**
  36. * Displays the title + grid
  37. */
  38. public function display()
  39. {
  40. // action links
  41. $content = Display::actions(array(
  42. array(
  43. 'url' => 'event_type.php',
  44. 'content' => Display::return_icon(
  45. 'new_document.png',
  46. get_lang('Add'),
  47. array(),
  48. ICON_SIZE_MEDIUM
  49. )
  50. )
  51. )
  52. );
  53. $content .= Display::grid_html('event_email_template');
  54. return $content;
  55. }
  56. /**
  57. * @return array
  58. */
  59. public function get_status_list()
  60. {
  61. return array(
  62. EVENT_EMAIL_TEMPLATE_ACTIVE => get_lang('Enabled'),
  63. EVENT_EMAIL_TEMPLATE_INACTIVE => get_lang('Disabled')
  64. );
  65. }
  66. /**
  67. * Returns a Form validator Obj
  68. * @param string $url
  69. * @param string $action add, edit
  70. *
  71. * @return FormValidator
  72. */
  73. public function return_form($url, $action)
  74. {
  75. $form = new FormValidator('career', 'post', $url);
  76. // Setting the form elements
  77. $header = get_lang('Add');
  78. if ($action == 'edit') {
  79. $header = get_lang('Modify');
  80. }
  81. $form->addElement('header', $header);
  82. $id = isset($_GET['id']) ? intval($_GET['id']) : '';
  83. $form->addElement('hidden', 'id', $id);
  84. $form->addElement('text', 'name', get_lang('Name'), array('size' => '70'));
  85. $form->addHtmlEditor(
  86. 'description',
  87. get_lang('Description'),
  88. false,
  89. false,
  90. array(
  91. 'ToolbarSet' => 'careers',
  92. 'Width' => '100%',
  93. 'Height' => '250',
  94. )
  95. );
  96. $status_list = $this->get_status_list();
  97. $form->addElement('select', 'status', get_lang('Status'), $status_list);
  98. if ($action == 'edit') {
  99. $form->addElement('text', 'created_at', get_lang('CreatedAt'));
  100. $form->freeze('created_at');
  101. }
  102. if ($action == 'edit') {
  103. $form->addButtonSave(get_lang('Modify'), 'submit');
  104. } else {
  105. $form->addButtonCreate(get_lang('Add'), 'submit');
  106. }
  107. // Setting the defaults
  108. $defaults = $this->get($id);
  109. if (!empty($defaults['created_at'])) {
  110. $defaults['created_at'] = api_convert_and_format_date($defaults['created_at']);
  111. }
  112. if (!empty($defaults['updated_at'])) {
  113. $defaults['updated_at'] = api_convert_and_format_date($defaults['updated_at']);
  114. }
  115. $form->setDefaults($defaults);
  116. // Setting the rules
  117. $form->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
  118. return $form;
  119. }
  120. public function get_count()
  121. {
  122. $row = Database::select('count(*) as count', $this->table, array(), 'first');
  123. return $row['count'];
  124. }
  125. }