<?php

/*****
 * Setup
 */
require_once 'panl.init.php';
$fileops = new GrlxFileOps();
$link = new GrlxLinkStyle();
$view = new GrlxView();
$message = new GrlxAlert();
$list = new GrlxList();
$list->draggable(false);
$image_obj = new GrlxImage();
// Default value
$page_title = 'Ad editor';
$var_list = array('title', 'ad_id', 'tap_url', 'small_image_url', 'medium_image_url', 'large_image_url', 'msg');
if ($var_list) {
    foreach ($var_list as $key => $val) {
        ${$val} = register_variable($val);
    }
}
$code = $_POST['code'];
// No ad selected? Send ’em back to the list.
if (!$ad_id || !is_numeric($ad_id)) {
    header('location:ad.list.php');
}
// Folder in which we keep ad images.
$image_path = $milieu_list['directory']['value'] . '/assets/images/ads';
// List of status levels.
/*
$priority_list = array(
<?php

/* Artists use this script to configure a theme tone.
 */
/*****
 * Setup
 */
require_once 'panl.init.php';
$view = new GrlxView();
$modal = new GrlxForm_Modal();
$link = new GrlxLinkStyle();
$message = new GrlxAlert();
$form = new GrlxForm();
$theme = new GrlxXML_Theme();
$img = new GrlxImage();
$img->db_new = $db;
$theme_id = numfunc_register_var('theme_id');
$tone_id = numfunc_register_var('tone_id');
$theme->set_theme_id($theme_id);
$theme->set_tone_id($tone_id);
/*****
 * Updates
 */
// Delete a tone
if (is_numeric($_GET['delete_id'])) {
    $delete_id = $_GET['delete_id'];
    $result = $db->where('id', $delete_id)->delete('theme_tone');
    if ($result) {
        $match_list = $db->where('tone_id', $delete_id)->delete('image_tone_match');
    } else {
        $alert_output .= $message->alert_dialog('Unable to delete tone from database.');
                $url = '-';
            }
            $size_key = $val['small_width'] . ',' . $val['small_height'];
            $size = $size_list[$size_key];
            $size ? $size : ($size = 'Custom');
            // Pretty much what it looks like.
            /*
            			$small_image = new GrlxImage;
            			$small_image-> src = $val['small_image_url']; // The “source” attribute.
            			$small_image-> alt = 'image '.$val['small_image_url']; // The “alternate text” attribute.
            
            			$medium_image = new GrlxImage;
            			$medium_image-> src = $val['medium_image_url']; // The “source” attribute.
            			$medium_image-> alt = 'image '.$val['medium_image_url']; // The “alternate text” attribute.
            */
            $large_image = new GrlxImage();
            $large_image->src = $val['large_image_url'];
            // The “source” attribute.
            $large_image->alt = 'image ' . $val['large_image_url'];
            // The “alternate text” attribute.
            $delete_link->query('delete_ad_id=' . $key);
            $edit_link->query('ad_id=' . $key);
            $promo_content[] = array($large_image->paint(), $url, '&nbsp;', $delete_link->icon_link() . "\n" . $edit_link->icon_link());
        }
    }
}
if ($promo_content) {
    $list->content($promo_content);
    $ad_list_output = '<form accept-charset="UTF-8" action="ad.list.php" method="get">' . "\n";
    $ad_list_output .= $list->format_headings();
    $ad_list_output .= $list->format_content();
    // 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]) {
            $action = '<input type="checkbox" id="change_to[' . $key . ']" name="change_to[' . $key . ']" checked="checked" value="on"/> <label for="change_to[' . $key . ']">on</label>' . "\n";
            $action .= '<input type="hidden" name="change_from[' . $key . ']" value="on"/>' . "\n";
        } else {
            $action = '<input type="checkbox" id="change_to[' . $key . ']" name="change_to[' . $key . ']" value="on"/> <label for="change_to[' . $key . ']">off</label>' . "\n";
            $action .= '<input type="hidden" name="change_from[' . $key . ']" value="off"/>' . "\n";
        }
        $title = $val['title'];
        $title ? $title : ($title = 'Untitled');
        if ($val['large_image_url']) {
            $image->src = $val['large_image_url'];
            $image->alt = $val['large_image_url'];
            $link->url('ad.promo-edit.php?ad_id=' . $key);