';
$theme = api_get_setting('course.homepage_view');
if ($theme == 'vertical_activity') {
//ordering by get_lang name
$order_tool_list = array();
if (is_array($toolList) && count($toolList)>0) {
foreach ($toolList as $key => $new_tool) {
$tool_name = self::translate_tool_name($new_tool);
$order_tool_list [$key]= $tool_name;
}
natsort($order_tool_list);
$my_temp_tool_array = array();
foreach ($order_tool_list as $key => $new_tool) {
$my_temp_tool_array[] = $toolList[$key];
}
$toolList = $my_temp_tool_array;
} else {
$toolList = array();
}
}
$courseInfo = api_get_course_info();
$web_code_path = api_get_path(WEB_CODE_PATH);
$is_allowed_to_edit = api_is_allowed_to_edit(null, true);
$is_platform_admin = api_is_platform_admin();
$session_id = api_get_session_id();
$items = array();
$app_plugin = new AppPlugin();
if (isset($toolList)) {
foreach ($toolList as & $tool) {
$lnk = [];
$item = array();
$tool['admin'] = isset($tool['admin']) ? $tool['admin'] : null;
//$tool['id'] = isset($tool['id']) ? $tool['id'] : null;
$tool['id'] = isset($tool['iid']) ? $tool['iid'] : null;
$tool['target'] = isset($tool['target']) ? $tool['target'] : null;
if (isset($tool['link_id'])) {
$tool['original_link'] = api_get_path(WEB_CODE_PATH).'link/link_goto.php?link_id='.$tool['link_id'].'&'.api_get_cidreq();
$tool['link'] = $tool['original_link'];
} else {
$tool['original_link'] = $tool['link'];
}
// Re-writing URL for new tools
$newTools = array(TOOL_CURRICULUM);
$toolName = isset($tool['name']) ? $tool['name'] : null;
if (in_array($toolName, $newTools)) {
$tool['link'] = $courseInfo['course_web_public_url'].$tool['name'].'/';
}
if ($tool['image'] == 'scormbuilder.gif') {
// Check if the published learnpath is visible for student
$published_lp_id = self::get_published_lp_id_from_link($tool['link']);
if (!api_is_allowed_to_edit(null, true) &&
!learnpath::is_lp_visible_for_student($published_lp_id, api_get_user_id())) {
continue;
}
}
if ($session_id != 0 && in_array($tool['name'], array('course_maintenance', 'course_setting'))) {
continue;
}
if ($tool['name'] == 'course_description') {
$tool['link'] = 'course_description/index.php';
}
// This part displays the links to hide or remove a tool.
// These links are only visible by the course manager.
$item['extra'] = null;
if ($is_allowed_to_edit && !api_is_coach()) {
if (empty($session_id)) {
if ($tool['visibility'] == '1' && $tool['admin'] != '1') {
$link['name'] = Display::return_icon(
'visible.png',
get_lang('Deactivate'),
array('id' => 'linktool_'.$tool['id']),
ICON_SIZE_SMALL,
false
);
if (!empty($tool['id'])) {
$link['cmd'] = $urlGenerator->generate(
'chamilo_course_home_home_hideicon',
array(
'course' => $courseInfo['real_id'],
'iconId' => $tool['id']
)
);
}
$lnk[] = $link;
}
if ($tool['visibility'] == '0' && $tool['admin'] != '1') {
$link['name'] = Display::return_icon(
'invisible.png',
get_lang('Activate'),
array('id' => 'linktool_'.$tool['id']),
ICON_SIZE_SMALL,
false
);
if (!empty($tool['id'])) {
$link['cmd'] = $urlGenerator->generate(
'chamilo_course_home_home_showicon',
array(
'course' => $courseInfo['real_id'],
'iconId' => $tool['id']
)
);
}
$lnk[] = $link;
}
}
if (!empty($tool['adminlink'])) {
$item['extra'] = '
'.
Display::return_icon('edit.gif', get_lang('Edit')).'';
}
}
// Both checks are necessary as is_platform_admin doesn't take student view into account
if ($is_platform_admin && $is_allowed_to_edit) {
if ($tool['admin'] != '1') {
$link['cmd'] = 'hide=yes';
}
}
$item['visibility'] = null;
if (isset($lnk) && is_array($lnk)) {
foreach ($lnk as $this_link) {
if (empty($tool['adminlink'])) {
$commandLink = isset($this_link['cmd']) ? $this_link['cmd'] : '#';
$item['visibility'] .= '
'.$this_link['name'].'';
}
}
} else {
$item['visibility'] .= null;
}
// NOTE : Table contains only the image file name, not full path
if (stripos($tool['link'], 'http://') === false &&
stripos($tool['link'], 'https://') === false &&
stripos($tool['link'], 'ftp://') === false
) {
$tool['link'] = $web_code_path.$tool['link'];
}
if (!empty($tool['custom_icon'])) {
$tool['image'] = self::getCustomIconPath($courseInfo).$tool['custom_icon'];
}
if ($tool['visibility'] == '0' && $tool['admin'] != '1') {
$class = 'invisible';
$info = pathinfo($tool['image']);
$dirName = null;
if ($info['dirname'] != '.') {
$dirName = $info['dirname'].'/';
}
$basename = basename($tool['image'], '.'.$info['extension']); // $file is set to "index"
$tool['image'] = $dirName.$basename.'_na.'.$info['extension'];
} else {
$class = '';
}
$qm_or_amp = strpos($tool['link'], '?') === false ? '?' : '&';
// If it's a link, we don't add the cidReq
if ($tool['image'] == 'file_html.gif' || $tool['image'] == 'file_html_na.gif') {
$tool['link'] = $tool['link'].$qm_or_amp;
} else {
$tool['link'] = $tool['link'].$qm_or_amp.api_get_cidreq();
}
$tool_link_params = array();
//@todo this visio stuff should be removed
if (strpos($tool['name'], 'visio_') !== false) {
$tool_link_params = array(
'id' => 'tooldesc_'.$tool["id"],
'href' => '"javascript: void(0);"',
'class' => $class,
'onclick' => 'javascript: window.open(\'' . $tool['link'] . '\',\'window_visio'.api_get_course_id().'\',config=\'height=\'+730+\', width=\'+1020+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')',
'target' => $tool['target']
);
} elseif (strpos($tool['name'], 'chat') !== false && api_get_course_setting('allow_open_chat_window')) {
$tool_link_params = array(
'id' => 'tooldesc_'.$tool["id"],
'class' => $class,
'href' => 'javascript: void(0);',
'onclick' => 'javascript: window.open(\'' . $tool['link'] . '\',\'window_chat'.api_get_course_id().'\',config=\'height=\'+380+\', width=\'+625+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')',
'target' => $tool['target']
);
} else {
if (count(explode('type=classroom',$tool['link'])) == 2 || count(explode('type=conference', $tool['link'])) == 2) {
$tool_link_params = array(
'id' => 'tooldesc_'.$tool["id"],
'href' => $tool['link'],
'class' => $class,
'target' => '_blank'
);
} else {
$tool_link_params = array(
'id' => 'tooldesc_'.$tool["id"],
'href' => $tool['link'],
'class' => $class,
'target' => $tool['target']
);
}
}
$tool_name = self::translate_tool_name($tool);
$toolTip = $tool_name;
if (!empty($tool['description'])) {
$toolTip = $tool['description'];
}
$tool_link_params['data-original-title'] = $toolTip;
$tool_link_params['data-toggle'] = 'tooltip';
//$tool_link_params['title'] = $toolTip;
// Including Courses Plugins
// Creating title and the link
if (isset($tool['category']) && $tool['category'] == 'plugin') {
$plugin_info = $app_plugin->get_plugin_info($tool['name']);
if (isset($plugin_info) && isset($plugin_info['title'])) {
$tool_name = $plugin_info['title'];
}
if (!file_exists(api_get_path(SYS_CODE_PATH).'img/'.$tool['image']) &&
!file_exists(api_get_path(SYS_CODE_PATH).'img/icons/64/'.$tool['image'])) {
$tool['image'] = 'plugins.png';
}
$tool_link_params['href'] = api_get_path(WEB_PLUGIN_PATH).$tool['original_link'].'?'.api_get_cidreq();
}
if (!empty($tool['custom_icon'])) {
//self::getCustomIconPath($courseInfo)
$icon = Display::img(
$tool['image'],
null,
array('class' => 'tool-icon', 'id' => 'toolimage_'.$tool['id'])
);
} else {
$image = substr(
$tool['image'],
0,
strpos($tool['image'], '.')
).'.png';
$icon = Display::return_icon(
$image,
null,
array('class' => 'tool-icon', 'id' => 'toolimage_'.$tool['id']),
ICON_SIZE_BIG,
false
);
}
$userInfo = api_get_user_info();
$userStatus = isset($userInfo['status']) ? $userInfo['status'] : null;
// Validation when belongs to a session
$session_img = api_get_session_image($tool['session_id'], $userStatus);
$item['url_params'] = $tool_link_params;
$item['icon'] = Display::url(
$icon,
$tool_link_params['href'],
$tool_link_params
);
$item['tool'] = $tool;
$item['name'] = $tool_name;
$tool_link_params['id'] = 'is'.$tool_link_params['id'];
$item['link'] = Display::url(
$tool_name.$session_img,
$tool_link_params['href'],
$tool_link_params
);
$items[] = $item;
} // end of foreach
}
$i = 0;
$html = '';
$counter = 0;
if (!empty($items)) {
foreach ($items as $item) {
switch ($theme) {
case 'activity_big':
$data = '';
$html .= '
';
break;
case 'activity':
$html .= '
';
$content = $item['extra'];
$content .= $item['visibility'];
$content .= $item['icon'];
$content .= $item['link'];
$html .= Display::div($content, array('class'=>'activity_content'));
$html .= '
';
break;
case 'vertical_activity':
if ($i == 0) {
$html .= '
';
}
$html .= '- ';
$html .= $item['extra'];
$html .= $item['visibility'];
$html .= $item['icon'];
$html .= $item['link'];
$html .= '
';
if ($i == count($items) -1) {
$html .= '
';
}
break;
}
$i++;
}
}
return array(
'content' => $html,
'tool_list' => $items
);
}
/**
* Shows the general data for a particular meeting
*
* @param id session id
* @return string session data
*/
public static function show_session_data($id_session)
{
$session_category_table = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
$sessionInfo = api_get_session_info($id_session);
if (empty($sessionInfo)) {
return '';
}
$sql = 'SELECT name FROM '.$session_category_table.'
WHERE id = "'.intval($sessionInfo['session_category_id']).'"';
$rs_category = Database::query($sql);
$session_category = '';
if (Database::num_rows($rs_category) > 0) {
$rows_session_category = Database::store_result($rs_category);
$rows_session_category = $rows_session_category[0];
$session_category = $rows_session_category['name'];
}
$coachInfo = api_get_user_info($sessionInfo['id_coach']);
$output = '';
if (!empty($session_category)) {
$output .= '
'.get_lang('SessionCategory').': '.''.$session_category.' |
';
}
$dateInfo = SessionManager::parseSessionDates($sessionInfo);
$msgDate = $dateInfo['access'];
$output .= '
'.get_lang('SessionName').': '.''.$sessionInfo['name'].' |
'.get_lang('GeneralCoach').': '.''.$coachInfo['complete_name'].' |
';
$output .= '
'.get_lang('SessionIdentifier').': '.
Display::return_icon(
'star.png',
' ',
array('align' => 'absmiddle')
).'
|
'.get_lang('Date').': '.''.$msgDate.'
|
';
return $output;
}
/**
* Retrieves the name-field within a tool-record and translates it on necessity.
* @param array $tool The input record.
* @return string Returns the name of the corresponding tool.
*/
public static function translate_tool_name(& $tool)
{
static $already_translated_icons = array(
'file_html.gif',
'file_html_na.gif',
'file_html.png',
'file_html_na.png',
'scormbuilder.gif',
'scormbuilder_na.gif',
'blog.gif',
'blog_na.gif',
'external.gif',
'external_na.gif'
);
$toolName = Security::remove_XSS(stripslashes($tool['name']));
if (in_array($tool['image'], $already_translated_icons)) {
return $toolName;
}
$toolName = api_underscore_to_camel_case($toolName);
if (isset($GLOBALS['Tool' . $toolName])) {
return get_lang('Tool' . $toolName);
}
return $toolName;
}
/**
* Get published learning path id from link inside course home
* @param string Link to published lp
* @return int Learning path id
*/
public static function get_published_lp_id_from_link($published_lp_link)
{
$lp_id = 0;
$param_lp_id = strstr($published_lp_link, 'lp_id=');
if (!empty($param_lp_id)) {
$a_param_lp_id = explode('=', $param_lp_id);
if (isset($a_param_lp_id[1])) {
$lp_id = intval($a_param_lp_id[1]);
}
}
return $lp_id;
}
/**
* @param bool $include_admin_tools
* @return array
*/
static function get_navigation_items($include_admin_tools = false)
{
$navigation_items = array();
$course_id = api_get_course_int_id();
$courseInfo = api_get_course_info();
if (!empty($course_id)) {
$course_tools_table = Database :: get_course_table(TABLE_TOOL_LIST);
/* Link to the Course homepage */
$navigation_items['home']['image'] = 'home.gif';
$navigation_items['home']['link'] = api_get_path(WEB_CODE_PATH).Security::remove_XSS($_SESSION['_course']['path']).'/index.php';
$navigation_items['home']['name'] = get_lang('CourseHomepageLink');
$sql = "SELECT * FROM $course_tools_table
WHERE c_id = $course_id AND visibility='1' and admin='0'
ORDER BY id ASC";
$sql_result = Database::query($sql);
while ($row = Database::fetch_array($sql_result)) {
$navigation_items[$row['id']] = $row;
if (stripos($row['link'], 'http://') === false && stripos($row['link'], 'https://') === false) {
$navigation_items[$row['id']]['link'] = api_get_path(WEB_CODE_PATH).$row['link'];
$navigation_items[$row['id']]['name'] = CourseHome::translate_tool_name($row);
}
}
/* Admin (edit rights) only links
- Course settings (course admin only)
- Course rights (roles & rights overview) */
if ($include_admin_tools) {
$sql = "SELECT name, image FROM $course_tools_table
WHERE c_id = $course_id AND link='course_info/infocours.php'";
$sql_result = Database::query($sql);
$course_setting_info = Database::fetch_array($sql_result);
$course_setting_visual_name = CourseHome::translate_tool_name($course_setting_info);
if (api_get_session_id() == 0) {
// course settings item
$navigation_items['course_settings']['image'] = $course_setting_info['image'];
$navigation_items['course_settings']['link'] = api_get_path(WEB_CODE_PATH).'course_info/infocours.php';
$navigation_items['course_settings']['name'] = $course_setting_visual_name;
}
}
}
foreach ($navigation_items as $key => $navigation_item) {
if (strstr($navigation_item['link'], '?')) {
//link already contains a parameter, add course id parameter with &
$parameter_separator = '&';
} else {
//link doesn't contain a parameter yet, add course id parameter with ?
$parameter_separator = '?';
}
//$navigation_items[$key]['link'] .= $parameter_separator.api_get_cidreq();
$navigation_items[$key]['link'] .= $parameter_separator.'cidReq='.api_get_course_id().'&gidReq=0&id_session='.api_get_session_id();
}
return $navigation_items;
}
/**
* Show a navigation menu
*/
public static function show_navigation_menu()
{
$navigation_items = self::get_navigation_items(true);
$course_id = api_get_course_id();
$html = '
';
return $html;
}
/**
* Show a toolbar with shortcuts to the course tool
*/
public static function show_navigation_tool_shortcuts($orientation = SHORTCUTS_HORIZONTAL)
{
$navigation_items = self::get_navigation_items(false);
$course_id = api_get_course_id();
$html = '';
if (!empty($navigation_items)) {
if ($orientation == SHORTCUTS_HORIZONTAL)
$style_id = "toolshortcuts_horizontal";
else {
$style_id = "toolshortcuts_vertical";
}
$html .= '
';
foreach ($navigation_items as $key => $navigation_item) {
if (strpos($navigation_item['link'], 'chat') !== false &&
api_get_course_setting('allow_open_chat_window')
) {
$html .= '
';
$html .= '';
$html .= ' ';
if ($orientation == SHORTCUTS_VERTICAL) {
$html .= '
';
}
}
$html .= '
';
}
return $html;
}
/**
* List course homepage tools from authoring and interaction sections
* @param int $courseId The course ID (guessed from context if not provided)
* @param int $sessionId The session ID (guessed from context if not provided)
* @return array List of all tools data from the c_tools table
*/
public static function toolsIconsAction($courseId = null, $sessionId = null)
{
if (empty($courseId)) {
$courseId = api_get_course_int_id();
} else {
$courseId = intval($courseId);
}
if (empty($sessionId)) {
$sessionId = api_get_session_id();
} else {
$sessionId = intval($sessionId);
}
if (empty($courseId)) {
// We shouldn't get here, but for some reason api_get_course_int_id()
// doesn't seem to get the course from the context, sometimes
return array();
}
$table = Database::get_course_table(TABLE_TOOL_LIST);
$sql = "SELECT * FROM $table
WHERE category in ('authoring','interaction')
AND c_id = $courseId
AND session_id = $sessionId
ORDER BY id";
$result = Database::query($sql);
$data = Database::store_result($result, 'ASSOC');
return $data;
}
/**
* @param int $editIcon
* @return array
*/
public static function getTool($editIcon)
{
$course_tool_table = Database::get_course_table(TABLE_TOOL_LIST);
$editIcon = intval($editIcon);
$sql = "SELECT * FROM $course_tool_table
WHERE iid = $editIcon";
$result = Database::query($sql);
$tool = Database::fetch_assoc($result, 'ASSOC');
return $tool;
}
/**
* @return string
*/
public static function getCustomSysIconPath()
{
// Check if directory exists or create it if it doesn't
$dir = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/upload/course_home_icons/';
if (!is_dir($dir)) {
mkdir($dir, api_get_permissions_for_new_directories(), true);
}
return $dir;
}
/**
* @return string
*/
public static function getCustomWebIconPath()
{
// Check if directory exists or create it if it doesn't
$dir = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/upload/course_home_icons/';
return $dir;
}
/**
* @param string $icon
* @return string
*/
public static function getDisableIcon($icon)
{
$fileInfo = pathinfo($icon);
return $fileInfo['filename'].'_na.'.$fileInfo['extension'];
}
/**
* @param int $id
* @param array $values
*/
public static function updateTool($id, $values)
{
$table = Database::get_course_table(TABLE_TOOL_LIST);
$params = [
'name' => $values['name'],
'link' => $values['link'],
'target' => $values['target'],
'visibility' => $values['visibility'],
'description' => $values['description'],
];
if (isset($_FILES['icon']['size']) && $_FILES['icon']['size'] !== 0) {
$dir = self::getCustomSysIconPath();
// Resize image if it is larger than 64px
$temp = new Image($_FILES['icon']['tmp_name']);
$picture_infos = $temp->get_image_info();
if ($picture_infos['width'] > 64) {
$thumbwidth = 64;
} else {
$thumbwidth = $picture_infos['width'];
}
if ($picture_infos['height'] > 64) {
$new_height = 64;
} else {
$new_height = $picture_infos['height'];
}
$temp->resize($thumbwidth, $new_height, 0);
//copy the image to the course upload folder
$path = $dir.$_FILES['icon']['name'];
$result = $temp->send_image($path);
$temp = new Image($path);
$r = $temp->convert2bw();
$ext = pathinfo($path, PATHINFO_EXTENSION);
$bwPath = substr($path,0,-(strlen($ext)+1)) . '_na.' . $ext;
if ($r === false) {
error_log('Conversion to B&W of '.$path.' failed in '.__FILE__.' at line '.__LINE__);
} else {
$temp->send_image($bwPath);
$iconName = $_FILES['icon']['name'];
$params['custom_icon'] = $iconName;
}
}
Database::update(
$table,
$params,
[' iid = ?' => [$id]]
);
}
/**
* @param int $id
*/
public static function deleteIcon($id)
{
$table = Database::get_course_table(TABLE_TOOL_LIST);
$tool = self::getTool($id);
if ($tool && !empty($tool['custom_icon'])) {
$file = self::getCustomSysIconPath().$tool['custom_icon'];
$fileInfo = pathinfo($file);
$fileGray = $fileInfo['filename'].'_na.'.$fileInfo['extension'];
$fileGray = self::getCustomSysIconPath().$fileGray;
if (file_exists($file) && is_file($file)) {
if (Security::check_abs_path($file, self::getCustomSysIconPath())) {
unlink($file);
}
}
if (file_exists($fileGray) && is_file($fileGray)) {
if (Security::check_abs_path($fileGray, self::getCustomSysIconPath())) {
unlink($fileGray);
}
}
$params = [
'custom_icon' => '',
];
Database::update(
$table,
$params,
[' iid = ?' => [$id]]
);
}
}
/**
* @param array $courseInfo
* @return string
*/
public static function getCustomIconPath($courseInfo)
{
return api_get_path(WEB_DATA_COURSE_PATH).$courseInfo['directory'].'/upload/course_home_icons/';
}
/**
* @param string $text
* @param array $toolList
* @return string
*/
public static function replaceTextWithToolUrls($text, $toolList)
{
if (empty($toolList)) {
return $text;
}
foreach ($toolList as $tool) {
if (!isset($tool['icon'])) {
continue;
}
$toolName = $tool['tool']['name'];
$search = array("{{ ".$toolName." }}", "{{".$toolName."}}", "((".$toolName."))", "(( ".$toolName." ))");
$text = str_replace($search, $tool['icon'], $text);
}
// Cleaning tags that are not used.
$tools = self::availableTools();
foreach ($tools as $toolName) {
$search = array("{{ ".$toolName." }}", "{{".$toolName."}}", "((".$toolName."))", "(( ".$toolName." ))");
$text = str_replace($search, null, $text);
}
return $text;
}
/**
* Available tools
* @return array
*/
public static function availableTools()
{
return array(
'course_description',
'quiz',
'announcement',
'forum',
'dropbox',
'user',
'group',
'chat',
'student_publication',
'survey',
'wiki',
'gradebook',
'glossary',
'notebook',
'attendance',
'course_progress',
'curriculum',
'blog_management',
'tracking',
'course_setting',
'course_maintenance'
);
}
}