dolibarr  17.0.3
dav.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2008-2019 Laurent Destailleur <eldy@users.sourceforge.net>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16  */
17 
24 // Load Dolibarr environment
25 require '../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
27 require_once DOL_DOCUMENT_ROOT.'/dav/dav.lib.php';
28 
29 // Load translation files required by the page
30 $langs->loadLangs(array("admin", "other", "agenda"));
31 
32 if (!$user->admin) {
34 }
35 
36 // Parameters
37 $action = GETPOST('action', 'aZ09');
38 $backtopage = GETPOST('backtopage', 'alpha');
39 
40 
41 
42 $arrayofparameters = array(
43  'DAV_RESTICT_ON_IP'=>array('css'=>'minwidth200', 'enabled'=>1),
44  'DAV_ALLOW_PRIVATE_DIR'=>array('css'=>'minwidth200', 'enabled'=>2),
45  'DAV_ALLOW_PUBLIC_DIR'=>array('css'=>'minwidth200', 'enabled'=>1),
46  'DAV_ALLOW_ECM_DIR'=>array('css'=>'minwidth200', 'enabled'=>isModEnabled('ecm'))
47 );
48 
49 // To fix when dire does not exists
50 dol_mkdir($conf->dav->dir_output.'/temp');
51 dol_mkdir($conf->dav->dir_output.'/public');
52 dol_mkdir($conf->dav->dir_output.'/private');
53 
54 
55 /*
56  * Actions
57  */
58 
59 include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
60 
61 
62 
63 /*
64  * View
65  */
66 
67 $help_url = 'EN:Module_DAV';
68 
69 llxHeader('', $langs->trans("DAVSetup"), $help_url);
70 
71 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
72 print load_fiche_titre($langs->trans("DAVSetup"), $linkback, 'title_setup');
73 
74 
75 print '<form name="agendasetupform" action="'.$_SERVER["PHP_SELF"].'" method="post">';
76 print '<input type="hidden" name="token" value="'.newToken().'">';
77 
78 $head = dav_admin_prepare_head();
79 
80 print dol_get_fiche_head($head, 'webdav', '', -1, '');
81 
82 if ($action == 'edit') {
83  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
84  print '<input type="hidden" name="token" value="'.newToken().'">';
85  print '<input type="hidden" name="action" value="update">';
86 
87  print '<table class="noborder centpercent nomarginbottom">';
88  print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
89 
90  foreach ($arrayofparameters as $key => $val) {
91  if (isset($val['enabled']) && empty($val['enabled'])) {
92  continue;
93  }
94 
95  print '<tr class="oddeven"><td>';
96  $tooltiphelp = (($langs->trans($key.'Tooltip') != $key.'Tooltip') ? $langs->trans($key.'Tooltip') : '');
97  $label = $langs->trans($key);
98  if ($key == 'DAV_RESTICT_ON_IP') {
99  $label = $langs->trans("RESTRICT_ON_IP");
100  $tooltiphelp .= ' '.$langs->trans("Example").': '.$langs->trans("IPListExample");
101  }
102  print $form->textwithpicto($label, $tooltiphelp);
103  print '</td><td>';
104  if ($key == 'DAV_ALLOW_PRIVATE_DIR') {
105  print $langs->trans("AlwaysActive");
106  } elseif ($key == 'DAV_ALLOW_PUBLIC_DIR' || $key == 'DAV_ALLOW_ECM_DIR') {
107  print $form->selectyesno($key, $conf->global->$key, 1);
108  } else {
109  print '<input name="'.$key.'" class="flat '.(empty($val['css']) ? 'minwidth200' : $val['css']).'" value="'.getDolGlobalString($key).'">';
110  }
111  print '</td></tr>';
112  }
113 
114  print '</table>';
115 
116  print '<br><div class="center">';
117  print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
118  print '</div>';
119 
120  print '</form>';
121  print '<br>';
122 } else {
123  print '<table class="noborder centpercent nomarginbottom">';
124  print '<tr class="liste_titre"><td>'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
125 
126  foreach ($arrayofparameters as $key => $val) {
127  if (isset($val['enabled']) && empty($val['enabled'])) {
128  continue;
129  }
130 
131  print '<tr class="oddeven"><td>';
132  $tooltiphelp = (($langs->trans($key.'Tooltip') != $key.'Tooltip') ? $langs->trans($key.'Tooltip') : '');
133  $label = $langs->trans($key);
134  if ($key == 'DAV_RESTICT_ON_IP') {
135  $label = $langs->trans("RESTRICT_ON_IP");
136  $tooltiphelp .= ' <span class="opacitymedium">'.$langs->trans("Example").': '.$langs->trans("IPListExample").'</span>';
137  }
138  print $form->textwithpicto($label, $tooltiphelp);
139  print '</td><td class="minwidth200">';
140  if ($key == 'DAV_ALLOW_PRIVATE_DIR') {
141  print $langs->trans("AlwaysActive");
142  } elseif ($key == 'DAV_ALLOW_PUBLIC_DIR' || $key == 'DAV_ALLOW_ECM_DIR') {
143  print yn($conf->global->$key);
144  } else {
145  print $conf->global->$key;
146  }
147  print '</td></tr>';
148  }
149 
150  print '</table>';
151 
152  print '<div class="tabsAction">';
153  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>';
154  print '</div>';
155 }
156 
157 
158 print dol_get_fiche_end();
159 
160 /*print '<div class="center">';
161 print '<input type="submit" name="save" class="button button-save" value="'.$langs->trans("Save").'">';
162 print "</div>";
163 */
164 print "</form>\n";
165 
166 
167 clearstatcache();
168 
169 print '<span class="opacitymedium">'.$langs->trans("WebDAVSetupDesc")."</span><br>\n";
170 print "<br>";
171 
172 
173 // Define $urlwithroot
174 $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
175 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
176 //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
177 
178 
179 // Show message
180 $message = '';
181 $url = '<a href="'.$urlwithroot.'/dav/fileserver.php" target="_blank" rel="noopener noreferrer">'.$urlwithroot.'/dav/fileserver.php</a>';
182 
183 $message .= img_picto('', 'globe').' '.str_replace('{url}', $url, $langs->trans("WebDavServer", 'WebDAV', ''));
184 $message .= '<div class="urllink"><input type="text" id="webdavpublicurl" class="quatrevingtpercent" value="'.$urlwithroot.'/dav/fileserver.php">';
185 $message .= '<a href="'.$urlwithroot.'/dav/fileserver.php" target="_blank" rel="noopener noreferrer">';
186 $message .= ' '.img_picto('', 'globe');
187 $message .= '</a>';
188 $message .= '</div>';
189 $message .= ajax_autoselect('webdavpublicurl');
190 
191 $message .= '<br>';
192 if (!empty($conf->global->DAV_ALLOW_PUBLIC_DIR)) {
193  $urlEntity = (isModEnabled('multicompany') ? '?entity=' . $conf->entity : '');
194  $url = '<a href="' . $urlwithroot . '/dav/fileserver.php/public/' . $urlEntity . '" target="_blank" rel="noopener noreferrer">' . $urlwithroot . '/dav/fileserver.php/public/' . $urlEntity . '</a>';
195 
196  $message .= img_picto('', 'globe') . ' ' . str_replace('{url}', $url, $langs->trans("WebDavServer", 'WebDAV public', ''));
197  $message .= '<div class="urllink"><input type="text" id="webdavurl" class="quatrevingtpercent" value="' . $urlwithroot . '/dav/fileserver.php/public/' . $urlEntity . '">';
198  $message .= '<a href="' . $urlwithroot . '/dav/fileserver.php/public/' . $urlEntity . '" target="_blank" rel="noopener noreferrer">';
199  $message .= ' ' . img_picto('', 'globe');
200  $message .= '</a>';
201  $message .= '</div>';
202  $message .= ajax_autoselect('webdavurl');
203  $message .= '<br>';
204 }
205 print $message;
206 
207 print '<br>';
208 
209 require_once DOL_DOCUMENT_ROOT.'/includes/sabre/autoload.php';
210 $version = Sabre\DAV\Version::VERSION;
211 print '<span class="opacitymedium">'.$langs->trans("BaseOnSabeDavVersion").' : '.$version.'</span>';
212 
213 
214 // End of page
215 llxFooter();
216 $db->close();
yn
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
Definition: functions.lib.php:6677
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:70
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5360
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:520
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
$help_url
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:118
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:4024
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1858
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:82
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:11295
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2054
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:137
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
Definition: security.lib.php:1125
ajax_autoselect
ajax_autoselect($htmlname, $addlink='', $textonlink='Link')
Make content of an input box selected when we click into input field.
Definition: functions.lib.php:10088
dav_admin_prepare_head
if(!defined('CDAV_CONTACT_TAG')) if(!defined('CDAV_URI_KEY')) dav_admin_prepare_head()
Prepare array with list of tabs.
Definition: dav.lib.php:50
dol_mkdir
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
Definition: functions.lib.php:6789