Beispiel #1
0
 public static function checkLogin(\PDO $pdo_db, string $lang, Reg $tkireg, Smarty $template) : bool
 {
     // Database driven language entries
     $langvars = Translate::load($pdo_db, $lang, array('login', 'global_funcs', 'common', 'footer', 'self_destruct'));
     // Check if game is closed - Ignore the false return if it is open
     Game::isGameClosed($pdo_db, $tkireg, $lang, $template, $langvars);
     // Handle authentication check - Will die if fails, or return correct playerinfo
     $playerinfo = Player::handleAuth($pdo_db, $lang, $langvars, $tkireg, $template);
     // Establish timestamp for interval in checking bans
     $stamp = date('Y-m-d H:i:s');
     $timestamp = array();
     $timestamp['now'] = (int) strtotime($stamp);
     $timestamp['last'] = (int) strtotime($playerinfo['last_login']);
     // Check for ban - Ignore the false return if not
     Player::handleBan($pdo_db, $lang, $timestamp, $template, $playerinfo, $langvars, $tkireg);
     // Check for destroyed ship - Ignore the false return if not
     Ship::isDestroyed($pdo_db, $lang, $tkireg, $langvars, $template, $playerinfo);
     return true;
 }
 /**
  * Return description of module
  *
  * @param	Translate	$langs		Object langs
  * @return	string   		   		Description of module
  */
 function info($langs)
 {
     global $conf;
     global $form;
     $langs->load("companies");
     $tooltip = '';
     $texte = '<form action="' . $_SERVER["PHP_SELF"] . '" method="POST">';
     $texte .= '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
     $texte .= '<input type="hidden" name="action" value="setModuleOptions">';
     $texte .= '<input type="hidden" name="param1" value="COMPANY_AQUARIUM_MASK_SUPPLIER">';
     $texte .= '<input type="hidden" name="param2" value="COMPANY_AQUARIUM_MASK_CUSTOMER">';
     $texte .= '<table class="nobordernopadding" width="100%">';
     $s1 = $form->textwithpicto('<input type="text" class="flat" size="4" name="value1" value="' . $conf->global->COMPANY_AQUARIUM_MASK_SUPPLIER . '">', $tooltip, 1, 1);
     $s2 = $form->textwithpicto('<input type="text" class="flat" size="4" name="value2" value="' . $conf->global->COMPANY_AQUARIUM_MASK_CUSTOMER . '">', $tooltip, 1, 1);
     $texte .= '<tr><td>' . $langs->trans("ModuleCompanyCode" . $this->nom, $s1, $s2) . "<br>\n";
     $texte .= '</td>';
     $texte .= '<td align="left">&nbsp; <input type="submit" class="button" value="' . $langs->trans("Modify") . '" name="Button"></td>';
     $texte .= '</tr></table>';
     $texte .= '</form>';
     return $texte;
 }
Beispiel #3
0
 public static function display(\PDO $pdo_db, string $lang, Smarty $template, string $title = null, string $body_class = 'tki', bool $include_ckeditor = null)
 {
     $langvars = Translate::load($pdo_db, $lang, array('common'));
     $variables = null;
     $variables['lang'] = $lang;
     // Body class defines a css file for a specific page, if one isn't defined, it defaults to tki, which is
     // nulled by the template.
     $variables['body_class'] = $body_class;
     if ($title !== null) {
         $variables['title'] = $title;
     }
     // Some pages (like mailto) include ckeditor js, check if this is one of those.
     if (isset($include_ckeditor)) {
         $variables['include_ckeditor'] = $include_ckeditor;
     } else {
         unset($variables['include_ckeditor']);
         // Otherwise, we make sure it is NOT set
     }
     $template->addVariables('langvars', $langvars);
     $template->addVariables('variables', $variables);
     $template->display('header.tpl');
     // Perhaps this should return the template instead of kicking off display. I'm not sure.
 }
 /**
  * Return an example of result returned by getNextValue
  *
  * @param	Translate	$langs			Object langs
  * @param	Product		$objproduct		Object product
  * @return	string						Return string example
  */
 function getExample($langs, $objproduct = 0)
 {
     $examplebarcode = $this->getNextValue($objproduct, 0);
     if (!$examplebarcode) {
         $examplebarcode = $langs->trans('NotConfigured');
     }
     if ($examplebarcode == "ErrorBadMask") {
         $langs->load("errors");
         $examplebarcode = $langs->trans($examplebarcode);
     }
     return $examplebarcode;
 }
