Author: benj
Date: Sat Feb  7 17:15:42 2015
New Revision: 1641

URL: http://svn.gna.org/viewcvs/gdtc?rev=1641&view=rev
Log:
Implement dtcsync import

Added:
    trunk/gdtc/include/dtcsync.php
    trunk/gdtc/templates/smarty/admin/dtcsync-list.tpl
    trunk/gdtc/templates/smarty/admin/dtcsync-show.tpl
Modified:
    trunk/gdtc/admin/index.php
    trunk/gdtc/include/errors.php
    trunk/gdtc/templates/smarty/admin/header.tpl

Modified: trunk/gdtc/admin/index.php
URL: 
http://svn.gna.org/viewcvs/gdtc/trunk/gdtc/admin/index.php?rev=1641&r1=1640&r2=1641&view=diff
==============================================================================
--- trunk/gdtc/admin/index.php  (original)
+++ trunk/gdtc/admin/index.php  Sat Feb  7 17:15:42 2015
@@ -67,6 +67,7 @@
     require '../include/ldap.php';
     require '../include/coherence.php';
     require '../include/mailing.php';
+    require '../include/dtcsync.php';
 
     setlocale(LC_ALL, "fr_FR");
 
@@ -498,6 +499,15 @@
                    return mailing_progress ( $http_args );
                else if ( $action == 'mailing_preview' )
                    return mailing_preview ( $http_args );
+
+               else if ( $action == 'dtcsync_list' )
+                   return dtcsync_list ( $http_args );
+               else if ( $action == 'dtcsync_run' )
+                   return dtcsync_run ( $http_args );
+               else if ( $action == 'dtcsync_show' )
+                   return dtcsync_show ( $http_args );
+               else if ( $action == 'dtcsync_tail' )
+                   return dtcsync_tail ( $http_args );
                
                else
                    return croak ( "I'm puzzled..." );
@@ -512,12 +522,14 @@
        croak ( "I'm puzzled..." );
     }
 
-    main($http_args);
+    return main($http_args);
 }
 catch ( Exception $e )
 {
-    exit;
+    exit ( 0 );
 }
+
+exit ( 0 );
 
 /* Local Variables: */
 /* c-basic-offset: 4 */

Added: trunk/gdtc/include/dtcsync.php
URL: 
http://svn.gna.org/viewcvs/gdtc/trunk/gdtc/include/dtcsync.php?rev=1641&view=auto
==============================================================================
--- trunk/gdtc/include/dtcsync.php      (added)
+++ trunk/gdtc/include/dtcsync.php      Sat Feb  7 17:15:42 2015
@@ -0,0 +1,104 @@
+<?php // -*- php -*-
+
+/* ************************************************************************** 
*/
+/*                                                                            
*/
+/*     Copyright (C)   2013 Benjamin Drieu ([email protected])                */
+/*                                                                            
*/
+/*  This program is free software; you can redistribute it and/or modify      
*/
+/*  it under the terms of the GNU General Public License as published by      
*/
+/*  the Free Software Foundation; either version 2 of the License, or         
*/
+/*  (at your option) any later version.                                       
*/
+/*                                                                            
*/
+/*  This program is distributed in the hope that it will be useful,           
*/
+/*  but WITHOUT ANY WARRANTY; without even the implied warranty of            
*/
+/*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             
*/
+/*  GNU General Public License for more details.                              
*/
+/*                                                                            
*/
+/*  You should have received a copy of the GNU General Public License         
*/
+/*  along with this program; if not, write to the Free Software               
*/
+/*  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
*/
+/*                                                                            
*/
+/* ************************************************************************** 
*/
+
+
+
+
+function dtcsync_list ( $args )
+{
+    $smarty = init_smarty ( );
+    
+    $logs = Array ( );
+    $files = Array ( );
+    $logpath = sprintf ( '%s/logs', DTCSYNC_PATH );
+    if ( $handle = opendir ( $logpath ) )
+    {
+       while (false !== ($entry = readdir($handle))) {
+           if ( preg_match ( '/^log-[0-9]*$/', $entry ) )
+           {
+               $files [] = $entry;
+           }
+       }
+
+       rsort ( $files );
+       foreach ( $files as $entry )
+       {
+           $logs [] = Array ( 'filename' => $entry,
+                              'date' => date ("d/m/Y H:i:s", filectime ( 
"$logpath/$entry" ) ) );
+       }
+    }
+
+    $smarty -> assign ( 'logs', $logs );
+    $smarty -> display ( 'admin/dtcsync-list.tpl' );
+}
+
+
+
+function dtcsync_run ()
+{
+    $smarty = init_smarty ( );
+
+    $log = strftime ( 'log-%s' );
+    $cmd = sprintf ( '(%s %s 2>/dev/null >/dev/null &)', DTCSYNC_COMMAND, $log 
);
+    exec ( $cmd );
+
+    $smarty -> assign ( 'log', $log );
+    $smarty -> display ( 'admin/dtcsync-show.tpl' );
+}
+
+
+function dtcsync_show ( $args )
+{
+    $smarty = init_smarty ( );
+
+    if ( ! array_key_exists ( 'pos', $args ) )
+       $args [ 'pos' ] = 0;
+    if ( ! array_key_exists ( 'log', $args ) || ! preg_match ( 
'/^log-[0-9]*$/', $args [ 'log' ] ) )
+       return;
+
+    $data = file_get_contents ( sprintf ( '%s/logs/%s', DTCSYNC_PATH, $args [ 
'log' ] ) );
+
+    $smarty -> assign ( 'full', $data );
+    $smarty -> assign ( 'log', $args [ 'log' ] );
+
+    $smarty -> display ( 'admin/dtcsync-show.tpl' );
+}
+
+
+
+function dtcsync_tail ( $args )
+{
+    if ( ! array_key_exists ( 'pos', $args ) )
+       $args [ 'pos' ] = 0;
+    if ( ! array_key_exists ( 'log', $args ) || ! preg_match ( 
'/^log-[0-9]*$/', $args [ 'log' ] ) )
+       return;
+
+    $data = file_get_contents ( sprintf ( '%s/logs/%s', DTCSYNC_PATH, $args [ 
'log' ] ), false, NULL, $args [ 'pos' ], 1024 );
+    if ( $data && strlen($data) > 0 )
+       print json_encode ( Array ( 'last_byte'=> $args [ 'pos' ] + strlen ( 
$data ), 
+                                   'content' => $data ) );
+}
+
+/* Local Variables: */
+/* c-basic-offset: 4 */
+/* End: */
+?>

