WIP of background & logo image upload into instance dir

This commit is contained in:
Hadi Nategh 2017-04-27 16:50:19 +02:00
parent d277c8b6cf
commit 33bc6f6ce0
2 changed files with 42 additions and 5 deletions

View File

@ -19,6 +19,37 @@ class admin_config
{
var $public_functions = array('index' => True);
/**
* Upload function to store files into instance files_dir
*
* @param type $file file info array
* @param type $dir directory to store file
*
*/
function ajax_upload ($file, $dir = null)
{
$files_dir = $dir ? $dir : $GLOBALS['egw_info']['server']['files_dir'].'/images';
$success = false;
$response = Api\Json\Response::get();
if (is_array($file) && is_writable(dirname($files_dir)))
{
if (!is_dir($files_dir)) mkdir ($files_dir);
$tmp_file = array_keys($file);
$destination = $files_dir.'/'.$file[$tmp_file[0]]['name'];
$success = rename($GLOBALS['egw_info']['server']['temp_dir'].'/'.$tmp_file[0],$destination);
}
if ($success)
{
$response->data(array(
'path' => $destination
));
}
else
{
$response->error(lang('Failed to upload %1',$destination));
}
}
function index($_content=null)
{
if (is_array($_content))

View File

@ -52,23 +52,29 @@
</row>
<row>
<description value="Enter the URL or filename (in api/templates/default/images) of your logo" label="%s:"/>
<textbox id="newsettings[login_logo_file]"/>
<hbox>
<textbox id="newsettings[login_logo_file]" width="70%"/>
<file onchange="egw.json('admin.admin_config.ajax_upload',[widget.get_value()], function(_data){widget._parent._children[0].set_value(_data.path)}).sendRequest()" width="30%" label="upload"/>
</hbox>
</row>
<row>
<description value="Enter the url where your logo should link to" label="%s:"/>
<textbox id="newsettings[login_logo_url]"/>
<textbox id="newsettings[login_logo_url]" width="100%"/>
</row>
<row>
<description value="Enter the title of your logo" label="%s:"/>
<textbox id="newsettings[login_logo_title]"/>
<textbox id="newsettings[login_logo_title]" width="100%"/>
</row>
<row>
<description value="Enter the URL or filename (in api/templates/default/images) of your background image" label="%s:"/>
<textbox id="newsettings[login_background_file]"/>
<hbox>
<textbox id="newsettings[login_background_file]" width="70%"/>
<file width="30%" label="upload" onchange="egw.json('admin.admin_config.ajax_upload',[widget.get_value()], function(_data){widget._parent._children[0].set_value(_data.path)}).sendRequest()"/>
</hbox>
</row>
<row>
<description value="Enter the URL or filename (in your templates image directory) of your favicon (the little icon that appears in the browsers tabs)" label="%s:"/>
<textbox id="newsettings[favicon_file]"/>
<textbox id="newsettings[favicon_file]" class="et2_fullWidth"/>
</row>
<row>
<description value="How big should thumbnails for linked images be (maximum in pixels) ?" label="%s:"/>