<?php
/* $Id: index.php,v 1.33 2003/09/27 17:04:06 k-fish Exp $ */
$myEnv["module"] = "tts";
$myEnv["output"] = "html";

require_once("../../config.inc.php");
require_once(INCLUDEPATH . "container.inc.php");
include_once("./inc/repository.inc.php");
include_once("./inc/ticket.class.php");
include_once("./inc/inter.class.php");



// adding file revision into global array
revisionInit("\$Revision: 1.33 $", __FILE__);

$action="";
if(isset($_GET["action"]))
	$action=$_GET["action"];


if (($action == "detail")
	|| ($action == "historic")
	|| ($action == "image")	
	){
    $id="";
    if(isset($_GET["id"])) {
    	$id=(int)$_GET["id"];
    }
	
	$tick = new Ticket($id);
}
else {
	$tick = new Ticket();
}


// =================================================
//	              creation of a new ticket
// =================================================

if (isset($_POST["create"]) and !empty($_POST["create"])){
	
    $currentProj=(int)$_POST["_project"];
    $ticketOwner = (int)$_POST["ownervalid"];
    $assignedUser=(int)$_POST["_assigned"];
    $priority=(int)$_POST["_priority"];    
    $severity=(int)$_POST["_severity"];    
    $resolution=(int)$_POST["_resolution"];    
    
    $shortDescription=$conn->QMagic($_POST["short_desc"]);
    $longDescription=$conn->QMagic($_POST["long_desc"]);

	//ticket creation
	$tick->opCreate();
	//first inter creation	
	$inter = new Inter($tick->getId());
	$inter->opCreateDefault($tick->getId()); 

   
    redirect("./index.php?".SID);

}

// =================================================
//	              modification of a ticket
// =================================================

if (isset($_POST["modify"]) and !empty($_POST["modify"])){

	$tick->opUpdate();
	
    redirect("./index.php?".SID);

}

// ===========================================================
//	  creation of a new intervention on a ticket
// ===========================================================

if (!empty($_POST["addinter"])){

	$inter = new Inter($tick->getId());
	$inter->opCreate();
    redirect("./index.php?".SID);

}

// =================================================
//	              Ticket Detail
// =================================================

if ($action == "detail") {
	global $priority;
    include_once(INCLUDEPATH . "mSelectBox.class.php");  

	$tick->viewDetails();
	
    exit();
}



// =================================================
//	              Ticket modification
// =================================================

if ($action == "editform") {
	global $priority;
    include_once(INCLUDEPATH . "mSelectBox.class.php");  

	$tick->viewEditForm();
    exit();
}


// =================================================
//	              Summary
// =================================================
if ($action == "summary") {
	global $status, $severity, $resolution;
    include_once(INCLUDEPATH . "mSelectBox.class.php");  
	
	$tick->viewSummary();
   
    exit();
    
}

// =================================================
//	              New Ticket
// =================================================
if ($action == "newform") {
	global $priority, $severity, $resolution;

	$tick->viewNewForm();

    exit();
}
// =================================================
//	              New intervention
// =================================================
if ($action == "newinter") {
	global $status;
    include_once(INCLUDEPATH . "mSelectBox.class.php");  

	$inter = new Inter(-1, $tick->getId());
	$inter->viewNewForm();
    exit();
}

// =================================================
//	              New intervention
// =================================================
if ($action == "detailsInter") {
	global $status;
    include_once(INCLUDEPATH . "mSelectBox.class.php");  

    $id="";
    if(isset($_GET["id"])) {
    	$id=$_GET["id"];
    }


	$inter = new Inter();
	$inter->setId($id);
	$inter->load();	
	$inter->viewDetails();
    exit();
}


// =================================================
//        Historic of the intervention on a bug
// =================================================
if ($action == "historic") {
	
	$tick->viewHistoric();
	exit();
}

// =================================================
//        Display the image
// =================================================
if ($action == "image") {
	
	echo $tick->getImage();
	exit();
}
if(isset($_POST["_owner"])) {
	$ownersb = (int)$_POST["_owner"];
} else {
	$ownersb = -1;
}
if(isset($_POST["_assigned"])) {
	$assignedUsersb = (int)$_POST["_assigned"];
} else {
	$assignedUsersb = -1;
}
if(isset($_POST["_priority"])) {
	$prioritysb = (int)$_POST["_priority"];
} else {
	$prioritysb = -1;
}
if(isset($_POST["_severity"])) {
	$severitysb = (int)$_POST["_severity"];
} else {
	$severitysb = -1;
}
if(isset($_POST["_resolution"])) {
	$resolutionsb = (int)$_POST["_resolution"];
} else {
	$resolutionsb = -1;
}
  

$tick->viewList($ownersb, $assignedUsersb, $prioritysb, $severitysb, $resolutionsb);
?>