$res .= "</table></center>";
    $res .= "<input type='hidden' id='action' name ='action' value='createaccount'>";
    $res .= "</form>";
    $res .= "<div class='menu_button_on_right'><span id='account_save_result'></span>";
    $res .= "<a href='#' onClick='cancelAccount();return false;'><img src='images/button_cancel_32.png'></a>&nbsp;&nbsp;";
    $res .= "<a href='#' onClick='createAccount();return false;'><img src='images/button_ok_32.png'></a>&nbsp;&nbsp;&nbsp;";
    $res .= "</div>";
    print $res;
    exit;
}
if ($action == "createaccount") {
    $mg = mg_connect($config, "", "", "");
    if ($mg) {
        $stmt = new mg_stmt_insert($mg, "accounts", $mg_account_defaults);
        $stmt->addColumnValueDate("createtime");
        $stmt->addColumnValue("name", $_POST["account_name"]);
        $stmt->addColumnValue("id_engine", intval($_POST["id_engine"]));
        if (!$stmt->checkNotNull($mg_account_not_null)) {
            $res = "Error&nbsp;&nbsp;&nbsp;";
        } else {
            $stmt->execute();
            $res = "Success&nbsp;&nbsp;&nbsp;";
        }
        $res = "Success&nbsp;&nbsp;&nbsp;";
        //$res .= $s;
    }
    print $res;
    exit;
}
if ($action == "saveaccount") {
    $id = $_POST["account_id"];
    $res .= "<input type='hidden' id='output_type' name='output_type' value='default'>";
    $res .= "<input type='hidden' id='action' name='action' value='createtarget'>";
    $res .= "</form>";
    $res .= "<div class='menu_button_on_right'><span id='target_save_result'></span>";
    $res .= "<a href='#' onClick='cancelTarget();return false;'><img src='images/button_cancel_32.png'></a>&nbsp;&nbsp;";
    $res .= "<a href='#' onClick='createTarget();return false;'><img src='images/button_ok_32.png'></a>&nbsp;&nbsp;&nbsp;";
    $res .= "</div>";
    print $res;
    exit;
}
if ($action == "createtarget") {
    $mg = mg_connect($config, "", "", "");
    if ($mg) {
        $stmt = new mg_stmt_insert($mg, "targets", $mg_target_defaults);
        $stmt->addColumnValueDate("createtime");
        $stmt->addColumnValue("id_account", intval($_POST["id_account"]));
        $stmt->addColumnValue("name", $_POST["name"]);
        $stmt->addColumnValue("output_type", $_POST["output_type"]);
        $stmt->addColumnValue("target_type", $_POST["target_type"]);
        $stmt->addColumnValue("target_parameters", $_POST["target_parameters"]);
        $stmt->addColumnValue("queue_dir", $_POST["queue_dir"]);
        if (!$stmt->checkNotNull($mg_target_not_null)) {
            $res = "Error&nbsp;&nbsp;&nbsp;";
        } else {
            $stmt->execute();
            $res = "Success&nbsp;&nbsp;&nbsp;";
        }
        $res = "Success&nbsp;&nbsp;&nbsp;";
    }
    print $res;
    exit;
         $mode = "update";
     }
 }
 if ($match == 'host') {
     $query = array('$and' => array($query, array("url_host" => (string) $item->url_host)));
     $count = mg_row_count($mg, "sources", $query);
     if ($count > 1) {
         continue;
     }
     if ($count == 1) {
         $mode = "update";
     }
 }
 if ($mode == 'insert') {
     $stmt = new mg_stmt_insert($mg, "sources", $mg_source_defaults);
     $stmt->addColumnValue("id_account", intval($id_account_current));
     $stmt->addColumnValueDate("createtime");
     $enabled = $status;
 } else {
     if ($strategy == 'skip') {
         continue;
     }
     $stmt = new mg_stmt_update($mg, "sources");
     $stmt->setQuery($query);
     $enabled = (string) $item->enabled;
 }
 $stmt->addColumnValue("deleted", "0");
 $stmt->addColumnValue("enabled", $enabled);
 if ($reset == "1") {
     $stmt->addColumnValue("crawl_mode", "2");
 } else {
    $res .= "</table></center>";
    $res .= "<input type='hidden' id='action' name ='action' value='createuser'>";
    $res .= "</form>";
    $res .= "<div class='menu_button_on_right'><span id='user_save_result'></span>";
    $res .= "<a href='#' onClick='cancelUser();return false;'><img src='images/button_cancel_32.png'></a>&nbsp;&nbsp;";
    $res .= "<a href='#' onClick='createUser();return false;'><img src='images/button_ok_32.png'></a>&nbsp;&nbsp;&nbsp;";
    $res .= "</div>";
    print $res;
    exit;
}
if ($action == "createuser") {
    $mg = mg_connect($config, "", "", "");
    if ($mg) {
        $stmt = new mg_stmt_insert($mg, "users", $mg_user_defaults);
        $stmt->addColumnValueDate("createtime");
        $stmt->addColumnValue("user_name", $_POST["user_name"]);
        if ($_POST["user_level"] == "2") {
            $stmt->addColumnValue("id_account", 0);
        } else {
            $stmt->addColumnValue("id_account", intval($_POST["id_account"]));
        }
        $stmt->addColumnValue("user_password", $_POST["user_password"]);
        $stmt->addColumnValue("user_level", $_POST["user_level"]);
        if (isset($_POST["change_password"]) && trim($_POST["change_password"] == "1")) {
            $stmt->addColumnValue("change_password_next_logon", "1");
        } else {
            $stmt->addColumnValue("change_password_next_logon", "0");
        }
        if (!$stmt->checkNotNull($mg_user_not_null)) {
            $res = "Error&nbsp;&nbsp;&nbsp;";
        } else {
    $res .= "</table></center>";
    $res .= "<input type='hidden' id='action' name ='action' value='createengine'>";
    $res .= "</form>";
    $res .= "<div class='menu_button_on_right'><span id='engine_save_result'></span>";
    $res .= "<a href='#' onClick='cancelEngine();return false;'><img src='images/button_cancel_32.png'></a>&nbsp;&nbsp;";
    $res .= "<a href='#' onClick='createEngine();return false;'><img src='images/button_ok_32.png'></a>&nbsp;&nbsp;&nbsp;";
    $res .= "</div>";
    print $res;
    exit;
}
if ($action == "createengine") {
    $mg = mg_connect($config, "", "", "");
    if ($mg) {
        $stmt = new mg_stmt_insert($mg, "engines", $mg_engine_defaults);
        $stmt->addColumnValueDate("createtime");
        $stmt->addColumnValue("name", $_POST["engine_name"]);
        if (!$stmt->checkNotNull($mg_engine_not_null)) {
            $res = "Error&nbsp;&nbsp;&nbsp;";
        } else {
            $stmt->execute();
            $res = "Success&nbsp;&nbsp;&nbsp;";
        }
        $res = "Success&nbsp;&nbsp;&nbsp;";
    }
    print $res;
    exit;
}
if ($action == "saveengine") {
    $id = $_POST["engine_id"];
    if ($id == "") {
        $res = "Error&nbsp;&nbsp;&nbsp;";