root/c3crm/sugarcrm/trunk/modules/Reports/DetailView.php

Revision 1154 (by jianting, 04/19/06 23:49:51)

lates report module

<?php
require_once('XTemplate/xtpl.php');
require_once('data/Tracker.php');
require_once('modules/Reports/Report.php');
require_once('include/TimeDate.php');
require_once("include/templates/TemplateGroupChooser.php");
$timedate = new TimeDate();
global $mod_strings;
global $app_strings;
global $app_list_strings;
global $gridline;
$focus =& new Report();


if(!empty($_REQUEST['record'])) {
    $result = $focus->retrieve($_REQUEST['record']);
    if($result == null)
    {
    	sugar_die("Error retrieving record.  You may not be authorized to view this record.");
    }
}
else {
	header("Location: index.php?module=Reports&action=index");
}

if(isset($_REQUEST['isDuplicate']) && $_REQUEST['isDuplicate'] == 'true') {
	$focus->id = "";
}
echo "\n<p>\n";
echo get_module_title($mod_strings['LBL_MODULE_NAME'], $mod_strings['LBL_MODULE_NAME'].": ".$focus->name, true);
echo "\n</p>\n";
global $theme;
$theme_path="themes/".$theme."/";
$image_path=$theme_path."images/";
require_once($theme_path.'layout_utils.php');

$log->info("Report detail view");

$xtpl=new XTemplate ('modules/Reports/DetailView.html');
$xtpl->assign("MOD", $mod_strings);
$xtpl->assign("APP", $app_strings);

$xtpl->assign("THEME", $theme);
$xtpl->assign("GRIDLINE", $gridline);
$xtpl->assign("IMAGE_PATH", $image_path);
$xtpl->assign("PRINT_URL", "index.php?".$GLOBALS['request_string']);
$xtpl_data = $focus->get_xtemplate_data();
$xtpl->assign("Report",$xtpl_data);

$primarymodule = $focus->primarymodule;

$relatedmodule = $focus->relatedmodule;
$field_array = array();
$relatedmodule_array = array();
if(!empty($primarymodule)) {
	include_once($beanFiles[$beanList[$primarymodule]]);
	$bean = new $beanList[$primarymodule]();
	$relatedmodule_array = $bean->get_related_modules();
	if(isset($bean->column_fields)) {
		foreach($bean->column_fields as $field)
		{
			$field_array[$bean->table_name.".".$field] = get_fieldlabel($bean->module_dir,$bean->field_defs[$field]['vname']);
		}
	}
}
if(!array_key_exists($relatedmodule,$relatedmodule_array)) {
	$relatedmodule = "";
}

if(!empty($relatedmodule)) {
	include_once($beanFiles[$beanList[$relatedmodule]]);
	$bean = new $beanList[$relatedmodule]();
	foreach($bean->column_fields as $field)
	{
		$field_array[$bean->table_name.".".$field] = get_fieldlabel($bean->module_dir,$bean->field_defs[$field]['vname']);
	}
}

$list_field_array = array();
if(!empty($focus->reportfields)) {
	$list_field_array = explode(",",$focus->reportfields);
	$temp_array = array();
	foreach($list_field_array as $value) {
		if(substr_count($value," ") > 0) {
			$value_array = explode(" ",$value);
			if(isset($field_array[$value_array[0]])) { 
				$temp_array[$value_array[0]] = $field_array[$value_array[0]];
			} else {
				$temp_array[$value_array[0]] = $value_array[0];
			}
		} else {
			if(isset($field_array[$value])) { 
				$temp_array[$value] = $field_array[$value];
			} else {
				$temp_array[$value] = $value;
			}
		}
		
	}
	$list_field_array = $temp_array;
}

$field_array_list = array_diff($field_array,$list_field_array);

$chooser = new TemplateGroupChooser();
$chooser->display_hide_tabs = true;
$chooser->args['id'] = 'list_users';
$values_array = array();
$values_array[] = $list_field_array;
$values_array[] = $field_array_list;
$chooser->args['values_array'] = $values_array;
$chooser->args['left_name'] = 'display_fields_list';
$chooser->args['right_name'] = 'hide_fields_list';
$chooser->args['left_label'] =  $mod_strings['LBL_YES_LIST_FIELDS'];
$chooser->args['right_label'] =  $mod_strings['LBL_NO_LIST_FIELDS'];
$chooser->args['title'] =  $mod_strings['LBL_LIST_FIELDS_TITLE'];
$xtpl->assign("REPORTFIELDS_CHOOSER", $chooser->display());

