Getting ‘Permission denied’ error when trying to add product image to database using Admin panel

Hello.
I am working on an e-commerce project. Using the Admin panel, I tried to add a picture with product data in the database, but it failed and errors were displayed.

**
THIS SHOWED AS AN ERROR AFTER ATTEMPTING TO ADD A PRODUCT WITH A PICTURE**

Warning: move_uploaded_file(product_images/dress.jpeg): failed to open stream: Permission denied in /opt/lampp/htdocs/project/admin_area/includes/insert_product.php on line 115

Warning: move_uploaded_file(): Unable to move ‘/opt/lampp/temp/php48ULD8’ to ‘product_images/dress.jpeg’ in /opt/lampp/htdocs/project/admin_area/includes/insert_product.php on line 115

And this is the code where the error is showing


    <div class="form_box">

     <form action="" method="post" enctype="multipart/form-data">
       
       <table align="center" width="100%">
         
         <tr>
           <td colspan="7">
           <h2>Add Product</h2>
           <div class="border bottom"></div><! --/. border bottom -->
           </td>
         </tr>
         
         <tr>
           <td><b>Product Title:</b></td>
           <td><input type="text" name="product_title" size="60" required/></td>
         </tr>
         
         <tr>
           <td><b>Product Category:</b></td>
           <td>
            <select name="product_cat">
              <option>Select a Category</option>
              
              <?php 
              $get_cats ="select * from categories";
        
        $run_cats = mysqli_query($con, $get_cats);
        
        while($row_cats=mysqli_fetch_array($run_cats)){
            $cat_id = $row_cats['cat_id'];
            
            $cat_title = $row_cats['cat_title'];
            
            echo "<option value='$cat_id'>$cat_title</option>";
        }
              ?>
            </select>
           </td>
           
         </tr>
         
         <tr>
           <td><b>Product Brand:</b></td>
           <td>
            <select name="product_brand">
              <option>Select a Brand</option>
            <?php
              $get_brands = "select * from brands";
        
        $run_brands = mysqli_query($con, $get_brands);
        
        while($row_brands = mysqli_fetch_array($run_brands)){
             $brand_id = $row_brands['brand_id'];
             
             $brand_title = $row_brands['brand_title'];
             
             echo "<option value='$brand_id'>$brand_title</option>";
        }
        
        ?>
            </select>
           </td>
           
         </tr>
        
        <tr>
          <td><b>Product Image: </b></td>
          <td><input type="file" name="product_image" /></td>
        </tr>
        
        <tr>
          <td><b>Product Price: </b></td>
          <td><input type="text" name="product_price" required/></td>
        </tr>
        
        <tr>
           <td valign="top"><b>Product Description:</b></td>
           <td><textarea name="product_desc"  rows="10"></textarea></td>
        </tr>
        
        
        <tr>
          <td><b>Product Keywords: </b></td>
          <td><input type="text" name="product_keywords" required/></td>
        </tr>
        
        <tr>
           <td></td>
           <td colspan="7"><input type="submit" name="insert_post" value="Add Product"/></td>
        </tr>
       </table>
       
     </form>
     
  </div><!-- /.form_box -->

<?php 

if(isset($_POST['insert_post'])){
   $product_title = $_POST['product_title'];
   $product_cat = $_POST['product_cat'];
   $product_brand = $_POST['product_brand'];
   $product_price = $_POST['product_price'];
   $product_desc = trim(mysqli_real_escape_string($con,$_POST['product_desc']));
   $product_keywords = $_POST['product_keywords']; 
   
   
   // Getting the image from the field
   $product_image  = $_FILES['product_image']['name'];
   $product_image_tmp = $_FILES['product_image']['tmp_name'];
   
   move_uploaded_file($product_image_tmp,"product_images/$product_image");
   
   $insert_product = " insert into products (product_cat,product_brand,product_title,product_price,product_desc,product_image,product_keywords) 
   values ('$product_cat','$product_brand','$product_title','$product_price','$product_desc','$product_image','$product_keywords') ";

   $insert_pro = mysqli_query($con, $insert_product);
   
   if($insert_pro){
    echo "<script>alert('Product Has Been inserted successfully!')</script>";
    
    //echo "<script>window.open('index.php?insert_product','_self')</script>";
   }
   
   }
?>

I tried to add various permissions, but nothing could be solved.

How to pass Model data to JavaScript function in ASP.NET Core MVC?

I want to pass my Model data to JS script and file. I have a file which creates a diagram to show my users some data. How can I pass my data to inline JS script or JS file?

Note: Using ASP .NET Core with MVC

JS Code:

onload="javascript:chartMaker(@Model.Context.Meetings.Where(c => c.Status == "Done").Count(),@Model.Context.Meetings.Where(c => c.Status == "Processing").Count(),@Model.Context.Meetings.Where(c => c.MeetingStatus == "Done").Count())"

    <script type="text/javascript">
        function chartMaker(meetingDone,meetingInProcess,meetingGoingOn) {
            const chartOrderStatistics = document.querySelector('#orderStatisticsChartLocal');
            let cardColor, headingColor, axisColor, shadeColor, borderColor;
            cardColor = config.colors.white;
            headingColor = config.colors.headingColor;
            axisColor = config.colors.axisColor;
            borderColor = config.colors.borderColor;
        orderChartConfig = {
            chart: {
                height: 165,
                width: 130,
                type: 'donut'
            },
            labels: ['Done', 'Processing', 'Processing'],
                series: [parseInt(meetingDone), 20, 30],
            colors: [config.colors.primary, config.colors.secondary, config.colors.info],
            stroke: {
                width: 5,
                colors: cardColor
            },
            dataLabels: {
                enabled: false,
                formatter: function (val, opt) {
                    return parseInt(val) + '%';
                }
            },
            legend: {
                show: false
            },
            grid: {
                padding: {
                    top: 0,
                    bottom: 0,
                    right: 15
                }
            },
            plotOptions: {
                pie: {
                    donut: {
                        size: '75%',
                        labels: {
                            show: true,
                            value: {
                                fontSize: '1.5rem',
                                fontFamily: 'Public Sans',
                                color: headingColor,
                                offsetY: -15,
                                formatter: function (val) {
                                    return parseInt(val) + '%';
                                }
                            },
                            name: {
                                offsetY: 20,
                                fontFamily: 'Public Sans'
                            },
                            total: {
                                show: true,
                                fontSize: '0.8125rem',
                                color: axisColor,
                                label: 'Monthly',
                                formatter: function (w) {
                                    return '38%';
                                }
                            }
                        }
                    }
                }
            }
        };
        if (typeof chartOrderStatistics !== undefined && chartOrderStatistics !== null) {
            const statisticsChart = new ApexCharts(chartOrderStatistics, orderChartConfig);
            statisticsChart.render();
        }
        }
    </script>

