You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
180 lines
5.8 KiB
180 lines
5.8 KiB
11 years ago
|
<?php
|
||
|
/* For licensing terms, see /license.txt */
|
||
|
|
||
|
/**
|
||
|
* @package chamilo.admin
|
||
|
*/
|
||
|
$cidReset = true;
|
||
|
|
||
8 years ago
|
require_once __DIR__.'/../inc/global.inc.php';
|
||
11 years ago
|
|
||
10 years ago
|
$extraFieldType = isset($_REQUEST['type']) ? $_REQUEST['type'] : null;
|
||
11 years ago
|
|
||
|
$this_section = SECTION_PLATFORM_ADMIN;
|
||
|
|
||
|
api_protect_admin_script();
|
||
|
|
||
|
//Add the JS needed to use the jqgrid
|
||
|
$htmlHeadXtra[] = api_get_jqgrid_js();
|
||
|
|
||
|
// setting breadcrumbs
|
||
5 years ago
|
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('Administration')];
|
||
11 years ago
|
|
||
|
$tool_name = null;
|
||
|
|
||
|
$action = isset($_GET['action']) ? $_GET['action'] : null;
|
||
|
if (!in_array($extraFieldType, ExtraField::getValidExtraFieldTypes())) {
|
||
8 years ago
|
api_not_allowed(true);
|
||
11 years ago
|
}
|
||
|
|
||
|
$check = Security::check_token('request');
|
||
|
$token = Security::get_token();
|
||
|
|
||
|
$obj = new ExtraField($extraFieldType);
|
||
|
|
||
|
$obj->setupBreadcrumb($interbreadcrumb, $action);
|
||
|
|
||
|
//jqgrid will use this URL to do the selects
|
||
8 years ago
|
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_extra_fields&type='.$extraFieldType;
|
||
11 years ago
|
|
||
|
//The order is important you need to check the the $column variable in the model.ajax.php file
|
||
|
$columns = $obj->getJqgridColumnNames();
|
||
|
|
||
|
//Column config
|
||
|
$column_model = $obj->getJqgridColumnModel();
|
||
|
|
||
|
//Autowidth
|
||
|
$extra_params['autowidth'] = 'true';
|
||
|
//height auto
|
||
|
$extra_params['height'] = 'auto';
|
||
|
$extra_params['sortname'] = 'field_order';
|
||
|
|
||
|
$action_links = $obj->getJqgridActionLinks($token);
|
||
|
|
||
10 years ago
|
$htmlHeadXtra[] = '<script>
|
||
11 years ago
|
$(function() {
|
||
|
// grid definition see the $obj->display() function
|
||
7 years ago
|
'.Display::grid_js(
|
||
10 years ago
|
$obj->type.'_fields',
|
||
|
$url,
|
||
|
$columns,
|
||
|
$column_model,
|
||
|
$extra_params,
|
||
7 years ago
|
[],
|
||
10 years ago
|
$action_links,
|
||
|
true
|
||
8 years ago
|
).'
|
||
11 years ago
|
|
||
|
$("#field_type").on("change", function() {
|
||
|
id = $(this).val();
|
||
|
switch(id) {
|
||
|
case "1":
|
||
7 years ago
|
$("#example").html("'.addslashes(Display::return_icon('userfield_text.png')).'");
|
||
11 years ago
|
break;
|
||
|
case "2":
|
||
7 years ago
|
$("#example").html("'.addslashes(Display::return_icon('userfield_text_area.png')).'");
|
||
11 years ago
|
break;
|
||
|
case "3":
|
||
7 years ago
|
$("#example").html("'.addslashes(Display::return_icon('add_user_field_howto.png')).'");
|
||
11 years ago
|
break;
|
||
|
case "4":
|
||
7 years ago
|
$("#example").html("'.addslashes(Display::return_icon('userfield_drop_down.png')).'");
|
||
11 years ago
|
break;
|
||
|
case "5":
|
||
7 years ago
|
$("#example").html("'.addslashes(Display::return_icon('userfield_multidropdown.png')).'");
|
||
11 years ago
|
break;
|
||
|
case "6":
|
||
7 years ago
|
$("#example").html("'.addslashes(Display::return_icon('userfield_data.png')).'");
|
||
11 years ago
|
break;
|
||
|
case "7":
|
||
7 years ago
|
$("#example").html("'.addslashes(Display::return_icon('userfield_date_time.png')).'");
|
||
11 years ago
|
break;
|
||
|
case "8":
|
||
7 years ago
|
$("#example").html("'.addslashes(Display::return_icon('userfield_doubleselect.png')).'");
|
||
11 years ago
|
break;
|
||
|
case "9":
|
||
7 years ago
|
$("#example").html("'.addslashes(Display::return_icon('userfield_divider.png')).'");
|
||
11 years ago
|
break;
|
||
|
case "10":
|
||
7 years ago
|
$("#example").html("'.addslashes(Display::return_icon('userfield_user_tag.png')).'");
|
||
11 years ago
|
break;
|
||
|
case "11":
|
||
7 years ago
|
$("#example").html("'.addslashes(Display::return_icon('userfield_data.png')).'");
|
||
11 years ago
|
break;
|
||
|
}
|
||
|
});
|
||
|
});
|
||
|
</script>';
|
||
|
|
||
|
// The header.
|
||
|
Display::display_header($tool_name);
|
||
|
|
||
|
// Action handling: Add
|
||
|
switch ($action) {
|
||
|
case 'add':
|
||
10 years ago
|
if (api_get_session_id() != 0 &&
|
||
|
!api_is_allowed_to_session_edit(false, true)
|
||
|
) {
|
||
11 years ago
|
api_not_allowed();
|
||
|
}
|
||
8 years ago
|
$url = api_get_self().'?type='.$obj->type.'&action='.Security::remove_XSS($_GET['action']);
|
||
11 years ago
|
$form = $obj->return_form($url, 'add');
|
||
|
|
||
|
// The validation or display
|
||
|
if ($form->validate()) {
|
||
10 years ago
|
$values = $form->exportValues();
|
||
9 years ago
|
unset($values['id']);
|
||
10 years ago
|
$res = $obj->save($values);
|
||
10 years ago
|
if ($res) {
|
||
5 years ago
|
echo Display::return_message(get_lang('Item added'), 'confirmation');
|
||
10 years ago
|
}
|
||
11 years ago
|
$obj->display();
|
||
|
} else {
|
||
|
echo '<div class="actions">';
|
||
8 years ago
|
echo '<a href="'.api_get_self().'?type='.$obj->type.'">'.
|
||
|
Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).'</a>';
|
||
11 years ago
|
echo '</div>';
|
||
|
$form->addElement('hidden', 'sec_token');
|
||
7 years ago
|
$form->setConstants(['sec_token' => $token]);
|
||
11 years ago
|
$form->display();
|
||
|
}
|
||
|
break;
|
||
|
case 'edit':
|
||
|
// Action handling: Editing
|
||
8 years ago
|
$url = api_get_self().'?type='.$obj->type.'&action='.Security::remove_XSS($_GET['action']).'&id='.intval($_GET['id']);
|
||
11 years ago
|
$form = $obj->return_form($url, 'edit');
|
||
|
|
||
|
// The validation or display
|
||
|
if ($form->validate()) {
|
||
10 years ago
|
$values = $form->exportValues();
|
||
10 years ago
|
$res = $obj->update($values);
|
||
8 years ago
|
echo Display::return_message(
|
||
5 years ago
|
sprintf(get_lang('Item updated'), $values['variable']),
|
||
8 years ago
|
'confirmation',
|
||
10 years ago
|
false
|
||
|
);
|
||
11 years ago
|
$obj->display();
|
||
|
} else {
|
||
|
echo '<div class="actions">';
|
||
8 years ago
|
echo '<a href="'.api_get_self().'?type='.$obj->type.'">'.
|
||
|
Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).'</a>';
|
||
11 years ago
|
echo '</div>';
|
||
|
$form->addElement('hidden', 'sec_token');
|
||
7 years ago
|
$form->setConstants(['sec_token' => $token]);
|
||
11 years ago
|
$form->display();
|
||
|
}
|
||
|
break;
|
||
|
case 'delete':
|
||
|
// Action handling: delete
|
||
10 years ago
|
$res = $obj->delete($_GET['id']);
|
||
|
if ($res) {
|
||
5 years ago
|
echo Display::return_message(get_lang('Item deleted'), 'confirmation');
|
||
10 years ago
|
}
|
||
11 years ago
|
$obj->display();
|
||
|
break;
|
||
|
default:
|
||
|
$obj->display();
|
||
|
break;
|
||
|
}
|
||
8 years ago
|
Display::display_footer();
|