diff --git a/admin/inc/class.uiasyncservice.inc.php b/admin/inc/class.uiasyncservice.inc.php index 54bf2c06d2..4b101f41f8 100644 --- a/admin/inc/class.uiasyncservice.inc.php +++ b/admin/inc/class.uiasyncservice.inc.php @@ -1,213 +1,203 @@ * - * Class to admin cron-job like timed calls of eGroupWare methods * - * -------------------------------------------------------------------------* - * This library is part of the eGroupWare API * - * http://www.egroupware.org/ * - * ------------------------------------------------------------------------ * - * This library is free software; you can redistribute it and/or modify it * - * under the terms of the GNU Lesser General Public License as published by * - * the Free Software Foundation; either version 2.1 of the License, * - * or any later version. * - * This library 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 Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public License * - * along with this library; if not, write to the Free Software Foundation, * - * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - \**************************************************************************/ +/** + * eGgroupWare admin - Timed Asynchron Services + * + * @link http://www.egroupware.org + * @author Ralf Becker + * @package admin + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @version $Id$ + */ - /* $Id$ */ +/** + * Class to admin cron-job like timed calls of eGroupWare methods + */ +class uiasyncservice +{ + var $public_functions = array( + 'index' => True, + ); - class uiasyncservice + function index() { - var $public_functions = array( - 'index' => True, + if ($GLOBALS['egw']->acl->check('asyncservice_access',1,'admin')) + { + $GLOBALS['egw']->redirect_link('/index.php'); + } + $GLOBALS['egw_info']['flags']['app_header'] = lang('Admin').' - '.lang('Asynchronous timed services'); + + $GLOBALS['egw']->js->validate_file('jscode','openwindow','admin'); + $GLOBALS['egw']->common->egw_header(); + echo parse_navbar(); + + $async = $GLOBALS['egw']->asyncservice; // use an own instance, as we might set debug=True + + $async->debug = !!$_POST['debug']; + + $units = array( + 'year' => lang('Year'), + 'month' => lang('Month'), + 'day' => lang('Day'), + 'dow' => lang('Day of week
(0-6, 0=Sun)'), + 'hour' => lang('Hour
(0-23)'), + 'min' => lang('Minute') ); - function index() + if ($_POST['send'] || $_POST['test'] || $_POST['cancel'] || $_POST['install'] || $_POST['deinstall'] || $_POST['update'] || isset($_POST['asyncservice'])) { - if ($GLOBALS['egw']->acl->check('asyncservice_access',1,'admin')) + $times = array(); + foreach($units as $u => $ulabel) { - $GLOBALS['egw']->redirect_link('/index.php'); - } - $GLOBALS['egw_info']['flags']['app_header'] = lang('Admin').' - '.lang('Asynchronous timed services'); - - $GLOBALS['egw']->js->validate_file('jscode','openwindow','admin'); - $GLOBALS['egw']->common->egw_header(); - echo parse_navbar(); - - $async = $GLOBALS['egw']->asyncservice; // use an own instance, as we might set debug=True - - $async->debug = !!$_POST['debug']; - - $units = array( - 'year' => lang('Year'), - 'month' => lang('Month'), - 'day' => lang('Day'), - 'dow' => lang('Day of week
(0-6, 0=Sun)'), - 'hour' => lang('Hour
(0-23)'), - 'min' => lang('Minute') - ); - - if ($_POST['send'] || $_POST['test'] || $_POST['cancel'] || $_POST['install'] || $_POST['deinstall'] || $_POST['update'] || isset($_POST['asyncservice'])) - { - $times = array(); - foreach($units as $u => $ulabel) + if ($_POST[$u] !== '') { - if ($_POST[$u] !== '') - { - $times[$u] = $_POST[$u]; - } - } - - if ($_POST['test']) - { - if (!$async->set_timer($times,'test','admin.uiasyncservice.test',$GLOBALS['egw_info']['user']['email'])) - { - echo '

'.lang("Error setting timer, wrong syntax or maybe there's one already running !!!")."

\n"; - } - } - if ($_POST['cancel']) - { - if (!$async->cancel_timer('test')) - { - echo '

'.lang("Error canceling timer, maybe there's none set !!!")."

