<?php
  /**************************************************************************\
  * phpGroupWare - dj                                                  *
  * http://www.phpgroupware.org                                              *
  * Written by Bettina Gille [ceb@phpgroupware.org]                          *
  * -----------------------------------------------                          *
  *  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 (at your  *
  *  option) any later version.                                              *
  \**************************************************************************/
/* $Id: adddirectory.php,v 1.2 2001/05/11 15:01:03 milosch Exp $ */

	$phpgw_info["flags"]["currentapp"] = 'dj';
	include('../header.inc.php');

	$t = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
	$t->set_file(array('form' => 'directory_form.tpl'));
	$t->set_block('form','add','addhandle');
	$t->set_block('form','edit','edithandle');

	if ($submit) {
		$errorcount = 0;

		$phpgw->db->query("SELECT * FROM phpgw_dj_directories WHERE dir_name='".$dir_name."'");
		if ($phpgw->db->next_record())
		{
			$error[$errorcount++] = lang('That directory name has been used already !');
		}

		if (!$dir_name)
		{
			$error[$errorcount++] = lang('Please enter a name for that directory !');
		}

		if (! $error)
		{
			if ($is_default == 'on')
			{
				$default_checked = True;
			}
			else
			{
				$default_checked = 0;
			}

			$dir_name     = addslashes($dir_name);

			$phpgw->db->query("INSERT INTO phpgw_dj_directories (dir_name) VALUES ('" . $dir_name . "')");
		}
	}

	if ($errorcount) { $t->set_var('message',$phpgw->common->error_list($error)); }
	if (($submit) && (! $error) && (! $errorcount)) { $t->set_var('message',lang('Directory x has been added !', $dir_name)); }
	if ((! $submit) && (! $error) && (! $errorcount)) { $t->set_var('message',''); }

	$t->set_var('title_directory',lang('Add Directory'));
	$t->set_var('actionurl',$phpgw->link('/dj/adddirectory.php'));
	$t->set_var('doneurl',$phpgw->link('/dj/directories.php'));
	$t->set_var('hidden_vars','<input type="hidden" name="dir_id" value="' . $dir_id . '">');

	$t->set_var('lang_name',lang('Directory Name'));

	$t->set_var('lang_add',lang('Add'));
	$t->set_var('lang_default',lang('Default'));
	$t->set_var('lang_reset',lang('Clear Form'));
	$t->set_var('lang_done',lang('Done'));

	$t->set_var('dir_name',$dir_name);

	$t->set_var('edithandle','');
	$t->set_var('addhandle','');
	$t->pparse('out','form');
	$t->pparse('addhandle','add');

	$phpgw->common->phpgw_footer();
?>
