/**
  *	Constructor
  *
  *  @param		DoliDB		$db      Database handler
  */
 function __construct($db)
 {
     global $conf;
     $this->db = $db;
     $this->arrayofproducts = array();
     // List of services
     $sql = "SELECT ref FROM " . MAIN_DB_PREFIX . "product";
     $sql .= " WHERE entity IN (" . getEntity('product', 1) . ")";
     if (empty($conf->global->CONTRACT_SUPPORT_PRODUCTS)) {
         $sql .= " AND fk_product_type = 1";
     }
     // By default, only services
     $sql .= " ORDER BY ref";
     $result = $this->db->query($sql);
     if ($result) {
         $num = $this->db->num_rows($result);
         dol_syslog("dolibarr_services_expired.modules.php:mailing_dolibarr_services_expired " . $num . " services found");
         $i = 0;
         while ($i < $num) {
             $obj = $this->db->fetch_object($result);
             $i++;
             $this->arrayofproducts[$i] = $obj->ref;
         }
     } else {
         dol_print_error($this->db);
     }
 }
	/**
	 * Constructor
	 *
	 * @param  $DB
	 * @return mailing_thirdparties_services_expired
	 */
	function mailing_thirdparties_services_expired($DB)
	{
		$this->db=$DB;

		$this->arrayofproducts=array();

		// List of services
		$sql = "SELECT ref FROM ".MAIN_DB_PREFIX."product";
		$sql.= " WHERE fk_product_type = 1";
		$sql.= " ORDER BY ref";
		$result=$this->db->query($sql);
		if ($result)
		{
			$num = $this->db->num_rows($result);
			dolibarr_syslog("dolibarr_services_expired.modules.php:mailing_dolibarr_services_expired ".$num." services found");

			$i = 0;
			while ($i < $num)
			{
				$obj = $this->db->fetch_object($result);
				$i++;
				$this->arrayofproducts[$i]=$obj->ref;
			}

		}
		else
		{
			dol_print_error($this->db);
		}
	}
Example #3
0
 /**
  *  Load data into info_box_contents array to show array later.
  *
  *  @param	int		$max        Maximum number of records to load
  *  @return	void
  */
 function loadBox($max = 5)
 {
     global $conf, $user, $langs, $db;
     $langs->load("boxes");
     $this->max = $max;
     $this->info_box_head = array('text' => $langs->trans("BoxTitleNbOfCustomers", $max));
     if ($user->rights->boutique->lire) {
         $sql = "SELECT count(*) as cus FROM " . $conf->global->OSC_DB_NAME . "." . $conf->global->OSC_DB_TABLE_PREFIX . "customers";
         $resql = $db->query($sql);
         if ($resql) {
             $num = $db->num_rows($resql);
             $i = 0;
             while ($i < $num) {
                 $objp = $db->fetch_object($resql);
                 $this->info_box_contents[$i][0] = array('td' => 'align="center" width="16"', 'logo' => $this->boximg, 'url' => DOL_URL_ROOT . "/boutique/client/index.php");
                 $this->info_box_contents[$i][1] = array('td' => 'align="center"', 'text' => $objp->cus, 'url' => DOL_URL_ROOT . "/boutique/client/index.php");
                 $i++;
             }
         } else {
             dol_print_error($db);
         }
     } else {
         $this->info_box_contents[0][0] = array('td' => 'align="left"', 'text' => $langs->trans("ReadPermissionNotAllowed"));
     }
 }
Example #4
0
/**
 * Return server timezone int.
 *
 * @param	string	$refgmtdate		Reference period for timezone (timezone differs on winter and summer. May be 'now', 'winter' or 'summer')
 * @return 	int						An offset in hour (+1 for Europe/Paris on winter and +2 for Europe/Paris on summer)
 */
function getServerTimeZoneInt($refgmtdate = 'now')
{
    global $conf;
    if (method_exists('DateTimeZone', 'getOffset')) {
        // Method 1 (include daylight)
        $gmtnow = dol_now('gmt');
        $yearref = dol_print_date($gmtnow, '%Y');
        $monthref = dol_print_date($gmtnow, '%m');
        $dayref = dol_print_date($gmtnow, '%d');
        if ($refgmtdate == 'now') {
            $newrefgmtdate = $yearref . '-' . $monthref . '-' . $dayref;
        } elseif ($refgmtdate == 'summer') {
            $newrefgmtdate = $yearref . '-08-01';
        } else {
            $newrefgmtdate = $yearref . '-01-01';
        }
        $newrefgmtdate .= 'T00:00:00+00:00';
        $localtz = new DateTimeZone(getServerTimeZoneString());
        $localdt = new DateTime($newrefgmtdate, $localtz);
        $tmp = -1 * $localtz->getOffset($localdt);
        //print $refgmtdate.'='.$tmp;
    } else {
        $tmp = 0;
        dol_print_error('', 'PHP version must be 5.3+');
    }
    $tz = round(($tmp < 0 ? 1 : -1) * abs($tmp / 3600));
    return $tz;
}
Example #5
0
	/**
	 *	Charge indicateurs this->nb de tableau de bord
	 *
	 *	@return     int         <0 if KO, >0 if OK
	 */
	function load_state_board()
	{
		global $conf, $user;

		$this->nb=array();

		$sql = "SELECT count(p.rowid) as nb";
		$sql.= " FROM ".MAIN_DB_PREFIX."product as p";
		$sql.= ' WHERE p.entity IN ('.getEntity('product', 1).')';
		$sql.= " AND p.fk_product_type = 1";

		$resql=$this->db->query($sql);
		if ($resql)
		{
			while ($obj=$this->db->fetch_object($resql))
			{
				$this->nb["services"]=$obj->nb;
			}
			return 1;
		}
		else
		{
			dol_print_error($this->db);
			$this->error=$this->db->error();
			return -1;
		}
	}
 /**
  *    Return combo list of differents status of a proposal
  *    Values are id of table c_propalst
  *
  *    @param	string	$selected   	Preselected value
  *    @param	int		$short			Use short labels
  *    @param	int		$excludedraft	0=All status, 1=Exclude draft status
  *    @param	int 	$showempty		1=Add empty line
  *    @param    string  $mode           'customer', 'supplier'
  *    @return	void
  */
 function selectProposalStatus($selected = '', $short = 0, $excludedraft = 0, $showempty = 1, $mode = 'customer')
 {
     global $langs;
     $prefix = '';
     $listofstatus = array();
     if ($mode == 'supplier') {
         $prefix = 'SupplierProposalStatus';
         $langs->load("supplier_proposal");
         $listofstatus = array(0 => array('code' => 'PR_DRAFT'), 1 => array('code' => 'PR_OPEN'), 2 => array('code' => 'PR_SIGNED'), 3 => array('code' => 'PR_NOTSIGNED'), 4 => array('code' => 'PR_CLOSED'));
     } else {
         $prefix = "PropalStatus";
         $sql = "SELECT id, code, label, active FROM " . MAIN_DB_PREFIX . "c_propalst";
         $sql .= " WHERE active = 1";
         dol_syslog(get_class($this) . "::selectProposalStatus", LOG_DEBUG);
         $resql = $this->db->query($sql);
         if ($resql) {
             $num = $this->db->num_rows($resql);
             $i = 0;
             if ($num) {
                 while ($i < $num) {
                     $obj = $this->db->fetch_object($resql);
                     $listofstatus[$obj->id] = array('id' => $obj->id, 'code' => $obj->code, 'label' => $obj->label);
                     $i++;
                 }
             }
         } else {
             dol_print_error($this->db);
         }
     }
     print '<select class="flat" name="propal_statut">';
     if ($showempty) {
         print '<option value="">&nbsp;</option>';
     }
     foreach ($listofstatus as $key => $obj) {
         if ($excludedraft) {
             if ($obj['code'] == 'Draft' || $obj['code'] == 'PR_DRAFT') {
                 $i++;
                 continue;
             }
         }
         if ($selected == $obj['id']) {
             print '<option value="' . $obj['id'] . '" selected>';
         } else {
             print '<option value="' . $obj['id'] . '">';
         }
         $key = $obj['code'];
         if ($langs->trans($prefix . "PropalStatus" . $key . ($short ? 'Short' : '')) != $prefix . "PropalStatus" . $key . ($short ? 'Short' : '')) {
             print $langs->trans($prefix . "PropalStatus" . $key . ($short ? 'Short' : ''));
         } else {
             $conv_to_new_code = array('PR_DRAFT' => 'Draft', 'PR_OPEN' => 'Opened', 'PR_CLOSED' => 'Closed', 'PR_SIGNED' => 'Signed', 'PR_NOTSIGNED' => 'NotSigned', 'PR_FAC' => 'Billed');
             if (!empty($conv_to_new_code[$obj['code']])) {
                 $key = $conv_to_new_code[$obj['code']];
             }
             print $langs->trans($prefix . $key . ($short ? 'Short' : '')) != $prefix . $key . ($short ? 'Short' : '') ? $langs->trans($prefix . $key . ($short ? 'Short' : '')) : $obj['label'];
         }
         print '</option>';
         $i++;
     }
     print '</select>';
 }
 /**
  *  Load indicators into this->nb for board
  *
  *  @return     int         <0 if KO, >0 if OK
  */
 function load_state_board()
 {
     global $conf, $user;
     $this->nb = array("customers" => 0, "prospects" => 0);
     $clause = "WHERE";
     $sql = "SELECT count(s.rowid) as nb, s.client";
     $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s";
     if (!$user->rights->societe->client->voir && !$user->societe_id) {
         $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON s.rowid = sc.fk_soc";
         $sql .= " WHERE sc.fk_user = "******"AND";
     }
     $sql .= " " . $clause . " s.client IN (1,2,3)";
     $sql .= ' AND s.entity IN (' . getEntity($this->element, 1) . ')';
     $sql .= " GROUP BY s.client";
     $resql = $this->db->query($sql);
     if ($resql) {
         while ($obj = $this->db->fetch_object($resql)) {
             if ($obj->client == 1 || $obj->client == 3) {
                 $this->nb["customers"] += $obj->nb;
             }
             if ($obj->client == 2 || $obj->client == 3) {
                 $this->nb["prospects"] += $obj->nb;
             }
         }
         $this->db->free($resql);
         return 1;
     } else {
         dol_print_error($this->db);
         $this->error = $this->db->error();
         return -1;
     }
 }
