1 | <?php |
||
2 | |||
3 | /* For licensing terms, see /license.txt */ |
||
4 | |||
5 | /** |
||
6 | * Main page for the group module. |
||
7 | * This script displays the general group settings, |
||
8 | * and a list of groups with buttons to view, edit... |
||
9 | * |
||
10 | * @author Thomas Depraetere, Hugues Peeters, Christophe Gesche: initial versions |
||
11 | * @author Bert Vanderkimpen, improved self-unsubscribe for cvs |
||
12 | * @author Patrick Cool, show group comment under the group name |
||
13 | * @author Roan Embrechts, initial self-unsubscribe code, code cleaning, virtual course support |
||
14 | * @author Bart Mollet, code cleaning, use of Display-library, list of courseAdmin-tools, use of GroupManager |
||
15 | */ |
||
16 | require_once __DIR__.'/../inc/global.inc.php'; |
||
17 | $this_section = SECTION_COURSES; |
||
18 | $current_course_tool = TOOL_GROUP; |
||
19 | |||
20 | // Notice for unauthorized people. |
||
21 | api_protect_course_script(true); |
||
22 | |||
23 | $nameTools = get_lang('GroupOverview'); |
||
24 | $courseId = api_get_course_int_id(); |
||
25 | $courseInfo = api_get_course_info(); |
||
26 | |||
27 | $groupId = isset($_GET['id']) ? (int) $_GET['id'] : 0; |
||
28 | $keyword = isset($_GET['keyword']) ? $_GET['keyword'] : ''; |
||
29 | |||
30 | if (isset($_GET['action'])) { |
||
31 | switch ($_GET['action']) { |
||
32 | case 'export_surveys': |
||
33 | $extraFieldValue = new ExtraFieldValue('survey'); |
||
34 | $surveyList = $extraFieldValue->get_item_id_from_field_variable_and_field_value( |
||
35 | 'group_id', |
||
36 | $groupId, |
||
37 | false, |
||
38 | false, |
||
39 | true |
||
40 | ); |
||
41 | |||
42 | if (!empty($surveyList)) { |
||
43 | $exportList = []; |
||
44 | foreach ($surveyList as $data) { |
||
45 | $surveyId = $data['item_id']; |
||
46 | $surveyData = SurveyManager::get_survey($surveyId, 0, api_get_course_id()); |
||
47 | if (!empty($surveyData)) { |
||
48 | $filename = $surveyData['code'].'.xlsx'; |
||
49 | $exportList[] = @SurveyUtil::export_complete_report_xls($surveyData, $filename, 0, true); |
||
50 | } |
||
51 | } |
||
52 | |||
53 | if (!empty($exportList)) { |
||
54 | $tempZipFile = api_get_path(SYS_ARCHIVE_PATH).api_get_unique_id().'.zip'; |
||
55 | $zip = new PclZip($tempZipFile); |
||
56 | foreach ($exportList as $file) { |
||
57 | $zip->add($file, PCLZIP_OPT_REMOVE_ALL_PATH); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
58 | } |
||
59 | |||
60 | DocumentManager::file_send_for_download( |
||
61 | $tempZipFile, |
||
62 | true, |
||
63 | get_lang('SurveysWordInASCII').'-'.api_get_course_id().'-'.api_get_local_time().'.zip' |
||
64 | ); |
||
65 | unlink($tempZipFile); |
||
66 | exit; |
||
67 | } |
||
68 | } |
||
69 | |||
70 | Display::addFlash(Display::return_message(get_lang('NoSurveyAvailable'))); |
||
71 | |||
72 | header('Location: '.api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq()); |
||
73 | exit; |
||
74 | |||
75 | break; |
||
76 | case 'export_all': |
||
77 | $data = GroupManager::exportCategoriesAndGroupsToArray(null, true); |
||
78 | switch ($_GET['type']) { |
||
79 | case 'csv': |
||
80 | Export::arrayToCsv($data); |
||
81 | exit; |
||
82 | break; |
||
83 | case 'xls': |
||
84 | if (!empty($data)) { |
||
85 | Export::arrayToXls($data); |
||
86 | exit; |
||
87 | } |
||
88 | break; |
||
89 | } |
||
90 | exit; |
||
91 | break; |
||
92 | case 'export_pdf': |
||
93 | $content = GroupManager::getOverview($courseId, $keyword); |
||
94 | $pdf = new PDF(); |
||
95 | $extra = '<div style="text-align:center"><h2>'.get_lang('GroupList').'</h2></div>'; |
||
96 | $extra .= '<strong>'.get_lang('Course').': </strong>'.$courseInfo['title'].' ('.$courseInfo['code'].')'; |
||
97 | |||
98 | $content = $extra.$content; |
||
99 | $pdf->content_to_pdf($content, null, null, api_get_course_id()); |
||
100 | break; |
||
101 | case 'export': |
||
102 | $data = GroupManager::exportCategoriesAndGroupsToArray($groupId, true); |
||
103 | switch ($_GET['type']) { |
||
104 | case 'csv': |
||
105 | Export::arrayToCsv($data); |
||
106 | exit; |
||
107 | break; |
||
108 | case 'xls': |
||
109 | if (!empty($data)) { |
||
110 | Export::arrayToXls($data); |
||
111 | exit; |
||
112 | } |
||
113 | break; |
||
114 | } |
||
115 | break; |
||
116 | case 'export_users': |
||
117 | $data = GroupManager::exportStudentsToArray($groupId, true); |
||
118 | Export::arrayToCsv($data); |
||
119 | exit; |
||
120 | break; |
||
121 | } |
||
122 | } |
||
123 | |||
124 | $interbreadcrumb[] = ['url' => 'group.php?'.api_get_cidreq(), 'name' => get_lang('Groups')]; |
||
125 | $origin = api_get_origin(); |
||
126 | if ('learnpath' != $origin) { |
||
127 | // So we are not in learnpath tool |
||
128 | if (!api_is_allowed_in_course()) { |
||
129 | api_not_allowed(true); |
||
130 | } |
||
131 | if (!api_is_allowed_to_edit(false, true)) { |
||
132 | api_not_allowed(true); |
||
133 | } else { |
||
134 | Display::display_header($nameTools, 'Group'); |
||
135 | Display::display_introduction_section(TOOL_GROUP); |
||
136 | } |
||
137 | } else { |
||
138 | Display::display_reduced_header(); |
||
139 | } |
||
140 | |||
141 | $actions = '<a href="group_creation.php?'.api_get_cidreq().'">'. |
||
142 | Display::return_icon('add.png', get_lang('NewGroupCreate'), '', ICON_SIZE_MEDIUM).'</a>'; |
||
143 | |||
144 | if (api_get_setting('allow_group_categories') === 'true') { |
||
145 | $actions .= '<a href="group_category.php?'.api_get_cidreq().'&action=add_category">'. |
||
146 | Display::return_icon('new_folder.png', get_lang('AddCategory'), '', ICON_SIZE_MEDIUM).'</a>'; |
||
147 | } else { |
||
148 | $actions .= '<a href="group_category.php?'.api_get_cidreq().'&id=2">'. |
||
149 | Display::return_icon('settings.png', get_lang('PropModify'), '', ICON_SIZE_MEDIUM).'</a>'; |
||
150 | } |
||
151 | $actions .= '<a href="import.php?'.api_get_cidreq().'&action=import">'. |
||
152 | Display::return_icon('import_csv.png', get_lang('Import'), '', ICON_SIZE_MEDIUM).'</a>'; |
||
153 | |||
154 | $actions .= '<a href="group_overview.php?'.api_get_cidreq().'&action=export_all&type=csv">'. |
||
155 | Display::return_icon('export_csv.png', get_lang('Export'), '', ICON_SIZE_MEDIUM).'</a>'; |
||
156 | |||
157 | $actions .= '<a href="group_overview.php?'.api_get_cidreq().'&action=export&type=xls">'. |
||
158 | Display::return_icon('export_excel.png', get_lang('ExportAsXLS'), '', ICON_SIZE_MEDIUM).'</a>'; |
||
159 | |||
160 | $actions .= '<a href="group_overview.php?'.api_get_cidreq().'&action=export_pdf">'. |
||
161 | Display::return_icon('pdf.png', get_lang('ExportToPDF'), '', ICON_SIZE_MEDIUM).'</a>'; |
||
162 | |||
163 | $actions .= '<a href="group.php?'.api_get_cidreq().'">'. |
||
164 | Display::return_icon('group.png', get_lang('Groups'), '', ICON_SIZE_MEDIUM).'</a>'; |
||
165 | |||
166 | $actions .= '<a href="../user/user.php?'.api_get_cidreq().'">'. |
||
167 | Display::return_icon('user.png', get_lang('GoTo').' '.get_lang('Users'), '', ICON_SIZE_MEDIUM).'</a>'; |
||
168 | |||
169 | // Action links |
||
170 | echo Display::toolbarAction('actions', [$actions, GroupManager::getSearchForm()]); |
||
171 | echo GroupManager::getOverview($courseId, $keyword); |
||
172 | |||
173 | if ('learnpath' !== $origin) { |
||
174 | Display::display_footer(); |
||
175 | } |
||
176 |