diff --git a/main/admin/settings.php b/main/admin/settings.php index c092e1828b..103e0d191c 100644 --- a/main/admin/settings.php +++ b/main/admin/settings.php @@ -1,5 +1,5 @@ '.get_lang('UploadNewStylesheet').''; + $form = new FormValidator('stylesheet_upload','post','settings.php?category=stylesheets&showuploadform=true'); + $form->addElement('text','name_stylesheet',get_lang('NameStylesheet'),array('size' => '40', 'maxlength' => '40')); + $form->addRule('name_stylesheet', get_lang('ThisFieldIsRequired'), 'required'); + $form->addElement('file', 'new_stylesheet', get_lang('UploadNewStylesheet')); + $allowed_file_types = array ('css'); + $form->addRule('new_stylesheet', get_lang('InvalidExtension').' ('.implode(',', $allowed_file_types).')', 'filetype', $allowed_file_types); + $form->addRule('new_stylesheet', get_lang('ThisFieldIsRequired'), 'required'); + $form->addElement('submit', 'stylesheet_upload', get_lang('Ok')); + if( $form->validate() AND is_writable(api_get_path(SYS_CODE_PATH).'css/')) + { + $values = $form->exportValues(); + $picture_element = & $form->getElement('new_stylesheet'); + $picture = $picture_element->getValue(); + upload_stylesheet($values, $picture); + Display::display_confirmation_message(get_lang('StylesheetAdded')); + } + else + { + if (!is_writable(api_get_path(SYS_CODE_PATH).'css/')) + { + Display::display_error_message(api_get_path(SYS_CODE_PATH).'css/'.get_lang('IsNotWritable')); + } + else + { + if ($_GET['showuploadform'] == 'true') + { + echo '
'; + } + else + { + echo ''; + } + } + // Preview of the stylesheet echo '
'; @@ -438,6 +479,36 @@ function handle_stylesheets() echo ''; } +/** + * creates the folder (if needed) and uploads the stylesheet in it + * + * @param array $values the values of the form + * @param array $picture the values of the uploaded file + * + * @author Patrick Cool , Ghent University, Belgium + * @version May 2008 + * @since Dokeos 1.8.5 + */ +function upload_stylesheet($values,$picture) +{ + // valid name for the stylesheet folder + $style_name = ereg_replace("[^A-Za-z0-9]", "", $values['name_stylesheet'] ); + + // create the folder if needed + if(!is_dir(api_get_path(SYS_CODE_PATH).'css/'.$style_name.'/')) + { + if(mkdir(api_get_path(SYS_CODE_PATH).'css/'.$style_name.'/')) + { + $perm = api_get_setting('permissions_for_new_directories'); + $perm = octdec(!empty($perm)?$perm:'0770'); + chmod(api_get_path(SYS_CODE_PATH).'css/'.$style_name.'/'); + } + } + + // move the file in the folder + move_uploaded_file($picture['tmp_name'], api_get_path(SYS_CODE_PATH).'css/'.$style_name.'/'.$picture['name']); +} + /** * This function allows easy activating and inactivating of plugins * @todo: a similar function needs to be written to activate or inactivate additional tools.