/**
 * \brief Crée un document PDF
 * \param db objet base de donnee
 * \param modele modele à utiliser
 * \param		outputlangs		objet lang a utiliser pour traduction
 * \return int <0 if KO, >0 if OK
 */
function immobilier_pdf_create($db, $id, $message, $typeModele, $outputlangs, $file)
{
    global $conf, $langs;
    $langs->load('immobilier@immobilier');
    // Charge le modele
    $nomModele = dol_buildpath('/immobilier/core/modules/immobilier/pdf/pdf_' . $typeModele . '.modules.php');
    if (file_exists($nomModele)) {
        require_once $nomModele;
        $classname = "pdf_" . $typeModele;
        $obj = new $classname($db);
        $obj->message = $message;
        // We save charset_output to restore it because write_file can change it if needed for
        // output format that does not support UTF8.
        $sav_charset_output = $outputlangs->charset_output;
        if ($obj->write_file($id, $outputlangs, $file, $socid, $courrier) > 0) {
            $outputlangs->charset_output = $sav_charset_output;
            return 1;
        } else {
            $outputlangs->charset_output = $sav_charset_output;
            dol_print_error($db, "pdf_create Error: " . $obj->error);
            return -1;
        }
    } else {
        dol_print_error('', $langs->trans("Error") . " " . $langs->trans("ErrorFileDoesNotExists", $file));
        return -1;
    }
}
Example #9
0
 /**
  *    Directs the bookmark
  *
  *    @param    int		$id		Bookmark Id Loader
  *    @return	int				<0 if KO, >0 if OK
  */
 function fetch($id)
 {
     global $conf;
     $sql = "SELECT rowid, fk_user, dateb as datec, url, target,";
     $sql .= " title, position, favicon";
     $sql .= " FROM " . MAIN_DB_PREFIX . "bookmark";
     $sql .= " WHERE rowid = " . $id;
     $sql .= " AND entity = " . $conf->entity;
     dol_syslog("Bookmark::fetch", LOG_DEBUG);
     $resql = $this->db->query($sql);
     if ($resql) {
         $obj = $this->db->fetch_object($resql);
         $this->id = $obj->rowid;
         $this->ref = $obj->rowid;
         $this->fk_user = $obj->fk_user;
         $this->datec = $this->db->jdate($obj->datec);
         $this->url = $obj->url;
         $this->target = $obj->target;
         $this->title = $obj->title;
         $this->position = $obj->position;
         $this->favicon = $obj->favicon;
         $this->db->free($resql);
         return $this->id;
     } else {
         dol_print_error($this->db);
         return -1;
     }
 }
function pt($db, $sql, $date)
{
    global $conf, $bc, $langs;
    $result = $db->query($sql);
    if ($result) {
        $num = $db->num_rows($result);
        $i = 0;
        $total = 0;
        print '<table class="noborder" width="100%">';
        print '<tr class="liste_titre">';
        print '<td class="nowrap" width="60%">' . $date . '</td>';
        print '<td align="right">' . $langs->trans("Amount") . '</td>';
        print '<td>&nbsp;</td>' . "\n";
        print "</tr>\n";
        $var = True;
        while ($i < $num) {
            $obj = $db->fetch_object($result);
            $var = !$var;
            print '<tr ' . $bc[$var] . '>';
            print '<td class="nowrap">' . $obj->dm . "</td>\n";
            $total = $total + $obj->mm;
            print '<td class="nowrap" align="right">' . price($obj->mm) . "</td><td >&nbsp;</td>\n";
            print "</tr>\n";
            $i++;
        }
        print '<tr class="liste_total"><td align="right">' . $langs->trans("Total") . " :</td><td nowrap=\"nowrap\" align=\"right\"><b>" . price($total) . "</b></td><td>&nbsp;</td></tr>";
        print "</table>";
        $db->free($result);
    } else {
        dol_print_error($db);
    }
}
Example #11
0
/**
 * Return server timezone int.
 *
 * @param	string	$refgmtdate		Reference period for timezone (timezone differs on winter and summer. May be 'now', 'winter' or 'summer')
 * @return 	int						An offset in hour (+1 for Europe/Paris on winter and +2 for Europe/Paris on summer)
 */
