<?php

	$action_list_query = "
    SELECT 
        *
    FROM
        (SELECT 
            tr_id AS obj_id,
                TIMESTAMP(tr_date) AS obj_date,
                'training' AS obj_type
        FROM
            training
        JOIN training_coach ON trc_training_tr_id = tr_id
        WHERE
            trc_coach_uc_id = " . $user->get_ua_id() . " AND tr_deleted = 0
        ORDER BY tr_date DESC) valami 
    UNION (SELECT 
        mox_id AS obj_id,
        TIMESTAMP(date_add(mox_date, INTERVAL '23:59' HOUR_MINUTE)) AS obj_date,
        'money_expense' AS obj_type
    FROM
        money_expense
    WHERE
        mox_user_coach_ua_id = " . $user->get_ua_id() . " AND mox_deleted = 0) ORDER BY obj_date DESC , obj_type ASC;
    ";
	

	$action_assoc_array = $sql->assoc_array($action_list_query);

    $actions = array();
    foreach ($action_assoc_array as $action_array) {
        if ('money_expense' == $action_array['obj_type']) {
            $action = new $action_array['obj_type']();
            $action->set_mox_data_by_id($action_array['obj_id']);
        }
        elseif ('training' == $action_array['obj_type']) {
            $action = new $action_array['obj_type']();
            $action->set_training_data_by_id($action_array['obj_id']);
        }
        $actions[] = $action;
    }

    //var_dump($actions);

    $smarty->assign('actions',$actions);
	$smarty->display('coach_diary.tpl');
	


?>