/**
  * Construct
  * @param string $title
  */
 public function __construct($title)
 {
     $this->tpl = new Template($title);
     $this->home = api_get_home_path();
     $this->user_id = api_get_user_id();
     $this->load_directories_preview = false;
     if (api_get_setting('show_documents_preview') == 'true') {
         $this->load_directories_preview = true;
     }
 }
 /**
  * Construct
  * @param string $title
  */
 public function __construct($title)
 {
     $this->tpl = new Template($title);
     $this->home = api_get_home_path();
     $this->user_id = api_get_user_id();
     $this->load_directories_preview = false;
     // Load footer plugins systematically
     /*$config = api_get_settings_params(array('subkey = ? ' => 'customfooter', ' AND category = ? ' => 'Plugins'));
       if (!empty($config)) {
           foreach ($config as $fooid => $configrecord) {
               $canonic = preg_replace('/^customfooter_/', '', $configrecord['variable']);
               $footerconfig->$canonic = $configrecord['selected_value'];
           }
           if (!empty($footerconfig->footer_left)) {
               $this->tpl->assign('plugin_footer_left', $footerconfig->footer_left);
           }
           if (!empty($footerconfig->footer_right)) {
               $this->tpl->assign('plugin_footer_right', $footerconfig->footer_right);
           }
       }*/
     if (api_get_setting('show_documents_preview') == 'true') {
         $this->load_directories_preview = true;
     }
 }
Example #3
0
 /**
  * Return the homepage, including announcements
  * @return string The portal's homepage as an HTML string
  * @assert () != ''
  */
 public function returnHomePage()
 {
     // Including the page for the news
     $html = null;
     $home = api_get_path(SYS_DATA_PATH) . api_get_home_path();
     $home_top_temp = null;
     if (!empty($_GET['include']) && preg_match('/^[a-zA-Z0-9_-]*\\.html$/', $_GET['include'])) {
         $open = @(string) file_get_contents(api_get_path(SYS_PATH) . $home . $_GET['include']);
         $html = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
     } else {
         $user_selected_language = api_get_user_language();
         if (!file_exists($home . 'home_news_' . $user_selected_language . '.html')) {
             if (file_exists($home . 'home_top.html')) {
                 $home_top_temp = file($home . 'home_top.html');
             } else {
                 //$home_top_temp = file('home/'.'home_top.html');
             }
             if (!empty($home_top_temp)) {
                 $home_top_temp = implode('', $home_top_temp);
             }
         } else {
             if (file_exists($home . 'home_top_' . $user_selected_language . '.html')) {
                 $home_top_temp = file_get_contents($home . 'home_top_' . $user_selected_language . '.html');
             } else {
                 $home_top_temp = file_get_contents($home . 'home_top.html');
             }
         }
         if (empty($home_top_temp) && api_is_platform_admin()) {
             $home_top_temp = get_lang('PortalHomepageDefaultIntroduction');
         }
         $open = str_replace('{rel_path}', api_get_path(REL_PATH), $home_top_temp);
         if (!empty($open)) {
             $html = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
         }
     }
     return $html;
 }
