<?php

/**
* @version 2.6.9
* @package Joomla 1.5
* @subpackage DT Register
* @copyright Copyright (C) 2006 DTH Development
* @copyright contact dthdev@dthdevelopment.com
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
*/

function com_install() {

	$database = &JFactory::getDBO();

	JFolder::create('../images/dtregister/');
	
	JFolder::create('../images/dtregister/barcode/');
	
	JFolder::create('../images/dtregister/locations/');
	
	JFolder::create('../images/dtregister/uploads/');
    
	// make changes or additions to #__dtregister_user

	$sql="Show columns from #__dtregister_user";

	$database->setQuery($sql);

	$rows=$database->loadObjectList();

	$arrFields=array();

	for($i=0,$n=count($rows);$i<$n;$i++)

	{

		$row=$rows[$i];

		$arrFields[]=$row->Field;

	}

	if(!in_array('register_date',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_user` ADD `register_date` DATETIME NULL";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('userZip',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_user` CHANGE `userZip` `userZip` VARCHAR( 50 ) NULL";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('payment_type',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_user` ADD `payment_type` VARCHAR(100) default NULL";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('due_amount',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_user` ADD `due_amount` decimal(10,2) NOT NULL default '0.00'";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('pay_later_option',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_user` ADD `pay_later_option` tinyint(4) NOT NULL default '0'";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('confirmNum',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_user` ADD `confirmNum` varchar(50) default NULL";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('user_id',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_user` ADD `user_id` int(11) NOT NULL default '0'";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('payment_verified',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_user` ADD `payment_verified` tinyint(4) NOT NULL default '1'";

		$database->setQuery($sql);

		$database->query();

		$sql="Update `#__dtregister_user` set `payment_verified`=1";

		$database->setQuery($sql);

	}

	if(!in_array('pay_later_paid',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_user` ADD `pay_later_paid` tinyint(4) NOT NULL default '0'";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('discount_code_id',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_user` ADD `discount_code_id` bigint(11) default '0'";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('billing_firstname',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_user` ADD `billing_firstname` varchar(150) default NULL";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('billing_lastname',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_user` ADD `billing_lastname` varchar(150) default NULL";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('billing_address',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_user` ADD `billing_address` varchar(255) default NULL";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('billing_city',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_user` ADD `billing_city` varchar(150) default NULL";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('billing_state',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_user` ADD `billing_state` varchar(150) default NULL";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('billing_zipcode',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_user` ADD `billing_zipcode` varchar(10) default NULL";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('billing_email',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_user` ADD `billing_email` varchar(150) default NULL";

		$database->setQuery($sql);

		$database->query();

	}
	
	if(!in_array('due_payment',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_user` ADD `due_payment` decimal(10,2) default '0.00'";

		$database->setQuery($sql);

		$database->query();

	}
	
	if(!in_array('cancel',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_user` ADD `cancel` int(11) default '0'";

		$database->setQuery($sql);

		$database->query();

	}
	
	if(!in_array('attend',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_user` ADD `attend` int(2) default '0'";

		$database->setQuery($sql);

		$database->query();

	}
	
	if(!in_array('paid_amount',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_user` ADD `paid_amount` varchar(30) default NULL";

		$database->setQuery($sql);

		$database->query();

	}
	
	if(!in_array('userTitle',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_user` ADD `userTitle` varchar(10) NOT NULL default ''";

		$database->setQuery($sql);

		$database->query();

	}
	
	if(!in_array('userAddress2',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_user` ADD `userAddress2` varchar(250) NOT NULL default ''";

		$database->setQuery($sql);

		$database->query();

	}
	
	if(!in_array('transaction_id',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_user` ADD `transaction_id` varchar(255) default NULL";

		$database->setQuery($sql);

		$database->query();

	}
  
// 2.3.3 Added 2 fields to #__dtregister_field_event for custom field options on group registrations

	$sql="Show columns from #__dtregister_field_event";

	$database->setQuery($sql);

	$rows=$database->loadObjectList();

	$arrFields=array();

	for($i=0,$n=count($rows);$i<$n;$i++)

	{

		$row=$rows[$i];

		$arrFields[]=$row->Field;

	}

	if(!in_array('group_behave',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_field_event` ADD `group_behave` mediumint(11) NOT NULL default '1'";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('required',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_field_event` ADD `required` tinyint(1) default '0'";

		$database->setQuery($sql);

		$database->query();

	}
	
	if(in_array('showed',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_field_event` CHANGE `showed` `showed` TINYINT(3) DEFAULT NULL";

		$database->setQuery($sql);

		$database->query();

	}

// End of changes to #__dtregister_field_event

// 2.3.3 Added 1 field to #__dtregister_categories for ordering of categories

	$sql="Show columns from #__dtregister_categories";

	$database->setQuery($sql);

	$rows=$database->loadObjectList();

	$arrFields=array();

	for($i=0,$n=count($rows);$i<$n;$i++)

	{

		$row=$rows[$i];

		$arrFields[]=$row->Field;

	}

	if(!in_array('ordering',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_categories` ADD `ordering` tinyint(3) UNSIGNED NULL";

		$database->setQuery($sql);

		$database->query();

	}
	
	if(!in_array('parent_id',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_categories` ADD `parent_id` int(11) default '0'";

		$database->setQuery($sql);

		$database->query();

	}

// End of changes to #__dtregister_categories


// 2.6.7d Added 1 field to #__dtregister_config for JoomFish fix

	$sql="Show columns from #__dtregister_config";

	$database->setQuery($sql);

	$rows=$database->loadObjectList();

	$arrFields=array();

	for($i=0,$n=count($rows);$i<$n;$i++)

	{

		$row=$rows[$i];

		$arrFields[]=$row->Field;

	}

	if(!in_array('title',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_config` ADD `title` varchar(50) default NULL";

		$database->setQuery($sql);

		$database->query();

	}


	//Check and insert default data for configuration

	$sql="Select count(*) From #__dtregister_config";

	$database->setQuery($sql);

	$total=$database->loadResult();

	if(!$total)

	{

		//Insert default data here

		$sql="INSERT INTO `#__dtregister_config` VALUES(1, 'capacity_column', '1', 'capacity_column');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(2, 'registered_column', '1', 'registered_column');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(3, 'merchid', '', 'merchid');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(4, 'transkey', '', 'transkey');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(5, 'thanksemail', '[NAME],\r\n\r\nThanks for registering for [EVENT_NAME] to be held on [EVENT_DATE]! We have your details as follows:

\r\n\r\n[CONTACT_DETAILS]\r\n[ORGANIZATION]\r\n\r\nYou chose these options:\r\n[CONTACT_CUSTOM_FIELDS]

\r\n\r\nThere are [GROUP_NUMBER] members in your group: \r\n[GROUP_NAMES]\r\n\r\nYou paid $[AMOUNT] for this registration and paid via [PAYMENT_TYPE].

\r\n\r\nThank you and we are glad that you will be a part of this great upcoming event!\r\n\r\nSincerely,\r\n\r\nRegistration Team', 'thanksemail');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(6, 'thanksmsg', 'Thank you for registering for this event! Your registration is being processed and you will be sent any information that you need for the event. You will also be receiving an email receipt of your registration.', 'thanksmsg');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(7, 'subthanksemail', 'You have registered for [EVENT_NAME]!', 'subthanksemail');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(8, 'topmsg', 'Place a message here to display above your registration forms. You can customize event-specific messages if you would like in the setup of each event to override this general default message.', 'topmsg');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(9, 'paypalmode', 'live', 'paypalmode');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(10, 'authnetmode', 'live', 'authnetmode');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(11, 'terms_conditions_msg', 'Place your terms and conditions message here.', 'terms_conditions_msg');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(12, 'terms_conditions', '0', 'terms_conditions');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(15, 'authpayoption', '', 'authpayoption');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(16, 'paymentmethod', 'authorizenet,paypal,pay_later', 'paymentmethod');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(17, 'paypalid', 'paypal@yourdomain.com', 'paypalid');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(18, 'regtypeallowed', '', 'regtypeallowed');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(19, 'discount_type', '', discount_type');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(20, 'discount_amount', '', 'discount_amount');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(21, 'echecknetmode', 'live', 'echecknetmode');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(22, 'full_message', 'This event is currently full and we are not allowing for any more registrations at this time.  We do apologize for this, but would like to offer you to be added to our Waiting List.  Fill out the following form, then if someone cancels their registration, you will be notified of the opening and your availability to then register.', 'full_message');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(23, 'cut_off_date_message', 'We are no longer accepting registrations for this event. Thank you.', 'cut_off_date_message');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(24, 'waiting_msg', 'You have been added to the Waiting List for this event.  You will be notified if space becomes available. Thank you.', 'waiting_msg');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(25, 'cb_integrated', '0', 'cb_integrated');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(26, 'security_image_check', '0', 'security_image_check');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(27, 'currency_code', 'USD', 'currency_code');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(28, 'p_s_organization', '1', 'p_s_organization');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(29, 'p_r_organization', '0', 'p_r_organization');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(30, 'p_s_address', '1', 'p_s_address');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(31, 'p_r_address', '1', 'p_r_address');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(32, 'p_s_city', '1', 'p_s_city');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(33, 'p_r_city', '1', 'p_r_city');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(34, 'p_s_state', '1', 'p_s_state');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(35, 'p_r_state', '1', 'p_r_state');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(36, 'p_s_zip', '1', 'p_s_zip');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(37, 'p_r_zip', '1', 'p_r_zip');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(38, 'p_s_country', '1', 'p_s_country');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(39, 'p_r_country', '0', 'p_r_country');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(40, 'p_s_phone', '1', 'p_s_phone');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(41, 'p_r_phone', '0', 'p_r_phone');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(42, 'f_s_organization', '1', 'f_s_organization');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(43, 'f_r_organization', '0', 'f_r_organization');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(44, 'f_s_address', '1', 'f_s_address');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(45, 'f_r_address', '1', 'f_r_address');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(46, 'f_s_city', '1', 'f_s_city');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(47, 'f_r_city', '1', 'f_r_city');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(48, 'f_s_state', '1', 'f_s_state');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(49, 'f_r_state', '1', 'f_r_state');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(50, 'f_s_zip', '1', 'f_s_zip');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(51, 'f_r_zip', '1', 'f_r_zip');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(52, 'f_s_country', '1', 'f_s_country');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(53, 'f_r_country', '0', 'f_r_country');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(54, 'f_s_phone', '1', 'f_s_phone');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(55, 'f_r_phone', '0', 'f_r_phone');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(56, 'm_s_firstname', '1', 'm_s_firstname');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(57, 'm_r_firstname', '1', 'm_r_firstname');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(58, 'm_s_lastname', '1', 'm_s_lastname');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(59, 'm_r_lastname', '1', 'm_r_lastname');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(60, 'm_s_organization', '0', 'm_s_organization');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(61, 'm_r_organization', '0', 'm_r_organization');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(62, 'm_s_address', '1', 'm_s_address');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(63, 'm_r_address', '0', 'm_r_address');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(64, 'm_s_city', '1', 'm_s_city');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(65, 'm_r_city', '0', 'm_r_city');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(66, 'm_s_state', '1', 'm_s_state');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(67, 'm_r_state', '0', 'm_r_state');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(68, 'm_s_zip', '1', 'm_s_zip');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(69, 'm_r_zip', '0', 'm_r_zip');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(70, 'm_s_email', '1', 'm_s_email');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(71, 'm_r_email', '1', 'm_r_email');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(72, 'm_s_country', '0', 'm_s_country');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(73, 'm_r_country', '0', 'm_r_country');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(74, 'm_s_phone', '0', 'm_s_phone');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(75, 'm_r_phone', '0', 'm_r_phone');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(76, 'pay_later_options', '1,2,3', 'pay_later_options');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(77, 'cardtype', 'Visa,MasterCard', 'cardtype');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(78, 'prevent_duplication', '0', 'prevent_duplication');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(79, 'godaddy_hosting', '0', 'godaddy_hosting');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(80, 'terms_conditions', '1', 'terms_conditions');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(81, 'save_payment_info', '1', 'save_payment_info');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(82, 'event_field_width', '200', 'event_field_width');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(83, 'price_column', '1', 'price_column');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(84, 'private_event_msg', 'This event requires that you be a logged in member of this website. Please register a user account to gain access to our private events.', 'private_event_msg');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(85, 'date_format', '%m-%d-%Y', 'date_format');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(86, 'detail_link_type', '1', 'detail_link_type');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(87, 'event_show_date', '1', 'event_show_date');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(88, 'show_past_event', '0', 'show_past_event');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(89, 'show_group_members', '0', 'show_group_members');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(90, 'registrant_message', ' ', 'registrant_message');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(91, 'button_color', 'green', 'button_color');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(92, 'registrant_city', '0', 'registrant_city');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(93, 'registrant_organization', '0', 'registrant_organization');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(94, 'registrant_address', '0', 'registrant_address');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(95, 'registrant_zip', '0', 'registrant_zip');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(96, 'registrant_country', '1', registrant_country');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(97, 'registrant_state', '0', 'registrant_state');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(98, 'registrant_list', '1', 'registrant_list');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(99, 'registrant_avatar_height', '86', 'registrant_avatar_height');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(100, 'registrant_avatar_width', '60', 'registrant_avatar_width');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(101, 'registrant_cb_linked', '0', 'registrant_cb_linked');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(102, 'registrant_name', '3', 'registrant_name');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(103, 'registrant_username', '1', 'registrant_username');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(104, 'registrant_registered_date', '1', 'registrant_registered_date');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(105, 'registrant_show_avatar', '1', 'registrant_show_avatar');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(106, 'show_registration_button', '1', 'show_registration_button');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(107, 'currency_separator', '2', 'currency_separator');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(108, 'partner_id', '', 'partner_id');";

		$database->setQuery($sql);

		$database->query();

		$sql="INSERT INTO `#__dtregister_config` VALUES(109, 'idealmode', 'live', 'idealmode');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(110, 'linktogoogle', '1', 'linktogoogle');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(111, 'showlocation', '1', 'showlocation');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(112, 'timeformat', '1', 'timeformat');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(113, 'displaytime', '0', 'displaytime');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(114, 'location_img_w', '150', 'location_img_w');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(115, 'location_img_h', '150', 'location_img_h');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(116, 'googlekey', '', 'googlekey');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(117, 'cancelfee', '0.00', 'cancelfee');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(118, 'cancelfee_enable', '0', 'cancelfee_enable');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(119, 'cancelfee_type', '1', 'cancelfee_type');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(120, 'changefee', '0.00', 'changefee');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(121, 'changefee_enable', '0', 'changefee_enable');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(122, 'changefee_type', '1', 'changefee_type');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(123, 'userpanelmessage', 'This is a message at the top of the user's control panel.', 'userpanelmessage');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(124, 'prerequisite_paid', '0', 'prerequisite_paid');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(125, 'prerequisite_attend', '0', 'prerequisite_attend');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(126, 'cbviewonly', '0', 'cbviewonly');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(127, 'timecheck', '0', 'timecheck');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(128, 'event_filter_show', '1', 'event_filter_show');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(129, 'event_search_show', '1', 'event_search_show');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(130, 'eventListOrder', '1', 'eventListOrder');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(131, 'event_title_link', 'dtregister', 'event_title_link');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(132, 'sendEmailToGroup', '1', 'sendEmailToGroup');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(133, 'paid_status_change_msg', 'The payment status of your registration of [EVENT_NAME] has been updated to [PAID_STATUS].', 'paid_status_change_msg');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(134, 'status_change_msg', 'The status of your registration of [EVENT_NAME] has been updated to [STATUS].', 'status_change_msg');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(135, 'map_joms_firstname', '', 'map_joms_firstname');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(136, 'map_joms_lastname', '', 'map_joms_lastname');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(137, 'map_joms_org', '', 'map_joms_org');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(138, 'map_joms_title', '', 'map_joms_title');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(139, 'map_joms_address', '8', 'map_joms_address');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(140, 'map_joms_address2', '', 'map_joms_address2');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(141, 'map_joms_city', '10', 'map_joms_city');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(142, 'map_joms_state', '9', 'map_joms_state');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(143, 'map_joms_zip', '', 'map_joms_zip');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(144, 'map_joms_country', '11', 'map_joms_country');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(145, 'map_joms_phone', '6', 'map_joms_phone');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(146, 'titleoptions', 'Dr|Mr|Mrs|Miss|Ms|Rev', 'titleoptions');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(147, 'paid_status_change_msg_send', '0', 'paid_status_change_msg_send');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(148, 'status_change_msg_send', '0', 'status_change_msg_send');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(149, 'mosConfig_mailfrom', '', 'mosConfig_mailfrom');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(150, 'mosConfig_fromname', '', 'mosConfig_fromname');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(151, 'usercreation', '0', 'usercreation');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(152, 'month_filter_show', '1', 'month_filter_show');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(153, 'netdeposit_clientid', '', 'netdeposit_clientid');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(154, 'netdeposit_clientcode', '', 'netdeposit_clientcode');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(155, 'event_date_show', '1', 'event_date_show');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(156, 'private_event_notification', 'onscreen', 'private_event_notification');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(157, 'private_event_redirect', '', 'private_event_redirect');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(158, 'eway_customerid', '', 'eway_customerid');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(159, 'ewaytype', 'live', 'ewaytype');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(160, 'ewaymode', 'test', 'ewaymode');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(161, 'googlemerchid', '', 'googlemerchid');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(162, 'googleapikey', '', 'googleapikey');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(163, 'googlemode', 'test', 'googlemode');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(164, 'paid_default_status', '0', 'paid_default_status');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(165, 'partial_default_status', '2', 'partial_default_status');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(166, 'paylater_default_status', '2', 'paylater_default_status');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(167, 'prerequisite_event_msg', '<p>Before you can register for this event, you must have already registered for the following event(s): [PREREQ_EVENTS]</p>', 'prerequisite_event_msg');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(168, 'overlap_event_msg', '<p>You can't register for this cause you're already registered for something else at this same time.</p>', 'overlap_event_msg');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(169, 'confirm_number_start', '', 'confirm_number_start');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(170, 'confirm_number_prefix', 'DT-', 'confirm_number_prefix');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(171, 'confirm_number_type', 'random', 'confirm_number_type');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(172, 'barcode_enable', '0', 'barcode_enable');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(173, 'barcode_font_size', '12', 'barcode_font_size');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(174, 'barcode_resolution', '1', 'barcode_resolution');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(175, 'barcodeThick', '30', 'barcodeThick');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(176, 'barcodeDpi', '72', 'barcodeDpi');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(177, 'barcode_image_type', 'png', 'barcode_image_type');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(178, 'barcode_type', 'code39', 'barcode_type');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(179, 'barcode_rotation', '0', 'barcode_rotation');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(180, 'csv_separator', ',', 'csv_separator');";

		$database->setQuery($sql);

		$database->query();
		
		$sql="INSERT INTO `#__dtregister_config` VALUES(181, 'show_price_tax', '0', 'show_price_tax');";

		$database->setQuery($sql);

		$database->query();
	
	}

	// make changes or additions to #__dtregister_group_event

	$sql="Show columns from #__dtregister_group_event";

	$database->setQuery($sql);

	$rows=$database->loadObjectList();

	$arrFields=array();

	for($i=0,$n=count($rows);$i<$n;$i++)

	{

		$row=$rows[$i];

		$arrFields[]=$row->Field;

	}

	if(!in_array('max_registrations',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_event` ADD `max_registrations` int(11) NOT NULL default '0'";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('registration_type',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_event` ADD `registration_type` varchar(50) default 'individual'";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('topmsg',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_event` ADD `topmsg` text default NULL";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('cut_off_date',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_event` ADD `cut_off_date` date default NULL";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('discount_type',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_event` ADD `discount_type` tinyint(4) NOT NULL default '0'";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('discount_amount',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_event` ADD `discount_amount` decimal(10,2) NOT NULL default '0.00'";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('thksmsg',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_event` ADD `thksmsg` text default NULL";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('thksmsg_set',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_event` ADD `thksmsg_set` tinyint(4) NOT NULL default '0'";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('event_describe',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_event` ADD `event_describe` text default NULL";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('event_describe_set',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_event` ADD `event_describe_set` tinyint(4) default NULL";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('terms_conditions_set',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_event` ADD `terms_conditions_set` tinyint(4) NOT NULL default '0'";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('terms_conditions_msg',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_event` ADD `terms_conditions_msg` text default NULL";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('category',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_event` ADD `category` int(11) default NULL";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('max_group_size',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_event` ADD `max_group_size` smallint(5) unsigned NULL";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('ordering',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_event` ADD `ordering` tinyint(3) unsigned default '1'";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('waiting_list',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_event` ADD `waiting_list` tinyint(1) default NULL";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('public',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_event` ADD `public` tinyint(1) NOT NULL default '1'";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('export',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_event` ADD `export` int(2) NOT NULL default '1'";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('use_discountcode',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_event` ADD `use_discountcode` int(3) default '0'";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('article_id',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_event` ADD `article_id` bigint(11) default '0'";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('detail_link_show',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_event` ADD `detail_link_show` int(2) NOT NULL default '0'";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('show_registrant',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_event` ADD `show_registrant` int(4) default '0'";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('publish',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_event` ADD `publish` int(4) NOT NULL default '0'";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('startdate',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_event` ADD `startdate` date default '0000-00-00'";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('bird_discount_type',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_event` ADD `bird_discount_type` tinyint(2) default '0'";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('bird_discount_amount',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_event` ADD `bird_discount_amount` varchar(12) default NULL";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('bird_discount_date',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_event` ADD `bird_discount_date` date default '0000-00-00'";

		$database->setQuery($sql);

		$database->query();

	}
	
	if(!in_array('payment_option',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_event` ADD `payment_option` tinyint(2) NOT NULL default '1'";

		$database->setQuery($sql);

		$database->query();

	}
	
	if(!in_array('location_id',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_event` ADD `location_id` int(11) default NULL";

		$database->setQuery($sql);

		$database->query();

	}
	
	if(!in_array('archive',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_event` ADD `archive` int(2) default '0'";

		$database->setQuery($sql);

		$database->query();

	}
	
	if(!in_array('partial_payment',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_event` ADD `partial_payment` int(2) default '0'";

		$database->setQuery($sql);

		$database->query();

	}
	
	if(!in_array('partial_amount',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_event` ADD `partial_amount` varchar(20) default NULL";

		$database->setQuery($sql);

		$database->query();

	}
	
	if(!in_array('partial_minimum_amount',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_event` ADD `partial_minimum_amount` varchar(20) default NULL";

		$database->setQuery($sql);

		$database->query();

	}
	
	if(!in_array('edit_fee',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_event` ADD `edit_fee` int(2) default '0'";

		$database->setQuery($sql);

		$database->query();

	}
	
	if(!in_array('cancelfee_enable',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_event` ADD `cancelfee_enable` int(2) default NULL";

		$database->setQuery($sql);

		$database->query();

	}
	
	if(!in_array('cancel_date',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_event` ADD `cancel_date` varchar(30) default NULL";

		$database->setQuery($sql);

		$database->query();

	}
	
	if(!in_array('cancel_refund_status',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_event` ADD `cancel_refund_status` int(1) default '0'";

		$database->setQuery($sql);

		$database->query();

	}
  
  if(!in_array('excludeoverlap',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_event` ADD `excludeoverlap` int(2) default '0'";

		$database->setQuery($sql);

		$database->query();

	}
	
	if(!in_array('pay_later_thk_msg_set',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_event` ADD `pay_later_thk_msg_set` tinyint(2) NOT NULL default '0'";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('pay_later_thk_msg',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_event` ADD `pay_later_thk_msg` text default NULL";

		$database->setQuery($sql);

		$database->query();

	}
	
	if(!in_array('thanksmsg_set',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_event` ADD `thanksmsg_set` tinyint(2) NOT NULL default '0'";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('thanksmsg',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_event` ADD `thanksmsg` text default NULL";

		$database->setQuery($sql);

		$database->query();

	}
	
	if(!in_array('change_date',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_event` ADD `change_date` varchar(20) default NULL";

		$database->setQuery($sql);

		$database->query();

	}
	
	if(!in_array('detail_itemid',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_event` ADD `detail_itemid` int(4) default NULL";

		$database->setQuery($sql);

		$database->query();

	}
	
	if(!in_array('tax_enable',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_event` ADD `tax_enable` int(2) default '0'";

		$database->setQuery($sql);

		$database->query();

	}
	
	if(!in_array('tax_amount',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_event` ADD `tax_amount` float default '0'";

		$database->setQuery($sql);

		$database->query();

	}

	// make changes or additions to #__dtregister_group_amount

	$sql="Show columns from #__dtregister_group_amount";

	$database->setQuery($sql);

	$rows=$database->loadObjectList();

	$arrFields=array();

	for($i=0,$n=count($rows);$i<$n;$i++)

	{

		$row=$rows[$i];

		$arrFields[]=$row->Field;

	}

	if(in_array('examount',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_amount` DROP COLUMN `examount`";

		$database->setQuery($sql);

		$database->query();

	}

	if(in_array('examountfor',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_amount` DROP COLUMN `examountfor`";

		$database->setQuery($sql);

		$database->query();

	}

	// make changes or additions to #__dtregister_group_member

	$sql="Show columns from #__dtregister_group_member";

	$database->setQuery($sql);

	$rows=$database->loadObjectList();

	$arrFields=array();

	for($i=0,$n=count($rows);$i<$n;$i++)

	{

		$row=$rows[$i];

		$arrFields[]=$row->Field;

	}

	if(!in_array('firstname',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_member` ADD `firstname` varchar(100) default NULL";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('lastname',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_member` ADD `lastname` varchar(100) default NULL";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('organization',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_member` ADD `organization` varchar(255) default NULL";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('address',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_member` ADD `address` varchar(255) default NULL";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('city',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_member` ADD `city` varchar(100) default NULL";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('state',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_member` ADD `state` varchar(50) default NULL";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('country',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_member` ADD `country` varchar(50) default NULL";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('zip',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_member` ADD `zip` varchar(50) default NULL";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('phone',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_member` ADD `phone` varchar(50) default NULL";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('email',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_member` ADD `email` varchar(100) NOT NULL default ''";

		$database->setQuery($sql);

		$database->query();

	}
	
	if(!in_array('title',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_member` ADD `title` varchar(10) default NULL";

		$database->setQuery($sql);

		$database->query();

	}
	
	if(!in_array('address2',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_group_member` ADD `address2` varchar(255) default NULL";

		$database->setQuery($sql);

		$database->query();

	}

	//Update data and remove the old columns

	if(in_array('groupMemberName',$arrFields))

	{

		//Update data and drop this column

		$sql="Update #__dtregister_group_member Set firstname=groupMemberName";

		$database->setQuery($sql);

		$database->query();

		//Drop the column

		$sql="ALTER TABLE #__dtregister_group_member DROP `groupMemberName`";

		$database->setQuery($sql);

		$database->query();

	}

	if(in_array('groupMemberEmail',$arrFields))

	{

		//Update data and drop this column

		$sql="Update #__dtregister_group_member Set email=groupMemberEmail";

		$database->setQuery($sql);

		$database->query();

		//Drop the column

		$sql="ALTER TABLE #__dtregister_group_member DROP `groupMemberEmail`";

		$database->setQuery($sql);

		$database->query();

	}

	//Update the custom fields list

	$sql="Select name From #__dtregister_fields";

	$database->setQuery($sql);

	$rowCustomFields=$database->loadObjectList();

	for($i=0,$n=count($rowCustomFields);$i<$n;$i++)

	{

		$rowCustomField=$rowCustomFields[$i];

		$name=$rowCustomField->name;

		if(!in_array($name,$arrFields))

		{

			//Add this field into table

			$sql="ALTER TABLE `#__dtregister_group_member` ADD `$name` VARCHAR(1000) NULL ;";

			$database->setQuery($sql);

			$database->query();

		}

	}

	// make changes or additions to #__dtregister_fields

	$sql="Show columns from #__dtregister_fields";

	$database->setQuery($sql);

	$rows=$database->loadObjectList();

	$arrFields=array();

	for($i=0,$n=count($rows);$i<$n;$i++)

	{

		$row=$rows[$i];

		$arrFields[]=$row->Field;

	}

	if(!in_array('fees',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_fields` ADD `fees` TEXT default NULL";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('fee_field',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_fields` ADD `fee_field` TINYINT(4) NOT NULL DEFAULT '0'";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('new_line',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_fields` ADD `new_line` TINYINT(4) NOT NULL DEFAULT '0'";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('textual',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_fields` ADD `textual` text NOT NULL";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('export_individual',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_fields` ADD `export_individual` int(2) NULL default '1'";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('export_group',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_fields` ADD `export_group` int(2) NULL default '1'";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('attendee_list',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_fields` ADD `attendee_list` tinyint(2) NOT NULL default '0'";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('usagelimit',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_fields` ADD `usagelimit` text default NULL";

		$database->setQuery($sql);

		$database->query();

	}

	if(!in_array('fee_type',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_fields` ADD `fee_type` tinyint(2) NOT NULL default '1'";

		$database->setQuery($sql);

		$database->query();

	}
	
	if(!in_array('filetypes',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_fields` ADD `filetypes` text default NULL";

		$database->setQuery($sql);

		$database->query();

	}
	
	if(!in_array('upload',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_fields` ADD `upload` tinyint(2) default NULL";

		$database->setQuery($sql);

		$database->query();

	}
	
	if(!in_array('filesize',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_fields` ADD `filesize` int(4) default NULL";

		$database->setQuery($sql);

		$database->query();

	}
	
	if(!in_array('hidden',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_fields` ADD `hidden` tinyint(2) default NULL";

		$database->setQuery($sql);

		$database->query();

	}
	
	if(!in_array('group_behave',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_fields` ADD `group_behave` tinyint(2) NOT NULL default '1'";

		$database->setQuery($sql);

		$database->query();

	}
	
	if(!in_array('allevent',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_fields` ADD `allevent` tinyint(2) NOT NULL default '0'";

		$database->setQuery($sql);

		$database->query();

	}
	
	if(!in_array('showed',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_fields` ADD `showed` tinyint(3) default NULL";

		$database->setQuery($sql);

		$database->query();

	}
	
	if(!in_array('maxlength',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_fields` ADD `maxlength` int(4) default NULL";

		$database->setQuery($sql);

		$database->query();
	
	}
	
	if(!in_array('date_format',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_fields` ADD `date_format` varchar(25) default NULL";

		$database->setQuery($sql);

		$database->query();
	
	}
	
	if(!in_array('parent_id',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_fields` ADD `parent_id` int(7) default '0'";

		$database->setQuery($sql);

		$database->query();
	
	}
	
	if(!in_array('selection_values',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_fields` ADD `selection_values` text default NULL";

		$database->setQuery($sql);

		$database->query();
	
	}
	
	if(!in_array('textareafee',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_fields` ADD `textareafee` text default NULL";

		$database->setQuery($sql);

		$database->query();
	
	}
	
	if(!in_array('showcharcnt',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_fields` ADD `showcharcnt` int(2) default '0'";

		$database->setQuery($sql);

		$database->query();
	
	}
	

	//Check if the fields exist or not for Payment Info Records

	$fieldName="cb_creditcardnumber";

	//$sql="Select count(*) From #__comprofiler_fields where name='$fieldName'";

	$sql="SHOW TABLES LIKE '%_comprofiler%'";

	$database->setQuery($sql);

	$database->getQuery();

	$total=$database->loadResult();

	if($total)

	{

		//Create CB tabs and CB fields for storing payment data

		$sql="Select tabid From #__comprofiler_tabs where title='Payment Information'";

		$database->setQuery($sql);

		$tabId=$database->loadResult();

		if(!$tabId)

		{

			$sql="INSERT INTO `#__comprofiler_tabs` VALUES ('', 'Payment Information', 'This information is used for online payments on this website.', 107, 10, '.5', 1, NULL, NULL, 1, '', 0, 'tab', 'cb_tabmain', -2);";

			$database->setQuery($sql);

			$database->query();

			$tabId=$database->insertid();

		}

			//Here we will add the additional fields for storing payment information

			$fieldName="cb_creditcardnumber";

			$sql="Select count(*) From #__comprofiler_fields where name='$fieldName'";

			$database->setQuery($sql);

			$total=$database->loadResult();

			if(!$total)

			{

				//Add the fields to this table

				$sql="INSERT INTO #__comprofiler_fields(`fieldid`,`name`,`table`,`title`,`description`,`type`,`maxlength`,`size`,`required`,`tabid`,`ordering`,`cols`,`rows`,`value`,`default`,`published`,`registration`,`profile`,`readonly`,`calculated`,`sys`,`params`) VALUES ('', '$fieldName', '#__comprofiler', 'Credit Card Number', 'Enter your card number without any dashes or spaces like aaaabbbbccccdddd', 'text', 16, 16, 0, $tabId, 5, 0, 0, NULL, NULL, 1, 0, 0, 0, 0, 0,  NULL);"	;

				$database->setQuery($sql);

				$database->query();

				$fieldId=$database->insertid();

				//Add this field to #___comprofiler table

				$sql="Alter table #__comprofiler add `$fieldName` VARCHAR( 255 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL";

				$database->setQuery($sql);

				$database->query();

			}

			$fieldName="cb_expdate";

			$sql="Select count(*) From #__comprofiler_fields where name='$fieldName'";

			$database->setQuery($sql);

			$total=$database->loadResult();

			if(!$total)

			{

				//Add the fields to this table

				$sql="INSERT INTO #__comprofiler_fields(`fieldid`,`name`,`table`,`title`,`description`,`type`,`maxlength`,`size`,`required`,`tabid`,`ordering`,`cols`,`rows`,`value`,`default`,`published`,`registration`,`profile`,`readonly`,`calculated`,`sys`,`params`) VALUES ('', '$fieldName', '#__comprofiler', 'Expiration Date', 'Enter your credit card expiration date as mm/yy', 'text', 5, 5, 0, $tabId, 6, 0, 0, NULL, NULL, 1, 0, 0, 0, 0, 0,  NULL);"	;

				$database->setQuery($sql);

				$database->query();

				$fieldId=$database->insertid();

				//Add this field to #___comprofiler table

				$sql="Alter table #__comprofiler add `$fieldName` VARCHAR( 255 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL";

				$database->setQuery($sql);

				$database->query();

			}

			$fieldName="cb_routingnumber";

			$sql="Select count(*) From #__comprofiler_fields where name='$fieldName'";

			$database->setQuery($sql);

			$total=$database->loadResult();

			if(!$total)

			{

				//Add the fields to this table

				$sql="INSERT INTO #__comprofiler_fields(`fieldid`,`name`,`table`,`title`,`description`,`type`,`maxlength`,`size`,`required`,`tabid`,`ordering`,`cols`,`rows`,`value`,`default`,`published`,`registration`,`profile`,`readonly`,`calculated`,`sys`,`params`) VALUES ('', '$fieldName', '#__comprofiler', 'ABA Routing Number', 'Enter your 9-digit routing number for your checking account. Do not use any space or other characters.', 'text', 9, 10, 0, $tabId, 3, 0, 0, NULL, NULL, 1, 0, 0, 0, 0, 0,  NULL);"	;

				$database->setQuery($sql);

				$database->query();

				$fieldId=$database->insertid();

				//Add this field to #___comprofiler table

				$sql="Alter table #__comprofiler add `$fieldName` VARCHAR( 255 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL";

				$database->setQuery($sql);

				$database->query();

			}

			$fieldName="cb_acctnumber";

			$sql="Select count(*) From #__comprofiler_fields where name='$fieldName'";

			$database->setQuery($sql);

			$total=$database->loadResult();

			if(!$total)

			{

				//Add the fields to this table

				$sql="INSERT INTO #__comprofiler_fields(`fieldid`,`name`,`table`,`title`,`description`,`type`,`maxlength`,`size`,`required`,`tabid`,`ordering`,`cols`,`rows`,`value`,`default`,`published`,`registration`,`profile`,`readonly`,`calculated`,`sys`,`params`) VALUES ('', '$fieldName', '#__comprofiler', 'Bank Account Number', 'Enter your bank account number with no spaces or other characters.', 'text', 0, 0, 0, $tabId, 1, 0, 0, NULL, NULL, 1, 0, 0, 0, 0, 0, NULL);"	;

				$database->setQuery($sql);

				$database->query();

				$fieldId=$database->insertid();

				//Add this field to #___comprofiler table

				$sql="Alter table #__comprofiler add `$fieldName` VARCHAR( 255 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL";

				$database->setQuery($sql);

				$database->query();

			}

			$fieldName="cb_bankname";

			$sql="Select count(*) From #__comprofiler_fields where name='$fieldName'";

			$database->setQuery($sql);

			$total=$database->loadResult();

			if(!$total)

			{

				//Add the fields to this table

				$sql="INSERT INTO #__comprofiler_fields(`fieldid`,`name`,`table`,`title`,`description`,`type`,`maxlength`,`size`,`required`,`tabid`,`ordering`,`cols`,`rows`,`value`,`default`,`published`,`registration`,`profile`,`readonly`,`calculated`,`sys`,`params`) VALUES ('', '$fieldName', '#__comprofiler', 'Bank Name', 'Enter the name of your Bank.', 'text', 60, 20, 0, $tabId, 2, 0, 0, NULL, NULL, 1, 0, 0, 0, 0, 0,  NULL);"	;

				$database->setQuery($sql);

				$database->query();

				$fieldId=$database->insertid();

				//Add this field to #___comprofiler table

				$sql="Alter table #__comprofiler add `$fieldName` VARCHAR( 255 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL";

				$database->setQuery($sql);

				$database->query();

			}

			$fieldName="cb_cardtype";

			$sql="Select count(*) From #__comprofiler_fields where name='$fieldName'";

			$database->setQuery($sql);

			$total=$database->loadResult();

			if(!$total)

			{

				//Add the fields to this table

				$sql="INSERT INTO #__comprofiler_fields(`fieldid`,`name`,`table`,`title`,`description`,`type`,`maxlength`,`size`,`required`,`tabid`,`ordering`,`cols`,`rows`,`value`,`default`,`published`,`registration`,`profile`,`readonly`,`calculated`,`sys`,`params`) VALUES ('', '$fieldName', '#__comprofiler', 'Card Type', 'Please select the type of card you are using.', 'select', 0, 20, 0, $tabId, 7, 0, 0, NULL, NULL, 1, 0, 0, 0, 0, 0,  NULL);"	;

				$database->setQuery($sql);

				$database->query();

				$fieldId=$database->insertid();

				//Add this field to #___comprofiler table

				$sql="Alter table #__comprofiler add `$fieldName` VARCHAR( 255 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL";

				$database->setQuery($sql);

				$database->query();

				//add values to these type of fields

				$sql="INSERT INTO `#__comprofiler_field_values` VALUES ('', $fieldId, 'Visa', 1, 0);"		;

				$database->setQuery($sql);

				$database->query();

				$sql="INSERT INTO `#__comprofiler_field_values` VALUES ('', $fieldId, 'MasterCard', 2, 0);"		;

				$database->setQuery($sql);

				$database->query();

				$sql="INSERT INTO `#__comprofiler_field_values` VALUES ('', $fieldId, 'Discover', 3, 0);"		;

				$database->setQuery($sql);

				$database->query();

				$sql="INSERT INTO `#__comprofiler_field_values` VALUES ('', $fieldId, 'American Express', 4, 0);"		;

				$database->setQuery($sql);

				$database->query();

			}

			$fieldName="cb_accountholder";

			$sql="Select count(*) From #__comprofiler_fields where name='$fieldName'";

			$database->setQuery($sql);

			$total=$database->loadResult();

			if(!$total)

			{

				//Add the fields to this table

				$sql="INSERT INTO #__comprofiler_fields(`fieldid`,`name`,`table`,`title`,`description`,`type`,`maxlength`,`size`,`required`,`tabid`,`ordering`,`cols`,`rows`,`value`,`default`,`published`,`registration`,`profile`,`readonly`,`calculated`,`sys`,`params`) VALUES ('', '$fieldName', '#__comprofiler', 'Account Holder', 'Enter the name on the bank account.', 'text', 50, 20, 0, $tabId, 8, 0, 0, NULL, NULL, 1, 0, 0, 0, 0, 0, NULL);"	;

				$database->setQuery($sql);

				$database->query();

				$fieldId=$database->insertid();

				//Add this field to #___comprofiler table

				$sql="Alter table #__comprofiler add `$fieldName` VARCHAR( 255 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL";

				$database->setQuery($sql);

				$database->query();

			}

	///////////////////////////////////////////////////////////

	//Check if the fields exist or not for Additional User Info

	///////////////////////////////////////////////////////////

		//Create CB tabs and CB fields for storing user information

		$sql="Select tabid From #__comprofiler_tabs where title='Additional Info'";

		$database->setQuery($sql);

		$tabId=$database->loadResult();

		if(!$tabId)

		{

			$sql="INSERT INTO `#__comprofiler_tabs` VALUES ('', 'Additional Info', 'Additional User contact information', 1, 10, '.5', 1, NULL, NULL, 1, NULL, 0, 'tab', 'cb_tabmain', -2);";

			$database->setQuery($sql);

			$database->query();

			$tabId=$database->insertid();

		}
		
	  $fieldName="cb_title";

		$sql="Select count(*) From #__comprofiler_fields where name='$fieldName'";

		$database->setQuery($sql);

		$total=$database->loadResult();

		if(!$total)

		{

			//Add the fields to this table

			$sql="INSERT INTO #__comprofiler_fields(`fieldid`,`name`,`table`,`title`,`description`,`type`,`maxlength`,`size`,`required`,`tabid`,`ordering`,`cols`,`rows`,`value`,`default`,`published`,`registration`,`profile`,`readonly`,`calculated`,`sys`,`params`) VALUES ('', '$fieldName', '#__comprofiler', 'Title', '', 'text', 0, 0, 0, '$tabId', 7, 0, 0, NULL, NULL, 1, 1, 1, 0, 0, 0,  NULL);"	;

			$database->setQuery($sql);

			$database->query();

			$fieldId=$database->insertid();

			//Add this field to #___comprofiler table

			$sql="Alter table #__comprofiler add `$fieldName` VARCHAR( 255 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL";

			$database->setQuery($sql);

			$database->query();

		}

		$fieldName="cb_address";

		$sql="Select count(*) From #__comprofiler_fields where name='$fieldName'";

		$database->setQuery($sql);

		$total=$database->loadResult();

		if(!$total)

		{

			//Add the fields to this table

			$sql="INSERT INTO #__comprofiler_fields(`fieldid`,`name`,`table`,`title`,`description`,`type`,`maxlength`,`size`,`required`,`tabid`,`ordering`,`cols`,`rows`,`value`,`default`,`published`,`registration`,`profile`,`readonly`,`calculated`,`sys`,`params`) VALUES ('', '$fieldName', '#__comprofiler', 'Address', '', 'text', 0, 0, 0, '$tabId', 7, 0, 0, NULL, NULL, 1, 1, 1, 0, 0, 0,  NULL);"	;

			$database->setQuery($sql);

			$database->query();

			$fieldId=$database->insertid();

			//Add this field to #___comprofiler table

			$sql="Alter table #__comprofiler add `$fieldName` VARCHAR( 255 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL";

			$database->setQuery($sql);

			$database->query();

		}

		$fieldName="cb_address2";

		$sql="Select count(*) From #__comprofiler_fields where name='$fieldName'";

		$database->setQuery($sql);

		$total=$database->loadResult();

		if(!$total)

		{

			//Add the fields to this table

			$sql="INSERT INTO #__comprofiler_fields(`fieldid`,`name`,`table`,`title`,`description`,`type`,`maxlength`,`size`,`required`,`tabid`,`ordering`,`cols`,`rows`,`value`,`default`,`published`,`registration`,`profile`,`readonly`,`calculated`,`sys`,`params`) VALUES ('', '$fieldName', '#__comprofiler', 'Address 2', '', 'text', 0, 0, 0, '$tabId', 7, 0, 0, NULL, NULL, 1, 1, 1, 0, 0, 0,  NULL);"	;

			$database->setQuery($sql);

			$database->query();

			$fieldId=$database->insertid();

			//Add this field to #___comprofiler table

			$sql="Alter table #__comprofiler add `$fieldName` VARCHAR( 255 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL";

			$database->setQuery($sql);

			$database->query();

		}

		//Here we will begin adding fields for additional user info

		$fieldName="cb_website";

		$sql="Select count(*) From #__comprofiler_fields where name='$fieldName'";

		$database->setQuery($sql);

		$total=$database->loadResult();

		if(!$total)

		{

			//Add the fields to this table

			$sql="INSERT INTO #__comprofiler_fields(`fieldid`,`name`,`table`,`title`,`description`,`type`,`maxlength`,`size`,`required`,`tabid`,`ordering`,`cols`,`rows`,`value`,`default`,`published`,`registration`,`profile`,`readonly`,`calculated`,`sys`,`params`) VALUES ('', '$fieldName', '#__comprofiler', 'Website', '', 'webaddress', 0, 0, 0, '$tabId', 1, 0, 0, NULL, NULL, 1, 0, 1, 0, 0, 0,  NULL);"	;

			$database->setQuery($sql);

			$database->query();

			$fieldId=$database->insertid();

			//Add this field to #___comprofiler table

			$sql="Alter table #__comprofiler add `$fieldName` VARCHAR( 255 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL";

			$database->setQuery($sql);

			$database->query();

		}

		$fieldName="cb_company";

		$sql="Select count(*) From #__comprofiler_fields where name='$fieldName'";

		$database->setQuery($sql);

		$total=$database->loadResult();

		if(!$total)

		{

			//Add the fields to this table

			$sql="INSERT INTO #__comprofiler_fields(`fieldid`,`name`,`table`,`title`,`description`,`type`,`maxlength`,`size`,`required`,`tabid`,`ordering`,`cols`,`rows`,`value`,`default`,`published`,`registration`,`profile`,`readonly`,`calculated`,`sys`,`params`) VALUES ('', '$fieldName', '#__comprofiler', 'Company', '', 'text', 0, 0, 0, '$tabId', 2, 0, 0, NULL, NULL, 1, 1, 1, 0, 0, 0,  NULL);"	;

			$database->setQuery($sql);

			$database->query();

			$fieldId=$database->insertid();

			//Add this field to #___comprofiler table

			$sql="Alter table #__comprofiler add `$fieldName` VARCHAR( 255 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL";

			$database->setQuery($sql);

			$database->query();

		}

		$fieldName="cb_phone";

		$sql="Select count(*) From #__comprofiler_fields where name='$fieldName'";

		$database->setQuery($sql);

		$total=$database->loadResult();

		if(!$total)

		{

			//Add the fields to this table

			$sql="INSERT INTO #__comprofiler_fields(`fieldid`,`name`,`table`,`title`,`description`,`type`,`maxlength`,`size`,`required`,`tabid`,`ordering`,`cols`,`rows`,`value`,`default`,`published`,`registration`,`profile`,`readonly`,`calculated`,`sys`,`params`) VALUES ('', '$fieldName', '#__comprofiler', 'Phone', '', 'text', 0, 0, 0, '$tabId', 8, 0, 0, NULL, NULL, 1, 1, 1, 0, 0, 0, NULL);"	;

			$database->setQuery($sql);

			$database->query();

			$fieldId=$database->insertid();

			//Add this field to #___comprofiler table

			$sql="Alter table #__comprofiler add `$fieldName` VARCHAR( 255 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL";

			$database->setQuery($sql);

			$database->query();

		}

		$fieldName="cb_city";

		$sql="Select count(*) From #__comprofiler_fields where name='$fieldName'";

		$database->setQuery($sql);

		$total=$database->loadResult();

		if(!$total)

		{

			//Add the fields to this table

			$sql="INSERT INTO #__comprofiler_fields(`fieldid`,`name`,`table`,`title`,`description`,`type`,`maxlength`,`size`,`required`,`tabid`,`ordering`,`cols`,`rows`,`value`,`default`,`published`,`registration`,`profile`,`readonly`,`calculated`,`sys`,`params`) VALUES ('', '$fieldName', '#__comprofiler', 'City', '.', 'text', 0, 0, 0, '$tabId', 3, 0, 0, NULL, NULL, 1, 1, 1, 0, 0, 0,  NULL);"	;

			$database->setQuery($sql);

			$database->query();

			$fieldId=$database->insertid();

			//Add this field to #___comprofiler table

			$sql="Alter table #__comprofiler add `$fieldName` VARCHAR( 255 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL";

			$database->setQuery($sql);

			$database->query();

		}

		$fieldName="cb_state";

		$sql="Select count(*) From #__comprofiler_fields where name='$fieldName'";

		$database->setQuery($sql);

		$total=$database->loadResult();

		if(!$total)

		{

			//Add the fields to this table

			$sql="INSERT INTO #__comprofiler_fields(`fieldid`,`name`,`table`,`title`,`description`,`type`,`maxlength`,`size`,`required`,`tabid`,`ordering`,`cols`,`rows`,`value`,`default`,`published`,`registration`,`profile`,`readonly`,`calculated`,`sys`,`params`) VALUES ('', '$fieldName', '#__comprofiler', 'State', '', 'text', 10, 4, 0, '$tabId', 4, 0, 0, NULL, NULL, 1, 1, 1, 0, 0, 0,  NULL);"	;

			$database->setQuery($sql);

			$database->query();

			$fieldId=$database->insertid();

			//Add this field to #___comprofiler table

			$sql="Alter table #__comprofiler add `$fieldName` VARCHAR( 255 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL";

			$database->setQuery($sql);

			$database->query();

		}

		$fieldName="cb_zipcode";

		$sql="Select count(*) From #__comprofiler_fields where name='$fieldName'";

		$database->setQuery($sql);

		$total=$database->loadResult();

		if(!$total)

		{

			//Add the fields to this table

			$sql="INSERT INTO #__comprofiler_fields(`fieldid`,`name`,`table`,`title`,`description`,`type`,`maxlength`,`size`,`required`,`tabid`,`ordering`,`cols`,`rows`,`value`,`default`,`published`,`registration`,`profile`,`readonly`,`calculated`,`sys`,`params`) VALUES ('', '$fieldName', '#__comprofiler', 'Zip Code', '', 'text', 0, 0, 0, '$tabId', 5, 0, 0, NULL, NULL, 1, 1, 1, 0, 0, 0,  NULL);"	;

			$database->setQuery($sql);

			$database->query();

			$fieldId=$database->insertid();

			//Add this field to #___comprofiler table

			$sql="Alter table #__comprofiler add `$fieldName` VARCHAR( 255 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL";

			$database->setQuery($sql);

			$database->query();

		}

		$fieldName="cb_country";

		$sql="Select count(*) From #__comprofiler_fields where name='$fieldName'";

		$database->setQuery($sql);

		$total=$database->loadResult();

		if(!$total)

		{

			//Add the fields to this table

			$sql="INSERT INTO #__comprofiler_fields(`fieldid`,`name`,`table`,`title`,`description`,`type`,`maxlength`,`size`,`required`,`tabid`,`ordering`,`cols`,`rows`,`value`,`default`,`published`,`registration`,`profile`,`readonly`,`calculated`,`sys`,`params`) VALUES ('', '$fieldName', '#__comprofiler', 'Country', '', 'text', 0, 0, 0, '$tabId', 6, 0, 0, NULL, NULL, 1, 1, 1, 0, 0, 0,  NULL);"	;

			$database->setQuery($sql);

			$database->query();

			$fieldId=$database->insertid();

			//Add this field to #___comprofiler table

			$sql="Alter table #__comprofiler add `$fieldName` VARCHAR( 255 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL";

			$database->setQuery($sql);

			$database->query();

		}

	}

	// make changes or additions to #__dtregister_codes

	$sql="Show columns from #__dtregister_codes";

	$database->setQuery($sql);

	$rows=$database->loadObjectList();

	$arrFields=array();

	for($i=0,$n=count($rows);$i<$n;$i++)

	{

		$row=$rows[$i];

		$arrFields[]=$row->Field;

	}

	if(!in_array('limit',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_codes` ADD `limit` INT(4) default '0'";

		$database->setQuery($sql);

		$database->query();

	}
	
	if(!in_array('events_enable',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_codes` ADD `events_enable` INT(2) default '0'";

		$database->setQuery($sql);

		$database->query();

	}
	
	// make changes or additions to #__dtregister_history

	$sql="Show columns from #__dtregister_history";

	$database->setQuery($sql);

	$rows=$database->loadObjectList();

	$arrFields=array();

	for($i=0,$n=count($rows);$i<$n;$i++)

	{

		$row=$rows[$i];

		$arrFields[]=$row->Field;

	}

	if(!in_array('transaction_id',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_history` ADD `transaction_id` VARCHAR(255) default NULL";

		$database->setQuery($sql);

		$database->query();

	}
	
// make changes or additions to #__dtregister_waiting

	$sql="Show columns from #__dtregister_waiting";

	$database->setQuery($sql);

	$rows=$database->loadObjectList();

	$arrFields=array();

	for($i=0,$n=count($rows);$i<$n;$i++)

	{

		$row=$rows[$i];

		$arrFields[]=$row->Field;

	}

	if(!in_array('created',$arrFields))

	{

		$sql="ALTER TABLE `#__dtregister_waiting` ADD `created` DATETIME default NULL";

		$database->setQuery($sql);

		$database->query();

	}
	
	// Change the old jos_event_waiting to jos_dtregister_waiting
	
	$database->setQuery("Describe #__event_waiting");
	$rows =  $database->loadObjectList();
	if($rows==null){
	  
	   $query = "CREATE TABLE IF NOT EXISTS `#__dtregister_waiting` (
				   `id` int(11) NOT NULL auto_increment,
				   `created` datetime default NULL,
				   `event_id` int(11) default NULL,
				   `fname` varchar(50) default NULL,
				   `phone` varchar(50) default NULL,
				   `email` varchar(50) default NULL,
				   `address` varchar(255) default NULL,
				   `state` varchar(50) default NULL,
				   `country` varchar(50) default NULL,
				   `zip` varchar(50) default NULL,
				   `number_registrants` int(11) default NULL,
				   `lname` varchar(50) default NULL,
				   PRIMARY KEY  (`id`)
				 ) TYPE=MyISAM;";
	}else{
	  
	   $query = "RENAME TABLE  #__event_waiting TO #__dtregister_waiting" ;
	}
	$database->setQuery($query);
	
	$database->query();
    if(JFolder::exists(JPATH_SITE.'/components/com_joomfish')  ){
	   require_once( JPATH_SITE.'/components/com_dtregister/class.dtregister.php');
	   $dtconfig =  new DTConfig();
     $dtconfig->joomfish_fix();
	}
	// Onscreen text after successful installation
	
 if(!is_dir('../images/dtregister/locations/')){
   print "<font color=red>Failed to create folder /images/dtregister/locations/  <br />Please create this directory manually and make sure it is writable.</font><br />";
 }
  echo "<p><b>DT Register component Installed Successfully!</b></p>";

  echo "<p>To create your landing page for registration and list your events, simply create a Component menu item for DT Register.

<br /><br /></p>";

  echo "<p>You need the JEvents calendar component along with DT Register and should use version 1.5.2 or later. This is required. To download it, go to:

<br><a href=\"http://joomlacode.org/gf/project/jevents/frs/\" target=\"_blank\">http://joomlacode.org/gf/project/jevents/frs/</a>.

<br /><br /></p>";

  echo "<p>Be sure to check our website at <a href=\"http://www.dthdevelopment.com\" target=\"_blank\">www.DTHDevelopment.com</a> for video tutorials and other support.

<br /><br /></p>";

}

?>