1 | <?php |
---|
2 | function piwecard_db_create($table) { |
---|
3 | $query = 'CREATE TABLE ' . $table . ' ( |
---|
4 | unique_id INT NOT NULL AUTO_INCREMENT, |
---|
5 | ecard_id CHAR(64) NOT NULL, |
---|
6 | sender_name CHAR(100) NOT NULL, |
---|
7 | sender_email CHAR(100) NOT NULL, |
---|
8 | recipient_name CHAR(100) NOT NULL, |
---|
9 | recipient_email CHAR(100) NOT NULL, |
---|
10 | title CHAR(100) NOT NULL, |
---|
11 | message TEXT NOT NULL, |
---|
12 | image MEDIUMINT(8) NOT NULL, |
---|
13 | date_creation DATETIME NOT NULL, |
---|
14 | date_validity DATETIME DEFAULT NULL, |
---|
15 | PRIMARY KEY (unique_id) |
---|
16 | ) DEFAULT CHARSET=utf8;'; |
---|
17 | pwg_query($query); |
---|
18 | } |
---|
19 | |
---|
20 | function piwecard_db_delete($table) { |
---|
21 | $query = 'DROP TABLE ' . $table . ';'; |
---|
22 | pwg_query($query); |
---|
23 | } |
---|
24 | |
---|
25 | function piwecard_db_update_from_2_3($old_table, $new_table) { |
---|
26 | $query = 'SELECT * FROM '.$old_table.';'; |
---|
27 | $result = pwg_query($query); |
---|
28 | |
---|
29 | while($data = pwg_db_fetch_assoc($result)) { |
---|
30 | $insert = array( |
---|
31 | 'ecard_id' => $data['numero'], |
---|
32 | 'sender_name' => $data['nomexp'], |
---|
33 | 'sender_email' => $data['adrexp'], |
---|
34 | 'recipient_name' => $data['nomdest'], |
---|
35 | 'recipient_email' => $data['adrdest'], |
---|
36 | 'title' => $data['sujet'], |
---|
37 | 'message' => $data['message'], |
---|
38 | 'image' => $data['image'], |
---|
39 | 'date_creation' => $data['date'], |
---|
40 | ); |
---|
41 | if ($data['duration'] != '0') { |
---|
42 | $date = new DateTime($data['date']); |
---|
43 | $date->modify("+".$data['duration']." day"); |
---|
44 | $insert['date_validity'] = $date->format('Y-m-d H:i:s'); |
---|
45 | } |
---|
46 | |
---|
47 | single_insert($new_table, $insert); |
---|
48 | } |
---|
49 | } |
---|
50 | |
---|
51 | function piwecard_db_update_from_2_4a_b3($table) { |
---|
52 | $query = 'ALTER TABLE '.$table.' DROP PRIMARY KEY;'; |
---|
53 | $result = pwg_query($query); |
---|
54 | $query = 'ALTER TABLE '.$table.' ADD unique_id INT NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (unique_id);'; |
---|
55 | $result = pwg_query($query); |
---|
56 | $query = 'ALTER TABLE '.$table.' CHANGE id ecard_id CHAR(64) NOT NULL;'; |
---|
57 | $result = pwg_query($query); |
---|
58 | } |
---|
59 | |
---|
60 | function piwecard_conf_create($name) { |
---|
61 | $query = 'INSERT INTO '.CONFIG_TABLE.' (param,value,comment) VALUES ("'.$name.'","","'.ucfirst($name).' configuration");'; |
---|
62 | pwg_query($query); |
---|
63 | } |
---|
64 | |
---|
65 | function piwecard_conf_delete($name){ |
---|
66 | $query = 'DELETE FROM '.CONFIG_TABLE.' WHERE param="'.$name.'";'; |
---|
67 | pwg_query($query); |
---|
68 | } |
---|
69 | |
---|
70 | function piwecard_conf_rename($old_name, $new_name){ |
---|
71 | $query = 'UPDATE '.CONFIG_TABLE.' SET param="'.$new_name.'" WHERE param="'.$old_name.'";'; |
---|
72 | pwg_query($query); |
---|
73 | } |
---|
74 | ?> |
---|