Esempio n. 1
0
def main(cursor):
	campaign_id = int(common.get_val('campaign', -1))
	team_id = int(common.get_val('team', -1))
	army_names_normal = common.get_val('army_names', "").replace("\n", ",").split(",")
	
	# Get last battle
	last_battle = battle_q.get_last_battle_from_campaign(cursor, campaign_id)
	if not last_battle:
		page_data['Redirect'] = 'setup_campaign&campaign=%d' % campaign_id
		return ""
	
	start_time = last_battle.start
	
	army_names = []
	for a in army_names_normal:
		army_names.append(a.lower().strip())
	
	army_dict = army_q.get_armies_from_team(cursor, team_id, True)
	army_list = []
	
	queries = []
	for army_id, the_army in army_dict.items():
		if the_army.name.lower() in army_names:
			queries.append("INSERT INTO campaign_armies (campaign, army, started) values (%d, %d, %d);" % (campaign_id, army_id, start_time))
	
	# print("")
	# print([a.name.lower() for i, a in army_dict.items()], "<br />")
	# print(army_names)
	# print("<br />".join(queries))
	# exit()
	
	# print("")
	# print(queries)
	# exit()
	
	for q in queries:
		try:
			cursor.execute(q)
		except Exception as e:
			pass
			# raise Exception("Database error: %s\nQuery: %s" % (str(e.args[0]).replace("\n",""), q))
	
	# if queries == []:
	# 	print("")
	# 	print(army_names)
	# 	
	# 	exit()
	
	# Redirect
	page_data['Redirect'] = 'setup_campaign&campaign={0:d}'.format(campaign_id)
Esempio n. 2
0
def _draw_map(cursor, team_id, build):
	minx, maxx = 999999, -9999999
	miny, maxy = 999999, -9999999
	
	city_dict = city_q.get_cities_from_team(cursor, team_id, include_dead=False)
	for city_id, the_city in city_dict.items():
		minx = min(minx, the_city.x)
		maxx = max(maxx, the_city.x)
		
		miny = min(miny, the_city.y)
		maxy = max(maxy, the_city.y)
	
	army_dict = army_q.get_armies_from_team(cursor, team_id, include_garrisons=False)
	for army_id, the_army in army_dict.items():
		minx = min(minx, the_army.x)
		maxx = max(maxx, the_army.x)
		
		miny = min(miny, the_army.y)
		maxy = max(maxy, the_army.y)
	
	centre = (int((maxx+minx)/2), int((maxy+miny)/2))
	radius = max((maxx-minx), (maxy-miny)) + 300
	
	the_map = mapper.Map_maker()
	the_map.centre = centre
	the_map.centre_radius = radius
	the_map.personalise	= [team_id]
	
	if build != 0:# Remote mode
		the_map.icon_path = '../map/images/teamIcons/'
	
	onclick_js = """
	var map_x = parseInt(document.getElementById('labelHideX').innerHTML);
	var map_y = parseInt(document.getElementById('labelHideY').innerHTML);
	
	use_map_xy(map_x, map_y);"""
	
	source_dict = {
		"build":				build,
		"onclick_js":			onclick_js,
		
		"output":				the_map.map_grid(cursor),
		
		# 'map_path':				"../map/images/theMap.jpg",
		# 'jquery':				"../includes/jquery.js",
		# 'transparent_path':		"../map/images/trans75.png",
		# 'key_path':				"../map/images/key.png",
	}
	
	source_dict['map_legend']	= ''
	
	source_dict["left"]			= the_map.left * 2.5
	source_dict["right"]		= the_map.right
	source_dict["top"]			= the_map.top * 2.5
	source_dict["bottom"]		= the_map.bottom
	
	source_dict["map_width"]	= the_map.width*2.5
	source_dict["map_height"]	= the_map.height*2.5
	
	x_diff = map_data.dimensions['left'] - the_map.left
	y_diff = map_data.dimensions['top'] - the_map.top
	source_dict["margin_left"]	= (x_diff + map_data.dimensions['margin_left'])*2.5
	source_dict["margin_top"]	= (y_diff + map_data.dimensions['margin_top'])*2.5
	
	if build:
		source_dict['map_path']			= '../map/images/theMap.jpg'
		source_dict['jquery']			= "../includes/jquery.js"
		source_dict['transparent_path']	= "../map/images/trans75.png"
		source_dict['key_path']			= "../map/images/key.png"
	
	output = mapper.map_source(source_dict)
	
	return output
