Location: PHPKode > projects > Yoxel Systems > yoxel_v1.24beta/sfs/sfs_view.php
<?php
// $Header: /home/CVS/rps/sfs/sfs_view.php,v 1.22 2008/10/08 01:00:34 yoxel Exp $
/*
 * ----START-LICENCE----
 * Copyright 2002-2008 Yoxel Systems, Santa Clara, CA, USA (hide@address.com)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA
 * -----END-LICENCE-----
 */

 $hide_header = true;
 $hide_logo = true;
 require_once "../includes/db.inc";
 require_once "includes/sfs/sfs.inc";

 if($is_customer)
	_quit_error("You are not allowed to use this part of the site.");

 define('ACTION_NORMAL', 0x0000);
 define('ACTION_SYNC', 0x0001);
 define('ACTION_STARTIMP', 0x0002);
 define('ACTION_STOPIMP', 0x0003);
 define('ACTION_RESUMEIMP', 0x0004);
 define('ACTION_DELRID', 0x0005);

 init_users();
 $rts = new ForecastTracker();
 $pqs_2d=&$rts->pqs_2d;

$rts->request_view_common_handler();

if (isset($_GET['cc_add']) || isset($_GET['cc_del'])){
	require_once('includes/rts/cc_add_del_inc.php');
}

if (isset($_GET['history'])){	// Request history ...


	$id = ereg_replace("[^0-9]", "", $_GET['history']);
	$xstr2uid=array();
	$RInfo=$rts->request_info($id,$xstr2uid);
	$ruid=$rts->request_owner($RInfo['class'],$RInfo['state'],$xstr2uid);

	// Read CC list
	$CCList = $rts->get_cc_list($id);
	$rts->add_to_cc_list($CCList,$ruid);
	$rts->add_to_cc_list($CCList,$RInfo['filed_by']);

	$Hist = &$rts->read_history($RInfo);

	$on_resize_str="save_geom('geom_sfs')";
	require_once "includes/header.inc";

	// Output data from $Hist
	require_once "includes/rts/show_history_inc.php";

	require_once("includes/footer.inc");
	exit;
}	// isset($_GET['history'])

if (isset($_POST['id'])){
	$id = ereg_replace("[^0-9]", "", $_POST['id']);
	$xstr2uid=array();
	$RInfo=$rts->request_info($id,$xstr2uid);
	$prev_state = $RInfo['prev_state'];

	$state		= $RInfo['state'];
	$class		= $RInfo['class'];
	$fixer		= $RInfo['fixer_uid'];
	$submitter	= $RInfo['filed_by'];
	$rid_is_external = ($RInfo['options']&REQ_OPT_EXTERNAL);

	$ism=$rts->inwork_state_mask[$class];
	$fsm=$rts->fixed_state_mask[$class];
	$vsm=$rts->verified_state_mask[$class];
	$lsm=$rts->last_state_mask($class);

	if (isset($_POST['just_comment'])){
		$comment = "\n".str_replace("\r", "", $_POST['just_comment']);
		$To = $rts->request_owner($class, $state, $xstr2uid);
		$rts->add_comment($RInfo, $comment, $To, $pqs_2d, isset($_POST['cc'])?$_POST['cc']:FALSE);
		header("Location: ".$_SERVER['PHP_SELF']."?history=$id");
		exit;
	}

	$a=explode(':',$_POST['actn']);
	$action = ereg_replace("[^0-9]", "", $a[0]);
	$wfaid = ereg_replace("[^0-9]", "", $a[1]);

	$SQL = array();
	$descr = "\n".str_replace("\r", "", $_POST['descr']);
	$SQLStr = ''; $comment = ''; $OldFixer = $OldTester = false;
	$Flags = $RInfo['options'];

	if(($action == ACTION_DELRID) && ($state&$lsm) && ($user_is&USER_IS_MU)){
                $rts->request_delete($RInfo);

                $on_resize_str="save_geom('geom_sfs')";
                $on_load_str="rts_view_init(true);window.close();";
                $hide_header=TRUE;
                require_once("includes/header.inc");
                require_once("includes/footer.inc");
                exit;
        }

	if($action!=ACTION_NORMAL)
		_quit_error('Unknown action ...');

	$rts->set_state_action($class, $state, $prev_state, $wfaid, $xstr2uid);
	$new_state=$rts->state_actions['next_state'][$wfaid];
	$action_name=$rts->state_actions['name'][$wfaid];
	$action_is_clone=$rts->state_actions['options'][$wfaid]&WFACTION_OPT_CLONE;
	$comment = "Action: $action_name\n";
	$res=$rts->process_view_fields($RInfo,$xstr2uid,$action_is_clone);
	$SQLStr.=array_shift($res);
	$comment.=array_shift($res);

	// Each action comes with default updates
	$f2v=$rts->f2v_for_action($wfaid,$xstr2uid);
	//print_r($f2v);
	foreach($f2v as $f =>$v)
		$SQLStr.=", $f='".escape_data($v)."'";

	$RInfo['state']=$new_state;

	if($action_is_clone){
		$cloned_rid=$rts->clone_request($id);
		$sql_str=$rts->detect_state_change($cloned_rid,$new_state);
		$CRInfo=$RInfo;
		$CRInfo['rid']=$cloned_rid;
		$rts->log_history($CRInfo,$uid,$comment."Cloned from request: $id\n".$descr);
		//$rts->log_history($id,$uid,$RInfo['state'],$comment."Cloned request: $cloned_rid\n".$descr);
		//$descr = "$comment$descr";

		$SQLStr = " state=$new_state $sql_str".($Flags!=$RInfo['options']?", options = {$RInfo['options']}":'')." $SQLStr";

		$RInfo['rid']=$cloned_rid;
		$RInfo['state']=$new_state;
		$rts->request_view_update($RInfo,$SQLStr);

		if($production_mode || !$at_isp)
			$rts->notify_by_email($cloned_rid, $uid, $_POST['descr'], $wfaid, false);
		$_POST=array();
		header("Location: ".$_SERVER['PHP_SELF']."?id=$cloned_rid&reload=true");
	}else{
		$descr = "$comment$descr";
		$sql_str=$rts->detect_state_change($id,$new_state);
		$rts->log_history($RInfo,$uid,$descr);

		$SQLStr = " state=$new_state $sql_str".($Flags!=$RInfo['options']?", options = {$RInfo['options']}":'')." $SQLStr";

		$RInfo['state']=$new_state;
		$rts->request_view_update($RInfo,$SQLStr);

		if($production_mode || !$at_isp)
			$rts->notify_by_email($id, $uid, $_POST['descr'], $wfaid, false);
		$_POST=array();
		header("Location: ".$_SERVER['PHP_SELF']."?id=$id&reload=true");
	}
	exit;
}	// isset($_POST['id'])


