insert('products', $_POST, true); $upl = new Uploader('Image'); if ($upl->picture) { $upl->picture->name = $id; $upl->picture->resample(180, 300, 'img/products'); $upl->picture->resample(20, 20, 'img/products/thumbs'); } if (!empty($_POST['description'])) { foreach ($_POST['description'] as $d) { $data = array('product_id' => $id, 'header' => $d[0], 'value' => $d[1]); $mysql->insert('products_description', $data); } } if (!empty($_POST['table'][0][0])) { foreach ($_POST['table'] as $y => $values) { foreach ($values as $x => $value) { $data = array('product_id' => $id, 'x' => $x, 'y' => $y, 'value' => $value); $mysql->insert('products_table', $data); } } } if ($_POST['parent'] != 'none') { $data = array( 'title' => $_POST['title'], 'parent' => $_POST['parent'], 'type' => 'product', 'link_id' => $id ); $mysql->insert('groups', $data); } redirect('admin/index.php'); break; case 'edit' : $id = $_POST['id']; $mysql->update('products', $_POST, $id); $upl = new Uploader('Image'); if ($upl->picture) { $upl->picture->name = $id; $upl->picture->resample(180, 300, 'img/products'); $upl->picture->resample(20, 20, 'img/products/thumbs'); } $mysql->delete('products_description', array('product_id', $id)); $mysql->delete('products_table', array('product_id', $id)); if (!empty($_POST['description'])) { foreach ($_POST['description'] as $d) { $data = array('product_id' => $id, 'header' => $d[0], 'value' => $d[1]); $mysql->insert('products_description', $data); } } if (!empty($_POST['table'][0][0])) { foreach ($_POST['table'] as $y => $values) { foreach ($values as $x => $value) { $data = array('product_id' => $id, 'x' => $x, 'y' => $y, 'value' => $value); $mysql->insert('products_table', $data); } } } $mysql->query("DELETE FROM groups WHERE type = 'product' AND link_id = $id"); if ($_POST['parent'] != 'none') { $data = array( 'title' => $_POST['title'], 'parent' => $_POST['parent'], 'type' => 'product', 'link_id' => $id ); $mysql->insert('groups', $data); } redirect('admin/index.php'); break; } switch (GET_ACTION) { case 'add' : $data['title'] = 'Добавить продукт'; $page = '_add'; break; case 'edit' : $data['product'] = new Product($_GET['id']); $data['title'] = 'Редактировать'; $page = '_edit'; break; case 'copy': $id = intval($_GET['id']); $product = $mysql->select('*')->from('products')->where('id', $id)->fetch_array(); $description = $mysql->select('header', 'value')->from('products_description')->where('product_id', $id)->order_by('id')->fetch_object(false); $table = $mysql->select('x', 'y', 'value')->from('products_table')->where('product_id', $id)->order_by('id')->fetch_object(false); unset($product['id']); $product['title'] = $product['title'] . ' (Копия)'; $new_id = $mysql->insert('products', $product, true); foreach ($description as $d) { $data = array('product_id' => $new_id, 'header' => $d->header, 'value' => $d->value); $mysql->insert('products_description', $data); } foreach ($table as $t) { $data = array('product_id' => $new_id, 'x' => $t->x, 'y' => $t->y, 'value' => $t->value); $mysql->insert('products_table', $data); } $image = PRODUCT_IMAGE_DIR . $id . '.jpg'; $thumb = PRODUCT_THUMB_DIR . $id . '.jpg'; if (file_exists($image)) copy($image, PRODUCT_IMAGE_DIR . $new_id . '.jpg'); if (file_exists($thumb)) copy($thumb, PRODUCT_THUMB_DIR . $new_id . '.jpg'); redirect('admin/index.php'); break; } load_template('admin/product' . $page, $data); ?>