Exemplo n.º 1
0
 /**
  *	Constructor
  *
  *  @param		DoliDB		$db      Database handler
  */
 function __construct($db)
 {
     $this->db = $db;
     parent::__construct($db);
     try {
         //$this->fk_extrafields = $this->couchdb->getDoc("extrafields:".  get_class($this)); // load fields company
         $this->fk_status = $this->couchdb->getDoc("status:Societe");
         //load status table
         //$this->fk_country = $this->couchdb->getDoc("dict:country"); //load country table
     } catch (Exception $e) {
         $error = "Something weird happened: " . $e->getMessage() . " (errcode=" . $e->getCode() . ")\n";
         print $error;
         exit;
     }
 }
Exemplo n.º 2
0
 /**
  * Function used to replace a thirdparty id with another one.
  *
  * @param DoliDB $db Database handler
  * @param int $origin_id Old thirdparty id
  * @param int $dest_id New thirdparty id
  * @return bool
  */
 public static function replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
 {
     $tables = array('facture');
     return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
 }
Exemplo n.º 3
0
 /**
  * Function used to replace a thirdparty id with another one.
  *
  * @param DoliDB 	$db 			Database handler
  * @param int 		$origin_id 		Old thirdparty id
  * @param int 		$dest_id 		New thirdparty id
  * @return bool
  */
 public static function replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
 {
     $tables = array('product_customer_price', 'product_customer_price_log');
     return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
 }
 /**
  *  Function to build pdf onto disk
  *
  *  @param		CommonObject	$object				Id of object to generate
  *  @param		object			$outputlangs		Lang output object
  *  @param		string			$srctemplatepath	Full path of source filename for generator using a template file
  *  @param		int				$hidedetails		Do not show line details
  *  @param		int				$hidedesc			Do not show desc
  *  @param		int				$hideref			Do not show ref
  *  @return		int									1=OK, 0=KO
  */
 function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
 {
     global $user, $langs, $conf, $mysoc;
     if (!is_object($outputlangs)) {
         $outputlangs = $langs;
     }
     // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
     if (!empty($conf->global->MAIN_USE_FPDF)) {
         $outputlangs->charset_output = 'ISO-8859-1';
     }
     $outputlangs->load("main");
     $outputlangs->load("dict");
     $outputlangs->load("companies");
     $outputlangs->load("contracts");
     if ($conf->contrat->dir_output) {
         $object->fetch_thirdparty();
         // Definition of $dir and $file
         if ($object->specimen) {
             $dir = $conf->contrat->dir_output;
             $file = $dir . "/SPECIMEN.pdf";
         } else {
             $objectref = dol_sanitizeFileName($object->ref);
             $dir = $conf->contrat->dir_output . "/" . $objectref;
             $file = $dir . "/" . $objectref . ".pdf";
         }
         if (!file_exists($dir)) {
             if (dol_mkdir($dir) < 0) {
                 $this->error = $outputlangs->trans("ErrorCanNotCreateDir", $dir);
                 return 0;
             }
         }
         if (file_exists($dir)) {
             $pdf = pdf_getInstance($this->format);
             $default_font_size = pdf_getPDFFontSize($outputlangs);
             // Must be after pdf_getInstance
             $heightforinfotot = 50;
             // Height reserved to output the info and total part
             $heightforfreetext = isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5;
             // Height reserved to output the free text on last page
             $heightforfooter = $this->marge_basse + 8;
             // Height reserved to output the footer (value include bottom margin)
             $pdf->SetAutoPageBreak(1, 0);
             if (class_exists('TCPDF')) {
                 $pdf->setPrintHeader(false);
                 $pdf->setPrintFooter(false);
             }
             $pdf->SetFont(pdf_getPDFFont($outputlangs));
             // Set path to the background PDF File
             if (empty($conf->global->MAIN_DISABLE_FPDI) && !empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
                 $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output . '/' . $conf->global->MAIN_ADD_PDF_BACKGROUND);
                 $tplidx = $pdf->importPage(1);
             }
             $pdf->Open();
             $pagenb = 0;
             $pdf->SetDrawColor(128, 128, 128);
             $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
             $pdf->SetSubject($outputlangs->transnoentities("ContractCard"));
             $pdf->SetCreator("Dolibarr " . DOL_VERSION);
             $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
             $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref) . " " . $outputlangs->transnoentities("ContractCard"));
             if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) {
                 $pdf->SetCompression(false);
             }
             $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
             // Left, Top, Right
             // New page
             $pdf->AddPage();
             if (!empty($tplidx)) {
                 $pdf->useTemplate($tplidx);
             }
             $pagenb++;
             $this->_pagehead($pdf, $object, 1, $outputlangs);
             $pdf->SetFont('', '', $default_font_size - 1);
             $pdf->MultiCell(0, 3, '');
             // Set interline to 3
             $pdf->SetTextColor(0, 0, 0);
             $tab_top = 90;
             $tab_top_newpage = empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 : 10;
             $tab_height = 130;
             $tab_height_newpage = 150;
             // Affiche notes
             if (!empty($object->note_public)) {
                 $tab_top = 88;
                 $pdf->SetFont('', '', $default_font_size - 1);
                 $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($object->note_public), 0, 1);
                 $nexY = $pdf->GetY();
                 $height_note = $nexY - $tab_top;
                 // Rect prend une longueur en 3eme param
                 $pdf->SetDrawColor(192, 192, 192);
                 $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1);
                 $tab_height = $tab_height - $height_note;
                 $tab_top = $nexY + 6;
             } else {
                 $height_note = 0;
             }
             $iniY = $tab_top + 7;
             $curY = $tab_top + 7;
             $nexY = $tab_top + 7;
             $pdf->SetXY($this->marge_gauche, $tab_top);
             $pdf->MultiCell(190, 8, $outputlangs->transnoentities("Description"), 0, 'L', 0);
             $pdf->line($this->marge_gauche, $tab_top + 8, $this->page_largeur - $this->marge_droite, $tab_top + 8);
             $pdf->SetFont('', '', $default_font_size - 1);
             $pdf->MultiCell(0, 3, '');
             // Set interline to 3
             $pdf->SetXY($this->marge_gauche, $tab_top + 8);
             $text = $object->description;
             if ($object->duree > 0) {
                 $totaltime = convertSecondToTime($object->duree, 'all', $conf->global->MAIN_DURATION_OF_WORKDAY);
                 $text .= ($text ? ' - ' : '') . $langs->trans("Total") . ": " . $totaltime;
             }
             $desc = dol_htmlentitiesbr($text, 1);
             //print $outputlangs->convToOutputCharset($desc); exit;
             $pdf->writeHTMLCell(180, 3, 10, $tab_top + 8, $outputlangs->convToOutputCharset($desc), 0, 1);
             $nexY = $pdf->GetY();
             $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
             $pdf->MultiCell(0, 2, '');
             // Set interline to 3. Then writeMultiCell must use 3 also.
             $nblines = count($object->lines);
             // Loop on each lines
             for ($i = 0; $i < $nblines; $i++) {
                 $objectligne = $object->lines[$i];
                 $valide = $objectligne->id ? $objectligne->fetch($objectligne->id) : 0;
                 if ($valide > 0 || $object->specimen) {
                     $curX = $this->posxdesc - 1;
                     $curY = $nexY;
                     $pdf->SetFont('', '', $default_font_size - 1);
                     // Into loop to work with multipage
                     $pdf->SetTextColor(0, 0, 0);
                     $pdf->setTopMargin($tab_top_newpage);
                     $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot);
                     // The only function to edit the bottom margin of current page to set it.
                     $pageposbefore = $pdf->getPage();
                     // Description of product line
                     $txt = '<strong>' . dol_htmlentitiesbr($outputlangs->transnoentities("Date") . " : " . dol_print_date($objectligne->datei, 'dayhour', false, $outputlangs, true) . " - " . $outputlangs->transnoentities("Duration") . " : " . convertSecondToTime($objectligne->duration), 1, $outputlangs->charset_output) . '</strong>';
                     $desc = dol_htmlentitiesbr($objectligne->desc, 1);
                     $pdf->writeHTMLCell(0, 0, $curX, $curY, dol_concatdesc($txt, $desc), 0, 1, 0);
                     $nexY = $pdf->GetY();
                     $pageposafter = $pdf->getPage();
                     $pdf->setPage($pageposbefore);
                     $pdf->setTopMargin($this->marge_haute);
                     $pdf->setPageOrientation('', 1, 0);
                     // The only function to edit the bottom margin of current page to set it.
                     // We suppose that a too long description is moved completely on next page
                     if ($pageposafter > $pageposbefore) {
                         $pdf->setPage($pageposafter);
                         $curY = $tab_top_newpage;
                     }
                     $pdf->SetFont('', '', $default_font_size - 1);
                     // On repositionne la police par defaut
                     // Detect if some page were added automatically and output _tableau for past pages
                     while ($pagenb < $pageposafter) {
                         $pdf->setPage($pagenb);
                         if ($pagenb == 1) {
                             $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
                         } else {
                             $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
                         }
                         $this->_pagefoot($pdf, $object, $outputlangs, 1);
                         $pagenb++;
                         $pdf->setPage($pagenb);
                         $pdf->setPageOrientation('', 1, 0);
                         // The only function to edit the bottom margin of current page to set it.
                     }
                     if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
                         if ($pagenb == 1) {
                             $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
                         } else {
                             $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
                         }
                         $this->_pagefoot($pdf, $object, $outputlangs, 1);
                         // New page
                         $pdf->AddPage();
                         if (!empty($tplidx)) {
                             $pdf->useTemplate($tplidx);
                         }
                         $pagenb++;
                     }
                 }
             }
             // Show square
             if ($pagenb == 1) {
                 $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
                 $bottomlasttab = $this->page_hauteur - $heightforfooter - $heightforfooter + 1;
             } else {
                 $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
                 $bottomlasttab = $this->page_hauteur - $heightforfooter - $heightforfooter + 1;
             }
             $this->_pagefoot($pdf, $object, $outputlangs);
             if (method_exists($pdf, 'AliasNbPages')) {
                 $pdf->AliasNbPages();
             }
             $pdf->Close();
             $pdf->Output($file, 'F');
             if (!empty($conf->global->MAIN_UMASK)) {
                 @chmod($file, octdec($conf->global->MAIN_UMASK));
             }
             return 1;
         } else {
             $this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
             return 0;
         }
     } else {
         $this->error = $langs->trans("ErrorConstantNotDefined", "CONTRACT_OUTPUTDIR");
         return 0;
     }
     $this->error = $langs->trans("ErrorUnknown");
     return 0;
     // Erreur par defaut
 }
 /**
  *  Show top header of page.
  *
  *  @param	PDF			$pdf     		Object PDF
  *  @param  CommonObject		$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;
     $default_font_size = pdf_getPDFFontSize($outputlangs);
     $outputlangs->load("main");
     $outputlangs->load("dict");
     $outputlangs->load("companies");
     $outputlangs->load("contract");
     pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
     //Affiche le filigrane brouillon - Print Draft Watermark
     if ($object->statut == 0 && !empty($conf->global->CONTRACT_DRAFT_WATERMARK)) {
         pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', $conf->global->CONTRACT_DRAFT_WATERMARK);
     }
     //Prepare la suite
     $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/' . $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("ContractCard");
     $pdf->MultiCell(100, 4, $title, '', 'R');
     $pdf->SetFont('', 'B', $default_font_size + 2);
     $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);
     $posy += 4;
     $pdf->SetXY($posx, $posy);
     $pdf->SetTextColor(0, 0, 60);
     $pdf->MultiCell(100, 3, $outputlangs->transnoentities("Date") . " : " . dol_print_date($object->date_creation, "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');
     }
     if ($showaddress) {
         // Sender properties
         $carac_emetteur = '';
         // Add internal contact of proposal if defined
         $arrayidcontact = $object->getIdContact('internal', 'INTERREPFOLL');
         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, $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->SetXY($posx, $posy);
         $pdf->SetFillColor(230, 230, 230);
         $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
         // Show sender name
         $pdf->SetXY($posx + 2, $posy + 3);
         $pdf->SetTextColor(0, 0, 60);
         $pdf->SetFont('', 'B', $default_font_size);
         $pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
         $posy = $pdf->getY();
         // Show sender information
         $pdf->SetFont('', '', $default_font_size - 1);
         $pdf->SetXY($posx + 2, $posy);
         $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]);
         }
         $this->recipient = $object->client;
         //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;
         }
         $this->recipient->name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
         $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->client, isset($object->contact) ? $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->Rect($posx, $posy, $widthrecbox, $hautcadre);
         $pdf->SetTextColor(0, 0, 0);
         // Show recipient name
         $pdf->SetXY($posx + 2, $posy + 3);
         $pdf->SetFont('', 'B', $default_font_size);
         $pdf->MultiCell($widthrecbox, 4, $this->recipient->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');
     }
 }
Exemplo n.º 6
0
 /**
  *    Copy contact from one element to current
  *
  *    @param    CommonObject    $objFrom    Source element
  *    @param    string          $source     Nature of contact ('internal' or 'external')
  *    @return   int                         >0 if OK, <0 if KO
  */
 function copy_linked_contact($objFrom, $source = 'internal')
 {
     $contacts = $objFrom->liste_contact(-1, $source);
     foreach ($contacts as $contact) {
         if ($this->add_contact($contact['id'], $contact['fk_c_type_contact'], $contact['source']) < 0) {
             $this->error = $this->db->lasterror();
             return -1;
         }
     }
     return 1;
 }
