<?php
$cms_root_path = "../../../";
require_once($cms_root_path."includes/compatibility_includer.php");

use Mtc\Cms\Models\PageList;

if (empty($_POST['item_list_id']) || !is_numeric($_POST['item_list_id'])) {
    header("HTTP/1.0 400 Bad Request");
    $error_message = "item_list_id missing from save request or malformed.";
    ContentManagerPanel::addMessage($error_message);
    exit($error_message);
}

$page_list = PageList::find($_POST['item_list_id']);

if (empty($page_list)) {
    header("HTTP/1.0 409 Conflict");
    $error_message = "The list of which settings you attempted to save was not found.";
    ContentManagerPanel::addMessage($error_message);
    exit($error_message);
}

$page_list->lock                   = $_POST['settings']['list_lock'];
$page_list->allow_more             = $_POST['settings']['list_allow_more'];
$page_list->add_list_item_to_top   = $_POST['settings']['list_to_top'];
$page_list->name                   = $_POST['settings']['list_name'];
$page_list->info                   = $_POST['settings']['list_info'];
$page_list->allow_more_min         = $_POST['settings']['list_allow_more_min'];
$page_list->allow_more_max         = $_POST['settings']['list_allow_more_max'];

if (isset($_POST['settings']['list_type'])) {
    $page_list->type = $_POST['settings']['list_type'];
}

$page_list->save();

die("true");
