Location: PHPKode > projects > BugIn and Ticketing System > bugin-0.65/inc/modify.inc.php
<?php

$upNum = 0;

$upNumField = 0;

// This is for the "owner" list...
$bugDatabase->lists['owner'] = $bugDatabase->lists['user'];
$bugDatabase->lists['owner'][0]['name'] = $bugDatabase->db->qstr($verbage['unowned']);
$ticket = $bugDatabase->getTicket($mod['num']);


// OK, We're taking the ticket!
if (isset($_REQUEST['take'])) {
	// Just taking ownership...
	echo "Taking ownership of ticket {$mod['num']}<br>\n";
	$update[$upNum]['modify'][$upNumField]['fieldName'] = "owner";
	$update[$upNum]['modify'][$upNumField]['fieldValue'] = $userinfo['uid'];
	$upNumField ++;
	$update[$upNum]['modify'][$upNumField]['fieldName'] = "status";
	$update[$upNum]['modify'][$upNumField]['fieldValue'] = $takeStatusNum;
	$mod['owner'] = $userinfo['uid'];
	$mod['modification'] = "** {$userinfo['name']}{$verbage['mod_taken_owner']}\n".$mod['modification'];
	$mod['modification'] = "{$verbage['mod_status_setto']}{$bugDatabase->lists['status'][$takeStatusNum]['name']}\n".$mod['modification'];
	$upNumField ++;
	$upNum ++;
}
elseif (isset($_REQUEST['save'])) {
	buginError("Modifiying {$options['ticketName']}", 2);
	// Modifiying a ticket, need to get the ticket to compare fields and update as necessairy...

	while (list($key, $value) = each($mod)) {
		if (($key != "modification") && ($key != "num") && isset($ticket[$key]) && (bugin_eval($mod[$key], $ticket[$key]))) {
			$noChange = 0;
			if (array_key_exists($key, $bugDatabase->lists['field'])) {
				$ticketname = $bugDatabase->lists['field'][$key]['name'];
				switch( $bugDatabase->lists['field'][$key]['type']) {
					case "datetime":
					case "timestamp":
						$mod[$key] = strtotime($mod[$key]);
						$modname = date($options['dateFormat'], $mod[$key]);
						$ticketname = date($options['dateFormat'], strtotime($ticket[$key]));
						if ($modname != $ticketname) {
							$update[$upNum]['modify'][$upNumField]['fieldName'] = $key;
							$update[$upNum]['modify'][$upNumField]['fieldValue'] = $bugDatabase->db->DBTimeSTamp($mod[$key]);
							$upNumField ++;
						}
						else
							$noChange = 1;
						break;
				}
			}
			else {
				$upNameList = $bugDatabase->lists[$key];
				if (isset($upNameList)) {
					$modname = $upNameList[$mod[$key]]['name'];
					$ticketname = $upNameList[$ticket[$key]]['name'];
				}
				else {
					$modname = $mod[$key];
					$ticketname = $ticket[$key];
				}
				$update[$upNum]['modify'][$upNumField]['fieldName'] = $key;
				$update[$upNum]['modify'][$upNumField]['fieldValue'] = $bugDatabase->db->qstr($mod[$key]);
				$upNumField ++;
			}
			
			if (!$noChange) {
				$mod['modification'] = "** $key{$verbage['mod_change_1']}\"{$ticketname}\"{$verbage['mod_change_2']}\"{$modname}\"{$verbage['mod_change_3']}\n".$mod['modification'];
				buginError("<b>$key</b> changed to \"{$modname}\" from \"{$ticketname}\" ({$mod[$key]},{$ticket[$key]})", 2);
			}

		}
	}

}

// Update the DB if we need to.
if (strlen($mod['modification'])) {
	buginError("Modifiying Ticket: Adding ticket timestamp", 1);
	$update[$upNum]['modify'][$upNumField]['fieldName'] = "date_modified";
	$update[$upNum]['modify'][$upNumField]['fieldValue'] = $bugDatabase->db->DBTimeSTamp(time());
	$upNumField = 0;
	$upNum ++;

	// Word wrap the modification, ok?
	$mod['modification'] = wordwrap($mod['modification']);
	// Set the update information...  here we go!
	$update[0]['action'] = "change";
	$update[0]['tableName'] = "tickets";
	$update[0]['uniqueRow'] = "id";
	$update[0]['rowid'] = $mod['num'];

	buginError("Modifiying Ticket #{$mod['num']}", 1);

	$update[$upNum]['action'] = "add";
	$update[$upNum]['tableName'] = "modifications";

	// The last modification is pretty standard....
	$update[$upNum]['modify'][0]['fieldName'] = "uid";
	$update[$upNum]['modify'][0]['fieldValue'] = $userinfo['uid'];
	$update[$upNum]['modify'][1]['fieldName'] = "text";
	$update[$upNum]['modify'][1]['fieldValue'] = $bugDatabase->db->qstr($mod['modification']);
	$update[$upNum]['modify'][2]['fieldName'] = "ts";
	$update[$upNum]['modify'][2]['fieldValue'] = $bugDatabase->db->DBTimeStamp(time());
	$update[$upNum]['modify'][3]['fieldName'] = "ticket_id";
	$update[$upNum]['modify'][3]['fieldValue'] = $mod['num'];
	$bugDatabase->alterDb($update);

	$newTicket = $bugDatabase->getTicket($ticket['id']);

	if (isset($alsoNotify))
		$ticket['alsoNotify'] = $alsoNotify;

	$run = runTriggers(TRIGGER_FLAG_MODIFY, $ticket, $mod);
	if (isset($run['notifyList']))
		$_SESSION['message'] = runNotify($ticket, $newTicket, $run['mod'], $run['notifyList']);
}
else {
	$_SESSION['message'] = "{$verbage['no_modifications_for']} {$options['ticketName']} #{$mod['num']}.";
}
echo <<<EOT

<script language="javascript">
window.location.replace="{$options['baseURL']}/?area=view&num={$mod['num']}";
</script>

EOT;
?>
Return current item: BugIn and Ticketing System