1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066 |
- <?php
- class Link extends Model
- {
- public $table;
- public $is_course_model = true;
- public $columns = array('id', 'c_id','url','title','description','category_id', 'display_order', 'on_homepage', 'target', 'session_id');
- public $required = array('url', 'title');
- public function __construct()
- {
- $this->table = Database::get_course_table(TABLE_LINK);
- }
- public function save($params, $show_query = null)
- {
- $course_info = api_get_course_info();
- $params['session_id'] = api_get_session_id();
- $params['category_id'] = isset($params['category_id']) ? $params['category_id'] : 0;
- $id = parent::save($params, $show_query);
- if (!empty($id)) {
- api_item_property_update($course_info, TOOL_LINK, $id, 'LinkAdded', api_get_user_id());
- }
- return $id;
- }
- }
- function addlinkcategory($type)
- {
- global $catlinkstatus;
- global $msgErr;
- $ok = true;
- $course_id = api_get_course_int_id();
- $courseInfo = api_get_course_info();
- if ($type == 'link') {
- $tbl_link = Database :: get_course_table(TABLE_LINK);
- $title = Security :: remove_XSS(stripslashes($_POST['title']));
- $urllink = Security :: remove_XSS($_POST['urllink']);
- $description = Security :: remove_XSS($_POST['description']);
- $selectcategory = Security :: remove_XSS($_POST['selectcategory']);
- if ($_POST['onhomepage'] == '') {
- $onhomepage = 0;
- } else {
- $onhomepage = Security :: remove_XSS($_POST['onhomepage']);
- }
- if (empty($_POST['target_link'])) {
- $target = '_self';
- } else {
- $target = Security :: remove_XSS($_POST['target_link']);
- }
- $urllink = trim($urllink);
- $title = trim($title);
- $description = trim($description);
-
- if (strpos($urllink, '://') === false) {
- $urllink = 'http://' . $urllink;
- }
-
- if ($title == '') {
- $title = $urllink;
- }
-
-
-
- if (!api_valid_url($urllink, true)) {
- $msgErr = get_lang('GiveURL');
- Display :: display_error_message(get_lang('GiveURL'));
- $ok = false;
- } else {
-
- $result = Database :: query("SELECT MAX(display_order) FROM " . $tbl_link . " WHERE c_id = $course_id AND category_id = '" . intval($_POST['selectcategory']) . "'");
- list ($orderMax) = Database :: fetch_row($result);
- $order = $orderMax +1;
- $session_id = api_get_session_id();
- $sql = "INSERT INTO " . $tbl_link . " (c_id, url, title, description, category_id, display_order, on_homepage, target, session_id)
- VALUES (".$course_id.", '".Database :: escape_string($urllink) . "','" . Database :: escape_string($title) . "','" . Database :: escape_string($description) . "','" .
- Database :: escape_string($selectcategory) . "','" . Database :: escape_string($order) . "', '" . Database :: escape_string($onhomepage) . "','" .
- Database :: escape_string($target) . "','" . Database :: escape_string($session_id) . "')";
- $catlinkstatus = get_lang('LinkAdded');
- Database :: query($sql);
- $link_id = Database :: insert_id();
- if ($link_id) {
- api_set_default_visibility($courseInfo, $link_id, TOOL_LINK);
- }
- if ((api_get_setting('search_enabled') == 'true') && $link_id && extension_loaded('xapian')) {
- require_once api_get_path(LIBRARY_PATH) . 'search/ChamiloIndexer.class.php';
- require_once api_get_path(LIBRARY_PATH) . 'search/IndexableChunk.class.php';
- require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php';
- $course_int_id = api_get_course_int_id();
- $courseid = api_get_course_id();
- $specific_fields = get_specific_field_list();
- $ic_slide = new IndexableChunk();
-
- $all_specific_terms = '';
- foreach ($specific_fields as $specific_field) {
- if (isset ($_REQUEST[$specific_field['code']])) {
- $sterms = trim($_REQUEST[$specific_field['code']]);
- if (!empty ($sterms)) {
- $all_specific_terms .= ' ' . $sterms;
- $sterms = explode(',', $sterms);
- foreach ($sterms as $sterm) {
- $ic_slide->addTerm(trim($sterm), $specific_field['code']);
- add_specific_field_value($specific_field['id'], $courseid, TOOL_LINK, $link_id, $sterm);
- }
- }
- }
- }
-
- $ic_slide->addValue('title', $title);
- $ic_slide->addCourseId($courseid);
- $ic_slide->addToolId(TOOL_LINK);
- $xapian_data = array (
- SE_COURSE_ID => $courseid,
- SE_TOOL_ID => TOOL_LINK,
- SE_DATA => array (
- 'link_id' => (int) $link_id
- ),
- SE_USER => (int) api_get_user_id(),
- );
- $ic_slide->xapian_data = serialize($xapian_data);
- $description = $all_specific_terms . ' ' . $description;
- $ic_slide->addValue('content', $description);
-
- if (isset ($_POST['selectcategory']) && $selectcategory > 0) {
- $table_link_category = Database :: get_course_table(TABLE_LINK_CATEGORY);
- $sql_cat = 'SELECT * FROM %s WHERE id=%d AND c_id = %d LIMIT 1';
- $sql_cat = sprintf($sql_cat, $table_link_category, (int) $selectcategory, $course_int_id);
- $result = Database :: query($sql_cat);
- if (Database :: num_rows($result) == 1) {
- $row = Database :: fetch_array($result);
- $ic_slide->addValue('category', $row['category_title']);
- }
- }
- $di = new ChamiloIndexer();
- isset ($_POST['language']) ? $lang = Database :: escape_string($_POST['language']) : $lang = 'english';
- $di->connectDb(NULL, NULL, $lang);
- $di->addChunk($ic_slide);
-
- $did = $di->index();
- if ($did) {
-
- $tbl_se_ref = Database :: get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
- $sql = 'INSERT INTO %s (c_id, id, course_code, tool_id, ref_id_high_level, search_did)
- VALUES (NULL , \'%s\', \'%s\', %s, %s)';
- $sql = sprintf($sql, $tbl_se_ref, $course_int_id, $courseid, TOOL_LINK, $link_id, $did);
- Database :: query($sql);
- }
- }
- unset ($urllink, $title, $description, $selectcategory);
- Display :: display_confirmation_message(get_lang('LinkAdded'));
- }
- } elseif ($type == 'category') {
- $tbl_categories = Database :: get_course_table(TABLE_LINK_CATEGORY);
- $category_title = trim($_POST['category_title']);
- $description = trim($_POST['description']);
- if (empty($category_title)) {
- $msgErr = get_lang('GiveCategoryName');
- Display :: display_error_message(get_lang('GiveCategoryName'));
- $ok = false;
- } else {
-
- $result = Database :: query("SELECT MAX(display_order) FROM " . $tbl_categories." WHERE c_id = $course_id ");
- list ($orderMax) = Database :: fetch_row($result);
- $order = $orderMax +1;
- $order = intval($order);
- $session_id = api_get_session_id();
- $sql = "INSERT INTO ".$tbl_categories." (c_id, category_title, description, display_order, session_id)
- VALUES (".$course_id.", '" .Database::escape_string($category_title) . "', '" . Database::escape_string($description) . "', '$order', '$session_id')";
- Database :: query($sql);
- $catlinkstatus = get_lang('CategoryAdded');
- unset ($category_title, $description);
- Display :: display_confirmation_message(get_lang('CategoryAdded'));
- }
- }
-
- if ($type == 'link') {
- global $_user;
- $_course = api_get_course_info();
- global $nameTools;
- api_item_property_update($_course, TOOL_LINK, $link_id, 'LinkAdded', $_user['user_id']);
- }
- return $ok;
- }
- function deletelinkcategory($id, $type)
- {
- global $catlinkstatus;
- $_course = api_get_course_info();
- $course_id = api_get_course_int_id();
- $tbl_link = Database :: get_course_table(TABLE_LINK);
- $tbl_categories = Database :: get_course_table(TABLE_LINK_CATEGORY);
- $id = intval($id);
- if ($type == 'link') {
-
-
- $sql = "UPDATE $tbl_link SET on_homepage='0' WHERE c_id = $course_id AND id='" . $id . "'";
- Database :: query($sql);
- api_item_property_update($_course, TOOL_LINK, $id, 'delete', api_get_user_id());
- delete_link_from_search_engine(api_get_course_id(), $id);
- $catlinkstatus = get_lang('LinkDeleted');
- Display :: display_confirmation_message(get_lang('LinkDeleted'));
- }
- if ($type == 'category') {
-
- $sql = "DELETE FROM " . $tbl_categories . " WHERE c_id = $course_id AND id='" .$id. "'";
- Database :: query($sql);
- $sql = "DELETE FROM " . $tbl_link . " WHERE c_id = $course_id AND category_id='" .$id. "'";
- $catlinkstatus = get_lang('CategoryDeleted');
- Database :: query($sql);
- Display :: display_confirmation_message(get_lang('CategoryDeleted'));
- }
- }
- function delete_link_from_search_engine($course_id, $link_id)
- {
-
- 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 LIMIT 1';
- $sql = sprintf($sql, $tbl_se_ref, $course_id, TOOL_LINK, $link_id);
- $res = Database :: query($sql);
- if (Database :: num_rows($res) > 0) {
- $row = Database :: fetch_array($res);
- require_once api_get_path(LIBRARY_PATH) . 'search/ChamiloIndexer.class.php';
- $di = new ChamiloIndexer();
- $di->remove_document((int) $row['search_did']);
- }
- $sql = 'DELETE FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s LIMIT 1';
- $sql = sprintf($sql, $tbl_se_ref, $course_id, TOOL_LINK, $link_id);
- Database :: query($sql);
-
- require_once (api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php');
- delete_all_values_for_item($course_id, TOOL_DOCUMENT, $link_id);
- }
- }
- function get_link_info($id)
- {
- $tbl_link = Database :: get_course_table(TABLE_LINK);
- $course_id = api_get_course_int_id();
- $sql = "SELECT * FROM " . $tbl_link . " WHERE c_id = $course_id AND id='" . intval($id) . "' ";
- $result = Database::query($sql);
- if (Database::num_rows($result)) {
- $data = Database::fetch_array($result);
- }
- return $data;
- }
- function editlinkcategory($type)
- {
- global $catlinkstatus;
- global $id;
- global $submit_link;
- global $submit_category;
- global $_user;
- $_course = api_get_course_info();
- global $nameTools;
- global $urllink;
- global $title;
- global $description;
- global $category;
- global $selectcategory;
- global $description;
- global $category_title;
- global $onhomepage;
- global $target_link;
- $tbl_link = Database :: get_course_table(TABLE_LINK);
- $tbl_categories = Database :: get_course_table(TABLE_LINK_CATEGORY);
- $course_id = api_get_course_int_id();
- if ($type == 'link') {
-
- if (!empty ($_GET['id'])) {
- $sql = "SELECT * FROM " . $tbl_link . " WHERE c_id = $course_id AND id='" . intval($_GET['id']) . "'";
- $result = Database :: query($sql);
- if ($myrow = Database :: fetch_array($result)) {
- $urllink = $myrow['url'];
- $title = $myrow['title'];
- $description = $myrow['description'];
- $category = $myrow['category_id'];
- if ($myrow['on_homepage'] != 0) {
- $onhomepage = 'checked';
- }
- $target_link = $myrow['target'];
- }
- }
-
- if ($_POST['submitLink']) {
-
- $_POST['urllink'] = trim($_POST['urllink']);
- $_POST['title'] = trim(Security :: remove_XSS($_POST['title']));
- $_POST['description'] = trim(Security :: remove_XSS($_POST['description']));
- $_POST['selectcategory'] = intval($_POST['selectcategory']);
- $_POST['id'] = intval($_POST['id']);
-
- if (strpos($_POST['urllink'], '://') === false) {
- $_POST['urllink'] = 'http://' . $_POST['urllink'];
- }
-
- if ($_POST['title'] == '') {
- $_POST['title'] = $_POST['urllink'];
- }
-
-
-
- if (!api_valid_url($urllink, true)) {
- $msgErr = get_lang('GiveURL');
- Display :: display_error_message(get_lang('GiveURL'));
- return false;
- }
- $onhomepage = Security :: remove_XSS($_POST['onhomepage']);
- $target = Database::escape_string($_POST['target_link']);
- if (empty ($mytarget)) {
- $mytarget = '_self';
- }
- $mytarget = ",target='" . $target . "'";
-
- $sql = "SELECT * FROM " . $tbl_link . " WHERE c_id = $course_id AND id='" . intval($_POST['id']) . "'";
- $result = Database :: query($sql);
- $row = Database :: fetch_array($result);
- $category_id = $row['category_id'];
- if ($category_id != $_POST['selectcategory']) {
- $sql = "SELECT MAX(display_order) FROM " . $tbl_link . " WHERE c_id = $course_id AND category_id='" . intval($_POST['selectcategory']) . "'";
- $result = Database :: query($sql);
- list ($max_display_order) = Database :: fetch_row($result);
- $max_display_order++;
- } else {
- $max_display_order = $row['display_order'];
- }
- $sql = "UPDATE " . $tbl_link . " SET " .
- "url='" . Database :: escape_string($_POST['urllink']) . "', " .
- "title='" . Database :: escape_string($_POST['title']) . "', " .
- "description='" . Database :: escape_string($_POST['description']) . "', " .
- "category_id='" . Database :: escape_string($_POST['selectcategory']) . "', " .
- "display_order='" . $max_display_order . "', " .
- "on_homepage='" . Database :: escape_string($onhomepage) . " ' $mytarget " .
- " WHERE c_id = $course_id AND id='" . intval($_POST['id']) . "'";
- Database :: query($sql);
-
- if (api_get_setting('search_enabled') == 'true') {
- $link_id = intval($_POST['id']);
- $course_int_id = api_get_course_int_id();
- $course_id = api_get_course_id();
- $link_url = Database :: escape_string($_POST['urllink']);
- $link_title = Database :: escape_string($_POST['title']);
- $link_description = Database :: escape_string($_POST['description']);
-
-
- $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 LIMIT 1';
- $sql = sprintf($sql, $tbl_se_ref, $course_id, TOOL_LINK, $link_id);
- $res = Database :: query($sql);
- if (Database :: num_rows($res) > 0) {
- require_once api_get_path(LIBRARY_PATH) . 'search/ChamiloIndexer.class.php';
- require_once api_get_path(LIBRARY_PATH) . 'search/IndexableChunk.class.php';
- require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php';
- $se_ref = Database :: fetch_array($res);
- $specific_fields = get_specific_field_list();
- $ic_slide = new IndexableChunk();
- $all_specific_terms = '';
- foreach ($specific_fields as $specific_field) {
- delete_all_specific_field_value($course_id, $specific_field['id'], TOOL_LINK, $link_id);
- if (isset ($_REQUEST[$specific_field['code']])) {
- $sterms = trim($_REQUEST[$specific_field['code']]);
- if (!empty ($sterms)) {
- $all_specific_terms .= ' ' . $sterms;
- $sterms = explode(',', $sterms);
- foreach ($sterms as $sterm) {
- $ic_slide->addTerm(trim($sterm), $specific_field['code']);
- add_specific_field_value($specific_field['id'], $course_id, TOOL_LINK, $link_id, $sterm);
- }
- }
- }
- }
-
- $ic_slide->addValue("title", $link_title);
- $ic_slide->addCourseId($course_id);
- $ic_slide->addToolId(TOOL_LINK);
- $xapian_data = array (
- SE_COURSE_ID => $course_id,
- SE_TOOL_ID => TOOL_LINK,
- SE_DATA => array (
- 'link_id' => (int) $link_id
- ),
- SE_USER => (int) api_get_user_id(),
- );
- $ic_slide->xapian_data = serialize($xapian_data);
- $link_description = $all_specific_terms . ' ' . $link_description;
- $ic_slide->addValue('content', $link_description);
-
- if (isset ($_POST['selectcategory']) && $selectcategory > 0) {
- $table_link_category = Database :: get_course_table(TABLE_LINK_CATEGORY);
- $sql_cat = 'SELECT * FROM %s WHERE id=%d and c_id = %d LIMIT 1';
- $sql_cat = sprintf($sql_cat, $table_link_category, (int) $selectcategory, $course_int_id);
- $result = Database :: query($sql_cat);
- if (Database :: num_rows($result) == 1) {
- $row = Database :: fetch_array($result);
- $ic_slide->addValue('category', $row['category_title']);
- }
- }
- $di = new ChamiloIndexer();
- isset ($_POST['language']) ? $lang = Database :: escape_string($_POST['language']) : $lang = 'english';
- $di->connectDb(NULL, NULL, $lang);
- $di->remove_document((int) $se_ref['search_did']);
- $di->addChunk($ic_slide);
-
- $did = $di->index();
- if ($did) {
-
- $sql = 'DELETE FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=\'%s\'';
- $sql = sprintf($sql, $tbl_se_ref, $course_id, TOOL_LINK, $link_id);
- Database :: query($sql);
- $sql = 'INSERT INTO %s (c_id, id, course_code, tool_id, ref_id_high_level, search_did)
- VALUES (NULL , \'%s\', \'%s\', %s, %s)';
- $sql = sprintf($sql, $tbl_se_ref, $course_int_id, $course_id, TOOL_LINK, $link_id, $did);
- Database :: query($sql);
- }
- }
- }
-
- api_item_property_update($_course, TOOL_LINK, $_POST['id'], 'LinkUpdated', $_user['user_id']);
- Display :: display_confirmation_message(get_lang('LinkModded'));
- }
- }
- if ($type == 'category') {
-
- if (!$submit_category) {
- $sql = "SELECT * FROM " . $tbl_categories . " WHERE c_id = $course_id AND id='" . intval($_GET['id']) . "'";
- $result = Database :: query($sql);
- if ($myrow = Database :: fetch_array($result)) {
- $category_title = $myrow['category_title'];
- $description = $myrow['description'];
- }
- }
-
- if ($submit_category) {
- $sql = "UPDATE " . $tbl_categories . "
- SET category_title='" . Database :: escape_string($_POST['category_title']) . "', description='" . Database :: escape_string($_POST['description']) . "'
- WHERE c_id = $course_id AND id='" . Database :: escape_string($_POST['id']) . "'";
- Database :: query($sql);
- Display :: display_confirmation_message(get_lang('CategoryModded'));
- }
- }
- return true;
- }
- function makedefaultviewcode($locatie) {
- global $aantalcategories, $view;
- for ($j = 0; $j <= $aantalcategories -1; $j++) {
- $view[$j] = 0;
- }
- $view[intval($locatie)] = '1';
- }
- function change_visibility($id, $scope) {
- global $_user;
- $_course = api_get_course_info();
- if ($scope == 'link') {
- api_item_property_update($_course, TOOL_LINK, $id, $_GET['action'], $_user['user_id']);
- Display :: display_confirmation_message(get_lang('VisibilityChanged'));
- }
- }
- function showlinksofcategory($catid) {
- global $is_allowed, $charset, $urlview, $up, $down, $_user, $token;
- $tbl_link = Database :: get_course_table(TABLE_LINK);
- $TABLE_ITEM_PROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY);
-
- $session_id = api_get_session_id();
- $condition_session = api_get_session_condition($session_id, true, true);
- $catid = intval($catid);
- $course_id = api_get_course_int_id();
- $sqlLinks = "SELECT *, link.id FROM " . $tbl_link . " link, " . $TABLE_ITEM_PROPERTY . " itemproperties
- WHERE itemproperties.tool='" . TOOL_LINK . "' AND
- link.id=itemproperties.ref AND
- link.category_id='" . $catid . "' AND
- (itemproperties.visibility='0' OR itemproperties.visibility='1')
- $condition_session AND
- link.c_id = ".$course_id." AND
- itemproperties.c_id = ".$course_id."
- ORDER BY link.display_order DESC";
- $result = Database :: query($sqlLinks);
- $numberoflinks = Database :: num_rows($result);
- if ($numberoflinks > 0) {
- echo '<table class="data_table" width="100%">';
- $i = 1;
- while ($myrow = Database :: fetch_array($result)) {
-
- $session_img = api_get_session_image($myrow['session_id'], $_user['status']);
- $css_class = $i % 2 == 0 ? $css_class = 'row_odd' : $css_class = 'row_even';
- $link_validator = '';
- if (api_is_allowed_to_edit(null, true)) {
- $link_validator = ''.Display::url(Display::return_icon('preview_view.png', get_lang('CheckURL'), array(), 16), '#', array('onclick'=>"check_url('".$myrow['id']."', '".addslashes($myrow['url'])."');"));
- $link_validator .= Display::span('', array('id'=>'url_id_'.$myrow['id']));
- }
- $icon = Display::return_icon('link.gif', get_lang('Link'));
- if ($myrow['visibility'] == '1') {
- echo '<tr class="'.$css_class.'">';
- echo '<td align="center" valign="middle" width="15">';
- echo '<a href="link_goto.php?'.api_get_cidreq().'&link_id='.$myrow['id'].'&link_url='.urlencode($myrow['url']).'" target="_blank">
- '.$icon.'
- </a></td>
- <td width="80%" valign="top"><a href="link_goto.php?'.api_get_cidreq().'&link_id='.$myrow['id'].'&link_url='.urlencode($myrow['url']).'" target="'.$myrow['target'].'">';
- echo Security :: remove_XSS($myrow['title']);
- echo '</a>';
- echo $link_validator;
- echo $session_img;
- echo '<br />'.$myrow['description'];
- } else {
- if (api_is_allowed_to_edit(null, true)) {
- echo '<tr class="'.$css_class.'">';
- echo '<td align="center" valign="middle" width="15"><a href="link_goto.php?'.api_get_cidreq().'&link_id='.$myrow['id']."&link_url=".urlencode($myrow['url']).'" target="_blank" class="invisible">';
- echo Display :: return_icon('link_na.gif', get_lang('Link')), '</a>';
- echo '</td><td width="80%" valign="top"><a href="link_goto.php?', api_get_cidreq(), '&link_id=', $myrow['id'], '&link_url=', urlencode($myrow['url']),'" target="', $myrow['target'], '" class="invisible">';
- echo Security :: remove_XSS($myrow['url']);
- echo "</a>";
- echo $link_validator;
- echo $session_img, '<br />', $myrow['title'];
- }
- }
- echo '<td style="text-align:center;">';
- if (api_is_allowed_to_edit(null, true)) {
- if ($session_id == $myrow['session_id']) {
- echo '<a href="' . api_get_self() . '?' . api_get_cidreq() . '&sec_token='.$token.'&action=editlink&category=' . (!empty ($category) ? $category : '') . '&id=' . $myrow['id'] . '&urlview=' . $urlview . '" title="' . get_lang('Modify') . '">' .
- Display :: return_icon('edit.png', get_lang('Modify'), array (), ICON_SIZE_SMALL) . '</a>';
-
-
- if ($myrow['visibility'] == '1') {
- echo '<a href="link.php?' . api_get_cidreq() . '&sec_token='.$token.'&action=invisible&id=' . $myrow['id'] . '&scope=link&urlview=' . $urlview . '" title="' . get_lang('Hide') . '">' .
- Display :: return_icon('visible.png', get_lang('Hide'), array (), ICON_SIZE_SMALL) . '</a>';
- }
- if ($myrow['visibility'] == '0') {
- echo ' <a href="link.php?' . api_get_cidreq() . '&sec_token='.$token.'&action=visible&id=' . $myrow['id'] . '&scope=link&urlview=' . $urlview . '" title="' . get_lang('Show') . '">' .
- Display :: return_icon('invisible.png', get_lang('Show'), array (), ICON_SIZE_SMALL) . '</a>';
- }
- echo ' <a href="' . api_get_self() . '?' . api_get_cidreq() . '&sec_token='.$token.'&action=deletelink&id=', $myrow['id'], '&urlview=', $urlview, "\" onclick=\"javascript: if(!confirm('" . get_lang('LinkDelconfirm') . "')) return false;\" title=\"" . get_lang('Delete') . '">' .
- Display :: return_icon('delete.png', get_lang('Delete'), array (), ICON_SIZE_SMALL) . '</a>';
- } else {
- echo Display :: return_icon('edit_na.png', get_lang('EditionNotAvailableFromSession'), array (), ICON_SIZE_SMALL);
- }
- }
- echo '</td></tr>';
- $i++;
- }
- echo '</table>';
- }
- }
- function showcategoryadmintools($categoryid) {
- global $urlview, $aantalcategories, $catcounter, $token;
- echo '<a href="' . api_get_self() . '?' . api_get_cidreq() . '&sec_token='.$token.'&action=editcategory&id=' . $categoryid . '&urlview=' . $urlview . '" title=' . get_lang('Modify') . '">' . Display :: return_icon('edit.png', get_lang('Modify'), array (), ICON_SIZE_SMALL) . '</a>';
-
- if ($catcounter != 1) {
- echo '<a href="' . api_get_self() . '?' . api_get_cidreq() . '&sec_token='.$token.'&catmove=true&up=', $categoryid, '&urlview=' . $urlview . '" title="' . get_lang('Up') . '">' . Display :: return_icon('up.png', get_lang('Up'), array (), ICON_SIZE_SMALL) . '</a>';
- } else {
- echo Display :: return_icon('up_na.png', get_lang('Up'), array (), ICON_SIZE_SMALL) . '</a>';
- }
-
- if ($catcounter < $aantalcategories) {
- echo '<a href="' . api_get_self() . '?' . api_get_cidreq() .'&sec_token='.$token.'&catmove=true&down=' . $categoryid . '&urlview=' . $urlview . '">
- ' . Display :: return_icon('down.png', get_lang('Down'), array (), ICON_SIZE_SMALL) . '</a>';
- } else {
- echo Display :: return_icon('down_na.png', get_lang('Down'), array (), ICON_SIZE_SMALL) . '</a>';
- }
- echo '<a href="' . api_get_self() . '?' . api_get_cidreq() . '&sec_token='.$token.'&action=deletecategory&id=', $categoryid, "&urlview=$urlview\" onclick=\"javascript: if(!confirm('" . get_lang('CategoryDelconfirm') . "')) return false;\">", Display :: return_icon('delete.png', get_lang('Delete'), array (), ICON_SIZE_SMALL) . '</a>';
- $catcounter++;
- }
- function movecatlink($catlinkid) {
- global $catmove;
- global $up;
- global $down;
- $tbl_link = Database :: get_course_table(TABLE_LINK);
- $tbl_categories = Database :: get_course_table(TABLE_LINK_CATEGORY);
- $course_id = api_get_course_int_id();
- if (!empty ($down)) {
- $thiscatlinkId = intval($down);
- $sortDirection = 'DESC';
- }
- if (!empty ($up)) {
- $thiscatlinkId = intval($up);
- $sortDirection = 'ASC';
- }
-
- if ($catmove == 'true') {
- $movetable = $tbl_categories;
- $catid = $catlinkid;
- } else {
- $movetable = $tbl_link;
-
- if (!empty ($thiscatlinkId)) {
- $sql = "SELECT category_id FROM " . $movetable . " WHERE c_id = $course_id AND id='$thiscatlinkId'";
- $result = Database :: query($sql);
- $catid = Database :: fetch_array($result);
- }
- }
-
- if (!empty($sortDirection)) {
- if (!in_array(trim(strtoupper($sortDirection)), array ('ASC', 'DESC'))){
- $sortDirection = 'ASC';
- }
- if ($catmove == 'true') {
- $sqlcatlinks = "SELECT id, display_order FROM " . $movetable . " WHERE c_id = $course_id ORDER BY display_order $sortDirection";
- } else {
- $sqlcatlinks = "SELECT id, display_order FROM " . $movetable . "
- WHERE c_id = $course_id AND category_id='" . $catid[0] . "'
- ORDER BY display_order $sortDirection";
- }
- $linkresult = Database :: query($sqlcatlinks);
- while ($sortrow = Database :: fetch_array($linkresult)) {
-
-
-
- if (isset ($thislinkFound) && $thislinkFound) {
- $nextlinkId = $sortrow['id'];
- $nextlinkOrdre = $sortrow['display_order'];
- Database :: query("UPDATE " . $movetable . "
- SET display_order = '$nextlinkOrdre'
- WHERE c_id = $course_id AND id = '$thiscatlinkId'");
- Database :: query("UPDATE " . $movetable . "
- SET display_order = '$thislinkOrdre'
- WHERE c_id = $course_id AND id = '$nextlinkId'");
- break;
- }
- if ($sortrow['id'] == $thiscatlinkId) {
- $thislinkOrdre = $sortrow['display_order'];
- $thislinkFound = true;
- }
- }
- }
- Display :: display_confirmation_message(get_lang('LinkMoved'));
- }
- function get_cat($catname) {
-
- $tbl_categories = Database :: get_course_table(TABLE_LINK_CATEGORY);
- $course_id = api_get_course_int_id();
- $result = Database :: query("SELECT id FROM " . $tbl_categories . " WHERE c_id = $course_id AND category_title='" . Database::escape_string($catname) . "'");
- if (Database :: num_rows($result) >= 1 && ($row = Database :: fetch_array($result))) {
- return $row['id'];
- }
- $result = Database :: query("SELECT MAX(display_order) FROM " . $tbl_categories." WHERE c_id = $course_id ");
- list ($max_order) = Database :: fetch_row($result);
- Database :: query("INSERT INTO " . $tbl_categories . " (c_id, category_title, description, display_order)
- VALUES (".$course_id.", '" . Database::escape_string($catname) . "','','" . ($max_order +1) . "')");
- return Database :: insert_id();
- }
- function put_link($url, $cat, $title, $description, $on_homepage, $hidden) {
- $tbl_link = Database :: get_course_table(TABLE_LINK);
- $course_id = api_get_course_int_id();
- $urleq = "url='" . Database :: escape_string($url) . "'";
- $cateq = "category_id=" . intval($cat);
- $result = Database :: query("SELECT id FROM $tbl_link WHERE c_id = $course_id AND " . $urleq . ' AND ' . $cateq);
- if (Database :: num_rows($result) >= 1 && ($row = Database :: fetch_array($result))) {
- Database :: query("UPDATE $tbl_link set title='" . Database :: escape_string($title) . "', description='" . Database :: escape_string($description) . "'
- WHERE c_id = $course_id AND id='" . Database :: escape_string($row['id']) . "'");
- $ipu = 'LinkUpdated';
- $rv = 1;
- } else {
-
- $result = Database :: query("SELECT MAX(display_order) FROM $tbl_link WHERE c_id = $course_id AND category_id='" . intval($cat) . "'");
- list ($max_order) = Database :: fetch_row($result);
- Database :: query("INSERT INTO $tbl_link (c_id, url, title, description, category_id, display_order, on_homepage)
- VALUES (".api_get_course_int_id().", '" . Database :: escape_string($url) . "','" . Database :: escape_string($title) . "','" . Database :: escape_string($description) . "','" . intval($cat) . "','" . (intval($max_order) + 1) . "','" . intval($on_homepage) . "')");
- $id = Database :: insert_id();
- $ipu = 'LinkAdded';
- $rv = 2;
- }
- global $nameTools, $_user;
- $_course = api_get_course_info();
- api_item_property_update($_course, TOOL_LINK, $id, $ipu, $_user['user_id']);
- if ($hidden && $ipu == 'LinkAdded') {
- api_item_property_update($_course, TOOL_LINK, $id, 'invisible', $_user['user_id']);
- }
- return $rv;
- }
- function import_link($linkdata) {
-
-
- $known_fields = array (
- 'url',
- 'category',
- 'title',
- 'description',
- 'on_homepage',
- 'hidden'
- );
- $hide_fields = array (
- 'kw',
- 'kwd',
- 'kwds',
- 'keyword',
- 'keywords'
- );
-
-
- if (!($url = trim($linkdata['url'])) || !($title = trim($linkdata['title']))) {
- return 0;
- }
- $cat = ($catname = trim($linkdata['category'])) ? get_cat($catname) : 0;
- $regs = array ();
- foreach ($linkdata as $key => $value)
- if (!in_array($key, $known_fields))
- if (in_array($key, $hide_fields) && ereg('^<?([^>]*)>?$', $value, $regs))
- if (($kwlist = trim($regs[1])) != '')
- $kw = '<i kw="' . htmlspecialchars($kwlist) . '">';
- else
- $kw = '';
-
-
- elseif (trim($value)) {
- $d .= ', ' . $key . ':' . $value;
- }
- if ($d) {
- $d = substr($d, 2) . ' - ';
- }
- return put_link($url, $cat, $title, $kw . ereg_replace('\[((/?(b|big|i|small|sub|sup|u))|br/)\]', '<\\1>', htmlspecialchars($d . $linkdata['description'])) . ($kw ? '</i>' : ''), $linkdata['on_homepage'] ? '1' : '0', $linkdata['hidden'] ? '1' : '0');
-
- }
- function import_csvfile()
- {
- global $catlinkstatus;
- if (is_uploaded_file($filespec = $_FILES['import_file']['tmp_name']) && filesize($filespec) && ($myFile = @ fopen($filespec, 'r'))) {
-
- $listsep = strpos($colnames = trim(fgets($myFile)), ',') !== false ? ',' : (strpos($colnames, ';') !== false ? ';' : '');
- if ($listsep) {
- $columns = array_map('strtolower', explode($listsep, $colnames));
- if (in_array('url', $columns) && in_array('title', $columns)) {
- $stats = array (
- 0,
- 0,
- 0
- );
-
-
- while (($data = Text::api_fgetcsv($myFile, null, $listsep))) {
-
- foreach ($data as $i => & $text) {
- $linkdata[$columns[$i]] = $text;
- }
- $stats[import_link($linkdata)]++;
- unset ($linkdata);
- }
- $catlinkstatus = '';
- if ($stats[0]) {
- $catlinkstatus .= $stats[0] . ' ' . get_lang('CsvLinesFailed');
- }
- if ($stats[1]) {
- $catlinkstatus .= $stats[1] . ' ' . get_lang('CsvLinesOld');
- }
- if ($stats[2]) {
- $catlinkstatus .= $stats[2] . ' ' . get_lang('CsvLinesNew');
- }
- } else {
- $catlinkstatus = get_lang('CsvFileNoURL') . ($colnames ? get_lang('CsvFileLine1') . htmlspecialchars(substr($colnames, 0, 200)) . '...' : '');
- }
- } else {
- $catlinkstatus = get_lang('CsvFileNoSeps') . ($colnames ? get_lang('CsvFileLine1') . htmlspecialchars(substr($colnames, 0, 200)) . '...' : '');
- }
- fclose($myFile);
- } else {
- $catlinkstatus = get_lang('CsvFileNotFound');
- }
- }
- function isVimeoLink($url)
- {
- $isLink = strrpos($url, "vimeo.com");
- return $isLink;
- }
- function getVimeoLinkId($url)
- {
- $possibleUrls = array(
- 'http://www.vimeo.com/',
- 'http://vimeo.com/',
- 'https://www.vimeo.com/',
- 'https://vimeo.com/'
- );
- $url = str_replace($possibleUrls, '', $url);
- if (is_numeric($url)) {
- return $url;
- }
- return false;
- }
- function is_youtube_link($url)
- {
- $is_youtube_link = strrpos($url, "youtube") || strrpos($url, "youtu.be");
- return $is_youtube_link;
- }
- function get_youtube_video_id($url)
- {
-
- $len = 11;
-
-
- $pos = strpos($url, "v=");
- $id = '';
-
- if ($pos === false) {
- $url_parsed = parse_url($url);
-
-
- $pos = strpos($url, "youtu.be");
- if ($pos == false) {
- $id = '';
- } else {
- return substr($url_parsed['path'], 1);
- }
-
- if (empty($id)) {
- $pos = strpos($url, "embed");
- if ($pos === false) {
- return '';
- } else {
- return substr($url_parsed['path'], 7);
- }
- }
- } else {
-
- $pos += 2;
-
- $id = substr($url, $pos, $len);
- return $id;
- }
- }
|