'group.php?'.api_get_cidreq(), 'name' => get_lang('Groups'), ]; $form = new FormValidator( 'import', 'post', api_get_self().'?'.api_get_cidreq() ); $form->addElement('header', get_lang('Import groups')); $form->addElement('file', 'file', get_lang('CSV file import location')); $form->addRule('file', get_lang('Required field'), 'required'); $form->addElement( 'checkbox', 'delete_not_in_file', null, get_lang('Delete items not in file') ); $form->addElement( 'label', null, Display::url( get_lang('Example CSV file'), api_get_path(WEB_CODE_PATH).'group/example.csv', ['download' => true] ) ); $form->addButtonImport(get_lang('Import')); if ($form->validate()) { if (isset($_FILES['file']['tmp_name']) && !empty($_FILES['file']['tmp_name']) ) { $groupData = Import::csv_reader($_FILES['file']['tmp_name']); $deleteNotInArray = $form->getSubmitValue('delete_not_in_file') == 1 ? true : false; $result = GroupManager::importCategoriesAndGroupsFromArray( $groupData, $deleteNotInArray ); if (!empty($result)) { $html = null; foreach ($result as $status => $data) { if ($status != 'error') { if (empty($data['category']) && empty($data['group'])) { continue; } } $html .= "

".get_lang(ucfirst($status)).'

'; if (!empty($data['category'])) { $html .= "

".get_lang('Categories').':

'; foreach ($data['category'] as $category) { $html .= "
".$category['category']."
"; } } if (!empty($data['group'])) { $html .= "

".get_lang('Groups').':

'; foreach ($data['group'] as $group) { $html .= "
".$group['group']."
"; } } if ($status == 'error') { if (!empty($data)) { foreach ($data as $message) { if (!empty($message)) { $html .= "
".$message."
"; } } } } } Display::addFlash( Display::return_message($html, 'information', false) ); header('Location: '.api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq()); exit; } } } Display::display_header($nameTools, 'Group'); $form->display(); Display::display_footer();