Beispiel #5
0
 include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
 $fileparams = dol_most_recent_file($conf->facture->dir_output . '/' . $ref, preg_quote($ref, '/') . '[^\\-]+');
 $file = $fileparams['fullname'];
 // Define output language
 $outputlangs = $langs;
 $newlang = '';
 if ($conf->global->MAIN_MULTILANGS && empty($newlang) && !empty($_REQUEST['lang_id'])) {
     $newlang = $_REQUEST['lang_id'];
 }
 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
     $newlang = $object->thirdparty->default_lang;
 }
 if (!empty($newlang)) {
     $outputlangs = new Translate('', $conf);
     $outputlangs->setDefaultLang($newlang);
     $outputlangs->load('bills');
 }
 // Build document if it not exists
 if (!$file || !is_readable($file)) {
     $result = $object->generateDocument(GETPOST('model') ? GETPOST('model') : $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
     if ($result <= 0) {
         dol_print_error($db, $object->error, $object->errors);
         exit;
     }
     $fileparams = dol_most_recent_file($conf->facture->dir_output . '/' . $ref, preg_quote($ref, '/') . '[^\\-]+');
     $file = $fileparams['fullname'];
 }
 print '<div class="clearboth"></div>';
 print '<br>';
 print load_fiche_titre($langs->trans($titreform));
 // Cree l'objet formulaire mail
 /**
  * testDolPrintDateTzFrance
  * Same than official testDolPrintDate but with parameter tzoutput that is false='tzserver'.
  * This test works only onto a server using TZ+1 Europe/Paris.
  *
  * You can use http://www.epochconverter.com/ to generate more tests.
  *
  * @return void
  */
 public function testDolPrintDateTzFrance()
 {
     global $conf, $user, $langs, $db;
     $conf = $this->savconf;
     $user = $this->savuser;
     $langs = $this->savlangs;
     $db = $this->savdb;
     // Check %Y-%m-%d %H:%M:%S format
     $result = dol_print_date(0, '%Y-%m-%d %H:%M:%S', false);
     print __METHOD__ . " result=" . $result . "\n";
     $this->assertEquals('1970-01-01 01:00:00', $result);
     // Check %Y-%m-%d %H:%M:%S format
     $result = dol_print_date(16725225600, '%Y-%m-%d %H:%M:%S', false);
     print __METHOD__ . " result=" . $result . "\n";
     $this->assertEquals('2500-01-01 01:00:00', $result);
     // Check %Y-%m-%d %H:%M:%S format
     $result = dol_print_date(-1830384000, '%Y-%m-%d %H:%M:%S', false);
     // http://www.epochconverter.com/
     print __METHOD__ . " result=" . $result . "\n";
     $this->assertEquals('1912-01-01 01:00:00', $result);
     // dol_print_date use a timezone, not epoch converter as it did not exists this year
     // Specific cas during war
     // 1940, no timezone
     $result = dol_print_date(-946771200, '%Y-%m-%d %H:%M:%S', false);
     // http://www.epochconverter.com/
     print __METHOD__ . " result=" . $result . "\n";
     $this->assertEquals('1940-01-01 01:00:00', $result);
     //  dol_print_date use a modern timezone, not epoch converter as it did not exists this year
     // 1941, timezone is added by germany to +2 (same for 1942)
     $result = dol_print_date(-915148800, '%Y-%m-%d %H:%M:%S', false);
     // http://www.epochconverter.com/
     print __METHOD__ . " result=" . $result . "\n";
     $this->assertEquals('1941-01-01 01:00:00', $result);
     // dol_print_date use a modern timezone, epoch converter use historic timezone
     // 1943, timezone is +1
     $result = dol_print_date(-852076800, '%Y-%m-%d %H:%M:%S', false);
     // http://www.epochconverter.com/
     print __METHOD__ . " result=" . $result . "\n";
     $this->assertEquals('1943-01-01 01:00:00', $result);
     // test with negative timezone
     $result = dol_print_date(-1, '%Y-%m-%d %H:%M:%S', false);
     // http://www.epochconverter.com/
     print __METHOD__ . " result=" . $result . "\n";
     $this->assertEquals('1970-01-01 00:59:59', $result);
     // Check dayhour format for fr_FR
     $outputlangs = new Translate('', $conf);
     $outputlangs->setDefaultLang('fr_FR');
     $outputlangs->load("main");
     $result = dol_print_date(0 + 24 * 3600, 'dayhour', false, $outputlangs);
     print __METHOD__ . " result=" . $result . "\n";
     $this->assertEquals('02/01/1970 01:00', $result);
     // Check day format for en_US
     $outputlangs = new Translate('', $conf);
     $outputlangs->setDefaultLang('en_US');
     $outputlangs->load("main");
     $result = dol_print_date(0 + 24 * 3600, 'day', false, $outputlangs);
     print __METHOD__ . " result=" . $result . "\n";
     $this->assertEquals('01/02/1970', $result);
     // Check %a and %b format for en_US
     $result = dol_print_date(0, '%a %b', false, $outputlangs);
     print __METHOD__ . " result=" . $result . "\n";
     $this->assertEquals('Thu Jan', $result);
     return $result;
 }
    // Define options
    if (preg_match('/^lang=/i', $value)) {
        $found = true;
        $valarray = explode('=', $value);
        $newlangid = $valarray[1];
        print 'Use language ' . $newlangid . ".\n";
    }
}
$outputlangs = $langs;
if (!empty($newlangid)) {
    if ($outputlangs->defaultlang != $newlangid) {
        $outputlangs = new Translate("", $conf);
        $outputlangs->setDefaultLang($newlangid);
    }
}
$outputlangs->load("main");
$outputlangs->load("bills");
$outputlangs->load("companies");
$outputlangs->load("banks");
$outputlangs->load("members");
$outputlangs->load("compta");
$acct = new Account($db);
$result = $acct->fetch('', $bankref);
if ($result <= 0) {
    print "Failed to find bank account with ref " . $bankref . ".\n";
    exit(-1);
} else {
    print "Export for bank account " . $acct->ref . " (" . $acct->label . ").\n";
}
// Creation de la classe d'export du model ExportXXX
$dir = DOL_DOCUMENT_ROOT . "/core/modules/export/";
Beispiel #8
0
 include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
 $fileparams = dol_most_recent_file($conf->expedition->dir_output . '/sending/' . $ref, preg_quote($ref, '/') . '[^\\-]+');
 $file = $fileparams['fullname'];
 // Define output language
 $outputlangs = $langs;
 $newlang = '';
 if ($conf->global->MAIN_MULTILANGS && empty($newlang) && !empty($_REQUEST['lang_id'])) {
     $newlang = $_REQUEST['lang_id'];
 }
 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
     $newlang = $object->client->default_lang;
 }
 if (!empty($newlang)) {
     $outputlangs = new Translate('', $conf);
     $outputlangs->setDefaultLang($newlang);
     $outputlangs->load('sendings');
 }
 // Build document if it not exists
 if (!$file || !is_readable($file)) {
     $result = $object->generateDocument(GETPOST('model') ? GETPOST('model') : $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
     if ($result <= 0) {
         dol_print_error($db, $object->error, $object->errors);
         exit;
     }
     $fileparams = dol_most_recent_file($conf->expedition->dir_output . '/sending/' . $ref, preg_quote($ref, '/') . '[^\\-]+');
     $file = $fileparams['fullname'];
 }
 print '<div class="clearboth"></div>';
 print '<br>';
 print load_fiche_titre($langs->trans('SendShippingByEMail'));
 dol_fiche_head('');
 /**
  *  Show top header of page.
  *
  *  @param	PDF			$pdf     		Object PDF
  *  @param  Object		$object     	Object to show
  *  @param  int	    	$showaddress    0=no, 1=yes
  *  @param  Translate	$outputlangs	Object lang for output
  *  @return	void
  */
 function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
 {
     global $conf, $langs, $hookmanager, $user;
     $outputlangs->load("main");
     $outputlangs->load("bills");
     $outputlangs->load("propal");
     $outputlangs->load("companies");
     $outputlangs->load("orders");
     $default_font_size = pdf_getPDFFontSize($outputlangs);
     pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
     // Show Draft Watermark
     if ($object->statut == 0 && !empty($conf->global->COMMANDE_DRAFT_WATERMARK)) {
         pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', $conf->global->COMMANDE_DRAFT_WATERMARK);
     }
     $pdf->SetTextColor(0, 0, 60);
     $pdf->SetFont('', 'B', $default_font_size + 3);
     $posy = $this->marge_haute;
     $posx = $this->page_largeur - $this->marge_droite - 100;
     $pdf->SetXY($this->marge_gauche, $posy);
     // Logo
     $logo = $conf->mycompany->dir_output . '/logos/' . $this->emetteur->logo;
     if ($this->emetteur->logo) {
         if (is_readable($logo)) {
             $height = pdf_getHeightForLogo($logo);
             $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
             // width=0 (auto)
         } else {
             $pdf->SetTextColor(200, 0, 0);
             $pdf->SetFont('', 'B', $default_font_size - 2);
             $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
             $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
         }
     } else {
         $text = $this->emetteur->name;
         $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
     }
     $pdf->SetFont('', 'B', $default_font_size + 3);
     $pdf->SetXY($posx, $posy);
     $pdf->SetTextColor(0, 0, 60);
     $title = $outputlangs->transnoentities("Order");
     $pdf->MultiCell(100, 3, $title, '', 'R');
     $pdf->SetFont('', 'B', $default_font_size);
     $posy += 5;
     $pdf->SetXY($posx, $posy);
     $pdf->SetTextColor(0, 0, 60);
     $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref") . " : " . $outputlangs->convToOutputCharset($object->ref), '', 'R');
     $posy += 1;
     $pdf->SetFont('', '', $default_font_size - 1);
     if ($object->ref_client) {
         $posy += 5;
         $pdf->SetXY($posx, $posy);
         $pdf->SetTextColor(0, 0, 60);
         $pdf->MultiCell(100, 3, $outputlangs->transnoentities("RefCustomer") . " : " . $outputlangs->convToOutputCharset($object->ref_client), '', 'R');
     }
     $posy += 4;
     $pdf->SetXY($posx, $posy);
     $pdf->SetTextColor(0, 0, 60);
     $pdf->MultiCell(100, 3, $outputlangs->transnoentities("OrderDate") . " : " . dol_print_date($object->date, "%d %b %Y", false, $outputlangs, true), '', 'R');
     $posy += 2;
     // Show list of linked objects
     $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
     if ($showaddress) {
         // Sender properties
         $carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->client);
         // Show sender
         $posy = 42;
         $posx = $this->marge_gauche;
         if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
             $posx = $this->page_largeur - $this->marge_droite - 80;
         }
         $hautcadre = 40;
         // Show sender frame
         $pdf->SetTextColor(0, 0, 0);
         $pdf->SetFont('', '', $default_font_size - 2);
         $pdf->SetXY($posx, $posy - 5);
         $pdf->MultiCell(66, 5, $outputlangs->transnoentities("BillFrom") . ":", 0, 'L');
         $pdf->SetXY($posx, $posy);
         $pdf->SetFillColor(230, 230, 230);
         $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
         $pdf->SetTextColor(0, 0, 60);
         // Show sender name
         $pdf->SetXY($posx + 2, $posy + 3);
         $pdf->SetFont('', 'B', $default_font_size);
         $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
         $posy = $pdf->getY();
         // Show sender information
         $pdf->SetXY($posx + 2, $posy);
         $pdf->SetFont('', '', $default_font_size - 1);
         //$pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
         //$pdf->MultiCell(80, 4, $user->id, 0, 'L');
         // if($object->fk_cash == '1' || $object->fk_cash == '2')
         // 	$pdf->MultiCell(80, 4, "Quinta Avenida #1001-B Fracc. La Agricultura <br>Aguascalientes, Ags.<br>01(449) 917 3017", 0, 'L');
         // if($object->fk_cash == '3')
         // 	$pdf->MultiCell(80, 4, "Salida a Zacatecas Km. 4.5 <br>Aguascalientes,Ags. <br>01(449) 973 1314", 0, 'L');
         // if($object->fk_cash == '4')
         // 	$pdf->MultiCell(80, 4, "Salida a San Luis Km. 1.9 Fracc. Asturias <br>Aguascalientes, Ags. <br>01(449) 1458210", 0, 'L');
         // if($object->fk_cash == '5' || $object->fk_cash == '6' || $object->fk_cash == '7')
         // 	$pdf->MultiCell(80, 4, "Carr. San Juan –Lagos Km 5.9 <br>San Juan de Los Lagos, Jal.", 0, 'L');
         // if($object->fk_cash == '8')
         // 	$pdf->MultiCell(80, 4, "Carr. San Juan –Lagos Km 5.9 <br>San Juan de Los Lagos, Jal.", 0, 'L');
         // if($object->fk_cash == '9' || $object->fk_cash == '10')
         // 	$pdf->MultiCell(80, 4, "Moreno Valley #199 <br>San Juan de los Lagos, Jal.<br>01(395) 785 3005", 0, 'L');
         if ($user->id == 1) {
             $pdf->MultiCell(80, 4, "Quinta Avenida #1001-B Fracc. La Agricultura Aguascalientes, Ags. 01(449) 917 3017", 0, 'L');
         }
         if ($user->id == 2) {
             $pdf->MultiCell(80, 4, "Quinta Avenida #1001-B Fracc. La Agricultura Aguascalientes, Ags. 01(449) 917 3017", 0, 'L');
         }
         if ($user->id == 16) {
             $pdf->MultiCell(80, 4, "Quinta Avenida #1001-B Fracc. La Agricultura Aguascalientes, Ags. 01(449) 917 3017", 0, 'L');
         }
         if ($user->id == 5) {
             $pdf->MultiCell(80, 4, "Carr. San Juan –Lagos Km 5.9 San Juan de Los Lagos, Jal.", 0, 'L');
         }
         if ($user->id == 7) {
             $pdf->MultiCell(80, 4, "Carr. San Juan –Lagos Km 5.9 San Juan de Los Lagos, Jal.", 0, 'L');
         }
         if ($user->id == 10) {
             $pdf->MultiCell(80, 4, "Carr. San Juan –Lagos Km 5.9 San Juan de Los Lagos, Jal.", 0, 'L');
         }
         if ($user->id == 11) {
             $pdf->MultiCell(80, 4, "Carr. San Juan –Lagos Km 5.9 San Juan de Los Lagos, Jal.", 0, 'L');
         }
         if ($user->id == 15) {
             $pdf->MultiCell(80, 4, "Carr. San Juan –Lagos Km 5.9 San Juan de Los Lagos, Jal.", 0, 'L');
         }
         if ($user->id == 17) {
             $pdf->MultiCell(80, 4, "Carr. San Juan –Lagos Km 5.9 San Juan de Los Lagos, Jal.", 0, 'L');
         }
         if ($user->id == 21) {
             $pdf->MultiCell(80, 4, "Carr. San Juan –Lagos Km 5.9 San Juan de Los Lagos, Jal.", 0, 'L');
         }
         if ($user->id == 8) {
             $pdf->MultiCell(80, 4, "Moreno Valley #199 San Juan de los Lagos, Jal. 01(395) 785 3005", 0, 'L');
         }
         if ($user->id == 14) {
             $pdf->MultiCell(80, 4, "Moreno Valley #199 San Juan de los Lagos, Jal. 01(395) 785 3005", 0, 'L');
         }
         if ($user->id == 13) {
             $pdf->MultiCell(80, 4, "Salida a Zacatecas Km. 4.5 Aguascalientes,Ags. 01(449) 973 1314", 0, 'L');
         }
         if ($user->id == 23) {
             $pdf->MultiCell(80, 4, "Salida a Zacatecas Km. 4.5 Aguascalientes,Ags. 01(449) 973 1314", 0, 'L');
         }
         if ($user->id == 12) {
             $pdf->MultiCell(80, 4, "Salida a San Luis Km. 1.9 Fracc. Asturias Aguascalientes, Ags. 01(449) 1458210", 0, 'L');
         }
         if ($user->id == 22) {
             $pdf->MultiCell(80, 4, "Salida a San Luis Km. 1.9 Fracc. Asturias Aguascalientes, Ags. 01(449) 1458210", 0, 'L');
         }
         // If CUSTOMER contact defined on order, we use it
         $usecontact = false;
         $arrayidcontact = $object->getIdContact('external', 'CUSTOMER');
         if (count($arrayidcontact) > 0) {
             $usecontact = true;
             $result = $object->fetch_contact($arrayidcontact[0]);
         }
         // Recipient name
         if (!empty($usecontact)) {
             // On peut utiliser le nom de la societe du contact
             if (!empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) {
                 $socname = $object->contact->socname;
             } else {
                 $socname = $object->client->nom;
             }
             $carac_client_name = $outputlangs->convToOutputCharset($socname);
         } else {
             $carac_client_name = $outputlangs->convToOutputCharset($object->client->nom);
         }
         $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->client, $usecontact ? $object->contact : '', $usecontact, 'target');
         // Show recipient
         $widthrecbox = 100;
         if ($this->page_largeur < 210) {
             $widthrecbox = 84;
         }
         // To work with US executive format
         $posy = 42;
         $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
         if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
             $posx = $this->marge_gauche;
         }
         // Show recipient frame
         $pdf->SetTextColor(0, 0, 0);
         $pdf->SetFont('', '', $default_font_size - 2);
         $pdf->SetXY($posx + 2, $posy - 5);
         $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo") . ":", 0, 'L');
         $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
         // Show recipient name
         $pdf->SetXY($posx + 2, $posy + 3);
         $pdf->SetFont('', 'B', $default_font_size);
         $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, 'L');
         // Show recipient information
         $pdf->SetFont('', '', $default_font_size - 1);
         $pdf->SetXY($posx + 2, $posy + 4 + dol_nboflines_bis($carac_client_name, 50) * 4);
         $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
     }
     $pdf->SetTextColor(0, 0, 0);
 }
 /**
  *  Show top header of page.
  *
  *  @param	PDF			&$pdf     		Object PDF
  *  @param  Object		$object     	Object to show
  *  @param  int	    	$showaddress    0=no, 1=yes
  *  @param  Translate	$outputlangs	Object lang for output
  *  @param	object		$hookmanager	Hookmanager object
  *  @return	void
  */
 function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $hookmanager)
 {
     global $conf, $langs;
     $outputlangs->load("main");
     $outputlangs->load("bills");
     $outputlangs->load("propal");
     $outputlangs->load("companies");
     $default_font_size = pdf_getPDFFontSize($outputlangs);
     pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
     //  Show Draft Watermark
     if ($object->statut == 0 && !empty($conf->global->PROPALE_DRAFT_WATERMARK)) {
         pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', $conf->global->PROPALE_DRAFT_WATERMARK);
     }
     $pdf->SetTextColor(0, 0, 60);
     $pdf->SetFont('', 'B', $default_font_size + 3);
     $posy = $this->marge_haute + 3;
     $posx = $this->page_largeur - $this->marge_droite - 100;
     $pdf->SetXY($this->marge_gauche, $posy);
     // Logo
     $logo = $conf->mycompany->dir_output . '/logos/' . $this->emetteur->logo;
     if ($this->emetteur->logo) {
         if (is_readable($logo)) {
             $height = pdf_getHeightForLogo($logo) * 0.8;
             $pdf->Image($logo, $this->marge_gauche + 5, $posy, 0, $height);
             // width=0 (auto)
         } else {
             $pdf->SetTextColor(200, 0, 0);
             $pdf->SetFont('', 'B', $default_font_size - 2);
             $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
             $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
         }
     } else {
         $text = $this->emetteur->name;
         $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
     }
     $pdf->SetFont('', 'B', $default_font_size + 3);
     $pdf->SetXY($posx, $posy);
     $pdf->SetTextColor(0, 0, 60);
     $title = $outputlangs->transnoentities("CommercialProposal");
     $pdf->MultiCell(100, 4, $title, '', 'R');
     $pdf->SetFont('', 'B', $default_font_size);
     $posy += 5;
     $pdf->SetXY($posx, $posy);
     $pdf->SetTextColor(0, 0, 60);
     $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref") . " : " . $outputlangs->convToOutputCharset($object->ref), '', 'R');
     $posy += 1;
     $pdf->SetFont('', '', $default_font_size - 1);
     if ($object->ref_client) {
         $posy += 5;
         $pdf->SetXY($posx, $posy);
         $pdf->SetTextColor(0, 0, 60);
         $pdf->MultiCell(100, 3, $outputlangs->transnoentities("RefCustomer") . " : " . $outputlangs->convToOutputCharset($object->ref_client), '', 'R');
     }
     $posy += 4;
     $pdf->SetXY($posx, $posy);
     $pdf->SetTextColor(0, 0, 60);
     $pdf->MultiCell(100, 3, $outputlangs->transnoentities("Date") . " : " . dol_print_date($object->date, "day", false, $outputlangs, true), '', 'R');
     $posy += 4;
     $pdf->SetXY($posx, $posy);
     $pdf->SetTextColor(0, 0, 60);
     $pdf->MultiCell(100, 3, $outputlangs->transnoentities("DateEndPropal") . " : " . dol_print_date($object->fin_validite, "day", false, $outputlangs, true), '', 'R');
     if ($object->client->code_client) {
         $posy += 4;
         $pdf->SetXY($posx, $posy);
         $pdf->SetTextColor(0, 0, 60);
         $pdf->MultiCell(100, 3, $outputlangs->transnoentities("CustomerCode") . " : " . $outputlangs->transnoentities($object->client->code_client), '', 'R');
     }
     $posy += 2;
     // Show list of linked objects
     $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size, $hookmanager);
     if ($showaddress) {
         // Sender properties
         $carac_emetteur = '';
         // Add internal contact of proposal if defined
         $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
         if (count($arrayidcontact) > 0) {
             $object->fetch_user($arrayidcontact[0]);
             $carac_emetteur .= ($carac_emetteur ? "\n" : '') . $outputlangs->transnoentities("Name") . ": " . $outputlangs->convToOutputCharset($object->user->getFullName($outputlangs)) . "\n";
         }
         $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur);
         // Show sender
         $posy = 42;
         $posx = $this->marge_gauche;
         if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
             $posx = $this->page_largeur - $this->marge_droite - 80;
         }
         $hautcadre = 40;
         // Show sender frame
         $pdf->SetTextColor(0, 0, 0);
         $pdf->SetFont('', '', $default_font_size - 2);
         $pdf->SetXY($posx, $posy - 5);
         $pdf->MultiCell(66, 5, $outputlangs->transnoentities("BillFrom") . ":", 0, 'L');
         $pdf->SetXY($posx, $posy);
         $pdf->SetFillColor(230, 230, 230);
         $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
         $pdf->SetTextColor(0, 0, 60);
         // Show sender name
         $pdf->SetXY($posx + 2, $posy + 3);
         $pdf->SetFont('', 'B', $default_font_size);
         $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
         // Show sender information
         $pdf->SetXY($posx + 2, $posy + 8);
         $pdf->SetFont('', '', $default_font_size - 1);
         $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
         // If CUSTOMER contact defined, we use it
         $usecontact = false;
         $arrayidcontact = $object->getIdContact('external', 'CUSTOMER');
         if (count($arrayidcontact) > 0) {
             $usecontact = true;
             $result = $object->fetch_contact($arrayidcontact[0]);
         }
         // Recipient name
         if (!empty($usecontact)) {
             // On peut utiliser le nom de la societe du contact
             if (!empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) {
                 $socname = $object->contact->socname;
             } else {
                 $socname = $object->client->nom;
             }
             $carac_client_name = $outputlangs->convToOutputCharset($socname);
         } else {
             $carac_client_name = $outputlangs->convToOutputCharset($object->client->nom);
         }
         $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->client, $usecontact ? $object->contact : '', $usecontact, 'target');
         // Show recipient
         $widthrecbox = 100;
         if ($this->page_largeur < 210) {
             $widthrecbox = 84;
         }
         // To work with US executive format
         $posy = 42;
         $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
         if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
             $posx = $this->marge_gauche;
         }
         // Show recipient frame
         $pdf->SetTextColor(0, 0, 0);
         $pdf->SetFont('', '', $default_font_size - 2);
         $pdf->SetXY($posx + 2, $posy - 5);
         $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo") . ":", 0, 'L');
         $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
         // Show recipient name
         $pdf->SetXY($posx + 2, $posy + 3);
         $pdf->SetFont('', 'B', $default_font_size);
         $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, 'L');
         // Show recipient information
         $pdf->SetFont('', '', $default_font_size - 1);
         $pdf->SetXY($posx + 2, $posy + 4 + dol_nboflines_bis($carac_client_name, 50) * 4);
         $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
     }
 }