Exemplo n.º 7
0
	/**
	 * Function used to replace a thirdparty id with another one.
	 * It must be used within a transaction to avoid trouble
	 *
	 * @param DoliDB $db Database handler
	 * @param int $origin_id Old thirdparty id
	 * @param int $dest_id New thirdparty id
	 * @return bool
	 */
	public static function replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
	{
		/**
		 * Thirdparty commercials cannot be the same in both thirdparties so we look for them and remove some
		 * Because this function is meant to be executed within a transaction, we won't take care of it.
		 */
		$sql = 'SELECT rowid
FROM llx_societe_commerciaux
WHERE fk_soc = '.(int) $dest_id.' AND fk_user IN (
  SELECT fk_user
  FROM llx_societe_commerciaux
  WHERE fk_soc = '.(int) $origin_id.'
);';

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

		while ($result = $db->fetch_object($query)) {
			$db->query('DELETE FROM llx_societe_commerciaux WHERE rowid = '.$result->rowid);
		}

		/**
		 * llx_societe_extrafields table must not be here because we don't care about the old thirdparty data
		 * Do not include llx_societe because it will be replaced later
		 */
		$tables = array(
			'societe_address',
			'societe_commerciaux',
			'societe_log',
			'societe_prices',
			'societe_remise',
			'societe_remise_except',
			'societe_rib'
		);

		return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
	}
