-
Notifications
You must be signed in to change notification settings - Fork 0
/
modify.php
111 lines (94 loc) · 2.55 KB
/
modify.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
// Add a prefilter
add_event_handler('loc_begin_admin', 'CR_set_prefilter_modify', 50 );
add_event_handler('loc_begin_admin_page', 'CR_modify_submit', 45 );
// Change the variables used by the function that changes the template
add_event_handler('loc_begin_admin_page', 'CR_add_modify_vars_to_template');
function CR_set_prefilter_modify()
{
global $template;
$template->set_prefilter('picture_modify', 'CR_modify');
}
function CR_modify($content)
{
$search = "#<strong>{'Creation date'#"; // Not ideal, but ok for now :)
// We use the <tr> from the Creation date, and give them a new <tr>
$replacement = '<strong>{\'Copyright\'|@translate}</strong>
<br>
<select id="copyrightID" name="copyrightID">
<option value="">--</option>
{html_options options=$CRoptions selected=$CRid}
</select>
</p>
</p>
<p>
<strong>{\'Creation date\'';
return preg_replace($search, $replacement, $content);
}
function CR_add_modify_vars_to_template()
{
if (isset($_GET['page']) and 'photo' == $_GET['page'] and isset($_GET['image_id']))
{
global $template;
load_language('plugin.lang', dirname(__FILE__).'/');
// Fetch all the copyrights and assign them to the template
$query = sprintf(
'SELECT `cr_id`,`name`
FROM %s
WHERE `visible`<>0
ORDER BY cr_id ASC
;',
COPYRIGHTS_ADMIN);
$result = pwg_query($query);
$CRoptions = array();
while ($row = pwg_db_fetch_assoc($result)) {
$CRoptions[$row['cr_id']] = $row['name'];
}
$template->assign('CRoptions', $CRoptions);
// Get the current Copyright
$image_id = $_GET['image_id'];
$query = sprintf(
'SELECT `media_id`, `cr_id`
FROM %s
WHERE `media_id` = %d
;',
COPYRIGHTS_MEDIA, $image_id);
$result = pwg_query($query);
$CRid = 0; // Default is '--'
while ($row = pwg_db_fetch_assoc($result)) {
$CRid = $row['cr_id'];
}
$template->assign('CRid', $CRid);
}
}
function CR_modify_submit()
{
if (isset($_GET['page']) and 'photo' == $_GET['page'] and isset($_GET['image_id']))
{
if (isset($_POST['submit']))
{
// The data from the submit
$image_id = $_GET['image_id'];
$CRid = $_POST['copyrightID'];
// Delete the Copyright if it allready exists
$query = sprintf(
'DELETE
FROM %s
WHERE `media_id` = %d
;',
COPYRIGHTS_MEDIA, $image_id);
pwg_query($query);
// If you assign no copyright, dont put it in the table
if ($CRid != '') {
// Insert the Copyright
$query = sprintf(
'INSERT INTO %s
VALUES (%d, %d)
;',
COPYRIGHTS_MEDIA, $image_id, $CRid);
pwg_query($query);
}
}
}
}
?>