Skip to content

Commit f8d933a

Browse files
committed
Merge pull request #59 from chamilo/1.9.x
1.9.x
2 parents 4c7d43f + 39daaec commit f8d933a

File tree

81 files changed

+8054
-3590
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+8054
-3590
lines changed

index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
//@todo move this inside the IndexManager
144144
if (!api_is_anonymous()) {
145145
$controller->tpl->assign('profile_block', $controller->return_profile_block());
146-
$controller->tpl->assign('user_image_block', $controller->return_user_image_block());
146+
$controller->tpl->assign('user_image_block', $controller->return_user_image_block());
147147

148148
if (api_is_platform_admin()) {
149149
$controller->tpl->assign('course_block', $controller->return_course_block());

main/admin/extra_field_options.php

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
<?php
2+
/* For licensing terms, see /license.txt */
3+
4+
/**
5+
* @package chamilo.admin
6+
*/
7+
8+
// Language files that need to be included.
9+
$language_file = array('admin');
10+
11+
$cidReset = true;
12+
require_once '../inc/global.inc.php';
13+
14+
$this_section = SECTION_PLATFORM_ADMIN;
15+
16+
$type = isset($_REQUEST['type']) ? $_REQUEST['type'] : null;
17+
18+
api_protect_admin_script();
19+
20+
//Add the JS needed to use the jqgrid
21+
$htmlHeadXtra[] = api_get_jqgrid_js();
22+
23+
// setting breadcrumbs
24+
$interbreadcrumb[]=array('url' => 'index.php','name' => get_lang('PlatformAdmin'));
25+
26+
$tool_name = null;
27+
28+
$action = isset($_GET['action']) ? $_GET['action'] : null;
29+
$field_id = isset($_GET['field_id']) ? $_GET['field_id'] : null;
30+
31+
if (empty($field_id)) {
32+
api_not_allowed();
33+
}
34+
if (!in_array($type, ExtraField::getValidExtraFieldTypes())) {
35+
api_not_allowed();
36+
}
37+
38+
$extra_field = new ExtraField($type);
39+
$extra_field_info = $extra_field->get($field_id);
40+
41+
$check = Security::check_token('request');
42+
$token = Security::get_token();
43+
44+
if ($action == 'add') {
45+
$interbreadcrumb[]=array('url' => 'extra_fields.php?type='.$extra_field->type,'name' => $extra_field->pageName);
46+
$interbreadcrumb[]=array('url' => 'extra_fields.php?type='.$extra_field->type.'&action=edit&id='.$extra_field_info['id'],'name' => $extra_field_info['field_display_text']);
47+
$interbreadcrumb[]=array('url' => 'extra_field_options.php?type='.$extra_field->type.'&field_id='.$extra_field_info['id'], 'name' => get_lang('EditExtraFieldOptions'));
48+
$interbreadcrumb[]=array('url' => '#','name' => get_lang('Add'));
49+
} elseif ($action == 'edit') {
50+
$interbreadcrumb[]=array('url' => 'extra_fields.php?type='.$extra_field->type,'name' => $extra_field->pageName);
51+
$interbreadcrumb[]=array('url' => 'extra_fields.php?type='.$extra_field->type.'&action=edit&id='.$extra_field_info['id'],'name' => $extra_field_info['field_display_text']);
52+
$interbreadcrumb[]=array('url' => 'extra_field_options.php?type='.$extra_field->type.'&field_id='.$extra_field_info['id'], 'name' => get_lang('EditExtraFieldOptions'));
53+
54+
$interbreadcrumb[]=array('url' => '#','name' => get_lang('Edit'));
55+
} else {
56+
$interbreadcrumb[]=array('url' => 'extra_fields.php?type='.$extra_field->type,'name' => $extra_field->pageName);
57+
$interbreadcrumb[]=array('url' => 'extra_fields.php?type='.$extra_field->type.'&action=edit&id='.$extra_field_info['id'],'name' => $extra_field_info['field_display_text']);
58+
$interbreadcrumb[]=array('url' => '#','name' => get_lang('EditExtraFieldOptions'));
59+
}
60+
61+
//jqgrid will use this URL to do the selects
62+
$params = 'field_id='.$field_id.'&type='.$extra_field->type;
63+
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_extra_field_options&'.$params;
64+
65+
//The order is important you need to check the the $column variable in the model.ajax.php file
66+
$columns = array(get_lang('Name'), get_lang('Value'), get_lang('Order'), get_lang('Actions'));
67+
68+
//Column config
69+
$column_model = array(
70+
array('name'=>'option_display_text', 'index'=>'option_display_text', 'width'=>'180', 'align'=>'left'),
71+
array('name'=>'option_value', 'index'=>'option_value', 'width'=>'', 'align'=>'left','sortable'=>'false'),
72+
array('name'=>'option_order', 'index'=>'option_order', 'width'=>'', 'align'=>'left','sortable'=>'false'),
73+
array('name'=>'actions', 'index'=>'actions', 'width'=>'100', 'align'=>'left','formatter'=>'action_formatter','sortable'=>'false')
74+
);
75+
//Autowidth
76+
$extra_params['autowidth'] = 'true';
77+
//height auto
78+
$extra_params['height'] = 'auto';
79+
80+
//With this function we can add actions to the jgrid (edit, delete, etc)
81+
$action_links = 'function action_formatter(cellvalue, options, rowObject) {
82+
return \'<a href="?action=edit&'.$params.'&id=\'+options.rowId+\'">'.Display::return_icon('edit.png',get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>'.
83+
'&nbsp;<a onclick="javascript:if(!confirm('."\'".addslashes(get_lang("ConfirmYourChoice"))."\'".')) return false;" href="?sec_token='.$token.'&action=delete&'.$params.'&id=\'+options.rowId+\'">'.Display::return_icon('delete.png',get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>'.
84+
'\';
85+
}';
86+
$htmlHeadXtra[]='
87+
<script>
88+
$(function() {
89+
// grid definition see the $obj->display() function
90+
'.Display::grid_js('extra_field_options', $url, $columns, $column_model, $extra_params, array(), $action_links, true).'
91+
92+
});
93+
</script>';
94+
95+
// The header.
96+
Display::display_header($tool_name);
97+
98+
echo Display::page_header($extra_field_info['field_display_text']);
99+
100+
$obj = new ExtraFieldOption($extra_field->type);
101+
$obj->field_id = $field_id;
102+
103+
// Action handling: Add
104+
switch ($action) {
105+
case 'add':
106+
if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
107+
api_not_allowed();
108+
}
109+
$url = api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&'.$params;
110+
$form = $obj->return_form($url, 'add');
111+
112+
// The validation or display
113+
if ($form->validate()) {
114+
if ($check) {
115+
$values = $form->exportValues();
116+
$res = $obj->save_one_item($values);
117+
if ($res) {
118+
Display::display_confirmation_message(get_lang('ItemAdded'));
119+
}
120+
}
121+
$obj->display();
122+
} else {
123+
/*echo '<div class="actions">';
124+
echo '<a href="'.api_get_self().'">'.Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM).'</a>';
125+
echo '</div>'; */
126+
$form->addElement('hidden', 'sec_token');
127+
$form->setConstants(array('sec_token' => $token));
128+
$form->display();
129+
}
130+
break;
131+
case 'edit':
132+
// Action handling: Editing
133+
$url = api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&id='.intval($_GET['id']).'&'.$params;
134+
$form = $obj->return_form($url, 'edit');
135+
136+
// The validation or display
137+
if ($form->validate()) {
138+
if ($check) {
139+
$values = $form->exportValues();
140+
$res = $obj->update($values);
141+
Display::display_confirmation_message(sprintf(get_lang('ItemUpdated'), $values['name']), false);
142+
}
143+
$obj->display();
144+
} else {
145+
/*echo '<div class="actions">';
146+
echo '<a href="'.api_get_self().'">'.Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM).'</a>';
147+
echo '</div>';*/
148+
$form->addElement('hidden', 'sec_token');
149+
$form->setConstants(array('sec_token' => $token));
150+
$form->display();
151+
}
152+
break;
153+
case 'delete':
154+
// Action handling: delete
155+
if ($check) {
156+
$res = $obj->delete($_GET['id']);
157+
if ($res) {
158+
Display::display_confirmation_message(get_lang('ItemDeleted'));
159+
}
160+
}
161+
$obj->display();
162+
break;
163+
default:
164+
$obj->display();
165+
break;
166+
}
167+
Display :: display_footer();
Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
<?php
2+
/* For licensing terms, see /license.txt */
3+
4+
/**
5+
* @package chamilo.admin
6+
*/
7+
8+
// Language files that need to be included.
9+
$language_file = array('admin');
10+
11+
$cidReset = true;
12+
require_once '../inc/global.inc.php';
13+
14+
$this_section = SECTION_PLATFORM_ADMIN;
15+
16+
$type = isset($_REQUEST['type']) ? $_REQUEST['type'] : null;
17+
18+
api_protect_admin_script();
19+
20+
// setting breadcrumbs
21+
$interbreadcrumb[] = array('url' => 'index.php','name' => get_lang('PlatformAdmin'));
22+
23+
$tool_name = null;
24+
25+
$action = isset($_GET['action']) ? $_GET['action'] : null;
26+
$field_id = isset($_GET['field_id']) ? $_GET['field_id'] : null;
27+
28+
if (empty($field_id)) {
29+
api_not_allowed();
30+
}
31+
if (!in_array($type, ExtraField::getValidExtraFieldTypes())) {
32+
api_not_allowed();
33+
}
34+
35+
$extraField = new ExtraField($type);
36+
$extraFieldInfo = $extraField->get($field_id);
37+
38+
$check = Security::check_token('request');
39+
$token = Security::get_token();
40+
41+
if ($action == 'add') {
42+
$interbreadcrumb[]=array('url' => 'extra_fields.php?type='.$extraField->type,'name' => $extraField->pageName);
43+
$interbreadcrumb[]=array('url' => 'extra_fields.php?type='.$extraField->type.'&action=edit&id='.$extraFieldInfo['id'],'name' => $extraFieldInfo['field_display_text']);
44+
$interbreadcrumb[]=array('url' => 'extra_field_options.php?type='.$extraField->type.'&field_id='.$extraFieldInfo['id'], 'name' => get_lang('EditExtraFieldOptions'));
45+
$interbreadcrumb[]=array('url' => '#','name' => get_lang('Add'));
46+
} elseif ($action == 'edit') {
47+
$interbreadcrumb[]=array('url' => 'extra_fields.php?type='.$extraField->type,'name' => $extraField->pageName);
48+
$interbreadcrumb[]=array('url' => 'extra_fields.php?type='.$extraField->type.'&action=edit&id='.$extraFieldInfo['id'],'name' => $extraFieldInfo['field_display_text']);
49+
$interbreadcrumb[]=array('url' => 'extra_field_options.php?type='.$extraField->type.'&field_id='.$extraFieldInfo['id'], 'name' => get_lang('EditExtraFieldOptions'));
50+
51+
$interbreadcrumb[]=array('url' => '#','name' => get_lang('Edit'));
52+
} else {
53+
$interbreadcrumb[]=array('url' => 'extra_fields.php?type='.$extraField->type,'name' => $extraField->pageName);
54+
$interbreadcrumb[]=array('url' => 'extra_fields.php?type='.$extraField->type.'&action=edit&id='.$extraFieldInfo['id'],'name' => $extraFieldInfo['field_display_text']);
55+
$interbreadcrumb[]=array('url' => '#','name' => get_lang('EditExtraFieldOptions'));
56+
}
57+
58+
$roleId = isset($_REQUEST['roleId']) ? $_REQUEST['roleId'] : null;
59+
60+
//jqgrid will use this URL to do the selects
61+
$params = 'field_id='.$field_id.'&type='.$extraField->type.'&roleId='.$roleId;
62+
$paramsNoRole = 'field_id='.$field_id.'&type='.$extraField->type;
63+
64+
//The order is important you need to check the the $column variable in the model.ajax.php file
65+
$columns = array(get_lang('Name'), get_lang('Value'), get_lang('Order'), get_lang('Actions'));
66+
67+
$htmlHeadXtra[]='<script>
68+
69+
function setHidden(obj) {
70+
var name = $(obj).attr("name");
71+
var hiddenName = "hidden_" + name;
72+
if ($("#" + hiddenName).attr("value") == 1) {
73+
$("#" + hiddenName).attr("value", 0);
74+
} else {
75+
$("#" + hiddenName).attr("value", 1);
76+
}
77+
}
78+
79+
function changeStatus(obj) {
80+
var roleId = $(obj).find(":selected").val();
81+
if (roleId != 0) {
82+
window.location.replace("'.api_get_self().'?'.$paramsNoRole.'&roleId="+roleId);
83+
}
84+
}
85+
$().ready( function() {
86+
$(".select_all").on("click", function() {
87+
$("#workflow :checkbox").prop("checked", 1);
88+
$("#workflow :hidden").prop("value", 1);
89+
return false;
90+
});
91+
$(".unselect_all").on("click", function() {
92+
$("#workflow :checkbox").prop("checked", 0);
93+
$("#workflow :hidden").prop("value", 0);
94+
return false;
95+
});
96+
});
97+
</script>';
98+
99+
// The header.
100+
Display::display_header($tool_name);
101+
102+
echo Display::page_header($extraFieldInfo['field_display_text']);
103+
104+
$obj = new ExtraFieldOption($type);
105+
$columns = array('option_display_text', 'option_value', 'option_order');
106+
$result = Database::select('*', $obj->table, array('where' => array("field_id = ? " => $field_id), 'order'=>"option_order ASC"));
107+
108+
$table = new HTML_Table(array('class' => 'data_table'));
109+
$column = 0;
110+
$row = 0;
111+
$table->setHeaderContents($row, $column, get_lang('CurrentStatus'));
112+
$column++;
113+
foreach ($result as $item) {
114+
$table->setHeaderContents($row, $column, $item['option_display_text']);
115+
$column++;
116+
}
117+
$row++;
118+
119+
$form = new FormValidator('workflow', 'post', api_get_self().'?'.$params);
120+
$options = api_get_user_roles();
121+
$options[0] = get_lang('SelectAnOption');
122+
ksort($options);
123+
$form->addElement('select', 'status', get_lang('SelectRole'), $options, array('onclick' => 'changeStatus(this)'));
124+
125+
$checks = $app['orm.em']->getRepository('ChamiloLMS\Entity\ExtraFieldOptionRelFieldOption')->findBy(array('fieldId' => $field_id, 'roleId' => $roleId));
126+
$includedFields = array();
127+
if (!empty($checks)) {
128+
foreach ($checks as $availableField) {
129+
$includedFields[$availableField->getFieldOptionId()][] = $availableField->getRelatedFieldOptionId();
130+
}
131+
}
132+
133+
foreach ($result as $item) {
134+
$column = 0;
135+
$table->setCellContents($row, $column, $item['option_display_text']);
136+
$column++;
137+
$value = null;
138+
139+
foreach ($result as $itemCol) {
140+
$id = 'extra_field_status_'.$item['id'].'_'.$itemCol['id'];
141+
$idForm = 'extra_field_status['.$item['id'].']['.$itemCol['id'].']';
142+
$attributes = array('onclick' => 'setHidden(this)');
143+
$value = 0;
144+
145+
if (isset($includedFields[$itemCol['id']]) && in_array($item['id'], $includedFields[$itemCol['id']])) {
146+
$value = 1;
147+
$attributes['checked'] = 'checked';
148+
}
149+
150+
$element = Display::input('checkbox', $id, null, $attributes);
151+
$table->setCellContents($row, $column, $element);
152+
$form->addElement('hidden', 'hidden_'.$idForm, $value, array('id' => 'hidden_'.$id));
153+
$column++;
154+
}
155+
$row++;
156+
}
157+
158+
if (!empty($roleId)) {
159+
$form->addElement('html', $table->toHtml());
160+
$group = array();
161+
$group[]= $form->createElement('button', 'submit', get_lang('Save'));
162+
$group[]= $form->createElement('button', 'select_all', get_lang('SelectAll'), array('class' => 'btn select_all'));
163+
$group[]= $form->createElement('button', 'unselect_all', get_lang('UnSelectAll'), array('class' => 'btn unselect_all'));
164+
$form->addGroup($group, '', null, ' ');
165+
166+
$form->setDefaults(array('status' => $roleId));
167+
} else {
168+
$form->addElement('button', 'submit', get_lang('Edit'));
169+
}
170+
171+
$form->display();
172+
173+
if ($form->validate()) {
174+
$values = $form->getSubmitValues();
175+
$result = $values['hidden_extra_field_status'];
176+
if (!empty($result)) {
177+
foreach ($result as $id => $items) {
178+
foreach ($items as $subItemId => $value) {
179+
$extraFieldOptionRelFieldOption = $app['orm.em']->getRepository('ChamiloLMS\Entity\ExtraFieldOptionRelFieldOption')->findOneBy(
180+
array(
181+
'fieldId' => $field_id,
182+
'fieldOptionId' => $subItemId,
183+
'roleId' => $roleId,
184+
'relatedFieldOptionId' => $id
185+
)
186+
);
187+
188+
if ($value == 1) {
189+
if (empty($extraFieldOptionRelFieldOption)) {
190+
$extraFieldOptionRelFieldOption = new \ChamiloLMS\Entity\ExtraFieldOptionRelFieldOption();
191+
$extraFieldOptionRelFieldOption->setFieldId($field_id);
192+
$extraFieldOptionRelFieldOption->setFieldOptionId($subItemId);
193+
$extraFieldOptionRelFieldOption->setRelatedFieldOptionId($id);
194+
$extraFieldOptionRelFieldOption->setRoleId($roleId);
195+
$app['orm.ems']['db_write']->persist($extraFieldOptionRelFieldOption);
196+
}
197+
} else {
198+
199+
if ($extraFieldOptionRelFieldOption) {
200+
$app['orm.ems']['db_write']->remove($extraFieldOptionRelFieldOption);
201+
}
202+
}
203+
204+
}
205+
}
206+
$app['orm.ems']['db_write']->flush();
207+
header('Location:'.api_get_self().'?'.$params);
208+
exit;
209+
}
210+
}
211+
212+
Display :: display_footer();

0 commit comments

Comments
 (0)