Passed
Branch develop (049034)
by
unknown
31:10
created

getPublicJobPositionUrl()   A

Complexity

Conditions 6
Paths 16

Size

Total Lines 26
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 10
c 1
b 0
f 0
nc 16
nop 3
dl 0
loc 26
rs 9.2222
1
<?php
2
/* Copyright (C) ---Put here your own copyright and developer email---
3
 *
4
 * This program is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
16
 */
17
18
/**
19
 * \file    lib/recruitment_recruitmentjobposition.lib.php
20
 * \ingroup recruitment
21
 * \brief   Library files with common functions for RecruitmentJobPosition
22
 */
23
24
/**
25
 * Prepare array of tabs for RecruitmentJobPosition
26
 *
27
 * @param	RecruitmentJobPosition	$object		RecruitmentJobPosition
28
 * @return 	array					Array of tabs
29
 */
30
function recruitmentjobpositionPrepareHead($object)
31
{
32
	global $db, $langs, $conf;
33
34
	$langs->load("recruitment");
35
36
	$h = 0;
37
	$head = array();
38
39
	$head[$h][0] = dol_buildpath("/recruitment/recruitmentjobposition_card.php", 1).'?id='.$object->id;
40
	$head[$h][1] = $langs->trans("PositionToBeFilled");
41
	$head[$h][2] = 'card';
42
	$h++;
43
44
	$head[$h][0] = dol_buildpath("/recruitment/recruitmentjobposition_candidature.php", 1).'?id='.$object->id;
45
	$head[$h][1] = $langs->trans("Candidatures");
46
	$head[$h][2] = 'candidatures';
47
	$h++;
48
49
	if (isset($object->fields['note_public']) || isset($object->fields['note_private']))
50
	{
51
		$nbNote = 0;
52
		if (!empty($object->note_private)) $nbNote++;
53
		if (!empty($object->note_public)) $nbNote++;
54
		$head[$h][0] = dol_buildpath('/recruitment/recruitmentjobposition_note.php', 1).'?id='.$object->id;
55
		$head[$h][1] = $langs->trans('Notes');
56
		if ($nbNote > 0) $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
57
		$head[$h][2] = 'note';
58
		$h++;
59
	}
60
61
	require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
62
	require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
63
	$upload_dir = $conf->recruitment->dir_output."/recruitmentjobposition/".dol_sanitizeFileName($object->ref);
64
	$nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
65
	$nbLinks = Link::count($db, $object->element, $object->id);
66
	$head[$h][0] = dol_buildpath("/recruitment/recruitmentjobposition_document.php", 1).'?id='.$object->id;
67
	$head[$h][1] = $langs->trans('Documents');
68
	if (($nbFiles + $nbLinks) > 0) $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
69
	$head[$h][2] = 'document';
70
	$h++;
71
72
	$head[$h][0] = dol_buildpath("/recruitment/recruitmentjobposition_agenda.php", 1).'?id='.$object->id;
73
	$head[$h][1] = $langs->trans("Events");
74
	$head[$h][2] = 'agenda';
75
	$h++;
76
77
	// Show more tabs from modules
78
	// Entries must be declared in modules descriptor with line
79
	//$this->tabs = array(
80
	//	'entity:+tabname:Title:@recruitment:/recruitment/mypage.php?id=__ID__'
81
	//); // to add new tab
82
	//$this->tabs = array(
83
	//	'entity:-tabname:Title:@recruitment:/recruitment/mypage.php?id=__ID__'
84
	//); // to remove a tab
85
	complete_head_from_modules($conf, $langs, $object, $head, $h, 'recruitmentjobposition');
86
87
	complete_head_from_modules($conf, $langs, $object, $head, $h, 'recruitmentjobposition', 'remove');
88
89
	return $head;
90
}
91
92
93
/**
94
 * Return string with full Url
95
 *
96
 * @param   int		$mode		      0=True url, 1=Url formated with colors
97
 * @param	string	$ref		      Ref of object
98
 * @param   string  $localorexternal  0=Url for browser, 1=Url for external access
99
 * @return	string				      Url string
100
 */
101
function getPublicJobPositionUrl($mode, $ref = '', $localorexternal = 0)
102
{
103
	global $conf, $dolibarr_main_url_root;
104
105
	$ref = str_replace(' ', '', $ref);
106
	$out = '';
107
108
	// Define $urlwithroot
109
	$urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
110
	$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
111
	//$urlwithroot=DOL_MAIN_URL_ROOT;					// This is to use same domain name than current
112
113
	$urltouse = DOL_MAIN_URL_ROOT;
114
	if ($localorexternal) $urltouse = $urlwithroot;
115
116
	$out = $urltouse.'/public/recruitment/view.php?ref='.($mode ? '<font color="#666666">' : '').$ref.($mode ? '</font>' : '');
117
	/*if (!empty($conf->global->RECRUITMENT_SECURITY_TOKEN))
118
	{
119
		if (empty($conf->global->RECRUITMENT_SECURITY_TOKEN)) $out .= '&securekey='.$conf->global->RECRUITMENT_SECURITY_TOKEN;
120
		else $out .= '&securekey='.dol_hash($conf->global->RECRUITMENT_SECURITY_TOKEN, 2);
121
	}*/
122
123
	// For multicompany
124
	if (!empty($out) && !empty($conf->multicompany->enabled)) $out .= "&entity=".$conf->entity; // Check the entity because we may have the same reference in several entities
125
126
	return $out;
127
}
128