[19956] | 1 | <?php |
---|
[20431] | 2 | /** |
---|
| 3 | * Create the piwecard table in the database |
---|
| 4 | * @param String name of the table |
---|
| 5 | */ |
---|
[19956] | 6 | function piwecard_db_create($table) { |
---|
| 7 | $query = 'CREATE TABLE ' . $table . ' ( |
---|
[20202] | 8 | unique_id INT NOT NULL AUTO_INCREMENT, |
---|
| 9 | ecard_id CHAR(64) NOT NULL, |
---|
[19956] | 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, |
---|
[20059] | 14 | title CHAR(100) NOT NULL, |
---|
[19956] | 15 | message TEXT NOT NULL, |
---|
| 16 | image MEDIUMINT(8) NOT NULL, |
---|
| 17 | date_creation DATETIME NOT NULL, |
---|
| 18 | date_validity DATETIME DEFAULT NULL, |
---|
[20202] | 19 | PRIMARY KEY (unique_id) |
---|
[19956] | 20 | ) DEFAULT CHARSET=utf8;'; |
---|
| 21 | pwg_query($query); |
---|
| 22 | } |
---|
| 23 | |
---|
[20431] | 24 | /** |
---|
| 25 | * Delete the piwecard table in the database |
---|
| 26 | * @param String name of the table |
---|
| 27 | */ |
---|
[19956] | 28 | function piwecard_db_delete($table) { |
---|
| 29 | $query = 'DROP TABLE ' . $table . ';'; |
---|
| 30 | pwg_query($query); |
---|
| 31 | } |
---|
| 32 | |
---|
[20431] | 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 | */ |
---|
[20202] | 38 | function piwecard_db_update_from_2_3($old_table, $new_table) { |
---|
[19956] | 39 | $query = 'SELECT * FROM '.$old_table.';'; |
---|
| 40 | $result = pwg_query($query); |
---|
| 41 | |
---|
[19968] | 42 | while($data = pwg_db_fetch_assoc($result)) { |
---|
[19956] | 43 | $insert = array( |
---|
[20202] | 44 | 'ecard_id' => $data['numero'], |
---|
[19956] | 45 | 'sender_name' => $data['nomexp'], |
---|
| 46 | 'sender_email' => $data['adrexp'], |
---|
| 47 | 'recipient_name' => $data['nomdest'], |
---|
| 48 | 'recipient_email' => $data['adrdest'], |
---|
[20059] | 49 | 'title' => $data['sujet'], |
---|
[19956] | 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 | |
---|
[20431] | 64 | /** |
---|
| 65 | * Update the piwecard table in the database from Piwecard version 2.4.a.b3 |
---|
| 66 | * @param String table name |
---|
| 67 | */ |
---|
[20202] | 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 | |
---|
[20431] | 77 | /** |
---|
| 78 | * Create the piwecard entry in the config table of the database |
---|
| 79 | * @param String entry name |
---|
| 80 | */ |
---|
[19956] | 81 | function piwecard_conf_create($name) { |
---|
[20104] | 82 | $query = 'INSERT INTO '.CONFIG_TABLE.' (param,value,comment) VALUES ("'.$name.'","","'.ucfirst($name).' configuration");'; |
---|
[19956] | 83 | pwg_query($query); |
---|
| 84 | } |
---|
| 85 | |
---|
[20431] | 86 | /** |
---|
| 87 | * Delete the piwecard entry in the config table of the database |
---|
| 88 | * @param String entry name |
---|
| 89 | */ |
---|
[19956] | 90 | function piwecard_conf_delete($name){ |
---|
| 91 | $query = 'DELETE FROM '.CONFIG_TABLE.' WHERE param="'.$name.'";'; |
---|
| 92 | pwg_query($query); |
---|
| 93 | } |
---|
| 94 | |
---|
[20431] | 95 | /** |
---|
| 96 | * Rename the piwecard entry in the config table of the database |
---|
| 97 | * @param String old name |
---|
| 98 | * @param String new name |
---|
| 99 | */ |
---|
[19956] | 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 | } |
---|