set_prefilter('batch_manager_unit', 'EA_batch_single');
}
// Insert the copyright selector to the template
function EA_batch_single($content, &$smarty)
{
// Replace the piwigo author by our own author stuff
$search = '/
{foreach from=$EAoptions item=option}
{/foreach}
';
return preg_replace($search, $replacement, $content);
}
// Assign the variables to the Smarty template
function EA_add_batch_single_vars_to_template()
{
global $template;
load_language('plugin.lang', dirname(__FILE__).'/');
// Fetch all the author names and assign them to the template
$query = sprintf(
'SELECT `author_id`,`name`
FROM %s
;',
AUTHORS);
$result = pwg_query($query);
$EAoptions = array();
while ($row = pwg_db_fetch_assoc($result)) {
$EAoptions[$row['author_id']] = $row['name'];
}
$template->assign('EAoptions', $EAoptions);
// Get the author name for every image id
$query = sprintf(
'SELECT `id`, `author`
FROM %s
;',
IMAGES);
$result = pwg_query($query);
// Get the author id for each element
$EAauthors = array();
while ($row = pwg_db_fetch_assoc($result)) {
$EAauthors[$row['id']] = $row['author'];
}
// Assign the copyrights to the template
$template->assign('EAauthors', $EAauthors);
}
// Catch the submit and update the copyrights tables
function EA_batch_single_submit()
{
if (isset($_POST['submit']))
{
// The image id's:
$collection = explode(',', $_POST['element_ids']);
// Check all authors, and give them defaults
$edits = array();
foreach ($collection as $image_id) {
// The copyright name's
$name = pwg_db_real_escape_string($_POST['author-'.$image_id]);
// Create the array to be updated
array_push(
$edits,
array(
'id' => $image_id,
'author' => $name,
)
);
// Add them to the images table
// (yes, this is double work, since the author will be set by the piwigo core. But its not set right now, and insert_default_CR needs it...)
mass_updates(
IMAGES,
array('primary' => array('id'), 'update' => array('author')),
$edits
);
// Insert the default copyrights
insert_default_CR($name);
}
}
}
?>