<?php $this->load->view('header');?>

	<div class="row-fluid">
		<div class="span12">

			<!-- BEGIN PAGE TITLE & BREADCRUMB-->

			<h3 class="page-title"><?php echo $this->lang->line('hf_edit_product');?> </h3>

			<ul class="breadcrumb">

				<li><i class="icon-home"></i><a href="<?php echo base_url();?>home/"><?php echo $this->lang->line('hf_home');?></a> <i class="icon-angle-right"></i></li>
				<li><?php echo $this->lang->line('hf_product');?> <i class="icon-angle-right"></i></li>
				<li><?php echo $this->lang->line('hf_edit_product');?></li>
			</ul>
			<!-- END PAGE TITLE & BREADCRUMB-->
		</div>
	</div>
	
	<div class="row-fluid">
		<div class="span12">
			<div class="portlet box blue">

				<div class="portlet-title">

					<div class="caption"><i class="icon-reorder"></i><?php echo $this->lang->line('hf_edit_product');?></div>

				</div>
				
				<div class="portlet-body form">

					<!-- BEGIN FORM-->

					<form enctype="multipart/form-data" id="product-form" class="form-horizontal" method="post" action="<?php echo base_url();?>product/update/<?php echo $this->uri->segment(3);?>/" onsubmit="return validateForm('product-form')">
						<?php 
							$alert_box = '';
							$alert_msg = '';
							
							if($this->session->userdata('form_msg_type') == 100) {
								$alert_box = 'success';
								$alert_msg = $this->session->userdata('form_msg');
							}
							else if($this->session->userdata('form_msg_type') == 200) {
								$alert_box = 'error';
								$alert_msg = $this->session->userdata('form_msg');
							}
							
							if($this->session->userdata('form_msg_type') == 100 OR $this->session->userdata('form_msg_type') == 200) {
								$this->session->unset_userdata(array('form_msg_type' => '', 'form_msg' => ''));
							}

							if( ! empty($alert_msg)) {
						?>
						<div class="alert alert-<?php echo $alert_box;?>">
							<button class="close" data-dismiss="alert"></button>
							<?php echo $alert_msg;?>
						</div>
						<?php }?>
						
						<div class="control-group">
							<label class="control-label" ><?php echo $this->lang->line('product_group');?>: <span class="mandatory">*</span></label>
							<div class="controls">
								<select id="product_group_id" name="product_group_id" class="m-wrap span4">
									<?php
										if($group->num_rows() > 0) {
											foreach($group->result() as $row) {
												if(isset($product_group_id)) {
													if($row->product_group_id == $product_group_id) {
														echo '<option value="' . $row->product_group_id . '" selected="selected">' . $row->product_group_name . '</option>';
													}
													else {
														echo '<option value="' . $row->product_group_id . '">' . $row->product_group_name . '</option>';
													}
												}
												else {
													echo '<option value="' . $row->product_group_id . '">' . $row->product_group_name . '</option>';
												}
											}
										}	
									?>
								</select>
							</div>
						</div>
						
						<div class="control-group">
							<label class="control-label" ><?php echo $this->lang->line('product_category');?>: <span class="mandatory">*</span></label>
							<div class="controls">
								<select id="product_category_id" name="product_category_id" class="m-wrap span4">
									<?php
										if($category->num_rows() > 0) {
											foreach($category->result() as $row) {
												if(isset($product_category_id)) {
													if($row->product_category_id == $product_category_id) {
														echo '<option value="' . $row->product_category_id . '" selected="selected">' . $row->product_category_name . '</option>';
													}
													else {
														echo '<option value="' . $row->product_category_id . '">' . $row->product_category_name . '</option>';
													}
												}
												else {
													echo '<option value="' . $row->product_category_id . '">' . $row->product_category_name . '</option>';
												}
											}
										}	
									?>
								</select>
							</div>
						</div>
						
						<div class="control-group">
							<label class="control-label" ><?php echo $this->lang->line('product_name');?>: <span class="mandatory">*</span></label>
							<div class="controls">
								<input type="text" id="product_name" name="product_name" class="m-wrap span4" value="<?php echo isset($product_name) ? htmlspecialchars($product_name, ENT_QUOTES) : '';?>">
							</div>
						</div>

						<div class="control-group">
							<label class="control-label" ><?php echo $this->lang->line('product_desc');?>: </label>
							<div class="controls">
								<textarea id="product_desc" name="product_desc" class="span10 m-wrap" rows="15"><?php echo isset($product_desc) ? $product_desc : '';?></textarea>
							</div>
						</div>
						
						<div class="control-group">
							<label class="control-label" ><?php echo $this->lang->line('product_image');?> 1: <span class="mandatory">*</span></label>
							<div class="controls">
								<input type="file" id="product_image" name="product_image" value="" class="wrap" />
								<span class="text">
								<?php 
									if($this->uri->segment(2) == 'edit') {
										
										if(isset($product_image) AND $product_image != '' AND file_exists(UPLOAD_PHYSICAL_PATH . $product_image)) {
								?>
										<img src="<?php echo UPLOAD_VIRTUAL_PATH . $product_image;?>" alt="" border="0" width="100" height="100" />
								<?php
										}
										else if(isset($old_product_image) AND $old_product_image != '' AND file_exists(UPLOAD_PHYSICAL_PATH . $old_product_image)) {
								?>
										<img src="<?php echo UPLOAD_VIRTUAL_PATH . $old_product_image;?>" alt="" border="0" width="100" height="100" />
								<?php
										}
									}
								?>
								</span>
							</div>
						</div>
						
						<div class="control-group">
							<label class="control-label" ><?php echo $this->lang->line('product_image');?> 2:</label>
							<div class="controls">
								<input type="file" id="product_image_2" name="product_image_2" value="" class="wrap" />
								<span class="text">
								<?php 
									if($this->uri->segment(2) == 'edit') {
										
										if(isset($product_image_2) AND $product_image_2 != '' AND file_exists(UPLOAD_PHYSICAL_PATH . $product_image_2)) {
								?>
										<img src="<?php echo UPLOAD_VIRTUAL_PATH . $product_image_2;?>" alt="" border="0" width="100" height="100" />
								<?php
										}
										else if(isset($old_product_image_2) AND $old_product_image_2 != '' AND file_exists(UPLOAD_PHYSICAL_PATH . $old_product_image_2)) {
								?>
										<img src="<?php echo UPLOAD_VIRTUAL_PATH . $old_product_image_2;?>" alt="" border="0" width="100" height="100" />
								<?php
										}
									}
								?>
								</span>
							</div>
						</div>
						
						<div class="control-group">
							<label class="control-label" ><?php echo $this->lang->line('product_image');?> 3:</label>
							<div class="controls">
								<input type="file" id="product_image_3" name="product_image_3" value="" class="wrap" />
								<span class="text">
								<?php 
									if($this->uri->segment(2) == 'edit') {
										
										if(isset($product_image_3) AND $product_image_3 != '' AND file_exists(UPLOAD_PHYSICAL_PATH . $product_image_3)) {
								?>
										<img src="<?php echo UPLOAD_VIRTUAL_PATH . $product_image_3;?>" alt="" border="0" width="100" height="100" />
								<?php
										}
										else if(isset($old_product_image_3) AND $old_product_image_3 != '' AND file_exists(UPLOAD_PHYSICAL_PATH . $old_product_image_3)) {
								?>
										<img src="<?php echo UPLOAD_VIRTUAL_PATH . $old_product_image_3;?>" alt="" border="0" width="100" height="100" />
								<?php
										}
									}
								?>
								</span>
							</div>
						</div>
						
						<div class="control-group">
							<label class="control-label" ><?php echo $this->lang->line('product_image');?> 4:</label>
							<div class="controls">
								<input type="file" id="product_image_4" name="product_image_4" value="" class="wrap" />
								<span class="text">
								<?php 
									if($this->uri->segment(2) == 'edit') {
										
										if(isset($product_image_4) AND $product_image_4 != '' AND file_exists(UPLOAD_PHYSICAL_PATH . $product_image_4)) {
								?>
										<img src="<?php echo UPLOAD_VIRTUAL_PATH . $product_image_4;?>" alt="" border="0" width="100" height="100" />
								<?php
										}
										else if(isset($old_product_image_4) AND $old_product_image_4 != '' AND file_exists(UPLOAD_PHYSICAL_PATH . $old_product_image_4)) {
								?>
										<img src="<?php echo UPLOAD_VIRTUAL_PATH . $old_product_image_4;?>" alt="" border="0" width="100" height="100" />
								<?php
										}
									}
								?>
								</span>
							</div>
						</div>
						
						<div class="control-group">
							<label class="control-label" ><?php echo $this->lang->line('product_image');?> 5:</label>
							<div class="controls">
								<input type="file" id="product_image_5" name="product_image_5" value="" class="wrap" />
								<span class="text">
								<?php 
									if($this->uri->segment(2) == 'edit') {
										
										if(isset($product_image_5) AND $product_image_5 != '' AND file_exists(UPLOAD_PHYSICAL_PATH . $product_image_5)) {
								?>
										<img src="<?php echo UPLOAD_VIRTUAL_PATH . $product_image_5;?>" alt="" border="0" width="100" height="100" />
								<?php
										}
										else if(isset($old_product_image_5) AND $old_product_image_5 != '' AND file_exists(UPLOAD_PHYSICAL_PATH . $old_product_image_5)) {
								?>
										<img src="<?php echo UPLOAD_VIRTUAL_PATH . $old_product_image_5;?>" alt="" border="0" width="100" height="100" />
								<?php
										}
									}
								?>
								</span>
							</div>
						</div>
						
						<div class="control-group">
							<label class="control-label" ><?php echo $this->lang->line('product_price');?>: <span class="mandatory">*</span></label>
							<div class="controls">
								<input type="text" id="product_price" name="product_price" class="m-wrap span2" value="<?php echo isset($product_price) ? htmlspecialchars($product_price, ENT_QUOTES) : '';?>">
							</div>
						</div>
						
						<div class="control-group">
							<label class="control-label" ><?php echo $this->lang->line('product_qty');?>: <span class="mandatory">*</span></label>
							<div class="controls">
								<input type="text" id="product_qty" name="product_qty" class="m-wrap span2" value="<?php echo isset($product_qty) ? htmlspecialchars($product_qty, ENT_QUOTES) : '';?>">
							</div>
						</div>
						
						<div class="control-group">
							<label class="control-label" ><?php echo $this->lang->line('product_enable');?>: <span class="mandatory">*</span></label>
							<div class="controls">
								<select id="product_enable" name="product_enable" class="m-wrap span2">
									<option value="0" <?php echo ((isset($product_enable) && $product_enable == 1) ? '' : 'selected="selected"')?>><?php echo $this->lang->line('product_no');?></option>
									<option value="1" <?php echo ((isset($product_enable) && $product_enable == 1) ? 'selected="selected"' : '')?>><?php echo $this->lang->line('product_yes');?></option>
								</select>
							</div>
						</div>
						
						<div class="form-actions">
							
							<input class="no_display" type="hidden" name="old_product_image" value="<?php echo isset($product_image) ? htmlspecialchars($product_image, ENT_QUOTES) : (isset($old_product_image) ? htmlspecialchars($old_product_image, ENT_QUOTES) : '');?>" />
							<input class="no_display" type="hidden" name="old_product_image_2" value="<?php echo isset($product_image_2) ? htmlspecialchars($product_image_2, ENT_QUOTES) : (isset($old_product_image_2) ? htmlspecialchars($old_product_image_2, ENT_QUOTES) : '');?>" />
							<input class="no_display" type="hidden" name="old_product_image_3" value="<?php echo isset($product_image_3) ? htmlspecialchars($product_image_3, ENT_QUOTES) : (isset($old_product_image_3) ? htmlspecialchars($old_product_image_3, ENT_QUOTES) : '');?>" />
							<input class="no_display" type="hidden" name="old_product_image_4" value="<?php echo isset($product_image_4) ? htmlspecialchars($product_image_4, ENT_QUOTES) : (isset($old_product_image_4) ? htmlspecialchars($old_product_image_4, ENT_QUOTES) : '');?>" />
							<input class="no_display" type="hidden" name="old_product_image_5" value="<?php echo isset($product_image_5) ? htmlspecialchars($product_image_5, ENT_QUOTES) : (isset($old_product_image_5) ? htmlspecialchars($old_product_image_5, ENT_QUOTES) : '');?>" />
							<input class="no_display" type="hidden" id="<?php echo $this->security->get_csrf_token_name(); ?>" name="<?php echo $this->security->get_csrf_token_name(); ?>" value="<?php echo $this->security->get_csrf_hash(); ?>" />
							<button type="submit" class="btn blue"><i class="icon-ok"></i> <?php echo $this->lang->line('product_submit');?></button>

						</div>

					</form>

					<!-- END FORM-->  

				</div>

			</div>					
		</div><!-- End span12 -->
		
	</div> <!-- End Row Fluid -->
	
<?php $this->load->view('footer');?>