<!--Copyright (C) 2014  Web3king - Alberto Bonacina

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
-->

<h1>Manage Dish</h1>

<div class="col-lg-12">
	<div class="panel panel-info">
		<div class="panel-heading">Create a new dish</div>
		<div class="panel-body">
		    
		    <?php   
                    $attributes = array('role' => 'form', 'class' => 'form-horizontal');
                    echo form_open('dish/createDishDb',$attributes);                    

                    echo "<div class='form-group'>";
	                    echo '<label for="dish-name" class="col-lg-2 control-label">Dish Name</label>';
	                    echo '<div class="col-lg-6">';
		                    $nome_array = array('type' => 'text',
		                        'name' => 'name',
		                        'class' => 'form-control'
		                    );
		                    echo form_input($nome_array);
	                    echo '</div>';
                    echo "</div>";

                    echo "<div class='form-group'>";
	                    echo '<label for="dish-name" class="col-lg-2 control-label">Ingredients</label>';
	                    echo '<div class="col-lg-9">';

	                    echo '<div class="panel-group">
						  <div class="panel panel-default">
						    <div id="collapseOne" class="panel-collapse collapse in">
						      <div class="panel-body">';

							echo '<table id="ingTable">
									<thead>
										<tr>
											<th>In use</th>
											<th>Name</th>
											<th>Quantity</th>
											<th>Measure</th>
										</tr>
									</thead>
									<tbody>';

							foreach($ingredentsFromDb->result() as $row): 
		                    	echo '<tr>';
		                    	echo '<td><input name="ingredients[]" type="checkbox" id="'.$row->id.'" class="bigCheckbox" value="'.$row->id.'"></td>';
		                    	echo '<td><label>'.$row->name.'<label></td>';
		                    	echo '<td class="col-lg-3">';
			                    	$q_array = array('type' => 'text',
				                        'name' => 'quantity['.$row->id.']',
				                        'class' => 'form-control'
				                    );
				                    echo form_input($q_array);
		                    	echo '</td>';
		                    	echo '<td><label>'.$row->measurename.'<label></td>';
		                    	echo '</tr>';
							endforeach;

							echo '</tbody></table>';

						echo '</div></div></div></div>';
	                    echo '</div>';
                    echo "</div>";

                    echo "<div class='form-group'>";
	                    echo '<label for="people-name" class="col-lg-2 control-label">People</label>';
	                    echo '<div class="col-lg-2">';
		                    $people_array = array('type' => 'text',
		                        'name' => 'people',
		                        'class' => 'form-control'
		                    );
		                    echo form_input($people_array);
	                    echo '</div>';
                    echo "</div>";

                    echo "<div class='form-group'>";
	                    echo '<label for="price-name" class="col-lg-2 control-label">Price</label>';
	                    echo '<div class="col-lg-2">';
		                    $price_array = array('type' => 'text',
		                        'name' => 'price',
		                        'class' => 'form-control',
		                        'placeholder' => 'Optional'
		                    );
		                    echo form_input($price_array);
	                    echo '</div>';
                    echo "</div>";

                    echo "<div class='form-group'>";
	                    echo '<label for="kcal-name" class="col-lg-2 control-label">KCal</label>';
	                    echo '<div class="col-lg-2">';
		                    $kcal_array = array('type' => 'text',
		                        'name' => 'kcal',
		                        'class' => 'form-control',
		                        'placeholder' => 'Optional'
		                    );
		                    echo form_input($kcal_array);
	                    echo '</div>';
                    echo "</div>";

                    echo "<div class='form-group'>";
	                    echo '<label for="type-name" class="col-lg-2 control-label">Type</label>';
	                    echo '<div class="col-lg-2">';
	                    	echo '<select name="type" class="form-control">';

	                    	foreach($typesFromDb->result() as $tipo){
		                    	echo '<option value="'.$tipo->id.'">'.$tipo->type.'</option>';
							};
							$typesFromDb->free_result(); 
							echo "</select>";
	                    echo '</div>';
                    echo "</div>";

                    echo "<div class='form-group'>";
	                    echo '<label for="description" class="col-lg-2 control-label">Description</label>';
	                    echo '<div class="col-lg-9">';
		                    $desc_array = array('type' => 'text',
		                        'name' => 'description',
		                        'class' => 'form-control',
		                        'rows' => '5'
		                    );
		                    echo form_textarea($desc_array);
	                    echo '</div>';
                    echo "</div>";
                    
                    echo "<div class='form-group'>";
	                    echo '<div class="col-lg-offset-2 col-lg-10">';
		                    $button_array = array('class' => 'btn btn-primary',
		                        'type' => 'submit',
		                        'name' => 'submit',
		                        'value' => 'Add Dish' 
		                    );
	                    echo form_submit($button_array);
	                    echo '</div>';
                    echo "</div>";

                    
                    echo form_close();                        
            ?>

		</div>	
	</div>
</div>	

<div class="col-lg-12">
	<div class="panel panel-info">
		<div class="panel-heading">Dishes List</div>
		<div class="panel-body">
			<div class="table-responsive">
				<table class="table table-striped table-bordered" id="myTable">
                    <thead>
                            <tr>
                                    <th>Dish</th>
                                    <th>People</th>
                                    <th>Type</th>
                                    <th>Price</th>
                                    <th>Kcal</th>
                                    <th>Azioni</th>
                            </tr>
                    </thead>
                    <tbody>
                        <?php foreach($dishFromDb->result() as $row): ?>
                        <tr>
                            <td><?php echo $row->name; ?></td>
                            <td><?php echo $row->people; ?></td>
                            <td><?php 
                            //metto il nome e non l'id del piatto
                            foreach($typesFromDb->result() as $tipo){
                            	if($tipo->id == $row->type){
                            		echo $tipo->type;
                            	}
							};
                            ?></td>
                            <td><?php echo $row->price; ?></td>
                            <td><?php echo $row->kcal; ?></td>
                            <td>
                                <div class="btn-group">
                                    <a href="<?php echo base_url();?>index.php/dish/modifySingleDish/<?php echo $row->id;?>" class="btn btn-info"><i class="fa fa-pencil"></i></a>
                                    <a class="btn btn-danger" href="<?php echo base_url();?>index.php/dish/deleteDishDb/<?php echo $row->id;?>"><i class="fa fa-trash-o"></i></a>
                                </div>
                            </td>
                        </tr>

                    	<?php endforeach; ?>
                    </tbody>
	    		</table>
	    	</div>
		</div>	
	</div>
</div>	