1 | <?php |
---|
2 | /** |
---|
3 | * Create the piwecard table in the database |
---|
4 | * @param String name of the table |
---|
5 | */ |
---|
6 | function piwecard_db_create($table) { |
---|
7 | $query = 'CREATE TABLE ' . $table . ' ( |
---|
8 | unique_id INT NOT NULL AUTO_INCREMENT, |
---|
9 | ecard_id CHAR(64) NOT NULL, |
---|
10 | sender_name CHAR(100) NOT NULL, |
---|
11 | sender_email CHAR(100) NOT NULL, |
---|
12 | recipient_name CHAR(100) NOT NULL, |
---|
13 | recipient_email CHAR(100) NOT NULL, |
---|
14 | title CHAR(100) NOT NULL, |
---|
15 | message TEXT NOT NULL, |
---|
16 | image MEDIUMINT(8) NOT NULL, |
---|
17 | date_creation DATETIME NOT NULL, |
---|
18 | date_validity DATETIME DEFAULT NULL, |
---|
19 | PRIMARY KEY (unique_id) |
---|
20 | ) DEFAULT CHARSET=utf8;'; |
---|
21 | pwg_query($query); |
---|
22 | } |
---|
23 | |
---|
24 | /** |
---|
25 | * Delete the piwecard table in the database |
---|
26 | * @param String name of the table |
---|
27 | */ |
---|
28 | function piwecard_db_delete($table) { |
---|
29 | $query = 'DROP TABLE ' . $table . ';'; |
---|
30 | pwg_query($query); |
---|
31 | } |
---|
32 | |
---|
33 | /** |
---|
34 | * Update the piwecard table in the database from Piwecard version 2.3 |
---|
35 | * @param String old table name |
---|
36 | * @param String new table name |
---|
37 | */ |
---|
38 | function piwecard_db_update_from_2_3($old_table, $new_table) { |
---|
39 | $query = 'SELECT * FROM '.$old_table.';'; |
---|
40 | $result = pwg_query($query); |
---|
41 | |
---|
42 | while($data = pwg_db_fetch_assoc($result)) { |
---|
43 | $insert = array( |
---|
44 | 'ecard_id' => $data['numero'], |
---|
45 | 'sender_name' => $data['nomexp'], |
---|
46 | 'sender_email' => $data['adrexp'], |
---|
47 | 'recipient_name' => $data['nomdest'], |
---|
48 | 'recipient_email' => $data['adrdest'], |
---|
49 | 'title' => $data['sujet'], |
---|
50 | 'message' => $data['message'], |
---|
51 | 'image' => $data['image'], |
---|
52 | 'date_creation' => $data['date'], |
---|
53 | ); |
---|
54 | if ($data['duration'] != '0') { |
---|
55 | $date = new DateTime($data['date']); |
---|
56 | $date->modify("+".$data['duration']." day"); |
---|
57 | $insert['date_validity'] = $date->format('Y-m-d H:i:s'); |
---|
58 | } |
---|
59 | |
---|
60 | single_insert($new_table, $insert); |
---|
61 | } |
---|
62 | } |
---|
63 | |
---|
64 | /** |
---|
65 | * Update the piwecard table in the database from Piwecard version 2.4.a.b3 |
---|
66 | * @param String table name |
---|
67 | */ |
---|
68 | function piwecard_db_update_from_2_4a_b3($table) { |
---|
69 | $query = 'ALTER TABLE '.$table.' DROP PRIMARY KEY;'; |
---|
70 | $result = pwg_query($query); |
---|
71 | $query = 'ALTER TABLE '.$table.' ADD unique_id INT NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (unique_id);'; |
---|
72 | $result = pwg_query($query); |
---|
73 | $query = 'ALTER TABLE '.$table.' CHANGE id ecard_id CHAR(64) NOT NULL;'; |
---|
74 | $result = pwg_query($query); |
---|
75 | } |
---|
76 | |
---|
77 | /** |
---|
78 | * Create the piwecard entry in the config table of the database |
---|
79 | * @param String entry name |
---|
80 | */ |
---|
81 | function piwecard_conf_create($name) { |
---|
82 | $query = 'INSERT INTO '.CONFIG_TABLE.' (param,value,comment) VALUES ("'.$name.'","","'.ucfirst($name).' configuration");'; |
---|
83 | pwg_query($query); |
---|
84 | } |
---|
85 | |
---|
86 | /** |
---|
87 | * Delete the piwecard entry in the config table of the database |
---|
88 | * @param String entry name |
---|
89 | */ |
---|
90 | function piwecard_conf_delete($name){ |
---|
91 | $query = 'DELETE FROM '.CONFIG_TABLE.' WHERE param="'.$name.'";'; |
---|
92 | pwg_query($query); |
---|
93 | } |
---|
94 | |
---|
95 | /** |
---|
96 | * Rename the piwecard entry in the config table of the database |
---|
97 | * @param String old name |
---|
98 | * @param String new name |
---|
99 | */ |
---|
100 | function piwecard_conf_rename($old_name, $new_name){ |
---|
101 | $query = 'UPDATE '.CONFIG_TABLE.' SET param="'.$new_name.'" WHERE param="'.$old_name.'";'; |
---|
102 | pwg_query($query); |
---|
103 | } |
---|
104 | ?> |
---|