Skip to content

Commit

Permalink
Start to work on a basic print sticker tool
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Dec 15, 2013
1 parent 77d670a commit c34e501
Show file tree
Hide file tree
Showing 6 changed files with 217 additions and 0 deletions.
1 change: 1 addition & 0 deletions build/rpm/dolibarr_fedora.spec
Expand Up @@ -159,6 +159,7 @@ done >>%{name}.lang
%_datadir/dolibarr/htdocs/adherents
%_datadir/dolibarr/htdocs/admin
%_datadir/dolibarr/htdocs/asterisk
%_datadir/dolibarr/htdocs/barcode
%_datadir/dolibarr/htdocs/bookmarks
%_datadir/dolibarr/htdocs/boutique
%_datadir/dolibarr/htdocs/cashdesk
Expand Down
1 change: 1 addition & 0 deletions build/rpm/dolibarr_generic.spec
Expand Up @@ -239,6 +239,7 @@ done >>%{name}.lang
%_datadir/dolibarr/htdocs/adherents
%_datadir/dolibarr/htdocs/admin
%_datadir/dolibarr/htdocs/asterisk
%_datadir/dolibarr/htdocs/barcode
%_datadir/dolibarr/htdocs/bookmarks
%_datadir/dolibarr/htdocs/boutique
%_datadir/dolibarr/htdocs/cashdesk
Expand Down
1 change: 1 addition & 0 deletions build/rpm/dolibarr_mandriva.spec
Expand Up @@ -156,6 +156,7 @@ done >>%{name}.lang
%_datadir/dolibarr/htdocs/adherents
%_datadir/dolibarr/htdocs/admin
%_datadir/dolibarr/htdocs/asterisk
%_datadir/dolibarr/htdocs/barcode
%_datadir/dolibarr/htdocs/bookmarks
%_datadir/dolibarr/htdocs/boutique
%_datadir/dolibarr/htdocs/cashdesk
Expand Down
1 change: 1 addition & 0 deletions build/rpm/dolibarr_opensuse.spec
Expand Up @@ -167,6 +167,7 @@ done >>%{name}.lang
%_datadir/dolibarr/htdocs/adherents
%_datadir/dolibarr/htdocs/admin
%_datadir/dolibarr/htdocs/asterisk
%_datadir/dolibarr/htdocs/barcode
%_datadir/dolibarr/htdocs/bookmarks
%_datadir/dolibarr/htdocs/boutique
%_datadir/dolibarr/htdocs/cashdesk
Expand Down
200 changes: 200 additions & 0 deletions htdocs/barcode/printsheet.php
@@ -0,0 +1,200 @@
<?php
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
* Copyright (C) 2006-2013 Laurent Destailleur <eldy@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/**
* \file htdocs/barcode/printsheet.php
* \ingroup member
* \brief Page to print sheets with barcodes using the document templates into core/modules/printsheets
*/
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/format_cards.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/modules/printsheet/modules_labels.php';

$langs->load("admin");
$langs->load("errors");

// Choix de l'annee d'impression ou annee courante.
$now = dol_now();
$year=dol_print_date($now,'%Y');
$month=dol_print_date($now,'%m');
$day=dol_print_date($now,'%d');
$forbarcode=GETPOST('forbarcode');
$forbartype=GETPOST('forbartype');
$mode=GETPOST('mode');
$model=GETPOST("model"); // Doc template to use for business cards
$modellabel=GETPOST("modellabel"); // Doc template to use for address sheet
$mesg='';


/*
* Actions
*/

if ($action == 'builddoc' && empty($forbarcode))
{
$mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Barcode"));
}
if ($action == 'builddoc' && empty($forbartype))
{
$mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("BarcodeType"));
}

