<?php
//v1.0.4 www.bcoos.net 2006/10 GPL
//v1.2 www.exoops.info 2006/03 
// $Id: pref.php,v 1.10 2004/02/06 21:22:10 nobse Exp $
// ------------------------------------------------------------------------- //
//               E-Xoops: Content Management for the Masses                  //
//                       < http://www.e-xoops.com >                          //
// ------------------------------------------------------------------------- //
// Original Author: Nobse, Bama
// Author Website : http://www.e-xoops.de, http://service.bama-webdesign.de
// License Type   : GPL: See /manual/LICENSES/GPL.txt
// ------------------------------------------------------------------------- //
include("admin_header.php");
include("../cache/config.php");
function Conf() {
	global $db, $xoopsUser, $bcoosConfig, $xoopsModule, $anoevent, $daycolor, $moderat, $nextncount, $blcklmt, $beginn, $weekcolor, $locat_yn, $user_locyn, $user_remind, $shownews, $showteiln;
	
	xoops_cp_header();
	
	OpenTable();
	echo "<h5><a href='index.php'>"._MAIN."</a>: "._CONFIGURATION."</h5>";
	
	echo "<FORM ACTION=\"pref.php?pa=ConfOk\" METHOD=POST>
		<TABLE BORDER=0>
		<TR>
	      <TD>"._CAL_MODERATE."</TD>
	      <TD><SELECT NAME=\"moderats\">";
    if ($moderat==1) {
		echo "<OPTION VALUE=\"1\" selected>  "._YES."";
		echo "<OPTION VALUE=\"0\">  "._NO."";
	} else {
		echo "<OPTION VALUE=\"1\"> "._YES."";
		echo "<OPTION VALUE=\"0\" selected>  "._NO."";
		}
	echo " </SELECT></TD>
	    </TR>
		
		<TR>
	      <TD>"._CAL_LOCATIONYESNO."</TD>
	      <TD><SELECT NAME=\"locat_yns\">";
    if ($locat_yn==1) {
		echo "<OPTION VALUE=\"1\" selected>  "._YES."";
		echo "<OPTION VALUE=\"0\">  "._NO."";
	} else {
		echo "<OPTION VALUE=\"1\"> "._YES."";
		echo "<OPTION VALUE=\"0\" selected>  "._NO."";
		}
	echo " </SELECT></TD>
	    </TR>
		
		<TR>
	      <TD>"._CAL_USERLOCYN."</TD>
	      <TD><SELECT NAME=\"user_locyns\">";
    if ($user_locyn==1) {
		echo "<OPTION VALUE=\"1\" selected>  "._YES."";
		echo "<OPTION VALUE=\"0\">  "._NO."";
	} else {
		echo "<OPTION VALUE=\"1\"> "._YES."";
		echo "<OPTION VALUE=\"0\" selected>  "._NO."";
		}
	echo " </SELECT></TD>
	    </TR>		
		
		<TR>
	      <TD>"._CAL_USERREMIND."</TD>
	      <TD><SELECT NAME=\"user_reminds\">";
    if ($user_remind ==1) {
		echo "<OPTION VALUE=\"1\" selected>  "._YES."";
		echo "<OPTION VALUE=\"0\">  "._NO."";
	} else {
		echo "<OPTION VALUE=\"1\"> "._YES."";
		echo "<OPTION VALUE=\"0\" selected>  "._NO."";
		}
	echo " </SELECT></TD>
	    </TR>		
		
		<TR>
	      <TD>"._CAL_SHOWNEWS."</TD>
	      <TD><SELECT NAME=\"shownewss\">";
    if ($shownews ==1) {
		echo "<OPTION VALUE=\"1\" selected>  "._YES."";
		echo "<OPTION VALUE=\"0\">  "._NO."";
	} else {
		echo "<OPTION VALUE=\"1\"> "._YES."";
		echo "<OPTION VALUE=\"0\" selected>  "._NO."";
		}
	echo " </SELECT></TD>
	    </TR>
		
		<TR>
	      <TD>"._CAL_SHOWTEILN."</TD>
	      <TD><SELECT NAME=\"showteilns\">";
    if ($showteiln ==1) {
		echo "<OPTION VALUE=\"1\" selected>  "._YES."";
		echo "<OPTION VALUE=\"0\">  "._NO."";
	} else {
		echo "<OPTION VALUE=\"1\"> "._YES."";
		echo "<OPTION VALUE=\"0\" selected>  "._NO."";
		}
	echo " </SELECT></TD>
	    </TR>";		
echo "<tr><td nowrap>"._ANNOEVENT."</td>";
echo "<td width='100%'>";
$sql    = "SELECT groupid, name FROM ".$db->prefix("groups")." ORDER BY groupid";
$result = $db->query($sql);
$anno        = array();
$anno        = explode("|", $anoevent);
echo "<select name='annoevents[]' size='3' multiple='true' id='annoevents[]'>";
while ( $myrow = $db->fetchArray($result) ) {
	echo $myrow['name'];
	if (in_array($myrow['groupid'], $anno)){
		$sel = "selected";
	}else{
		$sel = "";
	}
echo "<option value=".$myrow['groupid']." $sel> ".$myrow['name']."</option>";
}
echo "</select></td></tr>";
	
		
		echo "<TR>
	      <TD>"._CAL_BEGINN."</TD>
	      <TD><SELECT NAME=\"beginns\">";
    if ($beginn==1) {
		echo "<OPTION VALUE=\"1\" selected>  "._MON."";
		echo "<OPTION VALUE=\"0\">  "._SUN."";
	} else {
		echo "<OPTION VALUE=\"1\"> "._MON."";
		echo "<OPTION VALUE=\"0\" selected>  "._SUN."";
		}
	echo " </SELECT></TD>
	    </TR>
	    <TR>
	      <TD>"._DAYCOLOREV."</TD>
	      <TD><INPUT TYPE=\"text\" NAME=\"daycolors\" SIZE='10' value=\"$daycolor\"></TD>
	    </TR>
		<TR>
	      <TD>"._WEEKCOLOREV."</TD>
	      <TD><INPUT TYPE=\"text\" NAME=\"weekcolors\" SIZE='10' value=\"$weekcolor\"></TD>
	    </TR>
	    <TR>
	      <TD>"._NEXTNCOUNT."</TD>
	      <TD><INPUT TYPE=\"text\" NAME=\"nextncounts\" SIZE='10' value=\"$nextncount\"></TD>
	    </TR>
	    <TR>
	      <TD>"._BLCKLMT."</TD>
	      <TD><INPUT TYPE=\"text\" NAME=\"blcklmts\" SIZE='10' value=\"$blcklmt\"></TD>
	    </TR>
	</TABLE><P>
	<INPUT TYPE=\"submit\" CLASS=\"button\" VALUE=\""._VALID."\">
	</FORM>";
	
	CloseTable();
	xoops_cp_footer();
}
function ConfOK($annoevents , $daycolors, $moderats, $nextncounts, $blcklmts, $beginns, $weekcolors, $locat_yns, $user_locyns, $user_reminds, $shownewss, $showteilns) {
	global $xoopsUser, $anoevent, $daycolor, $moderat, $nextncount, $blcklmt, $beginn, $weekcolor, $locat_yn, $user_locyn, $user_remind, $shownews, $showteiln;
	$allow_anno = $annoevents;
	$annoevents = "";
		if ( count($allow_anno) > 0 ) {
			foreach ( $allow_anno as $anno ) {
				$annoevents .= $anno."|";
			}
			$annoevents = substr($annoevents, 0, -1);
		}
	$file = fopen("../cache/config.php",'w');
  	$content = "<?\n";
  	$content .= "#####################################################\n";
	  	$content .= "#  Based on PHP-NUKE: ecalendar System\n";
	 $content .= "#  by Don Grabowski Don@ecomjunk.com -  http://ecomjunk.com\n";
	 $content .= "#\n";
	 $content .= "#  Calendrier version 1.1 Beta for Xoops 1.0 RC2\n";
	 $content .= "#  Copyright © 2002, Pascal Le Boustouller\n";
	 $content .= "#  webmaster@i-annonces.net - http://www.i-annonces.net\n";
	 $content .= "#  Licence: GPL\n";
	 $content .= "#\n";
	 $content .= "#  Merci de laisser ce copyright en place...\n";
	 $content .= "#####################################################\n\n";
	 $content .= "// Moderate events : yes=1 no=0\n";
	 $content .= "// Modération des évenements : oui=1 non=0\n";
	 $content .= "\$moderat = \"$moderats\";\n\n";
     $content .= "// Location indicate : yes=1 no=0\n";
	 $content .= "// L'endroit indiquent : oui=1 non=0\n";
	 $content .= "\$locat_yn = \"$locat_yns\";\n\n";
	 $content .= "// 1 les anonymes peuvent ajouter un evenement - 0 les anonymes ne peuvent pas ajouter un evenement\n";
	 $content .= "// 1 Anonymous can add an event - 0 Anonymous can't add an event;\n";
     $content .= "\$user_locyn = \"$user_locyns\";\n\n";
	 $content .= "// 1 les User peuvent ajouter un location - 0 les User ne peuvent pas ajouter un location\n";
	 $content .= "// 1 User can add an location - 0 User can't add an location;\n";
	 $content .= "\$anoevent = \"$annoevents\";\n\n";
	 $content .= "// Couleur du jour\n";
	 $content .= "// Day color\n";
	 $content .= "\$daycolor = \"$daycolors\";\n\n";
	 $content .= "// numbre evenements pour Next N block\n";
	 $content .= "// number of events in Next N events block\n";
	 $content .= "\$nextncount = \"$nextncounts\";\n\n";
	 $content .= "// numbre evenements pour limit block length \n";
	 $content .= "// number of events to limit all events block\n";
	 $content .= "\$blcklmt = \"$blcklmts\";\n\n";
	 $content .= "\$beginn = \"$beginns\";\n\n";
	 $content .= "\$weekcolor = \"$weekcolors\";\n\n";
	 $content .= "\$user_remind = \"$user_reminds\";\n\n";
	 $content .= "\$shownews = \"$shownewss\";\n\n";
	 $content .= "\$showteiln = \"$showteilns\";\n\n";
	 $content .= "?>";
    fwrite($file, $content);
    fclose($file);
	redirect_header("pref.php",1,_OKCONFIG);
	exit();	
}
switch($pa){
	case "ConfOk":
		ConfOk($annoevents, $daycolors, $moderats, $nextncounts, $blcklmts, $beginns, $weekcolors, $locat_yns, $user_locyns, $user_reminds, $shownewss, $showteilns);
		break;
	default:
		Conf();
		break;
}
?>
