@@ -31,766 +31,766 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | class Notify |
| 33 | 33 | { |
| 34 | - /** |
|
| 35 | - * @var int ID |
|
| 36 | - */ |
|
| 37 | - public $id; |
|
| 34 | + /** |
|
| 35 | + * @var int ID |
|
| 36 | + */ |
|
| 37 | + public $id; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 39 | + /** |
|
| 40 | 40 | * @var DoliDB Database handler. |
| 41 | 41 | */ |
| 42 | 42 | public $db; |
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @var string Error code (or message) |
|
| 46 | - */ |
|
| 47 | - public $error=''; |
|
| 44 | + /** |
|
| 45 | + * @var string Error code (or message) |
|
| 46 | + */ |
|
| 47 | + public $error=''; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @var string[] Error codes (or messages) |
|
| 51 | - */ |
|
| 52 | - public $errors = array(); |
|
| 49 | + /** |
|
| 50 | + * @var string[] Error codes (or messages) |
|
| 51 | + */ |
|
| 52 | + public $errors = array(); |
|
| 53 | 53 | |
| 54 | - public $author; |
|
| 55 | - public $ref; |
|
| 56 | - public $date; |
|
| 57 | - public $duree; |
|
| 58 | - public $note; |
|
| 54 | + public $author; |
|
| 55 | + public $ref; |
|
| 56 | + public $date; |
|
| 57 | + public $duree; |
|
| 58 | + public $note; |
|
| 59 | 59 | |
| 60 | - /** |
|
| 60 | + /** |
|
| 61 | 61 | * @var int Project ID |
| 62 | 62 | */ |
| 63 | 63 | public $fk_project; |
| 64 | 64 | |
| 65 | - // Les codes actions sont definis dans la table llx_notify_def |
|
| 66 | - |
|
| 67 | - // codes actions supported are |
|
| 68 | - // @TODO defined also into interface_50_modNotificiation_Notificiation.class.php |
|
| 69 | - public $arrayofnotifsupported = array( |
|
| 70 | - 'BILL_VALIDATE', |
|
| 71 | - 'BILL_PAYED', |
|
| 72 | - 'ORDER_VALIDATE', |
|
| 73 | - 'PROPAL_VALIDATE', |
|
| 74 | - 'PROPAL_CLOSE_SIGNED', |
|
| 75 | - 'FICHINTER_VALIDATE', |
|
| 76 | - 'FICHINTER_ADD_CONTACT', |
|
| 77 | - 'ORDER_SUPPLIER_VALIDATE', |
|
| 78 | - 'ORDER_SUPPLIER_APPROVE', |
|
| 79 | - 'ORDER_SUPPLIER_REFUSE', |
|
| 80 | - 'SHIPPING_VALIDATE', |
|
| 81 | - 'EXPENSE_REPORT_VALIDATE', |
|
| 82 | - 'EXPENSE_REPORT_APPROVE', |
|
| 83 | - 'HOLIDAY_VALIDATE', |
|
| 84 | - 'HOLIDAY_APPROVE' |
|
| 85 | - ); |
|
| 86 | - |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Constructor |
|
| 90 | - * |
|
| 91 | - * @param DoliDB $db Database handler |
|
| 92 | - */ |
|
| 93 | - function __construct($db) |
|
| 94 | - { |
|
| 95 | - $this->db = $db; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * Return message that say how many notification (and to which email) will occurs on requested event. |
|
| 101 | - * This is to show confirmation messages before event is recorded. |
|
| 102 | - * |
|
| 103 | - * @param string $action Id of action in llx_c_action_trigger |
|
| 104 | - * @param int $socid Id of third party |
|
| 105 | - * @param Object $object Object the notification is about |
|
| 106 | - * @return string Message |
|
| 107 | - */ |
|
| 108 | - function confirmMessage($action,$socid,$object) |
|
| 109 | - { |
|
| 110 | - global $langs; |
|
| 111 | - $langs->load("mails"); |
|
| 112 | - |
|
| 113 | - $listofnotiftodo=$this->getNotificationsArray($action,$socid,$object,0); |
|
| 114 | - |
|
| 115 | - $nb=-1; |
|
| 116 | - if (is_array($listofnotiftodo)) $nb=count($listofnotiftodo); |
|
| 117 | - if ($nb < 0) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("ErrorFailedToGetListOfNotificationsToSend"); |
|
| 118 | - if ($nb == 0) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("NoNotificationsWillBeSent"); |
|
| 119 | - if ($nb == 1) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("ANotificationsWillBeSent"); |
|
| 120 | - if ($nb >= 2) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("SomeNotificationsWillBeSent",$nb); |
|
| 121 | - |
|
| 122 | - if (is_array($listofnotiftodo)) |
|
| 123 | - { |
|
| 124 | - $i=0; |
|
| 125 | - foreach ($listofnotiftodo as $key => $val) |
|
| 126 | - { |
|
| 127 | - if ($i) $texte.=', '; |
|
| 128 | - else $texte.=' ('; |
|
| 129 | - if ($val['isemailvalid']) $texte.=$val['email']; |
|
| 130 | - else $texte.=$val['emaildesc']; |
|
| 131 | - $i++; |
|
| 132 | - } |
|
| 133 | - if ($i) $texte.=')'; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - return $texte; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * Return number of notifications activated for action code (and third party) |
|
| 141 | - * |
|
| 142 | - * @param string $notifcode Code of action in llx_c_action_trigger (new usage) or Id of action in llx_c_action_trigger (old usage) |
|
| 143 | - * @param int $socid Id of third party or 0 for all thirdparties or -1 for no thirdparties |
|
| 144 | - * @param Object $object Object the notification is about (need it to check threshold value of some notifications) |
|
| 145 | - * @param int $userid Id of user or 0 for all users or -1 for no users |
|
| 146 | - * @param array $scope Scope where to search |
|
| 147 | - * @return array|int <0 if KO, array of notifications to send if OK |
|
| 148 | - */ |
|
| 149 | - function getNotificationsArray($notifcode, $socid=0, $object=null, $userid=0, $scope=array('thirdparty', 'user', 'global')) |
|
| 150 | - { |
|
| 151 | - global $conf, $user; |
|
| 152 | - |
|
| 153 | - $error=0; |
|
| 154 | - $resarray=array(); |
|
| 155 | - |
|
| 156 | - $valueforthreshold = 0; |
|
| 157 | - if (is_object($object)) $valueforthreshold = $object->total_ht; |
|
| 158 | - |
|
| 159 | - if (! $error) |
|
| 160 | - { |
|
| 161 | - if ($socid >= 0 && in_array('thirdparty', $scope)) |
|
| 162 | - { |
|
| 163 | - $sql = "SELECT a.code, c.email, c.rowid"; |
|
| 164 | - $sql.= " FROM ".MAIN_DB_PREFIX."notify_def as n,"; |
|
| 165 | - $sql.= " ".MAIN_DB_PREFIX."socpeople as c,"; |
|
| 166 | - $sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a,"; |
|
| 167 | - $sql.= " ".MAIN_DB_PREFIX."societe as s"; |
|
| 168 | - $sql.= " WHERE n.fk_contact = c.rowid"; |
|
| 169 | - $sql.= " AND a.rowid = n.fk_action"; |
|
| 170 | - $sql.= " AND n.fk_soc = s.rowid"; |
|
| 171 | - if ($notifcode) |
|
| 172 | - { |
|
| 173 | - if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode; // Old usage |
|
| 174 | - else $sql.= " AND a.code = '".$notifcode."'"; // New usage |
|
| 175 | - } |
|
| 176 | - $sql.= " AND s.entity IN (".getEntity('societe').")"; |
|
| 177 | - if ($socid > 0) $sql.= " AND s.rowid = ".$socid; |
|
| 178 | - |
|
| 179 | - dol_syslog(__METHOD__." ".$notifcode.", ".$socid."", LOG_DEBUG); |
|
| 180 | - |
|
| 181 | - $resql = $this->db->query($sql); |
|
| 182 | - if ($resql) |
|
| 183 | - { |
|
| 184 | - $num = $this->db->num_rows($resql); |
|
| 185 | - $i=0; |
|
| 186 | - while ($i < $num) |
|
| 187 | - { |
|
| 188 | - $obj = $this->db->fetch_object($resql); |
|
| 189 | - if ($obj) |
|
| 190 | - { |
|
| 191 | - $newval2=trim($obj->email); |
|
| 192 | - $isvalid=isValidEmail($newval2); |
|
| 193 | - if (empty($resarray[$newval2])) $resarray[$newval2] = array('type'=> 'tocontact', 'code'=>trim($obj->code), 'emaildesc'=>'Contact id '.$obj->rowid, 'email'=>$newval2, 'contactid'=>$obj->rowid, 'isemailvalid'=>$isvalid); |
|
| 194 | - } |
|
| 195 | - $i++; |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - else |
|
| 199 | - { |
|
| 200 | - $error++; |
|
| 201 | - $this->error=$this->db->lasterror(); |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - if (! $error) |
|
| 207 | - { |
|
| 208 | - if ($userid >= 0 && in_array('user', $scope)) |
|
| 209 | - { |
|
| 210 | - $sql = "SELECT a.code, c.email, c.rowid"; |
|
| 211 | - $sql.= " FROM ".MAIN_DB_PREFIX."notify_def as n,"; |
|
| 212 | - $sql.= " ".MAIN_DB_PREFIX."user as c,"; |
|
| 213 | - $sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a"; |
|
| 214 | - $sql.= " WHERE n.fk_user = c.rowid"; |
|
| 215 | - $sql.= " AND a.rowid = n.fk_action"; |
|
| 216 | - if ($notifcode) |
|
| 217 | - { |
|
| 218 | - if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode; // Old usage |
|
| 219 | - else $sql.= " AND a.code = '".$notifcode."'"; // New usage |
|
| 220 | - } |
|
| 221 | - $sql.= " AND c.entity IN (".getEntity('user').")"; |
|
| 222 | - if ($userid > 0) $sql.= " AND c.rowid = ".$userid; |
|
| 223 | - |
|
| 224 | - dol_syslog(__METHOD__." ".$notifcode.", ".$socid."", LOG_DEBUG); |
|
| 225 | - |
|
| 226 | - $resql = $this->db->query($sql); |
|
| 227 | - if ($resql) |
|
| 228 | - { |
|
| 229 | - $num = $this->db->num_rows($resql); |
|
| 230 | - $i=0; |
|
| 231 | - while ($i < $num) |
|
| 232 | - { |
|
| 233 | - $obj = $this->db->fetch_object($resql); |
|
| 234 | - if ($obj) |
|
| 235 | - { |
|
| 236 | - $newval2=trim($obj->email); |
|
| 237 | - $isvalid=isValidEmail($newval2); |
|
| 238 | - if (empty($resarray[$newval2])) $resarray[$newval2] = array('type'=> 'touser', 'code'=>trim($obj->code), 'emaildesc'=>'User id '.$obj->rowid, 'email'=>$newval2, 'userid'=>$obj->rowid, 'isemailvalid'=>$isvalid); |
|
| 239 | - } |
|
| 240 | - $i++; |
|
| 241 | - } |
|
| 242 | - } |
|
| 243 | - else |
|
| 244 | - { |
|
| 245 | - $error++; |
|
| 246 | - $this->error=$this->db->lasterror(); |
|
| 247 | - } |
|
| 248 | - } |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - if (! $error) |
|
| 252 | - { |
|
| 253 | - if (in_array('global', $scope)) |
|
| 254 | - { |
|
| 255 | - // List of notifications enabled for fixed email |
|
| 256 | - foreach($conf->global as $key => $val) |
|
| 257 | - { |
|
| 258 | - if ($notifcode) |
|
| 259 | - { |
|
| 260 | - if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) continue; |
|
| 261 | - } |
|
| 262 | - else |
|
| 263 | - { |
|
| 264 | - if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_.*_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) continue; |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - $threshold = (float) $reg[1]; |
|
| 268 | - if ($valueforthreshold < $threshold) continue; |
|
| 269 | - |
|
| 270 | - $tmpemail=explode(',',$val); |
|
| 271 | - foreach($tmpemail as $key2 => $val2) |
|
| 272 | - { |
|
| 273 | - $newval2=trim($val2); |
|
| 274 | - if ($newval2 == '__SUPERVISOREMAIL__') |
|
| 275 | - { |
|
| 276 | - if ($user->fk_user > 0) |
|
| 277 | - { |
|
| 278 | - $tmpuser=new User($this->db); |
|
| 279 | - $tmpuser->fetch($user->fk_user); |
|
| 280 | - if ($tmpuser->email) $newval2=trim($tmpuser->email); |
|
| 281 | - else $newval2=''; |
|
| 282 | - } |
|
| 283 | - else $newval2=''; |
|
| 284 | - } |
|
| 285 | - if ($newval2) |
|
| 286 | - { |
|
| 287 | - $isvalid=isValidEmail($newval2, 0); |
|
| 288 | - if (empty($resarray[$newval2])) $resarray[$newval2]=array('type'=> 'tofixedemail', 'code'=>trim($key), 'emaildesc'=>trim($val2), 'email'=>$newval2, 'isemailvalid'=>$isvalid); |
|
| 289 | - } |
|
| 290 | - } |
|
| 291 | - } |
|
| 292 | - } |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - if ($error) return -1; |
|
| 296 | - |
|
| 297 | - //var_dump($resarray); |
|
| 298 | - return $resarray; |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - /** |
|
| 302 | - * Check if notification are active for couple action/company. |
|
| 303 | - * If yes, send mail and save trace into llx_notify. |
|
| 304 | - * |
|
| 305 | - * @param string $notifcode Code of action in llx_c_action_trigger (new usage) or Id of action in llx_c_action_trigger (old usage) |
|
| 306 | - * @param Object $object Object the notification deals on |
|
| 307 | - * @param array $filename_list List of files to attach (full path of filename on file system) |
|
| 308 | - * @param array $mimetype_list List of MIME type of attached files |
|
| 309 | - * @param array $mimefilename_list List of attached file name in message |
|
| 310 | - * @return int <0 if KO, or number of changes if OK |
|
| 311 | - */ |
|
| 312 | - function send($notifcode, $object, $filename_list=array(), $mimetype_list=array(), $mimefilename_list=array()) |
|
| 313 | - { |
|
| 314 | - global $user,$conf,$langs,$mysoc; |
|
| 315 | - global $hookmanager; |
|
| 316 | - global $dolibarr_main_url_root; |
|
| 317 | - |
|
| 318 | - if (! in_array($notifcode, $this->arrayofnotifsupported)) return 0; |
|
| 319 | - |
|
| 320 | - include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
| 321 | - if (! is_object($hookmanager)) |
|
| 322 | - { |
|
| 323 | - include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; |
|
| 324 | - $hookmanager=new HookManager($this->db); |
|
| 325 | - } |
|
| 326 | - $hookmanager->initHooks(array('notification')); |
|
| 327 | - |
|
| 328 | - dol_syslog(get_class($this)."::send notifcode=".$notifcode.", object=".$object->id); |
|
| 329 | - |
|
| 330 | - $langs->load("other"); |
|
| 331 | - |
|
| 332 | - // Define $urlwithroot |
|
| 333 | - $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); |
|
| 334 | - $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
| 335 | - //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current |
|
| 336 | - |
|
| 337 | - // Define some vars |
|
| 338 | - $application = 'Dolibarr'; |
|
| 339 | - if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $application = $conf->global->MAIN_APPLICATION_TITLE; |
|
| 340 | - $replyto = $conf->notification->email_from; |
|
| 341 | - $object_type = ''; |
|
| 342 | - $link = ''; |
|
| 343 | - $num = 0; |
|
| 344 | - |
|
| 345 | - $oldref=(empty($object->oldref)?$object->ref:$object->oldref); |
|
| 346 | - $newref=(empty($object->newref)?$object->ref:$object->newref); |
|
| 347 | - |
|
| 348 | - $sql = ''; |
|
| 349 | - |
|
| 350 | - // Check notification per third party |
|
| 351 | - if ($object->socid > 0) |
|
| 352 | - { |
|
| 353 | - $sql.= "SELECT 'tocontactid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.default_lang,"; |
|
| 354 | - $sql.= " a.rowid as adid, a.label, a.code, n.rowid, n.type"; |
|
| 355 | - $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as c,"; |
|
| 356 | - $sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a,"; |
|
| 357 | - $sql.= " ".MAIN_DB_PREFIX."notify_def as n,"; |
|
| 358 | - $sql.= " ".MAIN_DB_PREFIX."societe as s"; |
|
| 359 | - $sql.= " WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action"; |
|
| 360 | - $sql.= " AND n.fk_soc = s.rowid"; |
|
| 361 | - if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode; // Old usage |
|
| 362 | - else $sql.= " AND a.code = '".$notifcode."'"; // New usage |
|
| 363 | - $sql .= " AND s.rowid = ".$object->socid; |
|
| 364 | - |
|
| 365 | - $sql.= "\nUNION\n"; |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - // Check notification per user |
|
| 369 | - $sql.= "SELECT 'touserid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.lang as default_lang,"; |
|
| 370 | - $sql.= " a.rowid as adid, a.label, a.code, n.rowid, n.type"; |
|
| 371 | - $sql.= " FROM ".MAIN_DB_PREFIX."user as c,"; |
|
| 372 | - $sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a,"; |
|
| 373 | - $sql.= " ".MAIN_DB_PREFIX."notify_def as n"; |
|
| 374 | - $sql.= " WHERE n.fk_user = c.rowid AND a.rowid = n.fk_action"; |
|
| 375 | - if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode; // Old usage |
|
| 376 | - else $sql.= " AND a.code = '".$this->db->escape($notifcode)."'"; // New usage |
|
| 377 | - |
|
| 378 | - $result = $this->db->query($sql); |
|
| 379 | - if ($result) |
|
| 380 | - { |
|
| 381 | - $num = $this->db->num_rows($result); |
|
| 382 | - $projtitle=''; |
|
| 383 | - if (! empty($object->fk_project)) |
|
| 384 | - { |
|
| 385 | - require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; |
|
| 386 | - $proj = new Project($this->db); |
|
| 387 | - $proj->fetch($object->fk_project); |
|
| 388 | - $projtitle='('.$proj->title.')'; |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - if ($num > 0) |
|
| 392 | - { |
|
| 393 | - $i = 0; |
|
| 394 | - while ($i < $num && ! $error) // For each notification couple defined (third party/actioncode) |
|
| 395 | - { |
|
| 396 | - $obj = $this->db->fetch_object($result); |
|
| 397 | - |
|
| 398 | - $sendto = dolGetFirstLastname($obj->firstname,$obj->lastname) . " <".$obj->email.">"; |
|
| 399 | - $notifcodedefid = $obj->adid; |
|
| 400 | - |
|
| 401 | - if (dol_strlen($obj->email)) |
|
| 402 | - { |
|
| 403 | - // Set output language |
|
| 404 | - $outputlangs = $langs; |
|
| 405 | - if ($obj->default_lang && $obj->default_lang != $langs->defaultlang) |
|
| 406 | - { |
|
| 407 | - $outputlangs = new Translate('', $conf); |
|
| 408 | - $outputlangs->setDefaultLang($obj->default_lang); |
|
| 409 | - $outputlangs->loadLangs(array("main","other")); |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - $subject = '['.$mysoc->name.'] '.$outputlangs->transnoentitiesnoconv("DolibarrNotification").($projtitle?' '.$projtitle:''); |
|
| 413 | - |
|
| 414 | - switch ($notifcode) { |
|
| 415 | - case 'BILL_VALIDATE': |
|
| 416 | - $link='/compta/facture/card.php?facid='.$object->id; |
|
| 417 | - $dir_output = $conf->facture->dir_output; |
|
| 418 | - $object_type = 'facture'; |
|
| 419 | - $mesg = $outputlangs->transnoentitiesnoconv("EMailTextInvoiceValidated",$newref); |
|
| 420 | - break; |
|
| 421 | - case 'BILL_PAYED': |
|
| 422 | - $link='/compta/facture/card.php?facid='.$object->id; |
|
| 423 | - $dir_output = $conf->facture->dir_output; |
|
| 424 | - $object_type = 'facture'; |
|
| 425 | - $mesg = $outputlangs->transnoentitiesnoconv("EMailTextInvoicePayed",$newref); |
|
| 426 | - break; |
|
| 427 | - case 'ORDER_VALIDATE': |
|
| 428 | - $link='/commande/card.php?id='.$object->id; |
|
| 429 | - $dir_output = $conf->commande->dir_output; |
|
| 430 | - $object_type = 'order'; |
|
| 431 | - $mesg = $outputlangs->transnoentitiesnoconv("EMailTextOrderValidated",$newref); |
|
| 432 | - break; |
|
| 433 | - case 'PROPAL_VALIDATE': |
|
| 434 | - $link='/comm/propal/card.php?id='.$object->id; |
|
| 435 | - $dir_output = $conf->propal->multidir_output[$object->entity]; |
|
| 436 | - $object_type = 'propal'; |
|
| 437 | - $mesg = $outputlangs->transnoentitiesnoconv("EMailTextProposalValidated",$newref); |
|
| 438 | - break; |
|
| 439 | - case 'PROPAL_CLOSE_SIGNED': |
|
| 440 | - $link='/comm/propal/card.php?id='.$object->id; |
|
| 441 | - $dir_output = $conf->propal->multidir_output[$object->entity]; |
|
| 442 | - $object_type = 'propal'; |
|
| 443 | - $mesg = $outputlangs->transnoentitiesnoconv("EMailTextProposalClosedSigned",$newref); |
|
| 444 | - break; |
|
| 445 | - case 'FICHINTER_ADD_CONTACT': |
|
| 446 | - $link='/fichinter/card.php?id='.$object->id; |
|
| 447 | - $dir_output = $conf->ficheinter->dir_output; |
|
| 448 | - $object_type = 'ficheinter'; |
|
| 449 | - $mesg = $outputlangs->transnoentitiesnoconv("EMailTextInterventionAddedContact",$newref); |
|
| 450 | - break; |
|
| 451 | - case 'FICHINTER_VALIDATE': |
|
| 452 | - $link='/fichinter/card.php?id='.$object->id; |
|
| 453 | - $dir_output = $conf->ficheinter->dir_output; |
|
| 454 | - $object_type = 'ficheinter'; |
|
| 455 | - $mesg = $outputlangs->transnoentitiesnoconv("EMailTextInterventionValidated",$newref); |
|
| 456 | - break; |
|
| 457 | - case 'ORDER_SUPPLIER_VALIDATE': |
|
| 458 | - $link='/fourn/commande/card.php?id='.$object->id; |
|
| 459 | - $dir_output = $conf->fournisseur->commande->dir_output; |
|
| 460 | - $object_type = 'order_supplier'; |
|
| 461 | - $mesg = $outputlangs->transnoentitiesnoconv("Hello").",\n\n"; |
|
| 462 | - $mesg.= $outputlangs->transnoentitiesnoconv("EMailTextOrderValidatedBy",$newref,$user->getFullName($langs)); |
|
| 463 | - $mesg.= "\n\n".$outputlangs->transnoentitiesnoconv("Sincerely").".\n\n"; |
|
| 464 | - break; |
|
| 465 | - case 'ORDER_SUPPLIER_APPROVE': |
|
| 466 | - $link='/fourn/commande/card.php?id='.$object->id; |
|
| 467 | - $dir_output = $conf->fournisseur->commande->dir_output; |
|
| 468 | - $object_type = 'order_supplier'; |
|
| 469 | - $mesg = $outputlangs->transnoentitiesnoconv("Hello").",\n\n"; |
|
| 470 | - $mesg.= $outputlangs->transnoentitiesnoconv("EMailTextOrderApprovedBy",$newref,$user->getFullName($langs)); |
|
| 471 | - $mesg.= "\n\n".$outputlangs->transnoentitiesnoconv("Sincerely").".\n\n"; |
|
| 472 | - break; |
|
| 473 | - case 'ORDER_SUPPLIER_REFUSE': |
|
| 474 | - $link='/fourn/commande/card.php?id='.$object->id; |
|
| 475 | - $dir_output = $conf->fournisseur->commande->dir_output; |
|
| 476 | - $object_type = 'order_supplier'; |
|
| 477 | - $mesg = $outputlangs->transnoentitiesnoconv("Hello").",\n\n"; |
|
| 478 | - $mesg.= $outputlangs->transnoentitiesnoconv("EMailTextOrderRefusedBy",$newref,$user->getFullName($langs)); |
|
| 479 | - $mesg.= "\n\n".$outputlangs->transnoentitiesnoconv("Sincerely").".\n\n"; |
|
| 480 | - break; |
|
| 481 | - case 'SHIPPING_VALIDATE': |
|
| 482 | - $dir_output = $conf->expedition->dir_output.'/sending/'; |
|
| 483 | - $object_type = 'order_supplier'; |
|
| 484 | - $mesg = $outputlangs->transnoentitiesnoconv("EMailTextExpeditionValidated",$newref); |
|
| 485 | - break; |
|
| 486 | - case 'EXPENSE_REPORT_VALIDATE': |
|
| 487 | - $dir_output = $conf->expensereport->dir_output; |
|
| 488 | - $object_type = 'expensereport'; |
|
| 489 | - $mesg = $outputlangs->transnoentitiesnoconv("EMailTextExpenseReportValidated",$newref); |
|
| 490 | - break; |
|
| 491 | - case 'EXPENSE_REPORT_APPROVE': |
|
| 492 | - $dir_output = $conf->expensereport->dir_output; |
|
| 493 | - $object_type = 'expensereport'; |
|
| 494 | - $mesg = $outputlangs->transnoentitiesnoconv("EMailTextExpenseReportApproved",$newref); |
|
| 495 | - break; |
|
| 496 | - case 'HOLIDAY_VALIDATE': |
|
| 497 | - $dir_output = $conf->holiday->dir_output; |
|
| 498 | - $object_type = 'holiday'; |
|
| 499 | - $mesg = $outputlangs->transnoentitiesnoconv("EMailTextHolidayValidated",$newref); |
|
| 500 | - break; |
|
| 501 | - case 'HOLIDAY_APPROVE': |
|
| 502 | - $dir_output = $conf->holiday->dir_output; |
|
| 503 | - $object_type = 'holiday'; |
|
| 504 | - $mesg = $outputlangs->transnoentitiesnoconv("EMailTextHolidayApproved",$newref); |
|
| 505 | - break; |
|
| 506 | - } |
|
| 507 | - $ref = dol_sanitizeFileName($newref); |
|
| 508 | - $pdf_path = $dir_output."/".$ref."/".$ref.".pdf"; |
|
| 509 | - if (! dol_is_file($pdf_path)) |
|
| 510 | - { |
|
| 511 | - // We can't add PDF as it is not generated yet. |
|
| 512 | - $filepdf = ''; |
|
| 513 | - } |
|
| 514 | - else |
|
| 515 | - { |
|
| 516 | - $filepdf = $pdf_path; |
|
| 517 | - } |
|
| 518 | - |
|
| 519 | - $message = $outputlangs->transnoentities("YouReceiveMailBecauseOfNotification",$application,$mysoc->name)."\n"; |
|
| 520 | - $message.= $outputlangs->transnoentities("YouReceiveMailBecauseOfNotification2",$application,$mysoc->name)."\n"; |
|
| 521 | - $message.= "\n"; |
|
| 522 | - $message.= $mesg; |
|
| 523 | - if ($link) $message.= "\n" . $urlwithroot . $link; |
|
| 524 | - |
|
| 525 | - $parameters=array('notifcode'=>$notifcode, 'sendto'=>$sendto, 'replyto'=>$replyto, 'file'=>$filename_list, 'mimefile'=>$mimetype_list, 'filename'=>$mimefilename_list); |
|
| 526 | - $reshook=$hookmanager->executeHooks('formatNotificationMessage',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks |
|
| 527 | - if (empty($reshook)) |
|
| 528 | - { |
|
| 529 | - if (! empty($hookmanager->resArray['subject'])) $subject.=$hookmanager->resArray['subject']; |
|
| 530 | - if (! empty($hookmanager->resArray['message'])) $message.=$hookmanager->resArray['message']; |
|
| 531 | - } |
|
| 532 | - |
|
| 533 | - $mailfile = new CMailFile( |
|
| 534 | - $subject, |
|
| 535 | - $sendto, |
|
| 536 | - $replyto, |
|
| 537 | - $message, |
|
| 538 | - $filename_list, |
|
| 539 | - $mimetype_list, |
|
| 540 | - $mimefilename_list, |
|
| 541 | - '', |
|
| 542 | - '', |
|
| 543 | - 0, |
|
| 544 | - -1 |
|
| 545 | - ); |
|
| 546 | - |
|
| 547 | - if ($mailfile->sendfile()) |
|
| 548 | - { |
|
| 549 | - if ($obj->type_target == 'touserid') { |
|
| 550 | - $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_user, type, objet_type, type_target, objet_id, email)"; |
|
| 551 | - $sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".($object->socid?$object->socid:'null').", ".$obj->cid.", '".$obj->type."', '".$object_type."', '".$obj->type_target."', ".$object->id.", '".$this->db->escape($obj->email)."')"; |
|
| 552 | - } |
|
| 553 | - else { |
|
| 554 | - $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, type_target, objet_id, email)"; |
|
| 555 | - $sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".($object->socid?$object->socid:'null').", ".$obj->cid.", '".$obj->type."', '".$object_type."', '".$obj->type_target."', ".$object->id.", '".$this->db->escape($obj->email)."')"; |
|
| 556 | - } |
|
| 557 | - if (! $this->db->query($sql)) |
|
| 558 | - { |
|
| 559 | - dol_print_error($this->db); |
|
| 560 | - } |
|
| 561 | - } |
|
| 562 | - else |
|
| 563 | - { |
|
| 564 | - $error++; |
|
| 565 | - $this->errors[]=$mailfile->error; |
|
| 566 | - } |
|
| 567 | - } |
|
| 568 | - else |
|
| 569 | - { |
|
| 570 | - dol_syslog("No notification sent for ".$sendto." because email is empty"); |
|
| 571 | - } |
|
| 572 | - $i++; |
|
| 573 | - } |
|
| 574 | - } |
|
| 575 | - else |
|
| 576 | - { |
|
| 577 | - dol_syslog("No notification to thirdparty sent, nothing into notification setup for the thirdparty socid = ".$object->socid); |
|
| 578 | - } |
|
| 579 | - } |
|
| 580 | - else |
|
| 581 | - { |
|
| 582 | - $error++; |
|
| 583 | - $this->errors[]=$this->db->lasterror(); |
|
| 584 | - dol_syslog("Failed to get list of notification to send ".$this->db->lasterror(), LOG_ERR); |
|
| 585 | - return -1; |
|
| 586 | - } |
|
| 587 | - |
|
| 588 | - // Check notification using fixed email |
|
| 589 | - if (! $error) |
|
| 590 | - { |
|
| 591 | - foreach($conf->global as $key => $val) |
|
| 592 | - { |
|
| 593 | - if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) continue; |
|
| 594 | - |
|
| 595 | - $threshold = (float) $reg[1]; |
|
| 596 | - if (!empty($object->total_ht) && $object->total_ht <= $threshold) |
|
| 597 | - { |
|
| 598 | - dol_syslog("A notification is requested for notifcode = ".$notifcode." but amount = ".$object->total_ht." so lower than threshold = ".$threshold.". We discard this notification"); |
|
| 599 | - continue; |
|
| 600 | - } |
|
| 601 | - |
|
| 602 | - $param='NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_'.$reg[1]; |
|
| 603 | - |
|
| 604 | - $sendto = $conf->global->$param; |
|
| 605 | - $notifcodedefid = dol_getIdFromCode($this->db, $notifcode, 'c_action_trigger', 'code', 'rowid'); |
|
| 606 | - if ($notifcodedefid <= 0) dol_print_error($this->db, 'Failed to get id from code'); |
|
| 607 | - |
|
| 608 | - $object_type = ''; |
|
| 609 | - $link = ''; |
|
| 610 | - $num++; |
|
| 611 | - |
|
| 612 | - $subject = '['.$mysoc->name.'] '.$langs->transnoentitiesnoconv("DolibarrNotification").($projtitle?' '.$projtitle:''); |
|
| 613 | - |
|
| 614 | - switch ($notifcode) { |
|
| 615 | - case 'BILL_VALIDATE': |
|
| 616 | - $link = '<a href="' . $urlwithroot . '/compta/facture/card.php?facid=' . $object->id . '">' . $newref . '</a>'; |
|
| 617 | - $dir_output = $conf->facture->dir_output; |
|
| 618 | - $object_type = 'facture'; |
|
| 619 | - $mesg = $langs->transnoentitiesnoconv("EMailTextInvoiceValidated",$link); |
|
| 620 | - break; |
|
| 621 | - case 'BILL_PAYED': |
|
| 622 | - $link ='<a href="' . $urlwithroot . '/compta/facture/card.php?facid='.$object->id . '">' . $newref . '</a>'; |
|
| 623 | - $dir_output = $conf->facture->dir_output; |
|
| 624 | - $object_type = 'facture'; |
|
| 625 | - $mesg = $langs->transnoentitiesnoconv("EMailTextInvoicePayed",$link); |
|
| 626 | - break; |
|
| 627 | - case 'ORDER_VALIDATE': |
|
| 628 | - $link = '<a href="' . $urlwithroot . '/commande/card.php?id='.$object->id . '">' . $newref . '</a>'; |
|
| 629 | - $dir_output = $conf->commande->dir_output; |
|
| 630 | - $object_type = 'order'; |
|
| 631 | - $mesg = $langs->transnoentitiesnoconv("EMailTextOrderValidated",$link); |
|
| 632 | - break; |
|
| 633 | - case 'PROPAL_VALIDATE': |
|
| 634 | - $link = '<a href="' . $urlwithroot . '/comm/propal/card.php?id='.$object->id . '">' . $newref . '</a>'; |
|
| 635 | - $dir_output = $conf->propal->multidir_output[$object->entity]; |
|
| 636 | - $object_type = 'propal'; |
|
| 637 | - $mesg = $langs->transnoentitiesnoconv("EMailTextProposalValidated",$link); |
|
| 638 | - break; |
|
| 639 | - case 'PROPAL_CLOSE_SIGNED': |
|
| 640 | - $link = '<a href="' . $urlwithroot . '/comm/propal/card.php?id='.$object->id . '">' . $newref . '</a>'; |
|
| 641 | - $dir_output = $conf->propal->multidir_output[$object->entity]; |
|
| 642 | - $object_type = 'propal'; |
|
| 643 | - $mesg = $langs->transnoentitiesnoconv("EMailTextProposalClosedSigned",$link); |
|
| 644 | - break; |
|
| 645 | - case 'FICHINTER_ADD_CONTACT': |
|
| 646 | - $link = '<a href="' . $urlwithroot . '/fichinter/card.php?id='.$object->id . '">' . $newref . '</a>'; |
|
| 647 | - $dir_output = $conf->facture->dir_output; |
|
| 648 | - $object_type = 'ficheinter'; |
|
| 649 | - $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionAddedContact",$link); |
|
| 650 | - break; |
|
| 651 | - case 'FICHINTER_VALIDATE': |
|
| 652 | - $link = '<a href="' . $urlwithroot . '/fichinter/card.php?id='.$object->id . '">' . $newref . '</a>'; |
|
| 653 | - $dir_output = $conf->facture->dir_output; |
|
| 654 | - $object_type = 'ficheinter'; |
|
| 655 | - $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionValidated",$link); |
|
| 656 | - break; |
|
| 657 | - case 'ORDER_SUPPLIER_VALIDATE': |
|
| 658 | - $link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id='.$object->id . '">' . $newref . '</a>'; |
|
| 659 | - $dir_output = $conf->fournisseur->commande->dir_output; |
|
| 660 | - $object_type = 'order_supplier'; |
|
| 661 | - $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n"; |
|
| 662 | - $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderValidatedBy",$link,$user->getFullName($langs)); |
|
| 663 | - $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n"; |
|
| 664 | - break; |
|
| 665 | - case 'ORDER_SUPPLIER_APPROVE': |
|
| 666 | - $link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id='.$object->id . '">' . $newref . '</a>'; |
|
| 667 | - $dir_output = $conf->fournisseur->commande->dir_output; |
|
| 668 | - $object_type = 'order_supplier'; |
|
| 669 | - $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n"; |
|
| 670 | - $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy",$link,$user->getFullName($langs)); |
|
| 671 | - $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n"; |
|
| 672 | - break; |
|
| 673 | - case 'ORDER_SUPPLIER_APPROVE2': |
|
| 674 | - $link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id='.$object->id . '">' . $newref . '</a>'; |
|
| 675 | - $dir_output = $conf->fournisseur->commande->dir_output; |
|
| 676 | - $object_type = 'order_supplier'; |
|
| 677 | - $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n"; |
|
| 678 | - $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy",$link,$user->getFullName($langs)); |
|
| 679 | - $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n"; |
|
| 680 | - break; |
|
| 681 | - case 'ORDER_SUPPLIER_REFUSE': |
|
| 682 | - $link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id='.$object->id . '">' . $newref . '</a>'; |
|
| 683 | - $dir_output = $conf->fournisseur->dir_output.'/commande/'; |
|
| 684 | - $object_type = 'order_supplier'; |
|
| 685 | - $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n"; |
|
| 686 | - $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderRefusedBy",$link,$user->getFullName($langs)); |
|
| 687 | - $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n"; |
|
| 688 | - break; |
|
| 689 | - case 'SHIPPING_VALIDATE': |
|
| 690 | - $dir_output = $conf->expedition->dir_output.'/sending/'; |
|
| 691 | - $object_type = 'order_supplier'; |
|
| 692 | - $mesg = $langs->transnoentitiesnoconv("EMailTextExpeditionValidated",$newref); |
|
| 693 | - break; |
|
| 694 | - case 'EXPENSE_REPORT_VALIDATE': |
|
| 695 | - $dir_output = $conf->expensereport->dir_output; |
|
| 696 | - $object_type = 'expensereport'; |
|
| 697 | - $mesg = $langs->transnoentitiesnoconv("EMailTextExpenseReportValidated",$newref); |
|
| 698 | - break; |
|
| 699 | - case 'EXPENSE_REPORT_APPROVE': |
|
| 700 | - $dir_output = $conf->expensereport->dir_output; |
|
| 701 | - $object_type = 'expensereport'; |
|
| 702 | - $mesg = $langs->transnoentitiesnoconv("EMailTextExpenseReportApproved",$newref); |
|
| 703 | - break; |
|
| 704 | - case 'HOLIDAY_VALIDATE': |
|
| 705 | - $dir_output = $conf->holiday->dir_output; |
|
| 706 | - $object_type = 'holiday'; |
|
| 707 | - $mesg = $langs->transnoentitiesnoconv("EMailTextHolidayValidated",$newref); |
|
| 708 | - break; |
|
| 709 | - case 'HOLIDAY_APPROVE': |
|
| 710 | - $dir_output = $conf->holiday->dir_output; |
|
| 711 | - $object_type = 'holiday'; |
|
| 712 | - $mesg = $langs->transnoentitiesnoconv("EMailTextHolidayApproved",$newref); |
|
| 713 | - break; |
|
| 714 | - } |
|
| 715 | - $ref = dol_sanitizeFileName($newref); |
|
| 716 | - $pdf_path = $dir_output."/".$ref."/".$ref.".pdf"; |
|
| 717 | - if (! dol_is_file($pdf_path)) |
|
| 718 | - { |
|
| 719 | - // We can't add PDF as it is not generated yet. |
|
| 720 | - $filepdf = ''; |
|
| 721 | - } |
|
| 722 | - else |
|
| 723 | - { |
|
| 724 | - $filepdf = $pdf_path; |
|
| 725 | - } |
|
| 726 | - |
|
| 727 | - $message = $langs->transnoentities("YouReceiveMailBecauseOfNotification",$application,$mysoc->name)."\n"; |
|
| 728 | - $message.= $langs->transnoentities("YouReceiveMailBecauseOfNotification2",$application,$mysoc->name)."\n"; |
|
| 729 | - $message.= "\n"; |
|
| 730 | - $message.= $mesg; |
|
| 731 | - //if ($link) $message.= "\n" . $urlwithroot . $link; // link already added around the ref into the text |
|
| 732 | - |
|
| 733 | - $message = nl2br($message); |
|
| 734 | - |
|
| 735 | - // Replace keyword __SUPERVISOREMAIL__ |
|
| 736 | - if (preg_match('/__SUPERVISOREMAIL__/', $sendto)) |
|
| 737 | - { |
|
| 738 | - $newval=''; |
|
| 739 | - if ($user->fk_user > 0) |
|
| 740 | - { |
|
| 741 | - $supervisoruser=new User($this->db); |
|
| 742 | - $supervisoruser->fetch($user->fk_user); |
|
| 743 | - if ($supervisoruser->email) $newval=trim(dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).' <'.$supervisoruser->email.'>'); |
|
| 744 | - } |
|
| 745 | - dol_syslog("Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval); |
|
| 746 | - $sendto = preg_replace('/__SUPERVISOREMAIL__/', $newval, $sendto); |
|
| 747 | - $sendto = preg_replace('/,\s*,/', ',', $sendto); // in some case you can have $sendto like "email, __SUPERVISOREMAIL__ , otheremail" then you have "email, , othermail" and it's not valid |
|
| 748 | - $sendto = preg_replace('/^[\s,]+/', '', $sendto); // Clean start of string |
|
| 749 | - $sendto = preg_replace('/[\s,]+$/', '', $sendto); // Clean end of string |
|
| 750 | - } |
|
| 751 | - |
|
| 752 | - if ($sendto) |
|
| 753 | - { |
|
| 754 | - $parameters=array('notifcode'=>$notifcode, 'sendto'=>$sendto, 'replyto'=>$replyto, 'file'=>$filename_list, 'mimefile'=>$mimetype_list, 'filename'=>$mimefilename_list); |
|
| 755 | - $reshook=$hookmanager->executeHooks('formatNotificationMessage',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks |
|
| 756 | - if (empty($reshook)) |
|
| 757 | - { |
|
| 758 | - if (! empty($hookmanager->resArray['subject'])) $subject.=$hookmanager->resArray['subject']; |
|
| 759 | - if (! empty($hookmanager->resArray['message'])) $message.=$hookmanager->resArray['message']; |
|
| 760 | - } |
|
| 761 | - $mailfile = new CMailFile( |
|
| 762 | - $subject, |
|
| 763 | - $sendto, |
|
| 764 | - $replyto, |
|
| 765 | - $message, |
|
| 766 | - $filename_list, |
|
| 767 | - $mimetype_list, |
|
| 768 | - $mimefilename_list, |
|
| 769 | - '', |
|
| 770 | - '', |
|
| 771 | - 0, |
|
| 772 | - 1 |
|
| 773 | - ); |
|
| 774 | - |
|
| 775 | - if ($mailfile->sendfile()) |
|
| 776 | - { |
|
| 777 | - $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_contact, type, type_target, objet_type, objet_id, email)"; |
|
| 778 | - $sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".($object->socid?$object->socid:'null').", null, 'email', 'tofixedemail', '".$object_type."', ".$object->id.", '".$this->db->escape($conf->global->$param)."')"; |
|
| 779 | - if (! $this->db->query($sql)) |
|
| 780 | - { |
|
| 781 | - dol_print_error($this->db); |
|
| 782 | - } |
|
| 783 | - } |
|
| 784 | - else |
|
| 785 | - { |
|
| 786 | - $error++; |
|
| 787 | - $this->errors[]=$mailfile->error; |
|
| 788 | - } |
|
| 789 | - } |
|
| 790 | - } |
|
| 791 | - } |
|
| 792 | - |
|
| 793 | - if (! $error) return $num; |
|
| 794 | - else return -1 * $error; |
|
| 795 | - } |
|
| 65 | + // Les codes actions sont definis dans la table llx_notify_def |
|
| 66 | + |
|
| 67 | + // codes actions supported are |
|
| 68 | + // @TODO defined also into interface_50_modNotificiation_Notificiation.class.php |
|
| 69 | + public $arrayofnotifsupported = array( |
|
| 70 | + 'BILL_VALIDATE', |
|
| 71 | + 'BILL_PAYED', |
|
| 72 | + 'ORDER_VALIDATE', |
|
| 73 | + 'PROPAL_VALIDATE', |
|
| 74 | + 'PROPAL_CLOSE_SIGNED', |
|
| 75 | + 'FICHINTER_VALIDATE', |
|
| 76 | + 'FICHINTER_ADD_CONTACT', |
|
| 77 | + 'ORDER_SUPPLIER_VALIDATE', |
|
| 78 | + 'ORDER_SUPPLIER_APPROVE', |
|
| 79 | + 'ORDER_SUPPLIER_REFUSE', |
|
| 80 | + 'SHIPPING_VALIDATE', |
|
| 81 | + 'EXPENSE_REPORT_VALIDATE', |
|
| 82 | + 'EXPENSE_REPORT_APPROVE', |
|
| 83 | + 'HOLIDAY_VALIDATE', |
|
| 84 | + 'HOLIDAY_APPROVE' |
|
| 85 | + ); |
|
| 86 | + |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Constructor |
|
| 90 | + * |
|
| 91 | + * @param DoliDB $db Database handler |
|
| 92 | + */ |
|
| 93 | + function __construct($db) |
|
| 94 | + { |
|
| 95 | + $this->db = $db; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * Return message that say how many notification (and to which email) will occurs on requested event. |
|
| 101 | + * This is to show confirmation messages before event is recorded. |
|
| 102 | + * |
|
| 103 | + * @param string $action Id of action in llx_c_action_trigger |
|
| 104 | + * @param int $socid Id of third party |
|
| 105 | + * @param Object $object Object the notification is about |
|
| 106 | + * @return string Message |
|
| 107 | + */ |
|
| 108 | + function confirmMessage($action,$socid,$object) |
|
| 109 | + { |
|
| 110 | + global $langs; |
|
| 111 | + $langs->load("mails"); |
|
| 112 | + |
|
| 113 | + $listofnotiftodo=$this->getNotificationsArray($action,$socid,$object,0); |
|
| 114 | + |
|
| 115 | + $nb=-1; |
|
| 116 | + if (is_array($listofnotiftodo)) $nb=count($listofnotiftodo); |
|
| 117 | + if ($nb < 0) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("ErrorFailedToGetListOfNotificationsToSend"); |
|
| 118 | + if ($nb == 0) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("NoNotificationsWillBeSent"); |
|
| 119 | + if ($nb == 1) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("ANotificationsWillBeSent"); |
|
| 120 | + if ($nb >= 2) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("SomeNotificationsWillBeSent",$nb); |
|
| 121 | + |
|
| 122 | + if (is_array($listofnotiftodo)) |
|
| 123 | + { |
|
| 124 | + $i=0; |
|
| 125 | + foreach ($listofnotiftodo as $key => $val) |
|
| 126 | + { |
|
| 127 | + if ($i) $texte.=', '; |
|
| 128 | + else $texte.=' ('; |
|
| 129 | + if ($val['isemailvalid']) $texte.=$val['email']; |
|
| 130 | + else $texte.=$val['emaildesc']; |
|
| 131 | + $i++; |
|
| 132 | + } |
|
| 133 | + if ($i) $texte.=')'; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + return $texte; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * Return number of notifications activated for action code (and third party) |
|
| 141 | + * |
|
| 142 | + * @param string $notifcode Code of action in llx_c_action_trigger (new usage) or Id of action in llx_c_action_trigger (old usage) |
|
| 143 | + * @param int $socid Id of third party or 0 for all thirdparties or -1 for no thirdparties |
|
| 144 | + * @param Object $object Object the notification is about (need it to check threshold value of some notifications) |
|
| 145 | + * @param int $userid Id of user or 0 for all users or -1 for no users |
|
| 146 | + * @param array $scope Scope where to search |
|
| 147 | + * @return array|int <0 if KO, array of notifications to send if OK |
|
| 148 | + */ |
|
| 149 | + function getNotificationsArray($notifcode, $socid=0, $object=null, $userid=0, $scope=array('thirdparty', 'user', 'global')) |
|
| 150 | + { |
|
| 151 | + global $conf, $user; |
|
| 152 | + |
|
| 153 | + $error=0; |
|
| 154 | + $resarray=array(); |
|
| 155 | + |
|
| 156 | + $valueforthreshold = 0; |
|
| 157 | + if (is_object($object)) $valueforthreshold = $object->total_ht; |
|
| 158 | + |
|
| 159 | + if (! $error) |
|
| 160 | + { |
|
| 161 | + if ($socid >= 0 && in_array('thirdparty', $scope)) |
|
| 162 | + { |
|
| 163 | + $sql = "SELECT a.code, c.email, c.rowid"; |
|
| 164 | + $sql.= " FROM ".MAIN_DB_PREFIX."notify_def as n,"; |
|
| 165 | + $sql.= " ".MAIN_DB_PREFIX."socpeople as c,"; |
|
| 166 | + $sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a,"; |
|
| 167 | + $sql.= " ".MAIN_DB_PREFIX."societe as s"; |
|
| 168 | + $sql.= " WHERE n.fk_contact = c.rowid"; |
|
| 169 | + $sql.= " AND a.rowid = n.fk_action"; |
|
| 170 | + $sql.= " AND n.fk_soc = s.rowid"; |
|
| 171 | + if ($notifcode) |
|
| 172 | + { |
|
| 173 | + if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode; // Old usage |
|
| 174 | + else $sql.= " AND a.code = '".$notifcode."'"; // New usage |
|
| 175 | + } |
|
| 176 | + $sql.= " AND s.entity IN (".getEntity('societe').")"; |
|
| 177 | + if ($socid > 0) $sql.= " AND s.rowid = ".$socid; |
|
| 178 | + |
|
| 179 | + dol_syslog(__METHOD__." ".$notifcode.", ".$socid."", LOG_DEBUG); |
|
| 180 | + |
|
| 181 | + $resql = $this->db->query($sql); |
|
| 182 | + if ($resql) |
|
| 183 | + { |
|
| 184 | + $num = $this->db->num_rows($resql); |
|
| 185 | + $i=0; |
|
| 186 | + while ($i < $num) |
|
| 187 | + { |
|
| 188 | + $obj = $this->db->fetch_object($resql); |
|
| 189 | + if ($obj) |
|
| 190 | + { |
|
| 191 | + $newval2=trim($obj->email); |
|
| 192 | + $isvalid=isValidEmail($newval2); |
|
| 193 | + if (empty($resarray[$newval2])) $resarray[$newval2] = array('type'=> 'tocontact', 'code'=>trim($obj->code), 'emaildesc'=>'Contact id '.$obj->rowid, 'email'=>$newval2, 'contactid'=>$obj->rowid, 'isemailvalid'=>$isvalid); |
|
| 194 | + } |
|
| 195 | + $i++; |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + else |
|
| 199 | + { |
|
| 200 | + $error++; |
|
| 201 | + $this->error=$this->db->lasterror(); |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + if (! $error) |
|
| 207 | + { |
|
| 208 | + if ($userid >= 0 && in_array('user', $scope)) |
|
| 209 | + { |
|
| 210 | + $sql = "SELECT a.code, c.email, c.rowid"; |
|
| 211 | + $sql.= " FROM ".MAIN_DB_PREFIX."notify_def as n,"; |
|
| 212 | + $sql.= " ".MAIN_DB_PREFIX."user as c,"; |
|
| 213 | + $sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a"; |
|
| 214 | + $sql.= " WHERE n.fk_user = c.rowid"; |
|
| 215 | + $sql.= " AND a.rowid = n.fk_action"; |
|
| 216 | + if ($notifcode) |
|
| 217 | + { |
|
| 218 | + if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode; // Old usage |
|
| 219 | + else $sql.= " AND a.code = '".$notifcode."'"; // New usage |
|
| 220 | + } |
|
| 221 | + $sql.= " AND c.entity IN (".getEntity('user').")"; |
|
| 222 | + if ($userid > 0) $sql.= " AND c.rowid = ".$userid; |
|
| 223 | + |
|
| 224 | + dol_syslog(__METHOD__." ".$notifcode.", ".$socid."", LOG_DEBUG); |
|
| 225 | + |
|
| 226 | + $resql = $this->db->query($sql); |
|
| 227 | + if ($resql) |
|
| 228 | + { |
|
| 229 | + $num = $this->db->num_rows($resql); |
|
| 230 | + $i=0; |
|
| 231 | + while ($i < $num) |
|
| 232 | + { |
|
| 233 | + $obj = $this->db->fetch_object($resql); |
|
| 234 | + if ($obj) |
|
| 235 | + { |
|
| 236 | + $newval2=trim($obj->email); |
|
| 237 | + $isvalid=isValidEmail($newval2); |
|
| 238 | + if (empty($resarray[$newval2])) $resarray[$newval2] = array('type'=> 'touser', 'code'=>trim($obj->code), 'emaildesc'=>'User id '.$obj->rowid, 'email'=>$newval2, 'userid'=>$obj->rowid, 'isemailvalid'=>$isvalid); |
|
| 239 | + } |
|
| 240 | + $i++; |
|
| 241 | + } |
|
| 242 | + } |
|
| 243 | + else |
|
| 244 | + { |
|
| 245 | + $error++; |
|
| 246 | + $this->error=$this->db->lasterror(); |
|
| 247 | + } |
|
| 248 | + } |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + if (! $error) |
|
| 252 | + { |
|
| 253 | + if (in_array('global', $scope)) |
|
| 254 | + { |
|
| 255 | + // List of notifications enabled for fixed email |
|
| 256 | + foreach($conf->global as $key => $val) |
|
| 257 | + { |
|
| 258 | + if ($notifcode) |
|
| 259 | + { |
|
| 260 | + if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) continue; |
|
| 261 | + } |
|
| 262 | + else |
|
| 263 | + { |
|
| 264 | + if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_.*_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) continue; |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + $threshold = (float) $reg[1]; |
|
| 268 | + if ($valueforthreshold < $threshold) continue; |
|
| 269 | + |
|
| 270 | + $tmpemail=explode(',',$val); |
|
| 271 | + foreach($tmpemail as $key2 => $val2) |
|
| 272 | + { |
|
| 273 | + $newval2=trim($val2); |
|
| 274 | + if ($newval2 == '__SUPERVISOREMAIL__') |
|
| 275 | + { |
|
| 276 | + if ($user->fk_user > 0) |
|
| 277 | + { |
|
| 278 | + $tmpuser=new User($this->db); |
|
| 279 | + $tmpuser->fetch($user->fk_user); |
|
| 280 | + if ($tmpuser->email) $newval2=trim($tmpuser->email); |
|
| 281 | + else $newval2=''; |
|
| 282 | + } |
|
| 283 | + else $newval2=''; |
|
| 284 | + } |
|
| 285 | + if ($newval2) |
|
| 286 | + { |
|
| 287 | + $isvalid=isValidEmail($newval2, 0); |
|
| 288 | + if (empty($resarray[$newval2])) $resarray[$newval2]=array('type'=> 'tofixedemail', 'code'=>trim($key), 'emaildesc'=>trim($val2), 'email'=>$newval2, 'isemailvalid'=>$isvalid); |
|
| 289 | + } |
|
| 290 | + } |
|
| 291 | + } |
|
| 292 | + } |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + if ($error) return -1; |
|
| 296 | + |
|
| 297 | + //var_dump($resarray); |
|
| 298 | + return $resarray; |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + /** |
|
| 302 | + * Check if notification are active for couple action/company. |
|
| 303 | + * If yes, send mail and save trace into llx_notify. |
|
| 304 | + * |
|
| 305 | + * @param string $notifcode Code of action in llx_c_action_trigger (new usage) or Id of action in llx_c_action_trigger (old usage) |
|
| 306 | + * @param Object $object Object the notification deals on |
|
| 307 | + * @param array $filename_list List of files to attach (full path of filename on file system) |
|
| 308 | + * @param array $mimetype_list List of MIME type of attached files |
|
| 309 | + * @param array $mimefilename_list List of attached file name in message |
|
| 310 | + * @return int <0 if KO, or number of changes if OK |
|
| 311 | + */ |
|
| 312 | + function send($notifcode, $object, $filename_list=array(), $mimetype_list=array(), $mimefilename_list=array()) |
|
| 313 | + { |
|
| 314 | + global $user,$conf,$langs,$mysoc; |
|
| 315 | + global $hookmanager; |
|
| 316 | + global $dolibarr_main_url_root; |
|
| 317 | + |
|
| 318 | + if (! in_array($notifcode, $this->arrayofnotifsupported)) return 0; |
|
| 319 | + |
|
| 320 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
| 321 | + if (! is_object($hookmanager)) |
|
| 322 | + { |
|
| 323 | + include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; |
|
| 324 | + $hookmanager=new HookManager($this->db); |
|
| 325 | + } |
|
| 326 | + $hookmanager->initHooks(array('notification')); |
|
| 327 | + |
|
| 328 | + dol_syslog(get_class($this)."::send notifcode=".$notifcode.", object=".$object->id); |
|
| 329 | + |
|
| 330 | + $langs->load("other"); |
|
| 331 | + |
|
| 332 | + // Define $urlwithroot |
|
| 333 | + $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); |
|
| 334 | + $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
| 335 | + //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current |
|
| 336 | + |
|
| 337 | + // Define some vars |
|
| 338 | + $application = 'Dolibarr'; |
|
| 339 | + if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $application = $conf->global->MAIN_APPLICATION_TITLE; |
|
| 340 | + $replyto = $conf->notification->email_from; |
|
| 341 | + $object_type = ''; |
|
| 342 | + $link = ''; |
|
| 343 | + $num = 0; |
|
| 344 | + |
|
| 345 | + $oldref=(empty($object->oldref)?$object->ref:$object->oldref); |
|
| 346 | + $newref=(empty($object->newref)?$object->ref:$object->newref); |
|
| 347 | + |
|
| 348 | + $sql = ''; |
|
| 349 | + |
|
| 350 | + // Check notification per third party |
|
| 351 | + if ($object->socid > 0) |
|
| 352 | + { |
|
| 353 | + $sql.= "SELECT 'tocontactid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.default_lang,"; |
|
| 354 | + $sql.= " a.rowid as adid, a.label, a.code, n.rowid, n.type"; |
|
| 355 | + $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as c,"; |
|
| 356 | + $sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a,"; |
|
| 357 | + $sql.= " ".MAIN_DB_PREFIX."notify_def as n,"; |
|
| 358 | + $sql.= " ".MAIN_DB_PREFIX."societe as s"; |
|
| 359 | + $sql.= " WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action"; |
|
| 360 | + $sql.= " AND n.fk_soc = s.rowid"; |
|
| 361 | + if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode; // Old usage |
|
| 362 | + else $sql.= " AND a.code = '".$notifcode."'"; // New usage |
|
| 363 | + $sql .= " AND s.rowid = ".$object->socid; |
|
| 364 | + |
|
| 365 | + $sql.= "\nUNION\n"; |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + // Check notification per user |
|
| 369 | + $sql.= "SELECT 'touserid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.lang as default_lang,"; |
|
| 370 | + $sql.= " a.rowid as adid, a.label, a.code, n.rowid, n.type"; |
|
| 371 | + $sql.= " FROM ".MAIN_DB_PREFIX."user as c,"; |
|
| 372 | + $sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a,"; |
|
| 373 | + $sql.= " ".MAIN_DB_PREFIX."notify_def as n"; |
|
| 374 | + $sql.= " WHERE n.fk_user = c.rowid AND a.rowid = n.fk_action"; |
|
| 375 | + if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode; // Old usage |
|
| 376 | + else $sql.= " AND a.code = '".$this->db->escape($notifcode)."'"; // New usage |
|
| 377 | + |
|
| 378 | + $result = $this->db->query($sql); |
|
| 379 | + if ($result) |
|
| 380 | + { |
|
| 381 | + $num = $this->db->num_rows($result); |
|
| 382 | + $projtitle=''; |
|
| 383 | + if (! empty($object->fk_project)) |
|
| 384 | + { |
|
| 385 | + require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; |
|
| 386 | + $proj = new Project($this->db); |
|
| 387 | + $proj->fetch($object->fk_project); |
|
| 388 | + $projtitle='('.$proj->title.')'; |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + if ($num > 0) |
|
| 392 | + { |
|
| 393 | + $i = 0; |
|
| 394 | + while ($i < $num && ! $error) // For each notification couple defined (third party/actioncode) |
|
| 395 | + { |
|
| 396 | + $obj = $this->db->fetch_object($result); |
|
| 397 | + |
|
| 398 | + $sendto = dolGetFirstLastname($obj->firstname,$obj->lastname) . " <".$obj->email.">"; |
|
| 399 | + $notifcodedefid = $obj->adid; |
|
| 400 | + |
|
| 401 | + if (dol_strlen($obj->email)) |
|
| 402 | + { |
|
| 403 | + // Set output language |
|
| 404 | + $outputlangs = $langs; |
|
| 405 | + if ($obj->default_lang && $obj->default_lang != $langs->defaultlang) |
|
| 406 | + { |
|
| 407 | + $outputlangs = new Translate('', $conf); |
|
| 408 | + $outputlangs->setDefaultLang($obj->default_lang); |
|
| 409 | + $outputlangs->loadLangs(array("main","other")); |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + $subject = '['.$mysoc->name.'] '.$outputlangs->transnoentitiesnoconv("DolibarrNotification").($projtitle?' '.$projtitle:''); |
|
| 413 | + |
|
| 414 | + switch ($notifcode) { |
|
| 415 | + case 'BILL_VALIDATE': |
|
| 416 | + $link='/compta/facture/card.php?facid='.$object->id; |
|
| 417 | + $dir_output = $conf->facture->dir_output; |
|
| 418 | + $object_type = 'facture'; |
|
| 419 | + $mesg = $outputlangs->transnoentitiesnoconv("EMailTextInvoiceValidated",$newref); |
|
| 420 | + break; |
|
| 421 | + case 'BILL_PAYED': |
|
| 422 | + $link='/compta/facture/card.php?facid='.$object->id; |
|
| 423 | + $dir_output = $conf->facture->dir_output; |
|
| 424 | + $object_type = 'facture'; |
|
| 425 | + $mesg = $outputlangs->transnoentitiesnoconv("EMailTextInvoicePayed",$newref); |
|
| 426 | + break; |
|
| 427 | + case 'ORDER_VALIDATE': |
|
| 428 | + $link='/commande/card.php?id='.$object->id; |
|
| 429 | + $dir_output = $conf->commande->dir_output; |
|
| 430 | + $object_type = 'order'; |
|
| 431 | + $mesg = $outputlangs->transnoentitiesnoconv("EMailTextOrderValidated",$newref); |
|
| 432 | + break; |
|
| 433 | + case 'PROPAL_VALIDATE': |
|
| 434 | + $link='/comm/propal/card.php?id='.$object->id; |
|
| 435 | + $dir_output = $conf->propal->multidir_output[$object->entity]; |
|
| 436 | + $object_type = 'propal'; |
|
| 437 | + $mesg = $outputlangs->transnoentitiesnoconv("EMailTextProposalValidated",$newref); |
|
| 438 | + break; |
|
| 439 | + case 'PROPAL_CLOSE_SIGNED': |
|
| 440 | + $link='/comm/propal/card.php?id='.$object->id; |
|
| 441 | + $dir_output = $conf->propal->multidir_output[$object->entity]; |
|
| 442 | + $object_type = 'propal'; |
|
| 443 | + $mesg = $outputlangs->transnoentitiesnoconv("EMailTextProposalClosedSigned",$newref); |
|
| 444 | + break; |
|
| 445 | + case 'FICHINTER_ADD_CONTACT': |
|
| 446 | + $link='/fichinter/card.php?id='.$object->id; |
|
| 447 | + $dir_output = $conf->ficheinter->dir_output; |
|
| 448 | + $object_type = 'ficheinter'; |
|
| 449 | + $mesg = $outputlangs->transnoentitiesnoconv("EMailTextInterventionAddedContact",$newref); |
|
| 450 | + break; |
|
| 451 | + case 'FICHINTER_VALIDATE': |
|
| 452 | + $link='/fichinter/card.php?id='.$object->id; |
|
| 453 | + $dir_output = $conf->ficheinter->dir_output; |
|
| 454 | + $object_type = 'ficheinter'; |
|
| 455 | + $mesg = $outputlangs->transnoentitiesnoconv("EMailTextInterventionValidated",$newref); |
|
| 456 | + break; |
|
| 457 | + case 'ORDER_SUPPLIER_VALIDATE': |
|
| 458 | + $link='/fourn/commande/card.php?id='.$object->id; |
|
| 459 | + $dir_output = $conf->fournisseur->commande->dir_output; |
|
| 460 | + $object_type = 'order_supplier'; |
|
| 461 | + $mesg = $outputlangs->transnoentitiesnoconv("Hello").",\n\n"; |
|
| 462 | + $mesg.= $outputlangs->transnoentitiesnoconv("EMailTextOrderValidatedBy",$newref,$user->getFullName($langs)); |
|
| 463 | + $mesg.= "\n\n".$outputlangs->transnoentitiesnoconv("Sincerely").".\n\n"; |
|
| 464 | + break; |
|
| 465 | + case 'ORDER_SUPPLIER_APPROVE': |
|
| 466 | + $link='/fourn/commande/card.php?id='.$object->id; |
|
| 467 | + $dir_output = $conf->fournisseur->commande->dir_output; |
|
| 468 | + $object_type = 'order_supplier'; |
|
| 469 | + $mesg = $outputlangs->transnoentitiesnoconv("Hello").",\n\n"; |
|
| 470 | + $mesg.= $outputlangs->transnoentitiesnoconv("EMailTextOrderApprovedBy",$newref,$user->getFullName($langs)); |
|
| 471 | + $mesg.= "\n\n".$outputlangs->transnoentitiesnoconv("Sincerely").".\n\n"; |
|
| 472 | + break; |
|
| 473 | + case 'ORDER_SUPPLIER_REFUSE': |
|
| 474 | + $link='/fourn/commande/card.php?id='.$object->id; |
|
| 475 | + $dir_output = $conf->fournisseur->commande->dir_output; |
|
| 476 | + $object_type = 'order_supplier'; |
|
| 477 | + $mesg = $outputlangs->transnoentitiesnoconv("Hello").",\n\n"; |
|
| 478 | + $mesg.= $outputlangs->transnoentitiesnoconv("EMailTextOrderRefusedBy",$newref,$user->getFullName($langs)); |
|
| 479 | + $mesg.= "\n\n".$outputlangs->transnoentitiesnoconv("Sincerely").".\n\n"; |
|
| 480 | + break; |
|
| 481 | + case 'SHIPPING_VALIDATE': |
|
| 482 | + $dir_output = $conf->expedition->dir_output.'/sending/'; |
|
| 483 | + $object_type = 'order_supplier'; |
|
| 484 | + $mesg = $outputlangs->transnoentitiesnoconv("EMailTextExpeditionValidated",$newref); |
|
| 485 | + break; |
|
| 486 | + case 'EXPENSE_REPORT_VALIDATE': |
|
| 487 | + $dir_output = $conf->expensereport->dir_output; |
|
| 488 | + $object_type = 'expensereport'; |
|
| 489 | + $mesg = $outputlangs->transnoentitiesnoconv("EMailTextExpenseReportValidated",$newref); |
|
| 490 | + break; |
|
| 491 | + case 'EXPENSE_REPORT_APPROVE': |
|
| 492 | + $dir_output = $conf->expensereport->dir_output; |
|
| 493 | + $object_type = 'expensereport'; |
|
| 494 | + $mesg = $outputlangs->transnoentitiesnoconv("EMailTextExpenseReportApproved",$newref); |
|
| 495 | + break; |
|
| 496 | + case 'HOLIDAY_VALIDATE': |
|
| 497 | + $dir_output = $conf->holiday->dir_output; |
|
| 498 | + $object_type = 'holiday'; |
|
| 499 | + $mesg = $outputlangs->transnoentitiesnoconv("EMailTextHolidayValidated",$newref); |
|
| 500 | + break; |
|
| 501 | + case 'HOLIDAY_APPROVE': |
|
| 502 | + $dir_output = $conf->holiday->dir_output; |
|
| 503 | + $object_type = 'holiday'; |
|
| 504 | + $mesg = $outputlangs->transnoentitiesnoconv("EMailTextHolidayApproved",$newref); |
|
| 505 | + break; |
|
| 506 | + } |
|
| 507 | + $ref = dol_sanitizeFileName($newref); |
|
| 508 | + $pdf_path = $dir_output."/".$ref."/".$ref.".pdf"; |
|
| 509 | + if (! dol_is_file($pdf_path)) |
|
| 510 | + { |
|
| 511 | + // We can't add PDF as it is not generated yet. |
|
| 512 | + $filepdf = ''; |
|
| 513 | + } |
|
| 514 | + else |
|
| 515 | + { |
|
| 516 | + $filepdf = $pdf_path; |
|
| 517 | + } |
|
| 518 | + |
|
| 519 | + $message = $outputlangs->transnoentities("YouReceiveMailBecauseOfNotification",$application,$mysoc->name)."\n"; |
|
| 520 | + $message.= $outputlangs->transnoentities("YouReceiveMailBecauseOfNotification2",$application,$mysoc->name)."\n"; |
|
| 521 | + $message.= "\n"; |
|
| 522 | + $message.= $mesg; |
|
| 523 | + if ($link) $message.= "\n" . $urlwithroot . $link; |
|
| 524 | + |
|
| 525 | + $parameters=array('notifcode'=>$notifcode, 'sendto'=>$sendto, 'replyto'=>$replyto, 'file'=>$filename_list, 'mimefile'=>$mimetype_list, 'filename'=>$mimefilename_list); |
|
| 526 | + $reshook=$hookmanager->executeHooks('formatNotificationMessage',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks |
|
| 527 | + if (empty($reshook)) |
|
| 528 | + { |
|
| 529 | + if (! empty($hookmanager->resArray['subject'])) $subject.=$hookmanager->resArray['subject']; |
|
| 530 | + if (! empty($hookmanager->resArray['message'])) $message.=$hookmanager->resArray['message']; |
|
| 531 | + } |
|
| 532 | + |
|
| 533 | + $mailfile = new CMailFile( |
|
| 534 | + $subject, |
|
| 535 | + $sendto, |
|
| 536 | + $replyto, |
|
| 537 | + $message, |
|
| 538 | + $filename_list, |
|
| 539 | + $mimetype_list, |
|
| 540 | + $mimefilename_list, |
|
| 541 | + '', |
|
| 542 | + '', |
|
| 543 | + 0, |
|
| 544 | + -1 |
|
| 545 | + ); |
|
| 546 | + |
|
| 547 | + if ($mailfile->sendfile()) |
|
| 548 | + { |
|
| 549 | + if ($obj->type_target == 'touserid') { |
|
| 550 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_user, type, objet_type, type_target, objet_id, email)"; |
|
| 551 | + $sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".($object->socid?$object->socid:'null').", ".$obj->cid.", '".$obj->type."', '".$object_type."', '".$obj->type_target."', ".$object->id.", '".$this->db->escape($obj->email)."')"; |
|
| 552 | + } |
|
| 553 | + else { |
|
| 554 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, type_target, objet_id, email)"; |
|
| 555 | + $sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".($object->socid?$object->socid:'null').", ".$obj->cid.", '".$obj->type."', '".$object_type."', '".$obj->type_target."', ".$object->id.", '".$this->db->escape($obj->email)."')"; |
|
| 556 | + } |
|
| 557 | + if (! $this->db->query($sql)) |
|
| 558 | + { |
|
| 559 | + dol_print_error($this->db); |
|
| 560 | + } |
|
| 561 | + } |
|
| 562 | + else |
|
| 563 | + { |
|
| 564 | + $error++; |
|
| 565 | + $this->errors[]=$mailfile->error; |
|
| 566 | + } |
|
| 567 | + } |
|
| 568 | + else |
|
| 569 | + { |
|
| 570 | + dol_syslog("No notification sent for ".$sendto." because email is empty"); |
|
| 571 | + } |
|
| 572 | + $i++; |
|
| 573 | + } |
|
| 574 | + } |
|
| 575 | + else |
|
| 576 | + { |
|
| 577 | + dol_syslog("No notification to thirdparty sent, nothing into notification setup for the thirdparty socid = ".$object->socid); |
|
| 578 | + } |
|
| 579 | + } |
|
| 580 | + else |
|
| 581 | + { |
|
| 582 | + $error++; |
|
| 583 | + $this->errors[]=$this->db->lasterror(); |
|
| 584 | + dol_syslog("Failed to get list of notification to send ".$this->db->lasterror(), LOG_ERR); |
|
| 585 | + return -1; |
|
| 586 | + } |
|
| 587 | + |
|
| 588 | + // Check notification using fixed email |
|
| 589 | + if (! $error) |
|
| 590 | + { |
|
| 591 | + foreach($conf->global as $key => $val) |
|
| 592 | + { |
|
| 593 | + if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) continue; |
|
| 594 | + |
|
| 595 | + $threshold = (float) $reg[1]; |
|
| 596 | + if (!empty($object->total_ht) && $object->total_ht <= $threshold) |
|
| 597 | + { |
|
| 598 | + dol_syslog("A notification is requested for notifcode = ".$notifcode." but amount = ".$object->total_ht." so lower than threshold = ".$threshold.". We discard this notification"); |
|
| 599 | + continue; |
|
| 600 | + } |
|
| 601 | + |
|
| 602 | + $param='NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_'.$reg[1]; |
|
| 603 | + |
|
| 604 | + $sendto = $conf->global->$param; |
|
| 605 | + $notifcodedefid = dol_getIdFromCode($this->db, $notifcode, 'c_action_trigger', 'code', 'rowid'); |
|
| 606 | + if ($notifcodedefid <= 0) dol_print_error($this->db, 'Failed to get id from code'); |
|
| 607 | + |
|
| 608 | + $object_type = ''; |
|
| 609 | + $link = ''; |
|
| 610 | + $num++; |
|
| 611 | + |
|
| 612 | + $subject = '['.$mysoc->name.'] '.$langs->transnoentitiesnoconv("DolibarrNotification").($projtitle?' '.$projtitle:''); |
|
| 613 | + |
|
| 614 | + switch ($notifcode) { |
|
| 615 | + case 'BILL_VALIDATE': |
|
| 616 | + $link = '<a href="' . $urlwithroot . '/compta/facture/card.php?facid=' . $object->id . '">' . $newref . '</a>'; |
|
| 617 | + $dir_output = $conf->facture->dir_output; |
|
| 618 | + $object_type = 'facture'; |
|
| 619 | + $mesg = $langs->transnoentitiesnoconv("EMailTextInvoiceValidated",$link); |
|
| 620 | + break; |
|
| 621 | + case 'BILL_PAYED': |
|
| 622 | + $link ='<a href="' . $urlwithroot . '/compta/facture/card.php?facid='.$object->id . '">' . $newref . '</a>'; |
|
| 623 | + $dir_output = $conf->facture->dir_output; |
|
| 624 | + $object_type = 'facture'; |
|
| 625 | + $mesg = $langs->transnoentitiesnoconv("EMailTextInvoicePayed",$link); |
|
| 626 | + break; |
|
| 627 | + case 'ORDER_VALIDATE': |
|
| 628 | + $link = '<a href="' . $urlwithroot . '/commande/card.php?id='.$object->id . '">' . $newref . '</a>'; |
|
| 629 | + $dir_output = $conf->commande->dir_output; |
|
| 630 | + $object_type = 'order'; |
|
| 631 | + $mesg = $langs->transnoentitiesnoconv("EMailTextOrderValidated",$link); |
|
| 632 | + break; |
|
| 633 | + case 'PROPAL_VALIDATE': |
|
| 634 | + $link = '<a href="' . $urlwithroot . '/comm/propal/card.php?id='.$object->id . '">' . $newref . '</a>'; |
|
| 635 | + $dir_output = $conf->propal->multidir_output[$object->entity]; |
|
| 636 | + $object_type = 'propal'; |
|
| 637 | + $mesg = $langs->transnoentitiesnoconv("EMailTextProposalValidated",$link); |
|
| 638 | + break; |
|
| 639 | + case 'PROPAL_CLOSE_SIGNED': |
|
| 640 | + $link = '<a href="' . $urlwithroot . '/comm/propal/card.php?id='.$object->id . '">' . $newref . '</a>'; |
|
| 641 | + $dir_output = $conf->propal->multidir_output[$object->entity]; |
|
| 642 | + $object_type = 'propal'; |
|
| 643 | + $mesg = $langs->transnoentitiesnoconv("EMailTextProposalClosedSigned",$link); |
|
| 644 | + break; |
|
| 645 | + case 'FICHINTER_ADD_CONTACT': |
|
| 646 | + $link = '<a href="' . $urlwithroot . '/fichinter/card.php?id='.$object->id . '">' . $newref . '</a>'; |
|
| 647 | + $dir_output = $conf->facture->dir_output; |
|
| 648 | + $object_type = 'ficheinter'; |
|
| 649 | + $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionAddedContact",$link); |
|
| 650 | + break; |
|
| 651 | + case 'FICHINTER_VALIDATE': |
|
| 652 | + $link = '<a href="' . $urlwithroot . '/fichinter/card.php?id='.$object->id . '">' . $newref . '</a>'; |
|
| 653 | + $dir_output = $conf->facture->dir_output; |
|
| 654 | + $object_type = 'ficheinter'; |
|
| 655 | + $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionValidated",$link); |
|
| 656 | + break; |
|
| 657 | + case 'ORDER_SUPPLIER_VALIDATE': |
|
| 658 | + $link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id='.$object->id . '">' . $newref . '</a>'; |
|
| 659 | + $dir_output = $conf->fournisseur->commande->dir_output; |
|
| 660 | + $object_type = 'order_supplier'; |
|
| 661 | + $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n"; |
|
| 662 | + $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderValidatedBy",$link,$user->getFullName($langs)); |
|
| 663 | + $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n"; |
|
| 664 | + break; |
|
| 665 | + case 'ORDER_SUPPLIER_APPROVE': |
|
| 666 | + $link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id='.$object->id . '">' . $newref . '</a>'; |
|
| 667 | + $dir_output = $conf->fournisseur->commande->dir_output; |
|
| 668 | + $object_type = 'order_supplier'; |
|
| 669 | + $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n"; |
|
| 670 | + $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy",$link,$user->getFullName($langs)); |
|
| 671 | + $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n"; |
|
| 672 | + break; |
|
| 673 | + case 'ORDER_SUPPLIER_APPROVE2': |
|
| 674 | + $link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id='.$object->id . '">' . $newref . '</a>'; |
|
| 675 | + $dir_output = $conf->fournisseur->commande->dir_output; |
|
| 676 | + $object_type = 'order_supplier'; |
|
| 677 | + $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n"; |
|
| 678 | + $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy",$link,$user->getFullName($langs)); |
|
| 679 | + $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n"; |
|
| 680 | + break; |
|
| 681 | + case 'ORDER_SUPPLIER_REFUSE': |
|
| 682 | + $link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id='.$object->id . '">' . $newref . '</a>'; |
|
| 683 | + $dir_output = $conf->fournisseur->dir_output.'/commande/'; |
|
| 684 | + $object_type = 'order_supplier'; |
|
| 685 | + $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n"; |
|
| 686 | + $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderRefusedBy",$link,$user->getFullName($langs)); |
|
| 687 | + $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n"; |
|
| 688 | + break; |
|
| 689 | + case 'SHIPPING_VALIDATE': |
|
| 690 | + $dir_output = $conf->expedition->dir_output.'/sending/'; |
|
| 691 | + $object_type = 'order_supplier'; |
|
| 692 | + $mesg = $langs->transnoentitiesnoconv("EMailTextExpeditionValidated",$newref); |
|
| 693 | + break; |
|
| 694 | + case 'EXPENSE_REPORT_VALIDATE': |
|
| 695 | + $dir_output = $conf->expensereport->dir_output; |
|
| 696 | + $object_type = 'expensereport'; |
|
| 697 | + $mesg = $langs->transnoentitiesnoconv("EMailTextExpenseReportValidated",$newref); |
|
| 698 | + break; |
|
| 699 | + case 'EXPENSE_REPORT_APPROVE': |
|
| 700 | + $dir_output = $conf->expensereport->dir_output; |
|
| 701 | + $object_type = 'expensereport'; |
|
| 702 | + $mesg = $langs->transnoentitiesnoconv("EMailTextExpenseReportApproved",$newref); |
|
| 703 | + break; |
|
| 704 | + case 'HOLIDAY_VALIDATE': |
|
| 705 | + $dir_output = $conf->holiday->dir_output; |
|
| 706 | + $object_type = 'holiday'; |
|
| 707 | + $mesg = $langs->transnoentitiesnoconv("EMailTextHolidayValidated",$newref); |
|
| 708 | + break; |
|
| 709 | + case 'HOLIDAY_APPROVE': |
|
| 710 | + $dir_output = $conf->holiday->dir_output; |
|
| 711 | + $object_type = 'holiday'; |
|
| 712 | + $mesg = $langs->transnoentitiesnoconv("EMailTextHolidayApproved",$newref); |
|
| 713 | + break; |
|
| 714 | + } |
|
| 715 | + $ref = dol_sanitizeFileName($newref); |
|
| 716 | + $pdf_path = $dir_output."/".$ref."/".$ref.".pdf"; |
|
| 717 | + if (! dol_is_file($pdf_path)) |
|
| 718 | + { |
|
| 719 | + // We can't add PDF as it is not generated yet. |
|
| 720 | + $filepdf = ''; |
|
| 721 | + } |
|
| 722 | + else |
|
| 723 | + { |
|
| 724 | + $filepdf = $pdf_path; |
|
| 725 | + } |
|
| 726 | + |
|
| 727 | + $message = $langs->transnoentities("YouReceiveMailBecauseOfNotification",$application,$mysoc->name)."\n"; |
|
| 728 | + $message.= $langs->transnoentities("YouReceiveMailBecauseOfNotification2",$application,$mysoc->name)."\n"; |
|
| 729 | + $message.= "\n"; |
|
| 730 | + $message.= $mesg; |
|
| 731 | + //if ($link) $message.= "\n" . $urlwithroot . $link; // link already added around the ref into the text |
|
| 732 | + |
|
| 733 | + $message = nl2br($message); |
|
| 734 | + |
|
| 735 | + // Replace keyword __SUPERVISOREMAIL__ |
|
| 736 | + if (preg_match('/__SUPERVISOREMAIL__/', $sendto)) |
|
| 737 | + { |
|
| 738 | + $newval=''; |
|
| 739 | + if ($user->fk_user > 0) |
|
| 740 | + { |
|
| 741 | + $supervisoruser=new User($this->db); |
|
| 742 | + $supervisoruser->fetch($user->fk_user); |
|
| 743 | + if ($supervisoruser->email) $newval=trim(dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).' <'.$supervisoruser->email.'>'); |
|
| 744 | + } |
|
| 745 | + dol_syslog("Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval); |
|
| 746 | + $sendto = preg_replace('/__SUPERVISOREMAIL__/', $newval, $sendto); |
|
| 747 | + $sendto = preg_replace('/,\s*,/', ',', $sendto); // in some case you can have $sendto like "email, __SUPERVISOREMAIL__ , otheremail" then you have "email, , othermail" and it's not valid |
|
| 748 | + $sendto = preg_replace('/^[\s,]+/', '', $sendto); // Clean start of string |
|
| 749 | + $sendto = preg_replace('/[\s,]+$/', '', $sendto); // Clean end of string |
|
| 750 | + } |
|
| 751 | + |
|
| 752 | + if ($sendto) |
|
| 753 | + { |
|
| 754 | + $parameters=array('notifcode'=>$notifcode, 'sendto'=>$sendto, 'replyto'=>$replyto, 'file'=>$filename_list, 'mimefile'=>$mimetype_list, 'filename'=>$mimefilename_list); |
|
| 755 | + $reshook=$hookmanager->executeHooks('formatNotificationMessage',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks |
|
| 756 | + if (empty($reshook)) |
|
| 757 | + { |
|
| 758 | + if (! empty($hookmanager->resArray['subject'])) $subject.=$hookmanager->resArray['subject']; |
|
| 759 | + if (! empty($hookmanager->resArray['message'])) $message.=$hookmanager->resArray['message']; |
|
| 760 | + } |
|
| 761 | + $mailfile = new CMailFile( |
|
| 762 | + $subject, |
|
| 763 | + $sendto, |
|
| 764 | + $replyto, |
|
| 765 | + $message, |
|
| 766 | + $filename_list, |
|
| 767 | + $mimetype_list, |
|
| 768 | + $mimefilename_list, |
|
| 769 | + '', |
|
| 770 | + '', |
|
| 771 | + 0, |
|
| 772 | + 1 |
|
| 773 | + ); |
|
| 774 | + |
|
| 775 | + if ($mailfile->sendfile()) |
|
| 776 | + { |
|
| 777 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_contact, type, type_target, objet_type, objet_id, email)"; |
|
| 778 | + $sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".($object->socid?$object->socid:'null').", null, 'email', 'tofixedemail', '".$object_type."', ".$object->id.", '".$this->db->escape($conf->global->$param)."')"; |
|
| 779 | + if (! $this->db->query($sql)) |
|
| 780 | + { |
|
| 781 | + dol_print_error($this->db); |
|
| 782 | + } |
|
| 783 | + } |
|
| 784 | + else |
|
| 785 | + { |
|
| 786 | + $error++; |
|
| 787 | + $this->errors[]=$mailfile->error; |
|
| 788 | + } |
|
| 789 | + } |
|
| 790 | + } |
|
| 791 | + } |
|
| 792 | + |
|
| 793 | + if (! $error) return $num; |
|
| 794 | + else return -1 * $error; |
|
| 795 | + } |
|
| 796 | 796 | } |
@@ -33,115 +33,115 @@ |
||
| 33 | 33 | */ |
| 34 | 34 | class DolGeoIP |
| 35 | 35 | { |
| 36 | - var $gi; |
|
| 36 | + var $gi; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Constructor |
|
| 40 | - * |
|
| 41 | - * @param string $type 'country' or 'city' |
|
| 42 | - * @param string $datfile Data file |
|
| 43 | - */ |
|
| 44 | - function __construct($type,$datfile) |
|
| 45 | - { |
|
| 46 | - if ($type == 'country') |
|
| 47 | - { |
|
| 48 | - // geoip may have been already included with PEAR |
|
| 49 | - if (! function_exists('geoip_country_code_by_name')) $res=include_once GEOIP_PATH.'geoip.inc'; |
|
| 50 | - } |
|
| 51 | - else if ($type == 'city') |
|
| 52 | - { |
|
| 53 | - // geoip may have been already included with PEAR |
|
| 54 | - if (! function_exists('geoip_country_code_by_name')) $res=include_once GEOIP_PATH.'geoipcity.inc'; |
|
| 55 | - } |
|
| 56 | - else { print 'ErrorBadParameterInConstructor'; return 0; } |
|
| 38 | + /** |
|
| 39 | + * Constructor |
|
| 40 | + * |
|
| 41 | + * @param string $type 'country' or 'city' |
|
| 42 | + * @param string $datfile Data file |
|
| 43 | + */ |
|
| 44 | + function __construct($type,$datfile) |
|
| 45 | + { |
|
| 46 | + if ($type == 'country') |
|
| 47 | + { |
|
| 48 | + // geoip may have been already included with PEAR |
|
| 49 | + if (! function_exists('geoip_country_code_by_name')) $res=include_once GEOIP_PATH.'geoip.inc'; |
|
| 50 | + } |
|
| 51 | + else if ($type == 'city') |
|
| 52 | + { |
|
| 53 | + // geoip may have been already included with PEAR |
|
| 54 | + if (! function_exists('geoip_country_code_by_name')) $res=include_once GEOIP_PATH.'geoipcity.inc'; |
|
| 55 | + } |
|
| 56 | + else { print 'ErrorBadParameterInConstructor'; return 0; } |
|
| 57 | 57 | |
| 58 | - // Here, function exists (embedded into PHP or exists because we made include) |
|
| 59 | - if (empty($type) || empty($datfile)) |
|
| 60 | - { |
|
| 61 | - $this->errorlabel='Constructor was called with no datafile parameter'; |
|
| 62 | - dol_syslog('DolGeoIP '.$this->errorlabel, LOG_ERR); |
|
| 63 | - return 0; |
|
| 64 | - } |
|
| 65 | - if (! file_exists($datfile) || ! is_readable($datfile)) |
|
| 66 | - { |
|
| 67 | - $this->error='ErrorGeoIPClassNotInitialized'; |
|
| 68 | - $this->errorlabel="Datafile ".$datfile." not found"; |
|
| 69 | - dol_syslog('DolGeoIP '.$this->errorlabel, LOG_ERR); |
|
| 70 | - return 0; |
|
| 71 | - } |
|
| 58 | + // Here, function exists (embedded into PHP or exists because we made include) |
|
| 59 | + if (empty($type) || empty($datfile)) |
|
| 60 | + { |
|
| 61 | + $this->errorlabel='Constructor was called with no datafile parameter'; |
|
| 62 | + dol_syslog('DolGeoIP '.$this->errorlabel, LOG_ERR); |
|
| 63 | + return 0; |
|
| 64 | + } |
|
| 65 | + if (! file_exists($datfile) || ! is_readable($datfile)) |
|
| 66 | + { |
|
| 67 | + $this->error='ErrorGeoIPClassNotInitialized'; |
|
| 68 | + $this->errorlabel="Datafile ".$datfile." not found"; |
|
| 69 | + dol_syslog('DolGeoIP '.$this->errorlabel, LOG_ERR); |
|
| 70 | + return 0; |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - if (function_exists('geoip_open')) |
|
| 74 | - { |
|
| 75 | - $this->gi = geoip_open($datfile,GEOIP_STANDARD); |
|
| 76 | - } |
|
| 77 | - else |
|
| 78 | - { |
|
| 79 | - $this->gi = 'NOGI'; // We are using embedded php geoip functions |
|
| 80 | - //print 'function_exists(geoip_country_code_by_name))='.function_exists('geoip_country_code_by_name'); |
|
| 81 | - //print geoip_database_info(); |
|
| 82 | - } |
|
| 83 | - } |
|
| 73 | + if (function_exists('geoip_open')) |
|
| 74 | + { |
|
| 75 | + $this->gi = geoip_open($datfile,GEOIP_STANDARD); |
|
| 76 | + } |
|
| 77 | + else |
|
| 78 | + { |
|
| 79 | + $this->gi = 'NOGI'; // We are using embedded php geoip functions |
|
| 80 | + //print 'function_exists(geoip_country_code_by_name))='.function_exists('geoip_country_code_by_name'); |
|
| 81 | + //print geoip_database_info(); |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * Return in lower case the country code from an ip |
|
| 87 | - * |
|
| 88 | - * @param string $ip IP to scan |
|
| 89 | - * @return string Country code (two letters) |
|
| 90 | - */ |
|
| 91 | - function getCountryCodeFromIP($ip) |
|
| 92 | - { |
|
| 93 | - if (empty($this->gi)) |
|
| 94 | - { |
|
| 95 | - return ''; |
|
| 96 | - } |
|
| 97 | - if ($this->gi == 'NOGI') |
|
| 98 | - { |
|
| 99 | - // geoip_country_code_by_addr does not exists |
|
| 100 | - return strtolower(geoip_country_code_by_name($ip)); |
|
| 101 | - } |
|
| 102 | - else |
|
| 103 | - { |
|
| 104 | - if (! function_exists('geoip_country_code_by_addr')) return strtolower(geoip_country_code_by_name($this->gi, $ip)); |
|
| 105 | - return strtolower(geoip_country_code_by_addr($this->gi, $ip)); |
|
| 106 | - } |
|
| 107 | - } |
|
| 85 | + /** |
|
| 86 | + * Return in lower case the country code from an ip |
|
| 87 | + * |
|
| 88 | + * @param string $ip IP to scan |
|
| 89 | + * @return string Country code (two letters) |
|
| 90 | + */ |
|
| 91 | + function getCountryCodeFromIP($ip) |
|
| 92 | + { |
|
| 93 | + if (empty($this->gi)) |
|
| 94 | + { |
|
| 95 | + return ''; |
|
| 96 | + } |
|
| 97 | + if ($this->gi == 'NOGI') |
|
| 98 | + { |
|
| 99 | + // geoip_country_code_by_addr does not exists |
|
| 100 | + return strtolower(geoip_country_code_by_name($ip)); |
|
| 101 | + } |
|
| 102 | + else |
|
| 103 | + { |
|
| 104 | + if (! function_exists('geoip_country_code_by_addr')) return strtolower(geoip_country_code_by_name($this->gi, $ip)); |
|
| 105 | + return strtolower(geoip_country_code_by_addr($this->gi, $ip)); |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * Return in lower case the country code from a host name |
|
| 111 | - * |
|
| 112 | - * @param string $name FQN of host (example: myserver.xyz.com) |
|
| 113 | - * @return string Country code (two letters) |
|
| 114 | - */ |
|
| 115 | - function getCountryCodeFromName($name) |
|
| 116 | - { |
|
| 117 | - if (empty($this->gi)) |
|
| 118 | - { |
|
| 119 | - return ''; |
|
| 120 | - } |
|
| 121 | - return geoip_country_code_by_name($this->gi, $name); |
|
| 122 | - } |
|
| 109 | + /** |
|
| 110 | + * Return in lower case the country code from a host name |
|
| 111 | + * |
|
| 112 | + * @param string $name FQN of host (example: myserver.xyz.com) |
|
| 113 | + * @return string Country code (two letters) |
|
| 114 | + */ |
|
| 115 | + function getCountryCodeFromName($name) |
|
| 116 | + { |
|
| 117 | + if (empty($this->gi)) |
|
| 118 | + { |
|
| 119 | + return ''; |
|
| 120 | + } |
|
| 121 | + return geoip_country_code_by_name($this->gi, $name); |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | - /** |
|
| 125 | - * Return verion of data file |
|
| 126 | - * |
|
| 127 | - * @return string Version of datafile |
|
| 128 | - */ |
|
| 129 | - function getVersion() |
|
| 130 | - { |
|
| 131 | - if ($this->gi == 'NOGI') return geoip_database_info(); |
|
| 132 | - return 'Not available (not using PHP internal geo functions)'; |
|
| 133 | - } |
|
| 124 | + /** |
|
| 125 | + * Return verion of data file |
|
| 126 | + * |
|
| 127 | + * @return string Version of datafile |
|
| 128 | + */ |
|
| 129 | + function getVersion() |
|
| 130 | + { |
|
| 131 | + if ($this->gi == 'NOGI') return geoip_database_info(); |
|
| 132 | + return 'Not available (not using PHP internal geo functions)'; |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - /** |
|
| 136 | - * Close geoip object |
|
| 137 | - * |
|
| 138 | - * @return void |
|
| 139 | - */ |
|
| 140 | - function close() |
|
| 141 | - { |
|
| 142 | - if (function_exists('geoip_close')) // With some geoip with PEAR, geoip_close function may not exists |
|
| 143 | - { |
|
| 144 | - geoip_close($this->gi); |
|
| 145 | - } |
|
| 146 | - } |
|
| 135 | + /** |
|
| 136 | + * Close geoip object |
|
| 137 | + * |
|
| 138 | + * @return void |
|
| 139 | + */ |
|
| 140 | + function close() |
|
| 141 | + { |
|
| 142 | + if (function_exists('geoip_close')) // With some geoip with PEAR, geoip_close function may not exists |
|
| 143 | + { |
|
| 144 | + geoip_close($this->gi); |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | 147 | } |
@@ -29,116 +29,22 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | abstract class Stats |
| 31 | 31 | { |
| 32 | - protected $db; |
|
| 33 | - var $_lastfetchdate=array(); // Dates of cache file read by methods |
|
| 34 | - var $cachefilesuffix=''; // Suffix to add to name of cache file (to avoid file name conflicts) |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Return nb of elements by month for several years |
|
| 38 | - * |
|
| 39 | - * @param int $endyear Start year |
|
| 40 | - * @param int $startyear End year |
|
| 41 | - * @param int $cachedelay Delay we accept for cache file (0=No read, no save of cache, -1=No read but save) |
|
| 32 | + protected $db; |
|
| 33 | + var $_lastfetchdate=array(); // Dates of cache file read by methods |
|
| 34 | + var $cachefilesuffix=''; // Suffix to add to name of cache file (to avoid file name conflicts) |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Return nb of elements by month for several years |
|
| 38 | + * |
|
| 39 | + * @param int $endyear Start year |
|
| 40 | + * @param int $startyear End year |
|
| 41 | + * @param int $cachedelay Delay we accept for cache file (0=No read, no save of cache, -1=No read but save) |
|
| 42 | 42 | * @param int $format 0=Label of absiss is a translated text, 1=Label of absiss is month number, 2=Label of absiss is first letter of month |
| 43 | - * @return array Array of values |
|
| 44 | - */ |
|
| 45 | - function getNbByMonthWithPrevYear($endyear, $startyear, $cachedelay=0, $format=0) |
|
| 46 | - { |
|
| 47 | - global $conf,$user,$langs; |
|
| 48 | - |
|
| 49 | - if ($startyear > $endyear) return -1; |
|
| 50 | - |
|
| 51 | - $datay=array(); |
|
| 52 | - |
|
| 53 | - // Search into cache |
|
| 54 | - if (! empty($cachedelay)) |
|
| 55 | - { |
|
| 56 | - include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
| 57 | - include_once DOL_DOCUMENT_ROOT.'/core/lib/json.lib.php'; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - $newpathofdestfile=$conf->user->dir_temp.'/'.get_class($this).'_'.__FUNCTION__.'_'.(empty($this->cachefilesuffix)?'':$this->cachefilesuffix.'_').$langs->defaultlang.'_entity.'.$conf->entity.'_user'.$user->id.'.cache'; |
|
| 61 | - $newmask='0644'; |
|
| 62 | - |
|
| 63 | - $nowgmt = dol_now(); |
|
| 64 | - |
|
| 65 | - $foundintocache=0; |
|
| 66 | - if ($cachedelay > 0) |
|
| 67 | - { |
|
| 68 | - $filedate=dol_filemtime($newpathofdestfile); |
|
| 69 | - if ($filedate >= ($nowgmt - $cachedelay)) |
|
| 70 | - { |
|
| 71 | - $foundintocache=1; |
|
| 72 | - |
|
| 73 | - $this->_lastfetchdate[get_class($this).'_'.__FUNCTION__]=$filedate; |
|
| 74 | - } |
|
| 75 | - else |
|
| 76 | - { |
|
| 77 | - dol_syslog(get_class($this).'::'.__FUNCTION__." cache file ".$newpathofdestfile." is not found or older than now - cachedelay (".$nowgmt." - ".$cachedelay.") so we can't use it."); |
|
| 78 | - } |
|
| 79 | - } |
|
| 80 | - // Load file into $data |
|
| 81 | - if ($foundintocache) // Cache file found and is not too old |
|
| 82 | - { |
|
| 83 | - dol_syslog(get_class($this).'::'.__FUNCTION__." read data from cache file ".$newpathofdestfile." ".$filedate."."); |
|
| 84 | - $data = json_decode(file_get_contents($newpathofdestfile), true); |
|
| 85 | - } |
|
| 86 | - else |
|
| 87 | - { |
|
| 88 | - $year=$startyear; |
|
| 89 | - while ($year <= $endyear) |
|
| 90 | - { |
|
| 91 | - $datay[$year] = $this->getNbByMonth($year, $format); |
|
| 92 | - $year++; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - $data = array(); |
|
| 96 | - |
|
| 97 | - for ($i = 0 ; $i < 12 ; $i++) |
|
| 98 | - { |
|
| 99 | - $data[$i][]=$datay[$endyear][$i][0]; |
|
| 100 | - $year=$startyear; |
|
| 101 | - while($year <= $endyear) |
|
| 102 | - { |
|
| 103 | - $data[$i][]=$datay[$year][$i][1]; |
|
| 104 | - $year++; |
|
| 105 | - } |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - // Save cache file |
|
| 110 | - if (empty($foundintocache) && ($cachedelay > 0 || $cachedelay == -1)) |
|
| 111 | - { |
|
| 112 | - dol_syslog(get_class($this).'::'.__FUNCTION__." save cache file ".$newpathofdestfile." onto disk."); |
|
| 113 | - if (! dol_is_dir($conf->user->dir_temp)) dol_mkdir($conf->user->dir_temp); |
|
| 114 | - $fp = fopen($newpathofdestfile, 'w'); |
|
| 115 | - fwrite($fp, json_encode($data)); |
|
| 116 | - fclose($fp); |
|
| 117 | - if (! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK; |
|
| 118 | - @chmod($newpathofdestfile, octdec($newmask)); |
|
| 119 | - |
|
| 120 | - $this->_lastfetchdate[get_class($this).'_'.__FUNCTION__]=$nowgmt; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - // return array(array('Month',val1,val2,val3),...) |
|
| 124 | - return $data; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * Return amount of elements by month for several years. |
|
| 129 | - * Criterias used to build request are defined into the constructor of parent class into xxx/class/xxxstats.class.php |
|
| 130 | - * The caller of class can add more filters into sql request by adding criteris into the $stats->where property just after |
|
| 131 | - * calling constructor. |
|
| 132 | - * |
|
| 133 | - * @param int $endyear Start year |
|
| 134 | - * @param int $startyear End year |
|
| 135 | - * @param int $cachedelay Delay we accept for cache file (0=No read, no save of cache, -1=No read but save) |
|
| 136 | - * @param int $format 0=Label of absiss is a translated text, 1=Label of absiss is month number, 2=Label of absiss is first letter of month |
|
| 137 | - * @return array Array of values |
|
| 138 | - */ |
|
| 139 | - function getAmountByMonthWithPrevYear($endyear, $startyear, $cachedelay=0, $format=0) |
|
| 140 | - { |
|
| 141 | - global $conf,$user,$langs; |
|
| 43 | + * @return array Array of values |
|
| 44 | + */ |
|
| 45 | + function getNbByMonthWithPrevYear($endyear, $startyear, $cachedelay=0, $format=0) |
|
| 46 | + { |
|
| 47 | + global $conf,$user,$langs; |
|
| 142 | 48 | |
| 143 | 49 | if ($startyear > $endyear) return -1; |
| 144 | 50 | |
@@ -147,8 +53,8 @@ discard block |
||
| 147 | 53 | // Search into cache |
| 148 | 54 | if (! empty($cachedelay)) |
| 149 | 55 | { |
| 150 | - include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
| 151 | - include_once DOL_DOCUMENT_ROOT.'/core/lib/json.lib.php'; |
|
| 56 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
| 57 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/json.lib.php'; |
|
| 152 | 58 | } |
| 153 | 59 | |
| 154 | 60 | $newpathofdestfile=$conf->user->dir_temp.'/'.get_class($this).'_'.__FUNCTION__.'_'.(empty($this->cachefilesuffix)?'':$this->cachefilesuffix.'_').$langs->defaultlang.'_entity.'.$conf->entity.'_user'.$user->id.'.cache'; |
@@ -159,122 +65,216 @@ discard block |
||
| 159 | 65 | $foundintocache=0; |
| 160 | 66 | if ($cachedelay > 0) |
| 161 | 67 | { |
| 162 | - $filedate=dol_filemtime($newpathofdestfile); |
|
| 163 | - if ($filedate >= ($nowgmt - $cachedelay)) |
|
| 164 | - { |
|
| 165 | - $foundintocache=1; |
|
| 68 | + $filedate=dol_filemtime($newpathofdestfile); |
|
| 69 | + if ($filedate >= ($nowgmt - $cachedelay)) |
|
| 70 | + { |
|
| 71 | + $foundintocache=1; |
|
| 72 | + |
|
| 73 | + $this->_lastfetchdate[get_class($this).'_'.__FUNCTION__]=$filedate; |
|
| 74 | + } |
|
| 75 | + else |
|
| 76 | + { |
|
| 77 | + dol_syslog(get_class($this).'::'.__FUNCTION__." cache file ".$newpathofdestfile." is not found or older than now - cachedelay (".$nowgmt." - ".$cachedelay.") so we can't use it."); |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + // Load file into $data |
|
| 81 | + if ($foundintocache) // Cache file found and is not too old |
|
| 82 | + { |
|
| 83 | + dol_syslog(get_class($this).'::'.__FUNCTION__." read data from cache file ".$newpathofdestfile." ".$filedate."."); |
|
| 84 | + $data = json_decode(file_get_contents($newpathofdestfile), true); |
|
| 85 | + } |
|
| 86 | + else |
|
| 87 | + { |
|
| 88 | + $year=$startyear; |
|
| 89 | + while ($year <= $endyear) |
|
| 90 | + { |
|
| 91 | + $datay[$year] = $this->getNbByMonth($year, $format); |
|
| 92 | + $year++; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + $data = array(); |
|
| 96 | + |
|
| 97 | + for ($i = 0 ; $i < 12 ; $i++) |
|
| 98 | + { |
|
| 99 | + $data[$i][]=$datay[$endyear][$i][0]; |
|
| 100 | + $year=$startyear; |
|
| 101 | + while($year <= $endyear) |
|
| 102 | + { |
|
| 103 | + $data[$i][]=$datay[$year][$i][1]; |
|
| 104 | + $year++; |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + // Save cache file |
|
| 110 | + if (empty($foundintocache) && ($cachedelay > 0 || $cachedelay == -1)) |
|
| 111 | + { |
|
| 112 | + dol_syslog(get_class($this).'::'.__FUNCTION__." save cache file ".$newpathofdestfile." onto disk."); |
|
| 113 | + if (! dol_is_dir($conf->user->dir_temp)) dol_mkdir($conf->user->dir_temp); |
|
| 114 | + $fp = fopen($newpathofdestfile, 'w'); |
|
| 115 | + fwrite($fp, json_encode($data)); |
|
| 116 | + fclose($fp); |
|
| 117 | + if (! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK; |
|
| 118 | + @chmod($newpathofdestfile, octdec($newmask)); |
|
| 119 | + |
|
| 120 | + $this->_lastfetchdate[get_class($this).'_'.__FUNCTION__]=$nowgmt; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + // return array(array('Month',val1,val2,val3),...) |
|
| 124 | + return $data; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * Return amount of elements by month for several years. |
|
| 129 | + * Criterias used to build request are defined into the constructor of parent class into xxx/class/xxxstats.class.php |
|
| 130 | + * The caller of class can add more filters into sql request by adding criteris into the $stats->where property just after |
|
| 131 | + * calling constructor. |
|
| 132 | + * |
|
| 133 | + * @param int $endyear Start year |
|
| 134 | + * @param int $startyear End year |
|
| 135 | + * @param int $cachedelay Delay we accept for cache file (0=No read, no save of cache, -1=No read but save) |
|
| 136 | + * @param int $format 0=Label of absiss is a translated text, 1=Label of absiss is month number, 2=Label of absiss is first letter of month |
|
| 137 | + * @return array Array of values |
|
| 138 | + */ |
|
| 139 | + function getAmountByMonthWithPrevYear($endyear, $startyear, $cachedelay=0, $format=0) |
|
| 140 | + { |
|
| 141 | + global $conf,$user,$langs; |
|
| 166 | 142 | |
| 167 | - $this->_lastfetchdate[get_class($this).'_'.__FUNCTION__]=$filedate; |
|
| 168 | - } |
|
| 169 | - else |
|
| 170 | - { |
|
| 171 | - dol_syslog(get_class($this).'::'.__FUNCTION__." cache file ".$newpathofdestfile." is not found or older than now - cachedelay (".$nowgmt." - ".$cachedelay.") so we can't use it."); |
|
| 172 | - } |
|
| 143 | + if ($startyear > $endyear) return -1; |
|
| 144 | + |
|
| 145 | + $datay=array(); |
|
| 146 | + |
|
| 147 | + // Search into cache |
|
| 148 | + if (! empty($cachedelay)) |
|
| 149 | + { |
|
| 150 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
| 151 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/json.lib.php'; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + $newpathofdestfile=$conf->user->dir_temp.'/'.get_class($this).'_'.__FUNCTION__.'_'.(empty($this->cachefilesuffix)?'':$this->cachefilesuffix.'_').$langs->defaultlang.'_entity.'.$conf->entity.'_user'.$user->id.'.cache'; |
|
| 155 | + $newmask='0644'; |
|
| 156 | + |
|
| 157 | + $nowgmt = dol_now(); |
|
| 158 | + |
|
| 159 | + $foundintocache=0; |
|
| 160 | + if ($cachedelay > 0) |
|
| 161 | + { |
|
| 162 | + $filedate=dol_filemtime($newpathofdestfile); |
|
| 163 | + if ($filedate >= ($nowgmt - $cachedelay)) |
|
| 164 | + { |
|
| 165 | + $foundintocache=1; |
|
| 166 | + |
|
| 167 | + $this->_lastfetchdate[get_class($this).'_'.__FUNCTION__]=$filedate; |
|
| 168 | + } |
|
| 169 | + else |
|
| 170 | + { |
|
| 171 | + dol_syslog(get_class($this).'::'.__FUNCTION__." cache file ".$newpathofdestfile." is not found or older than now - cachedelay (".$nowgmt." - ".$cachedelay.") so we can't use it."); |
|
| 172 | + } |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | // Load file into $data |
| 176 | 176 | if ($foundintocache) // Cache file found and is not too old |
| 177 | 177 | { |
| 178 | - dol_syslog(get_class($this).'::'.__FUNCTION__." read data from cache file ".$newpathofdestfile." ".$filedate."."); |
|
| 179 | - $data = json_decode(file_get_contents($newpathofdestfile), true); |
|
| 178 | + dol_syslog(get_class($this).'::'.__FUNCTION__." read data from cache file ".$newpathofdestfile." ".$filedate."."); |
|
| 179 | + $data = json_decode(file_get_contents($newpathofdestfile), true); |
|
| 180 | 180 | } |
| 181 | 181 | else |
| 182 | - { |
|
| 183 | - $year=$startyear; |
|
| 184 | - while($year <= $endyear) |
|
| 185 | - { |
|
| 186 | - $datay[$year] = $this->getAmountByMonth($year, $format); |
|
| 187 | - $year++; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - $data = array(); |
|
| 191 | - // $data = array('xval'=>array(0=>xlabel,1=>yval1,2=>yval2...),...) |
|
| 192 | - for ($i = 0 ; $i < 12 ; $i++) |
|
| 193 | - { |
|
| 194 | - $data[$i][]=$datay[$endyear][$i][0]; // set label |
|
| 195 | - $year=$startyear; |
|
| 196 | - while($year <= $endyear) |
|
| 197 | - { |
|
| 198 | - $data[$i][]=$datay[$year][$i][1]; // set yval for x=i |
|
| 199 | - $year++; |
|
| 200 | - } |
|
| 201 | - } |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - // Save cache file |
|
| 205 | - if (empty($foundintocache) && ($cachedelay > 0 || $cachedelay == -1)) |
|
| 206 | - { |
|
| 207 | - dol_syslog(get_class($this).'::'.__FUNCTION__." save cache file ".$newpathofdestfile." onto disk."); |
|
| 208 | - if (! dol_is_dir($conf->user->dir_temp)) dol_mkdir($conf->user->dir_temp); |
|
| 209 | - $fp = fopen($newpathofdestfile, 'w'); |
|
| 210 | - if ($fp) |
|
| 211 | - { |
|
| 212 | - fwrite($fp, json_encode($data)); |
|
| 213 | - fclose($fp); |
|
| 214 | - if (! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK; |
|
| 215 | - @chmod($newpathofdestfile, octdec($newmask)); |
|
| 216 | - } |
|
| 217 | - else dol_syslog("Failed to write cache file", LOG_ERR); |
|
| 218 | - $this->_lastfetchdate[get_class($this).'_'.__FUNCTION__]=$nowgmt; |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - return $data; |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * Return average of entity by month for several years |
|
| 226 | - * |
|
| 227 | - * @param int $endyear Start year |
|
| 228 | - * @param int $startyear End year |
|
| 229 | - * @return array Array of values |
|
| 230 | - */ |
|
| 231 | - function getAverageByMonthWithPrevYear($endyear,$startyear) |
|
| 232 | - { |
|
| 182 | + { |
|
| 183 | + $year=$startyear; |
|
| 184 | + while($year <= $endyear) |
|
| 185 | + { |
|
| 186 | + $datay[$year] = $this->getAmountByMonth($year, $format); |
|
| 187 | + $year++; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + $data = array(); |
|
| 191 | + // $data = array('xval'=>array(0=>xlabel,1=>yval1,2=>yval2...),...) |
|
| 192 | + for ($i = 0 ; $i < 12 ; $i++) |
|
| 193 | + { |
|
| 194 | + $data[$i][]=$datay[$endyear][$i][0]; // set label |
|
| 195 | + $year=$startyear; |
|
| 196 | + while($year <= $endyear) |
|
| 197 | + { |
|
| 198 | + $data[$i][]=$datay[$year][$i][1]; // set yval for x=i |
|
| 199 | + $year++; |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + // Save cache file |
|
| 205 | + if (empty($foundintocache) && ($cachedelay > 0 || $cachedelay == -1)) |
|
| 206 | + { |
|
| 207 | + dol_syslog(get_class($this).'::'.__FUNCTION__." save cache file ".$newpathofdestfile." onto disk."); |
|
| 208 | + if (! dol_is_dir($conf->user->dir_temp)) dol_mkdir($conf->user->dir_temp); |
|
| 209 | + $fp = fopen($newpathofdestfile, 'w'); |
|
| 210 | + if ($fp) |
|
| 211 | + { |
|
| 212 | + fwrite($fp, json_encode($data)); |
|
| 213 | + fclose($fp); |
|
| 214 | + if (! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK; |
|
| 215 | + @chmod($newpathofdestfile, octdec($newmask)); |
|
| 216 | + } |
|
| 217 | + else dol_syslog("Failed to write cache file", LOG_ERR); |
|
| 218 | + $this->_lastfetchdate[get_class($this).'_'.__FUNCTION__]=$nowgmt; |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + return $data; |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * Return average of entity by month for several years |
|
| 226 | + * |
|
| 227 | + * @param int $endyear Start year |
|
| 228 | + * @param int $startyear End year |
|
| 229 | + * @return array Array of values |
|
| 230 | + */ |
|
| 231 | + function getAverageByMonthWithPrevYear($endyear,$startyear) |
|
| 232 | + { |
|
| 233 | 233 | if ($startyear > $endyear) return -1; |
| 234 | 234 | |
| 235 | 235 | $datay=array(); |
| 236 | 236 | |
| 237 | - $year=$startyear; |
|
| 238 | - while($year <= $endyear) |
|
| 239 | - { |
|
| 240 | - $datay[$year] = $this->getAverageByMonth($year); |
|
| 241 | - $year++; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - $data = array(); |
|
| 245 | - |
|
| 246 | - for ($i = 0 ; $i < 12 ; $i++) |
|
| 247 | - { |
|
| 248 | - $data[$i][]=$datay[$endyear][$i][0]; |
|
| 249 | - $year=$startyear; |
|
| 250 | - while($year <= $endyear) |
|
| 251 | - { |
|
| 252 | - $data[$i][]=$datay[$year][$i][1]; |
|
| 253 | - $year++; |
|
| 254 | - } |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - return $data; |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - /** |
|
| 261 | - * Return count, and sum of products |
|
| 262 | - * |
|
| 263 | - * @param int $year Year |
|
| 264 | - * @param int $cachedelay Delay we accept for cache file (0=No read, no save of cache, -1=No read but save) |
|
| 265 | - * @return array Array of values |
|
| 266 | - */ |
|
| 267 | - function getAllByProductEntry($year,$cachedelay=0) |
|
| 268 | - { |
|
| 269 | - global $conf,$user,$langs; |
|
| 237 | + $year=$startyear; |
|
| 238 | + while($year <= $endyear) |
|
| 239 | + { |
|
| 240 | + $datay[$year] = $this->getAverageByMonth($year); |
|
| 241 | + $year++; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + $data = array(); |
|
| 245 | + |
|
| 246 | + for ($i = 0 ; $i < 12 ; $i++) |
|
| 247 | + { |
|
| 248 | + $data[$i][]=$datay[$endyear][$i][0]; |
|
| 249 | + $year=$startyear; |
|
| 250 | + while($year <= $endyear) |
|
| 251 | + { |
|
| 252 | + $data[$i][]=$datay[$year][$i][1]; |
|
| 253 | + $year++; |
|
| 254 | + } |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + return $data; |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + /** |
|
| 261 | + * Return count, and sum of products |
|
| 262 | + * |
|
| 263 | + * @param int $year Year |
|
| 264 | + * @param int $cachedelay Delay we accept for cache file (0=No read, no save of cache, -1=No read but save) |
|
| 265 | + * @return array Array of values |
|
| 266 | + */ |
|
| 267 | + function getAllByProductEntry($year,$cachedelay=0) |
|
| 268 | + { |
|
| 269 | + global $conf,$user,$langs; |
|
| 270 | 270 | |
| 271 | 271 | $datay=array(); |
| 272 | 272 | |
| 273 | 273 | // Search into cache |
| 274 | 274 | if (! empty($cachedelay)) |
| 275 | 275 | { |
| 276 | - include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
| 277 | - include_once DOL_DOCUMENT_ROOT.'/core/lib/json.lib.php'; |
|
| 276 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
| 277 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/json.lib.php'; |
|
| 278 | 278 | } |
| 279 | 279 | |
| 280 | 280 | $newpathofdestfile=$conf->user->dir_temp.'/'.get_class($this).'_'.__FUNCTION__.'_'.(empty($this->cachefilesuffix)?'':$this->cachefilesuffix.'_').$langs->defaultlang.'_entity.'.$conf->entity.'_user'.$user->id.'.cache'; |
@@ -285,324 +285,324 @@ discard block |
||
| 285 | 285 | $foundintocache=0; |
| 286 | 286 | if ($cachedelay > 0) |
| 287 | 287 | { |
| 288 | - $filedate=dol_filemtime($newpathofdestfile); |
|
| 289 | - if ($filedate >= ($nowgmt - $cachedelay)) |
|
| 290 | - { |
|
| 291 | - $foundintocache=1; |
|
| 292 | - |
|
| 293 | - $this->_lastfetchdate[get_class($this).'_'.__FUNCTION__]=$filedate; |
|
| 294 | - } |
|
| 295 | - else |
|
| 296 | - { |
|
| 297 | - dol_syslog(get_class($this).'::'.__FUNCTION__." cache file ".$newpathofdestfile." is not found or older than now - cachedelay (".$nowgmt." - ".$cachedelay.") so we can't use it."); |
|
| 298 | - } |
|
| 288 | + $filedate=dol_filemtime($newpathofdestfile); |
|
| 289 | + if ($filedate >= ($nowgmt - $cachedelay)) |
|
| 290 | + { |
|
| 291 | + $foundintocache=1; |
|
| 292 | + |
|
| 293 | + $this->_lastfetchdate[get_class($this).'_'.__FUNCTION__]=$filedate; |
|
| 294 | + } |
|
| 295 | + else |
|
| 296 | + { |
|
| 297 | + dol_syslog(get_class($this).'::'.__FUNCTION__." cache file ".$newpathofdestfile." is not found or older than now - cachedelay (".$nowgmt." - ".$cachedelay.") so we can't use it."); |
|
| 298 | + } |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | // Load file into $data |
| 302 | 302 | if ($foundintocache) // Cache file found and is not too old |
| 303 | 303 | { |
| 304 | - dol_syslog(get_class($this).'::'.__FUNCTION__." read data from cache file ".$newpathofdestfile." ".$filedate."."); |
|
| 305 | - $data = json_decode(file_get_contents($newpathofdestfile), true); |
|
| 304 | + dol_syslog(get_class($this).'::'.__FUNCTION__." read data from cache file ".$newpathofdestfile." ".$filedate."."); |
|
| 305 | + $data = json_decode(file_get_contents($newpathofdestfile), true); |
|
| 306 | 306 | } |
| 307 | 307 | else |
| 308 | - { |
|
| 309 | - $data=$this->getAllByProduct($year); |
|
| 310 | - // $data[$i][]=$datay[$year][$i][1]; // set yval for x=i |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - // Save cache file |
|
| 314 | - if (empty($foundintocache) && ($cachedelay > 0 || $cachedelay == -1)) |
|
| 315 | - { |
|
| 316 | - dol_syslog(get_class($this).'::'.__FUNCTION__." save cache file ".$newpathofdestfile." onto disk."); |
|
| 317 | - if (! dol_is_dir($conf->user->dir_temp)) dol_mkdir($conf->user->dir_temp); |
|
| 318 | - $fp = fopen($newpathofdestfile, 'w'); |
|
| 319 | - if ($fp) |
|
| 320 | - { |
|
| 321 | - fwrite($fp, json_encode($data)); |
|
| 322 | - fclose($fp); |
|
| 323 | - if (! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK; |
|
| 324 | - @chmod($newpathofdestfile, octdec($newmask)); |
|
| 325 | - } |
|
| 326 | - $this->_lastfetchdate[get_class($this).'_'.__FUNCTION__]=$nowgmt; |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - return $data; |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - |
|
| 333 | - // Here we have low level of shared code called by XxxStats.class.php |
|
| 334 | - |
|
| 335 | - |
|
| 336 | - /** |
|
| 337 | - * Return nb of elements by year |
|
| 338 | - * |
|
| 339 | - * @param string $sql SQL request |
|
| 340 | - * @return array |
|
| 341 | - */ |
|
| 342 | - function _getNbByYear($sql) |
|
| 343 | - { |
|
| 344 | - $result = array(); |
|
| 345 | - |
|
| 346 | - dol_syslog(get_class($this).'::'.__FUNCTION__."", LOG_DEBUG); |
|
| 347 | - $resql=$this->db->query($sql); |
|
| 348 | - if ($resql) |
|
| 349 | - { |
|
| 350 | - $num = $this->db->num_rows($resql); |
|
| 351 | - $i = 0; |
|
| 352 | - while ($i < $num) |
|
| 353 | - { |
|
| 354 | - $row = $this->db->fetch_row($resql); |
|
| 355 | - $result[$i] = $row; |
|
| 356 | - $i++; |
|
| 357 | - } |
|
| 358 | - $this->db->free($resql); |
|
| 359 | - } |
|
| 360 | - else { |
|
| 361 | - dol_print_error($this->db); |
|
| 362 | - } |
|
| 363 | - return $result; |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - /** |
|
| 367 | - * Return nb of elements, total amount and avg amount each year |
|
| 368 | - * |
|
| 369 | - * @param string $sql SQL request |
|
| 370 | - * @return array Array with nb, total amount, average for each year |
|
| 371 | - */ |
|
| 372 | - function _getAllByYear($sql) |
|
| 373 | - { |
|
| 374 | - $result = array(); |
|
| 375 | - |
|
| 376 | - dol_syslog(get_class($this).'::'.__FUNCTION__."", LOG_DEBUG); |
|
| 377 | - $resql=$this->db->query($sql); |
|
| 378 | - if ($resql) |
|
| 379 | - { |
|
| 380 | - $num = $this->db->num_rows($resql); |
|
| 381 | - $i = 0; |
|
| 382 | - while ($i < $num) |
|
| 383 | - { |
|
| 384 | - $row = $this->db->fetch_object($resql); |
|
| 385 | - $result[$i]['year'] = $row->year; |
|
| 386 | - $result[$i]['nb'] = $row->nb; |
|
| 387 | - if($i>0 && $row->nb) $result[$i-1]['nb_diff'] = ($result[$i-1]['nb'] - $row->nb) / $row->nb * 100; |
|
| 388 | - $result[$i]['total'] = $row->total; |
|
| 389 | - if($i>0 && $row->total) $result[$i-1]['total_diff'] = ($result[$i-1]['total'] - $row->total) / $row->total * 100; |
|
| 390 | - $result[$i]['avg'] = $row->avg; |
|
| 391 | - if($i>0 && $row->avg) $result[$i-1]['avg_diff'] = ($result[$i-1]['avg'] - $row->avg) / $row->avg * 100; |
|
| 392 | - // For some $sql only |
|
| 393 | - if (isset($row->weighted)) |
|
| 394 | - { |
|
| 395 | - $result[$i]['weighted'] = $row->weighted; |
|
| 396 | - if($i>0 && $row->weighted) $result[$i-1]['avg_weighted'] = ($result[$i-1]['weighted'] - $row->weighted) / $row->weighted * 100; |
|
| 397 | - } |
|
| 398 | - $i++; |
|
| 399 | - } |
|
| 400 | - $this->db->free($resql); |
|
| 401 | - } |
|
| 402 | - else { |
|
| 403 | - dol_print_error($this->db); |
|
| 404 | - } |
|
| 405 | - return $result; |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - /** |
|
| 409 | - * Renvoie le nombre de proposition par mois pour une annee donnee |
|
| 410 | - * |
|
| 308 | + { |
|
| 309 | + $data=$this->getAllByProduct($year); |
|
| 310 | + // $data[$i][]=$datay[$year][$i][1]; // set yval for x=i |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + // Save cache file |
|
| 314 | + if (empty($foundintocache) && ($cachedelay > 0 || $cachedelay == -1)) |
|
| 315 | + { |
|
| 316 | + dol_syslog(get_class($this).'::'.__FUNCTION__." save cache file ".$newpathofdestfile." onto disk."); |
|
| 317 | + if (! dol_is_dir($conf->user->dir_temp)) dol_mkdir($conf->user->dir_temp); |
|
| 318 | + $fp = fopen($newpathofdestfile, 'w'); |
|
| 319 | + if ($fp) |
|
| 320 | + { |
|
| 321 | + fwrite($fp, json_encode($data)); |
|
| 322 | + fclose($fp); |
|
| 323 | + if (! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK; |
|
| 324 | + @chmod($newpathofdestfile, octdec($newmask)); |
|
| 325 | + } |
|
| 326 | + $this->_lastfetchdate[get_class($this).'_'.__FUNCTION__]=$nowgmt; |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + return $data; |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + |
|
| 333 | + // Here we have low level of shared code called by XxxStats.class.php |
|
| 334 | + |
|
| 335 | + |
|
| 336 | + /** |
|
| 337 | + * Return nb of elements by year |
|
| 338 | + * |
|
| 339 | + * @param string $sql SQL request |
|
| 340 | + * @return array |
|
| 341 | + */ |
|
| 342 | + function _getNbByYear($sql) |
|
| 343 | + { |
|
| 344 | + $result = array(); |
|
| 345 | + |
|
| 346 | + dol_syslog(get_class($this).'::'.__FUNCTION__."", LOG_DEBUG); |
|
| 347 | + $resql=$this->db->query($sql); |
|
| 348 | + if ($resql) |
|
| 349 | + { |
|
| 350 | + $num = $this->db->num_rows($resql); |
|
| 351 | + $i = 0; |
|
| 352 | + while ($i < $num) |
|
| 353 | + { |
|
| 354 | + $row = $this->db->fetch_row($resql); |
|
| 355 | + $result[$i] = $row; |
|
| 356 | + $i++; |
|
| 357 | + } |
|
| 358 | + $this->db->free($resql); |
|
| 359 | + } |
|
| 360 | + else { |
|
| 361 | + dol_print_error($this->db); |
|
| 362 | + } |
|
| 363 | + return $result; |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + /** |
|
| 367 | + * Return nb of elements, total amount and avg amount each year |
|
| 368 | + * |
|
| 369 | + * @param string $sql SQL request |
|
| 370 | + * @return array Array with nb, total amount, average for each year |
|
| 371 | + */ |
|
| 372 | + function _getAllByYear($sql) |
|
| 373 | + { |
|
| 374 | + $result = array(); |
|
| 375 | + |
|
| 376 | + dol_syslog(get_class($this).'::'.__FUNCTION__."", LOG_DEBUG); |
|
| 377 | + $resql=$this->db->query($sql); |
|
| 378 | + if ($resql) |
|
| 379 | + { |
|
| 380 | + $num = $this->db->num_rows($resql); |
|
| 381 | + $i = 0; |
|
| 382 | + while ($i < $num) |
|
| 383 | + { |
|
| 384 | + $row = $this->db->fetch_object($resql); |
|
| 385 | + $result[$i]['year'] = $row->year; |
|
| 386 | + $result[$i]['nb'] = $row->nb; |
|
| 387 | + if($i>0 && $row->nb) $result[$i-1]['nb_diff'] = ($result[$i-1]['nb'] - $row->nb) / $row->nb * 100; |
|
| 388 | + $result[$i]['total'] = $row->total; |
|
| 389 | + if($i>0 && $row->total) $result[$i-1]['total_diff'] = ($result[$i-1]['total'] - $row->total) / $row->total * 100; |
|
| 390 | + $result[$i]['avg'] = $row->avg; |
|
| 391 | + if($i>0 && $row->avg) $result[$i-1]['avg_diff'] = ($result[$i-1]['avg'] - $row->avg) / $row->avg * 100; |
|
| 392 | + // For some $sql only |
|
| 393 | + if (isset($row->weighted)) |
|
| 394 | + { |
|
| 395 | + $result[$i]['weighted'] = $row->weighted; |
|
| 396 | + if($i>0 && $row->weighted) $result[$i-1]['avg_weighted'] = ($result[$i-1]['weighted'] - $row->weighted) / $row->weighted * 100; |
|
| 397 | + } |
|
| 398 | + $i++; |
|
| 399 | + } |
|
| 400 | + $this->db->free($resql); |
|
| 401 | + } |
|
| 402 | + else { |
|
| 403 | + dol_print_error($this->db); |
|
| 404 | + } |
|
| 405 | + return $result; |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + /** |
|
| 409 | + * Renvoie le nombre de proposition par mois pour une annee donnee |
|
| 410 | + * |
|
| 411 | 411 | * @param int $year Year |
| 412 | 412 | * @param string $sql SQL |
| 413 | 413 | * @param int $format 0=Label of absiss is a translated text, 1=Label of absiss is month number, 2=Label of absiss is first letter of month |
| 414 | 414 | * @return array Array of nb each month |
| 415 | - */ |
|
| 416 | - function _getNbByMonth($year, $sql, $format=0) |
|
| 417 | - { |
|
| 418 | - global $langs; |
|
| 419 | - |
|
| 420 | - $result=array(); |
|
| 421 | - $res=array(); |
|
| 422 | - |
|
| 423 | - dol_syslog(get_class($this).'::'.__FUNCTION__."", LOG_DEBUG); |
|
| 424 | - $resql=$this->db->query($sql); |
|
| 425 | - if ($resql) |
|
| 426 | - { |
|
| 427 | - $num = $this->db->num_rows($resql); |
|
| 428 | - $i = 0; $j = 0; |
|
| 429 | - while ($i < $num) |
|
| 430 | - { |
|
| 431 | - $row = $this->db->fetch_row($resql); |
|
| 432 | - $j = $row[0] * 1; |
|
| 433 | - $result[$j] = $row[1]; |
|
| 434 | - $i++; |
|
| 435 | - } |
|
| 436 | - $this->db->free($resql); |
|
| 437 | - } |
|
| 438 | - else |
|
| 439 | - { |
|
| 440 | - dol_print_error($this->db); |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - for ($i = 1 ; $i < 13 ; $i++) |
|
| 444 | - { |
|
| 445 | - $res[$i] = (isset($result[$i])?$result[$i]:0); |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - $data = array(); |
|
| 449 | - |
|
| 450 | - for ($i = 1 ; $i < 13 ; $i++) |
|
| 451 | - { |
|
| 452 | - $month='unknown'; |
|
| 453 | - if ($format == 0) $month=$langs->transnoentitiesnoconv('MonthShort'.sprintf("%02d", $i)); |
|
| 454 | - elseif ($format == 1) $month=$i; |
|
| 455 | - elseif ($format == 2) $month=$langs->transnoentitiesnoconv('MonthVeryShort'.sprintf("%02d", $i)); |
|
| 456 | - //$month=dol_print_date(dol_mktime(12,0,0,$i,1,$year),($format?"%m":"%b")); |
|
| 457 | - //$month=dol_substr($month,0,3); |
|
| 458 | - $data[$i-1] = array($month, $res[$i]); |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - return $data; |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - |
|
| 465 | - /** |
|
| 466 | - * Renvoie le nombre d'element par mois pour une annee donnee |
|
| 467 | - * |
|
| 468 | - * @param int $year Year |
|
| 469 | - * @param string $sql SQL |
|
| 415 | + */ |
|
| 416 | + function _getNbByMonth($year, $sql, $format=0) |
|
| 417 | + { |
|
| 418 | + global $langs; |
|
| 419 | + |
|
| 420 | + $result=array(); |
|
| 421 | + $res=array(); |
|
| 422 | + |
|
| 423 | + dol_syslog(get_class($this).'::'.__FUNCTION__."", LOG_DEBUG); |
|
| 424 | + $resql=$this->db->query($sql); |
|
| 425 | + if ($resql) |
|
| 426 | + { |
|
| 427 | + $num = $this->db->num_rows($resql); |
|
| 428 | + $i = 0; $j = 0; |
|
| 429 | + while ($i < $num) |
|
| 430 | + { |
|
| 431 | + $row = $this->db->fetch_row($resql); |
|
| 432 | + $j = $row[0] * 1; |
|
| 433 | + $result[$j] = $row[1]; |
|
| 434 | + $i++; |
|
| 435 | + } |
|
| 436 | + $this->db->free($resql); |
|
| 437 | + } |
|
| 438 | + else |
|
| 439 | + { |
|
| 440 | + dol_print_error($this->db); |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + for ($i = 1 ; $i < 13 ; $i++) |
|
| 444 | + { |
|
| 445 | + $res[$i] = (isset($result[$i])?$result[$i]:0); |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + $data = array(); |
|
| 449 | + |
|
| 450 | + for ($i = 1 ; $i < 13 ; $i++) |
|
| 451 | + { |
|
| 452 | + $month='unknown'; |
|
| 453 | + if ($format == 0) $month=$langs->transnoentitiesnoconv('MonthShort'.sprintf("%02d", $i)); |
|
| 454 | + elseif ($format == 1) $month=$i; |
|
| 455 | + elseif ($format == 2) $month=$langs->transnoentitiesnoconv('MonthVeryShort'.sprintf("%02d", $i)); |
|
| 456 | + //$month=dol_print_date(dol_mktime(12,0,0,$i,1,$year),($format?"%m":"%b")); |
|
| 457 | + //$month=dol_substr($month,0,3); |
|
| 458 | + $data[$i-1] = array($month, $res[$i]); |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + return $data; |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + |
|
| 465 | + /** |
|
| 466 | + * Renvoie le nombre d'element par mois pour une annee donnee |
|
| 467 | + * |
|
| 468 | + * @param int $year Year |
|
| 469 | + * @param string $sql SQL |
|
| 470 | 470 | * @param int $format 0=Label of absiss is a translated text, 1=Label of absiss is month number, 2=Label of absiss is first letter of month |
| 471 | - * @return array |
|
| 472 | - */ |
|
| 473 | - function _getAmountByMonth($year, $sql, $format=0) |
|
| 474 | - { |
|
| 475 | - global $langs; |
|
| 476 | - |
|
| 477 | - $result=array(); |
|
| 478 | - $res=array(); |
|
| 479 | - |
|
| 480 | - dol_syslog(get_class($this).'::'.__FUNCTION__."", LOG_DEBUG); |
|
| 481 | - |
|
| 482 | - $resql=$this->db->query($sql); |
|
| 483 | - if ($resql) |
|
| 484 | - { |
|
| 485 | - $num = $this->db->num_rows($resql); |
|
| 486 | - $i = 0; |
|
| 487 | - while ($i < $num) |
|
| 488 | - { |
|
| 489 | - $row = $this->db->fetch_row($resql); |
|
| 490 | - $j = $row[0] * 1; |
|
| 491 | - $result[$j] = $row[1]; |
|
| 492 | - $i++; |
|
| 493 | - } |
|
| 494 | - $this->db->free($resql); |
|
| 495 | - } |
|
| 471 | + * @return array |
|
| 472 | + */ |
|
| 473 | + function _getAmountByMonth($year, $sql, $format=0) |
|
| 474 | + { |
|
| 475 | + global $langs; |
|
| 476 | + |
|
| 477 | + $result=array(); |
|
| 478 | + $res=array(); |
|
| 479 | + |
|
| 480 | + dol_syslog(get_class($this).'::'.__FUNCTION__."", LOG_DEBUG); |
|
| 481 | + |
|
| 482 | + $resql=$this->db->query($sql); |
|
| 483 | + if ($resql) |
|
| 484 | + { |
|
| 485 | + $num = $this->db->num_rows($resql); |
|
| 486 | + $i = 0; |
|
| 487 | + while ($i < $num) |
|
| 488 | + { |
|
| 489 | + $row = $this->db->fetch_row($resql); |
|
| 490 | + $j = $row[0] * 1; |
|
| 491 | + $result[$j] = $row[1]; |
|
| 492 | + $i++; |
|
| 493 | + } |
|
| 494 | + $this->db->free($resql); |
|
| 495 | + } |
|
| 496 | 496 | else dol_print_error($this->db); |
| 497 | 497 | |
| 498 | - for ($i = 1 ; $i < 13 ; $i++) |
|
| 499 | - { |
|
| 500 | - $res[$i] = (int) round((isset($result[$i])?$result[$i]:0)); |
|
| 501 | - } |
|
| 502 | - |
|
| 503 | - $data = array(); |
|
| 504 | - |
|
| 505 | - for ($i = 1 ; $i < 13 ; $i++) |
|
| 506 | - { |
|
| 507 | - $month='unknown'; |
|
| 508 | - if ($format == 0) $month=$langs->transnoentitiesnoconv('MonthShort'.sprintf("%02d", $i)); |
|
| 509 | - elseif ($format == 1) $month=$i; |
|
| 510 | - elseif ($format == 2) $month=$langs->transnoentitiesnoconv('MonthVeryShort'.sprintf("%02d", $i)); |
|
| 511 | - //$month=dol_print_date(dol_mktime(12,0,0,$i,1,$year),($format?"%m":"%b")); |
|
| 512 | - //$month=dol_substr($month,0,3); |
|
| 513 | - $data[$i-1] = array($month, $res[$i]); |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - return $data; |
|
| 517 | - } |
|
| 518 | - |
|
| 519 | - /** |
|
| 520 | - * Renvoie le montant moyen par mois pour une annee donnee |
|
| 521 | - * |
|
| 498 | + for ($i = 1 ; $i < 13 ; $i++) |
|
| 499 | + { |
|
| 500 | + $res[$i] = (int) round((isset($result[$i])?$result[$i]:0)); |
|
| 501 | + } |
|
| 502 | + |
|
| 503 | + $data = array(); |
|
| 504 | + |
|
| 505 | + for ($i = 1 ; $i < 13 ; $i++) |
|
| 506 | + { |
|
| 507 | + $month='unknown'; |
|
| 508 | + if ($format == 0) $month=$langs->transnoentitiesnoconv('MonthShort'.sprintf("%02d", $i)); |
|
| 509 | + elseif ($format == 1) $month=$i; |
|
| 510 | + elseif ($format == 2) $month=$langs->transnoentitiesnoconv('MonthVeryShort'.sprintf("%02d", $i)); |
|
| 511 | + //$month=dol_print_date(dol_mktime(12,0,0,$i,1,$year),($format?"%m":"%b")); |
|
| 512 | + //$month=dol_substr($month,0,3); |
|
| 513 | + $data[$i-1] = array($month, $res[$i]); |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + return $data; |
|
| 517 | + } |
|
| 518 | + |
|
| 519 | + /** |
|
| 520 | + * Renvoie le montant moyen par mois pour une annee donnee |
|
| 521 | + * |
|
| 522 | 522 | * @param int $year Year |
| 523 | 523 | * @param string $sql SQL |
| 524 | 524 | * @param int $format 0=Label of absiss is a translated text, 1=Label of absiss is month number, 2=Label of absiss is first letter of month |
| 525 | - * @return array |
|
| 526 | - */ |
|
| 527 | - function _getAverageByMonth($year, $sql, $format=0) |
|
| 528 | - { |
|
| 529 | - global $langs; |
|
| 530 | - |
|
| 531 | - $result=array(); |
|
| 532 | - $res=array(); |
|
| 533 | - |
|
| 534 | - dol_syslog(get_class($this).'::'.__FUNCTION__."", LOG_DEBUG); |
|
| 535 | - $resql=$this->db->query($sql); |
|
| 536 | - if ($resql) |
|
| 537 | - { |
|
| 538 | - $num = $this->db->num_rows($resql); |
|
| 539 | - $i = 0; $j = 0; |
|
| 540 | - while ($i < $num) |
|
| 541 | - { |
|
| 542 | - $row = $this->db->fetch_row($resql); |
|
| 543 | - $j = $row[0] * 1; |
|
| 544 | - $result[$j] = $row[1]; |
|
| 545 | - $i++; |
|
| 546 | - } |
|
| 547 | - $this->db->free($resql); |
|
| 548 | - } |
|
| 525 | + * @return array |
|
| 526 | + */ |
|
| 527 | + function _getAverageByMonth($year, $sql, $format=0) |
|
| 528 | + { |
|
| 529 | + global $langs; |
|
| 530 | + |
|
| 531 | + $result=array(); |
|
| 532 | + $res=array(); |
|
| 533 | + |
|
| 534 | + dol_syslog(get_class($this).'::'.__FUNCTION__."", LOG_DEBUG); |
|
| 535 | + $resql=$this->db->query($sql); |
|
| 536 | + if ($resql) |
|
| 537 | + { |
|
| 538 | + $num = $this->db->num_rows($resql); |
|
| 539 | + $i = 0; $j = 0; |
|
| 540 | + while ($i < $num) |
|
| 541 | + { |
|
| 542 | + $row = $this->db->fetch_row($resql); |
|
| 543 | + $j = $row[0] * 1; |
|
| 544 | + $result[$j] = $row[1]; |
|
| 545 | + $i++; |
|
| 546 | + } |
|
| 547 | + $this->db->free($resql); |
|
| 548 | + } |
|
| 549 | 549 | else dol_print_error($this->db); |
| 550 | 550 | |
| 551 | - for ($i = 1 ; $i < 13 ; $i++) |
|
| 552 | - { |
|
| 553 | - $res[$i] = (isset($result[$i])?$result[$i]:0); |
|
| 554 | - } |
|
| 551 | + for ($i = 1 ; $i < 13 ; $i++) |
|
| 552 | + { |
|
| 553 | + $res[$i] = (isset($result[$i])?$result[$i]:0); |
|
| 554 | + } |
|
| 555 | 555 | |
| 556 | - $data = array(); |
|
| 556 | + $data = array(); |
|
| 557 | 557 | |
| 558 | - for ($i = 1 ; $i < 13 ; $i++) |
|
| 559 | - { |
|
| 560 | - $month='unknown'; |
|
| 561 | - if ($format == 0) $month=$langs->transnoentitiesnoconv('MonthShort'.sprintf("%02d", $i)); |
|
| 562 | - elseif ($format == 1) $month=$i; |
|
| 563 | - elseif ($format == 2) $month=$langs->transnoentitiesnoconv('MonthVeryShort'.sprintf("%02d", $i)); |
|
| 564 | - //$month=dol_print_date(dol_mktime(12,0,0,$i,1,$year),($format?"%m":"%b")); |
|
| 565 | - //$month=dol_substr($month,0,3); |
|
| 566 | - $data[$i-1] = array($month, $res[$i]); |
|
| 567 | - } |
|
| 558 | + for ($i = 1 ; $i < 13 ; $i++) |
|
| 559 | + { |
|
| 560 | + $month='unknown'; |
|
| 561 | + if ($format == 0) $month=$langs->transnoentitiesnoconv('MonthShort'.sprintf("%02d", $i)); |
|
| 562 | + elseif ($format == 1) $month=$i; |
|
| 563 | + elseif ($format == 2) $month=$langs->transnoentitiesnoconv('MonthVeryShort'.sprintf("%02d", $i)); |
|
| 564 | + //$month=dol_print_date(dol_mktime(12,0,0,$i,1,$year),($format?"%m":"%b")); |
|
| 565 | + //$month=dol_substr($month,0,3); |
|
| 566 | + $data[$i-1] = array($month, $res[$i]); |
|
| 567 | + } |
|
| 568 | 568 | |
| 569 | - return $data; |
|
| 570 | - } |
|
| 569 | + return $data; |
|
| 570 | + } |
|
| 571 | 571 | |
| 572 | 572 | |
| 573 | - /** |
|
| 574 | - * Return number or total of product refs |
|
| 575 | - * |
|
| 573 | + /** |
|
| 574 | + * Return number or total of product refs |
|
| 575 | + * |
|
| 576 | 576 | * @param string $sql SQL |
| 577 | 577 | * @param int $limit Limit |
| 578 | 578 | * @return array |
| 579 | - */ |
|
| 580 | - function _getAllByProduct($sql, $limit=10) |
|
| 581 | - { |
|
| 582 | - global $langs; |
|
| 583 | - |
|
| 584 | - $result=array(); |
|
| 585 | - $res=array(); |
|
| 586 | - |
|
| 587 | - dol_syslog(get_class($this).'::'.__FUNCTION__."", LOG_DEBUG); |
|
| 588 | - $resql=$this->db->query($sql); |
|
| 589 | - if ($resql) |
|
| 590 | - { |
|
| 591 | - $num = $this->db->num_rows($resql); |
|
| 592 | - $i = 0; $other=0; |
|
| 593 | - while ($i < $num) |
|
| 594 | - { |
|
| 595 | - $row = $this->db->fetch_row($resql); |
|
| 596 | - if ($i < $limit || $num == $limit) $result[$i] = array($row[0],$row[1]); // Ref of product, nb |
|
| 597 | - else $other += $row[1]; |
|
| 598 | - $i++; |
|
| 599 | - } |
|
| 600 | - if ($num > $limit) $result[$i] = array($langs->transnoentitiesnoconv("Other"),$other); |
|
| 601 | - $this->db->free($resql); |
|
| 602 | - } |
|
| 579 | + */ |
|
| 580 | + function _getAllByProduct($sql, $limit=10) |
|
| 581 | + { |
|
| 582 | + global $langs; |
|
| 583 | + |
|
| 584 | + $result=array(); |
|
| 585 | + $res=array(); |
|
| 586 | + |
|
| 587 | + dol_syslog(get_class($this).'::'.__FUNCTION__."", LOG_DEBUG); |
|
| 588 | + $resql=$this->db->query($sql); |
|
| 589 | + if ($resql) |
|
| 590 | + { |
|
| 591 | + $num = $this->db->num_rows($resql); |
|
| 592 | + $i = 0; $other=0; |
|
| 593 | + while ($i < $num) |
|
| 594 | + { |
|
| 595 | + $row = $this->db->fetch_row($resql); |
|
| 596 | + if ($i < $limit || $num == $limit) $result[$i] = array($row[0],$row[1]); // Ref of product, nb |
|
| 597 | + else $other += $row[1]; |
|
| 598 | + $i++; |
|
| 599 | + } |
|
| 600 | + if ($num > $limit) $result[$i] = array($langs->transnoentitiesnoconv("Other"),$other); |
|
| 601 | + $this->db->free($resql); |
|
| 602 | + } |
|
| 603 | 603 | else dol_print_error($this->db); |
| 604 | 604 | |
| 605 | - return $result; |
|
| 606 | - } |
|
| 605 | + return $result; |
|
| 606 | + } |
|
| 607 | 607 | } |
| 608 | 608 | |
@@ -34,312 +34,312 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | class FormFile |
| 36 | 36 | { |
| 37 | - private $db; |
|
| 37 | + private $db; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @var string Error code (or message) |
|
| 41 | - */ |
|
| 42 | - public $error; |
|
| 39 | + /** |
|
| 40 | + * @var string Error code (or message) |
|
| 41 | + */ |
|
| 42 | + public $error; |
|
| 43 | 43 | |
| 44 | - public $numoffiles; |
|
| 45 | - public $infofiles; // Used to return informations by function getDocumentsLink |
|
| 44 | + public $numoffiles; |
|
| 45 | + public $infofiles; // Used to return informations by function getDocumentsLink |
|
| 46 | 46 | |
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Constructor |
|
| 50 | - * |
|
| 51 | - * @param DoliDB $db Database handler |
|
| 52 | - */ |
|
| 53 | - function __construct($db) |
|
| 54 | - { |
|
| 55 | - $this->db = $db; |
|
| 56 | - $this->numoffiles=0; |
|
| 57 | - } |
|
| 48 | + /** |
|
| 49 | + * Constructor |
|
| 50 | + * |
|
| 51 | + * @param DoliDB $db Database handler |
|
| 52 | + */ |
|
| 53 | + function __construct($db) |
|
| 54 | + { |
|
| 55 | + $this->db = $db; |
|
| 56 | + $this->numoffiles=0; |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | 59 | |
| 60 | 60 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
| 61 | - /** |
|
| 62 | - * Show form to upload a new file. |
|
| 63 | - * |
|
| 64 | - * @param string $url Url |
|
| 65 | - * @param string $title Title zone (Title or '' or 'none') |
|
| 66 | - * @param int $addcancel 1=Add 'Cancel' button |
|
| 67 | - * @param int $sectionid If upload must be done inside a particular ECM section (is sectionid defined, sectiondir must not be) |
|
| 68 | - * @param int $perm Value of permission to allow upload |
|
| 69 | - * @param int $size Length of input file area. Deprecated. |
|
| 70 | - * @param Object $object Object to use (when attachment is done on an element) |
|
| 71 | - * @param string $options Add an option column |
|
| 72 | - * @param integer $useajax Use fileupload ajax (0=never, 1=if enabled, 2=always whatever is option). @deprecated 2 should never be used and if 1 is used, option should no be enabled. |
|
| 73 | - * @param string $savingdocmask Mask to use to define output filename. For example 'XXXXX-__YYYYMMDD__-__file__' |
|
| 74 | - * @param integer $linkfiles 1=Also add form to link files, 0=Do not show form to link files |
|
| 75 | - * @param string $htmlname Name and id of HTML form ('formuserfile' by default, 'formuserfileecm' when used to upload a file in ECM) |
|
| 76 | - * @param string $accept Specifies the types of files accepted (This is not a security check but an user interface facility. eg '.pdf,image/*' or '.png,.jpg' or 'video/*') |
|
| 77 | - * @param string $sectiondir If upload must be done inside a particular directory (is sectiondir defined, sectionid must not be) |
|
| 78 | - * @return int <0 if KO, >0 if OK |
|
| 79 | - */ |
|
| 80 | - function form_attach_new_file($url, $title='', $addcancel=0, $sectionid=0, $perm=1, $size=50, $object='', $options='', $useajax=1, $savingdocmask='', $linkfiles=1, $htmlname='formuserfile', $accept='', $sectiondir='') |
|
| 81 | - { |
|
| 61 | + /** |
|
| 62 | + * Show form to upload a new file. |
|
| 63 | + * |
|
| 64 | + * @param string $url Url |
|
| 65 | + * @param string $title Title zone (Title or '' or 'none') |
|
| 66 | + * @param int $addcancel 1=Add 'Cancel' button |
|
| 67 | + * @param int $sectionid If upload must be done inside a particular ECM section (is sectionid defined, sectiondir must not be) |
|
| 68 | + * @param int $perm Value of permission to allow upload |
|
| 69 | + * @param int $size Length of input file area. Deprecated. |
|
| 70 | + * @param Object $object Object to use (when attachment is done on an element) |
|
| 71 | + * @param string $options Add an option column |
|
| 72 | + * @param integer $useajax Use fileupload ajax (0=never, 1=if enabled, 2=always whatever is option). @deprecated 2 should never be used and if 1 is used, option should no be enabled. |
|
| 73 | + * @param string $savingdocmask Mask to use to define output filename. For example 'XXXXX-__YYYYMMDD__-__file__' |
|
| 74 | + * @param integer $linkfiles 1=Also add form to link files, 0=Do not show form to link files |
|
| 75 | + * @param string $htmlname Name and id of HTML form ('formuserfile' by default, 'formuserfileecm' when used to upload a file in ECM) |
|
| 76 | + * @param string $accept Specifies the types of files accepted (This is not a security check but an user interface facility. eg '.pdf,image/*' or '.png,.jpg' or 'video/*') |
|
| 77 | + * @param string $sectiondir If upload must be done inside a particular directory (is sectiondir defined, sectionid must not be) |
|
| 78 | + * @return int <0 if KO, >0 if OK |
|
| 79 | + */ |
|
| 80 | + function form_attach_new_file($url, $title='', $addcancel=0, $sectionid=0, $perm=1, $size=50, $object='', $options='', $useajax=1, $savingdocmask='', $linkfiles=1, $htmlname='formuserfile', $accept='', $sectiondir='') |
|
| 81 | + { |
|
| 82 | 82 | // phpcs:enable |
| 83 | - global $conf,$langs, $hookmanager; |
|
| 84 | - $hookmanager->initHooks(array('formfile')); |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - if (! empty($conf->browser->layout) && $conf->browser->layout != 'classic') $useajax=0; |
|
| 88 | - |
|
| 89 | - if ((! empty($conf->global->MAIN_USE_JQUERY_FILEUPLOAD) && $useajax) || ($useajax==2)) |
|
| 90 | - { |
|
| 91 | - // TODO: Check this works with 2 forms on same page |
|
| 92 | - // TODO: Check this works with GED module, otherwise, force useajax to 0 |
|
| 93 | - // TODO: This does not support option savingdocmask |
|
| 94 | - // TODO: This break feature to upload links too |
|
| 95 | - return $this->_formAjaxFileUpload($object); |
|
| 96 | - } |
|
| 97 | - else |
|
| 98 | - { |
|
| 99 | - //If there is no permission and the option to hide unauthorized actions is enabled, then nothing is printed |
|
| 100 | - if (!$perm && !empty($conf->global->MAIN_BUTTON_HIDE_UNAUTHORIZED)) { |
|
| 101 | - return 1; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - $maxlength=$size; |
|
| 105 | - |
|
| 106 | - $out = "\n\n<!-- Start form attach new file -->\n"; |
|
| 107 | - |
|
| 108 | - if (empty($title)) $title=$langs->trans("AttachANewFile"); |
|
| 109 | - if ($title != 'none') $out.=load_fiche_titre($title, null, null); |
|
| 110 | - |
|
| 111 | - $out .= '<form name="'.$htmlname.'" id="'.$htmlname.'" action="'.$url.'" enctype="multipart/form-data" method="POST">'; |
|
| 112 | - $out .= '<input type="hidden" id="'.$htmlname.'_section_dir" name="section_dir" value="'.$sectiondir.'">'; |
|
| 113 | - $out .= '<input type="hidden" id="'.$htmlname.'_section_id" name="section_id" value="'.$sectionid.'">'; |
|
| 114 | - $out .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
| 115 | - |
|
| 116 | - $out .= '<table width="100%" class="nobordernopadding">'; |
|
| 117 | - $out .= '<tr>'; |
|
| 118 | - |
|
| 119 | - if (! empty($options)) $out .= '<td>'.$options.'</td>'; |
|
| 120 | - |
|
| 121 | - $out .= '<td class="valignmiddle nowrap">'; |
|
| 122 | - |
|
| 123 | - $max=$conf->global->MAIN_UPLOAD_DOC; // En Kb |
|
| 124 | - $maxphp=@ini_get('upload_max_filesize'); // En inconnu |
|
| 125 | - if (preg_match('/k$/i',$maxphp)) $maxphp=$maxphp*1; |
|
| 126 | - if (preg_match('/m$/i',$maxphp)) $maxphp=$maxphp*1024; |
|
| 127 | - if (preg_match('/g$/i',$maxphp)) $maxphp=$maxphp*1024*1024; |
|
| 128 | - if (preg_match('/t$/i',$maxphp)) $maxphp=$maxphp*1024*1024*1024; |
|
| 129 | - // Now $max and $maxphp are in Kb |
|
| 130 | - $maxmin = $max; |
|
| 131 | - if ($maxphp > 0) $maxmin=min($max,$maxphp); |
|
| 132 | - |
|
| 133 | - if ($maxmin > 0) |
|
| 134 | - { |
|
| 135 | - // MAX_FILE_SIZE doit précéder le champ input de type file |
|
| 136 | - $out .= '<input type="hidden" name="max_file_size" value="'.($maxmin*1024).'">'; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - $out .= '<input class="flat minwidth400" type="file"'; |
|
| 140 | - $out .= ((! empty($conf->global->MAIN_DISABLE_MULTIPLE_FILEUPLOAD) || $conf->browser->layout != 'classic')?' name="userfile"':' name="userfile[]" multiple'); |
|
| 141 | - $out .= (empty($conf->global->MAIN_UPLOAD_DOC) || empty($perm)?' disabled':''); |
|
| 142 | - $out .= (!empty($accept)?' accept="'.$accept.'"':' accept=""'); |
|
| 143 | - $out .= '>'; |
|
| 144 | - $out .= ' '; |
|
| 145 | - $out .= '<input type="submit" class="button" name="sendit" value="'.$langs->trans("Upload").'"'; |
|
| 146 | - $out .= (empty($conf->global->MAIN_UPLOAD_DOC) || empty($perm)?' disabled':''); |
|
| 147 | - $out .= '>'; |
|
| 148 | - |
|
| 149 | - if ($addcancel) |
|
| 150 | - { |
|
| 151 | - $out .= ' '; |
|
| 152 | - $out .= '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">'; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - if (! empty($conf->global->MAIN_UPLOAD_DOC)) |
|
| 156 | - { |
|
| 157 | - if ($perm) |
|
| 158 | - { |
|
| 159 | - $langs->load('other'); |
|
| 160 | - $out .= ' '; |
|
| 161 | - $out .= info_admin($langs->trans("ThisLimitIsDefinedInSetup",$max,$maxphp),1); |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - else |
|
| 165 | - { |
|
| 166 | - $out .= ' ('.$langs->trans("UploadDisabled").')'; |
|
| 167 | - } |
|
| 168 | - $out .= "</td></tr>"; |
|
| 169 | - |
|
| 170 | - if ($savingdocmask) |
|
| 171 | - { |
|
| 172 | - $out .= '<tr>'; |
|
| 173 | - if (! empty($options)) $out .= '<td>'.$options.'</td>'; |
|
| 174 | - $out .= '<td valign="middle" class="nowrap">'; |
|
| 175 | - $out .= '<input type="checkbox" checked class="savingdocmask" name="savingdocmask" value="'.dol_escape_js($savingdocmask).'"> '.$langs->trans("SaveUploadedFileWithMask", preg_replace('/__file__/',$langs->transnoentitiesnoconv("OriginFileName"),$savingdocmask), $langs->transnoentitiesnoconv("OriginFileName")); |
|
| 176 | - $out .= '</td>'; |
|
| 177 | - $out .= '</tr>'; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - $out .= "</table>"; |
|
| 181 | - |
|
| 182 | - $out .= '</form>'; |
|
| 183 | - if (empty($sectionid)) $out .= '<br>'; |
|
| 184 | - |
|
| 185 | - $out .= "\n<!-- End form attach new file -->\n"; |
|
| 186 | - |
|
| 187 | - if ($linkfiles) |
|
| 188 | - { |
|
| 189 | - $out .= "\n<!-- Start form link new url -->\n"; |
|
| 190 | - $langs->load('link'); |
|
| 191 | - $title = $langs->trans("LinkANewFile"); |
|
| 192 | - $out .= load_fiche_titre($title, null, null); |
|
| 193 | - $out .= '<form name="'.$htmlname.'_link" id="'.$htmlname.'_link" action="'.$url.'" method="POST">'; |
|
| 194 | - $out .= '<input type="hidden" id="'.$htmlname.'_link_section_dir" name="link_section_dir" value="">'; |
|
| 195 | - $out .= '<input type="hidden" id="'.$htmlname.'_link_section_id" name="link_section_id" value="'.$sectionid.'">'; |
|
| 196 | - $out .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
| 197 | - |
|
| 198 | - $out .= '<div class="valignmiddle" >'; |
|
| 199 | - $out .= '<div class="inline-block" style="padding-right: 10px;">'; |
|
| 200 | - if (! empty($conf->global->OPTIMIZEFORTEXTBROWSER)) $out .= '<label for="link">'.$langs->trans("URLToLink") . ':</label> '; |
|
| 201 | - $out .= '<input type="text" name="link" class="flat minwidth400imp" id="link" placeholder="'.dol_escape_htmltag($langs->trans("URLToLink")).'">'; |
|
| 202 | - $out .= '</div>'; |
|
| 203 | - $out .= '<div class="inline-block" style="padding-right: 10px;">'; |
|
| 204 | - if (! empty($conf->global->OPTIMIZEFORTEXTBROWSER)) $out .= '<label for="label">'.$langs->trans("Label") . ':</label> '; |
|
| 205 | - $out .= '<input type="text" class="flat" name="label" id="label" placeholder="'.dol_escape_htmltag($langs->trans("Label")).'">'; |
|
| 206 | - $out .= '<input type="hidden" name="objecttype" value="' . $object->element . '">'; |
|
| 207 | - $out .= '<input type="hidden" name="objectid" value="' . $object->id . '">'; |
|
| 208 | - $out .= '</div>'; |
|
| 209 | - $out .= '<div class="inline-block" style="padding-right: 10px;">'; |
|
| 210 | - $out .= '<input type="submit" class="button" name="linkit" value="'.$langs->trans("ToLink").'"'; |
|
| 211 | - $out .= (empty($conf->global->MAIN_UPLOAD_DOC) || empty($perm)?' disabled':''); |
|
| 212 | - $out .= '>'; |
|
| 213 | - $out .= '</div>'; |
|
| 214 | - $out .= '</div>'; |
|
| 215 | - $out .= '<div class="clearboth"></div>'; |
|
| 216 | - $out .= '</form><br>'; |
|
| 217 | - |
|
| 218 | - $out .= "\n<!-- End form link new url -->\n"; |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - $parameters = array('socid'=>(isset($GLOBALS['socid'])?$GLOBALS['socid']:''), 'id'=>(isset($GLOBALS['id'])?$GLOBALS['id']:''), 'url'=>$url, 'perm'=>$perm); |
|
| 222 | - $res = $hookmanager->executeHooks('formattachOptions',$parameters,$object); |
|
| 223 | - if (empty($res)) |
|
| 224 | - { |
|
| 225 | - print '<div class="attacharea attacharea'.$htmlname.'">'; |
|
| 226 | - print $out; |
|
| 227 | - print '</div>'; |
|
| 228 | - } |
|
| 229 | - print $hookmanager->resPrint; |
|
| 230 | - |
|
| 231 | - return 1; |
|
| 232 | - } |
|
| 233 | - } |
|
| 83 | + global $conf,$langs, $hookmanager; |
|
| 84 | + $hookmanager->initHooks(array('formfile')); |
|
| 85 | + |
|
| 86 | + |
|
| 87 | + if (! empty($conf->browser->layout) && $conf->browser->layout != 'classic') $useajax=0; |
|
| 88 | + |
|
| 89 | + if ((! empty($conf->global->MAIN_USE_JQUERY_FILEUPLOAD) && $useajax) || ($useajax==2)) |
|
| 90 | + { |
|
| 91 | + // TODO: Check this works with 2 forms on same page |
|
| 92 | + // TODO: Check this works with GED module, otherwise, force useajax to 0 |
|
| 93 | + // TODO: This does not support option savingdocmask |
|
| 94 | + // TODO: This break feature to upload links too |
|
| 95 | + return $this->_formAjaxFileUpload($object); |
|
| 96 | + } |
|
| 97 | + else |
|
| 98 | + { |
|
| 99 | + //If there is no permission and the option to hide unauthorized actions is enabled, then nothing is printed |
|
| 100 | + if (!$perm && !empty($conf->global->MAIN_BUTTON_HIDE_UNAUTHORIZED)) { |
|
| 101 | + return 1; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + $maxlength=$size; |
|
| 105 | + |
|
| 106 | + $out = "\n\n<!-- Start form attach new file -->\n"; |
|
| 107 | + |
|
| 108 | + if (empty($title)) $title=$langs->trans("AttachANewFile"); |
|
| 109 | + if ($title != 'none') $out.=load_fiche_titre($title, null, null); |
|
| 110 | + |
|
| 111 | + $out .= '<form name="'.$htmlname.'" id="'.$htmlname.'" action="'.$url.'" enctype="multipart/form-data" method="POST">'; |
|
| 112 | + $out .= '<input type="hidden" id="'.$htmlname.'_section_dir" name="section_dir" value="'.$sectiondir.'">'; |
|
| 113 | + $out .= '<input type="hidden" id="'.$htmlname.'_section_id" name="section_id" value="'.$sectionid.'">'; |
|
| 114 | + $out .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
| 115 | + |
|
| 116 | + $out .= '<table width="100%" class="nobordernopadding">'; |
|
| 117 | + $out .= '<tr>'; |
|
| 118 | + |
|
| 119 | + if (! empty($options)) $out .= '<td>'.$options.'</td>'; |
|
| 120 | + |
|
| 121 | + $out .= '<td class="valignmiddle nowrap">'; |
|
| 122 | + |
|
| 123 | + $max=$conf->global->MAIN_UPLOAD_DOC; // En Kb |
|
| 124 | + $maxphp=@ini_get('upload_max_filesize'); // En inconnu |
|
| 125 | + if (preg_match('/k$/i',$maxphp)) $maxphp=$maxphp*1; |
|
| 126 | + if (preg_match('/m$/i',$maxphp)) $maxphp=$maxphp*1024; |
|
| 127 | + if (preg_match('/g$/i',$maxphp)) $maxphp=$maxphp*1024*1024; |
|
| 128 | + if (preg_match('/t$/i',$maxphp)) $maxphp=$maxphp*1024*1024*1024; |
|
| 129 | + // Now $max and $maxphp are in Kb |
|
| 130 | + $maxmin = $max; |
|
| 131 | + if ($maxphp > 0) $maxmin=min($max,$maxphp); |
|
| 132 | + |
|
| 133 | + if ($maxmin > 0) |
|
| 134 | + { |
|
| 135 | + // MAX_FILE_SIZE doit précéder le champ input de type file |
|
| 136 | + $out .= '<input type="hidden" name="max_file_size" value="'.($maxmin*1024).'">'; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + $out .= '<input class="flat minwidth400" type="file"'; |
|
| 140 | + $out .= ((! empty($conf->global->MAIN_DISABLE_MULTIPLE_FILEUPLOAD) || $conf->browser->layout != 'classic')?' name="userfile"':' name="userfile[]" multiple'); |
|
| 141 | + $out .= (empty($conf->global->MAIN_UPLOAD_DOC) || empty($perm)?' disabled':''); |
|
| 142 | + $out .= (!empty($accept)?' accept="'.$accept.'"':' accept=""'); |
|
| 143 | + $out .= '>'; |
|
| 144 | + $out .= ' '; |
|
| 145 | + $out .= '<input type="submit" class="button" name="sendit" value="'.$langs->trans("Upload").'"'; |
|
| 146 | + $out .= (empty($conf->global->MAIN_UPLOAD_DOC) || empty($perm)?' disabled':''); |
|
| 147 | + $out .= '>'; |
|
| 148 | + |
|
| 149 | + if ($addcancel) |
|
| 150 | + { |
|
| 151 | + $out .= ' '; |
|
| 152 | + $out .= '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">'; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + if (! empty($conf->global->MAIN_UPLOAD_DOC)) |
|
| 156 | + { |
|
| 157 | + if ($perm) |
|
| 158 | + { |
|
| 159 | + $langs->load('other'); |
|
| 160 | + $out .= ' '; |
|
| 161 | + $out .= info_admin($langs->trans("ThisLimitIsDefinedInSetup",$max,$maxphp),1); |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + else |
|
| 165 | + { |
|
| 166 | + $out .= ' ('.$langs->trans("UploadDisabled").')'; |
|
| 167 | + } |
|
| 168 | + $out .= "</td></tr>"; |
|
| 169 | + |
|
| 170 | + if ($savingdocmask) |
|
| 171 | + { |
|
| 172 | + $out .= '<tr>'; |
|
| 173 | + if (! empty($options)) $out .= '<td>'.$options.'</td>'; |
|
| 174 | + $out .= '<td valign="middle" class="nowrap">'; |
|
| 175 | + $out .= '<input type="checkbox" checked class="savingdocmask" name="savingdocmask" value="'.dol_escape_js($savingdocmask).'"> '.$langs->trans("SaveUploadedFileWithMask", preg_replace('/__file__/',$langs->transnoentitiesnoconv("OriginFileName"),$savingdocmask), $langs->transnoentitiesnoconv("OriginFileName")); |
|
| 176 | + $out .= '</td>'; |
|
| 177 | + $out .= '</tr>'; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + $out .= "</table>"; |
|
| 181 | + |
|
| 182 | + $out .= '</form>'; |
|
| 183 | + if (empty($sectionid)) $out .= '<br>'; |
|
| 184 | + |
|
| 185 | + $out .= "\n<!-- End form attach new file -->\n"; |
|
| 186 | + |
|
| 187 | + if ($linkfiles) |
|
| 188 | + { |
|
| 189 | + $out .= "\n<!-- Start form link new url -->\n"; |
|
| 190 | + $langs->load('link'); |
|
| 191 | + $title = $langs->trans("LinkANewFile"); |
|
| 192 | + $out .= load_fiche_titre($title, null, null); |
|
| 193 | + $out .= '<form name="'.$htmlname.'_link" id="'.$htmlname.'_link" action="'.$url.'" method="POST">'; |
|
| 194 | + $out .= '<input type="hidden" id="'.$htmlname.'_link_section_dir" name="link_section_dir" value="">'; |
|
| 195 | + $out .= '<input type="hidden" id="'.$htmlname.'_link_section_id" name="link_section_id" value="'.$sectionid.'">'; |
|
| 196 | + $out .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
| 197 | + |
|
| 198 | + $out .= '<div class="valignmiddle" >'; |
|
| 199 | + $out .= '<div class="inline-block" style="padding-right: 10px;">'; |
|
| 200 | + if (! empty($conf->global->OPTIMIZEFORTEXTBROWSER)) $out .= '<label for="link">'.$langs->trans("URLToLink") . ':</label> '; |
|
| 201 | + $out .= '<input type="text" name="link" class="flat minwidth400imp" id="link" placeholder="'.dol_escape_htmltag($langs->trans("URLToLink")).'">'; |
|
| 202 | + $out .= '</div>'; |
|
| 203 | + $out .= '<div class="inline-block" style="padding-right: 10px;">'; |
|
| 204 | + if (! empty($conf->global->OPTIMIZEFORTEXTBROWSER)) $out .= '<label for="label">'.$langs->trans("Label") . ':</label> '; |
|
| 205 | + $out .= '<input type="text" class="flat" name="label" id="label" placeholder="'.dol_escape_htmltag($langs->trans("Label")).'">'; |
|
| 206 | + $out .= '<input type="hidden" name="objecttype" value="' . $object->element . '">'; |
|
| 207 | + $out .= '<input type="hidden" name="objectid" value="' . $object->id . '">'; |
|
| 208 | + $out .= '</div>'; |
|
| 209 | + $out .= '<div class="inline-block" style="padding-right: 10px;">'; |
|
| 210 | + $out .= '<input type="submit" class="button" name="linkit" value="'.$langs->trans("ToLink").'"'; |
|
| 211 | + $out .= (empty($conf->global->MAIN_UPLOAD_DOC) || empty($perm)?' disabled':''); |
|
| 212 | + $out .= '>'; |
|
| 213 | + $out .= '</div>'; |
|
| 214 | + $out .= '</div>'; |
|
| 215 | + $out .= '<div class="clearboth"></div>'; |
|
| 216 | + $out .= '</form><br>'; |
|
| 217 | + |
|
| 218 | + $out .= "\n<!-- End form link new url -->\n"; |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + $parameters = array('socid'=>(isset($GLOBALS['socid'])?$GLOBALS['socid']:''), 'id'=>(isset($GLOBALS['id'])?$GLOBALS['id']:''), 'url'=>$url, 'perm'=>$perm); |
|
| 222 | + $res = $hookmanager->executeHooks('formattachOptions',$parameters,$object); |
|
| 223 | + if (empty($res)) |
|
| 224 | + { |
|
| 225 | + print '<div class="attacharea attacharea'.$htmlname.'">'; |
|
| 226 | + print $out; |
|
| 227 | + print '</div>'; |
|
| 228 | + } |
|
| 229 | + print $hookmanager->resPrint; |
|
| 230 | + |
|
| 231 | + return 1; |
|
| 232 | + } |
|
| 233 | + } |
|
| 234 | 234 | |
| 235 | 235 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
| 236 | - /** |
|
| 237 | - * Show the box with list of available documents for object |
|
| 238 | - * |
|
| 239 | - * @param string $modulepart propal, facture, facture_fourn, ... |
|
| 240 | - * @param string $modulesubdir Sub-directory to scan (Example: '0/1/10', 'FA/DD/MM/YY/9999'). Use '' if file is not into subdir of module. |
|
| 241 | - * @param string $filedir Directory to scan |
|
| 242 | - * @param string $urlsource Url of origin page (for return) |
|
| 243 | - * @param int $genallowed Generation is allowed (1/0 or array of formats) |
|
| 244 | - * @param int $delallowed Remove is allowed (1/0) |
|
| 245 | - * @param string $modelselected Model to preselect by default |
|
| 246 | - * @param integer $allowgenifempty Show warning if no model activated |
|
| 247 | - * @param integer $forcenomultilang Do not show language option (even if MAIN_MULTILANGS defined) |
|
| 248 | - * @param int $iconPDF Show only PDF icon with link (1/0) |
|
| 249 | - * @param int $notused Not used |
|
| 250 | - * @param integer $noform Do not output html form tags |
|
| 251 | - * @param string $param More param on http links |
|
| 252 | - * @param string $title Title to show on top of form |
|
| 253 | - * @param string $buttonlabel Label on submit button |
|
| 254 | - * @param string $codelang Default language code to use on lang combo box if multilang is enabled |
|
| 255 | - * @return int <0 if KO, number of shown files if OK |
|
| 256 | - * @deprecated Use print xxx->showdocuments() instead. |
|
| 257 | - */ |
|
| 258 | - function show_documents($modulepart,$modulesubdir,$filedir,$urlsource,$genallowed,$delallowed=0,$modelselected='',$allowgenifempty=1,$forcenomultilang=0,$iconPDF=0,$notused=0,$noform=0,$param='',$title='',$buttonlabel='',$codelang='') |
|
| 259 | - { |
|
| 236 | + /** |
|
| 237 | + * Show the box with list of available documents for object |
|
| 238 | + * |
|
| 239 | + * @param string $modulepart propal, facture, facture_fourn, ... |
|
| 240 | + * @param string $modulesubdir Sub-directory to scan (Example: '0/1/10', 'FA/DD/MM/YY/9999'). Use '' if file is not into subdir of module. |
|
| 241 | + * @param string $filedir Directory to scan |
|
| 242 | + * @param string $urlsource Url of origin page (for return) |
|
| 243 | + * @param int $genallowed Generation is allowed (1/0 or array of formats) |
|
| 244 | + * @param int $delallowed Remove is allowed (1/0) |
|
| 245 | + * @param string $modelselected Model to preselect by default |
|
| 246 | + * @param integer $allowgenifempty Show warning if no model activated |
|
| 247 | + * @param integer $forcenomultilang Do not show language option (even if MAIN_MULTILANGS defined) |
|
| 248 | + * @param int $iconPDF Show only PDF icon with link (1/0) |
|
| 249 | + * @param int $notused Not used |
|
| 250 | + * @param integer $noform Do not output html form tags |
|
| 251 | + * @param string $param More param on http links |
|
| 252 | + * @param string $title Title to show on top of form |
|
| 253 | + * @param string $buttonlabel Label on submit button |
|
| 254 | + * @param string $codelang Default language code to use on lang combo box if multilang is enabled |
|
| 255 | + * @return int <0 if KO, number of shown files if OK |
|
| 256 | + * @deprecated Use print xxx->showdocuments() instead. |
|
| 257 | + */ |
|
| 258 | + function show_documents($modulepart,$modulesubdir,$filedir,$urlsource,$genallowed,$delallowed=0,$modelselected='',$allowgenifempty=1,$forcenomultilang=0,$iconPDF=0,$notused=0,$noform=0,$param='',$title='',$buttonlabel='',$codelang='') |
|
| 259 | + { |
|
| 260 | 260 | // phpcs:enable |
| 261 | - $this->numoffiles=0; |
|
| 262 | - print $this->showdocuments($modulepart,$modulesubdir,$filedir,$urlsource,$genallowed,$delallowed,$modelselected,$allowgenifempty,$forcenomultilang,$iconPDF,$notused,$noform,$param,$title,$buttonlabel,$codelang); |
|
| 263 | - return $this->numoffiles; |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * Return a string to show the box with list of available documents for object. |
|
| 268 | - * This also set the property $this->numoffiles |
|
| 269 | - * |
|
| 270 | - * @param string $modulepart Module the files are related to ('propal', 'facture', 'facture_fourn', 'mymodule', 'mymodule_temp', ...) |
|
| 271 | - * @param string $modulesubdir Existing (so sanitized) sub-directory to scan (Example: '0/1/10', 'FA/DD/MM/YY/9999'). Use '' if file is not into subdir of module. |
|
| 272 | - * @param string $filedir Directory to scan |
|
| 273 | - * @param string $urlsource Url of origin page (for return) |
|
| 274 | - * @param int $genallowed Generation is allowed (1/0 or array list of templates) |
|
| 275 | - * @param int $delallowed Remove is allowed (1/0) |
|
| 276 | - * @param string $modelselected Model to preselect by default |
|
| 277 | - * @param integer $allowgenifempty Allow generation even if list of template ($genallowed) is empty (show however a warning) |
|
| 278 | - * @param integer $forcenomultilang Do not show language option (even if MAIN_MULTILANGS defined) |
|
| 279 | - * @param int $iconPDF Deprecated, see getDocumentsLink |
|
| 280 | - * @param int $notused Not used |
|
| 281 | - * @param integer $noform Do not output html form tags |
|
| 282 | - * @param string $param More param on http links |
|
| 283 | - * @param string $title Title to show on top of form |
|
| 284 | - * @param string $buttonlabel Label on submit button |
|
| 285 | - * @param string $codelang Default language code to use on lang combo box if multilang is enabled |
|
| 286 | - * @param string $morepicto Add more HTML content into cell with picto |
|
| 287 | - * @param Object $object Object when method is called from an object card. |
|
| 288 | - * @param int $hideifempty Hide section of generated files if there is no file |
|
| 289 | - * @return string Output string with HTML array of documents (might be empty string) |
|
| 290 | - */ |
|
| 291 | - function showdocuments($modulepart,$modulesubdir,$filedir,$urlsource,$genallowed,$delallowed=0,$modelselected='',$allowgenifempty=1,$forcenomultilang=0,$iconPDF=0,$notused=0,$noform=0,$param='',$title='',$buttonlabel='',$codelang='',$morepicto='',$object=null,$hideifempty=0) |
|
| 292 | - { |
|
| 293 | - // Deprecation warning |
|
| 294 | - if (! empty($iconPDF)) { |
|
| 295 | - dol_syslog(__METHOD__ . ": passing iconPDF parameter is deprecated", LOG_WARNING); |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - global $langs, $conf, $user, $hookmanager; |
|
| 299 | - global $form; |
|
| 300 | - |
|
| 301 | - if (! is_object($form)) $form=new Form($this->db); |
|
| 302 | - |
|
| 303 | - include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
| 304 | - |
|
| 305 | - // For backward compatibility |
|
| 306 | - if (! empty($iconPDF)) { |
|
| 307 | - return $this->getDocumentsLink($modulepart, $modulesubdir, $filedir); |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - // Add entity in $param |
|
| 311 | - $param.= 'entity='.(!empty($object->entity)?$object->entity:$conf->entity); |
|
| 312 | - |
|
| 313 | - $printer=0; |
|
| 314 | - if (in_array($modulepart,array('facture','supplier_proposal','propal','proposal','order','commande','expedition', 'commande_fournisseur', 'expensereport','livraison'))) // The direct print feature is implemented only for such elements |
|
| 315 | - { |
|
| 316 | - $printer = (!empty($user->rights->printing->read) && !empty($conf->printing->enabled))?true:false; |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - $hookmanager->initHooks(array('formfile')); |
|
| 320 | - |
|
| 321 | - // Get list of files |
|
| 322 | - $file_list=null; |
|
| 323 | - if (! empty($filedir)) |
|
| 324 | - { |
|
| 325 | - $file_list=dol_dir_list($filedir,'files',0,'','(\.meta|_preview.*.*\.png)$','date',SORT_DESC); |
|
| 326 | - } |
|
| 327 | - if ($hideifempty && empty($file_list)) return ''; |
|
| 328 | - |
|
| 329 | - $out=''; |
|
| 330 | - $forname='builddoc'; |
|
| 331 | - $headershown=0; |
|
| 332 | - $showempty=0; |
|
| 333 | - $i=0; |
|
| 334 | - |
|
| 335 | - $out.= "\n".'<!-- Start show_document -->'."\n"; |
|
| 336 | - //print 'filedir='.$filedir; |
|
| 337 | - |
|
| 338 | - if (preg_match('/massfilesarea_/', $modulepart)) |
|
| 339 | - { |
|
| 340 | - $out.='<div id="show_files"><br></div>'."\n"; |
|
| 341 | - $title=$langs->trans("MassFilesArea").' <a href="" id="togglemassfilesarea" ref="shown">('.$langs->trans("Hide").')</a>'; |
|
| 342 | - $title.='<script type="text/javascript" language="javascript"> |
|
| 261 | + $this->numoffiles=0; |
|
| 262 | + print $this->showdocuments($modulepart,$modulesubdir,$filedir,$urlsource,$genallowed,$delallowed,$modelselected,$allowgenifempty,$forcenomultilang,$iconPDF,$notused,$noform,$param,$title,$buttonlabel,$codelang); |
|
| 263 | + return $this->numoffiles; |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * Return a string to show the box with list of available documents for object. |
|
| 268 | + * This also set the property $this->numoffiles |
|
| 269 | + * |
|
| 270 | + * @param string $modulepart Module the files are related to ('propal', 'facture', 'facture_fourn', 'mymodule', 'mymodule_temp', ...) |
|
| 271 | + * @param string $modulesubdir Existing (so sanitized) sub-directory to scan (Example: '0/1/10', 'FA/DD/MM/YY/9999'). Use '' if file is not into subdir of module. |
|
| 272 | + * @param string $filedir Directory to scan |
|
| 273 | + * @param string $urlsource Url of origin page (for return) |
|
| 274 | + * @param int $genallowed Generation is allowed (1/0 or array list of templates) |
|
| 275 | + * @param int $delallowed Remove is allowed (1/0) |
|
| 276 | + * @param string $modelselected Model to preselect by default |
|
| 277 | + * @param integer $allowgenifempty Allow generation even if list of template ($genallowed) is empty (show however a warning) |
|
| 278 | + * @param integer $forcenomultilang Do not show language option (even if MAIN_MULTILANGS defined) |
|
| 279 | + * @param int $iconPDF Deprecated, see getDocumentsLink |
|
| 280 | + * @param int $notused Not used |
|
| 281 | + * @param integer $noform Do not output html form tags |
|
| 282 | + * @param string $param More param on http links |
|
| 283 | + * @param string $title Title to show on top of form |
|
| 284 | + * @param string $buttonlabel Label on submit button |
|
| 285 | + * @param string $codelang Default language code to use on lang combo box if multilang is enabled |
|
| 286 | + * @param string $morepicto Add more HTML content into cell with picto |
|
| 287 | + * @param Object $object Object when method is called from an object card. |
|
| 288 | + * @param int $hideifempty Hide section of generated files if there is no file |
|
| 289 | + * @return string Output string with HTML array of documents (might be empty string) |
|
| 290 | + */ |
|
| 291 | + function showdocuments($modulepart,$modulesubdir,$filedir,$urlsource,$genallowed,$delallowed=0,$modelselected='',$allowgenifempty=1,$forcenomultilang=0,$iconPDF=0,$notused=0,$noform=0,$param='',$title='',$buttonlabel='',$codelang='',$morepicto='',$object=null,$hideifempty=0) |
|
| 292 | + { |
|
| 293 | + // Deprecation warning |
|
| 294 | + if (! empty($iconPDF)) { |
|
| 295 | + dol_syslog(__METHOD__ . ": passing iconPDF parameter is deprecated", LOG_WARNING); |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + global $langs, $conf, $user, $hookmanager; |
|
| 299 | + global $form; |
|
| 300 | + |
|
| 301 | + if (! is_object($form)) $form=new Form($this->db); |
|
| 302 | + |
|
| 303 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
| 304 | + |
|
| 305 | + // For backward compatibility |
|
| 306 | + if (! empty($iconPDF)) { |
|
| 307 | + return $this->getDocumentsLink($modulepart, $modulesubdir, $filedir); |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + // Add entity in $param |
|
| 311 | + $param.= 'entity='.(!empty($object->entity)?$object->entity:$conf->entity); |
|
| 312 | + |
|
| 313 | + $printer=0; |
|
| 314 | + if (in_array($modulepart,array('facture','supplier_proposal','propal','proposal','order','commande','expedition', 'commande_fournisseur', 'expensereport','livraison'))) // The direct print feature is implemented only for such elements |
|
| 315 | + { |
|
| 316 | + $printer = (!empty($user->rights->printing->read) && !empty($conf->printing->enabled))?true:false; |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + $hookmanager->initHooks(array('formfile')); |
|
| 320 | + |
|
| 321 | + // Get list of files |
|
| 322 | + $file_list=null; |
|
| 323 | + if (! empty($filedir)) |
|
| 324 | + { |
|
| 325 | + $file_list=dol_dir_list($filedir,'files',0,'','(\.meta|_preview.*.*\.png)$','date',SORT_DESC); |
|
| 326 | + } |
|
| 327 | + if ($hideifempty && empty($file_list)) return ''; |
|
| 328 | + |
|
| 329 | + $out=''; |
|
| 330 | + $forname='builddoc'; |
|
| 331 | + $headershown=0; |
|
| 332 | + $showempty=0; |
|
| 333 | + $i=0; |
|
| 334 | + |
|
| 335 | + $out.= "\n".'<!-- Start show_document -->'."\n"; |
|
| 336 | + //print 'filedir='.$filedir; |
|
| 337 | + |
|
| 338 | + if (preg_match('/massfilesarea_/', $modulepart)) |
|
| 339 | + { |
|
| 340 | + $out.='<div id="show_files"><br></div>'."\n"; |
|
| 341 | + $title=$langs->trans("MassFilesArea").' <a href="" id="togglemassfilesarea" ref="shown">('.$langs->trans("Hide").')</a>'; |
|
| 342 | + $title.='<script type="text/javascript" language="javascript"> |
|
| 343 | 343 | jQuery(document).ready(function() { |
| 344 | 344 | jQuery(\'#togglemassfilesarea\').click(function() { |
| 345 | 345 | if (jQuery(\'#togglemassfilesarea\').attr(\'ref\') == "shown") |
@@ -358,1489 +358,1489 @@ discard block |
||
| 358 | 358 | }); |
| 359 | 359 | }); |
| 360 | 360 | </script>'; |
| 361 | - } |
|
| 362 | - |
|
| 363 | - $titletoshow=$langs->trans("Documents"); |
|
| 364 | - if (! empty($title)) $titletoshow=$title; |
|
| 365 | - |
|
| 366 | - // Show table |
|
| 367 | - if ($genallowed) |
|
| 368 | - { |
|
| 369 | - $modellist=array(); |
|
| 370 | - |
|
| 371 | - if ($modulepart == 'company') |
|
| 372 | - { |
|
| 373 | - $showempty=1; |
|
| 374 | - if (is_array($genallowed)) $modellist=$genallowed; |
|
| 375 | - else |
|
| 376 | - { |
|
| 377 | - include_once DOL_DOCUMENT_ROOT.'/core/modules/societe/modules_societe.class.php'; |
|
| 378 | - $modellist=ModeleThirdPartyDoc::liste_modeles($this->db); |
|
| 379 | - } |
|
| 380 | - } |
|
| 381 | - else if ($modulepart == 'propal') |
|
| 382 | - { |
|
| 383 | - if (is_array($genallowed)) $modellist=$genallowed; |
|
| 384 | - else |
|
| 385 | - { |
|
| 386 | - include_once DOL_DOCUMENT_ROOT.'/core/modules/propale/modules_propale.php'; |
|
| 387 | - $modellist=ModelePDFPropales::liste_modeles($this->db); |
|
| 388 | - } |
|
| 389 | - } |
|
| 390 | - else if ($modulepart == 'supplier_proposal') |
|
| 391 | - { |
|
| 392 | - if (is_array($genallowed)) $modellist=$genallowed; |
|
| 393 | - else |
|
| 394 | - { |
|
| 395 | - include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_proposal/modules_supplier_proposal.php'; |
|
| 396 | - $modellist=ModelePDFSupplierProposal::liste_modeles($this->db); |
|
| 397 | - } |
|
| 398 | - } |
|
| 399 | - else if ($modulepart == 'commande') |
|
| 400 | - { |
|
| 401 | - if (is_array($genallowed)) $modellist=$genallowed; |
|
| 402 | - else |
|
| 403 | - { |
|
| 404 | - include_once DOL_DOCUMENT_ROOT.'/core/modules/commande/modules_commande.php'; |
|
| 405 | - $modellist=ModelePDFCommandes::liste_modeles($this->db); |
|
| 406 | - } |
|
| 407 | - } |
|
| 408 | - elseif ($modulepart == 'expedition') |
|
| 409 | - { |
|
| 410 | - if (is_array($genallowed)) $modellist=$genallowed; |
|
| 411 | - else |
|
| 412 | - { |
|
| 413 | - include_once DOL_DOCUMENT_ROOT.'/core/modules/expedition/modules_expedition.php'; |
|
| 414 | - $modellist=ModelePDFExpedition::liste_modeles($this->db); |
|
| 415 | - } |
|
| 416 | - } |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + $titletoshow=$langs->trans("Documents"); |
|
| 364 | + if (! empty($title)) $titletoshow=$title; |
|
| 365 | + |
|
| 366 | + // Show table |
|
| 367 | + if ($genallowed) |
|
| 368 | + { |
|
| 369 | + $modellist=array(); |
|
| 370 | + |
|
| 371 | + if ($modulepart == 'company') |
|
| 372 | + { |
|
| 373 | + $showempty=1; |
|
| 374 | + if (is_array($genallowed)) $modellist=$genallowed; |
|
| 375 | + else |
|
| 376 | + { |
|
| 377 | + include_once DOL_DOCUMENT_ROOT.'/core/modules/societe/modules_societe.class.php'; |
|
| 378 | + $modellist=ModeleThirdPartyDoc::liste_modeles($this->db); |
|
| 379 | + } |
|
| 380 | + } |
|
| 381 | + else if ($modulepart == 'propal') |
|
| 382 | + { |
|
| 383 | + if (is_array($genallowed)) $modellist=$genallowed; |
|
| 384 | + else |
|
| 385 | + { |
|
| 386 | + include_once DOL_DOCUMENT_ROOT.'/core/modules/propale/modules_propale.php'; |
|
| 387 | + $modellist=ModelePDFPropales::liste_modeles($this->db); |
|
| 388 | + } |
|
| 389 | + } |
|
| 390 | + else if ($modulepart == 'supplier_proposal') |
|
| 391 | + { |
|
| 392 | + if (is_array($genallowed)) $modellist=$genallowed; |
|
| 393 | + else |
|
| 394 | + { |
|
| 395 | + include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_proposal/modules_supplier_proposal.php'; |
|
| 396 | + $modellist=ModelePDFSupplierProposal::liste_modeles($this->db); |
|
| 397 | + } |
|
| 398 | + } |
|
| 399 | + else if ($modulepart == 'commande') |
|
| 400 | + { |
|
| 401 | + if (is_array($genallowed)) $modellist=$genallowed; |
|
| 402 | + else |
|
| 403 | + { |
|
| 404 | + include_once DOL_DOCUMENT_ROOT.'/core/modules/commande/modules_commande.php'; |
|
| 405 | + $modellist=ModelePDFCommandes::liste_modeles($this->db); |
|
| 406 | + } |
|
| 407 | + } |
|
| 408 | + elseif ($modulepart == 'expedition') |
|
| 409 | + { |
|
| 410 | + if (is_array($genallowed)) $modellist=$genallowed; |
|
| 411 | + else |
|
| 412 | + { |
|
| 413 | + include_once DOL_DOCUMENT_ROOT.'/core/modules/expedition/modules_expedition.php'; |
|
| 414 | + $modellist=ModelePDFExpedition::liste_modeles($this->db); |
|
| 415 | + } |
|
| 416 | + } |
|
| 417 | 417 | elseif ($modulepart == 'reception') |
| 418 | 418 | { |
| 419 | 419 | if (is_array($genallowed)) $modellist=$genallowed; |
| 420 | 420 | else |
| 421 | 421 | { |
| 422 | - include_once DOL_DOCUMENT_ROOT.'/core/modules/reception/modules_reception.php'; |
|
| 423 | - $modellist = ModelePdfReception::liste_modeles($this->db); |
|
| 424 | - } |
|
| 425 | - } |
|
| 426 | - elseif ($modulepart == 'livraison') |
|
| 427 | - { |
|
| 428 | - if (is_array($genallowed)) $modellist=$genallowed; |
|
| 429 | - else |
|
| 430 | - { |
|
| 431 | - include_once DOL_DOCUMENT_ROOT.'/core/modules/livraison/modules_livraison.php'; |
|
| 432 | - $modellist=ModelePDFDeliveryOrder::liste_modeles($this->db); |
|
| 433 | - } |
|
| 434 | - } |
|
| 435 | - else if ($modulepart == 'ficheinter') |
|
| 436 | - { |
|
| 437 | - if (is_array($genallowed)) $modellist=$genallowed; |
|
| 438 | - else |
|
| 439 | - { |
|
| 440 | - include_once DOL_DOCUMENT_ROOT.'/core/modules/fichinter/modules_fichinter.php'; |
|
| 441 | - $modellist=ModelePDFFicheinter::liste_modeles($this->db); |
|
| 442 | - } |
|
| 443 | - } |
|
| 444 | - elseif ($modulepart == 'facture') |
|
| 445 | - { |
|
| 446 | - if (is_array($genallowed)) $modellist=$genallowed; |
|
| 447 | - else |
|
| 448 | - { |
|
| 449 | - include_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php'; |
|
| 450 | - $modellist=ModelePDFFactures::liste_modeles($this->db); |
|
| 451 | - } |
|
| 452 | - } |
|
| 453 | - elseif ($modulepart == 'contract') |
|
| 454 | - { |
|
| 455 | - if (is_array($genallowed)) $modellist=$genallowed; |
|
| 456 | - else |
|
| 457 | - { |
|
| 458 | - include_once DOL_DOCUMENT_ROOT.'/core/modules/contract/modules_contract.php'; |
|
| 459 | - $modellist=ModelePDFContract::liste_modeles($this->db); |
|
| 460 | - } |
|
| 461 | - } |
|
| 462 | - elseif ($modulepart == 'project') |
|
| 463 | - { |
|
| 464 | - if (is_array($genallowed)) $modellist=$genallowed; |
|
| 465 | - else |
|
| 466 | - { |
|
| 467 | - include_once DOL_DOCUMENT_ROOT.'/core/modules/project/modules_project.php'; |
|
| 468 | - $modellist=ModelePDFProjects::liste_modeles($this->db); |
|
| 469 | - } |
|
| 470 | - } |
|
| 471 | - elseif ($modulepart == 'project_task') |
|
| 472 | - { |
|
| 473 | - if (is_array($genallowed)) $modellist=$genallowed; |
|
| 474 | - else |
|
| 475 | - { |
|
| 476 | - include_once DOL_DOCUMENT_ROOT.'/core/modules/project/task/modules_task.php'; |
|
| 477 | - $modellist=ModelePDFTask::liste_modeles($this->db); |
|
| 478 | - } |
|
| 479 | - } |
|
| 480 | - elseif ($modulepart == 'product') |
|
| 481 | - { |
|
| 482 | - if (is_array($genallowed)) $modellist=$genallowed; |
|
| 483 | - else |
|
| 484 | - { |
|
| 485 | - include_once DOL_DOCUMENT_ROOT.'/core/modules/product/modules_product.class.php'; |
|
| 486 | - $modellist=ModelePDFProduct::liste_modeles($this->db); |
|
| 487 | - } |
|
| 488 | - } |
|
| 489 | - elseif ($modulepart == 'product_batch') |
|
| 490 | - { |
|
| 491 | - if (is_array($genallowed)) $modellist=$genallowed; |
|
| 492 | - else |
|
| 493 | - { |
|
| 494 | - include_once DOL_DOCUMENT_ROOT.'/core/modules/product_batch/modules_product_batch.class.php'; |
|
| 495 | - $modellist=ModelePDFProductBatch::liste_modeles($this->db); |
|
| 496 | - } |
|
| 497 | - } |
|
| 498 | - elseif ($modulepart == 'stock') |
|
| 499 | - { |
|
| 500 | - if (is_array($genallowed)) $modellist=$genallowed; |
|
| 501 | - else |
|
| 502 | - { |
|
| 503 | - include_once DOL_DOCUMENT_ROOT.'/core/modules/stock/modules_stock.php'; |
|
| 504 | - $modellist=ModelePDFStock::liste_modeles($this->db); |
|
| 505 | - } |
|
| 506 | - } |
|
| 507 | - elseif ($modulepart == 'movement') |
|
| 508 | - { |
|
| 509 | - if (is_array($genallowed)) $modellist=$genallowed; |
|
| 510 | - else |
|
| 511 | - { |
|
| 512 | - include_once DOL_DOCUMENT_ROOT.'/core/modules/stock/modules_movement.php'; |
|
| 513 | - $modellist=ModelePDFMovement::liste_modeles($this->db); |
|
| 514 | - } |
|
| 515 | - } |
|
| 516 | - elseif ($modulepart == 'export') |
|
| 517 | - { |
|
| 518 | - if (is_array($genallowed)) $modellist=$genallowed; |
|
| 519 | - else |
|
| 520 | - { |
|
| 521 | - include_once DOL_DOCUMENT_ROOT.'/core/modules/export/modules_export.php'; |
|
| 522 | - $modellist=ModeleExports::liste_modeles($this->db); |
|
| 523 | - } |
|
| 524 | - } |
|
| 525 | - else if ($modulepart == 'commande_fournisseur' || $modulepart == 'supplier_order') |
|
| 526 | - { |
|
| 527 | - if (is_array($genallowed)) $modellist=$genallowed; |
|
| 528 | - else |
|
| 529 | - { |
|
| 530 | - include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_order/modules_commandefournisseur.php'; |
|
| 531 | - $modellist=ModelePDFSuppliersOrders::liste_modeles($this->db); |
|
| 532 | - } |
|
| 533 | - } |
|
| 534 | - else if ($modulepart == 'facture_fournisseur' || $modulepart == 'supplier_invoice') |
|
| 535 | - { |
|
| 536 | - if (is_array($genallowed)) $modellist=$genallowed; |
|
| 537 | - else |
|
| 538 | - { |
|
| 539 | - include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_invoice/modules_facturefournisseur.php'; |
|
| 540 | - $modellist=ModelePDFSuppliersInvoices::liste_modeles($this->db); |
|
| 541 | - } |
|
| 542 | - } |
|
| 543 | - else if ($modulepart == 'supplier_payment') |
|
| 544 | - { |
|
| 545 | - if (is_array($genallowed)) $modellist=$genallowed; |
|
| 546 | - else |
|
| 547 | - { |
|
| 548 | - include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_payment/modules_supplier_payment.php'; |
|
| 549 | - $modellist=ModelePDFSuppliersPayments::liste_modeles($this->db); |
|
| 550 | - } |
|
| 551 | - } |
|
| 552 | - else if ($modulepart == 'remisecheque') |
|
| 553 | - { |
|
| 554 | - if (is_array($genallowed)) $modellist=$genallowed; |
|
| 555 | - else |
|
| 556 | - { |
|
| 557 | - include_once DOL_DOCUMENT_ROOT.'/core/modules/cheque/modules_chequereceipts.php'; |
|
| 558 | - $modellist=ModeleChequeReceipts::liste_modeles($this->db); |
|
| 559 | - } |
|
| 560 | - } |
|
| 561 | - elseif ($modulepart == 'donation') |
|
| 562 | - { |
|
| 563 | - if (is_array($genallowed)) $modellist=$genallowed; |
|
| 564 | - else |
|
| 565 | - { |
|
| 566 | - include_once DOL_DOCUMENT_ROOT.'/core/modules/dons/modules_don.php'; |
|
| 567 | - $modellist=ModeleDon::liste_modeles($this->db); |
|
| 568 | - } |
|
| 569 | - } |
|
| 570 | - elseif ($modulepart == 'member') |
|
| 571 | - { |
|
| 572 | - if (is_array($genallowed)) $modellist=$genallowed; |
|
| 573 | - else |
|
| 574 | - { |
|
| 575 | - include_once DOL_DOCUMENT_ROOT.'/core/modules/member/modules_cards.php'; |
|
| 576 | - $modellist=ModelePDFCards::liste_modeles($this->db); |
|
| 577 | - } |
|
| 578 | - } |
|
| 579 | - elseif ($modulepart == 'agenda' || $modulepart == 'actions') |
|
| 580 | - { |
|
| 581 | - if (is_array($genallowed)) $modellist=$genallowed; |
|
| 582 | - else |
|
| 583 | - { |
|
| 584 | - include_once DOL_DOCUMENT_ROOT.'/core/modules/action/modules_action.php'; |
|
| 585 | - $modellist=ModeleAction::liste_modeles($this->db); |
|
| 586 | - } |
|
| 587 | - } |
|
| 588 | - else if ($modulepart == 'expensereport') |
|
| 589 | - { |
|
| 590 | - if (is_array($genallowed)) $modellist=$genallowed; |
|
| 591 | - else |
|
| 592 | - { |
|
| 593 | - include_once DOL_DOCUMENT_ROOT.'/core/modules/expensereport/modules_expensereport.php'; |
|
| 594 | - $modellist=ModeleExpenseReport::liste_modeles($this->db); |
|
| 595 | - } |
|
| 596 | - } |
|
| 597 | - else if ($modulepart == 'unpaid') |
|
| 598 | - { |
|
| 599 | - $modellist=''; |
|
| 600 | - } |
|
| 601 | - elseif ($modulepart == 'user') |
|
| 602 | - { |
|
| 603 | - if (is_array($genallowed)) $modellist=$genallowed; |
|
| 604 | - else |
|
| 605 | - { |
|
| 606 | - include_once DOL_DOCUMENT_ROOT.'/core/modules/user/modules_user.class.php'; |
|
| 607 | - $modellist=ModelePDFUser::liste_modeles($this->db); |
|
| 608 | - } |
|
| 609 | - } |
|
| 610 | - elseif ($modulepart == 'usergroup') |
|
| 611 | - { |
|
| 612 | - if (is_array($genallowed)) $modellist=$genallowed; |
|
| 613 | - else |
|
| 614 | - { |
|
| 615 | - include_once DOL_DOCUMENT_ROOT.'/core/modules/usergroup/modules_usergroup.class.php'; |
|
| 616 | - $modellist=ModelePDFUserGroup::liste_modeles($this->db); |
|
| 617 | - } |
|
| 618 | - } |
|
| 619 | - else |
|
| 620 | - { |
|
| 621 | - // For normalized standard modules |
|
| 622 | - $file=dol_buildpath('/core/modules/'.$modulepart.'/modules_'.$modulepart.'.php',0); |
|
| 623 | - if (file_exists($file)) |
|
| 624 | - { |
|
| 625 | - $res=include_once $file; |
|
| 626 | - } |
|
| 627 | - // For normalized external modules |
|
| 628 | - else |
|
| 629 | - { |
|
| 630 | - $file=dol_buildpath('/'.$modulepart.'/core/modules/'.$modulepart.'/modules_'.$modulepart.'.php',0); |
|
| 631 | - $res=include_once $file; |
|
| 632 | - } |
|
| 633 | - $class='ModelePDF'.ucfirst($modulepart); |
|
| 634 | - if (class_exists($class)) |
|
| 635 | - { |
|
| 636 | - $modellist=call_user_func($class.'::liste_modeles',$this->db); |
|
| 637 | - } |
|
| 638 | - else |
|
| 639 | - { |
|
| 640 | - dol_print_error($this->db,'Bad value for modulepart'); |
|
| 641 | - return -1; |
|
| 642 | - } |
|
| 643 | - } |
|
| 644 | - |
|
| 645 | - // Set headershown to avoid to have table opened a second time later |
|
| 646 | - $headershown=1; |
|
| 647 | - |
|
| 648 | - $buttonlabeltoshow=$buttonlabel; |
|
| 649 | - if (empty($buttonlabel)) $buttonlabel=$langs->trans('Generate'); |
|
| 650 | - |
|
| 651 | - if ($conf->browser->layout == 'phone') $urlsource.='#'.$forname.'_form'; // So we switch to form after a generation |
|
| 652 | - if (empty($noform)) $out.= '<form action="'.$urlsource.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc').'" id="'.$forname.'_form" method="post">'; |
|
| 653 | - $out.= '<input type="hidden" name="action" value="builddoc">'; |
|
| 654 | - $out.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
| 655 | - |
|
| 656 | - $out.= load_fiche_titre($titletoshow, '', ''); |
|
| 657 | - $out.= '<div class="div-table-responsive-no-min">'; |
|
| 658 | - $out.= '<table class="liste formdoc noborder" summary="listofdocumentstable" width="100%">'; |
|
| 659 | - |
|
| 660 | - $out.= '<tr class="liste_titre">'; |
|
| 661 | - |
|
| 662 | - $addcolumforpicto=($delallowed || $printer || $morepicto); |
|
| 663 | - $out.= '<th align="center" colspan="'.(3+($addcolumforpicto?1:0)).'" class="formdoc liste_titre maxwidthonsmartphone">'; |
|
| 664 | - |
|
| 665 | - // Model |
|
| 666 | - if (! empty($modellist)) |
|
| 667 | - { |
|
| 668 | - $out.= '<span class="hideonsmartphone">'.$langs->trans('Model').' </span>'; |
|
| 669 | - if (is_array($modellist) && count($modellist) == 1) // If there is only one element |
|
| 670 | - { |
|
| 671 | - $arraykeys=array_keys($modellist); |
|
| 672 | - $modelselected=$arraykeys[0]; |
|
| 673 | - } |
|
| 674 | - $out.= $form->selectarray('model', $modellist, $modelselected, $showempty, 0, 0, '', 0, 0, 0, '', 'minwidth100'); |
|
| 675 | - if ($conf->use_javascript_ajax) |
|
| 676 | - { |
|
| 677 | - $out.= ajax_combobox('model'); |
|
| 678 | - } |
|
| 679 | - } |
|
| 680 | - else |
|
| 681 | - { |
|
| 682 | - $out.= '<div class="float">'.$langs->trans("Files").'</div>'; |
|
| 683 | - } |
|
| 684 | - |
|
| 685 | - // Language code (if multilang) |
|
| 686 | - if (($allowgenifempty || (is_array($modellist) && count($modellist) > 0)) && $conf->global->MAIN_MULTILANGS && ! $forcenomultilang && (! empty($modellist) || $showempty)) |
|
| 687 | - { |
|
| 688 | - include_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php'; |
|
| 689 | - $formadmin=new FormAdmin($this->db); |
|
| 690 | - $defaultlang=$codelang?$codelang:$langs->getDefaultLang(); |
|
| 691 | - $morecss='maxwidth150'; |
|
| 692 | - if ($conf->browser->layout == 'phone') $morecss='maxwidth100'; |
|
| 693 | - $out.= $formadmin->select_language($defaultlang, 'lang_id', 0, 0, 0, 0, 0, $morecss); |
|
| 694 | - } |
|
| 695 | - else |
|
| 696 | - { |
|
| 697 | - $out.= ' '; |
|
| 698 | - } |
|
| 699 | - |
|
| 700 | - // Button |
|
| 701 | - $genbutton = '<input class="button buttongen" id="'.$forname.'_generatebutton" name="'.$forname.'_generatebutton"'; |
|
| 702 | - $genbutton.= ' type="submit" value="'.$buttonlabel.'"'; |
|
| 703 | - if (! $allowgenifempty && ! is_array($modellist) && empty($modellist)) $genbutton.= ' disabled'; |
|
| 704 | - $genbutton.= '>'; |
|
| 705 | - if ($allowgenifempty && ! is_array($modellist) && empty($modellist) && empty($conf->dol_no_mouse_hover) && $modulepart != 'unpaid') |
|
| 706 | - { |
|
| 707 | - $langs->load("errors"); |
|
| 708 | - $genbutton.= ' '.img_warning($langs->transnoentitiesnoconv("WarningNoDocumentModelActivated")); |
|
| 709 | - } |
|
| 710 | - if (! $allowgenifempty && ! is_array($modellist) && empty($modellist) && empty($conf->dol_no_mouse_hover) && $modulepart != 'unpaid') $genbutton=''; |
|
| 711 | - if (empty($modellist) && ! $showempty && $modulepart != 'unpaid') $genbutton=''; |
|
| 712 | - $out.= $genbutton; |
|
| 713 | - $out.= '</th>'; |
|
| 714 | - |
|
| 715 | - if (!empty($hookmanager->hooks['formfile'])) |
|
| 716 | - { |
|
| 717 | - foreach($hookmanager->hooks['formfile'] as $module) |
|
| 718 | - { |
|
| 719 | - if (method_exists($module, 'formBuilddocLineOptions')) $out .= '<th></th>'; |
|
| 720 | - } |
|
| 721 | - } |
|
| 722 | - $out.= '</tr>'; |
|
| 723 | - |
|
| 724 | - // Execute hooks |
|
| 725 | - $parameters=array('socid'=>(isset($GLOBALS['socid'])?$GLOBALS['socid']:''),'id'=>(isset($GLOBALS['id'])?$GLOBALS['id']:''),'modulepart'=>$modulepart); |
|
| 726 | - if (is_object($hookmanager)) |
|
| 727 | - { |
|
| 728 | - $reshook = $hookmanager->executeHooks('formBuilddocOptions',$parameters,$GLOBALS['object']); |
|
| 729 | - $out.= $hookmanager->resPrint; |
|
| 730 | - } |
|
| 731 | - } |
|
| 732 | - |
|
| 733 | - // Get list of files |
|
| 734 | - if (! empty($filedir)) |
|
| 735 | - { |
|
| 736 | - $link_list = array(); |
|
| 737 | - if (is_object($object)) |
|
| 738 | - { |
|
| 739 | - require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php'; |
|
| 740 | - $link = new Link($this->db); |
|
| 741 | - $sortfield = $sortorder = null; |
|
| 742 | - $res = $link->fetchAll($link_list, $object->element, $object->id, $sortfield, $sortorder); |
|
| 743 | - } |
|
| 744 | - |
|
| 745 | - $out.= '<!-- html.formfile::showdocuments -->'."\n"; |
|
| 746 | - |
|
| 747 | - // Show title of array if not already shown |
|
| 748 | - if ((! empty($file_list) || ! empty($link_list) || preg_match('/^massfilesarea/', $modulepart)) |
|
| 749 | - && ! $headershown) |
|
| 750 | - { |
|
| 751 | - $headershown=1; |
|
| 752 | - $out.= '<div class="titre">'.$titletoshow.'</div>'."\n"; |
|
| 753 | - $out.= '<div class="div-table-responsive-no-min">'; |
|
| 754 | - $out.= '<table class="noborder" summary="listofdocumentstable" id="'.$modulepart.'_table" width="100%">'."\n"; |
|
| 755 | - } |
|
| 756 | - |
|
| 757 | - // Loop on each file found |
|
| 758 | - if (is_array($file_list)) |
|
| 759 | - { |
|
| 760 | - foreach($file_list as $file) |
|
| 761 | - { |
|
| 762 | - // Define relative path for download link (depends on module) |
|
| 763 | - $relativepath=$file["name"]; // Cas general |
|
| 764 | - if ($modulesubdir) $relativepath=$modulesubdir."/".$file["name"]; // Cas propal, facture... |
|
| 765 | - if ($modulepart == 'export') $relativepath = $file["name"]; // Other case |
|
| 766 | - |
|
| 767 | - $out.= '<tr class="oddeven">'; |
|
| 768 | - |
|
| 769 | - $documenturl = DOL_URL_ROOT.'/document.php'; |
|
| 770 | - if (isset($conf->global->DOL_URL_ROOT_DOCUMENT_PHP)) $documenturl=$conf->global->DOL_URL_ROOT_DOCUMENT_PHP; // To use another wrapper |
|
| 771 | - |
|
| 772 | - // Show file name with link to download |
|
| 773 | - $out.= '<td class="minwidth200">'; |
|
| 774 | - $out.= '<a class="documentdownload paddingright" href="'.$documenturl.'?modulepart='.$modulepart.'&file='.urlencode($relativepath).($param?'&'.$param:'').'"'; |
|
| 775 | - $mime=dol_mimetype($relativepath,'',0); |
|
| 776 | - if (preg_match('/text/',$mime)) $out.= ' target="_blank"'; |
|
| 777 | - $out.= ' target="_blank">'; |
|
| 778 | - $out.= img_mime($file["name"],$langs->trans("File").': '.$file["name"]); |
|
| 779 | - $out.= dol_trunc($file["name"], 150); |
|
| 780 | - $out.= '</a>'."\n"; |
|
| 781 | - $out.= $this->showPreview($file,$modulepart,$relativepath,0,$param); |
|
| 782 | - $out.= '</td>'; |
|
| 783 | - |
|
| 784 | - // Show file size |
|
| 785 | - $size=(! empty($file['size'])?$file['size']:dol_filesize($filedir."/".$file["name"])); |
|
| 786 | - $out.= '<td align="right" class="nowrap">'.dol_print_size($size,1,1).'</td>'; |
|
| 787 | - |
|
| 788 | - // Show file date |
|
| 789 | - $date=(! empty($file['date'])?$file['date']:dol_filemtime($filedir."/".$file["name"])); |
|
| 790 | - $out.= '<td align="right" class="nowrap">'.dol_print_date($date, 'dayhour', 'tzuser').'</td>'; |
|
| 791 | - |
|
| 792 | - if ($delallowed || $printer || $morepicto) |
|
| 793 | - { |
|
| 794 | - $out.= '<td class="right nowraponall">'; |
|
| 795 | - if ($delallowed) |
|
| 796 | - { |
|
| 797 | - $tmpurlsource = preg_replace('/#[a-zA-Z0-9_]*$/', '', $urlsource); |
|
| 798 | - $out.= '<a href="'.$tmpurlsource.(strpos($tmpurlsource,'?')?'&':'?').'action=remove_file&file='.urlencode($relativepath); |
|
| 799 | - $out.= ($param?'&'.$param:''); |
|
| 800 | - //$out.= '&modulepart='.$modulepart; // TODO obsolete ? |
|
| 801 | - //$out.= '&urlsource='.urlencode($urlsource); // TODO obsolete ? |
|
| 802 | - $out.= '">'.img_picto($langs->trans("Delete"), 'delete').'</a>'; |
|
| 803 | - } |
|
| 804 | - if ($printer) |
|
| 805 | - { |
|
| 806 | - //$out.= '<td align="right">'; |
|
| 807 | - $out.= '<a class="paddingleft" href="'.$urlsource.(strpos($urlsource,'?')?'&':'?').'action=print_file&printer='.$modulepart.'&file='.urlencode($relativepath); |
|
| 808 | - $out.= ($param?'&'.$param:''); |
|
| 809 | - $out.= '">'.img_picto($langs->trans("PrintFile", $relativepath),'printer.png').'</a>'; |
|
| 810 | - } |
|
| 811 | - if ($morepicto) |
|
| 812 | - { |
|
| 813 | - $morepicto=preg_replace('/__FILENAMEURLENCODED__/',urlencode($relativepath),$morepicto); |
|
| 814 | - $out.=$morepicto; |
|
| 815 | - } |
|
| 816 | - $out.='</td>'; |
|
| 817 | - } |
|
| 818 | - |
|
| 819 | - if (is_object($hookmanager)) |
|
| 820 | - { |
|
| 821 | - $parameters=array('socid'=>(isset($GLOBALS['socid'])?$GLOBALS['socid']:''),'id'=>(isset($GLOBALS['id'])?$GLOBALS['id']:''),'modulepart'=>$modulepart,'relativepath'=>$relativepath); |
|
| 822 | - $res = $hookmanager->executeHooks('formBuilddocLineOptions',$parameters,$file); |
|
| 823 | - if (empty($res)) |
|
| 824 | - { |
|
| 825 | - $out.= $hookmanager->resPrint; // Complete line |
|
| 826 | - $out.= '</tr>'; |
|
| 827 | - } |
|
| 828 | - else $out = $hookmanager->resPrint; // Replace line |
|
| 829 | - } |
|
| 830 | - } |
|
| 831 | - |
|
| 832 | - $this->numoffiles++; |
|
| 833 | - } |
|
| 834 | - // Loop on each link found |
|
| 835 | - if (is_array($link_list)) |
|
| 836 | - { |
|
| 837 | - $colspan=2; |
|
| 838 | - |
|
| 839 | - foreach($link_list as $file) |
|
| 840 | - { |
|
| 841 | - $out.='<tr class="oddeven">'; |
|
| 842 | - $out.='<td colspan="'.$colspan.'" class="maxwidhtonsmartphone">'; |
|
| 843 | - $out.='<a data-ajax="false" href="' . $link->url . '" target="_blank">'; |
|
| 844 | - $out.=$file->label; |
|
| 845 | - $out.='</a>'; |
|
| 846 | - $out.='</td>'; |
|
| 847 | - $out.='<td align="right">'; |
|
| 848 | - $out.=dol_print_date($file->datea,'dayhour'); |
|
| 849 | - $out.='</td>'; |
|
| 850 | - if ($delallowed || $printer || $morepicto) $out.='<td></td>'; |
|
| 851 | - $out.='</tr>'."\n"; |
|
| 852 | - } |
|
| 853 | - $this->numoffiles++; |
|
| 854 | - } |
|
| 855 | - |
|
| 856 | - if (count($file_list) == 0 && count($link_list) == 0 && $headershown) |
|
| 857 | - { |
|
| 858 | - $out.='<tr><td colspan="'.(3+($addcolumforpicto?1:0)).'" class="opacitymedium">'.$langs->trans("None").'</td></tr>'."\n"; |
|
| 859 | - } |
|
| 860 | - } |
|
| 861 | - |
|
| 862 | - if ($headershown) |
|
| 863 | - { |
|
| 864 | - // Affiche pied du tableau |
|
| 865 | - $out.= "</table>\n"; |
|
| 866 | - $out.= "</div>\n"; |
|
| 867 | - if ($genallowed) |
|
| 868 | - { |
|
| 869 | - if (empty($noform)) $out.= '</form>'."\n"; |
|
| 870 | - } |
|
| 871 | - } |
|
| 872 | - $out.= '<!-- End show_document -->'."\n"; |
|
| 873 | - //return ($i?$i:$headershown); |
|
| 874 | - return $out; |
|
| 875 | - } |
|
| 876 | - |
|
| 877 | - /** |
|
| 878 | - * Show a Document icon with link(s) |
|
| 879 | - * You may want to call this into a div like this: |
|
| 880 | - * print '<div class="inline-block valignmiddle">'.$formfile->getDocumentsLink($element_doc, $filename, $filedir).'</div>'; |
|
| 881 | - * |
|
| 882 | - * @param string $modulepart propal, facture, facture_fourn, ... |
|
| 883 | - * @param string $modulesubdir Sub-directory to scan (Example: '0/1/10', 'FA/DD/MM/YY/9999'). Use '' if file is not into subdir of module. |
|
| 884 | - * @param string $filedir Full path to directory to scan |
|
| 885 | - * @param string $filter Filter filenames on this regex string (Example: '\.pdf$') |
|
| 886 | - * @return string Output string with HTML link of documents (might be empty string). This also fill the array ->infofiles |
|
| 887 | - */ |
|
| 888 | - function getDocumentsLink($modulepart, $modulesubdir, $filedir, $filter='') |
|
| 889 | - { |
|
| 890 | - global $conf, $langs; |
|
| 891 | - |
|
| 892 | - include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
| 893 | - |
|
| 894 | - $out=''; |
|
| 895 | - $this->infofiles=array('nboffiles'=>0,'extensions'=>array(),'files'=>array()); |
|
| 896 | - |
|
| 897 | - $entity = 1; // Without multicompany |
|
| 898 | - |
|
| 899 | - // Get object entity |
|
| 900 | - if (! empty($conf->multicompany->enabled)) |
|
| 901 | - { |
|
| 902 | - preg_match('/\/([0-9]+)\/[^\/]+\/'.preg_quote($modulesubdir,'/').'$/', $filedir, $regs); |
|
| 903 | - $entity = ((! empty($regs[1]) && $regs[1] > 1) ? $regs[1] : 1); // If entity id not found in $filedir this is entity 1 by default |
|
| 904 | - } |
|
| 905 | - |
|
| 906 | - // Get list of files starting with name of ref (but not followed by "-" to discard uploaded files and get only generated files) |
|
| 907 | - // @TODO Why not showing by default all files by just removing the '[^\-]+' at end of regex ? |
|
| 908 | - if (! empty($conf->global->MAIN_SHOW_ALL_FILES_ON_DOCUMENT_TOOLTIP)) |
|
| 909 | - { |
|
| 910 | - $filterforfilesearch = preg_quote(basename($modulesubdir),'/'); |
|
| 911 | - } |
|
| 912 | - else |
|
| 913 | - { |
|
| 914 | - $filterforfilesearch = preg_quote(basename($modulesubdir),'/').'[^\-]+'; |
|
| 915 | - } |
|
| 916 | - $file_list=dol_dir_list($filedir, 'files', 0, $filterforfilesearch, '\.meta$|\.png$'); // We also discard .meta and .png preview |
|
| 917 | - |
|
| 918 | - //var_dump($file_list); |
|
| 919 | - // For ajax treatment |
|
| 920 | - $out.= '<!-- html.formfile::getDocumentsLink -->'."\n"; |
|
| 921 | - if (! empty($file_list)) |
|
| 922 | - { |
|
| 923 | - $out='<dl class="dropdown inline-block"> |
|
| 422 | + include_once DOL_DOCUMENT_ROOT.'/core/modules/reception/modules_reception.php'; |
|
| 423 | + $modellist = ModelePdfReception::liste_modeles($this->db); |
|
| 424 | + } |
|
| 425 | + } |
|
| 426 | + elseif ($modulepart == 'livraison') |
|
| 427 | + { |
|
| 428 | + if (is_array($genallowed)) $modellist=$genallowed; |
|
| 429 | + else |
|
| 430 | + { |
|
| 431 | + include_once DOL_DOCUMENT_ROOT.'/core/modules/livraison/modules_livraison.php'; |
|
| 432 | + $modellist=ModelePDFDeliveryOrder::liste_modeles($this->db); |
|
| 433 | + } |
|
| 434 | + } |
|
| 435 | + else if ($modulepart == 'ficheinter') |
|
| 436 | + { |
|
| 437 | + if (is_array($genallowed)) $modellist=$genallowed; |
|
| 438 | + else |
|
| 439 | + { |
|
| 440 | + include_once DOL_DOCUMENT_ROOT.'/core/modules/fichinter/modules_fichinter.php'; |
|
| 441 | + $modellist=ModelePDFFicheinter::liste_modeles($this->db); |
|
| 442 | + } |
|
| 443 | + } |
|
| 444 | + elseif ($modulepart == 'facture') |
|
| 445 | + { |
|
| 446 | + if (is_array($genallowed)) $modellist=$genallowed; |
|
| 447 | + else |
|
| 448 | + { |
|
| 449 | + include_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php'; |
|
| 450 | + $modellist=ModelePDFFactures::liste_modeles($this->db); |
|
| 451 | + } |
|
| 452 | + } |
|
| 453 | + elseif ($modulepart == 'contract') |
|
| 454 | + { |
|
| 455 | + if (is_array($genallowed)) $modellist=$genallowed; |
|
| 456 | + else |
|
| 457 | + { |
|
| 458 | + include_once DOL_DOCUMENT_ROOT.'/core/modules/contract/modules_contract.php'; |
|
| 459 | + $modellist=ModelePDFContract::liste_modeles($this->db); |
|
| 460 | + } |
|
| 461 | + } |
|
| 462 | + elseif ($modulepart == 'project') |
|
| 463 | + { |
|
| 464 | + if (is_array($genallowed)) $modellist=$genallowed; |
|
| 465 | + else |
|
| 466 | + { |
|
| 467 | + include_once DOL_DOCUMENT_ROOT.'/core/modules/project/modules_project.php'; |
|
| 468 | + $modellist=ModelePDFProjects::liste_modeles($this->db); |
|
| 469 | + } |
|
| 470 | + } |
|
| 471 | + elseif ($modulepart == 'project_task') |
|
| 472 | + { |
|
| 473 | + if (is_array($genallowed)) $modellist=$genallowed; |
|
| 474 | + else |
|
| 475 | + { |
|
| 476 | + include_once DOL_DOCUMENT_ROOT.'/core/modules/project/task/modules_task.php'; |
|
| 477 | + $modellist=ModelePDFTask::liste_modeles($this->db); |
|
| 478 | + } |
|
| 479 | + } |
|
| 480 | + elseif ($modulepart == 'product') |
|
| 481 | + { |
|
| 482 | + if (is_array($genallowed)) $modellist=$genallowed; |
|
| 483 | + else |
|
| 484 | + { |
|
| 485 | + include_once DOL_DOCUMENT_ROOT.'/core/modules/product/modules_product.class.php'; |
|
| 486 | + $modellist=ModelePDFProduct::liste_modeles($this->db); |
|
| 487 | + } |
|
| 488 | + } |
|
| 489 | + elseif ($modulepart == 'product_batch') |
|
| 490 | + { |
|
| 491 | + if (is_array($genallowed)) $modellist=$genallowed; |
|
| 492 | + else |
|
| 493 | + { |
|
| 494 | + include_once DOL_DOCUMENT_ROOT.'/core/modules/product_batch/modules_product_batch.class.php'; |
|
| 495 | + $modellist=ModelePDFProductBatch::liste_modeles($this->db); |
|
| 496 | + } |
|
| 497 | + } |
|
| 498 | + elseif ($modulepart == 'stock') |
|
| 499 | + { |
|
| 500 | + if (is_array($genallowed)) $modellist=$genallowed; |
|
| 501 | + else |
|
| 502 | + { |
|
| 503 | + include_once DOL_DOCUMENT_ROOT.'/core/modules/stock/modules_stock.php'; |
|
| 504 | + $modellist=ModelePDFStock::liste_modeles($this->db); |
|
| 505 | + } |
|
| 506 | + } |
|
| 507 | + elseif ($modulepart == 'movement') |
|
| 508 | + { |
|
| 509 | + if (is_array($genallowed)) $modellist=$genallowed; |
|
| 510 | + else |
|
| 511 | + { |
|
| 512 | + include_once DOL_DOCUMENT_ROOT.'/core/modules/stock/modules_movement.php'; |
|
| 513 | + $modellist=ModelePDFMovement::liste_modeles($this->db); |
|
| 514 | + } |
|
| 515 | + } |
|
| 516 | + elseif ($modulepart == 'export') |
|
| 517 | + { |
|
| 518 | + if (is_array($genallowed)) $modellist=$genallowed; |
|
| 519 | + else |
|
| 520 | + { |
|
| 521 | + include_once DOL_DOCUMENT_ROOT.'/core/modules/export/modules_export.php'; |
|
| 522 | + $modellist=ModeleExports::liste_modeles($this->db); |
|
| 523 | + } |
|
| 524 | + } |
|
| 525 | + else if ($modulepart == 'commande_fournisseur' || $modulepart == 'supplier_order') |
|
| 526 | + { |
|
| 527 | + if (is_array($genallowed)) $modellist=$genallowed; |
|
| 528 | + else |
|
| 529 | + { |
|
| 530 | + include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_order/modules_commandefournisseur.php'; |
|
| 531 | + $modellist=ModelePDFSuppliersOrders::liste_modeles($this->db); |
|
| 532 | + } |
|
| 533 | + } |
|
| 534 | + else if ($modulepart == 'facture_fournisseur' || $modulepart == 'supplier_invoice') |
|
| 535 | + { |
|
| 536 | + if (is_array($genallowed)) $modellist=$genallowed; |
|
| 537 | + else |
|
| 538 | + { |
|
| 539 | + include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_invoice/modules_facturefournisseur.php'; |
|
| 540 | + $modellist=ModelePDFSuppliersInvoices::liste_modeles($this->db); |
|
| 541 | + } |
|
| 542 | + } |
|
| 543 | + else if ($modulepart == 'supplier_payment') |
|
| 544 | + { |
|
| 545 | + if (is_array($genallowed)) $modellist=$genallowed; |
|
| 546 | + else |
|
| 547 | + { |
|
| 548 | + include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_payment/modules_supplier_payment.php'; |
|
| 549 | + $modellist=ModelePDFSuppliersPayments::liste_modeles($this->db); |
|
| 550 | + } |
|
| 551 | + } |
|
| 552 | + else if ($modulepart == 'remisecheque') |
|
| 553 | + { |
|
| 554 | + if (is_array($genallowed)) $modellist=$genallowed; |
|
| 555 | + else |
|
| 556 | + { |
|
| 557 | + include_once DOL_DOCUMENT_ROOT.'/core/modules/cheque/modules_chequereceipts.php'; |
|
| 558 | + $modellist=ModeleChequeReceipts::liste_modeles($this->db); |
|
| 559 | + } |
|
| 560 | + } |
|
| 561 | + elseif ($modulepart == 'donation') |
|
| 562 | + { |
|
| 563 | + if (is_array($genallowed)) $modellist=$genallowed; |
|
| 564 | + else |
|
| 565 | + { |
|
| 566 | + include_once DOL_DOCUMENT_ROOT.'/core/modules/dons/modules_don.php'; |
|
| 567 | + $modellist=ModeleDon::liste_modeles($this->db); |
|
| 568 | + } |
|
| 569 | + } |
|
| 570 | + elseif ($modulepart == 'member') |
|
| 571 | + { |
|
| 572 | + if (is_array($genallowed)) $modellist=$genallowed; |
|
| 573 | + else |
|
| 574 | + { |
|
| 575 | + include_once DOL_DOCUMENT_ROOT.'/core/modules/member/modules_cards.php'; |
|
| 576 | + $modellist=ModelePDFCards::liste_modeles($this->db); |
|
| 577 | + } |
|
| 578 | + } |
|
| 579 | + elseif ($modulepart == 'agenda' || $modulepart == 'actions') |
|
| 580 | + { |
|
| 581 | + if (is_array($genallowed)) $modellist=$genallowed; |
|
| 582 | + else |
|
| 583 | + { |
|
| 584 | + include_once DOL_DOCUMENT_ROOT.'/core/modules/action/modules_action.php'; |
|
| 585 | + $modellist=ModeleAction::liste_modeles($this->db); |
|
| 586 | + } |
|
| 587 | + } |
|
| 588 | + else if ($modulepart == 'expensereport') |
|
| 589 | + { |
|
| 590 | + if (is_array($genallowed)) $modellist=$genallowed; |
|
| 591 | + else |
|
| 592 | + { |
|
| 593 | + include_once DOL_DOCUMENT_ROOT.'/core/modules/expensereport/modules_expensereport.php'; |
|
| 594 | + $modellist=ModeleExpenseReport::liste_modeles($this->db); |
|
| 595 | + } |
|
| 596 | + } |
|
| 597 | + else if ($modulepart == 'unpaid') |
|
| 598 | + { |
|
| 599 | + $modellist=''; |
|
| 600 | + } |
|
| 601 | + elseif ($modulepart == 'user') |
|
| 602 | + { |
|
| 603 | + if (is_array($genallowed)) $modellist=$genallowed; |
|
| 604 | + else |
|
| 605 | + { |
|
| 606 | + include_once DOL_DOCUMENT_ROOT.'/core/modules/user/modules_user.class.php'; |
|
| 607 | + $modellist=ModelePDFUser::liste_modeles($this->db); |
|
| 608 | + } |
|
| 609 | + } |
|
| 610 | + elseif ($modulepart == 'usergroup') |
|
| 611 | + { |
|
| 612 | + if (is_array($genallowed)) $modellist=$genallowed; |
|
| 613 | + else |
|
| 614 | + { |
|
| 615 | + include_once DOL_DOCUMENT_ROOT.'/core/modules/usergroup/modules_usergroup.class.php'; |
|
| 616 | + $modellist=ModelePDFUserGroup::liste_modeles($this->db); |
|
| 617 | + } |
|
| 618 | + } |
|
| 619 | + else |
|
| 620 | + { |
|
| 621 | + // For normalized standard modules |
|
| 622 | + $file=dol_buildpath('/core/modules/'.$modulepart.'/modules_'.$modulepart.'.php',0); |
|
| 623 | + if (file_exists($file)) |
|
| 624 | + { |
|
| 625 | + $res=include_once $file; |
|
| 626 | + } |
|
| 627 | + // For normalized external modules |
|
| 628 | + else |
|
| 629 | + { |
|
| 630 | + $file=dol_buildpath('/'.$modulepart.'/core/modules/'.$modulepart.'/modules_'.$modulepart.'.php',0); |
|
| 631 | + $res=include_once $file; |
|
| 632 | + } |
|
| 633 | + $class='ModelePDF'.ucfirst($modulepart); |
|
| 634 | + if (class_exists($class)) |
|
| 635 | + { |
|
| 636 | + $modellist=call_user_func($class.'::liste_modeles',$this->db); |
|
| 637 | + } |
|
| 638 | + else |
|
| 639 | + { |
|
| 640 | + dol_print_error($this->db,'Bad value for modulepart'); |
|
| 641 | + return -1; |
|
| 642 | + } |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + // Set headershown to avoid to have table opened a second time later |
|
| 646 | + $headershown=1; |
|
| 647 | + |
|
| 648 | + $buttonlabeltoshow=$buttonlabel; |
|
| 649 | + if (empty($buttonlabel)) $buttonlabel=$langs->trans('Generate'); |
|
| 650 | + |
|
| 651 | + if ($conf->browser->layout == 'phone') $urlsource.='#'.$forname.'_form'; // So we switch to form after a generation |
|
| 652 | + if (empty($noform)) $out.= '<form action="'.$urlsource.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc').'" id="'.$forname.'_form" method="post">'; |
|
| 653 | + $out.= '<input type="hidden" name="action" value="builddoc">'; |
|
| 654 | + $out.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
| 655 | + |
|
| 656 | + $out.= load_fiche_titre($titletoshow, '', ''); |
|
| 657 | + $out.= '<div class="div-table-responsive-no-min">'; |
|
| 658 | + $out.= '<table class="liste formdoc noborder" summary="listofdocumentstable" width="100%">'; |
|
| 659 | + |
|
| 660 | + $out.= '<tr class="liste_titre">'; |
|
| 661 | + |
|
| 662 | + $addcolumforpicto=($delallowed || $printer || $morepicto); |
|
| 663 | + $out.= '<th align="center" colspan="'.(3+($addcolumforpicto?1:0)).'" class="formdoc liste_titre maxwidthonsmartphone">'; |
|
| 664 | + |
|
| 665 | + // Model |
|
| 666 | + if (! empty($modellist)) |
|
| 667 | + { |
|
| 668 | + $out.= '<span class="hideonsmartphone">'.$langs->trans('Model').' </span>'; |
|
| 669 | + if (is_array($modellist) && count($modellist) == 1) // If there is only one element |
|
| 670 | + { |
|
| 671 | + $arraykeys=array_keys($modellist); |
|
| 672 | + $modelselected=$arraykeys[0]; |
|
| 673 | + } |
|
| 674 | + $out.= $form->selectarray('model', $modellist, $modelselected, $showempty, 0, 0, '', 0, 0, 0, '', 'minwidth100'); |
|
| 675 | + if ($conf->use_javascript_ajax) |
|
| 676 | + { |
|
| 677 | + $out.= ajax_combobox('model'); |
|
| 678 | + } |
|
| 679 | + } |
|
| 680 | + else |
|
| 681 | + { |
|
| 682 | + $out.= '<div class="float">'.$langs->trans("Files").'</div>'; |
|
| 683 | + } |
|
| 684 | + |
|
| 685 | + // Language code (if multilang) |
|
| 686 | + if (($allowgenifempty || (is_array($modellist) && count($modellist) > 0)) && $conf->global->MAIN_MULTILANGS && ! $forcenomultilang && (! empty($modellist) || $showempty)) |
|
| 687 | + { |
|
| 688 | + include_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php'; |
|
| 689 | + $formadmin=new FormAdmin($this->db); |
|
| 690 | + $defaultlang=$codelang?$codelang:$langs->getDefaultLang(); |
|
| 691 | + $morecss='maxwidth150'; |
|
| 692 | + if ($conf->browser->layout == 'phone') $morecss='maxwidth100'; |
|
| 693 | + $out.= $formadmin->select_language($defaultlang, 'lang_id', 0, 0, 0, 0, 0, $morecss); |
|
| 694 | + } |
|
| 695 | + else |
|
| 696 | + { |
|
| 697 | + $out.= ' '; |
|
| 698 | + } |
|
| 699 | + |
|
| 700 | + // Button |
|
| 701 | + $genbutton = '<input class="button buttongen" id="'.$forname.'_generatebutton" name="'.$forname.'_generatebutton"'; |
|
| 702 | + $genbutton.= ' type="submit" value="'.$buttonlabel.'"'; |
|
| 703 | + if (! $allowgenifempty && ! is_array($modellist) && empty($modellist)) $genbutton.= ' disabled'; |
|
| 704 | + $genbutton.= '>'; |
|
| 705 | + if ($allowgenifempty && ! is_array($modellist) && empty($modellist) && empty($conf->dol_no_mouse_hover) && $modulepart != 'unpaid') |
|
| 706 | + { |
|
| 707 | + $langs->load("errors"); |
|
| 708 | + $genbutton.= ' '.img_warning($langs->transnoentitiesnoconv("WarningNoDocumentModelActivated")); |
|
| 709 | + } |
|
| 710 | + if (! $allowgenifempty && ! is_array($modellist) && empty($modellist) && empty($conf->dol_no_mouse_hover) && $modulepart != 'unpaid') $genbutton=''; |
|
| 711 | + if (empty($modellist) && ! $showempty && $modulepart != 'unpaid') $genbutton=''; |
|
| 712 | + $out.= $genbutton; |
|
| 713 | + $out.= '</th>'; |
|
| 714 | + |
|
| 715 | + if (!empty($hookmanager->hooks['formfile'])) |
|
| 716 | + { |
|
| 717 | + foreach($hookmanager->hooks['formfile'] as $module) |
|
| 718 | + { |
|
| 719 | + if (method_exists($module, 'formBuilddocLineOptions')) $out .= '<th></th>'; |
|
| 720 | + } |
|
| 721 | + } |
|
| 722 | + $out.= '</tr>'; |
|
| 723 | + |
|
| 724 | + // Execute hooks |
|
| 725 | + $parameters=array('socid'=>(isset($GLOBALS['socid'])?$GLOBALS['socid']:''),'id'=>(isset($GLOBALS['id'])?$GLOBALS['id']:''),'modulepart'=>$modulepart); |
|
| 726 | + if (is_object($hookmanager)) |
|
| 727 | + { |
|
| 728 | + $reshook = $hookmanager->executeHooks('formBuilddocOptions',$parameters,$GLOBALS['object']); |
|
| 729 | + $out.= $hookmanager->resPrint; |
|
| 730 | + } |
|
| 731 | + } |
|
| 732 | + |
|
| 733 | + // Get list of files |
|
| 734 | + if (! empty($filedir)) |
|
| 735 | + { |
|
| 736 | + $link_list = array(); |
|
| 737 | + if (is_object($object)) |
|
| 738 | + { |
|
| 739 | + require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php'; |
|
| 740 | + $link = new Link($this->db); |
|
| 741 | + $sortfield = $sortorder = null; |
|
| 742 | + $res = $link->fetchAll($link_list, $object->element, $object->id, $sortfield, $sortorder); |
|
| 743 | + } |
|
| 744 | + |
|
| 745 | + $out.= '<!-- html.formfile::showdocuments -->'."\n"; |
|
| 746 | + |
|
| 747 | + // Show title of array if not already shown |
|
| 748 | + if ((! empty($file_list) || ! empty($link_list) || preg_match('/^massfilesarea/', $modulepart)) |
|
| 749 | + && ! $headershown) |
|
| 750 | + { |
|
| 751 | + $headershown=1; |
|
| 752 | + $out.= '<div class="titre">'.$titletoshow.'</div>'."\n"; |
|
| 753 | + $out.= '<div class="div-table-responsive-no-min">'; |
|
| 754 | + $out.= '<table class="noborder" summary="listofdocumentstable" id="'.$modulepart.'_table" width="100%">'."\n"; |
|
| 755 | + } |
|
| 756 | + |
|
| 757 | + // Loop on each file found |
|
| 758 | + if (is_array($file_list)) |
|
| 759 | + { |
|
| 760 | + foreach($file_list as $file) |
|
| 761 | + { |
|
| 762 | + // Define relative path for download link (depends on module) |
|
| 763 | + $relativepath=$file["name"]; // Cas general |
|
| 764 | + if ($modulesubdir) $relativepath=$modulesubdir."/".$file["name"]; // Cas propal, facture... |
|
| 765 | + if ($modulepart == 'export') $relativepath = $file["name"]; // Other case |
|
| 766 | + |
|
| 767 | + $out.= '<tr class="oddeven">'; |
|
| 768 | + |
|
| 769 | + $documenturl = DOL_URL_ROOT.'/document.php'; |
|
| 770 | + if (isset($conf->global->DOL_URL_ROOT_DOCUMENT_PHP)) $documenturl=$conf->global->DOL_URL_ROOT_DOCUMENT_PHP; // To use another wrapper |
|
| 771 | + |
|
| 772 | + // Show file name with link to download |
|
| 773 | + $out.= '<td class="minwidth200">'; |
|
| 774 | + $out.= '<a class="documentdownload paddingright" href="'.$documenturl.'?modulepart='.$modulepart.'&file='.urlencode($relativepath).($param?'&'.$param:'').'"'; |
|
| 775 | + $mime=dol_mimetype($relativepath,'',0); |
|
| 776 | + if (preg_match('/text/',$mime)) $out.= ' target="_blank"'; |
|
| 777 | + $out.= ' target="_blank">'; |
|
| 778 | + $out.= img_mime($file["name"],$langs->trans("File").': '.$file["name"]); |
|
| 779 | + $out.= dol_trunc($file["name"], 150); |
|
| 780 | + $out.= '</a>'."\n"; |
|
| 781 | + $out.= $this->showPreview($file,$modulepart,$relativepath,0,$param); |
|
| 782 | + $out.= '</td>'; |
|
| 783 | + |
|
| 784 | + // Show file size |
|
| 785 | + $size=(! empty($file['size'])?$file['size']:dol_filesize($filedir."/".$file["name"])); |
|
| 786 | + $out.= '<td align="right" class="nowrap">'.dol_print_size($size,1,1).'</td>'; |
|
| 787 | + |
|
| 788 | + // Show file date |
|
| 789 | + $date=(! empty($file['date'])?$file['date']:dol_filemtime($filedir."/".$file["name"])); |
|
| 790 | + $out.= '<td align="right" class="nowrap">'.dol_print_date($date, 'dayhour', 'tzuser').'</td>'; |
|
| 791 | + |
|
| 792 | + if ($delallowed || $printer || $morepicto) |
|
| 793 | + { |
|
| 794 | + $out.= '<td class="right nowraponall">'; |
|
| 795 | + if ($delallowed) |
|
| 796 | + { |
|
| 797 | + $tmpurlsource = preg_replace('/#[a-zA-Z0-9_]*$/', '', $urlsource); |
|
| 798 | + $out.= '<a href="'.$tmpurlsource.(strpos($tmpurlsource,'?')?'&':'?').'action=remove_file&file='.urlencode($relativepath); |
|
| 799 | + $out.= ($param?'&'.$param:''); |
|
| 800 | + //$out.= '&modulepart='.$modulepart; // TODO obsolete ? |
|
| 801 | + //$out.= '&urlsource='.urlencode($urlsource); // TODO obsolete ? |
|
| 802 | + $out.= '">'.img_picto($langs->trans("Delete"), 'delete').'</a>'; |
|
| 803 | + } |
|
| 804 | + if ($printer) |
|
| 805 | + { |
|
| 806 | + //$out.= '<td align="right">'; |
|
| 807 | + $out.= '<a class="paddingleft" href="'.$urlsource.(strpos($urlsource,'?')?'&':'?').'action=print_file&printer='.$modulepart.'&file='.urlencode($relativepath); |
|
| 808 | + $out.= ($param?'&'.$param:''); |
|
| 809 | + $out.= '">'.img_picto($langs->trans("PrintFile", $relativepath),'printer.png').'</a>'; |
|
| 810 | + } |
|
| 811 | + if ($morepicto) |
|
| 812 | + { |
|
| 813 | + $morepicto=preg_replace('/__FILENAMEURLENCODED__/',urlencode($relativepath),$morepicto); |
|
| 814 | + $out.=$morepicto; |
|
| 815 | + } |
|
| 816 | + $out.='</td>'; |
|
| 817 | + } |
|
| 818 | + |
|
| 819 | + if (is_object($hookmanager)) |
|
| 820 | + { |
|
| 821 | + $parameters=array('socid'=>(isset($GLOBALS['socid'])?$GLOBALS['socid']:''),'id'=>(isset($GLOBALS['id'])?$GLOBALS['id']:''),'modulepart'=>$modulepart,'relativepath'=>$relativepath); |
|
| 822 | + $res = $hookmanager->executeHooks('formBuilddocLineOptions',$parameters,$file); |
|
| 823 | + if (empty($res)) |
|
| 824 | + { |
|
| 825 | + $out.= $hookmanager->resPrint; // Complete line |
|
| 826 | + $out.= '</tr>'; |
|
| 827 | + } |
|
| 828 | + else $out = $hookmanager->resPrint; // Replace line |
|
| 829 | + } |
|
| 830 | + } |
|
| 831 | + |
|
| 832 | + $this->numoffiles++; |
|
| 833 | + } |
|
| 834 | + // Loop on each link found |
|
| 835 | + if (is_array($link_list)) |
|
| 836 | + { |
|
| 837 | + $colspan=2; |
|
| 838 | + |
|
| 839 | + foreach($link_list as $file) |
|
| 840 | + { |
|
| 841 | + $out.='<tr class="oddeven">'; |
|
| 842 | + $out.='<td colspan="'.$colspan.'" class="maxwidhtonsmartphone">'; |
|
| 843 | + $out.='<a data-ajax="false" href="' . $link->url . '" target="_blank">'; |
|
| 844 | + $out.=$file->label; |
|
| 845 | + $out.='</a>'; |
|
| 846 | + $out.='</td>'; |
|
| 847 | + $out.='<td align="right">'; |
|
| 848 | + $out.=dol_print_date($file->datea,'dayhour'); |
|
| 849 | + $out.='</td>'; |
|
| 850 | + if ($delallowed || $printer || $morepicto) $out.='<td></td>'; |
|
| 851 | + $out.='</tr>'."\n"; |
|
| 852 | + } |
|
| 853 | + $this->numoffiles++; |
|
| 854 | + } |
|
| 855 | + |
|
| 856 | + if (count($file_list) == 0 && count($link_list) == 0 && $headershown) |
|
| 857 | + { |
|
| 858 | + $out.='<tr><td colspan="'.(3+($addcolumforpicto?1:0)).'" class="opacitymedium">'.$langs->trans("None").'</td></tr>'."\n"; |
|
| 859 | + } |
|
| 860 | + } |
|
| 861 | + |
|
| 862 | + if ($headershown) |
|
| 863 | + { |
|
| 864 | + // Affiche pied du tableau |
|
| 865 | + $out.= "</table>\n"; |
|
| 866 | + $out.= "</div>\n"; |
|
| 867 | + if ($genallowed) |
|
| 868 | + { |
|
| 869 | + if (empty($noform)) $out.= '</form>'."\n"; |
|
| 870 | + } |
|
| 871 | + } |
|
| 872 | + $out.= '<!-- End show_document -->'."\n"; |
|
| 873 | + //return ($i?$i:$headershown); |
|
| 874 | + return $out; |
|
| 875 | + } |
|
| 876 | + |
|
| 877 | + /** |
|
| 878 | + * Show a Document icon with link(s) |
|
| 879 | + * You may want to call this into a div like this: |
|
| 880 | + * print '<div class="inline-block valignmiddle">'.$formfile->getDocumentsLink($element_doc, $filename, $filedir).'</div>'; |
|
| 881 | + * |
|
| 882 | + * @param string $modulepart propal, facture, facture_fourn, ... |
|
| 883 | + * @param string $modulesubdir Sub-directory to scan (Example: '0/1/10', 'FA/DD/MM/YY/9999'). Use '' if file is not into subdir of module. |
|
| 884 | + * @param string $filedir Full path to directory to scan |
|
| 885 | + * @param string $filter Filter filenames on this regex string (Example: '\.pdf$') |
|
| 886 | + * @return string Output string with HTML link of documents (might be empty string). This also fill the array ->infofiles |
|
| 887 | + */ |
|
| 888 | + function getDocumentsLink($modulepart, $modulesubdir, $filedir, $filter='') |
|
| 889 | + { |
|
| 890 | + global $conf, $langs; |
|
| 891 | + |
|
| 892 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
| 893 | + |
|
| 894 | + $out=''; |
|
| 895 | + $this->infofiles=array('nboffiles'=>0,'extensions'=>array(),'files'=>array()); |
|
| 896 | + |
|
| 897 | + $entity = 1; // Without multicompany |
|
| 898 | + |
|
| 899 | + // Get object entity |
|
| 900 | + if (! empty($conf->multicompany->enabled)) |
|
| 901 | + { |
|
| 902 | + preg_match('/\/([0-9]+)\/[^\/]+\/'.preg_quote($modulesubdir,'/').'$/', $filedir, $regs); |
|
| 903 | + $entity = ((! empty($regs[1]) && $regs[1] > 1) ? $regs[1] : 1); // If entity id not found in $filedir this is entity 1 by default |
|
| 904 | + } |
|
| 905 | + |
|
| 906 | + // Get list of files starting with name of ref (but not followed by "-" to discard uploaded files and get only generated files) |
|
| 907 | + // @TODO Why not showing by default all files by just removing the '[^\-]+' at end of regex ? |
|
| 908 | + if (! empty($conf->global->MAIN_SHOW_ALL_FILES_ON_DOCUMENT_TOOLTIP)) |
|
| 909 | + { |
|
| 910 | + $filterforfilesearch = preg_quote(basename($modulesubdir),'/'); |
|
| 911 | + } |
|
| 912 | + else |
|
| 913 | + { |
|
| 914 | + $filterforfilesearch = preg_quote(basename($modulesubdir),'/').'[^\-]+'; |
|
| 915 | + } |
|
| 916 | + $file_list=dol_dir_list($filedir, 'files', 0, $filterforfilesearch, '\.meta$|\.png$'); // We also discard .meta and .png preview |
|
| 917 | + |
|
| 918 | + //var_dump($file_list); |
|
| 919 | + // For ajax treatment |
|
| 920 | + $out.= '<!-- html.formfile::getDocumentsLink -->'."\n"; |
|
| 921 | + if (! empty($file_list)) |
|
| 922 | + { |
|
| 923 | + $out='<dl class="dropdown inline-block"> |
|
| 924 | 924 | <dt><a data-ajax="false" href="#" onClick="return false;">'.img_picto('', 'listlight', '', 0, 0, 0, '', 'valignmiddle').'</a></dt> |
| 925 | 925 | <dd><div class="multichoicedoc" style="position:absolute;left:100px;" ><ul class="ulselectedfields" style="display: none;">'; |
| 926 | - $tmpout=''; |
|
| 927 | - |
|
| 928 | - // Loop on each file found |
|
| 929 | - $found=0; |
|
| 930 | - foreach($file_list as $file) |
|
| 931 | - { |
|
| 932 | - $i++; |
|
| 933 | - if ($filter && ! preg_match('/'.$filter.'/i', $file["name"])) continue; // Discard this. It does not match provided filter. |
|
| 934 | - |
|
| 935 | - $found++; |
|
| 936 | - // Define relative path for download link (depends on module) |
|
| 937 | - $relativepath=$file["name"]; // Cas general |
|
| 938 | - if ($modulesubdir) $relativepath=$modulesubdir."/".$file["name"]; // Cas propal, facture... |
|
| 939 | - // Autre cas |
|
| 940 | - if ($modulepart == 'donation') { |
|
| 941 | - $relativepath = get_exdir($modulesubdir,2,0,0,null,'donation').$file["name"]; |
|
| 942 | - } |
|
| 943 | - if ($modulepart == 'export') { |
|
| 944 | - $relativepath = $file["name"]; |
|
| 945 | - } |
|
| 946 | - |
|
| 947 | - $this->infofiles['nboffiles']++; |
|
| 948 | - $this->infofiles['files'][]=$file['fullname']; |
|
| 949 | - $ext=pathinfo($file["name"], PATHINFO_EXTENSION); |
|
| 950 | - if (empty($this->infofiles[$ext])) $this->infofiles['extensions'][$ext]=1; |
|
| 951 | - else $this->infofiles['extensions'][$ext]++; |
|
| 952 | - |
|
| 953 | - // Preview |
|
| 954 | - if (! empty($conf->use_javascript_ajax) && ($conf->browser->layout != 'phone')) |
|
| 955 | - { |
|
| 956 | - $tmparray = getAdvancedPreviewUrl($modulepart, $relativepath, 1, '&entity='.$entity); |
|
| 957 | - if ($tmparray && $tmparray['url']) |
|
| 958 | - { |
|
| 959 | - $tmpout.= '<li><a href="'.$tmparray['url'].'"'.($tmparray['css']?' class="'.$tmparray['css'].'"':'').($tmparray['mime']?' mime="'.$tmparray['mime'].'"':'').($tmparray['target']?' target="'.$tmparray['target'].'"':'').'>'; |
|
| 960 | - //$tmpout.= img_picto('','detail'); |
|
| 961 | - $tmpout.= '<i class="fa fa-search-plus paddingright" style="color: gray"></i>'; |
|
| 962 | - $tmpout.= $langs->trans("Preview").' '.$ext.'</a></li>'; |
|
| 963 | - } |
|
| 964 | - } |
|
| 965 | - |
|
| 966 | - // Download |
|
| 967 | - $tmpout.= '<li class="nowrap"><a class="pictopreview nowrap" href="'.DOL_URL_ROOT . '/document.php?modulepart='.$modulepart.'&entity='.$entity.'&file='.urlencode($relativepath).'"'; |
|
| 968 | - $mime=dol_mimetype($relativepath,'',0); |
|
| 969 | - if (preg_match('/text/',$mime)) $tmpout.= ' target="_blank"'; |
|
| 970 | - $tmpout.= '>'; |
|
| 971 | - $tmpout.= img_mime($relativepath, $file["name"]); |
|
| 972 | - $tmpout.= $langs->trans("Download").' '.$ext; |
|
| 973 | - $tmpout.= '</a></li>'."\n"; |
|
| 974 | - } |
|
| 975 | - $out.=$tmpout; |
|
| 976 | - $out.='</ul></div></dd> |
|
| 926 | + $tmpout=''; |
|
| 927 | + |
|
| 928 | + // Loop on each file found |
|
| 929 | + $found=0; |
|
| 930 | + foreach($file_list as $file) |
|
| 931 | + { |
|
| 932 | + $i++; |
|
| 933 | + if ($filter && ! preg_match('/'.$filter.'/i', $file["name"])) continue; // Discard this. It does not match provided filter. |
|
| 934 | + |
|
| 935 | + $found++; |
|
| 936 | + // Define relative path for download link (depends on module) |
|
| 937 | + $relativepath=$file["name"]; // Cas general |
|
| 938 | + if ($modulesubdir) $relativepath=$modulesubdir."/".$file["name"]; // Cas propal, facture... |
|
| 939 | + // Autre cas |
|
| 940 | + if ($modulepart == 'donation') { |
|
| 941 | + $relativepath = get_exdir($modulesubdir,2,0,0,null,'donation').$file["name"]; |
|
| 942 | + } |
|
| 943 | + if ($modulepart == 'export') { |
|
| 944 | + $relativepath = $file["name"]; |
|
| 945 | + } |
|
| 946 | + |
|
| 947 | + $this->infofiles['nboffiles']++; |
|
| 948 | + $this->infofiles['files'][]=$file['fullname']; |
|
| 949 | + $ext=pathinfo($file["name"], PATHINFO_EXTENSION); |
|
| 950 | + if (empty($this->infofiles[$ext])) $this->infofiles['extensions'][$ext]=1; |
|
| 951 | + else $this->infofiles['extensions'][$ext]++; |
|
| 952 | + |
|
| 953 | + // Preview |
|
| 954 | + if (! empty($conf->use_javascript_ajax) && ($conf->browser->layout != 'phone')) |
|
| 955 | + { |
|
| 956 | + $tmparray = getAdvancedPreviewUrl($modulepart, $relativepath, 1, '&entity='.$entity); |
|
| 957 | + if ($tmparray && $tmparray['url']) |
|
| 958 | + { |
|
| 959 | + $tmpout.= '<li><a href="'.$tmparray['url'].'"'.($tmparray['css']?' class="'.$tmparray['css'].'"':'').($tmparray['mime']?' mime="'.$tmparray['mime'].'"':'').($tmparray['target']?' target="'.$tmparray['target'].'"':'').'>'; |
|
| 960 | + //$tmpout.= img_picto('','detail'); |
|
| 961 | + $tmpout.= '<i class="fa fa-search-plus paddingright" style="color: gray"></i>'; |
|
| 962 | + $tmpout.= $langs->trans("Preview").' '.$ext.'</a></li>'; |
|
| 963 | + } |
|
| 964 | + } |
|
| 965 | + |
|
| 966 | + // Download |
|
| 967 | + $tmpout.= '<li class="nowrap"><a class="pictopreview nowrap" href="'.DOL_URL_ROOT . '/document.php?modulepart='.$modulepart.'&entity='.$entity.'&file='.urlencode($relativepath).'"'; |
|
| 968 | + $mime=dol_mimetype($relativepath,'',0); |
|
| 969 | + if (preg_match('/text/',$mime)) $tmpout.= ' target="_blank"'; |
|
| 970 | + $tmpout.= '>'; |
|
| 971 | + $tmpout.= img_mime($relativepath, $file["name"]); |
|
| 972 | + $tmpout.= $langs->trans("Download").' '.$ext; |
|
| 973 | + $tmpout.= '</a></li>'."\n"; |
|
| 974 | + } |
|
| 975 | + $out.=$tmpout; |
|
| 976 | + $out.='</ul></div></dd> |
|
| 977 | 977 | </dl>'; |
| 978 | 978 | |
| 979 | - if (! $found) $out=''; |
|
| 980 | - } |
|
| 981 | - else |
|
| 982 | - { |
|
| 983 | - // TODO Add link to regenerate doc ? |
|
| 984 | - //$out.= '<div id="gen_pdf_'.$modulesubdir.'" class="linkobject hideobject">'.img_picto('', 'refresh').'</div>'."\n"; |
|
| 985 | - } |
|
| 979 | + if (! $found) $out=''; |
|
| 980 | + } |
|
| 981 | + else |
|
| 982 | + { |
|
| 983 | + // TODO Add link to regenerate doc ? |
|
| 984 | + //$out.= '<div id="gen_pdf_'.$modulesubdir.'" class="linkobject hideobject">'.img_picto('', 'refresh').'</div>'."\n"; |
|
| 985 | + } |
|
| 986 | 986 | |
| 987 | - return $out; |
|
| 988 | - } |
|
| 987 | + return $out; |
|
| 988 | + } |
|
| 989 | 989 | |
| 990 | 990 | |
| 991 | 991 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
| 992 | - /** |
|
| 993 | - * Show list of documents in $filearray (may be they are all in same directory but may not) |
|
| 994 | - * This also sync database if $upload_dir is defined. |
|
| 995 | - * |
|
| 996 | - * @param array $filearray Array of files loaded by dol_dir_list('files') function before calling this. |
|
| 997 | - * @param Object $object Object on which document is linked to. |
|
| 998 | - * @param string $modulepart Value for modulepart used by download or viewimage wrapper. |
|
| 999 | - * @param string $param Parameters on sort links (param must start with &, example &aaa=bbb&ccc=ddd) |
|
| 1000 | - * @param int $forcedownload Force to open dialog box "Save As" when clicking on file. |
|
| 1001 | - * @param string $relativepath Relative path of docs (autodefined if not provided), relative to module dir, not to MAIN_DATA_ROOT. |
|
| 1002 | - * @param int $permonobject Permission on object (so permission to delete or crop document) |
|
| 1003 | - * @param int $useinecm Change output for use in ecm module: |
|
| 1004 | - * 0: Add a previw link. Show also rename and crop file |
|
| 1005 | - * 1: Add link to edit ECM entry |
|
| 1006 | - * 2: Add rename and crop file |
|
| 1007 | - * @param string $textifempty Text to show if filearray is empty ('NoFileFound' if not defined) |
|
| 1008 | - * @param int $maxlength Maximum length of file name shown. |
|
| 1009 | - * @param string $title Title before list. Use 'none' to disable title. |
|
| 1010 | - * @param string $url Full url to use for click links ('' = autodetect) |
|
| 1011 | - * @param int $showrelpart 0=Show only filename (default), 1=Show first level 1 dir |
|
| 1012 | - * @param int $permtoeditline Permission to edit document line (You must provide a value, -1 is deprecated and must not be used any more) |
|
| 1013 | - * @param string $upload_dir Full path directory so we can know dir relative to MAIN_DATA_ROOT. Fill this to complete file data with database indexes. |
|
| 1014 | - * @param string $sortfield Sort field ('name', 'size', 'position', ...) |
|
| 1015 | - * @param string $sortorder Sort order ('ASC' or 'DESC') |
|
| 1016 | - * @param int $disablemove 1=Disable move button, 0=Position move is possible. |
|
| 1017 | - * @param int $addfilterfields Add line with filters |
|
| 1018 | - * @return int <0 if KO, nb of files shown if OK |
|
| 1019 | - * @see list_of_autoecmfiles |
|
| 1020 | - */ |
|
| 1021 | - function list_of_documents($filearray,$object,$modulepart,$param='',$forcedownload=0,$relativepath='',$permonobject=1,$useinecm=0,$textifempty='',$maxlength=0,$title='',$url='', $showrelpart=0, $permtoeditline=-1,$upload_dir='',$sortfield='',$sortorder='ASC', $disablemove=1, $addfilterfields=0) |
|
| 1022 | - { |
|
| 992 | + /** |
|
| 993 | + * Show list of documents in $filearray (may be they are all in same directory but may not) |
|
| 994 | + * This also sync database if $upload_dir is defined. |
|
| 995 | + * |
|
| 996 | + * @param array $filearray Array of files loaded by dol_dir_list('files') function before calling this. |
|
| 997 | + * @param Object $object Object on which document is linked to. |
|
| 998 | + * @param string $modulepart Value for modulepart used by download or viewimage wrapper. |
|
| 999 | + * @param string $param Parameters on sort links (param must start with &, example &aaa=bbb&ccc=ddd) |
|
| 1000 | + * @param int $forcedownload Force to open dialog box "Save As" when clicking on file. |
|
| 1001 | + * @param string $relativepath Relative path of docs (autodefined if not provided), relative to module dir, not to MAIN_DATA_ROOT. |
|
| 1002 | + * @param int $permonobject Permission on object (so permission to delete or crop document) |
|
| 1003 | + * @param int $useinecm Change output for use in ecm module: |
|
| 1004 | + * 0: Add a previw link. Show also rename and crop file |
|
| 1005 | + * 1: Add link to edit ECM entry |
|
| 1006 | + * 2: Add rename and crop file |
|
| 1007 | + * @param string $textifempty Text to show if filearray is empty ('NoFileFound' if not defined) |
|
| 1008 | + * @param int $maxlength Maximum length of file name shown. |
|
| 1009 | + * @param string $title Title before list. Use 'none' to disable title. |
|
| 1010 | + * @param string $url Full url to use for click links ('' = autodetect) |
|
| 1011 | + * @param int $showrelpart 0=Show only filename (default), 1=Show first level 1 dir |
|
| 1012 | + * @param int $permtoeditline Permission to edit document line (You must provide a value, -1 is deprecated and must not be used any more) |
|
| 1013 | + * @param string $upload_dir Full path directory so we can know dir relative to MAIN_DATA_ROOT. Fill this to complete file data with database indexes. |
|
| 1014 | + * @param string $sortfield Sort field ('name', 'size', 'position', ...) |
|
| 1015 | + * @param string $sortorder Sort order ('ASC' or 'DESC') |
|
| 1016 | + * @param int $disablemove 1=Disable move button, 0=Position move is possible. |
|
| 1017 | + * @param int $addfilterfields Add line with filters |
|
| 1018 | + * @return int <0 if KO, nb of files shown if OK |
|
| 1019 | + * @see list_of_autoecmfiles |
|
| 1020 | + */ |
|
| 1021 | + function list_of_documents($filearray,$object,$modulepart,$param='',$forcedownload=0,$relativepath='',$permonobject=1,$useinecm=0,$textifempty='',$maxlength=0,$title='',$url='', $showrelpart=0, $permtoeditline=-1,$upload_dir='',$sortfield='',$sortorder='ASC', $disablemove=1, $addfilterfields=0) |
|
| 1022 | + { |
|
| 1023 | 1023 | // phpcs:enable |
| 1024 | - global $user, $conf, $langs, $hookmanager; |
|
| 1025 | - global $sortfield, $sortorder, $maxheightmini; |
|
| 1026 | - global $dolibarr_main_url_root; |
|
| 1027 | - global $form; |
|
| 1028 | - |
|
| 1029 | - $disablecrop=1; |
|
| 1030 | - if (in_array($modulepart, array('expensereport','holiday','member','project','product','produit','service','societe','tax','ticket','user'))) $disablecrop=0; |
|
| 1031 | - |
|
| 1032 | - // Define relative path used to store the file |
|
| 1033 | - if (empty($relativepath)) |
|
| 1034 | - { |
|
| 1035 | - $relativepath=(! empty($object->ref)?dol_sanitizeFileName($object->ref):'').'/'; |
|
| 1036 | - if ($object->element == 'invoice_supplier') $relativepath=get_exdir($object->id,2,0,0,$object,'invoice_supplier').$relativepath; // TODO Call using a defined value for $relativepath |
|
| 1037 | - if ($object->element == 'project_task') $relativepath='Call_not_supported_._Call_function_using_a_defined_relative_path_.'; |
|
| 1038 | - } |
|
| 1039 | - // For backward compatiblity, we detect file stored into an old path |
|
| 1040 | - if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO) && $filearray[0]['level1name'] == 'photos') |
|
| 1041 | - { |
|
| 1042 | - $relativepath=preg_replace('/^.*\/produit\//','',$filearray[0]['path']).'/'; |
|
| 1043 | - } |
|
| 1044 | - // Defined relative dir to DOL_DATA_ROOT |
|
| 1045 | - $relativedir = ''; |
|
| 1046 | - if ($upload_dir) |
|
| 1047 | - { |
|
| 1048 | - $relativedir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $upload_dir); |
|
| 1049 | - $relativedir = preg_replace('/^[\\/]/','',$relativedir); |
|
| 1050 | - } |
|
| 1051 | - |
|
| 1052 | - $hookmanager->initHooks(array('formfile')); |
|
| 1053 | - $parameters=array( |
|
| 1054 | - 'filearray' => $filearray, |
|
| 1055 | - 'modulepart'=> $modulepart, |
|
| 1056 | - 'param' => $param, |
|
| 1057 | - 'forcedownload' => $forcedownload, |
|
| 1058 | - 'relativepath' => $relativepath, // relative filename to module dir |
|
| 1059 | - 'relativedir' => $relativedir, // relative dirname to DOL_DATA_ROOT |
|
| 1060 | - 'permtodelete' => $permonobject, |
|
| 1061 | - 'useinecm' => $useinecm, |
|
| 1062 | - 'textifempty' => $textifempty, |
|
| 1063 | - 'maxlength' => $maxlength, |
|
| 1064 | - 'title' => $title, |
|
| 1065 | - 'url' => $url |
|
| 1066 | - ); |
|
| 1067 | - $reshook=$hookmanager->executeHooks('showFilesList', $parameters, $object); |
|
| 1068 | - |
|
| 1069 | - if (isset($reshook) && $reshook != '') // null or '' for bypass |
|
| 1070 | - { |
|
| 1071 | - return $reshook; |
|
| 1072 | - } |
|
| 1073 | - else |
|
| 1074 | - { |
|
| 1075 | - if (! is_object($form)) |
|
| 1076 | - { |
|
| 1077 | - include_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; // The compoent may be included into ajax page that does not include the Form class |
|
| 1078 | - $form=new Form($this->db); |
|
| 1079 | - } |
|
| 1080 | - |
|
| 1081 | - if (! preg_match('/&id=/', $param) && isset($object->id)) $param.='&id='.$object->id; |
|
| 1082 | - $relativepathwihtoutslashend=preg_replace('/\/$/', '', $relativepath); |
|
| 1083 | - if ($relativepathwihtoutslashend) $param.= '&file='.urlencode($relativepathwihtoutslashend); |
|
| 1084 | - |
|
| 1085 | - if ($permtoeditline < 0) // Old behaviour for backward compatibility. New feature should call method with value 0 or 1 |
|
| 1086 | - { |
|
| 1087 | - $permtoeditline=0; |
|
| 1088 | - if (in_array($modulepart, array('product','produit','service'))) |
|
| 1089 | - { |
|
| 1090 | - if ($user->rights->produit->creer && $object->type == Product::TYPE_PRODUCT) $permtoeditline=1; |
|
| 1091 | - if ($user->rights->service->creer && $object->type == Product::TYPE_SERVICE) $permtoeditline=1; |
|
| 1092 | - } |
|
| 1093 | - } |
|
| 1094 | - if (empty($conf->global->MAIN_UPLOAD_DOC)) |
|
| 1095 | - { |
|
| 1096 | - $permtoeditline=0; |
|
| 1097 | - $permonobject=0; |
|
| 1098 | - } |
|
| 1099 | - |
|
| 1100 | - // Show list of existing files |
|
| 1101 | - if (empty($useinecm) && $title != 'none') print load_fiche_titre($title?$title:$langs->trans("AttachedFiles")); |
|
| 1102 | - if (empty($url)) $url=$_SERVER["PHP_SELF"]; |
|
| 1103 | - |
|
| 1104 | - print '<!-- html.formfile::list_of_documents -->'."\n"; |
|
| 1105 | - if (GETPOST('action','aZ09') == 'editfile' && $permtoeditline) |
|
| 1106 | - { |
|
| 1107 | - print '<form action="'.$_SERVER["PHP_SELF"].'?'.$param.'" method="POST">'; |
|
| 1108 | - print '<input type="hidden" name="action" value="renamefile">'; |
|
| 1109 | - print '<input type="hidden" name="id" value="'.$object->id.'">'; |
|
| 1110 | - print '<input type="hidden" name="modulepart" value="'.$modulepart.'">'; |
|
| 1111 | - } |
|
| 1112 | - |
|
| 1113 | - print '<div class="div-table-responsive-no-min">'; |
|
| 1114 | - print '<table width="100%" id="tablelines" class="'.($useinecm?'liste noborder':'liste').'">'."\n"; |
|
| 1115 | - |
|
| 1116 | - if (! empty($addfilterfields)) |
|
| 1117 | - { |
|
| 1118 | - print '<tr class="liste_titre nodrag nodrop">'; |
|
| 1119 | - print '<td><input type="search_doc_ref" value="'.dol_escape_htmltag(GETPOST('search_doc_ref','alpha')).'"></td>'; |
|
| 1120 | - print '<td></td>'; |
|
| 1121 | - print '<td></td>'; |
|
| 1122 | - if (empty($useinecm)) print '<td></td>'; |
|
| 1123 | - print '<td></td>'; |
|
| 1124 | - print '<td></td>'; |
|
| 1125 | - if (! $disablemove) print '<td></td>'; |
|
| 1126 | - print "</tr>\n"; |
|
| 1127 | - } |
|
| 1128 | - |
|
| 1129 | - print '<tr class="liste_titre nodrag nodrop">'; |
|
| 1130 | - //print $url.' sortfield='.$sortfield.' sortorder='.$sortorder; |
|
| 1131 | - print_liste_field_titre('Documents2',$url,"name","",$param,'align="left"',$sortfield,$sortorder); |
|
| 1132 | - print_liste_field_titre('Size',$url,"size","",$param,'align="right"',$sortfield,$sortorder); |
|
| 1133 | - print_liste_field_titre('Date',$url,"date","",$param,'align="center"',$sortfield,$sortorder); |
|
| 1134 | - if (empty($useinecm)) print_liste_field_titre('',$url,"","",$param,'align="center"'); // Preview |
|
| 1135 | - print_liste_field_titre(''); |
|
| 1136 | - print_liste_field_titre(''); |
|
| 1137 | - if (! $disablemove) print_liste_field_titre(''); |
|
| 1138 | - print "</tr>\n"; |
|
| 1139 | - |
|
| 1140 | - // Get list of files stored into database for same relative directory |
|
| 1141 | - if ($relativedir) |
|
| 1142 | - { |
|
| 1143 | - completeFileArrayWithDatabaseInfo($filearray, $relativedir); |
|
| 1144 | - |
|
| 1145 | - //var_dump($sortfield.' - '.$sortorder); |
|
| 1146 | - if ($sortfield && $sortorder) // If $sortfield is for example 'position_name', we will sort on the property 'position_name' (that is concat of position+name) |
|
| 1147 | - { |
|
| 1148 | - $filearray=dol_sort_array($filearray, $sortfield, $sortorder); |
|
| 1149 | - } |
|
| 1150 | - } |
|
| 1151 | - |
|
| 1152 | - $nboffiles=count($filearray); |
|
| 1153 | - if ($nboffiles > 0) include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; |
|
| 1154 | - |
|
| 1155 | - $i=0; $nboflines = 0; $lastrowid=0; |
|
| 1156 | - foreach($filearray as $key => $file) // filearray must be only files here |
|
| 1157 | - { |
|
| 1158 | - if ($file['name'] != '.' |
|
| 1159 | - && $file['name'] != '..' |
|
| 1160 | - && ! preg_match('/\.meta$/i',$file['name'])) |
|
| 1161 | - { |
|
| 1162 | - if ($filearray[$key]['rowid'] > 0) $lastrowid = $filearray[$key]['rowid']; |
|
| 1163 | - $filepath=$relativepath.$file['name']; |
|
| 1164 | - |
|
| 1165 | - $editline=0; |
|
| 1166 | - $nboflines++; |
|
| 1167 | - print '<!-- Line list_of_documents '.$key.' relativepath = '.$relativepath.' -->'."\n"; |
|
| 1168 | - // Do we have entry into database ? |
|
| 1169 | - print '<!-- In database: position='.$filearray[$key]['position'].' -->'."\n"; |
|
| 1170 | - print '<tr class="oddeven" id="row-'.($filearray[$key]['rowid']>0?$filearray[$key]['rowid']:'AFTER'.$lastrowid.'POS'.($i+1)).'">'; |
|
| 1171 | - |
|
| 1172 | - // File name |
|
| 1173 | - print '<td class="minwith200">'; |
|
| 1174 | - |
|
| 1175 | - // Show file name with link to download |
|
| 1176 | - //print "XX".$file['name']; //$file['name'] must be utf8 |
|
| 1177 | - print '<a class="paddingright" href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart; |
|
| 1178 | - if ($forcedownload) print '&attachment=1'; |
|
| 1179 | - if (! empty($object->entity)) print '&entity='.$object->entity; |
|
| 1180 | - print '&file='.urlencode($filepath); |
|
| 1181 | - print '">'; |
|
| 1182 | - print img_mime($file['name'], $file['name'].' ('.dol_print_size($file['size'],0,0).')', 'inline-block valignbottom paddingright'); |
|
| 1183 | - if ($showrelpart == 1) print $relativepath; |
|
| 1184 | - //print dol_trunc($file['name'],$maxlength,'middle'); |
|
| 1185 | - if (GETPOST('action','aZ09') == 'editfile' && $file['name'] == basename(GETPOST('urlfile','alpha'))) |
|
| 1186 | - { |
|
| 1187 | - print '</a>'; |
|
| 1188 | - $section_dir=dirname(GETPOST('urlfile','alpha')); |
|
| 1189 | - print '<input type="hidden" name="section_dir" value="'.$section_dir.'">'; |
|
| 1190 | - print '<input type="hidden" name="renamefilefrom" value="'.dol_escape_htmltag($file['name']).'">'; |
|
| 1191 | - print '<input type="text" name="renamefileto" class="quatrevingtpercent" value="'.dol_escape_htmltag($file['name']).'">'; |
|
| 1192 | - $editline=1; |
|
| 1193 | - } |
|
| 1194 | - else |
|
| 1195 | - { |
|
| 1196 | - print dol_trunc($file['name'], 200); |
|
| 1197 | - print '</a>'; |
|
| 1198 | - } |
|
| 1199 | - // Preview link |
|
| 1200 | - if (! $editline) print $this->showPreview($file, $modulepart, $filepath); |
|
| 1201 | - // Public share link |
|
| 1202 | - //if (! $editline && ! empty($filearray[$key]['hashp'])) print pictowithlinktodirectdownload; |
|
| 1203 | - |
|
| 1204 | - print "</td>\n"; |
|
| 1205 | - |
|
| 1206 | - // Size |
|
| 1207 | - $sizetoshow = dol_print_size($file['size'],1,1); |
|
| 1208 | - $sizetoshowbytes = dol_print_size($file['size'],0,1); |
|
| 1209 | - |
|
| 1210 | - print '<td align="right" width="80px">'; |
|
| 1211 | - if ($sizetoshow == $sizetoshowbytes) print $sizetoshow; |
|
| 1212 | - else { |
|
| 1213 | - print $form->textwithpicto($sizetoshow, $sizetoshowbytes, -1); |
|
| 1214 | - } |
|
| 1215 | - print '</td>'; |
|
| 1216 | - |
|
| 1217 | - // Date |
|
| 1218 | - print '<td align="center" width="140px">'.dol_print_date($file['date'],"dayhour","tzuser").'</td>'; // 140px = width for date with PM format |
|
| 1219 | - |
|
| 1220 | - // Preview |
|
| 1221 | - if (empty($useinecm)) |
|
| 1222 | - { |
|
| 1223 | - $fileinfo = pathinfo($file['name']); |
|
| 1224 | - print '<td align="center">'; |
|
| 1225 | - if (image_format_supported($file['name']) > 0) |
|
| 1226 | - { |
|
| 1227 | - $minifile=getImageFileNameForSize($file['name'], '_mini'); // For new thumbs using same ext (in lower case howerver) than original |
|
| 1228 | - if (! dol_is_file($file['path'].'/'.$minifile)) $minifile=getImageFileNameForSize($file['name'], '_mini', '.png'); // For backward compatibility of old thumbs that were created with filename in lower case and with .png extension |
|
| 1229 | - //print $file['path'].'/'.$minifile.'<br>'; |
|
| 1230 | - |
|
| 1231 | - $urlforhref=getAdvancedPreviewUrl($modulepart, $relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension']), 1, '&entity='.(!empty($object->entity)?$object->entity:$conf->entity)); |
|
| 1232 | - if (empty($urlforhref)) { |
|
| 1233 | - $urlforhref=DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.(!empty($object->entity)?$object->entity:$conf->entity).'&file='.urlencode($relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension'])); |
|
| 1234 | - print '<a href="'.$urlforhref.'" class="aphoto" target="_blank">'; |
|
| 1235 | - } else { |
|
| 1236 | - print '<a href="'.$urlforhref['url'].'" class="'.$urlforhref['css'].'" target="'.$urlforhref['target'].'" mime="'.$urlforhref['mime'].'">'; |
|
| 1237 | - } |
|
| 1238 | - print '<img border="0" height="'.$maxheightmini.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.(!empty($object->entity)?$object->entity:$conf->entity).'&file='.urlencode($relativepath.$minifile).'" title="">'; |
|
| 1239 | - print '</a>'; |
|
| 1240 | - } |
|
| 1241 | - else print ' '; |
|
| 1242 | - print '</td>'; |
|
| 1243 | - } |
|
| 1244 | - |
|
| 1245 | - // Hash of file (only if we are in a mode where a scan of dir were done and we have id of file in ECM table) |
|
| 1246 | - print '<td align="center">'; |
|
| 1247 | - if ($relativedir && $filearray[$key]['rowid'] > 0) |
|
| 1248 | - { |
|
| 1249 | - if ($editline) |
|
| 1250 | - { |
|
| 1251 | - print $langs->trans("FileSharedViaALink").' '; |
|
| 1252 | - print '<input class="inline-block" type="checkbox" name="shareenabled"'.($file['share']?' checked="checked"':'').' /> '; |
|
| 1253 | - } |
|
| 1254 | - else |
|
| 1255 | - { |
|
| 1256 | - if ($file['share']) |
|
| 1257 | - { |
|
| 1258 | - // Define $urlwithroot |
|
| 1259 | - $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); |
|
| 1260 | - $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
| 1261 | - //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current |
|
| 1262 | - |
|
| 1263 | - //print '<span class="opacitymedium">'.$langs->trans("Hash").' : '.$file['share'].'</span>'; |
|
| 1264 | - $forcedownload=0; |
|
| 1265 | - $paramlink=''; |
|
| 1266 | - if (! empty($file['share'])) $paramlink.=($paramlink?'&':'').'hashp='.$file['share']; // Hash for public share |
|
| 1267 | - if ($forcedownload) $paramlink.=($paramlink?'&':'').'attachment=1'; |
|
| 1268 | - |
|
| 1269 | - $fulllink=$urlwithroot.'/document.php'.($paramlink?'?'.$paramlink:''); |
|
| 1270 | - |
|
| 1271 | - print img_picto($langs->trans("FileSharedViaALink"),'object_globe.png').' '; |
|
| 1272 | - print '<input type="text" class="quatrevingtpercent" id="downloadlink" name="downloadexternallink" value="'.dol_escape_htmltag($fulllink).'">'; |
|
| 1273 | - } |
|
| 1274 | - else |
|
| 1275 | - { |
|
| 1276 | - //print '<span class="opacitymedium">'.$langs->trans("FileNotShared").'</span>'; |
|
| 1277 | - } |
|
| 1278 | - } |
|
| 1279 | - } |
|
| 1280 | - print '</td>'; |
|
| 1281 | - |
|
| 1282 | - // Actions buttons |
|
| 1283 | - if (! $editline) |
|
| 1284 | - { |
|
| 1285 | - // Delete or view link |
|
| 1286 | - // ($param must start with &) |
|
| 1287 | - print '<td class="valignmiddle right actionbuttons"><!-- action on files -->'; |
|
| 1288 | - if ($useinecm == 1) |
|
| 1289 | - { |
|
| 1290 | - print '<a href="'.DOL_URL_ROOT.'/ecm/file_card.php?urlfile='.urlencode($file['name']).$param.'" class="editfilelink" rel="'.urlencode($file['name']).'">'.img_edit('default', 0, 'class="paddingrightonly"').'</a>'; |
|
| 1291 | - } |
|
| 1292 | - if (! $useinecm || $useinecm == 2) |
|
| 1293 | - { |
|
| 1294 | - $newmodulepart=$modulepart; |
|
| 1295 | - if (in_array($modulepart, array('product','produit','service'))) $newmodulepart='produit|service'; |
|
| 1296 | - |
|
| 1297 | - if (! $disablecrop && image_format_supported($file['name']) > 0) |
|
| 1298 | - { |
|
| 1299 | - if ($permtoeditline) |
|
| 1300 | - { |
|
| 1301 | - // Link to resize |
|
| 1302 | - print '<a href="'.DOL_URL_ROOT.'/core/photos_resize.php?modulepart='.urlencode($newmodulepart).'&id='.$object->id.'&file='.urlencode($relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension'])).'" title="'.dol_escape_htmltag($langs->trans("ResizeOrCrop")).'">'.img_picto($langs->trans("ResizeOrCrop"),'resize','class="paddingrightonly"').'</a>'; |
|
| 1303 | - } |
|
| 1304 | - } |
|
| 1305 | - |
|
| 1306 | - if ($permtoeditline) |
|
| 1307 | - { |
|
| 1308 | - $paramsectiondir=(in_array($modulepart, array('medias','ecm'))?'§ion_dir='.urlencode($relativepath):''); |
|
| 1309 | - print '<a href="'.(($useinecm == 1)?'#':($url.'?action=editfile&urlfile='.urlencode($filepath).$paramsectiondir.$param)).'" class="editfilelink" rel="'.$filepath.'">'.img_edit('default',0,'class="paddingrightonly"').'</a>'; |
|
| 1310 | - } |
|
| 1311 | - } |
|
| 1312 | - if ($permonobject) |
|
| 1313 | - { |
|
| 1314 | - $useajax=1; |
|
| 1315 | - if (! empty($conf->dol_use_jmobile)) $useajax=0; |
|
| 1316 | - if (empty($conf->use_javascript_ajax)) $useajax=0; |
|
| 1317 | - if (! empty($conf->global->MAIN_ECM_DISABLE_JS)) $useajax=0; |
|
| 1318 | - print '<a href="'.(($useinecm && $useajax)?'#':($url.'?action=delete&urlfile='.urlencode($filepath).$param)).'" class="deletefilelink" rel="'.$filepath.'">'.img_delete().'</a>'; |
|
| 1319 | - } |
|
| 1320 | - print "</td>"; |
|
| 1024 | + global $user, $conf, $langs, $hookmanager; |
|
| 1025 | + global $sortfield, $sortorder, $maxheightmini; |
|
| 1026 | + global $dolibarr_main_url_root; |
|
| 1027 | + global $form; |
|
| 1028 | + |
|
| 1029 | + $disablecrop=1; |
|
| 1030 | + if (in_array($modulepart, array('expensereport','holiday','member','project','product','produit','service','societe','tax','ticket','user'))) $disablecrop=0; |
|
| 1031 | + |
|
| 1032 | + // Define relative path used to store the file |
|
| 1033 | + if (empty($relativepath)) |
|
| 1034 | + { |
|
| 1035 | + $relativepath=(! empty($object->ref)?dol_sanitizeFileName($object->ref):'').'/'; |
|
| 1036 | + if ($object->element == 'invoice_supplier') $relativepath=get_exdir($object->id,2,0,0,$object,'invoice_supplier').$relativepath; // TODO Call using a defined value for $relativepath |
|
| 1037 | + if ($object->element == 'project_task') $relativepath='Call_not_supported_._Call_function_using_a_defined_relative_path_.'; |
|
| 1038 | + } |
|
| 1039 | + // For backward compatiblity, we detect file stored into an old path |
|
| 1040 | + if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO) && $filearray[0]['level1name'] == 'photos') |
|
| 1041 | + { |
|
| 1042 | + $relativepath=preg_replace('/^.*\/produit\//','',$filearray[0]['path']).'/'; |
|
| 1043 | + } |
|
| 1044 | + // Defined relative dir to DOL_DATA_ROOT |
|
| 1045 | + $relativedir = ''; |
|
| 1046 | + if ($upload_dir) |
|
| 1047 | + { |
|
| 1048 | + $relativedir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $upload_dir); |
|
| 1049 | + $relativedir = preg_replace('/^[\\/]/','',$relativedir); |
|
| 1050 | + } |
|
| 1051 | + |
|
| 1052 | + $hookmanager->initHooks(array('formfile')); |
|
| 1053 | + $parameters=array( |
|
| 1054 | + 'filearray' => $filearray, |
|
| 1055 | + 'modulepart'=> $modulepart, |
|
| 1056 | + 'param' => $param, |
|
| 1057 | + 'forcedownload' => $forcedownload, |
|
| 1058 | + 'relativepath' => $relativepath, // relative filename to module dir |
|
| 1059 | + 'relativedir' => $relativedir, // relative dirname to DOL_DATA_ROOT |
|
| 1060 | + 'permtodelete' => $permonobject, |
|
| 1061 | + 'useinecm' => $useinecm, |
|
| 1062 | + 'textifempty' => $textifempty, |
|
| 1063 | + 'maxlength' => $maxlength, |
|
| 1064 | + 'title' => $title, |
|
| 1065 | + 'url' => $url |
|
| 1066 | + ); |
|
| 1067 | + $reshook=$hookmanager->executeHooks('showFilesList', $parameters, $object); |
|
| 1068 | + |
|
| 1069 | + if (isset($reshook) && $reshook != '') // null or '' for bypass |
|
| 1070 | + { |
|
| 1071 | + return $reshook; |
|
| 1072 | + } |
|
| 1073 | + else |
|
| 1074 | + { |
|
| 1075 | + if (! is_object($form)) |
|
| 1076 | + { |
|
| 1077 | + include_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; // The compoent may be included into ajax page that does not include the Form class |
|
| 1078 | + $form=new Form($this->db); |
|
| 1079 | + } |
|
| 1321 | 1080 | |
| 1322 | - if (empty($disablemove)) |
|
| 1323 | - { |
|
| 1324 | - if ($nboffiles > 1 && $conf->browser->layout != 'phone') { |
|
| 1325 | - print '<td align="center" class="linecolmove tdlineupdown">'; |
|
| 1326 | - if ($i > 0) { |
|
| 1327 | - print '<a class="lineupdown" href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=up&rowid='.$line->id.'">'.img_up('default',0,'imgupforline').'</a>'; |
|
| 1328 | - } |
|
| 1329 | - if ($i < $nboffiles-1) { |
|
| 1330 | - print '<a class="lineupdown" href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=down&rowid='.$line->id.'">'.img_down('default',0,'imgdownforline').'</a>'; |
|
| 1331 | - } |
|
| 1332 | - print '</td>'; |
|
| 1333 | - } |
|
| 1334 | - else { |
|
| 1335 | - print '<td align="center"'.(($conf->browser->layout != 'phone' && empty($disablemove)) ?' class="linecolmove tdlineupdown"':' class="linecolmove"').'>'; |
|
| 1336 | - print '</td>'; |
|
| 1337 | - } |
|
| 1338 | - } |
|
| 1339 | - } |
|
| 1340 | - else |
|
| 1341 | - { |
|
| 1342 | - print '<td class="right">'; |
|
| 1343 | - print '<input type="hidden" name="ecmfileid" value="'.$filearray[$key]['rowid'].'">'; |
|
| 1344 | - print '<input type="submit" class="button" name="renamefilesave" value="'.dol_escape_htmltag($langs->trans("Save")).'">'; |
|
| 1345 | - print '<input type="submit" class="button" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">'; |
|
| 1346 | - print '</td>'; |
|
| 1347 | - if (empty($disablemove)) print '<td class="right"></td>'; |
|
| 1348 | - } |
|
| 1349 | - print "</tr>\n"; |
|
| 1350 | - |
|
| 1351 | - $i++; |
|
| 1352 | - } |
|
| 1353 | - } |
|
| 1354 | - if ($nboffiles == 0) |
|
| 1355 | - { |
|
| 1356 | - $colspan=(empty($useinecm)?'6':'6'); |
|
| 1357 | - if (empty($disablemove)) $colspan++; // 6 columns or 7 |
|
| 1358 | - print '<tr class="oddeven"><td colspan="'.$colspan.'" class="opacitymedium">'; |
|
| 1359 | - if (empty($textifempty)) print $langs->trans("NoFileFound"); |
|
| 1360 | - else print $textifempty; |
|
| 1361 | - print '</td></tr>'; |
|
| 1362 | - } |
|
| 1363 | - print "</table>"; |
|
| 1364 | - print '</div>'; |
|
| 1365 | - |
|
| 1366 | - if ($nboflines > 1 && is_object($object)) { |
|
| 1367 | - if (! empty($conf->use_javascript_ajax) && $permtoeditline) { |
|
| 1368 | - $table_element_line = 'ecm_files'; |
|
| 1369 | - include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php'; |
|
| 1370 | - } |
|
| 1371 | - } |
|
| 1372 | - |
|
| 1373 | - print ajax_autoselect('downloadlink'); |
|
| 1374 | - |
|
| 1375 | - if (GETPOST('action','aZ09') == 'editfile' && $permtoeditline) |
|
| 1376 | - { |
|
| 1377 | - print '</form>'; |
|
| 1378 | - } |
|
| 1379 | - |
|
| 1380 | - return $nboffiles; |
|
| 1381 | - } |
|
| 1382 | - } |
|
| 1081 | + if (! preg_match('/&id=/', $param) && isset($object->id)) $param.='&id='.$object->id; |
|
| 1082 | + $relativepathwihtoutslashend=preg_replace('/\/$/', '', $relativepath); |
|
| 1083 | + if ($relativepathwihtoutslashend) $param.= '&file='.urlencode($relativepathwihtoutslashend); |
|
| 1084 | + |
|
| 1085 | + if ($permtoeditline < 0) // Old behaviour for backward compatibility. New feature should call method with value 0 or 1 |
|
| 1086 | + { |
|
| 1087 | + $permtoeditline=0; |
|
| 1088 | + if (in_array($modulepart, array('product','produit','service'))) |
|
| 1089 | + { |
|
| 1090 | + if ($user->rights->produit->creer && $object->type == Product::TYPE_PRODUCT) $permtoeditline=1; |
|
| 1091 | + if ($user->rights->service->creer && $object->type == Product::TYPE_SERVICE) $permtoeditline=1; |
|
| 1092 | + } |
|
| 1093 | + } |
|
| 1094 | + if (empty($conf->global->MAIN_UPLOAD_DOC)) |
|
| 1095 | + { |
|
| 1096 | + $permtoeditline=0; |
|
| 1097 | + $permonobject=0; |
|
| 1098 | + } |
|
| 1099 | + |
|
| 1100 | + // Show list of existing files |
|
| 1101 | + if (empty($useinecm) && $title != 'none') print load_fiche_titre($title?$title:$langs->trans("AttachedFiles")); |
|
| 1102 | + if (empty($url)) $url=$_SERVER["PHP_SELF"]; |
|
| 1103 | + |
|
| 1104 | + print '<!-- html.formfile::list_of_documents -->'."\n"; |
|
| 1105 | + if (GETPOST('action','aZ09') == 'editfile' && $permtoeditline) |
|
| 1106 | + { |
|
| 1107 | + print '<form action="'.$_SERVER["PHP_SELF"].'?'.$param.'" method="POST">'; |
|
| 1108 | + print '<input type="hidden" name="action" value="renamefile">'; |
|
| 1109 | + print '<input type="hidden" name="id" value="'.$object->id.'">'; |
|
| 1110 | + print '<input type="hidden" name="modulepart" value="'.$modulepart.'">'; |
|
| 1111 | + } |
|
| 1112 | + |
|
| 1113 | + print '<div class="div-table-responsive-no-min">'; |
|
| 1114 | + print '<table width="100%" id="tablelines" class="'.($useinecm?'liste noborder':'liste').'">'."\n"; |
|
| 1115 | + |
|
| 1116 | + if (! empty($addfilterfields)) |
|
| 1117 | + { |
|
| 1118 | + print '<tr class="liste_titre nodrag nodrop">'; |
|
| 1119 | + print '<td><input type="search_doc_ref" value="'.dol_escape_htmltag(GETPOST('search_doc_ref','alpha')).'"></td>'; |
|
| 1120 | + print '<td></td>'; |
|
| 1121 | + print '<td></td>'; |
|
| 1122 | + if (empty($useinecm)) print '<td></td>'; |
|
| 1123 | + print '<td></td>'; |
|
| 1124 | + print '<td></td>'; |
|
| 1125 | + if (! $disablemove) print '<td></td>'; |
|
| 1126 | + print "</tr>\n"; |
|
| 1127 | + } |
|
| 1128 | + |
|
| 1129 | + print '<tr class="liste_titre nodrag nodrop">'; |
|
| 1130 | + //print $url.' sortfield='.$sortfield.' sortorder='.$sortorder; |
|
| 1131 | + print_liste_field_titre('Documents2',$url,"name","",$param,'align="left"',$sortfield,$sortorder); |
|
| 1132 | + print_liste_field_titre('Size',$url,"size","",$param,'align="right"',$sortfield,$sortorder); |
|
| 1133 | + print_liste_field_titre('Date',$url,"date","",$param,'align="center"',$sortfield,$sortorder); |
|
| 1134 | + if (empty($useinecm)) print_liste_field_titre('',$url,"","",$param,'align="center"'); // Preview |
|
| 1135 | + print_liste_field_titre(''); |
|
| 1136 | + print_liste_field_titre(''); |
|
| 1137 | + if (! $disablemove) print_liste_field_titre(''); |
|
| 1138 | + print "</tr>\n"; |
|
| 1139 | + |
|
| 1140 | + // Get list of files stored into database for same relative directory |
|
| 1141 | + if ($relativedir) |
|
| 1142 | + { |
|
| 1143 | + completeFileArrayWithDatabaseInfo($filearray, $relativedir); |
|
| 1144 | + |
|
| 1145 | + //var_dump($sortfield.' - '.$sortorder); |
|
| 1146 | + if ($sortfield && $sortorder) // If $sortfield is for example 'position_name', we will sort on the property 'position_name' (that is concat of position+name) |
|
| 1147 | + { |
|
| 1148 | + $filearray=dol_sort_array($filearray, $sortfield, $sortorder); |
|
| 1149 | + } |
|
| 1150 | + } |
|
| 1151 | + |
|
| 1152 | + $nboffiles=count($filearray); |
|
| 1153 | + if ($nboffiles > 0) include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; |
|
| 1154 | + |
|
| 1155 | + $i=0; $nboflines = 0; $lastrowid=0; |
|
| 1156 | + foreach($filearray as $key => $file) // filearray must be only files here |
|
| 1157 | + { |
|
| 1158 | + if ($file['name'] != '.' |
|
| 1159 | + && $file['name'] != '..' |
|
| 1160 | + && ! preg_match('/\.meta$/i',$file['name'])) |
|
| 1161 | + { |
|
| 1162 | + if ($filearray[$key]['rowid'] > 0) $lastrowid = $filearray[$key]['rowid']; |
|
| 1163 | + $filepath=$relativepath.$file['name']; |
|
| 1164 | + |
|
| 1165 | + $editline=0; |
|
| 1166 | + $nboflines++; |
|
| 1167 | + print '<!-- Line list_of_documents '.$key.' relativepath = '.$relativepath.' -->'."\n"; |
|
| 1168 | + // Do we have entry into database ? |
|
| 1169 | + print '<!-- In database: position='.$filearray[$key]['position'].' -->'."\n"; |
|
| 1170 | + print '<tr class="oddeven" id="row-'.($filearray[$key]['rowid']>0?$filearray[$key]['rowid']:'AFTER'.$lastrowid.'POS'.($i+1)).'">'; |
|
| 1171 | + |
|
| 1172 | + // File name |
|
| 1173 | + print '<td class="minwith200">'; |
|
| 1174 | + |
|
| 1175 | + // Show file name with link to download |
|
| 1176 | + //print "XX".$file['name']; //$file['name'] must be utf8 |
|
| 1177 | + print '<a class="paddingright" href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart; |
|
| 1178 | + if ($forcedownload) print '&attachment=1'; |
|
| 1179 | + if (! empty($object->entity)) print '&entity='.$object->entity; |
|
| 1180 | + print '&file='.urlencode($filepath); |
|
| 1181 | + print '">'; |
|
| 1182 | + print img_mime($file['name'], $file['name'].' ('.dol_print_size($file['size'],0,0).')', 'inline-block valignbottom paddingright'); |
|
| 1183 | + if ($showrelpart == 1) print $relativepath; |
|
| 1184 | + //print dol_trunc($file['name'],$maxlength,'middle'); |
|
| 1185 | + if (GETPOST('action','aZ09') == 'editfile' && $file['name'] == basename(GETPOST('urlfile','alpha'))) |
|
| 1186 | + { |
|
| 1187 | + print '</a>'; |
|
| 1188 | + $section_dir=dirname(GETPOST('urlfile','alpha')); |
|
| 1189 | + print '<input type="hidden" name="section_dir" value="'.$section_dir.'">'; |
|
| 1190 | + print '<input type="hidden" name="renamefilefrom" value="'.dol_escape_htmltag($file['name']).'">'; |
|
| 1191 | + print '<input type="text" name="renamefileto" class="quatrevingtpercent" value="'.dol_escape_htmltag($file['name']).'">'; |
|
| 1192 | + $editline=1; |
|
| 1193 | + } |
|
| 1194 | + else |
|
| 1195 | + { |
|
| 1196 | + print dol_trunc($file['name'], 200); |
|
| 1197 | + print '</a>'; |
|
| 1198 | + } |
|
| 1199 | + // Preview link |
|
| 1200 | + if (! $editline) print $this->showPreview($file, $modulepart, $filepath); |
|
| 1201 | + // Public share link |
|
| 1202 | + //if (! $editline && ! empty($filearray[$key]['hashp'])) print pictowithlinktodirectdownload; |
|
| 1203 | + |
|
| 1204 | + print "</td>\n"; |
|
| 1205 | + |
|
| 1206 | + // Size |
|
| 1207 | + $sizetoshow = dol_print_size($file['size'],1,1); |
|
| 1208 | + $sizetoshowbytes = dol_print_size($file['size'],0,1); |
|
| 1209 | + |
|
| 1210 | + print '<td align="right" width="80px">'; |
|
| 1211 | + if ($sizetoshow == $sizetoshowbytes) print $sizetoshow; |
|
| 1212 | + else { |
|
| 1213 | + print $form->textwithpicto($sizetoshow, $sizetoshowbytes, -1); |
|
| 1214 | + } |
|
| 1215 | + print '</td>'; |
|
| 1216 | + |
|
| 1217 | + // Date |
|
| 1218 | + print '<td align="center" width="140px">'.dol_print_date($file['date'],"dayhour","tzuser").'</td>'; // 140px = width for date with PM format |
|
| 1219 | + |
|
| 1220 | + // Preview |
|
| 1221 | + if (empty($useinecm)) |
|
| 1222 | + { |
|
| 1223 | + $fileinfo = pathinfo($file['name']); |
|
| 1224 | + print '<td align="center">'; |
|
| 1225 | + if (image_format_supported($file['name']) > 0) |
|
| 1226 | + { |
|
| 1227 | + $minifile=getImageFileNameForSize($file['name'], '_mini'); // For new thumbs using same ext (in lower case howerver) than original |
|
| 1228 | + if (! dol_is_file($file['path'].'/'.$minifile)) $minifile=getImageFileNameForSize($file['name'], '_mini', '.png'); // For backward compatibility of old thumbs that were created with filename in lower case and with .png extension |
|
| 1229 | + //print $file['path'].'/'.$minifile.'<br>'; |
|
| 1230 | + |
|
| 1231 | + $urlforhref=getAdvancedPreviewUrl($modulepart, $relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension']), 1, '&entity='.(!empty($object->entity)?$object->entity:$conf->entity)); |
|
| 1232 | + if (empty($urlforhref)) { |
|
| 1233 | + $urlforhref=DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.(!empty($object->entity)?$object->entity:$conf->entity).'&file='.urlencode($relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension'])); |
|
| 1234 | + print '<a href="'.$urlforhref.'" class="aphoto" target="_blank">'; |
|
| 1235 | + } else { |
|
| 1236 | + print '<a href="'.$urlforhref['url'].'" class="'.$urlforhref['css'].'" target="'.$urlforhref['target'].'" mime="'.$urlforhref['mime'].'">'; |
|
| 1237 | + } |
|
| 1238 | + print '<img border="0" height="'.$maxheightmini.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.(!empty($object->entity)?$object->entity:$conf->entity).'&file='.urlencode($relativepath.$minifile).'" title="">'; |
|
| 1239 | + print '</a>'; |
|
| 1240 | + } |
|
| 1241 | + else print ' '; |
|
| 1242 | + print '</td>'; |
|
| 1243 | + } |
|
| 1244 | + |
|
| 1245 | + // Hash of file (only if we are in a mode where a scan of dir were done and we have id of file in ECM table) |
|
| 1246 | + print '<td align="center">'; |
|
| 1247 | + if ($relativedir && $filearray[$key]['rowid'] > 0) |
|
| 1248 | + { |
|
| 1249 | + if ($editline) |
|
| 1250 | + { |
|
| 1251 | + print $langs->trans("FileSharedViaALink").' '; |
|
| 1252 | + print '<input class="inline-block" type="checkbox" name="shareenabled"'.($file['share']?' checked="checked"':'').' /> '; |
|
| 1253 | + } |
|
| 1254 | + else |
|
| 1255 | + { |
|
| 1256 | + if ($file['share']) |
|
| 1257 | + { |
|
| 1258 | + // Define $urlwithroot |
|
| 1259 | + $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); |
|
| 1260 | + $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
| 1261 | + //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current |
|
| 1262 | + |
|
| 1263 | + //print '<span class="opacitymedium">'.$langs->trans("Hash").' : '.$file['share'].'</span>'; |
|
| 1264 | + $forcedownload=0; |
|
| 1265 | + $paramlink=''; |
|
| 1266 | + if (! empty($file['share'])) $paramlink.=($paramlink?'&':'').'hashp='.$file['share']; // Hash for public share |
|
| 1267 | + if ($forcedownload) $paramlink.=($paramlink?'&':'').'attachment=1'; |
|
| 1268 | + |
|
| 1269 | + $fulllink=$urlwithroot.'/document.php'.($paramlink?'?'.$paramlink:''); |
|
| 1270 | + |
|
| 1271 | + print img_picto($langs->trans("FileSharedViaALink"),'object_globe.png').' '; |
|
| 1272 | + print '<input type="text" class="quatrevingtpercent" id="downloadlink" name="downloadexternallink" value="'.dol_escape_htmltag($fulllink).'">'; |
|
| 1273 | + } |
|
| 1274 | + else |
|
| 1275 | + { |
|
| 1276 | + //print '<span class="opacitymedium">'.$langs->trans("FileNotShared").'</span>'; |
|
| 1277 | + } |
|
| 1278 | + } |
|
| 1279 | + } |
|
| 1280 | + print '</td>'; |
|
| 1281 | + |
|
| 1282 | + // Actions buttons |
|
| 1283 | + if (! $editline) |
|
| 1284 | + { |
|
| 1285 | + // Delete or view link |
|
| 1286 | + // ($param must start with &) |
|
| 1287 | + print '<td class="valignmiddle right actionbuttons"><!-- action on files -->'; |
|
| 1288 | + if ($useinecm == 1) |
|
| 1289 | + { |
|
| 1290 | + print '<a href="'.DOL_URL_ROOT.'/ecm/file_card.php?urlfile='.urlencode($file['name']).$param.'" class="editfilelink" rel="'.urlencode($file['name']).'">'.img_edit('default', 0, 'class="paddingrightonly"').'</a>'; |
|
| 1291 | + } |
|
| 1292 | + if (! $useinecm || $useinecm == 2) |
|
| 1293 | + { |
|
| 1294 | + $newmodulepart=$modulepart; |
|
| 1295 | + if (in_array($modulepart, array('product','produit','service'))) $newmodulepart='produit|service'; |
|
| 1296 | + |
|
| 1297 | + if (! $disablecrop && image_format_supported($file['name']) > 0) |
|
| 1298 | + { |
|
| 1299 | + if ($permtoeditline) |
|
| 1300 | + { |
|
| 1301 | + // Link to resize |
|
| 1302 | + print '<a href="'.DOL_URL_ROOT.'/core/photos_resize.php?modulepart='.urlencode($newmodulepart).'&id='.$object->id.'&file='.urlencode($relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension'])).'" title="'.dol_escape_htmltag($langs->trans("ResizeOrCrop")).'">'.img_picto($langs->trans("ResizeOrCrop"),'resize','class="paddingrightonly"').'</a>'; |
|
| 1303 | + } |
|
| 1304 | + } |
|
| 1305 | + |
|
| 1306 | + if ($permtoeditline) |
|
| 1307 | + { |
|
| 1308 | + $paramsectiondir=(in_array($modulepart, array('medias','ecm'))?'§ion_dir='.urlencode($relativepath):''); |
|
| 1309 | + print '<a href="'.(($useinecm == 1)?'#':($url.'?action=editfile&urlfile='.urlencode($filepath).$paramsectiondir.$param)).'" class="editfilelink" rel="'.$filepath.'">'.img_edit('default',0,'class="paddingrightonly"').'</a>'; |
|
| 1310 | + } |
|
| 1311 | + } |
|
| 1312 | + if ($permonobject) |
|
| 1313 | + { |
|
| 1314 | + $useajax=1; |
|
| 1315 | + if (! empty($conf->dol_use_jmobile)) $useajax=0; |
|
| 1316 | + if (empty($conf->use_javascript_ajax)) $useajax=0; |
|
| 1317 | + if (! empty($conf->global->MAIN_ECM_DISABLE_JS)) $useajax=0; |
|
| 1318 | + print '<a href="'.(($useinecm && $useajax)?'#':($url.'?action=delete&urlfile='.urlencode($filepath).$param)).'" class="deletefilelink" rel="'.$filepath.'">'.img_delete().'</a>'; |
|
| 1319 | + } |
|
| 1320 | + print "</td>"; |
|
| 1321 | + |
|
| 1322 | + if (empty($disablemove)) |
|
| 1323 | + { |
|
| 1324 | + if ($nboffiles > 1 && $conf->browser->layout != 'phone') { |
|
| 1325 | + print '<td align="center" class="linecolmove tdlineupdown">'; |
|
| 1326 | + if ($i > 0) { |
|
| 1327 | + print '<a class="lineupdown" href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=up&rowid='.$line->id.'">'.img_up('default',0,'imgupforline').'</a>'; |
|
| 1328 | + } |
|
| 1329 | + if ($i < $nboffiles-1) { |
|
| 1330 | + print '<a class="lineupdown" href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=down&rowid='.$line->id.'">'.img_down('default',0,'imgdownforline').'</a>'; |
|
| 1331 | + } |
|
| 1332 | + print '</td>'; |
|
| 1333 | + } |
|
| 1334 | + else { |
|
| 1335 | + print '<td align="center"'.(($conf->browser->layout != 'phone' && empty($disablemove)) ?' class="linecolmove tdlineupdown"':' class="linecolmove"').'>'; |
|
| 1336 | + print '</td>'; |
|
| 1337 | + } |
|
| 1338 | + } |
|
| 1339 | + } |
|
| 1340 | + else |
|
| 1341 | + { |
|
| 1342 | + print '<td class="right">'; |
|
| 1343 | + print '<input type="hidden" name="ecmfileid" value="'.$filearray[$key]['rowid'].'">'; |
|
| 1344 | + print '<input type="submit" class="button" name="renamefilesave" value="'.dol_escape_htmltag($langs->trans("Save")).'">'; |
|
| 1345 | + print '<input type="submit" class="button" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">'; |
|
| 1346 | + print '</td>'; |
|
| 1347 | + if (empty($disablemove)) print '<td class="right"></td>'; |
|
| 1348 | + } |
|
| 1349 | + print "</tr>\n"; |
|
| 1350 | + |
|
| 1351 | + $i++; |
|
| 1352 | + } |
|
| 1353 | + } |
|
| 1354 | + if ($nboffiles == 0) |
|
| 1355 | + { |
|
| 1356 | + $colspan=(empty($useinecm)?'6':'6'); |
|
| 1357 | + if (empty($disablemove)) $colspan++; // 6 columns or 7 |
|
| 1358 | + print '<tr class="oddeven"><td colspan="'.$colspan.'" class="opacitymedium">'; |
|
| 1359 | + if (empty($textifempty)) print $langs->trans("NoFileFound"); |
|
| 1360 | + else print $textifempty; |
|
| 1361 | + print '</td></tr>'; |
|
| 1362 | + } |
|
| 1363 | + print "</table>"; |
|
| 1364 | + print '</div>'; |
|
| 1365 | + |
|
| 1366 | + if ($nboflines > 1 && is_object($object)) { |
|
| 1367 | + if (! empty($conf->use_javascript_ajax) && $permtoeditline) { |
|
| 1368 | + $table_element_line = 'ecm_files'; |
|
| 1369 | + include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php'; |
|
| 1370 | + } |
|
| 1371 | + } |
|
| 1372 | + |
|
| 1373 | + print ajax_autoselect('downloadlink'); |
|
| 1374 | + |
|
| 1375 | + if (GETPOST('action','aZ09') == 'editfile' && $permtoeditline) |
|
| 1376 | + { |
|
| 1377 | + print '</form>'; |
|
| 1378 | + } |
|
| 1379 | + |
|
| 1380 | + return $nboffiles; |
|
| 1381 | + } |
|
| 1382 | + } |
|
| 1383 | 1383 | |
| 1384 | 1384 | |
| 1385 | 1385 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
| 1386 | - /** |
|
| 1387 | - * Show list of documents in a directory |
|
| 1388 | - * |
|
| 1389 | - * @param string $upload_dir Directory that was scanned |
|
| 1390 | - * @param array $filearray Array of files loaded by dol_dir_list function before calling this function |
|
| 1391 | - * @param string $modulepart Value for modulepart used by download wrapper |
|
| 1392 | - * @param string $param Parameters on sort links |
|
| 1393 | - * @param int $forcedownload Force to open dialog box "Save As" when clicking on file |
|
| 1394 | - * @param string $relativepath Relative path of docs (autodefined if not provided) |
|
| 1395 | - * @param int $permtodelete Permission to delete |
|
| 1396 | - * @param int $useinecm Change output for use in ecm module |
|
| 1397 | - * @param int $textifempty Text to show if filearray is empty |
|
| 1398 | - * @param int $maxlength Maximum length of file name shown |
|
| 1399 | - * @param string $url Full url to use for click links ('' = autodetect) |
|
| 1400 | - * @param int $addfilterfields Add line with filters |
|
| 1401 | - * @return int <0 if KO, nb of files shown if OK |
|
| 1402 | - * @see list_of_documents |
|
| 1403 | - */ |
|
| 1404 | - function list_of_autoecmfiles($upload_dir, $filearray, $modulepart, $param, $forcedownload=0, $relativepath='', $permtodelete=1, $useinecm=0, $textifempty='', $maxlength=0, $url='', $addfilterfields=0) |
|
| 1405 | - { |
|
| 1386 | + /** |
|
| 1387 | + * Show list of documents in a directory |
|
| 1388 | + * |
|
| 1389 | + * @param string $upload_dir Directory that was scanned |
|
| 1390 | + * @param array $filearray Array of files loaded by dol_dir_list function before calling this function |
|
| 1391 | + * @param string $modulepart Value for modulepart used by download wrapper |
|
| 1392 | + * @param string $param Parameters on sort links |
|
| 1393 | + * @param int $forcedownload Force to open dialog box "Save As" when clicking on file |
|
| 1394 | + * @param string $relativepath Relative path of docs (autodefined if not provided) |
|
| 1395 | + * @param int $permtodelete Permission to delete |
|
| 1396 | + * @param int $useinecm Change output for use in ecm module |
|
| 1397 | + * @param int $textifempty Text to show if filearray is empty |
|
| 1398 | + * @param int $maxlength Maximum length of file name shown |
|
| 1399 | + * @param string $url Full url to use for click links ('' = autodetect) |
|
| 1400 | + * @param int $addfilterfields Add line with filters |
|
| 1401 | + * @return int <0 if KO, nb of files shown if OK |
|
| 1402 | + * @see list_of_documents |
|
| 1403 | + */ |
|
| 1404 | + function list_of_autoecmfiles($upload_dir, $filearray, $modulepart, $param, $forcedownload=0, $relativepath='', $permtodelete=1, $useinecm=0, $textifempty='', $maxlength=0, $url='', $addfilterfields=0) |
|
| 1405 | + { |
|
| 1406 | 1406 | // phpcs:enable |
| 1407 | - global $user, $conf, $langs, $form; |
|
| 1408 | - global $sortfield, $sortorder; |
|
| 1409 | - global $search_doc_ref; |
|
| 1410 | - |
|
| 1411 | - dol_syslog(get_class($this).'::list_of_autoecmfiles upload_dir='.$upload_dir.' modulepart='.$modulepart); |
|
| 1412 | - |
|
| 1413 | - // Show list of documents |
|
| 1414 | - if (empty($useinecm)) print load_fiche_titre($langs->trans("AttachedFiles")); |
|
| 1415 | - if (empty($url)) $url=$_SERVER["PHP_SELF"]; |
|
| 1416 | - |
|
| 1417 | - if (! empty($addfilterfields)) |
|
| 1418 | - { |
|
| 1419 | - print '<form action="'.$_SERVER['PHP_SELF'].'">'; |
|
| 1420 | - print '<input type="hidden" name="module" value="'.$modulepart.'">'; |
|
| 1421 | - } |
|
| 1422 | - |
|
| 1423 | - print '<div class="div-table-responsive-no-min">'; |
|
| 1424 | - print '<table width="100%" class="noborder">'."\n"; |
|
| 1425 | - |
|
| 1426 | - if (! empty($addfilterfields)) |
|
| 1427 | - { |
|
| 1428 | - print '<tr class="liste_titre nodrag nodrop">'; |
|
| 1429 | - print '<td></td>'; |
|
| 1430 | - print '<td><input type="text" class="maxwidth100onsmartphone" name="search_doc_ref" value="'.dol_escape_htmltag($search_doc_ref).'"></td>'; |
|
| 1431 | - print '<td></td>'; |
|
| 1432 | - print '<td></td>'; |
|
| 1433 | - // Action column |
|
| 1434 | - print '<td class="liste_titre" align="middle">'; |
|
| 1435 | - $searchpicto=$form->showFilterButtons(); |
|
| 1436 | - print $searchpicto; |
|
| 1437 | - print '</td>'; |
|
| 1438 | - print "</tr>\n"; |
|
| 1439 | - } |
|
| 1440 | - |
|
| 1441 | - print '<tr class="liste_titre">'; |
|
| 1442 | - $sortref="fullname"; |
|
| 1443 | - if ($modulepart == 'invoice_supplier') $sortref='level1name'; |
|
| 1444 | - print_liste_field_titre("Ref",$url,$sortref,"",$param,'align="left"',$sortfield,$sortorder); |
|
| 1445 | - print_liste_field_titre("Documents2",$url,"name","",$param,'align="left"',$sortfield,$sortorder); |
|
| 1446 | - print_liste_field_titre("Size",$url,"size","",$param,'align="right"',$sortfield,$sortorder); |
|
| 1447 | - print_liste_field_titre("Date",$url,"date","",$param,'align="center"',$sortfield,$sortorder); |
|
| 1448 | - print_liste_field_titre('','',''); |
|
| 1449 | - print '</tr>'."\n"; |
|
| 1450 | - |
|
| 1451 | - // To show ref or specific information according to view to show (defined by $module) |
|
| 1452 | - if ($modulepart == 'company') |
|
| 1453 | - { |
|
| 1454 | - include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; |
|
| 1455 | - $object_instance=new Societe($this->db); |
|
| 1456 | - } |
|
| 1457 | - else if ($modulepart == 'invoice') |
|
| 1458 | - { |
|
| 1459 | - include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; |
|
| 1460 | - $object_instance=new Facture($this->db); |
|
| 1461 | - } |
|
| 1462 | - else if ($modulepart == 'invoice_supplier') |
|
| 1463 | - { |
|
| 1464 | - include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; |
|
| 1465 | - $object_instance=new FactureFournisseur($this->db); |
|
| 1466 | - } |
|
| 1467 | - else if ($modulepart == 'propal') |
|
| 1468 | - { |
|
| 1469 | - include_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; |
|
| 1470 | - $object_instance=new Propal($this->db); |
|
| 1471 | - } |
|
| 1472 | - else if ($modulepart == 'supplier_proposal') |
|
| 1473 | - { |
|
| 1474 | - include_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php'; |
|
| 1475 | - $object_instance=new SupplierProposal($this->db); |
|
| 1476 | - } |
|
| 1477 | - else if ($modulepart == 'order') |
|
| 1478 | - { |
|
| 1479 | - include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; |
|
| 1480 | - $object_instance=new Commande($this->db); |
|
| 1481 | - } |
|
| 1482 | - else if ($modulepart == 'order_supplier') |
|
| 1483 | - { |
|
| 1484 | - include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php'; |
|
| 1485 | - $object_instance=new CommandeFournisseur($this->db); |
|
| 1486 | - } |
|
| 1487 | - else if ($modulepart == 'contract') |
|
| 1488 | - { |
|
| 1489 | - include_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php'; |
|
| 1490 | - $object_instance=new Contrat($this->db); |
|
| 1491 | - } |
|
| 1492 | - else if ($modulepart == 'product') |
|
| 1493 | - { |
|
| 1494 | - include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; |
|
| 1495 | - $object_instance=new Product($this->db); |
|
| 1496 | - } |
|
| 1497 | - else if ($modulepart == 'tax') |
|
| 1498 | - { |
|
| 1499 | - include_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php'; |
|
| 1500 | - $object_instance=new ChargeSociales($this->db); |
|
| 1501 | - } |
|
| 1502 | - else if ($modulepart == 'project') |
|
| 1503 | - { |
|
| 1504 | - include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; |
|
| 1505 | - $object_instance=new Project($this->db); |
|
| 1506 | - } |
|
| 1507 | - else if ($modulepart == 'fichinter') |
|
| 1508 | - { |
|
| 1509 | - include_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php'; |
|
| 1510 | - $object_instance=new Fichinter($this->db); |
|
| 1511 | - } |
|
| 1512 | - else if ($modulepart == 'user') |
|
| 1513 | - { |
|
| 1514 | - include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; |
|
| 1515 | - $object_instance=new User($this->db); |
|
| 1516 | - } |
|
| 1517 | - else if ($modulepart == 'expensereport') |
|
| 1518 | - { |
|
| 1519 | - include_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php'; |
|
| 1520 | - $object_instance=new ExpenseReport($this->db); |
|
| 1521 | - } |
|
| 1522 | - else if ($modulepart == 'holiday') |
|
| 1523 | - { |
|
| 1524 | - include_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php'; |
|
| 1525 | - $object_instance=new Holiday($this->db); |
|
| 1526 | - } |
|
| 1527 | - |
|
| 1528 | - foreach($filearray as $key => $file) |
|
| 1529 | - { |
|
| 1530 | - if (!is_dir($file['name']) |
|
| 1531 | - && $file['name'] != '.' |
|
| 1532 | - && $file['name'] != '..' |
|
| 1533 | - && $file['name'] != 'CVS' |
|
| 1534 | - && ! preg_match('/\.meta$/i',$file['name'])) |
|
| 1535 | - { |
|
| 1536 | - // Define relative path used to store the file |
|
| 1537 | - $relativefile=preg_replace('/'.preg_quote($upload_dir.'/','/').'/','',$file['fullname']); |
|
| 1538 | - |
|
| 1539 | - //var_dump($file); |
|
| 1540 | - $id=0; $ref=''; $label=''; |
|
| 1541 | - |
|
| 1542 | - // To show ref or specific information according to view to show (defined by $module) |
|
| 1543 | - if ($modulepart == 'company') { preg_match('/(\d+)\/[^\/]+$/',$relativefile,$reg); $id=(isset($reg[1])?$reg[1]:''); } |
|
| 1544 | - if ($modulepart == 'invoice') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); } |
|
| 1545 | - if ($modulepart == 'invoice_supplier') { preg_match('/([^\/]+)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); if (is_numeric($ref)) { $id=$ref; $ref=''; } } // $ref may be also id with old supplier invoices |
|
| 1546 | - if ($modulepart == 'propal') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); } |
|
| 1547 | - if ($modulepart == 'supplier_proposal') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); } |
|
| 1548 | - if ($modulepart == 'order') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); } |
|
| 1549 | - if ($modulepart == 'order_supplier') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); } |
|
| 1550 | - if ($modulepart == 'contract') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); } |
|
| 1551 | - if ($modulepart == 'product') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); } |
|
| 1552 | - if ($modulepart == 'tax') { preg_match('/(\d+)\/[^\/]+$/',$relativefile,$reg); $id=(isset($reg[1])?$reg[1]:''); } |
|
| 1553 | - if ($modulepart == 'project') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:'');} |
|
| 1554 | - if ($modulepart == 'fichinter') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:'');} |
|
| 1555 | - if ($modulepart == 'user') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $id=(isset($reg[1])?$reg[1]:'');} |
|
| 1556 | - if ($modulepart == 'expensereport') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:'');} |
|
| 1557 | - if ($modulepart == 'holiday') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $id=(isset($reg[1])?$reg[1]:'');} |
|
| 1558 | - |
|
| 1559 | - if (! $id && ! $ref) continue; |
|
| 1560 | - $found=0; |
|
| 1561 | - if (! empty($this->cache_objects[$modulepart.'_'.$id.'_'.$ref])) |
|
| 1562 | - { |
|
| 1563 | - $found=1; |
|
| 1564 | - } |
|
| 1565 | - else |
|
| 1566 | - { |
|
| 1567 | - //print 'Fetch '.$id." - ".$ref.'<br>'; |
|
| 1568 | - |
|
| 1569 | - if ($id) { |
|
| 1570 | - $result = $object_instance->fetch($id); |
|
| 1571 | - } else { |
|
| 1572 | - //fetchOneLike looks for objects with wildcards in its reference. |
|
| 1573 | - //It is useful for those masks who get underscores instead of their actual symbols |
|
| 1574 | - //fetchOneLike requires some info in the object. If it doesn't have it, then 0 is returned |
|
| 1575 | - //that's why we look only look fetchOneLike when fetch returns 0 |
|
| 1576 | - if (!$result = $object_instance->fetch('', $ref)) { |
|
| 1577 | - $result = $object_instance->fetchOneLike($ref); |
|
| 1578 | - } |
|
| 1579 | - } |
|
| 1580 | - |
|
| 1581 | - if ($result > 0) { // Save object into a cache |
|
| 1582 | - $found=1; $this->cache_objects[$modulepart.'_'.$id.'_'.$ref] = clone $object_instance; |
|
| 1583 | - } |
|
| 1584 | - if ($result == 0) { $found=1; $this->cache_objects[$modulepart.'_'.$id.'_'.$ref]='notfound'; unset($filearray[$key]); } |
|
| 1585 | - } |
|
| 1586 | - |
|
| 1587 | - if (! $found > 0 || ! is_object($this->cache_objects[$modulepart.'_'.$id.'_'.$ref])) continue; // We do not show orphelins files |
|
| 1588 | - |
|
| 1589 | - print '<!-- Line list_of_autoecmfiles '.$key.' -->'."\n"; |
|
| 1590 | - print '<tr class="oddeven">'; |
|
| 1591 | - print '<td>'; |
|
| 1592 | - if ($found > 0 && is_object($this->cache_objects[$modulepart.'_'.$id.'_'.$ref])) print $this->cache_objects[$modulepart.'_'.$id.'_'.$ref]->getNomUrl(1,'document'); |
|
| 1593 | - else print $langs->trans("ObjectDeleted",($id?$id:$ref)); |
|
| 1594 | - |
|
| 1595 | - //$modulesubdir=dol_sanitizeFileName($ref); |
|
| 1596 | - $modulesubdir=dirname($relativefile); |
|
| 1597 | - |
|
| 1598 | - //$filedir=$conf->$modulepart->dir_output . '/' . dol_sanitizeFileName($obj->ref); |
|
| 1599 | - $filedir=$file['path']; |
|
| 1600 | - //$urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid; |
|
| 1601 | - //print $formfile->getDocumentsLink($modulepart, $filename, $filedir); |
|
| 1602 | - |
|
| 1603 | - print '</td>'; |
|
| 1604 | - |
|
| 1605 | - // File |
|
| 1606 | - print '<td>'; |
|
| 1607 | - //print "XX".$file['name']; //$file['name'] must be utf8 |
|
| 1608 | - print '<a href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart; |
|
| 1609 | - if ($forcedownload) print '&attachment=1'; |
|
| 1610 | - print '&file='.urlencode($relativefile).'">'; |
|
| 1611 | - print img_mime($file['name'],$file['name'].' ('.dol_print_size($file['size'],0,0).')'); |
|
| 1612 | - print dol_trunc($file['name'],$maxlength,'middle'); |
|
| 1613 | - print '</a>'; |
|
| 1614 | - |
|
| 1615 | - //print $this->getDocumentsLink($modulepart, $modulesubdir, $filedir, '^'.preg_quote($file['name'],'/').'$'); |
|
| 1616 | - print $this->showPreview($file, $modulepart, $file['relativename']); |
|
| 1617 | - |
|
| 1618 | - print "</td>\n"; |
|
| 1619 | - print '<td align="right">'.dol_print_size($file['size'],1,1).'</td>'; |
|
| 1620 | - print '<td align="center">'.dol_print_date($file['date'],"dayhour").'</td>'; |
|
| 1621 | - print '<td align="right">'; |
|
| 1622 | - //if (! empty($useinecm)) print '<a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart; |
|
| 1623 | - //if ($forcedownload) print '&attachment=1'; |
|
| 1624 | - //print '&file='.urlencode($relativefile).'">'; |
|
| 1625 | - //print img_view().'</a> '; |
|
| 1626 | - //if ($permtodelete) print '<a href="'.$url.'?id='.$object->id.'§ion='.$_REQUEST["section"].'&action=delete&urlfile='.urlencode($file['name']).'">'.img_delete().'</a>'; |
|
| 1627 | - //else print ' '; |
|
| 1628 | - print "</td></tr>\n"; |
|
| 1629 | - } |
|
| 1630 | - } |
|
| 1631 | - |
|
| 1632 | - if (count($filearray) == 0) |
|
| 1633 | - { |
|
| 1634 | - print '<tr class="oddeven"><td colspan="5">'; |
|
| 1635 | - if (empty($textifempty)) print $langs->trans("NoFileFound"); |
|
| 1636 | - else print $textifempty; |
|
| 1637 | - print '</td></tr>'; |
|
| 1638 | - } |
|
| 1639 | - print "</table>"; |
|
| 1640 | - print '</div>'; |
|
| 1641 | - |
|
| 1642 | - if (! empty($addfilterfields)) print '</form>'; |
|
| 1643 | - // Fin de zone |
|
| 1644 | - } |
|
| 1645 | - |
|
| 1646 | - /** |
|
| 1647 | - * Show form to upload a new file with jquery fileupload. |
|
| 1648 | - * This form use the fileupload.php file. |
|
| 1649 | - * |
|
| 1650 | - * @param Object $object Object to use |
|
| 1651 | - * @return void |
|
| 1652 | - */ |
|
| 1653 | - private function _formAjaxFileUpload($object) |
|
| 1654 | - { |
|
| 1655 | - global $langs, $conf; |
|
| 1656 | - |
|
| 1657 | - // PHP post_max_size |
|
| 1658 | - $post_max_size = ini_get('post_max_size'); |
|
| 1659 | - $mul_post_max_size = substr($post_max_size, -1); |
|
| 1660 | - $mul_post_max_size = ($mul_post_max_size == 'M' ? 1048576 : ($mul_post_max_size == 'K' ? 1024 : ($mul_post_max_size == 'G' ? 1073741824 : 1))); |
|
| 1661 | - $post_max_size = $mul_post_max_size * (int) $post_max_size; |
|
| 1662 | - // PHP upload_max_filesize |
|
| 1663 | - $upload_max_filesize = ini_get('upload_max_filesize'); |
|
| 1664 | - $mul_upload_max_filesize = substr($upload_max_filesize, -1); |
|
| 1665 | - $mul_upload_max_filesize = ($mul_upload_max_filesize == 'M' ? 1048576 : ($mul_upload_max_filesize == 'K' ? 1024 : ($mul_upload_max_filesize == 'G' ? 1073741824 : 1))); |
|
| 1666 | - $upload_max_filesize = $mul_upload_max_filesize * (int) $upload_max_filesize; |
|
| 1667 | - // Max file size |
|
| 1668 | - $max_file_size = (($post_max_size < $upload_max_filesize) ? $post_max_size : $upload_max_filesize); |
|
| 1669 | - |
|
| 1670 | - // Include main |
|
| 1671 | - include DOL_DOCUMENT_ROOT.'/core/tpl/ajax/fileupload_main.tpl.php'; |
|
| 1672 | - |
|
| 1673 | - // Include template |
|
| 1674 | - include DOL_DOCUMENT_ROOT.'/core/tpl/ajax/fileupload_view.tpl.php'; |
|
| 1675 | - } |
|
| 1676 | - |
|
| 1677 | - /** |
|
| 1678 | - * Show array with linked files |
|
| 1679 | - * |
|
| 1680 | - * @param Object $object Object |
|
| 1681 | - * @param int $permtodelete Deletion is allowed |
|
| 1682 | - * @param string $action Action |
|
| 1683 | - * @param string $selected ??? |
|
| 1684 | - * @param string $param More param to add into URL |
|
| 1685 | - * @return int Number of links |
|
| 1686 | - */ |
|
| 1687 | - public function listOfLinks($object, $permtodelete=1, $action=null, $selected=null, $param='') |
|
| 1688 | - { |
|
| 1689 | - global $user, $conf, $langs, $user; |
|
| 1690 | - global $sortfield, $sortorder; |
|
| 1691 | - |
|
| 1692 | - $langs->load("link"); |
|
| 1693 | - |
|
| 1694 | - require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php'; |
|
| 1695 | - $link = new Link($this->db); |
|
| 1696 | - $links = array(); |
|
| 1697 | - if ($sortfield == "name") { |
|
| 1698 | - $sortfield = "label"; |
|
| 1699 | - } elseif ($sortfield == "date") { |
|
| 1700 | - $sortfield = "datea"; |
|
| 1701 | - } else { |
|
| 1702 | - $sortfield = null; |
|
| 1703 | - } |
|
| 1704 | - $res = $link->fetchAll($links, $object->element, $object->id, $sortfield, $sortorder); |
|
| 1705 | - $param .= (isset($object->id)?'&id=' . $object->id : ''); |
|
| 1706 | - |
|
| 1707 | - // Show list of associated links |
|
| 1708 | - print load_fiche_titre($langs->trans("LinkedFiles")); |
|
| 1709 | - |
|
| 1710 | - print '<form action="' . $_SERVER['PHP_SELF'] . ($param?'?'.$param:'') . '" method="POST">'; |
|
| 1711 | - |
|
| 1712 | - print '<table width="100%" class="liste">'; |
|
| 1713 | - print '<tr class="liste_titre">'; |
|
| 1714 | - print_liste_field_titre( |
|
| 1715 | - $langs->trans("Links"), |
|
| 1716 | - $_SERVER['PHP_SELF'], |
|
| 1717 | - "name", |
|
| 1718 | - "", |
|
| 1719 | - $param, |
|
| 1720 | - 'align="left"', |
|
| 1721 | - $sortfield, |
|
| 1722 | - $sortorder |
|
| 1723 | - ); |
|
| 1724 | - print_liste_field_titre( |
|
| 1725 | - "", |
|
| 1726 | - "", |
|
| 1727 | - "", |
|
| 1728 | - "", |
|
| 1729 | - "", |
|
| 1730 | - 'align="right"' |
|
| 1731 | - ); |
|
| 1732 | - print_liste_field_titre( |
|
| 1733 | - $langs->trans("Date"), |
|
| 1734 | - $_SERVER['PHP_SELF'], |
|
| 1735 | - "date", |
|
| 1736 | - "", |
|
| 1737 | - $param, |
|
| 1738 | - 'align="center"', |
|
| 1739 | - $sortfield, |
|
| 1740 | - $sortorder |
|
| 1741 | - ); |
|
| 1742 | - print_liste_field_titre( |
|
| 1743 | - '', |
|
| 1744 | - $_SERVER['PHP_SELF'], |
|
| 1745 | - "", |
|
| 1746 | - "", |
|
| 1747 | - $param, |
|
| 1748 | - 'align="center"' |
|
| 1749 | - ); |
|
| 1750 | - print_liste_field_titre('','',''); |
|
| 1751 | - print '</tr>'; |
|
| 1752 | - $nboflinks = count($links); |
|
| 1753 | - if ($nboflinks > 0) include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; |
|
| 1754 | - |
|
| 1755 | - foreach ($links as $link) |
|
| 1756 | - { |
|
| 1757 | - print '<tr class="oddeven">'; |
|
| 1758 | - //edit mode |
|
| 1759 | - if ($action == 'update' && $selected === $link->id) |
|
| 1760 | - { |
|
| 1761 | - print '<td>'; |
|
| 1762 | - print '<input type="hidden" name="id" value="' . $object->id . '">'; |
|
| 1763 | - print '<input type="hidden" name="linkid" value="' . $link->id . '">'; |
|
| 1764 | - print '<input type="hidden" name="action" value="confirm_updateline">'; |
|
| 1765 | - print $langs->trans('Link') . ': <input type="text" name="link" value="' . $link->url . '">'; |
|
| 1766 | - print '</td>'; |
|
| 1767 | - print '<td>'; |
|
| 1768 | - print $langs->trans('Label') . ': <input type="text" name="label" value="' . $link->label . '">'; |
|
| 1769 | - print '</td>'; |
|
| 1770 | - print '<td align="center">' . dol_print_date(dol_now(), "dayhour", "tzuser") . '</td>'; |
|
| 1771 | - print '<td align="right"></td>'; |
|
| 1772 | - print '<td align="right">'; |
|
| 1773 | - print '<input type="submit" name="save" class="button" value="' . dol_escape_htmltag($langs->trans('Save')) . '">'; |
|
| 1774 | - print '<input type="submit" name="cancel" class="button" value="' . dol_escape_htmltag($langs->trans('Cancel')) . '">'; |
|
| 1775 | - print '</td>'; |
|
| 1776 | - } |
|
| 1777 | - else |
|
| 1778 | - { |
|
| 1779 | - print '<td>'; |
|
| 1780 | - print img_picto('', 'object_globe').' '; |
|
| 1781 | - print '<a data-ajax="false" href="' . $link->url . '" target="_blank">'; |
|
| 1782 | - print $link->label; |
|
| 1783 | - print '</a>'; |
|
| 1784 | - print '</td>'."\n"; |
|
| 1785 | - print '<td align="right"></td>'; |
|
| 1786 | - print '<td align="center">' . dol_print_date($link->datea, "dayhour", "tzuser") . '</td>'; |
|
| 1787 | - print '<td align="center"></td>'; |
|
| 1788 | - print '<td align="right">'; |
|
| 1789 | - print '<a href="' . $_SERVER['PHP_SELF'] . '?action=update&linkid=' . $link->id . $param . '" class="editfilelink" >' . img_edit() . '</a>'; // id= is included into $param |
|
| 1790 | - if ($permtodelete) { |
|
| 1791 | - print ' <a href="'. $_SERVER['PHP_SELF'] .'?action=delete&linkid=' . $link->id . $param . '" class="deletefilelink">' . img_delete() . '</a>'; // id= is included into $param |
|
| 1792 | - } else { |
|
| 1793 | - print ' '; |
|
| 1794 | - } |
|
| 1795 | - print '</td>'; |
|
| 1796 | - } |
|
| 1797 | - print "</tr>\n"; |
|
| 1798 | - } |
|
| 1799 | - if ($nboflinks == 0) |
|
| 1800 | - { |
|
| 1801 | - print '<tr class="oddeven"><td colspan="5" class="opacitymedium">'; |
|
| 1802 | - print $langs->trans("NoLinkFound"); |
|
| 1803 | - print '</td></tr>'; |
|
| 1804 | - } |
|
| 1805 | - print "</table>"; |
|
| 1806 | - |
|
| 1807 | - print '</form>'; |
|
| 1808 | - |
|
| 1809 | - return $nboflinks; |
|
| 1810 | - } |
|
| 1811 | - |
|
| 1812 | - |
|
| 1813 | - /** |
|
| 1814 | - * Show detail icon with link for preview |
|
| 1815 | - * |
|
| 1816 | - * @param array $file Array with data of file. Example: array('name'=>...) |
|
| 1817 | - * @param string $modulepart propal, facture, facture_fourn, ... |
|
| 1818 | - * @param string $relativepath Relative path of docs |
|
| 1819 | - * @param string $ruleforpicto Rule for picto: 0=Use the generic preview picto, 1=Use the picto of mime type of file) |
|
| 1820 | - * @param string $param More param on http links |
|
| 1821 | - * @return string $out Output string with HTML |
|
| 1822 | - */ |
|
| 1823 | - public function showPreview($file, $modulepart, $relativepath, $ruleforpicto=0, $param='') |
|
| 1824 | - { |
|
| 1825 | - global $langs, $conf; |
|
| 1826 | - |
|
| 1827 | - $out=''; |
|
| 1828 | - if ($conf->browser->layout != 'phone' && ! empty($conf->use_javascript_ajax)) |
|
| 1829 | - { |
|
| 1830 | - $urladvancedpreview=getAdvancedPreviewUrl($modulepart, $relativepath, 1, $param); // Return if a file is qualified for preview. |
|
| 1831 | - if (count($urladvancedpreview)) |
|
| 1832 | - { |
|
| 1833 | - $out.= '<a class="pictopreview '.$urladvancedpreview['css'].'" href="'.$urladvancedpreview['url'].'"'.(empty($urladvancedpreview['mime'])?'':' mime="'.$urladvancedpreview['mime'].'"').' '.(empty($urladvancedpreview['target'])?'':' target="'.$urladvancedpreview['target'].'"').'>'; |
|
| 1834 | - //$out.= '<a class="pictopreview">'; |
|
| 1835 | - if (empty($ruleforpicto)) |
|
| 1836 | - { |
|
| 1837 | - //$out.= img_picto($langs->trans('Preview').' '.$file['name'], 'detail'); |
|
| 1838 | - $out.='<span class="fa fa-search-plus" style="color: gray"></span>'; |
|
| 1839 | - } |
|
| 1840 | - else $out.= img_mime($relativepath, $langs->trans('Preview').' '.$file['name']); |
|
| 1841 | - $out.= '</a>'; |
|
| 1842 | - } |
|
| 1843 | - } |
|
| 1844 | - return $out; |
|
| 1845 | - } |
|
| 1407 | + global $user, $conf, $langs, $form; |
|
| 1408 | + global $sortfield, $sortorder; |
|
| 1409 | + global $search_doc_ref; |
|
| 1410 | + |
|
| 1411 | + dol_syslog(get_class($this).'::list_of_autoecmfiles upload_dir='.$upload_dir.' modulepart='.$modulepart); |
|
| 1412 | + |
|
| 1413 | + // Show list of documents |
|
| 1414 | + if (empty($useinecm)) print load_fiche_titre($langs->trans("AttachedFiles")); |
|
| 1415 | + if (empty($url)) $url=$_SERVER["PHP_SELF"]; |
|
| 1416 | + |
|
| 1417 | + if (! empty($addfilterfields)) |
|
| 1418 | + { |
|
| 1419 | + print '<form action="'.$_SERVER['PHP_SELF'].'">'; |
|
| 1420 | + print '<input type="hidden" name="module" value="'.$modulepart.'">'; |
|
| 1421 | + } |
|
| 1422 | + |
|
| 1423 | + print '<div class="div-table-responsive-no-min">'; |
|
| 1424 | + print '<table width="100%" class="noborder">'."\n"; |
|
| 1425 | + |
|
| 1426 | + if (! empty($addfilterfields)) |
|
| 1427 | + { |
|
| 1428 | + print '<tr class="liste_titre nodrag nodrop">'; |
|
| 1429 | + print '<td></td>'; |
|
| 1430 | + print '<td><input type="text" class="maxwidth100onsmartphone" name="search_doc_ref" value="'.dol_escape_htmltag($search_doc_ref).'"></td>'; |
|
| 1431 | + print '<td></td>'; |
|
| 1432 | + print '<td></td>'; |
|
| 1433 | + // Action column |
|
| 1434 | + print '<td class="liste_titre" align="middle">'; |
|
| 1435 | + $searchpicto=$form->showFilterButtons(); |
|
| 1436 | + print $searchpicto; |
|
| 1437 | + print '</td>'; |
|
| 1438 | + print "</tr>\n"; |
|
| 1439 | + } |
|
| 1440 | + |
|
| 1441 | + print '<tr class="liste_titre">'; |
|
| 1442 | + $sortref="fullname"; |
|
| 1443 | + if ($modulepart == 'invoice_supplier') $sortref='level1name'; |
|
| 1444 | + print_liste_field_titre("Ref",$url,$sortref,"",$param,'align="left"',$sortfield,$sortorder); |
|
| 1445 | + print_liste_field_titre("Documents2",$url,"name","",$param,'align="left"',$sortfield,$sortorder); |
|
| 1446 | + print_liste_field_titre("Size",$url,"size","",$param,'align="right"',$sortfield,$sortorder); |
|
| 1447 | + print_liste_field_titre("Date",$url,"date","",$param,'align="center"',$sortfield,$sortorder); |
|
| 1448 | + print_liste_field_titre('','',''); |
|
| 1449 | + print '</tr>'."\n"; |
|
| 1450 | + |
|
| 1451 | + // To show ref or specific information according to view to show (defined by $module) |
|
| 1452 | + if ($modulepart == 'company') |
|
| 1453 | + { |
|
| 1454 | + include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; |
|
| 1455 | + $object_instance=new Societe($this->db); |
|
| 1456 | + } |
|
| 1457 | + else if ($modulepart == 'invoice') |
|
| 1458 | + { |
|
| 1459 | + include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; |
|
| 1460 | + $object_instance=new Facture($this->db); |
|
| 1461 | + } |
|
| 1462 | + else if ($modulepart == 'invoice_supplier') |
|
| 1463 | + { |
|
| 1464 | + include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; |
|
| 1465 | + $object_instance=new FactureFournisseur($this->db); |
|
| 1466 | + } |
|
| 1467 | + else if ($modulepart == 'propal') |
|
| 1468 | + { |
|
| 1469 | + include_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; |
|
| 1470 | + $object_instance=new Propal($this->db); |
|
| 1471 | + } |
|
| 1472 | + else if ($modulepart == 'supplier_proposal') |
|
| 1473 | + { |
|
| 1474 | + include_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php'; |
|
| 1475 | + $object_instance=new SupplierProposal($this->db); |
|
| 1476 | + } |
|
| 1477 | + else if ($modulepart == 'order') |
|
| 1478 | + { |
|
| 1479 | + include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; |
|
| 1480 | + $object_instance=new Commande($this->db); |
|
| 1481 | + } |
|
| 1482 | + else if ($modulepart == 'order_supplier') |
|
| 1483 | + { |
|
| 1484 | + include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php'; |
|
| 1485 | + $object_instance=new CommandeFournisseur($this->db); |
|
| 1486 | + } |
|
| 1487 | + else if ($modulepart == 'contract') |
|
| 1488 | + { |
|
| 1489 | + include_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php'; |
|
| 1490 | + $object_instance=new Contrat($this->db); |
|
| 1491 | + } |
|
| 1492 | + else if ($modulepart == 'product') |
|
| 1493 | + { |
|
| 1494 | + include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; |
|
| 1495 | + $object_instance=new Product($this->db); |
|
| 1496 | + } |
|
| 1497 | + else if ($modulepart == 'tax') |
|
| 1498 | + { |
|
| 1499 | + include_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php'; |
|
| 1500 | + $object_instance=new ChargeSociales($this->db); |
|
| 1501 | + } |
|
| 1502 | + else if ($modulepart == 'project') |
|
| 1503 | + { |
|
| 1504 | + include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; |
|
| 1505 | + $object_instance=new Project($this->db); |
|
| 1506 | + } |
|
| 1507 | + else if ($modulepart == 'fichinter') |
|
| 1508 | + { |
|
| 1509 | + include_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php'; |
|
| 1510 | + $object_instance=new Fichinter($this->db); |
|
| 1511 | + } |
|
| 1512 | + else if ($modulepart == 'user') |
|
| 1513 | + { |
|
| 1514 | + include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; |
|
| 1515 | + $object_instance=new User($this->db); |
|
| 1516 | + } |
|
| 1517 | + else if ($modulepart == 'expensereport') |
|
| 1518 | + { |
|
| 1519 | + include_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php'; |
|
| 1520 | + $object_instance=new ExpenseReport($this->db); |
|
| 1521 | + } |
|
| 1522 | + else if ($modulepart == 'holiday') |
|
| 1523 | + { |
|
| 1524 | + include_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php'; |
|
| 1525 | + $object_instance=new Holiday($this->db); |
|
| 1526 | + } |
|
| 1527 | + |
|
| 1528 | + foreach($filearray as $key => $file) |
|
| 1529 | + { |
|
| 1530 | + if (!is_dir($file['name']) |
|
| 1531 | + && $file['name'] != '.' |
|
| 1532 | + && $file['name'] != '..' |
|
| 1533 | + && $file['name'] != 'CVS' |
|
| 1534 | + && ! preg_match('/\.meta$/i',$file['name'])) |
|
| 1535 | + { |
|
| 1536 | + // Define relative path used to store the file |
|
| 1537 | + $relativefile=preg_replace('/'.preg_quote($upload_dir.'/','/').'/','',$file['fullname']); |
|
| 1538 | + |
|
| 1539 | + //var_dump($file); |
|
| 1540 | + $id=0; $ref=''; $label=''; |
|
| 1541 | + |
|
| 1542 | + // To show ref or specific information according to view to show (defined by $module) |
|
| 1543 | + if ($modulepart == 'company') { preg_match('/(\d+)\/[^\/]+$/',$relativefile,$reg); $id=(isset($reg[1])?$reg[1]:''); } |
|
| 1544 | + if ($modulepart == 'invoice') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); } |
|
| 1545 | + if ($modulepart == 'invoice_supplier') { preg_match('/([^\/]+)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); if (is_numeric($ref)) { $id=$ref; $ref=''; } } // $ref may be also id with old supplier invoices |
|
| 1546 | + if ($modulepart == 'propal') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); } |
|
| 1547 | + if ($modulepart == 'supplier_proposal') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); } |
|
| 1548 | + if ($modulepart == 'order') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); } |
|
| 1549 | + if ($modulepart == 'order_supplier') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); } |
|
| 1550 | + if ($modulepart == 'contract') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); } |
|
| 1551 | + if ($modulepart == 'product') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:''); } |
|
| 1552 | + if ($modulepart == 'tax') { preg_match('/(\d+)\/[^\/]+$/',$relativefile,$reg); $id=(isset($reg[1])?$reg[1]:''); } |
|
| 1553 | + if ($modulepart == 'project') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:'');} |
|
| 1554 | + if ($modulepart == 'fichinter') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:'');} |
|
| 1555 | + if ($modulepart == 'user') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $id=(isset($reg[1])?$reg[1]:'');} |
|
| 1556 | + if ($modulepart == 'expensereport') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=(isset($reg[1])?$reg[1]:'');} |
|
| 1557 | + if ($modulepart == 'holiday') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $id=(isset($reg[1])?$reg[1]:'');} |
|
| 1558 | + |
|
| 1559 | + if (! $id && ! $ref) continue; |
|
| 1560 | + $found=0; |
|
| 1561 | + if (! empty($this->cache_objects[$modulepart.'_'.$id.'_'.$ref])) |
|
| 1562 | + { |
|
| 1563 | + $found=1; |
|
| 1564 | + } |
|
| 1565 | + else |
|
| 1566 | + { |
|
| 1567 | + //print 'Fetch '.$id." - ".$ref.'<br>'; |
|
| 1568 | + |
|
| 1569 | + if ($id) { |
|
| 1570 | + $result = $object_instance->fetch($id); |
|
| 1571 | + } else { |
|
| 1572 | + //fetchOneLike looks for objects with wildcards in its reference. |
|
| 1573 | + //It is useful for those masks who get underscores instead of their actual symbols |
|
| 1574 | + //fetchOneLike requires some info in the object. If it doesn't have it, then 0 is returned |
|
| 1575 | + //that's why we look only look fetchOneLike when fetch returns 0 |
|
| 1576 | + if (!$result = $object_instance->fetch('', $ref)) { |
|
| 1577 | + $result = $object_instance->fetchOneLike($ref); |
|
| 1578 | + } |
|
| 1579 | + } |
|
| 1580 | + |
|
| 1581 | + if ($result > 0) { // Save object into a cache |
|
| 1582 | + $found=1; $this->cache_objects[$modulepart.'_'.$id.'_'.$ref] = clone $object_instance; |
|
| 1583 | + } |
|
| 1584 | + if ($result == 0) { $found=1; $this->cache_objects[$modulepart.'_'.$id.'_'.$ref]='notfound'; unset($filearray[$key]); } |
|
| 1585 | + } |
|
| 1586 | + |
|
| 1587 | + if (! $found > 0 || ! is_object($this->cache_objects[$modulepart.'_'.$id.'_'.$ref])) continue; // We do not show orphelins files |
|
| 1588 | + |
|
| 1589 | + print '<!-- Line list_of_autoecmfiles '.$key.' -->'."\n"; |
|
| 1590 | + print '<tr class="oddeven">'; |
|
| 1591 | + print '<td>'; |
|
| 1592 | + if ($found > 0 && is_object($this->cache_objects[$modulepart.'_'.$id.'_'.$ref])) print $this->cache_objects[$modulepart.'_'.$id.'_'.$ref]->getNomUrl(1,'document'); |
|
| 1593 | + else print $langs->trans("ObjectDeleted",($id?$id:$ref)); |
|
| 1594 | + |
|
| 1595 | + //$modulesubdir=dol_sanitizeFileName($ref); |
|
| 1596 | + $modulesubdir=dirname($relativefile); |
|
| 1597 | + |
|
| 1598 | + //$filedir=$conf->$modulepart->dir_output . '/' . dol_sanitizeFileName($obj->ref); |
|
| 1599 | + $filedir=$file['path']; |
|
| 1600 | + //$urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid; |
|
| 1601 | + //print $formfile->getDocumentsLink($modulepart, $filename, $filedir); |
|
| 1602 | + |
|
| 1603 | + print '</td>'; |
|
| 1604 | + |
|
| 1605 | + // File |
|
| 1606 | + print '<td>'; |
|
| 1607 | + //print "XX".$file['name']; //$file['name'] must be utf8 |
|
| 1608 | + print '<a href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart; |
|
| 1609 | + if ($forcedownload) print '&attachment=1'; |
|
| 1610 | + print '&file='.urlencode($relativefile).'">'; |
|
| 1611 | + print img_mime($file['name'],$file['name'].' ('.dol_print_size($file['size'],0,0).')'); |
|
| 1612 | + print dol_trunc($file['name'],$maxlength,'middle'); |
|
| 1613 | + print '</a>'; |
|
| 1614 | + |
|
| 1615 | + //print $this->getDocumentsLink($modulepart, $modulesubdir, $filedir, '^'.preg_quote($file['name'],'/').'$'); |
|
| 1616 | + print $this->showPreview($file, $modulepart, $file['relativename']); |
|
| 1617 | + |
|
| 1618 | + print "</td>\n"; |
|
| 1619 | + print '<td align="right">'.dol_print_size($file['size'],1,1).'</td>'; |
|
| 1620 | + print '<td align="center">'.dol_print_date($file['date'],"dayhour").'</td>'; |
|
| 1621 | + print '<td align="right">'; |
|
| 1622 | + //if (! empty($useinecm)) print '<a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart; |
|
| 1623 | + //if ($forcedownload) print '&attachment=1'; |
|
| 1624 | + //print '&file='.urlencode($relativefile).'">'; |
|
| 1625 | + //print img_view().'</a> '; |
|
| 1626 | + //if ($permtodelete) print '<a href="'.$url.'?id='.$object->id.'§ion='.$_REQUEST["section"].'&action=delete&urlfile='.urlencode($file['name']).'">'.img_delete().'</a>'; |
|
| 1627 | + //else print ' '; |
|
| 1628 | + print "</td></tr>\n"; |
|
| 1629 | + } |
|
| 1630 | + } |
|
| 1631 | + |
|
| 1632 | + if (count($filearray) == 0) |
|
| 1633 | + { |
|
| 1634 | + print '<tr class="oddeven"><td colspan="5">'; |
|
| 1635 | + if (empty($textifempty)) print $langs->trans("NoFileFound"); |
|
| 1636 | + else print $textifempty; |
|
| 1637 | + print '</td></tr>'; |
|
| 1638 | + } |
|
| 1639 | + print "</table>"; |
|
| 1640 | + print '</div>'; |
|
| 1641 | + |
|
| 1642 | + if (! empty($addfilterfields)) print '</form>'; |
|
| 1643 | + // Fin de zone |
|
| 1644 | + } |
|
| 1645 | + |
|
| 1646 | + /** |
|
| 1647 | + * Show form to upload a new file with jquery fileupload. |
|
| 1648 | + * This form use the fileupload.php file. |
|
| 1649 | + * |
|
| 1650 | + * @param Object $object Object to use |
|
| 1651 | + * @return void |
|
| 1652 | + */ |
|
| 1653 | + private function _formAjaxFileUpload($object) |
|
| 1654 | + { |
|
| 1655 | + global $langs, $conf; |
|
| 1656 | + |
|
| 1657 | + // PHP post_max_size |
|
| 1658 | + $post_max_size = ini_get('post_max_size'); |
|
| 1659 | + $mul_post_max_size = substr($post_max_size, -1); |
|
| 1660 | + $mul_post_max_size = ($mul_post_max_size == 'M' ? 1048576 : ($mul_post_max_size == 'K' ? 1024 : ($mul_post_max_size == 'G' ? 1073741824 : 1))); |
|
| 1661 | + $post_max_size = $mul_post_max_size * (int) $post_max_size; |
|
| 1662 | + // PHP upload_max_filesize |
|
| 1663 | + $upload_max_filesize = ini_get('upload_max_filesize'); |
|
| 1664 | + $mul_upload_max_filesize = substr($upload_max_filesize, -1); |
|
| 1665 | + $mul_upload_max_filesize = ($mul_upload_max_filesize == 'M' ? 1048576 : ($mul_upload_max_filesize == 'K' ? 1024 : ($mul_upload_max_filesize == 'G' ? 1073741824 : 1))); |
|
| 1666 | + $upload_max_filesize = $mul_upload_max_filesize * (int) $upload_max_filesize; |
|
| 1667 | + // Max file size |
|
| 1668 | + $max_file_size = (($post_max_size < $upload_max_filesize) ? $post_max_size : $upload_max_filesize); |
|
| 1669 | + |
|
| 1670 | + // Include main |
|
| 1671 | + include DOL_DOCUMENT_ROOT.'/core/tpl/ajax/fileupload_main.tpl.php'; |
|
| 1672 | + |
|
| 1673 | + // Include template |
|
| 1674 | + include DOL_DOCUMENT_ROOT.'/core/tpl/ajax/fileupload_view.tpl.php'; |
|
| 1675 | + } |
|
| 1676 | + |
|
| 1677 | + /** |
|
| 1678 | + * Show array with linked files |
|
| 1679 | + * |
|
| 1680 | + * @param Object $object Object |
|
| 1681 | + * @param int $permtodelete Deletion is allowed |
|
| 1682 | + * @param string $action Action |
|
| 1683 | + * @param string $selected ??? |
|
| 1684 | + * @param string $param More param to add into URL |
|
| 1685 | + * @return int Number of links |
|
| 1686 | + */ |
|
| 1687 | + public function listOfLinks($object, $permtodelete=1, $action=null, $selected=null, $param='') |
|
| 1688 | + { |
|
| 1689 | + global $user, $conf, $langs, $user; |
|
| 1690 | + global $sortfield, $sortorder; |
|
| 1691 | + |
|
| 1692 | + $langs->load("link"); |
|
| 1693 | + |
|
| 1694 | + require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php'; |
|
| 1695 | + $link = new Link($this->db); |
|
| 1696 | + $links = array(); |
|
| 1697 | + if ($sortfield == "name") { |
|
| 1698 | + $sortfield = "label"; |
|
| 1699 | + } elseif ($sortfield == "date") { |
|
| 1700 | + $sortfield = "datea"; |
|
| 1701 | + } else { |
|
| 1702 | + $sortfield = null; |
|
| 1703 | + } |
|
| 1704 | + $res = $link->fetchAll($links, $object->element, $object->id, $sortfield, $sortorder); |
|
| 1705 | + $param .= (isset($object->id)?'&id=' . $object->id : ''); |
|
| 1706 | + |
|
| 1707 | + // Show list of associated links |
|
| 1708 | + print load_fiche_titre($langs->trans("LinkedFiles")); |
|
| 1709 | + |
|
| 1710 | + print '<form action="' . $_SERVER['PHP_SELF'] . ($param?'?'.$param:'') . '" method="POST">'; |
|
| 1711 | + |
|
| 1712 | + print '<table width="100%" class="liste">'; |
|
| 1713 | + print '<tr class="liste_titre">'; |
|
| 1714 | + print_liste_field_titre( |
|
| 1715 | + $langs->trans("Links"), |
|
| 1716 | + $_SERVER['PHP_SELF'], |
|
| 1717 | + "name", |
|
| 1718 | + "", |
|
| 1719 | + $param, |
|
| 1720 | + 'align="left"', |
|
| 1721 | + $sortfield, |
|
| 1722 | + $sortorder |
|
| 1723 | + ); |
|
| 1724 | + print_liste_field_titre( |
|
| 1725 | + "", |
|
| 1726 | + "", |
|
| 1727 | + "", |
|
| 1728 | + "", |
|
| 1729 | + "", |
|
| 1730 | + 'align="right"' |
|
| 1731 | + ); |
|
| 1732 | + print_liste_field_titre( |
|
| 1733 | + $langs->trans("Date"), |
|
| 1734 | + $_SERVER['PHP_SELF'], |
|
| 1735 | + "date", |
|
| 1736 | + "", |
|
| 1737 | + $param, |
|
| 1738 | + 'align="center"', |
|
| 1739 | + $sortfield, |
|
| 1740 | + $sortorder |
|
| 1741 | + ); |
|
| 1742 | + print_liste_field_titre( |
|
| 1743 | + '', |
|
| 1744 | + $_SERVER['PHP_SELF'], |
|
| 1745 | + "", |
|
| 1746 | + "", |
|
| 1747 | + $param, |
|
| 1748 | + 'align="center"' |
|
| 1749 | + ); |
|
| 1750 | + print_liste_field_titre('','',''); |
|
| 1751 | + print '</tr>'; |
|
| 1752 | + $nboflinks = count($links); |
|
| 1753 | + if ($nboflinks > 0) include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; |
|
| 1754 | + |
|
| 1755 | + foreach ($links as $link) |
|
| 1756 | + { |
|
| 1757 | + print '<tr class="oddeven">'; |
|
| 1758 | + //edit mode |
|
| 1759 | + if ($action == 'update' && $selected === $link->id) |
|
| 1760 | + { |
|
| 1761 | + print '<td>'; |
|
| 1762 | + print '<input type="hidden" name="id" value="' . $object->id . '">'; |
|
| 1763 | + print '<input type="hidden" name="linkid" value="' . $link->id . '">'; |
|
| 1764 | + print '<input type="hidden" name="action" value="confirm_updateline">'; |
|
| 1765 | + print $langs->trans('Link') . ': <input type="text" name="link" value="' . $link->url . '">'; |
|
| 1766 | + print '</td>'; |
|
| 1767 | + print '<td>'; |
|
| 1768 | + print $langs->trans('Label') . ': <input type="text" name="label" value="' . $link->label . '">'; |
|
| 1769 | + print '</td>'; |
|
| 1770 | + print '<td align="center">' . dol_print_date(dol_now(), "dayhour", "tzuser") . '</td>'; |
|
| 1771 | + print '<td align="right"></td>'; |
|
| 1772 | + print '<td align="right">'; |
|
| 1773 | + print '<input type="submit" name="save" class="button" value="' . dol_escape_htmltag($langs->trans('Save')) . '">'; |
|
| 1774 | + print '<input type="submit" name="cancel" class="button" value="' . dol_escape_htmltag($langs->trans('Cancel')) . '">'; |
|
| 1775 | + print '</td>'; |
|
| 1776 | + } |
|
| 1777 | + else |
|
| 1778 | + { |
|
| 1779 | + print '<td>'; |
|
| 1780 | + print img_picto('', 'object_globe').' '; |
|
| 1781 | + print '<a data-ajax="false" href="' . $link->url . '" target="_blank">'; |
|
| 1782 | + print $link->label; |
|
| 1783 | + print '</a>'; |
|
| 1784 | + print '</td>'."\n"; |
|
| 1785 | + print '<td align="right"></td>'; |
|
| 1786 | + print '<td align="center">' . dol_print_date($link->datea, "dayhour", "tzuser") . '</td>'; |
|
| 1787 | + print '<td align="center"></td>'; |
|
| 1788 | + print '<td align="right">'; |
|
| 1789 | + print '<a href="' . $_SERVER['PHP_SELF'] . '?action=update&linkid=' . $link->id . $param . '" class="editfilelink" >' . img_edit() . '</a>'; // id= is included into $param |
|
| 1790 | + if ($permtodelete) { |
|
| 1791 | + print ' <a href="'. $_SERVER['PHP_SELF'] .'?action=delete&linkid=' . $link->id . $param . '" class="deletefilelink">' . img_delete() . '</a>'; // id= is included into $param |
|
| 1792 | + } else { |
|
| 1793 | + print ' '; |
|
| 1794 | + } |
|
| 1795 | + print '</td>'; |
|
| 1796 | + } |
|
| 1797 | + print "</tr>\n"; |
|
| 1798 | + } |
|
| 1799 | + if ($nboflinks == 0) |
|
| 1800 | + { |
|
| 1801 | + print '<tr class="oddeven"><td colspan="5" class="opacitymedium">'; |
|
| 1802 | + print $langs->trans("NoLinkFound"); |
|
| 1803 | + print '</td></tr>'; |
|
| 1804 | + } |
|
| 1805 | + print "</table>"; |
|
| 1806 | + |
|
| 1807 | + print '</form>'; |
|
| 1808 | + |
|
| 1809 | + return $nboflinks; |
|
| 1810 | + } |
|
| 1811 | + |
|
| 1812 | + |
|
| 1813 | + /** |
|
| 1814 | + * Show detail icon with link for preview |
|
| 1815 | + * |
|
| 1816 | + * @param array $file Array with data of file. Example: array('name'=>...) |
|
| 1817 | + * @param string $modulepart propal, facture, facture_fourn, ... |
|
| 1818 | + * @param string $relativepath Relative path of docs |
|
| 1819 | + * @param string $ruleforpicto Rule for picto: 0=Use the generic preview picto, 1=Use the picto of mime type of file) |
|
| 1820 | + * @param string $param More param on http links |
|
| 1821 | + * @return string $out Output string with HTML |
|
| 1822 | + */ |
|
| 1823 | + public function showPreview($file, $modulepart, $relativepath, $ruleforpicto=0, $param='') |
|
| 1824 | + { |
|
| 1825 | + global $langs, $conf; |
|
| 1826 | + |
|
| 1827 | + $out=''; |
|
| 1828 | + if ($conf->browser->layout != 'phone' && ! empty($conf->use_javascript_ajax)) |
|
| 1829 | + { |
|
| 1830 | + $urladvancedpreview=getAdvancedPreviewUrl($modulepart, $relativepath, 1, $param); // Return if a file is qualified for preview. |
|
| 1831 | + if (count($urladvancedpreview)) |
|
| 1832 | + { |
|
| 1833 | + $out.= '<a class="pictopreview '.$urladvancedpreview['css'].'" href="'.$urladvancedpreview['url'].'"'.(empty($urladvancedpreview['mime'])?'':' mime="'.$urladvancedpreview['mime'].'"').' '.(empty($urladvancedpreview['target'])?'':' target="'.$urladvancedpreview['target'].'"').'>'; |
|
| 1834 | + //$out.= '<a class="pictopreview">'; |
|
| 1835 | + if (empty($ruleforpicto)) |
|
| 1836 | + { |
|
| 1837 | + //$out.= img_picto($langs->trans('Preview').' '.$file['name'], 'detail'); |
|
| 1838 | + $out.='<span class="fa fa-search-plus" style="color: gray"></span>'; |
|
| 1839 | + } |
|
| 1840 | + else $out.= img_mime($relativepath, $langs->trans('Preview').' '.$file['name']); |
|
| 1841 | + $out.= '</a>'; |
|
| 1842 | + } |
|
| 1843 | + } |
|
| 1844 | + return $out; |
|
| 1845 | + } |
|
| 1846 | 1846 | } |
@@ -33,110 +33,110 @@ discard block |
||
| 33 | 33 | class FormAccounting extends Form |
| 34 | 34 | { |
| 35 | 35 | |
| 36 | - private $options_cache = array(); |
|
| 36 | + private $options_cache = array(); |
|
| 37 | 37 | |
| 38 | - /** |
|
| 38 | + /** |
|
| 39 | 39 | * @var DoliDB Database handler. |
| 40 | 40 | */ |
| 41 | 41 | public $db; |
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * @var string Error code (or message) |
|
| 45 | - */ |
|
| 46 | - public $error=''; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * Constructor |
|
| 50 | - * |
|
| 51 | - * @param DoliDB $db Database handler |
|
| 52 | - */ |
|
| 53 | - public function __construct($db) |
|
| 54 | - { |
|
| 55 | - $this->db = $db; |
|
| 56 | - } |
|
| 43 | + /** |
|
| 44 | + * @var string Error code (or message) |
|
| 45 | + */ |
|
| 46 | + public $error=''; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * Constructor |
|
| 50 | + * |
|
| 51 | + * @param DoliDB $db Database handler |
|
| 52 | + */ |
|
| 53 | + public function __construct($db) |
|
| 54 | + { |
|
| 55 | + $this->db = $db; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | 58 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
| 59 | - /** |
|
| 60 | - * Return list of journals with label by nature |
|
| 61 | - * |
|
| 62 | - * @param string $selectid Preselected pcg_type |
|
| 63 | - * @param string $htmlname Name of field in html form |
|
| 64 | - * @param int $nature Limit the list to a particular type of journals (1:various operations / 2:sale / 3:purchase / 4:bank / 9: has-new) |
|
| 65 | - * @param int $showempty Add an empty field |
|
| 66 | - * @param int $select_in 0=selectid value is the journal rowid (default) or 1=selectid is journal code |
|
| 67 | - * @param int $select_out Set value returned by select. 0=rowid (default), 1=code |
|
| 68 | - * @param string $morecss More css non HTML object |
|
| 69 | - * @param string $usecache Key to use to store result into a cache. Next call with same key will reuse the cache. |
|
| 70 | - * @param int $disabledajaxcombo Disable ajax combo box. |
|
| 71 | - * @return string String with HTML select |
|
| 72 | - */ |
|
| 73 | - function select_journal($selectid, $htmlname = 'journal', $nature=0, $showempty = 0, $select_in = 0, $select_out = 0, $morecss='maxwidth300 maxwidthonsmartphone', $usecache='', $disabledajaxcombo=0) |
|
| 74 | - { |
|
| 59 | + /** |
|
| 60 | + * Return list of journals with label by nature |
|
| 61 | + * |
|
| 62 | + * @param string $selectid Preselected pcg_type |
|
| 63 | + * @param string $htmlname Name of field in html form |
|
| 64 | + * @param int $nature Limit the list to a particular type of journals (1:various operations / 2:sale / 3:purchase / 4:bank / 9: has-new) |
|
| 65 | + * @param int $showempty Add an empty field |
|
| 66 | + * @param int $select_in 0=selectid value is the journal rowid (default) or 1=selectid is journal code |
|
| 67 | + * @param int $select_out Set value returned by select. 0=rowid (default), 1=code |
|
| 68 | + * @param string $morecss More css non HTML object |
|
| 69 | + * @param string $usecache Key to use to store result into a cache. Next call with same key will reuse the cache. |
|
| 70 | + * @param int $disabledajaxcombo Disable ajax combo box. |
|
| 71 | + * @return string String with HTML select |
|
| 72 | + */ |
|
| 73 | + function select_journal($selectid, $htmlname = 'journal', $nature=0, $showempty = 0, $select_in = 0, $select_out = 0, $morecss='maxwidth300 maxwidthonsmartphone', $usecache='', $disabledajaxcombo=0) |
|
| 74 | + { |
|
| 75 | 75 | // phpcs:enable |
| 76 | - global $conf,$langs; |
|
| 77 | - |
|
| 78 | - $out = ''; |
|
| 79 | - |
|
| 80 | - $options = array(); |
|
| 81 | - if ($usecache && ! empty($this->options_cache[$usecache])) |
|
| 82 | - { |
|
| 83 | - $options = $this->options_cache[$usecache]; |
|
| 84 | - $selected=$selectid; |
|
| 85 | - } |
|
| 86 | - else |
|
| 87 | - { |
|
| 88 | - $sql = "SELECT rowid, code, label, nature, entity, active"; |
|
| 89 | - $sql.= " FROM " . MAIN_DB_PREFIX . "accounting_journal"; |
|
| 90 | - $sql.= " WHERE active = 1"; |
|
| 91 | - $sql.= " AND entity = ".$conf->entity; |
|
| 92 | - //if ($nature && is_numeric($nature)) $sql .= " AND nature = ".$nature; |
|
| 93 | - $sql.= " ORDER BY code"; |
|
| 94 | - |
|
| 95 | - dol_syslog(get_class($this) . "::select_journal", LOG_DEBUG); |
|
| 96 | - $resql = $this->db->query($sql); |
|
| 97 | - |
|
| 98 | - if (!$resql) { |
|
| 99 | - $this->error = "Error ".$this->db->lasterror(); |
|
| 100 | - dol_syslog(get_class($this)."::select_journal ".$this->error, LOG_ERR); |
|
| 101 | - return -1; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - $selected = 0; |
|
| 105 | - $langs->load('accountancy'); |
|
| 106 | - while ($obj = $this->db->fetch_object($resql)) |
|
| 107 | - { |
|
| 108 | - $label = $obj->code . ' - ' . $langs->trans($obj->label); |
|
| 109 | - |
|
| 110 | - $select_value_in = $obj->rowid; |
|
| 111 | - $select_value_out = $obj->rowid; |
|
| 112 | - |
|
| 113 | - // Try to guess if we have found default value |
|
| 114 | - if ($select_in == 1) { |
|
| 115 | - $select_value_in = $obj->code; |
|
| 116 | - } |
|
| 117 | - if ($select_out == 1) { |
|
| 118 | - $select_value_out = $obj->code; |
|
| 119 | - } |
|
| 120 | - // Remember guy's we store in database llx_accounting_bookkeeping the code of accounting_journal and not the rowid |
|
| 121 | - if ($selectid != '' && $selectid == $select_value_in) { |
|
| 122 | - //var_dump("Found ".$selectid." ".$select_value_in); |
|
| 123 | - $selected = $select_value_out; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - $options[$select_value_out] = $label; |
|
| 127 | - } |
|
| 128 | - $this->db->free($resql); |
|
| 129 | - |
|
| 130 | - if ($usecache) |
|
| 131 | - { |
|
| 132 | - $this->options_cache[$usecache] = $options; |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - $out .= Form::selectarray($htmlname, $options, $selected, $showempty, 0, 0, '', 0, 0, 0, '', $morecss, ($disabledajaxcombo?0:1)); |
|
| 137 | - |
|
| 138 | - return $out; |
|
| 139 | - } |
|
| 76 | + global $conf,$langs; |
|
| 77 | + |
|
| 78 | + $out = ''; |
|
| 79 | + |
|
| 80 | + $options = array(); |
|
| 81 | + if ($usecache && ! empty($this->options_cache[$usecache])) |
|
| 82 | + { |
|
| 83 | + $options = $this->options_cache[$usecache]; |
|
| 84 | + $selected=$selectid; |
|
| 85 | + } |
|
| 86 | + else |
|
| 87 | + { |
|
| 88 | + $sql = "SELECT rowid, code, label, nature, entity, active"; |
|
| 89 | + $sql.= " FROM " . MAIN_DB_PREFIX . "accounting_journal"; |
|
| 90 | + $sql.= " WHERE active = 1"; |
|
| 91 | + $sql.= " AND entity = ".$conf->entity; |
|
| 92 | + //if ($nature && is_numeric($nature)) $sql .= " AND nature = ".$nature; |
|
| 93 | + $sql.= " ORDER BY code"; |
|
| 94 | + |
|
| 95 | + dol_syslog(get_class($this) . "::select_journal", LOG_DEBUG); |
|
| 96 | + $resql = $this->db->query($sql); |
|
| 97 | + |
|
| 98 | + if (!$resql) { |
|
| 99 | + $this->error = "Error ".$this->db->lasterror(); |
|
| 100 | + dol_syslog(get_class($this)."::select_journal ".$this->error, LOG_ERR); |
|
| 101 | + return -1; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + $selected = 0; |
|
| 105 | + $langs->load('accountancy'); |
|
| 106 | + while ($obj = $this->db->fetch_object($resql)) |
|
| 107 | + { |
|
| 108 | + $label = $obj->code . ' - ' . $langs->trans($obj->label); |
|
| 109 | + |
|
| 110 | + $select_value_in = $obj->rowid; |
|
| 111 | + $select_value_out = $obj->rowid; |
|
| 112 | + |
|
| 113 | + // Try to guess if we have found default value |
|
| 114 | + if ($select_in == 1) { |
|
| 115 | + $select_value_in = $obj->code; |
|
| 116 | + } |
|
| 117 | + if ($select_out == 1) { |
|
| 118 | + $select_value_out = $obj->code; |
|
| 119 | + } |
|
| 120 | + // Remember guy's we store in database llx_accounting_bookkeeping the code of accounting_journal and not the rowid |
|
| 121 | + if ($selectid != '' && $selectid == $select_value_in) { |
|
| 122 | + //var_dump("Found ".$selectid." ".$select_value_in); |
|
| 123 | + $selected = $select_value_out; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + $options[$select_value_out] = $label; |
|
| 127 | + } |
|
| 128 | + $this->db->free($resql); |
|
| 129 | + |
|
| 130 | + if ($usecache) |
|
| 131 | + { |
|
| 132 | + $this->options_cache[$usecache] = $options; |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + $out .= Form::selectarray($htmlname, $options, $selected, $showempty, 0, 0, '', 0, 0, 0, '', $morecss, ($disabledajaxcombo?0:1)); |
|
| 137 | + |
|
| 138 | + return $out; |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | 141 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
| 142 | 142 | /** |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | $sql = "SELECT c.rowid, c.label as type, c.range_account"; |
| 168 | 168 | $sql.= " FROM ".MAIN_DB_PREFIX."c_accounting_category as c"; |
| 169 | 169 | $sql.= " WHERE c.active = 1"; |
| 170 | - $sql.= " AND c.category_type = 0"; |
|
| 170 | + $sql.= " AND c.category_type = 0"; |
|
| 171 | 171 | if (empty($allcountries)) $sql.= " AND c.fk_country = ".$mysoc->country_id; |
| 172 | 172 | $sql.= " ORDER BY c.label ASC"; |
| 173 | 173 | } |
@@ -176,8 +176,8 @@ discard block |
||
| 176 | 176 | $sql = "SELECT c.rowid, c.label as type, c.range_account"; |
| 177 | 177 | $sql.= " FROM ".MAIN_DB_PREFIX."c_accounting_category as c, ".MAIN_DB_PREFIX."c_country as co"; |
| 178 | 178 | $sql.= " WHERE c.active = 1"; |
| 179 | - $sql.= " AND c.category_type = 0"; |
|
| 180 | - $sql.= " AND c.fk_country = co.rowid"; |
|
| 179 | + $sql.= " AND c.category_type = 0"; |
|
| 180 | + $sql.= " AND c.fk_country = co.rowid"; |
|
| 181 | 181 | if (empty($allcountries)) $sql.= " AND co.code = '".$mysoc->country_code."'"; |
| 182 | 182 | $sql.= " ORDER BY c.label ASC"; |
| 183 | 183 | } |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | $out .= '<option value="'.$obj->rowid.'"'; |
| 200 | 200 | if ($obj->rowid == $selected) $out .= ' selected'; |
| 201 | 201 | $out .= '>'.($maxlen ? dol_trunc($obj->type,$maxlen) : $obj->type); |
| 202 | - $out .= ' ('.$obj->range_account.')'; |
|
| 202 | + $out .= ' ('.$obj->range_account.')'; |
|
| 203 | 203 | $i++; |
| 204 | 204 | } |
| 205 | 205 | $out .= '</select>'; |
@@ -221,231 +221,231 @@ discard block |
||
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
| 224 | - /** |
|
| 225 | - * Return select filter with date of transaction |
|
| 226 | - * |
|
| 227 | - * @param string $htmlname Name of select field |
|
| 228 | - * @param string $selectedkey Value |
|
| 229 | - * @return string HTML edit field |
|
| 230 | - */ |
|
| 224 | + /** |
|
| 225 | + * Return select filter with date of transaction |
|
| 226 | + * |
|
| 227 | + * @param string $htmlname Name of select field |
|
| 228 | + * @param string $selectedkey Value |
|
| 229 | + * @return string HTML edit field |
|
| 230 | + */ |
|
| 231 | 231 | function select_bookkeeping_importkey($htmlname = 'importkey', $selectedkey = '') |
| 232 | 232 | { |
| 233 | 233 | // phpcs:enable |
| 234 | - $options = array(); |
|
| 234 | + $options = array(); |
|
| 235 | 235 | |
| 236 | - $sql = 'SELECT DISTINCT import_key from ' . MAIN_DB_PREFIX . 'accounting_bookkeeping'; |
|
| 237 | - $sql .= " WHERE entity IN (".getEntity('accountancy').")"; |
|
| 238 | - $sql .= ' ORDER BY import_key DESC'; |
|
| 236 | + $sql = 'SELECT DISTINCT import_key from ' . MAIN_DB_PREFIX . 'accounting_bookkeeping'; |
|
| 237 | + $sql .= " WHERE entity IN (".getEntity('accountancy').")"; |
|
| 238 | + $sql .= ' ORDER BY import_key DESC'; |
|
| 239 | 239 | |
| 240 | - dol_syslog(get_class($this) . "::select_bookkeeping_importkey", LOG_DEBUG); |
|
| 241 | - $resql = $this->db->query($sql); |
|
| 240 | + dol_syslog(get_class($this) . "::select_bookkeeping_importkey", LOG_DEBUG); |
|
| 241 | + $resql = $this->db->query($sql); |
|
| 242 | 242 | |
| 243 | - if (!$resql) { |
|
| 244 | - $this->error = "Error " . $this->db->lasterror(); |
|
| 245 | - dol_syslog(get_class($this) . "::select_bookkeeping_importkey " . $this->error, LOG_ERR); |
|
| 246 | - return - 1; |
|
| 247 | - } |
|
| 243 | + if (!$resql) { |
|
| 244 | + $this->error = "Error " . $this->db->lasterror(); |
|
| 245 | + dol_syslog(get_class($this) . "::select_bookkeeping_importkey " . $this->error, LOG_ERR); |
|
| 246 | + return - 1; |
|
| 247 | + } |
|
| 248 | 248 | |
| 249 | - while ($obj = $this->db->fetch_object($resql)) { |
|
| 250 | - $options[$obj->import_key] = dol_print_date($obj->import_key, 'dayhourtext'); |
|
| 251 | - } |
|
| 249 | + while ($obj = $this->db->fetch_object($resql)) { |
|
| 250 | + $options[$obj->import_key] = dol_print_date($obj->import_key, 'dayhourtext'); |
|
| 251 | + } |
|
| 252 | 252 | |
| 253 | - return Form::selectarray($htmlname, $options, $selectedkey); |
|
| 254 | - } |
|
| 253 | + return Form::selectarray($htmlname, $options, $selectedkey); |
|
| 254 | + } |
|
| 255 | 255 | |
| 256 | 256 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
| 257 | - /** |
|
| 258 | - * Return list of accounts with label by chart of accounts |
|
| 259 | - * |
|
| 260 | - * @param string $selectid Preselected id or code of accounting accounts (depends on $select_in) |
|
| 261 | - * @param string $htmlname Name of HTML field id. If name start with '.', it is name of HTML css class, so several component with same name in different forms can be used. |
|
| 262 | - * @param int $showempty 1=Add an empty field, 2=Add an empty field+'None' field |
|
| 263 | - * @param array $event Event options |
|
| 264 | - * @param int $select_in 0=selectid value is a aa.rowid (default) or 1=selectid is aa.account_number |
|
| 265 | - * @param int $select_out Set value returned by select. 0=rowid (default), 1=account_number |
|
| 266 | - * @param string $morecss More css non HTML object |
|
| 267 | - * @param string $usecache Key to use to store result into a cache. Next call with same key will reuse the cache. |
|
| 268 | - * @return string String with HTML select |
|
| 269 | - */ |
|
| 270 | - function select_account($selectid, $htmlname = 'account', $showempty = 0, $event = array(), $select_in = 0, $select_out = 0, $morecss='maxwidth300 maxwidthonsmartphone', $usecache='') |
|
| 271 | - { |
|
| 257 | + /** |
|
| 258 | + * Return list of accounts with label by chart of accounts |
|
| 259 | + * |
|
| 260 | + * @param string $selectid Preselected id or code of accounting accounts (depends on $select_in) |
|
| 261 | + * @param string $htmlname Name of HTML field id. If name start with '.', it is name of HTML css class, so several component with same name in different forms can be used. |
|
| 262 | + * @param int $showempty 1=Add an empty field, 2=Add an empty field+'None' field |
|
| 263 | + * @param array $event Event options |
|
| 264 | + * @param int $select_in 0=selectid value is a aa.rowid (default) or 1=selectid is aa.account_number |
|
| 265 | + * @param int $select_out Set value returned by select. 0=rowid (default), 1=account_number |
|
| 266 | + * @param string $morecss More css non HTML object |
|
| 267 | + * @param string $usecache Key to use to store result into a cache. Next call with same key will reuse the cache. |
|
| 268 | + * @return string String with HTML select |
|
| 269 | + */ |
|
| 270 | + function select_account($selectid, $htmlname = 'account', $showempty = 0, $event = array(), $select_in = 0, $select_out = 0, $morecss='maxwidth300 maxwidthonsmartphone', $usecache='') |
|
| 271 | + { |
|
| 272 | 272 | // phpcs:enable |
| 273 | - global $conf, $langs; |
|
| 274 | - |
|
| 275 | - require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php'; |
|
| 276 | - |
|
| 277 | - $out = ''; |
|
| 278 | - |
|
| 279 | - $options = array(); |
|
| 280 | - if ($usecache && ! empty($this->options_cache[$usecache])) |
|
| 281 | - { |
|
| 282 | - $options = $this->options_cache[$usecache]; |
|
| 283 | - $selected=$selectid; |
|
| 284 | - } |
|
| 285 | - else |
|
| 286 | - { |
|
| 287 | - $trunclength = empty($conf->global->ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT) ? 50 : $conf->global->ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT; |
|
| 288 | - |
|
| 289 | - $sql = "SELECT DISTINCT aa.account_number, aa.label, aa.rowid, aa.fk_pcg_version"; |
|
| 290 | - $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa"; |
|
| 291 | - $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; |
|
| 292 | - $sql .= " AND asy.rowid = " . $conf->global->CHARTOFACCOUNTS; |
|
| 293 | - $sql .= " AND aa.active = 1"; |
|
| 294 | - $sql .= " AND aa.entity=".$conf->entity; |
|
| 295 | - $sql .= " ORDER BY aa.account_number"; |
|
| 296 | - |
|
| 297 | - dol_syslog(get_class($this) . "::select_account", LOG_DEBUG); |
|
| 298 | - $resql = $this->db->query($sql); |
|
| 299 | - |
|
| 300 | - if (!$resql) { |
|
| 301 | - $this->error = "Error " . $this->db->lasterror(); |
|
| 302 | - dol_syslog(get_class($this) . "::select_account " . $this->error, LOG_ERR); |
|
| 303 | - return -1; |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - $selected = 0; |
|
| 307 | - while ($obj = $this->db->fetch_object($resql)) |
|
| 308 | - { |
|
| 309 | - $label = length_accountg($obj->account_number) . ' - ' . $obj->label; |
|
| 310 | - $label = dol_trunc($label, $trunclength); |
|
| 311 | - |
|
| 312 | - $select_value_in = $obj->rowid; |
|
| 313 | - $select_value_out = $obj->rowid; |
|
| 314 | - |
|
| 315 | - // Try to guess if we have found default value |
|
| 316 | - if ($select_in == 1) { |
|
| 317 | - $select_value_in = $obj->account_number; |
|
| 318 | - } |
|
| 319 | - if ($select_out == 1) { |
|
| 320 | - $select_value_out = $obj->account_number; |
|
| 321 | - } |
|
| 322 | - // Remember guy's we store in database llx_facturedet the rowid of accounting_account and not the account_number |
|
| 323 | - // Because same account_number can be share between different accounting_system and do have the same meaning |
|
| 324 | - if ($selectid != '' && $selectid == $select_value_in) { |
|
| 325 | - //var_dump("Found ".$selectid." ".$select_value_in); |
|
| 326 | - $selected = $select_value_out; |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - $options[$select_value_out] = $label; |
|
| 330 | - } |
|
| 331 | - $this->db->free($resql); |
|
| 332 | - |
|
| 333 | - if ($usecache) |
|
| 334 | - { |
|
| 273 | + global $conf, $langs; |
|
| 274 | + |
|
| 275 | + require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php'; |
|
| 276 | + |
|
| 277 | + $out = ''; |
|
| 278 | + |
|
| 279 | + $options = array(); |
|
| 280 | + if ($usecache && ! empty($this->options_cache[$usecache])) |
|
| 281 | + { |
|
| 282 | + $options = $this->options_cache[$usecache]; |
|
| 283 | + $selected=$selectid; |
|
| 284 | + } |
|
| 285 | + else |
|
| 286 | + { |
|
| 287 | + $trunclength = empty($conf->global->ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT) ? 50 : $conf->global->ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT; |
|
| 288 | + |
|
| 289 | + $sql = "SELECT DISTINCT aa.account_number, aa.label, aa.rowid, aa.fk_pcg_version"; |
|
| 290 | + $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa"; |
|
| 291 | + $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; |
|
| 292 | + $sql .= " AND asy.rowid = " . $conf->global->CHARTOFACCOUNTS; |
|
| 293 | + $sql .= " AND aa.active = 1"; |
|
| 294 | + $sql .= " AND aa.entity=".$conf->entity; |
|
| 295 | + $sql .= " ORDER BY aa.account_number"; |
|
| 296 | + |
|
| 297 | + dol_syslog(get_class($this) . "::select_account", LOG_DEBUG); |
|
| 298 | + $resql = $this->db->query($sql); |
|
| 299 | + |
|
| 300 | + if (!$resql) { |
|
| 301 | + $this->error = "Error " . $this->db->lasterror(); |
|
| 302 | + dol_syslog(get_class($this) . "::select_account " . $this->error, LOG_ERR); |
|
| 303 | + return -1; |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + $selected = 0; |
|
| 307 | + while ($obj = $this->db->fetch_object($resql)) |
|
| 308 | + { |
|
| 309 | + $label = length_accountg($obj->account_number) . ' - ' . $obj->label; |
|
| 310 | + $label = dol_trunc($label, $trunclength); |
|
| 311 | + |
|
| 312 | + $select_value_in = $obj->rowid; |
|
| 313 | + $select_value_out = $obj->rowid; |
|
| 314 | + |
|
| 315 | + // Try to guess if we have found default value |
|
| 316 | + if ($select_in == 1) { |
|
| 317 | + $select_value_in = $obj->account_number; |
|
| 318 | + } |
|
| 319 | + if ($select_out == 1) { |
|
| 320 | + $select_value_out = $obj->account_number; |
|
| 321 | + } |
|
| 322 | + // Remember guy's we store in database llx_facturedet the rowid of accounting_account and not the account_number |
|
| 323 | + // Because same account_number can be share between different accounting_system and do have the same meaning |
|
| 324 | + if ($selectid != '' && $selectid == $select_value_in) { |
|
| 325 | + //var_dump("Found ".$selectid." ".$select_value_in); |
|
| 326 | + $selected = $select_value_out; |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + $options[$select_value_out] = $label; |
|
| 330 | + } |
|
| 331 | + $this->db->free($resql); |
|
| 332 | + |
|
| 333 | + if ($usecache) |
|
| 334 | + { |
|
| 335 | 335 | $this->options_cache[$usecache] = $options; |
| 336 | - } |
|
| 337 | - } |
|
| 336 | + } |
|
| 337 | + } |
|
| 338 | 338 | |
| 339 | - if ($showempty == 2) |
|
| 340 | - { |
|
| 341 | - $options['0'] = $langs->trans("None"); |
|
| 342 | - } |
|
| 339 | + if ($showempty == 2) |
|
| 340 | + { |
|
| 341 | + $options['0'] = $langs->trans("None"); |
|
| 342 | + } |
|
| 343 | 343 | |
| 344 | - $out .= Form::selectarray($htmlname, $options, $selected, ($showempty > 0 ? 1 : 0), 0, 0, '', 0, 0, 0, '', $morecss, 1); |
|
| 344 | + $out .= Form::selectarray($htmlname, $options, $selected, ($showempty > 0 ? 1 : 0), 0, 0, '', 0, 0, 0, '', $morecss, 1); |
|
| 345 | 345 | |
| 346 | - return $out; |
|
| 347 | - } |
|
| 346 | + return $out; |
|
| 347 | + } |
|
| 348 | 348 | |
| 349 | 349 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
| 350 | - /** |
|
| 351 | - * Return list of auxilary thirdparty accounts |
|
| 352 | - * |
|
| 353 | - * @param string $selectid Preselected pcg_type |
|
| 354 | - * @param string $htmlname Name of field in html form |
|
| 355 | - * @param int $showempty Add an empty field |
|
| 356 | - * @param string $morecss More css |
|
| 357 | - * @return string String with HTML select |
|
| 358 | - */ |
|
| 350 | + /** |
|
| 351 | + * Return list of auxilary thirdparty accounts |
|
| 352 | + * |
|
| 353 | + * @param string $selectid Preselected pcg_type |
|
| 354 | + * @param string $htmlname Name of field in html form |
|
| 355 | + * @param int $showempty Add an empty field |
|
| 356 | + * @param string $morecss More css |
|
| 357 | + * @return string String with HTML select |
|
| 358 | + */ |
|
| 359 | 359 | function select_auxaccount($selectid, $htmlname='account_num_aux', $showempty=0, $morecss='maxwidth200') |
| 360 | 360 | { |
| 361 | 361 | // phpcs:enable |
| 362 | 362 | |
| 363 | - $aux_account = array(); |
|
| 364 | - |
|
| 365 | - // Auxiliary customer account |
|
| 366 | - $sql = "SELECT DISTINCT code_compta, nom "; |
|
| 367 | - $sql .= " FROM ".MAIN_DB_PREFIX."societe"; |
|
| 368 | - $sql .= " WHERE entity IN (" . getEntity('societe') . ")"; |
|
| 369 | - $sql .= " ORDER BY code_compta"; |
|
| 370 | - dol_syslog(get_class($this)."::select_auxaccount", LOG_DEBUG); |
|
| 371 | - $resql = $this->db->query($sql); |
|
| 372 | - if ($resql) { |
|
| 373 | - while ($obj = $this->db->fetch_object($resql)) { |
|
| 374 | - if (!empty($obj->code_compta)) { |
|
| 375 | - $aux_account[$obj->code_compta] = $obj->code_compta.' ('.$obj->nom.')'; |
|
| 376 | - } |
|
| 377 | - } |
|
| 378 | - } else { |
|
| 379 | - $this->error = "Error ".$this->db->lasterror(); |
|
| 380 | - dol_syslog(get_class($this)."::select_pcgsubtype ".$this->error, LOG_ERR); |
|
| 381 | - return -1; |
|
| 382 | - } |
|
| 383 | - $this->db->free($resql); |
|
| 384 | - |
|
| 385 | - // Auxiliary supplier account |
|
| 386 | - $sql = "SELECT DISTINCT code_compta_fournisseur, nom "; |
|
| 387 | - $sql .= " FROM ".MAIN_DB_PREFIX."societe"; |
|
| 388 | - $sql .= " WHERE entity IN (" . getEntity('societe') . ")"; |
|
| 389 | - $sql .= " ORDER BY code_compta_fournisseur"; |
|
| 390 | - dol_syslog(get_class($this)."::select_auxaccount", LOG_DEBUG); |
|
| 391 | - $resql = $this->db->query($sql); |
|
| 392 | - if ($resql) { |
|
| 393 | - while ($obj = $this->db->fetch_object($resql)) { |
|
| 394 | - if (!empty($obj->code_compta_fournisseur)) { |
|
| 395 | - $aux_account[$obj->code_compta_fournisseur] = $obj->code_compta_fournisseur.' ('.$obj->nom.')'; |
|
| 396 | - } |
|
| 397 | - } |
|
| 398 | - } else { |
|
| 399 | - $this->error = "Error ".$this->db->lasterror(); |
|
| 400 | - dol_syslog(get_class($this)."::select_pcgsubtype ".$this->error, LOG_ERR); |
|
| 401 | - return -1; |
|
| 402 | - } |
|
| 403 | - $this->db->free($resql); |
|
| 404 | - |
|
| 405 | - // Build select |
|
| 406 | - $out .= Form::selectarray($htmlname, $aux_account, $selectid, $showempty, 0, 0, '', 0, 0, 0, '', $morecss, 1); |
|
| 407 | - |
|
| 408 | - return $out; |
|
| 409 | - } |
|
| 363 | + $aux_account = array(); |
|
| 364 | + |
|
| 365 | + // Auxiliary customer account |
|
| 366 | + $sql = "SELECT DISTINCT code_compta, nom "; |
|
| 367 | + $sql .= " FROM ".MAIN_DB_PREFIX."societe"; |
|
| 368 | + $sql .= " WHERE entity IN (" . getEntity('societe') . ")"; |
|
| 369 | + $sql .= " ORDER BY code_compta"; |
|
| 370 | + dol_syslog(get_class($this)."::select_auxaccount", LOG_DEBUG); |
|
| 371 | + $resql = $this->db->query($sql); |
|
| 372 | + if ($resql) { |
|
| 373 | + while ($obj = $this->db->fetch_object($resql)) { |
|
| 374 | + if (!empty($obj->code_compta)) { |
|
| 375 | + $aux_account[$obj->code_compta] = $obj->code_compta.' ('.$obj->nom.')'; |
|
| 376 | + } |
|
| 377 | + } |
|
| 378 | + } else { |
|
| 379 | + $this->error = "Error ".$this->db->lasterror(); |
|
| 380 | + dol_syslog(get_class($this)."::select_pcgsubtype ".$this->error, LOG_ERR); |
|
| 381 | + return -1; |
|
| 382 | + } |
|
| 383 | + $this->db->free($resql); |
|
| 384 | + |
|
| 385 | + // Auxiliary supplier account |
|
| 386 | + $sql = "SELECT DISTINCT code_compta_fournisseur, nom "; |
|
| 387 | + $sql .= " FROM ".MAIN_DB_PREFIX."societe"; |
|
| 388 | + $sql .= " WHERE entity IN (" . getEntity('societe') . ")"; |
|
| 389 | + $sql .= " ORDER BY code_compta_fournisseur"; |
|
| 390 | + dol_syslog(get_class($this)."::select_auxaccount", LOG_DEBUG); |
|
| 391 | + $resql = $this->db->query($sql); |
|
| 392 | + if ($resql) { |
|
| 393 | + while ($obj = $this->db->fetch_object($resql)) { |
|
| 394 | + if (!empty($obj->code_compta_fournisseur)) { |
|
| 395 | + $aux_account[$obj->code_compta_fournisseur] = $obj->code_compta_fournisseur.' ('.$obj->nom.')'; |
|
| 396 | + } |
|
| 397 | + } |
|
| 398 | + } else { |
|
| 399 | + $this->error = "Error ".$this->db->lasterror(); |
|
| 400 | + dol_syslog(get_class($this)."::select_pcgsubtype ".$this->error, LOG_ERR); |
|
| 401 | + return -1; |
|
| 402 | + } |
|
| 403 | + $this->db->free($resql); |
|
| 404 | + |
|
| 405 | + // Build select |
|
| 406 | + $out .= Form::selectarray($htmlname, $aux_account, $selectid, $showempty, 0, 0, '', 0, 0, 0, '', $morecss, 1); |
|
| 407 | + |
|
| 408 | + return $out; |
|
| 409 | + } |
|
| 410 | 410 | |
| 411 | 411 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
| 412 | - /** |
|
| 413 | - * Return HTML combo list of years existing into book keepping |
|
| 414 | - * |
|
| 415 | - * @param string $selected Preselected value |
|
| 416 | - * @param string $htmlname Name of HTML select object |
|
| 417 | - * @param int $useempty Affiche valeur vide dans liste |
|
| 418 | - * @param string $output_format (html/opton (for option html only)/array (to return options arrays |
|
| 419 | - * @return string/array |
|
| 420 | - */ |
|
| 421 | - function selectyear_accountancy_bookkepping($selected = '', $htmlname = 'yearid', $useempty = 0, $output_format = 'html') |
|
| 422 | - { |
|
| 412 | + /** |
|
| 413 | + * Return HTML combo list of years existing into book keepping |
|
| 414 | + * |
|
| 415 | + * @param string $selected Preselected value |
|
| 416 | + * @param string $htmlname Name of HTML select object |
|
| 417 | + * @param int $useempty Affiche valeur vide dans liste |
|
| 418 | + * @param string $output_format (html/opton (for option html only)/array (to return options arrays |
|
| 419 | + * @return string/array |
|
| 420 | + */ |
|
| 421 | + function selectyear_accountancy_bookkepping($selected = '', $htmlname = 'yearid', $useempty = 0, $output_format = 'html') |
|
| 422 | + { |
|
| 423 | 423 | // phpcs:enable |
| 424 | - global $conf; |
|
| 425 | - |
|
| 426 | - $out_array = array(); |
|
| 427 | - |
|
| 428 | - $sql = "SELECT DISTINCT date_format(doc_date,'%Y') as dtyear"; |
|
| 429 | - $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping"; |
|
| 430 | - $sql .= " WHERE entity IN (" . getEntity('accountancy') . ")"; |
|
| 431 | - $sql .= " ORDER BY date_format(doc_date,'%Y')"; |
|
| 432 | - dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG); |
|
| 433 | - $resql = $this->db->query($sql); |
|
| 434 | - |
|
| 435 | - if (!$resql) { |
|
| 436 | - $this->error = "Error ".$this->db->lasterror(); |
|
| 437 | - dol_syslog(get_class($this)."::".__METHOD__.$this->error, LOG_ERR); |
|
| 438 | - return -1; |
|
| 439 | - } |
|
| 440 | - while ($obj = $this->db->fetch_object($resql)) { |
|
| 441 | - $out_array[$obj->dtyear] = $obj->dtyear; |
|
| 442 | - } |
|
| 443 | - $this->db->free($resql); |
|
| 444 | - |
|
| 445 | - if ($output_format == 'html') { |
|
| 446 | - return Form::selectarray($htmlname, $out_array, $selected, $useempty, 0, 0, 'placeholder="aa"'); |
|
| 447 | - } else { |
|
| 448 | - return $out_array; |
|
| 449 | - } |
|
| 450 | - } |
|
| 424 | + global $conf; |
|
| 425 | + |
|
| 426 | + $out_array = array(); |
|
| 427 | + |
|
| 428 | + $sql = "SELECT DISTINCT date_format(doc_date,'%Y') as dtyear"; |
|
| 429 | + $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping"; |
|
| 430 | + $sql .= " WHERE entity IN (" . getEntity('accountancy') . ")"; |
|
| 431 | + $sql .= " ORDER BY date_format(doc_date,'%Y')"; |
|
| 432 | + dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG); |
|
| 433 | + $resql = $this->db->query($sql); |
|
| 434 | + |
|
| 435 | + if (!$resql) { |
|
| 436 | + $this->error = "Error ".$this->db->lasterror(); |
|
| 437 | + dol_syslog(get_class($this)."::".__METHOD__.$this->error, LOG_ERR); |
|
| 438 | + return -1; |
|
| 439 | + } |
|
| 440 | + while ($obj = $this->db->fetch_object($resql)) { |
|
| 441 | + $out_array[$obj->dtyear] = $obj->dtyear; |
|
| 442 | + } |
|
| 443 | + $this->db->free($resql); |
|
| 444 | + |
|
| 445 | + if ($output_format == 'html') { |
|
| 446 | + return Form::selectarray($htmlname, $out_array, $selected, $useempty, 0, 0, 'placeholder="aa"'); |
|
| 447 | + } else { |
|
| 448 | + return $out_array; |
|
| 449 | + } |
|
| 450 | + } |
|
| 451 | 451 | } |
@@ -61,226 +61,226 @@ |
||
| 61 | 61 | */ |
| 62 | 62 | abstract class CommonStickerGenerator |
| 63 | 63 | { |
| 64 | - public $code; // Code of format |
|
| 64 | + public $code; // Code of format |
|
| 65 | 65 | |
| 66 | - /** |
|
| 66 | + /** |
|
| 67 | 67 | * @var array format Array with informations |
| 68 | 68 | */ |
| 69 | 69 | public $format; |
| 70 | 70 | |
| 71 | - // protected |
|
| 72 | - var $_Avery_Name = ''; // Nom du format de l'etiquette |
|
| 73 | - var $_Margin_Left = 0; // Marge de gauche de l'etiquette |
|
| 74 | - var $_Margin_Top = 0; // marge en haut de la page avant la premiere etiquette |
|
| 75 | - var $_X_Space = 0; // Espace horizontal entre 2 bandes d'etiquettes |
|
| 76 | - var $_Y_Space = 0; // Espace vertical entre 2 bandes d'etiquettes |
|
| 77 | - var $_X_Number = 0; // NX Nombre d'etiquettes sur la largeur de la page |
|
| 78 | - var $_Y_Number = 0; // NY Nombre d'etiquettes sur la hauteur de la page |
|
| 79 | - var $_Width = 0; // Largeur de chaque etiquette |
|
| 80 | - var $_Height = 0; // Hauteur de chaque etiquette |
|
| 81 | - var $_Char_Size = 10; // Hauteur des caracteres |
|
| 82 | - var $_Line_Height = 10; // Hauteur par defaut d'une ligne |
|
| 83 | - var $_Metric = 'mm'; // Type of metric.. Will help to calculate good values |
|
| 84 | - var $_Metric_Doc = 'mm'; // Type of metric for the doc.. |
|
| 85 | - var $_COUNTX = 1; |
|
| 86 | - var $_COUNTY = 1; |
|
| 87 | - var $_First = 1; |
|
| 88 | - var $Tformat; |
|
| 71 | + // protected |
|
| 72 | + var $_Avery_Name = ''; // Nom du format de l'etiquette |
|
| 73 | + var $_Margin_Left = 0; // Marge de gauche de l'etiquette |
|
| 74 | + var $_Margin_Top = 0; // marge en haut de la page avant la premiere etiquette |
|
| 75 | + var $_X_Space = 0; // Espace horizontal entre 2 bandes d'etiquettes |
|
| 76 | + var $_Y_Space = 0; // Espace vertical entre 2 bandes d'etiquettes |
|
| 77 | + var $_X_Number = 0; // NX Nombre d'etiquettes sur la largeur de la page |
|
| 78 | + var $_Y_Number = 0; // NY Nombre d'etiquettes sur la hauteur de la page |
|
| 79 | + var $_Width = 0; // Largeur de chaque etiquette |
|
| 80 | + var $_Height = 0; // Hauteur de chaque etiquette |
|
| 81 | + var $_Char_Size = 10; // Hauteur des caracteres |
|
| 82 | + var $_Line_Height = 10; // Hauteur par defaut d'une ligne |
|
| 83 | + var $_Metric = 'mm'; // Type of metric.. Will help to calculate good values |
|
| 84 | + var $_Metric_Doc = 'mm'; // Type of metric for the doc.. |
|
| 85 | + var $_COUNTX = 1; |
|
| 86 | + var $_COUNTY = 1; |
|
| 87 | + var $_First = 1; |
|
| 88 | + var $Tformat; |
|
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * Constructor |
|
| 92 | - * |
|
| 93 | - * @param DoliDB $db Database handler |
|
| 94 | - */ |
|
| 95 | - function __construct($db) |
|
| 96 | - { |
|
| 97 | - $this->db = $db; |
|
| 98 | - } |
|
| 90 | + /** |
|
| 91 | + * Constructor |
|
| 92 | + * |
|
| 93 | + * @param DoliDB $db Database handler |
|
| 94 | + */ |
|
| 95 | + function __construct($db) |
|
| 96 | + { |
|
| 97 | + $this->db = $db; |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | 100 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
| 101 | - /** |
|
| 102 | - * Function to build PDF on disk, then output on HTTP strem. |
|
| 103 | - * |
|
| 104 | - * @param array $arrayofrecords Array of record informations (array('textleft'=>,'textheader'=>, ..., 'id'=>,'photo'=>) |
|
| 105 | - * @param Translate $outputlangs Lang object for output language |
|
| 106 | - * @param string $srctemplatepath Full path of source filename for generator using a template file |
|
| 107 | - * @param string $outputdir Output directory for pdf file |
|
| 108 | - * @return int 1=OK, 0=KO |
|
| 109 | - */ |
|
| 110 | - abstract function write_file($arrayofrecords,$outputlangs,$srctemplatepath,$outputdir=''); |
|
| 101 | + /** |
|
| 102 | + * Function to build PDF on disk, then output on HTTP strem. |
|
| 103 | + * |
|
| 104 | + * @param array $arrayofrecords Array of record informations (array('textleft'=>,'textheader'=>, ..., 'id'=>,'photo'=>) |
|
| 105 | + * @param Translate $outputlangs Lang object for output language |
|
| 106 | + * @param string $srctemplatepath Full path of source filename for generator using a template file |
|
| 107 | + * @param string $outputdir Output directory for pdf file |
|
| 108 | + * @return int 1=OK, 0=KO |
|
| 109 | + */ |
|
| 110 | + abstract function write_file($arrayofrecords,$outputlangs,$srctemplatepath,$outputdir=''); |
|
| 111 | 111 | // phpcs:enable |
| 112 | 112 | |
| 113 | - /** |
|
| 114 | - * Output a sticker on page at position _COUNTX, _COUNTY (_COUNTX and _COUNTY start from 0) |
|
| 115 | - * |
|
| 116 | - * @param PDF $pdf PDF reference |
|
| 117 | - * @param Translate $outputlangs Output langs |
|
| 118 | - * @param array $param Associative array containing label content and optional parameters |
|
| 119 | - * @return void |
|
| 120 | - */ |
|
| 121 | - abstract function addSticker(&$pdf,$outputlangs,$param); |
|
| 113 | + /** |
|
| 114 | + * Output a sticker on page at position _COUNTX, _COUNTY (_COUNTX and _COUNTY start from 0) |
|
| 115 | + * |
|
| 116 | + * @param PDF $pdf PDF reference |
|
| 117 | + * @param Translate $outputlangs Output langs |
|
| 118 | + * @param array $param Associative array containing label content and optional parameters |
|
| 119 | + * @return void |
|
| 120 | + */ |
|
| 121 | + abstract function addSticker(&$pdf,$outputlangs,$param); |
|
| 122 | 122 | |
| 123 | 123 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
| 124 | - /** |
|
| 125 | - * Methode qui permet de modifier la taille des caracteres |
|
| 126 | - * Cela modiera aussi l'espace entre chaque ligne |
|
| 127 | - * |
|
| 128 | - * @param PDF $pdf PDF reference |
|
| 129 | - * @param int $pt point |
|
| 130 | - * @return void |
|
| 131 | - */ |
|
| 132 | - function Set_Char_Size(&$pdf,$pt) |
|
| 133 | - { |
|
| 124 | + /** |
|
| 125 | + * Methode qui permet de modifier la taille des caracteres |
|
| 126 | + * Cela modiera aussi l'espace entre chaque ligne |
|
| 127 | + * |
|
| 128 | + * @param PDF $pdf PDF reference |
|
| 129 | + * @param int $pt point |
|
| 130 | + * @return void |
|
| 131 | + */ |
|
| 132 | + function Set_Char_Size(&$pdf,$pt) |
|
| 133 | + { |
|
| 134 | 134 | // phpcs:enable |
| 135 | - if ($pt > 3) { |
|
| 136 | - $this->_Char_Size = $pt; |
|
| 137 | - $this->_Line_Height = $this->_Get_Height_Chars($pt); |
|
| 138 | - $pdf->SetFont('','',$pt); |
|
| 139 | - } |
|
| 140 | - } |
|
| 135 | + if ($pt > 3) { |
|
| 136 | + $this->_Char_Size = $pt; |
|
| 137 | + $this->_Line_Height = $this->_Get_Height_Chars($pt); |
|
| 138 | + $pdf->SetFont('','',$pt); |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | 142 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
| 143 | - /** |
|
| 144 | - * protected Print dot line |
|
| 145 | - * |
|
| 146 | - * @param PDF $pdf PDF reference |
|
| 147 | - * @param int $x1 X1 |
|
| 148 | - * @param int $y1 Y1 |
|
| 149 | - * @param int $x2 X2 |
|
| 150 | - * @param int $y2 Y2 |
|
| 151 | - * @param int $epaisseur Epaisseur |
|
| 152 | - * @param int $nbPointilles Nb pointilles |
|
| 153 | - * @return void |
|
| 154 | - */ |
|
| 143 | + /** |
|
| 144 | + * protected Print dot line |
|
| 145 | + * |
|
| 146 | + * @param PDF $pdf PDF reference |
|
| 147 | + * @param int $x1 X1 |
|
| 148 | + * @param int $y1 Y1 |
|
| 149 | + * @param int $x2 X2 |
|
| 150 | + * @param int $y2 Y2 |
|
| 151 | + * @param int $epaisseur Epaisseur |
|
| 152 | + * @param int $nbPointilles Nb pointilles |
|
| 153 | + * @return void |
|
| 154 | + */ |
|
| 155 | 155 | function _Pointille(&$pdf,$x1=0,$y1=0,$x2=210,$y2=297,$epaisseur=1,$nbPointilles=15) |
| 156 | - { |
|
| 156 | + { |
|
| 157 | 157 | // phpcs:enable |
| 158 | - $pdf->SetLineWidth($epaisseur); |
|
| 159 | - $length=abs($x1-$x2); |
|
| 160 | - $hauteur=abs($y1-$y2); |
|
| 161 | - if($length>$hauteur) { |
|
| 162 | - $Pointilles=($length/$nbPointilles)/2; // taille des pointilles |
|
| 163 | - } |
|
| 164 | - else { |
|
| 165 | - $Pointilles=($hauteur/$nbPointilles)/2; |
|
| 166 | - } |
|
| 167 | - for($i=$x1;$i<=$x2;$i+=$Pointilles+$Pointilles) { |
|
| 168 | - for($j=$i;$j<=($i+$Pointilles);$j++) { |
|
| 169 | - if($j<=($x2-1)) { |
|
| 170 | - $pdf->Line($j,$y1,$j+1,$y1); // on trace le pointill? du haut, point par point |
|
| 171 | - $pdf->Line($j,$y2,$j+1,$y2); // on trace le pointill? du bas, point par point |
|
| 172 | - } |
|
| 173 | - } |
|
| 174 | - } |
|
| 175 | - for($i=$y1;$i<=$y2;$i+=$Pointilles+$Pointilles) { |
|
| 176 | - for($j=$i;$j<=($i+$Pointilles);$j++) { |
|
| 177 | - if($j<=($y2-1)) { |
|
| 178 | - $pdf->Line($x1,$j,$x1,$j+1); // on trace le pointill? du haut, point par point |
|
| 179 | - $pdf->Line($x2,$j,$x2,$j+1); // on trace le pointill? du bas, point par point |
|
| 180 | - } |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - } |
|
| 158 | + $pdf->SetLineWidth($epaisseur); |
|
| 159 | + $length=abs($x1-$x2); |
|
| 160 | + $hauteur=abs($y1-$y2); |
|
| 161 | + if($length>$hauteur) { |
|
| 162 | + $Pointilles=($length/$nbPointilles)/2; // taille des pointilles |
|
| 163 | + } |
|
| 164 | + else { |
|
| 165 | + $Pointilles=($hauteur/$nbPointilles)/2; |
|
| 166 | + } |
|
| 167 | + for($i=$x1;$i<=$x2;$i+=$Pointilles+$Pointilles) { |
|
| 168 | + for($j=$i;$j<=($i+$Pointilles);$j++) { |
|
| 169 | + if($j<=($x2-1)) { |
|
| 170 | + $pdf->Line($j,$y1,$j+1,$y1); // on trace le pointill? du haut, point par point |
|
| 171 | + $pdf->Line($j,$y2,$j+1,$y2); // on trace le pointill? du bas, point par point |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | + } |
|
| 175 | + for($i=$y1;$i<=$y2;$i+=$Pointilles+$Pointilles) { |
|
| 176 | + for($j=$i;$j<=($i+$Pointilles);$j++) { |
|
| 177 | + if($j<=($y2-1)) { |
|
| 178 | + $pdf->Line($x1,$j,$x1,$j+1); // on trace le pointill? du haut, point par point |
|
| 179 | + $pdf->Line($x2,$j,$x2,$j+1); // on trace le pointill? du bas, point par point |
|
| 180 | + } |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + } |
|
| 184 | 184 | |
| 185 | 185 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
| 186 | - /** |
|
| 187 | - * protected Function realisant une croix aux 4 coins des cartes |
|
| 188 | - * |
|
| 189 | - * @param PDF $pdf PDF reference |
|
| 190 | - * @param int $x1 X1 |
|
| 191 | - * @param int $y1 Y1 |
|
| 192 | - * @param int $x2 X2 |
|
| 193 | - * @param int $y2 Y2 |
|
| 194 | - * @param int $epaisseur Epaisseur |
|
| 195 | - * @param int $taille Size |
|
| 196 | - * @return void |
|
| 197 | - */ |
|
| 198 | - function _Croix(&$pdf,$x1=0,$y1=0,$x2=210,$y2=297,$epaisseur=1,$taille=4) |
|
| 199 | - { |
|
| 186 | + /** |
|
| 187 | + * protected Function realisant une croix aux 4 coins des cartes |
|
| 188 | + * |
|
| 189 | + * @param PDF $pdf PDF reference |
|
| 190 | + * @param int $x1 X1 |
|
| 191 | + * @param int $y1 Y1 |
|
| 192 | + * @param int $x2 X2 |
|
| 193 | + * @param int $y2 Y2 |
|
| 194 | + * @param int $epaisseur Epaisseur |
|
| 195 | + * @param int $taille Size |
|
| 196 | + * @return void |
|
| 197 | + */ |
|
| 198 | + function _Croix(&$pdf,$x1=0,$y1=0,$x2=210,$y2=297,$epaisseur=1,$taille=4) |
|
| 199 | + { |
|
| 200 | 200 | // phpcs:enable |
| 201 | - $pdf->SetDrawColor(192,192,192); |
|
| 201 | + $pdf->SetDrawColor(192,192,192); |
|
| 202 | 202 | |
| 203 | - $pdf->SetLineWidth($epaisseur); |
|
| 204 | - $lg=$taille/2; |
|
| 205 | - // croix haut gauche |
|
| 206 | - $pdf->Line($x1,$y1-$lg,$x1,$y1+$lg); |
|
| 207 | - $pdf->Line($x1-$lg,$y1,$x1+$lg,$y1); |
|
| 208 | - // croix bas gauche |
|
| 209 | - $pdf->Line($x1,$y2-$lg,$x1,$y2+$lg); |
|
| 210 | - $pdf->Line($x1-$lg,$y2,$x1+$lg,$y2); |
|
| 211 | - // croix haut droit |
|
| 212 | - $pdf->Line($x2,$y1-$lg,$x2,$y1+$lg); |
|
| 213 | - $pdf->Line($x2-$lg,$y1,$x2+$lg,$y1); |
|
| 214 | - // croix bas droit |
|
| 215 | - $pdf->Line($x2,$y2-$lg,$x2,$y2+$lg); |
|
| 216 | - $pdf->Line($x2-$lg,$y2,$x2+$lg,$y2); |
|
| 203 | + $pdf->SetLineWidth($epaisseur); |
|
| 204 | + $lg=$taille/2; |
|
| 205 | + // croix haut gauche |
|
| 206 | + $pdf->Line($x1,$y1-$lg,$x1,$y1+$lg); |
|
| 207 | + $pdf->Line($x1-$lg,$y1,$x1+$lg,$y1); |
|
| 208 | + // croix bas gauche |
|
| 209 | + $pdf->Line($x1,$y2-$lg,$x1,$y2+$lg); |
|
| 210 | + $pdf->Line($x1-$lg,$y2,$x1+$lg,$y2); |
|
| 211 | + // croix haut droit |
|
| 212 | + $pdf->Line($x2,$y1-$lg,$x2,$y1+$lg); |
|
| 213 | + $pdf->Line($x2-$lg,$y1,$x2+$lg,$y1); |
|
| 214 | + // croix bas droit |
|
| 215 | + $pdf->Line($x2,$y2-$lg,$x2,$y2+$lg); |
|
| 216 | + $pdf->Line($x2-$lg,$y2,$x2+$lg,$y2); |
|
| 217 | 217 | |
| 218 | - $pdf->SetDrawColor(0,0,0); |
|
| 219 | - } |
|
| 218 | + $pdf->SetDrawColor(0,0,0); |
|
| 219 | + } |
|
| 220 | 220 | |
| 221 | - /** |
|
| 222 | - * Convert units (in to mm, mm to in) |
|
| 223 | - * $src and $dest must be 'in' or 'mm' |
|
| 224 | - * |
|
| 225 | - * @param int $value value |
|
| 226 | - * @param string $src from ('in' or 'mm') |
|
| 227 | - * @param string $dest to ('in' or 'mm') |
|
| 228 | - * @return float value value after conversion |
|
| 229 | - */ |
|
| 230 | - private function convertMetric($value, $src, $dest) |
|
| 231 | - { |
|
| 232 | - if ($src != $dest) { |
|
| 233 | - $tab = array( |
|
| 234 | - 'in'=>39.37008, |
|
| 235 | - 'mm'=>1000 |
|
| 236 | - ); |
|
| 237 | - return $value * $tab[$dest] / $tab[$src]; |
|
| 238 | - } |
|
| 221 | + /** |
|
| 222 | + * Convert units (in to mm, mm to in) |
|
| 223 | + * $src and $dest must be 'in' or 'mm' |
|
| 224 | + * |
|
| 225 | + * @param int $value value |
|
| 226 | + * @param string $src from ('in' or 'mm') |
|
| 227 | + * @param string $dest to ('in' or 'mm') |
|
| 228 | + * @return float value value after conversion |
|
| 229 | + */ |
|
| 230 | + private function convertMetric($value, $src, $dest) |
|
| 231 | + { |
|
| 232 | + if ($src != $dest) { |
|
| 233 | + $tab = array( |
|
| 234 | + 'in'=>39.37008, |
|
| 235 | + 'mm'=>1000 |
|
| 236 | + ); |
|
| 237 | + return $value * $tab[$dest] / $tab[$src]; |
|
| 238 | + } |
|
| 239 | 239 | |
| 240 | - return $value; |
|
| 241 | - } |
|
| 240 | + return $value; |
|
| 241 | + } |
|
| 242 | 242 | |
| 243 | 243 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
| 244 | - /** |
|
| 245 | - * protected Give the height for a char size given. |
|
| 246 | - * |
|
| 247 | - * @param int $pt Point |
|
| 248 | - * @return int Height chars |
|
| 249 | - */ |
|
| 250 | - function _Get_Height_Chars($pt) |
|
| 251 | - { |
|
| 244 | + /** |
|
| 245 | + * protected Give the height for a char size given. |
|
| 246 | + * |
|
| 247 | + * @param int $pt Point |
|
| 248 | + * @return int Height chars |
|
| 249 | + */ |
|
| 250 | + function _Get_Height_Chars($pt) |
|
| 251 | + { |
|
| 252 | 252 | // phpcs:enable |
| 253 | - // Tableau de concordance entre la hauteur des caracteres et de l'espacement entre les lignes |
|
| 254 | - $_Table_Hauteur_Chars = array(6=>2, 7=>2.5, 8=>3, 9=>3.5, 10=>4, 11=>6, 12=>7, 13=>8, 14=>9, 15=>10); |
|
| 255 | - if (in_array($pt, array_keys($_Table_Hauteur_Chars))) { |
|
| 256 | - return $_Table_Hauteur_Chars[$pt]; |
|
| 257 | - } else { |
|
| 258 | - return 100; // There is a prob.. |
|
| 259 | - } |
|
| 260 | - } |
|
| 253 | + // Tableau de concordance entre la hauteur des caracteres et de l'espacement entre les lignes |
|
| 254 | + $_Table_Hauteur_Chars = array(6=>2, 7=>2.5, 8=>3, 9=>3.5, 10=>4, 11=>6, 12=>7, 13=>8, 14=>9, 15=>10); |
|
| 255 | + if (in_array($pt, array_keys($_Table_Hauteur_Chars))) { |
|
| 256 | + return $_Table_Hauteur_Chars[$pt]; |
|
| 257 | + } else { |
|
| 258 | + return 100; // There is a prob.. |
|
| 259 | + } |
|
| 260 | + } |
|
| 261 | 261 | |
| 262 | 262 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
| 263 | - /** |
|
| 264 | - * protected Set format |
|
| 265 | - * |
|
| 266 | - * @param PDF $pdf PDF reference |
|
| 267 | - * @param string $format Format |
|
| 268 | - * @return void |
|
| 269 | - */ |
|
| 270 | - function _Set_Format(&$pdf, $format) |
|
| 271 | - { |
|
| 263 | + /** |
|
| 264 | + * protected Set format |
|
| 265 | + * |
|
| 266 | + * @param PDF $pdf PDF reference |
|
| 267 | + * @param string $format Format |
|
| 268 | + * @return void |
|
| 269 | + */ |
|
| 270 | + function _Set_Format(&$pdf, $format) |
|
| 271 | + { |
|
| 272 | 272 | // phpcs:enable |
| 273 | - $this->_Metric = $format['metric']; |
|
| 274 | - $this->_Avery_Name = $format['name']; |
|
| 275 | - $this->_Avery_Code = $format['code']; |
|
| 276 | - $this->_Margin_Left = $this->convertMetric($format['marginLeft'], $this->_Metric, $this->_Metric_Doc); |
|
| 277 | - $this->_Margin_Top = $this->convertMetric($format['marginTop'], $this->_Metric, $this->_Metric_Doc); |
|
| 278 | - $this->_X_Space = $this->convertMetric($format['SpaceX'], $this->_Metric, $this->_Metric_Doc); |
|
| 279 | - $this->_Y_Space = $this->convertMetric($format['SpaceY'], $this->_Metric, $this->_Metric_Doc); |
|
| 280 | - $this->_X_Number = $format['NX']; |
|
| 281 | - $this->_Y_Number = $format['NY']; |
|
| 282 | - $this->_Width = $this->convertMetric($format['width'], $this->_Metric, $this->_Metric_Doc); |
|
| 283 | - $this->_Height = $this->convertMetric($format['height'], $this->_Metric, $this->_Metric_Doc); |
|
| 284 | - $this->Set_Char_Size($pdf, $format['font-size']); |
|
| 285 | - } |
|
| 273 | + $this->_Metric = $format['metric']; |
|
| 274 | + $this->_Avery_Name = $format['name']; |
|
| 275 | + $this->_Avery_Code = $format['code']; |
|
| 276 | + $this->_Margin_Left = $this->convertMetric($format['marginLeft'], $this->_Metric, $this->_Metric_Doc); |
|
| 277 | + $this->_Margin_Top = $this->convertMetric($format['marginTop'], $this->_Metric, $this->_Metric_Doc); |
|
| 278 | + $this->_X_Space = $this->convertMetric($format['SpaceX'], $this->_Metric, $this->_Metric_Doc); |
|
| 279 | + $this->_Y_Space = $this->convertMetric($format['SpaceY'], $this->_Metric, $this->_Metric_Doc); |
|
| 280 | + $this->_X_Number = $format['NX']; |
|
| 281 | + $this->_Y_Number = $format['NY']; |
|
| 282 | + $this->_Width = $this->convertMetric($format['width'], $this->_Metric, $this->_Metric_Doc); |
|
| 283 | + $this->_Height = $this->convertMetric($format['height'], $this->_Metric, $this->_Metric_Doc); |
|
| 284 | + $this->Set_Char_Size($pdf, $format['font-size']); |
|
| 285 | + } |
|
| 286 | 286 | } |
@@ -27,26 +27,26 @@ discard block |
||
| 27 | 27 | */ |
| 28 | 28 | class FormSocialContrib |
| 29 | 29 | { |
| 30 | - /** |
|
| 30 | + /** |
|
| 31 | 31 | * @var DoliDB Database handler. |
| 32 | 32 | */ |
| 33 | 33 | public $db; |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @var string Error code (or message) |
|
| 37 | - */ |
|
| 38 | - public $error=''; |
|
| 35 | + /** |
|
| 36 | + * @var string Error code (or message) |
|
| 37 | + */ |
|
| 38 | + public $error=''; |
|
| 39 | 39 | |
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Constructor |
|
| 43 | - * |
|
| 44 | - * @param DoliDB $db Database handler |
|
| 45 | - */ |
|
| 46 | - public function __construct($db) |
|
| 47 | - { |
|
| 48 | - $this->db = $db; |
|
| 49 | - } |
|
| 41 | + /** |
|
| 42 | + * Constructor |
|
| 43 | + * |
|
| 44 | + * @param DoliDB $db Database handler |
|
| 45 | + */ |
|
| 46 | + public function __construct($db) |
|
| 47 | + { |
|
| 48 | + $this->db = $db; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | 51 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
| 52 | 52 | /** |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | $num = $db->num_rows($resql); |
| 97 | 97 | if ($num) |
| 98 | 98 | { |
| 99 | - print '<select class="'.($morecss?$morecss:'').'" id="'.$htmlname.'" name="'.$htmlname.'">'; |
|
| 99 | + print '<select class="'.($morecss?$morecss:'').'" id="'.$htmlname.'" name="'.$htmlname.'">'; |
|
| 100 | 100 | $i = 0; |
| 101 | 101 | |
| 102 | 102 | if ($useempty) print '<option value="0"> </option>'; |
@@ -32,38 +32,38 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | class Ccountry // extends CommonObject |
| 34 | 34 | { |
| 35 | - /** |
|
| 35 | + /** |
|
| 36 | 36 | * @var DoliDB Database handler. |
| 37 | 37 | */ |
| 38 | 38 | public $db; |
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @var string Error code (or message) |
|
| 42 | - */ |
|
| 43 | - public $error=''; |
|
| 40 | + /** |
|
| 41 | + * @var string Error code (or message) |
|
| 42 | + */ |
|
| 43 | + public $error=''; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @var string[] Error codes (or messages) |
|
| 47 | - */ |
|
| 48 | - public $errors = array(); |
|
| 45 | + /** |
|
| 46 | + * @var string[] Error codes (or messages) |
|
| 47 | + */ |
|
| 48 | + public $errors = array(); |
|
| 49 | 49 | |
| 50 | - //var $element='ccountry'; //!< Id that identify managed objects |
|
| 51 | - //var $table_element='ccountry'; //!< Name of table without prefix where object is stored |
|
| 50 | + //var $element='ccountry'; //!< Id that identify managed objects |
|
| 51 | + //var $table_element='ccountry'; //!< Name of table without prefix where object is stored |
|
| 52 | 52 | |
| 53 | 53 | /** |
| 54 | - * @var int ID |
|
| 55 | - */ |
|
| 56 | - public $id; |
|
| 54 | + * @var int ID |
|
| 55 | + */ |
|
| 56 | + public $id; |
|
| 57 | 57 | |
| 58 | - public $code; |
|
| 59 | - public $code_iso; |
|
| 58 | + public $code; |
|
| 59 | + public $code_iso; |
|
| 60 | 60 | |
| 61 | - /** |
|
| 61 | + /** |
|
| 62 | 62 | * @var string Countries label |
| 63 | 63 | */ |
| 64 | 64 | public $label; |
| 65 | 65 | |
| 66 | - public $active; |
|
| 66 | + public $active; |
|
| 67 | 67 | |
| 68 | 68 | |
| 69 | 69 | |
@@ -88,73 +88,73 @@ discard block |
||
| 88 | 88 | */ |
| 89 | 89 | function create($user, $notrigger=0) |
| 90 | 90 | { |
| 91 | - global $conf, $langs; |
|
| 92 | - $error=0; |
|
| 91 | + global $conf, $langs; |
|
| 92 | + $error=0; |
|
| 93 | 93 | |
| 94 | - // Clean parameters |
|
| 95 | - if (isset($this->code)) $this->code=trim($this->code); |
|
| 96 | - if (isset($this->code_iso)) $this->code_iso=trim($this->code_iso); |
|
| 97 | - if (isset($this->label)) $this->label=trim($this->label); |
|
| 98 | - if (isset($this->active)) $this->active=trim($this->active); |
|
| 94 | + // Clean parameters |
|
| 95 | + if (isset($this->code)) $this->code=trim($this->code); |
|
| 96 | + if (isset($this->code_iso)) $this->code_iso=trim($this->code_iso); |
|
| 97 | + if (isset($this->label)) $this->label=trim($this->label); |
|
| 98 | + if (isset($this->active)) $this->active=trim($this->active); |
|
| 99 | 99 | |
| 100 | - // Check parameters |
|
| 101 | - // Put here code to add control on parameters values |
|
| 100 | + // Check parameters |
|
| 101 | + // Put here code to add control on parameters values |
|
| 102 | 102 | |
| 103 | 103 | // Insert request |
| 104 | - $sql = "INSERT INTO ".MAIN_DB_PREFIX."c_country("; |
|
| 105 | - $sql.= "rowid,"; |
|
| 106 | - $sql.= "code,"; |
|
| 107 | - $sql.= "code_iso,"; |
|
| 108 | - $sql.= "label,"; |
|
| 109 | - $sql.= "active"; |
|
| 104 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX."c_country("; |
|
| 105 | + $sql.= "rowid,"; |
|
| 106 | + $sql.= "code,"; |
|
| 107 | + $sql.= "code_iso,"; |
|
| 108 | + $sql.= "label,"; |
|
| 109 | + $sql.= "active"; |
|
| 110 | 110 | $sql.= ") VALUES ("; |
| 111 | - $sql.= " ".(! isset($this->rowid)?'NULL':"'".$this->db->escape($this->rowid)."'").","; |
|
| 112 | - $sql.= " ".(! isset($this->code)?'NULL':"'".$this->db->escape($this->code)."'").","; |
|
| 113 | - $sql.= " ".(! isset($this->code_iso)?'NULL':"'".$this->db->escape($this->code_iso)."'").","; |
|
| 114 | - $sql.= " ".(! isset($this->label)?'NULL':"'".$this->db->escape($this->label)."'").","; |
|
| 115 | - $sql.= " ".(! isset($this->active)?'NULL':"'".$this->db->escape($this->active)."'").""; |
|
| 116 | - $sql.= ")"; |
|
| 111 | + $sql.= " ".(! isset($this->rowid)?'NULL':"'".$this->db->escape($this->rowid)."'").","; |
|
| 112 | + $sql.= " ".(! isset($this->code)?'NULL':"'".$this->db->escape($this->code)."'").","; |
|
| 113 | + $sql.= " ".(! isset($this->code_iso)?'NULL':"'".$this->db->escape($this->code_iso)."'").","; |
|
| 114 | + $sql.= " ".(! isset($this->label)?'NULL':"'".$this->db->escape($this->label)."'").","; |
|
| 115 | + $sql.= " ".(! isset($this->active)?'NULL':"'".$this->db->escape($this->active)."'").""; |
|
| 116 | + $sql.= ")"; |
|
| 117 | 117 | |
| 118 | - $this->db->begin(); |
|
| 118 | + $this->db->begin(); |
|
| 119 | 119 | |
| 120 | - dol_syslog(get_class($this)."::create", LOG_DEBUG); |
|
| 120 | + dol_syslog(get_class($this)."::create", LOG_DEBUG); |
|
| 121 | 121 | $resql=$this->db->query($sql); |
| 122 | - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
| 122 | + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
| 123 | 123 | |
| 124 | - if (! $error) |
|
| 124 | + if (! $error) |
|
| 125 | 125 | { |
| 126 | 126 | $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."c_country"); |
| 127 | 127 | |
| 128 | - if (! $notrigger) |
|
| 129 | - { |
|
| 130 | - // Uncomment this and change MYOBJECT to your own tag if you |
|
| 131 | - // want this action call a trigger. |
|
| 132 | - |
|
| 133 | - //// Call triggers |
|
| 134 | - //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
| 135 | - //$interface=new Interfaces($this->db); |
|
| 136 | - //$result=$interface->run_triggers('MYOBJECT_CREATE',$this,$user,$langs,$conf); |
|
| 137 | - //if ($result < 0) { $error++; $this->errors=$interface->errors; } |
|
| 138 | - //// End call triggers |
|
| 139 | - } |
|
| 128 | + if (! $notrigger) |
|
| 129 | + { |
|
| 130 | + // Uncomment this and change MYOBJECT to your own tag if you |
|
| 131 | + // want this action call a trigger. |
|
| 132 | + |
|
| 133 | + //// Call triggers |
|
| 134 | + //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
| 135 | + //$interface=new Interfaces($this->db); |
|
| 136 | + //$result=$interface->run_triggers('MYOBJECT_CREATE',$this,$user,$langs,$conf); |
|
| 137 | + //if ($result < 0) { $error++; $this->errors=$interface->errors; } |
|
| 138 | + //// End call triggers |
|
| 139 | + } |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | // Commit or rollback |
| 143 | 143 | if ($error) |
| 144 | - { |
|
| 145 | - foreach($this->errors as $errmsg) |
|
| 146 | - { |
|
| 147 | - dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR); |
|
| 148 | - $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
| 149 | - } |
|
| 150 | - $this->db->rollback(); |
|
| 151 | - return -1*$error; |
|
| 152 | - } |
|
| 153 | - else |
|
| 154 | - { |
|
| 155 | - $this->db->commit(); |
|
| 144 | + { |
|
| 145 | + foreach($this->errors as $errmsg) |
|
| 146 | + { |
|
| 147 | + dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR); |
|
| 148 | + $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
| 149 | + } |
|
| 150 | + $this->db->rollback(); |
|
| 151 | + return -1*$error; |
|
| 152 | + } |
|
| 153 | + else |
|
| 154 | + { |
|
| 155 | + $this->db->commit(); |
|
| 156 | 156 | return $this->id; |
| 157 | - } |
|
| 157 | + } |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | |
@@ -167,18 +167,18 @@ discard block |
||
| 167 | 167 | */ |
| 168 | 168 | function fetch($id,$code='') |
| 169 | 169 | { |
| 170 | - global $langs; |
|
| 170 | + global $langs; |
|
| 171 | 171 | $sql = "SELECT"; |
| 172 | - $sql.= " t.rowid,"; |
|
| 173 | - $sql.= " t.code,"; |
|
| 174 | - $sql.= " t.code_iso,"; |
|
| 175 | - $sql.= " t.label,"; |
|
| 176 | - $sql.= " t.active"; |
|
| 172 | + $sql.= " t.rowid,"; |
|
| 173 | + $sql.= " t.code,"; |
|
| 174 | + $sql.= " t.code_iso,"; |
|
| 175 | + $sql.= " t.label,"; |
|
| 176 | + $sql.= " t.active"; |
|
| 177 | 177 | $sql.= " FROM ".MAIN_DB_PREFIX."c_country as t"; |
| 178 | 178 | if ($id) $sql.= " WHERE t.rowid = ".$id; |
| 179 | 179 | elseif ($code) $sql.= " WHERE t.code = '".$this->db->escape($code)."'"; |
| 180 | 180 | |
| 181 | - dol_syslog(get_class($this)."::fetch", LOG_DEBUG); |
|
| 181 | + dol_syslog(get_class($this)."::fetch", LOG_DEBUG); |
|
| 182 | 182 | $resql=$this->db->query($sql); |
| 183 | 183 | if ($resql) |
| 184 | 184 | { |
@@ -187,10 +187,10 @@ discard block |
||
| 187 | 187 | $obj = $this->db->fetch_object($resql); |
| 188 | 188 | |
| 189 | 189 | $this->id = $obj->rowid; |
| 190 | - $this->code = $obj->code; |
|
| 191 | - $this->code_iso = $obj->code_iso; |
|
| 192 | - $this->label = $obj->label; |
|
| 193 | - $this->active = $obj->active; |
|
| 190 | + $this->code = $obj->code; |
|
| 191 | + $this->code_iso = $obj->code_iso; |
|
| 192 | + $this->label = $obj->label; |
|
| 193 | + $this->active = $obj->active; |
|
| 194 | 194 | |
| 195 | 195 | $this->db->free($resql); |
| 196 | 196 | return 1; |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | } |
| 202 | 202 | else |
| 203 | 203 | { |
| 204 | - $this->error="Error ".$this->db->lasterror(); |
|
| 204 | + $this->error="Error ".$this->db->lasterror(); |
|
| 205 | 205 | return -1; |
| 206 | 206 | } |
| 207 | 207 | } |
@@ -216,120 +216,120 @@ discard block |
||
| 216 | 216 | */ |
| 217 | 217 | function update($user=null, $notrigger=0) |
| 218 | 218 | { |
| 219 | - global $conf, $langs; |
|
| 220 | - $error=0; |
|
| 219 | + global $conf, $langs; |
|
| 220 | + $error=0; |
|
| 221 | 221 | |
| 222 | - // Clean parameters |
|
| 223 | - if (isset($this->code)) $this->code=trim($this->code); |
|
| 224 | - if (isset($this->code_iso)) $this->code_iso=trim($this->code_iso); |
|
| 225 | - if (isset($this->label)) $this->label=trim($this->label); |
|
| 226 | - if (isset($this->active)) $this->active=trim($this->active); |
|
| 222 | + // Clean parameters |
|
| 223 | + if (isset($this->code)) $this->code=trim($this->code); |
|
| 224 | + if (isset($this->code_iso)) $this->code_iso=trim($this->code_iso); |
|
| 225 | + if (isset($this->label)) $this->label=trim($this->label); |
|
| 226 | + if (isset($this->active)) $this->active=trim($this->active); |
|
| 227 | 227 | |
| 228 | 228 | |
| 229 | - // Check parameters |
|
| 230 | - // Put here code to add control on parameters values |
|
| 229 | + // Check parameters |
|
| 230 | + // Put here code to add control on parameters values |
|
| 231 | 231 | |
| 232 | 232 | // Update request |
| 233 | 233 | $sql = "UPDATE ".MAIN_DB_PREFIX."c_country SET"; |
| 234 | - $sql.= " code=".(isset($this->code)?"'".$this->db->escape($this->code)."'":"null").","; |
|
| 235 | - $sql.= " code_iso=".(isset($this->code_iso)?"'".$this->db->escape($this->code_iso)."'":"null").","; |
|
| 236 | - $sql.= " label=".(isset($this->label)?"'".$this->db->escape($this->label)."'":"null").","; |
|
| 237 | - $sql.= " active=".(isset($this->active)?$this->active:"null").""; |
|
| 234 | + $sql.= " code=".(isset($this->code)?"'".$this->db->escape($this->code)."'":"null").","; |
|
| 235 | + $sql.= " code_iso=".(isset($this->code_iso)?"'".$this->db->escape($this->code_iso)."'":"null").","; |
|
| 236 | + $sql.= " label=".(isset($this->label)?"'".$this->db->escape($this->label)."'":"null").","; |
|
| 237 | + $sql.= " active=".(isset($this->active)?$this->active:"null").""; |
|
| 238 | 238 | $sql.= " WHERE rowid=".$this->id; |
| 239 | 239 | |
| 240 | - $this->db->begin(); |
|
| 240 | + $this->db->begin(); |
|
| 241 | 241 | |
| 242 | - dol_syslog(get_class($this)."::update", LOG_DEBUG); |
|
| 242 | + dol_syslog(get_class($this)."::update", LOG_DEBUG); |
|
| 243 | 243 | $resql = $this->db->query($sql); |
| 244 | - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
| 245 | - |
|
| 246 | - if (! $error) |
|
| 247 | - { |
|
| 248 | - if (! $notrigger) |
|
| 249 | - { |
|
| 250 | - // Uncomment this and change MYOBJECT to your own tag if you |
|
| 251 | - // want this action call a trigger. |
|
| 252 | - |
|
| 253 | - //// Call triggers |
|
| 254 | - //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
| 255 | - //$interface=new Interfaces($this->db); |
|
| 256 | - //$result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf); |
|
| 257 | - //if ($result < 0) { $error++; $this->errors=$interface->errors; } |
|
| 258 | - //// End call triggers |
|
| 259 | - } |
|
| 260 | - } |
|
| 244 | + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
| 245 | + |
|
| 246 | + if (! $error) |
|
| 247 | + { |
|
| 248 | + if (! $notrigger) |
|
| 249 | + { |
|
| 250 | + // Uncomment this and change MYOBJECT to your own tag if you |
|
| 251 | + // want this action call a trigger. |
|
| 252 | + |
|
| 253 | + //// Call triggers |
|
| 254 | + //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
| 255 | + //$interface=new Interfaces($this->db); |
|
| 256 | + //$result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf); |
|
| 257 | + //if ($result < 0) { $error++; $this->errors=$interface->errors; } |
|
| 258 | + //// End call triggers |
|
| 259 | + } |
|
| 260 | + } |
|
| 261 | 261 | |
| 262 | 262 | // Commit or rollback |
| 263 | - if ($error) |
|
| 264 | - { |
|
| 265 | - foreach($this->errors as $errmsg) |
|
| 266 | - { |
|
| 267 | - dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); |
|
| 268 | - $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
| 269 | - } |
|
| 270 | - $this->db->rollback(); |
|
| 271 | - return -1*$error; |
|
| 272 | - } |
|
| 273 | - else |
|
| 274 | - { |
|
| 275 | - $this->db->commit(); |
|
| 276 | - return 1; |
|
| 277 | - } |
|
| 263 | + if ($error) |
|
| 264 | + { |
|
| 265 | + foreach($this->errors as $errmsg) |
|
| 266 | + { |
|
| 267 | + dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); |
|
| 268 | + $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
| 269 | + } |
|
| 270 | + $this->db->rollback(); |
|
| 271 | + return -1*$error; |
|
| 272 | + } |
|
| 273 | + else |
|
| 274 | + { |
|
| 275 | + $this->db->commit(); |
|
| 276 | + return 1; |
|
| 277 | + } |
|
| 278 | 278 | } |
| 279 | 279 | |
| 280 | 280 | |
| 281 | - /** |
|
| 282 | - * Delete object in database |
|
| 283 | - * |
|
| 284 | - * @param User $user User that delete |
|
| 285 | - * @param int $notrigger 0=launch triggers after, 1=disable triggers |
|
| 286 | - * @return int <0 if KO, >0 if OK |
|
| 287 | - */ |
|
| 288 | - function delete($user, $notrigger=0) |
|
| 289 | - { |
|
| 290 | - global $conf, $langs; |
|
| 291 | - $error=0; |
|
| 292 | - |
|
| 293 | - $sql = "DELETE FROM ".MAIN_DB_PREFIX."c_country"; |
|
| 294 | - $sql.= " WHERE rowid=".$this->id; |
|
| 295 | - |
|
| 296 | - $this->db->begin(); |
|
| 297 | - |
|
| 298 | - dol_syslog(get_class($this)."::delete", LOG_DEBUG); |
|
| 299 | - $resql = $this->db->query($sql); |
|
| 300 | - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
| 301 | - |
|
| 302 | - if (! $error) |
|
| 303 | - { |
|
| 304 | - if (! $notrigger) |
|
| 305 | - { |
|
| 306 | - // Uncomment this and change MYOBJECT to your own tag if you |
|
| 307 | - // want this action call a trigger. |
|
| 308 | - |
|
| 309 | - //// Call triggers |
|
| 310 | - //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
| 311 | - //$interface=new Interfaces($this->db); |
|
| 312 | - //$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf); |
|
| 313 | - //if ($result < 0) { $error++; $this->errors=$interface->errors; } |
|
| 314 | - //// End call triggers |
|
| 315 | - } |
|
| 316 | - } |
|
| 281 | + /** |
|
| 282 | + * Delete object in database |
|
| 283 | + * |
|
| 284 | + * @param User $user User that delete |
|
| 285 | + * @param int $notrigger 0=launch triggers after, 1=disable triggers |
|
| 286 | + * @return int <0 if KO, >0 if OK |
|
| 287 | + */ |
|
| 288 | + function delete($user, $notrigger=0) |
|
| 289 | + { |
|
| 290 | + global $conf, $langs; |
|
| 291 | + $error=0; |
|
| 292 | + |
|
| 293 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX."c_country"; |
|
| 294 | + $sql.= " WHERE rowid=".$this->id; |
|
| 295 | + |
|
| 296 | + $this->db->begin(); |
|
| 297 | + |
|
| 298 | + dol_syslog(get_class($this)."::delete", LOG_DEBUG); |
|
| 299 | + $resql = $this->db->query($sql); |
|
| 300 | + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
| 301 | + |
|
| 302 | + if (! $error) |
|
| 303 | + { |
|
| 304 | + if (! $notrigger) |
|
| 305 | + { |
|
| 306 | + // Uncomment this and change MYOBJECT to your own tag if you |
|
| 307 | + // want this action call a trigger. |
|
| 308 | + |
|
| 309 | + //// Call triggers |
|
| 310 | + //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
| 311 | + //$interface=new Interfaces($this->db); |
|
| 312 | + //$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf); |
|
| 313 | + //if ($result < 0) { $error++; $this->errors=$interface->errors; } |
|
| 314 | + //// End call triggers |
|
| 315 | + } |
|
| 316 | + } |
|
| 317 | 317 | |
| 318 | 318 | // Commit or rollback |
| 319 | - if ($error) |
|
| 320 | - { |
|
| 321 | - foreach($this->errors as $errmsg) |
|
| 322 | - { |
|
| 323 | - dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); |
|
| 324 | - $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
| 325 | - } |
|
| 326 | - $this->db->rollback(); |
|
| 327 | - return -1*$error; |
|
| 328 | - } |
|
| 329 | - else |
|
| 330 | - { |
|
| 331 | - $this->db->commit(); |
|
| 332 | - return 1; |
|
| 333 | - } |
|
| 334 | - } |
|
| 319 | + if ($error) |
|
| 320 | + { |
|
| 321 | + foreach($this->errors as $errmsg) |
|
| 322 | + { |
|
| 323 | + dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); |
|
| 324 | + $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
| 325 | + } |
|
| 326 | + $this->db->rollback(); |
|
| 327 | + return -1*$error; |
|
| 328 | + } |
|
| 329 | + else |
|
| 330 | + { |
|
| 331 | + $this->db->commit(); |
|
| 332 | + return 1; |
|
| 333 | + } |
|
| 334 | + } |
|
| 335 | 335 | } |
@@ -34,27 +34,27 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | abstract class CommonDocGenerator |
| 36 | 36 | { |
| 37 | - /** |
|
| 38 | - * @var string Error code (or message) |
|
| 39 | - */ |
|
| 40 | - public $error=''; |
|
| 37 | + /** |
|
| 38 | + * @var string Error code (or message) |
|
| 39 | + */ |
|
| 40 | + public $error=''; |
|
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | 43 | * @var string[] Array of error strings |
| 44 | 44 | */ |
| 45 | 45 | public $errors = array(); |
| 46 | 46 | |
| 47 | - /** |
|
| 47 | + /** |
|
| 48 | 48 | * @var DoliDB Database handler. |
| 49 | 49 | */ |
| 50 | - protected $db; |
|
| 50 | + protected $db; |
|
| 51 | 51 | |
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Constructor |
|
| 55 | - * |
|
| 56 | - * @param DoliDB $db Database handler |
|
| 57 | - */ |
|
| 53 | + /** |
|
| 54 | + * Constructor |
|
| 55 | + * |
|
| 56 | + * @param DoliDB $db Database handler |
|
| 57 | + */ |
|
| 58 | 58 | public function __construct($db) |
| 59 | 59 | { |
| 60 | 60 | $this->db = $db; |
@@ -82,18 +82,18 @@ discard block |
||
| 82 | 82 | 'myuser_fullname'=>$user->getFullName($outputlangs,1), |
| 83 | 83 | 'myuser_login'=>$user->login, |
| 84 | 84 | 'myuser_phone'=>$user->office_phone, |
| 85 | - 'myuser_address'=>$user->address, |
|
| 86 | - 'myuser_zip'=>$user->zip, |
|
| 87 | - 'myuser_town'=>$user->town, |
|
| 88 | - 'myuser_country'=>$user->country, |
|
| 89 | - 'myuser_country_code'=>$user->country_code, |
|
| 90 | - 'myuser_state'=>$user->state, |
|
| 91 | - 'myuser_state_code'=>$user->state_code, |
|
| 92 | - 'myuser_fax'=>$user->office_fax, |
|
| 85 | + 'myuser_address'=>$user->address, |
|
| 86 | + 'myuser_zip'=>$user->zip, |
|
| 87 | + 'myuser_town'=>$user->town, |
|
| 88 | + 'myuser_country'=>$user->country, |
|
| 89 | + 'myuser_country_code'=>$user->country_code, |
|
| 90 | + 'myuser_state'=>$user->state, |
|
| 91 | + 'myuser_state_code'=>$user->state_code, |
|
| 92 | + 'myuser_fax'=>$user->office_fax, |
|
| 93 | 93 | 'myuser_mobile'=>$user->user_mobile, |
| 94 | 94 | 'myuser_email'=>$user->email, |
| 95 | - 'myuser_logo'=>$logotouse, |
|
| 96 | - 'myuser_job'=>$user->job, |
|
| 95 | + 'myuser_logo'=>$logotouse, |
|
| 96 | + 'myuser_job'=>$user->job, |
|
| 97 | 97 | 'myuser_web'=>'' // url not exist in $user object |
| 98 | 98 | ); |
| 99 | 99 | } |
@@ -118,11 +118,11 @@ discard block |
||
| 118 | 118 | } |
| 119 | 119 | if (empty($mysoc->country) && ! empty($mysoc->country_code)) |
| 120 | 120 | { |
| 121 | - $mysoc->country=$outputlangs->transnoentitiesnoconv("Country".$mysoc->country_code); |
|
| 121 | + $mysoc->country=$outputlangs->transnoentitiesnoconv("Country".$mysoc->country_code); |
|
| 122 | 122 | } |
| 123 | 123 | if (empty($mysoc->state) && ! empty($mysoc->state_code)) |
| 124 | 124 | { |
| 125 | - $mysoc->state=getState($mysoc->state_code,0); |
|
| 125 | + $mysoc->state=getState($mysoc->state_code,0); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | $logotouse=$conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small; |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | 'mycompany_country_code'=>$mysoc->country_code, |
| 141 | 141 | 'mycompany_state'=>$mysoc->state, |
| 142 | 142 | 'mycompany_state_code'=>$mysoc->state_code, |
| 143 | - 'mycompany_web'=>$mysoc->url, |
|
| 143 | + 'mycompany_web'=>$mysoc->url, |
|
| 144 | 144 | 'mycompany_juridicalstatus'=>$mysoc->forme_juridique, |
| 145 | 145 | 'mycompany_managers'=>$mysoc->managers, |
| 146 | 146 | 'mycompany_capital'=>$mysoc->capital, |
@@ -151,8 +151,8 @@ discard block |
||
| 151 | 151 | 'mycompany_idprof4'=>$mysoc->idprof4, |
| 152 | 152 | 'mycompany_idprof5'=>$mysoc->idprof5, |
| 153 | 153 | 'mycompany_idprof6'=>$mysoc->idprof6, |
| 154 | - 'mycompany_vatnumber'=>$mysoc->tva_intra, |
|
| 155 | - 'mycompany_object'=>$mysoc->object, |
|
| 154 | + 'mycompany_vatnumber'=>$mysoc->tva_intra, |
|
| 155 | + 'mycompany_object'=>$mysoc->object, |
|
| 156 | 156 | 'mycompany_note_private'=>$mysoc->note_private, |
| 157 | 157 | //'mycompany_note_public'=>$mysoc->note_public, // Only private not exists for "mysoc" but both for thirdparties |
| 158 | 158 | ); |
@@ -174,16 +174,16 @@ discard block |
||
| 174 | 174 | |
| 175 | 175 | if (empty($object->country) && ! empty($object->country_code)) |
| 176 | 176 | { |
| 177 | - $object->country=$outputlangs->transnoentitiesnoconv("Country".$object->country_code); |
|
| 177 | + $object->country=$outputlangs->transnoentitiesnoconv("Country".$object->country_code); |
|
| 178 | 178 | } |
| 179 | 179 | if (empty($object->state) && ! empty($object->state_code)) |
| 180 | 180 | { |
| 181 | - $object->state=getState($object->state_code,0); |
|
| 181 | + $object->state=getState($object->state_code,0); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | $array_thirdparty = array( |
| 185 | 185 | 'company_name'=>$object->name, |
| 186 | - 'company_name_alias' => $object->name_alias, |
|
| 186 | + 'company_name_alias' => $object->name_alias, |
|
| 187 | 187 | 'company_email'=>$object->email, |
| 188 | 188 | 'company_phone'=>$object->phone, |
| 189 | 189 | 'company_fax'=>$object->fax, |
@@ -191,10 +191,10 @@ discard block |
||
| 191 | 191 | 'company_zip'=>$object->zip, |
| 192 | 192 | 'company_town'=>$object->town, |
| 193 | 193 | 'company_country'=>$object->country, |
| 194 | - 'company_country_code'=>$object->country_code, |
|
| 194 | + 'company_country_code'=>$object->country_code, |
|
| 195 | 195 | 'company_state'=>$object->state, |
| 196 | - 'company_state_code'=>$object->state_code, |
|
| 197 | - 'company_web'=>$object->url, |
|
| 196 | + 'company_state_code'=>$object->state_code, |
|
| 197 | + 'company_web'=>$object->url, |
|
| 198 | 198 | 'company_barcode'=>$object->barcode, |
| 199 | 199 | 'company_vatnumber'=>$object->tva_intra, |
| 200 | 200 | 'company_customercode'=>$object->code_client, |
@@ -219,52 +219,52 @@ discard block |
||
| 219 | 219 | // Retrieve extrafields |
| 220 | 220 | if(is_array($object->array_options) && count($object->array_options)) |
| 221 | 221 | { |
| 222 | - require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
| 223 | - $extrafields = new ExtraFields($this->db); |
|
| 224 | - $extralabels = $extrafields->fetch_name_optionals_label('societe',true); |
|
| 225 | - $object->fetch_optionals(); |
|
| 226 | - |
|
| 227 | - foreach($extrafields->attribute_label as $key=>$label) |
|
| 228 | - { |
|
| 229 | - if($extrafields->attribute_type[$key] == 'price') |
|
| 230 | - { |
|
| 231 | - $object->array_options['options_'.$key] = price($object->array_options['options_'.$key],0,$outputlangs,0,0,-1,$conf->currency); |
|
| 232 | - } |
|
| 233 | - else if($extrafields->attribute_type[$key] == 'select' || $extrafields->attribute_type[$key] == 'checkbox') |
|
| 234 | - { |
|
| 235 | - $object->array_options['options_'.$key] = $extrafields->attribute_param[$key]['options'][$object->array_options['options_'.$key]]; |
|
| 236 | - } |
|
| 237 | - $array_thirdparty = array_merge($array_thirdparty, array ('company_options_'.$key => $object->array_options ['options_' . $key])); |
|
| 238 | - } |
|
| 239 | - } |
|
| 240 | - return $array_thirdparty; |
|
| 241 | - } |
|
| 222 | + require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
| 223 | + $extrafields = new ExtraFields($this->db); |
|
| 224 | + $extralabels = $extrafields->fetch_name_optionals_label('societe',true); |
|
| 225 | + $object->fetch_optionals(); |
|
| 226 | + |
|
| 227 | + foreach($extrafields->attribute_label as $key=>$label) |
|
| 228 | + { |
|
| 229 | + if($extrafields->attribute_type[$key] == 'price') |
|
| 230 | + { |
|
| 231 | + $object->array_options['options_'.$key] = price($object->array_options['options_'.$key],0,$outputlangs,0,0,-1,$conf->currency); |
|
| 232 | + } |
|
| 233 | + else if($extrafields->attribute_type[$key] == 'select' || $extrafields->attribute_type[$key] == 'checkbox') |
|
| 234 | + { |
|
| 235 | + $object->array_options['options_'.$key] = $extrafields->attribute_param[$key]['options'][$object->array_options['options_'.$key]]; |
|
| 236 | + } |
|
| 237 | + $array_thirdparty = array_merge($array_thirdparty, array ('company_options_'.$key => $object->array_options ['options_' . $key])); |
|
| 238 | + } |
|
| 239 | + } |
|
| 240 | + return $array_thirdparty; |
|
| 241 | + } |
|
| 242 | 242 | |
| 243 | 243 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
| 244 | - /** |
|
| 245 | - * Define array with couple subtitution key => subtitution value |
|
| 246 | - * |
|
| 247 | - * @param Contact $object contact |
|
| 248 | - * @param Translate $outputlangs object for output |
|
| 249 | - * @param array $array_key Name of the key for return array |
|
| 250 | - * @return array Array of substitution key->code |
|
| 251 | - */ |
|
| 244 | + /** |
|
| 245 | + * Define array with couple subtitution key => subtitution value |
|
| 246 | + * |
|
| 247 | + * @param Contact $object contact |
|
| 248 | + * @param Translate $outputlangs object for output |
|
| 249 | + * @param array $array_key Name of the key for return array |
|
| 250 | + * @return array Array of substitution key->code |
|
| 251 | + */ |
|
| 252 | 252 | function get_substitutionarray_contact($object, $outputlangs, $array_key = 'object') |
| 253 | 253 | { |
| 254 | 254 | // phpcs:enable |
| 255 | - global $conf; |
|
| 256 | - |
|
| 257 | - if(empty($object->country) && ! empty($object->country_code)) |
|
| 258 | - { |
|
| 259 | - $object->country = $outputlangs->transnoentitiesnoconv("Country" . $object->country_code); |
|
| 260 | - } |
|
| 261 | - if(empty($object->state) && ! empty($object->state_code)) |
|
| 262 | - { |
|
| 263 | - $object->state = getState($object->state_code, 0); |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - $array_contact = array ( |
|
| 267 | - $array_key . '_fullname' => $object->getFullName($outputlangs, 1), |
|
| 255 | + global $conf; |
|
| 256 | + |
|
| 257 | + if(empty($object->country) && ! empty($object->country_code)) |
|
| 258 | + { |
|
| 259 | + $object->country = $outputlangs->transnoentitiesnoconv("Country" . $object->country_code); |
|
| 260 | + } |
|
| 261 | + if(empty($object->state) && ! empty($object->state_code)) |
|
| 262 | + { |
|
| 263 | + $object->state = getState($object->state_code, 0); |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + $array_contact = array ( |
|
| 267 | + $array_key . '_fullname' => $object->getFullName($outputlangs, 1), |
|
| 268 | 268 | $array_key . '_lastname' => $object->lastname, |
| 269 | 269 | $array_key . '_firstname' => $object->firstname, |
| 270 | 270 | $array_key . '_address' => $object->address, |
@@ -290,28 +290,28 @@ discard block |
||
| 290 | 290 | $array_key . '_default_lang' => $object->default_lang, |
| 291 | 291 | $array_key . '_note_public' => $object->note_public, |
| 292 | 292 | $array_key . '_note_private' => $object->note_private |
| 293 | - ); |
|
| 294 | - |
|
| 295 | - // Retrieve extrafields |
|
| 296 | - require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php'; |
|
| 297 | - $extrafields = new ExtraFields($this->db); |
|
| 298 | - $extralabels = $extrafields->fetch_name_optionals_label('socpeople', true); |
|
| 299 | - $object->fetch_optionals(); |
|
| 300 | - |
|
| 301 | - foreach($extrafields->attribute_label as $key => $label) |
|
| 302 | - { |
|
| 303 | - if ($extrafields->attribute_type[$key] == 'price') |
|
| 304 | - { |
|
| 305 | - $object->array_options['options_' . $key] = price($object->array_options ['options_' . $key], 0, $outputlangs, 0, 0, - 1, $conf->currency); |
|
| 306 | - } |
|
| 307 | - elseif($extrafields->attribute_type[$key] == 'select' || $extrafields->attribute_type[$key] == 'checkbox') |
|
| 308 | - { |
|
| 309 | - $object->array_options['options_' . $key] = $extrafields->attribute_param[$key]['options'][$object->array_options['options_' . $key]]; |
|
| 310 | - } |
|
| 311 | - $array_contact = array_merge($array_contact, array($array_key.'_options_' . $key => $object->array_options['options_'. $key])); |
|
| 312 | - } |
|
| 313 | - return $array_contact; |
|
| 314 | - } |
|
| 293 | + ); |
|
| 294 | + |
|
| 295 | + // Retrieve extrafields |
|
| 296 | + require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php'; |
|
| 297 | + $extrafields = new ExtraFields($this->db); |
|
| 298 | + $extralabels = $extrafields->fetch_name_optionals_label('socpeople', true); |
|
| 299 | + $object->fetch_optionals(); |
|
| 300 | + |
|
| 301 | + foreach($extrafields->attribute_label as $key => $label) |
|
| 302 | + { |
|
| 303 | + if ($extrafields->attribute_type[$key] == 'price') |
|
| 304 | + { |
|
| 305 | + $object->array_options['options_' . $key] = price($object->array_options ['options_' . $key], 0, $outputlangs, 0, 0, - 1, $conf->currency); |
|
| 306 | + } |
|
| 307 | + elseif($extrafields->attribute_type[$key] == 'select' || $extrafields->attribute_type[$key] == 'checkbox') |
|
| 308 | + { |
|
| 309 | + $object->array_options['options_' . $key] = $extrafields->attribute_param[$key]['options'][$object->array_options['options_' . $key]]; |
|
| 310 | + } |
|
| 311 | + $array_contact = array_merge($array_contact, array($array_key.'_options_' . $key => $object->array_options['options_'. $key])); |
|
| 312 | + } |
|
| 313 | + return $array_contact; |
|
| 314 | + } |
|
| 315 | 315 | |
| 316 | 316 | |
| 317 | 317 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
@@ -324,260 +324,260 @@ discard block |
||
| 324 | 324 | function get_substitutionarray_other($outputlangs) |
| 325 | 325 | { |
| 326 | 326 | // phpcs:enable |
| 327 | - global $conf; |
|
| 328 | - |
|
| 329 | - $now=dol_now('gmt'); // gmt |
|
| 330 | - $array_other = array( |
|
| 331 | - // Date in default language |
|
| 332 | - 'current_date'=>dol_print_date($now,'day','tzuser'), |
|
| 333 | - 'current_datehour'=>dol_print_date($now,'dayhour','tzuser'), |
|
| 334 | - 'current_server_date'=>dol_print_date($now,'day','tzserver'), |
|
| 335 | - 'current_server_datehour'=>dol_print_date($now,'dayhour','tzserver'), |
|
| 336 | - // Date in requested output language |
|
| 337 | - 'current_date_locale'=>dol_print_date($now,'day','tzuser',$outputlangs), |
|
| 338 | - 'current_datehour_locale'=>dol_print_date($now,'dayhour','tzuser',$outputlangs), |
|
| 339 | - 'current_server_date_locale'=>dol_print_date($now,'day','tzserver',$outputlangs), |
|
| 340 | - 'current_server_datehour_locale'=>dol_print_date($now,'dayhour','tzserver',$outputlangs), |
|
| 341 | - ); |
|
| 342 | - |
|
| 343 | - |
|
| 344 | - foreach($conf->global as $key => $val) |
|
| 345 | - { |
|
| 346 | - if (preg_match('/(_pass|password|secret|_key|key$)/i', $key)) $newval = '*****forbidden*****'; |
|
| 347 | - else $newval = $val; |
|
| 348 | - $array_other['__['.$key.']__'] = $newval; |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - return $array_other; |
|
| 327 | + global $conf; |
|
| 328 | + |
|
| 329 | + $now=dol_now('gmt'); // gmt |
|
| 330 | + $array_other = array( |
|
| 331 | + // Date in default language |
|
| 332 | + 'current_date'=>dol_print_date($now,'day','tzuser'), |
|
| 333 | + 'current_datehour'=>dol_print_date($now,'dayhour','tzuser'), |
|
| 334 | + 'current_server_date'=>dol_print_date($now,'day','tzserver'), |
|
| 335 | + 'current_server_datehour'=>dol_print_date($now,'dayhour','tzserver'), |
|
| 336 | + // Date in requested output language |
|
| 337 | + 'current_date_locale'=>dol_print_date($now,'day','tzuser',$outputlangs), |
|
| 338 | + 'current_datehour_locale'=>dol_print_date($now,'dayhour','tzuser',$outputlangs), |
|
| 339 | + 'current_server_date_locale'=>dol_print_date($now,'day','tzserver',$outputlangs), |
|
| 340 | + 'current_server_datehour_locale'=>dol_print_date($now,'dayhour','tzserver',$outputlangs), |
|
| 341 | + ); |
|
| 342 | + |
|
| 343 | + |
|
| 344 | + foreach($conf->global as $key => $val) |
|
| 345 | + { |
|
| 346 | + if (preg_match('/(_pass|password|secret|_key|key$)/i', $key)) $newval = '*****forbidden*****'; |
|
| 347 | + else $newval = $val; |
|
| 348 | + $array_other['__['.$key.']__'] = $newval; |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + return $array_other; |
|
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | |
| 355 | 355 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
| 356 | - /** |
|
| 357 | - * Define array with couple substitution key => substitution value |
|
| 358 | - * |
|
| 359 | - * @param Object $object Main object to use as data source |
|
| 360 | - * @param Translate $outputlangs Lang object to use for output |
|
| 356 | + /** |
|
| 357 | + * Define array with couple substitution key => substitution value |
|
| 358 | + * |
|
| 359 | + * @param Object $object Main object to use as data source |
|
| 360 | + * @param Translate $outputlangs Lang object to use for output |
|
| 361 | 361 | * @param string $array_key Name of the key for return array |
| 362 | - * @return array Array of substitution |
|
| 363 | - */ |
|
| 364 | - function get_substitutionarray_object($object,$outputlangs,$array_key='object') |
|
| 365 | - { |
|
| 362 | + * @return array Array of substitution |
|
| 363 | + */ |
|
| 364 | + function get_substitutionarray_object($object,$outputlangs,$array_key='object') |
|
| 365 | + { |
|
| 366 | 366 | // phpcs:enable |
| 367 | - global $conf; |
|
| 368 | - |
|
| 369 | - $sumpayed=$sumdeposit=$sumcreditnote=''; |
|
| 370 | - if ($object->element == 'facture') |
|
| 371 | - { |
|
| 372 | - $invoice_source=new Facture($this->db); |
|
| 373 | - if ($object->fk_facture_source > 0) |
|
| 374 | - { |
|
| 375 | - $invoice_source->fetch($object->fk_facture_source); |
|
| 376 | - } |
|
| 377 | - $sumpayed = $object->getSommePaiement(); |
|
| 378 | - $sumdeposit = $object->getSumDepositsUsed(); |
|
| 379 | - $sumcreditnote = $object->getSumCreditNotesUsed(); |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - $date = ($object->element == 'contrat' ? $object->date_contrat : $object->date); |
|
| 383 | - |
|
| 384 | - $resarray=array( |
|
| 385 | - $array_key.'_id'=>$object->id, |
|
| 386 | - $array_key.'_ref'=>$object->ref, |
|
| 387 | - $array_key.'_ref_ext'=>$object->ref_ext, |
|
| 388 | - $array_key.'_ref_customer'=>(! empty($object->ref_client) ? $object->ref_client : (empty($object->ref_customer) ? '' : $object->ref_customer)), |
|
| 389 | - $array_key.'_ref_supplier'=>(! empty($object->ref_fournisseur) ? $object->ref_fournisseur : (empty($object->ref_supplier) ? '' : $object->ref_supplier)), |
|
| 390 | - $array_key.'_source_invoice_ref'=>$invoice_source->ref, |
|
| 391 | - // Dates |
|
| 367 | + global $conf; |
|
| 368 | + |
|
| 369 | + $sumpayed=$sumdeposit=$sumcreditnote=''; |
|
| 370 | + if ($object->element == 'facture') |
|
| 371 | + { |
|
| 372 | + $invoice_source=new Facture($this->db); |
|
| 373 | + if ($object->fk_facture_source > 0) |
|
| 374 | + { |
|
| 375 | + $invoice_source->fetch($object->fk_facture_source); |
|
| 376 | + } |
|
| 377 | + $sumpayed = $object->getSommePaiement(); |
|
| 378 | + $sumdeposit = $object->getSumDepositsUsed(); |
|
| 379 | + $sumcreditnote = $object->getSumCreditNotesUsed(); |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + $date = ($object->element == 'contrat' ? $object->date_contrat : $object->date); |
|
| 383 | + |
|
| 384 | + $resarray=array( |
|
| 385 | + $array_key.'_id'=>$object->id, |
|
| 386 | + $array_key.'_ref'=>$object->ref, |
|
| 387 | + $array_key.'_ref_ext'=>$object->ref_ext, |
|
| 388 | + $array_key.'_ref_customer'=>(! empty($object->ref_client) ? $object->ref_client : (empty($object->ref_customer) ? '' : $object->ref_customer)), |
|
| 389 | + $array_key.'_ref_supplier'=>(! empty($object->ref_fournisseur) ? $object->ref_fournisseur : (empty($object->ref_supplier) ? '' : $object->ref_supplier)), |
|
| 390 | + $array_key.'_source_invoice_ref'=>$invoice_source->ref, |
|
| 391 | + // Dates |
|
| 392 | 392 | $array_key.'_hour'=>dol_print_date($date,'hour'), |
| 393 | - $array_key.'_date'=>dol_print_date($date,'day'), |
|
| 394 | - $array_key.'_date_rfc'=>dol_print_date($date,'dayrfc'), |
|
| 395 | - $array_key.'_date_limit'=>(! empty($object->date_lim_reglement)?dol_print_date($object->date_lim_reglement,'day'):''), |
|
| 396 | - $array_key.'_date_end'=>(! empty($object->fin_validite)?dol_print_date($object->fin_validite,'day'):''), |
|
| 397 | - $array_key.'_date_creation'=>dol_print_date($object->date_creation,'day'), |
|
| 398 | - $array_key.'_date_modification'=>(! empty($object->date_modification)?dol_print_date($object->date_modification,'day'):''), |
|
| 399 | - $array_key.'_date_validation'=>(! empty($object->date_validation)?dol_print_date($object->date_validation,'dayhour'):''), |
|
| 400 | - $array_key.'_date_delivery_planed'=>(! empty($object->date_livraison)?dol_print_date($object->date_livraison,'day'):''), |
|
| 401 | - $array_key.'_date_close'=>(! empty($object->date_cloture)?dol_print_date($object->date_cloture,'dayhour'):''), |
|
| 402 | - |
|
| 403 | - $array_key.'_payment_mode_code'=>$object->mode_reglement_code, |
|
| 404 | - $array_key.'_payment_mode'=>($outputlangs->transnoentitiesnoconv('PaymentType'.$object->mode_reglement_code)!='PaymentType'.$object->mode_reglement_code?$outputlangs->transnoentitiesnoconv('PaymentType'.$object->mode_reglement_code):$object->mode_reglement), |
|
| 405 | - $array_key.'_payment_term_code'=>$object->cond_reglement_code, |
|
| 406 | - $array_key.'_payment_term'=>($outputlangs->transnoentitiesnoconv('PaymentCondition'.$object->cond_reglement_code)!='PaymentCondition'.$object->cond_reglement_code?$outputlangs->transnoentitiesnoconv('PaymentCondition'.$object->cond_reglement_code):($object->cond_reglement_doc?$object->cond_reglement_doc:$object->cond_reglement)), |
|
| 407 | - |
|
| 408 | - $array_key.'_total_ht_locale'=>price($object->total_ht, 0, $outputlangs), |
|
| 409 | - $array_key.'_total_vat_locale'=>(! empty($object->total_vat)?price($object->total_vat, 0, $outputlangs):price($object->total_tva, 0, $outputlangs)), |
|
| 410 | - $array_key.'_total_localtax1_locale'=>price($object->total_localtax1, 0, $outputlangs), |
|
| 411 | - $array_key.'_total_localtax2_locale'=>price($object->total_localtax2, 0, $outputlangs), |
|
| 412 | - $array_key.'_total_ttc_locale'=>price($object->total_ttc, 0, $outputlangs), |
|
| 413 | - |
|
| 414 | - $array_key.'_total_ht'=>price2num($object->total_ht), |
|
| 415 | - $array_key.'_total_vat'=>(! empty($object->total_vat)?price2num($object->total_vat):price2num($object->total_tva)), |
|
| 416 | - $array_key.'_total_localtax1'=>price2num($object->total_localtax1), |
|
| 417 | - $array_key.'_total_localtax2'=>price2num($object->total_localtax2), |
|
| 418 | - $array_key.'_total_ttc'=>price2num($object->total_ttc), |
|
| 419 | - |
|
| 420 | - $array_key.'_multicurrency_code' => price2num($object->multicurrency_code), |
|
| 421 | - $array_key.'_multicurrency_tx' => price2num($object->multicurrency_tx), |
|
| 422 | - $array_key.'_multicurrency_total_ht' => price2num($object->multicurrency_total_ht), |
|
| 423 | - $array_key.'_multicurrency_total_tva' => price2num($object->multicurrency_total_tva), |
|
| 424 | - $array_key.'_multicurrency_total_ttc' => price2num($object->multicurrency_total_ttc), |
|
| 425 | - $array_key.'_multicurrency_total_ht_locale' => price($object->multicurrency_total_ht, 0, $outputlangs), |
|
| 426 | - $array_key.'_multicurrency_total_tva_locale' => price($object->multicurrency_total_tva, 0, $outputlangs), |
|
| 427 | - $array_key.'_multicurrency_total_ttc_locale' => price($object->multicurrency_total_ttc, 0, $outputlangs), |
|
| 428 | - |
|
| 429 | - $array_key.'_note_private'=>$object->note, |
|
| 430 | - $array_key.'_note_public'=>$object->note_public, |
|
| 431 | - $array_key.'_note'=>$object->note_public, // For backward compatibility |
|
| 432 | - |
|
| 433 | - // Payments |
|
| 434 | - $array_key.'_already_payed_locale'=>price($sumpayed, 0, $outputlangs), |
|
| 435 | - $array_key.'_already_payed'=>price2num($sumpayed), |
|
| 436 | - $array_key.'_already_deposit_locale'=>price($sumdeposit, 0, $outputlangs), |
|
| 437 | - $array_key.'_already_deposit'=>price2num($sumdeposit), |
|
| 438 | - $array_key.'_already_creditnote_locale'=>price($sumcreditnote, 0, $outputlangs), |
|
| 439 | - $array_key.'_already_creditnote'=>price2num($sumcreditnote), |
|
| 440 | - |
|
| 441 | - $array_key.'_already_payed_all_locale'=>price(price2num($sumpayed + $sumdeposit + $sumcreditnote, 'MT'), 0, $outputlangs), |
|
| 442 | - $array_key.'_already_payed_all'=> price2num(($sumpayed + $sumdeposit + $sumcreditnote), 'MT'), |
|
| 443 | - |
|
| 444 | - // Remain to pay with all know infrmation (except open direct debit requests) |
|
| 445 | - $array_key.'_remain_to_pay_locale'=>price(price2num($object->total_ttc - $sumpayed - $sumdeposit - $sumcreditnote, 'MT'), 0, $outputlangs), |
|
| 446 | - $array_key.'_remain_to_pay'=>price2num($object->total_ttc - $sumpayed - $sumdeposit - $sumcreditnote, 'MT') |
|
| 447 | - ); |
|
| 448 | - |
|
| 449 | - if (method_exists($object, 'getTotalDiscount')) { |
|
| 450 | - $resarray[$array_key.'_total_discount_ht_locale'] = price($object->getTotalDiscount(), 0, $outputlangs); |
|
| 451 | - $resarray[$array_key.'_total_discount_ht'] = price2num($object->getTotalDiscount()); |
|
| 452 | - } else { |
|
| 453 | - $resarray[$array_key.'_total_discount_ht_locale'] = ''; |
|
| 454 | - $resarray[$array_key.'_total_discount_ht'] = ''; |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - // Fetch project information if there is a project assigned to this object |
|
| 458 | - if ($object->element != "project" && ! empty($object->fk_project) && $object->fk_project > 0) |
|
| 459 | - { |
|
| 460 | - if (! is_object($object->project)) |
|
| 461 | - { |
|
| 462 | - $object->fetch_projet(); |
|
| 463 | - } |
|
| 464 | - |
|
| 465 | - $resarray[$array_key.'_project_ref'] = $object->project->ref; |
|
| 466 | - $resarray[$array_key.'_project_title'] = $object->project->title; |
|
| 467 | - $resarray[$array_key.'_project_description'] = $object->project->description; |
|
| 468 | - $resarray[$array_key.'_project_date_start'] = dol_print_date($object->project->date_start, 'day'); |
|
| 469 | - $resarray[$array_key.'_project_date_end'] = dol_print_date($object->project->date_end, 'day'); |
|
| 470 | - } |
|
| 471 | - |
|
| 472 | - // Add vat by rates |
|
| 473 | - if (is_array($object->lines) && count($object->lines)>0) |
|
| 474 | - { |
|
| 475 | - foreach ($object->lines as $line) |
|
| 476 | - { |
|
| 477 | - // $line->tva_tx format depends on database field accuraty, no reliable. This is kept for backward comaptibility |
|
| 478 | - if (empty($resarray[$array_key.'_total_vat_'.$line->tva_tx])) $resarray[$array_key.'_total_vat_'.$line->tva_tx]=0; |
|
| 479 | - $resarray[$array_key.'_total_vat_'.$line->tva_tx]+=$line->total_tva; |
|
| 480 | - $resarray[$array_key.'_total_vat_locale_'.$line->tva_tx]=price($resarray[$array_key.'_total_vat_'.$line->tva_tx]); |
|
| 481 | - // $vatformated is vat without not expected chars (so 20, or 8.5 or 5.99 for example) |
|
| 482 | - $vatformated=vatrate($line->tva_tx); |
|
| 483 | - if (empty($resarray[$array_key.'_total_vat_'.$vatformated])) $resarray[$array_key.'_total_vat_'.$vatformated]=0; |
|
| 484 | - $resarray[$array_key.'_total_vat_'.$vatformated]+=$line->total_tva; |
|
| 485 | - $resarray[$array_key.'_total_vat_locale_'.$vatformated]=price($resarray[$array_key.'_total_vat_'.$vatformated]); |
|
| 486 | - } |
|
| 487 | - } |
|
| 488 | - // Retrieve extrafields |
|
| 489 | - if (is_array($object->array_options) && count($object->array_options)) |
|
| 490 | - { |
|
| 491 | - $extrafieldkey=$object->element; |
|
| 492 | - |
|
| 493 | - require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
| 494 | - $extrafields = new ExtraFields($this->db); |
|
| 495 | - $extralabels = $extrafields->fetch_name_optionals_label($extrafieldkey,true); |
|
| 496 | - $object->fetch_optionals(); |
|
| 497 | - |
|
| 498 | - $resarray = $this->fill_substitutionarray_with_extrafields($object,$resarray,$extrafields,$array_key,$outputlangs); |
|
| 499 | - } |
|
| 500 | - return $resarray; |
|
| 501 | - } |
|
| 393 | + $array_key.'_date'=>dol_print_date($date,'day'), |
|
| 394 | + $array_key.'_date_rfc'=>dol_print_date($date,'dayrfc'), |
|
| 395 | + $array_key.'_date_limit'=>(! empty($object->date_lim_reglement)?dol_print_date($object->date_lim_reglement,'day'):''), |
|
| 396 | + $array_key.'_date_end'=>(! empty($object->fin_validite)?dol_print_date($object->fin_validite,'day'):''), |
|
| 397 | + $array_key.'_date_creation'=>dol_print_date($object->date_creation,'day'), |
|
| 398 | + $array_key.'_date_modification'=>(! empty($object->date_modification)?dol_print_date($object->date_modification,'day'):''), |
|
| 399 | + $array_key.'_date_validation'=>(! empty($object->date_validation)?dol_print_date($object->date_validation,'dayhour'):''), |
|
| 400 | + $array_key.'_date_delivery_planed'=>(! empty($object->date_livraison)?dol_print_date($object->date_livraison,'day'):''), |
|
| 401 | + $array_key.'_date_close'=>(! empty($object->date_cloture)?dol_print_date($object->date_cloture,'dayhour'):''), |
|
| 402 | + |
|
| 403 | + $array_key.'_payment_mode_code'=>$object->mode_reglement_code, |
|
| 404 | + $array_key.'_payment_mode'=>($outputlangs->transnoentitiesnoconv('PaymentType'.$object->mode_reglement_code)!='PaymentType'.$object->mode_reglement_code?$outputlangs->transnoentitiesnoconv('PaymentType'.$object->mode_reglement_code):$object->mode_reglement), |
|
| 405 | + $array_key.'_payment_term_code'=>$object->cond_reglement_code, |
|
| 406 | + $array_key.'_payment_term'=>($outputlangs->transnoentitiesnoconv('PaymentCondition'.$object->cond_reglement_code)!='PaymentCondition'.$object->cond_reglement_code?$outputlangs->transnoentitiesnoconv('PaymentCondition'.$object->cond_reglement_code):($object->cond_reglement_doc?$object->cond_reglement_doc:$object->cond_reglement)), |
|
| 407 | + |
|
| 408 | + $array_key.'_total_ht_locale'=>price($object->total_ht, 0, $outputlangs), |
|
| 409 | + $array_key.'_total_vat_locale'=>(! empty($object->total_vat)?price($object->total_vat, 0, $outputlangs):price($object->total_tva, 0, $outputlangs)), |
|
| 410 | + $array_key.'_total_localtax1_locale'=>price($object->total_localtax1, 0, $outputlangs), |
|
| 411 | + $array_key.'_total_localtax2_locale'=>price($object->total_localtax2, 0, $outputlangs), |
|
| 412 | + $array_key.'_total_ttc_locale'=>price($object->total_ttc, 0, $outputlangs), |
|
| 413 | + |
|
| 414 | + $array_key.'_total_ht'=>price2num($object->total_ht), |
|
| 415 | + $array_key.'_total_vat'=>(! empty($object->total_vat)?price2num($object->total_vat):price2num($object->total_tva)), |
|
| 416 | + $array_key.'_total_localtax1'=>price2num($object->total_localtax1), |
|
| 417 | + $array_key.'_total_localtax2'=>price2num($object->total_localtax2), |
|
| 418 | + $array_key.'_total_ttc'=>price2num($object->total_ttc), |
|
| 419 | + |
|
| 420 | + $array_key.'_multicurrency_code' => price2num($object->multicurrency_code), |
|
| 421 | + $array_key.'_multicurrency_tx' => price2num($object->multicurrency_tx), |
|
| 422 | + $array_key.'_multicurrency_total_ht' => price2num($object->multicurrency_total_ht), |
|
| 423 | + $array_key.'_multicurrency_total_tva' => price2num($object->multicurrency_total_tva), |
|
| 424 | + $array_key.'_multicurrency_total_ttc' => price2num($object->multicurrency_total_ttc), |
|
| 425 | + $array_key.'_multicurrency_total_ht_locale' => price($object->multicurrency_total_ht, 0, $outputlangs), |
|
| 426 | + $array_key.'_multicurrency_total_tva_locale' => price($object->multicurrency_total_tva, 0, $outputlangs), |
|
| 427 | + $array_key.'_multicurrency_total_ttc_locale' => price($object->multicurrency_total_ttc, 0, $outputlangs), |
|
| 428 | + |
|
| 429 | + $array_key.'_note_private'=>$object->note, |
|
| 430 | + $array_key.'_note_public'=>$object->note_public, |
|
| 431 | + $array_key.'_note'=>$object->note_public, // For backward compatibility |
|
| 432 | + |
|
| 433 | + // Payments |
|
| 434 | + $array_key.'_already_payed_locale'=>price($sumpayed, 0, $outputlangs), |
|
| 435 | + $array_key.'_already_payed'=>price2num($sumpayed), |
|
| 436 | + $array_key.'_already_deposit_locale'=>price($sumdeposit, 0, $outputlangs), |
|
| 437 | + $array_key.'_already_deposit'=>price2num($sumdeposit), |
|
| 438 | + $array_key.'_already_creditnote_locale'=>price($sumcreditnote, 0, $outputlangs), |
|
| 439 | + $array_key.'_already_creditnote'=>price2num($sumcreditnote), |
|
| 440 | + |
|
| 441 | + $array_key.'_already_payed_all_locale'=>price(price2num($sumpayed + $sumdeposit + $sumcreditnote, 'MT'), 0, $outputlangs), |
|
| 442 | + $array_key.'_already_payed_all'=> price2num(($sumpayed + $sumdeposit + $sumcreditnote), 'MT'), |
|
| 443 | + |
|
| 444 | + // Remain to pay with all know infrmation (except open direct debit requests) |
|
| 445 | + $array_key.'_remain_to_pay_locale'=>price(price2num($object->total_ttc - $sumpayed - $sumdeposit - $sumcreditnote, 'MT'), 0, $outputlangs), |
|
| 446 | + $array_key.'_remain_to_pay'=>price2num($object->total_ttc - $sumpayed - $sumdeposit - $sumcreditnote, 'MT') |
|
| 447 | + ); |
|
| 448 | + |
|
| 449 | + if (method_exists($object, 'getTotalDiscount')) { |
|
| 450 | + $resarray[$array_key.'_total_discount_ht_locale'] = price($object->getTotalDiscount(), 0, $outputlangs); |
|
| 451 | + $resarray[$array_key.'_total_discount_ht'] = price2num($object->getTotalDiscount()); |
|
| 452 | + } else { |
|
| 453 | + $resarray[$array_key.'_total_discount_ht_locale'] = ''; |
|
| 454 | + $resarray[$array_key.'_total_discount_ht'] = ''; |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + // Fetch project information if there is a project assigned to this object |
|
| 458 | + if ($object->element != "project" && ! empty($object->fk_project) && $object->fk_project > 0) |
|
| 459 | + { |
|
| 460 | + if (! is_object($object->project)) |
|
| 461 | + { |
|
| 462 | + $object->fetch_projet(); |
|
| 463 | + } |
|
| 464 | + |
|
| 465 | + $resarray[$array_key.'_project_ref'] = $object->project->ref; |
|
| 466 | + $resarray[$array_key.'_project_title'] = $object->project->title; |
|
| 467 | + $resarray[$array_key.'_project_description'] = $object->project->description; |
|
| 468 | + $resarray[$array_key.'_project_date_start'] = dol_print_date($object->project->date_start, 'day'); |
|
| 469 | + $resarray[$array_key.'_project_date_end'] = dol_print_date($object->project->date_end, 'day'); |
|
| 470 | + } |
|
| 471 | + |
|
| 472 | + // Add vat by rates |
|
| 473 | + if (is_array($object->lines) && count($object->lines)>0) |
|
| 474 | + { |
|
| 475 | + foreach ($object->lines as $line) |
|
| 476 | + { |
|
| 477 | + // $line->tva_tx format depends on database field accuraty, no reliable. This is kept for backward comaptibility |
|
| 478 | + if (empty($resarray[$array_key.'_total_vat_'.$line->tva_tx])) $resarray[$array_key.'_total_vat_'.$line->tva_tx]=0; |
|
| 479 | + $resarray[$array_key.'_total_vat_'.$line->tva_tx]+=$line->total_tva; |
|
| 480 | + $resarray[$array_key.'_total_vat_locale_'.$line->tva_tx]=price($resarray[$array_key.'_total_vat_'.$line->tva_tx]); |
|
| 481 | + // $vatformated is vat without not expected chars (so 20, or 8.5 or 5.99 for example) |
|
| 482 | + $vatformated=vatrate($line->tva_tx); |
|
| 483 | + if (empty($resarray[$array_key.'_total_vat_'.$vatformated])) $resarray[$array_key.'_total_vat_'.$vatformated]=0; |
|
| 484 | + $resarray[$array_key.'_total_vat_'.$vatformated]+=$line->total_tva; |
|
| 485 | + $resarray[$array_key.'_total_vat_locale_'.$vatformated]=price($resarray[$array_key.'_total_vat_'.$vatformated]); |
|
| 486 | + } |
|
| 487 | + } |
|
| 488 | + // Retrieve extrafields |
|
| 489 | + if (is_array($object->array_options) && count($object->array_options)) |
|
| 490 | + { |
|
| 491 | + $extrafieldkey=$object->element; |
|
| 492 | + |
|
| 493 | + require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
| 494 | + $extrafields = new ExtraFields($this->db); |
|
| 495 | + $extralabels = $extrafields->fetch_name_optionals_label($extrafieldkey,true); |
|
| 496 | + $object->fetch_optionals(); |
|
| 497 | + |
|
| 498 | + $resarray = $this->fill_substitutionarray_with_extrafields($object,$resarray,$extrafields,$array_key,$outputlangs); |
|
| 499 | + } |
|
| 500 | + return $resarray; |
|
| 501 | + } |
|
| 502 | 502 | |
| 503 | 503 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
| 504 | - /** |
|
| 505 | - * Define array with couple substitution key => substitution value |
|
| 506 | - * |
|
| 507 | - * @param Object $line Object line |
|
| 508 | - * @param Translate $outputlangs Lang object to use for output |
|
| 509 | - * @return array Return a substitution array |
|
| 510 | - */ |
|
| 511 | - function get_substitutionarray_lines($line, $outputlangs) |
|
| 512 | - { |
|
| 504 | + /** |
|
| 505 | + * Define array with couple substitution key => substitution value |
|
| 506 | + * |
|
| 507 | + * @param Object $line Object line |
|
| 508 | + * @param Translate $outputlangs Lang object to use for output |
|
| 509 | + * @return array Return a substitution array |
|
| 510 | + */ |
|
| 511 | + function get_substitutionarray_lines($line, $outputlangs) |
|
| 512 | + { |
|
| 513 | 513 | // phpcs:enable |
| 514 | - global $conf; |
|
| 515 | - |
|
| 516 | - $resarray= array( |
|
| 517 | - 'line_fulldesc'=>doc_getlinedesc($line,$outputlangs), |
|
| 518 | - 'line_product_ref'=>$line->product_ref, |
|
| 519 | - 'line_product_ref_fourn'=>$line->ref_fourn, // for supplier doc lines |
|
| 520 | - 'line_product_label'=>$line->product_label, |
|
| 521 | - 'line_product_type'=>$line->product_type, |
|
| 522 | - 'line_desc'=>$line->desc, |
|
| 523 | - 'line_vatrate'=>vatrate($line->tva_tx,true,$line->info_bits), |
|
| 524 | - 'line_up'=>price2num($line->subprice), |
|
| 525 | - 'line_up_locale'=>price($line->subprice, 0, $outputlangs), |
|
| 526 | - 'line_qty'=>$line->qty, |
|
| 527 | - 'line_discount_percent'=>($line->remise_percent?$line->remise_percent.'%':''), |
|
| 528 | - 'line_price_ht'=>price2num($line->total_ht), |
|
| 529 | - 'line_price_ttc'=>price2num($line->total_ttc), |
|
| 530 | - 'line_price_vat'=>price2num($line->total_tva), |
|
| 531 | - 'line_price_ht_locale'=>price($line->total_ht, 0, $outputlangs), |
|
| 532 | - 'line_price_ttc_locale'=>price($line->total_ttc, 0, $outputlangs), |
|
| 533 | - 'line_price_vat_locale'=>price($line->total_tva, 0, $outputlangs), |
|
| 534 | - // Dates |
|
| 535 | - 'line_date_start'=>dol_print_date($line->date_start, 'day', 'tzuser'), |
|
| 536 | - 'line_date_start_locale'=>dol_print_date($line->date_start, 'day', 'tzuser', $outputlangs), |
|
| 537 | - 'line_date_start_rfc'=>dol_print_date($line->date_start, 'dayrfc', 'tzuser'), |
|
| 538 | - 'line_date_end'=>dol_print_date($line->date_end, 'day', 'tzuser'), |
|
| 539 | - 'line_date_end_locale'=>dol_print_date($line->date_end, 'day', 'tzuser', $outputlangs), |
|
| 540 | - 'line_date_end_rfc'=>dol_print_date($line->date_end, 'dayrfc', 'tzuser'), |
|
| 541 | - |
|
| 542 | - 'line_multicurrency_code' => price2num($line->multicurrency_code), |
|
| 543 | - 'line_multicurrency_subprice' => price2num($line->multicurrency_subprice), |
|
| 544 | - 'line_multicurrency_total_ht' => price2num($line->multicurrency_total_ht), |
|
| 545 | - 'line_multicurrency_total_tva' => price2num($line->multicurrency_total_tva), |
|
| 546 | - 'line_multicurrency_total_ttc' => price2num($line->multicurrency_total_ttc), |
|
| 547 | - 'line_multicurrency_subprice_locale' => price($line->multicurrency_subprice, 0, $outputlangs), |
|
| 548 | - 'line_multicurrency_total_ht_locale' => price($line->multicurrency_total_ht, 0, $outputlangs), |
|
| 549 | - 'line_multicurrency_total_tva_locale' => price($line->multicurrency_total_tva, 0, $outputlangs), |
|
| 550 | - 'line_multicurrency_total_ttc_locale' => price($line->multicurrency_total_ttc, 0, $outputlangs), |
|
| 551 | - ); |
|
| 552 | - |
|
| 553 | - // Units |
|
| 554 | - if ($conf->global->PRODUCT_USE_UNITS) |
|
| 555 | - { |
|
| 556 | - $resarray['line_unit']=$outputlangs->trans($line->getLabelOfUnit('long')); |
|
| 557 | - $resarray['line_unit_short']=$outputlangs->trans($line->getLabelOfUnit('short')); |
|
| 558 | - } |
|
| 559 | - |
|
| 560 | - // Retrieve extrafields |
|
| 561 | - $extrafieldkey=$line->element; |
|
| 562 | - $array_key="line"; |
|
| 563 | - require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
| 564 | - $extrafields = new ExtraFields($this->db); |
|
| 565 | - $extralabels = $extrafields->fetch_name_optionals_label($extrafieldkey,true); |
|
| 566 | - $line->fetch_optionals(); |
|
| 567 | - |
|
| 568 | - $resarray = $this->fill_substitutionarray_with_extrafields($line,$resarray,$extrafields,$array_key=$array_key,$outputlangs); |
|
| 569 | - |
|
| 570 | - // Load product data optional fields to the line -> enables to use "line_options_{extrafield}" |
|
| 571 | - if (isset($line->fk_product) && $line->fk_product > 0) |
|
| 572 | - { |
|
| 573 | - $tmpproduct = new Product($this->db); |
|
| 574 | - $result = $tmpproduct->fetch($line->fk_product); |
|
| 575 | - foreach($tmpproduct->array_options as $key=>$label) |
|
| 576 | - $resarray["line_product_".$key] = $label; |
|
| 577 | - } |
|
| 578 | - |
|
| 579 | - return $resarray; |
|
| 580 | - } |
|
| 514 | + global $conf; |
|
| 515 | + |
|
| 516 | + $resarray= array( |
|
| 517 | + 'line_fulldesc'=>doc_getlinedesc($line,$outputlangs), |
|
| 518 | + 'line_product_ref'=>$line->product_ref, |
|
| 519 | + 'line_product_ref_fourn'=>$line->ref_fourn, // for supplier doc lines |
|
| 520 | + 'line_product_label'=>$line->product_label, |
|
| 521 | + 'line_product_type'=>$line->product_type, |
|
| 522 | + 'line_desc'=>$line->desc, |
|
| 523 | + 'line_vatrate'=>vatrate($line->tva_tx,true,$line->info_bits), |
|
| 524 | + 'line_up'=>price2num($line->subprice), |
|
| 525 | + 'line_up_locale'=>price($line->subprice, 0, $outputlangs), |
|
| 526 | + 'line_qty'=>$line->qty, |
|
| 527 | + 'line_discount_percent'=>($line->remise_percent?$line->remise_percent.'%':''), |
|
| 528 | + 'line_price_ht'=>price2num($line->total_ht), |
|
| 529 | + 'line_price_ttc'=>price2num($line->total_ttc), |
|
| 530 | + 'line_price_vat'=>price2num($line->total_tva), |
|
| 531 | + 'line_price_ht_locale'=>price($line->total_ht, 0, $outputlangs), |
|
| 532 | + 'line_price_ttc_locale'=>price($line->total_ttc, 0, $outputlangs), |
|
| 533 | + 'line_price_vat_locale'=>price($line->total_tva, 0, $outputlangs), |
|
| 534 | + // Dates |
|
| 535 | + 'line_date_start'=>dol_print_date($line->date_start, 'day', 'tzuser'), |
|
| 536 | + 'line_date_start_locale'=>dol_print_date($line->date_start, 'day', 'tzuser', $outputlangs), |
|
| 537 | + 'line_date_start_rfc'=>dol_print_date($line->date_start, 'dayrfc', 'tzuser'), |
|
| 538 | + 'line_date_end'=>dol_print_date($line->date_end, 'day', 'tzuser'), |
|
| 539 | + 'line_date_end_locale'=>dol_print_date($line->date_end, 'day', 'tzuser', $outputlangs), |
|
| 540 | + 'line_date_end_rfc'=>dol_print_date($line->date_end, 'dayrfc', 'tzuser'), |
|
| 541 | + |
|
| 542 | + 'line_multicurrency_code' => price2num($line->multicurrency_code), |
|
| 543 | + 'line_multicurrency_subprice' => price2num($line->multicurrency_subprice), |
|
| 544 | + 'line_multicurrency_total_ht' => price2num($line->multicurrency_total_ht), |
|
| 545 | + 'line_multicurrency_total_tva' => price2num($line->multicurrency_total_tva), |
|
| 546 | + 'line_multicurrency_total_ttc' => price2num($line->multicurrency_total_ttc), |
|
| 547 | + 'line_multicurrency_subprice_locale' => price($line->multicurrency_subprice, 0, $outputlangs), |
|
| 548 | + 'line_multicurrency_total_ht_locale' => price($line->multicurrency_total_ht, 0, $outputlangs), |
|
| 549 | + 'line_multicurrency_total_tva_locale' => price($line->multicurrency_total_tva, 0, $outputlangs), |
|
| 550 | + 'line_multicurrency_total_ttc_locale' => price($line->multicurrency_total_ttc, 0, $outputlangs), |
|
| 551 | + ); |
|
| 552 | + |
|
| 553 | + // Units |
|
| 554 | + if ($conf->global->PRODUCT_USE_UNITS) |
|
| 555 | + { |
|
| 556 | + $resarray['line_unit']=$outputlangs->trans($line->getLabelOfUnit('long')); |
|
| 557 | + $resarray['line_unit_short']=$outputlangs->trans($line->getLabelOfUnit('short')); |
|
| 558 | + } |
|
| 559 | + |
|
| 560 | + // Retrieve extrafields |
|
| 561 | + $extrafieldkey=$line->element; |
|
| 562 | + $array_key="line"; |
|
| 563 | + require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
| 564 | + $extrafields = new ExtraFields($this->db); |
|
| 565 | + $extralabels = $extrafields->fetch_name_optionals_label($extrafieldkey,true); |
|
| 566 | + $line->fetch_optionals(); |
|
| 567 | + |
|
| 568 | + $resarray = $this->fill_substitutionarray_with_extrafields($line,$resarray,$extrafields,$array_key=$array_key,$outputlangs); |
|
| 569 | + |
|
| 570 | + // Load product data optional fields to the line -> enables to use "line_options_{extrafield}" |
|
| 571 | + if (isset($line->fk_product) && $line->fk_product > 0) |
|
| 572 | + { |
|
| 573 | + $tmpproduct = new Product($this->db); |
|
| 574 | + $result = $tmpproduct->fetch($line->fk_product); |
|
| 575 | + foreach($tmpproduct->array_options as $key=>$label) |
|
| 576 | + $resarray["line_product_".$key] = $label; |
|
| 577 | + } |
|
| 578 | + |
|
| 579 | + return $resarray; |
|
| 580 | + } |
|
| 581 | 581 | |
| 582 | 582 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
| 583 | 583 | /** |
@@ -591,54 +591,54 @@ discard block |
||
| 591 | 591 | function get_substitutionarray_shipment($object,$outputlangs,$array_key='object') |
| 592 | 592 | { |
| 593 | 593 | // phpcs:enable |
| 594 | - global $conf; |
|
| 595 | - dol_include_once('/core/lib/product.lib.php'); |
|
| 596 | - $object->list_delivery_methods($object->shipping_method_id); |
|
| 597 | - $calculatedVolume=($object->trueWidth * $object->trueHeight * $object->trueDepth); |
|
| 598 | - |
|
| 599 | - $array_shipment=array( |
|
| 600 | - $array_key.'_id'=>$object->id, |
|
| 601 | - $array_key.'_ref'=>$object->ref, |
|
| 602 | - $array_key.'_ref_ext'=>$object->ref_ext, |
|
| 603 | - $array_key.'_ref_customer'=>$object->ref_customer, |
|
| 604 | - $array_key.'_date_delivery'=>dol_print_date($object->date_delivery,'day'), |
|
| 605 | - $array_key.'_hour_delivery'=>dol_print_date($object->date_delivery,'hour'), |
|
| 606 | - $array_key.'_date_creation'=>dol_print_date($object->date_creation,'day'), |
|
| 607 | - $array_key.'_total_ht'=>price($object->total_ht), |
|
| 608 | - $array_key.'_total_vat'=>price($object->total_tva), |
|
| 609 | - $array_key.'_total_ttc'=>price($object->total_ttc), |
|
| 610 | - $array_key.'_total_discount_ht' => price($object->getTotalDiscount()), |
|
| 611 | - $array_key.'_note_private'=>$object->note_private, |
|
| 612 | - $array_key.'_note'=>$object->note_public, |
|
| 613 | - $array_key.'_tracking_number'=>$object->tracking_number, |
|
| 614 | - $array_key.'_tracking_url'=>$object->tracking_url, |
|
| 615 | - $array_key.'_shipping_method'=>$object->listmeths[0]['libelle'], |
|
| 616 | - $array_key.'_weight'=>$object->trueWeight.' '.measuring_units_string($object->weight_units, 'weight'), |
|
| 617 | - $array_key.'_width'=>$object->trueWidth.' '.measuring_units_string($object->width_units, 'size'), |
|
| 618 | - $array_key.'_height'=>$object->trueHeight.' '.measuring_units_string($object->height_units, 'size'), |
|
| 619 | - $array_key.'_depth'=>$object->trueDepth.' '.measuring_units_string($object->depth_units, 'size'), |
|
| 620 | - $array_key.'_size'=>$calculatedVolume.' '.measuring_units_string(0, 'volume'), |
|
| 621 | - ); |
|
| 622 | - |
|
| 623 | - // Add vat by rates |
|
| 624 | - foreach ($object->lines as $line) |
|
| 625 | - { |
|
| 626 | - if (empty($array_shipment[$array_key.'_total_vat_'.$line->tva_tx])) $array_shipment[$array_key.'_total_vat_'.$line->tva_tx]=0; |
|
| 627 | - $array_shipment[$array_key.'_total_vat_'.$line->tva_tx]+=$line->total_tva; |
|
| 628 | - } |
|
| 629 | - |
|
| 630 | - // Retrieve extrafields |
|
| 631 | - if (is_array($object->array_options) && count($object->array_options)) |
|
| 632 | - { |
|
| 633 | - require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
| 634 | - $extrafields = new ExtraFields($this->db); |
|
| 635 | - $extralabels = $extrafields->fetch_name_optionals_label('expedition',true); |
|
| 636 | - $object->fetch_optionals(); |
|
| 637 | - |
|
| 638 | - $array_shipment = $this->fill_substitutionarray_with_extrafields($object,$array_shipment,$extrafields,$array_key,$outputlangs); |
|
| 639 | - } |
|
| 640 | - |
|
| 641 | - return $array_shipment; |
|
| 594 | + global $conf; |
|
| 595 | + dol_include_once('/core/lib/product.lib.php'); |
|
| 596 | + $object->list_delivery_methods($object->shipping_method_id); |
|
| 597 | + $calculatedVolume=($object->trueWidth * $object->trueHeight * $object->trueDepth); |
|
| 598 | + |
|
| 599 | + $array_shipment=array( |
|
| 600 | + $array_key.'_id'=>$object->id, |
|
| 601 | + $array_key.'_ref'=>$object->ref, |
|
| 602 | + $array_key.'_ref_ext'=>$object->ref_ext, |
|
| 603 | + $array_key.'_ref_customer'=>$object->ref_customer, |
|
| 604 | + $array_key.'_date_delivery'=>dol_print_date($object->date_delivery,'day'), |
|
| 605 | + $array_key.'_hour_delivery'=>dol_print_date($object->date_delivery,'hour'), |
|
| 606 | + $array_key.'_date_creation'=>dol_print_date($object->date_creation,'day'), |
|
| 607 | + $array_key.'_total_ht'=>price($object->total_ht), |
|
| 608 | + $array_key.'_total_vat'=>price($object->total_tva), |
|
| 609 | + $array_key.'_total_ttc'=>price($object->total_ttc), |
|
| 610 | + $array_key.'_total_discount_ht' => price($object->getTotalDiscount()), |
|
| 611 | + $array_key.'_note_private'=>$object->note_private, |
|
| 612 | + $array_key.'_note'=>$object->note_public, |
|
| 613 | + $array_key.'_tracking_number'=>$object->tracking_number, |
|
| 614 | + $array_key.'_tracking_url'=>$object->tracking_url, |
|
| 615 | + $array_key.'_shipping_method'=>$object->listmeths[0]['libelle'], |
|
| 616 | + $array_key.'_weight'=>$object->trueWeight.' '.measuring_units_string($object->weight_units, 'weight'), |
|
| 617 | + $array_key.'_width'=>$object->trueWidth.' '.measuring_units_string($object->width_units, 'size'), |
|
| 618 | + $array_key.'_height'=>$object->trueHeight.' '.measuring_units_string($object->height_units, 'size'), |
|
| 619 | + $array_key.'_depth'=>$object->trueDepth.' '.measuring_units_string($object->depth_units, 'size'), |
|
| 620 | + $array_key.'_size'=>$calculatedVolume.' '.measuring_units_string(0, 'volume'), |
|
| 621 | + ); |
|
| 622 | + |
|
| 623 | + // Add vat by rates |
|
| 624 | + foreach ($object->lines as $line) |
|
| 625 | + { |
|
| 626 | + if (empty($array_shipment[$array_key.'_total_vat_'.$line->tva_tx])) $array_shipment[$array_key.'_total_vat_'.$line->tva_tx]=0; |
|
| 627 | + $array_shipment[$array_key.'_total_vat_'.$line->tva_tx]+=$line->total_tva; |
|
| 628 | + } |
|
| 629 | + |
|
| 630 | + // Retrieve extrafields |
|
| 631 | + if (is_array($object->array_options) && count($object->array_options)) |
|
| 632 | + { |
|
| 633 | + require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
| 634 | + $extrafields = new ExtraFields($this->db); |
|
| 635 | + $extralabels = $extrafields->fetch_name_optionals_label('expedition',true); |
|
| 636 | + $object->fetch_optionals(); |
|
| 637 | + |
|
| 638 | + $array_shipment = $this->fill_substitutionarray_with_extrafields($object,$array_shipment,$extrafields,$array_key,$outputlangs); |
|
| 639 | + } |
|
| 640 | + |
|
| 641 | + return $array_shipment; |
|
| 642 | 642 | } |
| 643 | 643 | |
| 644 | 644 | |
@@ -657,24 +657,24 @@ discard block |
||
| 657 | 657 | dol_include_once('/core/lib/product.lib.php'); |
| 658 | 658 | |
| 659 | 659 | $resarray = array( |
| 660 | - 'line_fulldesc'=>doc_getlinedesc($line,$outputlangs), |
|
| 661 | - 'line_product_ref'=>$line->product_ref, |
|
| 662 | - 'line_product_label'=>$line->product_label, |
|
| 663 | - 'line_desc'=>$line->desc, |
|
| 664 | - 'line_vatrate'=>vatrate($line->tva_tx,true,$line->info_bits), |
|
| 665 | - 'line_up'=>price($line->subprice), |
|
| 666 | - 'line_qty'=>$line->qty, |
|
| 667 | - 'line_qty_shipped'=>$line->qty_shipped, |
|
| 668 | - 'line_qty_asked'=>$line->qty_asked, |
|
| 669 | - 'line_discount_percent'=>($line->remise_percent?$line->remise_percent.'%':''), |
|
| 670 | - 'line_price_ht'=>price($line->total_ht), |
|
| 671 | - 'line_price_ttc'=>price($line->total_ttc), |
|
| 672 | - 'line_price_vat'=>price($line->total_tva), |
|
| 673 | - 'line_weight'=>empty($line->weight) ? '' : $line->weight*$line->qty_shipped.' '.measuring_units_string($line->weight_units, 'weight'), |
|
| 674 | - 'line_length'=>empty($line->length) ? '' : $line->length*$line->qty_shipped.' '.measuring_units_string($line->length_units, 'size'), |
|
| 675 | - 'line_surface'=>empty($line->surface) ? '' : $line->surface*$line->qty_shipped.' '.measuring_units_string($line->surface_units, 'surface'), |
|
| 676 | - 'line_volume'=>empty($line->volume) ? '' : $line->volume*$line->qty_shipped.' '.measuring_units_string($line->volume_units, 'volume'), |
|
| 677 | - ); |
|
| 660 | + 'line_fulldesc'=>doc_getlinedesc($line,$outputlangs), |
|
| 661 | + 'line_product_ref'=>$line->product_ref, |
|
| 662 | + 'line_product_label'=>$line->product_label, |
|
| 663 | + 'line_desc'=>$line->desc, |
|
| 664 | + 'line_vatrate'=>vatrate($line->tva_tx,true,$line->info_bits), |
|
| 665 | + 'line_up'=>price($line->subprice), |
|
| 666 | + 'line_qty'=>$line->qty, |
|
| 667 | + 'line_qty_shipped'=>$line->qty_shipped, |
|
| 668 | + 'line_qty_asked'=>$line->qty_asked, |
|
| 669 | + 'line_discount_percent'=>($line->remise_percent?$line->remise_percent.'%':''), |
|
| 670 | + 'line_price_ht'=>price($line->total_ht), |
|
| 671 | + 'line_price_ttc'=>price($line->total_ttc), |
|
| 672 | + 'line_price_vat'=>price($line->total_tva), |
|
| 673 | + 'line_weight'=>empty($line->weight) ? '' : $line->weight*$line->qty_shipped.' '.measuring_units_string($line->weight_units, 'weight'), |
|
| 674 | + 'line_length'=>empty($line->length) ? '' : $line->length*$line->qty_shipped.' '.measuring_units_string($line->length_units, 'size'), |
|
| 675 | + 'line_surface'=>empty($line->surface) ? '' : $line->surface*$line->qty_shipped.' '.measuring_units_string($line->surface_units, 'surface'), |
|
| 676 | + 'line_volume'=>empty($line->volume) ? '' : $line->volume*$line->qty_shipped.' '.measuring_units_string($line->volume_units, 'volume'), |
|
| 677 | + ); |
|
| 678 | 678 | |
| 679 | 679 | // Retrieve extrafields |
| 680 | 680 | $extrafieldkey = $line->element; |
@@ -731,92 +731,92 @@ discard block |
||
| 731 | 731 | * @return array Substitution array |
| 732 | 732 | */ |
| 733 | 733 | function fill_substitutionarray_with_extrafields($object,$array_to_fill,$extrafields,$array_key,$outputlangs) |
| 734 | - { |
|
| 734 | + { |
|
| 735 | 735 | // phpcs:enable |
| 736 | - global $conf; |
|
| 737 | - foreach($extrafields->attribute_label as $key=>$label) |
|
| 738 | - { |
|
| 739 | - if($extrafields->attribute_type[$key] == 'price') |
|
| 740 | - { |
|
| 741 | - $object->array_options['options_'.$key] = price2num($object->array_options['options_'.$key]); |
|
| 742 | - $object->array_options['options_'.$key.'_currency'] = price($object->array_options['options_'.$key],0,$outputlangs,0,0,-1,$conf->currency); |
|
| 743 | - //Add value to store price with currency |
|
| 744 | - $array_to_fill=array_merge($array_to_fill,array($array_key.'_options_'.$key.'_currency' => $object->array_options['options_'.$key.'_currency'])); |
|
| 745 | - } |
|
| 746 | - else if($extrafields->attribute_type[$key] == 'select' || $extrafields->attribute_type[$key] == 'checkbox') |
|
| 747 | - { |
|
| 748 | - $object->array_options['options_'.$key] = $extrafields->attribute_param[$key]['options'][$object->array_options['options_'.$key]]; |
|
| 749 | - } |
|
| 750 | - else if($extrafields->attribute_type[$key] == 'date') |
|
| 751 | - { |
|
| 752 | - if (strlen($object->array_options['options_'.$key])>0) |
|
| 753 | - { |
|
| 754 | - $date = $object->array_options['options_'.$key]; |
|
| 755 | - $object->array_options['options_'.$key] = dol_print_date($date,'day'); // using company output language |
|
| 756 | - $object->array_options['options_'.$key.'_locale'] = dol_print_date($date,'day','tzserver',$outputlangs); // using output language format |
|
| 757 | - $object->array_options['options_'.$key.'_rfc'] = dol_print_date($date,'dayrfc'); // international format |
|
| 758 | - } |
|
| 759 | - else |
|
| 760 | - { |
|
| 761 | - $object->array_options['options_'.$key] = ''; |
|
| 762 | - $object->array_options['options_'.$key.'_locale'] = ''; |
|
| 763 | - $object->array_options['options_'.$key.'_rfc'] = ''; |
|
| 764 | - } |
|
| 765 | - $array_to_fill=array_merge($array_to_fill,array($array_key.'_options_'.$key.'_locale' => $object->array_options['options_'.$key.'_locale'])); |
|
| 766 | - $array_to_fill=array_merge($array_to_fill,array($array_key.'_options_'.$key.'_rfc' => $object->array_options['options_'.$key.'_rfc'])); |
|
| 767 | - } |
|
| 768 | - else if($extrafields->attribute_type[$key] == 'datetime') |
|
| 769 | - { |
|
| 770 | - $datetime = $object->array_options['options_'.$key]; |
|
| 771 | - $object->array_options['options_'.$key] = ($datetime!="0000-00-00 00:00:00"?dol_print_date($object->array_options['options_'.$key],'dayhour'):''); // using company output language |
|
| 772 | - $object->array_options['options_'.$key.'_locale'] = ($datetime!="0000-00-00 00:00:00"?dol_print_date($object->array_options['options_'.$key],'dayhour','tzserver',$outputlangs):''); // using output language format |
|
| 773 | - $object->array_options['options_'.$key.'_rfc'] = ($datetime!="0000-00-00 00:00:00"?dol_print_date($object->array_options['options_'.$key],'dayhourrfc'):''); // international format |
|
| 774 | - $array_to_fill=array_merge($array_to_fill,array($array_key.'_options_'.$key.'_locale' => $object->array_options['options_'.$key.'_locale'])); |
|
| 775 | - $array_to_fill=array_merge($array_to_fill,array($array_key.'_options_'.$key.'_rfc' => $object->array_options['options_'.$key.'_rfc'])); |
|
| 776 | - } |
|
| 777 | - else if($extrafields->attribute_type[$key] == 'link') |
|
| 778 | - { |
|
| 779 | - $id = $object->array_options['options_'.$key]; |
|
| 780 | - if ($id != "") |
|
| 781 | - { |
|
| 782 | - $param = $extrafields->attribute_param[$key]; |
|
| 783 | - $param_list=array_keys($param['options']); // $param_list='ObjectName:classPath' |
|
| 784 | - $InfoFieldList = explode(":", $param_list[0]); |
|
| 785 | - $classname=$InfoFieldList[0]; |
|
| 786 | - $classpath=$InfoFieldList[1]; |
|
| 787 | - if (! empty($classpath)) |
|
| 788 | - { |
|
| 789 | - dol_include_once($InfoFieldList[1]); |
|
| 790 | - if ($classname && class_exists($classname)) |
|
| 791 | - { |
|
| 792 | - $tmpobject = new $classname($this->db); |
|
| 793 | - $tmpobject->fetch($id); |
|
| 794 | - // completely replace the id with the linked object name |
|
| 795 | - $object->array_options['options_'.$key] = $tmpobject->name; |
|
| 796 | - } |
|
| 797 | - } |
|
| 798 | - } |
|
| 799 | - } |
|
| 800 | - |
|
| 801 | - $array_to_fill=array_merge($array_to_fill,array($array_key.'_options_'.$key => $object->array_options['options_'.$key])); |
|
| 802 | - } |
|
| 803 | - |
|
| 804 | - return $array_to_fill; |
|
| 805 | - } |
|
| 806 | - |
|
| 807 | - |
|
| 808 | - /** |
|
| 809 | - * Rect pdf |
|
| 810 | - * |
|
| 811 | - * @param TCPDF $pdf Object PDF |
|
| 812 | - * @param float $x Abscissa of first point |
|
| 813 | - * @param float $y Ordinate of first point |
|
| 814 | - * @param float $l ?? |
|
| 815 | - * @param float $h ?? |
|
| 816 | - * @param int $hidetop 1=Hide top bar of array and title, 0=Hide nothing, -1=Hide only title |
|
| 817 | - * @param int $hidebottom Hide bottom |
|
| 818 | - * @return void |
|
| 819 | - */ |
|
| 736 | + global $conf; |
|
| 737 | + foreach($extrafields->attribute_label as $key=>$label) |
|
| 738 | + { |
|
| 739 | + if($extrafields->attribute_type[$key] == 'price') |
|
| 740 | + { |
|
| 741 | + $object->array_options['options_'.$key] = price2num($object->array_options['options_'.$key]); |
|
| 742 | + $object->array_options['options_'.$key.'_currency'] = price($object->array_options['options_'.$key],0,$outputlangs,0,0,-1,$conf->currency); |
|
| 743 | + //Add value to store price with currency |
|
| 744 | + $array_to_fill=array_merge($array_to_fill,array($array_key.'_options_'.$key.'_currency' => $object->array_options['options_'.$key.'_currency'])); |
|
| 745 | + } |
|
| 746 | + else if($extrafields->attribute_type[$key] == 'select' || $extrafields->attribute_type[$key] == 'checkbox') |
|
| 747 | + { |
|
| 748 | + $object->array_options['options_'.$key] = $extrafields->attribute_param[$key]['options'][$object->array_options['options_'.$key]]; |
|
| 749 | + } |
|
| 750 | + else if($extrafields->attribute_type[$key] == 'date') |
|
| 751 | + { |
|
| 752 | + if (strlen($object->array_options['options_'.$key])>0) |
|
| 753 | + { |
|
| 754 | + $date = $object->array_options['options_'.$key]; |
|
| 755 | + $object->array_options['options_'.$key] = dol_print_date($date,'day'); // using company output language |
|
| 756 | + $object->array_options['options_'.$key.'_locale'] = dol_print_date($date,'day','tzserver',$outputlangs); // using output language format |
|
| 757 | + $object->array_options['options_'.$key.'_rfc'] = dol_print_date($date,'dayrfc'); // international format |
|
| 758 | + } |
|
| 759 | + else |
|
| 760 | + { |
|
| 761 | + $object->array_options['options_'.$key] = ''; |
|
| 762 | + $object->array_options['options_'.$key.'_locale'] = ''; |
|
| 763 | + $object->array_options['options_'.$key.'_rfc'] = ''; |
|
| 764 | + } |
|
| 765 | + $array_to_fill=array_merge($array_to_fill,array($array_key.'_options_'.$key.'_locale' => $object->array_options['options_'.$key.'_locale'])); |
|
| 766 | + $array_to_fill=array_merge($array_to_fill,array($array_key.'_options_'.$key.'_rfc' => $object->array_options['options_'.$key.'_rfc'])); |
|
| 767 | + } |
|
| 768 | + else if($extrafields->attribute_type[$key] == 'datetime') |
|
| 769 | + { |
|
| 770 | + $datetime = $object->array_options['options_'.$key]; |
|
| 771 | + $object->array_options['options_'.$key] = ($datetime!="0000-00-00 00:00:00"?dol_print_date($object->array_options['options_'.$key],'dayhour'):''); // using company output language |
|
| 772 | + $object->array_options['options_'.$key.'_locale'] = ($datetime!="0000-00-00 00:00:00"?dol_print_date($object->array_options['options_'.$key],'dayhour','tzserver',$outputlangs):''); // using output language format |
|
| 773 | + $object->array_options['options_'.$key.'_rfc'] = ($datetime!="0000-00-00 00:00:00"?dol_print_date($object->array_options['options_'.$key],'dayhourrfc'):''); // international format |
|
| 774 | + $array_to_fill=array_merge($array_to_fill,array($array_key.'_options_'.$key.'_locale' => $object->array_options['options_'.$key.'_locale'])); |
|
| 775 | + $array_to_fill=array_merge($array_to_fill,array($array_key.'_options_'.$key.'_rfc' => $object->array_options['options_'.$key.'_rfc'])); |
|
| 776 | + } |
|
| 777 | + else if($extrafields->attribute_type[$key] == 'link') |
|
| 778 | + { |
|
| 779 | + $id = $object->array_options['options_'.$key]; |
|
| 780 | + if ($id != "") |
|
| 781 | + { |
|
| 782 | + $param = $extrafields->attribute_param[$key]; |
|
| 783 | + $param_list=array_keys($param['options']); // $param_list='ObjectName:classPath' |
|
| 784 | + $InfoFieldList = explode(":", $param_list[0]); |
|
| 785 | + $classname=$InfoFieldList[0]; |
|
| 786 | + $classpath=$InfoFieldList[1]; |
|
| 787 | + if (! empty($classpath)) |
|
| 788 | + { |
|
| 789 | + dol_include_once($InfoFieldList[1]); |
|
| 790 | + if ($classname && class_exists($classname)) |
|
| 791 | + { |
|
| 792 | + $tmpobject = new $classname($this->db); |
|
| 793 | + $tmpobject->fetch($id); |
|
| 794 | + // completely replace the id with the linked object name |
|
| 795 | + $object->array_options['options_'.$key] = $tmpobject->name; |
|
| 796 | + } |
|
| 797 | + } |
|
| 798 | + } |
|
| 799 | + } |
|
| 800 | + |
|
| 801 | + $array_to_fill=array_merge($array_to_fill,array($array_key.'_options_'.$key => $object->array_options['options_'.$key])); |
|
| 802 | + } |
|
| 803 | + |
|
| 804 | + return $array_to_fill; |
|
| 805 | + } |
|
| 806 | + |
|
| 807 | + |
|
| 808 | + /** |
|
| 809 | + * Rect pdf |
|
| 810 | + * |
|
| 811 | + * @param TCPDF $pdf Object PDF |
|
| 812 | + * @param float $x Abscissa of first point |
|
| 813 | + * @param float $y Ordinate of first point |
|
| 814 | + * @param float $l ?? |
|
| 815 | + * @param float $h ?? |
|
| 816 | + * @param int $hidetop 1=Hide top bar of array and title, 0=Hide nothing, -1=Hide only title |
|
| 817 | + * @param int $hidebottom Hide bottom |
|
| 818 | + * @return void |
|
| 819 | + */ |
|
| 820 | 820 | function printRect($pdf, $x, $y, $l, $h, $hidetop=0, $hidebottom=0) |
| 821 | 821 | { |
| 822 | 822 | if (empty($hidetop) || $hidetop==-1) $pdf->line($x, $y, $x+$l, $y); |