diff --git a/main/newscorm/learnpath.class.php b/main/newscorm/learnpath.class.php index 654b18a249..32c4e4e396 100644 --- a/main/newscorm/learnpath.class.php +++ b/main/newscorm/learnpath.class.php @@ -857,10 +857,10 @@ class learnpath { $link[0]->delete(); } //TODO: also delete items and item-views - if (api_get_setting('search_enabled') == 'true') { - require_once(api_get_path(LIBRARY_PATH) .'specific_fields_manager.lib.php'); - $r = delete_all_values_for_item($this->cc, TOOL_LEARNPATH, $this->lp_id); - } + if (api_get_setting('search_enabled') == 'true') { + require_once(api_get_path(LIBRARY_PATH) .'specific_fields_manager.lib.php'); + $r = delete_all_values_for_item($this->cc, TOOL_LEARNPATH, $this->lp_id); + } } /** @@ -924,19 +924,19 @@ class learnpath { $res_all = api_sql_query($sql_all,__FILE__,__LINE__); // remove from search engine if enabled if (api_get_setting('search_enabled') == 'true') { - $tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF); - $sql = 'SELECT * FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s AND ref_id_second_level=%d LIMIT 1'; - $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id); - $res = api_sql_query($sql, __FILE__, __LINE__); - if (Database::num_rows($res) > 0) { - $row2 = Database::fetch_array($res); + $tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF); + $sql = 'SELECT * FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s AND ref_id_second_level=%d LIMIT 1'; + $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id); + $res = api_sql_query($sql, __FILE__, __LINE__); + if (Database::num_rows($res) > 0) { + $row2 = Database::fetch_array($res); require_once(api_get_path(LIBRARY_PATH) .'search/DokeosIndexer.class.php'); $di = new DokeosIndexer(); - $di->remove_document((int)$row2['search_did']); - } - $sql = 'DELETE FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s AND ref_id_second_level=%d LIMIT 1'; - $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id); - api_sql_query($sql, __FILE__, __LINE__); + $di->remove_document((int)$row2['search_did']); + } + $sql = 'DELETE FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s AND ref_id_second_level=%d LIMIT 1'; + $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp, $id); + api_sql_query($sql, __FILE__, __LINE__); } } @@ -949,10 +949,10 @@ class learnpath { * @param string Item description * @param string Prerequisites (optional) * @param string Indexing terms (optional) - * @param array The array resulting of the $_FILES[mp3] element + * @param array The array resulting of the $_FILES[mp3] element * @return boolean True on success, false on error */ - function edit_item($id, $parent, $previous, $title, $description, $prerequisites=0, $audio=NULL, $max_time_allowed=0) { + function edit_item($id, $parent, $previous, $title, $description, $prerequisites=0, $audio=NULL, $max_time_allowed=0) { if($this->debug > 0){error_log('New LP - In learnpath::edit_item()', 0);} if(empty($max_time_allowed)) { $max_time_allowed = 0;} @@ -967,17 +967,17 @@ class learnpath { $res_select = api_sql_query($sql_select, __FILE__, __LINE__); $row_select = Database::fetch_array($res_select); - $audio_update_sql = ''; - if (is_array($audio) && !empty($audio['tmp_name']) && $audio['error']===0) { - //upload file in documents - $pi = pathinfo($audio['name']); - if ($pi['extension'] == 'mp3') { - $c_det = api_get_course_info($this->cc); - $bp = api_get_path(SYS_COURSE_PATH).$c_det['path'].'/document'; - $path = handle_uploaded_document($c_det,$audio,$bp,'/audio',api_get_user_id(),0,null,'',0,'rename',false,0); - $path = substr($path,7); - //update reference in lp_item - audio path is the path from inside de document/audio/ dir - $audio_update_sql = ", audio = '".Database::escape_string($path)."' "; + $audio_update_sql = ''; + if (is_array($audio) && !empty($audio['tmp_name']) && $audio['error']===0) { + //upload file in documents + $pi = pathinfo($audio['name']); + if ($pi['extension'] == 'mp3') { + $c_det = api_get_course_info($this->cc); + $bp = api_get_path(SYS_COURSE_PATH).$c_det['path'].'/document'; + $path = handle_uploaded_document($c_det,$audio,$bp,'/audio',api_get_user_id(),0,null,'',0,'rename',false,0); + $path = substr($path,7); + //update reference in lp_item - audio path is the path from inside de document/audio/ dir + $audio_update_sql = ", audio = '".Database::escape_string($path)."' "; } } @@ -994,7 +994,7 @@ class learnpath { prerequisite = '".$prerequisites."', description = '" . $this->escape_string(htmlentities($description)) . "' ". $audio_update_sql . ", - max_time_allowed = '" . $this->escape_string(htmlentities($max_time_allowed)) . "' + max_time_allowed = '" . $this->escape_string(htmlentities($max_time_allowed)) . "' WHERE id = " . $id; $res_update = api_sql_query($sql_update, __FILE__, __LINE__); } @@ -1112,7 +1112,7 @@ class learnpath { previous_item_id = " . $previous . ", next_item_id = " . $new_next . ", display_order = " . $new_order . " - ". $audio_update_sql . " + ". $audio_update_sql . " WHERE id = " . $id; $res_update_next = api_sql_query($sql_update, __FILE__, __LINE__); //echo '