function getServerTimeZoneInt($refgmtdate = 'now')
{
    global $conf;
    if (method_exists('DateTimeZone', 'getOffset')) {
        // Method 1 (include daylight)
        $gmtnow = dol_now('gmt');
        $yearref = dol_print_date($gmtnow, '%Y');
        $monthref = dol_print_date($gmtnow, '%m');
        $dayref = dol_print_date($gmtnow, '%d');
        if ($refgmtdate == 'now') {
            $newrefgmtdate = $yearref . '-' . $monthref . '-' . $dayref;
        } elseif ($refgmtdate == 'summer') {
            $newrefgmtdate = $yearref . '-08-01';
        } else {
            $newrefgmtdate = $yearref . '-01-01';
        }
        $localtz = new DateTimeZone(getServerTimeZoneString());
        $localdt = new DateTime($newrefgmtdate, $localtz);
        $tmp = -1 * $localtz->getOffset($localdt);
        //print $refgmtdate.'='.$tmp;
    } else {
        dol_print_error('', 'PHP version must be 5.3+');
        /*
        // Method 2 (does not include daylight, not supported by adodb)
        if ($refgmtdate == 'now')
        {
            if (ini_get("date.timezone")=='UTC') return 0;
            // We don't know server timezone string, so we don't know location, so we can't guess daylight. We assume we use same than client but this may be a bug.
            $gmtnow=dol_now('gmt'); $yearref=dol_print_date($gmtnow,'%Y'); $monthref=dol_print_date($gmtnow,'%m'); $dayref=dol_print_date($gmtnow,'%d');
            if (dol_stringtotime($_SESSION['dol_dst_first']) <= $gmtnow && $gmtnow < dol_stringtotime($_SESSION['dol_dst_second'])) $daylight=1;
            else $daylight=0;
            $tmp=dol_mktime(0,0,0,$monthref,$dayref,$yearref,false,0)-dol_mktime(0,0,0,$monthref,$dayref,$yearref,true,0)-($daylight*3600);
            return 'unknown';    // For true result
        }
        elseif ($refgmtdate == 'summer')
        {
            if (ini_get("date.timezone")=='UTC') return 0;
            // We don't know server timezone string, so we don't know location, so we can't guess daylight. We assume we use same than client but this may be a bug.
            $gmtnow=dol_now('gmt'); $yearref=dol_print_date($gmtnow,'%Y'); $monthref='08'; $dayref='01';
            if (dol_stringtotime($_SESSION['dol_dst_first']) <= dol_stringtotime($yearref.'-'.$monthref.'-'.$dayref) && dol_stringtotime($yearref.'-'.$monthref.'-'.$dayref) < dol_stringtotime($_SESSION['dol_dst_second'])) $daylight=1;
            else $daylight=0;
            $tmp=dol_mktime(0,0,0,$monthref,$dayref,$yearref,false,0)-dol_mktime(0,0,0,$monthref,$dayref,$yearref,true,0)-($daylight*3600);
            return 'unknown';    // For true result
        }
        else $tmp=dol_mktime(0,0,0,1,1,1970);
        */
    }
    $tz = round(($tmp < 0 ? 1 : -1) * abs($tmp / 3600));
    return $tz;
}
Example #12
0
 /**
  * 	Constructor
  *
  * 	@param 		DoliDB		$db		Database handler
  */
 function __construct($db)
 {
     parent::__construct($db);
     try {
         $this->couchdb->useDatabase('adherent');
         $fk_extrafields = new ExtraFields($db);
         $fk_extrafields->useDatabase('adherent');
         $this->fk_extrafields = $fk_extrafields->load("extrafields:" . get_class($this), true);
         // load and cache
     } catch (Exception $e) {
         dol_print_error('', $e->getMessage());
         exit;
     }
     return 1;
 }
/**
 * Add area with bookmarks in menu
 *
 * @param 	DoliDb  	$aDb		Database handler
 * @param 	Translate	$aLangs		Object lang
 * @return	string
 */
function printBookmarksList($aDb, $aLangs)
{
    global $conf, $user;
    $db = $aDb;
    $langs = $aLangs;
    require_once DOL_DOCUMENT_ROOT . '/bookmarks/class/bookmark.class.php';
    if (!isset($conf->global->BOOKMARKS_SHOW_IN_MENU)) {
        $conf->global->BOOKMARKS_SHOW_IN_MENU = 5;
    }
    $bookm = new Bookmark($db);
    $langs->load("bookmarks");
    $url = $_SERVER["PHP_SELF"] . (!empty($_SERVER["QUERY_STRING"]) ? '?' . $_SERVER["QUERY_STRING"] : '');
    $ret = '';
    // Menu bookmark
    $ret .= '<div class="menu_titre">';
    $ret .= '<table class="nobordernopadding" width="100%" summary="bookmarkstable"><tr><td>';
    $ret .= '<a class="vmenu" href="' . DOL_URL_ROOT . '/bookmarks/liste.php">' . $langs->trans('Bookmarks') . '</a>';
    $ret .= '</td><td align="right">';
    if ($user->rights->bookmark->creer) {
        $ret .= '<a class="vsmenu" href="' . DOL_URL_ROOT . '/bookmarks/fiche.php?action=create&amp;urlsource=' . urlencode($url) . '&amp;url=' . urlencode($url) . '">';
        //$ret.=img_picto($langs->trans('AddThisPageToBookmarks'),'edit_add').' ';
        $ret .= img_object($langs->trans('AddThisPageToBookmarks'), 'bookmark');
        $ret .= '</a>';
    }
    $ret .= '</td></tr></table>';
    $ret .= '</div>';
    $ret .= '<div class="menu_top"></div>' . "\n";
    // Menu with all bookmarks
    if (!empty($conf->global->BOOKMARKS_SHOW_IN_MENU)) {
        $sql = "SELECT rowid, title, url, target FROM " . MAIN_DB_PREFIX . "bookmark";
        $sql .= " WHERE (fk_user = "******" OR fk_user is NULL OR fk_user = 0)";
        $sql .= " AND entity = " . $conf->entity;
        $sql .= " ORDER BY position";
        if ($resql = $db->query($sql)) {
            $i = 0;
            while ($i < $conf->global->BOOKMARKS_SHOW_IN_MENU && ($obj = $db->fetch_object($resql))) {
                $ret .= '<div class="menu_contenu"><a class="vsmenu" title="' . $obj->title . '" href="' . $obj->url . '"' . ($obj->target == 1 ? ' target="_blank"' : '') . '>';
                $ret .= ' ' . img_object('', 'bookmark') . ' ';
                $ret .= dol_trunc($obj->title, 20) . '</a><br></div>';
                $i++;
            }
        } else {
            dol_print_error($db);
        }
    }
    $ret .= '<div class="menu_end"></div>';
    return $ret;
}
 /**
  *      Return next reference of ticket not already used (or last reference)
  *      according to numbering module defined into constant FACSIM_ADDON
  *      @param	   soc  		           objet company
  *      @param     mode                    'next' for next value or 'last' for last value
  *      @return    string                  free ref or last ref
  */
 function getNextNumRef($soc, $mode = 'next')
 {
     global $conf, $db, $langs;
     $langs->load("bills");
     // Clean parameters (if not defined or using deprecated value)
     if (empty($conf->global->FACSIM_ADDON)) {
         $conf->global->FACSIM_ADDON = 'mod_facsim_alcoy';
     } else {
         if ($conf->global->FACSIM_ADDON == 'alcoy') {
             $conf->global->FACSIM_ADDON = 'mod_facsim_alcoy';
         }
     }
     $mybool = false;
     $file = $conf->global->FACSIM_ADDON . ".php";
     $classname = $conf->global->FACSIM_ADDON;
     // Include file with class
     foreach ($conf->file->dol_document_root as $dirroot) {
         $dir = $dirroot . "/pos/backend/numerotation/numerotation_facsim/";
         // Load file with numbering class (if found)
         $mybool |= @(include_once $dir . $file);
     }
     // For compatibility
     if (!$mybool) {
         $file = $conf->global->FACSIM_ADDON . "/" . $conf->global->FACSIM_ADDON . ".modules.php";
         $classname = "mod_facsim_" . $conf->global->FACSIM_ADDON;
         // Include file with class
         foreach ($conf->file->dol_document_root as $dirroot) {
             $dir = $dirroot . "/pos/backend/numerotation/numerotation_facsim/";
             // Load file with numbering class (if found)
             $mybool |= @(include_once $dir . $file);
         }
     }
     //print "xx".$mybool.$dir.$file."-".$classname;
     if (!$mybool) {
         dol_print_error('', "Failed to include file " . $file);
         return '';
     }
     $obj = new $classname();
     $numref = "";
     $numref = $obj->getNumRef($soc, $this, $mode);
     if ($numref != "") {
         return $numref;
     } else {
         //dol_print_error($db,"Ticket::getNextNumRef ".$obj->error);
         return false;
     }
 }
Example #15
0
/**
 * Replace the default llxHeader function
 * @param $head
 * @param $title
 * @param $help_url
 * @param $target
 * @param $disablejs
 * @param $disablehead
 * @param $arrayofjs
 * @param $arrayofcss
 */
