<?php
/* --------------------------------------------------------------
   ausgezeichnet_org.php 2018-09-26
   enyNET
   https://www.enynet.de
   Copyright (c) 2018 enyNET
   --------------------------------------------------------------*/

require('includes/application_top.php');

define('FILENAME_AUSGEZEICHNET_ORG',"ausgezeichnet_org.php");


/**
 * @var AORGOrderController $orderController
 */

$orderController = MainFactory::create_object('AORGOrderController');
$tableController = $orderController->getTableController();
/**
 * @var AORGMailer $mailer
 */
$mailer = MainFactory::create_object('AORGMailer');


$t_page_token = $_SESSION['coo_page_token']->generate_token();
$languages                = xtc_get_languages();

if($_POST['go_save']){
	$tableController->set_config('AORG_LINK',$_POST['AORG_LINK']);
	$tableController->set_config('AORG_CUSTOMER_NUMBER',$_POST['AORG_CUSTOMER_NUMBER']);
	$tableController->set_config('AORG_CUSTOMER_SALT',$_POST['AORG_CUSTOMER_SALT']);
	$tableController->set_config('AORG_SEND_WITH_ORDER',$_POST['AORG_SEND_WITH_ORDER']);
	$tableController->set_config('AORG_SEND_IN_ORDERMAIL',$_POST['AORG_SEND_IN_ORDERMAIL']);
	$tableController->set_config('AORG_SEND_MAIL_AFTER_X_DAYS',$_POST['AORG_SEND_MAIL_AFTER_X_DAYS']);
	$tableController->set_config('AORG_AUTO_SEND_START_AFTER_ORDER',$_POST['AORG_AUTO_SEND_START_AFTER_ORDER']);
	$tableController->set_config('AORG_MAIL_ABSENDER',$_POST['AORG_MAIL_ABSENDER']);
	$tableController->set_config('AORG_MAIL_BETREFF',$_POST['AORG_MAIL_BETREFF']);
    $tableController->set_config('AORG_SIEGEL',$_POST['AORG_SIEGEL']);
    $tableController->set_config('AORG_REVIEW_COLLECTOR',$_POST['AORG_REVIEW_COLLECTOR']);
    $tableController->set_config('AORG_SIEGEL_ACTIV',$_POST['AORG_SIEGEL_ACTIV']);
    $tableController->set_config('AORG_REVIEW_COLLECTOR_ACTIV',$_POST['AORG_REVIEW_COLLECTOR_ACTIV']);

	$tableController->loadConfiguration();
}
if($_POST['manual_cron_start']){
	$fp = fopen(HTTP_SERVER."/AORGCron.php?action=start_auto_mailer&return_info=1&language=".$_SESSION['language_code'], 'r');
	while ($buffer = fread($fp, 1024))
		$return_message .= $buffer;
	fclose($fp);
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html <?php echo HTML_PARAMS; ?>>
<head>
    <meta http-equiv="x-ua-compatible" content="IE=edge">
    <meta http-equiv="Content-Type" content="text/html; charset=<?php echo $_SESSION['language_charset']; ?>">
    <title><?php echo TITLE; ?></title>
    <link rel="stylesheet" type="text/css" href="html/assets/styles/legacy/stylesheet.css">
    <link rel="stylesheet" type="text/css" href="html/assets/styles/legacy/tooltip_plugin.css">
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF" >
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<script type="text/javascript" src="html/assets/javascript/legacy/gm/tooltip_plugin.js"></script>
<!-- header_eof //-->
<!-- body //-->
<table border="0" width="100%" cellspacing="2" cellpadding="2" class="miscellaneous">
    <tr>
        <td class="columnLeft2" width="<?php echo BOX_WIDTH; ?>" valign="top">
            <table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="1" cellpadding="1" class="columnLeft">
                <!-- left_navigation //-->
                <?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
                <!-- left_navigation_eof //-->
            </table>
        </td>
        <!-- body_text //-->
        <td class="boxCenter" width="100%" valign="top">

            <div class="pageHeading" style="background-image:url(images/gm_icons/gambio.png)"><?php echo HEADING_TITLE; ?></div>
            <br />

            <span class="main">
		<table style="margin-bottom:5px" border="0" cellpadding="0" cellspacing="0" width="100%">
		 <tr class="dataTableHeadingRow">
		 	<td class="dataTableHeadingContentText" style="width:1%; padding-right:20px; white-space: nowrap">
			    <?php
                echo '<a href="ausgezeichnet_org.php?content=configuration">' . HEADING_TITLE_CONFIGURATION . '</a>';
                ?>
		    </td>

		 </tr>
		</table>

		<table border="0" cellpadding="0" cellspacing="0" width="100%" class="breakpoint-small multi-table-wrapper">
			<tr class="gx-container">
				<td style="font-size: 12px; text-align: justify">

					<?php if(empty($_GET['content']) || $_GET['content'] === 'configuration'){ ?>

                        <form name="gm_miscellaneous" action="<?php echo FILENAME_AUSGEZEICHNET_ORG; ?>" method="post">
                        <table class="gx-configuration">
	                        <tr style="display: none">
		                        <td class="dataTableContent_gm configuration-label">
			                        &nbsp;
		                        </td>
		                        <td class="dataTableContent_gm">
			                        &nbsp;
		                        </td>
	                        </tr>
							<tr>
								<td class="dataTableContent_gm configuration-label">
									<?php echo HEADING_AORG_LINK; ?>
								</td>
								<td class="dataTableContent_gm">
									<input class="pull-left" style="width: 400px" type="text" name="AORG_LINK" value="<?php echo $tableController->get_config('AORG_LINK'); ?>" />
								</td>
							</tr>
							<tr>
								<td class="dataTableContent_gm configuration-label">
									<?php echo HEADING_AORG_CUSTOMER_NUMBER; ?>
								</td>
								<td class="dataTableContent_gm">
									<input class="pull-left" type="text" name="AORG_CUSTOMER_NUMBER" value="<?php echo $tableController->get_config('AORG_CUSTOMER_NUMBER'); ?>" />
								</td>
							</tr>
							<tr>
								<td class="dataTableContent_gm configuration-label">
									<?php echo HEADING_CUSTOMER_SALT; ?>
								</td>
								<td class="dataTableContent_gm">
									<input class="pull-left" style="width: 400px" type="text" name="AORG_CUSTOMER_SALT" value="<?php echo $tableController->get_config('AORG_CUSTOMER_SALT'); ?>" />
								</td>
							</tr>
							<tr>
								<td class="dataTableContent_gm configuration-label">
									<?php echo HEADING_SEND_IN_ORDERMAIL; ?>
								</td>
								<td class="dataTableContent_gm">
									<div class="gx-container" data-gx-widget="checkbox">
										<input class="pull-left" type="checkbox" name="AORG_SEND_IN_ORDERMAIL" value="1"<?php echo ($tableController->get_config('AORG_SEND_IN_ORDERMAIL') == '1' ? ' checked="checked"' : ''); ?> />
									</div>
								</td>
							</tr>
							<tr>
								<td class="dataTableContent_gm configuration-label">
									<?php echo HEADING_SEND_WITH_ORDER; ?>
								</td>
								<td class="dataTableContent_gm">
									<div class="gx-container" data-gx-widget="checkbox">
										<input class="pull-left" type="checkbox" name="AORG_SEND_WITH_ORDER" value="1"<?php echo ($tableController->get_config('AORG_SEND_WITH_ORDER') == '1' ? ' checked="checked"' : ''); ?> />
									</div>
								</td>
							</tr>
                            <tr>
								<td class="dataTableContent_gm configuration-label">
									<?php echo HEADING_SEND_MAIL_AFTER_X_DAYS; ?>
								</td>
								<td class="dataTableContent_gm">
									<input class="pull-left" type="text" name="AORG_SEND_MAIL_AFTER_X_DAYS" value="<?php echo $tableController->get_config('AORG_SEND_MAIL_AFTER_X_DAYS'); ?>" />
								</td>
							</tr>
							<tr>
								<td class="dataTableContent_gm configuration-label">
									<?php echo HEADING_AUTO_SEND_START_AFTER_ORDER; ?>
								</td>
								<td class="dataTableContent_gm">
									<div class="gx-container" data-gx-widget="checkbox">
										<input class="pull-left" type="checkbox" name="AORG_AUTO_SEND_START_AFTER_ORDER" value="1"<?php echo ($tableController->get_config('AORG_AUTO_SEND_START_AFTER_ORDER') == '1' ? ' checked="checked"' : ''); ?> />
									</div>
								</td>
							</tr>
							<tr>
								<td class="dataTableContent_gm configuration-label">
									<?php echo HEADING_AORG_MAIL_ABSENDER; ?>
								</td>
								<td class="dataTableContent_gm">
									<input class="pull-left" style="width: 400px" type="text" name="AORG_MAIL_ABSENDER" value="<?php echo $tableController->get_config('AORG_MAIL_ABSENDER'); ?>" />
								</td>
							</tr>
							<tr>
								<td class="dataTableContent_gm configuration-label">
									<?php echo HEADING_AORG_MAIL_BETREFF; ?>
								</td>
								<td class="dataTableContent_gm">
									<input class="pull-left" style="width: 400px" type="text" name="AORG_MAIL_BETREFF" value="<?php echo $tableController->get_config('AORG_MAIL_BETREFF'); ?>" />
								</td>
							</tr>
                            <tr>
								<td class="dataTableContent_gm configuration-label">
									<?php echo HEADING_SIEGEL_ACTIV; ?>
								</td>
								<td class="dataTableContent_gm">
									<div class="gx-container" data-gx-widget="checkbox">
										<input class="pull-left" type="checkbox" name="AORG_SIEGEL_ACTIV" value="1"<?php echo ($tableController->get_config('AORG_SIEGEL_ACTIV') == '1' ? ' checked="checked"' : ''); ?> />
									</div>
								</td>
							</tr>
                            <tr>
								<td class="dataTableContent_gm configuration-label">
									<?php echo HEADING_SIEGEL; ?>
								</td>
								<td class="dataTableContent_gm">
									<textarea class="form-control" style="width: 400px" rows="3" name="AORG_SIEGEL"><?php echo $tableController->get_config('AORG_SIEGEL'); ?></textarea>
								</td>
							</tr>
                             <tr>
								<td class="dataTableContent_gm configuration-label">
									<?php echo HEADING_REVIEW_COLLECTOR_ACTIV; ?>
								</td>
								<td class="dataTableContent_gm">
									<div class="gx-container" data-gx-widget="checkbox">
										<input class="pull-left" type="checkbox" name="AORG_REVIEW_COLLECTOR_ACTIV" value="1"<?php echo ($tableController->get_config('AORG_REVIEW_COLLECTOR_ACTIV') == '1' ? ' checked="checked"' : ''); ?> />
									</div>
								</td>
							</tr>
                            <tr>
								<td class="dataTableContent_gm configuration-label">
									<?php echo HEADING_REVIEW_COLLECTOR; ?>
								</td>
								<td class="dataTableContent_gm">
									<textarea class="form-control" style="width: 400px" rows="3" name="AORG_REVIEW_COLLECTOR"><?php echo $tableController->get_config('AORG_REVIEW_COLLECTOR'); ?></textarea>
								</td>
							</tr>

                            <tr>
								<td class="dataTableContent_gm configuration-label">
									<?php echo HEADING_MANUAL_START_CRON; ?>
								</td>
								<td class="dataTableContent_gm">
                                    <input class="btn" name="manual_cron_start" value="Ausführen<?php echo ($return_message != ""?" (".$return_message.")":""); ?>" type="submit" style="margin-left: 0px">
					                <span class="tooltip-icon" style="visibility: hidden;"><span class="gx-container tooltip-icon info" data-hasqtip="3" style="visibility: hidden;"><i class="fa fa-info-circle"></i></span></span>
								</td>
							</tr>
                            <!--<tr>
								<td class="dataTableContent_gm configuration-label">
									<?php echo PRODUCT_REVIEW_NAME; ?>
								</td>
								<td class="dataTableContent_gm">
                                    <div class="gx-container" data-gx-widget="checkbox">
	                                    <select name="PRODUCT_REVIEW_NAME">
		                                    <option value="short_nothing" <?php echo (gm_get_conf('PRODUCT_REVIEW_NAME') === 'short_nothing' ? 'selected>' : '>') . PRODUCT_REVIEW_NAME_OPTION_SHORT_NOTHING; ?></option>
                                            <option value="short_firstname" <?php echo (gm_get_conf('PRODUCT_REVIEW_NAME') === 'short_firstname' ? 'selected>' : '>') . PRODUCT_REVIEW_NAME_OPTION_SHORT_FIRSTNAME; ?></option>
                                            <option value="short_lastname" <?php echo (gm_get_conf('PRODUCT_REVIEW_NAME') === 'short_lastname' ? 'selected>' : '>') . PRODUCT_REVIEW_NAME_OPTION_SHORT_LASTNAME; ?></option>
	                                    </select>
                                    </div>
								</td>
							</tr>-->
						</table>
						<div class="grid bottom-save-bar-content">
							<?php echo xtc_draw_hidden_field('page_token', $t_page_token); ?>
                            <input type="submit" class="button btn btn-primary pull-right" name="go_save" value="<?php echo BUTTON_SAVE;?>" />
						</div>
					</form>

                    <?php } elseif($_GET['content'] == 'stock'){ ?>
                        <form action="<?php echo xtc_href_link('gm_miscellaneous.php', 'content='.$_GET['content']); ?>" method="post">
						<table class="gx-configuration">
							<tr style="display: none">
								<td class="dataTableContent_gm configuration-label">
									&nbsp;
								</td>
								<td class="dataTableContent_gm">
									&nbsp;
								</td>
								<td class="dataTableContent_gm">
									&nbsp;
								</td>
							</tr>
							<tr>
								<td class="dataTableContent_gm configuration-label">
									<?php echo GM_CAT_STOCK; ?>
								</td>
								<td class="dataTableContent_gm">
									<div class="gx-container" data-gx-widget="checkbox">
										<input type="checkbox" name="show_cat_stock" value="1" data-single_checkbox />
									</div>
								</td>
								<td class="dataTableContent_gm">
									<?php echo xtc_draw_hidden_field('page_token', $t_page_token); ?>
                                    <input type="submit" class="button btn btn-primary pull-right" name="go_cat_stock" value="<?php echo BUTTON_EXECUTE;?>" />
								</td>
							</tr>
						</table>
					</form>

                        <form action="<?php echo xtc_href_link('gm_miscellaneous.php', 'content='.$_GET['content']); ?>" method="post">
						<table class="gx-configuration">
							<tr>
								<td class="dataTableContent_gm configuration-label">
									<?php echo GM_PRODUCT_STOCK; ?>
								</td>
								<td class="dataTableContent_gm">
									<div class="gx-container" data-gx-widget="checkbox">
										<input type="checkbox" name="show_product_stock" value="1" data-single_checkbox />
									</div>
								</td>
								<td class="dataTableContent_gm">
									<?php echo xtc_draw_hidden_field('page_token', $t_page_token); ?>
                                    <input type="submit" class="button btn btn-primary pull-right" name="go_product_stock" value="<?php echo BUTTON_EXECUTE;?>" />
								</td>
							</tr>
						</table>
					</form>

                    <?php } elseif($_GET['content'] === 'delete_images' || $_GET['content'] === 'delete_unused_images'){ ?>

                        <form action="<?php echo xtc_href_link('gm_miscellaneous.php', 'content='.$_GET['content']); ?>" method="post">
						<table class="gx-configuration">
							<tr style="display: none">
								<td class="dataTableContent_gm configuration-label">
									&nbsp;
								</td>
								<td class="dataTableContent_gm">
									&nbsp;
								</td>
								<td class="dataTableContent_gm">
									&nbsp;
								</td>
							</tr>
							<tr>
								<td class="dataTableContent_gm configuration-label">
									<?php echo GM_DELETE_IMAGES; ?>
								</td>
								<td class="dataTableContent_gm">
									<div class="gx-container" data-gx-widget="checkbox">
										<input type="checkbox" name="delete_images" value="1" data-single_checkbox />
									</div>
								</td>
								<td class="dataTableContent_gm">
									<?php echo xtc_draw_hidden_field('page_token', $t_page_token); ?>
                                    <input style="margin-left:1px" type="submit" class="button btn btn-primary pull-right" name="go_images" value="<?php echo BUTTON_DELETE;?>" />
								</td>
							</tr>
						</table>
					</form>

                        <br />
                        <form action="<?php echo xtc_href_link('gm_miscellaneous.php', 'content=delete_unused_images'); ?>" method="post">
						<table class="gx-configuration">
							<tr style="display: none">
								<td class="dataTableContent_gm configuration-label">
									&nbsp;
								</td>
								<td class="dataTableContent_gm">
									&nbsp;
								</td>
								<td class="dataTableContent_gm">
									&nbsp;
								</td>
							</tr>
							<tr>
								<td class="dataTableContent_gm configuration-label">
									<?php echo GM_DELETE_UNUSED_IMAGES; ?>
								</td>
								<td class="dataTableContent_gm">
									<div class="gx-container" data-gx-widget="checkbox">
										<input type="checkbox" name="delete_unused_images" value="1" data-single_checkbox />
									</div>
								</td>
								<td class="dataTableContent_gm">
									<?php echo xtc_draw_hidden_field('page_token', $t_page_token); ?>
                                    <input style="margin-left:1px" type="submit" class="button btn btn-primary pull-right" name="go_images2" value="<?php echo BUTTON_DELETE;?>" />
								</td>
							</tr>
						</table>
					</form>


                    <?php } elseif($_GET['content'] == 'delete_stats'){ ?>

                    <?php } ?>

				</td>
			</tr>
		</table>

	</span>

        </td>
        <!-- body_text_eof //-->
    </tr>
</table>
<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
<br />
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>
