[ Index ]
 

Code source de eGroupWare 1.2.106-2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/admin/inc/ -> class.uiasyncservice.inc.php (source)

   1  <?php
   2      /**************************************************************************\
   3      * eGroupWare Admin - Timed Asynchron Services for eGroupWare               *
   4      * Written by Ralf Becker <RalfBecker@outdoor-training.de>                  *
   5      * Class to admin cron-job like timed calls of eGroupWare methods           *
   6      * -------------------------------------------------------------------------*
   7      * This library is part of the eGroupWare API                               *
   8      * http://www.egroupware.org/                                               *
   9      * ------------------------------------------------------------------------ *
  10      * This library is free software; you can redistribute it and/or modify it  *
  11      * under the terms of the GNU Lesser General Public License as published by *
  12      * the Free Software Foundation; either version 2.1 of the License,         *
  13      * or any later version.                                                    *
  14      * This library is distributed in the hope that it will be useful, but      *
  15      * WITHOUT ANY WARRANTY; without even the implied warranty of               *
  16      * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     *
  17      * See the GNU Lesser General Public License for more details.              *
  18      * You should have received a copy of the GNU Lesser General Public License *
  19      * along with this library; if not, write to the Free Software Foundation,  *
  20      * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA            *
  21      \**************************************************************************/
  22  
  23      /* $Id: class.uiasyncservice.inc.php 20295 2006-02-15 12:31:25Z  $ */
  24  
  25      class uiasyncservice
  26      {
  27          var $public_functions = array(
  28              'index' => True,
  29          );
  30  		function uiasyncservice()
  31          {
  32              if (!is_object($GLOBALS['egw']->asyncservice))
  33              {
  34                  $GLOBALS['egw']->asyncservice =& CreateObject('phpgwapi.asyncservice');
  35              }
  36          }
  37  
  38  		function index()
  39          {
  40              if ($GLOBALS['egw']->acl->check('asyncservice_access',1,'admin'))
  41              {
  42                  $GLOBALS['egw']->redirect_link('/index.php');
  43              }
  44              $GLOBALS['egw_info']['flags']['app_header'] = lang('Admin').' - '.lang('Asynchronous timed services');
  45              if(!@is_object($GLOBALS['egw']->js))
  46              {
  47                  $GLOBALS['egw']->js =& CreateObject('phpgwapi.javascript');
  48              }
  49              $GLOBALS['egw']->js->validate_file('jscode','openwindow','admin');
  50              $GLOBALS['egw']->common->egw_header();
  51              echo parse_navbar();
  52  
  53              $async = $GLOBALS['egw']->asyncservice;    // use an own instance, as we might set debug=True
  54  
  55              $async->debug = !!$_POST['debug'];
  56  
  57              $units = array(
  58                  'year'  => lang('Year'),
  59                  'month' => lang('Month'),
  60                  'day'   => lang('Day'),
  61                  'dow'   => lang('Day of week<br>(0-6, 0=Sun)'),
  62                  'hour'  => lang('Hour<br>(0-23)'),
  63                  'min'   => lang('Minute')
  64              );
  65  
  66              if ($_POST['send'] || $_POST['test'] || $_POST['cancel'] || $_POST['install'] || $_POST['deinstall'] || $_POST['update'] || isset($_POST['asyncservice']))
  67              {
  68                  $times = array();
  69                  foreach($units as $u => $ulabel)
  70                  {
  71                      if ($_POST[$u] !== '')
  72                      {
  73                          $times[$u] = $_POST[$u];
  74                      }
  75                  }
  76  
  77                  if ($_POST['test'])
  78                  {
  79                      if (!$async->set_timer($times,'test','admin.uiasyncservice.test',$GLOBALS['egw_info']['user']['email']))
  80                      {
  81                          echo '<p><b>'.lang("Error setting timer, wrong syntax or maybe there's one already running !!!")."</b></p>\n";
  82                      }
  83                  }
  84                  if ($_POST['cancel'])
  85                  {
  86                      if (!$async->cancel_timer('test'))
  87                      {
  88                          echo '<p><b>'.lang("Error canceling timer, maybe there's none set !!!")."</b></p>\n";
  89                      }
  90                  }
  91                  if ($_POST['install'] || $_POST['deinstall'])
  92                  {
  93                      if (!($install = $async->install($_POST['install'] ? $times : False)))
  94                      {
  95                          echo '<p><b>'.lang('Error: %1 not found or other error !!!',$async->crontab)."</b></p>\n";
  96                      }
  97                      $_POST['asyncservice'] = $_POST['deinstall'] ? 'fallback' : 'crontab';
  98                  }
  99              }
 100              else
 101              {
 102                  $times = array('min' => '*/5');        // set some default
 103              }
 104              echo '<form action="'.$GLOBALS['egw']->link('/index.php',array('menuaction'=>'admin.uiasyncservice.index')).'" method="POST">'."\n<p>";
 105              echo '<div style="text-align: left; margin: 10px;">'."\n";
 106  
 107              $last_run = $async->last_check_run();
 108              $lr_date = $last_run['end'] ? $GLOBALS['egw']->common->show_date($last_run['end']) : lang('never');
 109              echo '<p><b>'.lang('Async services last executed').'</b>: '.$lr_date.' ('.$last_run['run_by'].")</p>\n<hr>\n";
 110  
 111              if (isset($_POST['asyncservice']) && $_POST['asyncservice'] != $GLOBALS['egw_info']['server']['asyncservice'])
 112              {
 113                  $config =& CreateObject('phpgwapi.config','phpgwapi');
 114                  $config->read_repository();
 115                  $config->value('asyncservice',$GLOBALS['egw_info']['server']['asyncservice']=$_POST['asyncservice']);
 116                  $config->save_repository();
 117                  unset($config);
 118              }
 119              if (!$async->only_fallback)
 120              {
 121                  $installed = $async->installed();
 122                  if (is_array($installed) && isset($installed['cronline']))
 123                  {
 124                      $async_use['cron'] = lang('crontab only (recomended)');
 125                  }
 126              }
 127              $async_use['']    = lang('fallback (after each pageview)');
 128              $async_use['off'] = lang('disabled (not recomended)');
 129              echo '<p><b>'.lang('Run Asynchronous services').'</b>'.
 130                  ' <select name="asyncservice" onChange="this.form.submit();">';
 131              foreach ($async_use as $key => $label)
 132              {
 133                  $selected = $key == $GLOBALS['egw_info']['server']['asyncservice'] ? ' selected' : ''; 
 134                  echo "<option value=\"$key\"$selected>$label</option>\n";
 135              }
 136              echo "</select>\n";
 137  
 138              if (is_array($installed) && isset($installed['cronline']))
 139              {
 140                  echo ' &nbsp; <input type="submit" name="deinstall" value="'.lang('Deinstall crontab')."\">\n";
 141              }
 142              echo "</p>\n";
 143  
 144              if ($async->only_fallback)
 145              {
 146                  echo '<p>'.lang('Under windows you need to install the asyncservice %1manually%2 or use the fallback mode. Fallback means the jobs get only checked after each page-view !!!','<a href="http://www.egroupware.org/wiki/TimedAsyncServicesWindows" target="_blank">','</a>')."</p>\n";
 147              }
 148              else
 149              {
 150                  echo '<p>'.lang('Installed crontab').": \n";
 151  
 152                  if (is_array($installed) && isset($installed['cronline']))
 153                  {
 154                      echo "$installed[cronline]</p>";
 155                  }
 156                  elseif ($installed === 0)
 157                  {
 158                      echo '<b>'.lang('%1 not found or not executable !!!',$async->crontab)."</b></p>\n";
 159                  }
 160                  else
 161                  {
 162                      echo '<b>'.lang('asyncservices not yet installed or other error (%1) !!!',$installed['error'])."</b></p>\n";
 163                  }
 164                  echo '<p><input type="submit" name="install" value="'.lang('Install crontab')."\">\n".
 165                      lang("for the times below (empty values count as '*', all empty = every minute)")."</p>\n";
 166              }
 167  
 168              echo "<hr><table border=0><tr>\n";
 169              foreach ($units as $u => $ulabel)
 170              {
 171                  echo " <td>$ulabel</td><td><input name=\"$u\" value=\"$times[$u]\" size=5> &nbsp; </td>\n";
 172              }
 173              echo "</tr><tr>\n <td colspan=4>\n";
 174              echo ' <input type="submit" name="send" value="'.lang('Calculate next run').'"></td>'."\n";
 175              echo ' <td colspan="8"><input type="checkbox" name="debug" value="1"'.($_POST['debug'] ? ' checked' : '')."> \n".
 176                  lang('Enable debug-messages')."</td>\n</tr></table>\n";
 177  
 178              if ($_POST['send'])
 179              {
 180                  $next = $async->next_run($times,True);
 181  
 182                  echo "<p>asyncservice::next_run(";print_r($times);echo")=".($next === False ? 'False':"'$next'=".$GLOBALS['egw']->common->show_date($next))."</p>\n";
 183              }
 184              echo '<hr><p><input type="submit" name="cancel" value="'.lang('Cancel TestJob!')."\"> &nbsp;\n";
 185              echo '<input type="submit" name="test" value="'.lang('Start TestJob!')."\">\n";
 186              echo lang('for the times above')."</p>\n";
 187              echo '<p>'.lang('The TestJob sends you a mail everytime it is called.')."</p>\n";
 188  
 189              echo '<hr><p><b>'.lang('Jobs').":</b>\n";
 190              if ($jobs = $async->read('%'))
 191              {
 192                  echo "<table border=1>\n<tr>\n<th>Id</th><th>".lang('Next run').'</th><th>'.lang('Times').'</th><th>'.lang('Method').'</th><th>'.lang('Data')."</th><th>".lang('LoginID')."</th></tr>\n";
 193                  foreach($jobs as $job)
 194                  {
 195                      echo "<tr>\n<td>$job[id]</td><td>".$GLOBALS['egw']->common->show_date($job['next'])."</td><td>";
 196                      print_r($job['times']); 
 197                      echo "</td><td>$job[method]</td><td>"; 
 198                      print_r($job['data']); 
 199                      echo "</td><td align=\"center\">".$GLOBALS['egw']->accounts->id2name($job[account_id])."</td></tr>\n"; 
 200                  }
 201                  echo "</table>\n";
 202              }
 203              else
 204              {
 205                  echo lang('No jobs in the database !!!')."</p>\n";
 206              }
 207              echo '<p><input type="submit" name="update" value="'.lang('Update').'"></p>'."\n";
 208              echo "</form>\n";
 209              
 210          }
 211          
 212  		function test($to)
 213          {
 214              if (!is_object($GLOBALS['egw']->send))
 215              {
 216                  $GLOBALS['egw']->send =& CreateObject('phpgwapi.send');
 217              }
 218              $returncode = $GLOBALS['egw']->send->msg('email',$to,$subject='Asynchronous timed services','Greatings from cron ;-)');
 219  
 220              if (!$returncode)    // not nice, but better than failing silently
 221              {
 222                  echo "<p>bocalendar::send_update: sending message to '$to' subject='$subject' failed !!!<br>\n"; 
 223                  echo $GLOBALS['egw']->send->err['desc']."</p>\n";
 224              }
 225              //print_r($GLOBALS['egw_info']['user']);
 226          }
 227      }


Généré le : Sun Feb 25 17:20:01 2007 par Balluche grâce à PHPXref 0.7