source: extensions/Copyrights/modify.php @ 11638

Last change on this file since 11638 was 11638, checked in by J.Commelin, 13 years ago

Added Copyrights editability to picture_modify

File size: 2.3 KB
Line 
1<?php
2
3// Add a prefilter
4add_event_handler('loc_begin_admin', 'CR_set_prefilter_modify', 50 );
5add_event_handler('loc_end_admin', 'CR_modify_submit', 50 );
6
7// Change the variables used by the function that changes the template
8add_event_handler('loc_end_admin', 'CR_add_modify_vars_to_template');
9
10function CR_set_prefilter_modify()
11{
12        global $template;
13        $template->set_prefilter('picture_modify', 'CR_modify');
14}
15
16function CR_modify($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" name="copyright">
24                                <option value="0">--</option>
25                                {html_options options=$CRoptions selected=$CRcopyrights[$CRid]}
26                        </select>
27                </td>
28        </tr>
29       
30        <tr>
31                <td><strong>{\'Creation date\'';
32
33    return preg_replace($search, $replacement, $content);
34}
35
36function CR_add_modify_vars_to_template()
37{
38        global $template;
39
40        load_language('plugin.lang', dirname(__FILE__).'/');
41
42        // Fetch all the copyrights and assign them to the template
43        $query = sprintf(
44                'SELECT `cr_id`,`name`
45                FROM %s
46                WHERE `visible`<>0
47                ;',
48                COPYRIGHTS_ADMIN);
49        $result = pwg_query($query);
50
51        $CRoptions = array();
52        while ($row = pwg_db_fetch_assoc($result)) {
53                $CRoptions[$row['cr_id']] = $row['name'];
54        }
55        $template->assign('CRoptions', $CRoptions);
56       
57        // Get the current Copyright
58        $image_id = $_GET['image_id']);
59        $query = sprintf(
60                'SELECT `media_id`, `cr_id`
61                FROM %s
62    WHERE `media_id` = %d
63                ;',
64                COPYRIGHTS_MEDIA, $image_id);
65        $result = pwg_query($query);
66       
67  $CRid = 0; // Default is '--'
68        while ($row = pwg_db_fetch_assoc($result)) {
69                $CRid = $row['cr_id'];
70        }
71        $template->assign('CRid', $CRid);
72}
73
74function CR_modify_submit()
75{
76        if (isset($_POST['submit']))
77        {
78                // The data from the submit
79                $image_id = $_GET['image_id']);
80    $CRid = $_POST['copyright'];
81
82                // Delete the Copyright if it allready exists
83                $query = sprintf(
84                        'DELETE
85                        FROM %s
86                        WHERE `media_id` = %d
87                        ;',
88                        COPYRIGHTS_MEDIA, $image_id);
89                pwg_query($query);
90
91    // Insert the Copyright
92    $query = sprintf(
93      'INSERT INTO %s
94      VALUES (%d, %d)
95      ;',
96      COPYRIGHTS_MEDIA, $image_id, $CRid);
97    pwg_query($query);
98        }
99}
100
101?>
Note: See TracBrowser for help on using the repository browser.