<?php 
$page = 'video';
if (!empty($_GET['type'])) {
	$page = PT_Secure($_GET['type']);
}
$page_link = 'Hosted video file, e.g (http://site.com/video.mp4)';
if ($page == 'image') {
	$page_link = 'Image link, e.g (http://site.com/image.png)';
}
if ($page == 'vast') {
	$page_link = 'XML link, e.g (http://yourdomain.com/vast.xml)';
}
?>
<div class="container-fluid">
    <div class="block-header">
        <h2>Advertisement > Manage Video Ads > Create New Ad</h2>
    </div>
    <!-- Vertical Layout -->
    <div class="row">
        <div class="col-lg-8 col-md-8">
            <div class="card">
                <div class="header">
                    <h2>Create New <?php echo ucfirst($page) ?> Ad</h2>
                </div>
                <div class="body">
                    <div class="alert alert-success ads-settings-alert"></div>
                    <form class="ads-settings" method="POST">
                        <div class="form-group form-float">
                            <div class="form-line">
                                <input type="text" id="name" name="name" class="form-control">
                                <label class="form-label">Name</label>
                            </div>
                        </div>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <input type="text" id="link" name="link" class="form-control">
                                <label class="form-label"><?php echo $page_link ?></label>
                            </div>
                        </div>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <input type="text" id="ad_link" name="ad_link" class="form-control">
                                <label class="form-label">URL redirect the user to this link after clicking on the ad</label>
                            </div>
                        </div>
                        
                        <div class="form-group form-float">
                            <div class="form-line">
                                <input type="text" id="skip_seconds" name="skip_seconds" class="form-control" value="0">
                                <label class="form-label">Skip Ad Seconds (0 = disabled)</label>
                            </div>
                        </div>
                        <?php if ($page == 'vast') { ?>
                        <label for="vast_type">Type</label>
                        <div class="form-group">
                            <input type="radio" name="vast_type" id="vast_type-enabled" value="vast" checked>
                            <label for="vast_type-enabled">Vast</label>
                            <input type="radio" name="vast_type" id="vast_type-disabled" value="vpaid">
                            <label for="vast_type-disabled" class="m-l-20">VPaid</label>
                        </div>
                        <?php } ?>
                        <input type="hidden" value="<?php echo $page ?>" name="type">
                        <button type="submit" class="btn btn-primary m-t-15 waves-effect">Create</button>
                    </form>
                </div>
            </div>
        </div>
        <div class="clearfix"></div>
    </div>
    <!-- #END# Vertical Layout -->
<script>
$(function() {
    var form_ads_settings = $('form.ads-settings');

    form_ads_settings.ajaxForm({
        url: '{{LINK aj/ap/create-ads}}',
        beforeSend: function() {
            form_ads_settings.find('button').text('{{LANG please_wait}}');
        },
        success: function(data) {
            if (data.status == 200) {
            	$('.ads-settings-alert').html('<i class="fa fa-check"></i> New ad successfully created');
            	setTimeout(function () {
            		$('.ads-settings-alert').empty();
            		window.location.href = '{{LINK admin-cp/manage-video-ads}}';
            	}, 2000);
            } else {
                alert(data.error);
            }
            form_ads_settings.find('button').text('Save');
        }
    });
});
</script>