function llxHeader($head = '', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='')
{
	global $db, $user, $conf, $langs;

	top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);	// Show html headers
	top_menu($head, $title, $target, $disablejs, $disablehead, $arrayofjs, $arrayofcss);	// Show html headers

	$menu = new Menu();

	// Entry for each bank account
	if ($user->rights->banque->lire)
	{
		$sql = "SELECT rowid, label, courant, rappro, courant";
		$sql.= " FROM ".MAIN_DB_PREFIX."bank_account";
		$sql.= " WHERE entity = ".$conf->entity;
		$sql.= " AND clos = 0";
        $sql.= " ORDER BY label";

		$resql = $db->query($sql);
		if ($resql)
		{
			$numr = $db->num_rows($resql);
			$i = 0;

			if ($numr > 0) 	$menu->add('/compta/bank/index.php',$langs->trans("BankAccounts"),0,$user->rights->banque->lire);

			while ($i < $numr)
			{
				$objp = $db->fetch_object($resql);
				$menu->add('/compta/bank/fiche.php?id='.$objp->rowid,$objp->label,1,$user->rights->banque->lire);
                if ($objp->rappro && $objp->courant != 2 && ! $objp->clos)  // If not cash account and not closed and can be reconciliate
                {
				    $menu->add('/compta/bank/rappro.php?account='.$objp->rowid,$langs->trans("Conciliate"),2,$user->rights->banque->consolidate);
                }
				$i++;
			}
		}
		else dol_print_error($db);
		$db->free($resql);
	}

	left_menu('', $help_url, '', $menu->liste, 1);
    main_area();
}
Example #16
0
function pt ($db, $sql, $title) {
  global $bc;
  global $langs,$conf;

  print '<table class="border" width="100%">';
  print '<tr class="liste_titre">';
  print "<td>$title</td>";
  print "<td align=\"right\">Montant</td>";
  print "</tr>\n";

  $result = $db->query($sql);
  if ($result)
    {
      $num = $db->num_rows($result);
      $i = 0; $total = 0 ;

      $var=True;
      while ($i < $num)
	{
	  $obj = $db->fetch_object($result);
	  $var=!$var;
	  print '<tr '.$bc[$var].'>';
	  print '<td>'.$obj->dm.'</td>';
	  print '<td align="right">'.price($obj->amount).'</td>';

	  print "</tr>\n";
	  $total = $total + $obj->amount;
	  $i++;
	}
      print "<tr class=\"total\"><td colspan=\"2\" align=\"right\"><b>".$langs->trans("TotalHT").": ".price($total)."</b> ".$langs->trans("Currency".$conf->monnaie)."</td></tr>";

      $db->free();
    }
  else
    {
      dol_print_error($db);

    }
  print "</table>";

}
Example #17
0
 /**
  *	Renvoie tableau des ids de facture avoir issus de la facture
  *
  *	@return		array		Tableau d'id de factures avoirs
  */
 function getListIdAvoirFromInvoice()
 {
     $idarray = array();
     $sql = 'SELECT rowid';
     $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element;
     $sql .= ' WHERE fk_facture_source = ' . $this->id;
     $sql .= ' AND type = 2';
     $resql = $this->db->query($sql);
     if ($resql) {
         $num = $this->db->num_rows($resql);
         $i = 0;
         while ($i < $num) {
             $row = $this->db->fetch_row($resql);
             $idarray[] = $row[0];
             $i++;
         }
     } else {
         dol_print_error($this->db);
     }
     return $idarray;
 }
 /**
  *    Return combo list of differents status of a proposal
  *    Values are id of table c_propalst
  *
  *    @param	string	$selected   Preselected value
  *    @param	int		$short		Use short labels
  *    @return	void
  */
 function selectAskPriceSupplierStatus($selected = '', $short = 0)
 {
     global $langs;
     $sql = "SELECT id, code, label, active FROM " . MAIN_DB_PREFIX . "c_propalst";
     $sql .= " WHERE active = 1";
     dol_syslog(get_class($this) . "::selectAskPriceSupplierStatus", LOG_DEBUG);
     $resql = $this->db->query($sql);
     if ($resql) {
         print '<select class="flat" name="askpricesupplier_statut">';
         print '<option value="">&nbsp;</option>';
         $num = $this->db->num_rows($resql);
         $i = 0;
         if ($num) {
             while ($i < $num) {
                 $obj = $this->db->fetch_object($resql);
                 if ($selected == $obj->id) {
                     print '<option value="' . $obj->id . '" selected>';
                 } else {
                     print '<option value="' . $obj->id . '">';
                 }
                 $key = $obj->code;
                 if ($langs->trans("PropalStatus" . $key . ($short ? 'Short' : '')) != "PropalStatus" . $key . ($short ? 'Short' : '')) {
                     print $langs->trans("PropalStatus" . $key . ($short ? 'Short' : ''));
                 } else {
                     $conv_to_new_code = array('PR_DRAFT' => 'Draft', 'PR_OPEN' => 'Opened', 'PR_CLOSED' => 'Closed', 'PR_SIGNED' => 'Signed', 'PR_NOTSIGNED' => 'NotSigned', 'PR_FAC' => 'Billed');
                     if (!empty($conv_to_new_code[$obj->code])) {
                         $key = $conv_to_new_code[$obj->code];
                     }
                     print $langs->trans("PropalStatus" . $key . ($short ? 'Short' : '')) != "PropalStatus" . $key . ($short ? 'Short' : '') ? $langs->trans("PropalStatus" . $key . ($short ? 'Short' : '')) : $obj->label;
                 }
                 print '</option>';
                 $i++;
             }
         }
         print '</select>';
     } else {
         dol_print_error($this->db);
     }
 }
 /**
  * Load in cache array list of warehouses
  * If fk_product is not 0, we do not use cache
  *
  * @param	int		$fk_product		Add quantity of stock in label for product with id fk_product. Nothing if 0.
  * @return  int  		    		Nb of loaded lines, 0 if already loaded, <0 if KO
  */
 function loadWarehouses($fk_product = 0)
 {
     global $conf, $langs;
     if (empty($fk_product) && count($this->cache_warehouses)) {
         return 0;
     }
     // Cache already loaded and we do not want a list with information specific to a product
     $sql = "SELECT e.rowid, e.label";
     if ($fk_product) {
         $sql .= ", ps.reel";
     }
     $sql .= " FROM " . MAIN_DB_PREFIX . "entrepot as e";
     if ($fk_product) {
         $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_stock as ps on ps.fk_entrepot = e.rowid";
         $sql .= " AND ps.fk_product = '" . $fk_product . "'";
     }
     $sql .= " WHERE e.entity IN (" . getEntity('stock', 1) . ")";
     $sql .= " AND e.statut = 1";
     $sql .= " ORDER BY e.label";
     dol_syslog(get_class($this) . '::loadWarehouses', LOG_DEBUG);
     $resql = $this->db->query($sql);
     if ($resql) {
         $num = $this->db->num_rows($resql);
         $i = 0;
         while ($i < $num) {
             $obj = $this->db->fetch_object($resql);
             $this->cache_warehouses[$obj->rowid]['id'] = $obj->rowid;
             $this->cache_warehouses[$obj->rowid]['label'] = $obj->label;
             if ($fk_product) {
                 $this->cache_warehouses[$obj->rowid]['stock'] = $obj->reel;
             }
             $i++;
         }
         return $num;
     } else {
         dol_print_error($this->db);
         return -1;
     }
 }
Example #20
0
/**
 *	    \file       htdocs/lib/bookmark.lib.php
 *		\brief      List of functions for bookmark module
 *		\version    $Id: bookmark.lib.php,v 1.6 2011/07/31 23:25:41 eldy Exp $
 *
 *		Ensemble de fonctions de base de dolibarr sous forme d'include
 */

