<?PHP

/**************************************
    Webutler V3.0 - www.webutler.de
    Copyright (c) 2008 - 2014
    Autor: Sven Zinke
    Free for any use
    Lizenz: GPL
**************************************/

require_once dirname(dirname(dirname(__FILE__))).'/includes/loader.php';

$webutlermodadmin = new WebutlerAdminClass;
$webutlermodadmin->config = $webutler_config;
$webutlermodadmin->langconf = $webutler_langconf;
$webutlermodadmin->moduleslist = $webutler_moduleslist;

if(isset($_SESSION['newslang']))
	$news_adminlang = $_SESSION['newslang'];
elseif(isset($_SESSION['loggedin']['userlang']))
	$news_adminlang = $_SESSION['loggedin']['userlang'];
else
	$news_adminlang = $webutlermodadmin->config['defaultlang'];

$news_adminlangfile = $webutlermodadmin->config['server_path'].'/modules/news/admin/lang/'.$news_adminlang.'.php';
if(file_exists($news_adminlangfile))
	require_once $news_adminlangfile;

$news_viewlangfile = $webutlermodadmin->config['server_path'].'/modules/news/view/lang/'.$news_adminlang.'.php';
if(file_exists($news_viewlangfile))
	require_once $news_viewlangfile;

if(!isset($news_conf))
	require_once $webutlermodadmin->config['server_path'].'/modules/news/data/config.php';

$news_class = new MMAdminClass;
$news_class->modname = 'news';
$news_class->serverpath = $webutlermodadmin->config['server_path'];
$news_class->homepage = $webutlermodadmin->config['homepage'];
$news_class->chmod = $webutlermodadmin->config['chmod'];
$news_class->langconf = $webutlermodadmin->langconf;
$news_class->fileconfig = $news_conf;

if((!$webutlermodadmin->checkadmin() && (!isset($_SESSION['newslog']) || $_SESSION['newslog'] != 'true')) || isset($_GET['logout'])) {
	require_once $webutlermodadmin->config['server_path'].'/modules/news/admin/login.php';
	exit;
}

if(!isset($_GET['page'])) $_GET['page'] = '';

$news_viewlangfile = $webutlermodadmin->config['server_path'].'/modules/news/view/lang/'.$news_adminlang.'.php';
if(file_exists($news_viewlangfile))
	require_once $news_viewlangfile;

$news_class->pagelang = $news_adminlang;
$news_class->post = $_POST;
$news_class->files = $_FILES;
$news_class->get = $_GET;
$news_class->connectdb();

if((isset($news_class->dbconfig['hideforsubs']) && $news_class->dbconfig['hideforsubs'] != 'hide') || $webutlermodadmin->checkadmin()) {
    if(isset($_POST['saveconf'])) {
        $news_class->saveconfig();
        header("Location: admin.php?page=conf");
    }
    else {
        if($news_class->dbconfig == '' && $_GET['page'] != 'install')
    		header("Location: admin.php?page=install");
        elseif($news_class->dbconfig != '' && $_GET['page'] == 'install')
    		header("Location: admin.php");
    }
}

if(isset($_POST['newslang'])) {
	$_SESSION['newslang'] = preg_replace("/[^a-z]/", "", $_POST['newslang']);
    header("Location: admin.php".(($_SERVER['QUERY_STRING']) ? '?'.$_SERVER['QUERY_STRING'] : ''));
	exit;
}

if(isset($_POST['on'])) $news_class->online();
if(isset($_POST['off'])) $news_class->offline();
if(isset($_POST['delete'])) $news_class->delete();
if(isset($_POST['change'])) $news_class->changeto();
if(isset($_POST['savedata'])) $news_class->savedata();
if(isset($_POST['editdata'])) $news_class->updatedata();
if($_GET['page'] == 'datas' && isset($_GET['data']) && $_GET['data'] != 'new') $db_data = $news_class->getdata();


