<?php // $Id: cats.php,v 20.6 2004/01/11 12:30:15 EllselAn Exp $
/************************************************************************/
/* KalenderMx v1.3                                                      */
/* ===================                                                  */
/*  Calendar Module for vkpMx 2.x & phpNuke 5.5-7.0                     */
/*  Copyright (c) 2004 by A.Ellsel (kalender@pragmamx.org)              */
/*  http://www.pragmamx.org & http://ww.shiba-design.de                 */
/* -------------------------------------------------------------------- */
/* KalenderMx is based on EventCalendar 2.0                             */
/*  Copyright (c) 2001 Originally by Rob Sutton                         */
/*  http://smart.xnettech.net (Nuke Site)                               */
/*  Development continued by Aleks A.-Lessmann                          */
/* Included some ideas and changes by:                                  */
/*  flobee, bulli-frank, kicks, kochloeffel, FrankySz, Jubilee          */
/* -------------------------------------------------------------------- */
/* 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 or a newer version.   */
/************************************************************************/
if (!defined("CAL_MODULE_NAME")) die ("이 파일을 직접 접근할 수 없습니다."); // aus case datei

if (!defined("_CAL_ADM_SETCOLLINK")) define("_CAL_ADM_SETCOLLINK","admin.php?op=CalSetcols");

#error_reporting(E_ALL);
#########################################################################################
if (!isset($calconf)) include(CAL_MODULE_PATH."config/config.php");
include_once(CAL_MODULE_PATH."includes/functions.php");
get_lang(CAL_MODULE_NAME);
if ((!calIsAdmin()) || (!eregi("admin.php", $_SERVER["PHP_SELF"]))) {
	$op = "errNoAuthorized";
	}


#########################################################################################
function CalSavecols() {
	#mxDebugFuncVars($_POST);
	$setfile = CAL_MODULE_PATH."categories/".$_POST['x_trs_lng'].".php";

	$newcols = "";
	foreach($_POST['setcol'] as $i => $caption) {
		$newcols .= "\$caldotcolor[".$i."] = \"".$caption."\";\n";
		}

	$content = "<?php // write with: \$Id: cats.php,v 20.6 2004/01/11 12:30:15 EllselAn Exp $\n";
	$content .= "/************************************************************************/\n";
	$content .= "/* XCalender v".CAL_VERSION."                                           */\n";
	$content .= "/* ===================                                                  */\n";
	$content .= "/*  Calendar Module for vkpMx 2.x & phpNuke 5.5-7.0                     */\n";
	$content .= "/*  Copyright (c) 2004 by A.Ellsel (kalender@pragmamx.org)              */\n";
	$content .= "/*  Modified for Korean by Inhyun Choi (Inhyun.Choi@xybersystem.net)    */\n";
	$content .= "/*  http://www.pragmamx.org & http://ww.shiba-design.de                 */\n";
	$content .= "/*  http://www.xybersystem.net                                          */\n";
	$content .= "/************************************************************************/\n\n";
	$content .= "/// description of event dots color \n";
	$content .= "/// language: ".$_POST['x_trs_lng']." \n";
	$content .= "\n".$newcols."\n\n?>";

	#mxDebugFuncVars($content);	#exit;
	@chmod($setfile, 0666);
	$file = fopen($setfile, "w");
	$ok = fwrite($file, $content);
	fclose($file);
	@chmod($setfile, 0444);
	$ok = (int)$ok + 1;
	#print $ok; exit;
	Header("Location: "._CAL_ADM_SETCOLLINK."&trs_lng=".$_REQUEST['trs_lng']."&src_lng=".$_REQUEST['src_lng']."&ok=".$ok."");
	}


