ACC SHELL
<?php
/**
*
*
* @version $Id$
* @copyright 2010
* @name Zpracování kateogorií
*/
class Novinky extends Tools {
public $idNovinky = array();
public $idPopisu = array();
public $nazev = array();
public $seoNazev = array();
public $seoUrl = array();
public $title = array();
public $keywords = array();
public $description = array();
public $stav = array();
public $anotace = array();
public $obsah = array();
public $lang = array();
public $typ = array();
public $exturl = array();
public $datum = array();
public $currentpage = "";
public $totalpages = "";
public $pagesize = "10";
/**
* Constructor
*/
function __construct() {
}
public function pridatNovinkyPopis($arr) {
$result = dibi::query('INSERT INTO [novinky_popis]', $arr);
if ($result) {
$_SESSION['message_ok'][] = "Uložení novinky proběhlo v pořádku.";
return dibi::insertId();
} else {
$_SESSION['message_ko'][] = "Úprava novinky neproběhla.";
return false;
}
}
public function updateNovinkyPopis($arr) {
$result = dibi::query('UPDATE `novinky_popis` SET ', $arr, 'WHERE `id`=%i', $arr['id'], ' AND lang=%i', $arr['lang']);
if ($result) {
Tools::message('Úprava proběhla v pořádku.', 'OK');
return true;
} else {
Tools::message('Úprava neproběhla.', 'KO');
return false;
}
}
public function getAdminTable($id = 0, $table = 'novinky') {
if (isset($_SESSION['listuj']))
$this->pagesize = $_SESSION['listuj'];
$recordstart = isset($_GET['recordstart']) ? (int) $_GET['recordstart'] : 0;
$query = "SELECT k.id, k.hloubka, kp.nazev AS nazev, kp.seo_url, k.parent_id, k.lft, k.rgt,
kp.stav AS stav, kp.main_id, kp.premium, kp.anotace, kp.datum, kp.lang, j.kod
FROM novinky k
LEFT JOIN novinky_popis kp ON k.id = kp.main_id
LEFT JOIN jazyk j ON j.id = kp.lang
WHERE kp.lang = 1
ORDER BY k.lft DESC";
$result = mysql_query($query);
//NDebugger::dump($result);
$num_rows = 0;
if ($result) {
$num_rows = mysql_num_rows($result);
}
if ($num_rows > $this->pagesize) {
$query .= " LIMIT $recordstart, $this->pagesize";
$result = mysql_query($query);
}
//$this->debug($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='8'>Nejsou založeny žádné novinky</td></tr>";
} else {
//Zjisteni minimalni a maximalni hodnoty pro kazdou kategorii
$query = "SELECT parent_id, min(lft) lft, max(rgt) rgt FROM {$table} group by parent_id";
$test = mysql_query($query);
//$this->debug($query);
while ($test1 = mysql_fetch_assoc($test)) {
$showMove[$test1['parent_id']]['lft'] = $test1['lft'];
$showMove[$test1['parent_id']]['rgt'] = $test1['rgt'];
}
//$this->debug($showMove);
while ($row = mysql_fetch_assoc($result)) {
$adresa_novinek = dibi::query("SELECT url, lang FROM kategorie_popis WHERE typ=4")->fetchAssoc('lang');
echo "<tr>";
echo '<td><input type="checkbox" name="checkbox[]" value="' . $row['id'] . '" ></td>';
echo "<td><a href=\"{$table}_edit.php?id={$row['id']}\">" . $row['nazev'] . "</a><br />";
$query = "SELECT kp.seo_url, kp.lang, j.nazev, j.obrazek, j.kod
FROM novinky_popis kp
LEFT JOIN jazyk j ON j.id = kp.lang
WHERE kp.main_id = $row[main_id]
ORDER BY j.id";
$langs = dibi::query($query)->fetchAll();
//NDebugger::dump($langs);NDebugger::dump($adresa_novinek);
foreach ($langs as $n => $r) {
$adresa = isset($adresa_novinek[$r['lang']]->url) ? $adresa_novinek[$r['lang']]->url : 'novinky';
echo "<span>";
if ($r['lang'] == 1) {
$odkaz = 'http://' . SERVER_NAME . '/' . $adresa . '/' . $r['seo_url'];
}
echo 'http://' . SERVER_NAME . '/' . $adresa . '/' . $r['seo_url'];
echo "</span><br />";
}
echo "</td>";
echo '<td>' . NStrings::truncate($row['anotace'], '90', '...') . '</td>';
$stav = $row['stav'] == '1' ? "Ano" : "Ne";
echo "<td><a href=\"?id={$row['id']}&stav=$stav\">$stav</a></td>";
$premium = $row['premium'] == '1' ? "Ano" : "Ne";
echo "<td><a href=\"?id={$row['id']}&premium=$premium\">$premium</a></td>";
// jazykove mutace
$flags = Query::getLanguageFlags($row['id'], 'novinky');
echo "<td>";
foreach ($flags as $f) {
echo "<img class=\"vypis_jazyky\" src=\"images/flags/$f->obrazek\" alt=\"$f->nazev\" title=\"$f->nazev\" />";
}
echo "</td>";
// end of jazykove mutace
echo "<td>" . datum($row['datum']) . "</td>";
if ($showMove[$row['parent_id']]['lft'] != $row['lft']) {
echo "<td><a href=\"?up=" . $row['id'] . "\" title=\"Posun nahoru\"><img src=\"images/iko/up.png\" alt=\"Posun nahoru\" /></a>";
} else {
echo "<td>";
}
if ($showMove[$row['parent_id']]['rgt'] != $row['rgt']) {
echo "<a href=\"?down=" . $row['id'] . "\" title=\"Posun dolů\"><img src=\"images/iko/down.png\" alt=\"Posun dolů\" /></a>";
} else {
echo "</td>";
}
echo "<td><a href=\"{$table}_edit.php?id=" . $row['id'] . "\" title=\"Editovat\"><img src=\"images/iko/note_edit.png\" alt=\"Editovat\" /></a>";
echo '<a href="' . $odkaz . '" target="_blank" title="Prohlédnout"><img src="images/iko/computer.png" alt="Prohlédnout" /></a>';
echo '<a href="?smazat=' . $row['id'] . '" class="potvrzujiciLink" title="Smazat"><img src="images/iko/remove.png" alt="Smazat" /></a></td>';
echo "</tr>";
}
}
}
public function getNovinkyOption($kategorie = 'novinky') {
$query = "SELECT k.id, k.hloubka, kp.nazev AS nazev
FROM {$kategorie} k
LEFT JOIN {$kategorie}_popis kp ON k.id = kp.main_id
WHERE kp.lang = '" . $_SESSION['jazyk'] . "'
AND k.hloubka>0
ORDER BY k.lft ASC";
if (self::getNumRows($query) != '0') {
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result)) {
printf("<option name=\"%d\" id=\"%d\" value=\"%d\">%s</option>\n", $row['id'], $row['id'], $row['id'], str_repeat(" ", $row['hloubka'] * 3) . $row['nazev']);
}
if (isset($result)) {
mysql_free_result($result);
}
}
}
public function priraditNovinky($idclanku, $idkategorie, $lang) {
$idclanku = intval($idclanku);
$idkategorie = intval($idkategorie);
$lang = intval($lang);
if ($idkategorie != "") {
$query = "SELECT id_novinky FROM novinky_prirazeni WHERE id_novinky = '" . $idclanku . "' AND id_kategorie = '" . $idkategorie . "' LIMIT 1";
//$this->debug($query);
if ($this->getNumRows($query) > '0') {
$_SESSION['message_info'][] = "Novinka už je této kategorii přiřazena.";
} else {
//$query = "INSERT INTO clanky_prirazeni (id_clanku, id_kategorie, jazyk) VALUES($idclanku, $idkategorie, $lang)";
$query = "INSERT INTO novinky_prirazeni (id_novinky, id_kategorie) VALUES($idclanku, $idkategorie)";
$insert = mysql_query($query);
if (!$insert) {
$_SESSION['message_ko'][] = "Novinku se nepodařilo přiřadit.";
}
}
}
}
public function getPrirazeni($id = 0, $table = 'novinky') {
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_novinky, cpr.id_kategorie
FROM {$table}_prirazeni cpr
LEFT JOIN {$table}_popis cp ON cp.id_novinky = cpr.id_novinky
LEFT JOIN kategorie_popis kp ON kp.id = cpr.id_kategorie
WHERE cpr.id_novinky = '" . intval($id) . "'
ORDER BY cpr.id";
$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'>novinky 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['cpr_id']}\">" . $row['cp_nazev'] . "</a></td>";
echo "<td><a href=\"kategorie_edit.php?id={$row['cpr_id']}\">" . $row['kp_nazev'] . "</a></td>";
//echo "<td><a href=\"{$table}_edit.php?id=" . $row['id'] . "\" title=\"Editovat\"><img src=\"images/iko/note_edit.png\" alt=\"Editovat\" /></a>";
//echo '<a href="#" title="Prohlédnout"><img src="images/iko/computer.png" alt="Prohlédnout" /></a>';
echo '<td><a href="?zrusit=' . $row['cpr_id'] . '" class="potvrzujiciLinkPrirazeni" title="Zrušit přiřazení"><img src="images/iko/remove.png" alt="Zrušit přiřazení" /></a></td>';
echo "</tr>";
}
}
}
public function getInfoAdmin($id = '', $lang = -1, $table = 'novinky') {
//$id = intval($id);
//$limit = ' LIMIT 1';
//echo "id - >$id";
if ($lang == '-1')
$lang = $_SESSION['jazyk'];
if ($id == 'index') {
$find = "a.id='3'";
} else {
$find = "a.id = '$id'";
}
if ($id != '') {
$query = "SELECT a.id AS idNovinky, b.id AS idPopisu, a.hloubka, b.nazev AS nazev, b.seo_nazev, b.seo_url,
b.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} AS a
LEFT JOIN {$table}_popis AS b ON a.id = b.main_id
LEFT JOIN jazyk c ON c.id = b.lang
WHERE $find
AND b.lang = '" . $lang . "'
AND c.status = '1'
LIMIT 1
";
//echo $query;
$result = mysql_query($query);
//$this->debug($query);
if (mysql_num_rows($result) != 0) {
while ($row = mysql_fetch_assoc($result)) {
$this->idNovinky = $row['idNovinky'];
$this->idPopisu = $row['idPopisu'];
$this->nazev = $row['nazev'];
$this->seoNazev = $row['seo_nazev'];
$this->seoUrl = $row['seo_url'];
$this->title = $row['title'];
$this->anotace = $row['anotace'];
$this->obsah = $row['obsah'];
$this->stav = $row['stav'];
$this->exturl = $row['exturl'];
$this->datum = $row['datum'];
}
} else {
$this->idNovinky = '';
$this->idPopisu = '';
$this->nazev = '';
$this->seoNazev = '';
$this->seoUrl = '';
$this->title = '';
$this->keywords = '';
$this->description = '';
$this->anotace = '';
$this->obsah = '';
$this->stav = '';
$this->typ = '';
$this->exturl = '';
}
} else {
$this->idNovinky = '';
$this->idPopisu = '';
$this->nazev = '';
$this->seoNazev = '';
$this->seoUrl = '';
$this->title = '';
$this->keywords = '';
$this->description = '';
$this->anotace = '';
$this->obsah = '';
$this->stav = '';
$this->typ = '';
$this->exturl = '';
}
}
public function getNavstevnost($id) {
$query = "SELECT b.pocet FROM novinky_popis a , novinky_navsteva b WHERE a.main_id='" . $id . "' AND a.id=b.id LIMIT 1";
$pocet = dibi::query($query)->fetchSingle();
if (!$pocet) {
return 0;
}
return $pocet;
}
public function getDetail($id, $lang = 1, $table = 'novinky', $admin = false) {
if (!$id) {
return false;
} else {
if ($admin) {
$search = ' WHERE a.id=' . $id . ' AND b.lang=' . $lang . ' ';
} else {
$search = ' WHERE b.seo_url = "' . $id . '" AND b.lang = ' . $lang . ' ';
}
$query = "
SELECT
a.id AS main_id, b.id AS id_popisu, a.hloubka,
b.nazev AS nazev, b.seo_nazev, b.seo_url, b.komentare, b.fblike,
b.title, c.nazev AS jazyk, c.obrazek, c.kod,
b.keywords, b.description, b.stav, b.premium, b.anotace, b.obsah, b.typ, b.exturl, b.datum, b.obrazek
FROM {$table} AS a
LEFT JOIN {$table}_popis AS b
ON a.id = b.main_id
LEFT JOIN jazyk c
ON c.id = b.lang
$search
LIMIT 1
";
return dibi::query($query)->fetch();
}
}
public function fetchAll($arr) {
if (isset($arr['pagesize'])) {
$this->pagesize = $arr['pagesize'];
}
$lang = isset($arr['lang']) ? $arr['lang'] : '1';
$recordstart = (isset($_GET['recordstart'])) ? (int) $_GET['recordstart'] : 0;
$query = "SELECT a.id AS id_kategorie, b.id AS id_novinky, a.hloubka, b.nazev AS nazev, b.seo_nazev, b.seo_url,
b.title, b.obrazek obrazek_novinky, 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 novinky AS a
LEFT JOIN novinky_popis AS b ON a.id = b.main_id
LEFT JOIN jazyk c ON c.id = b.lang
WHERE b.lang = $lang
AND c.status = '1'";
if (isset($arr['stav'])) {
$query .= " AND b.stav =" . $arr['stav'];
}
$query .= " ORDER BY b.datum DESC, b.id";
$rows = dibi::query($query);
$pocetZaznamu = count($rows);
//NDebugger::barDump($pocetZaznamu, 'PocetNovinek');
//NDebugger::barDump($this->pagesize, 'Pagesize');
if ($pocetZaznamu > $this->pagesize) {
$this->totalpages = ceil($pocetZaznamu / $this->pagesize);
$this->currentpage = ($recordstart / $this->pagesize) + 1;
return $rows->fetchAll($recordstart, $this->pagesize);
} else {
return $rows->fetchAll();
}
}
public function getInfo($id = '', $lang = -1, $table = 'novinky', $admin = '') {
//$id = intval($id);
//$limit = ' LIMIT 1';
//echo "id - >$id";
if ($lang == '-1')
$lang = $_SESSION['jazyk'];
if ($id == 'index') {
$find = "a.id='1'";
}
if ($id == '') {
$find = "b.stav = '1'";
} elseif ($admin == 'admin') {
$find = "a.id = '$id'";
} else {
$find = "b.seo_url = '$id'";
}
$query = "SELECT a.id AS idNovinky, b.id AS idPopisu, a.hloubka, b.nazev AS nazev, b.seo_nazev, b.seo_url,
b.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} AS a
LEFT JOIN {$table}_popis AS b ON a.id = b.main_id
LEFT JOIN jazyk c ON c.id = b.lang
WHERE $find
AND b.lang = '" . $lang . "'
AND c.status = '1'
";
$result = mysql_query($query);
//$this->debug($query);
if (mysql_num_rows($result) != 0) {
while ($row = mysql_fetch_assoc($result)) {
$this->idNovinky = $row['idNovinky'];
$this->idPopisu = $row['idPopisu'];
$this->nazev = $row['nazev'];
$this->seoNazev = $row['seo_nazev'];
$this->seoUrl = $row['seo_url'];
$this->title = $row['title'];
$this->anotace = $row['anotace'];
$this->obsah = $row['obsah'];
$this->stav = $row['stav'];
$this->exturl = $row['exturl'];
$this->datum = $row['datum'];
$this->typ = $row['typ'];
}
} else {
$this->idNovinky = '';
$this->idPopisu = '';
$this->nazev = '';
$this->seoNazev = '';
$this->seoUrl = '';
$this->title = '';
$this->keywords = '';
$this->description = '';
$this->anotace = '';
$this->obsah = '';
$this->stav = '';
$this->typ = '';
$this->exturl = '';
}
}
public function smazatFotku($id) {
$obrazek = dibi::query('SELECT obrazek FROM novinky_popis WHERE main_id=%i', $id, ' AND lang=1')->fetchSingle();
$res = dibi::query('UPDATE novinky_popis SET obrazek=null WHERE main_id=%i', $id);
if ($res) {
unlink(ROOT . NOVINKY_F_M_PATH . $obrazek);
unlink(ROOT . NOVINKY_F_L_PATH . $obrazek);
return true;
} else {
return false;
}
}
}
$Novinky = new Novinky();
ACC SHELL 2018