Blame view

sources/apps/contacts/lib/controller/backendcontroller.php 1.87 KB
6d9380f96   Cédric Dupont   Update sources OC...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
  <?php
  /**
   * @author Nicolas Mora
   * @copyright 2014 Nicolas Mora (mail@babelouest.org)
   * This file is licensed under the Affero General Public License version 3 or
   * later.
   * See the COPYING-README file.
   */
  
  namespace OCA\Contacts\Controller;
  
  use OCA\Contacts\App,
  	OCA\Contacts\JSONResponse,
  	OCA\Contacts\Utils\JSONSerializer,
  	OCA\Contacts\Controller,
  	OCP\AppFramework\Http;
  
  /**
   * Controller class For Address Books
   */
  class BackendController extends Controller {
  
  	/**
  	 * @NoAdminRequired
  	 * @NoCSRFRequired
  	 */
  	public function getConnectors() {
  		$response = new JSONResponse();
  		$prefix = "backend_ldap_";
  		$suffix = "_connector.xml";
  		$path = __DIR__ . "/../../formats/";
  		$files = scandir($path);
  		$formats = array();
  		foreach ($files as $file) {
  			if (!strncmp($file, $prefix, strlen($prefix)) && substr($file, - strlen($suffix)) === $suffix) {
  				if (file_exists($path.$file)) {
  					$format = simplexml_load_file ( $path.$file );
  					if ($format) {
  						if (isset($format['name'])) {
  							$formatId = substr($file, strlen($prefix), - strlen($suffix));
  							$formats[] = array('id' => $formatId, 'name' => (string)$format['name'], 'xml' => $format->asXML());
  						}
  					}
  				}
  			}
  		}
  		return $response->setData($formats);
  	}
  	
  	/**
  	 * @NoAdminRequired
  	 * @NoCSRFRequired
  	 */
  	public function enableBackend() {
  		$response = new JSONResponse();
  		$params = $this->request->urlParams;
  		$backend = $params['backend'];
  		$enable = $params['enable'];
  		return $response->setData(\OCP\Config::setAppValue('contacts', 'backend_'.$backend, $enable));
  	}
  	/**
  	 * @NoAdminRequired
  	 * @NoCSRFRequired
  	 */
  	public function backendStatus() {
  		$response = new JSONResponse();
  		$params = $this->request->urlParams;
  		$backend = $params['backend'];
  		$enabled = \OCP\Config::getAppValue('contacts', 'backend_'.$backend, "false");
  		return $response->setData($enabled);
  	}
  }