<?php

/*************************************************************************/
/* DOCEBO CMS - Content Management System                                */
/* ============================================                          */
/*                                                                       */
/* Copyright (c) 2005 by Giovanni Derks <virtualdarkness[AT]gmail-com>   */
/* http://www.docebocms.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.        */
/*************************************************************************/

if (!defined("IN_DOCEBO")) die ("You can't access this file directly...");

function bannersBlockEdit(& $out, & $lang, & $form, $block_id, $sub_id) {

	$opt=loadBlockOption($block_id);
	$textof=loadTextof($block_id);

	$out->add(getBlockTitleField($form, $lang, $block_id));

	$out->add(banner_cat_list($form, $lang, $opt["cat_id"]));

 	$out->add(block_css_list($form, $lang, $opt["css"]));

	$pubdate=(isset($opt["pubdate"]) ? $opt["pubdate"] : "");
	$expdate=(isset($opt["expdate"]) ? $opt["expdate"] : "");
 	$out->add(show_pubexp_table($form, $lang, $pubdate, $expdate));

	$out->add(getBlindNavDescField($form, $lang, $opt));	
}



function bannersBlockSave($block_id, $sub_id) {

	saveBlockTitle($block_id);

	saveParam($block_id, "css", (int)$_POST["css"]);
	saveParam($block_id, "cat_id", (int)$_POST["cat_id"]);

	save_pubexp_info($block_id);
	
	saveBlindNavDesc($block_id);

}


function bannersBlockAdd($block_id, $sub_id) {

	saveParam($block_id, "css", 1);
	saveParam($block_id, "cat_id", 0);

}


function banner_cat_list(& $form, & $lang, $cur) {

	$res="";

	$qtxt="SELECT * FROM ".$GLOBALS["prefix_cms"]."_banner_cat WHERE language='".getLanguage()."' ORDER BY cat_name";
	$q=mysql_query($qtxt);

 	$cat_arr=array();

 	if (($q) && (mysql_num_rows($q) > 0)) {
 		while($row=mysql_fetch_array($q)) {
			$cat_arr[$row["cat_id"]]=$row["cat_name"];
			$i++;
		}
	}

	$res.=$form->getDropdown($lang->def("_BANNER_CAT").":", "cat_id", "cat_id", $cat_arr, $cur);

	return $res;
}



// OLD / TEMP:


require_once($GLOBALS["where_cms"]."/admin/modules/manpage/manBlocks.php");

function banners_options( $block ) {
	global $prefixCms;

	$backurl = $block->getBackurl();
	echo '<form method="POST" action="'.page_url(array()).'">' //&amp;insert=1
		.'<div class="stdBlock">';
	$block->loadParamAsInput();

	$idBlock=$block->getIdBlock();
	$q=mysql_query("SELECT title FROM ".$prefixCms."_area_block WHERE idBlock='$idBlock';");
	list($title)=mysql_fetch_row($q);

	$opt=loadBlockOption($idBlock); //--debug-//print_r($opt);
	echo "<br />";


	echo("<br /><b>"._BLOCK_TITLE.":</b>\n");
	echo("<input type=\"text\" id=\"title\" name=\"title\" size=\"25\" value=\"".$title."\" /><br />\n");

	echo("<br />\n");
	$db_group=db_block_groups($idBlock);
	sel_block_groups($idBlock, $db_group);

	echo("<br /><b>"._BLOCK_STYLE.":</b>\n");
	block_css_list($opt["css"]);

	echo("<br /><br />\n");
	show_pubexp_table($opt["pubdate"], $opt["expdate"]);

	echo("<br /><b>"._TYPE.":</b>\n");
	$dfv=array("block", "large");
	$dfl=array(_BLOCK, _LARGE);
	echo("<select id=\"type\" name=\"type\">\n");

	foreach ($dfv as $key=>$val) {
		if ($val == $opt["type"]) $sel=" selected=\"selected\""; else $sel="";
		echo("<option value=\"$val\"$sel>".$dfl[$key]."</option>\n");
	}
	echo("</select><br />\n");


	echo '<br /><input class="button" type="submit" id="save" name="save" value="'._BANNERS_INSERT.'" />'
		.'</div>'
		.'</form>';

	// back option
	echo '<form method="post" action="'.$backurl['backurl'].'">'
		.'<div class="stdBlock">';
	$block->loadParamAsInput();
	echo '<input class="button" type="submit" value="'._BANNERS_BACK.'" />'
		.'</div>'
		.'</form>';

}



function save_options( $block ) {
	global $prefixCms;

	//--debug--// print_r($_POST);

	$backurl = $block->getBackurl();
	$idBlock=$block->getIdBlock();

	if ((int)$_POST["folder_id"] == 0)
		$path="/";
	else {
		$q=mysql_query("SELECT * FROM ".$prefixCms."_media_dir WHERE id='".$_POST["folder_id"]."';");
		$row=mysql_fetch_array($q);

		$path=$row["path"];
	}

	$q=mysql_query("UPDATE ".$prefixCms."_area_block SET title='".$_POST["title"]."' WHERE idBlock='$idBlock';");

	$err="";
	saveParam($idBlock, "type", $_POST["type"]);
	saveParam($idBlock, "css", (int)$_POST["css"]);
	if (check_period($ts_pub, $ts_exp)) {
		saveParam($idBlock, "pubdate", (int)$ts_pub);
		saveParam($idBlock, "expdate", (int)$ts_exp);
	}
	else
		$err=_INVALID_PERIOD;
	save_block_groups($idBlock, $_POST["idGroups"]);

	// back option
	echo '<form method="post" action="'.$backurl['backurl'].'">'
		.'<div class="stdBlock">';
	$block->loadParamAsInput();

	if ($err == "") {
		echo("<b>"._BANNERS_ALLOK."</b><br />");
		echo '<input class="button" type="submit" value="'._BANNERS_BACK.'" />';
	}
	else {
		echo("<b><font color=\"#FF0000\">"._WARN."</font>:</b> $err<br />"._SAVEDREMAIN."<br /><br />\n");
		echo '<input class="button" type="submit" value="'._BANNERS_BACK.'" />';
	}


	echo '</div></form>';
}

?>