<?php

defined('BASEPATH') or exit('No direct script access allowed');

$aColumns = [
    'name',
    'is_public',
    ];

$sIndexColumn = 'id';
$sTable       = 'tblhpyevent_minutes';
$join = [
];
$where = [];

if ($this->ci->input->post('name')) {
    array_push($where, "AND tblproduct.name  LIKE '%".$this->ci->input->post('name')."%'");
}
if ($this->ci->input->post('price')) {
    array_push($where, 'AND price ="' . $this->ci->input->post('price').'"');
}
if ($this->ci->input->post('price_buy')) {
    array_push($where, 'AND price_buy ="' . $this->ci->input->post('price_buy').'"');
}
if ($this->ci->input->post('categ')) {
    array_push($where, 'AND tblproduct.categ_id =' . $this->ci->input->post('categ'));
}
if ($this->ci->input->post('valabilitate1')) {
    array_push($where, 'AND valabilitate1 ="' . $this->ci->input->post('valabilitate1').'"');
}
if ($this->ci->input->post('valabilitate2')) {
    array_push($where, 'AND valabilitate2 ="' . $this->ci->input->post('valabilitate2').'"');
}
if ($this->ci->input->post('stoc')) {
    array_push($where, 'AND stoc ="' . $this->ci->input->post('stoc').'"');
}
if ($this->ci->input->post('delivery')) {
    array_push($where, 'AND delivery ="' . $this->ci->input->post('delivery').'"');
}
if ($this->ci->input->post('supplier_id')) {
    array_push($where, 'AND supplier_id =' . $this->ci->input->post('supplier_id'));
}

$result  = data_tables_init($aColumns, $sIndexColumn, $sTable, $join, $where, ['tblhpyevent_minutes.id','tblhpyevent_minutes.event_id']);
$output  = $result['output'];
$rResult = $result['rResult'];

foreach ($rResult as $aRow) {
    $row = [];
//    $row[] = '<div class="checkbox"><input type="checkbox" value="' . $aRow['id'] . '"><label></label></div>';
    //$row[] = '<a href="' . admin_url('hpyevents/produs/' . $aRow['id']) . '" class="mbot10 display-block">' . $aRow['id'] . '</a>';
    $row[] = $aRow['id'];
    $row[] = '<a href="' . admin_url("hpyevents/minute/{$aRow['event_id']}/{$aRow['id']}") . '" class="mbot10 display-block">' . $aRow['name'] . '</a>';
    $row[] = '<a href="' . admin_url("hpyevents/minute/{$aRow['event_id']}/{$aRow['id']}") . '" class="mbot10 display-block">' . ((int)$aRow['is_public']=== 1 ? 'Da' : 'Nu') . '</a>';

    $options = icon_btn("hpyevents/minute/{$aRow['event_id']}/{$aRow['id']}", 'pencil-square-o');
    $options .= '<a data-id="' . $aRow['id']. '" class="btn btn-default btn-icon mailBtn"><i class="fal fa-envelope"></i></a>';
    $options .= icon_btn("hpyevents/minute/{$aRow['event_id']}/{$aRow['id']}", 'times', 'btn-danger _delete');
    $row[]   = $options ;

    $output['aaData'][] = $row;
}
