PageRenderTime 102ms CodeModel.GetById 60ms app.highlight 3ms RepoModel.GetById 37ms app.codeStats 1ms

/core/ajax/vcategories/add.php

https://github.com/sezuan/core
PHP | 42 lines | 28 code | 8 blank | 6 comment | 4 complexity | 36977f86a6cd16243aa91dc8a7da3e17 MD5 | raw file
 1<?php
 2/**
 3 * Copyright (c) 2012 Thomas Tanghus <thomas@tanghus.net>
 4 * This file is licensed under the Affero General Public License version 3 or
 5 * later.
 6 * See the COPYING-README file.
 7 */
 8function bailOut($msg) {
 9	OC_JSON::error(array('data' => array('message' => $msg)));
10	OC_Log::write('core', 'ajax/vcategories/add.php: '.$msg, OC_Log::DEBUG);
11	exit();
12}
13function debug($msg) {
14	OC_Log::write('core', 'ajax/vcategories/add.php: '.$msg, OC_Log::DEBUG);
15}
16
17OCP\JSON::checkLoggedIn();
18OCP\JSON::callCheck();
19
20$l = OC_L10N::get('core');
21
22$category = isset($_POST['category']) ? strip_tags($_POST['category']) : null;
23$type = isset($_POST['type']) ? $_POST['type'] : null;
24
25if(is_null($type)) {
26	bailOut($l->t('Category type not provided.'));
27}
28
29if(is_null($category)) {
30	bailOut($l->t('No category to add?'));
31}
32
33debug(print_r($category, true));
34
35$categories = new OC_VCategories($type);
36if($categories->hasCategory($category)) {
37	bailOut($l->t('This category already exists: %s', array($category)));
38} else {
39	$categories->add($category, true);
40}
41
42OC_JSON::success(array('data' => array('categories'=>$categories->categories())));