Example #1
0
/**
* move files to folder...
*
* NOTE: this works either...
* - directly by passing a target folder in 'folder' or 'folders_*'
* - in two steps, whereas
*   - the passed task-ids are keept as hidden fields,
*   - a list with folders is been rendered
*   - a flag 'from_selection' is set
*   - after submit, the kept tasks are moved to 'folders_*'
*
*/
function FilesMoveToFolder()
{
    global $PH;
    $file_ids = getPassedIds('file', 'files_*');
    if (!$file_ids) {
        $PH->abortWarning(__("Select some files to move"));
        exit;
    }
    /**
     * by default render list of folders...
     */
    $target_id = -1;
    /**
     * ...but, if folder was given, directly move files...
     */
    $folder_ids = getPassedIds('folder', 'folders_*');
    if (count($folder_ids) == 1) {
        if ($folder_task = Task::getVisibleById($folder_ids[0])) {
            $target_id = $folder_task->id;
        }
    } else {
        if (get('from_selection')) {
            $target_id = 0;
        }
    }
    if ($target_id != -1) {
        if ($target_id != 0) {
            if (!($target_task = Task::getEditableById($target_id))) {
                $PH->abortWarning(__("insufficient rights"));
            }
            ### get path of target to check for cycles ###
            $parent_tasks = $target_task->getFolder();
            $parent_tasks[] = $target_task;
        } else {
            $parent_tasks = array();
        }
        $count = 0;
        foreach ($file_ids as $id) {
            if ($file = File::getEditableById($id)) {
                $file->parent_item = $target_id;
                $file->update();
            } else {
                $PH->messages[] = sprintf(__("Can not edit file %s"), $file->name);
            }
        }
        ### return to from-page? ###
        if (!$PH->showFromPage()) {
            $PH->show('home');
        }
        exit;
    }
    #else if($target_id != -1) {
    #    $PH->abortWarning(__("insufficient rights to edit any of the selected items"));
    #}
    /**
     * build page folder lists...
     */
    ### get project ####
    if (!($file = File::getVisibleById($file_ids[0]))) {
        $PH->abortWarning("could not get file", ERROR_BUG);
    }
    if (!($project = Project::getVisibleById($file->project))) {
        $PH->abortWarning("file without project?", ERROR_BUG);
    }
    $page = new Page(array('use_jscalendar' => false, 'autofocus_field' => 'company_name'));
    $page->cur_tab = 'projects';
    $page->type = __("Edit files");
    $page->title = "{$project->name}";
    $page->title_minor = __("Select folder to move files into");
    $page->crumbs = build_project_crumbs($project);
    $page->options[] = new NaviOption(array('target_id' => 'filesMoveToFolder'));
    echo new PageHeader();
    echo new PageContentOpen();
    ### write files as hidden entry ###
    foreach ($file_ids as $id) {
        if ($file = File::getEditableById($id)) {
            echo "<input type=hidden name='files_{$id}_chk' value='1'>";
        }
    }
    require_once confGet('DIR_STREBER') . 'lists/list_tasks.inc.php';
    $list = new ListBlock_tasks();
    $list->query_options['show_folders'] = true;
    #$list->query_options['folders_only']= true;
    $list->query_options['project'] = $project->id;
    $list->groupings = NULL;
    $list->block_functions = NULL;
    $list->id = 'folders';
    $list->no_items_html = __('No folders available');
    unset($list->columns['status']);
    unset($list->columns['date_start']);
    unset($list->columns['days_left']);
    unset($list->columns['created_by']);
    unset($list->columns['label']);
    unset($list->columns['project']);
    $list->functions = array();
    $list->active_block_function = 'tree';
    $list->print_automatic($project, NULL);
    echo __("(or select nothing to move to project root)") . "<br> ";
    echo "<input type=hidden name='from_selection' value='1'>";
    # keep flag to ungroup files
    echo "<input type=hidden name='project' value='{$project->id}'>";
    $button_name = __("Move items");
    echo "<input class=button2 type=submit value='{$button_name}'>";
    $PH->go_submit = 'filesMoveToFolder';
    echo new PageContentClose();
    echo new PageHtmlEnd();
}