123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?php
- use \ChamiloSession as Session;
- $language_file = array('exercice','tracking');
- // including the global library
- require_once '../inc/global.inc.php';
- // Access control
- api_protect_course_script(true);
- $course_id = api_get_course_int_id();
- //Add the JS needed to use the jqgrid
- $htmlHeadXtra[] = api_get_jqgrid_js();
- $interbreadcrumb[] = array("url" => "exercice.php", "name" => get_lang('Exercices'));
- Display::display_header(get_lang('Media'));
- $action = isset($_GET['action']) ? $_GET['action'] : null;
- $page_url = "media.php?".api_get_cidreq();
- $token = Security::get_token();
- switch ($action) {
- case 'add':
- $url = $page_url.'&action='.Security::remove_XSS($_GET['action']);
- $objQuestion = Question::getInstance(MEDIA_QUESTION);
- $form = new FormValidator('question_admin_form', 'post' , $url);
- // question form elements
- $objQuestion->createForm($form);
- $objQuestion->createAnswersForm($form);
- if ($form->validate()) {
- // question
- $objQuestion->processCreation($form, null);
- // answers
- $objQuestion->processAnswersCreation($form);
- } else {
- $form->display();
- }
- break;
- case 'edit':
- $url = $page_url.'&action='.Security::remove_XSS($_GET['action']).'&id='.intval($_GET['id']);
- $objQuestion = Question::read($_GET['id']);
- $form = new FormValidator('question_admin_form','post', $url);
- // question form elements
- $objQuestion->createForm($form);
- $objQuestion->createAnswersForm($form);
- $form->addElement('hidden', 'id', intval($_GET['id']));
- $defaults = array();
- $defaults['questionName'] = $objQuestion->question;
- $defaults['questionDescription'] = $objQuestion->description;
- $defaults['questionLevel'] = $objQuestion->level;
- $defaults['questionCategory'] = $objQuestion->category_list;
- $defaults['parent_id'] = $objQuestion->parent_id;
- $form->setDefaults($defaults);
- if ($form->validate()) {
- // question
- $objQuestion->processCreation($form, null);
- // answers
- $objQuestion->processAnswersCreation($form);
- } else {
- $form->display();
- }
- break;
- case 'delete':
- $objQuestion = Question::read($_GET['id']);
- $objQuestion->delete();
- break;
- }
- //jqgrid will use this URL to do the selects
- $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_course_exercise_medias';
- //The order is important you need to check the the $column variable in the model.ajax.php file
- $columns = array(get_lang('Name'), get_lang('Actions'));
- //Column config
- $column_model = array(
- array('name'=>'name', 'index'=>'name', 'width'=>'200', 'align'=>'left'),
- array('name'=>'actions', 'index'=>'actions', 'width'=>'50', 'align'=>'left','formatter'=>'action_formatter','sortable'=>'false')
- );
- //Autowidth
- $extra_params['autowidth'] = 'true';
- //height auto
- $extra_params['height'] = 'auto';
- //With this function we can add actions to the jgrid (edit, delete, etc)
- $action_links = 'function action_formatter(cellvalue, options, rowObject) {
- return \'<a href="?action=edit&id=\'+options.rowId+\'">'.Display::return_icon('edit.png',get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>'.
- ' <a onclick="javascript:if(!confirm('."\'".addslashes(get_lang("ConfirmYourChoice"))."\'".')) return false;" href="?sec_token='.$token.'&action=delete&id=\'+options.rowId+\'">'.Display::return_icon('delete.png',get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>'.
- '\';
- }';
- ?>
- <script>
- $(function() {
- <?php
- // grid definition see the $career->display() function
- echo Display::grid_js('medias', $url, $columns, $column_model, $extra_params, array(), $action_links, true);
- ?>
- });
- </script>
- <?php
- $items = array(
- array('content' => Display::return_icon('add.png'), 'url' => $page_url.'&action=add')
- );
- echo Display::actions($items);
- echo Display::grid_html('medias');
- Display::display_footer();
|