ACC SHELL
<?php
/**
*
*
* @version $Id$
* @copyright 2010
* @name Zpracování kateogorií
*/
class Fotografie {
/*
public $idFotografie = array();
public $idFotografie = array();
public $nazev = array();
public $pripona = array();
public $velikost = array();
public $title = array();
public $hlavni = array();
public $stav = array();
public $datum = array();
public $currentpage = "";
public $totalpages = "";
public $pagesize = "10";
*/
/**
* Constructor
*/
function __construct() {
}
public function updateFotografiePopis($arr) {
/*
array(7) {
"nazev" => "3"
"title" => ""
"stav" => "1"
"id_fotografie" => "3"
"id_fotogalerie" => "1"
"lang" => "1"
"odeslat" => "Uložit" (7)
}
*/
/*
$arr['id'] = $_POST['id_fotografie'];
$arr['id_fotogalerie'] = $_POST['id_fotogalerie'];
$arr['nazev'] = $_POST['nazev'];
$arr['alt'] = $_POST['nazev'];
$arr['title'] = $_POST['title'];
$arr['hlavni'] = $_POST['hlavni'];
$arr['stav'] = $_POST['stav'];
$arr['lang'] = $_POST['lang'];
$arr['datum'] = new DateTime;
*/
$valid = true;
if (empty($arr['nazev'])) {
$_SESSION['message_ko'][] = "fotografie musí mít název";
$valid = false;
}
if ($valid == true) {
if ($arr['lang'] == 1) {
$query = "UPDATE fotografie
SET nazev_fotografie = '" . $arr['nazev'] . "',
title = '" . $arr['title'] . "',
alt = '" . $arr['alt'] . "',
stav = '" . $arr['stav'] . "',
datum = now()
WHERE id = '" . $arr['id'] . "'";
}
else {
$query = "UPDATE fotografie_popis
SET title = '" . $arr['title'] . "',
alt = '" . $arr['alt'] . "',
stav = '" . $arr['stav'] . "',
datum = now()
WHERE id_fotografie = '" . $arr['id'] . "' AND lang='" . $arr['lang'] . "'";
}
//NDebugger::dump($query);
$result = dibi::query($query);
}
if ($result) {
return true;
$_SESSION['message_ok'][] = "Úprava fotografie proběhla v pořádku.";
}
else {
return false;
$_SESSION['message_ko'][] = "Úprava fotografie neproběhla.";
}
}
public function povolit($id='-1', $kategorie='fotografie') {
$query = "UPDATE {$kategorie}_popis SET stav = '1' WHERE id = '" . intval($id) . "'";
$result = mysql_query($query);
if (isset($result)) {
mysql_free_result($result);
}
}
public function zakazat($id='-1', $kategorie='fotografie') {
$query = "UPDATE {$kategorie}_popis SET stav = '0' WHERE id = '" . intval($id) . "'";
$result = mysql_query($query);
if (isset($result)) {
mysql_free_result($result);
}
}
public function priraditFotogalerii($idclanku, $idkategorie, $lang) {
$idclanku = intval($idclanku);
$idkategorie = intval($idkategorie);
$lang = intval($lang);
if ($idkategorie != "") {
$query = "SELECT id_fotografie FROM fotografie_prirazeni WHERE id_fotografie = '" . $idclanku . "' AND id_kategorie = '" . $idkategorie . "' LIMIT 1";
//$this->debug($query);
if ($this->getNumRows($query) > '0') {
$_SESSION['message_info'][] = "Fotografie už je této kategorii přiřazena.";
}
else {
$query = "INSERT INTO fotografie_prirazeni (id_fotografie, id_kategorie) VALUES($idclanku, $idkategorie)";
$insert = mysql_query($query);
if (!$insert) {
$_SESSION['message_ko'][] = "Fotografii se nepodařilo přiřadit.";
}
}
}
}
public function getPrirazeni($id=0, $table='fotografie') {
if (isset($_SESSION['listuj'])) $this->pagesize = $_SESSION['listuj'];
$recordstart = (isset($_GET['recordstart'])) ? (int) $_GET['recordstart'] : 0;
$query = "SELECT cp.nazev cp_nazev, kp.nazev kp_nazev, cpr.id cpr_id, cpr.id_Fotografie, cpr.id_kategorie
FROM {$table}_prirazeni cpr
LEFT JOIN {$table}_popis cp ON cp.id_Fotografie = cpr.id_Fotografie
LEFT JOIN kategorie_popis kp ON kp.id = cpr.id_kategorie
WHERE cpr.id_Fotografie = '" . intval($id) . "'
ORDER BY cpr.id";
//Multilang -> AND cpr.jazyk = cp.lang
//$this->debug($query);
$result = mysql_query($query);
$num_rows = mysql_num_rows($result);
if ($num_rows>$this->pagesize) {
$query .= " LIMIT $recordstart, $this->pagesize";
}
$result = mysql_query($query);
//echo "<br />celkem zaznamu: " . $num_rows . "<br />\n";
$this->totalpages = ceil($num_rows / $this->pagesize);
//echo "celkem stranek: " . $totalpages . "<br />\n";
$this->currentpage = ($recordstart / $this->pagesize) + 1;
if ($num_rows == 0) {
echo "<tr><td colspan='9'>Fotografie není přiřazena.</td></tr>";
}
else {
while ($row = mysql_fetch_assoc($result)) {
echo "<tr>";
echo '<td><input type="checkbox" name="checkbox[]" value="' . $row['cpr_id'] . '" id="" ></td>';
echo "<td><a href=\"{$table}_edit.php?id={$row['id_Fotografie']}\">" . $row['cp_nazev'] . "</a></td>";
echo "<td><a href=\"kategorie_edit.php?id={$row['id_kategorie']}\">" . $row['kp_nazev'] . "</a></td>";
echo '<td><a href="?zrusit=' . $row['cpr_id'] . '" class="potvrzujiciLinkPrirazeni" title="Zrušit přiřazení"><img src="obr/iko/remove.png" alt="Zrušit přiřazení" /></a></td>';
echo "</tr>";
}
}
}
public function getHlavniFotografie($id='0') {
$query = "SELECT nazev, pripona FROM fotografie WHERE id_Fotografie = '" . intval($id) . "' AND hlavni='1'";
$result = mysql_query($query);
//$this->debug($query);
if ($result) {
$result = mysql_fetch_row($result);
return $result;
}
return false;
}
public function setHlavniFotografie($id='0', $id_Fotografie='0') {
if (intval($id) != '0' && intval($id_Fotografie) != '0') {
mysql_query("START TRANSACTION");
$query = "UPDATE fotografie SET hlavni = '0' WHERE id_Fotografie = '" . intval($id_Fotografie) . "'";
mysql_query($query);
$query = "UPDATE fotografie SET hlavni = '1' WHERE id_Fotografie = '" . intval($id_Fotografie) . "' AND id = '" . intval($id) . "'";
mysql_query($query);
mysql_query("COMMIT");
header("Location:" . $_SERVER['HTTP_REFERER']);
exit();
}
}
public function getFotografie($id='0', $admin=true, $stav = '0') {
//$id_galerie - v adminu je to cislo, na vystupu je to seo_url
//$stav - 0 vsechny, 1 jen aktivni
if ($admin) {
$query = "SELECT id, nazev, pripona, hlavni, stav FROM fotografie WHERE id_Fotografie = '" . intval($id) . "'";
}
else {
$query = "SELECT a.id, a.nazev, a.pripona, a.hlavni, a.stav, a.title, a.alt
FROM fotografie a
LEFT JOIN Fotografie_popis b
ON a.id_Fotografie = b.id_Fotografie
WHERE b.seo_url = '" . $id . "'
AND b.stav=$stav
ORDER BY datum";
}
$result = mysql_query($query);
//$this->debug($query);
if (!empty($result) && mysql_num_rows($result) != '0') {
while ($row = mysql_fetch_array($result)) {
$fotografie['id'][] = $row['id'];
$fotografie['nazev'][] = $row['nazev'];
$fotografie['pripona'][] = $row['pripona'];
$fotografie['hlavni'][] = $row['hlavni'];
$fotografie['stav'][] = $row['stav'];
$fotografie['alt'][] = $row['alt'];
$fotografie['title'][] = $row['title'];
}
return $fotografie;
}
else
return false;
}
public function zakazatCelouKategorii($id='-1', $kategorie='Fotografie') {
$query = "UPDATE {$kategorie}_popis SET stav = '0' WHERE id_{$kategorie} = '" . intval($id) . "'";
//$this->debug($query);
$result = mysql_query($query);
}
public function povolitCelouKategorii($id='-1', $kategorie='Fotografie') {
$query = "UPDATE {$kategorie}_popis SET stav = '1' WHERE id_{$kategorie} = '" . intval($id) . "'";
$result = mysql_query($query);
}
public function zrusitPrirazeni($id, $table='Fotografie') {
$query = "DELETE FROM {$table}_prirazeni WHERE id = '" . intval($id) . "'";
$result = mysql_query($query);
if ($result){
$_SESSION['message_ok'][] = "Zrušení přiřazení proběhlo v pořádku.";
Tools::redirect($_SERVER['HTTP_REFERER']);
}
else {
$_SESSION['message_ko'][] = "Zrušení přiřazení se nepovedlo.";
Tools::redirect($_SERVER['HTTP_REFERER']);
}
}
public function smazatFotku($id, $idgalerie) {
$query = "DELETE FROM fotografie WHERE id = '" . intval($id) . "'";
$result = mysql_query($query);
//$this->debug($query);
if (mysql_affected_rows() == '1') {
$_SESSION['message_ok'][] = "Vymazání fotografie proběhlo v pořádku.";
Tools::redirect($_SERVER['HTTP_REFERER']);
}
else {
$_SESSION['message_ko'][] = "Vymazání fotografie se nepovedlo.";
Tools::redirect($_SERVER['HTTP_REFERER']);
}
}
public function getInfo($id='', $lang=-1, $table='Fotografie', $admin ='') {
//$id = intval($id);
if ($lang == '-1')
$lang = $_SESSION['jazyk'];
if ($id == 'index') {
$find = "a.id='3'";
}
if ($id == '') {
$find = "b.stav = '1'";
} elseif ($admin == 'admin') {
$find = "a.id = '$id'";
} else {
$find = "b.seo_url = '$id'";
}
$query = "SELECT a.id AS idFotografie, b.id AS idPopisu, a.hloubka, b.nazev AS nazev, b.seo_nazev, b.seo_url,
b.title AS title, c.nazev AS jazyk, c.obrazek, c.kod,
b.keywords, b.description, b.stav, b.anotace, b.obsah, b.typ, b.exturl, b.datum
FROM {$table} a
LEFT JOIN {$table}_popis b ON a.id = b.id_Fotografie
LEFT JOIN jazyk c ON c.id = b.lang
WHERE $find
AND b.lang = '" . $lang . "'
AND c.status = '1'
";
//$this->debug($query);
$result = mysql_query($query);
if (mysql_num_rows($result) != 0) {
while ($row = mysql_fetch_assoc($result)) {
array_push($this->idFotografie, $row['idFotografie']);
array_push($this->idPopisu, $row['idPopisu']);
array_push($this->nazev, $row['nazev']);
array_push($this->seoNazev, $row['seo_nazev']);
array_push($this->seoUrl, $row['seo_url']);
array_push($this->anotace, html_entity_decode($row['anotace']));
array_push($this->obsah, html_entity_decode($row['obsah']));
array_push($this->stav, $row['stav']);
array_push($this->exturl, $row['exturl']);
array_push($this->datum, $row['datum']);
}
}
else {
$this->idFotografie = '';
$this->idPopisu = '';
$this->nazev = '';
$this->seoNazev = '';
$this->seoUrl = '';
$this->title = '';
$this->keywords = '';
$this->description = '';
$this->anotace = '';
$this->obsah = '';
$this->stav = '';
$this->typ = '';
$this->extrul = '';
$this->datum = '';
}
}
}
$Fotografie = new Fotografie();
if (isset($_GET['up'])) {
$Fotografie->moveUp($_GET['up']);
}
if (isset($_GET['down'])) {
$Fotografie->moveDown($_GET['down']);
}
if (isset($_GET['smazat'])) {
$Fotografie->delTree($_GET['smazat']);
}
if (isset($_GET['zrusit'])) {
$Fotografie->zrusitPrirazeni($_GET['zrusit']);
}
if (isset($_GET['hlavni']) && isset($_GET['id'])) {
$Fotografie->setHlavniFotografie($_GET['hlavni'], $_GET['id']);
}
//if (isset($_GET['smazatfotku']) && isset($_GET['id'])) {
if (isset($_GET['smazatfotku'])) {
$Fotografie->smazatFotku($_GET['smazatfotku'], $_GET['id']);
}
if (isset($_GET['stav'])) {
if ($_GET['stav'] == 'Ano') {
$Fotografie->zakazatCelouKategorii(intval($_GET['id']));
$_SESSION['message_ok'][] = "Fotografie je zakázána.";
header("Location: Fotografie.php");
exit();
}
if ($_GET['stav'] == 'Ne') {
$Fotografie->povolitCelouKategorii(intval($_GET['id']));
$_SESSION['message_ok'][] = "Fotografie je povolena.";
header("Location: Fotografie.php");
exit();
}
}
if (isset($_POST['aplikovat'])) {
if (isset($_POST['dropdown'])) {
if (!isset($_POST['checkbox'])) {
$_SESSION['message_info'][] = "Není co zpracovat.";
}
else {
switch($_POST['dropdown']) {
case 'zakazat':
foreach($_POST['checkbox'] as $akce) {
$Fotografie->zakazatCelouKategorii($akce);
}
break;
case 'povolit':
foreach($_POST['checkbox'] as $akce) {
$Fotografie->povolitCelouKategorii($akce);
}
break;
case 'smazat':
foreach($_POST['checkbox'] as $akce) {
$Fotografie->delAllTree($akce);
}
break;
case 'zrusit':
foreach($_POST['checkbox'] as $akce) {
$Fotografie->zrusitPrirazeni($akce);
}
break;
default :
$_SESSION['message_info'][] = "Není co zpracovat.";
}
}
}
}
ACC SHELL 2018