settings.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. use \OCA\Files_External\Lib\Backend\Backend;
  3. use \OCA\Files_External\Lib\DefinitionParameter;
  4. use \OCA\Files_External\Service\BackendService;
  5. script('files_external', 'settings');
  6. style('files_external', 'settings');
  7. // load custom JS
  8. foreach ($_['backends'] as $backend) {
  9. if ($backend->getCustomJs()) {
  10. script('files_external', $backend->getCustomJs());
  11. }
  12. }
  13. foreach ($_['authMechanisms'] as $authMechanism) {
  14. if ($authMechanism->getCustomJs()) {
  15. script('files_external', $authMechanism->getCustomJs());
  16. }
  17. }
  18. function writeParameterInput($parameter, $options, $classes = []) {
  19. $value = '';
  20. if (isset($options[$parameter->getName()])) {
  21. $value = $options[$parameter->getName()];
  22. }
  23. $placeholder = $parameter->getText();
  24. $is_optional = $parameter->isFlagSet(DefinitionParameter::FLAG_OPTIONAL);
  25. switch ($parameter->getType()) {
  26. case DefinitionParameter::VALUE_PASSWORD: ?>
  27. <?php if ($is_optional) { $classes[] = 'optional'; } ?>
  28. <input type="password"
  29. <?php if (!empty($classes)): ?> class="<?php p(implode(' ', $classes)); ?>"<?php endif; ?>
  30. data-parameter="<?php p($parameter->getName()); ?>"
  31. value="<?php p($value); ?>"
  32. placeholder="<?php p($placeholder); ?>"
  33. />
  34. <?php
  35. break;
  36. case DefinitionParameter::VALUE_BOOLEAN: ?>
  37. <?php $checkboxId = uniqid("checkbox_"); ?>
  38. <input type="checkbox"
  39. id="<?php p($checkboxId); ?>"
  40. <?php if (!empty($classes)): ?> class="checkbox <?php p(implode(' ', $classes)); ?>"<?php endif; ?>
  41. data-parameter="<?php p($parameter->getName()); ?>"
  42. <?php if ($value === true): ?> checked="checked"<?php endif; ?>
  43. />
  44. <label for="<?php p($checkboxId); ?>"><?php p($placeholder); ?></label>
  45. <?php
  46. break;
  47. case DefinitionParameter::VALUE_HIDDEN: ?>
  48. <input type="hidden"
  49. <?php if (!empty($classes)): ?> class="<?php p(implode(' ', $classes)); ?>"<?php endif; ?>
  50. data-parameter="<?php p($parameter->getName()); ?>"
  51. value="<?php p($value); ?>"
  52. />
  53. <?php
  54. break;
  55. default: ?>
  56. <?php if ($is_optional) { $classes[] = 'optional'; } ?>
  57. <input type="text"
  58. <?php if (!empty($classes)): ?> class="<?php p(implode(' ', $classes)); ?>"<?php endif; ?>
  59. data-parameter="<?php p($parameter->getName()); ?>"
  60. value="<?php p($value); ?>"
  61. placeholder="<?php p($placeholder); ?>"
  62. />
  63. <?php
  64. }
  65. }
  66. ?>
  67. <form autocomplete="false" class="section" action="#"
  68. id="global_credentials">
  69. <h2><?php p($l->t('External Storage')); ?></h2>
  70. <p><?php p($l->t('Global Credentials')); ?></p>
  71. <input type="text" name="username"
  72. autocomplete="false"
  73. value="<?php p($_['globalCredentials']['user']); ?>"
  74. placeholder="<?php p($l->t('Username')) ?>"/>
  75. <input type="password" name="password"
  76. autocomplete="false"
  77. value="<?php p($_['globalCredentials']['password']); ?>"
  78. placeholder="<?php p($l->t('Password')) ?>"/>
  79. <input type="hidden" name="uid"
  80. value="<?php p($_['globalCredentialsUid']); ?>"/>
  81. <input type="submit" value="<?php p($l->t('Save')) ?>"/>
  82. </form>
  83. <form id="files_external" class="section" data-encryption-enabled="<?php echo $_['encryptionEnabled']?'true': 'false'; ?>">
  84. <?php if (isset($_['dependencies']) and ($_['dependencies']<>'')) print_unescaped(''.$_['dependencies'].''); ?>
  85. <table id="externalStorage" class="grid" data-admin='<?php print_unescaped(json_encode($_['visibilityType'] === BackendService::VISIBILITY_ADMIN)); ?>'>
  86. <thead>
  87. <tr>
  88. <th></th>
  89. <th><?php p($l->t('Folder name')); ?></th>
  90. <th><?php p($l->t('External storage')); ?></th>
  91. <th><?php p($l->t('Authentication')); ?></th>
  92. <th><?php p($l->t('Configuration')); ?></th>
  93. <?php if ($_['visibilityType'] === BackendService::VISIBILITY_ADMIN) print_unescaped('<th>'.$l->t('Available for').'</th>'); ?>
  94. <th>&nbsp;</th>
  95. <th>&nbsp;</th>
  96. </tr>
  97. </thead>
  98. <tbody>
  99. <tr id="addMountPoint">
  100. <td class="status">
  101. <span></span>
  102. </td>
  103. <td class="mountPoint"><input type="text" name="mountPoint" value=""
  104. placeholder="<?php p($l->t('Folder name')); ?>">
  105. </td>
  106. <td class="backend">
  107. <select id="selectBackend" class="selectBackend" data-configurations='<?php p(json_encode($_['backends'])); ?>'>
  108. <option value="" disabled selected
  109. style="display:none;">
  110. <?php p($l->t('Add storage')); ?>
  111. </option>
  112. <?php
  113. $sortedBackends = array_filter($_['backends'], function($backend) use ($_) {
  114. return $backend->isVisibleFor($_['visibilityType']);
  115. });
  116. uasort($sortedBackends, function($a, $b) {
  117. return strcasecmp($a->getText(), $b->getText());
  118. });
  119. ?>
  120. <?php foreach ($sortedBackends as $backend): ?>
  121. <?php if ($backend->getDeprecateTo()) continue; // ignore deprecated backends ?>
  122. <option value="<?php p($backend->getIdentifier()); ?>"><?php p($backend->getText()); ?></option>
  123. <?php endforeach; ?>
  124. </select>
  125. </td>
  126. <td class="authentication" data-mechanisms='<?php p(json_encode($_['authMechanisms'])); ?>'></td>
  127. <td class="configuration"></td>
  128. <?php if ($_['visibilityType'] === BackendService::VISIBILITY_ADMIN): ?>
  129. <td class="applicable" align="right">
  130. <input type="hidden" class="applicableUsers" style="width:20em;" value="" />
  131. </td>
  132. <?php endif; ?>
  133. <td class="mountOptionsToggle hidden">
  134. <img class="svg action"
  135. title="<?php p($l->t('Advanced settings')); ?>"
  136. alt="<?php p($l->t('Advanced settings')); ?>"
  137. src="<?php print_unescaped(image_path('core', 'actions/settings.svg')); ?>"
  138. />
  139. <input type="hidden" class="mountOptions" value="" />
  140. </td>
  141. <td class="hidden">
  142. <img class="svg action"
  143. alt="<?php p($l->t('Delete')); ?>"
  144. title="<?php p($l->t('Delete')); ?>"
  145. src="<?php print_unescaped(image_path('core', 'actions/delete.svg')); ?>"
  146. />
  147. </td>
  148. </tr>
  149. </tbody>
  150. </table>
  151. <br />
  152. <?php if ($_['visibilityType'] === BackendService::VISIBILITY_ADMIN): ?>
  153. <br />
  154. <input type="checkbox" name="allowUserMounting" id="allowUserMounting" class="checkbox"
  155. value="1" <?php if ($_['allowUserMounting'] == 'yes') print_unescaped(' checked="checked"'); ?> />
  156. <label for="allowUserMounting"><?php p($l->t('Allow users to mount external storage')); ?></label> <span id="userMountingMsg" class="msg"></span>
  157. <p id="userMountingBackends"<?php if ($_['allowUserMounting'] != 'yes'): ?> class="hidden"<?php endif; ?>>
  158. <?php p($l->t('Allow users to mount the following external storage')); ?><br />
  159. <?php
  160. $userBackends = array_filter($_['backends'], function($backend) {
  161. return $backend->isAllowedVisibleFor(BackendService::VISIBILITY_PERSONAL);
  162. });
  163. ?>
  164. <?php $i = 0; foreach ($userBackends as $backend): ?>
  165. <?php if ($deprecateTo = $backend->getDeprecateTo()): ?>
  166. <input type="hidden" id="allowUserMountingBackends<?php p($i); ?>" name="allowUserMountingBackends[]" value="<?php p($backend->getIdentifier()); ?>" data-deprecate-to="<?php p($deprecateTo->getIdentifier()); ?>" />
  167. <?php else: ?>
  168. <input type="checkbox" id="allowUserMountingBackends<?php p($i); ?>" class="checkbox" name="allowUserMountingBackends[]" value="<?php p($backend->getIdentifier()); ?>" <?php if ($backend->isVisibleFor(BackendService::VISIBILITY_PERSONAL)) print_unescaped(' checked="checked"'); ?> />
  169. <label for="allowUserMountingBackends<?php p($i); ?>"><?php p($backend->getText()); ?></label> <br />
  170. <?php endif; ?>
  171. <?php $i++; ?>
  172. <?php endforeach; ?>
  173. </p>
  174. <?php endif; ?>
  175. </form>