1 | <?php |
---|
2 | |
---|
3 | // Add a prefilter |
---|
4 | add_event_handler('loc_begin_admin', 'CR_set_prefilter_modify', 50 ); |
---|
5 | add_event_handler('loc_begin_admin_page', 'CR_modify_submit', 45 ); |
---|
6 | |
---|
7 | // Change the variables used by the function that changes the template |
---|
8 | add_event_handler('loc_begin_admin_page', 'CR_add_modify_vars_to_template'); |
---|
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 = "#<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 = '<strong>{\'Copyright\'|@translate}</strong> |
---|
22 | <br> |
---|
23 | <select id="copyrightID" name="copyrightID"> |
---|
24 | <option value="">--</option> |
---|
25 | {html_options options=$CRoptions selected=$CRid} |
---|
26 | </select> |
---|
27 | </p> |
---|
28 | |
---|
29 | </p> |
---|
30 | <p> |
---|
31 | <strong>{\'Creation date\''; |
---|
32 | |
---|
33 | return preg_replace($search, $replacement, $content); |
---|
34 | } |
---|
35 | |
---|
36 | function CR_add_modify_vars_to_template() |
---|
37 | { |
---|
38 | if (isset($_GET['page']) and 'photo' == $_GET['page'] and isset($_GET['image_id'])) |
---|
39 | { |
---|
40 | global $template; |
---|
41 | |
---|
42 | load_language('plugin.lang', dirname(__FILE__).'/'); |
---|
43 | |
---|
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 |
---|
49 | ORDER BY cr_id ASC |
---|
50 | ;', |
---|
51 | COPYRIGHTS_ADMIN); |
---|
52 | $result = pwg_query($query); |
---|
53 | |
---|
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); |
---|
75 | } |
---|
76 | } |
---|
77 | |
---|
78 | function CR_modify_submit() |
---|
79 | { |
---|
80 | if (isset($_GET['page']) and 'photo' == $_GET['page'] and isset($_GET['image_id'])) |
---|
81 | { |
---|
82 | if (isset($_POST['submit'])) |
---|
83 | { |
---|
84 | // The data from the submit |
---|
85 | $image_id = $_GET['image_id']; |
---|
86 | $CRid = $_POST['copyrightID']; |
---|
87 | |
---|
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 | |
---|
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 | } |
---|
107 | } |
---|
108 | } |
---|
109 | } |
---|
110 | |
---|
111 | ?> |
---|