function showArrayOfBookmark($fac)
{
	$sql = "SELECT s.rowid as socid, s.nom, b.rowid as bid";
	$sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."bookmark as b";
	$sql .= " WHERE b.fk_soc = s.rowid AND b.fk_user = "******" ORDER BY lower(s.nom) ASC";

	$resql = $db->query($sql);

	if ( $resql )
	{
	  $num = $db->num_rows($resql);
	  $i = 0;
	  if ($num)
	    {
	      print '<table class="noborder" width="100%">';
	      print "<tr class=\"liste_titre\"><td colspan=\"2\">".$langs->trans("Bookmarks")."</td></tr>\n";
	      $var = True;
	      while ($i < $num)
		{
		  $obj = $db->fetch_object($resql);
		  $var = !$var;
		  print "<tr $bc[$var]>";
		  print '<td><a href="fiche.php?socid='.$obj->socid.'">'.$obj->nom.'</a></td>';
		  print '<td align="right"><a href="index.php?action=del_bookmark&amp;bid='.$obj->bid.'">'.img_delete().'</a></td>';
		  print '</tr>';
		  $i++;
		}
	      print '</table>';
	    }
	  $db->free($resql);
	}
	else
	{
	  dol_print_error($db);
	}
}
Example #21
0
        // Status
        print '<tr><td valign="top">' . $langs->trans("Status") . '</td>';
        print '<td colspan="3">' . $object->getLibStatut(4) . '</td></tr>';
        print '<tr><td>' . $langs->trans("NbOfAttachedFiles") . '</td><td colspan="3">' . count($filearray) . '</td></tr>';
        print '<tr><td>' . $langs->trans("TotalSizeOfAttachedFiles") . '</td><td colspan="3">' . $totalsize . ' ' . $langs->trans("bytes") . '</td></tr>';
        print "</table>\n";
        print "</div>\n";
        dol_htmloutput_mesg($mesg, $mesgs);
        /*
         * Confirmation suppression fichier
         */
        if ($action == 'delete') {
            $ret = $form->form_confirm($_SERVER["PHP_SELF"] . '?id=' . $object->id . '&urlfile=' . urlencode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
            if ($ret == 'html') {
                print '<br>';
            }
        }
        // Affiche formulaire upload
        $formfile = new FormFile($db);
        $formfile->form_attach_new_file(DOL_URL_ROOT . '/compta/bank/document.php?id=' . $object->id, '', 0, 0, $user->rights->banque, 50, $object);
        // List of document
        $param = '&id=' . $object->id;
        $formfile->list_of_documents($filearray, $object, 'bank', $param);
    } else {
        dol_print_error($db);
    }
} else {
    Header('Location: index.php');
}
llxFooter();
$db->close();
Example #22
0
 /**
  * 	Load array this->attribute_xxx like attribute_label, attribute_type, ...
  *
  * 	@param	string		$elementtype		Type of element ('adherent', 'commande', 'thirdparty', 'facture', 'propal', 'product', ...)
  * 	@param	boolean		$forceload			Force load of extra fields whatever is option MAIN_EXTRAFIELDS_DISABLED
  * 	@return	array							Array of attributes for all extra fields
  */
 function fetch_name_optionals_label($elementtype, $forceload = false)
 {
     global $conf;
     if (empty($elementtype)) {
         return array();
     }
     if ($elementtype == 'thirdparty') {
         $elementtype = 'societe';
     }
     if ($elementtype == 'contact') {
         $elementtype = 'socpeople';
     }
     $array_name_label = array();
     // For avoid conflicts with external modules
     if (!$forceload && !empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) {
         return $array_name_label;
     }
     $sql = "SELECT rowid,name,label,type,size,elementtype,fieldunique,fieldrequired,param,pos,alwayseditable,perms,list";
     $sql .= " FROM " . MAIN_DB_PREFIX . "extrafields";
     $sql .= " WHERE entity IN (0," . $conf->entity . ")";
     if ($elementtype) {
         $sql .= " AND elementtype = '" . $elementtype . "'";
     }
     $sql .= " ORDER BY pos";
     dol_syslog(get_class($this) . "::fetch_name_optionals_label", LOG_DEBUG);
     $resql = $this->db->query($sql);
     if ($resql) {
         if ($this->db->num_rows($resql)) {
             while ($tab = $this->db->fetch_object($resql)) {
                 // we can add this attribute to adherent object
                 if ($tab->type != 'separate') {
                     $array_name_label[$tab->name] = $tab->label;
                 }
                 $this->attribute_type[$tab->name] = $tab->type;
                 $this->attribute_label[$tab->name] = $tab->label;
                 $this->attribute_size[$tab->name] = $tab->size;
                 $this->attribute_elementtype[$tab->name] = $tab->elementtype;
                 $this->attribute_unique[$tab->name] = $tab->fieldunique;
                 $this->attribute_required[$tab->name] = $tab->fieldrequired;
                 $this->attribute_param[$tab->name] = $tab->param ? unserialize($tab->param) : '';
                 $this->attribute_pos[$tab->name] = $tab->pos;
                 $this->attribute_alwayseditable[$tab->name] = $tab->alwayseditable;
                 $this->attribute_perms[$tab->name] = $tab->perms;
                 $this->attribute_list[$tab->name] = $tab->list;
             }
         }
     } else {
         print dol_print_error($this->db);
     }
     return $array_name_label;
 }
