Example #1
0
            //update data
            $stmt = $db->prepare('UPDATE ' . NV_PREFIXLANG . '_' . $module_data . '_room SET parentid= :parentid, title= :title, alias = :alias, description = :description, keywords= :keywords, edit_time=' . NV_CURRENTTIME . ' WHERE roomid =' . $roomid);
            $stmt->bindParam(':parentid', $data['parentid'], PDO::PARAM_INT);
            $stmt->bindParam(':title', $data['title'], PDO::PARAM_STR);
            $stmt->bindParam(':alias', $data['alias'], PDO::PARAM_STR);
            $stmt->bindParam(':keywords', $data['keywords'], PDO::PARAM_STR);
            $stmt->bindParam(':description', $data['description'], PDO::PARAM_STR, strlen($data['description']));
            $stmt->execute();
            if ($stmt->rowCount()) {
                if ($data['parentid'] != $parentid_old) {
                    $result = $db->query("SELECT max(weight) FROM " . NV_PREFIXLANG . "_" . $module_data . "_room WHERE parentid='" . $data['parentid'] . "'");
                    $weight = $result->fetch();
                    $weight = intval($weight) + 1;
                    $sql = "UPDATE " . NV_PREFIXLANG . "_" . $module_data . "_room SET weight='" . $weight . "' WHERE roomid='" . intval($roomid) . "'";
                    $db->query($sql);
                    nv_fix_room_order();
                }
                nv_insert_logs(NV_LANG_DATA, $module_name, $lang_module['edit_room'], $data['title'], $admin_info['userid']);
                Header("Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=" . $op . "&parentid=" . $data['parentid'] . "");
                die;
            } else {
                $error = $lang_module['errorsave'];
            }
            $db->sqlreset();
        }
    }
}
//select data
if ($roomid > 0) {
    $sql = "SELECT * FROM " . NV_PREFIXLANG . "_" . $module_data . "_room WHERE roomid = '" . $roomid . "' ORDER BY weight ASC";
    $result = $db->query($sql);
function nv_fix_room_order($parentid = 0, $order = 0, $lev = 0)
{
    global $db, $db_config, $lang_module, $lang_global, $module_name, $module_data, $op;
    $query = "SELECT roomid, parentid FROM " . NV_PREFIXLANG . "_" . $module_data . "_room WHERE parentid='" . $parentid . "' ORDER BY weight ASC";
    $result = $db->query($query);
    $array_room_order = array();
    while ($row = $result->fetch()) {
        $array_room_order[] = $row['roomid'];
    }
    $db->sqlreset();
    $weight = 0;
    if ($parentid > 0) {
        $lev++;
    } else {
        $lev = 0;
    }
    foreach ($array_room_order as $roomid_i) {
        $order++;
        $weight++;
        $sql = "UPDATE " . NV_PREFIXLANG . "_" . $module_data . "_room SET weight='" . $weight . "', orders='" . $order . "', lev='" . $lev . "' WHERE roomid='" . intval($roomid_i) . "'";
        $db->query($sql);
        $order = nv_fix_room_order($roomid_i, $order, $lev);
    }
    $numsubroom = $weight;
    if ($parentid > 0) {
        $sql = "UPDATE " . NV_PREFIXLANG . "_" . $module_data . "_room SET numsubroom='" . $numsubroom . "'";
        if ($numsubroom == 0) {
            $sql .= ",subroomid=''";
        } else {
            $sql .= ",subroomid='" . implode(",", $array_room_order) . "'";
        }
        $sql .= " WHERE roomid='" . intval($parentid) . "'";
        $db->query($sql);
    }
    return $order;
}