[11638] | 1 | <?php |
---|
| 2 | |
---|
| 3 | // Add a prefilter |
---|
| 4 | add_event_handler('loc_begin_admin', 'CR_set_prefilter_modify', 50 ); |
---|
[11794] | 5 | add_event_handler('loc_begin_admin', 'CR_modify_submit', 45 ); |
---|
[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"> |
---|
[11794] | 24 | <option value="">--</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 |
---|
[11794] | 50 | ORDER BY cr_id ASC |
---|
[11675] | 51 | ;', |
---|
| 52 | COPYRIGHTS_ADMIN); |
---|
| 53 | $result = pwg_query($query); |
---|
[11638] | 54 | |
---|
[11675] | 55 | $CRoptions = array(); |
---|
| 56 | while ($row = pwg_db_fetch_assoc($result)) { |
---|
| 57 | $CRoptions[$row['cr_id']] = $row['name']; |
---|
| 58 | } |
---|
| 59 | $template->assign('CRoptions', $CRoptions); |
---|
| 60 | |
---|
| 61 | // Get the current Copyright |
---|
| 62 | $image_id = $_GET['image_id']; |
---|
| 63 | $query = sprintf( |
---|
| 64 | 'SELECT `media_id`, `cr_id` |
---|
| 65 | FROM %s |
---|
| 66 | WHERE `media_id` = %d |
---|
| 67 | ;', |
---|
| 68 | COPYRIGHTS_MEDIA, $image_id); |
---|
| 69 | $result = pwg_query($query); |
---|
| 70 | |
---|
| 71 | $CRid = 0; // Default is '--' |
---|
| 72 | while ($row = pwg_db_fetch_assoc($result)) { |
---|
| 73 | $CRid = $row['cr_id']; |
---|
| 74 | } |
---|
| 75 | $template->assign('CRid', $CRid); |
---|
[11638] | 76 | } |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | function CR_modify_submit() |
---|
| 80 | { |
---|
[11675] | 81 | // 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... |
---|
| 82 | if (isset($_GET['image_id'])) |
---|
[11638] | 83 | { |
---|
[11675] | 84 | if (isset($_POST['submit'])) |
---|
| 85 | { |
---|
| 86 | // The data from the submit |
---|
| 87 | $image_id = $_GET['image_id']; |
---|
[11678] | 88 | $CRid = $_POST['copyrightID']; |
---|
[11638] | 89 | |
---|
[11675] | 90 | // Delete the Copyright if it allready exists |
---|
| 91 | $query = sprintf( |
---|
| 92 | 'DELETE |
---|
| 93 | FROM %s |
---|
| 94 | WHERE `media_id` = %d |
---|
| 95 | ;', |
---|
| 96 | COPYRIGHTS_MEDIA, $image_id); |
---|
| 97 | pwg_query($query); |
---|
| 98 | |
---|
[11794] | 99 | // If you assign no copyright, dont put it in the table |
---|
| 100 | if ($CRid != '') { |
---|
| 101 | // Insert the Copyright |
---|
| 102 | $query = sprintf( |
---|
| 103 | 'INSERT INTO %s |
---|
| 104 | VALUES (%d, %d) |
---|
| 105 | ;', |
---|
| 106 | COPYRIGHTS_MEDIA, $image_id, $CRid); |
---|
| 107 | pwg_query($query); |
---|
| 108 | } |
---|
[11675] | 109 | } |
---|
[11638] | 110 | } |
---|
| 111 | } |
---|
| 112 | |
---|
[11794] | 113 | ?> |
---|