<?php
defined('BASEPATH') or exit('No direct script access allowed');
$aColumns = [
   'id',
	'triggertime',
	'triggerday',
	'emails',
	'(CASE WHEN choice_type="CONTRACT" THEN "Project with Contract Type" ELSE "Specific Project" END)',
	'(CASE WHEN choice_type="CONTRACT"  THEN (SELECT name FROM ' . db_prefix() . 'contracts_types WHERE ' . db_prefix() . 'contracts_types.id = ' . db_prefix() . 'project_notifications.contract_type) ELSE (SELECT name FROM ' . db_prefix() . 'projects WHERE ' . db_prefix() . 'projects.id = ' . db_prefix() . 'project_notifications.projects) END)',
	'(CASE WHEN dataset="SO-FAR" THEN "Send Details So Far" ELSE "Send Details For Previous Week" END)',
];
$sIndexColumn = 'id';
$sTable       = db_prefix() . 'project_notifications';
$result       = data_tables_init($aColumns, $sIndexColumn, $sTable, [], [], []);

$output  = $result['output'];
$rResult = $result['rResult'];

foreach ($rResult as $aRow) {

    $row = [];
    for ($i = 0; $i < count($aColumns); $i++) {
        $_data = $aRow[$aColumns[$i]];
		
        if ($aColumns[$i] == 'triggertime') {
            $_data = '<a href="#" onclick="new_task(\''.admin_url('project_notifications/configure/'.$aRow['id']).'\'); return false;">' . $_data . '</a>';

            $_data .= '<div class="row-options">';

            $_data .= '  <a href="#" onclick="new_task(\''.admin_url('project_notifications/configure/'.$aRow['id']).'\'); return false;">' . _l('edit') . '</a>';

            if (has_permission('notification', '', 'delete')) {
                $_data .= ' | <a href="' . admin_url('project_notifications/delete/' . $aRow['id']) . '" class="text-danger _delete">' . _l('delete') . '</a>';
            }
			
			 $_data .= ' | <a href="' . admin_url('project_notifications/execute/' . $aRow['id']) . '">' . _l('pn_execute') . '</a>';

            $_data .= '</div>';
        } 
        $row[] = $_data;
    }
    $row['DT_RowClass'] = 'has-row-options';
    $output['aaData'][] = $row;

}