<?php
	
	/**
	 * Template für das Anlegen und Bearbeiten einer Kundengruppe im Backend
	 */

?>
<div class="wrap wpsg_mod_kundenverwaltung_customergroup_addedit wpsg_customergroup_view wpsg_produkt_addedit wrap columns-2">
	<div class="icon32 icon32-posts-post" id="icon-add"><br /></div>
	
	<h2>
		<?php if ($this->view['mode'] == 'edit') { ?>
			<?php echo __('Kundengruppe bearbeiten', 'wpsg'); ?>
		<?php } else { ?>
			<?php echo __('Kundengruppe anlegen', 'wpsg'); ?>
		<?php } ?>
	</h2>
	<br />
	
	<?php echo $this->writeBackendMessage(); ?>
	
	<form method="POST" action="<?php echo WPSG_URL_WP; ?>wp-admin/admin.php?page=wpsg-Customergroup&action=save&noheader=1" enctype="multipart/form-data">
		
		<?php if ($this->view['mode'] == 'edit') { ?>
		<input type="hidden" name="edit_id" value="<?php echo $this->view['data']->id; ?>" />
		<?php } ?>
		
		<div id="postbox" class="metabox-holder has-right-sidebar">
			
			<div id="side-info-column" class="inner-sidebar" style="width:386px;">
				
				<div id="side-sortables" class="meta-box-sortables ui-sortable" style="width:380px;">
				
					<?php $this->callMods('customergroup_edit', array(&$this->view['data'])); ?>
				
				</div>
				
			</div>
			
			<div id="post-body">	
			
				<div id="normal-sortables" class="meta-box-sortables" style="margin-right:400px;">
				
					<div id="wpsg_customergroup_general" class="postbox">								
						<h3 class="wpsg_handlediv">
							<span title="<?php echo __('Zum Ein/Ausklappen hier klicken', 'wpsg'); ?>" class="handlediv"><br /></span>
							<span><?php echo __('Allgemein', 'wpsg'); ?></span>
						</h3>
						<div class="inside">
						
							<?php echo wpsg_drawForm_Input('wpsg_mod_kundenverwaltung[name]', __('Name', 'wpsg'), $this->view['data']->name); ?> 
							<?php echo wpsg_drawForm_Select('wpsg_mod_kundenverwaltung[calculation]', __('Preisangaben im Shop (Frontend)', 'wpsg'), array(
								-1 => __('Standard', 'wpsg'),
								WPSG_BRUTTO => __('Brutto (inkl. Steuer)', 'wpsg'), 
								WPSG_NETTO => __('Netto (zzgl. Steuer)', 'wpsg')
							), $this->view['data']->calculation); ?>
						
						</div>
					</div>
					
				</div>
				
				<p class="submit">
					<input type="submit" value="<?php echo __('Kundengruppe speichern', 'wpsg'); ?>" class="button-primary" id="submit" name="submit" />
					<input type="submit" value="<?php echo __('Kundengruppe speichern und zur Übersicht', 'wpsg'); ?>" class="button-primary" id="submit_index" name="submit_index" />
				</p>
				
			</div>
			
		</div>
		
	</form>
	
</div>

<script type="text/javascript">/* <![CDATA[ */
                                            
	jQuery(document).ready( function() {

		jQuery('.wpsg_form_help').tipTip();

	    jQuery("#normal-sortables, #side-sortables").sortable({
			connectWith: ".meta-box-sortables",
			placeholder: 'wpsg_placeholder',
			dropOnEmpty: true,
			cursor: 'move',
			handle: '.wpsg_handlediv',
			grid: [50, 20],
			forceHelperSize: true,
			forcePlaceholderSize: true,
			opacity: 0.8,
			stop: function(e,ui) {

				var ser = jQuery("#normal-sortables").sortable("serialize");				
				ser = ser.replace(/\&wpsg\[\]\=/g, ',').replace(/wpsg\[\]\=/g, '');

				jQuery.cookie('wpsg_customergroup_view_normal', ser);

				var ser = jQuery("#side-sortables").sortable("serialize");				
				ser = ser.replace(/\&wpsg\[\]\=/g, ',').replace(/wpsg\[\]\=/g, '');

				jQuery.cookie('wpsg_customergroup_view_side', ser);
				
			},
			receive: function(e, ui) {
			}
		}); 

	    if (jQuery.cookie('wpsg_customergroup_view_normal') != null)
		{

			var divs = jQuery.cookie('wpsg_customergroup_view_normal').split(',').reverse();

			for (index in divs)
			{

				jQuery('#normal-sortables').prepend(jQuery('#wpsg_' + divs[index]));
				
			}
			
		}

		if (jQuery.cookie('wpsg_customergroup_view_side') != null)
		{
 
			var divs = jQuery.cookie('wpsg_customergroup_view_side').split(',').reverse();

			for (index in divs)
			{
				 
				jQuery('#side-sortables').prepend(jQuery('#wpsg_' + divs[index]));
				
			}
			
		}

		jQuery('.wpsg_handlediv').bind('click', function() {
			jQuery(this).next().toggle();

			var arClose = new Array();
			jQuery('.wpsg_customergroup_view .postbox .inside:hidden').each(function() {
				arClose.push(jQuery(this).parent().attr("id"));
			} );

			jQuery.cookie('wpsg_customergroup_closed', arClose.join(','));
			
		} );

		if (jQuery.cookie('wpsg_customergroup_closed') != null)
		{

			var arClose = jQuery.cookie('wpsg_customergroup_closed').split(',');

			for (index in arClose)
			{
				
				jQuery('#' + arClose[index] + ' .inside').hide();
							
			}
			
		}
		
	} );
	
/* ]]> */</script>