Exemplo n.º 8
0
/**
 *	Create a meta file with document file into same directory.
 *	This should allow "grep" search.
 *  This feature is enabled only if option MAIN_DOC_CREATE_METAFILE is set.
 *
 *	@param	CommonObject	$object		Object
 *	@return	int					0 if we did nothing, >0 success, <0 error
 */
function dol_meta_create($object)
{
    global $conf;
    if (empty($conf->global->MAIN_DOC_CREATE_METAFILE)) {
        return 0;
    }
    // By default, no metafile.
    // Define parent dir of elements
    $element = $object->element;
    if ($object->element == 'order_supplier') {
        $dir = $conf->fournisseur->dir_output . '/commande';
    } elseif ($object->element == 'invoice_supplier') {
        $dir = $conf->fournisseur->dir_output . '/facture';
    } elseif ($object->element == 'project') {
        $dir = $conf->projet->dir_output;
    } elseif ($object->element == 'shipping') {
        $dir = $conf->expedition->dir_output . '/sending';
    } elseif ($object->element == 'delivery') {
        $dir = $conf->expedition->dir_output . '/receipt';
    } elseif ($object->element == 'fichinter') {
        $dir = $conf->ficheinter->dir_output;
    } else {
        $dir = empty($conf->{$element}->dir_output) ? '' : $conf->{$element}->dir_output;
    }
    if ($dir) {
        $object->fetch_thirdparty();
        $facref = dol_sanitizeFileName($object->ref);
        $dir = $dir . "/" . $facref;
        $file = $dir . "/" . $facref . ".meta";
        if (!is_dir($dir)) {
            dol_mkdir($dir);
        }
        if (is_dir($dir)) {
            $nblignes = count($object->lines);
            $client = $object->client->name . " " . $object->client->address . " " . $object->client->zip . " " . $object->client->town;
            $meta = "REFERENCE=\"" . $object->ref . "\"\n\t\t\tDATE=\"" . dol_print_date($object->date, '') . "\"\n\t\t\tNB_ITEMS=\"" . $nblignes . "\"\n\t\t\tCLIENT=\"" . $client . "\"\n\t\t\tTOTAL_HT=\"" . $object->total_ht . "\"\n\t\t\tTOTAL_TTC=\"" . $object->total_ttc . "\"\n";
            for ($i = 0; $i < $nblignes; $i++) {
                //Pour les articles
                $meta .= "ITEM_" . $i . "_QUANTITY=\"" . $object->lines[$i]->qty . "\"\n\t\t\t\tITEM_" . $i . "_TOTAL_HT=\"" . $object->lines[$i]->total_ht . "\"\n\t\t\t\tITEM_" . $i . "_TVA=\"" . $object->lines[$i]->tva_tx . "\"\n\t\t\t\tITEM_" . $i . "_DESCRIPTION=\"" . str_replace("\r\n", "", nl2br($object->lines[$i]->desc)) . "\"\n\t\t\t\t";
            }
        }
        $fp = fopen($file, "w");
        fputs($fp, $meta);
        fclose($fp);
        if (!empty($conf->global->MAIN_UMASK)) {
            @chmod($file, octdec($conf->global->MAIN_UMASK));
        }
        return 1;
    }
    return 0;
}
 /**
  *    Copy contact from one element to current
  *
  *    @param    CommonObject    $objFrom    Source element
  *    @param    string          $source     Nature of contact ('internal' or 'external')
  *    @return   int                         >0 if OK, <0 if KO
  */
 function copy_linked_contact($objFrom, $source = 'internal')
 {
     global $user, $langs, $conf;
     $contacts = $objFrom->liste_contact(-1, $source);
     foreach ($contacts as $contact) {
         if ($this->add_contact($contact['id'], $contact['fk_c_type_contact'], $contact['source']) < 0) {
             $this->error = $this->db->lasterror();
             dol_syslog(get_class($this) . "::copy_contact error=" . $this->error, LOG_ERR);
             return -1;
         }
     }
     return 1;
 }
