1 | <?php |
---|
2 | |
---|
3 | // Add a prefilter |
---|
4 | add_event_handler('loc_begin_admin', 'EA_set_prefilter_modify', 50 ); |
---|
5 | add_event_handler('loc_begin_admin', 'EA_modify_submit', 46 ); // CR weight + 1 |
---|
6 | |
---|
7 | // Change the variables used by the function that changes the template |
---|
8 | add_event_handler('loc_begin_admin', 'EA_add_modify_vars_to_template'); |
---|
9 | |
---|
10 | function EA_set_prefilter_modify() |
---|
11 | { |
---|
12 | global $template; |
---|
13 | $template->set_prefilter('picture_modify', 'EA_modify'); |
---|
14 | } |
---|
15 | |
---|
16 | function EA_modify($content, &$smarty) |
---|
17 | { |
---|
18 | // Replace the piwigo author by our own author stuff |
---|
19 | $search = '/<td><input type="text" class="large" name="author".*?<\/td>/is'; |
---|
20 | |
---|
21 | $replacement = '<td> |
---|
22 | <select id="author" name="author"> |
---|
23 | <option value="">--</option> |
---|
24 | {foreach from=$EAoptions item=option} |
---|
25 | <option value="{$option}"{if $EAname == $option} selected="selected"{/if}> |
---|
26 | {$option} |
---|
27 | </option> |
---|
28 | {/foreach} |
---|
29 | </select> |
---|
30 | </td>'; |
---|
31 | |
---|
32 | return preg_replace($search, $replacement, $content); |
---|
33 | } |
---|
34 | |
---|
35 | function EA_add_modify_vars_to_template() |
---|
36 | { |
---|
37 | // 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... |
---|
38 | if (isset($_GET['image_id'])) |
---|
39 | { |
---|
40 | global $template; |
---|
41 | |
---|
42 | load_language('plugin.lang', dirname(__FILE__).'/'); |
---|
43 | |
---|
44 | // Fetch all the authors and assign them to the template |
---|
45 | $query = sprintf( |
---|
46 | 'SELECT `author_id`,`name` |
---|
47 | FROM %s |
---|
48 | ;', |
---|
49 | AUTHORS); |
---|
50 | $result = pwg_query($query); |
---|
51 | |
---|
52 | $EAoptions = array(); |
---|
53 | while ($row = pwg_db_fetch_assoc($result)) { |
---|
54 | $EAoptions[$row['author_id']] = $row['name']; |
---|
55 | } |
---|
56 | $template->assign('EAoptions', $EAoptions); |
---|
57 | |
---|
58 | // Get the current author |
---|
59 | $image_id = $_GET['image_id']; |
---|
60 | $query = sprintf( |
---|
61 | 'SELECT author |
---|
62 | FROM %s |
---|
63 | WHERE id = %d |
---|
64 | ;', |
---|
65 | IMAGES, $image_id); |
---|
66 | $result = pwg_query($query); |
---|
67 | |
---|
68 | $EAname = '--'; // Default is '--' |
---|
69 | while ($row = pwg_db_fetch_assoc($result)) { |
---|
70 | $EAname = $row['author']; |
---|
71 | } |
---|
72 | $template->assign('EAname', $EAname); |
---|
73 | } |
---|
74 | } |
---|
75 | |
---|
76 | function EA_modify_submit() |
---|
77 | { |
---|
78 | // 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... |
---|
79 | if (isset($_GET['image_id'])) |
---|
80 | { |
---|
81 | if (isset($_POST['submit'])) |
---|
82 | { |
---|
83 | // The data from the submit |
---|
84 | $image_id = $_GET['image_id']; |
---|
85 | $name = pwg_db_real_escape_string($_POST['author']); |
---|
86 | |
---|
87 | // Dont update anything when the name is empty |
---|
88 | if(!$name) |
---|
89 | return false; |
---|
90 | |
---|
91 | // Add him to the images table |
---|
92 | // (yes, this is double work, since the author will be set by the piwigo core. But its not set right now, and insert_default_CR needs it...) |
---|
93 | $query = sprintf( |
---|
94 | 'UPDATE %s |
---|
95 | SET author=\'%s\' |
---|
96 | WHERE id=%d |
---|
97 | ;', |
---|
98 | IMAGES, $name, $image_id); |
---|
99 | pwg_query($query); |
---|
100 | |
---|
101 | // Insert the default copyrights |
---|
102 | insert_default_CR($name); |
---|
103 | } |
---|
104 | } |
---|
105 | } |
---|
106 | |
---|
107 | ?> |
---|