<?php
header("Expires: Sat, 05 Nov 2005 00:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

require_once "../../maincore.php";
require_once "infusion_db.php";

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

// Load studiobox settings
$sb_setting = @dbarray(dbquery("SELECT `default_sp`,`guests_allowed`,`infotext` FROM `".$sb_db['table_settings']."` WHERE `profile` = 'default' LIMIT 1"));

// convert current timestamp using global offset settings
$timestamp = (time() + (3600*$settings['timeoffset']));
if(IsSet($settings['serveroffset'])) { $timestamp += (3600*$settings['serveroffset']); }

// IMPORTANT: generate dateformat in gmt for db tables (without MESZ changes!)
$requestday = gmmktime(12,0,0,date("m",$timestamp),date("d",$timestamp),date("Y",$timestamp));

// Load scheduler settings
$sp_setting = @dbarray(dbquery("SELECT * FROM `".DB_PREFIX."sendeplan".($sb_setting['default_sp']>0 ? $sb_setting['default_sp'] : '')."_settings` WHERE `profile` = 'default' LIMIT 1"));

// Wer ist aktueller DJ ?
$result = dbquery("SELECT `".date("G",$timestamp)."` FROM `".DB_PREFIX."sendeplan".($sb_setting['default_sp']>0 ? $sb_setting['default_sp'] : '')."` WHERE `day` = ".$requestday);
$rows = dbrows($result);
if ($rows != 0) {
	$entry = dbarray($result);
	if($entry[date("G",$timestamp)]!="") {
		$dj_current_id = explode(".",$entry[date("G",$timestamp)]);
	}
	else { $dj_current_id[0] = 0; }
}
else { $dj_current_id[0] = 0; }

if(!checkgroup($sp_setting['dj_group']) && !checkgroup($sp_setting['dj_admingroup']) && !iSUPERADMIN) die($sb_locale['resctricted_access']);

if (iMEMBER) $result = dbquery("UPDATE `".DB_USERS."` SET `user_lastvisit`='".time()."', `user_ip`='".USER_IP."' WHERE `user_id`='".$userdata['user_id']."'");

//erledigte loeschen
if(IsSet($_POST['deletewish']) && IsSet($_POST['wish_id'])) {
	$delwish_id = trim(stripinput($_POST['wish_id']));
	$result = dbquery("DELETE FROM `".$sb_db['table_posts']."` WHERE `ID`='".$delwish_id."'");
	redirect("studiobox_dj.php");
	exit;
}

$entries = false;
//Liste ausgeben
$result = dbquery("SELECT * FROM `".$sb_db['table_posts']."` ORDER BY `ID` ASC");
	$numrows = dbrows($result);
	while ($data = dbarray($result)) {  
  echo '<hr />
	<h3 align="center">Eingang um '.date("H:i", $data['submit_time']).' Uhr:</h3>
 <table width="100%" border="0" cellspacing="10" cellpadding="0" align="center">
  <tr>
    <td valign="top"><strong>'.$sb_locale['input_username'].':</strong> '.($data['user_id']=='0' ? "&quot;".$data['user_name']."&quot; <small><br />(".$sb_locale['guest_with_ip'].": ".$data['user_ip'].")</small>" : "<a href='".BASEDIR."profile.php?lookup=".$data['user_id']."' title='".$sb_locale['user_profile']."' target='_blank'>".$data['user_name']."</a>").'</td>
  </tr>
 ';
  if($data['wishes']!='') {
	echo '<tr>
    <td valign="top"><strong>'.$sb_locale['input_wish'].':</strong> '.$data['wishes'].'</td>
  </tr>
  ';
  }
  if($data['greetings']!='') {
  	echo '<tr>    
    <td valign="top"><strong>'.$sb_locale['input_greetings'].':</strong> '.wordwrap($data['greetings'],40).'</td>
  </tr>
  ';
  }
  if((checkgroup($sp_setting['dj_group']) && $dj_current_id[0]==$userdata['user_id']) || checkgroup($sp_setting['dj_admingroup']) || iSUPERADMIN) {
  echo '
  <tr>
    <td align="center">
    <form name="wishbox" method="post" action="'.FUSION_SELF.'">
    <input name="wish_id" class="textbox" type="checkbox" id="wish_id" value="'.$data['ID'].'">'.$sb_locale['confirm_delete'].'&nbsp;&nbsp;
    <input name="deletewish" class="button" type="submit" id="deletewish" value="'.$sb_locale['button_delete'].'">
    </form>
    </td>
  </tr>
  ';
$entries = true;	
  }
  echo'
 </table>
';

  }
if(!$entries) { echo "<hr />\n<div align='center'>".$sb_locale['studiobox_no_entries']."</div>\n"; }

?>