<?php

  $position   = '../';
  $UrlImg     = "sandbox/switchpoint-app/articulos";

  require_once($position.'../switch/access.php');
  require_once($position.'assets/global.php');
  require_once($position.'assets/session.php');
  require_once($position.'assets/funciones.php');
  require_once($position.'assets/resize-class.php');

  //Articulos
  echo $Query = "
    SELECT
      art.id,
      art.codigo, art.sku,
      art.nombre, art.descripcion,
      art.principal, art.activo,
      pro.nombre AS proveedor,
      mar.nombre AS marca,
      cat.categoria
    FROM articulos art
    LEFT JOIN proveedores pro ON pro.id = art.fk_proveedor
    LEFT JOIN marcas mar ON mar.id = art.fk_marca
    LEFT JOIN cat_articulos_categorias cat ON cat.id = art.fk_articulo_categoria
      ORDER BY art.nombre ASC
  ";
  $Arts = mysqli_query($mysqli, $Query);
  mysqli_data_seek($Arts, 0);
  while($Art = mysqli_fetch_array($Arts)) {

    echo $Image    = $RootSite."/".$UrlImg."/".$Art[id].'.jpg';
    $ImageUpM = $RootSite.'/'.$UrlImg."/".$Art[id]."-m.jpg";
    echo '<br />';
    if (file_exists($Image)) {

      echo $Image;
      echo '<br />';

      if ( copy($Image, $ImageUpM) ){
        chmod($ImageUpM, 0777);
        //Ajuste de tamaño
        $width = getWidth($ImageUpM);
        $height = getHeight($ImageUpM);
        $max_width = "1800";
        if ($width > $max_width){
          $scale = $max_width/$width;
          $resizeObj = new resize($ImageUpM);
          $resizeObj -> resizeImage(200, 200, 'crop');
          $resizeObj -> saveImage($ImageUpM, 70);
        }else{
          $scale = 1;
          $resizeObj = new resize($ImageUpM);
          $resizeObj -> resizeImage(200, 200, 'crop');
          $resizeObj -> saveImage($ImageUpM, 70);
        }
      }

    }

  }
?>
