Location: PHPKode > projects > chillyCMS > chillyCMS/modules/bugtrap/bugtrap.php
<?php
defined('DOIT') or die('Restricted access');

require_once(PATH.'/modules/bugtrap/bug.class.php');
require_once(PATH.'/modules/bugtrap/bugtrap.include.php');

$tsa = explode(',',$this->specialaccess);

//who is allowed to submit tickets?
$submit = false;
if ($this->access == 0) {
	$submit = true;
} elseif ($this->access == 1 && ($is_user or $is_admin)) {
	$submit = true;
} elseif ($this->access == 2) {
	if ($is_admin) {
		$submit = true;
	} else {
	//check special rights of read groups, the user might be in
		foreach ($tsa as $a) {
			if ($mysession->user->gids_assoc[$a] == 'r') { $submit = true; break; }
		}
	}
	foreach($tsa as $ag) {
		if (in_array($ag,$mysession->user->gids)) { $submit = true; break; }
	}
}

//who is allowed to process the tickets?
$process = false;
if ($is_admin) { $process = true; }
foreach ($tsa as $a) {
	if (isset($mysession->user->gids_assoc[$a]) && $mysession->user->gids_assoc[$a] == 'w') { $process = true; break; }
}

$settings = explode(',',$this->settings);

echo '<div class="bugtrap">';

//what task??
if (isset($_POST['task']) && $_POST['task']=='detail') { $mytask = 'detail'; } else { $mytask = 'overview'; }

$errors = array();

//do something
if (isset($_POST['action']) && isset($_POST['whichbugs']) && $is_admin) {
	$whichbugs = intval($_POST['whichbugs']);
	$action = intval($_POST['action']);
	
	//all bugs
	if ($whichbugs==-1) {
		$where = ' where `mainmodid`='.$this->id;
	//some bugs
	} elseif ($whichbugs>0) {
		$where = ' where `mainmodid`='.$this->id.' and `state`='.$whichbugs;
	//no bugs
	} else {
		$where = ' where true=false';
	}
	
	//delete
	if ($action==-1) {
		$what = 'delete from mod_bugtrap';
	//change state
	} elseif ($action>0) {
		$what = "update mod_bugtrap set `state`=".$action;
	//do nothing
	} else {
		$what = 'select * from mod_bugtrap';
	}
	
	$sql = $what.$where;
	if ($this->query($sql)) {
		echo msg($mod_bugtrap["lbl_actiondone"],'good');
	} else {
		echo msg($mod_bugtrap["lbl_action_err"],'bad');
	}
}

//save bug
if (isset($_POST['action']) && $_POST['action']=='save') {

	$post = escape($_POST);
	$bugid = intval($_POST['bugid']);
	$bugname = $post['bug_name'];
	$bugstate = intval($_POST['bug_state']);
	$bugtype = intval($_POST['bug_type']);
	$bugdesc = $post['bug_description'];
	$bugcomm = $post['bug_comment'];
	$bugdial = $post['bug_dialogue'];
	$bugresp = intval($_POST['bug_responsible']);
	$bugsev = intval($_POST['bug_severity']);
	
	if ($bugresp==0) { $bugresp = 'null'; }
	
	$bug = new Bug();
	if ($bugid>0) { $bug->load($bugid); $savetype = 'update'; } else { $savetype = 'insert'; }
	//check values
	//--dialogue
	if (isset($_POST['bug_dialogue']) && $_POST['bug_dialogue']!='') {
		if ($mysession->user->name && $mysession->user->name!='') {
			$uname = $mysession->user->name;
		} else {
			$uname = $mod_bugtrap['lbl_guest'];
		}
		$bugdialogue = array('bugid'=>$bug->id,'uname'=>$uname,'date'=>date('Y-m-d H:i:s'),'statement'=>$bugdial);
	} else {
		$bugdialogue = false;
	}
	if (!$bugdesc or $bugdesc == '') { if ($bugid==0) { $errors[] = 'description'; } else { $bugdesc = $bug->description; } }
	if (!$bugname or $bugname == '') { if ($bugid==0 or $process) { $errors[] = 'name'; } else { $bugname = $bug->name; } }
	if (!$bugstate or $bugstate == '') { $bugstate = $bug->state; }
	if (!$bugtype or $bugtype == '') { $bugtype = $bug->type; }
	if (!isset($_POST['bug_responsible'])) { $bugresp = $bug->responsible; }
	//if status was changed from new to in progress change responsible (not null)!!!
	if ($bugstate>=2 && $bugstate<=4) {
		if ($bugresp==0) { $errors[] = 'responsible'; }
	}
	//user assigned
	if (isset($post['bug_assign']) && $post['bug_assign']=='bug_assign') {
		$sa = explode(',',$this->specialaccess);
		$doit = false;
		foreach ($sa as $a) {
			if ($mysession->user->gids_assoc[$a]=='w') {
				$doit = true;
			}
		}
		if ($doit) { $bugresp = intval($mysession->user->uid); }
	}
	
	//user resigned
	if (isset($post['bug_resign']) && $post['bug_resign']=='bug_resign') {
		if ($bug->responsible==$mysession->user->uid) {
			$bugresp = 0;
		}
	}
	
	//if status was changed to closed, comment must not be null TODO
	if (empty($errors)) {
		$bug->fill($this->id,$bugname,$bugstate,$bugtype,$bugdesc,$bugcomm,$bugdialogue,$bugresp,$bugsev);
		if ($bug->store($savetype)) {
			$mytask = 'overview';
			echo msg($mod_bugtrap["lbl_save_ok"],'good');
		} else {
			$mytask = 'detail';
			echo msg($mod_bugtrap["lbl_save_err"],'bad');
		}
	} else {
		$mytask = 'detail';
	}
}
if ($mytask == 'detail') {
	$bugid = intval($_POST['bugid']);
	detail($bugid,$submit,$process,$mod_bugtrap,$mod_bugtrap_states,$mod_bugtrap_types,$mod_bugtrap_severities,$errors);
} else {
	overview($submit,$process,$mod_bugtrap,$mod_bugtrap_states,$mod_bugtrap_severities);
}

echo '</div>';

?>
Return current item: chillyCMS