set_prefilter('picture_modify', 'CR_modify');
}
function CR_modify($content, &$smarty)
{
$search = "#
{'Creation date'#"; // Not ideal, but ok for now :)
// We use the
from the Creation date, and give them a new
$replacement = '
{\'Copyright\'|@translate}
{\'Creation date\'';
return preg_replace($search, $replacement, $content);
}
function CR_add_modify_vars_to_template()
{
// 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...
if (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()
{
// 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...
if (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);
}
}
}
}
?>