protected function getInstance()
 {
     if (self::$anchor == null) {
         self::$anchor = new KiwiAnchor(basename($_SERVER['PHP_SELF']));
         if (isset($_SESSION['KiwiAnchor'])) {
             self::$anchor->import($_SESSION['KiwiAnchor']);
         }
     }
     return self::$anchor;
 }
 public function handleInput($get, $post)
 {
     // todo: přidat práva
     $self = basename($_SERVER['PHP_SELF']);
     if (!empty($get)) {
         if (array_key_exists('sqs', $get)) {
             $this->sqs = $get['sqs'];
         }
         if (isset($get['nl'])) {
             if (($nl = (int) $get['nl']) < 1) {
                 throw new Excenlion("Neplatná hodnota parametru \"nl\": {$nl}");
             }
             $this->id = $nl;
             $anchor = new CurrentKiwiAnchor();
             $anchor->set_key_value(KIWI_NEWSLETTERS, $this->id);
         }
         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");
             }
             if (!$this->productsEnabled()) {
                 throw new Exception("Neplatný vstup - produkty newsletterů nejsou aktivovány");
             }
             $dow = isset($get['d']) || isset($get['dd']);
             $tot = isset($get['dd']) || isset($get['uu']);
             $qv = $dow ? 'd' : 'u';
             if ($tot) {
                 $qv .= $qv;
             }
             $this->loadProducts();
             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;
             $qs = $this->consQS();
             $this->redirection = KIWI_EDIT_NEWSLETTER . $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;
             }
         }
         switch ($post['cmd']) {
             case 'speichern':
                 $this->title = $xpost['Nazev'];
                 if ($this->title == '') {
                     throw new Exception('Název newsletteru nebyl vyplněn');
                 }
                 $this->content = $this->parseFckEditorInput($xpost['knlrfc_content']);
                 $this->start = $xpost['Start'];
                 $this->active = array_key_exists('Aktivni', $xpost) && $xpost['Aktivni'] == 'on' ? 1 : 0;
                 $this->saveData();
                 $qs = $this->consQS();
                 $this->redirection = $self . $qs . '#stred';
                 break;
             case 'Artikel hinzufügen':
                 if ($this->productsEnabled()) {
                     $qs = $this->consQS();
                     $this->redirection = KIWI_ADD_EXISTING_PRODUCT . $qs;
                 }
                 break;
             case 'entfernen':
                 $id_list = implode(',', $post['check']);
                 if ($id_list) {
                     $nlid = (int) $this->id;
                     mysql_query("DELETE FROM nlproducts WHERE NLID={$nlid} AND ID IN ({$id_list})");
                     $this->loadLastChange(false);
                     $this->lastchange->register();
                 }
                 $qs = $this->consQS();
                 $this->redirection = $self . $qs . '#stred';
                 break;
             default:
                 throw new Exception('Neočekávaný příkaz formuláře: ' . __CLASS__);
         }
     }
 }
 public function handleInput($get, $post)
 {
     // todo: přidat práva
     $self = basename($_SERVER['PHP_SELF']);
     if (!empty($get)) {
         if (array_key_exists('ei', $get)) {
             if (($ei = (int) $get['ei']) < 1) {
                 throw new Exception("Neplatná hodnota parametru \"ei\": {$ei}");
             }
             $this->eshop_item = $ei;
         }
         if (array_key_exists('sei', $get)) {
             if ($this->eshop_item) {
                 throw new Exception("Souběžné použití parametrů \"ei\" a \"sei\"");
             }
             if (($sei = (int) $get['sei']) < 1) {
                 throw new Exception("Neplatná hodnota parametru \"sei\": {$sei}");
             }
             $this->s_eshop_item = $sei;
         }
         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 (array_key_exists('sqs', $get)) {
             $this->sqs = $get['sqs'];
         }
         if (isset($get['p'])) {
             if (($p = (int) $get['p']) < 1) {
                 throw new Exception("Neplatná hodnota parametru \"p\": {$p}");
             }
             $this->id = $p;
             $anchor = new CurrentKiwiAnchor();
             $anchor->set_key_value(KIWI_PRODUCTS, $this->id);
         }
         if (isset($get['rp'])) {
             $qs = $this->consQS();
             $this->removeProductPhoto();
             $this->redirection = $self . $qs . '#stred';
             return;
         }
         if (isset($get['rpe'])) {
             if (($rpe = (int) $get['rpe']) < 1) {
                 throw new Exception("Neplatná hodnota parametru \"rpe\": {$rpe}");
             }
             $qs = $this->consQS();
             $this->removeExtraPhoto($rpe);
             $this->redirection = $self . $qs . '#stred';
             return;
         }
         if (isset($get['rpi'])) {
             if (($rpi = (int) $get['rpi']) < 1) {
                 throw new Exception("Neplatná hodnota parametru \"rpi\": {$rpi}");
             }
             $qs = $this->consQS();
             $this->removeIllustrativePhoto($rpi);
             $this->redirection = $self . $qs . '#stred';
             return;
         }
         if (isset($get['rpv'])) {
             $qs = $this->consQS();
             if (($rpv = (int) $get['rpv']) < 1) {
                 throw new Exception("Neplatná hodnota parametru \"rpv\": {$rpv}");
             }
             $propid = $this->removePropertyValue($rpv);
             $this->redirection = $self . $qs . '#prp' . $propid;
             return;
         }
         if (isset($get['apv'])) {
             $qs = $this->consQS();
             if (($apv = (int) $get['apv']) < 1) {
                 throw new Exception("Neplatná hodnota parametru \"apv\": {$apv}");
             }
             $propid = $this->addPropertyValue($apv);
             $this->redirection = $self . $qs . '#prp' . $propid;
             return;
         }
         if (isset($get['anpv'])) {
             $qs = $this->consQS();
             $anpv = explode(':', $get['anpv'], 2);
             try {
                 if (sizeof($anpv) != 2) {
                     throw new Exception();
                 }
                 $propid = $anpv[0];
                 if ($propid < 1) {
                     throw new Exception();
                 }
                 $pval = $anpv[1];
             } catch (Exception $e) {
                 throw new Exception("Neplatná hodnota parametru \"anpv\": {$anpv}");
             }
             $this->addNewPropertyValue($propid, $pval);
             $this->redirection = $self . $qs . '#prp' . $propid;
             return;
         }
         if (array_key_exists('eg', $get)) {
             if ($this->id == 0) {
                 throw new Exception('Pokus o editaci sdružených produktů s dosud nevytvořeným produktem');
             }
             $group = $this->acquireGroupedProductsGroup();
             $this->redirection = KIWI_EDIT_ESHOPITEM . "?ei={$group}&gp={$this->id}";
             return;
         }
     }
     if (!empty($post)) {
         $xpost = strip_gpc_slashes($post);
         switch ($post['cmd']) {
             case 'speichern':
                 $this->title = $xpost['Nazev_vyrobku'];
                 if ($this->title == '') {
                     throw new Exception('Název výrobku nebyl vyplněn');
                 }
                 $this->code = $xpost['Kod_vyrobku'];
                 $this->shortdesc = $xpost['ZkracenyPopis'];
                 $this->longdesc = $this->parseFckEditorInput($xpost['kprofc_ldsc']);
                 //$this->longdesc = $xpost['Popis'];
                 $this->auto = array_key_exists('Auto', $xpost);
                 if (array_key_exists('URL_vyrobku', $xpost)) {
                     $this->url = $xpost['URL_vyrobku'];
                 }
                 if (array_key_exists('htitle_vyrobku', $xpost)) {
                     $this->htitle = $xpost['htitle_vyrobku'];
                 }
                 $this->collection = $xpost['Kolekce'];
                 $this->original_cost = (double) $xpost['Puvodni_cena'];
                 $this->new_cost = (double) $xpost['Nova_cena'];
                 $this->ws_cost = (double) $xpost['VO_cena'];
                 $this->novelty = array_key_exists('Novinka', $xpost) && $xpost['Novinka'] == 'on' ? 1 : 0;
                 $this->action = array_key_exists('Akce', $xpost) && $xpost['Akce'] == 'on' ? 1 : 0;
                 $this->discount = array_key_exists('Sleva', $xpost) && $xpost['Sleva'] == 'on' ? 1 : 0;
                 $this->sellout = array_key_exists('Vyprodej', $xpost) && $xpost['Vyprodej'] == 'on' ? 1 : 0;
                 $this->exposed = array_key_exists('Exponovany', $xpost) && $xpost['Exponovany'] == 'on' ? 1 : 0;
                 $this->active = array_key_exists('Aktivni', $xpost) && $xpost['Aktivni'] == 'on' ? 1 : 0;
                 $this->handleUploads();
                 $this->saveData();
                 $qs = $this->consQS();
                 $this->redirection = $self . $qs . '#stred';
                 break;
             case 'kopieren':
                 if ($this->id === 0) {
                     throw new Exception('Pokus kopírovat dosud nevytvořený produkt!');
                 }
                 $copy = new Kiwi_Product_Copy($this->id);
                 $this->redirection = $self . "?p=" . $copy->getCopyPID();
                 break;
             default:
                 throw new Exception('Neočekávaný příkaz formuláře: ' . __CLASS__);
         }
     }
 }