<?php

/**
 *
 * @copyright  2016-2017 izend.org
 * @version    1
 * @link       http://www.izend.org
 */

function campaignedit($lang, $arglist=false) {
	global $supported_languages;

	$campaign=$page=false;

	if (is_array($arglist)) {
		if (isset($arglist[0])) {
			$campaign=$arglist[0];
		}
		if (isset($arglist[1])) {
			$page=$arglist[1];
		}
	}

	$clang=false;
	foreach ($supported_languages as $slang) {
		if (isset($_POST[$slang])) {
			$clang=$slang;
			break;
		}
	}
	if (!$clang) {
		if (isset($_POST['clang'])) {
			$clang = $_POST['clang'];
		}
		else if (isset($_GET['clang'])) {
			$clang = $_GET['clang'];
		}
		else {
			$clang=$lang;
		}
		if (!in_array($clang, $supported_languages)) {
			return run('error/notfound', $lang);
		}
	}

	if (!$campaign) {
		return run('error/notfound', $lang);
	}

	if (!$page) {
		require_once 'actions/campaigneditsummary.php';

		return campaigneditsummary($lang, $clang, $campaign);
	}

	require_once 'actions/campaigneditpage.php';

	return campaigneditpage($lang, $clang, $campaign, $page);
}