Using this js code with onLoad method attached to my html script and calling method with its function name.

It doesn’t really matter if it is inline JS code or new JS file for me to pass Model data to js. For example I need to pass given data in function name:

@Model.Context.Meetings.Where(c => c.Status == "Done").Count()

How can it be done or better way to think another solution to pass data tı JS code and use it as a normal variable in this code, any suggestion?

I have tried passing directly with razor syntax but it doesn’t work

“ReferenceError: setTimeout” while merging two tabs into one pdf using Google Apps Script

Continuing my previous question, I want to merge two tabs of Google Sheets into one pdf. @Tanaike proposed a solution that worked on this sheet as required. Here is the proposed code with javascript library:

function myFunction(e) {

   var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Form responses 1");
   SpreadsheetApp.flush();

   const output = [
    {sheetName: "Quan", range: "A2:Q28"},
    {sheetName: "Qual", range: "A1:I27"},
    ];

    var ss = SpreadsheetApp.getActiveSpreadsheet();
    const url_base = ss.getUrl().replace(/edit$/,'');
    const headers = {authorization: "Bearer " + ScriptApp.getOAuthToken()};
    const data = output.map(({sheetName, range}) => {
    const s = ss.getSheetByName(sheetName);
    const gid = s.getSheetId();
    const r = s.getRange(range);
    const r1 = r.getRow() - 1;
    const c1 = r.getColumn() - 1;
    const r2 = r1 + r.getNumRows();
    const c2 = c1 + r.getNumColumns();
    const url = `${url_base}export?exportFormat=pdf&format=pdf`
      + '&size=letter'
      + '&portrait=true'
      + '&fitw=true'
      + '&sheetnames=false&printtitle=false&pagenumbers=false'
      + '&gridlines=false'
      + '&fzr=false'
      + `&gid=${gid}&r1=${r1}&c1=${c1}&r2=${r2}&c2=${c2}`;
    const res = UrlFetchApp.fetch(url, {headers, muteHttpExceptions: true});
   
    if (res.getResponseCode() != 200) {
      console.log(res.getContentText())
      }
    return new Uint8Array(res.getContent());
     });
 
     const setTimeout = function(f, t) {
     Utilities.sleep(t);
     return f(); }
     const pdfDoc = await PDFLib.PDFDocument.create();
 
    for (let i = 0; i < data.length; i++) {
    const pdfData = await PDFLib.PDFDocument.load(data[i]);
    const pages = await pdfDoc.copyPages(pdfData, [...Array(pdfData.getPageCount())].map((_, i) => i));
    pages.forEach(page => pdfDoc.addPage(page));
    }
    const bytes = await pdfDoc.save();
    var folder = DriveApp.getFolderById('1t6ns346GNX_gP-uGkwE43egGhTCaWgKO');
    var pdf = folder.createFile(Utilities.newBlob([...new Int8Array(bytes)], MimeType.PDF, "sample1.pdf"));

    console.log(pdf.getUrl())
    sheet.getRange("AW7").setValue(pdf.getUrl());

}

The issue is this script works only for this Spreadsheet. If I copy it or access the other Spreadsheet with url then it shows the following error message:

ReferenceError: setTimeout is not defined (anonymous) @ JS
Library.gs:15 X @ JS Library.gs:15 (anonymous) @ JS Library.gs:15
(anonymous) @ JS Library.gs:15 (anonymous) @ JS Library.gs:15 a @ JS
Library.gs:15

In line 6 of the code, the statement is SpreadsheetApp.getActiveSpreadsheet(), I want to use SpreadsheetApp.openByUrl(). Any guidance would be much appreciated.

Issue with closing dialog box when clicking on NavLink in React

I’m currently working on a React application and have implemented a dialog box using the Dialog component from the Material-UI library. The dialog box contains a navigation menu, and I want it to close when the user clicks on one of the navigation links (NavLink) in desktop mode.

Here’s the relevant code snippet:

// Dialog component code

const [open, setOpen] = useState(false);

// Dialog opening and closing functions

const handleOpen = () => {
  setOpen(true);
};

const handleClose = () => {
  setOpen(false);
};

// JSX code for the dialog box

<Dialog open={open} onClose={handleClose}>
  <div className="dialog-content">
    {/* Navigation links */}
    {navItems.map((item) => (
      <NavLink
        key={item.id}
        to={item.href}
        className="-m-2 block p-2 text-gray-500"
        onClick={handleClose} // Issue here: dialog doesn't close
      >
        {item.name}
      </NavLink>
    ))}
  </div>
</Dialog>

The problem I’m facing is that the dialog box doesn’t close when I click on a NavLink. The onClick handler is correctly invoked, but the dialog remains open. I suspect there might be an issue with how I’m implementing the onClick handler.

I would appreciate any insights or suggestions on how to properly close the dialog box when clicking on a NavLink in React. Thank you in advance for your help!

fetch discord channel massages/posts and embed them in html

