Skip to content

Commit

Permalink
Filter by user login date
Browse files Browse the repository at this point in the history
  • Loading branch information
remdex committed Oct 5, 2021
1 parent a57736f commit adc32b1
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 2 deletions.
39 changes: 39 additions & 0 deletions lhc_web/design/defaulttheme/tpl/lhstatistic/userstats.tpl.php
Expand Up @@ -12,10 +12,12 @@
<a href="<?php echo erLhcoreClassDesign::baseurl('user/edit')?>/<?php echo $user->id?>" class="pr-2"><span class="material-icons">edit</span> <?php echo htmlspecialchars($user->name_official)?> [<?php echo $user->id?>]</a>
<a href="<?php echo erLhcoreClassDesign::baseurl('chat/list')?>/(user_ids)/<?php echo $user->id?>/(chat_status_ids)/0/1" class="pr-2"><span title="<?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('statistic/departmentstats','Operator active/pending chats');?>" class="material-icons">chat</span><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('statistic/departmentstats','Operator active/pending chats');?></a>
<a href="<?php echo erLhcoreClassDesign::baseurl('statistic/onlinehours')?>/(user_id)/<?php echo $user->id?>" class="pr-2"><span title="<?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('statistic/departmentstats','Online hours');?>" class="material-icons">schedule</span><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('statistic/departmentstats','Operator online hours');?></a>
<a href="<?php echo erLhcoreClassDesign::baseurl('audit/loginhistory')?>/(user_id)/<?php echo $user->id?>" class="pr-2"><span title="<?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('statistic/departmentstats','Login history');?>" class="material-icons">schedule</span><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('statistic/departmentstats','Login history');?></a>
</div>
<ul class="nav nav-pills mb-3" role="tablist">
<li role="presentation" class="nav-item"><a href="#user-status" class="nav-link active" aria-controls="user-status" role="tab" data-toggle="tab"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('statistic/departmentstats','User stats');?></a></li>
<li role="presentation" class="nav-item"><a href="#online-hours" class="nav-link" aria-controls="online-hours" role="tab" data-toggle="tab"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('statistic/departmentstats','Online hours');?></a></li>
<li role="presentation" class="nav-item"><a href="#login-history" class="nav-link" aria-controls="login-history" role="tab" data-toggle="tab"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('statistic/departmentstats','Login history');?></a></li>
</ul>
<div class="tab-content">
<div role="tabpanel" class="tab-pane" id="online-hours" style="max-height: 550px;overflow-y: auto">
Expand Down Expand Up @@ -116,6 +118,43 @@
<?php endforeach; ?>
</table>
</div>
<div role="tabpanel" class="tab-pane" id="login-history" style="max-height: 550px;overflow-y: auto">

<table class="table table-sm" ng-non-bindable cellpadding="0" cellspacing="0" width="100%">
<thead>
<tr>
<th width="1%"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('user/userlist','ID');?></th>
<th width="1%" nowrap=""><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('user/userlist','User ID');?></th>
<th><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('user/userlist','Message');?></th>
<th width="1%"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('user/userlist','IP');?></th>
<th width="1%"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('user/userlist','Date');?></th>
</tr>
</thead>
<?php foreach (erLhcoreClassModelUserLogin::getList(array('filter' => ['user_id' => $user->id],'offset' => 0, 'limit' => 20,'sort' => 'id DESC')) as $item) : ?>
<tr>
<td>
<?php echo $item->id?>
</td>
<td>
<?php echo $item->user_id?>
</td>
<td title="<?php echo $item->type?>">
<?php if ($item->status == erLhcoreClassModelUserLogin::STATUS_COMPLETED) : ?>
<span class="material-icons text-success">done</span>
<?php endif; ?>
<?php echo htmlspecialchars($item->msg)?>
</td>
<td>
<?php echo $item->ip?>
</td>
<td nowrap>
<?php echo $item->ctime_front?>
</td>
</tr>
<?php endforeach; ?>
</table>

</div>
</div>
</div>
</div>
Expand Down
10 changes: 9 additions & 1 deletion lhc_web/design/defaulttheme/tpl/lhuser/userlist.tpl.php
Expand Up @@ -24,7 +24,15 @@
<?php foreach ($userlist as $user) : ?>
<tr>
<td><?php echo $user->id?></td>
<td><?php echo htmlspecialchars($user->username)?><?php echo htmlspecialchars($user->chat_nickname !== '' ? ' ('. $user->chat_nickname .')' : '')?></td>
<td>
<?php if ($currentUser->hasAccessTo('lhstatistic','userstats')) : ?>
<a href="#" title="<?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/syncadmininterface','See operator statistic')?>" onclick="lhc.revealModal({'url':WWW_DIR_JAVASCRIPT+'statistic/userstats/<?php echo htmlspecialchars($user->id)?>'})">
<span class="material-icons">bar_chart</span>
</a>
<?php endif; ?>

