2014-12-08 17:04:20 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2016-05-05 09:20:07 +02:00
|
|
|
* EGroupware Filemanager: shares
|
2014-12-08 17:04:20 +01:00
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org/
|
|
|
|
* @package filemanager
|
|
|
|
* @author Ralf Becker <rb-AT-stylite.de>
|
2016-03-20 17:19:53 +01:00
|
|
|
* @copyright (c) 2014-16 by Ralf Becker <rb-AT-stylite.de>
|
2014-12-08 17:04:20 +01:00
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
2016-03-20 17:19:53 +01:00
|
|
|
use EGroupware\Api;
|
2016-05-05 09:20:07 +02:00
|
|
|
use EGroupware\Api\Framework;
|
|
|
|
use EGroupware\Api\Etemplate;
|
2016-03-20 17:19:53 +01:00
|
|
|
use EGroupware\Api\Vfs\Sharing;
|
|
|
|
|
2014-12-08 17:04:20 +01:00
|
|
|
/**
|
|
|
|
* Filemanager: shares
|
|
|
|
*/
|
|
|
|
class filemanager_shares extends filemanager_ui
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Functions callable via menuaction
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $public_functions = array(
|
|
|
|
'index' => true,
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Autheticated user is setup config user
|
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
*/
|
|
|
|
static protected $is_setup = false;
|
|
|
|
|
|
|
|
static protected $tmp_dir;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
|
|
|
function __construct()
|
|
|
|
{
|
|
|
|
// sudo handling
|
|
|
|
parent::__construct();
|
2016-03-20 17:19:53 +01:00
|
|
|
self::$is_setup = Api\Cache::getSession('filemanager', 'is_setup');
|
2014-12-08 17:04:20 +01:00
|
|
|
self::$tmp_dir = '/home/'.$GLOBALS['egw_info']['user']['account_lid'].'/.tmp/';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback to fetch the rows for the nextmatch widget
|
|
|
|
*
|
|
|
|
* @param array $query with keys 'start', 'search', 'order', 'sort', 'col_filter'
|
|
|
|
* For other keys like 'filter', 'cat_id' you have to reimplement this method in a derived class.
|
|
|
|
* @param array &$rows returned rows/competitions
|
|
|
|
* @param array &$readonlys eg. to disable buttons based on acl, not use here, maybe in a derived class
|
|
|
|
* @return int total number of rows
|
|
|
|
*/
|
2021-04-06 15:32:21 +02:00
|
|
|
public function get_rows(&$query_in, &$rows)
|
2014-12-08 17:04:20 +01:00
|
|
|
{
|
2021-04-06 15:32:21 +02:00
|
|
|
$query = $query_in;
|
2014-12-08 17:04:20 +01:00
|
|
|
switch ($query['col_filter']['type'])
|
|
|
|
{
|
2016-03-20 17:19:53 +01:00
|
|
|
case Sharing::LINK:
|
2014-12-08 17:04:20 +01:00
|
|
|
$query['col_filter'][] = "share_path LIKE ".$GLOBALS['egw']->db->quote(self::$tmp_dir.'%');
|
|
|
|
break;
|
|
|
|
|
2016-03-20 17:19:53 +01:00
|
|
|
case Sharing::READONLY:
|
2014-12-08 17:04:20 +01:00
|
|
|
$query['col_filter'][] = "share_path NOT LIKE ".$GLOBALS['egw']->db->quote(self::$tmp_dir.'%');
|
|
|
|
$query['col_filter']['share_writable'] = false;
|
|
|
|
break;
|
|
|
|
|
2016-03-20 17:19:53 +01:00
|
|
|
case Sharing::WRITABLE:
|
2014-12-08 17:04:20 +01:00
|
|
|
$query['col_filter']['share_writable'] = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
unset($query['col_filter']['type']);
|
|
|
|
|
2017-11-02 14:29:08 +01:00
|
|
|
if (class_exists('EGroupware\\Collabora\\Wopi'))
|
|
|
|
{
|
2018-03-21 12:43:25 +01:00
|
|
|
$query['col_filter'][] = 'share_writable NOT IN ('.
|
|
|
|
EGroupware\Collabora\Wopi::WOPI_WRITABLE.','.EGroupware\Collabora\Wopi::WOPI_READONLY.')';
|
2017-11-02 14:29:08 +01:00
|
|
|
}
|
|
|
|
|
2014-12-08 17:04:20 +01:00
|
|
|
if ((string)$query['col_filter']['share_passwd'] !== '')
|
|
|
|
{
|
|
|
|
$query['col_filter'][] = $query['col_filter']['share_passwd'] === 'yes' ?
|
|
|
|
'share_passwd IS NOT NULL' : 'share_passwd IS NULL';
|
|
|
|
}
|
|
|
|
unset($query['col_filter']['share_passwd']);
|
|
|
|
|
|
|
|
$query['col_filter']['share_owner'] = $GLOBALS['egw_info']['user']['account_id'];
|
|
|
|
|
|
|
|
$readonlys = null;
|
2016-03-20 17:19:53 +01:00
|
|
|
$total = Sharing::so()->get_rows($query, $rows, $readonlys);
|
2014-12-08 17:04:20 +01:00
|
|
|
|
|
|
|
foreach($rows as &$row)
|
|
|
|
{
|
|
|
|
if (substr($row['share_path'], 0, strlen(self::$tmp_dir)) === self::$tmp_dir)
|
|
|
|
{
|
|
|
|
$row['share_path'] = substr($row['share_path'], strlen(self::$tmp_dir));
|
2016-03-20 17:19:53 +01:00
|
|
|
$row['type'] = Sharing::LINK;
|
2014-12-08 17:04:20 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-03-20 17:19:53 +01:00
|
|
|
$row['type'] = $row['share_writable'] ? Sharing::WRITABLE : Sharing::READONLY;
|
2014-12-08 17:04:20 +01:00
|
|
|
}
|
|
|
|
$row['share_passwd'] = (boolean)$row['share_passwd'];
|
|
|
|
if ($row['share_with']) $row['share_with'] = preg_replace('/,([^ ])/', ', $1', $row['share_with']);
|
2020-12-09 22:30:47 +01:00
|
|
|
|
|
|
|
foreach(['share_created','share_last_accessed'] as $date_field)
|
|
|
|
{
|
|
|
|
$row[$date_field] = Api\DateTime::server2user($row[$date_field]);
|
|
|
|
}
|
2014-12-08 17:04:20 +01:00
|
|
|
}
|
|
|
|
return $total;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Context menu
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public static function get_actions()
|
|
|
|
{
|
|
|
|
$group = 1;
|
|
|
|
$actions = array(
|
2019-07-10 19:39:48 +02:00
|
|
|
|
|
|
|
'shareLink' => array(
|
|
|
|
'caption' => lang('View link'),
|
|
|
|
'group' => $group,
|
|
|
|
'icon' => 'share',
|
|
|
|
'allowOnMultiple' => false,
|
|
|
|
'default' => true,
|
|
|
|
'onExecute' => 'javaScript:app.filemanager.view_link',
|
|
|
|
'disableIfNoEPL' => true
|
|
|
|
),
|
|
|
|
'shareEdit' => array(
|
|
|
|
'caption' => lang('Edit Share'),
|
|
|
|
'group' => 1,
|
|
|
|
'icon' => 'edit',
|
|
|
|
'allowOnMultiple' => false,
|
2019-08-27 22:47:19 +02:00
|
|
|
'popup' => '500x200',
|
2019-07-10 19:39:48 +02:00
|
|
|
'url' => 'menuaction=stylite.stylite_filemanager.edit_share&share_id=$id',
|
|
|
|
'disableIfNoEPL' => true
|
|
|
|
),
|
2014-12-08 17:04:20 +01:00
|
|
|
'delete' => array(
|
|
|
|
'caption' => lang('Delete'),
|
|
|
|
'group' => ++$group,
|
|
|
|
'confirm' => 'Delete these shares?',
|
|
|
|
),
|
|
|
|
);
|
|
|
|
return $actions;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show files shared
|
|
|
|
*
|
|
|
|
* @param array $content=null
|
|
|
|
* @param string $msg=''
|
|
|
|
*/
|
2021-04-06 15:32:21 +02:00
|
|
|
public function index(array $content=null, $msg = null)
|
2014-12-08 17:04:20 +01:00
|
|
|
{
|
|
|
|
if (!is_array($content))
|
|
|
|
{
|
|
|
|
$content = array(
|
|
|
|
'nm' => array(
|
|
|
|
'get_rows' => 'filemanager.filemanager_shares.get_rows', // I method/callback to request the data for the rows eg. 'notes.bo.get_rows'
|
|
|
|
'no_filter' => True, // current dir only
|
|
|
|
'no_filter2' => True, // I disable the 2. filter (params are the same as for filter)
|
|
|
|
'no_cat' => True, // I disable the cat-selectbox
|
|
|
|
'lettersearch' => false, // I show a lettersearch
|
|
|
|
'searchletter' => false, // I0 active letter of the lettersearch or false for [all]
|
|
|
|
'start' => 0, // IO position in list
|
|
|
|
'order' => 'share_created', // IO name of the column to sort after (optional for the sortheaders)
|
|
|
|
'sort' => 'DESC', // IO direction of the sort: 'ASC' or 'DESC'
|
|
|
|
//'default_cols' => '!', // I columns to use if there's no user or default pref (! as first char uses all but the named columns), default all columns
|
|
|
|
'csv_fields' => false, // I false=disable csv export, true or unset=enable it with auto-detected fieldnames,
|
|
|
|
//or array with name=>label or name=>array('label'=>label,'type'=>type) pairs (type is a eT widget-type)
|
|
|
|
'actions' => self::get_actions(),
|
|
|
|
'row_id' => 'share_id',
|
|
|
|
'dataStorePrefix' => 'egw_shares',
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
elseif ($content['nm']['action'])
|
|
|
|
{
|
|
|
|
switch($content['nm']['action'])
|
|
|
|
{
|
|
|
|
case 'delete':
|
2014-12-09 13:46:38 +01:00
|
|
|
$where = array('share_owner' => $GLOBALS['egw_info']['user']['account_id']);
|
|
|
|
if (!$content['nm']['select_all'])
|
|
|
|
{
|
|
|
|
$where['share_id'] = $content['nm']['selected'];
|
|
|
|
}
|
2016-05-05 09:20:07 +02:00
|
|
|
Framework::message(lang('%1 shares deleted.', Sharing::delete($where)), 'success');
|
2014-12-08 17:04:20 +01:00
|
|
|
break;
|
|
|
|
default:
|
2016-03-20 17:19:53 +01:00
|
|
|
throw new Api\Exception\WrongParameter("Unknown action '{$content['nm']['action']}'!");
|
2014-12-08 17:04:20 +01:00
|
|
|
}
|
|
|
|
unset($content['nm']['action']);
|
2019-07-25 19:24:37 +02:00
|
|
|
unset($content['nm']['id']);
|
2014-12-08 17:04:20 +01:00
|
|
|
}
|
|
|
|
$content['is_setup'] = self::$is_setup;
|
|
|
|
|
|
|
|
$sel_options = array(
|
2016-03-20 17:19:53 +01:00
|
|
|
'type' => Sharing::$modes,
|
2014-12-08 17:04:20 +01:00
|
|
|
'share_passwd' => array(
|
|
|
|
'no' => lang('No'),
|
|
|
|
'yes' => lang('Yes'),
|
|
|
|
)
|
|
|
|
);
|
2016-03-20 17:19:53 +01:00
|
|
|
unset($sel_options['type'][Sharing::ATTACH]);
|
2014-12-08 17:04:20 +01:00
|
|
|
|
2016-05-05 09:20:07 +02:00
|
|
|
$tpl = new Etemplate('filemanager.shares');
|
2014-12-08 17:04:20 +01:00
|
|
|
$tpl->exec('filemanager.filemanager_shares.index', $content, $sel_options, null, $content);
|
|
|
|
}
|
|
|
|
}
|