diff --git a/main/admin/index.php b/main/admin/index.php index 80f88d38dd..97f54eed7e 100644 --- a/main/admin/index.php +++ b/main/admin/index.php @@ -1,4 +1,4 @@ -
  • + +
  • + diff --git a/main/admin/specific_fields.php b/main/admin/specific_fields.php new file mode 100644 index 0000000000..f8393c822f --- /dev/null +++ b/main/admin/specific_fields.php @@ -0,0 +1,93 @@ + 'index.php', "name" => get_lang('PlatformAdmin')); +$interbreadcrumb[] = array ("url" => 'specific_fields.php', "name" => get_lang('SpecificSearchFields')); + +$libpath = api_get_path(LIBRARY_PATH); +include_once ($libpath.'specific_fields_manager.lib.php'); +require_once ($libpath.'formvalidator/FormValidator.class.php'); + +// Create an add-field box +$form = new FormValidator('add_field','post','','',null,false); +$renderer =& $form->defaultRenderer(); +$renderer->setElementTemplate('{element} '); +$form->addElement('static','search_advanced_link',null,''.Display::return_icon('fieldadd.gif').get_lang('AddSpecificSearchField').''); + + + +// Create a sortable table with specific fields data +$column_show = array(1,1,1,1); +$column_order = array(3,2,1,4); +$extra_fields = get_specific_field_list(); +$number_of_extra_fields = count($extra_fields); + +$table = new SortableTableFromArrayConfig($extra_fields,2,50,'',$column_show,$column_order); +$table->set_header(0, '', false,null,'width="2%"', 'style="display:none"'); +$table->set_header(1, get_lang('Code'), TRUE, 'width="10%"'); +$table->set_header(2, get_lang('Name')); +$table->set_header(3, get_lang('Modify'),true,'width="10%"'); +$table->set_column_filter(3, 'edit_filter'); + +function edit_filter($id,$url_params,$row) +{ + global $charset; + $return = ''.Display::return_icon('edit.gif',get_lang('Edit')).''; + $return .= ' '.Display::return_icon('delete.gif',get_lang('Delete')).''; + return $return; +} + +if ($_REQUEST['action'] == 'delete') { + delete_specific_field($_REQUEST['field_id']); + header('Location: specific_fields.php?message='.get_lang('FieldRemoved')); +} + +// Start output + +// Displaying the header +Display::display_header($nameTools); +echo '
    '.get_lang('SpecificSearchFieldsIntro').'
    '; + +if(!empty($_GET['message'])) +{ + Display::display_confirmation_message($_GET['message']); +} + +echo '
    '; +$form->display(); +echo '
    '; + +$table->display(); + +// Displaying the footer +Display::display_footer(); diff --git a/main/admin/specific_fields_add.php b/main/admin/specific_fields_add.php new file mode 100644 index 0000000000..dd3f39072d --- /dev/null +++ b/main/admin/specific_fields_add.php @@ -0,0 +1,101 @@ + 'index.php', 'name' => get_lang('PlatformAdmin')); +$interbreadcrumb[] = array ('url' => 'specific_fields.php', 'name' => get_lang('SpecificSearchFields')); +if ($_GET['action']<>'edit') +{ + $tool_name = get_lang('AddSpecificSearchField'); +} +else +{ + $tool_name = get_lang('EditSpecificSearchField'); +} +// Create the form +$form = new FormValidator('specific_fields_add'); +// Field variable name +$form->addElement('hidden','field_id',(int)$_REQUEST['field_id']); +$form->addElement('text','field_name',get_lang('FieldName')); +$form->applyFilter('field_name','html_filter'); +$form->applyFilter('field_name','trim'); +$form->addRule('field_name', get_lang('ThisFieldIsRequired'), 'required'); +$form->addRule('fieldname', get_lang('OnlyLettersAndNumbersAllowed'), 'username'); +$form->addRule('fieldname', '', 'maxlength',20); + +// Set default values (only not empty when editing) +$defaults = array(); +if (is_numeric($_REQUEST['field_id'])) +{ + $form_information = get_specific_field_list(array( 'id' => (int)$_GET['field_id'] )); + $defaults['field_name'] = $form_information[0]['name']; +} +$form->setDefaults($defaults); +// Submit button +$form->addElement('submit', 'submit', get_lang('Add')); + +// Validate form +if ($form->validate()) { + $field = $form->exportValues(); + $field_name = $field['field_name']; + if (is_numeric($field['field_id']) && $field['field_id']<>0 && !empty($field['field_id'])) + { + edit_specific_field($field['field_id'],$field['field_name']); + $message = get_lang('FieldEdited'); + } + else + { + $field_id = add_specific_field($field_name); + $message = get_lang('FieldAdded'); + } + header('Location: specific_fields.php?message='.$message); + //exit (); +} + +// Display form +Display::display_header($tool_name); + +$form->display(); + +Display::display_footer(); \ No newline at end of file diff --git a/main/img/ButtonGallOff.png b/main/img/ButtonGallOff.png new file mode 100644 index 0000000000..1f82404c5a Binary files /dev/null and b/main/img/ButtonGallOff.png differ diff --git a/main/img/ButtonGallOn.png b/main/img/ButtonGallOn.png new file mode 100644 index 0000000000..8788594558 Binary files /dev/null and b/main/img/ButtonGallOn.png differ diff --git a/main/img/ButtonListOff.png b/main/img/ButtonListOff.png new file mode 100644 index 0000000000..64a8b760ee Binary files /dev/null and b/main/img/ButtonListOff.png differ diff --git a/main/img/ButtonListOn.png b/main/img/ButtonListOn.png new file mode 100644 index 0000000000..139c7acd4d Binary files /dev/null and b/main/img/ButtonListOn.png differ diff --git a/main/img/search-big-plus.gif b/main/img/search-big-plus.gif new file mode 100644 index 0000000000..8465cc2602 Binary files /dev/null and b/main/img/search-big-plus.gif differ diff --git a/main/img/search-lense.gif b/main/img/search-lense.gif new file mode 100644 index 0000000000..f54b9604f4 Binary files /dev/null and b/main/img/search-lense.gif differ diff --git a/main/img/thesaurus.gif b/main/img/thesaurus.gif new file mode 100644 index 0000000000..08524ac386 Binary files /dev/null and b/main/img/thesaurus.gif differ diff --git a/main/inc/lib/add_course.lib.inc.php b/main/inc/lib/add_course.lib.inc.php index b77a7a3d97..a0646bc0d3 100644 --- a/main/inc/lib/add_course.lib.inc.php +++ b/main/inc/lib/add_course.lib.inc.php @@ -1980,6 +1980,10 @@ function fill_Db_course($courseDbName, $courseRepository, $language,$default_doc } } + if (api_get_setting('search_enabled')=='true') { + api_sql_query("INSERT INTO `" . $tbl_course_homepage . "` VALUES (NULL, '" . TOOL_SEARCH. "','search/','info.gif','".string2binary(api_get_setting('course_create_active_tools', 'enable_search')) . "','0','search.gif','NO','_self','authoring')", __FILE__, __LINE__); + } + // Smartblogs (Kevin Van Den Haute :: kevin@develop-it.be) $sql = "INSERT INTO `" . $tbl_course_homepage . "` VALUES (NULL,'" . TOOL_BLOGS . "','blog/blog_admin.php','blog_admin.gif','" . string2binary(api_get_setting('course_create_active_tools', 'blogs')) . "','1','squaregrey.gif','NO','_self','admin')"; api_sql_query($sql, __FILE__, __LINE__); diff --git a/main/inc/lib/database.lib.php b/main/inc/lib/database.lib.php index 0601a89c27..0f0cc05e1a 100644 --- a/main/inc/lib/database.lib.php +++ b/main/inc/lib/database.lib.php @@ -1,4 +1,4 @@ - 1 && !select.visible() ) { + onChange(0, true); + } + }).bind("search", function() { + // TODO why not just specifying both arguments? + var fn = (arguments.length > 1) ? arguments[1] : null; + function findValueCallback(q, data) { + var result; + if( data && data.length ) { + for (var i=0; i < data.length; i++) { + if( data[i].result.toLowerCase() == q.toLowerCase() ) { + result = data[i]; + break; + } + } + } + if( typeof fn == "function" ) fn(result); + else $input.trigger("result", result && [result.data, result.value]); + } + $.each(trimWords($input.val()), function(i, value) { + request(value, findValueCallback, findValueCallback); + }); + }).bind("flushCache", function() { + cache.flush(); + }).bind("setOptions", function() { + $.extend(options, arguments[1]); + // if we've updated the data, repopulate + if ( "data" in arguments[1] ) + cache.populate(); + }).bind("unautocomplete", function() { + select.unbind(); + $input.unbind(); + $(input.form).unbind(".autocomplete"); + }); + + + function selectCurrent() { + var selected = select.selected(); + if( !selected ) + return false; + + var v = selected.result; + previousValue = v; + + if ( options.multiple ) { + var words = trimWords($input.val()); + if ( words.length > 1 ) { + v = words.slice(0, words.length - 1).join( options.multipleSeparator ) + options.multipleSeparator + v; + } + v += options.multipleSeparator; + } + + $input.val(v); + hideResultsNow(); + $input.trigger("result", [selected.data, selected.value]); + return true; + } + + function onChange(crap, skipPrevCheck) { + if( lastKeyPressCode == KEY.DEL ) { + select.hide(); + return; + } + + var currentValue = $input.val(); + + if ( !skipPrevCheck && currentValue == previousValue ) + return; + + previousValue = currentValue; + + currentValue = lastWord(currentValue); + if ( currentValue.length >= options.minChars) { + $input.addClass(options.loadingClass); + if (!options.matchCase) + currentValue = currentValue.toLowerCase(); + request(currentValue, receiveData, hideResultsNow); + } else { + stopLoading(); + select.hide(); + } + }; + + function trimWords(value) { + if ( !value ) { + return [""]; + } + var words = value.split( options.multipleSeparator ); + var result = []; + $.each(words, function(i, value) { + if ( $.trim(value) ) + result[i] = $.trim(value); + }); + return result; + } + + function lastWord(value) { + if ( !options.multiple ) + return value; + var words = trimWords(value); + return words[words.length - 1]; + } + + // fills in the input box w/the first match (assumed to be the best match) + // q: the term entered + // sValue: the first matching result + function autoFill(q, sValue){ + // autofill in the complete box w/the first match as long as the user hasn't entered in more data + // if the last user key pressed was backspace, don't autofill + if( options.autoFill && (lastWord($input.val()).toLowerCase() == q.toLowerCase()) && lastKeyPressCode != KEY.BACKSPACE ) { + // fill in the value (keep the case the user has typed) + $input.val($input.val() + sValue.substring(lastWord(previousValue).length)); + // select the portion of the value not typed by the user (so the next character will erase) + $.Autocompleter.Selection(input, previousValue.length, previousValue.length + sValue.length); + } + }; + + function hideResults() { + clearTimeout(timeout); + timeout = setTimeout(hideResultsNow, 200); + }; + + function hideResultsNow() { + var wasVisible = select.visible(); + select.hide(); + clearTimeout(timeout); + stopLoading(); + if (options.mustMatch) { + // call search and run callback + $input.search( + function (result){ + // if no value found, clear the input box + if( !result ) { + if (options.multiple) { + var words = trimWords($input.val()).slice(0, -1); + $input.val( words.join(options.multipleSeparator) + (words.length ? options.multipleSeparator : "") ); + } + else + $input.val( "" ); + } + } + ); + } + if (wasVisible) + // position cursor at end of input field + $.Autocompleter.Selection(input, input.value.length, input.value.length); + }; + + function receiveData(q, data) { + if ( data && data.length && hasFocus ) { + stopLoading(); + select.display(data, q); + autoFill(q, data[0].value); + select.show(); + } else { + hideResultsNow(); + } + }; + + function request(term, success, failure) { + if (!options.matchCase) + term = term.toLowerCase(); + var data = cache.load(term); + // recieve the cached data + if (data && data.length) { + success(term, data); + // if an AJAX url has been supplied, try loading the data now + } else if( (typeof options.url == "string") && (options.url.length > 0) ){ + + var extraParams = { + timestamp: +new Date() + }; + $.each(options.extraParams, function(key, param) { + extraParams[key] = typeof param == "function" ? param() : param; + }); + + $.ajax({ + // try to leverage ajaxQueue plugin to abort previous requests + mode: "abort", + // limit abortion to this input + port: "autocomplete" + input.name, + dataType: options.dataType, + url: options.url, + data: $.extend({ + q: lastWord(term), + limit: options.max + }, extraParams), + success: function(data) { + var parsed = options.parse && options.parse(data) || parse(data); + cache.add(term, parsed); + success(term, parsed); + } + }); + } else { + // if we have a failure, we need to empty the list -- this prevents the the [TAB] key from selecting the last successful match + select.emptyList(); + failure(term); + } + }; + + function parse(data) { + var parsed = []; + var rows = data.split("\n"); + for (var i=0; i < rows.length; i++) { + var row = $.trim(rows[i]); + if (row) { + row = row.split("|"); + parsed[parsed.length] = { + data: row, + value: row[0], + result: options.formatResult && options.formatResult(row, row[0]) || row[0] + }; + } + } + return parsed; + }; + + function stopLoading() { + $input.removeClass(options.loadingClass); + }; + +}; + +$.Autocompleter.defaults = { + inputClass: "ac_input", + resultsClass: "ac_results", + loadingClass: "ac_loading", + minChars: 1, + delay: 400, + matchCase: false, + matchSubset: true, + matchContains: false, + cacheLength: 10, + max: 100, + mustMatch: false, + extraParams: {}, + selectFirst: true, + formatItem: function(row) { return row[0]; }, + formatMatch: null, + autoFill: false, + width: 0, + multiple: false, + multipleSeparator: ", ", + highlight: function(value, term) { + return value.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + term.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1") + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "$1"); + }, + scroll: true, + scrollHeight: 180 +}; + +$.Autocompleter.Cache = function(options) { + + var data = {}; + var length = 0; + + function matchSubset(s, sub) { + if (!options.matchCase) + s = s.toLowerCase(); + var i = s.indexOf(sub); + if (i == -1) return false; + return i == 0 || options.matchContains; + }; + + function add(q, value) { + if (length > options.cacheLength){ + flush(); + } + if (!data[q]){ + length++; + } + data[q] = value; + } + + function populate(){ + if( !options.data ) return false; + // track the matches + var stMatchSets = {}, + nullData = 0; + + // no url was specified, we need to adjust the cache length to make sure it fits the local data store + if( !options.url ) options.cacheLength = 1; + + // track all options for minChars = 0 + stMatchSets[""] = []; + + // loop through the array and create a lookup structure + for ( var i = 0, ol = options.data.length; i < ol; i++ ) { + var rawValue = options.data[i]; + // if rawValue is a string, make an array otherwise just reference the array + rawValue = (typeof rawValue == "string") ? [rawValue] : rawValue; + + var value = options.formatMatch(rawValue, i+1, options.data.length); + if ( value === false ) + continue; + + var firstChar = value.charAt(0).toLowerCase(); + // if no lookup array for this character exists, look it up now + if( !stMatchSets[firstChar] ) + stMatchSets[firstChar] = []; + + // if the match is a string + var row = { + value: value, + data: rawValue, + result: options.formatResult && options.formatResult(rawValue) || value + }; + + // push the current match into the set list + stMatchSets[firstChar].push(row); + + // keep track of minChars zero items + if ( nullData++ < options.max ) { + stMatchSets[""].push(row); + } + }; + + // add the data items to the cache + $.each(stMatchSets, function(i, value) { + // increase the cache size + options.cacheLength++; + // add to the cache + add(i, value); + }); + } + + // populate any existing data + setTimeout(populate, 25); + + function flush(){ + data = {}; + length = 0; + } + + return { + flush: flush, + add: add, + populate: populate, + load: function(q) { + if (!options.cacheLength || !length) + return null; + /* + * if dealing w/local data and matchContains than we must make sure + * to loop through all the data collections looking for matches + */ + if( !options.url && options.matchContains ){ + // track all matches + var csub = []; + // loop through all the data grids for matches + for( var k in data ){ + // don't search through the stMatchSets[""] (minChars: 0) cache + // this prevents duplicates + if( k.length > 0 ){ + var c = data[k]; + $.each(c, function(i, x) { + // if we've got a match, add it to the array + if (matchSubset(x.value, q)) { + csub.push(x); + } + }); + } + } + return csub; + } else + // if the exact item exists, use it + if (data[q]){ + return data[q]; + } else + if (options.matchSubset) { + for (var i = q.length - 1; i >= options.minChars; i--) { + var c = data[q.substr(0, i)]; + if (c) { + var csub = []; + $.each(c, function(i, x) { + if (matchSubset(x.value, q)) { + csub[csub.length] = x; + } + }); + return csub; + } + } + } + return null; + } + }; +}; + +$.Autocompleter.Select = function (options, input, select, config) { + var CLASSES = { + ACTIVE: "ac_over" + }; + + var listItems, + active = -1, + data, + term = "", + needsInit = true, + element, + list; + + // Create results + function init() { + if (!needsInit) + return; + element = $("
    ") + .hide() + .addClass(options.resultsClass) + .css("position", "absolute") + .appendTo(document.body); + + list = $("