list.php

00001 <?php
00002 /* Copyright (C) 2012      Nicolas Villa aka Boyquotes http://informetic.fr
00003  * Copyright (C) 2013      Florian Henry <florian.henry@open-concept.pro>
00004  * Copyright (C) 2013      Laurent Destailleur <eldy@users.srouceforge.net>
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 3 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00018  */
00019 
00027 require '../main.inc.php';
00028 require_once(DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php");
00029 require_once DOL_DOCUMENT_ROOT."/cron/class/cronjob.class.php";
00030 require_once DOL_DOCUMENT_ROOT.'/core/lib/cron.lib.php';
00031 
00032 $langs->load("admin");
00033 $langs->load("cron");
00034 
00035 if (!$user->rights->cron->read) accessforbidden();
00036 
00037 
00038 /*
00039  * Actions
00040  */
00041 
00042 $action=GETPOST('action','alpha');
00043 $confirm=GETPOST('confirm','alpha');
00044 $id=GETPOST('id','int');
00045 
00046 $sortorder=GETPOST('sortorder','alpha');
00047 $sortfield=GETPOST('sortfield','alpha');
00048 $page=GETPOST('page','int');
00049 $status=GETPOST('status','int');
00050 
00051 //Search criteria
00052 $search_label=GETPOST("search_label",'alpha');
00053 
00054 if (empty($sortorder)) $sortorder="DESC";
00055 if (empty($sortfield)) $sortfield="t.datenextrun";
00056 if (empty($arch)) $arch = 0;
00057 if ($page == -1) {
00058   $page = 0 ;
00059 }
00060 
00061 $limit = $conf->global->MAIN_SIZE_LISTE_LIMIT;
00062 $offset = $limit * $page ;
00063 $pageprev = $page - 1;
00064 $pagenext = $page + 1;
00065 
00066 // Do we click on purge search criteria ?
00067 if (GETPOST("button_removefilter"))
00068 {
00069   $search_label='';
00070   $status=-1;
00071 }
00072 
00073 $filter=array();
00074 if (!empty($search_label))
00075 {
00076   $filter['t.label']=$search_label;
00077 }
00078 
00079 // Delete jobs
00080 if ($action == 'confirm_delete' && $confirm == "yes" && $user->rights->cron->delete){
00081 
00082   //Delete cron task
00083   $object = new Cronjob($db);
00084   $object->id=$id;
00085   $result = $object->delete($user);
00086 
00087   if ($result < 0) {
00088     setEventMessage($object->error,'errors');
00089   }
00090 }
00091 
00092 // Execute jobs
00093 if ($action == 'confirm_execute' && $confirm == "yes" && $user->rights->cron->execute){
00094 
00095   //Execute jobs
00096   $object = new Cronjob($db);
00097   $job = $object->fetch($id);
00098 
00099   $result = $object->run_jobs($user->login);
00100   if ($result < 0) {
00101     setEventMessage($object->error,'errors');
00102   }
00103 
00104   header("Location: ".DOL_URL_ROOT.'/cron/list.php?status=-1');   // Make a call to avoid to run twice job when using back
00105   exit;
00106 }
00107 
00108 
00109 /*
00110  * View
00111  */
00112 
00113 $form = new Form($db);
00114 
00115 $pagetitle=$langs->trans("CronList");
00116 
00117 llxHeader('',$pagetitle);
00118 
00119 print_fiche_titre($pagetitle,'','setup');
00120 
00121 print $langs->trans('CronInfo');
00122 
00123 if ($action == 'delete')
00124 {
00125   print $form->formconfirm($_SERVER['PHP_SELF']."?id=".$id.'&status='.$status,$langs->trans("CronDelete"),$langs->trans("CronConfirmDelete"),"confirm_delete",'','',1);
00126   
00127 }
00128 
00129 if ($action == 'execute')
00130 {
00131   print $form->formconfirm($_SERVER['PHP_SELF']."?id=".$id.'&status='.$status,$langs->trans("CronExecute"),$langs->trans("CronConfirmExecute"),"confirm_execute",'','',1);
00132   
00133 }
00134 
00135 // liste des jobs creer
00136 $object = new Cronjob($db);
00137 $result=$object->fetch_all($sortorder, $sortfield, $limit, $offset, $status, $filter);
00138 if ($result < 0)
00139 {
00140   setEventMessage($object->error,'errors');
00141 }
00142 
00143 
00144 print "<br><br>";
00145 
00146 
00147 print '<form method="GET" action="'.$url_form.'" name="search_form">'."\n";
00148 print '<input type="hidden" name="status" value="'.$status.'" >';
00149 
00150 print '<table width="100%" class="noborder">';
00151 print '<tr class="liste_titre">';
00152 $arg_url='&page='.$page.'&status='.$status.'&search_label='.$search_label;
00153 print_liste_field_titre($langs->trans("CronLabel"),$_SERVEUR['PHP_SELF'],"t.label","",$arg_url,'',$sortfield,$sortorder);
00154 print_liste_field_titre($langs->trans("CronTask"),'','',"",$arg_url,'',$sortfield,$sortorder);
00155 print_liste_field_titre($langs->trans("CronDtStart"),$_SERVEUR['PHP_SELF'],"t.datestart","",$arg_url,'',$sortfield,$sortorder);
00156 print_liste_field_titre($langs->trans("CronDtEnd"),$_SERVEUR['PHP_SELF'],"t.dateend","",$arg_url,'',$sortfield,$sortorder);
00157 print_liste_field_titre($langs->trans("CronDtLastLaunch"),$_SERVEUR['PHP_SELF'],"t.datelastrun","",$arg_url,'',$sortfield,$sortorder);
00158 print_liste_field_titre($langs->trans("CronDtNextLaunch"),$_SERVEUR['PHP_SELF'],"t.datenextrun","",$arg_url,'',$sortfield,$sortorder);
00159 print_liste_field_titre($langs->trans("CronFrequency"),'',"","",$arg_url,'',$sortfield,$sortorder);
00160 print_liste_field_titre($langs->trans("CronNbRun"),$_SERVEUR['PHP_SELF'],"t.nbrun","",$arg_url,'',$sortfield,$sortorder);
00161 print_liste_field_titre($langs->trans("CronLastResult"),$_SERVEUR['PHP_SELF'],"t.lastresult","",$arg_url,'',$sortfield,$sortorder);
00162 print_liste_field_titre($langs->trans("CronLastOutput"),$_SERVEUR['PHP_SELF'],"t.lastoutput","",$arg_url,'',$sortfield,$sortorder);
00163 print_liste_field_titre($langs->trans("Enabled"),$_SERVEUR['PHP_SELF'],"t.status","",$arg_url,'align="center"',$sortfield,$sortorder);
00164 print '<td></td>';
00165 print '</tr>';
00166 
00167 print '<tr class="liste_titre">';
00168 
00169 print '<td class="liste_titre">';
00170 print '<input type="text" class="flat" name="search_label" value="'.$search_label.'" size="10">';
00171 print '</td>';
00172 print '<td>&nbsp;</td>';
00173 print '<td>&nbsp;</td>';
00174 print '<td>&nbsp;</td>';
00175 print '<td>&nbsp;</td>';
00176 print '<td>&nbsp;</td>';
00177 print '<td>&nbsp;</td>';
00178 print '<td>&nbsp;</td>';
00179 print '<td>&nbsp;</td>';
00180 print '<td>&nbsp;</td>';
00181 print '<td class="liste_titre" align="center">';
00182 print $form->selectarray('status', array('0'=>$langs->trans("No"),'1'=>$langs->trans("Yes")), $status, 1);
00183 print '</td><td class="liste_titre" align="right">';
00184 print '&nbsp;';
00185 print '<input class="liste_titre" type="image" src="'.img_picto($langs->trans("Search"),'search.png','','',1).'" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
00186 print '&nbsp; ';
00187 print '<input type="image" class="liste_titre" name="button_removefilter" src="'.img_picto($langs->trans("Search"),'searchclear.png','','',1).'" value="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'" title="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'">';
00188 print '</td>';
00189 
00190 print '</tr>';
00191 
00192 
00193 if (count($object->lines) > 0)
00194 {
00195   // Loop on each active job
00196   $style='impair';
00197   foreach($object->lines as $line)
00198   {
00199     // title profil
00200     if ($style=='pair') {$style='impair';}
00201     else {$style='pair';}
00202 
00203     print '<tr class="'.$style.'">';
00204 
00205     print '<td>';
00206     if(!empty($line->label)) {
00207       print '<a href="'.DOL_URL_ROOT.'/cron/card.php?id='.$line->id.'">'.$line->label.'</a>';
00208     }
00209     else {
00210       print $langs->trans('CronNone');
00211     }
00212     print '</td>';
00213 
00214     print '<td>';
00215     if ($line->jobtype=='method') {
00216       print $langs->trans('CronModule').':'.$line->module_name.'<BR>';
00217       print $langs->trans('CronClass').':'. $line->classesname.'<BR>';
00218       print $langs->trans('CronObject').':'. $line->objectname.'<BR>';
00219       print $langs->trans('CronMethod').':'. $line->methodename;
00220       if(!empty($line->params)) {
00221         print '<BR/>'.$langs->trans('CronArgs').':'. $line->params;
00222       }
00223 
00224     }elseif ($line->jobtype=='command') {
00225       print $langs->trans('CronCommand').':'. dol_trunc($line->command);
00226       if(!empty($line->params)) {
00227         print '<BR/>'.$langs->trans('CronArgs').':'. $line->params;
00228       }
00229     }
00230     print '</td>';
00231 
00232     print '<td>';
00233     if(!empty($line->datestart)) {print dol_print_date($line->datestart,'dayhour');} else {print $langs->trans('CronNone');}
00234     print '</td>';
00235 
00236     print '<td>';
00237     if(!empty($line->dateend)) {print dol_print_date($line->dateend,'dayhour');} else {print $langs->trans('CronNone');}
00238     print '</td>';
00239 
00240     print '<td>';
00241     if(!empty($line->datelastrun)) {print dol_print_date($line->datelastrun,'dayhour');} else {print $langs->trans('CronNone');}
00242     print '</td>';
00243 
00244     print '<td>';
00245     if(!empty($line->datenextrun)) {print dol_print_date($line->datenextrun,'dayhour');} else {print $langs->trans('CronNone');}
00246     print '</td>';
00247 
00248     print '<td>';
00249     if($line->unitfrequency == "60") print $langs->trans('CronEach')." ".($line->frequency/$line->unitfrequency)." ".$langs->trans('Minutes');
00250     if($line->unitfrequency == "3600") print $langs->trans('CronEach')." ".($line->frequency/$line->unitfrequency)." ".$langs->trans('Hours');
00251     if($line->unitfrequency == "86400") print $langs->trans('CronEach')." ".($line->frequency/$line->unitfrequency)." ".$langs->trans('Days');
00252     if($line->unitfrequency == "604800") print $langs->trans('CronEach')." ".($line->frequency/$line->unitfrequency)." ".$langs->trans('Weeks');
00253     print '</td>';
00254 
00255     print '<td>';
00256     if(!empty($line->nbrun)) {print $line->nbrun;} else {print '0';}
00257     print '</td>';
00258 
00259     print '<td>';
00260     if(!empty($line->lastresult)) {print dol_trunc($line->lastresult);} else {print $langs->trans('CronNone');}
00261     print '</td>';
00262 
00263     print '<td>';
00264     if(!empty($line->lastoutput)) {print dol_trunc(nl2br($line->lastoutput),100);} else {print $langs->trans('CronNone');}
00265     print '</td>';
00266 
00267     print '<td align="center">';
00268     print yn($line->status);
00269     print '</td>';
00270 
00271     print '<td align="right">';
00272     if ($user->rights->cron->delete) {
00273       print "<a href=\"".$_SERVER["PHP_SELF"]."?id=".$line->id."&status=".$status."&action=delete\" title=\"".$langs->trans('CronDelete')."\">".img_delete()."</a> &nbsp;";
00274     } else {
00275       print "<a href=\"#\" title=\"".$langs->trans('NotEnoughPermissions')."\">".img_delete()."</a> &nbsp; ";
00276     }
00277     if ($user->rights->cron->execute) {
00278       print "<a href=\"".$_SERVER["PHP_SELF"]."?id=".$line->id."&status=".$status."&action=execute\" title=\"".$langs->trans('CronExecute')."\">".img_picto('',"play")."</a>";
00279     } else {
00280       print "<a href=\"#\" title=\"".$langs->trans('NotEnoughPermissions')."\">".img_picto('',"execute")."</a>";
00281     }
00282     print '</td>';
00283 
00284     print '</tr>';
00285   }
00286 }
00287 else
00288 {
00289   print '<tr><td colspan="8">'.$langs->trans('CronNoJobs').'</td></tr>';
00290 }
00291 
00292 print '</table>';
00293 
00294 print '</from>';
00295 
00296 
00297 
00298 print "\n<div class=\"tabsAction\">\n";
00299 
00300 if (! $user->rights->cron->create)
00301 {
00302   print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("New").'</a>';
00303 }
00304 else
00305 {
00306   print '<a class="butAction" href="'.DOL_URL_ROOT.'/cron/card.php?action=create">'.$langs->trans("New").'</a>';
00307 }
00308 
00309 print '</div>';
00310 
00311 print '<br>';
00312 
00313 
00314 dol_print_cron_urls();
00315 
00316 
00317 llxFooter();
00318 
00319 $db->close();
00320 ?>