Exemplo n.º 10
0
    /**
     *  Show block with links to link to other objects.
     *
     *  @param	CommonObject	$object				Object we want to show links to
     *  @param	array			$restrictlinksto	Restrict links to some elements, for exemple array('order') or array('supplier_order')
     *  @return	int									<0 if KO, >0 if OK
     */
    function showLinkToObjectBlock($object, $restrictlinksto = array())
    {
        global $conf, $langs, $hookmanager;
        global $bc;
        $linktoelem = '';
        if (!is_object($object->thirdparty)) {
            $object->fetch_thirdparty();
        }
        if ((!is_array($restrictlinksto) || in_array('order', $restrictlinksto)) && !empty($conf->commande->enabled)) {
            $linktoelem .= ($linktoelem ? ' &nbsp; ' : '') . '<a href="#linktoorder" id="linktoorder">' . $langs->trans('LinkedOrder') . '</a>';
            print '
				<script type="text/javascript" language="javascript">
				jQuery(document).ready(function() {
					jQuery("#linktoorder").click(function() {
						jQuery("#orderlist").toggle();
						jQuery("#linktoorder").toggle();
					});
				});
				</script>
				';
            print '<div id="orderlist"' . (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) ? ' style="display:none"' : '') . '>';
            $sql = "SELECT s.rowid as socid, s.nom as name, s.client, c.rowid, c.ref, c.ref_client, c.total_ht";
            $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s";
            $sql .= ", " . MAIN_DB_PREFIX . "commande as c";
            $sql .= ' WHERE c.fk_soc = s.rowid AND c.fk_soc = ' . $object->thirdparty->id . '';
            $resqlorderlist = $this->db->query($sql);
            if ($resqlorderlist) {
                $num = $this->db->num_rows($resqlorderlist);
                $i = 0;
                print '<br><form action="" method="POST" name="LinkedOrder">';
                print '<table class="noborder">';
                print '<tr class="liste_titre">';
                print '<td class="nowrap"></td>';
                print '<td align="center">' . $langs->trans("Ref") . '</td>';
                print '<td align="left">' . $langs->trans("RefCustomer") . '</td>';
                print '<td align="left">' . $langs->trans("AmountHTShort") . '</td>';
                print '<td align="left">' . $langs->trans("Company") . '</td>';
                print '</tr>';
                while ($i < $num) {
                    $objp = $this->db->fetch_object($resqlorderlist);
                    $var = !$var;
                    print '<tr ' . $bc[$var] . '>';
                    print '<td aling="left">';
                    print '<input type="radio" name="linkedOrder" value=' . $objp->rowid . '>';
                    print '</td>';
                    print '<td align="center">' . $objp->ref . '</td>';
                    print '<td>' . $objp->ref_client . '</td>';
                    print '<td>' . price($objp->total_ht) . '</td>';
                    print '<td>' . $objp->name . '</td>';
                    print '</tr>';
                    $i++;
                }
                print '</table>';
                print '<div class="center"><input type="submit" class="button" value="' . $langs->trans('ToLink') . '">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" class="button" name="cancel" value="' . $langs->trans('Cancel') . '"></div>';
                print '</form>';
                $this->db->free($resqlorderlist);
            } else {
                dol_print_error($this->db);
            }
            print '</div>';
        }
        if ((!is_array($restrictlinksto) || in_array('supplier_order', $restrictlinksto)) && !empty($conf->fournisseur->enabled)) {
            $linktoelem .= ($linktoelem ? ' &nbsp; ' : '') . '<a href="#linktoorder" id="linktoorder">' . $langs->trans('LinkedOrder') . '</a>';
            print '
			<script type="text/javascript" language="javascript">
			jQuery(document).ready(function() {
				jQuery("#linktoorder").click(function() {
					jQuery("#orderlist").toggle();
					jQuery("#linktoorder").toggle();
				});
			});
			</script>
			';
            print '<div id="orderlist"' . (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) ? ' style="display:none"' : '') . '>';
            $sql = "SELECT s.rowid as socid, s.nom as name, s.client, c.rowid, c.ref, c.ref_supplier, c.total_ht";
            $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s";
            $sql .= ", " . MAIN_DB_PREFIX . "commande_fournisseur as c";
            $sql .= ' WHERE c.fk_soc = s.rowid AND c.fk_soc = ' . $object->thirdparty->id;
            $resqlorderlist = $this->db->query($sql);
            if ($resqlorderlist) {
                $num = $this->db->num_rows($resqlorderlist);
                $i = 0;
                print '<br><form action="" method="POST" name="LinkedOrder">';
                print '<table class="noborder">';
                print '<tr class="liste_titre">';
                print '<td class="nowrap"></td>';
                print '<td align="center">' . $langs->trans("Ref") . '</td>';
                print '<td align="left">' . $langs->trans("RefSupplier") . '</td>';
                print '<td align="left">' . $langs->trans("AmountHTShort") . '</td>';
                print '<td align="left">' . $langs->trans("Company") . '</td>';
                print '</tr>';
                while ($i < $num) {
                    $objp = $this->db->fetch_object($resqlorderlist);
                    $var = !$var;
                    print '<tr ' . $bc[$var] . '>';
                    print '<td aling="left">';
                    print '<input type="radio" name="linkedOrder" value=' . $objp->rowid . '>';
                    print '</td>';
                    print '<td align="center">' . $objp->ref . '</td>';
                    print '<td>' . $objp->ref_supplier . '</td>';
                    print '<td>' . price($objp->total_ht) . '</td>';
                    print '<td>' . $objp->name . '</td>';
                    print '</tr>';
                    $i++;
                }
                print '</table>';
                print '<br><div class="center"><input type="submit" class="button" value="' . $langs->trans('ToLink') . '"> &nbsp; <input type="submit" class="button" name="cancel" value="' . $langs->trans('Cancel') . '"></div>';
                print '</form>';
                $this->db->free($resqlorderlist);
            } else {
                dol_print_error($this->db);
            }
            print '</div>';
        }
        return $linktoelem;
    }
