<?php
if (empty($scriptProperties['name'])) {
    $modx->error->addField('name',$modx->lexicon('trosk.parametar_err_ns_name'));
} else {
    $alreadyExists = $modx->getObject('param',array('name' => $scriptProperties['name']));
    if ($alreadyExists) {
        $modx->error->addField('name',$modx->lexicon('trosk.parametar_err_ae'));
    }
}

if (empty($scriptProperties['values'])) {
    $modx->error->addField('values',$modx->lexicon('trosk.parametar_err_ns_values'));
}

if (empty($scriptProperties['type'])) {
    $modx->error->addField('type',$modx->lexicon('trosk.parametar_err_ns_tip'));
}

if ($modx->error->hasError()) { return $modx->error->failure(); }
 
$param = $modx->newObject('params');
$param->fromArray($scriptProperties);
 
if ($param->save() == false) {
    return $modx->error->failure($modx->lexicon('trosk.parametar_err_save'));
}
 
return $modx->error->success('',$param);