<?php
/*
Copyright (c) 2010, Till Brehm, projektfarm Gmbh
All rights reserved.
*/


/******************************************
* Begin Form configuration
******************************************/

$tform_def_file = "form/invoice_client_settings.tform.php";

/******************************************
* End Form configuration
******************************************/

require_once('../../lib/config.inc.php');
require_once('../../lib/app.inc.php');

//* Check permissions for module
$app->auth->check_module_permissions('billing');

// Loading classes
$app->uses('tpl,tform,tform_actions');
$app->load('tform_actions');

class page_action extends tform_actions {

	function onShowEdit() {
		global $app, $conf;
		
		//* Check if the record exists, if not, create it
		$rec = $app->tform->getDataRecord($this->id);
		if(!isset($rec['client_id'])) {
			$sql = "INSERT INTO invoice_client_settings (client_id,sys_userid, sys_groupid,sys_perm_user,sys_perm_group,sys_perm_other,invoice_company_id,payment_email,payment_terms,payment_gateway,no_invoice_sending) 
			VALUES (".$this->id.",1, 1,'riud','riud','',0,'',0,'none','n')";
			$app->db->query($sql);
		}
		
		parent::onShowEdit();
	}

}

$page = new page_action;
$page->onLoad();

?>