Beispiel #1
0
 public function __construct()
 {
     parent::__construct();
     trigger_error("CFileFolder has been deprecated in v3.0 and will be removed by v4.0. Please use CFile_Folder instead.", E_USER_NOTICE);
 }
 /**
  * createColumn is handy because it can take any input $fieldName and use
  *   its suffix to determine how the field should be displayed.
  *
  * This allows us to treat project_description, task_description,
  *   company_description, or even some_other_crazy_wacky_description in
  *   exactly the same way without additional lines of code or configuration.
  *   If you want to do your own, feel free... but this is probably easier.
  * 
  * Examples: _budget, _date, _name, _owner
  * 
  * This may not work for things like company_type or project_type which are
  *   actually just references to look up tables, ... but should work on
  *   fields like project_company, dept_company because we still have a 
  *   common suffix.
  *
  * @note I'm kind of annoyed about the complexity and sheer number of
  *   paths of this method but overall I think it's laid out reasonably
  *   well. I think the more important part is that I've been able to
  *   encapsulate it all here instead of spreading it all over the modules
  *   and views.
  */
 public function createCell($fieldName, $value, $custom = array())
 {
     $additional = '';
     if ('' == $value) {
         return '<td>-</td>';
     }
     $pieces = explode('_', $fieldName);
     $prefix = $pieces[0];
     $suffix = '_' . end($pieces);
     if ($fieldName == 'project_actual_end_date') {
         $suffix = '_actual';
     }
     switch ($suffix) {
         //BEGIN: object-based linkings
         /*
          * TODO: The following cases are likely to change once we have an approach to 
          *   handle module-level objects and their proper mapping/linkings.
         */
         case '_company':
         case '_contact':
         case '_task':
             $module = substr($suffix, 1);
             $class = 'C' . ucfirst($module);
             $obj = new $class();
             $obj->load($value);
             $link = '?m=' . w2p_pluralize($module) . '&a=view&' . $module . '_id=' . $value;
             $cell = '<a href="' . $link . '">' . $obj->{"{$module}" . '_name'} . '</a>';
             $suffix .= ' _name';
             break;
         case '_department':
             $module = substr($suffix, 1);
             $class = 'C' . ucfirst($module);
             $obj = new $class();
             $obj->load($value);
             /**
              * This is a branch separate from _company, _contact, etc above because although the module is called
              *   departments, the fields are dept_id and dept_name. :(
              *                                                              ~ caseydk, Dec 11 2013
              */
             $link = '?m=' . w2p_pluralize($module) . '&a=view&dept_id=' . $value;
             $cell = '<a href="' . $link . '">' . $obj->dept_name . '</a>';
             $suffix .= ' _name';
             break;
         case '_folder':
             $obj = new CFile_Folder();
             $obj->load($value);
             $foldername = $value ? $obj->file_folder_name : 'Root';
             $image = '<img src="' . w2PfindImage('folder5_small.png', 'files') . '" />';
             $link = '?m=files&tab=4&folder=' . (int) $value;
             $cell = '<a href="' . $link . '">' . $image . ' ' . $foldername . '</a>';
             $suffix .= ' _name';
             break;
         case '_user':
         case '_username':
             $obj = new CContact();
             $obj->findContactByUserid($this->tableRowData['user_id']);
             $link = '?m=users&a=view&user_id=' . $this->tableRowData['user_id'];
             $cell = '<a href="' . $link . '">' . $obj->user_username . '</a>';
             break;
             //END: object-based linkings
             /*
              * TODO: These two prefix adjustments are an ugly hack because our departments 
              *   table doesn't follow the same convention as every other table we have. 
              *   This needs to be fixed in v4.0 - caseydk 13 Feb 2012
              *
              * TODO: And unfortunately, the forums module is screwy using 'viewer' instead 
              *   of our standard 'view' for the page. ~ caseydk 16 Feb 2012
             */
         //END: object-based linkings
         /*
          * TODO: These two prefix adjustments are an ugly hack because our departments 
          *   table doesn't follow the same convention as every other table we have. 
          *   This needs to be fixed in v4.0 - caseydk 13 Feb 2012
          *
          * TODO: And unfortunately, the forums module is screwy using 'viewer' instead 
          *   of our standard 'view' for the page. ~ caseydk 16 Feb 2012
         */
         case '_name':
             $prefix = $prefix == 'project_short' ? 'project' : $prefix;
             $prefix = $prefix == 'dept' ? 'department' : $prefix;
             $page = $prefix == 'forum' || $prefix == 'message' ? 'viewer' : 'view';
             $link = '?m=' . w2p_pluralize($prefix) . '&a=' . $page . '&';
             $link = $prefix == 'message' ? '?m=forums&a=' . $page . '&' : $link;
             $prefix = $prefix == 'department' ? 'dept' : $prefix;
             $link .= $prefix . '_id=' . $this->tableRowData[$prefix . '_id'];
             $link .= $prefix == 'task_log' ? '&tab=1&task_id=' . $this->tableRowData['task_id'] : '';
             $icon = $fieldName == 'file_name' ? '<img src="' . w2PfindImage(getIcon($this->tableRowData['file_type']), 'files') . '" />&nbsp;' : '';
             $cell = '<a href="' . $link . '">' . $icon . $value . '</a>';
             //TODO: task_logs are another oddball..
             $cell = $prefix == 'task_log' ? str_replace('task_logs', 'tasks', $cell) : $cell;
             break;
         case '_author':
         case '_creator':
         case '_owner':
         case '_updator':
             if ((int) $value) {
                 $obj = new CContact();
                 $obj->findContactByUserid($value);
                 $suffix .= ' nowrap';
                 $link = '?m=users&a=view&user_id=' . $value;
                 $cell = '<a href="' . $link . '">' . $obj->contact_display_name . '</a>';
             } else {
                 $cell = $value;
             }
             break;
             // The above are all contact/user display names, the below are numbers.
         // The above are all contact/user display names, the below are numbers.
         case '_count':
         case '_hours':
             $cell = $value;
             break;
         case '_duration':
             $durnTypes = w2PgetSysVal('TaskDurationType');
             $cell = $value . ' ' . $this->AppUI->_($durnTypes[$this->tableRowData['task_duration_type']]);
             break;
         case '_size':
             $cell = file_size($value);
             break;
         case '_budget':
             $cell = w2PgetConfig('currency_symbol');
             $cell .= formatCurrency($value, $this->AppUI->getPref('CURRENCYFORM'));
             break;
         case '_url':
             $value = str_replace(array('"', '"', '<', '>'), '', $value);
             $cell = w2p_url($value);
             break;
         case '_email':
             $cell = w2p_email($value);
             break;
         case '_birthday':
         case '_date':
             $myDate = intval($value) ? new w2p_Utilities_Date($value) : null;
             $cell = $myDate ? $myDate->format($this->df) : '-';
             break;
         case '_actual':
             $end_date = intval($this->tableRowData['project_end_date']) ? new w2p_Utilities_Date($this->tableRowData['project_end_date']) : null;
             $actual_end_date = intval($this->tableRowData['project_actual_end_date']) ? new w2p_Utilities_Date($this->tableRowData['project_actual_end_date']) : null;
             $style = $actual_end_date < $end_date && !empty($end_date) ? 'style="color:red; font-weight:bold"' : '';
             if ($actual_end_date) {
                 $cell = '<a href="?m=tasks&a=view&task_id=' . $this->tableRowData['project_last_task'] . '" ' . $style . '>' . $actual_end_date->format($this->df) . '</a>';
             } else {
                 $cell = '-';
             }
             break;
         case '_created':
         case '_datetime':
         case '_update':
         case '_updated':
             $myDate = intval($value) ? new w2p_Utilities_Date($this->AppUI->formatTZAwareTime($value, '%Y-%m-%d %T')) : null;
             $cell = $myDate ? $myDate->format($this->dtf) : '-';
             break;
         case '_description':
             $cell = w2p_textarea($value);
             break;
         case '_priority':
             $mod = $value > 0 ? '+' : '-';
             $image = '<img src="' . w2PfindImage('icons/priority' . $mod . abs($value) . '.gif') . '" width="13" height="16" alt="">';
             $cell = $value != 0 ? $image : '';
             break;
         case '_complete':
         case '_assignment':
         case '_allocated':
         case '_allocation':
             $cell = round($value) . '%';
             break;
         case '_password':
             $cell = '(' . $this->AppUI->_('hidden') . ')';
             break;
         case '_version':
             $value = (int) (100 * $value);
             $cell = number_format($value / 100, 2);
             break;
         case '_identifier':
             $additional = 'style="background-color:#' . $value . '; color:' . bestColor($value) . '" ';
             $cell = $this->tableRowData['project_percent_complete'] . '%';
             break;
         case '_project':
             $module = substr($suffix, 1);
             $class = 'C' . ucfirst($module);
             $obj = new $class();
             $obj->load($value);
             $color = $obj->project_color_identifier;
             $link = '?m=' . w2p_pluralize($module) . '&a=view&' . $module . '_id=' . $value;
             $cell = '<span style="background-color:#' . $color . '; padding: 3px"><a href="' . $link . '" style="color:' . bestColor($color) . '">' . $obj->{"{$module}" . '_name'} . '</a></span>';
             $suffix .= ' _name';
             break;
         case '_assignees':
             $cell = $value;
             break;
         case '_problem':
             if ($value) {
                 $cell = '<a href="?m=tasks&a=index&f=all&project_id=' . $this->tableRowData['project_id'] . '">';
                 $cell .= w2PshowImage('icons/dialog-warning5.png', 16, 16, 'Problem', 'Problem');
                 $cell .= '</a>';
             } else {
                 $cell = '-';
             }
             break;
         default:
             $value = isset($custom[$fieldName]) ? $custom[$fieldName][$value] : $value;
             $cell = htmlspecialchars($value, ENT_QUOTES);
     }
     $begin = '<td ' . $additional . 'class="' . $suffix . '">';
     $end = '</td>';
     return $begin . $cell . $end;
 }
