]> source.dussan.org Git - nextcloud-server.git/commitdiff
log viewer
authorRobin Appelman <icewind1991@gmail.com>
Thu, 21 Apr 2011 21:12:32 +0000 (23:12 +0200)
committerRobin Appelman <icewind1991@gmail.com>
Thu, 21 Apr 2011 21:12:32 +0000 (23:12 +0200)
log/index.php
log/js/log.js [new file with mode: 0644]
log/templates/index.php

index 646dbc0cc595429c746a89e1affefff49c1010a3..d86da6e000475e508fe922d532bc92a5c549b79e 100644 (file)
 //require_once('../../config/config.php');
 require_once('../lib/base.php');
 require( 'template.php' );
+
 if( !OC_USER::isLoggedIn()){
-    header( "Location: ".OC_HELPER::linkTo( "index.php" ));
+    header( 'Location: '.OC_HELPER::linkTo( 'index.php' ));
     exit();
 }
 
-OC_APP::setActiveNavigationEntry( "log" );
-$logs=OC_LOG::get( $dir );
+//load the script
+OC_UTIL::addScript( "log", "log" );
+
+$allActions=array('login','logout','read','write','create','delete');
+
+//check for a submited config
+if(isset($_POST['size'])){
+       $selectedActions=array();
+       foreach($allActions as $action){
+               if(isset($_POST[$action]) and $_POST[$action]=='on'){
+                       $selectedActions[]=$action;
+               }
+       }
+       OC_APPCONFIG::setValue('log','actions',implode(',',$selectedActions));
+       OC_APPCONFIG::setValue('log','pagesize',$_POST['size']);
+}
+
+OC_APP::setActiveNavigationEntry( 'log' );
+$logs=OC_LOG::get();
+
+$selectedActions=explode(',',OC_APPCONFIG::getValue('log','actions',implode(',',$allActions)));
+$logs=OC_LOG::filterAction($logs,$selectedActions);
+
+$pageSize=OC_APPCONFIG::getValue('log','pagesize',20);
+$pageCount=ceil(count($logs)/$pageSize);
+$page=isset($_GET['page'])?$_GET['page']:0;
+if($page>=$pageCount){
+       $page=$pageCount-1;
+}
+
+$logs=array_slice($logs,$page*$pageSize,$pageSize);
 
 foreach( $logs as &$i ){
-    $i["date"] = date( $CONFIG_DATEFORMAT, $i['timestamp'] );
-    $i["action"] = OC_LOG::$TYPE[$i['type']];
+    $i['date'] =$i['timestamp'];
+}
+
+$url=OC_HELPER::linkTo( 'log', 'index.php' ).'?page=';
+$pager=OC_UTIL::getPageNavi($pageCount,$page,$url);
+if($pager){
+       $pagerHTML=$pager->fetchPage();
+}else{
+       $pagerHTML='';
+}
+
+$showActions=array();
+foreach($allActions as $action){
+       if(array_search($action,$selectedActions)!==false){
+               $showActions[$action]='checked="checked"';
+       }else{
+               $showActions[$action]='';
+       }
 }
 
-$tmpl = new OC_TEMPLATE( "log", "index", "admin" );
-$tmpl->assign( "logs", $logs );
+$tmpl = new OC_TEMPLATE( 'log', 'index', 'admin' );
+$tmpl->assign( 'logs', $logs );
+$tmpl->assign( 'pager', $pagerHTML );
+$tmpl->assign( 'size', $pageSize );
+$tmpl->assign( 'showActions', $showActions );
 $tmpl->printPage();
 
 ?>
