<?php
require_once "../../maincore.php";
require_once "infusion_db.php";
require_once $sp_install_folder."sp_functions.php";

// Check if locale file is available matching the current site locale setting.
if (file_exists($sp_install_folder."locale/".$settings['locale'].".php")) {
	// Load the locale file matching the current site locale setting.
	include $sp_install_folder."locale/".$settings['locale'].".php";
} else {
	// Load the infusion's default locale file.
	include $sp_install_folder."locale/English.php";
}

if(!FUSION_V6) { 
	if (!checkrights("SP3".($sp_install_number=='' ? '0' : $sp_install_number)) || !defined("iAUTH") || $_GET['aid'] != iAUTH) { redirect("../../index.php"); }
	require_once THEMES."templates/admin_header.php";
	add_to_title(" &raquo; ".$splocale['linkname']);
	include LOCALE.LOCALESET."admin/infusions.php";	
}
else {
	if (!checkrights("IP")) redirect("../../index.php");
	require_once BASEDIR."subheader.php";
	require_once ADMIN."navigation.php";
}

// save new settings
if(IsSet($_POST['save'])) {
	if(@IsNum($_POST['dj_group']) && (@IsNum($_POST['dj_signin']) || $_POST['dj_signin']=='-1') && (@IsNum($_POST['dj_admingroup']) || $_POST['dj_admingroup']=='-1') && @IsNum($_POST['entry_starttime']) && @IsNum($_POST['entry_endtime']) && @IsNum($_POST['signoff_forbid']) && @IsNum($_POST['autodj_hidden']) && @IsNum($_POST['autodj_showid']) && @IsNum($_POST['setcard_dj']) && @IsNum($_POST['showrepeats_dj']) && @IsNum($_POST['showevents_dj']) && @IsNum($_POST['showbox_width']) && @IsNum($_POST['showbox_height']) && @IsNum($_POST['dj_avatar_maxwidth']) && @IsNum($_POST['dj_avatar_maxheight']) && @IsNum($_POST['use_nsv']) && @IsNum($_POST['use_studiobox']) && @IsNum($_POST['fontsize_showtitle']) && @IsNum($_POST['fontsize_showdescription']) && @IsNum($_POST['view_endtime']) && @IsNum($_POST['default_view'])) {
		$result = dbquery("UPDATE `".$sendeplan_db['table_settings']."` SET
		`dj_group` = '".$_POST['dj_group']."',
		`dj_signin` = '".$_POST['dj_signin']."',
		`dj_admingroup` = '".$_POST['dj_admingroup']."',
		`entry_starttime` = '".$_POST['entry_starttime']."',
		`entry_endtime` = '".$_POST['entry_endtime']."',
		`signoff_forbid` = '".$_POST['signoff_forbid']."',
		`autodj_hidden` = '".$_POST['autodj_hidden']."',
		`autodj_name` = '".stripinput($_POST['autodj_name'])."',
		`setcard_dj` = '".stripinput($_POST['setcard_dj'])."',
		`showrepeats_dj` = '".stripinput($_POST['showrepeats_dj'])."',
		`showevents_dj` = '".stripinput($_POST['showevents_dj'])."',
		`showbox_width` = '".$_POST['showbox_width']."',
		`showbox_height` = '".$_POST['showbox_height']."',
		`dj_avatar_maxwidth` = '".$_POST['dj_avatar_maxwidth']."',
		`dj_avatar_maxheight` = '".$_POST['dj_avatar_maxheight']."',
		`use_nsv` = '".$_POST['use_nsv']."',
		`use_studiobox` = '".$_POST['use_studiobox']."',
		`font_showtitle` = '".stripinput($_POST['font_showtitle'])."',
		`fontsize_showtitle` = '".$_POST['fontsize_showtitle']."',
		`bold_showtitle` = '".stripinput($_POST['bold_showtitle'])."',
		`align_showtitle` = '".stripinput($_POST['align_showtitle'])."',
		`font_showdescription` = '".stripinput($_POST['font_showdescription'])."',
		`bold_showdescription` = '".stripinput($_POST['bold_showdescription'])."',
		`fontsize_showdescription` = '".$_POST['fontsize_showdescription']."',
		`align_showdescription` = '".stripinput($_POST['align_showdescription'])."',
		`view_endtime` = '".$_POST['view_endtime']."',
		`default_view` = '".$_POST['default_view']."',
		`view_changeable` = '".stripinput($_POST['view_changeable'])."'
		WHERE `profile` = 'default' LIMIT 1");
		$result = dbquery("UPDATE `".$sendeplan_db['table_shows']."` SET
		`showid` = '".stripinput($_POST['autodj_showid'])."',
		`title` = '".stripinput($_POST['showtitle'])."',
		`description` = '".stripinput($_POST['showdescription'])."'
		WHERE `user_id` = '0'");
		redirect(FUSION_SELF.$aidlink."&status=success");
		exit;
	}
}

// Form results
opentable($splocale['administration'].($sp_channelname!="" ? " &raquo; ".htmlentities($sp_channelname) : ''));
include $sp_install_folder."admin_headermenu.php";

// Load default settings
$sp_setting = dbarray(dbquery("SELECT * FROM `".$sendeplan_db['table_settings']."` WHERE `profile` = 'default' LIMIT 1"));
// get usergroups
$result = dbquery("SELECT * FROM `".$db_prefix."user_groups` ORDER BY `group_name`");
$rows = dbrows($result);
$group_name = array();
$group_id = array();
	if ($rows != 0) {
	while ($groups = dbarray($result)) {
		$group_name[] = $groups['group_name'];
		$group_id[] = $groups['group_id'];			
	}
}
// get radioshows
$result = dbquery("SELECT * FROM `".$sendeplan_db['table_showdata']."` ORDER BY `title`");
$rows = dbrows($result);
$showtitle = array();
$showid = array();
	if ($rows != 0) {	
	while ($showdata = dbarray($result)) {
		$showtitle[] = $showdata['title'];
		$showid[] = $showdata['ID'];		
	}
}

// fetch showdata for autostream
$result = @dbquery("SELECT * FROM `".$sendeplan_db['table_shows']."` WHERE `user_id` = '0'");
$rows = @dbrows($result);
if ($rows == 0) {
	// create new entry if not exists:
	$result2 = dbquery("INSERT INTO `".$sendeplan_db['table_shows']."` (`user_id`) VALUES ('0')");
}
$showinfo = dbarray($result);
	
$install_failure=""; $error=false;
// some checks:
if(!is_folder_writable("./images/shows/")) { $install_failure = "- Der Ordner &quot;".$sp_install_folder."images/shows&quot; ben&ouml;tigt Schreibrechte (CHMOD 777)<br />\n"; }
if(!is_folder_writable("./images/dj-avatars/")) { $install_failure .= "- Der Ordner &quot;".$sp_install_folder."images/dj-avatars&quot; ben&ouml;tigt Schreibrechte (CHMOD 777)<br />\n"; }
// no show or no usergroups defined?
if(count($group_id)==0) { $install_failure .= "- ".sprintf($splocale['no_groups_found'],ADMIN."user_groups.php".$aidlink)."<br />\n"; }
if(count($showid)==0) { $install_failure .= "- ".sprintf($splocale['no_presets_found'],"sendeplan_showadmin.php$aidlink&amp;step=create_preset")."<br />\n"; }

echo "
<br />
<h3 align='center'>".$splocale['administration']."</h3>
<br />\n";

if($install_failure) {
	$error = true;
	echo "<div class='admin-message' style='text-align: left;'><strong>".$splocale['cant_continue'].":</strong><br />\n".$install_failure."\n</div>";
}
elseif(IsSet($_GET['status']) && $_GET['status']=="success") {
	echo "<div class='admin-message'>".$splocale['presets_successfully_saved']."</div>";
}

?><form method='post' action='<?php echo FUSION_SELF."?aid=".iAUTH;?>'>
<table width='100%' class='tbl-border' cellpadding='0' cellspacing='0' border='0' align='center'>
	<tr>
		<td>
			 <table width='100%' cellspacing='1' cellpadding='5' border='0'>
			 	<tr>
					<td class='tbl1' width='75%'>
						Standard-Ansicht des Sendeplanes</td>
					<td class='tbl1'>
						<select name='default_view' class='textbox' size='1'>						  
							<option value='0'<?php echo ($sp_setting['default_view']==0 ? " selected" : "");?>>Tagesansicht, Auswahl 7 Tage ab heute</option>
                            <option value='1'<?php echo ($sp_setting['default_view']==1 ? " selected" : "");?>>Tagesansicht, Auswahl Montag - Sonntag</option>
                            <option value='2'<?php echo ($sp_setting['default_view']==2 ? " selected" : "");?>>Wochenansicht, Anzeige HEUTE + 7 Tage</option>
                            <option value='3'<?php echo ($sp_setting['default_view']==3 ? " selected" : "");?>>Wochenansicht, Anzeige Montag - Sonntag</option>
						</select><br />
                        <input name="view_changeable" type="checkbox" value="1"<?php echo ($sp_setting['view_changeable']==true ? " checked" : "");?> />Auswahl durch Benutzer zulassen
                     </td>
				</tr>
				<tr>
					<td class='tbl2'>
						Schriftart des Sendungstitels <small>(Standard: Arial,Helvetica,Sans serif)</small></td>
					<td class='tbl2'>
						<input name='font_showtitle' type='text' class='textbox' size='25' maxlength='35' value='<?php echo $sp_setting['font_showtitle'];?>' /> <input name="bold_showtitle" type="checkbox" value="1"<?php echo ($sp_setting['bold_showtitle']==true ? " checked='checked'" : "");?>" /> Fettschrift
                    </td>
				</tr>
                <tr>
					<td class='tbl1' width='75%'>
						Schriftgr&ouml;&szlig;e des Sendungstitels</td>
					<td class='tbl1'>
						<select name='fontsize_showtitle' class='textbox' size='1'>						  
							<?php
							for($i=8; $i<=20; $i++) {
								echo "<option value='".$i."'".($sp_setting['fontsize_showtitle']==$i ? " selected" : "").">".$i."</option>
								";
							}
							?>
						</select> Pixel
                     </td>
				</tr>
				<tr>
					<td class='tbl2'>
						Ausrichtung des Sendungstitels</td>
					<td class='tbl2'>
						<select name='align_showtitle' class='textbox' size='1'>						  
							<option value='left'<?php echo ($sp_setting['align_showtitle']=="left" ? " selected" : "");?>>links</option>
                            <option value='center'<?php echo ($sp_setting['align_showtitle']=="center" ? " selected" : "");?>>zentriert</option>
                            <option value='right'<?php echo ($sp_setting['align_showtitle']=="right" ? " selected" : "");?>>rechts</option>
						</select>
                    </td>
				</tr>
                <tr>
					<td class='tbl1'>
						Schriftart der Sendungs-Beschreibung <small>(Standard: Arial,Helvetica,Sans serif)</small></td>
					<td class='tbl1'>
						<input name='font_showdescription' type='text' class='textbox' size='25' maxlength='35' value='<?php echo $sp_setting['font_showdescription'];?>' /> <input name="bold_showdescription" type="checkbox" value="1"<?php echo ($sp_setting['bold_showdescription']==true ? " checked='checked'" : "");?>" /> Fettschrift
                    </td>
				</tr>
                <tr>
					<td class='tbl2' width='75%'>
						Schriftgr&ouml;&szlig;e der Sendungs-Beschreibung</td>
					<td class='tbl2'>
						<select name='fontsize_showdescription' class='textbox' size='1'>						  
							<?php
							for($i=8; $i<=20; $i++) {
								echo "<option value='".$i."'".($sp_setting['fontsize_showdescription']==$i ? " selected" : "").">".$i."</option>
								";
							}
							?>
						</select> Pixel
                     </td>
				</tr>
				<tr>
					<td class='tbl1'>
						Ausrichtung der Sendungs-Beschreibung</td>
					<td class='tbl1'>
						<select name='align_showdescription' class='textbox' size='1'>						  
							<option value='left'<?php echo ($sp_setting['align_showdescription']=="left" ? " selected" : "");?>>links</option>
                            <option value='center'<?php echo ($sp_setting['align_showdescription']=="center" ? " selected" : "");?>>zentriert</option>
                            <option value='right'<?php echo ($sp_setting['align_showdescription']=="right" ? " selected" : "");?>>rechts</option>
						</select>
                    </td>
				</tr>
                <tr>
					<td class='tbl2' width='75%'>
						<?php echo $splocale['which_usergroup_is_dj']; ?></td>
					<td class='tbl2'>
						<select name='dj_group' class='textbox' size='1'>						  
							<?php
							for($i=0; $i<(count($group_name)); $i++) {
								echo "<option value='".$group_id[$i]."'".($sp_setting['dj_group']==$group_id[$i] ? " selected" : "").">".$group_name[$i]."</option>
								";
							}
							?>
						</select>					</td>
				</tr>
				<tr>
					<td class='tbl1'>
						<?php echo $splocale['which_usergroup_entry_allowed']; ?></td>
					<td class='tbl1'>
						<select name='dj_signin' class='textbox' size='1'>						  
							<option value='-1'>Superadmin</option>
							<?php
							for($i=0; $i<(count($group_name)); $i++) {
								echo "<option value='".$group_id[$i]."'".($sp_setting['dj_signin']==$group_id[$i] ? " selected" : "").">".$group_name[$i]."</option>
								";
							}
							?>
						</select>					</td>
				</tr>
				<tr>
					<td class='tbl2'>
						<?php echo $splocale['which_times_entries_allowed']; ?></td>
					<td class='tbl2'>
						<select name='entry_starttime' class='textbox' size='1'>						  
							<?php
							for($i=0; $i<=23; $i++) {
								echo "<option value='".$i."'".($sp_setting['entry_starttime']==$i ? " selected" : "").">".$splocale['time_from']." ".($i<10 ? "0" : "").$i.":00</option>
								";
							}
							?>
						</select>&nbsp;<select name='entry_endtime' class='textbox' size='1'>						  
							<?php
							for($i=0; $i<=23; $i++) {
								echo "<option value='".$i."'".($sp_setting['entry_endtime']==$i ? " selected" : "").">".$splocale['time_to']." ".($i<10 ? "0" : "").$i.":00</option>
								";
							}
							?>
						</select>					</td>
				</tr>
				<tr>
					<td class='tbl1'>
						<?php echo $splocale['which_group_is_admin']; ?>
                    </td>
					<td class='tbl1'>
						<select name='dj_admingroup' class='textbox' size='1'>						  
							<option value='-1'>nur Superadmin</option>
							<?php
							for($i=0; $i<(count($group_name)); $i++) {
								echo "<option value='".$group_id[$i]."'".($sp_setting['dj_admingroup']==$group_id[$i] ? " selected" : "").">".$group_name[$i]."</option>
								";
							}
							?>
						</select>					</td>
				</tr>
				<tr>
					<td class='tbl2'>
						<?php echo $splocale['block_shorttime_deletes']; ?>
                    </td>
					<td class='tbl2'>
						<select name='signoff_forbid' class='textbox' size='1'>						
						  <option value="0"<?php echo ($sp_setting['signoff_forbid']=='0' ? " selected" : "");?>><?php echo $splocale['not_activated']; ?></option>						  						  
						  <option value="1"<?php echo ($sp_setting['signoff_forbid']=='1' ? " selected" : "");?>>24 <?php echo $splocale['hours']; ?></option>
						  <option value="2"<?php echo ($sp_setting['signoff_forbid']=='2' ? " selected" : "");?>>48 <?php echo $splocale['hours']; ?></option>
						  <option value="3"<?php echo ($sp_setting['signoff_forbid']=='3' ? " selected" : "");?>>72 <?php echo $splocale['hours']; ?></option>
						  <option value="4"<?php echo ($sp_setting['signoff_forbid']=='4' ? " selected" : "");?>>96 <?php echo $splocale['hours']; ?></option>	
						  <option value="9"<?php echo ($sp_setting['signoff_forbid']=='9' ? " selected" : "");?>><?php echo $splocale['always_blocked']; ?></option>					  
						</select></td>
				</tr>
				<tr>
					<td class='tbl1'>
						<?php echo $splocale['fillmethod_for_autodj']; ?>
                    </td>
					<td class='tbl1'>
						<select name='autodj_hidden' class='textbox' size='1'>
						  <option value="0"<?php echo ($sp_setting['autodj_hidden']=='0' ? " selected" : "");?>><?php echo $splocale['fillmethod_24hours']; ?></option>
                          <option value="2"<?php echo ($sp_setting['autodj_hidden']=='2' ? " selected" : "");?>><?php echo $splocale['fillmethod_djtimes']; ?></option>
						  <option value="1"<?php echo ($sp_setting['autodj_hidden']=='1' ? " selected" : "");?>><?php echo $splocale['no']; ?></option>
						</select>					</td>
				</tr>
				<tr>
					<td class='tbl2'>
						<?php echo $splocale['autodj_name']; ?>
                    </td>
					<td class='tbl2'>
						<input name='autodj_name' type='text' class='textbox' size='25' maxlength="25" value='<?php echo $sp_setting['autodj_name'];?>' />					</td>
				</tr>
				<tr>
					<td class='tbl1'>
						<?php echo $splocale['which_showpreset_for_autodj']; ?>
                    </td>
					<td class='tbl1'>
						<select name='autodj_showid' class='textbox' size='1'>						  
							<?php
							for($i=0; $i<(count($showid)); $i++) {
								echo "<option value='".$showid[$i]."'".($showinfo['showid']==$showid[$i] ? " selected" : "").">".trimlink(html_entity_decode($showtitle[$i]),35)."</option>
								";
							}
							
							?>
						</select>					</td>
				</tr>
				<tr>
					<td class='tbl2'>
						<?php echo $splocale['which_showtitle_for_autodj']; ?>
                    </td>
					<td class='tbl2'>
						<input name='showtitle' type='text' class='textbox' size='25' maxlength='25' value='<?php echo $showinfo['title'];?>' />					</td>
				</tr>
				<tr>
					<td class='tbl1'>
						<?php echo $splocale['which_showdescription_for_autodj']; ?>
                    </td>
					<td class='tbl1'>
						<textarea name='showdescription' class='textbox' style='width: 260px; height: 28px; overflow: hidden;'><?php echo $showinfo['description'];?></textarea>
					</td>
				</tr>
				<tr>
					<td class='tbl2'>
						Endzeiten der Sendungen anzeigen?<br /><small>(Ausblenden empfiehlt sich nur bei 24h-Betrieb und wenn unbelegte Zeiten mit Autostream angezeigt werden. Andernfalls ist das Ende der Sendung unbekannt, wenn im Anschluss keine Sendung eingetragen oder Sendeschluss ist.)</small></td>
					<td class='tbl2'>
						<input name='view_endtime' class='textbox' value='1' type='radio'<?php echo ($sp_setting['view_endtime']=='1' ? " checked" : "");?>><?php echo $splocale['yes']; ?>&nbsp;&nbsp;&nbsp;&nbsp;<input name='view_endtime' class='textbox' value='0' type='radio'<?php echo ($sp_setting['view_endtime']=='0' ? " checked" : "");?>><?php echo $splocale['no']; ?>
                    </td>
				</tr>
                <tr>
				  <td class='tbl1'><?php echo $splocale['setcard_editable_for_dj']; ?> </td>
				  <td class='tbl1'>
				  	<input name='setcard_dj' class='textbox' value='1' type='radio'<?php echo ($sp_setting['setcard_dj']=='1' ? " checked" : "");?>><?php echo $splocale['yes']; ?>&nbsp;&nbsp;&nbsp;&nbsp;<input name='setcard_dj' class='textbox' value='0' type='radio'<?php echo ($sp_setting['setcard_dj']=='0' ? " checked" : "");?>><?php echo $splocale['no']; ?>
                  </td>
			   </tr>
				<tr>
				  <td class='tbl2'><?php echo $splocale['weekly_entries_for_dj']; ?> </td>
				  <td class='tbl2'>
				  	<input name='showrepeats_dj' class='textbox' value='1' type='radio'<?php echo ($sp_setting['showrepeats_dj']=='1' ? " checked" : "");?>><?php echo $splocale['yes']; ?>&nbsp;&nbsp;&nbsp;&nbsp;<input name='showrepeats_dj' class='textbox' value='0' type='radio'<?php echo ($sp_setting['showrepeats_dj']=='0' ? " checked" : "");?>><?php echo $splocale['no']; ?>
                  </td>
			   </tr>
				<tr>
				  <td class='tbl1'><?php echo $splocale['event_entries_for_dj']; ?> </td>
				  <td class='tbl1'>
				  	<input name='showevents_dj' class='textbox' value='1' type='radio'<?php echo ($sp_setting['showevents_dj']=='1' ? " checked" : "");?>><?php echo $splocale['yes']; ?>&nbsp;&nbsp;&nbsp;&nbsp;<input name='showevents_dj' class='textbox' value='0' type='radio'<?php echo ($sp_setting['showevents_dj']=='0' ? " checked" : "");?>><?php echo $splocale['no']; ?>
   				  </td>
			   </tr>
               <tr>
				  <td class='tbl2'>NSV-Feature aktivieren?<br /><small>(Falls aktiv kann angegeben werden, ob die jeweilige Sendung per Video/NSV &uuml;bertragen wird.)</small></td>
				  <td class='tbl2'>
                    <input name='use_nsv' class='textbox' value='1' type='radio'<?php echo ($sp_setting['use_nsv']=='1' ? " checked" : "");?>><?php echo $splocale['yes']; ?>&nbsp;&nbsp;&nbsp;&nbsp;<input name='use_nsv' class='textbox' value='0' type='radio'<?php echo ($sp_setting['use_nsv']=='0' ? " checked" : "");?>><?php echo $splocale['no']; ?>
                    </td>
			   </tr>
               <tr>
				  <td class='tbl1'>Wird das Sendeplan-Addon &quot;Studiobox&quot; verwendet?<br /><small>(Falls ja kann der DJ w&auml;hlen, ob er in seiner Sendung Gr&uuml;&szlig;e, Musikw&uuml;nsche oder keines von beiden zul&auml;sst.)</small></td>
				  <td class='tbl1'>
                    <input name='use_studiobox' class='textbox' value='1' type='radio'<?php echo ($sp_setting['use_studiobox']=='1' ? " checked" : "");?>><?php echo $splocale['yes']; ?>&nbsp;&nbsp;&nbsp;&nbsp;<input name='use_studiobox' class='textbox' value='0' type='radio'<?php echo ($sp_setting['use_studiobox']=='0' ? " checked" : "");?>><?php echo $splocale['no']; ?></td>
			   </tr>
				<tr>
				  <td class='tbl2'><?php echo $splocale['width_of_showbox']; ?> </td>
				  <td class='tbl2'><input name='showbox_width' type='text' class='textbox' size='5' maxlength='4' value='<?php echo $sp_setting['showbox_width'];?>' /><?php echo $splocale['pixels']; ?></td>
			   </tr>
				<tr>
				  <td class='tbl1'><?php echo $splocale['height_of_showbox']; ?> </td>
				  <td class='tbl1'><input name='showbox_height' type='text' class='textbox' size='5' maxlength='4' value='<?php echo $sp_setting['showbox_height'];?>' /><?php echo $splocale['pixels']; ?></td>
			   </tr>
               <tr>
				  <td class='tbl2'>Max. Breite der DJ-Avatare</td>
				  <td class='tbl2'><input name='dj_avatar_maxwidth' type='text' class='textbox' size='5' maxlength='4' value='<?php echo $sp_setting['dj_avatar_maxwidth'];?>' /><?php echo $splocale['pixels']; ?></td>
			   </tr>
               <tr>
				  <td class='tbl1'>Max. H&ouml;he der DJ-Avatare</td>
				  <td class='tbl1'><input name='dj_avatar_maxheight' type='text' class='textbox' size='5' maxlength='4' value='<?php echo $sp_setting['dj_avatar_maxheight'];?>' /><?php echo $splocale['pixels']; ?></td>
			   </tr>
               
			</table>			
		</td>
	</tr>
</table>
<?php if(!$error) { ?><br />
<p align="center"><input name='save' type='submit' class='button' value='<?php echo $splocale['save_settings']; ?>' /></p>
<?php } ?>
</form>

<?php

closetable();

if(!FUSION_V6) { require_once THEMES."templates/footer.php"; }
else {
	//require_once BASEDIR."side_right.php";
	require_once BASEDIR."footer.php";
}
?>
