Skip to content

Commit cc02afc

Browse files
committed
Add setting "allow_session_admin_read_careers" see BT#12861
- Setting allows session admins to get "read" access to careers. - Rework careers.php to use Display::addFlash
1 parent 2ca5df0 commit cc02afc

File tree

7 files changed

+147
-82
lines changed

7 files changed

+147
-82
lines changed

main/admin/career_dashboard.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88

99
$cidReset = true;
1010
require_once __DIR__.'/../inc/global.inc.php';
11-
api_protect_admin_script();
11+
12+
$allowCareer = api_get_configuration_value('allow_session_admin_read_careers');
13+
14+
api_protect_admin_script($allowCareer);
1215

1316
$this_section = SECTION_PLATFORM_ADMIN;
1417

@@ -74,15 +77,18 @@
7477
),
7578
'careers.php'
7679
);
77-
$actionLeft .= Display::url(
78-
Display::return_icon(
79-
'promotion.png',
80-
get_lang('Promotions'),
81-
null,
82-
ICON_SIZE_MEDIUM
83-
),
84-
'promotions.php'
85-
);
80+
81+
if (api_is_platform_admin()) {
82+
$actionLeft .= Display::url(
83+
Display::return_icon(
84+
'promotion.png',
85+
get_lang('Promotions'),
86+
null,
87+
ICON_SIZE_MEDIUM
88+
),
89+
'promotions.php'
90+
);
91+
}
8692

8793
$actions = Display::toolbarAction('toolbar-career', array($actionLeft));
8894
$html .= $form->returnForm();

main/admin/career_diagram.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525

2626
$this_section = SECTION_PLATFORM_ADMIN;
2727

28-
api_protect_admin_script();
28+
$allowCareer = api_get_configuration_value('allow_session_admin_read_careers');
29+
api_protect_admin_script($allowCareer);
2930

3031
$htmlHeadXtra[] = api_get_js('jsplumb2.js');
3132

main/admin/careers.php

Lines changed: 100 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212

1313
$this_section = SECTION_PLATFORM_ADMIN;
1414

15-
api_protect_admin_script();
15+
$allowCareer = api_get_configuration_value('allow_session_admin_read_careers');
16+
api_protect_admin_script($allowCareer);
1617

17-
//Add the JS needed to use the jqgrid
18+
// Add the JS needed to use the jqgrid
1819
$htmlHeadXtra[] = api_get_jqgrid_js();
1920

2021
// setting breadcrumbs
@@ -43,8 +44,7 @@
4344
$tool_name = get_lang('Careers');
4445
}
4546

46-
// The header.
47-
Display::display_header($tool_name);
47+
4848

4949
//jqgrid will use this URL to do the selects
5050
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_careers';
@@ -87,69 +87,67 @@
8787
$diagramLink = '<a href="'.api_get_path(WEB_CODE_PATH).'admin/career_diagram.php?id=\'+options.rowId+\'">'.get_lang('Diagram').'</a>';
8888
}
8989

90-
//With this function we can add actions to the jgrid (edit, delete, etc)
91-
$action_links = 'function action_formatter(cellvalue, options, rowObject) {
92-
return \'<a href="?action=edit&id=\'+options.rowId+\'">'.Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL).'</a>'.
93-
$diagramLink.
94-
'&nbsp;<a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES))."\'".')) return false;" href="?sec_token='.$token.'&action=copy&id=\'+options.rowId+\'">'.Display::return_icon('copy.png', get_lang('Copy'), '', ICON_SIZE_SMALL).'</a>'.
95-
'&nbsp;<a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES))."\'".')) return false;" href="?sec_token='.$token.'&action=delete&id=\'+options.rowId+\'">'.Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).'</a>'.
96-
'\';
97-
}';
98-
?>
99-
<script>
100-
$(function() {
101-
<?php
102-
// grid definition see the $career->display() function
103-
echo Display::grid_js(
104-
'careers',
105-
$url,
106-
$columns,
107-
$column_model,
108-
$extra_params,
109-
array(),
110-
$action_links,
111-
true
112-
);
113-
?>
114-
});
115-
</script>
116-
<?php
90+
// With this function we can add actions to the jgrid (edit, delete, etc)
91+
if (api_is_platform_admin()) {
92+
$actionLinks = 'function action_formatter(cellvalue, options, rowObject) {
93+
return \'<a href="?action=edit&id=\'+options.rowId+\'">'.Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL).'</a>'.
94+
$diagramLink.
95+
'&nbsp;<a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES))."\'".')) return false;" href="?sec_token='.$token.'&action=copy&id=\'+options.rowId+\'">'.Display::return_icon('copy.png', get_lang('Copy'), '', ICON_SIZE_SMALL).'</a>'.
96+
'&nbsp;<a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES))."\'".')) return false;" href="?sec_token='.$token.'&action=delete&id=\'+options.rowId+\'">'.Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).'</a>'.
97+
'\';
98+
}';
99+
} else {
100+
$actionLinks = "function action_formatter(cellvalue, options, rowObject) {
101+
return '".$diagramLink."';
102+
}";
103+
}
104+
105+
117106
$career = new Career();
107+
$content = '';
108+
109+
$listUrl = api_get_self();
118110

