Example #1
0
            if (array_key_exists('deleteMissing', $rule)) {
                $requestRules[$ruleName]['deleteMissing'] = false;
            }
        }
        if (!isset($requestRules[$ruleName]['updateExisting']) && isset($rule['updateExisting'])) {
            $requestRules[$ruleName]['updateExisting'] = false;
        }
        if (!isset($requestRules[$ruleName]['createMissing']) && isset($rule['createMissing'])) {
            $requestRules[$ruleName]['createMissing'] = false;
        }
        if (!isset($requestRules[$ruleName]['deleteMissing']) && isset($rule['deleteMissing'])) {
            $requestRules[$ruleName]['deleteMissing'] = false;
        }
    }
    $data['rules'] = $requestRules;
}
if (isset($_FILES['import_file'])) {
    $result = false;
    // CUploadFile throws exceptions, so we need to catch them
    try {
        $file = new CUploadFile($_FILES['import_file']);
        $result = API::Configuration()->import(['format' => CImportReaderFactory::fileExt2ImportFormat($file->getExtension()), 'source' => $file->getContent(), 'rules' => $data['rules']]);
    } catch (Exception $e) {
        error($e->getMessage());
    }
    show_messages($result, _('Imported successfully'), _('Import failed'));
}
$view = new CView('conf.import', $data);
$view->render();
$view->show();
require_once dirname(__FILE__) . '/include/page_footer.php';
Example #2
0
}
/*
 * Actions
 */
if (hasRequest('add') || hasRequest('update')) {
    if (hasRequest('update')) {
        $msgOk = _('Image updated');
        $msgFail = _('Cannot update image');
    } else {
        $msgOk = _('Image added');
        $msgFail = _('Cannot add image');
    }
    try {
        DBstart();
        if (isset($_FILES['image'])) {
            $file = new CUploadFile($_FILES['image']);
            $image = null;
            if ($file->wasUploaded()) {
                $file->validateImageSize();
                $image = base64_encode($file->getContent());
            }
        }
        if (hasRequest('update')) {
            $result = API::Image()->update(['imageid' => getRequest('imageid'), 'name' => getRequest('name'), 'image' => $image]);
            $audit_action = 'Image [' . getRequest('name') . '] updated';
        } else {
            $result = API::Image()->create(['name' => $_REQUEST['name'], 'imagetype' => $_REQUEST['imagetype'], 'image' => $image]);
            $audit_action = 'Image [' . $_REQUEST['name'] . '] added';
        }
        if ($result) {
            add_audit(AUDIT_ACTION_UPDATE, AUDIT_RESOURCE_IMAGE, $audit_action);
                $requestRules[$ruleName]['updateExisting'] = false;
            }
            if (isset($rule['createMissing'])) {
                $requestRules[$ruleName]['createMissing'] = false;
            }
        } elseif (!isset($requestRules[$ruleName]['updateExisting']) && isset($rule['updateExisting'])) {
            $requestRules[$ruleName]['updateExisting'] = false;
        } elseif (!isset($requestRules[$ruleName]['createMissing']) && isset($rule['createMissing'])) {
            $requestRules[$ruleName]['createMissing'] = false;
        }
    }
    $data['rules'] = $requestRules;
}
if (isset($_FILES['import_file'])) {
    try {
        $file = new CUploadFile($_FILES['import_file']);
        $importFormat = CImportReaderFactory::fileExt2ImportFormat($file->getExtension());
        $importReader = CImportReaderFactory::getReader($importFormat);
        $configurationImport = new CConfigurationImport($file->getContent(), $data['rules']);
        $configurationImport->setReader($importReader);
        $configurationImport->import();
        show_messages(true, _('Imported successfully'));
    } catch (Exception $e) {
        error($e->getMessage());
        show_messages(false, null, _('Import failed'));
    }
}
$view = new CView('conf.import', $data);
$view->render();
$view->show();
require_once 'include/page_footer.php';