Example #4
0
 // Avoid form elements which have nothing to do with settings
 if ($key == 'search_field' or $key == 'submit_fixed_in_bottom') {
     continue;
 }
 // Treat gradebook values in separate function.
 //if (strpos($key, 'gradebook_score_display_custom_values') === false) {
 if (!is_array($value)) {
     $old_value = api_get_setting($key);
     switch ($key) {
         case 'header_extra_content':
             file_put_contents(api_get_path(SYS_PATH) . api_get_home_path() . '/header_extra_content.txt', $value);
             $value = api_get_home_path() . '/header_extra_content.txt';
             break;
         case 'footer_extra_content':
             file_put_contents(api_get_path(SYS_PATH) . api_get_home_path() . '/footer_extra_content.txt', $value);
             $value = api_get_home_path() . '/footer_extra_content.txt';
             break;
             // URL validation for some settings.
         // URL validation for some settings.
         case 'InstitutionUrl':
         case 'course_validation_terms_and_conditions_url':
             $value = trim(Security::remove_XSS($value));
             if ($value != '') {
                 // Here we accept absolute URLs only.
                 if (strpos($value, '://') === false) {
                     $value = 'http://' . $value;
                 }
                 if (!api_valid_url($value, true)) {
                     // If the new (non-empty) URL value is invalid, then the old URL value stays.
                     $value = $old_value;
                 }
Example #5
0
/**
 * Returns the value of a setting from the web-adjustable admin config settings.
 *
 * WARNING true/false are stored as string, so when comparing you need to check e.g.
 * if (api_get_setting('course.show_navigation_menu') == 'true') //CORRECT
 * instead of
 * if (api_get_setting('course.show_navigation_menu') == true) //INCORRECT
 * @param string    $variable The variable name
 * @return string
 *
 * @author Julio Montoya
 */
function api_get_setting($variable)
{
    $variable = trim($variable);
    switch ($variable) {
        case 'server_type':
            $test = ['dev', 'test'];
            $environment = Container::getEnvironment();
            if (in_array($environment, $test)) {
                return 'test';
            }
            return 'prod';
        case 'stylesheets':
            $variable = 'platform.theme';
        default:
            return Container::getSettingsManager()->getSetting($variable);
    }
    global $_setting;
    if ($variable == 'header_extra_content') {
        $filename = api_get_path(SYS_PATH) . api_get_home_path() . 'header_extra_content.txt';
        if (file_exists($filename)) {
            $value = file_get_contents($filename);
            return $value;
        } else {
            return '';
        }
    }
    if ($variable == 'footer_extra_content') {
        $filename = api_get_path(SYS_PATH) . api_get_home_path() . 'footer_extra_content.txt';
        if (file_exists($filename)) {
            $value = file_get_contents($filename);
            return $value;
        } else {
            return '';
        }
    }
    $value = null;
    if (is_null($key)) {
        $value = isset($_setting[$variable]) && $_setting[$variable] != '' ? $_setting[$variable] : null;
    } else {
        if (isset($_setting[$variable][$key])) {
            $value = $_setting[$variable][$key];
        }
    }
    return $value;
}
Example #6
0
function generate_settings_form($settings, $settings_by_access_list)
{
    global $_configuration, $settings_to_avoid, $convert_byte_to_mega_list;
    $table_settings_current = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
    $form = new FormValidator('settings', 'post', 'settings.php?category=' . Security::remove_XSS($_GET['category']));
    $form->addElement('hidden', 'search_field', !empty($_GET['search_field']) ? Security::remove_XSS($_GET['search_field']) : null);
    $url_id = api_get_current_access_url_id();
    if (!empty($_configuration['multiple_access_urls']) && api_is_global_platform_admin() && $url_id == 1) {
        $group = array();
        $group[] = $form->createElement('button', 'mark_all', get_lang('MarkAll'));
        $group[] = $form->createElement('button', 'unmark_all', get_lang('UnmarkAll'));
        $form->addGroup($group, 'buttons_in_action_right');
    }
    $default_values = array();
    $url_info = api_get_access_url($url_id);
    $i = 0;
    foreach ($settings as $row) {
        if (in_array($row['variable'], array_keys($settings_to_avoid))) {
            continue;
        }
        if (!empty($_configuration['multiple_access_urls'])) {
            if (api_is_global_platform_admin()) {
                if ($row['access_url_locked'] == 0) {
                    if ($url_id == 1) {
                        if ($row['access_url_changeable'] == '1') {
                            $form->addElement('html', '<div style="float: right;"><a class="share_this_setting" data_status = "0"  data_to_send = "' . $row['variable'] . '" href="javascript:void(0);">' . Display::return_icon('shared_setting.png', get_lang('ChangeSharedSetting')) . '</a></div>');
                        } else {
                            $form->addElement('html', '<div style="float: right;"><a class="share_this_setting" data_status = "1" data_to_send = "' . $row['variable'] . '" href="javascript:void(0);">' . Display::return_icon('shared_setting_na.png', get_lang('ChangeSharedSetting')) . '</a></div>');
                        }
                    } else {
                        if ($row['access_url_changeable'] == '1') {
                            $form->addElement('html', '<div style="float: right;">' . Display::return_icon('shared_setting.png', get_lang('ChangeSharedSetting')) . '</div>');
                        } else {
                            $form->addElement('html', '<div style="float: right;">' . Display::return_icon('shared_setting_na.png', get_lang('ChangeSharedSetting')) . '</div>');
                        }
                    }
                }
            }
        }
        $hideme = array();
        $hide_element = false;
        if ($_configuration['access_url'] != 1) {
            if ($row['access_url_changeable'] == 0) {
                // We hide the element in other cases (checkbox, radiobutton) we 'freeze' the element.
                $hide_element = true;
                $hideme = array('disabled');
            } elseif ($url_info['active'] == 1) {
                // We show the elements.
                if (empty($row['variable'])) {
                    $row['variable'] = 0;
                }
                if (empty($row['subkey'])) {
                    $row['subkey'] = 0;
                }
                if (empty($row['category'])) {
                    $row['category'] = 0;
                }
                if (is_array($settings_by_access_list[$row['variable']][$row['subkey']][$row['category']])) {
                    // We are sure that the other site have a selected value.
                    if ($settings_by_access_list[$row['variable']][$row['subkey']][$row['category']]['selected_value'] != '') {
                        $row['selected_value'] = $settings_by_access_list[$row['variable']][$row['subkey']][$row['category']]['selected_value'];
                    }
                }
                // There is no else{} statement because we load the default $row['selected_value'] of the main Chamilo site.
            }
        }
        switch ($row['type']) {
            case 'textfield':
                if (in_array($row['variable'], $convert_byte_to_mega_list)) {
                    $form->addElement('text', $row['variable'], array(get_lang($row['title']), get_lang($row['comment']), get_lang('MB')), array('maxlength' => '8'));
                    $form->applyFilter($row['variable'], 'html_filter');
                    $default_values[$row['variable']] = round($row['selected_value'] / 1024 / 1024, 1);
                } elseif ($row['variable'] == 'account_valid_duration') {
                    $form->addElement('text', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), array('maxlength' => '5'));
                    $form->applyFilter($row['variable'], 'html_filter');
                    $default_values[$row['variable']] = $row['selected_value'];
                    // For platform character set selection: Conversion of the textfield to a select box with valid values.
                } elseif ($row['variable'] == 'platform_charset') {
                    continue;
                } else {
                    $hideme['class'] = 'col-md-4';
                    $form->addElement('text', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), $hideme);
                    $form->applyFilter($row['variable'], 'html_filter');
                    $default_values[$row['variable']] = $row['selected_value'];
                }
                break;
            case 'textarea':
                if ($row['variable'] == 'header_extra_content') {
                    $file = api_get_path(SYS_PATH) . api_get_home_path() . 'header_extra_content.txt';
                    $value = '';
                    if (file_exists($file)) {
                        $value = file_get_contents($file);
                    }
                    $form->addElement('textarea', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), array('rows' => '10'), $hideme);
                    $default_values[$row['variable']] = $value;
                } elseif ($row['variable'] == 'footer_extra_content') {
                    $file = api_get_path(SYS_PATH) . api_get_home_path() . 'footer_extra_content.txt';
                    $value = '';
                    if (file_exists($file)) {
                        $value = file_get_contents($file);
                    }
                    $form->addElement('textarea', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), array('rows' => '10'), $hideme);
                    $default_values[$row['variable']] = $value;
                } else {
                    $form->addElement('textarea', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), array('rows' => '10'), $hideme);
                    $default_values[$row['variable']] = $row['selected_value'];
                }
                break;
            case 'radio':
                $values = api_get_settings_options($row['variable']);
                $group = array();
                if (is_array($values)) {
                    foreach ($values as $key => $value) {
                        $element =& $form->createElement('radio', $row['variable'], '', get_lang($value['display_text']), $value['value']);
                        if ($hide_element) {
                            $element->freeze();
                        }
                        $group[] = $element;
                    }
                }
                $form->addGroup($group, $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), '', false);
                $default_values[$row['variable']] = $row['selected_value'];
                break;
            case 'checkbox':
                // 1. We collect all the options of this variable.
                $sql = "SELECT * FROM {$table_settings_current}\n                        WHERE variable='" . $row['variable'] . "' AND access_url =  1";
                $result = Database::query($sql);
                $group = array();
                while ($rowkeys = Database::fetch_array($result)) {
                    // Profile tab option should be hidden when the social tool is enabled.
                    if (api_get_setting('social.allow_social_tool') == 'true') {
                        if ($rowkeys['variable'] == 'show_tabs' && $rowkeys['subkey'] == 'my_profile') {
                            continue;
                        }
                    }
                    // Hiding the gradebook option.
                    if ($rowkeys['variable'] == 'show_tabs' && $rowkeys['subkey'] == 'my_gradebook') {
                        continue;
                    }
                    $element =& $form->createElement('checkbox', $rowkeys['subkey'], '', get_lang($rowkeys['subkeytext']));
                    if ($row['access_url_changeable'] == 1) {
                        // 2. We look into the DB if there is a setting for a specific access_url.
                        $access_url = $_configuration['access_url'];
                        if (empty($access_url)) {
                            $access_url = 1;
                        }
                        $sql = "SELECT selected_value FROM {$table_settings_current}\n                                WHERE\n                                    variable='" . $rowkeys['variable'] . "' AND\n                                    subkey='" . $rowkeys['subkey'] . "' AND\n                                    subkeytext='" . $rowkeys['subkeytext'] . "' AND\n                                    access_url =  {$access_url}";
                        $result_access = Database::query($sql);
                        $row_access = Database::fetch_array($result_access);
                        if ($row_access['selected_value'] == 'true' && !$form->isSubmitted()) {
                            $element->setChecked(true);
                        }
                    } else {
                        if ($rowkeys['selected_value'] == 'true' && !$form->isSubmitted()) {
                            $element->setChecked(true);
                        }
                    }
                    if ($hide_element) {
                        $element->freeze();
                    }
                    $group[] = $element;
                }
                $form->addGroup($group, $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), '');
                break;
            case 'link':
                $form->addElement('static', null, array(get_lang($row['title']), get_lang($row['comment'])), get_lang('CurrentValue') . ' : ' . $row['selected_value'], $hideme);
                break;
            case 'select':
                /*
                 * To populate the list of options, the select type dynamically calls a function that must be called select_ + the name of the variable being displayed.
                 * The functions being called must be added to the file settings.lib.php.
                 */
                $form->addElement('select', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), call_user_func('select_' . $row['variable']), $hideme);
                $default_values[$row['variable']] = $row['selected_value'];
                break;
            case 'custom':
                break;
        }
        switch ($row['variable']) {
            case 'pdf_export_watermark_enable':
                $url = PDF::get_watermark(null);
                if ($url != false) {
                    $delete_url = '<a href="?delete_watermark">' . get_lang('DelImage') . ' ' . Display::return_icon('delete.png', get_lang('DelImage')) . '</a>';
                    $form->addElement('html', '<div style="max-height:100px; max-width:100px; margin-left:162px; margin-bottom:10px; clear:both;"><img src="' . $url . '" style="margin-bottom:10px;" />' . $delete_url . '</div>');
                }
                $form->addElement('file', 'pdf_export_watermark_path', get_lang('AddWaterMark'));
                $allowed_picture_types = array('jpg', 'jpeg', 'png', 'gif');
                $form->addRule('pdf_export_watermark_path', get_lang('OnlyImagesAllowed') . ' (' . implode(',', $allowed_picture_types) . ')', 'filetype', $allowed_picture_types);
                break;
            case 'timezone_value':
                $timezone = $row['selected_value'];
                if (empty($timezone)) {
                    $timezone = _api_get_timezone();
                }
                $form->addElement('html', sprintf(get_lang('LocalTimeUsingPortalTimezoneXIsY'), $timezone, api_get_local_time()));
                break;
        }
    }
    // end for
    if (!empty($settings)) {
        $form->setDefaults($default_values);
    }
    $form->addHtml('<div class="bottom_actions">');
    $form->addButtonSave(get_lang('SaveSettings'));
    $form->addHtml('</div>');
    return $form;
}
Example #7
0
/**
 * Returns the value of a setting from the web-adjustable admin config settings.
 *
 * WARNING true/false are stored as string, so when comparing you need to check e.g.
 * if (api_get_setting('show_navigation_menu') == 'true') //CORRECT
 * instead of
 * if (api_get_setting('show_navigation_menu') == true) //INCORRECT
 * @param string    $variable The variable name
 * @param string    $key The subkey (sub-variable) if any. Defaults to NULL
 * @author René Haentjens
 * @author Bart Mollet
 */