Beispiel #3
0
// to pass to "new file" button
// get the list of visible companies
$extra = array('from' => 'files', 'where' => 'projects.project_id = file_project', 'join' => 'project_departments', 'on' => 'projects.project_id = project_departments.project_id');
//get "Allowed" projects for filter list ("All" is always allowed when basing permission on projects)
$project = new CProject();
$projects = $project->getAllowedRecords($AppUI->user_id, 'projects.project_id,project_name', 'project_name', null, $extra, 'projects');
$projects = arrayMerge(array('0' => $AppUI->_('All', UI_OUTPUT_RAW)), $projects);
// get SQL for allowed projects/tasks
$task = new CTask();
$allowedTasks = $task->getAllowedSQL($AppUI->user_id, 'file_task');
// setup the title block
$titleBlock = new w2p_Theme_TitleBlock('Files', 'icon.png', $m);
$titleBlock->addFilterCell('Filter', 'project_id', $projects, $project_id);
// override the $canEdit variable passed from the main index.php in order to check folder permissions
/** get permitted folders **/
$cfObj = new CFile_Folder();
$allowed_folders_ary = $cfObj->getAllowedRecords($AppUI->user_id);
$denied_folders_ary = $cfObj->getDeniedRecords($AppUI->user_id);
$limited = count($allowed_folders_ary) < $cfObj->countFolders() ? true : false;
if (!$limited) {
    $canEdit = true;
} elseif ($limited and array_key_exists($folder, $allowed_folders_ary)) {
    $canEdit = true;
} else {
    $canEdit = false;
}
if ($canEdit) {
    $titleBlock->addButton('new folder', '?m=files&a=addedit_folder');
    $titleBlock->addButton('new file', '?m=files&a=addedit&folder=' . $folder);
}
$titleBlock->show();
    $showProject = true;
}
if (!isset($company_id)) {
    $company_id = (int) w2PgetParam($_REQUEST, 'company_id', 0);
}
$obj = new CCompany();
$allowed_companies_ary = $obj->getAllowedRecords($AppUI->user_id, 'company_id,company_name', 'company_name');
$allowed_companies = implode(',', array_keys($allowed_companies_ary));
if (!isset($task_id)) {
    $task_id = (int) w2PgetParam($_REQUEST, 'task_id', 0);
}
$xpg_pagesize = w2PgetConfig('page_size', 50);
$xpg_min = $xpg_pagesize * ($page - 1);
// This is where we start our record set from
$file_types = w2PgetSysVal('FileType');
$myFolder = new CFile_Folder();
$xpg_totalrecs = $myFolder->getFileCountByFolder(null, $folder_id, $task_id, $project_id, $company_id, $allowed_companies);
?>
<script language="javascript" type="text/javascript">
function expand(id){
	var element = document.getElementById(id);
	element.style.display = (element.style.display == '' || element.style.display == 'none') ? 'block' : 'none';
}
function addBulkComponent(li) {
//IE
	if (document.all || navigator.appName == 'Microsoft Internet Explorer') {
		var ni = document.getElementById('frm_bulk');
		var newitem = document.createElement('input');
		newitem.id = 'bulk_selected_file['+li+']';
		newitem.name = 'bulk_selected_file['+li+']';
		newitem.type = 'hidden';
function getFolders($parent)
{
    global $AppUI, $allowed_folders_ary, $tab, $m, $a, $company_id, $project_id, $task_id;
    // retrieve all children of $parent
    $file_folder = new CFile_Folder();
    $folders = $file_folder->getFoldersByParent($parent);
    $s = '';
    // display each child
    foreach ($folders as $row) {
        if (array_key_exists($row['file_folder_id'], $allowed_folders_ary) or array_key_exists($parent, $allowed_folders_ary)) {
            $file_count = countFiles($row['file_folder_id']);
            $s .= '<tr><td colspan="20">';
            $s .= '<ul>';
            $s .= '<li><a href="./index.php?m=files&amp;a=addedit_folder&amp;file_folder_parent=' . $row['file_folder_id'] . '&amp;file_folder_id=0">' . w2PshowImage('edit_add.png', '', '', 'new folder', 'add a new subfolder', 'files') . '</a></li>';
            $s .= '<li><a href="./index.php?m=files&amp;a=addedit&amp;folder=' . $row['file_folder_id'] . '&amp;project_id=' . $project_id . '&amp;file_id=0">' . w2PshowImage('folder_new.png', '', '', 'new file', 'add new file to this folder', 'files') . '</a></li>';
            $s .= '<li><a href="./index.php?m=files&amp;a=addedit_folder&amp;folder=' . $row['file_folder_id'] . '">' . w2PshowImage('filesaveas.png', '', '', 'edit icon', 'edit this folder', 'files') . '</a></li>';
            if ($m == 'files') {
                $s .= '<li class="info-text"><a href="./index.php?m=' . $m . '&amp;a=' . $a . '&amp;tab=' . $tab . '&folder=' . $row['file_folder_id'] . '" name="ff' . $row['file_folder_id'] . '">';
            }
            $s .= w2PshowImage('folder5_small.png', '22', '22', '', '', 'files');
            $s .= $row['file_folder_name'];
            if ($m == 'files') {
                $s .= '</a></li>';
            }
            if ($file_count > 0) {
                $s .= '<li class="info-text"><a href="javascript: void(0);" onClick="expand(\'files_' . $row['file_folder_id'] . '\')" class="has-files">(' . $file_count . ' files) +</a></li>';
            }
            $s .= '<form name="frm_remove_folder_' . $row['file_folder_id'] . '" action="?m=files" method="post" accept-charset="utf-8">
                    <input type="hidden" name="dosql" value="do_folder_aed" />
                    <input type="hidden" name="del" value="1" />
                    <input type="hidden" name="file_folder_id" value="' . $row['file_folder_id'] . '" />
                    </form>';
            $s .= '</ul>';
            $s .= '<a class="small-delete" href="javascript: void(0);" onclick="if (confirm(\'Are you sure you want to delete this folder?\')) {document.frm_remove_folder_' . $row['file_folder_id'] . '.submit()}">' . w2PshowImage('remove.png', '', '', 'delete icon', 'delete this folder', 'files') . '</a>';
            $s .= '</td></tr>';
            if ($file_count > 0) {
                $s .= '<div class="files-list" id="files_' . $row['file_folder_id'] . '" style="display: none;">';
                $s .= displayFiles($AppUI, $row['file_folder_id'], $task_id, $project_id, $company_id);
                $s .= "</div>";
            }
        }
    }
    return $s;
}
 /**
  * Tests the delete of a link
  */
 public function testDelete()
 {
     $this->obj->bind($this->post_data);
     $result = $this->obj->store();
     $this->assertTrue($result);
     $original_id = $this->obj->file_folder_id;
     $result = $this->obj->delete();
     $item = new CFile_Folder();
     $item->overrideDatabase($this->mockDB);
     $this->mockDB->stageHash(array('file_folder_name' => ''));
     $item->load($original_id);
     $this->assertTrue(is_a($item, 'CFile_Folder'));
     $this->assertEquals('', $item->file_folder_name);
 }
<?php

if (!defined('W2P_BASE_DIR')) {
    die('You should not access this file directly.');
}
// @todo    convert to template
$file_folder_parent = intval(w2PgetParam($_GET, 'file_folder_parent', 0));
$object_id = intval(w2PgetParam($_GET, 'folder', 0));
$object = new CFile_Folder();
$object->setId($object_id);
$obj = $object;
$canAddEdit = $obj->canAddEdit();
$canAuthor = $obj->canCreate();
$canEdit = $obj->canEdit();
if (!$canAddEdit) {
    $AppUI->redirect(ACCESS_DENIED);
}
$obj = $AppUI->restoreObject();
if ($obj) {
    $object = $obj;
    $object_id = $object->file_folder_id;
} else {
    $obj = $object->load($object_id);
}
if (!$object && $object_id > 0) {
    $AppUI->setMsg('File Folder');
    $AppUI->setMsg('invalidID', UI_MSG_ERROR, true);
    $AppUI->redirect('m=' . $m);
}
$folders = getFolderSelectList();
// setup the title block
Beispiel #8
0
if (!$canAuthor && !$folder) {
    $AppUI->redirect('m=public&a=access_denied');
}
if (!$canEdit && $folder) {
    $AppUI->redirect('m=public&a=access_denied');
}
// check permissions for this record
if ($folder == 0) {
    $canEdit = $canAuthor;
}
if (!$canEdit) {
    $AppUI->redirect('m=public&a=access_denied');
}
// check if this record has dependancies to prevent deletion
$msg = '';
$obj = new CFile_Folder();
if ($folder > 0) {
    $canDelete = $obj->canDelete($msg, $folder);
}
$q = new w2p_Database_Query();
$q->addTable('file_folders');
$q->addQuery('file_folders.*');
$q->addWhere('file_folder_id=' . $folder);
$obj = null;
$q->loadObject($obj);
// load the record data
if (!$obj && $folder > 0) {
    $AppUI->setMsg('File Folder');
    $AppUI->setMsg('invalidID', UI_MSG_ERROR, true);
    $AppUI->redirect();
}