source: extensions/MyPiwiShop/maintain.inc.php @ 27568

Last change on this file since 27568 was 27568, checked in by Miklfe, 10 years ago
File size: 3.3 KB
Line 
1<?php
2defined('PHPWG_ROOT_PATH') or die('Hacking attempt!');
3
4class mps_maintain extends PluginMaintain
5{
6  private $installed = false;
7 
8
9        /*
10   * plugin installation
11   */
12  function install($plugin_version, &$errors=array())
13  {
14    global $conf, $prefixeTable;
15
16    // add a new table
17  $tables = mps_get_tables();
18
19 if (!in_array($prefixeTable.'mps_conf', $tables))
20  {
21         $query = "
22        CREATE TABLE IF NOT EXISTS ". $prefixeTable ."mps_conf (
23          `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
24          `PPid` varchar(100) NOT NULL,
25          `currency` varchar(100),
26          `ship` decimal NOT NULL,
27          `comm` text ,
28          `tprmulti` varchar(200) ,
29          `tpruniq` varchar(200) ,
30          PRIMARY KEY (`id`)
31        ) ENGINE=MyISAM DEFAULT CHARSET=utf8
32        ;";
33       
34    pwg_query($query);
35
36    single_insert(
37      $prefixeTable."mps_conf",
38      array(
39        'currency' => 'EUR',
40        )
41      );
42        }
43       
44        pwg_query('
45        CREATE TABLE IF NOT EXISTS `'. $prefixeTable .'mps_product` (
46          `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
47          `order` int(20),
48          `product` varchar(100) NOT NULL,
49          `noteAdmin` varchar(255),
50          `price` float NOT NULL,
51          PRIMARY KEY (`id`)
52        ) ENGINE=MyISAM DEFAULT CHARSET=utf8
53        ;');
54       
55        pwg_query('
56        CREATE TABLE IF NOT EXISTS `'. $prefixeTable .'mps_prod_img` (
57          `image_id` MEDIUMINT (20) UNSIGNED NOT NULL,
58          `product_id` MEDIUMINT (20) UNSIGNED NOT NULL,
59          PRIMARY KEY (`product_id`,`image_id`)
60        ) ENGINE=MyISAM DEFAULT CHARSET=utf8
61        ;');
62       
63        pwg_query('
64        CREATE TABLE IF NOT EXISTS `'. $prefixeTable .'mps_option` (
65          `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
66          `name` varchar(250) NOT NULL,
67          `type` varchar(100) NOT NULL,
68          `titre` varchar(200),
69          `requi` int(10),
70          `order` int(20),
71         
72          PRIMARY KEY (`id`)
73        ) ENGINE=MyISAM DEFAULT CHARSET=utf8
74        ;');
75
76        pwg_query('
77        CREATE TABLE IF NOT EXISTS `'. $prefixeTable .'mps_opt_val` (
78          `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
79          `val` varchar(100) NOT NULL,
80          `select_id` int(11) NOT NULL,
81          PRIMARY KEY (`id`)
82        ) ENGINE=MyISAM DEFAULT CHARSET=utf8
83        ;');
84
85        pwg_query('
86        CREATE TABLE IF NOT EXISTS `'. $prefixeTable .'mps_prod_opt` (
87          `opt_id` MEDIUMINT (20) UNSIGNED NOT NULL,
88          `product_id` MEDIUMINT (20) UNSIGNED NOT NULL,
89          PRIMARY KEY (`product_id`,`opt_id`)
90        ) ENGINE=MyISAM DEFAULT CHARSET=utf8
91        ;');
92       
93    $this->installed = true;
94  }
95 
96  /**
97   * plugin activation
98   */
99  function activate($plugin_version, &$errors=array())
100  {
101    if (!$this->installed)
102    {
103
104      $this->install($plugin_version, $errors);
105    }
106  }
107
108  /**
109   * plugin deactivation
110   */
111  function deactivate()
112  {
113  }
114
115  /**
116   * plugin uninstallation
117   */
118  function uninstall()
119  {
120    global $prefixeTable;
121
122    // delete table
123    pwg_query('DROP TABLE `'. $prefixeTable .'mps_conf`;');
124    pwg_query('DROP TABLE `'. $prefixeTable .'mps_product`;');
125    pwg_query('DROP TABLE `'. $prefixeTable .'mps_prod_img`;');
126    pwg_query('DROP TABLE `'. $prefixeTable .'mps_option`;');
127    pwg_query('DROP TABLE `'. $prefixeTable .'mps_opt_val`;');
128    pwg_query('DROP TABLE `'. $prefixeTable .'mps_prod_opt`;');
129 }
130}
131
132
133function mps_get_tables()
134{
135  global $prefixeTable;
136 
137  $tables = array();
138
139  $query = '
140SHOW TABLES
141;';
142  $result = pwg_query($query);
143
144  while ($row = pwg_db_fetch_row($result))
145  {
146    if (preg_match('/^'.$prefixeTable.'/', $row[0]))
147    {
148      array_push($tables, $row[0]);
149    }
150  }
151
152  return $tables;
153}
Note: See TracBrowser for help on using the repository browser.