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', 55 ); |
---|
6 | |
---|
7 | // Change the variables used by the function that changes the template |
---|
8 | add_event_handler('loc_begin_admin', '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 | {html_options name=copyright-{$element.ID} options=$CRoptions} |
---|
24 | </td> |
---|
25 | </tr> |
---|
26 | |
---|
27 | <tr> |
---|
28 | <td><strong>{\'Creation date\''; |
---|
29 | |
---|
30 | return preg_replace($search, $replacement, $content); |
---|
31 | |
---|
32 | // Dit is een interresant testje - deze functie word dus een aantal keren (3) aangeroepen, |
---|
33 | // en pas de laatste keer is bevat $content meer dan een aantal enters... |
---|
34 | // return $content.'<div id="dwo_test" style="display: none;">'.$content.'</div>'; |
---|
35 | } |
---|
36 | |
---|
37 | function CR_add_batch_single_vars_to_template() |
---|
38 | { |
---|
39 | global $template; |
---|
40 | |
---|
41 | load_language('plugin.lang', dirname(__FILE__).'/'); |
---|
42 | |
---|
43 | // Fetch all the copyrights and assign them to the template |
---|
44 | $query = sprintf( |
---|
45 | 'SELECT `cr_id`,`name` |
---|
46 | FROM %s |
---|
47 | WHERE `visible`<>0 |
---|
48 | ;', |
---|
49 | COPYRIGHTS_ADMIN); |
---|
50 | $result = pwg_query($query); |
---|
51 | |
---|
52 | $CRoptions = array(); |
---|
53 | while ($row = pwg_db_fetch_assoc($result)) { |
---|
54 | $CRoptions[$row['cr_id']] = $row['name']; |
---|
55 | } |
---|
56 | $template->assign('CRoptions', $CRoptions); |
---|
57 | } |
---|
58 | |
---|
59 | function CR_batch_single_submit() |
---|
60 | { |
---|
61 | // The image id's: |
---|
62 | $collection = explode(',', $_POST['element_ids']); |
---|
63 | |
---|
64 | // Delete all existing id's of which the Copyright is going to be set |
---|
65 | if (count($collection) > 0) { |
---|
66 | $query = sprintf( |
---|
67 | 'DELETE |
---|
68 | FROM %s |
---|
69 | WHERE media_id IN (%s) |
---|
70 | ;', |
---|
71 | COPYRIGHTS_MEDIA, implode(',', $collection)); |
---|
72 | pwg_query($query); |
---|
73 | } |
---|
74 | // Add all Copyrights to an array |
---|
75 | $edits = array(); |
---|
76 | foreach ($collection as $image_id) { |
---|
77 | // The copyright id's |
---|
78 | $crID = pwg_db_real_escape_string($_POST['copyrightID-'.$image_id]); |
---|
79 | |
---|
80 | array_push( |
---|
81 | $edits, |
---|
82 | array( |
---|
83 | 'media_id' => $image_id, |
---|
84 | 'cr_id' => $crID, |
---|
85 | ) |
---|
86 | ); |
---|
87 | } |
---|
88 | // Add the array to the database |
---|
89 | mass_inserts( |
---|
90 | COPYRIGHTS_MEDIA, // Table name |
---|
91 | array_keys($edits[0]), // Columns |
---|
92 | $edits // Data |
---|
93 | ); |
---|
94 | } |
---|
95 | |
---|
96 | ?> |
---|