diff --git a/admin/inc/class.admin_config.inc.php b/admin/inc/class.admin_config.inc.php index dfd51d2522..b00bfb8f6a 100644 --- a/admin/inc/class.admin_config.inc.php +++ b/admin/inc/class.admin_config.inc.php @@ -22,12 +22,13 @@ class admin_config /** * Upload function to store anonymous images into instance files_dir/anon_images * - * @param type $file file info array - * @param type $dir directory to store file + * @param array $file file info array + * @param array|string $value current value of login_background_file * */ - function ajax_upload_anon_images ($file) + function ajax_upload_anon_images ($file, $value) { + if (!isset($GLOBALS['egw_info']['user']['apps']['admin'])) die('no rights to be here!'); $path = $GLOBALS['egw_info']['server']['files_dir'].'/anon-images'; $success = false; $response = Api\Json\Response::get(); @@ -40,9 +41,10 @@ class admin_config } if ($success) { - $response->data(array( - 'path' => $GLOBALS['egw_info']['server']['webserver_url'].'/api/anon_images.php?src='.urlencode($file[$tmp_file[0]]['name']).'&'.filemtime($destination) + $value = array_merge($value, array( + $GLOBALS['egw_info']['server']['webserver_url'].'/api/anon_images.php?src='.urlencode($file[$tmp_file[0]]['name']).'&'.filemtime($destination), )); + $response->data($value); } else { @@ -50,6 +52,36 @@ class admin_config } } + /** + * Removes images from anon-images directory + * + * @param type $files + */ + function remove_anon_images ($files) + { + if (!isset($GLOBALS['egw_info']['user']['apps']['admin'])) die('no rights to be here!'); + if ($files) + { + $base = $GLOBALS['egw_info']['server']['files_dir'].'/anon-images'; + foreach ($files as $file) + { + $parts = explode('anon_images.php?src=', $file); + $parts = explode('&', $parts[1]); + $path = $base.'/'.urldecode($parts[0]); + if (is_writable(dirname($base)) && file_exists($path)) + { + unlink($path); + } + } + } + } + + /** + * List of configs + * + * @param type $_content + * @throws Api\Exception\WrongParameter + */ function index($_content=null) { if (is_array($_content)) @@ -107,6 +139,9 @@ class admin_config // support old validation hooks $_POST = array('newsettings' => &$_content['newsettings']); + // Remove actual files (cleanup) of deselected urls from login_background_file + $this->remove_anon_images(array_diff($c->config_data['login_background_file'], $_content['newsettings']['login_background_file'])); + /* Load hook file with functions to validate each config (one/none/all) */ Api\Hooks::single(array( 'location' => 'config_validate', diff --git a/admin/js/app.js b/admin/js/app.js index 0539791cb3..e35e988bf3 100644 --- a/admin/js/app.js +++ b/admin/js/app.js @@ -1273,5 +1273,21 @@ app.classes.admin = AppJS.extend( resizable: false, position: 'left top' }, et2_dialog._create_parent('mail')); + }, + + /** + * Triggers upload for background image and updates its taglist + * + * @param {type} node + * @param {type} widget + */ + login_background_update: function(node, widget) + { + var taglist = widget._parent._children[0]; + egw.json('admin.admin_config.ajax_upload_anon_images', + [widget.get_value(), taglist.get_value()], + function(_data){ + taglist.set_value(_data); + }).sendRequest() } }); diff --git a/admin/templates/default/config.xet b/admin/templates/default/config.xet index 86e70b9852..ac83b65b1b 100644 --- a/admin/templates/default/config.xet +++ b/admin/templates/default/config.xet @@ -77,10 +77,13 @@ - - - + + + + + + diff --git a/api/src/Framework/Login.php b/api/src/Framework/Login.php index 28504840e1..5312c425eb 100644 --- a/api/src/Framework/Login.php +++ b/api/src/Framework/Login.php @@ -172,15 +172,9 @@ class Login $tmpl->set_var('website_title', $GLOBALS['egw_info']['server']['site_title']); $tmpl->set_var('template_set',$this->framework->template); - if (substr($GLOBALS['egw_info']['server']['login_background_file'], 0, 4) == 'http' || - $GLOBALS['egw_info']['server']['login_background_file'][0] == '/') - { - $var['background_file'] = $GLOBALS['egw_info']['server']['login_background_file']; - } - else - { - $var['background_file'] = Api\Image::find('api',$GLOBALS['egw_info']['server']['login_background_file']?$GLOBALS['egw_info']['server']['login_background_file']:'login_background', '', null); - } + + $var['background_file'] = self::pick_login_background($GLOBALS['egw_info']['server']['login_background_file']); + if (substr($GLOBALS['egw_info']['server']['login_logo_file'], 0, 4) == 'http' || $GLOBALS['egw_info']['server']['login_logo_file'][0] == '/') { @@ -245,6 +239,36 @@ class Login $this->framework->render($tmpl->fp('loginout','login_form'),false,false); } + /** + * Function to pick login background from given values. It picks them randomly + * if there's more than one image in the list. + * + * @param array|string $backgrounds array of background urls or an url as string + * + * @return string returns full url of background image + */ + static function pick_login_background($backgrounds) + { + if (is_array($backgrounds)) + { + $chosen = $backgrounds[rand(0, count($backgrounds)-1)]; + } + else + { + $chosen = $backgrounds; + } + + if (substr($chosen, 0, 4) == 'http' || + $chosen[0] == '/') + { + return $chosen; + } + else + { + return Api\Image::find('api',$chosen ? $chosen : 'login_background', '', null); + } + } + /** * displays a login denied message */