<?php session_start(); ?>
    <!DOCTYPE html>
    <html>

    <head>
        <?php include 'includes/meta.php'; ?>
    </head>

    <body>
        <?php include 'includes/header.php'; ?>
        <?php
        include_once  'includes/inter.php';
		
		$permissions=array(FALSE,FALSE,FALSE,FALSE);
		$connected = isConnected();
		$owner = FALSE;
		$adminLevel=-1;
		
        $data = array();
		if(isset($_GET['id']) && isset($_GET['v'])){
			$data = getProjectVersionData($_GET['id'],$_GET['v']);
			if($data != NULL){
				$permissions = getPermissions($data);
			}else{
				header('Location:40A.php');
				goto end;
			}
		}else{
			header('Location:40A.php');
			goto end;
		}
		if($connected)
			$owner = preg_match('#[^0-9]?' . $_SESSION['session_id'] .'[^0-9]?#',$data ['owners']);
			$adminLevel = getAdminLevel();
		if($permissions[0] || $owner){
			?>

                <h1>Le projet <?php echo($data['name']) ?> en version <?php echo($data['version']) ?></h1>
                <br/>
                <?php if($data['language'] == 0){?>
                    <a class="project_option" href=<?php if($permissions[1] OR $owner OR $adminLevel>12){ echo( '"megaProcess/downloadJar.php?id='. $data[ 'pID'] . '&amp;v='. $data[ 'versionAbs'] . '"');}else{ echo( "\"#\"");} ?>>
				<img class="project_option_img<?php if(!$permissions[1] OR $owner OR $adminLevel>12){echo(" disabeled");} ?>" alt="T&eacute;l&eacute;charger le jar" title="T&eacute;l&eacute;charger le jar" src="pictures/download_jar.png"/>
				</a>
                    <a class="project_option" href=<?php if($permissions[2] OR $owner OR $adminLevel>12){ echo( '"megaProcess/viewJavaSrc.php?id='. $data[ 'pID'] . '&amp;v='. $data[ 'versionAbs'] . '"');}else{ echo( "\"#\"");} ?>>
				<img class="project_option_img<?php if(!$permissions[2] OR $owner OR $adminLevel>12){echo(" disabeled");} ?>" alt="Voir la source" title="Voir la source" src="pictures/view_code.png"/>
				</a>
                    <a class="project_option" href=<?php if($permissions[2] OR $owner OR $adminLevel>12){ echo( '"megaProcess/downloadJavaSrc.php?id='. $data[ 'pID'] . '&amp;v='. $data[ 'versionAbs'] . '"');}else{ echo( "\"#\"");} ?>>
				<img class="project_option_img<?php if(!$permissions[2] OR $owner OR $adminLevel>12){echo(" disabeled");} ?>" alt="T&eacute;l&eacute;charger la source" title="T&eacute;l&eacute;charger la source" src="pictures/download_code.png"/>
				</a>
                    <a class="project_option" href=<?php if($permissions[3] OR $owner OR $adminLevel>12){ echo( '"megaProcess/viewJavadoc.php?id='. $data[ 'pID'] . '&amp;v='. $data[ 'versionAbs'] . '"');}else{ echo( "\"#\"");} ?>>
				<img class="project_option_img<?php if(!$permissions[3] OR $owner OR $adminLevel>12){echo(" disabeled");} ?>" alt="Voir la doc" title="Voir la doc" src="pictures/view_javadoc.png"/>
				</a>
                    <a class="project_option" href=<?php if($permissions[3] OR $owner OR $adminLevel>12){ echo( '"megaProcess/downloadJavadoc.php?id='. $data[ 'pID'] . '&amp;v='. $data[ 'versionAbs'] . '"');}else{ echo( "\"#\"");} ?>>
				<img class="project_option_img<?php if(!$permissions[3] OR $owner OR $adminLevel>12){echo(" disabeled");} ?>" alt="T&eacute;lecharger la doc" title="T&eacute;lecharger la doc" src="pictures/download_javadoc.png"/>
				</a>

                    <br/>
                    <?php }else if($data['language'] == 1){?>
                        <a class="project_option" href=<?php if($permissions[1] OR $owner OR $adminLevel>12){ echo( '"megaProcess/downloadXlsm.php?id='. $data[ 'pID'] . '&amp;v='. $data[ 'versionAbs'] . '"');}else{ echo( "\"#\"");} ?>>
				<img class="project_option_img<?php if(!$permissions[1] OR $owner OR $adminLevel>12){echo(" disabeled");} ?>" alt="T&eacute;l&eacute;charger le xlsm" title="T&eacute;l&eacute;charger le xlsm" src="pictures/download_xlsm.png"/>
				</a>
                        <a class="project_option" href=<?php if($permissions[2] OR $owner OR $adminLevel>12){ echo( '"megaProcess/viewVbSrc.php?id='. $data[ 'pID'] . '&amp;v='. $data[ 'versionAbs'] . '"');}else{ echo( "\"#\"");} ?>>
				<img class="project_option_img<?php if(!$permissions[2] OR $owner OR $adminLevel>12){echo(" disabeled");} ?>" alt="Voir la source" title="Voir la source" src="pictures/voir_vb.png"/>
				</a>
                        <a class="project_option" href=<?php if($permissions[2] OR $owner OR $adminLevel>12){ echo( '"megaProcess/downloadVbSrc.php?id='. $data[ 'pID'] . '&amp;v='. $data[ 'versionAbs'] . '"');}else{ echo( "\"#\"");} ?>>
				<img class="project_option_img<?php if(!$permissions[2] OR $owner OR $adminLevel>12){echo(" disabeled");} ?>" alt="T&eacute;l&eacute;charger la source" title="T&eacute;l&eacute;charger la source" src="pictures/download_vb.png"/>
				</a>
                        <?php } ?>

                            <br/>
                            <br/>
                            <h3>Toutes les versions :</h3>
                            <br/>
                            <?php 
                            	$versions = getVersions($_GET ['id']);
                            	?>
                            <?php if(count($versions[0]) > 0){?>
                            <table class="versionTable">
                          		<tr>
                          			<th>Java</th>
                          		</tr>
                          		<?php foreach ($versions[0] as $version){  ?>
                          		<tr><td><a href = "projet.php?id=<?php echo $_GET['id']?>&amp;v=<?php echo $version['versionAbs'];?>"><?php echo $version['versionName'] ?></a></td></tr>
                          		<?php }?>
                            </table>
                           <?php }?>
                            
                           <?php if(count($versions[1]) > 0){?>
                            <table class="versionTable">
                          		<tr>
                          			<th>VBA</th>
                          		</tr>
                          		<?php foreach ($versions[1] as $version){  ?>
                          		<tr><td><a href = "projet.php?id=<?php echo $_GET['id']?>&amp;v=<?php echo $version['versionAbs'];?>"><?php echo $version['versionName'] ?></a></td></tr>
                          		<?php }?>
                            </table>
                            <?php }?>
                            
                            <br/>
                            <br/>
                            <?php if($owner){ ?>
                            <a href="newVersion.php?id=<?php echo $_GET['id'];?>">Nouvelle version</a><br/>
                            <a href="editVersion.php?id=<?php echo $_GET['id'];?>&amp;v=<?php echo $_GET['v'];?>">Modifier la version</a><br/>
                            <a href="delVersion.php?id=<?php echo $_GET['id'];?>&amp;v=<?php echo $_GET['v'];?>">Supprimer la version</a><br/>
                            <a href="editProject.php?id=<?php echo $_GET['id'];?>">Modifier le projet</a><br/>
                            <a href="delProject.php?id=<?php echo $_GET['id'];?>">Supprimer le projet</a><br/>
		<?php }  ?>
      <?}else{
			header('Location:403.php');
			goto end;
		}?>


                                <?php
		end:	
		?>
                                    <?php include 'includes/footer.php'; ?>
    </body>

    </html>