function mt_toutrix_campaign_page() { global $toutrix_adserver; toutrix_get_token(); if (!empty($_GET['flightId']) && $_GET['action'] != 'delete') { toutrix_flight(); return; } if ($_GET['action'] == 'new' && !isset($_GET['tab'])) { ?> <h2>Create a new campaign</h2> <?php $new = new stdclass(); toutrix_campaign_form($new); } if (isset($_GET['removetargetid']) && !isset($_GET['flightId']) && isset($_GET['campaignId'])) { $fields = new stdclass(); $fields->campaignId = intval($_GET['campaignId']); $fields->id = intval($_GET['removetargetid']); $response = $toutrix_adserver->campaign_targets_delete($fields); ?> <div class="updated"><p><strong><?php _e('Targeting deleted', 'wp-toutrix'); ?> </strong></p></div> <?php } if (empty($_GET['campaignId'])) { if (!empty($_POST['b'])) { $fields = new stdclass(); $fields->user_id = $adserver->userId; $fields->name = sanitize_text_field($_POST['camp_name']); $fields->isDeleted = 0; $fields->isActive = 1; stripslashes_deep($fields); $campaign = $toutrix_adserver->campaign_create($fields); ?> <div class="updated"><p><strong><?php _e('Campaign added', 'wp-toutrix'); ?> </strong></p></div> <?php } ?> <div class='wrap'> <a href="?page=toutrix_creative" class="page-title-action">Go to creatives</a><hr/> <h1>Campaigns <a href="?page=mt_toutrix_campaign&action=new" class="page-title-action">Add New</a></h1> <?php toutrix_echo_funds_available(); $table = new campaigns_table(); $table->prepare_items(); $table->display(); ?> </div> <?php } elseif (!empty($_GET['campaignId'])) { if (!empty($_POST['b']) && $_POST['target'] == 'yes') { $fields = get_form_target(); $target = $toutrix_adserver->target_create($fields); ?> <div class="updated"><p><strong><?php _e('Target added', 'wp-toutrix'); ?> </strong></p></div> <?php } elseif (!empty($_POST['b']) && $_POST['flight'] == 'yes') { $fields = new stdclass(); if (!empty($_POST['id'])) { $fields->id = intval($_POST['id']); } $fields->campaignId = intval($_POST['campaignId']); $fields->Name = sanitize_text_field($_POST['Name']); $fields->Price = $_POST['Price']; $fields->MaxPerIp = intval($_POST['MaxPerIp']); $fields->IsDeleted = false; $fields->IsActive = true; if ($_POST['IsActive'] == 'on') { $fields->IsActive = true; } $fields->IsUnlimited = true; $fields->NoEndDate = true; stripslashes_deep($fields); $flight = $toutrix_adserver->flight_create($fields); $_GET['action'] = "edit"; $_GET['tab'] = 'flights'; } elseif ($_GET['action'] == 'delete' && $_GET['campaignId'] > 0 && $_GET['flightId'] > 0) { $fields = new stdclass(); $fields->id = intval($_GET['flightId']); $fields->IsDeleted = true; $fields->IsActive = false; $flight = $toutrix_adserver->flight_update($fields); $_GET['action'] = 'edit'; } elseif (!empty($_POST['b'])) { $fields = new stdclass(); $fields->id = intval($_POST['id']); $fields->name = sanitize_text_field($_POST['name']); $fields->isActive = 0; if ($_POST['isActive'] == 'on') { $fields->isActive = 1; } stripslashes_deep($fields); $campaign = $toutrix_adserver->campaign_update($fields); ?> <div class="updated"><p><strong><?php _e('Campaign saved', 'wp-toutrix'); ?> </strong></p></div> <?php } $fields = new stdclass(); $fields->campaignId = intval($_GET['campaignId']); //var_dump($fields); echo "<br/>"; $campaign = $toutrix_adserver->campaign_get($fields); $cur_tab = 'homepage'; if (isset($_GET['tab'])) { $cur_tab = $_GET['tab']; } ?> <div class='wrap'> <a href="?page=mt_toutrix_campaign" class="page-title-action">All campaigns</a> > <?php echo $campaign->name; ?> <hr/> <?php $tabs = array('homepage' => 'Settings', 'flights' => 'Flights', 'targets' => 'Targets', 'stats' => 'Stats'); echo '<div id="icon-themes" class="icon32"><br></div>'; echo '<h2 class="nav-tab-wrapper">'; foreach ($tabs as $tab => $name) { $class = $tab == $cur_tab ? ' nav-tab-active' : ''; echo "<a class='nav-tab{$class}' href='?page=mt_toutrix_campaign&action=edit&campaignId=" . intval($_GET['campaignId']) . "&tab={$tab}'>{$name}</a>"; } echo '</h2>'; if ($cur_tab == 'homepage') { ?> <h2>Update campaign</h2> <?php toutrix_campaign_form($campaign); } elseif ($cur_tab == 'flights') { toutrix_flights($campaign); } elseif ($cur_tab == 'stats') { toutrix_campaign_show_stats(campaign); //?page=mt_toutrix_campaign&action=stats&campaignId=24 } else { ?> <h2>Targeting for this campaign</h2> It applies to all flights.<br/> <?php $fields = new stdclass(); $fields->campaignId = intval($_GET['campaignId']); $targets = $toutrix_adserver->campaign_targets($fields); toutrix_show_targets($targets); echo "<h2>Add a new target</h2>"; toutrix_show_target_form($fields); } } }
function toutrix_flight() { global $toutrix_adserver; toutrix_get_token(); if (isset($_GET['activeId']) && $_GET['activeId'] > 0) { $fields = new stdclass(); $fields->id = intval($_GET['activeId']); $fields->IsActive = true; $target = $toutrix_adserver->creative_flight_save($fields); ?> <div class="updated"><p><strong><?php _e('Creative started', 'wp-toutrix'); ?> </strong></p></div> <?php } if (isset($_GET['removetargetid']) && isset($_GET['flightId'])) { $fields = new stdclass(); $fields->flightId = intval($_GET['flightId']); $fields->id = intval($_GET['removetargetid']); $response = $toutrix_adserver->flight_targets_delete($fields); ?> <div class="updated"><p><strong><?php _e('Targeting deleted', 'wp-toutrix'); ?> </strong></p></div> <?php } if (isset($_GET['deactiveId']) && $_GET['deactiveId'] > 0) { $fields = new stdclass(); $fields->id = intval($_GET['deactiveId']); $fields->IsActive = false; $target = $toutrix_adserver->creative_flight_save($fields); ?> <div class="updated"><p><strong><?php _e('Creative stopped', 'wp-toutrix'); ?> </strong></p></div> <?php } if (isset($_GET['removeTargetId']) && $_GET['removeTargetId'] > 0) { $fields = new stdclass(); $fields->id = intval($_GET['removeTargetId']); $fields->IsDeleted = true; $fields->IsActive = false; $target = $toutrix_adserver->creative_flight_save($fields); ?> <div class="updated"><p><strong><?php _e('Creative removed', 'wp-toutrix'); ?> </strong></p></div> <?php } if (isset($_POST['target']) && $_POST['target'] == 'yes') { // We are adding a new target $fields = get_form_target(); $target = $toutrix_adserver->target_create($fields); //var_dump($target); ?> <div class="updated"><p><strong><?php _e('Flight target added', 'wp-toutrix'); ?> </strong></p></div> <?php } $fields = new stdclass(); $fields->campaignId = intval($_GET['campaignId']); //var_dump($fields); echo "<br/>"; $campaign = $toutrix_adserver->campaign_get($fields); $fields = new stdclass(); $fields->campaignId = intval($_GET['campaignId']); $fields->flightId = intval($_GET['flightId']); $flight = $toutrix_adserver->flights_get($fields); if (isset($_GET['b'])) { $flight->Price = $_GET['Price']; $flight->IsActive = 0; if ($_GET['IsActive'] == 'on') { $flight->IsActive = 1; } $flight->MaxPerIp = intval($_GET['MaxPerIp']); $flight = $toutrix_adserver->flight_update($flight); } if (isset($_POST['creative']) && $_POST['creative'] == 'Y') { $fields = new stdclass(); $fields->flightId = intval($_GET['flightId']); $fields->campaignId = intval($_GET['campaignId']); $fields->creativeId = intval($_POST['creativeId']); $fields->IsActive = true; $creative_flights = $toutrix_adserver->creative_flight_create($fields); //var_dump($creative_flights); ?> <div class="updated"><p><strong><?php _e('Creative added to the flight', 'wp-toutrix'); ?> </strong></p></div> <?php } ?> <div class="wrap"> <a href="?page=mt_toutrix_campaign" class="page-title-action">All campaigns</a> > <a href='?page=mt_toutrix_campaign&action=edit&campaignId=<?php echo $campaign->id; ?> "&tab=flights' class="page-title-action"><?php echo $campaign->name; ?> </a> <?php $cur_tab = 'homepage'; if (isset($_GET['tab'])) { $cur_tab = $_GET['tab']; } $tabs = array('homepage' => 'Settings', 'creative' => 'Creatives', 'targets' => 'Targets'); echo '<div id="icon-themes" class="icon32"><br></div>'; echo '<h2 class="nav-tab-wrapper">'; foreach ($tabs as $tab => $name) { $class = $tab == $cur_tab ? ' nav-tab-active' : ''; echo "<a class='nav-tab{$class}' href='?page=mt_toutrix_campaign&action=edit&campaignId=" . intval($_GET['campaignId']) . "&flightId=" . intval($_GET['flightId']) . "&tab={$tab}'>{$name}</a>"; } echo '</h2>'; if ($cur_tab == 'homepage') { echo "<h1>Update flight for " . $campaign->name . "</h1>"; ?> <form> <input type='hidden' name='page' value='mt_toutrix_campaign'> <input type='hidden' name='campaignId' value='<?php echo intval($_GET['campaignId']); ?> '> <input type='hidden' name='flightId' value='<?php echo intval($_GET['flightId']); ?> '> Enabled: <input type='checkbox' name='IsActive' <?php if ($flight->IsActive == 1) { echo "checked"; } ?> ><br/> Price: $<input type='text' name='Price' value='<?php echo $flight->Price; ?> '> (CPM price)<br/> Max Per IP: <input type='text' name='MaxPerIp' value='<?php echo $flight->MaxPerIp; ?> '><br/> <input type='submit' name='b' value='Save'> </form> <?php } elseif ($cur_tab == 'creative') { $fields = new stdclass(); $fields->flightId = intval($_GET['flightId']); $creative_flights = $toutrix_adserver->creative_flight_get($fields); //var_dump($creative_flights); echo "<h2>Creatives for " . $campaign->name . "</h2>"; $creatives_table = new creatives_table(); $creatives_table->set_datas($creative_flights); $creatives_table->prepare_items(); $creatives_table->display(); ?> <h2>Add a creative to this flight</h2> <?php $creatives = $toutrix_adserver->creatives_list(array()); ?> <form method='POST'> <input type='hidden' name='creative' value='Y'> <select name='creativeId'> <?php foreach ($creatives as $one_crea) { if ($all_used[$one_crea->id] != 1) { echo "<option value='" . $one_crea->id . "'>" . $one_crea->title . "</option>"; } } ?> </select> <input type='submit' name='b' value='Add'> </form> <?php } elseif ($cur_tab == 'targets') { echo "<h2>Targets for " . $campaign->name . "</h2>"; $fields = new stdclass(); $fields->flightId = intval($_GET['flightId']); $targets = $toutrix_adserver->flight_targets_get($fields); toutrix_show_targets($targets); $fields = new stdclass(); $fields->flightId = intval($_GET['flightId']); echo "<h2>Add a new target</h2>"; toutrix_show_target_form($fields); } }