<?php
	/**************************************************************************\
	* phpGroupWare - Inventory                                                 *
	* 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: adddist.php,v 1.14 2001/05/22 01:55:01 bettina Exp $ */

	if ($submit)
	{ 
		$phpgw_info['flags'] = array('noheader' => True,
									'nonavbar' => True);
	}

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

	$t = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
	$t->set_file(array('form' => 'dist_form.tpl'));
	$t->set_block('form','add','addhandle');
	$t->set_block('form','edit','edithandle');
	$d = CreateObject('phpgwapi.contacts');
    
	if ($submit)
	{
		$fields = Array();
		$fields['org_name']			= $company;
		$fields['org_unit']			= $department;
		$fields['n_given']			= $firstname;
		$fields['n_family']			= $lastname;
		$fields['industry_type']	= $industry_type;
		$fields['software']			= $software;
		$fields['email']			= $email;
		$fields['tel_work']			= $wphone;
		$fields['tel_fax']			= $fax;
		$fields['tel_pager']		= $pager;
		$fields['notes']			= $notes;
		if ($url == 'http://') { $url = ''; }
		$fields['url']				= $url;
		if ($url_mirror == 'http://') { $url_mirror = ''; }
		$fields['url_mirror']		= $url_mirror;
		if ($ftp == 'ftp://') { $ftp = ''; }
		$fields['ftp']				= $ftp;
		if ($ftp_mirror == 'ftp://') { $ftp_mirror = ''; }
		$fields['ftp_mirror']		= $ftp_mirror;

		if ($access) { $access = 'private'; }
		else { $access = 'public'; }

		$d->add($phpgw_info['user']['account_id'],$fields,$access,$cat_id,$tid='n');

		Header('Location: ' . $phpgw->link('/inv/listdist.php','cat_id=' . $cat_id . '&order=' . $order . '&sort=' . $sort . '&filter=' . $filter
											. '&start=' . $start));
	}

	$hidden_vars = '<input type="hidden" name="sort" value="' . $sort . '">' . "\n"
				. '<input type="hidden" name="order" value="' . $order . '">' . "\n"
				. '<input type="hidden" name="query" value="' . $query . '">' . "\n"
				. '<input type="hidden" name="start" value="' . $start . '">' . "\n"
				. '<input type="hidden" name="cat_id" value="' . $cat_id . '">' . "\n"
				. '<input type="hidden" name="filter" value="' . $filter . '">' . "\n";

	$t->set_var('lang_action',lang('Add distributor'));
	$t->set_var('actionurl',$phpgw->link('/inv/adddist.php'));
	$t->set_var('lang_company',lang('Company name'));
	$t->set_var('lang_department',lang('Department'));
	$t->set_var('lang_software',lang('Software'));
	$t->set_var('lang_url',lang('WWW'));
	$t->set_var('lang_url_mirror',lang('WWW mirror'));
	$t->set_var('lang_industry_type',lang('Industry type'));
	$t->set_var('lang_firstname',lang('Firstname'));
	$t->set_var('lang_lastname',lang('Lastname'));
	$t->set_var('lang_notes',lang('Notes'));
	$t->set_var('lang_pager',lang('Pager'));
	$t->set_var('lang_ftp',lang('FTP'));
	$t->set_var('lang_ftp_mirror',lang('FTP mirror'));
	$t->set_var('lang_email',lang('Email'));
	$t->set_var('lang_phone',lang('Phone'));
	$t->set_var('lang_fax',lang('Fax'));
	$t->set_var('lang_contact',lang('Contact'));
	$t->set_var('lang_select_cats',lang('Select category'));
	$t->set_var('lang_cats',lang('Category'));
	$t->set_var('hidden_vars',$hidden_vars);

	$c = CreateObject('phpgwapi.categories');
	$c->app_name = 'addressbook';
	$t->set_var('cats_list',$c->formated_list('select','all',$cat_id,'True'));
	$t->set_var('company',$company);
	$t->set_var('department',$department);
	$t->set_var('firstname',$firstname);
	$t->set_var('lastname',$lastname);
	$t->set_var('industry_type',$industry_type);
	$t->set_var('software',$software);
	$t->set_var('email',$email);
	$t->set_var('wphone',$wphone);
	$t->set_var('fax',$fax);
	$t->set_var('pager',$pager);
	if (! ereg('http://',$url)) { $url = 'http://'. $url; }
	$t->set_var('url',$url);
	if (! ereg('http://',$url_mirror)) { $url_mirror = 'http://'. $url_mirror; }
	$t->set_var('url_mirror',$url_mirror);
	if (! ereg('ftp://',$ftp)) { $ftp = 'ftp://'. $ftp; }
	$t->set_var('ftp',$ftp);
	if (! ereg('ftp://',$ftp_mirror)) { $ftp_mirror = 'ftp://'. $ftp_mirror; }
	$t->set_var('ftp_mirror',$ftp_mirror);
	$t->set_var('notes',$notes);
	$t->set_var('lang_access',lang('Private'));
	if ($access) { $t->set_var('access', '<input type="checkbox" name="access" value="True" checked>'); }
	else { $t->set_var('access', '<input type="checkbox" name="access" value="True">'); }
	$t->set_var('lang_add',lang('Add'));
	$t->set_var('lang_reset',lang('Clear Form'));
	$t->set_var('edithandle','');
	$t->set_var('addhandle','');

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

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