Modified: trunk/gdtc/include/errors.php
URL: 
http://svn.gna.org/viewcvs/gdtc/trunk/gdtc/include/errors.php?rev=1641&r1=1640&r2=1641&view=diff
==============================================================================
--- trunk/gdtc/include/errors.php       (original)
+++ trunk/gdtc/include/errors.php       Sat Feb  7 17:15:42 2015
@@ -159,6 +159,6 @@
 }
 
 set_error_handler("myErrorHandler");
-register_shutdown_function( "fatal_handler" );
+//register_shutdown_function( "fatal_handler" );
 
 ?>

Added: trunk/gdtc/templates/smarty/admin/dtcsync-list.tpl
URL: 
http://svn.gna.org/viewcvs/gdtc/trunk/gdtc/templates/smarty/admin/dtcsync-list.tpl?rev=1641&view=auto
==============================================================================
--- trunk/gdtc/templates/smarty/admin/dtcsync-list.tpl  (added)
+++ trunk/gdtc/templates/smarty/admin/dtcsync-list.tpl  Sat Feb  7 17:15:42 2015
@@ -0,0 +1,17 @@
+{include file="admin/header.tpl" template="$template" title="DTCsync" }
+
+<h2>Imports de DTC</h2>
+
+<p><span class="button"><a href="?action=dtcsync_run"><img border="0" 
src="{$dtc_admin_host_name}/dtcimages/reload.png"/> Synchro</a></span></p>
+
+<table class="supertable">
+<tr><th>Fichier</th><th>Date</th></tr>
+{section name=l loop=$logs}
+<tr>
+<td><a 
href="?action=dtcsync_show&log={$logs[l].filename}">{$logs[l].filename}</a></td>
+<td>{$logs[l].date}</td>
+</tr>
+{/section}
+</table>
+
+{include file="admin/footer.tpl"}

Added: trunk/gdtc/templates/smarty/admin/dtcsync-show.tpl
URL: 
http://svn.gna.org/viewcvs/gdtc/trunk/gdtc/templates/smarty/admin/dtcsync-show.tpl?rev=1641&view=auto
==============================================================================
--- trunk/gdtc/templates/smarty/admin/dtcsync-show.tpl  (added)
+++ trunk/gdtc/templates/smarty/admin/dtcsync-show.tpl  Sat Feb  7 17:15:42 2015
@@ -0,0 +1,51 @@
+{include file="admin/header.tpl" template="$template" title="DTCsync" }
+
+<style>
+#results {ldelim}
+    border: 1px solid orange;
+    padding: 1em;
+    margin: 1em;
+{rdelim}
+</style>
+
+<div id="results">
+{if $full}{$full}{/if}
+</div>
+
+{if ! $full}
+<div id="spinner">
+<b><img src="{$dtc_base_url}/dtcimages/ajax-spinner.gif" /> Processing 
<blink>...</blink></b>
+</div>      
+
+<script>
+{literal}
+var pos = 0;
+var whole = '';
+
+function refresh ()
+{
+  
$.getJSON("index.php?action=dtcsync_tail&log={/literal}{$log}{literal}&pos="+pos,
 function () { 
+    console.log('success');
+  } )
+  .done(function( data ) {
+    console.log ( 'OK' );
+    pos = data['last_byte'];
+    console.log ( pos );
+    console.log(data['content']);
+    whole = whole + data['content'];
+    $("#results").html(whole);
+    if ( data [ 'content' ] . indexOf ('*** FIN ***') != -1 ) 
+    {
+      clearInterval ( interval );
+      $('#spinner').hide();
+    }
+  } );
+}
+
+var interval = setInterval ( refresh, 1000 );
+
+{/literal}
+</script>
+{/if}
+
+{include file="admin/footer.tpl"}

Modified: trunk/gdtc/templates/smarty/admin/header.tpl
URL: 
http://svn.gna.org/viewcvs/gdtc/trunk/gdtc/templates/smarty/admin/header.tpl?rev=1641&r1=1640&r2=1641&view=diff
==============================================================================
--- trunk/gdtc/templates/smarty/admin/header.tpl        (original)
+++ trunk/gdtc/templates/smarty/admin/header.tpl        Sat Feb  7 17:15:42 2015
@@ -95,6 +95,7 @@
 <a href="?action=add&table=person">Ajouter un membre</a> |
 <a href="?action=list_table&table=actor">Liste des membres</a> | 
 <a href="?action=search">Rechercher un membre</a> |
+<a href="?action=dtcsync_list">Sync DTC</a> |
 <a href="?action=stats">Statistiques</a>
 {if isset($login)}
 | <a href="?action=do_logout">Déconnexion</a>


_______________________________________________
Gdtc-commits mailing list
[email protected]
https://mail.gna.org/listinfo/gdtc-commits

Reply via email to