\n"; - } - } - if ($_POST['install'] || $_POST['deinstall']) - { - if (!($install = $async->install($_POST['install'] ? $times : False))) - { - echo '

'.lang('Error: %1 not found or other error !!!',$async->crontab)."

\n"; - } - $_POST['asyncservice'] = $_POST['deinstall'] ? 'fallback' : 'crontab'; + $times[$u] = $_POST[$u]; } } - else - { - $times = array('min' => '*/5'); // set some default - } - echo '
'."\n

"; - echo '

'."\n"; - $last_run = $async->last_check_run(); - $lr_date = $last_run['end'] ? $GLOBALS['egw']->common->show_date($last_run['end']) : lang('never'); - echo '

'.lang('Async services last executed').': '.$lr_date.' ('.$last_run['run_by'].")

\n
\n"; - - if (isset($_POST['asyncservice']) && $_POST['asyncservice'] != $GLOBALS['egw_info']['server']['asyncservice']) + if ($_POST['test']) { - $config =& CreateObject('phpgwapi.config','phpgwapi'); - $config->read_repository(); - $config->value('asyncservice',$GLOBALS['egw_info']['server']['asyncservice']=$_POST['asyncservice']); - $config->save_repository(); - unset($config); - } - if (!$async->only_fallback) - { - $installed = $async->installed(); - if (is_array($installed) && isset($installed['cronline'])) + if (!$async->set_timer($times,'test','admin.uiasyncservice.test',$GLOBALS['egw_info']['user']['email'])) { - $async_use['cron'] = lang('crontab only (recomended)'); + echo '

'.lang("Error setting timer, wrong syntax or maybe there's one already running !!!")."

\n"; } } - $async_use[''] = lang('fallback (after each pageview)'); - $async_use['off'] = lang('disabled (not recomended)'); - echo '

'.lang('Run Asynchronous services').''. - ' \n"; + if ($_POST['install'] || $_POST['deinstall']) + { + if (!($install = $async->install($_POST['install'] ? $times : False))) + { + echo '

'.lang('Error: %1 not found or other error !!!',$async->crontab)."

\n"; + } + $_POST['asyncservice'] = $_POST['deinstall'] ? 'fallback' : 'crontab'; + } + } + else + { + $times = array('min' => '*/5'); // set some default + } + echo ''."\n

"; + echo '

'."\n"; + + $last_run = $async->last_check_run(); + $lr_date = $last_run['end'] ? $GLOBALS['egw']->common->show_date($last_run['end']) : lang('never'); + echo '

'.lang('Async services last executed').': '.$lr_date.' ('.$last_run['run_by'].")

\n
\n"; + + if (isset($_POST['asyncservice']) && $_POST['asyncservice'] != $GLOBALS['egw_info']['server']['asyncservice']) + { + $config =& CreateObject('phpgwapi.config','phpgwapi'); + $config->read_repository(); + $config->value('asyncservice',$GLOBALS['egw_info']['server']['asyncservice']=$_POST['asyncservice']); + $config->save_repository(); + unset($config); + } + if (!$async->only_fallback) + { + $installed = $async->installed(); + if (is_array($installed) && isset($installed['cronline'])) + { + $async_use['cron'] = lang('crontab only (recomended)'); + } + } + $async_use[''] = lang('fallback (after each pageview)'); + $async_use['off'] = lang('disabled (not recomended)'); + echo '

'.lang('Run Asynchronous services').''. + ' \n"; + + if (is_array($installed) && isset($installed['cronline'])) + { + echo '   \n"; + } + echo "

\n"; + + if ($async->only_fallback) + { + echo '

'.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 !!!','','')."

\n"; + } + else + { + echo '

'.lang('Installed crontab').": \n"; if (is_array($installed) && isset($installed['cronline'])) { - echo '   \n"; + echo "$installed[cronline]

"; } - echo "

\n"; - - if ($async->only_fallback) + elseif ($installed === 0) { - echo '

'.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 !!!','','')."

\n"; + echo ''.lang('%1 not found or not executable !!!',$async->crontab)."

\n"; } else { - echo '

'.lang('Installed crontab').": \n"; - - if (is_array($installed) && isset($installed['cronline'])) - { - echo "$installed[cronline]

