Example #1
0
/**
 * @param int $userId
 */
function preventMultipleLogin($userId)
{
    $table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ONLINE);
    $userId = intval($userId);
    if (api_get_settings('prevent_multiple_simultaneous_login') === 'true') {
        if (!empty($userId) && !api_is_anonymous()) {
            $isFirstLogin = Session::read('first_user_login');
            if (empty($isFirstLogin)) {
                $sql = "SELECT login_id FROM {$table}\n                        WHERE login_user_id = " . $userId . " LIMIT 1";
                $result = Database::query($sql);
                $loginData = array();
                if (Database::num_rows($result)) {
                    $loginData = Database::fetch_array($result);
                }
                $userIsReallyOnline = user_is_online($userId);
                // Trying double login.
                if (!empty($loginData) && $userIsReallyOnline == true) {
                    session_regenerate_id();
                    Session::destroy();
                    header('Location: ' . api_get_path(WEB_PATH) . 'index.php?loginFailed=1&error=multiple_connection_not_allowed');
                    exit;
                } else {
                    // First time
                    Session::write('first_user_login', 1);
                }
            }
        }
    }
}
Example #2
0
 function get_areas_by_plugin($plugin_name)
 {
     $result = api_get_settings('Plugins');
     $areas = array();
     foreach ($result as $row) {
         if ($plugin_name == $row['selected_value']) {
             $areas[] = $row['variable'];
         }
     }
     return $areas;
 }
