',
// '#weight' => -5,
// );
$form['title'] = array(
'#type' => 'textfield',
'#title' => t('Title'),
);
$form['author'] = array(
'#type' => 'textfield',
'#title' => t('Author'),
);
$form['description'] = array(
'#type' => 'textarea',
'#title' => t('Description'),
'#rows' => 3,
);
$form['permissions'] = array(
'#theme' => 'asset_upload_permissions',
'#tree' => false,
);
$form['permissions']['status'] = array(
'#type' => 'radios',
'#title' => t('Permissions'),
'#description' => t('Select the permissions for this asset. Selecting Public will allow anyone with asset permissions to use this asset. By selecting Private, you can restrict which roles, if any, can access this asset. If you select Private and do not select any roles, you will be the only user with access to this asset.'),
'#required' => true,
'#default_value' => $parent->status,
'#options' => array(
ASSET_PUBLIC => t('Public'),
ASSET_PRIVATE => t('Private'),
),
);
$form['permissions']['roles'] = array(
'#type' => 'checkboxes',
'#options' => user_roles(0, 'create assets'),
'#default_value' => $parent->roles,
);
return $form;
}
/**
* Validate callback for asset_wizard_form().
*/
function asset_wizard_form_validate($form_id, $form_values) {
// If the user presses 'cancel' or 'back', we should do no further
// validation. Also, if they press 'cancel' we should actually
// goto the finish page, because the 'submit' stage won't be called
// if the user hasn't filled in one of the mandatory fields. In fact,
// in that case, Drupal's built in form validation will have set
// errors that we don't need to show the user.
if($form_values['op'] == t(ASSET_WIZARD_CANCEL)) {
// Clear errors from Drupal's built in validation...
drupal_get_messages('error');
// Now go to the 'finish page'
drupal_goto(ASSET_WIZARD_FINISH_REDIRECT);
return;
} else if($form_values['op'] == t(ASSET_WIZARD_PREVIOUS)) {
// Clear messages, and do no further validation
drupal_get_messages('error');
return;
}
// Do whatever validation here. It's probably a good idea to do a
// switch/case on the wizard step. It may be a good idea to validate
// everything on each call, as that will catch anyone hacking the
// form with directly injected form posts, although at slightly
// more processing.
switch($form_values['op']){
case t('Next'):
if($form_values['step']==1 && isset($form_values['module'])){
// allow validate to return an aid
$retval = module_invoke($form_values['module'], 'asset_type', 'validate', $form_values['delta'], $form_values);
if(is_numeric($retval)){
$_POST['aid'] = $retval;
$form_values['aid'] = $retval;
}
}
if($form_values['step']==1 && !isset($_GET['op']) && !$form_values['aid']){
form_set_error('aid',t('Please select a file.'));
}
if($form_values['step']==2 && !$form_values['formatter']){
form_set_error('formatter',t('Please select a formatter.'));
}
break;
case t('New Folder'):
if(!$form_values['folder']){
form_set_error('folder', t('You must specify a folder name.'));
}
if(preg_match('/[^A-Za-z0-9-_.]/',$form_values['folder'])){
form_set_error('folder', t('The folder name may only contain alpha-numeric characters and dashes(-), underscores(_) and periods(.).'));
}
break;
}
}
/**
* Submit callback for asset_wizard_form().
*/
function asset_wizard_form_submit($form_id, $form_values) {
// If the user presses 'back' or 'cancel' don't do any submission work...
if($form_values['op'] == t(ASSET_WIZARD_PREVIOUS) || $form_values['op'] == t(ASSET_WIZARD_CANCEL)) {
return FALSE;
}
if($form_values['op'] == t('New Folder')){
$dir = file_create_path($form_values['parent'].'/'.$form_values['folder']);
if(!asset_check_directory($dir, FILE_CREATE_DIRECTORY, 'folder')){
drupal_set_message(t('Error creating %dir.',array('%dir'=>$dir)));
}
return FALSE;
}
if($form_values['step'] == 1 && isset($form_values['module'])){
// allow module submits to return an aid
$retval = module_invoke($form_values['module'], 'asset_type', 'submit', $form_values['delta'], $form_values);
if(is_numeric($retval)){
$_POST['aid'] = $retval;
}
return FALSE;
}
// If we haven't processed the form and completed fully, we have
// to return FALSE so that Drupal redisplays our form.
return FALSE;
}
function asset_wizard_directory_options($dir = ''){
global $user;
// build directory list and filename options array
$sql = 'SELECT DISTINCT(a.aid) FROM {asset} a ';
$args = array();
// for everyone but the admin, only get assets with proper permissions.
if($user->uid != 1){
$sql .= 'LEFT JOIN {asset_role} r ON a.aid=r.aid '
. 'WHERE (a.uid = %d '
. 'OR a.status = 1 '
. 'OR (r.rid IN (%s) AND r.status = 1) ) '
. 'AND a.dirname LIKE "%s%" ';
$args = array($user->uid, join(array_keys($user->roles),','), $dir);
}else{
$sql .= 'WHERE a.dirname LIKE "%s%" ';
$args = array($dir);
}
$sql .= ' AND a.type = "directory" ORDER BY a.dirname ASC';
$result = db_query($sql, $args);
$options = array();
while($asset = db_fetch_object($result)){
$asset = asset_load($asset->aid);
$dir = $asset->dirname . ($asset->dirname ? '/' : '') . $asset->filename;
$parts = explode('/',$dir);
if(count($parts) > 1){
$name = str_repeat('--', count($parts)-1) . ' ' . $asset->title;
}else{
$name = $asset->title;
}
$options[$dir] = $name;
}
ksort($options);
return $options;
}
function asset_wizard_location_bar($dir = ''){
global $user;
$defaults = array_unique(array($dir, 'PUBLIC', $user->name));
$qstr = $_GET;
unset($qstr['q']);
foreach($defaults as $path){
$info = asset_pathinfo($path);
$asset = asset_load(array('dirname' => $info['dirname'], 'filename' => $info['filename']));
$qstr['dir'] = $asset->filepath;
$links[] = l($asset->title,$_GET['q'],array(),asset_build_query($qstr));
}
return theme('item_list', $links);
}
/**
* Build a list of available asset_types that can be used.
*/
function asset_wizard_toolbar($dir = ''){
$form['toolbar'] = array(
'#tree' => false,
);
$query = $_GET;
$query['dir'] = $dir;
unset($query['q']);
$buttons = array();
$choose = t('Choose');
$html = theme('image', drupal_get_path('module','asset').'/icon.png', $choose, $choose, NULL, FALSE) . ' ' . $choose;
$buttons[] = l($html, 'asset/wizard/'.arg(2), array(), asset_build_query($query), null, false, true);
foreach(module_implements('asset_type') as $module){
$types = module_invoke($module, 'asset_type', 'info');
foreach($types as $delta=>$type){
if(user_access('create ' . $delta . ' assets')){
$key = $module.':'.$delta;
if($type['src']){
$html = theme('image', $type['src'], $type['value'], $type['value'], NULL, FALSE) . ' ' . $type['value'];
}else{
$html = $type['value'];
}
$query['op'] = $type['value'];
$buttons[] = l($html, 'asset/wizard/'.arg(2), array(), asset_build_query($query), null, false, true);
}
}
$i = count($buttons) - 1;
if(!is_array($buttons[$i])){
$buttons[$i] = array('data' => $buttons[$i], 'class' => 'last');
}
}
$form['toolbar'] = array('#value' => theme('item_list', $buttons));
return theme('item_list', $buttons);
}
/**
* Script tag to add to content to finish the wizard.
*/
function asset_wizard_finish(){
return '';
}
/**
* Theming Functions ==========================================================
*/
/**
* Much trimmed down version of theme_page();
*/
function theme_asset_popup($content){
$title = drupal_get_title();
$styles = drupal_get_css();
$scripts = drupal_get_js();
$head = drupal_get_html_head();
$messages = theme('status_messages');
return <<$title
$head
$styles
$scripts
$title
$messages
$content
POPUP;
}
/**
* Main theme function for asset_wizard_form.
*/
function theme_asset_wizard_form($form, $main_class = NULL){
$footer = '';
$help = ($form['help'] ? '
';
return $toolbar.$main.$footer;
}
/**
* Theme function for the selection step of the wizard.
*/
function theme_asset_wizard_selection_form($form){
// $output .= '