From 45a808e0345bc214db3128e5e9db7cdd12464629 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur <eldy@destailleur.fr> Date: Sun, 2 Oct 2016 20:15:11 +0200 Subject: [PATCH] NEW Generation of document is available on member card --- htdocs/adherents/agenda.php | 7 + htdocs/adherents/card.php | 107 ++++++++++---- htdocs/adherents/cartes/carte.php | 43 +++--- htdocs/adherents/class/adherent.class.php | 38 +++++ htdocs/adherents/document.php | 2 +- htdocs/adherents/info.php | 77 ---------- htdocs/adherents/subscription/card.php | 2 +- htdocs/adherents/subscription/info.php | 2 +- htdocs/adherents/subscription/list.php | 2 +- htdocs/commande/class/commande.class.php | 4 +- htdocs/core/class/commonobject.class.php | 47 +++--- htdocs/core/class/html.form.class.php | 8 +- htdocs/core/class/html.formfile.class.php | 10 +- htdocs/core/lib/functions.lib.php | 2 +- htdocs/core/lib/functions2.lib.php | 16 ++- htdocs/core/lib/member.lib.php | 31 ++-- .../modules/member/doc/pdf_standard.class.php | 134 ++++++++++++++---- htdocs/core/modules/member/modules_cards.php | 4 +- .../install/mysql/migration/4.0.0-5.0.0.sql | 2 + htdocs/install/mysql/tables/llx_adherent.sql | 1 + 20 files changed, 337 insertions(+), 202 deletions(-) delete mode 100644 htdocs/adherents/info.php diff --git a/htdocs/adherents/agenda.php b/htdocs/adherents/agenda.php index 057d7ada946..1aa1dc6bee7 100644 --- a/htdocs/adherents/agenda.php +++ b/htdocs/adherents/agenda.php @@ -120,6 +120,13 @@ if ($object->id > 0) print '</table>'; + + print '<br>'; + + $object->info($id); + print dol_print_object_info($object, 1); + + print '</div>'; dol_fiche_end(); diff --git a/htdocs/adherents/card.php b/htdocs/adherents/card.php index 05a6772163e..8e302643317 100644 --- a/htdocs/adherents/card.php +++ b/htdocs/adherents/card.php @@ -39,6 +39,7 @@ require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; $langs->load("companies"); $langs->load("bills"); @@ -51,6 +52,7 @@ $cancel=GETPOST('cancel','alpha'); $backtopage=GETPOST('backtopage','alpha'); $confirm=GETPOST('confirm','alpha'); $rowid=GETPOST('rowid','int'); +$id=GETPOST('id')?GETPOST('id','int'):$rowid; $typeid=GETPOST('typeid','int'); $userid=GETPOST('userid','int'); $socid=GETPOST('socid','int'); @@ -71,7 +73,7 @@ $extrafields = new ExtraFields($db); $extralabels=$extrafields->fetch_name_optionals_label($object->table_element); // Get object canvas (By default, this is not defined, so standard usage of dolibarr) -$object->getCanvas($rowid); +$object->getCanvas($id); $canvas = $object->canvas?$object->canvas:GETPOST("canvas"); $objcanvas=null; if (! empty($canvas)) @@ -82,12 +84,12 @@ if (! empty($canvas)) } // Security check -$result=restrictedArea($user, 'adherent', $rowid, '', '', 'fk_soc', 'rowid', $objcanvas); +$result=restrictedArea($user, 'adherent', $id, '', '', 'fk_soc', 'rowid', $objcanvas); -if ($rowid > 0) +if ($id > 0) { // Load member - $result = $object->fetch($rowid); + $result = $object->fetch($id); // Define variables to know what current user can do on users $canadduser=($user->admin || $user->rights->user->user->creer); @@ -105,7 +107,7 @@ if ($rowid > 0) // Define variables to determine what the current user can do on the members $canaddmember=$user->rights->adherent->creer; // Define variables to determine what the current user can do on the properties of a member -if ($rowid) +if ($id) { $caneditfieldmember=$user->rights->adherent->creer; } @@ -114,12 +116,14 @@ if ($rowid) $hookmanager->initHooks(array('membercard','globalcard')); + /* * Actions */ + if ($cancel) $action=''; -$parameters=array('rowid'=>$rowid, 'objcanvas'=>$objcanvas); +$parameters=array('id'=>$id, 'rowid'=>$id, 'objcanvas'=>$objcanvas); $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); @@ -343,15 +347,15 @@ if (empty($reshook)) $object->setCategories($categories); // Logo/Photo save - $dir= $conf->adherent->dir_output . '/' . get_exdir($object->id,2,0,1,$object,'member').'/photos'; + $dir= $conf->adherent->dir_output . '/' . get_exdir(0,0,0,1,$object,'member').'/photos'; $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']); if ($file_OK) { if (GETPOST('deletephoto')) { require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; - $fileimg=$conf->adherent->dir_output.'/'.get_exdir($object->id,2,0,1,$object,'member').'/photos/'.$object->photo; - $dirthumbs=$conf->adherent->dir_output.'/'.get_exdir($object->id,2,0,1,$object,'member').'/photos/thumbs'; + $fileimg=$conf->adherent->dir_output.'/'.get_exdir(0,0,0,1,$object,'member').'/photos/'.$object->photo; + $dirthumbs=$conf->adherent->dir_output.'/'.get_exdir(0,0,0,1,$object,'member').'/photos/thumbs'; dol_delete_file($fileimg); dol_delete_dir_recursive($dirthumbs); } @@ -394,6 +398,7 @@ if (empty($reshook)) } $rowid=$object->id; + $id=$object->id; $action=''; if (! empty($backtopage)) @@ -556,6 +561,7 @@ if (empty($reshook)) $db->commit(); $rowid=$object->id; + $id=$object->id; $action=''; } else @@ -578,7 +584,7 @@ if (empty($reshook)) if ($user->rights->adherent->supprimer && $action == 'confirm_delete' && $confirm == 'yes') { - $result=$object->delete($rowid); + $result=$object->delete($id); if ($result > 0) { if (! empty($backtopage)) @@ -707,6 +713,11 @@ if (empty($reshook)) } } } + + // Actions to build doc + $upload_dir = $conf->adherent->dir_output; + $permissioncreate=$user->rights->adherent->creer; + include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; } @@ -715,6 +726,7 @@ if (empty($reshook)) */ $form = new Form($db); +$formfile = new FormFile($db); $formcompany = new FormCompany($db); $title=$langs->trans("Member") . " - " . $langs->trans("Card"); @@ -728,10 +740,10 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) // ----------------------------------------- // When used with CANVAS // ----------------------------------------- - if (empty($object->error) && $rowid) + if (empty($object->error) && $id) { $object = new Adherent($db); - $result=$object->fetch($rowid); + $result=$object->fetch($id); if ($result <= 0) dol_print_error('',$object->error); } $objcanvas->assign_values($action, $object->id, $object->ref); // Set value for templates @@ -971,7 +983,7 @@ else * ********************************************/ - $res=$object->fetch($rowid); + $res=$object->fetch($id); if ($res < 0) { dol_print_error($db,$object->error); exit; } @@ -1043,7 +1055,7 @@ else print '<form name="formsoc" action="'.$_SERVER["PHP_SELF"].'" method="post" enctype="multipart/form-data">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'" />'; print '<input type="hidden" name="action" value="update" />'; - print '<input type="hidden" name="rowid" value="'.$rowid.'" />'; + print '<input type="hidden" name="rowid" value="'.$id.'" />'; print '<input type="hidden" name="statut" value="'.$object->statut.'" />'; if ($backtopage) print '<input type="hidden" name="backtopage" value="'.($backtopage != '1' ? $backtopage : $_SERVER["HTTP_REFERER"]).'">'; @@ -1235,7 +1247,7 @@ else } - if ($rowid && $action != 'edit') + if ($id > 0 && $action != 'edit') { /* ************************************************************************** */ /* */ @@ -1243,7 +1255,7 @@ else /* */ /* ************************************************************************** */ - $res=$object->fetch($rowid); + $res=$object->fetch($id); if ($res < 0) { dol_print_error($db,$object->error); exit; } @@ -1343,13 +1355,13 @@ else if (! empty($conf->mailman->enabled) && ! empty($conf->global->ADHERENT_USE_SPIP)) { $formquestion[]=array('type'=>'other','label'=>$langs->transnoentitiesnoconv("SynchroSpipEnabled"),'value'=>''); } - print $form->formconfirm("card.php?rowid=".$rowid,$langs->trans("ValidateMember"),$langs->trans("ConfirmValidateMember"),"confirm_valid",$formquestion,1,1); + print $form->formconfirm("card.php?rowid=".$id,$langs->trans("ValidateMember"),$langs->trans("ConfirmValidateMember"),"confirm_valid",$formquestion,1,1); } // Confirm send card by mail if ($action == 'sendinfo') { - print $form->formconfirm("card.php?rowid=".$rowid,$langs->trans("SendCardByMail"),$langs->trans("ConfirmSendCardByMail",$object->email),"confirm_sendinfo",'',0,1); + print $form->formconfirm("card.php?rowid=".$id,$langs->trans("SendCardByMail"),$langs->trans("ConfirmSendCardByMail",$object->email),"confirm_sendinfo",'',0,1); } // Confirm terminate @@ -1380,7 +1392,7 @@ else $formquestion=array(); if ($object->email) $formquestion[]=array('type' => 'checkbox', 'name' => 'send_mail', 'label' => $label, 'value' => (! empty($conf->global->ADHERENT_DEFAULT_SENDINFOBYMAIL)?'true':'false')); if ($backtopage) $formquestion[]=array('type' => 'hidden', 'name' => 'backtopage', 'value' => ($backtopage != '1' ? $backtopage : $_SERVER["HTTP_REFERER"])); - print $form->formconfirm("card.php?rowid=".$rowid,$langs->trans("ResiliateMember"),$langs->trans("ConfirmResiliateMember"),"confirm_resign",$formquestion,'no',1); + print $form->formconfirm("card.php?rowid=".$id,$langs->trans("ResiliateMember"),$langs->trans("ConfirmResiliateMember"),"confirm_resign",$formquestion,'no',1); } // Confirm remove member @@ -1388,18 +1400,18 @@ else { $formquestion=array(); if ($backtopage) $formquestion[]=array('type' => 'hidden', 'name' => 'backtopage', 'value' => ($backtopage != '1' ? $backtopage : $_SERVER["HTTP_REFERER"])); - print $form->formconfirm("card.php?rowid=".$rowid,$langs->trans("DeleteMember"),$langs->trans("ConfirmDeleteMember"),"confirm_delete",$formquestion,0,1); + print $form->formconfirm("card.php?rowid=".$id,$langs->trans("DeleteMember"),$langs->trans("ConfirmDeleteMember"),"confirm_delete",$formquestion,0,1); } // Confirm add in spip if ($action == 'add_spip') { - print $form->formconfirm("card.php?rowid=".$rowid, $langs->trans('AddIntoSpip'), $langs->trans('AddIntoSpipConfirmation'), 'confirm_add_spip'); + print $form->formconfirm("card.php?rowid=".$id, $langs->trans('AddIntoSpip'), $langs->trans('AddIntoSpipConfirmation'), 'confirm_add_spip'); } // Confirm removed from spip if ($action == 'del_spip') { - print $form->formconfirm("card.php?rowid=$rowid", $langs->trans('DeleteIntoSpip'), $langs->trans('DeleteIntoSpipConfirmation'), 'confirm_del_spip'); + print $form->formconfirm("card.php?rowid=$id", $langs->trans('DeleteIntoSpip'), $langs->trans('DeleteIntoSpipConfirmation'), 'confirm_del_spip'); } $rowspan=17; @@ -1601,7 +1613,7 @@ else // Modify if ($user->rights->adherent->creer) { - print '<div class="inline-block divButAction"><a class="butAction" href="card.php?rowid='.$rowid.'&action=edit">'.$langs->trans("Modify")."</a></div>"; + print '<div class="inline-block divButAction"><a class="butAction" href="card.php?rowid='.$id.'&action=edit">'.$langs->trans("Modify")."</a></div>"; } else { @@ -1613,7 +1625,7 @@ else { if ($user->rights->adherent->creer) { - print '<div class="inline-block divButAction"><a class="butAction" href="card.php?rowid='.$rowid.'&action=valid">'.$langs->trans("Validate")."</a></div>\n"; + print '<div class="inline-block divButAction"><a class="butAction" href="card.php?rowid='.$id.'&action=valid">'.$langs->trans("Validate")."</a></div>\n"; } else { @@ -1626,7 +1638,7 @@ else { if ($user->rights->adherent->creer) { - print '<div class="inline-block divButAction"><a class="butAction" href="card.php?rowid='.$rowid.'&action=valid">'.$langs->trans("Reenable")."</a></div>\n"; + print '<div class="inline-block divButAction"><a class="butAction" href="card.php?rowid='.$id.'&action=valid">'.$langs->trans("Reenable")."</a></div>\n"; } else { @@ -1657,7 +1669,7 @@ else { if ($user->rights->adherent->supprimer) { - print '<div class="inline-block divButAction"><a class="butAction" href="card.php?rowid='.$rowid.'&action=resign">'.$langs->trans("Resiliate")."</a></div>\n"; + print '<div class="inline-block divButAction"><a class="butAction" href="card.php?rowid='.$id.'&action=resign">'.$langs->trans("Resiliate")."</a></div>\n"; } else { @@ -1726,8 +1738,49 @@ else { print '<br><br><font class="error">'.$langs->trans('SPIPConnectionFailed').': '.$mailmanspip->error.'</font>'; } - print "<br>\n"; + + + print '<div class="fichecenter"><div class="fichehalfleft">'; + print '<a name="builddoc"></a>'; // ancre + + // Documents generes + $filename = dol_sanitizeFileName($object->ref); + //$filename = 'tmp_cards.php'; + //$filedir = $conf->adherent->dir_output . '/' . get_exdir($object->id, 2, 0, 0, $object, 'member') . dol_sanitizeFileName($object->ref); + $filedir = $conf->adherent->dir_output . '/' . get_exdir(0, 0, 0, 0, $object, 'member'); + $urlsource = $_SERVER['PHP_SELF'] . '?id=' . $object->id; + $genallowed = $user->rights->adherent->creer; + $delallowed = $user->rights->adherent->supprimer; + + print $formfile->showdocuments('member', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', '', '', $object->default_lang, '', $object); + $somethingshown = $formfile->numoffiles; + + // Show links to link elements + //$linktoelem = $form->showLinkToObjectBlock($object, null, array('subscription')); + //$somethingshown = $form->showLinkedObjectBlock($object, ''); + + // Show links to link elements + /*$linktoelem = $form->showLinkToObjectBlock($object,array('order')); + if ($linktoelem) print ($somethingshown?'':'<br>').$linktoelem; + + // Link for paypal payment + /* + if (! empty($conf->paypal->enabled) && $object->statut != 0) { + include_once DOL_DOCUMENT_ROOT . '/paypal/lib/paypal.lib.php'; + print showPaypalPaymentUrl('invoice', $object->ref); + } + */ + print '</div><div class="fichehalfright"><div class="ficheaddleft">'; + + // List of actions on element + /* Already in tab Agenda/Events + include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php'; + $formactions = new FormActions($db); + $somethingshown = $formactions->showactions($object, 'member', $socid); + */ + print '</div></div></div>'; + } } diff --git a/htdocs/adherents/cartes/carte.php b/htdocs/adherents/cartes/carte.php index 99de04bf000..db4c631c0c9 100644 --- a/htdocs/adherents/cartes/carte.php +++ b/htdocs/adherents/cartes/carte.php @@ -89,25 +89,25 @@ if ((! empty($foruserid) || ! empty($foruserlogin) || ! empty($mode)) && ! $mesg // List of values to scan for a replacement $substitutionarray = array ( - '%ID%'=>$objp->rowid, - '%LOGIN%'=>$objp->login, - '%FIRSTNAME%'=>$objp->firstname, - '%LASTNAME%'=>$objp->lastname, - '%FULLNAME%'=>$adherentstatic->getFullName($langs), - '%COMPANY%'=>$objp->company, - '%ADDRESS%'=>$objp->address, - '%ZIP%'=>$objp->zip, - '%TOWN%'=>$objp->town, - '%COUNTRY%'=>$objp->country, - '%COUNTRY_CODE%'=>$objp->country_code, - '%EMAIL%'=>$objp->email, - '%BIRTH%'=>dol_print_date($objp->birth,'day'), - '%TYPE%'=>$objp->type, - '%YEAR%'=>$year, - '%MONTH%'=>$month, - '%DAY%'=>$day, - '%DOL_MAIN_URL_ROOT%'=>DOL_MAIN_URL_ROOT, - '%SERVER%'=>"http://".$_SERVER["SERVER_NAME"]."/" + '%ID%'=>$objp->rowid, + '%LOGIN%'=>$objp->login, + '%FIRSTNAME%'=>$objp->firstname, + '%LASTNAME%'=>$objp->lastname, + '%FULLNAME%'=>$adherentstatic->getFullName($langs), + '%COMPANY%'=>$objp->company, + '%ADDRESS%'=>$objp->address, + '%ZIP%'=>$objp->zip, + '%TOWN%'=>$objp->town, + '%COUNTRY%'=>$objp->country, + '%COUNTRY_CODE%'=>$objp->country_code, + '%EMAIL%'=>$objp->email, + '%BIRTH%'=>dol_print_date($objp->birth,'day'), + '%TYPE%'=>$objp->type, + '%YEAR%'=>$year, + '%MONTH%'=>$month, + '%DAY%'=>$day, + '%DOL_MAIN_URL_ROOT%'=>DOL_MAIN_URL_ROOT, + '%SERVER%'=>"http://".$_SERVER["SERVER_NAME"]."/" ); complete_substitutions_array($substitutionarray, $langs); @@ -121,7 +121,10 @@ if ((! empty($foruserid) || ! empty($foruserlogin) || ! empty($mode)) && ! $mesg if (is_numeric($foruserid) || $foruserlogin) { - for($j=0;$j<100;$j++) + $nb = $_Avery_Labels[$model]['NX'] * $_Avery_Labels[$model]['NY']; + if ($nb <= 0) $nb=1; // Protection to avoid empty page + + for($j=0;$j<$nb;$j++) { $arrayofmembers[]=array( 'textleft'=>$textleft, diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php index 41fd2753109..191b23bea32 100644 --- a/htdocs/adherents/class/adherent.class.php +++ b/htdocs/adherents/class/adherent.class.php @@ -1070,6 +1070,7 @@ class Adherent extends CommonObject $sql.= " d.datevalid as datev,"; $sql.= " d.country,"; $sql.= " d.state_id,"; + $sql.= " d.model_pdf,"; $sql.= " c.rowid as country_id, c.code as country_code, c.label as country,"; $sql.= " dep.nom as state, dep.code_departement as state_code,"; $sql.= " t.libelle as type, t.subscription as subscription,"; @@ -1154,6 +1155,8 @@ class Adherent extends CommonObject $this->user_id = $obj->user_id; $this->user_login = $obj->user_login; + + $this->model_pdf = $obj->model_pdf; // Retreive all extrafield for thirdparty // fetch optionals attributes and labels @@ -1783,6 +1786,41 @@ class Adherent extends CommonObject } + /** + * Create a document onto disk according to template module. + * + * @param string $modele Force template to use ('' to not force) + * @param Translate $outputlangs objet lang a utiliser pour traduction + * @param int $hidedetails Hide details of lines + * @param int $hidedesc Hide description + * @param int $hideref Hide ref + * @return int 0 if KO, 1 if OK + */ + public function generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0) + { + global $conf,$langs; + + $langs->load("orders"); + + // Positionne le modele sur le nom du modele a utiliser + if (! dol_strlen($modele)) + { + if (! empty($conf->global->ADHERENT_ADDON_PDF)) + { + $modele = $conf->global->ADHERENT_ADDON_PDF; + } + else + { + $modele = 'standard'; + } + } + + $modelpath = "core/modules/member/doc/"; + + return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref); + } + + /** * Initialise an instance with random values. * Used to build previews or test instances. diff --git a/htdocs/adherents/document.php b/htdocs/adherents/document.php index eebb4fda37f..7860d36c9fb 100644 --- a/htdocs/adherents/document.php +++ b/htdocs/adherents/document.php @@ -69,7 +69,7 @@ if ($result < 0) dol_print_error($db); exit; } -$upload_dir = $conf->adherent->dir_output . "/" . get_exdir($object->id,2,0,1,$object,'member') . '/' . dol_sanitizeFileName($object->ref); +$upload_dir = $conf->adherent->dir_output . "/" . get_exdir(0, 0, 0, 1, $object, 'member'); /* diff --git a/htdocs/adherents/info.php b/htdocs/adherents/info.php deleted file mode 100644 index 53e9b7ee092..00000000000 --- a/htdocs/adherents/info.php +++ /dev/null @@ -1,77 +0,0 @@ -<?php -/* Copyright (C) 2005-2013 Laurent Destailleur <eldy@users.sourceforge.net> - * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -/** - * \file htdocs/adherents/info.php - * \ingroup member - * \brief Page des informations d'un adherent - */ - -require '../main.inc.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php'; - -$langs->load("companies"); -$langs->load("bills"); -$langs->load("members"); -$langs->load("users"); - -$id=(GETPOST('id','int') ? GETPOST('id','int') : GETPOST('rowid','int')); - -// Security check -$result=restrictedArea($user,'adherent',$id); - - -/* - * View - */ - -$form = new Form($db); - -$title=$langs->trans("Member") . " - " . $langs->trans("Info"); -$helpurl="EN:Module_Foundations|FR:Module_Adhérents|ES:Módulo_Miembros"; -llxHeader("",$title,$helpurl); - -$object = new Adherent($db); -$object->fetch($id); -$object->info($id); - -$head = member_prepare_head($object); - -dol_fiche_head($head, 'info', $langs->trans("Member"), 0, 'user'); - - -$linkback = '<a href="'.DOL_URL_ROOT.'/adherents/list.php">'.$langs->trans("BackToList").'</a>'; - -dol_banner_tab($object, 'rowid', $linkback); - -print '<div class="fichecenter">'; - -print '<div class="underbanner clearboth"></div>'; - -print '<br>'; -dol_print_object_info($object); - -print '</div>'; - -dol_fiche_end(); - - -llxFooter(); -$db->close(); diff --git a/htdocs/adherents/subscription/card.php b/htdocs/adherents/subscription/card.php index fb762a24345..ce3baee712b 100644 --- a/htdocs/adherents/subscription/card.php +++ b/htdocs/adherents/subscription/card.php @@ -21,7 +21,7 @@ * \brief Page to add/edit/remove a member subscription */ -require '../main.inc.php'; +require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php'; require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php'; diff --git a/htdocs/adherents/subscription/info.php b/htdocs/adherents/subscription/info.php index 4e82d959a28..5c5799ec2a5 100644 --- a/htdocs/adherents/subscription/info.php +++ b/htdocs/adherents/subscription/info.php @@ -22,7 +22,7 @@ * \brief Page with information of subscriptions of a member */ -require '../main.inc.php'; +require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php'; diff --git a/htdocs/adherents/subscription/list.php b/htdocs/adherents/subscription/list.php index c46c1ee0904..6062bb12567 100644 --- a/htdocs/adherents/subscription/list.php +++ b/htdocs/adherents/subscription/list.php @@ -23,7 +23,7 @@ * \brief list of subscription */ -require '../main.inc.php'; +require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 25a19868a45..49092d6e58e 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -3572,9 +3572,9 @@ class Commande extends CommonOrder } /** - * Create a document onto disk accordign to template module. + * Create a document onto disk according to template module. * - * @param string $modele Force le mnodele a utiliser ('' to not force) + * @param string $modele Force template to use ('' to not force) * @param Translate $outputlangs objet lang a utiliser pour traduction * @param int $hidedetails Hide details of lines * @param int $hidedesc Hide description diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 1457d10726c..c96eb2124f6 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -3753,30 +3753,30 @@ abstract class CommonObject { global $user; - $this->db->begin(); $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_resources"; $sql.= " WHERE rowid=".$rowid; dol_syslog(get_class($this)."::delete_resource", LOG_DEBUG); - $resql=$this->db->query($sql); - if (! $resql) - { - $this->error=$this->db->lasterror(); - $this->db->rollback(); - return -1; - } - else + + $resql=$this->db->query($sql); + if (! $resql) + { + $this->error=$this->db->lasterror(); + $this->db->rollback(); + return -1; + } + else + { + if (! $notrigger) { - if (! $notrigger) - { - $result=$this->call_trigger(strtoupper($element).'_DELETE_RESOURCE', $user); - if ($result < 0) { $this->db->rollback(); return -1; } - } - $this->db->commit(); - return 1; + $result=$this->call_trigger(strtoupper($element).'_DELETE_RESOURCE', $user); + if ($result < 0) { $this->db->rollback(); return -1; } } + $this->db->commit(); + return 1; + } } @@ -3837,7 +3837,8 @@ abstract class CommonObject { foreach(array('doc','pdf') as $prefix) { - $file = $prefix."_".$modele.".modules.php"; + if (in_array(get_class($this), array('Adherent'))) $file = $prefix."_".$modele.".class.php"; // Member module use prefix_module.class.php + else $file = $prefix."_".$modele.".modules.php"; // On verifie l'emplacement du modele $file=dol_buildpath($reldir.$modelspath.$file,0); @@ -3854,6 +3855,8 @@ abstract class CommonObject // If generator was found if ($filefound) { + global $db; // Required to solve a conception default in commonstickergenerator.class.php making an include of code using $db + require_once $file; $obj = new $classname($this->db); @@ -3911,7 +3914,15 @@ abstract class CommonObject // We save charset_output to restore it because write_file can change it if needed for // output format that does not support UTF8. $sav_charset_output=$outputlangs->charset_output; - if ($obj->write_file($this, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0) + + if (in_array(get_class($this), array('Adherent'))) + { + $arrayofrecords = array(); + $resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, 'member', 1); + } + else $resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref); + + if ($resultwritefile > 0) { $outputlangs->charset_output=$sav_charset_output; diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index f50803fa451..e9eedb0e32e 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -5640,10 +5640,10 @@ class Form $dir=$conf->adherent->dir_output; if (! empty($object->photo)) { - if ((string) $imagesize == 'mini') $file=get_exdir($id, 2, 0, 0, $object, 'member').'photos/'.getImageFileNameForSize($object->photo, '_mini'); - else if ((string) $imagesize == 'small') $file=get_exdir($id, 2, 0, 0, $object, 'member').'photos/'.getImageFileNameForSize($object->photo, '_small'); - else $file=get_exdir($id, 2, 0, 0, $object, 'member').'photos/'.$object->photo; - $originalfile=get_exdir($id, 2, 0, 0, $object, 'member').'photos/'.$object->photo; + if ((string) $imagesize == 'mini') $file=get_exdir(0, 0, 0, 0, $object, 'member').'photos/'.getImageFileNameForSize($object->photo, '_mini'); + else if ((string) $imagesize == 'small') $file=get_exdir(0, 0, 0, 0, $object, 'member').'photos/'.getImageFileNameForSize($object->photo, '_small'); + else $file=get_exdir(0, 0, 0, 0, $object, 'member').'photos/'.$object->photo; + $originalfile=get_exdir(0, 0, 0, 0, $object, 'member').'photos/'.$object->photo; } if (! empty($conf->global->MAIN_OLD_IMAGE_LINKS)) $altfile=$object->id.".jpg"; // For backward compatibility $email=$object->email; diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index b8fab63f906..e4cb365adfc 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -461,6 +461,15 @@ class FormFile $modellist=ModeleDon::liste_modeles($this->db); } } + elseif ($modulepart == 'member') + { + if (is_array($genallowed)) $modellist=$genallowed; + else + { + include_once DOL_DOCUMENT_ROOT.'/core/modules/member/modules_cards.php'; + $modellist=ModelePDFCards::liste_modeles($this->db); + } + } elseif ($modulepart == 'agenda') { if (is_array($genallowed)) $modellist=$genallowed; @@ -913,7 +922,6 @@ class FormFile { $relativepath=(! empty($object->ref)?dol_sanitizeFileName($object->ref):'').'/'; if ($object->element == 'invoice_supplier') $relativepath=get_exdir($object->id,2,0,0,$object,'invoice_supplier').$relativepath; // TODO Call using a defined value for $relativepath - if ($object->element == 'member') $relativepath=get_exdir($object->id,2,0,0,$object,'member').$relativepath; // TODO Call using a defined value for $relativepath if ($object->element == 'project_task') $relativepath='Call_not_supported_._Call_function_using_a_defined_relative_path_.'; } // For backward compatiblity, we detect file is stored into an old path diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index e98dd142e1e..828c4c301ff 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -4239,7 +4239,7 @@ function get_exdir($num,$level,$alpha,$withoutslash,$object,$modulepart) // TODO // We will enhance here a common way of forging path for document storage // Here, object->id, object->ref and object->modulepart are required. - if (in_array($modulepart, array('thirdparty','contact'))) + if (in_array($modulepart, array('thirdparty','contact','member'))) { $path=$object->ref?$object->ref:$object->id; } diff --git a/htdocs/core/lib/functions2.lib.php b/htdocs/core/lib/functions2.lib.php index a6fa6839fb8..98b1946d772 100644 --- a/htdocs/core/lib/functions2.lib.php +++ b/htdocs/core/lib/functions2.lib.php @@ -1524,7 +1524,7 @@ function getListOfModels($db,$type,$maxfilenamelength=0) // If this generation module needs to scan a directory, then description field is filled // with the constant that contains list of directories to scan (COMPANY_ADDON_PDF_ODT_PATH, ...). - if (! empty($obj->description)) // List of directories to scan is defined + if (! empty($obj->description)) // A list of directories to scan is defined { include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; @@ -1562,7 +1562,19 @@ function getListOfModels($db,$type,$maxfilenamelength=0) } else { - $liste[$obj->id]=$obj->label?$obj->label:$obj->lib; + if ($type == 'member' && $obj->lib == 'standard') // Special case, if member template, we add variant per format + { + global $_Avery_Labels; + include_once DOL_DOCUMENT_ROOT.'/core/lib/format_cards.lib.php'; + foreach($_Avery_Labels as $key => $val) + { + $liste[$obj->id.':'.$key]=($obj->label?$obj->label:$obj->lib).' '.$val['name']; + } + } + else // Common usage + { + $liste[$obj->id]=$obj->label?$obj->label:$obj->lib; + } } $i++; } diff --git a/htdocs/core/lib/member.lib.php b/htdocs/core/lib/member.lib.php index 47986ac8ee8..574f7a5b950 100644 --- a/htdocs/core/lib/member.lib.php +++ b/htdocs/core/lib/member.lib.php @@ -59,15 +59,6 @@ function member_prepare_head(Adherent $object) $h++; } - // Show agenda tab - if (! empty($conf->agenda->enabled)) - { - $head[$h][0] = DOL_URL_ROOT."/adherents/agenda.php?id=".$object->id; - $head[$h][1] = $langs->trans('Agenda'); - $head[$h][2] = 'agenda'; - $h++; - } - // Show more tabs from modules // Entries must be declared in modules descriptor with line // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab @@ -87,7 +78,7 @@ function member_prepare_head(Adherent $object) // Attachments require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php'; - $upload_dir = $conf->adherent->multidir_output[$object->entity].'/'.get_exdir($object->id,2,0,1,$object,'member').'/'.dol_sanitizeFileName($object->ref); + $upload_dir = $conf->adherent->multidir_output[$object->entity].'/'.get_exdir(0,0,0,1,$object,'member'); $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview\.png)$')); $nbLinks=Link::count($db, $object->element, $object->id); $head[$h][0] = DOL_URL_ROOT.'/adherents/document.php?id='.$object->id; @@ -96,12 +87,20 @@ function member_prepare_head(Adherent $object) $head[$h][2] = 'document'; $h++; - $head[$h][0] = DOL_URL_ROOT.'/adherents/info.php?id='.$object->id; - $head[$h][1] = $langs->trans("Info"); - $head[$h][2] = 'info'; - $h++; - - + // Show agenda tab + if (! empty($conf->agenda->enabled)) + { + $head[$h][0] = DOL_URL_ROOT."/adherents/agenda.php?id=".$object->id; + $head[$h][1] = $langs->trans("Events"); + if (! empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read) )) + { + $head[$h][1].= '/'; + $head[$h][1].= $langs->trans("Agenda"); + } + $head[$h][2] = 'agenda'; + $h++; + } + complete_head_from_modules($conf,$langs,$object,$head,$h,'member','remove'); return $head; diff --git a/htdocs/core/modules/member/doc/pdf_standard.class.php b/htdocs/core/modules/member/doc/pdf_standard.class.php index 7d369d34b7c..40547633adc 100644 --- a/htdocs/core/modules/member/doc/pdf_standard.class.php +++ b/htdocs/core/modules/member/doc/pdf_standard.class.php @@ -23,7 +23,7 @@ /** * \file htdocs/core/modules/member/doc/pdf_standard.class.php * \ingroup member - * \brief Fichier de la classe permettant d'editer au format PDF des etiquettes au format Avery ou personnalise + * \brief File of class to generate PDF document of labels */ require_once DOL_DOCUMENT_ROOT.'/core/class/commonstickergenerator.class.php'; @@ -63,7 +63,7 @@ class pdf_standard extends CommonStickerGenerator */ function Add_PDF_card(&$pdf,$textleft,$header,$footer,$outputlangs,$textright='',$idmember=0,$photo='') { - global $mysoc,$conf,$langs; + global $db,$mysoc,$conf,$langs; global $forceimgscalewidth,$forceimgscaleheight; $imgscalewidth=(empty($forceimgscalewidth)?0.3:$forceimgscalewidth); // Scale of image for width (1=Full width of sticker) @@ -92,11 +92,15 @@ class pdf_standard extends CommonStickerGenerator } } + $member=new Adherent($db); + $member->id = $idmember; + $member->ref = $idmember; + // Define photo $dir=$conf->adherent->dir_output; if (! empty($photo)) { - $file=get_exdir($idmember,2,0,0,null,'member').'photos/'.$photo; + $file=get_exdir(0,0,0,0,$member,'member').'photos/'.$photo; $photo=$dir.'/'.$file; if (! is_readable($photo)) $photo=''; } @@ -231,19 +235,79 @@ class pdf_standard extends CommonStickerGenerator } /** - * Function to build PDF on disk, then output on HTTP strem. + * Function to build PDF on disk, then output on HTTP stream. * - * @param array $arrayofrecords Array of record informations (array('textleft'=>,'textheader'=>, ...'id'=>,'photo'=>) + * @param Adherent $arrayofrecords New: Member object, Old: Array of record informations (array('textleft'=>,'textheader'=>, ...'id'=>,'photo'=>) * @param Translate $outputlangs Lang object for output language - * @param string $srctemplatepath Full path of source filename for generator using a template file + * @param string $srctemplatepath Full path of source filename for generator using a template file. Example: '5161', 'AVERYC32010', 'CARD', ... * @param string $mode Tell if doc module is called for 'member', ... + * @param int $nooutput 1=Generate only file on disk and do not return it on response * @return int 1=OK, 0=KO */ - function write_file($arrayofrecords,$outputlangs,$srctemplatepath,$mode='member') + function write_file($object, $outputlangs, $srctemplatepath, $mode='member', $noouput=0) { global $user,$conf,$langs,$mysoc,$_Avery_Labels; - + $this->code=$srctemplatepath; + + if (is_object($object)) + { + if ($object->country == '-') $object->country=''; + + // List of values to scan for a replacement + $substitutionarray = array ( + '%ID%'=>$object->rowid, + '%LOGIN%'=>$object->login, + '%FIRSTNAME%'=>$object->firstname, + '%LASTNAME%'=>$object->lastname, + '%FULLNAME%'=>$object->getFullName($langs), + '%COMPANY%'=>$object->company, + '%ADDRESS%'=>$object->address, + '%ZIP%'=>$object->zip, + '%TOWN%'=>$object->town, + '%COUNTRY%'=>$object->country, + '%COUNTRY_CODE%'=>$object->country_code, + '%EMAIL%'=>$object->email, + '%BIRTH%'=>dol_print_date($object->birth,'day'), + '%TYPE%'=>$object->type, + '%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 + $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); + + $nb = $_Avery_Labels[$this->code]['NX'] * $_Avery_Labels[$this->code]['NY']; + if ($nb <= 0) $nb=1; // Protection to avoid empty page + + for($j=0;$j<$nb;$j++) + { + $arrayofmembers[]=array( + 'textleft'=>$textleft, + 'textheader'=>$textheader, + 'textfooter'=>$textfooter, + 'textright'=>$textright, + 'id'=>$object->rowid, + 'photo'=>$object->photo + ); + } + + $arrayofrecords = $arrayofmembers; + } + else + { + $arrayofrecords = $object; + } + + //var_dump($arrayofrecords);exit; + $this->Tformat = $_Avery_Labels[$this->code]; if (empty($this->Tformat)) { dol_print_error('','ErrorBadTypeForCard'.$this->code); exit; } $this->type = 'pdf'; @@ -270,7 +334,6 @@ class pdf_standard extends CommonStickerGenerator { $title=$outputlangs->transnoentities('MembersCards'); $keywords=$outputlangs->transnoentities('MembersCards')." ".$outputlangs->transnoentities("Foundation")." ".$outputlangs->convToOutputCharset($mysoc->name); - $outputdir=$conf->adherent->dir_temp; } else { @@ -278,9 +341,21 @@ class pdf_standard extends CommonStickerGenerator return -1; } - $dir = $outputdir; $filename = 'tmp_cards.pdf'; - $file = $dir."/".$filename; + if (is_object($object)) + { + $outputdir = $conf->adherent->dir_output; + $dir = $outputdir."/".get_exdir(0, 0, 0, 0, $object, 'member'); + $file = $dir.'/'.$filename; + } + else + { + $outputdir = $conf->adherent->dir_temp; + $dir = $outputdir; + $file = $dir.'/'.$filename; + } + + //var_dump($file);exit; if (! file_exists($dir)) { @@ -344,23 +419,26 @@ class pdf_standard extends CommonStickerGenerator // Output to http stream - clearstatcache(); - - $attachment=true; - if (! empty($conf->global->MAIN_DISABLE_FORCE_SAVEAS)) $attachment=false; - $type=dol_mimetype($filename); - - //if ($encoding) header('Content-Encoding: '.$encoding); - if ($type) header('Content-Type: '.$type); - if ($attachment) header('Content-Disposition: attachment; filename="'.$filename.'"'); - else header('Content-Disposition: inline; filename="'.$filename.'"'); - - // Ajout directives pour resoudre bug IE - header('Cache-Control: Public, must-revalidate'); - header('Pragma: public'); - - readfile($file); - + if (empty($noouput)) + { + clearstatcache(); + + $attachment=true; + if (! empty($conf->global->MAIN_DISABLE_FORCE_SAVEAS)) $attachment=false; + $type=dol_mimetype($filename); + + //if ($encoding) header('Content-Encoding: '.$encoding); + if ($type) header('Content-Type: '.$type); + if ($attachment) header('Content-Disposition: attachment; filename="'.$filename.'"'); + else header('Content-Disposition: inline; filename="'.$filename.'"'); + + // Ajout directives pour resoudre bug IE + header('Cache-Control: Public, must-revalidate'); + header('Pragma: public'); + + readfile($file); + } + return 1; } diff --git a/htdocs/core/modules/member/modules_cards.php b/htdocs/core/modules/member/modules_cards.php index 9a8b931125d..f7ef8b94590 100644 --- a/htdocs/core/modules/member/modules_cards.php +++ b/htdocs/core/modules/member/modules_cards.php @@ -48,7 +48,7 @@ class ModelePDFCards { global $conf; - $type='members_card'; + $type='member'; $liste=array(); include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; @@ -99,7 +99,7 @@ function members_card_pdf_create($db, $arrayofmembers, $modele, $outputlangs, $o } } else $code=$modele; - + // If selected modele is a filename template (then $modele="modelname:filename") $tmp=explode(':',$template,2); if (! empty($tmp[1])) diff --git a/htdocs/install/mysql/migration/4.0.0-5.0.0.sql b/htdocs/install/mysql/migration/4.0.0-5.0.0.sql index 33a53a21763..aefe62a0189 100644 --- a/htdocs/install/mysql/migration/4.0.0-5.0.0.sql +++ b/htdocs/install/mysql/migration/4.0.0-5.0.0.sql @@ -27,6 +27,8 @@ ALTER TABLE llx_product_lot MODIFY COLUMN entity integer DEFAULT 1; UPDATE llx_product_lot SET entity = 1 WHERE entity IS NULL; +ALTER TABLE llx_adherent ADD COLUMN model_pdf varchar(255); + ALTER TABLE llx_don ADD COLUMN date_valid datetime; DELETE FROM llx_menu where module='expensereport'; diff --git a/htdocs/install/mysql/tables/llx_adherent.sql b/htdocs/install/mysql/tables/llx_adherent.sql index 9af9f5b1f26..37b01a59dc3 100644 --- a/htdocs/install/mysql/tables/llx_adherent.sql +++ b/htdocs/install/mysql/tables/llx_adherent.sql @@ -57,6 +57,7 @@ create table llx_adherent datefin datetime, -- date de fin de validite de la cotisation note_private text DEFAULT NULL, note_public text DEFAULT NULL, + model_pdf varchar(255), datevalid datetime, -- date de validation datec datetime, -- date de creation tms timestamp, -- date de modification -- GitLab