hey just wanted to ask what is the best way to get started with fetching massages/post from discord server channel and embed them in html, just the last 10 massages/posts sent in the channel ?

my end goal is to be able to add to my site news feed box that fetches massages from my channel.

not sure if the only way is to use discord.js and bot or maybe there is a more simple solution ?
please list me the steps to get started and helpful links or videos

have more than basic knowledge in JavaScript and basic/average knowledge in node.js if needed

Extendscript for Adobe Illustrator: Unexpected compound shape / path results from expanding image trace

I am writing a script in Extendscript for adobe illustrator that would automate these steps for an ink like effect: 1)Expand the selected object 2)convert to a compound shape 3)apply gaussian blur 4)rasterize 5)image trace. Here is how this looks when done manually:

Before doing the steps manually

after doing the steps manually

You can see a slight rounding effect to the edges. That is how i intend this.

However, when running these steps from my script, i get this result:

after result from script

The rounded effect applied as was expected, but the empty spaces in paths always turn out filled. As if the script was releasing the compound path.

I am wondering where in the script this could be happening, and how to prevent that ?

Here is the code for the function where the effect is being applied:

    function mainFunction(){
        inkifyScript.selection = app.activeDocument.selection;
        
        if (inkifyScript.selection.length > 0){
    
            app.executeMenuCommand('group');
            inkifyScript.xmlString = '<LiveEffect name="Adobe PSL Gaussian Blur"><Dict data="R blur '+ 20 +'"/></LiveEffect>';
            for (var i = 0; i < inkifyScript.selection.length; i++){
                inkifyScript.selection[i].applyEffect(inkifyScript.xmlString);
            }
            
            inkifyScript.raster = app.activeDocument.rasterize(selection[0]);
            inkifyScript.raster.selected = true;

            inkifyScript.pluginItem = inkifyScript.raster.trace();

            inkifyScript.tracingOptions = inkifyScript.pluginItem.tracing.tracingOptions;
            inkifyScript.tracingOptions.tracingMode = TracingModeType.TRACINGMODEBLACKANDWHITE;
            inkifyScript.tracingOptions.ignoreWhite = true;
            inkifyScript.tracingOptions.fills = true;
            inkifyScript.tracingOptions.maxColors = 2;
            inkifyScript.tracingOptions.threshold = 142;
            inkifyScript.tracingOptions.pathFitting = 10;
            app.redraw();
            inkifyScript.pluginItem.tracing.expandTracing();    
        }
        
    }`

Check whether a string consists of an element in an array [duplicate]

I want to perform the following actions depending on whether the string sample_input consists any of the characters in the array vowel_list.

let vowel_list = ["a", "e", "i", "o", "u"]
let sample_input = "Hello, Stack Overflow!"

// If sample_input has a vowel, I want to print "Great, sample_input has got a vowel in it!" on the console.

I tried to use .includes(), but later on it dawned on me that it could only check whether the string has a specific block of string in it. For instance,

let test = "Hello World!"

if (test.includes("H")) {
    console.log("The string 'test' includes letter H")
}

Reactflow – Adding nodes by drag and drop in Custom Edges button

Please help me with my issue. I’m currently making an open-source project using Reactflow. But I got some error.

enter image description here

I want to Add my drag and drop node on my “+” Edge Button. The elements are dropped on (+) it should have the same effect as the menu popup. How can I do that? Please help me.

Here’s the live link: https://whimsical-pegasus-f563db.netlify.app/

The code is really big. I think the problem is When I drag and drop the “Nodes”, the “Nodes” can’t get Id. And that’s why it shows an error.

Here’s some important File:

Automation.jsx :

import React, { useCallback, useEffect, useRef, useState } from "react";
import ReactFlow, {
    Controls,
    MiniMap,
    ReactFlowProvider,
    useEdgesState,
    useNodesState,
} from "reactflow";

// File imports
import "./Automation.css";

import { nodeTypes } from "./Nodes/index.jsx";
import { edgeTypes } from "./Edges/index.jsx";
import { getLayoutedElements } from "./Utils/WorkflowLayoutUtils.jsx";
import Sidebar from "./Sidebar/Sidebar";
import { getUpdatedElementsAfterNodeAddition } from "./Utils/WorkflowElementUtils";

export const Automation = (props) => {
    const { elements, onAddNodeCallback } = props;

    const reactFlowWrapper = useRef(null);
    const [nodes, setNodes, onNodesChange] = useNodesState();
    const [edges, setEdges, onEdgesChange] = useEdgesState();
    const [reactFlowInstance, setReactFlowInstance] = useState(null);

    useEffect(() => {
        const layoutElements = getLayoutedElements(elements);
        const layoutNodes = layoutElements.filter((x) => x.position);
        const layoutEdges = layoutElements.filter((x) => !x.position);
        setNodes(layoutNodes);
        setEdges(layoutEdges);
    }, [elements]);

    const onConnect = useCallback(
        (params) => setEdges((eds) => eds.concat(params)), // Modified: Concatenate edges
        [setEdges]
    );

    // ============================>

    // ==============================>
    let id = 0;
    const getId = () => `dndnode_${id++}`;

    const onDrop = useCallback(
        (event) => {
            event.preventDefault();

            const reactFlowBounds =
                reactFlowWrapper.current.getBoundingClientRect();
            const type = event.dataTransfer.getData("application/reactflow");

            // check if the dropped element is valid
            if (typeof type === "undefined" || !type) {
                return;
            }

            const position = reactFlowInstance.project({
                x: event.clientX - reactFlowBounds.left,
                y: event.clientY - reactFlowBounds.top,
            });
            const newNode = {
                id: getId(),
                type,
                position,
                data: { label: `${type} node` },
            };

            setNodes((nds) => nds.concat(newNode));

            // ===========

            // setNodes((elements) =>
            //     getUpdatedElementsAfterNodeAddition({
            //         elements,
            //         newNode: newNode,
            //         targetEdgeId: "e1-2",
            //     })
            // );

            // ===========
        },
        [reactFlowInstance, setNodes]
    );

    const onDragOver = useCallback((event) => {
        event.preventDefault();
        event.dataTransfer.dropEffect = "move";
    }, []);

    // =================================>

    return (
        <div className="AutomationCanvas">
            <ReactFlowProvider>
                <div ref={reactFlowWrapper} className="reactflow-wrapper">
                    <ReactFlow
                        nodes={nodes}
                        edges={edges}
                        // nodesDraggable={false}
                        // nodesConnectable={false}
                        nodeTypes={nodeTypes}
                        edgeTypes={edgeTypes}
                        // zoomOnScroll={false}
                        // zoomOnPinch={false}
                        // panOnScroll
                        // panOnDrag
                        // preventScrolling
                        onConnect={onConnect}
                        fitView
                        onInit={setReactFlowInstance}
                        onDrop={onDrop}
                        onDragOver={onDragOver}
                        onNodesChange={onNodesChange}
                        onEdgesChange={onEdgesChange}
                    >
                        <Controls
                            // showInteractive={false}
                            className="Controls"
                        />
                        <MiniMap />
                    </ReactFlow>
                </div>
            </ReactFlowProvider>
        </div>
    );
};

const Layout = (props) => (
    <ReactFlowProvider>
        <Automation {...props} />
    </ReactFlowProvider>
);

export default Layout;

App.jsx:

import React from "react";
import _ from "lodash";

import "antd/dist/reset.css";
import "./index.scss";
import { getIncomers, getOutgoers } from "react-flow-renderer";
// File Importing from folder
import Layout from "./Automation.jsx";
import { initialElements } from "./Data/Elements1.jsx";
import { getUpdatedElementsAfterNodeAddition } from "./Utils/WorkflowElementUtils.jsx";
import Sidebar from "./Sidebar/Sidebar";

const App = () => {
    const [elements, setElements] = React.useState([]);

    const onAddNodeCallback = ({ id, type }) => {
        setElements((elements) =>
            getUpdatedElementsAfterNodeAddition({
                elements,
                targetEdgeId: id,
                type,
                onDeleteNodeCallback,
                onNodeClickCallback,
                onAddNodeCallback,
            })
        );
    };

    const onDeleteNodeCallback = (id) => {
        setElements((elements) => {
            const clonedElements = _.cloneDeep(elements);
            const incomingEdges = clonedElements.filter((x) => x.target === id);
            const outgoingEdges = clonedElements.filter((x) => x.source === id);
            const updatedIncomingEdges = incomingEdges.map((x) => ({
                ...x,
                target: outgoingEdges[0].target,
            }));
            const filteredElements = clonedElements.filter(
                (x) =>
                    x.id !== id &&
                    x.target !== incomingEdges[0].target &&
                    x.source !== outgoingEdges[0].source
            );
            filteredElements.push(...updatedIncomingEdges);
            return filteredElements;
        });
    };

    const onNodeClickCallback = (id) => {
        setElements((elements) => {
            const currentNode = elements.find((x) => x.id === id);
            const nodes = elements.filter((x) => x.position);
            const edges = elements.filter((x) => !x.position);
            console.error({
                incomers: getIncomers(currentNode, nodes, edges),
                outgoers: getOutgoers(currentNode, nodes, edges),
            });
            return elements;
        });
        alert(`You clicked the "${id}" node`);
    };

    React.useEffect(() => {
        const nodes = initialElements
            .filter((x) => !x.target)
            .map((x) => ({
                ...x,
                data: { ...x.data, onDeleteNodeCallback, onNodeClickCallback },
            }));
        const edges = initialElements
            .filter((x) => x.target)
            .map((x) => ({ ...x, data: { ...x.data, onAddNodeCallback } }));
        setElements([...nodes, ...edges]);
    }, []);

    return (
        <div className="App">
            <Layout elements={elements} />
            <Sidebar />
        </div>
    );
};

export default App;

Edges:

import EdgeAddButton from "../Buttons/EdgeAddButton/EdgeAddButton.jsx";

import "./Style.scss";
import {
    getEdgeCenter,
    getBezierPath,
    getMarkerEnd,
} from "react-flow-renderer";

const [buttonWidth, buttonHeight] = [100, 40];

export const Condition = (props) => {
    const {
        id,
        sourceX,
        sourceY,
        targetX,
        targetY,
        sourcePosition,
        targetPosition,
        arrowHeadType,
        markerEndId,
        data,
    } = props;
    const edgePath = getBezierPath({
        sourceX,
        sourceY,
        sourcePosition,
        targetX,
        targetY,
        targetPosition,
    });
    const markerEnd = getMarkerEnd(arrowHeadType, markerEndId);

    const [edgeCenterX, edgeCenterY] = getEdgeCenter({
        sourceX,
        sourceY,
        targetX,
        targetY,
    });

    const { isAddButtonHidden } = data;

    return (
        <>
            <path
                id={id}
                d={edgePath}
                markerEnd={markerEnd}
                className="react-flow__edge-path"
            />
            {isAddButtonHidden ? null : (
                <>
                    <foreignObject
                        width={buttonWidth}
                        height={buttonHeight}
                        x={edgeCenterX - buttonWidth / 2}
                        y={edgeCenterY - buttonHeight / 2}
                        requiredExtensions="http://www.w3.org/1999/xhtml"
                    >
                        <EdgeAddButton
                            {...props}
                            onClick={() => console.log("clicked")}
                            style={{ width: buttonWidth, height: buttonHeight }}
                        />
                    </foreignObject>
                </>
            )}
        </>
    );
};

Workflow Elements:

import { v4 as uuidv4 } from "uuid";
import _ from "lodash";

const position = { x: 0, y: 0 };

const getTitleAndDescription = (type) => {
    switch (type) {
        case "email":
            return { title: "Email", description: "Send email to contacts." };
        case "sms":
            return { title: "Sms", description: "Send sms to contacts." };
        case "waitThenCheck":
            return {
                title: "New Rule",
                description: "Check behaviour of the Rule",
            };
        case "end":
            return { title: "End", description: "Process ends" };
        default:
            return { title: "", description: "" };
    }
};

const getUpdatedElementsAfterActionNodeAddition = ({
    elements,
    newNodeId,
    targetNodeId,
    onAddNodeCallback,
}) => {
    const clonedElements = _.cloneDeep(elements);
    const newEdge = {
        id: uuidv4(),
        source: newNodeId,
        target: targetNodeId,
        type: "condition",
        data: { onAddNodeCallback },
    };
    clonedElements.push(newEdge);
    return clonedElements;
};

const getUpdatedElementsAfterEndNodeAddition = () => {};

const getUpdatedElementsAfterRuleNodeAdditon = ({
    elements,
    newNodeId,
    targetNodeId,
    onAddNodeCallback,
}) => {
    const clonedElements = _.cloneDeep(elements);
    const emptyNode1Id = uuidv4();
    const emptyNode2Id = uuidv4();
    const mergeNodeId = uuidv4();
    const emptyNode1 = {
        id: emptyNode1Id,
        type: "empty",
        data: {},
        position,
        height: 6,
        // width: 40,
    };
    const emptyNode2 = {
        id: emptyNode2Id,
        type: "empty",
        data: {},
        position,
        height: 6,
        // width: 40,
    };
    const mergeNode = {
        id: mergeNodeId,
        type: "empty",
        data: {},
        position,
        height: 6,
    };
    const ruleNodeToEmptyNodeEdge1 = {
        id: uuidv4(),
        source: newNodeId,
        target: emptyNode1Id,
        type: "condition",
        // animated: true,
        data: { onAddNodeCallback },
    };
    const emptyNode1ToMergeNodeEdge = {
        id: uuidv4(),
        source: emptyNode1Id,
        target: mergeNodeId,
        type: "condition",
        // animated: true,
        data: { onAddNodeCallback, isAddButtonHidden: true },
    };
    const ruleNodeToEmptyNodeEdge2 = {
        id: uuidv4(),
        source: newNodeId,
        target: emptyNode2Id,
        type: "condition",
        // animated: true,

        data: { onAddNodeCallback },
    };
    const emptyNode2ToMergeNodeEdge = {
        id: uuidv4(),
        source: emptyNode2Id,
        target: mergeNodeId,
        type: "condition",
        // animated: true,
        data: { onAddNodeCallback, isAddButtonHidden: true },
    };
    const mergeNodeEdge = {
        id: uuidv4(),
        source: mergeNodeId,
        target: targetNodeId,
        type: "condition",
        data: { onAddNodeCallback },
        mergeNodeOfParentId: newNodeId,
    };
    clonedElements.push(
        ...[
            emptyNode1,
            emptyNode2,
            ruleNodeToEmptyNodeEdge1,
            emptyNode1ToMergeNodeEdge,
            ruleNodeToEmptyNodeEdge2,
            emptyNode2ToMergeNodeEdge,
            mergeNode,
            mergeNodeEdge,
        ]
    );
    console.error({ clonedElements });
    return clonedElements;
};

const getUpdatedElementsAfterNodeAddition = ({
    elements,
    targetEdgeId,
    type,
    onDeleteNodeCallback,
    onNodeClickCallback,
    onAddNodeCallback,
    position,
}) => {
    const newNodeId = uuidv4();
    const { title, description } = getTitleAndDescription(type);
    const newNode = {
        id: newNodeId,
        type,
        data: {
            title,
            description,
            onNodeClickCallback,
            onDeleteNodeCallback,
        },
        position,
    };
    const clonedElements = _.cloneDeep(elements);
    const targetEdgeIndex = clonedElements.findIndex(
        (x) => x.id === targetEdgeId
    );
    const targetEdge = elements[targetEdgeIndex];

    // Check if targetEdge is defined before accessing its properties
    if (targetEdge) {
        const { target: targetNodeId } = targetEdge;
        const updatedTargetEdge = { ...targetEdge, target: newNodeId };
        clonedElements[targetEdgeIndex] = updatedTargetEdge;
        clonedElements.push(newNode);

        switch (type) {
            case "end":
                return getUpdatedElementsAfterEndNodeAddition();
            case "waitThenCheck":
                return getUpdatedElementsAfterRuleNodeAdditon({
                    elements: clonedElements,
                    newNodeId,
                    targetNodeId,
                    onAddNodeCallback,
                });
            default:
                return getUpdatedElementsAfterActionNodeAddition({
                    elements: clonedElements,
                    newNodeId,
                    newNode,
                    targetNodeId,
                    onAddNodeCallback,
                });
        }
    } else {
        // Handle the case when targetEdge is undefined
        console.error("Target edge is undefined.");
        return elements; // Return the original elements array
    }
};

// ================
//
//
// const getUpdatedElementsAfterNodeAddition = ({
//     elements,
//     targetEdgeId,
//     type,
//     onDeleteNodeCallback,
//     onNodeClickCallback,
//     onAddNodeCallback,
// }) => {
//     const newNodeId = uuidv4();
//     const { title, description } = getTitleAndDescription(type);
//     const newNode = {
//         id: newNodeId,
//         type,
//         data: {
//             title,
//             description,
//             onNodeClickCallback,
//             onDeleteNodeCallback,
//         },
//         position,
//     };
//     const clonedElements = _.cloneDeep(elements);
//     const targetEdgeIndex = clonedElements.findIndex(
//         (x) => x.id === targetEdgeId
//     );
//     const targetEdge = elements[targetEdgeIndex];
//     const { target: targetNodeId } = targetEdge;
//     const updatedTargetEdge = { ...targetEdge, target: newNodeId };
//     clonedElements[targetEdgeIndex] = updatedTargetEdge;
//     clonedElements.push(newNode);

//     switch (type) {
//         case "end":
//             return getUpdatedElementsAfterEndNodeAddition();
//         case "waitThenCheck":
//             return getUpdatedElementsAfterRuleNodeAdditon({
//                 elements: clonedElements,
//                 newNodeId,
//                 targetNodeId,
//                 onAddNodeCallback,
//             });
//         default:
//             return getUpdatedElementsAfterActionNodeAddition({
//                 elements: clonedElements,
//                 newNodeId,
//                 newNode,
//                 targetNodeId,
//                 onAddNodeCallback,
//             });
//     }
// };

export { getUpdatedElementsAfterNodeAddition };

Thank You. And here’s the main code: https://github.com/sayedulkrm/react-flow-drag

Is it possible for the “+” button to listen while doing drag and drop?

undefined ‘className’ in magnificPopup

I’m trying to reproduce this gallery https://codepen.io/mattlansom/pen/epRNpp

I kind of did everything exactly the same, but I get an error

“Uncaught TypeError: Cannot read properties of undefined (reading ‘className’)”

And I can’t figure out what the problem is

I need to manually declare these variables myself, or is it somewhere an error with connecting magnificPopup?

$(document).ready(function() {
    $('.popup-gallery').magnificPopup({
        delegate: 'a',
        type: 'image',
    callbacks: {
      elementParse: function(item) {
        if(item.el.context.className == 'video') {
          item.type = 'iframe',
          item.iframe = {
             patterns: {
               youtube: {
                 index: 'youtube.com/',
                 id: 'v=',
                 src: '//www.youtube.com/embed/%id%?autoplay=1'
               },
               vimeo: {
                 index: 'vimeo.com/',
                 id: '/',
                 src: '//player.vimeo.com/video/%id%?autoplay=1'
               },
               gmaps: {
                 index: '//maps.google.',
                 src: '%id%&output=embed'
               }
             }
          }
        } else {
           item.type = 'image',
           item.tLoading = 'Loading image #%curr%...',
           item.mainClass = 'mfp-img-mobile',
           item.image = {
             tError: '<a href="%url%">The image #%curr%</a> could not be loaded.'
           }
        }

      }
    },
        gallery: {
            enabled: true,
            navigateByImgClick: true,
            preload: [0,1]
        }
    });
});
.popup-gallery a {display:inline-block;width:25%;}
.popup-gallery a img {height:auto;width:100%;}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/magnific-popup.css" integrity="sha512-WEQNv9d3+sqyHjrqUZobDhFARZDko2wpWdfcpv44lsypsSuMO0kHGd3MQ8rrsBn/Qa39VojphdU6CMkpJUmDVw==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/jquery.magnific-popup.min.js" integrity="sha512-IsNh5E3eYy3tr/JiX2Yx4vsCujtkhwl7SLqgnwLNgf04Hrt9BT9SXlLlZlWx+OK4ndzAoALhsMNcCmkggjZB1w==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>


<div class="row">
      <div class="col-sm-12">
        <div class="popup-gallery">
            <a href="http://sandbox.vciwork.com/codepenstuff/images/1.jpg" class="image" title="Some Text for the image">
              <img src="http://sandbox.vciwork.com/codepenstuff/images/1.jpg" alt="Alt text" />
            </a>
          <a href="https://www.youtube.com/watch?v=L0jQz6jqQS0" class="video" title="This is a video">
              <img src="http://sandbox.vciwork.com/codepenstuff/images/2.jpg" alt="Alt text" />
            </a>
          <a href="http://sandbox.vciwork.com/codepenstuff/images/4.jpg" class="image" title="Some Text for the image">
              <img src="http://sandbox.vciwork.com/codepenstuff/images/4.jpg" alt="Alt text" />
            </a>
        </div>
      </div>
    </div>
    

How can I get the _id of a user whose page I’m on?

I’m working on a Facebook clone and I’m setting up friend requests. I’m using Mongoose and I have a User schema so each user is automatically given a unique _id. I also have a form which connects to a Status schema. Each user can make status updates on the index page and when you visit their user profile Example: /users/dagger. It shows a list of all their status updates. Also on their page is a button that sends a friend request.

<form action="/friend-requests" method="POST">
  <input type="hidden" name="sender" value="<%= user.id %>" />
  <input type="hidden" name="receiver" value="<%= ??? %>" />
  <button type="submit">Send Friend Request</button>
</form>

This button takes the value of your _id and the person who you want to be friends with _id and does a POST request. It then adds the person to the pending friend requests. I’ve tested the code by manually inputting certain users _id so I know it works, I just can’t seem to figure out the JavaScript code to dynamically get the _id of the user whose page I’m on Example: <%= receiver.id %>. It’s easy to get the users _id because I’m the one who’s logged in, but getting the _id of someone whose page I’m on has proven to be tricky.

User Schema

const userSchema = new mongoose.Schema({
  username: {
    type: String,
    unique: true,
  },
  password: String,
  createdAt: { type: Date, default: Date.now },
  friends: [
    {
      type: mongoose.Schema.Types.ObjectId,
      ref: "User",
    },
  ],
});

FriendRequest Schema

const friendRequestSchema = new mongoose.Schema({
  sender: {
    type: mongoose.Schema.Types.ObjectId,
    ref: "User",
    required: true,
  },
  receiver: {
    type: mongoose.Schema.Types.ObjectId,
    ref: "User",
    required: true,
  },
  status: {
    type: String,
    enum: ["pending", "accepted", "rejected"],
    default: "pending",
  },
  createdAt: {
    type: Date,
    default: Date.now,
  },
});

Code to send a friend request and add to pending requests.

router.post("/friend-requests", (req, res) => {
  const { sender, receiver } = req.body;

  // Create a new FriendRequest instance
  const newRequest = new FriendRequest({
    sender,
    receiver,
  });

  // Save the friend request to the database
  newRequest
    .save()
    .then(() => {
      // Redirect to a success page or send a response indicating success
      res.send("Friend request sent successfully!");
    })
    .catch((error) => {
      // Handle the error appropriately
      res.status(500).send("Error sending friend request");
    });
  console.log(sender);
  console.log(receiver); // shows as blank
});

Scripting not working in above code need to validate the user and call the function

JavaScript function not working for validation I have created one servlet , servlet is working fine but just function validation is not working.

Created 7 labels using html but javascript function is not working i need to validate the field from user end which i have to display the message for user if user ignore some field .

`<!DOCTYPE html>
<html>
<head>
    <title>Registration</title>
    <style>
        a {
          text-decoration: none;
          }
          .login-page 
          {
          width: 100%;
          height: 100vh;
          display: inline-block;
          display: flex;
          align-items: center;
          }
          .form-right i
           {
          font-size: 100px;
          }
       </style>
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css">
        <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">  