Beispiel #11
0
 include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
 $fileparams = dol_most_recent_file($conf->propal->dir_output . '/' . $ref, preg_quote($ref, '/') . '[^\\-]+');
 $file = $fileparams['fullname'];
 // Define output language
 $outputlangs = $langs;
 $newlang = '';
 if ($conf->global->MAIN_MULTILANGS && empty($newlang) && !empty($_REQUEST['lang_id'])) {
     $newlang = $_REQUEST['lang_id'];
 }
 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
     $newlang = $object->thirdparty->default_lang;
 }
 if (!empty($newlang)) {
     $outputlangs = new Translate('', $conf);
     $outputlangs->setDefaultLang($newlang);
     $outputlangs->load('commercial');
 }
 // Build document if it not exists
 if (!$file || !is_readable($file)) {
     $result = $object->generateDocument(GETPOST('model') ? GETPOST('model') : $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
     if ($result <= 0) {
         dol_print_error($db, $object->error, $object->errors);
         exit;
     }
     $fileparams = dol_most_recent_file($conf->propal->dir_output . '/' . $ref, preg_quote($ref, '/') . '[^\\-]+');
     $file = $fileparams['fullname'];
 }
 print '<div class="clearboth"></div>';
 print '<br>';
 print load_fiche_titre($langs->trans('SendPropalByMail'));
 dol_fiche_head('');
 /**
  * Function called when a Dolibarrr business event is done.
  * All functions "runTrigger" are triggered if file is inside directory htdocs/core/triggers or htdocs/module/code/triggers (and declared)
  *
  * @param string		$action		Event action code
  * @param Object		$object     Object
  * @param User			$user       Object user
  * @param Translate		$langs      Object langs
  * @param conf			$conf       Object conf
  * @return int         				<0 if KO, 0 if no triggered ran, >0 if OK
  */
 public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
 {
     if (!empty($conf->global->MAIN_LOGEVENTS_DISABLE_ALL)) {
         return 0;
     }
     // Log events is disabled (hidden features)
     $key = 'MAIN_LOGEVENTS_' . $action;
     //dol_syslog("xxxxxxxxxxx".$key);
     if (empty($conf->global->{$key})) {
         return 0;
     }
     // Log events not enabled for this action
     if (empty($conf->entity)) {
         $conf->entity = $entity;
     }
     // forcing of the entity if it's not defined (ex: in login form)
     $date = dol_now();
     // Actions
     if ($action == 'USER_LOGIN') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         // Initialisation donnees (date,duree,texte,desc)
         $text = "(UserLogged," . $object->login . ")";
         $text .= empty($object->trigger_mesg) ? '' : ' - ' . $object->trigger_mesg;
         $desc = "(UserLogged," . $object->login . ")";
         $desc .= empty($object->trigger_mesg) ? '' : ' - ' . $object->trigger_mesg;
     }
     if ($action == 'USER_LOGIN_FAILED') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         // Initialisation donnees (date,duree,texte,desc)
         $text = $object->trigger_mesg;
         // Message direct
         $desc = $object->trigger_mesg;
         // Message direct
     }
     if ($action == 'USER_LOGOUT') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         // Initialisation donnees (date,duree,texte,desc)
         $text = "(UserLogoff," . $object->login . ")";
         $desc = "(UserLogoff," . $object->login . ")";
     }
     if ($action == 'USER_CREATE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("users");
         // Initialisation donnees (date,duree,texte,desc)
         $text = $langs->transnoentities("NewUserCreated", $object->login);
         $desc = $langs->transnoentities("NewUserCreated", $object->login);
     } elseif ($action == 'USER_MODIFY') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("users");
         // Initialisation donnees (date,duree,texte,desc)
         $text = $langs->transnoentities("EventUserModified", $object->login);
         $desc = $langs->transnoentities("EventUserModified", $object->login);
     } elseif ($action == 'USER_NEW_PASSWORD') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("users");
         // Initialisation donnees (date,duree,texte,desc)
         $text = $langs->transnoentities("NewUserPassword", $object->login);
         $desc = $langs->transnoentities("NewUserPassword", $object->login);
     } elseif ($action == 'USER_ENABLEDISABLE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("users");
         // Initialisation donnees (date,duree,texte,desc)
         if ($object->statut == 0) {
             $text = $langs->transnoentities("UserEnabled", $object->login);
             $desc = $langs->transnoentities("UserEnabled", $object->login);
         }
         if ($object->statut == 1) {
             $text = $langs->transnoentities("UserDisabled", $object->login);
             $desc = $langs->transnoentities("UserDisabled", $object->login);
         }
     } elseif ($action == 'USER_DELETE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("users");
         // Initialisation donnees (date,duree,texte,desc)
         $text = $langs->transnoentities("UserDeleted", $object->login);
         $desc = $langs->transnoentities("UserDeleted", $object->login);
     } elseif ($action == 'GROUP_CREATE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("users");
         // Initialisation donnees (date,duree,texte,desc)
         $text = $langs->transnoentities("NewGroupCreated", $object->name);
         $desc = $langs->transnoentities("NewGroupCreated", $object->name);
     } elseif ($action == 'GROUP_MODIFY') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("users");
         // Initialisation donnees (date,duree,texte,desc)
         $text = $langs->transnoentities("GroupModified", $object->name);
         $desc = $langs->transnoentities("GroupModified", $object->name);
     } elseif ($action == 'GROUP_DELETE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("users");
         // Initialisation donnees (date,duree,texte,desc)
         $text = $langs->transnoentities("GroupDeleted", $object->name);
         $desc = $langs->transnoentities("GroupDeleted", $object->name);
     }
     // If not found
     /*
             else
             {
                 dol_syslog("Trigger '".$this->name."' for action '$action' was ran by ".__FILE__." but no handler found for this action.");
     			return 0;
             }
     */
     // Add entry in event table
     include_once DOL_DOCUMENT_ROOT . '/core/class/events.class.php';
     $event = new Events($this->db);
     $event->type = $action;
     $event->dateevent = $date;
     $event->label = $text;
     $event->description = $desc;
     $event->user_agent = $_SERVER["HTTP_USER_AGENT"];
     $result = $event->create($user);
     if ($result > 0) {
         return 1;
     } else {
         $error = "Failed to insert security event: " . $event->error;
         $this->error = $error;
         dol_syslog(get_class($this) . ": " . $this->error, LOG_ERR);
         return -1;
     }
     return 0;
 }
 /**
  *  Show top header of page.
  *
  *  @param	PDF			&$pdf     		Object PDF
  *  @param  Object		$object     	Object to show
  *  @param  int	    	$showaddress    0=no, 1=yes
  *  @param  Translate	$outputlangs	Object lang for output
  *  @return	void
  */
 function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
 {
     global $langs, $conf, $mysoc;
     $outputlangs->load("main");
     $outputlangs->load("bills");
     $outputlangs->load("orders");
     $outputlangs->load("companies");
     $default_font_size = pdf_getPDFFontSize($outputlangs);
     // Do not add the BACKGROUND as this is for suppliers
     //pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
     $pdf->SetTextColor(0, 0, 60);
     $pdf->SetFont('', 'B', $default_font_size + 3);
     $posx = $this->page_largeur - $this->marge_droite - 100;
     $posy = $this->marge_haute;
     $pdf->SetXY($this->marge_gauche, $posy);
     // Logo
     /*
     		$logo=$conf->mycompany->dir_output.'/logos/'.$mysoc->logo;
     		if ($mysoc->logo)
     		{
     			if (is_readable($logo))
     			{
     			    $height=pdf_getHeightForLogo($logo);
     			    $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);	// width=0 (auto)
     			}
     			else
     			{
     				$pdf->SetTextColor(200,0,0);
     				$pdf->SetFont('','B', $default_font_size - 2);
     				$pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
     				$pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToModuleSetup"), 0, 'L');
     			}
     		}
     		else
     		{*/
     $text = $this->emetteur->name;
     $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
     //}
     $pdf->SetFont('', 'B', $default_font_size + 3);
     $pdf->SetXY($posx, $posy);
     $pdf->SetTextColor(0, 0, 60);
     $pdf->MultiCell(100, 4, $outputlangs->transnoentities("SupplierInvoice") . " " . $outputlangs->convToOutputCharset($object->ref), '', 'R');
     $pdf->SetFont('', '', $default_font_size + 2);
     if ($object->ref_supplier) {
         $posy += 5;
         $pdf->SetXY($posx, $posy);
         $pdf->MultiCell(100, 4, $outputlangs->transnoentities("RefSupplier") . " : " . $object->ref_supplier, '', 'R');
     }
     $posy += 6;
     $pdf->SetXY($posx, $posy);
     if ($object->date) {
         $pdf->SetTextColor(0, 0, 60);
         $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Date") . " : " . dol_print_date($object->date, "day", false, $outputlangs, true), '', 'R');
     } else {
         $pdf->SetTextColor(255, 0, 0);
         $pdf->MultiCell(100, 4, strtolower($outputlangs->transnoentities("OrderToProcess")), '', 'R');
     }
     if ($showaddress) {
         // Sender properties
         $carac_emetteur = pdf_build_address($outputlangs, $this->emetteur);
         // Show sender
         $posy = 42;
         $posx = $this->marge_gauche;
         if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
             $posx = $this->page_largeur - $this->marge_droite - 80;
         }
         $hautcadre = 40;
         // Show sender frame
         $pdf->SetTextColor(0, 0, 0);
         $pdf->SetFont('', '', $default_font_size - 2);
         $pdf->SetXY($posx, $posy - 5);
         $pdf->MultiCell(66, 5, $outputlangs->transnoentities("BillFrom") . ":", 0, 'L');
         $pdf->SetXY($posx, $posy);
         $pdf->SetFillColor(230, 230, 230);
         $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
         $pdf->SetTextColor(0, 0, 60);
         // Show sender name
         $pdf->SetXY($posx + 2, $posy + 3);
         $pdf->SetFont('', 'B', $default_font_size);
         $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
         // Show sender information
         $pdf->SetXY($posx + 2, $posy + 4 + dol_nboflines_bis($this->emetteur->name, 44) * 4);
         $pdf->SetFont('', '', $default_font_size - 1);
         $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
         // If BILLING contact defined on invoice, we use it
         $usecontact = false;
         $arrayidcontact = $object->getIdContact('internal', 'BILLING');
         if (count($arrayidcontact) > 0) {
             $usecontact = true;
             $result = $object->fetch_contact($arrayidcontact[0]);
         }
         // Recipient name
         if (!empty($usecontact)) {
             // On peut utiliser le nom de la societe du contact
             if ($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) {
                 $socname = $object->contact->socname;
             } else {
                 $socname = $mysoc->nom;
             }
             $carac_client_name = $outputlangs->convToOutputCharset($socname);
         } else {
             $carac_client_name = $outputlangs->convToOutputCharset($mysoc->nom);
         }
         $carac_client = pdf_build_address($outputlangs, $this->emetteur, $mysoc, $object->contact, $usecontact, 'target');
         // Show recipient
         $posy = 42;
         $posx = $this->page_largeur - $this->marge_droite - 100;
         if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
             $posx = $this->marge_gauche;
         }
         // Show recipient frame
         $pdf->SetTextColor(0, 0, 0);
         $pdf->SetFont('', '', $default_font_size - 2);
         $pdf->SetXY($posx + 2, $posy - 5);
         $pdf->MultiCell(80, 5, $outputlangs->transnoentities("BillTo") . ":", 0, 'L');
         $pdf->Rect($posx, $posy, 100, $hautcadre);
         // Show recipient name
         $pdf->SetXY($posx + 2, $posy + 3);
         $pdf->SetFont('', 'B', $default_font_size);
         $pdf->MultiCell(96, 4, $carac_client_name, 0, 'L');
         // Show recipient information
         $pdf->SetFont('', '', $default_font_size - 1);
         $pdf->SetXY($posx + 2, $posy + 4 + dol_nboflines_bis($carac_client_name, 50) * 4);
         $pdf->MultiCell(86, 4, $carac_client, 0, 'L');
     }
 }
 /**
  * Return an example of result returned by getNextValue
  *
  * @param	Translate	$langs		Object langs
  * @param	product		$objproduct		Object product
  * @param	int			$type		Type of third party (1:customer, 2:supplier, -1:autodetect)
  * @return	string					Return string example
  */
 function getExample($langs, $objproduct = 0, $type = -1)
 {
     if ($type == 0 || $type == -1) {
         $exampleproduct = $this->getNextValue($objproduct, 0);
         if (!$exampleproduct) {
             $exampleproduct = $langs->trans('NotConfigured');
         }
         if ($exampleproduct == "ErrorBadMask") {
             $langs->load("errors");
             $exampleproduct = $langs->trans($exampleproduct);
         }
     }
     if ($type == 1 || $type == -1) {
         $exampleservice = $this->getNextValue($objproduct, 1);
         if (!$exampleservice) {
             $exampleservice = $langs->trans('NotConfigured');
         }
         if ($exampleservice == "ErrorBadMask") {
             $langs->load("errors");
             $exampleservice = $langs->trans($exampleservice);
         }
     }
     if ($type == 0) {
         return $exampleproduct;
     }
     if ($type == 1) {
         return $exampleservice;
     }
     return $exampleproduct . '<br>' . $exampleservice;
 }
