1 | <?php |
---|
2 | defined('PHPWG_ROOT_PATH') or die('Hacking attempt!'); |
---|
3 | |
---|
4 | /** |
---|
5 | * The installation function is called by main.inc.php and maintain.inc.php |
---|
6 | * in order to install and/or update the plugin. |
---|
7 | * |
---|
8 | * That's why all operations must be conditionned : |
---|
9 | * - use "if empty" for configuration vars |
---|
10 | * - use "IF NOT EXISTS" for table creation |
---|
11 | * |
---|
12 | * Unlike the functions in maintain.inc.php, the name of this function must be unique |
---|
13 | * and not enter in conflict with other plugins. |
---|
14 | */ |
---|
15 | |
---|
16 | function ppppp_install() |
---|
17 | { |
---|
18 | global $conf, $prefixeTable, $template; |
---|
19 | |
---|
20 | $tables = ppppp_get_tables(); |
---|
21 | |
---|
22 | if (!in_array($prefixeTable.'ppppp_size', $tables)) |
---|
23 | { |
---|
24 | $query = " |
---|
25 | CREATE TABLE IF NOT EXISTS ".$prefixeTable."ppppp_size ( |
---|
26 | id tinyint(4) NOT NULL AUTO_INCREMENT, |
---|
27 | size varchar(40) NOT NULL, |
---|
28 | price float NOT NULL, |
---|
29 | PRIMARY KEY (id), |
---|
30 | UNIQUE KEY size (size) |
---|
31 | ) |
---|
32 | ;"; |
---|
33 | pwg_query($query); |
---|
34 | |
---|
35 | single_insert( |
---|
36 | $prefixeTable."ppppp_size", |
---|
37 | array( |
---|
38 | 'size' => 'Classique', |
---|
39 | 'price' => 40, |
---|
40 | ) |
---|
41 | ); |
---|
42 | } |
---|
43 | |
---|
44 | if (!in_array($prefixeTable.'ppppp_config', $tables)) |
---|
45 | { |
---|
46 | $query = " |
---|
47 | CREATE TABLE IF NOT EXISTS ".$prefixeTable."ppppp_config ( |
---|
48 | param varchar(40) NOT NULL, |
---|
49 | value text NOT NULL, |
---|
50 | PRIMARY KEY (param) |
---|
51 | ) |
---|
52 | ;"; |
---|
53 | pwg_query($query); |
---|
54 | |
---|
55 | mass_inserts( |
---|
56 | $prefixeTable."ppppp_config", |
---|
57 | array('param', 'value'), |
---|
58 | array( |
---|
59 | array('param' => 'fixed_shipping', 'value' => '0'), |
---|
60 | array('param' => 'currency', 'value' => 'EUR'), |
---|
61 | ) |
---|
62 | ); |
---|
63 | } |
---|
64 | |
---|
65 | // add a new column to existing table |
---|
66 | $result = pwg_query('SHOW COLUMNS FROM `'.CATEGORIES_TABLE.'` LIKE "paypal_active";'); |
---|
67 | if (!pwg_db_num_rows($result)) |
---|
68 | { |
---|
69 | pwg_query('ALTER TABLE `'.CATEGORIES_TABLE.'` ADD `paypal_active` enum(\'true\', \'false\') default \'false\';'); |
---|
70 | } |
---|
71 | |
---|
72 | // add config parameter |
---|
73 | if (empty($conf['PayPalShoppingCart'])) |
---|
74 | { |
---|
75 | $default_config = serialize(array( |
---|
76 | 'apply_to_albums' => 'all', |
---|
77 | )); |
---|
78 | |
---|
79 | conf_update_param('PayPalShoppingCart', $default_config); |
---|
80 | $conf['PayPalShoppingCart'] = $default_config; |
---|
81 | |
---|
82 | $template->delete_compiled_templates(); |
---|
83 | } |
---|
84 | } |
---|
85 | |
---|
86 | /** |
---|
87 | * list all tables in an array |
---|
88 | * |
---|
89 | * @return array |
---|
90 | */ |
---|
91 | function ppppp_get_tables() |
---|
92 | { |
---|
93 | global $prefixeTable; |
---|
94 | |
---|
95 | $tables = array(); |
---|
96 | |
---|
97 | $query = ' |
---|
98 | SHOW TABLES |
---|
99 | ;'; |
---|
100 | $result = pwg_query($query); |
---|
101 | |
---|
102 | while ($row = pwg_db_fetch_row($result)) |
---|
103 | { |
---|
104 | if (preg_match('/^'.$prefixeTable.'/', $row[0])) |
---|
105 | { |
---|
106 | array_push($tables, $row[0]); |
---|
107 | } |
---|
108 | } |
---|
109 | |
---|
110 | return $tables; |
---|
111 | } |
---|
112 | ?> |
---|