@@ -50,221 +50,221 @@ |
||
50 | 50 | $this->db = $db; |
51 | 51 | |
52 | 52 | $this->name = preg_replace('/^Interface/i', '', get_class($this)); |
53 | - $this->family = 'stripe'; |
|
53 | + $this->family = 'stripe'; |
|
54 | 54 | $this->description = "Triggers of the module Stripe"; |
55 | 55 | $this->version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' or version |
56 | 56 | $this->picto = 'stripe@stripe'; |
57 | 57 | } |
58 | 58 | |
59 | - /** |
|
60 | - * Trigger name |
|
61 | - * |
|
62 | - * @return string Name of trigger file |
|
63 | - */ |
|
64 | - public function getName() |
|
65 | - { |
|
66 | - return $this->name; |
|
67 | - } |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * Trigger description |
|
72 | - * |
|
73 | - * @return string Description of trigger file |
|
74 | - */ |
|
75 | - public function getDesc() |
|
76 | - { |
|
77 | - return $this->description; |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Trigger version |
|
82 | - * |
|
83 | - * @return string Version of trigger file |
|
84 | - */ |
|
85 | - public function getVersion() |
|
86 | - { |
|
87 | - global $langs; |
|
88 | - $langs->load("admin"); |
|
89 | - |
|
90 | - if ($this->version == 'development') { |
|
91 | - return $langs->trans("Development"); |
|
92 | - } elseif ($this->version == 'experimental') { |
|
93 | - return $langs->trans("Experimental"); |
|
94 | - } elseif ($this->version == 'dolibarr') { |
|
95 | - return DOL_VERSION; |
|
96 | - } elseif ($this->version) { |
|
97 | - return $this->version; |
|
98 | - } else { |
|
99 | - return $langs->trans("Unknown"); |
|
100 | - } |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Function called when a Dolibarrr business event is done. |
|
105 | - * All functions "runTrigger" are triggered if file |
|
106 | - * is inside directory core/triggers |
|
107 | - * |
|
108 | - * @param string $action Event action code |
|
109 | - * @param CommonObject $object Object |
|
110 | - * @param User $user Object user |
|
111 | - * @param Translate $langs Object langs |
|
112 | - * @param Conf $conf Object conf |
|
113 | - * @return int <0 if KO, 0 if no triggered ran, >0 if OK |
|
114 | - */ |
|
115 | - public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf) |
|
116 | - { |
|
117 | - // Put here code you want to execute when a Dolibarr business event occurs. |
|
118 | - // Data and type of action are stored into $object and $action |
|
119 | - global $langs, $db, $conf; |
|
120 | - |
|
121 | - // Load translation files required by the page |
|
59 | + /** |
|
60 | + * Trigger name |
|
61 | + * |
|
62 | + * @return string Name of trigger file |
|
63 | + */ |
|
64 | + public function getName() |
|
65 | + { |
|
66 | + return $this->name; |
|
67 | + } |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * Trigger description |
|
72 | + * |
|
73 | + * @return string Description of trigger file |
|
74 | + */ |
|
75 | + public function getDesc() |
|
76 | + { |
|
77 | + return $this->description; |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * Trigger version |
|
82 | + * |
|
83 | + * @return string Version of trigger file |
|
84 | + */ |
|
85 | + public function getVersion() |
|
86 | + { |
|
87 | + global $langs; |
|
88 | + $langs->load("admin"); |
|
89 | + |
|
90 | + if ($this->version == 'development') { |
|
91 | + return $langs->trans("Development"); |
|
92 | + } elseif ($this->version == 'experimental') { |
|
93 | + return $langs->trans("Experimental"); |
|
94 | + } elseif ($this->version == 'dolibarr') { |
|
95 | + return DOL_VERSION; |
|
96 | + } elseif ($this->version) { |
|
97 | + return $this->version; |
|
98 | + } else { |
|
99 | + return $langs->trans("Unknown"); |
|
100 | + } |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Function called when a Dolibarrr business event is done. |
|
105 | + * All functions "runTrigger" are triggered if file |
|
106 | + * is inside directory core/triggers |
|
107 | + * |
|
108 | + * @param string $action Event action code |
|
109 | + * @param CommonObject $object Object |
|
110 | + * @param User $user Object user |
|
111 | + * @param Translate $langs Object langs |
|
112 | + * @param Conf $conf Object conf |
|
113 | + * @return int <0 if KO, 0 if no triggered ran, >0 if OK |
|
114 | + */ |
|
115 | + public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf) |
|
116 | + { |
|
117 | + // Put here code you want to execute when a Dolibarr business event occurs. |
|
118 | + // Data and type of action are stored into $object and $action |
|
119 | + global $langs, $db, $conf; |
|
120 | + |
|
121 | + // Load translation files required by the page |
|
122 | 122 | $langs->loadLangs(array("members","other","users","mails")); |
123 | 123 | |
124 | - require_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php'; |
|
125 | - $stripe = new Stripe($db); |
|
126 | - |
|
127 | - if (empty($conf->stripe->enabled)) return 0; |
|
128 | - |
|
129 | - $ok = 1; |
|
130 | - |
|
131 | - $service = 'StripeTest'; |
|
132 | - $servicestatus = 0; |
|
133 | - if (! empty($conf->global->STRIPE_LIVE) && ! GETPOST('forcesandbox', 'alpha')) |
|
134 | - { |
|
135 | - $service = 'StripeLive'; |
|
136 | - $servicestatus = 1; |
|
137 | - } |
|
138 | - |
|
139 | - // If customer is linked to Stripe, we update/delete Stripe too |
|
140 | - if ($action == 'COMPANY_MODIFY') { |
|
141 | - dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); |
|
142 | - |
|
143 | - $stripeacc = $stripe->getStripeAccount($service); // No need of network access for this. May return '' if no Oauth defined. |
|
144 | - |
|
145 | - if ($object->client != 0) { |
|
146 | - $customer = $stripe->customerStripe($object, $stripeacc, $servicestatus); // This make a network request |
|
147 | - if ($customer) |
|
148 | - { |
|
149 | - $namecleaned = $object->name ? $object->name : null; |
|
150 | - $vatcleaned = $object->tva_intra ? $object->tva_intra : null; |
|
151 | - |
|
152 | - $taxinfo = array('type'=>'vat'); |
|
153 | - if ($vatcleaned) |
|
154 | - { |
|
155 | - $taxinfo["tax_id"] = $vatcleaned; |
|
156 | - } |
|
157 | - // We force data to "null" if not defined as expected by Stripe |
|
158 | - if (empty($vatcleaned)) $taxinfo=null; |
|
159 | - |
|
160 | - // Detect if we change a Stripe info (email, description, vat id) |
|
161 | - $changerequested = 0; |
|
162 | - if (! empty($object->email) && $object->email != $customer->email) $changerequested++; |
|
163 | - if ($namecleaned != $customer->description) $changerequested++; |
|
164 | - if (! isset($customer->tax_info['tax_id']) && ! is_null($vatcleaned)) $changerequested++; |
|
165 | - elseif (isset($customer->tax_info['tax_id']) && is_null($vatcleaned)) $changerequested++; |
|
166 | - elseif (isset($customer->tax_info['tax_id']) && ! is_null($vatcleaned)) |
|
167 | - { |
|
168 | - if ($vatcleaned != $customer->tax_info['tax_id']) $changerequested++; |
|
169 | - } |
|
170 | - |
|
171 | - if ($changerequested) |
|
172 | - { |
|
173 | - if (! empty($object->email)) $customer->email = $object->email; |
|
174 | - $customer->description = $namecleaned; |
|
175 | - if (empty($taxinfo)) $customer->tax_info = array('type'=>'vat', 'tax_id'=>null); |
|
176 | - else $customer->tax_info = $taxinfo; |
|
177 | - |
|
178 | - $customer->save(); |
|
179 | - } |
|
180 | - } |
|
181 | - } |
|
182 | - } |
|
183 | - if ($action == 'COMPANY_DELETE') { |
|
184 | - dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); |
|
185 | - |
|
186 | - $stripeacc = $stripe->getStripeAccount($service); // No need of network access for this. May return '' if no Oauth defined. |
|
187 | - |
|
188 | - $customer = $stripe->customerStripe($object, $stripeacc, $servicestatus); |
|
189 | - if ($customer) |
|
190 | - { |
|
191 | - $customer->delete(); |
|
192 | - } |
|
193 | - |
|
194 | - $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_account"; |
|
195 | - $sql.= " WHERE site='stripe' AND fk_soc = " . $object->id; |
|
196 | - $this->db->query($sql); |
|
197 | - } |
|
198 | - |
|
199 | - // If payment mode is linked to Stripee, we update/delete Stripe too |
|
200 | - if ($action == 'COMPANYPAYMENTMODE_MODIFY' && $object->type == 'card') { |
|
201 | - |
|
202 | - // For creation of credit card, we do not create in Stripe automatically |
|
203 | - } |
|
204 | - if ($action == 'COMPANYPAYMENTMODE_MODIFY' && $object->type == 'card') { |
|
205 | - dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); |
|
206 | - |
|
207 | - if (! empty($object->stripe_card_ref)) |
|
208 | - { |
|
209 | - $stripeacc = $stripe->getStripeAccount($service); // No need of network access for this. May return '' if no Oauth defined. |
|
210 | - $stripecu = $stripe->getStripeCustomerAccount($object->fk_soc); // No need of network access for this |
|
211 | - |
|
212 | - if ($stripecu) |
|
213 | - { |
|
214 | - // Get customer (required to get a card) |
|
215 | - if (empty($stripeacc)) { // If the Stripe connect account not set, we use common API usage |
|
216 | - $customer = \Stripe\Customer::retrieve($stripecu); |
|
217 | - } else { |
|
218 | - $customer = \Stripe\Customer::retrieve($stripecu, array("stripe_account" => $stripeacc)); |
|
219 | - } |
|
220 | - |
|
221 | - if ($customer) |
|
222 | - { |
|
223 | - $card = $stripe->cardStripe($customer, $object, $stripeacc, $servicestatus); |
|
224 | - if ($card) { |
|
225 | - $card->metadata=array('dol_id'=>$object->id, 'dol_version'=>DOL_VERSION, 'dol_entity'=>$conf->entity, 'ipaddress'=>(empty($_SERVER['REMOTE_ADDR'])?'':$_SERVER['REMOTE_ADDR'])); |
|
226 | - try { |
|
227 | - $card->save($dataforcard); |
|
228 | - } |
|
229 | - catch(Exception $e) |
|
230 | - { |
|
231 | - $ok = -1; |
|
232 | - $this->error = $e->getMessages(); |
|
233 | - } |
|
234 | - } |
|
235 | - } |
|
236 | - } |
|
237 | - } |
|
238 | - } |
|
239 | - if ($action == 'COMPANYPAYMENTMODE_DELETE' && $object->type == 'card') { |
|
240 | - dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); |
|
241 | - |
|
242 | - if (! empty($object->stripe_card_ref)) |
|
243 | - { |
|
244 | - $stripeacc = $stripe->getStripeAccount($service); // No need of network access for this. May return '' if no Oauth defined. |
|
245 | - $stripecu = $stripe->getStripeCustomerAccount($object->fk_soc); // No need of network access for this |
|
246 | - |
|
247 | - if ($stripecu) |
|
248 | - { |
|
249 | - // Get customer (required to get a card) |
|
250 | - if (empty($stripeacc)) { // If the Stripe connect account not set, we use common API usage |
|
251 | - $customer = \Stripe\Customer::retrieve($stripecu); |
|
252 | - } else { |
|
253 | - $customer = \Stripe\Customer::retrieve($stripecu, array("stripe_account" => $stripeacc)); |
|
254 | - } |
|
255 | - |
|
256 | - if ($customer) |
|
257 | - { |
|
258 | - $card = $stripe->cardStripe($customer, $object, $stripeacc, $servicestatus); |
|
259 | - if ($card) { |
|
260 | - if (method_exists($card, 'detach')) $card->detach(); |
|
261 | - else $card->delete(); |
|
262 | - } |
|
263 | - } |
|
264 | - } |
|
265 | - } |
|
266 | - } |
|
267 | - |
|
268 | - return $ok; |
|
269 | - } |
|
124 | + require_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php'; |
|
125 | + $stripe = new Stripe($db); |
|
126 | + |
|
127 | + if (empty($conf->stripe->enabled)) return 0; |
|
128 | + |
|
129 | + $ok = 1; |
|
130 | + |
|
131 | + $service = 'StripeTest'; |
|
132 | + $servicestatus = 0; |
|
133 | + if (! empty($conf->global->STRIPE_LIVE) && ! GETPOST('forcesandbox', 'alpha')) |
|
134 | + { |
|
135 | + $service = 'StripeLive'; |
|
136 | + $servicestatus = 1; |
|
137 | + } |
|
138 | + |
|
139 | + // If customer is linked to Stripe, we update/delete Stripe too |
|
140 | + if ($action == 'COMPANY_MODIFY') { |
|
141 | + dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); |
|
142 | + |
|
143 | + $stripeacc = $stripe->getStripeAccount($service); // No need of network access for this. May return '' if no Oauth defined. |
|
144 | + |
|
145 | + if ($object->client != 0) { |
|
146 | + $customer = $stripe->customerStripe($object, $stripeacc, $servicestatus); // This make a network request |
|
147 | + if ($customer) |
|
148 | + { |
|
149 | + $namecleaned = $object->name ? $object->name : null; |
|
150 | + $vatcleaned = $object->tva_intra ? $object->tva_intra : null; |
|
151 | + |
|
152 | + $taxinfo = array('type'=>'vat'); |
|
153 | + if ($vatcleaned) |
|
154 | + { |
|
155 | + $taxinfo["tax_id"] = $vatcleaned; |
|
156 | + } |
|
157 | + // We force data to "null" if not defined as expected by Stripe |
|
158 | + if (empty($vatcleaned)) $taxinfo=null; |
|
159 | + |
|
160 | + // Detect if we change a Stripe info (email, description, vat id) |
|
161 | + $changerequested = 0; |
|
162 | + if (! empty($object->email) && $object->email != $customer->email) $changerequested++; |
|
163 | + if ($namecleaned != $customer->description) $changerequested++; |
|
164 | + if (! isset($customer->tax_info['tax_id']) && ! is_null($vatcleaned)) $changerequested++; |
|
165 | + elseif (isset($customer->tax_info['tax_id']) && is_null($vatcleaned)) $changerequested++; |
|
166 | + elseif (isset($customer->tax_info['tax_id']) && ! is_null($vatcleaned)) |
|
167 | + { |
|
168 | + if ($vatcleaned != $customer->tax_info['tax_id']) $changerequested++; |
|
169 | + } |
|
170 | + |
|
171 | + if ($changerequested) |
|
172 | + { |
|
173 | + if (! empty($object->email)) $customer->email = $object->email; |
|
174 | + $customer->description = $namecleaned; |
|
175 | + if (empty($taxinfo)) $customer->tax_info = array('type'=>'vat', 'tax_id'=>null); |
|
176 | + else $customer->tax_info = $taxinfo; |
|
177 | + |
|
178 | + $customer->save(); |
|
179 | + } |
|
180 | + } |
|
181 | + } |
|
182 | + } |
|
183 | + if ($action == 'COMPANY_DELETE') { |
|
184 | + dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); |
|
185 | + |
|
186 | + $stripeacc = $stripe->getStripeAccount($service); // No need of network access for this. May return '' if no Oauth defined. |
|
187 | + |
|
188 | + $customer = $stripe->customerStripe($object, $stripeacc, $servicestatus); |
|
189 | + if ($customer) |
|
190 | + { |
|
191 | + $customer->delete(); |
|
192 | + } |
|
193 | + |
|
194 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_account"; |
|
195 | + $sql.= " WHERE site='stripe' AND fk_soc = " . $object->id; |
|
196 | + $this->db->query($sql); |
|
197 | + } |
|
198 | + |
|
199 | + // If payment mode is linked to Stripee, we update/delete Stripe too |
|
200 | + if ($action == 'COMPANYPAYMENTMODE_MODIFY' && $object->type == 'card') { |
|
201 | + |
|
202 | + // For creation of credit card, we do not create in Stripe automatically |
|
203 | + } |
|
204 | + if ($action == 'COMPANYPAYMENTMODE_MODIFY' && $object->type == 'card') { |
|
205 | + dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); |
|
206 | + |
|
207 | + if (! empty($object->stripe_card_ref)) |
|
208 | + { |
|
209 | + $stripeacc = $stripe->getStripeAccount($service); // No need of network access for this. May return '' if no Oauth defined. |
|
210 | + $stripecu = $stripe->getStripeCustomerAccount($object->fk_soc); // No need of network access for this |
|
211 | + |
|
212 | + if ($stripecu) |
|
213 | + { |
|
214 | + // Get customer (required to get a card) |
|
215 | + if (empty($stripeacc)) { // If the Stripe connect account not set, we use common API usage |
|
216 | + $customer = \Stripe\Customer::retrieve($stripecu); |
|
217 | + } else { |
|
218 | + $customer = \Stripe\Customer::retrieve($stripecu, array("stripe_account" => $stripeacc)); |
|
219 | + } |
|
220 | + |
|
221 | + if ($customer) |
|
222 | + { |
|
223 | + $card = $stripe->cardStripe($customer, $object, $stripeacc, $servicestatus); |
|
224 | + if ($card) { |
|
225 | + $card->metadata=array('dol_id'=>$object->id, 'dol_version'=>DOL_VERSION, 'dol_entity'=>$conf->entity, 'ipaddress'=>(empty($_SERVER['REMOTE_ADDR'])?'':$_SERVER['REMOTE_ADDR'])); |
|
226 | + try { |
|
227 | + $card->save($dataforcard); |
|
228 | + } |
|
229 | + catch(Exception $e) |
|
230 | + { |
|
231 | + $ok = -1; |
|
232 | + $this->error = $e->getMessages(); |
|
233 | + } |
|
234 | + } |
|
235 | + } |
|
236 | + } |
|
237 | + } |
|
238 | + } |
|
239 | + if ($action == 'COMPANYPAYMENTMODE_DELETE' && $object->type == 'card') { |
|
240 | + dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); |
|
241 | + |
|
242 | + if (! empty($object->stripe_card_ref)) |
|
243 | + { |
|
244 | + $stripeacc = $stripe->getStripeAccount($service); // No need of network access for this. May return '' if no Oauth defined. |
|
245 | + $stripecu = $stripe->getStripeCustomerAccount($object->fk_soc); // No need of network access for this |
|
246 | + |
|
247 | + if ($stripecu) |
|
248 | + { |
|
249 | + // Get customer (required to get a card) |
|
250 | + if (empty($stripeacc)) { // If the Stripe connect account not set, we use common API usage |
|
251 | + $customer = \Stripe\Customer::retrieve($stripecu); |
|
252 | + } else { |
|
253 | + $customer = \Stripe\Customer::retrieve($stripecu, array("stripe_account" => $stripeacc)); |
|
254 | + } |
|
255 | + |
|
256 | + if ($customer) |
|
257 | + { |
|
258 | + $card = $stripe->cardStripe($customer, $object, $stripeacc, $servicestatus); |
|
259 | + if ($card) { |
|
260 | + if (method_exists($card, 'detach')) $card->detach(); |
|
261 | + else $card->delete(); |
|
262 | + } |
|
263 | + } |
|
264 | + } |
|
265 | + } |
|
266 | + } |
|
267 | + |
|
268 | + return $ok; |
|
269 | + } |
|
270 | 270 | } |
@@ -30,119 +30,119 @@ |
||
30 | 30 | */ |
31 | 31 | class InterfaceNotification extends DolibarrTriggers |
32 | 32 | { |
33 | - public $family = 'notification'; |
|
34 | - public $description = "Triggers of this module send email notifications according to Notification module setup."; |
|
35 | - |
|
36 | - /** |
|
37 | - * Version of the trigger |
|
38 | - * @var string |
|
39 | - */ |
|
40 | - public $version = self::VERSION_DOLIBARR; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var string Image of the trigger |
|
44 | - */ |
|
45 | - public $picto = 'email'; |
|
46 | - |
|
47 | - // @TODO Defined also into notify.class.php) |
|
48 | - public $listofmanagedevents=array( |
|
49 | - 'BILL_VALIDATE', |
|
50 | - 'BILL_PAYED', |
|
51 | - 'ORDER_VALIDATE', |
|
52 | - 'PROPAL_VALIDATE', |
|
53 | - 'PROPAL_CLOSE_SIGNED', |
|
54 | - 'FICHINTER_VALIDATE', |
|
55 | - 'FICHINTER_ADD_CONTACT', |
|
56 | - 'ORDER_SUPPLIER_VALIDATE', |
|
57 | - 'ORDER_SUPPLIER_APPROVE', |
|
58 | - 'ORDER_SUPPLIER_REFUSE', |
|
59 | - 'SHIPPING_VALIDATE', |
|
60 | - 'EXPENSE_REPORT_VALIDATE', |
|
61 | - 'EXPENSE_REPORT_APPROVE', |
|
62 | - 'HOLIDAY_VALIDATE', |
|
63 | - 'HOLIDAY_APPROVE' |
|
64 | - ); |
|
65 | - |
|
66 | - /** |
|
67 | - * Function called when a Dolibarrr business event is done. |
|
68 | - * All functions "runTrigger" are triggered if file is inside directory htdocs/core/triggers or htdocs/module/code/triggers (and declared) |
|
69 | - * |
|
70 | - * @param string $action Event action code |
|
71 | - * @param Object $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->notification->enabled)) return 0; // Module not active, we do nothing |
|
80 | - |
|
81 | - require_once DOL_DOCUMENT_ROOT .'/core/class/notify.class.php'; |
|
82 | - $notify = new Notify($this->db); |
|
83 | - |
|
84 | - if (! in_array($action, $notify->arrayofnotifsupported)) return 0; |
|
85 | - |
|
86 | - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
87 | - |
|
88 | - $notify->send($action, $object); |
|
89 | - |
|
90 | - return 1; |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * Return list of events managed by notification module |
|
96 | - * |
|
97 | - * @return array Array of events managed by notification module |
|
98 | - */ |
|
99 | - function getListOfManagedEvents() |
|
100 | - { |
|
101 | - global $conf; |
|
102 | - |
|
103 | - $ret=array(); |
|
104 | - |
|
105 | - $sql = "SELECT rowid, code, label, description, elementtype"; |
|
106 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_action_trigger"; |
|
107 | - $sql.= $this->db->order("rang, elementtype, code"); |
|
108 | - dol_syslog("getListOfManagedEvents Get list of notifications", LOG_DEBUG); |
|
109 | - $resql=$this->db->query($sql); |
|
110 | - if ($resql) |
|
111 | - { |
|
112 | - $num=$this->db->num_rows($resql); |
|
113 | - $i=0; |
|
114 | - while ($i < $num) |
|
115 | - { |
|
116 | - $obj=$this->db->fetch_object($resql); |
|
117 | - |
|
118 | - $qualified=0; |
|
119 | - // Check is this event is supported by notification module |
|
120 | - if (in_array($obj->code, $this->listofmanagedevents)) $qualified=1; |
|
121 | - // Check if module for this event is active |
|
122 | - if ($qualified) |
|
123 | - { |
|
124 | - //print 'xx'.$obj->code; |
|
125 | - $element=$obj->elementtype; |
|
126 | - |
|
127 | - // Exclude events if related module is disabled |
|
128 | - if ($element == 'order_supplier' && empty($conf->fournisseur->enabled)) $qualified=0; |
|
129 | - elseif ($element == 'invoice_supplier' && empty($conf->fournisseur->enabled)) $qualified=0; |
|
130 | - elseif ($element == 'withdraw' && empty($conf->prelevement->enabled)) $qualified=0; |
|
131 | - elseif ($element == 'shipping' && empty($conf->expedition->enabled)) $qualified=0; |
|
132 | - elseif ($element == 'member' && empty($conf->adherent->enabled)) $qualified=0; |
|
133 | - elseif (! in_array($element,array('order_supplier','invoice_supplier','withdraw','shipping','member','expensereport')) && empty($conf->$element->enabled)) $qualified=0; |
|
134 | - } |
|
135 | - |
|
136 | - if ($qualified) |
|
137 | - { |
|
138 | - $ret[]=array('rowid'=>$obj->rowid,'code'=>$obj->code,'label'=>$obj->label,'description'=>$obj->description,'elementtype'=>$obj->elementtype); |
|
139 | - } |
|
140 | - |
|
141 | - $i++; |
|
142 | - } |
|
143 | - } |
|
144 | - else dol_print_error($this->db); |
|
145 | - |
|
146 | - return $ret; |
|
147 | - } |
|
33 | + public $family = 'notification'; |
|
34 | + public $description = "Triggers of this module send email notifications according to Notification module setup."; |
|
35 | + |
|
36 | + /** |
|
37 | + * Version of the trigger |
|
38 | + * @var string |
|
39 | + */ |
|
40 | + public $version = self::VERSION_DOLIBARR; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var string Image of the trigger |
|
44 | + */ |
|
45 | + public $picto = 'email'; |
|
46 | + |
|
47 | + // @TODO Defined also into notify.class.php) |
|
48 | + public $listofmanagedevents=array( |
|
49 | + 'BILL_VALIDATE', |
|
50 | + 'BILL_PAYED', |
|
51 | + 'ORDER_VALIDATE', |
|
52 | + 'PROPAL_VALIDATE', |
|
53 | + 'PROPAL_CLOSE_SIGNED', |
|
54 | + 'FICHINTER_VALIDATE', |
|
55 | + 'FICHINTER_ADD_CONTACT', |
|
56 | + 'ORDER_SUPPLIER_VALIDATE', |
|
57 | + 'ORDER_SUPPLIER_APPROVE', |
|
58 | + 'ORDER_SUPPLIER_REFUSE', |
|
59 | + 'SHIPPING_VALIDATE', |
|
60 | + 'EXPENSE_REPORT_VALIDATE', |
|
61 | + 'EXPENSE_REPORT_APPROVE', |
|
62 | + 'HOLIDAY_VALIDATE', |
|
63 | + 'HOLIDAY_APPROVE' |
|
64 | + ); |
|
65 | + |
|
66 | + /** |
|
67 | + * Function called when a Dolibarrr business event is done. |
|
68 | + * All functions "runTrigger" are triggered if file is inside directory htdocs/core/triggers or htdocs/module/code/triggers (and declared) |
|
69 | + * |
|
70 | + * @param string $action Event action code |
|
71 | + * @param Object $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->notification->enabled)) return 0; // Module not active, we do nothing |
|
80 | + |
|
81 | + require_once DOL_DOCUMENT_ROOT .'/core/class/notify.class.php'; |
|
82 | + $notify = new Notify($this->db); |
|
83 | + |
|
84 | + if (! in_array($action, $notify->arrayofnotifsupported)) return 0; |
|
85 | + |
|
86 | + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
87 | + |
|
88 | + $notify->send($action, $object); |
|
89 | + |
|
90 | + return 1; |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * Return list of events managed by notification module |
|
96 | + * |
|
97 | + * @return array Array of events managed by notification module |
|
98 | + */ |
|
99 | + function getListOfManagedEvents() |
|
100 | + { |
|
101 | + global $conf; |
|
102 | + |
|
103 | + $ret=array(); |
|
104 | + |
|
105 | + $sql = "SELECT rowid, code, label, description, elementtype"; |
|
106 | + $sql.= " FROM ".MAIN_DB_PREFIX."c_action_trigger"; |
|
107 | + $sql.= $this->db->order("rang, elementtype, code"); |
|
108 | + dol_syslog("getListOfManagedEvents Get list of notifications", LOG_DEBUG); |
|
109 | + $resql=$this->db->query($sql); |
|
110 | + if ($resql) |
|
111 | + { |
|
112 | + $num=$this->db->num_rows($resql); |
|
113 | + $i=0; |
|
114 | + while ($i < $num) |
|
115 | + { |
|
116 | + $obj=$this->db->fetch_object($resql); |
|
117 | + |
|
118 | + $qualified=0; |
|
119 | + // Check is this event is supported by notification module |
|
120 | + if (in_array($obj->code, $this->listofmanagedevents)) $qualified=1; |
|
121 | + // Check if module for this event is active |
|
122 | + if ($qualified) |
|
123 | + { |
|
124 | + //print 'xx'.$obj->code; |
|
125 | + $element=$obj->elementtype; |
|
126 | + |
|
127 | + // Exclude events if related module is disabled |
|
128 | + if ($element == 'order_supplier' && empty($conf->fournisseur->enabled)) $qualified=0; |
|
129 | + elseif ($element == 'invoice_supplier' && empty($conf->fournisseur->enabled)) $qualified=0; |
|
130 | + elseif ($element == 'withdraw' && empty($conf->prelevement->enabled)) $qualified=0; |
|
131 | + elseif ($element == 'shipping' && empty($conf->expedition->enabled)) $qualified=0; |
|
132 | + elseif ($element == 'member' && empty($conf->adherent->enabled)) $qualified=0; |
|
133 | + elseif (! in_array($element,array('order_supplier','invoice_supplier','withdraw','shipping','member','expensereport')) && empty($conf->$element->enabled)) $qualified=0; |
|
134 | + } |
|
135 | + |
|
136 | + if ($qualified) |
|
137 | + { |
|
138 | + $ret[]=array('rowid'=>$obj->rowid,'code'=>$obj->code,'label'=>$obj->label,'description'=>$obj->description,'elementtype'=>$obj->elementtype); |
|
139 | + } |
|
140 | + |
|
141 | + $i++; |
|
142 | + } |
|
143 | + } |
|
144 | + else dol_print_error($this->db); |
|
145 | + |
|
146 | + return $ret; |
|
147 | + } |
|
148 | 148 | } |
@@ -31,781 +31,781 @@ |
||
31 | 31 | */ |
32 | 32 | class InterfaceLdapsynchro extends DolibarrTriggers |
33 | 33 | { |
34 | - public $family = 'ldap'; |
|
35 | - public $description = "Triggers of this module allows to synchronize Dolibarr toward a LDAP database."; |
|
36 | - |
|
37 | - /** |
|
38 | - * Version of the trigger |
|
39 | - * @var string |
|
40 | - */ |
|
41 | - public $version = self::VERSION_DOLIBARR; |
|
42 | - |
|
43 | - /** |
|
44 | - * @var string Image of the trigger |
|
45 | - */ |
|
46 | - public $picto = 'technic'; |
|
47 | - |
|
48 | - /** |
|
49 | - * Function called when a Dolibarrr business event is done. |
|
50 | - * All functions "runTrigger" are triggered if file is inside directory htdocs/core/triggers or htdocs/module/code/triggers (and declared) |
|
51 | - * |
|
52 | - * @param string $action Event action code |
|
53 | - * @param Object $object Object |
|
54 | - * @param User $user Object user |
|
55 | - * @param Translate $langs Object langs |
|
56 | - * @param conf $conf Object conf |
|
57 | - * @return int <0 if KO, 0 if no triggered ran, >0 if OK |
|
58 | - */ |
|
59 | - public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf) |
|
60 | - { |
|
61 | - if (empty($conf->ldap->enabled)) return 0; // Module not active, we do nothing |
|
62 | - if (defined('DISABLE_LDAP_SYNCHRO')) return 0; // If constant defined, we do nothing |
|
63 | - |
|
64 | - if (! function_exists('ldap_connect')) |
|
65 | - { |
|
66 | - dol_syslog("Warning, module LDAP is enabled but LDAP functions not available in this PHP", LOG_WARNING); |
|
67 | - return 0; |
|
68 | - } |
|
69 | - |
|
70 | - require_once DOL_DOCUMENT_ROOT."/core/class/ldap.class.php"; |
|
71 | - require_once DOL_DOCUMENT_ROOT."/user/class/usergroup.class.php"; |
|
72 | - |
|
73 | - $result=0; |
|
74 | - |
|
75 | - // Users |
|
76 | - if ($action == 'USER_CREATE') |
|
77 | - { |
|
78 | - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
79 | - if (! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') |
|
80 | - { |
|
81 | - $ldap=new Ldap(); |
|
82 | - $result=$ldap->connect_bind(); |
|
83 | - |
|
84 | - if ($result > 0) |
|
85 | - { |
|
86 | - $info=$object->_load_ldap_info(); |
|
87 | - $dn=$object->_load_ldap_dn($info); |
|
88 | - |
|
89 | - $result=$ldap->add($dn,$info,$user); |
|
90 | - } |
|
91 | - |
|
92 | - if ($result < 0) $this->error="ErrorLDAP ".$ldap->error; |
|
93 | - } |
|
94 | - } |
|
95 | - elseif ($action == 'USER_MODIFY') |
|
96 | - { |
|
97 | - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
98 | - if (! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') |
|
99 | - { |
|
100 | - $ldap=new Ldap(); |
|
101 | - $result=$ldap->connect_bind(); |
|
102 | - |
|
103 | - if ($result > 0) |
|
104 | - { |
|
105 | - if (empty($object->oldcopy) || ! is_object($object->oldcopy)) |
|
106 | - { |
|
107 | - dol_syslog("Trigger ".$action." was called by a function that did not set previously the property ->oldcopy onto object", LOG_WARNING); |
|
108 | - $object->oldcopy = clone $object; |
|
109 | - } |
|
110 | - |
|
111 | - $oldinfo=$object->oldcopy->_load_ldap_info(); |
|
112 | - $olddn=$object->oldcopy->_load_ldap_dn($oldinfo); |
|
113 | - |
|
114 | - // Verify if entry exist |
|
115 | - $container=$object->oldcopy->_load_ldap_dn($oldinfo,1); |
|
116 | - $search = "(".$object->oldcopy->_load_ldap_dn($oldinfo,2).")"; |
|
117 | - $records=$ldap->search($container,$search); |
|
118 | - if (count($records) && $records['count'] == 0) |
|
119 | - { |
|
120 | - $olddn = ''; |
|
121 | - } |
|
122 | - |
|
123 | - $info=$object->_load_ldap_info(); |
|
124 | - $dn=$object->_load_ldap_dn($info); |
|
125 | - $newrdn=$object->_load_ldap_dn($info,2); |
|
126 | - $newparent=$object->_load_ldap_dn($info,1); |
|
127 | - |
|
128 | - $result=$ldap->update($dn,$info,$user,$olddn,$newrdn,$newparent); |
|
129 | - } |
|
130 | - |
|
131 | - if ($result < 0) $this->error="ErrorLDAP ".$ldap->error; |
|
132 | - } |
|
133 | - } |
|
134 | - elseif ($action == 'USER_NEW_PASSWORD') |
|
135 | - { |
|
136 | - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
137 | - if (! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') |
|
138 | - { |
|
139 | - $ldap=new Ldap(); |
|
140 | - $result=$ldap->connect_bind(); |
|
141 | - |
|
142 | - if ($result > 0) |
|
143 | - { |
|
144 | - if (empty($object->oldcopy) || ! is_object($object->oldcopy)) |
|
145 | - { |
|
146 | - dol_syslog("Trigger ".$action." was called by a function that did not set previously the property ->oldcopy onto object", LOG_WARNING); |
|
147 | - $object->oldcopy = clone $object; |
|
148 | - } |
|
149 | - |
|
150 | - $oldinfo=$object->oldcopy->_load_ldap_info(); |
|
151 | - $olddn=$object->oldcopy->_load_ldap_dn($oldinfo); |
|
152 | - |
|
153 | - // Verify if entry exist |
|
154 | - $container=$object->oldcopy->_load_ldap_dn($oldinfo,1); |
|
155 | - $search = "(".$object->oldcopy->_load_ldap_dn($oldinfo,2).")"; |
|
156 | - $records=$ldap->search($container,$search); |
|
157 | - if (count($records) && $records['count'] == 0) |
|
158 | - { |
|
159 | - $olddn = ''; |
|
160 | - } |
|
161 | - |
|
162 | - $info=$object->_load_ldap_info(); |
|
163 | - $dn=$object->_load_ldap_dn($info); |
|
164 | - |
|
165 | - $result=$ldap->update($dn,$info,$user,$olddn); |
|
166 | - } |
|
167 | - |
|
168 | - if ($result < 0) $this->error="ErrorLDAP ".$ldap->error; |
|
169 | - } |
|
170 | - } |
|
171 | - elseif ($action == 'USER_ENABLEDISABLE') |
|
172 | - { |
|
173 | - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
174 | - } |
|
175 | - elseif ($action == 'USER_DELETE') |
|
176 | - { |
|
177 | - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
178 | - if (! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') |
|
179 | - { |
|
180 | - $ldap=new Ldap(); |
|
181 | - $result=$ldap->connect_bind(); |
|
182 | - |
|
183 | - if ($result > 0) |
|
184 | - { |
|
185 | - $info=$object->_load_ldap_info(); |
|
186 | - $dn=$object->_load_ldap_dn($info); |
|
187 | - |
|
188 | - $result=$ldap->delete($dn); |
|
189 | - } |
|
190 | - |
|
191 | - if ($result < 0) $this->error="ErrorLDAP ".$ldap->error; |
|
192 | - } |
|
193 | - } |
|
194 | - elseif ($action == 'USER_SETINGROUP') |
|
195 | - { |
|
196 | - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
197 | - if (! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') |
|
198 | - { |
|
199 | - $ldap=new Ldap(); |
|
200 | - $result=$ldap->connect_bind(); |
|
201 | - |
|
202 | - if ($result > 0) |
|
203 | - { |
|
204 | - // Must edit $object->newgroupid |
|
205 | - $usergroup=new UserGroup($this->db); |
|
206 | - if ($object->newgroupid > 0) |
|
207 | - { |
|
208 | - $usergroup->fetch($object->newgroupid); |
|
209 | - |
|
210 | - $oldinfo=$usergroup->_load_ldap_info(); |
|
211 | - $olddn=$usergroup->_load_ldap_dn($oldinfo); |
|
212 | - |
|
213 | - // Verify if entry exist |
|
214 | - $container=$usergroup->_load_ldap_dn($oldinfo,1); |
|
215 | - $search = "(".$usergroup->_load_ldap_dn($oldinfo,2).")"; |
|
216 | - $records=$ldap->search($container,$search); |
|
217 | - if (count($records) && $records['count'] == 0) |
|
218 | - { |
|
219 | - $olddn = ''; |
|
220 | - } |
|
221 | - |
|
222 | - $info=$usergroup->_load_ldap_info(); // Contains all members, included the new one (insert already done before trigger call) |
|
223 | - $dn=$usergroup->_load_ldap_dn($info); |
|
224 | - |
|
225 | - $result=$ldap->update($dn,$info,$user,$olddn); |
|
226 | - } |
|
227 | - } |
|
228 | - |
|
229 | - if ($result < 0) $this->error="ErrorLDAP ".$ldap->error; |
|
230 | - } |
|
231 | - } |
|
232 | - elseif ($action == 'USER_REMOVEFROMGROUP') |
|
233 | - { |
|
234 | - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
235 | - if (! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') |
|
236 | - { |
|
237 | - $ldap=new Ldap(); |
|
238 | - $result=$ldap->connect_bind(); |
|
239 | - |
|
240 | - if ($result > 0) |
|
241 | - { |
|
242 | - // Must edit $object->newgroupid |
|
243 | - $usergroup=new UserGroup($this->db); |
|
244 | - if ($object->oldgroupid > 0) |
|
245 | - { |
|
246 | - $usergroup->fetch($object->oldgroupid); |
|
247 | - |
|
248 | - $oldinfo=$usergroup->_load_ldap_info(); |
|
249 | - $olddn=$usergroup->_load_ldap_dn($oldinfo); |
|
250 | - |
|
251 | - // Verify if entry exist |
|
252 | - $container=$usergroup->_load_ldap_dn($oldinfo,1); |
|
253 | - $search = "(".$usergroup->_load_ldap_dn($oldinfo,2).")"; |
|
254 | - $records=$ldap->search($container,$search); |
|
255 | - if (count($records) && $records['count'] == 0) |
|
256 | - { |
|
257 | - $olddn = ''; |
|
258 | - } |
|
259 | - |
|
260 | - $info=$usergroup->_load_ldap_info(); // Contains all members, included the new one (insert already done before trigger call) |
|
261 | - $dn=$usergroup->_load_ldap_dn($info); |
|
262 | - |
|
263 | - $result=$ldap->update($dn,$info,$user,$olddn); |
|
264 | - } |
|
265 | - } |
|
266 | - |
|
267 | - if ($result < 0) $this->error="ErrorLDAP ".$ldap->error; |
|
268 | - } |
|
269 | - } |
|
270 | - |
|
271 | - // Groupes |
|
272 | - elseif ($action == 'GROUP_CREATE') |
|
273 | - { |
|
274 | - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
275 | - if (! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') |
|
276 | - { |
|
277 | - $ldap=new Ldap(); |
|
278 | - $result=$ldap->connect_bind(); |
|
279 | - |
|
280 | - if ($result > 0) |
|
281 | - { |
|
282 | - $info=$object->_load_ldap_info(); |
|
283 | - $dn=$object->_load_ldap_dn($info); |
|
284 | - |
|
285 | - // Get a gid number for objectclass PosixGroup |
|
286 | - if (in_array('posixGroup',$info['objectclass'])) { |
|
287 | - $info['gidNumber'] = $ldap->getNextGroupGid('LDAP_KEY_GROUPS'); |
|
288 | - } |
|
289 | - |
|
290 | - $result=$ldap->add($dn,$info,$user); |
|
291 | - } |
|
292 | - |
|
293 | - if ($result < 0) $this->error="ErrorLDAP ".$ldap->error; |
|
294 | - } |
|
295 | - } |
|
296 | - elseif ($action == 'GROUP_MODIFY') |
|
297 | - { |
|
298 | - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
299 | - if (! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') |
|
300 | - { |
|
301 | - $ldap=new Ldap(); |
|
302 | - $result=$ldap->connect_bind(); |
|
303 | - |
|
304 | - if ($result > 0) |
|
305 | - { |
|
306 | - if (empty($object->oldcopy) || ! is_object($object->oldcopy)) |
|
307 | - { |
|
308 | - dol_syslog("Trigger ".$action." was called by a function that did not set previously the property ->oldcopy onto object", LOG_WARNING); |
|
309 | - $object->oldcopy = clone $object; |
|
310 | - } |
|
311 | - |
|
312 | - $oldinfo=$object->oldcopy->_load_ldap_info(); |
|
313 | - $olddn=$object->oldcopy->_load_ldap_dn($oldinfo); |
|
314 | - |
|
315 | - // Verify if entry exist |
|
316 | - $container=$object->oldcopy->_load_ldap_dn($oldinfo,1); |
|
317 | - $search = "(".$object->oldcopy->_load_ldap_dn($oldinfo,2).")"; |
|
318 | - $records=$ldap->search($container,$search); |
|
319 | - if (count($records) && $records['count'] == 0) |
|
320 | - { |
|
321 | - $olddn = ''; |
|
322 | - } |
|
323 | - |
|
324 | - $info=$object->_load_ldap_info(); |
|
325 | - $dn=$object->_load_ldap_dn($info); |
|
326 | - |
|
327 | - $result=$ldap->update($dn,$info,$user,$olddn); |
|
328 | - } |
|
329 | - |
|
330 | - if ($result < 0) $this->error="ErrorLDAP ".$ldap->error; |
|
331 | - } |
|
332 | - } |
|
333 | - elseif ($action == 'GROUP_DELETE') |
|
334 | - { |
|
335 | - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
336 | - if (! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') |
|
337 | - { |
|
338 | - $ldap=new Ldap(); |
|
339 | - $result=$ldap->connect_bind(); |
|
340 | - |
|
341 | - if ($result > 0) |
|
342 | - { |
|
343 | - $info=$object->_load_ldap_info(); |
|
344 | - $dn=$object->_load_ldap_dn($info); |
|
345 | - |
|
346 | - $result=$ldap->delete($dn); |
|
347 | - } |
|
348 | - |
|
349 | - if ($result < 0) $this->error="ErrorLDAP ".$ldap->error; |
|
350 | - } |
|
351 | - } |
|
352 | - |
|
353 | - // Contacts |
|
354 | - elseif ($action == 'CONTACT_CREATE') |
|
355 | - { |
|
356 | - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
357 | - if (! empty($conf->global->LDAP_CONTACT_ACTIVE)) |
|
358 | - { |
|
359 | - $ldap=new Ldap(); |
|
360 | - $result=$ldap->connect_bind(); |
|
361 | - |
|
362 | - if ($result > 0) |
|
363 | - { |
|
364 | - $info=$object->_load_ldap_info(); |
|
365 | - $dn=$object->_load_ldap_dn($info); |
|
366 | - |
|
367 | - $result=$ldap->add($dn,$info,$user); |
|
368 | - } |
|
369 | - |
|
370 | - if ($result < 0) $this->error="ErrorLDAP ".$ldap->error; |
|
371 | - } |
|
372 | - } |
|
373 | - elseif ($action == 'CONTACT_MODIFY') |
|
374 | - { |
|
375 | - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
376 | - if (! empty($conf->global->LDAP_CONTACT_ACTIVE)) |
|
377 | - { |
|
378 | - $ldap=new Ldap(); |
|
379 | - $result=$ldap->connect_bind(); |
|
380 | - |
|
381 | - if ($result > 0) |
|
382 | - { |
|
383 | - if (empty($object->oldcopy) || ! is_object($object->oldcopy)) |
|
384 | - { |
|
385 | - dol_syslog("Trigger ".$action." was called by a function that did not set previously the property ->oldcopy onto object", LOG_WARNING); |
|
386 | - $object->oldcopy = clone $object; |
|
387 | - } |
|
388 | - |
|
389 | - $oldinfo=$object->oldcopy->_load_ldap_info(); |
|
390 | - $olddn=$object->oldcopy->_load_ldap_dn($oldinfo); |
|
391 | - |
|
392 | - // Verify if entry exist |
|
393 | - $container=$object->oldcopy->_load_ldap_dn($oldinfo,1); |
|
394 | - $search = "(".$object->oldcopy->_load_ldap_dn($oldinfo,2).")"; |
|
395 | - $records=$ldap->search($container,$search); |
|
396 | - if (count($records) && $records['count'] == 0) |
|
397 | - { |
|
398 | - $olddn = ''; |
|
399 | - } |
|
400 | - |
|
401 | - $info=$object->_load_ldap_info(); |
|
402 | - $dn=$object->_load_ldap_dn($info); |
|
403 | - |
|
404 | - $result=$ldap->update($dn,$info,$user,$olddn); |
|
405 | - } |
|
406 | - |
|
407 | - if ($result < 0) $this->error="ErrorLDAP ".$ldap->error; |
|
408 | - } |
|
409 | - } |
|
410 | - elseif ($action == 'CONTACT_DELETE') |
|
411 | - { |
|
412 | - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
413 | - if (! empty($conf->global->LDAP_CONTACT_ACTIVE)) |
|
414 | - { |
|
415 | - $ldap=new Ldap(); |
|
416 | - $result=$ldap->connect_bind(); |
|
417 | - |
|
418 | - if ($result > 0) |
|
419 | - { |
|
420 | - $info=$object->_load_ldap_info(); |
|
421 | - $dn=$object->_load_ldap_dn($info); |
|
422 | - |
|
423 | - $result=$ldap->delete($dn); |
|
424 | - } |
|
425 | - |
|
426 | - if ($result < 0) $this->error="ErrorLDAP ".$ldap->error; |
|
427 | - } |
|
428 | - } |
|
429 | - |
|
430 | - // Members |
|
431 | - elseif ($action == 'MEMBER_CREATE') |
|
432 | - { |
|
433 | - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
434 | - if (! empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1') |
|
435 | - { |
|
436 | - $ldap=new Ldap(); |
|
437 | - $result=$ldap->connect_bind(); |
|
438 | - |
|
439 | - if ($result > 0) |
|
440 | - { |
|
441 | - $info=$object->_load_ldap_info(); |
|
442 | - $dn=$object->_load_ldap_dn($info); |
|
443 | - |
|
444 | - $result=$ldap->add($dn,$info,$user); |
|
445 | - |
|
446 | - // For member type |
|
447 | - if (! empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1') |
|
448 | - { |
|
449 | - $membertype=new AdherentType($this->db); |
|
450 | - if ($object->typeid > 0) |
|
451 | - { |
|
452 | - $membertype->fetch($object->typeid); |
|
453 | - $membertype->listMembersForMemberType('', 1); |
|
454 | - |
|
455 | - $oldinfo=$membertype->_load_ldap_info(); |
|
456 | - $olddn=$membertype->_load_ldap_dn($oldinfo); |
|
457 | - |
|
458 | - // Verify if entry exist |
|
459 | - $container=$membertype->_load_ldap_dn($oldinfo,1); |
|
460 | - $search = "(".$membertype->_load_ldap_dn($oldinfo,2).")"; |
|
461 | - $records=$ldap->search($container,$search); |
|
462 | - if (count($records) && $records['count'] == 0) |
|
463 | - { |
|
464 | - $olddn = ''; |
|
465 | - } |
|
466 | - |
|
467 | - $info=$membertype->_load_ldap_info(); // Contains all members, included the new one (insert already done before trigger call) |
|
468 | - $dn=$membertype->_load_ldap_dn($info); |
|
469 | - |
|
470 | - $result=$ldap->update($dn,$info,$user,$olddn); |
|
471 | - } |
|
472 | - } |
|
473 | - } |
|
474 | - |
|
475 | - if ($result < 0) $this->error="ErrorLDAP ".$ldap->error; |
|
476 | - } |
|
477 | - } |
|
478 | - elseif ($action == 'MEMBER_VALIDATE') |
|
479 | - { |
|
480 | - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
481 | - if (! empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1') |
|
482 | - { |
|
483 | - // If status field is setup to be synchronized |
|
484 | - if (! empty($conf->global->LDAP_FIELD_MEMBER_STATUS)) |
|
485 | - { |
|
486 | - $ldap=new Ldap(); |
|
487 | - $result=$ldap->connect_bind(); |
|
488 | - |
|
489 | - if ($result > 0) |
|
490 | - { |
|
491 | - $info=$object->_load_ldap_info(); |
|
492 | - $dn=$object->_load_ldap_dn($info); |
|
493 | - $olddn=$dn; // We know olddn=dn as we change only status |
|
494 | - |
|
495 | - $result=$ldap->update($dn,$info,$user,$olddn); |
|
496 | - } |
|
497 | - |
|
498 | - if ($result < 0) $this->error="ErrorLDAP ".$ldap->error; |
|
499 | - } |
|
500 | - } |
|
501 | - } |
|
502 | - elseif ($action == 'MEMBER_SUBSCRIPTION') |
|
503 | - { |
|
504 | - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
505 | - if (! empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1') |
|
506 | - { |
|
507 | - // If subscriptions fields are setup to be synchronized |
|
508 | - if ($conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE |
|
509 | - || $conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT |
|
510 | - || $conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE |
|
511 | - || $conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT |
|
512 | - || $conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION) |
|
513 | - { |
|
514 | - $ldap=new Ldap(); |
|
515 | - $result=$ldap->connect_bind(); |
|
516 | - |
|
517 | - if ($result > 0) |
|
518 | - { |
|
519 | - $info=$object->_load_ldap_info(); |
|
520 | - $dn=$object->_load_ldap_dn($info); |
|
521 | - $olddn=$dn; // We know olddn=dn as we change only subscriptions |
|
522 | - |
|
523 | - $result=$ldap->update($dn,$info,$user,$olddn); |
|
524 | - } |
|
525 | - |
|
526 | - if ($result < 0) $this->error="ErrorLDAP ".$ldap->error; |
|
527 | - } |
|
528 | - } |
|
529 | - } |
|
530 | - elseif ($action == 'MEMBER_MODIFY') |
|
531 | - { |
|
532 | - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
533 | - if (! empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1') |
|
534 | - { |
|
535 | - $ldap=new Ldap(); |
|
536 | - $result=$ldap->connect_bind(); |
|
537 | - |
|
538 | - if ($result > 0) |
|
539 | - { |
|
540 | - if (empty($object->oldcopy) || ! is_object($object->oldcopy)) |
|
541 | - { |
|
542 | - dol_syslog("Trigger ".$action." was called by a function that did not set previously the property ->oldcopy onto object", LOG_WARNING); |
|
543 | - $object->oldcopy = clone $object; |
|
544 | - } |
|
545 | - |
|
546 | - $oldinfo=$object->oldcopy->_load_ldap_info(); |
|
547 | - $olddn=$object->oldcopy->_load_ldap_dn($oldinfo); |
|
548 | - |
|
549 | - // Verify if entry exist |
|
550 | - $container=$object->oldcopy->_load_ldap_dn($oldinfo,1); |
|
551 | - $search = "(".$object->oldcopy->_load_ldap_dn($oldinfo,2).")"; |
|
552 | - $records=$ldap->search($container,$search); |
|
553 | - if (count($records) && $records['count'] == 0) |
|
554 | - { |
|
555 | - $olddn = ''; |
|
556 | - } |
|
557 | - |
|
558 | - $info=$object->_load_ldap_info(); |
|
559 | - $dn=$object->_load_ldap_dn($info); |
|
560 | - $newrdn=$object->_load_ldap_dn($info,2); |
|
561 | - $newparent=$object->_load_ldap_dn($info,1); |
|
562 | - |
|
563 | - $result=$ldap->update($dn,$info,$user,$olddn,$newrdn,$newparent); |
|
564 | - |
|
565 | - // For member type |
|
566 | - if (! empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1') |
|
567 | - { |
|
568 | - /* |
|
34 | + public $family = 'ldap'; |
|
35 | + public $description = "Triggers of this module allows to synchronize Dolibarr toward a LDAP database."; |
|
36 | + |
|
37 | + /** |
|
38 | + * Version of the trigger |
|
39 | + * @var string |
|
40 | + */ |
|
41 | + public $version = self::VERSION_DOLIBARR; |
|
42 | + |
|
43 | + /** |
|
44 | + * @var string Image of the trigger |
|
45 | + */ |
|
46 | + public $picto = 'technic'; |
|
47 | + |
|
48 | + /** |
|
49 | + * Function called when a Dolibarrr business event is done. |
|
50 | + * All functions "runTrigger" are triggered if file is inside directory htdocs/core/triggers or htdocs/module/code/triggers (and declared) |
|
51 | + * |
|
52 | + * @param string $action Event action code |
|
53 | + * @param Object $object Object |
|
54 | + * @param User $user Object user |
|
55 | + * @param Translate $langs Object langs |
|
56 | + * @param conf $conf Object conf |
|
57 | + * @return int <0 if KO, 0 if no triggered ran, >0 if OK |
|
58 | + */ |
|
59 | + public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf) |
|
60 | + { |
|
61 | + if (empty($conf->ldap->enabled)) return 0; // Module not active, we do nothing |
|
62 | + if (defined('DISABLE_LDAP_SYNCHRO')) return 0; // If constant defined, we do nothing |
|
63 | + |
|
64 | + if (! function_exists('ldap_connect')) |
|
65 | + { |
|
66 | + dol_syslog("Warning, module LDAP is enabled but LDAP functions not available in this PHP", LOG_WARNING); |
|
67 | + return 0; |
|
68 | + } |
|
69 | + |
|
70 | + require_once DOL_DOCUMENT_ROOT."/core/class/ldap.class.php"; |
|
71 | + require_once DOL_DOCUMENT_ROOT."/user/class/usergroup.class.php"; |
|
72 | + |
|
73 | + $result=0; |
|
74 | + |
|
75 | + // Users |
|
76 | + if ($action == 'USER_CREATE') |
|
77 | + { |
|
78 | + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
79 | + if (! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') |
|
80 | + { |
|
81 | + $ldap=new Ldap(); |
|
82 | + $result=$ldap->connect_bind(); |
|
83 | + |
|
84 | + if ($result > 0) |
|
85 | + { |
|
86 | + $info=$object->_load_ldap_info(); |
|
87 | + $dn=$object->_load_ldap_dn($info); |
|
88 | + |
|
89 | + $result=$ldap->add($dn,$info,$user); |
|
90 | + } |
|
91 | + |
|
92 | + if ($result < 0) $this->error="ErrorLDAP ".$ldap->error; |
|
93 | + } |
|
94 | + } |
|
95 | + elseif ($action == 'USER_MODIFY') |
|
96 | + { |
|
97 | + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
98 | + if (! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') |
|
99 | + { |
|
100 | + $ldap=new Ldap(); |
|
101 | + $result=$ldap->connect_bind(); |
|
102 | + |
|
103 | + if ($result > 0) |
|
104 | + { |
|
105 | + if (empty($object->oldcopy) || ! is_object($object->oldcopy)) |
|
106 | + { |
|
107 | + dol_syslog("Trigger ".$action." was called by a function that did not set previously the property ->oldcopy onto object", LOG_WARNING); |
|
108 | + $object->oldcopy = clone $object; |
|
109 | + } |
|
110 | + |
|
111 | + $oldinfo=$object->oldcopy->_load_ldap_info(); |
|
112 | + $olddn=$object->oldcopy->_load_ldap_dn($oldinfo); |
|
113 | + |
|
114 | + // Verify if entry exist |
|
115 | + $container=$object->oldcopy->_load_ldap_dn($oldinfo,1); |
|
116 | + $search = "(".$object->oldcopy->_load_ldap_dn($oldinfo,2).")"; |
|
117 | + $records=$ldap->search($container,$search); |
|
118 | + if (count($records) && $records['count'] == 0) |
|
119 | + { |
|
120 | + $olddn = ''; |
|
121 | + } |
|
122 | + |
|
123 | + $info=$object->_load_ldap_info(); |
|
124 | + $dn=$object->_load_ldap_dn($info); |
|
125 | + $newrdn=$object->_load_ldap_dn($info,2); |
|
126 | + $newparent=$object->_load_ldap_dn($info,1); |
|
127 | + |
|
128 | + $result=$ldap->update($dn,$info,$user,$olddn,$newrdn,$newparent); |
|
129 | + } |
|
130 | + |
|
131 | + if ($result < 0) $this->error="ErrorLDAP ".$ldap->error; |
|
132 | + } |
|
133 | + } |
|
134 | + elseif ($action == 'USER_NEW_PASSWORD') |
|
135 | + { |
|
136 | + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
137 | + if (! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') |
|
138 | + { |
|
139 | + $ldap=new Ldap(); |
|
140 | + $result=$ldap->connect_bind(); |
|
141 | + |
|
142 | + if ($result > 0) |
|
143 | + { |
|
144 | + if (empty($object->oldcopy) || ! is_object($object->oldcopy)) |
|
145 | + { |
|
146 | + dol_syslog("Trigger ".$action." was called by a function that did not set previously the property ->oldcopy onto object", LOG_WARNING); |
|
147 | + $object->oldcopy = clone $object; |
|
148 | + } |
|
149 | + |
|
150 | + $oldinfo=$object->oldcopy->_load_ldap_info(); |
|
151 | + $olddn=$object->oldcopy->_load_ldap_dn($oldinfo); |
|
152 | + |
|
153 | + // Verify if entry exist |
|
154 | + $container=$object->oldcopy->_load_ldap_dn($oldinfo,1); |
|
155 | + $search = "(".$object->oldcopy->_load_ldap_dn($oldinfo,2).")"; |
|
156 | + $records=$ldap->search($container,$search); |
|
157 | + if (count($records) && $records['count'] == 0) |
|
158 | + { |
|
159 | + $olddn = ''; |
|
160 | + } |
|
161 | + |
|
162 | + $info=$object->_load_ldap_info(); |
|
163 | + $dn=$object->_load_ldap_dn($info); |
|
164 | + |
|
165 | + $result=$ldap->update($dn,$info,$user,$olddn); |
|
166 | + } |
|
167 | + |
|
168 | + if ($result < 0) $this->error="ErrorLDAP ".$ldap->error; |
|
169 | + } |
|
170 | + } |
|
171 | + elseif ($action == 'USER_ENABLEDISABLE') |
|
172 | + { |
|
173 | + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
174 | + } |
|
175 | + elseif ($action == 'USER_DELETE') |
|
176 | + { |
|
177 | + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
178 | + if (! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') |
|
179 | + { |
|
180 | + $ldap=new Ldap(); |
|
181 | + $result=$ldap->connect_bind(); |
|
182 | + |
|
183 | + if ($result > 0) |
|
184 | + { |
|
185 | + $info=$object->_load_ldap_info(); |
|
186 | + $dn=$object->_load_ldap_dn($info); |
|
187 | + |
|
188 | + $result=$ldap->delete($dn); |
|
189 | + } |
|
190 | + |
|
191 | + if ($result < 0) $this->error="ErrorLDAP ".$ldap->error; |
|
192 | + } |
|
193 | + } |
|
194 | + elseif ($action == 'USER_SETINGROUP') |
|
195 | + { |
|
196 | + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
197 | + if (! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') |
|
198 | + { |
|
199 | + $ldap=new Ldap(); |
|
200 | + $result=$ldap->connect_bind(); |
|
201 | + |
|
202 | + if ($result > 0) |
|
203 | + { |
|
204 | + // Must edit $object->newgroupid |
|
205 | + $usergroup=new UserGroup($this->db); |
|
206 | + if ($object->newgroupid > 0) |
|
207 | + { |
|
208 | + $usergroup->fetch($object->newgroupid); |
|
209 | + |
|
210 | + $oldinfo=$usergroup->_load_ldap_info(); |
|
211 | + $olddn=$usergroup->_load_ldap_dn($oldinfo); |
|
212 | + |
|
213 | + // Verify if entry exist |
|
214 | + $container=$usergroup->_load_ldap_dn($oldinfo,1); |
|
215 | + $search = "(".$usergroup->_load_ldap_dn($oldinfo,2).")"; |
|
216 | + $records=$ldap->search($container,$search); |
|
217 | + if (count($records) && $records['count'] == 0) |
|
218 | + { |
|
219 | + $olddn = ''; |
|
220 | + } |
|
221 | + |
|
222 | + $info=$usergroup->_load_ldap_info(); // Contains all members, included the new one (insert already done before trigger call) |
|
223 | + $dn=$usergroup->_load_ldap_dn($info); |
|
224 | + |
|
225 | + $result=$ldap->update($dn,$info,$user,$olddn); |
|
226 | + } |
|
227 | + } |
|
228 | + |
|
229 | + if ($result < 0) $this->error="ErrorLDAP ".$ldap->error; |
|
230 | + } |
|
231 | + } |
|
232 | + elseif ($action == 'USER_REMOVEFROMGROUP') |
|
233 | + { |
|
234 | + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
235 | + if (! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') |
|
236 | + { |
|
237 | + $ldap=new Ldap(); |
|
238 | + $result=$ldap->connect_bind(); |
|
239 | + |
|
240 | + if ($result > 0) |
|
241 | + { |
|
242 | + // Must edit $object->newgroupid |
|
243 | + $usergroup=new UserGroup($this->db); |
|
244 | + if ($object->oldgroupid > 0) |
|
245 | + { |
|
246 | + $usergroup->fetch($object->oldgroupid); |
|
247 | + |
|
248 | + $oldinfo=$usergroup->_load_ldap_info(); |
|
249 | + $olddn=$usergroup->_load_ldap_dn($oldinfo); |
|
250 | + |
|
251 | + // Verify if entry exist |
|
252 | + $container=$usergroup->_load_ldap_dn($oldinfo,1); |
|
253 | + $search = "(".$usergroup->_load_ldap_dn($oldinfo,2).")"; |
|
254 | + $records=$ldap->search($container,$search); |
|
255 | + if (count($records) && $records['count'] == 0) |
|
256 | + { |
|
257 | + $olddn = ''; |
|
258 | + } |
|
259 | + |
|
260 | + $info=$usergroup->_load_ldap_info(); // Contains all members, included the new one (insert already done before trigger call) |
|
261 | + $dn=$usergroup->_load_ldap_dn($info); |
|
262 | + |
|
263 | + $result=$ldap->update($dn,$info,$user,$olddn); |
|
264 | + } |
|
265 | + } |
|
266 | + |
|
267 | + if ($result < 0) $this->error="ErrorLDAP ".$ldap->error; |
|
268 | + } |
|
269 | + } |
|
270 | + |
|
271 | + // Groupes |
|
272 | + elseif ($action == 'GROUP_CREATE') |
|
273 | + { |
|
274 | + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
275 | + if (! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') |
|
276 | + { |
|
277 | + $ldap=new Ldap(); |
|
278 | + $result=$ldap->connect_bind(); |
|
279 | + |
|
280 | + if ($result > 0) |
|
281 | + { |
|
282 | + $info=$object->_load_ldap_info(); |
|
283 | + $dn=$object->_load_ldap_dn($info); |
|
284 | + |
|
285 | + // Get a gid number for objectclass PosixGroup |
|
286 | + if (in_array('posixGroup',$info['objectclass'])) { |
|
287 | + $info['gidNumber'] = $ldap->getNextGroupGid('LDAP_KEY_GROUPS'); |
|
288 | + } |
|
289 | + |
|
290 | + $result=$ldap->add($dn,$info,$user); |
|
291 | + } |
|
292 | + |
|
293 | + if ($result < 0) $this->error="ErrorLDAP ".$ldap->error; |
|
294 | + } |
|
295 | + } |
|
296 | + elseif ($action == 'GROUP_MODIFY') |
|
297 | + { |
|
298 | + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
299 | + if (! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') |
|
300 | + { |
|
301 | + $ldap=new Ldap(); |
|
302 | + $result=$ldap->connect_bind(); |
|
303 | + |
|
304 | + if ($result > 0) |
|
305 | + { |
|
306 | + if (empty($object->oldcopy) || ! is_object($object->oldcopy)) |
|
307 | + { |
|
308 | + dol_syslog("Trigger ".$action." was called by a function that did not set previously the property ->oldcopy onto object", LOG_WARNING); |
|
309 | + $object->oldcopy = clone $object; |
|
310 | + } |
|
311 | + |
|
312 | + $oldinfo=$object->oldcopy->_load_ldap_info(); |
|
313 | + $olddn=$object->oldcopy->_load_ldap_dn($oldinfo); |
|
314 | + |
|
315 | + // Verify if entry exist |
|
316 | + $container=$object->oldcopy->_load_ldap_dn($oldinfo,1); |
|
317 | + $search = "(".$object->oldcopy->_load_ldap_dn($oldinfo,2).")"; |
|
318 | + $records=$ldap->search($container,$search); |
|
319 | + if (count($records) && $records['count'] == 0) |
|
320 | + { |
|
321 | + $olddn = ''; |
|
322 | + } |
|
323 | + |
|
324 | + $info=$object->_load_ldap_info(); |
|
325 | + $dn=$object->_load_ldap_dn($info); |
|
326 | + |
|
327 | + $result=$ldap->update($dn,$info,$user,$olddn); |
|
328 | + } |
|
329 | + |
|
330 | + if ($result < 0) $this->error="ErrorLDAP ".$ldap->error; |
|
331 | + } |
|
332 | + } |
|
333 | + elseif ($action == 'GROUP_DELETE') |
|
334 | + { |
|
335 | + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
336 | + if (! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') |
|
337 | + { |
|
338 | + $ldap=new Ldap(); |
|
339 | + $result=$ldap->connect_bind(); |
|
340 | + |
|
341 | + if ($result > 0) |
|
342 | + { |
|
343 | + $info=$object->_load_ldap_info(); |
|
344 | + $dn=$object->_load_ldap_dn($info); |
|
345 | + |
|
346 | + $result=$ldap->delete($dn); |
|
347 | + } |
|
348 | + |
|
349 | + if ($result < 0) $this->error="ErrorLDAP ".$ldap->error; |
|
350 | + } |
|
351 | + } |
|
352 | + |
|
353 | + // Contacts |
|
354 | + elseif ($action == 'CONTACT_CREATE') |
|
355 | + { |
|
356 | + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
357 | + if (! empty($conf->global->LDAP_CONTACT_ACTIVE)) |
|
358 | + { |
|
359 | + $ldap=new Ldap(); |
|
360 | + $result=$ldap->connect_bind(); |
|
361 | + |
|
362 | + if ($result > 0) |
|
363 | + { |
|
364 | + $info=$object->_load_ldap_info(); |
|
365 | + $dn=$object->_load_ldap_dn($info); |
|
366 | + |
|
367 | + $result=$ldap->add($dn,$info,$user); |
|
368 | + } |
|
369 | + |
|
370 | + if ($result < 0) $this->error="ErrorLDAP ".$ldap->error; |
|
371 | + } |
|
372 | + } |
|
373 | + elseif ($action == 'CONTACT_MODIFY') |
|
374 | + { |
|
375 | + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
376 | + if (! empty($conf->global->LDAP_CONTACT_ACTIVE)) |
|
377 | + { |
|
378 | + $ldap=new Ldap(); |
|
379 | + $result=$ldap->connect_bind(); |
|
380 | + |
|
381 | + if ($result > 0) |
|
382 | + { |
|
383 | + if (empty($object->oldcopy) || ! is_object($object->oldcopy)) |
|
384 | + { |
|
385 | + dol_syslog("Trigger ".$action." was called by a function that did not set previously the property ->oldcopy onto object", LOG_WARNING); |
|
386 | + $object->oldcopy = clone $object; |
|
387 | + } |
|
388 | + |
|
389 | + $oldinfo=$object->oldcopy->_load_ldap_info(); |
|
390 | + $olddn=$object->oldcopy->_load_ldap_dn($oldinfo); |
|
391 | + |
|
392 | + // Verify if entry exist |
|
393 | + $container=$object->oldcopy->_load_ldap_dn($oldinfo,1); |
|
394 | + $search = "(".$object->oldcopy->_load_ldap_dn($oldinfo,2).")"; |
|
395 | + $records=$ldap->search($container,$search); |
|
396 | + if (count($records) && $records['count'] == 0) |
|
397 | + { |
|
398 | + $olddn = ''; |
|
399 | + } |
|
400 | + |
|
401 | + $info=$object->_load_ldap_info(); |
|
402 | + $dn=$object->_load_ldap_dn($info); |
|
403 | + |
|
404 | + $result=$ldap->update($dn,$info,$user,$olddn); |
|
405 | + } |
|
406 | + |
|
407 | + if ($result < 0) $this->error="ErrorLDAP ".$ldap->error; |
|
408 | + } |
|
409 | + } |
|
410 | + elseif ($action == 'CONTACT_DELETE') |
|
411 | + { |
|
412 | + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
413 | + if (! empty($conf->global->LDAP_CONTACT_ACTIVE)) |
|
414 | + { |
|
415 | + $ldap=new Ldap(); |
|
416 | + $result=$ldap->connect_bind(); |
|
417 | + |
|
418 | + if ($result > 0) |
|
419 | + { |
|
420 | + $info=$object->_load_ldap_info(); |
|
421 | + $dn=$object->_load_ldap_dn($info); |
|
422 | + |
|
423 | + $result=$ldap->delete($dn); |
|
424 | + } |
|
425 | + |
|
426 | + if ($result < 0) $this->error="ErrorLDAP ".$ldap->error; |
|
427 | + } |
|
428 | + } |
|
429 | + |
|
430 | + // Members |
|
431 | + elseif ($action == 'MEMBER_CREATE') |
|
432 | + { |
|
433 | + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
434 | + if (! empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1') |
|
435 | + { |
|
436 | + $ldap=new Ldap(); |
|
437 | + $result=$ldap->connect_bind(); |
|
438 | + |
|
439 | + if ($result > 0) |
|
440 | + { |
|
441 | + $info=$object->_load_ldap_info(); |
|
442 | + $dn=$object->_load_ldap_dn($info); |
|
443 | + |
|
444 | + $result=$ldap->add($dn,$info,$user); |
|
445 | + |
|
446 | + // For member type |
|
447 | + if (! empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1') |
|
448 | + { |
|
449 | + $membertype=new AdherentType($this->db); |
|
450 | + if ($object->typeid > 0) |
|
451 | + { |
|
452 | + $membertype->fetch($object->typeid); |
|
453 | + $membertype->listMembersForMemberType('', 1); |
|
454 | + |
|
455 | + $oldinfo=$membertype->_load_ldap_info(); |
|
456 | + $olddn=$membertype->_load_ldap_dn($oldinfo); |
|
457 | + |
|
458 | + // Verify if entry exist |
|
459 | + $container=$membertype->_load_ldap_dn($oldinfo,1); |
|
460 | + $search = "(".$membertype->_load_ldap_dn($oldinfo,2).")"; |
|
461 | + $records=$ldap->search($container,$search); |
|
462 | + if (count($records) && $records['count'] == 0) |
|
463 | + { |
|
464 | + $olddn = ''; |
|
465 | + } |
|
466 | + |
|
467 | + $info=$membertype->_load_ldap_info(); // Contains all members, included the new one (insert already done before trigger call) |
|
468 | + $dn=$membertype->_load_ldap_dn($info); |
|
469 | + |
|
470 | + $result=$ldap->update($dn,$info,$user,$olddn); |
|
471 | + } |
|
472 | + } |
|
473 | + } |
|
474 | + |
|
475 | + if ($result < 0) $this->error="ErrorLDAP ".$ldap->error; |
|
476 | + } |
|
477 | + } |
|
478 | + elseif ($action == 'MEMBER_VALIDATE') |
|
479 | + { |
|
480 | + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
481 | + if (! empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1') |
|
482 | + { |
|
483 | + // If status field is setup to be synchronized |
|
484 | + if (! empty($conf->global->LDAP_FIELD_MEMBER_STATUS)) |
|
485 | + { |
|
486 | + $ldap=new Ldap(); |
|
487 | + $result=$ldap->connect_bind(); |
|
488 | + |
|
489 | + if ($result > 0) |
|
490 | + { |
|
491 | + $info=$object->_load_ldap_info(); |
|
492 | + $dn=$object->_load_ldap_dn($info); |
|
493 | + $olddn=$dn; // We know olddn=dn as we change only status |
|
494 | + |
|
495 | + $result=$ldap->update($dn,$info,$user,$olddn); |
|
496 | + } |
|
497 | + |
|
498 | + if ($result < 0) $this->error="ErrorLDAP ".$ldap->error; |
|
499 | + } |
|
500 | + } |
|
501 | + } |
|
502 | + elseif ($action == 'MEMBER_SUBSCRIPTION') |
|
503 | + { |
|
504 | + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
505 | + if (! empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1') |
|
506 | + { |
|
507 | + // If subscriptions fields are setup to be synchronized |
|
508 | + if ($conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE |
|
509 | + || $conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT |
|
510 | + || $conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE |
|
511 | + || $conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT |
|
512 | + || $conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION) |
|
513 | + { |
|
514 | + $ldap=new Ldap(); |
|
515 | + $result=$ldap->connect_bind(); |
|
516 | + |
|
517 | + if ($result > 0) |
|
518 | + { |
|
519 | + $info=$object->_load_ldap_info(); |
|
520 | + $dn=$object->_load_ldap_dn($info); |
|
521 | + $olddn=$dn; // We know olddn=dn as we change only subscriptions |
|
522 | + |
|
523 | + $result=$ldap->update($dn,$info,$user,$olddn); |
|
524 | + } |
|
525 | + |
|
526 | + if ($result < 0) $this->error="ErrorLDAP ".$ldap->error; |
|
527 | + } |
|
528 | + } |
|
529 | + } |
|
530 | + elseif ($action == 'MEMBER_MODIFY') |
|
531 | + { |
|
532 | + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
533 | + if (! empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1') |
|
534 | + { |
|
535 | + $ldap=new Ldap(); |
|
536 | + $result=$ldap->connect_bind(); |
|
537 | + |
|
538 | + if ($result > 0) |
|
539 | + { |
|
540 | + if (empty($object->oldcopy) || ! is_object($object->oldcopy)) |
|
541 | + { |
|
542 | + dol_syslog("Trigger ".$action." was called by a function that did not set previously the property ->oldcopy onto object", LOG_WARNING); |
|
543 | + $object->oldcopy = clone $object; |
|
544 | + } |
|
545 | + |
|
546 | + $oldinfo=$object->oldcopy->_load_ldap_info(); |
|
547 | + $olddn=$object->oldcopy->_load_ldap_dn($oldinfo); |
|
548 | + |
|
549 | + // Verify if entry exist |
|
550 | + $container=$object->oldcopy->_load_ldap_dn($oldinfo,1); |
|
551 | + $search = "(".$object->oldcopy->_load_ldap_dn($oldinfo,2).")"; |
|
552 | + $records=$ldap->search($container,$search); |
|
553 | + if (count($records) && $records['count'] == 0) |
|
554 | + { |
|
555 | + $olddn = ''; |
|
556 | + } |
|
557 | + |
|
558 | + $info=$object->_load_ldap_info(); |
|
559 | + $dn=$object->_load_ldap_dn($info); |
|
560 | + $newrdn=$object->_load_ldap_dn($info,2); |
|
561 | + $newparent=$object->_load_ldap_dn($info,1); |
|
562 | + |
|
563 | + $result=$ldap->update($dn,$info,$user,$olddn,$newrdn,$newparent); |
|
564 | + |
|
565 | + // For member type |
|
566 | + if (! empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1') |
|
567 | + { |
|
568 | + /* |
|
569 | 569 | * Change member info |
570 | 570 | */ |
571 | - $newmembertype=new AdherentType($this->db); |
|
572 | - $newmembertype->fetch($object->typeid); |
|
573 | - $newmembertype->listMembersForMemberType('', 1); |
|
574 | - |
|
575 | - $oldinfo=$newmembertype->_load_ldap_info(); |
|
576 | - $olddn=$newmembertype->_load_ldap_dn($oldinfo); |
|
577 | - |
|
578 | - // Verify if entry exist |
|
579 | - $container=$newmembertype->_load_ldap_dn($oldinfo,1); |
|
580 | - $search = "(".$newmembertype->_load_ldap_dn($oldinfo,2).")"; |
|
581 | - $records=$ldap->search($container,$search); |
|
582 | - if (count($records) && $records['count'] == 0) |
|
583 | - { |
|
584 | - $olddn = ''; |
|
585 | - } |
|
586 | - |
|
587 | - $info=$newmembertype->_load_ldap_info(); // Contains all members, included the new one (insert already done before trigger call) |
|
588 | - $dn=$newmembertype->_load_ldap_dn($info); |
|
589 | - |
|
590 | - $result=$ldap->update($dn,$info,$user,$olddn); |
|
591 | - |
|
592 | - if ($object->oldcopy->typeid != $object->typeid) |
|
593 | - { |
|
594 | - /* |
|
571 | + $newmembertype=new AdherentType($this->db); |
|
572 | + $newmembertype->fetch($object->typeid); |
|
573 | + $newmembertype->listMembersForMemberType('', 1); |
|
574 | + |
|
575 | + $oldinfo=$newmembertype->_load_ldap_info(); |
|
576 | + $olddn=$newmembertype->_load_ldap_dn($oldinfo); |
|
577 | + |
|
578 | + // Verify if entry exist |
|
579 | + $container=$newmembertype->_load_ldap_dn($oldinfo,1); |
|
580 | + $search = "(".$newmembertype->_load_ldap_dn($oldinfo,2).")"; |
|
581 | + $records=$ldap->search($container,$search); |
|
582 | + if (count($records) && $records['count'] == 0) |
|
583 | + { |
|
584 | + $olddn = ''; |
|
585 | + } |
|
586 | + |
|
587 | + $info=$newmembertype->_load_ldap_info(); // Contains all members, included the new one (insert already done before trigger call) |
|
588 | + $dn=$newmembertype->_load_ldap_dn($info); |
|
589 | + |
|
590 | + $result=$ldap->update($dn,$info,$user,$olddn); |
|
591 | + |
|
592 | + if ($object->oldcopy->typeid != $object->typeid) |
|
593 | + { |
|
594 | + /* |
|
595 | 595 | * Remove member in old member type |
596 | 596 | */ |
597 | - $oldmembertype=new AdherentType($this->db); |
|
598 | - $oldmembertype->fetch($object->oldcopy->typeid); |
|
599 | - $oldmembertype->listMembersForMemberType('', 1); |
|
600 | - |
|
601 | - $oldinfo=$oldmembertype->_load_ldap_info(); |
|
602 | - $olddn=$oldmembertype->_load_ldap_dn($oldinfo); |
|
603 | - |
|
604 | - // Verify if entry exist |
|
605 | - $container=$oldmembertype->_load_ldap_dn($oldinfo,1); |
|
606 | - $search = "(".$oldmembertype->_load_ldap_dn($oldinfo,2).")"; |
|
607 | - $records=$ldap->search($container,$search); |
|
608 | - if (count($records) && $records['count'] == 0) |
|
609 | - { |
|
610 | - $olddn = ''; |
|
611 | - } |
|
612 | - |
|
613 | - $info=$oldmembertype->_load_ldap_info(); // Contains all members, included the new one (insert already done before trigger call) |
|
614 | - $dn=$oldmembertype->_load_ldap_dn($info); |
|
615 | - |
|
616 | - $result=$ldap->update($dn,$info,$user,$olddn); |
|
617 | - } |
|
618 | - } |
|
619 | - } |
|
620 | - |
|
621 | - if ($result < 0) $this->error="ErrorLDAP ".$ldap->error; |
|
622 | - } |
|
623 | - } |
|
624 | - elseif ($action == 'MEMBER_NEW_PASSWORD') |
|
625 | - { |
|
626 | - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
627 | - if (! empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1') |
|
628 | - { |
|
629 | - // If password field is setup to be synchronized |
|
630 | - if ($conf->global->LDAP_FIELD_PASSWORD || $conf->global->LDAP_FIELD_PASSWORD_CRYPTED) |
|
631 | - { |
|
632 | - $ldap=new Ldap(); |
|
633 | - $result=$ldap->connect_bind(); |
|
634 | - |
|
635 | - if ($result > 0) |
|
636 | - { |
|
637 | - $info=$object->_load_ldap_info(); |
|
638 | - $dn=$object->_load_ldap_dn($info); |
|
639 | - $olddn=$dn; // We know olddn=dn as we change only password |
|
640 | - |
|
641 | - $result=$ldap->update($dn,$info,$user,$olddn); |
|
642 | - } |
|
643 | - |
|
644 | - if ($result < 0) $this->error="ErrorLDAP ".$ldap->error; |
|
645 | - } |
|
646 | - } |
|
647 | - } |
|
648 | - elseif ($action == 'MEMBER_RESILIATE') |
|
649 | - { |
|
650 | - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
651 | - if (! empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1') |
|
652 | - { |
|
653 | - // If status field is setup to be synchronized |
|
654 | - if (! empty($conf->global->LDAP_FIELD_MEMBER_STATUS)) |
|
655 | - { |
|
656 | - $ldap=new Ldap(); |
|
657 | - $result=$ldap->connect_bind(); |
|
658 | - |
|
659 | - if ($result > 0) |
|
660 | - { |
|
661 | - $info=$object->_load_ldap_info(); |
|
662 | - $dn=$object->_load_ldap_dn($info); |
|
663 | - $olddn=$dn; // We know olddn=dn as we change only status |
|
664 | - |
|
665 | - $result=$ldap->update($dn,$info,$user,$olddn); |
|
666 | - } |
|
667 | - |
|
668 | - if ($result < 0) $this->error="ErrorLDAP ".$ldap->error; |
|
669 | - } |
|
670 | - } |
|
671 | - } |
|
672 | - elseif ($action == 'MEMBER_DELETE') |
|
673 | - { |
|
674 | - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
675 | - if (! empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1') |
|
676 | - { |
|
677 | - $ldap=new Ldap(); |
|
678 | - $result=$ldap->connect_bind(); |
|
679 | - |
|
680 | - if ($result > 0) |
|
681 | - { |
|
682 | - $info=$object->_load_ldap_info(); |
|
683 | - $dn=$object->_load_ldap_dn($info); |
|
684 | - |
|
685 | - $result=$ldap->delete($dn); |
|
686 | - |
|
687 | - // For member type |
|
688 | - if (! empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1') |
|
689 | - { |
|
690 | - if ($object->typeid > 0) |
|
691 | - { |
|
692 | - /* |
|
597 | + $oldmembertype=new AdherentType($this->db); |
|
598 | + $oldmembertype->fetch($object->oldcopy->typeid); |
|
599 | + $oldmembertype->listMembersForMemberType('', 1); |
|
600 | + |
|
601 | + $oldinfo=$oldmembertype->_load_ldap_info(); |
|
602 | + $olddn=$oldmembertype->_load_ldap_dn($oldinfo); |
|
603 | + |
|
604 | + // Verify if entry exist |
|
605 | + $container=$oldmembertype->_load_ldap_dn($oldinfo,1); |
|
606 | + $search = "(".$oldmembertype->_load_ldap_dn($oldinfo,2).")"; |
|
607 | + $records=$ldap->search($container,$search); |
|
608 | + if (count($records) && $records['count'] == 0) |
|
609 | + { |
|
610 | + $olddn = ''; |
|
611 | + } |
|
612 | + |
|
613 | + $info=$oldmembertype->_load_ldap_info(); // Contains all members, included the new one (insert already done before trigger call) |
|
614 | + $dn=$oldmembertype->_load_ldap_dn($info); |
|
615 | + |
|
616 | + $result=$ldap->update($dn,$info,$user,$olddn); |
|
617 | + } |
|
618 | + } |
|
619 | + } |
|
620 | + |
|
621 | + if ($result < 0) $this->error="ErrorLDAP ".$ldap->error; |
|
622 | + } |
|
623 | + } |
|
624 | + elseif ($action == 'MEMBER_NEW_PASSWORD') |
|
625 | + { |
|
626 | + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
627 | + if (! empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1') |
|
628 | + { |
|
629 | + // If password field is setup to be synchronized |
|
630 | + if ($conf->global->LDAP_FIELD_PASSWORD || $conf->global->LDAP_FIELD_PASSWORD_CRYPTED) |
|
631 | + { |
|
632 | + $ldap=new Ldap(); |
|
633 | + $result=$ldap->connect_bind(); |
|
634 | + |
|
635 | + if ($result > 0) |
|
636 | + { |
|
637 | + $info=$object->_load_ldap_info(); |
|
638 | + $dn=$object->_load_ldap_dn($info); |
|
639 | + $olddn=$dn; // We know olddn=dn as we change only password |
|
640 | + |
|
641 | + $result=$ldap->update($dn,$info,$user,$olddn); |
|
642 | + } |
|
643 | + |
|
644 | + if ($result < 0) $this->error="ErrorLDAP ".$ldap->error; |
|
645 | + } |
|
646 | + } |
|
647 | + } |
|
648 | + elseif ($action == 'MEMBER_RESILIATE') |
|
649 | + { |
|
650 | + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
651 | + if (! empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1') |
|
652 | + { |
|
653 | + // If status field is setup to be synchronized |
|
654 | + if (! empty($conf->global->LDAP_FIELD_MEMBER_STATUS)) |
|
655 | + { |
|
656 | + $ldap=new Ldap(); |
|
657 | + $result=$ldap->connect_bind(); |
|
658 | + |
|
659 | + if ($result > 0) |
|
660 | + { |
|
661 | + $info=$object->_load_ldap_info(); |
|
662 | + $dn=$object->_load_ldap_dn($info); |
|
663 | + $olddn=$dn; // We know olddn=dn as we change only status |
|
664 | + |
|
665 | + $result=$ldap->update($dn,$info,$user,$olddn); |
|
666 | + } |
|
667 | + |
|
668 | + if ($result < 0) $this->error="ErrorLDAP ".$ldap->error; |
|
669 | + } |
|
670 | + } |
|
671 | + } |
|
672 | + elseif ($action == 'MEMBER_DELETE') |
|
673 | + { |
|
674 | + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
675 | + if (! empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1') |
|
676 | + { |
|
677 | + $ldap=new Ldap(); |
|
678 | + $result=$ldap->connect_bind(); |
|
679 | + |
|
680 | + if ($result > 0) |
|
681 | + { |
|
682 | + $info=$object->_load_ldap_info(); |
|
683 | + $dn=$object->_load_ldap_dn($info); |
|
684 | + |
|
685 | + $result=$ldap->delete($dn); |
|
686 | + |
|
687 | + // For member type |
|
688 | + if (! empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1') |
|
689 | + { |
|
690 | + if ($object->typeid > 0) |
|
691 | + { |
|
692 | + /* |
|
693 | 693 | * Remove member in member type |
694 | 694 | */ |
695 | - $membertype=new AdherentType($this->db); |
|
696 | - $membertype->fetch($object->typeid); |
|
697 | - $membertype->listMembersForMemberType('a.rowid != ' . $object->id, 1); // remove deleted member from the list |
|
698 | - |
|
699 | - $oldinfo=$membertype->_load_ldap_info(); |
|
700 | - $olddn=$membertype->_load_ldap_dn($oldinfo); |
|
701 | - |
|
702 | - // Verify if entry exist |
|
703 | - $container=$membertype->_load_ldap_dn($oldinfo,1); |
|
704 | - $search = "(".$membertype->_load_ldap_dn($oldinfo,2).")"; |
|
705 | - $records=$ldap->search($container,$search); |
|
706 | - if (count($records) && $records['count'] == 0) |
|
707 | - { |
|
708 | - $olddn = ''; |
|
709 | - } |
|
710 | - |
|
711 | - $info=$membertype->_load_ldap_info(); // Contains all members, included the new one (insert already done before trigger call) |
|
712 | - $dn=$membertype->_load_ldap_dn($info); |
|
713 | - |
|
714 | - $result=$ldap->update($dn,$info,$user,$olddn); |
|
715 | - } |
|
716 | - } |
|
717 | - } |
|
718 | - |
|
719 | - if ($result < 0) $this->error="ErrorLDAP ".$ldap->error; |
|
720 | - } |
|
721 | - } |
|
722 | - |
|
723 | - // Members types |
|
724 | - elseif ($action == 'MEMBER_TYPE_CREATE') |
|
725 | - { |
|
726 | - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
727 | - if (! empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1') |
|
728 | - { |
|
729 | - $ldap=new Ldap(); |
|
730 | - $result=$ldap->connect_bind(); |
|
731 | - |
|
732 | - if ($result > 0) |
|
733 | - { |
|
734 | - $info=$object->_load_ldap_info(); |
|
735 | - $dn=$object->_load_ldap_dn($info); |
|
736 | - |
|
737 | - // Get a gid number for objectclass PosixGroup |
|
738 | - if (in_array('posixGroup',$info['objectclass'])) { |
|
739 | - $info['gidNumber'] = $ldap->getNextGroupGid('LDAP_KEY_MEMBERS_TYPE'); |
|
740 | - } |
|
741 | - |
|
742 | - $result=$ldap->add($dn,$info,$user); |
|
743 | - } |
|
744 | - |
|
745 | - if ($result < 0) $this->error="ErrorLDAP ".$ldap->error; |
|
746 | - } |
|
747 | - } |
|
748 | - elseif ($action == 'MEMBER_TYPE_MODIFY') |
|
749 | - { |
|
750 | - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
751 | - if (! empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1') |
|
752 | - { |
|
753 | - $ldap=new Ldap(); |
|
754 | - $result=$ldap->connect_bind(); |
|
755 | - |
|
756 | - if ($result > 0) |
|
757 | - { |
|
758 | - if (empty($object->oldcopy) || ! is_object($object->oldcopy)) |
|
759 | - { |
|
760 | - dol_syslog("Trigger ".$action." was called by a function that did not set previously the property ->oldcopy onto object", LOG_WARNING); |
|
761 | - $object->oldcopy = clone $object; |
|
762 | - } |
|
763 | - |
|
764 | - $object->oldcopy->listMembersForMemberType('', 1); |
|
765 | - |
|
766 | - $oldinfo=$object->oldcopy->_load_ldap_info(); |
|
767 | - $olddn=$object->oldcopy->_load_ldap_dn($oldinfo); |
|
768 | - |
|
769 | - // Verify if entry exist |
|
770 | - $container=$object->oldcopy->_load_ldap_dn($oldinfo,1); |
|
771 | - $search = "(".$object->oldcopy->_load_ldap_dn($oldinfo,2).")"; |
|
772 | - $records=$ldap->search($container,$search); |
|
773 | - if (count($records) && $records['count'] == 0) |
|
774 | - { |
|
775 | - $olddn = ''; |
|
776 | - } |
|
777 | - |
|
778 | - $object->listMembersForMemberType('', 1); |
|
779 | - |
|
780 | - $info=$object->_load_ldap_info(); |
|
781 | - $dn=$object->_load_ldap_dn($info); |
|
782 | - |
|
783 | - $result=$ldap->update($dn,$info,$user,$olddn); |
|
784 | - } |
|
785 | - |
|
786 | - if ($result < 0) $this->error="ErrorLDAP ".$ldap->error; |
|
787 | - } |
|
788 | - } |
|
789 | - elseif ($action == 'MEMBER_TYPE_DELETE') |
|
790 | - { |
|
791 | - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
792 | - if (! empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1') |
|
793 | - { |
|
794 | - $ldap=new Ldap(); |
|
795 | - $result=$ldap->connect_bind(); |
|
796 | - |
|
797 | - if ($result > 0) |
|
798 | - { |
|
799 | - $info=$object->_load_ldap_info(); |
|
800 | - $dn=$object->_load_ldap_dn($info); |
|
801 | - |
|
802 | - $result=$ldap->delete($dn); |
|
803 | - } |
|
804 | - |
|
805 | - if ($result < 0) $this->error="ErrorLDAP ".$ldap->error; |
|
806 | - } |
|
807 | - } |
|
808 | - |
|
809 | - return $result; |
|
810 | - } |
|
695 | + $membertype=new AdherentType($this->db); |
|
696 | + $membertype->fetch($object->typeid); |
|
697 | + $membertype->listMembersForMemberType('a.rowid != ' . $object->id, 1); // remove deleted member from the list |
|
698 | + |
|
699 | + $oldinfo=$membertype->_load_ldap_info(); |
|
700 | + $olddn=$membertype->_load_ldap_dn($oldinfo); |
|
701 | + |
|
702 | + // Verify if entry exist |
|
703 | + $container=$membertype->_load_ldap_dn($oldinfo,1); |
|
704 | + $search = "(".$membertype->_load_ldap_dn($oldinfo,2).")"; |
|
705 | + $records=$ldap->search($container,$search); |
|
706 | + if (count($records) && $records['count'] == 0) |
|
707 | + { |
|
708 | + $olddn = ''; |
|
709 | + } |
|
710 | + |
|
711 | + $info=$membertype->_load_ldap_info(); // Contains all members, included the new one (insert already done before trigger call) |
|
712 | + $dn=$membertype->_load_ldap_dn($info); |
|
713 | + |
|
714 | + $result=$ldap->update($dn,$info,$user,$olddn); |
|
715 | + } |
|
716 | + } |
|
717 | + } |
|
718 | + |
|
719 | + if ($result < 0) $this->error="ErrorLDAP ".$ldap->error; |
|
720 | + } |
|
721 | + } |
|
722 | + |
|
723 | + // Members types |
|
724 | + elseif ($action == 'MEMBER_TYPE_CREATE') |
|
725 | + { |
|
726 | + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
727 | + if (! empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1') |
|
728 | + { |
|
729 | + $ldap=new Ldap(); |
|
730 | + $result=$ldap->connect_bind(); |
|
731 | + |
|
732 | + if ($result > 0) |
|
733 | + { |
|
734 | + $info=$object->_load_ldap_info(); |
|
735 | + $dn=$object->_load_ldap_dn($info); |
|
736 | + |
|
737 | + // Get a gid number for objectclass PosixGroup |
|
738 | + if (in_array('posixGroup',$info['objectclass'])) { |
|
739 | + $info['gidNumber'] = $ldap->getNextGroupGid('LDAP_KEY_MEMBERS_TYPE'); |
|
740 | + } |
|
741 | + |
|
742 | + $result=$ldap->add($dn,$info,$user); |
|
743 | + } |
|
744 | + |
|
745 | + if ($result < 0) $this->error="ErrorLDAP ".$ldap->error; |
|
746 | + } |
|
747 | + } |
|
748 | + elseif ($action == 'MEMBER_TYPE_MODIFY') |
|
749 | + { |
|
750 | + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
751 | + if (! empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1') |
|
752 | + { |
|
753 | + $ldap=new Ldap(); |
|
754 | + $result=$ldap->connect_bind(); |
|
755 | + |
|
756 | + if ($result > 0) |
|
757 | + { |
|
758 | + if (empty($object->oldcopy) || ! is_object($object->oldcopy)) |
|
759 | + { |
|
760 | + dol_syslog("Trigger ".$action." was called by a function that did not set previously the property ->oldcopy onto object", LOG_WARNING); |
|
761 | + $object->oldcopy = clone $object; |
|
762 | + } |
|
763 | + |
|
764 | + $object->oldcopy->listMembersForMemberType('', 1); |
|
765 | + |
|
766 | + $oldinfo=$object->oldcopy->_load_ldap_info(); |
|
767 | + $olddn=$object->oldcopy->_load_ldap_dn($oldinfo); |
|
768 | + |
|
769 | + // Verify if entry exist |
|
770 | + $container=$object->oldcopy->_load_ldap_dn($oldinfo,1); |
|
771 | + $search = "(".$object->oldcopy->_load_ldap_dn($oldinfo,2).")"; |
|
772 | + $records=$ldap->search($container,$search); |
|
773 | + if (count($records) && $records['count'] == 0) |
|
774 | + { |
|
775 | + $olddn = ''; |
|
776 | + } |
|
777 | + |
|
778 | + $object->listMembersForMemberType('', 1); |
|
779 | + |
|
780 | + $info=$object->_load_ldap_info(); |
|
781 | + $dn=$object->_load_ldap_dn($info); |
|
782 | + |
|
783 | + $result=$ldap->update($dn,$info,$user,$olddn); |
|
784 | + } |
|
785 | + |
|
786 | + if ($result < 0) $this->error="ErrorLDAP ".$ldap->error; |
|
787 | + } |
|
788 | + } |
|
789 | + elseif ($action == 'MEMBER_TYPE_DELETE') |
|
790 | + { |
|
791 | + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
792 | + if (! empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1') |
|
793 | + { |
|
794 | + $ldap=new Ldap(); |
|
795 | + $result=$ldap->connect_bind(); |
|
796 | + |
|
797 | + if ($result > 0) |
|
798 | + { |
|
799 | + $info=$object->_load_ldap_info(); |
|
800 | + $dn=$object->_load_ldap_dn($info); |
|
801 | + |
|
802 | + $result=$ldap->delete($dn); |
|
803 | + } |
|
804 | + |
|
805 | + if ($result < 0) $this->error="ErrorLDAP ".$ldap->error; |
|
806 | + } |
|
807 | + } |
|
808 | + |
|
809 | + return $result; |
|
810 | + } |
|
811 | 811 | } |
@@ -34,58 +34,58 @@ discard block |
||
34 | 34 | */ |
35 | 35 | class InterfaceActionsAuto extends DolibarrTriggers |
36 | 36 | { |
37 | - public $family = 'agenda'; |
|
38 | - public $description = "Triggers of this module add actions in agenda according to setup made in agenda setup."; |
|
39 | - |
|
40 | - /** |
|
41 | - * Version of the trigger |
|
42 | - * @var string |
|
43 | - */ |
|
44 | - public $version = self::VERSION_DOLIBARR; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var string Image of the trigger |
|
48 | - */ |
|
49 | - public $picto = 'action'; |
|
50 | - |
|
51 | - /** |
|
52 | - * Function called when a Dolibarrr business event is done. |
|
53 | - * All functions "runTrigger" are triggered if file is inside directory htdocs/core/triggers or htdocs/module/code/triggers (and declared) |
|
54 | - * |
|
55 | - * Following properties may be set before calling trigger. The may be completed by this trigger to be used for writing the event into database: |
|
56 | - * $object->actiontypecode (translation action code: AC_OTH, ...) |
|
57 | - * $object->actionmsg (note, long text) |
|
58 | - * $object->actionmsg2 (label, short text) |
|
59 | - * $object->sendtoid (id of contact or array of ids) |
|
60 | - * $object->socid (id of thirdparty) |
|
61 | - * $object->fk_project |
|
62 | - * $object->fk_element |
|
63 | - * $object->elementtype |
|
64 | - * |
|
65 | - * @param string $action Event action code |
|
66 | - * @param Object $object Object |
|
67 | - * @param User $user Object user |
|
68 | - * @param Translate $langs Object langs |
|
69 | - * @param conf $conf Object conf |
|
70 | - * @return int <0 if KO, 0 if no triggered ran, >0 if OK |
|
71 | - */ |
|
72 | - public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf) |
|
73 | - { |
|
37 | + public $family = 'agenda'; |
|
38 | + public $description = "Triggers of this module add actions in agenda according to setup made in agenda setup."; |
|
39 | + |
|
40 | + /** |
|
41 | + * Version of the trigger |
|
42 | + * @var string |
|
43 | + */ |
|
44 | + public $version = self::VERSION_DOLIBARR; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var string Image of the trigger |
|
48 | + */ |
|
49 | + public $picto = 'action'; |
|
50 | + |
|
51 | + /** |
|
52 | + * Function called when a Dolibarrr business event is done. |
|
53 | + * All functions "runTrigger" are triggered if file is inside directory htdocs/core/triggers or htdocs/module/code/triggers (and declared) |
|
54 | + * |
|
55 | + * Following properties may be set before calling trigger. The may be completed by this trigger to be used for writing the event into database: |
|
56 | + * $object->actiontypecode (translation action code: AC_OTH, ...) |
|
57 | + * $object->actionmsg (note, long text) |
|
58 | + * $object->actionmsg2 (label, short text) |
|
59 | + * $object->sendtoid (id of contact or array of ids) |
|
60 | + * $object->socid (id of thirdparty) |
|
61 | + * $object->fk_project |
|
62 | + * $object->fk_element |
|
63 | + * $object->elementtype |
|
64 | + * |
|
65 | + * @param string $action Event action code |
|
66 | + * @param Object $object Object |
|
67 | + * @param User $user Object user |
|
68 | + * @param Translate $langs Object langs |
|
69 | + * @param conf $conf Object conf |
|
70 | + * @return int <0 if KO, 0 if no triggered ran, >0 if OK |
|
71 | + */ |
|
72 | + public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf) |
|
73 | + { |
|
74 | 74 | if (empty($conf->agenda->enabled)) return 0; // Module not active, we do nothing |
75 | 75 | |
76 | - $key = 'MAIN_AGENDA_ACTIONAUTO_'.$action; |
|
76 | + $key = 'MAIN_AGENDA_ACTIONAUTO_'.$action; |
|
77 | 77 | |
78 | - // Do not log events not enabled for this action |
|
79 | - if (empty($conf->global->$key)) { |
|
80 | - return 0; |
|
81 | - } |
|
78 | + // Do not log events not enabled for this action |
|
79 | + if (empty($conf->global->$key)) { |
|
80 | + return 0; |
|
81 | + } |
|
82 | 82 | |
83 | - $langs->load("agenda"); |
|
83 | + $langs->load("agenda"); |
|
84 | 84 | |
85 | - if (empty($object->actiontypecode)) $object->actiontypecode='AC_OTH_AUTO'; |
|
85 | + if (empty($object->actiontypecode)) $object->actiontypecode='AC_OTH_AUTO'; |
|
86 | 86 | |
87 | - // Actions |
|
88 | - if ($action == 'COMPANY_CREATE') |
|
87 | + // Actions |
|
88 | + if ($action == 'COMPANY_CREATE') |
|
89 | 89 | { |
90 | 90 | // Load translation files required by the page |
91 | 91 | $langs->loadLangs(array("agenda","other","companies")); |
@@ -94,8 +94,8 @@ discard block |
||
94 | 94 | $object->actionmsg=$langs->transnoentities("NewCompanyToDolibarr",$object->name); |
95 | 95 | if (! empty($object->prefix)) $object->actionmsg.=" (".$object->prefix.")"; |
96 | 96 | |
97 | - $object->sendtoid=0; |
|
98 | - $object->socid=$object->id; |
|
97 | + $object->sendtoid=0; |
|
98 | + $object->socid=$object->id; |
|
99 | 99 | } |
100 | 100 | elseif ($action == 'COMPANY_SENTBYMAIL') |
101 | 101 | { |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | |
107 | 107 | // Parameters $object->sendtoid defined by caller |
108 | 108 | //$object->sendtoid=0; |
109 | - } |
|
109 | + } |
|
110 | 110 | elseif ($action == 'CONTRACT_VALIDATE') |
111 | 111 | { |
112 | 112 | // Load translation files required by the page |
@@ -116,22 +116,22 @@ discard block |
||
116 | 116 | $object->actionmsg=$langs->transnoentities("ContractValidatedInDolibarr",($object->newref?$object->newref:$object->ref)); |
117 | 117 | |
118 | 118 | $object->sendtoid=0; |
119 | - } |
|
120 | - elseif ($action == 'CONTRACT_SENTBYMAIL') |
|
121 | - { |
|
122 | - // Load translation files required by the page |
|
119 | + } |
|
120 | + elseif ($action == 'CONTRACT_SENTBYMAIL') |
|
121 | + { |
|
122 | + // Load translation files required by the page |
|
123 | 123 | $langs->loadLangs(array("agenda","other","contracts")); |
124 | 124 | |
125 | - if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ContractSentByEMail",$object->ref); |
|
126 | - if (empty($object->actionmsg)) |
|
127 | - { |
|
128 | - $object->actionmsg=$langs->transnoentities("ContractSentByEMail",$object->ref); |
|
129 | - } |
|
125 | + if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ContractSentByEMail",$object->ref); |
|
126 | + if (empty($object->actionmsg)) |
|
127 | + { |
|
128 | + $object->actionmsg=$langs->transnoentities("ContractSentByEMail",$object->ref); |
|
129 | + } |
|
130 | 130 | |
131 | - // Parameters $object->sendtoid defined by caller |
|
132 | - //$object->sendtoid=0; |
|
133 | - } |
|
134 | - elseif ($action == 'PROPAL_VALIDATE') |
|
131 | + // Parameters $object->sendtoid defined by caller |
|
132 | + //$object->sendtoid=0; |
|
133 | + } |
|
134 | + elseif ($action == 'PROPAL_VALIDATE') |
|
135 | 135 | { |
136 | 136 | // Load translation files required by the page |
137 | 137 | $langs->loadLangs(array("agenda","other","propal")); |
@@ -139,8 +139,8 @@ discard block |
||
139 | 139 | if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalValidatedInDolibarr",($object->newref?$object->newref:$object->ref)); |
140 | 140 | $object->actionmsg=$langs->transnoentities("PropalValidatedInDolibarr",($object->newref?$object->newref:$object->ref)); |
141 | 141 | |
142 | - $object->sendtoid=0; |
|
143 | - } |
|
142 | + $object->sendtoid=0; |
|
143 | + } |
|
144 | 144 | elseif ($action == 'PROPAL_SENTBYMAIL') |
145 | 145 | { |
146 | 146 | // Load translation files required by the page |
@@ -154,8 +154,8 @@ discard block |
||
154 | 154 | |
155 | 155 | // Parameters $object->sendtoid defined by caller |
156 | 156 | //$object->sendtoid=0; |
157 | - } |
|
158 | - elseif ($action == 'PROPAL_CLOSE_SIGNED') |
|
157 | + } |
|
158 | + elseif ($action == 'PROPAL_CLOSE_SIGNED') |
|
159 | 159 | { |
160 | 160 | // Load translation files required by the page |
161 | 161 | $langs->loadLangs(array("agenda","other","propal")); |
@@ -163,9 +163,9 @@ discard block |
||
163 | 163 | if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalClosedSignedInDolibarr",$object->ref); |
164 | 164 | $object->actionmsg=$langs->transnoentities("PropalClosedSignedInDolibarr",$object->ref); |
165 | 165 | |
166 | - $object->sendtoid=0; |
|
167 | - } |
|
168 | - elseif ($action == 'PROPAL_CLASSIFY_BILLED') |
|
166 | + $object->sendtoid=0; |
|
167 | + } |
|
168 | + elseif ($action == 'PROPAL_CLASSIFY_BILLED') |
|
169 | 169 | { |
170 | 170 | // Load translation files required by the page |
171 | 171 | $langs->loadLangs(array("agenda","other","propal")); |
@@ -173,9 +173,9 @@ discard block |
||
173 | 173 | if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalClassifiedBilledInDolibarr",$object->ref); |
174 | 174 | $object->actionmsg=$langs->transnoentities("PropalClassifiedBilledInDolibarr",$object->ref); |
175 | 175 | |
176 | - $object->sendtoid=0; |
|
177 | - } |
|
178 | - elseif ($action == 'PROPAL_CLOSE_REFUSED') |
|
176 | + $object->sendtoid=0; |
|
177 | + } |
|
178 | + elseif ($action == 'PROPAL_CLOSE_REFUSED') |
|
179 | 179 | { |
180 | 180 | // Load translation files required by the page |
181 | 181 | $langs->loadLangs(array("agenda","other","propal")); |
@@ -183,9 +183,9 @@ discard block |
||
183 | 183 | if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalClosedRefusedInDolibarr",$object->ref); |
184 | 184 | $object->actionmsg=$langs->transnoentities("PropalClosedRefusedInDolibarr",$object->ref); |
185 | 185 | |
186 | - $object->sendtoid=0; |
|
187 | - } |
|
188 | - elseif ($action == 'ORDER_VALIDATE') |
|
186 | + $object->sendtoid=0; |
|
187 | + } |
|
188 | + elseif ($action == 'ORDER_VALIDATE') |
|
189 | 189 | { |
190 | 190 | // Load translation files required by the page |
191 | 191 | $langs->loadLangs(array("agenda","orders")); |
@@ -193,9 +193,9 @@ discard block |
||
193 | 193 | if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderValidatedInDolibarr",($object->newref?$object->newref:$object->ref)); |
194 | 194 | $object->actionmsg=$langs->transnoentities("OrderValidatedInDolibarr",($object->newref?$object->newref:$object->ref)); |
195 | 195 | |
196 | - $object->sendtoid=0; |
|
197 | - } |
|
198 | - elseif ($action == 'ORDER_CLOSE') |
|
196 | + $object->sendtoid=0; |
|
197 | + } |
|
198 | + elseif ($action == 'ORDER_CLOSE') |
|
199 | 199 | { |
200 | 200 | // Load translation files required by the page |
201 | 201 | $langs->loadLangs(array("agenda","other","orders")); |
@@ -203,9 +203,9 @@ discard block |
||
203 | 203 | if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderDeliveredInDolibarr",$object->ref); |
204 | 204 | $object->actionmsg=$langs->transnoentities("OrderDeliveredInDolibarr",$object->ref); |
205 | 205 | |
206 | - $object->sendtoid=0; |
|
207 | - } |
|
208 | - elseif ($action == 'ORDER_CLASSIFY_BILLED') |
|
206 | + $object->sendtoid=0; |
|
207 | + } |
|
208 | + elseif ($action == 'ORDER_CLASSIFY_BILLED') |
|
209 | 209 | { |
210 | 210 | // Load translation files required by the page |
211 | 211 | $langs->loadLangs(array("agenda","other","orders")); |
@@ -213,9 +213,9 @@ discard block |
||
213 | 213 | if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderBilledInDolibarr",$object->ref); |
214 | 214 | $object->actionmsg=$langs->transnoentities("OrderBilledInDolibarr",$object->ref); |
215 | 215 | |
216 | - $object->sendtoid=0; |
|
217 | - } |
|
218 | - elseif ($action == 'ORDER_CANCEL') |
|
216 | + $object->sendtoid=0; |
|
217 | + } |
|
218 | + elseif ($action == 'ORDER_CANCEL') |
|
219 | 219 | { |
220 | 220 | // Load translation files required by the page |
221 | 221 | $langs->loadLangs(array("agenda","other","orders")); |
@@ -223,9 +223,9 @@ discard block |
||
223 | 223 | if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderCanceledInDolibarr",$object->ref); |
224 | 224 | $object->actionmsg=$langs->transnoentities("OrderCanceledInDolibarr",$object->ref); |
225 | 225 | |
226 | - $object->sendtoid=0; |
|
227 | - } |
|
228 | - elseif ($action == 'ORDER_SENTBYMAIL') |
|
226 | + $object->sendtoid=0; |
|
227 | + } |
|
228 | + elseif ($action == 'ORDER_SENTBYMAIL') |
|
229 | 229 | { |
230 | 230 | // Load translation files required by the page |
231 | 231 | $langs->loadLangs(array("agenda","other","orders")); |
@@ -238,8 +238,8 @@ discard block |
||
238 | 238 | |
239 | 239 | // Parameters $object->sendtoid defined by caller |
240 | 240 | //$object->sendtoid=0; |
241 | - } |
|
242 | - elseif ($action == 'BILL_VALIDATE') |
|
241 | + } |
|
242 | + elseif ($action == 'BILL_VALIDATE') |
|
243 | 243 | { |
244 | 244 | // Load translation files required by the page |
245 | 245 | $langs->loadLangs(array("agenda","other","bills")); |
@@ -247,18 +247,18 @@ discard block |
||
247 | 247 | if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceValidatedInDolibarr",($object->newref?$object->newref:$object->ref)); |
248 | 248 | $object->actionmsg=$langs->transnoentities("InvoiceValidatedInDolibarr",($object->newref?$object->newref:$object->ref)); |
249 | 249 | |
250 | - $object->sendtoid=0; |
|
251 | - } |
|
252 | - elseif ($action == 'BILL_UNVALIDATE') |
|
250 | + $object->sendtoid=0; |
|
251 | + } |
|
252 | + elseif ($action == 'BILL_UNVALIDATE') |
|
253 | 253 | { |
254 | - // Load translation files required by the page |
|
254 | + // Load translation files required by the page |
|
255 | 255 | $langs->loadLangs(array("agenda","other","bills")); |
256 | 256 | |
257 | 257 | if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceBackToDraftInDolibarr",$object->ref); |
258 | 258 | $object->actionmsg=$langs->transnoentities("InvoiceBackToDraftInDolibarr",$object->ref); |
259 | 259 | |
260 | - $object->sendtoid=0; |
|
261 | - } |
|
260 | + $object->sendtoid=0; |
|
261 | + } |
|
262 | 262 | elseif ($action == 'BILL_SENTBYMAIL') |
263 | 263 | { |
264 | 264 | // Load translation files required by the page |
@@ -272,8 +272,8 @@ discard block |
||
272 | 272 | |
273 | 273 | // Parameters $object->sendtoid defined by caller |
274 | 274 | //$object->sendtoid=0; |
275 | - } |
|
276 | - elseif ($action == 'BILL_PAYED') |
|
275 | + } |
|
276 | + elseif ($action == 'BILL_PAYED') |
|
277 | 277 | { |
278 | 278 | // Load translation files required by the page |
279 | 279 | $langs->loadLangs(array("agenda","other","bills")); |
@@ -283,8 +283,8 @@ discard block |
||
283 | 283 | $object->actionmsg=$langs->transnoentities("InvoicePaidInDolibarr",$object->ref); |
284 | 284 | |
285 | 285 | $object->sendtoid=0; |
286 | - } |
|
287 | - elseif ($action == 'BILL_CANCEL') |
|
286 | + } |
|
287 | + elseif ($action == 'BILL_CANCEL') |
|
288 | 288 | { |
289 | 289 | // Load translation files required by the page |
290 | 290 | $langs->loadLangs(array("agenda","other","bills")); |
@@ -293,8 +293,8 @@ discard block |
||
293 | 293 | $object->actionmsg=$langs->transnoentities("InvoiceCanceledInDolibarr",$object->ref); |
294 | 294 | |
295 | 295 | $object->sendtoid=0; |
296 | - } |
|
297 | - elseif ($action == 'FICHINTER_CREATE') |
|
296 | + } |
|
297 | + elseif ($action == 'FICHINTER_CREATE') |
|
298 | 298 | { |
299 | 299 | // Load translation files required by the page |
300 | 300 | $langs->loadLangs(array("agenda","other","interventions")); |
@@ -303,10 +303,10 @@ discard block |
||
303 | 303 | $object->actionmsg=$langs->transnoentities("InterventionCreatedInDolibarr",$object->ref); |
304 | 304 | |
305 | 305 | $object->sendtoid=0; |
306 | - $object->fk_element=0; |
|
307 | - $object->elementtype=''; |
|
308 | - } |
|
309 | - elseif ($action == 'FICHINTER_VALIDATE') |
|
306 | + $object->fk_element=0; |
|
307 | + $object->elementtype=''; |
|
308 | + } |
|
309 | + elseif ($action == 'FICHINTER_VALIDATE') |
|
310 | 310 | { |
311 | 311 | // Load translation files required by the page |
312 | 312 | $langs->loadLangs(array("agenda","other","interventions")); |
@@ -315,10 +315,10 @@ discard block |
||
315 | 315 | $object->actionmsg=$langs->transnoentities("InterventionValidatedInDolibarr",($object->newref?$object->newref:$object->ref)); |
316 | 316 | |
317 | 317 | $object->sendtoid=0; |
318 | - $object->fk_element=0; |
|
319 | - $object->elementtype=''; |
|
320 | - } |
|
321 | - elseif ($action == 'FICHINTER_MODIFY') |
|
318 | + $object->fk_element=0; |
|
319 | + $object->elementtype=''; |
|
320 | + } |
|
321 | + elseif ($action == 'FICHINTER_MODIFY') |
|
322 | 322 | { |
323 | 323 | // Load translation files required by the page |
324 | 324 | $langs->loadLangs(array("agenda","other","interventions")); |
@@ -327,10 +327,10 @@ discard block |
||
327 | 327 | $object->actionmsg=$langs->transnoentities("InterventionModifiedInDolibarr",$object->ref); |
328 | 328 | |
329 | 329 | $object->sendtoid=0; |
330 | - $object->fk_element=0; |
|
331 | - $object->elementtype=''; |
|
332 | - } |
|
333 | - elseif ($action == 'FICHINTER_SENTBYMAIL') |
|
330 | + $object->fk_element=0; |
|
331 | + $object->elementtype=''; |
|
332 | + } |
|
333 | + elseif ($action == 'FICHINTER_SENTBYMAIL') |
|
334 | 334 | { |
335 | 335 | // Load translation files required by the page |
336 | 336 | $langs->loadLangs(array("agenda","other","interventions")); |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionSentByEMail",$object->ref); |
339 | 339 | if (empty($object->actionmsg)) |
340 | 340 | { |
341 | - $object->actionmsg=$langs->transnoentities("InterventionSentByEMail",$object->ref); |
|
341 | + $object->actionmsg=$langs->transnoentities("InterventionSentByEMail",$object->ref); |
|
342 | 342 | } |
343 | 343 | |
344 | 344 | // Parameters $object->sendtoid defined by caller |
@@ -349,18 +349,18 @@ discard block |
||
349 | 349 | // Load translation files required by the page |
350 | 350 | $langs->loadLangs(array("agenda","other","interventions")); |
351 | 351 | |
352 | - if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionClassifiedBilledInDolibarr",$object->ref); |
|
353 | - $object->actionmsg=$langs->transnoentities("InterventionClassifiedBilledInDolibarr",$object->ref); |
|
352 | + if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionClassifiedBilledInDolibarr",$object->ref); |
|
353 | + $object->actionmsg=$langs->transnoentities("InterventionClassifiedBilledInDolibarr",$object->ref); |
|
354 | 354 | |
355 | 355 | $object->sendtoid=0; |
356 | 356 | } |
357 | - elseif ($action == 'FICHINTER_CLASSIFY_UNBILLED') |
|
357 | + elseif ($action == 'FICHINTER_CLASSIFY_UNBILLED') |
|
358 | 358 | { |
359 | 359 | // Load translation files required by the page |
360 | 360 | $langs->loadLangs(array("agenda","other","interventions")); |
361 | 361 | |
362 | - if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionClassifiedUnbilledInDolibarr",$object->ref); |
|
363 | - $object->actionmsg=$langs->transnoentities("InterventionClassifiedUnbilledInDolibarr",$object->ref); |
|
362 | + if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionClassifiedUnbilledInDolibarr",$object->ref); |
|
363 | + $object->actionmsg=$langs->transnoentities("InterventionClassifiedUnbilledInDolibarr",$object->ref); |
|
364 | 364 | |
365 | 365 | $object->sendtoid=0; |
366 | 366 | } |
@@ -373,24 +373,24 @@ discard block |
||
373 | 373 | $object->actionmsg=$langs->transnoentities("InterventionDeletedInDolibarr",$object->ref); |
374 | 374 | |
375 | 375 | $object->sendtoid=0; |
376 | - $object->fk_element=0; |
|
377 | - $object->elementtype=''; |
|
378 | - } |
|
376 | + $object->fk_element=0; |
|
377 | + $object->elementtype=''; |
|
378 | + } |
|
379 | 379 | elseif ($action == 'SHIPPING_VALIDATE') |
380 | 380 | { |
381 | 381 | // Load translation files required by the page |
382 | 382 | $langs->loadLangs(array("agenda","other","sendings")); |
383 | 383 | |
384 | - if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ShippingValidated",($object->newref?$object->newref:$object->ref)); |
|
385 | - if (empty($object->actionmsg)) |
|
386 | - { |
|
387 | - $object->actionmsg=$langs->transnoentities("ShippingValidated",($object->newref?$object->newref:$object->ref)); |
|
388 | - } |
|
384 | + if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ShippingValidated",($object->newref?$object->newref:$object->ref)); |
|
385 | + if (empty($object->actionmsg)) |
|
386 | + { |
|
387 | + $object->actionmsg=$langs->transnoentities("ShippingValidated",($object->newref?$object->newref:$object->ref)); |
|
388 | + } |
|
389 | 389 | |
390 | - // Parameters $object->sendtoid defined by caller |
|
391 | - //$object->sendtoid=0; |
|
390 | + // Parameters $object->sendtoid defined by caller |
|
391 | + //$object->sendtoid=0; |
|
392 | 392 | } |
393 | - elseif ($action == 'SHIPPING_SENTBYMAIL') |
|
393 | + elseif ($action == 'SHIPPING_SENTBYMAIL') |
|
394 | 394 | { |
395 | 395 | // Load translation files required by the page |
396 | 396 | $langs->loadLangs(array("agenda","other","sendings")); |
@@ -403,22 +403,22 @@ discard block |
||
403 | 403 | |
404 | 404 | // Parameters $object->sendtoid defined by caller |
405 | 405 | //$object->sendtoid=0; |
406 | - } elseif ($action == 'RECEPTION_VALIDATE') |
|
406 | + } elseif ($action == 'RECEPTION_VALIDATE') |
|
407 | 407 | { |
408 | 408 | $langs->load("agenda"); |
409 | 409 | $langs->load("other"); |
410 | - $langs->load("receptions"); |
|
410 | + $langs->load("receptions"); |
|
411 | 411 | |
412 | - if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ReceptionValidated",($object->newref?$object->newref:$object->ref)); |
|
413 | - if (empty($object->actionmsg)) |
|
414 | - { |
|
415 | - $object->actionmsg=$langs->transnoentities("ReceptionValidated",($object->newref?$object->newref:$object->ref)); |
|
416 | - } |
|
412 | + if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ReceptionValidated",($object->newref?$object->newref:$object->ref)); |
|
413 | + if (empty($object->actionmsg)) |
|
414 | + { |
|
415 | + $object->actionmsg=$langs->transnoentities("ReceptionValidated",($object->newref?$object->newref:$object->ref)); |
|
416 | + } |
|
417 | 417 | |
418 | - // Parameters $object->sendtoid defined by caller |
|
419 | - //$object->sendtoid=0; |
|
418 | + // Parameters $object->sendtoid defined by caller |
|
419 | + //$object->sendtoid=0; |
|
420 | 420 | } |
421 | - elseif ($action == 'RECEPTION_SENTBYMAIL') |
|
421 | + elseif ($action == 'RECEPTION_SENTBYMAIL') |
|
422 | 422 | { |
423 | 423 | $langs->load("agenda"); |
424 | 424 | $langs->load("other"); |
@@ -432,52 +432,52 @@ discard block |
||
432 | 432 | |
433 | 433 | // Parameters $object->sendtoid defined by caller |
434 | 434 | //$object->sendtoid=0; |
435 | - } |
|
436 | - elseif ($action == 'PROPOSAL_SUPPLIER_VALIDATE') |
|
437 | - { |
|
438 | - // Load translation files required by the page |
|
435 | + } |
|
436 | + elseif ($action == 'PROPOSAL_SUPPLIER_VALIDATE') |
|
437 | + { |
|
438 | + // Load translation files required by the page |
|
439 | 439 | $langs->loadLangs(array("agenda","other","propal")); |
440 | 440 | |
441 | - if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalValidatedInDolibarr",($object->newref?$object->newref:$object->ref)); |
|
442 | - $object->actionmsg=$langs->transnoentities("PropalValidatedInDolibarr",($object->newref?$object->newref:$object->ref)); |
|
441 | + if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalValidatedInDolibarr",($object->newref?$object->newref:$object->ref)); |
|
442 | + $object->actionmsg=$langs->transnoentities("PropalValidatedInDolibarr",($object->newref?$object->newref:$object->ref)); |
|
443 | 443 | |
444 | - $object->sendtoid=0; |
|
445 | - } |
|
446 | - elseif ($action == 'PROPOSAL_SUPPLIER_SENTBYMAIL') |
|
447 | - { |
|
448 | - // Load translation files required by the page |
|
444 | + $object->sendtoid=0; |
|
445 | + } |
|
446 | + elseif ($action == 'PROPOSAL_SUPPLIER_SENTBYMAIL') |
|
447 | + { |
|
448 | + // Load translation files required by the page |
|
449 | 449 | $langs->loadLangs(array("agenda","other","propal")); |
450 | 450 | |
451 | - if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ProposalSentByEMail",$object->ref); |
|
452 | - if (empty($object->actionmsg)) |
|
453 | - { |
|
454 | - $object->actionmsg=$langs->transnoentities("ProposalSentByEMail",$object->ref); |
|
455 | - } |
|
456 | - |
|
457 | - // Parameters $object->sendtoid defined by caller |
|
458 | - //$object->sendtoid=0; |
|
459 | - } |
|
460 | - elseif ($action == 'PROPOSAL_SUPPLIER_CLOSE_SIGNED') |
|
461 | - { |
|
462 | - // Load translation files required by the page |
|
451 | + if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ProposalSentByEMail",$object->ref); |
|
452 | + if (empty($object->actionmsg)) |
|
453 | + { |
|
454 | + $object->actionmsg=$langs->transnoentities("ProposalSentByEMail",$object->ref); |
|
455 | + } |
|
456 | + |
|
457 | + // Parameters $object->sendtoid defined by caller |
|
458 | + //$object->sendtoid=0; |
|
459 | + } |
|
460 | + elseif ($action == 'PROPOSAL_SUPPLIER_CLOSE_SIGNED') |
|
461 | + { |
|
462 | + // Load translation files required by the page |
|
463 | 463 | $langs->loadLangs(array("agenda","other","propal")); |
464 | 464 | |
465 | - if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalClosedSignedInDolibarr",$object->ref); |
|
466 | - $object->actionmsg=$langs->transnoentities("PropalClosedSignedInDolibarr",$object->ref); |
|
465 | + if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalClosedSignedInDolibarr",$object->ref); |
|
466 | + $object->actionmsg=$langs->transnoentities("PropalClosedSignedInDolibarr",$object->ref); |
|
467 | 467 | |
468 | - $object->sendtoid=0; |
|
469 | - } |
|
470 | - elseif ($action == 'PROPOSAL_SUPPLIER_CLOSE_REFUSED') |
|
471 | - { |
|
472 | - // Load translation files required by the page |
|
468 | + $object->sendtoid=0; |
|
469 | + } |
|
470 | + elseif ($action == 'PROPOSAL_SUPPLIER_CLOSE_REFUSED') |
|
471 | + { |
|
472 | + // Load translation files required by the page |
|
473 | 473 | $langs->loadLangs(array("agenda","other","propal")); |
474 | 474 | |
475 | - if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalClosedRefusedInDolibarr",$object->ref); |
|
476 | - $object->actionmsg=$langs->transnoentities("PropalClosedRefusedInDolibarr",$object->ref); |
|
475 | + if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalClosedRefusedInDolibarr",$object->ref); |
|
476 | + $object->actionmsg=$langs->transnoentities("PropalClosedRefusedInDolibarr",$object->ref); |
|
477 | 477 | |
478 | - $object->sendtoid=0; |
|
479 | - } |
|
480 | - elseif ($action == 'ORDER_SUPPLIER_CREATE') |
|
478 | + $object->sendtoid=0; |
|
479 | + } |
|
480 | + elseif ($action == 'ORDER_SUPPLIER_CREATE') |
|
481 | 481 | { |
482 | 482 | // Load translation files required by the page |
483 | 483 | $langs->loadLangs(array("agenda","other","orders")); |
@@ -486,8 +486,8 @@ discard block |
||
486 | 486 | $object->actionmsg=$langs->transnoentities("OrderCreatedInDolibarr",($object->newref?$object->newref:$object->ref)); |
487 | 487 | |
488 | 488 | $object->sendtoid=0; |
489 | - } |
|
490 | - elseif ($action == 'ORDER_SUPPLIER_VALIDATE') |
|
489 | + } |
|
490 | + elseif ($action == 'ORDER_SUPPLIER_VALIDATE') |
|
491 | 491 | { |
492 | 492 | // Load translation files required by the page |
493 | 493 | $langs->loadLangs(array("agenda","other","orders")); |
@@ -496,28 +496,28 @@ discard block |
||
496 | 496 | $object->actionmsg=$langs->transnoentities("OrderValidatedInDolibarr",($object->newref?$object->newref:$object->ref)); |
497 | 497 | |
498 | 498 | $object->sendtoid=0; |
499 | - } |
|
500 | - elseif ($action == 'ORDER_SUPPLIER_APPROVE') |
|
501 | - { |
|
499 | + } |
|
500 | + elseif ($action == 'ORDER_SUPPLIER_APPROVE') |
|
501 | + { |
|
502 | 502 | // Load translation files required by the page |
503 | 503 | $langs->loadLangs(array("agenda","other","orders")); |
504 | 504 | |
505 | - if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderApprovedInDolibarr",$object->ref); |
|
506 | - $object->actionmsg=$langs->transnoentities("OrderApprovedInDolibarr",$object->ref); |
|
505 | + if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderApprovedInDolibarr",$object->ref); |
|
506 | + $object->actionmsg=$langs->transnoentities("OrderApprovedInDolibarr",$object->ref); |
|
507 | 507 | |
508 | - $object->sendtoid=0; |
|
509 | - } |
|
510 | - elseif ($action == 'ORDER_SUPPLIER_REFUSE') |
|
511 | - { |
|
508 | + $object->sendtoid=0; |
|
509 | + } |
|
510 | + elseif ($action == 'ORDER_SUPPLIER_REFUSE') |
|
511 | + { |
|
512 | 512 | // Load translation files required by the page |
513 | 513 | $langs->loadLangs(array("agenda","other","orders")); |
514 | 514 | |
515 | - if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderRefusedInDolibarr",$object->ref); |
|
516 | - $object->actionmsg=$langs->transnoentities("OrderRefusedInDolibarr",$object->ref); |
|
515 | + if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderRefusedInDolibarr",$object->ref); |
|
516 | + $object->actionmsg=$langs->transnoentities("OrderRefusedInDolibarr",$object->ref); |
|
517 | 517 | |
518 | - $object->sendtoid=0; |
|
519 | - } |
|
520 | - elseif ($action == 'ORDER_SUPPLIER_SUBMIT') |
|
518 | + $object->sendtoid=0; |
|
519 | + } |
|
520 | + elseif ($action == 'ORDER_SUPPLIER_SUBMIT') |
|
521 | 521 | { |
522 | 522 | // Load translation files required by the page |
523 | 523 | $langs->loadLangs(array("agenda","other","orders")); |
@@ -526,8 +526,8 @@ discard block |
||
526 | 526 | $object->actionmsg=$langs->transnoentities("SupplierOrderSubmitedInDolibarr",($object->newref?$object->newref:$object->ref)); |
527 | 527 | |
528 | 528 | $object->sendtoid=0; |
529 | - } |
|
530 | - elseif ($action == 'ORDER_SUPPLIER_RECEIVE') |
|
529 | + } |
|
530 | + elseif ($action == 'ORDER_SUPPLIER_RECEIVE') |
|
531 | 531 | { |
532 | 532 | // Load translation files required by the page |
533 | 533 | $langs->loadLangs(array("agenda","other","orders")); |
@@ -536,8 +536,8 @@ discard block |
||
536 | 536 | $object->actionmsg=$langs->transnoentities("SupplierOrderReceivedInDolibarr",($object->newref?$object->newref:$object->ref)); |
537 | 537 | |
538 | 538 | $object->sendtoid=0; |
539 | - } |
|
540 | - elseif ($action == 'ORDER_SUPPLIER_SENTBYMAIL') |
|
539 | + } |
|
540 | + elseif ($action == 'ORDER_SUPPLIER_SENTBYMAIL') |
|
541 | 541 | { |
542 | 542 | // Load translation files required by the page |
543 | 543 | $langs->loadLangs(array("agenda","other","bills","orders")); |
@@ -551,7 +551,7 @@ discard block |
||
551 | 551 | // Parameters $object->sendtoid defined by caller |
552 | 552 | //$object->sendtoid=0; |
553 | 553 | } |
554 | - elseif ($action == 'ORDER_SUPPLIER_CLASSIFY_BILLED') |
|
554 | + elseif ($action == 'ORDER_SUPPLIER_CLASSIFY_BILLED') |
|
555 | 555 | { |
556 | 556 | // Load translation files required by the page |
557 | 557 | $langs->loadLangs(array("agenda","other","bills","orders")); |
@@ -564,7 +564,7 @@ discard block |
||
564 | 564 | |
565 | 565 | $object->sendtoid=0; |
566 | 566 | } |
567 | - elseif ($action == 'BILL_SUPPLIER_VALIDATE') |
|
567 | + elseif ($action == 'BILL_SUPPLIER_VALIDATE') |
|
568 | 568 | { |
569 | 569 | // Load translation files required by the page |
570 | 570 | $langs->loadLangs(array("agenda","other","bills")); |
@@ -573,8 +573,8 @@ discard block |
||
573 | 573 | $object->actionmsg=$langs->transnoentities("InvoiceValidatedInDolibarr",($object->newref?$object->newref:$object->ref)); |
574 | 574 | |
575 | 575 | $object->sendtoid=0; |
576 | - } |
|
577 | - elseif ($action == 'BILL_SUPPLIER_UNVALIDATE') |
|
576 | + } |
|
577 | + elseif ($action == 'BILL_SUPPLIER_UNVALIDATE') |
|
578 | 578 | { |
579 | 579 | // Load translation files required by the page |
580 | 580 | $langs->loadLangs(array("agenda","other","bills")); |
@@ -583,7 +583,7 @@ discard block |
||
583 | 583 | $object->actionmsg=$langs->transnoentities("InvoiceBackToDraftInDolibarr",$object->ref); |
584 | 584 | |
585 | 585 | $object->sendtoid=0; |
586 | - } |
|
586 | + } |
|
587 | 587 | elseif ($action == 'BILL_SUPPLIER_SENTBYMAIL') |
588 | 588 | { |
589 | 589 | // Load translation files required by the page |
@@ -598,7 +598,7 @@ discard block |
||
598 | 598 | // Parameters $object->sendtoid defined by caller |
599 | 599 | //$object->sendtoid=0; |
600 | 600 | } |
601 | - elseif ($action == 'BILL_SUPPLIER_PAYED') |
|
601 | + elseif ($action == 'BILL_SUPPLIER_PAYED') |
|
602 | 602 | { |
603 | 603 | // Load translation files required by the page |
604 | 604 | $langs->loadLangs(array("agenda","other","bills")); |
@@ -606,9 +606,9 @@ discard block |
||
606 | 606 | if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoicePaidInDolibarr",$object->ref); |
607 | 607 | $object->actionmsg=$langs->transnoentities("InvoicePaidInDolibarr",$object->ref); |
608 | 608 | |
609 | - $object->sendtoid=0; |
|
610 | - } |
|
611 | - elseif ($action == 'BILL_SUPPLIER_CANCELED') |
|
609 | + $object->sendtoid=0; |
|
610 | + } |
|
611 | + elseif ($action == 'BILL_SUPPLIER_CANCELED') |
|
612 | 612 | { |
613 | 613 | // Load translation files required by the page |
614 | 614 | $langs->loadLangs(array("agenda","other","bills")); |
@@ -616,8 +616,8 @@ discard block |
||
616 | 616 | if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceCanceledInDolibarr",$object->ref); |
617 | 617 | $object->actionmsg=$langs->transnoentities("InvoiceCanceledInDolibarr",$object->ref); |
618 | 618 | |
619 | - $object->sendtoid=0; |
|
620 | - } |
|
619 | + $object->sendtoid=0; |
|
620 | + } |
|
621 | 621 | |
622 | 622 | // Members |
623 | 623 | elseif ($action == 'MEMBER_VALIDATE') |
@@ -630,9 +630,9 @@ discard block |
||
630 | 630 | $object->actionmsg.="\n".$langs->transnoentities("Member").': '.$object->getFullName($langs); |
631 | 631 | $object->actionmsg.="\n".$langs->transnoentities("Type").': '.$object->type; |
632 | 632 | |
633 | - $object->sendtoid=0; |
|
633 | + $object->sendtoid=0; |
|
634 | 634 | } |
635 | - elseif ($action == 'MEMBER_MODIFY') |
|
635 | + elseif ($action == 'MEMBER_MODIFY') |
|
636 | 636 | { |
637 | 637 | // Load translation files required by the page |
638 | 638 | $langs->loadLangs(array("agenda","other","members")); |
@@ -643,7 +643,7 @@ discard block |
||
643 | 643 | $object->actionmsg.="\n".$langs->transnoentities("Type").': '.$object->type; |
644 | 644 | |
645 | 645 | $object->sendtoid=0; |
646 | - } |
|
646 | + } |
|
647 | 647 | elseif ($action == 'MEMBER_SUBSCRIPTION_CREATE') |
648 | 648 | { |
649 | 649 | // Load translation files required by the page |
@@ -656,38 +656,38 @@ discard block |
||
656 | 656 | $object->actionmsg.="\n".$langs->transnoentities("Amount").': '.$object->last_subscription_amount; |
657 | 657 | $object->actionmsg.="\n".$langs->transnoentities("Period").': '.dol_print_date($object->last_subscription_date_start,'day').' - '.dol_print_date($object->last_subscription_date_end,'day'); |
658 | 658 | |
659 | - $object->sendtoid=0; |
|
660 | - if ($object->fk_soc > 0) $object->socid=$object->fk_soc; |
|
659 | + $object->sendtoid=0; |
|
660 | + if ($object->fk_soc > 0) $object->socid=$object->fk_soc; |
|
661 | 661 | } |
662 | 662 | elseif ($action == 'MEMBER_SUBSCRIPTION_MODIFY') |
663 | 663 | { |
664 | - // Load translation files required by the page |
|
664 | + // Load translation files required by the page |
|
665 | 665 | $langs->loadLangs(array("agenda","other","members")); |
666 | 666 | |
667 | - if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("MemberSubscriptionModifiedInDolibarr",$object->ref,$object->getFullName($langs)); |
|
668 | - $object->actionmsg=$langs->transnoentities("MemberSubscriptionModifiedInDolibarr",$object->ref,$object->getFullName($langs)); |
|
669 | - $object->actionmsg.="\n".$langs->transnoentities("Member").': '.$object->getFullName($langs); |
|
670 | - $object->actionmsg.="\n".$langs->transnoentities("Type").': '.$object->type; |
|
671 | - $object->actionmsg.="\n".$langs->transnoentities("Amount").': '.$object->last_subscription_amount; |
|
672 | - $object->actionmsg.="\n".$langs->transnoentities("Period").': '.dol_print_date($object->last_subscription_date_start,'day').' - '.dol_print_date($object->last_subscription_date_end,'day'); |
|
667 | + if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("MemberSubscriptionModifiedInDolibarr",$object->ref,$object->getFullName($langs)); |
|
668 | + $object->actionmsg=$langs->transnoentities("MemberSubscriptionModifiedInDolibarr",$object->ref,$object->getFullName($langs)); |
|
669 | + $object->actionmsg.="\n".$langs->transnoentities("Member").': '.$object->getFullName($langs); |
|
670 | + $object->actionmsg.="\n".$langs->transnoentities("Type").': '.$object->type; |
|
671 | + $object->actionmsg.="\n".$langs->transnoentities("Amount").': '.$object->last_subscription_amount; |
|
672 | + $object->actionmsg.="\n".$langs->transnoentities("Period").': '.dol_print_date($object->last_subscription_date_start,'day').' - '.dol_print_date($object->last_subscription_date_end,'day'); |
|
673 | 673 | |
674 | - $object->sendtoid=0; |
|
675 | - if ($object->fk_soc > 0) $object->socid=$object->fk_soc; |
|
674 | + $object->sendtoid=0; |
|
675 | + if ($object->fk_soc > 0) $object->socid=$object->fk_soc; |
|
676 | 676 | } |
677 | 677 | elseif ($action == 'MEMBER_SUBSCRIPTION_DELETE') |
678 | 678 | { |
679 | - // Load translation files required by the page |
|
679 | + // Load translation files required by the page |
|
680 | 680 | $langs->loadLangs(array("agenda","other","members")); |
681 | 681 | |
682 | - if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("MemberSubscriptionDeletedInDolibarr",$object->ref,$object->getFullName($langs)); |
|
683 | - $object->actionmsg=$langs->transnoentities("MemberSubscriptionDeletedInDolibarr",$object->ref,$object->getFullName($langs)); |
|
684 | - $object->actionmsg.="\n".$langs->transnoentities("Member").': '.$object->getFullName($langs); |
|
685 | - $object->actionmsg.="\n".$langs->transnoentities("Type").': '.$object->type; |
|
686 | - $object->actionmsg.="\n".$langs->transnoentities("Amount").': '.$object->last_subscription_amount; |
|
687 | - $object->actionmsg.="\n".$langs->transnoentities("Period").': '.dol_print_date($object->last_subscription_date_start,'day').' - '.dol_print_date($object->last_subscription_date_end,'day'); |
|
682 | + if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("MemberSubscriptionDeletedInDolibarr",$object->ref,$object->getFullName($langs)); |
|
683 | + $object->actionmsg=$langs->transnoentities("MemberSubscriptionDeletedInDolibarr",$object->ref,$object->getFullName($langs)); |
|
684 | + $object->actionmsg.="\n".$langs->transnoentities("Member").': '.$object->getFullName($langs); |
|
685 | + $object->actionmsg.="\n".$langs->transnoentities("Type").': '.$object->type; |
|
686 | + $object->actionmsg.="\n".$langs->transnoentities("Amount").': '.$object->last_subscription_amount; |
|
687 | + $object->actionmsg.="\n".$langs->transnoentities("Period").': '.dol_print_date($object->last_subscription_date_start,'day').' - '.dol_print_date($object->last_subscription_date_end,'day'); |
|
688 | 688 | |
689 | - $object->sendtoid=0; |
|
690 | - if ($object->fk_soc > 0) $object->socid=$object->fk_soc; |
|
689 | + $object->sendtoid=0; |
|
690 | + if ($object->fk_soc > 0) $object->socid=$object->fk_soc; |
|
691 | 691 | } |
692 | 692 | elseif ($action == 'MEMBER_RESILIATE') |
693 | 693 | { |
@@ -699,7 +699,7 @@ discard block |
||
699 | 699 | $object->actionmsg.="\n".$langs->transnoentities("Member").': '.$object->getFullName($langs); |
700 | 700 | $object->actionmsg.="\n".$langs->transnoentities("Type").': '.$object->type; |
701 | 701 | |
702 | - $object->sendtoid=0; |
|
702 | + $object->sendtoid=0; |
|
703 | 703 | } |
704 | 704 | elseif ($action == 'MEMBER_DELETE') |
705 | 705 | { |
@@ -711,7 +711,7 @@ discard block |
||
711 | 711 | $object->actionmsg.="\n".$langs->transnoentities("Member").': '.$object->getFullName($langs); |
712 | 712 | $object->actionmsg.="\n".$langs->transnoentities("Type").': '.$object->type; |
713 | 713 | |
714 | - $object->sendtoid=0; |
|
714 | + $object->sendtoid=0; |
|
715 | 715 | } |
716 | 716 | |
717 | 717 | // Projects |
@@ -720,11 +720,11 @@ discard block |
||
720 | 720 | // Load translation files required by the page |
721 | 721 | $langs->loadLangs(array("agenda","other","projects")); |
722 | 722 | |
723 | - if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ProjectCreatedInDolibarr",$object->ref); |
|
724 | - $object->actionmsg=$langs->transnoentities("ProjectCreatedInDolibarr",$object->ref); |
|
725 | - $object->actionmsg.="\n".$langs->transnoentities("Project").': '.$object->ref; |
|
723 | + if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ProjectCreatedInDolibarr",$object->ref); |
|
724 | + $object->actionmsg=$langs->transnoentities("ProjectCreatedInDolibarr",$object->ref); |
|
725 | + $object->actionmsg.="\n".$langs->transnoentities("Project").': '.$object->ref; |
|
726 | 726 | |
727 | - $object->sendtoid=0; |
|
727 | + $object->sendtoid=0; |
|
728 | 728 | } |
729 | 729 | elseif($action == 'PROJECT_VALIDATE') |
730 | 730 | { |
@@ -749,74 +749,74 @@ discard block |
||
749 | 749 | $object->sendtoid=0; |
750 | 750 | } |
751 | 751 | |
752 | - // Project tasks |
|
753 | - elseif($action == 'TASK_CREATE') |
|
754 | - { |
|
752 | + // Project tasks |
|
753 | + elseif($action == 'TASK_CREATE') |
|
754 | + { |
|
755 | 755 | // Load translation files required by the page |
756 | 756 | $langs->loadLangs(array("agenda","other","projects")); |
757 | 757 | |
758 | - if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("TaskCreatedInDolibarr",$object->ref); |
|
759 | - $object->actionmsg=$langs->transnoentities("TaskCreatedInDolibarr",$object->ref); |
|
760 | - $object->actionmsg.="\n".$langs->transnoentities("Task").': '.$object->ref; |
|
758 | + if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("TaskCreatedInDolibarr",$object->ref); |
|
759 | + $object->actionmsg=$langs->transnoentities("TaskCreatedInDolibarr",$object->ref); |
|
760 | + $object->actionmsg.="\n".$langs->transnoentities("Task").': '.$object->ref; |
|
761 | 761 | |
762 | - $object->sendtoid=0; |
|
763 | - } |
|
762 | + $object->sendtoid=0; |
|
763 | + } |
|
764 | 764 | |
765 | - elseif($action == 'TASK_MODIFY') |
|
766 | - { |
|
765 | + elseif($action == 'TASK_MODIFY') |
|
766 | + { |
|
767 | 767 | // Load translation files required by the page |
768 | 768 | $langs->loadLangs(array("agenda","other","projects")); |
769 | 769 | |
770 | - if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("TaskModifiedInDolibarr",$object->ref); |
|
771 | - $object->actionmsg=$langs->transnoentities("TaskModifieddInDolibarr",$object->ref); |
|
772 | - $object->actionmsg.="\n".$langs->transnoentities("Task").': '.$object->ref; |
|
770 | + if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("TaskModifiedInDolibarr",$object->ref); |
|
771 | + $object->actionmsg=$langs->transnoentities("TaskModifieddInDolibarr",$object->ref); |
|
772 | + $object->actionmsg.="\n".$langs->transnoentities("Task").': '.$object->ref; |
|
773 | 773 | |
774 | - $object->sendtoid=0; |
|
775 | - } |
|
774 | + $object->sendtoid=0; |
|
775 | + } |
|
776 | 776 | |
777 | - elseif($action == 'TASK_DELETE') |
|
778 | - { |
|
777 | + elseif($action == 'TASK_DELETE') |
|
778 | + { |
|
779 | 779 | // Load translation files required by the page |
780 | 780 | $langs->loadLangs(array("agenda","other","projects")); |
781 | 781 | |
782 | - if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("TaskDeletedInDolibarr",$object->ref); |
|
783 | - $object->actionmsg=$langs->transnoentities("TaskDeletedInDolibarr",$object->ref); |
|
784 | - $object->actionmsg.="\n".$langs->transnoentities("Task").': '.$object->ref; |
|
785 | - |
|
786 | - $object->sendtoid=0; |
|
787 | - } |
|
788 | - // TODO Merge all previous cases into this generic one |
|
789 | - else // $action = TICKET_CREATE, TICKET_MODIFY, TICKET_DELETE, ... |
|
790 | - { |
|
791 | - // Note: We are here only if $conf->global->MAIN_AGENDA_ACTIONAUTO_action is on (tested at begining of this function) |
|
792 | - // Load translation files required by the page |
|
782 | + if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("TaskDeletedInDolibarr",$object->ref); |
|
783 | + $object->actionmsg=$langs->transnoentities("TaskDeletedInDolibarr",$object->ref); |
|
784 | + $object->actionmsg.="\n".$langs->transnoentities("Task").': '.$object->ref; |
|
785 | + |
|
786 | + $object->sendtoid=0; |
|
787 | + } |
|
788 | + // TODO Merge all previous cases into this generic one |
|
789 | + else // $action = TICKET_CREATE, TICKET_MODIFY, TICKET_DELETE, ... |
|
790 | + { |
|
791 | + // Note: We are here only if $conf->global->MAIN_AGENDA_ACTIONAUTO_action is on (tested at begining of this function) |
|
792 | + // Load translation files required by the page |
|
793 | 793 | $langs->loadLangs(array("agenda","other")); |
794 | 794 | |
795 | - if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities($action."InDolibarr",$object->ref); |
|
796 | - if (empty($object->actionmsg)) $object->actionmsg=$langs->transnoentities($action."InDolibarr",$object->ref); |
|
795 | + if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities($action."InDolibarr",$object->ref); |
|
796 | + if (empty($object->actionmsg)) $object->actionmsg=$langs->transnoentities($action."InDolibarr",$object->ref); |
|
797 | 797 | |
798 | - $object->sendtoid=0; |
|
799 | - } |
|
798 | + $object->sendtoid=0; |
|
799 | + } |
|
800 | 800 | |
801 | - $object->actionmsg = $langs->transnoentities("Author").': '.$user->login."\n".$object->actionmsg; |
|
801 | + $object->actionmsg = $langs->transnoentities("Author").': '.$user->login."\n".$object->actionmsg; |
|
802 | 802 | |
803 | - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
803 | + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
804 | 804 | |
805 | 805 | // Add entry in event table |
806 | - $now=dol_now(); |
|
806 | + $now=dol_now(); |
|
807 | 807 | |
808 | - if (isset($_SESSION['listofnames-'.$object->trackid])) |
|
809 | - { |
|
810 | - $attachs=$_SESSION['listofnames-'.$object->trackid]; |
|
811 | - if ($attachs && strpos($action,'SENTBYMAIL')) |
|
812 | - { |
|
808 | + if (isset($_SESSION['listofnames-'.$object->trackid])) |
|
809 | + { |
|
810 | + $attachs=$_SESSION['listofnames-'.$object->trackid]; |
|
811 | + if ($attachs && strpos($action,'SENTBYMAIL')) |
|
812 | + { |
|
813 | 813 | $object->actionmsg=dol_concatdesc($object->actionmsg, "\n".$langs->transnoentities("AttachedFiles").': '.$attachs); |
814 | - } |
|
815 | - } |
|
814 | + } |
|
815 | + } |
|
816 | 816 | |
817 | 817 | require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; |
818 | 818 | require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; |
819 | - $contactforaction=new Contact($this->db); |
|
819 | + $contactforaction=new Contact($this->db); |
|
820 | 820 | $societeforaction=new Societe($this->db); |
821 | 821 | // Set contactforaction if there is only 1 contact. |
822 | 822 | if (is_array($object->sendtoid)) |
@@ -838,87 +838,87 @@ discard block |
||
838 | 838 | $elementtype = $object->element; |
839 | 839 | if ($object->element == 'subscription') |
840 | 840 | { |
841 | - $elementid = $object->fk_adherent; |
|
842 | - $elementtype = 'member'; |
|
841 | + $elementid = $object->fk_adherent; |
|
842 | + $elementtype = 'member'; |
|
843 | 843 | } |
844 | 844 | //var_dump($societeforaction);var_dump($contactforaction);exit; |
845 | 845 | |
846 | - // Insertion action |
|
847 | - require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php'; |
|
848 | - $actioncomm = new ActionComm($this->db); |
|
849 | - $actioncomm->type_code = $object->actiontypecode; // Type of event ('AC_OTH', 'AC_OTH_AUTO', 'AC_XXX'...) |
|
850 | - $actioncomm->code = 'AC_'.$action; |
|
851 | - $actioncomm->label = $object->actionmsg2; |
|
852 | - $actioncomm->note = $object->actionmsg; // TODO Replace with ($actioncomm->email_msgid ? $object->email_content : $object->actionmsg) |
|
853 | - $actioncomm->fk_project = $projectid; |
|
854 | - $actioncomm->datep = $now; |
|
855 | - $actioncomm->datef = $now; |
|
856 | - $actioncomm->durationp = 0; |
|
857 | - $actioncomm->punctual = 1; |
|
858 | - $actioncomm->percentage = -1; // Not applicable |
|
859 | - $actioncomm->societe = $societeforaction; |
|
860 | - $actioncomm->contact = $contactforaction; |
|
861 | - $actioncomm->socid = $societeforaction->id; |
|
862 | - $actioncomm->contactid = $contactforaction->id; |
|
863 | - $actioncomm->authorid = $user->id; // User saving action |
|
864 | - $actioncomm->userownerid = $user->id; // Owner of action |
|
846 | + // Insertion action |
|
847 | + require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php'; |
|
848 | + $actioncomm = new ActionComm($this->db); |
|
849 | + $actioncomm->type_code = $object->actiontypecode; // Type of event ('AC_OTH', 'AC_OTH_AUTO', 'AC_XXX'...) |
|
850 | + $actioncomm->code = 'AC_'.$action; |
|
851 | + $actioncomm->label = $object->actionmsg2; |
|
852 | + $actioncomm->note = $object->actionmsg; // TODO Replace with ($actioncomm->email_msgid ? $object->email_content : $object->actionmsg) |
|
853 | + $actioncomm->fk_project = $projectid; |
|
854 | + $actioncomm->datep = $now; |
|
855 | + $actioncomm->datef = $now; |
|
856 | + $actioncomm->durationp = 0; |
|
857 | + $actioncomm->punctual = 1; |
|
858 | + $actioncomm->percentage = -1; // Not applicable |
|
859 | + $actioncomm->societe = $societeforaction; |
|
860 | + $actioncomm->contact = $contactforaction; |
|
861 | + $actioncomm->socid = $societeforaction->id; |
|
862 | + $actioncomm->contactid = $contactforaction->id; |
|
863 | + $actioncomm->authorid = $user->id; // User saving action |
|
864 | + $actioncomm->userownerid = $user->id; // Owner of action |
|
865 | 865 | // Fields defined when action is an email (content should be into object->actionmsg to be added into note, subject into object->actionms2 to be added into label) |
866 | - $actioncomm->email_msgid = $object->email_msgid; |
|
867 | - $actioncomm->email_from = $object->email_from; |
|
868 | - $actioncomm->email_sender = $object->email_sender; |
|
869 | - $actioncomm->email_to = $object->email_to; |
|
870 | - $actioncomm->email_tocc = $object->email_tocc; |
|
871 | - $actioncomm->email_tobcc = $object->email_tobcc; |
|
872 | - $actioncomm->email_subject = $object->email_subject; |
|
873 | - $actioncomm->errors_to = $object->errors_to; |
|
874 | - |
|
875 | - // Object linked (if link is for thirdparty, contact, project it is a recording error. We should not have links in link table |
|
876 | - // for such objects because there is already a dedicated field into table llx_actioncomm. |
|
877 | - if (! in_array($elementtype, array('societe','contact','project'))) |
|
878 | - { |
|
879 | - $actioncomm->fk_element = $elementid; |
|
880 | - $actioncomm->elementtype = $elementtype; |
|
881 | - } |
|
882 | - |
|
883 | - if (property_exists($object,'attachedfiles') && is_array($object->attachedfiles) && count($object->attachedfiles)>0) { |
|
884 | - $actioncomm->attachedfiles=$object->attachedfiles; |
|
885 | - } |
|
886 | - if (property_exists($object,'sendtouserid') && is_array($object->sendtouserid) && count($object->sendtouserid)>0) { |
|
887 | - $actioncomm->userassigned=$object->sendtouserid; |
|
888 | - } |
|
889 | - |
|
890 | - $ret=$actioncomm->create($user); // User creating action |
|
891 | - |
|
892 | - if ($ret > 0 && $conf->global->MAIN_COPY_FILE_IN_EVENT_AUTO) |
|
893 | - { |
|
894 | - if (is_array($object->attachedfiles) && array_key_exists('paths',$object->attachedfiles) && count($object->attachedfiles['paths'])>0) { |
|
895 | - foreach($object->attachedfiles['paths'] as $key=>$filespath) { |
|
896 | - $srcfile = $filespath; |
|
897 | - $destdir = $conf->agenda->dir_output . '/' . $ret; |
|
898 | - $destfile = $destdir . '/' . $object->attachedfiles['names'][$key]; |
|
899 | - if (dol_mkdir($destdir) >= 0) { |
|
900 | - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
901 | - dol_copy($srcfile, $destfile); |
|
902 | - } |
|
903 | - } |
|
904 | - } |
|
905 | - } |
|
906 | - |
|
907 | - unset($object->actionmsg); unset($object->actionmsg2); unset($object->actiontypecode); // When several action are called on same object, we must be sure to not reuse value of first action. |
|
908 | - |
|
909 | - if ($ret > 0) |
|
910 | - { |
|
911 | - $_SESSION['LAST_ACTION_CREATED'] = $ret; |
|
912 | - return 1; |
|
913 | - } |
|
914 | - else |
|
915 | - { |
|
866 | + $actioncomm->email_msgid = $object->email_msgid; |
|
867 | + $actioncomm->email_from = $object->email_from; |
|
868 | + $actioncomm->email_sender = $object->email_sender; |
|
869 | + $actioncomm->email_to = $object->email_to; |
|
870 | + $actioncomm->email_tocc = $object->email_tocc; |
|
871 | + $actioncomm->email_tobcc = $object->email_tobcc; |
|
872 | + $actioncomm->email_subject = $object->email_subject; |
|
873 | + $actioncomm->errors_to = $object->errors_to; |
|
874 | + |
|
875 | + // Object linked (if link is for thirdparty, contact, project it is a recording error. We should not have links in link table |
|
876 | + // for such objects because there is already a dedicated field into table llx_actioncomm. |
|
877 | + if (! in_array($elementtype, array('societe','contact','project'))) |
|
878 | + { |
|
879 | + $actioncomm->fk_element = $elementid; |
|
880 | + $actioncomm->elementtype = $elementtype; |
|
881 | + } |
|
882 | + |
|
883 | + if (property_exists($object,'attachedfiles') && is_array($object->attachedfiles) && count($object->attachedfiles)>0) { |
|
884 | + $actioncomm->attachedfiles=$object->attachedfiles; |
|
885 | + } |
|
886 | + if (property_exists($object,'sendtouserid') && is_array($object->sendtouserid) && count($object->sendtouserid)>0) { |
|
887 | + $actioncomm->userassigned=$object->sendtouserid; |
|
888 | + } |
|
889 | + |
|
890 | + $ret=$actioncomm->create($user); // User creating action |
|
891 | + |
|
892 | + if ($ret > 0 && $conf->global->MAIN_COPY_FILE_IN_EVENT_AUTO) |
|
893 | + { |
|
894 | + if (is_array($object->attachedfiles) && array_key_exists('paths',$object->attachedfiles) && count($object->attachedfiles['paths'])>0) { |
|
895 | + foreach($object->attachedfiles['paths'] as $key=>$filespath) { |
|
896 | + $srcfile = $filespath; |
|
897 | + $destdir = $conf->agenda->dir_output . '/' . $ret; |
|
898 | + $destfile = $destdir . '/' . $object->attachedfiles['names'][$key]; |
|
899 | + if (dol_mkdir($destdir) >= 0) { |
|
900 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
901 | + dol_copy($srcfile, $destfile); |
|
902 | + } |
|
903 | + } |
|
904 | + } |
|
905 | + } |
|
906 | + |
|
907 | + unset($object->actionmsg); unset($object->actionmsg2); unset($object->actiontypecode); // When several action are called on same object, we must be sure to not reuse value of first action. |
|
908 | + |
|
909 | + if ($ret > 0) |
|
910 | + { |
|
911 | + $_SESSION['LAST_ACTION_CREATED'] = $ret; |
|
912 | + return 1; |
|
913 | + } |
|
914 | + else |
|
915 | + { |
|
916 | 916 | $error ="Failed to insert event : ".$actioncomm->error." ".join(',',$actioncomm->errors); |
917 | 917 | $this->error=$error; |
918 | 918 | $this->errors=$actioncomm->errors; |
919 | 919 | |
920 | 920 | dol_syslog("interface_modAgenda_ActionsAuto.class.php: ".$this->error, LOG_ERR); |
921 | 921 | return -1; |
922 | - } |
|
922 | + } |
|
923 | 923 | } |
924 | 924 | } |
@@ -29,33 +29,33 @@ discard block |
||
29 | 29 | */ |
30 | 30 | class InterfaceMailmanSpipsynchro extends DolibarrTriggers |
31 | 31 | { |
32 | - public $family = 'mailmanspip'; |
|
33 | - public $description = "Triggers of this module allows to synchronize Mailman an Spip."; |
|
34 | - |
|
35 | - /** |
|
36 | - * Version of the trigger |
|
37 | - * @var string |
|
38 | - */ |
|
39 | - public $version = self::VERSION_DOLIBARR; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var string Image of the trigger |
|
43 | - */ |
|
44 | - public $picto = 'technic'; |
|
45 | - |
|
46 | - /** |
|
47 | - * Function called when a Dolibarrr business event is done. |
|
48 | - * All functions "runTrigger" are triggered if file is inside directory htdocs/core/triggers or htdocs/module/code/triggers (and declared) |
|
49 | - * |
|
50 | - * @param string $action Event action code |
|
51 | - * @param Object $object Object |
|
52 | - * @param User $user Object user |
|
53 | - * @param Translate $langs Object langs |
|
54 | - * @param conf $conf Object conf |
|
55 | - * @return int <0 if KO, 0 if no triggered ran, >0 if OK |
|
56 | - */ |
|
57 | - public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf) |
|
58 | - { |
|
32 | + public $family = 'mailmanspip'; |
|
33 | + public $description = "Triggers of this module allows to synchronize Mailman an Spip."; |
|
34 | + |
|
35 | + /** |
|
36 | + * Version of the trigger |
|
37 | + * @var string |
|
38 | + */ |
|
39 | + public $version = self::VERSION_DOLIBARR; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var string Image of the trigger |
|
43 | + */ |
|
44 | + public $picto = 'technic'; |
|
45 | + |
|
46 | + /** |
|
47 | + * Function called when a Dolibarrr business event is done. |
|
48 | + * All functions "runTrigger" are triggered if file is inside directory htdocs/core/triggers or htdocs/module/code/triggers (and declared) |
|
49 | + * |
|
50 | + * @param string $action Event action code |
|
51 | + * @param Object $object Object |
|
52 | + * @param User $user Object user |
|
53 | + * @param Translate $langs Object langs |
|
54 | + * @param conf $conf Object conf |
|
55 | + * @return int <0 if KO, 0 if no triggered ran, >0 if OK |
|
56 | + */ |
|
57 | + public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf) |
|
58 | + { |
|
59 | 59 | if (empty($conf->mailmanspip->enabled)) return 0; // Module not active, we do nothing |
60 | 60 | |
61 | 61 | require_once DOL_DOCUMENT_ROOT."/mailmanspip/class/mailmanspip.class.php"; |
@@ -63,39 +63,39 @@ discard block |
||
63 | 63 | |
64 | 64 | if ($action == 'CATEGORY_LINK') |
65 | 65 | { |
66 | - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
67 | - |
|
68 | - // We add subscription if we change category (new category may means more mailing-list to subscribe) |
|
69 | - if (is_object($object->context['linkto']) && method_exists($object->context['linkto'], 'add_to_abo') && $object->context['linkto']->add_to_abo() < 0) |
|
70 | - { |
|
71 | - $this->error=$object->context['linkto']->error; |
|
72 | - $this->errors=$object->context['linkto']->errors; |
|
73 | - $return=-1; |
|
74 | - } |
|
75 | - else |
|
76 | - { |
|
77 | - $return=1; |
|
78 | - } |
|
79 | - |
|
80 | - return $return; |
|
66 | + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
67 | + |
|
68 | + // We add subscription if we change category (new category may means more mailing-list to subscribe) |
|
69 | + if (is_object($object->context['linkto']) && method_exists($object->context['linkto'], 'add_to_abo') && $object->context['linkto']->add_to_abo() < 0) |
|
70 | + { |
|
71 | + $this->error=$object->context['linkto']->error; |
|
72 | + $this->errors=$object->context['linkto']->errors; |
|
73 | + $return=-1; |
|
74 | + } |
|
75 | + else |
|
76 | + { |
|
77 | + $return=1; |
|
78 | + } |
|
79 | + |
|
80 | + return $return; |
|
81 | 81 | } |
82 | 82 | elseif ($action == 'CATEGORY_UNLINK') |
83 | 83 | { |
84 | - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
85 | - |
|
86 | - // We remove subscription if we change category (lessw category may means less mailing-list to subscribe) |
|
87 | - if (is_object($object->context['unlinkoff']) && method_exists($object->context['unlinkoff'], 'del_to_abo') && $object->context['unlinkoff']->del_to_abo() < 0) |
|
88 | - { |
|
89 | - $this->error=$object->context['unlinkoff']->error; |
|
90 | - $this->errors=$object->context['unlinkoff']->errors; |
|
91 | - $return=-1; |
|
92 | - } |
|
93 | - else |
|
94 | - { |
|
95 | - $return=1; |
|
96 | - } |
|
97 | - |
|
98 | - return $return; |
|
84 | + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
85 | + |
|
86 | + // We remove subscription if we change category (lessw category may means less mailing-list to subscribe) |
|
87 | + if (is_object($object->context['unlinkoff']) && method_exists($object->context['unlinkoff'], 'del_to_abo') && $object->context['unlinkoff']->del_to_abo() < 0) |
|
88 | + { |
|
89 | + $this->error=$object->context['unlinkoff']->error; |
|
90 | + $this->errors=$object->context['unlinkoff']->errors; |
|
91 | + $return=-1; |
|
92 | + } |
|
93 | + else |
|
94 | + { |
|
95 | + $return=1; |
|
96 | + } |
|
97 | + |
|
98 | + return $return; |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | // Members |
@@ -103,37 +103,37 @@ discard block |
||
103 | 103 | { |
104 | 104 | dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
105 | 105 | |
106 | - $return=0; |
|
106 | + $return=0; |
|
107 | 107 | // Add user into some linked tools (mailman, spip, etc...) |
108 | - if (($object->oldcopy->email != $object->email) || ($object->oldcopy->typeid != $object->typeid)) // TODO Do del/add also if type change |
|
109 | - { |
|
110 | - if (is_object($object->oldcopy) && ($object->oldcopy->email != $object->email)) // If email has changed we delete mailman subscription for old email |
|
111 | - { |
|
112 | - if ($object->oldcopy->del_to_abo() < 0) |
|
113 | - { |
|
114 | - if (! empty($object->oldcopy->error)) $this->error=$object->oldcopy->error; |
|
115 | - $this->errors=$object->oldcopy->errors; |
|
116 | - $return=-1; |
|
117 | - } |
|
118 | - else |
|
119 | - { |
|
120 | - $return=1; |
|
121 | - } |
|
122 | - } |
|
123 | - // We add subscription if new email or new type (new type may means more mailing-list to subscribe) |
|
124 | - if ($object->add_to_abo() < 0) |
|
125 | - { |
|
126 | - if (! empty($object->error)) $this->error=$object->error; |
|
127 | - $this->errors=$object->errors; |
|
128 | - $return=-1; |
|
129 | - } |
|
130 | - else |
|
131 | - { |
|
132 | - $return=1; |
|
133 | - } |
|
134 | - } |
|
135 | - |
|
136 | - return $return; |
|
108 | + if (($object->oldcopy->email != $object->email) || ($object->oldcopy->typeid != $object->typeid)) // TODO Do del/add also if type change |
|
109 | + { |
|
110 | + if (is_object($object->oldcopy) && ($object->oldcopy->email != $object->email)) // If email has changed we delete mailman subscription for old email |
|
111 | + { |
|
112 | + if ($object->oldcopy->del_to_abo() < 0) |
|
113 | + { |
|
114 | + if (! empty($object->oldcopy->error)) $this->error=$object->oldcopy->error; |
|
115 | + $this->errors=$object->oldcopy->errors; |
|
116 | + $return=-1; |
|
117 | + } |
|
118 | + else |
|
119 | + { |
|
120 | + $return=1; |
|
121 | + } |
|
122 | + } |
|
123 | + // We add subscription if new email or new type (new type may means more mailing-list to subscribe) |
|
124 | + if ($object->add_to_abo() < 0) |
|
125 | + { |
|
126 | + if (! empty($object->error)) $this->error=$object->error; |
|
127 | + $this->errors=$object->errors; |
|
128 | + $return=-1; |
|
129 | + } |
|
130 | + else |
|
131 | + { |
|
132 | + $return=1; |
|
133 | + } |
|
134 | + } |
|
135 | + |
|
136 | + return $return; |
|
137 | 137 | } |
138 | 138 | elseif ($action == 'MEMBER_RESILIATE' || $action == 'MEMBER_DELETE') |
139 | 139 | { |
@@ -141,20 +141,20 @@ discard block |
||
141 | 141 | |
142 | 142 | $return=0; |
143 | 143 | // Remove from external tools (mailman, spip, etc...) |
144 | - if ($object->del_to_abo() < 0) |
|
145 | - { |
|
146 | - if (! empty($object->error)) $this->error=$object->error; |
|
147 | - $this->errors=$object->errors; |
|
148 | - $return=-1; |
|
149 | - } |
|
150 | - else |
|
151 | - { |
|
152 | - $return=1; |
|
153 | - } |
|
154 | - |
|
155 | - return $return; |
|
144 | + if ($object->del_to_abo() < 0) |
|
145 | + { |
|
146 | + if (! empty($object->error)) $this->error=$object->error; |
|
147 | + $this->errors=$object->errors; |
|
148 | + $return=-1; |
|
149 | + } |
|
150 | + else |
|
151 | + { |
|
152 | + $return=1; |
|
153 | + } |
|
154 | + |
|
155 | + return $return; |
|
156 | 156 | } |
157 | 157 | |
158 | - return 0; |
|
158 | + return 0; |
|
159 | 159 | } |
160 | 160 | } |
@@ -32,39 +32,39 @@ discard block |
||
32 | 32 | |
33 | 33 | class InterfaceWorkflowManager extends DolibarrTriggers |
34 | 34 | { |
35 | - /** |
|
36 | - * @var string Image of the trigger |
|
37 | - */ |
|
38 | - public $picto = 'technic'; |
|
35 | + /** |
|
36 | + * @var string Image of the trigger |
|
37 | + */ |
|
38 | + public $picto = 'technic'; |
|
39 | 39 | |
40 | - public $family = 'core'; |
|
41 | - public $description = "Triggers of this module allows to manage workflows"; |
|
40 | + public $family = 'core'; |
|
41 | + public $description = "Triggers of this module allows to manage workflows"; |
|
42 | 42 | |
43 | - /** |
|
44 | - * Version of the trigger |
|
45 | - * @var string |
|
46 | - */ |
|
47 | - public $version = self::VERSION_DOLIBARR; |
|
43 | + /** |
|
44 | + * Version of the trigger |
|
45 | + * @var string |
|
46 | + */ |
|
47 | + public $version = self::VERSION_DOLIBARR; |
|
48 | 48 | |
49 | - /** |
|
50 | - * Function called when a Dolibarrr business event is done. |
|
51 | - * All functions "runTrigger" are triggered if file is inside directory htdocs/core/triggers or htdocs/module/code/triggers (and declared) |
|
52 | - * |
|
53 | - * @param string $action Event action code |
|
54 | - * @param Object $object Object |
|
55 | - * @param User $user Object user |
|
56 | - * @param Translate $langs Object langs |
|
57 | - * @param conf $conf Object conf |
|
58 | - * @return int <0 if KO, 0 if no triggered ran, >0 if OK |
|
59 | - */ |
|
60 | - public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf) |
|
49 | + /** |
|
50 | + * Function called when a Dolibarrr business event is done. |
|
51 | + * All functions "runTrigger" are triggered if file is inside directory htdocs/core/triggers or htdocs/module/code/triggers (and declared) |
|
52 | + * |
|
53 | + * @param string $action Event action code |
|
54 | + * @param Object $object Object |
|
55 | + * @param User $user Object user |
|
56 | + * @param Translate $langs Object langs |
|
57 | + * @param conf $conf Object conf |
|
58 | + * @return int <0 if KO, 0 if no triggered ran, >0 if OK |
|
59 | + */ |
|
60 | + public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf) |
|
61 | 61 | { |
62 | 62 | if (empty($conf->workflow->enabled)) return 0; // Module not active, we do nothing |
63 | 63 | |
64 | 64 | // Proposals to order |
65 | 65 | if ($action == 'PROPAL_CLOSE_SIGNED') |
66 | 66 | { |
67 | - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
67 | + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
68 | 68 | if (! empty($conf->commande->enabled) && ! empty($conf->global->WORKFLOW_PROPAL_AUTOCREATE_ORDER)) |
69 | 69 | { |
70 | 70 | include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; |
@@ -102,132 +102,132 @@ discard block |
||
102 | 102 | // Order classify billed proposal |
103 | 103 | if ($action == 'ORDER_CLASSIFY_BILLED') |
104 | 104 | { |
105 | - dol_syslog( "Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id ); |
|
106 | - if (! empty($conf->propal->enabled) && ! empty($conf->workflow->enabled) && ! empty($conf->global->WORKFLOW_ORDER_CLASSIFY_BILLED_PROPAL)) |
|
107 | - { |
|
108 | - $object->fetchObjectLinked('','propal',$object->id,$object->element); |
|
109 | - if (! empty($object->linkedObjects)) |
|
110 | - { |
|
111 | - $totalonlinkedelements=0; |
|
112 | - foreach($object->linkedObjects['propal'] as $element) |
|
113 | - { |
|
114 | - if ($element->statut == Propal::STATUS_SIGNED || $element->statut == Propal::STATUS_BILLED) $totalonlinkedelements += $element->total_ht; |
|
115 | - } |
|
116 | - dol_syslog( "Amount of linked proposals = ".$totalonlinkedelements.", of order = ".$object->total_ht.", egality is ".($totalonlinkedelements == $object->total_ht) ); |
|
117 | - if ( ($totalonlinkedelements == $object->total_ht) || (! empty($conf->global->WORKFLOW_CLASSIFY_IF_AMOUNTS_ARE_DIFFERENTS)) ) |
|
118 | - { |
|
119 | - foreach($object->linkedObjects['propal'] as $element) |
|
120 | - { |
|
121 | - $ret=$element->classifyBilled($user); |
|
122 | - } |
|
123 | - } |
|
124 | - } |
|
125 | - return $ret; |
|
126 | - } |
|
105 | + dol_syslog( "Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id ); |
|
106 | + if (! empty($conf->propal->enabled) && ! empty($conf->workflow->enabled) && ! empty($conf->global->WORKFLOW_ORDER_CLASSIFY_BILLED_PROPAL)) |
|
107 | + { |
|
108 | + $object->fetchObjectLinked('','propal',$object->id,$object->element); |
|
109 | + if (! empty($object->linkedObjects)) |
|
110 | + { |
|
111 | + $totalonlinkedelements=0; |
|
112 | + foreach($object->linkedObjects['propal'] as $element) |
|
113 | + { |
|
114 | + if ($element->statut == Propal::STATUS_SIGNED || $element->statut == Propal::STATUS_BILLED) $totalonlinkedelements += $element->total_ht; |
|
115 | + } |
|
116 | + dol_syslog( "Amount of linked proposals = ".$totalonlinkedelements.", of order = ".$object->total_ht.", egality is ".($totalonlinkedelements == $object->total_ht) ); |
|
117 | + if ( ($totalonlinkedelements == $object->total_ht) || (! empty($conf->global->WORKFLOW_CLASSIFY_IF_AMOUNTS_ARE_DIFFERENTS)) ) |
|
118 | + { |
|
119 | + foreach($object->linkedObjects['propal'] as $element) |
|
120 | + { |
|
121 | + $ret=$element->classifyBilled($user); |
|
122 | + } |
|
123 | + } |
|
124 | + } |
|
125 | + return $ret; |
|
126 | + } |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | // classify billed order & billed propososal |
130 | 130 | if ($action == 'BILL_VALIDATE') |
131 | 131 | { |
132 | - dol_syslog( "Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id ); |
|
132 | + dol_syslog( "Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id ); |
|
133 | 133 | |
134 | - // First classify billed the order to allow the proposal classify process |
|
135 | - if (! empty($conf->commande->enabled) && ! empty($conf->workflow->enabled) && ! empty($conf->global->WORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_ORDER)) |
|
136 | - { |
|
137 | - $object->fetchObjectLinked('','commande',$object->id,$object->element); |
|
138 | - if (! empty($object->linkedObjects)) |
|
139 | - { |
|
140 | - $totalonlinkedelements=0; |
|
141 | - foreach($object->linkedObjects['commande'] as $element) |
|
142 | - { |
|
143 | - if ($element->statut == Commande::STATUS_VALIDATED || $element->statut == Commande::STATUS_SHIPMENTONPROCESS || $element->statut == Commande::STATUS_CLOSED) $totalonlinkedelements += $element->total_ht; |
|
144 | - } |
|
145 | - dol_syslog( "Amount of linked orders = ".$totalonlinkedelements.", of invoice = ".$object->total_ht.", egality is ".($totalonlinkedelements == $object->total_ht) ); |
|
146 | - if ( ($totalonlinkedelements == $object->total_ht) || (! empty($conf->global->WORKFLOW_CLASSIFY_IF_AMOUNTS_ARE_DIFFERENTS)) ) |
|
147 | - { |
|
148 | - foreach($object->linkedObjects['commande'] as $element) |
|
149 | - { |
|
150 | - $ret=$element->classifyBilled($user); |
|
151 | - } |
|
152 | - } |
|
153 | - } |
|
154 | - return $ret; |
|
155 | - } |
|
134 | + // First classify billed the order to allow the proposal classify process |
|
135 | + if (! empty($conf->commande->enabled) && ! empty($conf->workflow->enabled) && ! empty($conf->global->WORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_ORDER)) |
|
136 | + { |
|
137 | + $object->fetchObjectLinked('','commande',$object->id,$object->element); |
|
138 | + if (! empty($object->linkedObjects)) |
|
139 | + { |
|
140 | + $totalonlinkedelements=0; |
|
141 | + foreach($object->linkedObjects['commande'] as $element) |
|
142 | + { |
|
143 | + if ($element->statut == Commande::STATUS_VALIDATED || $element->statut == Commande::STATUS_SHIPMENTONPROCESS || $element->statut == Commande::STATUS_CLOSED) $totalonlinkedelements += $element->total_ht; |
|
144 | + } |
|
145 | + dol_syslog( "Amount of linked orders = ".$totalonlinkedelements.", of invoice = ".$object->total_ht.", egality is ".($totalonlinkedelements == $object->total_ht) ); |
|
146 | + if ( ($totalonlinkedelements == $object->total_ht) || (! empty($conf->global->WORKFLOW_CLASSIFY_IF_AMOUNTS_ARE_DIFFERENTS)) ) |
|
147 | + { |
|
148 | + foreach($object->linkedObjects['commande'] as $element) |
|
149 | + { |
|
150 | + $ret=$element->classifyBilled($user); |
|
151 | + } |
|
152 | + } |
|
153 | + } |
|
154 | + return $ret; |
|
155 | + } |
|
156 | 156 | |
157 | - // Second classify billed the proposal. |
|
158 | - if (! empty($conf->propal->enabled) && ! empty($conf->workflow->enabled) && ! empty($conf->global->WORKFLOW_INVOICE_CLASSIFY_BILLED_PROPAL)) |
|
159 | - { |
|
160 | - $object->fetchObjectLinked('','propal',$object->id,$object->element); |
|
161 | - if (! empty($object->linkedObjects)) |
|
162 | - { |
|
163 | - $totalonlinkedelements=0; |
|
164 | - foreach($object->linkedObjects['propal'] as $element) |
|
165 | - { |
|
166 | - if ($element->statut == Propal::STATUS_SIGNED || $element->statut == Propal::STATUS_BILLED) $totalonlinkedelements += $element->total_ht; |
|
167 | - } |
|
168 | - dol_syslog( "Amount of linked proposals = ".$totalonlinkedelements.", of invoice = ".$object->total_ht.", egality is ".($totalonlinkedelements == $object->total_ht) ); |
|
169 | - if ( ($totalonlinkedelements == $object->total_ht) || (! empty($conf->global->WORKFLOW_CLASSIFY_IF_AMOUNTS_ARE_DIFFERENTS)) ) |
|
170 | - { |
|
171 | - foreach($object->linkedObjects['propal'] as $element) |
|
172 | - { |
|
173 | - $ret=$element->classifyBilled($user); |
|
174 | - } |
|
175 | - } |
|
176 | - } |
|
177 | - return $ret; |
|
178 | - } |
|
157 | + // Second classify billed the proposal. |
|
158 | + if (! empty($conf->propal->enabled) && ! empty($conf->workflow->enabled) && ! empty($conf->global->WORKFLOW_INVOICE_CLASSIFY_BILLED_PROPAL)) |
|
159 | + { |
|
160 | + $object->fetchObjectLinked('','propal',$object->id,$object->element); |
|
161 | + if (! empty($object->linkedObjects)) |
|
162 | + { |
|
163 | + $totalonlinkedelements=0; |
|
164 | + foreach($object->linkedObjects['propal'] as $element) |
|
165 | + { |
|
166 | + if ($element->statut == Propal::STATUS_SIGNED || $element->statut == Propal::STATUS_BILLED) $totalonlinkedelements += $element->total_ht; |
|
167 | + } |
|
168 | + dol_syslog( "Amount of linked proposals = ".$totalonlinkedelements.", of invoice = ".$object->total_ht.", egality is ".($totalonlinkedelements == $object->total_ht) ); |
|
169 | + if ( ($totalonlinkedelements == $object->total_ht) || (! empty($conf->global->WORKFLOW_CLASSIFY_IF_AMOUNTS_ARE_DIFFERENTS)) ) |
|
170 | + { |
|
171 | + foreach($object->linkedObjects['propal'] as $element) |
|
172 | + { |
|
173 | + $ret=$element->classifyBilled($user); |
|
174 | + } |
|
175 | + } |
|
176 | + } |
|
177 | + return $ret; |
|
178 | + } |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | // classify billed order & billed propososal |
182 | 182 | if ($action == 'BILL_SUPPLIER_VALIDATE') |
183 | 183 | { |
184 | - dol_syslog( "Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id ); |
|
184 | + dol_syslog( "Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id ); |
|
185 | 185 | |
186 | - // First classify billed the order to allow the proposal classify process |
|
187 | - if (! empty($conf->fournisseur->commande->enabled) && ! empty($conf->global->WORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_SUPPLIER_ORDER)) |
|
188 | - { |
|
189 | - $object->fetchObjectLinked('','order_supplier',$object->id,$object->element); |
|
190 | - if (! empty($object->linkedObjects)) |
|
191 | - { |
|
192 | - $totalonlinkedelements=0; |
|
193 | - foreach($object->linkedObjects['order_supplier'] as $element) |
|
194 | - { |
|
195 | - if ($element->statut == CommandeFournisseur::STATUS_ACCEPTED || $element->statut == CommandeFournisseur::STATUS_ORDERSENT || $element->statut == CommandeFournisseur::STATUS_RECEIVED_PARTIALLY || $element->statut == CommandeFournisseur::STATUS_RECEIVED_COMPLETELY) $totalonlinkedelements += $element->total_ht; |
|
196 | - } |
|
197 | - dol_syslog( "Amount of linked orders = ".$totalonlinkedelements.", of invoice = ".$object->total_ht.", egality is ".($totalonlinkedelements == $object->total_ht) ); |
|
198 | - if ( ($totalonlinkedelements == $object->total_ht) || (! empty($conf->global->WORKFLOW_CLASSIFY_IF_AMOUNTS_ARE_DIFFERENTS)) ) |
|
199 | - { |
|
200 | - foreach($object->linkedObjects['order_supplier'] as $element) |
|
201 | - { |
|
202 | - $ret=$element->classifyBilled($user); |
|
203 | - } |
|
204 | - } |
|
205 | - } |
|
206 | - return $ret; |
|
207 | - } |
|
186 | + // First classify billed the order to allow the proposal classify process |
|
187 | + if (! empty($conf->fournisseur->commande->enabled) && ! empty($conf->global->WORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_SUPPLIER_ORDER)) |
|
188 | + { |
|
189 | + $object->fetchObjectLinked('','order_supplier',$object->id,$object->element); |
|
190 | + if (! empty($object->linkedObjects)) |
|
191 | + { |
|
192 | + $totalonlinkedelements=0; |
|
193 | + foreach($object->linkedObjects['order_supplier'] as $element) |
|
194 | + { |
|
195 | + if ($element->statut == CommandeFournisseur::STATUS_ACCEPTED || $element->statut == CommandeFournisseur::STATUS_ORDERSENT || $element->statut == CommandeFournisseur::STATUS_RECEIVED_PARTIALLY || $element->statut == CommandeFournisseur::STATUS_RECEIVED_COMPLETELY) $totalonlinkedelements += $element->total_ht; |
|
196 | + } |
|
197 | + dol_syslog( "Amount of linked orders = ".$totalonlinkedelements.", of invoice = ".$object->total_ht.", egality is ".($totalonlinkedelements == $object->total_ht) ); |
|
198 | + if ( ($totalonlinkedelements == $object->total_ht) || (! empty($conf->global->WORKFLOW_CLASSIFY_IF_AMOUNTS_ARE_DIFFERENTS)) ) |
|
199 | + { |
|
200 | + foreach($object->linkedObjects['order_supplier'] as $element) |
|
201 | + { |
|
202 | + $ret=$element->classifyBilled($user); |
|
203 | + } |
|
204 | + } |
|
205 | + } |
|
206 | + return $ret; |
|
207 | + } |
|
208 | 208 | |
209 | - // Second classify billed the proposal. |
|
210 | - if (! empty($conf->supplier_proposal->enabled) && ! empty($conf->global->WORKFLOW_INVOICE_CLASSIFY_BILLED_SUPPLIER_PROPOSAL)) |
|
211 | - { |
|
212 | - $object->fetchObjectLinked('','supplier_proposal',$object->id,$object->element); |
|
213 | - if (! empty($object->linkedObjects)) |
|
214 | - { |
|
215 | - $totalonlinkedelements=0; |
|
216 | - foreach($object->linkedObjects['supplier_proposal'] as $element) |
|
217 | - { |
|
218 | - if ($element->statut == SupplierProposal::STATUS_SIGNED || $element->statut == SupplierProposal::STATUS_BILLED) $totalonlinkedelements += $element->total_ht; |
|
219 | - } |
|
220 | - dol_syslog( "Amount of linked supplier proposals = ".$totalonlinkedelements.", of supplier invoice = ".$object->total_ht.", egality is ".($totalonlinkedelements == $object->total_ht) ); |
|
221 | - if ( ($totalonlinkedelements == $object->total_ht) || (! empty($conf->global->WORKFLOW_CLASSIFY_IF_AMOUNTS_ARE_DIFFERENTS)) ) |
|
222 | - { |
|
223 | - foreach($object->linkedObjects['supplier_proposal'] as $element) |
|
224 | - { |
|
225 | - $ret=$element->classifyBilled($user); |
|
226 | - } |
|
227 | - } |
|
228 | - } |
|
229 | - return $ret; |
|
230 | - } |
|
209 | + // Second classify billed the proposal. |
|
210 | + if (! empty($conf->supplier_proposal->enabled) && ! empty($conf->global->WORKFLOW_INVOICE_CLASSIFY_BILLED_SUPPLIER_PROPOSAL)) |
|
211 | + { |
|
212 | + $object->fetchObjectLinked('','supplier_proposal',$object->id,$object->element); |
|
213 | + if (! empty($object->linkedObjects)) |
|
214 | + { |
|
215 | + $totalonlinkedelements=0; |
|
216 | + foreach($object->linkedObjects['supplier_proposal'] as $element) |
|
217 | + { |
|
218 | + if ($element->statut == SupplierProposal::STATUS_SIGNED || $element->statut == SupplierProposal::STATUS_BILLED) $totalonlinkedelements += $element->total_ht; |
|
219 | + } |
|
220 | + dol_syslog( "Amount of linked supplier proposals = ".$totalonlinkedelements.", of supplier invoice = ".$object->total_ht.", egality is ".($totalonlinkedelements == $object->total_ht) ); |
|
221 | + if ( ($totalonlinkedelements == $object->total_ht) || (! empty($conf->global->WORKFLOW_CLASSIFY_IF_AMOUNTS_ARE_DIFFERENTS)) ) |
|
222 | + { |
|
223 | + foreach($object->linkedObjects['supplier_proposal'] as $element) |
|
224 | + { |
|
225 | + $ret=$element->classifyBilled($user); |
|
226 | + } |
|
227 | + } |
|
228 | + } |
|
229 | + return $ret; |
|
230 | + } |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | // Invoice classify billed order |
@@ -260,88 +260,88 @@ discard block |
||
260 | 260 | |
261 | 261 | if ($action=='SHIPPING_VALIDATE') |
262 | 262 | { |
263 | - dol_syslog( "Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id ); |
|
263 | + dol_syslog( "Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id ); |
|
264 | 264 | |
265 | - if (! empty($conf->commande->enabled) && ! empty($conf->expedition->enabled) && ! empty($conf->workflow->enabled) && ! empty($conf->global->WORKFLOW_ORDER_CLASSIFY_SHIPPED_SHIPPING)) |
|
266 | - { |
|
267 | - $qtyshipped=array(); |
|
268 | - $qtyordred=array(); |
|
269 | - require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; |
|
265 | + if (! empty($conf->commande->enabled) && ! empty($conf->expedition->enabled) && ! empty($conf->workflow->enabled) && ! empty($conf->global->WORKFLOW_ORDER_CLASSIFY_SHIPPED_SHIPPING)) |
|
266 | + { |
|
267 | + $qtyshipped=array(); |
|
268 | + $qtyordred=array(); |
|
269 | + require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; |
|
270 | 270 | |
271 | - //find all shippement on order origin |
|
272 | - $order = new Commande($this->db); |
|
273 | - $ret=$order->fetch($object->origin_id); |
|
274 | - if ($ret<0) { |
|
275 | - $this->error=$order->error; $this->errors=$order->errors; |
|
276 | - return $ret; |
|
277 | - } |
|
278 | - $ret=$order->fetchObjectLinked($order->id,'commande',null,'shipping'); |
|
279 | - if ($ret<0) { |
|
280 | - $this->error=$order->error; $this->errors=$order->errors; |
|
281 | - return $ret; |
|
282 | - } |
|
283 | - //Build array of quantity shipped by product for an order |
|
284 | - if (is_array($order->linkedObjects) && count($order->linkedObjects)>0) { |
|
285 | - foreach($order->linkedObjects as $type=>$shipping_array) { |
|
286 | - if ($type=='shipping' && is_array($shipping_array) && count($shipping_array)>0) { |
|
287 | - foreach ($shipping_array as $shipping) { |
|
288 | - if (is_array($shipping->lines) && count($shipping->lines)>0) { |
|
289 | - foreach($shipping->lines as $shippingline) { |
|
290 | - $qtyshipped[$shippingline->fk_product]+=$shippingline->qty; |
|
291 | - } |
|
292 | - } |
|
293 | - } |
|
294 | - } |
|
295 | - } |
|
296 | - } |
|
271 | + //find all shippement on order origin |
|
272 | + $order = new Commande($this->db); |
|
273 | + $ret=$order->fetch($object->origin_id); |
|
274 | + if ($ret<0) { |
|
275 | + $this->error=$order->error; $this->errors=$order->errors; |
|
276 | + return $ret; |
|
277 | + } |
|
278 | + $ret=$order->fetchObjectLinked($order->id,'commande',null,'shipping'); |
|
279 | + if ($ret<0) { |
|
280 | + $this->error=$order->error; $this->errors=$order->errors; |
|
281 | + return $ret; |
|
282 | + } |
|
283 | + //Build array of quantity shipped by product for an order |
|
284 | + if (is_array($order->linkedObjects) && count($order->linkedObjects)>0) { |
|
285 | + foreach($order->linkedObjects as $type=>$shipping_array) { |
|
286 | + if ($type=='shipping' && is_array($shipping_array) && count($shipping_array)>0) { |
|
287 | + foreach ($shipping_array as $shipping) { |
|
288 | + if (is_array($shipping->lines) && count($shipping->lines)>0) { |
|
289 | + foreach($shipping->lines as $shippingline) { |
|
290 | + $qtyshipped[$shippingline->fk_product]+=$shippingline->qty; |
|
291 | + } |
|
292 | + } |
|
293 | + } |
|
294 | + } |
|
295 | + } |
|
296 | + } |
|
297 | 297 | |
298 | - //Build array of quantity ordered by product |
|
299 | - if (is_array($order->lines) && count($order->lines)>0) { |
|
300 | - foreach($order->lines as $orderline) { |
|
301 | - $qtyordred[$orderline->fk_product]+=$orderline->qty; |
|
302 | - } |
|
303 | - } |
|
304 | - //dol_syslog(var_export($qtyordred,true),LOG_DEBUG); |
|
305 | - //dol_syslog(var_export($qtyshipped,true),LOG_DEBUG); |
|
306 | - //Compare array |
|
307 | - $diff_array=array_diff_assoc($qtyordred,$qtyshipped); |
|
308 | - if (count($diff_array)==0) { |
|
309 | - //No diff => mean everythings is shipped |
|
310 | - $ret=$object->setStatut(Commande::STATUS_CLOSED, $object->origin_id, $object->origin); |
|
311 | - if ($ret<0) { |
|
312 | - $this->error=$object->error; $this->errors=$object->errors; |
|
313 | - return $ret; |
|
314 | - } |
|
315 | - } |
|
316 | - } |
|
298 | + //Build array of quantity ordered by product |
|
299 | + if (is_array($order->lines) && count($order->lines)>0) { |
|
300 | + foreach($order->lines as $orderline) { |
|
301 | + $qtyordred[$orderline->fk_product]+=$orderline->qty; |
|
302 | + } |
|
303 | + } |
|
304 | + //dol_syslog(var_export($qtyordred,true),LOG_DEBUG); |
|
305 | + //dol_syslog(var_export($qtyshipped,true),LOG_DEBUG); |
|
306 | + //Compare array |
|
307 | + $diff_array=array_diff_assoc($qtyordred,$qtyshipped); |
|
308 | + if (count($diff_array)==0) { |
|
309 | + //No diff => mean everythings is shipped |
|
310 | + $ret=$object->setStatut(Commande::STATUS_CLOSED, $object->origin_id, $object->origin); |
|
311 | + if ($ret<0) { |
|
312 | + $this->error=$object->error; $this->errors=$object->errors; |
|
313 | + return $ret; |
|
314 | + } |
|
315 | + } |
|
316 | + } |
|
317 | 317 | } |
318 | - // classify billed reception |
|
318 | + // classify billed reception |
|
319 | 319 | if ($action == 'BILL_SUPPLIER_VALIDATE') |
320 | 320 | { |
321 | - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id, LOG_DEBUG); |
|
321 | + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id, LOG_DEBUG); |
|
322 | 322 | |
323 | - if (! empty($conf->reception->enabled) && ! empty($conf->global->WORKFLOW_BILL_ON_RECEPTION)) |
|
324 | - { |
|
325 | - $object->fetchObjectLinked('','reception',$object->id,$object->element); |
|
326 | - if (! empty($object->linkedObjects)) |
|
327 | - { |
|
328 | - $totalonlinkedelements=0; |
|
329 | - foreach($object->linkedObjects['reception'] as $element) |
|
330 | - { |
|
331 | - if ($element->statut == Reception::STATUS_VALIDATED) $totalonlinkedelements += $element->total_ht; |
|
332 | - } |
|
333 | - dol_syslog("Amount of linked proposals = ".$totalonlinkedelements.", of invoice = ".$object->total_ht.", egality is ".($totalonlinkedelements == $object->total_ht), LOG_DEBUG); |
|
334 | - if ($totalonlinkedelements == $object->total_ht) |
|
335 | - { |
|
336 | - foreach($object->linkedObjects['reception'] as $element) |
|
337 | - { |
|
338 | - $ret=$element->set_billed(); |
|
339 | - } |
|
340 | - } |
|
341 | - } |
|
342 | - return $ret; |
|
343 | - } |
|
344 | - } |
|
323 | + if (! empty($conf->reception->enabled) && ! empty($conf->global->WORKFLOW_BILL_ON_RECEPTION)) |
|
324 | + { |
|
325 | + $object->fetchObjectLinked('','reception',$object->id,$object->element); |
|
326 | + if (! empty($object->linkedObjects)) |
|
327 | + { |
|
328 | + $totalonlinkedelements=0; |
|
329 | + foreach($object->linkedObjects['reception'] as $element) |
|
330 | + { |
|
331 | + if ($element->statut == Reception::STATUS_VALIDATED) $totalonlinkedelements += $element->total_ht; |
|
332 | + } |
|
333 | + dol_syslog("Amount of linked proposals = ".$totalonlinkedelements.", of invoice = ".$object->total_ht.", egality is ".($totalonlinkedelements == $object->total_ht), LOG_DEBUG); |
|
334 | + if ($totalonlinkedelements == $object->total_ht) |
|
335 | + { |
|
336 | + foreach($object->linkedObjects['reception'] as $element) |
|
337 | + { |
|
338 | + $ret=$element->set_billed(); |
|
339 | + } |
|
340 | + } |
|
341 | + } |
|
342 | + return $ret; |
|
343 | + } |
|
344 | + } |
|
345 | 345 | |
346 | 346 | return 0; |
347 | 347 | } |
@@ -21,129 +21,129 @@ |
||
21 | 21 | abstract class DolibarrTriggers |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * Database handler |
|
26 | - * @var DoliDB |
|
27 | - */ |
|
28 | - protected $db; |
|
29 | - |
|
30 | - /** |
|
31 | - * Name of the trigger |
|
32 | - * @var mixed|string |
|
33 | - */ |
|
34 | - public $name = ''; |
|
35 | - |
|
36 | - /** |
|
37 | - * Description of the trigger |
|
38 | - * @var string |
|
39 | - */ |
|
40 | - public $description = ''; |
|
41 | - |
|
42 | - /** |
|
43 | - * Version of the trigger |
|
44 | - * @var string |
|
45 | - */ |
|
46 | - public $version = self::VERSION_DEVELOPMENT; |
|
47 | - |
|
48 | - /** |
|
49 | - * Image of the trigger |
|
50 | - * @var string |
|
51 | - */ |
|
52 | - public $picto = 'technic'; |
|
53 | - |
|
54 | - /** |
|
55 | - * Category of the trigger |
|
56 | - * @var string |
|
57 | - */ |
|
58 | - public $family = ''; |
|
59 | - |
|
60 | - /** |
|
61 | - * Error reported by the trigger |
|
62 | - * @var string |
|
63 | - * @deprecated Use $this->errors |
|
64 | - * @see errors |
|
65 | - */ |
|
66 | - public $error = ''; |
|
67 | - |
|
68 | - /** |
|
69 | - * Errors reported by the trigger |
|
70 | - * @var array |
|
71 | - */ |
|
72 | - public $errors = array(); |
|
73 | - |
|
74 | - const VERSION_DEVELOPMENT = 'development'; |
|
75 | - const VERSION_EXPERIMENTAL = 'experimental'; |
|
76 | - const VERSION_DOLIBARR = 'dolibarr'; |
|
77 | - |
|
78 | - /** |
|
79 | - * Constructor |
|
80 | - * |
|
81 | - * @param DoliDB $db Database handler |
|
82 | - */ |
|
24 | + /** |
|
25 | + * Database handler |
|
26 | + * @var DoliDB |
|
27 | + */ |
|
28 | + protected $db; |
|
29 | + |
|
30 | + /** |
|
31 | + * Name of the trigger |
|
32 | + * @var mixed|string |
|
33 | + */ |
|
34 | + public $name = ''; |
|
35 | + |
|
36 | + /** |
|
37 | + * Description of the trigger |
|
38 | + * @var string |
|
39 | + */ |
|
40 | + public $description = ''; |
|
41 | + |
|
42 | + /** |
|
43 | + * Version of the trigger |
|
44 | + * @var string |
|
45 | + */ |
|
46 | + public $version = self::VERSION_DEVELOPMENT; |
|
47 | + |
|
48 | + /** |
|
49 | + * Image of the trigger |
|
50 | + * @var string |
|
51 | + */ |
|
52 | + public $picto = 'technic'; |
|
53 | + |
|
54 | + /** |
|
55 | + * Category of the trigger |
|
56 | + * @var string |
|
57 | + */ |
|
58 | + public $family = ''; |
|
59 | + |
|
60 | + /** |
|
61 | + * Error reported by the trigger |
|
62 | + * @var string |
|
63 | + * @deprecated Use $this->errors |
|
64 | + * @see errors |
|
65 | + */ |
|
66 | + public $error = ''; |
|
67 | + |
|
68 | + /** |
|
69 | + * Errors reported by the trigger |
|
70 | + * @var array |
|
71 | + */ |
|
72 | + public $errors = array(); |
|
73 | + |
|
74 | + const VERSION_DEVELOPMENT = 'development'; |
|
75 | + const VERSION_EXPERIMENTAL = 'experimental'; |
|
76 | + const VERSION_DOLIBARR = 'dolibarr'; |
|
77 | + |
|
78 | + /** |
|
79 | + * Constructor |
|
80 | + * |
|
81 | + * @param DoliDB $db Database handler |
|
82 | + */ |
|
83 | 83 | public function __construct(DoliDB $db) |
84 | 84 | { |
85 | 85 | |
86 | - $this->db = $db; |
|
87 | - |
|
88 | - if (empty($this->name)) |
|
89 | - { |
|
90 | - $this->name = preg_replace('/^Interface/i', '', get_class($this)); |
|
91 | - } |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * Returns the name of the trigger file |
|
96 | - * |
|
97 | - * @return string |
|
98 | - */ |
|
99 | - public function getName() |
|
100 | - { |
|
101 | - return $this->name; |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Returns the description of trigger file |
|
106 | - * |
|
107 | - * @return string |
|
108 | - */ |
|
109 | - public function getDesc() |
|
110 | - { |
|
111 | - return $this->description; |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * Returns the version of the trigger file |
|
116 | - * |
|
117 | - * @return string Version of trigger file |
|
118 | - */ |
|
119 | - public function getVersion() |
|
120 | - { |
|
121 | - global $langs; |
|
122 | - $langs->load("admin"); |
|
123 | - |
|
124 | - if ($this->version == self::VERSION_DEVELOPMENT) { |
|
125 | - return $langs->trans("VersionDevelopment"); |
|
126 | - } elseif ($this->version == self::VERSION_EXPERIMENTAL) { |
|
127 | - return $langs->trans("VersionExperimental"); |
|
128 | - } elseif ($this->version == self::VERSION_DOLIBARR) { |
|
129 | - return DOL_VERSION; |
|
130 | - } elseif ($this->version) { |
|
131 | - return $this->version; |
|
132 | - } else { |
|
133 | - return $langs->trans("Unknown"); |
|
134 | - } |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * Function called when a Dolibarrr business event is done. |
|
139 | - * All functions "runTrigger" are triggered if file is inside directory htdocs/core/triggers or htdocs/module/code/triggers (and declared) |
|
140 | - * |
|
141 | - * @param string $action Event action code |
|
142 | - * @param Object $object Object |
|
143 | - * @param User $user Object user |
|
144 | - * @param Translate $langs Object langs |
|
145 | - * @param conf $conf Object conf |
|
146 | - * @return int <0 if KO, 0 if no triggered ran, >0 if OK |
|
147 | - */ |
|
148 | - abstract function runTrigger($action, $object, User $user, Translate $langs, Conf $conf); |
|
86 | + $this->db = $db; |
|
87 | + |
|
88 | + if (empty($this->name)) |
|
89 | + { |
|
90 | + $this->name = preg_replace('/^Interface/i', '', get_class($this)); |
|
91 | + } |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * Returns the name of the trigger file |
|
96 | + * |
|
97 | + * @return string |
|
98 | + */ |
|
99 | + public function getName() |
|
100 | + { |
|
101 | + return $this->name; |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Returns the description of trigger file |
|
106 | + * |
|
107 | + * @return string |
|
108 | + */ |
|
109 | + public function getDesc() |
|
110 | + { |
|
111 | + return $this->description; |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * Returns the version of the trigger file |
|
116 | + * |
|
117 | + * @return string Version of trigger file |
|
118 | + */ |
|
119 | + public function getVersion() |
|
120 | + { |
|
121 | + global $langs; |
|
122 | + $langs->load("admin"); |
|
123 | + |
|
124 | + if ($this->version == self::VERSION_DEVELOPMENT) { |
|
125 | + return $langs->trans("VersionDevelopment"); |
|
126 | + } elseif ($this->version == self::VERSION_EXPERIMENTAL) { |
|
127 | + return $langs->trans("VersionExperimental"); |
|
128 | + } elseif ($this->version == self::VERSION_DOLIBARR) { |
|
129 | + return DOL_VERSION; |
|
130 | + } elseif ($this->version) { |
|
131 | + return $this->version; |
|
132 | + } else { |
|
133 | + return $langs->trans("Unknown"); |
|
134 | + } |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * Function called when a Dolibarrr business event is done. |
|
139 | + * All functions "runTrigger" are triggered if file is inside directory htdocs/core/triggers or htdocs/module/code/triggers (and declared) |
|
140 | + * |
|
141 | + * @param string $action Event action code |
|
142 | + * @param Object $object Object |
|
143 | + * @param User $user Object user |
|
144 | + * @param Translate $langs Object langs |
|
145 | + * @param conf $conf Object conf |
|
146 | + * @return int <0 if KO, 0 if no triggered ran, >0 if OK |
|
147 | + */ |
|
148 | + abstract function runTrigger($action, $object, User $user, Translate $langs, Conf $conf); |
|
149 | 149 | } |
@@ -107,233 +107,233 @@ |
||
107 | 107 | */ |
108 | 108 | public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf) |
109 | 109 | { |
110 | - $ok = 0; |
|
111 | - |
|
112 | - switch ($action) { |
|
113 | - case 'TICKET_ASSIGNED': |
|
114 | - dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); |
|
115 | - |
|
116 | - if ($object->fk_user_assign > 0 && $object->fk_user_assign != $user->id) |
|
117 | - { |
|
118 | - $userstat = new User($this->db); |
|
119 | - $res = $userstat->fetch($object->fk_user_assign); |
|
120 | - if ($res > 0) |
|
121 | - { |
|
122 | - if (empty($conf->global->TICKET_DISABLE_ALL_MAILS)) |
|
123 | - { |
|
124 | - // Init to avoid errors |
|
125 | - $filepath = array(); |
|
126 | - $filename = array(); |
|
127 | - $mimetype = array(); |
|
128 | - |
|
129 | - // Send email to assigned user |
|
130 | - $subject = '[' . $conf->global->MAIN_INFO_SOCIETE_NOM . '] ' . $langs->transnoentities('TicketAssignedToYou'); |
|
131 | - $message = '<p>' . $langs->transnoentities('TicketAssignedEmailBody', $object->track_id, dolGetFirstLastname($user->firstname, $user->lastname)) . "</p>"; |
|
132 | - $message .= '<ul><li>' . $langs->trans('Title') . ' : ' . $object->subject . '</li>'; |
|
133 | - $message .= '<li>' . $langs->trans('Type') . ' : ' . $object->type_label . '</li>'; |
|
134 | - $message .= '<li>' . $langs->trans('Category') . ' : ' . $object->category_label . '</li>'; |
|
135 | - $message .= '<li>' . $langs->trans('Severity') . ' : ' . $object->severity_label . '</li>'; |
|
136 | - // Extrafields |
|
137 | - if (is_array($object->array_options) && count($object->array_options) > 0) { |
|
138 | - foreach ($object->array_options as $key => $value) { |
|
139 | - $message .= '<li>' . $langs->trans($key) . ' : ' . $value . '</li>'; |
|
140 | - } |
|
141 | - } |
|
142 | - |
|
143 | - $message .= '</ul>'; |
|
144 | - $message .= '<p>' . $langs->trans('Message') . ' : <br>' . $object->message . '</p>'; |
|
145 | - $message .= '<p><a href="' . dol_buildpath('/ticket/card.php', 2) . '?track_id=' . $object->track_id . '">' . $langs->trans('SeeThisTicketIntomanagementInterface') . '</a></p>'; |
|
146 | - |
|
147 | - $sendto = $userstat->email; |
|
148 | - $from = dolGetFirstLastname($user->firstname, $user->lastname) . '<' . $user->email . '>'; |
|
149 | - |
|
150 | - $message = dol_nl2br($message); |
|
151 | - |
|
152 | - if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) { |
|
153 | - $old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->MAIN_MAIL_AUTOCOPY_TO; |
|
154 | - $conf->global->MAIN_MAIL_AUTOCOPY_TO = ''; |
|
155 | - } |
|
156 | - include_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php'; |
|
157 | - $mailfile = new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, '', '', 0, -1); |
|
158 | - if ($mailfile->error) { |
|
159 | - setEventMessages($mailfile->error, $mailfile->errors, 'errors'); |
|
160 | - } else { |
|
161 | - $result = $mailfile->sendfile(); |
|
162 | - } |
|
163 | - if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) { |
|
164 | - $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO; |
|
165 | - } |
|
166 | - } |
|
110 | + $ok = 0; |
|
111 | + |
|
112 | + switch ($action) { |
|
113 | + case 'TICKET_ASSIGNED': |
|
114 | + dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); |
|
115 | + |
|
116 | + if ($object->fk_user_assign > 0 && $object->fk_user_assign != $user->id) |
|
117 | + { |
|
118 | + $userstat = new User($this->db); |
|
119 | + $res = $userstat->fetch($object->fk_user_assign); |
|
120 | + if ($res > 0) |
|
121 | + { |
|
122 | + if (empty($conf->global->TICKET_DISABLE_ALL_MAILS)) |
|
123 | + { |
|
124 | + // Init to avoid errors |
|
125 | + $filepath = array(); |
|
126 | + $filename = array(); |
|
127 | + $mimetype = array(); |
|
128 | + |
|
129 | + // Send email to assigned user |
|
130 | + $subject = '[' . $conf->global->MAIN_INFO_SOCIETE_NOM . '] ' . $langs->transnoentities('TicketAssignedToYou'); |
|
131 | + $message = '<p>' . $langs->transnoentities('TicketAssignedEmailBody', $object->track_id, dolGetFirstLastname($user->firstname, $user->lastname)) . "</p>"; |
|
132 | + $message .= '<ul><li>' . $langs->trans('Title') . ' : ' . $object->subject . '</li>'; |
|
133 | + $message .= '<li>' . $langs->trans('Type') . ' : ' . $object->type_label . '</li>'; |
|
134 | + $message .= '<li>' . $langs->trans('Category') . ' : ' . $object->category_label . '</li>'; |
|
135 | + $message .= '<li>' . $langs->trans('Severity') . ' : ' . $object->severity_label . '</li>'; |
|
136 | + // Extrafields |
|
137 | + if (is_array($object->array_options) && count($object->array_options) > 0) { |
|
138 | + foreach ($object->array_options as $key => $value) { |
|
139 | + $message .= '<li>' . $langs->trans($key) . ' : ' . $value . '</li>'; |
|
140 | + } |
|
141 | + } |
|
142 | + |
|
143 | + $message .= '</ul>'; |
|
144 | + $message .= '<p>' . $langs->trans('Message') . ' : <br>' . $object->message . '</p>'; |
|
145 | + $message .= '<p><a href="' . dol_buildpath('/ticket/card.php', 2) . '?track_id=' . $object->track_id . '">' . $langs->trans('SeeThisTicketIntomanagementInterface') . '</a></p>'; |
|
146 | + |
|
147 | + $sendto = $userstat->email; |
|
148 | + $from = dolGetFirstLastname($user->firstname, $user->lastname) . '<' . $user->email . '>'; |
|
149 | + |
|
150 | + $message = dol_nl2br($message); |
|
151 | + |
|
152 | + if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) { |
|
153 | + $old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->MAIN_MAIL_AUTOCOPY_TO; |
|
154 | + $conf->global->MAIN_MAIL_AUTOCOPY_TO = ''; |
|
155 | + } |
|
156 | + include_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php'; |
|
157 | + $mailfile = new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, '', '', 0, -1); |
|
158 | + if ($mailfile->error) { |
|
159 | + setEventMessages($mailfile->error, $mailfile->errors, 'errors'); |
|
160 | + } else { |
|
161 | + $result = $mailfile->sendfile(); |
|
162 | + } |
|
163 | + if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) { |
|
164 | + $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO; |
|
165 | + } |
|
166 | + } |
|
167 | 167 | |
168 | 168 | $ok = 1; |
169 | - } |
|
170 | - else |
|
171 | - { |
|
172 | - $this->error = $userstat->error; |
|
173 | - $this->errors = $userstat->errors; |
|
174 | - } |
|
175 | - } |
|
176 | - break; |
|
177 | - |
|
178 | - case 'TICKET_CREATE': |
|
179 | - dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); |
|
180 | - |
|
181 | - $langs->load('ticket'); |
|
182 | - |
|
183 | - $object->fetch('', $object->track_id); // Should be useless |
|
184 | - |
|
185 | - |
|
186 | - // Send email to notification email |
|
187 | - |
|
188 | - if (empty($conf->global->TICKET_DISABLE_ALL_MAILS) && empty($object->context['disableticketemail'])) |
|
189 | - { |
|
190 | - $sendto = $conf->global->TICKET_NOTIFICATION_EMAIL_TO; |
|
191 | - |
|
192 | - if ($sendto) |
|
193 | - { |
|
194 | - // Init to avoid errors |
|
195 | - $filepath = array(); |
|
196 | - $filename = array(); |
|
197 | - $mimetype = array(); |
|
198 | - |
|
199 | - /* Send email to admin */ |
|
200 | - $subject = '['.$conf->global->MAIN_INFO_SOCIETE_NOM.'] '.$langs->transnoentities('TicketNewEmailSubjectAdmin'); |
|
201 | - $message_admin= $langs->transnoentities('TicketNewEmailBodyAdmin', $object->track_id)."\n\n"; |
|
202 | - $message_admin.='<ul><li>'.$langs->trans('Title').' : '.$object->subject.'</li>'; |
|
203 | - $message_admin.='<li>'.$langs->trans('Type').' : '.$object->type_label.'</li>'; |
|
204 | - $message_admin.='<li>'.$langs->trans('Category').' : '.$object->category_label.'</li>'; |
|
205 | - $message_admin.='<li>'.$langs->trans('Severity').' : '.$object->severity_label.'</li>'; |
|
206 | - $message_admin.='<li>'.$langs->trans('From').' : '.( $object->email_from ? $object->email_from : ( $object->fk_user_create > 0 ? $langs->trans('Internal') : '') ).'</li>'; |
|
207 | - // Extrafields |
|
208 | - if (is_array($object->array_options) && count($object->array_options) > 0) { |
|
209 | - foreach ($object->array_options as $key => $value) { |
|
210 | - $message_admin.='<li>'.$langs->trans($key).' : '.$value.'</li>'; |
|
211 | - } |
|
212 | - } |
|
213 | - $message_admin.='</ul>'; |
|
214 | - |
|
215 | - if ($object->fk_soc > 0) { |
|
216 | - $object->fetch_thirdparty(); |
|
217 | - $message_admin.='<p>'.$langs->trans('Company'). ' : '.$object->thirdparty->name.'</p>'; |
|
218 | - } |
|
219 | - |
|
220 | - $message_admin.='<p>'.$langs->trans('Message').' : <br>'.$object->message.'</p>'; |
|
221 | - $message_admin.='<p><a href="'.dol_buildpath('/ticket/card.php', 2).'?track_id='.$object->track_id.'">'.$langs->trans('SeeThisTicketIntomanagementInterface').'</a></p>'; |
|
222 | - |
|
223 | - $from = $conf->global->MAIN_INFO_SOCIETE_NOM.'<'.$conf->global->TICKET_NOTIFICATION_EMAIL_FROM.'>'; |
|
224 | - $replyto = $from; |
|
225 | - |
|
226 | - $message_admin = dol_nl2br($message_admin); |
|
227 | - |
|
228 | - if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) { |
|
229 | - $old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->MAIN_MAIL_AUTOCOPY_TO; |
|
230 | - $conf->global->MAIN_MAIL_AUTOCOPY_TO = ''; |
|
231 | - } |
|
232 | - include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; |
|
233 | - $mailfile = new CMailFile($subject, $sendto, $from, $message_admin, $filepath, $mimetype, $filename, $sendtocc, '', $deliveryreceipt, -1); |
|
234 | - if ($mailfile->error) { |
|
235 | - dol_syslog($mailfile->error, LOG_DEBUG); |
|
236 | - } else { |
|
237 | - $result=$mailfile->sendfile(); |
|
238 | - } |
|
239 | - if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) { |
|
240 | - $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO; |
|
241 | - } |
|
242 | - } |
|
243 | - } |
|
244 | - |
|
245 | - // Send email to customer |
|
246 | - |
|
247 | - if (empty($conf->global->TICKET_DISABLE_ALL_MAILS) && empty($object->context['disableticketemail']) && $object->notify_tiers_at_create) |
|
248 | - { |
|
249 | - $sendto = ''; |
|
250 | - if (empty($user->socid) && empty($user->email)) { |
|
251 | - $object->fetch_thirdparty(); |
|
252 | - $sendto = $object->thirdparty->email; |
|
253 | - } else { |
|
254 | - $sendto = $user->email; |
|
255 | - } |
|
256 | - |
|
257 | - if ($sendto) { |
|
258 | - // Init to avoid errors |
|
259 | - $filepath = array(); |
|
260 | - $filename = array(); |
|
261 | - $mimetype = array(); |
|
262 | - |
|
263 | - $subject = '['.$conf->global->MAIN_INFO_SOCIETE_NOM.'] '.$langs->transnoentities('TicketNewEmailSubjectCustomer'); |
|
264 | - $message_customer= $langs->transnoentities('TicketNewEmailBodyCustomer', $object->track_id)."\n\n"; |
|
265 | - $message_customer.='<ul><li>'.$langs->trans('Title').' : '.$object->subject.'</li>'; |
|
266 | - $message_customer.='<li>'.$langs->trans('Type').' : '.$object->type_label.'</li>'; |
|
267 | - $message_customer.='<li>'.$langs->trans('Category').' : '.$object->category_label.'</li>'; |
|
268 | - $message_customer.='<li>'.$langs->trans('Severity').' : '.$object->severity_label.'</li>'; |
|
269 | - |
|
270 | - // Extrafields |
|
271 | - foreach ($this->attributes[$object->table_element]['label'] as $key => $value) |
|
272 | - { |
|
273 | - $enabled = 1; |
|
274 | - if ($enabled && isset($this->attributes[$object->table_element]['list'][$key])) |
|
275 | - { |
|
276 | - $enabled = dol_eval($this->attributes[$object->table_element]['list'][$key], 1); |
|
277 | - } |
|
278 | - $perms = 1; |
|
279 | - if ($perms && isset($this->attributes[$object->table_element]['perms'][$key])) |
|
280 | - { |
|
281 | - $perms = dol_eval($this->attributes[$object->table_element]['perms'][$key], 1); |
|
282 | - } |
|
283 | - |
|
284 | - $qualified = true; |
|
285 | - if (empty($enabled)) $qualified = false; |
|
286 | - if (empty($perms)) $qualified = false; |
|
287 | - |
|
288 | - if ($qualified) $message_customer.='<li>'.$langs->trans($key).' : '.$value.'</li>'; |
|
289 | - } |
|
290 | - |
|
291 | - $message_customer.='</ul>'; |
|
292 | - $message_customer.='<p>'.$langs->trans('Message').' : <br>'.$object->message.'</p>'; |
|
293 | - $url_public_ticket = ($conf->global->TICKET_URL_PUBLIC_INTERFACE?$conf->global->TICKET_URL_PUBLIC_INTERFACE.'/':dol_buildpath('/public/ticket/view.php', 2)).'?track_id='.$object->track_id; |
|
294 | - $message_customer.='<p>' . $langs->trans('TicketNewEmailBodyInfosTrackUrlCustomer') . ' : <a href="'.$url_public_ticket.'">'.$url_public_ticket.'</a></p>'; |
|
295 | - $message_customer.='<p>'.$langs->trans('TicketEmailPleaseDoNotReplyToThisEmail').'</p>'; |
|
296 | - |
|
297 | - $from = $conf->global->MAIN_INFO_SOCIETE_NOM.'<'.$conf->global->TICKET_NOTIFICATION_EMAIL_FROM.'>'; |
|
298 | - $replyto = $from; |
|
299 | - |
|
300 | - $message_customer = dol_nl2br($message_customer); |
|
301 | - |
|
302 | - if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) { |
|
303 | - $old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->MAIN_MAIL_AUTOCOPY_TO; |
|
304 | - $conf->global->MAIN_MAIL_AUTOCOPY_TO = ''; |
|
305 | - } |
|
306 | - include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; |
|
307 | - $mailfile = new CMailFile($subject, $sendto, $from, $message_customer, $filepath, $mimetype, $filename, $sendtocc, '', $deliveryreceipt, -1); |
|
308 | - if ($mailfile->error) { |
|
309 | - dol_syslog($mailfile->error, LOG_DEBUG); |
|
310 | - } else { |
|
311 | - $result=$mailfile->sendfile(); |
|
312 | - } |
|
313 | - if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) { |
|
314 | - $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO; |
|
315 | - } |
|
316 | - } |
|
317 | - } |
|
169 | + } |
|
170 | + else |
|
171 | + { |
|
172 | + $this->error = $userstat->error; |
|
173 | + $this->errors = $userstat->errors; |
|
174 | + } |
|
175 | + } |
|
176 | + break; |
|
177 | + |
|
178 | + case 'TICKET_CREATE': |
|
179 | + dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); |
|
180 | + |
|
181 | + $langs->load('ticket'); |
|
182 | + |
|
183 | + $object->fetch('', $object->track_id); // Should be useless |
|
184 | + |
|
185 | + |
|
186 | + // Send email to notification email |
|
187 | + |
|
188 | + if (empty($conf->global->TICKET_DISABLE_ALL_MAILS) && empty($object->context['disableticketemail'])) |
|
189 | + { |
|
190 | + $sendto = $conf->global->TICKET_NOTIFICATION_EMAIL_TO; |
|
191 | + |
|
192 | + if ($sendto) |
|
193 | + { |
|
194 | + // Init to avoid errors |
|
195 | + $filepath = array(); |
|
196 | + $filename = array(); |
|
197 | + $mimetype = array(); |
|
198 | + |
|
199 | + /* Send email to admin */ |
|
200 | + $subject = '['.$conf->global->MAIN_INFO_SOCIETE_NOM.'] '.$langs->transnoentities('TicketNewEmailSubjectAdmin'); |
|
201 | + $message_admin= $langs->transnoentities('TicketNewEmailBodyAdmin', $object->track_id)."\n\n"; |
|
202 | + $message_admin.='<ul><li>'.$langs->trans('Title').' : '.$object->subject.'</li>'; |
|
203 | + $message_admin.='<li>'.$langs->trans('Type').' : '.$object->type_label.'</li>'; |
|
204 | + $message_admin.='<li>'.$langs->trans('Category').' : '.$object->category_label.'</li>'; |
|
205 | + $message_admin.='<li>'.$langs->trans('Severity').' : '.$object->severity_label.'</li>'; |
|
206 | + $message_admin.='<li>'.$langs->trans('From').' : '.( $object->email_from ? $object->email_from : ( $object->fk_user_create > 0 ? $langs->trans('Internal') : '') ).'</li>'; |
|
207 | + // Extrafields |
|
208 | + if (is_array($object->array_options) && count($object->array_options) > 0) { |
|
209 | + foreach ($object->array_options as $key => $value) { |
|
210 | + $message_admin.='<li>'.$langs->trans($key).' : '.$value.'</li>'; |
|
211 | + } |
|
212 | + } |
|
213 | + $message_admin.='</ul>'; |
|
214 | + |
|
215 | + if ($object->fk_soc > 0) { |
|
216 | + $object->fetch_thirdparty(); |
|
217 | + $message_admin.='<p>'.$langs->trans('Company'). ' : '.$object->thirdparty->name.'</p>'; |
|
218 | + } |
|
219 | + |
|
220 | + $message_admin.='<p>'.$langs->trans('Message').' : <br>'.$object->message.'</p>'; |
|
221 | + $message_admin.='<p><a href="'.dol_buildpath('/ticket/card.php', 2).'?track_id='.$object->track_id.'">'.$langs->trans('SeeThisTicketIntomanagementInterface').'</a></p>'; |
|
222 | + |
|
223 | + $from = $conf->global->MAIN_INFO_SOCIETE_NOM.'<'.$conf->global->TICKET_NOTIFICATION_EMAIL_FROM.'>'; |
|
224 | + $replyto = $from; |
|
225 | + |
|
226 | + $message_admin = dol_nl2br($message_admin); |
|
227 | + |
|
228 | + if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) { |
|
229 | + $old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->MAIN_MAIL_AUTOCOPY_TO; |
|
230 | + $conf->global->MAIN_MAIL_AUTOCOPY_TO = ''; |
|
231 | + } |
|
232 | + include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; |
|
233 | + $mailfile = new CMailFile($subject, $sendto, $from, $message_admin, $filepath, $mimetype, $filename, $sendtocc, '', $deliveryreceipt, -1); |
|
234 | + if ($mailfile->error) { |
|
235 | + dol_syslog($mailfile->error, LOG_DEBUG); |
|
236 | + } else { |
|
237 | + $result=$mailfile->sendfile(); |
|
238 | + } |
|
239 | + if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) { |
|
240 | + $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO; |
|
241 | + } |
|
242 | + } |
|
243 | + } |
|
244 | + |
|
245 | + // Send email to customer |
|
246 | + |
|
247 | + if (empty($conf->global->TICKET_DISABLE_ALL_MAILS) && empty($object->context['disableticketemail']) && $object->notify_tiers_at_create) |
|
248 | + { |
|
249 | + $sendto = ''; |
|
250 | + if (empty($user->socid) && empty($user->email)) { |
|
251 | + $object->fetch_thirdparty(); |
|
252 | + $sendto = $object->thirdparty->email; |
|
253 | + } else { |
|
254 | + $sendto = $user->email; |
|
255 | + } |
|
256 | + |
|
257 | + if ($sendto) { |
|
258 | + // Init to avoid errors |
|
259 | + $filepath = array(); |
|
260 | + $filename = array(); |
|
261 | + $mimetype = array(); |
|
262 | + |
|
263 | + $subject = '['.$conf->global->MAIN_INFO_SOCIETE_NOM.'] '.$langs->transnoentities('TicketNewEmailSubjectCustomer'); |
|
264 | + $message_customer= $langs->transnoentities('TicketNewEmailBodyCustomer', $object->track_id)."\n\n"; |
|
265 | + $message_customer.='<ul><li>'.$langs->trans('Title').' : '.$object->subject.'</li>'; |
|
266 | + $message_customer.='<li>'.$langs->trans('Type').' : '.$object->type_label.'</li>'; |
|
267 | + $message_customer.='<li>'.$langs->trans('Category').' : '.$object->category_label.'</li>'; |
|
268 | + $message_customer.='<li>'.$langs->trans('Severity').' : '.$object->severity_label.'</li>'; |
|
269 | + |
|
270 | + // Extrafields |
|
271 | + foreach ($this->attributes[$object->table_element]['label'] as $key => $value) |
|
272 | + { |
|
273 | + $enabled = 1; |
|
274 | + if ($enabled && isset($this->attributes[$object->table_element]['list'][$key])) |
|
275 | + { |
|
276 | + $enabled = dol_eval($this->attributes[$object->table_element]['list'][$key], 1); |
|
277 | + } |
|
278 | + $perms = 1; |
|
279 | + if ($perms && isset($this->attributes[$object->table_element]['perms'][$key])) |
|
280 | + { |
|
281 | + $perms = dol_eval($this->attributes[$object->table_element]['perms'][$key], 1); |
|
282 | + } |
|
283 | + |
|
284 | + $qualified = true; |
|
285 | + if (empty($enabled)) $qualified = false; |
|
286 | + if (empty($perms)) $qualified = false; |
|
287 | + |
|
288 | + if ($qualified) $message_customer.='<li>'.$langs->trans($key).' : '.$value.'</li>'; |
|
289 | + } |
|
290 | + |
|
291 | + $message_customer.='</ul>'; |
|
292 | + $message_customer.='<p>'.$langs->trans('Message').' : <br>'.$object->message.'</p>'; |
|
293 | + $url_public_ticket = ($conf->global->TICKET_URL_PUBLIC_INTERFACE?$conf->global->TICKET_URL_PUBLIC_INTERFACE.'/':dol_buildpath('/public/ticket/view.php', 2)).'?track_id='.$object->track_id; |
|
294 | + $message_customer.='<p>' . $langs->trans('TicketNewEmailBodyInfosTrackUrlCustomer') . ' : <a href="'.$url_public_ticket.'">'.$url_public_ticket.'</a></p>'; |
|
295 | + $message_customer.='<p>'.$langs->trans('TicketEmailPleaseDoNotReplyToThisEmail').'</p>'; |
|
296 | + |
|
297 | + $from = $conf->global->MAIN_INFO_SOCIETE_NOM.'<'.$conf->global->TICKET_NOTIFICATION_EMAIL_FROM.'>'; |
|
298 | + $replyto = $from; |
|
299 | + |
|
300 | + $message_customer = dol_nl2br($message_customer); |
|
301 | + |
|
302 | + if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) { |
|
303 | + $old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->MAIN_MAIL_AUTOCOPY_TO; |
|
304 | + $conf->global->MAIN_MAIL_AUTOCOPY_TO = ''; |
|
305 | + } |
|
306 | + include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; |
|
307 | + $mailfile = new CMailFile($subject, $sendto, $from, $message_customer, $filepath, $mimetype, $filename, $sendtocc, '', $deliveryreceipt, -1); |
|
308 | + if ($mailfile->error) { |
|
309 | + dol_syslog($mailfile->error, LOG_DEBUG); |
|
310 | + } else { |
|
311 | + $result=$mailfile->sendfile(); |
|
312 | + } |
|
313 | + if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) { |
|
314 | + $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO; |
|
315 | + } |
|
316 | + } |
|
317 | + } |
|
318 | 318 | $ok = 1; |
319 | - break; |
|
319 | + break; |
|
320 | 320 | |
321 | 321 | case 'TICKET_DELETE': |
322 | - dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); |
|
323 | - break; |
|
322 | + dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); |
|
323 | + break; |
|
324 | 324 | |
325 | - case 'TICKET_MODIFY': |
|
326 | - dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); |
|
327 | - break; |
|
325 | + case 'TICKET_MODIFY': |
|
326 | + dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); |
|
327 | + break; |
|
328 | 328 | |
329 | - case 'TICKET_MARK_READ': |
|
330 | - dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); |
|
331 | - break; |
|
329 | + case 'TICKET_MARK_READ': |
|
330 | + dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); |
|
331 | + break; |
|
332 | 332 | |
333 | - case 'TICKET_CLOSE': |
|
334 | - dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); |
|
335 | - break; |
|
336 | - } |
|
333 | + case 'TICKET_CLOSE': |
|
334 | + dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); |
|
335 | + break; |
|
336 | + } |
|
337 | 337 | |
338 | 338 | |
339 | 339 | return $ok; |
@@ -30,121 +30,121 @@ |
||
30 | 30 | */ |
31 | 31 | class InterfaceActionsBlockedLog extends DolibarrTriggers |
32 | 32 | { |
33 | - public $family = 'system'; |
|
34 | - public $description = "Triggers of this module add action for BlockedLog module."; |
|
35 | - |
|
36 | - /** |
|
37 | - * Version of the trigger |
|
38 | - * @var string |
|
39 | - */ |
|
40 | - public $version = self::VERSION_DOLIBARR; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var string Image of the trigger |
|
44 | - */ |
|
45 | - public $picto = 'technic'; |
|
46 | - |
|
47 | - /** |
|
48 | - * Function called on Dolibarrr payment or invoice event. |
|
49 | - * |
|
50 | - * @param string $action Event action code |
|
51 | - * @param Object $object Object |
|
52 | - * @param User $user Object user |
|
53 | - * @param Translate $langs Object langs |
|
54 | - * @param conf $conf Object conf |
|
55 | - * @return int <0 if KO, 0 if no triggered ran, >0 if OK |
|
56 | - */ |
|
57 | - public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf) |
|
58 | - { |
|
59 | - if (empty($conf->blockedlog->enabled)) return 0; // Module not active, we do nothing |
|
60 | - |
|
61 | - // Test if event/record is qualified |
|
62 | - $listofqualifiedelement = array('facture', 'don', 'payment', 'payment_donation', 'subscription', 'payment_various', 'cashcontrol'); |
|
63 | - if (! in_array($object->element, $listofqualifiedelement)) return 1; |
|
64 | - |
|
65 | - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
66 | - |
|
67 | - require_once DOL_DOCUMENT_ROOT.'/blockedlog/class/blockedlog.class.php'; |
|
68 | - $b=new BlockedLog($this->db); |
|
69 | - |
|
70 | - // Tracked events |
|
71 | - if (! in_array($action, array_keys($b->trackedevents))) |
|
72 | - { |
|
73 | - return 0; |
|
74 | - } |
|
75 | - |
|
76 | - // Event/record is qualified |
|
77 | - $qualified = 0; |
|
78 | - $amounts = 0; |
|
79 | - if ($action==='BILL_VALIDATE' || $action==='BILL_DELETE' || $action === 'BILL_SENTBYMAIL' |
|
80 | - || $action==='BILL_SUPPLIER_VALIDATE' || $action==='BILL_SUPPLIER_DELETE' || $action === 'BILL_SUPPLIER_SENTBYMAIL' |
|
81 | - || $action==='MEMBER_SUBSCRIPTION_CREATE' || $action==='MEMBER_SUBSCRIPTION_MODIFY' || $action==='MEMBER_SUBSCRIPTION_DELETE' |
|
82 | - || $action==='DON_VALIDATE' || $action==='DON_MODIFY' || $action==='DON_DELETE' |
|
83 | - || $action==='CASHCONTROL_VALIDATE' |
|
84 | - || (in_array($object->element, array('facture','suplier_invoice')) && $action === 'DOC_DOWNLOAD') || (in_array($object->element, array('facture','suplier_invoice')) && $action === 'DOC_PREVIEW') |
|
85 | - ) |
|
86 | - { |
|
87 | - $qualified++; |
|
88 | - |
|
89 | - if (in_array($action, array( |
|
90 | - 'MEMBER_SUBSCRIPTION_CREATE','MEMBER_SUBSCRIPTION_MODIFY','MEMBER_SUBSCRIPTION_DELETE', |
|
91 | - 'DON_VALIDATE','DON_MODIFY','DON_DELETE'))) $amounts = (double) $object->amount; |
|
92 | - elseif ($action == 'CASHCONTROL_VALIDATE') |
|
93 | - { |
|
94 | - $amounts = (double) $object->cash + (double) $object->cheque + (double) $object->card; |
|
95 | - } |
|
96 | - else $amounts = (double) $object->total_ttc; |
|
97 | - } |
|
98 | - /*if ($action === 'BILL_PAYED' || $action==='BILL_UNPAYED' |
|
33 | + public $family = 'system'; |
|
34 | + public $description = "Triggers of this module add action for BlockedLog module."; |
|
35 | + |
|
36 | + /** |
|
37 | + * Version of the trigger |
|
38 | + * @var string |
|
39 | + */ |
|
40 | + public $version = self::VERSION_DOLIBARR; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var string Image of the trigger |
|
44 | + */ |
|
45 | + public $picto = 'technic'; |
|
46 | + |
|
47 | + /** |
|
48 | + * Function called on Dolibarrr payment or invoice event. |
|
49 | + * |
|
50 | + * @param string $action Event action code |
|
51 | + * @param Object $object Object |
|
52 | + * @param User $user Object user |
|
53 | + * @param Translate $langs Object langs |
|
54 | + * @param conf $conf Object conf |
|
55 | + * @return int <0 if KO, 0 if no triggered ran, >0 if OK |
|
56 | + */ |
|
57 | + public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf) |
|
58 | + { |
|
59 | + if (empty($conf->blockedlog->enabled)) return 0; // Module not active, we do nothing |
|
60 | + |
|
61 | + // Test if event/record is qualified |
|
62 | + $listofqualifiedelement = array('facture', 'don', 'payment', 'payment_donation', 'subscription', 'payment_various', 'cashcontrol'); |
|
63 | + if (! in_array($object->element, $listofqualifiedelement)) return 1; |
|
64 | + |
|
65 | + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); |
|
66 | + |
|
67 | + require_once DOL_DOCUMENT_ROOT.'/blockedlog/class/blockedlog.class.php'; |
|
68 | + $b=new BlockedLog($this->db); |
|
69 | + |
|
70 | + // Tracked events |
|
71 | + if (! in_array($action, array_keys($b->trackedevents))) |
|
72 | + { |
|
73 | + return 0; |
|
74 | + } |
|
75 | + |
|
76 | + // Event/record is qualified |
|
77 | + $qualified = 0; |
|
78 | + $amounts = 0; |
|
79 | + if ($action==='BILL_VALIDATE' || $action==='BILL_DELETE' || $action === 'BILL_SENTBYMAIL' |
|
80 | + || $action==='BILL_SUPPLIER_VALIDATE' || $action==='BILL_SUPPLIER_DELETE' || $action === 'BILL_SUPPLIER_SENTBYMAIL' |
|
81 | + || $action==='MEMBER_SUBSCRIPTION_CREATE' || $action==='MEMBER_SUBSCRIPTION_MODIFY' || $action==='MEMBER_SUBSCRIPTION_DELETE' |
|
82 | + || $action==='DON_VALIDATE' || $action==='DON_MODIFY' || $action==='DON_DELETE' |
|
83 | + || $action==='CASHCONTROL_VALIDATE' |
|
84 | + || (in_array($object->element, array('facture','suplier_invoice')) && $action === 'DOC_DOWNLOAD') || (in_array($object->element, array('facture','suplier_invoice')) && $action === 'DOC_PREVIEW') |
|
85 | + ) |
|
86 | + { |
|
87 | + $qualified++; |
|
88 | + |
|
89 | + if (in_array($action, array( |
|
90 | + 'MEMBER_SUBSCRIPTION_CREATE','MEMBER_SUBSCRIPTION_MODIFY','MEMBER_SUBSCRIPTION_DELETE', |
|
91 | + 'DON_VALIDATE','DON_MODIFY','DON_DELETE'))) $amounts = (double) $object->amount; |
|
92 | + elseif ($action == 'CASHCONTROL_VALIDATE') |
|
93 | + { |
|
94 | + $amounts = (double) $object->cash + (double) $object->cheque + (double) $object->card; |
|
95 | + } |
|
96 | + else $amounts = (double) $object->total_ttc; |
|
97 | + } |
|
98 | + /*if ($action === 'BILL_PAYED' || $action==='BILL_UNPAYED' |
|
99 | 99 | || $action === 'BILL_SUPPLIER_PAYED' || $action === 'BILL_SUPPLIER_UNPAYED') |
100 | 100 | { |
101 | 101 | $qualified++; |
102 | 102 | $amounts= (double) $object->total_ttc; |
103 | 103 | }*/ |
104 | - if ($action === 'PAYMENT_CUSTOMER_CREATE' || $action === 'PAYMENT_SUPPLIER_CREATE' || $action === 'DONATION_PAYMENT_CREATE' |
|
105 | - || $action === 'PAYMENT_CUSTOMER_DELETE' || $action === 'PAYMENT_SUPPLIER_DELETE' || $action === 'DONATION_PAYMENT_DELETE') |
|
106 | - { |
|
107 | - $qualified++; |
|
108 | - $amounts = 0; |
|
109 | - if(!empty($object->amounts)) { |
|
110 | - foreach($object->amounts as $amount) { |
|
111 | - $amounts += price2num($amount); |
|
112 | - } |
|
113 | - } |
|
114 | - } |
|
115 | - elseif (strpos($action,'PAYMENT')!==false && ! in_array($action, array('PAYMENT_ADD_TO_BANK'))) |
|
116 | - { |
|
117 | - $qualified++; |
|
118 | - $amounts = (double) $object->amount; |
|
119 | - } |
|
120 | - |
|
121 | - // Another protection. |
|
122 | - // May be used when event is DOC_DOWNLOAD or DOC_PREVIEW and element is not an invoice |
|
123 | - if (! $qualified) |
|
124 | - { |
|
125 | - return 0; // not implemented action log |
|
126 | - } |
|
127 | - |
|
128 | - $result = $b->setObjectData($object, $action, $amounts, $user); // Set field date_object, ref_object, fk_object, element, object_data |
|
129 | - |
|
130 | - if ($result < 0) |
|
131 | - { |
|
132 | - $this->error = $b->error; |
|
133 | - $this->errors = $b->errors; |
|
134 | - return -1; |
|
135 | - } |
|
136 | - |
|
137 | - $res = $b->create($user); |
|
138 | - |
|
139 | - if ($res < 0) |
|
140 | - { |
|
141 | - $this->error = $b->error; |
|
142 | - $this->errors = $b->errors; |
|
143 | - return -1; |
|
144 | - } |
|
145 | - else |
|
146 | - { |
|
147 | - return 1; |
|
148 | - } |
|
104 | + if ($action === 'PAYMENT_CUSTOMER_CREATE' || $action === 'PAYMENT_SUPPLIER_CREATE' || $action === 'DONATION_PAYMENT_CREATE' |
|
105 | + || $action === 'PAYMENT_CUSTOMER_DELETE' || $action === 'PAYMENT_SUPPLIER_DELETE' || $action === 'DONATION_PAYMENT_DELETE') |
|
106 | + { |
|
107 | + $qualified++; |
|
108 | + $amounts = 0; |
|
109 | + if(!empty($object->amounts)) { |
|
110 | + foreach($object->amounts as $amount) { |
|
111 | + $amounts += price2num($amount); |
|
112 | + } |
|
113 | + } |
|
114 | + } |
|
115 | + elseif (strpos($action,'PAYMENT')!==false && ! in_array($action, array('PAYMENT_ADD_TO_BANK'))) |
|
116 | + { |
|
117 | + $qualified++; |
|
118 | + $amounts = (double) $object->amount; |
|
119 | + } |
|
120 | + |
|
121 | + // Another protection. |
|
122 | + // May be used when event is DOC_DOWNLOAD or DOC_PREVIEW and element is not an invoice |
|
123 | + if (! $qualified) |
|
124 | + { |
|
125 | + return 0; // not implemented action log |
|
126 | + } |
|
127 | + |
|
128 | + $result = $b->setObjectData($object, $action, $amounts, $user); // Set field date_object, ref_object, fk_object, element, object_data |
|
129 | + |
|
130 | + if ($result < 0) |
|
131 | + { |
|
132 | + $this->error = $b->error; |
|
133 | + $this->errors = $b->errors; |
|
134 | + return -1; |
|
135 | + } |
|
136 | + |
|
137 | + $res = $b->create($user); |
|
138 | + |
|
139 | + if ($res < 0) |
|
140 | + { |
|
141 | + $this->error = $b->error; |
|
142 | + $this->errors = $b->errors; |
|
143 | + return -1; |
|
144 | + } |
|
145 | + else |
|
146 | + { |
|
147 | + return 1; |
|
148 | + } |
|
149 | 149 | } |
150 | 150 | } |