load_lang();
$db = new dbquery();
$db->connect();
$db2 = new dbquery();
$db2->connect();
$req = new request();
$list = new list_show();
$graph = new graphics();
$sec = new security();
$status_obj = new manage_status();
$ind_coll = $sec->get_ind_collection('letterbox_coll');
$table = $_SESSION['collections'][$ind_coll]['table'];
$view = $_SESSION['collections'][$ind_coll]['view'];
$search_status = $status_obj->get_searchable_status();
$id_report = $_REQUEST['id_report'];
if(empty($id_report))
{
?>
extract_date('creation_date', 'year')." = '".$_REQUEST['the_year']."'";
$date_title = _FOR_YEAR.' '.$_REQUEST['the_year'];
}
else if($period_type == 'period_month')
{
$arr_month = array('01','02','03','04','05','06','07','08','09','10','11','12');
if(empty($_REQUEST['the_month']) || !isset($_REQUEST['the_month']))
{
?>
extract_date('creation_date', 'year')." = '".$default_year."' and ".$req->extract_date('creation_date', 'month')." = '".$_REQUEST['the_month']."'";
$month = '';
switch($_REQUEST['the_month'])
{
case '01':
$month = _JANUARY;
break;
case '02':
$month = _FEBRUARY;
break;
case '03':
$month = _MARCH;
break;
case '04':
$month = _APRIL;
break;
case '05':
$month = _MAY;
break;
case '06':
$month = _JUNE;
break;
case '07':
$month = _JULY;
break;
case '08':
$month = _AUGUST;
break;
case '09':
$month = _SEPTEMBER;
break;
case '10':
$month = _OCTOBER;
break;
case '11':
$month = _NOVEMBER;
case '12':
$month = _DECEMBER;
break;
default:
$month = '';
}
$date_title = _FOR_MONTH.' '.$month;
}
else if($period_type == 'custom_period')
{
if(isset($_REQUEST['date_start']) && $_REQUEST['date_start'] <> '')
{
$where_date .= " AND ".$req->extract_date('creation_date')." > '".$db->format_date_db($_REQUEST['date_start'])."'";
$date_title .= strtolower(_SINCE).' '.$_REQUEST['date_start'].' ';
}
if(isset($_REQUEST['date_fin']) && $_REQUEST['date_fin'] <> '')
{
$where_date .= " AND ".$req->extract_date('creation_date')." < '".$db->format_date_db($_REQUEST['date_fin'])."'";
$date_title.= strtolower(_FOR).' '.$_REQUEST['date_fin'].' ';
}
if(empty($where_date))
{
$where_date = $req->extract_date('creation_date', 'year')." = '".$default_year."'";
$date_title = _FOR_YEAR.' '.$default_year;
}
}
else
{
?>
query("select type_id, description from ".$_SESSION['tablename']['doctypes']." where enabled = 'Y' order by description");
$doctypes = array();
while($res = $db->fetch_object())
{
array_push($doctypes, array('ID' => $res->type_id, 'LABEL' => $res->description));
}
if($report_type == 'graph')
{
$val_an = array();
$_SESSION['labels1'] = array();
}
elseif($report_type == 'array')
{
$data = array();
}
$has_data = false;
for($i=0; $iquery("SELECT ".$req->get_date_diff('closing_date', 'creation_date' )." AS delay FROM ".$view." WHERE ".$where_date." AND status in ".$str_status." and type_id = ".$doctypes[$i]['ID']."");
if( $db->nb_result() > 0)
{
$tmp = 0;
while($res = $db->fetch_object())
{
$tmp = $tmp + $res->delay;
}
if($report_type == 'graph')
{
array_push($val_an, (string)$tmp / $db->nb_result());
}
elseif($report_type == 'array')
{
array_push($data, array('LABEL' => $db->show_string($doctypes[$i]['LABEL']), 'VALUE' => (string)$tmp / $db->nb_result()));
}
if($tmp / $db->nb_result() > 0)
{
$has_data = true;
}
}
else
{
if($report_type == 'graph')
{
array_push($val_an, 0);
}
elseif($report_type == 'array')
{
array_push($data, array('LABEL' => $db->show_string($doctypes[$i]['LABEL']), 'VALUE' => _UNDEFINED));
}
}
if($report_type == 'graph')
{
array_push($_SESSION['labels1'], $db->show_string($doctypes[$i]['LABEL']));
}
}
if($report_type == 'graph')
{
$src1 = $_SESSION['config']['businessappurl']."index.php?display=true&module=reports&page=graphs&type=histo&largeur=1000&hauteur=400&title=".$title."&labelX="._MONTH."&labelY="._N_DAYS;
for($i=0;$i _DOCTYPE, 'VALUE' => _PROCESS_DELAY));
}
if ( $has_data)
{
if($report_type == 'graph')
{
?>
}
elseif($report_type == 'array')
{
$graph->show_stats_array($title, $data);
}
}
else
{
echo '
'._NO_DATA_MESSAGE.'
';
}
}
else if($id_report == 'mail_typology')
{
$has_data = false;
$title = _MAIL_TYPOLOGY_REPORT.' '.$date_title ;
$db->query("select distinct type_id, type_label from ".$view ." where status in ".$str_status." and ".$where_date);
//$db->show();
if($report_type == 'graph')
{
$vol_an = array();
$vol_mois = array();
$_SESSION['labels1'] = array();
}
elseif($report_type == 'array')
{
$data = array();
}
while($line = $db->fetch_object())
{
$db2->query("select count(*) as total from ".$view." where status in ".$str_status." and ".$where_date." and type_id = ".$line->type_id."");
$res = $db2->fetch_object();
if($report_type == 'graph')
{
array_push($_SESSION['labels1'], (string) $line->type_label);
array_push($vol_an, $res->total);
}
elseif($report_type == 'array')
{
array_push($data, array('LABEL' =>$line->type_label, 'VALUE' => $res->total ));
}
if($res->total > 0)
{
$has_data = true;
}
}
if($report_type == 'graph')
{
$src1 = $_SESSION['config']['businessappurl']."index.php?display=true&module=reports&page=graphs&type=pie&largeur=1000&hauteur=300&title=".$title;
for($i=0;$i _DOCTYPE, 'VALUE' => _NB_MAILS1));
}
//echo $src1;
if($has_data)
{
if($report_type == 'graph')
{
?>

}
elseif($report_type == 'array')
{
$graph->show_stats_array($title, $data);
}
}
else
{
echo '
'._NO_DATA_MESSAGE.'
';
}
exit();
}
else if($id_report == 'mail_vol_by_cat')
{
$has_data = false;
$title = _MAIL_VOL_BY_CAT_REPORT.' '.$date_title ;
if($report_type == 'graph')
{
$vol_an = array();
$vol_mois = array();
$_SESSION['labels1'] = array();
}
elseif($report_type == 'array')
{
$data = array();
}
foreach(array_keys($_SESSION['mail_categories']) as $key)
{
$db->query("select count(*) as total from ".$view." where status in ".$str_status." and ".$where_date." and category_id = '".$key."'");
$res = $db->fetch_object();
if($report_type == 'graph')
{
array_push($_SESSION['labels1'], $db->wash_html($_SESSION['mail_categories'][$key], 'NO_ACCENT'));
array_push($vol_an, $res->total);
}
elseif($report_type == 'array')
{
array_push($data, array('LABEL' => $_SESSION['mail_categories'][$key], 'VALUE' => $res->total ));
}
if($res->total > 0)
{
$has_data = true;
}
}
if($report_type == 'graph')
{
$src1 = $_SESSION['config']['businessappurl']."index.php?display=true&module=reports&page=graphs&type=pie&largeur=1000&hauteur=300&title=".$title;
for($i=0;$i _CATEGORY, 'VALUE' => _NB_MAILS1));
}
//echo $src1;
if($has_data)
{
if($report_type == 'graph')
{
?>

}
elseif($report_type == 'array')
{
$graph->show_stats_array($title, $data);
}
}
else
{
echo '
'._NO_DATA_MESSAGE.'
';
}
exit();
}