if ((! empty($forbarcode) || ! empty($forbartype) || ! empty($mode)) && ! $mesg)
{
// List of values to scan for a replacement
$substitutionarray = array (
'%LOGIN%'=>$user->login,
'%COMPANY%'=>$mysoc->name,
'%ADDRESS%'=>$mysoc->address,
'%ZIP%'=>$mysoc->zip,
'%TOWN%'=>$mysoc->town,
'%COUNTRY%'=>$mysoc->country,
'%COUNTRY_CODE%'=>$mysoc->country_code,
'%EMAIL%'=>$mysoc->email,
'%YEAR%'=>$year,
'%MONTH%'=>$month,
'%DAY%'=>$day,
'%DOL_MAIN_URL_ROOT%'=>DOL_MAIN_URL_ROOT,
'%SERVER%'=>"http://".$_SERVER["SERVER_NAME"]."/"
);
complete_substitutions_array($substitutionarray, $langs);

// For business cards
if (empty($mode) || $mode=='card' || $mode=='cardlogin')
{
$textleft=make_substitutions($conf->global->ADHERENT_CARD_TEXT, $substitutionarray);
$textheader=make_substitutions($conf->global->ADHERENT_CARD_HEADER_TEXT, $substitutionarray);
$textfooter=make_substitutions($conf->global->ADHERENT_CARD_FOOTER_TEXT, $substitutionarray);
$textright=make_substitutions($conf->global->ADHERENT_CARD_TEXT_RIGHT, $substitutionarray);

if (is_numeric($forbarcode) || $forbartype)
{
for($j=0;$j<100;$j++)
{
$arrayofmembers[]=array(
'textleft'=>$textleft,
'textheader'=>$textheader,
'textfooter'=>$textfooter,
'textright'=>$textright,
'id'=>$objp->rowid,
'photo'=>$objp->photo
);
}
}
else
{
$arrayofmembers[]=array(
'textleft'=>$textleft,
'textheader'=>$textheader,
'textfooter'=>$textfooter,
'textright'=>$textright,
'id'=>$objp->rowid,
'photo'=>$objp->photo
);
}
}

// For labels
if ($mode == 'label')
{
if (empty($conf->global->ADHERENT_ETIQUETTE_TEXT)) $conf->global->ADHERENT_ETIQUETTE_TEXT="%FULLNAME%\n%ADDRESS%\n%ZIP% %TOWN%\n%COUNTRY%";
$textleft=make_substitutions($conf->global->ADHERENT_ETIQUETTE_TEXT, $substitutionarray);
$textheader='';
$textfooter='';
$textright='';

$arrayofmembers[]=array('textleft'=>$textleft,
'textheader'=>$textheader,
'textfooter'=>$textfooter,
'textright'=>$textright,
'id'=>$objp->rowid,
'photo'=>$objp->photo);
}

$i++;

// Build and output PDF
if ($mode == 'label')
{
if (! count($arrayofmembers))
{
$mesg=$langs->trans("ErrorRecordNotFound");
}
if (empty($modellabel) || $modellabel == '-1')
{
$mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("DescADHERENT_ETIQUETTE_TYPE"));
}
if (! $mesg) $result=members_label_pdf_create($db, $arrayofmembers, $modellabel, $outputlangs);
}

if ($result <= 0)
{
dol_print_error('',$result);
}

if (! $mesg)
{
$db->close();
exit;
}
}


/*
* View
*/

$form=new Form($db);

llxHeader('',$langs->trans("BarCodePrintsheet"));

print_fiche_titre($langs->trans("BarCodePrintsheet"));
print '<br>';

print $langs->trans("PageToGenerateBarCodeSheets").'<br>';
print '<br>';

dol_htmloutput_errors($mesg);

print img_picto('','puce').' '.$langs->trans("BarCodePrintsheet").' ';
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
print '<input type="hidden" name="mode" value="label">';
print '<input type="hidden" name="action" value="builddoc">';
print $langs->trans("DescADHERENT_ETIQUETTE_TYPE").' ';
// List of possible labels (defined into $_Avery_Labels variable set into format_cards.lib.php)
$arrayoflabels=array();
foreach(array_keys($_Avery_Labels) as $codecards)
{
$arrayoflabels[$codecards]=$_Avery_Labels[$codecards]['name'];
}
print $form->selectarray('modellabel',$arrayoflabels,(GETPOST('modellabel')?GETPOST('modellabel'):$conf->global->ADHERENT_ETIQUETTE_TYPE),1,0,0);
print '<br>'.$langs->trans("Barcode").': <input size="10" type="text" name="forbarcode" value="'.GETPOST('forbarcode').'">';
print '<br>'.$langs->trans("Bartype").': <input size="10" type="text" name="forbartype" value="'.GETPOST('forbartype').'">';

$barcodestickersmask=GETPOST('barcodestickersmask');
print '<br>'.$langs->trans("BarcodeStickersMask").': <textarea cols="40" type="text" name="barcodestickersmask" value="'.GETPOST('barcodestickersmask').'">'.$barcodestickersmask.'</textarea>';
print '<br><input class="button" type="submit" value="'.$langs->trans("BuildDoc").'">';
print '</form>';
print '<br>';

llxFooter();

$db->close();
?>
13 changes: 13 additions & 0 deletions htdocs/core/modules/modBarcode.class.php
Expand Up @@ -94,6 +94,19 @@ function __construct($db)
$this->rights[4][3] = 0; // La permission est-elle une permission par defaut
$this->rights[4][4] = 'supprimer';

// Main menu entries
$r=0;
$this->menu[$r]=array( 'fk_menu'=>'fk_mainmenu=home,fk_leftmenu=modulesadmintools', // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
'type'=>'left', // This is a Left menu entry
'titre'=>'BarCodePrintsheet',
'url'=>'/barcode/printsheet.php',
'langs'=>'cron', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
'position'=>200,
'enabled'=>'$leftmenu==\'modulesadmintools\' && $conf->barcode->enabled', // Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
'target'=>'',
'user'=>2); // 0=Menu for internal users, 1=external users, 2=both
$r++;
}


Expand Down

0 comments on commit c34e501

Please sign in to comment.