Exemplo n.º 11
0
print '<!-- Ajax page called with url '.$_SERVER["PHP_SELF"].'?'.$_SERVER["QUERY_STRING"].' -->'."\n";

// Registering the location of boxes
if((isset($_GET['roworder']) && !empty($_GET['roworder'])) && (isset($_GET['table_element_line']) && !empty($_GET['table_element_line']))
	&& (isset($_GET['fk_element']) && !empty($_GET['fk_element'])) && (isset($_GET['element_id']) && !empty($_GET['element_id'])) )
{
	$roworder = explode(',',$_GET['roworder']);
	
	foreach($roworder as $value)
	{
		if (!empty($value))
		{
			$newroworder[] = $value;
		}
	}
	
	$roworder = implode(',',$newroworder);
	
	dol_syslog("AjaxRow roworder=".$_GET['roworder']." neworder=".$roworder." element=".$_GET['element'], LOG_DEBUG);

	$row=new CommonObject($db);
	$row->table_element_line = $_GET['table_element_line'];
	$row->fk_element = $_GET['fk_element'];
	$row->id = $_GET['element_id'];
	$result=$row->line_ajaxorder($roworder);
	$result=$row->line_order(true);
}

?>
Exemplo n.º 12
0
/**
 *  Show left menu bar
 *  @param      menu_array_before 	       Table of menu entries to show before entries of menu handler
 *  @param      helppagename    	       Name of wiki page for help ('' by default).
 * 				                           Syntax is: For a wiki page: EN:EnglishPage|FR:FrenchPage|ES:SpanishPage
 * 									                  For other external page: http://server/url
 *  @param      moresearchform             Search Form Permanent Supplemental
 *  @param      menu_array_after           Table of menu entries to show after entries of menu handler
 *  @param      leftmenuwithoutmainarea    Must be set to 1. 0 by default for backward compatibility with old modules.
 *  @param      title                      Title of web page
 */
