mirror of https://github.com/MISP/MISP
new: Added attribute level galaxy clusters
parent
c59174e4be
commit
962461890c
|
@ -1074,6 +1074,24 @@ class EventsController extends AppController {
|
|||
unset($event['EventTag'][$k]);
|
||||
}
|
||||
}
|
||||
foreach ($event['Attribute'] as $k => $attribute) {
|
||||
foreach ($attribute['AttributeTag'] as $k2 => $attributeTag) {
|
||||
if (in_array($attributeTag['Tag']['name'], $cluster_names)) {
|
||||
unset($event['Attribute'][$k]['AttributeTag'][$k2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($event['Object'] as $k => $object) {
|
||||
if (!empty($object['Attribute'])) {
|
||||
foreach ($object['Attribute'] as $k2 => $attribute) {
|
||||
foreach ($attribute['AttributeTag'] as $k3 => $attributeTag) {
|
||||
if (in_array($attributeTag['Tag']['name'], $cluster_names)) {
|
||||
unset($event['Object'][$k]['Attribute'][$k2]['AttributeTag'][$k3]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$params = $this->Event->rearrangeEventForView($event);
|
||||
$this->params->params['paging'] = array($this->modelClass => $params);
|
||||
$this->set('event', $event);
|
||||
|
|
|
@ -64,14 +64,15 @@ class GalaxiesController extends AppController {
|
|||
}
|
||||
}
|
||||
|
||||
public function selectGalaxy($event_id) {
|
||||
public function selectGalaxy($target_id, $target_type='event') {
|
||||
$galaxies = $this->Galaxy->find('all', array('recursive' => -1));
|
||||
$this->set('galaxies', $galaxies);
|
||||
$this->set('event_id', $event_id);
|
||||
$this->set('target_id', $target_id);
|
||||
$this->set('target_type', $target_type);
|
||||
$this->render('ajax/galaxy_choice');
|
||||
}
|
||||
|
||||
public function selectCluster($event_id, $selectGalaxy = false) {
|
||||
public function selectCluster($target_id, $target_type = 'event', $selectGalaxy = false) {
|
||||
$conditions = array();
|
||||
if ($selectGalaxy) {
|
||||
$conditions = array('GalaxyCluster.galaxy_id' => $selectGalaxy);
|
||||
|
@ -105,53 +106,17 @@ class GalaxiesController extends AppController {
|
|||
}
|
||||
ksort($clusters);
|
||||
$this->set('clusters', $clusters);
|
||||
$this->set('event_id', $event_id);
|
||||
$this->set('target_id', $target_id);
|
||||
$this->set('target_type', $target_type);
|
||||
$this->set('lookup_table', $lookup_table);
|
||||
$this->render('ajax/cluster_choice');
|
||||
}
|
||||
|
||||
public function attachClusterToEvent($event_id) {
|
||||
public function attachCluster($target_id, $target_type = 'event') {
|
||||
$cluster_id = $this->request->data['Galaxy']['target_id'];
|
||||
$cluster = $this->Galaxy->GalaxyCluster->find('first', array('recursive' => -1, 'conditions' => array('id' => $cluster_id), 'fields' => array('tag_name', 'id', 'value')));
|
||||
$this->loadModel('Tag');
|
||||
$event = $this->Tag->EventTag->Event->fetchEvent($this->Auth->user(), array('eventid' => $event_id, 'metadata' => 1));
|
||||
if (empty($event)) {
|
||||
throw new NotFoundException('Invalid event.');
|
||||
}
|
||||
$event = $event[0];
|
||||
$tag_id = $this->Tag->captureTag(array('name' => $cluster['GalaxyCluster']['tag_name'], 'colour' => '#0088cc', 'exportable' => 1), $this->Auth->user());
|
||||
if ($tag_id === false) {
|
||||
throw new MethodNotAllowedException('Could not attach cluster.');
|
||||
}
|
||||
$this->Tag->EventTag->create();
|
||||
$existingTag = $this->Tag->EventTag->find('first', array('conditions' => array('event_id' => $event_id, 'tag_id' => $tag_id)));
|
||||
if (!empty($existingTag)) {
|
||||
$this->Session->setFlash('Cluster already attached.');
|
||||
$this->redirect($this->referer());
|
||||
}
|
||||
$result = $this->Tag->EventTag->save(array('event_id' => $event_id, 'tag_id' => $tag_id));
|
||||
if ($result) {
|
||||
$event['Event']['published'] = 0;
|
||||
$date = new DateTime();
|
||||
$event['Event']['timestamp'] = $date->getTimestamp();
|
||||
$this->Tag->EventTag->Event->save($event);
|
||||
$this->Log = ClassRegistry::init('Log');
|
||||
$this->Log->create();
|
||||
$this->Log->save(array(
|
||||
'org' => $this->Auth->user('Organisation')['name'],
|
||||
'model' => 'Event',
|
||||
'model_id' => $event_id,
|
||||
'email' => $this->Auth->user('email'),
|
||||
'action' => 'galaxy',
|
||||
'title' => 'Attached ' . $cluster['GalaxyCluster']['value'] . ' (' . $cluster['GalaxyCluster']['id'] . ') to event (' . $event_id . ')',
|
||||
'change' => ''
|
||||
));
|
||||
$this->Session->setFlash('Cluster attached');
|
||||
$this->redirect($this->referer());
|
||||
} else {
|
||||
$this->Session->setFlash('Cluster could not be attached');
|
||||
$this->redirect($this->referer());
|
||||
}
|
||||
$result = $this->Galaxy->attachCluster($this->Auth->user(), $target_type, $target_id, $cluster_id);
|
||||
$this->Session->setFlash($result);
|
||||
$this->redirect($this->referer());
|
||||
}
|
||||
|
||||
public function viewGraph($id) {
|
||||
|
|
|
@ -187,8 +187,23 @@ class GalaxyClustersController extends AppController {
|
|||
$this->redirect($this->referer());
|
||||
}
|
||||
|
||||
public function detachFromEvent($event_id, $tag_id) {
|
||||
public function detach($target_id, $target_type, $tag_id) {
|
||||
$this->loadModel('Event');
|
||||
if ($target_type == 'attribute') {
|
||||
$attribute = $this->Event->Attribute->find('first', array(
|
||||
'recursive' => -1,
|
||||
'fields' => array('id', 'event_id'),
|
||||
'conditions' => array('Attribute.id' => $target_id)
|
||||
));
|
||||
if (empty($attribute)) {
|
||||
throw new MethodNotAllowedException('Invalid Attribute.');
|
||||
}
|
||||
$event_id = $attribute['Attribute']['event_id'];
|
||||
} else if ($target_type == 'event'){
|
||||
$event_id = $target_id;
|
||||
} else {
|
||||
throw new MethodNotAllowedException('Invalid options');
|
||||
}
|
||||
$this->Event->id = $event_id;
|
||||
$this->Event->recursive = -1;
|
||||
$event = $this->Event->read(array(), $event_id);
|
||||
|
@ -200,19 +215,32 @@ class GalaxyClustersController extends AppController {
|
|||
throw new MethodNotAllowedException('Invalid Event.');
|
||||
}
|
||||
}
|
||||
$existingEventTag = $this->Event->EventTag->find('first', array(
|
||||
'conditions' => array('EventTag.tag_id' => $tag_id, 'EventTag.event_id' => $event_id),
|
||||
'recursive' => -1,
|
||||
'contain' => array('Tag')
|
||||
));
|
||||
if (empty($existingEventTag)) {
|
||||
if ($target_type == 'attribute') {
|
||||
$existingTargetTag = $this->Event->Attribute->AttributeTag->find('first', array(
|
||||
'conditions' => array('AttributeTag.tag_id' => $tag_id, 'AttributeTag.attribute_id' => $target_id),
|
||||
'recursive' => -1,
|
||||
'contain' => array('Tag')
|
||||
));
|
||||
} else if ($target_type == 'event') {
|
||||
$existingTargetTag = $this->Event->EventTag->find('first', array(
|
||||
'conditions' => array('EventTag.tag_id' => $tag_id, 'EventTag.event_id' => $target_id),
|
||||
'recursive' => -1,
|
||||
'contain' => array('Tag')
|
||||
));
|
||||
}
|
||||
|
||||
if (empty($existingTargetTag)) {
|
||||
$this->Session->setFlash('Galaxy not attached.');
|
||||
} else {
|
||||
$cluster = $this->GalaxyCluster->find('first', array(
|
||||
'recursive' => -1,
|
||||
'conditions' => array('GalaxyCluster.tag_name' => $existingEventTag['Tag']['name'])
|
||||
'conditions' => array('GalaxyCluster.tag_name' => $existingTargetTag['Tag']['name'])
|
||||
));
|
||||
$result = $this->Event->EventTag->delete($existingEventTag['EventTag']['id']);
|
||||
if ($target_type == 'event') {
|
||||
$result = $this->Event->EventTag->delete($existingTargetTag['EventTag']['id']);
|
||||
} else if ($target_type == 'attribute') {
|
||||
$result = $this->Event->Attribute->AttributeTag->delete($existingTargetTag['AttributeTag']['id']);
|
||||
}
|
||||
if ($result) {
|
||||
$event['Event']['published'] = 0;
|
||||
$date = new DateTime();
|
||||
|
@ -223,11 +251,11 @@ class GalaxyClustersController extends AppController {
|
|||
$this->Log->create();
|
||||
$this->Log->save(array(
|
||||
'org' => $this->Auth->user('Organisation')['name'],
|
||||
'model' => 'Event',
|
||||
'model_id' => $event_id,
|
||||
'model' => ucfirst($target_type),
|
||||
'model_id' => $target_id,
|
||||
'email' => $this->Auth->user('email'),
|
||||
'action' => 'galaxy',
|
||||
'title' => 'Detached ' . $cluster['GalaxyCluster']['value'] . ' (' . $cluster['GalaxyCluster']['id'] . ') from event (' . $event_id . ')',
|
||||
'title' => 'Detached ' . $cluster['GalaxyCluster']['value'] . ' (' . $cluster['GalaxyCluster']['id'] . ') from ' . $target_type . ' (' . $target_id . ')',
|
||||
'change' => ''
|
||||
));
|
||||
} else {
|
||||
|
|
|
@ -1670,40 +1670,8 @@ class Event extends AppModel {
|
|||
}
|
||||
$event['Event']['event_creator_email'] = $userEmails[$event['Event']['user_id']];
|
||||
}
|
||||
$event['Galaxy'] = array();
|
||||
// unset empty event tags that got added because the tag wasn't exportable
|
||||
if (!empty($event['EventTag'])) {
|
||||
foreach ($event['EventTag'] as $k => &$eventTag) {
|
||||
if (empty($eventTag['Tag'])) {
|
||||
unset($event['EventTag'][$k]);
|
||||
continue;
|
||||
}
|
||||
if (!isset($options['excludeGalaxy']) || !$options['excludeGalaxy']) {
|
||||
if (substr($eventTag['Tag']['name'], 0, strlen('misp-galaxy:')) === 'misp-galaxy:') {
|
||||
$cluster = $this->GalaxyCluster->getCluster($eventTag['Tag']['name']);
|
||||
if ($cluster) {
|
||||
$found = false;
|
||||
foreach ($event['Galaxy'] as $k => $galaxy) {
|
||||
if ($galaxy['id'] == $cluster['GalaxyCluster']['Galaxy']['id']) {
|
||||
$found = true;
|
||||
$temp = $cluster;
|
||||
unset($temp['GalaxyCluster']['Galaxy']);
|
||||
$event['Galaxy'][$k]['GalaxyCluster'][] = $temp['GalaxyCluster'];
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (!$found) {
|
||||
$event['Galaxy'][] = $cluster['GalaxyCluster']['Galaxy'];
|
||||
$temp = $cluster;
|
||||
unset($temp['GalaxyCluster']['Galaxy']);
|
||||
$event['Galaxy'][count($event['Galaxy']) - 1]['GalaxyCluster'][] = $temp['GalaxyCluster'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$event['EventTag'] = array_values($event['EventTag']);
|
||||
}
|
||||
$event = $this->massageTags($event, 'Event');
|
||||
|
||||
// Let's find all the related events and attach it to the event itself
|
||||
$results[$eventKey]['RelatedEvent'] = $this->getRelatedEvents($user, $event['Event']['id'], $sgids);
|
||||
// Let's also find all the relations for the attributes - this won't be in the xml export though
|
||||
|
@ -1735,6 +1703,7 @@ class Event extends AppModel {
|
|||
unset($event['Attribute'][$key]);
|
||||
continue;
|
||||
}
|
||||
$event['Attribute'][$key] = $this->massageTags($attribute, 'Attribute');
|
||||
if ($event['Attribute'][$key]['category'] === 'Financial fraud') {
|
||||
$event['Attribute'][$key] = $this->Attribute->attachValidationWarnings($event['Attribute'][$key]);
|
||||
}
|
||||
|
@ -4266,4 +4235,42 @@ class Event extends AppModel {
|
|||
}
|
||||
return $attributes_added;
|
||||
}
|
||||
|
||||
public function massageTags($data, $dataType = 'Event') {
|
||||
$data['Galaxy'] = array();
|
||||
// unset empty event tags that got added because the tag wasn't exportable
|
||||
if (!empty($data[$dataType . 'Tag'])) {
|
||||
foreach ($data[$dataType . 'Tag'] as $k => &$dataTag) {
|
||||
if (empty($dataTag['Tag'])) {
|
||||
unset($data[$dataType . 'Tag'][$k]);
|
||||
continue;
|
||||
}
|
||||
if (!isset($options['excludeGalaxy']) || !$options['excludeGalaxy']) {
|
||||
if (substr($dataTag['Tag']['name'], 0, strlen('misp-galaxy:')) === 'misp-galaxy:') {
|
||||
$cluster = $this->GalaxyCluster->getCluster($dataTag['Tag']['name']);
|
||||
if ($cluster) {
|
||||
$found = false;
|
||||
foreach ($data['Galaxy'] as $k => $galaxy) {
|
||||
if ($galaxy['id'] == $cluster['GalaxyCluster']['Galaxy']['id']) {
|
||||
$found = true;
|
||||
$temp = $cluster;
|
||||
unset($temp['GalaxyCluster']['Galaxy']);
|
||||
$data['Galaxy'][$k]['GalaxyCluster'][] = $temp['GalaxyCluster'];
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (!$found) {
|
||||
$data['Galaxy'][] = $cluster['GalaxyCluster']['Galaxy'];
|
||||
$temp = $cluster;
|
||||
unset($temp['GalaxyCluster']['Galaxy']);
|
||||
$data['Galaxy'][count($data['Galaxy']) - 1]['GalaxyCluster'][] = $temp['GalaxyCluster'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$data[$dataType . 'Tag'] = array_values($data[$dataType . 'Tag']);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -146,4 +146,66 @@ class Galaxy extends AppModel{
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function attachCluster($user, $target_type, $target_id, $cluster_id) {
|
||||
$cluster = $this->GalaxyCluster->find('first', array('recursive' => -1, 'conditions' => array('id' => $cluster_id), 'fields' => array('tag_name', 'id', 'value')));
|
||||
$this->Tag = ClassRegistry::init('Tag');
|
||||
if ($target_type == 'event') {
|
||||
$event = $this->Tag->EventTag->Event->fetchEvent($user, array('eventid' => $target_id, 'metadata' => 1));
|
||||
if (empty($event)) {
|
||||
throw new NotFoundException('Invalid event.');
|
||||
}
|
||||
$event = $event[0];
|
||||
$tag_id = $this->Tag->captureTag(array('name' => $cluster['GalaxyCluster']['tag_name'], 'colour' => '#0088cc', 'exportable' => 1), $user);
|
||||
if ($tag_id === false) {
|
||||
throw new MethodNotAllowedException('Could not attach cluster.');
|
||||
}
|
||||
$this->Tag->EventTag->create();
|
||||
$existingTag = $this->Tag->EventTag->find('first', array('conditions' => array('event_id' => $target_id, 'tag_id' => $tag_id)));
|
||||
if (!empty($existingTag)) {
|
||||
return 'Cluster already attached.';
|
||||
}
|
||||
$result = $this->Tag->EventTag->save(array('event_id' => $target_id, 'tag_id' => $tag_id));
|
||||
} else if ($target_type == 'attribute') {
|
||||
$attribute = $this->Tag->AttributeTag->Attribute->fetchAttributes($user, array('conditions' => array('Attribute.id' => $target_id)));
|
||||
if (empty($attribute)) {
|
||||
throw new NotFoundException('Invalid attribute.');
|
||||
}
|
||||
$attribute = $attribute[0];
|
||||
$tag_id = $this->Tag->captureTag(array('name' => $cluster['GalaxyCluster']['tag_name'], 'colour' => '#0088cc', 'exportable' => 1), $user);
|
||||
if ($tag_id === false) {
|
||||
throw new MethodNotAllowedException('Could not attach cluster.');
|
||||
}
|
||||
$existingTag = $this->Tag->AttributeTag->find('first', array('conditions' => array('attribute_id' => $target_id, 'tag_id' => $tag_id)));
|
||||
if (!empty($existingTag)) {
|
||||
return 'Cluster already attached.';
|
||||
}
|
||||
$event = $this->Tag->EventTag->Event->find('first', array(
|
||||
'conditions' => array(
|
||||
'Event.id' => $attribute['Attribute']['event_id']
|
||||
),
|
||||
'recursive' => -1
|
||||
));
|
||||
$result = $this->Tag->AttributeTag->save(array('attribute_id' => $target_id, 'tag_id' => $tag_id, 'event_id' => $attribute['Attribute']['event_id']));
|
||||
}
|
||||
if ($result) {
|
||||
$event['Event']['published'] = 0;
|
||||
$date = new DateTime();
|
||||
$event['Event']['timestamp'] = $date->getTimestamp();
|
||||
$this->Tag->EventTag->Event->save($event);
|
||||
$this->Log = ClassRegistry::init('Log');
|
||||
$this->Log->create();
|
||||
$this->Log->save(array(
|
||||
'org' => $user['Organisation']['name'],
|
||||
'model' => ucfirst($target_type),
|
||||
'model_id' => $target_id,
|
||||
'email' => $user['email'],
|
||||
'action' => 'galaxy',
|
||||
'title' => 'Attached ' . $cluster['GalaxyCluster']['value'] . ' (' . $cluster['GalaxyCluster']['id'] . ') to ' . $target_type . ' (' . $target_id . ')',
|
||||
'change' => ''
|
||||
));
|
||||
return 'Cluster attached.';
|
||||
}
|
||||
return 'Could not attach the cluster';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -129,6 +129,17 @@
|
|||
<?php echo $this->element('ajaxAttributeTags', array('attributeId' => $object['id'], 'attributeTags' => $object['AttributeTag'], 'tagAccess' => ($isSiteAdmin || $mayModify || $me['org_id'] == $event['Event']['org_id']) )); ?>
|
||||
</div>
|
||||
</td>
|
||||
<td class="short">
|
||||
<?php
|
||||
echo $this->element('galaxyQuickViewMini', array(
|
||||
'mayModify' => $mayModify,
|
||||
'isAclTagger' => $isAclTagger,
|
||||
'data' => (!empty($object['Galaxy']) ? $object['Galaxy'] : array()),
|
||||
'target_id' => $object['id'],
|
||||
'target_type' => 'attribute'
|
||||
));
|
||||
?>
|
||||
</td>
|
||||
<td class="showspaces bitwider">
|
||||
<div id = "Attribute_<?php echo $object['id']; ?>_comment_placeholder" class = "inline-field-placeholder"></div>
|
||||
<div id = "Attribute_<?php echo $object['id']; ?>_comment_solid" class="inline-field-solid" ondblclick="activateField('<?php echo $editScope; ?>', '<?php echo $object['id']; ?>', 'comment', <?php echo $event['Event']['id'];?>);">
|
||||
|
|
|
@ -61,7 +61,7 @@
|
|||
?>
|
||||
|
||||
</td>
|
||||
<td colspan="4">
|
||||
<td colspan="5">
|
||||
<span class="bold"><?php echo __('Name: ');?></span><?php echo h($object['name']);?>
|
||||
<span class="fa fa-expand useCursorPointer" title="<?php echo __('Expand or Collapse');?>" role="button" tabindex="0" aria-label="<?php echo __('Expand or Collapse');?>" data-toggle="collapse" data-target="#Object_<?php echo h($object['id']); ?>_collapsible"></span>
|
||||
<br />
|
||||
|
|
|
@ -112,21 +112,8 @@
|
|||
?>
|
||||
</div>
|
||||
</td>
|
||||
<td class="shortish">
|
||||
<?php
|
||||
if ($object['objectType'] == 0):
|
||||
?>
|
||||
<div class="attributeTagContainer">
|
||||
|
||||
</div>
|
||||
<?php
|
||||
else:
|
||||
?>
|
||||
|
||||
<?php
|
||||
endif;
|
||||
?>
|
||||
</td>
|
||||
<td class="shortish"> </td>
|
||||
<td class="shortish"> </td>
|
||||
<td class="showspaces bitwider">
|
||||
<div id = "<?php echo $currentType . '_' . $object['id'] . '_comment_placeholder'; ?>" class = "inline-field-placeholder"></div>
|
||||
<div id = "<?php echo $currentType . '_' . $object['id'] . '_comment_solid'; ?>" class="inline-field-solid" ondblclick="activateField('<?php echo $currentType; ?>', '<?php echo $object['id']; ?>', 'comment', <?php echo $event['Event']['id'];?>);">
|
||||
|
|
|
@ -67,7 +67,7 @@
|
|||
}
|
||||
?>
|
||||
</td>
|
||||
<td colspan="<?php echo $fieldCount; ?>"> </td>
|
||||
<td colspan="<?php echo $fieldCount+1; ?>"> </td>
|
||||
<td class="short action-links">
|
||||
<?php
|
||||
if (($event['Orgc']['id'] == $me['org_id'] && $mayModify) || $isSiteAdmin) {
|
||||
|
|
|
@ -175,6 +175,7 @@
|
|||
<th><?php echo $this->Paginator->sort('type');?></th>
|
||||
<th><?php echo $this->Paginator->sort('value');?></th>
|
||||
<th>Tags</th>
|
||||
<th>Galaxies</th>
|
||||
<th><?php echo $this->Paginator->sort('comment');?></th>
|
||||
<th>Correlate</th>
|
||||
<th>Related Events</th>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
$fixed_fields = array('synonyms', 'description', 'meta', 'authors', 'source');
|
||||
foreach ($event['Galaxy'] as $galaxy):
|
||||
foreach ($data as $galaxy):
|
||||
?>
|
||||
<div style="margin-left:10px;">
|
||||
<span title="<?php echo isset($galaxy['description']) ? h($galaxy['description']) : h($galaxy['name']);?>" class="bold blue" style="font-size:14px;">
|
||||
|
@ -17,7 +17,7 @@
|
|||
<?php
|
||||
if ($isSiteAdmin || ($mayModify && $isAclTagger)) {
|
||||
echo $this->Form->postLink('',
|
||||
$baseurl . '/galaxy_clusters/detachFromEvent/' . $event['Event']['id'] . '/' . $cluster['tag_id'],
|
||||
$baseurl . '/galaxy_clusters/detach/' . ucfirst(h($target_id)) . '/' . h($target_type) . '/' . $cluster['tag_id'],
|
||||
array('class' => 'icon-trash', 'title' => 'Delete'),
|
||||
__('Are you sure you want to detach %s from this event?', h($cluster['value']))
|
||||
);
|
||||
|
@ -98,7 +98,7 @@
|
|||
<?php
|
||||
if ($isSiteAdmin || ($mayModify && $isAclTagger)):
|
||||
?>
|
||||
<span class="useCursorPointer btn btn-inverse" id="addGalaxy" data-event-id="<?php echo h($event['Event']['id']); ?>" role="button" tabindex="0" aria-label="Add new cluster" style="margin-top:20px;padding: 1px 5px !important;font-size: 12px !important;">Add new cluster</span>
|
||||
<span class="useCursorPointer btn btn-inverse addGalaxy" data-target-type="<?php echo h($target_type);?>" data-target-id="<?php echo h($target_id); ?>" role="button" tabindex="0" aria-label="Add new cluster" style="padding: 1px 5px !important;font-size: 12px !important;">Add</span>
|
||||
<?php
|
||||
endif;
|
||||
?>
|
||||
|
|
|
@ -0,0 +1,111 @@
|
|||
<?php
|
||||
$fixed_fields = array('synonyms', 'description', 'meta', 'authors', 'source');
|
||||
foreach ($data as $galaxy):
|
||||
?>
|
||||
<div>
|
||||
<span title="<?php echo isset($galaxy['description']) ? h($galaxy['description']) : h($galaxy['name']);?>" class="bold blue" style="font-size:14px;">
|
||||
<?php echo h($galaxy['name']); ?>
|
||||
</span>
|
||||
<?php
|
||||
foreach ($galaxy['GalaxyCluster'] as $cluster):
|
||||
$cluster_fields = array();
|
||||
if (isset($cluster['description'])) {
|
||||
$cluster_fields[] = array('key' => 'description', 'value' => $cluster['description']);
|
||||
}
|
||||
if (isset($cluster['meta']['synonyms'])) {
|
||||
$cluster_fields[] = array('key' => 'synonyms', 'value' => $cluster['meta']['synonyms']);
|
||||
}
|
||||
if (isset($cluster['source'])) {
|
||||
$cluster_fields[] = array('key' => 'source', 'value' => $cluster['source']);
|
||||
}
|
||||
if (isset($cluster['authors'])) {
|
||||
$cluster_fields[] = array('key' => 'authors', 'value' => $cluster['authors']);
|
||||
}
|
||||
if (!empty($cluster['meta'])) {
|
||||
foreach ($cluster['meta'] as $metaKey => $metaField) {
|
||||
if ($metaKey != 'synonyms') {
|
||||
$cluster_fields[] = array('key' => $metaKey, 'value' => $metaField);
|
||||
}
|
||||
}
|
||||
}
|
||||
$popover_data = sprintf('<h4 class="blue bold">%s</h4>', h($cluster['value']));
|
||||
foreach ($cluster_fields as $cluster_field) {
|
||||
$key = sprintf('<span class="blue bold">%s</span>', Inflector::humanize(h($cluster_field['key'])));
|
||||
if (is_array($cluster_field['value'])) {
|
||||
if ($cluster_field['key'] == 'refs') {
|
||||
$value = array();
|
||||
foreach ($cluster_field['value'] as $k => $v) {
|
||||
$v_name = $v;
|
||||
if (strlen($v_name) > 30) {
|
||||
$v_name = substr($v, 0, 30) . '...';
|
||||
}
|
||||
$value[$k] = '<a href="' . h($v) . '" title="' . h($v) . '">' . h($v_name) . '</a>';
|
||||
}
|
||||
$value_contents = nl2br(implode("\n", $value));
|
||||
} else if($cluster_field['key'] == 'country') {
|
||||
$value = array();
|
||||
foreach ($cluster_field['value'] as $k => $v) {
|
||||
$value[] = '<span class="famfamfam-flag-' . strtolower(h($v)) . '" ></span> ' . h($v);
|
||||
}
|
||||
$value_contents = nl2br(implode("\n", $value));
|
||||
} else {
|
||||
$value_contents = nl2br(h(implode("\n", $cluster_field['value'])));
|
||||
}
|
||||
} else {
|
||||
if ($cluster_field['key'] == 'source' && filter_var($cluster_field['value'], FILTER_VALIDATE_URL)) {
|
||||
$value_contents = '<a href="' . h($cluster_field['value']) . '">' . h($cluster_field['value']) . '</a>';;
|
||||
} else {
|
||||
$value_contents = h($cluster_field['value']);
|
||||
}
|
||||
}
|
||||
$value = sprintf('<span class="black">%s</span>', $value_contents);
|
||||
$popover_data .= sprintf('<span>%s: %s</span><br />', $key, $value);
|
||||
}
|
||||
?>
|
||||
<div style="margin-left:8px;">
|
||||
<span class="bold blue expandable useCursorPointer" data-toggle="popover" data-content="<?php echo h($popover_data); ?>">
|
||||
<?php echo h($cluster['value']); ?>
|
||||
</span>
|
||||
<a href="<?php echo $baseurl; ?>/galaxy_clusters/view/<?php echo h($cluster['id']); ?>" class="icon-search" title="View details about this cluster"></a>
|
||||
<a href="<?php echo $baseurl; ?>/events/index/searchtag:<?php echo h($cluster['tag_id']); ?>" class="icon-th-list" title="View all events containing this cluster."></a>
|
||||
<?php
|
||||
if ($isSiteAdmin || ($mayModify && $isAclTagger)) {
|
||||
echo $this->Form->postLink('',
|
||||
$baseurl . '/galaxy_clusters/detachFrom' . ucfirst(h($target_type)). '/' . ucfirst(h($target_id)) . '/' . $cluster['tag_id'],
|
||||
array('class' => 'icon-trash', 'title' => 'Delete'),
|
||||
__('Are you sure you want to detach %s from this %s?', h($cluster['value']), h($target_type))
|
||||
);
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
endforeach;
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
endforeach;
|
||||
?>
|
||||
<?php
|
||||
if ($isSiteAdmin || ($mayModify && $isAclTagger)):
|
||||
?>
|
||||
<span class="btn btn-inverse noPrint addGalaxy" data-target-type="<?php echo h($target_type);?>" data-target-id="<?php echo h($target_id); ?>" role="button" tabindex="0" aria-label="Add new cluster" style="padding: 1px 5px !important;font-size: 12px !important;">Add</span>
|
||||
<?php
|
||||
endif;
|
||||
?>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function () {
|
||||
$('.expandable').click(function() {
|
||||
$(this).parent().children('div').toggle();
|
||||
if ($(this).children('span').html() == '+') {
|
||||
$(this).children('span').html('-');
|
||||
} else {
|
||||
$(this).children('span').html('+');
|
||||
}
|
||||
});
|
||||
$('.delete-cluster').click(function() {
|
||||
var tagName = $(this).data('tag-name');
|
||||
removeTag($id = false, $tag_id = false, $galaxy = false);
|
||||
});
|
||||
});
|
||||
</script>
|
|
@ -382,7 +382,7 @@
|
|||
</div>
|
||||
<div id="galaxies_div" class="info_container">
|
||||
<h4 class="blue"><?php echo __('Galaxies');?></h4>
|
||||
<?php echo $this->element('galaxyQuickView', array('mayModify' => $mayModify, 'isAclTagger' => $isAclTagger)); ?>
|
||||
<?php echo $this->element('galaxyQuickView', array('mayModify' => $mayModify, 'isAclTagger' => $isAclTagger, 'data' => $event['Galaxy'], 'target_id' => $event['Event']['id'], 'target_type' => 'event')); ?>
|
||||
</div>
|
||||
<div id="eventgraph_div" class="info_container_eventgraph_network" style="display: none;" data-fullscreen="false">
|
||||
<?php echo $this->element('view_event_graph'); ?>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<legend><?php echo __('Select Cluster');?></legend>
|
||||
<div class="hidden">
|
||||
<?php
|
||||
echo $this->Form->create('Galaxy', array('url' => '/galaxies/attachClusterToEvent/' . $event_id, 'style' => 'margin:0px;'));
|
||||
echo $this->Form->create('Galaxy', array('url' => '/galaxies/attachCluster/' . $target_type . '/' . $target_id, 'style' => 'margin:0px;'));
|
||||
echo $this->Form->input('target_id', array('type' => 'text'));
|
||||
echo $this->Form->end();
|
||||
?>
|
||||
|
@ -17,13 +17,13 @@
|
|||
$title = isset($cluster['description']) ? $cluster['description'] : $cluster['value'];
|
||||
?>
|
||||
<tr id="field_<?php echo h($cluster['id']); ?>" style="border-bottom:1px solid black;" class="templateChoiceButton filterableButton">
|
||||
<td class="clusterSelectChoice" data-event-id="<?php echo h($event_id); ?>" data-cluster-id="<?php echo h($cluster['id']); ?>" style="padding-left:10px;padding-right:10px; text-align:center;width:100%;" title="<?php echo 'Synonyms: ' . h($cluster['synonyms_string']); ?>"><?php echo h($cluster['value']); ?></td>
|
||||
<td class="clusterSelectChoice" data-target-type="<?php echo h($target_type); ?>" data-target-id="<?php echo h($target_id); ?>" data-cluster-id="<?php echo h($cluster['id']); ?>" style="padding-left:10px;padding-right:10px; text-align:center;width:100%;" title="<?php echo 'Synonyms: ' . h($cluster['synonyms_string']); ?>"><?php echo h($cluster['value']); ?></td>
|
||||
</tr>
|
||||
<?php
|
||||
endforeach;
|
||||
?>
|
||||
<tr style="border-bottom:1px solid black;" class="templateChoiceButton">
|
||||
<td class="clusterSelectBack" style="padding-left:10px;padding-right:10px; text-align:center;width:100%;" data-event-id="<?php echo h($event_id); ?>" title="Select Galaxy"><?php echo __('Back to Galaxy Selection');?></td>
|
||||
<td class="clusterSelectBack" style="padding-left:10px;padding-right:10px; text-align:center;width:100%;" data-target-type="<?php echo h($target_type); ?>" data-event-id="<?php echo h($target_id); ?>" title="Select Galaxy"><?php echo __('Back to Galaxy Selection');?></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
@ -37,11 +37,11 @@
|
|||
});
|
||||
|
||||
$('.clusterSelectBack').click(function() {
|
||||
getPopup($(this).data('event-id'), 'galaxies', 'selectGalaxy');
|
||||
getPopup($(this).data('target-type') + '/' + $(this).data('target-id'), 'galaxies', 'selectGalaxy');
|
||||
});
|
||||
|
||||
$('.clusterSelectChoice').click(function() {
|
||||
quickSubmitGalaxyForm($(this).data('event-id'), $(this).data('cluster-id'));
|
||||
quickSubmitGalaxyForm($(this).data('target-type') + '/' + $(this).data('target-id'), $(this).data('cluster-id'));
|
||||
});
|
||||
$('#clusterFilterField').keyup(function() {
|
||||
var filterString = $("#clusterFilterField").val().toLowerCase();
|
||||
|
|
|
@ -3,11 +3,11 @@
|
|||
<div class="popover_choice_main" id ="popover_choice_main">
|
||||
<table style="width:100%;">
|
||||
<tr style="border-bottom:1px solid black;" class="templateChoiceButton">
|
||||
<td role="button" tabindex="0" aria-label="<?php echo __('All clusters');?>" title="<?php echo __('All clusters');?>" style="padding-left:10px;padding-right:10px; text-align:center;width:100%;" onClick="getPopup('<?php echo h($event_id); ?>/0', 'galaxies', 'selectCluster');"><?php echo __('All Galaxies');?></td>
|
||||
<td role="button" tabindex="0" aria-label="<?php echo __('All clusters');?>" title="<?php echo __('All clusters');?>" style="padding-left:10px;padding-right:10px; text-align:center;width:100%;" onClick="getPopup('<?php echo h($target_id); ?>/0', 'galaxies', 'selectCluster');"><?php echo __('All Galaxies');?></td>
|
||||
</tr>
|
||||
<?php foreach ($galaxies as $galaxy): ?>
|
||||
<tr style="border-bottom:1px solid black;" class="templateChoiceButton">
|
||||
<td role="button" tabindex="0" aria-label="<?php echo h($galaxy['Galaxy']['name']); ?>" title="<?php echo h($galaxy['Galaxy']['name']); ?>" style="padding-left:10px;padding-right:10px; text-align:center;width:100%;" onClick="getPopup('<?php echo h($event_id); ?>/<?php echo h($galaxy['Galaxy']['id']);?>', 'galaxies', 'selectCluster');">Galaxy: <?php echo h($galaxy['Galaxy']['name']); ?></td>
|
||||
<td role="button" tabindex="0" aria-label="<?php echo h($galaxy['Galaxy']['name']); ?>" title="<?php echo h($galaxy['Galaxy']['name']); ?>" style="padding-left:10px;padding-right:10px; text-align:center;width:100%;" onClick="getPopup('<?php echo h($target_id) . "/" . h($target_type); ?>/<?php echo h($galaxy['Galaxy']['id']);?>', 'galaxies', 'selectCluster');">Galaxy: <?php echo h($galaxy['Galaxy']['name']); ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
|
|
|
@ -1253,6 +1253,11 @@ function getPopup(id, context, target, admin, popupType) {
|
|||
$(popupType).html(data);
|
||||
openPopup(popupType);
|
||||
},
|
||||
error:function() {
|
||||
$(".loading").hide();
|
||||
$("#gray_out").fadeOut();
|
||||
showMessage('fail', 'Something went wrong - the queried function returned an exception. Contact your administrator for further details (the exception has been logged).');
|
||||
},
|
||||
url: url
|
||||
});
|
||||
}
|
||||
|
@ -1271,11 +1276,6 @@ function simplePopup(url) {
|
|||
$("#popover_form").html(data);
|
||||
openPopup("#popover_form");
|
||||
},
|
||||
error:function() {
|
||||
$(".loading").hide();
|
||||
$("#gray_out").fadeOut();
|
||||
showMessage('fail', 'Something went wrong - the queried function returned an exception. Contact your administrator for further details (the exception has been logged).');
|
||||
},
|
||||
url: url,
|
||||
});
|
||||
}
|
||||
|
@ -3059,8 +3059,10 @@ $('.galaxy-toggle-button').click(function() {
|
|||
}
|
||||
});
|
||||
|
||||
$('#addGalaxy').click(function() {
|
||||
getPopup($(this).data('event-id'), 'galaxies', 'selectGalaxy');
|
||||
$('.addGalaxy').click(function() {
|
||||
var target_type = $(this).data('target-type');
|
||||
var target_id = $(this).data('target-id');
|
||||
getPopup(target_type + '/' + target_id, 'galaxies', 'selectGalaxy');
|
||||
});
|
||||
|
||||
function quickSubmitGalaxyForm(event_id, cluster_id) {
|
||||
|
|
Loading…
Reference in New Issue