function api_get_setting($variable, $key = null)
{
    return Container::getSettingsManager()->getSetting($variable);
    //chamilo_core.settings_schema.platform
    $_setting = Session::read('_setting');
    if ($variable == 'header_extra_content') {
        $filename = api_get_path(SYS_PATH) . api_get_home_path() . 'header_extra_content.txt';
        if (file_exists($filename)) {
            $value = file_get_contents($filename);
            return $value;
        } else {
            return '';
        }
    }
    if ($variable == 'footer_extra_content') {
        $filename = api_get_path(SYS_PATH) . api_get_home_path() . 'footer_extra_content.txt';
        if (file_exists($filename)) {
            $value = file_get_contents($filename);
            return $value;
        } else {
            return '';
        }
    }
    $value = null;
    if (is_null($key)) {
        $value = isset($_setting[$variable]) && $_setting[$variable] != '' ? $_setting[$variable] : null;
    } else {
        if (isset($_setting[$variable][$key])) {
            $value = $_setting[$variable][$key];
        }
    }
    return $value;
}
Example #8
0
/**
 * Returns the value of a setting from the web-adjustable admin config settings.
 *
 * WARNING true/false are stored as string, so when comparing you need to check e.g.
 * if (api_get_setting('show_navigation_menu') == 'true') //CORRECT
 * instead of
 * if (api_get_setting('show_navigation_menu') == true) //INCORRECT
 * @param string    The variable name
 * @param string    The subkey (sub-variable) if any. Defaults to NULL
 * @author René Haentjens
 * @author Bart Mollet
 */
function api_get_setting($variable, $key = null)
{
    $_setting = Session::read('_setting');
    if ($variable == 'header_extra_content') {
        $filename = api_get_path(SYS_PATH) . api_get_home_path() . 'header_extra_content.txt';
        if (file_exists($filename)) {
            $value = file_get_contents($filename);
            return $value;
        } else {
            return '';
        }
    }
    if ($variable == 'footer_extra_content') {
        $filename = api_get_path(SYS_PATH) . api_get_home_path() . 'footer_extra_content.txt';
        if (file_exists($filename)) {
            $value = file_get_contents($filename);
            return $value;
        } else {
            return '';
        }
    }
    $value = null;
    if (is_null($key)) {
        $value = isset($_setting[$variable]) && $_setting[$variable] != '' ? $_setting[$variable] : null;
    } else {
        if (isset($_setting[$variable][$key])) {
            $value = $_setting[$variable][$key];
        }
    }
    return $value;
}