diff options
author | Camil Staps | 2020-02-03 10:22:56 +0100 |
---|---|---|
committer | Camil Staps | 2020-02-03 10:22:56 +0100 |
commit | 7dd04a84ab530ef572df3b0df4fa444271f78c7e (patch) | |
tree | 7b9be02b61277aeb910a3a0bb69eb32e2141b1a8 | |
parent | Initial commit (diff) |
Add ability to see description on list.php
-rw-r--r-- | db.php | 25 | ||||
-rw-r--r-- | list.php | 29 | ||||
-rw-r--r-- | style.css | 10 |
3 files changed, 60 insertions, 4 deletions
@@ -31,6 +31,31 @@ function add_event ($info) return $id; } +function get_event ($id) +{ + global $pdo; + $st=$pdo->prepare ( + 'select `title`,`location`,`start_date`,`end_date`,`description`,`sources`.`source` ' . + 'from `events` inner join `sources` on `events`.`source`=`sources`.`id` ' . + 'where `events`.`id`=?' + ); + if (!$st->execute ([$id])){ + $err=$st->errorInfo(); + throw new Exception ('Error ('.$err[0].', '.$err[1].'): '.$err[2]); + } + $event=$st->fetch (PDO::FETCH_ASSOC); + + $st=$pdo->prepare ( + 'select `keywords`.`keyword` from `keywords` ' . + 'where exists (select * from `event_keyword` where `event`=? and `event_keyword`.`keyword`=`keywords`.`id`)' + ); + $st->execute ([$id]); + $keywords=$st->fetchAll (PDO::FETCH_NUM); + $event['keywords']=array_map ('array_shift',$keywords); + + return $event; +} + function get_events ($keywords=[]) { global $pdo; @@ -55,7 +55,7 @@ foreach ($events as $event){ echo ' to '.date ('j M',strtotime ($event['end_date'])); echo '</td>'; echo '<td>'.htmlspecialchars ($event['location']).'</td>'; - echo '<td>'.htmlspecialchars ($event['title']).'</td>'; + echo '<td><span class="title-link" title="Click for details" onclick="expand_or_collapse(this,'.$event['id'].');">'.htmlspecialchars ($event['title']).'</span></td>'; foreach ($event['keywords'] as $i => $kw){ if (!is_null ($selected_keywords) && !in_array ($kw,$selected_keywords)) $event['keywords'][$i]='<span class="filtered-keyword">'.htmlspecialchars ($kw).'</span>'; @@ -84,6 +84,33 @@ function check_all_keywords (check) return false; } +function expand_or_collapse (elem,id) +{ + if (elem.parentNode.childNodes.length > 1){ + let p=elem.parentNode.childNodes[1]; + p.style.display=p.style.display=='none' ? 'block' : 'none'; + return; + } + + var xhttp=new XMLHttpRequest(); + xhttp.onreadystatechange=function(){ + if (this.readyState!=4) + return; + if (this.status!=200){ + window.alert ('Failed to fetch event information ('+this.status+')'); + return; + } + + let ev=JSON.parse (xhttp.responseText); + let p=document.createElement ('p'); + p.classList.add ('description'); + p.innerHTML=ev.description; + elem.parentNode.appendChild (p); + }; + xhttp.open ('GET','event.php?id='+id,true); + xhttp.send(); +} + update_keywords_field(); checkboxes.map (cb => cb.onchange=update_keywords_field); </script> @@ -20,14 +20,18 @@ th, td { vertical-align: top; } -td.description { +.description { font-size: 85%; } +.filtered-keyword { + color: gray; +} + #keyword-filters { column-width: 20em; } -.filtered-keyword { - color: gray; +.title-link { + cursor: pointer; } |