<?php echo htmlspecialchars($user->username)?><?php echo htmlspecialchars($user->chat_nickname !== '' ? ' ('. $user->chat_nickname .')' : '')?>
</td>
<td><?php echo htmlspecialchars($user->email)?></td>
<td>
<?php if ($user->exclude_autoasign == 1) : ?>
Expand Down
Expand Up @@ -58,6 +58,80 @@
</select>
</div>
</div>
<div class="col-12">
<div class="row">
<div class="col-md-2">
<div class="form-group">
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Login date range from');?></label>
<div class="row">
<div class="col-md-12">
<input type="text" autocomplete="off" class="form-control form-control-sm" name="timefrom" id="id_timefrom" placeholder="E.g <?php echo date('Y-m-d',time()-7*24*3600)?>" value="<?php echo htmlspecialchars($input->timefrom)?>" />
</div>
</div>
</div>
</div>

<div class="col-md-2">
<div class="form-group">
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Hour and minute from');?></label>
<div class="row">
<div class="col-md-6">
<select name="timefrom_hours" class="form-control form-control-sm">
<option value="">Select hour</option>
<?php for ($i = 0; $i <= 23; $i++) : ?>
<option value="<?php echo $i?>" <?php if (isset($input->timefrom_hours) && $input->timefrom_hours === $i) : ?>selected="selected"<?php endif;?>><?php echo str_pad($i,2, '0', STR_PAD_LEFT);?> h.</option>
<?php endfor;?>
</select>
</div>
<div class="col-md-6">
<select name="timefrom_minutes" class="form-control form-control-sm">
<option value="">Select minute</option>
<?php for ($i = 0; $i <= 59; $i++) : ?>
<option value="<?php echo $i?>" <?php if (isset($input->timefrom_minutes) && $input->timefrom_minutes === $i) : ?>selected="selected"<?php endif;?>><?php echo str_pad($i,2, '0', STR_PAD_LEFT);?> m.</option>
<?php endfor;?>
</select>
</div>
</div>
</div>
</div>

<div class="col-md-2">
<div class="form-group">
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Login date range to');?></label>
<div class="row">
<div class="col-md-12">
<input type="text" autocomplete="off" class="form-control form-control-sm" name="timeto" id="id_timeto" placeholder="E.g <?php echo date('Y-m-d')?>" value="<?php echo htmlspecialchars($input->timeto)?>" />
</div>
</div>
</div>
</div>

<div class="col-md-2">
<div class="form-group">
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Hour and minute to');?></label>
<div class="row">
<div class="col-md-6">
<select name="timeto_hours" class="form-control form-control-sm">
<option value="">Select hour</option>
<?php for ($i = 0; $i <= 23; $i++) : ?>
<option value="<?php echo $i?>" <?php if (isset($input->timeto_hours) && $input->timeto_hours === $i) : ?>selected="selected"<?php endif;?>><?php echo str_pad($i,2, '0', STR_PAD_LEFT);?> h.</option>
<?php endfor;?>
</select>
</div>
<div class="col-md-6">
<select name="timeto_minutes" class="form-control form-control-sm">
<option value="">Select minute</option>
<?php for ($i = 0; $i <= 59; $i++) : ?>
<option value="<?php echo $i?>" <?php if (isset($input->timeto_minutes) && $input->timeto_minutes === $i) : ?>selected="selected"<?php endif;?>><?php echo str_pad($i,2, '0', STR_PAD_LEFT);?> m.</option>
<?php endfor;?>
</select>
</div>
</div>
</div>
</div>
</div>
</div>


</div>

Expand All @@ -72,5 +146,8 @@
<script>
$(function() {
$('.btn-block-department').makeDropdown();
$('#id_timefrom,#id_timeto').fdatepicker({
format: 'yyyy-mm-dd'
});
});
</script>
Expand Up @@ -573,6 +573,13 @@ public function leftJoin()
return call_user_func_array( array( $this, 'doJoin' ), $args );
}