Beispiel #15
0
     $dol_tz_string = preg_replace('/\\s/', '_', $dol_tz_string);
     $dol_dst = 0;
     if (isset($_POST["dst_first"]) && isset($_POST["dst_second"])) {
         include_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
         $datenow = dol_now();
         $datefirst = dol_stringtotime($_POST["dst_first"]);
         $datesecond = dol_stringtotime($_POST["dst_second"]);
         if ($datenow >= $datefirst && $datenow < $datesecond) {
             $dol_dst = 1;
         }
     }
     //print $datefirst.'-'.$datesecond.'-'.$datenow.'-'.$dol_tz.'-'.$dol_tzstring.'-'.$dol_dst; exit;
 }
 if (!$login) {
     dol_syslog('Bad password, connexion refused', LOG_DEBUG);
     $langs->load('main');
     $langs->load('errors');
     // Bad password. No authmode has found a good password.
     $user->trigger_mesg = $langs->trans("ErrorBadLoginPassword") . ' - login='******'/core/class/interfaces.class.php';
     $interface = new Interfaces($db);
     $result = $interface->run_triggers('USER_LOGIN_FAILED', $user, $user, $langs, $conf, GETPOST("username", "alpha", 2));
     if ($result < 0) {
         $error++;
     }
Beispiel #16
0
/**
 * 	Return linked objects
 *
 * 	@param	object		$object			Object
 * 	@param	Translate	$outputlangs	Object lang for output
 * 	@return	array   Linked objects
 */
function pdf_getLinkedObjects($object, $outputlangs)
{
    global $hookmanager;
    $linkedobjects = array();
    $object->fetchObjectLinked();
    foreach ($object->linkedObjects as $objecttype => $objects) {
        if ($objecttype == 'propal') {
            $outputlangs->load('propal');
            foreach ($objects as $elementobject) {
                $linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefProposal");
                $linkedobjects[$objecttype]['ref_value'] = $outputlangs->transnoentities($elementobject->ref);
                $linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("DatePropal");
                $linkedobjects[$objecttype]['date_value'] = dol_print_date($elementobject->date, 'day', '', $outputlangs);
            }
        } else {
            if ($objecttype == 'commande') {
                $outputlangs->load('orders');
                foreach ($objects as $elementobject) {
                    $linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefOrder");
                    $linkedobjects[$objecttype]['ref_value'] = $outputlangs->transnoentities($elementobject->ref) . ($elementobject->ref_client ? ' (' . $elementobject->ref_client . ')' : '');
                    $linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("OrderDate");
                    $linkedobjects[$objecttype]['date_value'] = dol_print_date($elementobject->date, 'day', '', $outputlangs);
                }
            } else {
                if ($objecttype == 'contrat') {
                    $outputlangs->load('contracts');
                    foreach ($objects as $elementobject) {
                        $linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefContract");
                        $linkedobjects[$objecttype]['ref_value'] = $outputlangs->transnoentities($elementobject->ref);
                        $linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("DateContract");
                        $linkedobjects[$objecttype]['date_value'] = dol_print_date($elementobject->date_contrat, 'day', '', $outputlangs);
                    }
                } else {
                    if ($objecttype == 'shipping') {
                        $outputlangs->load('orders');
                        $outputlangs->load('sendings');
                        foreach ($objects as $elementobject) {
                            $elementobject->fetchObjectLinked();
                            $order = $elementobject->linkedObjects['commande'][0];
                            if (!empty($object->linkedObjects['commande'])) {
                                $linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefSending");
                                $linkedobjects[$objecttype]['ref_value'] .= $outputlangs->transnoentities($elementobject->ref);
                                $linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("DateSending");
                                $linkedobjects[$objecttype]['date_value'] .= dol_print_date($elementobject->date_delivery, 'day', '', $outputlangs);
                            } else {
                                $linkedobjects[$objecttype]['ref_title'] = $outputlangs->transnoentities("RefOrder") . ' / ' . $outputlangs->transnoentities("RefSending");
                                $linkedobjects[$objecttype]['ref_value'] = $outputlangs->convToOutputCharset($order->ref) . ($order->ref_client ? ' (' . $order->ref_client . ')' : '');
                                $linkedobjects[$objecttype]['ref_value'] .= ' / ' . $outputlangs->transnoentities($elementobject->ref);
                                $linkedobjects[$objecttype]['date_title'] = $outputlangs->transnoentities("OrderDate") . ' / ' . $outputlangs->transnoentities("DateSending");
                                $linkedobjects[$objecttype]['date_value'] = dol_print_date($order->date, 'day', '', $outputlangs);
                                $linkedobjects[$objecttype]['date_value'] .= ' / ' . dol_print_date($elementobject->date_delivery, 'day', '', $outputlangs);
                            }
                        }
                    }
                }
            }
        }
    }
    // For add external linked objects
    if (is_object($hookmanager)) {
        $parameters = array('linkedobjects' => $linkedobjects, 'outputlangs' => $outputlangs);
        $action = '';
        $hookmanager->executeHooks('pdf_getLinkedObjects', $parameters, $object, $action);
        // Note that $action and $object may have been modified by some hooks
        if (!empty($hookmanager->resArray)) {
            $linkedobjects = $hookmanager->resArray;
        }
    }
    return $linkedobjects;
}
 /**
  * Return description of a module
  *
  * @param	Translate	$langs		Object language
  * @return	string      			Description
  */
 function info($langs)
 {
     global $conf, $langs;
     $langs->load("companies");
     $langs->load("errors");
     $form = new Form($db);
     $texte = $this->description . ".<br>\n";
     $texte .= '<form action="' . $_SERVER["PHP_SELF"] . '" method="POST">';
     $texte .= '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
     $texte .= '<input type="hidden" name="action" value="setModuleOptions">';
     $texte .= '<input type="hidden" name="param1" value="COMPANY_ADDON_PDF_ODT_PATH">';
     $texte .= '<table class="nobordernopadding" width="100%">';
     // List of directories area
     $texte .= '<tr><td>';
     $texttitle = $langs->trans("ListOfDirectories");
     $listofdir = explode(',', preg_replace('/[\\r\\n]+/', ',', trim($conf->global->COMPANY_ADDON_PDF_ODT_PATH)));
     $listoffiles = array();
     foreach ($listofdir as $key => $tmpdir) {
         $tmpdir = trim($tmpdir);
         $tmpdir = preg_replace('/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
         if (!$tmpdir) {
             unset($listofdir[$key]);
             continue;
         }
         if (!is_dir($tmpdir)) {
             $texttitle .= img_warning($langs->trans("ErrorDirNotFound", $tmpdir), 0);
         } else {
             $tmpfiles = dol_dir_list($tmpdir, 'files', 0, '\\.odt');
             if (count($tmpfiles)) {
                 $listoffiles = array_merge($listoffiles, $tmpfiles);
             }
         }
     }
     $texthelp = $langs->trans("ListOfDirectoriesForModelGenODT");
     // Add list of substitution keys
     $texthelp .= '<br>' . $langs->trans("FollowingSubstitutionKeysCanBeUsed") . '<br>';
     $texthelp .= $langs->transnoentitiesnoconv("FullListOnOnlineDocumentation");
     // This contains an url, we don't modify it
     $texte .= $form->textwithpicto($texttitle, $texthelp, 1, 'help', '', 1);
     $texte .= '<table><tr><td>';
     $texte .= '<textarea class="flat" cols="60" name="value1">';
     $texte .= $conf->global->COMPANY_ADDON_PDF_ODT_PATH;
     $texte .= '</textarea>';
     $texte .= '</td>';
     $texte .= '<td align="center">&nbsp; ';
     $texte .= '<input type="submit" class="button" value="' . $langs->trans("Modify") . '" name="Button">';
     $texte .= '</td>';
     $texte .= '</tr>';
     $texte .= '</table>';
     // Scan directories
     if (count($listofdir)) {
         $texte .= $langs->trans("NumberOfModelFilesFound") . ': <b>' . count($listoffiles) . '</b>';
     }
     $texte .= '</td>';
     $texte .= '<td valign="top" rowspan="2">';
     $texte .= $langs->trans("ExampleOfDirectoriesForModelGen");
     $texte .= '</td>';
     $texte .= '</tr>';
     /*$texte.= '<tr><td align="center">';
     		$texte.= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">';
     		$texte.= '</td>';
     		$texte.= '</tr>';*/
     $texte .= '</table>';
     $texte .= '</form>';
     return $texte;
 }
 /**
  *      Return description of module parameters
  *
  *      @param	Translate	$langs      Output language
  *		@param	Product		$product	Product object
  *		@param	int			$type		-1=Nothing, 0=Customer, 1=Supplier
  *		@return	string					HTML translated description
  */
 function getToolTip($langs, $product, $type)
 {
     global $conf;
     $langs->load("admin");
     $s = '';
     if ($type == -1) {
         $s .= $langs->trans("Name") . ': <b>' . $this->nom . '</b><br>';
     }
     if ($type == -1) {
         $s .= $langs->trans("Version") . ': <b>' . $this->getVersion() . '</b><br>';
     }
     if ($type == 0) {
         $s .= $langs->trans("ProductCodeDesc") . '<br>';
     }
     if ($type == 1) {
         $s .= $langs->trans("ServiceCodeDesc") . '<br>';
     }
     if ($type != -1) {
         $s .= $langs->trans("ValidityControledByModule") . ': <b>' . $this->getNom($langs) . '</b><br>';
     }
     $s .= '<br>';
     $s .= '<u>' . $langs->trans("ThisIsModuleRules") . ':</u><br>';
     if ($type == 0) {
         $s .= $langs->trans("RequiredIfProduct") . ': ';
         if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) {
             $s .= '<strike>';
         }
         $s .= yn(!$this->code_null, 1, 2);
         if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) {
             $s .= '</strike> ' . yn(1, 1, 2) . ' (' . $langs->trans("ForcedToByAModule", $langs->transnoentities("yes")) . ')';
         }
         $s .= '<br>';
     }
     if ($type == 1) {
         $s .= $langs->trans("RequiredIfService") . ': ';
         if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) {
             $s .= '<strike>';
         }
         $s .= yn(!$this->code_null, 1, 2);
         if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) {
             $s .= '</strike> ' . yn(1, 1, 2) . ' (' . $langs->trans("ForcedToByAModule", $langs->transnoentities("yes")) . ')';
         }
         $s .= '<br>';
     }
     if ($type == -1) {
         $s .= $langs->trans("Required") . ': ';
         if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) {
             $s .= '<strike>';
         }
         $s .= yn(!$this->code_null, 1, 2);
         if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) {
             $s .= '</strike> ' . yn(1, 1, 2) . ' (' . $langs->trans("ForcedToByAModule", $langs->transnoentities("yes")) . ')';
         }
         $s .= '<br>';
     }
     $s .= $langs->trans("CanBeModifiedIfOk") . ': ';
     $s .= yn($this->code_modifiable, 1, 2);
     $s .= '<br>';
     $s .= $langs->trans("CanBeModifiedIfKo") . ': ' . yn($this->code_modifiable_invalide, 1, 2) . '<br>';
     $s .= $langs->trans("AutomaticCode") . ': ' . yn($this->code_auto, 1, 2) . '<br>';
     $s .= '<br>';
     if ($type == 0 || $type == -1) {
         $nextval = $this->getNextValue($product, 0);
         if (empty($nextval)) {
             $nextval = $langs->trans("Undefined");
         }
         $s .= $langs->trans("NextValue") . ($type == -1 ? ' (' . $langs->trans("Product") . ')' : '') . ': <b>' . $nextval . '</b><br>';
     }
     if ($type == 1 || $type == -1) {
         $nextval = $this->getNextValue($product, 1);
         if (empty($nextval)) {
             $nextval = $langs->trans("Undefined");
         }
         $s .= $langs->trans("NextValue") . ($type == -1 ? ' (' . $langs->trans("Service") . ')' : '') . ': <b>' . $nextval . '</b>';
     }
     return $s;
 }
 /**		Return description of module
  *
  * 		@param	Translate	$langs	Object langs
  * 		@return string      		Description of module
  */
 function info($langs)
 {
     $langs->load("companies");
     return $langs->trans("LeopardNumRefModelDesc");
 }