Esempio n. 3
0
def main(cursor):
	squad_id = int(common.get_val('squad'))
	
	the_squad = squad_q.get_one_squad(cursor, squad_id)
	armies_dict = army_q.get_armies_from_team(cursor, the_squad.team, include_garrisons=True)
	the_unit = unit_q.get_one_unit(cursor, the_squad.unit)
	
	names = {}
	for a, the_army in armies_dict.items():
		names[a] = the_army.name
	
	output = []
	
	output.append("<div style='padding: 5px;'>")
	
	output.append("""
	<form action="exec.py" id="the_squad_form" method="post" accept-charset="utf-8">
		<input type="hidden" name="mode" id="mode" value="edit_squad_commit" />
		<input type="hidden" name="id" id="id" value="%(squad_id)s" />
		
		<label for="name">Editing:</label> %(name_text)s
		<br /><br />
		
		<table border="0" cellspacing="5" cellpadding="5">
			<tr>
				<td><label for="army">Army:</label></td>
				<td style="padding: 1px;">%(army_select)s</td>
			
				<td width="5">&nbsp;</td>
			
				<td>Type: </td>
				<td>%(unit_type)s</td>
			</tr>
			<tr>
				<td><label for="amount">Amount:</label></td>
				<td>%(amount)s</td>
			
				<td>&nbsp;</td>
			
				<td><label for="experience">Experince:</label></td>
				<td>%(experience)s</td>
			</tr>
			<tr>
				<td colspan="5">
					<strong>%(unit_name)s</strong>: %(unit_description)s
				</td>
			</tr>
			<tr>
				<td colspan="5">
					<input type="submit" value="Apply" />
				</td>
			</tr>
		</table>
	</form>
	<form id="delete_form" action="exec.py" method="post" accept-charset="utf-8">
		<input type="hidden" name="squad" id="squad" value="%(squad_id)s" />
		<input type="hidden" name="mode" id="mode" value="remove_squad" />
		<input style="float:right; margin-right:100px;" type="button" value="Delete squad" onclick="var answer = confirm('Delete %(name)s?')
		if (answer) $('#delete_form').submit();" />
	</form>
	<br /><br />""" % {
		"squad_id":			squad_id,
		"name":				the_squad.name,
		"name_text":		common.text_box("name", the_squad.name),
		"unit_type":		the_unit.name,
		"army_select":		common.option_box(
			name='army',
			elements=names,
			element_order=armies_dict.keys(),
			custom_id="army",
			selected=the_squad.army,
		),
		
		"unit_name":		the_unit.name,
		"unit_description":	the_unit.equipment_string,
		
		"amount":			common.text_box("amount", the_squad.amount),
		"experience":		common.text_box("experience", the_squad.experience),
	})
	
	output.append("</div>")
	
	page_data['Title'] = "Editing squad (%s)" % the_squad.name
	return "".join(output)