Example #23
0
print "<td>Ref</td>";
print "<td>Titre</td>";
print "<td>Groupe</td>";
print '<td align="center">Stock</td>';
print '<td align="center">Status</td>';
print '</tr>' . "\n";
$resql = $dbosc->query($sql);
if ($resql) {
    $num = $dbosc->num_rows($resql);
    $i = 0;
    $var = True;
    while ($i < $num) {
        $objp = $dbosc->fetch_object($resql);
        $var = !$var;
        print "<TR {$bc[$var]}>";
        print "<TD>{$objp->products_id}</TD>\n";
        print "<TD>{$objp->products_model}</TD>\n";
        print "<TD>{$objp->products_name}</TD>\n";
        print "<TD>{$objp->manufacturers_name}</TD>\n";
        print '<TD align="center">' . $objp->products_quantity . "</TD>\n";
        print '<TD align="center">' . $objp->products_status . "</TD>\n";
        print "</TR>\n";
        $i++;
    }
    $dbosc->free();
} else {
    dol_print_error($dbosc);
}
print "</TABLE>";
$dbosc->close();
llxFooter();
 /**
  * Adds access rights
  *
  * @param   int $reinitadminperms   If 1, we also grant them to all admin users
  * @param   int $force_entity       Force current entity
  *
  * @return  int                     Error count (0 if OK)
  */
 function insert_permissions($reinitadminperms = 0, $force_entity = null)
 {
     global $conf, $user;
     $err = 0;
     $entity = !empty($force_entity) ? $force_entity : $conf->entity;
     // Test if module is activated
     $sql_del = "SELECT " . $this->db->decrypt('value') . " as value";
     $sql_del .= " FROM " . MAIN_DB_PREFIX . "const";
     $sql_del .= " WHERE " . $this->db->decrypt('name') . " = '" . $this->const_name . "'";
     $sql_del .= " AND entity IN (0," . $entity . ")";
     dol_syslog(get_class($this) . "::insert_permissions", LOG_DEBUG);
     $resql = $this->db->query($sql_del);
     if ($resql) {
         $obj = $this->db->fetch_object($resql);
         if ($obj !== null && !empty($obj->value) && !empty($this->rights)) {
             // If the module is active
             foreach ($this->rights as $key => $value) {
                 $r_id = $this->rights[$key][0];
                 $r_desc = $this->rights[$key][1];
                 $r_type = isset($this->rights[$key][2]) ? $this->rights[$key][2] : '';
                 $r_def = $this->rights[$key][3];
                 $r_perms = $this->rights[$key][4];
                 $r_subperms = isset($this->rights[$key][5]) ? $this->rights[$key][5] : '';
                 $r_modul = $this->rights_class;
                 if (empty($r_type)) {
                     $r_type = 'w';
                 }
                 // Search if perm already present
                 $sql = "SELECT count(*) as nb FROM " . MAIN_DB_PREFIX . "rights_def";
                 $sql .= " WHERE id = " . $r_id . " AND entity = " . $entity;
                 $resqlselect = $this->db->query($sql);
                 $obj = $this->db->fetch_object($resqlselect);
                 if ($obj->nb == 0) {
                     if (dol_strlen($r_perms)) {
                         if (dol_strlen($r_subperms)) {
                             $sql = "INSERT INTO " . MAIN_DB_PREFIX . "rights_def";
                             $sql .= " (id, entity, libelle, module, type, bydefault, perms, subperms)";
                             $sql .= " VALUES ";
                             $sql .= "(" . $r_id . "," . $entity . ",'" . $this->db->escape($r_desc) . "','" . $r_modul . "','" . $r_type . "'," . $r_def . ",'" . $r_perms . "','" . $r_subperms . "')";
                         } else {
                             $sql = "INSERT INTO " . MAIN_DB_PREFIX . "rights_def";
                             $sql .= " (id, entity, libelle, module, type, bydefault, perms)";
                             $sql .= " VALUES ";
                             $sql .= "(" . $r_id . "," . $entity . ",'" . $this->db->escape($r_desc) . "','" . $r_modul . "','" . $r_type . "'," . $r_def . ",'" . $r_perms . "')";
                         }
                     } else {
                         $sql = "INSERT INTO " . MAIN_DB_PREFIX . "rights_def ";
                         $sql .= " (id, entity, libelle, module, type, bydefault)";
                         $sql .= " VALUES ";
                         $sql .= "(" . $r_id . "," . $entity . ",'" . $this->db->escape($r_desc) . "','" . $r_modul . "','" . $r_type . "'," . $r_def . ")";
                     }
                     $resqlinsert = $this->db->query($sql, 1);
                     if (!$resqlinsert) {
                         if ($this->db->errno() != "DB_ERROR_RECORD_ALREADY_EXISTS") {
                             $this->error = $this->db->lasterror();
                             $err++;
                             break;
                         } else {
                             dol_syslog(get_class($this) . "::insert_permissions record already exists", LOG_INFO);
                         }
                     }
                     $this->db->free($resqlinsert);
                 }
                 $this->db->free($resqlselect);
                 // If we want to init permissions on admin users
                 if ($reinitadminperms) {
                     if (!class_exists('User')) {
                         require DOL_DOCUMENT_ROOT . '/user/class/user.class.php';
                     }
                     $sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "user WHERE admin = 1";
                     dol_syslog(get_class($this) . "::insert_permissions Search all admin users", LOG_DEBUG);
                     $resqlseladmin = $this->db->query($sql, 1);
                     if ($resqlseladmin) {
                         $num = $this->db->num_rows($resqlseladmin);
                         $i = 0;
                         while ($i < $num) {
                             $obj2 = $this->db->fetch_object($resqlseladmin);
                             dol_syslog(get_class($this) . "::insert_permissions Add permission to user id=" . $obj2->rowid);
                             $tmpuser = new User($this->db);
                             $tmpuser->fetch($obj2->rowid);
                             if (!empty($tmpuser->id)) {
                                 $tmpuser->addrights($r_id);
                             }
                             $i++;
                         }
                         if (!empty($user->admin)) {
                             // We reload permissions
                             $user->clearrights();
                             $user->getrights();
                         }
                     } else {
                         dol_print_error($this->db);
                     }
                 }
             }
         }
         $this->db->free($resql);
     } else {
         $this->error = $this->db->lasterror();
         $err++;
     }
     return $err;
 }
Example #25
0
 /**
  *    	\brief      Check if notification are active for couple action/company.
  * 					If yes, send mail and save trace into llx_notify.
  * 		\param		action		Code of action in llx_c_action_trigger (new usage) or Id of action in llx_c_action_trigger (old usage)
  * 		\param		socid		Id of third party
  * 		\param		texte		Message to send
  * 		\param		objet_type	Type of object the notification deals on (facture, order, propal, order_supplier...). Just for log in llx_notify.
  * 		\param		objet_id	Id of object the notification deals on
  * 		\param		file		Attach a file
  *		\return		int			<0 if KO, or number of changes if OK
  */
 function send($action, $socid, $texte, $objet_type, $objet_id, $file = "")
 {
     global $conf, $langs, $mysoc, $dolibarr_main_url_root;
     $langs->load("other");
     dol_syslog("Notify::send action={$action}, socid={$socid}, texte={$texte}, objet_type={$objet_type}, objet_id={$objet_id}, file={$file}");
     $sql = "SELECT s.nom, c.email, c.rowid as cid, c.name, c.firstname,";
     $sql .= " a.rowid as adid, a.label, a.code, n.rowid";
     $sql .= " FROM " . MAIN_DB_PREFIX . "socpeople as c,";
     $sql .= " " . MAIN_DB_PREFIX . "c_action_trigger as a,";
     $sql .= " " . MAIN_DB_PREFIX . "notify_def as n,";
     $sql .= " " . MAIN_DB_PREFIX . "societe as s";
     $sql .= " WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action";
     $sql .= " AND n.fk_soc = s.rowid";
     if (is_numeric($action)) {
         $sql .= " AND n.fk_action = " . $action;
     } else {
         $sql .= " AND a.code = '" . $action . "'";
     }
     // New usage
     $sql .= " AND s.rowid = " . $socid;
     dol_syslog("Notify::send sql=" . $sql);
     $result = $this->db->query($sql);
     if ($result) {
         $num = $this->db->num_rows($result);
         $i = 0;
         while ($i < $num) {
             $obj = $this->db->fetch_object($result);
             $sendto = $obj->firstname . " " . $obj->name . " <" . $obj->email . ">";
             $actiondefid = $obj->adid;
             if (dol_strlen($sendto)) {
                 include_once DOL_DOCUMENT_ROOT . '/lib/files.lib.php';
                 $application = $conf->global->MAIN_APPLICATION_TITLE ? $conf->global->MAIN_APPLICATION_TITLE : 'Dolibarr ERP/CRM';
                 $subject = '[' . $application . '] ' . $langs->transnoentitiesnoconv("DolibarrNotification");
                 $message = $langs->transnoentities("YouReceiveMailBecauseOfNotification", $application, $mysoc->name) . "\n";
                 $message .= $langs->transnoentities("YouReceiveMailBecauseOfNotification2", $application, $mysoc->name) . "\n";
                 $message .= "\n";
                 $message .= $texte;
                 // Add link
                 switch ($objet_type) {
                     case 'ficheinter':
                         $link = DOL_URL_ROOT . '/fichinter/fiche.php?id=' . $objet_id;
                         break;
                     case 'propal':
                         $link = DOL_URL_ROOT . '/comm/propal.php?id=' . $objet_id;
                         break;
                     case 'facture':
                         $link = DOL_URL_ROOT . '/compta/facture.php?facid=' . $objet_id;
                         break;
                     case 'order':
                         $link = DOL_URL_ROOT . '/commande/fiche.php?facid=' . $objet_id;
                         break;
                     case 'order_supplier':
                         $link = DOL_URL_ROOT . '/fourn/commande/fiche.php?facid=' . $objet_id;
                         break;
                 }
                 $urlwithouturlroot = preg_replace('/' . preg_quote(DOL_URL_ROOT, '/') . '$/i', '', $dolibarr_main_url_root);
                 if ($link) {
                     $message .= "\n" . $urlwithouturlroot . $link;
                 }
                 $filename = basename($file);
                 $mimefile = dol_mimetype($file);
                 $msgishtml = 0;
                 $replyto = $conf->notification->email_from;
                 $mailfile = new CMailFile($subject, $sendto, $replyto, $message, array($file), array($mimefile), array($filename[sizeof($filename) - 1]), '', '', 0, $msgishtml);
                 if ($mailfile->sendfile()) {
                     $sendto = htmlentities($sendto);
                     $sql = "INSERT INTO " . MAIN_DB_PREFIX . "notify (daten, fk_action, fk_contact, objet_type, objet_id, email)";
                     $sql .= " VALUES (" . $this->db->idate(mktime()) . ", " . $actiondefid . " ," . $obj->cid . " , '" . $objet_type . "', " . $objet_id . ", '" . $this->db->escape($obj->email) . "')";
                     dol_syslog("Notify::send sql=" . $sql);
                     if (!$this->db->query($sql)) {
                         dol_print_error($this->db);
                     }
                 } else {
                     $this->error = $mailfile->error;
                     //dol_syslog("Notify::send ".$this->error, LOG_ERR);
                 }
             }
             $i++;
         }
         return $i;
     } else {
         $this->error = $this->db->error();
         return -1;
     }
 }
