diff --git a/include/class.dept.php b/include/class.dept.php index af0cbe7ee6002331634e67b171b40c86a7c56105..9687f1977a14ae8a9b2c4c7279de619fdc557666 100644 --- a/include/class.dept.php +++ b/include/class.dept.php @@ -489,6 +489,15 @@ implements TemplateVariable, Searchable { $this->flags &= ~$flag; } + function export($dept, $criteria=null, $filename='') { + include_once(INCLUDE_DIR.'class.error.php'); + $members = $dept->getMembers(); + + //Sort based on name formating + $members = Staff::nsort($members); + Export::departmentMembers($dept, $members, $filename); + } + /*----Static functions-------*/ static function getIdByName($name, $pid=null) { $row = static::objects() diff --git a/include/class.export.php b/include/class.export.php index b08291c24980be7790135e67bdadf990872b654f..5e713e5d631474c16242af21a8590fe5eea34a87 100644 --- a/include/class.export.php +++ b/include/class.export.php @@ -239,7 +239,7 @@ class Export { return false; } - static function agents($agents, $filename='', $how='csv') { + static function agents($agents, $filename='', $how='csv') { // Filename or stream to export agents to $filename = $filename ?: sprintf('Agents-%s.csv', @@ -271,6 +271,40 @@ class Export { exit; } + +static function departmentMembers($dept, $agents, $filename='', $how='csv') { + $primaryMembers = array(); + foreach ($dept->getPrimaryMembers() as $agent) { + $primaryMembers[] = $agent->getId(); + } + + // Filename or stream to export depts' agents to + $filename = $filename ?: sprintf('%s-%s.csv', $dept->getName(), + strftime('%Y%m%d')); + Http::download($filename, "text/$how"); + echo self::dumpQuery($agents, array( + '::getName' => 'Name', + '::getUsername' => 'Username', + 2 => 'Access Type', + 3 => 'Access Role', + ), + $how, + array('modify' => function(&$record, $keys, $obj) use ($dept, $primaries, $primaryMembers) { + $role = $obj->getRole($dept); + + if (array_search($obj->getId(), $primaryMembers, true) === false) + $type = 'Extended'; + else { + $type = 'Primary'; + } + + $record[2] = $type; + $record[3] = $role->name; + return $record; + }) + ); + exit; + } } class ResultSetExporter { diff --git a/include/staff/department.inc.php b/include/staff/department.inc.php index 31e72f0256ffeb398929128c65a76e6d81c3754c..b8bd103003aad8ff155e111d051e255c73729c21 100644 --- a/include/staff/department.inc.php +++ b/include/staff/department.inc.php @@ -326,7 +326,17 @@ $info = Format::htmlchars(($errors && $_POST) ? $_POST : $info); <?php echo sprintf(__('Agents who are primary members of %s'), __('this department')); ?> </small></div> </td> - </tr> + <td> + <?php + echo sprintf( + '<a class="no-pjax" href="departments.php?id=%d&a=export"</a>', + $dept->getId()); + ?> + <span class="action-button pull-right" data-placement="bottom" data-toggle="tooltip" title="<?php echo __('Export');?>"> + <i class="icon-download-alt icon-fixed-width"></i> + </span> + </td> + </tr> <?php if (!count($dept->members)) { ?> <tr><td colspan=2><em><?php diff --git a/scp/departments.php b/scp/departments.php index c1d860488f991d92291f73c0102bf16e0647964a..6e0742199b98550f4c94c9969f526559a437f757 100644 --- a/scp/departments.php +++ b/scp/departments.php @@ -130,7 +130,10 @@ if($_POST){ $page='departments.inc.php'; $tip_namespace = 'staff.department'; -if($dept || ($_REQUEST['a'] && !strcasecmp($_REQUEST['a'],'add'))) { +if ($_REQUEST['a'] && $_REQUEST['a'] == 'export') { + if (!Dept::export($dept)) + $errors['err'] = sprintf(__('Unable to export %s.'), __('Department')); +} elseif ($dept || ($_REQUEST['a'] && !strcasecmp($_REQUEST['a'],'add'))) { $page='department.inc.php'; }