2011-08-21 15:01:34 +02:00
< ? php
2012-08-16 19:18:24 +02:00
/* Copyright ( C ) 2002 - 2003 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2014-08-15 23:20:31 +02:00
* Copyright ( C ) 2004 - 2014 Laurent Destailleur < eldy @ users . sourceforge . net >
2012-12-30 15:13:49 +01:00
* Copyright ( C ) 2005 - 2012 Regis Houssin < regis . houssin @ capnetworks . com >
2012-08-16 19:18:24 +02:00
* Copyright ( C ) 2011 - 2012 Juanjo Menent < jmenent @ 2 byte . es >
2013-09-10 16:43:06 +02:00
* Copyright ( C ) 2013 Cédric Salvador < csalvador @ gpcsolutions . fr >
2015-04-18 21:28:55 +02:00
* Copyright ( C ) 2015 Jean - François Ferry < jfefe @ aternatik . fr >
2011-08-21 15:01:34 +02: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 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2011-08-21 15:01:34 +02: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
* along with this program . If not , see < http :// www . gnu . org / licenses />.
*/
/**
* \file htdocs / fichinter / list . php
* \brief List of all interventions
* \ingroup ficheinter
*/
2012-08-22 23:24:21 +02:00
require '../main.inc.php' ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/fichinter/class/fichinter.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php' ;
2011-08-21 15:01:34 +02:00
$langs -> load ( " companies " );
2014-09-06 19:10:59 +02:00
$langs -> load ( " bills " );
2011-08-21 15:01:34 +02:00
$langs -> load ( " interventions " );
2012-02-27 22:26:22 +01:00
$socid = GETPOST ( 'socid' , 'int' );
2011-08-21 15:01:34 +02:00
// Security check
2012-02-27 22:26:22 +01:00
$fichinterid = GETPOST ( 'id' , 'int' );
2011-08-21 15:01:34 +02:00
if ( $user -> societe_id ) $socid = $user -> societe_id ;
$result = restrictedArea ( $user , 'ficheinter' , $fichinterid , 'fichinter' );
2016-02-11 20:40:33 +01:00
$limit = GETPOST ( 'limit' ) ? GETPOST ( 'limit' , 'int' ) : $conf -> liste_limit ;
2012-06-01 10:52:39 +02:00
$sortfield = GETPOST ( 'sortfield' , 'alpha' );
$sortorder = GETPOST ( 'sortorder' , 'alpha' );
$page = GETPOST ( 'page' , 'int' );
2012-08-19 09:05:50 +02:00
if ( $page == - 1 ) { $page = 0 ; }
2015-12-16 19:38:40 +01:00
$offset = $limit * $page ;
2012-06-01 10:52:39 +02:00
$pageprev = $page - 1 ;
2012-03-05 11:16:30 +01:00
$pagenext = $page + 1 ;
2011-08-21 15:01:34 +02:00
if ( ! $sortorder ) $sortorder = " DESC " ;
2014-10-17 13:09:18 +02:00
if ( ! $sortfield )
{
if ( empty ( $conf -> global -> FICHINTER_DISABLE_DETAILS )) $sortfield = " fd.date " ;
else $sortfield = " f.ref " ;
}
2011-08-21 15:01:34 +02:00
2014-11-03 17:48:10 +01:00
$search_ref = GETPOST ( 'search_ref' ) ? GETPOST ( 'search_ref' , 'alpha' ) : GETPOST ( 'search_inter' , 'alpha' );
2012-03-05 11:16:30 +01:00
$search_company = GETPOST ( 'search_company' , 'alpha' );
$search_desc = GETPOST ( 'search_desc' , 'alpha' );
2014-09-06 19:10:59 +02:00
$search_status = GETPOST ( 'search_status' );
2014-11-03 17:48:10 +01:00
$sall = GETPOST ( 'sall' );
2015-10-04 10:45:57 +02:00
$optioncss = GETPOST ( 'optioncss' , 'alpha' );
2011-08-21 15:01:34 +02:00
2015-10-17 00:52:35 +02:00
if ( GETPOST ( " button_removefilter_x " ) || GETPOST ( " button_removefilter.x " ) || GETPOST ( " button_removefilter " )) // Both test are required to be compatible with all browsers
2014-11-03 05:57:09 +01:00
{
$search_ref = " " ;
$search_company = " " ;
$search_desc = " " ;
$search_status = " " ;
}
2011-08-21 15:01:34 +02:00
2015-10-17 00:52:35 +02:00
// List of fields to search into when doing a "search in all"
$fieldstosearchall = array (
'f.ref' => 'Ref' ,
's.nom' => " ThirdParty " ,
'f.description' => 'Description' ,
'f.note_public' => 'NotePublic' ,
);
if ( empty ( $user -> socid )) $fieldstosearchall [ " f.note_private " ] = " NotePrivate " ;
if ( ! empty ( $conf -> global -> FICHINTER_DISABLE_DETAILS )) unset ( $fieldstosearchall [ 'f.description' ]);
2011-08-21 15:01:34 +02:00
/*
* View
*/
2014-09-06 19:10:59 +02:00
$form = new Form ( $db );
2014-09-18 09:24:10 +02:00
$interventionstatic = new Fichinter ( $db );
2014-09-06 19:10:59 +02:00
2014-09-18 09:24:10 +02:00
llxHeader ( '' , $langs -> trans ( " Intervention " ));
2011-08-21 15:01:34 +02:00
$sql = " SELECT " ;
$sql .= " f.ref, f.rowid as fichid, f.fk_statut, f.description, " ;
2014-10-17 13:09:18 +02:00
if ( empty ( $conf -> global -> FICHINTER_DISABLE_DETAILS )) $sql .= " fd.description as descriptiondetail, fd.date as dp, fd.duree, " ;
2014-10-04 17:20:17 +02:00
$sql .= " s.nom as name, s.rowid as socid, s.client " ;
2011-08-21 15:01:34 +02:00
$sql .= " FROM ( " . MAIN_DB_PREFIX . " societe as s " ;
2014-10-17 13:09:18 +02:00
if ( ! $user -> rights -> societe -> client -> voir && empty ( $socid )) $sql .= " , " . MAIN_DB_PREFIX . " societe_commerciaux as sc " ;
2011-08-21 15:01:34 +02:00
$sql .= " , " . MAIN_DB_PREFIX . " fichinter as f) " ;
2014-10-17 13:09:18 +02:00
if ( empty ( $conf -> global -> FICHINTER_DISABLE_DETAILS )) $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " fichinterdet as fd ON fd.fk_fichinter = f.rowid " ;
2011-08-21 15:01:34 +02:00
$sql .= " WHERE f.fk_soc = s.rowid " ;
$sql .= " AND f.entity = " . $conf -> entity ;
2013-09-10 16:43:06 +02:00
if ( $search_ref ) {
2013-09-13 10:52:04 +02:00
$sql .= natural_search ( 'f.ref' , $search_ref );
2013-09-10 16:43:06 +02:00
}
if ( $search_company ) {
2013-09-13 10:52:04 +02:00
$sql .= natural_search ( 's.nom' , $search_company );
2013-09-10 16:43:06 +02:00
}
if ( $search_desc ) {
2014-10-17 13:09:18 +02:00
if ( empty ( $conf -> global -> FICHINTER_DISABLE_DETAILS )) $sql .= natural_search ( array ( 'f.description' , 'fd.description' ), $search_desc );
else $sql .= natural_search ( array ( 'f.description' ), $search_desc );
2013-09-10 16:43:06 +02:00
}
2014-09-06 19:10:59 +02:00
if ( $search_status != '' && $search_status >= 0 ) {
$sql .= ' AND f.fk_statut = ' . $search_status ;
}
2012-08-16 19:18:24 +02:00
if ( ! $user -> rights -> societe -> client -> voir && empty ( $socid ))
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . $user -> id ;
if ( $socid )
$sql .= " AND s.rowid = " . $socid ;
2014-11-03 17:48:10 +01:00
if ( $sall ) {
2015-10-17 00:52:35 +02:00
$sql .= natural_search ( array_keys ( $fieldstosearchall ), $sall );
2014-11-03 17:48:10 +01:00
}
2016-02-11 20:40:33 +01:00
$sql .= $db -> order ( $sortfield , $sortorder );
2015-12-28 00:20:48 +01:00
$totalnboflines = 0 ;
$result = $db -> query ( $sql );
if ( $result )
{
$totalnboflines = $db -> num_rows ( $result );
}
2016-02-11 20:40:33 +01:00
2012-01-08 00:52:07 +01:00
$sql .= $db -> plimit ( $limit + 1 , $offset );
2014-10-17 13:09:18 +02:00
//print $sql;
2011-08-21 15:01:34 +02:00
$result = $db -> query ( $sql );
if ( $result )
{
$num = $db -> num_rows ( $result );
2016-02-11 20:40:33 +01:00
$param = '' ;
if ( $limit > 0 && $limit != $conf -> liste_limit ) $param .= '&limit=' . $limit ;
if ( $socid ) $param .= " &socid= " . $socid ;
if ( $search_ref ) $param .= " &search_ref= " . urlencode ( $search_ref );
if ( $search_company ) $param .= " &search_company= " . urlencode ( $search_company );
if ( $search_desc ) $param .= " &search_desc= " . urlencode ( $search_desc );
if ( $search_status != '' && $search_status > - 1 ) $param .= " &search_status= " . urlencode ( $search_status );
if ( $optioncss != '' ) $param .= '&optioncss=' . $optioncss ;
2011-08-21 15:01:34 +02:00
2014-09-06 19:10:59 +02:00
print '<form method="POST" action="' . $_SERVER [ " PHP_SELF " ] . '">' . " \n " ;
2015-10-04 12:31:32 +02:00
if ( $optioncss != '' ) print '<input type="hidden" name="optioncss" value="' . $optioncss . '">' ;
2016-02-16 17:43:05 +01:00
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">' ;
print '<input type="hidden" name="action" value="list">' ;
print '<input type="hidden" name="sortfield" value="' . $sortfield . '">' ;
print '<input type="hidden" name="sortorder" value="' . $sortorder . '">' ;
2015-10-17 00:52:35 +02:00
2016-02-11 20:40:33 +01:00
print_barre_liste ( $langs -> trans ( " ListOfInterventions " ), $page , $_SERVER [ 'PHP_SELF' ], $param , $sortfield , $sortorder , '' , $num , $totalnboflines , 'title_commercial.png' , 0 , '' , '' , $limit );
if ( $sall )
2015-10-17 00:52:35 +02:00
{
foreach ( $fieldstosearchall as $key => $val ) $fieldstosearchall [ $key ] = $langs -> trans ( $val );
2015-12-20 20:11:29 +01:00
print $langs -> trans ( " FilterOnInto " , $sall ) . join ( ', ' , $fieldstosearchall );
2015-10-17 00:52:35 +02:00
}
print '<table class="noborder" width="100%">' ;
2011-08-21 15:01:34 +02:00
2012-08-16 19:18:24 +02:00
print '<tr class="liste_titre">' ;
2016-02-11 20:40:33 +01:00
print_liste_field_titre ( $langs -> trans ( " Ref " ), $_SERVER [ " PHP_SELF " ], " f.ref " , " " , $param , 'width="15%"' , $sortfield , $sortorder );
print_liste_field_titre ( $langs -> trans ( " ThirdParty " ), $_SERVER [ " PHP_SELF " ], " s.nom " , " " , $param , '' , $sortfield , $sortorder );
print_liste_field_titre ( $langs -> trans ( " Description " ), $_SERVER [ " PHP_SELF " ], " f.description " , " " , $param , '' , $sortfield , $sortorder );
2014-08-15 23:20:31 +02:00
if ( empty ( $conf -> global -> FICHINTER_DISABLE_DETAILS ))
{
2014-09-18 00:48:53 +02:00
print_liste_field_titre ( '' , $_SERVER [ " PHP_SELF " ], '' );
2016-02-11 20:40:33 +01:00
print_liste_field_titre ( $langs -> trans ( " Date " ), $_SERVER [ " PHP_SELF " ], " fd.date " , " " , $param , 'align="center"' , $sortfield , $sortorder );
print_liste_field_titre ( $langs -> trans ( " Duration " ), $_SERVER [ " PHP_SELF " ], " fd.duree " , " " , $param , 'align="right"' , $sortfield , $sortorder );
2014-08-15 23:20:31 +02:00
}
2016-02-11 20:40:33 +01:00
print_liste_field_titre ( $langs -> trans ( " Status " ), $_SERVER [ " PHP_SELF " ], " f.fk_statut " , " " , $param , 'align="right"' , $sortfield , $sortorder );
2015-06-30 13:14:19 +02:00
print_liste_field_titre ( '' , $_SERVER [ " PHP_SELF " ], " " , '' , '' , '' , $sortfield , $sortorder , 'maxwidthsearch ' );
2011-08-21 15:01:34 +02:00
print " </tr> \n " ;
print '<tr class="liste_titre">' ;
print '<td class="liste_titre">' ;
print '<input type="text" class="flat" name="search_ref" value="' . $search_ref . '" size="8">' ;
print '</td><td class="liste_titre">' ;
print '<input type="text" class="flat" name="search_company" value="' . $search_company . '" size="10">' ;
print '</td><td class="liste_titre">' ;
print '<input type="text" class="flat" name="search_desc" value="' . $search_desc . '" size="12">' ;
print '</td>' ;
2014-08-15 23:20:31 +02:00
if ( empty ( $conf -> global -> FICHINTER_DISABLE_DETAILS ))
{
2014-09-18 00:48:53 +02:00
// Desc of line
print '<td class="liste_titre"> </td>' ;
2014-08-15 23:20:31 +02:00
print '<td class="liste_titre"> </td>' ;
print '<td class="liste_titre"> </td>' ;
}
2014-09-06 19:10:59 +02:00
print '<td class="liste_titre" align="right">' ;
2014-09-18 09:24:10 +02:00
$liststatus = $interventionstatic -> statuts_short ;
2016-03-25 15:34:37 +01:00
print $form -> selectarray ( 'search_status' , $liststatus , $search_status , 1 , 0 , 0 , '' , 1 );
2014-09-06 19:10:59 +02:00
print '</td>' ;
2016-02-07 15:50:48 +01:00
print '<td class="liste_titre" align="right">' ;
2016-03-25 15:53:44 +01:00
$searchpitco = $form -> showFilterAndCheckAddButtons ( 0 );
2016-02-07 15:50:48 +01:00
print $searchpitco ;
print '</td>' ;
print " </tr> \n " ;
2011-08-21 15:01:34 +02:00
$companystatic = new Societe ( $db );
$var = True ;
$total = 0 ;
$i = 0 ;
while ( $i < min ( $num , $limit ))
{
$objp = $db -> fetch_object ( $result );
$var =! $var ;
2013-06-20 09:18:12 +02:00
print " <tr " . $bc [ $var ] . " > " ;
2011-08-21 15:01:34 +02:00
print " <td> " ;
$interventionstatic -> id = $objp -> fichid ;
$interventionstatic -> ref = $objp -> ref ;
print $interventionstatic -> getNomUrl ( 1 );
print " </td> \n " ;
print '<td>' ;
2014-10-04 17:20:17 +02:00
$companystatic -> name = $objp -> name ;
2011-08-21 15:01:34 +02:00
$companystatic -> id = $objp -> socid ;
$companystatic -> client = $objp -> client ;
print $companystatic -> getNomUrl ( 1 , '' , 44 );
print '</td>' ;
print '<td>' . dol_htmlentitiesbr ( dol_trunc ( $objp -> description , 20 )) . '</td>' ;
2014-08-15 23:20:31 +02:00
if ( empty ( $conf -> global -> FICHINTER_DISABLE_DETAILS ))
{
2014-09-18 00:48:53 +02:00
print '<td>' . dol_htmlentitiesbr ( dol_trunc ( $objp -> descriptiondetail , 20 )) . '</td>' ;
2014-08-15 23:20:31 +02:00
print '<td align="center">' . dol_print_date ( $db -> jdate ( $objp -> dp ), 'dayhour' ) . " </td> \n " ;
print '<td align="right">' . convertSecondToTime ( $objp -> duree ) . '</td>' ;
}
2011-08-21 15:01:34 +02:00
print '<td align="right">' . $interventionstatic -> LibStatut ( $objp -> fk_statut , 5 ) . '</td>' ;
2014-12-23 18:00:14 +01:00
2014-11-03 05:57:09 +01:00
print '<td> </td>' ;
2011-08-21 15:01:34 +02:00
print " </tr> \n " ;
$total += $objp -> duree ;
$i ++ ;
}
2014-08-15 23:20:31 +02:00
$rowspan = 3 ;
if ( empty ( $conf -> global -> FICHINTER_DISABLE_DETAILS ))
{
print '<tr class="liste_total"><td colspan="5" class="liste_total">' . $langs -> trans ( " Total " ) . '</td>' ;
2014-11-03 05:57:09 +01:00
print '<td align="right" class="nowrap liste_total">' . convertSecondToTime ( $total ) . '</td><td> </td><td> </td>' ;
2014-08-15 23:20:31 +02:00
print '</tr>' ;
}
2014-12-23 18:00:14 +01:00
2011-08-21 15:01:34 +02:00
print '</table>' ;
print " </form> \n " ;
$db -> free ( $result );
}
else
{
dol_print_error ( $db );
}
2011-08-27 16:24:16 +02:00
llxFooter ();
2015-06-30 13:14:19 +02:00
$db -> close ();