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

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

// Get db handle
$dict = NewDataDictionary($db);
$taboptarray = array('mysql' => 'TYPE=MyISAM');

// create tables for articles
$flds = '
	entry_id I KEY AUTO,
	user_id I,
	active I1,
	datetime I,
	title C(255),
	short_desc X,
	long_desc X,
	detail_link I,
	start_date '.CMS_ADODB_DT.',
	end_date '.CMS_ADODB_DT.',
	availibility I,
	price C(255),
	vat F,
	delivery_time C(255),
	shipping_costs C(255),
	cart I1,
	url C(255),
	image_url C(255),
	image_text C(255),
	gallery_id I,
	sort_order I,
	seo_url C(150),
	meta_title C(70),
	meta_description C(160),
	noindex I1,
	nofollow I1,
	noarchive I1,
	noodp I1,
	notranslate I1,
	returnid I,
	created I,
	modified I';
$sqlarray = $dict->CreateTableSQL(cms_db_prefix().'module_articles_articles', $flds, $taboptarray);
$dict->ExecuteSQLArray($sqlarray);

// create tables for categories
$flds = '
	entry_id I KEY AUTO,
	belongs_to I,
	active I1,
	title C(255),
	short_desc X,
	long_desc X,
	image_url C(255),
	sort_order I,
	seo_url C(150),
	meta_title C(70),
	meta_description C(160),
	noindex I1,
	nofollow I1,
	noarchive I1,
	noodp I1,
	notranslate I1,
	returnid I';
$sqlarray = $dict->CreateTableSQL(cms_db_prefix().'module_articles_category', $flds, $taboptarray);
$dict->ExecuteSQLArray($sqlarray);
$flds = '
	cat_id I,
	article_id I,
	modified_date '.CMS_ADODB_DT;
$sqlarray = $dict->CreateTableSQL(cms_db_prefix().'module_articles_category_articles', $flds, $taboptarray);
$dict->ExecuteSQLArray($sqlarray);

// create tables for orders
$flds = '
	entry_id I KEY AUTO,
	cart X,
	price C(20),
	vat C(20),
	delivery_costs C(20),
	sum C(20),
	payment C(20),
	bank_account X,
	salutation C(50),
	firstname C(100),
	lastname C(100),
	city C(100),
	country C(50),
	org C(100),
	tel C(50),
	mail C(100),
	address X,
	newsletter I1,
	notice X';
$sqlarray = $dict->CreateTableSQL(cms_db_prefix().'module_articles_orders', $flds, $taboptarray);
$dict->ExecuteSQLArray($sqlarray);

// insert default template
$templatecontent = '
<div class="articles">
	{foreach from=$articles item=\'article\'}
		<div class="articleitem">
			<span class="articledate">
			{if $article->start|date_format:"%Y-%m-%d" == $article->end|date_format:"%Y-%m-%d"}
				{$article->start|date_format:"%e.%m.%Y"}{if $article->start|date_format:"%H:%M" == $article->end|date_format:"%H:%M"}
					{*{$article->start|date_format:"%H:%M"} Uhr*}
				{else},
					{$article->start|date_format:"%H:%M"} - {$article->end|date_format:"%H:%M"} Uhr
				{/if}
			{else}
				{$article->start|date_format:"%e.%m.%Y"} - {$article->end|date_format:"%e.%m.%Y"}
			{/if}
			</span>
			{if $article->linkid>1}<a href="{cms_selflink href=$article->linkid}" class="articlelink" title="{$article->title|strip_tags|replace:\'"\':\'\'}"><h2 class="articletitle">{$article->title}</h2></a>{else}<h2 class="articletitle">{$article->title}</h2>{/if}
			{if $article->content}<div class="articlecontent">{$article->content}</div>{/if}
		</div>
	{/foreach}
</div>
';
$this->SetTemplate('default', $templatecontent, $this->GetName());
$this->SetPreference('default_template','default');

// set default preferences
$this->SetPreference('returnid',15);
$this->SetPreference('mode_categories','Categories');
$this->SetPreference('mode_articles','Articles');
$this->SetPreference('mode_article','Article');
$this->SetPreference('mode_cart','Cart');
$this->SetPreference('mode_cartsnippet','CartSnippet');
$this->SetPreference('mode_form','Form');
$this->SetPreference('mode_summary','Summary');
$this->SetPreference('mode_ack','Ack');
$this->SetPreference('longdec_use',0);
$this->SetPreference('image_use',0);
$this->SetPreference('order_use',1);
$this->SetPreference('url_use',0);
$this->SetPreference('detailpage_use',0);
$this->SetPreference('dates_use',0);
$this->SetPreference('availibility_use',0);
$this->SetPreference('availibility_count',0);
$this->SetPreference('availibility_show',0);
$this->SetPreference('deliverytime_use',0);
$this->SetPreference('shippingcosts_use',0);
$this->SetPreference('price_use',0);
$this->SetPreference('vat_use',0);
$this->SetPreference('vat_standard',19);
$this->SetPreference('cart_use',0);
$this->SetPreference('currency','?');
$this->SetPreference('cash_on_delivery','7.00');
$this->SetPreference('emails',substr($_SERVER['HTTP_HOST'],0,4)=='www.' ? 'info@'.substr($_SERVER['HTTP_HOST']) : 'info@'.$_SERVER['HTTP_HOST']);
$this->SetPreference('subject_owner',$this->Lang('subject_owner'));
$this->SetPreference('subject_customer',$this->Lang('subject_customer'));
$this->SetPreference('date_format',$this->Lang('date_format'));
$this->SetPreference('seo_use',0);
$this->SetPreference('countries','Germany,Austria,Switzerland');

// create permissions
$this->CreatePermission('Articles: modify articles', $this->Lang('modarticles'));
$this->CreatePermission('Articles: modify categories', $this->Lang('modcategories'));
$this->CreatePermission('Articles: modify settings', $this->Lang('modsettings'));
$this->CreatePermission('Articles: show orders', $this->Lang('vieworders'));

// create image folders
$newdir = cms_join_path($config['image_uploads_path'],'Articles');
if (!is_dir($newdir)) if (!mkdir($newdir)) { echo "Error creating dir $newdir"; }
$newdir = cms_join_path($config['image_uploads_path'],'Articles','categories');
if (!is_dir($newdir)) if (!mkdir($newdir)) { echo "Error creating dir $newdir"; }
$newdir = cms_join_path($config['image_uploads_path'],'Articles','articles');
if (!is_dir($newdir)) if (!mkdir($newdir)) { echo "Error creating dir $newdir"; }

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

// EOF