event_email_template.class.php 3.5 KB

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