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');
if (!$thisstaff->isAdmin())
Http::response(403, 'Access denied');
$form = new DepartmentQuickAddForm($_POST);
if ($_POST && $form->isValid()) {
$dept = Dept::create();
$errors = array();
$vars = $form->getClean();
$vars += array(
'group_membership' => Dept::ALERTS_DEPT_AND_EXTENDED,
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");
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');
if (!$thisstaff->isAdmin())
Http::response(403, 'Access denied');
$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';
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/**
* Ajax: GET /admin/add/role
*
* Uses a dialog to add a new role
*
* Returns:
* 200 - HTML form for addition
* 201 - {id: <id>, name: <name>}
*
* Throws:
* 403 - Not logged in
* 403 - Not an adminitrator
*/
function addRole() {
global $ost, $thisstaff;
if (!$thisstaff)
Http::response(403, 'Agent login required');
if (!$thisstaff->isAdmin())
Http::response(403, 'Access denied');
$form = new RoleQuickAddForm($_POST);
if ($_POST && $form->isValid()) {
$role = Role::create();
$errors = array();
$vars = $form->getClean();
if ($role->update($vars, $errors)) {
Http::response(201, $this->encode(array(
'id' => $role->getId(),
'name' => $role->name,
), 'application/json'));
}
foreach ($errors as $name=>$desc)
if ($F = $form->getField($name))
$F->addError($desc);
}
$title = __("Add New Role");
$path = ltrim($ost->get_path_info(), '/');
include STAFFINC_DIR . 'templates/quick-add-role.tmpl.php';
}
function getRolePerms($id) {
global $ost, $thisstaff;
if (!$thisstaff)
Http::response(403, 'Agent login required');
if (!$thisstaff->isAdmin())
Http::response(403, 'Access denied');
if (!($role = Role::lookup($id)))
Http::response(404, 'No such role');
return $this->encode($role->getPermissionInfo());
}
function addStaff() {
global $ost, $thisstaff;
if (!$thisstaff)
Http::response(403, 'Agent login required');
if (!$thisstaff->isAdmin())
Http::response(403, 'Access denied');
$form = new StaffQuickAddForm($_POST);
if ($_POST && $form->isValid()) {
$staff = Staff::create();
$errors = array();
if ($staff->update($form->getClean(), $errors)) {
Http::response(201, $this->encode(array(
'id' => $staff->getId(),
'name' => (string) $staff->getName(),
), 'application/json'));
}
foreach ($errors as $name=>$desc) {
if ($F = $form->getField($name)) {
unset($errors[$name]);
}
}
$errors['err'] = implode(", ", $errors);
}
$title = __("Add New Agent");
$path = ltrim($ost->get_path_info(), '/');
include STAFFINC_DIR . 'templates/quick-add.tmpl.php';
}