Esempio n. 4
0
def main(cursor):
	# Get team Id
	team_id = int(common.get_val('team', 0))
	text_location = common.get_val('location', "")
	
	# Build team
	the_team = team_q.get_one_team(cursor, team_id)
	cities_dict = city_q.get_cities_from_team(cursor, team=team_id, include_dead=0)
	
	if team_id < 1:
		return "<div style='padding: 5px;'>%s</div>" %  common.select_team_form(cursor, 'list_armies')
		exit()
	
	armies_dict = army_q.get_armies_from_team(cursor, team=team_id, include_garrisons=1)
	
	output = []
	output.append("""
	<table border="0" cellspacing="0" cellpadding="5" style="width: 100%;">
		<tr class="row2">
			<th>Army</th>
			<th>Location</th>
			<th>Base</th>
			<th>Size</th>
			<th>&nbsp;</th>
			<th>&nbsp;</th>
		</tr>""")
	
	names = {}
	
	if len(armies_dict) > 0:
		count = -1
		
		# for team_id, team in team_dict.items():
		for army_id, the_army in armies_dict.items():
			count += 1
			
			city_location = the_army.garrison
			
			if the_army.garrison > 0:
				location = "Garrison"
			
			else:
				location = "%s, %s" % (the_army.x, the_army.y)
			
			if the_army.base in cities_dict:
				base_name = cities_dict[the_army.base].name
			else:
				base_name = "N/A"
			
			output.append("""
			<tr class="row%(row)d" id="%(army_id)d">
				<td><strong>%(name)s</strong></td>
				<td>%(location)s</td>
				<td>%(base)s</td>
				<td>%(size)s</td>
				
				<td style="padding: 0px;">
					<a class="block_link" id="show_squads_%(army_id)d" href="#" onclick="$('#div_%(army_id)d').load('web.py', {'mode':'list_squads', 'ajax':'True', 'army':'%(army_id)d'}, function () {$('#tr_%(army_id)d').fadeIn(0); $('#show_squads_%(army_id)d').fadeOut(0); $('#hide_squads_%(army_id)d').fadeIn(0);}); return false;">Show squads</a>
				<a id="hide_squads_%(army_id)d" style="display:none;" class="block_link" href="#" onclick="$('#tr_%(army_id)d').fadeOut(0); $('#show_squads_%(army_id)d').fadeIn(0); $('#hide_squads_%(army_id)d').fadeOut(0); return false;">Hide squads</a></td>
				
				<td style="padding: 0px;"><a class="block_link" href="web.py?mode=edit_army&amp;army=%(army_id)d">Edit army</a></td>
			</tr>
			<tr style="display: none;" id="tr_%(army_id)d">
				<td colspan="5" style="padding: 0 10px 10px 10px;">
					<div id="div_%(army_id)d">
						&nbsp;
					</div>
				</td>
			</tr>
			""" % {	'row': (count % 2),
					
					"army_id":		army_id,
					"name":			common.doubleclick_text("armies", "name", army_id, the_army.name, "font-weight:bold", size=18),
					"base":			base_name,
					"location":		location,
					"size":			the_army.get_size(cursor),
					})
	
	# Add new army thingie
	names = {}
	for c, the_city in cities_dict.items():
		names[c] = the_city.name
	
	count += 1
	output.append("""
	<tr class="row%(row)d">
		<form action="exec.py" id="add_army_form" method="post" accept-charset="utf-8">
		<input type="hidden" name="mode" value="add_army" />
		<input type="hidden" name="team" value="%(team_id)s" />
		<td style="padding: 1px;"><input type="text" id="new_name" name="name" value="" /></td>
		<td>&nbsp;</td>
		<td style="padding: 1px;">
			%(city_location)s
			&nbsp;&nbsp;&nbsp;
			%(text_location)s
		</td>
		<td style="padding: 0px;"><a href="web.py?mode=view_map&amp;new_mode=list_armies&amp;team=%(team_id)s" class="block_link">Pick location</a></td>
		<td colspan="2" style="padding: 0px;"><a class="block_link" href="#" onclick="$('#add_army_form').submit(); return false;">Add</a></td>
		</form>
		%(onload)s
	</tr>
	""" % {	'row': (count % 2),
			
			"team_id":			team_id,
			'city_location':	common.option_box(
				name='city_location',
				elements=names,
				element_order=cities_dict.keys(),
				custom_id="",
			),
			
			"text_location":	common.text_box("text_location", text_location, custom_id=""),
			"onload":			common.onload("$('#new_name').focus();")
			})	
	
	output.append("</table>")
	
	return "".join(output)
