<?php
/*============================================================================ 
Module: Articles
============================================================================*/

// Check authorisation
if (!isset($gCms)) exit;

// Get version
$current_version = $oldversion;

// Get db handle and set other vars
$dict = NewDataDictionary($db);
$taboptarray = array('mysql' => 'TYPE=MyISAM');
$message = '';

// upgrade workflow
switch($current_version){

	case '0.1':
		// Set new current version
		$current_version = '0.1.1';

	case '0.1.1':
		// Set new current version
		$current_version = '0.1.2';

	case '0.1.2':
		// Set preferences
		$this->SetPreference('vat_use',0);
		$this->SetPreference('vat_standard',19);
		// Add vat column to the article table
		$sqlarray = $dict->AddColumnSQL(cms_db_prefix().'module_articles_articles','vat F');
		$dict->ExecuteSQLArray($sqlarray);
		// Update existing products
		$db->Execute('UPDATE '.cms_db_prefix().'module_articles_articles SET vat = 19',array());
		$message.= $this->Lang('vat_added');
		// Add vat column to the order table
		$sqlarray = $dict->AddColumnSQL(cms_db_prefix().'module_articles_orders','vat C(20)');
		$dict->ExecuteSQLArray($sqlarray);
		// Set new current version
		$current_version = '0.1.3';

	case '0.1.3':
		// Add vat column to the article table
		$sqlarray = $dict->AddColumnSQL(cms_db_prefix().'module_articles_articles','user_id I,datetime I,image_text C(255),gallery_id I,created I,modified I');
		$dict->ExecuteSQLArray($sqlarray);
		// Set new current version
		$current_version = '0.1.4';

	case '0.1.4':
		// Set new current version
		$current_version = '0.2';

	case '0.2':
		// Set new current version
		$current_version = '0.2.1';

}

// put mention into the admin log
$this->Audit( 0, $this->Lang('friendlyname'), $this->Lang('postupgrade',$this->GetVersion()).$message);

// EOF