Example #26
0
        exit;
    } else {
        //TODO: Translate
        setEventMessage('Error ' . $langs->trans($ecmdir->error), 'errors');
        $action = "create";
    }
    clearstatcache();
}
// Remove file
if ($action == 'confirm_deletefile') {
    if (GETPOST('confirm') == 'yes') {
        $langs->load("other");
        if ($section) {
            $result = $ecmdir->fetch($section);
            if (!($result > 0)) {
                dol_print_error($db, $ecmdir->error);
                exit;
            }
            $relativepath = $ecmdir->getRelativePath();
        } else {
            $relativepath = '';
        }
        $upload_dir = $conf->ecm->dir_output . ($relativepath ? '/' . $relativepath : '');
        $file = $upload_dir . "/" . GETPOST('urlfile');
        // Do not use urldecode here ($_GET and $_POST are already decoded by PHP).
        $ret = dol_delete_file($file);
        if ($ret) {
            setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
        } else {
            setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
        }
Example #27
0
        $dir = $conf->product->multidir_output[$object->entity];
        // By default
        if ($object->type == Product::TYPE_PRODUCT) {
            $dir = $conf->product->multidir_output[$object->entity];
        }
        if ($object->type == Product::TYPE_SERVICE) {
            $dir = $conf->service->multidir_output[$object->entity];
        }
    }
} elseif ($modulepart == 'holiday') {
    require_once DOL_DOCUMENT_ROOT . '/holiday/class/holiday.class.php';
    $object = new Holiday($db);
    if ($id > 0) {
        $result = $object->fetch($id);
        if ($result <= 0) {
            dol_print_error($db, 'Failed to load object');
        }
        $dir = $conf->holiday->dir_output;
        // By default
    }
}
/*
 * Actions
 */
