$ad_list_output .= '</form>' . "\n";
} else {
    $link->url('ad.promo-create.php');
    $link->tap('Create one now');
    $ad_list_output = $message->info_dialog('Huh. Looks like you haven’t uploaded any ads. ' . $link->paint() . '.');
}
$link->url('ad.promo-create.php');
$link->tap('Create an ad');
$ad_list_output .= $link->button_primary('new');
///////// Display the slots.
// Get all slots for this theme.
$slot_list = get_slots($current_theme['theme_id'], 'ad', $db);
// How many ads are in each slot?
if ($slot_list) {
    foreach ($slot_list as $key => $val) {
        $ad_slot_match_list = get_ad_slot_matches($key, null, $db);
        $slot_list[$key]['ad_count'] = count($ad_slot_match_list);
    }
}
if ($slot_list) {
    $heading_list = array();
    // reset
    $heading_list[] = array('value' => 'Name', 'class' => 'nudge');
    $heading_list[] = array('value' => 'Size', 'class' => 'nudge');
    $heading_list[] = array('value' => 'Assigned ads', 'class' => null);
    /*
    	$heading_list[] = array(
    		'value' => 'Theme ID',
    		'class' => null
    	);
    */
    }
}
if ($change_made == true) {
    $link->title = 'Go back to the screen with all your site’s ads.';
    $link->url = 'ad.list.php';
    $link->tap = 'Return to the ad list';
    $alert_output = $message->success_dialog('Ads reassigned. ' . $link->paint());
}
/*****
 * Display logic
 */
if ($slot_id) {
    // Get basic information about this slot.
    $slot_info = get_slot_info($slot_id, $db);
    // What ads are in this slot?
    $match_list = get_ad_slot_matches($slot_id, null, $db);
}
// What ads might fit into this slot?
if ($slot_info) {
    //	$possible_ad_list = $db->where('large_width', $slot_info['max_width'],'<=')
    //	->where('large_height', $slot_info['max_height'],'<=')
    $possible_ad_list = $db->get('ad_reference', null, 'id,title,source_id,source_rel_id,large_width,large_height,large_image_url,code');
    if ($possible_ad_list) {
        $possible_ad_list = rekey_array($possible_ad_list, 'id');
    }
}
if ($possible_ad_list) {
    $image = new GrlxImage();
    $image->style = 'max-height:100px;max-width:468px';
    foreach ($possible_ad_list as $key => $val) {
        if ($match_list[$key]) {