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__); } } }
public function handleInput($get, $post) { // todo: ohlidat prava $self = basename($_SERVER['PHP_SELF']); $qs = ''; if (!empty($get)) { if (isset($get['sg'])) { if (($sg = (int) $get['sg']) < 1) { throw new Exception("Neplatné ID záznamu: {$sg}"); } $this->id = $sg; $qs = "?sg={$sg}"; } if (isset($get['n'])) { $result = mysql_query("SELECT Count(*) FROM eshop WHERE ID={$this->id} AND Subgroup=1"); if ($row = mysql_fetch_row($result)) { if ($row[0] == 1) { $this->new_subgroup = true; } } if (!$this->new_subgroup) { throw new Exception("Neplatné ID záznamu: {$this->id}"); } } 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(); $this->loadEShopItems(); 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}"); } $id_list_rec = implode(',', $this->getRecursiveIdList(array($as))); $this->activateGroupsAndLines($id_list_rec, $nas); /* $this->records[$this->index[$as]]->Active = $nas; $this->records[$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 = $self . $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(); $this->loadEShopItems(); if (($cp = (int) $get[$qv]) < 1 || !isset($this->index[$cp])) { throw new Exception("Neplatné ID záznamu: {$cp}"); } $this->moveItem($cp, $dow, $tot); $this->loadLastChange(false); $this->lastchange->register(); $this->lastchange = null; $this->anchor->ID = $cp; $this->redirection = $self . $qs . '#zmena'; } } 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 skupiny nebyl vyplněn'); } $this->description = $xpost['Popis']; $this->auto = array_key_exists('Auto', $xpost); if (array_key_exists('URL_skupiny', $xpost)) { $this->url = $xpost['URL_skupiny']; } if (array_key_exists('htitle_skupiny', $xpost)) { $this->htitle = $xpost['htitle_skupiny']; } $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 = array_key_exists('mainmenu_flag', $xpost) ? $this->flags | self::FLAG_FRONTMENU : $this->flags & ~self::FLAG_FRONTMENU; foreach ($flds as $fld) { ${$fld} = mysql_real_escape_string($this->{$fld}); } if (!$this->id) { throw new Exception("Neplatné ID záznamu: {$this->id}"); } if (!$this->new_subgroup) { if ($this->id == 1) { throw new Exception('Neplatná operace: editace nastavení hlavní skupiny'); } else { $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}"); } } elseif ($title != '') { $result = mysql_query("SELECT Max(Priority) FROM eshop WHERE Parent={$this->id}"); if ($row = mysql_fetch_row($result)) { $priority = (int) $row[0] + 1; } else { throw new Exception("Chyba při načítání priority položek eshopu"); } 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}, Subgroup, Parent, Flags, Priority) VALUES ('{$title}', '{$description}'{$ue_sql2}{$icon_sql2}, 1, {$this->id}, {$flags}, {$priority})"); $new_id = mysql_insert_id(); Kiwi_EShop_Indexer::index($new_id, $this->id); $qs = "?sg={$new_id}"; $this->loadLastChange(false); $this->lastchange->register(); } $this->redirection = $self . $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_rec = implode(',', $this->getRecursiveIdList($xpost['check'])); $this->activateGroupsAndLines($id_list_rec, $act); $this->loadLastChange(false); $this->lastchange->register(); $this->lastchange = null; $this->redirection = $self . $qs; break; case 'Serie hinzufügen': $this->redirection = KIWI_ADD_ESHOPITEM . "?sg={$this->id}"; break; case 'Gruppe hinzufügen': $this->redirection = KIWI_ADD_ESHOPGROUP . "?sg={$this->id}&n"; break; case 'entfernen': if (sizeof($xpost['check']) > 0) { $id_list_rec = implode(',', $this->getRecursiveIdList($xpost['check'])); $this->deleteGroupsAndLines($id_list_rec); $this->loadLastChange(false); $this->lastchange->register(); $this->redirection = $self . $qs; } break; default: throw new Exception('Neočekávaný příkaz formuláře: ' . __CLASS__); } } }