diff --git a/log/js/log.js b/log/js/log.js
new file mode 100644 (file)
index 0000000..47c20b3
--- /dev/null
@@ -0,0 +1,21 @@
+$(document).ready(function() {
+       // Sets the select_all checkbox behaviour :
+       $('#all').click(function() {
+               if($(this).attr('checked')){
+                       // Check all
+                       $('input.action:checkbox').attr('checked', true);
+               }else{
+                       // Uncheck all
+                       $('input.action:checkbox').attr('checked', false);
+               }
+       });
+       $('input.action:checkbox').click(function() {
+               if(!$(this).attr('checked')){
+                       $('#all').attr('checked',false);
+               }else{
+                       if($('input.action:checkbox:checked').length==$('input.action:checkbox').length){
+                               $('#all').attr('checked',true);
+                       }
+               }
+       });
+});
\ No newline at end of file
index 18630e49d065b6b0583a3c0e2eb152936b8cfdde..1e294091e3fa11803d99bc7f30c4beb16c915ed5 100644 (file)
@@ -1,20 +1,19 @@
 <div class="controls">
-       <form id="logs_options">
+       <form id="logs_options" method='post'>
                <p>
                        <span>Filter :</span>
 
-                       <input type="checkbox" checked="checked" name="all" id="all" /> <label for="all">All</label>
-                       <input type="checkbox" checked="checked" name="logins" id="logins" /> <label for="logins">Logins</label>
-                       <input type="checkbox" checked="checked" name="logouts" id="logouts" /> <label for="logouts">Logouts</label>
-                       <input type="checkbox" checked="checked" name="downloads" id="downloads" /> <label for="downloads">Downloads</label>
-                       <input type="checkbox" checked="checked" name="uploads" id="uploads" /> <label for="uploads">Uploads</label>
-
-                       <input type="checkbox" checked="checked" name="creations" id="creations" /> <label for="creations">Creations</label>
-                       <input type="checkbox" checked="checked" name="deletions" id="deletions" /> <label for="deletions">Deletions</label>
+                       <input type="checkbox" checked="" name="all" id="all" /> <label for="all">All</label>
+                       <input type="checkbox" class='action' <?php echo $_['showActions']['login']?> name="login" id="logins" /> <label for="logins">Logins</label>
+                       <input type="checkbox" class='action' <?php echo $_['showActions']['logout']?> name="logout" id="logouts" /> <label for="logouts">Logouts</label>
+                       <input type="checkbox" class='action' <?php echo $_['showActions']['read']?> name="read" id="downloads" /> <label for="downloads">Downloads</label>
+                       <input type="checkbox" class='action' <?php echo $_['showActions']['write']?> name="write" id="uploads" /> <label for="uploads">Uploads</label>
+                       <input type="checkbox" class='action' <?php echo $_['showActions']['create']?> name="create" id="creations" /> <label for="creations">Creations</label>
+                       <input type="checkbox" class='action' <?php echo $_['showActions']['delete']?> name="delete" id="deletions" /> <label for="deletions">Deletions</label>
                </p>
                <p>
                        <span>Show :</span>
-                       <input type="text" maxlength="3" size="3" value="10" />&nbsp;entries per page.
+                       <input type="text" maxlength="3" size="3" value="<?php echo $_['size']?>" name='size'/>&nbsp;entries per page.
                        <input class="prettybutton" type="submit" value="Save" />
 
                </p>
        <tbody>
                <?php foreach($_["logs"] as $entry): ?>
                        <tr>
-                               <td class="login"><em><?php echo $entry["user"]; ?></em> <?php echo $entry["message"]; ?></td>
+                               <td class="<?php echo $entry["action"]; ?>"><em><?php echo $entry["action"]; ?> <?php echo $entry["user"]; ?></em> <?php echo $entry["info"]; ?></td>
                                <td class="date"><?php echo $entry["date"]; ?></td>
                        </tr>
                <?php endforeach; ?>
        </tbody>
 </table>
 
-<div class="controls">
-    <p class="center"><a href="" title="Previous page">&larr;</a>&nbsp;3/5&nbsp;<a href="" title="Next page">&rarr;</a></p>
-</div>
+<?php echo $_['pager'];?>