2015-10-05 18:01:39 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* EGroupware - Tutorial
|
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @package home
|
|
|
|
* @author Hadi Nategh [hn@stylite.de]
|
|
|
|
* @copyright (c) 2015 by Stylite AG <info-AT-stylite.de>
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @version $Id:$
|
|
|
|
*/
|
|
|
|
|
|
|
|
class home_tutorial_ui {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Methods callable via menuaction
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $public_functions = array(
|
|
|
|
'popup' => true
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Popup window to display youtube video
|
|
|
|
* @param type $content
|
|
|
|
*/
|
2015-10-09 17:09:34 +02:00
|
|
|
function popup ($content=null)
|
2015-10-05 18:01:39 +02:00
|
|
|
{
|
|
|
|
//Allow youtube frame to pass the CSP check
|
|
|
|
egw_framework::csp_frame_src_attrs(array('www.youtube.com'));
|
|
|
|
|
|
|
|
$tmpl = new etemplate_new('home.tutorial');
|
|
|
|
|
|
|
|
// Get tutorial object id
|
|
|
|
$tuid_indx = explode('-',$_GET['tuid']);
|
2015-10-07 17:49:51 +02:00
|
|
|
if (!is_array($content))
|
|
|
|
{
|
|
|
|
// read tutorials json file to fetch data
|
|
|
|
$tutorials = json_decode(self::getJsonData(), true);
|
2015-10-09 17:09:34 +02:00
|
|
|
$apps = array('introduction' => lang('Introduction'));
|
2015-10-07 17:49:51 +02:00
|
|
|
foreach ($tutorials as $app => $val)
|
|
|
|
{
|
2015-10-09 09:31:35 +02:00
|
|
|
// show only apps user has access to them
|
|
|
|
if (in_array($app, array_keys($GLOBALS['egw_info']['user']['apps']))) $apps [$app] = $app;
|
2015-10-07 17:49:51 +02:00
|
|
|
}
|
|
|
|
$sel_options = array(
|
|
|
|
'apps' => $apps,
|
|
|
|
);
|
2015-10-09 09:31:35 +02:00
|
|
|
// Check if the user has right to see the app's tutorial
|
2015-10-09 17:09:34 +02:00
|
|
|
if (in_array($tuid_indx[0], array_keys($GLOBALS['egw_info']['user']['apps'])) || $tuid_indx[0] === "introduction")
|
2015-10-09 09:31:35 +02:00
|
|
|
{
|
2015-10-09 17:09:34 +02:00
|
|
|
// fallback to english video
|
|
|
|
$tutorial = $tutorials[$tuid_indx[0]][$tuid_indx[1]][$tuid_indx[2]]? $tutorials[$tuid_indx[0]][$tuid_indx[1]][$tuid_indx[2]]:
|
|
|
|
$tutorials[$tuid_indx[0]]['en'][$tuid_indx[2]];
|
|
|
|
|
2015-10-09 09:31:35 +02:00
|
|
|
$content = array (
|
2015-10-09 17:09:34 +02:00
|
|
|
'src' => $tutorial['src'],
|
|
|
|
'title' => $tutorial['title']
|
2015-10-09 09:31:35 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$content = array();
|
|
|
|
egw_framework::message(lang('You do not have permission to see this tutorial!'));
|
|
|
|
}
|
|
|
|
// If its the autoloading tutorial
|
|
|
|
if ($tuid_indx[3] === 'a')
|
|
|
|
{
|
|
|
|
$content ['discardbox'] = true;
|
|
|
|
}
|
2015-10-07 17:49:51 +02:00
|
|
|
}
|
2015-10-05 18:01:39 +02:00
|
|
|
|
2015-10-07 17:49:51 +02:00
|
|
|
$tmpl->exec('home.home_tutorial_ui.popup', $content,$sel_options,array(),array(),array(),2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ajax function to retrive selected app's tutorials based on prefered user lang
|
|
|
|
*
|
|
|
|
* @param type $_app application name
|
|
|
|
*/
|
|
|
|
function ajax_getAppsTutorials($_app)
|
|
|
|
{
|
|
|
|
$tutorials = json_decode(self::getJsonData(), true);
|
|
|
|
$lang = $GLOBALS['egw_info']['user']['preferences']['common']['lang'];
|
|
|
|
$response = egw_json_response::get();
|
2015-10-09 17:09:34 +02:00
|
|
|
$response->data($tutorials[$_app][$lang]?$tutorials[$_app][$lang]:$tutorials[$_app]['en']);
|
2015-10-05 18:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ajax function to get videos links as json
|
|
|
|
*/
|
|
|
|
function ajax_data()
|
|
|
|
{
|
|
|
|
$response = egw_json_response::get();
|
|
|
|
$response->data(json_decode(self::getJsonData()));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to fetch data from tutorials.json file
|
|
|
|
* @return string returns json string
|
|
|
|
*
|
|
|
|
* @TODO: implement tree level caching
|
|
|
|
*/
|
|
|
|
static function getJsonData()
|
|
|
|
{
|
|
|
|
if (!($json = egw_cache::getCache(egw_cache::TREE, 'home', 'egw_tutorial_json')))
|
|
|
|
{
|
|
|
|
$json = file_get_contents('http://www.egroupware.de/videos/tutorials.json');
|
2015-10-09 17:09:34 +02:00
|
|
|
// Cache the json object for two hours
|
|
|
|
egw_cache::setCache(egw_cache::TREE, 'home', 'egw_tutorial_json', $json, 720);
|
2015-10-05 18:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $json;
|
|
|
|
}
|
|
|
|
}
|