119111
// Action handling: Add
120112
switch ($action) {
121113
case 'add':
114+
api_protect_admin_script();
115+
122116
if (api_get_session_id() != 0 &&
123117
!api_is_allowed_to_session_edit(false, true)
124118
) {
125119
api_not_allowed();
126120
}
127121
Session::write('notebook_view', 'creation_date');
128122

129-
$url = api_get_self().'?action='.Security::remove_XSS($_GET['action']);
123+
$url = api_get_self().'?action='.Security::remove_XSS($_GET['action']);
130124
$form = $career->return_form($url, 'add');
131125

132126
// The validation or display
133127
if ($form->validate()) {
134128
if ($check) {
135129
$values = $form->exportValues();
136-
$res = $career->save($values);
130+
$res = $career->save($values);
137131
if ($res) {
138-
echo Display::return_message(get_lang('ItemAdded'), 'confirmation');
132+
Display::addFlash(
133+
Display::return_message(get_lang('ItemAdded'), 'confirmation')
134+
);
139135
}
140136
}
141-
$career->display();
137+
header('Location: '.$listUrl);
138+
exit;
142139
} else {
143-
echo '<div class="actions">';
144-
echo '<a href="'.api_get_self().'">'.
140+
$content .= '<div class="actions">';
141+
$content .= '<a href="'.api_get_self().'">'.
145142
Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).'</a>';
146-
echo '</div>';
143+
$content .= '</div>';
147144
$form->addElement('hidden', 'sec_token');
148145
$form->setConstants(array('sec_token' => $token));
149-
$form->display();
146+
$content .= $form->returnForm();
150147
}
151148
break;
152149
case 'edit':
150+
api_protect_admin_script();
153151
// Action handling: Editing
154152
$url = api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&id='.intval($_GET['id']);
155153
$form = $career->return_form($url, 'edit');
@@ -162,56 +160,98 @@
162160
$old_status = $career->get_status($values['id']);
163161
$res = $career->update($values);
164162
if ($res) {
165-
echo Display::return_message(get_lang('CareerUpdated'), 'confirmation');
163+
Display::addFlash(
164+
Display::return_message(get_lang('CareerUpdated'), 'confirmation')
165+
);
166166
if ($values['status'] && !$old_status) {
167-
echo Display::return_message(
168-
sprintf(get_lang('CareerXUnarchived'), $values['name']),
169-
'confirmation',
170-
false
167+
Display::addFlash(
168+
Display::return_message(
169+
sprintf(get_lang('CareerXUnarchived'), $values['name']),
170+
'confirmation',
171+
false
172+
)
171173
);
172174
} elseif (!$values['status'] && $old_status) {
173-
echo Display::return_message(
174-
sprintf(get_lang('CareerXArchived'), $values['name']),
175-
'confirmation',
176-
false
175+
Display::addFlash(
176+
Display::return_message(
177+
sprintf(get_lang('CareerXArchived'), $values['name']),
178+
'confirmation',
179+
false
180+
)
177181
);
178182
}
179183
}
180184
}
181-
$career->display();
185+
header('Location: '.$listUrl);
186+
exit;
182187
} else {
183-
echo '<div class="actions">';
184-
echo '<a href="'.api_get_self().'">'.Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).'</a>';
185-
echo '</div>';
188+
$content .= '<div class="actions">';
189+
$content .= '<a href="'.api_get_self().'">'.Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).'</a>';
190+
$content .= '</div>';
186191
$form->addElement('hidden', 'sec_token');
187192
$form->setConstants(array('sec_token' => $token));
188-
$form->display();
193+
$content .= $form->returnForm();
189194
}
190195
break;
191196
case 'delete':
197+
api_protect_admin_script();
192198
// Action handling: delete
193199
if ($check) {
194200
$res = $career->delete($_GET['id']);
195201
if ($res) {
196-
echo Display::return_message(get_lang('ItemDeleted'), 'confirmation');
202+
Display::addFlash(
203+
Display::return_message(get_lang('ItemDeleted'), 'confirmation')
204+
);
197205
}
198206
}
199-
$career->display();
207+
header('Location: '.$listUrl);
208+
exit;
200209
break;
201210
case 'copy':
211+
api_protect_admin_script();
202212
if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
203-
api_not_allowed();
213+
api_not_allowed(true);
204214
}
205215
if ($check) {
206216
$res = $career->copy($_GET['id'], true); //copy career and promotions inside
207217
if ($res) {
208-
echo Display::return_message(get_lang('ItemCopied'), 'confirmation');
218+
Display::addFlash(
219+
Display::return_message(get_lang('ItemCopied'), 'confirmation')
220+
);
209221
}
210222
}
211-
$career->display();
223+
224+
header('Location: '.$listUrl);
225+
exit;
212226
break;
213227
default:
214-
$career->display();
228+
$content = $career->display();
215229
break;
216230
}
217-
Display :: display_footer();
231+
232+
// The header.
233+
Display::display_header($tool_name);
234+
235+
?>
236+
<script>
237+
$(function() {
238+
<?php
239+
// grid definition see the $career->display() function
240+
echo Display::grid_js(
241+
'careers',
242+
$url,
243+
$columns,
244+
$column_model,
245+
$extra_params,
246+
array(),
247+
$actionLinks,
248+
true
249+
);
250+
?>
251+
});
252+
</script>
253+
<?php
254+
255+
echo $content;
256+
257+
Display::display_footer();

