1 | <?php |
---|
2 | |
---|
3 | // Add event handlers for the prefilter |
---|
4 | add_event_handler('loc_end_element_set_unit', 'CR_set_prefilter_batch_single', 55 ); |
---|
5 | add_event_handler('loc_begin_element_set_unit', 'CR_batch_single_submit', 50 ); |
---|
6 | |
---|
7 | // Change the variables used by the function that changes the template |
---|
8 | add_event_handler('loc_end_element_set_unit', 'CR_add_batch_single_vars_to_template'); |
---|
9 | |
---|
10 | // Add a prefilter to the template |
---|
11 | function CR_set_prefilter_batch_single() |
---|
12 | { |
---|
13 | global $template; |
---|
14 | $template->set_prefilter('batch_manager_unit', 'CR_batch_single'); |
---|
15 | } |
---|
16 | |
---|
17 | // Insert the copyright selector to the template |
---|
18 | function CR_batch_single($content, &$smarty) |
---|
19 | { |
---|
20 | $search = "#<td><strong>{'Creation date'#"; |
---|
21 | |
---|
22 | // We use the <tr> from the Creation date, and give them a new <tr> |
---|
23 | $replacement = '<td><strong>{\'Copyright\'|@translate}</strong></td> |
---|
24 | <td> |
---|
25 | <select id="copyright-{$element.ID}" name="copyright-{$element.ID}"> |
---|
26 | <option value="0">--</option> |
---|
27 | {html_options options=$CRoptions selected=$CRcopyrights[$element.ID]} |
---|
28 | </select> |
---|
29 | </td> |
---|
30 | </tr> |
---|
31 | |
---|
32 | <tr> |
---|
33 | <td><strong>{\'Creation date\''; |
---|
34 | |
---|
35 | return preg_replace($search, $replacement, $content); |
---|
36 | } |
---|
37 | |
---|
38 | // Assign the variables to the Smarty template |
---|
39 | function CR_add_batch_single_vars_to_template() |
---|
40 | { |
---|
41 | global $template; |
---|
42 | |
---|
43 | load_language('plugin.lang', dirname(__FILE__).'/'); |
---|
44 | |
---|
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); |
---|
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 copyright for each element |
---|
61 | $query = sprintf( |
---|
62 | 'SELECT `media_id`, `cr_id` |
---|
63 | FROM %s |
---|
64 | ;', |
---|
65 | COPYRIGHTS_MEDIA); |
---|
66 | $result = pwg_query($query); |
---|
67 | |
---|
68 | $CRcopyrights = array(); |
---|
69 | while ($row = pwg_db_fetch_assoc($result)) { |
---|
70 | $CRcopyrights[$row['media_id']] = $row['cr_id']; |
---|
71 | } |
---|
72 | |
---|
73 | // Assign the copyrights to the template |
---|
74 | $template->assign('CRcopyrights', $CRcopyrights); |
---|
75 | } |
---|
76 | |
---|
77 | // Catch the submit and update the copyrights tables |
---|
78 | function CR_batch_single_submit() |
---|
79 | { |
---|
80 | if (isset($_POST['submit'])) |
---|
81 | { |
---|
82 | // The image id's: |
---|
83 | $collection = explode(',', $_POST['element_ids']); |
---|
84 | |
---|
85 | // Delete all existing id's of which the copyright is going to be set |
---|
86 | if (count($collection) > 0) { |
---|
87 | $query = sprintf( |
---|
88 | 'DELETE |
---|
89 | FROM %s |
---|
90 | WHERE media_id IN (%s) |
---|
91 | ;', |
---|
92 | COPYRIGHTS_MEDIA, implode(',', $collection)); |
---|
93 | pwg_query($query); |
---|
94 | } |
---|
95 | |
---|
96 | // Add all copyrights to an array |
---|
97 | $edits = array(); |
---|
98 | foreach ($collection as $image_id) { |
---|
99 | // The copyright id's |
---|
100 | $crID = pwg_db_real_escape_string($_POST['copyright-'.$image_id]); |
---|
101 | |
---|
102 | array_push( |
---|
103 | $edits, |
---|
104 | array( |
---|
105 | 'media_id' => $image_id, |
---|
106 | |
---|
107 | 'cr_id' => $crID, |
---|
108 | ) |
---|
109 | ); |
---|
110 | } |
---|
111 | |
---|
112 | // Insert the array to the database |
---|
113 | mass_inserts( |
---|
114 | COPYRIGHTS_MEDIA, // Table name |
---|
115 | array_keys($edits[0]), // Columns |
---|
116 | $edits // Data |
---|
117 | ); |
---|
118 | } |
---|
119 | } |
---|
120 | |
---|
121 | ?> |
---|