Newer
Older
<?php
require_once(INCLUDE_DIR . 'class.dept.php');
class AdminAjaxAPI extends AjaxController {
/**
* Ajax: GET /admin/add/department
*
* Uses a dialog to add a new department
*
* Returns:
* 200 - HTML form for addition
* 201 - {id: <id>, name: <name>}
*
* Throws:
* 403 - Not logged in
*/
function addDepartment() {
global $ost, $thisstaff;
if (!$thisstaff)
Http::response(403, 'Agent login required');
$form = new DepartmentQuickAddForm($_POST);
if ($_POST && $form->isValid()) {
$dept = Dept::create();
$errors = array();
$vars = $form->getClean();
$vars += array(
'group_membership' => Dept::ALERTS_DEPT_AND_GROUPS,
);
Http::response(201, $this->encode(array(
'id' => $dept->id,
'name' => $dept->name,
), 'application/json'));
foreach ($errors as $name=>$desc)
if ($F = $form->getField($name))
$F->addError($desc);
}
$title = __("Add New Department");
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
include STAFFINC_DIR . 'templates/quick-add.tmpl.php';
}
/**
* Ajax: GET /admin/add/team
*
* Uses a dialog to add a new team
*
* Returns:
* 200 - HTML form for addition
* 201 - {id: <id>, name: <name>}
*
* Throws:
* 403 - Not logged in
*/
function addTeam() {
global $ost, $thisstaff;
if (!$thisstaff)
Http::response(403, 'Agent login required');
$form = new TeamQuickAddForm($_POST);
if ($_POST && $form->isValid()) {
$team = Team::create();
$errors = array();
$vars = $form->getClean();
$vars += array(
'isenabled' => true,
);
if ($team->update($vars, $errors)) {
Http::response(201, $this->encode(array(
'id' => $team->getId(),
'name' => $team->name,
), 'application/json'));
}
foreach ($errors as $name=>$desc)
if ($F = $form->getField($name))
$F->addError($desc);
}
$title = __("Add New Team");
include STAFFINC_DIR . 'templates/quick-add.tmpl.php';