protected static function unlockTables($lock)
 {
     if (self::$_locked === $lock) {
         mysql_query("UNLOCK TABLES");
         self::$_locked = null;
     }
 }
require_once 'include/project.inc.php';
require_once 'include/dbc.inc.php';
require_once 'include/kiwi_rights.class.php';
require_once 'include/kiwi_eshop_indexer.class.php';
require_once 'include/html_header.class.php';
require_once 'include/page_names.inc.php';
$rights = new Kiwi_Rights();
if ($rights->EShop == false) {
    if ($rights->UserID == DEFAULT_USERID) {
        redirectPage(KIWI_LOGIN . '?page=' . urlencode($_SERVER['REQUEST_URI']));
    }
}
$html_header = new HTML_Header();
$html_header->title = "{$project} - Content Management System";
$html_header->addCss('none.css');
Kiwi_EShop_Indexer::reindexAll();
$text = 'Kiwi_EShop_Indexer::reindexAll() called';
//Kiwi_EShop_Indexer::unindex(6);
//$text .= '<br />Kiwi_EShop_Indexer::unindex(6) called';
//Kiwi_EShop_Indexer::indexDeep(6);
//$text .= '<br />Kiwi_EShop_Indexer::deepIndex(6) called';
$html_header->send();
?>
<body>
	<!--Obsah-->
	<div id="stred">
		<div id="levy">
