ini_set('max_execution_time', '3600');
util_assertModerator(PRIV_LOC);
util_assertNotMirror();
DebugInfo::disable();
$modelType = util_getRequestParameter('modelType');
$modelNumber = util_getRequestParameter('modelNumber');
$previewButton = util_getRequestParameter('previewButton');
$confirmButton = util_getRequestParameter('confirmButton');
$modelType = ModelType::canonicalize($modelType);
$inflections = Model::factory('Inflection')->where('modelType', $modelType)->order_by_asc('rank')->find_many();
// Load the original data
$model = Model::factory('FlexModel')->where('modelType', $modelType)->where('number', $modelNumber)->find_one();
$exponent = $model->exponent;
$lexem = Lexem::create($exponent, $modelType, $modelNumber, '');
$ifs = $lexem->generateParadigm();
$mdMap = ModelDescription::getByModelIdMapByInflectionIdVariantApplOrder($model->id);
$forms = array();
foreach ($inflections as $infl) {
    $forms[$infl->id] = array();
}
foreach ($ifs as $if) {
    $forms[$if->inflectionId][] = array('form' => $if->form, 'isLoc' => $mdMap[$if->inflectionId][$if->variant][0]->isLoc, 'recommended' => $mdMap[$if->inflectionId][$if->variant][0]->recommended);
}
$participleNumber = $modelType == 'V' ? ParticipleModel::loadByVerbModel($modelNumber)->adjectiveModel : '';
if ($previewButton || $confirmButton) {
    // Load the new forms and exponent;
    $newModelNumber = util_getRequestParameter('newModelNumber');
    $newExponent = util_getRequestParameter('newExponent');
    $newDescription = util_getRequestParameter('newDescription');
    $newParticipleNumber = util_getRequestParameter('newParticipleNumber');
    $newForms = array();