Esempio n. 5
0
def main(cursor):
	team_id = int(common.get_val('team', 0))
	confirm = int(common.get_val('confirm', 0))
	
	if team_id < 1:
		return "<div style='padding: 5px;'>{0}</div>".format(common.select_team_form(cursor, 'purge_team'))
	
	if confirm == 0:
		return """
		<form action="web.py" method="post" accept-charset="utf-8" style="padding: 10px;">
			<input type="hidden" name="mode" id="mode" value="purge_team" />
			<input type="hidden" name="team" id="team" value="{0}" />
			<input type="hidden" name="confirm" id="confirm" value="1" />
			Are you sure?<br /><br />
			<input type="submit" value="Purge team" />
		</form>
		""".format(team_id)
	
	# Query the DB for some info
	city_dict = city_q.get_cities_from_team(cursor, team_id, include_dead=True)
	army_dict = army_q.get_armies_from_team(cursor, team_id, include_garrisons=True)
	squad_dict = squad_q.get_squads_from_team(cursor, team_id)
	
	# Turn the dictionaries into lists
	city_list = [str(c) for c in city_dict]
	army_list = [str(a) for a in army_dict]
	squad_list = [str(s) for s in squad_dict]
	
	queries = []
	
	if len(army_list) > 0:
		# Wipe squads
		queries.append("DELETE FROM squads WHERE army IN (%s)" % ",".join(army_list))
		queries.append("DELETE FROM army_monsters WHERE army IN (%s)" % ",".join(army_list))
		queries.append("DELETE FROM campaign_armies WHERE army IN (%s)" % ",".join(army_list))
		
		# Wipe armies
		queries.append("DELETE FROM armies WHERE id IN (%s)" % ",".join(army_list))
	
	if len(city_list) > 0:
		# Wipe buildings
		queries.append("DELETE FROM city_buildings WHERE city IN (%s)" % ",".join(city_list))
		
		# Wipe garrisons
		# queries.append("DELETE FROM armies WHERE garrison IN (%s)" % ",".join(city_list))
		
		# Wipe cities
		queries.append("UPDATE operatives SET city = 0 WHERE city IN (%s)" % ",".join(city_list))
		queries.append("DELETE FROM cities WHERE id IN (%s)" % ",".join(city_list))
		
		# Wipe buildings
		queries.append("DELETE FROM city_buildings WHERE city IN (%s)" % ",".join(city_list))
	
	if len(squad_list) > 0:
		# Wipe squad battle history
		queries.append("DELETE FROM squad_battle_history WHERE squad IN (%s)" % ",".join(squad_list))
	
	# Operatives
	queries.append("DELETE FROM operatives WHERE team = %s" % team_id)
	
	# Spy reports
	queries.append("DELETE FROM spy_reports WHERE team = %s" % team_id)
	
	# Resources
	queries.append("UPDATE team_resources SET amount = 0 WHERE team = %d" % int(team_id))
	queries.append("UPDATE team_resources SET amount = 1500 WHERE team = %d AND resource = 0" % int(team_id))
	queries.append("UPDATE team_resources SET amount = 300 WHERE team = %d AND resource = 1" % int(team_id))
	
	database.query_batch(cursor, queries)
	
	
	return "<br />".join(queries)