<?php 
echo $text;
?>
<br /><br />
 protected function acquireGroupedProductsGroup()
 {
     global $kiwi_config;
     $newgid = null;
     $this->loadData();
     if (!empty($this->group)) {
         // existuje sdružovací řada k tomuto produktu?
         $gid = $this->group[0];
     } else {
         $grouped_products_group = $kiwi_config['eshop']['grouped_products_group'];
         mysql_query("LOCK TABLES eshop WRITE, eshop AS E READ, prodbinds WRITE, prodbinds AS PB READ");
         $result = mysql_query("SELECT E.ID FROM eshop AS E LEFT OUTER JOIN prodbinds AS PB ON E.ID=PB.GID WHERE E.parent={$grouped_products_group} GROUP BY E.ID HAVING Count(PB.GID)=0 LIMIT 1");
         $name = mysql_real_escape_string('Gruppiert mit ' . $this->title);
         if ($row = mysql_fetch_row($result)) {
             $gid = $row[0];
             $result = mysql_query("UPDATE eshop SET Name='{$name}' WHERE ID={$gid}");
         } else {
             $result = mysql_query("SELECT MAX(E.Priority) FROM eshop AS E WHERE E.Parent={$grouped_products_group}");
             $row = mysql_fetch_row($result);
             $priority = (int) $row[0] + 1;
             mysql_query("INSERT INTO eshop(Name, Subgroup, Parent, Priority, Active) VALUES ('{$name}', 0, {$grouped_products_group}, {$priority}, 1)");
             $newgid = $gid = mysql_insert_id();
         }
         mysql_query("INSERT INTO prodbinds(PID, GID, Priority, Active) VALUES ({$this->id}, {$gid}, 0, 1)");
         mysql_query("UNLOCK TABLES");
         if ($newgid !== null) {
             Kiwi_EShop_Indexer::index($newgid, $grouped_products_group);
         }
     }
     return $gid;
 }
 public function handleInput($get, $post)
 {
     $self = basename($_SERVER['PHP_SELF']);
     $qs = '';
     if (!empty($get)) {
         if (isset($get['ei'])) {
             if (($ei = (int) $get['ei']) < 1) {
                 throw new Exception("Neplatné ID záznamu: {$ei}");
             }
             $this->id = $ei;
             $qs = "?ei={$this->id}";
         }
         if (isset($get['sg'])) {
             if (($this->parent = (int) $get['sg']) < 1) {
                 throw new Exception("Neplatné ID nadřazené skupiny: {$this->parent}");
             }
         }
         if (isset($get['gp'])) {
             if (($this->grouped_product = (int) $get['gp']) < 1) {
                 throw new Exception("Neplatné ID sdruženého produktu: {$this->grouped_product}");
             }
             if (!$this->id) {
                 throw new Exception("V případě použití parametru gp je povinný i parametr ei");
             }
             $qs .= '&gp=' . $this->grouped_product;
         }
         if (isset($get['ri']) && $this->id != 1) {
             $this->removeGroupIcon();
             $this->redirection = $self . $qs;
             return;
         }
         if (isset($get['asa']) || isset($get['asd'])) {
             $nas = isset($get['asa']) ? 1 : 0;
             if ($nas && isset($get['asd'])) {
                 throw new Exception("Současná přítomnost parametrů asa a asd není přípustná");
             }
             $qsv = 'as' . ($nas ? 'a' : 'd');
             $this->loadRecord();
             if (($as = (int) $get[$qsv]) < 1 || !isset($this->index[$as])) {
                 throw new Exception("Neplatné ID záznamu: {$as}");
             }
             if ($nas && !$this->record->Active) {
                 throw new Exception("Pokud o nepřípustnou aktivaci záznamu: {$as}");
             }
             mysql_query("UPDATE prodbinds SET Active='{$nas}', LastChange=CURRENT_TIMESTAMP WHERE ID={$as}");
             /*
             				$this->products[$this->index[$as]]->Active = $nas;
             				$this->products[$this->index[$as]]->LastChange = date('Y-m-d H:i', time());
             */
             $this->loadLastChange(false);
             $this->lastchange->register();
             $this->lastchange = null;
             $this->anchor->ID = $as;
             $this->redirection = KIWI_EDIT_ESHOPITEM . $qs . '#zmena';
         }
         if (isset($get['tn'])) {
             $this->loadRecord();
             if (($tn = (int) $get['tn']) < 1 || !isset($this->index[$tn])) {
                 throw new Exception("Neplatné ID záznamu: {$tn}");
             }
             $prod = $this->products[$this->index[$tn]];
             $ntn = !$prod->Novelty;
             mysql_query("UPDATE products SET Novelty='{$ntn}', LastChange=CURRENT_TIMESTAMP WHERE ID={$prod->PID}");
             mysql_query("UPDATE prodbinds SET LastChange=CURRENT_TIMESTAMP WHERE ID={$tn}");
             $this->products[$this->index[$tn]]->Novelty = $ntn;
             $this->products[$this->index[$tn]]->LastChange = date('Y-m-d H:i', time());
             $this->loadLastChange(false);
             $this->lastchange->register();
             $this->lastchange = null;
             $this->anchor->ID = $tn;
             $this->redirection = KIWI_EDIT_ESHOPITEM . $qs . '#zmena';
         }
         if (isset($get['ta'])) {
             $this->loadRecord();
             if (($ta = (int) $get['ta']) < 1 || !isset($this->index[$ta])) {
                 throw new Exception("Neplatné ID záznamu: {$ta}");
             }
             $prod = $this->products[$this->index[$ta]];
             $nta = !$prod->Action;
             mysql_query("UPDATE products SET Action='{$nta}', LastChange=CURRENT_TIMESTAMP WHERE ID={$prod->PID}");
             mysql_query("UPDATE prodbinds SET LastChange=CURRENT_TIMESTAMP WHERE ID={$ta}");
             $this->products[$this->index[$ta]]->Action = $nta;
             $this->products[$this->index[$ta]]->LastChange = date('Y-m-d H:i', time());
             $this->loadLastChange(false);
             $this->lastchange->register();
             $this->lastchange = null;
             $this->anchor->ID = $ta;
             $this->redirection = KIWI_EDIT_ESHOPITEM . $qs . '#zmena';
         }
         if (isset($get['td'])) {
             $this->loadRecord();
             if (($td = (int) $get['td']) < 1 || !isset($this->index[$td])) {
                 throw new Exception("Neplatné ID záznamu: {$td}");
             }
             $prod = $this->products[$this->index[$td]];
             $ntd = !$prod->Discount;
             mysql_query("UPDATE products SET Discount='{$ntd}', LastChange=CURRENT_TIMESTAMP WHERE ID={$prod->PID}");
             mysql_query("UPDATE prodbinds SET LastChange=CURRENT_TIMESTAMP WHERE ID={$td}");
             $this->products[$this->index[$td]]->Discount = $ntd;
             $this->products[$this->index[$td]]->LastChange = date('Y-m-d H:i', time());
             $this->loadLastChange(false);
             $this->lastchange->register();
             $this->lastchange = null;
             $this->anchor->ID = $td;
             $this->redirection = KIWI_EDIT_ESHOPITEM . $qs . '#zmena';
         }
         if (isset($get['ts'])) {
             $this->loadRecord();
             if (($ts = (int) $get['ts']) < 1 || !isset($this->index[$ts])) {
                 throw new Exception("Neplatné ID záznamu: {$ts}");
             }
             $prod = $this->products[$this->index[$ts]];
             $nts = !$prod->Sellout;
             mysql_query("UPDATE products SET Sellout='{$nts}', LastChange=CURRENT_TIMESTAMP WHERE ID={$prod->PID}");
             mysql_query("UPDATE prodbinds SET LastChange=CURRENT_TIMESTAMP WHERE ID={$ts}");
             $this->products[$this->index[$ts]]->Sellout = $nts;
             $this->products[$this->index[$ts]]->LastChange = date('Y-m-d H:i', time());
             $this->loadLastChange(false);
             $this->lastchange->register();
             $this->lastchange = null;
             $this->anchor->ID = $ts;
             $this->redirection = KIWI_EDIT_ESHOPITEM . $qs . '#zmena';
         }
         if (isset($get['d']) || isset($get['dd']) || isset($get['u']) || isset($get['uu'])) {
             if ((int) isset($get['d']) + (int) isset($get['dd']) + (int) isset($get['u']) + (int) isset($get['uu']) != 1) {
                 throw new Exception("Neplatný vstup - více než jeden příkaz pro přesun položky");
             }
             $dow = isset($get['d']) || isset($get['dd']);
             $tot = isset($get['dd']) || isset($get['uu']);
             $qv = $dow ? 'd' : 'u';
             if ($tot) {
                 $qv .= $qv;
             }
             $this->loadRecord();
             if (($cp = (int) $get[$qv]) < 1 || !isset($this->index[$cp])) {
                 throw new Exception("Neplatné ID záznamu: {$cp}");
             }
             $this->moveProduct($cp, $dow, $tot);
             $this->loadLastChange(false);
             $this->lastchange->register();
             $this->lastchange = null;
             $this->anchor->ID = $cp;
             $this->redirection = KIWI_EDIT_ESHOPITEM . $qs . '#zmena';
         }
     } else {
         throw new Exception("Chybějící ID nadřazené skupiny");
     }
     if (!empty($post)) {
         $xpost = strip_gpc_slashes($post);
         $this->all_checked = isset($xpost['checkall']);
         if (isset($xpost['check']) && is_array($xpost['check'])) {
             foreach ($xpost['check'] as $value) {
                 if (!is_numeric($value)) {
                     throw new Exception("Nepovolený vstup: check[]");
                 }
                 $this->checked[$value] = true;
             }
         }
         $act = 0;
         switch ($xpost['cmd']) {
             case 'speichern':
                 $this->handleUploads();
                 $this->title = $xpost['Nazev'];
                 if ($this->title == '') {
                     throw new Exception('Název řady nebyl vyplněn');
                 }
                 $this->description = $xpost['Popis'];
                 $this->auto = array_key_exists('Auto', $xpost);
                 if (array_key_exists('URL_rady', $xpost)) {
                     $this->url = $xpost['URL_rady'];
                 }
                 if (array_key_exists('htitle_rady', $xpost)) {
                     $this->htitle = $xpost['htitle_rady'];
                 }
                 $ue = $this->rights === true || $this->rights['EditURLs'];
                 $flds = array('title', 'description', 'icon', 'flags');
                 if ($ue || !$this->id) {
                     $flds[] = 'url';
                     $flds[] = 'htitle';
                     if ($this->auto || !$this->id && !$ue) {
                         $this->generateURL();
                         $this->generateTitle();
                     }
                 }
                 $this->flags = (int) array_key_exists('mainmenu_flag', $xpost);
                 foreach ($flds as $fld) {
                     ${$fld} = mysql_real_escape_string($this->{$fld});
                 }
                 if ($this->id) {
                     $ue_sql = $ue ? ", URL='{$url}', PageTitle='{$htitle}'" : '';
                     $icon_sql = $icon !== '' ? ", Icon='{$icon}'" : '';
                     mysql_query("UPDATE eshop SET Name='{$title}', Description='{$description}'{$ue_sql}{$icon_sql}, Flags={$flags}, LastChange=CURRENT_TIMESTAMP WHERE ID={$this->id}");
                 } else {
                     if ($this->parent == null) {
                         throw new Exception("Chybějící ID nadřazené skupiny");
                     }
                     $result = mysql_query("SELECT Count(ID) FROM eshop WHERE ID={$this->parent} AND Subgroup=1");
                     $row = mysql_fetch_row($result);
                     if ($row[0] != 1) {
                         throw new Exception("Neplatné ID nadřazené skupiny");
                     }
                     $result = mysql_query("SELECT MAX(Priority) FROM eshop WHERE Parent={$this->parent}");
                     $row = mysql_fetch_row($result);
                     $priority = (int) $row[0] + 1;
                     if ($ue) {
                         $ue_sql1 = ', URL, PageTitle';
                         $ue_sql2 = ",'{$url}', '{$htitle}'";
                     } else {
                         $ue_sql1 = $ue_sql2 = '';
                     }
                     if ($icon) {
                         $icon_sql1 = ', Icon';
                         $icon_sql2 = ",'{$icon}'";
                     } else {
                         $icon_sql1 = $icon_sql2 = '';
                     }
                     mysql_query("INSERT INTO eshop(Name, Description{$ue_sql1}{$icon_sql1}, Parent, Flags, Priority) VALUES ('{$title}', '{$description}'{$ue_sql2}{$icon_sql2}, {$this->parent}, {$flags}, {$priority})");
                     $this->id = mysql_insert_id();
                     Kiwi_EShop_Indexer::index($this->id, $this->parent);
                     $qs = "?ei={$this->id}";
                     $this->loadLastChange(false);
                     $this->lastchange->register();
                 }
                 $this->redirection = KIWI_EDIT_ESHOPITEM . $qs;
                 break;
             case 'Zurück':
                 $this->loadRecord();
                 $this->redirection = $this->getBackLink();
                 break;
             case 'aktivieren':
                 $act = 1;
             case 'deaktivieren':
                 $this->loadRecord();
                 if ($act && !$this->record->Active) {
                     throw new Exception("Pokud o nepřípustnou aktivaci záznamů");
                 }
                 $id_list = implode(',', $post['check']);
                 if ($id_list) {
                     mysql_query("UPDATE prodbinds SET Active={$act}, LastChange=CURRENT_TIMESTAMP WHERE ID IN ({$id_list})");
                 }
                 $this->loadLastChange(false);
                 $this->lastchange->register();
                 $this->lastchange = null;
                 $this->redirection = KIWI_EDIT_ESHOPITEM . $qs;
                 break;
             case 'neuer Artikel hinzufügen':
                 $this->redirection = KIWI_ADD_PRODUCT . $qs;
                 break;
             case 'vorhandene Artikel hinzufügen':
                 $this->redirection = KIWI_ADD_EXISTING_PRODUCT . $qs;
                 break;
             case 'entfernen':
                 $id_list = implode(',', $post['check']);
                 if ($id_list) {
                     mysql_query("DELETE FROM prodbinds WHERE ID IN ({$id_list})");
                     $this->loadLastChange(false);
                     $this->lastchange->register();
                 }
                 $this->redirection = KIWI_EDIT_ESHOPITEM . $qs;
                 break;
             default:
                 throw new Exception('Neočekávaný příkaz formuláře: ' . __CLASS__);
         }
     }
 }
 protected function deleteGroupsAndLines($ids)
 {
     if ($ids !== '') {
         $this->deleteIcons($ids);
         $nodelete = self::FLAG_NODELETE;
         $result = mysql_query("SELECT ID FROM eshop WHERE ID IN ({$ids}) AND Flags & {$nodelete}=0");
         $deleted_groups = array();
         while ($row = mysql_fetch_row($result)) {
             $deleted_groups[] = $row[0];
         }
         mysql_query("DELETE FROM eshop WHERE ID IN ({$ids}) AND Flags & {$nodelete}=0");
         // ID 1 odpovídá hlavní skupině, kterou nelze odstranit
         mysql_query("DELETE FROM prodbinds WHERE GID IN ({$ids})");
         Kiwi_EShop_Indexer::unindex($deleted_groups);
     }
 }