function left_menu($menu_array_before, $helppagename = '', $moresearchform = '', $menu_array_after = '', $leftmenuwithoutmainarea = 0, $title = '')
{
    global $user, $conf, $langs, $db;
    $searchform = '';
    $bookmarks = '';
    if ($conf->use_javascript_ajax && $conf->global->MAIN_MENU_USE_JQUERY_LAYOUT) {
        print "\n" . '<div class="ui-layout-west"> <!-- Begin left layout -->' . "\n";
    } else {
        print '<td class="vmenu" valign="top">';
    }
    print "\n";
    // Instantiate hooks of thirdparty module
    if (is_array($conf->hooks_modules) && !empty($conf->hooks_modules)) {
        require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php';
        $object = new CommonObject($db);
        $object->callHooks(array('searchform', 'leftblock'));
    }
    // Define $searchform
    if ($conf->societe->enabled && $conf->global->MAIN_SEARCHFORM_SOCIETE && $user->rights->societe->lire) {
        $langs->load("companies");
        $searchform .= printSearchForm(DOL_URL_ROOT . '/societe/societe.php', DOL_URL_ROOT . '/societe/societe.php', img_object('', 'company') . ' ' . $langs->trans("ThirdParties"), 'soc', 'socname');
    }
    if ($conf->societe->enabled && $conf->global->MAIN_SEARCHFORM_CONTACT && $user->rights->societe->lire) {
        $langs->load("companies");
        $searchform .= printSearchForm(DOL_URL_ROOT . '/contact/index.php', DOL_URL_ROOT . '/contact/index.php', img_object('', 'contact') . ' ' . $langs->trans("Contacts"), 'contact', 'contactname');
    }
    if (($conf->product->enabled && $user->rights->produit->lire || $conf->service->enabled && $user->rights->service->lire) && $conf->global->MAIN_SEARCHFORM_PRODUITSERVICE) {
        $langs->load("products");
        $searchform .= printSearchForm(DOL_URL_ROOT . '/product/liste.php', DOL_URL_ROOT . '/product/liste.php', img_object('', 'product') . ' ' . $langs->trans("Products") . "/" . $langs->trans("Services"), 'products', 'sall');
    }
    if ($conf->adherent->enabled && $conf->global->MAIN_SEARCHFORM_ADHERENT && $user->rights->adherent->lire) {
        $langs->load("members");
        $searchform .= printSearchForm(DOL_URL_ROOT . '/adherents/liste.php', DOL_URL_ROOT . '/adherents/liste.php', img_object('', 'user') . ' ' . $langs->trans("Members"), 'member', 'sall');
    }
    // Search form hook for external modules
    if (!empty($object->hooks)) {
        $searchform .= '<!-- Begin search form hook area -->' . "\n";
        foreach ($object->hooks as $hook) {
            if ($hook['type'] == 'searchform' && !empty($hook['modules'])) {
                foreach ($hook['modules'] as $module) {
                    if (method_exists($module, 'printSearchForm')) {
                        $searchform .= $module->printSearchForm();
                    }
                }
            }
        }
        $searchform .= "\n" . '<!-- End of search form hook area -->' . "\n";
    }
    // Define $bookmarks
    if ($conf->bookmark->enabled && $user->rights->bookmark->lire) {
        include_once DOL_DOCUMENT_ROOT . '/bookmarks/bookmarks.lib.php';
        $langs->load("bookmarks");
        $bookmarks = printBookmarksList($db, $langs);
    }
    $left_menu = isset($conf->browser->phone) ? $conf->smart_menu : $conf->top_menu;
    if (GETPOST('menu')) {
        $left_menu = GETPOST('menu');
    }
    // menu=eldy_backoffice.php
    // Load the left menu manager
    $result = dol_include_once("/includes/menus/standard/" . $left_menu);
    if (!$result) {
        $left_menu = 'eldy_backoffice.php';
        include_once DOL_DOCUMENT_ROOT . "/includes/menus/standard/" . $left_menu;
    }
    // Left column
    print '<!-- Begin left area - menu ' . $left_menu . ' -->' . "\n";
    print '<div class="vmenu">' . "\n";
    $menuleft = new MenuLeft($db, $menu_array_before, $menu_array_after);
    $menuleft->showmenu();
    // output menu_array and menu found in database
    // Show other forms
    if ($searchform) {
        print "\n";
        print "<!-- Begin SearchForm -->\n";
        print '<div id="blockvmenusearch" class="blockvmenusearch">' . "\n";
        print $searchform;
        print '</div>' . "\n";
        print "<!-- End SearchForm -->\n";
    }
    // More search form
    if ($moresearchform) {
        print $moresearchform;
    }
    // Bookmarks
    if ($bookmarks) {
        print "\n";
        print "<!-- Begin Bookmarks -->\n";
        print '<div id="blockvmenubookmarks" class="blockvmenubookmarks">' . "\n";
        print $bookmarks;
        print '</div>' . "\n";
        print "<!-- End Bookmarks -->\n";
    }
    // Link to Dolibarr wiki pages
    if ($helppagename && empty($conf->global->MAIN_HELP_DISABLELINK)) {
        $langs->load("help");
        $helpbaseurl = '';
        $helppage = '';
        $mode = '';
        // Get helpbaseurl, helppage and mode from helppagename and langs
        $arrayres = getHelpParamFor($helppagename, $langs);
        $helpbaseurl = $arrayres['helpbaseurl'];
        $helppage = $arrayres['helppage'];
        $mode = $arrayres['mode'];
        // Link to help pages
        if ($helpbaseurl && $helppage) {
            print '<div id="blockvmenuhelp" class="blockvmenuhelp">';
            print '<a class="help" target="_blank" title="' . $langs->trans($mode == 'wiki' ? 'GoToWikiHelpPage' : 'GoToHelpPage');
            if ($mode == 'wiki') {
                print ' - ' . $langs->trans("PageWiki") . ' &quot;' . dol_escape_htmltag(strtr($helppage, '_', ' ')) . '&quot;';
            }
            print '" href="';
            print sprintf($helpbaseurl, urlencode(html_entity_decode($helppage)));
            print '">';
            print img_picto('', DOL_URL_ROOT . '/theme/common/helpdoc.png', '', 1) . ' ';
            print $langs->trans($mode == 'wiki' ? 'OnlineHelp' : 'Help');
            //if ($mode == 'wiki') print ' ('.dol_trunc(strtr($helppage,'_',' '),8).')';
            print '</a>';
            print '</div>';
        }
    }
    // Link to bugtrack
    if (!empty($conf->global->MAIN_SHOW_BUGTRACK_LINK)) {
        $bugbaseurl = 'http://savannah.nongnu.org/bugs/?';
        $bugbaseurl .= 'func=additem&group=dolibarr&privacy=1&';
        $bugbaseurl .= "&details=";
        $bugbaseurl .= urlencode("\n\n\n\n\n-------------\n");
        $bugbaseurl .= urlencode($langs->trans("Version") . ": " . DOL_VERSION . "\n");
        $bugbaseurl .= urlencode($langs->trans("Server") . ": " . $_SERVER["SERVER_SOFTWARE"] . "\n");
        $bugbaseurl .= urlencode($langs->trans("Url") . ": " . $_SERVER["REQUEST_URI"] . "\n");
        print '<div class="help"><a class="help" target="_blank" href="' . $bugbaseurl . '">' . $langs->trans("FindBug") . '</a></div>';
    }
    print "\n";
    print "</div>\n";
    print "<!-- End left vertical menu -->\n";
    print "\n";
    // Left block hook for external modules
    if (!empty($object->hooks)) {
        print '<!-- Begin left block hook area -->' . "\n";
        foreach ($object->hooks as $hook) {
            if ($hook['type'] == 'leftblock' && !empty($hook['modules'])) {
                foreach ($hook['modules'] as $module) {
                    if (method_exists($module, 'printLeftBlock')) {
                        $module->printLeftBlock();
                    }
                }
            }
        }
        print "\n" . '<!-- End of left block hook area -->' . "\n";
    }
    if ($conf->use_javascript_ajax && $conf->global->MAIN_MENU_USE_JQUERY_LAYOUT) {
        print '</div> <!-- End left layout -->' . "\n";
    } else {
        print '</td>';
    }
    print "\n";
    print '<!-- End of left area -->' . "\n";
    print "\n";
    print '<!-- Begin right area -->' . "\n";
    if (empty($leftmenuwithoutmainarea)) {
        main_area($title);
    }
}