Example #3
0
function get_settings($category = null)
{
    $url_id = api_get_current_access_url_id();
    $settings_by_access_list = array();
    if ($url_id == 1) {
        $settings = api_get_settings($category, 'group', $url_id);
    } else {
        $url_info = api_get_access_url($url_id);
        if ($url_info['active'] == 1) {
            // The default settings of Chamilo
            $settings = api_get_settings($category, 'group', 1, 0);
            // The settings that are changeable from a particular site.
            $settings_by_access = api_get_settings($category, 'group', $url_id, 1);
            foreach ($settings_by_access as $row) {
                if (empty($row['variable'])) {
                    $row['variable'] = 0;
                }
                if (empty($row['subkey'])) {
                    $row['subkey'] = 0;
                }
                if (empty($row['category'])) {
                    $row['category'] = 0;
                }
                // One more validation if is changeable.
                if ($row['access_url_changeable'] == 1) {
                    $settings_by_access_list[$row['variable']][$row['subkey']][$row['category']] = $row;
                } else {
                    $settings_by_access_list[$row['variable']][$row['subkey']][$row['category']] = array();
                }
            }
        }
    }
    if (isset($category) && $category == 'search_setting') {
        if (!empty($_REQUEST['search_field'])) {
            $settings = search_setting($_REQUEST['search_field']);
        }
    }
    return array('settings' => $settings, 'settings_by_access_list' => $settings_by_access_list);
}
Example #4
0
function api_set_settings_and_plugins()
{
    global $_configuration;
    $_setting = array();
    $_plugins = array();
    // access_url == 1 is the default chamilo location
    $settings_by_access_list = array();
    $access_url_id = api_get_current_access_url_id();
    if ($access_url_id != 1) {
        $url_info = api_get_access_url($_configuration['access_url']);
        if ($url_info['active'] == 1) {
            $settings_by_access =& api_get_settings(null, 'list', $_configuration['access_url'], 1);
            foreach ($settings_by_access as &$row) {
                if (empty($row['variable'])) {
                    $row['variable'] = 0;
                }
                if (empty($row['subkey'])) {
                    $row['subkey'] = 0;
                }
                if (empty($row['category'])) {
                    $row['category'] = 0;
                }
                $settings_by_access_list[$row['variable']][$row['subkey']][$row['category']] = $row;
            }
        }
    }
    $result = api_get_settings(null, 'list', 1);
    foreach ($result as &$row) {
        if ($access_url_id != 1) {
            if ($url_info['active'] == 1) {
                $var = empty($row['variable']) ? 0 : $row['variable'];
                $subkey = empty($row['subkey']) ? 0 : $row['subkey'];
                $category = empty($row['category']) ? 0 : $row['category'];
            }
            if ($row['access_url_changeable'] == 1 && $url_info['active'] == 1) {
                if (isset($settings_by_access_list[$var]) && $settings_by_access_list[$var][$subkey][$category]['selected_value'] != '') {
                    if ($row['subkey'] == null) {
                        $_setting[$row['variable']] = $settings_by_access_list[$var][$subkey][$category]['selected_value'];
                    } else {
                        $_setting[$row['variable']][$row['subkey']] = $settings_by_access_list[$var][$subkey][$category]['selected_value'];
                    }
                } else {
                    if ($row['subkey'] == null) {
                        $_setting[$row['variable']] = $row['selected_value'];
                    } else {
                        $_setting[$row['variable']][$row['subkey']] = $row['selected_value'];
                    }
                }
            } else {
                if ($row['subkey'] == null) {
                    $_setting[$row['variable']] = $row['selected_value'];
                } else {
                    $_setting[$row['variable']][$row['subkey']] = $row['selected_value'];
                }
            }
        } else {
            if ($row['subkey'] == null) {
                $_setting[$row['variable']] = $row['selected_value'];
            } else {
                $_setting[$row['variable']][$row['subkey']] = $row['selected_value'];
            }
        }
    }
    $result = api_get_settings('Plugins', 'list', $access_url_id);
    $_plugins = array();
    foreach ($result as &$row) {
        $key =& $row['variable'];
        if (is_string($_setting[$key])) {
            $_setting[$key] = array();
        }
        $_setting[$key][] = $row['selected_value'];
        $_plugins[$key][] = $row['selected_value'];
    }
    $_SESSION['_setting'] = $_setting;
    $_SESSION['_plugins'] = $_plugins;
}
Example #5
0
 /**
  * Gets the tools of a certain category. Returns an array expected
  * by show_tools_category()
  * @param string $course_tool_category	contains the category of tools to
  * display: "toolauthoring", "toolinteraction", "tooladmin", "tooladminplatform", "toolplugin"
  * @return array
  */
 public static function get_tools_category($course_tool_category)
 {
     $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST);
     $is_platform_admin = api_is_platform_admin();
     $all_tools_list = array();
     // Condition for the session
     $session_id = api_get_session_id();
     $course_id = api_get_course_int_id();
     $condition_session = api_get_session_condition($session_id, true, true, 't.session_id');
     switch ($course_tool_category) {
         case TOOL_STUDENT_VIEW:
             $conditions = ' WHERE visibility = 1 AND (category = "authoring" OR category = "interaction" OR category = "plugin") ';
             if ((api_is_coach() || api_is_course_tutor()) && $_SESSION['studentview'] != 'studentview') {
                 $conditions = ' WHERE (visibility = 1 AND (category = "authoring" OR category = "interaction" OR category = "plugin") OR (name = "' . TOOL_TRACKING . '") )   ';
             }
             $sql = "SELECT *\n                        FROM {$course_tool_table} t\n                        {$conditions} AND\n                        c_id = {$course_id} {$condition_session}\n                        ORDER BY id";
             $result = Database::query($sql);
             break;
         case TOOL_AUTHORING:
             $sql = "SELECT * FROM {$course_tool_table} t\n                        WHERE category = 'authoring' AND c_id = {$course_id} {$condition_session}\n                        ORDER BY id";
             $result = Database::query($sql);
             break;
         case TOOL_INTERACTION:
             $sql = "SELECT * FROM {$course_tool_table} t\n                        WHERE category = 'interaction' AND c_id = {$course_id} {$condition_session}\n                        ORDER BY id";
             $result = Database::query($sql);
             break;
         case TOOL_ADMIN_VISIBLE:
             $sql = "SELECT * FROM {$course_tool_table} t\n                        WHERE category = 'admin' AND visibility ='1' AND c_id = {$course_id} {$condition_session}\n                        ORDER BY id";
             $result = Database::query($sql);
             break;
         case TOOL_ADMIN_PLATFORM:
             $sql = "SELECT * FROM {$course_tool_table} t\n                        WHERE category = 'admin' AND c_id = {$course_id} {$condition_session}\n                        ORDER BY id";
             $result = Database::query($sql);
             break;
         case TOOL_DRH:
             $sql = "SELECT * FROM {$course_tool_table} t\n                        WHERE name IN ('tracking') AND c_id = {$course_id} {$condition_session}\n                        ORDER BY id";
             $result = Database::query($sql);
             break;
         case TOOL_COURSE_PLUGIN:
             //Other queries recover id, name, link, image, visibility, admin, address, added_tool, target, category and session_id
             // but plugins are not present in the tool table, only globally and inside the course_settings table once configured
             $sql = "SELECT * FROM {$course_tool_table} t\n                        WHERE category = 'plugin' AND c_id = {$course_id} {$condition_session}\n                        ORDER BY id";
             $result = Database::query($sql);
             break;
     }
     //Get the list of hidden tools - this might imply performance slowdowns
     // if the course homepage is loaded many times, so the list of hidden
     // tools might benefit from a shared memory storage later on
     $list = api_get_settings('Tools', 'list', api_get_current_access_url_id());
     $hide_list = array();
     $check = false;
     foreach ($list as $line) {
         // Admin can see all tools even if the course_hide_tools configuration is set
         if ($is_platform_admin) {
             continue;
         }
         if ($line['variable'] == 'course_hide_tools' and $line['selected_value'] == 'true') {
             $hide_list[] = $line['subkey'];
             $check = true;
         }
     }
     while ($temp_row = Database::fetch_assoc($result)) {
         $add = false;
         if ($check) {
             if (!in_array($temp_row['name'], $hide_list)) {
                 $add = true;
             }
         } else {
             $add = true;
         }
         if ($temp_row['image'] == 'scormbuilder.gif') {
             $lp_id = self::get_published_lp_id_from_link($temp_row['link']);
             $lp = new learnpath(api_get_course_id(), $lp_id, api_get_user_id());
             $path = $lp->get_preview_image_path(ICON_SIZE_BIG);
             $add = $lp->is_lp_visible_for_student($lp_id, api_get_user_id(), api_get_course_id(), api_get_session_id());
             if ($path) {
                 $temp_row['custom_image'] = $path;
             }
         }
         if ($add) {
             $all_tools_list[] = $temp_row;
         }
     }
     // Grabbing all the links that have the property on_homepage set to 1
     $course_link_table = Database::get_course_table(TABLE_LINK);
     $course_item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
     $condition_session = api_get_session_condition($session_id, true, true, 'tip.session_id');
     switch ($course_tool_category) {
         case TOOL_AUTHORING:
             $sql_links = "SELECT tl.*, tip.visibility\n                    FROM {$course_link_table} tl\n                    LEFT JOIN {$course_item_property_table} tip\n                    ON tip.tool='link' AND tip.ref=tl.id\n                    WHERE\n                        tl.c_id = {$course_id} AND\n                        tip.c_id = {$course_id} AND\n                        tl.on_homepage='1' {$condition_session}";
             break;
         case TOOL_INTERACTION:
             $sql_links = null;
             /*
              $sql_links = "SELECT tl.*, tip.visibility
              FROM $course_link_table tl
              LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tip.ref=tl.id
              WHERE tl.on_homepage='1' ";
             */
             break;
         case TOOL_STUDENT_VIEW:
             $sql_links = "SELECT tl.*, tip.visibility\n                    FROM {$course_link_table} tl\n                    LEFT JOIN {$course_item_property_table} tip\n                    ON tip.tool='link' AND tip.ref=tl.id\n                    WHERE\n                        tl.c_id \t\t= {$course_id} AND\n                        tip.c_id \t\t= {$course_id} AND\n                        tl.on_homepage\t='1' {$condition_session}";
             break;
         case TOOL_ADMIN:
             $sql_links = "SELECT tl.*, tip.visibility\n                    FROM {$course_link_table} tl\n                    LEFT JOIN {$course_item_property_table} tip\n                    ON tip.tool='link' AND tip.ref=tl.id\n                    WHERE\n                        tl.c_id = {$course_id} AND\n                        tip.c_id = {$course_id} AND\n                        tl.on_homepage='1' {$condition_session}";
             break;
         default:
             $sql_links = null;
             break;
     }
     // Edited by Kevin Van Den Haute (kevin@develop-it.be) for integrating Smartblogs
     if ($sql_links != null) {
         $result_links = Database::query($sql_links);
         if (Database::num_rows($result_links) > 0) {
             while ($links_row = Database::fetch_array($result_links, 'ASSOC')) {
                 $properties = array();
                 $properties['name'] = $links_row['title'];
                 $properties['session_id'] = $links_row['session_id'];
                 $properties['link'] = $links_row['url'];
                 $properties['visibility'] = $links_row['visibility'];
                 $properties['image'] = $links_row['visibility'] == '0' ? 'file_html.png' : 'file_html.png';
                 $properties['adminlink'] = api_get_path(WEB_CODE_PATH) . 'link/link.php?action=editlink&id=' . $links_row['id'];
                 $properties['target'] = $links_row['target'];
                 $tmp_all_tools_list[] = $properties;
             }
         }
     }
     if (isset($tmp_all_tools_list)) {
         foreach ($tmp_all_tools_list as $tool) {
             if ($tool['image'] == 'blog.gif') {
                 // Init
                 $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
                 // Get blog id
                 $blog_id = substr($tool['link'], strrpos($tool['link'], '=') + 1, strlen($tool['link']));
                 // Get blog members
                 if ($is_platform_admin) {
                     $sql_blogs = "SELECT * FROM {$tbl_blogs_rel_user} blogs_rel_user\n                                      WHERE blog_id =" . $blog_id;
                 } else {
                     $sql_blogs = "SELECT * FROM {$tbl_blogs_rel_user} blogs_rel_user\n                                      WHERE blog_id =" . $blog_id . " AND user_id = " . api_get_user_id();
                 }
                 $result_blogs = Database::query($sql_blogs);
                 if (Database::num_rows($result_blogs) > 0) {
                     $all_tools_list[] = $tool;
                 }
             } else {
                 $all_tools_list[] = $tool;
             }
         }
     }
     return $all_tools_list;
 }