if ($cancel) {
    if ($backtourl) {
        header("Location: " . $backtourl);
        exit;
    } else {
        header("Location: " . DOL_URL_ROOT . "/product/document.php?id=" . $id . '&file=' . urldecode($_POST["file"]));
        exit;
Example #28
0
    /**
     * Build a graph onto disk using JFlot library. Input when calling this method should be:
     *	$this->data  = array(array(      0=>'labelxA',     1=>yA),  array('labelxB',yB)); or
     *  $this->data  = array(array('label'=>'labelxA','data'=>yA),  array('labelxB',yB));			// TODO Syntax not supported. Removed when dol_print_graph_removed
     *	$this->data  = array(array(0=>'labelxA',1=>yA1,...,n=>yAn), array('labelxB',yB1,...yBn));   // when there is n series to show for each x
     *  $this->legend= array("Val1",...,"Valn");													// list of n series name
     *  $this->type  = array('bars',...'lines'); or array('pie')
     *  $this->mode = 'depth' ???
     *  $this->bgcolorgrid
     *  $this->datacolor
     *
     * @param	string	$file    	Image file name to use to save onto disk (also used as javascript unique id)
     * @param	string	$fileurl	Url path to show image if saved onto disk
     * @return	void
     */
    private function draw_jflot($file, $fileurl)
    {
        global $artichow_defaultfont;
        dol_syslog(get_class($this) . "::draw_jflot this->type=" . join(',', $this->type));
        if (empty($this->width) && empty($this->height)) {
            print 'Error width or height not set';
            return;
        }
        $legends = array();
        $nblot = count($this->data[0]) - 1;
        // -1 to remove legend
        if ($nblot < 0) {
            dol_print_error('Bad value for property ->data. Must be set by mydolgraph->SetData before callinf mydolgrapgh->draw');
        }
        $firstlot = 0;
        // Works with line but not with bars
        //if ($nblot > 2) $firstlot = ($nblot - 2);        // We limit nblot to 2 because jflot can't manage more than 2 bars on same x
        $i = $firstlot;
        $serie = array();
        while ($i < $nblot) {
            $values = array();
            // Array with horizontal y values (specific values of a serie) for each abscisse x
            $serie[$i] = "var d" . $i . " = [];\n";
            // Fill array $values
            $x = 0;
            foreach ($this->data as $valarray) {
                $legends[$x] = $valarray[0];
                $values[$x] = is_numeric($valarray[$i + 1]) ? $valarray[$i + 1] : null;
                $x++;
            }
            // TODO Avoid push by adding generated long array...
            if (isset($this->type[$firstlot]) && $this->type[$firstlot] == 'pie') {
                foreach ($values as $x => $y) {
                    if (isset($y)) {
                        $serie[$i] .= 'd' . $i . '.push({"label":"' . dol_escape_js($legends[$x]) . '", "data":' . $y . '});' . "\n";
                    }
                }
            } else {
                foreach ($values as $x => $y) {
                    if (isset($y)) {
                        $serie[$i] .= 'd' . $i . '.push([' . $x . ', ' . $y . ']);' . "\n";
                    }
                }
            }
            unset($values);
            $i++;
        }
        $tag = dol_escape_htmltag(dol_string_unaccent(dol_string_nospecial(basename($file), '_', array('-', '.'))));
        $this->_stringtoshow = '<!-- Build using ' . $this->_library . ' -->' . "\n";
        if (!empty($this->title)) {
            $this->_stringtoshow .= '<div align="center" class="dolgraphtitle' . (empty($this->cssprefix) ? '' : ' dolgraphtitle' . $this->cssprefix) . '">' . $this->title . '</div>';
        }
        $this->_stringtoshow .= '<div id="placeholder_' . $tag . '" style="width:' . $this->width . 'px;height:' . $this->height . 'px;" class="dolgraph' . (empty($this->cssprefix) ? '' : ' dolgraph' . $this->cssprefix) . '"></div>' . "\n";
        $this->_stringtoshow .= '<script id="' . $tag . '">' . "\n";
        $this->_stringtoshow .= '$(function () {' . "\n";
        $i = $firstlot;
        while ($i < $nblot) {
            $this->_stringtoshow .= $serie[$i];
            $i++;
        }
        $this->_stringtoshow .= "\n";
        // Special case for Graph of type 'pie'
        if (isset($this->type[$firstlot]) && $this->type[$firstlot] == 'pie') {
            $datacolor = array();
            foreach ($this->datacolor as $val) {
                $datacolor[] = "#" . sprintf("%02x%02x%02x", $val[0], $val[1], $val[2]);
            }
            $urltemp = '';
            // TODO Add support for url link into labels
            $showlegend = $this->showlegend;
            $showpointvalue = $this->showpointvalue;
            $showpercent = $this->showpercent;
            $this->_stringtoshow .= '
			function plotWithOptions_' . $tag . '() {
			$.plot($("#placeholder_' . $tag . '"), d0,
			{
			series: {
			pie: {
			show: true,
			radius: 3/4,
			label: {
			show: true,
			radius: 3/4,
			formatter: function(label, series) {
			var percent=Math.round(series.percent);
			var number=series.data[0][1];
			return \'';
            $this->_stringtoshow .= '<div style="font-size:8pt;text-align:center;padding:2px;color:white;">';
            if ($urltemp) {
                $this->_stringtoshow .= '<a style="color: #FFFFFF;" border="0" href="' . $urltemp . '">';
            }
            $this->_stringtoshow .= '\'+';
            $this->_stringtoshow .= $showlegend ? '' : 'label+\'<br/>\'+';
            // Hide label if already shown in legend
            $this->_stringtoshow .= $showpointvalue ? 'number+' : '';
            $this->_stringtoshow .= $showpercent ? '\'<br/>\'+percent+\'%\'+' : '';
            $this->_stringtoshow .= '\'';
            if ($urltemp) {
                $this->_stringtoshow .= '</a>';
            }
            $this->_stringtoshow .= '</div>\';
			},
			background: {
			opacity: 0.5,
			color: \'#000000\'
			}
			}
			}
			},
			zoom: {
			interactive: true
			},
			pan: {
			interactive: true
			},';
            if (count($datacolor)) {
                $this->_stringtoshow .= 'colors: ' . (!empty($data['seriescolor']) ? json_encode($data['seriescolor']) : json_encode($datacolor)) . ',';
            }
            $this->_stringtoshow .= 'legend: {show: ' . ($showlegend ? 'true' : 'false') . ', position: \'ne\' }
		});
		}' . "\n";
        } else {
            // Add code to support tooltips
            $this->_stringtoshow .= '
			function showTooltip_' . $tag . '(x, y, contents) {
				$(\'<div id="tooltip_' . $tag . '">\' + contents + \'</div>\').css({
					position: \'absolute\',
					display: \'none\',
					top: y + 5,
					left: x + 5,
					border: \'1px solid #ddd\',
					padding: \'2px\',
					\'background-color\': \'#ffe\',
					width: 200,
					opacity: 0.80
				}).appendTo("body").fadeIn(20);
			}

			var previousPoint = null;
			$("#placeholder_' . $tag . '").bind("plothover", function (event, pos, item) {
				$("#x").text(pos.x.toFixed(2));
				$("#y").text(pos.y.toFixed(2));

				if (item) {
					if (previousPoint != item.dataIndex) {
						previousPoint = item.dataIndex;

						$("#tooltip").remove();
						/* console.log(item); */
						var x = item.datapoint[0].toFixed(2);
						var y = item.datapoint[1].toFixed(2);
						var z = item.series.xaxis.ticks[item.dataIndex].label;
						';
            if ($this->showpointvalue > 0) {
                $this->_stringtoshow .= '
							showTooltip_' . $tag . '(item.pageX, item.pageY, item.series.label + "<br>" + z + " => " + y);
						';
            }
            $this->_stringtoshow .= '
					}
				}
				else {
					$("#tooltip_' . $tag . '").remove();
					previousPoint = null;
				}
			});
			';
            $this->_stringtoshow .= 'var stack = null, steps = false;' . "\n";
            $this->_stringtoshow .= 'function plotWithOptions_' . $tag . '() {' . "\n";
            $this->_stringtoshow .= '$.plot($("#placeholder_' . $tag . '"), [ ' . "\n";
            $i = $firstlot;
            while ($i < $nblot) {
                if ($i > $firstlot) {
                    $this->_stringtoshow .= ', ' . "\n";
                }
                $color = sprintf("%02x%02x%02x", $this->datacolor[$i][0], $this->datacolor[$i][1], $this->datacolor[$i][2]);
                $this->_stringtoshow .= '{ ';
                if (!isset($this->type[$i]) || $this->type[$i] == 'bars') {
                    $this->_stringtoshow .= 'bars: { show: true, align: "' . ($i == $firstlot ? 'center' : 'left') . '", barWidth: 0.5 }, ';
                }
                if (isset($this->type[$i]) && $this->type[$i] == 'lines') {
                    $this->_stringtoshow .= 'lines: { show: true, fill: false }, ';
                }
                $this->_stringtoshow .= 'color: "#' . $color . '", label: "' . (isset($this->Legend[$i]) ? dol_escape_js($this->Legend[$i]) : '') . '", data: d' . $i . ' }';
                $i++;
            }
            $this->_stringtoshow .= "\n" . ' ], { series: { stack: stack, lines: { fill: false, steps: steps }, bars: { barWidth: 0.6 } }' . "\n";
            // Xaxis
            $this->_stringtoshow .= ', xaxis: { ticks: [' . "\n";
            $x = 0;
            foreach ($this->data as $key => $valarray) {
                if ($x > 0) {
                    $this->_stringtoshow .= ', ' . "\n";
                }
                $this->_stringtoshow .= ' [' . $x . ', "' . $valarray[0] . '"]';
                $x++;
            }
            $this->_stringtoshow .= '] }' . "\n";
            // Yaxis
            $this->_stringtoshow .= ', yaxis: { min: ' . $this->MinValue . ', max: ' . $this->MaxValue . ' }' . "\n";
            // Background color
            $color1 = sprintf("%02x%02x%02x", $this->bgcolorgrid[0], $this->bgcolorgrid[0], $this->bgcolorgrid[2]);
            $color2 = sprintf("%02x%02x%02x", $this->bgcolorgrid[0], $this->bgcolorgrid[1], $this->bgcolorgrid[2]);
            $this->_stringtoshow .= ', grid: { hoverable: true, backgroundColor: { colors: ["#' . $color1 . '", "#' . $color2 . '"] } }' . "\n";
            //$this->_stringtoshow.=', shadowSize: 20'."\n";    TODO Uncommet this
            $this->_stringtoshow .= '});' . "\n";
            $this->_stringtoshow .= '}' . "\n";
        }
        $this->_stringtoshow .= 'plotWithOptions_' . $tag . '();' . "\n";
        $this->_stringtoshow .= '});' . "\n";
        $this->_stringtoshow .= '</script>' . "\n";
    }
Example #29
0
	/**
	 *      \brief      Charge indicateurs this->nb de tableau de bord
	 *      \return     int         <0 si ko, >0 si ok
	 */
	function load_state_board()
	{
		global $conf, $user;

		$this->nb=array();
		$clause = "WHERE";

		$sql = "SELECT count(c.rowid) as nb";
		$sql.= " FROM ".MAIN_DB_PREFIX."contrat as c";
		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON c.fk_soc = s.rowid";
		if (!$user->rights->contrat->activer && !$user->societe_id)
		{
			$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
			$sql.= " WHERE sc.fk_user = "******"AND";
		}
		$sql.= " ".$clause." s.entity = ".$conf->entity;

		$resql=$this->db->query($sql);
		if ($resql)
		{
			while ($obj=$this->db->fetch_object($resql))
			{
				$this->nb["Contracts"]=$obj->nb;
			}
			return 1;
		}
		else
		{
			dol_print_error($this->db);
			$this->error=$this->db->error();
			return -1;
		}
	}
Example #30
0
	/**
	 *    \brief      Load an export profil from database
	 *    \param      rowid       id of profil to load
	 */
	function fetch($id)
	{
		$sql = 'SELECT em.rowid, em.field, em.label, em.type';
		$sql.= ' FROM '.MAIN_DB_PREFIX.'export_model as em';
		$sql.= ' WHERE em.rowid = '.$id;

		dol_syslog("Export::fetch sql=".$sql, LOG_DEBUG);
		$result = $this->db->query($sql) ;
		if ($result)
		{
			$obj = $this->db->fetch_object($result);
			if ($obj)
			{
				$this->id                   = $obj->rowid;
				$this->hexa                 = $obj->field;
				$this->model_name           = $obj->label;
				$this->datatoexport         = $obj->type;

				return 1;
			}
			else
			{
				$this->error="Model not found";
				return -2;
			}
		}
		else
		{
			dol_print_error($this->db);
			return -3;
		}
	}