' . $sql_update . '

'; @@ -1402,19 +1402,19 @@ class learnpath { } /** - * Get the specific prefix index terms of this learning path - * @return array Array of terms + * Get the specific prefix index terms of this learning path + * @return array Array of terms */ - function get_common_index_terms_by_prefix($prefix) + function get_common_index_terms_by_prefix($prefix) { - require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php'; - $terms = get_specific_field_values_list_by_prefix($prefix, $this->cc, TOOL_LEARNPATH, $this->lp_id); - $prefix_terms = array(); + require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php'; + $terms = get_specific_field_values_list_by_prefix($prefix, $this->cc, TOOL_LEARNPATH, $this->lp_id); + $prefix_terms = array(); foreach($terms as $term) { - $prefix_terms[] = $term['value']; + $prefix_terms[] = $term['value']; } - return $prefix_terms; + return $prefix_terms; } /** @@ -3054,20 +3054,20 @@ class learnpath { } } /** - * Checks if any of the items has an audio element attached - * @return bool True or false - */ - function has_audio() { - $has = false; - foreach ($this->items as $i=>$item) { - if (!empty($this->items[$i]->audio)) { - $has = true; - break; - } - } - return $has; - } - /** + * Checks if any of the items has an audio element attached + * @return bool True or false + */ + function has_audio() { + $has = false; + foreach ($this->items as $i=>$item) { + if (!empty($this->items[$i]->audio)) { + $has = true; + break; + } + } + return $has; + } + /** * Logs a message into a file * @param string Message to log * @return boolean True on success, false on error or if msg empty @@ -3708,80 +3708,80 @@ class learnpath { return true; } - + /** - * Set index specified prefix terms for all items in this path + * Set index specified prefix terms for all items in this path * @param string Comma-separated list of terms - * @param char Xapian term prefix + * @param char Xapian term prefix * @return boolean False on error, true otherwise */ - function set_terms_by_prefix($terms_string, $prefix) { - if (api_get_setting('search_enabled') !== 'true') - return FALSE; - - $terms_string = trim($terms_string); - $terms = explode(',', $terms_string); - array_walk($terms, 'trim_value'); - - $stored_terms = $this->get_common_index_terms_by_prefix($prefix); - //var_dump($stored_terms); - //var_dump($terms); - - // don't do anything if no change, verify only at DB, not the search engine - if ( (count(array_diff($terms, $stored_terms))==0) && (count(array_diff($stored_terms, $terms))==0) ) - return FALSE; - - require_once('xapian.php'); //TODO try catch every xapian use or make wrappers on api - require_once(api_get_path(LIBRARY_PATH).'search/DokeosIndexer.class.php'); - require_once(api_get_path(LIBRARY_PATH).'search/xapian/XapianQuery.php'); - require_once(api_get_path(LIBRARY_PATH).'search/IndexableChunk.class.php'); - - $items_table = Database::get_course_table('lp_item'); - //TODO: make query secure agains XSS : use member attr instead of post var - $lp_id = $_POST['lp_id']; - $sql = "SELECT * FROM $items_table WHERE lp_id = $lp_id"; - $result = api_sql_query($sql); - $di = new DokeosIndexer(); + function set_terms_by_prefix($terms_string, $prefix) { + if (api_get_setting('search_enabled') !== 'true') + return FALSE; + + $terms_string = trim($terms_string); + $terms = explode(',', $terms_string); + array_walk($terms, 'trim_value'); + + $stored_terms = $this->get_common_index_terms_by_prefix($prefix); + //var_dump($stored_terms); + //var_dump($terms); + + // don't do anything if no change, verify only at DB, not the search engine + if ( (count(array_diff($terms, $stored_terms))==0) && (count(array_diff($stored_terms, $terms))==0) ) + return FALSE; + + require_once('xapian.php'); //TODO try catch every xapian use or make wrappers on api + require_once(api_get_path(LIBRARY_PATH).'search/DokeosIndexer.class.php'); + require_once(api_get_path(LIBRARY_PATH).'search/xapian/XapianQuery.php'); + require_once(api_get_path(LIBRARY_PATH).'search/IndexableChunk.class.php'); + + $items_table = Database::get_course_table('lp_item'); + //TODO: make query secure agains XSS : use member attr instead of post var + $lp_id = $_POST['lp_id']; + $sql = "SELECT * FROM $items_table WHERE lp_id = $lp_id"; + $result = api_sql_query($sql); + $di = new DokeosIndexer(); - while($lp_item = Database::fetch_array($result)) - { - // get search_did - $tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF); - $sql = 'SELECT * FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s AND ref_id_second_level=%d LIMIT 1'; - $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp_id, $lp_item['id']); - $res = api_sql_query($sql, __FILE__, __LINE__); - $se_ref = Database::fetch_array($res); - - // compare terms - $doc = $di->get_document($se_ref['search_did']); - $xapian_terms = xapian_get_doc_terms($doc, $prefix); - //var_dump($xapian_terms); - $xterms = array(); - foreach ($xapian_terms as $xapian_term) $xterms[] = substr($xapian_term['name'],1); - - $dterms = $terms; - //var_dump($xterms); - //var_dump($dterms); - - $missing_terms = array_diff($dterms, $xterms); - $deprecated_terms = array_diff($xterms, $dterms); - - // save it to search engine - foreach ($missing_terms as $term) - { - $doc->add_term($prefix. $term, 1); - } - foreach ($deprecated_terms as $term) - { - $doc->remove_term($prefix.$term); - } - $di->getDb()->replace_document((int)$se_ref['search_did'], $doc); - $di->getDb()->flush(); + while($lp_item = Database::fetch_array($result)) + { + // get search_did + $tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF); + $sql = 'SELECT * FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s AND ref_id_second_level=%d LIMIT 1'; + $sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp_id, $lp_item['id']); + $res = api_sql_query($sql, __FILE__, __LINE__); + $se_ref = Database::fetch_array($res); + + // compare terms + $doc = $di->get_document($se_ref['search_did']); + $xapian_terms = xapian_get_doc_terms($doc, $prefix); + //var_dump($xapian_terms); + $xterms = array(); + foreach ($xapian_terms as $xapian_term) $xterms[] = substr($xapian_term['name'],1); + + $dterms = $terms; + //var_dump($xterms); + //var_dump($dterms); + + $missing_terms = array_diff($dterms, $xterms); + $deprecated_terms = array_diff($xterms, $dterms); + + // save it to search engine + foreach ($missing_terms as $term) + { + $doc->add_term($prefix. $term, 1); + } + foreach ($deprecated_terms as $term) + { + $doc->remove_term($prefix.$term); } - + $di->getDb()->replace_document((int)$se_ref['search_did'], $doc); + $di->getDb()->flush(); + } + return true; } - + /** * Sets the theme of the LP (local/remote) (and save) * @param string Optional string giving the new theme of this learnpath @@ -6503,14 +6503,14 @@ class learnpath { $form->addElement('file','mp3',get_lang('UploadMp3audio'),'id="mp3" size="33"'); $form->addRule('file', 'The extension of the Song file should be *.mp3', 'filename', '/^.*\.mp3$/'); - /* Code deprecated - moved to lp level (not lp-item) + /* Code deprecated - moved to lp level (not lp-item) if ( api_get_setting('search_enabled') === 'true' ) { //add terms field $terms = $form->addElement('text','terms', get_lang('SearchFeatureTerms').' :','id="idTerms" class="learnpath_item_form"'); $terms->setValue($item_terms); } - */ + */ $arrHide=array(); @@ -7710,7 +7710,7 @@ class learnpath { while ($row_hot = Database::fetch_array($res_hot)) { $return .= '
'; //display quizhotpotatoes - $return .= ''; + $return .= ''; $return .= '' . $row_hot['title'] . ''; //$return .= $row_quiz['title']; $return .= '
'; @@ -8852,13 +8852,13 @@ EOD; } } return false; - } -} - -if (!function_exists('trim_value')) { - function trim_value(&$value) { - $value = trim($value); + } +} + +if (!function_exists('trim_value')) { + function trim_value(&$value) { + $value = trim($value); } } - + ?> \ No newline at end of file diff --git a/main/resourcelinker/resourcelinker.inc.php b/main/resourcelinker/resourcelinker.inc.php index 32b5c427ce..96a4ffe458 100644 --- a/main/resourcelinker/resourcelinker.inc.php +++ b/main/resourcelinker/resourcelinker.inc.php @@ -1,4 +1,4 @@ -".get_lang('StepDeleted1')." $type ".get_lang('StepDeleted2').""; return(true); } if ($icon == 'nolink') { return(shorten($name,$length)); } - if ($icon == 'icon') { echo "hot potatoes"; } + if ($icon == 'icon') { echo "hot potatoes"; } $cid = $_course['official_code']; diff --git a/main/resourcelinker/resourcelinker.php b/main/resourcelinker/resourcelinker.php index 1c86da84d1..53f1255adc 100644 --- a/main/resourcelinker/resourcelinker.php +++ b/main/resourcelinker/resourcelinker.php @@ -902,7 +902,7 @@ if (($content == "Exercise") or ($content == "HotPotatoes")) while ($myrow = mysql_fetch_array($result)) { $path = $myrow["path"]; - echo "".GetQuizName($path, $documentPath)."
"; + echo "".GetQuizName($path, $documentPath)."
"; showorhide_addresourcelink("HotPotatoes", $myrow["id"]); echo "

";