[11638] | 1 | <?php |
---|
| 2 | |
---|
| 3 | // Add a prefilter |
---|
| 4 | add_event_handler('loc_begin_admin', 'CR_set_prefilter_modify', 50 ); |
---|
[22300] | 5 | add_event_handler('loc_begin_admin_page', 'CR_modify_submit', 45 ); |
---|
[11638] | 6 | |
---|
| 7 | // Change the variables used by the function that changes the template |
---|
[22300] | 8 | add_event_handler('loc_begin_admin_page', '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 | { |
---|
[22300] | 18 | $search = "#<strong>{'Creation date'#"; // Not ideal, but ok for now :) |
---|
[11638] | 19 | |
---|
| 20 | // We use the <tr> from the Creation date, and give them a new <tr> |
---|
[22300] | 21 | $replacement = '<strong>{\'Copyright\'|@translate}</strong> |
---|
| 22 | <br> |
---|
[11678] | 23 | <select id="copyrightID" name="copyrightID"> |
---|
[11794] | 24 | <option value="">--</option> |
---|
[11675] | 25 | {html_options options=$CRoptions selected=$CRid} |
---|
[11638] | 26 | </select> |
---|
[22300] | 27 | </p> |
---|
[11638] | 28 | |
---|
[22300] | 29 | </p> |
---|
| 30 | <p> |
---|
| 31 | <strong>{\'Creation date\''; |
---|
[11638] | 32 | |
---|
| 33 | return preg_replace($search, $replacement, $content); |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | function CR_add_modify_vars_to_template() |
---|
| 37 | { |
---|
[22300] | 38 | if (isset($_GET['page']) and 'photo' == $_GET['page'] and isset($_GET['image_id'])) |
---|
[11675] | 39 | { |
---|
| 40 | global $template; |
---|
[11638] | 41 | |
---|
[11675] | 42 | load_language('plugin.lang', dirname(__FILE__).'/'); |
---|
[11638] | 43 | |
---|
[11675] | 44 | // Fetch all the copyrights and assign them to the template |
---|
| 45 | $query = sprintf( |
---|
| 46 | 'SELECT `cr_id`,`name` |
---|
| 47 | FROM %s |
---|
| 48 | WHERE `visible`<>0 |
---|
[11794] | 49 | ORDER BY cr_id ASC |
---|
[11675] | 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 | { |
---|
[22300] | 80 | if (isset($_GET['page']) and 'photo' == $_GET['page'] and isset($_GET['image_id'])) |
---|
[11638] | 81 | { |
---|
[11675] | 82 | if (isset($_POST['submit'])) |
---|
| 83 | { |
---|
| 84 | // The data from the submit |
---|
| 85 | $image_id = $_GET['image_id']; |
---|
[11678] | 86 | $CRid = $_POST['copyrightID']; |
---|
[11638] | 87 | |
---|
[11675] | 88 | // Delete the Copyright if it allready exists |
---|
| 89 | $query = sprintf( |
---|
| 90 | 'DELETE |
---|
| 91 | FROM %s |
---|
| 92 | WHERE `media_id` = %d |
---|
| 93 | ;', |
---|
| 94 | COPYRIGHTS_MEDIA, $image_id); |
---|
| 95 | pwg_query($query); |
---|
| 96 | |
---|
[11794] | 97 | // If you assign no copyright, dont put it in the table |
---|
| 98 | if ($CRid != '') { |
---|
| 99 | // Insert the Copyright |
---|
| 100 | $query = sprintf( |
---|
| 101 | 'INSERT INTO %s |
---|
| 102 | VALUES (%d, %d) |
---|
| 103 | ;', |
---|
| 104 | COPYRIGHTS_MEDIA, $image_id, $CRid); |
---|
| 105 | pwg_query($query); |
---|
| 106 | } |
---|
[11675] | 107 | } |
---|
[11638] | 108 | } |
---|
| 109 | } |
---|
| 110 | |
---|
[11794] | 111 | ?> |
---|