Beispiel #20
0
 include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
 $fileparams = dol_most_recent_file($conf->ficheinter->dir_output . '/' . $ref, preg_quote($ref, '/') . '[^\\-]+');
 $file = $fileparams['fullname'];
 // Define output language
 $outputlangs = $langs;
 $newlang = '';
 if ($conf->global->MAIN_MULTILANGS && empty($newlang) && !empty($_REQUEST['lang_id'])) {
     $newlang = $_REQUEST['lang_id'];
 }
 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
     $newlang = $object->client->default_lang;
 }
 if (!empty($newlang)) {
     $outputlangs = new Translate('', $conf);
     $outputlangs->setDefaultLang($newlang);
     $outputlangs->load('interventions');
 }
 // Build document if it not exists
 if (!$file || !is_readable($file)) {
     $result = fichinter_create($db, $object, GETPOST('model') ? GETPOST('model') : $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
     if ($result <= 0) {
         dol_print_error($db, $result);
         exit;
     }
     $fileparams = dol_most_recent_file($conf->ficheinter->dir_output . '/' . $ref, preg_quote($ref, '/') . '[^\\-]+');
     $file = $fileparams['fullname'];
 }
 print '<div class="clearboth"></div>';
 print '<br>';
 print load_fiche_titre($langs->trans('SendInterventionByMail'));
 dol_fiche_head('');
Beispiel #21
0
/**
 *	Show a message to say access is forbidden and stop program
 *	Calling this function terminate execution of PHP.
 *
 *	@param	string	$message			    Force error message
 *	@param	int		$printheader		    Show header before
 *  @param  int		$printfooter         Show footer after
 *  @param  int		$showonlymessage     Show only message parameter. Otherwise add more information.
 *  @return	void
 */
function accessforbidden($message = '', $printheader = 1, $printfooter = 1, $showonlymessage = 0)
{
    global $conf, $db, $user, $langs;
    if (!is_object($langs)) {
        include_once DOL_DOCUMENT_ROOT . '/core/class/translate.class.php';
        $langs = new Translate('', $conf);
    }
    $langs->load("errors");
    if ($printheader) {
        if (function_exists("llxHeader")) {
            llxHeader('');
        } else {
            if (function_exists("llxHeaderVierge")) {
                llxHeaderVierge('');
            }
        }
    }
    print '<div class="error">';
    if (!$message) {
        print $langs->trans("ErrorForbidden");
    } else {
        print $message;
    }
    print '</div>';
    print '<br>';
    if (empty($showonlymessage)) {
        if ($user->login) {
            print $langs->trans("CurrentLogin") . ': <font class="error">' . $user->login . '</font><br>';
            print $langs->trans("ErrorForbidden2", $langs->trans("Home"), $langs->trans("Users"));
        } else {
            print $langs->trans("ErrorForbidden3");
        }
    }
    if ($printfooter && function_exists("llxFooter")) {
        llxFooter();
    }
    exit(0);
}
Beispiel #22
0
/**
 * Show Dolibarr default login page.
 * Part of this code is also duplicated into main.inc.php::top_htmlhead
 *
 * @param		Translate	$langs		Lang object (must be initialized by a new).
 * @param		Conf		$conf		Conf object
 * @param		Societe		$mysoc		Company object
 * @return		void
 */
function dol_loginfunction($langs, $conf, $mysoc)
{
    global $dolibarr_main_demo, $db;
    global $smartphone, $hookmanager;
    // Instantiate hooks of thirdparty module only if not already define
    $hookmanager->initHooks(array('mainloginpage'));
    $langs->load("main");
    $langs->load("other");
    $langs->load("help");
    $langs->load("admin");
    $main_authentication = $conf->file->main_authentication;
    $session_name = session_name();
    $dol_url_root = DOL_URL_ROOT;
    $php_self = $_SERVER['PHP_SELF'];
    $php_self .= $_SERVER["QUERY_STRING"] ? '?' . $_SERVER["QUERY_STRING"] : '';
    if (!preg_match('/mainmenu=/', $php_self)) {
        $php_self .= (preg_match('/\\?/', $php_self) ? '&' : '?') . 'mainmenu=home';
    }
    // Title
    $title = 'Dolibarr ' . DOL_VERSION;
    if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
        $title = $conf->global->MAIN_APPLICATION_TITLE;
    }
    // Note: $conf->css looks like '/theme/eldy/style.css.php'
    $conf->css = "/theme/" . (GETPOST('theme') ? GETPOST('theme', 'alpha') : $conf->theme) . "/style.css.php";
    //$themepath=dol_buildpath((empty($conf->global->MAIN_FORCETHEMEDIR)?'':$conf->global->MAIN_FORCETHEMEDIR).$conf->css,1);
    $themepath = dol_buildpath($conf->css, 1);
    if (!empty($conf->modules_parts['theme'])) {
        foreach ($conf->modules_parts['theme'] as $reldir) {
            if (file_exists(dol_buildpath($reldir . $conf->css, 0))) {
                $themepath = dol_buildpath($reldir . $conf->css, 1);
                break;
            }
        }
    }
    $conf_css = $themepath . "?lang=" . $langs->defaultlang;
    // Select templates
    if (!empty($conf->modules_parts['tpl'])) {
        $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl/'));
        foreach ($dirtpls as $reldir) {
            $tmp = dol_buildpath($reldir . 'login.tpl.php');
            if (file_exists($tmp)) {
                $template_dir = preg_replace('/login\\.tpl\\.php$/', '', $tmp);
                break;
            }
        }
    } else {
        $template_dir = DOL_DOCUMENT_ROOT . "/core/tpl/";
    }
    // Set cookie for timeout management
    $prefix = dol_getprefix();
    $sessiontimeout = 'DOLSESSTIMEOUT_' . $prefix;
    if (!empty($conf->global->MAIN_SESSION_TIMEOUT)) {
        setcookie($sessiontimeout, $conf->global->MAIN_SESSION_TIMEOUT, 0, "/", '', 0);
    }
    if (GETPOST('urlfrom', 'alpha')) {
        $_SESSION["urlfrom"] = GETPOST('urlfrom', 'alpha');
    } else {
        unset($_SESSION["urlfrom"]);
    }
    if (!GETPOST("username")) {
        $focus_element = 'username';
    } else {
        $focus_element = 'password';
    }
    $login_background = DOL_URL_ROOT . '/theme/login_background.png';
    if (file_exists(DOL_DOCUMENT_ROOT . '/theme/' . $conf->theme . '/img/login_background.png')) {
        $login_background = DOL_URL_ROOT . '/theme/' . $conf->theme . '/img/login_background.png';
    }
    $demologin = '';
    $demopassword = '';
    if (!empty($dolibarr_main_demo)) {
        $tab = explode(',', $dolibarr_main_demo);
        $demologin = $tab[0];
        $demopassword = $tab[1];
    }
    // Execute hook getLoginPageOptions
    // Should be an array with differents options in $hookmanager->resArray
    $parameters = array('entity' => GETPOST('entity', 'int'));
    $hookmanager->executeHooks('getLoginPageOptions', $parameters);
    // Note that $action and $object may have been modified by some hooks
    // Login
    $login = !empty($hookmanager->resArray['username']) ? $hookmanager->resArray['username'] : (GETPOST("username", "alpha") ? GETPOST("username", "alpha") : $demologin);
    $password = $demopassword;
    // Show logo (search in order: small company logo, large company logo, theme logo, common logo)
    $width = 0;
    $urllogo = DOL_URL_ROOT . '/theme/login_logo.png';
    if (!empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output . '/logos/thumbs/' . $mysoc->logo_small)) {
        $urllogo = DOL_URL_ROOT . '/viewimage.php?cache=1&amp;modulepart=companylogo&amp;file=' . urlencode('thumbs/' . $mysoc->logo_small);
    } elseif (!empty($mysoc->logo) && is_readable($conf->mycompany->dir_output . '/logos/' . $mysoc->logo)) {
        $urllogo = DOL_URL_ROOT . '/viewimage.php?cache=1&amp;modulepart=companylogo&amp;file=' . urlencode($mysoc->logo);
        $width = 128;
    } elseif (is_readable(DOL_DOCUMENT_ROOT . '/theme/' . $conf->theme . '/img/dolibarr_logo.png')) {
        $urllogo = DOL_URL_ROOT . '/theme/' . $conf->theme . '/img/dolibarr_logo.png';
    } elseif (is_readable(DOL_DOCUMENT_ROOT . '/theme/dolibarr_logo.png')) {
        $urllogo = DOL_URL_ROOT . '/theme/dolibarr_logo.png';
    }
    // Security graphical code
    $captcha = 0;
    $captcha_refresh = '';
    if (function_exists("imagecreatefrompng") && !empty($conf->global->MAIN_SECURITY_ENABLECAPTCHA)) {
        $captcha = 1;
        $captcha_refresh = img_picto($langs->trans("Refresh"), 'refresh', 'id="captcha_refresh_img"');
    }
    // Extra link
    $forgetpasslink = 0;
    $helpcenterlink = 0;
    if (empty($conf->global->MAIN_SECURITY_DISABLEFORGETPASSLINK) || empty($conf->global->MAIN_HELPCENTER_DISABLELINK)) {
        if (empty($conf->global->MAIN_SECURITY_DISABLEFORGETPASSLINK)) {
            $forgetpasslink = 1;
        }
        if (empty($conf->global->MAIN_HELPCENTER_DISABLELINK)) {
            $helpcenterlink = 1;
        }
    }
    // Home message
    $main_home = '';
    if (!empty($conf->global->MAIN_HOME)) {
        $i = 0;
        while (preg_match('/__\\(([a-zA-Z|@]+)\\)__/i', $conf->global->MAIN_HOME, $reg) && $i < 100) {
            $tmp = explode('|', $reg[1]);
            if (!empty($tmp[1])) {
                $langs->load($tmp[1]);
            }
            $conf->global->MAIN_HOME = preg_replace('/__\\(' . preg_quote($reg[1]) . '\\)__/i', $langs->trans($tmp[0]), $conf->global->MAIN_HOME);
            $i++;
        }
        $main_home = dol_htmlcleanlastbr($conf->global->MAIN_HOME);
    }
    // Google AD
    $main_google_ad_client = !empty($conf->global->MAIN_GOOGLE_AD_CLIENT) && !empty($conf->global->MAIN_GOOGLE_AD_SLOT) ? 1 : 0;
    // Set jquery theme
    $dol_loginmesg = !empty($_SESSION["dol_loginmesg"]) ? $_SESSION["dol_loginmesg"] : '';
    $favicon = dol_buildpath('/theme/' . $conf->theme . '/img/favicon.ico', 1);
    if (!empty($conf->global->MAIN_FAVICON_URL)) {
        $favicon = $conf->global->MAIN_FAVICON_URL;
    }
    $jquerytheme = 'smoothness';
    if (!empty($conf->global->MAIN_USE_JQUERY_THEME)) {
        $jquerytheme = $conf->global->MAIN_USE_JQUERY_THEME;
    }
    // Set dol_hide_topmenu, dol_hide_leftmenu, dol_optimize_smallscreen, dol_nomousehover
    $dol_hide_topmenu = GETPOST('dol_hide_topmenu', 'int');
    $dol_hide_leftmenu = GETPOST('dol_hide_leftmenu', 'int');
    $dol_optimize_smallscreen = GETPOST('dol_optimize_smallscreen', 'int');
    $dol_no_mouse_hover = GETPOST('dol_no_mouse_hover', 'int');
    $dol_use_jmobile = GETPOST('dol_use_jmobile', 'int');
    // Include login page template
    include $template_dir . 'login.tpl.php';
    $_SESSION["dol_loginmesg"] = '';
}
 /**
  *	Return description of a module
  *
  *	@param	Translate	$langs      Lang object to use for output
  *	@return string       			Description
  */
 function info($langs)
 {
     global $conf, $langs;
     $langs->load("companies");
     $langs->load("errors");
     $form = new Form($this->db);
     $texte = $this->description . ".<br>\n";
     $texte .= '<form action="' . $_SERVER["PHP_SELF"] . '" method="POST">';
     $texte .= '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
     $texte .= '<input type="hidden" name="action" value="setModuleOptions">';
     $texte .= '<input type="hidden" name="param1" value="SUPPLIER_PROPOSAL_ADDON_PDF_ODT_PATH">';
     if ($conf->global->MAIN_SUPPLIER_PROPOSAL_CHOOSE_ODT_DOCUMENT > 0) {
         $texte .= '<input type="hidden" name="param2" value="SUPPLIER_PROPOSAL_ADDON_PDF_ODT_DEFAULT">';
         $texte .= '<input type="hidden" name="param3" value="SUPPLIER_PROPOSAL_ADDON_PDF_ODT_TOBILL">';
         $texte .= '<input type="hidden" name="param4" value="SUPPLIER_PROPOSAL_ADDON_PDF_ODT_CLOSED">';
     }
     $texte .= '<table class="nobordernopadding" width="100%">';
     // List of directories area
     $texte .= '<tr><td>';
     $texttitle = $langs->trans("ListOfDirectories");
     $listofdir = explode(',', preg_replace('/[\\r\\n]+/', ',', trim($conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_PATH)));
     $listoffiles = array();
     foreach ($listofdir as $key => $tmpdir) {
         $tmpdir = trim($tmpdir);
         $tmpdir = preg_replace('/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
         if (!$tmpdir) {
             unset($listofdir[$key]);
             continue;
         }
         if (!is_dir($tmpdir)) {
             $texttitle .= img_warning($langs->trans("ErrorDirNotFound", $tmpdir), 0);
         } else {
             $tmpfiles = dol_dir_list($tmpdir, 'files', 0, '\\.(ods|odt)');
             if (count($tmpfiles)) {
                 $listoffiles = array_merge($listoffiles, $tmpfiles);
             }
         }
     }
     $texthelp = $langs->trans("ListOfDirectoriesForModelGenODT");
     // Add list of substitution keys
     $texthelp .= '<br>' . $langs->trans("FollowingSubstitutionKeysCanBeUsed") . '<br>';
     $texthelp .= $langs->transnoentitiesnoconv("FullListOnOnlineDocumentation");
     // This contains an url, we don't modify it
     $texte .= $form->textwithpicto($texttitle, $texthelp, 1, 'help', '', 1);
     $texte .= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">';
     $texte .= '<textarea class="flat" cols="60" name="value1">';
     $texte .= $conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_PATH;
     $texte .= '</textarea>';
     $texte .= '</div><div style="display: inline-block; vertical-align: middle;">';
     $texte .= '<input type="submit" class="button" value="' . $langs->trans("Modify") . '" name="Button">';
     $texte .= '<br></div></div>';
     // Scan directories
     if (count($listofdir)) {
         $texte .= $langs->trans("NumberOfModelFilesFound") . ': <b>' . count($listoffiles) . '</b>';
         if ($conf->global->MAIN_SUPPLIER_PROPOSAL_CHOOSE_ODT_DOCUMENT > 0) {
             // Model for creation
             $liste = ModelePDFSupplierProposal::liste_modeles($this->db);
             $texte .= '<table width="50%;">';
             $texte .= '<tr>';
             $texte .= '<td width="60%;">' . $langs->trans("DefaultModelSupplierProposalCreate") . '</td>';
             $texte .= '<td colspan="">';
             $texte .= $form->selectarray('value2', $liste, $conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_DEFAULT);
             $texte .= "</td></tr>";
             $texte .= '<tr>';
             $texte .= '<td width="60%;">' . $langs->trans("DefaultModelSupplierProposalToBill") . '</td>';
             $texte .= '<td colspan="">';
             $texte .= $form->selectarray('value3', $liste, $conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_TOBILL);
             $texte .= "</td></tr>";
             $texte .= '<tr>';
             $texte .= '<td width="60%;">' . $langs->trans("DefaultModelSupplierProposalClosed") . '</td>';
             $texte .= '<td colspan="">';
             $texte .= $form->selectarray('value4', $liste, $conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_CLOSED);
             $texte .= "</td></tr>";
             $texte .= '</table>';
         }
     }
     $texte .= '</td>';
     $texte .= '<td valign="top" rowspan="2" class="hideonsmartphone">';
     $texte .= $langs->trans("ExampleOfDirectoriesForModelGen");
     $texte .= '</td>';
     $texte .= '</tr>';
     $texte .= '</table>';
     $texte .= '</form>';
     return $texte;
 }
 /**
  *      Function called when a Dolibarrr business event is done.
  *      All functions "run_trigger" are triggered if file is inside directory htdocs/core/triggers
  *
  *      @param	string		$action		Event action code
  *      @param  Object		$object     Object
  *      @param  User		$user       Object user
  *      @param  Translate	$langs      Object langs
  *      @param  conf		$conf       Object conf
  *      @return int         			<0 if KO, 0 if no triggered ran, >0 if OK
  */
 function run_trigger($action, $object, $user, $langs, $conf)
 {
     if (empty($conf->notification->enabled)) {
         return 0;
     }
     // Module not active, we do nothing
     require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php';
     if ($action == 'BILL_VALIDATE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $ref = dol_sanitizeFileName($object->ref);
         $filepdf = $conf->facture->dir_output . '/' . $ref . '/' . $ref . '.pdf';
         if (!file_exists($filepdf)) {
             $filepdf = '';
         }
         $filepdf = '';
         // We can't add PDF as it is not generated yet.
         $langs->load("other");
         $mesg = $langs->transnoentitiesnoconv("EMailTextInvoiceValidated", $object->ref);
         $notify = new Notify($this->db);
         $notify->send($action, $object->socid, $mesg, 'facture', $object->id, $filepdf);
     } elseif ($action == 'ORDER_VALIDATE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $ref = dol_sanitizeFileName($object->ref);
         $filepdf = $conf->commande->dir_output . '/' . $ref . '/' . $ref . '.pdf';
         if (!file_exists($filepdf)) {
             $filepdf = '';
         }
         $filepdf = '';
         // We can't add PDF as it is not generated yet.
         $langs->load("other");
         $mesg = $langs->transnoentitiesnoconv("EMailTextOrderValidated", $object->ref);
         $notify = new Notify($this->db);
         $notify->send($action, $object->socid, $mesg, 'order', $object->id, $filepdf);
     } elseif ($action == 'PROPAL_VALIDATE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $ref = dol_sanitizeFileName($object->ref);
         $filepdf = $conf->propal->dir_output . '/' . $ref . '/' . $ref . '.pdf';
         if (!file_exists($filepdf)) {
             $filepdf = '';
         }
         $filepdf = '';
         // We can't add PDF as it is not generated yet.
         $langs->load("other");
         $mesg = $langs->transnoentitiesnoconv("EMailTextProposalValidated", $object->ref);
         $notify = new Notify($this->db);
         $notify->send($action, $object->socid, $mesg, 'propal', $object->id, $filepdf);
     } elseif ($action == 'FICHEINTER_VALIDATE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $ref = dol_sanitizeFileName($object->ref);
         $filepdf = $conf->facture->dir_output . '/' . $ref . '/' . $ref . '.pdf';
         if (!file_exists($filepdf)) {
             $filepdf = '';
         }
         $filepdf = '';
         // We can't add PDF as it is not generated yet.
         $langs->load("other");
         $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionValidated", $object->ref);
         $notify = new Notify($this->db);
         $notify->send($action, $object->socid, $mesg, 'ficheinter', $object->id, $filepdf);
     } elseif ($action == 'ORDER_SUPPLIER_APPROVE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $ref = dol_sanitizeFileName($object->ref);
         $filepdf = $conf->fournisseur->dir_output . '/commande/' . $ref . '/' . $ref . '.pdf';
         if (!file_exists($filepdf)) {
             $filepdf = '';
         }
         $mesg = $langs->transnoentitiesnoconv("Hello") . ",\n\n";
         $mesg .= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy", $object->ref, $user->getFullName($langs));
         $mesg .= "\n\n" . $langs->transnoentitiesnoconv("Sincerely") . ".\n\n";
         $notify = new Notify($this->db);
         $notify->send($action, $object->socid, $mesg, 'order_supplier', $object->id, $filepdf);
     } elseif ($action == 'ORDER_SUPPLIER_REFUSE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $ref = dol_sanitizeFileName($object->ref);
         $filepdf = $conf->fournisseur->dir_output . '/commande/' . $ref . '/' . $ref . '.pdf';
         if (!file_exists($filepdf)) {
             $filepdf = '';
         }
         $mesg = $langs->transnoentitiesnoconv("Hello") . ",\n\n";
         $mesg .= $langs->transnoentitiesnoconv("EMailTextOrderRefusedBy", $object->ref, $user->getFullName($langs));
         $mesg .= "\n\n" . $langs->transnoentitiesnoconv("Sincerely") . ".\n\n";
         $notify = new Notify($this->db);
         $notify->send($action, $object->socid, $mesg, 'order_supplier', $object->id, $filepdf);
     }
     // If not found
     /*
             else
             {
                 dol_syslog("Trigger '".$this->name."' for action '$action' was ran by ".__FILE__." but no handler found for this action.");
     			return -1;
             }
     */
     return 0;
 }
 /**
  *      Function called when a Dolibarrr business event is done.
  *      All functions "run_trigger" are triggered if file is inside directory htdocs/core/triggers
  *
  *      Following properties must be filled:
  *      $object->actiontypecode (translation action code: AC_OTH, ...)
  *      $object->actionmsg (note, long text)
  *      $object->actionmsg2 (label, short text)
  *      $object->sendtoid (id of contact)
  *      $object->socid
  *      Optionnal:
  *      $object->fk_element
  *      $object->elementtype
  *
  *      @param	string		$action		Event action code
  *      @param  Object		$object     Object
  *      @param  User		$user       Object user
  *      @param  Translate	$langs      Object langs
  *      @param  conf		$conf       Object conf
  *      @return int         			<0 if KO, 0 if no triggered ran, >0 if OK
  */
 function run_trigger($action, $object, $user, $langs, $conf)
 {
     $key = 'MAIN_AGENDA_ACTIONAUTO_' . $action;
     //dol_syslog("xxxxxxxxxxx".$key);
     if (empty($conf->agenda->enabled)) {
         return 0;
     }
     // Module not active, we do nothing
     if (empty($conf->global->{$key})) {
         return 0;
     }
     // Log events not enabled for this action
     $ok = 0;
     // Actions
     if ($action == 'COMPANY_CREATE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("other");
         $langs->load("agenda");
         $object->actiontypecode = 'AC_OTH';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("NewCompanyToDolibarr", $object->nom);
         }
         $object->actionmsg = $langs->transnoentities("NewCompanyToDolibarr", $object->nom);
         if ($object->prefix) {
             $object->actionmsg .= " (" . $object->prefix . ")";
         }
         //$this->desc.="\n".$langs->transnoentities("Customer").': '.yn($object->client);
         //$this->desc.="\n".$langs->transnoentities("Supplier").': '.yn($object->fournisseur);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
         $object->socid = $object->id;
         $ok = 1;
     } elseif ($action == 'CONTRACT_VALIDATE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("other");
         $langs->load("contracts");
         $langs->load("agenda");
         $object->actiontypecode = 'AC_OTH';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("ContractValidatedInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("ContractValidatedInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
         $ok = 1;
     } elseif ($action == 'PROPAL_VALIDATE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("propal");
         $langs->load("agenda");
         $object->actiontypecode = 'AC_OTH';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("PropalValidatedInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("PropalValidatedInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
         $ok = 1;
     } elseif ($action == 'PROPAL_SENTBYMAIL') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("propal");
         $langs->load("agenda");
         $object->actiontypecode = 'AC_EMAIL';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("ProposalSentByEMail", $object->ref);
         }
         if (empty($object->actionmsg)) {
             $object->actionmsg = $langs->transnoentities("ProposalSentByEMail", $object->ref);
             $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         }
         // Parameters $object->sendtoid defined by caller
         //$object->sendtoid=0;
         $ok = 1;
     } elseif ($action == 'PROPAL_CLOSE_SIGNED') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("propal");
         $langs->load("agenda");
         $object->actiontypecode = 'AC_OTH';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("PropalClosedSignedInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("PropalClosedSignedInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
         $ok = 1;
     } elseif ($action == 'PROPAL_CLOSE_REFUSED') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("propal");
         $langs->load("agenda");
         $object->actiontypecode = 'AC_OTH';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("PropalClosedRefusedInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("PropalClosedRefusedInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
         $ok = 1;
     } elseif ($action == 'ORDER_VALIDATE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("orders");
         $langs->load("agenda");
         $object->actiontypecode = 'AC_OTH';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("OrderValidatedInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("OrderValidatedInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
         $ok = 1;
     } elseif ($action == 'ORDER_SENTBYMAIL') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("orders");
         $langs->load("agenda");
         $object->actiontypecode = 'AC_EMAIL';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("OrderSentByEMail", $object->ref);
         }
         if (empty($object->actionmsg)) {
             $object->actionmsg = $langs->transnoentities("OrderSentByEMail", $object->ref);
             $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         }
         // Parameters $object->sendtoid defined by caller
         //$object->sendtoid=0;
         $ok = 1;
     } elseif ($action == 'BILL_VALIDATE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("other");
         $langs->load("bills");
         $langs->load("agenda");
         $object->actiontypecode = 'AC_OTH';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("InvoiceValidatedInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("InvoiceValidatedInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
         $ok = 1;
     } elseif ($action == 'BILL_SENTBYMAIL') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("other");
         $langs->load("bills");
         $langs->load("agenda");
         $object->actiontypecode = 'AC_EMAIL';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("InvoiceSentByEMail", $object->ref);
         }
         if (empty($object->actionmsg)) {
             $object->actionmsg = $langs->transnoentities("InvoiceSentByEMail", $object->ref);
             $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         }
         // Parameters $object->sendtoid defined by caller
         //$object->sendtoid=0;
         $ok = 1;
     } elseif ($action == 'BILL_PAYED') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("other");
         $langs->load("bills");
         $langs->load("agenda");
         $object->actiontypecode = 'AC_OTH';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("InvoicePaidInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("InvoicePaidInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
         $ok = 1;
     } elseif ($action == 'BILL_CANCEL') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("other");
         $langs->load("bills");
         $langs->load("agenda");
         $object->actiontypecode = 'AC_OTH';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("InvoiceCanceledInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("InvoiceCanceledInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
         $ok = 1;
     } elseif ($action == 'FICHEINTER_VALIDATE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("other");
         $langs->load("interventions");
         $langs->load("agenda");
         $object->actiontypecode = 'AC_OTH';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("InterventionValidatedInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("InterventionValidatedInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
         $object->fk_element = 0;
         $object->elementtype = '';
         $ok = 1;
     } elseif ($action == 'FICHEINTER_SENTBYMAIL') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("other");
         $langs->load("interventions");
         $langs->load("agenda");
         $object->actiontypecode = 'AC_EMAIL';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("InterventionSentByEMail", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("InterventionSentByEMail", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         // Parameters $object->sendotid defined by caller
         //$object->sendtoid=0;
         $ok = 1;
     } elseif ($action == 'SHIPPING_SENTBYMAIL') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("other");
         $langs->load("sendings");
         $langs->load("agenda");
         $object->actiontypecode = 'AC_SHIP';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("ShippingSentByEMail", $object->ref);
         }
         if (empty($object->actionmsg)) {
             $object->actionmsg = $langs->transnoentities("ShippingSentByEMail", $object->ref);
             $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         }
         // Parameters $object->sendtoid defined by caller
         //$object->sendtoid=0;
         $ok = 1;
     } elseif ($action == 'ORDER_SUPPLIER_VALIDATE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("orders");
         $langs->load("agenda");
         $object->actiontypecode = 'AC_OTH';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("OrderValidatedInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("OrderValidatedInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
         $ok = 1;
     } elseif ($action == 'ORDER_SUPPLIER_SENTBYMAIL') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("other");
         $langs->load("bills");
         $langs->load("agenda");
         $langs->load("orders");
         $object->actiontypecode = 'AC_EMAIL';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("SupplierOrderSentByEMail", $object->ref);
         }
         if (empty($object->actionmsg)) {
             $object->actionmsg = $langs->transnoentities("SupplierOrderSentByEMail", $object->ref);
             $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         }
         // Parameters $object->sendotid defined by caller
         //$object->sendtoid=0;
         $ok = 1;
     } elseif ($action == 'BILL_SUPPLIER_VALIDATE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("other");
         $langs->load("bills");
         $langs->load("agenda");
         $object->actiontypecode = 'AC_OTH';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("InvoiceValidatedInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("InvoiceValidatedInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
         $ok = 1;
     } elseif ($action == 'BILL_SUPPLIER_SENTBYMAIL') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("other");
         $langs->load("bills");
         $langs->load("agenda");
         $langs->load("orders");
         $object->actiontypecode = 'AC_EMAIL';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("SupplierInvoiceSentByEMail", $object->ref);
         }
         if (empty($object->actionmsg)) {
             $object->actionmsg = $langs->transnoentities("SupplierInvoiceSentByEMail", $object->ref);
             $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         }
         // Parameters $object->sendtoid defined by caller
         //$object->sendtoid=0;
         $ok = 1;
     } elseif ($action == 'BILL_SUPPLIER_PAYED') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("other");
         $langs->load("bills");
         $langs->load("agenda");
         $object->actiontypecode = 'AC_OTH';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("InvoicePaidInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("InvoicePaidInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
         $ok = 1;
     } elseif ($action == 'BILL_SUPPLIER_CANCELED') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("other");
         $langs->load("bills");
         $langs->load("agenda");
         $object->actiontypecode = 'AC_OTH';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("InvoiceCanceledInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("InvoiceCanceledInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
         $ok = 1;
     } elseif ($action == 'MEMBER_VALIDATE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("other");
         $langs->load("members");
         $langs->load("agenda");
         $object->actiontypecode = 'AC_OTH';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("MemberValidatedInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("MemberValidatedInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Member") . ': ' . $object->getFullName($langs);
         $object->actionmsg .= "\n" . $langs->transnoentities("Type") . ': ' . $object->type;
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
         $ok = 1;
     } elseif ($action == 'MEMBER_SUBSCRIPTION') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("other");
         $langs->load("members");
         $langs->load("agenda");
         $object->actiontypecode = 'AC_OTH';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("MemberSubscriptionAddedInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("MemberSubscriptionAddedInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Member") . ': ' . $object->getFullName($langs);
         $object->actionmsg .= "\n" . $langs->transnoentities("Type") . ': ' . $object->type;
         $object->actionmsg .= "\n" . $langs->transnoentities("Amount") . ': ' . $object->last_subscription_amount;
         $object->actionmsg .= "\n" . $langs->transnoentities("Period") . ': ' . dol_print_date($object->last_subscription_date_start, 'day') . ' - ' . dol_print_date($object->last_subscription_date_end, 'day');
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
         $ok = 1;
     } elseif ($action == 'MEMBER_MODIFY') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
     } elseif ($action == 'MEMBER_RESILIATE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("other");
         $langs->load("members");
         $langs->load("agenda");
         $object->actiontypecode = 'AC_OTH';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("MemberResiliatedInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("MemberResiliatedInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Member") . ': ' . $object->getFullName($langs);
         $object->actionmsg .= "\n" . $langs->transnoentities("Type") . ': ' . $object->type;
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
         $ok = 1;
     } elseif ($action == 'MEMBER_DELETE') {
         dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id);
         $langs->load("other");
         $langs->load("members");
         $langs->load("agenda");
         $object->actiontypecode = 'AC_OTH';
         if (empty($object->actionmsg2)) {
             $object->actionmsg2 = $langs->transnoentities("MemberDeletedInDolibarr", $object->ref);
         }
         $object->actionmsg = $langs->transnoentities("MemberDeletedInDolibarr", $object->ref);
         $object->actionmsg .= "\n" . $langs->transnoentities("Member") . ': ' . $object->getFullName($langs);
         $object->actionmsg .= "\n" . $langs->transnoentities("Type") . ': ' . $object->type;
         $object->actionmsg .= "\n" . $langs->transnoentities("Author") . ': ' . $user->login;
         $object->sendtoid = 0;
         $ok = 1;
     }
     // If not found
     /*
     else
     {
         dol_syslog("Trigger '".$this->name."' for action '$action' was ran by ".__FILE__." but no handler found for this action.");
     			return 0;
     }
     */
     // Add entry in event table
     if ($ok) {
         $now = dol_now();
         require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php';
         require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
         $contactforaction = new Contact($this->db);
         $societeforaction = new Societe($this->db);
         if ($object->sendtoid > 0) {
             $contactforaction->fetch($object->sendtoid);
         }
         if ($object->socid > 0) {
             $societeforaction->fetch($object->socid);
         }
         // Insertion action
         require_once DOL_DOCUMENT_ROOT . '/comm/action/class/actioncomm.class.php';
         $actioncomm = new ActionComm($this->db);
         $actioncomm->type_code = $object->actiontypecode;
         $actioncomm->label = $object->actionmsg2;
         $actioncomm->note = $object->actionmsg;
         $actioncomm->datep = $now;
         $actioncomm->datef = $now;
         $actioncomm->durationp = 0;
         $actioncomm->punctual = 1;
         $actioncomm->percentage = -1;
         // Not applicable
         $actioncomm->contact = $contactforaction;
         $actioncomm->societe = $societeforaction;
         $actioncomm->author = $user;
         // User saving action
         //$actioncomm->usertodo  = $user;	// User affected to action
         $actioncomm->userdone = $user;
         // User doing action
         $actioncomm->fk_element = $object->id;
         $actioncomm->elementtype = $object->element;
         $ret = $actioncomm->add($user);
         // User qui saisit l'action
         if ($ret > 0) {
             return 1;
         } else {
             $error = "Failed to insert : " . $actioncomm->error . " ";
             $this->error = $error;
             dol_syslog("interface_modAgenda_ActionsAuto.class.php: " . $this->error, LOG_ERR);
             return -1;
         }
     }
     return 0;
 }
 /**
  *	Open output file
  *
  * 	@param		string		$file			File name to generate
  *  @param		Translate	$outputlangs	Output language object
  *	@return		int							<0 if KO, >=0 if OK
  */
 function open_file($file, $outputlangs)
 {
     global $user, $conf, $langs;
     if (!empty($conf->global->MAIN_USE_PHP_WRITEEXCEL)) {
         $outputlangs->charset_output = 'ISO-8859-1';
         // Because Excel 5 format is ISO
     }
     dol_syslog(get_class($this) . "::open_file file=" . $file);
     $this->file = $file;
     $ret = 1;
     $outputlangs->load("exports");
     if (!empty($conf->global->MAIN_USE_PHP_WRITEEXCEL)) {
         require_once PHP_WRITEEXCEL_PATH . 'class.writeexcel_workbookbig.inc.php';
         require_once PHP_WRITEEXCEL_PATH . 'class.writeexcel_worksheet.inc.php';
         require_once PHP_WRITEEXCEL_PATH . 'functions.writeexcel_utility.inc.php';
         $this->workbook = new writeexcel_workbookbig($file);
         $this->workbook->set_tempdir($conf->export->dir_temp);
         // Set temporary directory
         $this->workbook->set_sheetname($outputlangs->trans("Sheet"));
         $this->worksheet =& $this->workbook->addworksheet();
     } else {
         require_once PHPEXCEL_PATH . 'PHPExcel.php';
         require_once PHPEXCEL_PATH . 'PHPExcel/Style/Alignment.php';
         if ($this->id == 'excel2007') {
             if (!class_exists('ZipArchive')) {
                 $langs->load("errors");
                 $this->error = $langs->trans('ErrorPHPNeedModule', 'zip');
                 return -1;
             }
         }
         $this->workbook = new PHPExcel();
         $this->workbook->getProperties()->setCreator($user->getFullName($outputlangs) . ' - Dolibarr ' . DOL_VERSION);
         //$this->workbook->getProperties()->setLastModifiedBy('Dolibarr '.DOL_VERSION);
         $this->workbook->getProperties()->setTitle($outputlangs->trans("Export") . ' - ' . $file);
         $this->workbook->getProperties()->setSubject($outputlangs->trans("Export") . ' - ' . $file);
         $this->workbook->getProperties()->setDescription($outputlangs->trans("Export") . ' - ' . $file);
         $this->workbook->setActiveSheetIndex(0);
         $this->workbook->getActiveSheet()->setTitle($outputlangs->trans("Sheet"));
         $this->workbook->getActiveSheet()->getDefaultRowDimension()->setRowHeight(16);
     }
     return $ret;
 }
 /**
  *  Show top header of page.
  *
  *  @param	PDF			$pdf     		Object PDF
  *  @param  Object		$object     	Object to show
  *  @param  int	    	$showaddress    0=no, 1=yes
  *  @param  Translate	$outputlangs	Object lang for output
  *  @return	void
  */
 function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
 {
     global $conf, $langs, $hookmanager;
     $outputlangs->load("main");
     $outputlangs->load("trips");
     $outputlangs->load("companies");
     $default_font_size = pdf_getPDFFontSize($outputlangs);
     /*
     // ajout du fondu vert en bas de page à droite
     $image_fondue = $conf->mycompany->dir_output.'/fondu_vert_.jpg';
     $pdf->Image($image_fondue,20,107,200,190);
     
     pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
     */
     // Draft watermark
     if ($object->fk_statut == 1 && !empty($conf->global->EXPENSEREPORT_FREE_TEXT)) {
         pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', $conf->global->EXPENSEREPORT_FREE_TEXT);
     }
     $pdf->SetTextColor(0, 0, 60);
     $pdf->SetFont('', 'B', $default_font_size + 3);
     $posy = $this->marge_haute;
     $posx = $this->page_largeur - $this->marge_droite - 100;
     $pdf->SetXY($this->marge_gauche, $posy);
     // Logo
     $logo = $conf->mycompany->dir_output . '/logos/' . $this->emetteur->logo;
     if ($this->emetteur->logo) {
         if (is_readable($logo)) {
             $height = pdf_getHeightForLogo($logo);
             $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
             // width=0 (auto)
         } else {
             $pdf->SetTextColor(200, 0, 0);
             $pdf->SetFont('', 'B', $default_font_size - 2);
             $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
             $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
         }
     } else {
         $text = $this->emetteur->name;
         $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
     }
     $pdf->SetFont('', 'B', $default_font_size + 4);
     $pdf->SetXY($posx, $posy);
     $pdf->SetTextColor(0, 0, 60);
     $pdf->MultiCell($this->page_largeur - $this->marge_droite - $posx, 6, $langs->trans("ExpenseReport"), 0, 'L');
     $pdf->SetFont('', '', $default_font_size - 1);
     // Ref complete
     $posy += 8;
     $pdf->SetXY($posx, $posy);
     $pdf->SetTextColor(0, 0, 60);
     $pdf->MultiCell($this->page_largeur - $this->marge_droite - $posx, 3, $outputlangs->transnoentities("Ref") . " : " . $object->ref, '', 'L');
     // Date start period
     $posy += 5;
     $pdf->SetXY($posx, $posy);
     $pdf->SetTextColor(0, 0, 60);
     $pdf->MultiCell($this->page_largeur - $this->marge_droite - $posx, 3, $outputlangs->transnoentities("DateStart") . " : " . ($object->date_debut > 0 ? dol_print_date($object->date_debut, "day", false, $outpulangs) : ''), '', 'L');
     // Date end period
     $posy += 5;
     $pdf->SetXY($posx, $posy);
     $pdf->SetTextColor(0, 0, 60);
     $pdf->MultiCell($this->page_largeur - $this->marge_droite - $posx, 3, $outputlangs->transnoentities("DateEnd") . " : " . ($object->date_fin > 0 ? dol_print_date($object->date_fin, "day", false, $outpulangs) : ''), '', 'L');
     // Status Expense Report
     $posy += 6;
     $pdf->SetXY($posx, $posy);
     $pdf->SetFont('', 'B', 18);
     $pdf->SetTextColor(111, 81, 124);
     $pdf->MultiCell($this->page_largeur - $this->marge_droite - $posx, 3, $object->getLibStatut(0), '', 'R');
     // Sender properties
     $carac_emetteur = '';
     $carac_emetteur .= ($carac_emetteur ? "\n" : '') . $outputlangs->convToOutputCharset($this->emetteur->address);
     $carac_emetteur .= ($carac_emetteur ? "\n" : '') . $outputlangs->convToOutputCharset($this->emetteur->zip) . ' ' . $outputlangs->convToOutputCharset($this->emetteur->town);
     $carac_emetteur .= "\n";
     // Phone
     if ($this->emetteur->phone) {
         $carac_emetteur .= ($carac_emetteur ? "\n" : '') . $outputlangs->transnoentities("Phone") . " : " . $outputlangs->convToOutputCharset($this->emetteur->phone);
     }
     // Fax
     if ($this->emetteur->fax) {
         $carac_emetteur .= ($carac_emetteur ? $this->emetteur->tel ? " - " : "\n" : '') . $outputlangs->transnoentities("Fax") . " : " . $outputlangs->convToOutputCharset($this->emetteur->fax);
     }
     // EMail
     if ($this->emetteur->email) {
         $carac_emetteur .= ($carac_emetteur ? "\n" : '') . $outputlangs->transnoentities("Email") . " : " . $outputlangs->convToOutputCharset($this->emetteur->email);
     }
     // Web
     if ($this->emetteur->url) {
         $carac_emetteur .= ($carac_emetteur ? "\n" : '') . $outputlangs->transnoentities("Web") . " : " . $outputlangs->convToOutputCharset($this->emetteur->url);
     }
     // Show sender
     $posy = 50;
     $posx = $this->marge_gauche;
     $hautcadre = 40;
     if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
         $posx = 118;
     }
     // Show sender frame
     $pdf->SetTextColor(0, 0, 0);
     $pdf->SetFont('', 'B', $default_font_size - 2);
     $pdf->SetXY($posx, $posy - 5);
     $pdf->MultiCell(66, 5, $outputlangs->transnoentities("TripSociete") . " :", '', 'L');
     $pdf->SetXY($posx, $posy);
     $pdf->SetFillColor(224, 224, 224);
     $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
     $pdf->SetTextColor(0, 0, 60);
     // Show sender name
     $pdf->SetXY($posx + 2, $posy + 3);
     $pdf->SetFont('', 'B', $default_font_size);
     $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
     // Show sender information
     $pdf->SetXY($posx + 2, $posy + 8);
     $pdf->SetFont('', '', $default_font_size - 1);
     $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
     // Show recipient
     $posy = 50;
     $posx = 100;
     // Show recipient frame
     $pdf->SetTextColor(0, 0, 0);
     $pdf->SetFont('', 'B', 8);
     $pdf->SetXY($posx, $posy - 5);
     $pdf->MultiCell(80, 5, $outputlangs->transnoentities("TripNDF") . " :", 0, 'L');
     $pdf->rect($posx, $posy, $this->page_largeur - $this->marge_gauche - $posx, $hautcadre);
     // Informations for trip (dates and users workflow)
     if ($object->fk_user_author > 0) {
         $userfee = new User($this->db);
         $userfee->fetch($object->fk_user_author);
         $posy += 3;
         $pdf->SetXY($posx + 2, $posy);
         $pdf->SetFont('', '', 10);
         $pdf->MultiCell(96, 4, $outputlangs->transnoentities("AUTHOR") . " : " . dolGetFirstLastname($userfee->firstname, $userfee->lastname), 0, 'L');
         $posy += 5;
         $pdf->SetXY($posx + 2, $posy);
         $pdf->MultiCell(96, 4, $outputlangs->transnoentities("DateCreation") . " : " . dol_print_date($object->date_create, "day", false, $outpulangs), 0, 'L');
     }
     if ($object->fk_statut == 99) {
         if ($object->fk_user_refuse > 0) {
             $userfee = new User($this->db);
             $userfee->fetch($object->fk_user_refuse);
             $posy += 6;
             $pdf->SetXY($posx + 2, $posy);
             $pdf->MultiCell(96, 4, $outputlangs->transnoentities("REFUSEUR") . " : " . dolGetFirstLastname($userfee->firstname, $userfee->lastname), 0, 'L');
             $posy += 5;
             $pdf->SetXY($posx + 2, $posy);
             $pdf->MultiCell(96, 4, $outputlangs->transnoentities("MOTIF_REFUS") . " : " . $outputlangs->convToOutputCharset($object->detail_refuse), 0, 'L');
             $posy += 5;
             $pdf->SetXY($posx + 2, $posy);
             $pdf->MultiCell(96, 4, $outputlangs->transnoentities("DATE_REFUS") . " : " . dol_print_date($object->date_refuse, "day", false, $outpulangs), 0, 'L');
         }
     } else {
         if ($object->fk_statut == 4) {
             if ($object->fk_user_cancel > 0) {
                 $userfee = new User($this->db);
                 $userfee->fetch($object->fk_user_cancel);
                 $posy += 6;
                 $pdf->SetXY($posx + 2, $posy);
                 $pdf->MultiCell(96, 4, $outputlangs->transnoentities("CANCEL_USER") . " : " . dolGetFirstLastname($userfee->firstname, $userfee->lastname), 0, 'L');
                 $posy += 5;
                 $pdf->SetXY($posx + 2, $posy);
                 $pdf->MultiCell(96, 4, $outputlangs->transnoentities("MOTIF_CANCEL") . " : " . $outputlangs->convToOutputCharset($object->detail_cancel), 0, 'L');
                 $posy += 5;
                 $pdf->SetXY($posx + 2, $posy);
                 $pdf->MultiCell(96, 4, $outputlangs->transnoentities("DATE_CANCEL") . " : " . dol_print_date($object->date_cancel, "day", false, $outpulangs), 0, 'L');
             }
         } else {
             if ($object->fk_user_approve > 0) {
                 $userfee = new User($this->db);
                 $userfee->fetch($object->fk_user_approve);
                 $posy += 6;
                 $pdf->SetXY($posx + 2, $posy);
                 $pdf->MultiCell(96, 4, $outputlangs->transnoentities("VALIDOR") . " : " . dolGetFirstLastname($userfee->firstname, $userfee->lastname), 0, 'L');
                 $posy += 5;
                 $pdf->SetXY($posx + 2, $posy);
                 $pdf->MultiCell(96, 4, $outputlangs->transnoentities("DateApprove") . " : " . dol_print_date($object->date_approve, "day", false, $outpulangs), 0, 'L');
             }
         }
     }
     if ($object->fk_statut == 6) {
         if ($object->fk_user_paid > 0) {
             $userfee = new User($this->db);
             $userfee->fetch($object->fk_user_paid);
             $posy += 6;
             $pdf->SetXY($posx + 2, $posy);
             $pdf->MultiCell(96, 4, $outputlangs->transnoentities("AUTHORPAIEMENT") . " : " . dolGetFirstLastname($userfee->firstname, $userfee->lastname), 0, 'L');
             $posy += 5;
             $pdf->SetXY($posx + 2, $posy);
             $pdf->MultiCell(96, 4, $outputlangs->transnoentities("DATE_PAIEMENT") . " : " . dol_print_date($object->date_paiement, "day", false, $outpulangs), 0, 'L');
         }
     }
 }
 /**
  *	Open output file
  *
  *	@param		string		$file			Path of filename to generate
  * 	@param		Translate	$outputlangs	Output language object
  *	@return		int							<0 if KO, >=0 if OK
  */
 function open_file($file, $outputlangs)
 {
     global $langs;
     dol_syslog("ExportCsv::open_file file=" . $file);
     $ret = 1;
     $outputlangs->load("exports");
     $this->handle = fopen($file, "wt");
     if (!$this->handle) {
         $langs->load("errors");
         $this->error = $langs->trans("ErrorFailToCreateFile", $file);
         $ret = -1;
     }
     return $ret;
 }
 /**
  *  Show top header of page.
  *
  *  @param	PDF			$pdf     		Object PDF
  *  @param  Object		$object     	Object to show
  *  @param  int	    	$showaddress    0=no, 1=yes
  *  @param  Translate	$outputlangs	Object lang for output
  *  @return	void
  */
 function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
 {
     global $conf, $langs;
     $outputlangs->load("main");
     $outputlangs->load("bills");
     $outputlangs->load("propal");
     $outputlangs->load("companies");
     $default_font_size = pdf_getPDFFontSize($outputlangs);
     pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
     // Show Draft Watermark
     if ($object->statut == 0 && !empty($conf->global->FACTURE_DRAFT_WATERMARK)) {
         pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', $conf->global->FACTURE_DRAFT_WATERMARK);
     }
     $pdf->SetTextColor(0, 0, 60);
     $pdf->SetFont('', 'B', $default_font_size + 3);
     $w = 110;
     $posy = $this->marge_haute;
     $posx = $this->page_largeur - $this->marge_droite - $w;
     $pdf->SetXY($this->marge_gauche, $posy);
     // Logo
     $logo = $conf->mycompany->dir_output . '/logos/' . $this->emetteur->logo;
     if ($this->emetteur->logo) {
         if (is_readable($logo)) {
             $height = pdf_getHeightForLogo($logo);
             $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
             // width=0 (auto)
         } else {
             $pdf->SetTextColor(200, 0, 0);
             $pdf->SetFont('', 'B', $default_font_size - 2);
             $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
             $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
         }
     } else {
         $text = $this->emetteur->name;
         $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
     }
     $pdf->SetFont('', 'B', $default_font_size + 3);
     $pdf->SetXY($posx, $posy);
     $pdf->SetTextColor(0, 0, 60);
     $title = $outputlangs->transnoentities("Invoice");
     if ($object->type == 1) {
         $title = $outputlangs->transnoentities("InvoiceReplacement");
     }
     if ($object->type == 2) {
         $title = $outputlangs->transnoentities("InvoiceAvoir");
     }
     if ($object->type == 3) {
         $title = $outputlangs->transnoentities("InvoiceDeposit");
     }
     if ($object->type == 4) {
         $title = $outputlangs->transnoentities("InvoiceProFormat");
     }
     $pdf->MultiCell($w, 3, $title, '', 'R');
     $pdf->SetFont('', 'B', $default_font_size);
     $posy += 5;
     $pdf->SetXY($posx, $posy);
     $pdf->SetTextColor(0, 0, 60);
     $pdf->MultiCell($w, 4, $outputlangs->transnoentities("Ref") . " : " . $outputlangs->convToOutputCharset($object->ref), '', 'R');
     $posy += 1;
     $pdf->SetFont('', '', $default_font_size - 2);
     if ($object->ref_client) {
         $posy += 4;
         $pdf->SetXY($posx, $posy);
         $pdf->SetTextColor(0, 0, 60);
         $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefCustomer") . " : " . $outputlangs->convToOutputCharset($object->ref_client), '', 'R');
     }
     $objectidnext = $object->getIdReplacingInvoice('validated');
     if ($object->type == 0 && $objectidnext) {
         $objectreplacing = new Facture($this->db);
         $objectreplacing->fetch($objectidnext);
         $posy += 3;
         $pdf->SetXY($posx, $posy);
         $pdf->SetTextColor(0, 0, 60);
         $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementByInvoice") . ' : ' . $outputlangs->convToOutputCharset($objectreplacing->ref), '', 'R');
     }
     if ($object->type == 1) {
         $objectreplaced = new Facture($this->db);
         $objectreplaced->fetch($object->fk_facture_source);
         $posy += 4;
         $pdf->SetXY($posx, $posy);
         $pdf->SetTextColor(0, 0, 60);
         $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementInvoice") . ' : ' . $outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
     }
     if ($object->type == 2 && !empty($object->fk_facture_source)) {
         $objectreplaced = new Facture($this->db);
         $objectreplaced->fetch($object->fk_facture_source);
         $posy += 3;
         $pdf->SetXY($posx, $posy);
         $pdf->SetTextColor(0, 0, 60);
         $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CorrectionInvoice") . ' : ' . $outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
     }
     $posy += 4;
     $pdf->SetXY($posx, $posy);
     $pdf->SetTextColor(0, 0, 60);
     $pdf->MultiCell($w, 3, $outputlangs->transnoentities("DateInvoice") . " : " . dol_print_date($object->date, "day", false, $outputlangs), '', 'R');
     if ($object->type != 2) {
         $posy += 3;
         $pdf->SetXY($posx, $posy);
         $pdf->SetTextColor(0, 0, 60);
         $pdf->MultiCell($w, 3, $outputlangs->transnoentities("DateEcheance") . " : " . dol_print_date($object->date_lim_reglement, "day", false, $outputlangs, true), '', 'R');
     }
     if ($object->thirdparty->code_client) {
         $posy += 3;
         $pdf->SetXY($posx, $posy);
         $pdf->SetTextColor(0, 0, 60);
         $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode") . " : " . $outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
     }
     $posy += 1;
     // Show list of linked objects
     $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3, 'R', $default_font_size);
     if ($showaddress) {
         // Sender properties
         $carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->client);
         // Show sender
         $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
         $posx = $this->marge_gauche;
         if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
             $posx = $this->page_largeur - $this->marge_droite - 80;
         }
         $hautcadre = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
         $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
         // Show sender frame
         $pdf->SetTextColor(0, 0, 0);
         $pdf->SetFont('', '', $default_font_size - 2);
         $pdf->SetXY($posx, $posy - 5);
         $pdf->MultiCell(66, 5, $outputlangs->transnoentities("BillFrom") . ":", 0, 'L');
         $pdf->SetXY($posx, $posy);
         $pdf->SetFillColor(230, 230, 230);
         $pdf->MultiCell($widthrecbox, $hautcadre, "", 0, 'R', 1);
         $pdf->SetTextColor(0, 0, 60);
         // Show sender name
         $pdf->SetXY($posx + 2, $posy + 3);
         $pdf->SetFont('', 'B', $default_font_size);
         $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
         $posy = $pdf->getY();
         // Show sender information
         $pdf->SetXY($posx + 2, $posy);
         $pdf->SetFont('', '', $default_font_size - 1);
         $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, 'L');
         // If BILLING contact defined on invoice, we use it
         $usecontact = false;
         $arrayidcontact = $object->getIdContact('external', 'BILLING');
         if (count($arrayidcontact) > 0) {
             $usecontact = true;
             $result = $object->fetch_contact($arrayidcontact[0]);
         }
         //Recipient name
         // On peut utiliser le nom de la societe du contact
         if ($usecontact && !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) {
             $thirdparty = $object->contact;
         } else {
             $thirdparty = $object->client;
         }
         $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
         $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->client, $usecontact ? $object->contact : '', $usecontact, 'target');
         // Show recipient
         $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
         if ($this->page_largeur < 210) {
             $widthrecbox = 84;
         }
         // To work with US executive format
         $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
         $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
         if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
             $posx = $this->marge_gauche;
         }
         // Show recipient frame
         $pdf->SetTextColor(0, 0, 0);
         $pdf->SetFont('', '', $default_font_size - 2);
         $pdf->SetXY($posx + 2, $posy - 5);
         $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo") . ":", 0, 'L');
         $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
         // Show recipient name
         $pdf->SetXY($posx + 2, $posy + 3);
         $pdf->SetFont('', 'B', $default_font_size);
         $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, 'L');
         $posy = $pdf->getY();
         // Show recipient information
         $pdf->SetFont('', '', $default_font_size - 1);
         $pdf->SetXY($posx + 2, $posy);
         $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
     }
     $pdf->SetTextColor(0, 0, 0);
 }