if($_GET['page'] == '') $_GET['page'] = 'datas';


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><?PHP echo _NEWSLANGADMIN_TITLE_.' '.strtoupper(_NEWSLANGADMIN_MODNAME_); ?></title>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
	<meta http-equiv="content-style-type" content="text/css" />
	<meta http-equiv="content-script-type" content="text/javascript" />
	<meta http-equiv="imagetoolbar" content="no" />
	<meta name="robots" content="noindex,nofollow" />
	<link type="text/css" rel="stylesheet" href="<?PHP echo $webutlermodadmin->config['homepage']; ?>/modules/news/admin/admin.css" />
	<?PHP if(isset($_GET['data'])) { ?>
<script type="text/javascript">
/* <![CDATA[ */
    var homepagepath = '<?PHP echo $webutlermodadmin->config['homepage']; ?>';
/* ]]> */
</script>
<script type="text/javascript" src="<?PHP echo $webutlermodadmin->config['homepage']; ?>/includes/modexts/calendar/datepickercontrol.js"></script>
<script type="text/javascript" src="<?PHP echo $webutlermodadmin->config['homepage']; ?>/includes/modexts/ckeditor/ckeditor.js"></script><?PHP } ?>

	<script language="javascript" type="text/javascript" src="<?PHP echo $webutlermodadmin->config['homepage']; ?>/modules/news/admin/admin.js"></script>
