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

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