source: extensions/ContactForm/include/install.inc.php @ 17945

Revision 17945, 3.0 KB checked in by mistic100, 7 years ago (diff)
  • stores emails in database (/!\ update only from published version, not from trunk)
  • allow emails to be categorized
Line 
1<?php
2if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
3
4function contact_form_install()
5{
6  global $conf, $prefixeTable;
7 
8  // email table
9  $query = '
10CREATE TABLE IF NOT EXISTS `'. $prefixeTable .'contact_form` (
11  `id` smallint(5) NOT NULL AUTO_INCREMENT,
12  `name` varchar(128) NOT NULL,
13  `email` varchar(128) NOT NULL,
14  `active` enum("true","false") NOT NULL DEFAULT "true",
15  `group_name` varchar(128) DEFAULT NULL,
16  PRIMARY KEY (`id`),
17  UNIQUE KEY `UNIQUE` (`email`,`group_name`)
18) ENGINE=MyISAM DEFAULT CHARSET=utf8;';
19  pwg_query($query);
20
21  // configuration
22  if (empty($conf['ContactForm']))
23  {
24    $contact_form_default_config = serialize(array(
25      'cf_must_initialize' => true,
26      'cf_menu_link' => true,
27      'cf_subject_prefix' => '%gallery_title%',
28      'cf_default_subject' => 'A comment on your site',
29      'cf_allow_guest' => true,
30      'cf_mandatory_mail' => true,
31      'cf_mandatory_name' => true,
32      'cf_redirect_delay' => 5,
33      'cf_mail_type' => 'text/html',
34      ));
35   
36    conf_update_param('ContactForm', $contact_form_default_config);
37    conf_update_param('ContactForm_before', null);
38    conf_update_param('ContactForm_after', null);
39   
40    $conf['ContactForm'] = $contact_form_default_config;
41    $conf['ContactForm_before'] = null;
42    $conf['ContactForm_after'] = null;
43  }
44  else
45  {
46    $new_conf = is_string($conf['ContactForm']) ? unserialize($conf['ContactForm']) : $conf['ContactForm'];
47   
48    // migration 2.4 -> 2.5
49    if (!isset($new_conf['cf_must_initialize']))
50    {
51      // new params
52      $new_conf['cf_must_initialize'] = false;
53      $new_conf['cf_default_subject'] = 'A comment on your site';
54      $new_conf['cf_mail_type'] = 'text/html';
55     
56      // move emails to database
57      $email = array();
58      foreach ($new_conf['cf_admin_mails'] as $email => $data)
59      {
60        array_push($emails, array(
61          'email' => $email,
62          'name' => $data['NAME'],
63          'active' => boolean_to_string($data['ACTIVE']),
64          ));
65      }
66     
67      mass_inserts(
68        $prefixeTable .'contact_form',
69        array('name','email','active'),
70        $emails
71        );
72     
73      // old params
74      unset(
75        $new_conf['comment'], $new_conf['cf_redirect_delay'], 
76        $new_conf['cf_separator'], $new_conf['cf_separator_length'], 
77        $new_conf['cf_admin_mails']
78        );
79     
80      // save config
81      $conf['ContactForm'] = serialize($new_conf);
82      $conf['ContactForm_before'] = stripslashes($conf['persoformtop']);
83      $conf['ContactForm_after'] = stripslashes($conf['persoformbottom']);
84     
85      conf_update_param('ContactForm', $conf['ContactForm']);
86      conf_update_param('ContactForm_before', $conf['ContactForm_before']);
87      conf_update_param('ContactForm_after', $conf['ContactForm_after']);
88     
89      pwg_query('DELETE FROM `'. CONFIG_TABLE .'` WHERE param IN("persoformtop", "persoformbottom") LIMIT 2;');
90    }
91  }
92}
93
94?>
Note: See TracBrowser for help on using the repository browser.