Merge branch 'MDL-55980-master' of https://github.com/sammarshallou/moodle
[moodle.git] / mod / data / tabs.php
blob62b2b88d5615bdf72ce3db88746cd2841be8fc85
1 <?php
2 ///////////////////////////////////////////////////////////////////////////
3 // //
4 // NOTICE OF COPYRIGHT //
5 // //
6 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
7 // http://moodle.org //
8 // //
9 // Copyright (C) 2005 Martin Dougiamas http://dougiamas.com //
10 // //
11 // This program is free software; you can redistribute it and/or modify //
12 // it under the terms of the GNU General Public License as published by //
13 // the Free Software Foundation; either version 2 of the License, or //
14 // (at your option) any later version. //
15 // //
16 // This program is distributed in the hope that it will be useful, //
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
19 // GNU General Public License for more details: //
20 // //
21 // http://www.gnu.org/copyleft/gpl.html //
22 // //
23 ///////////////////////////////////////////////////////////////////////////
25 // This file to be included so we can assume config.php has already been included.
26 // We also assume that $user, $course, $currenttab have been set
29 if (empty($currenttab) or empty($data) or empty($course)) {
30 print_error('cannotcallscript');
33 $context = context_module::instance($cm->id);
35 $row = array();
37 $row[] = new tabobject('list', new moodle_url('/mod/data/view.php', array('d' => $data->id)), get_string('list','data'));
39 if (isset($record)) {
40 $row[] = new tabobject('single', new moodle_url('/mod/data/view.php', array('d' => $data->id, 'rid' => $record->id)), get_string('single','data'));
41 } else {
42 $row[] = new tabobject('single', new moodle_url('/mod/data/view.php', array('d' => $data->id, 'mode' => 'single')), get_string('single','data'));
45 // Add an advanced search tab.
46 $row[] = new tabobject('asearch', new moodle_url('/mod/data/view.php', array('d' => $data->id, 'mode' => 'asearch')), get_string('search', 'data'));
48 if (isloggedin()) { // just a perf shortcut
49 if (data_user_can_add_entry($data, $currentgroup, $groupmode, $context)) { // took out participation list here!
50 $addstring = empty($editentry) ? get_string('add', 'data') : get_string('editentry', 'data');
51 $row[] = new tabobject('add', new moodle_url('/mod/data/edit.php', array('d' => $data->id)), $addstring);
53 if (has_capability(DATA_CAP_EXPORT, $context)) {
54 // The capability required to Export database records is centrally defined in 'lib.php'
55 // and should be weaker than those required to edit Templates, Fields and Presets.
56 $row[] = new tabobject('export', new moodle_url('/mod/data/export.php', array('d' => $data->id)),
57 get_string('export', 'data'));
59 if (has_capability('mod/data:managetemplates', $context)) {
60 if ($currenttab == 'list') {
61 $defaultemplate = 'listtemplate';
62 } else if ($currenttab == 'add') {
63 $defaultemplate = 'addtemplate';
64 } else if ($currenttab == 'asearch') {
65 $defaultemplate = 'asearchtemplate';
66 } else {
67 $defaultemplate = 'singletemplate';
70 $templatestab = new tabobject('templates', new moodle_url('/mod/data/templates.php', array('d' => $data->id, 'mode' => $defaultemplate)),
71 get_string('templates','data'));
72 $row[] = $templatestab;
73 $row[] = new tabobject('fields', new moodle_url('/mod/data/field.php', array('d' => $data->id)),
74 get_string('fields','data'));
75 $row[] = new tabobject('presets', new moodle_url('/mod/data/preset.php', array('d' => $data->id)),
76 get_string('presets', 'data'));
80 if ($currenttab == 'templates' and isset($mode) && isset($templatestab)) {
81 $templatestab->inactive = true;
82 $templatelist = array ('listtemplate', 'singletemplate', 'asearchtemplate', 'addtemplate', 'rsstemplate', 'csstemplate', 'jstemplate');
84 $currenttab ='';
85 foreach ($templatelist as $template) {
86 $templatestab->subtree[] = new tabobject($template, new moodle_url('/mod/data/templates.php', array('d' => $data->id, 'mode' => $template)), get_string($template, 'data'));
87 if ($template == $mode) {
88 $currenttab = $template;
91 if ($currenttab == '') {
92 $currenttab = $mode = 'singletemplate';
96 // Print out the tabs and continue!
97 echo $OUTPUT->tabtree($row, $currenttab);