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

Last change on this file since 24348 was 24348, checked in by mistic100, 11 years ago

revert changes form previous commit + fix undefined index after restoration

File size: 3.2 KB
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    $conf['ContactForm'] = 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_mail_type' => 'text/html',
33      'cf_redirect_url' => null,
34      'cf_theme' => 'dark',
35      ));
36   
37    $conf['ContactForm_before'] = null;
38    $conf['ContactForm_after'] = null;
39   
40    conf_update_param('ContactForm', $conf['ContactForm']);
41    conf_update_param('ContactForm_before', $conf['ContactForm_before']);
42    conf_update_param('ContactForm_after', $conf['ContactForm_after']);
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_default_subject'] = 'A comment on your site';
53      $new_conf['cf_mail_type'] = 'text/html';
54      $new_conf['cf_redirect_url'] = null;
55     
56      // move emails to database
57      $emails = 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      $new_conf['cf_must_initialize'] = empty($emails);
68     
69      mass_inserts(
70        $prefixeTable .'contact_form',
71        array('name','email','active'),
72        $emails
73        );
74     
75      // old params
76      unset(
77        $new_conf['comment'], $new_conf['cf_redirect_delay'], 
78        $new_conf['cf_separator'], $new_conf['cf_separator_length'], 
79        $new_conf['cf_admin_mails']
80        );
81     
82      // save config
83      $conf['ContactForm_before'] = stripslashes(@$conf['persoformtop']);
84      $conf['ContactForm_after'] = stripslashes(@$conf['persoformbottom']);
85     
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    // new param 2.5.c
93    if (!isset($new_conf['cf_theme']))
94    {
95      $new_conf['cf_theme'] = 'dark';
96    }
97   
98    // save config
99    $conf['ContactForm'] = serialize($new_conf);
100    conf_update_param('ContactForm', $conf['ContactForm']);
101  }
102}
103
104?>
Note: See TracBrowser for help on using the repository browser.