Example #1
0
/**
 * Render folder tree
 *
 * @param string $name Control name
 * @param Project $project
 * @param integer $selected ID of selected folder
 * @param array $attributes Select box attributes
 * @return string
 */
function render_folder_tree($folder, $depth = 0, $project = null, $selected = null, $attributes = null)
{
    if ($depth > 5) {
        return;
    }
    if (is_null($project)) {
        $project = active_project();
    }
    // if
    if (!$project instanceof Project) {
        throw new InvalidInstanceError('$project', $project, 'Project');
    }
    // if
    if (is_array($attributes)) {
        if (!isset($attributes['class'])) {
            $attributes['class'] = 'select_folder';
        }
    } else {
        $attributes = array('class' => 'select_folder');
    }
    // if
    $options = array(option_tag(lang('none'), 0));
    $html = '';
    if ($folder instanceof ProjectFolder) {
        $folders = ProjectFolders::getProjectFolderTree($project, $folder->getId());
    } else {
        $folders = ProjectFolders::getProjectFolderTree($project);
    }
    if (is_array($folders)) {
        $html .= '<ul>';
        foreach ($folders as $folder) {
            $class = $folder->getId() == $selected ? $class = 'class="selected"' : '';
            //$html .= '<li>' . $folder->getName() . render_folder_tree( $folder, $depth, $project, $selected, $attributes ) . '</li>';
            $html .= '<li><a href="' . $folder->getBrowseUrl() . '" ' . $class . '>' . clean($folder->getName()) . '</a>';
            if ($folder->canEdit(logged_user())) {
                $html .= ' <a href="' . $folder->getEditUrl() . '" class="blank" title="' . lang('edit folder') . '"><img src="' . icon_url('edit.gif') . '" alt="" /></a>';
            }
            // if
            if ($folder->canDelete(logged_user())) {
                $html .= ' <a href="' . $folder->getDeleteUrl() . '" class="blank" title="' . lang('delete folder') . '"><img src="' . icon_url('cancel_gray.gif') . '" alt="" /></a>';
            }
            // if
            $html .= render_folder_tree($folder, $depth + 1, $project, $selected, $attributes);
            $html .= '</li>';
        }
        // foreach
        $html .= '</ul>';
    }
    // if
    return $html;
}
 <?php 
            if ($folder->canDelete(logged_user())) {
                ?>
<a href="<?php 
                echo $folder->getDeleteUrl();
                ?>
" class="blank" title="<?php 
                echo lang('delete folder');
                ?>
"><img src="<?php 
                echo icon_url('cancel_gray.gif');
                ?>
" alt="" /></a><?php 
            }
            // if
            echo render_folder_tree($folder);
            // if
            ?>
</li>
<?php 
        }
        // if
    }
    // foreach
    ?>
    </ul>
<?php 
    if (ProjectFolder::canAdd(logged_user(), active_project())) {
        ?>
    <div><a href="<?php 
        echo get_url('files', 'add_folder');
Example #3
0
    ?>
      <li><a href="<?php 
    echo ProjectFiles::getIndexUrl($order, $page);
    ?>
" class="selected"><?php 
    echo lang('all files');
    ?>
</a></li>
<?php 
}
// if
?>
    </ul>
<?php 
trace(__FILE__, 'folders');
echo render_folder_tree(null, 0, active_project(), $current_folder_id);
?>
<br/>
<?php 
if (ProjectFolder::canAdd(logged_user(), active_project())) {
    ?>
    <div><a href="<?php 
    echo get_url('files', 'add_folder');
    ?>
"><?php 
    echo lang('add folder');
    ?>
</a></div>
<?php 
}
// if