ACC SHELL
<?php
function load_datevalidation_script()
{
echo "<script type=\"text/javascript\" src=\"datevalidation.js\" ></script>";
}
function jobs_print_user($user_id)
{
$query = "SELECT name FROM user WHERE user_id = " . $user_id;
$result = mysql_query($query);
if(mysql_num_rows($result) != 1)
die("Interni chyba, neznamy uzivatel");
$row = mysql_fetch_row($result);
echo $row[0];
}
function czech_date_to_date($date, $morning)
{
$date_array = explode(".", str_replace(" ", "", $date));
if(strlen($date_array[0]) == 1)
$date_array[0] = "0" . $date_array[0];
if(strlen($date_array[1]) == 1)
$date_array[1] = "0" . $date_array[1];
// 0 - day, 1 - month, 2 - year
return $date_array[2] . "-" . $date_array[1] . "-" . $date_array[0] . " " . ($morning ? "00:00:01" : " 23:59:59");
}
function add_job($name, $description, $date_from, $date_to, $visible)
{
$query =
"INSERT INTO jobs (name, description, date_from, date_to, visible) VALUES (" .
quote_smart($name) . ", " .
quote_smart($description) . ", '" .
$date_from . "', '" .
$date_to . "', " .
($visible ? "'1'" : "'0'") . ")";
mysql_query($query) or die("Nepodarilo se pridat brigadu (" . $query . ")");
return mysql_insert_id();
}
function update_job($id, $name, $description, $date_from, $date_to)
{
if(!is_numeric($id) || !is_int((int)$id))
{
return false;
return;
}
$query =
"UPDATE jobs SET " .
"name = " . quote_smart($name) . ", " .
"description = " . quote_smart($description) . ", " .
"date_from = " . quote_smart($date_from) . ", " .
"date_to = " . quote_smart($date_to) . " WHERE job_id = " . $id;
mysql_query($query);
}
function update_visibility($id, $visible)
{
if(!is_numeric($id) || !is_int((int)$id))
{
return false;
return;
}
$query = "UPDATE jobs SET visible = " . ($visible ? "'1'" : "'0'") . " WHERE job_id = " . $id;
mysql_query($query);
}
function delete_job($id)
{
if(!is_numeric($id) || !is_int((int)$id))
{
return false;
return;
}
$query = "DELETE FROM jobs WHERE job_id = " . $id;
mysql_query($query);
return true;
}
function admin_jobs_list()
{
$query =
//"SELECT jobs.job_id, jobs.name, jobs.description, jobs.date_from, jobs.date_to, jobs.visible, user.name FROM jobs NATURAL JOIN user WHERE jobs.date_to < NOW() ORDER BY jobs.job_id ASC";
"SELECT jobs.job_id, jobs.name, jobs.description, jobs.date_from, jobs.date_to, jobs.visible FROM jobs WHERE jobs.date_to >= NOW() ORDER BY jobs.job_id ASC";
$result = mysql_query($query);
echo "<table class=\"news_list\">";
echo "<tr><th style=\"width: 20px\">id</th>" .
"<th style=\"width: 150px\">název</th>" .
//"<th style=\"width: 150px\">popis</th>" .
"<th style=\"width: 70px\">vyvěsit od</th>" .
"<th style=\"width: 70px\">vyvěsit do</th>" .
"<th style=\"width: 50px\">zobrazeno</th>" .
"<th style=\"width: 55px\"> </th>" .
"<th style=\"width: 55px\">smazat</th>" .
"<th style=\"width: 55px\">editovat</th>" .
"</tr>";
$odd = true;
while($row = mysql_fetch_row($result))
{
$date_from = date("j. n. Y", strtotime($row[3]));
$date_to = date("j. n. Y", strtotime($row[4]));
$odd = !$odd;
echo "<tr" . ($odd ? "" : " style=\"background-color: #ddd\"") . ">" .
"<td>" . $row[0] . "</td>" . // id
"<td>" . $row[1] . "</td>" . // name
// description
"<td>" . $date_from . "</td>" .
"<td>" . $date_to . "</td>" .
"<td>" . ($row[5] == '1' ? 'ano' : 'ne') . "</td>";
?>
<td class="list_button">
<form class="verbose" <?php echo ($odd ? "" : " style=\"background-color: #ddd\"");?> action="index.php" method="post">
<input type="hidden" name="job_id" value="<?php echo $row[0]; ?>"/>
<input type="hidden" name="action" value="<?php echo ($row[5] == '1' ? STATE_MAKE_JOB_HIDDEN : STATE_MAKE_JOB_VISIBLE); ?>"/>
<input type="submit" value="<?php echo ($row[5] == '1' ? 'schovat' : 'zobrazit');?>"/>
</form>
</td>
<td class="list_button">
<form class="verbose" <?php echo ($odd ? "" : " style=\"background-color: #ddd\"");?> action="index.php" method="post">
<input type="hidden" name="job_id" value="<?php echo $row[0]; ?>"/>
<input type="hidden" name="action" value="<?php echo STATE_DELETE_JOB; ?>"/>
<input type="submit" value="odstranit"/>
</form>
</td>
<td class="list_button">
<form class="verbose" <?php echo ($odd ? "" : " style=\"background-color: #ddd\"");?> action="index.php" method="post">
<input type="hidden" name="job_id" value="<?php echo $row[0]; ?>"/>
<input type="hidden" name="action" value="<?php echo STATE_DISPLAY_EDIT_JOB; ?>"/>
<input type="submit" value="upravit"/>
</form>
</td>
</tr>
<tr<?php echo ($odd ? "" : " style=\"background-color: #ddd\"");?> >
<td colspan="8"><?php echo $row[2];?></td>
</tr>
<?php
}
echo "</table>";
}
function admin_display_edit_job($id)
{
if(!is_numeric($id) || !is_int((int)$id))
{
return false;
return;
}
$query = "SELECT name, description, date_from, date_to FROM jobs WHERE job_id = " . $id;
$result = mysql_query($query);
$row = mysql_fetch_row($result);
?>
<form method="post" action="index.php" onsubmit="return (isDate(document.getElementById('job_date_from').value) && isDate(document.getElementById('job_date_to').value) && firstSoonerThanSecond(document.getElementById('job_date_from').value, document.getElementById('job_date_to').value));">
<input type="hidden" name="action" value="<?php echo STATE_EDIT_JOB; ?>" />
<input type="hidden" name="job_id" value="<?php echo $id; ?>" />
<h2>Editovat brigádu</h2>
<?php
//echo "<input type=\"hidden\" name=\"action\" value=\"" . STATE_ADD_NEWS_PREVIEW . "\"/>";
?>
<table style="width: 100%">
<!--<tr>
<td style="width: 10em">autor</td>
<td style="vertical-align:middle">
<?php
//echo "<input type=\"hidden\" name=\"user_id\" value=\"" . $_SESSION["user_id"] . "/>";
jobs_print_user($_SESSION["user_id"]);
?>
</td>
</tr>-->
<tr>
<td style="vertical-align:middle">název</td>
<td>
<input name="job_name" type="text" value="<?php echo $row[0]; ?>"/>
</td>
</tr>
<tr>
<td style="vertical-align:middle">vyvěsit od</td>
<td>
<input id="job_date_from" name="job_date_from" type="text" value="<?php echo date("j.n.Y", strtotime($row[2])); ?>"/> (např. 25.1.2010)
</td>
</tr>
<tr>
<td style="vertical-align:middle">vyvěsit do</td>
<td>
<input id="job_date_to" name="job_date_to" type="text" value="<?php echo date("j.n.Y", strtotime($row[3])); ?>"/> (např. 25.1.2010)
</td>
</tr>
<tr>
<td style="vertical-align:middle">popis</td>
<td><textarea name="job_description" rows="3"><?php echo $row[1];?></textarea></td>
</tr>
<tr><td> </td><td><input type="submit" value="Upravit" name="submit"/></td></tr>
<?php
}
function admin_display_add_job()
{
?>
<!--<form method="post" action="index.php" onsubmit="alert('submit'); return false"> -->
<form method="post" action="index.php" onsubmit="return (isDate(document.getElementById('job_date_from').value) && isDate(document.getElementById('job_date_to').value) && firstSoonerThanSecond(document.getElementById('job_date_from').value, document.getElementById('job_date_to').value));">
<input type="hidden" name="action" value="<?php echo STATE_ADD_JOB; ?>" />
<h2>Přidat brigádu</h2>
<?php
//echo "<input type=\"hidden\" name=\"action\" value=\"" . STATE_ADD_NEWS_PREVIEW . "\"/>";
?>
<table style="width: 100%">
<tr>
<td style="vertical-align:middle">název</td>
<td>
<input name="job_name" type="text" />
</td>
</tr>
<tr>
<td style="vertical-align:middle">vyvěsit od</td>
<td>
<input id="job_date_from" name="job_date_from" type="text" /> (např. 25.1.2010)
</td>
</tr>
<tr>
<td style="vertical-align:middle">vyvěsit do</td>
<td>
<input id="job_date_to" name="job_date_to" type="text" /> (např. 25.1.2010)
</td>
</tr>
<tr>
<td style="vertical-align:middle">popis</td>
<td><textarea name="job_description" rows="3"></textarea></td>
</tr>
<tr><td> </td><td><input type="submit" value="Přidat" name="submit"/></td></tr>
<!--
<tr><td>titulek</td><td><input name="headline" type="text"></td></tr>
<tr><td>kategorie</td><td>
<select name="category_id">
<?php print_category_combo("dddcategory_id") ?>
</select>
</td>
</tr>
<tr>
<td>perex</td>
<td><textarea name="perex" rows="3"></textarea></td></tr>
<tr>
<td>text</td>
<td><textarea name="text" rows="10"></textarea></td></tr>
<tr><td colspan="2" style="text-align: center"><input type="submit" value="náhled"></td></tr>-->
</table>
</form>
<?php
}
?>
ACC SHELL 2018