Example #6
0
/**
 * This function allows the platform admin to choose the default stylesheet
 * @author Patrick Cool <*****@*****.**>, Ghent University
 * @author Julio Montoya <*****@*****.**>, Chamilo
 */
function handle_stylesheets()
{
    global $_configuration;
    // Current style.
    $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;
        }
    } else {
        $is_style_changeable = true;
    }
    $form = new FormValidator('stylesheet_upload', 'post', 'settings.php?category=Stylesheets#tabs-2');
    $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', 'ico', 'psd');
    $form->addRule('new_stylesheet', get_lang('InvalidExtension') . ' (' . implode(',', $allowed_file_types) . ')', 'filetype', $allowed_file_types);
    $form->addRule('new_stylesheet', get_lang('ThisFieldIsRequired'), 'required');
    $form->addButtonUpload(get_lang('Upload'), 'stylesheet_upload');
    $show_upload_form = false;
    if (!is_writable(CSS_UPLOAD_PATH)) {
        Display::display_error_message(CSS_UPLOAD_PATH . get_lang('IsNotWritable'));
    } else {
        // Uploading a new stylesheet.
        if ($_configuration['access_url'] == 1) {
            $show_upload_form = true;
        } else {
            if ($is_style_changeable) {
                $show_upload_form = true;
            }
        }
    }
    // Stylesheet upload.
    if (isset($_POST['stylesheet_upload'])) {
        if ($form->validate()) {
            $values = $form->exportValues();
            $picture_element = $form->getElement('new_stylesheet');
            $picture = $picture_element->getValue();
            $result = upload_stylesheet($values, $picture);
            // Add event to the system log.
            $user_id = api_get_user_id();
            $category = $_GET['category'];
            Event::addEvent(LOG_CONFIGURATION_SETTINGS_CHANGE, LOG_CONFIGURATION_SETTINGS_CATEGORY, $category, api_get_utc_datetime(), $user_id);
            if ($result) {
                Display::display_confirmation_message(get_lang('StylesheetAdded'));
            }
        }
    }
    $form_change = new FormValidator('stylesheet_upload', 'post', api_get_self() . '?category=Stylesheets', null, array('id' => 'stylesheets_id'));
    $list_of_names = array();
    $selected = '';
    $dirpath = '';
    $safe_style_dir = '';
    if ($handle = @opendir(CSS_UPLOAD_PATH)) {
        $counter = 1;
        while (false !== ($style_dir = readdir($handle))) {
            if (substr($style_dir, 0, 1) == '.') {
                // Skip directories starting with a '.'
                continue;
            }
            $dirpath = CSS_UPLOAD_PATH . $style_dir;
            if (is_dir($dirpath)) {
                if ($style_dir != '.' && $style_dir != '..') {
                    if (isset($_POST['style']) && (isset($_POST['preview']) || isset($_POST['download'])) && $_POST['style'] == $style_dir) {
                        $safe_style_dir = $style_dir;
                    } else {
                        if ($currentstyle == $style_dir || $style_dir == 'chamilo' && !$currentstyle) {
                            if (isset($_POST['style'])) {
                                $selected = Database::escape_string($_POST['style']);
                            } else {
                                $selected = $style_dir;
                            }
                        }
                    }
                    $show_name = ucwords(str_replace('_', ' ', $style_dir));
                    if ($is_style_changeable) {
                        $list_of_names[$style_dir] = $show_name;
                    }
                    $counter++;
                }
            }
        }
        closedir($handle);
    }
    // Sort styles in alphabetical order.
    asort($list_of_names);
    $select_list = array();
    foreach ($list_of_names as $style_dir => $item) {
        $select_list[$style_dir] = $item;
    }
    $styles =& $form_change->addElement('select', 'style', get_lang('NameStylesheet'), $select_list);
    $styles->setSelected($selected);
    if ($form_change->validate()) {
        // Submit stylesheets.
        if (isset($_POST['save'])) {
            store_stylesheets();
            Display::display_normal_message(get_lang('Saved'));
        }
        if (isset($_POST['download'])) {
            $arch = api_get_path(SYS_ARCHIVE_PATH) . $safe_style_dir . '.zip';
            $dir = api_get_path(SYS_CSS_PATH) . 'themes/' . $safe_style_dir;
            if (is_dir($dir)) {
                $zip = new PclZip($arch);
                // Remove path prefix except the style name and put file on disk
                $zip->create($dir, PCLZIP_OPT_REMOVE_PATH, substr($dir, 0, -strlen($safe_style_dir)));
                //@TODO: use more generic script to download.
                $str = '<a class="btn btn-primary btn-large" href="' . api_get_path(WEB_CODE_PATH) . 'course_info/download.php?archive=' . str_replace(api_get_path(SYS_ARCHIVE_PATH), '', $arch) . '">' . get_lang('ClickHereToDownloadTheFile') . '</a>';
                Display::display_normal_message($str, false);
            } else {
                Display::addFlash(Display::return_message(get_lang('FileNotFound'), 'warning'));
            }
        }
    }
    if ($is_style_changeable) {
        $group = [$form_change->addButtonSave(get_lang('SaveSettings'), 'save', true), $form_change->addButtonPreview(get_lang('Preview'), 'preview', true), $form_change->addButtonDownload(get_lang('Download'), 'download', true)];
        $form_change->addGroup($group);
        if ($show_upload_form) {
            echo '<script>
            $(function() {
                $( "#tabs" ).tabs();
            });
            </script>';
            echo Display::tabs(array(get_lang('Update'), get_lang('UploadNewStylesheet')), array($form_change->return_form(), $form->return_form()));
        } else {
            $form_change->display();
        }
    } else {
        $form_change->freeze();
    }
}
Example #7
0
 /**
  * Returns an HTML form (generated by FormValidator) of the plugin settings
  * @return string FormValidator-generated form
  */
 public function get_settings_form()
 {
     $result = new FormValidator($this->get_name());
     $defaults = array();
     $checkboxGroup = array();
     $checkboxCollection = array();
     if ($checkboxNames = array_keys($this->fields, 'checkbox')) {
         $pluginInfoCollection = api_get_settings('Plugins');
         foreach ($pluginInfoCollection as $pluginInfo) {
             if (array_search($pluginInfo['title'], $checkboxNames) !== false) {
                 $checkboxCollection[$pluginInfo['title']] = $pluginInfo;
             }
         }
     }
     foreach ($this->fields as $name => $type) {
         $options = null;
         if (is_array($type) && isset($type['type']) && $type['type'] === "select") {
             $options = $type['options'];
             $type = $type['type'];
         }
         $value = $this->get($name);
         $defaults[$name] = $value;
         $type = isset($type) ? $type : 'text';
         $help = null;
         if ($this->get_lang_plugin_exists($name . '_help')) {
             $help = $this->get_lang($name . '_help');
             if ($name === "show_main_menu_tab") {
                 $pluginName = strtolower(str_replace('Plugin', '', get_class($this)));
                 $pluginUrl = api_get_path(WEB_PATH) . "plugin/{$pluginName}/index.php";
                 $pluginUrl = "<a href={$pluginUrl}>{$pluginUrl}</a>";
                 $help = sprintf($help, $pluginUrl);
             }
         }
         switch ($type) {
             case 'html':
                 $result->addElement('html', $this->get_lang($name));
                 break;
             case 'wysiwyg':
                 $result->addHtmlEditor($name, $this->get_lang($name), false);
                 break;
             case 'text':
                 $result->addElement($type, $name, array($this->get_lang($name), $help));
                 break;
             case 'boolean':
                 $group = array();
                 $group[] = $result->createElement('radio', $name, '', get_lang('Yes'), 'true');
                 $group[] = $result->createElement('radio', $name, '', get_lang('No'), 'false');
                 $result->addGroup($group, null, array($this->get_lang($name), $help));
                 break;
             case 'checkbox':
                 $selectedValue = null;
                 if (isset($checkboxCollection[$name])) {
                     if ($checkboxCollection[$name]['selected_value'] === 'true') {
                         $selectedValue = 'checked';
                     }
                 }
                 $element = $result->createElement($type, $name, '', $this->get_lang($name), $selectedValue);
                 $element->_attributes['value'] = 'true';
                 $checkboxGroup[] = $element;
                 break;
             case 'select':
                 $result->addElement($type, $name, array($this->get_lang($name), $help), $options);
                 break;
         }
     }
     if (!empty($checkboxGroup)) {
         $result->addGroup($checkboxGroup, null, array($this->get_lang('sms_types'), $help));
     }
     $result->setDefaults($defaults);
     $result->addButtonSave($this->get_lang('Save'), 'submit_button');
     return $result;
 }
