2005-03-10 16:41:49 +00:00
< ? php
2007-01-02 15:27:51 +00:00
/* Copyright ( C ) 2001 - 2007 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2014-03-18 21:24:57 +00:00
* Copyright ( C ) 2004 - 2014 Laurent Destailleur < eldy @ users . sourceforge . net >
2005-07-12 08:51:47 +00:00
* Copyright ( C ) 2005 Eric Seigne < eric . seigne @ ryxeo . com >
2012-12-30 14:13:49 +00:00
* Copyright ( C ) 2005 - 2012 Regis Houssin < regis . houssin @ capnetworks . com >
2005-03-10 16:41:49 +00:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
2013-01-16 14:36:08 +00:00
* the Free Software Foundation ; either version 3 of the License , or
2005-03-10 16:41:49 +00:00
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2011-07-31 23:19:04 +00:00
* along with this program . If not , see < http :// www . gnu . org / licenses />.
2005-03-10 16:41:49 +00:00
*/
/**
2009-08-06 13:21:23 +00:00
* \file htdocs / product / photos . php
* \ingroup product
* \brief Onglet photos de la fiche produit
2009-05-06 16:27:45 +00:00
*/
2005-03-10 16:41:49 +00:00
2012-08-22 21:24:21 +00:00
require '../main.inc.php' ;
2012-08-22 21:11:24 +00:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/product.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php' ;
2005-03-10 16:41:49 +00:00
2010-05-02 17:05:07 +00:00
$langs -> load ( " products " );
2005-06-26 15:37:57 +00:00
$langs -> load ( " bills " );
2005-03-10 16:41:49 +00:00
2012-02-11 10:44:15 +00:00
$id = GETPOST ( 'id' , 'int' );
$ref = GETPOST ( 'ref' , 'alpha' );
2012-02-15 18:35:19 +00:00
$action = GETPOST ( 'action' , 'alpha' );
$confirm = GETPOST ( 'confirm' , 'alpha' );
2012-02-11 10:44:15 +00:00
2009-04-27 20:37:50 +00:00
// Security check
2012-02-11 10:44:15 +00:00
$fieldvalue = ( ! empty ( $id ) ? $id : ( ! empty ( $ref ) ? $ref : '' ));
$fieldtype = ( ! empty ( $ref ) ? 'ref' : 'rowid' );
2009-04-27 20:37:50 +00:00
if ( $user -> societe_id ) $socid = $user -> societe_id ;
2012-02-11 10:44:15 +00:00
$result = restrictedArea ( $user , 'produit|service' , $fieldvalue , 'product&product' , '' , '' , $fieldtype );
2005-03-10 16:41:49 +00:00
$mesg = '' ;
2012-04-06 20:39:40 +00:00
$object = new Product ( $db );
2012-05-22 17:11:41 +00:00
if ( $id > 0 || ! empty ( $ref ))
{
2012-04-06 20:39:40 +00:00
$result = $object -> fetch ( $id , $ref );
2012-05-22 17:11:41 +00:00
$dir = ( ! empty ( $conf -> product -> multidir_output [ $object -> entity ]) ? $conf -> product -> multidir_output [ $object -> entity ] : $conf -> service -> multidir_output [ $object -> entity ]);
2012-04-06 20:39:40 +00:00
}
2005-03-10 16:41:49 +00:00
2010-06-02 08:57:27 +00:00
2005-03-10 16:41:49 +00:00
/*
2005-06-11 11:39:38 +00:00
* Actions
2005-03-10 16:41:49 +00:00
*/
2012-07-09 10:31:21 +00:00
if ( isset ( $_FILES [ 'userfile' ]) && $_FILES [ 'userfile' ][ 'size' ] > 0 && GETPOST ( 'sendit' ) && ! empty ( $conf -> global -> MAIN_UPLOAD_DOC ))
2005-03-10 16:41:49 +00:00
{
2012-04-06 20:39:40 +00:00
if ( $object -> id ) $result = $object -> add_photo ( $dir , $_FILES [ 'userfile' ]);
2005-03-10 16:41:49 +00:00
}
2005-06-11 11:39:38 +00:00
2012-02-15 18:35:19 +00:00
if ( $action == 'confirm_delete' && $_GET [ " file " ] && $confirm == 'yes' && ( $user -> rights -> produit -> creer || $user -> rights -> service -> creer ))
2005-06-29 01:14:52 +00:00
{
2012-04-06 20:39:40 +00:00
$object -> delete_photo ( $dir . " / " . $_GET [ " file " ]);
2005-06-29 01:14:52 +00:00
}
2012-02-15 18:35:19 +00:00
if ( $action == 'addthumb' && $_GET [ " file " ])
2007-07-30 10:51:41 +00:00
{
2012-04-06 20:39:40 +00:00
$object -> add_thumb ( $dir . " / " . $_GET [ " file " ]);
2007-07-30 10:51:41 +00:00
}
2005-06-11 11:39:38 +00:00
2005-03-10 16:41:49 +00:00
/*
2009-08-06 13:21:23 +00:00
* View
2005-03-10 16:41:49 +00:00
*/
2005-06-29 01:14:52 +00:00
2011-11-08 09:18:45 +00:00
$form = new Form ( $db );
2005-06-11 11:39:38 +00:00
2012-04-06 20:39:40 +00:00
if ( $object -> id )
2005-03-10 16:41:49 +00:00
{
2012-04-06 20:39:40 +00:00
llxHeader ( " " , " " , $langs -> trans ( " CardProduct " . $object -> type ));
2012-07-09 10:31:21 +00:00
2012-05-22 17:11:41 +00:00
/*
* En mode visu
*/
$head = product_prepare_head ( $object , $user );
$titre = $langs -> trans ( " CardProduct " . $object -> type );
$picto = ( $object -> type == 1 ? 'service' : 'product' );
dol_fiche_head ( $head , 'photos' , $titre , 0 , $picto );
2012-07-09 10:31:21 +00:00
2012-05-22 17:11:41 +00:00
/*
* Confirmation de la suppression de photo
*/
2012-07-09 10:31:21 +00:00
if ( $action == 'delete' )
2012-05-22 17:11:41 +00:00
{
2013-09-06 10:10:09 +00:00
print $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&file=' . $_GET [ " file " ], $langs -> trans ( 'DeletePicture' ), $langs -> trans ( 'ConfirmDeletePicture' ), 'confirm_delete' , '' , 0 , 1 );
2013-12-15 13:26:27 +00:00
2012-05-22 17:11:41 +00:00
}
2012-07-09 10:31:21 +00:00
2012-05-22 17:11:41 +00:00
print ( $mesg );
2012-07-09 10:31:21 +00:00
2012-05-22 17:11:41 +00:00
print '<table class="border" width="100%">' ;
2012-07-09 10:31:21 +00:00
2012-05-22 17:11:41 +00:00
// Reference
print '<tr>' ;
print '<td width="15%">' . $langs -> trans ( " Ref " ) . '</td><td colspan="2">' ;
print $form -> showrefnav ( $object , 'ref' , '' , 1 , 'ref' );
print '</td>' ;
print '</tr>' ;
2012-07-09 10:31:21 +00:00
2012-05-22 17:11:41 +00:00
// Libelle
print '<tr><td>' . $langs -> trans ( " Label " ) . '</td><td colspan="2">' . $object -> libelle . '</td>' ;
print '</tr>' ;
2012-07-09 10:31:21 +00:00
2012-05-22 17:11:41 +00:00
// Status (to sell)
print '<tr><td>' . $langs -> trans ( " Status " ) . ' (' . $langs -> trans ( " Sell " ) . ')</td><td>' ;
print $object -> getLibStatut ( 2 , 0 );
print '</td></tr>' ;
2012-07-09 10:31:21 +00:00
2012-05-22 17:11:41 +00:00
// Status (to buy)
print '<tr><td>' . $langs -> trans ( " Status " ) . ' (' . $langs -> trans ( " Buy " ) . ')</td><td>' ;
print $object -> getLibStatut ( 2 , 1 );
print '</td></tr>' ;
2012-07-09 10:31:21 +00:00
2012-05-22 17:11:41 +00:00
print " </table> \n " ;
2012-07-09 10:31:21 +00:00
2012-05-22 17:11:41 +00:00
print " </div> \n " ;
2012-07-09 10:31:21 +00:00
2012-05-22 17:11:41 +00:00
/* ************************************************************************** */
/* */
/* Barre d'action */
/* */
/* ************************************************************************** */
2012-07-09 10:31:21 +00:00
2012-05-22 17:11:41 +00:00
print " \n <div class= \" tabsAction \" > \n " ;
2012-07-09 10:31:21 +00:00
if ( $action != 'ajout_photo' && ( $user -> rights -> produit -> creer || $user -> rights -> service -> creer ))
2012-05-22 17:11:41 +00:00
{
if ( ! empty ( $conf -> global -> MAIN_UPLOAD_DOC ))
{
print '<a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?action=ajout_photo&id=' . $object -> id . '">' ;
print $langs -> trans ( " AddPhoto " ) . '</a>' ;
}
else
{
print '<a class="butActionRefused" href="#">e' ;
print $langs -> trans ( " AddPhoto " ) . '</a>' ;
}
}
2012-07-09 10:31:21 +00:00
2012-05-22 17:11:41 +00:00
print " \n </div> \n " ;
2012-07-09 10:31:21 +00:00
2012-05-22 17:11:41 +00:00
/*
* Add a photo
2012-11-01 09:48:48 +00:00
*/
2012-05-22 17:11:41 +00:00
if ( $action == 'ajout_photo' && ( $user -> rights -> produit -> creer || $user -> rights -> service -> creer ) && ! empty ( $conf -> global -> MAIN_UPLOAD_DOC ))
{
// Affiche formulaire upload
$formfile = new FormFile ( $db );
2014-03-18 21:24:57 +00:00
$formfile -> form_attach_new_file ( $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id , $langs -> trans ( " AddPhoto " ), 1 , 0 , ( $user -> rights -> produit -> creer || $user -> rights -> service -> creer ), 50 , $object , '' , false , '' , 0 ); // ajax=false for the moment. true may not work.
2012-05-22 17:11:41 +00:00
}
2012-07-09 10:31:21 +00:00
2012-05-22 17:11:41 +00:00
// Affiche photos
if ( $action != 'ajout_photo' )
{
$nbphoto = 0 ;
$nbbyrow = 5 ;
2012-07-09 10:31:21 +00:00
2012-05-22 17:11:41 +00:00
$maxWidth = 160 ;
$maxHeight = 120 ;
2012-07-09 10:31:21 +00:00
2012-05-22 17:11:41 +00:00
print $object -> show_photos ( $dir , 1 , 1000 , $nbbyrow , 1 , 1 );
2012-07-09 10:31:21 +00:00
2012-05-22 17:11:41 +00:00
if ( $object -> nbphoto < 1 )
{
print '<br>' ;
2012-11-01 09:48:48 +00:00
print '<table width="100%" valign="top" align="center" border="0" cellpadding="2" cellspacing="2">' ;
print '<tr align=center valign=middle border=1><td class="photo">' ;
2012-05-22 17:11:41 +00:00
print " <br> " . $langs -> trans ( " NoPhotoYet " ) . " <br><br> " ;
print '</td></tr>' ;
print '</table>' ;
}
2009-05-06 16:27:45 +00:00
}
2005-03-10 16:41:49 +00:00
}
else
{
2009-05-06 16:27:45 +00:00
print $langs -> trans ( " ErrorUnknown " );
2005-03-10 16:41:49 +00:00
}
2012-02-15 18:35:19 +00:00
llxFooter ();
2005-03-10 16:41:49 +00:00
$db -> close ();
?>