api_get_self().'?'.api_get_cidreq(),
'name' => get_lang('Customize icons'),
];
$toolName = Security::remove_XSS(stripslashes($tool['name']));
$currentUrl = api_get_self().'?action=edit_icon&id='.$id.'&'.api_get_cidreq();
$form = new FormValidator('icon_edit', 'post', $currentUrl);
$form->addHeader(get_lang('Edit icon'));
$form->addHtml('
');
$form->addText('name', get_lang('Name'));
$form->addText('link', get_lang('Links'));
$allowedPictureTypes = ['jpg', 'jpeg', 'png'];
$form->addFile('icon', get_lang('Custom icon'));
$form->addRule(
'icon',
get_lang('Only PNG, JPG or GIF images allowed').' ('.implode(',', $allowedPictureTypes).')',
'filetype',
$allowedPictureTypes
);
$form->addSelect(
'target',
get_lang('Link\'s target'),
[
'_self' => get_lang('Open self'),
'_blank' => get_lang('Open blank'),
]
);
$form->addSelect(
'visibility',
get_lang('Visibility'),
[1 => get_lang('Visible'), 0 => get_lang('invisible')]
);
$form->addTextarea(
'description',
get_lang('Description'),
['rows' => '3', 'cols' => '40']
);
$form->addButtonUpdate(get_lang('Update'));
$form->addHtml('
');
$form->addHtml('');
if (isset($tool['custom_icon']) && !empty($tool['custom_icon'])) {
$form->addLabel(
get_lang('Current icon'),
Display::img(
CourseHome::getCustomWebIconPath().$tool['custom_icon']
)
);
$form->addCheckBox('delete_icon', null, get_lang('Delete picture'));
}
$form->addHtml('
');
$form->setDefaults($tool);
$content = $form->returnForm();
if ($form->validate()) {
$data = $form->getSubmitValues();
CourseHome::updateTool($id, $data);
Display::addFlash(Display::return_message(get_lang('Update successful')));
if (isset($data['delete_icon'])) {
CourseHome::deleteIcon($id);
}
$currentUrlReturn = api_get_self().'?'.api_get_cidreq();
header('Location: '.$currentUrlReturn);
exit;
}
break;
case 'list':
default:
$toolList = CourseHome::toolsIconsAction(
api_get_course_int_id(),
api_get_session_id()
);
$list = [];
$tmp = [];
foreach ($toolList as $tool) {
$tmp['id'] = $tool['id'];
$tmp['name'] = Security::remove_XSS(stripslashes($tool['name']));
$toolIconName = 'Tool'.api_underscore_to_camel_case($tool['name']);
$toolIconName = isset($$toolIconName) ? get_lang($toolIconName) : $tool['name'];
$tmp['name'] = $toolIconName;
$tmp['link'] = $tool['link'];
if (!empty($tool['custom_icon'])) {
$image = CourseHome::getCustomWebIconPath().$tool['custom_icon'];
$icon = Display::img($image, $tool['name']);
} else {
$image = 'tool_'.(substr($tool['image'], 0, strpos($tool['image'], '.'))).'.png';
$icon = Display::return_icon(
$image,
null,
['id' => 'tool_'.$tool['id']],
ICON_SIZE_BIG,
false,
true
);
}
$tmp['image'] = $icon;
$tmp['visibility'] = $tool['visibility'];
$delete = (!empty($tool['custom_icon'])) ? "
" : "";
$edit = '';
$tmp['action'] = $edit.$delete;
$list[] = $tmp;
}
$tpl->assign('tools', $list);
$layout = $tpl->get_template("course_info/tools.html.twig");
$content = $tpl->fetch($layout);
break;
}
$tpl = new Template($toolName);
$tpl->assign('content', $content);
$tpl->display_one_col_template();