<?php
if (!class_exists('nc_core')) {
    die;
}
?>
<div class="nc_admin_fieldset_head"><?= !empty($campaign_id) ? NETCAT_MODULE_SERVICES_DIRECT_CAMPAIGN_EDIT : NETCAT_MODULE_SERVICES_DIRECT_CAMPAIGN_ADD; ?></div>
<?php
$form = $ui->form("?controller=$controller_name")->vertical();
$form->add()->input('hidden', 'action', 'save_campaign');
$form->add()->input('hidden', 'data[CampaignID]', (!empty($campaign_id) ? $campaign_id : 0));

$form->add_row(NETCAT_MODULE_SERVICES_DIRECT_CAMPAIGN_NAME)->horizontal()
  ->string('data[Name]', $campaign['Name']);

$form->add_row(NETCAT_MODULE_SERVICES_DIRECT_CAMPAIGN_FIO)->horizontal()
  ->string('data[FIO]', $campaign['FIO']);

$form->add_row(NETCAT_MODULE_SERVICES_DIRECT_CAMPAIGN_NOTIFICATIONS)->horizontal()->large();
$form->add_row(NETCAT_MODULE_SERVICES_DIRECT_CAMPAIGN_NOTIFICATIONS_EMAIL)->horizontal()
  ->string('data[EmailNotification][Email]', $campaign['EmailNotification']['Email']);
$form->add_row(NETCAT_MODULE_SERVICES_DIRECT_CAMPAIGN_NOTIFICATIONS_WARNPLACEINTERVAL)->horizontal()
  ->select('data[EmailNotification][WarnPlaceInterval]', array(15 => 15, 30 => 30, 60 => 60), $campaign['EmailNotification']['WarnPlaceInterval'])->small()->style('margin-top: 12px;');
$form->add_row(NETCAT_MODULE_SERVICES_DIRECT_CAMPAIGN_NOTIFICATIONS_MONEYWARNINGVALUE)->horizontal()
  ->div(NETCAT_MODULE_SERVICES_DIRECT_CAMPAIGN_NOTIFICATIONS_MONEYWARNINGVALUE_ADD)->style('line-height: 38px;')
  ->string('data[EmailNotification][MoneyWarningValue]', !empty($campaign['EmailNotification']['MoneyWarningValue']) ? $campaign['EmailNotification']['MoneyWarningValue'] : 20 )->small()->style('float: left; margin-right: 10px;')
;

$form->add_row(NETCAT_MODULE_SERVICES_DIRECT_CAMPAIGN_STRATEGY)->horizontal()
  ->select('data[Strategy][StrategyName]', $strategies, !empty($campaign['Strategy']['StrategyName']) ? $campaign['Strategy']['StrategyName'] : null);

foreach ($strategies as $key => $value) {
    if (isset($strategies_fields[$key])) {
        foreach ($strategies_fields[$key] as $addition_field) {
            $form->add_row($addition_field['name'])->horizontal()->class_name('strategy_'.$key)->hide()
              ->string('data[Strategy]['.$addition_field['key'].']', !empty($campaign['Strategy'][$addition_field['key']]) ? $campaign['Strategy'][$addition_field['key']] : null);
        }
    }
}

$form->add_row(NETCAT_MODULE_SERVICES_DIRECT_CAMPAIGN_START)->horizontal()->string('data[StartDate]', $campaign['StartDate']);
?>
<div class="nc_services_form_wrapper"><?php echo $form; ?></div>

<script>
    (function() {
        $nc('INPUT[name="data[StartDate]"]').datepicker();
        $nc('select[name="data[Strategy][StrategyName]"]').change(function() {
<?php foreach ($strategies as $key => $value) : ?>
            $nc('.strategy_<?php echo $key;?>').hide();
            if ($nc(this).val() == '<?php echo $key; ?>') {
                $nc('.strategy_<?php echo $key;?>').show();
            }
<?php endforeach ?>
        });
        <?php if (!empty($campaign['Strategy']['StrategyName'])): ?>
            $nc('.strategy_<?php echo $campaign['Strategy']['StrategyName'];?>').show();
        <?php endif ?>
    })();
</script>
