<?php

	/**
	 * Template für die Integration des Lieferscheins in die Bestellverwaltung
	 */

?>
<div class="postbox" id="wpsg_deliverynote">		
	<h3 class="wpsg_handlediv">
		<span title="<?php echo __('Zum Ein/Ausklappen hier klicken', 'wpsg'); ?>" class="handlediv"><br /></span>
		<span><?php echo __('Lieferschein', 'wpsg'); ?></span>
	</h3>
	<div class="inside">
	
		<?php if (!wpsg_isSizedArray($this->view['wpsg_mod_deliverynote']['arDeliverynotes'])) { ?>
		<p><?php echo __('Bisher wurden zu dieser Bestellung keine Lieferscheine erstellt.', 'wpsg'); ?></p>
		<?php } else { ?>
				
			<?php foreach ($this->view['wpsg_mod_deliverynote']['arDeliverynotes'] as $k => $v) { ?>
				<?php echo wpsg_translate(__('##1# Lieferschein geschrieben am #2# (Lieferdatum: #3#)', 'wpsg'),
					$v->lnr,
					wpsg_formatTimestamp(strtotime($v->cdate), true),
					wpsg_formatTimestamp($v->getDeliveryTimestamp(), true)						
				); ?> <a target="_blank" href="<?php echo WPSG_URL_WP; ?>wp-admin/admin.php?page=wpsg-Order&action=ajax&noheader=1&mod=wpsg_mod_deliverynote&do=get&edit_id=<?php echo $this->view['data']['id']; ?>&dn_id=<?php echo $v->id; ?>"><?php echo __('Ansehen', 'wpsg'); ?></a><br />
			<?php } ?><br />
				
		<?php } ?>
		
		<?php if (wpsg_isSizedArray($this->view['wpsg_mod_deliverynote']['arNoDeliveredProducts'])) { ?>
			<fieldset style="border:1px solid #999999; width:100%;">			
				<legend style="margin-left:10px; margin-right:10px;"><?php echo __('Neuer Lieferschein', 'wpsg'); ?></legend>
				
				<form target="_blank" method="post" action="<?php echo WPSG_URL_WP; ?>wp-admin/admin.php?page=wpsg-Order&action=ajax&mod=wpsg_mod_deliverynote&cmd=deliverynote&noheader=1&edit_id=<?php echo $this->view['data']['id']; ?>">
				
					<div style="padding:5px;">
						
						<label style="height:25px; width:240px; float:left; margin-top:10px;">	
							<input onchange="if (this.checked) jQuery('#wpsg_mod_deliverynote_email').show(); else jQuery('#wpsg_mod_deliverynote_email').hide();" type="checkbox" checked="checked" value="1" name="wpsg_mod_deliverynote_showmail" />
							&nbsp;<?php echo __("E-Mail an Kunden senden.", "wpsg"); ?>
						</label>
						<input type="text" style="display:block; width:300px; float:right;" id="wpsg_mod_deliverynote_email" name="wpsg_mod_deliverynote_email" value="<?php echo wpsg_hspc($this->view['data']['email']); ?>" />
						<div style="clear:both; width:100%; height:5px;"></div>
						 
						<label style="height:25px; width:220px; float:left;">									
							<input checked="checked" onchange="if (this.checked) jQuery('#wpsg_mod_deliverynote_status').show(); else jQuery('#wpsg_mod_deliverynote_status').hide();" type="checkbox" value="1" name="wpsg_mod_deliverynote_setstatus" />
							&nbsp;<?php echo __("Neuer Status:", "wpsg"); ?>										
						</label>
						<select style="width:300px; float:right;" id="wpsg_mod_deliverynote_status" name="wpsg_mod_deliverynote_status">
							<?php foreach ($this->arStatus as $k => $v) { ?>
							<option value="<?php echo $k; ?>" <?php echo (($k == 250)?'selected="selected"':''); ?>><?php echo $v; ?></option>
							<?php } ?>
						</select>
						<div style="clear:both; width:100%; height:5px;"></div>				
		
						<label style="height:25px; width:240px; float:left;">
							<input <?php echo (($this->get_option("wpsg_mod_deliverynote_url_standard") === "1")?'checked="checked"':''); ?> type="checkbox" value="1" name="wpsg_mod_deliverynote_noticeurl" />
							&nbsp;<?php echo __("URL Benachrichtigung", "wpsg"); ?>
						</label>
						<div style="clear:both; width:100%; height:5px;"></div>
									
						<label style="height:25px; width:240px; float:left; padding-left:22px;">
							<?php echo __("Lieferdatum", "wpsg"); ?>:											
						</label>
						<input style="display:block;float:right; width:300px;" type="text" name="wpsg_mod_deliverynote_date" value="<?php echo date("d.m.Y", time()); ?>" />
						<div style="clear:both; width:100%; height:5px;"></div>
																		
						<label for="wpsg_mod_deliverynote_foottext" style="height:25px; width:220px; padding-left:22px; float:left">
							<?php echo __("Fußtext", "wpsg"); ?>
						</label>
						
						<?php 
													
							$wpsg_mod_deliverynote_footer = $this->get_option("wpsg_mod_deliverynote_footer");
		 					if (!is_array($wpsg_mod_deliverynote_footer)) $wpsg_mod_deliverynote_footer = unserialize($this->get_option("wpsg_mod_deliverynote_footer"));
							if (!is_array($wpsg_mod_deliverynote_footer)) $wpsg_mod_deliverynote_footer = Array();
		
						?>
												
						<?php if (sizeof($wpsg_mod_deliverynote_footer) > 0) { ?>				
						<select style="width:300px; float:right;" name="wpsg_mod_deliverynote_select" id="wpsg_mod_deliverynote_select" onchange="jQuery('#wpsg_mod_deliverynote_fusstext').val(this.value);">
							<?php foreach ($wpsg_mod_deliverynote_footer as $k => $v) { ?>
							<option <?php echo (($this->get_option('wpsg_mod_deliverynote_foottext_standard') == $k)?'selected="selected"':''); ?> value="<?php echo wpsg_hspc($v[1]); ?>"><?php echo wpsg_hspc($v[0]); ?></option>
							<?php } ?>
						</select>
						<?php } ?>
		
						<div style="clear:both; width:100%; height:5px;"></div>															
						<div style="padding-left:25px;"><input style="width:100%;" type="text" name="wpsg_mod_deliverynote_fusstext" id="wpsg_mod_deliverynote_fusstext" value="" /></div>								
						<div style="clear:both; width:100%; height:15px;"></div>
										
						<script type="text/javascript">/* <![CDATA[ */
		
							jQuery(document).ready(function() {
								jQuery('#wpsg_mod_deliverynote_fusstext').val(jQuery("#wpsg_mod_deliverynote_select").val());
							});
											
						/* ]]> */</script>
										
						<input type="hidden" id="wpsg_mod_deliverynote_productindexes" name="wpsg_mod_deliverynote_productindexes" />
										
						<input class="button" style="float:right;" onclick="if (!wpsg_mod_deliverynote_checkProducts()) return false; window.setTimeout(function() { location.href = '<?php echo WPSG_URL_WP; ?>wp-admin/admin.php?page=wpsg-Order&action=view&edit_id=<?php echo $this->view['data']['id']; ?>'; }, 1000);" name="wpsg_mod_deliverynote_write" type="submit" value="<?php echo __("Lieferschein erstellen", "wpsg"); ?>" />
						<input class="button" style="float:right; margin-right:10px;" onclick="if (!wpsg_mod_deliverynote_checkProducts()) return false;" name="wpsg_mod_deliverynote_preview" type="submit" value="<?php echo __("Vorschau", "wpsg"); ?>" />
										
						<div style="clear:both; width:100%; height:5px;"></div>
						
					</div>
					
				</form>
					
			</fieldset>
		<?php } ?>
	
	</div>
</div>

<script type="text/javascript">/* <![CDATA[ */

	/**
	 * Prüft ob Produkte für den Lieferschein ausgewählt wurden
	 */
	function wpsg_mod_deliverynote_checkProducts() 
	{

		if (jQuery('.wpsg_mod_deliverynote_product:checked').length <= 0)
		{

			alert('<?php echo __('Bitte mindestens ein Produkt für den Lieferschein wählen', 'wpsg'); ?>');
			return false;
			
		}
		else
		{

			var arProductKeys = Array();
			
			jQuery('.wpsg_mod_deliverynote_product:checked').each(function() {
				
				arProductKeys.push(jQuery(this).val());
				
			} );

			jQuery('#wpsg_mod_deliverynote_productindexes').val(arProductKeys.join(','));
			
		}

		return true;
		
	} // function wpsg_mod_deliverynote_checkProducts()
		
/* ]]> */</script>