<?php

/**********************************************************************
 * Copyright (C) 2006 L'équipe Wikigraphe
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * See also http://www.fsf.org
 *********************************************************************/

require_once('conf/conf.php');
require_once('model/node.php');
require_once('model/link.php');

// save a new image if requested
include_once('control/save_image.php');

$title = (isset($_GET['title']) ? $_GET['title'] : DEFAULT_PAGE);

$node = new DB_DataObject_Node();
$node->get('title', $title);
if ($node->count() > 0) {
  // node exists, process
  $node->fetch();
  // NULL extension indicates void image
  // XXX: kind of hacky, maybe we should rather opt for a specific field
  if (is_null($node->extension)) {
    $image_src = NULL;
  } else {
    $image_src = IMAGE_DIR . $title . '.' . $node->extension;
  }
} else {
  // node does not exists (yet)
  $image_src = NULL;
}

$tpl->assign('title', $title);
$tpl->assign('self', $_SERVER['PHP_SELF']);
$tpl->assign('header', '');
$tpl->assign('onload', '');
$tpl->assign('image_src', $image_src);

$tpl->display('edit_image.tpl.php');
?>