123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026 |
- <?php
- function get_settings_options($var) {
- $table_settings_options = Database :: get_main_table(TABLE_MAIN_SETTINGS_OPTIONS);
- $sql = "SELECT * FROM $table_settings_options WHERE variable='$var'";
- $result = Database::query($sql);
- while ($row = Database::fetch_array($result)) {
- $temp_array = array ('value' => $row['value'], 'display_text' => $row['display_text']);
- $settings_options_array[] = $temp_array;
- }
- return $settings_options_array;
- }
- function handle_plugins() {
- global $SettingsStored;
- $userplugins = array();
- $table_settings_current = Database :: get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
- if (isset($_POST['submit_plugins'])) {
- store_plugins();
-
- $user_id = api_get_user_id();
- $category = $_GET['category'];
- event_system(LOG_CONFIGURATION_SETTINGS_CHANGE, LOG_CONFIGURATION_SETTINGS_CATEGORY, $category, api_get_utc_datetime(), $user_id);
- Display :: display_confirmation_message(get_lang('SettingsStored'));
- }
-
- echo '<br />';
-
- $pluginpath = api_get_path(SYS_PLUGIN_PATH);
- $handle = @opendir($pluginpath);
- while (false !== ($file = readdir($handle))) {
- if ($file != '.' && $file != '..' && is_dir(api_get_path(SYS_PLUGIN_PATH).$file)) {
- $possibleplugins[] = $file;
- }
- }
- @closedir($handle);
-
- echo '<form name="plugins" method="post" action="'.api_get_self().'?category='.$_GET['category'].'">';
- echo '<table class="data_table">';
- echo '<tr>';
- echo '<th>';
- echo get_lang('Plugin');
- echo '</th><th>';
- echo get_lang('LoginPageMainArea');
- echo '</th><th>';
- echo get_lang('LoginPageMenu');
- echo '</th><th>';
- echo get_lang('CampusHomepageMainArea');
- echo '</th><th>';
- echo get_lang('CampusHomepageMenu');
- echo '</th><th>';
- echo get_lang('MyCoursesMainArea');
- echo '</th><th>';
- echo get_lang('MyCoursesMenu');
- echo '</th><th>';
- echo get_lang('Header');
- echo '</th><th>';
- echo get_lang('Footer');
- echo '</th><th>';
- echo get_lang('CourseTool');
- echo '</th>';
- echo '</tr>';
-
-
-
- $result = api_get_settings('Plugins');
-
- foreach ($result as $row) {
- $usedplugins[$row['variable']][] = $row['selected_value'];
- }
-
- foreach ($possibleplugins as $testplugin) {
- $plugin_info_file = api_get_path(SYS_PLUGIN_PATH).$testplugin.'/plugin.php';
- if (file_exists($plugin_info_file)) {
- $plugin_info = array();
- include ($plugin_info_file);
- echo '<tr>';
- echo '<td>';
- foreach ($plugin_info as $key => $value) {
- if ($key != 'location') {
- if ($key == 'title') {
- $value = '<strong>'.$value.'</strong>';
- }
- echo get_lang(ucwords($key)).': '.$value.'<br />';
- }
- }
- if (file_exists(api_get_path(SYS_PLUGIN_PATH).$testplugin.'/readme.txt')) {
- echo "<a href='".api_get_path(WEB_PLUGIN_PATH).$testplugin."/readme.txt'>readme.txt</a>";
- }
- echo '</td>';
-
- if (empty($usedplugins)) {
- $usedplugins = array();
- }
- display_plugin_cell('loginpage_main', $plugin_info, $testplugin, $usedplugins);
- display_plugin_cell('loginpage_menu', $plugin_info, $testplugin, $usedplugins);
- display_plugin_cell('campushomepage_main', $plugin_info, $testplugin, $usedplugins);
- display_plugin_cell('campushomepage_menu', $plugin_info, $testplugin, $usedplugins);
- display_plugin_cell('mycourses_main', $plugin_info, $testplugin, $usedplugins);
- display_plugin_cell('mycourses_menu', $plugin_info, $testplugin, $usedplugins);
- display_plugin_cell('header', $plugin_info, $testplugin, $usedplugins);
- display_plugin_cell('footer', $plugin_info, $testplugin, $usedplugins);
- display_plugin_cell('course_tool_plugin', $plugin_info, $testplugin, $usedplugins);
- echo '</tr>';
- }
- }
- echo '</table>';
- echo '<br />';
- echo '<button class="save" type="submit" name="submit_plugins">'.get_lang('EnablePlugins').'</button></form>';
- echo '<br />';
- }
- function display_plugin_cell($location, $plugin_info, $current_plugin, $active_plugins) {
- echo '<td align="center">';
- if (in_array($location, $plugin_info['location'])) {
- if (isset($active_plugins[$location]) && is_array($active_plugins[$location])
- && in_array($current_plugin, $active_plugins[$location])) {
- $checked = 'checked';
- } else {
- $checked = '';
- }
- echo '<input type="checkbox" name="'.$current_plugin.'-'.$location.'" value="true" '.$checked.'/>';
- }
- echo "</td>";
- }
- function handle_stylesheets() {
- global $_configuration;
-
- $currentstyle = api_get_setting('stylesheets');
- $is_style_changeable = false;
- if ($_configuration['access_url'] != 1) {
- $style_info = api_get_settings('stylesheets', '', 1, 0);
- $url_info = api_get_access_url($_configuration['access_url']);
- if ($style_info[0]['access_url_changeable'] == 1 && $url_info['active'] == 1) {
- $is_style_changeable = true;
- echo '<div class="actions" id="stylesheetuploadlink">';
- Display::display_icon('upload_stylesheets.png',get_lang('UploadNewStylesheet'),'','32');
- echo '<a href="" onclick="javascript: document.getElementById(\'newstylesheetform\').style.display = \'block\'; document.getElementById(\'stylesheetuploadlink\').style.display = \'none\'; return false; ">'.get_lang('UploadNewStylesheet').'</a>';
- echo '</div>';
- }
- } else {
- $is_style_changeable = true;
- echo '<div class="actions" id="stylesheetuploadlink">';
- Display::display_icon('upload_stylesheets.png',get_lang('UploadNewStylesheet'),'','32');
- echo '<a href="" onclick="javascript: document.getElementById(\'newstylesheetform\').style.display = \'block\'; document.getElementById(\'stylesheetuploadlink\').style.display = \'none\'; return false; ">'.get_lang('UploadNewStylesheet').'</a>';
- echo '</div>';
- }
- $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', 'zip', 'jpeg', 'jpg', 'png', 'gif');
- $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('style_submit_button', 'stylesheet_upload', get_lang('Ok'), array('class'=>'save'));
- if ($form->validate() && 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);
-
- $user_id = api_get_user_id();
- $category = $_GET['category'];
- event_system(LOG_CONFIGURATION_SETTINGS_CHANGE, LOG_CONFIGURATION_SETTINGS_CATEGORY, $category, api_get_utc_datetime(), $user_id);
- 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 '<div id="newstylesheetform">';
- } else {
- echo '<div id="newstylesheetform" style="display: none;">';
- }
-
- if ($_configuration['access_url'] == 1) {
- $form->display();
- } else {
- if ($is_style_changeable) {
- $form->display();
- }
- }
- echo '</div>';
- }
- }
-
- echo '<div><iframe src="style_preview.php" width="100%" height="300" name="preview"></iframe></div>';
- ?>
- <script type="text/javascript">
- function load_preview(selectobj){
- var style_dir = selectobj.options[selectobj.selectedIndex].value;
- parent.preview.location='style_preview.php?style=' + style_dir;
- }
- </script>
- <?php
- echo '<form name="stylesheets" method="post" action="'.api_get_self().'?category='.Security::remove_XSS($_GET['category']).'">';
- echo '<br /><select name="style" onChange="load_preview(this)" >';
- $list_of_styles = array();
- $list_of_names = array();
- if ($handle = @opendir(api_get_path(SYS_PATH).'main/css/')) {
- $counter = 1;
- while (false !== ($style_dir = readdir($handle))) {
- if (substr($style_dir, 0, 1) == '.') {
- continue;
- }
- $dirpath = api_get_path(SYS_PATH).'main/css/'.$style_dir;
- if (is_dir($dirpath)) {
- if ($style_dir != '.' && $style_dir != '..') {
- if ($currentstyle == $style_dir || ($style_dir == 'chamilo' && !$currentstyle)) {
- $selected = 'selected="true"';
- } else {
- $selected = '';
- }
- $show_name = ucwords(str_replace('_', ' ', $style_dir));
- if ($is_style_changeable) {
- $list_of_styles[$style_dir] = "<option value=\"".$style_dir."\" ".$selected." /> $show_name </option>";
- $list_of_names[$style_dir] = $show_name;
-
-
- } else {
- echo '<a href="style_preview.php?style='.$style_dir.'" target="preview">'.$show_name.'</a>';
- }
- echo '<br />';
- $counter++;
- }
- }
- }
- @closedir($handle);
- }
-
- asort($list_of_names);
- foreach($list_of_names as $style_dir=>$item) {
- echo $list_of_styles[$style_dir];
- }
-
- echo '</select> ';
- if ($is_style_changeable){
- echo '<button class="save" type="submit" name="submit_stylesheets"> '.get_lang('SaveSettings').' </button></form>';
- }
- }
- function upload_stylesheet($values, $picture) {
-
- $style_name = api_preg_replace('/[^A-Za-z0-9]/', '', $values['name_stylesheet']);
-
- if (!is_dir(api_get_path(SYS_CODE_PATH).'css/'.$style_name.'/')) {
- mkdir(api_get_path(SYS_CODE_PATH).'css/'.$style_name.'/', api_get_permissions_for_new_directories());
- }
- $info = pathinfo($picture['name']);
- if ($info['extension'] == 'zip') {
-
- $zip = new ZipArchive();
- if ($zip->open($picture['tmp_name'])) {
-
- $num_files = $zip->numFiles;
- $valid = true;
- $single_directory = true;
- $invalid_files = array();
- for ($i = 0; $i < $num_files; $i++) {
- $file = $zip->statIndex($i);
- if (substr($file['name'], -1) != '/') {
- $path_parts = pathinfo($file['name']);
- if (!in_array($path_parts['extension'], array('jpg', 'jpeg', 'png', 'gif', 'css'))) {
- $valid = false;
- $invalid_files[] = $file['name'];
- }
- }
- if (strpos($file['name'], '/') === false) {
- $single_directory = false;
- }
- }
- if (!$valid) {
- $error_string = '<ul>';
- foreach ($invalid_files as $invalid_file) {
- $error_string .= '<li>'.$invalid_file.'</li>';
- }
- $error_string .= '</ul>';
- Display::display_error_message(get_lang('ErrorStylesheetFilesExtensionsInsideZip').$error_string, false);
- } else {
-
- if (!$single_directory) {
-
- $zip->extractTo(api_get_path(SYS_CODE_PATH).'css/'.$style_name.'/');
- } else {
- $extraction_path = api_get_path(SYS_CODE_PATH).'css/'.$style_name.'/';
- for ($i = 0; $i < $num_files; $i++) {
- $entry = $zip->getNameIndex($i);
- if (substr($entry, -1) == '/') continue;
- $pos_slash = strpos($entry, '/');
- $entry_without_first_dir = substr($entry, $pos_slash + 1);
-
- if (strpos($entry_without_first_dir, '/') !== false) {
- if (!is_dir($extraction_path.dirname($entry_without_first_dir))) {
-
- @mkdir($extraction_path.dirname($entry_without_first_dir), $mode = 0777, true);
- }
- }
- $fp = $zip->getStream($entry);
- $ofp = fopen( $extraction_path. dirname($entry_without_first_dir).'/'.basename($entry), 'w');
- while (!feof($fp)) {
- fwrite($ofp, fread($fp, 8192));
- }
- fclose($fp);
- fclose($ofp);
- }
- }
- }
- $zip->close();
- } else {
- Display::display_error_message(get_lang('ErrorReadingZip').$info['extension'], false);
- }
- } else {
-
- move_uploaded_file($picture['tmp_name'], api_get_path(SYS_CODE_PATH).'css/'.$style_name.'/'.$picture['name']);
- }
- }
- function store_plugins() {
- $table_settings_current = Database :: get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
- global $_configuration;
-
- $installed_plugins = api_get_settings('Plugins','list',$_configuration['access_url']);
- $shortlist_installed = array();
- foreach ($installed_plugins as $plugin) {
- $shortlist_installed[] = $plugin['subkey'];
- }
- $shortlist_installed = array_flip(array_flip($shortlist_installed));
-
-
-
- $r = api_delete_category_settings('Plugins', $_configuration['access_url']);
- $shortlist_required = array();
-
- foreach ($_POST as $form_name => $formvalue) {
- $form_name_elements = explode('-', $form_name);
- if (is_valid_plugin_location($form_name_elements[1])) {
- $shortlist_required[] = $form_name_elements[0];
-
-
- api_add_setting($form_name_elements['0'], $form_name_elements['1'], $form_name_elements['0'], null, 'Plugins', $form_name_elements['0'], null, null, null, $_configuration['access_url'], 1);
-
- $pluginpath = api_get_path(SYS_PLUGIN_PATH).$form_name_elements[0].'/install.php';
- if (is_file($pluginpath) && is_readable($pluginpath)) {
-
- include $pluginpath;
- }
- }
- }
- foreach ($shortlist_installed as $plugin) {
-
- if (!in_array($plugin,$shortlist_required)) {
-
- $pluginpath = api_get_path(SYS_PLUGIN_PATH).$plugin.'/uninstall.php';
- if (is_file($pluginpath) && is_readable($pluginpath)) {
-
- include $pluginpath;
- }
- }
- }
- }
- function is_valid_plugin_location($location) {
- static $valid_locations = array('loginpage_main', 'loginpage_menu', 'campushomepage_main', 'campushomepage_menu', 'mycourses_main', 'mycourses_menu', 'header', 'footer', 'course_tool_plugin');
- return in_array($location, $valid_locations);
- }
- function store_stylesheets() {
- global $_configuration;
-
- $table_settings_current = Database :: get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
-
- $style = Database::escape_string($_POST['style']);
- if (is_style($style)) {
-
- api_set_setting('stylesheets', $style, null, 'stylesheets', $_configuration['access_url']);
- }
- return true;
- }
- function is_style($style) {
- $dir = api_get_path(SYS_PATH).'main/css/';
- $dirs = scandir($dir);
- $style = str_replace(array('/', '\\'), array('', ''), $style);
- if (in_array($style, $dirs) && is_dir($dir.$style)) {
- return true;
- }
- return false;
- }
- function handle_search() {
- global $SettingsStored, $_configuration;
- require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
- require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
- $search_enabled = api_get_setting('search_enabled');
-
- $form = new FormValidator('search-options', 'post', api_get_self().'?category=Search');
-
- $renderer = & $form->defaultRenderer();
- $renderer->setHeaderTemplate('<div class="sectiontitle">{header}</div>'."\n");
- $renderer->setElementTemplate('<div class="sectioncomment">{label}</div>'."\n".'<div class="sectionvalue">{element}</div>'."\n");
-
- $values = get_settings_options('search_enabled');
- $form->addElement('header', null, get_lang('SearchEnabledTitle'));
-
- $group = array ();
- if (is_array($values)) {
- foreach ($values as $key => $value) {
- $element = & $form->createElement('radio', 'search_enabled', '', get_lang($value['display_text']), $value['value']);
-
- $group[] = $element;
- }
- }
- $form->addGroup($group, 'search_enabled', get_lang('SearchEnabledComment'), '<br />', false);
-
- $search_enabled = api_get_setting('search_enabled');
-
- if ($form->validate()) {
- $formvalues = $form->exportValues();
- $r = api_set_settings_category('Search', 'false', $_configuration['access_url']);
-
- foreach ($formvalues as $key => $value) {
- $result = api_set_setting($key, $value, null, null);
- }
- $search_enabled = $formvalues['search_enabled'];
- Display::display_confirmation_message($SettingsStored);
- }
- $specific_fields = get_specific_field_list();
-
- if ($search_enabled == 'true') {
-
-
- $form->addElement('header', null, get_lang('SearchShowUnlinkedResultsTitle'));
-
- $values = get_settings_options('search_show_unlinked_results');
- $group = array ();
- foreach ($values as $key => $value) {
- $element = & $form->createElement('radio', 'search_show_unlinked_results', '', get_lang($value['display_text']), $value['value']);
- $group[] = $element;
- }
- $form->addGroup($group, 'search_show_unlinked_results', get_lang('SearchShowUnlinkedResultsComment'), '<br />', false);
- $default_values['search_show_unlinked_results'] = api_get_setting('search_show_unlinked_results');
-
-
- $form->addElement('header', null, get_lang('SearchPrefilterPrefix'));
-
-
- $sf_values = array();
- foreach ($specific_fields as $sf) {
- $sf_values[$sf['code']] = $sf['name'];
- }
- $group = array();
- $url = Display::div(Display::url(get_lang('AddSpecificSearchField'), 'specific_fields.php'), array('class'=>'sectioncomment'));
- if (empty($sf_values)) {
- $form->addElement('html', get_lang('SearchPrefilterPrefix'));
- } else {
- $form->addElement('select', 'search_prefilter_prefix', get_lang('SearchPrefilterPrefix'), $sf_values, '');
- $default_values['search_prefilter_prefix'] = api_get_setting('search_prefilter_prefix');
- }
- $form->addElement('html', $url);
- }
- $default_values['search_enabled'] = $search_enabled;
-
- $form->addElement('style_submit_button', 'submit', get_lang('Save'),'class="save"');
- $form->setDefaults($default_values);
-
- echo '<div id="search-options-form">';
- $form->display();
- echo '</div>';
-
- if ($search_enabled == 'true') {
- require_once api_get_path(LIBRARY_PATH).'sortabletable.class.php';
- $xapian_path = api_get_path(SYS_PATH).'searchdb';
-
-
-
- $xapian_loaded = Display::return_icon('bullet_green.gif', get_lang('Ok'));
- $dir_exists = Display::return_icon('bullet_green.gif', get_lang('Ok'));
- $dir_is_writable = Display::return_icon('bullet_green.gif', get_lang('Ok'));
- $specific_fields_exists = Display::return_icon('bullet_green.gif', get_lang('Ok'));
-
-
- if (empty($specific_fields)) {
- $specific_fields_exists = Display::return_icon('bullet_red.gif', get_lang('AddSpecificSearchField'));
- }
-
- if (!extension_loaded('xapian')) {
- $xapian_loaded = Display::return_icon('bullet_red.gif', get_lang('Error'));
- }
-
- if (!is_dir($xapian_path)) {
- $dir_exists = Display::return_icon('bullet_red.gif', get_lang('Error'));
- }
-
- if (!is_writable($xapian_path)) {
- $dir_is_writable = Display::return_icon('bullet_red.gif', get_lang('Error'));
- }
-
- $data[] = array(get_lang('XapianModuleInstalled'),$xapian_loaded);
- $data[] = array(get_lang('DirectoryExists').' - '.$xapian_path,$dir_exists);
- $data[] = array(get_lang('IsWritable').' - '.$xapian_path,$dir_is_writable);
- $data[] = array(get_lang('SpecificSearchFieldsAvailable') ,$specific_fields_exists);
- echo Display::tag('h3', get_lang('Settings'));
- $table = new SortableTableFromArray($data);
- $table->set_header(0, get_lang('Setting'), false);
- $table->set_header(1, get_lang('Status'), false);
- echo $table->display();
-
-
- if (api_is_windows_os() == false) {
- $list_of_programs = array('pdftotext','ps2pdf', 'catdoc','html2text','unrtf', 'catppt', 'xls2csv');
-
- foreach($list_of_programs as $program) {
- $output = $ret_val = null;
- exec("which $program", $output, $ret_val);
- $icon = Display::return_icon('bullet_red.gif', get_lang('NotInstalled'));
- if (!empty($output[0])) {
- $icon = Display::return_icon('bullet_green.gif', get_lang('Installed'));
- }
- $data2[]= array($program, $output[0], $icon);
- }
- echo Display::tag('h3', get_lang('ProgramsNeededToConvertFiles'));
- $table = new SortableTableFromArray($data2);
- $table->set_header(0, get_lang('Program'), false);
- $table->set_header(1, get_lang('Path'), false);
- $table->set_header(2, get_lang('Status'), false);
- echo $table->display();
- } else {
- Display::display_warning_message(get_lang('YouAreUsingChamiloInAWindowsPlatformSadlyYouCantConvertDocumentsInOrderToSearchTheContentUsingThisTool'));
- }
- }
- }
- function handle_templates() {
- if ($_GET['action'] != 'add') {
- echo '<div class="actions" style="margin-left: 1px;">';
- echo '<a href="settings.php?category=Templates&action=add">'.Display::return_icon('new_template.png', get_lang('AddTemplate'),'','32').'</a>';
- echo '</div>';
- }
- if ($_GET['action'] == 'add' || ($_GET['action'] == 'edit' && is_numeric($_GET['id']))) {
- add_edit_template();
-
- $user_id = api_get_user_id();
- $category = $_GET['category'];
- event_system(LOG_CONFIGURATION_SETTINGS_CHANGE, LOG_CONFIGURATION_SETTINGS_CATEGORY, $category, api_get_utc_datetime(), $user_id);
- } else {
- if ($_GET['action'] == 'delete' && is_numeric($_GET['id'])) {
- delete_template($_GET['id']);
-
- $user_id = api_get_user_id();
- $category = $_GET['category'];
- event_system(LOG_CONFIGURATION_SETTINGS_CHANGE, LOG_CONFIGURATION_SETTINGS_CATEGORY, $category, api_get_utc_datetime(), $user_id);
- }
- display_templates();
- }
- }
- function display_templates() {
- $table = new SortableTable('templates', 'get_number_of_templates', 'get_template_data', 1);
- $table->set_additional_parameters(array('category' => Security::remove_XSS($_GET['category'])));
- $table->set_header(0, get_lang('Image'), true, array('style' => 'width: 101px;'));
- $table->set_header(1, get_lang('Title'));
- $table->set_header(2, get_lang('Actions'), false, array('style' => 'width:50px;'));
- $table->set_column_filter(2, 'actions_filter');
- $table->set_column_filter(0, 'image_filter');
- $table->display();
- }
- function get_number_of_templates() {
-
- $table_system_template = Database :: get_main_table('system_template');
-
- $sql = "SELECT COUNT(id) AS total FROM $table_system_template";
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
-
- return $row['total'];
- }
- function get_template_data($from, $number_of_items, $column, $direction) {
-
- $table_system_template = Database :: get_main_table('system_template');
-
- $sql = "SELECT image as col0, title as col1, id as col2 FROM $table_system_template";
- $sql .= " ORDER BY col$column $direction ";
- $sql .= " LIMIT $from,$number_of_items";
- $result = Database::query($sql);
- while ($row = Database::fetch_array($result)) {
- $row['1'] = get_lang($row['1']);
- $return[] = $row;
- }
-
- return $return;
- }
- function actions_filter($id) {
- $return = '<a href="settings.php?category=Templates&action=edit&id='.Security::remove_XSS($id).'">'.Display::return_icon('edit.png', get_lang('Edit'),'',22).'</a>';
- $return .= '<a href="settings.php?category=Templates&action=delete&id='.Security::remove_XSS($id).'" onClick="javascript:if(!confirm('."'".get_lang('ConfirmYourChoice')."'".')) return false;">'.Display::return_icon('delete.png', get_lang('Delete'),'',22).'</a>';
- return $return;
- }
- function image_filter($image) {
- if (!empty($image)) {
- return '<img src="'.api_get_path(WEB_PATH).'home/default_platform_document/template_thumb/'.$image.'" alt="'.get_lang('TemplatePreview').'"/>';
- } else {
- return '<img src="'.api_get_path(WEB_PATH).'home/default_platform_document/template_thumb/noimage.gif" alt="'.get_lang('NoTemplatePreview').'"/>';
- }
- }
- function add_edit_template() {
-
- $form = new FormValidator('template', 'post', 'settings.php?category=Templates&action='.Security::remove_XSS($_GET['action']).'&id='.Security::remove_XSS($_GET['id']));
-
- if ($_GET['action'] == 'add') {
- $title = get_lang('AddTemplate');
- } else {
- $title = get_lang('EditTemplate');
- }
- $form->addElement('header', '', $title);
-
- $form->add_textfield('title', get_lang('Title'), false);
-
- $form->addElement('html_editor', 'template_text', get_lang('Text'), null, array('ToolbarSet' => 'AdminTemplates', 'Width' => '100%', 'Height' => '400'));
-
- $form->addElement('file','template_image',get_lang('Image'),'');
-
- $form->addElement('static', 'file_comment', '', get_lang('TemplateImageComment100x70'));
-
- if ($_GET['action'] == 'edit') {
-
- $table_system_template = Database :: get_main_table('system_template');
- $sql = "SELECT * FROM $table_system_template WHERE id = '".Database::escape_string($_GET['id'])."'";
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- $defaults['template_id'] = intval($_GET['id']);
- $defaults['template_text'] = $row['content'];
-
- $defaults['title'] = get_lang($row['title']);
-
- $form->addElement('hidden', 'template_id');
-
- if (!empty($row['image'])) {
- $form->addElement('static', 'template_image_preview', '', '<img src="'.api_get_path(WEB_PATH).'home/default_platform_document/template_thumb/'.$row['image'].'" alt="'.get_lang('TemplatePreview').'"/>');
- } else {
- $form->addElement('static', 'template_image_preview', '', '<img src="'.api_get_path(WEB_PATH).'home/default_platform_document/template_thumb/noimage.gif" alt="'.get_lang('NoTemplatePreview').'"/>');
- }
-
- $form->setDefaults($defaults);
- }
-
- $form->addElement('style_submit_button' , 'submit', get_lang('Ok') ,'class="save"');
-
- $form->addRule('title', '<div class="required">'.get_lang('ThisFieldIsRequired'), 'required');
- $form->addRule('template_text', '<div class="required">'.get_lang('ThisFieldIsRequired'), 'required');
-
- if ($form->validate()) {
- $check = Security::check_token('post');
- if ($check) {
-
- $values = $form->exportValues();
-
- if (!empty($_FILES['template_image']['name'])) {
- require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
- $upload_ok = process_uploaded_file($_FILES['template_image']);
- if ($upload_ok) {
-
- $new_file_name = add_ext_on_mime(stripslashes($_FILES['template_image']['name']), $_FILES['template_image']['type']);
-
- $upload_dir = api_get_path(SYS_PATH).'home/default_platform_document/template_thumb/';
-
- if (!is_dir($upload_dir)) {
- mkdir($upload_dir, api_get_permissions_for_new_directories());
- }
-
- $temp = new Image($_FILES['template_image']['tmp_name']);
- $picture_info = $temp->get_image_info();
- $max_width_for_picture = 100;
- if ($picture_info['width'] > $max_width_for_picture) {
- $thumbwidth = $max_width_for_picture;
- if (empty($thumbwidth) || $thumbwidth == 0) {
- $thumbwidth = $max_width_for_picture;
- }
- $new_height = round(($thumbwidth / $picture_info['width']) * $picture_info['height']);
- $temp->resize($thumbwidth, $new_height, 0);
- }
- $temp->send_image($upload_dir.$new_file_name);
- }
- }
-
- $table_system_template = Database :: get_main_table('system_template');
- if ($_GET['action'] == 'add') {
- $content_template = '<head>{CSS}<style type="text/css">.text{font-weight: normal;}</style></head><body>'.Database::escape_string($values['template_text']).'</body>';
- $sql = "INSERT INTO $table_system_template (title, content, image) VALUES ('".Database::escape_string($values['title'])."','".$content_template."','".Database::escape_string($new_file_name)."')";
- $result = Database::query($sql);
-
- Display::display_confirmation_message(get_lang('TemplateAdded'));
- echo '<a href="settings.php?category=Templates&action=add">'.Display::return_icon('new_template.png', get_lang('AddTemplate'),'','32').'</a>';
- } else {
- $content_template = '<head>{CSS}<style type="text/css">.text{font-weight: normal;}</style></head><body>'.Database::escape_string($values['template_text']).'</body>';
- $sql = "UPDATE $table_system_template set title = '".Database::escape_string($values['title'])."', content = '".$content_template."'";
- if (!empty($new_file_name)) {
- $sql .= ", image = '".Database::escape_string($new_file_name)."'";
- }
- $sql .= " WHERE id='".Database::escape_string($_GET['id'])."'";
- $result = Database::query($sql);
-
- Display::display_confirmation_message(get_lang('TemplateEdited'));
- }
- }
- Security::clear_token();
- display_templates();
- } else {
- $token = Security::get_token();
- $form->addElement('hidden','sec_token');
- $form->setConstants(array('sec_token' => $token));
-
- $form->display();
- }
- }
- function delete_template($id) {
-
- $table_system_template = Database :: get_main_table('system_template');
- $sql = "SELECT * FROM $table_system_template WHERE id = '".Database::escape_string($id)."'";
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- if (!empty($row['image'])) {
- @unlink(api_get_path(SYS_PATH).'home/default_platform_document/template_thumb/'.$row['image']);
- }
-
- $sql = "DELETE FROM $table_system_template WHERE id = '".Database::escape_string($id)."'";
- $result = Database::query($sql);
-
- Display::display_confirmation_message(get_lang('TemplateDeleted'));
- }
- function select_timezone_value() {
- return api_get_timezones();
- }
- function select_gradebook_number_decimals() {
- return array('0', '1', '2');
- }
- function update_gradebook_score_display_custom_values($values) {
- require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/scoredisplay.class.php';
- $scoredisplay = ScoreDisplay::instance();
- $scores = $values['gradebook_score_display_custom_values_endscore'];
- $displays = $values['gradebook_score_display_custom_values_displaytext'];
- $nr_displays = count($displays);
- $final = array();
- for ($i = 1; $i < $nr_displays; $i++) {
- if (!empty($scores[$i]) && !empty($displays[$i])) {
- $final[$i]['score'] = $scores[$i];
- $final[$i]['display'] = $displays[$i];
- }
- }
- $scoredisplay->update_custom_score_display_settings($final);
- }
|