You are here

filebrowser.form.actions.inc in Filebrowser 6.2

File

filebrowser.form.actions.inc
View source
<?php

/* This file is part of "filebrowser".
 *    Copyright 2009-2011, arNuméral
 *    Author : Yoran Brault
 *    eMail  : yoran.brault@bad_arnumeral.fr (remove bad_ before sending an email)
 *    Site   : http://www.arnumeral.fr
 *
 * "filebrowser" is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * "filebrowser" is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with "filebrowser"; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
function filebrowser_form_actions($form_state, $table, $actions, $node) {
  $form = array();
  $form['#node'] = $node;
  $form['table'] = array(
    '#value' => $table,
  );
  foreach ($node->file_listing as $file_name => $data) {
    $form["select_{$data['fid']}"] = array(
      '#type' => 'checkbox',
      '#prefix' => '<!-- ',
      '#suffix' => ' -->',
    );
  }
  $options = array(
    '' => t('choose an action'),
  );
  foreach ($actions as $action) {
    $options[$action['operation']] = $action['title'];
  }
  $form['action'] = array(
    '#prefix' => '<br/><div class="container-inline">',
    '#title' => t('actions'),
    '#type' => 'select',
    '#options' => $options,
  );
  $form['submit'] = array(
    '#value' => t('Process'),
    '#type' => 'submit',
    '#suffix' => '</div><br/>',
  );
  return $form;
}
function filebrowser_form_actions_submit($form, $form_state) {
  if (!empty($form_state['values']['action'])) {
    $fids = array();
    foreach ($form['#node']->file_listing as $file_name => $data) {
      if ($form_state['values']["select_{$data['fid']}"]) {
        $fids[] = $data['fid'];
      }
    }
    $result = module_invoke_all('filebrowser_action_process', $form['#node'], $form_state['values']['action'], $fids);
    if ($result) {
      return $result;
    }
  }
  header('Location: ' . request_uri(), TRUE, 302);
  exit;
}