dolibarr/htdocs/core/boxes/box_ficheinter.php

183 lines
5.4 KiB
PHP
Raw Normal View History

<?php
2017-11-02 17:58:46 +01:00
/* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2015 Frederic France <frederic.france@free.fr>
*
2015-01-25 01:20:58 +01: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
* the Free Software Foundation; either version 3 of the License, or
* (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
2019-09-23 21:55:30 +02:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2015-01-25 01:20:58 +01:00
*/
/**
2013-08-22 16:49:23 +02:00
* \file htdocs/core/boxes/box_ficheinter.php
* \ingroup ficheinter
2013-08-22 16:49:23 +02:00
* \brief Box to show last interventions
*/
include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
/**
2013-08-22 16:49:23 +02:00
* Class to manage the box to show last interventions
*/
class box_ficheinter extends ModeleBoxes
{
2019-02-28 20:48:07 +01:00
public $boxcode="ficheinter";
public $boximg="object_intervention";
public $boxlabel="BoxFicheInter";
public $depends = array("ficheinter"); // conf->contrat->enabled
2018-08-22 10:51:55 +02:00
/**
* @var DoliDB Database handler.
*/
public $db;
2019-02-09 15:24:21 +01:00
2019-02-28 20:48:07 +01:00
public $param;
2019-02-28 20:48:07 +01:00
public $info_box_head = array();
public $info_box_contents = array();
2017-06-12 14:09:00 +02:00
/**
* Constructor
*
* @param DoliDB $db Database handler
* @param string $param More parameters
*/
2019-02-28 20:48:07 +01:00
public function __construct($db, $param)
2017-06-12 14:09:00 +02:00
{
global $user;
2019-08-31 01:54:21 +02:00
$this->db = $db;
2017-06-12 14:09:00 +02:00
2019-08-31 01:54:21 +02:00
$this->hidden = ! ($user->rights->ficheinter->lire);
2017-06-12 14:09:00 +02:00
}
/**
* Load data for box to show them later
*
* @param int $max Maximum number of records to load
* @return void
*/
2019-02-28 20:48:07 +01:00
public function loadBox($max = 10)
{
2019-09-23 18:13:26 +02:00
global $user, $langs, $conf;
2013-06-08 00:52:02 +02:00
$this->max=$max;
include_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
2019-09-23 18:13:26 +02:00
$ficheinterstatic=new Fichinter($this->db);
$companystatic = new Societe($this->db);
2013-06-08 00:52:02 +02:00
$this->info_box_head = array('text' => $langs->trans("BoxTitleLastFicheInter", $max));
2017-11-02 17:58:46 +01:00
if (! empty($user->rights->ficheinter->lire))
{
$sql = "SELECT f.rowid, f.ref, f.fk_soc, f.fk_statut,";
$sql.= " f.datec,";
$sql.= " f.date_valid as datev,";
$sql.= " f.tms as datem,";
2019-09-23 18:13:26 +02:00
$sql.= " s.nom as name, s.rowid as socid, s.client, s.email as semail";
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
if (! $user->rights->societe->client->voir) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= ", ".MAIN_DB_PREFIX."fichinter as f";
$sql.= " WHERE f.fk_soc = s.rowid ";
$sql.= " AND f.entity = ".$conf->entity;
if (! $user->rights->societe->client->voir && !$user->socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
if($user->socid) $sql.= " AND s.rowid = ".$user->socid;
$sql.= " ORDER BY f.tms DESC";
2019-09-23 18:13:26 +02:00
$sql.= $this->db->plimit($max, 0);
2014-06-13 01:34:39 +02:00
dol_syslog(get_class($this).'::loadBox', LOG_DEBUG);
2019-09-23 18:13:26 +02:00
$resql = $this->db->query($sql);
if ($resql)
{
2019-09-23 18:13:26 +02:00
$num = $this->db->num_rows($resql);
$now=dol_now();
$i = 0;
while ($i < $num)
{
2019-09-23 18:13:26 +02:00
$objp = $this->db->fetch_object($resql);
$datec = $this->db->jdate($objp->datec);
$ficheinterstatic->statut=$objp->fk_statut;
$ficheinterstatic->id=$objp->rowid;
2017-11-11 00:28:00 +01:00
$ficheinterstatic->ref=$objp->ref;
2013-06-08 00:52:02 +02:00
2019-09-23 18:13:26 +02:00
$companystatic->id = $objp->socid;
$companystatic->name = $objp->name;
$companystatic->email = $objp->semail;
2019-02-09 15:24:21 +01:00
$this->info_box_contents[$i][] = array(
2019-11-04 11:40:54 +01:00
'td' => 'class="nowraponall"',
2019-02-09 15:24:21 +01:00
'text' => $ficheinterstatic->getNomUrl(1),
'asis' => 1,
2017-11-11 00:28:00 +01:00
);
2019-02-09 15:24:21 +01:00
$this->info_box_contents[$i][] = array(
2019-11-04 11:40:54 +01:00
'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
2019-09-23 18:13:26 +02:00
'text' => $companystatic->getNomUrl(1),
'asis' => 1,
2019-02-09 15:24:21 +01:00
);
$this->info_box_contents[$i][] = array(
'td' => 'class="right"',
'text' => dol_print_date($datec, 'day'),
);
$this->info_box_contents[$i][] = array(
'td' => 'class="nowrap right"',
2019-10-31 23:50:36 +01:00
'text' => $ficheinterstatic->getLibStatut(3),
2019-02-09 15:24:21 +01:00
'asis' => 1,
);
$i++;
}
2019-02-09 15:24:21 +01:00
if ($num==0) $this->info_box_contents[$i][] = array('td' => 'class="center"','text'=>$langs->trans("NoRecordedInterventions"));
2013-06-08 00:52:02 +02:00
2019-09-23 18:13:26 +02:00
$this->db->free($resql);
}
else
{
2019-02-09 15:24:21 +01:00
$this->info_box_contents[0][] = array(
'td' => '',
'maxlength'=>500,
2019-09-23 18:13:26 +02:00
'text' => ($this->db->error().' sql='.$sql),
2019-02-09 15:24:21 +01:00
);
}
}
else
{
2017-11-11 00:28:00 +01:00
$this->info_box_contents[0][] = array(
2019-02-09 15:24:21 +01:00
'td' => 'class="nohover opacitymedium left"',
'text' => $langs->trans("ReadPermissionNotAllowed")
);
}
}
/**
* Method to show box
*
* @param array $head Array with properties of box title
* @param array $contents Array with properties of box lines
2016-06-27 13:57:10 +02:00
* @param int $nooutput No print, only return string
2017-06-12 14:09:00 +02:00
* @return string
*/
2019-02-28 20:48:07 +01:00
public function showBox($head = null, $contents = null, $nooutput = 0)
2016-06-27 13:57:10 +02:00
{
2017-06-12 14:09:00 +02:00
return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
}
}