private function validateForm()
{
if ($this->frm->isSubmitted()) {
$this->frm->cleanupFields();
// get fields
$ddmGroup = $this->frm->getField('group');
$fileFile = $this->frm->getField('file');
$csv = array();
// validate input
$ddmGroup->isFilled(BL::getError('FieldIsRequired'));
if ($fileFile->isFilled(BL::err('FieldIsRequired'))) {
if ($fileFile->isAllowedExtension(array('csv'), sprintf(BL::getError('ExtensionNotAllowed'), 'csv'))) {
$csv = Csv::fileToArray($fileFile->getTempFileName());
if ($csv === false) {
$fileFile->addError(BL::getError('InvalidCSV'));
}
}
}
if ($this->frm->isCorrect()) {
// import the profiles
$overwrite = $this->frm->getField('overwrite_existing')->isChecked();
$statistics = BackendProfilesModel::importCsv($csv, $ddmGroup->getValue(), $overwrite);
// trigger event
BackendModel::triggerEvent($this->getModule(), 'after_import', array('statistics' => $statistics));
// build redirect url with the right message
$redirectUrl = BackendModel::createURLForAction('index') . '&report=';
$redirectUrl .= $overwrite ? 'profiles-imported-and-updated' : 'profiles-imported';
$redirectUrl .= '&var[]=' . $statistics['count']['inserted'];
$redirectUrl .= '&var[]=' . $statistics['count']['exists'];
// everything is saved, so redirect to the overview
$this->redirect($redirectUrl);
}
}
}