Exemple #1
0
function wpr_add()
{
    global $wpdb, $wpr_table_campaigns, $wpr_table_templates, $loadedmodules;
    $options = unserialize(get_option("wpr_options"));
    if ($options['wpr_installed'] != "yes") {
        echo '<div class="wrap"><h2>WP Robot</h2><div class="updated"><h3>Installation</h3><p>' . __('Please go <a href="?page=wpr-campaigns">here</a> to finish the installation of WP Robot first.', 'wprobot') . '</p></div></div>';
        return false;
    }
    if ($options["wpr_core"] == "advanced" || $options["wpr_core"] == "basic") {
        if (!$_GET['edit']) {
            if ($options["wpr_core"] == "basic") {
                $lmt = 3;
            }
            if ($options["wpr_core"] == "advanced") {
                $lmt = 6;
            }
            $count = $wpdb->get_var("SELECT COUNT(*) FROM " . $wpr_table_campaigns);
            if ($count >= $lmt) {
                echo '<div class="wrap"><h2>WP Robot</h2><div class="updated"><h3>Limit Reached</h3><p>' . __('Only ' . $lmt . ' Campaigns per site can be used with the ' . $options["wpr_core"] . ' Core. You can upgrade <a href="http://wprobot.net/order/ordercustom.php">here</a>.', 'wprobot') . '</p></div></div>';
                return false;
            }
        }
    }
    $templates = $wpdb->get_results("SELECT * FROM " . $wpr_table_templates . " WHERE `type` = 'post'");
    foreach ($templates as $template) {
        $presets[$template->name]["content"] = $template->content;
        $presets[$template->name]["title"] = $template->title;
        $presets[$template->name]["comments_amazon"] = $template->comments_amazon;
        $presets[$template->name]["comments_flickr"] = $template->comments_flickr;
        $presets[$template->name]["comments_yahoo"] = $template->comments_yahoo;
        $presets[$template->name]["comments_youtube"] = $template->comments_youtube;
    }
    if ($_POST['catbut']) {
        if ($_POST['multisingle'] == "multi") {
            $_POST['multisingle'] = "single";
        } else {
            $_POST['multisingle'] = "multi";
            $_POST['categories'] = "";
        }
    }
    if ($_POST['exact']) {
        $keywordsinput = str_replace("\r", "", $_POST['keywords']);
        $keywordsinput = explode("\n", $keywordsinput);
        $_POST["keywords"] = "";
        for ($i = 0; $i < count($keywordsinput); $i++) {
            if ($keywordsinput[$i] != "") {
                $_POST["keywords"] .= '"' . $keywordsinput[$i] . '"' . "\n";
            }
        }
    }
    if ($_POST['quickrand']) {
        $count = count($presets);
        $_POST['tnum'] = rand(2, $count);
        $rand_keys = array_rand($presets, $_POST['tnum']);
        $chance = floor(100 / $_POST['tnum']);
        $i = 1;
        $tchance = 0;
        foreach ($rand_keys as $rand_key) {
            $_POST["chance{$i}"] = $chance;
            $tchance = $tchance + $chance;
            $_POST["title{$i}"] = $presets[$rand_key]["title"];
            $_POST["content{$i}"] = $presets[$rand_key]["content"];
            $_POST["comments_amazon{$i}"] = $presets[$rand_key]["comments_amazon"];
            $_POST["comments_flickr{$i}"] = $presets[$rand_key]["comments_flickr"];
            $_POST["comments_yahoo{$i}"] = $presets[$rand_key]["comments_yahoo"];
            $_POST["comments_youtube{$i}"] = $presets[$rand_key]["comments_youtube"];
            $i++;
        }
        if ($tchance != 100) {
            $_POST["chance1"] = $_POST["chance1"] + (100 - $tchance);
        }
    }
    if ($_POST['quick']) {
        $count = count($presets);
        $_POST['tnum'] = $count;
        $chance = floor(100 / $count);
        $i = 1;
        $tchance = 0;
        foreach ($presets as $preset) {
            $_POST["chance{$i}"] = $chance;
            $tchance = $tchance + $chance;
            $_POST["title{$i}"] = $preset["title"];
            $_POST["content{$i}"] = $preset["content"];
            $_POST["comments_amazon{$i}"] = $preset["comments_amazon"];
            $_POST["comments_flickr{$i}"] = $preset["comments_flickr"];
            $_POST["comments_yahoo{$i}"] = $preset["comments_yahoo"];
            $_POST["comments_youtube{$i}"] = $preset["comments_youtube"];
            $i++;
        }
        if ($tchance != 100) {
            $_POST["chance1"] = $_POST["chance1"] + (100 - $tchance);
        }
    }
    if ($_POST['type1']) {
        $_POST['type'] = "keyword";
    }
    if ($_POST['type2']) {
        $_POST['type'] = "rss";
        $_POST["content1"] = "{rss}";
        $_POST["title1"] = "{rsstitle}";
        $_POST["comments_amazon1"] = 0;
        $_POST["comments_flickr1"] = 0;
        $_POST["comments_yahoo1"] = 0;
        $_POST["comments_youtube1"] = 0;
    }
    if ($_POST['type3']) {
        $_POST['type'] = "nodes";
        if (isset($presets["Amazon Default"])) {
            $_POST["content1"] = $presets["Amazon Default"]["content"];
            $_POST["title1"] = $presets["Amazon Default"]["title"];
            $_POST["comments_amazon1"] = $presets["Amazon Default"]["comments_amazon"];
            $_POST["comments_flickr1"] = $presets["Amazon Default"]["comments_flickr"];
            $_POST["comments_yahoo1"] = $presets["Amazon Default"]["comments_yahoo"];
            $_POST["comments_youtube1"] = $presets["Amazon Default"]["comments_youtube"];
        }
    }
    if (!$_POST['wpr_add_template'] && !$_POST['wpr_add'] && !$_POST['multisingle'] && !$_POST['exact'] && !$_POST['quick'] && !$_POST['quickrand'] && !$_POST['type1'] && !$_POST['type2'] && !$_POST['type3']) {
        if ($_GET['edit'] || $_GET['ccopy']) {
            // EDIT or COPY CAMPAIGN
            $id = $_GET['edit'];
            if (!$id) {
                $id = $_GET['ccopy'];
            }
            $campaign = $wpdb->get_row("SELECT * FROM " . $wpr_table_campaigns . " WHERE `id` = '{$id}'");
            $_POST["name"] = $campaign->name;
            $_POST["type"] = $campaign->ctype;
            if ($_GET['ccopy']) {
                $_POST["name"] .= " Copy";
            }
            $_POST["interval"] = $campaign->cinterval;
            $_POST["period"] = $campaign->period;
            if ($campaign->pause == 0) {
                $_POST["autopost"] = "yes";
            }
            $_POST['multisingle'] = "multi";
            $_POST["amazon_department"] = $campaign->amazon_department;
            $_POST["ebay_category"] = $campaign->ebay_cat;
            $_POST["yahoo_category"] = $campaign->yahoo_cat;
            $exclude = unserialize($campaign->excludekws);
            for ($i = 0; $i < count($exclude); $i++) {
                $_POST["exclude"] .= $exclude[$i] . "\n";
            }
            $replace = unserialize($campaign->replacekws);
            for ($i = 0; $i < count($replace); $i++) {
                $_POST["replace"] .= $replace[$i]["from"] . "|" . $replace[$i]["to"] . "|" . $replace[$i]["chance"] . "\n";
            }
            $keywords = unserialize($campaign->keywords);
            $_POST["keywords"] = "";
            $_POST["feeds"] = "";
            $_POST["nodes"] = "";
            for ($i = 0; $i < count($keywords); $i++) {
                $_POST["keywords"] .= $keywords[$i][0] . "\n";
                if ($campaign->ctype == "rss") {
                    $_POST["feeds"] .= $keywords[$i]["feed"] . "\n";
                } elseif ($campaign->ctype == "nodes") {
                    $_POST["nodes"] .= $keywords[$i]["node"] . "\n";
                }
            }
            $categories = unserialize($campaign->categories);
            for ($i = 0; $i < count($categories); $i++) {
                $_POST["categories"] .= $categories[$i]["name"] . "\n";
            }
            $templates = unserialize($campaign->templates);
            $_POST['tnum'] = count($templates);
            for ($i = 1; $i <= count($templates); $i++) {
                $_POST["chance{$i}"] = $templates[$i]["chance"];
                $_POST["title{$i}"] = $templates[$i]["title"];
                $_POST["content{$i}"] = $templates[$i]["content"];
                $_POST["comments_amazon{$i}"] = $templates[$i]["comments"]["amazon"];
                $_POST["comments_flickr{$i}"] = $templates[$i]["comments"]["flickr"];
                $_POST["comments_yahoo{$i}"] = $templates[$i]["comments"]["yahooanswers"];
                $_POST["comments_youtube{$i}"] = $templates[$i]["comments"]["youtube"];
            }
            $customfields = unserialize($campaign->customfield);
            $_POST["cf_name"] = $customfields["name"];
            $_POST["cf_value"] = $customfields["value"];
            $translation = unserialize($campaign->translation);
            $_POST["transchance"] = $translation["chance"];
            $_POST["trans1"] = $translation["from"];
            $_POST["trans2"] = $translation["to1"];
            $_POST["trans3"] = $translation["to2"];
        } else {
            $lid = $wpdb->get_var("SELECT id FROM {$wpr_table_campaigns} ORDER BY id DESC;");
            if ($lid == "") {
                $lid = 0;
            }
            $lid++;
            $_POST["name"] = "Campaign {$lid}";
            $_POST["interval"] = rand(12, 96);
            $_POST["chance1"] = 100;
            $rand = array_rand($presets);
            $_POST["content1"] = $presets[$rand]["content"];
            $_POST["title1"] = $presets[$rand]["title"];
            $_POST["comments_amazon1"] = $presets[$rand]["comments_amazon"];
            $_POST["comments_flickr1"] = $presets[$rand]["comments_flickr"];
            $_POST["comments_yahoo1"] = $presets[$rand]["comments_yahoo"];
            $_POST["comments_youtube1"] = $presets[$rand]["comments_youtube"];
            //$_POST["p1"] = ;
            $_POST['multisingle'] = "multi";
            $_POST['autopost'] = "yes";
            $_POST['createcats'] = "yes";
            $_POST['transchance'] = "0";
            $_POST['delaystart'] = "0";
            $_POST['type'] = "keyword";
        }
    }
    if ($_POST['wpr_add_template']) {
        $_POST['tnum'] = $_POST['tnum'] + 1;
        $xi = $_POST['tnum'];
        $_POST["chance{$xi}"] = 0;
        if ($_POST['wpr_add_template_preset'] == "Random") {
            $rand = array_rand($presets);
            $_POST["content{$xi}"] = $presets[$rand]["content"];
            $_POST["title{$xi}"] = $presets[$rand]["title"];
            $_POST["comments_amazon{$xi}"] = $presets[$rand]["comments_amazon"];
            $_POST["comments_flickr{$xi}"] = $presets[$rand]["comments_flickr"];
            $_POST["comments_yahoo{$xi}"] = $presets[$rand]["comments_yahoo"];
            $_POST["comments_youtube{$xi}"] = $presets[$rand]["comments_youtube"];
        } else {
            $_POST["content{$xi}"] = $presets[$_POST['wpr_add_template_preset']]["content"];
            $_POST["title{$xi}"] = $presets[$_POST['wpr_add_template_preset']]["title"];
            $_POST["comments_amazon{$xi}"] = $presets[$_POST['wpr_add_template_preset']]["comments_amazon"];
            $_POST["comments_flickr{$xi}"] = $presets[$_POST['wpr_add_template_preset']]["comments_flickr"];
            $_POST["comments_yahoo{$xi}"] = $presets[$_POST['wpr_add_template_preset']]["comments_yahoo"];
            $_POST["comments_youtube{$xi}"] = $presets[$_POST['wpr_add_template_preset']]["comments_youtube"];
        }
    }
    for ($i = 1; $i <= $_POST["tnum"]; $i++) {
        if ($_POST["load{$i}"]) {
            // LOAD PRESET
            $_POST["content{$i}"] = $presets[$_POST["p{$i}"]]["content"];
            $_POST["title{$i}"] = $presets[$_POST["p{$i}"]]["title"];
            $_POST["comments_amazon{$i}"] = $presets[$_POST["p{$i}"]]["comments_amazon"];
            $_POST["comments_flickr{$i}"] = $presets[$_POST["p{$i}"]]["comments_flickr"];
            $_POST["comments_yahoo{$i}"] = $presets[$_POST["p{$i}"]]["comments_yahoo"];
            $_POST["comments_youtube{$i}"] = $presets[$_POST["p{$i}"]]["comments_youtube"];
        } elseif ($_POST["delete{$i}"]) {
            // DELETE TEMPLATE
            $starter = $i;
            for ($x = $starter; $x <= $_POST["tnum"]; $x++) {
                $y = $x + 1;
                if ($y <= $_POST["tnum"]) {
                    $_POST["content{$x}"] = $_POST["content{$y}"];
                    $_POST["title{$x}"] = $_POST["title{$y}"];
                    $_POST["comments_amazon{$x}"] = $_POST["comments_amazon{$y}"];
                    $_POST["comments_flickr{$x}"] = $_POST["comments_flickr{$y}"];
                    $_POST["comments_yahoo{$x}"] = $_POST["comments_yahoo{$y}"];
                    $_POST["comments_youtube{$x}"] = $_POST["comments_youtube{$y}"];
                } else {
                    $_POST["content{$x}"] = "";
                    $_POST["title{$x}"] = "";
                    $_POST["comments_amazon{$x}"] = "";
                    $_POST["comments_flickr{$x}"] = "";
                    $_POST["comments_yahoo{$x}"] = "";
                    $_POST["comments_youtube{$x}"] = "";
                }
            }
            $_POST["tnum"] = $_POST["tnum"] - 1;
        }
    }
    if ($_POST['wpr_add']) {
        wpr_create_campaign();
    }
    include "add-campaigns.php";
}
Exemple #2
0
function wpr_xmlrpc_create_campaign($args) {
	global $wpr_modules;
	
	$username   = $args[0];
	$password   = $args[1];
	$_POST = $args[2];
	
	global $wp_xmlrpc_server;

	if($password != get_option('wpr_cron')) {
		if (!$user = $wp_xmlrpc_server->login($username, $password)) {
			echo '<div class="updated"><p>'.$wp_xmlrpc_server->error.'</p></div>';	
		}
	}	

	wpr_create_campaign();
	
	// MISSING: correct error return
}
Exemple #3
0
function wpr_add()
{
    global $wpdb, $wpr_table_campaigns, $wpr_table_templates, $wpr_loadedmodules, $_wp_using_ext_object_cache;
    $_wp_using_ext_object_cache = false;
    $options = unserialize(get_option("wpr_options"));
    $wpr_disabledmodules = $options["disabled_modules"];
    if (!is_array($wpr_disabledmodules)) {
        $wpr_disabledmodules = array();
    }
    if ($options['wpr_installed'] != "yes") {
        echo '<div class="wrap"><h2>WP Robot</h2><div class="updated"><h3>Installation</h3><p>' . __('Please go <a href="?page=wpr-campaigns">here</a> to finish the installation of WP Robot first.', 'wprobot') . '</p></div></div>';
        return false;
    }
    if ($options["wpr_core"] == "advanced" || $options["wpr_core"] == "basic") {
        if (!$_GET['edit']) {
            if ($options["wpr_core"] == "basic") {
                $lmt = 3;
            }
            if ($options["wpr_core"] == "advanced") {
                $lmt = 6;
            }
            $count = $wpdb->get_var("SELECT COUNT(*) FROM " . $wpr_table_campaigns);
            if ($count >= $lmt) {
                echo '<div class="wrap"><h2>WP Robot</h2><div class="updated"><h3>Limit Reached</h3><p>' . __('Only ' . $lmt . ' Campaigns per site can be used with the ' . $options["wpr_core"] . ' Core. You can upgrade <a href="http://wprobot.net/order/ordercustom.php">here</a>.', 'wprobot') . '</p></div></div>';
                return false;
            }
        }
    }
    $skippedx = 0;
    $templates = $wpdb->get_results("SELECT * FROM " . $wpr_table_templates . " WHERE `type` = 'post'");
    foreach ($templates as $template) {
        $skipmod = 0;
        $modulen = strtolower(str_replace(" ", "", str_replace(" Default", "", $template->name)));
        if (!in_array($modulen, $wpr_disabledmodules)) {
            // amazon, articlebuilder, flickr, yahooanswers, commissionjunction, oodle, shopzilla, linkshare, eventful, yelp, avantlink
            if ($modulen == "amazon" && empty($options['wpr_aa_apikey'])) {
                $skipmod = 1;
            }
            if ($modulen == "articlebuilder" && empty($options['wpr_ab_email'])) {
                $skipmod = 1;
            }
            if ($modulen == "flickr" && empty($options['wpr_fl_apikey'])) {
                $skipmod = 1;
            }
            if ($modulen == "yahooanswers" && empty($options['wpr_yap_appkey'])) {
                $skipmod = 1;
            }
            if ($modulen == "commissionjunction" && empty($options['wpr_commissionjunction_appkey'])) {
                $skipmod = 1;
            }
            if ($modulen == "oodle" && empty($options['wpr_oodle_appkey'])) {
                $skipmod = 1;
            }
            if ($modulen == "shopzilla" && empty($options['wpr_shopzilla_appkey'])) {
                $skipmod = 1;
            }
            if ($modulen == "linkshare" && empty($options['wpr_linkshare_appkey'])) {
                $skipmod = 1;
            }
            if ($modulen == "eventful" && empty($options['wpr_eventful_appkey'])) {
                $skipmod = 1;
            }
            if ($modulen == "yelp" && empty($options['wpr_yelp_appkey'])) {
                $skipmod = 1;
            }
            if ($modulen == "avantlink" && empty($options['wpr_avantlink_appkey'])) {
                $skipmod = 1;
            }
            if ($skipmod == 0) {
                $presets[$template->name]["content"] = $template->content;
                $presets[$template->name]["title"] = $template->title;
                $presets[$template->name]["comments_amazon"] = $template->comments_amazon;
                $presets[$template->name]["comments_flickr"] = $template->comments_flickr;
                $presets[$template->name]["comments_yahoo"] = $template->comments_yahoo;
                $presets[$template->name]["comments_youtube"] = $template->comments_youtube;
            } else {
                $skippedx++;
            }
        }
    }
    if ($_POST['catbut']) {
        if ($_POST['multisingle'] == "multi") {
            $_POST['multisingle'] = "single";
        } else {
            $_POST['multisingle'] = "multi";
            $_POST['categories'] = "";
        }
    }
    if ($_POST['importwpr2']) {
        $ma_dbtable = $wpdb->prefix . "wprobot";
        $records = $wpdb->get_results("SELECT * FROM " . $ma_dbtable . " ORDER BY id ASC");
        if ($records) {
            $_POST["keywords"] = "";
            foreach ($records as $record) {
                if (!empty($record->keyword)) {
                    $_POST["keywords"] .= '"' . $record->keyword . '"' . "\n";
                }
            }
        }
    }
    if ($_POST['exact']) {
        $keywordsinput = str_replace("\r", "", $_POST['keywords']);
        $keywordsinput = explode("\n", $keywordsinput);
        $_POST["keywords"] = "";
        for ($i = 0; $i < count($keywordsinput); $i++) {
            if ($keywordsinput[$i] != "") {
                $_POST["keywords"] .= '"' . $keywordsinput[$i] . '"' . "\n";
            }
        }
    }
    if ($_POST['evenchance']) {
        $chance = floor(100 / $_POST['tnum']);
        $tchance = 0;
        for ($i = 1; $i <= $_POST['tnum']; $i++) {
            $_POST["chance{$i}"] = $chance;
            $tchance = $tchance + $chance;
        }
        if ($tchance != 100) {
            $_POST["chance1"] = $_POST["chance1"] + (100 - $tchance);
        }
    }
    if ($_POST['quickrand']) {
        $count = count($presets);
        $_POST['tnum'] = rand(2, $count);
        $rand_keys = array_rand($presets, $_POST['tnum']);
        $chance = floor(100 / $_POST['tnum']);
        $i = 1;
        $tchance = 0;
        foreach ($rand_keys as $rand_key) {
            $_POST["chance{$i}"] = $chance;
            $tchance = $tchance + $chance;
            $_POST["title{$i}"] = $presets[$rand_key]["title"];
            $_POST["content{$i}"] = $presets[$rand_key]["content"];
            $_POST["comments_amazon{$i}"] = $presets[$rand_key]["comments_amazon"];
            $_POST["comments_flickr{$i}"] = $presets[$rand_key]["comments_flickr"];
            $_POST["comments_yahoo{$i}"] = $presets[$rand_key]["comments_yahoo"];
            $_POST["comments_youtube{$i}"] = $presets[$rand_key]["comments_youtube"];
            $i++;
        }
        if ($tchance != 100) {
            $_POST["chance1"] = $_POST["chance1"] + (100 - $tchance);
        }
    }
    if ($_POST['quick']) {
        $count = count($presets);
        $_POST['tnum'] = $count;
        $chance = floor(100 / $count);
        $i = 1;
        $tchance = 0;
        foreach ($presets as $prx => $preset) {
            $_POST["chance{$i}"] = $chance;
            $tchance = $tchance + $chance;
            $_POST["title{$i}"] = $preset["title"];
            $_POST["content{$i}"] = $preset["content"];
            $_POST["name{$i}"] = $prx;
            $_POST["comments_amazon{$i}"] = $preset["comments_amazon"];
            $_POST["comments_flickr{$i}"] = $preset["comments_flickr"];
            $_POST["comments_yahoo{$i}"] = $preset["comments_yahoo"];
            $_POST["comments_youtube{$i}"] = $preset["comments_youtube"];
            $i++;
        }
        if ($tchance != 100) {
            $_POST["chance1"] = $_POST["chance1"] + (100 - $tchance);
        }
    }
    if ($_POST['type1']) {
        $_POST['type'] = "keyword";
        if ($options['wpr_simple'] == 'Yes') {
            $lmcount = 0;
            $tchance = 0;
            foreach ($wpr_loadedmodules as $lmodule) {
                if ($lmodule != "translation" && $lmodule != "rss") {
                    $lmcount++;
                }
            }
            $lchance = floor(100 / $lmcount);
            foreach ($wpr_loadedmodules as $lmodule) {
                if ($lmodule != "translation" && $lmodule != "rss") {
                    if (empty($firstmodule)) {
                        $firstmodule = $lmodule;
                    }
                    $_POST[$lmodule . "chance"] = $lchance;
                    $tchance = $tchance + $lchance;
                }
            }
            if ($tchance != 100) {
                $_POST[$firstmodule . "chance"] = $_POST[$firstmodule . "chance"] + (100 - $tchance);
            }
            $_POST["mixchance"] = 0;
        }
    }
    if ($_POST['type2']) {
        $_POST["tnum"] = 1;
        $_POST["chance1"] = 100;
        $_POST['type'] = "rss";
        $_POST["content1"] = "{rss}";
        $_POST["title1"] = "{rsstitle}";
        $_POST["name1"] = "RSS Default";
        $_POST["comments_amazon1"] = 0;
        $_POST["comments_flickr1"] = 0;
        $_POST["comments_yahoo1"] = 0;
        $_POST["comments_youtube1"] = 0;
    }
    if ($_POST['type3']) {
        if (empty($_POST["tnum"])) {
            $_POST["tnum"] = 1;
        }
        $_POST['type'] = "nodes";
        if (isset($presets["Amazon Default"])) {
            $_POST["chance1"] = 100;
            $_POST["content1"] = $presets["Amazon Default"]["content"];
            $_POST["title1"] = $presets["Amazon Default"]["title"];
            $_POST["name1"] = "Amazon Default";
            $_POST["comments_amazon1"] = $presets["Amazon Default"]["comments_amazon"];
            $_POST["comments_flickr1"] = $presets["Amazon Default"]["comments_flickr"];
            $_POST["comments_yahoo1"] = $presets["Amazon Default"]["comments_yahoo"];
            $_POST["comments_youtube1"] = $presets["Amazon Default"]["comments_youtube"];
        }
    }
    if (!$_POST['evenchance'] && !$_POST['wpr_cf_remove'] && !$_POST['wpr_cf_add'] && !$_POST['wpr_add_template'] && !$_POST['wpr_add'] && !$_POST['multisingle'] && !$_POST['exact'] && !$_POST['importwpr2'] && !$_POST['quick'] && !$_POST['quickrand'] && !$_POST['type1'] && !$_POST['type2'] && !$_POST['type3']) {
        if ($_GET['edit'] || $_GET['ccopy']) {
            // EDIT or COPY CAMPAIGN
            $id = $_GET['edit'];
            if (!$id) {
                $id = $_GET['ccopy'];
            }
            $campaign = $wpdb->get_row("SELECT * FROM " . $wpr_table_campaigns . " WHERE `id` = '{$id}'");
            $_POST["name"] = $campaign->name;
            $yahoocat = unserialize($campaign->yahoo_cat);
            if (!is_array($yahoocat)) {
                $yahoocat = array();
                $yahoocat["a"] = "";
                $yahoocat["rw"] = 0;
                $yahoocat["ps"] = $campaign->yahoo_cat;
                $yahoocat["pt"] = "";
            }
            $_POST["wpr_poststatus"] = $yahoocat["ps"];
            $_POST["wpr_rewriter"] = $yahoocat["rw"];
            $_POST["wpr_author"] = $yahoocat["a"];
            $_POST['wpr_postthumbs'] = $yahoocat["t"];
            $_POST['wpr_posttype'] = $yahoocat["pt"];
            $_POST["type"] = $campaign->ctype;
            if ($_GET['ccopy']) {
                $_POST["name"] .= " Copy";
            }
            $_POST["interval"] = $campaign->cinterval;
            $_POST["period"] = $campaign->period;
            if ($campaign->pause == 0) {
                $_POST["autopost"] = "yes";
            }
            $_POST['multisingle'] = "multi";
            $_POST["amazon_department"] = $campaign->amazon_department;
            $_POST["ebay_category"] = $campaign->ebay_cat;
            $exclude = unserialize($campaign->excludekws);
            for ($i = 0; $i < count($exclude); $i++) {
                $_POST["exclude"] .= $exclude[$i] . "\n";
            }
            $replace = unserialize($campaign->replacekws);
            for ($i = 0; $i < count($replace); $i++) {
                $_POST["replace"] .= $replace[$i]["from"] . "|" . $replace[$i]["to"] . "|" . $replace[$i]["chance"] . "|" . $replace[$i]["code"] . "\n";
            }
            $keywords = unserialize($campaign->keywords);
            $_POST["keywords"] = "";
            $_POST["feeds"] = "";
            $_POST["nodes"] = "";
            for ($i = 0; $i < count($keywords); $i++) {
                $_POST["keywords"] .= $keywords[$i][0] . "\n";
                if ($campaign->ctype == "rss") {
                    $_POST["feeds"] .= $keywords[$i]["feed"] . "\n";
                } elseif ($campaign->ctype == "nodes") {
                    $_POST["nodes"] .= $keywords[$i]["node"] . "\n";
                }
            }
            $categories = unserialize($campaign->categories);
            if (!empty($categories[0]["id"])) {
                $categories = wpr_transform_cats($categories);
            }
            if (count($categories) == 1) {
                $_POST['multisingle'] = "single";
                $_POST['categories'] = $categories[0][0]["id"];
            } else {
                for ($i = 0; $i < count($categories); $i++) {
                    for ($o = 0; $o < count($categories[$i]); $o++) {
                        $_POST["categories"] .= $categories[$i][$o]["name"];
                        if ($o != count($categories[$i]) - 1) {
                            $_POST["categories"] .= ",";
                        }
                    }
                    $_POST["categories"] .= "\n";
                }
            }
            $templates = unserialize($campaign->templates);
            if ($options['wpr_simple'] == 'Yes' && $campaign->ctype == "keyword") {
                foreach ($wpr_loadedmodules as $lmodule) {
                    if ($lmodule != "translation" && $lmodule != "rss") {
                        $_POST[$lmodule . "chance"] = 0;
                    }
                }
                $_POST["mixchance"] = 0;
                for ($i = 1; $i <= count($templates); $i++) {
                    $lmodule = str_replace('{', '', $templates[$i]["title"]);
                    $lmodule = str_replace('title}', '', $lmodule);
                    $_POST[$lmodule . "chance"] = $templates[$i]["chance"];
                    if ($lmodule == "") {
                        $_POST["mixcontent"] = $templates[$i]["content"];
                    }
                }
                if ($_POST["chance"] > 0) {
                    $_POST["mixchance"] = $_POST["chance"];
                }
            } else {
                $_POST['tnum'] = count($templates);
                for ($i = 1; $i <= count($templates); $i++) {
                    $_POST["chance{$i}"] = $templates[$i]["chance"];
                    $_POST["title{$i}"] = $templates[$i]["title"];
                    $_POST["content{$i}"] = $templates[$i]["content"];
                    $_POST["comments_amazon{$i}"] = $templates[$i]["comments"]["amazon"];
                    $_POST["comments_flickr{$i}"] = $templates[$i]["comments"]["flickr"];
                    $_POST["comments_yahoo{$i}"] = $templates[$i]["comments"]["yahooanswers"];
                    $_POST["comments_youtube{$i}"] = $templates[$i]["comments"]["youtube"];
                }
            }
            $customfields = unserialize($campaign->customfield);
            if (isset($customfields["name"])) {
                $_POST["cf_name1"] = $customfields["name"];
                $_POST["cf_value1"] = $customfields["value"];
            } else {
                $_POST['cfnum'] = count($customfields);
                for ($i = 1; $i <= count($customfields); $i++) {
                    $_POST["cf_name{$i}"] = $customfields[$i]["name"];
                    $_POST["cf_value{$i}"] = $customfields[$i]["value"];
                }
            }
            $translation = unserialize($campaign->translation);
            $_POST["transchance"] = $translation["chance"];
            $_POST["trans1"] = $translation["from"];
            $_POST["trans2"] = $translation["to1"];
            $_POST["trans3"] = $translation["to2"];
            $_POST["trans4"] = $translation["to3"];
            $_POST['trans_comments'] = $translation["comments"];
        } else {
            $lid = $wpdb->get_var("SELECT id FROM {$wpr_table_campaigns} ORDER BY id DESC;");
            if ($lid == "") {
                $lid = 0;
            }
            $lid++;
            if (WPLANG == "de_DE") {
                $cnm = "Kampagne";
            } else {
                $cnm = "Campaign";
            }
            $_POST["name"] = "{$cnm} {$lid}";
            $_POST["interval"] = rand(12, 96);
            $_POST["chance1"] = 100;
            if ($options['wpr_simple'] == 'Yes') {
                $lmcount = 0;
                $tchance = 0;
                foreach ($wpr_loadedmodules as $lmodule) {
                    if ($lmodule != "translation" && $lmodule != "rss") {
                        $lmcount++;
                    }
                }
                $lchance = floor(100 / $lmcount);
                foreach ($wpr_loadedmodules as $lmodule) {
                    if ($lmodule != "translation" && $lmodule != "rss") {
                        if (empty($firstmodule)) {
                            $firstmodule = $lmodule;
                        }
                        $_POST[$lmodule . "chance"] = $lchance;
                        $tchance = $tchance + $lchance;
                    }
                }
                if ($tchance != 100) {
                    $_POST[$firstmodule . "chance"] = $_POST[$firstmodule . "chance"] + (100 - $tchance);
                }
                $_POST["mixchance"] = 0;
            } else {
                /*$rand = array_rand($presets); NO RAND TEMPLATE
                		$_POST["content1"] = $presets[$rand]["content"];
                		$_POST["title1"] = $presets[$rand]["title"];
                		$_POST["comments_amazon1"] = $presets[$rand]["comments_amazon"];
                		$_POST["comments_flickr1"] = $presets[$rand]["comments_flickr"];
                		$_POST["comments_yahoo1"] = $presets[$rand]["comments_yahoo"];
                		$_POST["comments_youtube1"] = $presets[$rand]["comments_youtube"];*/
            }
            $_POST['multisingle'] = "multi";
            $_POST['autopost'] = "yes";
            $_POST['createcats'] = "yes";
            $_POST['transchance'] = "0";
            $_POST['delaystart'] = "0";
            $_POST['type'] = "keyword";
        }
    }
    if ($_POST['wpr_cf_add']) {
        $_POST['cfnum'] = $_POST['cfnum'] + 1;
    }
    if ($_POST['wpr_cf_remove']) {
        $_POST['cfnum'] = $_POST['cfnum'] - 1;
    }
    if ($_POST['wpr_add_template']) {
        $_POST['tnum'] = $_POST['tnum'] + 1;
        $xi = $_POST['tnum'];
        if ($_POST['wpr_add_template_preset'] == "Random") {
            $rand = array_rand($presets);
            $_POST["content{$xi}"] = $presets[$rand]["content"];
            $_POST["title{$xi}"] = $presets[$rand]["title"];
            $_POST["name{$xi}"] = $rand;
            $_POST["comments_amazon{$xi}"] = $presets[$rand]["comments_amazon"];
            $_POST["comments_flickr{$xi}"] = $presets[$rand]["comments_flickr"];
            $_POST["comments_yahoo{$xi}"] = $presets[$rand]["comments_yahoo"];
            $_POST["comments_youtube{$xi}"] = $presets[$rand]["comments_youtube"];
        } else {
            $_POST["content{$xi}"] = $presets[$_POST['wpr_add_template_preset']]["content"];
            $_POST["title{$xi}"] = $presets[$_POST['wpr_add_template_preset']]["title"];
            $_POST["name{$xi}"] = $_POST['wpr_add_template_preset'];
            $_POST["comments_amazon{$xi}"] = $presets[$_POST['wpr_add_template_preset']]["comments_amazon"];
            $_POST["comments_flickr{$xi}"] = $presets[$_POST['wpr_add_template_preset']]["comments_flickr"];
            $_POST["comments_yahoo{$xi}"] = $presets[$_POST['wpr_add_template_preset']]["comments_yahoo"];
            $_POST["comments_youtube{$xi}"] = $presets[$_POST['wpr_add_template_preset']]["comments_youtube"];
        }
        $chance = floor(100 / $_POST['tnum']);
        $tchance = 0;
        for ($i = 1; $i <= $_POST['tnum']; $i++) {
            $_POST["chance{$i}"] = $chance;
            $tchance = $tchance + $chance;
        }
        if ($tchance != 100) {
            $_POST["chance1"] = $_POST["chance1"] + (100 - $tchance);
        }
    }
    for ($i = 1; $i <= $_POST["tnum"]; $i++) {
        if ($_POST["load{$i}"]) {
            // LOAD PRESET
            $_POST["content{$i}"] = $presets[$_POST["p{$i}"]]["content"];
            $_POST["title{$i}"] = $presets[$_POST["p{$i}"]]["title"];
            $_POST["name{$i}"] = $_POST["p{$i}"]["name"];
            $_POST["comments_amazon{$i}"] = $presets[$_POST["p{$i}"]]["comments_amazon"];
            $_POST["comments_flickr{$i}"] = $presets[$_POST["p{$i}"]]["comments_flickr"];
            $_POST["comments_yahoo{$i}"] = $presets[$_POST["p{$i}"]]["comments_yahoo"];
            $_POST["comments_youtube{$i}"] = $presets[$_POST["p{$i}"]]["comments_youtube"];
        } elseif ($_POST["delete{$i}"]) {
            // DELETE TEMPLATE
            $starter = $i;
            for ($x = $starter; $x <= $_POST["tnum"]; $x++) {
                $y = $x + 1;
                if ($y <= $_POST["tnum"]) {
                    $_POST["content{$x}"] = $_POST["content{$y}"];
                    $_POST["title{$x}"] = $_POST["title{$y}"];
                    $_POST["name{$x}"] = $_POST["name{$y}"];
                    $_POST["comments_amazon{$x}"] = $_POST["comments_amazon{$y}"];
                    $_POST["comments_flickr{$x}"] = $_POST["comments_flickr{$y}"];
                    $_POST["comments_yahoo{$x}"] = $_POST["comments_yahoo{$y}"];
                    $_POST["comments_youtube{$x}"] = $_POST["comments_youtube{$y}"];
                } else {
                    $_POST["content{$x}"] = "";
                    $_POST["title{$x}"] = "";
                    $_POST["name{$x}"] = "";
                    $_POST["comments_amazon{$x}"] = "";
                    $_POST["comments_flickr{$x}"] = "";
                    $_POST["comments_yahoo{$x}"] = "";
                    $_POST["comments_youtube{$x}"] = "";
                }
            }
            $_POST["tnum"] = $_POST["tnum"] - 1;
            $chance = floor(100 / $_POST['tnum']);
            $tchance = 0;
            for ($i = 1; $i <= $_POST['tnum']; $i++) {
                $_POST["chance{$i}"] = $chance;
                $tchance = $tchance + $chance;
            }
            if ($tchance != 100) {
                $_POST["chance1"] = $_POST["chance1"] + (100 - $tchance);
            }
        }
    }
    if ($_POST['wpr_add']) {
        wpr_create_campaign();
    }
    include "add-campaigns.php";
}