Exemple #1
0
function prehlad_zadani($zverejnene)
{
    if ($link = db_connect()) {
        if ($zverejnene) {
            $sql = "SELECT * FROM assignments a INNER JOIN texts t ON a.text_id_name = t.text_id WHERE begin <= NOW() AND end > NOW()";
            $nadpis = "published-assignments";
        } else {
            $sql = "SELECT * FROM assignments a INNER JOIN texts t ON a.text_id_name = t.text_id WHERE begin > NOW() OR begin is NULL";
            $nadpis = "unpublished-assignments";
        }
        $result = mysqli_query($link, $sql);
        if ($result) {
            ?>
			<div id="prehlad_zadani">
			<p>
			<form method="post">
				<h2 data-trans-key="<?php 
            echo $nadpis;
            ?>
"></h2>
				<table>
				<?php 
            while ($row = mysqli_fetch_assoc($result)) {
                $eng = is_null($row['eng']) ? $row['sk'] : $row['eng'];
                echo "<tr>";
                if (isUserTypeLogged("Administrator") || isUserTypeLogged("Jury") && $zverejnene == false) {
                    echo "<td><input type='radio' name='id' value='{$row['context_id']}'><br></td>\n";
                }
                echo "<td data-trans-lang='" . SK . "'><a href='assignment.php?id={$row['context_id']}'>{$row['sk']}</a></td>";
                echo "<td data-trans-lang='" . ENG . "'><a href='assignment.php?id={$row['context_id']}'>{$eng}</a></td>";
                ?>
						<td> <?php 
                if (isUserTypeLogged("Administrator") || isUserTypeLogged("Jury") && $zverejnene == false) {
                    if ($row['begin'] == "") {
                        echo "---";
                    } else {
                        echo $row['begin'];
                    }
                } else {
                    echo '<span data-trans-key="upload-by"></span>';
                }
                ?>
						</td>
						<td> <?php 
                if ($row['end'] == "") {
                    echo "---";
                } else {
                    echo $row['end'];
                }
                ?>
						</td>
						<?php 
                echo "</tr>";
            }
            if (isUserTypeLogged("Administrator")) {
                ?>
					<tr>
						<td> </td>
						<td data-trans-key="publish-date"> </td>
						<td> <input type='datetime-local' name='start' value="<?php 
                echo Date("Y-m-d") . "T" . Date("H:i");
                ?>
"> </td>
					</tr>
					<tr>
						<td> </td>
						<td data-trans-key="deadline-date"> </td>
						<td> <input type='datetime-local' name='stop' value="<?php 
                echo date('Y-m-d', strtotime(Date("Y-m-d") . ' + 14 days')) . "T23:59";
                ?>
"> </td>
						<td> <button type="submit" style="width:200px" formaction="prehladZadani.php?action=1" data-trans-key="publish-selected-assignment" id="publishAssignment" /> </td>
						
					 </tr>
					 <?php 
                if (!$zverejnene) {
                    ?>
						 <tr>
							<td> </td><td> </td><td> </td>
							<td> <button type="submit" style="width:200px" formaction="prehladZadani.php?action=2" data-trans-key="delete-selected-assignment" id="deleteAssignment" /> </td>
						 </tr>
						 <?php 
                }
            }
            if (isUserTypeLogged("Administrator") || isUserTypeLogged("Jury") && $zverejnene == false) {
                ?>
					<tr>
						<td> </td><td> </td><td> </td>
						<td> <button type="submit" style="width:200px" formaction="prehladZadani.php?action=3" data-trans-key="edit-selected-assignment" id="editAssignment" /> </td>
					 </tr>
					<?php 
            }
            ?>
				</table>
			</form>
			</p>
			</div>
			<?php 
            mysqli_free_result($result);
        } else {
            echoError('err-db-query-fail');
        }
        mysqli_close($link);
    } else {
        echoError('err-db-connection-fail');
    }
}
page_nav();
get_topright_form();
if (!isset($_SESSION["loggedUser"]) || $_SESSION["loggedUser"] == null) {
    dieWithError("err-not-logged-in");
}
if (get_class($_SESSION["loggedUser"]) == "Team") {
    dieWithError("err-add-assignment-rights");
}
$conn = db_connect();
if (isset($_GET["id"]) && !empty($_GET["id"])) {
    $sql_get_assignment = "SELECT * FROM assignments a, contexts c WHERE c.context_id = a.context_id AND c.context_id = " . $_GET["id"];
    $flag = false;
    $result = mysqli_query($conn, $sql_get_assignment);
    if ($result == true && mysqli_num_rows($result) != 0) {
        $assignment = new Assignment($conn, $_GET["id"]);
        if (!isUserTypeLogged("Administrator") && $_SESSION["loggedUser"]->getId() != $assignment->getAuthor()->getId()) {
            dieWithError("err-edit-assignment-rights");
        }
    } else {
        $assignment = new Assignment($conn, 0);
        $flag = true;
    }
    if (isset($_POST['checkbox'])) {
        $assignment->deleteAttachments($conn, $_POST['checkbox']);
    }
    if (isset($_POST['skName']) && $_POST['skName'] != $assignment->getSkName()) {
        $assignment->setSkName($conn, $_POST['skName']);
    }
    if (isset($_POST['engName']) && $_POST['engName'] != $assignment->getEngName()) {
        $assignment->setEngName($conn, $_POST['engName']);
    }
                        $result = mysqli_query($link, $sql);
                        if ($result && mysqli_num_rows($result) != 0 || isUserTypeLogged("Administrator")) {
                            ?>
 <meta http-equiv="refresh" content="0;url=addAssignment.php?id=<?php 
                            echo $_POST["id"];
                            ?>
"><?php 
                        } else {
                            echoError('err-edit-assignment-rights');
                        }
                        mysqli_close($link);
                    } else {
                        echoError('err-db-connection-fail');
                    }
                }
            }
        }
    }
}
if (isUserTypeLogged("Administrator") || isUserTypeLogged("Jury")) {
    prehlad_zadani(false);
    ?>
	<br>
	<form action="addAssignment.php">
		<input type="submit" data-trans-key="new-assignment">
	</form>
	<br>
	<?php 
}
prehlad_zadani(true);
page_footer();