Esempio n. 6
0
def main(cursor, campaign_id=-1):
	output = ['<div style="padding: 5px;">']
	
	grab_coords = common.get_val('coords', '')
	radius = int(common.get_val('radius', 10))
	
	if grab_coords != '' and radius > 0:
		# 138, 1224
		grabbed_armies = grab_armies(cursor, grab_coords, radius)
	else:
		grabbed_armies = ""
	
	campaign_id = int(common.get_val('campaign', campaign_id))
	if campaign_id < 1:
		return "No city selected"
	
	# Get stuff from DB
	the_campaign = campaign_q.get_one_campaign(cursor, campaign_id)
	team_dict = team_q.get_all_teams(cursor)
	city_dict = city_q.get_cities_for_dropdown(cursor)
	battle_dict = battle_q.get_battles_from_campaign(cursor, campaign_id)
	
	if len(battle_dict) < 1:
		return common.redirect("web.py?mode=list_battles&campaign=%d" % campaign_id)
	
	# last_battle = battle_dict[list(battle_dict.keys())[-1]]
	last_battle = battle_q.get_last_battle_from_campaign(cursor, campaign_id)
	if not last_battle:
		return common.redirect("web.py?mode=list_battles&campaign=%d" % campaign_id)
	
	# coords_cities
	coords_cities = ['<select name="coords">']
	for city_id, the_city in city_dict.items():
		if city_id == last_battle.city:
			coords_cities.append("<option value='%s,%s' selected='selected'>%s</option>" % (the_city.x, the_city.y, the_city.name))
		else:
			coords_cities.append("<option value='%s,%s'>%s</option>" % (the_city.x, the_city.y, the_city.name))
	
	coords_cities.append("</select>")
	coords_cities = "".join(coords_cities)
	
	output.append("""
	<a href="web.py?mode=list_campaigns&amp;turn={turn}" class="block_link" style="display:inline; text-align:left;">Campaigns of this turn</a>
	<a href="web.py?mode=list_battles&amp;campaign={id}" class="block_link" style="display:inline;">List battles</a>
	<a href="web.py?mode=perform_battle&amp;battle={last_battle}" class="block_link" style="display:inline;">Last battle</a>
	<br /><br />
	<form action="exec.py" id="mass_add_army_form" method="post" accept-charset="utf-8" style="display:block; float:right; border: 0px solid #000; margin-right:20px;">
		<strong>Mass add units</strong><br />
		<input type="hidden" name="mode" value="mass_add_armies" />
		<input type="hidden" name="campaign" value="{id}" />
		{team_list}
		<br />
		<textarea name="army_names" rows="10" cols="40">{grabbed_armies}</textarea>
		<br />
		<input type="submit" value="Add armies" />
		<br /><br />
	</form>
	
	<form action="web.py" id="grab_armies_form_cities" method="get" accept-charset="utf-8" style="display:block; float:right; border: 0px solid #000; margin-right:20px;">
		<strong>Grab armies</strong><br />
		<input type="hidden" name="mode" value="setup_campaign" />
		<input type="hidden" name="campaign" value="{id}" />
		<label for="coords">Coords: </label>{coords_cities}<br />
		<label for="radius">Radius: </label><input type="text" name="radius" id="radius" value="10" /><br />
		<input type="submit" value="Grab armies" />
		<br /><br />
	</form>
	
	<form action="web.py" id="grab_armies_form" method="get" accept-charset="utf-8" style="display:block; float:right; border: 0px solid #000; margin-right:20px;">
		<strong>Grab armies</strong><br />
		<input type="hidden" name="mode" value="setup_campaign" />
		<input type="hidden" name="campaign" value="{id}" />
		<label for="coords">Coords: </label><input type="text" name="coords" id="coords" value="{default_coods}" /><br />
		<label for="radius">Radius: </label><input type="text" name="radius" id="radius" value="10" /><br />
		<input type="submit" value="Grab armies" />
		<br /><br />
	</form>
	
	<form action="exec.py" method="post" accept-charset="utf-8">
		<input type="hidden" name="mode" id="mode" value="setup_campaign_commit" />
		<input type="hidden" name="id" id="id" value="{id}" />
		
		Editing: {name_text}
		<br /><br />
		
		<table border="0" cellspacing="5" cellpadding="5">
			<tr>
				<td><label for="turn">Turn:</label></td>
				<td style="padding: 1px;">{turn_text}</td>
				
				<td width="5">&nbsp;</td>
				
				<td><label for="turn">Sides:</label></td>
				<td style="padding: 1px;">{sides_text}</td>
			</tr>
		</table>
		<br />
		<input type="submit" value="Perform edit" />
	</form>
	<br /><br />""".format(
		id =					campaign_id,
		name =					the_campaign.name,
		turn =					the_campaign.turn,
		name_text =				common.text_box("name", the_campaign.name, size=20),
		turn_text =				common.text_box("turn", the_campaign.turn, size=5),
		sides_text =			common.text_box("sides", the_campaign.sides, size=5),
		team_list				= team_f.structured_list(cursor, include_irs=True),
		grabbed_armies			= grabbed_armies,
		last_battle				= last_battle.id,
		coords_cities			= coords_cities,
		default_coods			= "%s, %s" % (last_battle.x, last_battle.y),
	))
	
	# Sides and teams
	side_form = ['<select id="side_menu">']
	
	for s in range(1, the_campaign.sides+1):
		side_form.append('<option value="{s}">{s}</option>'.format(s=s))
	
	side_form.append("</select>")
	side_form = "".join(side_form)
	
	# Form JS
	js = """
	var side = $("#side_menu").attr("value");
	var team_id = $("#new_team").attr("value");
	var team_name = $("#new_team :selected").text();
	
	team_list_content = $("#team_list_" + side).html();
	
	if (team_list_content != "")
	{
		$("#team_list_" + side).html(team_list_content + ", " + team_name);
	}
	else
	{
		$("#team_list_" + side).html(team_name);
	}
	
	$("#ajax_target").load("exec.py", {mode: "add_team_to_campaign", campaign: %s, side: side, team: team_id});
	$("#new_team").focus();
	return false;
	""" % campaign_id
	
	js = js.replace("\t", "").replace("\n", "")
	
	output.append('''
	<form action="" onsubmit='{js}' method="post" accept-charset="utf-8">
		{team_list}
		{side}
		
		<input type="submit" value="Add" />
	</form>
	
	<!-- PY -->
	<form action="exec.py" method="post" accept-charset="utf-8">
		<input type="hidden" name="mode" value="edit_campaign_armies" />
		<input type="hidden" name="campaign" value="{c}" />
		<input type="submit" value="Apply armies" />
		<!-- PYEND -->
		<table border="0" cellspacing="0" cellpadding="5" style="width:99%">
			<tr class="row2">
				<th width="15">#</th>
				<th>Teams</th>
			</tr>
	'''.format(
		c=campaign_id,
		team_list=team_f.structured_list(cursor, include_irs=True, field_id="new_team"),
		side=side_form,
		js=js,
	))
	
	army_ids = []
	
	the_campaign.get_sides_full(cursor)
	the_campaign.get_armies_full(cursor)
	campaign_armies = campaign_q.get_campaign_armies_from_turn(cursor, the_campaign.turn)
	teams_on_side_str = []
	for s in range(1, the_campaign.sides+1):
		teams_on_side = the_campaign.sides_full[s]
		
		if len(teams_on_side) > 0:
			teams_on_side_str = ['<table border="0" cellspacing="0" cellpadding="5" width="100%">']
			for t in teams_on_side:
				where = "campaign=%d and team=%d" % (campaign_id, t['team'])
				
				# Display "make secret" or "make public"
				public_display, secret_display = "", ""
				if t['secret']:	secret_display	= "display: none;"
				else:			public_display	= "display: none;"
				
				teams_on_side_str.append("""
				<tr id="team_row_{t}" class="row1">
					<td width="100">{name}</td>
					<td width="65">
						{started}
						-&gt;
						{finished}
					</td>
					<td>{remove}</td>
					<td>
					<a href="#" id="team_public_{t}"
						onclick="$('#ajax_target').load('web.py', {{mode:'campaign_team_public', team:{t}, campaign:{c}}}); {show_hide} return false;" class="mini_link" style="{public_display}">Make public</a>
					<a href="#" id="team_secret_{t}"
						onclick="$('#ajax_target').load('web.py', {{mode:'campaign_team_secret', team:{t}, campaign:{c}}}); {show_hide} return false;" class="mini_link" style="{secret_display}'">Make secret</a>
					</td>
				</tr>
				""".format(
					t = t['team'],
					c = campaign_id,
					name=team_dict[t['team']].name,
					started=common.doubleclick_text_full("campaign_teams", "started", where, t['started'], size=2),
					finished=common.doubleclick_text_full("campaign_teams", "finished", where, t['finished'], size=2),
					remove='''<a href="#" onclick='$("#ajax_target").load("exec.py", {mode: "remove_team_from_campaign", campaign: %d, team: %d, side: %d}); $("#team_row_%d").hide(); return false;'>Remove</a>''' % (campaign_id, t['team'], s, t['team']),
					
					show_hide = "$('#team_public_%d').toggle(); $('#team_secret_%d').toggle();" % (t['team'], t['team']),
					
					public_display = public_display,
					secret_display = secret_display,
				))
				
				# Now to put in the armies form
				army_form = []
				garrison_form = []
				
				team_armies = army_q.get_armies_from_team(cursor, t['team'], include_garrisons=True)
				# the_campaign.get_armies_full
				for army_id, the_army in team_armies.items():
					selected = False
					start_finish = ""
					
					if army_id in the_campaign.armies_full:
						selected = True
						where = "campaign=%d and army=%d" % (campaign_id, army_id)
						
						start_finish = "%s -&gt; %s" % (
							common.doubleclick_text_full("campaign_armies", "started", where, the_campaign.armies_full[army_id]['started'], size=2),
							common.doubleclick_text_full("campaign_armies", "finished", where, the_campaign.armies_full[army_id]['finished'], size=2))
					
					# Is it selected?
					if selected:
						checked = "checked='checked'"
						rclass = "selected_army"
					else:
						checked = ""
						rclass = ""
					
					# Is it being used elsewhere this turn?
					elsewhere = "<td>&nbsp;</td>"
					if army_id in campaign_armies:
						if campaign_id in campaign_armies[army_id]:
							elsewhere_count = len(campaign_armies[army_id]) - 1
						else:
							elsewhere_count = len(campaign_armies[army_id])
						
						if elsewhere_count == 1:
							elsewhere = "<td style='background-color:#700;'>&nbsp;</td>"
						elif elsewhere_count == 2:
							elsewhere = "<td style='background-color:#B00;'>&nbsp;</td>"
						elif elsewhere_count > 2:
							elsewhere = "<td style='background-color:#F00;'>&nbsp;</td>"
					
					army_s = '''<tr id="row_{a}" class="{rclass}">
					<td><label for="a_{a}" style="width:100%; display:block;">{name}</label></td>
					<td><input type="checkbox" name="a_{a}" id="a_{a}" value="True" onchange="if ($('#a_{a}').attr('checked')) {{$('#row_{a}').addClass('selected_army');}} else {{$('#row_{a}').removeClass('selected_army');}}" {checked}/></td>
					<td>{start_finish}&nbsp;&nbsp;</td>
					{elsewhere}
					</tr>'''.format(
						a = army_id,
						name = the_army.name,
						# cb = common.check_box("a_%d" % army_id, checked=selected),
						start_finish=start_finish,
						checked = checked,
						rclass = rclass,
						elsewhere = elsewhere,
					)
					
					if the_army.garrison:
						garrison_form.append(army_s)
					else:
						army_form.append(army_s)
					
					army_ids.append(army_id)
				
				
				teams_on_side_str.append("""
				<tr>
					<td colspan="4">
						<table border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td width="300">
									<table border="0" cellspacing="0" cellpadding="3">
										{armies}
									</table>
								</td>
								<td>
									<table border="0" cellspacing="0" cellpadding="3">
										{garrisons}
									</table>
								</td>
								<td>
									&nbsp;
								</td>
							</tr>
						</table>
					</td>
				</tr>""".format(
					armies = "".join(army_form), 
					garrisons = "".join(garrison_form),
					
					c_id = campaign_id,
					team = t['team'],
				))
			
			teams_on_side_str.append("</table>")
		
		output.append("""
		<tr>
			<td colspan="2"><hr /></td>
		</tr>
		<tr>
			<td><strong>{s}</strong></td>
			<td>
				{teams}
				<br />
				<span id="team_list_{s}"></span>
			</td>
		</tr>
		""".format(
			s=s,
			teams="".join(teams_on_side_str),
			# teams=", ".join([team_dict[t].name for t in teams_on_side]),
		))
	
	# Field for the ids of the armies listed that we need to sort out
	output.append('<input type="hidden" name="army_ids" value="%s" />' % ",".join([str(a) for a in army_ids]))	
	output.append('<!-- PY --><tr><td colspan="2"><input type="submit" value="Apply armies" /></td></tr><!-- PYEND -->')
	output.append('''</table>
	<!-- PY --></form><!-- PYEND -->
	<br />''')
	
	# Delete button
	output.append("""
	<form id="delete_form" action="exec.py" method="post" accept-charset="utf-8">
		<input type="hidden" name="campaign" id="campaign" value="{id}" />
		<input type="hidden" name="mode" id="mode" value="remove_campaign" />
		<input style="float:right; margin-right:100px;" type="button" value="Delete campaign" onclick="var answer = confirm('Delete {esc_name}?')
		if (answer) $('#delete_form').submit();" />
	</form>""".format(
		id =					campaign_id,
		esc_name =				common.js_name(the_campaign.name),
	))
	
	output.append(common.onload("$('#new_team').focus();"))
	output.append('<a href="web.py?mode=list_battles&amp;campaign=%d" class="block_link">List battles</a>' % campaign_id)
	output.append("</div>")
	
	return "".join(output)