asset_batch_form()vpx_beheer_mm/asset/asset_batch.inc, line 37
<?php
function asset_batch_form() {
unset($_SESSION['autorisation_group_cache'], $_SESSION['foreign_app_cache']);
// init the progressbar
asset_js_progress();
$form['#attributes'] = array('onSubmit' => 'monitorProgress();');
$form['asset_list'] = array(
'#type' => 'fieldset',
'#title' => t('Assets that will be affected by the chosen action(s)'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#weight' => 1,
'#prefix' => '<div id="batch-asset-list-fieldset">',
'#suffix' => '</div>',
);
// create the asset list
$item_limit = variable_get('vpx_connector_item_limit', 200);
$url = sprintf('/asset?limit=%d&granted=TRUE', $item_limit);
if (isset($_SESSION['asset_filter_form']['filter'])) {
$url .= $_SESSION['asset_filter_form']['filter'];
}
// perform the request
$vpx = new vpx_connector();
$result = $vpx->request('GET', $url);
// get the item count
$item_count = (int)$result->header->item_count_total;
$batch_asset_item_limit = variable_get('batch_asset_item_limit', 2000);
$show_assets = ($item_count <= variable_get('batch_asset_item_display_limit', 200));
$_SESSION['show_assets'] = $show_assets;
db_query("DROP TABLE IF EXISTS {tempassets}");
db_query("CREATE TABLE {tempassets} (
assetid VARCHAR(255) NOT NULL,
title VARCHAR(255) NULL,
creator VARCHAR(255) NULL,
subject VARCHAR(255) NULL,
date VARCHAR(255) NULL,
description TEXT NULL,
publisher VARCHAR(255) NULL,
type VARCHAR(255) NULL,
isreferencedby VARCHAR(255) NULL,
issued VARCHAR(255) NULL
)");
if ($item_count === 0) {
$form['asset_list']['empty'] = array(
'#type' => 'markup',
'#value' => t('No assets found...'),
);
}
else {
for ($i = 0; $i < ceil($item_count / $item_limit); $i++) {
if (!isset($result)) {
$result = $vpx->request('GET', $url . sprintf('&offset=%d', $i * $item_limit));
variable_set('progress', ceil(100 * ($i / ($item_count / $item_limit))));
$vpx->check_result($result, '');
}
if ($show_assets) {
drupal_add_js(drupal_get_path('module', 'pa') .'/pa.js');
$form['asset_list']['toggle'] = array(
'#type' => 'checkbox',
'#title' => t('Select all/none'),
'#default_value' => TRUE,
'#attributes' => array(
'onclick' => 'pa_checkbox_toggle_all(".asset_checkbox");',
),
);
}
foreach ($result->items->item as $item) {
$asset_id = (string)$item->asset_id;
$title = pa_trim_string((string)$item->dublin_core[0]->title);
db_query("INSERT INTO {tempassets} (assetid, title, creator , subject, date, description,
publisher, type, isreferencedby, issued)
VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",
$asset_id, $title,
pa_trim_string((string)$item->dublin_core[0]->creator),
pa_trim_string((string)$item->dublin_core[0]->subject),
pa_trim_string((string)$item->dublin_core[0]->date),
pa_trim_string((string)$item->dublin_core[0]->description),
pa_trim_string((string)$item->dublin_core[0]->publisher),
pa_trim_string((string)$item->dublin_core[0]->type),
pa_trim_string((string)$item->qualified_dublin_core[0]->isreferencedby),
pa_trim_string((string)$item->qualified_dublin_core[0]->issued)
);
if ($show_assets) {
$form['asset_list']['asset_'. $asset_id] = array(
'#type' => ($show_assets) ? 'checkbox' : 'hidden',
'#title' => ($show_assets) ? $title : '',
'#default_value' => TRUE,
'#attributes' => array(
'class' => 'asset_checkbox',
),
);
}
}
if ($show_assets === FALSE) {
$form['asset_list']['show_assets'] = array(
'#type' => 'markup',
'#value' => t('Too many assets to be displayed here. All !count assets have been automatically selected.', array('!count' => $item_count)),
);
}
unset($result);
}
}
// create collection list
$url = sprintf('/collection?limit=%d&order_by=title', $item_limit);
$result = $vpx->request('GET', $url);
$item_count = (int)$result->header->item_count_total;
$form['collection_list'] = array(
'#type' => 'fieldset',
'#title' => t('Add the selected items to one or more collections'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#weight' => 2,
'#prefix' => '<div id="batch-collection-list-fieldset">',
'#suffix' => '</div><div class="clear-block"></div>',
);
if ($item_count === 0) {
$form['collection_list']['empty'] = array(
'#type' => 'markup',
'#value' => t('No collections found...'),
);
}
else {
for ($i = 0; $i < ceil($item_count / $item_limit); $i++) {
if (!isset($result)) {
$result = $vpx->request('GET', $url . sprintf('&offset=%d', $i * $item_limit));
$vpx->check_result($result, '');
}
foreach ($result->items->item as $item) {
$coll_id = (string)$item->coll_id;
$title = pa_trim_string((string)$item->title);
$description = (string)$item->description;
$form['collection_list']['collection_'. $coll_id] = array(
'#type' => 'checkbox',
'#title' => $title,
'#description' => $description,
'#default_value' => FALSE,
);
}
unset($result);
}
}
$form['acl'] = asset_batch_acl_form();
$form['app'] = asset_batch_app_form();
if ($show_assets) {
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Start batch operation',
'#submit' => array('asset_batch_form_submit'),
'#weight' => -2,
);
}
$form['progressbar'] = array(
'#type' => 'item',
'#prefix' => '<span>Processing: </span><br><span class="progressbar" id="processprogressbar">0%</span>'
);
$form['save_file'] = array(
'#type' => 'checkbox',
'#title' => t('Save as file'),
'#default_value' => TRUE,
'#weight' => 0
);
$form['template'] = array(
'#type' => 'select',
'#title' => t('Template'),
'#options' => array('ftp_upload_vuf_asset_batch_video_template' => t('Template 1'),
'ftp_upload_vuf_asset_batch_video_template2' => t('Template 2')
),
'#default_value' => TRUE,
'#weight' => 0
);
$form['submit_xml'] = array(
'#type' => 'submit',
'#name' => 'generate_xml',
'#value' => 'Generate XML',
'#submit' => array('asset_batch_form_submit'),
'#weight' => -1,
);
return $form;
}
?>