[11638] | 1 | <?php |
---|
| 2 | |
---|
| 3 | // Add a prefilter |
---|
| 4 | add_event_handler('loc_begin_admin', 'CR_set_prefilter_modify', 50 ); |
---|
[11675] | 5 | add_event_handler('loc_begin_admin', 'CR_modify_submit', 50 ); |
---|
[11638] | 6 | |
---|
| 7 | // Change the variables used by the function that changes the template |
---|
[11675] | 8 | add_event_handler('loc_begin_admin', 'CR_add_modify_vars_to_template'); |
---|
[11638] | 9 | |
---|
| 10 | function CR_set_prefilter_modify() |
---|
| 11 | { |
---|
| 12 | global $template; |
---|
| 13 | $template->set_prefilter('picture_modify', 'CR_modify'); |
---|
| 14 | } |
---|
| 15 | |
---|
| 16 | function CR_modify($content, &$smarty) |
---|
| 17 | { |
---|
| 18 | $search = "#<td><strong>{'Creation date'#"; // Not ideal, but ok for now :) |
---|
| 19 | |
---|
| 20 | // We use the <tr> from the Creation date, and give them a new <tr> |
---|
| 21 | $replacement = '<td><strong>{\'Copyright\'|@translate}</strong></td> |
---|
| 22 | <td> |
---|
[11678] | 23 | <select id="copyrightID" name="copyrightID"> |
---|
[11638] | 24 | <option value="0">--</option> |
---|
[11675] | 25 | {html_options options=$CRoptions selected=$CRid} |
---|
[11638] | 26 | </select> |
---|
| 27 | </td> |
---|
| 28 | </tr> |
---|
| 29 | |
---|
| 30 | <tr> |
---|
| 31 | <td><strong>{\'Creation date\''; |
---|
| 32 | |
---|
| 33 | return preg_replace($search, $replacement, $content); |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | function CR_add_modify_vars_to_template() |
---|
| 37 | { |
---|
[11675] | 38 | // Check if we are at the modify page (the problem is that this will send the stuff to every admin page that has an ?image_id... |
---|
| 39 | if (isset($_GET['image_id'])) |
---|
| 40 | { |
---|
| 41 | global $template; |
---|
[11638] | 42 | |
---|
[11675] | 43 | load_language('plugin.lang', dirname(__FILE__).'/'); |
---|
[11638] | 44 | |
---|
[11675] | 45 | // Fetch all the copyrights and assign them to the template |
---|
| 46 | $query = sprintf( |
---|
| 47 | 'SELECT `cr_id`,`name` |
---|
| 48 | FROM %s |
---|
| 49 | WHERE `visible`<>0 |
---|
| 50 | ;', |
---|
| 51 | COPYRIGHTS_ADMIN); |
---|
| 52 | $result = pwg_query($query); |
---|
[11638] | 53 | |
---|
[11675] | 54 | $CRoptions = array(); |
---|
| 55 | while ($row = pwg_db_fetch_assoc($result)) { |
---|
| 56 | $CRoptions[$row['cr_id']] = $row['name']; |
---|
| 57 | } |
---|
| 58 | $template->assign('CRoptions', $CRoptions); |
---|
| 59 | |
---|
| 60 | // Get the current Copyright |
---|
| 61 | $image_id = $_GET['image_id']; |
---|
| 62 | $query = sprintf( |
---|
| 63 | 'SELECT `media_id`, `cr_id` |
---|
| 64 | FROM %s |
---|
| 65 | WHERE `media_id` = %d |
---|
| 66 | ;', |
---|
| 67 | COPYRIGHTS_MEDIA, $image_id); |
---|
| 68 | $result = pwg_query($query); |
---|
| 69 | |
---|
| 70 | $CRid = 0; // Default is '--' |
---|
| 71 | while ($row = pwg_db_fetch_assoc($result)) { |
---|
| 72 | $CRid = $row['cr_id']; |
---|
| 73 | } |
---|
| 74 | $template->assign('CRid', $CRid); |
---|
[11638] | 75 | } |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | function CR_modify_submit() |
---|
| 79 | { |
---|
[11675] | 80 | // Check if we are at the modify page (the problem is that this will send the stuff to every admin page that has an ?image_id... |
---|
| 81 | if (isset($_GET['image_id'])) |
---|
[11638] | 82 | { |
---|
[11675] | 83 | if (isset($_POST['submit'])) |
---|
| 84 | { |
---|
| 85 | // The data from the submit |
---|
| 86 | $image_id = $_GET['image_id']; |
---|
[11678] | 87 | $CRid = $_POST['copyrightID']; |
---|
[11638] | 88 | |
---|
[11675] | 89 | // Delete the Copyright if it allready exists |
---|
| 90 | $query = sprintf( |
---|
| 91 | 'DELETE |
---|
| 92 | FROM %s |
---|
| 93 | WHERE `media_id` = %d |
---|
| 94 | ;', |
---|
| 95 | COPYRIGHTS_MEDIA, $image_id); |
---|
| 96 | pwg_query($query); |
---|
| 97 | |
---|
| 98 | // Insert the Copyright |
---|
[11638] | 99 | $query = sprintf( |
---|
[11675] | 100 | 'INSERT INTO %s |
---|
| 101 | VALUES (%d, %d) |
---|
| 102 | ;', |
---|
| 103 | COPYRIGHTS_MEDIA, $image_id, $CRid); |
---|
[11638] | 104 | pwg_query($query); |
---|
[11675] | 105 | } |
---|
[11638] | 106 | } |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | ?> |
---|