main/admin/index.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,9 @@
330330
);
331331
}
332332

333-
if (api_is_platform_admin()) {
333+
$allowCareer = api_get_configuration_value('allow_session_admin_read_careers');
334+
335+
if (api_is_platform_admin() || ($allowCareer && api_is_session_admin())) {
334336
// option only visible in development mode. Enable through code if required
335337
if (is_dir(api_get_path(SYS_TEST_PATH).'datafiller/')) {
336338
$items[] = array('url' => 'user_move_stats.php', 'label' => get_lang('MoveUserStats'));

main/inc/lib/career.lib.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,20 @@ public function update_all_promotion_status_by_career_id($career_id, $status)
7575
}
7676

7777
/**
78-
* Displays the title + grid
78+
* Returns HTML the title + grid
79+
* @return string
7980
*/
8081
public function display()
8182
{
82-
echo '<div class="actions" style="margin-bottom:20px">';
83-
echo '<a href="career_dashboard.php">'.
83+
$html = '<div class="actions" style="margin-bottom:20px">';
84+
$html .= '<a href="career_dashboard.php">'.
8485
Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).'</a>';
85-
echo '<a href="'.api_get_self().'?action=add">'.
86+
$html .= '<a href="'.api_get_self().'?action=add">'.
8687
Display::return_icon('new_career.png', get_lang('Add'), '', ICON_SIZE_MEDIUM).'</a>';
87-
echo '</div>';
88-
echo Display::grid_html('careers');
88+
$html .= '</div>';
89+
$html .= Display::grid_html('careers');
90+
91+
return $html;
8992
}
9093

9194
/**

main/install/configuration.dist.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,3 +691,6 @@
691691
];*/
692692
// Hide the session list in Reporting tool. Useful when a course has too many sessions.
693693
//$_configuration['hide_reporting_session_list'] = false;
694+
695+
// Allow session admin to read careers
696+
//$_configuration['allow_session_admin_read_careers'] = true;

main/template/default/admin/career_dashboard.tpl

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@
66
{% for item in data %}
77
<div id="career-{{ item.id }}" class="career panel panel-default">
88
<div class="panel-heading">
9-
<h4><a href="{{ _p.web }}main/admin/careers.php?action=edit&id={{ item.id }}">{{ item.name }}</a></h4>
9+
<h4>
10+
{% if _u.is_admin %}
11+
<a href="{{ _p.web }}main/admin/careers.php?action=edit&id={{ item.id }}">
12+
{{ item.name }}
13+
</a>
14+
{% else %}
15+
{{ item.name }}
16+
{% endif %}
17+
</h4>
1018
</div>
1119
<div class="panel-body">
1220
{{ item.description }}
@@ -20,7 +28,6 @@
2028
{% for prom in promotions %}
2129
{% set line = prom.sessions|length + 1 %}
2230
<tr>
23-
2431
<td class="promo" rowspan="{{ line }}">
2532
<h4 id="promotion-id-{{ prom.id }}">
2633
<a title="{{ prom.name }}" href="{{ _p.web }}main/admin/promotions.php?action=edit&id={{ prom.id }}">
@@ -45,7 +52,11 @@
4552
<td class="courses">
4653
<ul>
4754
{% for course in session.courses %}
48-
<li><a href="{{ _p.web }}courses/{{ course.directory }}/index.php?id_session={{ sessionid }}" title="{{ course.title }}">{{ course.title }}</a></li>
55+
<li>
56+
<a href="{{ _p.web }}courses/{{ course.directory }}/index.php?id_session={{ sessionid }}" title="{{ course.title }}">
57+
{{ course.title }}
58+
</a>
59+
</li>
4960
{% endfor %}
5061
</ul>
5162
</td>
@@ -57,5 +68,4 @@
5768
</div>
5869
</div>
5970
{% endfor %}
60-
6171
{% endblock %}

0 commit comments

Comments
 (0)