<commit_before><? /*
Copyright 2008 <NAME>

This file is part of Fossfactory-src.

Fossfactory-src is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Fossfactory-src 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 Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with Fossfactory-src.  If not, see <http://www.gnu.org/licenses/>.
*/ ?>
<? 
include_once('formattext.php');
$parentid = $id;
// Get the project info
list($rc,$projinfo) = ff_getprojectinfo( $parentid);
if( $rc == 2) {
    print "No such project: $parentid";
    softexit();
}

//get subprojects of project 
list($rc,$subprojects) = ff_getsubprojects($parentid);
$totsubprojallot = 0;
foreach($subprojects as $subproject) $totsubprojallot +=$subproject['allotment']; 

if( sizeof($subprojects)) {
?>
<script>
function update_unallotedPercentage() { 
    i=1;
    html='';
    totalpercentage=0;
<? foreach($subprojects as $subproject) {?>


    if (!(document.form.elements['sub<?=$subproject['id']?>'].value<0 || isNaN(document.form.elements['sub<?=$subproject['id']?>'].value)))  {
        totalpercentage+=parseFloat(document.form.elements['sub<?=$subproject['id']?>'].value);
    }
<? } ?>
    totalpercentage = totalpercentage*10;
    totalpercentageObj = document.getElementById('totalpercentage');

    if (totalpercentage>1000) { 
        totalpercentageObj.style.color='#ff0000';
        totalpercentageObj.style.fontWeight='bold';         
        totalpercentageObj.style.marginBottom='1em';
        //we use this method b/c of 'floor' usage in 'money' function
        totalpercentageObj.innerHTML='-'+((totalpercentage-1000)/10)+'%';
        return true;
    } else {
        totalpercentageObj.style.color='';

        totalpercentageObj.style.color='';
        totalpercentageObj.style.fontWeight='';
        totalpercentageObj.style.marginBottom='';

        totalpercentageObj.innerHTML=((1000-totalpercentage)/10)+'%';
        return true;
    }
}

function checkAllot() {
    var total = 0;
    i=0; 
<? foreach( $subprojects as $id => $subproject) { ?>
        if(document.form.elements[i].value<0) {
            alert("Cannot have negative percentages");
            return false;
        } else if(isNaN(document.form.elements[i].value)) {
            alert("Please enter percentages in integers only");
            return false;
        }

        total = total + 10*document.form.elements[i].value;
        i++;
 <? } ?> 
    if (total<=1000) { 
        return true;
    } else {
        alert('Please enter a total allotment percentage at most 100%');
        return false;
    }
}
</script>
<form action="allotpost.php" name='form' method='post'>
<table width=100% border=1 cellpadding=5 cellspacing=0>
<tr bgcolor="#e0e0e0"><th>ID</th><th>Priority</th><th>Status</th><th>Project<br>Lead</th><th>Allotment</th><th>Bounty</th><th>Summary</th></tr>
<? foreach($subprojects as $subproject) { 
    $totalallotment+=$subproject['allotment']/10;
?>
    <tr>
        <td align=right valign=top><?=$subproject['status']==='complete'?'<del>':''?><a href="project.php?p=<?=$subproject['id']?>"><?=$subproject['id']?></a><?=$subproject['status']=='complete'?'</del>':''?></td>
        <td valign=top><?=$subproject['priority']?></td>
        <td valign=top><?=$subproject['status']?></td>
        <td valign=top><? if($subproject["lead"] !== '') { ?><a href="member.php?id=<?=urlencode($subproject['lead'])?>"><?=htmlentities($subproject['lead'])?></a><? } else { ?>(none)<? } ?></td>
        <td align=right valign=top><? if ($GLOBALS['username']==$projinfo['lead']) { ?> 
            <input type='textfield' name='sub<?=$subproject['id']?>' size='4' onChange="return update_unallotedPercentage()" maxLength='4' value='<?=($subproject['allotment'])/10?>'>
            <? } else { ?>
                <?=$subproject['allotment']/10?>
            <? } ?>%
        </td>
        <td align=right valign=top><?=htmlentities(format_money($subproject['bounty']))?></td>
        <td valign=top><?=ereg("^Bug [a-z0-9]*$",$subproject["name"])?formatText(ereg_replace("\n.*","",$subproject['reqmts'])):htmlentities($subproject["name"])?></td>
    </tr>
<?  
}
?>
</tr></table>
<? if ($GLOBALS['username']==$projinfo['lead']) { ?> 
<input type='hidden' name='id' value=<?=$parentid?>>
<input type='hidden' name='tab' value='subprojects'>
<p align='right'><input type='submit' name='submit' value='update allotments' onClick='return checkAllot()'></p>
<? } ?>
<hr height=1></hr>
<p align=right><b>Unalloted Percentage:</b><span id='totalpercentage'><?=(100-$totalallotment)?>%</span></p>
</form>
<p>
<a href="newbug.php?p=<?=$parentid?>">Report a bug</a>
</p>
<?
} else {
?>
<br>
<b>This project has no bugs/subprojects.</b>
<br>
<br><commit_msg>Shortened bounty formatting on the bugs tab.<commit_after><? /*
Copyright 2008 <NAME>

This file is part of Fossfactory-src.

Fossfactory-src is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Fossfactory-src 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 Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with Fossfactory-src.  If not, see <http://www.gnu.org/licenses/>.
*/ ?>
<? 
include_once('formattext.php');
$parentid = $id;
// Get the project info
list($rc,$projinfo) = ff_getprojectinfo( $parentid);
if( $rc == 2) {
    print "No such project: $parentid";
    softexit();
}

//get subprojects of project 
list($rc,$subprojects) = ff_getsubprojects($parentid);
$totsubprojallot = 0;
foreach($subprojects as $subproject) $totsubprojallot +=$subproject['allotment']; 

if( sizeof($subprojects)) {
?>
<script>
function update_unallotedPercentage() { 
    i=1;
    html='';
    totalpercentage=0;
<? foreach($subprojects as $subproject) {?>


    if (!(document.form.elements['sub<?=$subproject['id']?>'].value<0 || isNaN(document.form.elements['sub<?=$subproject['id']?>'].value)))  {
        totalpercentage+=parseFloat(document.form.elements['sub<?=$subproject['id']?>'].value);
    }
<? } ?>
    totalpercentage = totalpercentage*10;
    totalpercentageObj = document.getElementById('totalpercentage');

    if (totalpercentage>1000) { 
        totalpercentageObj.style.color='#ff0000';
        totalpercentageObj.style.fontWeight='bold';         
        totalpercentageObj.style.marginBottom='1em';
        //we use this method b/c of 'floor' usage in 'money' function
        totalpercentageObj.innerHTML='-'+((totalpercentage-1000)/10)+'%';
        return true;
    } else {
        totalpercentageObj.style.color='';

        totalpercentageObj.style.color='';
        totalpercentageObj.style.fontWeight='';
        totalpercentageObj.style.marginBottom='';

        totalpercentageObj.innerHTML=((1000-totalpercentage)/10)+'%';
        return true;
    }
}

function checkAllot() {
    var total = 0;
    i=0; 
<? foreach( $subprojects as $id => $subproject) { ?>
        if(document.form.elements[i].value<0) {
            alert("Cannot have negative percentages");
            return false;
        } else if(isNaN(document.form.elements[i].value)) {
            alert("Please enter percentages in integers only");
            return false;
        }

        total = total + 10*document.form.elements[i].value;
        i++;
 <? } ?> 
    if (total<=1000) { 
        return true;
    } else {
        alert('Please enter a total allotment percentage at most 100%');
        return false;
    }
}
</script>
<form action="allotpost.php" name='form' method='post'>
<table width=100% border=1 cellpadding=5 cellspacing=0>
<tr bgcolor="#e0e0e0"><th>ID</th><th>Priority</th><th>Status</th><th>Project<br>Lead</th><th>Allotment</th><th>Bounty</th><th>Summary</th></tr>
<? foreach($subprojects as $subproject) { 
    $totalallotment+=$subproject['allotment']/10;
?>
    <tr>
        <td align=right valign=top><?=$subproject['status']==='complete'?'<del>':''?><a href="project.php?p=<?=$subproject['id']?>"><?=$subproject['id']?></a><?=$subproject['status']=='complete'?'</del>':''?></td>
        <td valign=top><?=$subproject['priority']?></td>
        <td valign=top><?=$subproject['status']?></td>
        <td valign=top><? if($subproject["lead"] !== '') { ?><a href="member.php?id=<?=urlencode($subproject['lead'])?>"><?=htmlentities($subproject['lead'])?></a><? } else { ?>(none)<? } ?></td>
        <td align=right valign=top><? if ($GLOBALS['username']==$projinfo['lead']) { ?> 
            <input type='textfield' name='sub<?=$subproject['id']?>' size='4' onChange="return update_unallotedPercentage()" maxLength='4' value='<?=($subproject['allotment'])/10?>'>
            <? } else { ?>
                <?=$subproject['allotment']/10?>
            <? } ?>%
        </td>
        <td align=right valign=top><?=htmlentities(convert_money($subproject['bounty']))?></td>
        <td valign=top><?=ereg("^Bug [a-z0-9]*$",$subproject["name"])?formatText(ereg_replace("\n.*","",$subproject['reqmts'])):htmlentities($subproject["name"])?></td>
    </tr>
<?  
}
?>
</tr></table>
<? if ($GLOBALS['username']==$projinfo['lead']) { ?> 
<input type='hidden' name='id' value=<?=$parentid?>>
<input type='hidden' name='tab' value='subprojects'>
<p align='right'><input type='submit' name='submit' value='update allotments' onClick='return checkAllot()'></p>
<? } ?>
<hr height=1></hr>
<p align=right><b>Unalloted Percentage:</b><span id='totalpercentage'><?=(100-$totalallotment)?>%</span></p>
</form>
<p>
<a href="newbug.php?p=<?=$parentid?>">Report a bug</a>
</p>
<?
} else {
?>
<br>
<b>This project has no bugs/subprojects.</b>
<br>
<br>
{'fraction_non_alphanumeric': 0.1974814525575947, 'fraction_numerical': 0.013276064037485357, 'mean_word_length': 4.23237997957099, 'pattern_counts': {'":': 0, '<': 223, '<?xml version=': 0, '>': 221, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3551421', 'n_tokens_mistral': 3426, 'n_tokens_neox': 3294, 'n_words': 669}