"; - } - elseif ($installed === 0) - { - echo ''.lang('%1 not found or not executable !!!',$async->crontab)."

\n"; - } - else - { - echo ''.lang('asyncservices not yet installed or other error (%1) !!!',$installed['error'])."

\n"; - } - echo '

\n". - lang("for the times below (empty values count as '*', all empty = every minute)")."

\n"; + echo ''.lang('asyncservices not yet installed or other error (%1) !!!',$installed['error'])."

\n"; } - - echo "
\n"; - foreach ($units as $u => $ulabel) - { - echo " \n"; - } - echo "\n '."\n"; - echo ' \n
$ulabel  
\n"; - echo ' \n". - lang('Enable debug-messages')."
\n"; - - if ($_POST['send']) - { - $next = $async->next_run($times,True); - - echo "

asyncservice::next_run(";print_r($times);echo")=".($next === False ? 'False':"'$next'=".$GLOBALS['egw']->common->show_date($next))."

\n"; - } - echo '

 \n"; - echo '\n"; - echo lang('for the times above')."

\n"; - echo '

'.lang('The TestJob sends you a mail everytime it is called.')."

\n"; - - echo '

'.lang('Jobs').":\n"; - if ($jobs = $async->read('%')) - { - echo "\n\n\n"; - foreach($jobs as $job) - { - echo "\n\n"; - } - echo "
Id".lang('Next run').''.lang('Times').''.lang('Method').''.lang('Data')."".lang('LoginID')."
$job[id]".$GLOBALS['egw']->common->show_date($job['next']).""; - print_r($job['times']); - echo "$job[method]"; - print_r($job['data']); - echo "".$GLOBALS['egw']->accounts->id2name($job[account_id])."
\n"; - } - else - { - echo lang('No jobs in the database !!!')."

\n"; - } - echo '

'."\n"; - echo "\n"; - + echo '

\n". + lang("for the times below (empty values count as '*', all empty = every minute)")."

\n"; } - - function test($to) + + echo "
\n"; + foreach ($units as $u => $ulabel) { - $returncode = $GLOBALS['egw']->send->msg('email',$to,$subject='Asynchronous timed services','Greatings from cron ;-)'); - - if (!$returncode) // not nice, but better than failing silently - { - echo "

bocalendar::send_update: sending message to '$to' subject='$subject' failed !!!
\n"; - echo $GLOBALS['egw']->send->err['desc']."

\n"; - } - //print_r($GLOBALS['egw_info']['user']); + echo " \n"; } + echo "\n '."\n"; + echo ' \n
$ulabel  
\n"; + echo ' \n". + lang('Enable debug-messages')."
\n"; + + if ($_POST['send']) + { + $next = $async->next_run($times,True); + + echo "

asyncservice::next_run(";print_r($times);echo")=".($next === False ? 'False':"'$next'=".$GLOBALS['egw']->common->show_date($next))."

\n"; + } + echo '

 \n"; + echo '\n"; + echo lang('for the times above')."

\n"; + echo '

'.lang('The TestJob sends you a mail everytime it is called.')."

\n"; + + echo '

'.lang('Jobs').":\n"; + if ($jobs = $async->read('%')) + { + echo "\n\n\n"; + foreach($jobs as $job) + { + echo "\n\n"; + } + echo "
Id".lang('Next run').''.lang('Times').''.lang('Method').''.lang('Data')."".lang('LoginID')."
$job[id]".$GLOBALS['egw']->common->show_date($job['next']).""; + print_r($job['times']); + echo "$job[method]"; + print_r($job['data']); + echo "".$GLOBALS['egw']->accounts->id2name($job[account_id])."
\n"; + } + else + { + echo lang('No jobs in the database !!!')."

\n"; + } + echo '

'."\n"; + echo "\n"; + } + + function test($to) + { + $returncode = $GLOBALS['egw']->send->msg('email',$to,$subject='Asynchronous timed services','Greetings from cron ;-)'); + + if (!$returncode) // not nice, but better than failing silently + { + echo "

bocalendar::send_update: sending message to '$to' subject='$subject' failed !!!
\n"; + echo $GLOBALS['egw']->send->err['desc']."

\n"; + } + //print_r($GLOBALS['egw_info']['user']); + } +}