cron.lib.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /* Copyright (C) 2012 Nicolas Villa aka Boyquotes http://informetic.fr
  3. * Copyright (C) 2013 Florian Henry <florian.henry@opn-concept.pro>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file core/lib/cron.lib.php
  20. * \brief Function for module cron
  21. * \ingroup cron
  22. */
  23. /**
  24. * Return array of tabs to used on pages to setup cron module.
  25. *
  26. * @return array Array of tabs
  27. */
  28. function cronadmin_prepare_head()
  29. {
  30. global $langs, $conf, $user;
  31. $h = 0;
  32. $head = array();
  33. $head[$h][0] = dol_buildpath('/cron/admin/cron.php', 1);
  34. $head[$h][1] = $langs->trans("Miscellaneous");
  35. $head[$h][2] = 'setup';
  36. $h++;
  37. complete_head_from_modules($conf, $langs, null, $head, $h, 'cronadmin');
  38. complete_head_from_modules($conf, $langs, null, $head, $h, 'cronadmin', 'remove');
  39. return $head;
  40. }
  41. /**
  42. * Return array of tabs to used on a cron job
  43. *
  44. * @param Object $object Object cron
  45. * @return array Array of tabs
  46. */
  47. function cron_prepare_head($object)
  48. {
  49. global $langs, $conf, $user;
  50. $h = 0;
  51. $head = array();
  52. $head[$h][0] = dol_buildpath('/cron/card.php', 1).'?id='.$object->id;
  53. $head[$h][1] = $langs->trans("CronTask");
  54. $head[$h][2] = 'card';
  55. $h++;
  56. $head[$h][0] = dol_buildpath('/cron/info.php', 1).'?id='.$object->id;
  57. $head[$h][1] = $langs->trans("Info");
  58. $head[$h][2] = 'info';
  59. $h++;
  60. complete_head_from_modules($conf, $langs, $object, $head, $h, 'cron');
  61. complete_head_from_modules($conf, $langs, $object, $head, $h, 'cron', 'remove');
  62. return $head;
  63. }
  64. /**
  65. * Show information with URLs to launch jobs
  66. *
  67. * @return int 0
  68. */
  69. function dol_print_cron_urls()
  70. {
  71. global $conf, $langs, $user;
  72. global $dolibarr_main_url_root;
  73. // Define $urlwithroot
  74. $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
  75. $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
  76. //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
  77. // Cron launch
  78. print '<u>'.$langs->trans("URLToLaunchCronJobs").':</u><br>';
  79. $url=$urlwithroot.'/public/cron/cron_run_jobs.php'.(empty($conf->global->CRON_KEY)?'':'?securitykey='.$conf->global->CRON_KEY.'&').'userlogin='.$user->login;
  80. print img_picto('','object_globe.png').' <a href="'.$url.'" target="_blank">'.$url."</a><br>\n";
  81. print ' '.$langs->trans("OrToLaunchASpecificJob").'<br>';
  82. $url=$urlwithroot.'/public/cron/cron_run_jobs.php'.(empty($conf->global->CRON_KEY)?'':'?securitykey='.$conf->global->CRON_KEY.'&').'userlogin='.$user->login.'&id=cronjobid';
  83. print img_picto('','object_globe.png').' <a href="'.$url.'" target="_blank">'.$url."</a><br>\n";
  84. print '<br>';
  85. print '<u>'.$langs->trans("FileToLaunchCronJobs").':</u><br>';
  86. $file='/scripts/cron/cron_run_jobs.php'.' '.(empty($conf->global->CRON_KEY)?'securitykey':''.$conf->global->CRON_KEY.'').' '.$user->login.' [cronjobid]';
  87. print '<textarea rows="'.ROWS_2.'" cols="120">..'.$file."</textarea><br>\n";
  88. print '<br>';
  89. // Add note
  90. $linuxlike=1;
  91. if (preg_match('/^win/i',PHP_OS)) $linuxlike=0;
  92. if (preg_match('/^mac/i',PHP_OS)) $linuxlike=0;
  93. print $langs->trans("Note").': ';
  94. if ($linuxlike)
  95. {
  96. print $langs->trans("CronExplainHowToRunUnix");
  97. }
  98. else
  99. {
  100. print $langs->trans("CronExplainHowToRunWin");
  101. }
  102. return 0;
  103. }