$total_field_array = array();
if(!empty($focus->reporttotal)) {
	$total_field_array = explode(",",$focus->reporttotal);
	$temp_array = array();
	foreach($total_field_array as $value) {
		if(isset($field_array[$value])) { 
			$temp_array[$value] = $field_array[$value];
		} else {
			$temp_array[$value] = $value;
		}
		//$temp_array[$value] = $value;
	}
	$total_field_array = $temp_array;
}
$field_array_total = array_diff($field_array,$total_field_array);

$chooser_total = new TemplateGroupChooser();
$chooser_total->display_hide_tabs = true;
$chooser_total->args['id'] = 'total_fields';
$values_array = array();
$values_array[] = $total_field_array;
$values_array[] = $field_array_total;
$chooser_total->args['values_array'] = $values_array;
$chooser_total->args['left_name'] = 'total_fields_list';
$chooser_total->args['right_name'] = 'no_total_fields_list';
$chooser_total->args['left_label'] =  $mod_strings['LBL_YES_TOTAL_FIELDS'];
$chooser_total->args['right_label'] =  $mod_strings['LBL_NO_TOTAL_FIELDS'];
$chooser_total->args['title'] =  $mod_strings['LBL_TOTAL_FIELDS_TITLE'];
$xtpl->assign("TOTALFIELDS_CHOOSER", $chooser_total->display());

$xtpl->assign("CHOOSER_SCRIPT","set_chooser();");

$xtpl->assign("CONTION_OPERATOR_OPTIONS", get_options_without_line($app_list_strings['fop_select_type_dom'], ""));
$xtpl->assign("CONDITION_FIELDS_OPTIONS", get_options_without_line($field_array, ""));

$xtpl->assign("ORDERBY_DIRECTION_OPTIONS", get_options_without_line($app_list_strings['orderby_direction_dom'], ""));
$xtpl->assign("ORDERBY_FIELDS_OPTIONS", get_options_without_line($field_array, ""));

global $current_user;
if(is_admin($current_user) && $_REQUEST['module'] != 'DynamicLayout' && !empty($_SESSION['editinplace'])){
	$xtpl->assign("ADMIN_EDIT","<a href='index.php?action=index&module=DynamicLayout&from_action=".$_REQUEST['action'] ."&from_module=".$_REQUEST['module'] ."&record=".$_REQUEST['record']. "'>".get_image($image_path."EditLayout","border='0' alt='Edit Layout' align='bottom'")."</a>");
}
$xtpl->parse("main");
$xtpl->out("main");

if(!empty($focus->reportconditions)) {
	$i = 0;
	$orderby_array = explode(" and ",$focus->reportconditions);
	foreach($orderby_array as $value) {
		$i ++;
		$fieldname = trim(substr($value,0,strpos($value," ")));
		$value = trim(substr($value,strpos($value," ")+1));
		$fieldop = trim(substr($value,0,strpos($value," ")));
		$value = trim(substr($value,strpos($value," ")+1));
		//$value = trim($value,"'");
		if(substr_count($fieldop,'like') > 0) {
			$value = trim(str_replace("%","",$value));
		}
		echo "<script language='javascript'>";
		echo "fnAddRow();";
		echo "document.DetailView.conditionField_".$i.".value='".$fieldname."';";
		echo "document.DetailView.fopField_".$i.".value='".$fieldop."';";
		echo "document.DetailView.conditionValue_".$i.".value=replaceAll('".$value."','&#039;','');";
		echo "</script>";
	}
}

if(!empty($focus->reportorderby)) {
	$i = 0;
	$orderby_array = explode(",",$focus->reportorderby);
	foreach($orderby_array as $value) {
		$i ++;
		$field = trim(substr($value,0,strpos($value," ")));
		$direction = trim(substr($value,strpos($value," ")+1));
		echo "<script language='javascript'>";
		echo "orderbyAddRow();";
		echo "document.DetailView.orderbyField_".$i.".value='".$field."';";
		echo "document.DetailView.orderbyDirection_".$i.".value='".$direction."';";
		echo "</script>";
	}
}

?>
Note: See TracBrowser for help on using the browser.