</head>
<body>
<div id="adminpage">
  <?PHP echo $webutlermodadmin->getmodulesheadermenu('news', $news_adminlang); ?>
  <h1 id="adminheadline"><img src="<?PHP echo $webutlermodadmin->config['homepage']; ?>/admin/system/images/webutler_s.gif" align="right" /><?PHP echo _NEWSLANGADMIN_TITLE_.' '.strtoupper(_NEWSLANGADMIN_MODNAME_); ?></h1>
  <?PHP if($_GET['page'] != 'install') { ?>
  <table id="adminmenu" border="0" cellspacing="0" cellpadding="5">
	<tr>
      <?PHP if((isset($news_class->dbconfig['hideforsubs']) && $news_class->dbconfig['hideforsubs'] != 'hide') || $webutlermodadmin->checkadmin()) { ?><td><a href="admin.php?page=conf"><?PHP echo _NEWSLANGADMIN_SETTINGS_; ?></a></td>
<?PHP } ?><td><a href="admin.php?page=datas"><?PHP echo _NEWSLANGADMIN_DATAS_; ?></a></td>
<td><a href="admin.php?logout=1"><?PHP echo _NEWSLANGADMIN_LOGOUT_; ?></a></td>

	</tr>
  </table>
  <?PHP } ?>
  <div id="admincontent">
      
      
      
    <form method="post" name="baseform" action="admin.php<?PHP echo ($_SERVER['QUERY_STRING']) ? '?'.$_SERVER['QUERY_STRING'] : ''; ?>" enctype="multipart/form-data">
      <?PHP if($_GET['page'] == 'conf' || $_GET['page'] == 'install') { ?>
<?PHP $checkchmods = '';
				if($_GET['page'] == 'install') {
					$checkchmoddb = $news_class->checkchmoddb();
					clearstatcache();
					$checkchmodsmedia = $news_class->checkchmods('media');
					clearstatcache();
					$checkchmods = $checkchmoddb.$checkchmodsmedia;
				}
				if($checkchmods != '') { ?>
					<table border="0" cellspacing="0" cellpadding="5">
						<tr class="top"><td><h3><?PHP echo str_replace('###CHMODMODNAME###', $news_class->modname, _NEWSLANGADMIN_SETCHMODFOR_); ?></h3></td></tr>
						<tr><td style="padding: 10px 25px 5px 25px"><strong><?PHP echo _NEWSLANGADMIN_WRONGCHMOD_; ?></strong></td></tr>
						<?PHP echo $checkchmods; ?>
						<tr><td style="padding: 15px 0px 0px 25px"><?PHP echo str_replace(array('###CHMODFOLDER###', '###CHMODFILES###'), array('<strong>'.decoct($news_class->chmod[0]).'</strong>', '<strong>'.decoct($news_class->chmod[1]).'</strong>'), _NEWSLANGADMIN_SETRIGHTCHMODS_); ?></td></tr>
					</table>
				<?PHP } else { ?>
<?PHP if((isset($news_class->dbconfig['hideforsubs']) && $news_class->dbconfig['hideforsubs'] != 'hide') || $webutlermodadmin->checkadmin()) { ?>
<table border="0" cellspacing="0" cellpadding="5">
                <tr class="top">
                  <td colspan="2"><h2><?PHP echo $_GET['page'] == 'install' ? _NEWSLANGADMIN_INSTALL_ : _NEWSLANGADMIN_SETTINGS_; ?></h2></td>
                </tr>
            	<?PHP if($webutlermodadmin->checkadmin()) { ?>
<tr class="even"><td class="start"><?PHP echo _NEWSLANGADMIN_FIELD_LOGINFORSUBS_; ?>:</td>
<td class="end"><strong class="isfor"><?PHP echo _NEWSLANGADMIN_FIELD_USERSASSUBS_; ?></strong>
				<select name="config[subeditors]" size="1">
                <option value="no"<?PHP echo $news_class->setnousersselection(isset($news_class->dbconfig['subeditors']) ? $news_class->dbconfig['subeditors'] : ''); ?>><?PHP echo _NEWSLANGADMIN_FIELD_NOSUBEDITOR_; ?></option>
                <?PHP echo $news_class->getusergroupids(isset($news_class->dbconfig['subeditors']) ? $news_class->dbconfig['subeditors'] : ''); ?>
                </select><br />
				<input type="checkbox" name="config[hideforsubs]" style="width: 15px" id="hideforsubs" value="hide"<?PHP if(isset($news_class->dbconfig['hideforsubs']) && $news_class->dbconfig['hideforsubs'] == 'hide') echo ' checked="checked"'; ?> /><label for="hideforsubs"><?PHP echo _NEWSLANGADMIN_FIELD_HIDEFORSUBS_; ?></label></td>
                        </tr>
<?PHP } ?><tr class="odd"><td class="start"><?PHP echo _NEWSLANGADMIN_FIELD_SETPERPAGE_; ?>:</td>
<td class="end"><table class="setperpage" border="0" cellspacing="0" cellpadding="0"><tr><td style="border-top: 0px"><strong><?PHP echo _NEWSLANGADMIN_DATAS_; ?>:</strong></td><td style="border-top: 0px"><input type="text" name="config[datasperpage]" style="width: 40px" value="<?PHP if(isset($news_class->dbconfig['datasperpage'])) echo $news_class->dbconfig['datasperpage']; ?>" /> <?PHP echo _NEWSLANGADMIN_FIELD_DATAPERPAGE_; ?></td></tr></table></td>
                        </tr>
<tr class="even"><td class="start"><?PHP echo _NEWSLANGADMIN_FIELD_SORTING_; ?>:</td>
<td class="end"><table class="sortconf" border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="2" style="border-top: 0px; padding-bottom: 0px"><strong><?PHP echo _NEWSLANGADMIN_DATAS_; ?>:</strong></td>
                    <td style="border-top: 0px; padding-bottom: 0px"><input type="radio" name="config[datasort]" value="DESC" style="width: 12px" id="sorting_datadesc"<?PHP if(!isset($news_class->dbconfig['datasort']) || $news_class->dbconfig['datasort'] == 'DESC') echo ' checked="checked"'; ?> /><label for="sorting_datadesc"><?PHP echo _NEWSLANGADMIN_FIELD_SORTNEWFIRST_; ?></label></td>
                    <td width="100%" style="border-top: 0px; padding-bottom: 0px"><input type="radio" name="config[datasort]" value="ASC" style="width: 12px" id="sorting_dataasc"<?PHP if(isset($news_class->dbconfig['datasort']) && $news_class->dbconfig['datasort'] == 'ASC') echo ' checked="checked"'; ?> /><label for="sorting_dataasc"><?PHP echo _NEWSLANGADMIN_FIELD_SORTOLDFIRST_; ?></label></td>
                    </tr><tr><td colspan="2" class="sortbyfield"><?PHP echo _NEWSLANGADMIN_FIELD_SORTBYFIELD_; ?>:<select name="config[sortdatafield]" size="1">
                            <?PHP echo $news_class->datafieldsforsort('data'); ?>
                        </select></td></tr></table></td>
                        </tr>
<tr class="odd"><td class="start"><?PHP echo _NEWSLANGADMIN_FIELD_NUMBNEWEST_; ?>:</td>
<td class="end"><input type="text" value="<?PHP echo $news_class->dbconfig['numbnewest']; ?>" style="width: 40px" name="config[numbnewest]" /> <?PHP echo _NEWSLANGADMIN_FIELD_NEWESTINBLOCK_; ?></td>
                        </tr>
<tr class="even"><td class="start"><?PHP echo _NEWSLANGADMIN_HEADLINETITLE_SEO_; ?>:</td>
<td class="end"><input type="checkbox" name="config[headlinetitle]" value="show" style="width: 12px" id="showheadlinetitle"<?PHP if(isset($news_class->dbconfig['headlinetitle']) && $news_class->dbconfig['headlinetitle'] == 'show') echo ' checked="checked"'; ?> /><label for="showheadlinetitle"><?PHP echo _NEWSLANGADMIN_HEADLINETITLE_SHOW_.' ('._NEWSLANGADMIN_HEADLINETITLE_DATA_.')'; ?></label></td>
                        </tr>
<tr class="odd"><td class="start"><?PHP echo _NEWSLANGADMIN_FIELD_BOXCOMMON_; ?>:</td>
<td class="end"><input type="radio" name="config[lightboxlistdata]" value="nodatas" onclick="checkonlyfull()" style="width: 12px" id="nodatas"<?PHP if(!isset($news_class->dbconfig['lightboxlistdata']) || $news_class->dbconfig['lightboxlistdata'] == 'nodatas') echo ' checked="checked"'; ?> /><label for="nodatas"><?PHP echo _NEWSLANGADMIN_FIELD_BOXSINGLE_; ?></label><br />
                <input type="radio" name="config[lightboxlistdata]" value="onedatas" onclick="checkonlyfull()" style="width: 12px" id="onedatas"<?PHP if(isset($news_class->dbconfig['lightboxlistdata']) && $news_class->dbconfig['lightboxlistdata'] == 'onedatas') echo ' checked="checked"'; ?> /><label for="onedatas"><?PHP echo _NEWSLANGADMIN_FIELD_BOXDATASTEP_; ?></label><br />
                <input type="radio" name="config[lightboxlistdata]" value="alldatas" onclick="checkonlyfull()" <?PHP if(isset($news_class->dbconfig['lightboxonlyfull']) && $news_class->dbconfig['lightboxonlyfull'] == 'onlyfull') echo 'disabled="disabled" '; ?>style="width: 12px" id="alldatas"<?PHP if(isset($news_class->dbconfig['lightboxlistdata']) && $news_class->dbconfig['lightboxlistdata'] == 'alldatas') echo ' checked="checked"'; ?> /><label for="alldatas"><?PHP echo _NEWSLANGADMIN_FIELD_BOXFULLSTEP_; ?></label><br /><input type="checkbox" name="config[lightboxonlyfull]" value="onlyfull" onclick="checkonlyfull()" style="width: 12px" id="onlyfull"<?PHP if(isset($news_class->dbconfig['lightboxonlyfull']) && $news_class->dbconfig['lightboxonlyfull'] == 'onlyfull') echo ' checked="checked"'; ?>  <?PHP if(isset($news_class->dbconfig['lightboxlistdata']) && $news_class->dbconfig['lightboxlistdata'] == 'alldatas') echo 'disabled="disabled" '; ?> /><label for="onlyfull"><?PHP echo _NEWSLANGADMIN_FIELD_BOXONLYONFULL_; ?></label></td>
                        </tr>
<tr class="even"><td class="start"><?PHP echo _NEWSLANGADMIN_FIELDTYPE_IMAGEUPLOAD_.'<br />('._NEWSLANGADMIN_INPUT_IMAGE_.')'; ?>:</td>
<td class="end"><input type="checkbox" name="config[lightbox][image]"<?PHP if(isset($news_class->dbconfig['lightbox']['image']) && $news_class->dbconfig['lightbox']['image'] == 'on') echo ' checked="checked"'; ?> style="width: 12px" id="lightbox_image" /><label for="lightbox_image"><?PHP echo _NEWSLANGADMIN_FIELD_BOXOPEN_; ?></label></td>
                        </tr>
<tr class="odd"><td class="start"><?PHP echo _NEWSLANGADMIN_INPUT_HEADLINE_; ?>:</td>
<td class="end"><input type="radio" name="config[title]"<?PHP if((!isset($news_class->dbconfig['title']) || $news_class->dbconfig['title'] == '') || (isset($news_class->dbconfig['title']) && $news_class->dbconfig['title'] == 'headline')) echo ' checked="checked"'; ?> value="headline" style="width: 12px" id="title_headline" /><label for="title_headline"><?PHP echo _NEWSLANGADMIN_FIELD_USEASTITLE_; ?></label></td>
                        </tr>

                <tr class="bottom">
                  <td>&nbsp;</td><td><input type="submit" class="button" name="saveconf" value="<?PHP echo _NEWSLANGADMIN_BUTTON_SAVE_; ?>" /></td>
                </tr>
              </table>
<?PHP } else { echo _NEWSLANGADMIN_NOTAVAILFORSUBS_; } ?>
<?PHP } } ?>

      
      
      
      
      
      
      <?PHP if($_GET['page'] == 'datas' && !isset($_GET['data'])) {
            	echo '<div id="submenu">
					<a href="'.$news_class->getnewdatalink().'">'._NEWSLANGADMIN_NEWDATA_.'</a>
				</div>';
 ?>
<?PHP $getdatalist = $news_class->getdatalist();
            if($getdatalist == '') {
                echo _NEWSLANGADMIN_NOAVAILDATA_;
            } else { ?>
          <table border="0" cellspacing="0" cellpadding="5">
            <tr class="top">
              <td colspan="3"><h2><?PHP echo _NEWSLANGADMIN_DATAS_.$news_class->getdatasheadline(); ?></h2></td>
            </tr>
            <?PHP echo $getdatalist; ?>
          </table>
<?PHP } } ?>

      <?PHP if($_GET['page'] == 'datas' && isset($_GET['data'])) {
 ?>
<?PHP if($_GET['data'] != 'new' && (!isset($db_data) || $db_data == '')) {
                echo _NEWSLANGADMIN_NOEXISTDAT_;
            } else { ?>
<table border="0" cellspacing="0" cellpadding="5">
            <tr class="top">
              <td colspan="2"><h2><?PHP echo ($_GET['data'] == 'new') ? _NEWSLANGADMIN_NEWDATA_ : _NEWSLANGADMIN_EDITDATA_; ?></h2></td>
            </tr>
        	<tr class="odd"><td class="start"><?PHP echo _NEWSLANGADMIN_INPUT_HEADLINE_; ?>:</td>
<td class="end"><input type="text" name="headline" value="<?PHP if(isset($db_data['headline'])) echo $db_data['headline']; ?>" /></td>
                        </tr>
<tr class="even"><td class="start"><?PHP echo _NEWSLANGADMIN_INPUT_DATE_; ?>:</td>
<td class="end"><input type="text" name="date" id="DPC_date" value="<?PHP echo (isset($db_data['date']) && $db_data['date'] != '') ? strftime('%Y-%m-%d', $db_data['date']) : date('Y-m-d'); ?>" size="10" maxlength="10" style="width: 80px" readonly="readonly" /><img src="admin/icons/delete.png" title="<?PHP echo _NEWSLANGADMIN_FIELD_CLEARDATE_; ?>" class="cleardate" onclick="cleardatefield('date')" /></td>
                        </tr>
<tr class="odd"><td class="start"><?PHP echo _NEWSLANGADMIN_INPUT_IMAGE_; ?>:</td>
<td class="end"><div class="fakeupload"><input type="file" class="fileupload" size="53" name="image" onchange="setuploadpath(this)" /><input type="text" class="fakefield" /><input type="text" class="fakebutton" value="<?PHP echo _NEWSLANGADMIN_CHOOSE_UPLOAD_; ?>" /></div><div class="filepreview">
                        <?PHP echo $news_class->getimageof('datas', (isset($db_data['id']) ? $db_data['id'] : ''), 'image'); ?>
                        </div></td>
                        </tr>
<tr class="even"><td class="start"><?PHP echo _NEWSLANGADMIN_INPUT_TEASER_; ?>:</td>
<td class="end"><textarea name="teaser"><?PHP if(isset($db_data['teaser'])) echo $db_data['teaser']; ?></textarea></td>
                        </tr>
<tr class="odd"><td class="start"><?PHP echo _NEWSLANGADMIN_INPUT_TEXT_; ?>:</td>
<td class="end"><div class="editorarea"><textarea name="text"><?PHP if(isset($db_data['text'])) echo $db_data['text']; ?></textarea>
                        <script type="text/javascript">
                        /* <![CDATA[ */
                            CKEDITOR.replace( 'text', {
                                customConfig : 'html_config.js',
                                language : '<?PHP echo $news_adminlang; ?>'
                            });
                        /* ]]> */
                        </script>
                        </div></td>
                        </tr>

			<tr class="bottom">
              <td>&nbsp;</td><td><input type="submit" class="button" name="<?PHP echo ($_GET['data'] == 'new') ? 'savedata' : 'editdata'; ?>" value="<?PHP echo _NEWSLANGADMIN_BUTTON_SAVE_; ?>" /></td>
            </tr>
          </table>
<?PHP } } ?>

    </form>
  </div>
</div>
</body>
</html>