if (isset($_GET['id']))			// Request view ...
{
	require_once('includes/rts/view_get_start_inc.php');

	$aList=array(); $a2f=array();
	foreach($rts->state_actions['frequency'] as $wfaid => $f){
		$n=$rts->state_actions['name'][$wfaid];
		array_push($aList,ACTION_NORMAL.':'.$wfaid.':'.($f>0?'* ':'').$n);
		$a2f[$wfaid]=$rts->get_rw_fields($wfaid);
	}

	if (($state&$lsm) && ($user_is&USER_IS_MU))
                array_push($aList, ACTION_DELRID.':0:Delete request');

	$on_resize_str="save_geom('geom_sfs')";
	$on_load_str="rts_view_init(".isset($_GET['reload']).");";
	require_once("includes/header.inc");
	if(!$rid_is_external && $asp_mode)
		if(($licn=check_out_license(LIC_SFS))>-1){
                	if($licn>0)
                     	   _quit_error('License checkout failed. Licensed number of users ('.$licn.') for SFS already reached.');
               		else
                      	  _quit_error('License checkout failed. No license to use this part of SFS.');
		}

	require_once "includes/rts/js_view_filter_inc.php";
	view_menu($id,RTS_VIEW_IS_MAIN);

  $rts->request_view_frm_Start($RInfo);
  $rts->request_view_tr_Action($RInfo,$aList);
  $rts->request_view_tr_IDnDon($RInfo);
  $rts->request_view_tr_Submitter($RInfo);
  $rts->request_view_tr_State($RInfo);
  $rts->request_view_tr_Class($RInfo);
  $rts->request_view_tr_PQ($RInfo,$xstr2uid);
  $rts->request_view_tr_Synopsis($RInfo,'Opportunity Name');
  $rts->request_view_tr_Fixer($RInfo,$xstr2uid,'Owner');
  $rts->request_view_tr_AddRemoveCC($RInfo,$CCList,$inCCList);
  $rts->request_view_tr_Customer($RInfo,TRUE);
  $rts->request_view_tr_Select($RInfo,'lead_source',$lead_source,'Lead Source');
  $rts->request_view_tr_Date($RInfo,'expected_close_date','Expected Close Date');
  $rts->request_view_tr_Amount($RInfo,'booking_amount','Estimated Booking Amount','$');

  //if($state&$ism && !($state&$fsm))
  //	$rts->request_view_tr_FixCompletePct($RInfo);
  $rts->request_view_tr_Parent($RInfo,isset($PhList)?$PhList:FALSE,isset($Parent)?$Parent:FALSE);
  $rts->request_view_tr_SubRequests($RInfo,isset($PhList)?$PhList:FALSE);
  $rts->request_view_tr_Description($RInfo);
  $rts->request_view_frm_Close($RInfo);
?>

<script language='JavaScript'>
<!--
	filter_fields(document.view_frm<?php echo $aList?'':',true'; ?>);
//-->
</script>

<?php
	require_once("includes/footer.inc");
	exit;
} // isset($_GET['id'])

_quit_error("Unknown mode: ".$_SERVER['QUERY_STRING']." ...");

	function view_menu($id,$rts_view_menu=RTS_VIEW_IS_MAIN){
	  global $dir_name;
	  global $is_customer;


		$main_here	= ($rts_view_menu == RTS_VIEW_IS_MAIN)   ? 'class="here"' : '';
		$history_here	= ($rts_view_menu == RTS_VIEW_IS_HISTORY)? 'class="here"' : '';
		$phrase_param = isset($_GET['phrase'])?'&phrase='.$_GET['phrase']:'';
		echo '
         <ul id="topnav">
            <li>'.yxl_gen_link('/sfs/sfs_view.php?id='.$id.$phrase_param,'main view',$main_here).'</li>
            <li>'.yxl_gen_link('/sfs/sfs_view.php?history='.$id.$phrase_param,'history',$history_here).'</li>
	</ul>';
	}
?>





Return current item: Yoxel Systems