<?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(
            } else {
            }
            $data = array('title' => $input['title'], 'url' => $input['url'], 'sort_order' => 0, 'img_path' => $web_file_path);
            $new_id = $db->insert('link_list', $data);
            if ($new_id <= 0) {
                $alert_output = $message->alert_dialog('Could not add new link.');
            }
        }
    }
}
/*****
 * Display logic
 */
$list->row_class('link');
$list->sort_by('link');
$list->draggable(true);
$delete_link = new GrlxLinkStyle();
$delete_link->i_only(true);
$delete_link->action('delete');
$edit_link = new GrlxLinkStyle();
$edit_link->url('site.link-edit.ajax.php');
$edit_link->reveal(true);
$edit_link->action('edit');
// Fetch the link list
$cols = array('title', 'url', 'sort_order', 'img_path', 'id');
$result = $db->orderBy('sort_order', 'ASC')->get('link_list', NULL, $cols);
if ($db->count > 0) {
    foreach ($result as $item) {
        if ($item['img_path']) {
            $icon = '<img src="' . $item['img_path'] . '" alt="icon" />';
        } else {