• 27-03-2024, 15:54:39
    #1
    arkadaşlar dün ticico scripti aldım excel ile toplu ürün eklerken ;

    toplu ürün ekle dediğimde her ürüne şu şekilde c_id tanımlanıyor import sırasında

    ben excel ile attığım her ürüne kendisi id tanımlıyor [64] ilk ürün [64] [64] ikinci ürün [64][64][64] üçüncü ürün bu binlerce olunca patlıyor





    bu durumda şuna neden oluyor




    nasıl çözebiliriz yardımcı olabilen var mı ?
  • 27-03-2024, 15:58:32
    #2
    Merhabalar. UserModel.php gibi bir dosya olması, bu dosyada import işlevleri olması gerekli. Kodları görmeden bir şey diyemeyiz. Ancak genellikle Modal dosyasından ayarlama yapılır. Tavsiyem yazılım sahibine ulaşın.
  • 27-03-2024, 16:00:05
    #3
    gorev adlı üyeden alıntı: mesajı görüntüle
    Merhabalar. UserModel.php gibi bir dosya olması, bu dosyada import işlevleri olması gerekli. Kodları görmeden bir şey diyemeyiz. Ancak genellikle Modal dosyasından ayarlama yapılır. Tavsiyem yazılım sahibine ulaşın.

    import_export.php diye bir dosya var kodları şu şekilde

    <?php if(!defined('ADMIN_INCLUDED')) { exit; } ?>
    <div class="container-fluid">
    
    
    <div class="row">
    <div class="col-12">
    <div class="page-title-box d-sm-flex align-items-center justify-content-between">
        <a href="<?php echo ADMIN_URL; ?>/index.php?page=products" class="menu_link"><h4 class="mb-sm-0 font-size-18"><?php echo LGA_PRODUCTS; ?> - <?php echo LGA_IMPORT_EXPORT; ?></h4></a>
    
        <div class="page-title-right">
            <ol class="breadcrumb m-0">
                <li class="breadcrumb-item"><a href="<?php echo ADMIN_URL; ?>"><?php echo LGA_HOME; ?></a></li>
                <li class="breadcrumb-item active"><?php echo LGA_EXPORT; ?></li>
            </ol>
        </div>
    
    </div>
    </div>
    </div>
    
    <div class="row">
    <div class="col-12">
    
    
    
    <div class="card mb-3">
        <div class="card-header">
            <h4 class="card-title">Excel - <?php echo LGA_PRODUCTS; ?> - <?php echo LGA_EXPORT; ?></h4>
        </div>
        <div class="card-body p-4">
        <?php
        if(m_a_p('type')=='excel_export')
        {
            
            if(DEMO)
            {
    
                echo m_admin_alert(LGA_ERROR,LGA_DEMO_ERROR);
            }
            else
            {
                $list = array();
                $products = $db->table('products')->order('id','asc')->get();
                $list[0]['Stock Code'] = 'Stock';
                $list[0]['Bar Code'] = 'Bar Code';
                $list[0]['Stock'] = 'Stock';
                $list[0]['Brand'] = 'Brand';
                $list[0]['Product Title'] = 'Product Title';
                $list[0]['Product Image'] = 'Product Image';
                $list[0]['Undiscounted Price'] = 'Undiscounted Price';
                $list[0]['Sale Price'] = 'Sale Price';
                $list[0]['Categories'] = 'Categories';
                $n=1;
                foreach($products['data'] as $product)
                {
                    $list[$n]['Stock Code'] = $product['stock_code'];
                    $list[$n]['Bar Code'] = $product['barcode'];
                    $list[$n]['Stock'] = $product['stock'];
                    if($product['b_id']==0)
                    {
                        $list[$n]['Brand'] = '';
                    }
                    else
                    {
                        $list[$n]['Brand'] = $db->table('brands')->where('id','=',$product['b_id'])->get_var('title');
                    }
                    $list[$n]['Product Title'] = $product['title'];
                    $list[$n]['Product Image'] = m_image_url($product['image']);
                    $list[$n]['Undiscounted Price'] = m_currency($product['undiscounted_price']);
                    $list[$n]['Sale Price'] = m_currency($product['sale_price']);
                    $list[$n]['Categories'] = m_category_extract($product['c_id'],'text');
                    $n++;
                }
                 $xlsx = SimpleXLSXGen::fromArray( $list);
                 $file = ''.time().'-EXPORT.xlsx';
                 $xlsx->saveAs(''.UPLOAD_DIR.'/export/'.$file.'');
                 echo '<a href="'.SITE_DOMAIN.'/uploads/export/'.$file.'" class="btn btn-success btn-sm" download>'.LGA_TRANSACTION_SUCCESS.' - Download</a><br><br>';
                
            }
        }
        ?>
        
            <form action="" method="post" enctype="multipart/form-data">
            <input type="hidden" name="type" value="excel_export">
                <button type="submit" class="btn btn-success waves-effect btn-label waves-light"><i class="bx bx-check-double label-icon"></i> <?php echo LGA_EXPORT; ?></button>
            </form>
        </div>
    </div>
    
    
    <div class="card mb-3">
        <div class="card-header">
            <h4 class="card-title">XML - <?php echo LGA_PRODUCTS; ?> - <?php echo LGA_EXPORT; ?></h4>
        </div>
        <div class="card-body p-4">
        <?php
        if(m_a_p('type')=='xml_export')
        {
            
            if(DEMO)
            {
    
                echo m_admin_alert(LGA_ERROR,LGA_DEMO_ERROR);
            }
            else
            {
                $list = array();
                $products = $db->table('products')->order('id','asc')->get();
                $n=1;
                foreach($products['data'] as $product)
                {
                    $list[$n]['Stock_Code'] = $product['stock_code'];
                    $list[$n]['Bar_Code'] = $product['barcode'];
                    $list[$n]['Stock'] = $product['stock'];
                    if($product['b_id']==0)
                    {
                        $list[$n]['Brand'] = '';
                    }
                    else
                    {
                        $list[$n]['Brand'] = str_replace('&','&amp;',$db->table('brands')->where('id','=',$product['b_id'])->get_var('title'));
                    }
                    $list[$n]['Product_Title'] = str_replace('&','&amp;',$product['title']);
                    $list[$n]['Product_Image'] = m_image_url($product['image']);
                    $list[$n]['Product_Description'] = '<![CDATA['.$product['content'].']]>';
                    $list[$n]['Undiscounted_Price'] = m_currency($product['undiscounted_price']);
                    $list[$n]['Sale_Price'] = m_currency($product['sale_price']);
                    $list[$n]['Categories'] = str_replace('&','&amp;',m_category_extract($product['c_id'],'text'));
                    $n++;
                }
                $xml="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Products>\n";
                 foreach($list as $keyv => $valv)
                 {
                     $xml.= "<Product>\n";
                     foreach($valv as $key => $val)
                     {
                         $xml.="<".$key.">".$val."</".$key.">\n";
                          
                     }
                     $xml.= "</Product>\n";
                 }
                 $xml.= '</Products>';
                 $file = ''.time().'-EXPORT.xml';
                 file_put_contents(''.UPLOAD_DIR.'/export/'.$file.'',$xml);
                 echo '<a href="'.SITE_DOMAIN.'/uploads/export/'.$file.'" class="btn btn-success btn-sm" download>'.LGA_TRANSACTION_SUCCESS.' - Download</a><br><br>';
                
            }
        }
        ?>
        
            <form action="" method="post" enctype="multipart/form-data">
            <input type="hidden" name="type" value="xml_export">
                <button type="submit" class="btn btn-success waves-effect btn-label waves-light"><i class="bx bx-check-double label-icon"></i> <?php echo LGA_EXPORT; ?></button>
            </form>
        </div>
    </div>
    
    <div class="card mb-3">
        <div class="card-header">
            <h4 class="card-title">Excel - <?php echo LGA_PRODUCTS; ?> - <?php echo LGA_IMPORT; ?></h4>
        </div>
        <div class="card-body p-4">
        <?php
        if(m_a_p('type')=='excel_import')
        {
            
            if(DEMO)
            {
    
                echo m_admin_alert(LGA_ERROR,LGA_DEMO_ERROR);
            }
            else
            {
                $extension = end(explode('.',$_FILES['excel']['name']));
                if($extension=='xlsx')
                {
                    move_uploaded_file($_FILES['excel']['tmp_name'],UPLOAD_DIR.'/import/'.$_FILES['excel']['name']);
                    $xlsx = SimpleXLSX::parse(''.UPLOAD_DIR.'/import/'.$_FILES['excel']['name'].'');
                    $n=0;
                    foreach($xlsx->rowsEx() as $product)
                    {
                        if($n>0)
                        {
                            
                        $cat_id = '';
                        $stock_code = trim($product[m_a_p('stock_code_tag')]['value']);
                        $barcode = trim($product[m_a_p('barcode_tag')]['value']);
                        $stock = null_to_zero(trim($product[m_a_p('stock_tag')]['value']));
                        $title = $product[m_a_p('title_tag')]['value'];
                        $content = $product[m_a_p('description_tag')]['value'];
                        $image = $product[m_a_p('image_tag')]['value'];
                        $brand = trim($product[m_a_p('brand_tag')]['value']);
                        $category = trim($product[m_a_p('category_tag')]['value']);
                        $undiscounted_price = null_to_zero($product[m_a_p('undiscounted_price_tag')]['value']);
                        $sale_price = null_to_zero($product[m_a_p('sale_price_tag')]['value']);
                    
                        if($image=='')
                        {
                            $image_name = '';
                        }
                        else
                        {
                            
                            $extension = strtolower(end(explode('.',$image)));
                            $available_extension = array('jpg','jpeg','webp','png','bmp');
                            if(in_array($extension,$available_extension))
                            {
                                $image_name = 'product_'.m_sef($title).'_'.uniqid().'.'.$extension.'';
                                $upload_path = UPLOAD_DIR.'/images/'.$image_name;
                                copy($image,$upload_path);
                                $image_name = m_image_webp_convert(''.UPLOAD_DIR.'/images/'.m_image_extension_converter($image_name).'');
                                
                            }
                            else
                            {
                                $image_name = '';
                            }
                        }
                        $ct_n = 0;
                        $ct_id = 0;
                        foreach(explode('/',$category) as $cat_name)
                        {
                            $ct_n = 0;
                            $ct_id = 0;
                            $category_name = trim($cat_name);
                            $cat_search = $db->table('categories')->where('sef','=',m_sef($category_name))->get();
                            
                            if($cat_search['total_count']==0)
                            {
                                $data = [
                                'image' => '',
                                'c_id' => $ct_id,
                                'title' => $category_name,
                                'seo_content' => '',
                                'c_rank' => 0,
                                'sef' => m_sef($category_name),
                                'status' => 1
                                ];
                                $query = $db->table('categories')->insert($data);
                                if($ct_n==0)
                                {
                                    $ct_id = $query;
                                }
                                    $c_id.='['.$ct_id.']';
                                    
                            }
                            else
                            {
                                if($ct_n==0)
                                {
                                    $ct_id = $cat_search['data'][0]['id'];
                                    
                                }
                                $c_id.='['.$cat_search['data'][0]['id'].']';
                                
                            }
                            $ct_n++;
                            
                        }
                        if($brand=='')
                        {
                            $b_id = 0;
                        }
                        else
                        {
                            $brand_search = $db->table('brands')->where('sef','=',m_sef($brand))->get();
                            if($brand_search['total_count']==0)
                            {
                                $data = [
                                'title' => $brand,
                                'sef' => m_sef($brand),
                                'status' => 1
                                ];
                                
                                $b_id = $db->table('brands')->insert($data);
                            }
                            else
                            {
                                $b_id = $brand_search['data'][0]['id'];
                            }
                        }
                        
                        $data = [
                        'image' => $image_name,
                        'c_id' => $c_id,
                        'b_id' => $b_id,
                        'title' => $title,
                        'barcode' => $barcode,
                        'stock_code' => $stock_code,
                        'stock' => $stock,
                        'currency_type' => m_setting('currency_type'),
                        'foreign_type' => 0,
                        'foreign_currency' => 0,
                        'foreign_price' => 0,
                        'buying_price' => 0,
                        'market_price' => 0,
                        'sale_price' => $sale_price,
                        'undiscounted_price' => $undiscounted_price,
                        'cargo_price' => 0,
                        'cargo_time' => '',
                        'lead_time' => '',
                        'tax' => 0,
                        'tax_included' => 1,
                        'content' => $content,
                        'sef' => m_sef($title),
                        'date' => $db->now(),
                        'status' => 1
                        ];
                        $query = $db->table('products')->insert($data);
                        
                        }
                        $n++;
                        
                    }
                    echo m_admin_alert(LGA_SUCCESS,LGA_TRANSACTION_SUCCESS);
                    unlink(UPLOAD_DIR.'/import/'.$_FILES['excel']['name']);
                    
                }
                else
                {
                    echo m_admin_alert(LGA_ERROR,LGA_TRANSACTION_ERROR);
                }
                
                
                
            }
        }
        ?>
        
            <form action="" method="post" enctype="multipart/form-data">
            <input type="hidden" name="type" value="excel_import">
                            <div class="mb-3">
                                    <label class="form-label">Excel ( XLSX )</label>
                                    <input class="form-control" type="file" name="excel" required>
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_STOCK_CODE; ?> - <?php echo LGA_COLUMN_ROW; ?></label>
                                    <input class="form-control" type="text" name="stock_code_tag" value="0">
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_BARCODE; ?> - <?php echo LGA_COLUMN_ROW; ?></label>
                                    <input class="form-control" type="text" name="barcode_tag" value="1">
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_STOCK; ?> - <?php echo LGA_COLUMN_ROW; ?></label>
                                    <input class="form-control" type="text" name="stock_tag" value="2">
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_PRODUCT_NAME; ?> - <?php echo LGA_COLUMN_ROW; ?></label>
                                    <input class="form-control" type="text" name="title_tag" value="4" required>
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_PRODUCT_IMAGE; ?> - <?php echo LGA_COLUMN_ROW; ?></label>
                                    <input class="form-control" type="text" name="image_tag" value="5">
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_BRAND; ?> - <?php echo LGA_COLUMN_ROW; ?></label>
                                    <input class="form-control" type="text" name="brand_tag" value="3">
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_CATEGORY; ?> - <?php echo LGA_COLUMN_ROW; ?></label>
                                    <input class="form-control" type="text" name="category_tag" value="8" required>
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_UNDISCOUNTED_PRICE; ?> - <?php echo LGA_COLUMN_ROW; ?></label>
                                    <input class="form-control" type="text" name="undiscounted_price_tag" value="6">
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_SALE_PRICE; ?> - <?php echo LGA_COLUMN_ROW; ?></label>
                                    <input class="form-control" type="text" name="sale_price_tag" value="7" required>
                            </div>
                            
                <button type="submit" class="btn btn-success waves-effect btn-label waves-light"><i class="bx bx-check-double label-icon"></i> <?php echo LGA_IMPORT; ?></button>
            </form>
        </div>
    </div>
    
    <div class="card mb-3">
        <div class="card-header">
            <h4 class="card-title">XML - <?php echo LGA_PRODUCTS; ?> - <?php echo LGA_IMPORT; ?></h4>
        </div>
        <div class="card-body p-4">
        <?php
        if(m_a_p('type')=='xml_import')
        {
            
            if(DEMO)
            {
    
                echo m_admin_alert(LGA_ERROR,LGA_DEMO_ERROR);
            }
            else
            {
                $xml=simplexml_load_string(m_url_get(m_a_p('xml_url')));
                if($xml)
                {
                    $n=0;
                    foreach($xml->{m_a_p('product_tag')} as $product)
                    {
                        $cat_id = '';
                        $stock_code = trim($product->{m_a_p('stock_code_tag')});
                        $barcode = trim($product->{m_a_p('barcode_tag')});
                        $stock = null_to_zero(trim($product->{m_a_p('stock_tag')}));
                        $title = $product->{m_a_p('title_tag')};
                        $content = $product->{m_a_p('description_tag')};
                        $image = $product->{m_a_p('image_tag')};
                        $brand = trim($product->{m_a_p('brand_tag')});
                        $category = trim($product->{m_a_p('category_tag')});
                        $undiscounted_price = null_to_zero($product->{m_a_p('undiscounted_price_tag')});
                        $sale_price = null_to_zero($product->{m_a_p('sale_price_tag')});
                        if($image=='')
                        {
                            $image_name = '';
                        }
                        else
                        {
                            
                            $extension = strtolower(end(explode('.',$image)));
                            $available_extension = array('jpg','jpeg','webp','png','bmp');
                            if(in_array($extension,$available_extension))
                            {
                                $image_name = 'product_'.m_sef($title).'_'.uniqid().'.'.$extension.'';
                                $upload_path = UPLOAD_DIR.'/images/'.$image_name;
                                copy($image,$upload_path);
                                $image_name = m_image_webp_convert(''.UPLOAD_DIR.'/images/'.m_image_extension_converter($image_name).'');
                                
                            }
                            else
                            {
                                $image_name = '';
                            }
                        }
                        $ct_n = 0;
                        $ct_id = 0;
                        foreach(explode('/',$category) as $cat_name)
                        {
                            $category_name = trim($cat_name);
                            $cat_search = $db->table('categories')->where('sef','=',m_sef($category_name))->get();
                            
                            if($cat_search['total_count']==0)
                            {
                                $data = [
                                'image' => '',
                                'c_id' => $ct_id,
                                'title' => $category_name,
                                'seo_content' => '',
                                'c_rank' => 0,
                                'sef' => m_sef($category_name),
                                'status' => 1
                                ];
                                
                                $query = $db->table('categories')->insert($data);
                                if($ct_n==0)
                                {
                                    $ct_id = $query;
                                }
                                    $c_id.='['.$ct_id.']';
                            }
                            else
                            {
                                if($ct_n==0)
                                {
                                    $ct_id = $cat_search['data'][0]['id'];
                                }
                                $c_id.='['.$cat_search['data'][0]['id'].']';
                            }
                            $ct_n++;
                            
                        }
                        if($brand=='')
                        {
                            $b_id = 0;
                        }
                        else
                        {
                            $brand_search = $db->table('brands')->where('sef','=',m_sef($brand))->get();
                            if($brand_search['total_count']==0)
                            {
                                $data = [
                                'title' => $brand,
                                'sef' => m_sef($brand),
                                'status' => 1
                                ];
                                
                                $b_id = $db->table('brands')->insert($data);
                            }
                            else
                            {
                                $b_id = $brand_search['data'][0]['id'];
                            }
                        }
                        
                        $data = [
                        'image' => $image_name,
                        'c_id' => $c_id,
                        'b_id' => $b_id,
                        'title' => $title,
                        'barcode' => $barcode,
                        'stock_code' => $stock_code,
                        'stock' => $stock,
                        'currency_type' => m_setting('currency_type'),
                        'foreign_type' => 0,
                        'foreign_currency' => 0,
                        'foreign_price' => 0,
                        'buying_price' => 0,
                        'market_price' => 0,
                        'sale_price' => $sale_price,
                        'undiscounted_price' => $undiscounted_price,
                        'cargo_price' => 0,
                        'cargo_time' => '',
                        'lead_time' => '',
                        'tax' => 0,
                        'tax_included' => 1,
                        'content' => $content,
                        'sef' => m_sef($title),
                        'date' => $db->now(),
                        'status' => 1
                        ];
                        $query = $db->table('products')->insert($data);
                        
                        
                        
                    }
                    echo m_admin_alert(LGA_SUCCESS,LGA_TRANSACTION_SUCCESS);
                }
                else
                {
                    echo m_admin_alert(LGA_ERROR,LGA_TRANSACTION_ERROR);
                }
                
                
                
            }
        }
        ?>
        
            <form action="" method="post" enctype="multipart/form-data">
            <input type="hidden" name="type" value="xml_import">
                            <div class="mb-3">
                                    <label class="form-label">XML URL</label>
                                    <input class="form-control" type="text" name="xml_url" required>
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_PRODUCT; ?> - TAG</label>
                                    <input class="form-control" type="text" name="product_tag" value="Product" required>
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_STOCK_CODE; ?> - TAG</label>
                                    <input class="form-control" type="text" name="stock_code_tag" value="Stock_Code">
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_BARCODE; ?> - TAG</label>
                                    <input class="form-control" type="text" name="barcode_tag" value="Barcode">
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_STOCK; ?> - TAG</label>
                                    <input class="form-control" type="text" name="stock_tag" value="Stock">
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_PRODUCT_NAME; ?> - TAG</label>
                                    <input class="form-control" type="text" name="title_tag" value="Product_Title" required>
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_PRODUCT_CONTENT; ?> - TAG</label>
                                    <input class="form-control" type="text" name="description_tag" value="Product_Description">
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_PRODUCT_IMAGE; ?> - TAG</label>
                                    <input class="form-control" type="text" name="image_tag" value="Product_Image">
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_BRAND; ?> - TAG</label>
                                    <input class="form-control" type="text" name="brand_tag" value="Brand">
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_CATEGORY; ?> - TAG</label>
                                    <input class="form-control" type="text" name="category_tag" value="Categories" required>
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_UNDISCOUNTED_PRICE; ?> - TAG</label>
                                    <input class="form-control" type="text" name="undiscounted_price_tag" value="Undiscounted_Price">
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_SALE_PRICE; ?> - TAG</label>
                                    <input class="form-control" type="text" name="sale_price_tag" value="Sale_Price" required>
                            </div>
                            
                <button type="submit" class="btn btn-success waves-effect btn-label waves-light"><i class="bx bx-check-double label-icon"></i> <?php echo LGA_IMPORT; ?></button>
            </form>
        </div>
    </div>
    
    
    </div>
    </div>
    
    </div>

    yazılım sahibine ulaşmak zor
  • 27-03-2024, 16:08:07
    #4
    <?php if(!defined('ADMIN_INCLUDED')) { exit; } ?>
    <div class="container-fluid">
     
     
    <div class="row">
    <div class="col-12">
    <div class="page-title-box d-sm-flex align-items-center justify-content-between">
        <a href="<?php echo ADMIN_URL; ?>/index.php?page=products" class="menu_link"><h4 class="mb-sm-0 font-size-18"><?php echo LGA_PRODUCTS; ?> - <?php echo LGA_IMPORT_EXPORT; ?></h4></a>
     
        <div class="page-title-right">
            <ol class="breadcrumb m-0">
                <li class="breadcrumb-item"><a href="<?php echo ADMIN_URL; ?>"><?php echo LGA_HOME; ?></a></li>
                <li class="breadcrumb-item active"><?php echo LGA_EXPORT; ?></li>
            </ol>
        </div>
     
    </div>
    </div>
    </div>
     
    <div class="row">
    <div class="col-12">
     
     
     
    <div class="card mb-3">
        <div class="card-header">
            <h4 class="card-title">Excel - <?php echo LGA_PRODUCTS; ?> - <?php echo LGA_EXPORT; ?></h4>
        </div>
        <div class="card-body p-4">
        <?php
        if(m_a_p('type')=='excel_export')
        {
            
            if(DEMO)
            {
     
                echo m_admin_alert(LGA_ERROR,LGA_DEMO_ERROR);
            }
            else
            {
                $list = array();
                $products = $db->table('products')->order('id','asc')->get();
                $list[0]['Stock Code'] = 'Stock';
                $list[0]['Bar Code'] = 'Bar Code';
                $list[0]['Stock'] = 'Stock';
                $list[0]['Brand'] = 'Brand';
                $list[0]['Product Title'] = 'Product Title';
                $list[0]['Product Image'] = 'Product Image';
                $list[0]['Undiscounted Price'] = 'Undiscounted Price';
                $list[0]['Sale Price'] = 'Sale Price';
                $list[0]['Categories'] = 'Categories';
                $n=1;
                foreach($products['data'] as $product)
                {
                    $list[$n]['Stock Code'] = $product['stock_code'];
                    $list[$n]['Bar Code'] = $product['barcode'];
                    $list[$n]['Stock'] = $product['stock'];
                    if($product['b_id']==0)
                    {
                        $list[$n]['Brand'] = '';
                    }
                    else
                    {
                        $list[$n]['Brand'] = $db->table('brands')->where('id','=',$product['b_id'])->get_var('title');
                    }
                    $list[$n]['Product Title'] = $product['title'];
                    $list[$n]['Product Image'] = m_image_url($product['image']);
                    $list[$n]['Undiscounted Price'] = m_currency($product['undiscounted_price']);
                    $list[$n]['Sale Price'] = m_currency($product['sale_price']);
                    $list[$n]['Categories'] = m_category_extract($product['c_id'],'text');
                    $n++;
                }
                 $xlsx = SimpleXLSXGen::fromArray( $list);
                 $file = ''.time().'-EXPORT.xlsx';
                 $xlsx->saveAs(''.UPLOAD_DIR.'/export/'.$file.'');
                 echo '<a href="'.SITE_DOMAIN.'/uploads/export/'.$file.'" class="btn btn-success btn-sm" download>'.LGA_TRANSACTION_SUCCESS.' - Download</a><br><br>';
                
            }
        }
        ?>
        
            <form action="" method="post" enctype="multipart/form-data">
            <input type="hidden" name="type" value="excel_export">
                <button type="submit" class="btn btn-success waves-effect btn-label waves-light"><i class="bx bx-check-double label-icon"></i> <?php echo LGA_EXPORT; ?></button>
            </form>
        </div>
    </div>
     
     
    <div class="card mb-3">
        <div class="card-header">
            <h4 class="card-title">XML - <?php echo LGA_PRODUCTS; ?> - <?php echo LGA_EXPORT; ?></h4>
        </div>
        <div class="card-body p-4">
        <?php
        if(m_a_p('type')=='xml_export')
        {
            
            if(DEMO)
            {
     
                echo m_admin_alert(LGA_ERROR,LGA_DEMO_ERROR);
            }
            else
            {
                $list = array();
                $products = $db->table('products')->order('id','asc')->get();
                $n=1;
                foreach($products['data'] as $product)
                {
                    $list[$n]['Stock_Code'] = $product['stock_code'];
                    $list[$n]['Bar_Code'] = $product['barcode'];
                    $list[$n]['Stock'] = $product['stock'];
                    if($product['b_id']==0)
                    {
                        $list[$n]['Brand'] = '';
                    }
                    else
                    {
                        $list[$n]['Brand'] = str_replace('&','&amp;',$db->table('brands')->where('id','=',$product['b_id'])->get_var('title'));
                    }
                    $list[$n]['Product_Title'] = str_replace('&','&amp;',$product['title']);
                    $list[$n]['Product_Image'] = m_image_url($product['image']);
                    $list[$n]['Product_Description'] = '<![CDATA['.$product['content'].']]>';
                    $list[$n]['Undiscounted_Price'] = m_currency($product['undiscounted_price']);
                    $list[$n]['Sale_Price'] = m_currency($product['sale_price']);
                    $list[$n]['Categories'] = str_replace('&','&amp;',m_category_extract($product['c_id'],'text'));
                    $n++;
                }
                $xml="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Products>\n";
                 foreach($list as $keyv => $valv)
                 {
                     $xml.= "<Product>\n";
                     foreach($valv as $key => $val)
                     {
                         $xml.="<".$key.">".$val."</".$key.">\n";
                          
                     }
                     $xml.= "</Product>\n";
                 }
                 $xml.= '</Products>';
                 $file = ''.time().'-EXPORT.xml';
                 file_put_contents(''.UPLOAD_DIR.'/export/'.$file.'',$xml);
                 echo '<a href="'.SITE_DOMAIN.'/uploads/export/'.$file.'" class="btn btn-success btn-sm" download>'.LGA_TRANSACTION_SUCCESS.' - Download</a><br><br>';
                
            }
        }
        ?>
        
            <form action="" method="post" enctype="multipart/form-data">
            <input type="hidden" name="type" value="xml_export">
                <button type="submit" class="btn btn-success waves-effect btn-label waves-light"><i class="bx bx-check-double label-icon"></i> <?php echo LGA_EXPORT; ?></button>
            </form>
        </div>
    </div>
     
    <div class="card mb-3">
        <div class="card-header">
            <h4 class="card-title">Excel - <?php echo LGA_PRODUCTS; ?> - <?php echo LGA_IMPORT; ?></h4>
        </div>
        <div class="card-body p-4">
        <?php
        if(m_a_p('type')=='excel_import')
        {
            
            if(DEMO)
            {
     
                echo m_admin_alert(LGA_ERROR,LGA_DEMO_ERROR);
            }
            else
            {
                $extension = end(explode('.',$_FILES['excel']['name']));
                if($extension=='xlsx')
                {
                    move_uploaded_file($_FILES['excel']['tmp_name'],UPLOAD_DIR.'/import/'.$_FILES['excel']['name']);
                    $xlsx = SimpleXLSX::parse(''.UPLOAD_DIR.'/import/'.$_FILES['excel']['name'].'');
                    $n=0;
                    foreach($xlsx->rowsEx() as $product)
                    {
                        if($n>0)
                        {
                            
                        $cat_id = '';
                        $stock_code = trim($product[m_a_p('stock_code_tag')]['value']);
                        $barcode = trim($product[m_a_p('barcode_tag')]['value']);
                        $stock = null_to_zero(trim($product[m_a_p('stock_tag')]['value']));
                        $title = $product[m_a_p('title_tag')]['value'];
                        $content = $product[m_a_p('description_tag')]['value'];
                        $image = $product[m_a_p('image_tag')]['value'];
                        $brand = trim($product[m_a_p('brand_tag')]['value']);
                        $category = trim($product[m_a_p('category_tag')]['value']);
                        $undiscounted_price = null_to_zero($product[m_a_p('undiscounted_price_tag')]['value']);
                        $sale_price = null_to_zero($product[m_a_p('sale_price_tag')]['value']);
                    
                        if($image=='')
                        {
                            $image_name = '';
                        }
                        else
                        {
                            
                            $extension = strtolower(end(explode('.',$image)));
                            $available_extension = array('jpg','jpeg','webp','png','bmp');
                            if(in_array($extension,$available_extension))
                            {
                                $image_name = 'product_'.m_sef($title).'_'.uniqid().'.'.$extension.'';
                                $upload_path = UPLOAD_DIR.'/images/'.$image_name;
                                copy($image,$upload_path);
                                $image_name = m_image_webp_convert(''.UPLOAD_DIR.'/images/'.m_image_extension_converter($image_name).'');
                                
                            }
                            else
                            {
                                $image_name = '';
                            }
                        }
                        $ct_n = 0;
                        $ct_id = 0;
                        foreach(explode('/',$category) as $cat_name)
                        {
                            $ct_n = 0;
                            $ct_id = 0;
                            $category_name = trim($cat_name);
                            $cat_search = $db->table('categories')->where('sef','=',m_sef($category_name))->get();
                            
                            if($cat_search['total_count']==0)
                            {
                                $data = [
                                'image' => '',
                                'c_id' => $ct_id,
                                'title' => $category_name,
                                'seo_content' => '',
                                'c_rank' => 0,
                                'sef' => m_sef($category_name),
                                'status' => 1
                                ];
                                $query = $db->table('categories')->insert($data);
                                if($ct_n==0)
                                {
                                    $ct_id = $query;
                                }
                                    $c_id.='['.$ct_id.']';
                                    
                            }
                            else
                            {
                                if($ct_n==0)
                                {
                                    $ct_id = $cat_search['data'][0]['id'];
                                    
                                }
                                $c_id.='['.$cat_search['data'][0]['id'].']';
                                
                            }
                            $ct_n++;
                            
                        }
                        if($brand=='')
                        {
                            $b_id = 0;
                        }
                        else
                        {
                            $brand_search = $db->table('brands')->where('sef','=',m_sef($brand))->get();
                            if($brand_search['total_count']==0)
                            {
                                $data = [
                                'title' => $brand,
                                'sef' => m_sef($brand),
                                'status' => 1
                                ];
                                
                                $b_id = $db->table('brands')->insert($data);
                            }
                            else
                            {
                                $b_id = $brand_search['data'][0]['id'];
                            }
                        }
                        
                        $data = [
                        'image' => $image_name,
                        'c_id' => $c_id,
                        'b_id' => $b_id,
                        'title' => $title,
                        'barcode' => $barcode,
                        'stock_code' => $stock_code,
                        'stock' => $stock,
                        'currency_type' => m_setting('currency_type'),
                        'foreign_type' => 0,
                        'foreign_currency' => 0,
                        'foreign_price' => 0,
                        'buying_price' => 0,
                        'market_price' => 0,
                        'sale_price' => $sale_price,
                        'undiscounted_price' => $undiscounted_price,
                        'cargo_price' => 0,
                        'cargo_time' => '',
                        'lead_time' => '',
                        'tax' => 0,
                        'tax_included' => 1,
                        'content' => $content,
                        'sef' => m_sef($title),
                        'date' => $db->now(),
                        'status' => 1
                        ];
                        $query = $db->table('products')->insert($data);
                        
                        }
                        $n++;
                        
                    }
                    echo m_admin_alert(LGA_SUCCESS,LGA_TRANSACTION_SUCCESS);
                    unlink(UPLOAD_DIR.'/import/'.$_FILES['excel']['name']);
                    
                }
                else
                {
                    echo m_admin_alert(LGA_ERROR,LGA_TRANSACTION_ERROR);
                }
                
                
                
            }
        }
        ?>
        
            <form action="" method="post" enctype="multipart/form-data">
            <input type="hidden" name="type" value="excel_import">
                            <div class="mb-3">
                                    <label class="form-label">Excel ( XLSX )</label>
                                    <input class="form-control" type="file" name="excel" required>
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_STOCK_CODE; ?> - <?php echo LGA_COLUMN_ROW; ?></label>
                                    <input class="form-control" type="text" name="stock_code_tag" value="0">
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_BARCODE; ?> - <?php echo LGA_COLUMN_ROW; ?></label>
                                    <input class="form-control" type="text" name="barcode_tag" value="1">
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_STOCK; ?> - <?php echo LGA_COLUMN_ROW; ?></label>
                                    <input class="form-control" type="text" name="stock_tag" value="2">
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_PRODUCT_NAME; ?> - <?php echo LGA_COLUMN_ROW; ?></label>
                                    <input class="form-control" type="text" name="title_tag" value="4" required>
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_PRODUCT_IMAGE; ?> - <?php echo LGA_COLUMN_ROW; ?></label>
                                    <input class="form-control" type="text" name="image_tag" value="5">
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_BRAND; ?> - <?php echo LGA_COLUMN_ROW; ?></label>
                                    <input class="form-control" type="text" name="brand_tag" value="3">
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_CATEGORY; ?> - <?php echo LGA_COLUMN_ROW; ?></label>
                                    <input class="form-control" type="text" name="category_tag" value="8" required>
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_UNDISCOUNTED_PRICE; ?> - <?php echo LGA_COLUMN_ROW; ?></label>
                                    <input class="form-control" type="text" name="undiscounted_price_tag" value="6">
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_SALE_PRICE; ?> - <?php echo LGA_COLUMN_ROW; ?></label>
                                    <input class="form-control" type="text" name="sale_price_tag" value="7" required>
                            </div>
                            
                <button type="submit" class="btn btn-success waves-effect btn-label waves-light"><i class="bx bx-check-double label-icon"></i> <?php echo LGA_IMPORT; ?></button>
            </form>
        </div>
    </div>
     
    <div class="card mb-3">
        <div class="card-header">
            <h4 class="card-title">XML - <?php echo LGA_PRODUCTS; ?> - <?php echo LGA_IMPORT; ?></h4>
        </div>
        <div class="card-body p-4">
        <?php
        if(m_a_p('type')=='xml_import')
        {
            
            if(DEMO)
            {
     
                echo m_admin_alert(LGA_ERROR,LGA_DEMO_ERROR);
            }
            else
            {
                $xml=simplexml_load_string(m_url_get(m_a_p('xml_url')));
                if($xml)
                {
                    $n=0;
                    foreach($xml->{m_a_p('product_tag')} as $product)
                    {
                        $cat_id = '';
                        $stock_code = trim($product->{m_a_p('stock_code_tag')});
                        $barcode = trim($product->{m_a_p('barcode_tag')});
                        $stock = null_to_zero(trim($product->{m_a_p('stock_tag')}));
                        $title = $product->{m_a_p('title_tag')};
                        $content = $product->{m_a_p('description_tag')};
                        $image = $product->{m_a_p('image_tag')};
                        $brand = trim($product->{m_a_p('brand_tag')});
                        $category = trim($product->{m_a_p('category_tag')});
                        $undiscounted_price = null_to_zero($product->{m_a_p('undiscounted_price_tag')});
                        $sale_price = null_to_zero($product->{m_a_p('sale_price_tag')});
                        if($image=='')
                        {
                            $image_name = '';
                        }
                        else
                        {
                            
                            $extension = strtolower(end(explode('.',$image)));
                            $available_extension = array('jpg','jpeg','webp','png','bmp');
                            if(in_array($extension,$available_extension))
                            {
                                $image_name = 'product_'.m_sef($title).'_'.uniqid().'.'.$extension.'';
                                $upload_path = UPLOAD_DIR.'/images/'.$image_name;
                                copy($image,$upload_path);
                                $image_name = m_image_webp_convert(''.UPLOAD_DIR.'/images/'.m_image_extension_converter($image_name).'');
                                
                            }
                            else
                            {
                                $image_name = '';
                            }
                        }
                        $ct_n = 0;
                        $ct_id = 0;
    
    <!--EKLEME BAŞI-->
    $c_id = '';
    foreach(explode('/',$category) as $cat_name) {
        $category_name = trim($cat_name);
        $cat_search = $db->table('categories')->where('sef','=',m_sef($category_name))->get();
    
        if($cat_search['total_count'] == 0) {
            $data = [
                'image' => '',
                'c_id' => $ct_id,
                'title' => $category_name,
                'seo_content' => '',
                'c_rank' => 0,
                'sef' => m_sef($category_name),
                'status' => 1
            ];
            $query = $db->table('categories')->insert($data);
            if($ct_n == 0) {
                $ct_id = $query;
            }
            $c_id .= '['.$ct_id.']';
        } else {
            if($ct_n == 0) {
                $ct_id = $cat_search['data'][0]['id'];
            }
            $c_id .= '['.$cat_search['data'][0]['id'].']';
        }
        $ct_n++;
    }
    
    <!--EKLEME SONU-->
                        if($brand=='')
                        {
                            $b_id = 0;
                        }
                        else
                        {
                            $brand_search = $db->table('brands')->where('sef','=',m_sef($brand))->get();
                            if($brand_search['total_count']==0)
                            {
                                $data = [
                                'title' => $brand,
                                'sef' => m_sef($brand),
                                'status' => 1
                                ];
                                
                                $b_id = $db->table('brands')->insert($data);
                            }
                            else
                            {
                                $b_id = $brand_search['data'][0]['id'];
                            }
                        }
                        
                        $data = [
                        'image' => $image_name,
                        'c_id' => $c_id,
                        'b_id' => $b_id,
                        'title' => $title,
                        'barcode' => $barcode,
                        'stock_code' => $stock_code,
                        'stock' => $stock,
                        'currency_type' => m_setting('currency_type'),
                        'foreign_type' => 0,
                        'foreign_currency' => 0,
                        'foreign_price' => 0,
                        'buying_price' => 0,
                        'market_price' => 0,
                        'sale_price' => $sale_price,
                        'undiscounted_price' => $undiscounted_price,
                        'cargo_price' => 0,
                        'cargo_time' => '',
                        'lead_time' => '',
                        'tax' => 0,
                        'tax_included' => 1,
                        'content' => $content,
                        'sef' => m_sef($title),
                        'date' => $db->now(),
                        'status' => 1
                        ];
                        $query = $db->table('products')->insert($data);
                        
                        
                        
                    }
                    echo m_admin_alert(LGA_SUCCESS,LGA_TRANSACTION_SUCCESS);
                }
                else
                {
                    echo m_admin_alert(LGA_ERROR,LGA_TRANSACTION_ERROR);
                }
                
                
                
            }
        }
        ?>
        
            <form action="" method="post" enctype="multipart/form-data">
            <input type="hidden" name="type" value="xml_import">
                            <div class="mb-3">
                                    <label class="form-label">XML URL</label>
                                    <input class="form-control" type="text" name="xml_url" required>
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_PRODUCT; ?> - TAG</label>
                                    <input class="form-control" type="text" name="product_tag" value="Product" required>
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_STOCK_CODE; ?> - TAG</label>
                                    <input class="form-control" type="text" name="stock_code_tag" value="Stock_Code">
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_BARCODE; ?> - TAG</label>
                                    <input class="form-control" type="text" name="barcode_tag" value="Barcode">
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_STOCK; ?> - TAG</label>
                                    <input class="form-control" type="text" name="stock_tag" value="Stock">
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_PRODUCT_NAME; ?> - TAG</label>
                                    <input class="form-control" type="text" name="title_tag" value="Product_Title" required>
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_PRODUCT_CONTENT; ?> - TAG</label>
                                    <input class="form-control" type="text" name="description_tag" value="Product_Description">
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_PRODUCT_IMAGE; ?> - TAG</label>
                                    <input class="form-control" type="text" name="image_tag" value="Product_Image">
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_BRAND; ?> - TAG</label>
                                    <input class="form-control" type="text" name="brand_tag" value="Brand">
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_CATEGORY; ?> - TAG</label>
                                    <input class="form-control" type="text" name="category_tag" value="Categories" required>
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_UNDISCOUNTED_PRICE; ?> - TAG</label>
                                    <input class="form-control" type="text" name="undiscounted_price_tag" value="Undiscounted_Price">
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_SALE_PRICE; ?> - TAG</label>
                                    <input class="form-control" type="text" name="sale_price_tag" value="Sale_Price" required>
                            </div>
                            
                <button type="submit" class="btn btn-success waves-effect btn-label waves-light"><i class="bx bx-check-double label-icon"></i> <?php echo LGA_IMPORT; ?></button>
            </form>
        </div>
    </div>
     
     
    </div>
    </div>
     
    </div>
    dener misin?
  • 27-03-2024, 16:17:44
    #5
    gorev adlı üyeden alıntı: mesajı görüntüle
    <?php if(!defined('ADMIN_INCLUDED')) { exit; } ?>
    <div class="container-fluid">
     
     
    <div class="row">
    <div class="col-12">
    <div class="page-title-box d-sm-flex align-items-center justify-content-between">
        <a href="<?php echo ADMIN_URL; ?>/index.php?page=products" class="menu_link"><h4 class="mb-sm-0 font-size-18"><?php echo LGA_PRODUCTS; ?> - <?php echo LGA_IMPORT_EXPORT; ?></h4></a>
     
        <div class="page-title-right">
            <ol class="breadcrumb m-0">
                <li class="breadcrumb-item"><a href="<?php echo ADMIN_URL; ?>"><?php echo LGA_HOME; ?></a></li>
                <li class="breadcrumb-item active"><?php echo LGA_EXPORT; ?></li>
            </ol>
        </div>
     
    </div>
    </div>
    </div>
     
    <div class="row">
    <div class="col-12">
     
     
     
    <div class="card mb-3">
        <div class="card-header">
            <h4 class="card-title">Excel - <?php echo LGA_PRODUCTS; ?> - <?php echo LGA_EXPORT; ?></h4>
        </div>
        <div class="card-body p-4">
        <?php
        if(m_a_p('type')=='excel_export')
        {
            
            if(DEMO)
            {
     
                echo m_admin_alert(LGA_ERROR,LGA_DEMO_ERROR);
            }
            else
            {
                $list = array();
                $products = $db->table('products')->order('id','asc')->get();
                $list[0]['Stock Code'] = 'Stock';
                $list[0]['Bar Code'] = 'Bar Code';
                $list[0]['Stock'] = 'Stock';
                $list[0]['Brand'] = 'Brand';
                $list[0]['Product Title'] = 'Product Title';
                $list[0]['Product Image'] = 'Product Image';
                $list[0]['Undiscounted Price'] = 'Undiscounted Price';
                $list[0]['Sale Price'] = 'Sale Price';
                $list[0]['Categories'] = 'Categories';
                $n=1;
                foreach($products['data'] as $product)
                {
                    $list[$n]['Stock Code'] = $product['stock_code'];
                    $list[$n]['Bar Code'] = $product['barcode'];
                    $list[$n]['Stock'] = $product['stock'];
                    if($product['b_id']==0)
                    {
                        $list[$n]['Brand'] = '';
                    }
                    else
                    {
                        $list[$n]['Brand'] = $db->table('brands')->where('id','=',$product['b_id'])->get_var('title');
                    }
                    $list[$n]['Product Title'] = $product['title'];
                    $list[$n]['Product Image'] = m_image_url($product['image']);
                    $list[$n]['Undiscounted Price'] = m_currency($product['undiscounted_price']);
                    $list[$n]['Sale Price'] = m_currency($product['sale_price']);
                    $list[$n]['Categories'] = m_category_extract($product['c_id'],'text');
                    $n++;
                }
                 $xlsx = SimpleXLSXGen::fromArray( $list);
                 $file = ''.time().'-EXPORT.xlsx';
                 $xlsx->saveAs(''.UPLOAD_DIR.'/export/'.$file.'');
                 echo '<a href="'.SITE_DOMAIN.'/uploads/export/'.$file.'" class="btn btn-success btn-sm" download>'.LGA_TRANSACTION_SUCCESS.' - Download</a><br><br>';
                
            }
        }
        ?>
        
            <form action="" method="post" enctype="multipart/form-data">
            <input type="hidden" name="type" value="excel_export">
                <button type="submit" class="btn btn-success waves-effect btn-label waves-light"><i class="bx bx-check-double label-icon"></i> <?php echo LGA_EXPORT; ?></button>
            </form>
        </div>
    </div>
     
     
    <div class="card mb-3">
        <div class="card-header">
            <h4 class="card-title">XML - <?php echo LGA_PRODUCTS; ?> - <?php echo LGA_EXPORT; ?></h4>
        </div>
        <div class="card-body p-4">
        <?php
        if(m_a_p('type')=='xml_export')
        {
            
            if(DEMO)
            {
     
                echo m_admin_alert(LGA_ERROR,LGA_DEMO_ERROR);
            }
            else
            {
                $list = array();
                $products = $db->table('products')->order('id','asc')->get();
                $n=1;
                foreach($products['data'] as $product)
                {
                    $list[$n]['Stock_Code'] = $product['stock_code'];
                    $list[$n]['Bar_Code'] = $product['barcode'];
                    $list[$n]['Stock'] = $product['stock'];
                    if($product['b_id']==0)
                    {
                        $list[$n]['Brand'] = '';
                    }
                    else
                    {
                        $list[$n]['Brand'] = str_replace('&','&amp;',$db->table('brands')->where('id','=',$product['b_id'])->get_var('title'));
                    }
                    $list[$n]['Product_Title'] = str_replace('&','&amp;',$product['title']);
                    $list[$n]['Product_Image'] = m_image_url($product['image']);
                    $list[$n]['Product_Description'] = '<![CDATA['.$product['content'].']]>';
                    $list[$n]['Undiscounted_Price'] = m_currency($product['undiscounted_price']);
                    $list[$n]['Sale_Price'] = m_currency($product['sale_price']);
                    $list[$n]['Categories'] = str_replace('&','&amp;',m_category_extract($product['c_id'],'text'));
                    $n++;
                }
                $xml="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Products>\n";
                 foreach($list as $keyv => $valv)
                 {
                     $xml.= "<Product>\n";
                     foreach($valv as $key => $val)
                     {
                         $xml.="<".$key.">".$val."</".$key.">\n";
                          
                     }
                     $xml.= "</Product>\n";
                 }
                 $xml.= '</Products>';
                 $file = ''.time().'-EXPORT.xml';
                 file_put_contents(''.UPLOAD_DIR.'/export/'.$file.'',$xml);
                 echo '<a href="'.SITE_DOMAIN.'/uploads/export/'.$file.'" class="btn btn-success btn-sm" download>'.LGA_TRANSACTION_SUCCESS.' - Download</a><br><br>';
                
            }
        }
        ?>
        
            <form action="" method="post" enctype="multipart/form-data">
            <input type="hidden" name="type" value="xml_export">
                <button type="submit" class="btn btn-success waves-effect btn-label waves-light"><i class="bx bx-check-double label-icon"></i> <?php echo LGA_EXPORT; ?></button>
            </form>
        </div>
    </div>
     
    <div class="card mb-3">
        <div class="card-header">
            <h4 class="card-title">Excel - <?php echo LGA_PRODUCTS; ?> - <?php echo LGA_IMPORT; ?></h4>
        </div>
        <div class="card-body p-4">
        <?php
        if(m_a_p('type')=='excel_import')
        {
            
            if(DEMO)
            {
     
                echo m_admin_alert(LGA_ERROR,LGA_DEMO_ERROR);
            }
            else
            {
                $extension = end(explode('.',$_FILES['excel']['name']));
                if($extension=='xlsx')
                {
                    move_uploaded_file($_FILES['excel']['tmp_name'],UPLOAD_DIR.'/import/'.$_FILES['excel']['name']);
                    $xlsx = SimpleXLSX::parse(''.UPLOAD_DIR.'/import/'.$_FILES['excel']['name'].'');
                    $n=0;
                    foreach($xlsx->rowsEx() as $product)
                    {
                        if($n>0)
                        {
                            
                        $cat_id = '';
                        $stock_code = trim($product[m_a_p('stock_code_tag')]['value']);
                        $barcode = trim($product[m_a_p('barcode_tag')]['value']);
                        $stock = null_to_zero(trim($product[m_a_p('stock_tag')]['value']));
                        $title = $product[m_a_p('title_tag')]['value'];
                        $content = $product[m_a_p('description_tag')]['value'];
                        $image = $product[m_a_p('image_tag')]['value'];
                        $brand = trim($product[m_a_p('brand_tag')]['value']);
                        $category = trim($product[m_a_p('category_tag')]['value']);
                        $undiscounted_price = null_to_zero($product[m_a_p('undiscounted_price_tag')]['value']);
                        $sale_price = null_to_zero($product[m_a_p('sale_price_tag')]['value']);
                    
                        if($image=='')
                        {
                            $image_name = '';
                        }
                        else
                        {
                            
                            $extension = strtolower(end(explode('.',$image)));
                            $available_extension = array('jpg','jpeg','webp','png','bmp');
                            if(in_array($extension,$available_extension))
                            {
                                $image_name = 'product_'.m_sef($title).'_'.uniqid().'.'.$extension.'';
                                $upload_path = UPLOAD_DIR.'/images/'.$image_name;
                                copy($image,$upload_path);
                                $image_name = m_image_webp_convert(''.UPLOAD_DIR.'/images/'.m_image_extension_converter($image_name).'');
                                
                            }
                            else
                            {
                                $image_name = '';
                            }
                        }
                        $ct_n = 0;
                        $ct_id = 0;
                        foreach(explode('/',$category) as $cat_name)
                        {
                            $ct_n = 0;
                            $ct_id = 0;
                            $category_name = trim($cat_name);
                            $cat_search = $db->table('categories')->where('sef','=',m_sef($category_name))->get();
                            
                            if($cat_search['total_count']==0)
                            {
                                $data = [
                                'image' => '',
                                'c_id' => $ct_id,
                                'title' => $category_name,
                                'seo_content' => '',
                                'c_rank' => 0,
                                'sef' => m_sef($category_name),
                                'status' => 1
                                ];
                                $query = $db->table('categories')->insert($data);
                                if($ct_n==0)
                                {
                                    $ct_id = $query;
                                }
                                    $c_id.='['.$ct_id.']';
                                    
                            }
                            else
                            {
                                if($ct_n==0)
                                {
                                    $ct_id = $cat_search['data'][0]['id'];
                                    
                                }
                                $c_id.='['.$cat_search['data'][0]['id'].']';
                                
                            }
                            $ct_n++;
                            
                        }
                        if($brand=='')
                        {
                            $b_id = 0;
                        }
                        else
                        {
                            $brand_search = $db->table('brands')->where('sef','=',m_sef($brand))->get();
                            if($brand_search['total_count']==0)
                            {
                                $data = [
                                'title' => $brand,
                                'sef' => m_sef($brand),
                                'status' => 1
                                ];
                                
                                $b_id = $db->table('brands')->insert($data);
                            }
                            else
                            {
                                $b_id = $brand_search['data'][0]['id'];
                            }
                        }
                        
                        $data = [
                        'image' => $image_name,
                        'c_id' => $c_id,
                        'b_id' => $b_id,
                        'title' => $title,
                        'barcode' => $barcode,
                        'stock_code' => $stock_code,
                        'stock' => $stock,
                        'currency_type' => m_setting('currency_type'),
                        'foreign_type' => 0,
                        'foreign_currency' => 0,
                        'foreign_price' => 0,
                        'buying_price' => 0,
                        'market_price' => 0,
                        'sale_price' => $sale_price,
                        'undiscounted_price' => $undiscounted_price,
                        'cargo_price' => 0,
                        'cargo_time' => '',
                        'lead_time' => '',
                        'tax' => 0,
                        'tax_included' => 1,
                        'content' => $content,
                        'sef' => m_sef($title),
                        'date' => $db->now(),
                        'status' => 1
                        ];
                        $query = $db->table('products')->insert($data);
                        
                        }
                        $n++;
                        
                    }
                    echo m_admin_alert(LGA_SUCCESS,LGA_TRANSACTION_SUCCESS);
                    unlink(UPLOAD_DIR.'/import/'.$_FILES['excel']['name']);
                    
                }
                else
                {
                    echo m_admin_alert(LGA_ERROR,LGA_TRANSACTION_ERROR);
                }
                
                
                
            }
        }
        ?>
        
            <form action="" method="post" enctype="multipart/form-data">
            <input type="hidden" name="type" value="excel_import">
                            <div class="mb-3">
                                    <label class="form-label">Excel ( XLSX )</label>
                                    <input class="form-control" type="file" name="excel" required>
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_STOCK_CODE; ?> - <?php echo LGA_COLUMN_ROW; ?></label>
                                    <input class="form-control" type="text" name="stock_code_tag" value="0">
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_BARCODE; ?> - <?php echo LGA_COLUMN_ROW; ?></label>
                                    <input class="form-control" type="text" name="barcode_tag" value="1">
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_STOCK; ?> - <?php echo LGA_COLUMN_ROW; ?></label>
                                    <input class="form-control" type="text" name="stock_tag" value="2">
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_PRODUCT_NAME; ?> - <?php echo LGA_COLUMN_ROW; ?></label>
                                    <input class="form-control" type="text" name="title_tag" value="4" required>
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_PRODUCT_IMAGE; ?> - <?php echo LGA_COLUMN_ROW; ?></label>
                                    <input class="form-control" type="text" name="image_tag" value="5">
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_BRAND; ?> - <?php echo LGA_COLUMN_ROW; ?></label>
                                    <input class="form-control" type="text" name="brand_tag" value="3">
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_CATEGORY; ?> - <?php echo LGA_COLUMN_ROW; ?></label>
                                    <input class="form-control" type="text" name="category_tag" value="8" required>
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_UNDISCOUNTED_PRICE; ?> - <?php echo LGA_COLUMN_ROW; ?></label>
                                    <input class="form-control" type="text" name="undiscounted_price_tag" value="6">
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_SALE_PRICE; ?> - <?php echo LGA_COLUMN_ROW; ?></label>
                                    <input class="form-control" type="text" name="sale_price_tag" value="7" required>
                            </div>
                            
                <button type="submit" class="btn btn-success waves-effect btn-label waves-light"><i class="bx bx-check-double label-icon"></i> <?php echo LGA_IMPORT; ?></button>
            </form>
        </div>
    </div>
     
    <div class="card mb-3">
        <div class="card-header">
            <h4 class="card-title">XML - <?php echo LGA_PRODUCTS; ?> - <?php echo LGA_IMPORT; ?></h4>
        </div>
        <div class="card-body p-4">
        <?php
        if(m_a_p('type')=='xml_import')
        {
            
            if(DEMO)
            {
     
                echo m_admin_alert(LGA_ERROR,LGA_DEMO_ERROR);
            }
            else
            {
                $xml=simplexml_load_string(m_url_get(m_a_p('xml_url')));
                if($xml)
                {
                    $n=0;
                    foreach($xml->{m_a_p('product_tag')} as $product)
                    {
                        $cat_id = '';
                        $stock_code = trim($product->{m_a_p('stock_code_tag')});
                        $barcode = trim($product->{m_a_p('barcode_tag')});
                        $stock = null_to_zero(trim($product->{m_a_p('stock_tag')}));
                        $title = $product->{m_a_p('title_tag')};
                        $content = $product->{m_a_p('description_tag')};
                        $image = $product->{m_a_p('image_tag')};
                        $brand = trim($product->{m_a_p('brand_tag')});
                        $category = trim($product->{m_a_p('category_tag')});
                        $undiscounted_price = null_to_zero($product->{m_a_p('undiscounted_price_tag')});
                        $sale_price = null_to_zero($product->{m_a_p('sale_price_tag')});
                        if($image=='')
                        {
                            $image_name = '';
                        }
                        else
                        {
                            
                            $extension = strtolower(end(explode('.',$image)));
                            $available_extension = array('jpg','jpeg','webp','png','bmp');
                            if(in_array($extension,$available_extension))
                            {
                                $image_name = 'product_'.m_sef($title).'_'.uniqid().'.'.$extension.'';
                                $upload_path = UPLOAD_DIR.'/images/'.$image_name;
                                copy($image,$upload_path);
                                $image_name = m_image_webp_convert(''.UPLOAD_DIR.'/images/'.m_image_extension_converter($image_name).'');
                                
                            }
                            else
                            {
                                $image_name = '';
                            }
                        }
                        $ct_n = 0;
                        $ct_id = 0;
    
    <!--EKLEME BAŞI-->
    $c_id = '';
    foreach(explode('/',$category) as $cat_name) {
        $category_name = trim($cat_name);
        $cat_search = $db->table('categories')->where('sef','=',m_sef($category_name))->get();
    
        if($cat_search['total_count'] == 0) {
            $data = [
                'image' => '',
                'c_id' => $ct_id,
                'title' => $category_name,
                'seo_content' => '',
                'c_rank' => 0,
                'sef' => m_sef($category_name),
                'status' => 1
            ];
            $query = $db->table('categories')->insert($data);
            if($ct_n == 0) {
                $ct_id = $query;
            }
            $c_id .= '['.$ct_id.']';
        } else {
            if($ct_n == 0) {
                $ct_id = $cat_search['data'][0]['id'];
            }
            $c_id .= '['.$cat_search['data'][0]['id'].']';
        }
        $ct_n++;
    }
    
    <!--EKLEME SONU-->
                        if($brand=='')
                        {
                            $b_id = 0;
                        }
                        else
                        {
                            $brand_search = $db->table('brands')->where('sef','=',m_sef($brand))->get();
                            if($brand_search['total_count']==0)
                            {
                                $data = [
                                'title' => $brand,
                                'sef' => m_sef($brand),
                                'status' => 1
                                ];
                                
                                $b_id = $db->table('brands')->insert($data);
                            }
                            else
                            {
                                $b_id = $brand_search['data'][0]['id'];
                            }
                        }
                        
                        $data = [
                        'image' => $image_name,
                        'c_id' => $c_id,
                        'b_id' => $b_id,
                        'title' => $title,
                        'barcode' => $barcode,
                        'stock_code' => $stock_code,
                        'stock' => $stock,
                        'currency_type' => m_setting('currency_type'),
                        'foreign_type' => 0,
                        'foreign_currency' => 0,
                        'foreign_price' => 0,
                        'buying_price' => 0,
                        'market_price' => 0,
                        'sale_price' => $sale_price,
                        'undiscounted_price' => $undiscounted_price,
                        'cargo_price' => 0,
                        'cargo_time' => '',
                        'lead_time' => '',
                        'tax' => 0,
                        'tax_included' => 1,
                        'content' => $content,
                        'sef' => m_sef($title),
                        'date' => $db->now(),
                        'status' => 1
                        ];
                        $query = $db->table('products')->insert($data);
                        
                        
                        
                    }
                    echo m_admin_alert(LGA_SUCCESS,LGA_TRANSACTION_SUCCESS);
                }
                else
                {
                    echo m_admin_alert(LGA_ERROR,LGA_TRANSACTION_ERROR);
                }
                
                
                
            }
        }
        ?>
        
            <form action="" method="post" enctype="multipart/form-data">
            <input type="hidden" name="type" value="xml_import">
                            <div class="mb-3">
                                    <label class="form-label">XML URL</label>
                                    <input class="form-control" type="text" name="xml_url" required>
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_PRODUCT; ?> - TAG</label>
                                    <input class="form-control" type="text" name="product_tag" value="Product" required>
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_STOCK_CODE; ?> - TAG</label>
                                    <input class="form-control" type="text" name="stock_code_tag" value="Stock_Code">
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_BARCODE; ?> - TAG</label>
                                    <input class="form-control" type="text" name="barcode_tag" value="Barcode">
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_STOCK; ?> - TAG</label>
                                    <input class="form-control" type="text" name="stock_tag" value="Stock">
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_PRODUCT_NAME; ?> - TAG</label>
                                    <input class="form-control" type="text" name="title_tag" value="Product_Title" required>
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_PRODUCT_CONTENT; ?> - TAG</label>
                                    <input class="form-control" type="text" name="description_tag" value="Product_Description">
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_PRODUCT_IMAGE; ?> - TAG</label>
                                    <input class="form-control" type="text" name="image_tag" value="Product_Image">
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_BRAND; ?> - TAG</label>
                                    <input class="form-control" type="text" name="brand_tag" value="Brand">
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_CATEGORY; ?> - TAG</label>
                                    <input class="form-control" type="text" name="category_tag" value="Categories" required>
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_UNDISCOUNTED_PRICE; ?> - TAG</label>
                                    <input class="form-control" type="text" name="undiscounted_price_tag" value="Undiscounted_Price">
                            </div>
                            <div class="mb-3">
                                    <label class="form-label"><?php echo LGA_SALE_PRICE; ?> - TAG</label>
                                    <input class="form-control" type="text" name="sale_price_tag" value="Sale_Price" required>
                            </div>
                            
                <button type="submit" class="btn btn-success waves-effect btn-label waves-light"><i class="bx bx-check-double label-icon"></i> <?php echo LGA_IMPORT; ?></button>
            </form>
        </div>
    </div>
     
     
    </div>
    </div>
     
    </div>
    dener misin?

    direk yapıştırdım sayfa böyleyken



    böyle oluyor