</head>
<body>
    <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
        <div class="container-fluid">
          <a class="navbar-brand" href="#">PC</a>
          <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarTogglerDemo02" aria-controls="navbarTogglerDemo02" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
          </button>
          <div class="collapse navbar-collapse" id="navbarTogglerDemo02">
            <ul class="navbar-nav me-auto mb-2 mb-lg-0">
              <li class="nav-item">
                <a class="nav-link active" aria-current="page" href="#">Home</a>
              </li>
              <li class="nav-item">
                <a class="nav-link active" aria-current="page" href="#">About</a>
              </li>
            </ul>
            <form class="d-flex" action="login.html">
              <button class="btn btn-outline-success" type="submit">Login</button>
            </form>
          </div>
        </div>
      </nav>
      <br><br><br><br><br>
      <div class="login-page bg-light">
        <div class="container">
            <div class="row">
                <div class="col-lg-10 offset-lg-1">
                  <h3 class="mb-3">Register</h3>
                    <div class="bg-white shadow rounded">
                        <div class="row">
                            <div class="col-md-7 pe-0">
                                <div class="form-left h-100 py-5 px-5">
                                    <form action="Registration" method="post" onsubmit="return register_form_validation()" class="row g-4" >
                                    
                                     <div class="col-12">
                                                <label>Username<span class="text-danger">*</span></label>
                                                <div class="input-group">
                                                    <div class="input-group-text"><i class="bi bi-person-fill"></i></div>
                                                    <input type="text" class="form-control" placeholder="Enter Username" name="uname">
                                                </div>
                                            </div>

                                            <div class="col-12">
                                                <label>Password<span class="text-danger">*</span></label>
                                                <div class="input-group">
                                                    <div class="input-group-text"><i class="bi bi-lock-fill"></i></div>
                                                    <input type="password" class="form-control" placeholder="Enter Password" name="pwd">
                                                </div>
                                            </div>
                                    
                                        <div class="col-12">
                                            <label>First Name<span class="text-danger">*</span></label>
                                            <div class="input-group">
                                                
                                                <input type="text" class="form-control" placeholder="Enter First name" name="fname">
                                            </div>
                                        </div>
                                        <div class="col-12">
                                            <label>Middle Name<span class="text-danger">*</span></label>
                                            <div class="input-group">
                                                
                                                <input type="text" class="form-control" placeholder="Enter Middle name" name="mname">
                                            </div>
                                        </div>
                                          <div class="col-12">
                                            <label>Last Name<span class="text-danger">*</span></label>
                                            <div class="input-group">
                                                
                                                <input type="text" class="form-control" placeholder="Enter Last name" name="lname">
                                            </div>
                                        </div>
                                           
                                            <div class="col-12">
                                                <label>Email<span class="text-danger">*</span></label>
                                                <div class="input-group">
                                                    
                                                    <input type="text" class="form-control" placeholder="Enter Email Address" name="email">
                                                </div>
                                            </div>
                                            <div class="col-12">
                                                <label>Mobile Number<span class="text-danger">*</span></label>
                                                <div class="input-group">
                                                    
                                                    <input type="number" class="form-control" placeholder="Enter Mobile Number" name="mobile">
                                                </div>
                                            </div>

                                           
                                            <div class="col-sm-6">
                                                <div>
                                                  
                                                  <button type="submit" class="btn btn-primary px-4 float-end mt-4">Register</button>
                                                </div>
                                            </div>
                                            
                                           
                                            
                                           
                                    </form>
                                </div>
                            </div>
                            <div class="col-md-5 ps-0 d-none d-md-block">
                                <div class="form-right h-100 bg-primary text-white text-center pt-5">
                                  <i class="bi bi-book-half"></i>
                                    <h2 class="fs-1">Welcome to PC bookshop!!!</h2>
                                </div>
                            </div>
                        </div>
                    </div>
                    <p class="text-end text-secondary mt-3"></p>
                </div>
            </div>
        </div>
    </div>
    <script>
        function register_form_validation()
        {
          var uname=document.getElementById("uname").value;
          var pwd=document.getElementById("pwd").value;
          var email=document.getElementById("email").value;
          var fname=document.getElementById("fname").value;
          var mname=document.getElementById("mname").value;
          var lname=document.getElementById("lname").value;
          var mobile=document.getElementById("mobile").value;
        
       
          if(uname=='')
          {
            alert('Please enter Username');
          return false;
         }
        else if(pwd=='')
           {
          alert('Please enter Email');
          return false;
           }
        else if(email=='')
           {
          alert('Please enter password');
          return false;
           }
        else if(fname=='')
           {
          alert('Please enter fname');
          return false;
           }
        else if(mname=='')
           {
          alert('Please enter mname');
          return false;
           }
        else if(lname=='')
           {
          alert('Please enter lname');
          return false;
           }
        else if(mobile=='')
           {
          alert('Please enter mobile');
          return false;
           }
        else
        {
          return true;
        }
         
        return false;
        }
       
    </script> 
