6 | *
7 | * This program is free software; you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation; either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 |
21 | /**
22 | * \file distributionlist/distributionlistindex.php
23 | * \ingroup distributionlist
24 | * \brief Home page of distributionlist top menu
25 | */
26 |
27 | // Load Dolibarr environment
28 | $res = 0;
29 | // Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
30 | if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
31 | // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
32 | $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
33 | while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { $i--; $j--; }
34 | if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
35 | if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
36 | // Try main.inc.php using relative path
37 | if (!$res && file_exists("../main.inc.php")) $res = @include "../main.inc.php";
38 | if (!$res && file_exists("../../main.inc.php")) $res = @include "../../main.inc.php";
39 | if (!$res && file_exists("../../../main.inc.php")) $res = @include "../../../main.inc.php";
40 | if (!$res) die("Include of main fails");
41 |
42 | require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
43 |
44 | // Load translation files required by the page
45 | $langs->loadLangs(array("distributionlist@distributionlist"));
46 |
47 | $action = GETPOST('action', 'alpha');
48 |
49 |
50 | // Security check
51 | //if (! $user->rights->distributionlist->myobject->read) accessforbidden();
52 | $socid = GETPOST('socid', 'int');
53 | if (isset($user->socid) && $user->socid > 0)
54 | {
55 | $action = '';
56 | $socid = $user->socid;
57 | }
58 |
59 | $max = 5;
60 | $now = dol_now();
61 |
62 |
63 | /*
64 | * Actions
65 | */
66 |
67 | // None
68 |
69 |
70 | /*
71 | * View
72 | */
73 |
74 | $form = new Form($db);
75 | $formfile = new FormFile($db);
76 |
77 | llxHeader("", $langs->trans("DistributionListArea"));
78 |
79 | print load_fiche_titre($langs->trans("DistributionListArea"), '', 'distributionlist.png@distributionlist');
80 |
81 | print '';
82 |
83 |
84 | /* BEGIN MODULEBUILDER DRAFT MYOBJECT
85 | // Draft MyObject
86 | if (! empty($conf->distributionlist->enabled) && $user->rights->distributionlist->read)
87 | {
88 | $langs->load("orders");
89 |
90 | $sql = "SELECT c.rowid, c.ref, c.ref_client, c.total_ht, c.tva as total_tva, c.total_ttc, s.rowid as socid, s.nom as name, s.client, s.canvas";
91 | $sql.= ", s.code_client";
92 | $sql.= " FROM ".MAIN_DB_PREFIX."commande as c";
93 | $sql.= ", ".MAIN_DB_PREFIX."societe as s";
94 | if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
95 | $sql.= " WHERE c.fk_soc = s.rowid";
96 | $sql.= " AND c.fk_statut = 0";
97 | $sql.= " AND c.entity IN (".getEntity('commande').")";
98 | if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
99 | if ($socid) $sql.= " AND c.fk_soc = ".$socid;
100 |
101 | $resql = $db->query($sql);
102 | if ($resql)
103 | {
104 | $total = 0;
105 | $num = $db->num_rows($resql);
106 |
107 | print '
';
108 | print '';
109 | print '| '.$langs->trans("DraftOrders").($num?''.$num.'':'').' |
';
110 |
111 | $var = true;
112 | if ($num > 0)
113 | {
114 | $i = 0;
115 | while ($i < $num)
116 | {
117 |
118 | $obj = $db->fetch_object($resql);
119 | print '| ';
120 | $orderstatic->id=$obj->rowid;
121 | $orderstatic->ref=$obj->ref;
122 | $orderstatic->ref_client=$obj->ref_client;
123 | $orderstatic->total_ht = $obj->total_ht;
124 | $orderstatic->total_tva = $obj->total_tva;
125 | $orderstatic->total_ttc = $obj->total_ttc;
126 | print $orderstatic->getNomUrl(1);
127 | print ' | ';
128 | print '';
129 | $companystatic->id=$obj->socid;
130 | $companystatic->name=$obj->name;
131 | $companystatic->client=$obj->client;
132 | $companystatic->code_client = $obj->code_client;
133 | $companystatic->code_fournisseur = $obj->code_fournisseur;
134 | $companystatic->canvas=$obj->canvas;
135 | print $companystatic->getNomUrl(1,'customer',16);
136 | print ' | ';
137 | print ''.price($obj->total_ttc).' |
';
138 | $i++;
139 | $total += $obj->total_ttc;
140 | }
141 | if ($total>0)
142 | {
143 |
144 | print '| '.$langs->trans("Total").' | '.price($total)." |
";
145 | }
146 | }
147 | else
148 | {
149 |
150 | print '| '.$langs->trans("NoOrder").' |
';
151 | }
152 | print "
";
153 |
154 | $db->free($resql);
155 | }
156 | else
157 | {
158 | dol_print_error($db);
159 | }
160 | }
161 | END MODULEBUILDER DRAFT MYOBJECT */
162 |
163 |
164 | print '
';
165 |
166 |
167 | $NBMAX = 3;
168 | $max = 3;
169 |
170 | /* BEGIN MODULEBUILDER LASTMODIFIED MYOBJECT
171 | // Last modified myobject
172 | if (! empty($conf->distributionlist->enabled) && $user->rights->distributionlist->read)
173 | {
174 | $sql = "SELECT s.rowid, s.nom as name, s.client, s.datec, s.tms, s.canvas";
175 | $sql.= ", s.code_client";
176 | $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
177 | if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
178 | $sql.= " WHERE s.client IN (1, 2, 3)";
179 | $sql.= " AND s.entity IN (".getEntity($companystatic->element).")";
180 | if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
181 | if ($socid) $sql.= " AND s.rowid = $socid";
182 | $sql .= " ORDER BY s.tms DESC";
183 | $sql .= $db->plimit($max, 0);
184 |
185 | $resql = $db->query($sql);
186 | if ($resql)
187 | {
188 | $num = $db->num_rows($resql);
189 | $i = 0;
190 |
191 | print '
';
192 | print '';
193 | print '| ';
194 | if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) print $langs->trans("BoxTitleLastCustomersOrProspects",$max);
195 | else if (! empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) print $langs->trans("BoxTitleLastModifiedProspects",$max);
196 | else print $langs->trans("BoxTitleLastModifiedCustomers",$max);
197 | print ' | ';
198 | print ''.$langs->trans("DateModificationShort").' | ';
199 | print '
';
200 | if ($num)
201 | {
202 | while ($i < $num)
203 | {
204 | $objp = $db->fetch_object($resql);
205 | $companystatic->id=$objp->rowid;
206 | $companystatic->name=$objp->name;
207 | $companystatic->client=$objp->client;
208 | $companystatic->code_client = $objp->code_client;
209 | $companystatic->code_fournisseur = $objp->code_fournisseur;
210 | $companystatic->canvas=$objp->canvas;
211 | print '';
212 | print '| '.$companystatic->getNomUrl(1,'customer',48).' | ';
213 | print '';
214 | print $companystatic->getLibCustProspStatut();
215 | print " | ";
216 | print ''.dol_print_date($db->jdate($objp->tms),'day')." | ";
217 | print '
';
218 | $i++;
219 |
220 |
221 | }
222 |
223 | $db->free($resql);
224 | }
225 | else
226 | {
227 | print '| '.$langs->trans("None").' |
';
228 | }
229 | print "
";
230 | }
231 | }
232 | */
233 |
234 | print '
';
235 |
236 | // End of page
237 | llxFooter();
238 | $db->close();
239 |
--------------------------------------------------------------------------------
/distributionlist_document.php:
--------------------------------------------------------------------------------
1 |
3 | * Copyright (C) ---Put here your own copyright and developer email---
4 | *
5 | * This program is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation; either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | /**
20 | * \file distributionlist_document.php
21 | * \ingroup distributionlist
22 | * \brief Tab for documents linked to DistributionList
23 | */
24 |
25 | // Load Dolibarr environment
26 | $res = 0;
27 | // Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
28 | if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
29 | // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
30 | $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
31 | while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { $i--; $j--; }
32 | if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
33 | if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
34 | // Try main.inc.php using relative path
35 | if (!$res && file_exists("../main.inc.php")) $res = @include "../main.inc.php";
36 | if (!$res && file_exists("../../main.inc.php")) $res = @include "../../main.inc.php";
37 | if (!$res && file_exists("../../../main.inc.php")) $res = @include "../../../main.inc.php";
38 | if (!$res) die("Include of main fails");
39 |
40 | require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
41 | require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
42 | require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
43 | require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
44 | dol_include_once('/distributionlist/class/distributionlist.class.php');
45 | dol_include_once('/distributionlist/lib/distributionlist_distributionlist.lib.php');
46 |
47 | // Load translation files required by the page
48 | $langs->loadLangs(array("distributionlist@distributionlist", "companies", "other", "mails"));
49 |
50 |
51 | $action = GETPOST('action', 'aZ09');
52 | $confirm = GETPOST('confirm');
53 | $id = (GETPOST('socid', 'int') ? GETPOST('socid', 'int') : GETPOST('id', 'int'));
54 | $ref = GETPOST('ref', 'alpha');
55 |
56 | // Get parameters
57 | $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
58 | $sortfield = GETPOST("sortfield", 'alpha');
59 | $sortorder = GETPOST("sortorder", 'alpha');
60 | $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
61 | if (empty($page) || $page == -1) $page = 0; // If $page is not defined, or '' or -1
62 | if (!empty($liste_limit) && intval($liste_limit) > 0) $offset = $liste_limit * $page;
63 | $pageprev = $page - 1;
64 | $pagenext = $page + 1;
65 | if (!$sortorder) $sortorder = "ASC";
66 | if (!$sortfield) $sortfield = "name";
67 | //if (! $sortfield) $sortfield="position_name";
68 |
69 | // Initialize technical objects
70 | $object = new DistributionList($db);
71 | $extrafields = new ExtraFields($db);
72 | $diroutputmassaction = $conf->distributionlist->dir_output.'/temp/massgeneration/'.$user->id;
73 | $hookmanager->initHooks(array('distributionlistdocument', 'globalcard')); // Note that conf->hooks_modules contains array
74 | // Fetch optionals attributes and labels
75 | $extrafields->fetch_name_optionals_label($object->table_element);
76 |
77 | // Load object
78 | include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
79 |
80 | //if ($id > 0 || ! empty($ref)) $upload_dir = $conf->distributionlist->multidir_output[$object->entity?$object->entity:$conf->entity] . "/distributionlist/" . dol_sanitizeFileName($object->id);
81 | if ($id > 0 || !empty($ref)) $upload_dir = $conf->distributionlist->multidir_output[$object->entity ? $object->entity : $conf->entity]."/distributionlist/".dol_sanitizeFileName($object->ref);
82 |
83 | // Security check - Protection if external user
84 | //if ($user->socid > 0) accessforbidden();
85 | //if ($user->socid > 0) $socid = $user->socid;
86 | //$result = restrictedArea($user, 'distributionlist', $object->id);
87 |
88 | $permissiontoadd = $user->hasRight('distributionlist', 'distributionlist', 'create'); // Used by the include of actions_addupdatedelete.inc.php
89 |
90 |
91 |
92 | /*
93 | * Actions
94 | */
95 |
96 | include_once DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
97 |
98 |
99 | /*
100 | * View
101 | */
102 |
103 | $form = new Form($db);
104 |
105 | $title = $langs->trans("DistributionList").' - '.$langs->trans("Files");
106 | $help_url = '';
107 | //$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
108 | llxHeader('', $title, $help_url);
109 |
110 | if ($object->id)
111 | {
112 | /*
113 | * Show tabs
114 | */
115 | $head = distributionlistPrepareHead($object);
116 |
117 | dol_fiche_head($head, 'document', $langs->trans("DistributionList"), -1, $object->picto);
118 |
119 |
120 | // Build file list
121 | $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
122 | $totalsize = 0;
123 | foreach ($filearray as $key => $file)
124 | {
125 | $totalsize += $file['size'];
126 | }
127 |
128 | // Object card
129 | // ------------------------------------------------------------
130 | $linkback = ''.$langs->trans("BackToList").'';
131 |
132 | $morehtmlref = '';
133 | /*
134 | // Ref customer
135 | $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
136 | $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
137 | // Thirdparty
138 | $morehtmlref.='
'.$langs->trans('ThirdParty') . ' : ' . (is_object($object->thirdparty) ? $object->thirdparty->getNomUrl(1) : '');
139 | // Project
140 | if (! empty($conf->projet->enabled))
141 | {
142 | $langs->load("projects");
143 | $morehtmlref.='
'.$langs->trans('Project') . ' ';
144 | if ($permissiontoadd)
145 | {
146 | if ($action != 'classify')
147 | //$morehtmlref.='
' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' : ';
148 | $morehtmlref.=' : ';
149 | if ($action == 'classify') {
150 | //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
151 | $morehtmlref.='
';
157 | } else {
158 | $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
159 | }
160 | } else {
161 | if (! empty($object->fk_project)) {
162 | $proj = new Project($db);
163 | $proj->fetch($object->fk_project);
164 | $morehtmlref .= ': '.$proj->getNomUrl();
165 | } else {
166 | $morehtmlref .= '';
167 | }
168 | }
169 | }*/
170 | $morehtmlref .= '
';
171 |
172 | dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
173 |
174 | print '';
175 |
176 | print '
';
177 | print '
';
178 |
179 | // Number of files
180 | print '| '.$langs->trans("NbOfAttachedFiles").' | '.count($filearray).' |
';
181 |
182 | // Total size
183 | print '| '.$langs->trans("TotalSizeOfAttachedFiles").' | '.$totalsize.' '.$langs->trans("bytes").' |
';
184 |
185 | print '
';
186 |
187 | print '
';
188 |
189 | dol_fiche_end();
190 |
191 | $modulepart = 'distributionlist';
192 | $permission = $user->hasRight('distributionlist', 'distributionlist', 'create');
193 | // $permission = 1;
194 | $permtoedit = $user->hasRight('distributionlist', 'distributionlist', 'create');
195 | // $permtoedit = 1;
196 | $param = '&id=' . $object->id;
197 |
198 |
199 | //$relativepathwithnofile='distributionlist/' . dol_sanitizeFileName($object->id).'/';
200 | $relativepathwithnofile = 'distributionlist/'.dol_sanitizeFileName($object->ref).'/';
201 |
202 | include_once DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
203 | }
204 | else
205 | {
206 | accessforbidden('', 0, 1);
207 | }
208 |
209 | // End of page
210 | llxFooter();
211 | $db->close();
212 |
--------------------------------------------------------------------------------
/core/triggers/interface_99_moddistributionlist_distributionlisttrigger.class.php:
--------------------------------------------------------------------------------
1 | .
16 | */
17 |
18 | require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php';
19 | dol_include_once('/distributionlist/class/distributionlist.class.php');
20 | dol_include_once('/distributionlist/class/distributionlistsocpeople.class.php');
21 |
22 | /**
23 | * Class of triggers for Distributionlist module
24 | */
25 | class InterfaceDistributionlisttrigger extends DolibarrTriggers
26 | {
27 | /**
28 | * Constructor
29 | *
30 | * @param DoliDB $db Database handler
31 | */
32 | public function __construct($db)
33 | {
34 | $this->db = $db;
35 |
36 | $this->name = preg_replace('/^Interface/i', '', get_class($this));
37 | $this->family = "demo";
38 | $this->description = "Distributionlist triggers.";
39 | // 'development', 'experimental', 'dolibarr' or version
40 | $this->version = 'development';
41 | $this->picto = 'distributionlist@distributionlist';
42 | }
43 |
44 | /**
45 | * Trigger name
46 | *
47 | * @return string Name of trigger file
48 | */
49 | public function getName()
50 | {
51 | return $this->name;
52 | }
53 |
54 | /**
55 | * Trigger description
56 | *
57 | * @return string Description of trigger file
58 | */
59 | public function getDesc()
60 | {
61 | return $this->description;
62 | }
63 |
64 |
65 | /**
66 | * Function called when a Dolibarrr business event is done.
67 | * All functions "runTrigger" are triggered if file
68 | * is inside directory core/triggers
69 | *
70 | * @param string $action Event action code
71 | * @param CommonObject $object Object
72 | * @param User $user Object user
73 | * @param Translate $langs Object langs
74 | * @param Conf $conf Object conf
75 | * @return int <0 if KO, 0 if no triggered ran, >0 if OK
76 | */
77 | public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
78 | {
79 | if (empty($conf->distributionlist) || !isModEnabled('distributionlist')) {
80 | return 0; // If module is not enabled, we do nothing
81 | }
82 |
83 | // Put here code you want to execute when a Dolibarr business events occurs.
84 | // Data and type of action are stored into $object and $action
85 |
86 | // You can isolate code for each action in a separate method: this method should be named like the trigger in camelCase.
87 | // For example : COMPANY_CREATE => public function companyCreate($action, $object, User $user, Translate $langs, Conf $conf)
88 | $methodName = lcfirst(str_replace(' ', '', ucwords(str_replace('_', ' ', strtolower($action)))));
89 | $callback = array($this, $methodName);
90 | if (is_callable($callback)) {
91 | dol_syslog(
92 | "Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id
93 | );
94 |
95 | return call_user_func($callback, $action, $object, $user, $langs, $conf);
96 | };
97 |
98 | // Or you can execute some code here
99 | switch ($action) {
100 | // Users
101 | //case 'USER_CREATE':
102 | //case 'USER_MODIFY':
103 | //case 'USER_NEW_PASSWORD':
104 | //case 'USER_ENABLEDISABLE':
105 | //case 'USER_DELETE':
106 |
107 | // Actions
108 | //case 'ACTION_MODIFY':
109 | //case 'ACTION_CREATE':
110 | //case 'ACTION_DELETE':
111 |
112 | // Groups
113 | //case 'USERGROUP_CREATE':
114 | //case 'USERGROUP_MODIFY':
115 | //case 'USERGROUP_DELETE':
116 |
117 | // Companies
118 | //case 'COMPANY_CREATE':
119 | //case 'COMPANY_MODIFY':
120 | //case 'COMPANY_DELETE':
121 |
122 | // Contacts
123 | //case 'CONTACT_CREATE':
124 | //case 'CONTACT_MODIFY':
125 | case 'CONTACT_DELETE':
126 |
127 | //Si le contact est dans une ou plusieurs listes de diffusion, alors, lors de sa suppression, on le décompte dans le nombre de contacts
128 | $this->db->begin();
129 |
130 | $error = 0;
131 | $sql = "SELECT fk_distributionlist FROM ".MAIN_DB_PREFIX."distributionlist_distributionlistsocpeople WHERE fk_socpeople = " .intval($object->id);
132 | $resql = $this->db->query($sql);
133 | if($resql){
134 | while($obj = $this->db->fetch_object($resql)) {
135 | $distributionList = new DistributionList($this->db);
136 | $res = $distributionList->fetch($obj->fk_distributionlist);
137 | if ($res) {
138 | $distributionList->nb_contacts--;
139 | $distributionList->update($user);
140 |
141 | $distributionListSocpeople = new DistributionListSocpeople($this->db);
142 | $distributionListSocpeople->deleteByContact($object->id);
143 | }
144 | }
145 | } else {
146 | $error++;
147 | }
148 |
149 | if(!$error){
150 | $this->db->commit();
151 | } else {
152 | $this->db->rollback();
153 | }
154 |
155 | //case 'CONTACT_ENABLEDISABLE':
156 |
157 | // Products
158 | //case 'PRODUCT_CREATE':
159 | //case 'PRODUCT_MODIFY':
160 | //case 'PRODUCT_DELETE':
161 | //case 'PRODUCT_PRICE_MODIFY':
162 | //case 'PRODUCT_SET_MULTILANGS':
163 | //case 'PRODUCT_DEL_MULTILANGS':
164 |
165 | //Stock mouvement
166 | //case 'STOCK_MOVEMENT':
167 |
168 | //MYECMDIR
169 | //case 'MYECMDIR_CREATE':
170 | //case 'MYECMDIR_MODIFY':
171 | //case 'MYECMDIR_DELETE':
172 |
173 | // Customer orders
174 | //case 'ORDER_CREATE':
175 | //case 'ORDER_MODIFY':
176 | //case 'ORDER_VALIDATE':
177 | //case 'ORDER_DELETE':
178 | //case 'ORDER_CANCEL':
179 | //case 'ORDER_SENTBYMAIL':
180 | //case 'ORDER_CLASSIFY_BILLED':
181 | //case 'ORDER_SETDRAFT':
182 | //case 'LINEORDER_INSERT':
183 | //case 'LINEORDER_UPDATE':
184 | //case 'LINEORDER_DELETE':
185 |
186 | // Supplier orders
187 | //case 'ORDER_SUPPLIER_CREATE':
188 | //case 'ORDER_SUPPLIER_MODIFY':
189 | //case 'ORDER_SUPPLIER_VALIDATE':
190 | //case 'ORDER_SUPPLIER_DELETE':
191 | //case 'ORDER_SUPPLIER_APPROVE':
192 | //case 'ORDER_SUPPLIER_REFUSE':
193 | //case 'ORDER_SUPPLIER_CANCEL':
194 | //case 'ORDER_SUPPLIER_SENTBYMAIL':
195 | //case 'ORDER_SUPPLIER_DISPATCH':
196 | //case 'LINEORDER_SUPPLIER_DISPATCH':
197 | //case 'LINEORDER_SUPPLIER_CREATE':
198 | //case 'LINEORDER_SUPPLIER_UPDATE':
199 | //case 'LINEORDER_SUPPLIER_DELETE':
200 |
201 | // Proposals
202 | //case 'PROPAL_CREATE':
203 | //case 'PROPAL_MODIFY':
204 | //case 'PROPAL_VALIDATE':
205 | //case 'PROPAL_SENTBYMAIL':
206 | //case 'PROPAL_CLOSE_SIGNED':
207 | //case 'PROPAL_CLOSE_REFUSED':
208 | //case 'PROPAL_DELETE':
209 | //case 'LINEPROPAL_INSERT':
210 | //case 'LINEPROPAL_UPDATE':
211 | //case 'LINEPROPAL_DELETE':
212 |
213 | // SupplierProposal
214 | //case 'SUPPLIER_PROPOSAL_CREATE':
215 | //case 'SUPPLIER_PROPOSAL_MODIFY':
216 | //case 'SUPPLIER_PROPOSAL_VALIDATE':
217 | //case 'SUPPLIER_PROPOSAL_SENTBYMAIL':
218 | //case 'SUPPLIER_PROPOSAL_CLOSE_SIGNED':
219 | //case 'SUPPLIER_PROPOSAL_CLOSE_REFUSED':
220 | //case 'SUPPLIER_PROPOSAL_DELETE':
221 | //case 'LINESUPPLIER_PROPOSAL_INSERT':
222 | //case 'LINESUPPLIER_PROPOSAL_UPDATE':
223 | //case 'LINESUPPLIER_PROPOSAL_DELETE':
224 |
225 | // Contracts
226 | // case 'CONTRACT_CREATE':
227 |
228 | //case 'CONTRACT_MODIFY':
229 | //case 'CONTRACT_ACTIVATE':
230 | //case 'CONTRACT_CANCEL':
231 | //case 'CONTRACT_CLOSE':
232 | // case 'CONTRACT_DELETE':
233 |
234 |
235 | //case 'LINECONTRACT_INSERT':
236 | //case 'LINECONTRACT_UPDATE':
237 | //case 'LINECONTRACT_DELETE':
238 |
239 | // Bills
240 | //case 'BILL_CREATE':
241 | //case 'BILL_MODIFY':
242 | //case 'BILL_VALIDATE':
243 | //case 'BILL_UNVALIDATE':
244 | //case 'BILL_SENTBYMAIL':
245 | //case 'BILL_CANCEL':
246 | //case 'BILL_DELETE':
247 | //case 'BILL_PAYED':
248 | //case 'LINEBILL_INSERT':
249 | //case 'LINEBILL_UPDATE':
250 | //case 'LINEBILL_DELETE':
251 |
252 | //Supplier Bill
253 | //case 'BILL_SUPPLIER_CREATE':
254 | //case 'BILL_SUPPLIER_UPDATE':
255 | //case 'BILL_SUPPLIER_DELETE':
256 | //case 'BILL_SUPPLIER_PAYED':
257 | //case 'BILL_SUPPLIER_UNPAYED':
258 | //case 'BILL_SUPPLIER_VALIDATE':
259 | //case 'BILL_SUPPLIER_UNVALIDATE':
260 | //case 'LINEBILL_SUPPLIER_CREATE':
261 | //case 'LINEBILL_SUPPLIER_UPDATE':
262 | //case 'LINEBILL_SUPPLIER_DELETE':
263 |
264 | // Payments
265 | //case 'PAYMENT_CUSTOMER_CREATE':
266 | //case 'PAYMENT_SUPPLIER_CREATE':
267 | //case 'PAYMENT_ADD_TO_BANK':
268 | //case 'PAYMENT_DELETE':
269 |
270 | // Online
271 | //case 'PAYMENT_PAYBOX_OK':
272 | //case 'PAYMENT_PAYPAL_OK':
273 | //case 'PAYMENT_STRIPE_OK':
274 |
275 | // Donation
276 | //case 'DON_CREATE':
277 | //case 'DON_UPDATE':
278 | //case 'DON_DELETE':
279 |
280 | // Interventions
281 | //case 'FICHINTER_CREATE':
282 | //case 'FICHINTER_MODIFY':
283 | //case 'FICHINTER_VALIDATE':
284 | //case 'FICHINTER_DELETE':
285 | //case 'LINEFICHINTER_CREATE':
286 | //case 'LINEFICHINTER_UPDATE':
287 | //case 'LINEFICHINTER_DELETE':
288 |
289 | // Members
290 | //case 'MEMBER_CREATE':
291 | //case 'MEMBER_VALIDATE':
292 | //case 'MEMBER_SUBSCRIPTION':
293 | //case 'MEMBER_MODIFY':
294 | //case 'MEMBER_NEW_PASSWORD':
295 | //case 'MEMBER_RESILIATE':
296 | //case 'MEMBER_DELETE':
297 |
298 | // Categories
299 | //case 'CATEGORY_CREATE':
300 | //case 'CATEGORY_MODIFY':
301 | //case 'CATEGORY_DELETE':
302 | //case 'CATEGORY_SET_MULTILANGS':
303 |
304 | // Projects
305 | //case 'PROJECT_CREATE':
306 | //case 'PROJECT_MODIFY':
307 | //case 'PROJECT_DELETE':
308 |
309 | // Project tasks
310 | //case 'TASK_CREATE':
311 | //case 'TASK_MODIFY':
312 | //case 'TASK_DELETE':
313 |
314 | // Task time spent
315 | //case 'TASK_TIMESPENT_CREATE':
316 | //case 'TASK_TIMESPENT_MODIFY':
317 | //case 'TASK_TIMESPENT_DELETE':
318 | //case 'PROJECT_ADD_CONTACT':
319 | //case 'PROJECT_DELETE_CONTACT':
320 | //case 'PROJECT_DELETE_RESOURCE':
321 |
322 | // Shipping
323 | //case 'SHIPPING_CREATE':
324 | //case 'SHIPPING_MODIFY':
325 | //case 'SHIPPING_VALIDATE':
326 | //case 'SHIPPING_SENTBYMAIL':
327 | //case 'SHIPPING_BILLED':
328 | //case 'SHIPPING_CLOSED':
329 | //case 'SHIPPING_REOPEN':
330 | //case 'SHIPPING_DELETE':
331 |
332 | // and more...
333 |
334 | default:
335 | dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
336 | break;
337 | }
338 |
339 | return 0;
340 | }
341 | }
342 |
--------------------------------------------------------------------------------
/distributionlist_agenda.php:
--------------------------------------------------------------------------------
1 |
3 | * Copyright (C) ---Put here your own copyright and developer email---
4 | *
5 | * This program is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation; either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | /**
20 | * \file distributionlist_agenda.php
21 | * \ingroup distributionlist
22 | * \brief Page of DistributionList events
23 | */
24 |
25 | // Load Dolibarr environment
26 | $res = 0;
27 | // Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
28 | if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
29 | // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
30 | $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
31 | while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { $i--; $j--; }
32 | if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
33 | if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
34 | // Try main.inc.php using relative path
35 | if (!$res && file_exists("../main.inc.php")) $res = @include "../main.inc.php";
36 | if (!$res && file_exists("../../main.inc.php")) $res = @include "../../main.inc.php";
37 | if (!$res && file_exists("../../../main.inc.php")) $res = @include "../../../main.inc.php";
38 | if (!$res) die("Include of main fails");
39 |
40 | require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
41 | require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
42 | require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
43 | dol_include_once('/distributionlist/class/distributionlist.class.php');
44 | dol_include_once('/distributionlist/lib/distributionlist_distributionlist.lib.php');
45 |
46 |
47 | // Load translation files required by the page
48 | $langs->loadLangs(array("distributionlist@distributionlist", "other"));
49 |
50 | // Get parameters
51 | $id = GETPOST('id', 'int');
52 | $ref = GETPOST('ref', 'alpha');
53 | $action = GETPOST('action', 'alpha');
54 | $cancel = GETPOST('cancel', 'aZ09');
55 | $backtopage = GETPOST('backtopage', 'alpha');
56 |
57 | if (GETPOST('actioncode', 'array')) {
58 | $actioncode = GETPOST('actioncode', 'array', 3);
59 | if (!count($actioncode)) $actioncode = '0';
60 | } else {
61 | $postedActionCode = GETPOST("actioncode", "alpha", 3);
62 | $rawActionCode = GETPOST("actioncode", "alpha");
63 | $defaultFilter = getDolGlobalString('AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT');
64 | if ($postedActionCode !== '') {
65 | $actioncode = $postedActionCode;
66 | } elseif ($rawActionCode === '0') {
67 | $actioncode = '0';
68 | } elseif ($defaultFilter !== '') {
69 | $actioncode = '';
70 | } else {
71 | $actioncode = $defaultFilter;
72 | }
73 | }
74 | $search_agenda_label = GETPOST('search_agenda_label', 'alpha');
75 |
76 | $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
77 | $sortfield = GETPOST("sortfield", 'alpha');
78 | $sortorder = GETPOST("sortorder", 'alpha');
79 | $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
80 | if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
81 | $offset = $limit * $page;
82 | $pageprev = $page - 1;
83 | $pagenext = $page + 1;
84 | if (!$sortfield) $sortfield = 'a.datep,a.id';
85 | if (!$sortorder) $sortorder = 'DESC,DESC';
86 |
87 | // Initialize technical objects
88 | $object = new DistributionList($db);
89 | $extrafields = new ExtraFields($db);
90 | $diroutputmassaction = $conf->distributionlist->dir_output.'/temp/massgeneration/'.$user->id;
91 | $hookmanager->initHooks(array('distributionlistagenda', 'globalcard')); // Note that conf->hooks_modules contains array
92 | // Fetch optionals attributes and labels
93 | $extrafields->fetch_name_optionals_label($object->table_element);
94 |
95 | // Load object
96 | include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
97 | if (array_key_exists('$object->entity', $conf->distributionlist->multidir_output) && $id > 0 || !empty($ref)) {
98 | $upload_dir = $conf->distributionlist->multidir_output[$object->entity]."/".$object->id;
99 | }
100 |
101 | // Security check - Protection if external user
102 | //if ($user->socid > 0) accessforbidden();
103 | //if ($user->socid > 0) $socid = $user->socid;
104 | //$result = restrictedArea($user, 'distributionlist', $object->id);
105 |
106 | $permissiontoadd = $user->hasRight('distributionlist', 'distributionlist', 'create'); // Used by the include of actions_addupdatedelete.inc.php
107 |
108 |
109 | /*
110 | * Actions
111 | */
112 |
113 | $parameters = array('id'=>$id);
114 | $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
115 | if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
116 |
117 | if (empty($reshook))
118 | {
119 | // Cancel
120 | if (GETPOST('cancel', 'alpha') && !empty($backtopage))
121 | {
122 | header("Location: ".$backtopage);
123 | exit;
124 | }
125 |
126 | // Purge search criteria
127 | if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers
128 | {
129 | $actioncode = '';
130 | $search_agenda_label = '';
131 | }
132 | }
133 |
134 |
135 |
136 | /*
137 | * View
138 | */
139 |
140 | $form = new Form($db);
141 |
142 | if ($object->id > 0)
143 | {
144 | $title = $langs->trans("Agenda");
145 | //if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name." - ".$title;
146 | $help_url = '';
147 | llxHeader('', $title, $help_url);
148 |
149 | if (isModEnabled('notification')) $langs->load("mails");
150 | $head = distributionlistPrepareHead($object);
151 |
152 |
153 | dol_fiche_head($head, 'agenda', $langs->trans("DistributionList"), -1, $object->picto);
154 |
155 | // Object card
156 | // ------------------------------------------------------------
157 | $linkback = ''.$langs->trans("BackToList").'';
158 |
159 | $morehtmlref = '';
160 | /*
161 | // Ref customer
162 | $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
163 | $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
164 | // Thirdparty
165 | $morehtmlref.='
'.$langs->trans('ThirdParty') . ' : ' . (is_object($object->thirdparty) ? $object->thirdparty->getNomUrl(1) : '');
166 | // Project
167 | if (! empty($conf->projet->enabled))
168 | {
169 | $langs->load("projects");
170 | $morehtmlref.='
'.$langs->trans('Project') . ' ';
171 | if ($permissiontoadd)
172 | {
173 | if ($action != 'classify')
174 | //$morehtmlref.='
' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' : ';
175 | $morehtmlref.=' : ';
176 | if ($action == 'classify') {
177 | //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
178 | $morehtmlref.='
';
184 | } else {
185 | $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
186 | }
187 | } else {
188 | if (! empty($object->fk_project)) {
189 | $proj = new Project($db);
190 | $proj->fetch($object->fk_project);
191 | $morehtmlref .= ': '.$proj->getNomUrl();
192 | } else {
193 | $morehtmlref .= '';
194 | }
195 | }
196 | }*/
197 | $morehtmlref .= '
';
198 |
199 |
200 | dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
201 |
202 | print '';
203 | print '
';
204 |
205 | $object->info($object->id);
206 | dol_print_object_info($object, 1);
207 |
208 | print '
';
209 |
210 | dol_fiche_end();
211 |
212 |
213 |
214 | // Actions buttons
215 |
216 | $objthirdparty = $object;
217 | $objcon = new stdClass();
218 |
219 | $out = '&origin='.$object->element.'&originid='.$object->id;
220 | $permok = $user->hasRight('agenda', 'myactions', 'create');
221 | if ((!empty($objthirdparty->id) || !empty($objcon->id)) && $permok)
222 | {
223 | //$out.='trans("AddAnAction"),'filenew');
228 | //$out.="";
229 | }
230 |
231 |
232 | print '';
233 |
234 | if (isModEnabled('agenda'))
235 | {
236 | if ( $user->hasRight('agenda', 'myactions', 'create') || $user->hasRight('agenda', 'allactions', 'create'))
237 | {
238 | print '
'.$langs->trans("AddAction").'';
239 | }
240 | else
241 | {
242 | print '
'.$langs->trans("AddAction").'';
243 | }
244 | }
245 |
246 | print '
';
247 |
248 | if (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read')))
249 | {
250 | $param = '&id='.$object->id;
251 | $param .= !empty($socid) ?'&socid='.$socid : '';
252 | if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
253 | if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
254 |
255 |
256 | //print load_fiche_titre($langs->trans("ActionsOnDistributionList"), '', '');
257 |
258 | // List of all actions
259 | $filters = array();
260 | $filters['search_agenda_label'] = $search_agenda_label;
261 |
262 | // TODO Replace this with same code than into list.php
263 | show_actions_done($conf, $langs, $db, $object, null, 0, $actioncode, '', $filters, $sortfield, $sortorder, '');
264 | }
265 | }
266 |
267 | // End of page
268 | llxFooter();
269 | $db->close();
270 |
--------------------------------------------------------------------------------
/distributionlist_contact.php:
--------------------------------------------------------------------------------
1 |
3 | * Copyright (C) ---Put here your own copyright and developer email---
4 | *
5 | * This program is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation; either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | /**
20 | * \file distributionlist_note.php
21 | * \ingroup distributionlist
22 | * \brief Car with notes on DistributionList
23 | */
24 |
25 | // Load Dolibarr environment
26 | $res = 0;
27 | // Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
28 | if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
29 | // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
30 | $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
31 | while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { $i--; $j--; }
32 | if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
33 | if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
34 | // Try main.inc.php using relative path
35 | if (!$res && file_exists("../main.inc.php")) $res = @include "../main.inc.php";
36 | if (!$res && file_exists("../../main.inc.php")) $res = @include "../../main.inc.php";
37 | if (!$res && file_exists("../../../main.inc.php")) $res = @include "../../../main.inc.php";
38 | if (!$res) die("Include of main fails");
39 |
40 | dol_include_once('/distributionlist/class/distributionlist.class.php');
41 | dol_include_once('/distributionlist/class/tools_distributionlist.class.php');
42 | dol_include_once('/distributionlist/class/distributionlistsocpeople.class.php');
43 | dol_include_once('/distributionlist/class/distributionlistsocpeoplefilter.class.php');
44 | dol_include_once('/distributionlist/lib/distributionlist_distributionlist.lib.php');
45 | require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
46 |
47 | // Load translation files required by the page
48 | $langs->loadLangs(array("distributionlist@distributionlist", "companies", "mails", "main"));
49 |
50 | // Get parameters
51 | $id = GETPOST('id', 'int');
52 | $filter_id = GETPOST('filter', 'int');
53 | $ref = GETPOST('ref', 'alpha');
54 | $action = GETPOST('action', 'alpha');
55 | $massaction = GETPOST('massaction', 'alpha');
56 | $cancel = GETPOST('cancel', 'aZ09');
57 | $backtopage = GETPOST('backtopage', 'alpha');
58 | $label = GETPOST('label', 'alpha');
59 | $contacts = GETPOST('toselect');
60 | $confirm = GETPOST('confirm', 'alpha');
61 | $msg_to_display = GETPOST('msg_to_display', 'alpha');
62 | $style_msg_to_display = GETPOST('style_msg_to_display', 'alpha');
63 |
64 | // Initialize technical objects
65 | $object = new DistributionList($db);
66 | $extrafields = new ExtraFields($db);
67 | $diroutputmassaction = $conf->distributionlist->dir_output.'/temp/massgeneration/'.$user->id;
68 | $hookmanager->initHooks(array('distributionlistcontact', 'globalcard')); // Note that conf->hooks_modules contains array
69 | // Fetch optionals attributes and labels
70 | $extrafields->fetch_name_optionals_label($object->table_element);
71 |
72 | // Security check - Protection if external user
73 | //if ($user->socid > 0) accessforbidden();
74 | //if ($user->socid > 0) $socid = $user->socid;
75 | //$result = restrictedArea($user, 'distributionlist', $id);
76 |
77 | // Load object
78 | include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
79 | if (array_key_exists('$object->entity', $conf->distributionlist->multidir_output) && $id > 0 || !empty($ref)) $upload_dir = $conf->distributionlist->multidir_output[$object->entity]."/".$object->id;
80 |
81 | $permissionnote = $user->hasRight('distributionlist', 'distributionlist', 'create'); // Used by the include of actions_setnotes.inc.php
82 | $permissiontoadd = $user->hasRight('distributionlist', 'distributionlist', 'update'); // Used by the include of actions_addupdatedelete.inc.php
83 |
84 | $form = new Form($db);
85 |
86 | // Retrait des droits network car ici il n'y pas lieu d'effectuer ce type d'action
87 | unset($user->rights->network);
88 |
89 | /*
90 | * Actions
91 | */
92 |
93 | //include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
94 |
95 | // Si la liste est clôturée, on renvoie vers l'onlet fiche
96 | if($object->status > 1 || empty($permissiontoadd)) {
97 | header('Location: '.dol_buildpath('/distributionlist/distributionlist_card.php', 1).'?id='.$object->id);
98 | exit;
99 | }
100 |
101 |
102 | $TParamURL = $_REQUEST;
103 |
104 | // Suppression de la liste des contacts sélectionnés si existante pour ne pas remplir inutilement l'url lors de l'appel à la liste standard des contacts (sinon bug)
105 | unset($TParamURL['toselect']);
106 |
107 | // Pour l'enregistrement du filtre, on retire l'information de la page car au moment de l'application du filtre c'est bizarre de tomber sur une page > à la première
108 | if($action === 'confirm_add_filter' && $confirm === 'yes') {
109 | unset($TParamURL['page']);
110 | unset($TParamURL['pageplusone']);
111 | unset($TParamURL['limit']);
112 | }
113 |
114 | $TParamURL_HTTP_build_query = http_build_query($TParamURL);
115 |
116 | if($action === 'add_filter') {
117 |
118 | // Create an array for form
119 | $formquestion = array(
120 | // 'text' => $langs->trans("ConfirmClone"),
121 | // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
122 | // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
123 | array('type' => 'text', 'name' => 'label', 'label' => $langs->trans('AdvTgtOrCreateNewFilter'), 'value'=>(empty($label)) ? $langs->trans('Filter').' '.date('d/m/Y H:i:s') : $label)
124 | );
125 | $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&'.$TParamURL_HTTP_build_query, $langs->trans('AdvTgtCreateFilter'), '', 'confirm_add_filter', $formquestion, 'yes', 1);
126 |
127 | } elseif ($action === 'confirm_add_filter' && $confirm === 'yes') {
128 |
129 | if($id_doubledistributionlistfilter = ToolsDistributionlist::distributionlistsocpeoplefilter_alreadyexist($label)){
130 | setEventMessage($langs->trans('DistributionListFilterSocPeople_Label_AlreadyExist', $label), 'errors');
131 | header('Location: '.$_SERVER['PHP_SELF'].'?id='.$id.'&action=add_filter&label='.$label);
132 | exit;
133 | } else {
134 | $filter = new DistributionListSocpeopleFilter($db);
135 | $filter->url_params = $TParamURL_HTTP_build_query;
136 | $filter->fk_distributionlist = $id;
137 | $filter->label = $label;
138 | $filter->create($user);
139 | // Pour éviter de réenregistrer le filtre en cas de réactualisation de la page
140 | header('Location: ' . $_SERVER['PHP_SELF'] . '?id=' . $id . '&set_filter=1&filter=' . $filter->id);
141 | exit;
142 | }
143 |
144 | } elseif(GETPOSTISSET('delete_filter')) {
145 |
146 |
147 | if($filter_id > 0) {
148 | // pour conserver le filtre si l'utilisateur dit finalement non pour la suppression
149 | $f = new DistributionListSocpeopleFilter($db);
150 | $f->fetch($filter_id);
151 |
152 | // Create an array for form
153 | $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&filter='.$filter_id, $langs->trans('RemoveFilter'), $langs->trans('ConfirmDeleteDistributionListFilter', $f->label), 'confirm_remove_filter', '', 'yes', 1);
154 |
155 | $TParamURL_HTTP_build_query = $f->url_params;
156 | } else setEventMessage($langs->trans('DistributionListNeedToSelectFilterForDeletion'), 'warnings');
157 |
158 |
159 | } elseif($action === 'confirm_remove_filter' && $confirm === 'yes' && $filter_id > 0) {
160 |
161 | $filter = new DistributionListSocpeopleFilter($db);
162 | $filter->fetch($filter_id);
163 | $filter->delete($user);
164 |
165 | header('Location: '.$_SERVER['PHP_SELF'].'?id='.$id.'&msg_to_display=DistributionListDeleteFilterSuccess');
166 | exit;
167 |
168 | } elseif(GETPOSTISSET('set_filter')) {
169 |
170 | if($filter_id > 0) {
171 | $f = new DistributionListSocpeopleFilter($db);
172 | $f->fetch($filter_id);
173 | $TParamURL_HTTP_build_query = $f->url_params;
174 |
175 | } else setEventMessage($langs->trans('DistributionListNeedToSelectFilterForSelection'), 'warnings');
176 | }
177 | //maintient le filtre si on change le nombre de contacts à afficher
178 | elseif(!empty($filter_id) && GETPOSTISSET('limit')){
179 | $f = new DistributionListSocpeopleFilter($db);
180 | $res = $f->fetch($filter_id);
181 |
182 | /*Vieux hack pour faire marcher l'ajout ou la suppression de colonnes : je supprimme certains éléments des params du filtre pour éviter qu'ils écrasent les paramètres définis de base */
183 | parse_str($f->url_params,$TParamURL_Filter);
184 | unset($TParamURL_Filter['selectedfields']);
185 | unset($TParamURL_Filter['formfilteraction']);
186 | $f->url_params = http_build_query($TParamURL_Filter);
187 |
188 | if($res > 0) $TParamURL_HTTP_build_query .= '&' . $f->url_params;
189 | else setEventMessage($langs->trans('DistributionListFilterError'), 'errors');
190 | }
191 |
192 | if($action === 'add_all_filtered_contacts') {
193 | $contacts = $object->getAllContactIds();
194 | $massaction = 'distributionlist_add_contacts';
195 | }
196 |
197 | // Ajout des contacts à la liste de diffusion
198 | if($massaction === 'distributionlist_add_contacts') {
199 |
200 | if(!empty($contacts) && $object->status < DistributionList::STATUS_CLOSED) {
201 |
202 | $nb_add = 0;
203 | foreach ($contacts as $id_contact) $nb_add += $object->addContact($user, $id_contact, false, false);
204 |
205 | if(!empty($nb_add)) {
206 | setEventMessage($langs->trans('DistributionListNbAddedContacts', $nb_add));
207 | $object->nb_contacts += $nb_add;
208 | $object->update($user);
209 | } else setEventMessage($langs->trans('DistributionListNoAddedContacts'), 'warnings');
210 | }
211 |
212 | }
213 |
214 | $hookmanager->executeHooks('doActions', $parameters, $object, $action);
215 |
216 | /*
217 | * View
218 | */
219 |
220 | if(!empty($msg_to_display)) setEventMessage($langs->trans($msg_to_display, $style_msg_to_display));
221 |
222 |
223 | $help_url = '';
224 |
225 | llxHeader('', $langs->trans('DistributionList'), $help_url);
226 |
227 | ?>
228 |
229 |
265 |
266 | 0 || !empty($ref)) {
269 |
270 | // Print form confirm
271 | print $formconfirm ?? '';
272 |
273 | $object->fetch_thirdparty();
274 |
275 | $head = distributionlistPrepareHead($object);
276 |
277 | dol_fiche_head($head, 'contact', $langs->trans("DistributionList"), -1, $object->picto);
278 |
279 | // Object card
280 | // ------------------------------------------------------------
281 | $linkback = '' . $langs->trans("BackToList") . '';
282 |
283 | $morehtmlref = '';
284 | /*
285 | // Ref customer
286 | $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
287 | $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
288 | // Thirdparty
289 | $morehtmlref.='
'.$langs->trans('ThirdParty') . ' : ' . (is_object($object->thirdparty) ? $object->thirdparty->getNomUrl(1) : '');
290 | // Project
291 | if (! empty($conf->projet->enabled))
292 | {
293 | $langs->load("projects");
294 | $morehtmlref.='
'.$langs->trans('Project') . ' ';
295 | if ($permissiontoadd)
296 | {
297 | if ($action != 'classify')
298 | //$morehtmlref.='
' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' : ';
299 | $morehtmlref.=' : ';
300 | if ($action == 'classify') {
301 | //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
302 | $morehtmlref.='
';
308 | } else {
309 | $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
310 | }
311 | } else {
312 | if (! empty($object->fk_project)) {
313 | $proj = new Project($db);
314 | $proj->fetch($object->fk_project);
315 | $morehtmlref .= ': '.$proj->getNomUrl();
316 | } else {
317 | $morehtmlref .= '';
318 | }
319 | }
320 | }*/
321 | $morehtmlref .= '
';
322 |
323 |
324 | dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
325 |
326 |
327 | print '';
328 | print '
';
329 |
330 | $filter = new DistributionListSocpeopleFilter($db);
331 | $TFilters = $filter->fetchAll('ASC', 'label', 0, 0, array());
332 |
333 | print '
';
334 | print '
';
363 | print '
';
364 |
365 | $cssclass = "titlefield";
366 |
367 | //print '
';
370 |
371 | print '
';
372 |
373 | dol_fiche_end();
374 | }
375 |
376 | // End of page
377 | llxFooter();
378 | $db->close();
379 |
--------------------------------------------------------------------------------
/admin/setup.php:
--------------------------------------------------------------------------------
1 |
3 | * Copyright (C) 2021 SuperAdmin
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | /**
20 | * \file distributionlist/admin/setup.php
21 | * \ingroup distributionlist
22 | * \brief DistributionList setup page.
23 | */
24 |
25 | // Load Dolibarr environment
26 | $res = 0;
27 | // Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
28 | if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
29 | // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
30 | $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
31 | while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { $i--; $j--; }
32 | if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
33 | if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
34 | // Try main.inc.php using relative path
35 | if (!$res && file_exists("../../main.inc.php")) $res = @include "../../main.inc.php";
36 | if (!$res && file_exists("../../../main.inc.php")) $res = @include "../../../main.inc.php";
37 | if (!$res) die("Include of main fails");
38 |
39 | global $langs, $user;
40 |
41 | // Libraries
42 | require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
43 | require_once '../lib/distributionlist.lib.php';
44 | //require_once "../class/myclass.class.php";
45 |
46 | // Translations
47 | $langs->loadLangs(array("admin", "distributionlist@distributionlist"));
48 |
49 | // Access control
50 | if (!$user->admin) accessforbidden();
51 |
52 | // Parameters
53 | $action = GETPOST('action', 'alpha');
54 | $backtopage = GETPOST('backtopage', 'alpha');
55 |
56 | $value = GETPOST('value', 'alpha');
57 |
58 | /*$arrayofparameters = array(
59 | 'DISTRIBUTIONLIST_MYPARAM1'=>array('css'=>'minwidth200', 'enabled'=>1),
60 | 'DISTRIBUTIONLIST_MYPARAM2'=>array('css'=>'minwidth500', 'enabled'=>1)
61 | );*/
62 |
63 | $error = 0;
64 | $setupnotempty = 0;
65 |
66 |
67 | /*
68 | * Actions
69 | */
70 | include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
71 |
72 | if ($action == 'updateMask')
73 | {
74 | $maskconstorder = GETPOST('maskConstDistributionList', 'alpha');
75 | $maskorder = GETPOST('maskDistributionList', 'alpha');
76 |
77 | if ($maskconstorder) $res = dolibarr_set_const($db, $maskconstorder, $maskorder, 'chaine', 0, '', $conf->entity);
78 |
79 | if (!$res > 0) $error++;
80 |
81 | if (!$error)
82 | {
83 | setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
84 | } else {
85 | setEventMessages($langs->trans("Error"), null, 'errors');
86 | }
87 | } elseif ($action == 'specimen')
88 | {
89 | $modele = GETPOST('module', 'alpha');
90 | $tmpobjectkey = GETPOST('object');
91 |
92 | $tmpobject = new $tmpobjectkey($db);
93 | $tmpobject->initAsSpecimen();
94 |
95 | // Search template files
96 | $file = ''; $classname = ''; $filefound = 0;
97 | $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
98 | foreach ($dirmodels as $reldir)
99 | {
100 | $file = dol_buildpath($reldir."core/modules/distributionlist/doc/pdf_".$modele."_".strtolower($tmpobjectkey).".modules.php", 0);
101 | if (file_exists($file))
102 | {
103 | $filefound = 1;
104 | $classname = "pdf_".$modele;
105 | break;
106 | }
107 | }
108 |
109 | if ($filefound)
110 | {
111 | require_once $file;
112 |
113 | $module = new $classname($db);
114 |
115 | if ($module->write_file($tmpobject, $langs) > 0)
116 | {
117 | header("Location: ".DOL_URL_ROOT."/document.php?modulepart=".strtolower($tmpobjectkey)."&file=SPECIMEN.pdf");
118 | return;
119 | } else {
120 | setEventMessages($module->error, null, 'errors');
121 | dol_syslog($module->error, LOG_ERR);
122 | }
123 | } else {
124 | setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
125 | dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
126 | }
127 | }
128 |
129 | // Activate a model
130 | elseif ($action == 'set')
131 | {
132 | $ret = addDocumentModel($value, $type, $label, $scandir);
133 | } elseif ($action == 'del')
134 | {
135 | $tmpobjectkey = GETPOST('object');
136 |
137 | $ret = delDocumentModel($value, $type);
138 | if ($ret > 0)
139 | {
140 | $constforval = strtoupper($tmpobjectkey).'_ADDON_PDF';
141 | if (getDolGlobalString($constforval) == "$value") dolibarr_del_const($db, $constforval, $conf->entity);
142 | }
143 | }
144 |
145 | // Set default model
146 | elseif ($action == 'setdoc')
147 | {
148 | $tmpobjectkey = GETPOST('object');
149 | $constforval = strtoupper($tmpobjectkey).'_ADDON_PDF';
150 | if (dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity))
151 | {
152 | // The constant that was read before the new set
153 | // We therefore requires a variable to have a coherent view
154 | $conf->global->$constforval = $value;
155 | }
156 |
157 | // On active le modele
158 | $ret = delDocumentModel($value, $type);
159 | if ($ret > 0)
160 | {
161 | $ret = addDocumentModel($value, $type, $label, $scandir);
162 | }
163 | } elseif ($action == 'setmod')
164 | {
165 | // TODO Check if numbering module chosen can be activated
166 | // by calling method canBeActivated
167 | $tmpobjectkey = GETPOST('object');
168 | $constforval = 'DISTRIBUTIONLIST_'.strtoupper($tmpobjectkey)."_ADDON";
169 | dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity);
170 | }
171 |
172 |
173 |
174 | /*
175 | * View
176 | */
177 |
178 | $form = new Form($db);
179 |
180 | $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
181 |
182 | $page_name = "DistributionListSetup";
183 | llxHeader('', $langs->trans($page_name));
184 |
185 | // Subheader
186 | $linkback = ''.$langs->trans("BackToModuleList").'';
187 |
188 | print load_fiche_titre($langs->trans($page_name), $linkback, 'object_distributionlist@distributionlist');
189 |
190 | // Configuration header
191 | $head = distributionlistAdminPrepareHead();
192 | dol_fiche_head($head, 'settings', '', -1, "distributionlist@distributionlist");
193 |
194 | // Setup page goes here
195 | echo ''.$langs->trans("DistributionListSetupPage").'';
196 |
197 | //Partie "Paramètres" en général
198 |
199 | print load_fiche_titre($langs->trans("Parameters"), '', '');
200 |
201 | print '';
202 |
203 | print '';
204 | print '| '.$langs->trans("Description").' | ';
205 | print ''.$langs->trans("Value").' | ';
206 | print '
'."\n";
207 |
208 | print '';
209 | print '| '.$langs->trans("DistributionList_UniqueLabel").' | ';
210 | print '';
211 | print ajax_constantonoff('DISTRIBUTIONLISTUNIQUELABEL');
212 | print " | \n
\n";
213 |
214 | print '
';
215 |
216 |
217 | if ($action == 'edit')
218 | {
219 | print '';
240 | print '
';
241 | } else {
242 | if (!empty($arrayofparameters))
243 | {
244 | print '';
245 | print '| '.$langs->trans("Parameter").' | '.$langs->trans("Value").' |
';
246 |
247 | foreach ($arrayofparameters as $key => $val)
248 | {
249 | $setupnotempty++;
250 |
251 | print '| ';
252 | $tooltiphelp = (($langs->trans($key.'Tooltip') != $key.'Tooltip') ? $langs->trans($key.'Tooltip') : '');
253 | print $form->textwithpicto($langs->trans($key), $tooltiphelp);
254 | print ' | '.getDolGlobalString($key).' |
';
255 | }
256 |
257 | print '
';
258 |
259 | print '';
262 | }
263 | /*else
264 | {
265 | print '
'.$langs->trans("NothingToSetup");
266 | }*/
267 | }
268 |
269 |
270 | $moduledir = 'distributionlist';
271 | $myTmpObjects = array();
272 | $myTmpObjects['DistributionList']=array('includerefgeneration'=>1, 'includedocgeneration'=>0);
273 |
274 |
275 | foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
276 |
277 | if ($myTmpObjectKey == 'MyObject') continue;
278 | if ($myTmpObjectArray['includerefgeneration']) {
279 | /*
280 | * Orders Numbering model
281 | */
282 | $setupnotempty++;
283 |
284 | print load_fiche_titre($langs->trans("NumberingModules", $myTmpObjectKey), '', '');
285 |
286 | print '';
287 | print '';
288 | print '| '.$langs->trans("Name").' | ';
289 | print ''.$langs->trans("Description").' | ';
290 | print ''.$langs->trans("Example").' | ';
291 | print ''.$langs->trans("Status").' | ';
292 | print ''.$langs->trans("ShortInfo").' | ';
293 | print '
'."\n";
294 |
295 | clearstatcache();
296 |
297 | foreach ($dirmodels as $reldir)
298 | {
299 | $dir = dol_buildpath($reldir."core/modules/".$moduledir);
300 |
301 | if (is_dir($dir))
302 | {
303 | $handle = opendir($dir);
304 | if (is_resource($handle))
305 | {
306 | while (($file = readdir($handle)) !== false)
307 | {
308 | if (strpos($file, 'mod_'.strtolower($myTmpObjectKey).'_') === 0 && substr($file, dol_strlen($file) - 3, 3) == 'php')
309 | {
310 | $file = substr($file, 0, dol_strlen($file) - 4);
311 |
312 | require_once $dir.'/'.$file.'.php';
313 |
314 | $module = new $file($db);
315 |
316 | // Show modules according to features level
317 | if ($module->version == 'development' && getDolGlobalString('MAIN_FEATURES_LEVEL') < 2) continue;
318 | if ($module->version == 'experimental' && getDolGlobalString('MAIN_FEATURES_LEVEL') < 1) continue;
319 |
320 | if ($module->isEnabled())
321 | {
322 | dol_include_once('/'.$moduledir.'/class/'.strtolower($myTmpObjectKey).'.class.php');
323 |
324 | print '| '.$module->name." | \n";
325 | print $module->info();
326 | print ' | ';
327 |
328 | // Show example of numbering model
329 | print '';
330 | $tmp = $module->getExample();
331 | if (preg_match('/^Error/', $tmp)) print ' '.$langs->trans($tmp).' ';
332 | elseif ($tmp == 'NotConfigured') print $langs->trans($tmp);
333 | else print $tmp;
334 | print ' | '."\n";
335 |
336 | print '';
337 | $constforvar = 'DISTRIBUTIONLIST_'.strtoupper($myTmpObjectKey).'_ADDON';
338 | if (getDolGlobalString($constforvar) == $file)
339 | {
340 | print img_picto($langs->trans("Activated"), 'switch_on');
341 | } else {
342 | print '';
343 | print img_picto($langs->trans("Disabled"), 'switch_off');
344 | print '';
345 | }
346 | print ' | ';
347 |
348 | $mytmpinstance = new $myTmpObjectKey($db);
349 | $mytmpinstance->initAsSpecimen();
350 |
351 | // Info
352 | $htmltooltip = '';
353 | $htmltooltip .= ''.$langs->trans("Version").': '.$module->getVersion().'
';
354 |
355 | $nextval = $module->getNextValue($mytmpinstance);
356 | if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
357 | $htmltooltip .= ''.$langs->trans("NextValue").': ';
358 | if ($nextval) {
359 | if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured')
360 | $nextval = $langs->trans($nextval);
361 | $htmltooltip .= $nextval.'
';
362 | } else {
363 | $htmltooltip .= $langs->trans($module->error).'
';
364 | }
365 | }
366 |
367 | print '';
368 | print $form->textwithpicto('', $htmltooltip, 1, 0);
369 | print ' | ';
370 |
371 | print "
\n";
372 | }
373 | }
374 | }
375 | closedir($handle);
376 | }
377 | }
378 | }
379 | print "
\n";
380 | }
381 |
382 | if ($myTmpObjectArray['includedocgeneration']) {
383 | /*
384 | * Document templates generators
385 | */
386 | $setupnotempty++;
387 | $type = strtolower($myTmpObjectKey);
388 |
389 | print load_fiche_titre($langs->trans("DocumentModules", $myTmpObjectKey), '', '');
390 |
391 | // Load array def with activated templates
392 | $def = array();
393 | $sql = "SELECT nom";
394 | $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
395 | $sql .= " WHERE type = '".$type."'";
396 | $sql .= " AND entity = ".$conf->entity;
397 | $resql = $db->query($sql);
398 | if ($resql)
399 | {
400 | $i = 0;
401 | $num_rows = $db->num_rows($resql);
402 | while ($i < $num_rows)
403 | {
404 | $array = $db->fetch_array($resql);
405 | array_push($def, $array[0]);
406 | $i++;
407 | }
408 | } else {
409 | dol_print_error($db);
410 | }
411 |
412 | print "\n";
413 | print "\n";
414 | print '| '.$langs->trans("Name").' | ';
415 | print ''.$langs->trans("Description").' | ';
416 | print ''.$langs->trans("Status")." | \n";
417 | print ''.$langs->trans("Default")." | \n";
418 | print ''.$langs->trans("ShortInfo").' | ';
419 | print ''.$langs->trans("Preview").' | ';
420 | print "
\n";
421 |
422 | clearstatcache();
423 |
424 | foreach ($dirmodels as $reldir)
425 | {
426 | foreach (array('', '/doc') as $valdir)
427 | {
428 | $realpath = $reldir."core/modules/".$moduledir.$valdir;
429 | $dir = dol_buildpath($realpath);
430 |
431 | if (is_dir($dir))
432 | {
433 | $handle = opendir($dir);
434 | if (is_resource($handle))
435 | {
436 | while (($file = readdir($handle)) !== false)
437 | {
438 | $filelist[] = $file;
439 | }
440 | closedir($handle);
441 | arsort($filelist);
442 |
443 | foreach ($filelist as $file)
444 | {
445 | if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file))
446 | {
447 | if (file_exists($dir.'/'.$file))
448 | {
449 | $name = substr($file, 4, dol_strlen($file) - 16);
450 | $classname = substr($file, 0, dol_strlen($file) - 12);
451 |
452 | require_once $dir.'/'.$file;
453 | $module = new $classname($db);
454 |
455 | $modulequalified = 1;
456 | if ($module->version == 'development' && getDolGlobalString('MAIN_FEATURES_LEVEL') < 2) $modulequalified = 0;
457 | if ($module->version == 'experimental' && getDolGlobalString('MAIN_FEATURES_LEVEL') < 1) $modulequalified = 0;
458 |
459 | if ($modulequalified)
460 | {
461 | print '| ';
462 | print (empty($module->name) ? $name : $module->name);
463 | print " | \n";
464 | if (method_exists($module, 'info')) print $module->info($langs);
465 | else print $module->description;
466 | print ' | ';
467 |
468 | // Active
469 | if (in_array($name, $def))
470 | {
471 | print ''."\n";
472 | print '';
473 | print img_picto($langs->trans("Enabled"), 'switch_on');
474 | print '';
475 | print ' | ';
476 | } else {
477 | print ''."\n";
478 | print 'scandir.'&label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"), 'switch_off').'';
479 | print " | ";
480 | }
481 |
482 | // Default
483 | print '';
484 | $constforvar = 'DISTRIBUTIONLIST_'.strtoupper($myTmpObjectKey).'_ADDON';
485 | if (getDolGlobalString($constforvar) == $name)
486 | {
487 | print img_picto($langs->trans("Default"), 'on');
488 | } else {
489 | print 'scandir.'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').'';
490 | }
491 | print ' | ';
492 |
493 | // Info
494 | $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
495 | $htmltooltip .= '
'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
496 | if ($module->type == 'pdf')
497 | {
498 | $htmltooltip .= '
'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
499 | }
500 | $htmltooltip .= '
'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
501 |
502 | $htmltooltip .= '
'.$langs->trans("FeaturesSupported").':';
503 | $htmltooltip .= '
'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
504 | $htmltooltip .= '
'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
505 |
506 | print '';
507 | print $form->textwithpicto('', $htmltooltip, 1, 0);
508 | print ' | ';
509 |
510 | // Preview
511 | print '';
512 | if ($module->type == 'pdf')
513 | {
514 | print ''.img_object($langs->trans("Preview"), 'generic').'';
515 | } else {
516 | print img_object($langs->trans("PreviewNotAvailable"), 'generic');
517 | }
518 | print ' | ';
519 |
520 | print "
\n";
521 | }
522 | }
523 | }
524 | }
525 | }
526 | }
527 | }
528 | }
529 |
530 | print '
';
531 | }
532 | }
533 |
534 | /*if (empty($setupnotempty)) {
535 | print '
'.$langs->trans("NothingToSetup");
536 | }*/
537 |
538 | // Page end
539 | dol_fiche_end();
540 |
541 | llxFooter();
542 | $db->close();
543 |
--------------------------------------------------------------------------------
/core/modules/modDistributionList.class.php:
--------------------------------------------------------------------------------
1 |
3 | * Copyright (C) 2018-2019 Nicolas ZABOURI
4 | * Copyright (C) 2019-2020 Frédéric France
5 | * Copyright (C) 2021 SuperAdmin
6 | *
7 | * This program is free software; you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation; either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 |
21 | /**
22 | * \defgroup distributionlist Module DistributionList
23 | * \brief DistributionList module descriptor.
24 | *
25 | * \file htdocs/distributionlist/core/modules/modDistributionList.class.php
26 | * \ingroup distributionlist
27 | * \brief Description and activation file for module DistributionList
28 | */
29 | include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
30 |
31 | /**
32 | * Description and activation class for module DistributionList
33 | */
34 | class modDistributionList extends DolibarrModules
35 | {
36 | /**
37 | * Constructor. Define names, constants, directories, boxes, permissions
38 | *
39 | * @param DoliDB $db Database handler
40 | */
41 | public function __construct($db)
42 | {
43 | global $langs, $conf;
44 | $this->db = $db;
45 |
46 | // Id for module (must be unique).
47 | // Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id).
48 | $this->numero = 104943; // TODO Go on page https://wiki.dolibarr.org/index.php/List_of_modules_id to reserve an id number for your module
49 | // Key text used to identify module (for permissions, menus, etc...)
50 | $this->rights_class = 'distributionlist';
51 | // Family can be 'base' (core modules),'crm','financial','hr','projects','products','ecm','technic' (transverse modules),'interface' (link with external tools),'other','...'
52 | // It is used to group modules by family in module setup page
53 | $this->family = "other";
54 | // Module position in the family on 2 digits ('01', '10', '20', ...)
55 | $this->module_position = '90';
56 | // Gives the possibility for the module, to provide his own family info and position of this family (Overwrite $this->family and $this->module_position. Avoid this)
57 | //$this->familyinfo = array('myownfamily' => array('position' => '01', 'label' => $langs->trans("MyOwnFamily")));
58 | // Module label (no space allowed), used if translation string 'ModuleDistributionListName' not found (DistributionList is name of module).
59 | $this->name = preg_replace('/^mod/i', '', get_class($this));
60 | // Module description, used if translation string 'ModuleDistributionListDesc' not found (DistributionList is name of module).
61 | $this->description = "DistributionListDescription";
62 | // Used only if file README.md and README-LL.md not found.
63 | $this->descriptionlong = "DistributionList description (Long)";
64 | $this->editor_name = 'Editor name';
65 | $this->editor_url = 'https://www.example.com';
66 | // Possible values for version are: 'development', 'experimental', 'dolibarr', 'dolibarr_deprecated' or a version string like 'x.y.z'
67 | $this->version = '1.3.4';
68 | // Url to the file with your last numberversion of this module
69 | //$this->url_last_version = 'http://www.example.com/versionmodule.txt';
70 |
71 | // Key used in llx_const table to save module status enabled/disabled (where DISTRIBUTIONLIST is value of property name of module in uppercase)
72 | $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
73 | // Name of image file used for this module.
74 | // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
75 | // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module'
76 | $this->picto = 'distributionlist@distributionlist';
77 | // Define some features supported by module (triggers, login, substitutions, menus, css, etc...)
78 | $this->module_parts = array(
79 | // Set this to 1 if module has its own trigger directory (core/triggers)
80 | 'triggers' => 1,
81 | // Set this to 1 if module has its own login method file (core/login)
82 | 'login' => 0,
83 | // Set this to 1 if module has its own substitution function file (core/substitutions)
84 | 'substitutions' => 0,
85 | // Set this to 1 if module has its own menus handler directory (core/menus)
86 | 'menus' => 0,
87 | // Set this to 1 if module overwrite template dir (core/tpl)
88 | 'tpl' => 0,
89 | // Set this to 1 if module has its own barcode directory (core/modules/barcode)
90 | 'barcode' => 0,
91 | // Set this to 1 if module has its own models directory (core/modules/xxx)
92 | 'models' => 1,
93 | // Set this to 1 if module has its own theme directory (theme)
94 | 'theme' => 0,
95 | // Set this to relative path of css file if module has its own css file
96 | 'css' => array(
97 | // '/distributionlist/css/distributionlist.css.php',
98 | ),
99 | // Set this to relative path of js file if module must load a js on all pages
100 | 'js' => array(
101 | // '/distributionlist/js/distributionlist.js.php',
102 | ),
103 | // Set here all hooks context managed by module. To find available hook context, make a "grep -r '>initHooks(' *" on source code. You can also set hook context to 'all'
104 | 'hooks' => array('contactlist'
105 | // 'data' => array(
106 | // 'hookcontext1',
107 | // 'hookcontext2',
108 | // ),
109 | // 'entity' => '0',
110 | ),
111 | // Set this to 1 if features of module are opened to external users
112 | 'moduleforexternal' => 0,
113 | );
114 | // Data directories to create when module is enabled.
115 | // Example: this->dirs = array("/distributionlist/temp","/distributionlist/subdir");
116 | $this->dirs = array("/distributionlist/temp");
117 | // Config pages. Put here list of php page, stored into distributionlist/admin directory, to use to setup module.
118 | $this->config_page_url = array("setup.php@distributionlist");
119 | // Dependencies
120 | // A condition to hide module
121 | $this->hidden = false;
122 | // List of module class names as string that must be enabled if this module is enabled. Example: array('always1'=>'modModuleToEnable1','always2'=>'modModuleToEnable2', 'FR1'=>'modModuleToEnableFR'...)
123 | $this->depends = array();
124 | $this->requiredby = array(); // List of module class names as string to disable if this one is disabled. Example: array('modModuleToDisable1', ...)
125 | $this->conflictwith = array(); // List of module class names as string this module is in conflict with. Example: array('modModuleToDisable1', ...)
126 | $this->langfiles = array("distributionlist@distributionlist");
127 | $this->phpmin = array(7, 0); // Minimum version of PHP required by module
128 | $this->need_dolibarr_version = array(16, 0); // Minimum version of Dolibarr required by module
129 | $this->warnings_activation = array(); // Warning to show when we activate module. array('always'='text') or array('FR'='textfr','ES'='textes'...)
130 | $this->warnings_activation_ext = array(); // Warning to show when we activate an external module. array('always'='text') or array('FR'='textfr','ES'='textes'...)
131 | //$this->automatic_activation = array('FR'=>'DistributionListWasAutomaticallyActivatedBecauseOfYourCountryChoice');
132 | //$this->always_enabled = true; // If true, can't be disabled
133 |
134 | // Constants
135 | // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive)
136 | // Example: $this->const=array(1 => array('DISTRIBUTIONLIST_MYNEWCONST1', 'chaine', 'myvalue', 'This is a constant to add', 1),
137 | // 2 => array('DISTRIBUTIONLIST_MYNEWCONST2', 'chaine', 'myvalue', 'This is another constant to add', 0, 'current', 1)
138 | // );
139 | $this->const = array();
140 |
141 | // Some keys to add into the overwriting translation tables
142 | /*$this->overwrite_translation = array(
143 | 'en_US:ParentCompany'=>'Parent company or reseller',
144 | 'fr_FR:ParentCompany'=>'Maison mère ou revendeur'
145 | )*/
146 | if (!isset($conf->distributionlist) || !isModEnabled('distributionlist')) {
147 | $conf->distributionlist = new stdClass();
148 | $conf->distributionlist->enabled = 0;
149 | }
150 |
151 | // Array to add new pages in new tabs
152 | $this->tabs = array();
153 | // Example:
154 | // $this->tabs[] = array('data'=>'objecttype:+tabname1:Title1:mylangfile@distributionlist:$user->rights->distributionlist->read:/distributionlist/mynewtab1.php?id=__ID__'); // To add a new tab identified by code tabname1
155 | // $this->tabs[] = array('data'=>'objecttype:+tabname2:SUBSTITUTION_Title2:mylangfile@distributionlist:$user->rights->othermodule->read:/distributionlist/mynewtab2.php?id=__ID__', // To add another new tab identified by code tabname2. Label will be result of calling all substitution functions on 'Title2' key.
156 | // $this->tabs[] = array('data'=>'objecttype:-tabname:NU:conditiontoremove'); // To remove an existing tab identified by code tabname
157 | //
158 | // Where objecttype can be
159 | // 'categories_x' to add a tab in category view (replace 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member)
160 | // 'contact' to add a tab in contact view
161 | // 'contract' to add a tab in contract view
162 | // 'group' to add a tab in group view
163 | // 'intervention' to add a tab in intervention view
164 | // 'invoice' to add a tab in customer invoice view
165 | // 'invoice_supplier' to add a tab in supplier invoice view
166 | // 'member' to add a tab in fundation member view
167 | // 'opensurveypoll' to add a tab in opensurvey poll view
168 | // 'order' to add a tab in customer order view
169 | // 'order_supplier' to add a tab in supplier order view
170 | // 'payment' to add a tab in payment view
171 | // 'payment_supplier' to add a tab in supplier payment view
172 | // 'product' to add a tab in product view
173 | // 'propal' to add a tab in propal view
174 | // 'project' to add a tab in project view
175 | // 'stock' to add a tab in stock view
176 | // 'thirdparty' to add a tab in third party view
177 | // 'user' to add a tab in user view
178 |
179 | // Dictionaries
180 | $this->dictionaries = array();
181 | /* Example:
182 | $this->dictionaries=array(
183 | 'langs'=>'distributionlist@distributionlist',
184 | // List of tables we want to see into dictonnary editor
185 | 'tabname'=>array(MAIN_DB_PREFIX."table1", MAIN_DB_PREFIX."table2", MAIN_DB_PREFIX."table3"),
186 | // Label of tables
187 | 'tablib'=>array("Table1", "Table2", "Table3"),
188 | // Request to select fields
189 | 'tabsql'=>array('SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.MAIN_DB_PREFIX.'table1 as f', 'SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.MAIN_DB_PREFIX.'table2 as f', 'SELECT f.rowid as rowid, f.code, f.label, f.active FROM '.MAIN_DB_PREFIX.'table3 as f'),
190 | // Sort order
191 | 'tabsqlsort'=>array("label ASC", "label ASC", "label ASC"),
192 | // List of fields (result of select to show dictionary)
193 | 'tabfield'=>array("code,label", "code,label", "code,label"),
194 | // List of fields (list of fields to edit a record)
195 | 'tabfieldvalue'=>array("code,label", "code,label", "code,label"),
196 | // List of fields (list of fields for insert)
197 | 'tabfieldinsert'=>array("code,label", "code,label", "code,label"),
198 | // Name of columns with primary key (try to always name it 'rowid')
199 | 'tabrowid'=>array("rowid", "rowid", "rowid"),
200 | // Condition to show each dictionary
201 | 'tabcond'=>array($conf->distributionlist->enabled, $conf->distributionlist->enabled, $conf->distributionlist->enabled)
202 | );
203 | */
204 |
205 | // Boxes/Widgets
206 | // Add here list of php file(s) stored in distributionlist/core/boxes that contains a class to show a widget.
207 | $this->boxes = array(
208 | // 0 => array(
209 | // 'file' => 'distributionlistwidget1.php@distributionlist',
210 | // 'note' => 'Widget provided by DistributionList',
211 | // 'enabledbydefaulton' => 'Home',
212 | // ),
213 | // ...
214 | );
215 |
216 | // Cronjobs (List of cron jobs entries to add when module is enabled)
217 | // unit_frequency must be 60 for minute, 3600 for hour, 86400 for day, 604800 for week
218 | $this->cronjobs = array(
219 | // 0 => array(
220 | // 'label' => 'MyJob label',
221 | // 'jobtype' => 'method',
222 | // 'class' => '/distributionlist/class/distributionlist.class.php',
223 | // 'objectname' => 'DistributionList',
224 | // 'method' => 'doScheduledJob',
225 | // 'parameters' => '',
226 | // 'comment' => 'Comment',
227 | // 'frequency' => 2,
228 | // 'unitfrequency' => 3600,
229 | // 'status' => 0,
230 | // 'test' => '$conf->distributionlist->enabled',
231 | // 'priority' => 50,
232 | // ),
233 | );
234 | // Example: $this->cronjobs=array(
235 | // 0=>array('label'=>'My label', 'jobtype'=>'method', 'class'=>'/dir/class/file.class.php', 'objectname'=>'MyClass', 'method'=>'myMethod', 'parameters'=>'param1, param2', 'comment'=>'Comment', 'frequency'=>2, 'unitfrequency'=>3600, 'status'=>0, 'test'=>'$conf->distributionlist->enabled', 'priority'=>50),
236 | // 1=>array('label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'param1, param2', 'comment'=>'Comment', 'frequency'=>1, 'unitfrequency'=>3600*24, 'status'=>0, 'test'=>'$conf->distributionlist->enabled', 'priority'=>50)
237 | // );
238 |
239 | // Permissions provided by this module
240 | $this->rights = array();
241 | $r = 0;
242 | // Add here entries to declare new permissions
243 | /* BEGIN MODULEBUILDER PERMISSIONS */
244 | $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used)
245 | $this->rights[$r][1] = 'DistributionListPermRead'; // Permission label
246 | $this->rights[$r][4] = 'distributionlist'; // In php code, permission will be checked by test if ($user->rights->distributionlist->level1->level2)
247 | $this->rights[$r][5] = 'read'; // In php code, permission will be checked by test if ($user->rights->distributionlist->level1->level2)
248 | $r++;
249 | $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used)
250 | $this->rights[$r][1] = 'DistributionListPermCreate'; // Permission label
251 | $this->rights[$r][4] = 'distributionlist'; // In php code, permission will be checked by test if ($user->rights->distributionlist->level1->level2)
252 | $this->rights[$r][5] = 'create'; // In php code, permission will be checked by test if ($user->rights->distributionlist->level1->level2)
253 | $r++;
254 | $this->rights[$r][0] = $this->numero . $r; // Permission id (must not be already used)
255 | $this->rights[$r][1] = 'DistributionListPermUpdate'; // Permission label
256 | $this->rights[$r][4] = 'distributionlist'; // In php code, permission will be checked by test if ($user->rights->distributionlist->level1->level2)
257 | $this->rights[$r][5] = 'update'; // In php code, permission will be checked by test if ($user->rights->distributionlist->level1->level2)
258 | $r++;
259 | $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used)
260 | $this->rights[$r][1] = 'DistributionListPermDelete'; // Permission label
261 | $this->rights[$r][4] = 'distributionlist'; // In php code, permission will be checked by test if ($user->rights->distributionlist->level1->level2)
262 | $this->rights[$r][5] = 'delete'; // In php code, permission will be checked by test if ($user->rights->distributionlist->level1->level2)
263 | $r++;
264 | /* END MODULEBUILDER PERMISSIONS */
265 |
266 | // Main menu entries to add
267 | $this->menu = array();
268 | $r = 0;
269 | // Add here entries to declare new menus
270 | /* BEGIN MODULEBUILDER TOPMENU */
271 | $this->menu[$r++] = array(
272 | 'fk_menu'=>'', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
273 | 'type'=>'top', // This is a Top menu entry
274 | 'titre'=>$langs->trans('ModuleDistributionListName'),
275 | 'mainmenu'=>'distributionlist',
276 | 'leftmenu'=>'',
277 | 'url'=>'/distributionlist/distributionlist_list.php',
278 | 'langs'=>'distributionlist@distributionlist', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
279 | 'position'=>1000 + $r,
280 | 'enabled'=>'$conf->distributionlist->enabled', // Define condition to show or hide menu entry. Use '$conf->distributionlist->enabled' if entry must be visible if module is enabled.
281 | 'perms'=>'1', // Use 'perms'=>'$user->rights->distributionlist->distributionlist->read' if you want your menu with a permission rules
282 | 'target'=>'',
283 | 'user'=>2, // 0=Menu for internal users, 1=external users, 2=both
284 | );
285 | /* END MODULEBUILDER TOPMENU */
286 | /* BEGIN MODULEBUILDER LEFTMENU DISTRIBUTIONLIST
287 | $this->menu[$r++]=array(
288 | 'fk_menu'=>'fk_mainmenu=distributionlist', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
289 | 'type'=>'left', // This is a Top menu entry
290 | 'titre'=>'DistributionList',
291 | 'mainmenu'=>'distributionlist',
292 | 'leftmenu'=>'distributionlist',
293 | 'url'=>'/distributionlist/distributionlistindex.php',
294 | 'langs'=>'distributionlist@distributionlist', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
295 | 'position'=>1000+$r,
296 | 'enabled'=>'$conf->distributionlist->enabled', // Define condition to show or hide menu entry. Use '$conf->distributionlist->enabled' if entry must be visible if module is enabled.
297 | 'perms'=>'$user->rights->distributionlist->distributionlist->read', // Use 'perms'=>'$user->rights->distributionlist->level1->level2' if you want your menu with a permission rules
298 | 'target'=>'',
299 | 'user'=>2, // 0=Menu for internal users, 1=external users, 2=both
300 | );
301 | $this->menu[$r++]=array(
302 | 'fk_menu'=>'fk_mainmenu=distributionlist,fk_leftmenu=distributionlist', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
303 | 'type'=>'left', // This is a Left menu entry
304 | 'titre'=>'List DistributionList',
305 | 'mainmenu'=>'distributionlist',
306 | 'leftmenu'=>'distributionlist_distributionlist_list',
307 | 'url'=>'/distributionlist/distributionlist_list.php',
308 | 'langs'=>'distributionlist@distributionlist', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
309 | 'position'=>1000+$r,
310 | 'enabled'=>'$conf->distributionlist->enabled', // Define condition to show or hide menu entry. Use '$conf->distributionlist->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
311 | 'perms'=>'$user->rights->distributionlist->distributionlist->read', // Use 'perms'=>'$user->rights->distributionlist->level1->level2' if you want your menu with a permission rules
312 | 'target'=>'',
313 | 'user'=>2, // 0=Menu for internal users, 1=external users, 2=both
314 | );
315 | $this->menu[$r++]=array(
316 | 'fk_menu'=>'fk_mainmenu=distributionlist,fk_leftmenu=distributionlist', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
317 | 'type'=>'left', // This is a Left menu entry
318 | 'titre'=>'New DistributionList',
319 | 'mainmenu'=>'distributionlist',
320 | 'leftmenu'=>'distributionlist_distributionlist_new',
321 | 'url'=>'/distributionlist/distributionlist_card.php?action=create',
322 | 'langs'=>'distributionlist@distributionlist', // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
323 | 'position'=>1000+$r,
324 | 'enabled'=>'$conf->distributionlist->enabled', // Define condition to show or hide menu entry. Use '$conf->distributionlist->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
325 | 'perms'=>'$user->rights->distributionlist->distributionlist->write', // Use 'perms'=>'$user->rights->distributionlist->level1->level2' if you want your menu with a permission rules
326 | 'target'=>'',
327 | 'user'=>2, // 0=Menu for internal users, 1=external users, 2=both
328 | );
329 | */
330 |
331 | $this->menu[$r++]=array(
332 | // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
333 | 'fk_menu'=>'fk_mainmenu=distributionlist',
334 | // This is a Left menu entry
335 | 'type'=>'left',
336 | 'titre'=>$langs->trans('ModuleDistributionListName'),
337 | 'mainmenu'=>'distributionlist',
338 | 'leftmenu'=>'distributionlist_distributionlist',
339 | 'url'=>'/distributionlist/distributionlist_list.php',
340 | // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
341 | 'langs'=>'distributionlist@distributionlist',
342 | 'position'=>1100+$r,
343 | // Define condition to show or hide menu entry. Use '$conf->distributionlist->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
344 | 'enabled'=>'$conf->distributionlist->enabled',
345 | // Use 'perms'=>'$user->rights->distributionlist->level1->level2' if you want your menu with a permission rules
346 | 'perms'=>'1',
347 | 'target'=>'',
348 | // 0=Menu for internal users, 1=external users, 2=both
349 | 'user'=>2,
350 | );
351 | $this->menu[$r++]=array(
352 | // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
353 | 'fk_menu'=>'fk_mainmenu=distributionlist,fk_leftmenu=distributionlist_distributionlist',
354 | // This is a Left menu entry
355 | 'type'=>'left',
356 | 'titre'=>$langs->trans('DistributionListNew'),
357 | 'mainmenu'=>'distributionlist',
358 | 'leftmenu'=>'distributionlist_distributioncreate',
359 | 'url'=>'/distributionlist/distributionlist_card.php?action=create',
360 | // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
361 | 'langs'=>'distributionlist@distributionlist',
362 | 'position'=>1100+$r,
363 | // Define condition to show or hide menu entry. Use '$conf->distributionlist->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
364 | 'enabled'=>'$conf->distributionlist->enabled',
365 | // Use 'perms'=>'$user->rights->distributionlist->level1->level2' if you want your menu with a permission rules
366 | 'perms'=>'$user->rights->distributionlist->distributionlist->create',
367 | 'target'=>'',
368 | // 0=Menu for internal users, 1=external users, 2=both
369 | 'user'=>2
370 | );
371 | $this->menu[$r++]=array(
372 | // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
373 | 'fk_menu'=>'fk_mainmenu=distributionlist,fk_leftmenu=distributionlist_distributionlist',
374 | // This is a Left menu entry
375 | 'type'=>'left',
376 | 'titre'=>$langs->trans('DistributionListList'),
377 | 'mainmenu'=>'distributionlist',
378 | 'leftmenu'=>'distributionlist_distributionlist',
379 | 'url'=>'/distributionlist/distributionlist_list.php',
380 | // Lang file to use (without .lang) by module. File must be in langs/code_CODE/ directory.
381 | 'langs'=>'distributionlist@distributionlist',
382 | 'position'=>1100+$r,
383 | // Define condition to show or hide menu entry. Use '$conf->distributionlist->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected.
384 | 'enabled'=>'$conf->distributionlist->enabled',
385 | // Use 'perms'=>'$user->rights->distributionlist->level1->level2' if you want your menu with a permission rules
386 | 'perms'=>'1',
387 | 'target'=>'',
388 | // 0=Menu for internal users, 1=external users, 2=both
389 | 'user'=>2
390 | );
391 |
392 | /* END MODULEBUILDER LEFTMENU DISTRIBUTIONLIST */
393 |
394 | // Exports profiles provided by this module
395 | $r = 1;
396 | /* BEGIN MODULEBUILDER EXPORT DISTRIBUTIONLIST */
397 | /*
398 | $langs->load("distributionlist@distributionlist");
399 | $this->export_code[$r]=$this->rights_class.'_'.$r;
400 | $this->export_label[$r]='DistributionListLines'; // Translation key (used only if key ExportDataset_xxx_z not found)
401 | $this->export_icon[$r]='distributionlist@distributionlist';
402 | // Define $this->export_fields_array, $this->export_TypeFields_array and $this->export_entities_array
403 | $keyforclass = 'DistributionList'; $keyforclassfile='/distributionlist/class/distributionlist.class.php'; $keyforelement='distributionlist@distributionlist';
404 | include DOL_DOCUMENT_ROOT.'/core/commonfieldsinexport.inc.php';
405 | //$this->export_fields_array[$r]['t.fieldtoadd']='FieldToAdd'; $this->export_TypeFields_array[$r]['t.fieldtoadd']='Text';
406 | //unset($this->export_fields_array[$r]['t.fieldtoremove']);
407 | //$keyforclass = 'DistributionListLine'; $keyforclassfile='/distributionlist/class/distributionlist.class.php'; $keyforelement='distributionlistline@distributionlist'; $keyforalias='tl';
408 | //include DOL_DOCUMENT_ROOT.'/core/commonfieldsinexport.inc.php';
409 | $keyforselect='distributionlist'; $keyforaliasextra='extra'; $keyforelement='distributionlist@distributionlist';
410 | include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
411 | //$keyforselect='distributionlistline'; $keyforaliasextra='extraline'; $keyforelement='distributionlistline@distributionlist';
412 | //include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
413 | //$this->export_dependencies_array[$r] = array('distributionlistline'=>array('tl.rowid','tl.ref')); // To force to activate one or several fields if we select some fields that need same (like to select a unique key if we ask a field of a child to avoid the DISTINCT to discard them, or for computed field than need several other fields)
414 | //$this->export_special_array[$r] = array('t.field'=>'...');
415 | //$this->export_examplevalues_array[$r] = array('t.field'=>'Example');
416 | //$this->export_help_array[$r] = array('t.field'=>'FieldDescHelp');
417 | $this->export_sql_start[$r]='SELECT DISTINCT ';
418 | $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'distributionlist as t';
419 | //$this->export_sql_end[$r] =' LEFT JOIN '.MAIN_DB_PREFIX.'distributionlist_line as tl ON tl.fk_distributionlist = t.rowid';
420 | $this->export_sql_end[$r] .=' WHERE 1 = 1';
421 | $this->export_sql_end[$r] .=' AND t.entity IN ('.getEntity('distributionlist').')';
422 | $r++; */
423 | /* END MODULEBUILDER EXPORT DISTRIBUTIONLIST */
424 |
425 | // Imports profiles provided by this module
426 | $r = 1;
427 | /* BEGIN MODULEBUILDER IMPORT DISTRIBUTIONLIST */
428 | /*
429 | $langs->load("distributionlist@distributionlist");
430 | $this->export_code[$r]=$this->rights_class.'_'.$r;
431 | $this->export_label[$r]='DistributionListLines'; // Translation key (used only if key ExportDataset_xxx_z not found)
432 | $this->export_icon[$r]='distributionlist@distributionlist';
433 | $keyforclass = 'DistributionList'; $keyforclassfile='/distributionlist/class/distributionlist.class.php'; $keyforelement='distributionlist@distributionlist';
434 | include DOL_DOCUMENT_ROOT.'/core/commonfieldsinexport.inc.php';
435 | $keyforselect='distributionlist'; $keyforaliasextra='extra'; $keyforelement='distributionlist@distributionlist';
436 | include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
437 | //$this->export_dependencies_array[$r]=array('mysubobject'=>'ts.rowid', 't.myfield'=>array('t.myfield2','t.myfield3')); // To force to activate one or several fields if we select some fields that need same (like to select a unique key if we ask a field of a child to avoid the DISTINCT to discard them, or for computed field than need several other fields)
438 | $this->export_sql_start[$r]='SELECT DISTINCT ';
439 | $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'distributionlist as t';
440 | $this->export_sql_end[$r] .=' WHERE 1 = 1';
441 | $this->export_sql_end[$r] .=' AND t.entity IN ('.getEntity('distributionlist').')';
442 | $r++; */
443 | /* END MODULEBUILDER IMPORT DISTRIBUTIONLIST */
444 | }
445 |
446 | /**
447 | * Function called when module is enabled.
448 | * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
449 | * It also creates data directories
450 | *
451 | * @param string $options Options when enabling module ('', 'noboxes')
452 | * @return int 1 if OK, 0 if KO
453 | */
454 | public function init($options = '')
455 | {
456 | global $conf, $langs;
457 |
458 | $result = $this->_load_tables('/distributionlist/sql/');
459 | if ($result < 0) return -1; // Do not activate module if error 'not allowed' returned when loading module SQL queries (the _load_table run sql with run_sql with the error allowed parameter set to 'default')
460 |
461 | // Create extrafields during init
462 | //include_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
463 | //$extrafields = new ExtraFields($this->db);
464 | //$result1=$extrafields->addExtraField('distributionlist_myattr1', "New Attr 1 label", 'boolean', 1, 3, 'thirdparty', 0, 0, '', '', 1, '', 0, 0, '', '', 'distributionlist@distributionlist', '$conf->distributionlist->enabled');
465 | //$result2=$extrafields->addExtraField('distributionlist_myattr2', "New Attr 2 label", 'varchar', 1, 10, 'project', 0, 0, '', '', 1, '', 0, 0, '', '', 'distributionlist@distributionlist', '$conf->distributionlist->enabled');
466 | //$result3=$extrafields->addExtraField('distributionlist_myattr3', "New Attr 3 label", 'varchar', 1, 10, 'bank_account', 0, 0, '', '', 1, '', 0, 0, '', '', 'distributionlist@distributionlist', '$conf->distributionlist->enabled');
467 | //$result4=$extrafields->addExtraField('distributionlist_myattr4', "New Attr 4 label", 'select', 1, 3, 'thirdparty', 0, 1, '', array('options'=>array('code1'=>'Val1','code2'=>'Val2','code3'=>'Val3')), 1,'', 0, 0, '', '', 'distributionlist@distributionlist', '$conf->distributionlist->enabled');
468 | //$result5=$extrafields->addExtraField('distributionlist_myattr5', "New Attr 5 label", 'text', 1, 10, 'user', 0, 0, '', '', 1, '', 0, 0, '', '', 'distributionlist@distributionlist', '$conf->distributionlist->enabled');
469 |
470 | // Permissions
471 | $this->remove($options);
472 |
473 | $sql = array();
474 |
475 | // Document templates
476 | $moduledir = 'distributionlist';
477 | $myTmpObjects = array();
478 | $myTmpObjects['DistributionList']=array('includerefgeneration'=>0, 'includedocgeneration'=>0);
479 |
480 | foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
481 | if ($myTmpObjectKey == 'DistributionList') continue;
482 | if ($myTmpObjectArray['includerefgeneration']) {
483 | $src=DOL_DOCUMENT_ROOT.'/install/doctemplates/distributionlist/template_distributionlists.odt';
484 | $dirodt=DOL_DATA_ROOT.'/doctemplates/distributionlist';
485 | $dest=$dirodt.'/template_distributionlists.odt';
486 |
487 | if (file_exists($src) && ! file_exists($dest))
488 | {
489 | require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
490 | dol_mkdir($dirodt);
491 | $result=dol_copy($src, $dest, 0, 0);
492 | if ($result < 0)
493 | {
494 | $langs->load("errors");
495 | $this->error=$langs->trans('ErrorFailToCopyFile', $src, $dest);
496 | return 0;
497 | }
498 | }
499 |
500 | $sql = array_merge($sql, array(
501 | "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = 'standard_".strtolower($myTmpObjectKey)."' AND type = '".strtolower($myTmpObjectKey)."' AND entity = ".$conf->entity,
502 | "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('standard_".strtolower($myTmpObjectKey)."','".strtolower($myTmpObjectKey)."',".$conf->entity.")",
503 | "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = 'generic_".strtolower($myTmpObjectKey)."_odt' AND type = '".strtolower($myTmpObjectKey)."' AND entity = ".$conf->entity,
504 | "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('generic_".strtolower($myTmpObjectKey)."_odt', '".strtolower($myTmpObjectKey)."', ".$conf->entity.")"
505 | ));
506 | }
507 | }
508 |
509 | return $this->_init($sql, $options);
510 | }
511 |
512 | /**
513 | * Function called when module is disabled.
514 | * Remove from database constants, boxes and permissions from Dolibarr database.
515 | * Data directories are not deleted
516 | *
517 | * @param string $options Options when enabling module ('', 'noboxes')
518 | * @return int 1 if OK, 0 if KO
519 | */
520 | public function remove($options = '')
521 | {
522 | $sql = array();
523 | return $this->_remove($sql, $options);
524 | }
525 | }
526 |
--------------------------------------------------------------------------------