<?php
defined('DOIT') or die('Restricted access');
function overview($submit,$process,$mod_bugtrap,$mod_bugtrap_states,$mod_bugtrap_severities) {
global $page,$settings,$mysession,$is_admin,$l_gen;
$page->query('select * from mod_bugtrap where `mainmodid`='.intval($page->id).' order by state,insertdate desc');
$buglist = $page->db->getdata_array();
echo '<h1>'.$page->name.'</h1><div class="bugtrap_overview">';
//progress
if (is_array($buglist) && !empty($buglist)) {
$num_tickets = sizeof($buglist);
$done = 0;
foreach($buglist as $bug) {
if ($bug['state']==3 or $bug['state']==4) { $done++; }
}
$percentdone = round($done/$num_tickets*100);
echo '<div class="bugtrap_progress">'.
'<span>'.$mod_bugtrap['lbl_progress'].':</span>'.
'<div class="bugtrap_progressbar">'.
'<div class="bugtrap_progress_done" style="width:'.$percentdone.'%;"></div>'.
'</div>'.
'</div>';
}
//project end
if (strtotime($settings[1]) > strtotime('now')) {
$endclass = 'ok';
} else {
$endclass = 'overdue';
}
//time left
$secondsleft = strtotime($settings[1])-strtotime('now');
$years = floor($secondsleft / (31536000));
$months = floor(($secondsleft - $years * 31536000) / (2592000));
$weeks = floor(($secondsleft - $years * 31536000 - $months*2592000) / (604800));
$days = floor(($secondsleft - $years * 31536000 - $months*2592000 - $weeks*604800)/ (86400));
$hours = floor(($secondsleft - $years * 31536000 - $months*2592000 - $weeks*604800 - $days*86400)/ (3600));
$minutes = floor(($secondsleft - $years * 31536000 - $months*2592000 - $weeks*604800 - $days*86400 - $hours*3600)/ (60));
$seconds = floor($secondsleft - $years * 31536000 - $months*2592000 - $weeks*604800 - $days*86400 - $hours*3600 -$minutes*60);
$leftstring = "$months ".$mod_bugtrap['lbl_months']." $weeks ".$mod_bugtrap['lbl_weeks'].
" $days ".$mod_bugtrap['lbl_days']." $hours h $minutes min $seconds s";
echo '<p><span class="bugtrap_end_'.$endclass.'" title="'.$mod_bugtrap['lbl_projectend'].
'"></span>'.$settings[1].'<br />'.$leftstring.' '.$mod_bugtrap['lbl_left'].'</p><br />'.
'<strong>'.$mod_bugtrap['lbl_desc'].':</strong><br />'.str_replace("\n",'<br />',$page->content).'<br /><br />'.
'</div>'.
'<div class="bugtrap_allactions">';
//actions
if ($is_admin) {
$whichbugs = $mod_bugtrap_states;
$whichbugs[-1] = $mod_bugtrap['lbl_all'];
ksort($whichbugs);
$actions = $mod_bugtrap_states;
$actions[-1] = $mod_bugtrap['lbl_delete'];
ksort($actions);
echo '<div class="bugtrap_actions">'.
'<form method="post" action="">'.
'<input type="hidden" name="task" value="overview" />'.
'<select name="whichbugs" class="bugtrap_actions">';
foreach($whichbugs as $n=>$wb) {
echo '<option value="'.$n.'">'.$wb.'</option>';
}
echo '</select>'.
'<span class="bugtrap_arrow"></span>'.
'<select name="action" class="bugtrap_actions">';
foreach($actions as $n=>$a) {
echo '<option value="'.$n.'">'.$a.'</option>';
}
echo '</select>'.
'<input type="submit" value="'.$l_gen['lbl_go'].'" />'.
'</form></div>';
}
//new ticket
if ($submit && $settings[0]=='1') {
echo '<form method="post" action="">'.
'<input type="hidden" name="task" value="detail" />'.
'<input type="hidden" name="bugid" value="0" />'.
'<span class="bugtrap_newticket"></span>'.
'<input type="submit" class="bugtrap_newticket" value="'.$mod_bugtrap['lbl_newticket'].'" />'.
'</form>';
}
echo '</div>';
if (is_array($buglist) && !empty($buglist)) {
echo '<ul class="bugtrap_buglist">';
foreach ($buglist as $bug) {
if (strlen($bug['name'])>30) {
$bugname = substr($bug['name'],0,30).'...';
} else {
$bugname = $bug['name'];
}
if (strlen($bug['description'])>30) {
$bugdesc = substr($bug['description'],0,30).'...';
} else {
$bugdesc = $bug['description'];
}
if (intval($bug['severity'])>=4) {
$importantspan = '<span class="bugtrap_important" title="'.
$mod_bugtrap_severities[$bug['severity']].'"></span>';
} else {
$importantspan = '';
}
if (intval($bug['responsible'])==$mysession->user->uid) {
$myspan = '<span class="bugtrap_mybug" title="'.$mod_bugtrap['lbl_mybug'].'"></span>';
} else {
if ($process) {
$tooltip = $mod_bugtrap['lbl_sebug'];
} else {
$tooltip = $mod_bugtrap['lbl_seassigned'];
}
if (intval($bug['responsible'])>0) {
$myspan = '<span class="bugtrap_sebug" title="'.$tooltip.'"></span>';
} else {
$myspan = '';
}
}
echo '<li class="state'.$bug['state'].'">'.$myspan.$importantspan.
'<span class="bugtrap_name">'.$bugname.'</span>'.
'<span class="bugtrap_time">'.date('d.m.Y, H:i:s',strtotime($bug['insertdate'])).'</span>'.
'<span class="bugtrap_desc">'.$bugdesc.'</span>'.
'<div class="bugtrap_editdiv">';
if ($process) {
echo '<form method="post" action="">'.
'<input type="hidden" name="task" value="detail" />'.
'<input type="hidden" name="detailmode" value="edit" />'.
'<input type="hidden" name="bugid" value="'.$bug['id'].'" />'.
'<input type="submit" class="bugtrap_edit" title="'.$mod_bugtrap['tip_edit'].'" />'.
'</form>';
} else {
echo '<form method="post" action="">'.
'<input type="hidden" name="task" value="detail" />'.
'<input type="hidden" name="detailmode" value="view" />'.
'<input type="hidden" name="bugid" value="'.$bug['id'].'" />'.
'<input type="submit" class="bugtrap_view" title="'.$mod_bugtrap['tip_view'].'" />'.
'</form>';
}
echo '</div>'.
'</li>';
}
echo '</ul>';
} else {
echo '<p>'.$mod_bugtrap['lbl_noneyet'].'</p>';
}
echo '<div class="bugtrap_legend"><span>'.$mod_bugtrap['lbl_legend'].':</span><ul class="bugtrap_legend">';
foreach ($mod_bugtrap_states as $n=>$s) {
echo '<li class="state'.$n.'">'.$s.'</li>';
}
echo '</ul></div>';
}
function detail($bugid,$submit,$process,$mod_bugtrap,$mod_bugtrap_states,$mod_bugtrap_types,$mod_bugtrap_severities,$errors) {
global $page,$is_admin,$mysession,$l_gen,$settings;
$post = escape($_POST);
$bug = new Bug();
//reload
echo '<form action="" method="post">'.
'<input type="submit" value="'.$l_gen['lbl_reload'].'" class="floatright">'.
'<input type="hidden" name="task" value="detail">'.
'<input type="hidden" name="bugid" value="'.$bugid.'">'.
'</form>'.
//back
'<form action="" method="post">'.
'<input type="submit" value="'.$l_gen['lbl_back'].'" class="floatright">'.
'<input type="hidden" name="task" value="overview">'.
'</form>'.
//save
'<form action="" method="post">'.
'<input type="submit" value="'.$l_gen['lbl_save'].'" class="floatright">'.
'<h1>'.$page->name.'</h1>'.
'<h3>';
$doit = false;
//existing ticket
if ($bugid>0) {
$doit = true;
if ($process) { echo $mod_bugtrap['tip_edit']; } else { echo $mod_bugtrap['tip_view']; }
$bug->load($bugid);
//new ticket
} elseif ($bugid<=0 && $settings[0]=='1') {
$doit = true;
echo $mod_bugtrap['lbl_newticket'];
}
if ($doit) {
echo '</h3><table class="bugtrap_detailtable">';
if ($bugid>0) {
echo '<tr><td>ID</td><td>'.$bugid.'</td></tr>';
}
//name
if ($bugid==0 or $process) {
if ($bug->name == '') { $bug->name = $post['bug_name']; }
echo '<tr><td>Name</td><td><input type="text" name="bug_name" value="'.$bug->name.'" maxlength="40"';
if (in_array('name',$errors)) { echo ' class="wrong"'; }
echo ' /></td></tr>';
} else {
echo '<tr><td>Name</td><td>'.$bug->name.'</td></tr>';
}
//state
echo '<tr><td>'.$mod_bugtrap['lbl_state'].'</td><td>';
if ($process) {
echo '<select size="1" name="bug_state">';
foreach ($mod_bugtrap_states as $nr=>$s) {
echo '<option value="'.$nr.'"';
if ($nr==$bug->state) { echo ' selected="selected"'; }
echo '>'.$s.'</option>';
}
echo '</select>';
} else {
if ($bugid>0) {
echo $mod_bugtrap_states[$bug->state].
'<input type="hidden" name="bug_state" value="'.$bug->state.'">';
} else {
echo $mod_bugtrap_states[1];
}
}
echo '</td></tr>';
//submitted by
if ($bugid==0) {
echo '<input type="hidden" name="bug_reporter" value="'.$bug->reporter.'">';
} else {
echo '<tr><td>'.$mod_bugtrap['lbl_reporter'].'</td><td>'.$bug->reporter_name.'</td></tr>';
}
//responsible programmer
echo '<tr><td>'.$mod_bugtrap['lbl_responsible'].'</td><td>';
$responsibles = array(0=>$mod_bugtrap['lbl_nobody']);
$page->query('select * from system_users');
$allusers = $page->db->getdata_array();
//get groups
$page->query('select * from system_groups');
$allgroups = $page->db->getdata_array();
$pageaccess = explode(',',$page->specialaccess);
$writeaccess = array();
//get only write access groups
foreach ($allgroups as $g) {
if (in_array($g["gid"],$pageaccess)) {
if (isset($g["write"]) && $g["write"]==1) {
$writeaccess[]=$g["gid"];
}
}
}
foreach($allusers as $u) {
$thisgids = explode(',',$u['gids']);
//user is an admin
if (in_array(1,$thisgids)) {
$responsibles[$u['uid']] = $u['name'];
} else {
//user is in a special write group
foreach ($writeaccess as $sa) {
if (in_array($sa,$thisgids)) {
$responsibles[$u['uid']] = $u['name'];
}
}
}
}
if ($process) {
if ($is_admin) {
//admin: get possible responsibles and make dropdown
//show all responsible users
echo '<select size="1" name="bug_responsible">';
foreach ($responsibles as $r=>$name) {
echo '<option value="'.$r.'"';
if ($bug->responsible==$r) { echo ' selected="selected"'; }
echo '>'.$name.'</option>';
}
echo '</select>';
} else {
//user with write right: if nobody is assigned show self-assign
if ($bug->responsible==0) {
echo $mod_bugtrap['lbl_nobodyyet'].'<br />'.
'<input type="checkbox" name="bug_assign" value="bug_assign" />'.
$mod_bugtrap['lbl_assign'];
} else {
//--if the user himself is assigned show resign
if ($bug->responsible==$mysession->user->uid) {
echo 'You<br />'.
'<input type="checkbox" name="bug_resign" value="bug_resign" />'.
$mod_bugtrap['lbl_resign'];
//--if somebody else is assigned just show his name
} else {
echo $responsibles[$bug->responsible];
}
}
}
} else {
//show responsible programmer if there is one
echo $responsibles[$bug->responsible];
}
echo '</td></tr>';
//type
echo '<tr><td>'.$mod_bugtrap['lbl_type'].'</td><td>';
if ($process or $bugid==0) {
echo '<select size="1" name="bug_type">';
foreach ($mod_bugtrap_types as $nr=>$t) {
echo '<option value="'.$nr.'"';
if ($nr==$bug->type) { echo ' selected="selected"'; }
echo '>'.$t.'</option>';
}
echo '</select>';
} else {
echo $mod_bugtrap_types[$bug->type];
}
echo '</td></tr>'.
//severity
'<tr><td>'.$mod_bugtrap['lbl_severity'].'</td><td>';
if ($process or $bugid==0) {
echo '<select size="1" name="bug_severity">';
foreach ($mod_bugtrap_severities as $nr=>$s) {
echo '<option value="'.$nr.'"';
if ($nr==$bug->severity) { echo ' selected="selected"'; }
echo '>'.$s.'</option>';
}
echo '</select>';
} else {
echo $mod_bugtrap_severities[$bug->severity];
}
echo '</td></tr>'.
//description
'<tr><td>'.$mod_bugtrap['lbl_bugdesc'].'</td><td>';
if ($process or $bugid==0) {
if ($bug->description == '') { $bug->description = $post['bug_description']; }
echo '<textarea name="bug_description" rows="5" cols="50"';
if (in_array('description',$errors)) { echo ' class="wrong"'; }
echo '>'.$bug->description.'</textarea>';
} else {
echo $bug->description;
}
echo '</td></tr>';
//comment
if ($bugid>0) {
if ($process or trim($bug->comment)!='') {
echo '<tr><td>'.$mod_bugtrap['lbl_comment'].'</td><td>';
if ($process) {
echo '<input type="text" name="bug_comment" value="'.$bug->comment.'" maxlength="255"/>';
} elseif (!$process && trim($bug->comment)!='') {
echo $bug->comment;
}
echo '</td></tr>';
}
}
//dialogue
if ($bugid>0) {
echo '<tr><td>'.$mod_bugtrap['lbl_dialogue'].'</td><td>'.
'<textarea name="bug_dialogue" cols="50" rows="3"></textarea>';
if (is_array($bug->dialogue) && sizeof($bug->dialogue)>0) {
foreach ($bug->dialogue as $d) {
if (is_array($d) && !empty($d)) {
//each response
echo '<div class="bugtrap_statement">'.
'<p class="bugtrap_statementheader">';
if ($d['id']==$bug->responsible) {
echo '<span class="bugtrap_mybug" title="Responsible person"></span>';
} else {
echo '<span class="bugtrap_comment"></span>';
}
echo'<strong>'.$d['uname'].'</strong>, '.
'<em>'.date('d.m.Y, H:i:s',strtotime($d['date'])).'</em></p>'.
'<p>'.$d['statement'].'</p>'.
'</div>';
}
}
}
echo '</td></tr>';
}
echo '</table>'.
'<input type="hidden" name="task" value="detail">'.
'<input type="hidden" name="action" value="save">';
if ($bugid>0) {
echo '<input type="hidden" name="bugid" value="'.$bug->id.'">';
} else {
echo '<input type="hidden" name="bugid" value="'.$bug->id.'">';
}
echo '</form>';
}
}
?>