</body>
</html>`

Getting result mismatch from CryptoJs vs online encryptor

I’m trying to encrypt the string ‘hello’ in cryptoJs using custom generated IV and key values. On trying that same combination online I’m getting a slightly different result, it looks like a bit length mismatch but even after trying different conversions i can’t get the same result.

here is my CryptoJs code:

const encrypt = () => {
    try {
      const encodedText = CryptoJS.enc.Utf8.parse(JSON.stringify('hello'));
      const encodedKey = CryptoJS.enc.Utf8.parse('12345610');
      const encodedIv = CryptoS.enc.Utf8.parse(
        '43389f57-197b-4f69-8284-113d06f05e16'
      );

      const encryptedData = CryptoJS.AES.encrypt(encodedText, encodedKey, {
        encodedIv,
        mode: CryptoJsmode.CBC,
        padding: CryptoJS.pad.Pkcs7,
      });

      return encryptedData.ciphertext.toString(Crypto.JS.enc.Base64);
    } catch (error) {}
  };

On pasting the same iv, key and text values on this site: https://the-x.cn/en-us/cryptography/Aes.aspx
with the settings:

text to be encrypted: hello
mode: CBC
padding: PKCS7
size: 128bits
key: 12345610
iv: 43389f57-197b-4f69-8284-113d06f05e16

I’m getting gGki5uPxz3JJs+UegClTzA== string as the final encrypted output.

Meanwhile my CryptoJs function is returning a totally different one. I feel like there’s a mismatch of bit size somewhere. What am I missing?

add text to the start of chart js 4

i use chart js 4 and i need to add text to the horizontal line chart, i use with afterDraw but i had nothing

my code ts is like that :
createChart() {
const canavs = document.getElementById(‘MyChart’) as HTMLCanvasElement;

this.chart = new Chart('MyChart', {
  type: 'bar', //this denotes tha type of chart

  data: {
    labels: [
      'Jan',
      'Fev',
      'Mar',
      'Avr',
     
    ],
    datasets: [
      {
        label: 'Courbe 1',
        data: [
          [-5000, 35000],
          [-20000, 50000],

          [-2000, 30000],
         
         
        ],
        barPercentage: 0.1,
        borderColor: '#D37D7D',
        backgroundColor: '#D37D7D',
        borderWidth: 2,
        borderRadius: 30,
        borderSkipped: false,
        order: 3,
      },

      {
        label: 'Courbe 2',
        data: [
          20000, 25000, 30000, 15000, 10000, 0, -20000, -25000, -30000,
          20000, 25000, 30000,
        ],
        borderColor: '#ADD8E6',
        backgroundColor: 'rgba(173,216,230,0.2)',
        type: 'line',
        order: 2,

       
        pointBackgroundColor: 'white',
        pointBorderColor: 'black',
        borderWidth: 1,
      },
      {
        label: 'courbe 3',
        data: [
          10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000,
          10000, 10000, 10000,
        ],

        backgroundColor: '#D37D7D',
        type: 'line',
        pointStyle: 'line',
        pointBorderColor: '#D37D7D',
        borderColor: '#D37D7D',
        borderWidth: 0.5,
        order: 1,
      },
    ],
  },

  options: {
    plugins: {
      legend: {
        position: 'top',
        align: 'end',
        labels: {
          filter: (l: any) => l.text !== 'Dataset 3',
          usePointStyle: true,
          pointStyle: 'circle',
          boxWidth: 8,
          fontSize: 10,
          pointRadius: 1,
        },
      },
      afterDraw: (chart: any) => {
        let ctx = canavs.getContext('2d');
        console.log('chart', chart);
        if (chart.data.datasets[2]._meta[0]) {
          ctx = chart.chart.ctx;
          let meta = chart.getDatasetMeta(2);
          let rect = meta.data[0]._model;
          let x = rect.x - 20; // move to the left of the bar by 20 pixels
          let y = rect.y - 10; // move up by 10 pixels
          let radius = 19; // set the radius to 12 pixels
          ctx.beginPath();
          ctx.arc(x, y, radius, 0, 2 * Math.PI, false);
          ctx.fillStyle = 'rgba(0,0,0,0.8)';
          chart.data.datasets[2].forEach(function (dataset: any) {
            for (let i = 0; i < dataset.data.length; i++) {
              console.log(dataset);
              if (dataset.type == 'line') {
                let model =
                  dataset._meta[Object.keys(dataset._meta)[0]].data[i]
                    ._model;

                chart.ctx.fillText(dataset.name, model.x, model.y - 20);
              }
            }
          });
          ctx.fill();
          ctx.lineWidth = 1;
          ctx.strokeStyle = '#fff';
          ctx.stroke();

          ctx.fillStyle = '#fff';
          ctx.font = '12px Arial';
          ctx.fillText(
            chart.config.options.scales.yAxes[2].scaleLabel.labelString,
            x - 35,
            y - 10
          );
        }
      },
    } as any,

   
    scales: {
      x: {
        grid: {
          display: false,
        },
      },
      y: {
        suggestedMin: -5000,
        suggestedMax: 5000,
        grid: {
          display: false,
        },
      },
    },
  },
});

} what i need is that the horizontal chart start with text bordered with some color like what i have in the picture enter image description here

select an entry each month using mongoose

I have a dictionary model like this:

const dictionarySchema = new Schema({
    entry: String,
    created: { type: Date, default: Date.now },
});

and I want to select this entry each month after its creation date.

How you do this ?

Something like this gives me the entries older than a month, but this is not what I want:

const conditions = { 
    created: { $lt: minusDays(new Date(), 30) },    
}
const dicEntry = await dbs['en'].Dictionary.find(conditions);

I want a solution to select the entry every 30 days from its creation date.