Example #8
0
        } else {
            if ($row['subkey'] == null) {
                $_setting[$row['variable']] = $row['selected_value'];
            } else {
                $_setting[$row['variable']][$row['subkey']] = $row['selected_value'];
            }
        }
    } else {
        if ($row['subkey'] == null) {
            $_setting[$row['variable']] = $row['selected_value'];
        } else {
            $_setting[$row['variable']][$row['subkey']] = $row['selected_value'];
        }
    }
}
$result =& api_get_settings('Plugins', 'list', $_configuration['access_url']);
$_plugins = array();
foreach ($result as &$row) {
    $key =& $row['variable'];
    if (is_string($_setting[$key])) {
        $_setting[$key] = array();
    }
    $_setting[$key][] = $row['selected_value'];
    $_plugins[$key][] = $row['selected_value'];
}
// Error reporting settings.
if (api_get_setting('server_type') == 'test') {
    ini_set('display_errors', '1');
    ini_set('log_errors', '1');
    error_reporting(-1);
} else {
/**
 * Search options
 * TODO: support for multiple site. aka $_configuration['access_url'] == 1
 * @author Marco Villegas <*****@*****.**>
 */
function handle_search()
{
    global $SettingsStored, $_configuration;
    $search_enabled = api_get_setting('search_enabled');
    $settings = api_get_settings('Search');
    if ($search_enabled !== 'true' || count($settings) < 1) {
        Display::display_error_message(get_lang('SearchFeatureNotEnabledComment'));
        return;
    }
    require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php';
    $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");
    //search_show_unlinked_results
    $form->addElement('header', null, get_lang('SearchShowUnlinkedResultsTitle'));
    $form->addElement('label', null, get_lang('SearchShowUnlinkedResultsComment'));
    $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');
    //search_prefilter_prefix
    $form->addElement('header', null, get_lang('SearchPrefilterPrefix'));
    $form->addElement('label', null, get_lang('SearchPrefilterPrefixComment'));
    $specific_fields = get_specific_field_list();
    $sf_values = array();
    foreach ($specific_fields as $sf) {
        $sf_values[$sf['code']] = $sf['name'];
    }
    $group = array();
    $form->addElement('select', 'search_prefilter_prefix', get_lang('SearchPrefilterPrefix'), $sf_values, '');
    $default_values['search_prefilter_prefix'] = api_get_setting('search_prefilter_prefix');
    //$form->addRule('search_show_unlinked_results', get_lang('ThisFieldIsRequired'), 'required');
    $form->addElement('style_submit_button', 'search-options-save', get_lang('Ok'));
    $form->setDefaults($default_values);
    if ($form->validate()) {
        $formvalues = $form->exportValues();
        $r = api_set_settings_category('Search', 'false', $_configuration['access_url']);
        // Save the settings
        foreach ($formvalues as $key => $value) {
            $result = api_set_setting($key, $value, null, null);
        }
        Display::display_normal_message($SettingsStored);
    } else {
        echo '<div id="search-options-form">';
        $form->display();
        echo '</div>';
    }
}
Example #10
0
 /**
  * Retrieves transaction mapping settings.
  *
  * @return array
  *   Every item is an array of mapping settings, keyed by transaction
  *   action, with the following keys:
  *   - max_attempts: Maximum number of attempts for trying to import the
  *     transaction into the system.
  */
 public static function getTransactionMappingSettings($action = null, $reset = false)
 {
     static $settings;
     if (isset($settings) && !$reset) {
         if (!empty($action)) {
             return $settings[$action];
         }
         return $settings;
     }
     $settings = array();
     $transaction_mapping_settings = api_get_settings('TransactionMapping');
     foreach ($transaction_mapping_settings as $setting) {
         $maps = unserialize($setting['selected_value']);
         $settings[$setting['subkey']] = $maps;
     }
     if (!empty($action)) {
         return $settings[$action];
     }
     return $settings;
 }