View source
<?php
function filebrowser_form_create_folder($form_state, $node) {
$form = array();
$form['filebrowser_create_folder'] = array(
'#type' => 'fieldset',
'#title' => t('Create a folder'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#description' => t('This folder will be created within the current directory.'),
'#weight' => 30,
);
$form['#node'] = $node;
$form['#submit'][] = 'filebrowser_form_create_folder_submit';
$form['#validate'][] = 'filebrowser_create_folder_validate';
$form['filebrowser_create_folder']['folder_name'] = array(
'#type' => 'textfield',
'#title' => t('Folder Name'),
'#size' => 40,
'#required' => TRUE,
);
$form['filebrowser_create_folder']['description'] = array(
'#type' => 'textarea',
'#title' => t('Description'),
'#size' => 255,
);
$form['submitted'] = array(
'#tree' => TRUE,
);
$form['filebrowser_create_folder']['submit'] = array(
'#type' => 'submit',
'#value' => t('Create'),
);
return $form;
}
function filebrowser_form_create_folder_validate($form, $form_state) {
$node = $form['#node'];
_filebrowser_load_files($node);
$target = _filebrowser_convert_to_fs_encoding($node, "{$node->file_listing['.']['full-path']}/{$form_state['values']['folder_name']}");
if (file_exists($target)) {
form_error($form['filebrowser_create_folder']['folder_name'], t("This folder already exists."));
}
}
function filebrowser_form_create_folder_submit($form, &$form_state) {
$i = 1;
$node = $form['#node'];
$target = _filebrowser_convert_to_fs_encoding($node, "{$node->file_listing['.']['full-path']}/{$form_state['values']['folder_name']}");
$success = mkdir($target, 0777);
if (!$success) {
drupal_set_message(t("Unable to create this folder, do you have filesystem right to do that ?"), 'error');
}
else {
_filebrowser_load_files($node, NULL, TRUE);
if (!empty($form_state['values']["description"])) {
$file = $node->file_listing[_filebrowser_safe_basename($target)];
module_invoke_all('filebrowser_metadata_set', $file, array(
'description' => $form_state['values']["description"],
));
}
}
drupal_goto("node/{$node->nid}/{$node->file_listing['.']['fid']}", _filebrowser_url_query());
}