#########################################################################################
function CalSetcols() {
	$color_src = calgetlangsrc($_REQUEST['src_lng']);
	$color_trs = calgetlangsrc($_REQUEST['trs_lng']);
	$ok = (isset($_REQUEST['ok'])) ? $_REQUEST['ok'] : 0;
	if ($ok == 1) {
		$statmsg = _CALCONF1;
		}
	else if ($ok > 1) {
		$statmsg = _CALCONF2;
		}

	#mxDebugFuncVars($_REQUEST);
	$handle = @opendir(CAL_MODULE_PATH."images/colors");
	if (!$handle) return;
	while ($file = readdir($handle)) {
		if (preg_match("/^ball_(.+)\.gif/", $file, $matches)) {
			$imglist[(int)$matches[1]] = $matches[1]."&nbsp;<img src='".CAL_MODULE_PATH."images/colors/".$file."' alt='".$matches[1]."' width='14' height='14' border='0'>";
			}
		}
	closedir($handle);
	ksort($imglist);
	#mxDebugFuncVars($imglist);
	
	$content = "";
	foreach($imglist as $i => $imgtag) {
		$ctrs = (isset($color_trs[$i])) ? $color_trs[$i] : "";
		$csrc = (isset($color_src[$i])) ? '&nbsp;'.$color_src[$i] : "";
		$csrc = (empty($csrc) && !empty($ctrs)) ? "&nbsp;&nbsp;??" : $csrc;
		$content .= "<tr>
		<td width='10%' align='center' nowrap>".$imgtag."&nbsp;</td>
		<td width='40%' nowrap><b>".$csrc."</b>&nbsp;</td>
		<!-- <td>&nbsp;&nbsp;</td> -->
		<td width='50%'><input type='text' name='setcol[".$i."]' value='".$ctrs."' size='40' maxlength='50'></td>
		</tr>";
		}
	
	$GLOBALS["pagetitle"]=_CALCATEGORIESADMIN;
	include("header.php");
	calAdminMenu(_CALCATEGORIESADMIN);
	OpenTable();

	if (isset($statmsg)) {
		OpenTable2();
		echo "<blockquote><font class=\"title\"><b>$statmsg</b></font></blockquote>";
		CloseTable2();
		echo "<br>";
		}

	echo "
	<form action='"._CAL_ADM_SETCOLLINK."&trs_lng=".$_REQUEST['trs_lng']."&src_lng=".$_REQUEST['src_lng']."' method='post'>
	<input type='hidden' name='x_trs_lng' value='".$_REQUEST['trs_lng']."'>
	<input type='hidden' name='op' value='CalSavecols'>
	<table width='90%' border='1' cellspacing='0' cellpadding='2' align='center'>
	<tr><th colspan='3'>"._CALCATEGORIESLANG."</th></tr>
	<tr><td width='50%' align='center' colspan='2'>".calgetlanglist('src')."</td><td width='50%' align='center'>".calgetlanglist('trs')."</td></tr>
	</table><br>
	<table width='90%' border='1' cellspacing='0' cellpadding='2' align='center'>
	<tr>
	<th width='50%' colspan='2'>"._CALSOURCE.":&nbsp;".$_REQUEST['src_lng']."&nbsp;<img src='images/language/flag-".$_REQUEST['src_lng'].".png' alt='' width='30' height='16' border='0'></th>
	<th width='50%' colspan='2'>"._CALGOAL.":&nbsp;".$_REQUEST['trs_lng']."&nbsp;<img src='images/language/flag-".$_REQUEST['trs_lng'].".png' alt='' width='30' height='16' border='0'></th>
	</tr>
	".$content."
	<tr><td colspan='2'>&nbsp;</td><td align='center' colspan='2'><input type='submit' value='Speichern'><br><br></td></tr>
	</table>
	</form>
	";
	CloseTable();
	echo "<br>";
	include("footer.php");
	}

#########################################################################################
function calgetlangsrc($lang) {
	$ok =	@include(CAL_MODULE_PATH."categories/".$lang.".php");
	if ($ok) return $caldotcolor;
	return array();
	}

#########################################################################################
function calgetlanglist($mode) {
	static $linklist;
	if (!isset($linklist)) {
		$handle = @opendir('language');
		if (!$handle) return;
		while ($file = readdir($handle)) {
			if (preg_match("/^lang\-(.+)\.php/", $file, $matches)) {
				$linklist[$matches[1]] = ucwords(str_replace("_"," ", str_replace("german","deutsch", $matches[1])));
				}
			}
		closedir($handle);
		ksort($linklist);
		}
	$content = "";
	$pre = "border=\"0\" hspace=\"3\" vspace=\"3\"";
	foreach($linklist as $langu => $alt) {
		$to = ($mode=='src') ? "src_lng=".$langu."&trs_lng=".$_REQUEST['trs_lng']."" : "trs_lng=".$langu."&src_lng=".$_REQUEST['src_lng']."";
		$content .= "<a href='"._CAL_ADM_SETCOLLINK."&".$to."' title='".$alt."'><img src='images/language/flag-".$langu.".png' alt='".$langu."' width='30' height='16' border='0'></a> ";
		}
	return $content;
	}



#########################################################################################

$_REQUEST['src_lng'] = (isset($_REQUEST['src_lng'])) ? $_REQUEST['src_lng'] : $GLOBALS['currentlang'];
$_REQUEST['trs_lng'] = (isset($_REQUEST['trs_lng'])) ? $_REQUEST['trs_lng'] : $GLOBALS['language'];

$op = (isset($_REQUEST["op"])) ? $_REQUEST["op"] : "CalSetcols";
switch($op) {
	case "CalSavecols":
		CalSavecols($op);
		die();
	case "CalSetcols":
		CalSetcols();
		die();
	default:
		CalSetcols();
		die();
	}


?>