/**
 * 	Send email
 *
 * 	@param	string	$mode					Mode (test | confirm)
 *  @param	string	$oldemail				Old email
 * 	@param	string	$message				Message to send
 * 	@param	string	$total					Total amount of unpayed invoices
 *  @param	string	$userlang				Code lang to use for email output.
 *  @param	string	$oldsalerepresentative	Old sale representative
 * 	@return	int								<0 if KO, >0 if OK
 */
function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldsalerepresentative)
{
    global $conf, $langs;
    if (getenv('DOL_FORCE_EMAIL_TO')) {
        $oldemail = getenv('DOL_FORCE_EMAIL_TO');
    }
    $newlangs = new Translate('', $conf);
    $newlangs->setDefaultLang(empty($userlang) ? empty($conf->global->MAIN_LANG_DEFAULT) ? 'auto' : $conf->global->MAIN_LANG_DEFAULT : $userlang);
    $newlangs->load("main");
    $newlangs->load("bills");
    $subject = empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_SUBJECT) ? $newlangs->trans("ListOfYourUnpaidInvoices") : $conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_SUBJECT;
    $sendto = $oldemail;
    $from = $conf->global->MAIN_MAIL_EMAIL_FROM;
    $errorsto = $conf->global->MAIN_MAIL_ERRORS_TO;
    $msgishtml = -1;
    print "- Send email for " . $oldsalerepresentative . " (" . $oldemail . "), total: " . $total . "\n";
    dol_syslog("email_unpaid_invoices_to_representatives.php: send mail to " . $oldemail);
    $usehtml = 0;
    if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER)) {
        $usehtml += 1;
    }
    if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER)) {
        $usehtml += 1;
    }
    $allmessage = '';
    if (!empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER)) {
        $allmessage .= $conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_HEADER;
    } else {
        $allmessage .= $newlangs->transnoentities("ListOfYourUnpaidInvoices") . ($usehtml ? "<br>\n" : "\n") . ($usehtml ? "<br>\n" : "\n");
        $allmessage .= $newlangs->transnoentities("NoteListOfYourUnpaidInvoices") . ($usehtml ? "<br>\n" : "\n");
    }
    $allmessage .= $message . ($usehtml ? "<br>\n" : "\n");
    $allmessage .= $langs->trans("Total") . " = " . price($total, 0, $newlangs, 0, 0, -1, $conf->currency) . ($usehtml ? "<br>\n" : "\n");
    if (!empty($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER)) {
        $allmessage .= $conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER;
        if (dol_textishtml($conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_SALESREPRESENTATIVES_FOOTER)) {
            $usehtml += 1;
        }
    }
    $mail = new CMailFile($subject, $sendto, $from, $allmessage, array(), array(), array(), '', '', 0, $msgishtml);
    $mail->errors_to = $errorsto;
    // Send or not email
    if ($mode == 'confirm') {
        $result = $mail->sendfile();
        if (!$result) {
            print "Error sending email " . $mail->error . "\n";
            dol_syslog("Error sending email " . $mail->error . "\n");
        }
    } else {
        print "No email sent (test mode)\n";
        dol_syslog("No email sent (test mode)");
        $mail->dump_mail();
        $result = 1;
    }
    if ($result) {
        return 1;
    } else {
        return -1;
    }
}