Skip to content
Snippets Groups Projects
Commit 564b0540 authored by Peter Rotich's avatar Peter Rotich
Browse files

Agents Access Export

Add ability to export agents access in CSV format
parent ca442132
No related branches found
No related tags found
No related merge requests found
......@@ -258,6 +258,38 @@ class Export {
return false;
}
static function agents($agents, $filename='', $how='csv') {
// Filename or stream to export agents to
$filename = $filename ?: sprintf('Agents-%s.csv',
strftime('%Y%m%d'));
Http::download($filename, "text/$how");
$depts = Dept::getDepartments();
echo self::dumpQuery($agents, array(
'::getName' => 'Name',
'::getUsername' => 'Username',
'::getStatus' => 'Status',
'permissions' => 'Permissions',
'::getDept' => 'Primary Department',
) + $depts,
$how,
array('modify' => function(&$record, $keys, $obj) use ($depts) {
if (($i = array_search('permissions', $keys)))
$record[$i] = implode(",", array_keys($obj->getPermission()->getInfo()));
$roles = $obj->getRoles();
foreach ($depts as $k => $v) {
if (is_numeric($k) && ($i = array_search($k, $keys)) !== false) {
$record[$i] = $roles[$k] ?: '';
}
}
return $record;
})
);
exit;
}
}
class ResultSetExporter {
......
......@@ -432,23 +432,27 @@ implements AuthenticatedUser, EmailContact, TemplateVariable {
return isset($this->locale) ? $this->locale : 0;
}
function getRoles() {
if (!isset($this->_roles)) {
$this->_roles = array($this->dept_id => $this->role);
foreach($this->dept_access as $da)
$this->_roles[$da->dept_id] = $da->role;
}
return $this->_roles;
}
function getRole($dept=null) {
$deptId = is_object($dept) ? $dept->getId() : $dept;
if ($deptId && $deptId != $this->dept_id) {
if (isset($this->_roles[$deptId]))
return $this->_roles[$deptId];
if ($access = $this->dept_access->findFirst(array('dept_id' => $deptId)))
return $this->_roles[$deptId] = $access->role;
$roles = $this->getRoles();
if (isset($roles[$deptId]))
return $roles[$deptId];
if (!$this->usePrimaryRoleOnAssignment())
// View only access
return new Role(array());
if ($this->usePrimaryRoleOnAssignment())
return $this->role;
// Fall through to primary role
}
// For the primary department, use the primary role
return $this->role;
// View only access
return new Role(array());
}
function hasPerm($perm, $global=true) {
......@@ -477,10 +481,14 @@ implements AuthenticatedUser, EmailContact, TemplateVariable {
return TRUE;
}
function isactive() {
function isActive() {
return $this->isactive;
}
function getStatus() {
return $this->isActive() ? __('Active') : __('Locked');
}
function isVisible() {
return $this->isvisible;
}
......@@ -490,7 +498,7 @@ implements AuthenticatedUser, EmailContact, TemplateVariable {
}
function isAvailable() {
return ($this->isactive() && !$this->onVacation());
return ($this->isActive() && !$this->onVacation());
}
function showAssignedOnly() {
......@@ -1137,6 +1145,15 @@ implements AuthenticatedUser, EmailContact, TemplateVariable {
return true;
}
static function export($criteria=null, $filename='') {
include_once(INCLUDE_DIR.'class.error.php');
$agents = Staff::objects();
// Sort based on name formating
$agents = self::nsort($agents);
Export::agents($agents, $filename);
}
}
interface RestrictedAccess {
......
......@@ -143,6 +143,12 @@ $agents->limit($pageNav->getLimit())->offset($pageNav->getStart());
<?php echo __( 'Change Department'); ?>
</a>
</li>
<li>
<a class="no-pjax" href="staff.php?a=export">
<i class="icon-download-alt icon-fixed-width"></i>
<?php echo __( 'Export Agents'); ?>
</a>
</li>
<!-- TODO: Implement "Reset Access" mass action
<li><a class="dialog-first" href="#staff/reset-access">
<i class="icon-puzzle-piece icon-fixed-width"></i>
......
......@@ -171,8 +171,11 @@ if($_POST){
$page='staffmembers.inc.php';
$tip_namespace = 'staff.agent';
if($staff || ($_REQUEST['a'] && !strcasecmp($_REQUEST['a'],'add'))) {
if ($staff || ($_REQUEST['a'] && !strcasecmp($_REQUEST['a'],'add'))) {
$page='staff.inc.php';
} elseif ($_REQUEST['a'] && !strcasecmp($_REQUEST['a'],'export')) {
if (!Staff::export())
$errors['err'] = sprintf(__('Unable to export %s.'), __('Agents'));
}
$nav->setTabActive('staff');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment