<?php

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

require_once 'userhasrole.php';
require_once 'userprofile.php';
require_once 'models/sms.inc';

function campaign($lang, $arglist=false) {
	$campaign=$page=false;

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

	if (!$campaign) {
		if (user_has_role('administrator')) {
			require_once 'actions/campaignall.php';

			return campaignall($lang);
		}

		$user_id=user_profile('id');

		if (!$user_id) {
			return run('error/unauthorized', $lang);
		}

		$campaign=sms_get_user_campaign_id($user_id);

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

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

		return campaignsummary($lang, $campaign);
	}

	require_once 'actions/campaignpage.php';

	return campaignpage($lang, $campaign, $page);
}

