1 | <?php |
---|
2 | |
---|
3 | // Add a prefilter |
---|
4 | add_event_handler('loc_end_element_set_unit', 'CR_set_prefilter_batch_single', 55 ); |
---|
5 | add_event_handler('loc_end_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 | function CR_set_prefilter_batch_single() |
---|
11 | { |
---|
12 | global $template; |
---|
13 | $template->set_prefilter('batch_manager_unit', 'CR_batch_single'); |
---|
14 | } |
---|
15 | |
---|
16 | function CR_batch_single($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> |
---|
23 | <select id="copyright-{$element.ID}" name="copyright-{$element.ID}"> |
---|
24 | <option value="0">--</option> |
---|
25 | {html_options options=$CRoptions selected=$CRcopyrights[$element.ID]} |
---|
26 | </select> |
---|
27 | </td> |
---|
28 | </tr> |
---|
29 | |
---|
30 | <tr> |
---|
31 | <td><strong>{\'Creation date\''; |
---|
32 | |
---|
33 | return preg_replace($search, $replacement, $content); |
---|
34 | |
---|
35 | // Dit is een interresant testje - deze functie word dus een aantal keren (3) aangeroepen, |
---|
36 | // en pas de laatste keer is bevat $content meer dan een aantal enters... |
---|
37 | // return $content.'<div id="dwo_test" style="display: none;">'.$content.'</div>'; |
---|
38 | } |
---|
39 | |
---|
40 | function CR_add_batch_single_vars_to_template() |
---|
41 | { |
---|
42 | global $template; |
---|
43 | |
---|
44 | load_language('plugin.lang', dirname(__FILE__).'/'); |
---|
45 | |
---|
46 | // Fetch all the copyrights and assign them to the template |
---|
47 | $query = sprintf( |
---|
48 | 'SELECT `cr_id`,`name` |
---|
49 | FROM %s |
---|
50 | WHERE `visible`<>0 |
---|
51 | ;', |
---|
52 | COPYRIGHTS_ADMIN); |
---|
53 | $result = pwg_query($query); |
---|
54 | |
---|
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 copyright for each element |
---|
62 | $query = sprintf( |
---|
63 | 'SELECT `media_id`, `cr_id` |
---|
64 | FROM %s |
---|
65 | ;', |
---|
66 | COPYRIGHTS_MEDIA); |
---|
67 | $result = pwg_query($query); |
---|
68 | |
---|
69 | $CRcopyrights = array(); |
---|
70 | while ($row = pwg_db_fetch_assoc($result)) { |
---|
71 | $CRcopyrights[$row['media_id']] = $row['cr_id']; |
---|
72 | } |
---|
73 | $template->assign('CRcopyrights', $CRcopyrights); |
---|
74 | } |
---|
75 | |
---|
76 | function CR_batch_single_submit() |
---|
77 | { |
---|
78 | if (isset($_POST['submit'])) |
---|
79 | { |
---|
80 | // The image id's: |
---|
81 | $collection = explode(',', $_POST['element_ids']); |
---|
82 | |
---|
83 | // Delete all existing id's of which the Copyright is going to be set |
---|
84 | if (count($collection) > 0) { |
---|
85 | $query = sprintf( |
---|
86 | 'DELETE |
---|
87 | FROM %s |
---|
88 | WHERE media_id IN (%s) |
---|
89 | ;', |
---|
90 | COPYRIGHTS_MEDIA, implode(',', $collection)); |
---|
91 | pwg_query($query); |
---|
92 | } |
---|
93 | // Add all Copyrights to an array |
---|
94 | $edits = array(); |
---|
95 | foreach ($collection as $image_id) { |
---|
96 | // The copyright id's |
---|
97 | $crID = pwg_db_real_escape_string($_POST['copyright-'.$image_id]); |
---|
98 | |
---|
99 | array_push( |
---|
100 | $edits, |
---|
101 | array( |
---|
102 | 'media_id' => $image_id, |
---|
103 | |
---|
104 | 'cr_id' => $crID, |
---|
105 | ) |
---|
106 | ); |
---|
107 | } |
---|
108 | // Add the array to the database |
---|
109 | mass_inserts( |
---|
110 | COPYRIGHTS_MEDIA, // Table name |
---|
111 | array_keys($edits[0]), // Columns |
---|
112 | $edits // Data |
---|
113 | ); |
---|
114 | } |
---|
115 | } |
---|
116 | |
---|
117 | ?> |
---|