insert('lists', $_POST, true); $products_ids = (!empty($_POST['products_ids'])) ? $_POST['products_ids'] : array(); foreach ($products_ids as $pid) { $data = array('list_id' => $id, 'product_id' => $pid); $mysql->insert('list_items', $data); } if ($_POST['parent'] != 'none') { $data = array( 'title' => $_POST['title'], 'parent' => $_POST['parent'], 'type' => 'list', 'link_id' => $id ); $mysql->insert('groups', $data); } redirect('admin/lists.php'); break; case 'edit' : $id = $_POST['id']; if ($id) { $mysql->update('lists', array('title' => $_POST['title']), $id); $mysql->delete('list_items', array('list_id', $id)); $mysql->query("DELETE FROM groups WHERE type = 'list' AND link_id = $id"); if ($_POST['parent'] != 'none') { $data = array( 'title' => $_POST['title'], 'parent' => $_POST['parent'], 'type' => 'list', 'link_id' => $id ); $mysql->insert('groups', $data); } $products_ids = (!empty($_POST['products_ids'])) ? $_POST['products_ids'] : array(); foreach ($products_ids as $pid) { $data = array('list_id' => $id, 'product_id' => $pid); $mysql->insert('list_items', $data); } } redirect('admin/lists.php'); break; } $data['products'] = $mysql->select('id')->from('products')->order_by('title')->fetch_dbda('Product', false); switch (GET_ACTION) { case 'add' : $data['title'] = 'Новый список'; $page = '_add'; break; case 'edit' : $data['list'] = new pList($_GET['id']); $data['title'] = 'Редактировать'; $page = '_edit'; break; } load_template('admin/list' . $page, $data); ?>