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 <https://www.gnu.org/licenses/>.
17 */
18
19/**
20 *	\file       core/lib/cron.lib.php
21 *	\brief      Function for module cron
22 *	\ingroup    cron
23 */
24
25
26/**
27 * Return array of tabs to used on pages to setup cron module.
28 *
29 * @return 	array				Array of tabs
30 */
31function cronadmin_prepare_head()
32{
33	global $langs, $conf, $user;
34	$h = 0;
35	$head = array();
36
37	$head[$h][0] = DOL_URL_ROOT.'/cron/admin/cron.php';
38	$head[$h][1] = $langs->trans("Miscellaneous");
39	$head[$h][2] = 'setup';
40	$h++;
41
42	$head[$h][0] = DOL_URL_ROOT.'/cron/list.php?mode=modulesetup';
43	$head[$h][1] = $langs->trans("Module2300Name");
44	$head[$h][2] = 'jobs';
45	$h++;
46
47	complete_head_from_modules($conf, $langs, null, $head, $h, 'cronadmin');
48
49	complete_head_from_modules($conf, $langs, null, $head, $h, 'cronadmin', 'remove');
50
51
52	return $head;
53}
54
55/**
56 * Return array of tabs to used on a cron job
57 *
58 * @param 	Cronjob	$object		Object cron
59 * @return 	array				Array of tabs
60 */
61function cron_prepare_head(Cronjob $object)
62{
63	global $langs, $conf, $user;
64	$h = 0;
65	$head = array();
66
67	$head[$h][0] = DOL_URL_ROOT.'/cron/card.php?id='.$object->id;
68	$head[$h][1] = $langs->trans("CronTask");
69	$head[$h][2] = 'card';
70	$h++;
71
72	$head[$h][0] = DOL_URL_ROOT.'/cron/info.php?id='.$object->id;
73	$head[$h][1] = $langs->trans("Info");
74	$head[$h][2] = 'info';
75	$h++;
76
77	complete_head_from_modules($conf, $langs, $object, $head, $h, 'cron');
78
79	complete_head_from_modules($conf, $langs, $object, $head, $h, 'cron', 'remove');
80
81	return $head;
82}
83
84/**
85 * Show information with URLs to launch jobs
86 *
87 * @return	int			0
88 */
89function dol_print_cron_urls()
90{
91	global $conf, $langs, $user;
92	global $dolibarr_main_url_root;
93
94	// Define $urlwithroot
95	$urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
96	$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
97	//$urlwithroot=DOL_MAIN_URL_ROOT;					// This is to use same domain name than current
98
99	// Cron launch
100	print '<div class="div-table-responsive-no-min">';
101	print $langs->trans("URLToLaunchCronJobs").':<br>';
102	$url = $urlwithroot.'/public/cron/cron_run_jobs_by_url.php?'.(empty($conf->global->CRON_KEY) ? '' : 'securitykey='.$conf->global->CRON_KEY.'&').'userlogin='.$user->login;
103	print img_picto('', 'globe').' <a href="'.$url.'" target="_blank">'.$url."</a><br>\n";
104	print ' '.$langs->trans("OrToLaunchASpecificJob").'<br>';
105	$url = $urlwithroot.'/public/cron/cron_run_jobs_by_url.php?'.(empty($conf->global->CRON_KEY) ? '' : 'securitykey='.$conf->global->CRON_KEY.'&').'userlogin='.$user->login.'&id=cronjobid';
106	print img_picto('', 'globe').' <a href="'.$url.'" target="_blank">'.$url."</a><br>\n";
107	print '</div>';
108	print '<br>';
109
110	$logintouse = 'firstadmin';
111	if ($user->admin) {
112		$logintouse = $user->login;
113	}
114
115	print '<u>'.$langs->trans("FileToLaunchCronJobs").':</u><br>';
116
117	$pathtoscript = '/pathtoscript';
118	if (!empty($conf->global->MAIN_DOL_SCRIPTS_ROOT)) {
119		$pathtoscript = $conf->global->MAIN_DOL_SCRIPTS_ROOT;
120	}
121
122	$file = $pathtoscript.'/scripts/cron/cron_run_jobs.php '.(empty($conf->global->CRON_KEY) ? 'securitykey' : ''.$conf->global->CRON_KEY.'').' '.$logintouse.' [cronjobid]';
123	print '<textarea class="quatrevingtpercent">'.$file."</textarea><br>\n";
124	print '<br>';
125
126	// Add note
127	if (empty($conf->global->CRON_DISABLE_TUTORIAL_CRON)) {
128		$linuxlike = 1;
129		if (preg_match('/^win/i', PHP_OS)) {
130			$linuxlike = 0;
131		}
132		if (preg_match('/^mac/i', PHP_OS)) {
133			$linuxlike = 0;
134		}
135		print $langs->trans("Note").': ';
136		if ($linuxlike) {
137			print $langs->trans("CronExplainHowToRunUnix");
138			print '<br>';
139			print '<textarea class="quatrevingtpercent">*/5 * * * * '.$pathtoscript.'/scripts/cron/cron_run_jobs.php '.(empty($conf->global->CRON_KEY) ? 'securitykey' : ''.$conf->global->CRON_KEY.'').' '.$logintouse.' &gt; '.DOL_DATA_ROOT.'/cron_run_jobs.php.log</textarea><br>';
140		} else {
141			print $langs->trans("CronExplainHowToRunWin");
142		}
143	}
144
145	return 0;
146}
147