public function leftOuterJoin()
{
$args = func_get_args();
array_unshift( $args, 'left outer' );
return call_user_func_array( array( $this, 'doJoin' ), $args );
}

/**
* Returns the SQL for a right join or prepares $fromString for a right join.
*
Expand Down
4 changes: 4 additions & 0 deletions lhc_web/lib/core/lhchat/lhchatexport.php
Expand Up @@ -69,6 +69,10 @@ public static function exportUsers($users) {
$values['dep_groups_id'] = implode(',',$depGroupIds);
$values['dep_groups_name'] = implode(',',$depGroupNames);

$lastLogin = erLhcoreClassModelUserLogin::findOne(array('sort' => 'ctime DESC','filter' => array('user_id' => $user->id)));

$values['last_login'] = $lastLogin instanceof erLhcoreClassModelUserLogin ? date(erLhcoreClassModule::$dateDateHourFormat,$lastLogin->ctime) : '';

if ($counter == 0) {
fputcsv($fp, array_keys($values));
}
Expand Down
6 changes: 6 additions & 0 deletions lhc_web/lib/core/lhcore/lhdbtrait.php
Expand Up @@ -502,6 +502,12 @@ public static function getConditions($params, $q)
}
}

if (isset($params['leftouterjoin']) && count($params['leftouterjoin']) > 0) {
foreach ($params['leftouterjoin'] as $table => $joinOn) {
$q->leftOuterJoin($table, $joinOn);
}
}

if (isset($params['group']) && $params['group'] != '') {
$q->groupBy($params['group']);
}
Expand Down
27 changes: 27 additions & 0 deletions lhc_web/lib/core/lhuser/searchattr/user_list.php
Expand Up @@ -86,6 +86,33 @@
)
);

$fieldsSearch['timefrom'] = array (
'type' => 'text',
'trans' => 'Timefrom',
'required' => false,
'valid_if_filled' => false,
'datatype' => 'datetime',
'filter_type' => 'filtergte',
'filter_table_field' => '`p1`.`ctime`',
'validation_definition' => new ezcInputFormDefinitionElement (
ezcInputFormDefinitionElement::OPTIONAL, 'string'
)
);

$fieldsSearch['timeto'] = array (
'type' => 'text',
'trans' => 'Timeto',
'required' => false,
'valid_if_filled' => false,
'datatype' => 'datetime',
'filter_type' => 'filterlte',
'filter_table_field' => '`p1`.`ctime`',
'validation_definition' => new ezcInputFormDefinitionElement (
ezcInputFormDefinitionElement::OPTIONAL, 'string'
)
);


$fieldSortAttr = array (
'field' => false,
'default' => false,
Expand Down
2 changes: 1 addition & 1 deletion lhc_web/modules/lhuser/module.php
Expand Up @@ -48,7 +48,7 @@

$ViewList['userlist'] = array(
'params' => array(),
'uparams' => array('email' , 'name' , 'username' , 'surname', 'group_ids', 'disabled', 'export'),
'uparams' => array('email' , 'name' , 'username' , 'surname', 'group_ids', 'disabled', 'export','timefrom','timeto','timefrom_minutes','timefrom_hours','timeto_hours','timeto_minutes'),
'functions' => array( 'userlist' ),
'multiple_arguments' => array('group_ids')
);
Expand Down
5 changes: 5 additions & 0 deletions lhc_web/modules/lhuser/userlist.php
Expand Up @@ -14,6 +14,11 @@

erLhcoreClassChatStatistic::formatUserFilter($filterParams, 'lh_users', 'id');

if (isset($filterParams['filter']['filtergte']['`p1`.`ctime`']) || isset($filterParams['filter']['filterlte']['`p1`.`ctime`'])) {
$filterParams['filter']['innerjoin'] = array('lh_users_login as p1' => array('`p1`.`user_id`', '`lh_users`.`id`'));
$filterParams['filter']['leftouterjoin'] = array('lh_users_login as p2' => '(`p2`.`user_id` = `lh_users`.`id` AND p1.id < p2.id)');
$filterParams['filter']['customfilter'][] = 'p2.id IS NULL';
}

if ($Params['user_parameters_unordered']['export'] == 1) {
erLhcoreClassChatExport::exportUsers(erLhcoreClassModelUser::getUserList(array_merge($filterParams['filter'],array('limit' => false,'sort' => 'id DESC'))));
Expand Down

0 comments on commit adc32b1

Please sign in to comment.