<?php
/*======================================================\
|                      CHurch                           |
|-------------------------------------------------------|
\======================================================*/

$page_security = 'SA_GRP_TARGET';
$path_to_root  = '../../..';
include($path_to_root . "/includes/db_pager.inc");
include_once($path_to_root . "/includes/session.inc");
add_access_extensions();

$js = "";
if ($SysPrefs->use_popup_windows)
	$js .= get_js_open_window(700, 300);
if (user_use_date_picker())
	$js .= get_js_date_picker();

include_once($path_to_root . "/includes/ui.inc");
include_once($path_to_root . "/modules/church/includes/church_db.inc");
include_once($path_to_root . "/modules/church/includes/church_ui.inc");
include_once($path_to_root . '/modules/kanban/includes/kanban_db.inc');
include_once($path_to_root . '/modules/kanban/includes/kanban_ui.inc');

//--------------------------------------------------------------------------

function target_link($row) {
	return "<a href='addprojecttargets.php?id=".$row['id']."'>".$row['id']."</a>";
}

function edit_link($row) {
    return button('edit_'.$row['id'], _('Edit this target'), false, ICON_EDIT);
}

function amount_format($row) {
    return price_format($row['proj_amt']);
}

//--------------------------------------------------------------------------

foreach (db_query(get_targets(get_post('id'), get_post('proj_id'), get_post('per_Group'))) as $proj) {
    if(isset($_POST['edit_'.$proj['id']]))
        meta_forward($path_to_root.'/modules/church/manage/addprojecttargets.php', 'id='.$proj['id']);
}


    page(_($help_context = "Group Targets"), false, false, "", $js);
    start_form();

    start_outer_table(TABLESTYLE2);
    
    projects_list_cells(_('Project : '), 'proj_id', get_post('proj_id'), _('Select Project'),TRUE);
    group_list_cells(_('Group:'), 'per_Group',  get_post('per_Group'), _('Select Group'),TRUE);
    
    if(!empty(get_post('proj_id'))){
        $project = get_projects(get_post('proj_id'));
        label_cell(_('Project Traget : '). price_format($project['proj_amt']));
    }
    
    $sql = get_targets(false, get_post('proj_id'), get_post('per_Group'));

    $cols = array(
        _('ID') => array('align'=>'center','fun'=>'target_link'),
        _('Project') ,
        _('Group'),
        _('Amount') => array('fun'=>'amount_format', 'align'=>'right'),
        _('Target date') => array('type'=>'date'),
        _('Edit') => array('fun'=>'edit_link','align'=>'center')
    );

    $table = new_db_pager('projects_tbl', $sql, $cols);
    // $table->width = "60%";
    display_note(_('Press id to go to project details.'));
    display_db_pager($table);

    end_form();


end_page();