/[drupal]/contributions/modules/autoresponder/autoresponder.module
ViewVC logotype

Contents of /contributions/modules/autoresponder/autoresponder.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.7 - (show annotations) (download) (as text)
Tue May 1 19:12:12 2007 UTC (2 years, 6 months ago) by antinomia
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--1, DRUPAL-4-7
Changes since 1.6: +536 -507 lines
File MIME type: text/x-php
First pass at update to Drupal 5, moved administrative pages from /admin/autoresponder to /admin/settings/autoresponder.
1 <?php
2
3 $Id$
4
5 function autoresponder_perm() {
6 return array('configure autoresponder');
7 }
8
9 function autoresponder_menu($may_cache) {
10 $items = array();
11 if ($may_cache) {
12 global $user;
13 $items[] = array(
14 'path' => 'autoresponder/unsubscribe',
15 'access' => user_access('configure autoresponder'),
16 'callback' => 'autoresponder_unsubscribe'
17 );
18
19 $items[] = array(
20 'path' => 'admin/settings/autoresponder', 'title' => t('Autoresponder'),
21 'access' => user_access('configure autoresponder'),
22 'callback' => 'autoresponder_user_list'
23 );
24 $items[] = array(
25 'path' => 'admin/settings/autoresponder/user/list', 'title' => t('Users list'),
26 'access' => user_access('configure autoresponder'),
27 'type' => MENU_DEFAULT_LOCAL_TASK,
28 'callback' => 'autoresponder_user_list',
29 'weight' => 0
30 );
31 $items[] = array(
32 'path' => 'admin/settings/autoresponder/user/edit',
33 'access' => user_access('configure autoresponder'),
34 'callback' => 'autoresponder_user_list',
35 'type' => MENU_CALLBACK,
36 'weight' => 1
37 );
38 $items[] = array(
39 'path' => 'admin/settings/autoresponder/user/delete',
40 'access' => user_access('configure autoresponder'),
41 'callback' => 'autoresponder_user_list',
42 'type' => MENU_CALLBACK,
43 );
44
45 $items[] = array(
46 'path' => 'admin/settings/autoresponder/mail/list', 'title' => t('Messages list'),
47 'access' => user_access('configure autoresponder'),
48 'type' => MENU_LOCAL_TASK,
49 'callback' => 'autoresponder_mail_list',
50 'weight' => 2
51 );
52 $items[] = array(
53 'path' => 'admin/settings/autoresponder/mail/add', 'title' => t('Add message'),
54 'access' => user_access('configure autoresponder'),
55 'callback' => 'autoresponder_mail_list',
56 'type' => MENU_LOCAL_TASK,
57 'weight' => 3
58 );
59 $items[] = array(
60 'path' => 'admin/settings/autoresponder/mail/edit',
61 'access' => user_access('configure autoresponder'),
62 'callback' => 'autoresponder_mail_list',
63 'type' => MENU_CALLBACK,
64 );
65 $items[] = array(
66 'path' => 'admin/settings/autoresponder/mail/delete',
67 'access' => user_access('configure autoresponder'),
68 'callback' => 'autoresponder_mail_list',
69 'type' => MENU_CALLBACK,
70 );
71 $items[] = array(
72 'path' => 'admin/settings/autoresponder/set/list', 'title' => t('Sets list'),
73 'access' => user_access('configure autoresponder'),
74 'type' => MENU_LOCAL_TASK,
75 'callback' => 'autoresponder_set_list',
76 'weight' => 4
77 );
78
79 $items[] = array(
80 'path' => 'admin/settings/autoresponder/set/add', 'title' => t('Add set'),
81 'access' => user_access('configure autoresponder'),
82 'callback' => 'autoresponder_set_list',
83 'type' => MENU_LOCAL_TASK,
84 'weight' => 5
85 );
86 $items[] = array(
87 'path' => 'admin/settings/autoresponder/set/activate',
88 'access' => user_access('configure autoresponder'),
89 'callback' => 'autoresponder_set_list',
90 'type' => MENU_CALLBACK,
91 );
92 $items[] = array(
93 'path' => 'admin/settings/autoresponder/set/deactivate',
94 'access' => user_access('configure autoresponder'),
95 'callback' => 'autoresponder_set_list',
96 'type' => MENU_CALLBACK,
97 );
98 $items[] = array(
99 'path' => 'admin/settings/autoresponder/set/edit',
100 'access' => user_access('configure autoresponder'),
101 'callback' => 'autoresponder_set_list',
102 'type' => MENU_CALLBACK,
103 );
104 $items[] = array(
105 'path' => 'admin/settings/autoresponder/set/delete',
106 'access' => user_access('configure autoresponder'),
107 'callback' => 'autoresponder_set_list',
108 'type' => MENU_CALLBACK,
109 );
110 $items[] = array(
111 'path' => 'admin/settings/autoresponder/status', 'title' => t('Status'),
112 'access' => user_access('configure autoresponder'),
113 'callback' => 'autoresponder_status',
114 'type' => MENU_LOCAL_TASK,
115 'weight' => 6
116 );
117 }
118 return $items;
119 }
120
121 function autoresponder_status() {
122 return drupal_get_form('autoresponder_status_form');
123 }
124
125 function autoresponder_status_form() {
126 $emails_sent = variable_get('emails_sent', time());
127 $date = date("F j, Y, g:i a", $emails_sent);
128 $form['status'] = array(
129 '#type' => 'fieldset',
130 '#title' => t('Status'),
131 );
132 $form['status']['emails_sent'] = array(
133 '#value' => 'Last mailing time: <i>'.$date.'</i><br /><br />'
134 );
135 $form['status']['send'] = array(
136 '#type' => 'submit',
137 '#value' => t('Send manually')
138 );
139 return $form;
140 }
141
142 function autoresponder_status_form_submit($form_id, $form_values) {
143 variable_set('emails_sent', 0);
144 autoresponder_cron();
145 drupal_set_message('E-Mails successfully sent!');
146 }
147
148 function autoresponder_unsubscribe() {
149 $id = arg(2);
150 if ($id) {
151 $result = db_query("SELECT a.*, at.name, au.email
152 FROM autoresponder AS a
153 LEFT JOIN autoresponder_sets AS at ON a.setid = at.id
154 LEFT JOIN autoresponder_users AS au ON a.uid = au.id
155 WHERE au.id = %d
156 LIMIT 1
157 ", $id);
158 $us = db_fetch_object($result);
159 if (db_num_rows($result) > 0) {
160 $form['id'] = array(
161 '#type' => 'hidden',
162 '#value' => arg(2)
163 );
164 $form['email'] = array(
165 '#type' => 'hidden',
166 '#value' => $us->email
167 );
168 $form['set'] = array(
169 '#type' => 'hidden',
170 '#value' => $us->name
171 );
172 return confirm_form(
173 'theme_user_unsubscribe_confirm', $form,
174 t('Are you sure you want to unsubscribe \'<i>'.$us->email.'</i>\' from mailing list \'<i>'.$us->name.'</i>\'?'),
175 '',
176 t('This action cannot be undone. '),
177 t('Unsubscribe'), t('Cancel'));
178 }
179 else
180 drupal_goto();
181 }
182 else
183 drupal_goto();
184 }
185
186 function autoresponder_cron() {
187 $messages_count = 0;
188 $user_count = 0;
189 $emails_sent = variable_get('emails_sent', 0);
190 if ((time() - $emails_sent) > (60*60*24) || $emails_sent == 0) {
191 $result_users = db_query("SELECT a.*, at.name, au.email, au.reg_date
192 FROM {autoresponder} AS a
193 LEFT JOIN {autoresponder_sets} AS at ON a.setid = at.id
194 LEFT JOIN {autoresponder_users} AS au ON a.uid = au.id
195 WHERE at.active = 1
196 ");
197 while ($u = db_fetch_array($result_users)) {
198 $tmp = (time() - $u['reg_date']) / (60*60*24);
199 $day = floor($tmp);
200 if (!$day)
201 continue;
202 $result_messages = db_query("SELECT *
203 FROM {autoresponder_messages}
204 WHERE day = %d AND mset= %d
205 ", $day, $u['setid']);
206 while ($message = db_fetch_array($result_messages)) {
207 if (autoresponder_mail($u, $message))
208 $messages_count = $messages_count + 1;
209 }
210 $user_count = $user_count + 1;
211 }
212 variable_set('emails_sent', time());
213 watchdog('autoresponder', 'Mass mailing: '.$messages_count.' e-mail(s) sent to '.$user_count.' user(s)');
214 }
215 }
216
217 function autoresponder_mail($u, $message) {
218 srand(time());
219 $to = $u['email'];
220 $from = variable_get('site_mail', ini_get('sendmail_from'));
221 $subject = $message['subject'];
222 $mime_boundary = "==Multipart_Boundary_x".md5(mt_rand())."x";
223 $url = url('autoresponder/unsubscribe/'.$u['uid'], NULL, NULL, TRUE);
224 $unsubscribe_text = "-------------------------\nTo unsubscribe from the list follow this link $url".
225 $unsubscribe_html = "<small>-------------------------<br />To unsubscribe from the list follow this link <a href='$url'>$url</a></small>";
226 $headers = "From: $from\r\n" .
227 "MIME-Version: 1.0\r\n" .
228 "Content-Type:multipart/alternative;\n" .
229 " boundary=\"{$mime_boundary}\r\n\"";
230 $headers.= "From: $from\r\n";
231 $text = "This is a multi-part message in MIME format.\n\n" .
232 "--{$mime_boundary}\n" .
233 "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
234 "Content-Transfer-Encoding: 7bit\n\n" .
235 strip_tags($message['body'])."\n".$unsubscribe_text."\n".
236 "--{$mime_boundary}\n" .
237 "Content-Type: text/html; charset=\"iso-8859-1\"\n" .
238 "Content-Transfer-Encoding: 7bit\n\n" .
239 $message['body']."\n".$unsubscribe_html."\n";
240
241 return mail($to, $subject, $text, $headers);
242 }
243
244
245 function autoresponder_user_list() {
246 switch (arg(4)) {
247 case 'delete':
248 return drupal_get_form('autoresponder_user_delete_confirm');
249 }
250
251 $output .= drupal_get_form('autoresponder_user_list_form', $form);
252 return $output;
253 }
254
255 function autoresponder_user_delete_confirm() {
256 $result = db_query("SELECT *
257 FROM {autoresponder_users}
258 WHERE id = %d
259 LIMIT 1", arg(5));
260 $us = db_fetch_object($result);
261 $form['id'] = array(
262 '#type' => 'hidden',
263 '#value' => arg(5)
264 );
265 $form['email'] = array(
266 '#type' => 'hidden',
267 '#value' => $us->email
268 );
269 return confirm_form($form,
270 t('Are you sure you want to delete \'<i>'.$us->email.'</i>\'?'),
271 'admin/settings/autoresponder/user/list', t('This action cannot be undone. '),
272 t('Delete'), t('Cancel'));
273 }
274
275 function autoresponder_user_list_form() {
276 $result = db_query("SELECT a.*, at.name, au.email, au.reg_date
277 FROM autoresponder AS a
278 LEFT JOIN autoresponder_sets AS at ON a.setid = at.id
279 LEFT JOIN autoresponder_users AS au ON a.uid = au.id
280 ");
281 while ($us = db_fetch_object($result)) {
282 $date = date("m.d.y", $us->reg_date);
283 $tmp = (time() - $us->reg_date) / (60*60*24);
284 $day = floor($tmp);
285 $rows[$us->uid] = array(
286 '',
287 $us->email,
288 $us->name,
289 $date,
290 $day,
291 l(t('Delete'), 'admin/settings/autoresponder/user/delete/'.$us->uid),
292 ''
293 );
294 $row = implode("%%%", $rows[$us->uid]);
295 $form['checks'][$us->uid] = array(
296 '#type' => 'checkbox',
297 '#default_value' => 0,
298 '#description' => $row
299 );
300 }
301 if ($rows)
302 $form['delete'] = array(
303 '#type' => 'submit',
304 '#value' => t('Delete users')
305 );
306 if (!$rows)
307 $form['no_users'] = array(
308 '#type' => 'markup',
309 '#value' => 'No users in autoresponder database!'
310 );
311 return $form;
312 }
313
314 function autoresponder_mail_list() {
315 switch (arg(4)) {
316 case 'edit':
317 $result = db_query("SELECT *
318 FROM {autoresponder_messages}
319 WHERE id = %d
320 LIMIT 1", arg(5));
321 return autoresponder_mail_edit_create(db_fetch_array($result));
322 case 'add':
323 return autoresponder_mail_edit_create(array());
324 case 'delete':
325 return drupal_get_form('autoresponder_mail_delete_confirm');
326 }
327 return drupal_get_form('autoresponder_mail_list_form');
328 }
329
330 function autoresponder_mail_delete_confirm() {
331 $result = db_query("SELECT *
332 FROM {autoresponder_messages}
333 WHERE id = %d
334 LIMIT 1", arg(5));
335 $mail = db_fetch_object($result);
336 $form['id'] = array(
337 '#type' => 'hidden',
338 '#value' => arg(5)
339 );
340 $form['subject'] = array(
341 '#type' => 'hidden',
342 '#value' => $mail->subject
343 );
344 return confirm_form($form,
345 t('Are you sure you want to delete <i>\''.$mail->subject.'\'</i>?'),
346 'admin/settings/autoresponder/mail/list', t('This action cannot be undone. '),
347 t('Delete'), t('Cancel'));
348 }
349
350 function autoresponder_mail_list_form() {
351 $result = db_query("SELECT am.*, at.name
352 FROM {autoresponder_messages} as am
353 LEFT JOIN {autoresponder_sets} as at ON am.mset = at.id
354 ORDER BY am.subject ASC, am.day ASC
355 ");
356 while ($mail = db_fetch_object($result)) {
357 $rows[$mail->id] = array(
358 '',
359 $mail->subject,
360 $mail->day,
361 $mail->name,
362 l(t('Edit'), 'admin/settings/autoresponder/mail/edit/'.$mail->id).' | ',
363 l(t('Delete'), 'admin/settings/autoresponder/mail/delete/'.$mail->id),
364 ''
365 );
366 $row = implode("%%%", $rows[$mail->id]);
367 $form['checks'][$mail->id] = array(
368 '#type' => 'checkbox',
369 '#default_value' => 0,
370 '#description' => $row
371 );
372 }
373 if ($rows)
374 $form['delete'] = array(
375 '#type' => 'submit',
376 '#value' => t('Delete messages')
377 );
378 if (!$rows)
379 $form['no_messages'] = array(
380 '#type' => 'markup',
381 '#value' => t('No messages in database! You can add them '.l(t('here...'), 'admin/settings/autoresponder/mail/add'))
382 );
383 return $form;
384 }
385
386 function autoresponder_set_list() {
387 switch (arg(4)) {
388 case 'edit':
389 $result = db_query("SELECT *
390 FROM {autoresponder_sets}
391 WHERE id=%d
392 LIMIT 1", arg(5));
393 return autoresponder_set_edit_create(db_fetch_array($result));
394 case 'add':
395 return autoresponder_set_edit_create(array());
396 case 'activate':
397 return autoresponder_set_activate(arg(5));
398 case 'deactivate':
399 return autoresponder_set_deactivate(arg(5));
400 case 'delete':
401 return drupal_get_form('autoresponder_set_delete_confirm');
402 }
403 $output .= drupal_get_form('autoresponder_set_list_form');
404 return $output;
405 }
406
407 function autoresponder_set_delete_confirm() {
408 $result = db_query("SELECT *
409 FROM {autoresponder_sets}
410 WHERE id = %d
411 LIMIT 1", arg(5));
412 $set = db_fetch_object($result);
413 $form['id'] = array(
414 '#type' => 'hidden',
415 '#value' => arg(5)
416 );
417 $form['name'] = array(
418 '#type' => 'hidden',
419 '#value' => $set->name
420 );
421 return confirm_form($form,
422 t('Are you sure you want to delete <i>\''.$set->name.'\'</i>?'),
423 'admin/settings/autoresponder/set/list', t('This action cannot be undone. All messages from this set will be deleted too.'),
424 t('Delete'), t('Cancel'));
425 }
426
427 function autoresponder_set_list_form() {
428 $sql = "SELECT * FROM {autoresponder_sets} WHERE 1";
429 $result = db_query($sql);
430 while ($set = db_fetch_object($result)) {
431 $rows[$set->id] = array(
432 '',
433 $set->name,
434 $set->active == 0 ? l(t('Activate'), 'admin/settings/autoresponder/set/activate/'.$set->id) : l(t('Deactivate'), 'admin/settings/autoresponder/set/deactivate/'.$set->id),
435 l(t('Edit'), 'admin/settings/autoresponder/set/edit/'.$set->id),
436 l(t('Delete'), 'admin/settings/autoresponder/set/delete/'.$set->id),
437 l(t('Add message'), 'admin/settings/autoresponder/mail/add/'.$set->id),
438 ''
439 );
440 $row = implode("%%%", $rows[$set->id]);
441 $form['checks'][$set->id] = array(
442 '#type' => 'checkbox',
443 '#default_value' => 0,
444 '#description' => $row
445 );
446 }
447 if ($rows)
448 $form['delete'] = array(
449 '#type' => 'submit',
450 '#value' => t('Delete sets')
451 );
452 if (!$rows)
453 $form['no_sets'] = array(
454 '#type' => 'markup',
455 '#value' => t('No mailing list users in database! You can add them '.l(t('here...'), 'admin/settings/autoresponder/set/add'))
456 );
457
458 return $form;
459 }
460
461 function theme_autoresponder_user_list_form($form) {
462 $header = array(
463 '',
464 array('data' => t('E-mail')),
465 array('data' => t('Set')),
466 array('data' => t('Register date')),
467 array('data' => t('Now On Day #')),
468 array('data' => t('Functions'), 'colspan' => 3)
469 );
470 if ($form['checks'])
471 foreach ($form['checks'] AS $key => $value) {
472 if (is_int($key)) {
473 $form['checks'][$key]['#description'] = "";
474 $row = explode('%%%', $value['#description']);
475 $row[0] = drupal_render($form['checks'][$key]);
476 $class = array_pop($row);
477 $rows[] = array(
478 'data' => $row,
479 'class' => $class
480 );
481 }
482 }
483 $output = theme('table', $header, $rows);
484 $output .= "<br />".drupal_render($form);
485 return $output;
486 }
487
488 function autoresponder_user_list_form_submit($form_id, $form_values) {
489 switch ($form_values['op']) {
490 case t('Delete users'):
491 foreach ($_POST AS $key => $value)
492 if (is_int($key))
493 $id[] = $key;
494 if ($id)
495 $ids = implode(",", $id);
496 $count = count($id);
497 if ($count) {
498 $form['count'] = array(
499 '#type' => 'hidden',
500 '#value' => $count
501 );
502 $form['ids'] = array(
503 '#type' => 'hidden',
504 '#value' => $ids
505 );
506 db_query("DELETE FROM {autoresponder_users} WHERE id IN (%s)", $ids);
507 db_query("DELETE FROM {autoresponder} WHERE uid IN (%s)", $ids);
508 drupal_set_message($count.' user(s) has been deleted successfully!');
509 drupal_goto('admin/settings/autoresponder/user/list');
510 }
511 else
512 drupal_set_message('There are no selected users!');
513 break;
514 }
515 }
516
517 function autoresponder_mail_list_form_submit($form_id, $form_values) {
518 switch ($form_values['op']) {
519 case t('Delete messages'):
520 foreach ($_POST AS $key => $value)
521 if (is_int($key))
522 $id[] = $key;
523 if ($id)
524 $ids = implode(",", $id);
525 $count = count($id);
526 if ($count) {
527 $form['count'] = array(
528 '#type' => 'hidden',
529 '#value' => $count
530 );
531 $form['ids'] = array(
532 '#type' => 'hidden',
533 '#value' => $ids
534 );
535 db_query("DELETE FROM {autoresponder_messages} WHERE id IN (%s)", $ids);
536 drupal_set_message($count.' message(s) has been deleted successfully!');
537 drupal_goto('admin/settings/autoresponder/mail/list');
538 }
539 else
540 drupal_set_message('There are no selected messages!');
541 }
542 }
543
544 function autoresponder_set_list_form_submit($form_id, $form_values) {
545 switch ($form_values['op']) {
546 case t('Delete sets'):
547 foreach ($_POST AS $key => $value)
548 if (is_int($key))
549 $id[] = $key;
550 if ($id)
551 $ids = implode(",", $id);
552 $count = count($id);
553 if ($count) {
554 $form['count'] = array(
555 '#type' => 'hidden',
556 '#value' => $count
557 );
558 $form['ids'] = array(
559 '#type' => 'hidden',
560 '#value' => $ids
561 );
562 db_query("DELETE FROM {autoresponder_sets} WHERE id IN (%s)", $ids);
563 drupal_set_message($count.' set(s) has been deleted successfully!');
564 drupal_goto('admin/settings/autoresponder/set/list');
565 }
566 else
567 drupal_set_message('There are no selected sets!');
568 }
569 }
570
571 function theme_autoresponder_set_list_form($form) {
572 $header = array(
573 '',
574 array('data' => t('Name')),
575 array('data' => t('Functions'), 'colspan' => 4)
576 );
577 if ($form['checks'])
578 foreach ($form['checks'] AS $key => $value) {
579 if (is_int($key)) {
580 $form['checks'][$key]['#description'] = "";
581 $row = explode('%%%', $value['#description']);
582 $row[0] = drupal_render($form['checks'][$key]);
583 $class = array_pop($row);
584 $rows[] = array(
585 'data' => $row,
586 'class' => $class
587 );
588 }
589 }
590 $output = theme('table', $header, $rows);
591 $output .= '<br />'.drupal_render($form);
592 return $output;
593 }
594
595 function theme_autoresponder_mail_list_form($form) {
596 $header = array(
597 '',
598 array('data' => t('Subject')),
599 array('data' => t('Day #')),
600 array('data' => t('Set')),
601 array('data' => t('Functions'), 'colspan' => 2)
602 );
603 if ($form['checks'])
604 foreach ($form['checks'] AS $key => $value) {
605 if (is_int($key)) {
606 $form['checks'][$key]['#description'] = "";
607 $row = explode('%%%', $value['#description']);
608 $row[0] = drupal_render($form['checks'][$key]);
609 $class = array_pop($row);
610 $rows[] = array(
611 'data' => $row,
612 'class' => $class
613 );
614 }
615 }
616 $output = theme('table', $header, $rows);
617 $output .= "<br />".drupal_render($form);
618 return $output;
619 }
620
621 function autoresponder_block($op = 'list', $delta = 0, $edit = array()) {
622 switch ($op) {
623 case 'list':
624 $blocks[0]['info'] = t('Autoresponder');
625 return $blocks;
626 case 'configure':
627 $form = array();
628 if ($delta == 0) {
629 // Here will be configure form (if needed)
630 }
631 return $form;
632 case 'save':
633 if ($delta == 0) {
634 // Save configured settings
635 }
636 return;
637 case 'view': default:
638 switch ($delta) {
639 case 0:
640 $block['subject'] = t('Autoresponder');
641 $block['content'] = autoresponder_contents(1);
642 $block['weight'] = 0;
643 $block['enabled'] = 1;
644 break;
645 }
646 return $block;
647 }
648 }
649
650 function autoresponder_contents($which_block) {
651 if ($which_block == 1) {
652 return drupal_get_form('autoresponder_email_enter');
653 }
654 }
655
656 function autoresponder_email_enter() {
657 $sql = "SELECT * FROM {autoresponder_sets} WHERE 1";
658 $result = db_query($sql);
659 $sets = array();
660 while ($set = db_fetch_object($result)) {
661 if ($set->active)
662 $sets["$set->id"] = $set->name;
663 }
664 if (empty($sets))
665 $sets = array('empty' => '<empty>');
666 $form['email'] = array(
667 '#type' => 'textfield',
668 '#title' => t('E-mail'),
669 '#size' => 25,
670 '#description' => 'Enter your e-mail to sign up for a series of emails',
671 '#required' => TRUE,
672 '#weight' => 1
673 );
674 $form['set'] = array(
675 '#type' => 'select',
676 '#title' => t('Category'),
677 '#options' => $sets,
678 '#description' => t('Select preferred list'),
679 '#required' => TRUE,
680 );
681 $form['submit'] = array(
682 '#type' => 'submit',
683 '#value' => t('Signup'),
684 '#weight' => 3
685 );
686 return $form;
687 }
688
689 function autoresponder_set_edit_create($set) {
690 return drupal_get_form('autoresponder_set_edit_create_form', $set);
691 }
692
693 function autoresponder_set_edit_create_form($set) {
694 $form['name'] = array(
695 '#type' => 'textfield',
696 '#title' => t('Title'),
697 '#default_value' => $set['name'],
698 '#size' => 60,
699 '#maxlength' => 64,
700 '#description' => t('Enter mailing list set title'),
701 '#required' => TRUE
702 );
703 $form['active'] = array(
704 '#type' => 'checkbox',
705 '#title' => t('Active'),
706 '#default_value' => $set['active'],
707 '#description' => t('Check this to create a active set'),
708 );
709 $form['submit' ] = array(
710 '#type' => 'submit',
711 '#value' => t('OK')
712 );
713 if ($set['id']) {
714 $form['id'] = array(
715 '#type' => 'hidden',
716 '#value' => $set['id']
717 );
718 }
719 return $form;
720 }
721
722 function autoresponder_mail_edit_create($mail) {
723 return drupal_get_form('autoresponder_mail_edit_create_form', $mail);
724 }
725
726 function autoresponder_mail_edit_create_form($mail) {
727 $sql = "SELECT * FROM {autoresponder_sets} WHERE 1";
728 $result = db_query($sql);
729 $sets = array();
730 while ($set = db_fetch_object($result))
731 if ($set->active)
732 $sets["$set->id"] = $set->name;
733 $setid = arg(5);
734 $form['subject'] = array(
735 '#type' => 'textfield',
736 '#title' => t('Subject'),
737 '#default_value' => $mail['subject'],
738 '#size' => 60,
739 '#maxlength' => 64,
740 '#description' => t('Enter message subject'),
741 '#required' => TRUE
742 );
743 $form['set'] = array(
744 '#type' => 'select',
745 '#title' => t('Category'),
746 '#options' => $sets,
747 '#description' => t('Select preferred list'),
748 '#default_value' => !empty($setid) ? $setid : $mail['mset'],
749 '#required' => TRUE,
750 );
751 $form['day'] = array(
752 '#type' => 'textfield',
753 '#title' => t('Day #'),
754 '#default_value' => $mail['day'],
755 '#size' => 3,
756 '#maxlength' => 128,
757 '#required' => TRUE,
758 '#description' => 'Enter the day #, when email must be sent'
759 );
760 $form['body'] = array(
761 '#type' => 'textarea',
762 '#title' => t('Body'),
763 '#default_value' => $mail['body'],
764 '#required' => TRUE,
765 '#rows' => 15,
766 '#description' => 'Enter an e-mail body'
767 );
768 $form['submit' ] = array(
769 '#type' => 'submit',
770 '#value' => t('OK')
771 );
772 if ($mail['id']) {
773 $form['id'] = array(
774 '#type' => 'hidden',
775 '#value' => $mail['id']
776 );
777 }
778 return $form;
779 }
780
781 function autoresponder_email_enter_validate($form_id, $form_values) {
782 if (!valid_email_address($form_values['email']))
783 form_set_error('email', 'Email address is wrong. Example: <i>john@coolsite.com</i>');
784 $result = db_query("SELECT * FROM {autoresponder_users} WHERE email = '%s'", $form_values['email']);
785 $exist = db_num_rows($result);
786 if ($exist)
787 form_set_error('email','The email address <i>'.$form_values['email'].'</i> you provide is already registered.');
788 }
789
790 function autoresponder_email_enter_submit($form_id, $form_values) {
791 $auid = db_next_id('{autoresponder_users}');
792 $time = time();
793 db_query("INSERT INTO {autoresponder_users}
794 (id, email, reg_date)
795 VALUES(%d, '%s', %d)",
796 $auid, $form_values['email'], $time);
797 $aid = db_next_id('{autoresponder}');
798 db_query("INSERT INTO {autoresponder}
799 (id, uid, setid)
800 VALUES(%d, %d, %d)",
801 $aid, $auid, $form_values['set']);
802 $result_messages = db_query("SELECT *
803 FROM {autoresponder_messages}
804 WHERE day = %d AND mset= %d
805 ", 0, $form_values['set']);
806 $message = db_fetch_array($result_messages);
807 autoresponder_mail(array('email' => $form_values['email'], 'uid' => $auid), $message);
808 drupal_set_message('Your email address <i>\''.$form_values['email'].'\'</i> is added to our mailing list! Please check your email.');
809 }
810
811 function autoresponder_user_delete_confirm_submit($form_id, $form_values) {
812 db_query("DELETE FROM {autoresponder_users}
813 WHERE id = %d",
814 $form_values['id']);
815 db_query("DELETE FROM {autoresponder}
816 WHERE uid = %d",
817 $form_values['id']);
818 drupal_set_message('User <i>\''.$form_values['email'].'\'</i> successfully deleted!');
819 drupal_goto('admin/settings/autoresponder/user/list');
820 }
821
822 function autoresponder_mail_delete_confirm_submit($form_id, $form_values) {
823 db_query("DELETE FROM {autoresponder_messages}
824 WHERE id = %d",
825 $form_values['id']);
826 drupal_set_message('Message <i>\''.$form_values['subject'].'\'</i> successfully deleted!');
827 drupal_goto('admin/settings/autoresponder/mail/list');
828 }
829
830 function autoresponder_set_delete_confirm_submit($form_id, $form_values) {
831 db_query("DELETE FROM {autoresponder_sets}
832 WHERE id = %d",
833 $form_values['id']);
834 db_query("DELETE FROM {autoresponder_messages}
835 WHERE mset = %d",
836 $form_values['id']);
837 db_query("DELETE FROM {autoresponder}
838 WHERE setid = %d",
839 $form_values['id']);
840 drupal_set_message('Set <i>\''.$form_values['name'].'\'</i> successfully deleted! Messages, that associated with this set was deleted too.');
841 drupal_goto('admin/settings/autoresponder/set/list');
842 }
843
844 function autoresponder_set_edit_create_form_submit($form_id, $form_values) {
845 $id = db_next_id('{autoresponder_sets}');
846 if ($form_values['id']) {
847 db_query("UPDATE {autoresponder_sets}
848 SET name = '%s', active = '%s'
849 WHERE id = %d",
850 $form_values['name'], $form_values['active'], $form_values['id']);
851 drupal_set_message('Mail set <i>\''.$form_values['name'].'\'</i> successfully updated!');
852 }
853 else {
854 db_query("INSERT INTO {autoresponder_sets}
855 (id, name, active)
856 VALUES(%d, '%s', '%s')",
857 $id, $form_values['name'], $form_values['active']
858 );
859 drupal_set_message('New messages set <i>\''.$form_values['name'].'\'</i> successfully added as '.($form_values['active'] ? 'active' : 'inactive').'! Add messages to this list '.l(t(here), 'admin/administration/mail/add/'.$id));
860 }
861 return 'admin/settings/autoresponder/set/list';
862 }
863
864 function autoresponder_mail_edit_create_form_validate($form_id, $form_values) {
865 if (!is_numeric($form_values['day']))
866 form_set_error('day', 'The day must be a number. Example: <i>10</i>');
867 }
868
869 function autoresponder_mail_edit_create_form_submit($form_id, $form_values) {
870 $id = db_next_id('{autoresponder_messages}');
871 if ($form_values['id']) {
872 db_query("UPDATE {autoresponder_messages}
873 SET subject = '%s', body = '%s', mset = '%s', day = %d
874 WHERE id = %d",
875 $form_values['subject'], $form_values['body'], $form_values['set'], $form_values['day'], $form_values['id']);
876 drupal_set_message('Mail set <i>\''.$form_values['subject'].'\'</i> successfully updated!');
877 }
878 else {
879 db_query("INSERT INTO {autoresponder_messages}
880 (id, subject, body, mset, day)
881 VALUES(%d, '%s', '%s', %d, '%s')",
882 $id, $form_values['subject'], $form_values['body'], $form_values['set'], $form_values['day']
883 );
884 drupal_set_message('New message <i>\''.$form_values['subject'].'\'</i> successfully added on day '.$form_values['day'].'!');
885 }
886 return 'admin/settings/autoresponder/mail/list';
887 }
888
889 function autoresponder_user_unsubscribe_confirm_submit($form_id, $form_values) {
890 db_query("DELETE FROM {autoresponder_users}
891 WHERE id = %d",
892 $form_values['id']);
893 db_query("DELETE FROM {autoresponder}
894 WHERE uid = %d",
895 $form_values['id']);
896 drupal_set_message('<i>\''.$form_values['email'].'\'</i> successfully removed from <i>\''.$form_values['set'].'\' mailing list!');
897 drupal_goto('admin/settings/autoresponder/user/list');
898 }
899
900 function autoresponder_set_activate($id) {
901 $query = db_query("SELECT *
902 FROM {autoresponder_sets}
903 WHERE id=%d
904 LIMIT 1", $id);
905 $set = db_fetch_object($query);
906 db_query("UPDATE {autoresponder_sets}
907 SET active = 1
908 WHERE id = %d",
909 $id);
910 drupal_set_message('Set <i>\''.$set->name.'\'</i> successfully activated!');
911 drupal_goto('admin/settings/autoresponder/set/list');
912 }
913
914 function autoresponder_set_deactivate($id) {
915 $query = db_query("SELECT *
916 FROM {autoresponder_sets}
917 WHERE id=%d
918 LIMIT 1", $id);
919 $set = db_fetch_object($query);
920 db_query("UPDATE {autoresponder_sets}
921 SET active = 0
922 WHERE id = %d",
923 $id);
924 drupal_set_message('Set <i>\''.$set->name.'\'</i> successfully deactivated!');
925 drupal_goto('admin/settings/autoresponder/set/list');
926 }
927 ?>

  ViewVC Help
Powered by ViewVC 1.1.2