maillog.module 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <?php
  2. /**
  3. * @file
  4. * Provides a 'maillog' node type
  5. *
  6. * @todo: better implementation of detail link
  7. *
  8. *
  9. * Extensibility of maillog engines is based on the mimemail engine hooks.
  10. * See mimemail_get_engines in mimemail.module with
  11. * Please install mimemail to make the outgoing engine pluggable.
  12. *
  13. * mail flow:
  14. * drupal_mail -> maillog:drupal_mail_wrapper -> maillog_mail_send
  15. * mimemail -> maillog_mailengine -> maillog_mail_send [-> ANY_engine]
  16. */
  17. /**
  18. * Implementation of hook_permision().
  19. */
  20. function maillog_permission() {
  21. return array('view maillog' => array(
  22. 'title' => t('View Maillog'),
  23. 'description' => t('Allow users to view a list of recently logged mails.'),
  24. ),
  25. 'delete maillog' => array(
  26. 'title' => t('Delete Entries from the log'),
  27. 'description' => t('Allow users to delete logged mails.'),
  28. ),
  29. 'administer maillog' => array(
  30. 'title' => t('Administer Maillog'),
  31. 'description' => t('Allow users to change maillog seetings.'),
  32. )
  33. );
  34. }
  35. function maillog_maillog_delete($maillog) {
  36. $idmaillog = $maillog['idmaillog'];
  37. $result = db_query("DELETE FROM {maillog} WHERE idmaillog = :id", array(':id' => $idmaillog));
  38. if ($result == FALSE) {
  39. drupal_set_message(t('A Problem occured when deleting Mail with idmaillog !idmaillog !', array('!idmaillog' => $idmaillog)));
  40. }
  41. else {
  42. drupal_set_message(t('Mail with idmaillog !idmaillog has been deleted!', array('!idmaillog' => $idmaillog)));
  43. }
  44. drupal_goto('admin/reports/maillog');
  45. }
  46. /**
  47. * Implementation of hook_menu().
  48. */
  49. function maillog_menu() {
  50. $items = array();
  51. $items['admin/config/development/maillog'] = array(
  52. 'title' => t('Maillog Settings'),
  53. 'description' => t('Configure the settings of Maillog module.'),
  54. 'page callback' => 'drupal_get_form',
  55. 'page arguments' => array('maillog_admin_settings'),
  56. 'access arguments' => array('administer maillog'),
  57. 'type' => MENU_NORMAL_ITEM,
  58. );
  59. $items['maillog/delete/%maillog_maillog'] = array(
  60. 'title' => t("Delete Maillog from 'maillog' Table"),
  61. 'description' => t("Delete the Maillog with the idmaillog given by the parameter from 'maillog' Table"),
  62. 'page callback' => 'maillog_maillog_delete',
  63. 'page arguments' => array(2),
  64. 'access arguments' => array('delete maillog'),
  65. 'type' => MENU_CALLBACK,
  66. );
  67. $items['maillog/details/%maillog_maillog'] = array(
  68. 'title callback' => 'maillog_maillog_title',
  69. 'title arguments' => array(2),
  70. 'description' => t("Delete the Maillog with the idmaillog given by the parameter from 'maillog' Table"),
  71. 'page callback' => 'maillog_maillog_page',
  72. 'page arguments' => array(2),
  73. 'access arguments' => array('view maillog'),
  74. 'type' => MENU_CALLBACK,
  75. );
  76. return $items;
  77. }
  78. /**
  79. *
  80. */
  81. function maillog_maillog_title($maillog) {
  82. return $maillog['subject'];
  83. }
  84. /**
  85. *
  86. */
  87. function maillog_maillog_load($idmaillog) {
  88. $result = db_query("SELECT idmaillog, header_from, header_to, header_reply_to, header_all, subject, body FROM {maillog} WHERE idmaillog=:id", array(
  89. ':id' => $idmaillog,
  90. ));
  91. if ($result == FALSE) {
  92. $maillog = NULL;
  93. }
  94. else {
  95. $maillog = $result->fetchAssoc();
  96. // unserialize values
  97. $maillog['header_all'] = unserialize($maillog['header_all']);
  98. }
  99. return $maillog;
  100. }
  101. /**
  102. *
  103. */
  104. function maillog_maillog_page($maillog) {
  105. return theme('maillog', array('maillog' => $maillog));
  106. }
  107. /**
  108. * Implementation of the module settings form.
  109. */
  110. function maillog_admin_settings() {
  111. $form = array();
  112. $form['maillog_send'] = array(
  113. '#type' => 'checkbox',
  114. '#title' => t("Allow the e-mails to be sent."),
  115. '#default_value' => variable_get('maillog_send', TRUE),
  116. );
  117. $form['maillog_log'] = array(
  118. '#type' => 'checkbox',
  119. '#title' => t("Create table entries in maillog table for each e-mail."),
  120. '#default_value' => variable_get('maillog_log', TRUE),
  121. );
  122. $form['maillog_devel'] = array(
  123. '#type' => 'checkbox',
  124. '#title' => t("Display the e-mails on page using devel module (if enabled)."),
  125. '#default_value' => variable_get('maillog_devel', TRUE),
  126. );
  127. if (module_exists('mimemail')) {
  128. $engines = mimemail_get_engines();
  129. // maillog will be unset, because ist would cause an recursion
  130. unset($engines['maillog']);
  131. $form['maillog_engine'] = array(
  132. '#type' => 'select',
  133. '#title' => t("Select the mailengine which should be used."),
  134. '#default_value' => variable_get('maillog_engine', 'mimemail'),
  135. '#options' => $engines,
  136. );
  137. }
  138. return system_settings_form($form);
  139. }
  140. /**
  141. * Implementation of hook_views_api().
  142. */
  143. function maillog_views_api() {
  144. return array(
  145. 'api' => 3,
  146. 'path' => drupal_get_path('module', 'maillog') . '/includes/',
  147. );
  148. }
  149. /**
  150. * Implementation of hook_theme().
  151. */
  152. function maillog_theme() {
  153. return array(
  154. 'maillog_header_from' => array(
  155. 'variables' => array('header_from' => NULL),
  156. ),
  157. 'maillog_header_to' => array(
  158. 'variables' => array('header_to' => NULL),
  159. ),
  160. 'maillog_header_reply_to' => array(
  161. 'variables' => array('header_reply_to' => NULL),
  162. ),
  163. 'maillog_header_all' => array(
  164. 'variables' => array('header_all' => NULL),
  165. ),
  166. 'maillog_body' => array(
  167. 'variables' => array('body' => NULL),
  168. ),
  169. 'maillog' => array(
  170. 'variables' => array('maillog' => NULL),
  171. ),
  172. );
  173. }
  174. /**
  175. * Render the 'From' field in the node type 'Logged Mail'
  176. */
  177. function theme_maillog_header_from($variables) {
  178. $output = '';
  179. $output .= '<div class="field mail-log-header-from">';
  180. $output .= '<div class="field-label">' . t('From') . ':</div>';
  181. $output .= '<div class="field-item">' . check_plain($variables['header_from']) . '</div>';
  182. $output .= '</div>';
  183. return $output;
  184. }
  185. /**
  186. *
  187. */
  188. function theme_maillog($variables) {
  189. $output = theme( 'maillog_header_from', array('header_from' => $variables['maillog']['header_from']) );
  190. $output .= theme( 'maillog_header_to', array('header_to' => $variables['maillog']['header_to']) );
  191. $output .= theme( 'maillog_header_reply_to', array('header_reply_to' => $variables['maillog']['header_reply_to']) );
  192. $output .= theme( 'maillog_header_all', array('header_all' => $variables['maillog']['header_all']) );
  193. $output .= theme( 'maillog_body', array('body' => $variables['maillog']['body']) );
  194. return $output;
  195. }
  196. /**
  197. * Render the 'To' field in the node type 'Logged Mail'
  198. */
  199. function theme_maillog_header_to($variables) {
  200. $output = '';
  201. $output .= '<div class="field mail-log-header-to">';
  202. $output .= '<div class="field-label">' . t('To') . ':</div>';
  203. $output .= '<div class="field-item">' . check_plain($variables['header_to']) . '</div>';
  204. $output .= '</div>';
  205. return $output;
  206. }
  207. /**
  208. * Render the 'Reply-To' field in the node type 'Logged Mail'
  209. */
  210. function theme_maillog_header_reply_to($variables) {
  211. $output = '';
  212. $output .= '<div class="field mail-log-header-reply-to">';
  213. $output .= '<div class="field-label">' . t('Reply To') . ':</div>';
  214. $output .= '<div class="field-item">' . check_plain($variables['header_reply_to']) . '</div>';
  215. $output .= '</div>';
  216. return $output;
  217. }
  218. /**
  219. * Render the 'Header' field in the node type 'Logged Mail'
  220. */
  221. function theme_maillog_header_all($variables) {
  222. $output = '';
  223. $output .= '<div class="field mail-log-header-all">';
  224. $output .= '<div class="field-label">' . t('Header') . ':</div>';
  225. $output .= '<div class="field-item">';
  226. foreach ($variables['header_all'] as $header_all_name => $header_all_value) {
  227. $output .= '<div class="mail-log-header-all-subitem">';
  228. $output .= check_plain($header_all_name) . ': ' . check_plain($header_all_value);
  229. $output .= '</div>';
  230. }
  231. $output .= '</div>';
  232. $output .= '</div>';
  233. return $output;
  234. }
  235. /**
  236. * Render the 'Body' field in the node type 'Logged Mail'
  237. */
  238. function theme_maillog_body($variables) {
  239. $output = '';
  240. $output .= '<div class="field mail-log-body">';
  241. $output .= '<div class="field-label">' . t('Body') . ':</div>';
  242. $output .= '<div class="field-item">';
  243. $output .= '<pre>';
  244. $output .= check_plain($variables['body']);
  245. $output .= '</pre>';
  246. $output .= '</div>';
  247. $output .= '</div>';
  248. return $output;
  249. }