<?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.3 2001/09/15 12:02:51 milosch Exp $ */

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

	$GLOBALS['phpgw']->template->set_file(array('form' => 'directory_form.tpl'));
	$GLOBALS['phpgw']->template->set_block('form','add','addhandle');
	$GLOBALS['phpgw']->template->set_block('form','edit','edithandle');

	$submit = $HTTP_POST_VARS['submit'];

	if ($submit)
	{
		$dir_name = $HTTP_POST_VARS['dir_name'];

		$errorcount = 0;

		$GLOBALS['phpgw']->db->query("SELECT * FROM phpgw_dj_directories WHERE dir_name='".$dir_name."'");
		if ($GLOBALS['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);

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

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

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

	$GLOBALS['phpgw']->template->set_var('lang_name',lang('Directory Name'));

	$GLOBALS['phpgw']->template->set_var('lang_add',lang('Add'));
	$GLOBALS['phpgw']->template->set_var('lang_default',lang('Default'));
	$GLOBALS['phpgw']->template->set_var('lang_reset',lang('Clear Form'));
	$GLOBALS['phpgw']->template->set_var('lang_done',lang('Done'));

	$GLOBALS['phpgw']->template->set_var('dir_name',$dir_name);

	$GLOBALS['phpgw']->template->set_var('edithandle','');
	$GLOBALS['phpgw']->template->set_var('addhandle','');
	$GLOBALS['phpgw']->template->pparse('out','form');
	$GLOBALS['phpgw']->template->pparse('addhandle','add');

	$GLOBALS['phpgw']->common->phpgw_footer();
?>
