source: extensions/Copyrights/modify.php @ 11735

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

Finished adding comments to the code

File size: 2.6 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', 50 );
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="0">--</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                        ;',
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 current Copyright
61                $image_id = $_GET['image_id'];
62                $query = sprintf(
63                        'SELECT `media_id`, `cr_id`
64                        FROM %s
65                        WHERE `media_id` = %d
66                        ;',
67                        COPYRIGHTS_MEDIA, $image_id);
68                $result = pwg_query($query);
69               
70                $CRid = 0; // Default is '--'
71                while ($row = pwg_db_fetch_assoc($result)) {
72                        $CRid = $row['cr_id'];
73                }
74                $template->assign('CRid', $CRid);
75        }
76}
77
78function CR_modify_submit()
79{
80        // 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...
81        if (isset($_GET['image_id']))
82        {
83                if (isset($_POST['submit']))
84                {
85                        // The data from the submit
86                        $image_id = $_GET['image_id'];
87                        $CRid = $_POST['copyrightID'];
88
89                        // Delete the Copyright if it allready exists
90                        $query = sprintf(
91                                'DELETE
92                                FROM %s
93                                WHERE `media_id` = %d
94                                ;',
95                                COPYRIGHTS_MEDIA, $image_id);
96                        pwg_query($query);
97
98                // Insert the Copyright
99                $query = sprintf(
100                  'INSERT INTO %s
101                  VALUES (%d, %d)
102                  ;',
103                  COPYRIGHTS_MEDIA, $image_id, $CRid);
104                pwg_query($query);
105                }
106        }
107}
108
109?>
Note: See TracBrowser for help on using the repository browser.