function mt_toutrix_bank_page() { global $toutrix_adserver; toutrix_get_token(); $fields = new stdclass(); $fields->id = $toutrix_adserver->userId; $bitcoin_addresse = $toutrix_adserver->get_bitcoin_address($fields); $bitcoin_addresse = $bitcoin_addresse->address->bitcoin_address; ?> <h1>TouTrix Bank<h1> <?php toutrix_echo_funds_available(); ?> <h2>Make a deposit</h2> We only accept BitCoin for the moment.<br/> <br/> <center><font size='4'>First deposit is doubled.</font></center> <br/> <h3>Bitcoin</h3> Send any amount to this payment address: <?php echo $bitcoin_addresse; ?> <br/><br/> <img src='https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=<?php echo $bitcoin_addresse; ?> '> <br/><br/> Deposit are automatic. But it take few minutes. <h2>Withdrawal</h2> Configure your account in settings to receive hourly payment. You never have to wait for your money. You can send the money directly to your exchanger or in your mobile wallet.<br/> We may have to approve your account first. <h1>Exchange Bitcoins</h1> <!-- TODO Exchange recommendation --> If you don't have BitCoin Wallet, you can use an exchanger and they will receive money on your behalf. <br/> <br/> We recommend <a href="https://www.coinbase.com/join/52cb9f042fe57d1d9400001f" target="_blank">CoinBase</a>. <br/> <br/> <h1>Need a lend?</h1> <!-- TODO We should ask adserver with keyword: btc lend --> <a href='https://btcjam.com/?r=688f61e1-439f-4b8a-93a5-e7f57068c158&utm_medium=direct&utm_source=referral_url&utm_campaign=ad_2' target="_blank">BTCjam</a> <h1>Need a lend?</h1> <!-- TODO We should ask adserver with keyword: btc lend --> <a href='https://btcjam.com/?r=a4b60cb9-52a2-4a41-9dc3-7c1bc5e817e4&utm_medium=direct&utm_source=referral_url&utm_campaign=ad-2'>BTCjam</a> <?php }
function mt_toutrix_marketplace_page() { global $toutrix_adserver; toutrix_get_token(); $zone = new stdClass(); $zone->id = get_option("ad_toutrix_zone_id"); $zone = $toutrix_adserver->zone_get($zone); if (empty($_GET['subpage'])) { echo "<h2>Marketplace</h2>"; echo "The volume may be little higher because it's only sold volume."; $marketplace = $toutrix_adserver->marketplace_list(null); usort($marketplace, 'ToutrixVolumeSort'); $table = new toutrix_marketplace_table(); $table->set_datas($marketplace); $table->prepare_items(); $table->display(); } }
function toutrix_creative_page() { global $toutrix_adserver; toutrix_get_token(); if ($_GET['action'] == 'delete' && !empty($_GET['creativeId'])) { $fields = new stdclass(); $fields->id = intval($_GET['creativeId']); $fields->IsActive = 0; $fields->IsDeleted = 1; $creative = $toutrix_adserver->creative_update($fields); unset($_GET['action']); unset($_GET['creativeId']); } if (empty($_GET['creativeId'])) { if (!empty($_POST['b'])) { $fields = new stdclass(); $fields->user_id = $adserver->userId; $fields->title = sanitize_text_field($_POST['title']); $fields->url = sanitize_text_field($_POST['url']); $fields->banner_url = sanitize_text_field($_POST['banner_url']); $fields->body = sanitize_text_field($_POST['body']); $fields->html = sanitize_text_field($_POST['html']); $fields->adtypeId = intval($_POST['adtypeId']); $fields->IsDeleted = 0; $fields->IsActive = 1; stripslashes_deep($fields); $creative = $toutrix_adserver->creative_create($fields); $_GET['new'] = ''; //var_dump($creative); ?> <div class="updated"><p><strong><?php _e('Creative added', 'wp-toutrix'); ?> </strong></p></div> <?php } ?> <div class='wrap'> <?php if (!isset($_GET['new']) || $_GET['new'] == '') { ?> <a href="?page=mt_toutrix_campaign" class="page-title-action">Go to campaigns</a> <hr/> <h1>Creatives <a href="?page=toutrix_creative&new=1" class="page-title-action">Add New</a></h1> <?php $creatives = $toutrix_adserver->creatives_list(array()); ?> <ul class='subsubsub'> <li class='all'><a href='' class="current">All <span class="count">(<?php echo count($creatives); ?> )</span></a></li> </ul> <?php $table = new creative_table(); $table->prepare_items(); $table->display(); } else { ?> <a href="?page=toutrix_creative" class="page-title-action">Go to creatives</a> <hr/> <h2>Create a new creative</h2> <?php $new = new stdclass(); toutrix_creative_form($new); } } elseif (!empty($_GET['creativeId'])) { if (!empty($_POST['b'])) { $fields = new stdclass(); $isActive = 0; if ($_POST['IsActive'] == 'on') { $isActive = 1; } $fields->id = intval($_POST['id']); $fields->IsActive = $isActive; $fields->title = sanitize_text_field($_POST['title']); $fields->url = sanitize_text_field($_POST['url']); $fields->banner_url = sanitize_text_field($_POST['banner_url']); $fields->body = sanitize_text_field($_POST['body']); $fields->html = sanitize_text_field($_POST['html']); $fields->adtypeId = intval($_POST['adtypeId']); stripslashes_deep($fields); $creative = $toutrix_adserver->creative_update($fields); ?> <div class="updated"><p><strong><?php _e('Creative saved', 'wp-toutrix'); ?> </strong></p></div> <?php } $fields = new stdclass(); $fields->creativeId = intval($_GET['creativeId']); $creative = $toutrix_adserver->creative_get($fields); ?> <div class='wrap'> <a href="?page=toutrix_creative" class="page-title-action">Go to creatives</a> <hr/> <h2>Update creative</h2> <?php toutrix_creative_form($creative); //var_dump($creative); } if ($toutrix_do_wrap) { ?> </div> <?php } }
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_settings_page() { //must check that the user has the required capability if (!current_user_can('manage_options')) { wp_die(__('You do not have sufficient permissions to access this page.')); } global $toutrix_adserver; echo "<script src='http://serv.toutrix.com/serv/tag?tagId=1'></script>"; echo "<div class='container'>"; echo "<center><a href='http://toutrix.com/2015/09/07/we-are-looking-for-developpers/'>We are looking for developpers</a></center><br/>"; // Read in existing option value from database $toutrix_username = get_option("ad_toutrix_username"); $toutrix_password = get_option("ad_toutrix_password"); $toutrix_access_token = get_option("ad_toutrix_access_token"); $toutrix_website_id = get_option("ad_toutrix_website_id"); $toutrix_zone_id = get_option("ad_toutrix_zone_id"); if (isset($_POST["wp_config"]) && $_POST["wp_config"] == 'Y') { $is_skimmed = 0; if ($_POST['is_skimmed'] == 'on') { $is_skimmed = 1; } update_option("ad_toutrix_skimmed_enabled", $is_skimmed); $replace_links = 0; if ($_POST['replace_links'] == 'on') { $replace_links = 1; } update_option("ad_toutrix_replace_links", $replace_links); ?> <div class="updated"><p><strong><?php _e($user->error->message, 'menu-test'); ?> </strong></p></div> <?php } elseif (isset($_POST["signup"]) && $_POST["signup"] == 'Y') { update_option("ad_toutrix_access_token", ""); update_option("ad_toutrix_website_id", ""); update_option("ad_toutrix_zone_id", ""); update_option("ad_channel_id", intval($_POST['channelId'])); // Read their posted value $toutrix_username = sanitize_text_field($_POST["ad_toutrix_username"]); $toutrix_password = sanitize_text_field($_POST["ad_toutrix_password"]); $user = new stdClass(); $user->username = sanitize_text_field($_POST["ad_toutrix_username"]); $user->password = sanitize_text_field($_POST["ad_toutrix_password"]); $user->email = sanitize_text_field($_POST["ad_toutrix_email"]); $user->refererId = intval($_POST["refererId"]); //var_dump($adserver); $user = $toutrix_adserver->user_create($user); if ($user->error && $user->error->status != 500) { ?> <div class="updated"><p><strong><?php _e($user->error->message, 'menu-test'); ?> </strong></p></div> <?php $toutrix_username = ""; $toutrix_password = ""; } else { update_option("ad_toutrix_username", $toutrix_username); update_option("ad_toutrix_password", $toutrix_password); ?> <div class="updated"><p><strong><?php _e('TouTrix account is created.', 'menu-test'); ?> </strong></p></div> <?php } } if (isset($_POST["config"]) && $_POST["config"] == 'Y') { // Read their posted value $toutrix_username = sanitize_text_field($_POST["ad_toutrix_username"]); $toutrix_password = sanitize_text_field($_POST["ad_toutrix_password"]); // Save the posted value in the database update_option("ad_toutrix_username", $toutrix_username); update_option("ad_toutrix_password", $toutrix_password); // Put a "settings saved" message on the screen ?> <div class="updated"><p><strong><?php _e('settings saved.', 'menu-test'); ?> </strong></p></div> <?php } if (strlen($toutrix_username) == 0 && strlen($toutrix_password) == 0) { $channels = toutrix_get_channels(); echo '<div class="wrap">'; ?> <h1>Create your account now</h2> Fill-up the form to create your account now.<br/> <form name="form1" method="post" action=""> <input type="hidden" name="signup" value="Y"> <input type="hidden" name="refererId" value="<?php echo toutrix_referer_id; ?> "> <input type="hidden" name="tab" value="setting"> <p><?php _e("Username:"******"text" name="ad_toutrix_username" value="<?php echo $toutrix_username; ?> " size="20"> </p> <p><?php _e("Password:"******"text" name="ad_toutrix_password" value="<?php echo $toutrix_password; ?> " size="20"> </p> <p><?php _e("Channel:", 'menu-test'); ?> <select name='channelId'> <?php foreach ($channels as $channel) { ?> <option value='<?php echo $channel->id; ?> '><?php echo $channel->Title; ?> </option> <?php } ?> </select> Choose the good channel for your website. We may change it for you later. </p> <p><?php _e("Your email:", 'menu-test'); ?> <input type="text" name="ad_toutrix_email" value="<?php echo $toutrix_email; ?> " size="20"> </p> <hr /> <p class="submit"> <input type="submit" name="Submit" class="button-primary" value="<?php _e("Signup on TouTrix", 'menu-test'); ?> " /> </p> </form> </div> <?php } elseif (strlen($toutrix_username) > 0 && strlen($toutrix_password) > 0) { //echo "Getting token<br/>"; if (toutrix_get_token()) { //echo "Got Token<br/>"; $toutrix_access_token = get_option("ad_toutrix_access_token"); $toutrix_website_id = get_option("ad_toutrix_website_id"); $toutrix_channel_id = get_option("ad_channel_id"); if (strlen($toutrix_website_id) == 0) { echo "Creating website...<br/>"; $site = new stdClass(); $site->Title = get_bloginfo(); $site->Url = get_site_url(); $site->Description = get_bloginfo('description'); $site->channelId = $toutrix_channel_id; //var_dump($site); //echo "<br/>"; $site = $toutrix_adserver->site_create($site); // echo "Create website: "; // var_dump($site); //echo "<br/>"; if ($site->id > 0) { update_option("ad_toutrix_website_id", $site->id); $toutrix_website_id = $site->id; } else { echo "<font color='red'>Can't find WebSite ID</font>"; } echo "<br/>"; } if (strlen($toutrix_zone_id) == 0 && strlen($toutrix_website_id) > 0) { //echo "Creating zone...<br/>"; $zone = new stdClass(); $zone->Name = get_bloginfo(); $zone->siteId = $toutrix_website_id; $zone->channelId = $toutrix_channel_id; $zone = $toutrix_adserver->zone_create($zone); echo "Create zone: "; //var_dump($zone); if ($zone->id > 0) { update_option("ad_toutrix_zone_id", $zone->id); $toutrix_zone_id = $zone->id; } else { echo "<font color='red'>Can't find Zone ID</font>"; } echo "<br/>"; } } } $is_skimmed = get_option("ad_toutrix_skimmed_enabled"); $replace_links = get_option("ad_toutrix_replace_links"); ?> <div class='wrap'> <h1>AdServer setting</h1> <form name="form_setting" method="POST"> <input type="hidden" name="wp_config" value="Y"> <!--<table class="form-table">--> <table class="form-table"> <tr> <td><input type="checkbox" name="is_skimmed" <?php if ($is_skimmed == 1) { echo "checked"; } ?> ></td> <td><?php _e("Skimmed some traffic", 'toutrix'); ?> </td> </tr> <tr> <td><input type="checkbox" name="replace_links" <?php if ($replace_links == 1) { echo "checked"; } ?> ></td> <td><?php _e("Replace links with bitcoin address referer", 'toutrix'); ?> </td> </tr> </table> <p class="submit"> <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e('Save Changes'); ?> " /> </p> </form> </div> <h1>Connect with your TouTrix account</h2> <?php echo '<div class="wrap">'; ?> <form name="form1" method="post" action=""> <input type="hidden" name="config" value="Y"> <table class="form-table"> <tr><td><?php _e("TouTrix Username:"******"text" name="ad_toutrix_username"" value="<?php echo $toutrix_username; ?> " size="20"></td> </tr> <tr><td><?php _e("TouTrix password:"******"text" name="ad_toutrix_password"" value="<?php echo $toutrix_password; ?> " size="20"></td> </tr> </table> <?php if (strlen($toutrix_username) > 0 && strlen($toutrix_password) > 0) { ?> <p><?php _e("Access Token:", 'menu-test'); ?> <?php echo $toutrix_access_token; ?> </p> <p><?php _e("Website ID:", 'menu-test'); ?> <?php echo $toutrix_website_id; ?> </p> <p><?php _e("Default Zone ID:", 'menu-test'); ?> <?php echo $toutrix_zone_id; ?> </p> <hr /> <?php } ?> <p class="submit"> <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e('Save Changes'); ?> " /> </p> </form> <?php echo "</div>"; if (strlen($toutrix_username) > 0 && strlen($toutrix_password) > 0) { toutrix_user_form(); } }
function toutrix_site_show_stats($site) { global $toutrix_adserver; global $_countries; toutrix_get_token(); $toutrix_website_id = get_option("ad_toutrix_website_id"); $fields = new stdClass(); $fields->id = $toutrix_website_id; if (isset($_GET['startDate'])) { $fields->startDate = $_GET['startDate']; $fields->endDate = $_GET['endDate']; } else { $fields->startDate = date("m/01/Y"); $fields->endDate = date("m/t/Y"); } $stats = $toutrix_adserver->site_report($fields); ?> <h1>Publisher statistics</h1> <form method='GET'> <input type='hidden' name='page' value='mt_toutrix_stats_page'> Start date: <input type='text' name='startDate' value='<?php echo $fields->startDate; ?> '><br/> End date: <input type='text' name='endDate' value='<?php echo $fields->endDate; ?> '><br/> <input type='submit' name='b' value='Go'><br/> </form> <?php $cur_tab = 'homepage'; if (isset($_GET['tab'])) { $cur_tab = $_GET['tab']; } $tabs = array('homepage' => 'Per day', 'per_country' => 'Per country'); 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_stats_page&tab={$tab}&startDate={$fields->startDate}&endDate={$fields->endDate}'>{$name}</a>"; } echo '</h2>'; if ($cur_tab == 'homepage') { //var_dump($stats->stats); //echo "<hr/>"; $stats_per_day = $stats->stats->per_day; //var_dump($stats_per_day); $table = new stats_revenue_per_day_table(); $table->set_datas($stats->stats->per_day); $table->prepare_items(); ?> <div id="day_chart" style="width: 900px; height: 500px;"></div> <script type="text/javascript" src="https://www.google.com/jsapi"></script> <script type="text/javascript"> google.load("visualization", "1.1", {packages:["bar"]}); google.setOnLoadCallback(drawChart); function drawChart() { var data = google.visualization.arrayToDataTable([ ['Day', 'Impressions', 'Clicks', 'Profit'], <?php foreach ($stats->stats->per_day as $day => $stat) { echo "['" . $day . "', " . $stat->nbr_impressions . ", " . $stat->nbr_clicks . ", " . $stat->revenu . "],"; } ?> ]); var options = { chart: { title: 'Day Performance', //subtitle: 'Sales, Expenses, and Profit: 2014-2017', } }; var chart = new google.charts.Bar(document.getElementById('day_chart')); chart.draw(data, options); } </script> <?php $table->display(); } else { $table = new stats_revenu_per_country_table(); $table->set_datas($stats->stats->per_country); $table->prepare_items(); ?> <script type="text/javascript" src="https://www.google.com/jsapi"></script> <script type="text/javascript"> google.load("visualization", "1", {packages:["geochart"]}); google.setOnLoadCallback(drawRegionsMap); function drawRegionsMap() { var data = google.visualization.arrayToDataTable([ ['Country', 'Popularity'], <?php //var_dump($stats->stats->per_country); foreach ($stats->stats->per_country as $country_code => $stat) { echo "['" . str_replace("'", "\\'", $_countries[$country_code]) . "', " . $stat->nbr_impressions . "],"; } ?> ]); var options = {}; var chart = new google.visualization.GeoChart(document.getElementById('regions_div')); chart.draw(data, options); } </script> <div id="regions_div" style="width: 900px; height: 500px;"></div> <?php $table->display(); } }
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); } }
function toutrix_connect() { global $user; global $toutrix_adserver; if (toutrix_get_token()) { $user = $toutrix_adserver->get_user(); if ($user->error) { update_option("ad_toutrix_access_token", ''); if (!toutrix_get_token()) { echo "TOUTRIX PROBLEM<br/>"; die; } else { update_option("ad_toutrix_access_token", $toutrix_adserver->access_token); } $user = $toutrix_adserver->get_user(); } } }