event_email_template.class.php 3.3 KB

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