@@ -29,42 +29,42 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | function emailing_prepare_head(Mailing $object) |
| 31 | 31 | { |
| 32 | - global $user, $langs, $conf; |
|
| 32 | + global $user, $langs, $conf; |
|
| 33 | 33 | |
| 34 | - $h = 0; |
|
| 35 | - $head = array(); |
|
| 34 | + $h = 0; |
|
| 35 | + $head = array(); |
|
| 36 | 36 | |
| 37 | - $head[$h][0] = DOL_URL_ROOT."/comm/mailing/card.php?id=".$object->id; |
|
| 38 | - $head[$h][1] = $langs->trans("MailCard"); |
|
| 39 | - $head[$h][2] = 'card'; |
|
| 40 | - $h++; |
|
| 37 | + $head[$h][0] = DOL_URL_ROOT."/comm/mailing/card.php?id=".$object->id; |
|
| 38 | + $head[$h][1] = $langs->trans("MailCard"); |
|
| 39 | + $head[$h][2] = 'card'; |
|
| 40 | + $h++; |
|
| 41 | 41 | |
| 42 | - if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->mailing->mailing_advance->recipient)) |
|
| 43 | - { |
|
| 44 | - $head[$h][0] = DOL_URL_ROOT."/comm/mailing/cibles.php?id=".$object->id; |
|
| 45 | - $head[$h][1] = $langs->trans("MailRecipients"); |
|
| 46 | - if ($object->nbemail > 0) $head[$h][1].= ' <span class="badge">'.$object->nbemail.'</span>'; |
|
| 47 | - $head[$h][2] = 'targets'; |
|
| 48 | - $h++; |
|
| 49 | - } |
|
| 42 | + if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->mailing->mailing_advance->recipient)) |
|
| 43 | + { |
|
| 44 | + $head[$h][0] = DOL_URL_ROOT."/comm/mailing/cibles.php?id=".$object->id; |
|
| 45 | + $head[$h][1] = $langs->trans("MailRecipients"); |
|
| 46 | + if ($object->nbemail > 0) $head[$h][1].= ' <span class="badge">'.$object->nbemail.'</span>'; |
|
| 47 | + $head[$h][2] = 'targets'; |
|
| 48 | + $h++; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - if (! empty($conf->global->EMAILING_USE_ADVANCED_SELECTOR)) |
|
| 52 | - { |
|
| 53 | - $head[$h][0] = DOL_URL_ROOT."/comm/mailing/advtargetemailing.php?id=".$object->id; |
|
| 54 | - $head[$h][1] = $langs->trans("MailAdvTargetRecipients"); |
|
| 55 | - $head[$h][2] = 'advtargets'; |
|
| 56 | - $h++; |
|
| 57 | - } |
|
| 51 | + if (! empty($conf->global->EMAILING_USE_ADVANCED_SELECTOR)) |
|
| 52 | + { |
|
| 53 | + $head[$h][0] = DOL_URL_ROOT."/comm/mailing/advtargetemailing.php?id=".$object->id; |
|
| 54 | + $head[$h][1] = $langs->trans("MailAdvTargetRecipients"); |
|
| 55 | + $head[$h][2] = 'advtargets'; |
|
| 56 | + $h++; |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - $head[$h][0] = DOL_URL_ROOT."/comm/mailing/info.php?id=".$object->id; |
|
| 60 | - $head[$h][1] = $langs->trans("Info"); |
|
| 61 | - $head[$h][2] = 'info'; |
|
| 62 | - $h++; |
|
| 59 | + $head[$h][0] = DOL_URL_ROOT."/comm/mailing/info.php?id=".$object->id; |
|
| 60 | + $head[$h][1] = $langs->trans("Info"); |
|
| 61 | + $head[$h][2] = 'info'; |
|
| 62 | + $h++; |
|
| 63 | 63 | |
| 64 | - complete_head_from_modules($conf,$langs,$object,$head,$h,'emailing'); |
|
| 64 | + complete_head_from_modules($conf,$langs,$object,$head,$h,'emailing'); |
|
| 65 | 65 | |
| 66 | - complete_head_from_modules($conf,$langs,$object,$head,$h,'emailing','remove'); |
|
| 66 | + complete_head_from_modules($conf,$langs,$object,$head,$h,'emailing','remove'); |
|
| 67 | 67 | |
| 68 | - return $head; |
|
| 68 | + return $head; |
|
| 69 | 69 | } |
| 70 | 70 | |
@@ -39,16 +39,16 @@ discard block |
||
| 39 | 39 | $head[$h][2] = 'card'; |
| 40 | 40 | $h++; |
| 41 | 41 | |
| 42 | - if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->mailing->mailing_advance->recipient)) |
|
| 42 | + if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->mailing->mailing_advance->recipient)) |
|
| 43 | 43 | { |
| 44 | 44 | $head[$h][0] = DOL_URL_ROOT."/comm/mailing/cibles.php?id=".$object->id; |
| 45 | 45 | $head[$h][1] = $langs->trans("MailRecipients"); |
| 46 | - if ($object->nbemail > 0) $head[$h][1].= ' <span class="badge">'.$object->nbemail.'</span>'; |
|
| 46 | + if ($object->nbemail > 0) $head[$h][1] .= ' <span class="badge">'.$object->nbemail.'</span>'; |
|
| 47 | 47 | $head[$h][2] = 'targets'; |
| 48 | 48 | $h++; |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - if (! empty($conf->global->EMAILING_USE_ADVANCED_SELECTOR)) |
|
| 51 | + if (!empty($conf->global->EMAILING_USE_ADVANCED_SELECTOR)) |
|
| 52 | 52 | { |
| 53 | 53 | $head[$h][0] = DOL_URL_ROOT."/comm/mailing/advtargetemailing.php?id=".$object->id; |
| 54 | 54 | $head[$h][1] = $langs->trans("MailAdvTargetRecipients"); |
@@ -61,9 +61,9 @@ discard block |
||
| 61 | 61 | $head[$h][2] = 'info'; |
| 62 | 62 | $h++; |
| 63 | 63 | |
| 64 | - complete_head_from_modules($conf,$langs,$object,$head,$h,'emailing'); |
|
| 64 | + complete_head_from_modules($conf, $langs, $object, $head, $h, 'emailing'); |
|
| 65 | 65 | |
| 66 | - complete_head_from_modules($conf,$langs,$object,$head,$h,'emailing','remove'); |
|
| 66 | + complete_head_from_modules($conf, $langs, $object, $head, $h, 'emailing', 'remove'); |
|
| 67 | 67 | |
| 68 | 68 | return $head; |
| 69 | 69 | } |
@@ -43,7 +43,9 @@ |
||
| 43 | 43 | { |
| 44 | 44 | $head[$h][0] = DOL_URL_ROOT."/comm/mailing/cibles.php?id=".$object->id; |
| 45 | 45 | $head[$h][1] = $langs->trans("MailRecipients"); |
| 46 | - if ($object->nbemail > 0) $head[$h][1].= ' <span class="badge">'.$object->nbemail.'</span>'; |
|
| 46 | + if ($object->nbemail > 0) { |
|
| 47 | + $head[$h][1].= ' <span class="badge">'.$object->nbemail.'</span>'; |
|
| 48 | + } |
|
| 47 | 49 | $head[$h][2] = 'targets'; |
| 48 | 50 | $h++; |
| 49 | 51 | } |
@@ -33,48 +33,48 @@ discard block |
||
| 33 | 33 | */ |
| 34 | 34 | function commande_prepare_head(Commande $object) |
| 35 | 35 | { |
| 36 | - global $db, $langs, $conf, $user; |
|
| 37 | - if (! empty($conf->expedition->enabled)) $langs->load("sendings"); |
|
| 38 | - $langs->load("orders"); |
|
| 39 | - |
|
| 40 | - $h = 0; |
|
| 41 | - $head = array(); |
|
| 42 | - |
|
| 43 | - if (! empty($conf->commande->enabled) && $user->rights->commande->lire) |
|
| 44 | - { |
|
| 45 | - $head[$h][0] = DOL_URL_ROOT.'/commande/card.php?id='.$object->id; |
|
| 46 | - $head[$h][1] = $langs->trans("OrderCard"); |
|
| 47 | - $head[$h][2] = 'order'; |
|
| 48 | - $h++; |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) |
|
| 52 | - { |
|
| 53 | - $nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external')); |
|
| 54 | - $head[$h][0] = DOL_URL_ROOT.'/commande/contact.php?id='.$object->id; |
|
| 55 | - $head[$h][1] = $langs->trans('ContactsAddresses'); |
|
| 56 | - if ($nbContact > 0) $head[$h][1].= ' <span class="badge">'.$nbContact.'</span>'; |
|
| 57 | - $head[$h][2] = 'contact'; |
|
| 58 | - $h++; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - if (($conf->expedition_bon->enabled && $user->rights->expedition->lire) |
|
| 62 | - || ($conf->livraison_bon->enabled && $user->rights->expedition->livraison->lire)) |
|
| 63 | - { |
|
| 64 | - $nbShipments=$object->getNbOfShipments(); $nbReceiption=0; |
|
| 65 | - $head[$h][0] = DOL_URL_ROOT.'/expedition/shipment.php?id='.$object->id; |
|
| 66 | - $text=''; |
|
| 67 | - if ($conf->expedition_bon->enabled) $text.=$langs->trans("Shipments"); |
|
| 68 | - if ($conf->expedition_bon->enabled && $conf->livraison_bon->enabled) $text.='/'; |
|
| 69 | - if ($conf->livraison_bon->enabled) $text.=$langs->trans("Receivings"); |
|
| 70 | - if ($nbShipments > 0 || $nbReceiption > 0) $text.= ' <span class="badge">'.($nbShipments?$nbShipments:0); |
|
| 71 | - if ($conf->expedition_bon->enabled && $conf->livraison_bon->enabled) $text.='/'; |
|
| 72 | - if ($conf->expedition_bon->enabled && $conf->livraison_bon->enabled && ($nbShipments > 0 || $nbReceiption > 0)) $text.= ($nbReceiption?$nbReceiption:0); |
|
| 73 | - if ($nbShipments > 0 || $nbReceiption > 0) $text.= '</span>'; |
|
| 74 | - $head[$h][1] = $text; |
|
| 75 | - $head[$h][2] = 'shipping'; |
|
| 76 | - $h++; |
|
| 77 | - } |
|
| 36 | + global $db, $langs, $conf, $user; |
|
| 37 | + if (! empty($conf->expedition->enabled)) $langs->load("sendings"); |
|
| 38 | + $langs->load("orders"); |
|
| 39 | + |
|
| 40 | + $h = 0; |
|
| 41 | + $head = array(); |
|
| 42 | + |
|
| 43 | + if (! empty($conf->commande->enabled) && $user->rights->commande->lire) |
|
| 44 | + { |
|
| 45 | + $head[$h][0] = DOL_URL_ROOT.'/commande/card.php?id='.$object->id; |
|
| 46 | + $head[$h][1] = $langs->trans("OrderCard"); |
|
| 47 | + $head[$h][2] = 'order'; |
|
| 48 | + $h++; |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) |
|
| 52 | + { |
|
| 53 | + $nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external')); |
|
| 54 | + $head[$h][0] = DOL_URL_ROOT.'/commande/contact.php?id='.$object->id; |
|
| 55 | + $head[$h][1] = $langs->trans('ContactsAddresses'); |
|
| 56 | + if ($nbContact > 0) $head[$h][1].= ' <span class="badge">'.$nbContact.'</span>'; |
|
| 57 | + $head[$h][2] = 'contact'; |
|
| 58 | + $h++; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + if (($conf->expedition_bon->enabled && $user->rights->expedition->lire) |
|
| 62 | + || ($conf->livraison_bon->enabled && $user->rights->expedition->livraison->lire)) |
|
| 63 | + { |
|
| 64 | + $nbShipments=$object->getNbOfShipments(); $nbReceiption=0; |
|
| 65 | + $head[$h][0] = DOL_URL_ROOT.'/expedition/shipment.php?id='.$object->id; |
|
| 66 | + $text=''; |
|
| 67 | + if ($conf->expedition_bon->enabled) $text.=$langs->trans("Shipments"); |
|
| 68 | + if ($conf->expedition_bon->enabled && $conf->livraison_bon->enabled) $text.='/'; |
|
| 69 | + if ($conf->livraison_bon->enabled) $text.=$langs->trans("Receivings"); |
|
| 70 | + if ($nbShipments > 0 || $nbReceiption > 0) $text.= ' <span class="badge">'.($nbShipments?$nbShipments:0); |
|
| 71 | + if ($conf->expedition_bon->enabled && $conf->livraison_bon->enabled) $text.='/'; |
|
| 72 | + if ($conf->expedition_bon->enabled && $conf->livraison_bon->enabled && ($nbShipments > 0 || $nbReceiption > 0)) $text.= ($nbReceiption?$nbReceiption:0); |
|
| 73 | + if ($nbShipments > 0 || $nbReceiption > 0) $text.= '</span>'; |
|
| 74 | + $head[$h][1] = $text; |
|
| 75 | + $head[$h][2] = 'shipping'; |
|
| 76 | + $h++; |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | 79 | // Show more tabs from modules |
| 80 | 80 | // Entries must be declared in modules descriptor with line |
@@ -82,33 +82,33 @@ discard block |
||
| 82 | 82 | // $this->tabs = array('entity:-tabname); to remove a tab |
| 83 | 83 | complete_head_from_modules($conf,$langs,$object,$head,$h,'order'); |
| 84 | 84 | |
| 85 | - if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) |
|
| 86 | - { |
|
| 87 | - $nbNote = 0; |
|
| 85 | + if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) |
|
| 86 | + { |
|
| 87 | + $nbNote = 0; |
|
| 88 | 88 | if(!empty($object->note_private)) $nbNote++; |
| 89 | - if(!empty($object->note_public)) $nbNote++; |
|
| 90 | - $head[$h][0] = DOL_URL_ROOT.'/commande/note.php?id='.$object->id; |
|
| 91 | - $head[$h][1] = $langs->trans('Notes'); |
|
| 92 | - if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>'; |
|
| 93 | - $head[$h][2] = 'note'; |
|
| 94 | - $h++; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
| 89 | + if(!empty($object->note_public)) $nbNote++; |
|
| 90 | + $head[$h][0] = DOL_URL_ROOT.'/commande/note.php?id='.$object->id; |
|
| 91 | + $head[$h][1] = $langs->trans('Notes'); |
|
| 92 | + if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>'; |
|
| 93 | + $head[$h][2] = 'note'; |
|
| 94 | + $h++; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
| 98 | 98 | require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php'; |
| 99 | - $upload_dir = $conf->commande->dir_output . "/" . dol_sanitizeFileName($object->ref); |
|
| 100 | - $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview.*\.png)$')); |
|
| 99 | + $upload_dir = $conf->commande->dir_output . "/" . dol_sanitizeFileName($object->ref); |
|
| 100 | + $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview.*\.png)$')); |
|
| 101 | 101 | $nbLinks=Link::count($db, $object->element, $object->id); |
| 102 | - $head[$h][0] = DOL_URL_ROOT.'/commande/document.php?id='.$object->id; |
|
| 103 | - $head[$h][1] = $langs->trans('Documents'); |
|
| 104 | - if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>'; |
|
| 105 | - $head[$h][2] = 'documents'; |
|
| 106 | - $h++; |
|
| 102 | + $head[$h][0] = DOL_URL_ROOT.'/commande/document.php?id='.$object->id; |
|
| 103 | + $head[$h][1] = $langs->trans('Documents'); |
|
| 104 | + if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>'; |
|
| 105 | + $head[$h][2] = 'documents'; |
|
| 106 | + $h++; |
|
| 107 | 107 | |
| 108 | - $head[$h][0] = DOL_URL_ROOT.'/commande/info.php?id='.$object->id; |
|
| 109 | - $head[$h][1] = $langs->trans("Info"); |
|
| 110 | - $head[$h][2] = 'info'; |
|
| 111 | - $h++; |
|
| 108 | + $head[$h][0] = DOL_URL_ROOT.'/commande/info.php?id='.$object->id; |
|
| 109 | + $head[$h][1] = $langs->trans("Info"); |
|
| 110 | + $head[$h][2] = 'info'; |
|
| 111 | + $h++; |
|
| 112 | 112 | |
| 113 | 113 | complete_head_from_modules($conf,$langs,$object,$head,$h,'order','remove'); |
| 114 | 114 | |
@@ -122,31 +122,31 @@ discard block |
||
| 122 | 122 | */ |
| 123 | 123 | function order_admin_prepare_head() |
| 124 | 124 | { |
| 125 | - global $langs, $conf, $user; |
|
| 125 | + global $langs, $conf, $user; |
|
| 126 | 126 | |
| 127 | - $h = 0; |
|
| 128 | - $head = array(); |
|
| 127 | + $h = 0; |
|
| 128 | + $head = array(); |
|
| 129 | 129 | |
| 130 | - $head[$h][0] = DOL_URL_ROOT.'/admin/commande.php'; |
|
| 131 | - $head[$h][1] = $langs->trans("Miscellaneous"); |
|
| 132 | - $head[$h][2] = 'general'; |
|
| 133 | - $h++; |
|
| 130 | + $head[$h][0] = DOL_URL_ROOT.'/admin/commande.php'; |
|
| 131 | + $head[$h][1] = $langs->trans("Miscellaneous"); |
|
| 132 | + $head[$h][2] = 'general'; |
|
| 133 | + $h++; |
|
| 134 | 134 | |
| 135 | - complete_head_from_modules($conf,$langs,null,$head,$h,'order_admin'); |
|
| 135 | + complete_head_from_modules($conf,$langs,null,$head,$h,'order_admin'); |
|
| 136 | 136 | |
| 137 | - $head[$h][0] = DOL_URL_ROOT.'/admin/order_extrafields.php'; |
|
| 138 | - $head[$h][1] = $langs->trans("ExtraFields"); |
|
| 139 | - $head[$h][2] = 'attributes'; |
|
| 140 | - $h++; |
|
| 137 | + $head[$h][0] = DOL_URL_ROOT.'/admin/order_extrafields.php'; |
|
| 138 | + $head[$h][1] = $langs->trans("ExtraFields"); |
|
| 139 | + $head[$h][2] = 'attributes'; |
|
| 140 | + $h++; |
|
| 141 | 141 | |
| 142 | - $head[$h][0] = DOL_URL_ROOT.'/admin/orderdet_extrafields.php'; |
|
| 143 | - $head[$h][1] = $langs->trans("ExtraFieldsLines"); |
|
| 144 | - $head[$h][2] = 'attributeslines'; |
|
| 145 | - $h++; |
|
| 142 | + $head[$h][0] = DOL_URL_ROOT.'/admin/orderdet_extrafields.php'; |
|
| 143 | + $head[$h][1] = $langs->trans("ExtraFieldsLines"); |
|
| 144 | + $head[$h][2] = 'attributeslines'; |
|
| 145 | + $h++; |
|
| 146 | 146 | |
| 147 | - complete_head_from_modules($conf,$langs,null,$head,$h,'order_admin','remove'); |
|
| 147 | + complete_head_from_modules($conf,$langs,null,$head,$h,'order_admin','remove'); |
|
| 148 | 148 | |
| 149 | - return $head; |
|
| 149 | + return $head; |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | |
@@ -34,13 +34,13 @@ discard block |
||
| 34 | 34 | function commande_prepare_head(Commande $object) |
| 35 | 35 | { |
| 36 | 36 | global $db, $langs, $conf, $user; |
| 37 | - if (! empty($conf->expedition->enabled)) $langs->load("sendings"); |
|
| 37 | + if (!empty($conf->expedition->enabled)) $langs->load("sendings"); |
|
| 38 | 38 | $langs->load("orders"); |
| 39 | 39 | |
| 40 | 40 | $h = 0; |
| 41 | 41 | $head = array(); |
| 42 | 42 | |
| 43 | - if (! empty($conf->commande->enabled) && $user->rights->commande->lire) |
|
| 43 | + if (!empty($conf->commande->enabled) && $user->rights->commande->lire) |
|
| 44 | 44 | { |
| 45 | 45 | $head[$h][0] = DOL_URL_ROOT.'/commande/card.php?id='.$object->id; |
| 46 | 46 | $head[$h][1] = $langs->trans("OrderCard"); |
@@ -50,10 +50,10 @@ discard block |
||
| 50 | 50 | |
| 51 | 51 | if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) |
| 52 | 52 | { |
| 53 | - $nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external')); |
|
| 53 | + $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external')); |
|
| 54 | 54 | $head[$h][0] = DOL_URL_ROOT.'/commande/contact.php?id='.$object->id; |
| 55 | 55 | $head[$h][1] = $langs->trans('ContactsAddresses'); |
| 56 | - if ($nbContact > 0) $head[$h][1].= ' <span class="badge">'.$nbContact.'</span>'; |
|
| 56 | + if ($nbContact > 0) $head[$h][1] .= ' <span class="badge">'.$nbContact.'</span>'; |
|
| 57 | 57 | $head[$h][2] = 'contact'; |
| 58 | 58 | $h++; |
| 59 | 59 | } |
@@ -61,16 +61,16 @@ discard block |
||
| 61 | 61 | if (($conf->expedition_bon->enabled && $user->rights->expedition->lire) |
| 62 | 62 | || ($conf->livraison_bon->enabled && $user->rights->expedition->livraison->lire)) |
| 63 | 63 | { |
| 64 | - $nbShipments=$object->getNbOfShipments(); $nbReceiption=0; |
|
| 64 | + $nbShipments = $object->getNbOfShipments(); $nbReceiption = 0; |
|
| 65 | 65 | $head[$h][0] = DOL_URL_ROOT.'/expedition/shipment.php?id='.$object->id; |
| 66 | - $text=''; |
|
| 67 | - if ($conf->expedition_bon->enabled) $text.=$langs->trans("Shipments"); |
|
| 68 | - if ($conf->expedition_bon->enabled && $conf->livraison_bon->enabled) $text.='/'; |
|
| 69 | - if ($conf->livraison_bon->enabled) $text.=$langs->trans("Receivings"); |
|
| 70 | - if ($nbShipments > 0 || $nbReceiption > 0) $text.= ' <span class="badge">'.($nbShipments?$nbShipments:0); |
|
| 71 | - if ($conf->expedition_bon->enabled && $conf->livraison_bon->enabled) $text.='/'; |
|
| 72 | - if ($conf->expedition_bon->enabled && $conf->livraison_bon->enabled && ($nbShipments > 0 || $nbReceiption > 0)) $text.= ($nbReceiption?$nbReceiption:0); |
|
| 73 | - if ($nbShipments > 0 || $nbReceiption > 0) $text.= '</span>'; |
|
| 66 | + $text = ''; |
|
| 67 | + if ($conf->expedition_bon->enabled) $text .= $langs->trans("Shipments"); |
|
| 68 | + if ($conf->expedition_bon->enabled && $conf->livraison_bon->enabled) $text .= '/'; |
|
| 69 | + if ($conf->livraison_bon->enabled) $text .= $langs->trans("Receivings"); |
|
| 70 | + if ($nbShipments > 0 || $nbReceiption > 0) $text .= ' <span class="badge">'.($nbShipments ? $nbShipments : 0); |
|
| 71 | + if ($conf->expedition_bon->enabled && $conf->livraison_bon->enabled) $text .= '/'; |
|
| 72 | + if ($conf->expedition_bon->enabled && $conf->livraison_bon->enabled && ($nbShipments > 0 || $nbReceiption > 0)) $text .= ($nbReceiption ? $nbReceiption : 0); |
|
| 73 | + if ($nbShipments > 0 || $nbReceiption > 0) $text .= '</span>'; |
|
| 74 | 74 | $head[$h][1] = $text; |
| 75 | 75 | $head[$h][2] = 'shipping'; |
| 76 | 76 | $h++; |
@@ -80,28 +80,28 @@ discard block |
||
| 80 | 80 | // Entries must be declared in modules descriptor with line |
| 81 | 81 | // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab |
| 82 | 82 | // $this->tabs = array('entity:-tabname); to remove a tab |
| 83 | - complete_head_from_modules($conf,$langs,$object,$head,$h,'order'); |
|
| 83 | + complete_head_from_modules($conf, $langs, $object, $head, $h, 'order'); |
|
| 84 | 84 | |
| 85 | 85 | if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) |
| 86 | 86 | { |
| 87 | 87 | $nbNote = 0; |
| 88 | - if(!empty($object->note_private)) $nbNote++; |
|
| 89 | - if(!empty($object->note_public)) $nbNote++; |
|
| 88 | + if (!empty($object->note_private)) $nbNote++; |
|
| 89 | + if (!empty($object->note_public)) $nbNote++; |
|
| 90 | 90 | $head[$h][0] = DOL_URL_ROOT.'/commande/note.php?id='.$object->id; |
| 91 | 91 | $head[$h][1] = $langs->trans('Notes'); |
| 92 | - if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>'; |
|
| 92 | + if ($nbNote > 0) $head[$h][1] .= ' <span class="badge">'.$nbNote.'</span>'; |
|
| 93 | 93 | $head[$h][2] = 'note'; |
| 94 | 94 | $h++; |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
| 98 | 98 | require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php'; |
| 99 | - $upload_dir = $conf->commande->dir_output . "/" . dol_sanitizeFileName($object->ref); |
|
| 100 | - $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview.*\.png)$')); |
|
| 101 | - $nbLinks=Link::count($db, $object->element, $object->id); |
|
| 99 | + $upload_dir = $conf->commande->dir_output."/".dol_sanitizeFileName($object->ref); |
|
| 100 | + $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$')); |
|
| 101 | + $nbLinks = Link::count($db, $object->element, $object->id); |
|
| 102 | 102 | $head[$h][0] = DOL_URL_ROOT.'/commande/document.php?id='.$object->id; |
| 103 | 103 | $head[$h][1] = $langs->trans('Documents'); |
| 104 | - if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>'; |
|
| 104 | + if (($nbFiles + $nbLinks) > 0) $head[$h][1] .= ' <span class="badge">'.($nbFiles + $nbLinks).'</span>'; |
|
| 105 | 105 | $head[$h][2] = 'documents'; |
| 106 | 106 | $h++; |
| 107 | 107 | |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | $head[$h][2] = 'info'; |
| 111 | 111 | $h++; |
| 112 | 112 | |
| 113 | - complete_head_from_modules($conf,$langs,$object,$head,$h,'order','remove'); |
|
| 113 | + complete_head_from_modules($conf, $langs, $object, $head, $h, 'order', 'remove'); |
|
| 114 | 114 | |
| 115 | 115 | return $head; |
| 116 | 116 | } |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | $head[$h][2] = 'general'; |
| 133 | 133 | $h++; |
| 134 | 134 | |
| 135 | - complete_head_from_modules($conf,$langs,null,$head,$h,'order_admin'); |
|
| 135 | + complete_head_from_modules($conf, $langs, null, $head, $h, 'order_admin'); |
|
| 136 | 136 | |
| 137 | 137 | $head[$h][0] = DOL_URL_ROOT.'/admin/order_extrafields.php'; |
| 138 | 138 | $head[$h][1] = $langs->trans("ExtraFields"); |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | $head[$h][2] = 'attributeslines'; |
| 145 | 145 | $h++; |
| 146 | 146 | |
| 147 | - complete_head_from_modules($conf,$langs,null,$head,$h,'order_admin','remove'); |
|
| 147 | + complete_head_from_modules($conf, $langs, null, $head, $h, 'order_admin', 'remove'); |
|
| 148 | 148 | |
| 149 | 149 | return $head; |
| 150 | 150 | } |
@@ -34,7 +34,9 @@ discard block |
||
| 34 | 34 | function commande_prepare_head(Commande $object) |
| 35 | 35 | { |
| 36 | 36 | global $db, $langs, $conf, $user; |
| 37 | - if (! empty($conf->expedition->enabled)) $langs->load("sendings"); |
|
| 37 | + if (! empty($conf->expedition->enabled)) { |
|
| 38 | + $langs->load("sendings"); |
|
| 39 | + } |
|
| 38 | 40 | $langs->load("orders"); |
| 39 | 41 | |
| 40 | 42 | $h = 0; |
@@ -53,7 +55,9 @@ discard block |
||
| 53 | 55 | $nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external')); |
| 54 | 56 | $head[$h][0] = DOL_URL_ROOT.'/commande/contact.php?id='.$object->id; |
| 55 | 57 | $head[$h][1] = $langs->trans('ContactsAddresses'); |
| 56 | - if ($nbContact > 0) $head[$h][1].= ' <span class="badge">'.$nbContact.'</span>'; |
|
| 58 | + if ($nbContact > 0) { |
|
| 59 | + $head[$h][1].= ' <span class="badge">'.$nbContact.'</span>'; |
|
| 60 | + } |
|
| 57 | 61 | $head[$h][2] = 'contact'; |
| 58 | 62 | $h++; |
| 59 | 63 | } |
@@ -64,13 +68,27 @@ discard block |
||
| 64 | 68 | $nbShipments=$object->getNbOfShipments(); $nbReceiption=0; |
| 65 | 69 | $head[$h][0] = DOL_URL_ROOT.'/expedition/shipment.php?id='.$object->id; |
| 66 | 70 | $text=''; |
| 67 | - if ($conf->expedition_bon->enabled) $text.=$langs->trans("Shipments"); |
|
| 68 | - if ($conf->expedition_bon->enabled && $conf->livraison_bon->enabled) $text.='/'; |
|
| 69 | - if ($conf->livraison_bon->enabled) $text.=$langs->trans("Receivings"); |
|
| 70 | - if ($nbShipments > 0 || $nbReceiption > 0) $text.= ' <span class="badge">'.($nbShipments?$nbShipments:0); |
|
| 71 | - if ($conf->expedition_bon->enabled && $conf->livraison_bon->enabled) $text.='/'; |
|
| 72 | - if ($conf->expedition_bon->enabled && $conf->livraison_bon->enabled && ($nbShipments > 0 || $nbReceiption > 0)) $text.= ($nbReceiption?$nbReceiption:0); |
|
| 73 | - if ($nbShipments > 0 || $nbReceiption > 0) $text.= '</span>'; |
|
| 71 | + if ($conf->expedition_bon->enabled) { |
|
| 72 | + $text.=$langs->trans("Shipments"); |
|
| 73 | + } |
|
| 74 | + if ($conf->expedition_bon->enabled && $conf->livraison_bon->enabled) { |
|
| 75 | + $text.='/'; |
|
| 76 | + } |
|
| 77 | + if ($conf->livraison_bon->enabled) { |
|
| 78 | + $text.=$langs->trans("Receivings"); |
|
| 79 | + } |
|
| 80 | + if ($nbShipments > 0 || $nbReceiption > 0) { |
|
| 81 | + $text.= ' <span class="badge">'.($nbShipments?$nbShipments:0); |
|
| 82 | + } |
|
| 83 | + if ($conf->expedition_bon->enabled && $conf->livraison_bon->enabled) { |
|
| 84 | + $text.='/'; |
|
| 85 | + } |
|
| 86 | + if ($conf->expedition_bon->enabled && $conf->livraison_bon->enabled && ($nbShipments > 0 || $nbReceiption > 0)) { |
|
| 87 | + $text.= ($nbReceiption?$nbReceiption:0); |
|
| 88 | + } |
|
| 89 | + if ($nbShipments > 0 || $nbReceiption > 0) { |
|
| 90 | + $text.= '</span>'; |
|
| 91 | + } |
|
| 74 | 92 | $head[$h][1] = $text; |
| 75 | 93 | $head[$h][2] = 'shipping'; |
| 76 | 94 | $h++; |
@@ -85,11 +103,17 @@ discard block |
||
| 85 | 103 | if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) |
| 86 | 104 | { |
| 87 | 105 | $nbNote = 0; |
| 88 | - if(!empty($object->note_private)) $nbNote++; |
|
| 89 | - if(!empty($object->note_public)) $nbNote++; |
|
| 106 | + if(!empty($object->note_private)) { |
|
| 107 | + $nbNote++; |
|
| 108 | + } |
|
| 109 | + if(!empty($object->note_public)) { |
|
| 110 | + $nbNote++; |
|
| 111 | + } |
|
| 90 | 112 | $head[$h][0] = DOL_URL_ROOT.'/commande/note.php?id='.$object->id; |
| 91 | 113 | $head[$h][1] = $langs->trans('Notes'); |
| 92 | - if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>'; |
|
| 114 | + if ($nbNote > 0) { |
|
| 115 | + $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>'; |
|
| 116 | + } |
|
| 93 | 117 | $head[$h][2] = 'note'; |
| 94 | 118 | $h++; |
| 95 | 119 | } |
@@ -101,7 +125,9 @@ discard block |
||
| 101 | 125 | $nbLinks=Link::count($db, $object->element, $object->id); |
| 102 | 126 | $head[$h][0] = DOL_URL_ROOT.'/commande/document.php?id='.$object->id; |
| 103 | 127 | $head[$h][1] = $langs->trans('Documents'); |
| 104 | - if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>'; |
|
| 128 | + if (($nbFiles+$nbLinks) > 0) { |
|
| 129 | + $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>'; |
|
| 130 | + } |
|
| 105 | 131 | $head[$h][2] = 'documents'; |
| 106 | 132 | $h++; |
| 107 | 133 | |
@@ -35,63 +35,63 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | function dolWebsiteReplacementOfLinks($website, $content, $removephppart=0) |
| 37 | 37 | { |
| 38 | - $nbrep = 0; |
|
| 39 | - |
|
| 40 | - // Replace php code. Note $content may come from database and does not contains body tags. |
|
| 41 | - $replacewith='...php...'; |
|
| 42 | - if ($removephppart) $replacewith=''; |
|
| 43 | - $content = preg_replace('/value="<\?php((?!\?>).)*\?>\n*/ims', 'value="'.$replacewith.'"', $content); |
|
| 44 | - |
|
| 45 | - $replacewith='"callto=#'; |
|
| 46 | - if ($removephppart) $replacewith=''; |
|
| 47 | - $content = preg_replace('/"callto:<\?php((?!\?>).)*\?>\n*/ims', $replacewith, $content); |
|
| 48 | - |
|
| 49 | - $replacewith='"mailto=#'; |
|
| 50 | - if ($removephppart) $replacewith=''; |
|
| 51 | - $content = preg_replace('/"mailto:<\?php((?!\?>).)*\?>\n*/ims', $replacewith, $content); |
|
| 52 | - |
|
| 53 | - $replacewith='src="php'; |
|
| 54 | - if ($removephppart) $replacewith=''; |
|
| 55 | - $content = preg_replace('/src="<\?php((?!\?>).)*\?>\n*/ims', $replacewith, $content); |
|
| 56 | - |
|
| 57 | - $replacewith='href="php'; |
|
| 58 | - if ($removephppart) $replacewith=''; |
|
| 59 | - $content = preg_replace('/href="<\?php((?!\?>).)*\?>\n*/ims', $replacewith, $content); |
|
| 60 | - |
|
| 61 | - //$replacewith='<span class="phptag">...php...</span>'; |
|
| 62 | - $replacewith='<span class="phptag">...php...</span>'; |
|
| 63 | - if ($removephppart) $replacewith=''; |
|
| 64 | - //$content = preg_replace('/<\?php((?!\?toremove>).)*\?toremove>\n*/ims', $replacewith, $content); |
|
| 65 | - /*if ($content === null) { |
|
| 38 | + $nbrep = 0; |
|
| 39 | + |
|
| 40 | + // Replace php code. Note $content may come from database and does not contains body tags. |
|
| 41 | + $replacewith='...php...'; |
|
| 42 | + if ($removephppart) $replacewith=''; |
|
| 43 | + $content = preg_replace('/value="<\?php((?!\?>).)*\?>\n*/ims', 'value="'.$replacewith.'"', $content); |
|
| 44 | + |
|
| 45 | + $replacewith='"callto=#'; |
|
| 46 | + if ($removephppart) $replacewith=''; |
|
| 47 | + $content = preg_replace('/"callto:<\?php((?!\?>).)*\?>\n*/ims', $replacewith, $content); |
|
| 48 | + |
|
| 49 | + $replacewith='"mailto=#'; |
|
| 50 | + if ($removephppart) $replacewith=''; |
|
| 51 | + $content = preg_replace('/"mailto:<\?php((?!\?>).)*\?>\n*/ims', $replacewith, $content); |
|
| 52 | + |
|
| 53 | + $replacewith='src="php'; |
|
| 54 | + if ($removephppart) $replacewith=''; |
|
| 55 | + $content = preg_replace('/src="<\?php((?!\?>).)*\?>\n*/ims', $replacewith, $content); |
|
| 56 | + |
|
| 57 | + $replacewith='href="php'; |
|
| 58 | + if ($removephppart) $replacewith=''; |
|
| 59 | + $content = preg_replace('/href="<\?php((?!\?>).)*\?>\n*/ims', $replacewith, $content); |
|
| 60 | + |
|
| 61 | + //$replacewith='<span class="phptag">...php...</span>'; |
|
| 62 | + $replacewith='<span class="phptag">...php...</span>'; |
|
| 63 | + if ($removephppart) $replacewith=''; |
|
| 64 | + //$content = preg_replace('/<\?php((?!\?toremove>).)*\?toremove>\n*/ims', $replacewith, $content); |
|
| 65 | + /*if ($content === null) { |
|
| 66 | 66 | if (preg_last_error() == PREG_JIT_STACKLIMIT_ERROR) $content = 'preg_replace error (when removing php tags) PREG_JIT_STACKLIMIT_ERROR'; |
| 67 | 67 | }*/ |
| 68 | - $content = dolStripPhpCode($content, $replacewith); |
|
| 69 | - //var_dump($content); |
|
| 68 | + $content = dolStripPhpCode($content, $replacewith); |
|
| 69 | + //var_dump($content); |
|
| 70 | 70 | |
| 71 | - // Replace relative link / with dolibarr URL |
|
| 72 | - $content = preg_replace('/(href=")\/\"/', '\1'.DOL_URL_ROOT.'/website/index.php?website='.$website->ref.'&pageid='.$website->fk_default_home.'"', $content, -1, $nbrep); |
|
| 73 | - // Replace relative link /xxx.php with dolibarr URL |
|
| 74 | - $content = preg_replace('/(href=")\/?([^:\"]*)(\.php\")/', '\1'.DOL_URL_ROOT.'/website/index.php?website='.$website->ref.'&pageref=\2"', $content, -1, $nbrep); |
|
| 71 | + // Replace relative link / with dolibarr URL |
|
| 72 | + $content = preg_replace('/(href=")\/\"/', '\1'.DOL_URL_ROOT.'/website/index.php?website='.$website->ref.'&pageid='.$website->fk_default_home.'"', $content, -1, $nbrep); |
|
| 73 | + // Replace relative link /xxx.php with dolibarr URL |
|
| 74 | + $content = preg_replace('/(href=")\/?([^:\"]*)(\.php\")/', '\1'.DOL_URL_ROOT.'/website/index.php?website='.$website->ref.'&pageref=\2"', $content, -1, $nbrep); |
|
| 75 | 75 | |
| 76 | - // Fix relative link into medias with correct URL after the DOL_URL_ROOT: ../url("medias/ |
|
| 77 | - $content = preg_replace('/url\((["\']?)medias\//', 'url(\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep); |
|
| 78 | - $content = preg_replace('/data-slide-bg=(["\']?)medias\//', 'data-slide-bg=\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep); |
|
| 76 | + // Fix relative link into medias with correct URL after the DOL_URL_ROOT: ../url("medias/ |
|
| 77 | + $content = preg_replace('/url\((["\']?)medias\//', 'url(\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep); |
|
| 78 | + $content = preg_replace('/data-slide-bg=(["\']?)medias\//', 'data-slide-bg=\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep); |
|
| 79 | 79 | |
| 80 | - // <img src="medias/image.png... => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png... |
|
| 81 | - $content = preg_replace('/(<img[^>]*src=")(medias\/)/', '\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep); |
|
| 82 | - // <img src="image.png... => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png... |
|
| 83 | - $content = preg_replace('/(<img[^>]*src=")(?!(http|\/?viewimage|'.preg_quote(DOL_URL_ROOT,'/').'\/viewimage))/', '\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep); |
|
| 84 | - // <img src="viewimage.php/modulepart=medias&file=image.png" => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png" |
|
| 85 | - $content = preg_replace('/(<img[^>]*src=")(\/?viewimage\.php)/', '\1'.DOL_URL_ROOT.'/viewimage.php', $content, -1, $nbrep); |
|
| 80 | + // <img src="medias/image.png... => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png... |
|
| 81 | + $content = preg_replace('/(<img[^>]*src=")(medias\/)/', '\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep); |
|
| 82 | + // <img src="image.png... => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png... |
|
| 83 | + $content = preg_replace('/(<img[^>]*src=")(?!(http|\/?viewimage|'.preg_quote(DOL_URL_ROOT,'/').'\/viewimage))/', '\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep); |
|
| 84 | + // <img src="viewimage.php/modulepart=medias&file=image.png" => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png" |
|
| 85 | + $content = preg_replace('/(<img[^>]*src=")(\/?viewimage\.php)/', '\1'.DOL_URL_ROOT.'/viewimage.php', $content, -1, $nbrep); |
|
| 86 | 86 | |
| 87 | - // action="newpage.php" => action="dolibarr/website/index.php?website=...&pageref=newpage |
|
| 88 | - $content = preg_replace('/(action=")\/?([^:\"]*)(\.php\")/', '\1'.DOL_URL_ROOT.'/website/index.php?website='.$website->ref.'&pageref=\2"', $content, -1, $nbrep); |
|
| 87 | + // action="newpage.php" => action="dolibarr/website/index.php?website=...&pageref=newpage |
|
| 88 | + $content = preg_replace('/(action=")\/?([^:\"]*)(\.php\")/', '\1'.DOL_URL_ROOT.'/website/index.php?website='.$website->ref.'&pageref=\2"', $content, -1, $nbrep); |
|
| 89 | 89 | |
| 90 | - // Fix relative link /document.php with correct URL after the DOL_URL_ROOT: ...href="/document.php?modulepart=" |
|
| 91 | - $content=preg_replace('/(href=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep); |
|
| 92 | - $content=preg_replace('/(src=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep); |
|
| 90 | + // Fix relative link /document.php with correct URL after the DOL_URL_ROOT: ...href="/document.php?modulepart=" |
|
| 91 | + $content=preg_replace('/(href=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep); |
|
| 92 | + $content=preg_replace('/(src=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep); |
|
| 93 | 93 | |
| 94 | - return $content; |
|
| 94 | + return $content; |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | |
@@ -104,33 +104,33 @@ discard block |
||
| 104 | 104 | */ |
| 105 | 105 | function dolStripPhpCode($str, $replacewith='') |
| 106 | 106 | { |
| 107 | - $newstr = ''; |
|
| 108 | - |
|
| 109 | - //split on each opening tag |
|
| 110 | - $parts = explode('<?php',$str); |
|
| 111 | - if (!empty($parts)) |
|
| 112 | - { |
|
| 113 | - $i=0; |
|
| 114 | - foreach($parts as $part) |
|
| 115 | - { |
|
| 116 | - if ($i == 0) // The first part is never php code |
|
| 117 | - { |
|
| 118 | - $i++; |
|
| 119 | - $newstr .= $part; |
|
| 120 | - continue; |
|
| 121 | - } |
|
| 122 | - //split on closing tag |
|
| 123 | - $partlings = explode('?>', $part); |
|
| 124 | - if (!empty($partlings)) |
|
| 125 | - { |
|
| 126 | - //remove content before closing tag |
|
| 127 | - if (count($partlings) > 1) $partlings[0] = ''; |
|
| 128 | - //append to out string |
|
| 129 | - $newstr .= $replacewith.implode('',$partlings); |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - return $newstr; |
|
| 107 | + $newstr = ''; |
|
| 108 | + |
|
| 109 | + //split on each opening tag |
|
| 110 | + $parts = explode('<?php',$str); |
|
| 111 | + if (!empty($parts)) |
|
| 112 | + { |
|
| 113 | + $i=0; |
|
| 114 | + foreach($parts as $part) |
|
| 115 | + { |
|
| 116 | + if ($i == 0) // The first part is never php code |
|
| 117 | + { |
|
| 118 | + $i++; |
|
| 119 | + $newstr .= $part; |
|
| 120 | + continue; |
|
| 121 | + } |
|
| 122 | + //split on closing tag |
|
| 123 | + $partlings = explode('?>', $part); |
|
| 124 | + if (!empty($partlings)) |
|
| 125 | + { |
|
| 126 | + //remove content before closing tag |
|
| 127 | + if (count($partlings) > 1) $partlings[0] = ''; |
|
| 128 | + //append to out string |
|
| 129 | + $newstr .= $replacewith.implode('',$partlings); |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + return $newstr; |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | |
@@ -144,101 +144,101 @@ discard block |
||
| 144 | 144 | */ |
| 145 | 145 | function dolWebsiteOutput($content) |
| 146 | 146 | { |
| 147 | - global $db, $langs, $conf, $user; |
|
| 148 | - global $dolibarr_main_url_root, $dolibarr_main_data_root; |
|
| 147 | + global $db, $langs, $conf, $user; |
|
| 148 | + global $dolibarr_main_url_root, $dolibarr_main_data_root; |
|
| 149 | + |
|
| 150 | + dol_syslog("dolWebsiteOutput start (USEDOLIBARRSERVER=".(defined('USEDOLIBARRSERVER')?'1':'')." (USEDOLIBARREDITOR=".(defined('USEDOLIBARREDITOR')?'1':'').')'); |
|
| 151 | + |
|
| 152 | + // Define $urlwithroot |
|
| 153 | + $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); |
|
| 154 | + $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
| 155 | + //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current |
|
| 156 | + |
|
| 157 | + if (defined('USEDOLIBARREDITOR')) // REPLACEMENT OF LINKS When page called from Dolibarr editor |
|
| 158 | + { |
|
| 159 | + // We remove the <head> part of content |
|
| 160 | + $content = preg_replace('/<head>.*<\/head>/ims', '', $content); |
|
| 161 | + $content = preg_replace('/^.*<body(\s[^>]*)*>/ims', '', $content); |
|
| 162 | + $content = preg_replace('/<\/body(\s[^>]*)*>.*$/ims', '', $content); |
|
| 163 | + } |
|
| 164 | + elseif (defined('USEDOLIBARRSERVER')) // REPLACEMENT OF LINKS When page called from Dolibarr server |
|
| 165 | + { |
|
| 166 | + global $website; |
|
| 167 | + |
|
| 168 | + // Replace relative link / with dolibarr URL: ...href="/"... |
|
| 169 | + $content=preg_replace('/(href=")\/\"/', '\1'.DOL_URL_ROOT.'/public/website/index.php?website='.$website->ref.'"', $content, -1, $nbrep); |
|
| 170 | + // Replace relative link /xxx.php with dolibarr URL: ...href="....php" |
|
| 171 | + $content=preg_replace('/(href=")\/?([^:\"]*)(\.php\")/', '\1'.DOL_URL_ROOT.'/public/website/index.php?website='.$website->ref.'&pageref=\2"', $content, -1, $nbrep); |
|
| 172 | + // Replace relative link /xxx with dolibarr URL: ...href="....php" |
|
| 173 | + $content=preg_replace('/(href=")\/?([a-zA-Z0-9\-]+)(\")/', '\1'.DOL_URL_ROOT.'/public/website/index.php?website='.$website->ref.'&pageref=\2\3', $content, -1, $nbrep); |
|
| 174 | + $content=preg_replace('/(href=")\/?([a-zA-Z0-9\-]+)(\?)/', '\1'.DOL_URL_ROOT.'/public/website/index.php?website='.$website->ref.'&pageref=\2\3', $content, -1, $nbrep); |
|
| 175 | + |
|
| 176 | + // Fix relative link /document.php with correct URL after the DOL_URL_ROOT: href="/document.php?modulepart=" => href="/dolibarr/document.php?modulepart=" |
|
| 177 | + $content=preg_replace('/(href=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep); |
|
| 178 | + $content=preg_replace('/(src=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep); |
|
| 179 | + |
|
| 180 | + // Fix relative link /viewimage.php with correct URL after the DOL_URL_ROOT: href="/viewimage.php?modulepart=" => href="/dolibarr/viewimage.php?modulepart=" |
|
| 181 | + $content=preg_replace('/(href=")(\/?viewimage\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep); |
|
| 182 | + $content=preg_replace('/(src=")(\/?viewimage\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep); |
|
| 183 | + |
|
| 184 | + // Fix relative link into medias with correct URL after the DOL_URL_ROOT: ../url("medias/ |
|
| 185 | + $content=preg_replace('/url\((["\']?)medias\//', 'url(\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep); |
|
| 186 | + $content=preg_replace('/data-slide-bg=(["\']?)medias\//', 'data-slide-bg=\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep); |
|
| 187 | + |
|
| 188 | + // <img src="medias/image.png... => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png... |
|
| 189 | + $content = preg_replace('/(<img[^>]*src=")(medias\/)/', '\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep); |
|
| 190 | + // <img src="image.png... => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png... |
|
| 191 | + $content = preg_replace('/(<img[^>]*src=")(?!(http|\/?viewimage|'.preg_quote(DOL_URL_ROOT,'/').'\/viewimage))/', '\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep); |
|
| 192 | + // <img src="viewimage.php/modulepart=medias&file=image.png" => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png" |
|
| 193 | + $content = preg_replace('/(<img[^>]*src=")(\/?viewimage\.php)/', '\1'.DOL_URL_ROOT.'/viewimage.php', $content, -1, $nbrep); |
|
| 194 | + |
|
| 195 | + // action="newpage.php" => action="dolibarr/website/index.php?website=...&pageref=newpage |
|
| 196 | + $content = preg_replace('/(action=")\/?([^:\"]*)(\.php\")/', '\1'.DOL_URL_ROOT.'/public/website/index.php?website='.$website->ref.'&pageref=\2"', $content, -1, $nbrep); |
|
| 197 | + } |
|
| 198 | + else // REPLACEMENT OF LINKS When page called from virtual host |
|
| 199 | + { |
|
| 200 | + $symlinktomediaexists=1; |
|
| 201 | + |
|
| 202 | + // Make a change into HTML code to allow to include images from medias directory correct with direct link for virtual server |
|
| 203 | + // <img alt="" src="/dolibarr_dev/htdocs/viewimage.php?modulepart=medias&entity=1&file=image/ldestailleur_166x166.jpg" style="height:166px; width:166px" /> |
|
| 204 | + // become |
|
| 205 | + // <img alt="" src="'.$urlwithroot.'/medias/image/ldestailleur_166x166.jpg" style="height:166px; width:166px" /> |
|
| 206 | + $nbrep=0; |
|
| 207 | + if (! $symlinktomediaexists) |
|
| 208 | + { |
|
| 209 | + $content=preg_replace('/(<script[^>]*src=")[^\"]*document\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\wrapper.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep); |
|
| 210 | + |
|
| 211 | + $content=preg_replace('/(<a[^>]*href=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep); |
|
| 212 | + $content=preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep); |
|
| 213 | + $content=preg_replace('/(url\(["\']?)[^\)]*viewimage\.php([^\)]*)modulepart=medias([^\)]*)file=([^\)]*)(["\']?\))/', '\1/wrapper.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep); |
|
| 214 | + |
|
| 215 | + $content=preg_replace('/(<a[^>]*href=")[^\"]*viewimage\.php([^\"]*)hashp=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2hashp=\3\4', $content, -1, $nbrep); |
|
| 216 | + $content=preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)hashp=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2hashp=\3\4', $content, -1, $nbrep); |
|
| 217 | + $content=preg_replace('/(url\(["\']?)[^\)]*viewimage\.php([^\)]*)hashp=([^\)]*)(["\']?\))/', '\1/wrapper.php\2hashp\3\4', $content, -1, $nbrep); |
|
| 218 | + |
|
| 219 | + $content=preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)modulepart=mycompany([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2modulepart=mycompany\3file=\4\5', $content, -1, $nbrep); |
|
| 220 | + } |
|
| 221 | + else |
|
| 222 | + { |
|
| 223 | + $content=preg_replace('/(<script[^>]*src=")[^\"]*document\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1medias/\4\5', $content, -1, $nbrep); |
|
| 224 | + |
|
| 225 | + $content=preg_replace('/(<a[^>]*href=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1medias/\4\5', $content, -1, $nbrep); |
|
| 226 | + $content=preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1medias/\4\5', $content, -1, $nbrep); |
|
| 227 | + $content=preg_replace('/(url\(["\']?)[^\)]*viewimage\.php([^\)]*)modulepart=medias([^\)]*)file=([^\)]*)(["\']?\))/', '\1medias/\4\5', $content, -1, $nbrep); |
|
| 228 | + |
|
| 229 | + $content=preg_replace('/(<a[^>]*href=")[^\"]*viewimage\.php([^\"]*)hashp=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2hashp=\3\4', $content, -1, $nbrep); |
|
| 230 | + $content=preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)hashp=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2hashp=\3\4', $content, -1, $nbrep); |
|
| 231 | + $content=preg_replace('/(url\(["\']?)[^\)]*viewimage\.php([^\)]*)hashp=([^\)]*)(["\']?\))/', '\1/wrapper.php\2hashp=\3\4', $content, -1, $nbrep); |
|
| 232 | + |
|
| 233 | + $content=preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)modulepart=mycompany([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2modulepart=mycompany\3file=\4\5', $content, -1, $nbrep); |
|
| 234 | + } |
|
| 235 | + } |
|
| 149 | 236 | |
| 150 | - dol_syslog("dolWebsiteOutput start (USEDOLIBARRSERVER=".(defined('USEDOLIBARRSERVER')?'1':'')." (USEDOLIBARREDITOR=".(defined('USEDOLIBARREDITOR')?'1':'').')'); |
|
| 237 | + $content=preg_replace('/ contenteditable="true"/', ' contenteditable="false"', $content, -1, $nbrep); |
|
| 151 | 238 | |
| 152 | - // Define $urlwithroot |
|
| 153 | - $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); |
|
| 154 | - $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
| 155 | - //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current |
|
| 239 | + dol_syslog("dolWebsiteOutput end"); |
|
| 156 | 240 | |
| 157 | - if (defined('USEDOLIBARREDITOR')) // REPLACEMENT OF LINKS When page called from Dolibarr editor |
|
| 158 | - { |
|
| 159 | - // We remove the <head> part of content |
|
| 160 | - $content = preg_replace('/<head>.*<\/head>/ims', '', $content); |
|
| 161 | - $content = preg_replace('/^.*<body(\s[^>]*)*>/ims', '', $content); |
|
| 162 | - $content = preg_replace('/<\/body(\s[^>]*)*>.*$/ims', '', $content); |
|
| 163 | - } |
|
| 164 | - elseif (defined('USEDOLIBARRSERVER')) // REPLACEMENT OF LINKS When page called from Dolibarr server |
|
| 165 | - { |
|
| 166 | - global $website; |
|
| 167 | - |
|
| 168 | - // Replace relative link / with dolibarr URL: ...href="/"... |
|
| 169 | - $content=preg_replace('/(href=")\/\"/', '\1'.DOL_URL_ROOT.'/public/website/index.php?website='.$website->ref.'"', $content, -1, $nbrep); |
|
| 170 | - // Replace relative link /xxx.php with dolibarr URL: ...href="....php" |
|
| 171 | - $content=preg_replace('/(href=")\/?([^:\"]*)(\.php\")/', '\1'.DOL_URL_ROOT.'/public/website/index.php?website='.$website->ref.'&pageref=\2"', $content, -1, $nbrep); |
|
| 172 | - // Replace relative link /xxx with dolibarr URL: ...href="....php" |
|
| 173 | - $content=preg_replace('/(href=")\/?([a-zA-Z0-9\-]+)(\")/', '\1'.DOL_URL_ROOT.'/public/website/index.php?website='.$website->ref.'&pageref=\2\3', $content, -1, $nbrep); |
|
| 174 | - $content=preg_replace('/(href=")\/?([a-zA-Z0-9\-]+)(\?)/', '\1'.DOL_URL_ROOT.'/public/website/index.php?website='.$website->ref.'&pageref=\2\3', $content, -1, $nbrep); |
|
| 175 | - |
|
| 176 | - // Fix relative link /document.php with correct URL after the DOL_URL_ROOT: href="/document.php?modulepart=" => href="/dolibarr/document.php?modulepart=" |
|
| 177 | - $content=preg_replace('/(href=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep); |
|
| 178 | - $content=preg_replace('/(src=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep); |
|
| 179 | - |
|
| 180 | - // Fix relative link /viewimage.php with correct URL after the DOL_URL_ROOT: href="/viewimage.php?modulepart=" => href="/dolibarr/viewimage.php?modulepart=" |
|
| 181 | - $content=preg_replace('/(href=")(\/?viewimage\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep); |
|
| 182 | - $content=preg_replace('/(src=")(\/?viewimage\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep); |
|
| 183 | - |
|
| 184 | - // Fix relative link into medias with correct URL after the DOL_URL_ROOT: ../url("medias/ |
|
| 185 | - $content=preg_replace('/url\((["\']?)medias\//', 'url(\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep); |
|
| 186 | - $content=preg_replace('/data-slide-bg=(["\']?)medias\//', 'data-slide-bg=\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep); |
|
| 187 | - |
|
| 188 | - // <img src="medias/image.png... => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png... |
|
| 189 | - $content = preg_replace('/(<img[^>]*src=")(medias\/)/', '\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep); |
|
| 190 | - // <img src="image.png... => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png... |
|
| 191 | - $content = preg_replace('/(<img[^>]*src=")(?!(http|\/?viewimage|'.preg_quote(DOL_URL_ROOT,'/').'\/viewimage))/', '\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep); |
|
| 192 | - // <img src="viewimage.php/modulepart=medias&file=image.png" => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png" |
|
| 193 | - $content = preg_replace('/(<img[^>]*src=")(\/?viewimage\.php)/', '\1'.DOL_URL_ROOT.'/viewimage.php', $content, -1, $nbrep); |
|
| 194 | - |
|
| 195 | - // action="newpage.php" => action="dolibarr/website/index.php?website=...&pageref=newpage |
|
| 196 | - $content = preg_replace('/(action=")\/?([^:\"]*)(\.php\")/', '\1'.DOL_URL_ROOT.'/public/website/index.php?website='.$website->ref.'&pageref=\2"', $content, -1, $nbrep); |
|
| 197 | - } |
|
| 198 | - else // REPLACEMENT OF LINKS When page called from virtual host |
|
| 199 | - { |
|
| 200 | - $symlinktomediaexists=1; |
|
| 201 | - |
|
| 202 | - // Make a change into HTML code to allow to include images from medias directory correct with direct link for virtual server |
|
| 203 | - // <img alt="" src="/dolibarr_dev/htdocs/viewimage.php?modulepart=medias&entity=1&file=image/ldestailleur_166x166.jpg" style="height:166px; width:166px" /> |
|
| 204 | - // become |
|
| 205 | - // <img alt="" src="'.$urlwithroot.'/medias/image/ldestailleur_166x166.jpg" style="height:166px; width:166px" /> |
|
| 206 | - $nbrep=0; |
|
| 207 | - if (! $symlinktomediaexists) |
|
| 208 | - { |
|
| 209 | - $content=preg_replace('/(<script[^>]*src=")[^\"]*document\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\wrapper.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep); |
|
| 210 | - |
|
| 211 | - $content=preg_replace('/(<a[^>]*href=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep); |
|
| 212 | - $content=preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep); |
|
| 213 | - $content=preg_replace('/(url\(["\']?)[^\)]*viewimage\.php([^\)]*)modulepart=medias([^\)]*)file=([^\)]*)(["\']?\))/', '\1/wrapper.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep); |
|
| 214 | - |
|
| 215 | - $content=preg_replace('/(<a[^>]*href=")[^\"]*viewimage\.php([^\"]*)hashp=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2hashp=\3\4', $content, -1, $nbrep); |
|
| 216 | - $content=preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)hashp=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2hashp=\3\4', $content, -1, $nbrep); |
|
| 217 | - $content=preg_replace('/(url\(["\']?)[^\)]*viewimage\.php([^\)]*)hashp=([^\)]*)(["\']?\))/', '\1/wrapper.php\2hashp\3\4', $content, -1, $nbrep); |
|
| 218 | - |
|
| 219 | - $content=preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)modulepart=mycompany([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2modulepart=mycompany\3file=\4\5', $content, -1, $nbrep); |
|
| 220 | - } |
|
| 221 | - else |
|
| 222 | - { |
|
| 223 | - $content=preg_replace('/(<script[^>]*src=")[^\"]*document\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1medias/\4\5', $content, -1, $nbrep); |
|
| 224 | - |
|
| 225 | - $content=preg_replace('/(<a[^>]*href=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1medias/\4\5', $content, -1, $nbrep); |
|
| 226 | - $content=preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1medias/\4\5', $content, -1, $nbrep); |
|
| 227 | - $content=preg_replace('/(url\(["\']?)[^\)]*viewimage\.php([^\)]*)modulepart=medias([^\)]*)file=([^\)]*)(["\']?\))/', '\1medias/\4\5', $content, -1, $nbrep); |
|
| 228 | - |
|
| 229 | - $content=preg_replace('/(<a[^>]*href=")[^\"]*viewimage\.php([^\"]*)hashp=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2hashp=\3\4', $content, -1, $nbrep); |
|
| 230 | - $content=preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)hashp=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2hashp=\3\4', $content, -1, $nbrep); |
|
| 231 | - $content=preg_replace('/(url\(["\']?)[^\)]*viewimage\.php([^\)]*)hashp=([^\)]*)(["\']?\))/', '\1/wrapper.php\2hashp=\3\4', $content, -1, $nbrep); |
|
| 232 | - |
|
| 233 | - $content=preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)modulepart=mycompany([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2modulepart=mycompany\3file=\4\5', $content, -1, $nbrep); |
|
| 234 | - } |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - $content=preg_replace('/ contenteditable="true"/', ' contenteditable="false"', $content, -1, $nbrep); |
|
| 238 | - |
|
| 239 | - dol_syslog("dolWebsiteOutput end"); |
|
| 240 | - |
|
| 241 | - print $content; |
|
| 241 | + print $content; |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | |
@@ -279,74 +279,74 @@ discard block |
||
| 279 | 279 | */ |
| 280 | 280 | function redirectToContainer($containerref, $containeraliasalt='',$containerid=0) |
| 281 | 281 | { |
| 282 | - global $db, $website; |
|
| 283 | - |
|
| 284 | - $newurl = ''; |
|
| 285 | - $result=0; |
|
| 286 | - |
|
| 287 | - // We make redirect using the alternative alias, we must find the real $containerref |
|
| 288 | - if ($containeraliasalt) |
|
| 289 | - { |
|
| 290 | - include_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php'; |
|
| 291 | - $tmpwebsitepage=new WebsitePage($db); |
|
| 292 | - $result = $tmpwebsitepage->fetch(0, $website->id, '', $containeraliasalt); |
|
| 293 | - if ($result > 0) |
|
| 294 | - { |
|
| 295 | - $containerref = $tmpwebsitepage->pageurl; |
|
| 296 | - } |
|
| 297 | - else |
|
| 298 | - { |
|
| 299 | - print "Error, page contains a redirect to the alternative alias '".$containeraliasalt."' that does not exists in web site (".$website->id." / ".$website->ref.")"; |
|
| 300 | - exit; |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - if (defined('USEDOLIBARRSERVER')) // When page called from Dolibarr server |
|
| 305 | - { |
|
| 306 | - // Check new container exists |
|
| 307 | - if (! $containeraliasalt) // If containeraliasalt set, we already did the test |
|
| 308 | - { |
|
| 309 | - include_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php'; |
|
| 310 | - $tmpwebsitepage=new WebsitePage($db); |
|
| 311 | - $result = $tmpwebsitepage->fetch(0, $website->id, $containerref); |
|
| 312 | - unset($tmpwebsitepage); |
|
| 313 | - } |
|
| 314 | - if ($result > 0) |
|
| 315 | - { |
|
| 316 | - $currenturi = $_SERVER["REQUEST_URI"]; |
|
| 317 | - if (preg_match('/&pageref=([^&]+)/', $currenturi, $regtmp)) |
|
| 318 | - { |
|
| 319 | - if ($regtmp[0] == $containerref) |
|
| 320 | - { |
|
| 321 | - print "Error, page with uri '.$currenturi.' try a redirect to the same alias page '".$containerref."' in web site '".$website->ref."'"; |
|
| 322 | - exit; |
|
| 323 | - } |
|
| 324 | - else |
|
| 325 | - { |
|
| 326 | - $newurl = preg_replace('/&pageref=([^&]+)/', '&pageref='.$containerref, $currenturi); |
|
| 327 | - } |
|
| 328 | - } |
|
| 329 | - else |
|
| 330 | - { |
|
| 331 | - $newurl = $currenturi.'&pageref='.urlencode($containerref); |
|
| 332 | - } |
|
| 333 | - } |
|
| 334 | - } |
|
| 335 | - else // When page called from virtual host server |
|
| 336 | - { |
|
| 337 | - $newurl = '/'.$containerref.'.php'; |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - if ($newurl) |
|
| 341 | - { |
|
| 342 | - header("Location: ".$newurl); |
|
| 343 | - exit; |
|
| 344 | - } |
|
| 345 | - else |
|
| 346 | - { |
|
| 347 | - print "Error, page contains a redirect to the alias page '".$containerref."' that does not exists in web site (".$website->id." / ".$website->ref.")"; |
|
| 348 | - exit; |
|
| 349 | - } |
|
| 282 | + global $db, $website; |
|
| 283 | + |
|
| 284 | + $newurl = ''; |
|
| 285 | + $result=0; |
|
| 286 | + |
|
| 287 | + // We make redirect using the alternative alias, we must find the real $containerref |
|
| 288 | + if ($containeraliasalt) |
|
| 289 | + { |
|
| 290 | + include_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php'; |
|
| 291 | + $tmpwebsitepage=new WebsitePage($db); |
|
| 292 | + $result = $tmpwebsitepage->fetch(0, $website->id, '', $containeraliasalt); |
|
| 293 | + if ($result > 0) |
|
| 294 | + { |
|
| 295 | + $containerref = $tmpwebsitepage->pageurl; |
|
| 296 | + } |
|
| 297 | + else |
|
| 298 | + { |
|
| 299 | + print "Error, page contains a redirect to the alternative alias '".$containeraliasalt."' that does not exists in web site (".$website->id." / ".$website->ref.")"; |
|
| 300 | + exit; |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + if (defined('USEDOLIBARRSERVER')) // When page called from Dolibarr server |
|
| 305 | + { |
|
| 306 | + // Check new container exists |
|
| 307 | + if (! $containeraliasalt) // If containeraliasalt set, we already did the test |
|
| 308 | + { |
|
| 309 | + include_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php'; |
|
| 310 | + $tmpwebsitepage=new WebsitePage($db); |
|
| 311 | + $result = $tmpwebsitepage->fetch(0, $website->id, $containerref); |
|
| 312 | + unset($tmpwebsitepage); |
|
| 313 | + } |
|
| 314 | + if ($result > 0) |
|
| 315 | + { |
|
| 316 | + $currenturi = $_SERVER["REQUEST_URI"]; |
|
| 317 | + if (preg_match('/&pageref=([^&]+)/', $currenturi, $regtmp)) |
|
| 318 | + { |
|
| 319 | + if ($regtmp[0] == $containerref) |
|
| 320 | + { |
|
| 321 | + print "Error, page with uri '.$currenturi.' try a redirect to the same alias page '".$containerref."' in web site '".$website->ref."'"; |
|
| 322 | + exit; |
|
| 323 | + } |
|
| 324 | + else |
|
| 325 | + { |
|
| 326 | + $newurl = preg_replace('/&pageref=([^&]+)/', '&pageref='.$containerref, $currenturi); |
|
| 327 | + } |
|
| 328 | + } |
|
| 329 | + else |
|
| 330 | + { |
|
| 331 | + $newurl = $currenturi.'&pageref='.urlencode($containerref); |
|
| 332 | + } |
|
| 333 | + } |
|
| 334 | + } |
|
| 335 | + else // When page called from virtual host server |
|
| 336 | + { |
|
| 337 | + $newurl = '/'.$containerref.'.php'; |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + if ($newurl) |
|
| 341 | + { |
|
| 342 | + header("Location: ".$newurl); |
|
| 343 | + exit; |
|
| 344 | + } |
|
| 345 | + else |
|
| 346 | + { |
|
| 347 | + print "Error, page contains a redirect to the alias page '".$containerref."' that does not exists in web site (".$website->id." / ".$website->ref.")"; |
|
| 348 | + exit; |
|
| 349 | + } |
|
| 350 | 350 | } |
| 351 | 351 | |
| 352 | 352 | |
@@ -359,41 +359,41 @@ discard block |
||
| 359 | 359 | */ |
| 360 | 360 | function includeContainer($containerref) |
| 361 | 361 | { |
| 362 | - global $conf, $db, $hookmanager, $langs, $mysoc, $user, $website, $websitepage, $weblangs; // Very important. Required to have var available when running inluded containers. |
|
| 363 | - global $includehtmlcontentopened; |
|
| 364 | - global $websitekey, $websitepagefile; |
|
| 362 | + global $conf, $db, $hookmanager, $langs, $mysoc, $user, $website, $websitepage, $weblangs; // Very important. Required to have var available when running inluded containers. |
|
| 363 | + global $includehtmlcontentopened; |
|
| 364 | + global $websitekey, $websitepagefile; |
|
| 365 | 365 | |
| 366 | - $MAXLEVEL=20; |
|
| 366 | + $MAXLEVEL=20; |
|
| 367 | 367 | |
| 368 | - if (! preg_match('/\.php$/i', $containerref)) $containerref.='.php'; |
|
| 368 | + if (! preg_match('/\.php$/i', $containerref)) $containerref.='.php'; |
|
| 369 | 369 | |
| 370 | - $fullpathfile=DOL_DATA_ROOT.'/website/'.$websitekey.'/'.$containerref; |
|
| 370 | + $fullpathfile=DOL_DATA_ROOT.'/website/'.$websitekey.'/'.$containerref; |
|
| 371 | 371 | |
| 372 | - if (empty($includehtmlcontentopened)) $includehtmlcontentopened=0; |
|
| 373 | - $includehtmlcontentopened++; |
|
| 374 | - if ($includehtmlcontentopened > $MAXLEVEL) |
|
| 375 | - { |
|
| 376 | - print 'ERROR: RECURSIVE CONTENT LEVEL. Depth of recursive call is more than the limit of '.$MAXLEVEL.".\n"; |
|
| 377 | - return; |
|
| 378 | - } |
|
| 379 | - // file_get_contents is not possible. We must execute code with include |
|
| 380 | - //$content = file_get_contents($fullpathfile); |
|
| 381 | - //print preg_replace(array('/^.*<body[^>]*>/ims','/<\/body>.*$/ims'), array('', ''), $content);*/ |
|
| 372 | + if (empty($includehtmlcontentopened)) $includehtmlcontentopened=0; |
|
| 373 | + $includehtmlcontentopened++; |
|
| 374 | + if ($includehtmlcontentopened > $MAXLEVEL) |
|
| 375 | + { |
|
| 376 | + print 'ERROR: RECURSIVE CONTENT LEVEL. Depth of recursive call is more than the limit of '.$MAXLEVEL.".\n"; |
|
| 377 | + return; |
|
| 378 | + } |
|
| 379 | + // file_get_contents is not possible. We must execute code with include |
|
| 380 | + //$content = file_get_contents($fullpathfile); |
|
| 381 | + //print preg_replace(array('/^.*<body[^>]*>/ims','/<\/body>.*$/ims'), array('', ''), $content);*/ |
|
| 382 | 382 | |
| 383 | - ob_start(); |
|
| 384 | - $res = include $fullpathfile; // Include because we want to execute code content |
|
| 385 | - $tmpoutput = ob_get_contents(); |
|
| 386 | - ob_end_clean(); |
|
| 383 | + ob_start(); |
|
| 384 | + $res = include $fullpathfile; // Include because we want to execute code content |
|
| 385 | + $tmpoutput = ob_get_contents(); |
|
| 386 | + ob_end_clean(); |
|
| 387 | 387 | |
| 388 | - print "\n".'<!-- include '.$fullpathfile.' level = '.$includehtmlcontentopened.' -->'."\n"; |
|
| 389 | - print preg_replace(array('/^.*<body[^>]*>/ims','/<\/body>.*$/ims'), array('', ''), $tmpoutput); |
|
| 388 | + print "\n".'<!-- include '.$fullpathfile.' level = '.$includehtmlcontentopened.' -->'."\n"; |
|
| 389 | + print preg_replace(array('/^.*<body[^>]*>/ims','/<\/body>.*$/ims'), array('', ''), $tmpoutput); |
|
| 390 | 390 | |
| 391 | - if (! $res) |
|
| 392 | - { |
|
| 393 | - print 'ERROR: FAILED TO INCLUDE PAGE '.$containerref.".\n"; |
|
| 394 | - } |
|
| 391 | + if (! $res) |
|
| 392 | + { |
|
| 393 | + print 'ERROR: FAILED TO INCLUDE PAGE '.$containerref.".\n"; |
|
| 394 | + } |
|
| 395 | 395 | |
| 396 | - $includehtmlcontentopened--; |
|
| 396 | + $includehtmlcontentopened--; |
|
| 397 | 397 | } |
| 398 | 398 | |
| 399 | 399 | |
@@ -414,172 +414,172 @@ discard block |
||
| 414 | 414 | */ |
| 415 | 415 | function getAllImages($object, $objectpage, $urltograb, &$tmp, &$action, $modifylinks=0, $grabimages=1, $grabimagesinto='subpage') |
| 416 | 416 | { |
| 417 | - global $conf; |
|
| 418 | - |
|
| 419 | - $error=0; |
|
| 420 | - |
|
| 421 | - dol_syslog("Call getAllImages with grabimagesinto=".$grabimagesinto); |
|
| 422 | - |
|
| 423 | - $alreadygrabbed=array(); |
|
| 424 | - |
|
| 425 | - if (preg_match('/\/$/', $urltograb)) $urltograb.='.'; |
|
| 426 | - $urltograb = dirname($urltograb); // So urltograb is now http://www.nltechno.com or http://www.nltechno.com/dir1 |
|
| 427 | - |
|
| 428 | - // Search X in "img...src=X" |
|
| 429 | - preg_match_all('/<img([^\.\/]+)src="([^>"]+)"([^>]*)>/i', $tmp, $regs); |
|
| 430 | - |
|
| 431 | - foreach ($regs[0] as $key => $val) |
|
| 432 | - { |
|
| 433 | - if (preg_match('/^data:image/i', $regs[2][$key])) continue; // We do nothing for such images |
|
| 434 | - |
|
| 435 | - if (preg_match('/^\//', $regs[2][$key])) |
|
| 436 | - { |
|
| 437 | - $urltograbdirrootwithoutslash = getRootURLFromURL($urltograb); |
|
| 438 | - $urltograbbis = $urltograbdirrootwithoutslash.$regs[2][$key]; // We use dirroot |
|
| 439 | - } |
|
| 440 | - else |
|
| 441 | - { |
|
| 442 | - $urltograbbis = $urltograb.'/'.$regs[2][$key]; // We use dir of grabbed file |
|
| 443 | - } |
|
| 444 | - |
|
| 445 | - $linkwithoutdomain = $regs[2][$key]; |
|
| 446 | - $dirforimages = '/'.$objectpage->pageurl; |
|
| 447 | - if ($grabimagesinto == 'root') $dirforimages=''; |
|
| 448 | - |
|
| 449 | - // Define $filetosave and $filename |
|
| 450 | - $filetosave = $conf->medias->multidir_output[$conf->entity].'/image/'.$object->ref.$dirforimages.(preg_match('/^\//', $regs[2][$key])?'':'/').$regs[2][$key]; |
|
| 451 | - if (preg_match('/^http/', $regs[2][$key])) |
|
| 452 | - { |
|
| 453 | - $urltograbbis = $regs[2][$key]; |
|
| 454 | - $linkwithoutdomain = preg_replace('/^https?:\/\/[^\/]+\//i', '', $regs[2][$key]); |
|
| 455 | - $filetosave = $conf->medias->multidir_output[$conf->entity].'/image/'.$object->ref.$dirforimages.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain; |
|
| 456 | - } |
|
| 457 | - $filename = 'image/'.$object->ref.$dirforimages.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain; |
|
| 458 | - |
|
| 459 | - // Clean the aa/bb/../cc into aa/cc |
|
| 460 | - $filetosave = preg_replace('/\/[^\/]+\/\.\./', '', $filetosave); |
|
| 461 | - $filename = preg_replace('/\/[^\/]+\/\.\./', '', $filename); |
|
| 462 | - |
|
| 463 | - //var_dump($filetosave); |
|
| 464 | - //var_dump($filename); |
|
| 465 | - //exit; |
|
| 466 | - |
|
| 467 | - if (empty($alreadygrabbed[$urltograbbis])) |
|
| 468 | - { |
|
| 469 | - if ($grabimages) |
|
| 470 | - { |
|
| 471 | - $tmpgeturl = getURLContent($urltograbbis); |
|
| 472 | - if ($tmpgeturl['curl_error_no']) |
|
| 473 | - { |
|
| 474 | - $error++; |
|
| 475 | - setEventMessages('Error getting '.$urltograbbis.': '.$tmpgeturl['curl_error_msg'], null, 'errors'); |
|
| 476 | - $action='create'; |
|
| 477 | - } |
|
| 478 | - elseif ($tmpgeturl['http_code'] != '200') |
|
| 479 | - { |
|
| 480 | - $error++; |
|
| 481 | - setEventMessages('Error getting '.$urltograbbis.': '.$tmpgeturl['http_code'], null, 'errors'); |
|
| 482 | - $action='create'; |
|
| 483 | - } |
|
| 484 | - else |
|
| 485 | - { |
|
| 486 | - $alreadygrabbed[$urltograbbis]=1; // Track that file was alreay grabbed. |
|
| 487 | - |
|
| 488 | - dol_mkdir(dirname($filetosave)); |
|
| 489 | - |
|
| 490 | - $fp = fopen($filetosave, "w"); |
|
| 491 | - fputs($fp, $tmpgeturl['content']); |
|
| 492 | - fclose($fp); |
|
| 493 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 494 | - @chmod($filetosave, octdec($conf->global->MAIN_UMASK)); |
|
| 495 | - } |
|
| 496 | - } |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - if ($modifylinks) |
|
| 500 | - { |
|
| 501 | - $tmp = preg_replace('/'.preg_quote($regs[0][$key],'/').'/i', '<img'.$regs[1][$key].'src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file='.$filename.'"'.$regs[3][$key].'>', $tmp); |
|
| 502 | - } |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - // Search X in "background...url(X)" |
|
| 506 | - preg_match_all('/background([^\.\/\(;]+)url\([\"\']?([^\)\"\']*)[\"\']?\)/i', $tmp, $regs); |
|
| 507 | - |
|
| 508 | - foreach ($regs[0] as $key => $val) |
|
| 509 | - { |
|
| 510 | - if (preg_match('/^data:image/i', $regs[2][$key])) continue; // We do nothing for such images |
|
| 511 | - |
|
| 512 | - if (preg_match('/^\//', $regs[2][$key])) |
|
| 513 | - { |
|
| 514 | - $urltograbdirrootwithoutslash = getRootURLFromURL($urltograb); |
|
| 515 | - $urltograbbis = $urltograbdirrootwithoutslash.$regs[2][$key]; // We use dirroot |
|
| 516 | - } |
|
| 517 | - else |
|
| 518 | - { |
|
| 519 | - $urltograbbis = $urltograb.'/'.$regs[2][$key]; // We use dir of grabbed file |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - $linkwithoutdomain = $regs[2][$key]; |
|
| 523 | - |
|
| 524 | - $dirforimages = '/'.$objectpage->pageurl; |
|
| 525 | - if ($grabimagesinto == 'root') $dirforimages=''; |
|
| 526 | - |
|
| 527 | - $filetosave = $conf->medias->multidir_output[$conf->entity].'/image/'.$object->ref.$dirforimages.(preg_match('/^\//', $regs[2][$key])?'':'/').$regs[2][$key]; |
|
| 528 | - |
|
| 529 | - if (preg_match('/^http/', $regs[2][$key])) |
|
| 530 | - { |
|
| 531 | - $urltograbbis = $regs[2][$key]; |
|
| 532 | - $linkwithoutdomain = preg_replace('/^https?:\/\/[^\/]+\//i', '', $regs[2][$key]); |
|
| 533 | - $filetosave = $conf->medias->multidir_output[$conf->entity].'/image/'.$object->ref.$dirforimages.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain; |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - $filename = 'image/'.$object->ref.$dirforimages.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain; |
|
| 537 | - |
|
| 538 | - // Clean the aa/bb/../cc into aa/cc |
|
| 539 | - $filetosave = preg_replace('/\/[^\/]+\/\.\./', '', $filetosave); |
|
| 540 | - $filename = preg_replace('/\/[^\/]+\/\.\./', '', $filename); |
|
| 541 | - |
|
| 542 | - //var_dump($filetosave); |
|
| 543 | - //var_dump($filename); |
|
| 544 | - //exit; |
|
| 545 | - |
|
| 546 | - if (empty($alreadygrabbed[$urltograbbis])) |
|
| 547 | - { |
|
| 548 | - if ($grabimages) |
|
| 549 | - { |
|
| 550 | - $tmpgeturl = getURLContent($urltograbbis); |
|
| 551 | - if ($tmpgeturl['curl_error_no']) |
|
| 552 | - { |
|
| 553 | - $error++; |
|
| 554 | - setEventMessages('Error getting '.$urltograbbis.': '.$tmpgeturl['curl_error_msg'], null, 'errors'); |
|
| 555 | - $action='create'; |
|
| 556 | - } |
|
| 557 | - elseif ($tmpgeturl['http_code'] != '200') |
|
| 558 | - { |
|
| 559 | - $error++; |
|
| 560 | - setEventMessages('Error getting '.$urltograbbis.': '.$tmpgeturl['http_code'], null, 'errors'); |
|
| 561 | - $action='create'; |
|
| 562 | - } |
|
| 563 | - else |
|
| 564 | - { |
|
| 565 | - $alreadygrabbed[$urltograbbis]=1; // Track that file was alreay grabbed. |
|
| 566 | - |
|
| 567 | - dol_mkdir(dirname($filetosave)); |
|
| 568 | - |
|
| 569 | - $fp = fopen($filetosave, "w"); |
|
| 570 | - fputs($fp, $tmpgeturl['content']); |
|
| 571 | - fclose($fp); |
|
| 572 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 573 | - @chmod($filetosave, octdec($conf->global->MAIN_UMASK)); |
|
| 574 | - } |
|
| 575 | - } |
|
| 576 | - } |
|
| 577 | - |
|
| 578 | - if ($modifylinks) |
|
| 579 | - { |
|
| 580 | - $tmp = preg_replace('/'.preg_quote($regs[0][$key],'/').'/i', 'background'.$regs[1][$key].'url("'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file='.$filename.'")', $tmp); |
|
| 581 | - } |
|
| 582 | - } |
|
| 417 | + global $conf; |
|
| 418 | + |
|
| 419 | + $error=0; |
|
| 420 | + |
|
| 421 | + dol_syslog("Call getAllImages with grabimagesinto=".$grabimagesinto); |
|
| 422 | + |
|
| 423 | + $alreadygrabbed=array(); |
|
| 424 | + |
|
| 425 | + if (preg_match('/\/$/', $urltograb)) $urltograb.='.'; |
|
| 426 | + $urltograb = dirname($urltograb); // So urltograb is now http://www.nltechno.com or http://www.nltechno.com/dir1 |
|
| 427 | + |
|
| 428 | + // Search X in "img...src=X" |
|
| 429 | + preg_match_all('/<img([^\.\/]+)src="([^>"]+)"([^>]*)>/i', $tmp, $regs); |
|
| 430 | + |
|
| 431 | + foreach ($regs[0] as $key => $val) |
|
| 432 | + { |
|
| 433 | + if (preg_match('/^data:image/i', $regs[2][$key])) continue; // We do nothing for such images |
|
| 434 | + |
|
| 435 | + if (preg_match('/^\//', $regs[2][$key])) |
|
| 436 | + { |
|
| 437 | + $urltograbdirrootwithoutslash = getRootURLFromURL($urltograb); |
|
| 438 | + $urltograbbis = $urltograbdirrootwithoutslash.$regs[2][$key]; // We use dirroot |
|
| 439 | + } |
|
| 440 | + else |
|
| 441 | + { |
|
| 442 | + $urltograbbis = $urltograb.'/'.$regs[2][$key]; // We use dir of grabbed file |
|
| 443 | + } |
|
| 444 | + |
|
| 445 | + $linkwithoutdomain = $regs[2][$key]; |
|
| 446 | + $dirforimages = '/'.$objectpage->pageurl; |
|
| 447 | + if ($grabimagesinto == 'root') $dirforimages=''; |
|
| 448 | + |
|
| 449 | + // Define $filetosave and $filename |
|
| 450 | + $filetosave = $conf->medias->multidir_output[$conf->entity].'/image/'.$object->ref.$dirforimages.(preg_match('/^\//', $regs[2][$key])?'':'/').$regs[2][$key]; |
|
| 451 | + if (preg_match('/^http/', $regs[2][$key])) |
|
| 452 | + { |
|
| 453 | + $urltograbbis = $regs[2][$key]; |
|
| 454 | + $linkwithoutdomain = preg_replace('/^https?:\/\/[^\/]+\//i', '', $regs[2][$key]); |
|
| 455 | + $filetosave = $conf->medias->multidir_output[$conf->entity].'/image/'.$object->ref.$dirforimages.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain; |
|
| 456 | + } |
|
| 457 | + $filename = 'image/'.$object->ref.$dirforimages.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain; |
|
| 458 | + |
|
| 459 | + // Clean the aa/bb/../cc into aa/cc |
|
| 460 | + $filetosave = preg_replace('/\/[^\/]+\/\.\./', '', $filetosave); |
|
| 461 | + $filename = preg_replace('/\/[^\/]+\/\.\./', '', $filename); |
|
| 462 | + |
|
| 463 | + //var_dump($filetosave); |
|
| 464 | + //var_dump($filename); |
|
| 465 | + //exit; |
|
| 466 | + |
|
| 467 | + if (empty($alreadygrabbed[$urltograbbis])) |
|
| 468 | + { |
|
| 469 | + if ($grabimages) |
|
| 470 | + { |
|
| 471 | + $tmpgeturl = getURLContent($urltograbbis); |
|
| 472 | + if ($tmpgeturl['curl_error_no']) |
|
| 473 | + { |
|
| 474 | + $error++; |
|
| 475 | + setEventMessages('Error getting '.$urltograbbis.': '.$tmpgeturl['curl_error_msg'], null, 'errors'); |
|
| 476 | + $action='create'; |
|
| 477 | + } |
|
| 478 | + elseif ($tmpgeturl['http_code'] != '200') |
|
| 479 | + { |
|
| 480 | + $error++; |
|
| 481 | + setEventMessages('Error getting '.$urltograbbis.': '.$tmpgeturl['http_code'], null, 'errors'); |
|
| 482 | + $action='create'; |
|
| 483 | + } |
|
| 484 | + else |
|
| 485 | + { |
|
| 486 | + $alreadygrabbed[$urltograbbis]=1; // Track that file was alreay grabbed. |
|
| 487 | + |
|
| 488 | + dol_mkdir(dirname($filetosave)); |
|
| 489 | + |
|
| 490 | + $fp = fopen($filetosave, "w"); |
|
| 491 | + fputs($fp, $tmpgeturl['content']); |
|
| 492 | + fclose($fp); |
|
| 493 | + if (! empty($conf->global->MAIN_UMASK)) |
|
| 494 | + @chmod($filetosave, octdec($conf->global->MAIN_UMASK)); |
|
| 495 | + } |
|
| 496 | + } |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + if ($modifylinks) |
|
| 500 | + { |
|
| 501 | + $tmp = preg_replace('/'.preg_quote($regs[0][$key],'/').'/i', '<img'.$regs[1][$key].'src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file='.$filename.'"'.$regs[3][$key].'>', $tmp); |
|
| 502 | + } |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + // Search X in "background...url(X)" |
|
| 506 | + preg_match_all('/background([^\.\/\(;]+)url\([\"\']?([^\)\"\']*)[\"\']?\)/i', $tmp, $regs); |
|
| 507 | + |
|
| 508 | + foreach ($regs[0] as $key => $val) |
|
| 509 | + { |
|
| 510 | + if (preg_match('/^data:image/i', $regs[2][$key])) continue; // We do nothing for such images |
|
| 511 | + |
|
| 512 | + if (preg_match('/^\//', $regs[2][$key])) |
|
| 513 | + { |
|
| 514 | + $urltograbdirrootwithoutslash = getRootURLFromURL($urltograb); |
|
| 515 | + $urltograbbis = $urltograbdirrootwithoutslash.$regs[2][$key]; // We use dirroot |
|
| 516 | + } |
|
| 517 | + else |
|
| 518 | + { |
|
| 519 | + $urltograbbis = $urltograb.'/'.$regs[2][$key]; // We use dir of grabbed file |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + $linkwithoutdomain = $regs[2][$key]; |
|
| 523 | + |
|
| 524 | + $dirforimages = '/'.$objectpage->pageurl; |
|
| 525 | + if ($grabimagesinto == 'root') $dirforimages=''; |
|
| 526 | + |
|
| 527 | + $filetosave = $conf->medias->multidir_output[$conf->entity].'/image/'.$object->ref.$dirforimages.(preg_match('/^\//', $regs[2][$key])?'':'/').$regs[2][$key]; |
|
| 528 | + |
|
| 529 | + if (preg_match('/^http/', $regs[2][$key])) |
|
| 530 | + { |
|
| 531 | + $urltograbbis = $regs[2][$key]; |
|
| 532 | + $linkwithoutdomain = preg_replace('/^https?:\/\/[^\/]+\//i', '', $regs[2][$key]); |
|
| 533 | + $filetosave = $conf->medias->multidir_output[$conf->entity].'/image/'.$object->ref.$dirforimages.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain; |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + $filename = 'image/'.$object->ref.$dirforimages.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain; |
|
| 537 | + |
|
| 538 | + // Clean the aa/bb/../cc into aa/cc |
|
| 539 | + $filetosave = preg_replace('/\/[^\/]+\/\.\./', '', $filetosave); |
|
| 540 | + $filename = preg_replace('/\/[^\/]+\/\.\./', '', $filename); |
|
| 541 | + |
|
| 542 | + //var_dump($filetosave); |
|
| 543 | + //var_dump($filename); |
|
| 544 | + //exit; |
|
| 545 | + |
|
| 546 | + if (empty($alreadygrabbed[$urltograbbis])) |
|
| 547 | + { |
|
| 548 | + if ($grabimages) |
|
| 549 | + { |
|
| 550 | + $tmpgeturl = getURLContent($urltograbbis); |
|
| 551 | + if ($tmpgeturl['curl_error_no']) |
|
| 552 | + { |
|
| 553 | + $error++; |
|
| 554 | + setEventMessages('Error getting '.$urltograbbis.': '.$tmpgeturl['curl_error_msg'], null, 'errors'); |
|
| 555 | + $action='create'; |
|
| 556 | + } |
|
| 557 | + elseif ($tmpgeturl['http_code'] != '200') |
|
| 558 | + { |
|
| 559 | + $error++; |
|
| 560 | + setEventMessages('Error getting '.$urltograbbis.': '.$tmpgeturl['http_code'], null, 'errors'); |
|
| 561 | + $action='create'; |
|
| 562 | + } |
|
| 563 | + else |
|
| 564 | + { |
|
| 565 | + $alreadygrabbed[$urltograbbis]=1; // Track that file was alreay grabbed. |
|
| 566 | + |
|
| 567 | + dol_mkdir(dirname($filetosave)); |
|
| 568 | + |
|
| 569 | + $fp = fopen($filetosave, "w"); |
|
| 570 | + fputs($fp, $tmpgeturl['content']); |
|
| 571 | + fclose($fp); |
|
| 572 | + if (! empty($conf->global->MAIN_UMASK)) |
|
| 573 | + @chmod($filetosave, octdec($conf->global->MAIN_UMASK)); |
|
| 574 | + } |
|
| 575 | + } |
|
| 576 | + } |
|
| 577 | + |
|
| 578 | + if ($modifylinks) |
|
| 579 | + { |
|
| 580 | + $tmp = preg_replace('/'.preg_quote($regs[0][$key],'/').'/i', 'background'.$regs[1][$key].'url("'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file='.$filename.'")', $tmp); |
|
| 581 | + } |
|
| 582 | + } |
|
| 583 | 583 | } |
| 584 | 584 | |
| 585 | 585 | |
@@ -592,21 +592,21 @@ discard block |
||
| 592 | 592 | */ |
| 593 | 593 | function dolSaveMasterFile($filemaster) |
| 594 | 594 | { |
| 595 | - global $conf; |
|
| 595 | + global $conf; |
|
| 596 | 596 | |
| 597 | - // Now generate the master.inc.php page |
|
| 598 | - dol_syslog("We regenerate the master file"); |
|
| 599 | - dol_delete_file($filemaster); |
|
| 597 | + // Now generate the master.inc.php page |
|
| 598 | + dol_syslog("We regenerate the master file"); |
|
| 599 | + dol_delete_file($filemaster); |
|
| 600 | 600 | |
| 601 | - $mastercontent = '<?php'."\n"; |
|
| 602 | - $mastercontent.= '// File generated to link to the master file - DO NOT MODIFY - It is just an include'."\n"; |
|
| 603 | - $mastercontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) require_once '".DOL_DOCUMENT_ROOT."/master.inc.php';\n"; |
|
| 604 | - $mastercontent.= '?>'."\n"; |
|
| 605 | - $result = file_put_contents($filemaster, $mastercontent); |
|
| 606 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 607 | - @chmod($filemaster, octdec($conf->global->MAIN_UMASK)); |
|
| 601 | + $mastercontent = '<?php'."\n"; |
|
| 602 | + $mastercontent.= '// File generated to link to the master file - DO NOT MODIFY - It is just an include'."\n"; |
|
| 603 | + $mastercontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) require_once '".DOL_DOCUMENT_ROOT."/master.inc.php';\n"; |
|
| 604 | + $mastercontent.= '?>'."\n"; |
|
| 605 | + $result = file_put_contents($filemaster, $mastercontent); |
|
| 606 | + if (! empty($conf->global->MAIN_UMASK)) |
|
| 607 | + @chmod($filemaster, octdec($conf->global->MAIN_UMASK)); |
|
| 608 | 608 | |
| 609 | - return $result; |
|
| 609 | + return $result; |
|
| 610 | 610 | } |
| 611 | 611 | |
| 612 | 612 | /** |
@@ -619,23 +619,23 @@ discard block |
||
| 619 | 619 | */ |
| 620 | 620 | function dolSavePageAlias($filealias, $object, $objectpage) |
| 621 | 621 | { |
| 622 | - global $conf; |
|
| 623 | - |
|
| 624 | - // Now create the .tpl file (duplicate code with actions updatesource or updatecontent but we need this to save new header) |
|
| 625 | - dol_syslog("We regenerate the alias page filealias=".$filealias); |
|
| 626 | - |
|
| 627 | - $aliascontent = '<?php'."\n"; |
|
| 628 | - $aliascontent.= "// File generated to wrap the alias page - DO NOT MODIFY - It is just a wrapper to real page\n"; |
|
| 629 | - $aliascontent.= 'global $dolibarr_main_data_root;'."\n"; |
|
| 630 | - $aliascontent.= 'if (empty($dolibarr_main_data_root)) require \'./page'.$objectpage->id.'.tpl.php\'; '; |
|
| 631 | - $aliascontent.= 'else require $dolibarr_main_data_root.\'/website/\'.$website->ref.\'/page'.$objectpage->id.'.tpl.php\';'."\n"; |
|
| 632 | - $aliascontent.= '?>'."\n"; |
|
| 633 | - $result = file_put_contents($filealias, $aliascontent); |
|
| 634 | - if (! empty($conf->global->MAIN_UMASK)) { |
|
| 622 | + global $conf; |
|
| 623 | + |
|
| 624 | + // Now create the .tpl file (duplicate code with actions updatesource or updatecontent but we need this to save new header) |
|
| 625 | + dol_syslog("We regenerate the alias page filealias=".$filealias); |
|
| 626 | + |
|
| 627 | + $aliascontent = '<?php'."\n"; |
|
| 628 | + $aliascontent.= "// File generated to wrap the alias page - DO NOT MODIFY - It is just a wrapper to real page\n"; |
|
| 629 | + $aliascontent.= 'global $dolibarr_main_data_root;'."\n"; |
|
| 630 | + $aliascontent.= 'if (empty($dolibarr_main_data_root)) require \'./page'.$objectpage->id.'.tpl.php\'; '; |
|
| 631 | + $aliascontent.= 'else require $dolibarr_main_data_root.\'/website/\'.$website->ref.\'/page'.$objectpage->id.'.tpl.php\';'."\n"; |
|
| 632 | + $aliascontent.= '?>'."\n"; |
|
| 633 | + $result = file_put_contents($filealias, $aliascontent); |
|
| 634 | + if (! empty($conf->global->MAIN_UMASK)) { |
|
| 635 | 635 | @chmod($filealias, octdec($conf->global->MAIN_UMASK)); |
| 636 | 636 | } |
| 637 | 637 | |
| 638 | - return ($result?true:false); |
|
| 638 | + return ($result?true:false); |
|
| 639 | 639 | } |
| 640 | 640 | |
| 641 | 641 | |
@@ -649,60 +649,60 @@ discard block |
||
| 649 | 649 | */ |
| 650 | 650 | function dolSavePageContent($filetpl, $object, $objectpage) |
| 651 | 651 | { |
| 652 | - global $conf; |
|
| 653 | - |
|
| 654 | - // Now create the .tpl file (duplicate code with actions updatesource or updatecontent but we need this to save new header) |
|
| 655 | - dol_syslog("We regenerate the tpl page filetpl=".$filetpl); |
|
| 656 | - |
|
| 657 | - dol_delete_file($filetpl); |
|
| 658 | - |
|
| 659 | - $shortlangcode = ''; |
|
| 660 | - if ($objectpage->lang) $shortlangcode=preg_replace('/[_-].*$/', '', $objectpage->lang); // en_US or en-US -> en |
|
| 661 | - |
|
| 662 | - $tplcontent =''; |
|
| 663 | - $tplcontent.= "<?php // BEGIN PHP\n"; |
|
| 664 | - $tplcontent.= '$websitekey=basename(dirname(__FILE__)); if (empty($websitepagefile)) $websitepagefile=__FILE__;'."\n"; |
|
| 665 | - $tplcontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once './master.inc.php'; } // Not already loaded"."\n"; |
|
| 666 | - $tplcontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n"; |
|
| 667 | - $tplcontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n"; |
|
| 668 | - $tplcontent.= "ob_start();\n"; |
|
| 669 | - $tplcontent.= "// END PHP ?>\n"; |
|
| 670 | - $tplcontent.= '<html'.($shortlangcode ? ' lang="'.$shortlangcode.'"':'').'>'."\n"; |
|
| 671 | - $tplcontent.= '<head>'."\n"; |
|
| 672 | - $tplcontent.= '<title>'.dol_string_nohtmltag($objectpage->title, 0, 'UTF-8').'</title>'."\n"; |
|
| 673 | - $tplcontent.= '<meta charset="UTF-8">'."\n"; |
|
| 674 | - $tplcontent.= '<meta http-equiv="content-type" content="text/html; charset=utf-8" />'."\n"; |
|
| 675 | - $tplcontent.= '<meta name="robots" content="index, follow" />'."\n"; |
|
| 676 | - $tplcontent.= '<meta name="viewport" content="width=device-width, initial-scale=1.0">'."\n"; |
|
| 677 | - $tplcontent.= '<meta name="keywords" content="'.dol_string_nohtmltag($objectpage->keywords).'" />'."\n"; |
|
| 678 | - $tplcontent.= '<meta name="title" content="'.dol_string_nohtmltag($objectpage->title, 0, 'UTF-8').'" />'."\n"; |
|
| 679 | - $tplcontent.= '<meta name="description" content="'.dol_string_nohtmltag($objectpage->description, 0, 'UTF-8').'" />'."\n"; |
|
| 680 | - $tplcontent.= '<meta name="generator" content="'.DOL_APPLICATION_TITLE.' '.DOL_VERSION.' (https://www.dolibarr.org)" />'."\n"; |
|
| 681 | - $tplcontent.= '<link href="/'.(($objectpage->id == $object->fk_default_home) ? '' : ($objectpage->pageurl.'.php')).'" rel="canonical" />'."\n"; |
|
| 682 | - $tplcontent.= '<!-- Include link to CSS file -->'."\n"; |
|
| 683 | - $tplcontent.= '<link rel="stylesheet" href="styles.css.php?website=<?php echo $websitekey; ?>" type="text/css" />'."\n"; |
|
| 684 | - $tplcontent.= '<!-- Include HTML header from common file -->'."\n"; |
|
| 685 | - $tplcontent.= '<?php print preg_replace(\'/<\/?html>/ims\', \'\', file_get_contents(DOL_DATA_ROOT."/website/".$websitekey."/htmlheader.html")); ?>'."\n"; |
|
| 686 | - $tplcontent.= '<!-- Include HTML header from page header block -->'."\n"; |
|
| 687 | - $tplcontent.= preg_replace('/<\/?html>/ims', '', $objectpage->htmlheader)."\n"; |
|
| 688 | - $tplcontent.= '</head>'."\n"; |
|
| 689 | - |
|
| 690 | - $tplcontent.= '<!-- File generated by Dolibarr website module editor -->'."\n"; |
|
| 691 | - $tplcontent.= '<body id="bodywebsite" class="bodywebsite">'."\n"; |
|
| 692 | - $tplcontent.= $objectpage->content."\n"; |
|
| 693 | - $tplcontent.= '</body>'."\n"; |
|
| 694 | - $tplcontent.= '</html>'."\n"; |
|
| 695 | - |
|
| 696 | - $tplcontent.= '<?php // BEGIN PHP'."\n"; |
|
| 697 | - $tplcontent.= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp);'."\n"; |
|
| 698 | - $tplcontent.= "// END PHP ?>"."\n"; |
|
| 699 | - |
|
| 700 | - //var_dump($filetpl);exit; |
|
| 701 | - $result = file_put_contents($filetpl, $tplcontent); |
|
| 702 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 703 | - @chmod($filetpl, octdec($conf->global->MAIN_UMASK)); |
|
| 704 | - |
|
| 705 | - return $result; |
|
| 652 | + global $conf; |
|
| 653 | + |
|
| 654 | + // Now create the .tpl file (duplicate code with actions updatesource or updatecontent but we need this to save new header) |
|
| 655 | + dol_syslog("We regenerate the tpl page filetpl=".$filetpl); |
|
| 656 | + |
|
| 657 | + dol_delete_file($filetpl); |
|
| 658 | + |
|
| 659 | + $shortlangcode = ''; |
|
| 660 | + if ($objectpage->lang) $shortlangcode=preg_replace('/[_-].*$/', '', $objectpage->lang); // en_US or en-US -> en |
|
| 661 | + |
|
| 662 | + $tplcontent =''; |
|
| 663 | + $tplcontent.= "<?php // BEGIN PHP\n"; |
|
| 664 | + $tplcontent.= '$websitekey=basename(dirname(__FILE__)); if (empty($websitepagefile)) $websitepagefile=__FILE__;'."\n"; |
|
| 665 | + $tplcontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once './master.inc.php'; } // Not already loaded"."\n"; |
|
| 666 | + $tplcontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n"; |
|
| 667 | + $tplcontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n"; |
|
| 668 | + $tplcontent.= "ob_start();\n"; |
|
| 669 | + $tplcontent.= "// END PHP ?>\n"; |
|
| 670 | + $tplcontent.= '<html'.($shortlangcode ? ' lang="'.$shortlangcode.'"':'').'>'."\n"; |
|
| 671 | + $tplcontent.= '<head>'."\n"; |
|
| 672 | + $tplcontent.= '<title>'.dol_string_nohtmltag($objectpage->title, 0, 'UTF-8').'</title>'."\n"; |
|
| 673 | + $tplcontent.= '<meta charset="UTF-8">'."\n"; |
|
| 674 | + $tplcontent.= '<meta http-equiv="content-type" content="text/html; charset=utf-8" />'."\n"; |
|
| 675 | + $tplcontent.= '<meta name="robots" content="index, follow" />'."\n"; |
|
| 676 | + $tplcontent.= '<meta name="viewport" content="width=device-width, initial-scale=1.0">'."\n"; |
|
| 677 | + $tplcontent.= '<meta name="keywords" content="'.dol_string_nohtmltag($objectpage->keywords).'" />'."\n"; |
|
| 678 | + $tplcontent.= '<meta name="title" content="'.dol_string_nohtmltag($objectpage->title, 0, 'UTF-8').'" />'."\n"; |
|
| 679 | + $tplcontent.= '<meta name="description" content="'.dol_string_nohtmltag($objectpage->description, 0, 'UTF-8').'" />'."\n"; |
|
| 680 | + $tplcontent.= '<meta name="generator" content="'.DOL_APPLICATION_TITLE.' '.DOL_VERSION.' (https://www.dolibarr.org)" />'."\n"; |
|
| 681 | + $tplcontent.= '<link href="/'.(($objectpage->id == $object->fk_default_home) ? '' : ($objectpage->pageurl.'.php')).'" rel="canonical" />'."\n"; |
|
| 682 | + $tplcontent.= '<!-- Include link to CSS file -->'."\n"; |
|
| 683 | + $tplcontent.= '<link rel="stylesheet" href="styles.css.php?website=<?php echo $websitekey; ?>" type="text/css" />'."\n"; |
|
| 684 | + $tplcontent.= '<!-- Include HTML header from common file -->'."\n"; |
|
| 685 | + $tplcontent.= '<?php print preg_replace(\'/<\/?html>/ims\', \'\', file_get_contents(DOL_DATA_ROOT."/website/".$websitekey."/htmlheader.html")); ?>'."\n"; |
|
| 686 | + $tplcontent.= '<!-- Include HTML header from page header block -->'."\n"; |
|
| 687 | + $tplcontent.= preg_replace('/<\/?html>/ims', '', $objectpage->htmlheader)."\n"; |
|
| 688 | + $tplcontent.= '</head>'."\n"; |
|
| 689 | + |
|
| 690 | + $tplcontent.= '<!-- File generated by Dolibarr website module editor -->'."\n"; |
|
| 691 | + $tplcontent.= '<body id="bodywebsite" class="bodywebsite">'."\n"; |
|
| 692 | + $tplcontent.= $objectpage->content."\n"; |
|
| 693 | + $tplcontent.= '</body>'."\n"; |
|
| 694 | + $tplcontent.= '</html>'."\n"; |
|
| 695 | + |
|
| 696 | + $tplcontent.= '<?php // BEGIN PHP'."\n"; |
|
| 697 | + $tplcontent.= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp);'."\n"; |
|
| 698 | + $tplcontent.= "// END PHP ?>"."\n"; |
|
| 699 | + |
|
| 700 | + //var_dump($filetpl);exit; |
|
| 701 | + $result = file_put_contents($filetpl, $tplcontent); |
|
| 702 | + if (! empty($conf->global->MAIN_UMASK)) |
|
| 703 | + @chmod($filetpl, octdec($conf->global->MAIN_UMASK)); |
|
| 704 | + |
|
| 705 | + return $result; |
|
| 706 | 706 | } |
| 707 | 707 | |
| 708 | 708 | |
@@ -717,38 +717,38 @@ discard block |
||
| 717 | 717 | */ |
| 718 | 718 | function dolSaveIndexPage($pathofwebsite, $fileindex, $filetpl, $filewrapper) |
| 719 | 719 | { |
| 720 | - global $conf; |
|
| 721 | - |
|
| 722 | - $result1=false; |
|
| 723 | - $result2=false; |
|
| 724 | - |
|
| 725 | - dol_mkdir($pathofwebsite); |
|
| 726 | - |
|
| 727 | - dol_delete_file($fileindex); |
|
| 728 | - $indexcontent = '<?php'."\n"; |
|
| 729 | - $indexcontent.= "// BEGIN PHP File generated to provide an index.php as Home Page or alias redirector - DO NOT MODIFY - It is just a generated wrapper.\n"; |
|
| 730 | - $indexcontent.= '$websitekey=basename(dirname(__FILE__)); if (empty($websitepagefile)) $websitepagefile=__FILE__;'."\n"; |
|
| 731 | - $indexcontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once './master.inc.php'; } // Load master if not already loaded\n"; |
|
| 732 | - $indexcontent.= 'if (! empty($_GET[\'pageref\']) || ! empty($_GET[\'pagealiasalt\']) || ! empty($_GET[\'pageid\'])) {'."\n"; |
|
| 733 | - $indexcontent.= " require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n"; |
|
| 734 | - $indexcontent.= " require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n"; |
|
| 735 | - $indexcontent.= ' redirectToContainer($_GET[\'pageref\'], $_GET[\'pagealiasalt\'], $_GET[\'pageid\']);'."\n"; |
|
| 736 | - $indexcontent.= "}\n"; |
|
| 737 | - $indexcontent.= "include_once './".basename($filetpl)."'\n"; |
|
| 738 | - $indexcontent.= '// END PHP ?>'."\n"; |
|
| 739 | - $result1 = file_put_contents($fileindex, $indexcontent); |
|
| 740 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 741 | - @chmod($fileindex, octdec($conf->global->MAIN_UMASK)); |
|
| 742 | - |
|
| 743 | - dol_delete_file($filewrapper); |
|
| 744 | - |
|
| 745 | - $wrappercontent=file_get_contents(DOL_DOCUMENT_ROOT.'/website/samples/wrapper.html'); |
|
| 746 | - |
|
| 747 | - $result2 = file_put_contents($filewrapper, $wrappercontent); |
|
| 748 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 749 | - @chmod($filewrapper, octdec($conf->global->MAIN_UMASK)); |
|
| 750 | - |
|
| 751 | - return ($result1 && $result2); |
|
| 720 | + global $conf; |
|
| 721 | + |
|
| 722 | + $result1=false; |
|
| 723 | + $result2=false; |
|
| 724 | + |
|
| 725 | + dol_mkdir($pathofwebsite); |
|
| 726 | + |
|
| 727 | + dol_delete_file($fileindex); |
|
| 728 | + $indexcontent = '<?php'."\n"; |
|
| 729 | + $indexcontent.= "// BEGIN PHP File generated to provide an index.php as Home Page or alias redirector - DO NOT MODIFY - It is just a generated wrapper.\n"; |
|
| 730 | + $indexcontent.= '$websitekey=basename(dirname(__FILE__)); if (empty($websitepagefile)) $websitepagefile=__FILE__;'."\n"; |
|
| 731 | + $indexcontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once './master.inc.php'; } // Load master if not already loaded\n"; |
|
| 732 | + $indexcontent.= 'if (! empty($_GET[\'pageref\']) || ! empty($_GET[\'pagealiasalt\']) || ! empty($_GET[\'pageid\'])) {'."\n"; |
|
| 733 | + $indexcontent.= " require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n"; |
|
| 734 | + $indexcontent.= " require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n"; |
|
| 735 | + $indexcontent.= ' redirectToContainer($_GET[\'pageref\'], $_GET[\'pagealiasalt\'], $_GET[\'pageid\']);'."\n"; |
|
| 736 | + $indexcontent.= "}\n"; |
|
| 737 | + $indexcontent.= "include_once './".basename($filetpl)."'\n"; |
|
| 738 | + $indexcontent.= '// END PHP ?>'."\n"; |
|
| 739 | + $result1 = file_put_contents($fileindex, $indexcontent); |
|
| 740 | + if (! empty($conf->global->MAIN_UMASK)) |
|
| 741 | + @chmod($fileindex, octdec($conf->global->MAIN_UMASK)); |
|
| 742 | + |
|
| 743 | + dol_delete_file($filewrapper); |
|
| 744 | + |
|
| 745 | + $wrappercontent=file_get_contents(DOL_DOCUMENT_ROOT.'/website/samples/wrapper.html'); |
|
| 746 | + |
|
| 747 | + $result2 = file_put_contents($filewrapper, $wrappercontent); |
|
| 748 | + if (! empty($conf->global->MAIN_UMASK)) |
|
| 749 | + @chmod($filewrapper, octdec($conf->global->MAIN_UMASK)); |
|
| 750 | + |
|
| 751 | + return ($result1 && $result2); |
|
| 752 | 752 | } |
| 753 | 753 | |
| 754 | 754 | |
@@ -761,22 +761,22 @@ discard block |
||
| 761 | 761 | */ |
| 762 | 762 | function dolSaveHtmlHeader($filehtmlheader, $htmlheadercontent) |
| 763 | 763 | { |
| 764 | - global $conf, $pathofwebsite; |
|
| 764 | + global $conf, $pathofwebsite; |
|
| 765 | 765 | |
| 766 | - dol_syslog("Save html header into ".$filehtmlheader); |
|
| 766 | + dol_syslog("Save html header into ".$filehtmlheader); |
|
| 767 | 767 | |
| 768 | - dol_mkdir($pathofwebsite); |
|
| 769 | - $result = file_put_contents($filehtmlheader, $htmlheadercontent); |
|
| 770 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 771 | - @chmod($filehtmlheader, octdec($conf->global->MAIN_UMASK)); |
|
| 768 | + dol_mkdir($pathofwebsite); |
|
| 769 | + $result = file_put_contents($filehtmlheader, $htmlheadercontent); |
|
| 770 | + if (! empty($conf->global->MAIN_UMASK)) |
|
| 771 | + @chmod($filehtmlheader, octdec($conf->global->MAIN_UMASK)); |
|
| 772 | 772 | |
| 773 | - if (! $result) |
|
| 774 | - { |
|
| 775 | - setEventMessages('Failed to write file '.$filehtmlheader, null, 'errors'); |
|
| 776 | - return false; |
|
| 777 | - } |
|
| 773 | + if (! $result) |
|
| 774 | + { |
|
| 775 | + setEventMessages('Failed to write file '.$filehtmlheader, null, 'errors'); |
|
| 776 | + return false; |
|
| 777 | + } |
|
| 778 | 778 | |
| 779 | - return true; |
|
| 779 | + return true; |
|
| 780 | 780 | } |
| 781 | 781 | |
| 782 | 782 | /** |
@@ -788,22 +788,22 @@ discard block |
||
| 788 | 788 | */ |
| 789 | 789 | function dolSaveCssFile($filecss, $csscontent) |
| 790 | 790 | { |
| 791 | - global $conf, $pathofwebsite; |
|
| 791 | + global $conf, $pathofwebsite; |
|
| 792 | 792 | |
| 793 | - dol_syslog("Save css file into ".$filecss); |
|
| 793 | + dol_syslog("Save css file into ".$filecss); |
|
| 794 | 794 | |
| 795 | - dol_mkdir($pathofwebsite); |
|
| 796 | - $result = file_put_contents($filecss, $csscontent); |
|
| 797 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 798 | - @chmod($filecss, octdec($conf->global->MAIN_UMASK)); |
|
| 795 | + dol_mkdir($pathofwebsite); |
|
| 796 | + $result = file_put_contents($filecss, $csscontent); |
|
| 797 | + if (! empty($conf->global->MAIN_UMASK)) |
|
| 798 | + @chmod($filecss, octdec($conf->global->MAIN_UMASK)); |
|
| 799 | 799 | |
| 800 | - if (! $result) |
|
| 801 | - { |
|
| 802 | - setEventMessages('Failed to write file '.$filecss, null, 'errors'); |
|
| 803 | - return false; |
|
| 804 | - } |
|
| 800 | + if (! $result) |
|
| 801 | + { |
|
| 802 | + setEventMessages('Failed to write file '.$filecss, null, 'errors'); |
|
| 803 | + return false; |
|
| 804 | + } |
|
| 805 | 805 | |
| 806 | - return true; |
|
| 806 | + return true; |
|
| 807 | 807 | } |
| 808 | 808 | |
| 809 | 809 | /** |
@@ -815,22 +815,22 @@ discard block |
||
| 815 | 815 | */ |
| 816 | 816 | function dolSaveJsFile($filejs, $jscontent) |
| 817 | 817 | { |
| 818 | - global $conf, $pathofwebsite; |
|
| 818 | + global $conf, $pathofwebsite; |
|
| 819 | 819 | |
| 820 | - dol_syslog("Save js file into ".$filejs); |
|
| 820 | + dol_syslog("Save js file into ".$filejs); |
|
| 821 | 821 | |
| 822 | - dol_mkdir($pathofwebsite); |
|
| 823 | - $result = file_put_contents($filejs, $jscontent); |
|
| 824 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 825 | - @chmod($filejs, octdec($conf->global->MAIN_UMASK)); |
|
| 822 | + dol_mkdir($pathofwebsite); |
|
| 823 | + $result = file_put_contents($filejs, $jscontent); |
|
| 824 | + if (! empty($conf->global->MAIN_UMASK)) |
|
| 825 | + @chmod($filejs, octdec($conf->global->MAIN_UMASK)); |
|
| 826 | 826 | |
| 827 | - if (! $result) |
|
| 828 | - { |
|
| 829 | - setEventMessages('Failed to write file '.$filejs, null, 'errors'); |
|
| 830 | - return false; |
|
| 831 | - } |
|
| 827 | + if (! $result) |
|
| 828 | + { |
|
| 829 | + setEventMessages('Failed to write file '.$filejs, null, 'errors'); |
|
| 830 | + return false; |
|
| 831 | + } |
|
| 832 | 832 | |
| 833 | - return true; |
|
| 833 | + return true; |
|
| 834 | 834 | } |
| 835 | 835 | |
| 836 | 836 | /** |
@@ -842,22 +842,22 @@ discard block |
||
| 842 | 842 | */ |
| 843 | 843 | function dolSaveRobotFile($filerobot, $robotcontent) |
| 844 | 844 | { |
| 845 | - global $conf, $pathofwebsite; |
|
| 845 | + global $conf, $pathofwebsite; |
|
| 846 | 846 | |
| 847 | - dol_syslog("Save robot file into ".$filerobot); |
|
| 847 | + dol_syslog("Save robot file into ".$filerobot); |
|
| 848 | 848 | |
| 849 | - dol_mkdir($pathofwebsite); |
|
| 850 | - $result = file_put_contents($filerobot, $robotcontent); |
|
| 851 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 852 | - @chmod($filerobot, octdec($conf->global->MAIN_UMASK)); |
|
| 849 | + dol_mkdir($pathofwebsite); |
|
| 850 | + $result = file_put_contents($filerobot, $robotcontent); |
|
| 851 | + if (! empty($conf->global->MAIN_UMASK)) |
|
| 852 | + @chmod($filerobot, octdec($conf->global->MAIN_UMASK)); |
|
| 853 | 853 | |
| 854 | - if (! $result) |
|
| 855 | - { |
|
| 856 | - setEventMessages('Failed to write file '.$filerobot, null, 'errors'); |
|
| 857 | - return false; |
|
| 858 | - } |
|
| 854 | + if (! $result) |
|
| 855 | + { |
|
| 856 | + setEventMessages('Failed to write file '.$filerobot, null, 'errors'); |
|
| 857 | + return false; |
|
| 858 | + } |
|
| 859 | 859 | |
| 860 | - return true; |
|
| 860 | + return true; |
|
| 861 | 861 | } |
| 862 | 862 | |
| 863 | 863 | /** |
@@ -869,20 +869,20 @@ discard block |
||
| 869 | 869 | */ |
| 870 | 870 | function dolSaveHtaccessFile($filehtaccess, $htaccess) |
| 871 | 871 | { |
| 872 | - global $conf, $pathofwebsite; |
|
| 872 | + global $conf, $pathofwebsite; |
|
| 873 | 873 | |
| 874 | - dol_syslog("Save htaccess file into ".$filehtaccess); |
|
| 874 | + dol_syslog("Save htaccess file into ".$filehtaccess); |
|
| 875 | 875 | |
| 876 | - dol_mkdir($pathofwebsite); |
|
| 877 | - $result = file_put_contents($filehtaccess, $htaccess); |
|
| 878 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 879 | - @chmod($filehtaccess, octdec($conf->global->MAIN_UMASK)); |
|
| 876 | + dol_mkdir($pathofwebsite); |
|
| 877 | + $result = file_put_contents($filehtaccess, $htaccess); |
|
| 878 | + if (! empty($conf->global->MAIN_UMASK)) |
|
| 879 | + @chmod($filehtaccess, octdec($conf->global->MAIN_UMASK)); |
|
| 880 | 880 | |
| 881 | - if (! $result) |
|
| 882 | - { |
|
| 883 | - setEventMessages('Failed to write file '.$filehtaccess, null, 'errors'); |
|
| 884 | - return false; |
|
| 885 | - } |
|
| 881 | + if (! $result) |
|
| 882 | + { |
|
| 883 | + setEventMessages('Failed to write file '.$filehtaccess, null, 'errors'); |
|
| 884 | + return false; |
|
| 885 | + } |
|
| 886 | 886 | |
| 887 | - return true; |
|
| 887 | + return true; |
|
| 888 | 888 | } |
@@ -33,34 +33,34 @@ discard block |
||
| 33 | 33 | * @return boolean True if OK |
| 34 | 34 | * @see dolWebsiteOutput for function used to replace content in a web server context |
| 35 | 35 | */ |
| 36 | -function dolWebsiteReplacementOfLinks($website, $content, $removephppart=0) |
|
| 36 | +function dolWebsiteReplacementOfLinks($website, $content, $removephppart = 0) |
|
| 37 | 37 | { |
| 38 | 38 | $nbrep = 0; |
| 39 | 39 | |
| 40 | 40 | // Replace php code. Note $content may come from database and does not contains body tags. |
| 41 | - $replacewith='...php...'; |
|
| 42 | - if ($removephppart) $replacewith=''; |
|
| 41 | + $replacewith = '...php...'; |
|
| 42 | + if ($removephppart) $replacewith = ''; |
|
| 43 | 43 | $content = preg_replace('/value="<\?php((?!\?>).)*\?>\n*/ims', 'value="'.$replacewith.'"', $content); |
| 44 | 44 | |
| 45 | - $replacewith='"callto=#'; |
|
| 46 | - if ($removephppart) $replacewith=''; |
|
| 45 | + $replacewith = '"callto=#'; |
|
| 46 | + if ($removephppart) $replacewith = ''; |
|
| 47 | 47 | $content = preg_replace('/"callto:<\?php((?!\?>).)*\?>\n*/ims', $replacewith, $content); |
| 48 | 48 | |
| 49 | - $replacewith='"mailto=#'; |
|
| 50 | - if ($removephppart) $replacewith=''; |
|
| 49 | + $replacewith = '"mailto=#'; |
|
| 50 | + if ($removephppart) $replacewith = ''; |
|
| 51 | 51 | $content = preg_replace('/"mailto:<\?php((?!\?>).)*\?>\n*/ims', $replacewith, $content); |
| 52 | 52 | |
| 53 | - $replacewith='src="php'; |
|
| 54 | - if ($removephppart) $replacewith=''; |
|
| 53 | + $replacewith = 'src="php'; |
|
| 54 | + if ($removephppart) $replacewith = ''; |
|
| 55 | 55 | $content = preg_replace('/src="<\?php((?!\?>).)*\?>\n*/ims', $replacewith, $content); |
| 56 | 56 | |
| 57 | - $replacewith='href="php'; |
|
| 58 | - if ($removephppart) $replacewith=''; |
|
| 57 | + $replacewith = 'href="php'; |
|
| 58 | + if ($removephppart) $replacewith = ''; |
|
| 59 | 59 | $content = preg_replace('/href="<\?php((?!\?>).)*\?>\n*/ims', $replacewith, $content); |
| 60 | 60 | |
| 61 | 61 | //$replacewith='<span class="phptag">...php...</span>'; |
| 62 | - $replacewith='<span class="phptag">...php...</span>'; |
|
| 63 | - if ($removephppart) $replacewith=''; |
|
| 62 | + $replacewith = '<span class="phptag">...php...</span>'; |
|
| 63 | + if ($removephppart) $replacewith = ''; |
|
| 64 | 64 | //$content = preg_replace('/<\?php((?!\?toremove>).)*\?toremove>\n*/ims', $replacewith, $content); |
| 65 | 65 | /*if ($content === null) { |
| 66 | 66 | if (preg_last_error() == PREG_JIT_STACKLIMIT_ERROR) $content = 'preg_replace error (when removing php tags) PREG_JIT_STACKLIMIT_ERROR'; |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | // <img src="medias/image.png... => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png... |
| 81 | 81 | $content = preg_replace('/(<img[^>]*src=")(medias\/)/', '\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep); |
| 82 | 82 | // <img src="image.png... => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png... |
| 83 | - $content = preg_replace('/(<img[^>]*src=")(?!(http|\/?viewimage|'.preg_quote(DOL_URL_ROOT,'/').'\/viewimage))/', '\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep); |
|
| 83 | + $content = preg_replace('/(<img[^>]*src=")(?!(http|\/?viewimage|'.preg_quote(DOL_URL_ROOT, '/').'\/viewimage))/', '\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep); |
|
| 84 | 84 | // <img src="viewimage.php/modulepart=medias&file=image.png" => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png" |
| 85 | 85 | $content = preg_replace('/(<img[^>]*src=")(\/?viewimage\.php)/', '\1'.DOL_URL_ROOT.'/viewimage.php', $content, -1, $nbrep); |
| 86 | 86 | |
@@ -88,8 +88,8 @@ discard block |
||
| 88 | 88 | $content = preg_replace('/(action=")\/?([^:\"]*)(\.php\")/', '\1'.DOL_URL_ROOT.'/website/index.php?website='.$website->ref.'&pageref=\2"', $content, -1, $nbrep); |
| 89 | 89 | |
| 90 | 90 | // Fix relative link /document.php with correct URL after the DOL_URL_ROOT: ...href="/document.php?modulepart=" |
| 91 | - $content=preg_replace('/(href=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep); |
|
| 92 | - $content=preg_replace('/(src=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep); |
|
| 91 | + $content = preg_replace('/(href=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep); |
|
| 92 | + $content = preg_replace('/(src=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep); |
|
| 93 | 93 | |
| 94 | 94 | return $content; |
| 95 | 95 | } |
@@ -102,16 +102,16 @@ discard block |
||
| 102 | 102 | * @param string $replacewith String to use as replacement |
| 103 | 103 | * @return string Result string without php code |
| 104 | 104 | */ |
| 105 | -function dolStripPhpCode($str, $replacewith='') |
|
| 105 | +function dolStripPhpCode($str, $replacewith = '') |
|
| 106 | 106 | { |
| 107 | 107 | $newstr = ''; |
| 108 | 108 | |
| 109 | 109 | //split on each opening tag |
| 110 | - $parts = explode('<?php',$str); |
|
| 110 | + $parts = explode('<?php', $str); |
|
| 111 | 111 | if (!empty($parts)) |
| 112 | 112 | { |
| 113 | - $i=0; |
|
| 114 | - foreach($parts as $part) |
|
| 113 | + $i = 0; |
|
| 114 | + foreach ($parts as $part) |
|
| 115 | 115 | { |
| 116 | 116 | if ($i == 0) // The first part is never php code |
| 117 | 117 | { |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | //remove content before closing tag |
| 127 | 127 | if (count($partlings) > 1) $partlings[0] = ''; |
| 128 | 128 | //append to out string |
| 129 | - $newstr .= $replacewith.implode('',$partlings); |
|
| 129 | + $newstr .= $replacewith.implode('', $partlings); |
|
| 130 | 130 | } |
| 131 | 131 | } |
| 132 | 132 | } |
@@ -147,11 +147,11 @@ discard block |
||
| 147 | 147 | global $db, $langs, $conf, $user; |
| 148 | 148 | global $dolibarr_main_url_root, $dolibarr_main_data_root; |
| 149 | 149 | |
| 150 | - dol_syslog("dolWebsiteOutput start (USEDOLIBARRSERVER=".(defined('USEDOLIBARRSERVER')?'1':'')." (USEDOLIBARREDITOR=".(defined('USEDOLIBARREDITOR')?'1':'').')'); |
|
| 150 | + dol_syslog("dolWebsiteOutput start (USEDOLIBARRSERVER=".(defined('USEDOLIBARRSERVER') ? '1' : '')." (USEDOLIBARREDITOR=".(defined('USEDOLIBARREDITOR') ? '1' : '').')'); |
|
| 151 | 151 | |
| 152 | 152 | // Define $urlwithroot |
| 153 | - $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); |
|
| 154 | - $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
| 153 | + $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root)); |
|
| 154 | + $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
| 155 | 155 | //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current |
| 156 | 156 | |
| 157 | 157 | if (defined('USEDOLIBARREDITOR')) // REPLACEMENT OF LINKS When page called from Dolibarr editor |
@@ -166,29 +166,29 @@ discard block |
||
| 166 | 166 | global $website; |
| 167 | 167 | |
| 168 | 168 | // Replace relative link / with dolibarr URL: ...href="/"... |
| 169 | - $content=preg_replace('/(href=")\/\"/', '\1'.DOL_URL_ROOT.'/public/website/index.php?website='.$website->ref.'"', $content, -1, $nbrep); |
|
| 169 | + $content = preg_replace('/(href=")\/\"/', '\1'.DOL_URL_ROOT.'/public/website/index.php?website='.$website->ref.'"', $content, -1, $nbrep); |
|
| 170 | 170 | // Replace relative link /xxx.php with dolibarr URL: ...href="....php" |
| 171 | - $content=preg_replace('/(href=")\/?([^:\"]*)(\.php\")/', '\1'.DOL_URL_ROOT.'/public/website/index.php?website='.$website->ref.'&pageref=\2"', $content, -1, $nbrep); |
|
| 171 | + $content = preg_replace('/(href=")\/?([^:\"]*)(\.php\")/', '\1'.DOL_URL_ROOT.'/public/website/index.php?website='.$website->ref.'&pageref=\2"', $content, -1, $nbrep); |
|
| 172 | 172 | // Replace relative link /xxx with dolibarr URL: ...href="....php" |
| 173 | - $content=preg_replace('/(href=")\/?([a-zA-Z0-9\-]+)(\")/', '\1'.DOL_URL_ROOT.'/public/website/index.php?website='.$website->ref.'&pageref=\2\3', $content, -1, $nbrep); |
|
| 174 | - $content=preg_replace('/(href=")\/?([a-zA-Z0-9\-]+)(\?)/', '\1'.DOL_URL_ROOT.'/public/website/index.php?website='.$website->ref.'&pageref=\2\3', $content, -1, $nbrep); |
|
| 173 | + $content = preg_replace('/(href=")\/?([a-zA-Z0-9\-]+)(\")/', '\1'.DOL_URL_ROOT.'/public/website/index.php?website='.$website->ref.'&pageref=\2\3', $content, -1, $nbrep); |
|
| 174 | + $content = preg_replace('/(href=")\/?([a-zA-Z0-9\-]+)(\?)/', '\1'.DOL_URL_ROOT.'/public/website/index.php?website='.$website->ref.'&pageref=\2\3', $content, -1, $nbrep); |
|
| 175 | 175 | |
| 176 | 176 | // Fix relative link /document.php with correct URL after the DOL_URL_ROOT: href="/document.php?modulepart=" => href="/dolibarr/document.php?modulepart=" |
| 177 | - $content=preg_replace('/(href=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep); |
|
| 178 | - $content=preg_replace('/(src=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep); |
|
| 177 | + $content = preg_replace('/(href=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep); |
|
| 178 | + $content = preg_replace('/(src=")(\/?document\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep); |
|
| 179 | 179 | |
| 180 | 180 | // Fix relative link /viewimage.php with correct URL after the DOL_URL_ROOT: href="/viewimage.php?modulepart=" => href="/dolibarr/viewimage.php?modulepart=" |
| 181 | - $content=preg_replace('/(href=")(\/?viewimage\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep); |
|
| 182 | - $content=preg_replace('/(src=")(\/?viewimage\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep); |
|
| 181 | + $content = preg_replace('/(href=")(\/?viewimage\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep); |
|
| 182 | + $content = preg_replace('/(src=")(\/?viewimage\.php\?[^\"]*modulepart=[^\"]*)(\")/', '\1'.DOL_URL_ROOT.'\2\3', $content, -1, $nbrep); |
|
| 183 | 183 | |
| 184 | 184 | // Fix relative link into medias with correct URL after the DOL_URL_ROOT: ../url("medias/ |
| 185 | - $content=preg_replace('/url\((["\']?)medias\//', 'url(\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep); |
|
| 186 | - $content=preg_replace('/data-slide-bg=(["\']?)medias\//', 'data-slide-bg=\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep); |
|
| 185 | + $content = preg_replace('/url\((["\']?)medias\//', 'url(\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep); |
|
| 186 | + $content = preg_replace('/data-slide-bg=(["\']?)medias\//', 'data-slide-bg=\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep); |
|
| 187 | 187 | |
| 188 | 188 | // <img src="medias/image.png... => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png... |
| 189 | 189 | $content = preg_replace('/(<img[^>]*src=")(medias\/)/', '\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep); |
| 190 | 190 | // <img src="image.png... => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png... |
| 191 | - $content = preg_replace('/(<img[^>]*src=")(?!(http|\/?viewimage|'.preg_quote(DOL_URL_ROOT,'/').'\/viewimage))/', '\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep); |
|
| 191 | + $content = preg_replace('/(<img[^>]*src=")(?!(http|\/?viewimage|'.preg_quote(DOL_URL_ROOT, '/').'\/viewimage))/', '\1'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file=', $content, -1, $nbrep); |
|
| 192 | 192 | // <img src="viewimage.php/modulepart=medias&file=image.png" => <img src="dolibarr/viewimage.php/modulepart=medias&file=image.png" |
| 193 | 193 | $content = preg_replace('/(<img[^>]*src=")(\/?viewimage\.php)/', '\1'.DOL_URL_ROOT.'/viewimage.php', $content, -1, $nbrep); |
| 194 | 194 | |
@@ -197,44 +197,44 @@ discard block |
||
| 197 | 197 | } |
| 198 | 198 | else // REPLACEMENT OF LINKS When page called from virtual host |
| 199 | 199 | { |
| 200 | - $symlinktomediaexists=1; |
|
| 200 | + $symlinktomediaexists = 1; |
|
| 201 | 201 | |
| 202 | 202 | // Make a change into HTML code to allow to include images from medias directory correct with direct link for virtual server |
| 203 | 203 | // <img alt="" src="/dolibarr_dev/htdocs/viewimage.php?modulepart=medias&entity=1&file=image/ldestailleur_166x166.jpg" style="height:166px; width:166px" /> |
| 204 | 204 | // become |
| 205 | 205 | // <img alt="" src="'.$urlwithroot.'/medias/image/ldestailleur_166x166.jpg" style="height:166px; width:166px" /> |
| 206 | - $nbrep=0; |
|
| 207 | - if (! $symlinktomediaexists) |
|
| 206 | + $nbrep = 0; |
|
| 207 | + if (!$symlinktomediaexists) |
|
| 208 | 208 | { |
| 209 | - $content=preg_replace('/(<script[^>]*src=")[^\"]*document\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\wrapper.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep); |
|
| 209 | + $content = preg_replace('/(<script[^>]*src=")[^\"]*document\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\wrapper.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep); |
|
| 210 | 210 | |
| 211 | - $content=preg_replace('/(<a[^>]*href=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep); |
|
| 212 | - $content=preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep); |
|
| 213 | - $content=preg_replace('/(url\(["\']?)[^\)]*viewimage\.php([^\)]*)modulepart=medias([^\)]*)file=([^\)]*)(["\']?\))/', '\1/wrapper.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep); |
|
| 211 | + $content = preg_replace('/(<a[^>]*href=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep); |
|
| 212 | + $content = preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep); |
|
| 213 | + $content = preg_replace('/(url\(["\']?)[^\)]*viewimage\.php([^\)]*)modulepart=medias([^\)]*)file=([^\)]*)(["\']?\))/', '\1/wrapper.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep); |
|
| 214 | 214 | |
| 215 | - $content=preg_replace('/(<a[^>]*href=")[^\"]*viewimage\.php([^\"]*)hashp=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2hashp=\3\4', $content, -1, $nbrep); |
|
| 216 | - $content=preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)hashp=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2hashp=\3\4', $content, -1, $nbrep); |
|
| 217 | - $content=preg_replace('/(url\(["\']?)[^\)]*viewimage\.php([^\)]*)hashp=([^\)]*)(["\']?\))/', '\1/wrapper.php\2hashp\3\4', $content, -1, $nbrep); |
|
| 215 | + $content = preg_replace('/(<a[^>]*href=")[^\"]*viewimage\.php([^\"]*)hashp=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2hashp=\3\4', $content, -1, $nbrep); |
|
| 216 | + $content = preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)hashp=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2hashp=\3\4', $content, -1, $nbrep); |
|
| 217 | + $content = preg_replace('/(url\(["\']?)[^\)]*viewimage\.php([^\)]*)hashp=([^\)]*)(["\']?\))/', '\1/wrapper.php\2hashp\3\4', $content, -1, $nbrep); |
|
| 218 | 218 | |
| 219 | - $content=preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)modulepart=mycompany([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2modulepart=mycompany\3file=\4\5', $content, -1, $nbrep); |
|
| 219 | + $content = preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)modulepart=mycompany([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2modulepart=mycompany\3file=\4\5', $content, -1, $nbrep); |
|
| 220 | 220 | } |
| 221 | 221 | else |
| 222 | 222 | { |
| 223 | - $content=preg_replace('/(<script[^>]*src=")[^\"]*document\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1medias/\4\5', $content, -1, $nbrep); |
|
| 223 | + $content = preg_replace('/(<script[^>]*src=")[^\"]*document\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1medias/\4\5', $content, -1, $nbrep); |
|
| 224 | 224 | |
| 225 | - $content=preg_replace('/(<a[^>]*href=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1medias/\4\5', $content, -1, $nbrep); |
|
| 226 | - $content=preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1medias/\4\5', $content, -1, $nbrep); |
|
| 227 | - $content=preg_replace('/(url\(["\']?)[^\)]*viewimage\.php([^\)]*)modulepart=medias([^\)]*)file=([^\)]*)(["\']?\))/', '\1medias/\4\5', $content, -1, $nbrep); |
|
| 225 | + $content = preg_replace('/(<a[^>]*href=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1medias/\4\5', $content, -1, $nbrep); |
|
| 226 | + $content = preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1medias/\4\5', $content, -1, $nbrep); |
|
| 227 | + $content = preg_replace('/(url\(["\']?)[^\)]*viewimage\.php([^\)]*)modulepart=medias([^\)]*)file=([^\)]*)(["\']?\))/', '\1medias/\4\5', $content, -1, $nbrep); |
|
| 228 | 228 | |
| 229 | - $content=preg_replace('/(<a[^>]*href=")[^\"]*viewimage\.php([^\"]*)hashp=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2hashp=\3\4', $content, -1, $nbrep); |
|
| 230 | - $content=preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)hashp=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2hashp=\3\4', $content, -1, $nbrep); |
|
| 231 | - $content=preg_replace('/(url\(["\']?)[^\)]*viewimage\.php([^\)]*)hashp=([^\)]*)(["\']?\))/', '\1/wrapper.php\2hashp=\3\4', $content, -1, $nbrep); |
|
| 229 | + $content = preg_replace('/(<a[^>]*href=")[^\"]*viewimage\.php([^\"]*)hashp=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2hashp=\3\4', $content, -1, $nbrep); |
|
| 230 | + $content = preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)hashp=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2hashp=\3\4', $content, -1, $nbrep); |
|
| 231 | + $content = preg_replace('/(url\(["\']?)[^\)]*viewimage\.php([^\)]*)hashp=([^\)]*)(["\']?\))/', '\1/wrapper.php\2hashp=\3\4', $content, -1, $nbrep); |
|
| 232 | 232 | |
| 233 | - $content=preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)modulepart=mycompany([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2modulepart=mycompany\3file=\4\5', $content, -1, $nbrep); |
|
| 233 | + $content = preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)modulepart=mycompany([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2modulepart=mycompany\3file=\4\5', $content, -1, $nbrep); |
|
| 234 | 234 | } |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | - $content=preg_replace('/ contenteditable="true"/', ' contenteditable="false"', $content, -1, $nbrep); |
|
| 237 | + $content = preg_replace('/ contenteditable="true"/', ' contenteditable="false"', $content, -1, $nbrep); |
|
| 238 | 238 | |
| 239 | 239 | dol_syslog("dolWebsiteOutput end"); |
| 240 | 240 | |
@@ -277,18 +277,18 @@ discard block |
||
| 277 | 277 | * @param int $containerid Id of container. |
| 278 | 278 | * @return void |
| 279 | 279 | */ |
| 280 | -function redirectToContainer($containerref, $containeraliasalt='',$containerid=0) |
|
| 280 | +function redirectToContainer($containerref, $containeraliasalt = '', $containerid = 0) |
|
| 281 | 281 | { |
| 282 | 282 | global $db, $website; |
| 283 | 283 | |
| 284 | 284 | $newurl = ''; |
| 285 | - $result=0; |
|
| 285 | + $result = 0; |
|
| 286 | 286 | |
| 287 | 287 | // We make redirect using the alternative alias, we must find the real $containerref |
| 288 | 288 | if ($containeraliasalt) |
| 289 | 289 | { |
| 290 | 290 | include_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php'; |
| 291 | - $tmpwebsitepage=new WebsitePage($db); |
|
| 291 | + $tmpwebsitepage = new WebsitePage($db); |
|
| 292 | 292 | $result = $tmpwebsitepage->fetch(0, $website->id, '', $containeraliasalt); |
| 293 | 293 | if ($result > 0) |
| 294 | 294 | { |
@@ -304,10 +304,10 @@ discard block |
||
| 304 | 304 | if (defined('USEDOLIBARRSERVER')) // When page called from Dolibarr server |
| 305 | 305 | { |
| 306 | 306 | // Check new container exists |
| 307 | - if (! $containeraliasalt) // If containeraliasalt set, we already did the test |
|
| 307 | + if (!$containeraliasalt) // If containeraliasalt set, we already did the test |
|
| 308 | 308 | { |
| 309 | 309 | include_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php'; |
| 310 | - $tmpwebsitepage=new WebsitePage($db); |
|
| 310 | + $tmpwebsitepage = new WebsitePage($db); |
|
| 311 | 311 | $result = $tmpwebsitepage->fetch(0, $website->id, $containerref); |
| 312 | 312 | unset($tmpwebsitepage); |
| 313 | 313 | } |
@@ -359,17 +359,17 @@ discard block |
||
| 359 | 359 | */ |
| 360 | 360 | function includeContainer($containerref) |
| 361 | 361 | { |
| 362 | - global $conf, $db, $hookmanager, $langs, $mysoc, $user, $website, $websitepage, $weblangs; // Very important. Required to have var available when running inluded containers. |
|
| 362 | + global $conf, $db, $hookmanager, $langs, $mysoc, $user, $website, $websitepage, $weblangs; // Very important. Required to have var available when running inluded containers. |
|
| 363 | 363 | global $includehtmlcontentopened; |
| 364 | 364 | global $websitekey, $websitepagefile; |
| 365 | 365 | |
| 366 | - $MAXLEVEL=20; |
|
| 366 | + $MAXLEVEL = 20; |
|
| 367 | 367 | |
| 368 | - if (! preg_match('/\.php$/i', $containerref)) $containerref.='.php'; |
|
| 368 | + if (!preg_match('/\.php$/i', $containerref)) $containerref .= '.php'; |
|
| 369 | 369 | |
| 370 | - $fullpathfile=DOL_DATA_ROOT.'/website/'.$websitekey.'/'.$containerref; |
|
| 370 | + $fullpathfile = DOL_DATA_ROOT.'/website/'.$websitekey.'/'.$containerref; |
|
| 371 | 371 | |
| 372 | - if (empty($includehtmlcontentopened)) $includehtmlcontentopened=0; |
|
| 372 | + if (empty($includehtmlcontentopened)) $includehtmlcontentopened = 0; |
|
| 373 | 373 | $includehtmlcontentopened++; |
| 374 | 374 | if ($includehtmlcontentopened > $MAXLEVEL) |
| 375 | 375 | { |
@@ -381,14 +381,14 @@ discard block |
||
| 381 | 381 | //print preg_replace(array('/^.*<body[^>]*>/ims','/<\/body>.*$/ims'), array('', ''), $content);*/ |
| 382 | 382 | |
| 383 | 383 | ob_start(); |
| 384 | - $res = include $fullpathfile; // Include because we want to execute code content |
|
| 384 | + $res = include $fullpathfile; // Include because we want to execute code content |
|
| 385 | 385 | $tmpoutput = ob_get_contents(); |
| 386 | 386 | ob_end_clean(); |
| 387 | 387 | |
| 388 | 388 | print "\n".'<!-- include '.$fullpathfile.' level = '.$includehtmlcontentopened.' -->'."\n"; |
| 389 | - print preg_replace(array('/^.*<body[^>]*>/ims','/<\/body>.*$/ims'), array('', ''), $tmpoutput); |
|
| 389 | + print preg_replace(array('/^.*<body[^>]*>/ims', '/<\/body>.*$/ims'), array('', ''), $tmpoutput); |
|
| 390 | 390 | |
| 391 | - if (! $res) |
|
| 391 | + if (!$res) |
|
| 392 | 392 | { |
| 393 | 393 | print 'ERROR: FAILED TO INCLUDE PAGE '.$containerref.".\n"; |
| 394 | 394 | } |
@@ -412,49 +412,49 @@ discard block |
||
| 412 | 412 | * @param string $grabimagesinto 'root' or 'subpage' |
| 413 | 413 | * @return void |
| 414 | 414 | */ |
| 415 | -function getAllImages($object, $objectpage, $urltograb, &$tmp, &$action, $modifylinks=0, $grabimages=1, $grabimagesinto='subpage') |
|
| 415 | +function getAllImages($object, $objectpage, $urltograb, &$tmp, &$action, $modifylinks = 0, $grabimages = 1, $grabimagesinto = 'subpage') |
|
| 416 | 416 | { |
| 417 | 417 | global $conf; |
| 418 | 418 | |
| 419 | - $error=0; |
|
| 419 | + $error = 0; |
|
| 420 | 420 | |
| 421 | 421 | dol_syslog("Call getAllImages with grabimagesinto=".$grabimagesinto); |
| 422 | 422 | |
| 423 | - $alreadygrabbed=array(); |
|
| 423 | + $alreadygrabbed = array(); |
|
| 424 | 424 | |
| 425 | - if (preg_match('/\/$/', $urltograb)) $urltograb.='.'; |
|
| 426 | - $urltograb = dirname($urltograb); // So urltograb is now http://www.nltechno.com or http://www.nltechno.com/dir1 |
|
| 425 | + if (preg_match('/\/$/', $urltograb)) $urltograb .= '.'; |
|
| 426 | + $urltograb = dirname($urltograb); // So urltograb is now http://www.nltechno.com or http://www.nltechno.com/dir1 |
|
| 427 | 427 | |
| 428 | 428 | // Search X in "img...src=X" |
| 429 | 429 | preg_match_all('/<img([^\.\/]+)src="([^>"]+)"([^>]*)>/i', $tmp, $regs); |
| 430 | 430 | |
| 431 | 431 | foreach ($regs[0] as $key => $val) |
| 432 | 432 | { |
| 433 | - if (preg_match('/^data:image/i', $regs[2][$key])) continue; // We do nothing for such images |
|
| 433 | + if (preg_match('/^data:image/i', $regs[2][$key])) continue; // We do nothing for such images |
|
| 434 | 434 | |
| 435 | 435 | if (preg_match('/^\//', $regs[2][$key])) |
| 436 | 436 | { |
| 437 | 437 | $urltograbdirrootwithoutslash = getRootURLFromURL($urltograb); |
| 438 | - $urltograbbis = $urltograbdirrootwithoutslash.$regs[2][$key]; // We use dirroot |
|
| 438 | + $urltograbbis = $urltograbdirrootwithoutslash.$regs[2][$key]; // We use dirroot |
|
| 439 | 439 | } |
| 440 | 440 | else |
| 441 | 441 | { |
| 442 | - $urltograbbis = $urltograb.'/'.$regs[2][$key]; // We use dir of grabbed file |
|
| 442 | + $urltograbbis = $urltograb.'/'.$regs[2][$key]; // We use dir of grabbed file |
|
| 443 | 443 | } |
| 444 | 444 | |
| 445 | 445 | $linkwithoutdomain = $regs[2][$key]; |
| 446 | 446 | $dirforimages = '/'.$objectpage->pageurl; |
| 447 | - if ($grabimagesinto == 'root') $dirforimages=''; |
|
| 447 | + if ($grabimagesinto == 'root') $dirforimages = ''; |
|
| 448 | 448 | |
| 449 | 449 | // Define $filetosave and $filename |
| 450 | - $filetosave = $conf->medias->multidir_output[$conf->entity].'/image/'.$object->ref.$dirforimages.(preg_match('/^\//', $regs[2][$key])?'':'/').$regs[2][$key]; |
|
| 450 | + $filetosave = $conf->medias->multidir_output[$conf->entity].'/image/'.$object->ref.$dirforimages.(preg_match('/^\//', $regs[2][$key]) ? '' : '/').$regs[2][$key]; |
|
| 451 | 451 | if (preg_match('/^http/', $regs[2][$key])) |
| 452 | 452 | { |
| 453 | 453 | $urltograbbis = $regs[2][$key]; |
| 454 | 454 | $linkwithoutdomain = preg_replace('/^https?:\/\/[^\/]+\//i', '', $regs[2][$key]); |
| 455 | - $filetosave = $conf->medias->multidir_output[$conf->entity].'/image/'.$object->ref.$dirforimages.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain; |
|
| 455 | + $filetosave = $conf->medias->multidir_output[$conf->entity].'/image/'.$object->ref.$dirforimages.(preg_match('/^\//', $linkwithoutdomain) ? '' : '/').$linkwithoutdomain; |
|
| 456 | 456 | } |
| 457 | - $filename = 'image/'.$object->ref.$dirforimages.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain; |
|
| 457 | + $filename = 'image/'.$object->ref.$dirforimages.(preg_match('/^\//', $linkwithoutdomain) ? '' : '/').$linkwithoutdomain; |
|
| 458 | 458 | |
| 459 | 459 | // Clean the aa/bb/../cc into aa/cc |
| 460 | 460 | $filetosave = preg_replace('/\/[^\/]+\/\.\./', '', $filetosave); |
@@ -473,24 +473,24 @@ discard block |
||
| 473 | 473 | { |
| 474 | 474 | $error++; |
| 475 | 475 | setEventMessages('Error getting '.$urltograbbis.': '.$tmpgeturl['curl_error_msg'], null, 'errors'); |
| 476 | - $action='create'; |
|
| 476 | + $action = 'create'; |
|
| 477 | 477 | } |
| 478 | 478 | elseif ($tmpgeturl['http_code'] != '200') |
| 479 | 479 | { |
| 480 | 480 | $error++; |
| 481 | 481 | setEventMessages('Error getting '.$urltograbbis.': '.$tmpgeturl['http_code'], null, 'errors'); |
| 482 | - $action='create'; |
|
| 482 | + $action = 'create'; |
|
| 483 | 483 | } |
| 484 | 484 | else |
| 485 | 485 | { |
| 486 | - $alreadygrabbed[$urltograbbis]=1; // Track that file was alreay grabbed. |
|
| 486 | + $alreadygrabbed[$urltograbbis] = 1; // Track that file was alreay grabbed. |
|
| 487 | 487 | |
| 488 | 488 | dol_mkdir(dirname($filetosave)); |
| 489 | 489 | |
| 490 | 490 | $fp = fopen($filetosave, "w"); |
| 491 | 491 | fputs($fp, $tmpgeturl['content']); |
| 492 | 492 | fclose($fp); |
| 493 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 493 | + if (!empty($conf->global->MAIN_UMASK)) |
|
| 494 | 494 | @chmod($filetosave, octdec($conf->global->MAIN_UMASK)); |
| 495 | 495 | } |
| 496 | 496 | } |
@@ -498,7 +498,7 @@ discard block |
||
| 498 | 498 | |
| 499 | 499 | if ($modifylinks) |
| 500 | 500 | { |
| 501 | - $tmp = preg_replace('/'.preg_quote($regs[0][$key],'/').'/i', '<img'.$regs[1][$key].'src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file='.$filename.'"'.$regs[3][$key].'>', $tmp); |
|
| 501 | + $tmp = preg_replace('/'.preg_quote($regs[0][$key], '/').'/i', '<img'.$regs[1][$key].'src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file='.$filename.'"'.$regs[3][$key].'>', $tmp); |
|
| 502 | 502 | } |
| 503 | 503 | } |
| 504 | 504 | |
@@ -507,33 +507,33 @@ discard block |
||
| 507 | 507 | |
| 508 | 508 | foreach ($regs[0] as $key => $val) |
| 509 | 509 | { |
| 510 | - if (preg_match('/^data:image/i', $regs[2][$key])) continue; // We do nothing for such images |
|
| 510 | + if (preg_match('/^data:image/i', $regs[2][$key])) continue; // We do nothing for such images |
|
| 511 | 511 | |
| 512 | 512 | if (preg_match('/^\//', $regs[2][$key])) |
| 513 | 513 | { |
| 514 | 514 | $urltograbdirrootwithoutslash = getRootURLFromURL($urltograb); |
| 515 | - $urltograbbis = $urltograbdirrootwithoutslash.$regs[2][$key]; // We use dirroot |
|
| 515 | + $urltograbbis = $urltograbdirrootwithoutslash.$regs[2][$key]; // We use dirroot |
|
| 516 | 516 | } |
| 517 | 517 | else |
| 518 | 518 | { |
| 519 | - $urltograbbis = $urltograb.'/'.$regs[2][$key]; // We use dir of grabbed file |
|
| 519 | + $urltograbbis = $urltograb.'/'.$regs[2][$key]; // We use dir of grabbed file |
|
| 520 | 520 | } |
| 521 | 521 | |
| 522 | 522 | $linkwithoutdomain = $regs[2][$key]; |
| 523 | 523 | |
| 524 | 524 | $dirforimages = '/'.$objectpage->pageurl; |
| 525 | - if ($grabimagesinto == 'root') $dirforimages=''; |
|
| 525 | + if ($grabimagesinto == 'root') $dirforimages = ''; |
|
| 526 | 526 | |
| 527 | - $filetosave = $conf->medias->multidir_output[$conf->entity].'/image/'.$object->ref.$dirforimages.(preg_match('/^\//', $regs[2][$key])?'':'/').$regs[2][$key]; |
|
| 527 | + $filetosave = $conf->medias->multidir_output[$conf->entity].'/image/'.$object->ref.$dirforimages.(preg_match('/^\//', $regs[2][$key]) ? '' : '/').$regs[2][$key]; |
|
| 528 | 528 | |
| 529 | 529 | if (preg_match('/^http/', $regs[2][$key])) |
| 530 | 530 | { |
| 531 | 531 | $urltograbbis = $regs[2][$key]; |
| 532 | 532 | $linkwithoutdomain = preg_replace('/^https?:\/\/[^\/]+\//i', '', $regs[2][$key]); |
| 533 | - $filetosave = $conf->medias->multidir_output[$conf->entity].'/image/'.$object->ref.$dirforimages.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain; |
|
| 533 | + $filetosave = $conf->medias->multidir_output[$conf->entity].'/image/'.$object->ref.$dirforimages.(preg_match('/^\//', $linkwithoutdomain) ? '' : '/').$linkwithoutdomain; |
|
| 534 | 534 | } |
| 535 | 535 | |
| 536 | - $filename = 'image/'.$object->ref.$dirforimages.(preg_match('/^\//', $linkwithoutdomain)?'':'/').$linkwithoutdomain; |
|
| 536 | + $filename = 'image/'.$object->ref.$dirforimages.(preg_match('/^\//', $linkwithoutdomain) ? '' : '/').$linkwithoutdomain; |
|
| 537 | 537 | |
| 538 | 538 | // Clean the aa/bb/../cc into aa/cc |
| 539 | 539 | $filetosave = preg_replace('/\/[^\/]+\/\.\./', '', $filetosave); |
@@ -552,24 +552,24 @@ discard block |
||
| 552 | 552 | { |
| 553 | 553 | $error++; |
| 554 | 554 | setEventMessages('Error getting '.$urltograbbis.': '.$tmpgeturl['curl_error_msg'], null, 'errors'); |
| 555 | - $action='create'; |
|
| 555 | + $action = 'create'; |
|
| 556 | 556 | } |
| 557 | 557 | elseif ($tmpgeturl['http_code'] != '200') |
| 558 | 558 | { |
| 559 | 559 | $error++; |
| 560 | 560 | setEventMessages('Error getting '.$urltograbbis.': '.$tmpgeturl['http_code'], null, 'errors'); |
| 561 | - $action='create'; |
|
| 561 | + $action = 'create'; |
|
| 562 | 562 | } |
| 563 | 563 | else |
| 564 | 564 | { |
| 565 | - $alreadygrabbed[$urltograbbis]=1; // Track that file was alreay grabbed. |
|
| 565 | + $alreadygrabbed[$urltograbbis] = 1; // Track that file was alreay grabbed. |
|
| 566 | 566 | |
| 567 | 567 | dol_mkdir(dirname($filetosave)); |
| 568 | 568 | |
| 569 | 569 | $fp = fopen($filetosave, "w"); |
| 570 | 570 | fputs($fp, $tmpgeturl['content']); |
| 571 | 571 | fclose($fp); |
| 572 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 572 | + if (!empty($conf->global->MAIN_UMASK)) |
|
| 573 | 573 | @chmod($filetosave, octdec($conf->global->MAIN_UMASK)); |
| 574 | 574 | } |
| 575 | 575 | } |
@@ -577,7 +577,7 @@ discard block |
||
| 577 | 577 | |
| 578 | 578 | if ($modifylinks) |
| 579 | 579 | { |
| 580 | - $tmp = preg_replace('/'.preg_quote($regs[0][$key],'/').'/i', 'background'.$regs[1][$key].'url("'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file='.$filename.'")', $tmp); |
|
| 580 | + $tmp = preg_replace('/'.preg_quote($regs[0][$key], '/').'/i', 'background'.$regs[1][$key].'url("'.DOL_URL_ROOT.'/viewimage.php?modulepart=medias&file='.$filename.'")', $tmp); |
|
| 581 | 581 | } |
| 582 | 582 | } |
| 583 | 583 | } |
@@ -599,11 +599,11 @@ discard block |
||
| 599 | 599 | dol_delete_file($filemaster); |
| 600 | 600 | |
| 601 | 601 | $mastercontent = '<?php'."\n"; |
| 602 | - $mastercontent.= '// File generated to link to the master file - DO NOT MODIFY - It is just an include'."\n"; |
|
| 603 | - $mastercontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) require_once '".DOL_DOCUMENT_ROOT."/master.inc.php';\n"; |
|
| 604 | - $mastercontent.= '?>'."\n"; |
|
| 602 | + $mastercontent .= '// File generated to link to the master file - DO NOT MODIFY - It is just an include'."\n"; |
|
| 603 | + $mastercontent .= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) require_once '".DOL_DOCUMENT_ROOT."/master.inc.php';\n"; |
|
| 604 | + $mastercontent .= '?>'."\n"; |
|
| 605 | 605 | $result = file_put_contents($filemaster, $mastercontent); |
| 606 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 606 | + if (!empty($conf->global->MAIN_UMASK)) |
|
| 607 | 607 | @chmod($filemaster, octdec($conf->global->MAIN_UMASK)); |
| 608 | 608 | |
| 609 | 609 | return $result; |
@@ -625,17 +625,17 @@ discard block |
||
| 625 | 625 | dol_syslog("We regenerate the alias page filealias=".$filealias); |
| 626 | 626 | |
| 627 | 627 | $aliascontent = '<?php'."\n"; |
| 628 | - $aliascontent.= "// File generated to wrap the alias page - DO NOT MODIFY - It is just a wrapper to real page\n"; |
|
| 629 | - $aliascontent.= 'global $dolibarr_main_data_root;'."\n"; |
|
| 630 | - $aliascontent.= 'if (empty($dolibarr_main_data_root)) require \'./page'.$objectpage->id.'.tpl.php\'; '; |
|
| 631 | - $aliascontent.= 'else require $dolibarr_main_data_root.\'/website/\'.$website->ref.\'/page'.$objectpage->id.'.tpl.php\';'."\n"; |
|
| 632 | - $aliascontent.= '?>'."\n"; |
|
| 628 | + $aliascontent .= "// File generated to wrap the alias page - DO NOT MODIFY - It is just a wrapper to real page\n"; |
|
| 629 | + $aliascontent .= 'global $dolibarr_main_data_root;'."\n"; |
|
| 630 | + $aliascontent .= 'if (empty($dolibarr_main_data_root)) require \'./page'.$objectpage->id.'.tpl.php\'; '; |
|
| 631 | + $aliascontent .= 'else require $dolibarr_main_data_root.\'/website/\'.$website->ref.\'/page'.$objectpage->id.'.tpl.php\';'."\n"; |
|
| 632 | + $aliascontent .= '?>'."\n"; |
|
| 633 | 633 | $result = file_put_contents($filealias, $aliascontent); |
| 634 | - if (! empty($conf->global->MAIN_UMASK)) { |
|
| 634 | + if (!empty($conf->global->MAIN_UMASK)) { |
|
| 635 | 635 | @chmod($filealias, octdec($conf->global->MAIN_UMASK)); |
| 636 | 636 | } |
| 637 | 637 | |
| 638 | - return ($result?true:false); |
|
| 638 | + return ($result ?true:false); |
|
| 639 | 639 | } |
| 640 | 640 | |
| 641 | 641 | |
@@ -657,49 +657,49 @@ discard block |
||
| 657 | 657 | dol_delete_file($filetpl); |
| 658 | 658 | |
| 659 | 659 | $shortlangcode = ''; |
| 660 | - if ($objectpage->lang) $shortlangcode=preg_replace('/[_-].*$/', '', $objectpage->lang); // en_US or en-US -> en |
|
| 661 | - |
|
| 662 | - $tplcontent =''; |
|
| 663 | - $tplcontent.= "<?php // BEGIN PHP\n"; |
|
| 664 | - $tplcontent.= '$websitekey=basename(dirname(__FILE__)); if (empty($websitepagefile)) $websitepagefile=__FILE__;'."\n"; |
|
| 665 | - $tplcontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once './master.inc.php'; } // Not already loaded"."\n"; |
|
| 666 | - $tplcontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n"; |
|
| 667 | - $tplcontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n"; |
|
| 668 | - $tplcontent.= "ob_start();\n"; |
|
| 669 | - $tplcontent.= "// END PHP ?>\n"; |
|
| 670 | - $tplcontent.= '<html'.($shortlangcode ? ' lang="'.$shortlangcode.'"':'').'>'."\n"; |
|
| 671 | - $tplcontent.= '<head>'."\n"; |
|
| 672 | - $tplcontent.= '<title>'.dol_string_nohtmltag($objectpage->title, 0, 'UTF-8').'</title>'."\n"; |
|
| 673 | - $tplcontent.= '<meta charset="UTF-8">'."\n"; |
|
| 674 | - $tplcontent.= '<meta http-equiv="content-type" content="text/html; charset=utf-8" />'."\n"; |
|
| 675 | - $tplcontent.= '<meta name="robots" content="index, follow" />'."\n"; |
|
| 676 | - $tplcontent.= '<meta name="viewport" content="width=device-width, initial-scale=1.0">'."\n"; |
|
| 677 | - $tplcontent.= '<meta name="keywords" content="'.dol_string_nohtmltag($objectpage->keywords).'" />'."\n"; |
|
| 678 | - $tplcontent.= '<meta name="title" content="'.dol_string_nohtmltag($objectpage->title, 0, 'UTF-8').'" />'."\n"; |
|
| 679 | - $tplcontent.= '<meta name="description" content="'.dol_string_nohtmltag($objectpage->description, 0, 'UTF-8').'" />'."\n"; |
|
| 680 | - $tplcontent.= '<meta name="generator" content="'.DOL_APPLICATION_TITLE.' '.DOL_VERSION.' (https://www.dolibarr.org)" />'."\n"; |
|
| 681 | - $tplcontent.= '<link href="/'.(($objectpage->id == $object->fk_default_home) ? '' : ($objectpage->pageurl.'.php')).'" rel="canonical" />'."\n"; |
|
| 682 | - $tplcontent.= '<!-- Include link to CSS file -->'."\n"; |
|
| 683 | - $tplcontent.= '<link rel="stylesheet" href="styles.css.php?website=<?php echo $websitekey; ?>" type="text/css" />'."\n"; |
|
| 684 | - $tplcontent.= '<!-- Include HTML header from common file -->'."\n"; |
|
| 685 | - $tplcontent.= '<?php print preg_replace(\'/<\/?html>/ims\', \'\', file_get_contents(DOL_DATA_ROOT."/website/".$websitekey."/htmlheader.html")); ?>'."\n"; |
|
| 686 | - $tplcontent.= '<!-- Include HTML header from page header block -->'."\n"; |
|
| 687 | - $tplcontent.= preg_replace('/<\/?html>/ims', '', $objectpage->htmlheader)."\n"; |
|
| 688 | - $tplcontent.= '</head>'."\n"; |
|
| 689 | - |
|
| 690 | - $tplcontent.= '<!-- File generated by Dolibarr website module editor -->'."\n"; |
|
| 691 | - $tplcontent.= '<body id="bodywebsite" class="bodywebsite">'."\n"; |
|
| 692 | - $tplcontent.= $objectpage->content."\n"; |
|
| 693 | - $tplcontent.= '</body>'."\n"; |
|
| 694 | - $tplcontent.= '</html>'."\n"; |
|
| 695 | - |
|
| 696 | - $tplcontent.= '<?php // BEGIN PHP'."\n"; |
|
| 697 | - $tplcontent.= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp);'."\n"; |
|
| 698 | - $tplcontent.= "// END PHP ?>"."\n"; |
|
| 660 | + if ($objectpage->lang) $shortlangcode = preg_replace('/[_-].*$/', '', $objectpage->lang); // en_US or en-US -> en |
|
| 661 | + |
|
| 662 | + $tplcontent = ''; |
|
| 663 | + $tplcontent .= "<?php // BEGIN PHP\n"; |
|
| 664 | + $tplcontent .= '$websitekey=basename(dirname(__FILE__)); if (empty($websitepagefile)) $websitepagefile=__FILE__;'."\n"; |
|
| 665 | + $tplcontent .= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once './master.inc.php'; } // Not already loaded"."\n"; |
|
| 666 | + $tplcontent .= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n"; |
|
| 667 | + $tplcontent .= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n"; |
|
| 668 | + $tplcontent .= "ob_start();\n"; |
|
| 669 | + $tplcontent .= "// END PHP ?>\n"; |
|
| 670 | + $tplcontent .= '<html'.($shortlangcode ? ' lang="'.$shortlangcode.'"' : '').'>'."\n"; |
|
| 671 | + $tplcontent .= '<head>'."\n"; |
|
| 672 | + $tplcontent .= '<title>'.dol_string_nohtmltag($objectpage->title, 0, 'UTF-8').'</title>'."\n"; |
|
| 673 | + $tplcontent .= '<meta charset="UTF-8">'."\n"; |
|
| 674 | + $tplcontent .= '<meta http-equiv="content-type" content="text/html; charset=utf-8" />'."\n"; |
|
| 675 | + $tplcontent .= '<meta name="robots" content="index, follow" />'."\n"; |
|
| 676 | + $tplcontent .= '<meta name="viewport" content="width=device-width, initial-scale=1.0">'."\n"; |
|
| 677 | + $tplcontent .= '<meta name="keywords" content="'.dol_string_nohtmltag($objectpage->keywords).'" />'."\n"; |
|
| 678 | + $tplcontent .= '<meta name="title" content="'.dol_string_nohtmltag($objectpage->title, 0, 'UTF-8').'" />'."\n"; |
|
| 679 | + $tplcontent .= '<meta name="description" content="'.dol_string_nohtmltag($objectpage->description, 0, 'UTF-8').'" />'."\n"; |
|
| 680 | + $tplcontent .= '<meta name="generator" content="'.DOL_APPLICATION_TITLE.' '.DOL_VERSION.' (https://www.dolibarr.org)" />'."\n"; |
|
| 681 | + $tplcontent .= '<link href="/'.(($objectpage->id == $object->fk_default_home) ? '' : ($objectpage->pageurl.'.php')).'" rel="canonical" />'."\n"; |
|
| 682 | + $tplcontent .= '<!-- Include link to CSS file -->'."\n"; |
|
| 683 | + $tplcontent .= '<link rel="stylesheet" href="styles.css.php?website=<?php echo $websitekey; ?>" type="text/css" />'."\n"; |
|
| 684 | + $tplcontent .= '<!-- Include HTML header from common file -->'."\n"; |
|
| 685 | + $tplcontent .= '<?php print preg_replace(\'/<\/?html>/ims\', \'\', file_get_contents(DOL_DATA_ROOT."/website/".$websitekey."/htmlheader.html")); ?>'."\n"; |
|
| 686 | + $tplcontent .= '<!-- Include HTML header from page header block -->'."\n"; |
|
| 687 | + $tplcontent .= preg_replace('/<\/?html>/ims', '', $objectpage->htmlheader)."\n"; |
|
| 688 | + $tplcontent .= '</head>'."\n"; |
|
| 689 | + |
|
| 690 | + $tplcontent .= '<!-- File generated by Dolibarr website module editor -->'."\n"; |
|
| 691 | + $tplcontent .= '<body id="bodywebsite" class="bodywebsite">'."\n"; |
|
| 692 | + $tplcontent .= $objectpage->content."\n"; |
|
| 693 | + $tplcontent .= '</body>'."\n"; |
|
| 694 | + $tplcontent .= '</html>'."\n"; |
|
| 695 | + |
|
| 696 | + $tplcontent .= '<?php // BEGIN PHP'."\n"; |
|
| 697 | + $tplcontent .= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp);'."\n"; |
|
| 698 | + $tplcontent .= "// END PHP ?>"."\n"; |
|
| 699 | 699 | |
| 700 | 700 | //var_dump($filetpl);exit; |
| 701 | 701 | $result = file_put_contents($filetpl, $tplcontent); |
| 702 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 702 | + if (!empty($conf->global->MAIN_UMASK)) |
|
| 703 | 703 | @chmod($filetpl, octdec($conf->global->MAIN_UMASK)); |
| 704 | 704 | |
| 705 | 705 | return $result; |
@@ -719,33 +719,33 @@ discard block |
||
| 719 | 719 | { |
| 720 | 720 | global $conf; |
| 721 | 721 | |
| 722 | - $result1=false; |
|
| 723 | - $result2=false; |
|
| 722 | + $result1 = false; |
|
| 723 | + $result2 = false; |
|
| 724 | 724 | |
| 725 | 725 | dol_mkdir($pathofwebsite); |
| 726 | 726 | |
| 727 | 727 | dol_delete_file($fileindex); |
| 728 | 728 | $indexcontent = '<?php'."\n"; |
| 729 | - $indexcontent.= "// BEGIN PHP File generated to provide an index.php as Home Page or alias redirector - DO NOT MODIFY - It is just a generated wrapper.\n"; |
|
| 730 | - $indexcontent.= '$websitekey=basename(dirname(__FILE__)); if (empty($websitepagefile)) $websitepagefile=__FILE__;'."\n"; |
|
| 731 | - $indexcontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once './master.inc.php'; } // Load master if not already loaded\n"; |
|
| 732 | - $indexcontent.= 'if (! empty($_GET[\'pageref\']) || ! empty($_GET[\'pagealiasalt\']) || ! empty($_GET[\'pageid\'])) {'."\n"; |
|
| 733 | - $indexcontent.= " require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n"; |
|
| 734 | - $indexcontent.= " require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n"; |
|
| 735 | - $indexcontent.= ' redirectToContainer($_GET[\'pageref\'], $_GET[\'pagealiasalt\'], $_GET[\'pageid\']);'."\n"; |
|
| 736 | - $indexcontent.= "}\n"; |
|
| 737 | - $indexcontent.= "include_once './".basename($filetpl)."'\n"; |
|
| 738 | - $indexcontent.= '// END PHP ?>'."\n"; |
|
| 729 | + $indexcontent .= "// BEGIN PHP File generated to provide an index.php as Home Page or alias redirector - DO NOT MODIFY - It is just a generated wrapper.\n"; |
|
| 730 | + $indexcontent .= '$websitekey=basename(dirname(__FILE__)); if (empty($websitepagefile)) $websitepagefile=__FILE__;'."\n"; |
|
| 731 | + $indexcontent .= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once './master.inc.php'; } // Load master if not already loaded\n"; |
|
| 732 | + $indexcontent .= 'if (! empty($_GET[\'pageref\']) || ! empty($_GET[\'pagealiasalt\']) || ! empty($_GET[\'pageid\'])) {'."\n"; |
|
| 733 | + $indexcontent .= " require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n"; |
|
| 734 | + $indexcontent .= " require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n"; |
|
| 735 | + $indexcontent .= ' redirectToContainer($_GET[\'pageref\'], $_GET[\'pagealiasalt\'], $_GET[\'pageid\']);'."\n"; |
|
| 736 | + $indexcontent .= "}\n"; |
|
| 737 | + $indexcontent .= "include_once './".basename($filetpl)."'\n"; |
|
| 738 | + $indexcontent .= '// END PHP ?>'."\n"; |
|
| 739 | 739 | $result1 = file_put_contents($fileindex, $indexcontent); |
| 740 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 740 | + if (!empty($conf->global->MAIN_UMASK)) |
|
| 741 | 741 | @chmod($fileindex, octdec($conf->global->MAIN_UMASK)); |
| 742 | 742 | |
| 743 | 743 | dol_delete_file($filewrapper); |
| 744 | 744 | |
| 745 | - $wrappercontent=file_get_contents(DOL_DOCUMENT_ROOT.'/website/samples/wrapper.html'); |
|
| 745 | + $wrappercontent = file_get_contents(DOL_DOCUMENT_ROOT.'/website/samples/wrapper.html'); |
|
| 746 | 746 | |
| 747 | 747 | $result2 = file_put_contents($filewrapper, $wrappercontent); |
| 748 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 748 | + if (!empty($conf->global->MAIN_UMASK)) |
|
| 749 | 749 | @chmod($filewrapper, octdec($conf->global->MAIN_UMASK)); |
| 750 | 750 | |
| 751 | 751 | return ($result1 && $result2); |
@@ -767,10 +767,10 @@ discard block |
||
| 767 | 767 | |
| 768 | 768 | dol_mkdir($pathofwebsite); |
| 769 | 769 | $result = file_put_contents($filehtmlheader, $htmlheadercontent); |
| 770 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 770 | + if (!empty($conf->global->MAIN_UMASK)) |
|
| 771 | 771 | @chmod($filehtmlheader, octdec($conf->global->MAIN_UMASK)); |
| 772 | 772 | |
| 773 | - if (! $result) |
|
| 773 | + if (!$result) |
|
| 774 | 774 | { |
| 775 | 775 | setEventMessages('Failed to write file '.$filehtmlheader, null, 'errors'); |
| 776 | 776 | return false; |
@@ -794,10 +794,10 @@ discard block |
||
| 794 | 794 | |
| 795 | 795 | dol_mkdir($pathofwebsite); |
| 796 | 796 | $result = file_put_contents($filecss, $csscontent); |
| 797 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 797 | + if (!empty($conf->global->MAIN_UMASK)) |
|
| 798 | 798 | @chmod($filecss, octdec($conf->global->MAIN_UMASK)); |
| 799 | 799 | |
| 800 | - if (! $result) |
|
| 800 | + if (!$result) |
|
| 801 | 801 | { |
| 802 | 802 | setEventMessages('Failed to write file '.$filecss, null, 'errors'); |
| 803 | 803 | return false; |
@@ -821,10 +821,10 @@ discard block |
||
| 821 | 821 | |
| 822 | 822 | dol_mkdir($pathofwebsite); |
| 823 | 823 | $result = file_put_contents($filejs, $jscontent); |
| 824 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 824 | + if (!empty($conf->global->MAIN_UMASK)) |
|
| 825 | 825 | @chmod($filejs, octdec($conf->global->MAIN_UMASK)); |
| 826 | 826 | |
| 827 | - if (! $result) |
|
| 827 | + if (!$result) |
|
| 828 | 828 | { |
| 829 | 829 | setEventMessages('Failed to write file '.$filejs, null, 'errors'); |
| 830 | 830 | return false; |
@@ -848,10 +848,10 @@ discard block |
||
| 848 | 848 | |
| 849 | 849 | dol_mkdir($pathofwebsite); |
| 850 | 850 | $result = file_put_contents($filerobot, $robotcontent); |
| 851 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 851 | + if (!empty($conf->global->MAIN_UMASK)) |
|
| 852 | 852 | @chmod($filerobot, octdec($conf->global->MAIN_UMASK)); |
| 853 | 853 | |
| 854 | - if (! $result) |
|
| 854 | + if (!$result) |
|
| 855 | 855 | { |
| 856 | 856 | setEventMessages('Failed to write file '.$filerobot, null, 'errors'); |
| 857 | 857 | return false; |
@@ -875,10 +875,10 @@ discard block |
||
| 875 | 875 | |
| 876 | 876 | dol_mkdir($pathofwebsite); |
| 877 | 877 | $result = file_put_contents($filehtaccess, $htaccess); |
| 878 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 878 | + if (!empty($conf->global->MAIN_UMASK)) |
|
| 879 | 879 | @chmod($filehtaccess, octdec($conf->global->MAIN_UMASK)); |
| 880 | 880 | |
| 881 | - if (! $result) |
|
| 881 | + if (!$result) |
|
| 882 | 882 | { |
| 883 | 883 | setEventMessages('Failed to write file '.$filehtaccess, null, 'errors'); |
| 884 | 884 | return false; |
@@ -39,28 +39,40 @@ discard block |
||
| 39 | 39 | |
| 40 | 40 | // Replace php code. Note $content may come from database and does not contains body tags. |
| 41 | 41 | $replacewith='...php...'; |
| 42 | - if ($removephppart) $replacewith=''; |
|
| 42 | + if ($removephppart) { |
|
| 43 | + $replacewith=''; |
|
| 44 | + } |
|
| 43 | 45 | $content = preg_replace('/value="<\?php((?!\?>).)*\?>\n*/ims', 'value="'.$replacewith.'"', $content); |
| 44 | 46 | |
| 45 | 47 | $replacewith='"callto=#'; |
| 46 | - if ($removephppart) $replacewith=''; |
|
| 48 | + if ($removephppart) { |
|
| 49 | + $replacewith=''; |
|
| 50 | + } |
|
| 47 | 51 | $content = preg_replace('/"callto:<\?php((?!\?>).)*\?>\n*/ims', $replacewith, $content); |
| 48 | 52 | |
| 49 | 53 | $replacewith='"mailto=#'; |
| 50 | - if ($removephppart) $replacewith=''; |
|
| 54 | + if ($removephppart) { |
|
| 55 | + $replacewith=''; |
|
| 56 | + } |
|
| 51 | 57 | $content = preg_replace('/"mailto:<\?php((?!\?>).)*\?>\n*/ims', $replacewith, $content); |
| 52 | 58 | |
| 53 | 59 | $replacewith='src="php'; |
| 54 | - if ($removephppart) $replacewith=''; |
|
| 60 | + if ($removephppart) { |
|
| 61 | + $replacewith=''; |
|
| 62 | + } |
|
| 55 | 63 | $content = preg_replace('/src="<\?php((?!\?>).)*\?>\n*/ims', $replacewith, $content); |
| 56 | 64 | |
| 57 | 65 | $replacewith='href="php'; |
| 58 | - if ($removephppart) $replacewith=''; |
|
| 66 | + if ($removephppart) { |
|
| 67 | + $replacewith=''; |
|
| 68 | + } |
|
| 59 | 69 | $content = preg_replace('/href="<\?php((?!\?>).)*\?>\n*/ims', $replacewith, $content); |
| 60 | 70 | |
| 61 | 71 | //$replacewith='<span class="phptag">...php...</span>'; |
| 62 | 72 | $replacewith='<span class="phptag">...php...</span>'; |
| 63 | - if ($removephppart) $replacewith=''; |
|
| 73 | + if ($removephppart) { |
|
| 74 | + $replacewith=''; |
|
| 75 | + } |
|
| 64 | 76 | //$content = preg_replace('/<\?php((?!\?toremove>).)*\?toremove>\n*/ims', $replacewith, $content); |
| 65 | 77 | /*if ($content === null) { |
| 66 | 78 | if (preg_last_error() == PREG_JIT_STACKLIMIT_ERROR) $content = 'preg_replace error (when removing php tags) PREG_JIT_STACKLIMIT_ERROR'; |
@@ -113,9 +125,11 @@ discard block |
||
| 113 | 125 | $i=0; |
| 114 | 126 | foreach($parts as $part) |
| 115 | 127 | { |
| 116 | - if ($i == 0) // The first part is never php code |
|
| 128 | + if ($i == 0) { |
|
| 129 | + // The first part is never php code |
|
| 117 | 130 | { |
| 118 | 131 | $i++; |
| 132 | + } |
|
| 119 | 133 | $newstr .= $part; |
| 120 | 134 | continue; |
| 121 | 135 | } |
@@ -124,7 +138,9 @@ discard block |
||
| 124 | 138 | if (!empty($partlings)) |
| 125 | 139 | { |
| 126 | 140 | //remove content before closing tag |
| 127 | - if (count($partlings) > 1) $partlings[0] = ''; |
|
| 141 | + if (count($partlings) > 1) { |
|
| 142 | + $partlings[0] = ''; |
|
| 143 | + } |
|
| 128 | 144 | //append to out string |
| 129 | 145 | $newstr .= $replacewith.implode('',$partlings); |
| 130 | 146 | } |
@@ -154,16 +170,19 @@ discard block |
||
| 154 | 170 | $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
| 155 | 171 | //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current |
| 156 | 172 | |
| 157 | - if (defined('USEDOLIBARREDITOR')) // REPLACEMENT OF LINKS When page called from Dolibarr editor |
|
| 173 | + if (defined('USEDOLIBARREDITOR')) { |
|
| 174 | + // REPLACEMENT OF LINKS When page called from Dolibarr editor |
|
| 158 | 175 | { |
| 159 | 176 | // We remove the <head> part of content |
| 160 | 177 | $content = preg_replace('/<head>.*<\/head>/ims', '', $content); |
| 178 | + } |
|
| 161 | 179 | $content = preg_replace('/^.*<body(\s[^>]*)*>/ims', '', $content); |
| 162 | 180 | $content = preg_replace('/<\/body(\s[^>]*)*>.*$/ims', '', $content); |
| 163 | - } |
|
| 164 | - elseif (defined('USEDOLIBARRSERVER')) // REPLACEMENT OF LINKS When page called from Dolibarr server |
|
| 181 | + } elseif (defined('USEDOLIBARRSERVER')) { |
|
| 182 | + // REPLACEMENT OF LINKS When page called from Dolibarr server |
|
| 165 | 183 | { |
| 166 | 184 | global $website; |
| 185 | + } |
|
| 167 | 186 | |
| 168 | 187 | // Replace relative link / with dolibarr URL: ...href="/"... |
| 169 | 188 | $content=preg_replace('/(href=")\/\"/', '\1'.DOL_URL_ROOT.'/public/website/index.php?website='.$website->ref.'"', $content, -1, $nbrep); |
@@ -194,8 +213,7 @@ discard block |
||
| 194 | 213 | |
| 195 | 214 | // action="newpage.php" => action="dolibarr/website/index.php?website=...&pageref=newpage |
| 196 | 215 | $content = preg_replace('/(action=")\/?([^:\"]*)(\.php\")/', '\1'.DOL_URL_ROOT.'/public/website/index.php?website='.$website->ref.'&pageref=\2"', $content, -1, $nbrep); |
| 197 | - } |
|
| 198 | - else // REPLACEMENT OF LINKS When page called from virtual host |
|
| 216 | + } else // REPLACEMENT OF LINKS When page called from virtual host |
|
| 199 | 217 | { |
| 200 | 218 | $symlinktomediaexists=1; |
| 201 | 219 | |
@@ -217,8 +235,7 @@ discard block |
||
| 217 | 235 | $content=preg_replace('/(url\(["\']?)[^\)]*viewimage\.php([^\)]*)hashp=([^\)]*)(["\']?\))/', '\1/wrapper.php\2hashp\3\4', $content, -1, $nbrep); |
| 218 | 236 | |
| 219 | 237 | $content=preg_replace('/(<img[^>]*src=")[^\"]*viewimage\.php([^\"]*)modulepart=mycompany([^\"]*)file=([^\"]*)("[^>]*>)/', '\1/wrapper.php\2modulepart=mycompany\3file=\4\5', $content, -1, $nbrep); |
| 220 | - } |
|
| 221 | - else |
|
| 238 | + } else |
|
| 222 | 239 | { |
| 223 | 240 | $content=preg_replace('/(<script[^>]*src=")[^\"]*document\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^>]*>)/', '\1medias/\4\5', $content, -1, $nbrep); |
| 224 | 241 | |
@@ -293,20 +310,21 @@ discard block |
||
| 293 | 310 | if ($result > 0) |
| 294 | 311 | { |
| 295 | 312 | $containerref = $tmpwebsitepage->pageurl; |
| 296 | - } |
|
| 297 | - else |
|
| 313 | + } else |
|
| 298 | 314 | { |
| 299 | 315 | print "Error, page contains a redirect to the alternative alias '".$containeraliasalt."' that does not exists in web site (".$website->id." / ".$website->ref.")"; |
| 300 | 316 | exit; |
| 301 | 317 | } |
| 302 | 318 | } |
| 303 | 319 | |
| 304 | - if (defined('USEDOLIBARRSERVER')) // When page called from Dolibarr server |
|
| 320 | + if (defined('USEDOLIBARRSERVER')) { |
|
| 321 | + // When page called from Dolibarr server |
|
| 305 | 322 | { |
| 306 | 323 | // Check new container exists |
| 307 | 324 | if (! $containeraliasalt) // If containeraliasalt set, we already did the test |
| 308 | 325 | { |
| 309 | 326 | include_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php'; |
| 327 | + } |
|
| 310 | 328 | $tmpwebsitepage=new WebsitePage($db); |
| 311 | 329 | $result = $tmpwebsitepage->fetch(0, $website->id, $containerref); |
| 312 | 330 | unset($tmpwebsitepage); |
@@ -320,19 +338,16 @@ discard block |
||
| 320 | 338 | { |
| 321 | 339 | print "Error, page with uri '.$currenturi.' try a redirect to the same alias page '".$containerref."' in web site '".$website->ref."'"; |
| 322 | 340 | exit; |
| 323 | - } |
|
| 324 | - else |
|
| 341 | + } else |
|
| 325 | 342 | { |
| 326 | 343 | $newurl = preg_replace('/&pageref=([^&]+)/', '&pageref='.$containerref, $currenturi); |
| 327 | 344 | } |
| 328 | - } |
|
| 329 | - else |
|
| 345 | + } else |
|
| 330 | 346 | { |
| 331 | 347 | $newurl = $currenturi.'&pageref='.urlencode($containerref); |
| 332 | 348 | } |
| 333 | 349 | } |
| 334 | - } |
|
| 335 | - else // When page called from virtual host server |
|
| 350 | + } else // When page called from virtual host server |
|
| 336 | 351 | { |
| 337 | 352 | $newurl = '/'.$containerref.'.php'; |
| 338 | 353 | } |
@@ -341,8 +356,7 @@ discard block |
||
| 341 | 356 | { |
| 342 | 357 | header("Location: ".$newurl); |
| 343 | 358 | exit; |
| 344 | - } |
|
| 345 | - else |
|
| 359 | + } else |
|
| 346 | 360 | { |
| 347 | 361 | print "Error, page contains a redirect to the alias page '".$containerref."' that does not exists in web site (".$website->id." / ".$website->ref.")"; |
| 348 | 362 | exit; |
@@ -365,11 +379,15 @@ discard block |
||
| 365 | 379 | |
| 366 | 380 | $MAXLEVEL=20; |
| 367 | 381 | |
| 368 | - if (! preg_match('/\.php$/i', $containerref)) $containerref.='.php'; |
|
| 382 | + if (! preg_match('/\.php$/i', $containerref)) { |
|
| 383 | + $containerref.='.php'; |
|
| 384 | + } |
|
| 369 | 385 | |
| 370 | 386 | $fullpathfile=DOL_DATA_ROOT.'/website/'.$websitekey.'/'.$containerref; |
| 371 | 387 | |
| 372 | - if (empty($includehtmlcontentopened)) $includehtmlcontentopened=0; |
|
| 388 | + if (empty($includehtmlcontentopened)) { |
|
| 389 | + $includehtmlcontentopened=0; |
|
| 390 | + } |
|
| 373 | 391 | $includehtmlcontentopened++; |
| 374 | 392 | if ($includehtmlcontentopened > $MAXLEVEL) |
| 375 | 393 | { |
@@ -422,7 +440,9 @@ discard block |
||
| 422 | 440 | |
| 423 | 441 | $alreadygrabbed=array(); |
| 424 | 442 | |
| 425 | - if (preg_match('/\/$/', $urltograb)) $urltograb.='.'; |
|
| 443 | + if (preg_match('/\/$/', $urltograb)) { |
|
| 444 | + $urltograb.='.'; |
|
| 445 | + } |
|
| 426 | 446 | $urltograb = dirname($urltograb); // So urltograb is now http://www.nltechno.com or http://www.nltechno.com/dir1 |
| 427 | 447 | |
| 428 | 448 | // Search X in "img...src=X" |
@@ -430,21 +450,25 @@ discard block |
||
| 430 | 450 | |
| 431 | 451 | foreach ($regs[0] as $key => $val) |
| 432 | 452 | { |
| 433 | - if (preg_match('/^data:image/i', $regs[2][$key])) continue; // We do nothing for such images |
|
| 453 | + if (preg_match('/^data:image/i', $regs[2][$key])) { |
|
| 454 | + continue; |
|
| 455 | + } |
|
| 456 | + // We do nothing for such images |
|
| 434 | 457 | |
| 435 | 458 | if (preg_match('/^\//', $regs[2][$key])) |
| 436 | 459 | { |
| 437 | 460 | $urltograbdirrootwithoutslash = getRootURLFromURL($urltograb); |
| 438 | 461 | $urltograbbis = $urltograbdirrootwithoutslash.$regs[2][$key]; // We use dirroot |
| 439 | - } |
|
| 440 | - else |
|
| 462 | + } else |
|
| 441 | 463 | { |
| 442 | 464 | $urltograbbis = $urltograb.'/'.$regs[2][$key]; // We use dir of grabbed file |
| 443 | 465 | } |
| 444 | 466 | |
| 445 | 467 | $linkwithoutdomain = $regs[2][$key]; |
| 446 | 468 | $dirforimages = '/'.$objectpage->pageurl; |
| 447 | - if ($grabimagesinto == 'root') $dirforimages=''; |
|
| 469 | + if ($grabimagesinto == 'root') { |
|
| 470 | + $dirforimages=''; |
|
| 471 | + } |
|
| 448 | 472 | |
| 449 | 473 | // Define $filetosave and $filename |
| 450 | 474 | $filetosave = $conf->medias->multidir_output[$conf->entity].'/image/'.$object->ref.$dirforimages.(preg_match('/^\//', $regs[2][$key])?'':'/').$regs[2][$key]; |
@@ -474,14 +498,12 @@ discard block |
||
| 474 | 498 | $error++; |
| 475 | 499 | setEventMessages('Error getting '.$urltograbbis.': '.$tmpgeturl['curl_error_msg'], null, 'errors'); |
| 476 | 500 | $action='create'; |
| 477 | - } |
|
| 478 | - elseif ($tmpgeturl['http_code'] != '200') |
|
| 501 | + } elseif ($tmpgeturl['http_code'] != '200') |
|
| 479 | 502 | { |
| 480 | 503 | $error++; |
| 481 | 504 | setEventMessages('Error getting '.$urltograbbis.': '.$tmpgeturl['http_code'], null, 'errors'); |
| 482 | 505 | $action='create'; |
| 483 | - } |
|
| 484 | - else |
|
| 506 | + } else |
|
| 485 | 507 | { |
| 486 | 508 | $alreadygrabbed[$urltograbbis]=1; // Track that file was alreay grabbed. |
| 487 | 509 | |
@@ -490,8 +512,9 @@ discard block |
||
| 490 | 512 | $fp = fopen($filetosave, "w"); |
| 491 | 513 | fputs($fp, $tmpgeturl['content']); |
| 492 | 514 | fclose($fp); |
| 493 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 494 | - @chmod($filetosave, octdec($conf->global->MAIN_UMASK)); |
|
| 515 | + if (! empty($conf->global->MAIN_UMASK)) { |
|
| 516 | + @chmod($filetosave, octdec($conf->global->MAIN_UMASK)); |
|
| 517 | + } |
|
| 495 | 518 | } |
| 496 | 519 | } |
| 497 | 520 | } |
@@ -507,14 +530,16 @@ discard block |
||
| 507 | 530 | |
| 508 | 531 | foreach ($regs[0] as $key => $val) |
| 509 | 532 | { |
| 510 | - if (preg_match('/^data:image/i', $regs[2][$key])) continue; // We do nothing for such images |
|
| 533 | + if (preg_match('/^data:image/i', $regs[2][$key])) { |
|
| 534 | + continue; |
|
| 535 | + } |
|
| 536 | + // We do nothing for such images |
|
| 511 | 537 | |
| 512 | 538 | if (preg_match('/^\//', $regs[2][$key])) |
| 513 | 539 | { |
| 514 | 540 | $urltograbdirrootwithoutslash = getRootURLFromURL($urltograb); |
| 515 | 541 | $urltograbbis = $urltograbdirrootwithoutslash.$regs[2][$key]; // We use dirroot |
| 516 | - } |
|
| 517 | - else |
|
| 542 | + } else |
|
| 518 | 543 | { |
| 519 | 544 | $urltograbbis = $urltograb.'/'.$regs[2][$key]; // We use dir of grabbed file |
| 520 | 545 | } |
@@ -522,7 +547,9 @@ discard block |
||
| 522 | 547 | $linkwithoutdomain = $regs[2][$key]; |
| 523 | 548 | |
| 524 | 549 | $dirforimages = '/'.$objectpage->pageurl; |
| 525 | - if ($grabimagesinto == 'root') $dirforimages=''; |
|
| 550 | + if ($grabimagesinto == 'root') { |
|
| 551 | + $dirforimages=''; |
|
| 552 | + } |
|
| 526 | 553 | |
| 527 | 554 | $filetosave = $conf->medias->multidir_output[$conf->entity].'/image/'.$object->ref.$dirforimages.(preg_match('/^\//', $regs[2][$key])?'':'/').$regs[2][$key]; |
| 528 | 555 | |
@@ -553,14 +580,12 @@ discard block |
||
| 553 | 580 | $error++; |
| 554 | 581 | setEventMessages('Error getting '.$urltograbbis.': '.$tmpgeturl['curl_error_msg'], null, 'errors'); |
| 555 | 582 | $action='create'; |
| 556 | - } |
|
| 557 | - elseif ($tmpgeturl['http_code'] != '200') |
|
| 583 | + } elseif ($tmpgeturl['http_code'] != '200') |
|
| 558 | 584 | { |
| 559 | 585 | $error++; |
| 560 | 586 | setEventMessages('Error getting '.$urltograbbis.': '.$tmpgeturl['http_code'], null, 'errors'); |
| 561 | 587 | $action='create'; |
| 562 | - } |
|
| 563 | - else |
|
| 588 | + } else |
|
| 564 | 589 | { |
| 565 | 590 | $alreadygrabbed[$urltograbbis]=1; // Track that file was alreay grabbed. |
| 566 | 591 | |
@@ -569,8 +594,9 @@ discard block |
||
| 569 | 594 | $fp = fopen($filetosave, "w"); |
| 570 | 595 | fputs($fp, $tmpgeturl['content']); |
| 571 | 596 | fclose($fp); |
| 572 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 573 | - @chmod($filetosave, octdec($conf->global->MAIN_UMASK)); |
|
| 597 | + if (! empty($conf->global->MAIN_UMASK)) { |
|
| 598 | + @chmod($filetosave, octdec($conf->global->MAIN_UMASK)); |
|
| 599 | + } |
|
| 574 | 600 | } |
| 575 | 601 | } |
| 576 | 602 | } |
@@ -603,8 +629,9 @@ discard block |
||
| 603 | 629 | $mastercontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) require_once '".DOL_DOCUMENT_ROOT."/master.inc.php';\n"; |
| 604 | 630 | $mastercontent.= '?>'."\n"; |
| 605 | 631 | $result = file_put_contents($filemaster, $mastercontent); |
| 606 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 607 | - @chmod($filemaster, octdec($conf->global->MAIN_UMASK)); |
|
| 632 | + if (! empty($conf->global->MAIN_UMASK)) { |
|
| 633 | + @chmod($filemaster, octdec($conf->global->MAIN_UMASK)); |
|
| 634 | + } |
|
| 608 | 635 | |
| 609 | 636 | return $result; |
| 610 | 637 | } |
@@ -657,7 +684,10 @@ discard block |
||
| 657 | 684 | dol_delete_file($filetpl); |
| 658 | 685 | |
| 659 | 686 | $shortlangcode = ''; |
| 660 | - if ($objectpage->lang) $shortlangcode=preg_replace('/[_-].*$/', '', $objectpage->lang); // en_US or en-US -> en |
|
| 687 | + if ($objectpage->lang) { |
|
| 688 | + $shortlangcode=preg_replace('/[_-].*$/', '', $objectpage->lang); |
|
| 689 | + } |
|
| 690 | + // en_US or en-US -> en |
|
| 661 | 691 | |
| 662 | 692 | $tplcontent =''; |
| 663 | 693 | $tplcontent.= "<?php // BEGIN PHP\n"; |
@@ -699,8 +729,9 @@ discard block |
||
| 699 | 729 | |
| 700 | 730 | //var_dump($filetpl);exit; |
| 701 | 731 | $result = file_put_contents($filetpl, $tplcontent); |
| 702 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 703 | - @chmod($filetpl, octdec($conf->global->MAIN_UMASK)); |
|
| 732 | + if (! empty($conf->global->MAIN_UMASK)) { |
|
| 733 | + @chmod($filetpl, octdec($conf->global->MAIN_UMASK)); |
|
| 734 | + } |
|
| 704 | 735 | |
| 705 | 736 | return $result; |
| 706 | 737 | } |
@@ -737,16 +768,18 @@ discard block |
||
| 737 | 768 | $indexcontent.= "include_once './".basename($filetpl)."'\n"; |
| 738 | 769 | $indexcontent.= '// END PHP ?>'."\n"; |
| 739 | 770 | $result1 = file_put_contents($fileindex, $indexcontent); |
| 740 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 741 | - @chmod($fileindex, octdec($conf->global->MAIN_UMASK)); |
|
| 771 | + if (! empty($conf->global->MAIN_UMASK)) { |
|
| 772 | + @chmod($fileindex, octdec($conf->global->MAIN_UMASK)); |
|
| 773 | + } |
|
| 742 | 774 | |
| 743 | 775 | dol_delete_file($filewrapper); |
| 744 | 776 | |
| 745 | 777 | $wrappercontent=file_get_contents(DOL_DOCUMENT_ROOT.'/website/samples/wrapper.html'); |
| 746 | 778 | |
| 747 | 779 | $result2 = file_put_contents($filewrapper, $wrappercontent); |
| 748 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 749 | - @chmod($filewrapper, octdec($conf->global->MAIN_UMASK)); |
|
| 780 | + if (! empty($conf->global->MAIN_UMASK)) { |
|
| 781 | + @chmod($filewrapper, octdec($conf->global->MAIN_UMASK)); |
|
| 782 | + } |
|
| 750 | 783 | |
| 751 | 784 | return ($result1 && $result2); |
| 752 | 785 | } |
@@ -767,8 +800,9 @@ discard block |
||
| 767 | 800 | |
| 768 | 801 | dol_mkdir($pathofwebsite); |
| 769 | 802 | $result = file_put_contents($filehtmlheader, $htmlheadercontent); |
| 770 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 771 | - @chmod($filehtmlheader, octdec($conf->global->MAIN_UMASK)); |
|
| 803 | + if (! empty($conf->global->MAIN_UMASK)) { |
|
| 804 | + @chmod($filehtmlheader, octdec($conf->global->MAIN_UMASK)); |
|
| 805 | + } |
|
| 772 | 806 | |
| 773 | 807 | if (! $result) |
| 774 | 808 | { |
@@ -794,8 +828,9 @@ discard block |
||
| 794 | 828 | |
| 795 | 829 | dol_mkdir($pathofwebsite); |
| 796 | 830 | $result = file_put_contents($filecss, $csscontent); |
| 797 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 798 | - @chmod($filecss, octdec($conf->global->MAIN_UMASK)); |
|
| 831 | + if (! empty($conf->global->MAIN_UMASK)) { |
|
| 832 | + @chmod($filecss, octdec($conf->global->MAIN_UMASK)); |
|
| 833 | + } |
|
| 799 | 834 | |
| 800 | 835 | if (! $result) |
| 801 | 836 | { |
@@ -821,8 +856,9 @@ discard block |
||
| 821 | 856 | |
| 822 | 857 | dol_mkdir($pathofwebsite); |
| 823 | 858 | $result = file_put_contents($filejs, $jscontent); |
| 824 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 825 | - @chmod($filejs, octdec($conf->global->MAIN_UMASK)); |
|
| 859 | + if (! empty($conf->global->MAIN_UMASK)) { |
|
| 860 | + @chmod($filejs, octdec($conf->global->MAIN_UMASK)); |
|
| 861 | + } |
|
| 826 | 862 | |
| 827 | 863 | if (! $result) |
| 828 | 864 | { |
@@ -848,8 +884,9 @@ discard block |
||
| 848 | 884 | |
| 849 | 885 | dol_mkdir($pathofwebsite); |
| 850 | 886 | $result = file_put_contents($filerobot, $robotcontent); |
| 851 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 852 | - @chmod($filerobot, octdec($conf->global->MAIN_UMASK)); |
|
| 887 | + if (! empty($conf->global->MAIN_UMASK)) { |
|
| 888 | + @chmod($filerobot, octdec($conf->global->MAIN_UMASK)); |
|
| 889 | + } |
|
| 853 | 890 | |
| 854 | 891 | if (! $result) |
| 855 | 892 | { |
@@ -875,8 +912,9 @@ discard block |
||
| 875 | 912 | |
| 876 | 913 | dol_mkdir($pathofwebsite); |
| 877 | 914 | $result = file_put_contents($filehtaccess, $htaccess); |
| 878 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 879 | - @chmod($filehtaccess, octdec($conf->global->MAIN_UMASK)); |
|
| 915 | + if (! empty($conf->global->MAIN_UMASK)) { |
|
| 916 | + @chmod($filehtaccess, octdec($conf->global->MAIN_UMASK)); |
|
| 917 | + } |
|
| 880 | 918 | |
| 881 | 919 | if (! $result) |
| 882 | 920 | { |
@@ -31,28 +31,28 @@ discard block |
||
| 31 | 31 | */ |
| 32 | 32 | function supplier_proposal_prepare_head($object) |
| 33 | 33 | { |
| 34 | - global $db, $langs, $conf, $user; |
|
| 34 | + global $db, $langs, $conf, $user; |
|
| 35 | 35 | |
| 36 | - // Load translation files required by the page |
|
| 36 | + // Load translation files required by the page |
|
| 37 | 37 | $langs->loadLangs(array("supplier_proposal","compta")); |
| 38 | 38 | |
| 39 | - $h = 0; |
|
| 40 | - $head = array(); |
|
| 39 | + $h = 0; |
|
| 40 | + $head = array(); |
|
| 41 | 41 | |
| 42 | - $head[$h][0] = DOL_URL_ROOT.'/supplier_proposal/card.php?id='.$object->id; |
|
| 43 | - $head[$h][1] = $langs->trans('SupplierProposalCard'); |
|
| 44 | - $head[$h][2] = 'comm'; |
|
| 45 | - $h++; |
|
| 42 | + $head[$h][0] = DOL_URL_ROOT.'/supplier_proposal/card.php?id='.$object->id; |
|
| 43 | + $head[$h][1] = $langs->trans('SupplierProposalCard'); |
|
| 44 | + $head[$h][2] = 'comm'; |
|
| 45 | + $h++; |
|
| 46 | 46 | |
| 47 | - if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) |
|
| 48 | - { |
|
| 49 | - $nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external')); |
|
| 50 | - $head[$h][0] = DOL_URL_ROOT.'/supplier_proposal/contact.php?id='.$object->id; |
|
| 51 | - $head[$h][1] = $langs->trans('ContactsAddresses'); |
|
| 52 | - if ($nbContact > 0) $head[$h][1].= ' <span class="badge">'.$nbContact.'</span>'; |
|
| 53 | - $head[$h][2] = 'contact'; |
|
| 54 | - $h++; |
|
| 55 | - } |
|
| 47 | + if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) |
|
| 48 | + { |
|
| 49 | + $nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external')); |
|
| 50 | + $head[$h][0] = DOL_URL_ROOT.'/supplier_proposal/contact.php?id='.$object->id; |
|
| 51 | + $head[$h][1] = $langs->trans('ContactsAddresses'); |
|
| 52 | + if ($nbContact > 0) $head[$h][1].= ' <span class="badge">'.$nbContact.'</span>'; |
|
| 53 | + $head[$h][2] = 'contact'; |
|
| 54 | + $h++; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | 57 | // Show more tabs from modules |
| 58 | 58 | // Entries must be declared in modules descriptor with line |
@@ -62,35 +62,35 @@ discard block |
||
| 62 | 62 | |
| 63 | 63 | if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) |
| 64 | 64 | { |
| 65 | - $nbNote = 0; |
|
| 65 | + $nbNote = 0; |
|
| 66 | 66 | if(!empty($object->note_private)) $nbNote++; |
| 67 | - if(!empty($object->note_public)) $nbNote++; |
|
| 68 | - $head[$h][0] = DOL_URL_ROOT.'/supplier_proposal/note.php?id='.$object->id; |
|
| 69 | - $head[$h][1] = $langs->trans('Notes'); |
|
| 70 | - if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>'; |
|
| 71 | - $head[$h][2] = 'note'; |
|
| 72 | - $h++; |
|
| 67 | + if(!empty($object->note_public)) $nbNote++; |
|
| 68 | + $head[$h][0] = DOL_URL_ROOT.'/supplier_proposal/note.php?id='.$object->id; |
|
| 69 | + $head[$h][1] = $langs->trans('Notes'); |
|
| 70 | + if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>'; |
|
| 71 | + $head[$h][2] = 'note'; |
|
| 72 | + $h++; |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
| 75 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
| 76 | 76 | require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php'; |
| 77 | - $upload_dir = $conf->supplier_proposal->dir_output . "/" . dol_sanitizeFileName($object->ref); |
|
| 78 | - $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview.*\.png)$')); |
|
| 77 | + $upload_dir = $conf->supplier_proposal->dir_output . "/" . dol_sanitizeFileName($object->ref); |
|
| 78 | + $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview.*\.png)$')); |
|
| 79 | 79 | $nbLinks=Link::count($db, $object->element, $object->id); |
| 80 | - $head[$h][0] = DOL_URL_ROOT.'/supplier_proposal/document.php?id='.$object->id; |
|
| 81 | - $head[$h][1] = $langs->trans('Documents'); |
|
| 82 | - if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>'; |
|
| 83 | - $head[$h][2] = 'document'; |
|
| 84 | - $h++; |
|
| 80 | + $head[$h][0] = DOL_URL_ROOT.'/supplier_proposal/document.php?id='.$object->id; |
|
| 81 | + $head[$h][1] = $langs->trans('Documents'); |
|
| 82 | + if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>'; |
|
| 83 | + $head[$h][2] = 'document'; |
|
| 84 | + $h++; |
|
| 85 | 85 | |
| 86 | - $head[$h][0] = DOL_URL_ROOT.'/supplier_proposal/info.php?id='.$object->id; |
|
| 87 | - $head[$h][1] = $langs->trans('Info'); |
|
| 88 | - $head[$h][2] = 'info'; |
|
| 89 | - $h++; |
|
| 86 | + $head[$h][0] = DOL_URL_ROOT.'/supplier_proposal/info.php?id='.$object->id; |
|
| 87 | + $head[$h][1] = $langs->trans('Info'); |
|
| 88 | + $head[$h][2] = 'info'; |
|
| 89 | + $h++; |
|
| 90 | 90 | |
| 91 | - complete_head_from_modules($conf,$langs,$object,$head,$h,'supplier_proposal','remove'); |
|
| 91 | + complete_head_from_modules($conf,$langs,$object,$head,$h,'supplier_proposal','remove'); |
|
| 92 | 92 | |
| 93 | - return $head; |
|
| 93 | + return $head; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
@@ -100,24 +100,24 @@ discard block |
||
| 100 | 100 | */ |
| 101 | 101 | function supplier_proposal_admin_prepare_head() |
| 102 | 102 | { |
| 103 | - global $langs, $conf, $user; |
|
| 103 | + global $langs, $conf, $user; |
|
| 104 | 104 | |
| 105 | - $h = 0; |
|
| 106 | - $head = array(); |
|
| 105 | + $h = 0; |
|
| 106 | + $head = array(); |
|
| 107 | 107 | |
| 108 | - $head[$h][0] = DOL_URL_ROOT.'/admin/supplier_proposal.php'; |
|
| 109 | - $head[$h][1] = $langs->trans("Miscellaneous"); |
|
| 110 | - $head[$h][2] = 'general'; |
|
| 111 | - $h++; |
|
| 108 | + $head[$h][0] = DOL_URL_ROOT.'/admin/supplier_proposal.php'; |
|
| 109 | + $head[$h][1] = $langs->trans("Miscellaneous"); |
|
| 110 | + $head[$h][2] = 'general'; |
|
| 111 | + $h++; |
|
| 112 | 112 | |
| 113 | - // Show more tabs from modules |
|
| 114 | - // Entries must be declared in modules descriptor with line |
|
| 115 | - // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab |
|
| 116 | - // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab |
|
| 117 | - complete_head_from_modules($conf,$langs,null,$head,$h,'supplier_proposal_admin'); |
|
| 113 | + // Show more tabs from modules |
|
| 114 | + // Entries must be declared in modules descriptor with line |
|
| 115 | + // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab |
|
| 116 | + // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab |
|
| 117 | + complete_head_from_modules($conf,$langs,null,$head,$h,'supplier_proposal_admin'); |
|
| 118 | 118 | |
| 119 | - $head[$h][0] = DOL_URL_ROOT.'/supplier_proposal/admin/supplier_proposal_extrafields.php'; |
|
| 120 | - $head[$h][1] = $langs->trans("ExtraFields"); |
|
| 119 | + $head[$h][0] = DOL_URL_ROOT.'/supplier_proposal/admin/supplier_proposal_extrafields.php'; |
|
| 120 | + $head[$h][1] = $langs->trans("ExtraFields"); |
|
| 121 | 121 | $head[$h][2] = 'attributes'; |
| 122 | 122 | $h++; |
| 123 | 123 | |
@@ -126,9 +126,9 @@ discard block |
||
| 126 | 126 | $head[$h][2] = 'attributeslines'; |
| 127 | 127 | $h++; |
| 128 | 128 | |
| 129 | - complete_head_from_modules($conf,$langs,null,$head,$h,'supplier_proposal_admin','remove'); |
|
| 129 | + complete_head_from_modules($conf,$langs,null,$head,$h,'supplier_proposal_admin','remove'); |
|
| 130 | 130 | |
| 131 | - return $head; |
|
| 131 | + return $head; |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | global $db, $langs, $conf, $user; |
| 35 | 35 | |
| 36 | 36 | // Load translation files required by the page |
| 37 | - $langs->loadLangs(array("supplier_proposal","compta")); |
|
| 37 | + $langs->loadLangs(array("supplier_proposal", "compta")); |
|
| 38 | 38 | |
| 39 | 39 | $h = 0; |
| 40 | 40 | $head = array(); |
@@ -46,10 +46,10 @@ discard block |
||
| 46 | 46 | |
| 47 | 47 | if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) |
| 48 | 48 | { |
| 49 | - $nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external')); |
|
| 49 | + $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external')); |
|
| 50 | 50 | $head[$h][0] = DOL_URL_ROOT.'/supplier_proposal/contact.php?id='.$object->id; |
| 51 | 51 | $head[$h][1] = $langs->trans('ContactsAddresses'); |
| 52 | - if ($nbContact > 0) $head[$h][1].= ' <span class="badge">'.$nbContact.'</span>'; |
|
| 52 | + if ($nbContact > 0) $head[$h][1] .= ' <span class="badge">'.$nbContact.'</span>'; |
|
| 53 | 53 | $head[$h][2] = 'contact'; |
| 54 | 54 | $h++; |
| 55 | 55 | } |
@@ -58,28 +58,28 @@ discard block |
||
| 58 | 58 | // Entries must be declared in modules descriptor with line |
| 59 | 59 | // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab |
| 60 | 60 | // $this->tabs = array('entity:-tabname); to remove a tab |
| 61 | - complete_head_from_modules($conf,$langs,$object,$head,$h,'supplier_proposal'); |
|
| 61 | + complete_head_from_modules($conf, $langs, $object, $head, $h, 'supplier_proposal'); |
|
| 62 | 62 | |
| 63 | 63 | if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) |
| 64 | 64 | { |
| 65 | 65 | $nbNote = 0; |
| 66 | - if(!empty($object->note_private)) $nbNote++; |
|
| 67 | - if(!empty($object->note_public)) $nbNote++; |
|
| 66 | + if (!empty($object->note_private)) $nbNote++; |
|
| 67 | + if (!empty($object->note_public)) $nbNote++; |
|
| 68 | 68 | $head[$h][0] = DOL_URL_ROOT.'/supplier_proposal/note.php?id='.$object->id; |
| 69 | 69 | $head[$h][1] = $langs->trans('Notes'); |
| 70 | - if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>'; |
|
| 70 | + if ($nbNote > 0) $head[$h][1] .= ' <span class="badge">'.$nbNote.'</span>'; |
|
| 71 | 71 | $head[$h][2] = 'note'; |
| 72 | 72 | $h++; |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
| 76 | 76 | require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php'; |
| 77 | - $upload_dir = $conf->supplier_proposal->dir_output . "/" . dol_sanitizeFileName($object->ref); |
|
| 78 | - $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview.*\.png)$')); |
|
| 79 | - $nbLinks=Link::count($db, $object->element, $object->id); |
|
| 77 | + $upload_dir = $conf->supplier_proposal->dir_output."/".dol_sanitizeFileName($object->ref); |
|
| 78 | + $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$')); |
|
| 79 | + $nbLinks = Link::count($db, $object->element, $object->id); |
|
| 80 | 80 | $head[$h][0] = DOL_URL_ROOT.'/supplier_proposal/document.php?id='.$object->id; |
| 81 | 81 | $head[$h][1] = $langs->trans('Documents'); |
| 82 | - if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>'; |
|
| 82 | + if (($nbFiles + $nbLinks) > 0) $head[$h][1] .= ' <span class="badge">'.($nbFiles + $nbLinks).'</span>'; |
|
| 83 | 83 | $head[$h][2] = 'document'; |
| 84 | 84 | $h++; |
| 85 | 85 | |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | $head[$h][2] = 'info'; |
| 89 | 89 | $h++; |
| 90 | 90 | |
| 91 | - complete_head_from_modules($conf,$langs,$object,$head,$h,'supplier_proposal','remove'); |
|
| 91 | + complete_head_from_modules($conf, $langs, $object, $head, $h, 'supplier_proposal', 'remove'); |
|
| 92 | 92 | |
| 93 | 93 | return $head; |
| 94 | 94 | } |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | // Entries must be declared in modules descriptor with line |
| 115 | 115 | // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab |
| 116 | 116 | // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab |
| 117 | - complete_head_from_modules($conf,$langs,null,$head,$h,'supplier_proposal_admin'); |
|
| 117 | + complete_head_from_modules($conf, $langs, null, $head, $h, 'supplier_proposal_admin'); |
|
| 118 | 118 | |
| 119 | 119 | $head[$h][0] = DOL_URL_ROOT.'/supplier_proposal/admin/supplier_proposal_extrafields.php'; |
| 120 | 120 | $head[$h][1] = $langs->trans("ExtraFields"); |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | $head[$h][2] = 'attributeslines'; |
| 127 | 127 | $h++; |
| 128 | 128 | |
| 129 | - complete_head_from_modules($conf,$langs,null,$head,$h,'supplier_proposal_admin','remove'); |
|
| 129 | + complete_head_from_modules($conf, $langs, null, $head, $h, 'supplier_proposal_admin', 'remove'); |
|
| 130 | 130 | |
| 131 | 131 | return $head; |
| 132 | 132 | } |
@@ -49,7 +49,9 @@ discard block |
||
| 49 | 49 | $nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external')); |
| 50 | 50 | $head[$h][0] = DOL_URL_ROOT.'/supplier_proposal/contact.php?id='.$object->id; |
| 51 | 51 | $head[$h][1] = $langs->trans('ContactsAddresses'); |
| 52 | - if ($nbContact > 0) $head[$h][1].= ' <span class="badge">'.$nbContact.'</span>'; |
|
| 52 | + if ($nbContact > 0) { |
|
| 53 | + $head[$h][1].= ' <span class="badge">'.$nbContact.'</span>'; |
|
| 54 | + } |
|
| 53 | 55 | $head[$h][2] = 'contact'; |
| 54 | 56 | $h++; |
| 55 | 57 | } |
@@ -63,11 +65,17 @@ discard block |
||
| 63 | 65 | if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) |
| 64 | 66 | { |
| 65 | 67 | $nbNote = 0; |
| 66 | - if(!empty($object->note_private)) $nbNote++; |
|
| 67 | - if(!empty($object->note_public)) $nbNote++; |
|
| 68 | + if(!empty($object->note_private)) { |
|
| 69 | + $nbNote++; |
|
| 70 | + } |
|
| 71 | + if(!empty($object->note_public)) { |
|
| 72 | + $nbNote++; |
|
| 73 | + } |
|
| 68 | 74 | $head[$h][0] = DOL_URL_ROOT.'/supplier_proposal/note.php?id='.$object->id; |
| 69 | 75 | $head[$h][1] = $langs->trans('Notes'); |
| 70 | - if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>'; |
|
| 76 | + if ($nbNote > 0) { |
|
| 77 | + $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>'; |
|
| 78 | + } |
|
| 71 | 79 | $head[$h][2] = 'note'; |
| 72 | 80 | $h++; |
| 73 | 81 | } |
@@ -79,7 +87,9 @@ discard block |
||
| 79 | 87 | $nbLinks=Link::count($db, $object->element, $object->id); |
| 80 | 88 | $head[$h][0] = DOL_URL_ROOT.'/supplier_proposal/document.php?id='.$object->id; |
| 81 | 89 | $head[$h][1] = $langs->trans('Documents'); |
| 82 | - if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>'; |
|
| 90 | + if (($nbFiles+$nbLinks) > 0) { |
|
| 91 | + $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>'; |
|
| 92 | + } |
|
| 83 | 93 | $head[$h][2] = 'document'; |
| 84 | 94 | $h++; |
| 85 | 95 | |
@@ -98,8 +98,8 @@ discard block |
||
| 98 | 98 | } |
| 99 | 99 | else |
| 100 | 100 | { |
| 101 | - $tmp=0; |
|
| 102 | - dol_print_error('','PHP version must be 5.3+'); |
|
| 101 | + $tmp=0; |
|
| 102 | + dol_print_error('','PHP version must be 5.3+'); |
|
| 103 | 103 | } |
| 104 | 104 | $tz=round(($tmp<0?1:-1)*abs($tmp/3600)); |
| 105 | 105 | return $tz; |
@@ -116,29 +116,29 @@ discard block |
||
| 116 | 116 | */ |
| 117 | 117 | function dol_time_plus_duree($time, $duration_value, $duration_unit) |
| 118 | 118 | { |
| 119 | - global $conf; |
|
| 119 | + global $conf; |
|
| 120 | 120 | |
| 121 | - if ($duration_value == 0) return $time; |
|
| 122 | - if ($duration_unit == 'h') return $time + (3600*$duration_value); |
|
| 123 | - if ($duration_unit == 'w') return $time + (3600*24*7*$duration_value); |
|
| 121 | + if ($duration_value == 0) return $time; |
|
| 122 | + if ($duration_unit == 'h') return $time + (3600*$duration_value); |
|
| 123 | + if ($duration_unit == 'w') return $time + (3600*24*7*$duration_value); |
|
| 124 | 124 | |
| 125 | - $deltastring='P'; |
|
| 125 | + $deltastring='P'; |
|
| 126 | 126 | |
| 127 | - if ($duration_value > 0){ $deltastring.=abs($duration_value); $sub= false; } |
|
| 128 | - if ($duration_value < 0){ $deltastring.=abs($duration_value); $sub= true; } |
|
| 129 | - if ($duration_unit == 'd') { $deltastring.="D"; } |
|
| 130 | - if ($duration_unit == 'm') { $deltastring.="M"; } |
|
| 131 | - if ($duration_unit == 'y') { $deltastring.="Y"; } |
|
| 127 | + if ($duration_value > 0){ $deltastring.=abs($duration_value); $sub= false; } |
|
| 128 | + if ($duration_value < 0){ $deltastring.=abs($duration_value); $sub= true; } |
|
| 129 | + if ($duration_unit == 'd') { $deltastring.="D"; } |
|
| 130 | + if ($duration_unit == 'm') { $deltastring.="M"; } |
|
| 131 | + if ($duration_unit == 'y') { $deltastring.="Y"; } |
|
| 132 | 132 | |
| 133 | - $date = new DateTime(); |
|
| 134 | - if (! empty($conf->global->MAIN_DATE_IN_MEMORY_ARE_GMT)) $date->setTimezone(new DateTimeZone('UTC')); |
|
| 135 | - $date->setTimestamp($time); |
|
| 136 | - $interval = new DateInterval($deltastring); |
|
| 133 | + $date = new DateTime(); |
|
| 134 | + if (! empty($conf->global->MAIN_DATE_IN_MEMORY_ARE_GMT)) $date->setTimezone(new DateTimeZone('UTC')); |
|
| 135 | + $date->setTimestamp($time); |
|
| 136 | + $interval = new DateInterval($deltastring); |
|
| 137 | 137 | |
| 138 | - if($sub) $date->sub($interval); |
|
| 139 | - else $date->add( $interval ); |
|
| 138 | + if($sub) $date->sub($interval); |
|
| 139 | + else $date->add( $interval ); |
|
| 140 | 140 | |
| 141 | - return $date->getTimestamp(); |
|
| 141 | + return $date->getTimestamp(); |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | |
@@ -153,8 +153,8 @@ discard block |
||
| 153 | 153 | */ |
| 154 | 154 | function convertTime2Seconds($iHours=0, $iMinutes=0, $iSeconds=0) |
| 155 | 155 | { |
| 156 | - $iResult=($iHours*3600)+($iMinutes*60)+$iSeconds; |
|
| 157 | - return $iResult; |
|
| 156 | + $iResult=($iHours*3600)+($iMinutes*60)+$iSeconds; |
|
| 157 | + return $iResult; |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | |
@@ -180,33 +180,33 @@ discard block |
||
| 180 | 180 | */ |
| 181 | 181 | function convertSecondToTime($iSecond, $format='all', $lengthOfDay=86400, $lengthOfWeek=7) |
| 182 | 182 | { |
| 183 | - global $langs; |
|
| 183 | + global $langs; |
|
| 184 | 184 | |
| 185 | - if (empty($lengthOfDay)) $lengthOfDay = 86400; // 1 day = 24 hours |
|
| 185 | + if (empty($lengthOfDay)) $lengthOfDay = 86400; // 1 day = 24 hours |
|
| 186 | 186 | if (empty($lengthOfWeek)) $lengthOfWeek = 7; // 1 week = 7 days |
| 187 | 187 | |
| 188 | - if ($format == 'all' || $format == 'allwithouthour' || $format == 'allhour' || $format == 'allhourmin') |
|
| 189 | - { |
|
| 190 | - if ((int) $iSecond === 0) return '0'; // This is to avoid having 0 return a 12:00 AM for en_US |
|
| 188 | + if ($format == 'all' || $format == 'allwithouthour' || $format == 'allhour' || $format == 'allhourmin') |
|
| 189 | + { |
|
| 190 | + if ((int) $iSecond === 0) return '0'; // This is to avoid having 0 return a 12:00 AM for en_US |
|
| 191 | 191 | |
| 192 | 192 | $sTime=''; |
| 193 | 193 | $sDay=0; |
| 194 | 194 | $sWeek=0; |
| 195 | 195 | |
| 196 | - if ($iSecond >= $lengthOfDay) |
|
| 197 | - { |
|
| 198 | - for($i = $iSecond; $i >= $lengthOfDay; $i -= $lengthOfDay ) |
|
| 199 | - { |
|
| 200 | - $sDay++; |
|
| 201 | - $iSecond-=$lengthOfDay; |
|
| 202 | - } |
|
| 203 | - $dayTranslate = $langs->trans("Day"); |
|
| 204 | - if ($iSecond >= ($lengthOfDay*2)) $dayTranslate = $langs->trans("Days"); |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - if ($lengthOfWeek < 7) |
|
| 208 | - { |
|
| 209 | - if ($sDay) |
|
| 196 | + if ($iSecond >= $lengthOfDay) |
|
| 197 | + { |
|
| 198 | + for($i = $iSecond; $i >= $lengthOfDay; $i -= $lengthOfDay ) |
|
| 199 | + { |
|
| 200 | + $sDay++; |
|
| 201 | + $iSecond-=$lengthOfDay; |
|
| 202 | + } |
|
| 203 | + $dayTranslate = $langs->trans("Day"); |
|
| 204 | + if ($iSecond >= ($lengthOfDay*2)) $dayTranslate = $langs->trans("Days"); |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + if ($lengthOfWeek < 7) |
|
| 208 | + { |
|
| 209 | + if ($sDay) |
|
| 210 | 210 | { |
| 211 | 211 | if ($sDay >= $lengthOfWeek) |
| 212 | 212 | { |
@@ -217,48 +217,48 @@ discard block |
||
| 217 | 217 | $sTime.=$sWeek.' '.$weekTranslate.' '; |
| 218 | 218 | } |
| 219 | 219 | } |
| 220 | - } |
|
| 221 | - if ($sDay>0) |
|
| 222 | - { |
|
| 223 | - $dayTranslate = $langs->trans("Day"); |
|
| 224 | - if ($sDay > 1) $dayTranslate = $langs->trans("Days"); |
|
| 225 | - $sTime.=$sDay.' '.$dayTranslate.' '; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - if ($format == 'all') |
|
| 229 | - { |
|
| 230 | - if ($iSecond || empty($sDay)) |
|
| 231 | - { |
|
| 232 | - $sTime.= dol_print_date($iSecond,'hourduration',true); |
|
| 233 | - } |
|
| 234 | - } |
|
| 235 | - if ($format == 'allhourmin') |
|
| 236 | - { |
|
| 237 | - return sprintf("%02d",($sWeek*$lengthOfWeek*24 + $sDay*24 + (int) floor($iSecond/3600))).':'.sprintf("%02d",((int) floor(($iSecond % 3600)/60))); |
|
| 238 | - } |
|
| 239 | - if ($format == 'allhour') |
|
| 240 | - { |
|
| 241 | - return sprintf("%02d",($sWeek*$lengthOfWeek*24 + $sDay*24 + (int) floor($iSecond/3600))); |
|
| 242 | - } |
|
| 243 | - } |
|
| 244 | - else if ($format == 'hour') // only hour part |
|
| 245 | - { |
|
| 246 | - $sTime=dol_print_date($iSecond,'%H',true); |
|
| 247 | - } |
|
| 248 | - else if ($format == 'fullhour') |
|
| 249 | - { |
|
| 250 | - if (!empty($iSecond)) { |
|
| 251 | - $iSecond=$iSecond/3600; |
|
| 252 | - } |
|
| 253 | - else { |
|
| 254 | - $iSecond=0; |
|
| 255 | - } |
|
| 256 | - $sTime=$iSecond; |
|
| 257 | - } |
|
| 258 | - else if ($format == 'min') // only min part |
|
| 259 | - { |
|
| 260 | - $sTime=dol_print_date($iSecond,'%M',true); |
|
| 261 | - } |
|
| 220 | + } |
|
| 221 | + if ($sDay>0) |
|
| 222 | + { |
|
| 223 | + $dayTranslate = $langs->trans("Day"); |
|
| 224 | + if ($sDay > 1) $dayTranslate = $langs->trans("Days"); |
|
| 225 | + $sTime.=$sDay.' '.$dayTranslate.' '; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + if ($format == 'all') |
|
| 229 | + { |
|
| 230 | + if ($iSecond || empty($sDay)) |
|
| 231 | + { |
|
| 232 | + $sTime.= dol_print_date($iSecond,'hourduration',true); |
|
| 233 | + } |
|
| 234 | + } |
|
| 235 | + if ($format == 'allhourmin') |
|
| 236 | + { |
|
| 237 | + return sprintf("%02d",($sWeek*$lengthOfWeek*24 + $sDay*24 + (int) floor($iSecond/3600))).':'.sprintf("%02d",((int) floor(($iSecond % 3600)/60))); |
|
| 238 | + } |
|
| 239 | + if ($format == 'allhour') |
|
| 240 | + { |
|
| 241 | + return sprintf("%02d",($sWeek*$lengthOfWeek*24 + $sDay*24 + (int) floor($iSecond/3600))); |
|
| 242 | + } |
|
| 243 | + } |
|
| 244 | + else if ($format == 'hour') // only hour part |
|
| 245 | + { |
|
| 246 | + $sTime=dol_print_date($iSecond,'%H',true); |
|
| 247 | + } |
|
| 248 | + else if ($format == 'fullhour') |
|
| 249 | + { |
|
| 250 | + if (!empty($iSecond)) { |
|
| 251 | + $iSecond=$iSecond/3600; |
|
| 252 | + } |
|
| 253 | + else { |
|
| 254 | + $iSecond=0; |
|
| 255 | + } |
|
| 256 | + $sTime=$iSecond; |
|
| 257 | + } |
|
| 258 | + else if ($format == 'min') // only min part |
|
| 259 | + { |
|
| 260 | + $sTime=dol_print_date($iSecond,'%M',true); |
|
| 261 | + } |
|
| 262 | 262 | else if ($format == 'sec') // only sec part |
| 263 | 263 | { |
| 264 | 264 | $sTime=dol_print_date($iSecond,'%S',true); |
@@ -286,22 +286,22 @@ discard block |
||
| 286 | 286 | */ |
| 287 | 287 | function dolSqlDateFilter($datefield, $day_date, $month_date, $year_date) |
| 288 | 288 | { |
| 289 | - global $db; |
|
| 290 | - $sqldate=""; |
|
| 291 | - if ($month_date > 0) { |
|
| 292 | - if ($year_date > 0 && empty($day_date)) { |
|
| 293 | - $sqldate.= " AND ".$datefield." BETWEEN '".$db->idate(dol_get_first_day($year_date, $month_date, false)); |
|
| 294 | - $sqldate.= "' AND '".$db->idate(dol_get_last_day($year_date, $month_date, false))."'"; |
|
| 295 | - } else if ($year_date > 0 && ! empty($day_date)) { |
|
| 296 | - $sqldate.= " AND ".$datefield." BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month_date, $day_date, $year_date)); |
|
| 297 | - $sqldate.= "' AND '".$db->idate(dol_mktime(23, 59, 59, $month_date, $day_date, $year_date))."'"; |
|
| 298 | - } else |
|
| 299 | - $sqldate.= " AND date_format( ".$datefield.", '%m') = '".$db->escape($month_date)."'"; |
|
| 300 | - } else if ($year_date > 0){ |
|
| 301 | - $sqldate.= " AND ".$datefield." BETWEEN '".$db->idate(dol_get_first_day($year_date, 1, false)); |
|
| 302 | - $sqldate.= "' AND '".$db->idate(dol_get_last_day($year_date, 12, false))."'"; |
|
| 303 | - } |
|
| 304 | - return $sqldate; |
|
| 289 | + global $db; |
|
| 290 | + $sqldate=""; |
|
| 291 | + if ($month_date > 0) { |
|
| 292 | + if ($year_date > 0 && empty($day_date)) { |
|
| 293 | + $sqldate.= " AND ".$datefield." BETWEEN '".$db->idate(dol_get_first_day($year_date, $month_date, false)); |
|
| 294 | + $sqldate.= "' AND '".$db->idate(dol_get_last_day($year_date, $month_date, false))."'"; |
|
| 295 | + } else if ($year_date > 0 && ! empty($day_date)) { |
|
| 296 | + $sqldate.= " AND ".$datefield." BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month_date, $day_date, $year_date)); |
|
| 297 | + $sqldate.= "' AND '".$db->idate(dol_mktime(23, 59, 59, $month_date, $day_date, $year_date))."'"; |
|
| 298 | + } else |
|
| 299 | + $sqldate.= " AND date_format( ".$datefield.", '%m') = '".$db->escape($month_date)."'"; |
|
| 300 | + } else if ($year_date > 0){ |
|
| 301 | + $sqldate.= " AND ".$datefield." BETWEEN '".$db->idate(dol_get_first_day($year_date, 1, false)); |
|
| 302 | + $sqldate.= "' AND '".$db->idate(dol_get_last_day($year_date, 12, false))."'"; |
|
| 303 | + } |
|
| 304 | + return $sqldate; |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | /** |
@@ -341,9 +341,9 @@ discard block |
||
| 341 | 341 | $string=sprintf("%04d%02d%02d%02d%02d%02d",$syear,$smonth,$sday,$shour,$smin,$ssec); |
| 342 | 342 | } |
| 343 | 343 | else if ( |
| 344 | - preg_match('/^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})Z$/i',$string,$reg) // Convert date with format YYYY-MM-DDTHH:MM:SSZ (RFC3339) |
|
| 345 | - || preg_match('/^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})$/i',$string,$reg) // Convert date with format YYYY-MM-DD HH:MM:SS |
|
| 346 | - || preg_match('/^([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2})([0-9]{2})([0-9]{2})Z$/i',$string,$reg) // Convert date with format YYYYMMDDTHHMMSSZ |
|
| 344 | + preg_match('/^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})Z$/i',$string,$reg) // Convert date with format YYYY-MM-DDTHH:MM:SSZ (RFC3339) |
|
| 345 | + || preg_match('/^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})$/i',$string,$reg) // Convert date with format YYYY-MM-DD HH:MM:SS |
|
| 346 | + || preg_match('/^([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2})([0-9]{2})([0-9]{2})Z$/i',$string,$reg) // Convert date with format YYYYMMDDTHHMMSSZ |
|
| 347 | 347 | ) |
| 348 | 348 | { |
| 349 | 349 | $syear = $reg[1]; |
@@ -371,10 +371,10 @@ discard block |
||
| 371 | 371 | */ |
| 372 | 372 | function dol_get_prev_day($day, $month, $year) |
| 373 | 373 | { |
| 374 | - $time=dol_mktime(12,0,0,$month,$day,$year,1,0); |
|
| 375 | - $time-=24*60*60; |
|
| 376 | - $tmparray=dol_getdate($time,true); |
|
| 377 | - return array('year' => $tmparray['year'], 'month' => $tmparray['mon'], 'day' => $tmparray['mday']); |
|
| 374 | + $time=dol_mktime(12,0,0,$month,$day,$year,1,0); |
|
| 375 | + $time-=24*60*60; |
|
| 376 | + $tmparray=dol_getdate($time,true); |
|
| 377 | + return array('year' => $tmparray['year'], 'month' => $tmparray['mon'], 'day' => $tmparray['mday']); |
|
| 378 | 378 | } |
| 379 | 379 | |
| 380 | 380 | /** Return next day |
@@ -386,10 +386,10 @@ discard block |
||
| 386 | 386 | */ |
| 387 | 387 | function dol_get_next_day($day, $month, $year) |
| 388 | 388 | { |
| 389 | - $time=dol_mktime(12,0,0,$month,$day,$year,1,0); |
|
| 390 | - $time+=24*60*60; |
|
| 391 | - $tmparray=dol_getdate($time,true); |
|
| 392 | - return array('year' => $tmparray['year'], 'month' => $tmparray['mon'], 'day' => $tmparray['mday']); |
|
| 389 | + $time=dol_mktime(12,0,0,$month,$day,$year,1,0); |
|
| 390 | + $time+=24*60*60; |
|
| 391 | + $tmparray=dol_getdate($time,true); |
|
| 392 | + return array('year' => $tmparray['year'], 'month' => $tmparray['mon'], 'day' => $tmparray['mday']); |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | /** Return previous month |
@@ -400,17 +400,17 @@ discard block |
||
| 400 | 400 | */ |
| 401 | 401 | function dol_get_prev_month($month, $year) |
| 402 | 402 | { |
| 403 | - if ($month == 1) |
|
| 404 | - { |
|
| 405 | - $prev_month = 12; |
|
| 406 | - $prev_year = $year - 1; |
|
| 407 | - } |
|
| 408 | - else |
|
| 409 | - { |
|
| 410 | - $prev_month = $month-1; |
|
| 411 | - $prev_year = $year; |
|
| 412 | - } |
|
| 413 | - return array('year' => $prev_year, 'month' => $prev_month); |
|
| 403 | + if ($month == 1) |
|
| 404 | + { |
|
| 405 | + $prev_month = 12; |
|
| 406 | + $prev_year = $year - 1; |
|
| 407 | + } |
|
| 408 | + else |
|
| 409 | + { |
|
| 410 | + $prev_month = $month-1; |
|
| 411 | + $prev_year = $year; |
|
| 412 | + } |
|
| 413 | + return array('year' => $prev_year, 'month' => $prev_month); |
|
| 414 | 414 | } |
| 415 | 415 | |
| 416 | 416 | /** Return next month |
@@ -421,17 +421,17 @@ discard block |
||
| 421 | 421 | */ |
| 422 | 422 | function dol_get_next_month($month, $year) |
| 423 | 423 | { |
| 424 | - if ($month == 12) |
|
| 425 | - { |
|
| 426 | - $next_month = 1; |
|
| 427 | - $next_year = $year + 1; |
|
| 428 | - } |
|
| 429 | - else |
|
| 430 | - { |
|
| 431 | - $next_month = $month + 1; |
|
| 432 | - $next_year = $year; |
|
| 433 | - } |
|
| 434 | - return array('year' => $next_year, 'month' => $next_month); |
|
| 424 | + if ($month == 12) |
|
| 425 | + { |
|
| 426 | + $next_month = 1; |
|
| 427 | + $next_year = $year + 1; |
|
| 428 | + } |
|
| 429 | + else |
|
| 430 | + { |
|
| 431 | + $next_month = $month + 1; |
|
| 432 | + $next_year = $year; |
|
| 433 | + } |
|
| 434 | + return array('year' => $next_year, 'month' => $next_month); |
|
| 435 | 435 | } |
| 436 | 436 | |
| 437 | 437 | /** Return previous week |
@@ -444,12 +444,12 @@ discard block |
||
| 444 | 444 | */ |
| 445 | 445 | function dol_get_prev_week($day, $week, $month, $year) |
| 446 | 446 | { |
| 447 | - $tmparray = dol_get_first_day_week($day, $month, $year); |
|
| 447 | + $tmparray = dol_get_first_day_week($day, $month, $year); |
|
| 448 | 448 | |
| 449 | - $time=dol_mktime(12,0,0,$month,$tmparray['first_day'],$year,1,0); |
|
| 450 | - $time-=24*60*60*7; |
|
| 451 | - $tmparray=dol_getdate($time,true); |
|
| 452 | - return array('year' => $tmparray['year'], 'month' => $tmparray['mon'], 'day' => $tmparray['mday']); |
|
| 449 | + $time=dol_mktime(12,0,0,$month,$tmparray['first_day'],$year,1,0); |
|
| 450 | + $time-=24*60*60*7; |
|
| 451 | + $tmparray=dol_getdate($time,true); |
|
| 452 | + return array('year' => $tmparray['year'], 'month' => $tmparray['mon'], 'day' => $tmparray['mday']); |
|
| 453 | 453 | } |
| 454 | 454 | |
| 455 | 455 | /** Return next week |
@@ -462,13 +462,13 @@ discard block |
||
| 462 | 462 | */ |
| 463 | 463 | function dol_get_next_week($day, $week, $month, $year) |
| 464 | 464 | { |
| 465 | - $tmparray = dol_get_first_day_week($day, $month, $year); |
|
| 465 | + $tmparray = dol_get_first_day_week($day, $month, $year); |
|
| 466 | 466 | |
| 467 | - $time=dol_mktime(12,0,0,$tmparray['first_month'],$tmparray['first_day'],$tmparray['first_year'],1,0); |
|
| 468 | - $time+=24*60*60*7; |
|
| 469 | - $tmparray=dol_getdate($time,true); |
|
| 467 | + $time=dol_mktime(12,0,0,$tmparray['first_month'],$tmparray['first_day'],$tmparray['first_year'],1,0); |
|
| 468 | + $time+=24*60*60*7; |
|
| 469 | + $tmparray=dol_getdate($time,true); |
|
| 470 | 470 | |
| 471 | - return array('year' => $tmparray['year'], 'month' => $tmparray['mon'], 'day' => $tmparray['mday']); |
|
| 471 | + return array('year' => $tmparray['year'], 'month' => $tmparray['mon'], 'day' => $tmparray['mday']); |
|
| 472 | 472 | } |
| 473 | 473 | |
| 474 | 474 | /** Return GMT time for first day of a month or year |
@@ -482,8 +482,8 @@ discard block |
||
| 482 | 482 | */ |
| 483 | 483 | function dol_get_first_day($year,$month=1,$gm=false) |
| 484 | 484 | { |
| 485 | - if ($year > 9999) return ''; |
|
| 486 | - return dol_mktime(0,0,0,$month,1,$year,$gm); |
|
| 485 | + if ($year > 9999) return ''; |
|
| 486 | + return dol_mktime(0,0,0,$month,1,$year,$gm); |
|
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | |
@@ -496,22 +496,22 @@ discard block |
||
| 496 | 496 | */ |
| 497 | 497 | function dol_get_last_day($year,$month=12,$gm=false) |
| 498 | 498 | { |
| 499 | - if ($year > 9999) return ''; |
|
| 500 | - if ($month == 12) |
|
| 501 | - { |
|
| 502 | - $month = 1; |
|
| 503 | - $year += 1; |
|
| 504 | - } |
|
| 505 | - else |
|
| 506 | - { |
|
| 507 | - $month += 1; |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - // On se deplace au debut du mois suivant, et on retire un jour |
|
| 511 | - $datelim=dol_mktime(23,59,59,$month,1,$year,$gm); |
|
| 512 | - $datelim -= (3600 * 24); |
|
| 513 | - |
|
| 514 | - return $datelim; |
|
| 499 | + if ($year > 9999) return ''; |
|
| 500 | + if ($month == 12) |
|
| 501 | + { |
|
| 502 | + $month = 1; |
|
| 503 | + $year += 1; |
|
| 504 | + } |
|
| 505 | + else |
|
| 506 | + { |
|
| 507 | + $month += 1; |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + // On se deplace au debut du mois suivant, et on retire un jour |
|
| 511 | + $datelim=dol_mktime(23,59,59,$month,1,$year,$gm); |
|
| 512 | + $datelim -= (3600 * 24); |
|
| 513 | + |
|
| 514 | + return $datelim; |
|
| 515 | 515 | } |
| 516 | 516 | |
| 517 | 517 | /** Return first day of week for a date. First day of week may be monday if option MAIN_START_WEEK is 1. |
@@ -524,69 +524,69 @@ discard block |
||
| 524 | 524 | */ |
| 525 | 525 | function dol_get_first_day_week($day,$month,$year,$gm=false) |
| 526 | 526 | { |
| 527 | - global $conf; |
|
| 527 | + global $conf; |
|
| 528 | 528 | |
| 529 | - //$day=2; $month=2; $year=2015; |
|
| 530 | - $date = dol_mktime(0,0,0,$month,$day,$year,$gm); |
|
| 529 | + //$day=2; $month=2; $year=2015; |
|
| 530 | + $date = dol_mktime(0,0,0,$month,$day,$year,$gm); |
|
| 531 | 531 | |
| 532 | - //Checking conf of start week |
|
| 533 | - $start_week = (isset($conf->global->MAIN_START_WEEK)?$conf->global->MAIN_START_WEEK:1); |
|
| 532 | + //Checking conf of start week |
|
| 533 | + $start_week = (isset($conf->global->MAIN_START_WEEK)?$conf->global->MAIN_START_WEEK:1); |
|
| 534 | 534 | |
| 535 | - $tmparray = dol_getdate($date,true); // detail of current day |
|
| 535 | + $tmparray = dol_getdate($date,true); // detail of current day |
|
| 536 | 536 | |
| 537 | - //Calculate days = offset from current day |
|
| 538 | - $days = $start_week - $tmparray['wday']; |
|
| 539 | - if ($days>=1) $days=7-$days; |
|
| 540 | - $days = abs($days); |
|
| 537 | + //Calculate days = offset from current day |
|
| 538 | + $days = $start_week - $tmparray['wday']; |
|
| 539 | + if ($days>=1) $days=7-$days; |
|
| 540 | + $days = abs($days); |
|
| 541 | 541 | $seconds = $days*24*60*60; |
| 542 | - //print 'start_week='.$start_week.' tmparray[wday]='.$tmparray['wday'].' day offset='.$days.' seconds offset='.$seconds.'<br>'; |
|
| 542 | + //print 'start_week='.$start_week.' tmparray[wday]='.$tmparray['wday'].' day offset='.$days.' seconds offset='.$seconds.'<br>'; |
|
| 543 | 543 | |
| 544 | 544 | //Get first day of week |
| 545 | 545 | $tmpdaytms = date($tmparray[0])-$seconds; // $tmparray[0] is day of parameters |
| 546 | - $tmpday = date("d",$tmpdaytms); |
|
| 546 | + $tmpday = date("d",$tmpdaytms); |
|
| 547 | 547 | |
| 548 | - //Check first day of week is in same month than current day or not |
|
| 549 | - if ($tmpday>$day) |
|
| 548 | + //Check first day of week is in same month than current day or not |
|
| 549 | + if ($tmpday>$day) |
|
| 550 | 550 | { |
| 551 | - $prev_month = $month-1; |
|
| 552 | - $prev_year = $year; |
|
| 553 | - |
|
| 554 | - if ($prev_month==0) |
|
| 555 | - { |
|
| 556 | - $prev_month = 12; |
|
| 557 | - $prev_year = $year-1; |
|
| 558 | - } |
|
| 551 | + $prev_month = $month-1; |
|
| 552 | + $prev_year = $year; |
|
| 553 | + |
|
| 554 | + if ($prev_month==0) |
|
| 555 | + { |
|
| 556 | + $prev_month = 12; |
|
| 557 | + $prev_year = $year-1; |
|
| 558 | + } |
|
| 559 | 559 | } |
| 560 | 560 | else |
| 561 | 561 | { |
| 562 | - $prev_month = $month; |
|
| 563 | - $prev_year = $year; |
|
| 562 | + $prev_month = $month; |
|
| 563 | + $prev_year = $year; |
|
| 564 | 564 | } |
| 565 | - $tmpmonth = $prev_month; |
|
| 566 | - $tmpyear = $prev_year; |
|
| 565 | + $tmpmonth = $prev_month; |
|
| 566 | + $tmpyear = $prev_year; |
|
| 567 | 567 | |
| 568 | - //Get first day of next week |
|
| 569 | - $tmptime=dol_mktime(12,0,0,$month,$tmpday,$year,1,0); |
|
| 570 | - $tmptime-=24*60*60*7; |
|
| 571 | - $tmparray=dol_getdate($tmptime,true); |
|
| 568 | + //Get first day of next week |
|
| 569 | + $tmptime=dol_mktime(12,0,0,$month,$tmpday,$year,1,0); |
|
| 570 | + $tmptime-=24*60*60*7; |
|
| 571 | + $tmparray=dol_getdate($tmptime,true); |
|
| 572 | 572 | $prev_day = $tmparray['mday']; |
| 573 | 573 | |
| 574 | 574 | //Check prev day of week is in same month than first day or not |
| 575 | - if ($prev_day > $tmpday) |
|
| 575 | + if ($prev_day > $tmpday) |
|
| 576 | 576 | { |
| 577 | - $prev_month = $month-1; |
|
| 578 | - $prev_year = $year; |
|
| 579 | - |
|
| 580 | - if ($prev_month==0) |
|
| 581 | - { |
|
| 582 | - $prev_month = 12; |
|
| 583 | - $prev_year = $year-1; |
|
| 584 | - } |
|
| 577 | + $prev_month = $month-1; |
|
| 578 | + $prev_year = $year; |
|
| 579 | + |
|
| 580 | + if ($prev_month==0) |
|
| 581 | + { |
|
| 582 | + $prev_month = 12; |
|
| 583 | + $prev_year = $year-1; |
|
| 584 | + } |
|
| 585 | 585 | } |
| 586 | 586 | |
| 587 | 587 | $week = date("W",dol_mktime(0,0,0,$tmpmonth,$tmpday,$tmpyear,$gm)); |
| 588 | 588 | |
| 589 | - return array('year' => $year, 'month' => $month, 'week' => $week, 'first_day' => $tmpday, 'first_month' => $tmpmonth, 'first_year' => $tmpyear, 'prev_year' => $prev_year, 'prev_month' => $prev_month, 'prev_day' => $prev_day); |
|
| 589 | + return array('year' => $year, 'month' => $month, 'week' => $week, 'first_day' => $tmpday, 'first_month' => $tmpmonth, 'first_year' => $tmpyear, 'prev_year' => $prev_year, 'prev_month' => $prev_month, 'prev_day' => $prev_day); |
|
| 590 | 590 | } |
| 591 | 591 | |
| 592 | 592 | /** |
@@ -602,66 +602,66 @@ discard block |
||
| 602 | 602 | */ |
| 603 | 603 | function num_public_holiday($timestampStart, $timestampEnd, $countrycode='FR', $lastday=0) |
| 604 | 604 | { |
| 605 | - global $conf; |
|
| 606 | - |
|
| 607 | - $nbFerie = 0; |
|
| 608 | - |
|
| 609 | - // Check to ensure we use correct parameters |
|
| 610 | - if ((($timestampEnd - $timestampStart) % 86400) != 0) return 'ErrorDates must use same hours and must be GMT dates'; |
|
| 611 | - |
|
| 612 | - $i=0; |
|
| 613 | - while (( ($lastday == 0 && $timestampStart < $timestampEnd) || ($lastday && $timestampStart <= $timestampEnd) ) |
|
| 614 | - && ($i < 50000)) // Loop end when equals (Test on i is a security loop to avoid infinite loop) |
|
| 615 | - { |
|
| 616 | - $ferie=false; |
|
| 617 | - $countryfound=0; |
|
| 618 | - $includesaturdayandsunday=1; |
|
| 619 | - |
|
| 620 | - $jour = date("d", $timestampStart); |
|
| 621 | - $mois = date("m", $timestampStart); |
|
| 622 | - $annee = date("Y", $timestampStart); |
|
| 623 | - |
|
| 624 | - |
|
| 625 | - // Check into var $conf->global->HOLIDAY_MORE_DAYS MM-DD,YYYY-MM-DD, ... |
|
| 626 | - if (! empty($conf->global->HOLIDAY_MORE_PUBLIC_HOLIDAYS)) |
|
| 627 | - { |
|
| 628 | - $arrayofdaystring=explode(',',$conf->global->HOLIDAY_MORE_PUBLIC_HOLIDAYS); |
|
| 629 | - foreach($arrayofdaystring as $daystring) |
|
| 630 | - { |
|
| 631 | - $tmp=explode('-',$daystring); |
|
| 632 | - if ($tmp[2]) |
|
| 633 | - { |
|
| 634 | - if ($tmp[0] == $annee && $tmp[1] == $mois && $tmp[2] == $jour) $ferie=true; |
|
| 635 | - } |
|
| 636 | - else |
|
| 637 | - { |
|
| 638 | - if ($tmp[0] == $mois && $tmp[1] == $jour) $ferie=true; |
|
| 639 | - } |
|
| 640 | - } |
|
| 641 | - } |
|
| 642 | - |
|
| 643 | - if ($countrycode == 'FR') |
|
| 644 | - { |
|
| 645 | - $countryfound=1; |
|
| 646 | - |
|
| 647 | - // Definition of fixed working days |
|
| 648 | - if($jour == 1 && $mois == 1) $ferie=true; // 1er january |
|
| 649 | - if($jour == 1 && $mois == 5) $ferie=true; // 1er may |
|
| 650 | - if($jour == 8 && $mois == 5) $ferie=true; // 5 may |
|
| 651 | - if($jour == 14 && $mois == 7) $ferie=true; // 14 july |
|
| 652 | - if($jour == 15 && $mois == 8) $ferie=true; // 15 august |
|
| 653 | - if($jour == 1 && $mois == 11) $ferie=true; // 1 november |
|
| 654 | - if($jour == 11 && $mois == 11) $ferie=true; // 11 november |
|
| 655 | - if($jour == 25 && $mois == 12) $ferie=true; // 25 december |
|
| 656 | - |
|
| 657 | - // Calculation for easter date |
|
| 658 | - $date_paques = easter_date($annee); |
|
| 659 | - $jour_paques = date("d", $date_paques); |
|
| 660 | - $mois_paques = date("m", $date_paques); |
|
| 661 | - if($jour_paques == $jour && $mois_paques == $mois) $ferie=true; |
|
| 662 | - // Pâques |
|
| 663 | - |
|
| 664 | - // Calculation for the monday of easter date |
|
| 605 | + global $conf; |
|
| 606 | + |
|
| 607 | + $nbFerie = 0; |
|
| 608 | + |
|
| 609 | + // Check to ensure we use correct parameters |
|
| 610 | + if ((($timestampEnd - $timestampStart) % 86400) != 0) return 'ErrorDates must use same hours and must be GMT dates'; |
|
| 611 | + |
|
| 612 | + $i=0; |
|
| 613 | + while (( ($lastday == 0 && $timestampStart < $timestampEnd) || ($lastday && $timestampStart <= $timestampEnd) ) |
|
| 614 | + && ($i < 50000)) // Loop end when equals (Test on i is a security loop to avoid infinite loop) |
|
| 615 | + { |
|
| 616 | + $ferie=false; |
|
| 617 | + $countryfound=0; |
|
| 618 | + $includesaturdayandsunday=1; |
|
| 619 | + |
|
| 620 | + $jour = date("d", $timestampStart); |
|
| 621 | + $mois = date("m", $timestampStart); |
|
| 622 | + $annee = date("Y", $timestampStart); |
|
| 623 | + |
|
| 624 | + |
|
| 625 | + // Check into var $conf->global->HOLIDAY_MORE_DAYS MM-DD,YYYY-MM-DD, ... |
|
| 626 | + if (! empty($conf->global->HOLIDAY_MORE_PUBLIC_HOLIDAYS)) |
|
| 627 | + { |
|
| 628 | + $arrayofdaystring=explode(',',$conf->global->HOLIDAY_MORE_PUBLIC_HOLIDAYS); |
|
| 629 | + foreach($arrayofdaystring as $daystring) |
|
| 630 | + { |
|
| 631 | + $tmp=explode('-',$daystring); |
|
| 632 | + if ($tmp[2]) |
|
| 633 | + { |
|
| 634 | + if ($tmp[0] == $annee && $tmp[1] == $mois && $tmp[2] == $jour) $ferie=true; |
|
| 635 | + } |
|
| 636 | + else |
|
| 637 | + { |
|
| 638 | + if ($tmp[0] == $mois && $tmp[1] == $jour) $ferie=true; |
|
| 639 | + } |
|
| 640 | + } |
|
| 641 | + } |
|
| 642 | + |
|
| 643 | + if ($countrycode == 'FR') |
|
| 644 | + { |
|
| 645 | + $countryfound=1; |
|
| 646 | + |
|
| 647 | + // Definition of fixed working days |
|
| 648 | + if($jour == 1 && $mois == 1) $ferie=true; // 1er january |
|
| 649 | + if($jour == 1 && $mois == 5) $ferie=true; // 1er may |
|
| 650 | + if($jour == 8 && $mois == 5) $ferie=true; // 5 may |
|
| 651 | + if($jour == 14 && $mois == 7) $ferie=true; // 14 july |
|
| 652 | + if($jour == 15 && $mois == 8) $ferie=true; // 15 august |
|
| 653 | + if($jour == 1 && $mois == 11) $ferie=true; // 1 november |
|
| 654 | + if($jour == 11 && $mois == 11) $ferie=true; // 11 november |
|
| 655 | + if($jour == 25 && $mois == 12) $ferie=true; // 25 december |
|
| 656 | + |
|
| 657 | + // Calculation for easter date |
|
| 658 | + $date_paques = easter_date($annee); |
|
| 659 | + $jour_paques = date("d", $date_paques); |
|
| 660 | + $mois_paques = date("m", $date_paques); |
|
| 661 | + if($jour_paques == $jour && $mois_paques == $mois) $ferie=true; |
|
| 662 | + // Pâques |
|
| 663 | + |
|
| 664 | + // Calculation for the monday of easter date |
|
| 665 | 665 | $date_lundi_paques = mktime( |
| 666 | 666 | date("H", $date_paques), |
| 667 | 667 | date("i", $date_paques), |
@@ -670,12 +670,12 @@ discard block |
||
| 670 | 670 | date("d", $date_paques) + 1, |
| 671 | 671 | date("Y", $date_paques) |
| 672 | 672 | ); |
| 673 | - $jour_lundi_ascension = date("d", $date_lundi_paques); |
|
| 674 | - $mois_lundi_ascension = date("m", $date_lundi_paques); |
|
| 675 | - if($jour_lundi_ascension == $jour && $mois_lundi_ascension == $mois) $ferie=true; |
|
| 676 | - // Lundi de Pâques |
|
| 673 | + $jour_lundi_ascension = date("d", $date_lundi_paques); |
|
| 674 | + $mois_lundi_ascension = date("m", $date_lundi_paques); |
|
| 675 | + if($jour_lundi_ascension == $jour && $mois_lundi_ascension == $mois) $ferie=true; |
|
| 676 | + // Lundi de Pâques |
|
| 677 | 677 | |
| 678 | - // Calcul du jour de l'ascension (38 days after easter day) |
|
| 678 | + // Calcul du jour de l'ascension (38 days after easter day) |
|
| 679 | 679 | $date_ascension = mktime( |
| 680 | 680 | date("H", $date_paques), |
| 681 | 681 | date("i", $date_paques), |
@@ -684,12 +684,12 @@ discard block |
||
| 684 | 684 | date("d", $date_paques) + 39, |
| 685 | 685 | date("Y", $date_paques) |
| 686 | 686 | ); |
| 687 | - $jour_ascension = date("d", $date_ascension); |
|
| 688 | - $mois_ascension = date("m", $date_ascension); |
|
| 689 | - if($jour_ascension == $jour && $mois_ascension == $mois) $ferie=true; |
|
| 690 | - // Ascension |
|
| 687 | + $jour_ascension = date("d", $date_ascension); |
|
| 688 | + $mois_ascension = date("m", $date_ascension); |
|
| 689 | + if($jour_ascension == $jour && $mois_ascension == $mois) $ferie=true; |
|
| 690 | + // Ascension |
|
| 691 | 691 | |
| 692 | - // Calculation of "Pentecote" (11 days after easter day) |
|
| 692 | + // Calculation of "Pentecote" (11 days after easter day) |
|
| 693 | 693 | $date_pentecote = mktime( |
| 694 | 694 | date("H", $date_paques), |
| 695 | 695 | date("i", $date_paques), |
@@ -698,73 +698,73 @@ discard block |
||
| 698 | 698 | date("d", $date_paques) + 49, |
| 699 | 699 | date("Y", $date_paques) |
| 700 | 700 | ); |
| 701 | - $jour_pentecote = date("d", $date_pentecote); |
|
| 702 | - $mois_pentecote = date("m", $date_pentecote); |
|
| 703 | - if($jour_pentecote == $jour && $mois_pentecote == $mois) $ferie=true; |
|
| 704 | - // "Pentecote" |
|
| 705 | - } |
|
| 706 | - |
|
| 707 | - // Pentecoste and Ascensione in Italy go to the sunday after: isn't holiday. |
|
| 708 | - // Pentecoste is 50 days after Easter, Ascensione 40 |
|
| 709 | - if ($countrycode == 'IT') |
|
| 710 | - { |
|
| 711 | - $countryfound=1; |
|
| 712 | - |
|
| 713 | - // Definition des dates feriees fixes |
|
| 714 | - if($jour == 1 && $mois == 1) $ferie=true; // Capodanno |
|
| 715 | - if($jour == 6 && $mois == 1) $ferie=true; // Epifania |
|
| 716 | - if($jour == 25 && $mois == 4) $ferie=true; // Anniversario Liberazione |
|
| 717 | - if($jour == 1 && $mois == 5) $ferie=true; // Festa del Lavoro |
|
| 718 | - if($jour == 2 && $mois == 6) $ferie=true; // Festa della Repubblica |
|
| 719 | - if($jour == 15 && $mois == 8) $ferie=true; // Ferragosto |
|
| 720 | - if($jour == 1 && $mois == 11) $ferie=true; // Tutti i Santi |
|
| 721 | - if($jour == 8 && $mois == 12) $ferie=true; // Immacolata Concezione |
|
| 722 | - if($jour == 25 && $mois == 12) $ferie=true; // 25 decembre |
|
| 723 | - if($jour == 26 && $mois == 12) $ferie=true; // Santo Stefano |
|
| 724 | - |
|
| 725 | - // Calcul du jour de paques |
|
| 726 | - $date_paques = easter_date($annee); |
|
| 727 | - $jour_paques = date("d", $date_paques); |
|
| 728 | - $mois_paques = date("m", $date_paques); |
|
| 729 | - if($jour_paques == $jour && $mois_paques == $mois) $ferie=true; |
|
| 730 | - // Paques |
|
| 731 | - } |
|
| 732 | - |
|
| 733 | - if ($countrycode == 'IN') |
|
| 734 | - { |
|
| 735 | - $countryfound=1; |
|
| 736 | - |
|
| 737 | - if($jour == 1 && $mois == 1) $ferie=true; // New Year's Day |
|
| 738 | - if($jour == 26 && $mois == 1) $ferie=true; // Republic Day |
|
| 739 | - if($jour == 1 && $mois == 5) $ferie=true; // May Day |
|
| 740 | - if($jour == 15 && $mois == 8) $ferie=true; // Independence Day |
|
| 741 | - if($jour == 2 && $mois == 10) $ferie=true; // Gandhi Jayanti |
|
| 742 | - if($jour == 25 && $mois == 12) $ferie=true; // Christmas |
|
| 743 | - } |
|
| 744 | - |
|
| 745 | - if ($countrycode == 'ES') |
|
| 746 | - { |
|
| 747 | - $countryfound=1; |
|
| 748 | - |
|
| 749 | - // Definition des dates feriees fixes |
|
| 750 | - if($jour == 1 && $mois == 1) $ferie=true; // Año nuevo |
|
| 751 | - if($jour == 6 && $mois == 1) $ferie=true; // Día Reyes |
|
| 752 | - if($jour == 1 && $mois == 5) $ferie=true; // 1 Mayo |
|
| 753 | - if($jour == 15 && $mois == 8) $ferie=true; // 15 Agosto |
|
| 754 | - if($jour == 12 && $mois == 10) $ferie=true; // Día Hispanidad |
|
| 755 | - if($jour == 1 && $mois == 11) $ferie=true; // 1 noviembre |
|
| 756 | - if($jour == 6 && $mois == 12) $ferie=true; // Constitución |
|
| 757 | - if($jour == 8 && $mois == 12) $ferie=true; // Inmaculada |
|
| 758 | - if($jour == 25 && $mois == 12) $ferie=true; // 25 diciembre |
|
| 759 | - |
|
| 760 | - // Calcul día de Pascua |
|
| 761 | - $date_paques = easter_date($annee); |
|
| 762 | - $jour_paques = date("d", $date_paques); |
|
| 763 | - $mois_paques = date("m", $date_paques); |
|
| 764 | - if($jour_paques == $jour && $mois_paques == $mois) $ferie=true; |
|
| 765 | - // Paques |
|
| 766 | - |
|
| 767 | - // Viernes Santo |
|
| 701 | + $jour_pentecote = date("d", $date_pentecote); |
|
| 702 | + $mois_pentecote = date("m", $date_pentecote); |
|
| 703 | + if($jour_pentecote == $jour && $mois_pentecote == $mois) $ferie=true; |
|
| 704 | + // "Pentecote" |
|
| 705 | + } |
|
| 706 | + |
|
| 707 | + // Pentecoste and Ascensione in Italy go to the sunday after: isn't holiday. |
|
| 708 | + // Pentecoste is 50 days after Easter, Ascensione 40 |
|
| 709 | + if ($countrycode == 'IT') |
|
| 710 | + { |
|
| 711 | + $countryfound=1; |
|
| 712 | + |
|
| 713 | + // Definition des dates feriees fixes |
|
| 714 | + if($jour == 1 && $mois == 1) $ferie=true; // Capodanno |
|
| 715 | + if($jour == 6 && $mois == 1) $ferie=true; // Epifania |
|
| 716 | + if($jour == 25 && $mois == 4) $ferie=true; // Anniversario Liberazione |
|
| 717 | + if($jour == 1 && $mois == 5) $ferie=true; // Festa del Lavoro |
|
| 718 | + if($jour == 2 && $mois == 6) $ferie=true; // Festa della Repubblica |
|
| 719 | + if($jour == 15 && $mois == 8) $ferie=true; // Ferragosto |
|
| 720 | + if($jour == 1 && $mois == 11) $ferie=true; // Tutti i Santi |
|
| 721 | + if($jour == 8 && $mois == 12) $ferie=true; // Immacolata Concezione |
|
| 722 | + if($jour == 25 && $mois == 12) $ferie=true; // 25 decembre |
|
| 723 | + if($jour == 26 && $mois == 12) $ferie=true; // Santo Stefano |
|
| 724 | + |
|
| 725 | + // Calcul du jour de paques |
|
| 726 | + $date_paques = easter_date($annee); |
|
| 727 | + $jour_paques = date("d", $date_paques); |
|
| 728 | + $mois_paques = date("m", $date_paques); |
|
| 729 | + if($jour_paques == $jour && $mois_paques == $mois) $ferie=true; |
|
| 730 | + // Paques |
|
| 731 | + } |
|
| 732 | + |
|
| 733 | + if ($countrycode == 'IN') |
|
| 734 | + { |
|
| 735 | + $countryfound=1; |
|
| 736 | + |
|
| 737 | + if($jour == 1 && $mois == 1) $ferie=true; // New Year's Day |
|
| 738 | + if($jour == 26 && $mois == 1) $ferie=true; // Republic Day |
|
| 739 | + if($jour == 1 && $mois == 5) $ferie=true; // May Day |
|
| 740 | + if($jour == 15 && $mois == 8) $ferie=true; // Independence Day |
|
| 741 | + if($jour == 2 && $mois == 10) $ferie=true; // Gandhi Jayanti |
|
| 742 | + if($jour == 25 && $mois == 12) $ferie=true; // Christmas |
|
| 743 | + } |
|
| 744 | + |
|
| 745 | + if ($countrycode == 'ES') |
|
| 746 | + { |
|
| 747 | + $countryfound=1; |
|
| 748 | + |
|
| 749 | + // Definition des dates feriees fixes |
|
| 750 | + if($jour == 1 && $mois == 1) $ferie=true; // Año nuevo |
|
| 751 | + if($jour == 6 && $mois == 1) $ferie=true; // Día Reyes |
|
| 752 | + if($jour == 1 && $mois == 5) $ferie=true; // 1 Mayo |
|
| 753 | + if($jour == 15 && $mois == 8) $ferie=true; // 15 Agosto |
|
| 754 | + if($jour == 12 && $mois == 10) $ferie=true; // Día Hispanidad |
|
| 755 | + if($jour == 1 && $mois == 11) $ferie=true; // 1 noviembre |
|
| 756 | + if($jour == 6 && $mois == 12) $ferie=true; // Constitución |
|
| 757 | + if($jour == 8 && $mois == 12) $ferie=true; // Inmaculada |
|
| 758 | + if($jour == 25 && $mois == 12) $ferie=true; // 25 diciembre |
|
| 759 | + |
|
| 760 | + // Calcul día de Pascua |
|
| 761 | + $date_paques = easter_date($annee); |
|
| 762 | + $jour_paques = date("d", $date_paques); |
|
| 763 | + $mois_paques = date("m", $date_paques); |
|
| 764 | + if($jour_paques == $jour && $mois_paques == $mois) $ferie=true; |
|
| 765 | + // Paques |
|
| 766 | + |
|
| 767 | + // Viernes Santo |
|
| 768 | 768 | $date_viernes = mktime( |
| 769 | 769 | date("H", $date_paques), |
| 770 | 770 | date("i", $date_paques), |
@@ -773,113 +773,113 @@ discard block |
||
| 773 | 773 | date("d", $date_paques) -2, |
| 774 | 774 | date("Y", $date_paques) |
| 775 | 775 | ); |
| 776 | - $jour_viernes = date("d", $date_viernes); |
|
| 777 | - $mois_viernes = date("m", $date_viernes); |
|
| 778 | - if($jour_viernes == $jour && $mois_viernes == $mois) $ferie=true; |
|
| 779 | - //Viernes Santo |
|
| 780 | - } |
|
| 781 | - |
|
| 782 | - if ($countrycode == 'AT') |
|
| 783 | - { |
|
| 784 | - $countryfound=1; |
|
| 785 | - |
|
| 786 | - // Definition des dates feriees fixes |
|
| 787 | - if($jour == 1 && $mois == 1) $ferie=true; // Neujahr |
|
| 788 | - if($jour == 6 && $mois == 1) $ferie=true; // Hl. 3 Koenige |
|
| 789 | - if($jour == 1 && $mois == 5) $ferie=true; // 1. Mai |
|
| 790 | - if($jour == 15 && $mois == 8) $ferie=true; // Mariae Himmelfahrt |
|
| 791 | - if($jour == 26 && $mois == 10) $ferie=true; // 26. Oktober |
|
| 792 | - if($jour == 1 && $mois == 11) $ferie=true; // Allerheiligen |
|
| 793 | - if($jour == 8 && $mois == 12) $ferie=true; // Mariae Empfaengnis |
|
| 794 | - if($jour == 24 && $mois == 12) $ferie=true; // Heilig abend |
|
| 795 | - if($jour == 25 && $mois == 12) $ferie=true; // Christtag |
|
| 796 | - if($jour == 26 && $mois == 12) $ferie=true; // Stefanietag |
|
| 797 | - if($jour == 31 && $mois == 12) $ferie=true; // Silvester |
|
| 798 | - |
|
| 799 | - // Easter calculation |
|
| 800 | - $date_paques = easter_date($annee); |
|
| 801 | - $jour_paques = date("d", $date_paques); |
|
| 802 | - $mois_paques = date("m", $date_paques); |
|
| 803 | - if($jour_paques == $jour && $mois_paques == $mois) $ferie=true; |
|
| 804 | - // Easter sunday |
|
| 805 | - |
|
| 806 | - // Monday after easter |
|
| 807 | - $date_eastermonday = mktime( |
|
| 808 | - date("H", $date_paques), |
|
| 809 | - date("i", $date_paques), |
|
| 810 | - date("s", $date_paques), |
|
| 811 | - date("m", $date_paques), |
|
| 812 | - date("d", $date_paques) + 1, |
|
| 813 | - date("Y", $date_paques) |
|
| 814 | - ); |
|
| 815 | - $jour_eastermonday = date("d", $date_eastermonday); |
|
| 816 | - $mois_eastermonday = date("m", $date_eastermonday); |
|
| 817 | - if($jour_eastermonday == $jour && $mois_eastermonday == $mois) $ferie=true; |
|
| 818 | - // Easter monday |
|
| 819 | - |
|
| 820 | - // Christi Himmelfahrt (39 days after easter sunday) |
|
| 821 | - $date_ch = mktime( |
|
| 822 | - date("H", $date_paques), |
|
| 823 | - date("i", $date_paques), |
|
| 824 | - date("s", $date_paques), |
|
| 825 | - date("m", $date_paques), |
|
| 826 | - date("d", $date_paques) + 39, |
|
| 827 | - date("Y", $date_paques) |
|
| 828 | - ); |
|
| 829 | - $jour_ch = date("d", $date_ch); |
|
| 830 | - $mois_ch = date("m", $date_ch); |
|
| 831 | - if($jour_ch == $jour && $mois_ch == $mois) $ferie=true; |
|
| 832 | - // Christi Himmelfahrt |
|
| 833 | - |
|
| 834 | - // Pfingsten (50 days after easter sunday) |
|
| 835 | - $date_pentecote = mktime( |
|
| 836 | - date("H", $date_paques), |
|
| 837 | - date("i", $date_paques), |
|
| 838 | - date("s", $date_paques), |
|
| 839 | - date("m", $date_paques), |
|
| 840 | - date("d", $date_paques) + 50, |
|
| 841 | - date("Y", $date_paques) |
|
| 842 | - ); |
|
| 843 | - $jour_pentecote = date("d", $date_pentecote); |
|
| 844 | - $mois_pentecote = date("m", $date_pentecote); |
|
| 845 | - if($jour_pentecote == $jour && $mois_pentecote == $mois) $ferie=true; |
|
| 846 | - // Pfingsten |
|
| 847 | - |
|
| 848 | - // Fronleichnam (60 days after easter sunday) |
|
| 849 | - $date_fronleichnam = mktime( |
|
| 850 | - date("H", $date_paques), |
|
| 851 | - date("i", $date_paques), |
|
| 852 | - date("s", $date_paques), |
|
| 853 | - date("m", $date_paques), |
|
| 854 | - date("d", $date_paques) + 60, |
|
| 855 | - date("Y", $date_paques) |
|
| 856 | - ); |
|
| 857 | - $jour_fronleichnam = date("d", $date_fronleichnam); |
|
| 858 | - $mois_fronleichnam = date("m", $date_fronleichnam); |
|
| 859 | - if($jour_fronleichnam == $jour && $mois_fronleichnam == $mois) $ferie=true; |
|
| 860 | - // Fronleichnam |
|
| 861 | - } |
|
| 862 | - |
|
| 863 | - // If we have to include saturday and sunday |
|
| 864 | - if ($includesaturdayandsunday) |
|
| 865 | - { |
|
| 866 | - $jour_julien = unixtojd($timestampStart); |
|
| 867 | - $jour_semaine = jddayofweek($jour_julien, 0); |
|
| 868 | - if($jour_semaine == 0 || $jour_semaine == 6) $ferie=true; |
|
| 869 | - //Saturday (6) and Sunday (0) |
|
| 870 | - } |
|
| 871 | - |
|
| 872 | - // On incremente compteur |
|
| 873 | - if ($ferie) $nbFerie++; |
|
| 874 | - |
|
| 875 | - // Increase number of days (on go up into loop) |
|
| 876 | - $timestampStart=dol_time_plus_duree($timestampStart, 1, 'd'); |
|
| 877 | - //var_dump($jour.' '.$mois.' '.$annee.' '.$timestampStart); |
|
| 878 | - |
|
| 879 | - $i++; |
|
| 880 | - } |
|
| 881 | - |
|
| 882 | - return $nbFerie; |
|
| 776 | + $jour_viernes = date("d", $date_viernes); |
|
| 777 | + $mois_viernes = date("m", $date_viernes); |
|
| 778 | + if($jour_viernes == $jour && $mois_viernes == $mois) $ferie=true; |
|
| 779 | + //Viernes Santo |
|
| 780 | + } |
|
| 781 | + |
|
| 782 | + if ($countrycode == 'AT') |
|
| 783 | + { |
|
| 784 | + $countryfound=1; |
|
| 785 | + |
|
| 786 | + // Definition des dates feriees fixes |
|
| 787 | + if($jour == 1 && $mois == 1) $ferie=true; // Neujahr |
|
| 788 | + if($jour == 6 && $mois == 1) $ferie=true; // Hl. 3 Koenige |
|
| 789 | + if($jour == 1 && $mois == 5) $ferie=true; // 1. Mai |
|
| 790 | + if($jour == 15 && $mois == 8) $ferie=true; // Mariae Himmelfahrt |
|
| 791 | + if($jour == 26 && $mois == 10) $ferie=true; // 26. Oktober |
|
| 792 | + if($jour == 1 && $mois == 11) $ferie=true; // Allerheiligen |
|
| 793 | + if($jour == 8 && $mois == 12) $ferie=true; // Mariae Empfaengnis |
|
| 794 | + if($jour == 24 && $mois == 12) $ferie=true; // Heilig abend |
|
| 795 | + if($jour == 25 && $mois == 12) $ferie=true; // Christtag |
|
| 796 | + if($jour == 26 && $mois == 12) $ferie=true; // Stefanietag |
|
| 797 | + if($jour == 31 && $mois == 12) $ferie=true; // Silvester |
|
| 798 | + |
|
| 799 | + // Easter calculation |
|
| 800 | + $date_paques = easter_date($annee); |
|
| 801 | + $jour_paques = date("d", $date_paques); |
|
| 802 | + $mois_paques = date("m", $date_paques); |
|
| 803 | + if($jour_paques == $jour && $mois_paques == $mois) $ferie=true; |
|
| 804 | + // Easter sunday |
|
| 805 | + |
|
| 806 | + // Monday after easter |
|
| 807 | + $date_eastermonday = mktime( |
|
| 808 | + date("H", $date_paques), |
|
| 809 | + date("i", $date_paques), |
|
| 810 | + date("s", $date_paques), |
|
| 811 | + date("m", $date_paques), |
|
| 812 | + date("d", $date_paques) + 1, |
|
| 813 | + date("Y", $date_paques) |
|
| 814 | + ); |
|
| 815 | + $jour_eastermonday = date("d", $date_eastermonday); |
|
| 816 | + $mois_eastermonday = date("m", $date_eastermonday); |
|
| 817 | + if($jour_eastermonday == $jour && $mois_eastermonday == $mois) $ferie=true; |
|
| 818 | + // Easter monday |
|
| 819 | + |
|
| 820 | + // Christi Himmelfahrt (39 days after easter sunday) |
|
| 821 | + $date_ch = mktime( |
|
| 822 | + date("H", $date_paques), |
|
| 823 | + date("i", $date_paques), |
|
| 824 | + date("s", $date_paques), |
|
| 825 | + date("m", $date_paques), |
|
| 826 | + date("d", $date_paques) + 39, |
|
| 827 | + date("Y", $date_paques) |
|
| 828 | + ); |
|
| 829 | + $jour_ch = date("d", $date_ch); |
|
| 830 | + $mois_ch = date("m", $date_ch); |
|
| 831 | + if($jour_ch == $jour && $mois_ch == $mois) $ferie=true; |
|
| 832 | + // Christi Himmelfahrt |
|
| 833 | + |
|
| 834 | + // Pfingsten (50 days after easter sunday) |
|
| 835 | + $date_pentecote = mktime( |
|
| 836 | + date("H", $date_paques), |
|
| 837 | + date("i", $date_paques), |
|
| 838 | + date("s", $date_paques), |
|
| 839 | + date("m", $date_paques), |
|
| 840 | + date("d", $date_paques) + 50, |
|
| 841 | + date("Y", $date_paques) |
|
| 842 | + ); |
|
| 843 | + $jour_pentecote = date("d", $date_pentecote); |
|
| 844 | + $mois_pentecote = date("m", $date_pentecote); |
|
| 845 | + if($jour_pentecote == $jour && $mois_pentecote == $mois) $ferie=true; |
|
| 846 | + // Pfingsten |
|
| 847 | + |
|
| 848 | + // Fronleichnam (60 days after easter sunday) |
|
| 849 | + $date_fronleichnam = mktime( |
|
| 850 | + date("H", $date_paques), |
|
| 851 | + date("i", $date_paques), |
|
| 852 | + date("s", $date_paques), |
|
| 853 | + date("m", $date_paques), |
|
| 854 | + date("d", $date_paques) + 60, |
|
| 855 | + date("Y", $date_paques) |
|
| 856 | + ); |
|
| 857 | + $jour_fronleichnam = date("d", $date_fronleichnam); |
|
| 858 | + $mois_fronleichnam = date("m", $date_fronleichnam); |
|
| 859 | + if($jour_fronleichnam == $jour && $mois_fronleichnam == $mois) $ferie=true; |
|
| 860 | + // Fronleichnam |
|
| 861 | + } |
|
| 862 | + |
|
| 863 | + // If we have to include saturday and sunday |
|
| 864 | + if ($includesaturdayandsunday) |
|
| 865 | + { |
|
| 866 | + $jour_julien = unixtojd($timestampStart); |
|
| 867 | + $jour_semaine = jddayofweek($jour_julien, 0); |
|
| 868 | + if($jour_semaine == 0 || $jour_semaine == 6) $ferie=true; |
|
| 869 | + //Saturday (6) and Sunday (0) |
|
| 870 | + } |
|
| 871 | + |
|
| 872 | + // On incremente compteur |
|
| 873 | + if ($ferie) $nbFerie++; |
|
| 874 | + |
|
| 875 | + // Increase number of days (on go up into loop) |
|
| 876 | + $timestampStart=dol_time_plus_duree($timestampStart, 1, 'd'); |
|
| 877 | + //var_dump($jour.' '.$mois.' '.$annee.' '.$timestampStart); |
|
| 878 | + |
|
| 879 | + $i++; |
|
| 880 | + } |
|
| 881 | + |
|
| 882 | + return $nbFerie; |
|
| 883 | 883 | } |
| 884 | 884 | |
| 885 | 885 | /** |
@@ -894,20 +894,20 @@ discard block |
||
| 894 | 894 | */ |
| 895 | 895 | function num_between_day($timestampStart, $timestampEnd, $lastday=0) |
| 896 | 896 | { |
| 897 | - if ($timestampStart < $timestampEnd) |
|
| 898 | - { |
|
| 899 | - if ($lastday == 1) |
|
| 900 | - { |
|
| 901 | - $bit = 0; |
|
| 902 | - } |
|
| 903 | - else |
|
| 904 | - { |
|
| 905 | - $bit = 1; |
|
| 906 | - } |
|
| 907 | - $nbjours = (int) floor(($timestampEnd - $timestampStart)/(60*60*24)) + 1 - $bit; |
|
| 908 | - } |
|
| 909 | - //print ($timestampEnd - $timestampStart) - $lastday; |
|
| 910 | - return $nbjours; |
|
| 897 | + if ($timestampStart < $timestampEnd) |
|
| 898 | + { |
|
| 899 | + if ($lastday == 1) |
|
| 900 | + { |
|
| 901 | + $bit = 0; |
|
| 902 | + } |
|
| 903 | + else |
|
| 904 | + { |
|
| 905 | + $bit = 1; |
|
| 906 | + } |
|
| 907 | + $nbjours = (int) floor(($timestampEnd - $timestampStart)/(60*60*24)) + 1 - $bit; |
|
| 908 | + } |
|
| 909 | + //print ($timestampEnd - $timestampStart) - $lastday; |
|
| 910 | + return $nbjours; |
|
| 911 | 911 | } |
| 912 | 912 | |
| 913 | 913 | /** |
@@ -924,36 +924,36 @@ discard block |
||
| 924 | 924 | */ |
| 925 | 925 | function num_open_day($timestampStart, $timestampEnd, $inhour=0, $lastday=0, $halfday=0, $country_code='') |
| 926 | 926 | { |
| 927 | - global $langs,$mysoc; |
|
| 928 | - |
|
| 929 | - if (empty($country_code)) $country_code=$mysoc->country_code; |
|
| 930 | - |
|
| 931 | - dol_syslog('num_open_day timestampStart='.$timestampStart.' timestampEnd='.$timestampEnd.' bit='.$lastday.' country_code='.$country_code); |
|
| 932 | - |
|
| 933 | - // Check parameters |
|
| 934 | - if (! is_int($timestampStart) && ! is_float($timestampStart)) return 'ErrorBadParameter_num_open_day'; |
|
| 935 | - if (! is_int($timestampEnd) && ! is_float($timestampEnd)) return 'ErrorBadParameter_num_open_day'; |
|
| 936 | - |
|
| 937 | - //print 'num_open_day timestampStart='.$timestampStart.' timestampEnd='.$timestampEnd.' bit='.$lastday; |
|
| 938 | - if ($timestampStart < $timestampEnd) |
|
| 939 | - { |
|
| 940 | - $numdays = num_between_day($timestampStart, $timestampEnd, $lastday); |
|
| 941 | - $numholidays = num_public_holiday($timestampStart, $timestampEnd, $country_code, $lastday); |
|
| 942 | - $nbOpenDay = $numdays - $numholidays; |
|
| 943 | - $nbOpenDay.= " " . $langs->trans("Days"); |
|
| 944 | - if ($inhour == 1 && $nbOpenDay <= 3) $nbOpenDay = $nbOpenDay*24 . $langs->trans("HourShort"); |
|
| 945 | - return $nbOpenDay - (($inhour == 1 ? 12 : 0.5) * abs($halfday)); |
|
| 946 | - } |
|
| 947 | - elseif ($timestampStart == $timestampEnd) |
|
| 948 | - { |
|
| 949 | - $nbOpenDay=$lastday; |
|
| 950 | - if ($inhour == 1) $nbOpenDay = $nbOpenDay*24 . $langs->trans("HourShort"); |
|
| 951 | - return $nbOpenDay - (($inhour == 1 ? 12 : 0.5) * abs($halfday)); |
|
| 952 | - } |
|
| 953 | - else |
|
| 954 | - { |
|
| 955 | - return $langs->trans("Error"); |
|
| 956 | - } |
|
| 927 | + global $langs,$mysoc; |
|
| 928 | + |
|
| 929 | + if (empty($country_code)) $country_code=$mysoc->country_code; |
|
| 930 | + |
|
| 931 | + dol_syslog('num_open_day timestampStart='.$timestampStart.' timestampEnd='.$timestampEnd.' bit='.$lastday.' country_code='.$country_code); |
|
| 932 | + |
|
| 933 | + // Check parameters |
|
| 934 | + if (! is_int($timestampStart) && ! is_float($timestampStart)) return 'ErrorBadParameter_num_open_day'; |
|
| 935 | + if (! is_int($timestampEnd) && ! is_float($timestampEnd)) return 'ErrorBadParameter_num_open_day'; |
|
| 936 | + |
|
| 937 | + //print 'num_open_day timestampStart='.$timestampStart.' timestampEnd='.$timestampEnd.' bit='.$lastday; |
|
| 938 | + if ($timestampStart < $timestampEnd) |
|
| 939 | + { |
|
| 940 | + $numdays = num_between_day($timestampStart, $timestampEnd, $lastday); |
|
| 941 | + $numholidays = num_public_holiday($timestampStart, $timestampEnd, $country_code, $lastday); |
|
| 942 | + $nbOpenDay = $numdays - $numholidays; |
|
| 943 | + $nbOpenDay.= " " . $langs->trans("Days"); |
|
| 944 | + if ($inhour == 1 && $nbOpenDay <= 3) $nbOpenDay = $nbOpenDay*24 . $langs->trans("HourShort"); |
|
| 945 | + return $nbOpenDay - (($inhour == 1 ? 12 : 0.5) * abs($halfday)); |
|
| 946 | + } |
|
| 947 | + elseif ($timestampStart == $timestampEnd) |
|
| 948 | + { |
|
| 949 | + $nbOpenDay=$lastday; |
|
| 950 | + if ($inhour == 1) $nbOpenDay = $nbOpenDay*24 . $langs->trans("HourShort"); |
|
| 951 | + return $nbOpenDay - (($inhour == 1 ? 12 : 0.5) * abs($halfday)); |
|
| 952 | + } |
|
| 953 | + else |
|
| 954 | + { |
|
| 955 | + return $langs->trans("Error"); |
|
| 956 | + } |
|
| 957 | 957 | } |
| 958 | 958 | |
| 959 | 959 | |
@@ -968,38 +968,38 @@ discard block |
||
| 968 | 968 | */ |
| 969 | 969 | function monthArray($outputlangs,$short=0) |
| 970 | 970 | { |
| 971 | - $montharray = array ( |
|
| 972 | - 1 => $outputlangs->trans("Month01"), |
|
| 973 | - 2 => $outputlangs->trans("Month02"), |
|
| 974 | - 3 => $outputlangs->trans("Month03"), |
|
| 975 | - 4 => $outputlangs->trans("Month04"), |
|
| 976 | - 5 => $outputlangs->trans("Month05"), |
|
| 977 | - 6 => $outputlangs->trans("Month06"), |
|
| 978 | - 7 => $outputlangs->trans("Month07"), |
|
| 979 | - 8 => $outputlangs->trans("Month08"), |
|
| 980 | - 9 => $outputlangs->trans("Month09"), |
|
| 981 | - 10 => $outputlangs->trans("Month10"), |
|
| 982 | - 11 => $outputlangs->trans("Month11"), |
|
| 983 | - 12 => $outputlangs->trans("Month12") |
|
| 971 | + $montharray = array ( |
|
| 972 | + 1 => $outputlangs->trans("Month01"), |
|
| 973 | + 2 => $outputlangs->trans("Month02"), |
|
| 974 | + 3 => $outputlangs->trans("Month03"), |
|
| 975 | + 4 => $outputlangs->trans("Month04"), |
|
| 976 | + 5 => $outputlangs->trans("Month05"), |
|
| 977 | + 6 => $outputlangs->trans("Month06"), |
|
| 978 | + 7 => $outputlangs->trans("Month07"), |
|
| 979 | + 8 => $outputlangs->trans("Month08"), |
|
| 980 | + 9 => $outputlangs->trans("Month09"), |
|
| 981 | + 10 => $outputlangs->trans("Month10"), |
|
| 982 | + 11 => $outputlangs->trans("Month11"), |
|
| 983 | + 12 => $outputlangs->trans("Month12") |
|
| 984 | 984 | ); |
| 985 | 985 | |
| 986 | - if (! empty($short)) |
|
| 987 | - { |
|
| 988 | - $montharray = array ( |
|
| 989 | - 1 => $outputlangs->trans("MonthShort01"), |
|
| 990 | - 2 => $outputlangs->trans("MonthShort02"), |
|
| 991 | - 3 => $outputlangs->trans("MonthShort03"), |
|
| 992 | - 4 => $outputlangs->trans("MonthShort04"), |
|
| 993 | - 5 => $outputlangs->trans("MonthShort05"), |
|
| 994 | - 6 => $outputlangs->trans("MonthShort06"), |
|
| 995 | - 7 => $outputlangs->trans("MonthShort07"), |
|
| 996 | - 8 => $outputlangs->trans("MonthShort08"), |
|
| 997 | - 9 => $outputlangs->trans("MonthShort09"), |
|
| 998 | - 10 => $outputlangs->trans("MonthShort10"), |
|
| 999 | - 11 => $outputlangs->trans("MonthShort11"), |
|
| 1000 | - 12 => $outputlangs->trans("MonthShort12") |
|
| 1001 | - ); |
|
| 1002 | - } |
|
| 1003 | - |
|
| 1004 | - return $montharray; |
|
| 986 | + if (! empty($short)) |
|
| 987 | + { |
|
| 988 | + $montharray = array ( |
|
| 989 | + 1 => $outputlangs->trans("MonthShort01"), |
|
| 990 | + 2 => $outputlangs->trans("MonthShort02"), |
|
| 991 | + 3 => $outputlangs->trans("MonthShort03"), |
|
| 992 | + 4 => $outputlangs->trans("MonthShort04"), |
|
| 993 | + 5 => $outputlangs->trans("MonthShort05"), |
|
| 994 | + 6 => $outputlangs->trans("MonthShort06"), |
|
| 995 | + 7 => $outputlangs->trans("MonthShort07"), |
|
| 996 | + 8 => $outputlangs->trans("MonthShort08"), |
|
| 997 | + 9 => $outputlangs->trans("MonthShort09"), |
|
| 998 | + 10 => $outputlangs->trans("MonthShort10"), |
|
| 999 | + 11 => $outputlangs->trans("MonthShort11"), |
|
| 1000 | + 12 => $outputlangs->trans("MonthShort12") |
|
| 1001 | + ); |
|
| 1002 | + } |
|
| 1003 | + |
|
| 1004 | + return $montharray; |
|
| 1005 | 1005 | } |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | */ |
| 34 | 34 | function get_tz_array() |
| 35 | 35 | { |
| 36 | - $tzarray=array( |
|
| 36 | + $tzarray = array( |
|
| 37 | 37 | -11=>"Pacific/Midway", |
| 38 | 38 | -10=>"Pacific/Fakaofo", |
| 39 | 39 | -9=>"America/Anchorage", |
@@ -80,28 +80,28 @@ discard block |
||
| 80 | 80 | * @param string $refgmtdate Reference period for timezone (timezone differs on winter and summer. May be 'now', 'winter' or 'summer') |
| 81 | 81 | * @return int An offset in hour (+1 for Europe/Paris on winter and +2 for Europe/Paris on summer) |
| 82 | 82 | */ |
| 83 | -function getServerTimeZoneInt($refgmtdate='now') |
|
| 83 | +function getServerTimeZoneInt($refgmtdate = 'now') |
|
| 84 | 84 | { |
| 85 | 85 | global $conf; |
| 86 | - if (method_exists('DateTimeZone','getOffset')) |
|
| 86 | + if (method_exists('DateTimeZone', 'getOffset')) |
|
| 87 | 87 | { |
| 88 | 88 | // Method 1 (include daylight) |
| 89 | - $gmtnow=dol_now('gmt'); $yearref=dol_print_date($gmtnow,'%Y'); $monthref=dol_print_date($gmtnow,'%m'); $dayref=dol_print_date($gmtnow,'%d'); |
|
| 90 | - if ($refgmtdate == 'now') $newrefgmtdate=$yearref.'-'.$monthref.'-'.$dayref; |
|
| 91 | - elseif ($refgmtdate == 'summer') $newrefgmtdate=$yearref.'-08-01'; |
|
| 92 | - else $newrefgmtdate=$yearref.'-01-01'; |
|
| 93 | - $newrefgmtdate.='T00:00:00+00:00'; |
|
| 89 | + $gmtnow = dol_now('gmt'); $yearref = dol_print_date($gmtnow, '%Y'); $monthref = dol_print_date($gmtnow, '%m'); $dayref = dol_print_date($gmtnow, '%d'); |
|
| 90 | + if ($refgmtdate == 'now') $newrefgmtdate = $yearref.'-'.$monthref.'-'.$dayref; |
|
| 91 | + elseif ($refgmtdate == 'summer') $newrefgmtdate = $yearref.'-08-01'; |
|
| 92 | + else $newrefgmtdate = $yearref.'-01-01'; |
|
| 93 | + $newrefgmtdate .= 'T00:00:00+00:00'; |
|
| 94 | 94 | $localtz = new DateTimeZone(getServerTimeZoneString()); |
| 95 | 95 | $localdt = new DateTime($newrefgmtdate, $localtz); |
| 96 | - $tmp=-1*$localtz->getOffset($localdt); |
|
| 96 | + $tmp = -1 * $localtz->getOffset($localdt); |
|
| 97 | 97 | //print $refgmtdate.'='.$tmp; |
| 98 | 98 | } |
| 99 | 99 | else |
| 100 | 100 | { |
| 101 | - $tmp=0; |
|
| 102 | - dol_print_error('','PHP version must be 5.3+'); |
|
| 101 | + $tmp = 0; |
|
| 102 | + dol_print_error('', 'PHP version must be 5.3+'); |
|
| 103 | 103 | } |
| 104 | - $tz=round(($tmp<0?1:-1)*abs($tmp/3600)); |
|
| 104 | + $tz = round(($tmp < 0 ? 1 : -1) * abs($tmp / 3600)); |
|
| 105 | 105 | return $tz; |
| 106 | 106 | } |
| 107 | 107 | |
@@ -119,24 +119,24 @@ discard block |
||
| 119 | 119 | global $conf; |
| 120 | 120 | |
| 121 | 121 | if ($duration_value == 0) return $time; |
| 122 | - if ($duration_unit == 'h') return $time + (3600*$duration_value); |
|
| 123 | - if ($duration_unit == 'w') return $time + (3600*24*7*$duration_value); |
|
| 122 | + if ($duration_unit == 'h') return $time + (3600 * $duration_value); |
|
| 123 | + if ($duration_unit == 'w') return $time + (3600 * 24 * 7 * $duration_value); |
|
| 124 | 124 | |
| 125 | - $deltastring='P'; |
|
| 125 | + $deltastring = 'P'; |
|
| 126 | 126 | |
| 127 | - if ($duration_value > 0){ $deltastring.=abs($duration_value); $sub= false; } |
|
| 128 | - if ($duration_value < 0){ $deltastring.=abs($duration_value); $sub= true; } |
|
| 129 | - if ($duration_unit == 'd') { $deltastring.="D"; } |
|
| 130 | - if ($duration_unit == 'm') { $deltastring.="M"; } |
|
| 131 | - if ($duration_unit == 'y') { $deltastring.="Y"; } |
|
| 127 | + if ($duration_value > 0) { $deltastring .= abs($duration_value); $sub = false; } |
|
| 128 | + if ($duration_value < 0) { $deltastring .= abs($duration_value); $sub = true; } |
|
| 129 | + if ($duration_unit == 'd') { $deltastring .= "D"; } |
|
| 130 | + if ($duration_unit == 'm') { $deltastring .= "M"; } |
|
| 131 | + if ($duration_unit == 'y') { $deltastring .= "Y"; } |
|
| 132 | 132 | |
| 133 | 133 | $date = new DateTime(); |
| 134 | - if (! empty($conf->global->MAIN_DATE_IN_MEMORY_ARE_GMT)) $date->setTimezone(new DateTimeZone('UTC')); |
|
| 134 | + if (!empty($conf->global->MAIN_DATE_IN_MEMORY_ARE_GMT)) $date->setTimezone(new DateTimeZone('UTC')); |
|
| 135 | 135 | $date->setTimestamp($time); |
| 136 | 136 | $interval = new DateInterval($deltastring); |
| 137 | 137 | |
| 138 | - if($sub) $date->sub($interval); |
|
| 139 | - else $date->add( $interval ); |
|
| 138 | + if ($sub) $date->sub($interval); |
|
| 139 | + else $date->add($interval); |
|
| 140 | 140 | |
| 141 | 141 | return $date->getTimestamp(); |
| 142 | 142 | } |
@@ -151,9 +151,9 @@ discard block |
||
| 151 | 151 | * @return int Time into seconds |
| 152 | 152 | * @see convertSecondToTime |
| 153 | 153 | */ |
| 154 | -function convertTime2Seconds($iHours=0, $iMinutes=0, $iSeconds=0) |
|
| 154 | +function convertTime2Seconds($iHours = 0, $iMinutes = 0, $iSeconds = 0) |
|
| 155 | 155 | { |
| 156 | - $iResult=($iHours*3600)+($iMinutes*60)+$iSeconds; |
|
| 156 | + $iResult = ($iHours * 3600) + ($iMinutes * 60) + $iSeconds; |
|
| 157 | 157 | return $iResult; |
| 158 | 158 | } |
| 159 | 159 | |
@@ -178,30 +178,30 @@ discard block |
||
| 178 | 178 | * Example: 0 return 00:00, 3600 return 1:00, 86400 return 1d, 90000 return 1 Day 01:00 |
| 179 | 179 | * @see convertTime2Seconds |
| 180 | 180 | */ |
| 181 | -function convertSecondToTime($iSecond, $format='all', $lengthOfDay=86400, $lengthOfWeek=7) |
|
| 181 | +function convertSecondToTime($iSecond, $format = 'all', $lengthOfDay = 86400, $lengthOfWeek = 7) |
|
| 182 | 182 | { |
| 183 | 183 | global $langs; |
| 184 | 184 | |
| 185 | - if (empty($lengthOfDay)) $lengthOfDay = 86400; // 1 day = 24 hours |
|
| 186 | - if (empty($lengthOfWeek)) $lengthOfWeek = 7; // 1 week = 7 days |
|
| 185 | + if (empty($lengthOfDay)) $lengthOfDay = 86400; // 1 day = 24 hours |
|
| 186 | + if (empty($lengthOfWeek)) $lengthOfWeek = 7; // 1 week = 7 days |
|
| 187 | 187 | |
| 188 | 188 | if ($format == 'all' || $format == 'allwithouthour' || $format == 'allhour' || $format == 'allhourmin') |
| 189 | 189 | { |
| 190 | - if ((int) $iSecond === 0) return '0'; // This is to avoid having 0 return a 12:00 AM for en_US |
|
| 190 | + if ((int) $iSecond === 0) return '0'; // This is to avoid having 0 return a 12:00 AM for en_US |
|
| 191 | 191 | |
| 192 | - $sTime=''; |
|
| 193 | - $sDay=0; |
|
| 194 | - $sWeek=0; |
|
| 192 | + $sTime = ''; |
|
| 193 | + $sDay = 0; |
|
| 194 | + $sWeek = 0; |
|
| 195 | 195 | |
| 196 | 196 | if ($iSecond >= $lengthOfDay) |
| 197 | 197 | { |
| 198 | - for($i = $iSecond; $i >= $lengthOfDay; $i -= $lengthOfDay ) |
|
| 198 | + for ($i = $iSecond; $i >= $lengthOfDay; $i -= $lengthOfDay) |
|
| 199 | 199 | { |
| 200 | 200 | $sDay++; |
| 201 | - $iSecond-=$lengthOfDay; |
|
| 201 | + $iSecond -= $lengthOfDay; |
|
| 202 | 202 | } |
| 203 | 203 | $dayTranslate = $langs->trans("Day"); |
| 204 | - if ($iSecond >= ($lengthOfDay*2)) $dayTranslate = $langs->trans("Days"); |
|
| 204 | + if ($iSecond >= ($lengthOfDay * 2)) $dayTranslate = $langs->trans("Days"); |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | if ($lengthOfWeek < 7) |
@@ -210,66 +210,66 @@ discard block |
||
| 210 | 210 | { |
| 211 | 211 | if ($sDay >= $lengthOfWeek) |
| 212 | 212 | { |
| 213 | - $sWeek = (int) (($sDay - $sDay % $lengthOfWeek ) / $lengthOfWeek); |
|
| 213 | + $sWeek = (int) (($sDay - $sDay % $lengthOfWeek) / $lengthOfWeek); |
|
| 214 | 214 | $sDay = $sDay % $lengthOfWeek; |
| 215 | 215 | $weekTranslate = $langs->trans("DurationWeek"); |
| 216 | 216 | if ($sWeek >= 2) $weekTranslate = $langs->trans("DurationWeeks"); |
| 217 | - $sTime.=$sWeek.' '.$weekTranslate.' '; |
|
| 217 | + $sTime .= $sWeek.' '.$weekTranslate.' '; |
|
| 218 | 218 | } |
| 219 | 219 | } |
| 220 | 220 | } |
| 221 | - if ($sDay>0) |
|
| 221 | + if ($sDay > 0) |
|
| 222 | 222 | { |
| 223 | 223 | $dayTranslate = $langs->trans("Day"); |
| 224 | 224 | if ($sDay > 1) $dayTranslate = $langs->trans("Days"); |
| 225 | - $sTime.=$sDay.' '.$dayTranslate.' '; |
|
| 225 | + $sTime .= $sDay.' '.$dayTranslate.' '; |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | if ($format == 'all') |
| 229 | 229 | { |
| 230 | 230 | if ($iSecond || empty($sDay)) |
| 231 | 231 | { |
| 232 | - $sTime.= dol_print_date($iSecond,'hourduration',true); |
|
| 232 | + $sTime .= dol_print_date($iSecond, 'hourduration', true); |
|
| 233 | 233 | } |
| 234 | 234 | } |
| 235 | 235 | if ($format == 'allhourmin') |
| 236 | 236 | { |
| 237 | - return sprintf("%02d",($sWeek*$lengthOfWeek*24 + $sDay*24 + (int) floor($iSecond/3600))).':'.sprintf("%02d",((int) floor(($iSecond % 3600)/60))); |
|
| 237 | + return sprintf("%02d", ($sWeek * $lengthOfWeek * 24 + $sDay * 24 + (int) floor($iSecond / 3600))).':'.sprintf("%02d", ((int) floor(($iSecond % 3600) / 60))); |
|
| 238 | 238 | } |
| 239 | 239 | if ($format == 'allhour') |
| 240 | 240 | { |
| 241 | - return sprintf("%02d",($sWeek*$lengthOfWeek*24 + $sDay*24 + (int) floor($iSecond/3600))); |
|
| 241 | + return sprintf("%02d", ($sWeek * $lengthOfWeek * 24 + $sDay * 24 + (int) floor($iSecond / 3600))); |
|
| 242 | 242 | } |
| 243 | 243 | } |
| 244 | 244 | else if ($format == 'hour') // only hour part |
| 245 | 245 | { |
| 246 | - $sTime=dol_print_date($iSecond,'%H',true); |
|
| 246 | + $sTime = dol_print_date($iSecond, '%H', true); |
|
| 247 | 247 | } |
| 248 | 248 | else if ($format == 'fullhour') |
| 249 | 249 | { |
| 250 | 250 | if (!empty($iSecond)) { |
| 251 | - $iSecond=$iSecond/3600; |
|
| 251 | + $iSecond = $iSecond / 3600; |
|
| 252 | 252 | } |
| 253 | 253 | else { |
| 254 | - $iSecond=0; |
|
| 254 | + $iSecond = 0; |
|
| 255 | 255 | } |
| 256 | - $sTime=$iSecond; |
|
| 256 | + $sTime = $iSecond; |
|
| 257 | 257 | } |
| 258 | 258 | else if ($format == 'min') // only min part |
| 259 | 259 | { |
| 260 | - $sTime=dol_print_date($iSecond,'%M',true); |
|
| 260 | + $sTime = dol_print_date($iSecond, '%M', true); |
|
| 261 | 261 | } |
| 262 | 262 | else if ($format == 'sec') // only sec part |
| 263 | 263 | { |
| 264 | - $sTime=dol_print_date($iSecond,'%S',true); |
|
| 264 | + $sTime = dol_print_date($iSecond, '%S', true); |
|
| 265 | 265 | } |
| 266 | 266 | else if ($format == 'month') // only month part |
| 267 | 267 | { |
| 268 | - $sTime=dol_print_date($iSecond,'%m',true); |
|
| 268 | + $sTime = dol_print_date($iSecond, '%m', true); |
|
| 269 | 269 | } |
| 270 | 270 | else if ($format == 'year') // only year part |
| 271 | 271 | { |
| 272 | - $sTime=dol_print_date($iSecond,'%Y',true); |
|
| 272 | + $sTime = dol_print_date($iSecond, '%Y', true); |
|
| 273 | 273 | } |
| 274 | 274 | return trim($sTime); |
| 275 | 275 | } |
@@ -287,19 +287,19 @@ discard block |
||
| 287 | 287 | function dolSqlDateFilter($datefield, $day_date, $month_date, $year_date) |
| 288 | 288 | { |
| 289 | 289 | global $db; |
| 290 | - $sqldate=""; |
|
| 290 | + $sqldate = ""; |
|
| 291 | 291 | if ($month_date > 0) { |
| 292 | 292 | if ($year_date > 0 && empty($day_date)) { |
| 293 | - $sqldate.= " AND ".$datefield." BETWEEN '".$db->idate(dol_get_first_day($year_date, $month_date, false)); |
|
| 294 | - $sqldate.= "' AND '".$db->idate(dol_get_last_day($year_date, $month_date, false))."'"; |
|
| 295 | - } else if ($year_date > 0 && ! empty($day_date)) { |
|
| 296 | - $sqldate.= " AND ".$datefield." BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month_date, $day_date, $year_date)); |
|
| 297 | - $sqldate.= "' AND '".$db->idate(dol_mktime(23, 59, 59, $month_date, $day_date, $year_date))."'"; |
|
| 293 | + $sqldate .= " AND ".$datefield." BETWEEN '".$db->idate(dol_get_first_day($year_date, $month_date, false)); |
|
| 294 | + $sqldate .= "' AND '".$db->idate(dol_get_last_day($year_date, $month_date, false))."'"; |
|
| 295 | + } else if ($year_date > 0 && !empty($day_date)) { |
|
| 296 | + $sqldate .= " AND ".$datefield." BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month_date, $day_date, $year_date)); |
|
| 297 | + $sqldate .= "' AND '".$db->idate(dol_mktime(23, 59, 59, $month_date, $day_date, $year_date))."'"; |
|
| 298 | 298 | } else |
| 299 | - $sqldate.= " AND date_format( ".$datefield.", '%m') = '".$db->escape($month_date)."'"; |
|
| 300 | - } else if ($year_date > 0){ |
|
| 301 | - $sqldate.= " AND ".$datefield." BETWEEN '".$db->idate(dol_get_first_day($year_date, 1, false)); |
|
| 302 | - $sqldate.= "' AND '".$db->idate(dol_get_last_day($year_date, 12, false))."'"; |
|
| 299 | + $sqldate .= " AND date_format( ".$datefield.", '%m') = '".$db->escape($month_date)."'"; |
|
| 300 | + } else if ($year_date > 0) { |
|
| 301 | + $sqldate .= " AND ".$datefield." BETWEEN '".$db->idate(dol_get_first_day($year_date, 1, false)); |
|
| 302 | + $sqldate .= "' AND '".$db->idate(dol_get_last_day($year_date, 12, false))."'"; |
|
| 303 | 303 | } |
| 304 | 304 | return $sqldate; |
| 305 | 305 | } |
@@ -322,10 +322,10 @@ discard block |
||
| 322 | 322 | * |
| 323 | 323 | * @see dol_print_date, dol_mktime, dol_getdate |
| 324 | 324 | */ |
| 325 | -function dol_stringtotime($string, $gm=1) |
|
| 325 | +function dol_stringtotime($string, $gm = 1) |
|
| 326 | 326 | { |
| 327 | 327 | // Convert date with format DD/MM/YYY HH:MM:SS. This part of code should not be used. |
| 328 | - if (preg_match('/^([0-9]+)\/([0-9]+)\/([0-9]+)\s?([0-9]+)?:?([0-9]+)?:?([0-9]+)?/i',$string,$reg)) |
|
| 328 | + if (preg_match('/^([0-9]+)\/([0-9]+)\/([0-9]+)\s?([0-9]+)?:?([0-9]+)?:?([0-9]+)?/i', $string, $reg)) |
|
| 329 | 329 | { |
| 330 | 330 | dol_syslog("dol_stringtotime call to function with deprecated parameter format", LOG_WARNING); |
| 331 | 331 | // Date est au format 'DD/MM/YY' ou 'DD/MM/YY HH:MM:SS' |
@@ -336,14 +336,14 @@ discard block |
||
| 336 | 336 | $shour = $reg[4]; |
| 337 | 337 | $smin = $reg[5]; |
| 338 | 338 | $ssec = $reg[6]; |
| 339 | - if ($syear < 50) $syear+=1900; |
|
| 340 | - if ($syear >= 50 && $syear < 100) $syear+=2000; |
|
| 341 | - $string=sprintf("%04d%02d%02d%02d%02d%02d",$syear,$smonth,$sday,$shour,$smin,$ssec); |
|
| 339 | + if ($syear < 50) $syear += 1900; |
|
| 340 | + if ($syear >= 50 && $syear < 100) $syear += 2000; |
|
| 341 | + $string = sprintf("%04d%02d%02d%02d%02d%02d", $syear, $smonth, $sday, $shour, $smin, $ssec); |
|
| 342 | 342 | } |
| 343 | 343 | else if ( |
| 344 | - preg_match('/^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})Z$/i',$string,$reg) // Convert date with format YYYY-MM-DDTHH:MM:SSZ (RFC3339) |
|
| 345 | - || preg_match('/^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})$/i',$string,$reg) // Convert date with format YYYY-MM-DD HH:MM:SS |
|
| 346 | - || preg_match('/^([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2})([0-9]{2})([0-9]{2})Z$/i',$string,$reg) // Convert date with format YYYYMMDDTHHMMSSZ |
|
| 344 | + preg_match('/^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})Z$/i', $string, $reg) // Convert date with format YYYY-MM-DDTHH:MM:SSZ (RFC3339) |
|
| 345 | + || preg_match('/^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})$/i', $string, $reg) // Convert date with format YYYY-MM-DD HH:MM:SS |
|
| 346 | + || preg_match('/^([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2})([0-9]{2})([0-9]{2})Z$/i', $string, $reg) // Convert date with format YYYYMMDDTHHMMSSZ |
|
| 347 | 347 | ) |
| 348 | 348 | { |
| 349 | 349 | $syear = $reg[1]; |
@@ -352,12 +352,12 @@ discard block |
||
| 352 | 352 | $shour = $reg[4]; |
| 353 | 353 | $smin = $reg[5]; |
| 354 | 354 | $ssec = $reg[6]; |
| 355 | - $string=sprintf("%04d%02d%02d%02d%02d%02d",$syear,$smonth,$sday,$shour,$smin,$ssec); |
|
| 355 | + $string = sprintf("%04d%02d%02d%02d%02d%02d", $syear, $smonth, $sday, $shour, $smin, $ssec); |
|
| 356 | 356 | } |
| 357 | 357 | |
| 358 | - $string=preg_replace('/([^0-9])/i','',$string); |
|
| 359 | - $tmp=$string.'000000'; |
|
| 360 | - $date=dol_mktime(substr($tmp,8,2),substr($tmp,10,2),substr($tmp,12,2),substr($tmp,4,2),substr($tmp,6,2),substr($tmp,0,4),($gm?1:0)); |
|
| 358 | + $string = preg_replace('/([^0-9])/i', '', $string); |
|
| 359 | + $tmp = $string.'000000'; |
|
| 360 | + $date = dol_mktime(substr($tmp, 8, 2), substr($tmp, 10, 2), substr($tmp, 12, 2), substr($tmp, 4, 2), substr($tmp, 6, 2), substr($tmp, 0, 4), ($gm ? 1 : 0)); |
|
| 361 | 361 | return $date; |
| 362 | 362 | } |
| 363 | 363 | |
@@ -371,9 +371,9 @@ discard block |
||
| 371 | 371 | */ |
| 372 | 372 | function dol_get_prev_day($day, $month, $year) |
| 373 | 373 | { |
| 374 | - $time=dol_mktime(12,0,0,$month,$day,$year,1,0); |
|
| 375 | - $time-=24*60*60; |
|
| 376 | - $tmparray=dol_getdate($time,true); |
|
| 374 | + $time = dol_mktime(12, 0, 0, $month, $day, $year, 1, 0); |
|
| 375 | + $time -= 24 * 60 * 60; |
|
| 376 | + $tmparray = dol_getdate($time, true); |
|
| 377 | 377 | return array('year' => $tmparray['year'], 'month' => $tmparray['mon'], 'day' => $tmparray['mday']); |
| 378 | 378 | } |
| 379 | 379 | |
@@ -386,9 +386,9 @@ discard block |
||
| 386 | 386 | */ |
| 387 | 387 | function dol_get_next_day($day, $month, $year) |
| 388 | 388 | { |
| 389 | - $time=dol_mktime(12,0,0,$month,$day,$year,1,0); |
|
| 390 | - $time+=24*60*60; |
|
| 391 | - $tmparray=dol_getdate($time,true); |
|
| 389 | + $time = dol_mktime(12, 0, 0, $month, $day, $year, 1, 0); |
|
| 390 | + $time += 24 * 60 * 60; |
|
| 391 | + $tmparray = dol_getdate($time, true); |
|
| 392 | 392 | return array('year' => $tmparray['year'], 'month' => $tmparray['mon'], 'day' => $tmparray['mday']); |
| 393 | 393 | } |
| 394 | 394 | |
@@ -407,7 +407,7 @@ discard block |
||
| 407 | 407 | } |
| 408 | 408 | else |
| 409 | 409 | { |
| 410 | - $prev_month = $month-1; |
|
| 410 | + $prev_month = $month - 1; |
|
| 411 | 411 | $prev_year = $year; |
| 412 | 412 | } |
| 413 | 413 | return array('year' => $prev_year, 'month' => $prev_month); |
@@ -446,9 +446,9 @@ discard block |
||
| 446 | 446 | { |
| 447 | 447 | $tmparray = dol_get_first_day_week($day, $month, $year); |
| 448 | 448 | |
| 449 | - $time=dol_mktime(12,0,0,$month,$tmparray['first_day'],$year,1,0); |
|
| 450 | - $time-=24*60*60*7; |
|
| 451 | - $tmparray=dol_getdate($time,true); |
|
| 449 | + $time = dol_mktime(12, 0, 0, $month, $tmparray['first_day'], $year, 1, 0); |
|
| 450 | + $time -= 24 * 60 * 60 * 7; |
|
| 451 | + $tmparray = dol_getdate($time, true); |
|
| 452 | 452 | return array('year' => $tmparray['year'], 'month' => $tmparray['mon'], 'day' => $tmparray['mday']); |
| 453 | 453 | } |
| 454 | 454 | |
@@ -464,9 +464,9 @@ discard block |
||
| 464 | 464 | { |
| 465 | 465 | $tmparray = dol_get_first_day_week($day, $month, $year); |
| 466 | 466 | |
| 467 | - $time=dol_mktime(12,0,0,$tmparray['first_month'],$tmparray['first_day'],$tmparray['first_year'],1,0); |
|
| 468 | - $time+=24*60*60*7; |
|
| 469 | - $tmparray=dol_getdate($time,true); |
|
| 467 | + $time = dol_mktime(12, 0, 0, $tmparray['first_month'], $tmparray['first_day'], $tmparray['first_year'], 1, 0); |
|
| 468 | + $time += 24 * 60 * 60 * 7; |
|
| 469 | + $tmparray = dol_getdate($time, true); |
|
| 470 | 470 | |
| 471 | 471 | return array('year' => $tmparray['year'], 'month' => $tmparray['mon'], 'day' => $tmparray['mday']); |
| 472 | 472 | } |
@@ -480,10 +480,10 @@ discard block |
||
| 480 | 480 | * Exemple: dol_get_first_day(1970,1,true) will return 0 whatever is TZ, after a dol_print_date will return 1970-01-01 00:00:00 |
| 481 | 481 | * @return int Date for first day, '' if error |
| 482 | 482 | */ |
| 483 | -function dol_get_first_day($year,$month=1,$gm=false) |
|
| 483 | +function dol_get_first_day($year, $month = 1, $gm = false) |
|
| 484 | 484 | { |
| 485 | 485 | if ($year > 9999) return ''; |
| 486 | - return dol_mktime(0,0,0,$month,1,$year,$gm); |
|
| 486 | + return dol_mktime(0, 0, 0, $month, 1, $year, $gm); |
|
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | |
@@ -494,7 +494,7 @@ discard block |
||
| 494 | 494 | * @param boolean $gm False or 0 or 'server' = Return date to compare with server TZ, True or 1 to compare with GM date. |
| 495 | 495 | * @return int Date for first day, '' if error |
| 496 | 496 | */ |
| 497 | -function dol_get_last_day($year,$month=12,$gm=false) |
|
| 497 | +function dol_get_last_day($year, $month = 12, $gm = false) |
|
| 498 | 498 | { |
| 499 | 499 | if ($year > 9999) return ''; |
| 500 | 500 | if ($month == 12) |
@@ -508,7 +508,7 @@ discard block |
||
| 508 | 508 | } |
| 509 | 509 | |
| 510 | 510 | // On se deplace au debut du mois suivant, et on retire un jour |
| 511 | - $datelim=dol_mktime(23,59,59,$month,1,$year,$gm); |
|
| 511 | + $datelim = dol_mktime(23, 59, 59, $month, 1, $year, $gm); |
|
| 512 | 512 | $datelim -= (3600 * 24); |
| 513 | 513 | |
| 514 | 514 | return $datelim; |
@@ -522,69 +522,69 @@ discard block |
||
| 522 | 522 | * @param int $gm False or 0 or 'server' = Return date to compare with server TZ, True or 1 to compare with GM date. |
| 523 | 523 | * @return array year,month,week,first_day,first_month,first_year,prev_day,prev_month,prev_year |
| 524 | 524 | */ |
| 525 | -function dol_get_first_day_week($day,$month,$year,$gm=false) |
|
| 525 | +function dol_get_first_day_week($day, $month, $year, $gm = false) |
|
| 526 | 526 | { |
| 527 | 527 | global $conf; |
| 528 | 528 | |
| 529 | 529 | //$day=2; $month=2; $year=2015; |
| 530 | - $date = dol_mktime(0,0,0,$month,$day,$year,$gm); |
|
| 530 | + $date = dol_mktime(0, 0, 0, $month, $day, $year, $gm); |
|
| 531 | 531 | |
| 532 | 532 | //Checking conf of start week |
| 533 | - $start_week = (isset($conf->global->MAIN_START_WEEK)?$conf->global->MAIN_START_WEEK:1); |
|
| 533 | + $start_week = (isset($conf->global->MAIN_START_WEEK) ? $conf->global->MAIN_START_WEEK : 1); |
|
| 534 | 534 | |
| 535 | - $tmparray = dol_getdate($date,true); // detail of current day |
|
| 535 | + $tmparray = dol_getdate($date, true); // detail of current day |
|
| 536 | 536 | |
| 537 | 537 | //Calculate days = offset from current day |
| 538 | 538 | $days = $start_week - $tmparray['wday']; |
| 539 | - if ($days>=1) $days=7-$days; |
|
| 539 | + if ($days >= 1) $days = 7 - $days; |
|
| 540 | 540 | $days = abs($days); |
| 541 | - $seconds = $days*24*60*60; |
|
| 541 | + $seconds = $days * 24 * 60 * 60; |
|
| 542 | 542 | //print 'start_week='.$start_week.' tmparray[wday]='.$tmparray['wday'].' day offset='.$days.' seconds offset='.$seconds.'<br>'; |
| 543 | 543 | |
| 544 | 544 | //Get first day of week |
| 545 | - $tmpdaytms = date($tmparray[0])-$seconds; // $tmparray[0] is day of parameters |
|
| 546 | - $tmpday = date("d",$tmpdaytms); |
|
| 545 | + $tmpdaytms = date($tmparray[0]) - $seconds; // $tmparray[0] is day of parameters |
|
| 546 | + $tmpday = date("d", $tmpdaytms); |
|
| 547 | 547 | |
| 548 | 548 | //Check first day of week is in same month than current day or not |
| 549 | - if ($tmpday>$day) |
|
| 549 | + if ($tmpday > $day) |
|
| 550 | 550 | { |
| 551 | - $prev_month = $month-1; |
|
| 552 | - $prev_year = $year; |
|
| 551 | + $prev_month = $month - 1; |
|
| 552 | + $prev_year = $year; |
|
| 553 | 553 | |
| 554 | - if ($prev_month==0) |
|
| 554 | + if ($prev_month == 0) |
|
| 555 | 555 | { |
| 556 | 556 | $prev_month = 12; |
| 557 | - $prev_year = $year-1; |
|
| 557 | + $prev_year = $year - 1; |
|
| 558 | 558 | } |
| 559 | 559 | } |
| 560 | 560 | else |
| 561 | 561 | { |
| 562 | 562 | $prev_month = $month; |
| 563 | - $prev_year = $year; |
|
| 563 | + $prev_year = $year; |
|
| 564 | 564 | } |
| 565 | 565 | $tmpmonth = $prev_month; |
| 566 | 566 | $tmpyear = $prev_year; |
| 567 | 567 | |
| 568 | 568 | //Get first day of next week |
| 569 | - $tmptime=dol_mktime(12,0,0,$month,$tmpday,$year,1,0); |
|
| 570 | - $tmptime-=24*60*60*7; |
|
| 571 | - $tmparray=dol_getdate($tmptime,true); |
|
| 572 | - $prev_day = $tmparray['mday']; |
|
| 569 | + $tmptime = dol_mktime(12, 0, 0, $month, $tmpday, $year, 1, 0); |
|
| 570 | + $tmptime -= 24 * 60 * 60 * 7; |
|
| 571 | + $tmparray = dol_getdate($tmptime, true); |
|
| 572 | + $prev_day = $tmparray['mday']; |
|
| 573 | 573 | |
| 574 | 574 | //Check prev day of week is in same month than first day or not |
| 575 | 575 | if ($prev_day > $tmpday) |
| 576 | 576 | { |
| 577 | - $prev_month = $month-1; |
|
| 578 | - $prev_year = $year; |
|
| 577 | + $prev_month = $month - 1; |
|
| 578 | + $prev_year = $year; |
|
| 579 | 579 | |
| 580 | - if ($prev_month==0) |
|
| 580 | + if ($prev_month == 0) |
|
| 581 | 581 | { |
| 582 | 582 | $prev_month = 12; |
| 583 | - $prev_year = $year-1; |
|
| 583 | + $prev_year = $year - 1; |
|
| 584 | 584 | } |
| 585 | 585 | } |
| 586 | 586 | |
| 587 | - $week = date("W",dol_mktime(0,0,0,$tmpmonth,$tmpday,$tmpyear,$gm)); |
|
| 587 | + $week = date("W", dol_mktime(0, 0, 0, $tmpmonth, $tmpday, $tmpyear, $gm)); |
|
| 588 | 588 | |
| 589 | 589 | return array('year' => $year, 'month' => $month, 'week' => $week, 'first_day' => $tmpday, 'first_month' => $tmpmonth, 'first_year' => $tmpyear, 'prev_year' => $prev_year, 'prev_month' => $prev_month, 'prev_day' => $prev_day); |
| 590 | 590 | } |
@@ -600,7 +600,7 @@ discard block |
||
| 600 | 600 | * @return int Nombre de jours feries |
| 601 | 601 | * @see num_between_day, num_open_day |
| 602 | 602 | */ |
| 603 | -function num_public_holiday($timestampStart, $timestampEnd, $countrycode='FR', $lastday=0) |
|
| 603 | +function num_public_holiday($timestampStart, $timestampEnd, $countrycode = 'FR', $lastday = 0) |
|
| 604 | 604 | { |
| 605 | 605 | global $conf; |
| 606 | 606 | |
@@ -609,13 +609,13 @@ discard block |
||
| 609 | 609 | // Check to ensure we use correct parameters |
| 610 | 610 | if ((($timestampEnd - $timestampStart) % 86400) != 0) return 'ErrorDates must use same hours and must be GMT dates'; |
| 611 | 611 | |
| 612 | - $i=0; |
|
| 613 | - while (( ($lastday == 0 && $timestampStart < $timestampEnd) || ($lastday && $timestampStart <= $timestampEnd) ) |
|
| 612 | + $i = 0; |
|
| 613 | + while ((($lastday == 0 && $timestampStart < $timestampEnd) || ($lastday && $timestampStart <= $timestampEnd)) |
|
| 614 | 614 | && ($i < 50000)) // Loop end when equals (Test on i is a security loop to avoid infinite loop) |
| 615 | 615 | { |
| 616 | - $ferie=false; |
|
| 617 | - $countryfound=0; |
|
| 618 | - $includesaturdayandsunday=1; |
|
| 616 | + $ferie = false; |
|
| 617 | + $countryfound = 0; |
|
| 618 | + $includesaturdayandsunday = 1; |
|
| 619 | 619 | |
| 620 | 620 | $jour = date("d", $timestampStart); |
| 621 | 621 | $mois = date("m", $timestampStart); |
@@ -623,42 +623,42 @@ discard block |
||
| 623 | 623 | |
| 624 | 624 | |
| 625 | 625 | // Check into var $conf->global->HOLIDAY_MORE_DAYS MM-DD,YYYY-MM-DD, ... |
| 626 | - if (! empty($conf->global->HOLIDAY_MORE_PUBLIC_HOLIDAYS)) |
|
| 626 | + if (!empty($conf->global->HOLIDAY_MORE_PUBLIC_HOLIDAYS)) |
|
| 627 | 627 | { |
| 628 | - $arrayofdaystring=explode(',',$conf->global->HOLIDAY_MORE_PUBLIC_HOLIDAYS); |
|
| 629 | - foreach($arrayofdaystring as $daystring) |
|
| 628 | + $arrayofdaystring = explode(',', $conf->global->HOLIDAY_MORE_PUBLIC_HOLIDAYS); |
|
| 629 | + foreach ($arrayofdaystring as $daystring) |
|
| 630 | 630 | { |
| 631 | - $tmp=explode('-',$daystring); |
|
| 631 | + $tmp = explode('-', $daystring); |
|
| 632 | 632 | if ($tmp[2]) |
| 633 | 633 | { |
| 634 | - if ($tmp[0] == $annee && $tmp[1] == $mois && $tmp[2] == $jour) $ferie=true; |
|
| 634 | + if ($tmp[0] == $annee && $tmp[1] == $mois && $tmp[2] == $jour) $ferie = true; |
|
| 635 | 635 | } |
| 636 | 636 | else |
| 637 | 637 | { |
| 638 | - if ($tmp[0] == $mois && $tmp[1] == $jour) $ferie=true; |
|
| 638 | + if ($tmp[0] == $mois && $tmp[1] == $jour) $ferie = true; |
|
| 639 | 639 | } |
| 640 | 640 | } |
| 641 | 641 | } |
| 642 | 642 | |
| 643 | 643 | if ($countrycode == 'FR') |
| 644 | 644 | { |
| 645 | - $countryfound=1; |
|
| 645 | + $countryfound = 1; |
|
| 646 | 646 | |
| 647 | 647 | // Definition of fixed working days |
| 648 | - if($jour == 1 && $mois == 1) $ferie=true; // 1er january |
|
| 649 | - if($jour == 1 && $mois == 5) $ferie=true; // 1er may |
|
| 650 | - if($jour == 8 && $mois == 5) $ferie=true; // 5 may |
|
| 651 | - if($jour == 14 && $mois == 7) $ferie=true; // 14 july |
|
| 652 | - if($jour == 15 && $mois == 8) $ferie=true; // 15 august |
|
| 653 | - if($jour == 1 && $mois == 11) $ferie=true; // 1 november |
|
| 654 | - if($jour == 11 && $mois == 11) $ferie=true; // 11 november |
|
| 655 | - if($jour == 25 && $mois == 12) $ferie=true; // 25 december |
|
| 648 | + if ($jour == 1 && $mois == 1) $ferie = true; // 1er january |
|
| 649 | + if ($jour == 1 && $mois == 5) $ferie = true; // 1er may |
|
| 650 | + if ($jour == 8 && $mois == 5) $ferie = true; // 5 may |
|
| 651 | + if ($jour == 14 && $mois == 7) $ferie = true; // 14 july |
|
| 652 | + if ($jour == 15 && $mois == 8) $ferie = true; // 15 august |
|
| 653 | + if ($jour == 1 && $mois == 11) $ferie = true; // 1 november |
|
| 654 | + if ($jour == 11 && $mois == 11) $ferie = true; // 11 november |
|
| 655 | + if ($jour == 25 && $mois == 12) $ferie = true; // 25 december |
|
| 656 | 656 | |
| 657 | 657 | // Calculation for easter date |
| 658 | 658 | $date_paques = easter_date($annee); |
| 659 | 659 | $jour_paques = date("d", $date_paques); |
| 660 | 660 | $mois_paques = date("m", $date_paques); |
| 661 | - if($jour_paques == $jour && $mois_paques == $mois) $ferie=true; |
|
| 661 | + if ($jour_paques == $jour && $mois_paques == $mois) $ferie = true; |
|
| 662 | 662 | // Pâques |
| 663 | 663 | |
| 664 | 664 | // Calculation for the monday of easter date |
@@ -672,7 +672,7 @@ discard block |
||
| 672 | 672 | ); |
| 673 | 673 | $jour_lundi_ascension = date("d", $date_lundi_paques); |
| 674 | 674 | $mois_lundi_ascension = date("m", $date_lundi_paques); |
| 675 | - if($jour_lundi_ascension == $jour && $mois_lundi_ascension == $mois) $ferie=true; |
|
| 675 | + if ($jour_lundi_ascension == $jour && $mois_lundi_ascension == $mois) $ferie = true; |
|
| 676 | 676 | // Lundi de Pâques |
| 677 | 677 | |
| 678 | 678 | // Calcul du jour de l'ascension (38 days after easter day) |
@@ -686,7 +686,7 @@ discard block |
||
| 686 | 686 | ); |
| 687 | 687 | $jour_ascension = date("d", $date_ascension); |
| 688 | 688 | $mois_ascension = date("m", $date_ascension); |
| 689 | - if($jour_ascension == $jour && $mois_ascension == $mois) $ferie=true; |
|
| 689 | + if ($jour_ascension == $jour && $mois_ascension == $mois) $ferie = true; |
|
| 690 | 690 | // Ascension |
| 691 | 691 | |
| 692 | 692 | // Calculation of "Pentecote" (11 days after easter day) |
@@ -700,7 +700,7 @@ discard block |
||
| 700 | 700 | ); |
| 701 | 701 | $jour_pentecote = date("d", $date_pentecote); |
| 702 | 702 | $mois_pentecote = date("m", $date_pentecote); |
| 703 | - if($jour_pentecote == $jour && $mois_pentecote == $mois) $ferie=true; |
|
| 703 | + if ($jour_pentecote == $jour && $mois_pentecote == $mois) $ferie = true; |
|
| 704 | 704 | // "Pentecote" |
| 705 | 705 | } |
| 706 | 706 | |
@@ -708,60 +708,60 @@ discard block |
||
| 708 | 708 | // Pentecoste is 50 days after Easter, Ascensione 40 |
| 709 | 709 | if ($countrycode == 'IT') |
| 710 | 710 | { |
| 711 | - $countryfound=1; |
|
| 711 | + $countryfound = 1; |
|
| 712 | 712 | |
| 713 | 713 | // Definition des dates feriees fixes |
| 714 | - if($jour == 1 && $mois == 1) $ferie=true; // Capodanno |
|
| 715 | - if($jour == 6 && $mois == 1) $ferie=true; // Epifania |
|
| 716 | - if($jour == 25 && $mois == 4) $ferie=true; // Anniversario Liberazione |
|
| 717 | - if($jour == 1 && $mois == 5) $ferie=true; // Festa del Lavoro |
|
| 718 | - if($jour == 2 && $mois == 6) $ferie=true; // Festa della Repubblica |
|
| 719 | - if($jour == 15 && $mois == 8) $ferie=true; // Ferragosto |
|
| 720 | - if($jour == 1 && $mois == 11) $ferie=true; // Tutti i Santi |
|
| 721 | - if($jour == 8 && $mois == 12) $ferie=true; // Immacolata Concezione |
|
| 722 | - if($jour == 25 && $mois == 12) $ferie=true; // 25 decembre |
|
| 723 | - if($jour == 26 && $mois == 12) $ferie=true; // Santo Stefano |
|
| 714 | + if ($jour == 1 && $mois == 1) $ferie = true; // Capodanno |
|
| 715 | + if ($jour == 6 && $mois == 1) $ferie = true; // Epifania |
|
| 716 | + if ($jour == 25 && $mois == 4) $ferie = true; // Anniversario Liberazione |
|
| 717 | + if ($jour == 1 && $mois == 5) $ferie = true; // Festa del Lavoro |
|
| 718 | + if ($jour == 2 && $mois == 6) $ferie = true; // Festa della Repubblica |
|
| 719 | + if ($jour == 15 && $mois == 8) $ferie = true; // Ferragosto |
|
| 720 | + if ($jour == 1 && $mois == 11) $ferie = true; // Tutti i Santi |
|
| 721 | + if ($jour == 8 && $mois == 12) $ferie = true; // Immacolata Concezione |
|
| 722 | + if ($jour == 25 && $mois == 12) $ferie = true; // 25 decembre |
|
| 723 | + if ($jour == 26 && $mois == 12) $ferie = true; // Santo Stefano |
|
| 724 | 724 | |
| 725 | 725 | // Calcul du jour de paques |
| 726 | 726 | $date_paques = easter_date($annee); |
| 727 | 727 | $jour_paques = date("d", $date_paques); |
| 728 | 728 | $mois_paques = date("m", $date_paques); |
| 729 | - if($jour_paques == $jour && $mois_paques == $mois) $ferie=true; |
|
| 729 | + if ($jour_paques == $jour && $mois_paques == $mois) $ferie = true; |
|
| 730 | 730 | // Paques |
| 731 | 731 | } |
| 732 | 732 | |
| 733 | 733 | if ($countrycode == 'IN') |
| 734 | 734 | { |
| 735 | - $countryfound=1; |
|
| 736 | - |
|
| 737 | - if($jour == 1 && $mois == 1) $ferie=true; // New Year's Day |
|
| 738 | - if($jour == 26 && $mois == 1) $ferie=true; // Republic Day |
|
| 739 | - if($jour == 1 && $mois == 5) $ferie=true; // May Day |
|
| 740 | - if($jour == 15 && $mois == 8) $ferie=true; // Independence Day |
|
| 741 | - if($jour == 2 && $mois == 10) $ferie=true; // Gandhi Jayanti |
|
| 742 | - if($jour == 25 && $mois == 12) $ferie=true; // Christmas |
|
| 735 | + $countryfound = 1; |
|
| 736 | + |
|
| 737 | + if ($jour == 1 && $mois == 1) $ferie = true; // New Year's Day |
|
| 738 | + if ($jour == 26 && $mois == 1) $ferie = true; // Republic Day |
|
| 739 | + if ($jour == 1 && $mois == 5) $ferie = true; // May Day |
|
| 740 | + if ($jour == 15 && $mois == 8) $ferie = true; // Independence Day |
|
| 741 | + if ($jour == 2 && $mois == 10) $ferie = true; // Gandhi Jayanti |
|
| 742 | + if ($jour == 25 && $mois == 12) $ferie = true; // Christmas |
|
| 743 | 743 | } |
| 744 | 744 | |
| 745 | 745 | if ($countrycode == 'ES') |
| 746 | 746 | { |
| 747 | - $countryfound=1; |
|
| 747 | + $countryfound = 1; |
|
| 748 | 748 | |
| 749 | 749 | // Definition des dates feriees fixes |
| 750 | - if($jour == 1 && $mois == 1) $ferie=true; // Año nuevo |
|
| 751 | - if($jour == 6 && $mois == 1) $ferie=true; // Día Reyes |
|
| 752 | - if($jour == 1 && $mois == 5) $ferie=true; // 1 Mayo |
|
| 753 | - if($jour == 15 && $mois == 8) $ferie=true; // 15 Agosto |
|
| 754 | - if($jour == 12 && $mois == 10) $ferie=true; // Día Hispanidad |
|
| 755 | - if($jour == 1 && $mois == 11) $ferie=true; // 1 noviembre |
|
| 756 | - if($jour == 6 && $mois == 12) $ferie=true; // Constitución |
|
| 757 | - if($jour == 8 && $mois == 12) $ferie=true; // Inmaculada |
|
| 758 | - if($jour == 25 && $mois == 12) $ferie=true; // 25 diciembre |
|
| 750 | + if ($jour == 1 && $mois == 1) $ferie = true; // Año nuevo |
|
| 751 | + if ($jour == 6 && $mois == 1) $ferie = true; // Día Reyes |
|
| 752 | + if ($jour == 1 && $mois == 5) $ferie = true; // 1 Mayo |
|
| 753 | + if ($jour == 15 && $mois == 8) $ferie = true; // 15 Agosto |
|
| 754 | + if ($jour == 12 && $mois == 10) $ferie = true; // Día Hispanidad |
|
| 755 | + if ($jour == 1 && $mois == 11) $ferie = true; // 1 noviembre |
|
| 756 | + if ($jour == 6 && $mois == 12) $ferie = true; // Constitución |
|
| 757 | + if ($jour == 8 && $mois == 12) $ferie = true; // Inmaculada |
|
| 758 | + if ($jour == 25 && $mois == 12) $ferie = true; // 25 diciembre |
|
| 759 | 759 | |
| 760 | 760 | // Calcul día de Pascua |
| 761 | 761 | $date_paques = easter_date($annee); |
| 762 | 762 | $jour_paques = date("d", $date_paques); |
| 763 | 763 | $mois_paques = date("m", $date_paques); |
| 764 | - if($jour_paques == $jour && $mois_paques == $mois) $ferie=true; |
|
| 764 | + if ($jour_paques == $jour && $mois_paques == $mois) $ferie = true; |
|
| 765 | 765 | // Paques |
| 766 | 766 | |
| 767 | 767 | // Viernes Santo |
@@ -770,37 +770,37 @@ discard block |
||
| 770 | 770 | date("i", $date_paques), |
| 771 | 771 | date("s", $date_paques), |
| 772 | 772 | date("m", $date_paques), |
| 773 | - date("d", $date_paques) -2, |
|
| 773 | + date("d", $date_paques) - 2, |
|
| 774 | 774 | date("Y", $date_paques) |
| 775 | 775 | ); |
| 776 | 776 | $jour_viernes = date("d", $date_viernes); |
| 777 | 777 | $mois_viernes = date("m", $date_viernes); |
| 778 | - if($jour_viernes == $jour && $mois_viernes == $mois) $ferie=true; |
|
| 778 | + if ($jour_viernes == $jour && $mois_viernes == $mois) $ferie = true; |
|
| 779 | 779 | //Viernes Santo |
| 780 | 780 | } |
| 781 | 781 | |
| 782 | 782 | if ($countrycode == 'AT') |
| 783 | 783 | { |
| 784 | - $countryfound=1; |
|
| 784 | + $countryfound = 1; |
|
| 785 | 785 | |
| 786 | 786 | // Definition des dates feriees fixes |
| 787 | - if($jour == 1 && $mois == 1) $ferie=true; // Neujahr |
|
| 788 | - if($jour == 6 && $mois == 1) $ferie=true; // Hl. 3 Koenige |
|
| 789 | - if($jour == 1 && $mois == 5) $ferie=true; // 1. Mai |
|
| 790 | - if($jour == 15 && $mois == 8) $ferie=true; // Mariae Himmelfahrt |
|
| 791 | - if($jour == 26 && $mois == 10) $ferie=true; // 26. Oktober |
|
| 792 | - if($jour == 1 && $mois == 11) $ferie=true; // Allerheiligen |
|
| 793 | - if($jour == 8 && $mois == 12) $ferie=true; // Mariae Empfaengnis |
|
| 794 | - if($jour == 24 && $mois == 12) $ferie=true; // Heilig abend |
|
| 795 | - if($jour == 25 && $mois == 12) $ferie=true; // Christtag |
|
| 796 | - if($jour == 26 && $mois == 12) $ferie=true; // Stefanietag |
|
| 797 | - if($jour == 31 && $mois == 12) $ferie=true; // Silvester |
|
| 787 | + if ($jour == 1 && $mois == 1) $ferie = true; // Neujahr |
|
| 788 | + if ($jour == 6 && $mois == 1) $ferie = true; // Hl. 3 Koenige |
|
| 789 | + if ($jour == 1 && $mois == 5) $ferie = true; // 1. Mai |
|
| 790 | + if ($jour == 15 && $mois == 8) $ferie = true; // Mariae Himmelfahrt |
|
| 791 | + if ($jour == 26 && $mois == 10) $ferie = true; // 26. Oktober |
|
| 792 | + if ($jour == 1 && $mois == 11) $ferie = true; // Allerheiligen |
|
| 793 | + if ($jour == 8 && $mois == 12) $ferie = true; // Mariae Empfaengnis |
|
| 794 | + if ($jour == 24 && $mois == 12) $ferie = true; // Heilig abend |
|
| 795 | + if ($jour == 25 && $mois == 12) $ferie = true; // Christtag |
|
| 796 | + if ($jour == 26 && $mois == 12) $ferie = true; // Stefanietag |
|
| 797 | + if ($jour == 31 && $mois == 12) $ferie = true; // Silvester |
|
| 798 | 798 | |
| 799 | 799 | // Easter calculation |
| 800 | 800 | $date_paques = easter_date($annee); |
| 801 | 801 | $jour_paques = date("d", $date_paques); |
| 802 | 802 | $mois_paques = date("m", $date_paques); |
| 803 | - if($jour_paques == $jour && $mois_paques == $mois) $ferie=true; |
|
| 803 | + if ($jour_paques == $jour && $mois_paques == $mois) $ferie = true; |
|
| 804 | 804 | // Easter sunday |
| 805 | 805 | |
| 806 | 806 | // Monday after easter |
@@ -814,7 +814,7 @@ discard block |
||
| 814 | 814 | ); |
| 815 | 815 | $jour_eastermonday = date("d", $date_eastermonday); |
| 816 | 816 | $mois_eastermonday = date("m", $date_eastermonday); |
| 817 | - if($jour_eastermonday == $jour && $mois_eastermonday == $mois) $ferie=true; |
|
| 817 | + if ($jour_eastermonday == $jour && $mois_eastermonday == $mois) $ferie = true; |
|
| 818 | 818 | // Easter monday |
| 819 | 819 | |
| 820 | 820 | // Christi Himmelfahrt (39 days after easter sunday) |
@@ -828,7 +828,7 @@ discard block |
||
| 828 | 828 | ); |
| 829 | 829 | $jour_ch = date("d", $date_ch); |
| 830 | 830 | $mois_ch = date("m", $date_ch); |
| 831 | - if($jour_ch == $jour && $mois_ch == $mois) $ferie=true; |
|
| 831 | + if ($jour_ch == $jour && $mois_ch == $mois) $ferie = true; |
|
| 832 | 832 | // Christi Himmelfahrt |
| 833 | 833 | |
| 834 | 834 | // Pfingsten (50 days after easter sunday) |
@@ -842,7 +842,7 @@ discard block |
||
| 842 | 842 | ); |
| 843 | 843 | $jour_pentecote = date("d", $date_pentecote); |
| 844 | 844 | $mois_pentecote = date("m", $date_pentecote); |
| 845 | - if($jour_pentecote == $jour && $mois_pentecote == $mois) $ferie=true; |
|
| 845 | + if ($jour_pentecote == $jour && $mois_pentecote == $mois) $ferie = true; |
|
| 846 | 846 | // Pfingsten |
| 847 | 847 | |
| 848 | 848 | // Fronleichnam (60 days after easter sunday) |
@@ -856,7 +856,7 @@ discard block |
||
| 856 | 856 | ); |
| 857 | 857 | $jour_fronleichnam = date("d", $date_fronleichnam); |
| 858 | 858 | $mois_fronleichnam = date("m", $date_fronleichnam); |
| 859 | - if($jour_fronleichnam == $jour && $mois_fronleichnam == $mois) $ferie=true; |
|
| 859 | + if ($jour_fronleichnam == $jour && $mois_fronleichnam == $mois) $ferie = true; |
|
| 860 | 860 | // Fronleichnam |
| 861 | 861 | } |
| 862 | 862 | |
@@ -865,7 +865,7 @@ discard block |
||
| 865 | 865 | { |
| 866 | 866 | $jour_julien = unixtojd($timestampStart); |
| 867 | 867 | $jour_semaine = jddayofweek($jour_julien, 0); |
| 868 | - if($jour_semaine == 0 || $jour_semaine == 6) $ferie=true; |
|
| 868 | + if ($jour_semaine == 0 || $jour_semaine == 6) $ferie = true; |
|
| 869 | 869 | //Saturday (6) and Sunday (0) |
| 870 | 870 | } |
| 871 | 871 | |
@@ -873,7 +873,7 @@ discard block |
||
| 873 | 873 | if ($ferie) $nbFerie++; |
| 874 | 874 | |
| 875 | 875 | // Increase number of days (on go up into loop) |
| 876 | - $timestampStart=dol_time_plus_duree($timestampStart, 1, 'd'); |
|
| 876 | + $timestampStart = dol_time_plus_duree($timestampStart, 1, 'd'); |
|
| 877 | 877 | //var_dump($jour.' '.$mois.' '.$annee.' '.$timestampStart); |
| 878 | 878 | |
| 879 | 879 | $i++; |
@@ -892,7 +892,7 @@ discard block |
||
| 892 | 892 | * @return int Number of days |
| 893 | 893 | * @see also num_public_holiday, num_open_day |
| 894 | 894 | */ |
| 895 | -function num_between_day($timestampStart, $timestampEnd, $lastday=0) |
|
| 895 | +function num_between_day($timestampStart, $timestampEnd, $lastday = 0) |
|
| 896 | 896 | { |
| 897 | 897 | if ($timestampStart < $timestampEnd) |
| 898 | 898 | { |
@@ -904,7 +904,7 @@ discard block |
||
| 904 | 904 | { |
| 905 | 905 | $bit = 1; |
| 906 | 906 | } |
| 907 | - $nbjours = (int) floor(($timestampEnd - $timestampStart)/(60*60*24)) + 1 - $bit; |
|
| 907 | + $nbjours = (int) floor(($timestampEnd - $timestampStart) / (60 * 60 * 24)) + 1 - $bit; |
|
| 908 | 908 | } |
| 909 | 909 | //print ($timestampEnd - $timestampStart) - $lastday; |
| 910 | 910 | return $nbjours; |
@@ -922,17 +922,17 @@ discard block |
||
| 922 | 922 | * @return int Number of days or hours |
| 923 | 923 | * @see also num_between_day, num_public_holiday |
| 924 | 924 | */ |
| 925 | -function num_open_day($timestampStart, $timestampEnd, $inhour=0, $lastday=0, $halfday=0, $country_code='') |
|
| 925 | +function num_open_day($timestampStart, $timestampEnd, $inhour = 0, $lastday = 0, $halfday = 0, $country_code = '') |
|
| 926 | 926 | { |
| 927 | - global $langs,$mysoc; |
|
| 927 | + global $langs, $mysoc; |
|
| 928 | 928 | |
| 929 | - if (empty($country_code)) $country_code=$mysoc->country_code; |
|
| 929 | + if (empty($country_code)) $country_code = $mysoc->country_code; |
|
| 930 | 930 | |
| 931 | 931 | dol_syslog('num_open_day timestampStart='.$timestampStart.' timestampEnd='.$timestampEnd.' bit='.$lastday.' country_code='.$country_code); |
| 932 | 932 | |
| 933 | 933 | // Check parameters |
| 934 | - if (! is_int($timestampStart) && ! is_float($timestampStart)) return 'ErrorBadParameter_num_open_day'; |
|
| 935 | - if (! is_int($timestampEnd) && ! is_float($timestampEnd)) return 'ErrorBadParameter_num_open_day'; |
|
| 934 | + if (!is_int($timestampStart) && !is_float($timestampStart)) return 'ErrorBadParameter_num_open_day'; |
|
| 935 | + if (!is_int($timestampEnd) && !is_float($timestampEnd)) return 'ErrorBadParameter_num_open_day'; |
|
| 936 | 936 | |
| 937 | 937 | //print 'num_open_day timestampStart='.$timestampStart.' timestampEnd='.$timestampEnd.' bit='.$lastday; |
| 938 | 938 | if ($timestampStart < $timestampEnd) |
@@ -940,14 +940,14 @@ discard block |
||
| 940 | 940 | $numdays = num_between_day($timestampStart, $timestampEnd, $lastday); |
| 941 | 941 | $numholidays = num_public_holiday($timestampStart, $timestampEnd, $country_code, $lastday); |
| 942 | 942 | $nbOpenDay = $numdays - $numholidays; |
| 943 | - $nbOpenDay.= " " . $langs->trans("Days"); |
|
| 944 | - if ($inhour == 1 && $nbOpenDay <= 3) $nbOpenDay = $nbOpenDay*24 . $langs->trans("HourShort"); |
|
| 943 | + $nbOpenDay .= " ".$langs->trans("Days"); |
|
| 944 | + if ($inhour == 1 && $nbOpenDay <= 3) $nbOpenDay = $nbOpenDay * 24.$langs->trans("HourShort"); |
|
| 945 | 945 | return $nbOpenDay - (($inhour == 1 ? 12 : 0.5) * abs($halfday)); |
| 946 | 946 | } |
| 947 | 947 | elseif ($timestampStart == $timestampEnd) |
| 948 | 948 | { |
| 949 | - $nbOpenDay=$lastday; |
|
| 950 | - if ($inhour == 1) $nbOpenDay = $nbOpenDay*24 . $langs->trans("HourShort"); |
|
| 949 | + $nbOpenDay = $lastday; |
|
| 950 | + if ($inhour == 1) $nbOpenDay = $nbOpenDay * 24.$langs->trans("HourShort"); |
|
| 951 | 951 | return $nbOpenDay - (($inhour == 1 ? 12 : 0.5) * abs($halfday)); |
| 952 | 952 | } |
| 953 | 953 | else |
@@ -966,9 +966,9 @@ discard block |
||
| 966 | 966 | * @param int $short 0=Return long label, 1=Return short label |
| 967 | 967 | * @return array Month string or array if selected < 0 |
| 968 | 968 | */ |
| 969 | -function monthArray($outputlangs,$short=0) |
|
| 969 | +function monthArray($outputlangs, $short = 0) |
|
| 970 | 970 | { |
| 971 | - $montharray = array ( |
|
| 971 | + $montharray = array( |
|
| 972 | 972 | 1 => $outputlangs->trans("Month01"), |
| 973 | 973 | 2 => $outputlangs->trans("Month02"), |
| 974 | 974 | 3 => $outputlangs->trans("Month03"), |
@@ -983,9 +983,9 @@ discard block |
||
| 983 | 983 | 12 => $outputlangs->trans("Month12") |
| 984 | 984 | ); |
| 985 | 985 | |
| 986 | - if (! empty($short)) |
|
| 986 | + if (!empty($short)) |
|
| 987 | 987 | { |
| 988 | - $montharray = array ( |
|
| 988 | + $montharray = array( |
|
| 989 | 989 | 1 => $outputlangs->trans("MonthShort01"), |
| 990 | 990 | 2 => $outputlangs->trans("MonthShort02"), |
| 991 | 991 | 3 => $outputlangs->trans("MonthShort03"), |
@@ -87,16 +87,19 @@ discard block |
||
| 87 | 87 | { |
| 88 | 88 | // Method 1 (include daylight) |
| 89 | 89 | $gmtnow=dol_now('gmt'); $yearref=dol_print_date($gmtnow,'%Y'); $monthref=dol_print_date($gmtnow,'%m'); $dayref=dol_print_date($gmtnow,'%d'); |
| 90 | - if ($refgmtdate == 'now') $newrefgmtdate=$yearref.'-'.$monthref.'-'.$dayref; |
|
| 91 | - elseif ($refgmtdate == 'summer') $newrefgmtdate=$yearref.'-08-01'; |
|
| 92 | - else $newrefgmtdate=$yearref.'-01-01'; |
|
| 90 | + if ($refgmtdate == 'now') { |
|
| 91 | + $newrefgmtdate=$yearref.'-'.$monthref.'-'.$dayref; |
|
| 92 | + } elseif ($refgmtdate == 'summer') { |
|
| 93 | + $newrefgmtdate=$yearref.'-08-01'; |
|
| 94 | + } else { |
|
| 95 | + $newrefgmtdate=$yearref.'-01-01'; |
|
| 96 | + } |
|
| 93 | 97 | $newrefgmtdate.='T00:00:00+00:00'; |
| 94 | 98 | $localtz = new DateTimeZone(getServerTimeZoneString()); |
| 95 | 99 | $localdt = new DateTime($newrefgmtdate, $localtz); |
| 96 | 100 | $tmp=-1*$localtz->getOffset($localdt); |
| 97 | 101 | //print $refgmtdate.'='.$tmp; |
| 98 | - } |
|
| 99 | - else |
|
| 102 | + } else |
|
| 100 | 103 | { |
| 101 | 104 | $tmp=0; |
| 102 | 105 | dol_print_error('','PHP version must be 5.3+'); |
@@ -118,9 +121,15 @@ discard block |
||
| 118 | 121 | { |
| 119 | 122 | global $conf; |
| 120 | 123 | |
| 121 | - if ($duration_value == 0) return $time; |
|
| 122 | - if ($duration_unit == 'h') return $time + (3600*$duration_value); |
|
| 123 | - if ($duration_unit == 'w') return $time + (3600*24*7*$duration_value); |
|
| 124 | + if ($duration_value == 0) { |
|
| 125 | + return $time; |
|
| 126 | + } |
|
| 127 | + if ($duration_unit == 'h') { |
|
| 128 | + return $time + (3600*$duration_value); |
|
| 129 | + } |
|
| 130 | + if ($duration_unit == 'w') { |
|
| 131 | + return $time + (3600*24*7*$duration_value); |
|
| 132 | + } |
|
| 124 | 133 | |
| 125 | 134 | $deltastring='P'; |
| 126 | 135 | |
@@ -131,12 +140,17 @@ discard block |
||
| 131 | 140 | if ($duration_unit == 'y') { $deltastring.="Y"; } |
| 132 | 141 | |
| 133 | 142 | $date = new DateTime(); |
| 134 | - if (! empty($conf->global->MAIN_DATE_IN_MEMORY_ARE_GMT)) $date->setTimezone(new DateTimeZone('UTC')); |
|
| 143 | + if (! empty($conf->global->MAIN_DATE_IN_MEMORY_ARE_GMT)) { |
|
| 144 | + $date->setTimezone(new DateTimeZone('UTC')); |
|
| 145 | + } |
|
| 135 | 146 | $date->setTimestamp($time); |
| 136 | 147 | $interval = new DateInterval($deltastring); |
| 137 | 148 | |
| 138 | - if($sub) $date->sub($interval); |
|
| 139 | - else $date->add( $interval ); |
|
| 149 | + if($sub) { |
|
| 150 | + $date->sub($interval); |
|
| 151 | + } else { |
|
| 152 | + $date->add( $interval ); |
|
| 153 | + } |
|
| 140 | 154 | |
| 141 | 155 | return $date->getTimestamp(); |
| 142 | 156 | } |
@@ -182,12 +196,21 @@ discard block |
||
| 182 | 196 | { |
| 183 | 197 | global $langs; |
| 184 | 198 | |
| 185 | - if (empty($lengthOfDay)) $lengthOfDay = 86400; // 1 day = 24 hours |
|
| 186 | - if (empty($lengthOfWeek)) $lengthOfWeek = 7; // 1 week = 7 days |
|
| 199 | + if (empty($lengthOfDay)) { |
|
| 200 | + $lengthOfDay = 86400; |
|
| 201 | + } |
|
| 202 | + // 1 day = 24 hours |
|
| 203 | + if (empty($lengthOfWeek)) { |
|
| 204 | + $lengthOfWeek = 7; |
|
| 205 | + } |
|
| 206 | + // 1 week = 7 days |
|
| 187 | 207 | |
| 188 | 208 | if ($format == 'all' || $format == 'allwithouthour' || $format == 'allhour' || $format == 'allhourmin') |
| 189 | 209 | { |
| 190 | - if ((int) $iSecond === 0) return '0'; // This is to avoid having 0 return a 12:00 AM for en_US |
|
| 210 | + if ((int) $iSecond === 0) { |
|
| 211 | + return '0'; |
|
| 212 | + } |
|
| 213 | + // This is to avoid having 0 return a 12:00 AM for en_US |
|
| 191 | 214 | |
| 192 | 215 | $sTime=''; |
| 193 | 216 | $sDay=0; |
@@ -201,7 +224,9 @@ discard block |
||
| 201 | 224 | $iSecond-=$lengthOfDay; |
| 202 | 225 | } |
| 203 | 226 | $dayTranslate = $langs->trans("Day"); |
| 204 | - if ($iSecond >= ($lengthOfDay*2)) $dayTranslate = $langs->trans("Days"); |
|
| 227 | + if ($iSecond >= ($lengthOfDay*2)) { |
|
| 228 | + $dayTranslate = $langs->trans("Days"); |
|
| 229 | + } |
|
| 205 | 230 | } |
| 206 | 231 | |
| 207 | 232 | if ($lengthOfWeek < 7) |
@@ -213,7 +238,9 @@ discard block |
||
| 213 | 238 | $sWeek = (int) (($sDay - $sDay % $lengthOfWeek ) / $lengthOfWeek); |
| 214 | 239 | $sDay = $sDay % $lengthOfWeek; |
| 215 | 240 | $weekTranslate = $langs->trans("DurationWeek"); |
| 216 | - if ($sWeek >= 2) $weekTranslate = $langs->trans("DurationWeeks"); |
|
| 241 | + if ($sWeek >= 2) { |
|
| 242 | + $weekTranslate = $langs->trans("DurationWeeks"); |
|
| 243 | + } |
|
| 217 | 244 | $sTime.=$sWeek.' '.$weekTranslate.' '; |
| 218 | 245 | } |
| 219 | 246 | } |
@@ -221,7 +248,9 @@ discard block |
||
| 221 | 248 | if ($sDay>0) |
| 222 | 249 | { |
| 223 | 250 | $dayTranslate = $langs->trans("Day"); |
| 224 | - if ($sDay > 1) $dayTranslate = $langs->trans("Days"); |
|
| 251 | + if ($sDay > 1) { |
|
| 252 | + $dayTranslate = $langs->trans("Days"); |
|
| 253 | + } |
|
| 225 | 254 | $sTime.=$sDay.' '.$dayTranslate.' '; |
| 226 | 255 | } |
| 227 | 256 | |
@@ -240,37 +269,40 @@ discard block |
||
| 240 | 269 | { |
| 241 | 270 | return sprintf("%02d",($sWeek*$lengthOfWeek*24 + $sDay*24 + (int) floor($iSecond/3600))); |
| 242 | 271 | } |
| 243 | - } |
|
| 244 | - else if ($format == 'hour') // only hour part |
|
| 272 | + } else if ($format == 'hour') { |
|
| 273 | + // only hour part |
|
| 245 | 274 | { |
| 246 | 275 | $sTime=dol_print_date($iSecond,'%H',true); |
| 247 | 276 | } |
| 248 | - else if ($format == 'fullhour') |
|
| 277 | + } else if ($format == 'fullhour') |
|
| 249 | 278 | { |
| 250 | 279 | if (!empty($iSecond)) { |
| 251 | 280 | $iSecond=$iSecond/3600; |
| 252 | - } |
|
| 253 | - else { |
|
| 281 | + } else { |
|
| 254 | 282 | $iSecond=0; |
| 255 | 283 | } |
| 256 | 284 | $sTime=$iSecond; |
| 257 | - } |
|
| 258 | - else if ($format == 'min') // only min part |
|
| 285 | + } else if ($format == 'min') { |
|
| 286 | + // only min part |
|
| 259 | 287 | { |
| 260 | 288 | $sTime=dol_print_date($iSecond,'%M',true); |
| 261 | 289 | } |
| 262 | - else if ($format == 'sec') // only sec part |
|
| 290 | + } else if ($format == 'sec') { |
|
| 291 | + // only sec part |
|
| 263 | 292 | { |
| 264 | 293 | $sTime=dol_print_date($iSecond,'%S',true); |
| 265 | 294 | } |
| 266 | - else if ($format == 'month') // only month part |
|
| 295 | + } else if ($format == 'month') { |
|
| 296 | + // only month part |
|
| 267 | 297 | { |
| 268 | 298 | $sTime=dol_print_date($iSecond,'%m',true); |
| 269 | 299 | } |
| 270 | - else if ($format == 'year') // only year part |
|
| 300 | + } else if ($format == 'year') { |
|
| 301 | + // only year part |
|
| 271 | 302 | { |
| 272 | 303 | $sTime=dol_print_date($iSecond,'%Y',true); |
| 273 | 304 | } |
| 305 | + } |
|
| 274 | 306 | return trim($sTime); |
| 275 | 307 | } |
| 276 | 308 | |
@@ -295,8 +327,9 @@ discard block |
||
| 295 | 327 | } else if ($year_date > 0 && ! empty($day_date)) { |
| 296 | 328 | $sqldate.= " AND ".$datefield." BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month_date, $day_date, $year_date)); |
| 297 | 329 | $sqldate.= "' AND '".$db->idate(dol_mktime(23, 59, 59, $month_date, $day_date, $year_date))."'"; |
| 298 | - } else |
|
| 299 | - $sqldate.= " AND date_format( ".$datefield.", '%m') = '".$db->escape($month_date)."'"; |
|
| 330 | + } else { |
|
| 331 | + $sqldate.= " AND date_format( ".$datefield.", '%m') = '".$db->escape($month_date)."'"; |
|
| 332 | + } |
|
| 300 | 333 | } else if ($year_date > 0){ |
| 301 | 334 | $sqldate.= " AND ".$datefield." BETWEEN '".$db->idate(dol_get_first_day($year_date, 1, false)); |
| 302 | 335 | $sqldate.= "' AND '".$db->idate(dol_get_last_day($year_date, 12, false))."'"; |
@@ -336,11 +369,14 @@ discard block |
||
| 336 | 369 | $shour = $reg[4]; |
| 337 | 370 | $smin = $reg[5]; |
| 338 | 371 | $ssec = $reg[6]; |
| 339 | - if ($syear < 50) $syear+=1900; |
|
| 340 | - if ($syear >= 50 && $syear < 100) $syear+=2000; |
|
| 372 | + if ($syear < 50) { |
|
| 373 | + $syear+=1900; |
|
| 374 | + } |
|
| 375 | + if ($syear >= 50 && $syear < 100) { |
|
| 376 | + $syear+=2000; |
|
| 377 | + } |
|
| 341 | 378 | $string=sprintf("%04d%02d%02d%02d%02d%02d",$syear,$smonth,$sday,$shour,$smin,$ssec); |
| 342 | - } |
|
| 343 | - else if ( |
|
| 379 | + } else if ( |
|
| 344 | 380 | preg_match('/^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})Z$/i',$string,$reg) // Convert date with format YYYY-MM-DDTHH:MM:SSZ (RFC3339) |
| 345 | 381 | || preg_match('/^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})$/i',$string,$reg) // Convert date with format YYYY-MM-DD HH:MM:SS |
| 346 | 382 | || preg_match('/^([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2})([0-9]{2})([0-9]{2})Z$/i',$string,$reg) // Convert date with format YYYYMMDDTHHMMSSZ |
@@ -404,8 +440,7 @@ discard block |
||
| 404 | 440 | { |
| 405 | 441 | $prev_month = 12; |
| 406 | 442 | $prev_year = $year - 1; |
| 407 | - } |
|
| 408 | - else |
|
| 443 | + } else |
|
| 409 | 444 | { |
| 410 | 445 | $prev_month = $month-1; |
| 411 | 446 | $prev_year = $year; |
@@ -425,8 +460,7 @@ discard block |
||
| 425 | 460 | { |
| 426 | 461 | $next_month = 1; |
| 427 | 462 | $next_year = $year + 1; |
| 428 | - } |
|
| 429 | - else |
|
| 463 | + } else |
|
| 430 | 464 | { |
| 431 | 465 | $next_month = $month + 1; |
| 432 | 466 | $next_year = $year; |
@@ -482,7 +516,9 @@ discard block |
||
| 482 | 516 | */ |
| 483 | 517 | function dol_get_first_day($year,$month=1,$gm=false) |
| 484 | 518 | { |
| 485 | - if ($year > 9999) return ''; |
|
| 519 | + if ($year > 9999) { |
|
| 520 | + return ''; |
|
| 521 | + } |
|
| 486 | 522 | return dol_mktime(0,0,0,$month,1,$year,$gm); |
| 487 | 523 | } |
| 488 | 524 | |
@@ -496,13 +532,14 @@ discard block |
||
| 496 | 532 | */ |
| 497 | 533 | function dol_get_last_day($year,$month=12,$gm=false) |
| 498 | 534 | { |
| 499 | - if ($year > 9999) return ''; |
|
| 535 | + if ($year > 9999) { |
|
| 536 | + return ''; |
|
| 537 | + } |
|
| 500 | 538 | if ($month == 12) |
| 501 | 539 | { |
| 502 | 540 | $month = 1; |
| 503 | 541 | $year += 1; |
| 504 | - } |
|
| 505 | - else |
|
| 542 | + } else |
|
| 506 | 543 | { |
| 507 | 544 | $month += 1; |
| 508 | 545 | } |
@@ -536,7 +573,9 @@ discard block |
||
| 536 | 573 | |
| 537 | 574 | //Calculate days = offset from current day |
| 538 | 575 | $days = $start_week - $tmparray['wday']; |
| 539 | - if ($days>=1) $days=7-$days; |
|
| 576 | + if ($days>=1) { |
|
| 577 | + $days=7-$days; |
|
| 578 | + } |
|
| 540 | 579 | $days = abs($days); |
| 541 | 580 | $seconds = $days*24*60*60; |
| 542 | 581 | //print 'start_week='.$start_week.' tmparray[wday]='.$tmparray['wday'].' day offset='.$days.' seconds offset='.$seconds.'<br>'; |
@@ -556,8 +595,7 @@ discard block |
||
| 556 | 595 | $prev_month = 12; |
| 557 | 596 | $prev_year = $year-1; |
| 558 | 597 | } |
| 559 | - } |
|
| 560 | - else |
|
| 598 | + } else |
|
| 561 | 599 | { |
| 562 | 600 | $prev_month = $month; |
| 563 | 601 | $prev_year = $year; |
@@ -607,13 +645,17 @@ discard block |
||
| 607 | 645 | $nbFerie = 0; |
| 608 | 646 | |
| 609 | 647 | // Check to ensure we use correct parameters |
| 610 | - if ((($timestampEnd - $timestampStart) % 86400) != 0) return 'ErrorDates must use same hours and must be GMT dates'; |
|
| 648 | + if ((($timestampEnd - $timestampStart) % 86400) != 0) { |
|
| 649 | + return 'ErrorDates must use same hours and must be GMT dates'; |
|
| 650 | + } |
|
| 611 | 651 | |
| 612 | 652 | $i=0; |
| 613 | 653 | while (( ($lastday == 0 && $timestampStart < $timestampEnd) || ($lastday && $timestampStart <= $timestampEnd) ) |
| 614 | - && ($i < 50000)) // Loop end when equals (Test on i is a security loop to avoid infinite loop) |
|
| 654 | + && ($i < 50000)) { |
|
| 655 | + // Loop end when equals (Test on i is a security loop to avoid infinite loop) |
|
| 615 | 656 | { |
| 616 | 657 | $ferie=false; |
| 658 | + } |
|
| 617 | 659 | $countryfound=0; |
| 618 | 660 | $includesaturdayandsunday=1; |
| 619 | 661 | |
@@ -631,11 +673,14 @@ discard block |
||
| 631 | 673 | $tmp=explode('-',$daystring); |
| 632 | 674 | if ($tmp[2]) |
| 633 | 675 | { |
| 634 | - if ($tmp[0] == $annee && $tmp[1] == $mois && $tmp[2] == $jour) $ferie=true; |
|
| 635 | - } |
|
| 636 | - else |
|
| 676 | + if ($tmp[0] == $annee && $tmp[1] == $mois && $tmp[2] == $jour) { |
|
| 677 | + $ferie=true; |
|
| 678 | + } |
|
| 679 | + } else |
|
| 637 | 680 | { |
| 638 | - if ($tmp[0] == $mois && $tmp[1] == $jour) $ferie=true; |
|
| 681 | + if ($tmp[0] == $mois && $tmp[1] == $jour) { |
|
| 682 | + $ferie=true; |
|
| 683 | + } |
|
| 639 | 684 | } |
| 640 | 685 | } |
| 641 | 686 | } |
@@ -645,20 +690,46 @@ discard block |
||
| 645 | 690 | $countryfound=1; |
| 646 | 691 | |
| 647 | 692 | // Definition of fixed working days |
| 648 | - if($jour == 1 && $mois == 1) $ferie=true; // 1er january |
|
| 649 | - if($jour == 1 && $mois == 5) $ferie=true; // 1er may |
|
| 650 | - if($jour == 8 && $mois == 5) $ferie=true; // 5 may |
|
| 651 | - if($jour == 14 && $mois == 7) $ferie=true; // 14 july |
|
| 652 | - if($jour == 15 && $mois == 8) $ferie=true; // 15 august |
|
| 653 | - if($jour == 1 && $mois == 11) $ferie=true; // 1 november |
|
| 654 | - if($jour == 11 && $mois == 11) $ferie=true; // 11 november |
|
| 655 | - if($jour == 25 && $mois == 12) $ferie=true; // 25 december |
|
| 693 | + if($jour == 1 && $mois == 1) { |
|
| 694 | + $ferie=true; |
|
| 695 | + } |
|
| 696 | + // 1er january |
|
| 697 | + if($jour == 1 && $mois == 5) { |
|
| 698 | + $ferie=true; |
|
| 699 | + } |
|
| 700 | + // 1er may |
|
| 701 | + if($jour == 8 && $mois == 5) { |
|
| 702 | + $ferie=true; |
|
| 703 | + } |
|
| 704 | + // 5 may |
|
| 705 | + if($jour == 14 && $mois == 7) { |
|
| 706 | + $ferie=true; |
|
| 707 | + } |
|
| 708 | + // 14 july |
|
| 709 | + if($jour == 15 && $mois == 8) { |
|
| 710 | + $ferie=true; |
|
| 711 | + } |
|
| 712 | + // 15 august |
|
| 713 | + if($jour == 1 && $mois == 11) { |
|
| 714 | + $ferie=true; |
|
| 715 | + } |
|
| 716 | + // 1 november |
|
| 717 | + if($jour == 11 && $mois == 11) { |
|
| 718 | + $ferie=true; |
|
| 719 | + } |
|
| 720 | + // 11 november |
|
| 721 | + if($jour == 25 && $mois == 12) { |
|
| 722 | + $ferie=true; |
|
| 723 | + } |
|
| 724 | + // 25 december |
|
| 656 | 725 | |
| 657 | 726 | // Calculation for easter date |
| 658 | 727 | $date_paques = easter_date($annee); |
| 659 | 728 | $jour_paques = date("d", $date_paques); |
| 660 | 729 | $mois_paques = date("m", $date_paques); |
| 661 | - if($jour_paques == $jour && $mois_paques == $mois) $ferie=true; |
|
| 730 | + if($jour_paques == $jour && $mois_paques == $mois) { |
|
| 731 | + $ferie=true; |
|
| 732 | + } |
|
| 662 | 733 | // Pâques |
| 663 | 734 | |
| 664 | 735 | // Calculation for the monday of easter date |
@@ -672,7 +743,9 @@ discard block |
||
| 672 | 743 | ); |
| 673 | 744 | $jour_lundi_ascension = date("d", $date_lundi_paques); |
| 674 | 745 | $mois_lundi_ascension = date("m", $date_lundi_paques); |
| 675 | - if($jour_lundi_ascension == $jour && $mois_lundi_ascension == $mois) $ferie=true; |
|
| 746 | + if($jour_lundi_ascension == $jour && $mois_lundi_ascension == $mois) { |
|
| 747 | + $ferie=true; |
|
| 748 | + } |
|
| 676 | 749 | // Lundi de Pâques |
| 677 | 750 | |
| 678 | 751 | // Calcul du jour de l'ascension (38 days after easter day) |
@@ -686,7 +759,9 @@ discard block |
||
| 686 | 759 | ); |
| 687 | 760 | $jour_ascension = date("d", $date_ascension); |
| 688 | 761 | $mois_ascension = date("m", $date_ascension); |
| 689 | - if($jour_ascension == $jour && $mois_ascension == $mois) $ferie=true; |
|
| 762 | + if($jour_ascension == $jour && $mois_ascension == $mois) { |
|
| 763 | + $ferie=true; |
|
| 764 | + } |
|
| 690 | 765 | // Ascension |
| 691 | 766 | |
| 692 | 767 | // Calculation of "Pentecote" (11 days after easter day) |
@@ -700,7 +775,9 @@ discard block |
||
| 700 | 775 | ); |
| 701 | 776 | $jour_pentecote = date("d", $date_pentecote); |
| 702 | 777 | $mois_pentecote = date("m", $date_pentecote); |
| 703 | - if($jour_pentecote == $jour && $mois_pentecote == $mois) $ferie=true; |
|
| 778 | + if($jour_pentecote == $jour && $mois_pentecote == $mois) { |
|
| 779 | + $ferie=true; |
|
| 780 | + } |
|
| 704 | 781 | // "Pentecote" |
| 705 | 782 | } |
| 706 | 783 | |
@@ -711,22 +788,54 @@ discard block |
||
| 711 | 788 | $countryfound=1; |
| 712 | 789 | |
| 713 | 790 | // Definition des dates feriees fixes |
| 714 | - if($jour == 1 && $mois == 1) $ferie=true; // Capodanno |
|
| 715 | - if($jour == 6 && $mois == 1) $ferie=true; // Epifania |
|
| 716 | - if($jour == 25 && $mois == 4) $ferie=true; // Anniversario Liberazione |
|
| 717 | - if($jour == 1 && $mois == 5) $ferie=true; // Festa del Lavoro |
|
| 718 | - if($jour == 2 && $mois == 6) $ferie=true; // Festa della Repubblica |
|
| 719 | - if($jour == 15 && $mois == 8) $ferie=true; // Ferragosto |
|
| 720 | - if($jour == 1 && $mois == 11) $ferie=true; // Tutti i Santi |
|
| 721 | - if($jour == 8 && $mois == 12) $ferie=true; // Immacolata Concezione |
|
| 722 | - if($jour == 25 && $mois == 12) $ferie=true; // 25 decembre |
|
| 723 | - if($jour == 26 && $mois == 12) $ferie=true; // Santo Stefano |
|
| 791 | + if($jour == 1 && $mois == 1) { |
|
| 792 | + $ferie=true; |
|
| 793 | + } |
|
| 794 | + // Capodanno |
|
| 795 | + if($jour == 6 && $mois == 1) { |
|
| 796 | + $ferie=true; |
|
| 797 | + } |
|
| 798 | + // Epifania |
|
| 799 | + if($jour == 25 && $mois == 4) { |
|
| 800 | + $ferie=true; |
|
| 801 | + } |
|
| 802 | + // Anniversario Liberazione |
|
| 803 | + if($jour == 1 && $mois == 5) { |
|
| 804 | + $ferie=true; |
|
| 805 | + } |
|
| 806 | + // Festa del Lavoro |
|
| 807 | + if($jour == 2 && $mois == 6) { |
|
| 808 | + $ferie=true; |
|
| 809 | + } |
|
| 810 | + // Festa della Repubblica |
|
| 811 | + if($jour == 15 && $mois == 8) { |
|
| 812 | + $ferie=true; |
|
| 813 | + } |
|
| 814 | + // Ferragosto |
|
| 815 | + if($jour == 1 && $mois == 11) { |
|
| 816 | + $ferie=true; |
|
| 817 | + } |
|
| 818 | + // Tutti i Santi |
|
| 819 | + if($jour == 8 && $mois == 12) { |
|
| 820 | + $ferie=true; |
|
| 821 | + } |
|
| 822 | + // Immacolata Concezione |
|
| 823 | + if($jour == 25 && $mois == 12) { |
|
| 824 | + $ferie=true; |
|
| 825 | + } |
|
| 826 | + // 25 decembre |
|
| 827 | + if($jour == 26 && $mois == 12) { |
|
| 828 | + $ferie=true; |
|
| 829 | + } |
|
| 830 | + // Santo Stefano |
|
| 724 | 831 | |
| 725 | 832 | // Calcul du jour de paques |
| 726 | 833 | $date_paques = easter_date($annee); |
| 727 | 834 | $jour_paques = date("d", $date_paques); |
| 728 | 835 | $mois_paques = date("m", $date_paques); |
| 729 | - if($jour_paques == $jour && $mois_paques == $mois) $ferie=true; |
|
| 836 | + if($jour_paques == $jour && $mois_paques == $mois) { |
|
| 837 | + $ferie=true; |
|
| 838 | + } |
|
| 730 | 839 | // Paques |
| 731 | 840 | } |
| 732 | 841 | |
@@ -734,12 +843,30 @@ discard block |
||
| 734 | 843 | { |
| 735 | 844 | $countryfound=1; |
| 736 | 845 | |
| 737 | - if($jour == 1 && $mois == 1) $ferie=true; // New Year's Day |
|
| 738 | - if($jour == 26 && $mois == 1) $ferie=true; // Republic Day |
|
| 739 | - if($jour == 1 && $mois == 5) $ferie=true; // May Day |
|
| 740 | - if($jour == 15 && $mois == 8) $ferie=true; // Independence Day |
|
| 741 | - if($jour == 2 && $mois == 10) $ferie=true; // Gandhi Jayanti |
|
| 742 | - if($jour == 25 && $mois == 12) $ferie=true; // Christmas |
|
| 846 | + if($jour == 1 && $mois == 1) { |
|
| 847 | + $ferie=true; |
|
| 848 | + } |
|
| 849 | + // New Year's Day |
|
| 850 | + if($jour == 26 && $mois == 1) { |
|
| 851 | + $ferie=true; |
|
| 852 | + } |
|
| 853 | + // Republic Day |
|
| 854 | + if($jour == 1 && $mois == 5) { |
|
| 855 | + $ferie=true; |
|
| 856 | + } |
|
| 857 | + // May Day |
|
| 858 | + if($jour == 15 && $mois == 8) { |
|
| 859 | + $ferie=true; |
|
| 860 | + } |
|
| 861 | + // Independence Day |
|
| 862 | + if($jour == 2 && $mois == 10) { |
|
| 863 | + $ferie=true; |
|
| 864 | + } |
|
| 865 | + // Gandhi Jayanti |
|
| 866 | + if($jour == 25 && $mois == 12) { |
|
| 867 | + $ferie=true; |
|
| 868 | + } |
|
| 869 | + // Christmas |
|
| 743 | 870 | } |
| 744 | 871 | |
| 745 | 872 | if ($countrycode == 'ES') |
@@ -747,21 +874,50 @@ discard block |
||
| 747 | 874 | $countryfound=1; |
| 748 | 875 | |
| 749 | 876 | // Definition des dates feriees fixes |
| 750 | - if($jour == 1 && $mois == 1) $ferie=true; // Año nuevo |
|
| 751 | - if($jour == 6 && $mois == 1) $ferie=true; // Día Reyes |
|
| 752 | - if($jour == 1 && $mois == 5) $ferie=true; // 1 Mayo |
|
| 753 | - if($jour == 15 && $mois == 8) $ferie=true; // 15 Agosto |
|
| 754 | - if($jour == 12 && $mois == 10) $ferie=true; // Día Hispanidad |
|
| 755 | - if($jour == 1 && $mois == 11) $ferie=true; // 1 noviembre |
|
| 756 | - if($jour == 6 && $mois == 12) $ferie=true; // Constitución |
|
| 757 | - if($jour == 8 && $mois == 12) $ferie=true; // Inmaculada |
|
| 758 | - if($jour == 25 && $mois == 12) $ferie=true; // 25 diciembre |
|
| 877 | + if($jour == 1 && $mois == 1) { |
|
| 878 | + $ferie=true; |
|
| 879 | + } |
|
| 880 | + // Año nuevo |
|
| 881 | + if($jour == 6 && $mois == 1) { |
|
| 882 | + $ferie=true; |
|
| 883 | + } |
|
| 884 | + // Día Reyes |
|
| 885 | + if($jour == 1 && $mois == 5) { |
|
| 886 | + $ferie=true; |
|
| 887 | + } |
|
| 888 | + // 1 Mayo |
|
| 889 | + if($jour == 15 && $mois == 8) { |
|
| 890 | + $ferie=true; |
|
| 891 | + } |
|
| 892 | + // 15 Agosto |
|
| 893 | + if($jour == 12 && $mois == 10) { |
|
| 894 | + $ferie=true; |
|
| 895 | + } |
|
| 896 | + // Día Hispanidad |
|
| 897 | + if($jour == 1 && $mois == 11) { |
|
| 898 | + $ferie=true; |
|
| 899 | + } |
|
| 900 | + // 1 noviembre |
|
| 901 | + if($jour == 6 && $mois == 12) { |
|
| 902 | + $ferie=true; |
|
| 903 | + } |
|
| 904 | + // Constitución |
|
| 905 | + if($jour == 8 && $mois == 12) { |
|
| 906 | + $ferie=true; |
|
| 907 | + } |
|
| 908 | + // Inmaculada |
|
| 909 | + if($jour == 25 && $mois == 12) { |
|
| 910 | + $ferie=true; |
|
| 911 | + } |
|
| 912 | + // 25 diciembre |
|
| 759 | 913 | |
| 760 | 914 | // Calcul día de Pascua |
| 761 | 915 | $date_paques = easter_date($annee); |
| 762 | 916 | $jour_paques = date("d", $date_paques); |
| 763 | 917 | $mois_paques = date("m", $date_paques); |
| 764 | - if($jour_paques == $jour && $mois_paques == $mois) $ferie=true; |
|
| 918 | + if($jour_paques == $jour && $mois_paques == $mois) { |
|
| 919 | + $ferie=true; |
|
| 920 | + } |
|
| 765 | 921 | // Paques |
| 766 | 922 | |
| 767 | 923 | // Viernes Santo |
@@ -775,7 +931,9 @@ discard block |
||
| 775 | 931 | ); |
| 776 | 932 | $jour_viernes = date("d", $date_viernes); |
| 777 | 933 | $mois_viernes = date("m", $date_viernes); |
| 778 | - if($jour_viernes == $jour && $mois_viernes == $mois) $ferie=true; |
|
| 934 | + if($jour_viernes == $jour && $mois_viernes == $mois) { |
|
| 935 | + $ferie=true; |
|
| 936 | + } |
|
| 779 | 937 | //Viernes Santo |
| 780 | 938 | } |
| 781 | 939 | |
@@ -784,23 +942,58 @@ discard block |
||
| 784 | 942 | $countryfound=1; |
| 785 | 943 | |
| 786 | 944 | // Definition des dates feriees fixes |
| 787 | - if($jour == 1 && $mois == 1) $ferie=true; // Neujahr |
|
| 788 | - if($jour == 6 && $mois == 1) $ferie=true; // Hl. 3 Koenige |
|
| 789 | - if($jour == 1 && $mois == 5) $ferie=true; // 1. Mai |
|
| 790 | - if($jour == 15 && $mois == 8) $ferie=true; // Mariae Himmelfahrt |
|
| 791 | - if($jour == 26 && $mois == 10) $ferie=true; // 26. Oktober |
|
| 792 | - if($jour == 1 && $mois == 11) $ferie=true; // Allerheiligen |
|
| 793 | - if($jour == 8 && $mois == 12) $ferie=true; // Mariae Empfaengnis |
|
| 794 | - if($jour == 24 && $mois == 12) $ferie=true; // Heilig abend |
|
| 795 | - if($jour == 25 && $mois == 12) $ferie=true; // Christtag |
|
| 796 | - if($jour == 26 && $mois == 12) $ferie=true; // Stefanietag |
|
| 797 | - if($jour == 31 && $mois == 12) $ferie=true; // Silvester |
|
| 945 | + if($jour == 1 && $mois == 1) { |
|
| 946 | + $ferie=true; |
|
| 947 | + } |
|
| 948 | + // Neujahr |
|
| 949 | + if($jour == 6 && $mois == 1) { |
|
| 950 | + $ferie=true; |
|
| 951 | + } |
|
| 952 | + // Hl. 3 Koenige |
|
| 953 | + if($jour == 1 && $mois == 5) { |
|
| 954 | + $ferie=true; |
|
| 955 | + } |
|
| 956 | + // 1. Mai |
|
| 957 | + if($jour == 15 && $mois == 8) { |
|
| 958 | + $ferie=true; |
|
| 959 | + } |
|
| 960 | + // Mariae Himmelfahrt |
|
| 961 | + if($jour == 26 && $mois == 10) { |
|
| 962 | + $ferie=true; |
|
| 963 | + } |
|
| 964 | + // 26. Oktober |
|
| 965 | + if($jour == 1 && $mois == 11) { |
|
| 966 | + $ferie=true; |
|
| 967 | + } |
|
| 968 | + // Allerheiligen |
|
| 969 | + if($jour == 8 && $mois == 12) { |
|
| 970 | + $ferie=true; |
|
| 971 | + } |
|
| 972 | + // Mariae Empfaengnis |
|
| 973 | + if($jour == 24 && $mois == 12) { |
|
| 974 | + $ferie=true; |
|
| 975 | + } |
|
| 976 | + // Heilig abend |
|
| 977 | + if($jour == 25 && $mois == 12) { |
|
| 978 | + $ferie=true; |
|
| 979 | + } |
|
| 980 | + // Christtag |
|
| 981 | + if($jour == 26 && $mois == 12) { |
|
| 982 | + $ferie=true; |
|
| 983 | + } |
|
| 984 | + // Stefanietag |
|
| 985 | + if($jour == 31 && $mois == 12) { |
|
| 986 | + $ferie=true; |
|
| 987 | + } |
|
| 988 | + // Silvester |
|
| 798 | 989 | |
| 799 | 990 | // Easter calculation |
| 800 | 991 | $date_paques = easter_date($annee); |
| 801 | 992 | $jour_paques = date("d", $date_paques); |
| 802 | 993 | $mois_paques = date("m", $date_paques); |
| 803 | - if($jour_paques == $jour && $mois_paques == $mois) $ferie=true; |
|
| 994 | + if($jour_paques == $jour && $mois_paques == $mois) { |
|
| 995 | + $ferie=true; |
|
| 996 | + } |
|
| 804 | 997 | // Easter sunday |
| 805 | 998 | |
| 806 | 999 | // Monday after easter |
@@ -814,7 +1007,9 @@ discard block |
||
| 814 | 1007 | ); |
| 815 | 1008 | $jour_eastermonday = date("d", $date_eastermonday); |
| 816 | 1009 | $mois_eastermonday = date("m", $date_eastermonday); |
| 817 | - if($jour_eastermonday == $jour && $mois_eastermonday == $mois) $ferie=true; |
|
| 1010 | + if($jour_eastermonday == $jour && $mois_eastermonday == $mois) { |
|
| 1011 | + $ferie=true; |
|
| 1012 | + } |
|
| 818 | 1013 | // Easter monday |
| 819 | 1014 | |
| 820 | 1015 | // Christi Himmelfahrt (39 days after easter sunday) |
@@ -828,7 +1023,9 @@ discard block |
||
| 828 | 1023 | ); |
| 829 | 1024 | $jour_ch = date("d", $date_ch); |
| 830 | 1025 | $mois_ch = date("m", $date_ch); |
| 831 | - if($jour_ch == $jour && $mois_ch == $mois) $ferie=true; |
|
| 1026 | + if($jour_ch == $jour && $mois_ch == $mois) { |
|
| 1027 | + $ferie=true; |
|
| 1028 | + } |
|
| 832 | 1029 | // Christi Himmelfahrt |
| 833 | 1030 | |
| 834 | 1031 | // Pfingsten (50 days after easter sunday) |
@@ -842,7 +1039,9 @@ discard block |
||
| 842 | 1039 | ); |
| 843 | 1040 | $jour_pentecote = date("d", $date_pentecote); |
| 844 | 1041 | $mois_pentecote = date("m", $date_pentecote); |
| 845 | - if($jour_pentecote == $jour && $mois_pentecote == $mois) $ferie=true; |
|
| 1042 | + if($jour_pentecote == $jour && $mois_pentecote == $mois) { |
|
| 1043 | + $ferie=true; |
|
| 1044 | + } |
|
| 846 | 1045 | // Pfingsten |
| 847 | 1046 | |
| 848 | 1047 | // Fronleichnam (60 days after easter sunday) |
@@ -856,7 +1055,9 @@ discard block |
||
| 856 | 1055 | ); |
| 857 | 1056 | $jour_fronleichnam = date("d", $date_fronleichnam); |
| 858 | 1057 | $mois_fronleichnam = date("m", $date_fronleichnam); |
| 859 | - if($jour_fronleichnam == $jour && $mois_fronleichnam == $mois) $ferie=true; |
|
| 1058 | + if($jour_fronleichnam == $jour && $mois_fronleichnam == $mois) { |
|
| 1059 | + $ferie=true; |
|
| 1060 | + } |
|
| 860 | 1061 | // Fronleichnam |
| 861 | 1062 | } |
| 862 | 1063 | |
@@ -865,12 +1066,16 @@ discard block |
||
| 865 | 1066 | { |
| 866 | 1067 | $jour_julien = unixtojd($timestampStart); |
| 867 | 1068 | $jour_semaine = jddayofweek($jour_julien, 0); |
| 868 | - if($jour_semaine == 0 || $jour_semaine == 6) $ferie=true; |
|
| 1069 | + if($jour_semaine == 0 || $jour_semaine == 6) { |
|
| 1070 | + $ferie=true; |
|
| 1071 | + } |
|
| 869 | 1072 | //Saturday (6) and Sunday (0) |
| 870 | 1073 | } |
| 871 | 1074 | |
| 872 | 1075 | // On incremente compteur |
| 873 | - if ($ferie) $nbFerie++; |
|
| 1076 | + if ($ferie) { |
|
| 1077 | + $nbFerie++; |
|
| 1078 | + } |
|
| 874 | 1079 | |
| 875 | 1080 | // Increase number of days (on go up into loop) |
| 876 | 1081 | $timestampStart=dol_time_plus_duree($timestampStart, 1, 'd'); |
@@ -899,8 +1104,7 @@ discard block |
||
| 899 | 1104 | if ($lastday == 1) |
| 900 | 1105 | { |
| 901 | 1106 | $bit = 0; |
| 902 | - } |
|
| 903 | - else |
|
| 1107 | + } else |
|
| 904 | 1108 | { |
| 905 | 1109 | $bit = 1; |
| 906 | 1110 | } |
@@ -926,13 +1130,19 @@ discard block |
||
| 926 | 1130 | { |
| 927 | 1131 | global $langs,$mysoc; |
| 928 | 1132 | |
| 929 | - if (empty($country_code)) $country_code=$mysoc->country_code; |
|
| 1133 | + if (empty($country_code)) { |
|
| 1134 | + $country_code=$mysoc->country_code; |
|
| 1135 | + } |
|
| 930 | 1136 | |
| 931 | 1137 | dol_syslog('num_open_day timestampStart='.$timestampStart.' timestampEnd='.$timestampEnd.' bit='.$lastday.' country_code='.$country_code); |
| 932 | 1138 | |
| 933 | 1139 | // Check parameters |
| 934 | - if (! is_int($timestampStart) && ! is_float($timestampStart)) return 'ErrorBadParameter_num_open_day'; |
|
| 935 | - if (! is_int($timestampEnd) && ! is_float($timestampEnd)) return 'ErrorBadParameter_num_open_day'; |
|
| 1140 | + if (! is_int($timestampStart) && ! is_float($timestampStart)) { |
|
| 1141 | + return 'ErrorBadParameter_num_open_day'; |
|
| 1142 | + } |
|
| 1143 | + if (! is_int($timestampEnd) && ! is_float($timestampEnd)) { |
|
| 1144 | + return 'ErrorBadParameter_num_open_day'; |
|
| 1145 | + } |
|
| 936 | 1146 | |
| 937 | 1147 | //print 'num_open_day timestampStart='.$timestampStart.' timestampEnd='.$timestampEnd.' bit='.$lastday; |
| 938 | 1148 | if ($timestampStart < $timestampEnd) |
@@ -941,16 +1151,18 @@ discard block |
||
| 941 | 1151 | $numholidays = num_public_holiday($timestampStart, $timestampEnd, $country_code, $lastday); |
| 942 | 1152 | $nbOpenDay = $numdays - $numholidays; |
| 943 | 1153 | $nbOpenDay.= " " . $langs->trans("Days"); |
| 944 | - if ($inhour == 1 && $nbOpenDay <= 3) $nbOpenDay = $nbOpenDay*24 . $langs->trans("HourShort"); |
|
| 1154 | + if ($inhour == 1 && $nbOpenDay <= 3) { |
|
| 1155 | + $nbOpenDay = $nbOpenDay*24 . $langs->trans("HourShort"); |
|
| 1156 | + } |
|
| 945 | 1157 | return $nbOpenDay - (($inhour == 1 ? 12 : 0.5) * abs($halfday)); |
| 946 | - } |
|
| 947 | - elseif ($timestampStart == $timestampEnd) |
|
| 1158 | + } elseif ($timestampStart == $timestampEnd) |
|
| 948 | 1159 | { |
| 949 | 1160 | $nbOpenDay=$lastday; |
| 950 | - if ($inhour == 1) $nbOpenDay = $nbOpenDay*24 . $langs->trans("HourShort"); |
|
| 1161 | + if ($inhour == 1) { |
|
| 1162 | + $nbOpenDay = $nbOpenDay*24 . $langs->trans("HourShort"); |
|
| 1163 | + } |
|
| 951 | 1164 | return $nbOpenDay - (($inhour == 1 ? 12 : 0.5) * abs($halfday)); |
| 952 | - } |
|
| 953 | - else |
|
| 1165 | + } else |
|
| 954 | 1166 | { |
| 955 | 1167 | return $langs->trans("Error"); |
| 956 | 1168 | } |
@@ -31,26 +31,26 @@ discard block |
||
| 31 | 31 | */ |
| 32 | 32 | function ecm_prepare_dasboard_head($object) |
| 33 | 33 | { |
| 34 | - global $langs, $conf, $user, $form; |
|
| 35 | - global $helptext1, $helptext2; |
|
| 34 | + global $langs, $conf, $user, $form; |
|
| 35 | + global $helptext1, $helptext2; |
|
| 36 | 36 | |
| 37 | - $h = 0; |
|
| 38 | - $head = array(); |
|
| 37 | + $h = 0; |
|
| 38 | + $head = array(); |
|
| 39 | 39 | $helptext =$langs->trans("ECMAreaDesc").'<br>'; |
| 40 | 40 | $helptext.=$langs->trans("ECMAreaDesc2"); |
| 41 | 41 | |
| 42 | - $head[$h][0] = DOL_URL_ROOT.'/ecm/index.php'; |
|
| 43 | - $head[$h][1] = $langs->trans("ECMSectionsManual").$form->textwithpicto('', $helptext, 1, 'info', '', 0, 3); |
|
| 44 | - $head[$h][2] = 'index'; |
|
| 45 | - $h++; |
|
| 42 | + $head[$h][0] = DOL_URL_ROOT.'/ecm/index.php'; |
|
| 43 | + $head[$h][1] = $langs->trans("ECMSectionsManual").$form->textwithpicto('', $helptext, 1, 'info', '', 0, 3); |
|
| 44 | + $head[$h][2] = 'index'; |
|
| 45 | + $h++; |
|
| 46 | 46 | |
| 47 | - if (! empty($conf->global->ECM_AUTO_TREE_ENABLED)) |
|
| 48 | - { |
|
| 49 | - $head[$h][0] = DOL_URL_ROOT.'/ecm/index_auto.php'; |
|
| 50 | - $head[$h][1] = $langs->trans("ECMSectionsAuto").$form->textwithpicto('', $helptext, 1, 'info', '', 0, 3); |
|
| 51 | - $head[$h][2] = 'index_auto'; |
|
| 52 | - $h++; |
|
| 53 | - } |
|
| 47 | + if (! empty($conf->global->ECM_AUTO_TREE_ENABLED)) |
|
| 48 | + { |
|
| 49 | + $head[$h][0] = DOL_URL_ROOT.'/ecm/index_auto.php'; |
|
| 50 | + $head[$h][1] = $langs->trans("ECMSectionsAuto").$form->textwithpicto('', $helptext, 1, 'info', '', 0, 3); |
|
| 51 | + $head[$h][2] = 'index_auto'; |
|
| 52 | + $h++; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | 55 | // Show more tabs from modules |
| 56 | 56 | // Entries must be declared in modules descriptor with line |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | |
| 61 | 61 | complete_head_from_modules($conf,$langs,$object,$head,$h,'ecm','remove'); |
| 62 | 62 | |
| 63 | - return $head; |
|
| 63 | + return $head; |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | |
@@ -74,26 +74,26 @@ discard block |
||
| 74 | 74 | */ |
| 75 | 75 | function ecm_prepare_head($object, $module='ecm', $section='') |
| 76 | 76 | { |
| 77 | - global $langs, $conf, $user; |
|
| 78 | - $h = 0; |
|
| 79 | - $head = array(); |
|
| 80 | - |
|
| 81 | - if ($module == 'ecm') |
|
| 82 | - { |
|
| 83 | - $head[$h][0] = DOL_URL_ROOT.'/ecm/dir_card.php?section='.$object->id; |
|
| 84 | - $head[$h][1] = $langs->trans("Card"); |
|
| 85 | - $head[$h][2] = 'card'; |
|
| 86 | - $h++; |
|
| 87 | - } |
|
| 88 | - else |
|
| 89 | - { |
|
| 90 | - $head[$h][0] = DOL_URL_ROOT.'/ecm/dir_card.php?section='.$section.'&module='.$module; |
|
| 91 | - $head[$h][1] = $langs->trans("Card"); |
|
| 92 | - $head[$h][2] = 'card'; |
|
| 93 | - $h++; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - return $head; |
|
| 77 | + global $langs, $conf, $user; |
|
| 78 | + $h = 0; |
|
| 79 | + $head = array(); |
|
| 80 | + |
|
| 81 | + if ($module == 'ecm') |
|
| 82 | + { |
|
| 83 | + $head[$h][0] = DOL_URL_ROOT.'/ecm/dir_card.php?section='.$object->id; |
|
| 84 | + $head[$h][1] = $langs->trans("Card"); |
|
| 85 | + $head[$h][2] = 'card'; |
|
| 86 | + $h++; |
|
| 87 | + } |
|
| 88 | + else |
|
| 89 | + { |
|
| 90 | + $head[$h][0] = DOL_URL_ROOT.'/ecm/dir_card.php?section='.$section.'&module='.$module; |
|
| 91 | + $head[$h][1] = $langs->trans("Card"); |
|
| 92 | + $head[$h][2] = 'card'; |
|
| 93 | + $h++; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + return $head; |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | /** |
@@ -124,20 +124,20 @@ discard block |
||
| 124 | 124 | */ |
| 125 | 125 | function ecm_prepare_head_fm($object) |
| 126 | 126 | { |
| 127 | - global $langs, $conf; |
|
| 128 | - $h = 0; |
|
| 129 | - $head = array(); |
|
| 127 | + global $langs, $conf; |
|
| 128 | + $h = 0; |
|
| 129 | + $head = array(); |
|
| 130 | 130 | |
| 131 | - $head[$h][0] = DOL_URL_ROOT.'/ecm/index.php?action=file_manager'; |
|
| 132 | - $head[$h][1] = $langs->trans('ECMFileManager'); |
|
| 133 | - $head[$h][2] = 'file_manager'; |
|
| 134 | - $h++; |
|
| 131 | + $head[$h][0] = DOL_URL_ROOT.'/ecm/index.php?action=file_manager'; |
|
| 132 | + $head[$h][1] = $langs->trans('ECMFileManager'); |
|
| 133 | + $head[$h][2] = 'file_manager'; |
|
| 134 | + $h++; |
|
| 135 | 135 | |
| 136 | - $head[$h][0] = DOL_URL_ROOT.'/ecm/search.php'; |
|
| 137 | - $head[$h][1] = $langs->trans('Search'); |
|
| 138 | - $head[$h][2] = 'search_form'; |
|
| 139 | - $h++; |
|
| 136 | + $head[$h][0] = DOL_URL_ROOT.'/ecm/search.php'; |
|
| 137 | + $head[$h][1] = $langs->trans('Search'); |
|
| 138 | + $head[$h][2] = 'search_form'; |
|
| 139 | + $h++; |
|
| 140 | 140 | |
| 141 | - return $head; |
|
| 141 | + return $head; |
|
| 142 | 142 | } |
| 143 | 143 | |
@@ -36,15 +36,15 @@ discard block |
||
| 36 | 36 | |
| 37 | 37 | $h = 0; |
| 38 | 38 | $head = array(); |
| 39 | - $helptext =$langs->trans("ECMAreaDesc").'<br>'; |
|
| 40 | - $helptext.=$langs->trans("ECMAreaDesc2"); |
|
| 39 | + $helptext = $langs->trans("ECMAreaDesc").'<br>'; |
|
| 40 | + $helptext .= $langs->trans("ECMAreaDesc2"); |
|
| 41 | 41 | |
| 42 | 42 | $head[$h][0] = DOL_URL_ROOT.'/ecm/index.php'; |
| 43 | 43 | $head[$h][1] = $langs->trans("ECMSectionsManual").$form->textwithpicto('', $helptext, 1, 'info', '', 0, 3); |
| 44 | 44 | $head[$h][2] = 'index'; |
| 45 | 45 | $h++; |
| 46 | 46 | |
| 47 | - if (! empty($conf->global->ECM_AUTO_TREE_ENABLED)) |
|
| 47 | + if (!empty($conf->global->ECM_AUTO_TREE_ENABLED)) |
|
| 48 | 48 | { |
| 49 | 49 | $head[$h][0] = DOL_URL_ROOT.'/ecm/index_auto.php'; |
| 50 | 50 | $head[$h][1] = $langs->trans("ECMSectionsAuto").$form->textwithpicto('', $helptext, 1, 'info', '', 0, 3); |
@@ -56,9 +56,9 @@ discard block |
||
| 56 | 56 | // Entries must be declared in modules descriptor with line |
| 57 | 57 | // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab |
| 58 | 58 | // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab |
| 59 | - complete_head_from_modules($conf,$langs,$object,$head,$h,'ecm'); |
|
| 59 | + complete_head_from_modules($conf, $langs, $object, $head, $h, 'ecm'); |
|
| 60 | 60 | |
| 61 | - complete_head_from_modules($conf,$langs,$object,$head,$h,'ecm','remove'); |
|
| 61 | + complete_head_from_modules($conf, $langs, $object, $head, $h, 'ecm', 'remove'); |
|
| 62 | 62 | |
| 63 | 63 | return $head; |
| 64 | 64 | } |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | * @param string $section Section |
| 73 | 73 | * @return array Array of tabs to show |
| 74 | 74 | */ |
| 75 | -function ecm_prepare_head($object, $module='ecm', $section='') |
|
| 75 | +function ecm_prepare_head($object, $module = 'ecm', $section = '') |
|
| 76 | 76 | { |
| 77 | 77 | global $langs, $conf, $user; |
| 78 | 78 | $h = 0; |
@@ -84,8 +84,7 @@ |
||
| 84 | 84 | $head[$h][1] = $langs->trans("Card"); |
| 85 | 85 | $head[$h][2] = 'card'; |
| 86 | 86 | $h++; |
| 87 | - } |
|
| 88 | - else |
|
| 87 | + } else |
|
| 89 | 88 | { |
| 90 | 89 | $head[$h][0] = DOL_URL_ROOT.'/ecm/dir_card.php?section='.$section.'&module='.$module; |
| 91 | 90 | $head[$h][1] = $langs->trans("Card"); |
@@ -35,31 +35,31 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | function dol_convertToWord($num, $langs, $currency=false, $centimes=false) |
| 37 | 37 | { |
| 38 | - global $conf; |
|
| 38 | + global $conf; |
|
| 39 | 39 | |
| 40 | 40 | $num = str_replace(array(',', ' '), '', trim($num)); |
| 41 | 41 | if(! $num) { |
| 42 | 42 | return false; |
| 43 | 43 | } |
| 44 | - if($centimes && strlen($num) == 1) { |
|
| 45 | - $num = $num*10; |
|
| 46 | - } |
|
| 47 | - $TNum = explode('.',$num); |
|
| 44 | + if($centimes && strlen($num) == 1) { |
|
| 45 | + $num = $num*10; |
|
| 46 | + } |
|
| 47 | + $TNum = explode('.',$num); |
|
| 48 | 48 | $num = (int) $TNum[0]; |
| 49 | 49 | $words = array(); |
| 50 | 50 | $list1 = array( |
| 51 | - '', |
|
| 52 | - $langs->transnoentitiesnoconv('one'), |
|
| 53 | - $langs->transnoentitiesnoconv('two'), |
|
| 54 | - $langs->transnoentitiesnoconv('three'), |
|
| 55 | - $langs->transnoentitiesnoconv('four'), |
|
| 56 | - $langs->transnoentitiesnoconv('five'), |
|
| 57 | - $langs->transnoentitiesnoconv('six'), |
|
| 58 | - $langs->transnoentitiesnoconv('seven'), |
|
| 59 | - $langs->transnoentitiesnoconv('eight'), |
|
| 60 | - $langs->transnoentitiesnoconv('nine'), |
|
| 61 | - $langs->transnoentitiesnoconv('ten'), |
|
| 62 | - $langs->transnoentitiesnoconv('eleven'), |
|
| 51 | + '', |
|
| 52 | + $langs->transnoentitiesnoconv('one'), |
|
| 53 | + $langs->transnoentitiesnoconv('two'), |
|
| 54 | + $langs->transnoentitiesnoconv('three'), |
|
| 55 | + $langs->transnoentitiesnoconv('four'), |
|
| 56 | + $langs->transnoentitiesnoconv('five'), |
|
| 57 | + $langs->transnoentitiesnoconv('six'), |
|
| 58 | + $langs->transnoentitiesnoconv('seven'), |
|
| 59 | + $langs->transnoentitiesnoconv('eight'), |
|
| 60 | + $langs->transnoentitiesnoconv('nine'), |
|
| 61 | + $langs->transnoentitiesnoconv('ten'), |
|
| 62 | + $langs->transnoentitiesnoconv('eleven'), |
|
| 63 | 63 | $langs->transnoentitiesnoconv('twelve'), |
| 64 | 64 | $langs->transnoentitiesnoconv('thirteen'), |
| 65 | 65 | $langs->transnoentitiesnoconv('fourteen'), |
@@ -70,25 +70,25 @@ discard block |
||
| 70 | 70 | $langs->transnoentitiesnoconv('nineteen') |
| 71 | 71 | ); |
| 72 | 72 | $list2 = array( |
| 73 | - '', |
|
| 74 | - $langs->transnoentitiesnoconv('ten'), |
|
| 75 | - $langs->transnoentitiesnoconv('twenty'), |
|
| 76 | - $langs->transnoentitiesnoconv('thirty'), |
|
| 77 | - $langs->transnoentitiesnoconv('forty'), |
|
| 78 | - $langs->transnoentitiesnoconv('fifty'), |
|
| 79 | - $langs->transnoentitiesnoconv('sixty'), |
|
| 80 | - $langs->transnoentitiesnoconv('seventy'), |
|
| 81 | - $langs->transnoentitiesnoconv('eighty'), |
|
| 82 | - $langs->transnoentitiesnoconv('ninety'), |
|
| 83 | - $langs->transnoentitiesnoconv('hundred') |
|
| 84 | - ); |
|
| 73 | + '', |
|
| 74 | + $langs->transnoentitiesnoconv('ten'), |
|
| 75 | + $langs->transnoentitiesnoconv('twenty'), |
|
| 76 | + $langs->transnoentitiesnoconv('thirty'), |
|
| 77 | + $langs->transnoentitiesnoconv('forty'), |
|
| 78 | + $langs->transnoentitiesnoconv('fifty'), |
|
| 79 | + $langs->transnoentitiesnoconv('sixty'), |
|
| 80 | + $langs->transnoentitiesnoconv('seventy'), |
|
| 81 | + $langs->transnoentitiesnoconv('eighty'), |
|
| 82 | + $langs->transnoentitiesnoconv('ninety'), |
|
| 83 | + $langs->transnoentitiesnoconv('hundred') |
|
| 84 | + ); |
|
| 85 | 85 | $list3 = array( |
| 86 | - '', |
|
| 87 | - $langs->transnoentitiesnoconv('thousand'), |
|
| 88 | - $langs->transnoentitiesnoconv('million'), |
|
| 89 | - $langs->transnoentitiesnoconv('billion'), |
|
| 90 | - $langs->transnoentitiesnoconv('trillion'), |
|
| 91 | - $langs->transnoentitiesnoconv('quadrillion') |
|
| 86 | + '', |
|
| 87 | + $langs->transnoentitiesnoconv('thousand'), |
|
| 88 | + $langs->transnoentitiesnoconv('million'), |
|
| 89 | + $langs->transnoentitiesnoconv('billion'), |
|
| 90 | + $langs->transnoentitiesnoconv('trillion'), |
|
| 91 | + $langs->transnoentitiesnoconv('quadrillion') |
|
| 92 | 92 | ); |
| 93 | 93 | |
| 94 | 94 | $num_length = strlen($num); |
@@ -117,20 +117,20 @@ discard block |
||
| 117 | 117 | if ($commas > 1) { |
| 118 | 118 | $commas = $commas - 1; |
| 119 | 119 | } |
| 120 | - $concatWords = implode(' ', $words); |
|
| 121 | - // Delete multi whitespaces |
|
| 122 | - $concatWords = trim(preg_replace('/[ ]+/', ' ', $concatWords)); |
|
| 120 | + $concatWords = implode(' ', $words); |
|
| 121 | + // Delete multi whitespaces |
|
| 122 | + $concatWords = trim(preg_replace('/[ ]+/', ' ', $concatWords)); |
|
| 123 | 123 | |
| 124 | - if(!empty($currency)) { |
|
| 125 | - $concatWords .= ' '.$currency; |
|
| 126 | - } |
|
| 124 | + if(!empty($currency)) { |
|
| 125 | + $concatWords .= ' '.$currency; |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | - // If we need to write cents call again this function for cents |
|
| 129 | - if(!empty($TNum[1])) { |
|
| 130 | - if(!empty($currency)) $concatWords .= ' '.$langs->transnoentities('and'); |
|
| 131 | - $concatWords .= ' '.dol_convertToWord($TNum[1], $langs, $currency, true); |
|
| 132 | - if(!empty($currency)) $concatWords .= ' '.$langs->transnoentities('centimes'); |
|
| 133 | - } |
|
| 128 | + // If we need to write cents call again this function for cents |
|
| 129 | + if(!empty($TNum[1])) { |
|
| 130 | + if(!empty($currency)) $concatWords .= ' '.$langs->transnoentities('and'); |
|
| 131 | + $concatWords .= ' '.dol_convertToWord($TNum[1], $langs, $currency, true); |
|
| 132 | + if(!empty($currency)) $concatWords .= ' '.$langs->transnoentities('centimes'); |
|
| 133 | + } |
|
| 134 | 134 | return $concatWords; |
| 135 | 135 | } |
| 136 | 136 | |
@@ -146,85 +146,85 @@ discard block |
||
| 146 | 146 | */ |
| 147 | 147 | function dolNumberToWord($numero, $langs, $numorcurrency='number') |
| 148 | 148 | { |
| 149 | - // If the number is negative convert to positive and return -1 if is too long |
|
| 150 | - if ($numero < 0) $numero *= -1; |
|
| 151 | - if ($numero >= 1000000000001) |
|
| 152 | - return -1; |
|
| 153 | - // Get 2 decimals to cents, another functions round or truncate |
|
| 154 | - $strnumber = number_format ($numero,10); |
|
| 155 | - $len=strlen($strnumber); |
|
| 156 | - for ($i=0; $i<$len; $i++) |
|
| 157 | - { |
|
| 158 | - if ($strnumber[$i]=='.') { |
|
| 159 | - $parte_decimal = $strnumber[$i+1].$strnumber[$i+2]; |
|
| 160 | - break; |
|
| 161 | - } |
|
| 162 | - } |
|
| 149 | + // If the number is negative convert to positive and return -1 if is too long |
|
| 150 | + if ($numero < 0) $numero *= -1; |
|
| 151 | + if ($numero >= 1000000000001) |
|
| 152 | + return -1; |
|
| 153 | + // Get 2 decimals to cents, another functions round or truncate |
|
| 154 | + $strnumber = number_format ($numero,10); |
|
| 155 | + $len=strlen($strnumber); |
|
| 156 | + for ($i=0; $i<$len; $i++) |
|
| 157 | + { |
|
| 158 | + if ($strnumber[$i]=='.') { |
|
| 159 | + $parte_decimal = $strnumber[$i+1].$strnumber[$i+2]; |
|
| 160 | + break; |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | - /*In dolibarr 3.6.2 (my current version) doesn't have $langs->default and |
|
| 164 | + /*In dolibarr 3.6.2 (my current version) doesn't have $langs->default and |
|
| 165 | 165 | in case exist why ask $lang like a parameter?*/ |
| 166 | - if (((is_object($langs) && $langs->default == 'es_MX') || (! is_object($langs) && $langs == 'es_MX')) && $numorcurrency == 'currency') |
|
| 167 | - { |
|
| 168 | - if ($numero>=1 && $numero<2) { |
|
| 169 | - return ("UN PESO ".$parte_decimal." / 100 M.N."); |
|
| 170 | - } |
|
| 171 | - elseif ($numero>=0 && $numero<1){ |
|
| 172 | - return ("CERO PESOS ".$parte_decimal." / 100 M.N."); |
|
| 173 | - } |
|
| 174 | - elseif ($numero>=1000000 && $numero<1000001){ |
|
| 175 | - return ("UN MILLÓN DE PESOS ".$parte_decimal." / 100 M.N."); |
|
| 176 | - } |
|
| 177 | - elseif ($numero>=1000000000000 && $numero<1000000000001){ |
|
| 178 | - return ("UN BILLÓN DE PESOS ".$parte_decimal." / 100 M.N."); |
|
| 179 | - } |
|
| 180 | - else { |
|
| 181 | - $entexto =""; |
|
| 182 | - $number = $numero; |
|
| 183 | - if ($number >= 1000000000){ |
|
| 184 | - $CdMMillon = (int) ($numero / 100000000000); |
|
| 185 | - $numero = $numero - $CdMMillon * 100000000000; |
|
| 186 | - $DdMMillon = (int) ($numero / 10000000000); |
|
| 187 | - $numero = $numero - $DdMMillon * 10000000000; |
|
| 188 | - $UdMMillon = (int) ($numero / 1000000000); |
|
| 189 | - $numero = $numero - $UdMMillon * 1000000000; |
|
| 190 | - $entexto .= hundreds2text ($CdMMillon, $DdMMillon, $UdMMillon); |
|
| 191 | - $entexto .= " MIL "; |
|
| 192 | - } |
|
| 193 | - if ($number >= 1000000){ |
|
| 194 | - $CdMILLON = (int) ($numero / 100000000); |
|
| 195 | - $numero = $numero - $CdMILLON * 100000000; |
|
| 196 | - $DdMILLON = (int) ($numero / 10000000); |
|
| 197 | - $numero = $numero - $DdMILLON * 10000000; |
|
| 198 | - $udMILLON = (int) ($numero / 1000000); |
|
| 199 | - $numero = $numero - $udMILLON * 1000000; |
|
| 200 | - $entexto .= hundreds2text ($CdMILLON, $DdMILLON, $udMILLON); |
|
| 201 | - if (!$CdMMillon && !$DdMMillon && !$UdMMillon && !$CdMILLON && !$DdMILLON && $udMILLON==1) |
|
| 202 | - $entexto .= " MILLÓN "; |
|
| 203 | - else |
|
| 204 | - $entexto .= " MILLONES "; |
|
| 205 | - } |
|
| 206 | - if ($number >= 1000) { |
|
| 207 | - $cdm = (int) ($numero / 100000); |
|
| 208 | - $numero = $numero - $cdm * 100000; |
|
| 209 | - $ddm = (int) ($numero / 10000); |
|
| 210 | - $numero = $numero - $ddm * 10000; |
|
| 211 | - $udm = (int) ($numero / 1000); |
|
| 212 | - $numero = $numero - $udm * 1000; |
|
| 213 | - $entexto .= hundreds2text ($cdm, $ddm, $udm); |
|
| 214 | - if ($cdm || $ddm || $udm) |
|
| 215 | - $entexto .= " MIL "; |
|
| 216 | - } |
|
| 217 | - $c = (int) ($numero / 100); |
|
| 218 | - $numero = $numero - $c * 100; |
|
| 219 | - $d = (int) ($numero / 10); |
|
| 220 | - $u = (int) $numero - $d * 10; |
|
| 221 | - $entexto .= hundreds2text ($c, $d, $u); |
|
| 222 | - if (!$cdm && !$ddm && !$udm && !$c && !$d && !$u && $number>1000000) |
|
| 223 | - $entexto .= " DE"; |
|
| 224 | - $entexto .= " PESOS ".$parte_decimal." / 100 M.N."; |
|
| 225 | - } |
|
| 226 | - return $entexto; |
|
| 227 | - } |
|
| 166 | + if (((is_object($langs) && $langs->default == 'es_MX') || (! is_object($langs) && $langs == 'es_MX')) && $numorcurrency == 'currency') |
|
| 167 | + { |
|
| 168 | + if ($numero>=1 && $numero<2) { |
|
| 169 | + return ("UN PESO ".$parte_decimal." / 100 M.N."); |
|
| 170 | + } |
|
| 171 | + elseif ($numero>=0 && $numero<1){ |
|
| 172 | + return ("CERO PESOS ".$parte_decimal." / 100 M.N."); |
|
| 173 | + } |
|
| 174 | + elseif ($numero>=1000000 && $numero<1000001){ |
|
| 175 | + return ("UN MILLÓN DE PESOS ".$parte_decimal." / 100 M.N."); |
|
| 176 | + } |
|
| 177 | + elseif ($numero>=1000000000000 && $numero<1000000000001){ |
|
| 178 | + return ("UN BILLÓN DE PESOS ".$parte_decimal." / 100 M.N."); |
|
| 179 | + } |
|
| 180 | + else { |
|
| 181 | + $entexto =""; |
|
| 182 | + $number = $numero; |
|
| 183 | + if ($number >= 1000000000){ |
|
| 184 | + $CdMMillon = (int) ($numero / 100000000000); |
|
| 185 | + $numero = $numero - $CdMMillon * 100000000000; |
|
| 186 | + $DdMMillon = (int) ($numero / 10000000000); |
|
| 187 | + $numero = $numero - $DdMMillon * 10000000000; |
|
| 188 | + $UdMMillon = (int) ($numero / 1000000000); |
|
| 189 | + $numero = $numero - $UdMMillon * 1000000000; |
|
| 190 | + $entexto .= hundreds2text ($CdMMillon, $DdMMillon, $UdMMillon); |
|
| 191 | + $entexto .= " MIL "; |
|
| 192 | + } |
|
| 193 | + if ($number >= 1000000){ |
|
| 194 | + $CdMILLON = (int) ($numero / 100000000); |
|
| 195 | + $numero = $numero - $CdMILLON * 100000000; |
|
| 196 | + $DdMILLON = (int) ($numero / 10000000); |
|
| 197 | + $numero = $numero - $DdMILLON * 10000000; |
|
| 198 | + $udMILLON = (int) ($numero / 1000000); |
|
| 199 | + $numero = $numero - $udMILLON * 1000000; |
|
| 200 | + $entexto .= hundreds2text ($CdMILLON, $DdMILLON, $udMILLON); |
|
| 201 | + if (!$CdMMillon && !$DdMMillon && !$UdMMillon && !$CdMILLON && !$DdMILLON && $udMILLON==1) |
|
| 202 | + $entexto .= " MILLÓN "; |
|
| 203 | + else |
|
| 204 | + $entexto .= " MILLONES "; |
|
| 205 | + } |
|
| 206 | + if ($number >= 1000) { |
|
| 207 | + $cdm = (int) ($numero / 100000); |
|
| 208 | + $numero = $numero - $cdm * 100000; |
|
| 209 | + $ddm = (int) ($numero / 10000); |
|
| 210 | + $numero = $numero - $ddm * 10000; |
|
| 211 | + $udm = (int) ($numero / 1000); |
|
| 212 | + $numero = $numero - $udm * 1000; |
|
| 213 | + $entexto .= hundreds2text ($cdm, $ddm, $udm); |
|
| 214 | + if ($cdm || $ddm || $udm) |
|
| 215 | + $entexto .= " MIL "; |
|
| 216 | + } |
|
| 217 | + $c = (int) ($numero / 100); |
|
| 218 | + $numero = $numero - $c * 100; |
|
| 219 | + $d = (int) ($numero / 10); |
|
| 220 | + $u = (int) $numero - $d * 10; |
|
| 221 | + $entexto .= hundreds2text ($c, $d, $u); |
|
| 222 | + if (!$cdm && !$ddm && !$udm && !$c && !$d && !$u && $number>1000000) |
|
| 223 | + $entexto .= " DE"; |
|
| 224 | + $entexto .= " PESOS ".$parte_decimal." / 100 M.N."; |
|
| 225 | + } |
|
| 226 | + return $entexto; |
|
| 227 | + } |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | /** |
@@ -237,40 +237,40 @@ discard block |
||
| 237 | 237 | */ |
| 238 | 238 | function hundreds2text($hundreds, $tens, $units) |
| 239 | 239 | { |
| 240 | - if ($hundreds==1 && $tens==0 && $units==0){ |
|
| 241 | - return "CIEN"; |
|
| 242 | - } |
|
| 243 | - $centenas = array("CIENTO","DOSCIENTOS","TRESCIENTOS","CUATROCIENTOS","QUINIENTOS","SEISCIENTOS","SETECIENTOS","OCHOCIENTOS","NOVECIENTOS"); |
|
| 244 | - $decenas = array("","","TREINTA ","CUARENTA ","CINCUENTA ","SESENTA ","SETENTA ","OCHENTA ","NOVENTA "); |
|
| 245 | - $veintis = array("VEINTE","VEINTIUN","VEINTIDÓS","VEINTITRÉS","VEINTICUATRO","VEINTICINCO","VEINTISÉIS","VEINTISIETE","VEINTIOCHO","VEINTINUEVE"); |
|
| 246 | - $diecis = array("DIEZ","ONCE","DOCE","TRECE","CATORCE","QUINCE","DIECISÉIS","DIECISIETE","DIECIOCHO","DIECINUEVE"); |
|
| 240 | + if ($hundreds==1 && $tens==0 && $units==0){ |
|
| 241 | + return "CIEN"; |
|
| 242 | + } |
|
| 243 | + $centenas = array("CIENTO","DOSCIENTOS","TRESCIENTOS","CUATROCIENTOS","QUINIENTOS","SEISCIENTOS","SETECIENTOS","OCHOCIENTOS","NOVECIENTOS"); |
|
| 244 | + $decenas = array("","","TREINTA ","CUARENTA ","CINCUENTA ","SESENTA ","SETENTA ","OCHENTA ","NOVENTA "); |
|
| 245 | + $veintis = array("VEINTE","VEINTIUN","VEINTIDÓS","VEINTITRÉS","VEINTICUATRO","VEINTICINCO","VEINTISÉIS","VEINTISIETE","VEINTIOCHO","VEINTINUEVE"); |
|
| 246 | + $diecis = array("DIEZ","ONCE","DOCE","TRECE","CATORCE","QUINCE","DIECISÉIS","DIECISIETE","DIECIOCHO","DIECINUEVE"); |
|
| 247 | 247 | $unidades = array("UN","DOS","TRES","CUATRO","CINCO","SEIS","SIETE","OCHO","NUEVE"); |
| 248 | - $entexto = ""; |
|
| 249 | - if ($hundreds!=0){ |
|
| 250 | - $entexto .= $centenas[$hundreds-1]; |
|
| 251 | - } |
|
| 252 | - if ($tens>2){ |
|
| 253 | - if ($hundreds!=0) $entexto .= " "; |
|
| 254 | - $entexto .= $decenas[$tens-1]; |
|
| 255 | - if ($units!=0){ |
|
| 256 | - $entexto .= " Y "; |
|
| 257 | - $entexto .= $unidades[$units-1]; |
|
| 258 | - } |
|
| 259 | - return $entexto; |
|
| 260 | - } |
|
| 261 | - elseif ($tens==2){ |
|
| 262 | - if ($hundreds!=0) $entexto .= " "; |
|
| 263 | - $entexto .= " ".$veintis[$units]; |
|
| 264 | - return $entexto; |
|
| 265 | - } |
|
| 266 | - elseif ($tens==1){ |
|
| 267 | - if ($hundreds!=0) $entexto .= " "; |
|
| 268 | - $entexto .= $diecis[$units]; |
|
| 269 | - return $entexto; |
|
| 270 | - } |
|
| 271 | - if ($units!=0) { |
|
| 272 | - if ($hundreds!=0 || $tens!=0) $entexto .= " "; |
|
| 273 | - $entexto .= $unidades[$units-1]; |
|
| 274 | - } |
|
| 275 | - return $entexto; |
|
| 248 | + $entexto = ""; |
|
| 249 | + if ($hundreds!=0){ |
|
| 250 | + $entexto .= $centenas[$hundreds-1]; |
|
| 251 | + } |
|
| 252 | + if ($tens>2){ |
|
| 253 | + if ($hundreds!=0) $entexto .= " "; |
|
| 254 | + $entexto .= $decenas[$tens-1]; |
|
| 255 | + if ($units!=0){ |
|
| 256 | + $entexto .= " Y "; |
|
| 257 | + $entexto .= $unidades[$units-1]; |
|
| 258 | + } |
|
| 259 | + return $entexto; |
|
| 260 | + } |
|
| 261 | + elseif ($tens==2){ |
|
| 262 | + if ($hundreds!=0) $entexto .= " "; |
|
| 263 | + $entexto .= " ".$veintis[$units]; |
|
| 264 | + return $entexto; |
|
| 265 | + } |
|
| 266 | + elseif ($tens==1){ |
|
| 267 | + if ($hundreds!=0) $entexto .= " "; |
|
| 268 | + $entexto .= $diecis[$units]; |
|
| 269 | + return $entexto; |
|
| 270 | + } |
|
| 271 | + if ($units!=0) { |
|
| 272 | + if ($hundreds!=0 || $tens!=0) $entexto .= " "; |
|
| 273 | + $entexto .= $unidades[$units-1]; |
|
| 274 | + } |
|
| 275 | + return $entexto; |
|
| 276 | 276 | } |
@@ -33,18 +33,18 @@ discard block |
||
| 33 | 33 | * @param boolean $centimes 0=no centimes | 1=centimes to translate |
| 34 | 34 | * @return string Text of the number |
| 35 | 35 | */ |
| 36 | -function dol_convertToWord($num, $langs, $currency=false, $centimes=false) |
|
| 36 | +function dol_convertToWord($num, $langs, $currency = false, $centimes = false) |
|
| 37 | 37 | { |
| 38 | 38 | global $conf; |
| 39 | 39 | |
| 40 | 40 | $num = str_replace(array(',', ' '), '', trim($num)); |
| 41 | - if(! $num) { |
|
| 41 | + if (!$num) { |
|
| 42 | 42 | return false; |
| 43 | 43 | } |
| 44 | - if($centimes && strlen($num) == 1) { |
|
| 45 | - $num = $num*10; |
|
| 44 | + if ($centimes && strlen($num) == 1) { |
|
| 45 | + $num = $num * 10; |
|
| 46 | 46 | } |
| 47 | - $TNum = explode('.',$num); |
|
| 47 | + $TNum = explode('.', $num); |
|
| 48 | 48 | $num = (int) $TNum[0]; |
| 49 | 49 | $words = array(); |
| 50 | 50 | $list1 = array( |
@@ -94,24 +94,24 @@ discard block |
||
| 94 | 94 | $num_length = strlen($num); |
| 95 | 95 | $levels = (int) (($num_length + 2) / 3); |
| 96 | 96 | $max_length = $levels * 3; |
| 97 | - $num = substr('00' . $num, -$max_length); |
|
| 97 | + $num = substr('00'.$num, -$max_length); |
|
| 98 | 98 | $num_levels = str_split($num, 3); |
| 99 | 99 | $nboflevels = count($num_levels); |
| 100 | 100 | for ($i = 0; $i < $nboflevels; $i++) { |
| 101 | 101 | $levels--; |
| 102 | 102 | $hundreds = (int) ($num_levels[$i] / 100); |
| 103 | - $hundreds = ($hundreds ? ' ' . $list1[$hundreds] . ' '.$langs->transnoentities('hundred') . ( $hundreds == 1 ? '' : 's' ) . ' ': ''); |
|
| 103 | + $hundreds = ($hundreds ? ' '.$list1[$hundreds].' '.$langs->transnoentities('hundred').($hundreds == 1 ? '' : 's').' ' : ''); |
|
| 104 | 104 | $tens = (int) ($num_levels[$i] % 100); |
| 105 | 105 | $singles = ''; |
| 106 | - if ( $tens < 20 ) { |
|
| 107 | - $tens = ($tens ? ' ' . $list1[$tens] . ' ' : '' ); |
|
| 106 | + if ($tens < 20) { |
|
| 107 | + $tens = ($tens ? ' '.$list1[$tens].' ' : ''); |
|
| 108 | 108 | } else { |
| 109 | 109 | $tens = (int) ($tens / 10); |
| 110 | - $tens = ' ' . $list2[$tens] . ' '; |
|
| 110 | + $tens = ' '.$list2[$tens].' '; |
|
| 111 | 111 | $singles = (int) ($num_levels[$i] % 10); |
| 112 | - $singles = ' ' . $list1[$singles] . ' '; |
|
| 112 | + $singles = ' '.$list1[$singles].' '; |
|
| 113 | 113 | } |
| 114 | - $words[] = $hundreds . $tens . $singles . ( ( $levels && ( int ) ( $num_levels[$i] ) ) ? ' ' . $list3[$levels] . ' ' : '' ); |
|
| 114 | + $words[] = $hundreds.$tens.$singles.(($levels && (int) ($num_levels[$i])) ? ' '.$list3[$levels].' ' : ''); |
|
| 115 | 115 | } //end for loop |
| 116 | 116 | $commas = count($words); |
| 117 | 117 | if ($commas > 1) { |
@@ -121,15 +121,15 @@ discard block |
||
| 121 | 121 | // Delete multi whitespaces |
| 122 | 122 | $concatWords = trim(preg_replace('/[ ]+/', ' ', $concatWords)); |
| 123 | 123 | |
| 124 | - if(!empty($currency)) { |
|
| 124 | + if (!empty($currency)) { |
|
| 125 | 125 | $concatWords .= ' '.$currency; |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | // If we need to write cents call again this function for cents |
| 129 | - if(!empty($TNum[1])) { |
|
| 130 | - if(!empty($currency)) $concatWords .= ' '.$langs->transnoentities('and'); |
|
| 129 | + if (!empty($TNum[1])) { |
|
| 130 | + if (!empty($currency)) $concatWords .= ' '.$langs->transnoentities('and'); |
|
| 131 | 131 | $concatWords .= ' '.dol_convertToWord($TNum[1], $langs, $currency, true); |
| 132 | - if(!empty($currency)) $concatWords .= ' '.$langs->transnoentities('centimes'); |
|
| 132 | + if (!empty($currency)) $concatWords .= ' '.$langs->transnoentities('centimes'); |
|
| 133 | 133 | } |
| 134 | 134 | return $concatWords; |
| 135 | 135 | } |
@@ -144,61 +144,61 @@ discard block |
||
| 144 | 144 | * @param string $numorcurrency 'number' or 'amount' |
| 145 | 145 | * @return string Text of the number or -1 in case TOO LONG (more than 1000000000000.99) |
| 146 | 146 | */ |
| 147 | -function dolNumberToWord($numero, $langs, $numorcurrency='number') |
|
| 147 | +function dolNumberToWord($numero, $langs, $numorcurrency = 'number') |
|
| 148 | 148 | { |
| 149 | 149 | // If the number is negative convert to positive and return -1 if is too long |
| 150 | 150 | if ($numero < 0) $numero *= -1; |
| 151 | 151 | if ($numero >= 1000000000001) |
| 152 | 152 | return -1; |
| 153 | 153 | // Get 2 decimals to cents, another functions round or truncate |
| 154 | - $strnumber = number_format ($numero,10); |
|
| 155 | - $len=strlen($strnumber); |
|
| 156 | - for ($i=0; $i<$len; $i++) |
|
| 154 | + $strnumber = number_format($numero, 10); |
|
| 155 | + $len = strlen($strnumber); |
|
| 156 | + for ($i = 0; $i < $len; $i++) |
|
| 157 | 157 | { |
| 158 | - if ($strnumber[$i]=='.') { |
|
| 159 | - $parte_decimal = $strnumber[$i+1].$strnumber[$i+2]; |
|
| 158 | + if ($strnumber[$i] == '.') { |
|
| 159 | + $parte_decimal = $strnumber[$i + 1].$strnumber[$i + 2]; |
|
| 160 | 160 | break; |
| 161 | 161 | } |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | /*In dolibarr 3.6.2 (my current version) doesn't have $langs->default and |
| 165 | 165 | in case exist why ask $lang like a parameter?*/ |
| 166 | - if (((is_object($langs) && $langs->default == 'es_MX') || (! is_object($langs) && $langs == 'es_MX')) && $numorcurrency == 'currency') |
|
| 166 | + if (((is_object($langs) && $langs->default == 'es_MX') || (!is_object($langs) && $langs == 'es_MX')) && $numorcurrency == 'currency') |
|
| 167 | 167 | { |
| 168 | - if ($numero>=1 && $numero<2) { |
|
| 168 | + if ($numero >= 1 && $numero < 2) { |
|
| 169 | 169 | return ("UN PESO ".$parte_decimal." / 100 M.N."); |
| 170 | 170 | } |
| 171 | - elseif ($numero>=0 && $numero<1){ |
|
| 171 | + elseif ($numero >= 0 && $numero < 1) { |
|
| 172 | 172 | return ("CERO PESOS ".$parte_decimal." / 100 M.N."); |
| 173 | 173 | } |
| 174 | - elseif ($numero>=1000000 && $numero<1000001){ |
|
| 174 | + elseif ($numero >= 1000000 && $numero < 1000001) { |
|
| 175 | 175 | return ("UN MILLÓN DE PESOS ".$parte_decimal." / 100 M.N."); |
| 176 | 176 | } |
| 177 | - elseif ($numero>=1000000000000 && $numero<1000000000001){ |
|
| 177 | + elseif ($numero >= 1000000000000 && $numero < 1000000000001) { |
|
| 178 | 178 | return ("UN BILLÓN DE PESOS ".$parte_decimal." / 100 M.N."); |
| 179 | 179 | } |
| 180 | 180 | else { |
| 181 | - $entexto =""; |
|
| 181 | + $entexto = ""; |
|
| 182 | 182 | $number = $numero; |
| 183 | - if ($number >= 1000000000){ |
|
| 183 | + if ($number >= 1000000000) { |
|
| 184 | 184 | $CdMMillon = (int) ($numero / 100000000000); |
| 185 | 185 | $numero = $numero - $CdMMillon * 100000000000; |
| 186 | 186 | $DdMMillon = (int) ($numero / 10000000000); |
| 187 | 187 | $numero = $numero - $DdMMillon * 10000000000; |
| 188 | 188 | $UdMMillon = (int) ($numero / 1000000000); |
| 189 | 189 | $numero = $numero - $UdMMillon * 1000000000; |
| 190 | - $entexto .= hundreds2text ($CdMMillon, $DdMMillon, $UdMMillon); |
|
| 190 | + $entexto .= hundreds2text($CdMMillon, $DdMMillon, $UdMMillon); |
|
| 191 | 191 | $entexto .= " MIL "; |
| 192 | 192 | } |
| 193 | - if ($number >= 1000000){ |
|
| 193 | + if ($number >= 1000000) { |
|
| 194 | 194 | $CdMILLON = (int) ($numero / 100000000); |
| 195 | 195 | $numero = $numero - $CdMILLON * 100000000; |
| 196 | 196 | $DdMILLON = (int) ($numero / 10000000); |
| 197 | 197 | $numero = $numero - $DdMILLON * 10000000; |
| 198 | 198 | $udMILLON = (int) ($numero / 1000000); |
| 199 | 199 | $numero = $numero - $udMILLON * 1000000; |
| 200 | - $entexto .= hundreds2text ($CdMILLON, $DdMILLON, $udMILLON); |
|
| 201 | - if (!$CdMMillon && !$DdMMillon && !$UdMMillon && !$CdMILLON && !$DdMILLON && $udMILLON==1) |
|
| 200 | + $entexto .= hundreds2text($CdMILLON, $DdMILLON, $udMILLON); |
|
| 201 | + if (!$CdMMillon && !$DdMMillon && !$UdMMillon && !$CdMILLON && !$DdMILLON && $udMILLON == 1) |
|
| 202 | 202 | $entexto .= " MILLÓN "; |
| 203 | 203 | else |
| 204 | 204 | $entexto .= " MILLONES "; |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | $numero = $numero - $ddm * 10000; |
| 211 | 211 | $udm = (int) ($numero / 1000); |
| 212 | 212 | $numero = $numero - $udm * 1000; |
| 213 | - $entexto .= hundreds2text ($cdm, $ddm, $udm); |
|
| 213 | + $entexto .= hundreds2text($cdm, $ddm, $udm); |
|
| 214 | 214 | if ($cdm || $ddm || $udm) |
| 215 | 215 | $entexto .= " MIL "; |
| 216 | 216 | } |
@@ -218,8 +218,8 @@ discard block |
||
| 218 | 218 | $numero = $numero - $c * 100; |
| 219 | 219 | $d = (int) ($numero / 10); |
| 220 | 220 | $u = (int) $numero - $d * 10; |
| 221 | - $entexto .= hundreds2text ($c, $d, $u); |
|
| 222 | - if (!$cdm && !$ddm && !$udm && !$c && !$d && !$u && $number>1000000) |
|
| 221 | + $entexto .= hundreds2text($c, $d, $u); |
|
| 222 | + if (!$cdm && !$ddm && !$udm && !$c && !$d && !$u && $number > 1000000) |
|
| 223 | 223 | $entexto .= " DE"; |
| 224 | 224 | $entexto .= " PESOS ".$parte_decimal." / 100 M.N."; |
| 225 | 225 | } |
@@ -237,40 +237,40 @@ discard block |
||
| 237 | 237 | */ |
| 238 | 238 | function hundreds2text($hundreds, $tens, $units) |
| 239 | 239 | { |
| 240 | - if ($hundreds==1 && $tens==0 && $units==0){ |
|
| 240 | + if ($hundreds == 1 && $tens == 0 && $units == 0) { |
|
| 241 | 241 | return "CIEN"; |
| 242 | 242 | } |
| 243 | - $centenas = array("CIENTO","DOSCIENTOS","TRESCIENTOS","CUATROCIENTOS","QUINIENTOS","SEISCIENTOS","SETECIENTOS","OCHOCIENTOS","NOVECIENTOS"); |
|
| 244 | - $decenas = array("","","TREINTA ","CUARENTA ","CINCUENTA ","SESENTA ","SETENTA ","OCHENTA ","NOVENTA "); |
|
| 245 | - $veintis = array("VEINTE","VEINTIUN","VEINTIDÓS","VEINTITRÉS","VEINTICUATRO","VEINTICINCO","VEINTISÉIS","VEINTISIETE","VEINTIOCHO","VEINTINUEVE"); |
|
| 246 | - $diecis = array("DIEZ","ONCE","DOCE","TRECE","CATORCE","QUINCE","DIECISÉIS","DIECISIETE","DIECIOCHO","DIECINUEVE"); |
|
| 247 | - $unidades = array("UN","DOS","TRES","CUATRO","CINCO","SEIS","SIETE","OCHO","NUEVE"); |
|
| 243 | + $centenas = array("CIENTO", "DOSCIENTOS", "TRESCIENTOS", "CUATROCIENTOS", "QUINIENTOS", "SEISCIENTOS", "SETECIENTOS", "OCHOCIENTOS", "NOVECIENTOS"); |
|
| 244 | + $decenas = array("", "", "TREINTA ", "CUARENTA ", "CINCUENTA ", "SESENTA ", "SETENTA ", "OCHENTA ", "NOVENTA "); |
|
| 245 | + $veintis = array("VEINTE", "VEINTIUN", "VEINTIDÓS", "VEINTITRÉS", "VEINTICUATRO", "VEINTICINCO", "VEINTISÉIS", "VEINTISIETE", "VEINTIOCHO", "VEINTINUEVE"); |
|
| 246 | + $diecis = array("DIEZ", "ONCE", "DOCE", "TRECE", "CATORCE", "QUINCE", "DIECISÉIS", "DIECISIETE", "DIECIOCHO", "DIECINUEVE"); |
|
| 247 | + $unidades = array("UN", "DOS", "TRES", "CUATRO", "CINCO", "SEIS", "SIETE", "OCHO", "NUEVE"); |
|
| 248 | 248 | $entexto = ""; |
| 249 | - if ($hundreds!=0){ |
|
| 250 | - $entexto .= $centenas[$hundreds-1]; |
|
| 249 | + if ($hundreds != 0) { |
|
| 250 | + $entexto .= $centenas[$hundreds - 1]; |
|
| 251 | 251 | } |
| 252 | - if ($tens>2){ |
|
| 253 | - if ($hundreds!=0) $entexto .= " "; |
|
| 254 | - $entexto .= $decenas[$tens-1]; |
|
| 255 | - if ($units!=0){ |
|
| 252 | + if ($tens > 2) { |
|
| 253 | + if ($hundreds != 0) $entexto .= " "; |
|
| 254 | + $entexto .= $decenas[$tens - 1]; |
|
| 255 | + if ($units != 0) { |
|
| 256 | 256 | $entexto .= " Y "; |
| 257 | - $entexto .= $unidades[$units-1]; |
|
| 257 | + $entexto .= $unidades[$units - 1]; |
|
| 258 | 258 | } |
| 259 | 259 | return $entexto; |
| 260 | 260 | } |
| 261 | - elseif ($tens==2){ |
|
| 262 | - if ($hundreds!=0) $entexto .= " "; |
|
| 261 | + elseif ($tens == 2) { |
|
| 262 | + if ($hundreds != 0) $entexto .= " "; |
|
| 263 | 263 | $entexto .= " ".$veintis[$units]; |
| 264 | 264 | return $entexto; |
| 265 | 265 | } |
| 266 | - elseif ($tens==1){ |
|
| 267 | - if ($hundreds!=0) $entexto .= " "; |
|
| 266 | + elseif ($tens == 1) { |
|
| 267 | + if ($hundreds != 0) $entexto .= " "; |
|
| 268 | 268 | $entexto .= $diecis[$units]; |
| 269 | 269 | return $entexto; |
| 270 | 270 | } |
| 271 | - if ($units!=0) { |
|
| 272 | - if ($hundreds!=0 || $tens!=0) $entexto .= " "; |
|
| 273 | - $entexto .= $unidades[$units-1]; |
|
| 271 | + if ($units != 0) { |
|
| 272 | + if ($hundreds != 0 || $tens != 0) $entexto .= " "; |
|
| 273 | + $entexto .= $unidades[$units - 1]; |
|
| 274 | 274 | } |
| 275 | 275 | return $entexto; |
| 276 | 276 | } |
@@ -127,9 +127,13 @@ discard block |
||
| 127 | 127 | |
| 128 | 128 | // If we need to write cents call again this function for cents |
| 129 | 129 | if(!empty($TNum[1])) { |
| 130 | - if(!empty($currency)) $concatWords .= ' '.$langs->transnoentities('and'); |
|
| 130 | + if(!empty($currency)) { |
|
| 131 | + $concatWords .= ' '.$langs->transnoentities('and'); |
|
| 132 | + } |
|
| 131 | 133 | $concatWords .= ' '.dol_convertToWord($TNum[1], $langs, $currency, true); |
| 132 | - if(!empty($currency)) $concatWords .= ' '.$langs->transnoentities('centimes'); |
|
| 134 | + if(!empty($currency)) { |
|
| 135 | + $concatWords .= ' '.$langs->transnoentities('centimes'); |
|
| 136 | + } |
|
| 133 | 137 | } |
| 134 | 138 | return $concatWords; |
| 135 | 139 | } |
@@ -147,9 +151,12 @@ discard block |
||
| 147 | 151 | function dolNumberToWord($numero, $langs, $numorcurrency='number') |
| 148 | 152 | { |
| 149 | 153 | // If the number is negative convert to positive and return -1 if is too long |
| 150 | - if ($numero < 0) $numero *= -1; |
|
| 151 | - if ($numero >= 1000000000001) |
|
| 152 | - return -1; |
|
| 154 | + if ($numero < 0) { |
|
| 155 | + $numero *= -1; |
|
| 156 | + } |
|
| 157 | + if ($numero >= 1000000000001) { |
|
| 158 | + return -1; |
|
| 159 | + } |
|
| 153 | 160 | // Get 2 decimals to cents, another functions round or truncate |
| 154 | 161 | $strnumber = number_format ($numero,10); |
| 155 | 162 | $len=strlen($strnumber); |
@@ -167,17 +174,13 @@ discard block |
||
| 167 | 174 | { |
| 168 | 175 | if ($numero>=1 && $numero<2) { |
| 169 | 176 | return ("UN PESO ".$parte_decimal." / 100 M.N."); |
| 170 | - } |
|
| 171 | - elseif ($numero>=0 && $numero<1){ |
|
| 177 | + } elseif ($numero>=0 && $numero<1){ |
|
| 172 | 178 | return ("CERO PESOS ".$parte_decimal." / 100 M.N."); |
| 173 | - } |
|
| 174 | - elseif ($numero>=1000000 && $numero<1000001){ |
|
| 179 | + } elseif ($numero>=1000000 && $numero<1000001){ |
|
| 175 | 180 | return ("UN MILLÓN DE PESOS ".$parte_decimal." / 100 M.N."); |
| 176 | - } |
|
| 177 | - elseif ($numero>=1000000000000 && $numero<1000000000001){ |
|
| 181 | + } elseif ($numero>=1000000000000 && $numero<1000000000001){ |
|
| 178 | 182 | return ("UN BILLÓN DE PESOS ".$parte_decimal." / 100 M.N."); |
| 179 | - } |
|
| 180 | - else { |
|
| 183 | + } else { |
|
| 181 | 184 | $entexto =""; |
| 182 | 185 | $number = $numero; |
| 183 | 186 | if ($number >= 1000000000){ |
@@ -198,10 +201,11 @@ discard block |
||
| 198 | 201 | $udMILLON = (int) ($numero / 1000000); |
| 199 | 202 | $numero = $numero - $udMILLON * 1000000; |
| 200 | 203 | $entexto .= hundreds2text ($CdMILLON, $DdMILLON, $udMILLON); |
| 201 | - if (!$CdMMillon && !$DdMMillon && !$UdMMillon && !$CdMILLON && !$DdMILLON && $udMILLON==1) |
|
| 202 | - $entexto .= " MILLÓN "; |
|
| 203 | - else |
|
| 204 | - $entexto .= " MILLONES "; |
|
| 204 | + if (!$CdMMillon && !$DdMMillon && !$UdMMillon && !$CdMILLON && !$DdMILLON && $udMILLON==1) { |
|
| 205 | + $entexto .= " MILLÓN "; |
|
| 206 | + } else { |
|
| 207 | + $entexto .= " MILLONES "; |
|
| 208 | + } |
|
| 205 | 209 | } |
| 206 | 210 | if ($number >= 1000) { |
| 207 | 211 | $cdm = (int) ($numero / 100000); |
@@ -211,16 +215,18 @@ discard block |
||
| 211 | 215 | $udm = (int) ($numero / 1000); |
| 212 | 216 | $numero = $numero - $udm * 1000; |
| 213 | 217 | $entexto .= hundreds2text ($cdm, $ddm, $udm); |
| 214 | - if ($cdm || $ddm || $udm) |
|
| 215 | - $entexto .= " MIL "; |
|
| 218 | + if ($cdm || $ddm || $udm) { |
|
| 219 | + $entexto .= " MIL "; |
|
| 220 | + } |
|
| 216 | 221 | } |
| 217 | 222 | $c = (int) ($numero / 100); |
| 218 | 223 | $numero = $numero - $c * 100; |
| 219 | 224 | $d = (int) ($numero / 10); |
| 220 | 225 | $u = (int) $numero - $d * 10; |
| 221 | 226 | $entexto .= hundreds2text ($c, $d, $u); |
| 222 | - if (!$cdm && !$ddm && !$udm && !$c && !$d && !$u && $number>1000000) |
|
| 223 | - $entexto .= " DE"; |
|
| 227 | + if (!$cdm && !$ddm && !$udm && !$c && !$d && !$u && $number>1000000) { |
|
| 228 | + $entexto .= " DE"; |
|
| 229 | + } |
|
| 224 | 230 | $entexto .= " PESOS ".$parte_decimal." / 100 M.N."; |
| 225 | 231 | } |
| 226 | 232 | return $entexto; |
@@ -250,26 +256,32 @@ discard block |
||
| 250 | 256 | $entexto .= $centenas[$hundreds-1]; |
| 251 | 257 | } |
| 252 | 258 | if ($tens>2){ |
| 253 | - if ($hundreds!=0) $entexto .= " "; |
|
| 259 | + if ($hundreds!=0) { |
|
| 260 | + $entexto .= " "; |
|
| 261 | + } |
|
| 254 | 262 | $entexto .= $decenas[$tens-1]; |
| 255 | 263 | if ($units!=0){ |
| 256 | 264 | $entexto .= " Y "; |
| 257 | 265 | $entexto .= $unidades[$units-1]; |
| 258 | 266 | } |
| 259 | 267 | return $entexto; |
| 260 | - } |
|
| 261 | - elseif ($tens==2){ |
|
| 262 | - if ($hundreds!=0) $entexto .= " "; |
|
| 268 | + } elseif ($tens==2){ |
|
| 269 | + if ($hundreds!=0) { |
|
| 270 | + $entexto .= " "; |
|
| 271 | + } |
|
| 263 | 272 | $entexto .= " ".$veintis[$units]; |
| 264 | 273 | return $entexto; |
| 265 | - } |
|
| 266 | - elseif ($tens==1){ |
|
| 267 | - if ($hundreds!=0) $entexto .= " "; |
|
| 274 | + } elseif ($tens==1){ |
|
| 275 | + if ($hundreds!=0) { |
|
| 276 | + $entexto .= " "; |
|
| 277 | + } |
|
| 268 | 278 | $entexto .= $diecis[$units]; |
| 269 | 279 | return $entexto; |
| 270 | 280 | } |
| 271 | 281 | if ($units!=0) { |
| 272 | - if ($hundreds!=0 || $tens!=0) $entexto .= " "; |
|
| 282 | + if ($hundreds!=0 || $tens!=0) { |
|
| 283 | + $entexto .= " "; |
|
| 284 | + } |
|
| 273 | 285 | $entexto .= $unidades[$units-1]; |
| 274 | 286 | } |
| 275 | 287 | return $entexto; |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | function dol_basename($pathfile) |
| 36 | 36 | { |
| 37 | - return preg_replace('/^.*\/([^\/]+)$/','$1',rtrim($pathfile,'/')); |
|
| 37 | + return preg_replace('/^.*\/([^\/]+)$/','$1',rtrim($pathfile,'/')); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /** |
@@ -58,158 +58,158 @@ discard block |
||
| 58 | 58 | */ |
| 59 | 59 | function dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0) |
| 60 | 60 | { |
| 61 | - global $db, $hookmanager; |
|
| 62 | - global $object; |
|
| 63 | - |
|
| 64 | - dol_syslog("files.lib.php::dol_dir_list path=".$path." types=".$types." recursive=".$recursive." filter=".$filter." excludefilter=".json_encode($excludefilter)); |
|
| 65 | - //print 'xxx'."files.lib.php::dol_dir_list path=".$path." types=".$types." recursive=".$recursive." filter=".$filter." excludefilter=".json_encode($excludefilter); |
|
| 66 | - |
|
| 67 | - $loaddate=($mode==1||$mode==2)?true:false; |
|
| 68 | - $loadsize=($mode==1||$mode==3)?true:false; |
|
| 69 | - |
|
| 70 | - // Clean parameters |
|
| 71 | - $path=preg_replace('/([\\/]+)$/i','',$path); |
|
| 72 | - $newpath=dol_osencode($path); |
|
| 73 | - |
|
| 74 | - $reshook = 0; |
|
| 75 | - $file_list = array(); |
|
| 76 | - |
|
| 77 | - if (is_object($hookmanager) && ! $nohook) |
|
| 78 | - { |
|
| 79 | - $hookmanager->resArray=array(); |
|
| 80 | - |
|
| 81 | - $hookmanager->initHooks(array('fileslib')); |
|
| 82 | - |
|
| 83 | - $parameters=array( |
|
| 84 | - 'path' => $newpath, |
|
| 85 | - 'types'=> $types, |
|
| 86 | - 'recursive' => $recursive, |
|
| 87 | - 'filter' => $filter, |
|
| 88 | - 'excludefilter' => $excludefilter, |
|
| 89 | - 'sortcriteria' => $sortcriteria, |
|
| 90 | - 'sortorder' => $sortorder, |
|
| 91 | - 'loaddate' => $loaddate, |
|
| 92 | - 'loadsize' => $loadsize, |
|
| 93 | - 'mode' => $mode |
|
| 94 | - ); |
|
| 95 | - $reshook=$hookmanager->executeHooks('getDirList', $parameters, $object); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - // $hookmanager->resArray may contain array stacked by other modules |
|
| 99 | - if (empty($reshook)) |
|
| 100 | - { |
|
| 101 | - if (! is_dir($newpath)) return array(); |
|
| 102 | - |
|
| 103 | - if ($dir = opendir($newpath)) |
|
| 104 | - { |
|
| 105 | - $filedate=''; |
|
| 106 | - $filesize=''; |
|
| 107 | - |
|
| 108 | - while (false !== ($file = readdir($dir))) // $file is always a basename (into directory $newpath) |
|
| 109 | - { |
|
| 110 | - if (! utf8_check($file)) $file=utf8_encode($file); // To be sure data is stored in utf8 in memory |
|
| 111 | - $fullpathfile=($newpath?$newpath.'/':'').$file; |
|
| 112 | - |
|
| 113 | - $qualified=1; |
|
| 114 | - |
|
| 115 | - // Define excludefilterarray |
|
| 116 | - $excludefilterarray=array('^\.'); |
|
| 117 | - if (is_array($excludefilter)) |
|
| 118 | - { |
|
| 119 | - $excludefilterarray=array_merge($excludefilterarray,$excludefilter); |
|
| 120 | - } |
|
| 121 | - else if ($excludefilter) $excludefilterarray[]=$excludefilter; |
|
| 122 | - // Check if file is qualified |
|
| 123 | - foreach($excludefilterarray as $filt) |
|
| 124 | - { |
|
| 125 | - if (preg_match('/'.$filt.'/i', $file) || preg_match('/'.$filt.'/i', $fullpathfile)) { |
|
| 126 | - $qualified=0; break; |
|
| 127 | - } |
|
| 128 | - } |
|
| 129 | - //print $fullpathfile.' '.$file.' '.$qualified.'<br>'; |
|
| 130 | - |
|
| 131 | - if ($qualified) |
|
| 132 | - { |
|
| 133 | - $isdir=is_dir(dol_osencode($path."/".$file)); |
|
| 134 | - // Check whether this is a file or directory and whether we're interested in that type |
|
| 135 | - if ($isdir && (($types=="directories") || ($types=="all") || $recursive)) |
|
| 136 | - { |
|
| 137 | - // Add entry into file_list array |
|
| 138 | - if (($types=="directories") || ($types=="all")) |
|
| 139 | - { |
|
| 140 | - if ($loaddate || $sortcriteria == 'date') $filedate=dol_filemtime($path."/".$file); |
|
| 141 | - if ($loadsize || $sortcriteria == 'size') $filesize=dol_filesize($path."/".$file); |
|
| 142 | - |
|
| 143 | - if (! $filter || preg_match('/'.$filter.'/i',$file)) // We do not search key $filter into all $path, only into $file part |
|
| 144 | - { |
|
| 145 | - preg_match('/([^\/]+)\/[^\/]+$/',$path.'/'.$file,$reg); |
|
| 146 | - $level1name=(isset($reg[1])?$reg[1]:''); |
|
| 147 | - $file_list[] = array( |
|
| 148 | - "name" => $file, |
|
| 149 | - "path" => $path, |
|
| 150 | - "level1name" => $level1name, |
|
| 151 | - "relativename" => ($relativename?$relativename.'/':'').$file, |
|
| 152 | - "fullname" => $path.'/'.$file, |
|
| 153 | - "date" => $filedate, |
|
| 154 | - "size" => $filesize, |
|
| 155 | - "type" => 'dir' |
|
| 156 | - ); |
|
| 157 | - } |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - // if we're in a directory and we want recursive behavior, call this function again |
|
| 161 | - if ($recursive) |
|
| 162 | - { |
|
| 163 | - if (empty($donotfollowsymlinks) || ! is_link($path."/".$file)) |
|
| 164 | - { |
|
| 165 | - //var_dump('eee '. $path."/".$file. ' '.is_dir($path."/".$file).' '.is_link($path."/".$file)); |
|
| 166 | - $file_list = array_merge($file_list, dol_dir_list($path."/".$file, $types, $recursive, $filter, $excludefilter, $sortcriteria, $sortorder, $mode, $nohook, ($relativename!=''?$relativename.'/':'').$file, $donotfollowsymlinks)); |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - else if (! $isdir && (($types == "files") || ($types == "all"))) |
|
| 171 | - { |
|
| 172 | - // Add file into file_list array |
|
| 173 | - if ($loaddate || $sortcriteria == 'date') $filedate=dol_filemtime($path."/".$file); |
|
| 174 | - if ($loadsize || $sortcriteria == 'size') $filesize=dol_filesize($path."/".$file); |
|
| 175 | - |
|
| 176 | - if (! $filter || preg_match('/'.$filter.'/i',$file)) // We do not search key $filter into $path, only into $file |
|
| 177 | - { |
|
| 178 | - preg_match('/([^\/]+)\/[^\/]+$/',$path.'/'.$file,$reg); |
|
| 179 | - $level1name=(isset($reg[1])?$reg[1]:''); |
|
| 180 | - $file_list[] = array( |
|
| 181 | - "name" => $file, |
|
| 182 | - "path" => $path, |
|
| 183 | - "level1name" => $level1name, |
|
| 184 | - "relativename" => ($relativename?$relativename.'/':'').$file, |
|
| 185 | - "fullname" => $path.'/'.$file, |
|
| 186 | - "date" => $filedate, |
|
| 187 | - "size" => $filesize, |
|
| 188 | - "type" => 'file' |
|
| 189 | - ); |
|
| 190 | - } |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - } |
|
| 194 | - closedir($dir); |
|
| 195 | - |
|
| 196 | - // Obtain a list of columns |
|
| 197 | - if (! empty($sortcriteria)) |
|
| 198 | - { |
|
| 199 | - $myarray=array(); |
|
| 200 | - foreach ($file_list as $key => $row) |
|
| 201 | - { |
|
| 202 | - $myarray[$key] = (isset($row[$sortcriteria])?$row[$sortcriteria]:''); |
|
| 203 | - } |
|
| 204 | - // Sort the data |
|
| 205 | - if ($sortorder) array_multisort($myarray, $sortorder, $file_list); |
|
| 206 | - } |
|
| 207 | - } |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - if (is_object($hookmanager) && is_array($hookmanager->resArray)) $file_list = array_merge($file_list, $hookmanager->resArray); |
|
| 211 | - |
|
| 212 | - return $file_list; |
|
| 61 | + global $db, $hookmanager; |
|
| 62 | + global $object; |
|
| 63 | + |
|
| 64 | + dol_syslog("files.lib.php::dol_dir_list path=".$path." types=".$types." recursive=".$recursive." filter=".$filter." excludefilter=".json_encode($excludefilter)); |
|
| 65 | + //print 'xxx'."files.lib.php::dol_dir_list path=".$path." types=".$types." recursive=".$recursive." filter=".$filter." excludefilter=".json_encode($excludefilter); |
|
| 66 | + |
|
| 67 | + $loaddate=($mode==1||$mode==2)?true:false; |
|
| 68 | + $loadsize=($mode==1||$mode==3)?true:false; |
|
| 69 | + |
|
| 70 | + // Clean parameters |
|
| 71 | + $path=preg_replace('/([\\/]+)$/i','',$path); |
|
| 72 | + $newpath=dol_osencode($path); |
|
| 73 | + |
|
| 74 | + $reshook = 0; |
|
| 75 | + $file_list = array(); |
|
| 76 | + |
|
| 77 | + if (is_object($hookmanager) && ! $nohook) |
|
| 78 | + { |
|
| 79 | + $hookmanager->resArray=array(); |
|
| 80 | + |
|
| 81 | + $hookmanager->initHooks(array('fileslib')); |
|
| 82 | + |
|
| 83 | + $parameters=array( |
|
| 84 | + 'path' => $newpath, |
|
| 85 | + 'types'=> $types, |
|
| 86 | + 'recursive' => $recursive, |
|
| 87 | + 'filter' => $filter, |
|
| 88 | + 'excludefilter' => $excludefilter, |
|
| 89 | + 'sortcriteria' => $sortcriteria, |
|
| 90 | + 'sortorder' => $sortorder, |
|
| 91 | + 'loaddate' => $loaddate, |
|
| 92 | + 'loadsize' => $loadsize, |
|
| 93 | + 'mode' => $mode |
|
| 94 | + ); |
|
| 95 | + $reshook=$hookmanager->executeHooks('getDirList', $parameters, $object); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + // $hookmanager->resArray may contain array stacked by other modules |
|
| 99 | + if (empty($reshook)) |
|
| 100 | + { |
|
| 101 | + if (! is_dir($newpath)) return array(); |
|
| 102 | + |
|
| 103 | + if ($dir = opendir($newpath)) |
|
| 104 | + { |
|
| 105 | + $filedate=''; |
|
| 106 | + $filesize=''; |
|
| 107 | + |
|
| 108 | + while (false !== ($file = readdir($dir))) // $file is always a basename (into directory $newpath) |
|
| 109 | + { |
|
| 110 | + if (! utf8_check($file)) $file=utf8_encode($file); // To be sure data is stored in utf8 in memory |
|
| 111 | + $fullpathfile=($newpath?$newpath.'/':'').$file; |
|
| 112 | + |
|
| 113 | + $qualified=1; |
|
| 114 | + |
|
| 115 | + // Define excludefilterarray |
|
| 116 | + $excludefilterarray=array('^\.'); |
|
| 117 | + if (is_array($excludefilter)) |
|
| 118 | + { |
|
| 119 | + $excludefilterarray=array_merge($excludefilterarray,$excludefilter); |
|
| 120 | + } |
|
| 121 | + else if ($excludefilter) $excludefilterarray[]=$excludefilter; |
|
| 122 | + // Check if file is qualified |
|
| 123 | + foreach($excludefilterarray as $filt) |
|
| 124 | + { |
|
| 125 | + if (preg_match('/'.$filt.'/i', $file) || preg_match('/'.$filt.'/i', $fullpathfile)) { |
|
| 126 | + $qualified=0; break; |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | + //print $fullpathfile.' '.$file.' '.$qualified.'<br>'; |
|
| 130 | + |
|
| 131 | + if ($qualified) |
|
| 132 | + { |
|
| 133 | + $isdir=is_dir(dol_osencode($path."/".$file)); |
|
| 134 | + // Check whether this is a file or directory and whether we're interested in that type |
|
| 135 | + if ($isdir && (($types=="directories") || ($types=="all") || $recursive)) |
|
| 136 | + { |
|
| 137 | + // Add entry into file_list array |
|
| 138 | + if (($types=="directories") || ($types=="all")) |
|
| 139 | + { |
|
| 140 | + if ($loaddate || $sortcriteria == 'date') $filedate=dol_filemtime($path."/".$file); |
|
| 141 | + if ($loadsize || $sortcriteria == 'size') $filesize=dol_filesize($path."/".$file); |
|
| 142 | + |
|
| 143 | + if (! $filter || preg_match('/'.$filter.'/i',$file)) // We do not search key $filter into all $path, only into $file part |
|
| 144 | + { |
|
| 145 | + preg_match('/([^\/]+)\/[^\/]+$/',$path.'/'.$file,$reg); |
|
| 146 | + $level1name=(isset($reg[1])?$reg[1]:''); |
|
| 147 | + $file_list[] = array( |
|
| 148 | + "name" => $file, |
|
| 149 | + "path" => $path, |
|
| 150 | + "level1name" => $level1name, |
|
| 151 | + "relativename" => ($relativename?$relativename.'/':'').$file, |
|
| 152 | + "fullname" => $path.'/'.$file, |
|
| 153 | + "date" => $filedate, |
|
| 154 | + "size" => $filesize, |
|
| 155 | + "type" => 'dir' |
|
| 156 | + ); |
|
| 157 | + } |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + // if we're in a directory and we want recursive behavior, call this function again |
|
| 161 | + if ($recursive) |
|
| 162 | + { |
|
| 163 | + if (empty($donotfollowsymlinks) || ! is_link($path."/".$file)) |
|
| 164 | + { |
|
| 165 | + //var_dump('eee '. $path."/".$file. ' '.is_dir($path."/".$file).' '.is_link($path."/".$file)); |
|
| 166 | + $file_list = array_merge($file_list, dol_dir_list($path."/".$file, $types, $recursive, $filter, $excludefilter, $sortcriteria, $sortorder, $mode, $nohook, ($relativename!=''?$relativename.'/':'').$file, $donotfollowsymlinks)); |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + else if (! $isdir && (($types == "files") || ($types == "all"))) |
|
| 171 | + { |
|
| 172 | + // Add file into file_list array |
|
| 173 | + if ($loaddate || $sortcriteria == 'date') $filedate=dol_filemtime($path."/".$file); |
|
| 174 | + if ($loadsize || $sortcriteria == 'size') $filesize=dol_filesize($path."/".$file); |
|
| 175 | + |
|
| 176 | + if (! $filter || preg_match('/'.$filter.'/i',$file)) // We do not search key $filter into $path, only into $file |
|
| 177 | + { |
|
| 178 | + preg_match('/([^\/]+)\/[^\/]+$/',$path.'/'.$file,$reg); |
|
| 179 | + $level1name=(isset($reg[1])?$reg[1]:''); |
|
| 180 | + $file_list[] = array( |
|
| 181 | + "name" => $file, |
|
| 182 | + "path" => $path, |
|
| 183 | + "level1name" => $level1name, |
|
| 184 | + "relativename" => ($relativename?$relativename.'/':'').$file, |
|
| 185 | + "fullname" => $path.'/'.$file, |
|
| 186 | + "date" => $filedate, |
|
| 187 | + "size" => $filesize, |
|
| 188 | + "type" => 'file' |
|
| 189 | + ); |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + } |
|
| 194 | + closedir($dir); |
|
| 195 | + |
|
| 196 | + // Obtain a list of columns |
|
| 197 | + if (! empty($sortcriteria)) |
|
| 198 | + { |
|
| 199 | + $myarray=array(); |
|
| 200 | + foreach ($file_list as $key => $row) |
|
| 201 | + { |
|
| 202 | + $myarray[$key] = (isset($row[$sortcriteria])?$row[$sortcriteria]:''); |
|
| 203 | + } |
|
| 204 | + // Sort the data |
|
| 205 | + if ($sortorder) array_multisort($myarray, $sortorder, $file_list); |
|
| 206 | + } |
|
| 207 | + } |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + if (is_object($hookmanager) && is_array($hookmanager->resArray)) $file_list = array_merge($file_list, $hookmanager->resArray); |
|
| 211 | + |
|
| 212 | + return $file_list; |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | |
@@ -228,68 +228,68 @@ discard block |
||
| 228 | 228 | */ |
| 229 | 229 | function dol_dir_list_in_database($path, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0) |
| 230 | 230 | { |
| 231 | - global $conf, $db; |
|
| 232 | - |
|
| 233 | - $sql =" SELECT rowid, label, entity, filename, filepath, fullpath_orig, keywords, cover, gen_or_uploaded, extraparams, date_c, date_m, fk_user_c, fk_user_m,"; |
|
| 234 | - $sql.=" acl, position, share"; |
|
| 235 | - if ($mode) $sql.=", description"; |
|
| 236 | - $sql.=" FROM ".MAIN_DB_PREFIX."ecm_files"; |
|
| 237 | - $sql.=" WHERE filepath = '".$db->escape($path)."'"; |
|
| 238 | - $sql.=" AND entity = ".$conf->entity; |
|
| 239 | - |
|
| 240 | - $resql = $db->query($sql); |
|
| 241 | - if ($resql) |
|
| 242 | - { |
|
| 243 | - $file_list=array(); |
|
| 244 | - $num = $db->num_rows($resql); |
|
| 245 | - $i = 0; |
|
| 246 | - while ($i < $num) |
|
| 247 | - { |
|
| 248 | - $obj = $db->fetch_object($resql); |
|
| 249 | - if ($obj) |
|
| 250 | - { |
|
| 251 | - preg_match('/([^\/]+)\/[^\/]+$/',DOL_DATA_ROOT.'/'.$obj->filepath.'/'.$obj->filename,$reg); |
|
| 252 | - $level1name=(isset($reg[1])?$reg[1]:''); |
|
| 253 | - $file_list[] = array( |
|
| 254 | - "rowid" => $obj->rowid, |
|
| 255 | - "label" => $obj->label, // md5 |
|
| 256 | - "name" => $obj->filename, |
|
| 257 | - "path" => DOL_DATA_ROOT.'/'.$obj->filepath, |
|
| 258 | - "level1name" => $level1name, |
|
| 259 | - "fullname" => DOL_DATA_ROOT.'/'.$obj->filepath.'/'.$obj->filename, |
|
| 260 | - "fullpath_orig" => $obj->fullpath_orig, |
|
| 261 | - "date_c" => $db->jdate($obj->date_c), |
|
| 262 | - "date_m" => $db->jdate($obj->date_m), |
|
| 263 | - "type" => 'file', |
|
| 264 | - "keywords" => $obj->keywords, |
|
| 265 | - "cover" => $obj->cover, |
|
| 266 | - "position" => (int) $obj->position, |
|
| 267 | - "acl" => $obj->acl, |
|
| 268 | - "share" => $obj->share |
|
| 269 | - ); |
|
| 270 | - } |
|
| 271 | - $i++; |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - // Obtain a list of columns |
|
| 275 | - if (! empty($sortcriteria)) |
|
| 276 | - { |
|
| 277 | - $myarray=array(); |
|
| 278 | - foreach ($file_list as $key => $row) |
|
| 279 | - { |
|
| 280 | - $myarray[$key] = (isset($row[$sortcriteria])?$row[$sortcriteria]:''); |
|
| 281 | - } |
|
| 282 | - // Sort the data |
|
| 283 | - if ($sortorder) array_multisort($myarray, $sortorder, $file_list); |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - return $file_list; |
|
| 287 | - } |
|
| 288 | - else |
|
| 289 | - { |
|
| 290 | - dol_print_error($db); |
|
| 291 | - return array(); |
|
| 292 | - } |
|
| 231 | + global $conf, $db; |
|
| 232 | + |
|
| 233 | + $sql =" SELECT rowid, label, entity, filename, filepath, fullpath_orig, keywords, cover, gen_or_uploaded, extraparams, date_c, date_m, fk_user_c, fk_user_m,"; |
|
| 234 | + $sql.=" acl, position, share"; |
|
| 235 | + if ($mode) $sql.=", description"; |
|
| 236 | + $sql.=" FROM ".MAIN_DB_PREFIX."ecm_files"; |
|
| 237 | + $sql.=" WHERE filepath = '".$db->escape($path)."'"; |
|
| 238 | + $sql.=" AND entity = ".$conf->entity; |
|
| 239 | + |
|
| 240 | + $resql = $db->query($sql); |
|
| 241 | + if ($resql) |
|
| 242 | + { |
|
| 243 | + $file_list=array(); |
|
| 244 | + $num = $db->num_rows($resql); |
|
| 245 | + $i = 0; |
|
| 246 | + while ($i < $num) |
|
| 247 | + { |
|
| 248 | + $obj = $db->fetch_object($resql); |
|
| 249 | + if ($obj) |
|
| 250 | + { |
|
| 251 | + preg_match('/([^\/]+)\/[^\/]+$/',DOL_DATA_ROOT.'/'.$obj->filepath.'/'.$obj->filename,$reg); |
|
| 252 | + $level1name=(isset($reg[1])?$reg[1]:''); |
|
| 253 | + $file_list[] = array( |
|
| 254 | + "rowid" => $obj->rowid, |
|
| 255 | + "label" => $obj->label, // md5 |
|
| 256 | + "name" => $obj->filename, |
|
| 257 | + "path" => DOL_DATA_ROOT.'/'.$obj->filepath, |
|
| 258 | + "level1name" => $level1name, |
|
| 259 | + "fullname" => DOL_DATA_ROOT.'/'.$obj->filepath.'/'.$obj->filename, |
|
| 260 | + "fullpath_orig" => $obj->fullpath_orig, |
|
| 261 | + "date_c" => $db->jdate($obj->date_c), |
|
| 262 | + "date_m" => $db->jdate($obj->date_m), |
|
| 263 | + "type" => 'file', |
|
| 264 | + "keywords" => $obj->keywords, |
|
| 265 | + "cover" => $obj->cover, |
|
| 266 | + "position" => (int) $obj->position, |
|
| 267 | + "acl" => $obj->acl, |
|
| 268 | + "share" => $obj->share |
|
| 269 | + ); |
|
| 270 | + } |
|
| 271 | + $i++; |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + // Obtain a list of columns |
|
| 275 | + if (! empty($sortcriteria)) |
|
| 276 | + { |
|
| 277 | + $myarray=array(); |
|
| 278 | + foreach ($file_list as $key => $row) |
|
| 279 | + { |
|
| 280 | + $myarray[$key] = (isset($row[$sortcriteria])?$row[$sortcriteria]:''); |
|
| 281 | + } |
|
| 282 | + // Sort the data |
|
| 283 | + if ($sortorder) array_multisort($myarray, $sortorder, $file_list); |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + return $file_list; |
|
| 287 | + } |
|
| 288 | + else |
|
| 289 | + { |
|
| 290 | + dol_print_error($db); |
|
| 291 | + return array(); |
|
| 292 | + } |
|
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | |
@@ -303,94 +303,94 @@ discard block |
||
| 303 | 303 | */ |
| 304 | 304 | function completeFileArrayWithDatabaseInfo(&$filearray, $relativedir) |
| 305 | 305 | { |
| 306 | - global $conf, $db, $user; |
|
| 307 | - |
|
| 308 | - $filearrayindatabase = dol_dir_list_in_database($relativedir, '', null, 'name', SORT_ASC); |
|
| 309 | - |
|
| 310 | - // TODO Remove this when PRODUCT_USE_OLD_PATH_FOR_PHOTO will be removed |
|
| 311 | - global $modulepart; |
|
| 312 | - if ($modulepart == 'produit' && ! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) { |
|
| 313 | - global $object; |
|
| 314 | - if (! empty($object->id)) |
|
| 315 | - { |
|
| 316 | - if (! empty($conf->product->enabled)) $upload_dirold = $conf->product->multidir_output[$object->entity].'/'.substr(substr("000".$object->id, -2),1,1).'/'.substr(substr("000".$object->id, -2),0,1).'/'.$object->id."/photos"; |
|
| 317 | - else $upload_dirold = $conf->service->multidir_output[$object->entity].'/'.substr(substr("000".$object->id, -2),1,1).'/'.substr(substr("000".$object->id, -2),0,1).'/'.$object->id."/photos"; |
|
| 318 | - |
|
| 319 | - $relativedirold = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $upload_dirold); |
|
| 320 | - $relativedirold = preg_replace('/^[\\/]/','',$relativedirold); |
|
| 321 | - |
|
| 322 | - $filearrayindatabase = array_merge($filearrayindatabase, dol_dir_list_in_database($relativedirold, '', null, 'name', SORT_ASC)); |
|
| 323 | - } |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - //var_dump($filearray); |
|
| 327 | - //var_dump($filearrayindatabase); |
|
| 328 | - |
|
| 329 | - // Complete filearray with properties found into $filearrayindatabase |
|
| 330 | - foreach($filearray as $key => $val) |
|
| 331 | - { |
|
| 332 | - $found=0; |
|
| 333 | - // Search if it exists into $filearrayindatabase |
|
| 334 | - foreach($filearrayindatabase as $key2 => $val2) |
|
| 335 | - { |
|
| 336 | - if ($filearrayindatabase[$key2]['name'] == $filearray[$key]['name']) |
|
| 337 | - { |
|
| 338 | - $filearray[$key]['position_name']=($filearrayindatabase[$key2]['position']?$filearrayindatabase[$key2]['position']:'0').'_'.$filearrayindatabase[$key2]['name']; |
|
| 339 | - $filearray[$key]['position']=$filearrayindatabase[$key2]['position']; |
|
| 340 | - $filearray[$key]['cover']=$filearrayindatabase[$key2]['cover']; |
|
| 341 | - $filearray[$key]['acl']=$filearrayindatabase[$key2]['acl']; |
|
| 342 | - $filearray[$key]['rowid']=$filearrayindatabase[$key2]['rowid']; |
|
| 343 | - $filearray[$key]['label']=$filearrayindatabase[$key2]['label']; |
|
| 344 | - $filearray[$key]['share']=$filearrayindatabase[$key2]['share']; |
|
| 345 | - $found=1; |
|
| 346 | - break; |
|
| 347 | - } |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - if (! $found) // This happen in transition toward version 6, or if files were added manually into os dir. |
|
| 351 | - { |
|
| 352 | - $filearray[$key]['position']='999999'; // File not indexed are at end. So if we add a file, it will not replace an existing position |
|
| 353 | - $filearray[$key]['cover']=0; |
|
| 354 | - $filearray[$key]['acl']=''; |
|
| 355 | - |
|
| 356 | - $rel_filename = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $filearray[$key]['fullname']); |
|
| 357 | - if (! preg_match('/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filetorenameafter)) // If not a tmp file |
|
| 358 | - { |
|
| 359 | - dol_syslog("list_of_documents We found a file called '".$filearray[$key]['name']."' not indexed into database. We add it"); |
|
| 360 | - include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; |
|
| 361 | - $ecmfile=new EcmFiles($db); |
|
| 362 | - |
|
| 363 | - // Add entry into database |
|
| 364 | - $filename = basename($rel_filename); |
|
| 365 | - $rel_dir = dirname($rel_filename); |
|
| 366 | - $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir); |
|
| 367 | - $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir); |
|
| 368 | - |
|
| 369 | - $ecmfile->filepath = $rel_dir; |
|
| 370 | - $ecmfile->filename = $filename; |
|
| 371 | - $ecmfile->label = md5_file(dol_osencode($filearray[$key]['fullname'])); // $destfile is a full path to file |
|
| 372 | - $ecmfile->fullpath_orig = $filearray[$key]['fullname']; |
|
| 373 | - $ecmfile->gen_or_uploaded = 'unknown'; |
|
| 374 | - $ecmfile->description = ''; // indexed content |
|
| 375 | - $ecmfile->keyword = ''; // keyword content |
|
| 376 | - $result = $ecmfile->create($user); |
|
| 377 | - if ($result < 0) |
|
| 378 | - { |
|
| 379 | - setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings'); |
|
| 380 | - } |
|
| 381 | - else |
|
| 382 | - { |
|
| 383 | - $filearray[$key]['rowid']=$result; |
|
| 384 | - } |
|
| 385 | - } |
|
| 386 | - else |
|
| 387 | - { |
|
| 388 | - $filearray[$key]['rowid']=0; // Should not happened |
|
| 389 | - } |
|
| 390 | - } |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - /*var_dump($filearray);*/ |
|
| 306 | + global $conf, $db, $user; |
|
| 307 | + |
|
| 308 | + $filearrayindatabase = dol_dir_list_in_database($relativedir, '', null, 'name', SORT_ASC); |
|
| 309 | + |
|
| 310 | + // TODO Remove this when PRODUCT_USE_OLD_PATH_FOR_PHOTO will be removed |
|
| 311 | + global $modulepart; |
|
| 312 | + if ($modulepart == 'produit' && ! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) { |
|
| 313 | + global $object; |
|
| 314 | + if (! empty($object->id)) |
|
| 315 | + { |
|
| 316 | + if (! empty($conf->product->enabled)) $upload_dirold = $conf->product->multidir_output[$object->entity].'/'.substr(substr("000".$object->id, -2),1,1).'/'.substr(substr("000".$object->id, -2),0,1).'/'.$object->id."/photos"; |
|
| 317 | + else $upload_dirold = $conf->service->multidir_output[$object->entity].'/'.substr(substr("000".$object->id, -2),1,1).'/'.substr(substr("000".$object->id, -2),0,1).'/'.$object->id."/photos"; |
|
| 318 | + |
|
| 319 | + $relativedirold = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $upload_dirold); |
|
| 320 | + $relativedirold = preg_replace('/^[\\/]/','',$relativedirold); |
|
| 321 | + |
|
| 322 | + $filearrayindatabase = array_merge($filearrayindatabase, dol_dir_list_in_database($relativedirold, '', null, 'name', SORT_ASC)); |
|
| 323 | + } |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + //var_dump($filearray); |
|
| 327 | + //var_dump($filearrayindatabase); |
|
| 328 | + |
|
| 329 | + // Complete filearray with properties found into $filearrayindatabase |
|
| 330 | + foreach($filearray as $key => $val) |
|
| 331 | + { |
|
| 332 | + $found=0; |
|
| 333 | + // Search if it exists into $filearrayindatabase |
|
| 334 | + foreach($filearrayindatabase as $key2 => $val2) |
|
| 335 | + { |
|
| 336 | + if ($filearrayindatabase[$key2]['name'] == $filearray[$key]['name']) |
|
| 337 | + { |
|
| 338 | + $filearray[$key]['position_name']=($filearrayindatabase[$key2]['position']?$filearrayindatabase[$key2]['position']:'0').'_'.$filearrayindatabase[$key2]['name']; |
|
| 339 | + $filearray[$key]['position']=$filearrayindatabase[$key2]['position']; |
|
| 340 | + $filearray[$key]['cover']=$filearrayindatabase[$key2]['cover']; |
|
| 341 | + $filearray[$key]['acl']=$filearrayindatabase[$key2]['acl']; |
|
| 342 | + $filearray[$key]['rowid']=$filearrayindatabase[$key2]['rowid']; |
|
| 343 | + $filearray[$key]['label']=$filearrayindatabase[$key2]['label']; |
|
| 344 | + $filearray[$key]['share']=$filearrayindatabase[$key2]['share']; |
|
| 345 | + $found=1; |
|
| 346 | + break; |
|
| 347 | + } |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + if (! $found) // This happen in transition toward version 6, or if files were added manually into os dir. |
|
| 351 | + { |
|
| 352 | + $filearray[$key]['position']='999999'; // File not indexed are at end. So if we add a file, it will not replace an existing position |
|
| 353 | + $filearray[$key]['cover']=0; |
|
| 354 | + $filearray[$key]['acl']=''; |
|
| 355 | + |
|
| 356 | + $rel_filename = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $filearray[$key]['fullname']); |
|
| 357 | + if (! preg_match('/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filetorenameafter)) // If not a tmp file |
|
| 358 | + { |
|
| 359 | + dol_syslog("list_of_documents We found a file called '".$filearray[$key]['name']."' not indexed into database. We add it"); |
|
| 360 | + include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; |
|
| 361 | + $ecmfile=new EcmFiles($db); |
|
| 362 | + |
|
| 363 | + // Add entry into database |
|
| 364 | + $filename = basename($rel_filename); |
|
| 365 | + $rel_dir = dirname($rel_filename); |
|
| 366 | + $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir); |
|
| 367 | + $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir); |
|
| 368 | + |
|
| 369 | + $ecmfile->filepath = $rel_dir; |
|
| 370 | + $ecmfile->filename = $filename; |
|
| 371 | + $ecmfile->label = md5_file(dol_osencode($filearray[$key]['fullname'])); // $destfile is a full path to file |
|
| 372 | + $ecmfile->fullpath_orig = $filearray[$key]['fullname']; |
|
| 373 | + $ecmfile->gen_or_uploaded = 'unknown'; |
|
| 374 | + $ecmfile->description = ''; // indexed content |
|
| 375 | + $ecmfile->keyword = ''; // keyword content |
|
| 376 | + $result = $ecmfile->create($user); |
|
| 377 | + if ($result < 0) |
|
| 378 | + { |
|
| 379 | + setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings'); |
|
| 380 | + } |
|
| 381 | + else |
|
| 382 | + { |
|
| 383 | + $filearray[$key]['rowid']=$result; |
|
| 384 | + } |
|
| 385 | + } |
|
| 386 | + else |
|
| 387 | + { |
|
| 388 | + $filearray[$key]['rowid']=0; // Should not happened |
|
| 389 | + } |
|
| 390 | + } |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + /*var_dump($filearray);*/ |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | |
@@ -403,29 +403,29 @@ discard block |
||
| 403 | 403 | */ |
| 404 | 404 | function dol_compare_file($a, $b) |
| 405 | 405 | { |
| 406 | - global $sortorder; |
|
| 407 | - global $sortfield; |
|
| 408 | - |
|
| 409 | - $sortorder=strtoupper($sortorder); |
|
| 410 | - |
|
| 411 | - if ($sortorder == 'ASC') { $retup=-1; $retdown=1; } |
|
| 412 | - else { $retup=1; $retdown=-1; } |
|
| 413 | - |
|
| 414 | - if ($sortfield == 'name') |
|
| 415 | - { |
|
| 416 | - if ($a->name == $b->name) return 0; |
|
| 417 | - return ($a->name < $b->name) ? $retup : $retdown; |
|
| 418 | - } |
|
| 419 | - if ($sortfield == 'date') |
|
| 420 | - { |
|
| 421 | - if ($a->date == $b->date) return 0; |
|
| 422 | - return ($a->date < $b->date) ? $retup : $retdown; |
|
| 423 | - } |
|
| 424 | - if ($sortfield == 'size') |
|
| 425 | - { |
|
| 426 | - if ($a->size == $b->size) return 0; |
|
| 427 | - return ($a->size < $b->size) ? $retup : $retdown; |
|
| 428 | - } |
|
| 406 | + global $sortorder; |
|
| 407 | + global $sortfield; |
|
| 408 | + |
|
| 409 | + $sortorder=strtoupper($sortorder); |
|
| 410 | + |
|
| 411 | + if ($sortorder == 'ASC') { $retup=-1; $retdown=1; } |
|
| 412 | + else { $retup=1; $retdown=-1; } |
|
| 413 | + |
|
| 414 | + if ($sortfield == 'name') |
|
| 415 | + { |
|
| 416 | + if ($a->name == $b->name) return 0; |
|
| 417 | + return ($a->name < $b->name) ? $retup : $retdown; |
|
| 418 | + } |
|
| 419 | + if ($sortfield == 'date') |
|
| 420 | + { |
|
| 421 | + if ($a->date == $b->date) return 0; |
|
| 422 | + return ($a->date < $b->date) ? $retup : $retdown; |
|
| 423 | + } |
|
| 424 | + if ($sortfield == 'size') |
|
| 425 | + { |
|
| 426 | + if ($a->size == $b->size) return 0; |
|
| 427 | + return ($a->size < $b->size) ? $retup : $retdown; |
|
| 428 | + } |
|
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | |
@@ -437,9 +437,9 @@ discard block |
||
| 437 | 437 | */ |
| 438 | 438 | function dol_is_dir($folder) |
| 439 | 439 | { |
| 440 | - $newfolder=dol_osencode($folder); |
|
| 441 | - if (is_dir($newfolder)) return true; |
|
| 442 | - else return false; |
|
| 440 | + $newfolder=dol_osencode($folder); |
|
| 441 | + if (is_dir($newfolder)) return true; |
|
| 442 | + else return false; |
|
| 443 | 443 | } |
| 444 | 444 | |
| 445 | 445 | /** |
@@ -450,8 +450,8 @@ discard block |
||
| 450 | 450 | */ |
| 451 | 451 | function dol_is_file($pathoffile) |
| 452 | 452 | { |
| 453 | - $newpathoffile=dol_osencode($pathoffile); |
|
| 454 | - return is_file($newpathoffile); |
|
| 453 | + $newpathoffile=dol_osencode($pathoffile); |
|
| 454 | + return is_file($newpathoffile); |
|
| 455 | 455 | } |
| 456 | 456 | |
| 457 | 457 | /** |
@@ -462,8 +462,8 @@ discard block |
||
| 462 | 462 | */ |
| 463 | 463 | function dol_is_link($pathoffile) |
| 464 | 464 | { |
| 465 | - $newpathoffile=dol_osencode($pathoffile); |
|
| 466 | - return is_link($newpathoffile); |
|
| 465 | + $newpathoffile=dol_osencode($pathoffile); |
|
| 466 | + return is_link($newpathoffile); |
|
| 467 | 467 | } |
| 468 | 468 | |
| 469 | 469 | /** |
@@ -474,12 +474,12 @@ discard block |
||
| 474 | 474 | */ |
| 475 | 475 | function dol_is_url($url) |
| 476 | 476 | { |
| 477 | - $tmpprot=array('file','http','https','ftp','zlib','data','ssh','ssh2','ogg','expect'); |
|
| 478 | - foreach($tmpprot as $prot) |
|
| 479 | - { |
|
| 480 | - if (preg_match('/^'.$prot.':/i',$url)) return true; |
|
| 481 | - } |
|
| 482 | - return false; |
|
| 477 | + $tmpprot=array('file','http','https','ftp','zlib','data','ssh','ssh2','ogg','expect'); |
|
| 478 | + foreach($tmpprot as $prot) |
|
| 479 | + { |
|
| 480 | + if (preg_match('/^'.$prot.':/i',$url)) return true; |
|
| 481 | + } |
|
| 482 | + return false; |
|
| 483 | 483 | } |
| 484 | 484 | |
| 485 | 485 | /** |
@@ -490,24 +490,24 @@ discard block |
||
| 490 | 490 | */ |
| 491 | 491 | function dol_dir_is_emtpy($folder) |
| 492 | 492 | { |
| 493 | - $newfolder=dol_osencode($folder); |
|
| 494 | - if (is_dir($newfolder)) |
|
| 495 | - { |
|
| 496 | - $handle = opendir($newfolder); |
|
| 497 | - $folder_content = ''; |
|
| 498 | - while ((gettype($name = readdir($handle)) != "boolean")) |
|
| 499 | - { |
|
| 500 | - $name_array[] = $name; |
|
| 501 | - } |
|
| 502 | - foreach($name_array as $temp) $folder_content .= $temp; |
|
| 503 | - |
|
| 504 | - closedir($handle); |
|
| 505 | - |
|
| 506 | - if ($folder_content == "...") return true; |
|
| 507 | - else return false; |
|
| 508 | - } |
|
| 509 | - else |
|
| 510 | - return true; // Dir does not exists |
|
| 493 | + $newfolder=dol_osencode($folder); |
|
| 494 | + if (is_dir($newfolder)) |
|
| 495 | + { |
|
| 496 | + $handle = opendir($newfolder); |
|
| 497 | + $folder_content = ''; |
|
| 498 | + while ((gettype($name = readdir($handle)) != "boolean")) |
|
| 499 | + { |
|
| 500 | + $name_array[] = $name; |
|
| 501 | + } |
|
| 502 | + foreach($name_array as $temp) $folder_content .= $temp; |
|
| 503 | + |
|
| 504 | + closedir($handle); |
|
| 505 | + |
|
| 506 | + if ($folder_content == "...") return true; |
|
| 507 | + else return false; |
|
| 508 | + } |
|
| 509 | + else |
|
| 510 | + return true; // Dir does not exists |
|
| 511 | 511 | } |
| 512 | 512 | |
| 513 | 513 | /** |
@@ -519,27 +519,27 @@ discard block |
||
| 519 | 519 | */ |
| 520 | 520 | function dol_count_nb_of_line($file) |
| 521 | 521 | { |
| 522 | - $nb=0; |
|
| 523 | - |
|
| 524 | - $newfile=dol_osencode($file); |
|
| 525 | - //print 'x'.$file; |
|
| 526 | - $fp=fopen($newfile,'r'); |
|
| 527 | - if ($fp) |
|
| 528 | - { |
|
| 529 | - while (!feof($fp)) |
|
| 530 | - { |
|
| 531 | - $line=fgets($fp); |
|
| 532 | - // We increase count only if read was success. We need test because feof return true only after fgets so we do n+1 fgets for a file with n lines. |
|
| 533 | - if (! $line === false) $nb++; |
|
| 534 | - } |
|
| 535 | - fclose($fp); |
|
| 536 | - } |
|
| 537 | - else |
|
| 538 | - { |
|
| 539 | - $nb=-1; |
|
| 540 | - } |
|
| 541 | - |
|
| 542 | - return $nb; |
|
| 522 | + $nb=0; |
|
| 523 | + |
|
| 524 | + $newfile=dol_osencode($file); |
|
| 525 | + //print 'x'.$file; |
|
| 526 | + $fp=fopen($newfile,'r'); |
|
| 527 | + if ($fp) |
|
| 528 | + { |
|
| 529 | + while (!feof($fp)) |
|
| 530 | + { |
|
| 531 | + $line=fgets($fp); |
|
| 532 | + // We increase count only if read was success. We need test because feof return true only after fgets so we do n+1 fgets for a file with n lines. |
|
| 533 | + if (! $line === false) $nb++; |
|
| 534 | + } |
|
| 535 | + fclose($fp); |
|
| 536 | + } |
|
| 537 | + else |
|
| 538 | + { |
|
| 539 | + $nb=-1; |
|
| 540 | + } |
|
| 541 | + |
|
| 542 | + return $nb; |
|
| 543 | 543 | } |
| 544 | 544 | |
| 545 | 545 | |
@@ -551,8 +551,8 @@ discard block |
||
| 551 | 551 | */ |
| 552 | 552 | function dol_filesize($pathoffile) |
| 553 | 553 | { |
| 554 | - $newpathoffile=dol_osencode($pathoffile); |
|
| 555 | - return filesize($newpathoffile); |
|
| 554 | + $newpathoffile=dol_osencode($pathoffile); |
|
| 555 | + return filesize($newpathoffile); |
|
| 556 | 556 | } |
| 557 | 557 | |
| 558 | 558 | /** |
@@ -563,8 +563,8 @@ discard block |
||
| 563 | 563 | */ |
| 564 | 564 | function dol_filemtime($pathoffile) |
| 565 | 565 | { |
| 566 | - $newpathoffile=dol_osencode($pathoffile); |
|
| 567 | - return @filemtime($newpathoffile); // @Is to avoid errors if files does not exists |
|
| 566 | + $newpathoffile=dol_osencode($pathoffile); |
|
| 567 | + return @filemtime($newpathoffile); // @Is to avoid errors if files does not exists |
|
| 568 | 568 | } |
| 569 | 569 | |
| 570 | 570 | /** |
@@ -580,61 +580,61 @@ discard block |
||
| 580 | 580 | */ |
| 581 | 581 | function dolReplaceInFile($srcfile, $arrayreplacement, $destfile='', $newmask=0, $indexdatabase=0) |
| 582 | 582 | { |
| 583 | - global $conf; |
|
| 583 | + global $conf; |
|
| 584 | 584 | |
| 585 | - dol_syslog("files.lib.php::dolReplaceInFile srcfile=".$srcfile." destfile=".$destfile." newmask=".$newmask." indexdatabase=".$indexdatabase); |
|
| 585 | + dol_syslog("files.lib.php::dolReplaceInFile srcfile=".$srcfile." destfile=".$destfile." newmask=".$newmask." indexdatabase=".$indexdatabase); |
|
| 586 | 586 | |
| 587 | - if (empty($srcfile)) return -1; |
|
| 588 | - if (empty($destfile)) $destfile=$srcfile; |
|
| 587 | + if (empty($srcfile)) return -1; |
|
| 588 | + if (empty($destfile)) $destfile=$srcfile; |
|
| 589 | 589 | |
| 590 | - $destexists=dol_is_file($destfile); |
|
| 591 | - if (($destfile != $srcfile) && $destexists) return 0; |
|
| 590 | + $destexists=dol_is_file($destfile); |
|
| 591 | + if (($destfile != $srcfile) && $destexists) return 0; |
|
| 592 | 592 | |
| 593 | - $tmpdestfile=$destfile.'.tmp'; |
|
| 593 | + $tmpdestfile=$destfile.'.tmp'; |
|
| 594 | 594 | |
| 595 | - $newpathofsrcfile=dol_osencode($srcfile); |
|
| 596 | - $newpathoftmpdestfile=dol_osencode($tmpdestfile); |
|
| 597 | - $newpathofdestfile=dol_osencode($destfile); |
|
| 598 | - $newdirdestfile=dirname($newpathofdestfile); |
|
| 595 | + $newpathofsrcfile=dol_osencode($srcfile); |
|
| 596 | + $newpathoftmpdestfile=dol_osencode($tmpdestfile); |
|
| 597 | + $newpathofdestfile=dol_osencode($destfile); |
|
| 598 | + $newdirdestfile=dirname($newpathofdestfile); |
|
| 599 | 599 | |
| 600 | - if ($destexists && ! is_writable($newpathofdestfile)) |
|
| 601 | - { |
|
| 602 | - dol_syslog("files.lib.php::dolReplaceInFile failed Permission denied to overwrite target file", LOG_WARNING); |
|
| 603 | - return -1; |
|
| 604 | - } |
|
| 605 | - if (! is_writable($newdirdestfile)) |
|
| 606 | - { |
|
| 607 | - dol_syslog("files.lib.php::dolReplaceInFile failed Permission denied to write into target directory ".$newdirdestfile, LOG_WARNING); |
|
| 608 | - return -2; |
|
| 609 | - } |
|
| 600 | + if ($destexists && ! is_writable($newpathofdestfile)) |
|
| 601 | + { |
|
| 602 | + dol_syslog("files.lib.php::dolReplaceInFile failed Permission denied to overwrite target file", LOG_WARNING); |
|
| 603 | + return -1; |
|
| 604 | + } |
|
| 605 | + if (! is_writable($newdirdestfile)) |
|
| 606 | + { |
|
| 607 | + dol_syslog("files.lib.php::dolReplaceInFile failed Permission denied to write into target directory ".$newdirdestfile, LOG_WARNING); |
|
| 608 | + return -2; |
|
| 609 | + } |
|
| 610 | 610 | |
| 611 | - dol_delete_file($tmpdestfile); |
|
| 611 | + dol_delete_file($tmpdestfile); |
|
| 612 | 612 | |
| 613 | - // Create $newpathoftmpdestfile from $newpathofsrcfile |
|
| 614 | - $content = file_get_contents($newpathofsrcfile, 'r'); |
|
| 613 | + // Create $newpathoftmpdestfile from $newpathofsrcfile |
|
| 614 | + $content = file_get_contents($newpathofsrcfile, 'r'); |
|
| 615 | 615 | |
| 616 | - $content = make_substitutions($content, $arrayreplacement, null); |
|
| 616 | + $content = make_substitutions($content, $arrayreplacement, null); |
|
| 617 | 617 | |
| 618 | - file_put_contents($newpathoftmpdestfile, $content); |
|
| 619 | - @chmod($newpathoftmpdestfile, octdec($newmask)); |
|
| 618 | + file_put_contents($newpathoftmpdestfile, $content); |
|
| 619 | + @chmod($newpathoftmpdestfile, octdec($newmask)); |
|
| 620 | 620 | |
| 621 | - // Rename |
|
| 622 | - $result=dol_move($newpathoftmpdestfile, $newpathofdestfile, $newmask, (($destfile == $srcfile)?1:0), 0, $indexdatabase); |
|
| 623 | - if (! $result) |
|
| 624 | - { |
|
| 625 | - dol_syslog("files.lib.php::dolReplaceInFile failed to move tmp file to final dest", LOG_WARNING); |
|
| 626 | - return -3; |
|
| 627 | - } |
|
| 628 | - if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK; |
|
| 629 | - if (empty($newmask)) // This should no happen |
|
| 630 | - { |
|
| 631 | - dol_syslog("Warning: dolReplaceInFile called with empty value for newmask and no default value defined", LOG_WARNING); |
|
| 632 | - $newmask='0664'; |
|
| 633 | - } |
|
| 621 | + // Rename |
|
| 622 | + $result=dol_move($newpathoftmpdestfile, $newpathofdestfile, $newmask, (($destfile == $srcfile)?1:0), 0, $indexdatabase); |
|
| 623 | + if (! $result) |
|
| 624 | + { |
|
| 625 | + dol_syslog("files.lib.php::dolReplaceInFile failed to move tmp file to final dest", LOG_WARNING); |
|
| 626 | + return -3; |
|
| 627 | + } |
|
| 628 | + if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK; |
|
| 629 | + if (empty($newmask)) // This should no happen |
|
| 630 | + { |
|
| 631 | + dol_syslog("Warning: dolReplaceInFile called with empty value for newmask and no default value defined", LOG_WARNING); |
|
| 632 | + $newmask='0664'; |
|
| 633 | + } |
|
| 634 | 634 | |
| 635 | - @chmod($newpathofdestfile, octdec($newmask)); |
|
| 635 | + @chmod($newpathofdestfile, octdec($newmask)); |
|
| 636 | 636 | |
| 637 | - return 1; |
|
| 637 | + return 1; |
|
| 638 | 638 | } |
| 639 | 639 | |
| 640 | 640 | /** |
@@ -650,7 +650,7 @@ discard block |
||
| 650 | 650 | */ |
| 651 | 651 | function dolReplaceRegExInFile($srcfile, $arrayreplacement, $destfile='', $newmask=0, $indexdatabase=0) |
| 652 | 652 | { |
| 653 | - // TODO |
|
| 653 | + // TODO |
|
| 654 | 654 | } |
| 655 | 655 | |
| 656 | 656 | /** |
@@ -665,47 +665,47 @@ discard block |
||
| 665 | 665 | */ |
| 666 | 666 | function dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1) |
| 667 | 667 | { |
| 668 | - global $conf; |
|
| 669 | - |
|
| 670 | - dol_syslog("files.lib.php::dol_copy srcfile=".$srcfile." destfile=".$destfile." newmask=".$newmask." overwriteifexists=".$overwriteifexists); |
|
| 671 | - |
|
| 672 | - if (empty($srcfile) || empty($destfile)) return -1; |
|
| 673 | - |
|
| 674 | - $destexists=dol_is_file($destfile); |
|
| 675 | - if (! $overwriteifexists && $destexists) return 0; |
|
| 676 | - |
|
| 677 | - $newpathofsrcfile=dol_osencode($srcfile); |
|
| 678 | - $newpathofdestfile=dol_osencode($destfile); |
|
| 679 | - $newdirdestfile=dirname($newpathofdestfile); |
|
| 680 | - |
|
| 681 | - if ($destexists && ! is_writable($newpathofdestfile)) |
|
| 682 | - { |
|
| 683 | - dol_syslog("files.lib.php::dol_copy failed Permission denied to overwrite target file", LOG_WARNING); |
|
| 684 | - return -1; |
|
| 685 | - } |
|
| 686 | - if (! is_writable($newdirdestfile)) |
|
| 687 | - { |
|
| 688 | - dol_syslog("files.lib.php::dol_copy failed Permission denied to write into target directory ".$newdirdestfile, LOG_WARNING); |
|
| 689 | - return -2; |
|
| 690 | - } |
|
| 691 | - // Copy with overwriting if exists |
|
| 692 | - $result=@copy($newpathofsrcfile, $newpathofdestfile); |
|
| 693 | - //$result=copy($newpathofsrcfile, $newpathofdestfile); // To see errors, remove @ |
|
| 694 | - if (! $result) |
|
| 695 | - { |
|
| 696 | - dol_syslog("files.lib.php::dol_copy failed to copy", LOG_WARNING); |
|
| 697 | - return -3; |
|
| 698 | - } |
|
| 699 | - if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK; |
|
| 700 | - if (empty($newmask)) // This should no happen |
|
| 701 | - { |
|
| 702 | - dol_syslog("Warning: dol_copy called with empty value for newmask and no default value defined", LOG_WARNING); |
|
| 703 | - $newmask='0664'; |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - @chmod($newpathofdestfile, octdec($newmask)); |
|
| 707 | - |
|
| 708 | - return 1; |
|
| 668 | + global $conf; |
|
| 669 | + |
|
| 670 | + dol_syslog("files.lib.php::dol_copy srcfile=".$srcfile." destfile=".$destfile." newmask=".$newmask." overwriteifexists=".$overwriteifexists); |
|
| 671 | + |
|
| 672 | + if (empty($srcfile) || empty($destfile)) return -1; |
|
| 673 | + |
|
| 674 | + $destexists=dol_is_file($destfile); |
|
| 675 | + if (! $overwriteifexists && $destexists) return 0; |
|
| 676 | + |
|
| 677 | + $newpathofsrcfile=dol_osencode($srcfile); |
|
| 678 | + $newpathofdestfile=dol_osencode($destfile); |
|
| 679 | + $newdirdestfile=dirname($newpathofdestfile); |
|
| 680 | + |
|
| 681 | + if ($destexists && ! is_writable($newpathofdestfile)) |
|
| 682 | + { |
|
| 683 | + dol_syslog("files.lib.php::dol_copy failed Permission denied to overwrite target file", LOG_WARNING); |
|
| 684 | + return -1; |
|
| 685 | + } |
|
| 686 | + if (! is_writable($newdirdestfile)) |
|
| 687 | + { |
|
| 688 | + dol_syslog("files.lib.php::dol_copy failed Permission denied to write into target directory ".$newdirdestfile, LOG_WARNING); |
|
| 689 | + return -2; |
|
| 690 | + } |
|
| 691 | + // Copy with overwriting if exists |
|
| 692 | + $result=@copy($newpathofsrcfile, $newpathofdestfile); |
|
| 693 | + //$result=copy($newpathofsrcfile, $newpathofdestfile); // To see errors, remove @ |
|
| 694 | + if (! $result) |
|
| 695 | + { |
|
| 696 | + dol_syslog("files.lib.php::dol_copy failed to copy", LOG_WARNING); |
|
| 697 | + return -3; |
|
| 698 | + } |
|
| 699 | + if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK; |
|
| 700 | + if (empty($newmask)) // This should no happen |
|
| 701 | + { |
|
| 702 | + dol_syslog("Warning: dol_copy called with empty value for newmask and no default value defined", LOG_WARNING); |
|
| 703 | + $newmask='0664'; |
|
| 704 | + } |
|
| 705 | + |
|
| 706 | + @chmod($newpathofdestfile, octdec($newmask)); |
|
| 707 | + |
|
| 708 | + return 1; |
|
| 709 | 709 | } |
| 710 | 710 | |
| 711 | 711 | /** |
@@ -721,77 +721,77 @@ discard block |
||
| 721 | 721 | */ |
| 722 | 722 | function dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists, $arrayreplacement=null) |
| 723 | 723 | { |
| 724 | - global $conf; |
|
| 725 | - |
|
| 726 | - $result=0; |
|
| 727 | - |
|
| 728 | - dol_syslog("files.lib.php::dolCopyDir srcfile=".$srcfile." destfile=".$destfile." newmask=".$newmask." overwriteifexists=".$overwriteifexists); |
|
| 729 | - |
|
| 730 | - if (empty($srcfile) || empty($destfile)) return -1; |
|
| 731 | - |
|
| 732 | - $destexists=dol_is_dir($destfile); |
|
| 733 | - //if (! $overwriteifexists && $destexists) return 0; // The overwriteifexists is for files only, so propagated to dol_copy only. |
|
| 734 | - |
|
| 735 | - if (! $destexists) |
|
| 736 | - { |
|
| 737 | - // We must set mask just before creating dir, becaause it can be set differently by dol_copy |
|
| 738 | - umask(0); |
|
| 739 | - $dirmaskdec=octdec($newmask); |
|
| 740 | - if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) $dirmaskdec=octdec($conf->global->MAIN_UMASK); |
|
| 741 | - $dirmaskdec |= octdec('0200'); // Set w bit required to be able to create content for recursive subdirs files |
|
| 742 | - dol_mkdir($destfile, '', decoct($dirmaskdec)); |
|
| 743 | - } |
|
| 744 | - |
|
| 745 | - $ossrcfile=dol_osencode($srcfile); |
|
| 746 | - $osdestfile=dol_osencode($destfile); |
|
| 747 | - |
|
| 748 | - // Recursive function to copy all subdirectories and contents: |
|
| 749 | - if (is_dir($ossrcfile)) |
|
| 750 | - { |
|
| 751 | - $dir_handle=opendir($ossrcfile); |
|
| 752 | - while ($file=readdir($dir_handle)) |
|
| 753 | - { |
|
| 754 | - if ($file != "." && $file != ".." && ! is_link($ossrcfile."/".$file)) |
|
| 755 | - { |
|
| 756 | - if (is_dir($ossrcfile."/".$file)) |
|
| 757 | - { |
|
| 758 | - //var_dump("xxx dolCopyDir $srcfile/$file, $destfile/$file, $newmask, $overwriteifexists"); |
|
| 759 | - $tmpresult=dolCopyDir($srcfile."/".$file, $destfile."/".$file, $newmask, $overwriteifexists, $arrayreplacement); |
|
| 760 | - } |
|
| 761 | - else |
|
| 762 | - { |
|
| 763 | - $newfile = $file; |
|
| 764 | - // Replace destination filename with a new one |
|
| 765 | - if (is_array($arrayreplacement)) |
|
| 766 | - { |
|
| 767 | - foreach($arrayreplacement as $key => $val) |
|
| 768 | - { |
|
| 769 | - $newfile = str_replace($key, $val, $newfile); |
|
| 770 | - } |
|
| 771 | - } |
|
| 772 | - $tmpresult=dol_copy($srcfile."/".$file, $destfile."/".$newfile, $newmask, $overwriteifexists); |
|
| 773 | - } |
|
| 774 | - // Set result |
|
| 775 | - if ($result > 0 && $tmpresult >= 0) |
|
| 776 | - { |
|
| 777 | - // Do nothing, so we don't set result to 0 if tmpresult is 0 and result was success in a previous pass |
|
| 778 | - } |
|
| 779 | - else |
|
| 780 | - { |
|
| 781 | - $result=$tmpresult; |
|
| 782 | - } |
|
| 783 | - if ($result < 0) break; |
|
| 784 | - } |
|
| 785 | - } |
|
| 786 | - closedir($dir_handle); |
|
| 787 | - } |
|
| 788 | - else |
|
| 789 | - { |
|
| 790 | - // Source directory does not exists |
|
| 791 | - $result = -2; |
|
| 792 | - } |
|
| 793 | - |
|
| 794 | - return $result; |
|
| 724 | + global $conf; |
|
| 725 | + |
|
| 726 | + $result=0; |
|
| 727 | + |
|
| 728 | + dol_syslog("files.lib.php::dolCopyDir srcfile=".$srcfile." destfile=".$destfile." newmask=".$newmask." overwriteifexists=".$overwriteifexists); |
|
| 729 | + |
|
| 730 | + if (empty($srcfile) || empty($destfile)) return -1; |
|
| 731 | + |
|
| 732 | + $destexists=dol_is_dir($destfile); |
|
| 733 | + //if (! $overwriteifexists && $destexists) return 0; // The overwriteifexists is for files only, so propagated to dol_copy only. |
|
| 734 | + |
|
| 735 | + if (! $destexists) |
|
| 736 | + { |
|
| 737 | + // We must set mask just before creating dir, becaause it can be set differently by dol_copy |
|
| 738 | + umask(0); |
|
| 739 | + $dirmaskdec=octdec($newmask); |
|
| 740 | + if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) $dirmaskdec=octdec($conf->global->MAIN_UMASK); |
|
| 741 | + $dirmaskdec |= octdec('0200'); // Set w bit required to be able to create content for recursive subdirs files |
|
| 742 | + dol_mkdir($destfile, '', decoct($dirmaskdec)); |
|
| 743 | + } |
|
| 744 | + |
|
| 745 | + $ossrcfile=dol_osencode($srcfile); |
|
| 746 | + $osdestfile=dol_osencode($destfile); |
|
| 747 | + |
|
| 748 | + // Recursive function to copy all subdirectories and contents: |
|
| 749 | + if (is_dir($ossrcfile)) |
|
| 750 | + { |
|
| 751 | + $dir_handle=opendir($ossrcfile); |
|
| 752 | + while ($file=readdir($dir_handle)) |
|
| 753 | + { |
|
| 754 | + if ($file != "." && $file != ".." && ! is_link($ossrcfile."/".$file)) |
|
| 755 | + { |
|
| 756 | + if (is_dir($ossrcfile."/".$file)) |
|
| 757 | + { |
|
| 758 | + //var_dump("xxx dolCopyDir $srcfile/$file, $destfile/$file, $newmask, $overwriteifexists"); |
|
| 759 | + $tmpresult=dolCopyDir($srcfile."/".$file, $destfile."/".$file, $newmask, $overwriteifexists, $arrayreplacement); |
|
| 760 | + } |
|
| 761 | + else |
|
| 762 | + { |
|
| 763 | + $newfile = $file; |
|
| 764 | + // Replace destination filename with a new one |
|
| 765 | + if (is_array($arrayreplacement)) |
|
| 766 | + { |
|
| 767 | + foreach($arrayreplacement as $key => $val) |
|
| 768 | + { |
|
| 769 | + $newfile = str_replace($key, $val, $newfile); |
|
| 770 | + } |
|
| 771 | + } |
|
| 772 | + $tmpresult=dol_copy($srcfile."/".$file, $destfile."/".$newfile, $newmask, $overwriteifexists); |
|
| 773 | + } |
|
| 774 | + // Set result |
|
| 775 | + if ($result > 0 && $tmpresult >= 0) |
|
| 776 | + { |
|
| 777 | + // Do nothing, so we don't set result to 0 if tmpresult is 0 and result was success in a previous pass |
|
| 778 | + } |
|
| 779 | + else |
|
| 780 | + { |
|
| 781 | + $result=$tmpresult; |
|
| 782 | + } |
|
| 783 | + if ($result < 0) break; |
|
| 784 | + } |
|
| 785 | + } |
|
| 786 | + closedir($dir_handle); |
|
| 787 | + } |
|
| 788 | + else |
|
| 789 | + { |
|
| 790 | + // Source directory does not exists |
|
| 791 | + $result = -2; |
|
| 792 | + } |
|
| 793 | + |
|
| 794 | + return $result; |
|
| 795 | 795 | } |
| 796 | 796 | |
| 797 | 797 | |
@@ -813,123 +813,123 @@ discard block |
||
| 813 | 813 | */ |
| 814 | 814 | function dol_move($srcfile, $destfile, $newmask=0, $overwriteifexists=1, $testvirus=0, $indexdatabase=1) |
| 815 | 815 | { |
| 816 | - global $user, $db, $conf; |
|
| 817 | - $result=false; |
|
| 818 | - |
|
| 819 | - dol_syslog("files.lib.php::dol_move srcfile=".$srcfile." destfile=".$destfile." newmask=".$newmask." overwritifexists=".$overwriteifexists); |
|
| 820 | - $srcexists=dol_is_file($srcfile); |
|
| 821 | - $destexists=dol_is_file($destfile); |
|
| 822 | - |
|
| 823 | - if (! $srcexists) |
|
| 824 | - { |
|
| 825 | - dol_syslog("files.lib.php::dol_move srcfile does not exists. we ignore the move request."); |
|
| 826 | - return false; |
|
| 827 | - } |
|
| 828 | - |
|
| 829 | - if ($overwriteifexists || ! $destexists) |
|
| 830 | - { |
|
| 831 | - $newpathofsrcfile=dol_osencode($srcfile); |
|
| 832 | - $newpathofdestfile=dol_osencode($destfile); |
|
| 833 | - |
|
| 834 | - // Check virus |
|
| 835 | - $testvirusarray=array(); |
|
| 836 | - if ($testvirus) |
|
| 837 | - { |
|
| 838 | - $testvirusarray=dolCheckVirus($newpathofsrcfile); |
|
| 839 | - if (count($testvirusarray)) |
|
| 840 | - { |
|
| 841 | - dol_syslog("files.lib.php::dol_move canceled because a virus was found into source file. we ignore the move request.", LOG_WARNING); |
|
| 842 | - return false; |
|
| 843 | - } |
|
| 844 | - } |
|
| 845 | - |
|
| 846 | - $result=@rename($newpathofsrcfile, $newpathofdestfile); // To see errors, remove @ |
|
| 847 | - if (! $result) |
|
| 848 | - { |
|
| 849 | - if ($destexists) |
|
| 850 | - { |
|
| 851 | - dol_syslog("files.lib.php::dol_move Failed. We try to delete target first and move after.", LOG_WARNING); |
|
| 852 | - // We force delete and try again. Rename function sometimes fails to replace dest file with some windows NTFS partitions. |
|
| 853 | - dol_delete_file($destfile); |
|
| 854 | - $result=@rename($newpathofsrcfile, $newpathofdestfile); // To see errors, remove @ |
|
| 855 | - } |
|
| 856 | - else dol_syslog("files.lib.php::dol_move Failed.", LOG_WARNING); |
|
| 857 | - } |
|
| 858 | - |
|
| 859 | - // Move ok |
|
| 860 | - if ($result && $indexdatabase) |
|
| 861 | - { |
|
| 862 | - // Rename entry into ecm database |
|
| 863 | - $rel_filetorenamebefore = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $srcfile); |
|
| 864 | - $rel_filetorenameafter = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $destfile); |
|
| 865 | - if (! preg_match('/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filetorenameafter)) // If not a tmp file |
|
| 866 | - { |
|
| 867 | - $rel_filetorenamebefore = preg_replace('/^[\\/]/', '', $rel_filetorenamebefore); |
|
| 868 | - $rel_filetorenameafter = preg_replace('/^[\\/]/', '', $rel_filetorenameafter); |
|
| 869 | - //var_dump($rel_filetorenamebefore.' - '.$rel_filetorenameafter); |
|
| 870 | - |
|
| 871 | - dol_syslog("Try to rename also entries in database for full relative path before = ".$rel_filetorenamebefore." after = ".$rel_filetorenameafter, LOG_DEBUG); |
|
| 872 | - include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; |
|
| 873 | - |
|
| 874 | - $ecmfiletarget=new EcmFiles($db); |
|
| 875 | - $resultecmtarget = $ecmfiletarget->fetch(0, '', $rel_filetorenameafter); |
|
| 876 | - if ($resultecmtarget > 0) // An entry for target name already exists for target, we delete it, a new one will be created. |
|
| 877 | - { |
|
| 878 | - $ecmfiletarget->delete($user); |
|
| 879 | - } |
|
| 880 | - |
|
| 881 | - $ecmfile=new EcmFiles($db); |
|
| 882 | - $resultecm = $ecmfile->fetch(0, '', $rel_filetorenamebefore); |
|
| 883 | - if ($resultecm > 0) // If an entry was found for src file, we use it to move entry |
|
| 884 | - { |
|
| 885 | - $filename = basename($rel_filetorenameafter); |
|
| 886 | - $rel_dir = dirname($rel_filetorenameafter); |
|
| 887 | - $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir); |
|
| 888 | - $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir); |
|
| 889 | - |
|
| 890 | - $ecmfile->filepath = $rel_dir; |
|
| 891 | - $ecmfile->filename = $filename; |
|
| 892 | - $resultecm = $ecmfile->update($user); |
|
| 893 | - } |
|
| 894 | - elseif ($resultecm == 0) // If no entry were found for src files, create/update target file |
|
| 895 | - { |
|
| 896 | - $filename = basename($rel_filetorenameafter); |
|
| 897 | - $rel_dir = dirname($rel_filetorenameafter); |
|
| 898 | - $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir); |
|
| 899 | - $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir); |
|
| 900 | - |
|
| 901 | - $ecmfile->filepath = $rel_dir; |
|
| 902 | - $ecmfile->filename = $filename; |
|
| 903 | - $ecmfile->label = md5_file(dol_osencode($destfile)); // $destfile is a full path to file |
|
| 904 | - $ecmfile->fullpath_orig = $srcfile; |
|
| 905 | - $ecmfile->gen_or_uploaded = 'unknown'; |
|
| 906 | - $ecmfile->description = ''; // indexed content |
|
| 907 | - $ecmfile->keyword = ''; // keyword content |
|
| 908 | - $resultecm = $ecmfile->create($user); |
|
| 909 | - if ($resultecm < 0) |
|
| 910 | - { |
|
| 911 | - setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings'); |
|
| 912 | - } |
|
| 913 | - } |
|
| 914 | - elseif ($resultecm < 0) |
|
| 915 | - { |
|
| 916 | - setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings'); |
|
| 917 | - } |
|
| 918 | - |
|
| 919 | - if ($resultecm > 0) $result=true; |
|
| 920 | - else $result = false; |
|
| 921 | - } |
|
| 922 | - } |
|
| 923 | - |
|
| 924 | - if (empty($newmask)) $newmask=empty($conf->global->MAIN_UMASK)?'0755':$conf->global->MAIN_UMASK; |
|
| 925 | - $newmaskdec=octdec($newmask); |
|
| 926 | - // Currently method is restricted to files (dol_delete_files previously used is for files, and mask usage if for files too) |
|
| 927 | - // to allow mask usage for dir, we shoul introduce a new param "isdir" to 1 to complete newmask like this |
|
| 928 | - // if ($isdir) $newmaskdec |= octdec('0111'); // Set x bit required for directories |
|
| 929 | - @chmod($newpathofdestfile, $newmaskdec); |
|
| 930 | - } |
|
| 931 | - |
|
| 932 | - return $result; |
|
| 816 | + global $user, $db, $conf; |
|
| 817 | + $result=false; |
|
| 818 | + |
|
| 819 | + dol_syslog("files.lib.php::dol_move srcfile=".$srcfile." destfile=".$destfile." newmask=".$newmask." overwritifexists=".$overwriteifexists); |
|
| 820 | + $srcexists=dol_is_file($srcfile); |
|
| 821 | + $destexists=dol_is_file($destfile); |
|
| 822 | + |
|
| 823 | + if (! $srcexists) |
|
| 824 | + { |
|
| 825 | + dol_syslog("files.lib.php::dol_move srcfile does not exists. we ignore the move request."); |
|
| 826 | + return false; |
|
| 827 | + } |
|
| 828 | + |
|
| 829 | + if ($overwriteifexists || ! $destexists) |
|
| 830 | + { |
|
| 831 | + $newpathofsrcfile=dol_osencode($srcfile); |
|
| 832 | + $newpathofdestfile=dol_osencode($destfile); |
|
| 833 | + |
|
| 834 | + // Check virus |
|
| 835 | + $testvirusarray=array(); |
|
| 836 | + if ($testvirus) |
|
| 837 | + { |
|
| 838 | + $testvirusarray=dolCheckVirus($newpathofsrcfile); |
|
| 839 | + if (count($testvirusarray)) |
|
| 840 | + { |
|
| 841 | + dol_syslog("files.lib.php::dol_move canceled because a virus was found into source file. we ignore the move request.", LOG_WARNING); |
|
| 842 | + return false; |
|
| 843 | + } |
|
| 844 | + } |
|
| 845 | + |
|
| 846 | + $result=@rename($newpathofsrcfile, $newpathofdestfile); // To see errors, remove @ |
|
| 847 | + if (! $result) |
|
| 848 | + { |
|
| 849 | + if ($destexists) |
|
| 850 | + { |
|
| 851 | + dol_syslog("files.lib.php::dol_move Failed. We try to delete target first and move after.", LOG_WARNING); |
|
| 852 | + // We force delete and try again. Rename function sometimes fails to replace dest file with some windows NTFS partitions. |
|
| 853 | + dol_delete_file($destfile); |
|
| 854 | + $result=@rename($newpathofsrcfile, $newpathofdestfile); // To see errors, remove @ |
|
| 855 | + } |
|
| 856 | + else dol_syslog("files.lib.php::dol_move Failed.", LOG_WARNING); |
|
| 857 | + } |
|
| 858 | + |
|
| 859 | + // Move ok |
|
| 860 | + if ($result && $indexdatabase) |
|
| 861 | + { |
|
| 862 | + // Rename entry into ecm database |
|
| 863 | + $rel_filetorenamebefore = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $srcfile); |
|
| 864 | + $rel_filetorenameafter = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $destfile); |
|
| 865 | + if (! preg_match('/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filetorenameafter)) // If not a tmp file |
|
| 866 | + { |
|
| 867 | + $rel_filetorenamebefore = preg_replace('/^[\\/]/', '', $rel_filetorenamebefore); |
|
| 868 | + $rel_filetorenameafter = preg_replace('/^[\\/]/', '', $rel_filetorenameafter); |
|
| 869 | + //var_dump($rel_filetorenamebefore.' - '.$rel_filetorenameafter); |
|
| 870 | + |
|
| 871 | + dol_syslog("Try to rename also entries in database for full relative path before = ".$rel_filetorenamebefore." after = ".$rel_filetorenameafter, LOG_DEBUG); |
|
| 872 | + include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; |
|
| 873 | + |
|
| 874 | + $ecmfiletarget=new EcmFiles($db); |
|
| 875 | + $resultecmtarget = $ecmfiletarget->fetch(0, '', $rel_filetorenameafter); |
|
| 876 | + if ($resultecmtarget > 0) // An entry for target name already exists for target, we delete it, a new one will be created. |
|
| 877 | + { |
|
| 878 | + $ecmfiletarget->delete($user); |
|
| 879 | + } |
|
| 880 | + |
|
| 881 | + $ecmfile=new EcmFiles($db); |
|
| 882 | + $resultecm = $ecmfile->fetch(0, '', $rel_filetorenamebefore); |
|
| 883 | + if ($resultecm > 0) // If an entry was found for src file, we use it to move entry |
|
| 884 | + { |
|
| 885 | + $filename = basename($rel_filetorenameafter); |
|
| 886 | + $rel_dir = dirname($rel_filetorenameafter); |
|
| 887 | + $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir); |
|
| 888 | + $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir); |
|
| 889 | + |
|
| 890 | + $ecmfile->filepath = $rel_dir; |
|
| 891 | + $ecmfile->filename = $filename; |
|
| 892 | + $resultecm = $ecmfile->update($user); |
|
| 893 | + } |
|
| 894 | + elseif ($resultecm == 0) // If no entry were found for src files, create/update target file |
|
| 895 | + { |
|
| 896 | + $filename = basename($rel_filetorenameafter); |
|
| 897 | + $rel_dir = dirname($rel_filetorenameafter); |
|
| 898 | + $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir); |
|
| 899 | + $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir); |
|
| 900 | + |
|
| 901 | + $ecmfile->filepath = $rel_dir; |
|
| 902 | + $ecmfile->filename = $filename; |
|
| 903 | + $ecmfile->label = md5_file(dol_osencode($destfile)); // $destfile is a full path to file |
|
| 904 | + $ecmfile->fullpath_orig = $srcfile; |
|
| 905 | + $ecmfile->gen_or_uploaded = 'unknown'; |
|
| 906 | + $ecmfile->description = ''; // indexed content |
|
| 907 | + $ecmfile->keyword = ''; // keyword content |
|
| 908 | + $resultecm = $ecmfile->create($user); |
|
| 909 | + if ($resultecm < 0) |
|
| 910 | + { |
|
| 911 | + setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings'); |
|
| 912 | + } |
|
| 913 | + } |
|
| 914 | + elseif ($resultecm < 0) |
|
| 915 | + { |
|
| 916 | + setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings'); |
|
| 917 | + } |
|
| 918 | + |
|
| 919 | + if ($resultecm > 0) $result=true; |
|
| 920 | + else $result = false; |
|
| 921 | + } |
|
| 922 | + } |
|
| 923 | + |
|
| 924 | + if (empty($newmask)) $newmask=empty($conf->global->MAIN_UMASK)?'0755':$conf->global->MAIN_UMASK; |
|
| 925 | + $newmaskdec=octdec($newmask); |
|
| 926 | + // Currently method is restricted to files (dol_delete_files previously used is for files, and mask usage if for files too) |
|
| 927 | + // to allow mask usage for dir, we shoul introduce a new param "isdir" to 1 to complete newmask like this |
|
| 928 | + // if ($isdir) $newmaskdec |= octdec('0111'); // Set x bit required for directories |
|
| 929 | + @chmod($newpathofdestfile, $newmaskdec); |
|
| 930 | + } |
|
| 931 | + |
|
| 932 | + return $result; |
|
| 933 | 933 | } |
| 934 | 934 | |
| 935 | 935 | /** |
@@ -941,10 +941,10 @@ discard block |
||
| 941 | 941 | */ |
| 942 | 942 | function dol_unescapefile($filename) |
| 943 | 943 | { |
| 944 | - // Remove path information and dots around the filename, to prevent uploading |
|
| 945 | - // into different directories or replacing hidden system files. |
|
| 946 | - // Also remove control characters and spaces (\x00..\x20) around the filename: |
|
| 947 | - return trim(basename($filename), ".\x00..\x20"); |
|
| 944 | + // Remove path information and dots around the filename, to prevent uploading |
|
| 945 | + // into different directories or replacing hidden system files. |
|
| 946 | + // Also remove control characters and spaces (\x00..\x20) around the filename: |
|
| 947 | + return trim(basename($filename), ".\x00..\x20"); |
|
| 948 | 948 | } |
| 949 | 949 | |
| 950 | 950 | |
@@ -956,22 +956,22 @@ discard block |
||
| 956 | 956 | */ |
| 957 | 957 | function dolCheckVirus($src_file) |
| 958 | 958 | { |
| 959 | - global $conf; |
|
| 960 | - |
|
| 961 | - if (! empty($conf->global->MAIN_ANTIVIRUS_COMMAND)) |
|
| 962 | - { |
|
| 963 | - if (! class_exists('AntiVir')) { |
|
| 964 | - require_once DOL_DOCUMENT_ROOT.'/core/class/antivir.class.php'; |
|
| 965 | - } |
|
| 966 | - $antivir=new AntiVir($db); |
|
| 967 | - $result = $antivir->dol_avscan_file($src_file); |
|
| 968 | - if ($result < 0) // If virus or error, we stop here |
|
| 969 | - { |
|
| 970 | - $reterrors=$antivir->errors; |
|
| 971 | - return $reterrors; |
|
| 972 | - } |
|
| 973 | - } |
|
| 974 | - return array(); |
|
| 959 | + global $conf; |
|
| 960 | + |
|
| 961 | + if (! empty($conf->global->MAIN_ANTIVIRUS_COMMAND)) |
|
| 962 | + { |
|
| 963 | + if (! class_exists('AntiVir')) { |
|
| 964 | + require_once DOL_DOCUMENT_ROOT.'/core/class/antivir.class.php'; |
|
| 965 | + } |
|
| 966 | + $antivir=new AntiVir($db); |
|
| 967 | + $result = $antivir->dol_avscan_file($src_file); |
|
| 968 | + if ($result < 0) // If virus or error, we stop here |
|
| 969 | + { |
|
| 970 | + $reterrors=$antivir->errors; |
|
| 971 | + return $reterrors; |
|
| 972 | + } |
|
| 973 | + } |
|
| 974 | + return array(); |
|
| 975 | 975 | } |
| 976 | 976 | |
| 977 | 977 | |
@@ -995,131 +995,131 @@ discard block |
||
| 995 | 995 | */ |
| 996 | 996 | function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0, $nohook=0, $varfiles='addedfile') |
| 997 | 997 | { |
| 998 | - global $conf, $db, $user, $langs; |
|
| 999 | - global $object, $hookmanager; |
|
| 1000 | - |
|
| 1001 | - $reshook=0; |
|
| 1002 | - $file_name = $dest_file; |
|
| 1003 | - |
|
| 1004 | - if (empty($nohook)) |
|
| 1005 | - { |
|
| 1006 | - $reshook=$hookmanager->initHooks(array('fileslib')); |
|
| 1007 | - |
|
| 1008 | - $parameters=array('dest_file' => $dest_file, 'src_file' => $src_file, 'file_name' => $file_name, 'varfiles' => $varfiles, 'allowoverwrite' => $allowoverwrite); |
|
| 1009 | - $reshook=$hookmanager->executeHooks('moveUploadedFile', $parameters, $object); |
|
| 1010 | - } |
|
| 1011 | - |
|
| 1012 | - if (empty($reshook)) |
|
| 1013 | - { |
|
| 1014 | - // If an upload error has been reported |
|
| 1015 | - if ($uploaderrorcode) |
|
| 1016 | - { |
|
| 1017 | - switch($uploaderrorcode) |
|
| 1018 | - { |
|
| 1019 | - case UPLOAD_ERR_INI_SIZE: // 1 |
|
| 1020 | - return 'ErrorFileSizeTooLarge'; |
|
| 1021 | - break; |
|
| 1022 | - case UPLOAD_ERR_FORM_SIZE: // 2 |
|
| 1023 | - return 'ErrorFileSizeTooLarge'; |
|
| 1024 | - break; |
|
| 1025 | - case UPLOAD_ERR_PARTIAL: // 3 |
|
| 1026 | - return 'ErrorPartialFile'; |
|
| 1027 | - break; |
|
| 1028 | - case UPLOAD_ERR_NO_TMP_DIR: // |
|
| 1029 | - return 'ErrorNoTmpDir'; |
|
| 1030 | - break; |
|
| 1031 | - case UPLOAD_ERR_CANT_WRITE: |
|
| 1032 | - return 'ErrorFailedToWriteInDir'; |
|
| 1033 | - break; |
|
| 1034 | - case UPLOAD_ERR_EXTENSION: |
|
| 1035 | - return 'ErrorUploadBlockedByAddon'; |
|
| 1036 | - break; |
|
| 1037 | - default: |
|
| 1038 | - break; |
|
| 1039 | - } |
|
| 1040 | - } |
|
| 1041 | - |
|
| 1042 | - // If we need to make a virus scan |
|
| 1043 | - if (empty($disablevirusscan) && file_exists($src_file)) |
|
| 1044 | - { |
|
| 1045 | - $checkvirusarray=dolCheckVirus($src_file); |
|
| 1046 | - if (count($checkvirusarray)) |
|
| 1047 | - { |
|
| 1048 | - dol_syslog('Files.lib::dol_move_uploaded_file File "'.$src_file.'" (target name "'.$dest_file.'") KO with antivirus: result='.$result.' errors='.join(',',$checkvirusarray), LOG_WARNING); |
|
| 1049 | - return 'ErrorFileIsInfectedWithAVirus: '.join(',',$checkvirusarray); |
|
| 1050 | - } |
|
| 1051 | - } |
|
| 1052 | - |
|
| 1053 | - // Security: |
|
| 1054 | - // Disallow file with some extensions. We rename them. |
|
| 1055 | - // Because if we put the documents directory into a directory inside web root (very bad), this allows to execute on demand arbitrary code. |
|
| 1056 | - if (preg_match('/(\.htm|\.html|\.php|\.pl|\.cgi)$/i',$dest_file) && empty($conf->global->MAIN_DOCUMENT_IS_OUTSIDE_WEBROOT_SO_NOEXE_NOT_REQUIRED)) |
|
| 1057 | - { |
|
| 1058 | - $file_name.= '.noexe'; |
|
| 1059 | - } |
|
| 1060 | - |
|
| 1061 | - // Security: |
|
| 1062 | - // We refuse cache files/dirs, upload using .. and pipes into filenames. |
|
| 1063 | - if (preg_match('/^\./',$src_file) || preg_match('/\.\./',$src_file) || preg_match('/[<>|]/',$src_file)) |
|
| 1064 | - { |
|
| 1065 | - dol_syslog("Refused to deliver file ".$src_file, LOG_WARNING); |
|
| 1066 | - return -1; |
|
| 1067 | - } |
|
| 1068 | - |
|
| 1069 | - // Security: |
|
| 1070 | - // On interdit fichiers caches, remontees de repertoire ainsi que les pipe dans les noms de fichiers. |
|
| 1071 | - if (preg_match('/^\./',$dest_file) || preg_match('/\.\./',$dest_file) || preg_match('/[<>|]/',$dest_file)) |
|
| 1072 | - { |
|
| 1073 | - dol_syslog("Refused to deliver file ".$dest_file, LOG_WARNING); |
|
| 1074 | - return -2; |
|
| 1075 | - } |
|
| 1076 | - } |
|
| 1077 | - |
|
| 1078 | - if ($reshook < 0) // At least one blocking error returned by one hook |
|
| 1079 | - { |
|
| 1080 | - $errmsg = join(',', $hookmanager->errors); |
|
| 1081 | - if (empty($errmsg)) $errmsg = 'ErrorReturnedBySomeHooks'; // Should not occurs. Added if hook is bugged and does not set ->errors when there is error. |
|
| 1082 | - return $errmsg; |
|
| 1083 | - } |
|
| 1084 | - elseif (empty($reshook)) |
|
| 1085 | - { |
|
| 1086 | - // The file functions must be in OS filesystem encoding. |
|
| 1087 | - $src_file_osencoded=dol_osencode($src_file); |
|
| 1088 | - $file_name_osencoded=dol_osencode($file_name); |
|
| 1089 | - |
|
| 1090 | - // Check if destination dir is writable |
|
| 1091 | - if (! is_writable(dirname($file_name_osencoded))) |
|
| 1092 | - { |
|
| 1093 | - dol_syslog("Files.lib::dol_move_uploaded_file Dir ".dirname($file_name_osencoded)." is not writable. Return 'ErrorDirNotWritable'", LOG_WARNING); |
|
| 1094 | - return 'ErrorDirNotWritable'; |
|
| 1095 | - } |
|
| 1096 | - |
|
| 1097 | - // Check if destination file already exists |
|
| 1098 | - if (! $allowoverwrite) |
|
| 1099 | - { |
|
| 1100 | - if (file_exists($file_name_osencoded)) |
|
| 1101 | - { |
|
| 1102 | - dol_syslog("Files.lib::dol_move_uploaded_file File ".$file_name." already exists. Return 'ErrorFileAlreadyExists'", LOG_WARNING); |
|
| 1103 | - return 'ErrorFileAlreadyExists'; |
|
| 1104 | - } |
|
| 1105 | - } |
|
| 1106 | - |
|
| 1107 | - // Move file |
|
| 1108 | - $return=move_uploaded_file($src_file_osencoded, $file_name_osencoded); |
|
| 1109 | - if ($return) |
|
| 1110 | - { |
|
| 1111 | - if (! empty($conf->global->MAIN_UMASK)) @chmod($file_name_osencoded, octdec($conf->global->MAIN_UMASK)); |
|
| 1112 | - dol_syslog("Files.lib::dol_move_uploaded_file Success to move ".$src_file." to ".$file_name." - Umask=".$conf->global->MAIN_UMASK, LOG_DEBUG); |
|
| 1113 | - return 1; // Success |
|
| 1114 | - } |
|
| 1115 | - else |
|
| 1116 | - { |
|
| 1117 | - dol_syslog("Files.lib::dol_move_uploaded_file Failed to move ".$src_file." to ".$file_name, LOG_ERR); |
|
| 1118 | - return -3; // Unknown error |
|
| 1119 | - } |
|
| 1120 | - } |
|
| 1121 | - |
|
| 1122 | - return 1; // Success |
|
| 998 | + global $conf, $db, $user, $langs; |
|
| 999 | + global $object, $hookmanager; |
|
| 1000 | + |
|
| 1001 | + $reshook=0; |
|
| 1002 | + $file_name = $dest_file; |
|
| 1003 | + |
|
| 1004 | + if (empty($nohook)) |
|
| 1005 | + { |
|
| 1006 | + $reshook=$hookmanager->initHooks(array('fileslib')); |
|
| 1007 | + |
|
| 1008 | + $parameters=array('dest_file' => $dest_file, 'src_file' => $src_file, 'file_name' => $file_name, 'varfiles' => $varfiles, 'allowoverwrite' => $allowoverwrite); |
|
| 1009 | + $reshook=$hookmanager->executeHooks('moveUploadedFile', $parameters, $object); |
|
| 1010 | + } |
|
| 1011 | + |
|
| 1012 | + if (empty($reshook)) |
|
| 1013 | + { |
|
| 1014 | + // If an upload error has been reported |
|
| 1015 | + if ($uploaderrorcode) |
|
| 1016 | + { |
|
| 1017 | + switch($uploaderrorcode) |
|
| 1018 | + { |
|
| 1019 | + case UPLOAD_ERR_INI_SIZE: // 1 |
|
| 1020 | + return 'ErrorFileSizeTooLarge'; |
|
| 1021 | + break; |
|
| 1022 | + case UPLOAD_ERR_FORM_SIZE: // 2 |
|
| 1023 | + return 'ErrorFileSizeTooLarge'; |
|
| 1024 | + break; |
|
| 1025 | + case UPLOAD_ERR_PARTIAL: // 3 |
|
| 1026 | + return 'ErrorPartialFile'; |
|
| 1027 | + break; |
|
| 1028 | + case UPLOAD_ERR_NO_TMP_DIR: // |
|
| 1029 | + return 'ErrorNoTmpDir'; |
|
| 1030 | + break; |
|
| 1031 | + case UPLOAD_ERR_CANT_WRITE: |
|
| 1032 | + return 'ErrorFailedToWriteInDir'; |
|
| 1033 | + break; |
|
| 1034 | + case UPLOAD_ERR_EXTENSION: |
|
| 1035 | + return 'ErrorUploadBlockedByAddon'; |
|
| 1036 | + break; |
|
| 1037 | + default: |
|
| 1038 | + break; |
|
| 1039 | + } |
|
| 1040 | + } |
|
| 1041 | + |
|
| 1042 | + // If we need to make a virus scan |
|
| 1043 | + if (empty($disablevirusscan) && file_exists($src_file)) |
|
| 1044 | + { |
|
| 1045 | + $checkvirusarray=dolCheckVirus($src_file); |
|
| 1046 | + if (count($checkvirusarray)) |
|
| 1047 | + { |
|
| 1048 | + dol_syslog('Files.lib::dol_move_uploaded_file File "'.$src_file.'" (target name "'.$dest_file.'") KO with antivirus: result='.$result.' errors='.join(',',$checkvirusarray), LOG_WARNING); |
|
| 1049 | + return 'ErrorFileIsInfectedWithAVirus: '.join(',',$checkvirusarray); |
|
| 1050 | + } |
|
| 1051 | + } |
|
| 1052 | + |
|
| 1053 | + // Security: |
|
| 1054 | + // Disallow file with some extensions. We rename them. |
|
| 1055 | + // Because if we put the documents directory into a directory inside web root (very bad), this allows to execute on demand arbitrary code. |
|
| 1056 | + if (preg_match('/(\.htm|\.html|\.php|\.pl|\.cgi)$/i',$dest_file) && empty($conf->global->MAIN_DOCUMENT_IS_OUTSIDE_WEBROOT_SO_NOEXE_NOT_REQUIRED)) |
|
| 1057 | + { |
|
| 1058 | + $file_name.= '.noexe'; |
|
| 1059 | + } |
|
| 1060 | + |
|
| 1061 | + // Security: |
|
| 1062 | + // We refuse cache files/dirs, upload using .. and pipes into filenames. |
|
| 1063 | + if (preg_match('/^\./',$src_file) || preg_match('/\.\./',$src_file) || preg_match('/[<>|]/',$src_file)) |
|
| 1064 | + { |
|
| 1065 | + dol_syslog("Refused to deliver file ".$src_file, LOG_WARNING); |
|
| 1066 | + return -1; |
|
| 1067 | + } |
|
| 1068 | + |
|
| 1069 | + // Security: |
|
| 1070 | + // On interdit fichiers caches, remontees de repertoire ainsi que les pipe dans les noms de fichiers. |
|
| 1071 | + if (preg_match('/^\./',$dest_file) || preg_match('/\.\./',$dest_file) || preg_match('/[<>|]/',$dest_file)) |
|
| 1072 | + { |
|
| 1073 | + dol_syslog("Refused to deliver file ".$dest_file, LOG_WARNING); |
|
| 1074 | + return -2; |
|
| 1075 | + } |
|
| 1076 | + } |
|
| 1077 | + |
|
| 1078 | + if ($reshook < 0) // At least one blocking error returned by one hook |
|
| 1079 | + { |
|
| 1080 | + $errmsg = join(',', $hookmanager->errors); |
|
| 1081 | + if (empty($errmsg)) $errmsg = 'ErrorReturnedBySomeHooks'; // Should not occurs. Added if hook is bugged and does not set ->errors when there is error. |
|
| 1082 | + return $errmsg; |
|
| 1083 | + } |
|
| 1084 | + elseif (empty($reshook)) |
|
| 1085 | + { |
|
| 1086 | + // The file functions must be in OS filesystem encoding. |
|
| 1087 | + $src_file_osencoded=dol_osencode($src_file); |
|
| 1088 | + $file_name_osencoded=dol_osencode($file_name); |
|
| 1089 | + |
|
| 1090 | + // Check if destination dir is writable |
|
| 1091 | + if (! is_writable(dirname($file_name_osencoded))) |
|
| 1092 | + { |
|
| 1093 | + dol_syslog("Files.lib::dol_move_uploaded_file Dir ".dirname($file_name_osencoded)." is not writable. Return 'ErrorDirNotWritable'", LOG_WARNING); |
|
| 1094 | + return 'ErrorDirNotWritable'; |
|
| 1095 | + } |
|
| 1096 | + |
|
| 1097 | + // Check if destination file already exists |
|
| 1098 | + if (! $allowoverwrite) |
|
| 1099 | + { |
|
| 1100 | + if (file_exists($file_name_osencoded)) |
|
| 1101 | + { |
|
| 1102 | + dol_syslog("Files.lib::dol_move_uploaded_file File ".$file_name." already exists. Return 'ErrorFileAlreadyExists'", LOG_WARNING); |
|
| 1103 | + return 'ErrorFileAlreadyExists'; |
|
| 1104 | + } |
|
| 1105 | + } |
|
| 1106 | + |
|
| 1107 | + // Move file |
|
| 1108 | + $return=move_uploaded_file($src_file_osencoded, $file_name_osencoded); |
|
| 1109 | + if ($return) |
|
| 1110 | + { |
|
| 1111 | + if (! empty($conf->global->MAIN_UMASK)) @chmod($file_name_osencoded, octdec($conf->global->MAIN_UMASK)); |
|
| 1112 | + dol_syslog("Files.lib::dol_move_uploaded_file Success to move ".$src_file." to ".$file_name." - Umask=".$conf->global->MAIN_UMASK, LOG_DEBUG); |
|
| 1113 | + return 1; // Success |
|
| 1114 | + } |
|
| 1115 | + else |
|
| 1116 | + { |
|
| 1117 | + dol_syslog("Files.lib::dol_move_uploaded_file Failed to move ".$src_file." to ".$file_name, LOG_ERR); |
|
| 1118 | + return -3; // Unknown error |
|
| 1119 | + } |
|
| 1120 | + } |
|
| 1121 | + |
|
| 1122 | + return 1; // Success |
|
| 1123 | 1123 | } |
| 1124 | 1124 | |
| 1125 | 1125 | /** |
@@ -1138,103 +1138,103 @@ discard block |
||
| 1138 | 1138 | */ |
| 1139 | 1139 | function dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1) |
| 1140 | 1140 | { |
| 1141 | - global $db, $conf, $user, $langs; |
|
| 1142 | - global $hookmanager; |
|
| 1141 | + global $db, $conf, $user, $langs; |
|
| 1142 | + global $hookmanager; |
|
| 1143 | 1143 | |
| 1144 | - // Load translation files required by the page |
|
| 1144 | + // Load translation files required by the page |
|
| 1145 | 1145 | $langs->loadLangs(array('other', 'errors')); |
| 1146 | 1146 | |
| 1147 | - dol_syslog("dol_delete_file file=".$file." disableglob=".$disableglob." nophperrors=".$nophperrors." nohook=".$nohook); |
|
| 1148 | - |
|
| 1149 | - // Security: |
|
| 1150 | - // We refuse transversal using .. and pipes into filenames. |
|
| 1151 | - if ((! $allowdotdot && preg_match('/\.\./',$file)) || preg_match('/[<>|]/',$file)) |
|
| 1152 | - { |
|
| 1153 | - dol_syslog("Refused to delete file ".$file, LOG_WARNING); |
|
| 1154 | - return false; |
|
| 1155 | - } |
|
| 1156 | - |
|
| 1157 | - if (empty($nohook)) |
|
| 1158 | - { |
|
| 1159 | - $hookmanager->initHooks(array('fileslib')); |
|
| 1160 | - |
|
| 1161 | - $parameters=array( |
|
| 1162 | - 'GET' => $_GET, |
|
| 1163 | - 'file' => $file, |
|
| 1164 | - 'disableglob'=> $disableglob, |
|
| 1165 | - 'nophperrors' => $nophperrors |
|
| 1166 | - ); |
|
| 1167 | - $reshook=$hookmanager->executeHooks('deleteFile', $parameters, $object); |
|
| 1168 | - } |
|
| 1169 | - |
|
| 1170 | - if (empty($nohook) && $reshook != 0) // reshook = 0 to do standard actions, 1 = ok, -1 = ko |
|
| 1171 | - { |
|
| 1172 | - if ($reshook < 0) return false; |
|
| 1173 | - return true; |
|
| 1174 | - } |
|
| 1175 | - else |
|
| 1176 | - { |
|
| 1177 | - $error=0; |
|
| 1178 | - |
|
| 1179 | - //print "x".$file." ".$disableglob;exit; |
|
| 1180 | - $file_osencoded=dol_osencode($file); // New filename encoded in OS filesystem encoding charset |
|
| 1181 | - if (empty($disableglob) && ! empty($file_osencoded)) |
|
| 1182 | - { |
|
| 1183 | - $ok=true; |
|
| 1184 | - $globencoded=str_replace('[','\[',$file_osencoded); |
|
| 1185 | - $globencoded=str_replace(']','\]',$globencoded); |
|
| 1186 | - $listofdir=glob($globencoded); |
|
| 1187 | - if (! empty($listofdir) && is_array($listofdir)) |
|
| 1188 | - { |
|
| 1189 | - foreach ($listofdir as $filename) |
|
| 1190 | - { |
|
| 1191 | - if ($nophperrors) $ok=@unlink($filename); |
|
| 1192 | - else $ok=unlink($filename); |
|
| 1193 | - if ($ok) |
|
| 1194 | - { |
|
| 1195 | - dol_syslog("Removed file ".$filename, LOG_DEBUG); |
|
| 1196 | - |
|
| 1197 | - // Delete entry into ecm database |
|
| 1198 | - $rel_filetodelete = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $filename); |
|
| 1199 | - if (! preg_match('/(\/temp\/|\/thumbs\/|\.meta$)/', $rel_filetodelete)) // If not a tmp file |
|
| 1200 | - { |
|
| 1201 | - $rel_filetodelete = preg_replace('/^[\\/]/', '', $rel_filetodelete); |
|
| 1202 | - |
|
| 1203 | - if (is_object($db) && $indexdatabase) // $db may not be defined when lib is in a context with define('NOREQUIREDB',1) |
|
| 1204 | - { |
|
| 1205 | - dol_syslog("Try to remove also entries in database for full relative path = ".$rel_filetodelete, LOG_DEBUG); |
|
| 1206 | - include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; |
|
| 1207 | - $ecmfile=new EcmFiles($db); |
|
| 1208 | - $result = $ecmfile->fetch(0, '', $rel_filetodelete); |
|
| 1209 | - if ($result >= 0 && $ecmfile->id > 0) |
|
| 1210 | - { |
|
| 1211 | - $result = $ecmfile->delete($user); |
|
| 1212 | - } |
|
| 1213 | - if ($result < 0) |
|
| 1214 | - { |
|
| 1215 | - setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings'); |
|
| 1216 | - } |
|
| 1217 | - } |
|
| 1218 | - } |
|
| 1219 | - } |
|
| 1220 | - else dol_syslog("Failed to remove file ".$filename, LOG_WARNING); |
|
| 1221 | - // TODO Failure to remove can be because file was already removed or because of permission |
|
| 1222 | - // If error because it does not exists, we should return true, and we should return false if this is a permission problem |
|
| 1223 | - } |
|
| 1224 | - } |
|
| 1225 | - else dol_syslog("No files to delete found", LOG_DEBUG); |
|
| 1226 | - } |
|
| 1227 | - else |
|
| 1228 | - { |
|
| 1229 | - $ok=false; |
|
| 1230 | - if ($nophperrors) $ok=@unlink($file_osencoded); |
|
| 1231 | - else $ok=unlink($file_osencoded); |
|
| 1232 | - if ($ok) dol_syslog("Removed file ".$file_osencoded, LOG_DEBUG); |
|
| 1233 | - else dol_syslog("Failed to remove file ".$file_osencoded, LOG_WARNING); |
|
| 1234 | - } |
|
| 1235 | - |
|
| 1236 | - return $ok; |
|
| 1237 | - } |
|
| 1147 | + dol_syslog("dol_delete_file file=".$file." disableglob=".$disableglob." nophperrors=".$nophperrors." nohook=".$nohook); |
|
| 1148 | + |
|
| 1149 | + // Security: |
|
| 1150 | + // We refuse transversal using .. and pipes into filenames. |
|
| 1151 | + if ((! $allowdotdot && preg_match('/\.\./',$file)) || preg_match('/[<>|]/',$file)) |
|
| 1152 | + { |
|
| 1153 | + dol_syslog("Refused to delete file ".$file, LOG_WARNING); |
|
| 1154 | + return false; |
|
| 1155 | + } |
|
| 1156 | + |
|
| 1157 | + if (empty($nohook)) |
|
| 1158 | + { |
|
| 1159 | + $hookmanager->initHooks(array('fileslib')); |
|
| 1160 | + |
|
| 1161 | + $parameters=array( |
|
| 1162 | + 'GET' => $_GET, |
|
| 1163 | + 'file' => $file, |
|
| 1164 | + 'disableglob'=> $disableglob, |
|
| 1165 | + 'nophperrors' => $nophperrors |
|
| 1166 | + ); |
|
| 1167 | + $reshook=$hookmanager->executeHooks('deleteFile', $parameters, $object); |
|
| 1168 | + } |
|
| 1169 | + |
|
| 1170 | + if (empty($nohook) && $reshook != 0) // reshook = 0 to do standard actions, 1 = ok, -1 = ko |
|
| 1171 | + { |
|
| 1172 | + if ($reshook < 0) return false; |
|
| 1173 | + return true; |
|
| 1174 | + } |
|
| 1175 | + else |
|
| 1176 | + { |
|
| 1177 | + $error=0; |
|
| 1178 | + |
|
| 1179 | + //print "x".$file." ".$disableglob;exit; |
|
| 1180 | + $file_osencoded=dol_osencode($file); // New filename encoded in OS filesystem encoding charset |
|
| 1181 | + if (empty($disableglob) && ! empty($file_osencoded)) |
|
| 1182 | + { |
|
| 1183 | + $ok=true; |
|
| 1184 | + $globencoded=str_replace('[','\[',$file_osencoded); |
|
| 1185 | + $globencoded=str_replace(']','\]',$globencoded); |
|
| 1186 | + $listofdir=glob($globencoded); |
|
| 1187 | + if (! empty($listofdir) && is_array($listofdir)) |
|
| 1188 | + { |
|
| 1189 | + foreach ($listofdir as $filename) |
|
| 1190 | + { |
|
| 1191 | + if ($nophperrors) $ok=@unlink($filename); |
|
| 1192 | + else $ok=unlink($filename); |
|
| 1193 | + if ($ok) |
|
| 1194 | + { |
|
| 1195 | + dol_syslog("Removed file ".$filename, LOG_DEBUG); |
|
| 1196 | + |
|
| 1197 | + // Delete entry into ecm database |
|
| 1198 | + $rel_filetodelete = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $filename); |
|
| 1199 | + if (! preg_match('/(\/temp\/|\/thumbs\/|\.meta$)/', $rel_filetodelete)) // If not a tmp file |
|
| 1200 | + { |
|
| 1201 | + $rel_filetodelete = preg_replace('/^[\\/]/', '', $rel_filetodelete); |
|
| 1202 | + |
|
| 1203 | + if (is_object($db) && $indexdatabase) // $db may not be defined when lib is in a context with define('NOREQUIREDB',1) |
|
| 1204 | + { |
|
| 1205 | + dol_syslog("Try to remove also entries in database for full relative path = ".$rel_filetodelete, LOG_DEBUG); |
|
| 1206 | + include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; |
|
| 1207 | + $ecmfile=new EcmFiles($db); |
|
| 1208 | + $result = $ecmfile->fetch(0, '', $rel_filetodelete); |
|
| 1209 | + if ($result >= 0 && $ecmfile->id > 0) |
|
| 1210 | + { |
|
| 1211 | + $result = $ecmfile->delete($user); |
|
| 1212 | + } |
|
| 1213 | + if ($result < 0) |
|
| 1214 | + { |
|
| 1215 | + setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings'); |
|
| 1216 | + } |
|
| 1217 | + } |
|
| 1218 | + } |
|
| 1219 | + } |
|
| 1220 | + else dol_syslog("Failed to remove file ".$filename, LOG_WARNING); |
|
| 1221 | + // TODO Failure to remove can be because file was already removed or because of permission |
|
| 1222 | + // If error because it does not exists, we should return true, and we should return false if this is a permission problem |
|
| 1223 | + } |
|
| 1224 | + } |
|
| 1225 | + else dol_syslog("No files to delete found", LOG_DEBUG); |
|
| 1226 | + } |
|
| 1227 | + else |
|
| 1228 | + { |
|
| 1229 | + $ok=false; |
|
| 1230 | + if ($nophperrors) $ok=@unlink($file_osencoded); |
|
| 1231 | + else $ok=unlink($file_osencoded); |
|
| 1232 | + if ($ok) dol_syslog("Removed file ".$file_osencoded, LOG_DEBUG); |
|
| 1233 | + else dol_syslog("Failed to remove file ".$file_osencoded, LOG_WARNING); |
|
| 1234 | + } |
|
| 1235 | + |
|
| 1236 | + return $ok; |
|
| 1237 | + } |
|
| 1238 | 1238 | } |
| 1239 | 1239 | |
| 1240 | 1240 | /** |
@@ -1248,16 +1248,16 @@ discard block |
||
| 1248 | 1248 | */ |
| 1249 | 1249 | function dol_delete_dir($dir,$nophperrors=0) |
| 1250 | 1250 | { |
| 1251 | - // Security: |
|
| 1252 | - // We refuse transversal using .. and pipes into filenames. |
|
| 1253 | - if (preg_match('/\.\./',$dir) || preg_match('/[<>|]/',$dir)) |
|
| 1254 | - { |
|
| 1255 | - dol_syslog("Refused to delete dir ".$dir, LOG_WARNING); |
|
| 1256 | - return false; |
|
| 1257 | - } |
|
| 1258 | - |
|
| 1259 | - $dir_osencoded=dol_osencode($dir); |
|
| 1260 | - return ($nophperrors?@rmdir($dir_osencoded):rmdir($dir_osencoded)); |
|
| 1251 | + // Security: |
|
| 1252 | + // We refuse transversal using .. and pipes into filenames. |
|
| 1253 | + if (preg_match('/\.\./',$dir) || preg_match('/[<>|]/',$dir)) |
|
| 1254 | + { |
|
| 1255 | + dol_syslog("Refused to delete dir ".$dir, LOG_WARNING); |
|
| 1256 | + return false; |
|
| 1257 | + } |
|
| 1258 | + |
|
| 1259 | + $dir_osencoded=dol_osencode($dir); |
|
| 1260 | + return ($nophperrors?@rmdir($dir_osencoded):rmdir($dir_osencoded)); |
|
| 1261 | 1261 | } |
| 1262 | 1262 | |
| 1263 | 1263 | /** |
@@ -1272,44 +1272,44 @@ discard block |
||
| 1272 | 1272 | */ |
| 1273 | 1273 | function dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0) |
| 1274 | 1274 | { |
| 1275 | - dol_syslog("functions.lib:dol_delete_dir_recursive ".$dir,LOG_DEBUG); |
|
| 1276 | - if (dol_is_dir($dir)) |
|
| 1277 | - { |
|
| 1278 | - $dir_osencoded=dol_osencode($dir); |
|
| 1279 | - if ($handle = opendir("$dir_osencoded")) |
|
| 1280 | - { |
|
| 1281 | - while (false !== ($item = readdir($handle))) |
|
| 1282 | - { |
|
| 1283 | - if (! utf8_check($item)) $item=utf8_encode($item); // should be useless |
|
| 1284 | - |
|
| 1285 | - if ($item != "." && $item != "..") |
|
| 1286 | - { |
|
| 1287 | - if (is_dir(dol_osencode("$dir/$item")) && ! is_link(dol_osencode("$dir/$item"))) |
|
| 1288 | - { |
|
| 1289 | - $count=dol_delete_dir_recursive("$dir/$item", $count, $nophperrors, 0, $countdeleted); |
|
| 1290 | - } |
|
| 1291 | - else |
|
| 1292 | - { |
|
| 1293 | - $result=dol_delete_file("$dir/$item", 1, $nophperrors); |
|
| 1294 | - $count++; |
|
| 1295 | - if ($result) $countdeleted++; |
|
| 1296 | - //else print 'Error on '.$item."\n"; |
|
| 1297 | - } |
|
| 1298 | - } |
|
| 1299 | - } |
|
| 1300 | - closedir($handle); |
|
| 1301 | - |
|
| 1302 | - if (empty($onlysub)) |
|
| 1303 | - { |
|
| 1304 | - $result=dol_delete_dir($dir, $nophperrors); |
|
| 1305 | - $count++; |
|
| 1306 | - if ($result) $countdeleted++; |
|
| 1307 | - //else print 'Error on '.$dir."\n"; |
|
| 1308 | - } |
|
| 1309 | - } |
|
| 1310 | - } |
|
| 1311 | - |
|
| 1312 | - return $count; |
|
| 1275 | + dol_syslog("functions.lib:dol_delete_dir_recursive ".$dir,LOG_DEBUG); |
|
| 1276 | + if (dol_is_dir($dir)) |
|
| 1277 | + { |
|
| 1278 | + $dir_osencoded=dol_osencode($dir); |
|
| 1279 | + if ($handle = opendir("$dir_osencoded")) |
|
| 1280 | + { |
|
| 1281 | + while (false !== ($item = readdir($handle))) |
|
| 1282 | + { |
|
| 1283 | + if (! utf8_check($item)) $item=utf8_encode($item); // should be useless |
|
| 1284 | + |
|
| 1285 | + if ($item != "." && $item != "..") |
|
| 1286 | + { |
|
| 1287 | + if (is_dir(dol_osencode("$dir/$item")) && ! is_link(dol_osencode("$dir/$item"))) |
|
| 1288 | + { |
|
| 1289 | + $count=dol_delete_dir_recursive("$dir/$item", $count, $nophperrors, 0, $countdeleted); |
|
| 1290 | + } |
|
| 1291 | + else |
|
| 1292 | + { |
|
| 1293 | + $result=dol_delete_file("$dir/$item", 1, $nophperrors); |
|
| 1294 | + $count++; |
|
| 1295 | + if ($result) $countdeleted++; |
|
| 1296 | + //else print 'Error on '.$item."\n"; |
|
| 1297 | + } |
|
| 1298 | + } |
|
| 1299 | + } |
|
| 1300 | + closedir($handle); |
|
| 1301 | + |
|
| 1302 | + if (empty($onlysub)) |
|
| 1303 | + { |
|
| 1304 | + $result=dol_delete_dir($dir, $nophperrors); |
|
| 1305 | + $count++; |
|
| 1306 | + if ($result) $countdeleted++; |
|
| 1307 | + //else print 'Error on '.$dir."\n"; |
|
| 1308 | + } |
|
| 1309 | + } |
|
| 1310 | + } |
|
| 1311 | + |
|
| 1312 | + return $count; |
|
| 1313 | 1313 | } |
| 1314 | 1314 | |
| 1315 | 1315 | |
@@ -1323,72 +1323,72 @@ discard block |
||
| 1323 | 1323 | */ |
| 1324 | 1324 | function dol_delete_preview($object) |
| 1325 | 1325 | { |
| 1326 | - global $langs,$conf; |
|
| 1327 | - |
|
| 1328 | - // Define parent dir of elements |
|
| 1329 | - $element = $object->element; |
|
| 1330 | - |
|
| 1331 | - if ($object->element == 'order_supplier') $dir = $conf->fournisseur->commande->dir_output; |
|
| 1332 | - elseif ($object->element == 'invoice_supplier') $dir = $conf->fournisseur->facture->dir_output; |
|
| 1333 | - elseif ($object->element == 'project') $dir = $conf->projet->dir_output; |
|
| 1334 | - elseif ($object->element == 'shipping') $dir = $conf->expedition->dir_output.'/sending'; |
|
| 1335 | - elseif ($object->element == 'delivery') $dir = $conf->expedition->dir_output.'/receipt'; |
|
| 1336 | - elseif ($object->element == 'fichinter') $dir = $conf->ficheinter->dir_output; |
|
| 1337 | - else $dir=empty($conf->$element->dir_output)?'':$conf->$element->dir_output; |
|
| 1338 | - |
|
| 1339 | - if (empty($dir)) return 'ErrorObjectNoSupportedByFunction'; |
|
| 1340 | - |
|
| 1341 | - $refsan = dol_sanitizeFileName($object->ref); |
|
| 1342 | - $dir = $dir . "/" . $refsan ; |
|
| 1343 | - $filepreviewnew = $dir . "/" . $refsan . ".pdf_preview.png"; |
|
| 1344 | - $filepreviewnewbis = $dir . "/" . $refsan . ".pdf_preview-0.png"; |
|
| 1345 | - $filepreviewold = $dir . "/" . $refsan . ".pdf.png"; |
|
| 1346 | - |
|
| 1347 | - // For new preview files |
|
| 1348 | - if (file_exists($filepreviewnew) && is_writable($filepreviewnew)) |
|
| 1349 | - { |
|
| 1350 | - if (! dol_delete_file($filepreviewnew,1)) |
|
| 1351 | - { |
|
| 1352 | - $object->error=$langs->trans("ErrorFailedToDeleteFile",$filepreviewnew); |
|
| 1353 | - return 0; |
|
| 1354 | - } |
|
| 1355 | - } |
|
| 1356 | - if (file_exists($filepreviewnewbis) && is_writable($filepreviewnewbis)) |
|
| 1357 | - { |
|
| 1358 | - if (! dol_delete_file($filepreviewnewbis,1)) |
|
| 1359 | - { |
|
| 1360 | - $object->error=$langs->trans("ErrorFailedToDeleteFile",$filepreviewnewbis); |
|
| 1361 | - return 0; |
|
| 1362 | - } |
|
| 1363 | - } |
|
| 1364 | - // For old preview files |
|
| 1365 | - if (file_exists($filepreviewold) && is_writable($filepreviewold)) |
|
| 1366 | - { |
|
| 1367 | - if (! dol_delete_file($filepreviewold,1)) |
|
| 1368 | - { |
|
| 1369 | - $object->error=$langs->trans("ErrorFailedToDeleteFile",$filepreviewold); |
|
| 1370 | - return 0; |
|
| 1371 | - } |
|
| 1372 | - } |
|
| 1373 | - else |
|
| 1374 | - { |
|
| 1375 | - $multiple = $filepreviewold . "."; |
|
| 1376 | - for ($i = 0; $i < 20; $i++) |
|
| 1377 | - { |
|
| 1378 | - $preview = $multiple.$i; |
|
| 1379 | - |
|
| 1380 | - if (file_exists($preview) && is_writable($preview)) |
|
| 1381 | - { |
|
| 1382 | - if ( ! dol_delete_file($preview,1) ) |
|
| 1383 | - { |
|
| 1384 | - $object->error=$langs->trans("ErrorFailedToOpenFile",$preview); |
|
| 1385 | - return 0; |
|
| 1386 | - } |
|
| 1387 | - } |
|
| 1388 | - } |
|
| 1389 | - } |
|
| 1390 | - |
|
| 1391 | - return 1; |
|
| 1326 | + global $langs,$conf; |
|
| 1327 | + |
|
| 1328 | + // Define parent dir of elements |
|
| 1329 | + $element = $object->element; |
|
| 1330 | + |
|
| 1331 | + if ($object->element == 'order_supplier') $dir = $conf->fournisseur->commande->dir_output; |
|
| 1332 | + elseif ($object->element == 'invoice_supplier') $dir = $conf->fournisseur->facture->dir_output; |
|
| 1333 | + elseif ($object->element == 'project') $dir = $conf->projet->dir_output; |
|
| 1334 | + elseif ($object->element == 'shipping') $dir = $conf->expedition->dir_output.'/sending'; |
|
| 1335 | + elseif ($object->element == 'delivery') $dir = $conf->expedition->dir_output.'/receipt'; |
|
| 1336 | + elseif ($object->element == 'fichinter') $dir = $conf->ficheinter->dir_output; |
|
| 1337 | + else $dir=empty($conf->$element->dir_output)?'':$conf->$element->dir_output; |
|
| 1338 | + |
|
| 1339 | + if (empty($dir)) return 'ErrorObjectNoSupportedByFunction'; |
|
| 1340 | + |
|
| 1341 | + $refsan = dol_sanitizeFileName($object->ref); |
|
| 1342 | + $dir = $dir . "/" . $refsan ; |
|
| 1343 | + $filepreviewnew = $dir . "/" . $refsan . ".pdf_preview.png"; |
|
| 1344 | + $filepreviewnewbis = $dir . "/" . $refsan . ".pdf_preview-0.png"; |
|
| 1345 | + $filepreviewold = $dir . "/" . $refsan . ".pdf.png"; |
|
| 1346 | + |
|
| 1347 | + // For new preview files |
|
| 1348 | + if (file_exists($filepreviewnew) && is_writable($filepreviewnew)) |
|
| 1349 | + { |
|
| 1350 | + if (! dol_delete_file($filepreviewnew,1)) |
|
| 1351 | + { |
|
| 1352 | + $object->error=$langs->trans("ErrorFailedToDeleteFile",$filepreviewnew); |
|
| 1353 | + return 0; |
|
| 1354 | + } |
|
| 1355 | + } |
|
| 1356 | + if (file_exists($filepreviewnewbis) && is_writable($filepreviewnewbis)) |
|
| 1357 | + { |
|
| 1358 | + if (! dol_delete_file($filepreviewnewbis,1)) |
|
| 1359 | + { |
|
| 1360 | + $object->error=$langs->trans("ErrorFailedToDeleteFile",$filepreviewnewbis); |
|
| 1361 | + return 0; |
|
| 1362 | + } |
|
| 1363 | + } |
|
| 1364 | + // For old preview files |
|
| 1365 | + if (file_exists($filepreviewold) && is_writable($filepreviewold)) |
|
| 1366 | + { |
|
| 1367 | + if (! dol_delete_file($filepreviewold,1)) |
|
| 1368 | + { |
|
| 1369 | + $object->error=$langs->trans("ErrorFailedToDeleteFile",$filepreviewold); |
|
| 1370 | + return 0; |
|
| 1371 | + } |
|
| 1372 | + } |
|
| 1373 | + else |
|
| 1374 | + { |
|
| 1375 | + $multiple = $filepreviewold . "."; |
|
| 1376 | + for ($i = 0; $i < 20; $i++) |
|
| 1377 | + { |
|
| 1378 | + $preview = $multiple.$i; |
|
| 1379 | + |
|
| 1380 | + if (file_exists($preview) && is_writable($preview)) |
|
| 1381 | + { |
|
| 1382 | + if ( ! dol_delete_file($preview,1) ) |
|
| 1383 | + { |
|
| 1384 | + $object->error=$langs->trans("ErrorFailedToOpenFile",$preview); |
|
| 1385 | + return 0; |
|
| 1386 | + } |
|
| 1387 | + } |
|
| 1388 | + } |
|
| 1389 | + } |
|
| 1390 | + |
|
| 1391 | + return 1; |
|
| 1392 | 1392 | } |
| 1393 | 1393 | |
| 1394 | 1394 | /** |
@@ -1401,71 +1401,71 @@ discard block |
||
| 1401 | 1401 | */ |
| 1402 | 1402 | function dol_meta_create($object) |
| 1403 | 1403 | { |
| 1404 | - global $conf; |
|
| 1405 | - |
|
| 1406 | - // Create meta file |
|
| 1407 | - if (empty($conf->global->MAIN_DOC_CREATE_METAFILE)) return 0; // By default, no metafile. |
|
| 1408 | - |
|
| 1409 | - // Define parent dir of elements |
|
| 1410 | - $element=$object->element; |
|
| 1411 | - |
|
| 1412 | - if ($object->element == 'order_supplier') $dir = $conf->fournisseur->dir_output.'/commande'; |
|
| 1413 | - elseif ($object->element == 'invoice_supplier') $dir = $conf->fournisseur->dir_output.'/facture'; |
|
| 1414 | - elseif ($object->element == 'project') $dir = $conf->projet->dir_output; |
|
| 1415 | - elseif ($object->element == 'shipping') $dir = $conf->expedition->dir_output.'/sending'; |
|
| 1416 | - elseif ($object->element == 'delivery') $dir = $conf->expedition->dir_output.'/receipt'; |
|
| 1417 | - elseif ($object->element == 'fichinter') $dir = $conf->ficheinter->dir_output; |
|
| 1418 | - else $dir=empty($conf->$element->dir_output)?'':$conf->$element->dir_output; |
|
| 1419 | - |
|
| 1420 | - if ($dir) |
|
| 1421 | - { |
|
| 1422 | - $object->fetch_thirdparty(); |
|
| 1423 | - |
|
| 1424 | - $objectref = dol_sanitizeFileName($object->ref); |
|
| 1425 | - $dir = $dir . "/" . $objectref; |
|
| 1426 | - $file = $dir . "/" . $objectref . ".meta"; |
|
| 1427 | - |
|
| 1428 | - if (! is_dir($dir)) |
|
| 1429 | - { |
|
| 1430 | - dol_mkdir($dir); |
|
| 1431 | - } |
|
| 1432 | - |
|
| 1433 | - if (is_dir($dir)) |
|
| 1434 | - { |
|
| 1435 | - $nblignes = count($object->lines); |
|
| 1436 | - $client = $object->thirdparty->name . " " . $object->thirdparty->address . " " . $object->thirdparty->zip . " " . $object->thirdparty->town; |
|
| 1437 | - $meta = "REFERENCE=\"" . $object->ref . "\" |
|
| 1404 | + global $conf; |
|
| 1405 | + |
|
| 1406 | + // Create meta file |
|
| 1407 | + if (empty($conf->global->MAIN_DOC_CREATE_METAFILE)) return 0; // By default, no metafile. |
|
| 1408 | + |
|
| 1409 | + // Define parent dir of elements |
|
| 1410 | + $element=$object->element; |
|
| 1411 | + |
|
| 1412 | + if ($object->element == 'order_supplier') $dir = $conf->fournisseur->dir_output.'/commande'; |
|
| 1413 | + elseif ($object->element == 'invoice_supplier') $dir = $conf->fournisseur->dir_output.'/facture'; |
|
| 1414 | + elseif ($object->element == 'project') $dir = $conf->projet->dir_output; |
|
| 1415 | + elseif ($object->element == 'shipping') $dir = $conf->expedition->dir_output.'/sending'; |
|
| 1416 | + elseif ($object->element == 'delivery') $dir = $conf->expedition->dir_output.'/receipt'; |
|
| 1417 | + elseif ($object->element == 'fichinter') $dir = $conf->ficheinter->dir_output; |
|
| 1418 | + else $dir=empty($conf->$element->dir_output)?'':$conf->$element->dir_output; |
|
| 1419 | + |
|
| 1420 | + if ($dir) |
|
| 1421 | + { |
|
| 1422 | + $object->fetch_thirdparty(); |
|
| 1423 | + |
|
| 1424 | + $objectref = dol_sanitizeFileName($object->ref); |
|
| 1425 | + $dir = $dir . "/" . $objectref; |
|
| 1426 | + $file = $dir . "/" . $objectref . ".meta"; |
|
| 1427 | + |
|
| 1428 | + if (! is_dir($dir)) |
|
| 1429 | + { |
|
| 1430 | + dol_mkdir($dir); |
|
| 1431 | + } |
|
| 1432 | + |
|
| 1433 | + if (is_dir($dir)) |
|
| 1434 | + { |
|
| 1435 | + $nblignes = count($object->lines); |
|
| 1436 | + $client = $object->thirdparty->name . " " . $object->thirdparty->address . " " . $object->thirdparty->zip . " " . $object->thirdparty->town; |
|
| 1437 | + $meta = "REFERENCE=\"" . $object->ref . "\" |
|
| 1438 | 1438 | DATE=\"" . dol_print_date($object->date,'') . "\" |
| 1439 | 1439 | NB_ITEMS=\"" . $nblignes . "\" |
| 1440 | 1440 | CLIENT=\"" . $client . "\" |
| 1441 | 1441 | AMOUNT_EXCL_TAX=\"" . $object->total_ht . "\" |
| 1442 | 1442 | AMOUNT=\"" . $object->total_ttc . "\"\n"; |
| 1443 | 1443 | |
| 1444 | - for ($i = 0 ; $i < $nblignes ; $i++) |
|
| 1445 | - { |
|
| 1446 | - //Pour les articles |
|
| 1447 | - $meta .= "ITEM_" . $i . "_QUANTITY=\"" . $object->lines[$i]->qty . "\" |
|
| 1444 | + for ($i = 0 ; $i < $nblignes ; $i++) |
|
| 1445 | + { |
|
| 1446 | + //Pour les articles |
|
| 1447 | + $meta .= "ITEM_" . $i . "_QUANTITY=\"" . $object->lines[$i]->qty . "\" |
|
| 1448 | 1448 | ITEM_" . $i . "_AMOUNT_WO_TAX=\"" . $object->lines[$i]->total_ht . "\" |
| 1449 | 1449 | ITEM_" . $i . "_VAT=\"" .$object->lines[$i]->tva_tx . "\" |
| 1450 | 1450 | ITEM_" . $i . "_DESCRIPTION=\"" . str_replace("\r\n","",nl2br($object->lines[$i]->desc)) . "\" |
| 1451 | 1451 | "; |
| 1452 | - } |
|
| 1453 | - } |
|
| 1454 | - |
|
| 1455 | - $fp = fopen($file,"w"); |
|
| 1456 | - fputs($fp,$meta); |
|
| 1457 | - fclose($fp); |
|
| 1458 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 1459 | - @chmod($file, octdec($conf->global->MAIN_UMASK)); |
|
| 1460 | - |
|
| 1461 | - return 1; |
|
| 1462 | - } |
|
| 1463 | - else |
|
| 1464 | - { |
|
| 1465 | - dol_syslog('FailedToDetectDirInDolMetaCreateFor'.$object->element, LOG_WARNING); |
|
| 1466 | - } |
|
| 1467 | - |
|
| 1468 | - return 0; |
|
| 1452 | + } |
|
| 1453 | + } |
|
| 1454 | + |
|
| 1455 | + $fp = fopen($file,"w"); |
|
| 1456 | + fputs($fp,$meta); |
|
| 1457 | + fclose($fp); |
|
| 1458 | + if (! empty($conf->global->MAIN_UMASK)) |
|
| 1459 | + @chmod($file, octdec($conf->global->MAIN_UMASK)); |
|
| 1460 | + |
|
| 1461 | + return 1; |
|
| 1462 | + } |
|
| 1463 | + else |
|
| 1464 | + { |
|
| 1465 | + dol_syslog('FailedToDetectDirInDolMetaCreateFor'.$object->element, LOG_WARNING); |
|
| 1466 | + } |
|
| 1467 | + |
|
| 1468 | + return 0; |
|
| 1469 | 1469 | } |
| 1470 | 1470 | |
| 1471 | 1471 | |
@@ -1480,24 +1480,24 @@ discard block |
||
| 1480 | 1480 | */ |
| 1481 | 1481 | function dol_init_file_process($pathtoscan='', $trackid='') |
| 1482 | 1482 | { |
| 1483 | - $listofpaths=array(); |
|
| 1484 | - $listofnames=array(); |
|
| 1485 | - $listofmimes=array(); |
|
| 1486 | - |
|
| 1487 | - if ($pathtoscan) |
|
| 1488 | - { |
|
| 1489 | - $listoffiles=dol_dir_list($pathtoscan,'files'); |
|
| 1490 | - foreach($listoffiles as $key => $val) |
|
| 1491 | - { |
|
| 1492 | - $listofpaths[]=$val['fullname']; |
|
| 1493 | - $listofnames[]=$val['name']; |
|
| 1494 | - $listofmimes[]=dol_mimetype($val['name']); |
|
| 1495 | - } |
|
| 1496 | - } |
|
| 1497 | - $keytoavoidconflict = empty($trackid)?'':'-'.$trackid; |
|
| 1498 | - $_SESSION["listofpaths".$keytoavoidconflict]=join(';',$listofpaths); |
|
| 1499 | - $_SESSION["listofnames".$keytoavoidconflict]=join(';',$listofnames); |
|
| 1500 | - $_SESSION["listofmimes".$keytoavoidconflict]=join(';',$listofmimes); |
|
| 1483 | + $listofpaths=array(); |
|
| 1484 | + $listofnames=array(); |
|
| 1485 | + $listofmimes=array(); |
|
| 1486 | + |
|
| 1487 | + if ($pathtoscan) |
|
| 1488 | + { |
|
| 1489 | + $listoffiles=dol_dir_list($pathtoscan,'files'); |
|
| 1490 | + foreach($listoffiles as $key => $val) |
|
| 1491 | + { |
|
| 1492 | + $listofpaths[]=$val['fullname']; |
|
| 1493 | + $listofnames[]=$val['name']; |
|
| 1494 | + $listofmimes[]=dol_mimetype($val['name']); |
|
| 1495 | + } |
|
| 1496 | + } |
|
| 1497 | + $keytoavoidconflict = empty($trackid)?'':'-'.$trackid; |
|
| 1498 | + $_SESSION["listofpaths".$keytoavoidconflict]=join(';',$listofpaths); |
|
| 1499 | + $_SESSION["listofnames".$keytoavoidconflict]=join(';',$listofnames); |
|
| 1500 | + $_SESSION["listofmimes".$keytoavoidconflict]=join(';',$listofmimes); |
|
| 1501 | 1501 | } |
| 1502 | 1502 | |
| 1503 | 1503 | |
@@ -1518,135 +1518,135 @@ discard block |
||
| 1518 | 1518 | */ |
| 1519 | 1519 | function dol_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesession=0, $varfiles='addedfile', $savingdocmask='', $link=null, $trackid='', $generatethumbs=1) |
| 1520 | 1520 | { |
| 1521 | - global $db,$user,$conf,$langs; |
|
| 1522 | - |
|
| 1523 | - $res = 0; |
|
| 1524 | - |
|
| 1525 | - if (! empty($_FILES[$varfiles])) // For view $_FILES[$varfiles]['error'] |
|
| 1526 | - { |
|
| 1527 | - dol_syslog('dol_add_file_process upload_dir='.$upload_dir.' allowoverwrite='.$allowoverwrite.' donotupdatesession='.$donotupdatesession.' savingdocmask='.$savingdocmask, LOG_DEBUG); |
|
| 1528 | - if (dol_mkdir($upload_dir) >= 0) |
|
| 1529 | - { |
|
| 1530 | - $TFile = $_FILES[$varfiles]; |
|
| 1531 | - if (!is_array($TFile['name'])) |
|
| 1532 | - { |
|
| 1533 | - foreach ($TFile as $key => &$val) |
|
| 1534 | - { |
|
| 1535 | - $val = array($val); |
|
| 1536 | - } |
|
| 1537 | - } |
|
| 1538 | - |
|
| 1539 | - $nbfile = count($TFile['name']); |
|
| 1540 | - $nbok = 0; |
|
| 1541 | - for ($i = 0; $i < $nbfile; $i++) |
|
| 1542 | - { |
|
| 1543 | - // Define $destfull (path to file including filename) and $destfile (only filename) |
|
| 1544 | - $destfull=$upload_dir . "/" . $TFile['name'][$i]; |
|
| 1545 | - $destfile=$TFile['name'][$i]; |
|
| 1546 | - |
|
| 1547 | - if ($savingdocmask) |
|
| 1548 | - { |
|
| 1549 | - $destfull=$upload_dir . "/" . preg_replace('/__file__/',$TFile['name'][$i],$savingdocmask); |
|
| 1550 | - $destfile=preg_replace('/__file__/',$TFile['name'][$i],$savingdocmask); |
|
| 1551 | - } |
|
| 1552 | - |
|
| 1553 | - // dol_sanitizeFileName the file name and lowercase extension |
|
| 1554 | - $info = pathinfo($destfull); |
|
| 1555 | - $destfull = $info['dirname'].'/'.dol_sanitizeFileName($info['filename'].'.'.strtolower($info['extension'])); |
|
| 1556 | - $info = pathinfo($destfile); |
|
| 1557 | - $destfile = dol_sanitizeFileName($info['filename'].'.'.strtolower($info['extension'])); |
|
| 1558 | - |
|
| 1559 | - $resupload = dol_move_uploaded_file($TFile['tmp_name'][$i], $destfull, $allowoverwrite, 0, $TFile['error'][$i], 0, $varfiles); |
|
| 1560 | - |
|
| 1561 | - if (is_numeric($resupload) && $resupload > 0) // $resupload can be 'ErrorFileAlreadyExists' |
|
| 1562 | - { |
|
| 1563 | - global $maxwidthsmall, $maxheightsmall, $maxwidthmini, $maxheightmini; |
|
| 1564 | - |
|
| 1565 | - include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; |
|
| 1566 | - |
|
| 1567 | - // Generate thumbs. |
|
| 1568 | - if ($generatethumbs) |
|
| 1569 | - { |
|
| 1570 | - if (image_format_supported($destfull) == 1) |
|
| 1571 | - { |
|
| 1572 | - // Create thumbs |
|
| 1573 | - // We can't use $object->addThumbs here because there is no $object known |
|
| 1574 | - |
|
| 1575 | - // Used on logon for example |
|
| 1576 | - $imgThumbSmall = vignette($destfull, $maxwidthsmall, $maxheightsmall, '_small', 50, "thumbs"); |
|
| 1577 | - // Create mini thumbs for image (Ratio is near 16/9) |
|
| 1578 | - // Used on menu or for setup page for example |
|
| 1579 | - $imgThumbMini = vignette($destfull, $maxwidthmini, $maxheightmini, '_mini', 50, "thumbs"); |
|
| 1580 | - } |
|
| 1581 | - } |
|
| 1582 | - |
|
| 1583 | - // Update session |
|
| 1584 | - if (empty($donotupdatesession)) |
|
| 1585 | - { |
|
| 1586 | - include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; |
|
| 1587 | - $formmail = new FormMail($db); |
|
| 1588 | - $formmail->trackid = $trackid; |
|
| 1589 | - $formmail->add_attached_files($destfull, $destfile, $TFile['type'][$i]); |
|
| 1590 | - } |
|
| 1591 | - |
|
| 1592 | - // Update table of files |
|
| 1593 | - if ($donotupdatesession == 1) |
|
| 1594 | - { |
|
| 1595 | - $result = addFileIntoDatabaseIndex($upload_dir, basename($destfile), $TFile['name'][$i], 'uploaded', 0); |
|
| 1596 | - if ($result < 0) |
|
| 1597 | - { |
|
| 1598 | - setEventMessages('FailedToAddFileIntoDatabaseIndex', '', 'warnings'); |
|
| 1599 | - } |
|
| 1600 | - } |
|
| 1601 | - |
|
| 1602 | - $nbok++; |
|
| 1603 | - } |
|
| 1604 | - else |
|
| 1605 | - { |
|
| 1606 | - $langs->load("errors"); |
|
| 1607 | - if ($resupload < 0) // Unknown error |
|
| 1608 | - { |
|
| 1609 | - setEventMessages($langs->trans("ErrorFileNotUploaded"), null, 'errors'); |
|
| 1610 | - } |
|
| 1611 | - else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus |
|
| 1612 | - { |
|
| 1613 | - setEventMessages($langs->trans("ErrorFileIsInfectedWithAVirus"), null, 'errors'); |
|
| 1614 | - } |
|
| 1615 | - else // Known error |
|
| 1616 | - { |
|
| 1617 | - setEventMessages($langs->trans($resupload), null, 'errors'); |
|
| 1618 | - } |
|
| 1619 | - } |
|
| 1620 | - } |
|
| 1621 | - if ($nbok > 0) |
|
| 1622 | - { |
|
| 1623 | - $res = 1; |
|
| 1624 | - setEventMessages($langs->trans("FileTransferComplete"), null, 'mesgs'); |
|
| 1625 | - } |
|
| 1626 | - } |
|
| 1627 | - } elseif ($link) { |
|
| 1628 | - require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php'; |
|
| 1629 | - $linkObject = new Link($db); |
|
| 1630 | - $linkObject->entity = $conf->entity; |
|
| 1631 | - $linkObject->url = $link; |
|
| 1632 | - $linkObject->objecttype = GETPOST('objecttype', 'alpha'); |
|
| 1633 | - $linkObject->objectid = GETPOST('objectid', 'int'); |
|
| 1634 | - $linkObject->label = GETPOST('label', 'alpha'); |
|
| 1635 | - $res = $linkObject->create($user); |
|
| 1636 | - $langs->load('link'); |
|
| 1637 | - if ($res > 0) { |
|
| 1638 | - setEventMessages($langs->trans("LinkComplete"), null, 'mesgs'); |
|
| 1639 | - } else { |
|
| 1640 | - setEventMessages($langs->trans("ErrorFileNotLinked"), null, 'errors'); |
|
| 1641 | - } |
|
| 1642 | - } |
|
| 1643 | - else |
|
| 1644 | - { |
|
| 1645 | - $langs->load("errors"); |
|
| 1646 | - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("File")), null, 'errors'); |
|
| 1647 | - } |
|
| 1648 | - |
|
| 1649 | - return $res; |
|
| 1521 | + global $db,$user,$conf,$langs; |
|
| 1522 | + |
|
| 1523 | + $res = 0; |
|
| 1524 | + |
|
| 1525 | + if (! empty($_FILES[$varfiles])) // For view $_FILES[$varfiles]['error'] |
|
| 1526 | + { |
|
| 1527 | + dol_syslog('dol_add_file_process upload_dir='.$upload_dir.' allowoverwrite='.$allowoverwrite.' donotupdatesession='.$donotupdatesession.' savingdocmask='.$savingdocmask, LOG_DEBUG); |
|
| 1528 | + if (dol_mkdir($upload_dir) >= 0) |
|
| 1529 | + { |
|
| 1530 | + $TFile = $_FILES[$varfiles]; |
|
| 1531 | + if (!is_array($TFile['name'])) |
|
| 1532 | + { |
|
| 1533 | + foreach ($TFile as $key => &$val) |
|
| 1534 | + { |
|
| 1535 | + $val = array($val); |
|
| 1536 | + } |
|
| 1537 | + } |
|
| 1538 | + |
|
| 1539 | + $nbfile = count($TFile['name']); |
|
| 1540 | + $nbok = 0; |
|
| 1541 | + for ($i = 0; $i < $nbfile; $i++) |
|
| 1542 | + { |
|
| 1543 | + // Define $destfull (path to file including filename) and $destfile (only filename) |
|
| 1544 | + $destfull=$upload_dir . "/" . $TFile['name'][$i]; |
|
| 1545 | + $destfile=$TFile['name'][$i]; |
|
| 1546 | + |
|
| 1547 | + if ($savingdocmask) |
|
| 1548 | + { |
|
| 1549 | + $destfull=$upload_dir . "/" . preg_replace('/__file__/',$TFile['name'][$i],$savingdocmask); |
|
| 1550 | + $destfile=preg_replace('/__file__/',$TFile['name'][$i],$savingdocmask); |
|
| 1551 | + } |
|
| 1552 | + |
|
| 1553 | + // dol_sanitizeFileName the file name and lowercase extension |
|
| 1554 | + $info = pathinfo($destfull); |
|
| 1555 | + $destfull = $info['dirname'].'/'.dol_sanitizeFileName($info['filename'].'.'.strtolower($info['extension'])); |
|
| 1556 | + $info = pathinfo($destfile); |
|
| 1557 | + $destfile = dol_sanitizeFileName($info['filename'].'.'.strtolower($info['extension'])); |
|
| 1558 | + |
|
| 1559 | + $resupload = dol_move_uploaded_file($TFile['tmp_name'][$i], $destfull, $allowoverwrite, 0, $TFile['error'][$i], 0, $varfiles); |
|
| 1560 | + |
|
| 1561 | + if (is_numeric($resupload) && $resupload > 0) // $resupload can be 'ErrorFileAlreadyExists' |
|
| 1562 | + { |
|
| 1563 | + global $maxwidthsmall, $maxheightsmall, $maxwidthmini, $maxheightmini; |
|
| 1564 | + |
|
| 1565 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; |
|
| 1566 | + |
|
| 1567 | + // Generate thumbs. |
|
| 1568 | + if ($generatethumbs) |
|
| 1569 | + { |
|
| 1570 | + if (image_format_supported($destfull) == 1) |
|
| 1571 | + { |
|
| 1572 | + // Create thumbs |
|
| 1573 | + // We can't use $object->addThumbs here because there is no $object known |
|
| 1574 | + |
|
| 1575 | + // Used on logon for example |
|
| 1576 | + $imgThumbSmall = vignette($destfull, $maxwidthsmall, $maxheightsmall, '_small', 50, "thumbs"); |
|
| 1577 | + // Create mini thumbs for image (Ratio is near 16/9) |
|
| 1578 | + // Used on menu or for setup page for example |
|
| 1579 | + $imgThumbMini = vignette($destfull, $maxwidthmini, $maxheightmini, '_mini', 50, "thumbs"); |
|
| 1580 | + } |
|
| 1581 | + } |
|
| 1582 | + |
|
| 1583 | + // Update session |
|
| 1584 | + if (empty($donotupdatesession)) |
|
| 1585 | + { |
|
| 1586 | + include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; |
|
| 1587 | + $formmail = new FormMail($db); |
|
| 1588 | + $formmail->trackid = $trackid; |
|
| 1589 | + $formmail->add_attached_files($destfull, $destfile, $TFile['type'][$i]); |
|
| 1590 | + } |
|
| 1591 | + |
|
| 1592 | + // Update table of files |
|
| 1593 | + if ($donotupdatesession == 1) |
|
| 1594 | + { |
|
| 1595 | + $result = addFileIntoDatabaseIndex($upload_dir, basename($destfile), $TFile['name'][$i], 'uploaded', 0); |
|
| 1596 | + if ($result < 0) |
|
| 1597 | + { |
|
| 1598 | + setEventMessages('FailedToAddFileIntoDatabaseIndex', '', 'warnings'); |
|
| 1599 | + } |
|
| 1600 | + } |
|
| 1601 | + |
|
| 1602 | + $nbok++; |
|
| 1603 | + } |
|
| 1604 | + else |
|
| 1605 | + { |
|
| 1606 | + $langs->load("errors"); |
|
| 1607 | + if ($resupload < 0) // Unknown error |
|
| 1608 | + { |
|
| 1609 | + setEventMessages($langs->trans("ErrorFileNotUploaded"), null, 'errors'); |
|
| 1610 | + } |
|
| 1611 | + else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus |
|
| 1612 | + { |
|
| 1613 | + setEventMessages($langs->trans("ErrorFileIsInfectedWithAVirus"), null, 'errors'); |
|
| 1614 | + } |
|
| 1615 | + else // Known error |
|
| 1616 | + { |
|
| 1617 | + setEventMessages($langs->trans($resupload), null, 'errors'); |
|
| 1618 | + } |
|
| 1619 | + } |
|
| 1620 | + } |
|
| 1621 | + if ($nbok > 0) |
|
| 1622 | + { |
|
| 1623 | + $res = 1; |
|
| 1624 | + setEventMessages($langs->trans("FileTransferComplete"), null, 'mesgs'); |
|
| 1625 | + } |
|
| 1626 | + } |
|
| 1627 | + } elseif ($link) { |
|
| 1628 | + require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php'; |
|
| 1629 | + $linkObject = new Link($db); |
|
| 1630 | + $linkObject->entity = $conf->entity; |
|
| 1631 | + $linkObject->url = $link; |
|
| 1632 | + $linkObject->objecttype = GETPOST('objecttype', 'alpha'); |
|
| 1633 | + $linkObject->objectid = GETPOST('objectid', 'int'); |
|
| 1634 | + $linkObject->label = GETPOST('label', 'alpha'); |
|
| 1635 | + $res = $linkObject->create($user); |
|
| 1636 | + $langs->load('link'); |
|
| 1637 | + if ($res > 0) { |
|
| 1638 | + setEventMessages($langs->trans("LinkComplete"), null, 'mesgs'); |
|
| 1639 | + } else { |
|
| 1640 | + setEventMessages($langs->trans("ErrorFileNotLinked"), null, 'errors'); |
|
| 1641 | + } |
|
| 1642 | + } |
|
| 1643 | + else |
|
| 1644 | + { |
|
| 1645 | + $langs->load("errors"); |
|
| 1646 | + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("File")), null, 'errors'); |
|
| 1647 | + } |
|
| 1648 | + |
|
| 1649 | + return $res; |
|
| 1650 | 1650 | } |
| 1651 | 1651 | |
| 1652 | 1652 | |
@@ -1662,41 +1662,41 @@ discard block |
||
| 1662 | 1662 | */ |
| 1663 | 1663 | function dol_remove_file_process($filenb,$donotupdatesession=0,$donotdeletefile=1,$trackid='') |
| 1664 | 1664 | { |
| 1665 | - global $db,$user,$conf,$langs,$_FILES; |
|
| 1666 | - |
|
| 1667 | - $keytodelete=$filenb; |
|
| 1668 | - $keytodelete--; |
|
| 1669 | - |
|
| 1670 | - $listofpaths=array(); |
|
| 1671 | - $listofnames=array(); |
|
| 1672 | - $listofmimes=array(); |
|
| 1673 | - $keytoavoidconflict = empty($trackid)?'':'-'.$trackid; |
|
| 1674 | - if (! empty($_SESSION["listofpaths".$keytoavoidconflict])) $listofpaths=explode(';',$_SESSION["listofpaths".$keytoavoidconflict]); |
|
| 1675 | - if (! empty($_SESSION["listofnames".$keytoavoidconflict])) $listofnames=explode(';',$_SESSION["listofnames".$keytoavoidconflict]); |
|
| 1676 | - if (! empty($_SESSION["listofmimes".$keytoavoidconflict])) $listofmimes=explode(';',$_SESSION["listofmimes".$keytoavoidconflict]); |
|
| 1677 | - |
|
| 1678 | - if ($keytodelete >= 0) |
|
| 1679 | - { |
|
| 1680 | - $pathtodelete=$listofpaths[$keytodelete]; |
|
| 1681 | - $filetodelete=$listofnames[$keytodelete]; |
|
| 1682 | - if (empty($donotdeletefile)) $result = dol_delete_file($pathtodelete,1); // The delete of ecm database is inside the function dol_delete_file |
|
| 1683 | - else $result=0; |
|
| 1684 | - if ($result >= 0) |
|
| 1685 | - { |
|
| 1686 | - if (empty($donotdeletefile)) |
|
| 1687 | - { |
|
| 1688 | - $langs->load("other"); |
|
| 1689 | - setEventMessages($langs->trans("FileWasRemoved",$filetodelete), null, 'mesgs'); |
|
| 1690 | - } |
|
| 1691 | - if (empty($donotupdatesession)) |
|
| 1692 | - { |
|
| 1693 | - include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; |
|
| 1694 | - $formmail = new FormMail($db); |
|
| 1695 | - $formmail->trackid = $trackid; |
|
| 1696 | - $formmail->remove_attached_files($keytodelete); |
|
| 1697 | - } |
|
| 1698 | - } |
|
| 1699 | - } |
|
| 1665 | + global $db,$user,$conf,$langs,$_FILES; |
|
| 1666 | + |
|
| 1667 | + $keytodelete=$filenb; |
|
| 1668 | + $keytodelete--; |
|
| 1669 | + |
|
| 1670 | + $listofpaths=array(); |
|
| 1671 | + $listofnames=array(); |
|
| 1672 | + $listofmimes=array(); |
|
| 1673 | + $keytoavoidconflict = empty($trackid)?'':'-'.$trackid; |
|
| 1674 | + if (! empty($_SESSION["listofpaths".$keytoavoidconflict])) $listofpaths=explode(';',$_SESSION["listofpaths".$keytoavoidconflict]); |
|
| 1675 | + if (! empty($_SESSION["listofnames".$keytoavoidconflict])) $listofnames=explode(';',$_SESSION["listofnames".$keytoavoidconflict]); |
|
| 1676 | + if (! empty($_SESSION["listofmimes".$keytoavoidconflict])) $listofmimes=explode(';',$_SESSION["listofmimes".$keytoavoidconflict]); |
|
| 1677 | + |
|
| 1678 | + if ($keytodelete >= 0) |
|
| 1679 | + { |
|
| 1680 | + $pathtodelete=$listofpaths[$keytodelete]; |
|
| 1681 | + $filetodelete=$listofnames[$keytodelete]; |
|
| 1682 | + if (empty($donotdeletefile)) $result = dol_delete_file($pathtodelete,1); // The delete of ecm database is inside the function dol_delete_file |
|
| 1683 | + else $result=0; |
|
| 1684 | + if ($result >= 0) |
|
| 1685 | + { |
|
| 1686 | + if (empty($donotdeletefile)) |
|
| 1687 | + { |
|
| 1688 | + $langs->load("other"); |
|
| 1689 | + setEventMessages($langs->trans("FileWasRemoved",$filetodelete), null, 'mesgs'); |
|
| 1690 | + } |
|
| 1691 | + if (empty($donotupdatesession)) |
|
| 1692 | + { |
|
| 1693 | + include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; |
|
| 1694 | + $formmail = new FormMail($db); |
|
| 1695 | + $formmail->trackid = $trackid; |
|
| 1696 | + $formmail->remove_attached_files($keytodelete); |
|
| 1697 | + } |
|
| 1698 | + } |
|
| 1699 | + } |
|
| 1700 | 1700 | } |
| 1701 | 1701 | |
| 1702 | 1702 | |
@@ -1714,41 +1714,41 @@ discard block |
||
| 1714 | 1714 | */ |
| 1715 | 1715 | function addFileIntoDatabaseIndex($dir, $file, $fullpathorig='', $mode='uploaded', $setsharekey=0) |
| 1716 | 1716 | { |
| 1717 | - global $db, $user; |
|
| 1718 | - |
|
| 1719 | - $result = 0; |
|
| 1720 | - |
|
| 1721 | - $rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $dir); |
|
| 1722 | - |
|
| 1723 | - if (! preg_match('/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) // If not a tmp dir |
|
| 1724 | - { |
|
| 1725 | - $filename = basename($file); |
|
| 1726 | - $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir); |
|
| 1727 | - $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir); |
|
| 1728 | - |
|
| 1729 | - include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; |
|
| 1730 | - $ecmfile=new EcmFiles($db); |
|
| 1731 | - $ecmfile->filepath = $rel_dir; |
|
| 1732 | - $ecmfile->filename = $filename; |
|
| 1733 | - $ecmfile->label = md5_file(dol_osencode($dir.'/'.$file)); // MD5 of file content |
|
| 1734 | - $ecmfile->fullpath_orig = $fullpathorig; |
|
| 1735 | - $ecmfile->gen_or_uploaded = $mode; |
|
| 1736 | - $ecmfile->description = ''; // indexed content |
|
| 1737 | - $ecmfile->keyword = ''; // keyword content |
|
| 1738 | - if ($setsharekey) |
|
| 1739 | - { |
|
| 1740 | - require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; |
|
| 1741 | - $ecmfile->share = getRandomPassword(true); |
|
| 1742 | - } |
|
| 1743 | - |
|
| 1744 | - $result = $ecmfile->create($user); |
|
| 1745 | - if ($result < 0) |
|
| 1746 | - { |
|
| 1747 | - dol_syslog($ecmfile->error); |
|
| 1748 | - } |
|
| 1749 | - } |
|
| 1750 | - |
|
| 1751 | - return $result; |
|
| 1717 | + global $db, $user; |
|
| 1718 | + |
|
| 1719 | + $result = 0; |
|
| 1720 | + |
|
| 1721 | + $rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $dir); |
|
| 1722 | + |
|
| 1723 | + if (! preg_match('/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) // If not a tmp dir |
|
| 1724 | + { |
|
| 1725 | + $filename = basename($file); |
|
| 1726 | + $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir); |
|
| 1727 | + $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir); |
|
| 1728 | + |
|
| 1729 | + include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; |
|
| 1730 | + $ecmfile=new EcmFiles($db); |
|
| 1731 | + $ecmfile->filepath = $rel_dir; |
|
| 1732 | + $ecmfile->filename = $filename; |
|
| 1733 | + $ecmfile->label = md5_file(dol_osencode($dir.'/'.$file)); // MD5 of file content |
|
| 1734 | + $ecmfile->fullpath_orig = $fullpathorig; |
|
| 1735 | + $ecmfile->gen_or_uploaded = $mode; |
|
| 1736 | + $ecmfile->description = ''; // indexed content |
|
| 1737 | + $ecmfile->keyword = ''; // keyword content |
|
| 1738 | + if ($setsharekey) |
|
| 1739 | + { |
|
| 1740 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; |
|
| 1741 | + $ecmfile->share = getRandomPassword(true); |
|
| 1742 | + } |
|
| 1743 | + |
|
| 1744 | + $result = $ecmfile->create($user); |
|
| 1745 | + if ($result < 0) |
|
| 1746 | + { |
|
| 1747 | + dol_syslog($ecmfile->error); |
|
| 1748 | + } |
|
| 1749 | + } |
|
| 1750 | + |
|
| 1751 | + return $result; |
|
| 1752 | 1752 | } |
| 1753 | 1753 | |
| 1754 | 1754 | |
@@ -1762,48 +1762,48 @@ discard block |
||
| 1762 | 1762 | */ |
| 1763 | 1763 | function deleteFilesIntoDatabaseIndex($dir, $file, $mode='uploaded') |
| 1764 | 1764 | { |
| 1765 | - global $conf, $db, $user; |
|
| 1766 | - |
|
| 1767 | - $error = 0; |
|
| 1768 | - |
|
| 1769 | - if (empty($dir)) |
|
| 1770 | - { |
|
| 1771 | - dol_syslog("deleteFilesIntoDatabaseIndex: dir parameter can't be empty", LOG_ERR); |
|
| 1772 | - return -1; |
|
| 1773 | - } |
|
| 1774 | - |
|
| 1775 | - $db->begin(); |
|
| 1776 | - |
|
| 1777 | - $rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $dir); |
|
| 1778 | - |
|
| 1779 | - $filename = basename($file); |
|
| 1780 | - $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir); |
|
| 1781 | - $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir); |
|
| 1782 | - |
|
| 1783 | - if (! $error) |
|
| 1784 | - { |
|
| 1785 | - $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . 'ecm_files'; |
|
| 1786 | - $sql.= ' WHERE entity = '.$conf->entity; |
|
| 1787 | - $sql.= " AND filepath = '" . $db->escape($rel_dir) . "'"; |
|
| 1788 | - if ($file) $sql.= " AND filename = '" . $db->escape($file) . "'"; |
|
| 1789 | - if ($mode) $sql.= " AND gen_or_uploaded = '" . $db->escape($mode) . "'"; |
|
| 1790 | - |
|
| 1791 | - $resql = $db->query($sql); |
|
| 1792 | - if (!$resql) |
|
| 1793 | - { |
|
| 1794 | - $error++; |
|
| 1795 | - dol_syslog(__METHOD__ . ' ' . $db->lasterror(), LOG_ERR); |
|
| 1796 | - } |
|
| 1797 | - } |
|
| 1798 | - |
|
| 1799 | - // Commit or rollback |
|
| 1800 | - if ($error) { |
|
| 1801 | - $db->rollback(); |
|
| 1802 | - return - 1 * $error; |
|
| 1803 | - } else { |
|
| 1804 | - $db->commit(); |
|
| 1805 | - return 1; |
|
| 1806 | - } |
|
| 1765 | + global $conf, $db, $user; |
|
| 1766 | + |
|
| 1767 | + $error = 0; |
|
| 1768 | + |
|
| 1769 | + if (empty($dir)) |
|
| 1770 | + { |
|
| 1771 | + dol_syslog("deleteFilesIntoDatabaseIndex: dir parameter can't be empty", LOG_ERR); |
|
| 1772 | + return -1; |
|
| 1773 | + } |
|
| 1774 | + |
|
| 1775 | + $db->begin(); |
|
| 1776 | + |
|
| 1777 | + $rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $dir); |
|
| 1778 | + |
|
| 1779 | + $filename = basename($file); |
|
| 1780 | + $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir); |
|
| 1781 | + $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir); |
|
| 1782 | + |
|
| 1783 | + if (! $error) |
|
| 1784 | + { |
|
| 1785 | + $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . 'ecm_files'; |
|
| 1786 | + $sql.= ' WHERE entity = '.$conf->entity; |
|
| 1787 | + $sql.= " AND filepath = '" . $db->escape($rel_dir) . "'"; |
|
| 1788 | + if ($file) $sql.= " AND filename = '" . $db->escape($file) . "'"; |
|
| 1789 | + if ($mode) $sql.= " AND gen_or_uploaded = '" . $db->escape($mode) . "'"; |
|
| 1790 | + |
|
| 1791 | + $resql = $db->query($sql); |
|
| 1792 | + if (!$resql) |
|
| 1793 | + { |
|
| 1794 | + $error++; |
|
| 1795 | + dol_syslog(__METHOD__ . ' ' . $db->lasterror(), LOG_ERR); |
|
| 1796 | + } |
|
| 1797 | + } |
|
| 1798 | + |
|
| 1799 | + // Commit or rollback |
|
| 1800 | + if ($error) { |
|
| 1801 | + $db->rollback(); |
|
| 1802 | + return - 1 * $error; |
|
| 1803 | + } else { |
|
| 1804 | + $db->commit(); |
|
| 1805 | + return 1; |
|
| 1806 | + } |
|
| 1807 | 1807 | } |
| 1808 | 1808 | |
| 1809 | 1809 | |
@@ -1818,51 +1818,51 @@ discard block |
||
| 1818 | 1818 | */ |
| 1819 | 1819 | function dol_convert_file($fileinput, $ext='png', $fileoutput='') |
| 1820 | 1820 | { |
| 1821 | - global $langs; |
|
| 1822 | - |
|
| 1823 | - if (class_exists('Imagick')) |
|
| 1824 | - { |
|
| 1825 | - $image=new Imagick(); |
|
| 1826 | - try { |
|
| 1827 | - $ret = $image->readImage($fileinput); |
|
| 1828 | - } catch(Exception $e) { |
|
| 1829 | - dol_syslog("Failed to read image using Imagick. Try to install package 'apt-get install ghostscript'.", LOG_WARNING); |
|
| 1830 | - return 0; |
|
| 1831 | - } |
|
| 1832 | - if ($ret) |
|
| 1833 | - { |
|
| 1834 | - $ret = $image->setImageFormat($ext); |
|
| 1835 | - if ($ret) |
|
| 1836 | - { |
|
| 1837 | - if (empty($fileoutput)) $fileoutput=$fileinput.".".$ext; |
|
| 1838 | - |
|
| 1839 | - $count = $image->getNumberImages(); |
|
| 1840 | - |
|
| 1841 | - if (! dol_is_file($fileoutput) || is_writeable($fileoutput)) |
|
| 1842 | - { |
|
| 1843 | - $ret = $image->writeImages($fileoutput, true); |
|
| 1844 | - } |
|
| 1845 | - else |
|
| 1846 | - { |
|
| 1847 | - dol_syslog("Warning: Failed to write cache preview file '.$fileoutput.'. Check permission on file/dir", LOG_ERR); |
|
| 1848 | - } |
|
| 1849 | - if ($ret) return $count; |
|
| 1850 | - else return -3; |
|
| 1851 | - } |
|
| 1852 | - else |
|
| 1853 | - { |
|
| 1854 | - return -2; |
|
| 1855 | - } |
|
| 1856 | - } |
|
| 1857 | - else |
|
| 1858 | - { |
|
| 1859 | - return -1; |
|
| 1860 | - } |
|
| 1861 | - } |
|
| 1862 | - else |
|
| 1863 | - { |
|
| 1864 | - return 0; |
|
| 1865 | - } |
|
| 1821 | + global $langs; |
|
| 1822 | + |
|
| 1823 | + if (class_exists('Imagick')) |
|
| 1824 | + { |
|
| 1825 | + $image=new Imagick(); |
|
| 1826 | + try { |
|
| 1827 | + $ret = $image->readImage($fileinput); |
|
| 1828 | + } catch(Exception $e) { |
|
| 1829 | + dol_syslog("Failed to read image using Imagick. Try to install package 'apt-get install ghostscript'.", LOG_WARNING); |
|
| 1830 | + return 0; |
|
| 1831 | + } |
|
| 1832 | + if ($ret) |
|
| 1833 | + { |
|
| 1834 | + $ret = $image->setImageFormat($ext); |
|
| 1835 | + if ($ret) |
|
| 1836 | + { |
|
| 1837 | + if (empty($fileoutput)) $fileoutput=$fileinput.".".$ext; |
|
| 1838 | + |
|
| 1839 | + $count = $image->getNumberImages(); |
|
| 1840 | + |
|
| 1841 | + if (! dol_is_file($fileoutput) || is_writeable($fileoutput)) |
|
| 1842 | + { |
|
| 1843 | + $ret = $image->writeImages($fileoutput, true); |
|
| 1844 | + } |
|
| 1845 | + else |
|
| 1846 | + { |
|
| 1847 | + dol_syslog("Warning: Failed to write cache preview file '.$fileoutput.'. Check permission on file/dir", LOG_ERR); |
|
| 1848 | + } |
|
| 1849 | + if ($ret) return $count; |
|
| 1850 | + else return -3; |
|
| 1851 | + } |
|
| 1852 | + else |
|
| 1853 | + { |
|
| 1854 | + return -2; |
|
| 1855 | + } |
|
| 1856 | + } |
|
| 1857 | + else |
|
| 1858 | + { |
|
| 1859 | + return -1; |
|
| 1860 | + } |
|
| 1861 | + } |
|
| 1862 | + else |
|
| 1863 | + { |
|
| 1864 | + return 0; |
|
| 1865 | + } |
|
| 1866 | 1866 | } |
| 1867 | 1867 | |
| 1868 | 1868 | |
@@ -1876,48 +1876,48 @@ discard block |
||
| 1876 | 1876 | */ |
| 1877 | 1877 | function dol_compress_file($inputfile, $outputfile, $mode="gz") |
| 1878 | 1878 | { |
| 1879 | - $foundhandler=0; |
|
| 1880 | - |
|
| 1881 | - try |
|
| 1882 | - { |
|
| 1883 | - $data = implode("", file(dol_osencode($inputfile))); |
|
| 1884 | - if ($mode == 'gz') { $foundhandler=1; $compressdata = gzencode($data, 9); } |
|
| 1885 | - elseif ($mode == 'bz') { $foundhandler=1; $compressdata = bzcompress($data, 9); } |
|
| 1886 | - elseif ($mode == 'zip') |
|
| 1887 | - { |
|
| 1888 | - if (defined('ODTPHP_PATHTOPCLZIP')) |
|
| 1889 | - { |
|
| 1890 | - $foundhandler=1; |
|
| 1891 | - |
|
| 1892 | - include_once ODTPHP_PATHTOPCLZIP.'/pclzip.lib.php'; |
|
| 1893 | - $archive = new PclZip($outputfile); |
|
| 1894 | - $archive->add($inputfile, PCLZIP_OPT_REMOVE_PATH, dirname($inputfile)); |
|
| 1895 | - //$archive->add($inputfile); |
|
| 1896 | - return 1; |
|
| 1897 | - } |
|
| 1898 | - } |
|
| 1899 | - |
|
| 1900 | - if ($foundhandler) |
|
| 1901 | - { |
|
| 1902 | - $fp = fopen($outputfile, "w"); |
|
| 1903 | - fwrite($fp, $compressdata); |
|
| 1904 | - fclose($fp); |
|
| 1905 | - return 1; |
|
| 1906 | - } |
|
| 1907 | - else |
|
| 1908 | - { |
|
| 1909 | - dol_syslog("Try to zip with format ".$mode." with no handler for this format",LOG_ERR); |
|
| 1910 | - return -2; |
|
| 1911 | - } |
|
| 1912 | - } |
|
| 1913 | - catch (Exception $e) |
|
| 1914 | - { |
|
| 1915 | - global $langs, $errormsg; |
|
| 1916 | - $langs->load("errors"); |
|
| 1917 | - dol_syslog("Failed to open file ".$outputfile,LOG_ERR); |
|
| 1918 | - $errormsg=$langs->trans("ErrorFailedToWriteInDir"); |
|
| 1919 | - return -1; |
|
| 1920 | - } |
|
| 1879 | + $foundhandler=0; |
|
| 1880 | + |
|
| 1881 | + try |
|
| 1882 | + { |
|
| 1883 | + $data = implode("", file(dol_osencode($inputfile))); |
|
| 1884 | + if ($mode == 'gz') { $foundhandler=1; $compressdata = gzencode($data, 9); } |
|
| 1885 | + elseif ($mode == 'bz') { $foundhandler=1; $compressdata = bzcompress($data, 9); } |
|
| 1886 | + elseif ($mode == 'zip') |
|
| 1887 | + { |
|
| 1888 | + if (defined('ODTPHP_PATHTOPCLZIP')) |
|
| 1889 | + { |
|
| 1890 | + $foundhandler=1; |
|
| 1891 | + |
|
| 1892 | + include_once ODTPHP_PATHTOPCLZIP.'/pclzip.lib.php'; |
|
| 1893 | + $archive = new PclZip($outputfile); |
|
| 1894 | + $archive->add($inputfile, PCLZIP_OPT_REMOVE_PATH, dirname($inputfile)); |
|
| 1895 | + //$archive->add($inputfile); |
|
| 1896 | + return 1; |
|
| 1897 | + } |
|
| 1898 | + } |
|
| 1899 | + |
|
| 1900 | + if ($foundhandler) |
|
| 1901 | + { |
|
| 1902 | + $fp = fopen($outputfile, "w"); |
|
| 1903 | + fwrite($fp, $compressdata); |
|
| 1904 | + fclose($fp); |
|
| 1905 | + return 1; |
|
| 1906 | + } |
|
| 1907 | + else |
|
| 1908 | + { |
|
| 1909 | + dol_syslog("Try to zip with format ".$mode." with no handler for this format",LOG_ERR); |
|
| 1910 | + return -2; |
|
| 1911 | + } |
|
| 1912 | + } |
|
| 1913 | + catch (Exception $e) |
|
| 1914 | + { |
|
| 1915 | + global $langs, $errormsg; |
|
| 1916 | + $langs->load("errors"); |
|
| 1917 | + dol_syslog("Failed to open file ".$outputfile,LOG_ERR); |
|
| 1918 | + $errormsg=$langs->trans("ErrorFailedToWriteInDir"); |
|
| 1919 | + return -1; |
|
| 1920 | + } |
|
| 1921 | 1921 | } |
| 1922 | 1922 | |
| 1923 | 1923 | /** |
@@ -1929,54 +1929,54 @@ discard block |
||
| 1929 | 1929 | */ |
| 1930 | 1930 | function dol_uncompress($inputfile,$outputdir) |
| 1931 | 1931 | { |
| 1932 | - global $langs; |
|
| 1933 | - |
|
| 1934 | - if (defined('ODTPHP_PATHTOPCLZIP')) |
|
| 1935 | - { |
|
| 1936 | - dol_syslog("Constant ODTPHP_PATHTOPCLZIP for pclzip library is set to ".ODTPHP_PATHTOPCLZIP.", so we use Pclzip to unzip into ".$outputdir); |
|
| 1937 | - include_once ODTPHP_PATHTOPCLZIP.'/pclzip.lib.php'; |
|
| 1938 | - $archive = new PclZip($inputfile); |
|
| 1939 | - $result=$archive->extract(PCLZIP_OPT_PATH, $outputdir); |
|
| 1940 | - //var_dump($result); |
|
| 1941 | - if (! is_array($result) && $result <= 0) return array('error'=>$archive->errorInfo(true)); |
|
| 1942 | - else |
|
| 1943 | - { |
|
| 1944 | - $ok=1; $errmsg=''; |
|
| 1945 | - // Loop on each file to check result for unzipping file |
|
| 1946 | - foreach($result as $key => $val) |
|
| 1947 | - { |
|
| 1948 | - if ($val['status'] == 'path_creation_fail') |
|
| 1949 | - { |
|
| 1950 | - $langs->load("errors"); |
|
| 1951 | - $ok=0; |
|
| 1952 | - $errmsg=$langs->trans("ErrorFailToCreateDir", $val['filename']); |
|
| 1953 | - break; |
|
| 1954 | - } |
|
| 1955 | - } |
|
| 1956 | - |
|
| 1957 | - if ($ok) return array(); |
|
| 1958 | - else return array('error'=>$errmsg); |
|
| 1959 | - } |
|
| 1960 | - } |
|
| 1961 | - |
|
| 1962 | - if (class_exists('ZipArchive')) |
|
| 1963 | - { |
|
| 1964 | - dol_syslog("Class ZipArchive is set so we unzip using ZipArchive to unzip into ".$outputdir); |
|
| 1965 | - $zip = new ZipArchive; |
|
| 1966 | - $res = $zip->open($inputfile); |
|
| 1967 | - if ($res === true) |
|
| 1968 | - { |
|
| 1969 | - $zip->extractTo($outputdir.'/'); |
|
| 1970 | - $zip->close(); |
|
| 1971 | - return array(); |
|
| 1972 | - } |
|
| 1973 | - else |
|
| 1974 | - { |
|
| 1975 | - return array('error'=>'ErrUnzipFails'); |
|
| 1976 | - } |
|
| 1977 | - } |
|
| 1978 | - |
|
| 1979 | - return array('error'=>'ErrNoZipEngine'); |
|
| 1932 | + global $langs; |
|
| 1933 | + |
|
| 1934 | + if (defined('ODTPHP_PATHTOPCLZIP')) |
|
| 1935 | + { |
|
| 1936 | + dol_syslog("Constant ODTPHP_PATHTOPCLZIP for pclzip library is set to ".ODTPHP_PATHTOPCLZIP.", so we use Pclzip to unzip into ".$outputdir); |
|
| 1937 | + include_once ODTPHP_PATHTOPCLZIP.'/pclzip.lib.php'; |
|
| 1938 | + $archive = new PclZip($inputfile); |
|
| 1939 | + $result=$archive->extract(PCLZIP_OPT_PATH, $outputdir); |
|
| 1940 | + //var_dump($result); |
|
| 1941 | + if (! is_array($result) && $result <= 0) return array('error'=>$archive->errorInfo(true)); |
|
| 1942 | + else |
|
| 1943 | + { |
|
| 1944 | + $ok=1; $errmsg=''; |
|
| 1945 | + // Loop on each file to check result for unzipping file |
|
| 1946 | + foreach($result as $key => $val) |
|
| 1947 | + { |
|
| 1948 | + if ($val['status'] == 'path_creation_fail') |
|
| 1949 | + { |
|
| 1950 | + $langs->load("errors"); |
|
| 1951 | + $ok=0; |
|
| 1952 | + $errmsg=$langs->trans("ErrorFailToCreateDir", $val['filename']); |
|
| 1953 | + break; |
|
| 1954 | + } |
|
| 1955 | + } |
|
| 1956 | + |
|
| 1957 | + if ($ok) return array(); |
|
| 1958 | + else return array('error'=>$errmsg); |
|
| 1959 | + } |
|
| 1960 | + } |
|
| 1961 | + |
|
| 1962 | + if (class_exists('ZipArchive')) |
|
| 1963 | + { |
|
| 1964 | + dol_syslog("Class ZipArchive is set so we unzip using ZipArchive to unzip into ".$outputdir); |
|
| 1965 | + $zip = new ZipArchive; |
|
| 1966 | + $res = $zip->open($inputfile); |
|
| 1967 | + if ($res === true) |
|
| 1968 | + { |
|
| 1969 | + $zip->extractTo($outputdir.'/'); |
|
| 1970 | + $zip->close(); |
|
| 1971 | + return array(); |
|
| 1972 | + } |
|
| 1973 | + else |
|
| 1974 | + { |
|
| 1975 | + return array('error'=>'ErrUnzipFails'); |
|
| 1976 | + } |
|
| 1977 | + } |
|
| 1978 | + |
|
| 1979 | + return array('error'=>'ErrNoZipEngine'); |
|
| 1980 | 1980 | } |
| 1981 | 1981 | |
| 1982 | 1982 | |
@@ -1990,25 +1990,25 @@ discard block |
||
| 1990 | 1990 | */ |
| 1991 | 1991 | function dol_compress_dir($inputdir, $outputfile, $mode="zip") |
| 1992 | 1992 | { |
| 1993 | - $foundhandler=0; |
|
| 1994 | - |
|
| 1995 | - dol_syslog("Try to zip dir ".$inputdir." into ".$outputdir." mode=".$mode); |
|
| 1996 | - |
|
| 1997 | - if (! dol_is_dir(dirname($outputfile)) || ! is_writable(dirname($outputfile))) |
|
| 1998 | - { |
|
| 1999 | - global $langs, $errormsg; |
|
| 2000 | - $langs->load("errors"); |
|
| 2001 | - $errormsg=$langs->trans("ErrorFailedToWriteInDir",$outputfile); |
|
| 2002 | - return -3; |
|
| 2003 | - } |
|
| 2004 | - |
|
| 2005 | - try |
|
| 2006 | - { |
|
| 2007 | - if ($mode == 'gz') { $foundhandler=0; } |
|
| 2008 | - elseif ($mode == 'bz') { $foundhandler=0; } |
|
| 2009 | - elseif ($mode == 'zip') |
|
| 2010 | - { |
|
| 2011 | - /*if (defined('ODTPHP_PATHTOPCLZIP')) |
|
| 1993 | + $foundhandler=0; |
|
| 1994 | + |
|
| 1995 | + dol_syslog("Try to zip dir ".$inputdir." into ".$outputdir." mode=".$mode); |
|
| 1996 | + |
|
| 1997 | + if (! dol_is_dir(dirname($outputfile)) || ! is_writable(dirname($outputfile))) |
|
| 1998 | + { |
|
| 1999 | + global $langs, $errormsg; |
|
| 2000 | + $langs->load("errors"); |
|
| 2001 | + $errormsg=$langs->trans("ErrorFailedToWriteInDir",$outputfile); |
|
| 2002 | + return -3; |
|
| 2003 | + } |
|
| 2004 | + |
|
| 2005 | + try |
|
| 2006 | + { |
|
| 2007 | + if ($mode == 'gz') { $foundhandler=0; } |
|
| 2008 | + elseif ($mode == 'bz') { $foundhandler=0; } |
|
| 2009 | + elseif ($mode == 'zip') |
|
| 2010 | + { |
|
| 2011 | + /*if (defined('ODTPHP_PATHTOPCLZIP')) |
|
| 2012 | 2012 | { |
| 2013 | 2013 | $foundhandler=0; // TODO implement this |
| 2014 | 2014 | |
@@ -2019,61 +2019,61 @@ discard block |
||
| 2019 | 2019 | return 1; |
| 2020 | 2020 | } |
| 2021 | 2021 | else*/ |
| 2022 | - if (class_exists('ZipArchive')) |
|
| 2023 | - { |
|
| 2024 | - $foundhandler=1; |
|
| 2025 | - |
|
| 2026 | - // Initialize archive object |
|
| 2027 | - $zip = new ZipArchive(); |
|
| 2028 | - $result = $zip->open($outputfile, ZipArchive::CREATE | ZipArchive::OVERWRITE); |
|
| 2029 | - |
|
| 2030 | - // Create recursive directory iterator |
|
| 2031 | - /** @var SplFileInfo[] $files */ |
|
| 2032 | - $files = new RecursiveIteratorIterator( |
|
| 2033 | - new RecursiveDirectoryIterator($inputdir), |
|
| 2034 | - RecursiveIteratorIterator::LEAVES_ONLY |
|
| 2035 | - ); |
|
| 2036 | - |
|
| 2037 | - foreach ($files as $name => $file) |
|
| 2038 | - { |
|
| 2039 | - // Skip directories (they would be added automatically) |
|
| 2040 | - if (!$file->isDir()) |
|
| 2041 | - { |
|
| 2042 | - // Get real and relative path for current file |
|
| 2043 | - $filePath = $file->getRealPath(); |
|
| 2044 | - $relativePath = substr($filePath, strlen($inputdir) + 1); |
|
| 2045 | - |
|
| 2046 | - // Add current file to archive |
|
| 2047 | - $zip->addFile($filePath, $relativePath); |
|
| 2048 | - } |
|
| 2049 | - } |
|
| 2050 | - |
|
| 2051 | - // Zip archive will be created only after closing object |
|
| 2052 | - $zip->close(); |
|
| 2053 | - |
|
| 2054 | - return 1; |
|
| 2055 | - } |
|
| 2056 | - } |
|
| 2057 | - |
|
| 2058 | - if (! $foundhandler) |
|
| 2059 | - { |
|
| 2060 | - dol_syslog("Try to zip with format ".$mode." with no handler for this format",LOG_ERR); |
|
| 2061 | - return -2; |
|
| 2062 | - } |
|
| 2063 | - else |
|
| 2064 | - { |
|
| 2065 | - return 0; |
|
| 2066 | - } |
|
| 2067 | - } |
|
| 2068 | - catch (Exception $e) |
|
| 2069 | - { |
|
| 2070 | - global $langs, $errormsg; |
|
| 2071 | - $langs->load("errors"); |
|
| 2072 | - dol_syslog("Failed to open file ".$outputfile, LOG_ERR); |
|
| 2073 | - dol_syslog($e->getMessage(), LOG_ERR); |
|
| 2074 | - $errormsg=$langs->trans("ErrorFailedToWriteInDir",$outputfile); |
|
| 2075 | - return -1; |
|
| 2076 | - } |
|
| 2022 | + if (class_exists('ZipArchive')) |
|
| 2023 | + { |
|
| 2024 | + $foundhandler=1; |
|
| 2025 | + |
|
| 2026 | + // Initialize archive object |
|
| 2027 | + $zip = new ZipArchive(); |
|
| 2028 | + $result = $zip->open($outputfile, ZipArchive::CREATE | ZipArchive::OVERWRITE); |
|
| 2029 | + |
|
| 2030 | + // Create recursive directory iterator |
|
| 2031 | + /** @var SplFileInfo[] $files */ |
|
| 2032 | + $files = new RecursiveIteratorIterator( |
|
| 2033 | + new RecursiveDirectoryIterator($inputdir), |
|
| 2034 | + RecursiveIteratorIterator::LEAVES_ONLY |
|
| 2035 | + ); |
|
| 2036 | + |
|
| 2037 | + foreach ($files as $name => $file) |
|
| 2038 | + { |
|
| 2039 | + // Skip directories (they would be added automatically) |
|
| 2040 | + if (!$file->isDir()) |
|
| 2041 | + { |
|
| 2042 | + // Get real and relative path for current file |
|
| 2043 | + $filePath = $file->getRealPath(); |
|
| 2044 | + $relativePath = substr($filePath, strlen($inputdir) + 1); |
|
| 2045 | + |
|
| 2046 | + // Add current file to archive |
|
| 2047 | + $zip->addFile($filePath, $relativePath); |
|
| 2048 | + } |
|
| 2049 | + } |
|
| 2050 | + |
|
| 2051 | + // Zip archive will be created only after closing object |
|
| 2052 | + $zip->close(); |
|
| 2053 | + |
|
| 2054 | + return 1; |
|
| 2055 | + } |
|
| 2056 | + } |
|
| 2057 | + |
|
| 2058 | + if (! $foundhandler) |
|
| 2059 | + { |
|
| 2060 | + dol_syslog("Try to zip with format ".$mode." with no handler for this format",LOG_ERR); |
|
| 2061 | + return -2; |
|
| 2062 | + } |
|
| 2063 | + else |
|
| 2064 | + { |
|
| 2065 | + return 0; |
|
| 2066 | + } |
|
| 2067 | + } |
|
| 2068 | + catch (Exception $e) |
|
| 2069 | + { |
|
| 2070 | + global $langs, $errormsg; |
|
| 2071 | + $langs->load("errors"); |
|
| 2072 | + dol_syslog("Failed to open file ".$outputfile, LOG_ERR); |
|
| 2073 | + dol_syslog($e->getMessage(), LOG_ERR); |
|
| 2074 | + $errormsg=$langs->trans("ErrorFailedToWriteInDir",$outputfile); |
|
| 2075 | + return -1; |
|
| 2076 | + } |
|
| 2077 | 2077 | } |
| 2078 | 2078 | |
| 2079 | 2079 | |
@@ -2090,8 +2090,8 @@ discard block |
||
| 2090 | 2090 | */ |
| 2091 | 2091 | function dol_most_recent_file($dir,$regexfilter='',$excludefilter=array('(\.meta|_preview.*\.png)$','^\.'),$nohook=false,$mode='') |
| 2092 | 2092 | { |
| 2093 | - $tmparray=dol_dir_list($dir,'files',0,$regexfilter,$excludefilter,'date',SORT_DESC,$mode,$nohook); |
|
| 2094 | - return $tmparray[0]; |
|
| 2093 | + $tmparray=dol_dir_list($dir,'files',0,$regexfilter,$excludefilter,'date',SORT_DESC,$mode,$nohook); |
|
| 2094 | + return $tmparray[0]; |
|
| 2095 | 2095 | } |
| 2096 | 2096 | |
| 2097 | 2097 | /** |
@@ -2108,770 +2108,770 @@ discard block |
||
| 2108 | 2108 | */ |
| 2109 | 2109 | function dol_check_secure_access_document($modulepart, $original_file, $entity, $fuser='', $refname='', $mode='read') |
| 2110 | 2110 | { |
| 2111 | - global $conf, $db, $user; |
|
| 2112 | - global $dolibarr_main_data_root, $dolibarr_main_document_root_alt; |
|
| 2113 | - |
|
| 2114 | - if (! is_object($fuser)) $fuser=$user; |
|
| 2115 | - |
|
| 2116 | - if (empty($modulepart)) return 'ErrorBadParameter'; |
|
| 2117 | - if (empty($entity)) |
|
| 2118 | - { |
|
| 2119 | - if (empty($conf->multicompany->enabled)) $entity=1; |
|
| 2120 | - else $entity=0; |
|
| 2121 | - } |
|
| 2122 | - // Fix modulepart |
|
| 2123 | - if ($modulepart == 'users') $modulepart='user'; |
|
| 2124 | - |
|
| 2125 | - dol_syslog('modulepart='.$modulepart.' original_file='.$original_file.' entity='.$entity); |
|
| 2126 | - // We define $accessallowed and $sqlprotectagainstexternals |
|
| 2127 | - $accessallowed=0; |
|
| 2128 | - $sqlprotectagainstexternals=''; |
|
| 2129 | - $ret=array(); |
|
| 2130 | - |
|
| 2131 | - // Find the subdirectory name as the reference. For exemple original_file='10/myfile.pdf' -> refname='10' |
|
| 2132 | - if (empty($refname)) $refname=basename(dirname($original_file)."/"); |
|
| 2133 | - |
|
| 2134 | - $relative_original_file = $original_file; |
|
| 2135 | - |
|
| 2136 | - // Define possible keys to use for permission check |
|
| 2137 | - $lire='lire'; $read='read'; $download='download'; |
|
| 2138 | - if ($mode == 'write') |
|
| 2139 | - { |
|
| 2140 | - $lire='creer'; $read='write'; $download='upload'; |
|
| 2141 | - } |
|
| 2142 | - |
|
| 2143 | - // Wrapping for miscellaneous medias files |
|
| 2144 | - if ($modulepart == 'medias' && !empty($dolibarr_main_data_root)) |
|
| 2145 | - { |
|
| 2146 | - if (empty($entity) || empty($conf->medias->multidir_output[$entity])) return array('accessallowed'=>0, 'error'=>'Value entity must be provided'); |
|
| 2147 | - $accessallowed=1; |
|
| 2148 | - $original_file=$conf->medias->multidir_output[$entity].'/'.$original_file; |
|
| 2149 | - } |
|
| 2150 | - // Wrapping for *.log files, like when used with url http://.../document.php?modulepart=logs&file=dolibarr.log |
|
| 2151 | - elseif ($modulepart == 'logs' && !empty($dolibarr_main_data_root)) |
|
| 2152 | - { |
|
| 2153 | - $accessallowed=($user->admin && basename($original_file) == $original_file && preg_match('/^dolibarr.*\.log$/', basename($original_file))); |
|
| 2154 | - $original_file=$dolibarr_main_data_root.'/'.$original_file; |
|
| 2155 | - } |
|
| 2156 | - // Wrapping for *.zip files, like when used with url http://.../document.php?modulepart=packages&file=module_myfile.zip |
|
| 2157 | - elseif ($modulepart == 'packages' && !empty($dolibarr_main_data_root)) |
|
| 2158 | - { |
|
| 2159 | - // Dir for custom dirs |
|
| 2160 | - $tmp=explode(',', $dolibarr_main_document_root_alt); |
|
| 2161 | - $dirins = $tmp[0]; |
|
| 2162 | - |
|
| 2163 | - $accessallowed=($user->admin && preg_match('/^module_.*\.zip$/', basename($original_file))); |
|
| 2164 | - $original_file=$dirins.'/'.$original_file; |
|
| 2165 | - } |
|
| 2166 | - // Wrapping for some images |
|
| 2167 | - elseif ($modulepart == 'mycompany' && !empty($conf->mycompany->dir_output)) |
|
| 2168 | - { |
|
| 2169 | - $accessallowed=1; |
|
| 2170 | - $original_file=$conf->mycompany->dir_output.'/'.$original_file; |
|
| 2171 | - } |
|
| 2172 | - // Wrapping for users photos |
|
| 2173 | - elseif ($modulepart == 'userphoto' && !empty($conf->user->dir_output)) |
|
| 2174 | - { |
|
| 2175 | - $accessallowed=1; |
|
| 2176 | - $original_file=$conf->user->dir_output.'/'.$original_file; |
|
| 2177 | - } |
|
| 2178 | - // Wrapping for members photos |
|
| 2179 | - elseif ($modulepart == 'memberphoto' && !empty($conf->adherent->dir_output)) |
|
| 2180 | - { |
|
| 2181 | - $accessallowed=1; |
|
| 2182 | - $original_file=$conf->adherent->dir_output.'/'.$original_file; |
|
| 2183 | - } |
|
| 2184 | - // Wrapping pour les apercu factures |
|
| 2185 | - elseif ($modulepart == 'apercufacture' && !empty($conf->facture->dir_output)) |
|
| 2186 | - { |
|
| 2187 | - if ($fuser->rights->facture->{$lire}) $accessallowed=1; |
|
| 2188 | - $original_file=$conf->facture->dir_output.'/'.$original_file; |
|
| 2189 | - } |
|
| 2190 | - // Wrapping pour les apercu propal |
|
| 2191 | - elseif ($modulepart == 'apercupropal' && !empty($conf->propal->multidir_output[$entity])) |
|
| 2192 | - { |
|
| 2193 | - if ($fuser->rights->propale->{$lire}) $accessallowed=1; |
|
| 2194 | - $original_file=$conf->propal->multidir_output[$entity].'/'.$original_file; |
|
| 2195 | - } |
|
| 2196 | - // Wrapping pour les apercu commande |
|
| 2197 | - elseif ($modulepart == 'apercucommande' && !empty($conf->commande->dir_output)) |
|
| 2198 | - { |
|
| 2199 | - if ($fuser->rights->commande->{$lire}) $accessallowed=1; |
|
| 2200 | - $original_file=$conf->commande->dir_output.'/'.$original_file; |
|
| 2201 | - } |
|
| 2202 | - // Wrapping pour les apercu intervention |
|
| 2203 | - elseif (($modulepart == 'apercufichinter' || $modulepart == 'apercuficheinter') && !empty($conf->ficheinter->dir_output)) |
|
| 2204 | - { |
|
| 2205 | - if ($fuser->rights->ficheinter->{$lire}) $accessallowed=1; |
|
| 2206 | - $original_file=$conf->ficheinter->dir_output.'/'.$original_file; |
|
| 2207 | - } |
|
| 2208 | - // Wrapping pour les apercu conat |
|
| 2209 | - elseif (($modulepart == 'apercucontract') && !empty($conf->contrat->dir_output)) |
|
| 2210 | - { |
|
| 2211 | - if ($fuser->rights->contrat->{$lire}) $accessallowed=1; |
|
| 2212 | - $original_file=$conf->contrat->dir_output.'/'.$original_file; |
|
| 2213 | - } |
|
| 2214 | - // Wrapping pour les apercu supplier proposal |
|
| 2215 | - elseif (($modulepart == 'apercusupplier_proposal' || $modulepart == 'apercusupplier_proposal') && !empty($conf->supplier_proposal->dir_output)) |
|
| 2216 | - { |
|
| 2217 | - if ($fuser->rights->supplier_proposal->{$lire}) $accessallowed=1; |
|
| 2218 | - $original_file=$conf->supplier_proposal->dir_output.'/'.$original_file; |
|
| 2219 | - } |
|
| 2220 | - // Wrapping pour les apercu supplier order |
|
| 2221 | - elseif (($modulepart == 'apercusupplier_order' || $modulepart == 'apercusupplier_order') && !empty($conf->fournisseur->commande->dir_output)) |
|
| 2222 | - { |
|
| 2223 | - if ($fuser->rights->fournisseur->commande->{$lire}) $accessallowed=1; |
|
| 2224 | - $original_file=$conf->fournisseur->commande->dir_output.'/'.$original_file; |
|
| 2225 | - } |
|
| 2226 | - // Wrapping pour les apercu supplier invoice |
|
| 2227 | - elseif (($modulepart == 'apercusupplier_invoice' || $modulepart == 'apercusupplier_invoice') && !empty($conf->fournisseur->facture->dir_output)) |
|
| 2228 | - { |
|
| 2229 | - if ($fuser->rights->fournisseur->facture->{$lire}) $accessallowed=1; |
|
| 2230 | - $original_file=$conf->fournisseur->facture->dir_output.'/'.$original_file; |
|
| 2231 | - } |
|
| 2232 | - // Wrapping pour les apercu supplier invoice |
|
| 2233 | - elseif (($modulepart == 'apercuexpensereport') && !empty($conf->expensereport->dir_output)) |
|
| 2234 | - { |
|
| 2235 | - if ($fuser->rights->expensereport->{$lire}) $accessallowed=1; |
|
| 2236 | - $original_file=$conf->expensereport->dir_output.'/'.$original_file; |
|
| 2237 | - } |
|
| 2238 | - // Wrapping pour les images des stats propales |
|
| 2239 | - elseif ($modulepart == 'propalstats' && !empty($conf->propal->multidir_temp[$entity])) |
|
| 2240 | - { |
|
| 2241 | - if ($fuser->rights->propale->{$lire}) $accessallowed=1; |
|
| 2242 | - $original_file=$conf->propal->multidir_temp[$entity].'/'.$original_file; |
|
| 2243 | - } |
|
| 2244 | - // Wrapping pour les images des stats commandes |
|
| 2245 | - elseif ($modulepart == 'orderstats' && !empty($conf->commande->dir_temp)) |
|
| 2246 | - { |
|
| 2247 | - if ($fuser->rights->commande->{$lire}) $accessallowed=1; |
|
| 2248 | - $original_file=$conf->commande->dir_temp.'/'.$original_file; |
|
| 2249 | - } |
|
| 2250 | - elseif ($modulepart == 'orderstatssupplier' && !empty($conf->fournisseur->dir_output)) |
|
| 2251 | - { |
|
| 2252 | - if ($fuser->rights->fournisseur->commande->{$lire}) $accessallowed=1; |
|
| 2253 | - $original_file=$conf->fournisseur->commande->dir_temp.'/'.$original_file; |
|
| 2254 | - } |
|
| 2255 | - // Wrapping pour les images des stats factures |
|
| 2256 | - elseif ($modulepart == 'billstats' && !empty($conf->facture->dir_temp)) |
|
| 2257 | - { |
|
| 2258 | - if ($fuser->rights->facture->{$lire}) $accessallowed=1; |
|
| 2259 | - $original_file=$conf->facture->dir_temp.'/'.$original_file; |
|
| 2260 | - } |
|
| 2261 | - elseif ($modulepart == 'billstatssupplier' && !empty($conf->fournisseur->dir_output)) |
|
| 2262 | - { |
|
| 2263 | - if ($fuser->rights->fournisseur->facture->{$lire}) $accessallowed=1; |
|
| 2264 | - $original_file=$conf->fournisseur->facture->dir_temp.'/'.$original_file; |
|
| 2265 | - } |
|
| 2266 | - // Wrapping pour les images des stats expeditions |
|
| 2267 | - elseif ($modulepart == 'expeditionstats' && !empty($conf->expedition->dir_temp)) |
|
| 2268 | - { |
|
| 2269 | - if ($fuser->rights->expedition->{$lire}) $accessallowed=1; |
|
| 2270 | - $original_file=$conf->expedition->dir_temp.'/'.$original_file; |
|
| 2271 | - } |
|
| 2272 | - // Wrapping pour les images des stats expeditions |
|
| 2273 | - elseif ($modulepart == 'tripsexpensesstats' && !empty($conf->deplacement->dir_temp)) |
|
| 2274 | - { |
|
| 2275 | - if ($fuser->rights->deplacement->{$lire}) $accessallowed=1; |
|
| 2276 | - $original_file=$conf->deplacement->dir_temp.'/'.$original_file; |
|
| 2277 | - } |
|
| 2278 | - // Wrapping pour les images des stats expeditions |
|
| 2279 | - elseif ($modulepart == 'memberstats' && !empty($conf->adherent->dir_temp)) |
|
| 2280 | - { |
|
| 2281 | - if ($fuser->rights->adherent->{$lire}) $accessallowed=1; |
|
| 2282 | - $original_file=$conf->adherent->dir_temp.'/'.$original_file; |
|
| 2283 | - } |
|
| 2284 | - // Wrapping pour les images des stats produits |
|
| 2285 | - elseif (preg_match('/^productstats_/i',$modulepart) && !empty($conf->product->dir_temp)) |
|
| 2286 | - { |
|
| 2287 | - if ($fuser->rights->produit->{$lire} || $fuser->rights->service->{$lire}) $accessallowed=1; |
|
| 2288 | - $original_file=(!empty($conf->product->multidir_temp[$entity])?$conf->product->multidir_temp[$entity]:$conf->service->multidir_temp[$entity]).'/'.$original_file; |
|
| 2289 | - } |
|
| 2290 | - // Wrapping for taxes |
|
| 2291 | - elseif ($modulepart == 'tax' && !empty($conf->tax->dir_output)) |
|
| 2292 | - { |
|
| 2293 | - if ($fuser->rights->tax->charges->{$lire}) $accessallowed=1; |
|
| 2294 | - $original_file=$conf->tax->dir_output.'/'.$original_file; |
|
| 2295 | - } |
|
| 2296 | - // Wrapping for events |
|
| 2297 | - elseif ($modulepart == 'actions' && !empty($conf->agenda->dir_output)) |
|
| 2298 | - { |
|
| 2299 | - if ($fuser->rights->agenda->myactions->{$read}) $accessallowed=1; |
|
| 2300 | - $original_file=$conf->agenda->dir_output.'/'.$original_file; |
|
| 2301 | - } |
|
| 2302 | - // Wrapping for categories |
|
| 2303 | - elseif ($modulepart == 'category' && !empty($conf->categorie->dir_output)) |
|
| 2304 | - { |
|
| 2305 | - if (empty($entity) || empty($conf->categorie->multidir_output[$entity])) return array('accessallowed'=>0, 'error'=>'Value entity must be provided'); |
|
| 2306 | - if ($fuser->rights->categorie->{$lire}) $accessallowed=1; |
|
| 2307 | - $original_file=$conf->categorie->multidir_output[$entity].'/'.$original_file; |
|
| 2308 | - } |
|
| 2309 | - // Wrapping pour les prelevements |
|
| 2310 | - elseif ($modulepart == 'prelevement' && !empty($conf->prelevement->dir_output)) |
|
| 2311 | - { |
|
| 2312 | - if ($fuser->rights->prelevement->bons->{$lire} || preg_match('/^specimen/i',$original_file)) $accessallowed=1; |
|
| 2313 | - $original_file=$conf->prelevement->dir_output.'/'.$original_file; |
|
| 2314 | - } |
|
| 2315 | - // Wrapping pour les graph energie |
|
| 2316 | - elseif ($modulepart == 'graph_stock' && !empty($conf->stock->dir_temp)) |
|
| 2317 | - { |
|
| 2318 | - $accessallowed=1; |
|
| 2319 | - $original_file=$conf->stock->dir_temp.'/'.$original_file; |
|
| 2320 | - } |
|
| 2321 | - // Wrapping pour les graph fournisseurs |
|
| 2322 | - elseif ($modulepart == 'graph_fourn' && !empty($conf->fournisseur->dir_temp)) |
|
| 2323 | - { |
|
| 2324 | - $accessallowed=1; |
|
| 2325 | - $original_file=$conf->fournisseur->dir_temp.'/'.$original_file; |
|
| 2326 | - } |
|
| 2327 | - // Wrapping pour les graph des produits |
|
| 2328 | - elseif ($modulepart == 'graph_product' && !empty($conf->product->dir_temp)) |
|
| 2329 | - { |
|
| 2330 | - $accessallowed=1; |
|
| 2331 | - $original_file=$conf->product->multidir_temp[$entity].'/'.$original_file; |
|
| 2332 | - } |
|
| 2333 | - // Wrapping pour les code barre |
|
| 2334 | - elseif ($modulepart == 'barcode') |
|
| 2335 | - { |
|
| 2336 | - $accessallowed=1; |
|
| 2337 | - // If viewimage is called for barcode, we try to output an image on the fly, with no build of file on disk. |
|
| 2338 | - //$original_file=$conf->barcode->dir_temp.'/'.$original_file; |
|
| 2339 | - $original_file=''; |
|
| 2340 | - } |
|
| 2341 | - // Wrapping pour les icones de background des mailings |
|
| 2342 | - elseif ($modulepart == 'iconmailing' && !empty($conf->mailing->dir_temp)) |
|
| 2343 | - { |
|
| 2344 | - $accessallowed=1; |
|
| 2345 | - $original_file=$conf->mailing->dir_temp.'/'.$original_file; |
|
| 2346 | - } |
|
| 2347 | - // Wrapping pour le scanner |
|
| 2348 | - elseif ($modulepart == 'scanner_user_temp' && !empty($conf->scanner->dir_temp)) |
|
| 2349 | - { |
|
| 2350 | - $accessallowed=1; |
|
| 2351 | - $original_file=$conf->scanner->dir_temp.'/'.$fuser->id.'/'.$original_file; |
|
| 2352 | - } |
|
| 2353 | - // Wrapping pour les images fckeditor |
|
| 2354 | - elseif ($modulepart == 'fckeditor' && !empty($conf->fckeditor->dir_output)) |
|
| 2355 | - { |
|
| 2356 | - $accessallowed=1; |
|
| 2357 | - $original_file=$conf->fckeditor->dir_output.'/'.$original_file; |
|
| 2358 | - } |
|
| 2359 | - |
|
| 2360 | - // Wrapping for users |
|
| 2361 | - else if ($modulepart == 'user' && !empty($conf->user->dir_output)) |
|
| 2362 | - { |
|
| 2363 | - $canreaduser=(! empty($fuser->admin) || $fuser->rights->user->user->{$lire}); |
|
| 2364 | - if ($fuser->id == (int) $refname) { $canreaduser=1; } // A user can always read its own card |
|
| 2365 | - if ($canreaduser || preg_match('/^specimen/i',$original_file)) |
|
| 2366 | - { |
|
| 2367 | - $accessallowed=1; |
|
| 2368 | - } |
|
| 2369 | - $original_file=$conf->user->dir_output.'/'.$original_file; |
|
| 2370 | - } |
|
| 2371 | - |
|
| 2372 | - // Wrapping for third parties |
|
| 2373 | - else if (($modulepart == 'company' || $modulepart == 'societe') && !empty($conf->societe->dir_output)) |
|
| 2374 | - { |
|
| 2375 | - if (empty($entity) || empty($conf->societe->multidir_output[$entity])) return array('accessallowed'=>0, 'error'=>'Value entity must be provided'); |
|
| 2376 | - if ($fuser->rights->societe->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2377 | - { |
|
| 2378 | - $accessallowed=1; |
|
| 2379 | - } |
|
| 2380 | - $original_file=$conf->societe->multidir_output[$entity].'/'.$original_file; |
|
| 2381 | - $sqlprotectagainstexternals = "SELECT rowid as fk_soc FROM ".MAIN_DB_PREFIX."societe WHERE rowid='".$db->escape($refname)."' AND entity IN (".getEntity('societe').")"; |
|
| 2382 | - } |
|
| 2383 | - |
|
| 2384 | - // Wrapping for contact |
|
| 2385 | - else if ($modulepart == 'contact' && !empty($conf->societe->dir_output)) |
|
| 2386 | - { |
|
| 2387 | - if (empty($entity) || empty($conf->societe->multidir_output[$entity])) return array('accessallowed'=>0, 'error'=>'Value entity must be provided'); |
|
| 2388 | - if ($fuser->rights->societe->{$lire}) |
|
| 2389 | - { |
|
| 2390 | - $accessallowed=1; |
|
| 2391 | - } |
|
| 2392 | - $original_file=$conf->societe->multidir_output[$entity].'/contact/'.$original_file; |
|
| 2393 | - } |
|
| 2394 | - |
|
| 2395 | - // Wrapping for invoices |
|
| 2396 | - else if (($modulepart == 'facture' || $modulepart == 'invoice') && !empty($conf->facture->dir_output)) |
|
| 2397 | - { |
|
| 2398 | - if ($fuser->rights->facture->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2399 | - { |
|
| 2400 | - $accessallowed=1; |
|
| 2401 | - } |
|
| 2402 | - $original_file=$conf->facture->dir_output.'/'.$original_file; |
|
| 2403 | - $sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."facture WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity; |
|
| 2404 | - } |
|
| 2405 | - // Wrapping for mass actions |
|
| 2406 | - else if ($modulepart == 'massfilesarea_proposals' && !empty($conf->propal->multidir_output[$entity])) |
|
| 2407 | - { |
|
| 2408 | - if ($fuser->rights->propal->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2409 | - { |
|
| 2410 | - $accessallowed=1; |
|
| 2411 | - } |
|
| 2412 | - $original_file=$conf->propal->multidir_output[$entity].'/temp/massgeneration/'.$user->id.'/'.$original_file; |
|
| 2413 | - } |
|
| 2414 | - else if ($modulepart == 'massfilesarea_orders') |
|
| 2415 | - { |
|
| 2416 | - if ($fuser->rights->commande->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2417 | - { |
|
| 2418 | - $accessallowed=1; |
|
| 2419 | - } |
|
| 2420 | - $original_file=$conf->commande->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; |
|
| 2421 | - } |
|
| 2422 | - else if ($modulepart == 'massfilesarea_invoices') |
|
| 2423 | - { |
|
| 2424 | - if ($fuser->rights->facture->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2425 | - { |
|
| 2426 | - $accessallowed=1; |
|
| 2427 | - } |
|
| 2428 | - $original_file=$conf->facture->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; |
|
| 2429 | - } |
|
| 2430 | - else if ($modulepart == 'massfilesarea_expensereport') |
|
| 2431 | - { |
|
| 2432 | - if ($fuser->rights->facture->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2433 | - { |
|
| 2434 | - $accessallowed=1; |
|
| 2435 | - } |
|
| 2436 | - $original_file=$conf->expensereport->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; |
|
| 2437 | - } |
|
| 2438 | - else if ($modulepart == 'massfilesarea_interventions') |
|
| 2439 | - { |
|
| 2440 | - if ($fuser->rights->ficheinter->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2441 | - { |
|
| 2442 | - $accessallowed=1; |
|
| 2443 | - } |
|
| 2444 | - $original_file=$conf->ficheinter->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; |
|
| 2445 | - } |
|
| 2446 | - else if ($modulepart == 'massfilesarea_supplier_proposal' && !empty($conf->supplier_proposal->dir_output)) |
|
| 2447 | - { |
|
| 2448 | - if ($fuser->rights->supplier_proposal->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2449 | - { |
|
| 2450 | - $accessallowed=1; |
|
| 2451 | - } |
|
| 2452 | - $original_file=$conf->supplier_proposal->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; |
|
| 2453 | - } |
|
| 2454 | - else if ($modulepart == 'massfilesarea_supplier_order') |
|
| 2455 | - { |
|
| 2456 | - if ($fuser->rights->fournisseur->commande->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2457 | - { |
|
| 2458 | - $accessallowed=1; |
|
| 2459 | - } |
|
| 2460 | - $original_file=$conf->fournisseur->commande->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; |
|
| 2461 | - } |
|
| 2462 | - else if ($modulepart == 'massfilesarea_supplier_invoice') |
|
| 2463 | - { |
|
| 2464 | - if ($fuser->rights->fournisseur->facture->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2465 | - { |
|
| 2466 | - $accessallowed=1; |
|
| 2467 | - } |
|
| 2468 | - $original_file=$conf->fournisseur->facture->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; |
|
| 2469 | - } |
|
| 2470 | - else if ($modulepart == 'massfilesarea_contract' && !empty($conf->contrat->dir_output)) |
|
| 2471 | - { |
|
| 2472 | - if ($fuser->rights->contrat->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2473 | - { |
|
| 2474 | - $accessallowed=1; |
|
| 2475 | - } |
|
| 2476 | - $original_file=$conf->contrat->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; |
|
| 2477 | - } |
|
| 2478 | - |
|
| 2479 | - // Wrapping for interventions |
|
| 2480 | - else if (($modulepart == 'fichinter' || $modulepart == 'ficheinter') && !empty($conf->ficheinter->dir_output)) |
|
| 2481 | - { |
|
| 2482 | - if ($fuser->rights->ficheinter->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2483 | - { |
|
| 2484 | - $accessallowed=1; |
|
| 2485 | - } |
|
| 2486 | - $original_file=$conf->ficheinter->dir_output.'/'.$original_file; |
|
| 2487 | - $sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."fichinter WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity; |
|
| 2488 | - } |
|
| 2489 | - |
|
| 2490 | - // Wrapping pour les deplacements et notes de frais |
|
| 2491 | - else if ($modulepart == 'deplacement' && !empty($conf->deplacement->dir_output)) |
|
| 2492 | - { |
|
| 2493 | - if ($fuser->rights->deplacement->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2494 | - { |
|
| 2495 | - $accessallowed=1; |
|
| 2496 | - } |
|
| 2497 | - $original_file=$conf->deplacement->dir_output.'/'.$original_file; |
|
| 2498 | - //$sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."fichinter WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity; |
|
| 2499 | - } |
|
| 2500 | - // Wrapping pour les propales |
|
| 2501 | - else if (($modulepart == 'propal' || $modulepart == 'propale') && !empty($conf->propal->multidir_output[$entity])) |
|
| 2502 | - { |
|
| 2503 | - if ($fuser->rights->propale->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2504 | - { |
|
| 2505 | - $accessallowed=1; |
|
| 2506 | - } |
|
| 2507 | - $original_file=$conf->propal->multidir_output[$entity].'/'.$original_file; |
|
| 2508 | - $sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."propal WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity; |
|
| 2509 | - } |
|
| 2510 | - |
|
| 2511 | - // Wrapping pour les commandes |
|
| 2512 | - else if (($modulepart == 'commande' || $modulepart == 'order') && !empty($conf->commande->dir_output)) |
|
| 2513 | - { |
|
| 2514 | - if ($fuser->rights->commande->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2515 | - { |
|
| 2516 | - $accessallowed=1; |
|
| 2517 | - } |
|
| 2518 | - $original_file=$conf->commande->dir_output.'/'.$original_file; |
|
| 2519 | - $sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."commande WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity; |
|
| 2520 | - } |
|
| 2521 | - |
|
| 2522 | - // Wrapping pour les projets |
|
| 2523 | - else if ($modulepart == 'project' && !empty($conf->projet->dir_output)) |
|
| 2524 | - { |
|
| 2525 | - if ($fuser->rights->projet->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2526 | - { |
|
| 2527 | - $accessallowed=1; |
|
| 2528 | - } |
|
| 2529 | - $original_file=$conf->projet->dir_output.'/'.$original_file; |
|
| 2530 | - $sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."projet WHERE ref='".$db->escape($refname)."' AND entity IN (".getEntity('project').")"; |
|
| 2531 | - } |
|
| 2532 | - else if ($modulepart == 'project_task' && !empty($conf->projet->dir_output)) |
|
| 2533 | - { |
|
| 2534 | - if ($fuser->rights->projet->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2535 | - { |
|
| 2536 | - $accessallowed=1; |
|
| 2537 | - } |
|
| 2538 | - $original_file=$conf->projet->dir_output.'/'.$original_file; |
|
| 2539 | - $sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."projet WHERE ref='".$db->escape($refname)."' AND entity IN (".getEntity('project').")"; |
|
| 2540 | - } |
|
| 2541 | - |
|
| 2542 | - // Wrapping pour les commandes fournisseurs |
|
| 2543 | - else if (($modulepart == 'commande_fournisseur' || $modulepart == 'order_supplier') && !empty($conf->fournisseur->commande->dir_output)) |
|
| 2544 | - { |
|
| 2545 | - if ($fuser->rights->fournisseur->commande->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2546 | - { |
|
| 2547 | - $accessallowed=1; |
|
| 2548 | - } |
|
| 2549 | - $original_file=$conf->fournisseur->commande->dir_output.'/'.$original_file; |
|
| 2550 | - $sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."commande_fournisseur WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity; |
|
| 2551 | - } |
|
| 2552 | - |
|
| 2553 | - // Wrapping pour les factures fournisseurs |
|
| 2554 | - else if (($modulepart == 'facture_fournisseur' || $modulepart == 'invoice_supplier') && !empty($conf->fournisseur->facture->dir_output)) |
|
| 2555 | - { |
|
| 2556 | - if ($fuser->rights->fournisseur->facture->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2557 | - { |
|
| 2558 | - $accessallowed=1; |
|
| 2559 | - } |
|
| 2560 | - $original_file=$conf->fournisseur->facture->dir_output.'/'.$original_file; |
|
| 2561 | - $sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."facture_fourn WHERE facnumber='".$db->escape($refname)."' AND entity=".$conf->entity; |
|
| 2562 | - } |
|
| 2563 | - // Wrapping pour les rapport de paiements |
|
| 2564 | - else if ($modulepart == 'supplier_payment') |
|
| 2565 | - { |
|
| 2566 | - if ($fuser->rights->fournisseur->facture->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2567 | - { |
|
| 2568 | - $accessallowed=1; |
|
| 2569 | - } |
|
| 2570 | - $original_file=$conf->fournisseur->payment->dir_output.'/'.$original_file; |
|
| 2571 | - $sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."paiementfournisseur WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity; |
|
| 2572 | - } |
|
| 2573 | - |
|
| 2574 | - // Wrapping pour les rapport de paiements |
|
| 2575 | - else if ($modulepart == 'facture_paiement' && !empty($conf->facture->dir_output)) |
|
| 2576 | - { |
|
| 2577 | - if ($fuser->rights->facture->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2578 | - { |
|
| 2579 | - $accessallowed=1; |
|
| 2580 | - } |
|
| 2581 | - if ($fuser->societe_id > 0) $original_file=$conf->facture->dir_output.'/payments/private/'.$fuser->id.'/'.$original_file; |
|
| 2582 | - else $original_file=$conf->facture->dir_output.'/payments/'.$original_file; |
|
| 2583 | - } |
|
| 2584 | - |
|
| 2585 | - // Wrapping for accounting exports |
|
| 2586 | - else if ($modulepart == 'export_compta' && !empty($conf->accounting->dir_output)) |
|
| 2587 | - { |
|
| 2588 | - if ($fuser->rights->accounting->bind->write || preg_match('/^specimen/i',$original_file)) |
|
| 2589 | - { |
|
| 2590 | - $accessallowed=1; |
|
| 2591 | - } |
|
| 2592 | - $original_file=$conf->accounting->dir_output.'/'.$original_file; |
|
| 2593 | - } |
|
| 2594 | - |
|
| 2595 | - // Wrapping pour les expedition |
|
| 2596 | - else if ($modulepart == 'expedition' && !empty($conf->expedition->dir_output)) |
|
| 2597 | - { |
|
| 2598 | - if ($fuser->rights->expedition->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2599 | - { |
|
| 2600 | - $accessallowed=1; |
|
| 2601 | - } |
|
| 2602 | - $original_file=$conf->expedition->dir_output."/sending/".$original_file; |
|
| 2603 | - } |
|
| 2604 | - // Wrapping pour les bons de livraison |
|
| 2605 | - else if ($modulepart == 'livraison' && !empty($conf->expedition->dir_output)) |
|
| 2606 | - { |
|
| 2607 | - if ($fuser->rights->expedition->livraison->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2608 | - { |
|
| 2609 | - $accessallowed=1; |
|
| 2610 | - } |
|
| 2611 | - $original_file=$conf->expedition->dir_output."/receipt/".$original_file; |
|
| 2612 | - } |
|
| 2613 | - |
|
| 2614 | - // Wrapping pour les actions |
|
| 2615 | - else if ($modulepart == 'actions' && !empty($conf->agenda->dir_output)) |
|
| 2616 | - { |
|
| 2617 | - if ($fuser->rights->agenda->myactions->{$read} || preg_match('/^specimen/i',$original_file)) |
|
| 2618 | - { |
|
| 2619 | - $accessallowed=1; |
|
| 2620 | - } |
|
| 2621 | - $original_file=$conf->agenda->dir_output.'/'.$original_file; |
|
| 2622 | - } |
|
| 2623 | - |
|
| 2624 | - // Wrapping pour les actions |
|
| 2625 | - else if ($modulepart == 'actionsreport' && !empty($conf->agenda->dir_temp)) |
|
| 2626 | - { |
|
| 2627 | - if ($fuser->rights->agenda->allactions->{$read} || preg_match('/^specimen/i',$original_file)) |
|
| 2628 | - { |
|
| 2629 | - $accessallowed=1; |
|
| 2630 | - } |
|
| 2631 | - $original_file = $conf->agenda->dir_temp."/".$original_file; |
|
| 2632 | - } |
|
| 2633 | - |
|
| 2634 | - // Wrapping pour les produits et services |
|
| 2635 | - else if ($modulepart == 'product' || $modulepart == 'produit' || $modulepart == 'service' || $modulepart == 'produit|service') |
|
| 2636 | - { |
|
| 2637 | - if (empty($entity) || (empty($conf->product->multidir_output[$entity]) && empty($conf->service->multidir_output[$entity]))) return array('accessallowed'=>0, 'error'=>'Value entity must be provided'); |
|
| 2638 | - if (($fuser->rights->produit->{$lire} || $fuser->rights->service->{$lire}) || preg_match('/^specimen/i',$original_file)) |
|
| 2639 | - { |
|
| 2640 | - $accessallowed=1; |
|
| 2641 | - } |
|
| 2642 | - if (! empty($conf->product->enabled)) $original_file=$conf->product->multidir_output[$entity].'/'.$original_file; |
|
| 2643 | - elseif (! empty($conf->service->enabled)) $original_file=$conf->service->multidir_output[$entity].'/'.$original_file; |
|
| 2644 | - } |
|
| 2645 | - |
|
| 2646 | - // Wrapping pour les lots produits |
|
| 2647 | - else if ($modulepart == 'product_batch' || $modulepart == 'produitlot') |
|
| 2648 | - { |
|
| 2649 | - if (empty($entity) || (empty($conf->productbatch->multidir_output[$entity]))) return array('accessallowed'=>0, 'error'=>'Value entity must be provided'); |
|
| 2650 | - if (($fuser->rights->produit->{$lire} ) || preg_match('/^specimen/i',$original_file)) |
|
| 2651 | - { |
|
| 2652 | - $accessallowed=1; |
|
| 2653 | - } |
|
| 2654 | - if (! empty($conf->productbatch->enabled)) $original_file=$conf->productbatch->multidir_output[$entity].'/'.$original_file; |
|
| 2655 | - } |
|
| 2656 | - |
|
| 2657 | - // Wrapping pour les contrats |
|
| 2658 | - else if ($modulepart == 'contract' && !empty($conf->contrat->dir_output)) |
|
| 2659 | - { |
|
| 2660 | - if ($fuser->rights->contrat->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2661 | - { |
|
| 2662 | - $accessallowed=1; |
|
| 2663 | - } |
|
| 2664 | - $original_file=$conf->contrat->dir_output.'/'.$original_file; |
|
| 2665 | - $sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."contrat WHERE ref='".$db->escape($refname)."' AND entity IN (".getEntity('contract').")"; |
|
| 2666 | - } |
|
| 2667 | - |
|
| 2668 | - // Wrapping pour les dons |
|
| 2669 | - else if ($modulepart == 'donation' && !empty($conf->don->dir_output)) |
|
| 2670 | - { |
|
| 2671 | - if ($fuser->rights->don->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2672 | - { |
|
| 2673 | - $accessallowed=1; |
|
| 2674 | - } |
|
| 2675 | - $original_file=$conf->don->dir_output.'/'.$original_file; |
|
| 2676 | - } |
|
| 2677 | - |
|
| 2678 | - // Wrapping pour les dons |
|
| 2679 | - else if ($modulepart == 'dolresource' && !empty($conf->resource->dir_output)) |
|
| 2680 | - { |
|
| 2681 | - if ($fuser->rights->resource->{$read} || preg_match('/^specimen/i',$original_file)) |
|
| 2682 | - { |
|
| 2683 | - $accessallowed=1; |
|
| 2684 | - } |
|
| 2685 | - $original_file=$conf->resource->dir_output.'/'.$original_file; |
|
| 2686 | - } |
|
| 2687 | - |
|
| 2688 | - // Wrapping pour les remises de cheques |
|
| 2689 | - else if ($modulepart == 'remisecheque' && !empty($conf->banque->dir_output)) |
|
| 2690 | - { |
|
| 2691 | - if ($fuser->rights->banque->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2692 | - { |
|
| 2693 | - $accessallowed=1; |
|
| 2694 | - } |
|
| 2695 | - |
|
| 2696 | - $original_file=$conf->bank->dir_output.'/checkdeposits/'.$original_file; // original_file should contains relative path so include the get_exdir result |
|
| 2697 | - } |
|
| 2698 | - |
|
| 2699 | - // Wrapping for bank |
|
| 2700 | - else if ($modulepart == 'bank' && !empty($conf->bank->dir_output)) |
|
| 2701 | - { |
|
| 2702 | - if ($fuser->rights->banque->{$lire}) |
|
| 2703 | - { |
|
| 2704 | - $accessallowed=1; |
|
| 2705 | - } |
|
| 2706 | - $original_file=$conf->bank->dir_output.'/'.$original_file; |
|
| 2707 | - } |
|
| 2708 | - |
|
| 2709 | - // Wrapping for export module |
|
| 2710 | - else if ($modulepart == 'export' && !empty($conf->export->dir_temp)) |
|
| 2711 | - { |
|
| 2712 | - // Aucun test necessaire car on force le rep de download sur |
|
| 2713 | - // le rep export qui est propre a l'utilisateur |
|
| 2714 | - $accessallowed=1; |
|
| 2715 | - $original_file=$conf->export->dir_temp.'/'.$fuser->id.'/'.$original_file; |
|
| 2716 | - } |
|
| 2717 | - |
|
| 2718 | - // Wrapping for import module |
|
| 2719 | - else if ($modulepart == 'import' && !empty($conf->import->dir_temp)) |
|
| 2720 | - { |
|
| 2721 | - $accessallowed=1; |
|
| 2722 | - $original_file=$conf->import->dir_temp.'/'.$original_file; |
|
| 2723 | - } |
|
| 2724 | - |
|
| 2725 | - // Wrapping pour l'editeur wysiwyg |
|
| 2726 | - else if ($modulepart == 'editor' && !empty($conf->fckeditor->dir_output)) |
|
| 2727 | - { |
|
| 2728 | - $accessallowed=1; |
|
| 2729 | - $original_file=$conf->fckeditor->dir_output.'/'.$original_file; |
|
| 2730 | - } |
|
| 2731 | - |
|
| 2732 | - // Wrapping for backups |
|
| 2733 | - else if ($modulepart == 'systemtools' && !empty($conf->admin->dir_output)) |
|
| 2734 | - { |
|
| 2735 | - if ($fuser->admin) $accessallowed=1; |
|
| 2736 | - $original_file=$conf->admin->dir_output.'/'.$original_file; |
|
| 2737 | - } |
|
| 2738 | - |
|
| 2739 | - // Wrapping for upload file test |
|
| 2740 | - else if ($modulepart == 'admin_temp' && !empty($conf->admin->dir_temp)) |
|
| 2741 | - { |
|
| 2742 | - if ($fuser->admin) $accessallowed=1; |
|
| 2743 | - $original_file=$conf->admin->dir_temp.'/'.$original_file; |
|
| 2744 | - } |
|
| 2745 | - |
|
| 2746 | - // Wrapping pour BitTorrent |
|
| 2747 | - else if ($modulepart == 'bittorrent' && !empty($conf->bittorrent->dir_output)) |
|
| 2748 | - { |
|
| 2749 | - $accessallowed=1; |
|
| 2750 | - $dir='files'; |
|
| 2751 | - if (dol_mimetype($original_file) == 'application/x-bittorrent') $dir='torrents'; |
|
| 2752 | - $original_file=$conf->bittorrent->dir_output.'/'.$dir.'/'.$original_file; |
|
| 2753 | - } |
|
| 2754 | - |
|
| 2755 | - // Wrapping pour Foundation module |
|
| 2756 | - else if ($modulepart == 'member' && !empty($conf->adherent->dir_output)) |
|
| 2757 | - { |
|
| 2758 | - if ($fuser->rights->adherent->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2759 | - { |
|
| 2760 | - $accessallowed=1; |
|
| 2761 | - } |
|
| 2762 | - $original_file=$conf->adherent->dir_output.'/'.$original_file; |
|
| 2763 | - } |
|
| 2764 | - |
|
| 2765 | - // Wrapping for Scanner |
|
| 2766 | - else if ($modulepart == 'scanner_user_temp' && !empty($conf->scanner->dir_temp)) |
|
| 2767 | - { |
|
| 2768 | - $accessallowed=1; |
|
| 2769 | - $original_file=$conf->scanner->dir_temp.'/'.$fuser->id.'/'.$original_file; |
|
| 2770 | - } |
|
| 2771 | - |
|
| 2772 | - // GENERIC Wrapping |
|
| 2773 | - // If modulepart=module_user_temp Allows any module to open a file if file is in directory called DOL_DATA_ROOT/modulepart/temp/iduser |
|
| 2774 | - // If modulepart=module_temp Allows any module to open a file if file is in directory called DOL_DATA_ROOT/modulepart/temp |
|
| 2775 | - // If modulepart=module_user Allows any module to open a file if file is in directory called DOL_DATA_ROOT/modulepart/iduser |
|
| 2776 | - // If modulepart=module Allows any module to open a file if file is in directory called DOL_DATA_ROOT/modulepart |
|
| 2777 | - else |
|
| 2778 | - { |
|
| 2779 | - if (preg_match('/^specimen/i',$original_file)) $accessallowed=1; // If link to a file called specimen. Test must be done before changing $original_file int full path. |
|
| 2780 | - if ($fuser->admin) $accessallowed=1; // If user is admin |
|
| 2781 | - |
|
| 2782 | - // Define $accessallowed |
|
| 2783 | - if (preg_match('/^([a-z]+)_user_temp$/i',$modulepart,$reg)) |
|
| 2784 | - { |
|
| 2785 | - if (empty($conf->{$reg[1]}->dir_temp)) // modulepart not supported |
|
| 2786 | - { |
|
| 2787 | - dol_print_error('','Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')'); |
|
| 2788 | - exit; |
|
| 2789 | - } |
|
| 2790 | - if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) $accessallowed=1; |
|
| 2791 | - $original_file=$conf->{$reg[1]}->dir_temp.'/'.$fuser->id.'/'.$original_file; |
|
| 2792 | - } |
|
| 2793 | - else if (preg_match('/^([a-z]+)_temp$/i',$modulepart,$reg)) |
|
| 2794 | - { |
|
| 2795 | - if (empty($conf->{$reg[1]}->dir_temp)) // modulepart not supported |
|
| 2796 | - { |
|
| 2797 | - dol_print_error('','Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')'); |
|
| 2798 | - exit; |
|
| 2799 | - } |
|
| 2800 | - if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) $accessallowed=1; |
|
| 2801 | - $original_file=$conf->{$reg[1]}->dir_temp.'/'.$original_file; |
|
| 2802 | - } |
|
| 2803 | - else if (preg_match('/^([a-z]+)_user$/i',$modulepart,$reg)) |
|
| 2804 | - { |
|
| 2805 | - if (empty($conf->{$reg[1]}->dir_output)) // modulepart not supported |
|
| 2806 | - { |
|
| 2807 | - dol_print_error('','Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')'); |
|
| 2808 | - exit; |
|
| 2809 | - } |
|
| 2810 | - if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) $accessallowed=1; |
|
| 2811 | - $original_file=$conf->{$reg[1]}->dir_output.'/'.$fuser->id.'/'.$original_file; |
|
| 2812 | - } |
|
| 2813 | - else if (preg_match('/^massfilesarea_([a-z]+)$/i', $modulepart, $reg)) |
|
| 2814 | - { |
|
| 2815 | - if (empty($conf->{$reg[1]}->dir_output)) // modulepart not supported |
|
| 2816 | - { |
|
| 2817 | - dol_print_error('','Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')'); |
|
| 2818 | - exit; |
|
| 2819 | - } |
|
| 2820 | - if ($fuser->rights->{$reg[1]}->{$lire} || preg_match('/^specimen/i', $original_file)) |
|
| 2821 | - { |
|
| 2822 | - $accessallowed=1; |
|
| 2823 | - } |
|
| 2824 | - $original_file=$conf->{$reg[1]}->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; |
|
| 2825 | - } |
|
| 2826 | - else |
|
| 2827 | - { |
|
| 2828 | - if (empty($conf->$modulepart->dir_output)) // modulepart not supported |
|
| 2829 | - { |
|
| 2830 | - dol_print_error('','Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')'); |
|
| 2831 | - exit; |
|
| 2832 | - } |
|
| 2833 | - |
|
| 2834 | - $perm=GETPOST('perm'); |
|
| 2835 | - $subperm=GETPOST('subperm'); |
|
| 2836 | - if ($perm || $subperm) |
|
| 2837 | - { |
|
| 2838 | - if (($perm && ! $subperm && $fuser->rights->$modulepart->$perm) || ($perm && $subperm && $fuser->rights->$modulepart->$perm->$subperm)) $accessallowed=1; |
|
| 2839 | - $original_file=$conf->$modulepart->dir_output.'/'.$original_file; |
|
| 2840 | - } |
|
| 2841 | - else |
|
| 2842 | - { |
|
| 2843 | - if ($fuser->rights->$modulepart->{$lire} || $fuser->rights->$modulepart->{$read}) $accessallowed=1; |
|
| 2844 | - $original_file=$conf->$modulepart->dir_output.'/'.$original_file; |
|
| 2845 | - } |
|
| 2846 | - } |
|
| 2847 | - |
|
| 2848 | - // For modules who wants to manage different levels of permissions for documents |
|
| 2849 | - $subPermCategoryConstName = strtoupper($modulepart).'_SUBPERMCATEGORY_FOR_DOCUMENTS'; |
|
| 2850 | - if (! empty($conf->global->$subPermCategoryConstName)) |
|
| 2851 | - { |
|
| 2852 | - $subPermCategory = $conf->global->$subPermCategoryConstName; |
|
| 2853 | - if (! empty($subPermCategory) && (($fuser->rights->$modulepart->$subPermCategory->{$lire}) || ($fuser->rights->$modulepart->$subPermCategory->{$read}) || ($fuser->rights->$modulepart->$subPermCategory->{$download}))) |
|
| 2854 | - { |
|
| 2855 | - $accessallowed=1; |
|
| 2856 | - } |
|
| 2857 | - } |
|
| 2858 | - |
|
| 2859 | - // Define $sqlprotectagainstexternals for modules who want to protect access using a SQL query. |
|
| 2860 | - $sqlProtectConstName = strtoupper($modulepart).'_SQLPROTECTAGAINSTEXTERNALS_FOR_DOCUMENTS'; |
|
| 2861 | - if (! empty($conf->global->$sqlProtectConstName)) // If module want to define its own $sqlprotectagainstexternals |
|
| 2862 | - { |
|
| 2863 | - // Example: mymodule__SQLPROTECTAGAINSTEXTERNALS_FOR_DOCUMENTS = "SELECT fk_soc FROM ".MAIN_DB_PREFIX.$modulepart." WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity; |
|
| 2864 | - eval('$sqlprotectagainstexternals = "'.$conf->global->$sqlProtectConstName.'";'); |
|
| 2865 | - } |
|
| 2866 | - } |
|
| 2867 | - |
|
| 2868 | - $ret = array( |
|
| 2869 | - 'accessallowed' => $accessallowed, |
|
| 2870 | - 'sqlprotectagainstexternals'=>$sqlprotectagainstexternals, |
|
| 2871 | - 'original_file'=>$original_file |
|
| 2872 | - ); |
|
| 2873 | - |
|
| 2874 | - return $ret; |
|
| 2111 | + global $conf, $db, $user; |
|
| 2112 | + global $dolibarr_main_data_root, $dolibarr_main_document_root_alt; |
|
| 2113 | + |
|
| 2114 | + if (! is_object($fuser)) $fuser=$user; |
|
| 2115 | + |
|
| 2116 | + if (empty($modulepart)) return 'ErrorBadParameter'; |
|
| 2117 | + if (empty($entity)) |
|
| 2118 | + { |
|
| 2119 | + if (empty($conf->multicompany->enabled)) $entity=1; |
|
| 2120 | + else $entity=0; |
|
| 2121 | + } |
|
| 2122 | + // Fix modulepart |
|
| 2123 | + if ($modulepart == 'users') $modulepart='user'; |
|
| 2124 | + |
|
| 2125 | + dol_syslog('modulepart='.$modulepart.' original_file='.$original_file.' entity='.$entity); |
|
| 2126 | + // We define $accessallowed and $sqlprotectagainstexternals |
|
| 2127 | + $accessallowed=0; |
|
| 2128 | + $sqlprotectagainstexternals=''; |
|
| 2129 | + $ret=array(); |
|
| 2130 | + |
|
| 2131 | + // Find the subdirectory name as the reference. For exemple original_file='10/myfile.pdf' -> refname='10' |
|
| 2132 | + if (empty($refname)) $refname=basename(dirname($original_file)."/"); |
|
| 2133 | + |
|
| 2134 | + $relative_original_file = $original_file; |
|
| 2135 | + |
|
| 2136 | + // Define possible keys to use for permission check |
|
| 2137 | + $lire='lire'; $read='read'; $download='download'; |
|
| 2138 | + if ($mode == 'write') |
|
| 2139 | + { |
|
| 2140 | + $lire='creer'; $read='write'; $download='upload'; |
|
| 2141 | + } |
|
| 2142 | + |
|
| 2143 | + // Wrapping for miscellaneous medias files |
|
| 2144 | + if ($modulepart == 'medias' && !empty($dolibarr_main_data_root)) |
|
| 2145 | + { |
|
| 2146 | + if (empty($entity) || empty($conf->medias->multidir_output[$entity])) return array('accessallowed'=>0, 'error'=>'Value entity must be provided'); |
|
| 2147 | + $accessallowed=1; |
|
| 2148 | + $original_file=$conf->medias->multidir_output[$entity].'/'.$original_file; |
|
| 2149 | + } |
|
| 2150 | + // Wrapping for *.log files, like when used with url http://.../document.php?modulepart=logs&file=dolibarr.log |
|
| 2151 | + elseif ($modulepart == 'logs' && !empty($dolibarr_main_data_root)) |
|
| 2152 | + { |
|
| 2153 | + $accessallowed=($user->admin && basename($original_file) == $original_file && preg_match('/^dolibarr.*\.log$/', basename($original_file))); |
|
| 2154 | + $original_file=$dolibarr_main_data_root.'/'.$original_file; |
|
| 2155 | + } |
|
| 2156 | + // Wrapping for *.zip files, like when used with url http://.../document.php?modulepart=packages&file=module_myfile.zip |
|
| 2157 | + elseif ($modulepart == 'packages' && !empty($dolibarr_main_data_root)) |
|
| 2158 | + { |
|
| 2159 | + // Dir for custom dirs |
|
| 2160 | + $tmp=explode(',', $dolibarr_main_document_root_alt); |
|
| 2161 | + $dirins = $tmp[0]; |
|
| 2162 | + |
|
| 2163 | + $accessallowed=($user->admin && preg_match('/^module_.*\.zip$/', basename($original_file))); |
|
| 2164 | + $original_file=$dirins.'/'.$original_file; |
|
| 2165 | + } |
|
| 2166 | + // Wrapping for some images |
|
| 2167 | + elseif ($modulepart == 'mycompany' && !empty($conf->mycompany->dir_output)) |
|
| 2168 | + { |
|
| 2169 | + $accessallowed=1; |
|
| 2170 | + $original_file=$conf->mycompany->dir_output.'/'.$original_file; |
|
| 2171 | + } |
|
| 2172 | + // Wrapping for users photos |
|
| 2173 | + elseif ($modulepart == 'userphoto' && !empty($conf->user->dir_output)) |
|
| 2174 | + { |
|
| 2175 | + $accessallowed=1; |
|
| 2176 | + $original_file=$conf->user->dir_output.'/'.$original_file; |
|
| 2177 | + } |
|
| 2178 | + // Wrapping for members photos |
|
| 2179 | + elseif ($modulepart == 'memberphoto' && !empty($conf->adherent->dir_output)) |
|
| 2180 | + { |
|
| 2181 | + $accessallowed=1; |
|
| 2182 | + $original_file=$conf->adherent->dir_output.'/'.$original_file; |
|
| 2183 | + } |
|
| 2184 | + // Wrapping pour les apercu factures |
|
| 2185 | + elseif ($modulepart == 'apercufacture' && !empty($conf->facture->dir_output)) |
|
| 2186 | + { |
|
| 2187 | + if ($fuser->rights->facture->{$lire}) $accessallowed=1; |
|
| 2188 | + $original_file=$conf->facture->dir_output.'/'.$original_file; |
|
| 2189 | + } |
|
| 2190 | + // Wrapping pour les apercu propal |
|
| 2191 | + elseif ($modulepart == 'apercupropal' && !empty($conf->propal->multidir_output[$entity])) |
|
| 2192 | + { |
|
| 2193 | + if ($fuser->rights->propale->{$lire}) $accessallowed=1; |
|
| 2194 | + $original_file=$conf->propal->multidir_output[$entity].'/'.$original_file; |
|
| 2195 | + } |
|
| 2196 | + // Wrapping pour les apercu commande |
|
| 2197 | + elseif ($modulepart == 'apercucommande' && !empty($conf->commande->dir_output)) |
|
| 2198 | + { |
|
| 2199 | + if ($fuser->rights->commande->{$lire}) $accessallowed=1; |
|
| 2200 | + $original_file=$conf->commande->dir_output.'/'.$original_file; |
|
| 2201 | + } |
|
| 2202 | + // Wrapping pour les apercu intervention |
|
| 2203 | + elseif (($modulepart == 'apercufichinter' || $modulepart == 'apercuficheinter') && !empty($conf->ficheinter->dir_output)) |
|
| 2204 | + { |
|
| 2205 | + if ($fuser->rights->ficheinter->{$lire}) $accessallowed=1; |
|
| 2206 | + $original_file=$conf->ficheinter->dir_output.'/'.$original_file; |
|
| 2207 | + } |
|
| 2208 | + // Wrapping pour les apercu conat |
|
| 2209 | + elseif (($modulepart == 'apercucontract') && !empty($conf->contrat->dir_output)) |
|
| 2210 | + { |
|
| 2211 | + if ($fuser->rights->contrat->{$lire}) $accessallowed=1; |
|
| 2212 | + $original_file=$conf->contrat->dir_output.'/'.$original_file; |
|
| 2213 | + } |
|
| 2214 | + // Wrapping pour les apercu supplier proposal |
|
| 2215 | + elseif (($modulepart == 'apercusupplier_proposal' || $modulepart == 'apercusupplier_proposal') && !empty($conf->supplier_proposal->dir_output)) |
|
| 2216 | + { |
|
| 2217 | + if ($fuser->rights->supplier_proposal->{$lire}) $accessallowed=1; |
|
| 2218 | + $original_file=$conf->supplier_proposal->dir_output.'/'.$original_file; |
|
| 2219 | + } |
|
| 2220 | + // Wrapping pour les apercu supplier order |
|
| 2221 | + elseif (($modulepart == 'apercusupplier_order' || $modulepart == 'apercusupplier_order') && !empty($conf->fournisseur->commande->dir_output)) |
|
| 2222 | + { |
|
| 2223 | + if ($fuser->rights->fournisseur->commande->{$lire}) $accessallowed=1; |
|
| 2224 | + $original_file=$conf->fournisseur->commande->dir_output.'/'.$original_file; |
|
| 2225 | + } |
|
| 2226 | + // Wrapping pour les apercu supplier invoice |
|
| 2227 | + elseif (($modulepart == 'apercusupplier_invoice' || $modulepart == 'apercusupplier_invoice') && !empty($conf->fournisseur->facture->dir_output)) |
|
| 2228 | + { |
|
| 2229 | + if ($fuser->rights->fournisseur->facture->{$lire}) $accessallowed=1; |
|
| 2230 | + $original_file=$conf->fournisseur->facture->dir_output.'/'.$original_file; |
|
| 2231 | + } |
|
| 2232 | + // Wrapping pour les apercu supplier invoice |
|
| 2233 | + elseif (($modulepart == 'apercuexpensereport') && !empty($conf->expensereport->dir_output)) |
|
| 2234 | + { |
|
| 2235 | + if ($fuser->rights->expensereport->{$lire}) $accessallowed=1; |
|
| 2236 | + $original_file=$conf->expensereport->dir_output.'/'.$original_file; |
|
| 2237 | + } |
|
| 2238 | + // Wrapping pour les images des stats propales |
|
| 2239 | + elseif ($modulepart == 'propalstats' && !empty($conf->propal->multidir_temp[$entity])) |
|
| 2240 | + { |
|
| 2241 | + if ($fuser->rights->propale->{$lire}) $accessallowed=1; |
|
| 2242 | + $original_file=$conf->propal->multidir_temp[$entity].'/'.$original_file; |
|
| 2243 | + } |
|
| 2244 | + // Wrapping pour les images des stats commandes |
|
| 2245 | + elseif ($modulepart == 'orderstats' && !empty($conf->commande->dir_temp)) |
|
| 2246 | + { |
|
| 2247 | + if ($fuser->rights->commande->{$lire}) $accessallowed=1; |
|
| 2248 | + $original_file=$conf->commande->dir_temp.'/'.$original_file; |
|
| 2249 | + } |
|
| 2250 | + elseif ($modulepart == 'orderstatssupplier' && !empty($conf->fournisseur->dir_output)) |
|
| 2251 | + { |
|
| 2252 | + if ($fuser->rights->fournisseur->commande->{$lire}) $accessallowed=1; |
|
| 2253 | + $original_file=$conf->fournisseur->commande->dir_temp.'/'.$original_file; |
|
| 2254 | + } |
|
| 2255 | + // Wrapping pour les images des stats factures |
|
| 2256 | + elseif ($modulepart == 'billstats' && !empty($conf->facture->dir_temp)) |
|
| 2257 | + { |
|
| 2258 | + if ($fuser->rights->facture->{$lire}) $accessallowed=1; |
|
| 2259 | + $original_file=$conf->facture->dir_temp.'/'.$original_file; |
|
| 2260 | + } |
|
| 2261 | + elseif ($modulepart == 'billstatssupplier' && !empty($conf->fournisseur->dir_output)) |
|
| 2262 | + { |
|
| 2263 | + if ($fuser->rights->fournisseur->facture->{$lire}) $accessallowed=1; |
|
| 2264 | + $original_file=$conf->fournisseur->facture->dir_temp.'/'.$original_file; |
|
| 2265 | + } |
|
| 2266 | + // Wrapping pour les images des stats expeditions |
|
| 2267 | + elseif ($modulepart == 'expeditionstats' && !empty($conf->expedition->dir_temp)) |
|
| 2268 | + { |
|
| 2269 | + if ($fuser->rights->expedition->{$lire}) $accessallowed=1; |
|
| 2270 | + $original_file=$conf->expedition->dir_temp.'/'.$original_file; |
|
| 2271 | + } |
|
| 2272 | + // Wrapping pour les images des stats expeditions |
|
| 2273 | + elseif ($modulepart == 'tripsexpensesstats' && !empty($conf->deplacement->dir_temp)) |
|
| 2274 | + { |
|
| 2275 | + if ($fuser->rights->deplacement->{$lire}) $accessallowed=1; |
|
| 2276 | + $original_file=$conf->deplacement->dir_temp.'/'.$original_file; |
|
| 2277 | + } |
|
| 2278 | + // Wrapping pour les images des stats expeditions |
|
| 2279 | + elseif ($modulepart == 'memberstats' && !empty($conf->adherent->dir_temp)) |
|
| 2280 | + { |
|
| 2281 | + if ($fuser->rights->adherent->{$lire}) $accessallowed=1; |
|
| 2282 | + $original_file=$conf->adherent->dir_temp.'/'.$original_file; |
|
| 2283 | + } |
|
| 2284 | + // Wrapping pour les images des stats produits |
|
| 2285 | + elseif (preg_match('/^productstats_/i',$modulepart) && !empty($conf->product->dir_temp)) |
|
| 2286 | + { |
|
| 2287 | + if ($fuser->rights->produit->{$lire} || $fuser->rights->service->{$lire}) $accessallowed=1; |
|
| 2288 | + $original_file=(!empty($conf->product->multidir_temp[$entity])?$conf->product->multidir_temp[$entity]:$conf->service->multidir_temp[$entity]).'/'.$original_file; |
|
| 2289 | + } |
|
| 2290 | + // Wrapping for taxes |
|
| 2291 | + elseif ($modulepart == 'tax' && !empty($conf->tax->dir_output)) |
|
| 2292 | + { |
|
| 2293 | + if ($fuser->rights->tax->charges->{$lire}) $accessallowed=1; |
|
| 2294 | + $original_file=$conf->tax->dir_output.'/'.$original_file; |
|
| 2295 | + } |
|
| 2296 | + // Wrapping for events |
|
| 2297 | + elseif ($modulepart == 'actions' && !empty($conf->agenda->dir_output)) |
|
| 2298 | + { |
|
| 2299 | + if ($fuser->rights->agenda->myactions->{$read}) $accessallowed=1; |
|
| 2300 | + $original_file=$conf->agenda->dir_output.'/'.$original_file; |
|
| 2301 | + } |
|
| 2302 | + // Wrapping for categories |
|
| 2303 | + elseif ($modulepart == 'category' && !empty($conf->categorie->dir_output)) |
|
| 2304 | + { |
|
| 2305 | + if (empty($entity) || empty($conf->categorie->multidir_output[$entity])) return array('accessallowed'=>0, 'error'=>'Value entity must be provided'); |
|
| 2306 | + if ($fuser->rights->categorie->{$lire}) $accessallowed=1; |
|
| 2307 | + $original_file=$conf->categorie->multidir_output[$entity].'/'.$original_file; |
|
| 2308 | + } |
|
| 2309 | + // Wrapping pour les prelevements |
|
| 2310 | + elseif ($modulepart == 'prelevement' && !empty($conf->prelevement->dir_output)) |
|
| 2311 | + { |
|
| 2312 | + if ($fuser->rights->prelevement->bons->{$lire} || preg_match('/^specimen/i',$original_file)) $accessallowed=1; |
|
| 2313 | + $original_file=$conf->prelevement->dir_output.'/'.$original_file; |
|
| 2314 | + } |
|
| 2315 | + // Wrapping pour les graph energie |
|
| 2316 | + elseif ($modulepart == 'graph_stock' && !empty($conf->stock->dir_temp)) |
|
| 2317 | + { |
|
| 2318 | + $accessallowed=1; |
|
| 2319 | + $original_file=$conf->stock->dir_temp.'/'.$original_file; |
|
| 2320 | + } |
|
| 2321 | + // Wrapping pour les graph fournisseurs |
|
| 2322 | + elseif ($modulepart == 'graph_fourn' && !empty($conf->fournisseur->dir_temp)) |
|
| 2323 | + { |
|
| 2324 | + $accessallowed=1; |
|
| 2325 | + $original_file=$conf->fournisseur->dir_temp.'/'.$original_file; |
|
| 2326 | + } |
|
| 2327 | + // Wrapping pour les graph des produits |
|
| 2328 | + elseif ($modulepart == 'graph_product' && !empty($conf->product->dir_temp)) |
|
| 2329 | + { |
|
| 2330 | + $accessallowed=1; |
|
| 2331 | + $original_file=$conf->product->multidir_temp[$entity].'/'.$original_file; |
|
| 2332 | + } |
|
| 2333 | + // Wrapping pour les code barre |
|
| 2334 | + elseif ($modulepart == 'barcode') |
|
| 2335 | + { |
|
| 2336 | + $accessallowed=1; |
|
| 2337 | + // If viewimage is called for barcode, we try to output an image on the fly, with no build of file on disk. |
|
| 2338 | + //$original_file=$conf->barcode->dir_temp.'/'.$original_file; |
|
| 2339 | + $original_file=''; |
|
| 2340 | + } |
|
| 2341 | + // Wrapping pour les icones de background des mailings |
|
| 2342 | + elseif ($modulepart == 'iconmailing' && !empty($conf->mailing->dir_temp)) |
|
| 2343 | + { |
|
| 2344 | + $accessallowed=1; |
|
| 2345 | + $original_file=$conf->mailing->dir_temp.'/'.$original_file; |
|
| 2346 | + } |
|
| 2347 | + // Wrapping pour le scanner |
|
| 2348 | + elseif ($modulepart == 'scanner_user_temp' && !empty($conf->scanner->dir_temp)) |
|
| 2349 | + { |
|
| 2350 | + $accessallowed=1; |
|
| 2351 | + $original_file=$conf->scanner->dir_temp.'/'.$fuser->id.'/'.$original_file; |
|
| 2352 | + } |
|
| 2353 | + // Wrapping pour les images fckeditor |
|
| 2354 | + elseif ($modulepart == 'fckeditor' && !empty($conf->fckeditor->dir_output)) |
|
| 2355 | + { |
|
| 2356 | + $accessallowed=1; |
|
| 2357 | + $original_file=$conf->fckeditor->dir_output.'/'.$original_file; |
|
| 2358 | + } |
|
| 2359 | + |
|
| 2360 | + // Wrapping for users |
|
| 2361 | + else if ($modulepart == 'user' && !empty($conf->user->dir_output)) |
|
| 2362 | + { |
|
| 2363 | + $canreaduser=(! empty($fuser->admin) || $fuser->rights->user->user->{$lire}); |
|
| 2364 | + if ($fuser->id == (int) $refname) { $canreaduser=1; } // A user can always read its own card |
|
| 2365 | + if ($canreaduser || preg_match('/^specimen/i',$original_file)) |
|
| 2366 | + { |
|
| 2367 | + $accessallowed=1; |
|
| 2368 | + } |
|
| 2369 | + $original_file=$conf->user->dir_output.'/'.$original_file; |
|
| 2370 | + } |
|
| 2371 | + |
|
| 2372 | + // Wrapping for third parties |
|
| 2373 | + else if (($modulepart == 'company' || $modulepart == 'societe') && !empty($conf->societe->dir_output)) |
|
| 2374 | + { |
|
| 2375 | + if (empty($entity) || empty($conf->societe->multidir_output[$entity])) return array('accessallowed'=>0, 'error'=>'Value entity must be provided'); |
|
| 2376 | + if ($fuser->rights->societe->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2377 | + { |
|
| 2378 | + $accessallowed=1; |
|
| 2379 | + } |
|
| 2380 | + $original_file=$conf->societe->multidir_output[$entity].'/'.$original_file; |
|
| 2381 | + $sqlprotectagainstexternals = "SELECT rowid as fk_soc FROM ".MAIN_DB_PREFIX."societe WHERE rowid='".$db->escape($refname)."' AND entity IN (".getEntity('societe').")"; |
|
| 2382 | + } |
|
| 2383 | + |
|
| 2384 | + // Wrapping for contact |
|
| 2385 | + else if ($modulepart == 'contact' && !empty($conf->societe->dir_output)) |
|
| 2386 | + { |
|
| 2387 | + if (empty($entity) || empty($conf->societe->multidir_output[$entity])) return array('accessallowed'=>0, 'error'=>'Value entity must be provided'); |
|
| 2388 | + if ($fuser->rights->societe->{$lire}) |
|
| 2389 | + { |
|
| 2390 | + $accessallowed=1; |
|
| 2391 | + } |
|
| 2392 | + $original_file=$conf->societe->multidir_output[$entity].'/contact/'.$original_file; |
|
| 2393 | + } |
|
| 2394 | + |
|
| 2395 | + // Wrapping for invoices |
|
| 2396 | + else if (($modulepart == 'facture' || $modulepart == 'invoice') && !empty($conf->facture->dir_output)) |
|
| 2397 | + { |
|
| 2398 | + if ($fuser->rights->facture->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2399 | + { |
|
| 2400 | + $accessallowed=1; |
|
| 2401 | + } |
|
| 2402 | + $original_file=$conf->facture->dir_output.'/'.$original_file; |
|
| 2403 | + $sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."facture WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity; |
|
| 2404 | + } |
|
| 2405 | + // Wrapping for mass actions |
|
| 2406 | + else if ($modulepart == 'massfilesarea_proposals' && !empty($conf->propal->multidir_output[$entity])) |
|
| 2407 | + { |
|
| 2408 | + if ($fuser->rights->propal->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2409 | + { |
|
| 2410 | + $accessallowed=1; |
|
| 2411 | + } |
|
| 2412 | + $original_file=$conf->propal->multidir_output[$entity].'/temp/massgeneration/'.$user->id.'/'.$original_file; |
|
| 2413 | + } |
|
| 2414 | + else if ($modulepart == 'massfilesarea_orders') |
|
| 2415 | + { |
|
| 2416 | + if ($fuser->rights->commande->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2417 | + { |
|
| 2418 | + $accessallowed=1; |
|
| 2419 | + } |
|
| 2420 | + $original_file=$conf->commande->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; |
|
| 2421 | + } |
|
| 2422 | + else if ($modulepart == 'massfilesarea_invoices') |
|
| 2423 | + { |
|
| 2424 | + if ($fuser->rights->facture->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2425 | + { |
|
| 2426 | + $accessallowed=1; |
|
| 2427 | + } |
|
| 2428 | + $original_file=$conf->facture->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; |
|
| 2429 | + } |
|
| 2430 | + else if ($modulepart == 'massfilesarea_expensereport') |
|
| 2431 | + { |
|
| 2432 | + if ($fuser->rights->facture->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2433 | + { |
|
| 2434 | + $accessallowed=1; |
|
| 2435 | + } |
|
| 2436 | + $original_file=$conf->expensereport->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; |
|
| 2437 | + } |
|
| 2438 | + else if ($modulepart == 'massfilesarea_interventions') |
|
| 2439 | + { |
|
| 2440 | + if ($fuser->rights->ficheinter->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2441 | + { |
|
| 2442 | + $accessallowed=1; |
|
| 2443 | + } |
|
| 2444 | + $original_file=$conf->ficheinter->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; |
|
| 2445 | + } |
|
| 2446 | + else if ($modulepart == 'massfilesarea_supplier_proposal' && !empty($conf->supplier_proposal->dir_output)) |
|
| 2447 | + { |
|
| 2448 | + if ($fuser->rights->supplier_proposal->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2449 | + { |
|
| 2450 | + $accessallowed=1; |
|
| 2451 | + } |
|
| 2452 | + $original_file=$conf->supplier_proposal->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; |
|
| 2453 | + } |
|
| 2454 | + else if ($modulepart == 'massfilesarea_supplier_order') |
|
| 2455 | + { |
|
| 2456 | + if ($fuser->rights->fournisseur->commande->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2457 | + { |
|
| 2458 | + $accessallowed=1; |
|
| 2459 | + } |
|
| 2460 | + $original_file=$conf->fournisseur->commande->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; |
|
| 2461 | + } |
|
| 2462 | + else if ($modulepart == 'massfilesarea_supplier_invoice') |
|
| 2463 | + { |
|
| 2464 | + if ($fuser->rights->fournisseur->facture->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2465 | + { |
|
| 2466 | + $accessallowed=1; |
|
| 2467 | + } |
|
| 2468 | + $original_file=$conf->fournisseur->facture->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; |
|
| 2469 | + } |
|
| 2470 | + else if ($modulepart == 'massfilesarea_contract' && !empty($conf->contrat->dir_output)) |
|
| 2471 | + { |
|
| 2472 | + if ($fuser->rights->contrat->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2473 | + { |
|
| 2474 | + $accessallowed=1; |
|
| 2475 | + } |
|
| 2476 | + $original_file=$conf->contrat->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; |
|
| 2477 | + } |
|
| 2478 | + |
|
| 2479 | + // Wrapping for interventions |
|
| 2480 | + else if (($modulepart == 'fichinter' || $modulepart == 'ficheinter') && !empty($conf->ficheinter->dir_output)) |
|
| 2481 | + { |
|
| 2482 | + if ($fuser->rights->ficheinter->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2483 | + { |
|
| 2484 | + $accessallowed=1; |
|
| 2485 | + } |
|
| 2486 | + $original_file=$conf->ficheinter->dir_output.'/'.$original_file; |
|
| 2487 | + $sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."fichinter WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity; |
|
| 2488 | + } |
|
| 2489 | + |
|
| 2490 | + // Wrapping pour les deplacements et notes de frais |
|
| 2491 | + else if ($modulepart == 'deplacement' && !empty($conf->deplacement->dir_output)) |
|
| 2492 | + { |
|
| 2493 | + if ($fuser->rights->deplacement->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2494 | + { |
|
| 2495 | + $accessallowed=1; |
|
| 2496 | + } |
|
| 2497 | + $original_file=$conf->deplacement->dir_output.'/'.$original_file; |
|
| 2498 | + //$sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."fichinter WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity; |
|
| 2499 | + } |
|
| 2500 | + // Wrapping pour les propales |
|
| 2501 | + else if (($modulepart == 'propal' || $modulepart == 'propale') && !empty($conf->propal->multidir_output[$entity])) |
|
| 2502 | + { |
|
| 2503 | + if ($fuser->rights->propale->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2504 | + { |
|
| 2505 | + $accessallowed=1; |
|
| 2506 | + } |
|
| 2507 | + $original_file=$conf->propal->multidir_output[$entity].'/'.$original_file; |
|
| 2508 | + $sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."propal WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity; |
|
| 2509 | + } |
|
| 2510 | + |
|
| 2511 | + // Wrapping pour les commandes |
|
| 2512 | + else if (($modulepart == 'commande' || $modulepart == 'order') && !empty($conf->commande->dir_output)) |
|
| 2513 | + { |
|
| 2514 | + if ($fuser->rights->commande->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2515 | + { |
|
| 2516 | + $accessallowed=1; |
|
| 2517 | + } |
|
| 2518 | + $original_file=$conf->commande->dir_output.'/'.$original_file; |
|
| 2519 | + $sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."commande WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity; |
|
| 2520 | + } |
|
| 2521 | + |
|
| 2522 | + // Wrapping pour les projets |
|
| 2523 | + else if ($modulepart == 'project' && !empty($conf->projet->dir_output)) |
|
| 2524 | + { |
|
| 2525 | + if ($fuser->rights->projet->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2526 | + { |
|
| 2527 | + $accessallowed=1; |
|
| 2528 | + } |
|
| 2529 | + $original_file=$conf->projet->dir_output.'/'.$original_file; |
|
| 2530 | + $sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."projet WHERE ref='".$db->escape($refname)."' AND entity IN (".getEntity('project').")"; |
|
| 2531 | + } |
|
| 2532 | + else if ($modulepart == 'project_task' && !empty($conf->projet->dir_output)) |
|
| 2533 | + { |
|
| 2534 | + if ($fuser->rights->projet->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2535 | + { |
|
| 2536 | + $accessallowed=1; |
|
| 2537 | + } |
|
| 2538 | + $original_file=$conf->projet->dir_output.'/'.$original_file; |
|
| 2539 | + $sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."projet WHERE ref='".$db->escape($refname)."' AND entity IN (".getEntity('project').")"; |
|
| 2540 | + } |
|
| 2541 | + |
|
| 2542 | + // Wrapping pour les commandes fournisseurs |
|
| 2543 | + else if (($modulepart == 'commande_fournisseur' || $modulepart == 'order_supplier') && !empty($conf->fournisseur->commande->dir_output)) |
|
| 2544 | + { |
|
| 2545 | + if ($fuser->rights->fournisseur->commande->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2546 | + { |
|
| 2547 | + $accessallowed=1; |
|
| 2548 | + } |
|
| 2549 | + $original_file=$conf->fournisseur->commande->dir_output.'/'.$original_file; |
|
| 2550 | + $sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."commande_fournisseur WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity; |
|
| 2551 | + } |
|
| 2552 | + |
|
| 2553 | + // Wrapping pour les factures fournisseurs |
|
| 2554 | + else if (($modulepart == 'facture_fournisseur' || $modulepart == 'invoice_supplier') && !empty($conf->fournisseur->facture->dir_output)) |
|
| 2555 | + { |
|
| 2556 | + if ($fuser->rights->fournisseur->facture->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2557 | + { |
|
| 2558 | + $accessallowed=1; |
|
| 2559 | + } |
|
| 2560 | + $original_file=$conf->fournisseur->facture->dir_output.'/'.$original_file; |
|
| 2561 | + $sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."facture_fourn WHERE facnumber='".$db->escape($refname)."' AND entity=".$conf->entity; |
|
| 2562 | + } |
|
| 2563 | + // Wrapping pour les rapport de paiements |
|
| 2564 | + else if ($modulepart == 'supplier_payment') |
|
| 2565 | + { |
|
| 2566 | + if ($fuser->rights->fournisseur->facture->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2567 | + { |
|
| 2568 | + $accessallowed=1; |
|
| 2569 | + } |
|
| 2570 | + $original_file=$conf->fournisseur->payment->dir_output.'/'.$original_file; |
|
| 2571 | + $sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."paiementfournisseur WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity; |
|
| 2572 | + } |
|
| 2573 | + |
|
| 2574 | + // Wrapping pour les rapport de paiements |
|
| 2575 | + else if ($modulepart == 'facture_paiement' && !empty($conf->facture->dir_output)) |
|
| 2576 | + { |
|
| 2577 | + if ($fuser->rights->facture->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2578 | + { |
|
| 2579 | + $accessallowed=1; |
|
| 2580 | + } |
|
| 2581 | + if ($fuser->societe_id > 0) $original_file=$conf->facture->dir_output.'/payments/private/'.$fuser->id.'/'.$original_file; |
|
| 2582 | + else $original_file=$conf->facture->dir_output.'/payments/'.$original_file; |
|
| 2583 | + } |
|
| 2584 | + |
|
| 2585 | + // Wrapping for accounting exports |
|
| 2586 | + else if ($modulepart == 'export_compta' && !empty($conf->accounting->dir_output)) |
|
| 2587 | + { |
|
| 2588 | + if ($fuser->rights->accounting->bind->write || preg_match('/^specimen/i',$original_file)) |
|
| 2589 | + { |
|
| 2590 | + $accessallowed=1; |
|
| 2591 | + } |
|
| 2592 | + $original_file=$conf->accounting->dir_output.'/'.$original_file; |
|
| 2593 | + } |
|
| 2594 | + |
|
| 2595 | + // Wrapping pour les expedition |
|
| 2596 | + else if ($modulepart == 'expedition' && !empty($conf->expedition->dir_output)) |
|
| 2597 | + { |
|
| 2598 | + if ($fuser->rights->expedition->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2599 | + { |
|
| 2600 | + $accessallowed=1; |
|
| 2601 | + } |
|
| 2602 | + $original_file=$conf->expedition->dir_output."/sending/".$original_file; |
|
| 2603 | + } |
|
| 2604 | + // Wrapping pour les bons de livraison |
|
| 2605 | + else if ($modulepart == 'livraison' && !empty($conf->expedition->dir_output)) |
|
| 2606 | + { |
|
| 2607 | + if ($fuser->rights->expedition->livraison->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2608 | + { |
|
| 2609 | + $accessallowed=1; |
|
| 2610 | + } |
|
| 2611 | + $original_file=$conf->expedition->dir_output."/receipt/".$original_file; |
|
| 2612 | + } |
|
| 2613 | + |
|
| 2614 | + // Wrapping pour les actions |
|
| 2615 | + else if ($modulepart == 'actions' && !empty($conf->agenda->dir_output)) |
|
| 2616 | + { |
|
| 2617 | + if ($fuser->rights->agenda->myactions->{$read} || preg_match('/^specimen/i',$original_file)) |
|
| 2618 | + { |
|
| 2619 | + $accessallowed=1; |
|
| 2620 | + } |
|
| 2621 | + $original_file=$conf->agenda->dir_output.'/'.$original_file; |
|
| 2622 | + } |
|
| 2623 | + |
|
| 2624 | + // Wrapping pour les actions |
|
| 2625 | + else if ($modulepart == 'actionsreport' && !empty($conf->agenda->dir_temp)) |
|
| 2626 | + { |
|
| 2627 | + if ($fuser->rights->agenda->allactions->{$read} || preg_match('/^specimen/i',$original_file)) |
|
| 2628 | + { |
|
| 2629 | + $accessallowed=1; |
|
| 2630 | + } |
|
| 2631 | + $original_file = $conf->agenda->dir_temp."/".$original_file; |
|
| 2632 | + } |
|
| 2633 | + |
|
| 2634 | + // Wrapping pour les produits et services |
|
| 2635 | + else if ($modulepart == 'product' || $modulepart == 'produit' || $modulepart == 'service' || $modulepart == 'produit|service') |
|
| 2636 | + { |
|
| 2637 | + if (empty($entity) || (empty($conf->product->multidir_output[$entity]) && empty($conf->service->multidir_output[$entity]))) return array('accessallowed'=>0, 'error'=>'Value entity must be provided'); |
|
| 2638 | + if (($fuser->rights->produit->{$lire} || $fuser->rights->service->{$lire}) || preg_match('/^specimen/i',$original_file)) |
|
| 2639 | + { |
|
| 2640 | + $accessallowed=1; |
|
| 2641 | + } |
|
| 2642 | + if (! empty($conf->product->enabled)) $original_file=$conf->product->multidir_output[$entity].'/'.$original_file; |
|
| 2643 | + elseif (! empty($conf->service->enabled)) $original_file=$conf->service->multidir_output[$entity].'/'.$original_file; |
|
| 2644 | + } |
|
| 2645 | + |
|
| 2646 | + // Wrapping pour les lots produits |
|
| 2647 | + else if ($modulepart == 'product_batch' || $modulepart == 'produitlot') |
|
| 2648 | + { |
|
| 2649 | + if (empty($entity) || (empty($conf->productbatch->multidir_output[$entity]))) return array('accessallowed'=>0, 'error'=>'Value entity must be provided'); |
|
| 2650 | + if (($fuser->rights->produit->{$lire} ) || preg_match('/^specimen/i',$original_file)) |
|
| 2651 | + { |
|
| 2652 | + $accessallowed=1; |
|
| 2653 | + } |
|
| 2654 | + if (! empty($conf->productbatch->enabled)) $original_file=$conf->productbatch->multidir_output[$entity].'/'.$original_file; |
|
| 2655 | + } |
|
| 2656 | + |
|
| 2657 | + // Wrapping pour les contrats |
|
| 2658 | + else if ($modulepart == 'contract' && !empty($conf->contrat->dir_output)) |
|
| 2659 | + { |
|
| 2660 | + if ($fuser->rights->contrat->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2661 | + { |
|
| 2662 | + $accessallowed=1; |
|
| 2663 | + } |
|
| 2664 | + $original_file=$conf->contrat->dir_output.'/'.$original_file; |
|
| 2665 | + $sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."contrat WHERE ref='".$db->escape($refname)."' AND entity IN (".getEntity('contract').")"; |
|
| 2666 | + } |
|
| 2667 | + |
|
| 2668 | + // Wrapping pour les dons |
|
| 2669 | + else if ($modulepart == 'donation' && !empty($conf->don->dir_output)) |
|
| 2670 | + { |
|
| 2671 | + if ($fuser->rights->don->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2672 | + { |
|
| 2673 | + $accessallowed=1; |
|
| 2674 | + } |
|
| 2675 | + $original_file=$conf->don->dir_output.'/'.$original_file; |
|
| 2676 | + } |
|
| 2677 | + |
|
| 2678 | + // Wrapping pour les dons |
|
| 2679 | + else if ($modulepart == 'dolresource' && !empty($conf->resource->dir_output)) |
|
| 2680 | + { |
|
| 2681 | + if ($fuser->rights->resource->{$read} || preg_match('/^specimen/i',$original_file)) |
|
| 2682 | + { |
|
| 2683 | + $accessallowed=1; |
|
| 2684 | + } |
|
| 2685 | + $original_file=$conf->resource->dir_output.'/'.$original_file; |
|
| 2686 | + } |
|
| 2687 | + |
|
| 2688 | + // Wrapping pour les remises de cheques |
|
| 2689 | + else if ($modulepart == 'remisecheque' && !empty($conf->banque->dir_output)) |
|
| 2690 | + { |
|
| 2691 | + if ($fuser->rights->banque->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2692 | + { |
|
| 2693 | + $accessallowed=1; |
|
| 2694 | + } |
|
| 2695 | + |
|
| 2696 | + $original_file=$conf->bank->dir_output.'/checkdeposits/'.$original_file; // original_file should contains relative path so include the get_exdir result |
|
| 2697 | + } |
|
| 2698 | + |
|
| 2699 | + // Wrapping for bank |
|
| 2700 | + else if ($modulepart == 'bank' && !empty($conf->bank->dir_output)) |
|
| 2701 | + { |
|
| 2702 | + if ($fuser->rights->banque->{$lire}) |
|
| 2703 | + { |
|
| 2704 | + $accessallowed=1; |
|
| 2705 | + } |
|
| 2706 | + $original_file=$conf->bank->dir_output.'/'.$original_file; |
|
| 2707 | + } |
|
| 2708 | + |
|
| 2709 | + // Wrapping for export module |
|
| 2710 | + else if ($modulepart == 'export' && !empty($conf->export->dir_temp)) |
|
| 2711 | + { |
|
| 2712 | + // Aucun test necessaire car on force le rep de download sur |
|
| 2713 | + // le rep export qui est propre a l'utilisateur |
|
| 2714 | + $accessallowed=1; |
|
| 2715 | + $original_file=$conf->export->dir_temp.'/'.$fuser->id.'/'.$original_file; |
|
| 2716 | + } |
|
| 2717 | + |
|
| 2718 | + // Wrapping for import module |
|
| 2719 | + else if ($modulepart == 'import' && !empty($conf->import->dir_temp)) |
|
| 2720 | + { |
|
| 2721 | + $accessallowed=1; |
|
| 2722 | + $original_file=$conf->import->dir_temp.'/'.$original_file; |
|
| 2723 | + } |
|
| 2724 | + |
|
| 2725 | + // Wrapping pour l'editeur wysiwyg |
|
| 2726 | + else if ($modulepart == 'editor' && !empty($conf->fckeditor->dir_output)) |
|
| 2727 | + { |
|
| 2728 | + $accessallowed=1; |
|
| 2729 | + $original_file=$conf->fckeditor->dir_output.'/'.$original_file; |
|
| 2730 | + } |
|
| 2731 | + |
|
| 2732 | + // Wrapping for backups |
|
| 2733 | + else if ($modulepart == 'systemtools' && !empty($conf->admin->dir_output)) |
|
| 2734 | + { |
|
| 2735 | + if ($fuser->admin) $accessallowed=1; |
|
| 2736 | + $original_file=$conf->admin->dir_output.'/'.$original_file; |
|
| 2737 | + } |
|
| 2738 | + |
|
| 2739 | + // Wrapping for upload file test |
|
| 2740 | + else if ($modulepart == 'admin_temp' && !empty($conf->admin->dir_temp)) |
|
| 2741 | + { |
|
| 2742 | + if ($fuser->admin) $accessallowed=1; |
|
| 2743 | + $original_file=$conf->admin->dir_temp.'/'.$original_file; |
|
| 2744 | + } |
|
| 2745 | + |
|
| 2746 | + // Wrapping pour BitTorrent |
|
| 2747 | + else if ($modulepart == 'bittorrent' && !empty($conf->bittorrent->dir_output)) |
|
| 2748 | + { |
|
| 2749 | + $accessallowed=1; |
|
| 2750 | + $dir='files'; |
|
| 2751 | + if (dol_mimetype($original_file) == 'application/x-bittorrent') $dir='torrents'; |
|
| 2752 | + $original_file=$conf->bittorrent->dir_output.'/'.$dir.'/'.$original_file; |
|
| 2753 | + } |
|
| 2754 | + |
|
| 2755 | + // Wrapping pour Foundation module |
|
| 2756 | + else if ($modulepart == 'member' && !empty($conf->adherent->dir_output)) |
|
| 2757 | + { |
|
| 2758 | + if ($fuser->rights->adherent->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2759 | + { |
|
| 2760 | + $accessallowed=1; |
|
| 2761 | + } |
|
| 2762 | + $original_file=$conf->adherent->dir_output.'/'.$original_file; |
|
| 2763 | + } |
|
| 2764 | + |
|
| 2765 | + // Wrapping for Scanner |
|
| 2766 | + else if ($modulepart == 'scanner_user_temp' && !empty($conf->scanner->dir_temp)) |
|
| 2767 | + { |
|
| 2768 | + $accessallowed=1; |
|
| 2769 | + $original_file=$conf->scanner->dir_temp.'/'.$fuser->id.'/'.$original_file; |
|
| 2770 | + } |
|
| 2771 | + |
|
| 2772 | + // GENERIC Wrapping |
|
| 2773 | + // If modulepart=module_user_temp Allows any module to open a file if file is in directory called DOL_DATA_ROOT/modulepart/temp/iduser |
|
| 2774 | + // If modulepart=module_temp Allows any module to open a file if file is in directory called DOL_DATA_ROOT/modulepart/temp |
|
| 2775 | + // If modulepart=module_user Allows any module to open a file if file is in directory called DOL_DATA_ROOT/modulepart/iduser |
|
| 2776 | + // If modulepart=module Allows any module to open a file if file is in directory called DOL_DATA_ROOT/modulepart |
|
| 2777 | + else |
|
| 2778 | + { |
|
| 2779 | + if (preg_match('/^specimen/i',$original_file)) $accessallowed=1; // If link to a file called specimen. Test must be done before changing $original_file int full path. |
|
| 2780 | + if ($fuser->admin) $accessallowed=1; // If user is admin |
|
| 2781 | + |
|
| 2782 | + // Define $accessallowed |
|
| 2783 | + if (preg_match('/^([a-z]+)_user_temp$/i',$modulepart,$reg)) |
|
| 2784 | + { |
|
| 2785 | + if (empty($conf->{$reg[1]}->dir_temp)) // modulepart not supported |
|
| 2786 | + { |
|
| 2787 | + dol_print_error('','Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')'); |
|
| 2788 | + exit; |
|
| 2789 | + } |
|
| 2790 | + if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) $accessallowed=1; |
|
| 2791 | + $original_file=$conf->{$reg[1]}->dir_temp.'/'.$fuser->id.'/'.$original_file; |
|
| 2792 | + } |
|
| 2793 | + else if (preg_match('/^([a-z]+)_temp$/i',$modulepart,$reg)) |
|
| 2794 | + { |
|
| 2795 | + if (empty($conf->{$reg[1]}->dir_temp)) // modulepart not supported |
|
| 2796 | + { |
|
| 2797 | + dol_print_error('','Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')'); |
|
| 2798 | + exit; |
|
| 2799 | + } |
|
| 2800 | + if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) $accessallowed=1; |
|
| 2801 | + $original_file=$conf->{$reg[1]}->dir_temp.'/'.$original_file; |
|
| 2802 | + } |
|
| 2803 | + else if (preg_match('/^([a-z]+)_user$/i',$modulepart,$reg)) |
|
| 2804 | + { |
|
| 2805 | + if (empty($conf->{$reg[1]}->dir_output)) // modulepart not supported |
|
| 2806 | + { |
|
| 2807 | + dol_print_error('','Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')'); |
|
| 2808 | + exit; |
|
| 2809 | + } |
|
| 2810 | + if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) $accessallowed=1; |
|
| 2811 | + $original_file=$conf->{$reg[1]}->dir_output.'/'.$fuser->id.'/'.$original_file; |
|
| 2812 | + } |
|
| 2813 | + else if (preg_match('/^massfilesarea_([a-z]+)$/i', $modulepart, $reg)) |
|
| 2814 | + { |
|
| 2815 | + if (empty($conf->{$reg[1]}->dir_output)) // modulepart not supported |
|
| 2816 | + { |
|
| 2817 | + dol_print_error('','Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')'); |
|
| 2818 | + exit; |
|
| 2819 | + } |
|
| 2820 | + if ($fuser->rights->{$reg[1]}->{$lire} || preg_match('/^specimen/i', $original_file)) |
|
| 2821 | + { |
|
| 2822 | + $accessallowed=1; |
|
| 2823 | + } |
|
| 2824 | + $original_file=$conf->{$reg[1]}->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; |
|
| 2825 | + } |
|
| 2826 | + else |
|
| 2827 | + { |
|
| 2828 | + if (empty($conf->$modulepart->dir_output)) // modulepart not supported |
|
| 2829 | + { |
|
| 2830 | + dol_print_error('','Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')'); |
|
| 2831 | + exit; |
|
| 2832 | + } |
|
| 2833 | + |
|
| 2834 | + $perm=GETPOST('perm'); |
|
| 2835 | + $subperm=GETPOST('subperm'); |
|
| 2836 | + if ($perm || $subperm) |
|
| 2837 | + { |
|
| 2838 | + if (($perm && ! $subperm && $fuser->rights->$modulepart->$perm) || ($perm && $subperm && $fuser->rights->$modulepart->$perm->$subperm)) $accessallowed=1; |
|
| 2839 | + $original_file=$conf->$modulepart->dir_output.'/'.$original_file; |
|
| 2840 | + } |
|
| 2841 | + else |
|
| 2842 | + { |
|
| 2843 | + if ($fuser->rights->$modulepart->{$lire} || $fuser->rights->$modulepart->{$read}) $accessallowed=1; |
|
| 2844 | + $original_file=$conf->$modulepart->dir_output.'/'.$original_file; |
|
| 2845 | + } |
|
| 2846 | + } |
|
| 2847 | + |
|
| 2848 | + // For modules who wants to manage different levels of permissions for documents |
|
| 2849 | + $subPermCategoryConstName = strtoupper($modulepart).'_SUBPERMCATEGORY_FOR_DOCUMENTS'; |
|
| 2850 | + if (! empty($conf->global->$subPermCategoryConstName)) |
|
| 2851 | + { |
|
| 2852 | + $subPermCategory = $conf->global->$subPermCategoryConstName; |
|
| 2853 | + if (! empty($subPermCategory) && (($fuser->rights->$modulepart->$subPermCategory->{$lire}) || ($fuser->rights->$modulepart->$subPermCategory->{$read}) || ($fuser->rights->$modulepart->$subPermCategory->{$download}))) |
|
| 2854 | + { |
|
| 2855 | + $accessallowed=1; |
|
| 2856 | + } |
|
| 2857 | + } |
|
| 2858 | + |
|
| 2859 | + // Define $sqlprotectagainstexternals for modules who want to protect access using a SQL query. |
|
| 2860 | + $sqlProtectConstName = strtoupper($modulepart).'_SQLPROTECTAGAINSTEXTERNALS_FOR_DOCUMENTS'; |
|
| 2861 | + if (! empty($conf->global->$sqlProtectConstName)) // If module want to define its own $sqlprotectagainstexternals |
|
| 2862 | + { |
|
| 2863 | + // Example: mymodule__SQLPROTECTAGAINSTEXTERNALS_FOR_DOCUMENTS = "SELECT fk_soc FROM ".MAIN_DB_PREFIX.$modulepart." WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity; |
|
| 2864 | + eval('$sqlprotectagainstexternals = "'.$conf->global->$sqlProtectConstName.'";'); |
|
| 2865 | + } |
|
| 2866 | + } |
|
| 2867 | + |
|
| 2868 | + $ret = array( |
|
| 2869 | + 'accessallowed' => $accessallowed, |
|
| 2870 | + 'sqlprotectagainstexternals'=>$sqlprotectagainstexternals, |
|
| 2871 | + 'original_file'=>$original_file |
|
| 2872 | + ); |
|
| 2873 | + |
|
| 2874 | + return $ret; |
|
| 2875 | 2875 | } |
| 2876 | 2876 | |
| 2877 | 2877 | /** |
@@ -2884,10 +2884,10 @@ discard block |
||
| 2884 | 2884 | */ |
| 2885 | 2885 | function dol_filecache($directory, $filename, $object) |
| 2886 | 2886 | { |
| 2887 | - if (! dol_is_dir($directory)) dol_mkdir($directory); |
|
| 2888 | - $cachefile = $directory . $filename; |
|
| 2889 | - file_put_contents($cachefile, serialize($object), LOCK_EX); |
|
| 2890 | - @chmod($cachefile, 0644); |
|
| 2887 | + if (! dol_is_dir($directory)) dol_mkdir($directory); |
|
| 2888 | + $cachefile = $directory . $filename; |
|
| 2889 | + file_put_contents($cachefile, serialize($object), LOCK_EX); |
|
| 2890 | + @chmod($cachefile, 0644); |
|
| 2891 | 2891 | } |
| 2892 | 2892 | |
| 2893 | 2893 | /** |
@@ -2900,10 +2900,10 @@ discard block |
||
| 2900 | 2900 | */ |
| 2901 | 2901 | function dol_cache_refresh($directory, $filename, $cachetime) |
| 2902 | 2902 | { |
| 2903 | - $now = dol_now(); |
|
| 2904 | - $cachefile = $directory . $filename; |
|
| 2905 | - $refresh = !file_exists($cachefile) || ($now-$cachetime) > dol_filemtime($cachefile); |
|
| 2906 | - return $refresh; |
|
| 2903 | + $now = dol_now(); |
|
| 2904 | + $cachefile = $directory . $filename; |
|
| 2905 | + $refresh = !file_exists($cachefile) || ($now-$cachetime) > dol_filemtime($cachefile); |
|
| 2906 | + return $refresh; |
|
| 2907 | 2907 | } |
| 2908 | 2908 | |
| 2909 | 2909 | /** |
@@ -2915,9 +2915,9 @@ discard block |
||
| 2915 | 2915 | */ |
| 2916 | 2916 | function dol_readcachefile($directory, $filename) |
| 2917 | 2917 | { |
| 2918 | - $cachefile = $directory . $filename; |
|
| 2919 | - $object = unserialize(file_get_contents($cachefile)); |
|
| 2920 | - return $object; |
|
| 2918 | + $cachefile = $directory . $filename; |
|
| 2919 | + $object = unserialize(file_get_contents($cachefile)); |
|
| 2920 | + return $object; |
|
| 2921 | 2921 | } |
| 2922 | 2922 | |
| 2923 | 2923 | |
@@ -2934,43 +2934,43 @@ discard block |
||
| 2934 | 2934 | */ |
| 2935 | 2935 | function getFilesUpdated(&$file_list, SimpleXMLElement $dir, $path = '', $pathref = '', &$checksumconcat = array()) |
| 2936 | 2936 | { |
| 2937 | - global $conffile; |
|
| 2938 | - |
|
| 2939 | - $exclude = 'install'; |
|
| 2940 | - |
|
| 2941 | - foreach ($dir->md5file as $file) // $file is a simpleXMLElement |
|
| 2942 | - { |
|
| 2943 | - $filename = $path.$file['name']; |
|
| 2944 | - $file_list['insignature'][] = $filename; |
|
| 2945 | - $expectedmd5 = (string) $file; |
|
| 2946 | - |
|
| 2947 | - //if (preg_match('#'.$exclude.'#', $filename)) continue; |
|
| 2948 | - |
|
| 2949 | - if (!file_exists($pathref.'/'.$filename)) |
|
| 2950 | - { |
|
| 2951 | - $file_list['missing'][] = array('filename'=>$filename, 'expectedmd5'=>$expectedmd5); |
|
| 2952 | - } |
|
| 2953 | - else |
|
| 2954 | - { |
|
| 2955 | - $md5_local = md5_file($pathref.'/'.$filename); |
|
| 2956 | - |
|
| 2957 | - if ($conffile == '/etc/dolibarr/conf.php' && $filename == '/filefunc.inc.php') // For install with deb or rpm, we ignore test on filefunc.inc.php that was modified by package |
|
| 2958 | - { |
|
| 2959 | - $checksumconcat[] = $expectedmd5; |
|
| 2960 | - } |
|
| 2961 | - else |
|
| 2962 | - { |
|
| 2963 | - if ($md5_local != $expectedmd5) $file_list['updated'][] = array('filename'=>$filename, 'expectedmd5'=>$expectedmd5, 'md5'=>(string) $md5_local); |
|
| 2964 | - $checksumconcat[] = $md5_local; |
|
| 2965 | - } |
|
| 2966 | - } |
|
| 2967 | - } |
|
| 2968 | - |
|
| 2969 | - foreach ($dir->dir as $subdir) // $subdir['name'] is '' or '/accountancy/admin' for example |
|
| 2970 | - { |
|
| 2971 | - getFilesUpdated($file_list, $subdir, $path.$subdir['name'].'/', $pathref, $checksumconcat); |
|
| 2972 | - } |
|
| 2973 | - |
|
| 2974 | - return $file_list; |
|
| 2937 | + global $conffile; |
|
| 2938 | + |
|
| 2939 | + $exclude = 'install'; |
|
| 2940 | + |
|
| 2941 | + foreach ($dir->md5file as $file) // $file is a simpleXMLElement |
|
| 2942 | + { |
|
| 2943 | + $filename = $path.$file['name']; |
|
| 2944 | + $file_list['insignature'][] = $filename; |
|
| 2945 | + $expectedmd5 = (string) $file; |
|
| 2946 | + |
|
| 2947 | + //if (preg_match('#'.$exclude.'#', $filename)) continue; |
|
| 2948 | + |
|
| 2949 | + if (!file_exists($pathref.'/'.$filename)) |
|
| 2950 | + { |
|
| 2951 | + $file_list['missing'][] = array('filename'=>$filename, 'expectedmd5'=>$expectedmd5); |
|
| 2952 | + } |
|
| 2953 | + else |
|
| 2954 | + { |
|
| 2955 | + $md5_local = md5_file($pathref.'/'.$filename); |
|
| 2956 | + |
|
| 2957 | + if ($conffile == '/etc/dolibarr/conf.php' && $filename == '/filefunc.inc.php') // For install with deb or rpm, we ignore test on filefunc.inc.php that was modified by package |
|
| 2958 | + { |
|
| 2959 | + $checksumconcat[] = $expectedmd5; |
|
| 2960 | + } |
|
| 2961 | + else |
|
| 2962 | + { |
|
| 2963 | + if ($md5_local != $expectedmd5) $file_list['updated'][] = array('filename'=>$filename, 'expectedmd5'=>$expectedmd5, 'md5'=>(string) $md5_local); |
|
| 2964 | + $checksumconcat[] = $md5_local; |
|
| 2965 | + } |
|
| 2966 | + } |
|
| 2967 | + } |
|
| 2968 | + |
|
| 2969 | + foreach ($dir->dir as $subdir) // $subdir['name'] is '' or '/accountancy/admin' for example |
|
| 2970 | + { |
|
| 2971 | + getFilesUpdated($file_list, $subdir, $path.$subdir['name'].'/', $pathref, $checksumconcat); |
|
| 2972 | + } |
|
| 2973 | + |
|
| 2974 | + return $file_list; |
|
| 2975 | 2975 | } |
| 2976 | 2976 | |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | function dol_basename($pathfile) |
| 36 | 36 | { |
| 37 | - return preg_replace('/^.*\/([^\/]+)$/','$1',rtrim($pathfile,'/')); |
|
| 37 | + return preg_replace('/^.*\/([^\/]+)$/', '$1', rtrim($pathfile, '/')); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /** |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | * @return array Array of array('name'=>'xxx','fullname'=>'/abc/xxx','date'=>'yyy','size'=>99,'type'=>'dir|file',...) |
| 57 | 57 | * @see dol_dir_list_indatabase |
| 58 | 58 | */ |
| 59 | -function dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0) |
|
| 59 | +function dol_dir_list($path, $types = "all", $recursive = 0, $filter = "", $excludefilter = null, $sortcriteria = "name", $sortorder = SORT_ASC, $mode = 0, $nohook = 0, $relativename = "", $donotfollowsymlinks = 0) |
|
| 60 | 60 | { |
| 61 | 61 | global $db, $hookmanager; |
| 62 | 62 | global $object; |
@@ -64,23 +64,23 @@ discard block |
||
| 64 | 64 | dol_syslog("files.lib.php::dol_dir_list path=".$path." types=".$types." recursive=".$recursive." filter=".$filter." excludefilter=".json_encode($excludefilter)); |
| 65 | 65 | //print 'xxx'."files.lib.php::dol_dir_list path=".$path." types=".$types." recursive=".$recursive." filter=".$filter." excludefilter=".json_encode($excludefilter); |
| 66 | 66 | |
| 67 | - $loaddate=($mode==1||$mode==2)?true:false; |
|
| 68 | - $loadsize=($mode==1||$mode==3)?true:false; |
|
| 67 | + $loaddate = ($mode == 1 || $mode == 2) ?true:false; |
|
| 68 | + $loadsize = ($mode == 1 || $mode == 3) ?true:false; |
|
| 69 | 69 | |
| 70 | 70 | // Clean parameters |
| 71 | - $path=preg_replace('/([\\/]+)$/i','',$path); |
|
| 72 | - $newpath=dol_osencode($path); |
|
| 71 | + $path = preg_replace('/([\\/]+)$/i', '', $path); |
|
| 72 | + $newpath = dol_osencode($path); |
|
| 73 | 73 | |
| 74 | 74 | $reshook = 0; |
| 75 | 75 | $file_list = array(); |
| 76 | 76 | |
| 77 | - if (is_object($hookmanager) && ! $nohook) |
|
| 77 | + if (is_object($hookmanager) && !$nohook) |
|
| 78 | 78 | { |
| 79 | - $hookmanager->resArray=array(); |
|
| 79 | + $hookmanager->resArray = array(); |
|
| 80 | 80 | |
| 81 | 81 | $hookmanager->initHooks(array('fileslib')); |
| 82 | 82 | |
| 83 | - $parameters=array( |
|
| 83 | + $parameters = array( |
|
| 84 | 84 | 'path' => $newpath, |
| 85 | 85 | 'types'=> $types, |
| 86 | 86 | 'recursive' => $recursive, |
@@ -92,63 +92,63 @@ discard block |
||
| 92 | 92 | 'loadsize' => $loadsize, |
| 93 | 93 | 'mode' => $mode |
| 94 | 94 | ); |
| 95 | - $reshook=$hookmanager->executeHooks('getDirList', $parameters, $object); |
|
| 95 | + $reshook = $hookmanager->executeHooks('getDirList', $parameters, $object); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | // $hookmanager->resArray may contain array stacked by other modules |
| 99 | 99 | if (empty($reshook)) |
| 100 | 100 | { |
| 101 | - if (! is_dir($newpath)) return array(); |
|
| 101 | + if (!is_dir($newpath)) return array(); |
|
| 102 | 102 | |
| 103 | 103 | if ($dir = opendir($newpath)) |
| 104 | 104 | { |
| 105 | - $filedate=''; |
|
| 106 | - $filesize=''; |
|
| 105 | + $filedate = ''; |
|
| 106 | + $filesize = ''; |
|
| 107 | 107 | |
| 108 | 108 | while (false !== ($file = readdir($dir))) // $file is always a basename (into directory $newpath) |
| 109 | 109 | { |
| 110 | - if (! utf8_check($file)) $file=utf8_encode($file); // To be sure data is stored in utf8 in memory |
|
| 111 | - $fullpathfile=($newpath?$newpath.'/':'').$file; |
|
| 110 | + if (!utf8_check($file)) $file = utf8_encode($file); // To be sure data is stored in utf8 in memory |
|
| 111 | + $fullpathfile = ($newpath ? $newpath.'/' : '').$file; |
|
| 112 | 112 | |
| 113 | - $qualified=1; |
|
| 113 | + $qualified = 1; |
|
| 114 | 114 | |
| 115 | 115 | // Define excludefilterarray |
| 116 | - $excludefilterarray=array('^\.'); |
|
| 116 | + $excludefilterarray = array('^\.'); |
|
| 117 | 117 | if (is_array($excludefilter)) |
| 118 | 118 | { |
| 119 | - $excludefilterarray=array_merge($excludefilterarray,$excludefilter); |
|
| 119 | + $excludefilterarray = array_merge($excludefilterarray, $excludefilter); |
|
| 120 | 120 | } |
| 121 | - else if ($excludefilter) $excludefilterarray[]=$excludefilter; |
|
| 121 | + else if ($excludefilter) $excludefilterarray[] = $excludefilter; |
|
| 122 | 122 | // Check if file is qualified |
| 123 | - foreach($excludefilterarray as $filt) |
|
| 123 | + foreach ($excludefilterarray as $filt) |
|
| 124 | 124 | { |
| 125 | 125 | if (preg_match('/'.$filt.'/i', $file) || preg_match('/'.$filt.'/i', $fullpathfile)) { |
| 126 | - $qualified=0; break; |
|
| 126 | + $qualified = 0; break; |
|
| 127 | 127 | } |
| 128 | 128 | } |
| 129 | 129 | //print $fullpathfile.' '.$file.' '.$qualified.'<br>'; |
| 130 | 130 | |
| 131 | 131 | if ($qualified) |
| 132 | 132 | { |
| 133 | - $isdir=is_dir(dol_osencode($path."/".$file)); |
|
| 133 | + $isdir = is_dir(dol_osencode($path."/".$file)); |
|
| 134 | 134 | // Check whether this is a file or directory and whether we're interested in that type |
| 135 | - if ($isdir && (($types=="directories") || ($types=="all") || $recursive)) |
|
| 135 | + if ($isdir && (($types == "directories") || ($types == "all") || $recursive)) |
|
| 136 | 136 | { |
| 137 | 137 | // Add entry into file_list array |
| 138 | - if (($types=="directories") || ($types=="all")) |
|
| 138 | + if (($types == "directories") || ($types == "all")) |
|
| 139 | 139 | { |
| 140 | - if ($loaddate || $sortcriteria == 'date') $filedate=dol_filemtime($path."/".$file); |
|
| 141 | - if ($loadsize || $sortcriteria == 'size') $filesize=dol_filesize($path."/".$file); |
|
| 140 | + if ($loaddate || $sortcriteria == 'date') $filedate = dol_filemtime($path."/".$file); |
|
| 141 | + if ($loadsize || $sortcriteria == 'size') $filesize = dol_filesize($path."/".$file); |
|
| 142 | 142 | |
| 143 | - if (! $filter || preg_match('/'.$filter.'/i',$file)) // We do not search key $filter into all $path, only into $file part |
|
| 143 | + if (!$filter || preg_match('/'.$filter.'/i', $file)) // We do not search key $filter into all $path, only into $file part |
|
| 144 | 144 | { |
| 145 | - preg_match('/([^\/]+)\/[^\/]+$/',$path.'/'.$file,$reg); |
|
| 146 | - $level1name=(isset($reg[1])?$reg[1]:''); |
|
| 145 | + preg_match('/([^\/]+)\/[^\/]+$/', $path.'/'.$file, $reg); |
|
| 146 | + $level1name = (isset($reg[1]) ? $reg[1] : ''); |
|
| 147 | 147 | $file_list[] = array( |
| 148 | 148 | "name" => $file, |
| 149 | 149 | "path" => $path, |
| 150 | 150 | "level1name" => $level1name, |
| 151 | - "relativename" => ($relativename?$relativename.'/':'').$file, |
|
| 151 | + "relativename" => ($relativename ? $relativename.'/' : '').$file, |
|
| 152 | 152 | "fullname" => $path.'/'.$file, |
| 153 | 153 | "date" => $filedate, |
| 154 | 154 | "size" => $filesize, |
@@ -160,28 +160,28 @@ discard block |
||
| 160 | 160 | // if we're in a directory and we want recursive behavior, call this function again |
| 161 | 161 | if ($recursive) |
| 162 | 162 | { |
| 163 | - if (empty($donotfollowsymlinks) || ! is_link($path."/".$file)) |
|
| 163 | + if (empty($donotfollowsymlinks) || !is_link($path."/".$file)) |
|
| 164 | 164 | { |
| 165 | 165 | //var_dump('eee '. $path."/".$file. ' '.is_dir($path."/".$file).' '.is_link($path."/".$file)); |
| 166 | - $file_list = array_merge($file_list, dol_dir_list($path."/".$file, $types, $recursive, $filter, $excludefilter, $sortcriteria, $sortorder, $mode, $nohook, ($relativename!=''?$relativename.'/':'').$file, $donotfollowsymlinks)); |
|
| 166 | + $file_list = array_merge($file_list, dol_dir_list($path."/".$file, $types, $recursive, $filter, $excludefilter, $sortcriteria, $sortorder, $mode, $nohook, ($relativename != '' ? $relativename.'/' : '').$file, $donotfollowsymlinks)); |
|
| 167 | 167 | } |
| 168 | 168 | } |
| 169 | 169 | } |
| 170 | - else if (! $isdir && (($types == "files") || ($types == "all"))) |
|
| 170 | + else if (!$isdir && (($types == "files") || ($types == "all"))) |
|
| 171 | 171 | { |
| 172 | 172 | // Add file into file_list array |
| 173 | - if ($loaddate || $sortcriteria == 'date') $filedate=dol_filemtime($path."/".$file); |
|
| 174 | - if ($loadsize || $sortcriteria == 'size') $filesize=dol_filesize($path."/".$file); |
|
| 173 | + if ($loaddate || $sortcriteria == 'date') $filedate = dol_filemtime($path."/".$file); |
|
| 174 | + if ($loadsize || $sortcriteria == 'size') $filesize = dol_filesize($path."/".$file); |
|
| 175 | 175 | |
| 176 | - if (! $filter || preg_match('/'.$filter.'/i',$file)) // We do not search key $filter into $path, only into $file |
|
| 176 | + if (!$filter || preg_match('/'.$filter.'/i', $file)) // We do not search key $filter into $path, only into $file |
|
| 177 | 177 | { |
| 178 | - preg_match('/([^\/]+)\/[^\/]+$/',$path.'/'.$file,$reg); |
|
| 179 | - $level1name=(isset($reg[1])?$reg[1]:''); |
|
| 178 | + preg_match('/([^\/]+)\/[^\/]+$/', $path.'/'.$file, $reg); |
|
| 179 | + $level1name = (isset($reg[1]) ? $reg[1] : ''); |
|
| 180 | 180 | $file_list[] = array( |
| 181 | 181 | "name" => $file, |
| 182 | 182 | "path" => $path, |
| 183 | 183 | "level1name" => $level1name, |
| 184 | - "relativename" => ($relativename?$relativename.'/':'').$file, |
|
| 184 | + "relativename" => ($relativename ? $relativename.'/' : '').$file, |
|
| 185 | 185 | "fullname" => $path.'/'.$file, |
| 186 | 186 | "date" => $filedate, |
| 187 | 187 | "size" => $filesize, |
@@ -194,12 +194,12 @@ discard block |
||
| 194 | 194 | closedir($dir); |
| 195 | 195 | |
| 196 | 196 | // Obtain a list of columns |
| 197 | - if (! empty($sortcriteria)) |
|
| 197 | + if (!empty($sortcriteria)) |
|
| 198 | 198 | { |
| 199 | - $myarray=array(); |
|
| 199 | + $myarray = array(); |
|
| 200 | 200 | foreach ($file_list as $key => $row) |
| 201 | 201 | { |
| 202 | - $myarray[$key] = (isset($row[$sortcriteria])?$row[$sortcriteria]:''); |
|
| 202 | + $myarray[$key] = (isset($row[$sortcriteria]) ? $row[$sortcriteria] : ''); |
|
| 203 | 203 | } |
| 204 | 204 | // Sort the data |
| 205 | 205 | if ($sortorder) array_multisort($myarray, $sortorder, $file_list); |
@@ -226,21 +226,21 @@ discard block |
||
| 226 | 226 | * @return array Array of array('name'=>'xxx','fullname'=>'/abc/xxx','type'=>'dir|file',...) |
| 227 | 227 | * @see dol_dir_list |
| 228 | 228 | */ |
| 229 | -function dol_dir_list_in_database($path, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0) |
|
| 229 | +function dol_dir_list_in_database($path, $filter = "", $excludefilter = null, $sortcriteria = "name", $sortorder = SORT_ASC, $mode = 0) |
|
| 230 | 230 | { |
| 231 | 231 | global $conf, $db; |
| 232 | 232 | |
| 233 | - $sql =" SELECT rowid, label, entity, filename, filepath, fullpath_orig, keywords, cover, gen_or_uploaded, extraparams, date_c, date_m, fk_user_c, fk_user_m,"; |
|
| 234 | - $sql.=" acl, position, share"; |
|
| 235 | - if ($mode) $sql.=", description"; |
|
| 236 | - $sql.=" FROM ".MAIN_DB_PREFIX."ecm_files"; |
|
| 237 | - $sql.=" WHERE filepath = '".$db->escape($path)."'"; |
|
| 238 | - $sql.=" AND entity = ".$conf->entity; |
|
| 233 | + $sql = " SELECT rowid, label, entity, filename, filepath, fullpath_orig, keywords, cover, gen_or_uploaded, extraparams, date_c, date_m, fk_user_c, fk_user_m,"; |
|
| 234 | + $sql .= " acl, position, share"; |
|
| 235 | + if ($mode) $sql .= ", description"; |
|
| 236 | + $sql .= " FROM ".MAIN_DB_PREFIX."ecm_files"; |
|
| 237 | + $sql .= " WHERE filepath = '".$db->escape($path)."'"; |
|
| 238 | + $sql .= " AND entity = ".$conf->entity; |
|
| 239 | 239 | |
| 240 | 240 | $resql = $db->query($sql); |
| 241 | 241 | if ($resql) |
| 242 | 242 | { |
| 243 | - $file_list=array(); |
|
| 243 | + $file_list = array(); |
|
| 244 | 244 | $num = $db->num_rows($resql); |
| 245 | 245 | $i = 0; |
| 246 | 246 | while ($i < $num) |
@@ -248,11 +248,11 @@ discard block |
||
| 248 | 248 | $obj = $db->fetch_object($resql); |
| 249 | 249 | if ($obj) |
| 250 | 250 | { |
| 251 | - preg_match('/([^\/]+)\/[^\/]+$/',DOL_DATA_ROOT.'/'.$obj->filepath.'/'.$obj->filename,$reg); |
|
| 252 | - $level1name=(isset($reg[1])?$reg[1]:''); |
|
| 251 | + preg_match('/([^\/]+)\/[^\/]+$/', DOL_DATA_ROOT.'/'.$obj->filepath.'/'.$obj->filename, $reg); |
|
| 252 | + $level1name = (isset($reg[1]) ? $reg[1] : ''); |
|
| 253 | 253 | $file_list[] = array( |
| 254 | 254 | "rowid" => $obj->rowid, |
| 255 | - "label" => $obj->label, // md5 |
|
| 255 | + "label" => $obj->label, // md5 |
|
| 256 | 256 | "name" => $obj->filename, |
| 257 | 257 | "path" => DOL_DATA_ROOT.'/'.$obj->filepath, |
| 258 | 258 | "level1name" => $level1name, |
@@ -272,12 +272,12 @@ discard block |
||
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | // Obtain a list of columns |
| 275 | - if (! empty($sortcriteria)) |
|
| 275 | + if (!empty($sortcriteria)) |
|
| 276 | 276 | { |
| 277 | - $myarray=array(); |
|
| 277 | + $myarray = array(); |
|
| 278 | 278 | foreach ($file_list as $key => $row) |
| 279 | 279 | { |
| 280 | - $myarray[$key] = (isset($row[$sortcriteria])?$row[$sortcriteria]:''); |
|
| 280 | + $myarray[$key] = (isset($row[$sortcriteria]) ? $row[$sortcriteria] : ''); |
|
| 281 | 281 | } |
| 282 | 282 | // Sort the data |
| 283 | 283 | if ($sortorder) array_multisort($myarray, $sortorder, $file_list); |
@@ -309,15 +309,15 @@ discard block |
||
| 309 | 309 | |
| 310 | 310 | // TODO Remove this when PRODUCT_USE_OLD_PATH_FOR_PHOTO will be removed |
| 311 | 311 | global $modulepart; |
| 312 | - if ($modulepart == 'produit' && ! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) { |
|
| 312 | + if ($modulepart == 'produit' && !empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) { |
|
| 313 | 313 | global $object; |
| 314 | - if (! empty($object->id)) |
|
| 314 | + if (!empty($object->id)) |
|
| 315 | 315 | { |
| 316 | - if (! empty($conf->product->enabled)) $upload_dirold = $conf->product->multidir_output[$object->entity].'/'.substr(substr("000".$object->id, -2),1,1).'/'.substr(substr("000".$object->id, -2),0,1).'/'.$object->id."/photos"; |
|
| 317 | - else $upload_dirold = $conf->service->multidir_output[$object->entity].'/'.substr(substr("000".$object->id, -2),1,1).'/'.substr(substr("000".$object->id, -2),0,1).'/'.$object->id."/photos"; |
|
| 316 | + if (!empty($conf->product->enabled)) $upload_dirold = $conf->product->multidir_output[$object->entity].'/'.substr(substr("000".$object->id, -2), 1, 1).'/'.substr(substr("000".$object->id, -2), 0, 1).'/'.$object->id."/photos"; |
|
| 317 | + else $upload_dirold = $conf->service->multidir_output[$object->entity].'/'.substr(substr("000".$object->id, -2), 1, 1).'/'.substr(substr("000".$object->id, -2), 0, 1).'/'.$object->id."/photos"; |
|
| 318 | 318 | |
| 319 | - $relativedirold = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $upload_dirold); |
|
| 320 | - $relativedirold = preg_replace('/^[\\/]/','',$relativedirold); |
|
| 319 | + $relativedirold = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $upload_dirold); |
|
| 320 | + $relativedirold = preg_replace('/^[\\/]/', '', $relativedirold); |
|
| 321 | 321 | |
| 322 | 322 | $filearrayindatabase = array_merge($filearrayindatabase, dol_dir_list_in_database($relativedirold, '', null, 'name', SORT_ASC)); |
| 323 | 323 | } |
@@ -327,38 +327,38 @@ discard block |
||
| 327 | 327 | //var_dump($filearrayindatabase); |
| 328 | 328 | |
| 329 | 329 | // Complete filearray with properties found into $filearrayindatabase |
| 330 | - foreach($filearray as $key => $val) |
|
| 330 | + foreach ($filearray as $key => $val) |
|
| 331 | 331 | { |
| 332 | - $found=0; |
|
| 332 | + $found = 0; |
|
| 333 | 333 | // Search if it exists into $filearrayindatabase |
| 334 | - foreach($filearrayindatabase as $key2 => $val2) |
|
| 334 | + foreach ($filearrayindatabase as $key2 => $val2) |
|
| 335 | 335 | { |
| 336 | 336 | if ($filearrayindatabase[$key2]['name'] == $filearray[$key]['name']) |
| 337 | 337 | { |
| 338 | - $filearray[$key]['position_name']=($filearrayindatabase[$key2]['position']?$filearrayindatabase[$key2]['position']:'0').'_'.$filearrayindatabase[$key2]['name']; |
|
| 339 | - $filearray[$key]['position']=$filearrayindatabase[$key2]['position']; |
|
| 340 | - $filearray[$key]['cover']=$filearrayindatabase[$key2]['cover']; |
|
| 341 | - $filearray[$key]['acl']=$filearrayindatabase[$key2]['acl']; |
|
| 342 | - $filearray[$key]['rowid']=$filearrayindatabase[$key2]['rowid']; |
|
| 343 | - $filearray[$key]['label']=$filearrayindatabase[$key2]['label']; |
|
| 344 | - $filearray[$key]['share']=$filearrayindatabase[$key2]['share']; |
|
| 345 | - $found=1; |
|
| 338 | + $filearray[$key]['position_name'] = ($filearrayindatabase[$key2]['position'] ? $filearrayindatabase[$key2]['position'] : '0').'_'.$filearrayindatabase[$key2]['name']; |
|
| 339 | + $filearray[$key]['position'] = $filearrayindatabase[$key2]['position']; |
|
| 340 | + $filearray[$key]['cover'] = $filearrayindatabase[$key2]['cover']; |
|
| 341 | + $filearray[$key]['acl'] = $filearrayindatabase[$key2]['acl']; |
|
| 342 | + $filearray[$key]['rowid'] = $filearrayindatabase[$key2]['rowid']; |
|
| 343 | + $filearray[$key]['label'] = $filearrayindatabase[$key2]['label']; |
|
| 344 | + $filearray[$key]['share'] = $filearrayindatabase[$key2]['share']; |
|
| 345 | + $found = 1; |
|
| 346 | 346 | break; |
| 347 | 347 | } |
| 348 | 348 | } |
| 349 | 349 | |
| 350 | - if (! $found) // This happen in transition toward version 6, or if files were added manually into os dir. |
|
| 350 | + if (!$found) // This happen in transition toward version 6, or if files were added manually into os dir. |
|
| 351 | 351 | { |
| 352 | - $filearray[$key]['position']='999999'; // File not indexed are at end. So if we add a file, it will not replace an existing position |
|
| 353 | - $filearray[$key]['cover']=0; |
|
| 354 | - $filearray[$key]['acl']=''; |
|
| 352 | + $filearray[$key]['position'] = '999999'; // File not indexed are at end. So if we add a file, it will not replace an existing position |
|
| 353 | + $filearray[$key]['cover'] = 0; |
|
| 354 | + $filearray[$key]['acl'] = ''; |
|
| 355 | 355 | |
| 356 | - $rel_filename = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $filearray[$key]['fullname']); |
|
| 357 | - if (! preg_match('/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filetorenameafter)) // If not a tmp file |
|
| 356 | + $rel_filename = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $filearray[$key]['fullname']); |
|
| 357 | + if (!preg_match('/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filetorenameafter)) // If not a tmp file |
|
| 358 | 358 | { |
| 359 | 359 | dol_syslog("list_of_documents We found a file called '".$filearray[$key]['name']."' not indexed into database. We add it"); |
| 360 | 360 | include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; |
| 361 | - $ecmfile=new EcmFiles($db); |
|
| 361 | + $ecmfile = new EcmFiles($db); |
|
| 362 | 362 | |
| 363 | 363 | // Add entry into database |
| 364 | 364 | $filename = basename($rel_filename); |
@@ -368,11 +368,11 @@ discard block |
||
| 368 | 368 | |
| 369 | 369 | $ecmfile->filepath = $rel_dir; |
| 370 | 370 | $ecmfile->filename = $filename; |
| 371 | - $ecmfile->label = md5_file(dol_osencode($filearray[$key]['fullname'])); // $destfile is a full path to file |
|
| 371 | + $ecmfile->label = md5_file(dol_osencode($filearray[$key]['fullname'])); // $destfile is a full path to file |
|
| 372 | 372 | $ecmfile->fullpath_orig = $filearray[$key]['fullname']; |
| 373 | 373 | $ecmfile->gen_or_uploaded = 'unknown'; |
| 374 | - $ecmfile->description = ''; // indexed content |
|
| 375 | - $ecmfile->keyword = ''; // keyword content |
|
| 374 | + $ecmfile->description = ''; // indexed content |
|
| 375 | + $ecmfile->keyword = ''; // keyword content |
|
| 376 | 376 | $result = $ecmfile->create($user); |
| 377 | 377 | if ($result < 0) |
| 378 | 378 | { |
@@ -380,12 +380,12 @@ discard block |
||
| 380 | 380 | } |
| 381 | 381 | else |
| 382 | 382 | { |
| 383 | - $filearray[$key]['rowid']=$result; |
|
| 383 | + $filearray[$key]['rowid'] = $result; |
|
| 384 | 384 | } |
| 385 | 385 | } |
| 386 | 386 | else |
| 387 | 387 | { |
| 388 | - $filearray[$key]['rowid']=0; // Should not happened |
|
| 388 | + $filearray[$key]['rowid'] = 0; // Should not happened |
|
| 389 | 389 | } |
| 390 | 390 | } |
| 391 | 391 | } |
@@ -406,10 +406,10 @@ discard block |
||
| 406 | 406 | global $sortorder; |
| 407 | 407 | global $sortfield; |
| 408 | 408 | |
| 409 | - $sortorder=strtoupper($sortorder); |
|
| 409 | + $sortorder = strtoupper($sortorder); |
|
| 410 | 410 | |
| 411 | - if ($sortorder == 'ASC') { $retup=-1; $retdown=1; } |
|
| 412 | - else { $retup=1; $retdown=-1; } |
|
| 411 | + if ($sortorder == 'ASC') { $retup = -1; $retdown = 1; } |
|
| 412 | + else { $retup = 1; $retdown = -1; } |
|
| 413 | 413 | |
| 414 | 414 | if ($sortfield == 'name') |
| 415 | 415 | { |
@@ -437,7 +437,7 @@ discard block |
||
| 437 | 437 | */ |
| 438 | 438 | function dol_is_dir($folder) |
| 439 | 439 | { |
| 440 | - $newfolder=dol_osencode($folder); |
|
| 440 | + $newfolder = dol_osencode($folder); |
|
| 441 | 441 | if (is_dir($newfolder)) return true; |
| 442 | 442 | else return false; |
| 443 | 443 | } |
@@ -450,7 +450,7 @@ discard block |
||
| 450 | 450 | */ |
| 451 | 451 | function dol_is_file($pathoffile) |
| 452 | 452 | { |
| 453 | - $newpathoffile=dol_osencode($pathoffile); |
|
| 453 | + $newpathoffile = dol_osencode($pathoffile); |
|
| 454 | 454 | return is_file($newpathoffile); |
| 455 | 455 | } |
| 456 | 456 | |
@@ -462,7 +462,7 @@ discard block |
||
| 462 | 462 | */ |
| 463 | 463 | function dol_is_link($pathoffile) |
| 464 | 464 | { |
| 465 | - $newpathoffile=dol_osencode($pathoffile); |
|
| 465 | + $newpathoffile = dol_osencode($pathoffile); |
|
| 466 | 466 | return is_link($newpathoffile); |
| 467 | 467 | } |
| 468 | 468 | |
@@ -474,10 +474,10 @@ discard block |
||
| 474 | 474 | */ |
| 475 | 475 | function dol_is_url($url) |
| 476 | 476 | { |
| 477 | - $tmpprot=array('file','http','https','ftp','zlib','data','ssh','ssh2','ogg','expect'); |
|
| 478 | - foreach($tmpprot as $prot) |
|
| 477 | + $tmpprot = array('file', 'http', 'https', 'ftp', 'zlib', 'data', 'ssh', 'ssh2', 'ogg', 'expect'); |
|
| 478 | + foreach ($tmpprot as $prot) |
|
| 479 | 479 | { |
| 480 | - if (preg_match('/^'.$prot.':/i',$url)) return true; |
|
| 480 | + if (preg_match('/^'.$prot.':/i', $url)) return true; |
|
| 481 | 481 | } |
| 482 | 482 | return false; |
| 483 | 483 | } |
@@ -490,7 +490,7 @@ discard block |
||
| 490 | 490 | */ |
| 491 | 491 | function dol_dir_is_emtpy($folder) |
| 492 | 492 | { |
| 493 | - $newfolder=dol_osencode($folder); |
|
| 493 | + $newfolder = dol_osencode($folder); |
|
| 494 | 494 | if (is_dir($newfolder)) |
| 495 | 495 | { |
| 496 | 496 | $handle = opendir($newfolder); |
@@ -499,7 +499,7 @@ discard block |
||
| 499 | 499 | { |
| 500 | 500 | $name_array[] = $name; |
| 501 | 501 | } |
| 502 | - foreach($name_array as $temp) $folder_content .= $temp; |
|
| 502 | + foreach ($name_array as $temp) $folder_content .= $temp; |
|
| 503 | 503 | |
| 504 | 504 | closedir($handle); |
| 505 | 505 | |
@@ -519,24 +519,24 @@ discard block |
||
| 519 | 519 | */ |
| 520 | 520 | function dol_count_nb_of_line($file) |
| 521 | 521 | { |
| 522 | - $nb=0; |
|
| 522 | + $nb = 0; |
|
| 523 | 523 | |
| 524 | - $newfile=dol_osencode($file); |
|
| 524 | + $newfile = dol_osencode($file); |
|
| 525 | 525 | //print 'x'.$file; |
| 526 | - $fp=fopen($newfile,'r'); |
|
| 526 | + $fp = fopen($newfile, 'r'); |
|
| 527 | 527 | if ($fp) |
| 528 | 528 | { |
| 529 | 529 | while (!feof($fp)) |
| 530 | 530 | { |
| 531 | - $line=fgets($fp); |
|
| 531 | + $line = fgets($fp); |
|
| 532 | 532 | // We increase count only if read was success. We need test because feof return true only after fgets so we do n+1 fgets for a file with n lines. |
| 533 | - if (! $line === false) $nb++; |
|
| 533 | + if (!$line === false) $nb++; |
|
| 534 | 534 | } |
| 535 | 535 | fclose($fp); |
| 536 | 536 | } |
| 537 | 537 | else |
| 538 | 538 | { |
| 539 | - $nb=-1; |
|
| 539 | + $nb = -1; |
|
| 540 | 540 | } |
| 541 | 541 | |
| 542 | 542 | return $nb; |
@@ -551,7 +551,7 @@ discard block |
||
| 551 | 551 | */ |
| 552 | 552 | function dol_filesize($pathoffile) |
| 553 | 553 | { |
| 554 | - $newpathoffile=dol_osencode($pathoffile); |
|
| 554 | + $newpathoffile = dol_osencode($pathoffile); |
|
| 555 | 555 | return filesize($newpathoffile); |
| 556 | 556 | } |
| 557 | 557 | |
@@ -563,7 +563,7 @@ discard block |
||
| 563 | 563 | */ |
| 564 | 564 | function dol_filemtime($pathoffile) |
| 565 | 565 | { |
| 566 | - $newpathoffile=dol_osencode($pathoffile); |
|
| 566 | + $newpathoffile = dol_osencode($pathoffile); |
|
| 567 | 567 | return @filemtime($newpathoffile); // @Is to avoid errors if files does not exists |
| 568 | 568 | } |
| 569 | 569 | |
@@ -578,31 +578,31 @@ discard block |
||
| 578 | 578 | * @return int <0 if error, 0 if nothing done (dest file already exists), >0 if OK |
| 579 | 579 | * @see dol_copy dolReplaceRegExInFile |
| 580 | 580 | */ |
| 581 | -function dolReplaceInFile($srcfile, $arrayreplacement, $destfile='', $newmask=0, $indexdatabase=0) |
|
| 581 | +function dolReplaceInFile($srcfile, $arrayreplacement, $destfile = '', $newmask = 0, $indexdatabase = 0) |
|
| 582 | 582 | { |
| 583 | 583 | global $conf; |
| 584 | 584 | |
| 585 | 585 | dol_syslog("files.lib.php::dolReplaceInFile srcfile=".$srcfile." destfile=".$destfile." newmask=".$newmask." indexdatabase=".$indexdatabase); |
| 586 | 586 | |
| 587 | 587 | if (empty($srcfile)) return -1; |
| 588 | - if (empty($destfile)) $destfile=$srcfile; |
|
| 588 | + if (empty($destfile)) $destfile = $srcfile; |
|
| 589 | 589 | |
| 590 | - $destexists=dol_is_file($destfile); |
|
| 590 | + $destexists = dol_is_file($destfile); |
|
| 591 | 591 | if (($destfile != $srcfile) && $destexists) return 0; |
| 592 | 592 | |
| 593 | - $tmpdestfile=$destfile.'.tmp'; |
|
| 593 | + $tmpdestfile = $destfile.'.tmp'; |
|
| 594 | 594 | |
| 595 | - $newpathofsrcfile=dol_osencode($srcfile); |
|
| 596 | - $newpathoftmpdestfile=dol_osencode($tmpdestfile); |
|
| 597 | - $newpathofdestfile=dol_osencode($destfile); |
|
| 598 | - $newdirdestfile=dirname($newpathofdestfile); |
|
| 595 | + $newpathofsrcfile = dol_osencode($srcfile); |
|
| 596 | + $newpathoftmpdestfile = dol_osencode($tmpdestfile); |
|
| 597 | + $newpathofdestfile = dol_osencode($destfile); |
|
| 598 | + $newdirdestfile = dirname($newpathofdestfile); |
|
| 599 | 599 | |
| 600 | - if ($destexists && ! is_writable($newpathofdestfile)) |
|
| 600 | + if ($destexists && !is_writable($newpathofdestfile)) |
|
| 601 | 601 | { |
| 602 | 602 | dol_syslog("files.lib.php::dolReplaceInFile failed Permission denied to overwrite target file", LOG_WARNING); |
| 603 | 603 | return -1; |
| 604 | 604 | } |
| 605 | - if (! is_writable($newdirdestfile)) |
|
| 605 | + if (!is_writable($newdirdestfile)) |
|
| 606 | 606 | { |
| 607 | 607 | dol_syslog("files.lib.php::dolReplaceInFile failed Permission denied to write into target directory ".$newdirdestfile, LOG_WARNING); |
| 608 | 608 | return -2; |
@@ -619,17 +619,17 @@ discard block |
||
| 619 | 619 | @chmod($newpathoftmpdestfile, octdec($newmask)); |
| 620 | 620 | |
| 621 | 621 | // Rename |
| 622 | - $result=dol_move($newpathoftmpdestfile, $newpathofdestfile, $newmask, (($destfile == $srcfile)?1:0), 0, $indexdatabase); |
|
| 623 | - if (! $result) |
|
| 622 | + $result = dol_move($newpathoftmpdestfile, $newpathofdestfile, $newmask, (($destfile == $srcfile) ? 1 : 0), 0, $indexdatabase); |
|
| 623 | + if (!$result) |
|
| 624 | 624 | { |
| 625 | 625 | dol_syslog("files.lib.php::dolReplaceInFile failed to move tmp file to final dest", LOG_WARNING); |
| 626 | 626 | return -3; |
| 627 | 627 | } |
| 628 | - if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK; |
|
| 628 | + if (empty($newmask) && !empty($conf->global->MAIN_UMASK)) $newmask = $conf->global->MAIN_UMASK; |
|
| 629 | 629 | if (empty($newmask)) // This should no happen |
| 630 | 630 | { |
| 631 | 631 | dol_syslog("Warning: dolReplaceInFile called with empty value for newmask and no default value defined", LOG_WARNING); |
| 632 | - $newmask='0664'; |
|
| 632 | + $newmask = '0664'; |
|
| 633 | 633 | } |
| 634 | 634 | |
| 635 | 635 | @chmod($newpathofdestfile, octdec($newmask)); |
@@ -648,7 +648,7 @@ discard block |
||
| 648 | 648 | * @return int <0 if error, 0 if nothing done (dest file already exists), >0 if OK |
| 649 | 649 | * @see dol_copy dolReplaceInFile |
| 650 | 650 | */ |
| 651 | -function dolReplaceRegExInFile($srcfile, $arrayreplacement, $destfile='', $newmask=0, $indexdatabase=0) |
|
| 651 | +function dolReplaceRegExInFile($srcfile, $arrayreplacement, $destfile = '', $newmask = 0, $indexdatabase = 0) |
|
| 652 | 652 | { |
| 653 | 653 | // TODO |
| 654 | 654 | } |
@@ -663,7 +663,7 @@ discard block |
||
| 663 | 663 | * @return int <0 if error, 0 if nothing done (dest file already exists and overwriteifexists=0), >0 if OK |
| 664 | 664 | * @see dol_delete_file |
| 665 | 665 | */ |
| 666 | -function dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1) |
|
| 666 | +function dol_copy($srcfile, $destfile, $newmask = 0, $overwriteifexists = 1) |
|
| 667 | 667 | { |
| 668 | 668 | global $conf; |
| 669 | 669 | |
@@ -671,36 +671,36 @@ discard block |
||
| 671 | 671 | |
| 672 | 672 | if (empty($srcfile) || empty($destfile)) return -1; |
| 673 | 673 | |
| 674 | - $destexists=dol_is_file($destfile); |
|
| 675 | - if (! $overwriteifexists && $destexists) return 0; |
|
| 674 | + $destexists = dol_is_file($destfile); |
|
| 675 | + if (!$overwriteifexists && $destexists) return 0; |
|
| 676 | 676 | |
| 677 | - $newpathofsrcfile=dol_osencode($srcfile); |
|
| 678 | - $newpathofdestfile=dol_osencode($destfile); |
|
| 679 | - $newdirdestfile=dirname($newpathofdestfile); |
|
| 677 | + $newpathofsrcfile = dol_osencode($srcfile); |
|
| 678 | + $newpathofdestfile = dol_osencode($destfile); |
|
| 679 | + $newdirdestfile = dirname($newpathofdestfile); |
|
| 680 | 680 | |
| 681 | - if ($destexists && ! is_writable($newpathofdestfile)) |
|
| 681 | + if ($destexists && !is_writable($newpathofdestfile)) |
|
| 682 | 682 | { |
| 683 | 683 | dol_syslog("files.lib.php::dol_copy failed Permission denied to overwrite target file", LOG_WARNING); |
| 684 | 684 | return -1; |
| 685 | 685 | } |
| 686 | - if (! is_writable($newdirdestfile)) |
|
| 686 | + if (!is_writable($newdirdestfile)) |
|
| 687 | 687 | { |
| 688 | 688 | dol_syslog("files.lib.php::dol_copy failed Permission denied to write into target directory ".$newdirdestfile, LOG_WARNING); |
| 689 | 689 | return -2; |
| 690 | 690 | } |
| 691 | 691 | // Copy with overwriting if exists |
| 692 | - $result=@copy($newpathofsrcfile, $newpathofdestfile); |
|
| 692 | + $result = @copy($newpathofsrcfile, $newpathofdestfile); |
|
| 693 | 693 | //$result=copy($newpathofsrcfile, $newpathofdestfile); // To see errors, remove @ |
| 694 | - if (! $result) |
|
| 694 | + if (!$result) |
|
| 695 | 695 | { |
| 696 | 696 | dol_syslog("files.lib.php::dol_copy failed to copy", LOG_WARNING); |
| 697 | 697 | return -3; |
| 698 | 698 | } |
| 699 | - if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK; |
|
| 699 | + if (empty($newmask) && !empty($conf->global->MAIN_UMASK)) $newmask = $conf->global->MAIN_UMASK; |
|
| 700 | 700 | if (empty($newmask)) // This should no happen |
| 701 | 701 | { |
| 702 | 702 | dol_syslog("Warning: dol_copy called with empty value for newmask and no default value defined", LOG_WARNING); |
| 703 | - $newmask='0664'; |
|
| 703 | + $newmask = '0664'; |
|
| 704 | 704 | } |
| 705 | 705 | |
| 706 | 706 | @chmod($newpathofdestfile, octdec($newmask)); |
@@ -719,44 +719,44 @@ discard block |
||
| 719 | 719 | * @return int <0 if error, 0 if nothing done (all files already exists and overwriteifexists=0), >0 if OK |
| 720 | 720 | * @see dol_copy |
| 721 | 721 | */ |
| 722 | -function dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists, $arrayreplacement=null) |
|
| 722 | +function dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists, $arrayreplacement = null) |
|
| 723 | 723 | { |
| 724 | 724 | global $conf; |
| 725 | 725 | |
| 726 | - $result=0; |
|
| 726 | + $result = 0; |
|
| 727 | 727 | |
| 728 | 728 | dol_syslog("files.lib.php::dolCopyDir srcfile=".$srcfile." destfile=".$destfile." newmask=".$newmask." overwriteifexists=".$overwriteifexists); |
| 729 | 729 | |
| 730 | 730 | if (empty($srcfile) || empty($destfile)) return -1; |
| 731 | 731 | |
| 732 | - $destexists=dol_is_dir($destfile); |
|
| 732 | + $destexists = dol_is_dir($destfile); |
|
| 733 | 733 | //if (! $overwriteifexists && $destexists) return 0; // The overwriteifexists is for files only, so propagated to dol_copy only. |
| 734 | 734 | |
| 735 | - if (! $destexists) |
|
| 735 | + if (!$destexists) |
|
| 736 | 736 | { |
| 737 | 737 | // We must set mask just before creating dir, becaause it can be set differently by dol_copy |
| 738 | 738 | umask(0); |
| 739 | - $dirmaskdec=octdec($newmask); |
|
| 740 | - if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) $dirmaskdec=octdec($conf->global->MAIN_UMASK); |
|
| 741 | - $dirmaskdec |= octdec('0200'); // Set w bit required to be able to create content for recursive subdirs files |
|
| 739 | + $dirmaskdec = octdec($newmask); |
|
| 740 | + if (empty($newmask) && !empty($conf->global->MAIN_UMASK)) $dirmaskdec = octdec($conf->global->MAIN_UMASK); |
|
| 741 | + $dirmaskdec |= octdec('0200'); // Set w bit required to be able to create content for recursive subdirs files |
|
| 742 | 742 | dol_mkdir($destfile, '', decoct($dirmaskdec)); |
| 743 | 743 | } |
| 744 | 744 | |
| 745 | - $ossrcfile=dol_osencode($srcfile); |
|
| 746 | - $osdestfile=dol_osencode($destfile); |
|
| 745 | + $ossrcfile = dol_osencode($srcfile); |
|
| 746 | + $osdestfile = dol_osencode($destfile); |
|
| 747 | 747 | |
| 748 | 748 | // Recursive function to copy all subdirectories and contents: |
| 749 | 749 | if (is_dir($ossrcfile)) |
| 750 | 750 | { |
| 751 | - $dir_handle=opendir($ossrcfile); |
|
| 752 | - while ($file=readdir($dir_handle)) |
|
| 751 | + $dir_handle = opendir($ossrcfile); |
|
| 752 | + while ($file = readdir($dir_handle)) |
|
| 753 | 753 | { |
| 754 | - if ($file != "." && $file != ".." && ! is_link($ossrcfile."/".$file)) |
|
| 754 | + if ($file != "." && $file != ".." && !is_link($ossrcfile."/".$file)) |
|
| 755 | 755 | { |
| 756 | 756 | if (is_dir($ossrcfile."/".$file)) |
| 757 | 757 | { |
| 758 | 758 | //var_dump("xxx dolCopyDir $srcfile/$file, $destfile/$file, $newmask, $overwriteifexists"); |
| 759 | - $tmpresult=dolCopyDir($srcfile."/".$file, $destfile."/".$file, $newmask, $overwriteifexists, $arrayreplacement); |
|
| 759 | + $tmpresult = dolCopyDir($srcfile."/".$file, $destfile."/".$file, $newmask, $overwriteifexists, $arrayreplacement); |
|
| 760 | 760 | } |
| 761 | 761 | else |
| 762 | 762 | { |
@@ -764,12 +764,12 @@ discard block |
||
| 764 | 764 | // Replace destination filename with a new one |
| 765 | 765 | if (is_array($arrayreplacement)) |
| 766 | 766 | { |
| 767 | - foreach($arrayreplacement as $key => $val) |
|
| 767 | + foreach ($arrayreplacement as $key => $val) |
|
| 768 | 768 | { |
| 769 | 769 | $newfile = str_replace($key, $val, $newfile); |
| 770 | 770 | } |
| 771 | 771 | } |
| 772 | - $tmpresult=dol_copy($srcfile."/".$file, $destfile."/".$newfile, $newmask, $overwriteifexists); |
|
| 772 | + $tmpresult = dol_copy($srcfile."/".$file, $destfile."/".$newfile, $newmask, $overwriteifexists); |
|
| 773 | 773 | } |
| 774 | 774 | // Set result |
| 775 | 775 | if ($result > 0 && $tmpresult >= 0) |
@@ -778,7 +778,7 @@ discard block |
||
| 778 | 778 | } |
| 779 | 779 | else |
| 780 | 780 | { |
| 781 | - $result=$tmpresult; |
|
| 781 | + $result = $tmpresult; |
|
| 782 | 782 | } |
| 783 | 783 | if ($result < 0) break; |
| 784 | 784 | } |
@@ -811,31 +811,31 @@ discard block |
||
| 811 | 811 | * @return boolean True if OK, false if KO |
| 812 | 812 | * @see dol_move_uploaded_file |
| 813 | 813 | */ |
| 814 | -function dol_move($srcfile, $destfile, $newmask=0, $overwriteifexists=1, $testvirus=0, $indexdatabase=1) |
|
| 814 | +function dol_move($srcfile, $destfile, $newmask = 0, $overwriteifexists = 1, $testvirus = 0, $indexdatabase = 1) |
|
| 815 | 815 | { |
| 816 | 816 | global $user, $db, $conf; |
| 817 | - $result=false; |
|
| 817 | + $result = false; |
|
| 818 | 818 | |
| 819 | 819 | dol_syslog("files.lib.php::dol_move srcfile=".$srcfile." destfile=".$destfile." newmask=".$newmask." overwritifexists=".$overwriteifexists); |
| 820 | - $srcexists=dol_is_file($srcfile); |
|
| 821 | - $destexists=dol_is_file($destfile); |
|
| 820 | + $srcexists = dol_is_file($srcfile); |
|
| 821 | + $destexists = dol_is_file($destfile); |
|
| 822 | 822 | |
| 823 | - if (! $srcexists) |
|
| 823 | + if (!$srcexists) |
|
| 824 | 824 | { |
| 825 | 825 | dol_syslog("files.lib.php::dol_move srcfile does not exists. we ignore the move request."); |
| 826 | 826 | return false; |
| 827 | 827 | } |
| 828 | 828 | |
| 829 | - if ($overwriteifexists || ! $destexists) |
|
| 829 | + if ($overwriteifexists || !$destexists) |
|
| 830 | 830 | { |
| 831 | - $newpathofsrcfile=dol_osencode($srcfile); |
|
| 832 | - $newpathofdestfile=dol_osencode($destfile); |
|
| 831 | + $newpathofsrcfile = dol_osencode($srcfile); |
|
| 832 | + $newpathofdestfile = dol_osencode($destfile); |
|
| 833 | 833 | |
| 834 | 834 | // Check virus |
| 835 | - $testvirusarray=array(); |
|
| 835 | + $testvirusarray = array(); |
|
| 836 | 836 | if ($testvirus) |
| 837 | 837 | { |
| 838 | - $testvirusarray=dolCheckVirus($newpathofsrcfile); |
|
| 838 | + $testvirusarray = dolCheckVirus($newpathofsrcfile); |
|
| 839 | 839 | if (count($testvirusarray)) |
| 840 | 840 | { |
| 841 | 841 | dol_syslog("files.lib.php::dol_move canceled because a virus was found into source file. we ignore the move request.", LOG_WARNING); |
@@ -843,15 +843,15 @@ discard block |
||
| 843 | 843 | } |
| 844 | 844 | } |
| 845 | 845 | |
| 846 | - $result=@rename($newpathofsrcfile, $newpathofdestfile); // To see errors, remove @ |
|
| 847 | - if (! $result) |
|
| 846 | + $result = @rename($newpathofsrcfile, $newpathofdestfile); // To see errors, remove @ |
|
| 847 | + if (!$result) |
|
| 848 | 848 | { |
| 849 | 849 | if ($destexists) |
| 850 | 850 | { |
| 851 | 851 | dol_syslog("files.lib.php::dol_move Failed. We try to delete target first and move after.", LOG_WARNING); |
| 852 | 852 | // We force delete and try again. Rename function sometimes fails to replace dest file with some windows NTFS partitions. |
| 853 | 853 | dol_delete_file($destfile); |
| 854 | - $result=@rename($newpathofsrcfile, $newpathofdestfile); // To see errors, remove @ |
|
| 854 | + $result = @rename($newpathofsrcfile, $newpathofdestfile); // To see errors, remove @ |
|
| 855 | 855 | } |
| 856 | 856 | else dol_syslog("files.lib.php::dol_move Failed.", LOG_WARNING); |
| 857 | 857 | } |
@@ -860,9 +860,9 @@ discard block |
||
| 860 | 860 | if ($result && $indexdatabase) |
| 861 | 861 | { |
| 862 | 862 | // Rename entry into ecm database |
| 863 | - $rel_filetorenamebefore = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $srcfile); |
|
| 864 | - $rel_filetorenameafter = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $destfile); |
|
| 865 | - if (! preg_match('/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filetorenameafter)) // If not a tmp file |
|
| 863 | + $rel_filetorenamebefore = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $srcfile); |
|
| 864 | + $rel_filetorenameafter = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $destfile); |
|
| 865 | + if (!preg_match('/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filetorenameafter)) // If not a tmp file |
|
| 866 | 866 | { |
| 867 | 867 | $rel_filetorenamebefore = preg_replace('/^[\\/]/', '', $rel_filetorenamebefore); |
| 868 | 868 | $rel_filetorenameafter = preg_replace('/^[\\/]/', '', $rel_filetorenameafter); |
@@ -871,14 +871,14 @@ discard block |
||
| 871 | 871 | dol_syslog("Try to rename also entries in database for full relative path before = ".$rel_filetorenamebefore." after = ".$rel_filetorenameafter, LOG_DEBUG); |
| 872 | 872 | include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; |
| 873 | 873 | |
| 874 | - $ecmfiletarget=new EcmFiles($db); |
|
| 874 | + $ecmfiletarget = new EcmFiles($db); |
|
| 875 | 875 | $resultecmtarget = $ecmfiletarget->fetch(0, '', $rel_filetorenameafter); |
| 876 | 876 | if ($resultecmtarget > 0) // An entry for target name already exists for target, we delete it, a new one will be created. |
| 877 | 877 | { |
| 878 | 878 | $ecmfiletarget->delete($user); |
| 879 | 879 | } |
| 880 | 880 | |
| 881 | - $ecmfile=new EcmFiles($db); |
|
| 881 | + $ecmfile = new EcmFiles($db); |
|
| 882 | 882 | $resultecm = $ecmfile->fetch(0, '', $rel_filetorenamebefore); |
| 883 | 883 | if ($resultecm > 0) // If an entry was found for src file, we use it to move entry |
| 884 | 884 | { |
@@ -900,11 +900,11 @@ discard block |
||
| 900 | 900 | |
| 901 | 901 | $ecmfile->filepath = $rel_dir; |
| 902 | 902 | $ecmfile->filename = $filename; |
| 903 | - $ecmfile->label = md5_file(dol_osencode($destfile)); // $destfile is a full path to file |
|
| 903 | + $ecmfile->label = md5_file(dol_osencode($destfile)); // $destfile is a full path to file |
|
| 904 | 904 | $ecmfile->fullpath_orig = $srcfile; |
| 905 | 905 | $ecmfile->gen_or_uploaded = 'unknown'; |
| 906 | - $ecmfile->description = ''; // indexed content |
|
| 907 | - $ecmfile->keyword = ''; // keyword content |
|
| 906 | + $ecmfile->description = ''; // indexed content |
|
| 907 | + $ecmfile->keyword = ''; // keyword content |
|
| 908 | 908 | $resultecm = $ecmfile->create($user); |
| 909 | 909 | if ($resultecm < 0) |
| 910 | 910 | { |
@@ -916,13 +916,13 @@ discard block |
||
| 916 | 916 | setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings'); |
| 917 | 917 | } |
| 918 | 918 | |
| 919 | - if ($resultecm > 0) $result=true; |
|
| 919 | + if ($resultecm > 0) $result = true; |
|
| 920 | 920 | else $result = false; |
| 921 | 921 | } |
| 922 | 922 | } |
| 923 | 923 | |
| 924 | - if (empty($newmask)) $newmask=empty($conf->global->MAIN_UMASK)?'0755':$conf->global->MAIN_UMASK; |
|
| 925 | - $newmaskdec=octdec($newmask); |
|
| 924 | + if (empty($newmask)) $newmask = empty($conf->global->MAIN_UMASK) ? '0755' : $conf->global->MAIN_UMASK; |
|
| 925 | + $newmaskdec = octdec($newmask); |
|
| 926 | 926 | // Currently method is restricted to files (dol_delete_files previously used is for files, and mask usage if for files too) |
| 927 | 927 | // to allow mask usage for dir, we shoul introduce a new param "isdir" to 1 to complete newmask like this |
| 928 | 928 | // if ($isdir) $newmaskdec |= octdec('0111'); // Set x bit required for directories |
@@ -958,16 +958,16 @@ discard block |
||
| 958 | 958 | { |
| 959 | 959 | global $conf; |
| 960 | 960 | |
| 961 | - if (! empty($conf->global->MAIN_ANTIVIRUS_COMMAND)) |
|
| 961 | + if (!empty($conf->global->MAIN_ANTIVIRUS_COMMAND)) |
|
| 962 | 962 | { |
| 963 | - if (! class_exists('AntiVir')) { |
|
| 963 | + if (!class_exists('AntiVir')) { |
|
| 964 | 964 | require_once DOL_DOCUMENT_ROOT.'/core/class/antivir.class.php'; |
| 965 | 965 | } |
| 966 | - $antivir=new AntiVir($db); |
|
| 966 | + $antivir = new AntiVir($db); |
|
| 967 | 967 | $result = $antivir->dol_avscan_file($src_file); |
| 968 | 968 | if ($result < 0) // If virus or error, we stop here |
| 969 | 969 | { |
| 970 | - $reterrors=$antivir->errors; |
|
| 970 | + $reterrors = $antivir->errors; |
|
| 971 | 971 | return $reterrors; |
| 972 | 972 | } |
| 973 | 973 | } |
@@ -993,20 +993,20 @@ discard block |
||
| 993 | 993 | * @return int >0 if OK, <0 or string if KO |
| 994 | 994 | * @see dol_move |
| 995 | 995 | */ |
| 996 | -function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0, $nohook=0, $varfiles='addedfile') |
|
| 996 | +function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan = 0, $uploaderrorcode = 0, $nohook = 0, $varfiles = 'addedfile') |
|
| 997 | 997 | { |
| 998 | 998 | global $conf, $db, $user, $langs; |
| 999 | 999 | global $object, $hookmanager; |
| 1000 | 1000 | |
| 1001 | - $reshook=0; |
|
| 1001 | + $reshook = 0; |
|
| 1002 | 1002 | $file_name = $dest_file; |
| 1003 | 1003 | |
| 1004 | 1004 | if (empty($nohook)) |
| 1005 | 1005 | { |
| 1006 | - $reshook=$hookmanager->initHooks(array('fileslib')); |
|
| 1006 | + $reshook = $hookmanager->initHooks(array('fileslib')); |
|
| 1007 | 1007 | |
| 1008 | - $parameters=array('dest_file' => $dest_file, 'src_file' => $src_file, 'file_name' => $file_name, 'varfiles' => $varfiles, 'allowoverwrite' => $allowoverwrite); |
|
| 1009 | - $reshook=$hookmanager->executeHooks('moveUploadedFile', $parameters, $object); |
|
| 1008 | + $parameters = array('dest_file' => $dest_file, 'src_file' => $src_file, 'file_name' => $file_name, 'varfiles' => $varfiles, 'allowoverwrite' => $allowoverwrite); |
|
| 1009 | + $reshook = $hookmanager->executeHooks('moveUploadedFile', $parameters, $object); |
|
| 1010 | 1010 | } |
| 1011 | 1011 | |
| 1012 | 1012 | if (empty($reshook)) |
@@ -1014,7 +1014,7 @@ discard block |
||
| 1014 | 1014 | // If an upload error has been reported |
| 1015 | 1015 | if ($uploaderrorcode) |
| 1016 | 1016 | { |
| 1017 | - switch($uploaderrorcode) |
|
| 1017 | + switch ($uploaderrorcode) |
|
| 1018 | 1018 | { |
| 1019 | 1019 | case UPLOAD_ERR_INI_SIZE: // 1 |
| 1020 | 1020 | return 'ErrorFileSizeTooLarge'; |
@@ -1042,25 +1042,25 @@ discard block |
||
| 1042 | 1042 | // If we need to make a virus scan |
| 1043 | 1043 | if (empty($disablevirusscan) && file_exists($src_file)) |
| 1044 | 1044 | { |
| 1045 | - $checkvirusarray=dolCheckVirus($src_file); |
|
| 1045 | + $checkvirusarray = dolCheckVirus($src_file); |
|
| 1046 | 1046 | if (count($checkvirusarray)) |
| 1047 | 1047 | { |
| 1048 | - dol_syslog('Files.lib::dol_move_uploaded_file File "'.$src_file.'" (target name "'.$dest_file.'") KO with antivirus: result='.$result.' errors='.join(',',$checkvirusarray), LOG_WARNING); |
|
| 1049 | - return 'ErrorFileIsInfectedWithAVirus: '.join(',',$checkvirusarray); |
|
| 1048 | + dol_syslog('Files.lib::dol_move_uploaded_file File "'.$src_file.'" (target name "'.$dest_file.'") KO with antivirus: result='.$result.' errors='.join(',', $checkvirusarray), LOG_WARNING); |
|
| 1049 | + return 'ErrorFileIsInfectedWithAVirus: '.join(',', $checkvirusarray); |
|
| 1050 | 1050 | } |
| 1051 | 1051 | } |
| 1052 | 1052 | |
| 1053 | 1053 | // Security: |
| 1054 | 1054 | // Disallow file with some extensions. We rename them. |
| 1055 | 1055 | // Because if we put the documents directory into a directory inside web root (very bad), this allows to execute on demand arbitrary code. |
| 1056 | - if (preg_match('/(\.htm|\.html|\.php|\.pl|\.cgi)$/i',$dest_file) && empty($conf->global->MAIN_DOCUMENT_IS_OUTSIDE_WEBROOT_SO_NOEXE_NOT_REQUIRED)) |
|
| 1056 | + if (preg_match('/(\.htm|\.html|\.php|\.pl|\.cgi)$/i', $dest_file) && empty($conf->global->MAIN_DOCUMENT_IS_OUTSIDE_WEBROOT_SO_NOEXE_NOT_REQUIRED)) |
|
| 1057 | 1057 | { |
| 1058 | - $file_name.= '.noexe'; |
|
| 1058 | + $file_name .= '.noexe'; |
|
| 1059 | 1059 | } |
| 1060 | 1060 | |
| 1061 | 1061 | // Security: |
| 1062 | 1062 | // We refuse cache files/dirs, upload using .. and pipes into filenames. |
| 1063 | - if (preg_match('/^\./',$src_file) || preg_match('/\.\./',$src_file) || preg_match('/[<>|]/',$src_file)) |
|
| 1063 | + if (preg_match('/^\./', $src_file) || preg_match('/\.\./', $src_file) || preg_match('/[<>|]/', $src_file)) |
|
| 1064 | 1064 | { |
| 1065 | 1065 | dol_syslog("Refused to deliver file ".$src_file, LOG_WARNING); |
| 1066 | 1066 | return -1; |
@@ -1068,7 +1068,7 @@ discard block |
||
| 1068 | 1068 | |
| 1069 | 1069 | // Security: |
| 1070 | 1070 | // On interdit fichiers caches, remontees de repertoire ainsi que les pipe dans les noms de fichiers. |
| 1071 | - if (preg_match('/^\./',$dest_file) || preg_match('/\.\./',$dest_file) || preg_match('/[<>|]/',$dest_file)) |
|
| 1071 | + if (preg_match('/^\./', $dest_file) || preg_match('/\.\./', $dest_file) || preg_match('/[<>|]/', $dest_file)) |
|
| 1072 | 1072 | { |
| 1073 | 1073 | dol_syslog("Refused to deliver file ".$dest_file, LOG_WARNING); |
| 1074 | 1074 | return -2; |
@@ -1078,24 +1078,24 @@ discard block |
||
| 1078 | 1078 | if ($reshook < 0) // At least one blocking error returned by one hook |
| 1079 | 1079 | { |
| 1080 | 1080 | $errmsg = join(',', $hookmanager->errors); |
| 1081 | - if (empty($errmsg)) $errmsg = 'ErrorReturnedBySomeHooks'; // Should not occurs. Added if hook is bugged and does not set ->errors when there is error. |
|
| 1081 | + if (empty($errmsg)) $errmsg = 'ErrorReturnedBySomeHooks'; // Should not occurs. Added if hook is bugged and does not set ->errors when there is error. |
|
| 1082 | 1082 | return $errmsg; |
| 1083 | 1083 | } |
| 1084 | 1084 | elseif (empty($reshook)) |
| 1085 | 1085 | { |
| 1086 | 1086 | // The file functions must be in OS filesystem encoding. |
| 1087 | - $src_file_osencoded=dol_osencode($src_file); |
|
| 1088 | - $file_name_osencoded=dol_osencode($file_name); |
|
| 1087 | + $src_file_osencoded = dol_osencode($src_file); |
|
| 1088 | + $file_name_osencoded = dol_osencode($file_name); |
|
| 1089 | 1089 | |
| 1090 | 1090 | // Check if destination dir is writable |
| 1091 | - if (! is_writable(dirname($file_name_osencoded))) |
|
| 1091 | + if (!is_writable(dirname($file_name_osencoded))) |
|
| 1092 | 1092 | { |
| 1093 | 1093 | dol_syslog("Files.lib::dol_move_uploaded_file Dir ".dirname($file_name_osencoded)." is not writable. Return 'ErrorDirNotWritable'", LOG_WARNING); |
| 1094 | 1094 | return 'ErrorDirNotWritable'; |
| 1095 | 1095 | } |
| 1096 | 1096 | |
| 1097 | 1097 | // Check if destination file already exists |
| 1098 | - if (! $allowoverwrite) |
|
| 1098 | + if (!$allowoverwrite) |
|
| 1099 | 1099 | { |
| 1100 | 1100 | if (file_exists($file_name_osencoded)) |
| 1101 | 1101 | { |
@@ -1105,21 +1105,21 @@ discard block |
||
| 1105 | 1105 | } |
| 1106 | 1106 | |
| 1107 | 1107 | // Move file |
| 1108 | - $return=move_uploaded_file($src_file_osencoded, $file_name_osencoded); |
|
| 1108 | + $return = move_uploaded_file($src_file_osencoded, $file_name_osencoded); |
|
| 1109 | 1109 | if ($return) |
| 1110 | 1110 | { |
| 1111 | - if (! empty($conf->global->MAIN_UMASK)) @chmod($file_name_osencoded, octdec($conf->global->MAIN_UMASK)); |
|
| 1111 | + if (!empty($conf->global->MAIN_UMASK)) @chmod($file_name_osencoded, octdec($conf->global->MAIN_UMASK)); |
|
| 1112 | 1112 | dol_syslog("Files.lib::dol_move_uploaded_file Success to move ".$src_file." to ".$file_name." - Umask=".$conf->global->MAIN_UMASK, LOG_DEBUG); |
| 1113 | - return 1; // Success |
|
| 1113 | + return 1; // Success |
|
| 1114 | 1114 | } |
| 1115 | 1115 | else |
| 1116 | 1116 | { |
| 1117 | 1117 | dol_syslog("Files.lib::dol_move_uploaded_file Failed to move ".$src_file." to ".$file_name, LOG_ERR); |
| 1118 | - return -3; // Unknown error |
|
| 1118 | + return -3; // Unknown error |
|
| 1119 | 1119 | } |
| 1120 | 1120 | } |
| 1121 | 1121 | |
| 1122 | - return 1; // Success |
|
| 1122 | + return 1; // Success |
|
| 1123 | 1123 | } |
| 1124 | 1124 | |
| 1125 | 1125 | /** |
@@ -1136,7 +1136,7 @@ discard block |
||
| 1136 | 1136 | * @return boolean True if no error (file is deleted or if glob is used and there's nothing to delete), False if error |
| 1137 | 1137 | * @see dol_delete_dir |
| 1138 | 1138 | */ |
| 1139 | -function dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1) |
|
| 1139 | +function dol_delete_file($file, $disableglob = 0, $nophperrors = 0, $nohook = 0, $object = null, $allowdotdot = false, $indexdatabase = 1) |
|
| 1140 | 1140 | { |
| 1141 | 1141 | global $db, $conf, $user, $langs; |
| 1142 | 1142 | global $hookmanager; |
@@ -1148,7 +1148,7 @@ discard block |
||
| 1148 | 1148 | |
| 1149 | 1149 | // Security: |
| 1150 | 1150 | // We refuse transversal using .. and pipes into filenames. |
| 1151 | - if ((! $allowdotdot && preg_match('/\.\./',$file)) || preg_match('/[<>|]/',$file)) |
|
| 1151 | + if ((!$allowdotdot && preg_match('/\.\./', $file)) || preg_match('/[<>|]/', $file)) |
|
| 1152 | 1152 | { |
| 1153 | 1153 | dol_syslog("Refused to delete file ".$file, LOG_WARNING); |
| 1154 | 1154 | return false; |
@@ -1158,13 +1158,13 @@ discard block |
||
| 1158 | 1158 | { |
| 1159 | 1159 | $hookmanager->initHooks(array('fileslib')); |
| 1160 | 1160 | |
| 1161 | - $parameters=array( |
|
| 1161 | + $parameters = array( |
|
| 1162 | 1162 | 'GET' => $_GET, |
| 1163 | 1163 | 'file' => $file, |
| 1164 | 1164 | 'disableglob'=> $disableglob, |
| 1165 | 1165 | 'nophperrors' => $nophperrors |
| 1166 | 1166 | ); |
| 1167 | - $reshook=$hookmanager->executeHooks('deleteFile', $parameters, $object); |
|
| 1167 | + $reshook = $hookmanager->executeHooks('deleteFile', $parameters, $object); |
|
| 1168 | 1168 | } |
| 1169 | 1169 | |
| 1170 | 1170 | if (empty($nohook) && $reshook != 0) // reshook = 0 to do standard actions, 1 = ok, -1 = ko |
@@ -1174,29 +1174,29 @@ discard block |
||
| 1174 | 1174 | } |
| 1175 | 1175 | else |
| 1176 | 1176 | { |
| 1177 | - $error=0; |
|
| 1177 | + $error = 0; |
|
| 1178 | 1178 | |
| 1179 | 1179 | //print "x".$file." ".$disableglob;exit; |
| 1180 | - $file_osencoded=dol_osencode($file); // New filename encoded in OS filesystem encoding charset |
|
| 1181 | - if (empty($disableglob) && ! empty($file_osencoded)) |
|
| 1182 | - { |
|
| 1183 | - $ok=true; |
|
| 1184 | - $globencoded=str_replace('[','\[',$file_osencoded); |
|
| 1185 | - $globencoded=str_replace(']','\]',$globencoded); |
|
| 1186 | - $listofdir=glob($globencoded); |
|
| 1187 | - if (! empty($listofdir) && is_array($listofdir)) |
|
| 1180 | + $file_osencoded = dol_osencode($file); // New filename encoded in OS filesystem encoding charset |
|
| 1181 | + if (empty($disableglob) && !empty($file_osencoded)) |
|
| 1182 | + { |
|
| 1183 | + $ok = true; |
|
| 1184 | + $globencoded = str_replace('[', '\[', $file_osencoded); |
|
| 1185 | + $globencoded = str_replace(']', '\]', $globencoded); |
|
| 1186 | + $listofdir = glob($globencoded); |
|
| 1187 | + if (!empty($listofdir) && is_array($listofdir)) |
|
| 1188 | 1188 | { |
| 1189 | 1189 | foreach ($listofdir as $filename) |
| 1190 | 1190 | { |
| 1191 | - if ($nophperrors) $ok=@unlink($filename); |
|
| 1192 | - else $ok=unlink($filename); |
|
| 1191 | + if ($nophperrors) $ok = @unlink($filename); |
|
| 1192 | + else $ok = unlink($filename); |
|
| 1193 | 1193 | if ($ok) |
| 1194 | 1194 | { |
| 1195 | 1195 | dol_syslog("Removed file ".$filename, LOG_DEBUG); |
| 1196 | 1196 | |
| 1197 | 1197 | // Delete entry into ecm database |
| 1198 | - $rel_filetodelete = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $filename); |
|
| 1199 | - if (! preg_match('/(\/temp\/|\/thumbs\/|\.meta$)/', $rel_filetodelete)) // If not a tmp file |
|
| 1198 | + $rel_filetodelete = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $filename); |
|
| 1199 | + if (!preg_match('/(\/temp\/|\/thumbs\/|\.meta$)/', $rel_filetodelete)) // If not a tmp file |
|
| 1200 | 1200 | { |
| 1201 | 1201 | $rel_filetodelete = preg_replace('/^[\\/]/', '', $rel_filetodelete); |
| 1202 | 1202 | |
@@ -1204,7 +1204,7 @@ discard block |
||
| 1204 | 1204 | { |
| 1205 | 1205 | dol_syslog("Try to remove also entries in database for full relative path = ".$rel_filetodelete, LOG_DEBUG); |
| 1206 | 1206 | include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; |
| 1207 | - $ecmfile=new EcmFiles($db); |
|
| 1207 | + $ecmfile = new EcmFiles($db); |
|
| 1208 | 1208 | $result = $ecmfile->fetch(0, '', $rel_filetodelete); |
| 1209 | 1209 | if ($result >= 0 && $ecmfile->id > 0) |
| 1210 | 1210 | { |
@@ -1226,9 +1226,9 @@ discard block |
||
| 1226 | 1226 | } |
| 1227 | 1227 | else |
| 1228 | 1228 | { |
| 1229 | - $ok=false; |
|
| 1230 | - if ($nophperrors) $ok=@unlink($file_osencoded); |
|
| 1231 | - else $ok=unlink($file_osencoded); |
|
| 1229 | + $ok = false; |
|
| 1230 | + if ($nophperrors) $ok = @unlink($file_osencoded); |
|
| 1231 | + else $ok = unlink($file_osencoded); |
|
| 1232 | 1232 | if ($ok) dol_syslog("Removed file ".$file_osencoded, LOG_DEBUG); |
| 1233 | 1233 | else dol_syslog("Failed to remove file ".$file_osencoded, LOG_WARNING); |
| 1234 | 1234 | } |
@@ -1246,18 +1246,18 @@ discard block |
||
| 1246 | 1246 | * @return boolean True if success, false if error |
| 1247 | 1247 | * @see dol_delete_file dol_copy |
| 1248 | 1248 | */ |
| 1249 | -function dol_delete_dir($dir,$nophperrors=0) |
|
| 1249 | +function dol_delete_dir($dir, $nophperrors = 0) |
|
| 1250 | 1250 | { |
| 1251 | 1251 | // Security: |
| 1252 | 1252 | // We refuse transversal using .. and pipes into filenames. |
| 1253 | - if (preg_match('/\.\./',$dir) || preg_match('/[<>|]/',$dir)) |
|
| 1253 | + if (preg_match('/\.\./', $dir) || preg_match('/[<>|]/', $dir)) |
|
| 1254 | 1254 | { |
| 1255 | 1255 | dol_syslog("Refused to delete dir ".$dir, LOG_WARNING); |
| 1256 | 1256 | return false; |
| 1257 | 1257 | } |
| 1258 | 1258 | |
| 1259 | - $dir_osencoded=dol_osencode($dir); |
|
| 1260 | - return ($nophperrors?@rmdir($dir_osencoded):rmdir($dir_osencoded)); |
|
| 1259 | + $dir_osencoded = dol_osencode($dir); |
|
| 1260 | + return ($nophperrors ? @rmdir($dir_osencoded) : rmdir($dir_osencoded)); |
|
| 1261 | 1261 | } |
| 1262 | 1262 | |
| 1263 | 1263 | /** |
@@ -1270,27 +1270,27 @@ discard block |
||
| 1270 | 1270 | * @param int $countdeleted Counter to count nb of elements found really deleted |
| 1271 | 1271 | * @return int Number of files and directory we try to remove. NB really removed is returned into var by reference $countdeleted. |
| 1272 | 1272 | */ |
| 1273 | -function dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0) |
|
| 1273 | +function dol_delete_dir_recursive($dir, $count = 0, $nophperrors = 0, $onlysub = 0, &$countdeleted = 0) |
|
| 1274 | 1274 | { |
| 1275 | - dol_syslog("functions.lib:dol_delete_dir_recursive ".$dir,LOG_DEBUG); |
|
| 1275 | + dol_syslog("functions.lib:dol_delete_dir_recursive ".$dir, LOG_DEBUG); |
|
| 1276 | 1276 | if (dol_is_dir($dir)) |
| 1277 | 1277 | { |
| 1278 | - $dir_osencoded=dol_osencode($dir); |
|
| 1278 | + $dir_osencoded = dol_osencode($dir); |
|
| 1279 | 1279 | if ($handle = opendir("$dir_osencoded")) |
| 1280 | 1280 | { |
| 1281 | 1281 | while (false !== ($item = readdir($handle))) |
| 1282 | 1282 | { |
| 1283 | - if (! utf8_check($item)) $item=utf8_encode($item); // should be useless |
|
| 1283 | + if (!utf8_check($item)) $item = utf8_encode($item); // should be useless |
|
| 1284 | 1284 | |
| 1285 | 1285 | if ($item != "." && $item != "..") |
| 1286 | 1286 | { |
| 1287 | - if (is_dir(dol_osencode("$dir/$item")) && ! is_link(dol_osencode("$dir/$item"))) |
|
| 1287 | + if (is_dir(dol_osencode("$dir/$item")) && !is_link(dol_osencode("$dir/$item"))) |
|
| 1288 | 1288 | { |
| 1289 | - $count=dol_delete_dir_recursive("$dir/$item", $count, $nophperrors, 0, $countdeleted); |
|
| 1289 | + $count = dol_delete_dir_recursive("$dir/$item", $count, $nophperrors, 0, $countdeleted); |
|
| 1290 | 1290 | } |
| 1291 | 1291 | else |
| 1292 | 1292 | { |
| 1293 | - $result=dol_delete_file("$dir/$item", 1, $nophperrors); |
|
| 1293 | + $result = dol_delete_file("$dir/$item", 1, $nophperrors); |
|
| 1294 | 1294 | $count++; |
| 1295 | 1295 | if ($result) $countdeleted++; |
| 1296 | 1296 | //else print 'Error on '.$item."\n"; |
@@ -1301,7 +1301,7 @@ discard block |
||
| 1301 | 1301 | |
| 1302 | 1302 | if (empty($onlysub)) |
| 1303 | 1303 | { |
| 1304 | - $result=dol_delete_dir($dir, $nophperrors); |
|
| 1304 | + $result = dol_delete_dir($dir, $nophperrors); |
|
| 1305 | 1305 | $count++; |
| 1306 | 1306 | if ($result) $countdeleted++; |
| 1307 | 1307 | //else print 'Error on '.$dir."\n"; |
@@ -1323,7 +1323,7 @@ discard block |
||
| 1323 | 1323 | */ |
| 1324 | 1324 | function dol_delete_preview($object) |
| 1325 | 1325 | { |
| 1326 | - global $langs,$conf; |
|
| 1326 | + global $langs, $conf; |
|
| 1327 | 1327 | |
| 1328 | 1328 | // Define parent dir of elements |
| 1329 | 1329 | $element = $object->element; |
@@ -1334,54 +1334,54 @@ discard block |
||
| 1334 | 1334 | elseif ($object->element == 'shipping') $dir = $conf->expedition->dir_output.'/sending'; |
| 1335 | 1335 | elseif ($object->element == 'delivery') $dir = $conf->expedition->dir_output.'/receipt'; |
| 1336 | 1336 | elseif ($object->element == 'fichinter') $dir = $conf->ficheinter->dir_output; |
| 1337 | - else $dir=empty($conf->$element->dir_output)?'':$conf->$element->dir_output; |
|
| 1337 | + else $dir = empty($conf->$element->dir_output) ? '' : $conf->$element->dir_output; |
|
| 1338 | 1338 | |
| 1339 | 1339 | if (empty($dir)) return 'ErrorObjectNoSupportedByFunction'; |
| 1340 | 1340 | |
| 1341 | 1341 | $refsan = dol_sanitizeFileName($object->ref); |
| 1342 | - $dir = $dir . "/" . $refsan ; |
|
| 1343 | - $filepreviewnew = $dir . "/" . $refsan . ".pdf_preview.png"; |
|
| 1344 | - $filepreviewnewbis = $dir . "/" . $refsan . ".pdf_preview-0.png"; |
|
| 1345 | - $filepreviewold = $dir . "/" . $refsan . ".pdf.png"; |
|
| 1342 | + $dir = $dir."/".$refsan; |
|
| 1343 | + $filepreviewnew = $dir."/".$refsan.".pdf_preview.png"; |
|
| 1344 | + $filepreviewnewbis = $dir."/".$refsan.".pdf_preview-0.png"; |
|
| 1345 | + $filepreviewold = $dir."/".$refsan.".pdf.png"; |
|
| 1346 | 1346 | |
| 1347 | 1347 | // For new preview files |
| 1348 | 1348 | if (file_exists($filepreviewnew) && is_writable($filepreviewnew)) |
| 1349 | 1349 | { |
| 1350 | - if (! dol_delete_file($filepreviewnew,1)) |
|
| 1350 | + if (!dol_delete_file($filepreviewnew, 1)) |
|
| 1351 | 1351 | { |
| 1352 | - $object->error=$langs->trans("ErrorFailedToDeleteFile",$filepreviewnew); |
|
| 1352 | + $object->error = $langs->trans("ErrorFailedToDeleteFile", $filepreviewnew); |
|
| 1353 | 1353 | return 0; |
| 1354 | 1354 | } |
| 1355 | 1355 | } |
| 1356 | 1356 | if (file_exists($filepreviewnewbis) && is_writable($filepreviewnewbis)) |
| 1357 | 1357 | { |
| 1358 | - if (! dol_delete_file($filepreviewnewbis,1)) |
|
| 1358 | + if (!dol_delete_file($filepreviewnewbis, 1)) |
|
| 1359 | 1359 | { |
| 1360 | - $object->error=$langs->trans("ErrorFailedToDeleteFile",$filepreviewnewbis); |
|
| 1360 | + $object->error = $langs->trans("ErrorFailedToDeleteFile", $filepreviewnewbis); |
|
| 1361 | 1361 | return 0; |
| 1362 | 1362 | } |
| 1363 | 1363 | } |
| 1364 | 1364 | // For old preview files |
| 1365 | 1365 | if (file_exists($filepreviewold) && is_writable($filepreviewold)) |
| 1366 | 1366 | { |
| 1367 | - if (! dol_delete_file($filepreviewold,1)) |
|
| 1367 | + if (!dol_delete_file($filepreviewold, 1)) |
|
| 1368 | 1368 | { |
| 1369 | - $object->error=$langs->trans("ErrorFailedToDeleteFile",$filepreviewold); |
|
| 1369 | + $object->error = $langs->trans("ErrorFailedToDeleteFile", $filepreviewold); |
|
| 1370 | 1370 | return 0; |
| 1371 | 1371 | } |
| 1372 | 1372 | } |
| 1373 | 1373 | else |
| 1374 | 1374 | { |
| 1375 | - $multiple = $filepreviewold . "."; |
|
| 1375 | + $multiple = $filepreviewold."."; |
|
| 1376 | 1376 | for ($i = 0; $i < 20; $i++) |
| 1377 | 1377 | { |
| 1378 | 1378 | $preview = $multiple.$i; |
| 1379 | 1379 | |
| 1380 | 1380 | if (file_exists($preview) && is_writable($preview)) |
| 1381 | 1381 | { |
| 1382 | - if ( ! dol_delete_file($preview,1) ) |
|
| 1382 | + if (!dol_delete_file($preview, 1)) |
|
| 1383 | 1383 | { |
| 1384 | - $object->error=$langs->trans("ErrorFailedToOpenFile",$preview); |
|
| 1384 | + $object->error = $langs->trans("ErrorFailedToOpenFile", $preview); |
|
| 1385 | 1385 | return 0; |
| 1386 | 1386 | } |
| 1387 | 1387 | } |
@@ -1404,10 +1404,10 @@ discard block |
||
| 1404 | 1404 | global $conf; |
| 1405 | 1405 | |
| 1406 | 1406 | // Create meta file |
| 1407 | - if (empty($conf->global->MAIN_DOC_CREATE_METAFILE)) return 0; // By default, no metafile. |
|
| 1407 | + if (empty($conf->global->MAIN_DOC_CREATE_METAFILE)) return 0; // By default, no metafile. |
|
| 1408 | 1408 | |
| 1409 | 1409 | // Define parent dir of elements |
| 1410 | - $element=$object->element; |
|
| 1410 | + $element = $object->element; |
|
| 1411 | 1411 | |
| 1412 | 1412 | if ($object->element == 'order_supplier') $dir = $conf->fournisseur->dir_output.'/commande'; |
| 1413 | 1413 | elseif ($object->element == 'invoice_supplier') $dir = $conf->fournisseur->dir_output.'/facture'; |
@@ -1415,17 +1415,17 @@ discard block |
||
| 1415 | 1415 | elseif ($object->element == 'shipping') $dir = $conf->expedition->dir_output.'/sending'; |
| 1416 | 1416 | elseif ($object->element == 'delivery') $dir = $conf->expedition->dir_output.'/receipt'; |
| 1417 | 1417 | elseif ($object->element == 'fichinter') $dir = $conf->ficheinter->dir_output; |
| 1418 | - else $dir=empty($conf->$element->dir_output)?'':$conf->$element->dir_output; |
|
| 1418 | + else $dir = empty($conf->$element->dir_output) ? '' : $conf->$element->dir_output; |
|
| 1419 | 1419 | |
| 1420 | 1420 | if ($dir) |
| 1421 | 1421 | { |
| 1422 | 1422 | $object->fetch_thirdparty(); |
| 1423 | 1423 | |
| 1424 | 1424 | $objectref = dol_sanitizeFileName($object->ref); |
| 1425 | - $dir = $dir . "/" . $objectref; |
|
| 1426 | - $file = $dir . "/" . $objectref . ".meta"; |
|
| 1425 | + $dir = $dir."/".$objectref; |
|
| 1426 | + $file = $dir."/".$objectref.".meta"; |
|
| 1427 | 1427 | |
| 1428 | - if (! is_dir($dir)) |
|
| 1428 | + if (!is_dir($dir)) |
|
| 1429 | 1429 | { |
| 1430 | 1430 | dol_mkdir($dir); |
| 1431 | 1431 | } |
@@ -1433,29 +1433,29 @@ discard block |
||
| 1433 | 1433 | if (is_dir($dir)) |
| 1434 | 1434 | { |
| 1435 | 1435 | $nblignes = count($object->lines); |
| 1436 | - $client = $object->thirdparty->name . " " . $object->thirdparty->address . " " . $object->thirdparty->zip . " " . $object->thirdparty->town; |
|
| 1437 | - $meta = "REFERENCE=\"" . $object->ref . "\" |
|
| 1438 | - DATE=\"" . dol_print_date($object->date,'') . "\" |
|
| 1439 | - NB_ITEMS=\"" . $nblignes . "\" |
|
| 1440 | - CLIENT=\"" . $client . "\" |
|
| 1441 | - AMOUNT_EXCL_TAX=\"" . $object->total_ht . "\" |
|
| 1442 | - AMOUNT=\"" . $object->total_ttc . "\"\n"; |
|
| 1443 | - |
|
| 1444 | - for ($i = 0 ; $i < $nblignes ; $i++) |
|
| 1436 | + $client = $object->thirdparty->name." ".$object->thirdparty->address." ".$object->thirdparty->zip." ".$object->thirdparty->town; |
|
| 1437 | + $meta = "REFERENCE=\"".$object->ref."\" |
|
| 1438 | + DATE=\"" . dol_print_date($object->date, '')."\" |
|
| 1439 | + NB_ITEMS=\"" . $nblignes."\" |
|
| 1440 | + CLIENT=\"" . $client."\" |
|
| 1441 | + AMOUNT_EXCL_TAX=\"" . $object->total_ht."\" |
|
| 1442 | + AMOUNT=\"" . $object->total_ttc."\"\n"; |
|
| 1443 | + |
|
| 1444 | + for ($i = 0; $i < $nblignes; $i++) |
|
| 1445 | 1445 | { |
| 1446 | 1446 | //Pour les articles |
| 1447 | - $meta .= "ITEM_" . $i . "_QUANTITY=\"" . $object->lines[$i]->qty . "\" |
|
| 1448 | - ITEM_" . $i . "_AMOUNT_WO_TAX=\"" . $object->lines[$i]->total_ht . "\" |
|
| 1449 | - ITEM_" . $i . "_VAT=\"" .$object->lines[$i]->tva_tx . "\" |
|
| 1450 | - ITEM_" . $i . "_DESCRIPTION=\"" . str_replace("\r\n","",nl2br($object->lines[$i]->desc)) . "\" |
|
| 1447 | + $meta .= "ITEM_".$i."_QUANTITY=\"".$object->lines[$i]->qty."\" |
|
| 1448 | + ITEM_" . $i."_AMOUNT_WO_TAX=\"".$object->lines[$i]->total_ht."\" |
|
| 1449 | + ITEM_" . $i."_VAT=\"".$object->lines[$i]->tva_tx."\" |
|
| 1450 | + ITEM_" . $i."_DESCRIPTION=\"".str_replace("\r\n", "", nl2br($object->lines[$i]->desc))."\" |
|
| 1451 | 1451 | "; |
| 1452 | 1452 | } |
| 1453 | 1453 | } |
| 1454 | 1454 | |
| 1455 | - $fp = fopen($file,"w"); |
|
| 1456 | - fputs($fp,$meta); |
|
| 1455 | + $fp = fopen($file, "w"); |
|
| 1456 | + fputs($fp, $meta); |
|
| 1457 | 1457 | fclose($fp); |
| 1458 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 1458 | + if (!empty($conf->global->MAIN_UMASK)) |
|
| 1459 | 1459 | @chmod($file, octdec($conf->global->MAIN_UMASK)); |
| 1460 | 1460 | |
| 1461 | 1461 | return 1; |
@@ -1478,26 +1478,26 @@ discard block |
||
| 1478 | 1478 | * @param string $trackid Track id (used to prefix name of session vars to avoid conflict) |
| 1479 | 1479 | * @return void |
| 1480 | 1480 | */ |
| 1481 | -function dol_init_file_process($pathtoscan='', $trackid='') |
|
| 1481 | +function dol_init_file_process($pathtoscan = '', $trackid = '') |
|
| 1482 | 1482 | { |
| 1483 | - $listofpaths=array(); |
|
| 1484 | - $listofnames=array(); |
|
| 1485 | - $listofmimes=array(); |
|
| 1483 | + $listofpaths = array(); |
|
| 1484 | + $listofnames = array(); |
|
| 1485 | + $listofmimes = array(); |
|
| 1486 | 1486 | |
| 1487 | 1487 | if ($pathtoscan) |
| 1488 | 1488 | { |
| 1489 | - $listoffiles=dol_dir_list($pathtoscan,'files'); |
|
| 1490 | - foreach($listoffiles as $key => $val) |
|
| 1489 | + $listoffiles = dol_dir_list($pathtoscan, 'files'); |
|
| 1490 | + foreach ($listoffiles as $key => $val) |
|
| 1491 | 1491 | { |
| 1492 | - $listofpaths[]=$val['fullname']; |
|
| 1493 | - $listofnames[]=$val['name']; |
|
| 1494 | - $listofmimes[]=dol_mimetype($val['name']); |
|
| 1492 | + $listofpaths[] = $val['fullname']; |
|
| 1493 | + $listofnames[] = $val['name']; |
|
| 1494 | + $listofmimes[] = dol_mimetype($val['name']); |
|
| 1495 | 1495 | } |
| 1496 | 1496 | } |
| 1497 | - $keytoavoidconflict = empty($trackid)?'':'-'.$trackid; |
|
| 1498 | - $_SESSION["listofpaths".$keytoavoidconflict]=join(';',$listofpaths); |
|
| 1499 | - $_SESSION["listofnames".$keytoavoidconflict]=join(';',$listofnames); |
|
| 1500 | - $_SESSION["listofmimes".$keytoavoidconflict]=join(';',$listofmimes); |
|
| 1497 | + $keytoavoidconflict = empty($trackid) ? '' : '-'.$trackid; |
|
| 1498 | + $_SESSION["listofpaths".$keytoavoidconflict] = join(';', $listofpaths); |
|
| 1499 | + $_SESSION["listofnames".$keytoavoidconflict] = join(';', $listofnames); |
|
| 1500 | + $_SESSION["listofmimes".$keytoavoidconflict] = join(';', $listofmimes); |
|
| 1501 | 1501 | } |
| 1502 | 1502 | |
| 1503 | 1503 | |
@@ -1516,13 +1516,13 @@ discard block |
||
| 1516 | 1516 | * @param int $generatethumbs 1=Generate also thumbs for uploaded image files |
| 1517 | 1517 | * @return int <=0 if KO, >0 if OK |
| 1518 | 1518 | */ |
| 1519 | -function dol_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesession=0, $varfiles='addedfile', $savingdocmask='', $link=null, $trackid='', $generatethumbs=1) |
|
| 1519 | +function dol_add_file_process($upload_dir, $allowoverwrite = 0, $donotupdatesession = 0, $varfiles = 'addedfile', $savingdocmask = '', $link = null, $trackid = '', $generatethumbs = 1) |
|
| 1520 | 1520 | { |
| 1521 | - global $db,$user,$conf,$langs; |
|
| 1521 | + global $db, $user, $conf, $langs; |
|
| 1522 | 1522 | |
| 1523 | 1523 | $res = 0; |
| 1524 | 1524 | |
| 1525 | - if (! empty($_FILES[$varfiles])) // For view $_FILES[$varfiles]['error'] |
|
| 1525 | + if (!empty($_FILES[$varfiles])) // For view $_FILES[$varfiles]['error'] |
|
| 1526 | 1526 | { |
| 1527 | 1527 | dol_syslog('dol_add_file_process upload_dir='.$upload_dir.' allowoverwrite='.$allowoverwrite.' donotupdatesession='.$donotupdatesession.' savingdocmask='.$savingdocmask, LOG_DEBUG); |
| 1528 | 1528 | if (dol_mkdir($upload_dir) >= 0) |
@@ -1541,13 +1541,13 @@ discard block |
||
| 1541 | 1541 | for ($i = 0; $i < $nbfile; $i++) |
| 1542 | 1542 | { |
| 1543 | 1543 | // Define $destfull (path to file including filename) and $destfile (only filename) |
| 1544 | - $destfull=$upload_dir . "/" . $TFile['name'][$i]; |
|
| 1545 | - $destfile=$TFile['name'][$i]; |
|
| 1544 | + $destfull = $upload_dir."/".$TFile['name'][$i]; |
|
| 1545 | + $destfile = $TFile['name'][$i]; |
|
| 1546 | 1546 | |
| 1547 | 1547 | if ($savingdocmask) |
| 1548 | 1548 | { |
| 1549 | - $destfull=$upload_dir . "/" . preg_replace('/__file__/',$TFile['name'][$i],$savingdocmask); |
|
| 1550 | - $destfile=preg_replace('/__file__/',$TFile['name'][$i],$savingdocmask); |
|
| 1549 | + $destfull = $upload_dir."/".preg_replace('/__file__/', $TFile['name'][$i], $savingdocmask); |
|
| 1550 | + $destfile = preg_replace('/__file__/', $TFile['name'][$i], $savingdocmask); |
|
| 1551 | 1551 | } |
| 1552 | 1552 | |
| 1553 | 1553 | // dol_sanitizeFileName the file name and lowercase extension |
@@ -1608,7 +1608,7 @@ discard block |
||
| 1608 | 1608 | { |
| 1609 | 1609 | setEventMessages($langs->trans("ErrorFileNotUploaded"), null, 'errors'); |
| 1610 | 1610 | } |
| 1611 | - else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus |
|
| 1611 | + else if (preg_match('/ErrorFileIsInfectedWithAVirus/', $resupload)) // Files infected by a virus |
|
| 1612 | 1612 | { |
| 1613 | 1613 | setEventMessages($langs->trans("ErrorFileIsInfectedWithAVirus"), null, 'errors'); |
| 1614 | 1614 | } |
@@ -1625,7 +1625,7 @@ discard block |
||
| 1625 | 1625 | } |
| 1626 | 1626 | } |
| 1627 | 1627 | } elseif ($link) { |
| 1628 | - require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php'; |
|
| 1628 | + require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php'; |
|
| 1629 | 1629 | $linkObject = new Link($db); |
| 1630 | 1630 | $linkObject->entity = $conf->entity; |
| 1631 | 1631 | $linkObject->url = $link; |
@@ -1660,33 +1660,33 @@ discard block |
||
| 1660 | 1660 | * @param string $trackid Track id (used to prefix name of session vars to avoid conflict) |
| 1661 | 1661 | * @return void |
| 1662 | 1662 | */ |
| 1663 | -function dol_remove_file_process($filenb,$donotupdatesession=0,$donotdeletefile=1,$trackid='') |
|
| 1663 | +function dol_remove_file_process($filenb, $donotupdatesession = 0, $donotdeletefile = 1, $trackid = '') |
|
| 1664 | 1664 | { |
| 1665 | - global $db,$user,$conf,$langs,$_FILES; |
|
| 1665 | + global $db, $user, $conf, $langs, $_FILES; |
|
| 1666 | 1666 | |
| 1667 | - $keytodelete=$filenb; |
|
| 1667 | + $keytodelete = $filenb; |
|
| 1668 | 1668 | $keytodelete--; |
| 1669 | 1669 | |
| 1670 | - $listofpaths=array(); |
|
| 1671 | - $listofnames=array(); |
|
| 1672 | - $listofmimes=array(); |
|
| 1673 | - $keytoavoidconflict = empty($trackid)?'':'-'.$trackid; |
|
| 1674 | - if (! empty($_SESSION["listofpaths".$keytoavoidconflict])) $listofpaths=explode(';',$_SESSION["listofpaths".$keytoavoidconflict]); |
|
| 1675 | - if (! empty($_SESSION["listofnames".$keytoavoidconflict])) $listofnames=explode(';',$_SESSION["listofnames".$keytoavoidconflict]); |
|
| 1676 | - if (! empty($_SESSION["listofmimes".$keytoavoidconflict])) $listofmimes=explode(';',$_SESSION["listofmimes".$keytoavoidconflict]); |
|
| 1670 | + $listofpaths = array(); |
|
| 1671 | + $listofnames = array(); |
|
| 1672 | + $listofmimes = array(); |
|
| 1673 | + $keytoavoidconflict = empty($trackid) ? '' : '-'.$trackid; |
|
| 1674 | + if (!empty($_SESSION["listofpaths".$keytoavoidconflict])) $listofpaths = explode(';', $_SESSION["listofpaths".$keytoavoidconflict]); |
|
| 1675 | + if (!empty($_SESSION["listofnames".$keytoavoidconflict])) $listofnames = explode(';', $_SESSION["listofnames".$keytoavoidconflict]); |
|
| 1676 | + if (!empty($_SESSION["listofmimes".$keytoavoidconflict])) $listofmimes = explode(';', $_SESSION["listofmimes".$keytoavoidconflict]); |
|
| 1677 | 1677 | |
| 1678 | 1678 | if ($keytodelete >= 0) |
| 1679 | 1679 | { |
| 1680 | - $pathtodelete=$listofpaths[$keytodelete]; |
|
| 1681 | - $filetodelete=$listofnames[$keytodelete]; |
|
| 1682 | - if (empty($donotdeletefile)) $result = dol_delete_file($pathtodelete,1); // The delete of ecm database is inside the function dol_delete_file |
|
| 1683 | - else $result=0; |
|
| 1680 | + $pathtodelete = $listofpaths[$keytodelete]; |
|
| 1681 | + $filetodelete = $listofnames[$keytodelete]; |
|
| 1682 | + if (empty($donotdeletefile)) $result = dol_delete_file($pathtodelete, 1); // The delete of ecm database is inside the function dol_delete_file |
|
| 1683 | + else $result = 0; |
|
| 1684 | 1684 | if ($result >= 0) |
| 1685 | 1685 | { |
| 1686 | 1686 | if (empty($donotdeletefile)) |
| 1687 | 1687 | { |
| 1688 | 1688 | $langs->load("other"); |
| 1689 | - setEventMessages($langs->trans("FileWasRemoved",$filetodelete), null, 'mesgs'); |
|
| 1689 | + setEventMessages($langs->trans("FileWasRemoved", $filetodelete), null, 'mesgs'); |
|
| 1690 | 1690 | } |
| 1691 | 1691 | if (empty($donotupdatesession)) |
| 1692 | 1692 | { |
@@ -1712,29 +1712,29 @@ discard block |
||
| 1712 | 1712 | * @param int $setsharekey Set also the share key |
| 1713 | 1713 | * @return int <0 if KO, 0 if nothing done, >0 if OK |
| 1714 | 1714 | */ |
| 1715 | -function addFileIntoDatabaseIndex($dir, $file, $fullpathorig='', $mode='uploaded', $setsharekey=0) |
|
| 1715 | +function addFileIntoDatabaseIndex($dir, $file, $fullpathorig = '', $mode = 'uploaded', $setsharekey = 0) |
|
| 1716 | 1716 | { |
| 1717 | 1717 | global $db, $user; |
| 1718 | 1718 | |
| 1719 | 1719 | $result = 0; |
| 1720 | 1720 | |
| 1721 | - $rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $dir); |
|
| 1721 | + $rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $dir); |
|
| 1722 | 1722 | |
| 1723 | - if (! preg_match('/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) // If not a tmp dir |
|
| 1723 | + if (!preg_match('/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) // If not a tmp dir |
|
| 1724 | 1724 | { |
| 1725 | 1725 | $filename = basename($file); |
| 1726 | 1726 | $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir); |
| 1727 | 1727 | $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir); |
| 1728 | 1728 | |
| 1729 | 1729 | include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; |
| 1730 | - $ecmfile=new EcmFiles($db); |
|
| 1730 | + $ecmfile = new EcmFiles($db); |
|
| 1731 | 1731 | $ecmfile->filepath = $rel_dir; |
| 1732 | 1732 | $ecmfile->filename = $filename; |
| 1733 | - $ecmfile->label = md5_file(dol_osencode($dir.'/'.$file)); // MD5 of file content |
|
| 1733 | + $ecmfile->label = md5_file(dol_osencode($dir.'/'.$file)); // MD5 of file content |
|
| 1734 | 1734 | $ecmfile->fullpath_orig = $fullpathorig; |
| 1735 | 1735 | $ecmfile->gen_or_uploaded = $mode; |
| 1736 | - $ecmfile->description = ''; // indexed content |
|
| 1737 | - $ecmfile->keyword = ''; // keyword content |
|
| 1736 | + $ecmfile->description = ''; // indexed content |
|
| 1737 | + $ecmfile->keyword = ''; // keyword content |
|
| 1738 | 1738 | if ($setsharekey) |
| 1739 | 1739 | { |
| 1740 | 1740 | require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; |
@@ -1760,7 +1760,7 @@ discard block |
||
| 1760 | 1760 | * @param string $mode How file was created ('uploaded', 'generated', ...) |
| 1761 | 1761 | * @return int <0 if KO, 0 if nothing done, >0 if OK |
| 1762 | 1762 | */ |
| 1763 | -function deleteFilesIntoDatabaseIndex($dir, $file, $mode='uploaded') |
|
| 1763 | +function deleteFilesIntoDatabaseIndex($dir, $file, $mode = 'uploaded') |
|
| 1764 | 1764 | { |
| 1765 | 1765 | global $conf, $db, $user; |
| 1766 | 1766 | |
@@ -1774,32 +1774,32 @@ discard block |
||
| 1774 | 1774 | |
| 1775 | 1775 | $db->begin(); |
| 1776 | 1776 | |
| 1777 | - $rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $dir); |
|
| 1777 | + $rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $dir); |
|
| 1778 | 1778 | |
| 1779 | 1779 | $filename = basename($file); |
| 1780 | 1780 | $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir); |
| 1781 | 1781 | $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir); |
| 1782 | 1782 | |
| 1783 | - if (! $error) |
|
| 1783 | + if (!$error) |
|
| 1784 | 1784 | { |
| 1785 | - $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . 'ecm_files'; |
|
| 1786 | - $sql.= ' WHERE entity = '.$conf->entity; |
|
| 1787 | - $sql.= " AND filepath = '" . $db->escape($rel_dir) . "'"; |
|
| 1788 | - if ($file) $sql.= " AND filename = '" . $db->escape($file) . "'"; |
|
| 1789 | - if ($mode) $sql.= " AND gen_or_uploaded = '" . $db->escape($mode) . "'"; |
|
| 1785 | + $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'ecm_files'; |
|
| 1786 | + $sql .= ' WHERE entity = '.$conf->entity; |
|
| 1787 | + $sql .= " AND filepath = '".$db->escape($rel_dir)."'"; |
|
| 1788 | + if ($file) $sql .= " AND filename = '".$db->escape($file)."'"; |
|
| 1789 | + if ($mode) $sql .= " AND gen_or_uploaded = '".$db->escape($mode)."'"; |
|
| 1790 | 1790 | |
| 1791 | 1791 | $resql = $db->query($sql); |
| 1792 | 1792 | if (!$resql) |
| 1793 | 1793 | { |
| 1794 | 1794 | $error++; |
| 1795 | - dol_syslog(__METHOD__ . ' ' . $db->lasterror(), LOG_ERR); |
|
| 1795 | + dol_syslog(__METHOD__.' '.$db->lasterror(), LOG_ERR); |
|
| 1796 | 1796 | } |
| 1797 | 1797 | } |
| 1798 | 1798 | |
| 1799 | 1799 | // Commit or rollback |
| 1800 | 1800 | if ($error) { |
| 1801 | 1801 | $db->rollback(); |
| 1802 | - return - 1 * $error; |
|
| 1802 | + return -1 * $error; |
|
| 1803 | 1803 | } else { |
| 1804 | 1804 | $db->commit(); |
| 1805 | 1805 | return 1; |
@@ -1816,16 +1816,16 @@ discard block |
||
| 1816 | 1816 | * @param string $fileoutput Output filename |
| 1817 | 1817 | * @return int <0 if KO, 0=Nothing done, >0 if OK |
| 1818 | 1818 | */ |
| 1819 | -function dol_convert_file($fileinput, $ext='png', $fileoutput='') |
|
| 1819 | +function dol_convert_file($fileinput, $ext = 'png', $fileoutput = '') |
|
| 1820 | 1820 | { |
| 1821 | 1821 | global $langs; |
| 1822 | 1822 | |
| 1823 | 1823 | if (class_exists('Imagick')) |
| 1824 | 1824 | { |
| 1825 | - $image=new Imagick(); |
|
| 1825 | + $image = new Imagick(); |
|
| 1826 | 1826 | try { |
| 1827 | 1827 | $ret = $image->readImage($fileinput); |
| 1828 | - } catch(Exception $e) { |
|
| 1828 | + } catch (Exception $e) { |
|
| 1829 | 1829 | dol_syslog("Failed to read image using Imagick. Try to install package 'apt-get install ghostscript'.", LOG_WARNING); |
| 1830 | 1830 | return 0; |
| 1831 | 1831 | } |
@@ -1834,11 +1834,11 @@ discard block |
||
| 1834 | 1834 | $ret = $image->setImageFormat($ext); |
| 1835 | 1835 | if ($ret) |
| 1836 | 1836 | { |
| 1837 | - if (empty($fileoutput)) $fileoutput=$fileinput.".".$ext; |
|
| 1837 | + if (empty($fileoutput)) $fileoutput = $fileinput.".".$ext; |
|
| 1838 | 1838 | |
| 1839 | 1839 | $count = $image->getNumberImages(); |
| 1840 | 1840 | |
| 1841 | - if (! dol_is_file($fileoutput) || is_writeable($fileoutput)) |
|
| 1841 | + if (!dol_is_file($fileoutput) || is_writeable($fileoutput)) |
|
| 1842 | 1842 | { |
| 1843 | 1843 | $ret = $image->writeImages($fileoutput, true); |
| 1844 | 1844 | } |
@@ -1874,20 +1874,20 @@ discard block |
||
| 1874 | 1874 | * @param string $mode 'gz' or 'bz' or 'zip' |
| 1875 | 1875 | * @return int <0 if KO, >0 if OK |
| 1876 | 1876 | */ |
| 1877 | -function dol_compress_file($inputfile, $outputfile, $mode="gz") |
|
| 1877 | +function dol_compress_file($inputfile, $outputfile, $mode = "gz") |
|
| 1878 | 1878 | { |
| 1879 | - $foundhandler=0; |
|
| 1879 | + $foundhandler = 0; |
|
| 1880 | 1880 | |
| 1881 | 1881 | try |
| 1882 | 1882 | { |
| 1883 | 1883 | $data = implode("", file(dol_osencode($inputfile))); |
| 1884 | - if ($mode == 'gz') { $foundhandler=1; $compressdata = gzencode($data, 9); } |
|
| 1885 | - elseif ($mode == 'bz') { $foundhandler=1; $compressdata = bzcompress($data, 9); } |
|
| 1884 | + if ($mode == 'gz') { $foundhandler = 1; $compressdata = gzencode($data, 9); } |
|
| 1885 | + elseif ($mode == 'bz') { $foundhandler = 1; $compressdata = bzcompress($data, 9); } |
|
| 1886 | 1886 | elseif ($mode == 'zip') |
| 1887 | 1887 | { |
| 1888 | 1888 | if (defined('ODTPHP_PATHTOPCLZIP')) |
| 1889 | 1889 | { |
| 1890 | - $foundhandler=1; |
|
| 1890 | + $foundhandler = 1; |
|
| 1891 | 1891 | |
| 1892 | 1892 | include_once ODTPHP_PATHTOPCLZIP.'/pclzip.lib.php'; |
| 1893 | 1893 | $archive = new PclZip($outputfile); |
@@ -1906,7 +1906,7 @@ discard block |
||
| 1906 | 1906 | } |
| 1907 | 1907 | else |
| 1908 | 1908 | { |
| 1909 | - dol_syslog("Try to zip with format ".$mode." with no handler for this format",LOG_ERR); |
|
| 1909 | + dol_syslog("Try to zip with format ".$mode." with no handler for this format", LOG_ERR); |
|
| 1910 | 1910 | return -2; |
| 1911 | 1911 | } |
| 1912 | 1912 | } |
@@ -1914,8 +1914,8 @@ discard block |
||
| 1914 | 1914 | { |
| 1915 | 1915 | global $langs, $errormsg; |
| 1916 | 1916 | $langs->load("errors"); |
| 1917 | - dol_syslog("Failed to open file ".$outputfile,LOG_ERR); |
|
| 1918 | - $errormsg=$langs->trans("ErrorFailedToWriteInDir"); |
|
| 1917 | + dol_syslog("Failed to open file ".$outputfile, LOG_ERR); |
|
| 1918 | + $errormsg = $langs->trans("ErrorFailedToWriteInDir"); |
|
| 1919 | 1919 | return -1; |
| 1920 | 1920 | } |
| 1921 | 1921 | } |
@@ -1927,7 +1927,7 @@ discard block |
||
| 1927 | 1927 | * @param string $outputdir Target dir name |
| 1928 | 1928 | * @return array array('error'=>'Error code') or array() if no error |
| 1929 | 1929 | */ |
| 1930 | -function dol_uncompress($inputfile,$outputdir) |
|
| 1930 | +function dol_uncompress($inputfile, $outputdir) |
|
| 1931 | 1931 | { |
| 1932 | 1932 | global $langs; |
| 1933 | 1933 | |
@@ -1936,20 +1936,20 @@ discard block |
||
| 1936 | 1936 | dol_syslog("Constant ODTPHP_PATHTOPCLZIP for pclzip library is set to ".ODTPHP_PATHTOPCLZIP.", so we use Pclzip to unzip into ".$outputdir); |
| 1937 | 1937 | include_once ODTPHP_PATHTOPCLZIP.'/pclzip.lib.php'; |
| 1938 | 1938 | $archive = new PclZip($inputfile); |
| 1939 | - $result=$archive->extract(PCLZIP_OPT_PATH, $outputdir); |
|
| 1939 | + $result = $archive->extract(PCLZIP_OPT_PATH, $outputdir); |
|
| 1940 | 1940 | //var_dump($result); |
| 1941 | - if (! is_array($result) && $result <= 0) return array('error'=>$archive->errorInfo(true)); |
|
| 1941 | + if (!is_array($result) && $result <= 0) return array('error'=>$archive->errorInfo(true)); |
|
| 1942 | 1942 | else |
| 1943 | 1943 | { |
| 1944 | - $ok=1; $errmsg=''; |
|
| 1944 | + $ok = 1; $errmsg = ''; |
|
| 1945 | 1945 | // Loop on each file to check result for unzipping file |
| 1946 | - foreach($result as $key => $val) |
|
| 1946 | + foreach ($result as $key => $val) |
|
| 1947 | 1947 | { |
| 1948 | 1948 | if ($val['status'] == 'path_creation_fail') |
| 1949 | 1949 | { |
| 1950 | 1950 | $langs->load("errors"); |
| 1951 | - $ok=0; |
|
| 1952 | - $errmsg=$langs->trans("ErrorFailToCreateDir", $val['filename']); |
|
| 1951 | + $ok = 0; |
|
| 1952 | + $errmsg = $langs->trans("ErrorFailToCreateDir", $val['filename']); |
|
| 1953 | 1953 | break; |
| 1954 | 1954 | } |
| 1955 | 1955 | } |
@@ -1988,24 +1988,24 @@ discard block |
||
| 1988 | 1988 | * @param string $mode 'zip' |
| 1989 | 1989 | * @return int <0 if KO, >0 if OK |
| 1990 | 1990 | */ |
| 1991 | -function dol_compress_dir($inputdir, $outputfile, $mode="zip") |
|
| 1991 | +function dol_compress_dir($inputdir, $outputfile, $mode = "zip") |
|
| 1992 | 1992 | { |
| 1993 | - $foundhandler=0; |
|
| 1993 | + $foundhandler = 0; |
|
| 1994 | 1994 | |
| 1995 | 1995 | dol_syslog("Try to zip dir ".$inputdir." into ".$outputdir." mode=".$mode); |
| 1996 | 1996 | |
| 1997 | - if (! dol_is_dir(dirname($outputfile)) || ! is_writable(dirname($outputfile))) |
|
| 1997 | + if (!dol_is_dir(dirname($outputfile)) || !is_writable(dirname($outputfile))) |
|
| 1998 | 1998 | { |
| 1999 | 1999 | global $langs, $errormsg; |
| 2000 | 2000 | $langs->load("errors"); |
| 2001 | - $errormsg=$langs->trans("ErrorFailedToWriteInDir",$outputfile); |
|
| 2001 | + $errormsg = $langs->trans("ErrorFailedToWriteInDir", $outputfile); |
|
| 2002 | 2002 | return -3; |
| 2003 | 2003 | } |
| 2004 | 2004 | |
| 2005 | 2005 | try |
| 2006 | 2006 | { |
| 2007 | - if ($mode == 'gz') { $foundhandler=0; } |
|
| 2008 | - elseif ($mode == 'bz') { $foundhandler=0; } |
|
| 2007 | + if ($mode == 'gz') { $foundhandler = 0; } |
|
| 2008 | + elseif ($mode == 'bz') { $foundhandler = 0; } |
|
| 2009 | 2009 | elseif ($mode == 'zip') |
| 2010 | 2010 | { |
| 2011 | 2011 | /*if (defined('ODTPHP_PATHTOPCLZIP')) |
@@ -2021,7 +2021,7 @@ discard block |
||
| 2021 | 2021 | else*/ |
| 2022 | 2022 | if (class_exists('ZipArchive')) |
| 2023 | 2023 | { |
| 2024 | - $foundhandler=1; |
|
| 2024 | + $foundhandler = 1; |
|
| 2025 | 2025 | |
| 2026 | 2026 | // Initialize archive object |
| 2027 | 2027 | $zip = new ZipArchive(); |
@@ -2055,9 +2055,9 @@ discard block |
||
| 2055 | 2055 | } |
| 2056 | 2056 | } |
| 2057 | 2057 | |
| 2058 | - if (! $foundhandler) |
|
| 2058 | + if (!$foundhandler) |
|
| 2059 | 2059 | { |
| 2060 | - dol_syslog("Try to zip with format ".$mode." with no handler for this format",LOG_ERR); |
|
| 2060 | + dol_syslog("Try to zip with format ".$mode." with no handler for this format", LOG_ERR); |
|
| 2061 | 2061 | return -2; |
| 2062 | 2062 | } |
| 2063 | 2063 | else |
@@ -2071,7 +2071,7 @@ discard block |
||
| 2071 | 2071 | $langs->load("errors"); |
| 2072 | 2072 | dol_syslog("Failed to open file ".$outputfile, LOG_ERR); |
| 2073 | 2073 | dol_syslog($e->getMessage(), LOG_ERR); |
| 2074 | - $errormsg=$langs->trans("ErrorFailedToWriteInDir",$outputfile); |
|
| 2074 | + $errormsg = $langs->trans("ErrorFailedToWriteInDir", $outputfile); |
|
| 2075 | 2075 | return -1; |
| 2076 | 2076 | } |
| 2077 | 2077 | } |
@@ -2088,9 +2088,9 @@ discard block |
||
| 2088 | 2088 | * @param int $mode 0=Return array minimum keys loaded (faster), 1=Force all keys like date and size to be loaded (slower), 2=Force load of date only, 3=Force load of size only |
| 2089 | 2089 | * @return string Full path to most recent file |
| 2090 | 2090 | */ |
| 2091 | -function dol_most_recent_file($dir,$regexfilter='',$excludefilter=array('(\.meta|_preview.*\.png)$','^\.'),$nohook=false,$mode='') |
|
| 2091 | +function dol_most_recent_file($dir, $regexfilter = '', $excludefilter = array('(\.meta|_preview.*\.png)$', '^\.'), $nohook = false, $mode = '') |
|
| 2092 | 2092 | { |
| 2093 | - $tmparray=dol_dir_list($dir,'files',0,$regexfilter,$excludefilter,'date',SORT_DESC,$mode,$nohook); |
|
| 2093 | + $tmparray = dol_dir_list($dir, 'files', 0, $regexfilter, $excludefilter, 'date', SORT_DESC, $mode, $nohook); |
|
| 2094 | 2094 | return $tmparray[0]; |
| 2095 | 2095 | } |
| 2096 | 2096 | |
@@ -2106,278 +2106,278 @@ discard block |
||
| 2106 | 2106 | * @return mixed Array with access information : 'accessallowed' & 'sqlprotectagainstexternals' & 'original_file' (as a full path name) |
| 2107 | 2107 | * @see restrictedArea |
| 2108 | 2108 | */ |
| 2109 | -function dol_check_secure_access_document($modulepart, $original_file, $entity, $fuser='', $refname='', $mode='read') |
|
| 2109 | +function dol_check_secure_access_document($modulepart, $original_file, $entity, $fuser = '', $refname = '', $mode = 'read') |
|
| 2110 | 2110 | { |
| 2111 | 2111 | global $conf, $db, $user; |
| 2112 | 2112 | global $dolibarr_main_data_root, $dolibarr_main_document_root_alt; |
| 2113 | 2113 | |
| 2114 | - if (! is_object($fuser)) $fuser=$user; |
|
| 2114 | + if (!is_object($fuser)) $fuser = $user; |
|
| 2115 | 2115 | |
| 2116 | 2116 | if (empty($modulepart)) return 'ErrorBadParameter'; |
| 2117 | 2117 | if (empty($entity)) |
| 2118 | 2118 | { |
| 2119 | - if (empty($conf->multicompany->enabled)) $entity=1; |
|
| 2120 | - else $entity=0; |
|
| 2119 | + if (empty($conf->multicompany->enabled)) $entity = 1; |
|
| 2120 | + else $entity = 0; |
|
| 2121 | 2121 | } |
| 2122 | 2122 | // Fix modulepart |
| 2123 | - if ($modulepart == 'users') $modulepart='user'; |
|
| 2123 | + if ($modulepart == 'users') $modulepart = 'user'; |
|
| 2124 | 2124 | |
| 2125 | 2125 | dol_syslog('modulepart='.$modulepart.' original_file='.$original_file.' entity='.$entity); |
| 2126 | 2126 | // We define $accessallowed and $sqlprotectagainstexternals |
| 2127 | - $accessallowed=0; |
|
| 2128 | - $sqlprotectagainstexternals=''; |
|
| 2129 | - $ret=array(); |
|
| 2127 | + $accessallowed = 0; |
|
| 2128 | + $sqlprotectagainstexternals = ''; |
|
| 2129 | + $ret = array(); |
|
| 2130 | 2130 | |
| 2131 | 2131 | // Find the subdirectory name as the reference. For exemple original_file='10/myfile.pdf' -> refname='10' |
| 2132 | - if (empty($refname)) $refname=basename(dirname($original_file)."/"); |
|
| 2132 | + if (empty($refname)) $refname = basename(dirname($original_file)."/"); |
|
| 2133 | 2133 | |
| 2134 | 2134 | $relative_original_file = $original_file; |
| 2135 | 2135 | |
| 2136 | 2136 | // Define possible keys to use for permission check |
| 2137 | - $lire='lire'; $read='read'; $download='download'; |
|
| 2137 | + $lire = 'lire'; $read = 'read'; $download = 'download'; |
|
| 2138 | 2138 | if ($mode == 'write') |
| 2139 | 2139 | { |
| 2140 | - $lire='creer'; $read='write'; $download='upload'; |
|
| 2140 | + $lire = 'creer'; $read = 'write'; $download = 'upload'; |
|
| 2141 | 2141 | } |
| 2142 | 2142 | |
| 2143 | 2143 | // Wrapping for miscellaneous medias files |
| 2144 | 2144 | if ($modulepart == 'medias' && !empty($dolibarr_main_data_root)) |
| 2145 | 2145 | { |
| 2146 | 2146 | if (empty($entity) || empty($conf->medias->multidir_output[$entity])) return array('accessallowed'=>0, 'error'=>'Value entity must be provided'); |
| 2147 | - $accessallowed=1; |
|
| 2148 | - $original_file=$conf->medias->multidir_output[$entity].'/'.$original_file; |
|
| 2147 | + $accessallowed = 1; |
|
| 2148 | + $original_file = $conf->medias->multidir_output[$entity].'/'.$original_file; |
|
| 2149 | 2149 | } |
| 2150 | 2150 | // Wrapping for *.log files, like when used with url http://.../document.php?modulepart=logs&file=dolibarr.log |
| 2151 | 2151 | elseif ($modulepart == 'logs' && !empty($dolibarr_main_data_root)) |
| 2152 | 2152 | { |
| 2153 | - $accessallowed=($user->admin && basename($original_file) == $original_file && preg_match('/^dolibarr.*\.log$/', basename($original_file))); |
|
| 2154 | - $original_file=$dolibarr_main_data_root.'/'.$original_file; |
|
| 2153 | + $accessallowed = ($user->admin && basename($original_file) == $original_file && preg_match('/^dolibarr.*\.log$/', basename($original_file))); |
|
| 2154 | + $original_file = $dolibarr_main_data_root.'/'.$original_file; |
|
| 2155 | 2155 | } |
| 2156 | 2156 | // Wrapping for *.zip files, like when used with url http://.../document.php?modulepart=packages&file=module_myfile.zip |
| 2157 | 2157 | elseif ($modulepart == 'packages' && !empty($dolibarr_main_data_root)) |
| 2158 | 2158 | { |
| 2159 | 2159 | // Dir for custom dirs |
| 2160 | - $tmp=explode(',', $dolibarr_main_document_root_alt); |
|
| 2160 | + $tmp = explode(',', $dolibarr_main_document_root_alt); |
|
| 2161 | 2161 | $dirins = $tmp[0]; |
| 2162 | 2162 | |
| 2163 | - $accessallowed=($user->admin && preg_match('/^module_.*\.zip$/', basename($original_file))); |
|
| 2164 | - $original_file=$dirins.'/'.$original_file; |
|
| 2163 | + $accessallowed = ($user->admin && preg_match('/^module_.*\.zip$/', basename($original_file))); |
|
| 2164 | + $original_file = $dirins.'/'.$original_file; |
|
| 2165 | 2165 | } |
| 2166 | 2166 | // Wrapping for some images |
| 2167 | 2167 | elseif ($modulepart == 'mycompany' && !empty($conf->mycompany->dir_output)) |
| 2168 | 2168 | { |
| 2169 | - $accessallowed=1; |
|
| 2170 | - $original_file=$conf->mycompany->dir_output.'/'.$original_file; |
|
| 2169 | + $accessallowed = 1; |
|
| 2170 | + $original_file = $conf->mycompany->dir_output.'/'.$original_file; |
|
| 2171 | 2171 | } |
| 2172 | 2172 | // Wrapping for users photos |
| 2173 | 2173 | elseif ($modulepart == 'userphoto' && !empty($conf->user->dir_output)) |
| 2174 | 2174 | { |
| 2175 | - $accessallowed=1; |
|
| 2176 | - $original_file=$conf->user->dir_output.'/'.$original_file; |
|
| 2175 | + $accessallowed = 1; |
|
| 2176 | + $original_file = $conf->user->dir_output.'/'.$original_file; |
|
| 2177 | 2177 | } |
| 2178 | 2178 | // Wrapping for members photos |
| 2179 | 2179 | elseif ($modulepart == 'memberphoto' && !empty($conf->adherent->dir_output)) |
| 2180 | 2180 | { |
| 2181 | - $accessallowed=1; |
|
| 2182 | - $original_file=$conf->adherent->dir_output.'/'.$original_file; |
|
| 2181 | + $accessallowed = 1; |
|
| 2182 | + $original_file = $conf->adherent->dir_output.'/'.$original_file; |
|
| 2183 | 2183 | } |
| 2184 | 2184 | // Wrapping pour les apercu factures |
| 2185 | 2185 | elseif ($modulepart == 'apercufacture' && !empty($conf->facture->dir_output)) |
| 2186 | 2186 | { |
| 2187 | - if ($fuser->rights->facture->{$lire}) $accessallowed=1; |
|
| 2188 | - $original_file=$conf->facture->dir_output.'/'.$original_file; |
|
| 2187 | + if ($fuser->rights->facture->{$lire}) $accessallowed = 1; |
|
| 2188 | + $original_file = $conf->facture->dir_output.'/'.$original_file; |
|
| 2189 | 2189 | } |
| 2190 | 2190 | // Wrapping pour les apercu propal |
| 2191 | 2191 | elseif ($modulepart == 'apercupropal' && !empty($conf->propal->multidir_output[$entity])) |
| 2192 | 2192 | { |
| 2193 | - if ($fuser->rights->propale->{$lire}) $accessallowed=1; |
|
| 2194 | - $original_file=$conf->propal->multidir_output[$entity].'/'.$original_file; |
|
| 2193 | + if ($fuser->rights->propale->{$lire}) $accessallowed = 1; |
|
| 2194 | + $original_file = $conf->propal->multidir_output[$entity].'/'.$original_file; |
|
| 2195 | 2195 | } |
| 2196 | 2196 | // Wrapping pour les apercu commande |
| 2197 | 2197 | elseif ($modulepart == 'apercucommande' && !empty($conf->commande->dir_output)) |
| 2198 | 2198 | { |
| 2199 | - if ($fuser->rights->commande->{$lire}) $accessallowed=1; |
|
| 2200 | - $original_file=$conf->commande->dir_output.'/'.$original_file; |
|
| 2199 | + if ($fuser->rights->commande->{$lire}) $accessallowed = 1; |
|
| 2200 | + $original_file = $conf->commande->dir_output.'/'.$original_file; |
|
| 2201 | 2201 | } |
| 2202 | 2202 | // Wrapping pour les apercu intervention |
| 2203 | 2203 | elseif (($modulepart == 'apercufichinter' || $modulepart == 'apercuficheinter') && !empty($conf->ficheinter->dir_output)) |
| 2204 | 2204 | { |
| 2205 | - if ($fuser->rights->ficheinter->{$lire}) $accessallowed=1; |
|
| 2206 | - $original_file=$conf->ficheinter->dir_output.'/'.$original_file; |
|
| 2205 | + if ($fuser->rights->ficheinter->{$lire}) $accessallowed = 1; |
|
| 2206 | + $original_file = $conf->ficheinter->dir_output.'/'.$original_file; |
|
| 2207 | 2207 | } |
| 2208 | 2208 | // Wrapping pour les apercu conat |
| 2209 | 2209 | elseif (($modulepart == 'apercucontract') && !empty($conf->contrat->dir_output)) |
| 2210 | 2210 | { |
| 2211 | - if ($fuser->rights->contrat->{$lire}) $accessallowed=1; |
|
| 2212 | - $original_file=$conf->contrat->dir_output.'/'.$original_file; |
|
| 2211 | + if ($fuser->rights->contrat->{$lire}) $accessallowed = 1; |
|
| 2212 | + $original_file = $conf->contrat->dir_output.'/'.$original_file; |
|
| 2213 | 2213 | } |
| 2214 | 2214 | // Wrapping pour les apercu supplier proposal |
| 2215 | 2215 | elseif (($modulepart == 'apercusupplier_proposal' || $modulepart == 'apercusupplier_proposal') && !empty($conf->supplier_proposal->dir_output)) |
| 2216 | 2216 | { |
| 2217 | - if ($fuser->rights->supplier_proposal->{$lire}) $accessallowed=1; |
|
| 2218 | - $original_file=$conf->supplier_proposal->dir_output.'/'.$original_file; |
|
| 2217 | + if ($fuser->rights->supplier_proposal->{$lire}) $accessallowed = 1; |
|
| 2218 | + $original_file = $conf->supplier_proposal->dir_output.'/'.$original_file; |
|
| 2219 | 2219 | } |
| 2220 | 2220 | // Wrapping pour les apercu supplier order |
| 2221 | 2221 | elseif (($modulepart == 'apercusupplier_order' || $modulepart == 'apercusupplier_order') && !empty($conf->fournisseur->commande->dir_output)) |
| 2222 | 2222 | { |
| 2223 | - if ($fuser->rights->fournisseur->commande->{$lire}) $accessallowed=1; |
|
| 2224 | - $original_file=$conf->fournisseur->commande->dir_output.'/'.$original_file; |
|
| 2223 | + if ($fuser->rights->fournisseur->commande->{$lire}) $accessallowed = 1; |
|
| 2224 | + $original_file = $conf->fournisseur->commande->dir_output.'/'.$original_file; |
|
| 2225 | 2225 | } |
| 2226 | 2226 | // Wrapping pour les apercu supplier invoice |
| 2227 | 2227 | elseif (($modulepart == 'apercusupplier_invoice' || $modulepart == 'apercusupplier_invoice') && !empty($conf->fournisseur->facture->dir_output)) |
| 2228 | 2228 | { |
| 2229 | - if ($fuser->rights->fournisseur->facture->{$lire}) $accessallowed=1; |
|
| 2230 | - $original_file=$conf->fournisseur->facture->dir_output.'/'.$original_file; |
|
| 2229 | + if ($fuser->rights->fournisseur->facture->{$lire}) $accessallowed = 1; |
|
| 2230 | + $original_file = $conf->fournisseur->facture->dir_output.'/'.$original_file; |
|
| 2231 | 2231 | } |
| 2232 | 2232 | // Wrapping pour les apercu supplier invoice |
| 2233 | 2233 | elseif (($modulepart == 'apercuexpensereport') && !empty($conf->expensereport->dir_output)) |
| 2234 | 2234 | { |
| 2235 | - if ($fuser->rights->expensereport->{$lire}) $accessallowed=1; |
|
| 2236 | - $original_file=$conf->expensereport->dir_output.'/'.$original_file; |
|
| 2235 | + if ($fuser->rights->expensereport->{$lire}) $accessallowed = 1; |
|
| 2236 | + $original_file = $conf->expensereport->dir_output.'/'.$original_file; |
|
| 2237 | 2237 | } |
| 2238 | 2238 | // Wrapping pour les images des stats propales |
| 2239 | 2239 | elseif ($modulepart == 'propalstats' && !empty($conf->propal->multidir_temp[$entity])) |
| 2240 | 2240 | { |
| 2241 | - if ($fuser->rights->propale->{$lire}) $accessallowed=1; |
|
| 2242 | - $original_file=$conf->propal->multidir_temp[$entity].'/'.$original_file; |
|
| 2241 | + if ($fuser->rights->propale->{$lire}) $accessallowed = 1; |
|
| 2242 | + $original_file = $conf->propal->multidir_temp[$entity].'/'.$original_file; |
|
| 2243 | 2243 | } |
| 2244 | 2244 | // Wrapping pour les images des stats commandes |
| 2245 | 2245 | elseif ($modulepart == 'orderstats' && !empty($conf->commande->dir_temp)) |
| 2246 | 2246 | { |
| 2247 | - if ($fuser->rights->commande->{$lire}) $accessallowed=1; |
|
| 2248 | - $original_file=$conf->commande->dir_temp.'/'.$original_file; |
|
| 2247 | + if ($fuser->rights->commande->{$lire}) $accessallowed = 1; |
|
| 2248 | + $original_file = $conf->commande->dir_temp.'/'.$original_file; |
|
| 2249 | 2249 | } |
| 2250 | 2250 | elseif ($modulepart == 'orderstatssupplier' && !empty($conf->fournisseur->dir_output)) |
| 2251 | 2251 | { |
| 2252 | - if ($fuser->rights->fournisseur->commande->{$lire}) $accessallowed=1; |
|
| 2253 | - $original_file=$conf->fournisseur->commande->dir_temp.'/'.$original_file; |
|
| 2252 | + if ($fuser->rights->fournisseur->commande->{$lire}) $accessallowed = 1; |
|
| 2253 | + $original_file = $conf->fournisseur->commande->dir_temp.'/'.$original_file; |
|
| 2254 | 2254 | } |
| 2255 | 2255 | // Wrapping pour les images des stats factures |
| 2256 | 2256 | elseif ($modulepart == 'billstats' && !empty($conf->facture->dir_temp)) |
| 2257 | 2257 | { |
| 2258 | - if ($fuser->rights->facture->{$lire}) $accessallowed=1; |
|
| 2259 | - $original_file=$conf->facture->dir_temp.'/'.$original_file; |
|
| 2258 | + if ($fuser->rights->facture->{$lire}) $accessallowed = 1; |
|
| 2259 | + $original_file = $conf->facture->dir_temp.'/'.$original_file; |
|
| 2260 | 2260 | } |
| 2261 | 2261 | elseif ($modulepart == 'billstatssupplier' && !empty($conf->fournisseur->dir_output)) |
| 2262 | 2262 | { |
| 2263 | - if ($fuser->rights->fournisseur->facture->{$lire}) $accessallowed=1; |
|
| 2264 | - $original_file=$conf->fournisseur->facture->dir_temp.'/'.$original_file; |
|
| 2263 | + if ($fuser->rights->fournisseur->facture->{$lire}) $accessallowed = 1; |
|
| 2264 | + $original_file = $conf->fournisseur->facture->dir_temp.'/'.$original_file; |
|
| 2265 | 2265 | } |
| 2266 | 2266 | // Wrapping pour les images des stats expeditions |
| 2267 | 2267 | elseif ($modulepart == 'expeditionstats' && !empty($conf->expedition->dir_temp)) |
| 2268 | 2268 | { |
| 2269 | - if ($fuser->rights->expedition->{$lire}) $accessallowed=1; |
|
| 2270 | - $original_file=$conf->expedition->dir_temp.'/'.$original_file; |
|
| 2269 | + if ($fuser->rights->expedition->{$lire}) $accessallowed = 1; |
|
| 2270 | + $original_file = $conf->expedition->dir_temp.'/'.$original_file; |
|
| 2271 | 2271 | } |
| 2272 | 2272 | // Wrapping pour les images des stats expeditions |
| 2273 | 2273 | elseif ($modulepart == 'tripsexpensesstats' && !empty($conf->deplacement->dir_temp)) |
| 2274 | 2274 | { |
| 2275 | - if ($fuser->rights->deplacement->{$lire}) $accessallowed=1; |
|
| 2276 | - $original_file=$conf->deplacement->dir_temp.'/'.$original_file; |
|
| 2275 | + if ($fuser->rights->deplacement->{$lire}) $accessallowed = 1; |
|
| 2276 | + $original_file = $conf->deplacement->dir_temp.'/'.$original_file; |
|
| 2277 | 2277 | } |
| 2278 | 2278 | // Wrapping pour les images des stats expeditions |
| 2279 | 2279 | elseif ($modulepart == 'memberstats' && !empty($conf->adherent->dir_temp)) |
| 2280 | 2280 | { |
| 2281 | - if ($fuser->rights->adherent->{$lire}) $accessallowed=1; |
|
| 2282 | - $original_file=$conf->adherent->dir_temp.'/'.$original_file; |
|
| 2281 | + if ($fuser->rights->adherent->{$lire}) $accessallowed = 1; |
|
| 2282 | + $original_file = $conf->adherent->dir_temp.'/'.$original_file; |
|
| 2283 | 2283 | } |
| 2284 | 2284 | // Wrapping pour les images des stats produits |
| 2285 | - elseif (preg_match('/^productstats_/i',$modulepart) && !empty($conf->product->dir_temp)) |
|
| 2285 | + elseif (preg_match('/^productstats_/i', $modulepart) && !empty($conf->product->dir_temp)) |
|
| 2286 | 2286 | { |
| 2287 | - if ($fuser->rights->produit->{$lire} || $fuser->rights->service->{$lire}) $accessallowed=1; |
|
| 2288 | - $original_file=(!empty($conf->product->multidir_temp[$entity])?$conf->product->multidir_temp[$entity]:$conf->service->multidir_temp[$entity]).'/'.$original_file; |
|
| 2287 | + if ($fuser->rights->produit->{$lire} || $fuser->rights->service->{$lire}) $accessallowed = 1; |
|
| 2288 | + $original_file = (!empty($conf->product->multidir_temp[$entity]) ? $conf->product->multidir_temp[$entity] : $conf->service->multidir_temp[$entity]).'/'.$original_file; |
|
| 2289 | 2289 | } |
| 2290 | 2290 | // Wrapping for taxes |
| 2291 | 2291 | elseif ($modulepart == 'tax' && !empty($conf->tax->dir_output)) |
| 2292 | 2292 | { |
| 2293 | - if ($fuser->rights->tax->charges->{$lire}) $accessallowed=1; |
|
| 2294 | - $original_file=$conf->tax->dir_output.'/'.$original_file; |
|
| 2293 | + if ($fuser->rights->tax->charges->{$lire}) $accessallowed = 1; |
|
| 2294 | + $original_file = $conf->tax->dir_output.'/'.$original_file; |
|
| 2295 | 2295 | } |
| 2296 | 2296 | // Wrapping for events |
| 2297 | 2297 | elseif ($modulepart == 'actions' && !empty($conf->agenda->dir_output)) |
| 2298 | 2298 | { |
| 2299 | - if ($fuser->rights->agenda->myactions->{$read}) $accessallowed=1; |
|
| 2300 | - $original_file=$conf->agenda->dir_output.'/'.$original_file; |
|
| 2299 | + if ($fuser->rights->agenda->myactions->{$read}) $accessallowed = 1; |
|
| 2300 | + $original_file = $conf->agenda->dir_output.'/'.$original_file; |
|
| 2301 | 2301 | } |
| 2302 | 2302 | // Wrapping for categories |
| 2303 | 2303 | elseif ($modulepart == 'category' && !empty($conf->categorie->dir_output)) |
| 2304 | 2304 | { |
| 2305 | 2305 | if (empty($entity) || empty($conf->categorie->multidir_output[$entity])) return array('accessallowed'=>0, 'error'=>'Value entity must be provided'); |
| 2306 | - if ($fuser->rights->categorie->{$lire}) $accessallowed=1; |
|
| 2307 | - $original_file=$conf->categorie->multidir_output[$entity].'/'.$original_file; |
|
| 2306 | + if ($fuser->rights->categorie->{$lire}) $accessallowed = 1; |
|
| 2307 | + $original_file = $conf->categorie->multidir_output[$entity].'/'.$original_file; |
|
| 2308 | 2308 | } |
| 2309 | 2309 | // Wrapping pour les prelevements |
| 2310 | 2310 | elseif ($modulepart == 'prelevement' && !empty($conf->prelevement->dir_output)) |
| 2311 | 2311 | { |
| 2312 | - if ($fuser->rights->prelevement->bons->{$lire} || preg_match('/^specimen/i',$original_file)) $accessallowed=1; |
|
| 2313 | - $original_file=$conf->prelevement->dir_output.'/'.$original_file; |
|
| 2312 | + if ($fuser->rights->prelevement->bons->{$lire} || preg_match('/^specimen/i', $original_file)) $accessallowed = 1; |
|
| 2313 | + $original_file = $conf->prelevement->dir_output.'/'.$original_file; |
|
| 2314 | 2314 | } |
| 2315 | 2315 | // Wrapping pour les graph energie |
| 2316 | 2316 | elseif ($modulepart == 'graph_stock' && !empty($conf->stock->dir_temp)) |
| 2317 | 2317 | { |
| 2318 | - $accessallowed=1; |
|
| 2319 | - $original_file=$conf->stock->dir_temp.'/'.$original_file; |
|
| 2318 | + $accessallowed = 1; |
|
| 2319 | + $original_file = $conf->stock->dir_temp.'/'.$original_file; |
|
| 2320 | 2320 | } |
| 2321 | 2321 | // Wrapping pour les graph fournisseurs |
| 2322 | 2322 | elseif ($modulepart == 'graph_fourn' && !empty($conf->fournisseur->dir_temp)) |
| 2323 | 2323 | { |
| 2324 | - $accessallowed=1; |
|
| 2325 | - $original_file=$conf->fournisseur->dir_temp.'/'.$original_file; |
|
| 2324 | + $accessallowed = 1; |
|
| 2325 | + $original_file = $conf->fournisseur->dir_temp.'/'.$original_file; |
|
| 2326 | 2326 | } |
| 2327 | 2327 | // Wrapping pour les graph des produits |
| 2328 | 2328 | elseif ($modulepart == 'graph_product' && !empty($conf->product->dir_temp)) |
| 2329 | 2329 | { |
| 2330 | - $accessallowed=1; |
|
| 2331 | - $original_file=$conf->product->multidir_temp[$entity].'/'.$original_file; |
|
| 2330 | + $accessallowed = 1; |
|
| 2331 | + $original_file = $conf->product->multidir_temp[$entity].'/'.$original_file; |
|
| 2332 | 2332 | } |
| 2333 | 2333 | // Wrapping pour les code barre |
| 2334 | 2334 | elseif ($modulepart == 'barcode') |
| 2335 | 2335 | { |
| 2336 | - $accessallowed=1; |
|
| 2336 | + $accessallowed = 1; |
|
| 2337 | 2337 | // If viewimage is called for barcode, we try to output an image on the fly, with no build of file on disk. |
| 2338 | 2338 | //$original_file=$conf->barcode->dir_temp.'/'.$original_file; |
| 2339 | - $original_file=''; |
|
| 2339 | + $original_file = ''; |
|
| 2340 | 2340 | } |
| 2341 | 2341 | // Wrapping pour les icones de background des mailings |
| 2342 | 2342 | elseif ($modulepart == 'iconmailing' && !empty($conf->mailing->dir_temp)) |
| 2343 | 2343 | { |
| 2344 | - $accessallowed=1; |
|
| 2345 | - $original_file=$conf->mailing->dir_temp.'/'.$original_file; |
|
| 2344 | + $accessallowed = 1; |
|
| 2345 | + $original_file = $conf->mailing->dir_temp.'/'.$original_file; |
|
| 2346 | 2346 | } |
| 2347 | 2347 | // Wrapping pour le scanner |
| 2348 | 2348 | elseif ($modulepart == 'scanner_user_temp' && !empty($conf->scanner->dir_temp)) |
| 2349 | 2349 | { |
| 2350 | - $accessallowed=1; |
|
| 2351 | - $original_file=$conf->scanner->dir_temp.'/'.$fuser->id.'/'.$original_file; |
|
| 2350 | + $accessallowed = 1; |
|
| 2351 | + $original_file = $conf->scanner->dir_temp.'/'.$fuser->id.'/'.$original_file; |
|
| 2352 | 2352 | } |
| 2353 | 2353 | // Wrapping pour les images fckeditor |
| 2354 | 2354 | elseif ($modulepart == 'fckeditor' && !empty($conf->fckeditor->dir_output)) |
| 2355 | 2355 | { |
| 2356 | - $accessallowed=1; |
|
| 2357 | - $original_file=$conf->fckeditor->dir_output.'/'.$original_file; |
|
| 2356 | + $accessallowed = 1; |
|
| 2357 | + $original_file = $conf->fckeditor->dir_output.'/'.$original_file; |
|
| 2358 | 2358 | } |
| 2359 | 2359 | |
| 2360 | 2360 | // Wrapping for users |
| 2361 | 2361 | else if ($modulepart == 'user' && !empty($conf->user->dir_output)) |
| 2362 | 2362 | { |
| 2363 | - $canreaduser=(! empty($fuser->admin) || $fuser->rights->user->user->{$lire}); |
|
| 2364 | - if ($fuser->id == (int) $refname) { $canreaduser=1; } // A user can always read its own card |
|
| 2365 | - if ($canreaduser || preg_match('/^specimen/i',$original_file)) |
|
| 2363 | + $canreaduser = (!empty($fuser->admin) || $fuser->rights->user->user->{$lire}); |
|
| 2364 | + if ($fuser->id == (int) $refname) { $canreaduser = 1; } // A user can always read its own card |
|
| 2365 | + if ($canreaduser || preg_match('/^specimen/i', $original_file)) |
|
| 2366 | 2366 | { |
| 2367 | - $accessallowed=1; |
|
| 2367 | + $accessallowed = 1; |
|
| 2368 | 2368 | } |
| 2369 | - $original_file=$conf->user->dir_output.'/'.$original_file; |
|
| 2369 | + $original_file = $conf->user->dir_output.'/'.$original_file; |
|
| 2370 | 2370 | } |
| 2371 | 2371 | |
| 2372 | 2372 | // Wrapping for third parties |
| 2373 | 2373 | else if (($modulepart == 'company' || $modulepart == 'societe') && !empty($conf->societe->dir_output)) |
| 2374 | 2374 | { |
| 2375 | 2375 | if (empty($entity) || empty($conf->societe->multidir_output[$entity])) return array('accessallowed'=>0, 'error'=>'Value entity must be provided'); |
| 2376 | - if ($fuser->rights->societe->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2376 | + if ($fuser->rights->societe->{$lire} || preg_match('/^specimen/i', $original_file)) |
|
| 2377 | 2377 | { |
| 2378 | - $accessallowed=1; |
|
| 2378 | + $accessallowed = 1; |
|
| 2379 | 2379 | } |
| 2380 | - $original_file=$conf->societe->multidir_output[$entity].'/'.$original_file; |
|
| 2380 | + $original_file = $conf->societe->multidir_output[$entity].'/'.$original_file; |
|
| 2381 | 2381 | $sqlprotectagainstexternals = "SELECT rowid as fk_soc FROM ".MAIN_DB_PREFIX."societe WHERE rowid='".$db->escape($refname)."' AND entity IN (".getEntity('societe').")"; |
| 2382 | 2382 | } |
| 2383 | 2383 | |
@@ -2387,246 +2387,246 @@ discard block |
||
| 2387 | 2387 | if (empty($entity) || empty($conf->societe->multidir_output[$entity])) return array('accessallowed'=>0, 'error'=>'Value entity must be provided'); |
| 2388 | 2388 | if ($fuser->rights->societe->{$lire}) |
| 2389 | 2389 | { |
| 2390 | - $accessallowed=1; |
|
| 2390 | + $accessallowed = 1; |
|
| 2391 | 2391 | } |
| 2392 | - $original_file=$conf->societe->multidir_output[$entity].'/contact/'.$original_file; |
|
| 2392 | + $original_file = $conf->societe->multidir_output[$entity].'/contact/'.$original_file; |
|
| 2393 | 2393 | } |
| 2394 | 2394 | |
| 2395 | 2395 | // Wrapping for invoices |
| 2396 | 2396 | else if (($modulepart == 'facture' || $modulepart == 'invoice') && !empty($conf->facture->dir_output)) |
| 2397 | 2397 | { |
| 2398 | - if ($fuser->rights->facture->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2398 | + if ($fuser->rights->facture->{$lire} || preg_match('/^specimen/i', $original_file)) |
|
| 2399 | 2399 | { |
| 2400 | - $accessallowed=1; |
|
| 2400 | + $accessallowed = 1; |
|
| 2401 | 2401 | } |
| 2402 | - $original_file=$conf->facture->dir_output.'/'.$original_file; |
|
| 2402 | + $original_file = $conf->facture->dir_output.'/'.$original_file; |
|
| 2403 | 2403 | $sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."facture WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity; |
| 2404 | 2404 | } |
| 2405 | 2405 | // Wrapping for mass actions |
| 2406 | 2406 | else if ($modulepart == 'massfilesarea_proposals' && !empty($conf->propal->multidir_output[$entity])) |
| 2407 | 2407 | { |
| 2408 | - if ($fuser->rights->propal->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2408 | + if ($fuser->rights->propal->{$lire} || preg_match('/^specimen/i', $original_file)) |
|
| 2409 | 2409 | { |
| 2410 | - $accessallowed=1; |
|
| 2410 | + $accessallowed = 1; |
|
| 2411 | 2411 | } |
| 2412 | - $original_file=$conf->propal->multidir_output[$entity].'/temp/massgeneration/'.$user->id.'/'.$original_file; |
|
| 2412 | + $original_file = $conf->propal->multidir_output[$entity].'/temp/massgeneration/'.$user->id.'/'.$original_file; |
|
| 2413 | 2413 | } |
| 2414 | 2414 | else if ($modulepart == 'massfilesarea_orders') |
| 2415 | 2415 | { |
| 2416 | - if ($fuser->rights->commande->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2416 | + if ($fuser->rights->commande->{$lire} || preg_match('/^specimen/i', $original_file)) |
|
| 2417 | 2417 | { |
| 2418 | - $accessallowed=1; |
|
| 2418 | + $accessallowed = 1; |
|
| 2419 | 2419 | } |
| 2420 | - $original_file=$conf->commande->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; |
|
| 2420 | + $original_file = $conf->commande->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; |
|
| 2421 | 2421 | } |
| 2422 | 2422 | else if ($modulepart == 'massfilesarea_invoices') |
| 2423 | 2423 | { |
| 2424 | - if ($fuser->rights->facture->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2424 | + if ($fuser->rights->facture->{$lire} || preg_match('/^specimen/i', $original_file)) |
|
| 2425 | 2425 | { |
| 2426 | - $accessallowed=1; |
|
| 2426 | + $accessallowed = 1; |
|
| 2427 | 2427 | } |
| 2428 | - $original_file=$conf->facture->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; |
|
| 2428 | + $original_file = $conf->facture->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; |
|
| 2429 | 2429 | } |
| 2430 | 2430 | else if ($modulepart == 'massfilesarea_expensereport') |
| 2431 | 2431 | { |
| 2432 | - if ($fuser->rights->facture->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2432 | + if ($fuser->rights->facture->{$lire} || preg_match('/^specimen/i', $original_file)) |
|
| 2433 | 2433 | { |
| 2434 | - $accessallowed=1; |
|
| 2434 | + $accessallowed = 1; |
|
| 2435 | 2435 | } |
| 2436 | - $original_file=$conf->expensereport->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; |
|
| 2436 | + $original_file = $conf->expensereport->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; |
|
| 2437 | 2437 | } |
| 2438 | 2438 | else if ($modulepart == 'massfilesarea_interventions') |
| 2439 | 2439 | { |
| 2440 | - if ($fuser->rights->ficheinter->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2440 | + if ($fuser->rights->ficheinter->{$lire} || preg_match('/^specimen/i', $original_file)) |
|
| 2441 | 2441 | { |
| 2442 | - $accessallowed=1; |
|
| 2442 | + $accessallowed = 1; |
|
| 2443 | 2443 | } |
| 2444 | - $original_file=$conf->ficheinter->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; |
|
| 2444 | + $original_file = $conf->ficheinter->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; |
|
| 2445 | 2445 | } |
| 2446 | 2446 | else if ($modulepart == 'massfilesarea_supplier_proposal' && !empty($conf->supplier_proposal->dir_output)) |
| 2447 | 2447 | { |
| 2448 | - if ($fuser->rights->supplier_proposal->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2448 | + if ($fuser->rights->supplier_proposal->{$lire} || preg_match('/^specimen/i', $original_file)) |
|
| 2449 | 2449 | { |
| 2450 | - $accessallowed=1; |
|
| 2450 | + $accessallowed = 1; |
|
| 2451 | 2451 | } |
| 2452 | - $original_file=$conf->supplier_proposal->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; |
|
| 2452 | + $original_file = $conf->supplier_proposal->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; |
|
| 2453 | 2453 | } |
| 2454 | 2454 | else if ($modulepart == 'massfilesarea_supplier_order') |
| 2455 | 2455 | { |
| 2456 | - if ($fuser->rights->fournisseur->commande->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2456 | + if ($fuser->rights->fournisseur->commande->{$lire} || preg_match('/^specimen/i', $original_file)) |
|
| 2457 | 2457 | { |
| 2458 | - $accessallowed=1; |
|
| 2458 | + $accessallowed = 1; |
|
| 2459 | 2459 | } |
| 2460 | - $original_file=$conf->fournisseur->commande->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; |
|
| 2460 | + $original_file = $conf->fournisseur->commande->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; |
|
| 2461 | 2461 | } |
| 2462 | 2462 | else if ($modulepart == 'massfilesarea_supplier_invoice') |
| 2463 | 2463 | { |
| 2464 | - if ($fuser->rights->fournisseur->facture->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2464 | + if ($fuser->rights->fournisseur->facture->{$lire} || preg_match('/^specimen/i', $original_file)) |
|
| 2465 | 2465 | { |
| 2466 | - $accessallowed=1; |
|
| 2466 | + $accessallowed = 1; |
|
| 2467 | 2467 | } |
| 2468 | - $original_file=$conf->fournisseur->facture->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; |
|
| 2468 | + $original_file = $conf->fournisseur->facture->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; |
|
| 2469 | 2469 | } |
| 2470 | 2470 | else if ($modulepart == 'massfilesarea_contract' && !empty($conf->contrat->dir_output)) |
| 2471 | 2471 | { |
| 2472 | - if ($fuser->rights->contrat->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2472 | + if ($fuser->rights->contrat->{$lire} || preg_match('/^specimen/i', $original_file)) |
|
| 2473 | 2473 | { |
| 2474 | - $accessallowed=1; |
|
| 2474 | + $accessallowed = 1; |
|
| 2475 | 2475 | } |
| 2476 | - $original_file=$conf->contrat->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; |
|
| 2476 | + $original_file = $conf->contrat->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; |
|
| 2477 | 2477 | } |
| 2478 | 2478 | |
| 2479 | 2479 | // Wrapping for interventions |
| 2480 | 2480 | else if (($modulepart == 'fichinter' || $modulepart == 'ficheinter') && !empty($conf->ficheinter->dir_output)) |
| 2481 | 2481 | { |
| 2482 | - if ($fuser->rights->ficheinter->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2482 | + if ($fuser->rights->ficheinter->{$lire} || preg_match('/^specimen/i', $original_file)) |
|
| 2483 | 2483 | { |
| 2484 | - $accessallowed=1; |
|
| 2484 | + $accessallowed = 1; |
|
| 2485 | 2485 | } |
| 2486 | - $original_file=$conf->ficheinter->dir_output.'/'.$original_file; |
|
| 2486 | + $original_file = $conf->ficheinter->dir_output.'/'.$original_file; |
|
| 2487 | 2487 | $sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."fichinter WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity; |
| 2488 | 2488 | } |
| 2489 | 2489 | |
| 2490 | 2490 | // Wrapping pour les deplacements et notes de frais |
| 2491 | 2491 | else if ($modulepart == 'deplacement' && !empty($conf->deplacement->dir_output)) |
| 2492 | 2492 | { |
| 2493 | - if ($fuser->rights->deplacement->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2493 | + if ($fuser->rights->deplacement->{$lire} || preg_match('/^specimen/i', $original_file)) |
|
| 2494 | 2494 | { |
| 2495 | - $accessallowed=1; |
|
| 2495 | + $accessallowed = 1; |
|
| 2496 | 2496 | } |
| 2497 | - $original_file=$conf->deplacement->dir_output.'/'.$original_file; |
|
| 2497 | + $original_file = $conf->deplacement->dir_output.'/'.$original_file; |
|
| 2498 | 2498 | //$sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."fichinter WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity; |
| 2499 | 2499 | } |
| 2500 | 2500 | // Wrapping pour les propales |
| 2501 | 2501 | else if (($modulepart == 'propal' || $modulepart == 'propale') && !empty($conf->propal->multidir_output[$entity])) |
| 2502 | 2502 | { |
| 2503 | - if ($fuser->rights->propale->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2503 | + if ($fuser->rights->propale->{$lire} || preg_match('/^specimen/i', $original_file)) |
|
| 2504 | 2504 | { |
| 2505 | - $accessallowed=1; |
|
| 2505 | + $accessallowed = 1; |
|
| 2506 | 2506 | } |
| 2507 | - $original_file=$conf->propal->multidir_output[$entity].'/'.$original_file; |
|
| 2507 | + $original_file = $conf->propal->multidir_output[$entity].'/'.$original_file; |
|
| 2508 | 2508 | $sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."propal WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity; |
| 2509 | 2509 | } |
| 2510 | 2510 | |
| 2511 | 2511 | // Wrapping pour les commandes |
| 2512 | 2512 | else if (($modulepart == 'commande' || $modulepart == 'order') && !empty($conf->commande->dir_output)) |
| 2513 | 2513 | { |
| 2514 | - if ($fuser->rights->commande->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2514 | + if ($fuser->rights->commande->{$lire} || preg_match('/^specimen/i', $original_file)) |
|
| 2515 | 2515 | { |
| 2516 | - $accessallowed=1; |
|
| 2516 | + $accessallowed = 1; |
|
| 2517 | 2517 | } |
| 2518 | - $original_file=$conf->commande->dir_output.'/'.$original_file; |
|
| 2518 | + $original_file = $conf->commande->dir_output.'/'.$original_file; |
|
| 2519 | 2519 | $sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."commande WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity; |
| 2520 | 2520 | } |
| 2521 | 2521 | |
| 2522 | 2522 | // Wrapping pour les projets |
| 2523 | 2523 | else if ($modulepart == 'project' && !empty($conf->projet->dir_output)) |
| 2524 | 2524 | { |
| 2525 | - if ($fuser->rights->projet->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2525 | + if ($fuser->rights->projet->{$lire} || preg_match('/^specimen/i', $original_file)) |
|
| 2526 | 2526 | { |
| 2527 | - $accessallowed=1; |
|
| 2527 | + $accessallowed = 1; |
|
| 2528 | 2528 | } |
| 2529 | - $original_file=$conf->projet->dir_output.'/'.$original_file; |
|
| 2529 | + $original_file = $conf->projet->dir_output.'/'.$original_file; |
|
| 2530 | 2530 | $sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."projet WHERE ref='".$db->escape($refname)."' AND entity IN (".getEntity('project').")"; |
| 2531 | 2531 | } |
| 2532 | 2532 | else if ($modulepart == 'project_task' && !empty($conf->projet->dir_output)) |
| 2533 | 2533 | { |
| 2534 | - if ($fuser->rights->projet->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2534 | + if ($fuser->rights->projet->{$lire} || preg_match('/^specimen/i', $original_file)) |
|
| 2535 | 2535 | { |
| 2536 | - $accessallowed=1; |
|
| 2536 | + $accessallowed = 1; |
|
| 2537 | 2537 | } |
| 2538 | - $original_file=$conf->projet->dir_output.'/'.$original_file; |
|
| 2538 | + $original_file = $conf->projet->dir_output.'/'.$original_file; |
|
| 2539 | 2539 | $sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."projet WHERE ref='".$db->escape($refname)."' AND entity IN (".getEntity('project').")"; |
| 2540 | 2540 | } |
| 2541 | 2541 | |
| 2542 | 2542 | // Wrapping pour les commandes fournisseurs |
| 2543 | 2543 | else if (($modulepart == 'commande_fournisseur' || $modulepart == 'order_supplier') && !empty($conf->fournisseur->commande->dir_output)) |
| 2544 | 2544 | { |
| 2545 | - if ($fuser->rights->fournisseur->commande->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2545 | + if ($fuser->rights->fournisseur->commande->{$lire} || preg_match('/^specimen/i', $original_file)) |
|
| 2546 | 2546 | { |
| 2547 | - $accessallowed=1; |
|
| 2547 | + $accessallowed = 1; |
|
| 2548 | 2548 | } |
| 2549 | - $original_file=$conf->fournisseur->commande->dir_output.'/'.$original_file; |
|
| 2549 | + $original_file = $conf->fournisseur->commande->dir_output.'/'.$original_file; |
|
| 2550 | 2550 | $sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."commande_fournisseur WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity; |
| 2551 | 2551 | } |
| 2552 | 2552 | |
| 2553 | 2553 | // Wrapping pour les factures fournisseurs |
| 2554 | 2554 | else if (($modulepart == 'facture_fournisseur' || $modulepart == 'invoice_supplier') && !empty($conf->fournisseur->facture->dir_output)) |
| 2555 | 2555 | { |
| 2556 | - if ($fuser->rights->fournisseur->facture->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2556 | + if ($fuser->rights->fournisseur->facture->{$lire} || preg_match('/^specimen/i', $original_file)) |
|
| 2557 | 2557 | { |
| 2558 | - $accessallowed=1; |
|
| 2558 | + $accessallowed = 1; |
|
| 2559 | 2559 | } |
| 2560 | - $original_file=$conf->fournisseur->facture->dir_output.'/'.$original_file; |
|
| 2560 | + $original_file = $conf->fournisseur->facture->dir_output.'/'.$original_file; |
|
| 2561 | 2561 | $sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."facture_fourn WHERE facnumber='".$db->escape($refname)."' AND entity=".$conf->entity; |
| 2562 | 2562 | } |
| 2563 | 2563 | // Wrapping pour les rapport de paiements |
| 2564 | 2564 | else if ($modulepart == 'supplier_payment') |
| 2565 | 2565 | { |
| 2566 | - if ($fuser->rights->fournisseur->facture->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2566 | + if ($fuser->rights->fournisseur->facture->{$lire} || preg_match('/^specimen/i', $original_file)) |
|
| 2567 | 2567 | { |
| 2568 | - $accessallowed=1; |
|
| 2568 | + $accessallowed = 1; |
|
| 2569 | 2569 | } |
| 2570 | - $original_file=$conf->fournisseur->payment->dir_output.'/'.$original_file; |
|
| 2570 | + $original_file = $conf->fournisseur->payment->dir_output.'/'.$original_file; |
|
| 2571 | 2571 | $sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."paiementfournisseur WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity; |
| 2572 | 2572 | } |
| 2573 | 2573 | |
| 2574 | 2574 | // Wrapping pour les rapport de paiements |
| 2575 | 2575 | else if ($modulepart == 'facture_paiement' && !empty($conf->facture->dir_output)) |
| 2576 | 2576 | { |
| 2577 | - if ($fuser->rights->facture->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2577 | + if ($fuser->rights->facture->{$lire} || preg_match('/^specimen/i', $original_file)) |
|
| 2578 | 2578 | { |
| 2579 | - $accessallowed=1; |
|
| 2579 | + $accessallowed = 1; |
|
| 2580 | 2580 | } |
| 2581 | - if ($fuser->societe_id > 0) $original_file=$conf->facture->dir_output.'/payments/private/'.$fuser->id.'/'.$original_file; |
|
| 2582 | - else $original_file=$conf->facture->dir_output.'/payments/'.$original_file; |
|
| 2581 | + if ($fuser->societe_id > 0) $original_file = $conf->facture->dir_output.'/payments/private/'.$fuser->id.'/'.$original_file; |
|
| 2582 | + else $original_file = $conf->facture->dir_output.'/payments/'.$original_file; |
|
| 2583 | 2583 | } |
| 2584 | 2584 | |
| 2585 | 2585 | // Wrapping for accounting exports |
| 2586 | 2586 | else if ($modulepart == 'export_compta' && !empty($conf->accounting->dir_output)) |
| 2587 | 2587 | { |
| 2588 | - if ($fuser->rights->accounting->bind->write || preg_match('/^specimen/i',$original_file)) |
|
| 2588 | + if ($fuser->rights->accounting->bind->write || preg_match('/^specimen/i', $original_file)) |
|
| 2589 | 2589 | { |
| 2590 | - $accessallowed=1; |
|
| 2590 | + $accessallowed = 1; |
|
| 2591 | 2591 | } |
| 2592 | - $original_file=$conf->accounting->dir_output.'/'.$original_file; |
|
| 2592 | + $original_file = $conf->accounting->dir_output.'/'.$original_file; |
|
| 2593 | 2593 | } |
| 2594 | 2594 | |
| 2595 | 2595 | // Wrapping pour les expedition |
| 2596 | 2596 | else if ($modulepart == 'expedition' && !empty($conf->expedition->dir_output)) |
| 2597 | 2597 | { |
| 2598 | - if ($fuser->rights->expedition->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2598 | + if ($fuser->rights->expedition->{$lire} || preg_match('/^specimen/i', $original_file)) |
|
| 2599 | 2599 | { |
| 2600 | - $accessallowed=1; |
|
| 2600 | + $accessallowed = 1; |
|
| 2601 | 2601 | } |
| 2602 | - $original_file=$conf->expedition->dir_output."/sending/".$original_file; |
|
| 2602 | + $original_file = $conf->expedition->dir_output."/sending/".$original_file; |
|
| 2603 | 2603 | } |
| 2604 | 2604 | // Wrapping pour les bons de livraison |
| 2605 | 2605 | else if ($modulepart == 'livraison' && !empty($conf->expedition->dir_output)) |
| 2606 | 2606 | { |
| 2607 | - if ($fuser->rights->expedition->livraison->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2607 | + if ($fuser->rights->expedition->livraison->{$lire} || preg_match('/^specimen/i', $original_file)) |
|
| 2608 | 2608 | { |
| 2609 | - $accessallowed=1; |
|
| 2609 | + $accessallowed = 1; |
|
| 2610 | 2610 | } |
| 2611 | - $original_file=$conf->expedition->dir_output."/receipt/".$original_file; |
|
| 2611 | + $original_file = $conf->expedition->dir_output."/receipt/".$original_file; |
|
| 2612 | 2612 | } |
| 2613 | 2613 | |
| 2614 | 2614 | // Wrapping pour les actions |
| 2615 | 2615 | else if ($modulepart == 'actions' && !empty($conf->agenda->dir_output)) |
| 2616 | 2616 | { |
| 2617 | - if ($fuser->rights->agenda->myactions->{$read} || preg_match('/^specimen/i',$original_file)) |
|
| 2617 | + if ($fuser->rights->agenda->myactions->{$read} || preg_match('/^specimen/i', $original_file)) |
|
| 2618 | 2618 | { |
| 2619 | - $accessallowed=1; |
|
| 2619 | + $accessallowed = 1; |
|
| 2620 | 2620 | } |
| 2621 | - $original_file=$conf->agenda->dir_output.'/'.$original_file; |
|
| 2621 | + $original_file = $conf->agenda->dir_output.'/'.$original_file; |
|
| 2622 | 2622 | } |
| 2623 | 2623 | |
| 2624 | 2624 | // Wrapping pour les actions |
| 2625 | 2625 | else if ($modulepart == 'actionsreport' && !empty($conf->agenda->dir_temp)) |
| 2626 | 2626 | { |
| 2627 | - if ($fuser->rights->agenda->allactions->{$read} || preg_match('/^specimen/i',$original_file)) |
|
| 2627 | + if ($fuser->rights->agenda->allactions->{$read} || preg_match('/^specimen/i', $original_file)) |
|
| 2628 | 2628 | { |
| 2629 | - $accessallowed=1; |
|
| 2629 | + $accessallowed = 1; |
|
| 2630 | 2630 | } |
| 2631 | 2631 | $original_file = $conf->agenda->dir_temp."/".$original_file; |
| 2632 | 2632 | } |
@@ -2635,65 +2635,65 @@ discard block |
||
| 2635 | 2635 | else if ($modulepart == 'product' || $modulepart == 'produit' || $modulepart == 'service' || $modulepart == 'produit|service') |
| 2636 | 2636 | { |
| 2637 | 2637 | if (empty($entity) || (empty($conf->product->multidir_output[$entity]) && empty($conf->service->multidir_output[$entity]))) return array('accessallowed'=>0, 'error'=>'Value entity must be provided'); |
| 2638 | - if (($fuser->rights->produit->{$lire} || $fuser->rights->service->{$lire}) || preg_match('/^specimen/i',$original_file)) |
|
| 2638 | + if (($fuser->rights->produit->{$lire} || $fuser->rights->service->{$lire}) || preg_match('/^specimen/i', $original_file)) |
|
| 2639 | 2639 | { |
| 2640 | - $accessallowed=1; |
|
| 2640 | + $accessallowed = 1; |
|
| 2641 | 2641 | } |
| 2642 | - if (! empty($conf->product->enabled)) $original_file=$conf->product->multidir_output[$entity].'/'.$original_file; |
|
| 2643 | - elseif (! empty($conf->service->enabled)) $original_file=$conf->service->multidir_output[$entity].'/'.$original_file; |
|
| 2642 | + if (!empty($conf->product->enabled)) $original_file = $conf->product->multidir_output[$entity].'/'.$original_file; |
|
| 2643 | + elseif (!empty($conf->service->enabled)) $original_file = $conf->service->multidir_output[$entity].'/'.$original_file; |
|
| 2644 | 2644 | } |
| 2645 | 2645 | |
| 2646 | 2646 | // Wrapping pour les lots produits |
| 2647 | 2647 | else if ($modulepart == 'product_batch' || $modulepart == 'produitlot') |
| 2648 | 2648 | { |
| 2649 | 2649 | if (empty($entity) || (empty($conf->productbatch->multidir_output[$entity]))) return array('accessallowed'=>0, 'error'=>'Value entity must be provided'); |
| 2650 | - if (($fuser->rights->produit->{$lire} ) || preg_match('/^specimen/i',$original_file)) |
|
| 2650 | + if (($fuser->rights->produit->{$lire} ) || preg_match('/^specimen/i', $original_file)) |
|
| 2651 | 2651 | { |
| 2652 | - $accessallowed=1; |
|
| 2652 | + $accessallowed = 1; |
|
| 2653 | 2653 | } |
| 2654 | - if (! empty($conf->productbatch->enabled)) $original_file=$conf->productbatch->multidir_output[$entity].'/'.$original_file; |
|
| 2654 | + if (!empty($conf->productbatch->enabled)) $original_file = $conf->productbatch->multidir_output[$entity].'/'.$original_file; |
|
| 2655 | 2655 | } |
| 2656 | 2656 | |
| 2657 | 2657 | // Wrapping pour les contrats |
| 2658 | 2658 | else if ($modulepart == 'contract' && !empty($conf->contrat->dir_output)) |
| 2659 | 2659 | { |
| 2660 | - if ($fuser->rights->contrat->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2660 | + if ($fuser->rights->contrat->{$lire} || preg_match('/^specimen/i', $original_file)) |
|
| 2661 | 2661 | { |
| 2662 | - $accessallowed=1; |
|
| 2662 | + $accessallowed = 1; |
|
| 2663 | 2663 | } |
| 2664 | - $original_file=$conf->contrat->dir_output.'/'.$original_file; |
|
| 2664 | + $original_file = $conf->contrat->dir_output.'/'.$original_file; |
|
| 2665 | 2665 | $sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."contrat WHERE ref='".$db->escape($refname)."' AND entity IN (".getEntity('contract').")"; |
| 2666 | 2666 | } |
| 2667 | 2667 | |
| 2668 | 2668 | // Wrapping pour les dons |
| 2669 | 2669 | else if ($modulepart == 'donation' && !empty($conf->don->dir_output)) |
| 2670 | 2670 | { |
| 2671 | - if ($fuser->rights->don->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2671 | + if ($fuser->rights->don->{$lire} || preg_match('/^specimen/i', $original_file)) |
|
| 2672 | 2672 | { |
| 2673 | - $accessallowed=1; |
|
| 2673 | + $accessallowed = 1; |
|
| 2674 | 2674 | } |
| 2675 | - $original_file=$conf->don->dir_output.'/'.$original_file; |
|
| 2675 | + $original_file = $conf->don->dir_output.'/'.$original_file; |
|
| 2676 | 2676 | } |
| 2677 | 2677 | |
| 2678 | 2678 | // Wrapping pour les dons |
| 2679 | 2679 | else if ($modulepart == 'dolresource' && !empty($conf->resource->dir_output)) |
| 2680 | 2680 | { |
| 2681 | - if ($fuser->rights->resource->{$read} || preg_match('/^specimen/i',$original_file)) |
|
| 2681 | + if ($fuser->rights->resource->{$read} || preg_match('/^specimen/i', $original_file)) |
|
| 2682 | 2682 | { |
| 2683 | - $accessallowed=1; |
|
| 2683 | + $accessallowed = 1; |
|
| 2684 | 2684 | } |
| 2685 | - $original_file=$conf->resource->dir_output.'/'.$original_file; |
|
| 2685 | + $original_file = $conf->resource->dir_output.'/'.$original_file; |
|
| 2686 | 2686 | } |
| 2687 | 2687 | |
| 2688 | 2688 | // Wrapping pour les remises de cheques |
| 2689 | 2689 | else if ($modulepart == 'remisecheque' && !empty($conf->banque->dir_output)) |
| 2690 | 2690 | { |
| 2691 | - if ($fuser->rights->banque->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2691 | + if ($fuser->rights->banque->{$lire} || preg_match('/^specimen/i', $original_file)) |
|
| 2692 | 2692 | { |
| 2693 | - $accessallowed=1; |
|
| 2693 | + $accessallowed = 1; |
|
| 2694 | 2694 | } |
| 2695 | 2695 | |
| 2696 | - $original_file=$conf->bank->dir_output.'/checkdeposits/'.$original_file; // original_file should contains relative path so include the get_exdir result |
|
| 2696 | + $original_file = $conf->bank->dir_output.'/checkdeposits/'.$original_file; // original_file should contains relative path so include the get_exdir result |
|
| 2697 | 2697 | } |
| 2698 | 2698 | |
| 2699 | 2699 | // Wrapping for bank |
@@ -2701,9 +2701,9 @@ discard block |
||
| 2701 | 2701 | { |
| 2702 | 2702 | if ($fuser->rights->banque->{$lire}) |
| 2703 | 2703 | { |
| 2704 | - $accessallowed=1; |
|
| 2704 | + $accessallowed = 1; |
|
| 2705 | 2705 | } |
| 2706 | - $original_file=$conf->bank->dir_output.'/'.$original_file; |
|
| 2706 | + $original_file = $conf->bank->dir_output.'/'.$original_file; |
|
| 2707 | 2707 | } |
| 2708 | 2708 | |
| 2709 | 2709 | // Wrapping for export module |
@@ -2711,62 +2711,62 @@ discard block |
||
| 2711 | 2711 | { |
| 2712 | 2712 | // Aucun test necessaire car on force le rep de download sur |
| 2713 | 2713 | // le rep export qui est propre a l'utilisateur |
| 2714 | - $accessallowed=1; |
|
| 2715 | - $original_file=$conf->export->dir_temp.'/'.$fuser->id.'/'.$original_file; |
|
| 2714 | + $accessallowed = 1; |
|
| 2715 | + $original_file = $conf->export->dir_temp.'/'.$fuser->id.'/'.$original_file; |
|
| 2716 | 2716 | } |
| 2717 | 2717 | |
| 2718 | 2718 | // Wrapping for import module |
| 2719 | 2719 | else if ($modulepart == 'import' && !empty($conf->import->dir_temp)) |
| 2720 | 2720 | { |
| 2721 | - $accessallowed=1; |
|
| 2722 | - $original_file=$conf->import->dir_temp.'/'.$original_file; |
|
| 2721 | + $accessallowed = 1; |
|
| 2722 | + $original_file = $conf->import->dir_temp.'/'.$original_file; |
|
| 2723 | 2723 | } |
| 2724 | 2724 | |
| 2725 | 2725 | // Wrapping pour l'editeur wysiwyg |
| 2726 | 2726 | else if ($modulepart == 'editor' && !empty($conf->fckeditor->dir_output)) |
| 2727 | 2727 | { |
| 2728 | - $accessallowed=1; |
|
| 2729 | - $original_file=$conf->fckeditor->dir_output.'/'.$original_file; |
|
| 2728 | + $accessallowed = 1; |
|
| 2729 | + $original_file = $conf->fckeditor->dir_output.'/'.$original_file; |
|
| 2730 | 2730 | } |
| 2731 | 2731 | |
| 2732 | 2732 | // Wrapping for backups |
| 2733 | 2733 | else if ($modulepart == 'systemtools' && !empty($conf->admin->dir_output)) |
| 2734 | 2734 | { |
| 2735 | - if ($fuser->admin) $accessallowed=1; |
|
| 2736 | - $original_file=$conf->admin->dir_output.'/'.$original_file; |
|
| 2735 | + if ($fuser->admin) $accessallowed = 1; |
|
| 2736 | + $original_file = $conf->admin->dir_output.'/'.$original_file; |
|
| 2737 | 2737 | } |
| 2738 | 2738 | |
| 2739 | 2739 | // Wrapping for upload file test |
| 2740 | 2740 | else if ($modulepart == 'admin_temp' && !empty($conf->admin->dir_temp)) |
| 2741 | 2741 | { |
| 2742 | - if ($fuser->admin) $accessallowed=1; |
|
| 2743 | - $original_file=$conf->admin->dir_temp.'/'.$original_file; |
|
| 2742 | + if ($fuser->admin) $accessallowed = 1; |
|
| 2743 | + $original_file = $conf->admin->dir_temp.'/'.$original_file; |
|
| 2744 | 2744 | } |
| 2745 | 2745 | |
| 2746 | 2746 | // Wrapping pour BitTorrent |
| 2747 | 2747 | else if ($modulepart == 'bittorrent' && !empty($conf->bittorrent->dir_output)) |
| 2748 | 2748 | { |
| 2749 | - $accessallowed=1; |
|
| 2750 | - $dir='files'; |
|
| 2751 | - if (dol_mimetype($original_file) == 'application/x-bittorrent') $dir='torrents'; |
|
| 2752 | - $original_file=$conf->bittorrent->dir_output.'/'.$dir.'/'.$original_file; |
|
| 2749 | + $accessallowed = 1; |
|
| 2750 | + $dir = 'files'; |
|
| 2751 | + if (dol_mimetype($original_file) == 'application/x-bittorrent') $dir = 'torrents'; |
|
| 2752 | + $original_file = $conf->bittorrent->dir_output.'/'.$dir.'/'.$original_file; |
|
| 2753 | 2753 | } |
| 2754 | 2754 | |
| 2755 | 2755 | // Wrapping pour Foundation module |
| 2756 | 2756 | else if ($modulepart == 'member' && !empty($conf->adherent->dir_output)) |
| 2757 | 2757 | { |
| 2758 | - if ($fuser->rights->adherent->{$lire} || preg_match('/^specimen/i',$original_file)) |
|
| 2758 | + if ($fuser->rights->adherent->{$lire} || preg_match('/^specimen/i', $original_file)) |
|
| 2759 | 2759 | { |
| 2760 | - $accessallowed=1; |
|
| 2760 | + $accessallowed = 1; |
|
| 2761 | 2761 | } |
| 2762 | - $original_file=$conf->adherent->dir_output.'/'.$original_file; |
|
| 2762 | + $original_file = $conf->adherent->dir_output.'/'.$original_file; |
|
| 2763 | 2763 | } |
| 2764 | 2764 | |
| 2765 | 2765 | // Wrapping for Scanner |
| 2766 | 2766 | else if ($modulepart == 'scanner_user_temp' && !empty($conf->scanner->dir_temp)) |
| 2767 | 2767 | { |
| 2768 | - $accessallowed=1; |
|
| 2769 | - $original_file=$conf->scanner->dir_temp.'/'.$fuser->id.'/'.$original_file; |
|
| 2768 | + $accessallowed = 1; |
|
| 2769 | + $original_file = $conf->scanner->dir_temp.'/'.$fuser->id.'/'.$original_file; |
|
| 2770 | 2770 | } |
| 2771 | 2771 | |
| 2772 | 2772 | // GENERIC Wrapping |
@@ -2776,89 +2776,89 @@ discard block |
||
| 2776 | 2776 | // If modulepart=module Allows any module to open a file if file is in directory called DOL_DATA_ROOT/modulepart |
| 2777 | 2777 | else |
| 2778 | 2778 | { |
| 2779 | - if (preg_match('/^specimen/i',$original_file)) $accessallowed=1; // If link to a file called specimen. Test must be done before changing $original_file int full path. |
|
| 2780 | - if ($fuser->admin) $accessallowed=1; // If user is admin |
|
| 2779 | + if (preg_match('/^specimen/i', $original_file)) $accessallowed = 1; // If link to a file called specimen. Test must be done before changing $original_file int full path. |
|
| 2780 | + if ($fuser->admin) $accessallowed = 1; // If user is admin |
|
| 2781 | 2781 | |
| 2782 | 2782 | // Define $accessallowed |
| 2783 | - if (preg_match('/^([a-z]+)_user_temp$/i',$modulepart,$reg)) |
|
| 2783 | + if (preg_match('/^([a-z]+)_user_temp$/i', $modulepart, $reg)) |
|
| 2784 | 2784 | { |
| 2785 | 2785 | if (empty($conf->{$reg[1]}->dir_temp)) // modulepart not supported |
| 2786 | 2786 | { |
| 2787 | - dol_print_error('','Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')'); |
|
| 2787 | + dol_print_error('', 'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')'); |
|
| 2788 | 2788 | exit; |
| 2789 | 2789 | } |
| 2790 | - if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) $accessallowed=1; |
|
| 2791 | - $original_file=$conf->{$reg[1]}->dir_temp.'/'.$fuser->id.'/'.$original_file; |
|
| 2790 | + if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) $accessallowed = 1; |
|
| 2791 | + $original_file = $conf->{$reg[1]}->dir_temp.'/'.$fuser->id.'/'.$original_file; |
|
| 2792 | 2792 | } |
| 2793 | - else if (preg_match('/^([a-z]+)_temp$/i',$modulepart,$reg)) |
|
| 2793 | + else if (preg_match('/^([a-z]+)_temp$/i', $modulepart, $reg)) |
|
| 2794 | 2794 | { |
| 2795 | 2795 | if (empty($conf->{$reg[1]}->dir_temp)) // modulepart not supported |
| 2796 | 2796 | { |
| 2797 | - dol_print_error('','Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')'); |
|
| 2797 | + dol_print_error('', 'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')'); |
|
| 2798 | 2798 | exit; |
| 2799 | 2799 | } |
| 2800 | - if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) $accessallowed=1; |
|
| 2801 | - $original_file=$conf->{$reg[1]}->dir_temp.'/'.$original_file; |
|
| 2800 | + if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) $accessallowed = 1; |
|
| 2801 | + $original_file = $conf->{$reg[1]}->dir_temp.'/'.$original_file; |
|
| 2802 | 2802 | } |
| 2803 | - else if (preg_match('/^([a-z]+)_user$/i',$modulepart,$reg)) |
|
| 2803 | + else if (preg_match('/^([a-z]+)_user$/i', $modulepart, $reg)) |
|
| 2804 | 2804 | { |
| 2805 | 2805 | if (empty($conf->{$reg[1]}->dir_output)) // modulepart not supported |
| 2806 | 2806 | { |
| 2807 | - dol_print_error('','Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')'); |
|
| 2807 | + dol_print_error('', 'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')'); |
|
| 2808 | 2808 | exit; |
| 2809 | 2809 | } |
| 2810 | - if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) $accessallowed=1; |
|
| 2811 | - $original_file=$conf->{$reg[1]}->dir_output.'/'.$fuser->id.'/'.$original_file; |
|
| 2810 | + if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) $accessallowed = 1; |
|
| 2811 | + $original_file = $conf->{$reg[1]}->dir_output.'/'.$fuser->id.'/'.$original_file; |
|
| 2812 | 2812 | } |
| 2813 | 2813 | else if (preg_match('/^massfilesarea_([a-z]+)$/i', $modulepart, $reg)) |
| 2814 | 2814 | { |
| 2815 | 2815 | if (empty($conf->{$reg[1]}->dir_output)) // modulepart not supported |
| 2816 | 2816 | { |
| 2817 | - dol_print_error('','Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')'); |
|
| 2817 | + dol_print_error('', 'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')'); |
|
| 2818 | 2818 | exit; |
| 2819 | 2819 | } |
| 2820 | 2820 | if ($fuser->rights->{$reg[1]}->{$lire} || preg_match('/^specimen/i', $original_file)) |
| 2821 | 2821 | { |
| 2822 | - $accessallowed=1; |
|
| 2822 | + $accessallowed = 1; |
|
| 2823 | 2823 | } |
| 2824 | - $original_file=$conf->{$reg[1]}->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; |
|
| 2824 | + $original_file = $conf->{$reg[1]}->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; |
|
| 2825 | 2825 | } |
| 2826 | 2826 | else |
| 2827 | 2827 | { |
| 2828 | 2828 | if (empty($conf->$modulepart->dir_output)) // modulepart not supported |
| 2829 | 2829 | { |
| 2830 | - dol_print_error('','Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')'); |
|
| 2830 | + dol_print_error('', 'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')'); |
|
| 2831 | 2831 | exit; |
| 2832 | 2832 | } |
| 2833 | 2833 | |
| 2834 | - $perm=GETPOST('perm'); |
|
| 2835 | - $subperm=GETPOST('subperm'); |
|
| 2834 | + $perm = GETPOST('perm'); |
|
| 2835 | + $subperm = GETPOST('subperm'); |
|
| 2836 | 2836 | if ($perm || $subperm) |
| 2837 | 2837 | { |
| 2838 | - if (($perm && ! $subperm && $fuser->rights->$modulepart->$perm) || ($perm && $subperm && $fuser->rights->$modulepart->$perm->$subperm)) $accessallowed=1; |
|
| 2839 | - $original_file=$conf->$modulepart->dir_output.'/'.$original_file; |
|
| 2838 | + if (($perm && !$subperm && $fuser->rights->$modulepart->$perm) || ($perm && $subperm && $fuser->rights->$modulepart->$perm->$subperm)) $accessallowed = 1; |
|
| 2839 | + $original_file = $conf->$modulepart->dir_output.'/'.$original_file; |
|
| 2840 | 2840 | } |
| 2841 | 2841 | else |
| 2842 | 2842 | { |
| 2843 | - if ($fuser->rights->$modulepart->{$lire} || $fuser->rights->$modulepart->{$read}) $accessallowed=1; |
|
| 2844 | - $original_file=$conf->$modulepart->dir_output.'/'.$original_file; |
|
| 2843 | + if ($fuser->rights->$modulepart->{$lire} || $fuser->rights->$modulepart->{$read}) $accessallowed = 1; |
|
| 2844 | + $original_file = $conf->$modulepart->dir_output.'/'.$original_file; |
|
| 2845 | 2845 | } |
| 2846 | 2846 | } |
| 2847 | 2847 | |
| 2848 | 2848 | // For modules who wants to manage different levels of permissions for documents |
| 2849 | 2849 | $subPermCategoryConstName = strtoupper($modulepart).'_SUBPERMCATEGORY_FOR_DOCUMENTS'; |
| 2850 | - if (! empty($conf->global->$subPermCategoryConstName)) |
|
| 2850 | + if (!empty($conf->global->$subPermCategoryConstName)) |
|
| 2851 | 2851 | { |
| 2852 | 2852 | $subPermCategory = $conf->global->$subPermCategoryConstName; |
| 2853 | - if (! empty($subPermCategory) && (($fuser->rights->$modulepart->$subPermCategory->{$lire}) || ($fuser->rights->$modulepart->$subPermCategory->{$read}) || ($fuser->rights->$modulepart->$subPermCategory->{$download}))) |
|
| 2853 | + if (!empty($subPermCategory) && (($fuser->rights->$modulepart->$subPermCategory->{$lire}) || ($fuser->rights->$modulepart->$subPermCategory->{$read}) || ($fuser->rights->$modulepart->$subPermCategory->{$download}))) |
|
| 2854 | 2854 | { |
| 2855 | - $accessallowed=1; |
|
| 2855 | + $accessallowed = 1; |
|
| 2856 | 2856 | } |
| 2857 | 2857 | } |
| 2858 | 2858 | |
| 2859 | 2859 | // Define $sqlprotectagainstexternals for modules who want to protect access using a SQL query. |
| 2860 | 2860 | $sqlProtectConstName = strtoupper($modulepart).'_SQLPROTECTAGAINSTEXTERNALS_FOR_DOCUMENTS'; |
| 2861 | - if (! empty($conf->global->$sqlProtectConstName)) // If module want to define its own $sqlprotectagainstexternals |
|
| 2861 | + if (!empty($conf->global->$sqlProtectConstName)) // If module want to define its own $sqlprotectagainstexternals |
|
| 2862 | 2862 | { |
| 2863 | 2863 | // Example: mymodule__SQLPROTECTAGAINSTEXTERNALS_FOR_DOCUMENTS = "SELECT fk_soc FROM ".MAIN_DB_PREFIX.$modulepart." WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity; |
| 2864 | 2864 | eval('$sqlprotectagainstexternals = "'.$conf->global->$sqlProtectConstName.'";'); |
@@ -2884,8 +2884,8 @@ discard block |
||
| 2884 | 2884 | */ |
| 2885 | 2885 | function dol_filecache($directory, $filename, $object) |
| 2886 | 2886 | { |
| 2887 | - if (! dol_is_dir($directory)) dol_mkdir($directory); |
|
| 2888 | - $cachefile = $directory . $filename; |
|
| 2887 | + if (!dol_is_dir($directory)) dol_mkdir($directory); |
|
| 2888 | + $cachefile = $directory.$filename; |
|
| 2889 | 2889 | file_put_contents($cachefile, serialize($object), LOCK_EX); |
| 2890 | 2890 | @chmod($cachefile, 0644); |
| 2891 | 2891 | } |
@@ -2901,8 +2901,8 @@ discard block |
||
| 2901 | 2901 | function dol_cache_refresh($directory, $filename, $cachetime) |
| 2902 | 2902 | { |
| 2903 | 2903 | $now = dol_now(); |
| 2904 | - $cachefile = $directory . $filename; |
|
| 2905 | - $refresh = !file_exists($cachefile) || ($now-$cachetime) > dol_filemtime($cachefile); |
|
| 2904 | + $cachefile = $directory.$filename; |
|
| 2905 | + $refresh = !file_exists($cachefile) || ($now - $cachetime) > dol_filemtime($cachefile); |
|
| 2906 | 2906 | return $refresh; |
| 2907 | 2907 | } |
| 2908 | 2908 | |
@@ -2915,7 +2915,7 @@ discard block |
||
| 2915 | 2915 | */ |
| 2916 | 2916 | function dol_readcachefile($directory, $filename) |
| 2917 | 2917 | { |
| 2918 | - $cachefile = $directory . $filename; |
|
| 2918 | + $cachefile = $directory.$filename; |
|
| 2919 | 2919 | $object = unserialize(file_get_contents($cachefile)); |
| 2920 | 2920 | return $object; |
| 2921 | 2921 | } |
@@ -98,16 +98,21 @@ discard block |
||
| 98 | 98 | // $hookmanager->resArray may contain array stacked by other modules |
| 99 | 99 | if (empty($reshook)) |
| 100 | 100 | { |
| 101 | - if (! is_dir($newpath)) return array(); |
|
| 101 | + if (! is_dir($newpath)) { |
|
| 102 | + return array(); |
|
| 103 | + } |
|
| 102 | 104 | |
| 103 | 105 | if ($dir = opendir($newpath)) |
| 104 | 106 | { |
| 105 | 107 | $filedate=''; |
| 106 | 108 | $filesize=''; |
| 107 | 109 | |
| 108 | - while (false !== ($file = readdir($dir))) // $file is always a basename (into directory $newpath) |
|
| 110 | + while (false !== ($file = readdir($dir))) { |
|
| 111 | + // $file is always a basename (into directory $newpath) |
|
| 109 | 112 | { |
| 110 | - if (! utf8_check($file)) $file=utf8_encode($file); // To be sure data is stored in utf8 in memory |
|
| 113 | + if (! utf8_check($file)) $file=utf8_encode($file); |
|
| 114 | + } |
|
| 115 | + // To be sure data is stored in utf8 in memory |
|
| 111 | 116 | $fullpathfile=($newpath?$newpath.'/':'').$file; |
| 112 | 117 | |
| 113 | 118 | $qualified=1; |
@@ -117,8 +122,9 @@ discard block |
||
| 117 | 122 | if (is_array($excludefilter)) |
| 118 | 123 | { |
| 119 | 124 | $excludefilterarray=array_merge($excludefilterarray,$excludefilter); |
| 125 | + } else if ($excludefilter) { |
|
| 126 | + $excludefilterarray[]=$excludefilter; |
|
| 120 | 127 | } |
| 121 | - else if ($excludefilter) $excludefilterarray[]=$excludefilter; |
|
| 122 | 128 | // Check if file is qualified |
| 123 | 129 | foreach($excludefilterarray as $filt) |
| 124 | 130 | { |
@@ -137,12 +143,18 @@ discard block |
||
| 137 | 143 | // Add entry into file_list array |
| 138 | 144 | if (($types=="directories") || ($types=="all")) |
| 139 | 145 | { |
| 140 | - if ($loaddate || $sortcriteria == 'date') $filedate=dol_filemtime($path."/".$file); |
|
| 141 | - if ($loadsize || $sortcriteria == 'size') $filesize=dol_filesize($path."/".$file); |
|
| 146 | + if ($loaddate || $sortcriteria == 'date') { |
|
| 147 | + $filedate=dol_filemtime($path."/".$file); |
|
| 148 | + } |
|
| 149 | + if ($loadsize || $sortcriteria == 'size') { |
|
| 150 | + $filesize=dol_filesize($path."/".$file); |
|
| 151 | + } |
|
| 142 | 152 | |
| 143 | - if (! $filter || preg_match('/'.$filter.'/i',$file)) // We do not search key $filter into all $path, only into $file part |
|
| 153 | + if (! $filter || preg_match('/'.$filter.'/i',$file)) { |
|
| 154 | + // We do not search key $filter into all $path, only into $file part |
|
| 144 | 155 | { |
| 145 | 156 | preg_match('/([^\/]+)\/[^\/]+$/',$path.'/'.$file,$reg); |
| 157 | + } |
|
| 146 | 158 | $level1name=(isset($reg[1])?$reg[1]:''); |
| 147 | 159 | $file_list[] = array( |
| 148 | 160 | "name" => $file, |
@@ -166,16 +178,21 @@ discard block |
||
| 166 | 178 | $file_list = array_merge($file_list, dol_dir_list($path."/".$file, $types, $recursive, $filter, $excludefilter, $sortcriteria, $sortorder, $mode, $nohook, ($relativename!=''?$relativename.'/':'').$file, $donotfollowsymlinks)); |
| 167 | 179 | } |
| 168 | 180 | } |
| 169 | - } |
|
| 170 | - else if (! $isdir && (($types == "files") || ($types == "all"))) |
|
| 181 | + } else if (! $isdir && (($types == "files") || ($types == "all"))) |
|
| 171 | 182 | { |
| 172 | 183 | // Add file into file_list array |
| 173 | - if ($loaddate || $sortcriteria == 'date') $filedate=dol_filemtime($path."/".$file); |
|
| 174 | - if ($loadsize || $sortcriteria == 'size') $filesize=dol_filesize($path."/".$file); |
|
| 184 | + if ($loaddate || $sortcriteria == 'date') { |
|
| 185 | + $filedate=dol_filemtime($path."/".$file); |
|
| 186 | + } |
|
| 187 | + if ($loadsize || $sortcriteria == 'size') { |
|
| 188 | + $filesize=dol_filesize($path."/".$file); |
|
| 189 | + } |
|
| 175 | 190 | |
| 176 | - if (! $filter || preg_match('/'.$filter.'/i',$file)) // We do not search key $filter into $path, only into $file |
|
| 191 | + if (! $filter || preg_match('/'.$filter.'/i',$file)) { |
|
| 192 | + // We do not search key $filter into $path, only into $file |
|
| 177 | 193 | { |
| 178 | 194 | preg_match('/([^\/]+)\/[^\/]+$/',$path.'/'.$file,$reg); |
| 195 | + } |
|
| 179 | 196 | $level1name=(isset($reg[1])?$reg[1]:''); |
| 180 | 197 | $file_list[] = array( |
| 181 | 198 | "name" => $file, |
@@ -202,12 +219,16 @@ discard block |
||
| 202 | 219 | $myarray[$key] = (isset($row[$sortcriteria])?$row[$sortcriteria]:''); |
| 203 | 220 | } |
| 204 | 221 | // Sort the data |
| 205 | - if ($sortorder) array_multisort($myarray, $sortorder, $file_list); |
|
| 222 | + if ($sortorder) { |
|
| 223 | + array_multisort($myarray, $sortorder, $file_list); |
|
| 224 | + } |
|
| 206 | 225 | } |
| 207 | 226 | } |
| 208 | 227 | } |
| 209 | 228 | |
| 210 | - if (is_object($hookmanager) && is_array($hookmanager->resArray)) $file_list = array_merge($file_list, $hookmanager->resArray); |
|
| 229 | + if (is_object($hookmanager) && is_array($hookmanager->resArray)) { |
|
| 230 | + $file_list = array_merge($file_list, $hookmanager->resArray); |
|
| 231 | + } |
|
| 211 | 232 | |
| 212 | 233 | return $file_list; |
| 213 | 234 | } |
@@ -232,7 +253,9 @@ discard block |
||
| 232 | 253 | |
| 233 | 254 | $sql =" SELECT rowid, label, entity, filename, filepath, fullpath_orig, keywords, cover, gen_or_uploaded, extraparams, date_c, date_m, fk_user_c, fk_user_m,"; |
| 234 | 255 | $sql.=" acl, position, share"; |
| 235 | - if ($mode) $sql.=", description"; |
|
| 256 | + if ($mode) { |
|
| 257 | + $sql.=", description"; |
|
| 258 | + } |
|
| 236 | 259 | $sql.=" FROM ".MAIN_DB_PREFIX."ecm_files"; |
| 237 | 260 | $sql.=" WHERE filepath = '".$db->escape($path)."'"; |
| 238 | 261 | $sql.=" AND entity = ".$conf->entity; |
@@ -280,12 +303,13 @@ discard block |
||
| 280 | 303 | $myarray[$key] = (isset($row[$sortcriteria])?$row[$sortcriteria]:''); |
| 281 | 304 | } |
| 282 | 305 | // Sort the data |
| 283 | - if ($sortorder) array_multisort($myarray, $sortorder, $file_list); |
|
| 306 | + if ($sortorder) { |
|
| 307 | + array_multisort($myarray, $sortorder, $file_list); |
|
| 308 | + } |
|
| 284 | 309 | } |
| 285 | 310 | |
| 286 | 311 | return $file_list; |
| 287 | - } |
|
| 288 | - else |
|
| 312 | + } else |
|
| 289 | 313 | { |
| 290 | 314 | dol_print_error($db); |
| 291 | 315 | return array(); |
@@ -313,8 +337,11 @@ discard block |
||
| 313 | 337 | global $object; |
| 314 | 338 | if (! empty($object->id)) |
| 315 | 339 | { |
| 316 | - if (! empty($conf->product->enabled)) $upload_dirold = $conf->product->multidir_output[$object->entity].'/'.substr(substr("000".$object->id, -2),1,1).'/'.substr(substr("000".$object->id, -2),0,1).'/'.$object->id."/photos"; |
|
| 317 | - else $upload_dirold = $conf->service->multidir_output[$object->entity].'/'.substr(substr("000".$object->id, -2),1,1).'/'.substr(substr("000".$object->id, -2),0,1).'/'.$object->id."/photos"; |
|
| 340 | + if (! empty($conf->product->enabled)) { |
|
| 341 | + $upload_dirold = $conf->product->multidir_output[$object->entity].'/'.substr(substr("000".$object->id, -2),1,1).'/'.substr(substr("000".$object->id, -2),0,1).'/'.$object->id."/photos"; |
|
| 342 | + } else { |
|
| 343 | + $upload_dirold = $conf->service->multidir_output[$object->entity].'/'.substr(substr("000".$object->id, -2),1,1).'/'.substr(substr("000".$object->id, -2),0,1).'/'.$object->id."/photos"; |
|
| 344 | + } |
|
| 318 | 345 | |
| 319 | 346 | $relativedirold = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $upload_dirold); |
| 320 | 347 | $relativedirold = preg_replace('/^[\\/]/','',$relativedirold); |
@@ -347,16 +374,21 @@ discard block |
||
| 347 | 374 | } |
| 348 | 375 | } |
| 349 | 376 | |
| 350 | - if (! $found) // This happen in transition toward version 6, or if files were added manually into os dir. |
|
| 377 | + if (! $found) { |
|
| 378 | + // This happen in transition toward version 6, or if files were added manually into os dir. |
|
| 351 | 379 | { |
| 352 | - $filearray[$key]['position']='999999'; // File not indexed are at end. So if we add a file, it will not replace an existing position |
|
| 380 | + $filearray[$key]['position']='999999'; |
|
| 381 | + } |
|
| 382 | + // File not indexed are at end. So if we add a file, it will not replace an existing position |
|
| 353 | 383 | $filearray[$key]['cover']=0; |
| 354 | 384 | $filearray[$key]['acl']=''; |
| 355 | 385 | |
| 356 | 386 | $rel_filename = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $filearray[$key]['fullname']); |
| 357 | - if (! preg_match('/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filetorenameafter)) // If not a tmp file |
|
| 387 | + if (! preg_match('/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filetorenameafter)) { |
|
| 388 | + // If not a tmp file |
|
| 358 | 389 | { |
| 359 | 390 | dol_syslog("list_of_documents We found a file called '".$filearray[$key]['name']."' not indexed into database. We add it"); |
| 391 | + } |
|
| 360 | 392 | include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; |
| 361 | 393 | $ecmfile=new EcmFiles($db); |
| 362 | 394 | |
@@ -377,13 +409,11 @@ discard block |
||
| 377 | 409 | if ($result < 0) |
| 378 | 410 | { |
| 379 | 411 | setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings'); |
| 380 | - } |
|
| 381 | - else |
|
| 412 | + } else |
|
| 382 | 413 | { |
| 383 | 414 | $filearray[$key]['rowid']=$result; |
| 384 | 415 | } |
| 385 | - } |
|
| 386 | - else |
|
| 416 | + } else |
|
| 387 | 417 | { |
| 388 | 418 | $filearray[$key]['rowid']=0; // Should not happened |
| 389 | 419 | } |
@@ -408,22 +438,27 @@ discard block |
||
| 408 | 438 | |
| 409 | 439 | $sortorder=strtoupper($sortorder); |
| 410 | 440 | |
| 411 | - if ($sortorder == 'ASC') { $retup=-1; $retdown=1; } |
|
| 412 | - else { $retup=1; $retdown=-1; } |
|
| 441 | + if ($sortorder == 'ASC') { $retup=-1; $retdown=1; } else { $retup=1; $retdown=-1; } |
|
| 413 | 442 | |
| 414 | 443 | if ($sortfield == 'name') |
| 415 | 444 | { |
| 416 | - if ($a->name == $b->name) return 0; |
|
| 445 | + if ($a->name == $b->name) { |
|
| 446 | + return 0; |
|
| 447 | + } |
|
| 417 | 448 | return ($a->name < $b->name) ? $retup : $retdown; |
| 418 | 449 | } |
| 419 | 450 | if ($sortfield == 'date') |
| 420 | 451 | { |
| 421 | - if ($a->date == $b->date) return 0; |
|
| 452 | + if ($a->date == $b->date) { |
|
| 453 | + return 0; |
|
| 454 | + } |
|
| 422 | 455 | return ($a->date < $b->date) ? $retup : $retdown; |
| 423 | 456 | } |
| 424 | 457 | if ($sortfield == 'size') |
| 425 | 458 | { |
| 426 | - if ($a->size == $b->size) return 0; |
|
| 459 | + if ($a->size == $b->size) { |
|
| 460 | + return 0; |
|
| 461 | + } |
|
| 427 | 462 | return ($a->size < $b->size) ? $retup : $retdown; |
| 428 | 463 | } |
| 429 | 464 | } |
@@ -438,9 +473,12 @@ discard block |
||
| 438 | 473 | function dol_is_dir($folder) |
| 439 | 474 | { |
| 440 | 475 | $newfolder=dol_osencode($folder); |
| 441 | - if (is_dir($newfolder)) return true; |
|
| 442 | - else return false; |
|
| 443 | -} |
|
| 476 | + if (is_dir($newfolder)) { |
|
| 477 | + return true; |
|
| 478 | + } else { |
|
| 479 | + return false; |
|
| 480 | + } |
|
| 481 | + } |
|
| 444 | 482 | |
| 445 | 483 | /** |
| 446 | 484 | * Return if path is a file |
@@ -477,7 +515,9 @@ discard block |
||
| 477 | 515 | $tmpprot=array('file','http','https','ftp','zlib','data','ssh','ssh2','ogg','expect'); |
| 478 | 516 | foreach($tmpprot as $prot) |
| 479 | 517 | { |
| 480 | - if (preg_match('/^'.$prot.':/i',$url)) return true; |
|
| 518 | + if (preg_match('/^'.$prot.':/i',$url)) { |
|
| 519 | + return true; |
|
| 520 | + } |
|
| 481 | 521 | } |
| 482 | 522 | return false; |
| 483 | 523 | } |
@@ -499,15 +539,21 @@ discard block |
||
| 499 | 539 | { |
| 500 | 540 | $name_array[] = $name; |
| 501 | 541 | } |
| 502 | - foreach($name_array as $temp) $folder_content .= $temp; |
|
| 542 | + foreach($name_array as $temp) { |
|
| 543 | + $folder_content .= $temp; |
|
| 544 | + } |
|
| 503 | 545 | |
| 504 | 546 | closedir($handle); |
| 505 | 547 | |
| 506 | - if ($folder_content == "...") return true; |
|
| 507 | - else return false; |
|
| 548 | + if ($folder_content == "...") { |
|
| 549 | + return true; |
|
| 550 | + } else { |
|
| 551 | + return false; |
|
| 552 | + } |
|
| 553 | + } else { |
|
| 554 | + return true; |
|
| 508 | 555 | } |
| 509 | - else |
|
| 510 | - return true; // Dir does not exists |
|
| 556 | + // Dir does not exists |
|
| 511 | 557 | } |
| 512 | 558 | |
| 513 | 559 | /** |
@@ -530,11 +576,12 @@ discard block |
||
| 530 | 576 | { |
| 531 | 577 | $line=fgets($fp); |
| 532 | 578 | // We increase count only if read was success. We need test because feof return true only after fgets so we do n+1 fgets for a file with n lines. |
| 533 | - if (! $line === false) $nb++; |
|
| 579 | + if (! $line === false) { |
|
| 580 | + $nb++; |
|
| 581 | + } |
|
| 534 | 582 | } |
| 535 | 583 | fclose($fp); |
| 536 | - } |
|
| 537 | - else |
|
| 584 | + } else |
|
| 538 | 585 | { |
| 539 | 586 | $nb=-1; |
| 540 | 587 | } |
@@ -584,11 +631,17 @@ discard block |
||
| 584 | 631 | |
| 585 | 632 | dol_syslog("files.lib.php::dolReplaceInFile srcfile=".$srcfile." destfile=".$destfile." newmask=".$newmask." indexdatabase=".$indexdatabase); |
| 586 | 633 | |
| 587 | - if (empty($srcfile)) return -1; |
|
| 588 | - if (empty($destfile)) $destfile=$srcfile; |
|
| 634 | + if (empty($srcfile)) { |
|
| 635 | + return -1; |
|
| 636 | + } |
|
| 637 | + if (empty($destfile)) { |
|
| 638 | + $destfile=$srcfile; |
|
| 639 | + } |
|
| 589 | 640 | |
| 590 | 641 | $destexists=dol_is_file($destfile); |
| 591 | - if (($destfile != $srcfile) && $destexists) return 0; |
|
| 642 | + if (($destfile != $srcfile) && $destexists) { |
|
| 643 | + return 0; |
|
| 644 | + } |
|
| 592 | 645 | |
| 593 | 646 | $tmpdestfile=$destfile.'.tmp'; |
| 594 | 647 | |
@@ -625,10 +678,14 @@ discard block |
||
| 625 | 678 | dol_syslog("files.lib.php::dolReplaceInFile failed to move tmp file to final dest", LOG_WARNING); |
| 626 | 679 | return -3; |
| 627 | 680 | } |
| 628 | - if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK; |
|
| 629 | - if (empty($newmask)) // This should no happen |
|
| 681 | + if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) { |
|
| 682 | + $newmask=$conf->global->MAIN_UMASK; |
|
| 683 | + } |
|
| 684 | + if (empty($newmask)) { |
|
| 685 | + // This should no happen |
|
| 630 | 686 | { |
| 631 | 687 | dol_syslog("Warning: dolReplaceInFile called with empty value for newmask and no default value defined", LOG_WARNING); |
| 688 | + } |
|
| 632 | 689 | $newmask='0664'; |
| 633 | 690 | } |
| 634 | 691 | |
@@ -669,10 +726,14 @@ discard block |
||
| 669 | 726 | |
| 670 | 727 | dol_syslog("files.lib.php::dol_copy srcfile=".$srcfile." destfile=".$destfile." newmask=".$newmask." overwriteifexists=".$overwriteifexists); |
| 671 | 728 | |
| 672 | - if (empty($srcfile) || empty($destfile)) return -1; |
|
| 729 | + if (empty($srcfile) || empty($destfile)) { |
|
| 730 | + return -1; |
|
| 731 | + } |
|
| 673 | 732 | |
| 674 | 733 | $destexists=dol_is_file($destfile); |
| 675 | - if (! $overwriteifexists && $destexists) return 0; |
|
| 734 | + if (! $overwriteifexists && $destexists) { |
|
| 735 | + return 0; |
|
| 736 | + } |
|
| 676 | 737 | |
| 677 | 738 | $newpathofsrcfile=dol_osencode($srcfile); |
| 678 | 739 | $newpathofdestfile=dol_osencode($destfile); |
@@ -696,10 +757,14 @@ discard block |
||
| 696 | 757 | dol_syslog("files.lib.php::dol_copy failed to copy", LOG_WARNING); |
| 697 | 758 | return -3; |
| 698 | 759 | } |
| 699 | - if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK; |
|
| 700 | - if (empty($newmask)) // This should no happen |
|
| 760 | + if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) { |
|
| 761 | + $newmask=$conf->global->MAIN_UMASK; |
|
| 762 | + } |
|
| 763 | + if (empty($newmask)) { |
|
| 764 | + // This should no happen |
|
| 701 | 765 | { |
| 702 | 766 | dol_syslog("Warning: dol_copy called with empty value for newmask and no default value defined", LOG_WARNING); |
| 767 | + } |
|
| 703 | 768 | $newmask='0664'; |
| 704 | 769 | } |
| 705 | 770 | |
@@ -727,7 +792,9 @@ discard block |
||
| 727 | 792 | |
| 728 | 793 | dol_syslog("files.lib.php::dolCopyDir srcfile=".$srcfile." destfile=".$destfile." newmask=".$newmask." overwriteifexists=".$overwriteifexists); |
| 729 | 794 | |
| 730 | - if (empty($srcfile) || empty($destfile)) return -1; |
|
| 795 | + if (empty($srcfile) || empty($destfile)) { |
|
| 796 | + return -1; |
|
| 797 | + } |
|
| 731 | 798 | |
| 732 | 799 | $destexists=dol_is_dir($destfile); |
| 733 | 800 | //if (! $overwriteifexists && $destexists) return 0; // The overwriteifexists is for files only, so propagated to dol_copy only. |
@@ -737,7 +804,9 @@ discard block |
||
| 737 | 804 | // We must set mask just before creating dir, becaause it can be set differently by dol_copy |
| 738 | 805 | umask(0); |
| 739 | 806 | $dirmaskdec=octdec($newmask); |
| 740 | - if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) $dirmaskdec=octdec($conf->global->MAIN_UMASK); |
|
| 807 | + if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) { |
|
| 808 | + $dirmaskdec=octdec($conf->global->MAIN_UMASK); |
|
| 809 | + } |
|
| 741 | 810 | $dirmaskdec |= octdec('0200'); // Set w bit required to be able to create content for recursive subdirs files |
| 742 | 811 | dol_mkdir($destfile, '', decoct($dirmaskdec)); |
| 743 | 812 | } |
@@ -757,8 +826,7 @@ discard block |
||
| 757 | 826 | { |
| 758 | 827 | //var_dump("xxx dolCopyDir $srcfile/$file, $destfile/$file, $newmask, $overwriteifexists"); |
| 759 | 828 | $tmpresult=dolCopyDir($srcfile."/".$file, $destfile."/".$file, $newmask, $overwriteifexists, $arrayreplacement); |
| 760 | - } |
|
| 761 | - else |
|
| 829 | + } else |
|
| 762 | 830 | { |
| 763 | 831 | $newfile = $file; |
| 764 | 832 | // Replace destination filename with a new one |
@@ -775,17 +843,17 @@ discard block |
||
| 775 | 843 | if ($result > 0 && $tmpresult >= 0) |
| 776 | 844 | { |
| 777 | 845 | // Do nothing, so we don't set result to 0 if tmpresult is 0 and result was success in a previous pass |
| 778 | - } |
|
| 779 | - else |
|
| 846 | + } else |
|
| 780 | 847 | { |
| 781 | 848 | $result=$tmpresult; |
| 782 | 849 | } |
| 783 | - if ($result < 0) break; |
|
| 850 | + if ($result < 0) { |
|
| 851 | + break; |
|
| 852 | + } |
|
| 784 | 853 | } |
| 785 | 854 | } |
| 786 | 855 | closedir($dir_handle); |
| 787 | - } |
|
| 788 | - else |
|
| 856 | + } else |
|
| 789 | 857 | { |
| 790 | 858 | // Source directory does not exists |
| 791 | 859 | $result = -2; |
@@ -852,8 +920,9 @@ discard block |
||
| 852 | 920 | // We force delete and try again. Rename function sometimes fails to replace dest file with some windows NTFS partitions. |
| 853 | 921 | dol_delete_file($destfile); |
| 854 | 922 | $result=@rename($newpathofsrcfile, $newpathofdestfile); // To see errors, remove @ |
| 923 | + } else { |
|
| 924 | + dol_syslog("files.lib.php::dol_move Failed.", LOG_WARNING); |
|
| 855 | 925 | } |
| 856 | - else dol_syslog("files.lib.php::dol_move Failed.", LOG_WARNING); |
|
| 857 | 926 | } |
| 858 | 927 | |
| 859 | 928 | // Move ok |
@@ -862,9 +931,11 @@ discard block |
||
| 862 | 931 | // Rename entry into ecm database |
| 863 | 932 | $rel_filetorenamebefore = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $srcfile); |
| 864 | 933 | $rel_filetorenameafter = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $destfile); |
| 865 | - if (! preg_match('/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filetorenameafter)) // If not a tmp file |
|
| 934 | + if (! preg_match('/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filetorenameafter)) { |
|
| 935 | + // If not a tmp file |
|
| 866 | 936 | { |
| 867 | 937 | $rel_filetorenamebefore = preg_replace('/^[\\/]/', '', $rel_filetorenamebefore); |
| 938 | + } |
|
| 868 | 939 | $rel_filetorenameafter = preg_replace('/^[\\/]/', '', $rel_filetorenameafter); |
| 869 | 940 | //var_dump($rel_filetorenamebefore.' - '.$rel_filetorenameafter); |
| 870 | 941 | |
@@ -873,16 +944,20 @@ discard block |
||
| 873 | 944 | |
| 874 | 945 | $ecmfiletarget=new EcmFiles($db); |
| 875 | 946 | $resultecmtarget = $ecmfiletarget->fetch(0, '', $rel_filetorenameafter); |
| 876 | - if ($resultecmtarget > 0) // An entry for target name already exists for target, we delete it, a new one will be created. |
|
| 947 | + if ($resultecmtarget > 0) { |
|
| 948 | + // An entry for target name already exists for target, we delete it, a new one will be created. |
|
| 877 | 949 | { |
| 878 | 950 | $ecmfiletarget->delete($user); |
| 879 | 951 | } |
| 952 | + } |
|
| 880 | 953 | |
| 881 | 954 | $ecmfile=new EcmFiles($db); |
| 882 | 955 | $resultecm = $ecmfile->fetch(0, '', $rel_filetorenamebefore); |
| 883 | - if ($resultecm > 0) // If an entry was found for src file, we use it to move entry |
|
| 956 | + if ($resultecm > 0) { |
|
| 957 | + // If an entry was found for src file, we use it to move entry |
|
| 884 | 958 | { |
| 885 | 959 | $filename = basename($rel_filetorenameafter); |
| 960 | + } |
|
| 886 | 961 | $rel_dir = dirname($rel_filetorenameafter); |
| 887 | 962 | $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir); |
| 888 | 963 | $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir); |
@@ -890,10 +965,11 @@ discard block |
||
| 890 | 965 | $ecmfile->filepath = $rel_dir; |
| 891 | 966 | $ecmfile->filename = $filename; |
| 892 | 967 | $resultecm = $ecmfile->update($user); |
| 893 | - } |
|
| 894 | - elseif ($resultecm == 0) // If no entry were found for src files, create/update target file |
|
| 968 | + } elseif ($resultecm == 0) { |
|
| 969 | + // If no entry were found for src files, create/update target file |
|
| 895 | 970 | { |
| 896 | 971 | $filename = basename($rel_filetorenameafter); |
| 972 | + } |
|
| 897 | 973 | $rel_dir = dirname($rel_filetorenameafter); |
| 898 | 974 | $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir); |
| 899 | 975 | $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir); |
@@ -910,18 +986,22 @@ discard block |
||
| 910 | 986 | { |
| 911 | 987 | setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings'); |
| 912 | 988 | } |
| 913 | - } |
|
| 914 | - elseif ($resultecm < 0) |
|
| 989 | + } elseif ($resultecm < 0) |
|
| 915 | 990 | { |
| 916 | 991 | setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings'); |
| 917 | 992 | } |
| 918 | 993 | |
| 919 | - if ($resultecm > 0) $result=true; |
|
| 920 | - else $result = false; |
|
| 994 | + if ($resultecm > 0) { |
|
| 995 | + $result=true; |
|
| 996 | + } else { |
|
| 997 | + $result = false; |
|
| 998 | + } |
|
| 921 | 999 | } |
| 922 | 1000 | } |
| 923 | 1001 | |
| 924 | - if (empty($newmask)) $newmask=empty($conf->global->MAIN_UMASK)?'0755':$conf->global->MAIN_UMASK; |
|
| 1002 | + if (empty($newmask)) { |
|
| 1003 | + $newmask=empty($conf->global->MAIN_UMASK)?'0755':$conf->global->MAIN_UMASK; |
|
| 1004 | + } |
|
| 925 | 1005 | $newmaskdec=octdec($newmask); |
| 926 | 1006 | // Currently method is restricted to files (dol_delete_files previously used is for files, and mask usage if for files too) |
| 927 | 1007 | // to allow mask usage for dir, we shoul introduce a new param "isdir" to 1 to complete newmask like this |
@@ -965,9 +1045,11 @@ discard block |
||
| 965 | 1045 | } |
| 966 | 1046 | $antivir=new AntiVir($db); |
| 967 | 1047 | $result = $antivir->dol_avscan_file($src_file); |
| 968 | - if ($result < 0) // If virus or error, we stop here |
|
| 1048 | + if ($result < 0) { |
|
| 1049 | + // If virus or error, we stop here |
|
| 969 | 1050 | { |
| 970 | 1051 | $reterrors=$antivir->errors; |
| 1052 | + } |
|
| 971 | 1053 | return $reterrors; |
| 972 | 1054 | } |
| 973 | 1055 | } |
@@ -1075,13 +1157,17 @@ discard block |
||
| 1075 | 1157 | } |
| 1076 | 1158 | } |
| 1077 | 1159 | |
| 1078 | - if ($reshook < 0) // At least one blocking error returned by one hook |
|
| 1160 | + if ($reshook < 0) { |
|
| 1161 | + // At least one blocking error returned by one hook |
|
| 1079 | 1162 | { |
| 1080 | 1163 | $errmsg = join(',', $hookmanager->errors); |
| 1081 | - if (empty($errmsg)) $errmsg = 'ErrorReturnedBySomeHooks'; // Should not occurs. Added if hook is bugged and does not set ->errors when there is error. |
|
| 1082 | - return $errmsg; |
|
| 1083 | 1164 | } |
| 1084 | - elseif (empty($reshook)) |
|
| 1165 | + if (empty($errmsg)) { |
|
| 1166 | + $errmsg = 'ErrorReturnedBySomeHooks'; |
|
| 1167 | + } |
|
| 1168 | + // Should not occurs. Added if hook is bugged and does not set ->errors when there is error. |
|
| 1169 | + return $errmsg; |
|
| 1170 | + } elseif (empty($reshook)) |
|
| 1085 | 1171 | { |
| 1086 | 1172 | // The file functions must be in OS filesystem encoding. |
| 1087 | 1173 | $src_file_osencoded=dol_osencode($src_file); |
@@ -1108,11 +1194,12 @@ discard block |
||
| 1108 | 1194 | $return=move_uploaded_file($src_file_osencoded, $file_name_osencoded); |
| 1109 | 1195 | if ($return) |
| 1110 | 1196 | { |
| 1111 | - if (! empty($conf->global->MAIN_UMASK)) @chmod($file_name_osencoded, octdec($conf->global->MAIN_UMASK)); |
|
| 1197 | + if (! empty($conf->global->MAIN_UMASK)) { |
|
| 1198 | + @chmod($file_name_osencoded, octdec($conf->global->MAIN_UMASK)); |
|
| 1199 | + } |
|
| 1112 | 1200 | dol_syslog("Files.lib::dol_move_uploaded_file Success to move ".$src_file." to ".$file_name." - Umask=".$conf->global->MAIN_UMASK, LOG_DEBUG); |
| 1113 | 1201 | return 1; // Success |
| 1114 | - } |
|
| 1115 | - else |
|
| 1202 | + } else |
|
| 1116 | 1203 | { |
| 1117 | 1204 | dol_syslog("Files.lib::dol_move_uploaded_file Failed to move ".$src_file." to ".$file_name, LOG_ERR); |
| 1118 | 1205 | return -3; // Unknown error |
@@ -1167,12 +1254,13 @@ discard block |
||
| 1167 | 1254 | $reshook=$hookmanager->executeHooks('deleteFile', $parameters, $object); |
| 1168 | 1255 | } |
| 1169 | 1256 | |
| 1170 | - if (empty($nohook) && $reshook != 0) // reshook = 0 to do standard actions, 1 = ok, -1 = ko |
|
| 1257 | + if (empty($nohook) && $reshook != 0) { |
|
| 1258 | + // reshook = 0 to do standard actions, 1 = ok, -1 = ko |
|
| 1171 | 1259 | { |
| 1172 | 1260 | if ($reshook < 0) return false; |
| 1173 | - return true; |
|
| 1174 | 1261 | } |
| 1175 | - else |
|
| 1262 | + return true; |
|
| 1263 | + } else |
|
| 1176 | 1264 | { |
| 1177 | 1265 | $error=0; |
| 1178 | 1266 | |
@@ -1188,21 +1276,28 @@ discard block |
||
| 1188 | 1276 | { |
| 1189 | 1277 | foreach ($listofdir as $filename) |
| 1190 | 1278 | { |
| 1191 | - if ($nophperrors) $ok=@unlink($filename); |
|
| 1192 | - else $ok=unlink($filename); |
|
| 1279 | + if ($nophperrors) { |
|
| 1280 | + $ok=@unlink($filename); |
|
| 1281 | + } else { |
|
| 1282 | + $ok=unlink($filename); |
|
| 1283 | + } |
|
| 1193 | 1284 | if ($ok) |
| 1194 | 1285 | { |
| 1195 | 1286 | dol_syslog("Removed file ".$filename, LOG_DEBUG); |
| 1196 | 1287 | |
| 1197 | 1288 | // Delete entry into ecm database |
| 1198 | 1289 | $rel_filetodelete = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $filename); |
| 1199 | - if (! preg_match('/(\/temp\/|\/thumbs\/|\.meta$)/', $rel_filetodelete)) // If not a tmp file |
|
| 1290 | + if (! preg_match('/(\/temp\/|\/thumbs\/|\.meta$)/', $rel_filetodelete)) { |
|
| 1291 | + // If not a tmp file |
|
| 1200 | 1292 | { |
| 1201 | 1293 | $rel_filetodelete = preg_replace('/^[\\/]/', '', $rel_filetodelete); |
| 1294 | + } |
|
| 1202 | 1295 | |
| 1203 | - if (is_object($db) && $indexdatabase) // $db may not be defined when lib is in a context with define('NOREQUIREDB',1) |
|
| 1296 | + if (is_object($db) && $indexdatabase) { |
|
| 1297 | + // $db may not be defined when lib is in a context with define('NOREQUIREDB',1) |
|
| 1204 | 1298 | { |
| 1205 | 1299 | dol_syslog("Try to remove also entries in database for full relative path = ".$rel_filetodelete, LOG_DEBUG); |
| 1300 | + } |
|
| 1206 | 1301 | include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; |
| 1207 | 1302 | $ecmfile=new EcmFiles($db); |
| 1208 | 1303 | $result = $ecmfile->fetch(0, '', $rel_filetodelete); |
@@ -1216,21 +1311,28 @@ discard block |
||
| 1216 | 1311 | } |
| 1217 | 1312 | } |
| 1218 | 1313 | } |
| 1314 | + } else { |
|
| 1315 | + dol_syslog("Failed to remove file ".$filename, LOG_WARNING); |
|
| 1219 | 1316 | } |
| 1220 | - else dol_syslog("Failed to remove file ".$filename, LOG_WARNING); |
|
| 1221 | 1317 | // TODO Failure to remove can be because file was already removed or because of permission |
| 1222 | 1318 | // If error because it does not exists, we should return true, and we should return false if this is a permission problem |
| 1223 | 1319 | } |
| 1320 | + } else { |
|
| 1321 | + dol_syslog("No files to delete found", LOG_DEBUG); |
|
| 1224 | 1322 | } |
| 1225 | - else dol_syslog("No files to delete found", LOG_DEBUG); |
|
| 1226 | - } |
|
| 1227 | - else |
|
| 1323 | + } else |
|
| 1228 | 1324 | { |
| 1229 | 1325 | $ok=false; |
| 1230 | - if ($nophperrors) $ok=@unlink($file_osencoded); |
|
| 1231 | - else $ok=unlink($file_osencoded); |
|
| 1232 | - if ($ok) dol_syslog("Removed file ".$file_osencoded, LOG_DEBUG); |
|
| 1233 | - else dol_syslog("Failed to remove file ".$file_osencoded, LOG_WARNING); |
|
| 1326 | + if ($nophperrors) { |
|
| 1327 | + $ok=@unlink($file_osencoded); |
|
| 1328 | + } else { |
|
| 1329 | + $ok=unlink($file_osencoded); |
|
| 1330 | + } |
|
| 1331 | + if ($ok) { |
|
| 1332 | + dol_syslog("Removed file ".$file_osencoded, LOG_DEBUG); |
|
| 1333 | + } else { |
|
| 1334 | + dol_syslog("Failed to remove file ".$file_osencoded, LOG_WARNING); |
|
| 1335 | + } |
|
| 1234 | 1336 | } |
| 1235 | 1337 | |
| 1236 | 1338 | return $ok; |
@@ -1280,19 +1382,23 @@ discard block |
||
| 1280 | 1382 | { |
| 1281 | 1383 | while (false !== ($item = readdir($handle))) |
| 1282 | 1384 | { |
| 1283 | - if (! utf8_check($item)) $item=utf8_encode($item); // should be useless |
|
| 1385 | + if (! utf8_check($item)) { |
|
| 1386 | + $item=utf8_encode($item); |
|
| 1387 | + } |
|
| 1388 | + // should be useless |
|
| 1284 | 1389 | |
| 1285 | 1390 | if ($item != "." && $item != "..") |
| 1286 | 1391 | { |
| 1287 | 1392 | if (is_dir(dol_osencode("$dir/$item")) && ! is_link(dol_osencode("$dir/$item"))) |
| 1288 | 1393 | { |
| 1289 | 1394 | $count=dol_delete_dir_recursive("$dir/$item", $count, $nophperrors, 0, $countdeleted); |
| 1290 | - } |
|
| 1291 | - else |
|
| 1395 | + } else |
|
| 1292 | 1396 | { |
| 1293 | 1397 | $result=dol_delete_file("$dir/$item", 1, $nophperrors); |
| 1294 | 1398 | $count++; |
| 1295 | - if ($result) $countdeleted++; |
|
| 1399 | + if ($result) { |
|
| 1400 | + $countdeleted++; |
|
| 1401 | + } |
|
| 1296 | 1402 | //else print 'Error on '.$item."\n"; |
| 1297 | 1403 | } |
| 1298 | 1404 | } |
@@ -1303,7 +1409,9 @@ discard block |
||
| 1303 | 1409 | { |
| 1304 | 1410 | $result=dol_delete_dir($dir, $nophperrors); |
| 1305 | 1411 | $count++; |
| 1306 | - if ($result) $countdeleted++; |
|
| 1412 | + if ($result) { |
|
| 1413 | + $countdeleted++; |
|
| 1414 | + } |
|
| 1307 | 1415 | //else print 'Error on '.$dir."\n"; |
| 1308 | 1416 | } |
| 1309 | 1417 | } |
@@ -1328,15 +1436,25 @@ discard block |
||
| 1328 | 1436 | // Define parent dir of elements |
| 1329 | 1437 | $element = $object->element; |
| 1330 | 1438 | |
| 1331 | - if ($object->element == 'order_supplier') $dir = $conf->fournisseur->commande->dir_output; |
|
| 1332 | - elseif ($object->element == 'invoice_supplier') $dir = $conf->fournisseur->facture->dir_output; |
|
| 1333 | - elseif ($object->element == 'project') $dir = $conf->projet->dir_output; |
|
| 1334 | - elseif ($object->element == 'shipping') $dir = $conf->expedition->dir_output.'/sending'; |
|
| 1335 | - elseif ($object->element == 'delivery') $dir = $conf->expedition->dir_output.'/receipt'; |
|
| 1336 | - elseif ($object->element == 'fichinter') $dir = $conf->ficheinter->dir_output; |
|
| 1337 | - else $dir=empty($conf->$element->dir_output)?'':$conf->$element->dir_output; |
|
| 1439 | + if ($object->element == 'order_supplier') { |
|
| 1440 | + $dir = $conf->fournisseur->commande->dir_output; |
|
| 1441 | + } elseif ($object->element == 'invoice_supplier') { |
|
| 1442 | + $dir = $conf->fournisseur->facture->dir_output; |
|
| 1443 | + } elseif ($object->element == 'project') { |
|
| 1444 | + $dir = $conf->projet->dir_output; |
|
| 1445 | + } elseif ($object->element == 'shipping') { |
|
| 1446 | + $dir = $conf->expedition->dir_output.'/sending'; |
|
| 1447 | + } elseif ($object->element == 'delivery') { |
|
| 1448 | + $dir = $conf->expedition->dir_output.'/receipt'; |
|
| 1449 | + } elseif ($object->element == 'fichinter') { |
|
| 1450 | + $dir = $conf->ficheinter->dir_output; |
|
| 1451 | + } else { |
|
| 1452 | + $dir=empty($conf->$element->dir_output)?'':$conf->$element->dir_output; |
|
| 1453 | + } |
|
| 1338 | 1454 | |
| 1339 | - if (empty($dir)) return 'ErrorObjectNoSupportedByFunction'; |
|
| 1455 | + if (empty($dir)) { |
|
| 1456 | + return 'ErrorObjectNoSupportedByFunction'; |
|
| 1457 | + } |
|
| 1340 | 1458 | |
| 1341 | 1459 | $refsan = dol_sanitizeFileName($object->ref); |
| 1342 | 1460 | $dir = $dir . "/" . $refsan ; |
@@ -1369,8 +1487,7 @@ discard block |
||
| 1369 | 1487 | $object->error=$langs->trans("ErrorFailedToDeleteFile",$filepreviewold); |
| 1370 | 1488 | return 0; |
| 1371 | 1489 | } |
| 1372 | - } |
|
| 1373 | - else |
|
| 1490 | + } else |
|
| 1374 | 1491 | { |
| 1375 | 1492 | $multiple = $filepreviewold . "."; |
| 1376 | 1493 | for ($i = 0; $i < 20; $i++) |
@@ -1404,18 +1521,29 @@ discard block |
||
| 1404 | 1521 | global $conf; |
| 1405 | 1522 | |
| 1406 | 1523 | // Create meta file |
| 1407 | - if (empty($conf->global->MAIN_DOC_CREATE_METAFILE)) return 0; // By default, no metafile. |
|
| 1524 | + if (empty($conf->global->MAIN_DOC_CREATE_METAFILE)) { |
|
| 1525 | + return 0; |
|
| 1526 | + } |
|
| 1527 | + // By default, no metafile. |
|
| 1408 | 1528 | |
| 1409 | 1529 | // Define parent dir of elements |
| 1410 | 1530 | $element=$object->element; |
| 1411 | 1531 | |
| 1412 | - if ($object->element == 'order_supplier') $dir = $conf->fournisseur->dir_output.'/commande'; |
|
| 1413 | - elseif ($object->element == 'invoice_supplier') $dir = $conf->fournisseur->dir_output.'/facture'; |
|
| 1414 | - elseif ($object->element == 'project') $dir = $conf->projet->dir_output; |
|
| 1415 | - elseif ($object->element == 'shipping') $dir = $conf->expedition->dir_output.'/sending'; |
|
| 1416 | - elseif ($object->element == 'delivery') $dir = $conf->expedition->dir_output.'/receipt'; |
|
| 1417 | - elseif ($object->element == 'fichinter') $dir = $conf->ficheinter->dir_output; |
|
| 1418 | - else $dir=empty($conf->$element->dir_output)?'':$conf->$element->dir_output; |
|
| 1532 | + if ($object->element == 'order_supplier') { |
|
| 1533 | + $dir = $conf->fournisseur->dir_output.'/commande'; |
|
| 1534 | + } elseif ($object->element == 'invoice_supplier') { |
|
| 1535 | + $dir = $conf->fournisseur->dir_output.'/facture'; |
|
| 1536 | + } elseif ($object->element == 'project') { |
|
| 1537 | + $dir = $conf->projet->dir_output; |
|
| 1538 | + } elseif ($object->element == 'shipping') { |
|
| 1539 | + $dir = $conf->expedition->dir_output.'/sending'; |
|
| 1540 | + } elseif ($object->element == 'delivery') { |
|
| 1541 | + $dir = $conf->expedition->dir_output.'/receipt'; |
|
| 1542 | + } elseif ($object->element == 'fichinter') { |
|
| 1543 | + $dir = $conf->ficheinter->dir_output; |
|
| 1544 | + } else { |
|
| 1545 | + $dir=empty($conf->$element->dir_output)?'':$conf->$element->dir_output; |
|
| 1546 | + } |
|
| 1419 | 1547 | |
| 1420 | 1548 | if ($dir) |
| 1421 | 1549 | { |
@@ -1455,12 +1583,12 @@ discard block |
||
| 1455 | 1583 | $fp = fopen($file,"w"); |
| 1456 | 1584 | fputs($fp,$meta); |
| 1457 | 1585 | fclose($fp); |
| 1458 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 1459 | - @chmod($file, octdec($conf->global->MAIN_UMASK)); |
|
| 1586 | + if (! empty($conf->global->MAIN_UMASK)) { |
|
| 1587 | + @chmod($file, octdec($conf->global->MAIN_UMASK)); |
|
| 1588 | + } |
|
| 1460 | 1589 | |
| 1461 | 1590 | return 1; |
| 1462 | - } |
|
| 1463 | - else |
|
| 1591 | + } else |
|
| 1464 | 1592 | { |
| 1465 | 1593 | dol_syslog('FailedToDetectDirInDolMetaCreateFor'.$object->element, LOG_WARNING); |
| 1466 | 1594 | } |
@@ -1522,9 +1650,11 @@ discard block |
||
| 1522 | 1650 | |
| 1523 | 1651 | $res = 0; |
| 1524 | 1652 | |
| 1525 | - if (! empty($_FILES[$varfiles])) // For view $_FILES[$varfiles]['error'] |
|
| 1653 | + if (! empty($_FILES[$varfiles])) { |
|
| 1654 | + // For view $_FILES[$varfiles]['error'] |
|
| 1526 | 1655 | { |
| 1527 | 1656 | dol_syslog('dol_add_file_process upload_dir='.$upload_dir.' allowoverwrite='.$allowoverwrite.' donotupdatesession='.$donotupdatesession.' savingdocmask='.$savingdocmask, LOG_DEBUG); |
| 1657 | + } |
|
| 1528 | 1658 | if (dol_mkdir($upload_dir) >= 0) |
| 1529 | 1659 | { |
| 1530 | 1660 | $TFile = $_FILES[$varfiles]; |
@@ -1558,9 +1688,11 @@ discard block |
||
| 1558 | 1688 | |
| 1559 | 1689 | $resupload = dol_move_uploaded_file($TFile['tmp_name'][$i], $destfull, $allowoverwrite, 0, $TFile['error'][$i], 0, $varfiles); |
| 1560 | 1690 | |
| 1561 | - if (is_numeric($resupload) && $resupload > 0) // $resupload can be 'ErrorFileAlreadyExists' |
|
| 1691 | + if (is_numeric($resupload) && $resupload > 0) { |
|
| 1692 | + // $resupload can be 'ErrorFileAlreadyExists' |
|
| 1562 | 1693 | { |
| 1563 | 1694 | global $maxwidthsmall, $maxheightsmall, $maxwidthmini, $maxheightmini; |
| 1695 | + } |
|
| 1564 | 1696 | |
| 1565 | 1697 | include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; |
| 1566 | 1698 | |
@@ -1600,19 +1732,20 @@ discard block |
||
| 1600 | 1732 | } |
| 1601 | 1733 | |
| 1602 | 1734 | $nbok++; |
| 1603 | - } |
|
| 1604 | - else |
|
| 1735 | + } else |
|
| 1605 | 1736 | { |
| 1606 | 1737 | $langs->load("errors"); |
| 1607 | - if ($resupload < 0) // Unknown error |
|
| 1738 | + if ($resupload < 0) { |
|
| 1739 | + // Unknown error |
|
| 1608 | 1740 | { |
| 1609 | 1741 | setEventMessages($langs->trans("ErrorFileNotUploaded"), null, 'errors'); |
| 1610 | 1742 | } |
| 1611 | - else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus |
|
| 1743 | + } else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) { |
|
| 1744 | + // Files infected by a virus |
|
| 1612 | 1745 | { |
| 1613 | 1746 | setEventMessages($langs->trans("ErrorFileIsInfectedWithAVirus"), null, 'errors'); |
| 1614 | 1747 | } |
| 1615 | - else // Known error |
|
| 1748 | + } else // Known error |
|
| 1616 | 1749 | { |
| 1617 | 1750 | setEventMessages($langs->trans($resupload), null, 'errors'); |
| 1618 | 1751 | } |
@@ -1639,8 +1772,7 @@ discard block |
||
| 1639 | 1772 | } else { |
| 1640 | 1773 | setEventMessages($langs->trans("ErrorFileNotLinked"), null, 'errors'); |
| 1641 | 1774 | } |
| 1642 | - } |
|
| 1643 | - else |
|
| 1775 | + } else |
|
| 1644 | 1776 | { |
| 1645 | 1777 | $langs->load("errors"); |
| 1646 | 1778 | setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("File")), null, 'errors'); |
@@ -1671,16 +1803,27 @@ discard block |
||
| 1671 | 1803 | $listofnames=array(); |
| 1672 | 1804 | $listofmimes=array(); |
| 1673 | 1805 | $keytoavoidconflict = empty($trackid)?'':'-'.$trackid; |
| 1674 | - if (! empty($_SESSION["listofpaths".$keytoavoidconflict])) $listofpaths=explode(';',$_SESSION["listofpaths".$keytoavoidconflict]); |
|
| 1675 | - if (! empty($_SESSION["listofnames".$keytoavoidconflict])) $listofnames=explode(';',$_SESSION["listofnames".$keytoavoidconflict]); |
|
| 1676 | - if (! empty($_SESSION["listofmimes".$keytoavoidconflict])) $listofmimes=explode(';',$_SESSION["listofmimes".$keytoavoidconflict]); |
|
| 1806 | + if (! empty($_SESSION["listofpaths".$keytoavoidconflict])) { |
|
| 1807 | + $listofpaths=explode(';',$_SESSION["listofpaths".$keytoavoidconflict]); |
|
| 1808 | + } |
|
| 1809 | + if (! empty($_SESSION["listofnames".$keytoavoidconflict])) { |
|
| 1810 | + $listofnames=explode(';',$_SESSION["listofnames".$keytoavoidconflict]); |
|
| 1811 | + } |
|
| 1812 | + if (! empty($_SESSION["listofmimes".$keytoavoidconflict])) { |
|
| 1813 | + $listofmimes=explode(';',$_SESSION["listofmimes".$keytoavoidconflict]); |
|
| 1814 | + } |
|
| 1677 | 1815 | |
| 1678 | 1816 | if ($keytodelete >= 0) |
| 1679 | 1817 | { |
| 1680 | 1818 | $pathtodelete=$listofpaths[$keytodelete]; |
| 1681 | 1819 | $filetodelete=$listofnames[$keytodelete]; |
| 1682 | - if (empty($donotdeletefile)) $result = dol_delete_file($pathtodelete,1); // The delete of ecm database is inside the function dol_delete_file |
|
| 1683 | - else $result=0; |
|
| 1820 | + if (empty($donotdeletefile)) { |
|
| 1821 | + $result = dol_delete_file($pathtodelete,1); |
|
| 1822 | + } |
|
| 1823 | + // The delete of ecm database is inside the function dol_delete_file |
|
| 1824 | + else { |
|
| 1825 | + $result=0; |
|
| 1826 | + } |
|
| 1684 | 1827 | if ($result >= 0) |
| 1685 | 1828 | { |
| 1686 | 1829 | if (empty($donotdeletefile)) |
@@ -1720,9 +1863,11 @@ discard block |
||
| 1720 | 1863 | |
| 1721 | 1864 | $rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $dir); |
| 1722 | 1865 | |
| 1723 | - if (! preg_match('/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) // If not a tmp dir |
|
| 1866 | + if (! preg_match('/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) { |
|
| 1867 | + // If not a tmp dir |
|
| 1724 | 1868 | { |
| 1725 | 1869 | $filename = basename($file); |
| 1870 | + } |
|
| 1726 | 1871 | $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir); |
| 1727 | 1872 | $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir); |
| 1728 | 1873 | |
@@ -1785,8 +1930,12 @@ discard block |
||
| 1785 | 1930 | $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . 'ecm_files'; |
| 1786 | 1931 | $sql.= ' WHERE entity = '.$conf->entity; |
| 1787 | 1932 | $sql.= " AND filepath = '" . $db->escape($rel_dir) . "'"; |
| 1788 | - if ($file) $sql.= " AND filename = '" . $db->escape($file) . "'"; |
|
| 1789 | - if ($mode) $sql.= " AND gen_or_uploaded = '" . $db->escape($mode) . "'"; |
|
| 1933 | + if ($file) { |
|
| 1934 | + $sql.= " AND filename = '" . $db->escape($file) . "'"; |
|
| 1935 | + } |
|
| 1936 | + if ($mode) { |
|
| 1937 | + $sql.= " AND gen_or_uploaded = '" . $db->escape($mode) . "'"; |
|
| 1938 | + } |
|
| 1790 | 1939 | |
| 1791 | 1940 | $resql = $db->query($sql); |
| 1792 | 1941 | if (!$resql) |
@@ -1834,32 +1983,33 @@ discard block |
||
| 1834 | 1983 | $ret = $image->setImageFormat($ext); |
| 1835 | 1984 | if ($ret) |
| 1836 | 1985 | { |
| 1837 | - if (empty($fileoutput)) $fileoutput=$fileinput.".".$ext; |
|
| 1986 | + if (empty($fileoutput)) { |
|
| 1987 | + $fileoutput=$fileinput.".".$ext; |
|
| 1988 | + } |
|
| 1838 | 1989 | |
| 1839 | 1990 | $count = $image->getNumberImages(); |
| 1840 | 1991 | |
| 1841 | 1992 | if (! dol_is_file($fileoutput) || is_writeable($fileoutput)) |
| 1842 | 1993 | { |
| 1843 | 1994 | $ret = $image->writeImages($fileoutput, true); |
| 1844 | - } |
|
| 1845 | - else |
|
| 1995 | + } else |
|
| 1846 | 1996 | { |
| 1847 | 1997 | dol_syslog("Warning: Failed to write cache preview file '.$fileoutput.'. Check permission on file/dir", LOG_ERR); |
| 1848 | 1998 | } |
| 1849 | - if ($ret) return $count; |
|
| 1850 | - else return -3; |
|
| 1851 | - } |
|
| 1852 | - else |
|
| 1999 | + if ($ret) { |
|
| 2000 | + return $count; |
|
| 2001 | + } else { |
|
| 2002 | + return -3; |
|
| 2003 | + } |
|
| 2004 | + } else |
|
| 1853 | 2005 | { |
| 1854 | 2006 | return -2; |
| 1855 | 2007 | } |
| 1856 | - } |
|
| 1857 | - else |
|
| 2008 | + } else |
|
| 1858 | 2009 | { |
| 1859 | 2010 | return -1; |
| 1860 | 2011 | } |
| 1861 | - } |
|
| 1862 | - else |
|
| 2012 | + } else |
|
| 1863 | 2013 | { |
| 1864 | 2014 | return 0; |
| 1865 | 2015 | } |
@@ -1881,9 +2031,7 @@ discard block |
||
| 1881 | 2031 | try |
| 1882 | 2032 | { |
| 1883 | 2033 | $data = implode("", file(dol_osencode($inputfile))); |
| 1884 | - if ($mode == 'gz') { $foundhandler=1; $compressdata = gzencode($data, 9); } |
|
| 1885 | - elseif ($mode == 'bz') { $foundhandler=1; $compressdata = bzcompress($data, 9); } |
|
| 1886 | - elseif ($mode == 'zip') |
|
| 2034 | + if ($mode == 'gz') { $foundhandler=1; $compressdata = gzencode($data, 9); } elseif ($mode == 'bz') { $foundhandler=1; $compressdata = bzcompress($data, 9); } elseif ($mode == 'zip') |
|
| 1887 | 2035 | { |
| 1888 | 2036 | if (defined('ODTPHP_PATHTOPCLZIP')) |
| 1889 | 2037 | { |
@@ -1903,14 +2051,12 @@ discard block |
||
| 1903 | 2051 | fwrite($fp, $compressdata); |
| 1904 | 2052 | fclose($fp); |
| 1905 | 2053 | return 1; |
| 1906 | - } |
|
| 1907 | - else |
|
| 2054 | + } else |
|
| 1908 | 2055 | { |
| 1909 | 2056 | dol_syslog("Try to zip with format ".$mode." with no handler for this format",LOG_ERR); |
| 1910 | 2057 | return -2; |
| 1911 | 2058 | } |
| 1912 | - } |
|
| 1913 | - catch (Exception $e) |
|
| 2059 | + } catch (Exception $e) |
|
| 1914 | 2060 | { |
| 1915 | 2061 | global $langs, $errormsg; |
| 1916 | 2062 | $langs->load("errors"); |
@@ -1938,8 +2084,9 @@ discard block |
||
| 1938 | 2084 | $archive = new PclZip($inputfile); |
| 1939 | 2085 | $result=$archive->extract(PCLZIP_OPT_PATH, $outputdir); |
| 1940 | 2086 | //var_dump($result); |
| 1941 | - if (! is_array($result) && $result <= 0) return array('error'=>$archive->errorInfo(true)); |
|
| 1942 | - else |
|
| 2087 | + if (! is_array($result) && $result <= 0) { |
|
| 2088 | + return array('error'=>$archive->errorInfo(true)); |
|
| 2089 | + } else |
|
| 1943 | 2090 | { |
| 1944 | 2091 | $ok=1; $errmsg=''; |
| 1945 | 2092 | // Loop on each file to check result for unzipping file |
@@ -1954,8 +2101,11 @@ discard block |
||
| 1954 | 2101 | } |
| 1955 | 2102 | } |
| 1956 | 2103 | |
| 1957 | - if ($ok) return array(); |
|
| 1958 | - else return array('error'=>$errmsg); |
|
| 2104 | + if ($ok) { |
|
| 2105 | + return array(); |
|
| 2106 | + } else { |
|
| 2107 | + return array('error'=>$errmsg); |
|
| 2108 | + } |
|
| 1959 | 2109 | } |
| 1960 | 2110 | } |
| 1961 | 2111 | |
@@ -1969,8 +2119,7 @@ discard block |
||
| 1969 | 2119 | $zip->extractTo($outputdir.'/'); |
| 1970 | 2120 | $zip->close(); |
| 1971 | 2121 | return array(); |
| 1972 | - } |
|
| 1973 | - else |
|
| 2122 | + } else |
|
| 1974 | 2123 | { |
| 1975 | 2124 | return array('error'=>'ErrUnzipFails'); |
| 1976 | 2125 | } |
@@ -2004,9 +2153,7 @@ discard block |
||
| 2004 | 2153 | |
| 2005 | 2154 | try |
| 2006 | 2155 | { |
| 2007 | - if ($mode == 'gz') { $foundhandler=0; } |
|
| 2008 | - elseif ($mode == 'bz') { $foundhandler=0; } |
|
| 2009 | - elseif ($mode == 'zip') |
|
| 2156 | + if ($mode == 'gz') { $foundhandler=0; } elseif ($mode == 'bz') { $foundhandler=0; } elseif ($mode == 'zip') |
|
| 2010 | 2157 | { |
| 2011 | 2158 | /*if (defined('ODTPHP_PATHTOPCLZIP')) |
| 2012 | 2159 | { |
@@ -2059,13 +2206,11 @@ discard block |
||
| 2059 | 2206 | { |
| 2060 | 2207 | dol_syslog("Try to zip with format ".$mode." with no handler for this format",LOG_ERR); |
| 2061 | 2208 | return -2; |
| 2062 | - } |
|
| 2063 | - else |
|
| 2209 | + } else |
|
| 2064 | 2210 | { |
| 2065 | 2211 | return 0; |
| 2066 | 2212 | } |
| 2067 | - } |
|
| 2068 | - catch (Exception $e) |
|
| 2213 | + } catch (Exception $e) |
|
| 2069 | 2214 | { |
| 2070 | 2215 | global $langs, $errormsg; |
| 2071 | 2216 | $langs->load("errors"); |
@@ -2111,16 +2256,25 @@ discard block |
||
| 2111 | 2256 | global $conf, $db, $user; |
| 2112 | 2257 | global $dolibarr_main_data_root, $dolibarr_main_document_root_alt; |
| 2113 | 2258 | |
| 2114 | - if (! is_object($fuser)) $fuser=$user; |
|
| 2259 | + if (! is_object($fuser)) { |
|
| 2260 | + $fuser=$user; |
|
| 2261 | + } |
|
| 2115 | 2262 | |
| 2116 | - if (empty($modulepart)) return 'ErrorBadParameter'; |
|
| 2263 | + if (empty($modulepart)) { |
|
| 2264 | + return 'ErrorBadParameter'; |
|
| 2265 | + } |
|
| 2117 | 2266 | if (empty($entity)) |
| 2118 | 2267 | { |
| 2119 | - if (empty($conf->multicompany->enabled)) $entity=1; |
|
| 2120 | - else $entity=0; |
|
| 2268 | + if (empty($conf->multicompany->enabled)) { |
|
| 2269 | + $entity=1; |
|
| 2270 | + } else { |
|
| 2271 | + $entity=0; |
|
| 2272 | + } |
|
| 2121 | 2273 | } |
| 2122 | 2274 | // Fix modulepart |
| 2123 | - if ($modulepart == 'users') $modulepart='user'; |
|
| 2275 | + if ($modulepart == 'users') { |
|
| 2276 | + $modulepart='user'; |
|
| 2277 | + } |
|
| 2124 | 2278 | |
| 2125 | 2279 | dol_syslog('modulepart='.$modulepart.' original_file='.$original_file.' entity='.$entity); |
| 2126 | 2280 | // We define $accessallowed and $sqlprotectagainstexternals |
@@ -2129,7 +2283,9 @@ discard block |
||
| 2129 | 2283 | $ret=array(); |
| 2130 | 2284 | |
| 2131 | 2285 | // Find the subdirectory name as the reference. For exemple original_file='10/myfile.pdf' -> refname='10' |
| 2132 | - if (empty($refname)) $refname=basename(dirname($original_file)."/"); |
|
| 2286 | + if (empty($refname)) { |
|
| 2287 | + $refname=basename(dirname($original_file)."/"); |
|
| 2288 | + } |
|
| 2133 | 2289 | |
| 2134 | 2290 | $relative_original_file = $original_file; |
| 2135 | 2291 | |
@@ -2143,7 +2299,9 @@ discard block |
||
| 2143 | 2299 | // Wrapping for miscellaneous medias files |
| 2144 | 2300 | if ($modulepart == 'medias' && !empty($dolibarr_main_data_root)) |
| 2145 | 2301 | { |
| 2146 | - if (empty($entity) || empty($conf->medias->multidir_output[$entity])) return array('accessallowed'=>0, 'error'=>'Value entity must be provided'); |
|
| 2302 | + if (empty($entity) || empty($conf->medias->multidir_output[$entity])) { |
|
| 2303 | + return array('accessallowed'=>0, 'error'=>'Value entity must be provided'); |
|
| 2304 | + } |
|
| 2147 | 2305 | $accessallowed=1; |
| 2148 | 2306 | $original_file=$conf->medias->multidir_output[$entity].'/'.$original_file; |
| 2149 | 2307 | } |
@@ -2184,132 +2342,176 @@ discard block |
||
| 2184 | 2342 | // Wrapping pour les apercu factures |
| 2185 | 2343 | elseif ($modulepart == 'apercufacture' && !empty($conf->facture->dir_output)) |
| 2186 | 2344 | { |
| 2187 | - if ($fuser->rights->facture->{$lire}) $accessallowed=1; |
|
| 2345 | + if ($fuser->rights->facture->{$lire}) { |
|
| 2346 | + $accessallowed=1; |
|
| 2347 | + } |
|
| 2188 | 2348 | $original_file=$conf->facture->dir_output.'/'.$original_file; |
| 2189 | 2349 | } |
| 2190 | 2350 | // Wrapping pour les apercu propal |
| 2191 | 2351 | elseif ($modulepart == 'apercupropal' && !empty($conf->propal->multidir_output[$entity])) |
| 2192 | 2352 | { |
| 2193 | - if ($fuser->rights->propale->{$lire}) $accessallowed=1; |
|
| 2353 | + if ($fuser->rights->propale->{$lire}) { |
|
| 2354 | + $accessallowed=1; |
|
| 2355 | + } |
|
| 2194 | 2356 | $original_file=$conf->propal->multidir_output[$entity].'/'.$original_file; |
| 2195 | 2357 | } |
| 2196 | 2358 | // Wrapping pour les apercu commande |
| 2197 | 2359 | elseif ($modulepart == 'apercucommande' && !empty($conf->commande->dir_output)) |
| 2198 | 2360 | { |
| 2199 | - if ($fuser->rights->commande->{$lire}) $accessallowed=1; |
|
| 2361 | + if ($fuser->rights->commande->{$lire}) { |
|
| 2362 | + $accessallowed=1; |
|
| 2363 | + } |
|
| 2200 | 2364 | $original_file=$conf->commande->dir_output.'/'.$original_file; |
| 2201 | 2365 | } |
| 2202 | 2366 | // Wrapping pour les apercu intervention |
| 2203 | 2367 | elseif (($modulepart == 'apercufichinter' || $modulepart == 'apercuficheinter') && !empty($conf->ficheinter->dir_output)) |
| 2204 | 2368 | { |
| 2205 | - if ($fuser->rights->ficheinter->{$lire}) $accessallowed=1; |
|
| 2369 | + if ($fuser->rights->ficheinter->{$lire}) { |
|
| 2370 | + $accessallowed=1; |
|
| 2371 | + } |
|
| 2206 | 2372 | $original_file=$conf->ficheinter->dir_output.'/'.$original_file; |
| 2207 | 2373 | } |
| 2208 | 2374 | // Wrapping pour les apercu conat |
| 2209 | 2375 | elseif (($modulepart == 'apercucontract') && !empty($conf->contrat->dir_output)) |
| 2210 | 2376 | { |
| 2211 | - if ($fuser->rights->contrat->{$lire}) $accessallowed=1; |
|
| 2377 | + if ($fuser->rights->contrat->{$lire}) { |
|
| 2378 | + $accessallowed=1; |
|
| 2379 | + } |
|
| 2212 | 2380 | $original_file=$conf->contrat->dir_output.'/'.$original_file; |
| 2213 | 2381 | } |
| 2214 | 2382 | // Wrapping pour les apercu supplier proposal |
| 2215 | 2383 | elseif (($modulepart == 'apercusupplier_proposal' || $modulepart == 'apercusupplier_proposal') && !empty($conf->supplier_proposal->dir_output)) |
| 2216 | 2384 | { |
| 2217 | - if ($fuser->rights->supplier_proposal->{$lire}) $accessallowed=1; |
|
| 2385 | + if ($fuser->rights->supplier_proposal->{$lire}) { |
|
| 2386 | + $accessallowed=1; |
|
| 2387 | + } |
|
| 2218 | 2388 | $original_file=$conf->supplier_proposal->dir_output.'/'.$original_file; |
| 2219 | 2389 | } |
| 2220 | 2390 | // Wrapping pour les apercu supplier order |
| 2221 | 2391 | elseif (($modulepart == 'apercusupplier_order' || $modulepart == 'apercusupplier_order') && !empty($conf->fournisseur->commande->dir_output)) |
| 2222 | 2392 | { |
| 2223 | - if ($fuser->rights->fournisseur->commande->{$lire}) $accessallowed=1; |
|
| 2393 | + if ($fuser->rights->fournisseur->commande->{$lire}) { |
|
| 2394 | + $accessallowed=1; |
|
| 2395 | + } |
|
| 2224 | 2396 | $original_file=$conf->fournisseur->commande->dir_output.'/'.$original_file; |
| 2225 | 2397 | } |
| 2226 | 2398 | // Wrapping pour les apercu supplier invoice |
| 2227 | 2399 | elseif (($modulepart == 'apercusupplier_invoice' || $modulepart == 'apercusupplier_invoice') && !empty($conf->fournisseur->facture->dir_output)) |
| 2228 | 2400 | { |
| 2229 | - if ($fuser->rights->fournisseur->facture->{$lire}) $accessallowed=1; |
|
| 2401 | + if ($fuser->rights->fournisseur->facture->{$lire}) { |
|
| 2402 | + $accessallowed=1; |
|
| 2403 | + } |
|
| 2230 | 2404 | $original_file=$conf->fournisseur->facture->dir_output.'/'.$original_file; |
| 2231 | 2405 | } |
| 2232 | 2406 | // Wrapping pour les apercu supplier invoice |
| 2233 | 2407 | elseif (($modulepart == 'apercuexpensereport') && !empty($conf->expensereport->dir_output)) |
| 2234 | 2408 | { |
| 2235 | - if ($fuser->rights->expensereport->{$lire}) $accessallowed=1; |
|
| 2409 | + if ($fuser->rights->expensereport->{$lire}) { |
|
| 2410 | + $accessallowed=1; |
|
| 2411 | + } |
|
| 2236 | 2412 | $original_file=$conf->expensereport->dir_output.'/'.$original_file; |
| 2237 | 2413 | } |
| 2238 | 2414 | // Wrapping pour les images des stats propales |
| 2239 | 2415 | elseif ($modulepart == 'propalstats' && !empty($conf->propal->multidir_temp[$entity])) |
| 2240 | 2416 | { |
| 2241 | - if ($fuser->rights->propale->{$lire}) $accessallowed=1; |
|
| 2417 | + if ($fuser->rights->propale->{$lire}) { |
|
| 2418 | + $accessallowed=1; |
|
| 2419 | + } |
|
| 2242 | 2420 | $original_file=$conf->propal->multidir_temp[$entity].'/'.$original_file; |
| 2243 | 2421 | } |
| 2244 | 2422 | // Wrapping pour les images des stats commandes |
| 2245 | 2423 | elseif ($modulepart == 'orderstats' && !empty($conf->commande->dir_temp)) |
| 2246 | 2424 | { |
| 2247 | - if ($fuser->rights->commande->{$lire}) $accessallowed=1; |
|
| 2425 | + if ($fuser->rights->commande->{$lire}) { |
|
| 2426 | + $accessallowed=1; |
|
| 2427 | + } |
|
| 2248 | 2428 | $original_file=$conf->commande->dir_temp.'/'.$original_file; |
| 2249 | - } |
|
| 2250 | - elseif ($modulepart == 'orderstatssupplier' && !empty($conf->fournisseur->dir_output)) |
|
| 2429 | + } elseif ($modulepart == 'orderstatssupplier' && !empty($conf->fournisseur->dir_output)) |
|
| 2251 | 2430 | { |
| 2252 | - if ($fuser->rights->fournisseur->commande->{$lire}) $accessallowed=1; |
|
| 2431 | + if ($fuser->rights->fournisseur->commande->{$lire}) { |
|
| 2432 | + $accessallowed=1; |
|
| 2433 | + } |
|
| 2253 | 2434 | $original_file=$conf->fournisseur->commande->dir_temp.'/'.$original_file; |
| 2254 | 2435 | } |
| 2255 | 2436 | // Wrapping pour les images des stats factures |
| 2256 | 2437 | elseif ($modulepart == 'billstats' && !empty($conf->facture->dir_temp)) |
| 2257 | 2438 | { |
| 2258 | - if ($fuser->rights->facture->{$lire}) $accessallowed=1; |
|
| 2439 | + if ($fuser->rights->facture->{$lire}) { |
|
| 2440 | + $accessallowed=1; |
|
| 2441 | + } |
|
| 2259 | 2442 | $original_file=$conf->facture->dir_temp.'/'.$original_file; |
| 2260 | - } |
|
| 2261 | - elseif ($modulepart == 'billstatssupplier' && !empty($conf->fournisseur->dir_output)) |
|
| 2443 | + } elseif ($modulepart == 'billstatssupplier' && !empty($conf->fournisseur->dir_output)) |
|
| 2262 | 2444 | { |
| 2263 | - if ($fuser->rights->fournisseur->facture->{$lire}) $accessallowed=1; |
|
| 2445 | + if ($fuser->rights->fournisseur->facture->{$lire}) { |
|
| 2446 | + $accessallowed=1; |
|
| 2447 | + } |
|
| 2264 | 2448 | $original_file=$conf->fournisseur->facture->dir_temp.'/'.$original_file; |
| 2265 | 2449 | } |
| 2266 | 2450 | // Wrapping pour les images des stats expeditions |
| 2267 | 2451 | elseif ($modulepart == 'expeditionstats' && !empty($conf->expedition->dir_temp)) |
| 2268 | 2452 | { |
| 2269 | - if ($fuser->rights->expedition->{$lire}) $accessallowed=1; |
|
| 2453 | + if ($fuser->rights->expedition->{$lire}) { |
|
| 2454 | + $accessallowed=1; |
|
| 2455 | + } |
|
| 2270 | 2456 | $original_file=$conf->expedition->dir_temp.'/'.$original_file; |
| 2271 | 2457 | } |
| 2272 | 2458 | // Wrapping pour les images des stats expeditions |
| 2273 | 2459 | elseif ($modulepart == 'tripsexpensesstats' && !empty($conf->deplacement->dir_temp)) |
| 2274 | 2460 | { |
| 2275 | - if ($fuser->rights->deplacement->{$lire}) $accessallowed=1; |
|
| 2461 | + if ($fuser->rights->deplacement->{$lire}) { |
|
| 2462 | + $accessallowed=1; |
|
| 2463 | + } |
|
| 2276 | 2464 | $original_file=$conf->deplacement->dir_temp.'/'.$original_file; |
| 2277 | 2465 | } |
| 2278 | 2466 | // Wrapping pour les images des stats expeditions |
| 2279 | 2467 | elseif ($modulepart == 'memberstats' && !empty($conf->adherent->dir_temp)) |
| 2280 | 2468 | { |
| 2281 | - if ($fuser->rights->adherent->{$lire}) $accessallowed=1; |
|
| 2469 | + if ($fuser->rights->adherent->{$lire}) { |
|
| 2470 | + $accessallowed=1; |
|
| 2471 | + } |
|
| 2282 | 2472 | $original_file=$conf->adherent->dir_temp.'/'.$original_file; |
| 2283 | 2473 | } |
| 2284 | 2474 | // Wrapping pour les images des stats produits |
| 2285 | 2475 | elseif (preg_match('/^productstats_/i',$modulepart) && !empty($conf->product->dir_temp)) |
| 2286 | 2476 | { |
| 2287 | - if ($fuser->rights->produit->{$lire} || $fuser->rights->service->{$lire}) $accessallowed=1; |
|
| 2477 | + if ($fuser->rights->produit->{$lire} || $fuser->rights->service->{$lire}) { |
|
| 2478 | + $accessallowed=1; |
|
| 2479 | + } |
|
| 2288 | 2480 | $original_file=(!empty($conf->product->multidir_temp[$entity])?$conf->product->multidir_temp[$entity]:$conf->service->multidir_temp[$entity]).'/'.$original_file; |
| 2289 | 2481 | } |
| 2290 | 2482 | // Wrapping for taxes |
| 2291 | 2483 | elseif ($modulepart == 'tax' && !empty($conf->tax->dir_output)) |
| 2292 | 2484 | { |
| 2293 | - if ($fuser->rights->tax->charges->{$lire}) $accessallowed=1; |
|
| 2485 | + if ($fuser->rights->tax->charges->{$lire}) { |
|
| 2486 | + $accessallowed=1; |
|
| 2487 | + } |
|
| 2294 | 2488 | $original_file=$conf->tax->dir_output.'/'.$original_file; |
| 2295 | 2489 | } |
| 2296 | 2490 | // Wrapping for events |
| 2297 | 2491 | elseif ($modulepart == 'actions' && !empty($conf->agenda->dir_output)) |
| 2298 | 2492 | { |
| 2299 | - if ($fuser->rights->agenda->myactions->{$read}) $accessallowed=1; |
|
| 2493 | + if ($fuser->rights->agenda->myactions->{$read}) { |
|
| 2494 | + $accessallowed=1; |
|
| 2495 | + } |
|
| 2300 | 2496 | $original_file=$conf->agenda->dir_output.'/'.$original_file; |
| 2301 | 2497 | } |
| 2302 | 2498 | // Wrapping for categories |
| 2303 | 2499 | elseif ($modulepart == 'category' && !empty($conf->categorie->dir_output)) |
| 2304 | 2500 | { |
| 2305 | - if (empty($entity) || empty($conf->categorie->multidir_output[$entity])) return array('accessallowed'=>0, 'error'=>'Value entity must be provided'); |
|
| 2306 | - if ($fuser->rights->categorie->{$lire}) $accessallowed=1; |
|
| 2501 | + if (empty($entity) || empty($conf->categorie->multidir_output[$entity])) { |
|
| 2502 | + return array('accessallowed'=>0, 'error'=>'Value entity must be provided'); |
|
| 2503 | + } |
|
| 2504 | + if ($fuser->rights->categorie->{$lire}) { |
|
| 2505 | + $accessallowed=1; |
|
| 2506 | + } |
|
| 2307 | 2507 | $original_file=$conf->categorie->multidir_output[$entity].'/'.$original_file; |
| 2308 | 2508 | } |
| 2309 | 2509 | // Wrapping pour les prelevements |
| 2310 | 2510 | elseif ($modulepart == 'prelevement' && !empty($conf->prelevement->dir_output)) |
| 2311 | 2511 | { |
| 2312 | - if ($fuser->rights->prelevement->bons->{$lire} || preg_match('/^specimen/i',$original_file)) $accessallowed=1; |
|
| 2512 | + if ($fuser->rights->prelevement->bons->{$lire} || preg_match('/^specimen/i',$original_file)) { |
|
| 2513 | + $accessallowed=1; |
|
| 2514 | + } |
|
| 2313 | 2515 | $original_file=$conf->prelevement->dir_output.'/'.$original_file; |
| 2314 | 2516 | } |
| 2315 | 2517 | // Wrapping pour les graph energie |
@@ -2372,7 +2574,9 @@ discard block |
||
| 2372 | 2574 | // Wrapping for third parties |
| 2373 | 2575 | else if (($modulepart == 'company' || $modulepart == 'societe') && !empty($conf->societe->dir_output)) |
| 2374 | 2576 | { |
| 2375 | - if (empty($entity) || empty($conf->societe->multidir_output[$entity])) return array('accessallowed'=>0, 'error'=>'Value entity must be provided'); |
|
| 2577 | + if (empty($entity) || empty($conf->societe->multidir_output[$entity])) { |
|
| 2578 | + return array('accessallowed'=>0, 'error'=>'Value entity must be provided'); |
|
| 2579 | + } |
|
| 2376 | 2580 | if ($fuser->rights->societe->{$lire} || preg_match('/^specimen/i',$original_file)) |
| 2377 | 2581 | { |
| 2378 | 2582 | $accessallowed=1; |
@@ -2384,7 +2588,9 @@ discard block |
||
| 2384 | 2588 | // Wrapping for contact |
| 2385 | 2589 | else if ($modulepart == 'contact' && !empty($conf->societe->dir_output)) |
| 2386 | 2590 | { |
| 2387 | - if (empty($entity) || empty($conf->societe->multidir_output[$entity])) return array('accessallowed'=>0, 'error'=>'Value entity must be provided'); |
|
| 2591 | + if (empty($entity) || empty($conf->societe->multidir_output[$entity])) { |
|
| 2592 | + return array('accessallowed'=>0, 'error'=>'Value entity must be provided'); |
|
| 2593 | + } |
|
| 2388 | 2594 | if ($fuser->rights->societe->{$lire}) |
| 2389 | 2595 | { |
| 2390 | 2596 | $accessallowed=1; |
@@ -2410,64 +2616,56 @@ discard block |
||
| 2410 | 2616 | $accessallowed=1; |
| 2411 | 2617 | } |
| 2412 | 2618 | $original_file=$conf->propal->multidir_output[$entity].'/temp/massgeneration/'.$user->id.'/'.$original_file; |
| 2413 | - } |
|
| 2414 | - else if ($modulepart == 'massfilesarea_orders') |
|
| 2619 | + } else if ($modulepart == 'massfilesarea_orders') |
|
| 2415 | 2620 | { |
| 2416 | 2621 | if ($fuser->rights->commande->{$lire} || preg_match('/^specimen/i',$original_file)) |
| 2417 | 2622 | { |
| 2418 | 2623 | $accessallowed=1; |
| 2419 | 2624 | } |
| 2420 | 2625 | $original_file=$conf->commande->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; |
| 2421 | - } |
|
| 2422 | - else if ($modulepart == 'massfilesarea_invoices') |
|
| 2626 | + } else if ($modulepart == 'massfilesarea_invoices') |
|
| 2423 | 2627 | { |
| 2424 | 2628 | if ($fuser->rights->facture->{$lire} || preg_match('/^specimen/i',$original_file)) |
| 2425 | 2629 | { |
| 2426 | 2630 | $accessallowed=1; |
| 2427 | 2631 | } |
| 2428 | 2632 | $original_file=$conf->facture->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; |
| 2429 | - } |
|
| 2430 | - else if ($modulepart == 'massfilesarea_expensereport') |
|
| 2633 | + } else if ($modulepart == 'massfilesarea_expensereport') |
|
| 2431 | 2634 | { |
| 2432 | 2635 | if ($fuser->rights->facture->{$lire} || preg_match('/^specimen/i',$original_file)) |
| 2433 | 2636 | { |
| 2434 | 2637 | $accessallowed=1; |
| 2435 | 2638 | } |
| 2436 | 2639 | $original_file=$conf->expensereport->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; |
| 2437 | - } |
|
| 2438 | - else if ($modulepart == 'massfilesarea_interventions') |
|
| 2640 | + } else if ($modulepart == 'massfilesarea_interventions') |
|
| 2439 | 2641 | { |
| 2440 | 2642 | if ($fuser->rights->ficheinter->{$lire} || preg_match('/^specimen/i',$original_file)) |
| 2441 | 2643 | { |
| 2442 | 2644 | $accessallowed=1; |
| 2443 | 2645 | } |
| 2444 | 2646 | $original_file=$conf->ficheinter->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; |
| 2445 | - } |
|
| 2446 | - else if ($modulepart == 'massfilesarea_supplier_proposal' && !empty($conf->supplier_proposal->dir_output)) |
|
| 2647 | + } else if ($modulepart == 'massfilesarea_supplier_proposal' && !empty($conf->supplier_proposal->dir_output)) |
|
| 2447 | 2648 | { |
| 2448 | 2649 | if ($fuser->rights->supplier_proposal->{$lire} || preg_match('/^specimen/i',$original_file)) |
| 2449 | 2650 | { |
| 2450 | 2651 | $accessallowed=1; |
| 2451 | 2652 | } |
| 2452 | 2653 | $original_file=$conf->supplier_proposal->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; |
| 2453 | - } |
|
| 2454 | - else if ($modulepart == 'massfilesarea_supplier_order') |
|
| 2654 | + } else if ($modulepart == 'massfilesarea_supplier_order') |
|
| 2455 | 2655 | { |
| 2456 | 2656 | if ($fuser->rights->fournisseur->commande->{$lire} || preg_match('/^specimen/i',$original_file)) |
| 2457 | 2657 | { |
| 2458 | 2658 | $accessallowed=1; |
| 2459 | 2659 | } |
| 2460 | 2660 | $original_file=$conf->fournisseur->commande->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; |
| 2461 | - } |
|
| 2462 | - else if ($modulepart == 'massfilesarea_supplier_invoice') |
|
| 2661 | + } else if ($modulepart == 'massfilesarea_supplier_invoice') |
|
| 2463 | 2662 | { |
| 2464 | 2663 | if ($fuser->rights->fournisseur->facture->{$lire} || preg_match('/^specimen/i',$original_file)) |
| 2465 | 2664 | { |
| 2466 | 2665 | $accessallowed=1; |
| 2467 | 2666 | } |
| 2468 | 2667 | $original_file=$conf->fournisseur->facture->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; |
| 2469 | - } |
|
| 2470 | - else if ($modulepart == 'massfilesarea_contract' && !empty($conf->contrat->dir_output)) |
|
| 2668 | + } else if ($modulepart == 'massfilesarea_contract' && !empty($conf->contrat->dir_output)) |
|
| 2471 | 2669 | { |
| 2472 | 2670 | if ($fuser->rights->contrat->{$lire} || preg_match('/^specimen/i',$original_file)) |
| 2473 | 2671 | { |
@@ -2528,8 +2726,7 @@ discard block |
||
| 2528 | 2726 | } |
| 2529 | 2727 | $original_file=$conf->projet->dir_output.'/'.$original_file; |
| 2530 | 2728 | $sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."projet WHERE ref='".$db->escape($refname)."' AND entity IN (".getEntity('project').")"; |
| 2531 | - } |
|
| 2532 | - else if ($modulepart == 'project_task' && !empty($conf->projet->dir_output)) |
|
| 2729 | + } else if ($modulepart == 'project_task' && !empty($conf->projet->dir_output)) |
|
| 2533 | 2730 | { |
| 2534 | 2731 | if ($fuser->rights->projet->{$lire} || preg_match('/^specimen/i',$original_file)) |
| 2535 | 2732 | { |
@@ -2578,8 +2775,11 @@ discard block |
||
| 2578 | 2775 | { |
| 2579 | 2776 | $accessallowed=1; |
| 2580 | 2777 | } |
| 2581 | - if ($fuser->societe_id > 0) $original_file=$conf->facture->dir_output.'/payments/private/'.$fuser->id.'/'.$original_file; |
|
| 2582 | - else $original_file=$conf->facture->dir_output.'/payments/'.$original_file; |
|
| 2778 | + if ($fuser->societe_id > 0) { |
|
| 2779 | + $original_file=$conf->facture->dir_output.'/payments/private/'.$fuser->id.'/'.$original_file; |
|
| 2780 | + } else { |
|
| 2781 | + $original_file=$conf->facture->dir_output.'/payments/'.$original_file; |
|
| 2782 | + } |
|
| 2583 | 2783 | } |
| 2584 | 2784 | |
| 2585 | 2785 | // Wrapping for accounting exports |
@@ -2634,24 +2834,33 @@ discard block |
||
| 2634 | 2834 | // Wrapping pour les produits et services |
| 2635 | 2835 | else if ($modulepart == 'product' || $modulepart == 'produit' || $modulepart == 'service' || $modulepart == 'produit|service') |
| 2636 | 2836 | { |
| 2637 | - if (empty($entity) || (empty($conf->product->multidir_output[$entity]) && empty($conf->service->multidir_output[$entity]))) return array('accessallowed'=>0, 'error'=>'Value entity must be provided'); |
|
| 2837 | + if (empty($entity) || (empty($conf->product->multidir_output[$entity]) && empty($conf->service->multidir_output[$entity]))) { |
|
| 2838 | + return array('accessallowed'=>0, 'error'=>'Value entity must be provided'); |
|
| 2839 | + } |
|
| 2638 | 2840 | if (($fuser->rights->produit->{$lire} || $fuser->rights->service->{$lire}) || preg_match('/^specimen/i',$original_file)) |
| 2639 | 2841 | { |
| 2640 | 2842 | $accessallowed=1; |
| 2641 | 2843 | } |
| 2642 | - if (! empty($conf->product->enabled)) $original_file=$conf->product->multidir_output[$entity].'/'.$original_file; |
|
| 2643 | - elseif (! empty($conf->service->enabled)) $original_file=$conf->service->multidir_output[$entity].'/'.$original_file; |
|
| 2844 | + if (! empty($conf->product->enabled)) { |
|
| 2845 | + $original_file=$conf->product->multidir_output[$entity].'/'.$original_file; |
|
| 2846 | + } elseif (! empty($conf->service->enabled)) { |
|
| 2847 | + $original_file=$conf->service->multidir_output[$entity].'/'.$original_file; |
|
| 2848 | + } |
|
| 2644 | 2849 | } |
| 2645 | 2850 | |
| 2646 | 2851 | // Wrapping pour les lots produits |
| 2647 | 2852 | else if ($modulepart == 'product_batch' || $modulepart == 'produitlot') |
| 2648 | 2853 | { |
| 2649 | - if (empty($entity) || (empty($conf->productbatch->multidir_output[$entity]))) return array('accessallowed'=>0, 'error'=>'Value entity must be provided'); |
|
| 2854 | + if (empty($entity) || (empty($conf->productbatch->multidir_output[$entity]))) { |
|
| 2855 | + return array('accessallowed'=>0, 'error'=>'Value entity must be provided'); |
|
| 2856 | + } |
|
| 2650 | 2857 | if (($fuser->rights->produit->{$lire} ) || preg_match('/^specimen/i',$original_file)) |
| 2651 | 2858 | { |
| 2652 | 2859 | $accessallowed=1; |
| 2653 | 2860 | } |
| 2654 | - if (! empty($conf->productbatch->enabled)) $original_file=$conf->productbatch->multidir_output[$entity].'/'.$original_file; |
|
| 2861 | + if (! empty($conf->productbatch->enabled)) { |
|
| 2862 | + $original_file=$conf->productbatch->multidir_output[$entity].'/'.$original_file; |
|
| 2863 | + } |
|
| 2655 | 2864 | } |
| 2656 | 2865 | |
| 2657 | 2866 | // Wrapping pour les contrats |
@@ -2732,14 +2941,18 @@ discard block |
||
| 2732 | 2941 | // Wrapping for backups |
| 2733 | 2942 | else if ($modulepart == 'systemtools' && !empty($conf->admin->dir_output)) |
| 2734 | 2943 | { |
| 2735 | - if ($fuser->admin) $accessallowed=1; |
|
| 2944 | + if ($fuser->admin) { |
|
| 2945 | + $accessallowed=1; |
|
| 2946 | + } |
|
| 2736 | 2947 | $original_file=$conf->admin->dir_output.'/'.$original_file; |
| 2737 | 2948 | } |
| 2738 | 2949 | |
| 2739 | 2950 | // Wrapping for upload file test |
| 2740 | 2951 | else if ($modulepart == 'admin_temp' && !empty($conf->admin->dir_temp)) |
| 2741 | 2952 | { |
| 2742 | - if ($fuser->admin) $accessallowed=1; |
|
| 2953 | + if ($fuser->admin) { |
|
| 2954 | + $accessallowed=1; |
|
| 2955 | + } |
|
| 2743 | 2956 | $original_file=$conf->admin->dir_temp.'/'.$original_file; |
| 2744 | 2957 | } |
| 2745 | 2958 | |
@@ -2748,7 +2961,9 @@ discard block |
||
| 2748 | 2961 | { |
| 2749 | 2962 | $accessallowed=1; |
| 2750 | 2963 | $dir='files'; |
| 2751 | - if (dol_mimetype($original_file) == 'application/x-bittorrent') $dir='torrents'; |
|
| 2964 | + if (dol_mimetype($original_file) == 'application/x-bittorrent') { |
|
| 2965 | + $dir='torrents'; |
|
| 2966 | + } |
|
| 2752 | 2967 | $original_file=$conf->bittorrent->dir_output.'/'.$dir.'/'.$original_file; |
| 2753 | 2968 | } |
| 2754 | 2969 | |
@@ -2776,45 +2991,62 @@ discard block |
||
| 2776 | 2991 | // If modulepart=module Allows any module to open a file if file is in directory called DOL_DATA_ROOT/modulepart |
| 2777 | 2992 | else |
| 2778 | 2993 | { |
| 2779 | - if (preg_match('/^specimen/i',$original_file)) $accessallowed=1; // If link to a file called specimen. Test must be done before changing $original_file int full path. |
|
| 2780 | - if ($fuser->admin) $accessallowed=1; // If user is admin |
|
| 2994 | + if (preg_match('/^specimen/i',$original_file)) { |
|
| 2995 | + $accessallowed=1; |
|
| 2996 | + } |
|
| 2997 | + // If link to a file called specimen. Test must be done before changing $original_file int full path. |
|
| 2998 | + if ($fuser->admin) { |
|
| 2999 | + $accessallowed=1; |
|
| 3000 | + } |
|
| 3001 | + // If user is admin |
|
| 2781 | 3002 | |
| 2782 | 3003 | // Define $accessallowed |
| 2783 | 3004 | if (preg_match('/^([a-z]+)_user_temp$/i',$modulepart,$reg)) |
| 2784 | 3005 | { |
| 2785 | - if (empty($conf->{$reg[1]}->dir_temp)) // modulepart not supported |
|
| 3006 | + if (empty($conf->{$reg[1]}->dir_temp)) { |
|
| 3007 | + // modulepart not supported |
|
| 2786 | 3008 | { |
| 2787 | 3009 | dol_print_error('','Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')'); |
| 3010 | + } |
|
| 2788 | 3011 | exit; |
| 2789 | 3012 | } |
| 2790 | - if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) $accessallowed=1; |
|
| 3013 | + if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) { |
|
| 3014 | + $accessallowed=1; |
|
| 3015 | + } |
|
| 2791 | 3016 | $original_file=$conf->{$reg[1]}->dir_temp.'/'.$fuser->id.'/'.$original_file; |
| 2792 | - } |
|
| 2793 | - else if (preg_match('/^([a-z]+)_temp$/i',$modulepart,$reg)) |
|
| 3017 | + } else if (preg_match('/^([a-z]+)_temp$/i',$modulepart,$reg)) |
|
| 2794 | 3018 | { |
| 2795 | - if (empty($conf->{$reg[1]}->dir_temp)) // modulepart not supported |
|
| 3019 | + if (empty($conf->{$reg[1]}->dir_temp)) { |
|
| 3020 | + // modulepart not supported |
|
| 2796 | 3021 | { |
| 2797 | 3022 | dol_print_error('','Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')'); |
| 3023 | + } |
|
| 2798 | 3024 | exit; |
| 2799 | 3025 | } |
| 2800 | - if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) $accessallowed=1; |
|
| 3026 | + if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) { |
|
| 3027 | + $accessallowed=1; |
|
| 3028 | + } |
|
| 2801 | 3029 | $original_file=$conf->{$reg[1]}->dir_temp.'/'.$original_file; |
| 2802 | - } |
|
| 2803 | - else if (preg_match('/^([a-z]+)_user$/i',$modulepart,$reg)) |
|
| 3030 | + } else if (preg_match('/^([a-z]+)_user$/i',$modulepart,$reg)) |
|
| 2804 | 3031 | { |
| 2805 | - if (empty($conf->{$reg[1]}->dir_output)) // modulepart not supported |
|
| 3032 | + if (empty($conf->{$reg[1]}->dir_output)) { |
|
| 3033 | + // modulepart not supported |
|
| 2806 | 3034 | { |
| 2807 | 3035 | dol_print_error('','Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')'); |
| 3036 | + } |
|
| 2808 | 3037 | exit; |
| 2809 | 3038 | } |
| 2810 | - if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) $accessallowed=1; |
|
| 3039 | + if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) { |
|
| 3040 | + $accessallowed=1; |
|
| 3041 | + } |
|
| 2811 | 3042 | $original_file=$conf->{$reg[1]}->dir_output.'/'.$fuser->id.'/'.$original_file; |
| 2812 | - } |
|
| 2813 | - else if (preg_match('/^massfilesarea_([a-z]+)$/i', $modulepart, $reg)) |
|
| 3043 | + } else if (preg_match('/^massfilesarea_([a-z]+)$/i', $modulepart, $reg)) |
|
| 2814 | 3044 | { |
| 2815 | - if (empty($conf->{$reg[1]}->dir_output)) // modulepart not supported |
|
| 3045 | + if (empty($conf->{$reg[1]}->dir_output)) { |
|
| 3046 | + // modulepart not supported |
|
| 2816 | 3047 | { |
| 2817 | 3048 | dol_print_error('','Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')'); |
| 3049 | + } |
|
| 2818 | 3050 | exit; |
| 2819 | 3051 | } |
| 2820 | 3052 | if ($fuser->rights->{$reg[1]}->{$lire} || preg_match('/^specimen/i', $original_file)) |
@@ -2822,12 +3054,13 @@ discard block |
||
| 2822 | 3054 | $accessallowed=1; |
| 2823 | 3055 | } |
| 2824 | 3056 | $original_file=$conf->{$reg[1]}->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; |
| 2825 | - } |
|
| 2826 | - else |
|
| 3057 | + } else |
|
| 2827 | 3058 | { |
| 2828 | - if (empty($conf->$modulepart->dir_output)) // modulepart not supported |
|
| 3059 | + if (empty($conf->$modulepart->dir_output)) { |
|
| 3060 | + // modulepart not supported |
|
| 2829 | 3061 | { |
| 2830 | 3062 | dol_print_error('','Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.')'); |
| 3063 | + } |
|
| 2831 | 3064 | exit; |
| 2832 | 3065 | } |
| 2833 | 3066 | |
@@ -2835,12 +3068,15 @@ discard block |
||
| 2835 | 3068 | $subperm=GETPOST('subperm'); |
| 2836 | 3069 | if ($perm || $subperm) |
| 2837 | 3070 | { |
| 2838 | - if (($perm && ! $subperm && $fuser->rights->$modulepart->$perm) || ($perm && $subperm && $fuser->rights->$modulepart->$perm->$subperm)) $accessallowed=1; |
|
| 3071 | + if (($perm && ! $subperm && $fuser->rights->$modulepart->$perm) || ($perm && $subperm && $fuser->rights->$modulepart->$perm->$subperm)) { |
|
| 3072 | + $accessallowed=1; |
|
| 3073 | + } |
|
| 2839 | 3074 | $original_file=$conf->$modulepart->dir_output.'/'.$original_file; |
| 2840 | - } |
|
| 2841 | - else |
|
| 3075 | + } else |
|
| 2842 | 3076 | { |
| 2843 | - if ($fuser->rights->$modulepart->{$lire} || $fuser->rights->$modulepart->{$read}) $accessallowed=1; |
|
| 3077 | + if ($fuser->rights->$modulepart->{$lire} || $fuser->rights->$modulepart->{$read}) { |
|
| 3078 | + $accessallowed=1; |
|
| 3079 | + } |
|
| 2844 | 3080 | $original_file=$conf->$modulepart->dir_output.'/'.$original_file; |
| 2845 | 3081 | } |
| 2846 | 3082 | } |
@@ -2858,11 +3094,13 @@ discard block |
||
| 2858 | 3094 | |
| 2859 | 3095 | // Define $sqlprotectagainstexternals for modules who want to protect access using a SQL query. |
| 2860 | 3096 | $sqlProtectConstName = strtoupper($modulepart).'_SQLPROTECTAGAINSTEXTERNALS_FOR_DOCUMENTS'; |
| 2861 | - if (! empty($conf->global->$sqlProtectConstName)) // If module want to define its own $sqlprotectagainstexternals |
|
| 3097 | + if (! empty($conf->global->$sqlProtectConstName)) { |
|
| 3098 | + // If module want to define its own $sqlprotectagainstexternals |
|
| 2862 | 3099 | { |
| 2863 | 3100 | // Example: mymodule__SQLPROTECTAGAINSTEXTERNALS_FOR_DOCUMENTS = "SELECT fk_soc FROM ".MAIN_DB_PREFIX.$modulepart." WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity; |
| 2864 | 3101 | eval('$sqlprotectagainstexternals = "'.$conf->global->$sqlProtectConstName.'";'); |
| 2865 | 3102 | } |
| 3103 | + } |
|
| 2866 | 3104 | } |
| 2867 | 3105 | |
| 2868 | 3106 | $ret = array( |
@@ -2884,7 +3122,9 @@ discard block |
||
| 2884 | 3122 | */ |
| 2885 | 3123 | function dol_filecache($directory, $filename, $object) |
| 2886 | 3124 | { |
| 2887 | - if (! dol_is_dir($directory)) dol_mkdir($directory); |
|
| 3125 | + if (! dol_is_dir($directory)) { |
|
| 3126 | + dol_mkdir($directory); |
|
| 3127 | + } |
|
| 2888 | 3128 | $cachefile = $directory . $filename; |
| 2889 | 3129 | file_put_contents($cachefile, serialize($object), LOCK_EX); |
| 2890 | 3130 | @chmod($cachefile, 0644); |
@@ -2938,9 +3178,11 @@ discard block |
||
| 2938 | 3178 | |
| 2939 | 3179 | $exclude = 'install'; |
| 2940 | 3180 | |
| 2941 | - foreach ($dir->md5file as $file) // $file is a simpleXMLElement |
|
| 3181 | + foreach ($dir->md5file as $file) { |
|
| 3182 | + // $file is a simpleXMLElement |
|
| 2942 | 3183 | { |
| 2943 | 3184 | $filename = $path.$file['name']; |
| 3185 | + } |
|
| 2944 | 3186 | $file_list['insignature'][] = $filename; |
| 2945 | 3187 | $expectedmd5 = (string) $file; |
| 2946 | 3188 | |
@@ -2949,27 +3191,31 @@ discard block |
||
| 2949 | 3191 | if (!file_exists($pathref.'/'.$filename)) |
| 2950 | 3192 | { |
| 2951 | 3193 | $file_list['missing'][] = array('filename'=>$filename, 'expectedmd5'=>$expectedmd5); |
| 2952 | - } |
|
| 2953 | - else |
|
| 3194 | + } else |
|
| 2954 | 3195 | { |
| 2955 | 3196 | $md5_local = md5_file($pathref.'/'.$filename); |
| 2956 | 3197 | |
| 2957 | - if ($conffile == '/etc/dolibarr/conf.php' && $filename == '/filefunc.inc.php') // For install with deb or rpm, we ignore test on filefunc.inc.php that was modified by package |
|
| 3198 | + if ($conffile == '/etc/dolibarr/conf.php' && $filename == '/filefunc.inc.php') { |
|
| 3199 | + // For install with deb or rpm, we ignore test on filefunc.inc.php that was modified by package |
|
| 2958 | 3200 | { |
| 2959 | 3201 | $checksumconcat[] = $expectedmd5; |
| 2960 | 3202 | } |
| 2961 | - else |
|
| 3203 | + } else |
|
| 2962 | 3204 | { |
| 2963 | - if ($md5_local != $expectedmd5) $file_list['updated'][] = array('filename'=>$filename, 'expectedmd5'=>$expectedmd5, 'md5'=>(string) $md5_local); |
|
| 3205 | + if ($md5_local != $expectedmd5) { |
|
| 3206 | + $file_list['updated'][] = array('filename'=>$filename, 'expectedmd5'=>$expectedmd5, 'md5'=>(string) $md5_local); |
|
| 3207 | + } |
|
| 2964 | 3208 | $checksumconcat[] = $md5_local; |
| 2965 | 3209 | } |
| 2966 | 3210 | } |
| 2967 | 3211 | } |
| 2968 | 3212 | |
| 2969 | - foreach ($dir->dir as $subdir) // $subdir['name'] is '' or '/accountancy/admin' for example |
|
| 3213 | + foreach ($dir->dir as $subdir) { |
|
| 3214 | + // $subdir['name'] is '' or '/accountancy/admin' for example |
|
| 2970 | 3215 | { |
| 2971 | 3216 | getFilesUpdated($file_list, $subdir, $path.$subdir['name'].'/', $pathref, $checksumconcat); |
| 2972 | 3217 | } |
| 3218 | + } |
|
| 2973 | 3219 | |
| 2974 | 3220 | return $file_list; |
| 2975 | 3221 | } |
@@ -34,29 +34,29 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | function expedition_prepare_head(Expedition $object) |
| 36 | 36 | { |
| 37 | - global $langs, $conf, $user; |
|
| 38 | - if (! empty($conf->expedition->enabled)) $langs->load("sendings"); |
|
| 39 | - $langs->load("orders"); |
|
| 37 | + global $langs, $conf, $user; |
|
| 38 | + if (! empty($conf->expedition->enabled)) $langs->load("sendings"); |
|
| 39 | + $langs->load("orders"); |
|
| 40 | 40 | |
| 41 | - $h = 0; |
|
| 42 | - $head = array(); |
|
| 43 | - $h = 0; |
|
| 44 | - |
|
| 45 | - $head[$h][0] = DOL_URL_ROOT."/admin/confexped.php"; |
|
| 46 | - $head[$h][1] = $langs->trans("Setup"); |
|
| 47 | - $h++; |
|
| 48 | - |
|
| 49 | - $head[$h][0] = DOL_URL_ROOT."/admin/expedition.php"; |
|
| 50 | - $head[$h][1] = $langs->trans("Shipment"); |
|
| 51 | - $hselected=$h; |
|
| 52 | - $h++; |
|
| 53 | - |
|
| 54 | - if (! empty($conf->global->MAIN_SUBMODULE_LIVRAISON)) |
|
| 55 | - { |
|
| 56 | - $head[$h][0] = DOL_URL_ROOT."/admin/livraison.php"; |
|
| 57 | - $head[$h][1] = $langs->trans("Receivings"); |
|
| 58 | - $h++; |
|
| 59 | - } |
|
| 41 | + $h = 0; |
|
| 42 | + $head = array(); |
|
| 43 | + $h = 0; |
|
| 44 | + |
|
| 45 | + $head[$h][0] = DOL_URL_ROOT."/admin/confexped.php"; |
|
| 46 | + $head[$h][1] = $langs->trans("Setup"); |
|
| 47 | + $h++; |
|
| 48 | + |
|
| 49 | + $head[$h][0] = DOL_URL_ROOT."/admin/expedition.php"; |
|
| 50 | + $head[$h][1] = $langs->trans("Shipment"); |
|
| 51 | + $hselected=$h; |
|
| 52 | + $h++; |
|
| 53 | + |
|
| 54 | + if (! empty($conf->global->MAIN_SUBMODULE_LIVRAISON)) |
|
| 55 | + { |
|
| 56 | + $head[$h][0] = DOL_URL_ROOT."/admin/livraison.php"; |
|
| 57 | + $head[$h][1] = $langs->trans("Receivings"); |
|
| 58 | + $h++; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | 61 | |
| 62 | 62 | complete_head_from_modules($conf,$langs,$object,$head,$h,'order','remove'); |
@@ -71,72 +71,72 @@ discard block |
||
| 71 | 71 | */ |
| 72 | 72 | function expedition_admin_prepare_head() |
| 73 | 73 | { |
| 74 | - global $langs, $conf, $user; |
|
| 75 | - $langs->load("sendings"); |
|
| 74 | + global $langs, $conf, $user; |
|
| 75 | + $langs->load("sendings"); |
|
| 76 | 76 | |
| 77 | - $h = 0; |
|
| 78 | - $head = array(); |
|
| 79 | - |
|
| 80 | - $head[$h][0] = DOL_URL_ROOT."/admin/confexped.php"; |
|
| 81 | - $head[$h][1] = $langs->trans("Setup"); |
|
| 82 | - $head[$h][2] = 'general'; |
|
| 83 | - $h++; |
|
| 84 | - |
|
| 85 | - |
|
| 86 | - if (! empty($conf->global->MAIN_SUBMODULE_EXPEDITION)) |
|
| 87 | - { |
|
| 88 | - $head[$h][0] = DOL_URL_ROOT."/admin/expedition.php"; |
|
| 89 | - $head[$h][1] = $langs->trans("Shipment"); |
|
| 90 | - $head[$h][2] = 'shipment'; |
|
| 91 | - $h++; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - if (! empty($conf->global->MAIN_SUBMODULE_EXPEDITION)) |
|
| 96 | - { |
|
| 97 | - $head[$h][0] = DOL_URL_ROOT.'/admin/expedition_extrafields.php'; |
|
| 98 | - $head[$h][1] = $langs->trans("ExtraFields"); |
|
| 99 | - $head[$h][2] = 'attributes_shipment'; |
|
| 100 | - $h++; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - if (! empty($conf->global->MAIN_SUBMODULE_EXPEDITION)) |
|
| 104 | - { |
|
| 105 | - $head[$h][0] = DOL_URL_ROOT.'/admin/expeditiondet_extrafields.php'; |
|
| 106 | - $head[$h][1] = $langs->trans("ExtraFieldsLines"); |
|
| 107 | - $head[$h][2] = 'attributeslines_shipment'; |
|
| 108 | - $h++; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - if (! empty($conf->global->MAIN_SUBMODULE_LIVRAISON)) |
|
| 112 | - { |
|
| 113 | - $head[$h][0] = DOL_URL_ROOT."/admin/livraison.php"; |
|
| 114 | - $head[$h][1] = $langs->trans("Receivings"); |
|
| 115 | - $head[$h][2] = 'receivings'; |
|
| 116 | - $h++; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - if (! empty($conf->global->MAIN_SUBMODULE_LIVRAISON)) |
|
| 120 | - { |
|
| 121 | - $head[$h][0] = DOL_URL_ROOT.'/admin/livraison_extrafields.php'; |
|
| 122 | - $head[$h][1] = $langs->trans("ExtraFields"); |
|
| 123 | - $head[$h][2] = 'attributes_receivings'; |
|
| 124 | - $h++; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - if (! empty($conf->global->MAIN_SUBMODULE_LIVRAISON)) |
|
| 128 | - { |
|
| 129 | - $head[$h][0] = DOL_URL_ROOT.'/admin/livraisondet_extrafields.php'; |
|
| 130 | - $head[$h][1] = $langs->trans("ExtraFieldsLines"); |
|
| 131 | - $head[$h][2] = 'attributeslines_receivings'; |
|
| 132 | - $h++; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - |
|
| 136 | - |
|
| 137 | - complete_head_from_modules($conf,$langs,null,$head,$h,'expedition_admin','remove'); |
|
| 77 | + $h = 0; |
|
| 78 | + $head = array(); |
|
| 79 | + |
|
| 80 | + $head[$h][0] = DOL_URL_ROOT."/admin/confexped.php"; |
|
| 81 | + $head[$h][1] = $langs->trans("Setup"); |
|
| 82 | + $head[$h][2] = 'general'; |
|
| 83 | + $h++; |
|
| 84 | + |
|
| 85 | + |
|
| 86 | + if (! empty($conf->global->MAIN_SUBMODULE_EXPEDITION)) |
|
| 87 | + { |
|
| 88 | + $head[$h][0] = DOL_URL_ROOT."/admin/expedition.php"; |
|
| 89 | + $head[$h][1] = $langs->trans("Shipment"); |
|
| 90 | + $head[$h][2] = 'shipment'; |
|
| 91 | + $h++; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + if (! empty($conf->global->MAIN_SUBMODULE_EXPEDITION)) |
|
| 96 | + { |
|
| 97 | + $head[$h][0] = DOL_URL_ROOT.'/admin/expedition_extrafields.php'; |
|
| 98 | + $head[$h][1] = $langs->trans("ExtraFields"); |
|
| 99 | + $head[$h][2] = 'attributes_shipment'; |
|
| 100 | + $h++; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + if (! empty($conf->global->MAIN_SUBMODULE_EXPEDITION)) |
|
| 104 | + { |
|
| 105 | + $head[$h][0] = DOL_URL_ROOT.'/admin/expeditiondet_extrafields.php'; |
|
| 106 | + $head[$h][1] = $langs->trans("ExtraFieldsLines"); |
|
| 107 | + $head[$h][2] = 'attributeslines_shipment'; |
|
| 108 | + $h++; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + if (! empty($conf->global->MAIN_SUBMODULE_LIVRAISON)) |
|
| 112 | + { |
|
| 113 | + $head[$h][0] = DOL_URL_ROOT."/admin/livraison.php"; |
|
| 114 | + $head[$h][1] = $langs->trans("Receivings"); |
|
| 115 | + $head[$h][2] = 'receivings'; |
|
| 116 | + $h++; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + if (! empty($conf->global->MAIN_SUBMODULE_LIVRAISON)) |
|
| 120 | + { |
|
| 121 | + $head[$h][0] = DOL_URL_ROOT.'/admin/livraison_extrafields.php'; |
|
| 122 | + $head[$h][1] = $langs->trans("ExtraFields"); |
|
| 123 | + $head[$h][2] = 'attributes_receivings'; |
|
| 124 | + $h++; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + if (! empty($conf->global->MAIN_SUBMODULE_LIVRAISON)) |
|
| 128 | + { |
|
| 129 | + $head[$h][0] = DOL_URL_ROOT.'/admin/livraisondet_extrafields.php'; |
|
| 130 | + $head[$h][1] = $langs->trans("ExtraFieldsLines"); |
|
| 131 | + $head[$h][2] = 'attributeslines_receivings'; |
|
| 132 | + $h++; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + |
|
| 136 | + |
|
| 137 | + complete_head_from_modules($conf,$langs,null,$head,$h,'expedition_admin','remove'); |
|
| 138 | 138 | |
| 139 | - return $head; |
|
| 139 | + return $head; |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | function expedition_prepare_head(Expedition $object) |
| 36 | 36 | { |
| 37 | 37 | global $langs, $conf, $user; |
| 38 | - if (! empty($conf->expedition->enabled)) $langs->load("sendings"); |
|
| 38 | + if (!empty($conf->expedition->enabled)) $langs->load("sendings"); |
|
| 39 | 39 | $langs->load("orders"); |
| 40 | 40 | |
| 41 | 41 | $h = 0; |
@@ -48,10 +48,10 @@ discard block |
||
| 48 | 48 | |
| 49 | 49 | $head[$h][0] = DOL_URL_ROOT."/admin/expedition.php"; |
| 50 | 50 | $head[$h][1] = $langs->trans("Shipment"); |
| 51 | - $hselected=$h; |
|
| 51 | + $hselected = $h; |
|
| 52 | 52 | $h++; |
| 53 | 53 | |
| 54 | - if (! empty($conf->global->MAIN_SUBMODULE_LIVRAISON)) |
|
| 54 | + if (!empty($conf->global->MAIN_SUBMODULE_LIVRAISON)) |
|
| 55 | 55 | { |
| 56 | 56 | $head[$h][0] = DOL_URL_ROOT."/admin/livraison.php"; |
| 57 | 57 | $head[$h][1] = $langs->trans("Receivings"); |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | |
| 62 | - complete_head_from_modules($conf,$langs,$object,$head,$h,'order','remove'); |
|
| 62 | + complete_head_from_modules($conf, $langs, $object, $head, $h, 'order', 'remove'); |
|
| 63 | 63 | |
| 64 | 64 | return $head; |
| 65 | 65 | } |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | $h++; |
| 84 | 84 | |
| 85 | 85 | |
| 86 | - if (! empty($conf->global->MAIN_SUBMODULE_EXPEDITION)) |
|
| 86 | + if (!empty($conf->global->MAIN_SUBMODULE_EXPEDITION)) |
|
| 87 | 87 | { |
| 88 | 88 | $head[$h][0] = DOL_URL_ROOT."/admin/expedition.php"; |
| 89 | 89 | $head[$h][1] = $langs->trans("Shipment"); |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | |
| 95 | - if (! empty($conf->global->MAIN_SUBMODULE_EXPEDITION)) |
|
| 95 | + if (!empty($conf->global->MAIN_SUBMODULE_EXPEDITION)) |
|
| 96 | 96 | { |
| 97 | 97 | $head[$h][0] = DOL_URL_ROOT.'/admin/expedition_extrafields.php'; |
| 98 | 98 | $head[$h][1] = $langs->trans("ExtraFields"); |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | $h++; |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - if (! empty($conf->global->MAIN_SUBMODULE_EXPEDITION)) |
|
| 103 | + if (!empty($conf->global->MAIN_SUBMODULE_EXPEDITION)) |
|
| 104 | 104 | { |
| 105 | 105 | $head[$h][0] = DOL_URL_ROOT.'/admin/expeditiondet_extrafields.php'; |
| 106 | 106 | $head[$h][1] = $langs->trans("ExtraFieldsLines"); |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | $h++; |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - if (! empty($conf->global->MAIN_SUBMODULE_LIVRAISON)) |
|
| 111 | + if (!empty($conf->global->MAIN_SUBMODULE_LIVRAISON)) |
|
| 112 | 112 | { |
| 113 | 113 | $head[$h][0] = DOL_URL_ROOT."/admin/livraison.php"; |
| 114 | 114 | $head[$h][1] = $langs->trans("Receivings"); |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | $h++; |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - if (! empty($conf->global->MAIN_SUBMODULE_LIVRAISON)) |
|
| 119 | + if (!empty($conf->global->MAIN_SUBMODULE_LIVRAISON)) |
|
| 120 | 120 | { |
| 121 | 121 | $head[$h][0] = DOL_URL_ROOT.'/admin/livraison_extrafields.php'; |
| 122 | 122 | $head[$h][1] = $langs->trans("ExtraFields"); |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | $h++; |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | - if (! empty($conf->global->MAIN_SUBMODULE_LIVRAISON)) |
|
| 127 | + if (!empty($conf->global->MAIN_SUBMODULE_LIVRAISON)) |
|
| 128 | 128 | { |
| 129 | 129 | $head[$h][0] = DOL_URL_ROOT.'/admin/livraisondet_extrafields.php'; |
| 130 | 130 | $head[$h][1] = $langs->trans("ExtraFieldsLines"); |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | |
| 135 | 135 | |
| 136 | 136 | |
| 137 | - complete_head_from_modules($conf,$langs,null,$head,$h,'expedition_admin','remove'); |
|
| 137 | + complete_head_from_modules($conf, $langs, null, $head, $h, 'expedition_admin', 'remove'); |
|
| 138 | 138 | |
| 139 | 139 | return $head; |
| 140 | 140 | } |
@@ -35,7 +35,9 @@ |
||
| 35 | 35 | function expedition_prepare_head(Expedition $object) |
| 36 | 36 | { |
| 37 | 37 | global $langs, $conf, $user; |
| 38 | - if (! empty($conf->expedition->enabled)) $langs->load("sendings"); |
|
| 38 | + if (! empty($conf->expedition->enabled)) { |
|
| 39 | + $langs->load("sendings"); |
|
| 40 | + } |
|
| 39 | 41 | $langs->load("orders"); |
| 40 | 42 | |
| 41 | 43 | $h = 0; |