source: extensions/Copyrights/modify.php @ 20461

Last change on this file since 20461 was 11794, checked in by Mattias, 13 years ago

added support for -1 copyright
added an order by cr_id
the plugin handles deletes (no copyright) better

File size: 2.7 KB
Line 
1<?php
2
3// Add a prefilter
4add_event_handler('loc_begin_admin', 'CR_set_prefilter_modify', 50 );
5add_event_handler('loc_begin_admin', 'CR_modify_submit', 45 );
6
7// Change the variables used by the function that changes the template
8add_event_handler('loc_begin_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="copyrightID" name="copyrightID">
24                                <option value="">--</option>
25                                {html_options options=$CRoptions selected=$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        // 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...
39        if (isset($_GET['image_id']))
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                        ORDER BY cr_id ASC
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 current Copyright
62                $image_id = $_GET['image_id'];
63                $query = sprintf(
64                        'SELECT `media_id`, `cr_id`
65                        FROM %s
66                        WHERE `media_id` = %d
67                        ;',
68                        COPYRIGHTS_MEDIA, $image_id);
69                $result = pwg_query($query);
70               
71                $CRid = 0; // Default is '--'
72                while ($row = pwg_db_fetch_assoc($result)) {
73                        $CRid = $row['cr_id'];
74                }
75                $template->assign('CRid', $CRid);
76        }
77}
78
79function CR_modify_submit()
80{
81        // 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...
82        if (isset($_GET['image_id']))
83        {
84                if (isset($_POST['submit']))
85                {
86                        // The data from the submit
87                        $image_id = $_GET['image_id'];
88                        $CRid = $_POST['copyrightID'];
89
90                        // Delete the Copyright if it allready exists
91                        $query = sprintf(
92                                'DELETE
93                                FROM %s
94                                WHERE `media_id` = %d
95                                ;',
96                                COPYRIGHTS_MEDIA, $image_id);
97                        pwg_query($query);
98
99                        // If you assign no copyright, dont put it in the table
100                        if ($CRid != '') {
101                                // Insert the Copyright
102                                $query = sprintf(
103                                        'INSERT INTO %s
104                                        VALUES (%d, %d)
105                                        ;',
106                                        COPYRIGHTS_MEDIA, $image_id, $CRid);
107                                pwg_query($query);
108                        }
109                }
110        }
111}
112
113?>
Note: See TracBrowser for help on using the repository browser.