Filters updated and some changes for the sync

- visual changes
- date from/until fields
- published field
- a reset form button

- the org of an event added by a sync user will be that of the host
instance's own organisation identifier
pull/217/head
iglocska 2013-06-05 17:45:01 +02:00
parent 2543916944
commit bc42dbd78c
3 changed files with 110 additions and 55 deletions

View File

@ -30,7 +30,7 @@ class EventsController extends AppController {
'maxLimit' => 9999, // LATER we will bump here on a problem once we have more than 9999 events <- no we won't, this is the max a user van view/page.
'order' => array(
'Event.id' => 'DESC'
)
),
);
public $helpers = array('Js' => array('Jquery'));
@ -77,7 +77,6 @@ class EventsController extends AppController {
)
);
}
}
/**
@ -92,32 +91,37 @@ class EventsController extends AppController {
if($this->request->is("post")) {
$url = array('action'=>'index');
$filters = array();
/*
if(isset($this->data['Event']['searchValue']) && $this->data['Event']['searchValue']){
//maybe clean up user input here??? or urlencode??
$filters['searchValue'] = $this->data['Event']['searchValue'];
}
*/
if (isset($this->data['Event']) && ($this->data['Event']['searchinfo'] || $this->data['Event']['searchorgc'] || $this->data['Event']['searchpublished'])) {
if (isset($this->data['Event'])) {
$filters = $this->data['Event'];
}
//redirect user to the index page including the selected filters
$this->redirect(array_merge($url,$filters));
}
$this->Event->recursive = 0;
if (!empty($this->passedArgs["searchinfo"])) {
$this->paginate['conditions'][] = array('Event.info LIKE' => '%' . $this->passedArgs["searchinfo"] . '%');
// check each of the passed arguments whether they're a filter (could also be a sort for example) and if yes, add it to the pagination conditions
foreach ($this->passedArgs as $k => $v) {
if (substr($k, 0, 6) === 'search') {
$searchTerm = substr($k, 6);
switch ($searchTerm) {
case 'published' :
if ($v == 2) continue 2;
else $this->paginate['conditions'][] = array('Event.' . substr($k, 6) . ' =' => $this->passedArgs["search" . $searchTerm]);
break;
case 'Datefrom' :
if (!$v) continue 2;
$this->paginate['conditions'][] = array('Event.date' . ' >' => $this->passedArgs["search" . $searchTerm]);
break;
case 'Dateuntil' :
if (!$v) continue 2;
$this->paginate['conditions'][] = array('Event.date' . ' <' => $this->passedArgs["search" . $searchTerm]);
break;
default:
$this->paginate['conditions'][] = array('Event.' . substr($k, 6) . ' LIKE' => '%' . $this->passedArgs["search" . $searchTerm] . '%');
break;
}
}
}
if (!empty($this->passedArgs["searchorgc"])) {
$this->paginate['conditions'][] = array('Event.orgc LIKE' => '%' . $this->passedArgs["searchorgc"] . '%');
}
if (!empty($this->passedArgs["searchpublished"])) {
$this->paginate['conditions'][] = array('Event.published LIKE' => '%' . $this->passedArgs["searchpublished"] . '%');
}
//throw new Exception();
$this->set('events', $this->paginate());
if (!$this->Auth->user('gpgkey')) {
$this->Session->setFlash(__('No GPG key set in your profile. To receive emails, submit your public key in your profile.'));
@ -203,6 +207,7 @@ class EventsController extends AppController {
$relatedEvents = $this->Event->getRelatedEvents($this->Auth->user());
$relatedAttributes = $this->Event->getRelatedAttributes($this->Auth->user());
$this->loadModel('Attribute');
if ($this->_isRest()) {
foreach ($this->Event->data['Attribute'] as &$attribute) {
@ -236,7 +241,6 @@ class EventsController extends AppController {
}
$remaining = $this->Event->data['ShadowAttribute'];
}
$this->loadModel('Attribute');
// params for the jQuery RESTfull interface
$this->set('authkey', $this->Auth->user('authkey'));
$this->set('baseurl', Configure::read('CyDefSIG.baseurl'));
@ -411,14 +415,15 @@ class EventsController extends AppController {
// force check userid and orgname to be from yourself
$auth = $this->Auth;
$data['Event']['user_id'] = $auth->user('id');
$data['Event']['org'] = $auth->user('org');
if ($this->checkAction('perm_sync')) $data['Event']['org'] = Configure::read('CyDefSIG.sync');
else $data['Event']['org'] = $auth->user('org');
if (!$fromXml) {
$data['Event']['orgc'] = $data['Event']['org'];
}
if ($fromXml) {
// FIXME FIXME chri: temporary workaround for unclear org, orgc, from
$data['Event']['orgc'] = $data['Event']['org'];
$data['Event']['from'] = $data['Event']['org'];
//$data['Event']['orgc'] = $data['Event']['org'];
//$data['Event']['from'] = $data['Event']['org'];
// Workaround for different structure in XML/array than what CakePHP expects
$this->Event->cleanupEventArrayFromXML($data);
// the event_id field is not set (normal) so make sure no validation errors are thrown

View File

@ -1,30 +1,7 @@
<?php if(empty($this->passedArgs['searchinfo'])) $this->passedArgs['searchinfo'] = '';?>
<?php if(empty($this->passedArgs['searchorgc'])) $this->passedArgs['searchorgc'] = '';?>
<?php if(empty($this->passedArgs['searchpublished'])) $this->passedArgs['searchpublished'] = '';?>
<?php //die(debug($events));?>
<div class="events index">
<?php echo $this->Form->create('', array('action' => 'index')); ?>
<div class="input-append">
<div id = "searchinfo">
<?php
echo $this->Form->input('searchinfo', array('value' => $this->passedArgs['searchinfo'], 'div' => false, 'label' => 'Value', 'class' => 'input'));
echo $this->Form->button('Go', array('class' => 'btn', 'div' => false));
?>
</div><div id = "searchorgc">
<?php
echo $this->Form->input('searchorgc', array('value' => $this->passedArgs['searchorgc'], 'div' => false, 'label' => 'Org'));
echo $this->Form->button('Go', array('class' => 'btn', 'div' => false));
?>
</div><div id = "searchpublished">
<?php
echo $this->Form->input('searchpublished', array('options' => array('0' => 'No', '1' => 'Yes'), 'value' => $this->passedArgs['searchpublished'], 'div' => false, 'label' => 'Published'));
echo $this->Form->button('Go', array('class' => 'btn', 'div' => false));
?>
</div>
</div>
<h2>Events</h2>
<div class="pagination">
<ul>
@ -42,6 +19,37 @@
?>
</ul>
</div>
<?php echo $this->Form->create('', array('action' => 'index', 'style' => 'margin-bottom:0px')); ?>
<div class="input-prepend input-append" style="margin-bottom:0px;">
<div id = "searchcancel" class="add-on span" style="margin-left:0px; margin-top:25px">
<div><a href=# onClick='resetForm()'><div class="icon-remove" style = "margin-top:3px"></div></a></div>
</div>
<div id = "searchinfo" class="span" style="width:220px; margin-left:0px">
<?php
echo $this->Form->input('searchinfo', array('value' => $this->passedArgs['searchinfo'], 'label' => 'Info'));
?>
</div><div id = "searchorgc" class="span" style="margin-left:0px; width:220px">
<?php
echo $this->Form->input('searchorgc', array('value' => $this->passedArgs['searchorgc'], 'label' => 'Org'));
?>
</div><div id = "searchpublished" class="span" style="margin-left:0px; width:220px">
<?php
echo $this->Form->input('searchpublished', array('options' => array('0' => 'No', '1' => 'Yes', '2' => 'Any'), 'default' => 2, 'label' => 'Published'));
?>
</div><div id = "searchfrom" class="span" style="margin-left:0px; width:110px">
<?php
echo $this->Form->input('searchDatefrom', array('value' => $this->passedArgs['searchorgc'], 'label' => 'From', 'style' => 'width:96px; margin-top: 0px;', 'class' => 'datepicker'));
?>
</div><div id = "searchuntil" class="span" style="margin-left:0px; width:110px">
<?php
echo $this->Form->input('searchDateuntil', array('value' => $this->passedArgs['searchorgc'], 'label' => 'Until', 'style' => 'width:96px; margin-top: 0px;', 'class' => 'datepicker'));
?>
</div><div id = "searchbutton" class="span" style="margin-left:0px; margin-top:25px">
<?php
echo $this->Form->button('Go', array('class' => 'btn'));
?>
</div>
</div>
<?php
// Let's output a small label of each filter
$count = 0;
@ -49,9 +57,28 @@
<table><tr>
<?php
foreach ($this->passedArgs as $k => $v) {
if ($v && (substr($k, 0, 6) === 'search')) {
if ((substr($k, 0, 6) === 'search')) {
$searchTerm = substr($k, 6);
if ($searchTerm === 'published') {
switch ($v) {
case '0' :
$value = 'No';
break;
case '1' :
$value = 'Yes';
break;
case '2' :
continue 2;
break;
}
} else {
if (!$v) {
continue;
}
$value = $v;
}
?>
<td class="<?php echo (($count < 1) ? 'searchLabelFirst' : 'searchLabel');?>"><?php echo substr($k, 6); ?> : <?php echo $v; ?></td>
<td class="<?php echo (($count < 1) ? 'searchLabelFirst' : 'searchLabel');?>"><?php echo $searchTerm; ?> : <?php echo $value; ?></td>
<?php
$count++;
}
@ -68,7 +95,7 @@
?>
<table class="table table-striped table-hover table-condensed">
<tr>
<th><?php echo $this->Paginator->sort('published', 'Valid.');?></th>
<th><?php echo $this->Paginator->sort('published', 'Valid.');?><a href=# onClick='enableField("searchpublished")'><br /><div class="icon-search"></div></a></th>
<?php if ('true' == Configure::read('CyDefSIG.showorg') || $isAdmin): ?>
<th><?php echo $this->Paginator->sort('org');?></th>
<?php endif; ?>
@ -80,7 +107,7 @@
<?php if ($isAdmin): ?>
<th><?php echo $this->Paginator->sort('user_id', 'Email');?></th>
<?php endif; ?>
<th><?php echo $this->Paginator->sort('date');?></th>
<th><?php echo $this->Paginator->sort('date');?><a href=# onClick='enableDate()'><br /><div class="icon-search"></div></a></th>
<th title="<?php echo $eventDescriptions['risk']['desc'];?>">
<?php echo $this->Paginator->sort('risk');?>
</th>
@ -203,14 +230,37 @@
</ul>
</div>
<script>
$(document).ready(disableField('searchinfo'));
$(document).ready(disableField('searchorgc'));
$(document).ready(disableField('searchpublished'));
$(document).ready(disableAll());
function resetForm() {
document.getElementById('EventSearchinfo').value=null;
document.getElementById('EventSearchorgc').value=null;
document.getElementById('EventSearchpublished').value=2;
disableAll();
}
function disableAll() {
disableField('searchinfo');
disableField('searchorgc');
disableField('searchfrom');
disableField('searchuntil');
disableField('searchpublished');
disableField('searchbutton');
disableField('searchcancel');
}
function disableField(field) {
document.getElementById(field).style.display="none";
}
function enableField(field) {
document.getElementById(field).style.display="";
document.getElementById('searchbutton').style.display="";
document.getElementById('searchcancel').style.display="";
}
function enableDate() {
enableField('searchfrom');
enableField('searchuntil');
}
</script>

View File

@ -1,5 +1,5 @@
<div class="servers form">
<?php echo $this->Form->create('Server');?>
<?php echo $this->Form->create('Server', array('novalidate'=>true));?>
<fieldset>
<legend>Edit Server</legend>
<?php