dimanche 18 janvier 2015

Checkbox checked using tcpdf that generated from mysql table with codeigniter

I am using codeigniter to develop my App and I have a field in mysql table that generated from checkbox array value in html.


So, this is my view



<div class="box-content">
<?php
$properties = array('class' => 'form-horizontal', 'id' => 'myForm');
echo form_open("control_fixing/userRequest", $properties);?>

<div class="control-group">
<label class="control-label">Request :</label>
<div class="controls" id="chekboxes">
<label class="checkbox inline"><input type="checkbox" name="request[]" id="Login" value="Login" > Login </label>
<label class="checkbox inline"><input type="checkbox" name="request[]" id="Printer" value="Printer"> Printer </label>
<label class="checkbox inline"><input type="checkbox" name="request[]" id="Monitor" value="Monitor"> Monitor</label>
<label class="checkbox inline"><input type="checkbox" name="request[]" id="Computer" value="Computer"> Computer</label>
<label class="checkbox inline"><input type="checkbox" name="request[]" id="Network" value="Network"> Network</label>
<label class="checkbox inline"><input type="checkbox" name="request[]" id="Lain-lain" value="Lain-lain" > Other</label>
</div>

<a class="btn btn-success" >
<i class="halflings-icon pencil"></i> Print
</a>
</div>
<?php echo form_close(); ?>
</div>
<script>

$(".btn-success").click(function() {
var $row = $(this).closest("tr"); // Find the row
var test = $row.find("#id_request").text(); // Find the text
var get_id = tes.substring(10);
window.location.href="<?php echo base_url(). 'control_fixing/generate_pdf/'?>"+ get_id;

});


And this is my model



public function insertRequest($id_request, $kindOf_request) {
$query = $this->db->query(" INSERT INTO
tbl_requestfix
(id_request,jenis_request)
VALUES
('$id_request','$kindOf_request');
return $query;
}

public function selectOneRequest($id_request) {
$query = $this->db->get_where('tbl_requestfix', array('id_request' => $id_request));
return $query->result_array();
}


Storyboard : Just say if user want to checked any option like Login, printer and Monitor it will save in my tbl_requestfix in kindOf_Request field like this : Login, Printer, Monitor and it's done...


So, this is my controller :



public function userRequest(){
$user_request = $_POST['request'];
$selected_request = "";
foreach($user_request as $request){
$selected_request .= $request. ", " ;
}
$selected_request = substr($selected_request,0,-2);

$insert_data = $this->model_request->insertRequest($selected_request);



public function generate_pdf($idRequest) { //This function to generate a PDF report

$data = $this->model_request->selectOneRequest($idRequest);

foreach ($data as $d) {

$this->load->library("TC_PDF");
$pdf = new TC_Pdf(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

// set margins
//$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetMargins(10, 10, 10, true);

// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__) . '/lang/eng.php')) {
require_once(dirname(__FILE__) . '/lang/eng.php');
$pdf->setLanguageArray($l);
}


// add a page
$pdf->AddPage();

$check= $d['kindOf_request'];

//This is the problem, how to get just the checkbox that have checked based in field of my table. So, the **Login, Printer, Monitor** will be checked and another will be blank checked.

$html = <<<EOD

<form action="">
<input type="checkbox" name="request[]" id="Login" value="Login" > Login $check
<input type="checkbox" name="request[]" id="Printer" value="Printer" > &nbsp; Printer
<input type="checkbox" name="request[]" id="Monitor" value="Monitor" > &nbsp; Monitor
<input type="checkbox" name="request[]" id="Computer" value="Computer" > &nbsp; Computer
<input type="checkbox" name="request[]" id="Network" value="Network" > &nbsp; Network
<input type="checkbox" name="request[]" id="Lain-lain" value="Lain-lain" > Other
</form>
EOD;

// reset pointer to the last page
$pdf->lastPage();


// ---------------------------------------------------------
//Close and output PDF document
$pdf->Output('Request '.$d['id_request'].'.pdf', 'I');


The problem is to generate a pdf, how to get just the checkbox that have checked based in field of my table. So, the Login, Printer, Monitor will be checked and another like Computer, Network,Other will be blank checked.


Thank you So much for the help ...





Aucun commentaire:

Enregistrer un commentaire